@hatk/hatk 0.0.1-alpha.6 → 0.0.1-alpha.60
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 +108 -0
- package/dist/backfill.d.ts +2 -2
- package/dist/backfill.d.ts.map +1 -1
- package/dist/backfill.js +78 -31
- package/dist/car.d.ts +42 -10
- package/dist/car.d.ts.map +1 -1
- package/dist/car.js +154 -14
- package/dist/cli.js +243 -1043
- package/dist/config.d.ts +31 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +40 -9
- 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 +23 -0
- package/dist/database/adapters/sqlite-search.d.ts.map +1 -0
- package/dist/database/adapters/sqlite-search.js +74 -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/{db.d.ts → database/db.d.ts} +57 -6
- package/dist/database/db.d.ts.map +1 -0
- package/dist/{db.js → database/db.js} +730 -549
- 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} +116 -32
- 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/{schema.d.ts → database/schema.d.ts} +14 -3
- package/dist/database/schema.d.ts.map +1 -0
- package/dist/{schema.js → database/schema.js} +81 -41
- package/dist/dev-entry.d.ts +8 -0
- package/dist/dev-entry.d.ts.map +1 -0
- package/dist/dev-entry.js +112 -0
- package/dist/feeds.d.ts +12 -8
- package/dist/feeds.d.ts.map +1 -1
- package/dist/feeds.js +51 -6
- package/dist/hooks.d.ts +85 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +161 -0
- package/dist/hydrate.d.ts +7 -6
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.js +4 -16
- package/dist/indexer.d.ts +22 -0
- package/dist/indexer.d.ts.map +1 -1
- package/dist/indexer.js +123 -32
- package/dist/labels.d.ts +36 -0
- package/dist/labels.d.ts.map +1 -1
- package/dist/labels.js +71 -6
- 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 +24 -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 +137 -67
- package/dist/mst.d.ts +18 -1
- package/dist/mst.d.ts.map +1 -1
- package/dist/mst.js +19 -8
- package/dist/oauth/db.d.ts +3 -1
- package/dist/oauth/db.d.ts.map +1 -1
- package/dist/oauth/db.js +48 -19
- package/dist/oauth/server.d.ts +24 -0
- package/dist/oauth/server.d.ts.map +1 -1
- package/dist/oauth/server.js +198 -22
- package/dist/oauth/session.d.ts +11 -0
- package/dist/oauth/session.d.ts.map +1 -0
- package/dist/oauth/session.js +65 -0
- package/dist/opengraph.d.ts +10 -0
- package/dist/opengraph.d.ts.map +1 -1
- package/dist/opengraph.js +80 -40
- package/dist/pds-proxy.d.ts +60 -0
- package/dist/pds-proxy.d.ts.map +1 -0
- package/dist/pds-proxy.js +277 -0
- package/dist/push.d.ts +34 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +184 -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 +21 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +88 -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 +62 -0
- package/dist/server.d.ts +26 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +629 -635
- package/dist/setup.d.ts +28 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +50 -3
- package/dist/templates/feed.tpl +14 -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 +41 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +39 -32
- 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 +75 -11
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +189 -39
- package/package.json +14 -7
- package/public/admin.html +133 -54
- package/dist/db.d.ts.map +0 -1
- 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.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,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.describeFeeds",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "List available feeds.",
|
|
8
|
+
"output": {
|
|
9
|
+
"encoding": "application/json",
|
|
10
|
+
"schema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"properties": {
|
|
13
|
+
"feeds": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"items": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"required": ["name", "label"],
|
|
18
|
+
"properties": {
|
|
19
|
+
"name": { "type": "string" },
|
|
20
|
+
"label": { "type": "string" }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.describeLabels",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "List available label definitions.",
|
|
8
|
+
"output": {
|
|
9
|
+
"encoding": "application/json",
|
|
10
|
+
"schema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"properties": {
|
|
13
|
+
"definitions": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"items": { "type": "ref", "ref": "#labelDefinition" }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"labelDefinition": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["identifier", "severity", "blurs", "defaultSetting"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"identifier": { "type": "string" },
|
|
26
|
+
"severity": { "type": "string" },
|
|
27
|
+
"blurs": { "type": "string" },
|
|
28
|
+
"defaultSetting": { "type": "string" },
|
|
29
|
+
"locales": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"items": { "type": "ref", "ref": "#labelLocale" }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"labelLocale": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"required": ["lang", "name", "description"],
|
|
38
|
+
"properties": {
|
|
39
|
+
"lang": { "type": "string" },
|
|
40
|
+
"name": { "type": "string" },
|
|
41
|
+
"description": { "type": "string" }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.getFeed",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "Retrieve a named feed of items.",
|
|
8
|
+
"parameters": {
|
|
9
|
+
"type": "params",
|
|
10
|
+
"required": ["feed"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"feed": { "type": "string", "description": "Feed name" },
|
|
13
|
+
"limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 30 },
|
|
14
|
+
"cursor": { "type": "string" }
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"output": {
|
|
18
|
+
"encoding": "application/json",
|
|
19
|
+
"schema": {
|
|
20
|
+
"type": "object",
|
|
21
|
+
"required": ["items"],
|
|
22
|
+
"properties": {
|
|
23
|
+
"items": { "type": "array", "items": { "type": "unknown" } },
|
|
24
|
+
"cursor": { "type": "string" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lexicon": 1,
|
|
3
|
+
"id": "dev.hatk.getPreferences",
|
|
4
|
+
"defs": {
|
|
5
|
+
"main": {
|
|
6
|
+
"type": "query",
|
|
7
|
+
"description": "Get all preferences for the authenticated user.",
|
|
8
|
+
"output": {
|
|
9
|
+
"encoding": "application/json",
|
|
10
|
+
"schema": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"properties": {
|
|
13
|
+
"preferences": { "type": "unknown" }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -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,29 +1,47 @@
|
|
|
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 { 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, migrateSchema } 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
25
|
import { startIndexer } from "./indexer.js";
|
|
14
|
-
import { rebuildAllIndexes } from "./fts.js";
|
|
15
|
-
import {
|
|
26
|
+
import { rebuildAllIndexes } from "./database/fts.js";
|
|
27
|
+
import { createHandler, registerCoreHandlers } from "./server.js";
|
|
28
|
+
import { serve } from "./adapter.js";
|
|
16
29
|
import { validateLexicons } from '@bigmoves/lexicon';
|
|
17
30
|
import { relayHttpUrl } from "./config.js";
|
|
18
31
|
import { runBackfill } from "./backfill.js";
|
|
19
32
|
import { initOAuth } from "./oauth/server.js";
|
|
20
|
-
import {
|
|
33
|
+
import { parseSessionCookie, getSessionCookieName } from "./oauth/session.js";
|
|
34
|
+
import { loadOnLoginHook } from "./hooks.js";
|
|
35
|
+
import { initPush, isPushEnabled } from "./push.js";
|
|
21
36
|
import { initSetup } from "./setup.js";
|
|
22
|
-
|
|
37
|
+
import { initServer } from "./server-init.js";
|
|
38
|
+
const configPath = process.argv[2] || 'hatk.config.ts';
|
|
23
39
|
const configDir = dirname(resolve(configPath));
|
|
40
|
+
registerHatkResolveHook();
|
|
24
41
|
// 1. Load config
|
|
25
|
-
const config = loadConfig(configPath);
|
|
42
|
+
const config = await loadConfig(configPath);
|
|
26
43
|
configureRelay(config.relay);
|
|
44
|
+
configureCdn(config.cdn);
|
|
27
45
|
// 2. Load lexicons, validate schemas, and discover collections
|
|
28
46
|
const lexicons = loadLexicons(resolve(configDir, 'lexicons'));
|
|
29
47
|
const lexiconErrors = validateLexicons([...lexicons.values()]);
|
|
@@ -44,44 +62,65 @@ if (collections.length === 0) {
|
|
|
44
62
|
log(`[main] Loaded config: ${collections.length} collections`);
|
|
45
63
|
// Discover view defs from lexicons
|
|
46
64
|
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;
|
|
65
|
+
const engineDialect = getDialect(config.databaseEngine);
|
|
66
|
+
const { schemas, ddlStatements } = buildSchemas(lexicons, collections, engineDialect);
|
|
67
|
+
for (const s of schemas) {
|
|
68
|
+
if (s.columns.length === 0) {
|
|
69
|
+
log(`[main] No lexicon found for ${s.collection}, using generic JSON storage`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
log(`[main] Schema for ${s.collection}: ${s.columns.length} columns, ${s.unions.length} unions`);
|
|
66
73
|
}
|
|
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
74
|
}
|
|
72
|
-
// 3. Ensure data directory exists and initialize
|
|
75
|
+
// 3. Ensure data directory exists and initialize database
|
|
73
76
|
if (config.database !== ':memory:') {
|
|
74
77
|
mkdirSync(dirname(config.database), { recursive: true });
|
|
75
78
|
}
|
|
76
|
-
await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
await
|
|
79
|
+
const { adapter, searchPort } = await createAdapter(config.databaseEngine);
|
|
80
|
+
setSearchPort(searchPort);
|
|
81
|
+
await initDatabase(adapter, config.database, schemas, ddlStatements);
|
|
82
|
+
log(`[main] Database initialized (${config.databaseEngine}, ${config.database === ':memory:' ? 'in-memory' : config.database})`);
|
|
83
|
+
// Auto-migrate schema if lexicons changed
|
|
84
|
+
const migrationChanges = await migrateSchema(schemas);
|
|
85
|
+
if (migrationChanges.length > 0) {
|
|
86
|
+
log(`[main] Applied ${migrationChanges.length} schema migration(s)`);
|
|
87
|
+
}
|
|
88
|
+
// 3b. Run setup hooks, feeds, xrpc, og, labels
|
|
89
|
+
const serverDir = resolve(configDir, 'server');
|
|
90
|
+
if (existsSync(serverDir)) {
|
|
91
|
+
// New: single server/ directory
|
|
92
|
+
await initServer(serverDir);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Legacy: separate directories
|
|
96
|
+
await initSetup(resolve(configDir, 'setup'));
|
|
97
|
+
await loadOnLoginHook(resolve(configDir, 'hooks'));
|
|
98
|
+
await initFeeds(resolve(configDir, 'feeds'));
|
|
99
|
+
log(`[main] Feeds initialized: ${listFeeds()
|
|
100
|
+
.map((f) => f.name)
|
|
101
|
+
.join(', ') || 'none'}`);
|
|
102
|
+
await initXrpc(resolve(configDir, 'xrpc'));
|
|
103
|
+
log(`[main] XRPC handlers initialized: ${listXrpc().join(', ') || 'none'}`);
|
|
104
|
+
await initOpengraph(resolve(configDir, 'og'));
|
|
105
|
+
log(`[main] OpenGraph initialized`);
|
|
106
|
+
await initLabels(resolve(configDir, 'labels'));
|
|
107
|
+
log(`[main] Labels initialized: ${getLabelDefinitions().length} definitions`);
|
|
108
|
+
}
|
|
109
|
+
// Register built-in dev.hatk.* handlers so callXrpc() can find them
|
|
110
|
+
registerCoreHandlers(collections, config.oauth);
|
|
111
|
+
configureOAuth(config.oauth);
|
|
112
|
+
// Write db/schema.sql (after setup, so setup-created tables are included)
|
|
113
|
+
try {
|
|
114
|
+
const schemaDir = resolve(configDir, 'db');
|
|
115
|
+
mkdirSync(schemaDir, { recursive: true });
|
|
116
|
+
const schemaDump = await getSchemaDump();
|
|
117
|
+
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`);
|
|
118
|
+
log(`[main] Schema written to db/schema.sql`);
|
|
119
|
+
}
|
|
120
|
+
catch { }
|
|
82
121
|
// Detect orphaned tables
|
|
83
122
|
try {
|
|
84
|
-
const existingTables = await querySQL(
|
|
123
|
+
const existingTables = (await querySQL(getSqlDialect().listTablesQuery));
|
|
85
124
|
for (const row of existingTables) {
|
|
86
125
|
const tableName = row.table_name;
|
|
87
126
|
const isChildTable = collections.some((c) => tableName.startsWith(c + '__'));
|
|
@@ -91,24 +130,64 @@ try {
|
|
|
91
130
|
}
|
|
92
131
|
}
|
|
93
132
|
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
133
|
if (config.oauth) {
|
|
106
134
|
await initOAuth(config.oauth, config.plc, config.relay);
|
|
107
135
|
log(`[main] OAuth initialized (issuer: ${config.oauth.issuer})`);
|
|
108
136
|
}
|
|
137
|
+
if (config.push) {
|
|
138
|
+
initPush(config.push, configDir);
|
|
139
|
+
if (isPushEnabled()) {
|
|
140
|
+
log(`[main] Push initialized (APNs bundle: ${config.push.apns.bundleId})`);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
log(`[main] Push configured but key file missing — push disabled`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
109
146
|
// 5. Start server immediately (don't wait for backfill)
|
|
110
147
|
const collectionSet = new Set(collections);
|
|
111
|
-
|
|
148
|
+
const backfillOpts = {
|
|
149
|
+
pdsUrl: relayHttpUrl(config.relay),
|
|
150
|
+
plcUrl: config.plc,
|
|
151
|
+
collections: collectionSet,
|
|
152
|
+
config: config.backfill,
|
|
153
|
+
};
|
|
154
|
+
function runBackfillAndRestart() {
|
|
155
|
+
runBackfill(backfillOpts)
|
|
156
|
+
.then(async (recordCount) => {
|
|
157
|
+
log('[main] Backfill complete, building FTS indexes...');
|
|
158
|
+
await rebuildAllIndexes(collections);
|
|
159
|
+
log('[main] FTS indexes ready');
|
|
160
|
+
return recordCount;
|
|
161
|
+
})
|
|
162
|
+
.then((recordCount) => {
|
|
163
|
+
if (recordCount > 0 && !process.env.DEV_MODE) {
|
|
164
|
+
log('[main] Restarting to reclaim memory...');
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
.catch((err) => {
|
|
169
|
+
console.error('[main] Backfill error:', err.message);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const handler = createHandler({
|
|
173
|
+
collections,
|
|
174
|
+
publicDir: config.publicDir,
|
|
175
|
+
oauth: config.oauth,
|
|
176
|
+
admins: config.admins,
|
|
177
|
+
onResync: runBackfillAndRestart,
|
|
178
|
+
});
|
|
179
|
+
globalThis.__hatk_callXrpc = callXrpc;
|
|
180
|
+
globalThis.__hatk_parseSessionCookie = parseSessionCookie;
|
|
181
|
+
globalThis.__hatk_sessionCookieName = getSessionCookieName();
|
|
182
|
+
// Detect SvelteKit build output and use it as fallback handler
|
|
183
|
+
let fallback = undefined;
|
|
184
|
+
const sveltekitHandler = resolve(configDir, 'build', 'handler.js');
|
|
185
|
+
if (existsSync(sveltekitHandler)) {
|
|
186
|
+
const sk = await import(__rewriteRelativeImportExtension(/* @vite-ignore */ sveltekitHandler));
|
|
187
|
+
fallback = sk.handler;
|
|
188
|
+
log(`[main] SvelteKit handler loaded from build/handler.js`);
|
|
189
|
+
}
|
|
190
|
+
serve(handler, config.port, undefined, fallback);
|
|
112
191
|
log(`\nhatk running:`);
|
|
113
192
|
log(` Relay: ${config.relay}`);
|
|
114
193
|
log(` Database: ${config.database}`);
|
|
@@ -127,22 +206,13 @@ startIndexer({
|
|
|
127
206
|
cursor,
|
|
128
207
|
fetchTimeout: config.backfill.fetchTimeout,
|
|
129
208
|
maxRetries: config.backfill.maxRetries,
|
|
209
|
+
parallelism: config.backfill.parallelism,
|
|
130
210
|
ftsRebuildInterval: config.ftsRebuildInterval,
|
|
131
211
|
});
|
|
132
212
|
// 7. Run backfill in background
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
-
.then(() => {
|
|
140
|
-
log('[main] Backfill complete, rebuilding FTS indexes...');
|
|
141
|
-
return rebuildAllIndexes(collections);
|
|
142
|
-
})
|
|
143
|
-
.then(() => {
|
|
144
|
-
log('[main] FTS indexes ready');
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
console.error('[main] Backfill error:', err.message);
|
|
213
|
+
runBackfillAndRestart();
|
|
214
|
+
// Graceful shutdown
|
|
215
|
+
process.on('SIGTERM', () => {
|
|
216
|
+
log('[main] Received SIGTERM, shutting down...');
|
|
217
|
+
process.exit(0);
|
|
148
218
|
});
|