fix: remove bad URL constructor
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);
|
||||
}
|
||||
|
||||
// Cache everything
|
||||
if (this.#config.cachingRelay) {
|
||||
this.on("event", async (_, ev) => {
|
||||
await this.#config.cachingRelay?.event(ev);
|
||||
})
|
||||
}
|
||||
|
||||
// Hook on-event when building follow graph
|
||||
if (this.#config.buildFollowGraph) {
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
```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
|
||||
await relay.init();
|
||||
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 }]);
|
||||
@ -33,7 +30,9 @@ 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");
|
||||
|
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",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "A nostr relay in a service worker",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@ -17,14 +17,16 @@
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@sqlite.org/sqlite-wasm": "^3.45.1-build1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/uuid": "^9.0.7",
|
||||
"esbuild": "^0.20.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
}
|
@ -11,17 +11,16 @@ export class WorkerRelayInterface {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
constructor(path?: string | Worker, sqlite3Dir?: string) {
|
||||
if (path instanceof Worker) {
|
||||
this.#worker = path;
|
||||
constructor(scriptPath?: string | URL | Worker, sqlite3Dir?: string) {
|
||||
this.#sqliteDir = sqlite3Dir;
|
||||
if (scriptPath instanceof Worker) {
|
||||
this.#worker = scriptPath;
|
||||
} else {
|
||||
const sqliteBase = new URL("@sqlite.org/sqlite-wasm?url", import.meta.url);
|
||||
this.#sqliteDir = sqlite3Dir ?? sqliteBase.href;
|
||||
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" })
|
||||
const sp = scriptPath ? scriptPath : new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
|
||||
this.#worker = new Worker(sp, { type: "module" })
|
||||
};
|
||||
this.#worker.onerror = e => {
|
||||
console.error(e.message, e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user