@dasl/fisl 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CLI.md +111 -0
  2. package/README.md +108 -2
  3. package/dist/cli.d.ts +13 -0
  4. package/dist/cli.js +315 -0
  5. package/dist/mod.d.ts +21 -0
  6. package/dist/mod.js +21 -0
  7. package/dist/src/atproto.d.ts +67 -0
  8. package/dist/src/atproto.js +163 -0
  9. package/dist/src/cid-core.d.ts +9 -0
  10. package/dist/src/cid-core.js +39 -0
  11. package/dist/src/cid.d.ts +18 -0
  12. package/dist/src/cid.js +40 -0
  13. package/dist/src/fetch.d.ts +27 -0
  14. package/dist/src/fetch.js +328 -0
  15. package/dist/src/fisl/client.d.ts +17 -0
  16. package/dist/src/fisl/client.js +124 -0
  17. package/dist/src/fisl/server.d.ts +19 -0
  18. package/dist/src/fisl/server.js +69 -0
  19. package/dist/src/index/ingest.d.ts +8 -0
  20. package/dist/src/index/ingest.js +22 -0
  21. package/dist/src/index/jetstream.d.ts +13 -0
  22. package/dist/src/index/jetstream.js +88 -0
  23. package/dist/src/index/pds.d.ts +14 -0
  24. package/dist/src/index/pds.js +42 -0
  25. package/dist/src/index/sqlite.d.ts +16 -0
  26. package/dist/src/index/sqlite.js +105 -0
  27. package/dist/src/index/store.d.ts +37 -0
  28. package/dist/src/index/store.js +59 -0
  29. package/dist/src/index/verify.d.ts +19 -0
  30. package/dist/src/index/verify.js +61 -0
  31. package/dist/src/publish.d.ts +11 -0
  32. package/dist/src/publish.js +24 -0
  33. package/dist/src/rasl/server.d.ts +24 -0
  34. package/dist/src/rasl/server.js +110 -0
  35. package/dist/src/record-core.d.ts +8 -0
  36. package/dist/src/record-core.js +58 -0
  37. package/dist/src/record.d.ts +35 -0
  38. package/dist/src/record.js +47 -0
  39. package/dist/src/serve.d.ts +12 -0
  40. package/dist/src/serve.js +69 -0
  41. package/package.json +50 -4
package/CLI.md ADDED
@@ -0,0 +1,111 @@
1
+ # fisl CLI
2
+
3
+ The `fisl` command line tool publishes, indexes, serves, and fetches content by DASL CID. The [@dasl/fisl](README.md) package includes both the CLI and the library for FISL and ATFISL operations.
4
+
5
+ The installed CLI requires Node.js 22.13 or later. Repository development and tests use Node 24 or later.
6
+
7
+ ## Install
8
+
9
+ Install from npm:
10
+
11
+ ```sh
12
+ npm install -g @dasl/fisl
13
+ fisl help
14
+ ```
15
+
16
+ Or run it without a global install:
17
+
18
+ ```sh
19
+ npx @dasl/fisl help
20
+ ```
21
+
22
+ From a checkout, install and build the package at the repository root:
23
+
24
+ ```sh
25
+ npm install
26
+ npm run build
27
+ npm run fisl -w @dasl/fisl -- help
28
+ ```
29
+
30
+ To install the workspace command globally after the build, run `npm link` inside `packages/lib/`.
31
+
32
+ ## Commands
33
+
34
+ ```sh
35
+ # Print the DASL CID of files
36
+ fisl cid photo.jpg
37
+
38
+ # Log in with an app password
39
+ export FISL_HANDLE=alice.bsky.social FISL_APP_PASSWORD=xxxx-xxxx-xxxx-xxxx
40
+
41
+ # Announce that a file is at a URL
42
+ fisl publish photo.jpg --url https://example.com/photo.jpg --expires 2026-12-31T00:00:00Z
43
+
44
+ # Publish many records, one {"cid", ...record} object per line
45
+ fisl publish --jsonl records.jsonl
46
+
47
+ # List and remove records
48
+ fisl list alice.bsky.social
49
+ fisl unpublish bafkrei...
50
+
51
+ # Serve a directory at /.well-known/rasl/{cid} and announce every file
52
+ fisl serve ./public --port 8080 --public-url https://files.example.com --publish
53
+
54
+ # Run an indexer that follows every dev.fisl.at commit on Jetstream
55
+ fisl indexer --port 8000 --db fisl-index.sqlite
56
+
57
+ # Or index selected repos, read from their PDS every 60 seconds
58
+ fisl indexer --source pds --did alice.bsky.social --did did:plc:...
59
+
60
+ # Look up and fetch by CID
61
+ export FISL_INDEXER=http://localhost:8000
62
+ fisl resolve bafkrei...
63
+ fisl get bafkrei... -o photo.jpg
64
+ fisl get bafkrei... --did alice.bsky.social
65
+ ```
66
+
67
+ `fisl get` uses `https` URLs and `rasl://` URLs. To allow plain `http`, add `--allow-http`. To allow hosts on loopback or private networks, add `--allow-private`. It skips URL schemes it does not know, such as `radiroh://`.
68
+
69
+ With `--output`, the CLI streams the download into a temporary file beside the destination. It replaces the destination only after the bytes match the CID.
70
+
71
+ ## Configuration
72
+
73
+ The CLI reads these environment variables. A command-line flag overrides the variable.
74
+
75
+ | Variable | Used by | Flag |
76
+ | --- | --- | --- |
77
+ | `FISL_HANDLE` | `publish`, `list`, ... | `--handle` |
78
+ | `FISL_APP_PASSWORD` | `publish`, `unpublish` | `--password` |
79
+ | `FISL_INDEXER` | `resolve`, `get` | `--indexer` |
80
+
81
+ The CLI does not read a `.env` file by itself. Node.js can load one with `--env-file`. Example `.env`:
82
+
83
+ ```sh
84
+ FISL_HANDLE=alice.bsky.social
85
+ FISL_APP_PASSWORD=xxxx-xxxx-xxxx-xxxx
86
+ FISL_INDEXER=http://localhost:8000
87
+ ```
88
+
89
+ Do not commit this file. It holds a secret. Add `.env` to your `.gitignore`.
90
+
91
+ To load it, pass the flag to Node.js:
92
+
93
+ ```sh
94
+ NODE_OPTIONS="--env-file=$HOME/.config/fisl/.env" fisl publish photo.jpg --url https://example.com/photo.jpg
95
+
96
+ # Or, from a checkout, in packages/lib/
97
+ node --env-file=.env cli.ts publish photo.jpg --url https://example.com/photo.jpg
98
+ ```
99
+
100
+ Variables already set in your shell take priority over the file.
101
+
102
+ ## Test
103
+
104
+ After building the package, run these commands from the repository root:
105
+
106
+ ```sh
107
+ npm test -w @dasl/fisl
108
+ node scripts/check-pack.mjs
109
+ ```
110
+
111
+ The package test installs the tarball outside the workspace. It tests the installed executable and the library exports.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # @dasl/fisl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Node.js library for [FISL](https://dasl.ing/fisl.html) and [ATFISL](https://dasl.ing/atfisl.html). It does four things:
4
+
5
+ - Publish `dev.fisl.at` records to your AT Protocol repo (Bluesky-hosted or self-hosted PDS).
6
+ - Run a FISL indexer. It follows Jetstream or polls a PDS, verifies each record against a signed commit, and serves `GET /routing/locations/{cid}/{json,jsonl}`.
7
+ - Serve a local directory over [RASL](https://dasl.ing/rasl.html), and optionally publish a record for each file.
8
+ - Fetch content by CID. It resolves locations with FISL, tries each URL, and verifies the hash.
9
+
10
+ Requires Node.js 22.13 or later. Repository development and tests use Node 24 or later. The package also includes the [`fisl` command line tool](CLI.md).
11
+
12
+ ## Install
13
+
14
+ Install the package in your project:
15
+
16
+ ```sh
17
+ npm install @dasl/fisl
18
+ ```
19
+
20
+ Import the library from `@dasl/fisl`:
21
+
22
+ ```ts
23
+ import { cidForFile, fetchCid, login, publish } from "@dasl/fisl";
24
+
25
+ const cid = await cidForFile("photo.jpg");
26
+ const session = await login("alice.bsky.social", process.env.APP_PASSWORD!);
27
+ await publish(session, [{
28
+ cid,
29
+ record: { addrs: [{ url: "https://example.com/photo.jpg" }] },
30
+ }]);
31
+
32
+ const bytes = await fetchCid(cid, { indexers: ["https://indexer.example"] });
33
+ ```
34
+
35
+ The handlers return `null` for paths they do not own, so you can combine them in one server:
36
+
37
+ ```ts
38
+ import { fislHandler, indexDir, MemoryStore, raslHandler } from "@dasl/fisl";
39
+
40
+ const fisl = fislHandler(new MemoryStore());
41
+ const rasl = raslHandler(await indexDir("./public"));
42
+ export default {
43
+ fetch: async (req: Request) =>
44
+ (await fisl(req)) ?? (await rasl(req)) ?? new Response(null, { status: 404 }),
45
+ };
46
+ ```
47
+
48
+ The handlers take a `Request` and return a `Response`, so they work in Cloudflare Workers and other fetch-style servers. For a Node.js HTTP server, import `serve` from `@dasl/fisl/serve`. The `fisl` CLI uses this server adapter.
49
+
50
+ For a persistent index, import `SqliteStore` from `@dasl/fisl/sqlite`. It uses `node:sqlite`:
51
+
52
+ ```ts
53
+ import { SqliteStore } from "@dasl/fisl/sqlite";
54
+
55
+ const store = await SqliteStore.open("fisl-index.sqlite");
56
+ ```
57
+
58
+ ### Cloudflare Workers
59
+
60
+ The library uses Node.js built-in modules, and so do its dependencies. Workers with a compatibility date of 2026-08-04 or later have them by default. For an earlier date, add `"compatibility_flags": ["nodejs_compat"]` to your Wrangler config.
61
+
62
+ Workers have no local file system. Do not use `cidForFile`, `downloadCid`, `indexDir` or `SqliteStore` in a Worker. The Workers in this repository use `cidFromDigest`, `login`, `putRecords`, `resolveIdentity`, `fislHandler`, `ingest` and their own `Store` on D1. See the Workers at the repository root: `indexer-worker/`, `kiwix-worker/`, and `nasa-worker/`.
63
+
64
+ ## How indexing works
65
+
66
+ Jetstream events have no commit proof. For each `dev.fisl.at` event, the indexer fetches `com.atproto.sync.getRecord` from the publisher's PDS. That call returns the signed commit and the path to the record. The indexer then:
67
+
68
+ 1. checks the commit signature against the DID's signing key;
69
+ 2. applies the ATFISL expiry rules;
70
+ 3. stores one row per CID and DID, and keeps the newest repo revision.
71
+
72
+ The Jetstream cursor is saved, so a restart continues from where it stopped.
73
+
74
+ ## Test
75
+
76
+ From the repository root:
77
+
78
+ ```sh
79
+ npm install
80
+ npm run build
81
+ npm test -w @dasl/fisl
82
+ ```
83
+
84
+ To test the CLI and library from the package tarball and build the Workers, run this at the repository root:
85
+
86
+ ```sh
87
+ npm run test:pack
88
+ ```
89
+
90
+ For large files, use `downloadCid(cid, destination, options)` or `fisl get CID --output PATH`.
91
+ The download streams into a temporary file beside the destination.
92
+ It replaces the destination only after the bytes match the CID.
93
+ File downloads have no default size limit. Set `maxSize` to impose one.
94
+
95
+ Retrieval resolves up to four sources and downloads from up to three mirrors at once.
96
+ The default deadlines are 10 seconds per source and 30 seconds per mirror.
97
+ Set `resolutionTimeoutMs`, `downloadTimeoutMs`, `resolutionConcurrency`, or `concurrency` to change these limits.
98
+ Pass an `AbortSignal` as `signal` to cancel retrieval.
99
+ Private address filtering pins each connection to the address that it checks.
100
+
101
+ `indexDir` copies files into temporary snapshots before it hashes them.
102
+ RASL serves these snapshots, so edits to the source directory cannot change bytes behind an existing CID.
103
+ Snapshots require additional disk space equal to the indexed files.
104
+ After stopping the server, call `await files.dispose()` on the result of `indexDir` to remove the snapshots.
105
+
106
+ Stores retain deletion revisions and expiry revisions after they hide records.
107
+ This prevents an older update from restoring a deleted record.
108
+ The Worker saves failed proofs before it advances stream or backfill progress, then retries them on later runs.
109
+ The CLI follower reconnects from its saved position after a failed proof.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The fisl command line tool. Install it with:
4
+ *
5
+ * ```sh
6
+ * npm install -g @dasl/fisl
7
+ * ```
8
+ *
9
+ * For the library, import from `@dasl/fisl`.
10
+ *
11
+ * @module
12
+ */
13
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,315 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The fisl command line tool. Install it with:
4
+ *
5
+ * ```sh
6
+ * npm install -g @dasl/fisl
7
+ * ```
8
+ *
9
+ * For the library, import from `@dasl/fisl`.
10
+ *
11
+ * @module
12
+ */
13
+ import { readFile, stat } from "node:fs/promises";
14
+ import { text } from "node:stream/consumers";
15
+ import { parseArgs } from "node:util";
16
+ import { backfill, cidForFile, deleteRecord, downloadCid, fetchCid, fislHandler, followJetstream, indexDir, isDatetime, JETSTREAM, listRecords, login, MemoryStore, parseCid, pollRepos, publish, RASL_PREFIX, raslHandler, resolve, resolveIdentity, Verifier, } from "./mod.js";
17
+ import { SqliteStore } from "./src/index/sqlite.js";
18
+ import { serve } from "./src/serve.js";
19
+ const USAGE = `fisl: publish, index, serve and fetch content by DASL CID
20
+
21
+ Usage:
22
+ fisl cid <file...>
23
+ fisl publish <file|cid> --url <url>... [--expires <datetime>] [--size <n>]
24
+ fisl publish --jsonl <file|->
25
+ fisl unpublish <cid...>
26
+ fisl list [<handle|did>]
27
+ fisl serve <dir> [--port 8080] [--hostname 0.0.0.0]
28
+ [--public-url https://host] [--publish] [--expires <datetime>]
29
+ fisl indexer [--port 8000] [--db <path>|:memory:] [--source jetstream|pds]
30
+ [--did <handle|did>]... [--interval <seconds>] [--jetstream <url>]
31
+ fisl resolve <cid> [--indexer <url>]... [--did <handle|did>]...
32
+ fisl get <cid> [--indexer <url>]... [--did <handle|did>]... [-o <file>]
33
+ [--allow-http] [--allow-private]
34
+
35
+ resolve and get use FISL_INDEXER when no --indexer or --did is given.
36
+ publish --jsonl reads one {"cid", ...record} object per line, as list prints.
37
+ Publishing needs a login. Set FISL_HANDLE and FISL_APP_PASSWORD, or pass
38
+ --handle and --password.`;
39
+ function fail(message) {
40
+ console.error(`fisl: ${message}`);
41
+ process.exit(1);
42
+ }
43
+ /** Parse flags. Unknown flags fail. */
44
+ function parse(args, options) {
45
+ try {
46
+ const { values, positionals } = parseArgs({
47
+ args,
48
+ options,
49
+ allowPositionals: true,
50
+ });
51
+ return { ...values, _: positionals };
52
+ }
53
+ catch (e) {
54
+ fail(e.message);
55
+ }
56
+ }
57
+ const LOGIN = {
58
+ handle: { type: "string" },
59
+ password: { type: "string" },
60
+ };
61
+ function session(flags) {
62
+ const handle = flags.handle ?? process.env.FISL_HANDLE;
63
+ const password = flags.password ?? process.env.FISL_APP_PASSWORD;
64
+ if (!handle || !password) {
65
+ fail("set FISL_HANDLE and FISL_APP_PASSWORD, or --handle and --password");
66
+ }
67
+ return login(handle, password);
68
+ }
69
+ async function resolveHandleOrFail(handle) {
70
+ try {
71
+ return (await resolveIdentity(handle)).did;
72
+ }
73
+ catch (e) {
74
+ fail(`could not resolve ${handle}: ${e.message}`);
75
+ }
76
+ }
77
+ function lookupArgs(args) {
78
+ const flags = parse(args, {
79
+ indexer: { type: "string", multiple: true, default: [] },
80
+ did: { type: "string", multiple: true, default: [] },
81
+ output: { type: "string", short: "o" },
82
+ "allow-http": { type: "boolean" },
83
+ "allow-private": { type: "boolean" },
84
+ });
85
+ const cid = flags._[0];
86
+ if (!cid || !parseCid(cid))
87
+ fail("needs a DASL CID");
88
+ let indexers = flags.indexer;
89
+ const env = process.env.FISL_INDEXER;
90
+ if (!indexers.length && !flags.did.length && env)
91
+ indexers = [env];
92
+ if (!indexers.length && !flags.did.length) {
93
+ fail("give --indexer or --did, or set FISL_INDEXER");
94
+ }
95
+ const opts = {
96
+ indexers,
97
+ publishers: flags.did,
98
+ onError: (source, e) => console.error(`${source}: ${e.message}`),
99
+ };
100
+ return { cid, opts, flags };
101
+ }
102
+ function checkExpires(expires) {
103
+ if (expires !== undefined && !isDatetime(expires)) {
104
+ fail(`--expires must be a datetime like 2026-12-31T00:00:00Z`);
105
+ }
106
+ }
107
+ const commands = {
108
+ async cid(args) {
109
+ const { _: files } = parse(args, {});
110
+ if (!files.length)
111
+ fail("cid needs at least one file");
112
+ for (const f of files) {
113
+ console.log(`${await cidForFile(f)} ${f}`);
114
+ }
115
+ },
116
+ async publish(args) {
117
+ const flags = parse(args, {
118
+ ...LOGIN,
119
+ url: { type: "string", multiple: true, default: [] },
120
+ expires: { type: "string" },
121
+ size: { type: "string" },
122
+ jsonl: { type: "string" },
123
+ });
124
+ if (flags.jsonl !== undefined) {
125
+ const input = flags.jsonl === "-"
126
+ ? await text(process.stdin)
127
+ : await readFile(flags.jsonl, "utf8");
128
+ const items = input.split("\n").filter((l) => l.trim()).map((l) => {
129
+ const { cid, ...record } = JSON.parse(l);
130
+ return { cid, record };
131
+ });
132
+ const s = await session(flags);
133
+ await publish(s, items);
134
+ console.log(`Published ${items.length} records as ${s.did}`);
135
+ return;
136
+ }
137
+ const target = flags._[0];
138
+ if (!target)
139
+ fail("publish needs a file or a CID");
140
+ if (!flags.url.length)
141
+ fail("publish needs at least one --url");
142
+ checkExpires(flags.expires);
143
+ let cid = target;
144
+ let size = flags.size === undefined ? undefined : Number(flags.size);
145
+ if (!parseCid(target)) {
146
+ cid = await cidForFile(target);
147
+ size ??= (await stat(target)).size;
148
+ }
149
+ const record = {
150
+ addrs: flags.url.map((url) => ({ url })),
151
+ };
152
+ if (size !== undefined)
153
+ record.size = size;
154
+ if (flags.expires)
155
+ record.expires = flags.expires;
156
+ const s = await session(flags);
157
+ await publish(s, [{ cid, record }]);
158
+ console.log(`at://${s.did}/dev.fisl.at/${cid}`);
159
+ },
160
+ async unpublish(args) {
161
+ const flags = parse(args, LOGIN);
162
+ if (!flags._.length)
163
+ fail("unpublish needs at least one CID");
164
+ const s = await session(flags);
165
+ for (const cid of flags._) {
166
+ await deleteRecord(s, cid);
167
+ console.log(`Deleted ${cid}`);
168
+ }
169
+ },
170
+ async list(args) {
171
+ const flags = parse(args, LOGIN);
172
+ const who = flags._[0] ?? flags.handle ?? process.env.FISL_HANDLE;
173
+ if (!who)
174
+ fail("list needs a handle or DID");
175
+ const id = await resolveIdentity(who);
176
+ for await (const { cid, record } of listRecords(id)) {
177
+ console.log(JSON.stringify({ cid, ...record }));
178
+ }
179
+ },
180
+ async indexer(args) {
181
+ const flags = parse(args, {
182
+ port: { type: "string", default: "8000" },
183
+ hostname: { type: "string", default: "0.0.0.0" },
184
+ db: { type: "string", default: "fisl-index.sqlite" },
185
+ source: { type: "string", default: "jetstream" },
186
+ did: { type: "string", multiple: true, default: [] },
187
+ interval: { type: "string", default: "60" },
188
+ jetstream: { type: "string", default: JETSTREAM },
189
+ });
190
+ if (flags.source !== "jetstream" && flags.source !== "pds") {
191
+ fail("--source must be jetstream or pds");
192
+ }
193
+ if (flags.source === "pds" && !flags.did.length) {
194
+ fail("--source pds needs at least one --did");
195
+ }
196
+ const store = flags.db === ":memory:"
197
+ ? new MemoryStore()
198
+ : await SqliteStore.open(flags.db);
199
+ const verifier = new Verifier();
200
+ const log = (msg) => console.error(msg);
201
+ const dids = await Promise.all(flags.did.map(resolveHandleOrFail));
202
+ const fisl = fislHandler(store);
203
+ await serve(async (req) => (await fisl(req)) ?? new Response("Not found", { status: 404 }), { port: Number(flags.port), hostname: flags.hostname });
204
+ setInterval(async () => {
205
+ const n = await store.sweep();
206
+ if (n)
207
+ log(`swept ${n} expired records`);
208
+ }, 60_000);
209
+ if (flags.source === "pds") {
210
+ await pollRepos(store, verifier, dids, {
211
+ interval: Number(flags.interval) * 1000,
212
+ log,
213
+ });
214
+ }
215
+ else {
216
+ for (const did of dids)
217
+ await backfill(store, verifier, did, { log });
218
+ await followJetstream(store, verifier, {
219
+ url: flags.jetstream,
220
+ dids,
221
+ log,
222
+ });
223
+ }
224
+ },
225
+ async resolve(args) {
226
+ const { cid, opts } = lookupArgs(args);
227
+ for await (const loc of resolve(cid, opts)) {
228
+ console.log(JSON.stringify(loc));
229
+ }
230
+ },
231
+ async get(args) {
232
+ const { cid, opts, flags } = lookupArgs(args);
233
+ try {
234
+ const options = {
235
+ ...opts,
236
+ allowHttp: flags["allow-http"],
237
+ allowPrivate: flags["allow-private"],
238
+ log: (msg) => console.error(msg),
239
+ };
240
+ if (flags.output)
241
+ await downloadCid(cid, flags.output, options);
242
+ else
243
+ process.stdout.write(await fetchCid(cid, options));
244
+ }
245
+ catch (e) {
246
+ fail(e.message);
247
+ }
248
+ },
249
+ async serve(args) {
250
+ const flags = parse(args, {
251
+ ...LOGIN,
252
+ port: { type: "string", default: "8080" },
253
+ hostname: { type: "string", default: "0.0.0.0" },
254
+ "public-url": { type: "string" },
255
+ expires: { type: "string" },
256
+ publish: { type: "boolean" },
257
+ });
258
+ const dir = flags._[0];
259
+ if (!dir)
260
+ fail("serve needs a directory");
261
+ const publicUrl = flags["public-url"]?.replace(/\/$/, "");
262
+ if (flags.publish && !publicUrl)
263
+ fail("--publish needs --public-url");
264
+ checkExpires(flags.expires);
265
+ // Log in first, so a bad password fails before hashing a large directory.
266
+ let s;
267
+ if (flags.publish)
268
+ s = await session(flags);
269
+ const files = await indexDir(dir, {
270
+ onFile: (f) => console.error(`${f.cid} ${f.name}`),
271
+ });
272
+ console.error(`Indexed ${files.size} files`);
273
+ const rasl = raslHandler(files);
274
+ const server = await serve(async (req) => (await rasl(req)) ?? new Response("Not found", { status: 404 }), { port: Number(flags.port), hostname: flags.hostname });
275
+ const stop = () => {
276
+ void server.shutdown();
277
+ };
278
+ process.once("SIGINT", stop);
279
+ process.once("SIGTERM", stop);
280
+ console.error(`Serving ${RASL_PREFIX}{cid}`);
281
+ try {
282
+ if (s) {
283
+ await publish(s, [...files.values()].map((f) => ({
284
+ cid: f.cid,
285
+ record: {
286
+ addrs: [{ url: `${publicUrl}${RASL_PREFIX}${f.cid}` }],
287
+ size: f.size,
288
+ ...(flags.expires ? { expires: flags.expires } : {}),
289
+ },
290
+ })));
291
+ console.error(`Published ${files.size} records as ${s.did}`);
292
+ }
293
+ await server.finished;
294
+ }
295
+ finally {
296
+ process.off("SIGINT", stop);
297
+ process.off("SIGTERM", stop);
298
+ await server.shutdown();
299
+ await files.dispose();
300
+ }
301
+ },
302
+ };
303
+ // Exit quietly when the reader closes the pipe, as in `fisl list | head`.
304
+ process.stdout.on("error", (e) => {
305
+ if (e.code === "EPIPE")
306
+ process.exit(0);
307
+ throw e;
308
+ });
309
+ const [name, ...rest] = process.argv.slice(2);
310
+ const command = Object.hasOwn(commands, name) ? commands[name] : undefined;
311
+ if (!command || rest.includes("--help")) {
312
+ console.log(USAGE);
313
+ process.exit(command || name === "help" || !name ? 0 : 1);
314
+ }
315
+ await command(rest);
package/dist/mod.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Publish, index, serve and fetch content by DASL CID, with FISL and ATFISL.
3
+ *
4
+ * Import this module as `@dasl/fisl`. The Node.js SQLite store is in
5
+ * `@dasl/fisl/sqlite`, and the Node.js HTTP server is in `@dasl/fisl/serve`.
6
+ *
7
+ * @module
8
+ */
9
+ export * from "./src/cid.ts";
10
+ export * from "./src/record.ts";
11
+ export * from "./src/atproto.ts";
12
+ export * from "./src/publish.ts";
13
+ export * from "./src/fetch.ts";
14
+ export * from "./src/fisl/server.ts";
15
+ export * from "./src/fisl/client.ts";
16
+ export * from "./src/rasl/server.ts";
17
+ export * from "./src/index/store.ts";
18
+ export * from "./src/index/verify.ts";
19
+ export * from "./src/index/ingest.ts";
20
+ export * from "./src/index/pds.ts";
21
+ export * from "./src/index/jetstream.ts";
package/dist/mod.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Publish, index, serve and fetch content by DASL CID, with FISL and ATFISL.
3
+ *
4
+ * Import this module as `@dasl/fisl`. The Node.js SQLite store is in
5
+ * `@dasl/fisl/sqlite`, and the Node.js HTTP server is in `@dasl/fisl/serve`.
6
+ *
7
+ * @module
8
+ */
9
+ export * from "./src/cid.js";
10
+ export * from "./src/record.js";
11
+ export * from "./src/atproto.js";
12
+ export * from "./src/publish.js";
13
+ export * from "./src/fetch.js";
14
+ export * from "./src/fisl/server.js";
15
+ export * from "./src/fisl/client.js";
16
+ export * from "./src/rasl/server.js";
17
+ export * from "./src/index/store.js";
18
+ export * from "./src/index/verify.js";
19
+ export * from "./src/index/ingest.js";
20
+ export * from "./src/index/pds.js";
21
+ export * from "./src/index/jetstream.js";
@@ -0,0 +1,67 @@
1
+ import { type AtfislRecord } from "./record.ts";
2
+ export interface Identity {
3
+ did: string;
4
+ pds: string;
5
+ /** The repo signing key as a did:key, if the DID document has one. */
6
+ signingKey?: string;
7
+ }
8
+ export declare const PLC_DIRECTORY = "https://plc.directory";
9
+ export declare const APPVIEW = "https://public.api.bsky.app";
10
+ export declare class XrpcError extends Error {
11
+ readonly status: number;
12
+ readonly error: string | undefined;
13
+ constructor(status: number, error: string | undefined, message: string);
14
+ }
15
+ /** Call an XRPC method. Queries use GET with params; procedures POST a JSON body. */
16
+ export declare function xrpc<T = unknown>(service: string, method: string, opts?: {
17
+ params?: Record<string, string | number | undefined>;
18
+ body?: unknown;
19
+ token?: string;
20
+ signal?: AbortSignal;
21
+ }): Promise<T>;
22
+ /** Resolve a handle to a DID: DNS, then .well-known, then the Bluesky AppView. */
23
+ export declare function resolveHandle(handle: string, signal?: AbortSignal): Promise<string>;
24
+ interface DidDocument {
25
+ id: string;
26
+ service?: {
27
+ id: string;
28
+ type: string;
29
+ serviceEndpoint: string;
30
+ }[];
31
+ verificationMethod?: {
32
+ id: string;
33
+ type: string;
34
+ publicKeyMultibase?: string;
35
+ }[];
36
+ }
37
+ export declare function resolveDid(did: string, signal?: AbortSignal): Promise<DidDocument>;
38
+ /** Resolve a handle or DID to its DID, PDS and signing key. */
39
+ export declare function resolveIdentity(handleOrDid: string, signal?: AbortSignal): Promise<Identity>;
40
+ /** An authenticated session on the user's PDS. */
41
+ export interface Session extends Identity {
42
+ accessJwt: string;
43
+ }
44
+ /** Log in with a handle (or DID) and an app password. */
45
+ export declare function login(identifier: string, password: string): Promise<Session>;
46
+ /** Create or replace the record for a CID. */
47
+ export declare function putRecord(s: Session, cid: string, record: AtfislRecord): Promise<{
48
+ uri: string;
49
+ cid: string;
50
+ }>;
51
+ export declare function deleteRecord(s: Session, cid: string): Promise<unknown>;
52
+ /**
53
+ * Create or replace many records in one commit. At most 200 per call.
54
+ * applyWrites has no upsert, so pass the CIDs that already have a record.
55
+ */
56
+ export declare function putRecords(s: Session, records: {
57
+ cid: string;
58
+ record: AtfislRecord;
59
+ }[], existing?: Set<string>): Promise<unknown>;
60
+ /** Read one record from a repo. Returns null if there is none. */
61
+ export declare function getRecord(id: Identity, cid: string, signal?: AbortSignal): Promise<AtfislRecord | null>;
62
+ /** List every dev.fisl.at record in a repo. */
63
+ export declare function listRecords(id: Identity): AsyncGenerator<{
64
+ cid: string;
65
+ record: AtfislRecord;
66
+ }>;
67
+ export {};