1.3.1 • Published 6 months ago

@snort/worker-relay v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Worker Relay

Worker relay is a Nostr relay built on sqlite-wasm

WorkerRelayInterface is the class which accepts the URL of the worker script

sqlite-wasm uses OFPS in order to persist the database.

Example

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";

// 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 workerRelay = new WorkerRelayInterface(workerScript);

// load sqlite database and run migrations
await workerRelay.init({
  databasePath: "relay.db",
  insertBatchSize: 100,
});

// Query worker relay with regular nostr REQ command
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: [],
};
if (await workerRelay.event(myEvent)) {
  console.log("Success");
}
1.3.1

6 months ago

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

1 year ago

1.3.0

10 months ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.2

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago