Merge branch 'main' of https://git.v0l.io/Kieran/snort
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Kieran 2024-03-07 16:38:27 +00:00
commit 2b98f0fc4a
13 changed files with 43 additions and 44 deletions

View File

@ -9,7 +9,7 @@ import { ProfileCacheRelayWorker } from "./ProfileWorkerCache";
import { UserFollowsWorker } from "./UserFollowsWorker";
export const Relay = new WorkerRelayInterface(
import.meta.env.DEV ? new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url) : new WorkerVite()
import.meta.env.DEV ? new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url) : new WorkerVite(),
);
export async function initRelayWorker() {
try {

View File

@ -208,7 +208,7 @@
"J+dIsA": "Abonnements",
"J1iLmb": "Benachrichtigungen nicht erlaubt",
"J2HeQ+": "Benutze Kommas um Wörter zu trennen, z.B. Wort1, Wort2, Wort3",
"JA+tz3": "Looking up thread...",
"JA+tz3": "Thread wird gesucht...",
"JCIgkj": "Benutzername",
"JGrt9q": "Sats an {name} senden",
"JHEHCk": "Zaps ({n})",

View File

@ -208,7 +208,7 @@
"J+dIsA": "Előfizetések",
"J1iLmb": "Az értesítések nincsenek engedélyezve",
"J2HeQ+": "Szavak elválasztása vesszőkkel, pl. word1, word2, word3.",
"JA+tz3": "Looking up thread...",
"JA+tz3": "Keresem a fonalat...",
"JCIgkj": "Felhasználónév",
"JGrt9q": "Sat-ok küldése {name}",
"JHEHCk": "Zap-ek ({n})",

View File

@ -54,6 +54,6 @@ export default defineConfig({
global: {}, // needed for custom-event lib
},
worker: {
format: "es"
format: "es",
},
});

View File

@ -197,7 +197,7 @@ export class NostrSystem extends EventEmitter<NostrSystemEvents> implements Syst
if (this.#config.cachingRelay) {
this.on("event", async (_, ev) => {
await this.#config.cachingRelay?.event(ev);
})
});
}
// Hook on-event when building follow graph

View File

@ -12,12 +12,12 @@ Worker relay is a Nostr relay built on `sqlite-wasm`
import { WorkerRelayInterface } from "@snort/worker-relay";
// when using Vite import the worker script directly (for production)
import WorkerVite from "@snort/worker-relay/src/worker?worker"
import WorkerVite from "@snort/worker-relay/src/worker?worker";
// in dev mode import esm module, i have no idea why it has to work like this
const workerScript = import.meta.env.DEV ?
new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url) :
new WorkerVite();
const workerScript = import.meta.env.DEV
? new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url)
: new WorkerVite();
const workerRelay = new WorkerRelayInterface(workerScript);
@ -29,12 +29,12 @@ const results = await workerRelay.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: []
kind: 1,
created_at: Math.floor(new Date().getTime() / 1000),
content: "test",
tags: [],
};
if (await workerRelay.event(myEvent)) {
console.log("Success");
console.log("Success");
}
```

View File

@ -1,12 +1,12 @@
import { WorkerRelayInterface } from "@snort/worker-relay";
// when using Vite import the worker script directly (for production)
import WorkerVite from "@snort/worker-relay/src/worker?worker"
import WorkerVite from "@snort/worker-relay/src/worker?worker";
// in dev mode import esm module, i have no idea why it has to work like this
const workerScript = import.meta.env.DEV ?
new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url) :
new WorkerVite();
const workerScript = import.meta.env.DEV
? new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url)
: new WorkerVite();
const workerRelay = new WorkerRelayInterface(workerScript);
@ -18,11 +18,11 @@ const results = await workerRelay.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: []
kind: 1,
created_at: Math.floor(new Date().getTime() / 1000),
content: "test",
tags: [],
};
if (await workerRelay.event(myEvent)) {
console.log("Success");
}
console.log("Success");
}

View File

@ -5,4 +5,4 @@ declare module "*.wasm" {
declare module "*.wasm?url" {
const value: string;
export default value;
}
}

View File

@ -1,10 +1,9 @@
let debug = false;
export function debugLog(scope: string, msg: string, ...args: Array<any>) {
if (!debug) return;
console.log(scope, msg, ...args);
if (!debug) return;
console.log(scope, msg, ...args);
}
export function setLogging(v: boolean) {
debug = v;
}
debug = v;
}

View File

@ -1 +1 @@
export * from "./interface";
export * from "./interface";

View File

@ -17,14 +17,14 @@ export class WorkerRelayInterface {
this.#worker = scriptPath;
} else {
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 = new Worker(sp, { type: "module" });
}
this.#worker.onerror = e => {
console.error(e.message, e);
}
};
this.#worker.onmessageerror = e => {
console.error(e);
}
};
this.#worker.onmessage = e => {
const cmd = e.data as WorkerMessage<any>;
if (cmd.cmd === "reply") {

View File

@ -26,7 +26,7 @@ export class SqliteRelay extends EventEmitter<RelayHandlerEvents> implements Rel
return prefix + path;
},
print: msg => this.#log(msg),
printErr: msg => this.#log(msg)
printErr: msg => this.#log(msg),
});
this.#log(`Got SQLite version: ${this.#sqlite.version.libVersion}`);
await this.#open(path);

View File

@ -162,20 +162,20 @@ const handleMsg = async (port: MessagePort | DedicatedWorkerGlobalScope, ev: Mes
} else if (typeof e === "string") {
reply(msg.id, { error: e });
} else {
reply(msg.id, "Unknown error")
reply(msg.id, "Unknown error");
}
}
}
};
if ("SharedWorkerGlobalScope" in globalThis) {
onconnect = (e) => {
onconnect = e => {
const port = e.ports[0];
port.onmessage = (msg) => handleMsg(port, msg);
port.onmessage = msg => handleMsg(port, msg);
port.start();
}
};
}
if ("DedicatedWorkerGlobalScope" in globalThis) {
onmessage = e => {
handleMsg(self as DedicatedWorkerGlobalScope, e)
}
}
handleMsg(self as DedicatedWorkerGlobalScope, e);
};
}