fix: remove bad URL constructor
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
6785ef72e1
commit
99b4d01ff7
@ -193,6 +193,13 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
|
|||||||
this.requestRouter = OutboxModel.fromSystem(this);
|
this.requestRouter = OutboxModel.fromSystem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache everything
|
||||||
|
if (this.#config.cachingRelay) {
|
||||||
|
this.on("event", async (_, ev) => {
|
||||||
|
await this.#config.cachingRelay?.event(ev);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Hook on-event when building follow graph
|
// Hook on-event when building follow graph
|
||||||
if (this.#config.buildFollowGraph) {
|
if (this.#config.buildFollowGraph) {
|
||||||
let evBuf: Array<TaggedNostrEvent> = [];
|
let evBuf: Array<TaggedNostrEvent> = [];
|
||||||
|
@ -6,26 +6,23 @@ Worker relay is a Nostr relay built on `sqlite-wasm`
|
|||||||
|
|
||||||
`sqlite-wasm` uses OFPS in order to persist the database.
|
`sqlite-wasm` uses OFPS in order to persist the database.
|
||||||
|
|
||||||
OPFS requires special headers to be present when serving your application. Read more about it [here](https://sqlite.org/wasm/doc/trunk/persistence.md#opfs)
|
|
||||||
|
|
||||||
```
|
|
||||||
Cross-Origin-Opener-Policy: same-origin
|
|
||||||
Cross-Origin-Embedder-Policy: require-corp
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage (Vite)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import WorkerRelayPath from "@snort/worker-relay/dist/worker?worker&url";
|
|
||||||
```
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const relay = new WorkerRelayInterface(WorkerRelayPath);
|
import { WorkerRelayInterface } from "@snort/worker-relay";
|
||||||
|
|
||||||
|
// in debug mode you may need this, to map to the correct sqlite-wasm path
|
||||||
|
// this is needed because sqlite-wasm will otherwise look inside @snort/worker-relay directory for sqlite3.wasm
|
||||||
|
const basePath = new URL("@sqlite.org/sqlite-wasm", import.meta.url);
|
||||||
|
|
||||||
|
// internally we resolve the script path like this:
|
||||||
|
const scriptPath = new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
|
||||||
|
|
||||||
|
// scriptPath & basePath are optional
|
||||||
|
const relay = new WorkerRelayInterface(scriptPath.href, basePath.href);
|
||||||
|
|
||||||
// load sqlite database and run migrations
|
// load sqlite database and run migrations
|
||||||
await relay.init();
|
await relay.init("my-relay.db");
|
||||||
|
|
||||||
// Query worker relay with regular nostr REQ command
|
// Query worker relay with regular nostr REQ command
|
||||||
const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
|
const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
|
||||||
@ -33,7 +30,9 @@ const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
|
|||||||
// publish a new event to the relay
|
// publish a new event to the relay
|
||||||
const myEvent = {
|
const myEvent = {
|
||||||
kind: 1,
|
kind: 1,
|
||||||
|
created_at: Math.floor(new Date().getTime() / 1000),
|
||||||
content: "test",
|
content: "test",
|
||||||
|
tags: []
|
||||||
};
|
};
|
||||||
if (await relay.event(myEvent)) {
|
if (await relay.event(myEvent)) {
|
||||||
console.log("Success");
|
console.log("Success");
|
||||||
|
28
packages/worker-relay/example/basic.ts
Normal file
28
packages/worker-relay/example/basic.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { WorkerRelayInterface } from "@snort/worker-relay";
|
||||||
|
|
||||||
|
// in debug mode you may need this, to map to the correct sqlite-wasm path
|
||||||
|
// this is needed because sqlite-wasm will otherwise look inside @snort/worker-relay directory for sqlite3.wasm
|
||||||
|
const basePath = new URL("@sqlite.org/sqlite-wasm", import.meta.url);
|
||||||
|
|
||||||
|
// internally we resolve the script path like this:
|
||||||
|
const scriptPath = new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
|
||||||
|
|
||||||
|
// scriptPath & basePath are optional
|
||||||
|
const relay = new WorkerRelayInterface(scriptPath, basePath.href);
|
||||||
|
|
||||||
|
// load sqlite database and run migrations
|
||||||
|
await relay.init("my-relay.db");
|
||||||
|
|
||||||
|
// Query worker relay with regular nostr REQ command
|
||||||
|
const results = await relay.query(["REQ", "1", { kinds: [1], limit: 10 }]);
|
||||||
|
|
||||||
|
// publish a new event to the relay
|
||||||
|
const myEvent = {
|
||||||
|
kind: 1,
|
||||||
|
created_at: Math.floor(new Date().getTime() / 1000),
|
||||||
|
content: "test",
|
||||||
|
tags: []
|
||||||
|
};
|
||||||
|
if (await relay.event(myEvent)) {
|
||||||
|
console.log("Success");
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@snort/worker-relay",
|
"name": "@snort/worker-relay",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"description": "A nostr relay in a service worker",
|
"description": "A nostr relay in a service worker",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
@ -17,10 +17,12 @@
|
|||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1",
|
|
||||||
"eventemitter3": "^5.0.1",
|
"eventemitter3": "^5.0.1",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@sqlite.org/sqlite-wasm": "^3.45.1-build1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/debug": "^4.1.12",
|
"@types/debug": "^4.1.12",
|
||||||
"@types/uuid": "^9.0.7",
|
"@types/uuid": "^9.0.7",
|
||||||
|
@ -11,17 +11,16 @@ export class WorkerRelayInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface wrapper for worker relay
|
* Interface wrapper for worker relay
|
||||||
* @param path Path to worker script or Worker script object
|
* @param scriptPath Path to worker script or Worker script object
|
||||||
* @param sqlite3Dir Directory to search for sqlite3 depends
|
* @param sqlite3Dir Directory to search for sqlite3 depends
|
||||||
*/
|
*/
|
||||||
constructor(path?: string | Worker, sqlite3Dir?: string) {
|
constructor(scriptPath?: string | URL | Worker, sqlite3Dir?: string) {
|
||||||
if (path instanceof Worker) {
|
this.#sqliteDir = sqlite3Dir;
|
||||||
this.#worker = path;
|
if (scriptPath instanceof Worker) {
|
||||||
|
this.#worker = scriptPath;
|
||||||
} else {
|
} else {
|
||||||
const sqliteBase = new URL("@sqlite.org/sqlite-wasm?url", import.meta.url);
|
const sp = scriptPath ? scriptPath : new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
|
||||||
this.#sqliteDir = sqlite3Dir ?? sqliteBase.href;
|
this.#worker = new Worker(sp, { type: "module" })
|
||||||
const scriptPath = path ? new URL(path) : new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
|
|
||||||
this.#worker = new Worker(scriptPath, { type: "module" })
|
|
||||||
};
|
};
|
||||||
this.#worker.onerror = e => {
|
this.#worker.onerror = e => {
|
||||||
console.error(e.message, e);
|
console.error(e.message, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user