@hatk/hatk 0.0.1-alpha.11 → 0.0.1-alpha.111
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.
- package/dist/adapter.d.ts +19 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +113 -0
- package/dist/backfill.d.ts +36 -2
- package/dist/backfill.d.ts.map +1 -1
- package/dist/backfill.js +153 -37
- package/dist/car.js +1 -1
- package/dist/classifiers.d.ts +228 -0
- package/dist/classifiers.d.ts.map +1 -0
- package/dist/classifiers.js +688 -0
- package/dist/cli.js +248 -1043
- package/dist/config.d.ts +179 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +78 -8
- package/dist/database/adapter-factory.d.ts +6 -0
- package/dist/database/adapter-factory.d.ts.map +1 -0
- package/dist/database/adapter-factory.js +20 -0
- package/dist/database/adapters/duckdb-search.d.ts +12 -0
- package/dist/database/adapters/duckdb-search.d.ts.map +1 -0
- package/dist/database/adapters/duckdb-search.js +27 -0
- package/dist/database/adapters/duckdb.d.ts +25 -0
- package/dist/database/adapters/duckdb.d.ts.map +1 -0
- package/dist/database/adapters/duckdb.js +161 -0
- package/dist/database/adapters/sqlite-search.d.ts +16 -0
- package/dist/database/adapters/sqlite-search.d.ts.map +1 -0
- package/dist/database/adapters/sqlite-search.js +76 -0
- package/dist/database/adapters/sqlite.d.ts +18 -0
- package/dist/database/adapters/sqlite.d.ts.map +1 -0
- package/dist/database/adapters/sqlite.js +88 -0
- package/dist/database/db.d.ts +290 -0
- package/dist/database/db.d.ts.map +1 -0
- package/dist/database/db.js +2073 -0
- package/dist/database/dialect.d.ts +45 -0
- package/dist/database/dialect.d.ts.map +1 -0
- package/dist/database/dialect.js +72 -0
- package/dist/{fts.d.ts → database/fts.d.ts} +7 -0
- package/dist/database/fts.d.ts.map +1 -0
- package/dist/{fts.js → database/fts.js} +122 -34
- package/dist/database/index.d.ts +7 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +6 -0
- package/dist/database/ports.d.ts +50 -0
- package/dist/database/ports.d.ts.map +1 -0
- package/dist/database/ports.js +1 -0
- package/dist/database/schema.d.ts +91 -0
- package/dist/database/schema.d.ts.map +1 -0
- package/dist/{schema.js → database/schema.js} +153 -54
- package/dist/dev-entry.d.ts +8 -0
- package/dist/dev-entry.d.ts.map +1 -0
- package/dist/dev-entry.js +131 -0
- package/dist/feeds.d.ts +26 -8
- package/dist/feeds.d.ts.map +1 -1
- package/dist/feeds.js +72 -16
- package/dist/hooks.d.ts +102 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +186 -0
- package/dist/hydrate.d.ts +55 -6
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.js +21 -20
- package/dist/indexer.d.ts +194 -3
- package/dist/indexer.d.ts.map +1 -1
- package/dist/indexer.js +627 -92
- package/dist/jetstream.d.ts +118 -0
- package/dist/jetstream.d.ts.map +1 -0
- package/dist/jetstream.js +238 -0
- package/dist/labels.d.ts +36 -0
- package/dist/labels.d.ts.map +1 -1
- package/dist/labels.js +71 -6
- package/dist/lex-types.d.ts +2 -0
- package/dist/lex-types.d.ts.map +1 -1
- package/dist/lexicon-resolve.d.ts.map +1 -1
- package/dist/lexicon-resolve.js +27 -112
- package/dist/lexicons/com/atproto/label/defs.json +75 -0
- package/dist/lexicons/com/atproto/moderation/defs.json +30 -0
- package/dist/lexicons/com/atproto/repo/strongRef.json +21 -0
- package/dist/lexicons/dev/hatk/applyWrites.json +87 -0
- package/dist/lexicons/dev/hatk/createRecord.json +40 -0
- package/dist/lexicons/dev/hatk/createReport.json +48 -0
- package/dist/lexicons/dev/hatk/deleteRecord.json +25 -0
- package/dist/lexicons/dev/hatk/describeCollections.json +41 -0
- package/dist/lexicons/dev/hatk/describeFeeds.json +29 -0
- package/dist/lexicons/dev/hatk/describeLabels.json +45 -0
- package/dist/lexicons/dev/hatk/getFeed.json +30 -0
- package/dist/lexicons/dev/hatk/getPreferences.json +19 -0
- package/dist/lexicons/dev/hatk/getRecord.json +26 -0
- package/dist/lexicons/dev/hatk/getRecords.json +32 -0
- package/dist/lexicons/dev/hatk/putPreference.json +28 -0
- package/dist/lexicons/dev/hatk/putRecord.json +41 -0
- package/dist/lexicons/dev/hatk/searchRecords.json +32 -0
- package/dist/lexicons/dev/hatk/uploadBlob.json +23 -0
- package/dist/logger.d.ts +29 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +29 -0
- package/dist/main.js +212 -75
- package/dist/mst.d.ts +15 -0
- package/dist/mst.d.ts.map +1 -1
- package/dist/mst.js +13 -0
- package/dist/oauth/db.d.ts +27 -1
- package/dist/oauth/db.d.ts.map +1 -1
- package/dist/oauth/db.js +80 -19
- package/dist/oauth/discovery.d.ts +10 -0
- package/dist/oauth/discovery.d.ts.map +1 -1
- package/dist/oauth/discovery.js +54 -2
- package/dist/oauth/server.d.ts +131 -1
- package/dist/oauth/server.d.ts.map +1 -1
- package/dist/oauth/server.js +504 -39
- package/dist/oauth/service-describe.d.ts +42 -0
- package/dist/oauth/service-describe.d.ts.map +1 -0
- package/dist/oauth/service-describe.js +108 -0
- package/dist/oauth/session.d.ts +32 -0
- package/dist/oauth/session.d.ts.map +1 -0
- package/dist/oauth/session.js +131 -0
- package/dist/opengraph.d.ts +10 -0
- package/dist/opengraph.d.ts.map +1 -1
- package/dist/opengraph.js +94 -42
- package/dist/pds-proxy.d.ts +92 -0
- package/dist/pds-proxy.d.ts.map +1 -0
- package/dist/pds-proxy.js +396 -0
- package/dist/private-collections.d.ts +13 -0
- package/dist/private-collections.d.ts.map +1 -0
- package/dist/private-collections.js +27 -0
- package/dist/push.d.ts +54 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +367 -0
- package/dist/renderer.d.ts +27 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +46 -0
- package/dist/resolve-hatk.d.ts +6 -0
- package/dist/resolve-hatk.d.ts.map +1 -0
- package/dist/resolve-hatk.js +20 -0
- package/dist/response.d.ts +16 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +69 -0
- package/dist/scanner.d.ts +22 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +92 -0
- package/dist/seed.d.ts +19 -0
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +43 -4
- package/dist/server-init.d.ts +8 -0
- package/dist/server-init.d.ts.map +1 -0
- package/dist/server-init.js +75 -0
- package/dist/server.d.ts +46 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1137 -649
- package/dist/setup.d.ts +28 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +50 -3
- package/dist/spaces/blob.d.ts +112 -0
- package/dist/spaces/blob.d.ts.map +1 -0
- package/dist/spaces/blob.js +460 -0
- package/dist/spaces/credential.d.ts +82 -0
- package/dist/spaces/credential.d.ts.map +1 -0
- package/dist/spaces/credential.js +220 -0
- package/dist/spaces/engine.d.ts +97 -0
- package/dist/spaces/engine.d.ts.map +1 -0
- package/dist/spaces/engine.js +563 -0
- package/dist/spaces/guard.d.ts +41 -0
- package/dist/spaces/guard.d.ts.map +1 -0
- package/dist/spaces/guard.js +79 -0
- package/dist/spaces/identity.d.ts +37 -0
- package/dist/spaces/identity.d.ts.map +1 -0
- package/dist/spaces/identity.js +93 -0
- package/dist/spaces/index.d.ts +56 -0
- package/dist/spaces/index.d.ts.map +1 -0
- package/dist/spaces/index.js +134 -0
- package/dist/spaces/notify.d.ts +60 -0
- package/dist/spaces/notify.d.ts.map +1 -0
- package/dist/spaces/notify.js +128 -0
- package/dist/spaces/records.d.ts +37 -0
- package/dist/spaces/records.d.ts.map +1 -0
- package/dist/spaces/records.js +63 -0
- package/dist/spaces/signature.d.ts +36 -0
- package/dist/spaces/signature.d.ts.map +1 -0
- package/dist/spaces/signature.js +83 -0
- package/dist/spaces/store.d.ts +51 -0
- package/dist/spaces/store.d.ts.map +1 -0
- package/dist/spaces/store.js +99 -0
- package/dist/spaces/uri.d.ts +60 -0
- package/dist/spaces/uri.d.ts.map +1 -0
- package/dist/spaces/uri.js +97 -0
- package/dist/spaces/verify.d.ts +46 -0
- package/dist/spaces/verify.d.ts.map +1 -0
- package/dist/spaces/verify.js +94 -0
- package/dist/spaces/viewer.d.ts +51 -0
- package/dist/spaces/viewer.d.ts.map +1 -0
- package/dist/spaces/viewer.js +167 -0
- package/dist/spaces/visibility.d.ts +57 -0
- package/dist/spaces/visibility.d.ts.map +1 -0
- package/dist/spaces/visibility.js +81 -0
- package/dist/templates/feed.tpl +18 -0
- package/dist/templates/hook.tpl +5 -0
- package/dist/templates/label.tpl +15 -0
- package/dist/templates/og.tpl +17 -0
- package/dist/templates/seed.tpl +11 -0
- package/dist/templates/setup.tpl +5 -0
- package/dist/templates/test-feed.tpl +19 -0
- package/dist/templates/test-xrpc.tpl +19 -0
- package/dist/templates/xrpc.tpl +53 -0
- package/dist/test.d.ts +3 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +60 -36
- package/dist/views.js +1 -1
- package/dist/vite-plugin.d.ts +1 -1
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +254 -66
- package/dist/xrpc.d.ts +143 -12
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +282 -55
- package/package.json +29 -9
- package/public/admin-auth.js +271 -306
- package/public/admin.html +652 -61
- package/dist/db.d.ts +0 -135
- package/dist/db.d.ts.map +0 -1
- package/dist/db.js +0 -1365
- package/dist/fts.d.ts.map +0 -1
- package/dist/oauth/hooks.d.ts +0 -10
- package/dist/oauth/hooks.d.ts.map +0 -1
- package/dist/oauth/hooks.js +0 -40
- package/dist/schema.d.ts +0 -51
- package/dist/schema.d.ts.map +0 -1
- package/dist/test-browser.d.ts +0 -14
- package/dist/test-browser.d.ts.map +0 -1
- package/dist/test-browser.js +0 -26
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.getRecord",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "Fetch a single record by AT URI.",
|
|
8
|
+
"parameters": {
|
|
9
|
+
"type": "params",
|
|
10
|
+
"required": ["uri"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"uri": { "type": "string", "format": "at-uri" }
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"output": {
|
|
16
|
+
"encoding": "application/json",
|
|
17
|
+
"schema": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"record": { "type": "unknown" }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.getRecords",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "List records from a collection with optional filters.",
|
|
8
|
+
"parameters": {
|
|
9
|
+
"type": "params",
|
|
10
|
+
"required": ["collection"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"collection": { "type": "string" },
|
|
13
|
+
"limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 },
|
|
14
|
+
"cursor": { "type": "string" },
|
|
15
|
+
"sort": { "type": "string" },
|
|
16
|
+
"order": { "type": "string" }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"output": {
|
|
20
|
+
"encoding": "application/json",
|
|
21
|
+
"schema": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["items"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"items": { "type": "array", "items": { "type": "unknown" } },
|
|
26
|
+
"cursor": { "type": "string" }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.putPreference",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "procedure",
|
|
7
|
+
"description": "Set a single preference by key.",
|
|
8
|
+
"input": {
|
|
9
|
+
"encoding": "application/json",
|
|
10
|
+
"schema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"required": ["key", "value"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"key": { "type": "string" },
|
|
15
|
+
"value": { "type": "unknown" }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"output": {
|
|
20
|
+
"encoding": "application/json",
|
|
21
|
+
"schema": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"properties": {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.putRecord",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "procedure",
|
|
7
|
+
"description": "Create or update a record via the user's PDS.",
|
|
8
|
+
"input": {
|
|
9
|
+
"encoding": "application/json",
|
|
10
|
+
"schema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"required": ["collection", "rkey", "record"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"collection": { "type": "string" },
|
|
15
|
+
"rkey": { "type": "string" },
|
|
16
|
+
"record": { "type": "unknown" },
|
|
17
|
+
"repo": { "type": "string", "format": "did" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"output": {
|
|
22
|
+
"encoding": "application/json",
|
|
23
|
+
"schema": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"properties": {
|
|
26
|
+
"uri": { "type": "string", "format": "at-uri" },
|
|
27
|
+
"cid": { "type": "string", "format": "cid" },
|
|
28
|
+
"commit": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"properties": {
|
|
31
|
+
"cid": { "type": "string", "format": "cid" },
|
|
32
|
+
"rev": { "type": "string" }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"validationStatus": { "type": "string" }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.searchRecords",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "Full-text search across a collection.",
|
|
8
|
+
"parameters": {
|
|
9
|
+
"type": "params",
|
|
10
|
+
"required": ["collection", "q"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"collection": { "type": "string" },
|
|
13
|
+
"q": { "type": "string", "description": "Search query" },
|
|
14
|
+
"limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 },
|
|
15
|
+
"cursor": { "type": "string" },
|
|
16
|
+
"fuzzy": { "type": "boolean", "default": true }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"output": {
|
|
20
|
+
"encoding": "application/json",
|
|
21
|
+
"schema": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["items"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"items": { "type": "array", "items": { "type": "unknown" } },
|
|
26
|
+
"cursor": { "type": "string" }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.uploadBlob",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "procedure",
|
|
7
|
+
"description": "Upload a blob via the user's PDS.",
|
|
8
|
+
"input": {
|
|
9
|
+
"encoding": "*/*"
|
|
10
|
+
},
|
|
11
|
+
"output": {
|
|
12
|
+
"encoding": "application/json",
|
|
13
|
+
"schema": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"required": ["blob"],
|
|
16
|
+
"properties": {
|
|
17
|
+
"blob": { "type": "blob" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unstructured debug log — use sparingly for human-readable dev output.
|
|
3
|
+
* Prefer {@link emit} for anything that should be queryable in production.
|
|
4
|
+
* Disabled when `DEBUG=0`.
|
|
5
|
+
*/
|
|
1
6
|
export declare function log(...args: unknown[]): void;
|
|
7
|
+
/**
|
|
8
|
+
* Emit a structured wide event as a single JSON line to stdout.
|
|
9
|
+
*
|
|
10
|
+
* Each call produces one canonical log line with a timestamp, module, operation,
|
|
11
|
+
* and arbitrary key-value fields — designed for columnar search and aggregation,
|
|
12
|
+
* not string grep. Pack as much context as possible into `fields` (request IDs,
|
|
13
|
+
* durations, status codes, user DIDs, counts) so a single event tells the full
|
|
14
|
+
* story. See https://loggingsucks.com for the philosophy behind this approach.
|
|
15
|
+
*
|
|
16
|
+
* Disabled when `DEBUG=0`.
|
|
17
|
+
*
|
|
18
|
+
* @param module - Subsystem emitting the event (e.g. "server", "indexer", "backfill")
|
|
19
|
+
* @param op - Operation name (e.g. "request", "commit", "memory")
|
|
20
|
+
* @param fields - High-cardinality key-value context — include everything relevant
|
|
21
|
+
*/
|
|
2
22
|
export declare function emit(module: string, op: string, fields: Record<string, unknown>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Start a millisecond timer. Call the returned function to get elapsed ms.
|
|
25
|
+
* Use with {@link emit} to add `duration_ms` to wide events.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const elapsed = timer()
|
|
29
|
+
* await doWork()
|
|
30
|
+
* emit('server', 'request', { path, status_code, duration_ms: elapsed() })
|
|
31
|
+
*/
|
|
3
32
|
export declare function timer(): () => number;
|
|
4
33
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAG5C;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAWtF;AAED,wBAAgB,KAAK,IAAI,MAAM,MAAM,CAGpC"}
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAG5C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAWtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,IAAI,MAAM,MAAM,CAGpC"}
|
package/dist/logger.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unstructured debug log — use sparingly for human-readable dev output.
|
|
3
|
+
* Prefer {@link emit} for anything that should be queryable in production.
|
|
4
|
+
* Disabled when `DEBUG=0`.
|
|
5
|
+
*/
|
|
1
6
|
export function log(...args) {
|
|
2
7
|
if (process.env.DEBUG === '0')
|
|
3
8
|
return;
|
|
4
9
|
console.log(...args);
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Emit a structured wide event as a single JSON line to stdout.
|
|
13
|
+
*
|
|
14
|
+
* Each call produces one canonical log line with a timestamp, module, operation,
|
|
15
|
+
* and arbitrary key-value fields — designed for columnar search and aggregation,
|
|
16
|
+
* not string grep. Pack as much context as possible into `fields` (request IDs,
|
|
17
|
+
* durations, status codes, user DIDs, counts) so a single event tells the full
|
|
18
|
+
* story. See https://loggingsucks.com for the philosophy behind this approach.
|
|
19
|
+
*
|
|
20
|
+
* Disabled when `DEBUG=0`.
|
|
21
|
+
*
|
|
22
|
+
* @param module - Subsystem emitting the event (e.g. "server", "indexer", "backfill")
|
|
23
|
+
* @param op - Operation name (e.g. "request", "commit", "memory")
|
|
24
|
+
* @param fields - High-cardinality key-value context — include everything relevant
|
|
25
|
+
*/
|
|
6
26
|
export function emit(module, op, fields) {
|
|
7
27
|
if (process.env.DEBUG === '0')
|
|
8
28
|
return;
|
|
@@ -17,6 +37,15 @@ export function emit(module, op, fields) {
|
|
|
17
37
|
}
|
|
18
38
|
process.stdout.write(JSON.stringify(entry) + '\n');
|
|
19
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Start a millisecond timer. Call the returned function to get elapsed ms.
|
|
42
|
+
* Use with {@link emit} to add `duration_ms` to wide events.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const elapsed = timer()
|
|
46
|
+
* await doWork()
|
|
47
|
+
* emit('server', 'request', { path, status_code, duration_ms: elapsed() })
|
|
48
|
+
*/
|
|
20
49
|
export function timer() {
|
|
21
50
|
const start = performance.now();
|
|
22
51
|
return () => Math.round(performance.now() - start);
|
package/dist/main.js
CHANGED
|
@@ -1,32 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
import { mkdirSync, writeFileSync, existsSync } from 'node:fs';
|
|
3
11
|
import { dirname, resolve } from 'node:path';
|
|
12
|
+
import { registerHatkResolveHook } from "./resolve-hatk.js";
|
|
4
13
|
import { log } from "./logger.js";
|
|
5
14
|
import { loadConfig } from "./config.js";
|
|
6
|
-
import { loadLexicons, storeLexicons, discoverCollections,
|
|
15
|
+
import { validatableLexicons, loadLexicons, storeLexicons, discoverCollections, buildSchemas, } from "./database/schema.js";
|
|
7
16
|
import { discoverViews } from "./views.js";
|
|
8
|
-
import { initDatabase, getCursor, querySQL,
|
|
17
|
+
import { initDatabase, getCursor, querySQL, getSqlDialect, getSchemaDump } from "./database/db.js";
|
|
18
|
+
import { createAdapter } from "./database/adapter-factory.js";
|
|
19
|
+
import { getDialect } from "./database/dialect.js";
|
|
20
|
+
import { setSearchPort } from "./database/fts.js";
|
|
9
21
|
import { initFeeds, listFeeds } from "./feeds.js";
|
|
10
|
-
import { initXrpc, listXrpc, configureRelay } from "./xrpc.js";
|
|
22
|
+
import { initXrpc, listXrpc, configureRelay, configureCdn, configureOAuth, callXrpc } from "./xrpc.js";
|
|
11
23
|
import { initOpengraph } from "./opengraph.js";
|
|
12
24
|
import { initLabels, getLabelDefinitions } from "./labels.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
25
|
+
import { initClassifiers, listClassifiers, configureClef, startScoringOnIndex } from "./classifiers.js";
|
|
26
|
+
import { auxCursorKey, jetstreamCursorKey, startAuxIndexer, startIndexer, sweepReferences } from "./indexer.js";
|
|
27
|
+
import { startJetstreamIndexer } from "./jetstream.js";
|
|
28
|
+
import { rebuildAllIndexes } from "./database/fts.js";
|
|
29
|
+
import { createHandler, registerCoreHandlers } from "./server.js";
|
|
30
|
+
import { setPrivateCollections } from "./private-collections.js";
|
|
31
|
+
import { serve } from "./adapter.js";
|
|
16
32
|
import { validateLexicons } from '@bigmoves/lexicon';
|
|
17
33
|
import { relayHttpUrl } from "./config.js";
|
|
18
|
-
import { runBackfill } from "./backfill.js";
|
|
34
|
+
import { runBackfill, configurePlc, configureSkipPds } from "./backfill.js";
|
|
19
35
|
import { initOAuth } from "./oauth/server.js";
|
|
20
|
-
import {
|
|
36
|
+
import { parseSessionCookie, getSessionCookieName } from "./oauth/session.js";
|
|
37
|
+
import { loadOnLoginHook } from "./hooks.js";
|
|
38
|
+
import { enabledPushTransports, initPush, isPushEnabled } from "./push.js";
|
|
21
39
|
import { initSetup } from "./setup.js";
|
|
22
|
-
|
|
40
|
+
import { initServer } from "./server-init.js";
|
|
41
|
+
import { startSpaces } from "./spaces/index.js";
|
|
42
|
+
import { configureSpaceIdentity } from "./spaces/identity.js";
|
|
43
|
+
const configPath = process.argv[2] || 'hatk.config.ts';
|
|
23
44
|
const configDir = dirname(resolve(configPath));
|
|
45
|
+
registerHatkResolveHook();
|
|
24
46
|
// 1. Load config
|
|
25
|
-
const config = loadConfig(configPath);
|
|
47
|
+
const config = await loadConfig(configPath);
|
|
26
48
|
configureRelay(config.relay);
|
|
49
|
+
configurePlc(config.plc);
|
|
50
|
+
configureSkipPds(config.backfill.skipPds);
|
|
51
|
+
// Space reads resolve authorities too, and ctx.spaceCredential works without
|
|
52
|
+
// `spaces` indexing being configured.
|
|
53
|
+
configureSpaceIdentity(config.plc);
|
|
54
|
+
configureCdn(config.cdn);
|
|
27
55
|
// 2. Load lexicons, validate schemas, and discover collections
|
|
28
56
|
const lexicons = loadLexicons(resolve(configDir, 'lexicons'));
|
|
29
|
-
const lexiconErrors = validateLexicons(
|
|
57
|
+
const lexiconErrors = validateLexicons(validatableLexicons(lexicons));
|
|
30
58
|
if (lexiconErrors) {
|
|
31
59
|
for (const [nsid, errors] of Object.entries(lexiconErrors)) {
|
|
32
60
|
for (const err of errors) {
|
|
@@ -44,44 +72,74 @@ if (collections.length === 0) {
|
|
|
44
72
|
log(`[main] Loaded config: ${collections.length} collections`);
|
|
45
73
|
// Discover view defs from lexicons
|
|
46
74
|
discoverViews();
|
|
47
|
-
|
|
48
|
-
const schemas =
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
uri TEXT PRIMARY KEY,
|
|
56
|
-
cid TEXT,
|
|
57
|
-
did TEXT NOT NULL,
|
|
58
|
-
indexed_at TIMESTAMP NOT NULL,
|
|
59
|
-
data JSON
|
|
60
|
-
);
|
|
61
|
-
CREATE INDEX IF NOT EXISTS idx_${nsid.replace(/\./g, '_')}_indexed ON "${nsid}"(indexed_at DESC);
|
|
62
|
-
CREATE INDEX IF NOT EXISTS idx_${nsid.replace(/\./g, '_')}_author ON "${nsid}"(did);`;
|
|
63
|
-
schemas.push({ collection: nsid, tableName: `"${nsid}"`, columns: [], refColumns: [], children: [], unions: [] });
|
|
64
|
-
ddlStatements.push(genericDDL);
|
|
65
|
-
continue;
|
|
75
|
+
const engineDialect = getDialect(config.databaseEngine);
|
|
76
|
+
const { schemas, ddlStatements, indexStatements } = buildSchemas(lexicons, collections, engineDialect);
|
|
77
|
+
for (const s of schemas) {
|
|
78
|
+
if (s.columns.length === 0) {
|
|
79
|
+
log(`[main] No lexicon found for ${s.collection}, using generic JSON storage`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
log(`[main] Schema for ${s.collection}: ${s.columns.length} columns, ${s.unions.length} unions`);
|
|
66
83
|
}
|
|
67
|
-
const schema = generateTableSchema(nsid, lexicon, lexicons);
|
|
68
|
-
schemas.push(schema);
|
|
69
|
-
ddlStatements.push(generateCreateTableSQL(schema));
|
|
70
|
-
log(`[main] Schema for ${nsid}: ${schema.columns.length} columns, ${schema.unions.length} unions`);
|
|
71
84
|
}
|
|
72
|
-
// 3. Ensure data directory exists and initialize
|
|
85
|
+
// 3. Ensure data directory exists and initialize database
|
|
73
86
|
if (config.database !== ':memory:') {
|
|
74
87
|
mkdirSync(dirname(config.database), { recursive: true });
|
|
75
88
|
}
|
|
76
|
-
await
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
await
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
const { adapter, searchPort } = await createAdapter(config.databaseEngine);
|
|
90
|
+
setSearchPort(searchPort);
|
|
91
|
+
// Migrates as part of opening, between creating the tables and indexing them.
|
|
92
|
+
const migrationChanges = await initDatabase(adapter, config.database, schemas, ddlStatements, indexStatements);
|
|
93
|
+
log(`[main] Database initialized (${config.databaseEngine}, ${config.database === ':memory:' ? 'in-memory' : config.database})`);
|
|
94
|
+
if (migrationChanges.length > 0) {
|
|
95
|
+
log(`[main] Applied ${migrationChanges.length} schema migration(s)`);
|
|
96
|
+
}
|
|
97
|
+
// 3b. Run setup hooks, feeds, xrpc, og, labels
|
|
98
|
+
const serverDir = resolve(configDir, 'server');
|
|
99
|
+
if (existsSync(serverDir)) {
|
|
100
|
+
// New: single server/ directory
|
|
101
|
+
await initServer(serverDir);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Legacy: separate directories
|
|
105
|
+
await initSetup(resolve(configDir, 'setup'));
|
|
106
|
+
await loadOnLoginHook(resolve(configDir, 'hooks'));
|
|
107
|
+
await initFeeds(resolve(configDir, 'feeds'));
|
|
108
|
+
log(`[main] Feeds initialized: ${listFeeds()
|
|
109
|
+
.map((f) => f.name)
|
|
110
|
+
.join(', ') || 'none'}`);
|
|
111
|
+
await initXrpc(resolve(configDir, 'xrpc'));
|
|
112
|
+
log(`[main] XRPC handlers initialized: ${listXrpc().join(', ') || 'none'}`);
|
|
113
|
+
await initOpengraph(resolve(configDir, 'og'));
|
|
114
|
+
log(`[main] OpenGraph initialized`);
|
|
115
|
+
await initLabels(resolve(configDir, 'labels'));
|
|
116
|
+
log(`[main] Labels initialized: ${getLabelDefinitions().length} definitions`);
|
|
117
|
+
await initClassifiers(resolve(configDir, 'classifiers'));
|
|
118
|
+
log(`[main] Classifiers initialized: ${listClassifiers().join(', ') || 'none'}`);
|
|
119
|
+
}
|
|
120
|
+
// Register built-in dev.hatk.* handlers so callXrpc() can find them
|
|
121
|
+
configureClef(config.clef && {
|
|
122
|
+
apiToken: config.clef.apiToken,
|
|
123
|
+
model: config.clef.model,
|
|
124
|
+
endpoint: `https://api.cloudflare.com/client/v4/accounts/${config.clef.accountId}/ai/run/@cf/cloudflare/${config.clef.model}`,
|
|
125
|
+
});
|
|
126
|
+
if (config.clef?.scoreOnIndex && listClassifiers().length)
|
|
127
|
+
await startScoringOnIndex();
|
|
128
|
+
setPrivateCollections(config.privateCollections);
|
|
129
|
+
registerCoreHandlers(collections, config.oauth);
|
|
130
|
+
configureOAuth(config.oauth);
|
|
131
|
+
// Write db/schema.sql (after setup, so setup-created tables are included)
|
|
132
|
+
try {
|
|
133
|
+
const schemaDir = resolve(configDir, 'db');
|
|
134
|
+
mkdirSync(schemaDir, { recursive: true });
|
|
135
|
+
const schemaDump = await getSchemaDump();
|
|
136
|
+
writeFileSync(resolve(schemaDir, 'schema.sql'), `-- This file is auto-generated by hatk on startup. Do not edit.\n-- Database engine: ${config.databaseEngine}\n\n${schemaDump}\n`);
|
|
137
|
+
log(`[main] Schema written to db/schema.sql`);
|
|
138
|
+
}
|
|
139
|
+
catch { }
|
|
82
140
|
// Detect orphaned tables
|
|
83
141
|
try {
|
|
84
|
-
const existingTables = await querySQL(
|
|
142
|
+
const existingTables = (await querySQL(getSqlDialect().listTablesQuery));
|
|
85
143
|
for (const row of existingTables) {
|
|
86
144
|
const tableName = row.table_name;
|
|
87
145
|
const isChildTable = collections.some((c) => tableName.startsWith(c + '__'));
|
|
@@ -91,24 +149,78 @@ try {
|
|
|
91
149
|
}
|
|
92
150
|
}
|
|
93
151
|
catch { }
|
|
94
|
-
// 4. Initialize feeds, xrpc handlers, og, labels from directories
|
|
95
|
-
await initFeeds(resolve(configDir, 'feeds'));
|
|
96
|
-
log(`[main] Feeds initialized: ${listFeeds()
|
|
97
|
-
.map((f) => f.name)
|
|
98
|
-
.join(', ') || 'none'}`);
|
|
99
|
-
await initXrpc(resolve(configDir, 'xrpc'));
|
|
100
|
-
log(`[main] XRPC handlers initialized: ${listXrpc().join(', ') || 'none'}`);
|
|
101
|
-
await initOpengraph(resolve(configDir, 'og'));
|
|
102
|
-
log(`[main] OpenGraph initialized`);
|
|
103
|
-
await initLabels(resolve(configDir, 'labels'));
|
|
104
|
-
log(`[main] Labels initialized: ${getLabelDefinitions().length} definitions`);
|
|
105
152
|
if (config.oauth) {
|
|
106
153
|
await initOAuth(config.oauth, config.plc, config.relay);
|
|
107
154
|
log(`[main] OAuth initialized (issuer: ${config.oauth.issuer})`);
|
|
108
155
|
}
|
|
156
|
+
if (config.push) {
|
|
157
|
+
initPush(config.push, configDir);
|
|
158
|
+
if (isPushEnabled()) {
|
|
159
|
+
log(`[main] Push initialized (${enabledPushTransports().join(', ')})`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
log(`[main] Push configured but no usable credential — push disabled`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
109
165
|
// 5. Start server immediately (don't wait for backfill)
|
|
110
166
|
const collectionSet = new Set(collections);
|
|
111
|
-
|
|
167
|
+
const backfillOpts = {
|
|
168
|
+
pdsUrl: relayHttpUrl(config.relay),
|
|
169
|
+
extraPdsUrls: config.relays.map(relayHttpUrl),
|
|
170
|
+
plcUrl: config.plc,
|
|
171
|
+
collections: collectionSet,
|
|
172
|
+
config: config.backfill,
|
|
173
|
+
};
|
|
174
|
+
function runBackfillAndRestart() {
|
|
175
|
+
runBackfill(backfillOpts)
|
|
176
|
+
.then(async (recordCount) => {
|
|
177
|
+
log('[main] Backfill complete, building FTS indexes...');
|
|
178
|
+
await rebuildAllIndexes(collections);
|
|
179
|
+
log('[main] FTS indexes ready');
|
|
180
|
+
return recordCount;
|
|
181
|
+
})
|
|
182
|
+
.then((recordCount) => {
|
|
183
|
+
if (recordCount > 0 && !process.env.DEV_MODE) {
|
|
184
|
+
log('[main] Restarting to reclaim memory...');
|
|
185
|
+
process.exit(1);
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
.catch((err) => {
|
|
189
|
+
console.error('[main] Backfill error:', err.message);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const handler = createHandler({
|
|
193
|
+
collections,
|
|
194
|
+
publicDir: config.publicDir,
|
|
195
|
+
oauth: config.oauth,
|
|
196
|
+
admins: config.admins,
|
|
197
|
+
adminToken: config.adminToken,
|
|
198
|
+
onResync: runBackfillAndRestart,
|
|
199
|
+
...(config.spaces?.serviceDid
|
|
200
|
+
? {
|
|
201
|
+
spaces: {
|
|
202
|
+
serviceDid: config.spaces.serviceDid,
|
|
203
|
+
serviceFragment: config.spaces.serviceFragment ?? 'atproto_space_syncer',
|
|
204
|
+
// The origin an authority delivers to. The OAuth issuer is already
|
|
205
|
+
// the public origin an operator has had to get right, so it is the
|
|
206
|
+
// honest default rather than a second thing to configure wrong.
|
|
207
|
+
...(config.oauth?.issuer ? { publicUrl: config.oauth.issuer } : {}),
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
: {}),
|
|
211
|
+
});
|
|
212
|
+
globalThis.__hatk_callXrpc = callXrpc;
|
|
213
|
+
globalThis.__hatk_parseSessionCookie = parseSessionCookie;
|
|
214
|
+
globalThis.__hatk_sessionCookieName = getSessionCookieName();
|
|
215
|
+
// Detect SvelteKit build output and use it as fallback handler
|
|
216
|
+
let fallback = undefined;
|
|
217
|
+
const sveltekitHandler = resolve(configDir, 'build', 'handler.js');
|
|
218
|
+
if (existsSync(sveltekitHandler)) {
|
|
219
|
+
const sk = await import(__rewriteRelativeImportExtension(/* @vite-ignore */ sveltekitHandler));
|
|
220
|
+
fallback = sk.handler;
|
|
221
|
+
log(`[main] SvelteKit handler loaded from build/handler.js`);
|
|
222
|
+
}
|
|
223
|
+
serve(handler, config.port, undefined, fallback);
|
|
112
224
|
log(`\nhatk running:`);
|
|
113
225
|
log(` Relay: ${config.relay}`);
|
|
114
226
|
log(` Database: ${config.database}`);
|
|
@@ -118,32 +230,57 @@ log(` Feeds: ${listFeeds()
|
|
|
118
230
|
.map((f) => f.name)
|
|
119
231
|
.join(', ')}`);
|
|
120
232
|
// 6. Start indexer with cursor
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
233
|
+
// HATK_IGNORE_SAVED_CURSOR=1 boots from the live firehose instead of the saved
|
|
234
|
+
// cursor — the escape hatch when a stale cursor would make the relay replay its
|
|
235
|
+
// retention window at line rate (see checkpointCursor in indexer.ts). Unset it
|
|
236
|
+
// after one boot so later restarts resume normally.
|
|
237
|
+
const ignoreSavedCursor = Boolean(process.env.HATK_IGNORE_SAVED_CURSOR);
|
|
238
|
+
if (ignoreSavedCursor)
|
|
239
|
+
log('[main] HATK_IGNORE_SAVED_CURSOR set — starting indexer from live');
|
|
240
|
+
// Each source keeps its own cursor row: relay seqs and Jetstream seqs are
|
|
241
|
+
// different coordinate systems, so switching sources must not resume one from
|
|
242
|
+
// the other's value.
|
|
243
|
+
const indexerCore = {
|
|
244
|
+
plcUrl: config.plc,
|
|
124
245
|
collections: collectionSet,
|
|
125
246
|
signalCollections: config.backfill.signalCollections ? new Set(config.backfill.signalCollections) : undefined,
|
|
247
|
+
references: config.backfill.references,
|
|
126
248
|
pinnedRepos: config.backfill.repos ? new Set(config.backfill.repos) : undefined,
|
|
127
|
-
cursor,
|
|
128
249
|
fetchTimeout: config.backfill.fetchTimeout,
|
|
129
250
|
maxRetries: config.backfill.maxRetries,
|
|
130
251
|
parallelism: config.backfill.parallelism,
|
|
131
252
|
ftsRebuildInterval: config.ftsRebuildInterval,
|
|
132
|
-
}
|
|
253
|
+
};
|
|
254
|
+
if (config.jetstream) {
|
|
255
|
+
const cursor = ignoreSavedCursor ? null : await getCursor(jetstreamCursorKey(config.jetstream.url));
|
|
256
|
+
startJetstreamIndexer({ ...indexerCore, jetstreamUrl: config.jetstream.url, cursor });
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const cursor = ignoreSavedCursor ? null : await getCursor('relay');
|
|
260
|
+
startIndexer({ ...indexerCore, relayUrl: config.relay, cursor });
|
|
261
|
+
for (const relayUrl of config.relays) {
|
|
262
|
+
const auxCursor = ignoreSavedCursor ? null : await getCursor(auxCursorKey(relayUrl));
|
|
263
|
+
startAuxIndexer({ relayUrl, collections: collectionSet, cursor: auxCursor });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// What is already indexed may name repos too; a reference configured after
|
|
267
|
+
// the fact reaches them here rather than on their next write.
|
|
268
|
+
void sweepReferences();
|
|
133
269
|
// 7. Run backfill in background
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
270
|
+
runBackfillAndRestart();
|
|
271
|
+
// 8. Follow permissioned spaces, if this instance indexes any. Started after
|
|
272
|
+
// the firehose and backfill because it is neither: a space has no stream to
|
|
273
|
+
// tail, so it is a sweep on a timer rather than a source to resume.
|
|
274
|
+
if (config.spaces) {
|
|
275
|
+
startSpaces({
|
|
276
|
+
spaces: config.spaces,
|
|
277
|
+
oauth: config.oauth,
|
|
278
|
+
plc: config.plc,
|
|
279
|
+
collections: collectionSet,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// Graceful shutdown
|
|
283
|
+
process.on('SIGTERM', () => {
|
|
284
|
+
log('[main] Received SIGTERM, shutting down...');
|
|
285
|
+
process.exit(0);
|
|
149
286
|
});
|
package/dist/mst.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
/** A single entry from a Merkle Search Tree — a record path paired with its content CID. */
|
|
1
2
|
export interface MstEntry {
|
|
3
|
+
/** Record path, e.g. "xyz.marketplace.listing/3mfniulnr7c2g" */
|
|
2
4
|
path: string;
|
|
5
|
+
/** CID of the record's CBOR block */
|
|
3
6
|
cid: string;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Walk an AT Protocol Merkle Search Tree (MST) in key order, yielding every record entry.
|
|
10
|
+
*
|
|
11
|
+
* The MST is a prefix-compressed B+ tree used by AT Protocol repositories to map
|
|
12
|
+
* record paths to CIDs. Each node contains a left subtree pointer, an array of entries
|
|
13
|
+
* (each with a prefix length, key suffix, value CID, and right subtree pointer), and
|
|
14
|
+
* keys are reconstructed by combining the prefix of the previous key with the suffix.
|
|
15
|
+
*
|
|
16
|
+
* @param blocks - Block store that resolves CIDs to raw CBOR bytes
|
|
17
|
+
* @param rootCid - CID of the MST root node
|
|
18
|
+
* @yields {MstEntry} Record entries in lexicographic key order
|
|
19
|
+
*/
|
|
5
20
|
export declare function walkMst(blocks: {
|
|
6
21
|
get(cid: string): Uint8Array | undefined;
|
|
7
22
|
}, rootCid: string): Generator<MstEntry>;
|
package/dist/mst.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mst.d.ts","sourceRoot":"","sources":["../src/mst.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,wBAAiB,OAAO,CAAC,MAAM,EAAE;IAAE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"mst.d.ts","sourceRoot":"","sources":["../src/mst.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,WAAW,QAAQ;IACvB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;;;;;;;;;GAWG;AACH,wBAAiB,OAAO,CAAC,MAAM,EAAE;IAAE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CA+BnH"}
|