@hatk/hatk 0.0.1-alpha.4 → 0.0.1-alpha.40
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 +107 -0
- package/dist/backfill.d.ts +60 -1
- package/dist/backfill.d.ts.map +1 -1
- package/dist/backfill.js +167 -33
- package/dist/car.d.ts +59 -1
- package/dist/car.d.ts.map +1 -1
- package/dist/car.js +179 -7
- package/dist/cbor.d.ts +37 -0
- package/dist/cbor.d.ts.map +1 -1
- package/dist/cbor.js +36 -3
- package/dist/cid.d.ts +37 -0
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.js +38 -3
- package/dist/cli.js +417 -133
- package/dist/cloudflare/container.d.ts +73 -0
- package/dist/cloudflare/container.d.ts.map +1 -0
- package/dist/cloudflare/container.js +232 -0
- package/dist/cloudflare/hooks.d.ts +33 -0
- package/dist/cloudflare/hooks.d.ts.map +1 -0
- package/dist/cloudflare/hooks.js +40 -0
- package/dist/cloudflare/init.d.ts +27 -0
- package/dist/cloudflare/init.d.ts.map +1 -0
- package/dist/cloudflare/init.js +103 -0
- package/dist/cloudflare/worker.d.ts +27 -0
- package/dist/cloudflare/worker.d.ts.map +1 -0
- package/dist/cloudflare/worker.js +54 -0
- package/dist/config.d.ts +12 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +36 -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/d1.d.ts +56 -0
- package/dist/database/adapters/d1.d.ts.map +1 -0
- package/dist/database/adapters/d1.js +108 -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 +87 -0
- package/dist/database/db.d.ts +159 -0
- package/dist/database/db.d.ts.map +1 -0
- package/dist/database/db.js +1445 -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/database/fts.d.ts +27 -0
- package/dist/database/fts.d.ts.map +1 -0
- package/dist/database/fts.js +846 -0
- 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 +61 -0
- package/dist/database/schema.d.ts.map +1 -0
- package/dist/database/schema.js +394 -0
- package/dist/db.d.ts +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +4 -38
- package/dist/dev-entry.d.ts +8 -0
- package/dist/dev-entry.d.ts.map +1 -0
- package/dist/dev-entry.js +110 -0
- package/dist/feeds.d.ts +12 -8
- package/dist/feeds.d.ts.map +1 -1
- package/dist/feeds.js +45 -6
- package/dist/fts.d.ts.map +1 -1
- package/dist/fts.js +5 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +75 -0
- package/dist/hydrate.d.ts +6 -5
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.js +4 -16
- package/dist/indexer.d.ts +20 -0
- package/dist/indexer.d.ts.map +1 -1
- package/dist/indexer.js +53 -7
- package/dist/labels.d.ts +34 -0
- package/dist/labels.d.ts.map +1 -1
- package/dist/labels.js +66 -6
- 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 +134 -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.map +1 -1
- package/dist/oauth/db.js +43 -17
- package/dist/oauth/server.d.ts +2 -0
- package/dist/oauth/server.d.ts.map +1 -1
- package/dist/oauth/server.js +102 -7
- 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 +73 -39
- package/dist/pds-proxy.d.ts +42 -0
- package/dist/pds-proxy.d.ts.map +1 -0
- package/dist/pds-proxy.js +189 -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/schema.d.ts +8 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +29 -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 +61 -0
- package/dist/server.d.ts +26 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +528 -635
- package/dist/setup.d.ts +28 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +50 -3
- package/dist/test.d.ts +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +38 -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 +46 -10
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +128 -39
- package/package.json +13 -6
- package/public/admin.html +0 -54
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Container entry point for hatk.
|
|
3
|
+
*
|
|
4
|
+
* Runs as a long-lived Node.js process alongside the Worker. Handles the
|
|
5
|
+
* firehose indexer and backfill loop — the Worker delegates resync requests
|
|
6
|
+
* here via RPC (Cloudflare Container service bindings).
|
|
7
|
+
*
|
|
8
|
+
* No HTTP server — all communication is via the Container RPC interface.
|
|
9
|
+
*/
|
|
10
|
+
export interface Env {
|
|
11
|
+
/** Cloudflare D1 database binding */
|
|
12
|
+
DB: D1Database;
|
|
13
|
+
HATK_RELAY: string;
|
|
14
|
+
HATK_PLC: string;
|
|
15
|
+
HATK_OAUTH_ISSUER?: string;
|
|
16
|
+
HATK_OAUTH_SCOPES?: string;
|
|
17
|
+
HATK_ADMINS?: string;
|
|
18
|
+
HATK_COLLECTIONS?: string;
|
|
19
|
+
HATK_BACKFILL_PARALLELISM?: string;
|
|
20
|
+
HATK_BACKFILL_FETCH_TIMEOUT?: string;
|
|
21
|
+
HATK_BACKFILL_MAX_RETRIES?: string;
|
|
22
|
+
HATK_BACKFILL_FULL_NETWORK?: string;
|
|
23
|
+
HATK_BACKFILL_REPOS?: string;
|
|
24
|
+
HATK_BACKFILL_SIGNAL_COLLECTIONS?: string;
|
|
25
|
+
}
|
|
26
|
+
interface D1Database {
|
|
27
|
+
prepare(sql: string): any;
|
|
28
|
+
batch<T = unknown>(statements: any[]): Promise<any[]>;
|
|
29
|
+
exec(sql: string): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resync a single DID by triggering auto-backfill.
|
|
33
|
+
* Called by the Worker via Container service binding RPC.
|
|
34
|
+
*/
|
|
35
|
+
declare function resync(did: string): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Trigger a full re-enumeration backfill of all repos.
|
|
38
|
+
* Called by the Worker via Container service binding RPC.
|
|
39
|
+
*/
|
|
40
|
+
declare function resyncAll(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Return basic status info about the Container.
|
|
43
|
+
* Called by the Worker for health checks / admin UI.
|
|
44
|
+
*/
|
|
45
|
+
declare function getStatus(): {
|
|
46
|
+
initialized: boolean;
|
|
47
|
+
collections: string[];
|
|
48
|
+
uptimeMs: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Cloudflare Container entry point.
|
|
52
|
+
*
|
|
53
|
+
* Containers expose RPC methods that the Worker can call via the service binding.
|
|
54
|
+
* The Container also handles fetch requests routed from the Worker, but for hatk
|
|
55
|
+
* all Worker-to-Container communication uses the RPC methods above.
|
|
56
|
+
*/
|
|
57
|
+
declare const _default: {
|
|
58
|
+
/**
|
|
59
|
+
* Container startup — called when the Container is first instantiated.
|
|
60
|
+
* Initializes the database, starts the firehose, and begins backfill.
|
|
61
|
+
*/
|
|
62
|
+
start(env: Env): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Handle fetch requests forwarded from the Worker.
|
|
65
|
+
* The Container doesn't serve HTTP — return 404 for any direct requests.
|
|
66
|
+
*/
|
|
67
|
+
fetch(request: Request, env: Env): Promise<Response>;
|
|
68
|
+
resync: typeof resync;
|
|
69
|
+
resyncAll: typeof resyncAll;
|
|
70
|
+
getStatus: typeof getStatus;
|
|
71
|
+
};
|
|
72
|
+
export default _default;
|
|
73
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/cloudflare/container.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0BH,MAAM,WAAW,GAAG;IAClB,qCAAqC;IACrC,EAAE,EAAE,UA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
1
|
+
/**
|
|
2
|
+
* Cloudflare Container entry point for hatk.
|
|
3
|
+
*
|
|
4
|
+
* Runs as a long-lived Node.js process alongside the Worker. Handles the
|
|
5
|
+
* firehose indexer and backfill loop — the Worker delegates resync requests
|
|
6
|
+
* here via RPC (Cloudflare Container service bindings).
|
|
7
|
+
*
|
|
8
|
+
* No HTTP server — all communication is via the Container RPC interface.
|
|
9
|
+
*/
|
|
10
|
+
import { D1Adapter } from "../database/adapters/d1.js";
|
|
11
|
+
import { initDatabase, getCursor, migrateSchema } from "../database/db.js";
|
|
12
|
+
import { storeLexicons, discoverCollections, buildSchemas } from "../database/schema.js";
|
|
13
|
+
import { discoverViews } from "../views.js";
|
|
14
|
+
import { getDialect } from "../database/dialect.js";
|
|
15
|
+
import { setSearchPort } from "../database/fts.js";
|
|
16
|
+
import { rebuildAllIndexes } from "../database/fts.js";
|
|
17
|
+
import { registerCoreHandlers } from "../server.js";
|
|
18
|
+
import { configureRelay } from "../xrpc.js";
|
|
19
|
+
import { startIndexer, triggerAutoBackfill } from "../indexer.js";
|
|
20
|
+
import { runBackfill } from "../backfill.js";
|
|
21
|
+
import { relayHttpUrl } from "../config.js";
|
|
22
|
+
import { validateLexicons } from '@bigmoves/lexicon';
|
|
23
|
+
import { log } from "../logger.js";
|
|
24
|
+
// ---------- Container state ----------
|
|
25
|
+
let initialized = false;
|
|
26
|
+
let initPromise = null;
|
|
27
|
+
let collections = [];
|
|
28
|
+
let collectionSet = new Set();
|
|
29
|
+
let backfillOpts = null;
|
|
30
|
+
let startedAt = 0;
|
|
31
|
+
/**
|
|
32
|
+
* One-time initialization. Mirrors main.ts startup minus the HTTP server.
|
|
33
|
+
*/
|
|
34
|
+
async function initialize(env) {
|
|
35
|
+
startedAt = Date.now();
|
|
36
|
+
// 1. Parse config from env vars
|
|
37
|
+
const relay = env.HATK_RELAY || 'wss://bsky.network';
|
|
38
|
+
const plc = env.HATK_PLC || 'https://plc.directory';
|
|
39
|
+
configureRelay(relay);
|
|
40
|
+
const admins = env.HATK_ADMINS ? env.HATK_ADMINS.split(',').map((s) => s.trim()) : [];
|
|
41
|
+
// 2. Load lexicons — injected at build time via virtual module
|
|
42
|
+
let lexicons;
|
|
43
|
+
try {
|
|
44
|
+
// @ts-expect-error — virtual module generated at build time
|
|
45
|
+
const lexiconModule = await import('virtual:hatk-lexicons');
|
|
46
|
+
lexicons = new Map(Object.entries(lexiconModule.default));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
lexicons = new Map();
|
|
50
|
+
}
|
|
51
|
+
const lexiconErrors = validateLexicons([...lexicons.values()]);
|
|
52
|
+
if (lexiconErrors) {
|
|
53
|
+
for (const [nsid, errors] of Object.entries(lexiconErrors)) {
|
|
54
|
+
for (const err of errors) {
|
|
55
|
+
console.error(`[container] Invalid lexicon ${nsid}: ${err}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw new Error('Invalid lexicons — check build output');
|
|
59
|
+
}
|
|
60
|
+
storeLexicons(lexicons);
|
|
61
|
+
// 3. Determine collections
|
|
62
|
+
collections = env.HATK_COLLECTIONS
|
|
63
|
+
? env.HATK_COLLECTIONS.split(',').map((s) => s.trim())
|
|
64
|
+
: discoverCollections(lexicons);
|
|
65
|
+
collectionSet = new Set(collections);
|
|
66
|
+
if (collections.length === 0) {
|
|
67
|
+
log('[container] No record collections found — running in indexer-only mode');
|
|
68
|
+
}
|
|
69
|
+
log(`[container] Loaded config: ${collections.length} collections`);
|
|
70
|
+
// 4. Build schemas and init D1
|
|
71
|
+
discoverViews();
|
|
72
|
+
const engineDialect = getDialect('d1');
|
|
73
|
+
const { schemas, ddlStatements } = buildSchemas(lexicons, collections, engineDialect);
|
|
74
|
+
const adapter = new D1Adapter();
|
|
75
|
+
adapter.initWithBinding(env.DB);
|
|
76
|
+
setSearchPort(null); // D1 uses SQLite FTS natively
|
|
77
|
+
await initDatabase(adapter, ':memory:', schemas, ddlStatements);
|
|
78
|
+
// Auto-migrate schema if lexicons changed
|
|
79
|
+
const migrationChanges = await migrateSchema(schemas);
|
|
80
|
+
if (migrationChanges.length > 0) {
|
|
81
|
+
log(`[container] Applied ${migrationChanges.length} schema migration(s)`);
|
|
82
|
+
}
|
|
83
|
+
// 5. Init server directory handlers (feeds, labels, hooks, xrpc, setup)
|
|
84
|
+
// In Containers, we load these via the bundled virtual module like the Worker.
|
|
85
|
+
// The server/ directory scanning won't work in a Container since there's no filesystem
|
|
86
|
+
// layout matching the dev project. For now, register core handlers only.
|
|
87
|
+
// When build tooling (Task 7) bundles server handlers, they'll be imported here.
|
|
88
|
+
const oauthConfig = env.HATK_OAUTH_ISSUER
|
|
89
|
+
? {
|
|
90
|
+
issuer: env.HATK_OAUTH_ISSUER,
|
|
91
|
+
scopes: env.HATK_OAUTH_SCOPES ? env.HATK_OAUTH_SCOPES.split(',').map((s) => s.trim()) : ['read', 'write'],
|
|
92
|
+
clients: [],
|
|
93
|
+
}
|
|
94
|
+
: null;
|
|
95
|
+
registerCoreHandlers(collections, oauthConfig);
|
|
96
|
+
// 6. Parse backfill config
|
|
97
|
+
const backfillConfig = {
|
|
98
|
+
fullNetwork: env.HATK_BACKFILL_FULL_NETWORK === 'true',
|
|
99
|
+
parallelism: env.HATK_BACKFILL_PARALLELISM ? parseInt(env.HATK_BACKFILL_PARALLELISM, 10) : 10,
|
|
100
|
+
fetchTimeout: env.HATK_BACKFILL_FETCH_TIMEOUT ? parseInt(env.HATK_BACKFILL_FETCH_TIMEOUT, 10) : 30,
|
|
101
|
+
maxRetries: env.HATK_BACKFILL_MAX_RETRIES ? parseInt(env.HATK_BACKFILL_MAX_RETRIES, 10) : 5,
|
|
102
|
+
repos: env.HATK_BACKFILL_REPOS ? env.HATK_BACKFILL_REPOS.split(',').map((s) => s.trim()) : undefined,
|
|
103
|
+
signalCollections: env.HATK_BACKFILL_SIGNAL_COLLECTIONS
|
|
104
|
+
? env.HATK_BACKFILL_SIGNAL_COLLECTIONS.split(',').map((s) => s.trim())
|
|
105
|
+
: undefined,
|
|
106
|
+
};
|
|
107
|
+
backfillOpts = {
|
|
108
|
+
pdsUrl: relayHttpUrl(relay),
|
|
109
|
+
plcUrl: plc,
|
|
110
|
+
collections: collectionSet,
|
|
111
|
+
config: backfillConfig,
|
|
112
|
+
};
|
|
113
|
+
// 7. Start firehose indexer
|
|
114
|
+
const cursor = await getCursor('relay');
|
|
115
|
+
startIndexer({
|
|
116
|
+
relayUrl: relay,
|
|
117
|
+
collections: collectionSet,
|
|
118
|
+
signalCollections: backfillConfig.signalCollections ? new Set(backfillConfig.signalCollections) : undefined,
|
|
119
|
+
pinnedRepos: backfillConfig.repos ? new Set(backfillConfig.repos) : undefined,
|
|
120
|
+
cursor,
|
|
121
|
+
fetchTimeout: backfillConfig.fetchTimeout,
|
|
122
|
+
maxRetries: backfillConfig.maxRetries,
|
|
123
|
+
parallelism: backfillConfig.parallelism,
|
|
124
|
+
});
|
|
125
|
+
log('[container] Firehose indexer started');
|
|
126
|
+
// 8. Run backfill in background
|
|
127
|
+
runBackfillAndRestart();
|
|
128
|
+
initialized = true;
|
|
129
|
+
log('[container] Initialization complete');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Run backfill, rebuild FTS indexes, and restart the process if records
|
|
133
|
+
* were imported (to reclaim memory from CAR parsing). Mirrors main.ts behavior.
|
|
134
|
+
*/
|
|
135
|
+
function runBackfillAndRestart() {
|
|
136
|
+
if (!backfillOpts)
|
|
137
|
+
return;
|
|
138
|
+
runBackfill(backfillOpts)
|
|
139
|
+
.then(async (recordCount) => {
|
|
140
|
+
log('[container] Backfill complete, building FTS indexes...');
|
|
141
|
+
await rebuildAllIndexes(collections);
|
|
142
|
+
log('[container] FTS indexes ready');
|
|
143
|
+
return recordCount;
|
|
144
|
+
})
|
|
145
|
+
.then((recordCount) => {
|
|
146
|
+
if (recordCount > 0) {
|
|
147
|
+
log('[container] Restarting to reclaim memory...');
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
.catch((err) => {
|
|
152
|
+
console.error('[container] Backfill error:', err.message);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Ensure initialization has completed. Uses a shared promise so concurrent
|
|
157
|
+
* RPC calls don't trigger multiple inits.
|
|
158
|
+
*/
|
|
159
|
+
function ensureInit(env) {
|
|
160
|
+
if (initialized)
|
|
161
|
+
return Promise.resolve();
|
|
162
|
+
if (!initPromise) {
|
|
163
|
+
initPromise = initialize(env).catch((err) => {
|
|
164
|
+
initPromise = null;
|
|
165
|
+
throw err;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return initPromise;
|
|
169
|
+
}
|
|
170
|
+
// ---------- RPC methods ----------
|
|
171
|
+
/**
|
|
172
|
+
* Resync a single DID by triggering auto-backfill.
|
|
173
|
+
* Called by the Worker via Container service binding RPC.
|
|
174
|
+
*/
|
|
175
|
+
async function resync(did) {
|
|
176
|
+
await triggerAutoBackfill(did);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Trigger a full re-enumeration backfill of all repos.
|
|
180
|
+
* Called by the Worker via Container service binding RPC.
|
|
181
|
+
*/
|
|
182
|
+
async function resyncAll() {
|
|
183
|
+
runBackfillAndRestart();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Return basic status info about the Container.
|
|
187
|
+
* Called by the Worker for health checks / admin UI.
|
|
188
|
+
*/
|
|
189
|
+
function getStatus() {
|
|
190
|
+
return {
|
|
191
|
+
initialized,
|
|
192
|
+
collections,
|
|
193
|
+
uptimeMs: startedAt > 0 ? Date.now() - startedAt : 0,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
// ---------- Container export ----------
|
|
197
|
+
/**
|
|
198
|
+
* Cloudflare Container entry point.
|
|
199
|
+
*
|
|
200
|
+
* Containers expose RPC methods that the Worker can call via the service binding.
|
|
201
|
+
* The Container also handles fetch requests routed from the Worker, but for hatk
|
|
202
|
+
* all Worker-to-Container communication uses the RPC methods above.
|
|
203
|
+
*/
|
|
204
|
+
export default {
|
|
205
|
+
/**
|
|
206
|
+
* Container startup — called when the Container is first instantiated.
|
|
207
|
+
* Initializes the database, starts the firehose, and begins backfill.
|
|
208
|
+
*/
|
|
209
|
+
async start(env) {
|
|
210
|
+
await ensureInit(env);
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* Handle fetch requests forwarded from the Worker.
|
|
214
|
+
* The Container doesn't serve HTTP — return 404 for any direct requests.
|
|
215
|
+
*/
|
|
216
|
+
async fetch(request, env) {
|
|
217
|
+
await ensureInit(env);
|
|
218
|
+
return new Response(JSON.stringify({ error: 'Container does not serve HTTP requests' }), {
|
|
219
|
+
status: 404,
|
|
220
|
+
headers: { 'Content-Type': 'application/json' },
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
// RPC methods exposed to the Worker via service binding
|
|
224
|
+
resync,
|
|
225
|
+
resyncAll,
|
|
226
|
+
getStatus,
|
|
227
|
+
};
|
|
228
|
+
// Graceful shutdown
|
|
229
|
+
process.on('SIGTERM', () => {
|
|
230
|
+
log('[container] Received SIGTERM, shutting down...');
|
|
231
|
+
process.exit(0);
|
|
232
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SvelteKit handle hook for Cloudflare Workers.
|
|
3
|
+
*
|
|
4
|
+
* Use with @sveltejs/adapter-cloudflare. Lazily initializes hatk on the first
|
|
5
|
+
* request using the D1 binding from platform.env, then intercepts hatk API
|
|
6
|
+
* routes before SvelteKit processes them.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // app/hooks.server.ts
|
|
11
|
+
* import { createHandle } from '@hatk/hatk/cloudflare/hooks'
|
|
12
|
+
* export const handle = createHandle()
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
16
|
+
/** Minimal SvelteKit Handle type to avoid depending on @sveltejs/kit. */
|
|
17
|
+
type Handle = (input: {
|
|
18
|
+
event: {
|
|
19
|
+
request: Request;
|
|
20
|
+
url: URL;
|
|
21
|
+
platform?: {
|
|
22
|
+
env?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
resolve: (event: any) => MaybePromise<Response>;
|
|
26
|
+
}) => MaybePromise<Response>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a SvelteKit `handle` function that initializes hatk with D1
|
|
29
|
+
* and intercepts API routes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createHandle(): Handle;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/cloudflare/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAErC,yEAAyE;AACzE,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;IACpB,KAAK,EAAE;QACL,OAAO,EAAE,OAAO,CAAA;QAChB,GAAG,EAAE,GAAG,CAAA;QACR,QAAQ,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAA;KAC7C,CAAA;IACD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAA;CAChD,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAA;AAE5B;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAsBrC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SvelteKit handle hook for Cloudflare Workers.
|
|
3
|
+
*
|
|
4
|
+
* Use with @sveltejs/adapter-cloudflare. Lazily initializes hatk on the first
|
|
5
|
+
* request using the D1 binding from platform.env, then intercepts hatk API
|
|
6
|
+
* routes before SvelteKit processes them.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // app/hooks.server.ts
|
|
11
|
+
* import { createHandle } from '@hatk/hatk/cloudflare/hooks'
|
|
12
|
+
* export const handle = createHandle()
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { ensureInit, getHandler } from "./init.js";
|
|
16
|
+
import { isHatkRoute } from "../adapter.js";
|
|
17
|
+
/**
|
|
18
|
+
* Create a SvelteKit `handle` function that initializes hatk with D1
|
|
19
|
+
* and intercepts API routes.
|
|
20
|
+
*/
|
|
21
|
+
export function createHandle() {
|
|
22
|
+
return async ({ event, resolve }) => {
|
|
23
|
+
const env = event.platform?.env;
|
|
24
|
+
if (!env || !env.DB) {
|
|
25
|
+
// Not running on Cloudflare (e.g. dev mode) — pass through
|
|
26
|
+
return resolve(event);
|
|
27
|
+
}
|
|
28
|
+
// Lazy init hatk with the D1 binding
|
|
29
|
+
await ensureInit(env);
|
|
30
|
+
// hatk API routes
|
|
31
|
+
if (isHatkRoute(event.url.pathname)) {
|
|
32
|
+
const handler = getHandler();
|
|
33
|
+
if (handler) {
|
|
34
|
+
return handler(event.request);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Everything else → SvelteKit
|
|
38
|
+
return resolve(event);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Cloudflare initialization logic used by both the standalone Worker
|
|
3
|
+
* entry and the SvelteKit handle hook.
|
|
4
|
+
*/
|
|
5
|
+
export interface CloudflareEnv {
|
|
6
|
+
DB: D1Database;
|
|
7
|
+
HATK_RELAY?: string;
|
|
8
|
+
HATK_PLC?: string;
|
|
9
|
+
HATK_OAUTH_ISSUER?: string;
|
|
10
|
+
HATK_OAUTH_SCOPES?: string;
|
|
11
|
+
HATK_ADMINS?: string;
|
|
12
|
+
HATK_COLLECTIONS?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
interface D1Database {
|
|
16
|
+
prepare(sql: string): any;
|
|
17
|
+
batch<T = unknown>(statements: any[]): Promise<any[]>;
|
|
18
|
+
exec(sql: string): Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Ensure initialization has completed. Concurrent calls share the same promise.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ensureInit(env: CloudflareEnv): Promise<void>;
|
|
24
|
+
/** Get the hatk request handler (only valid after init). */
|
|
25
|
+
export declare function getHandler(): ((request: Request) => Promise<Response>) | null;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cloudflare/init.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,UAAU,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,UAAU,UAAU;IAClB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IACzB,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IACrD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CAChC;AAoFD;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAS5D;AAED,4DAA4D;AAC5D,wBAAgB,UAAU,IAAI,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAE7E"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Cloudflare initialization logic used by both the standalone Worker
|
|
3
|
+
* entry and the SvelteKit handle hook.
|
|
4
|
+
*/
|
|
5
|
+
import { D1Adapter } from "../database/adapters/d1.js";
|
|
6
|
+
import { initDatabase, migrateSchema } from "../database/db.js";
|
|
7
|
+
import { storeLexicons, discoverCollections, buildSchemas } from "../database/schema.js";
|
|
8
|
+
import { discoverViews } from "../views.js";
|
|
9
|
+
import { getDialect } from "../database/dialect.js";
|
|
10
|
+
import { setSearchPort } from "../database/fts.js";
|
|
11
|
+
import { initOAuth } from "../oauth/server.js";
|
|
12
|
+
import { parseSessionCookie, getSessionCookieName } from "../oauth/session.js";
|
|
13
|
+
import { createHandler, registerCoreHandlers } from "../server.js";
|
|
14
|
+
import { configureRelay } from "../xrpc.js";
|
|
15
|
+
import { callXrpc } from "../xrpc.js";
|
|
16
|
+
import { validateLexicons } from '@bigmoves/lexicon';
|
|
17
|
+
let handler = null;
|
|
18
|
+
let initPromise = null;
|
|
19
|
+
/**
|
|
20
|
+
* One-time initialization. Sets up D1 adapter, database schemas, XRPC
|
|
21
|
+
* handlers, OAuth, and the globalThis bridge for SvelteKit SSR.
|
|
22
|
+
*/
|
|
23
|
+
async function initialize(env) {
|
|
24
|
+
const relay = env.HATK_RELAY || 'wss://bsky.network';
|
|
25
|
+
const plc = env.HATK_PLC || 'https://plc.directory';
|
|
26
|
+
configureRelay(relay);
|
|
27
|
+
const admins = env.HATK_ADMINS ? env.HATK_ADMINS.split(',').map((s) => s.trim()) : [];
|
|
28
|
+
// Load lexicons — injected at build time via virtual module
|
|
29
|
+
let lexicons;
|
|
30
|
+
try {
|
|
31
|
+
// @ts-expect-error — virtual module generated at build time
|
|
32
|
+
const lexiconModule = await import('virtual:hatk-lexicons');
|
|
33
|
+
lexicons = new Map(Object.entries(lexiconModule.default));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
lexicons = new Map();
|
|
37
|
+
}
|
|
38
|
+
const lexiconErrors = validateLexicons([...lexicons.values()]);
|
|
39
|
+
if (lexiconErrors) {
|
|
40
|
+
for (const [nsid, errors] of Object.entries(lexiconErrors)) {
|
|
41
|
+
for (const err of errors) {
|
|
42
|
+
console.error(`[hatk] Invalid lexicon ${nsid}: ${err}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error('Invalid lexicons — check build output');
|
|
46
|
+
}
|
|
47
|
+
storeLexicons(lexicons);
|
|
48
|
+
const collections = env.HATK_COLLECTIONS
|
|
49
|
+
? env.HATK_COLLECTIONS.split(',').map((s) => s.trim())
|
|
50
|
+
: discoverCollections(lexicons);
|
|
51
|
+
// Build schemas and init D1
|
|
52
|
+
discoverViews();
|
|
53
|
+
const engineDialect = getDialect('d1');
|
|
54
|
+
const { schemas, ddlStatements } = buildSchemas(lexicons, collections, engineDialect);
|
|
55
|
+
const adapter = new D1Adapter();
|
|
56
|
+
adapter.initWithBinding(env.DB);
|
|
57
|
+
setSearchPort(null);
|
|
58
|
+
await initDatabase(adapter, ':memory:', schemas, ddlStatements);
|
|
59
|
+
await migrateSchema(schemas);
|
|
60
|
+
// Register core XRPC handlers
|
|
61
|
+
const oauthConfig = env.HATK_OAUTH_ISSUER
|
|
62
|
+
? {
|
|
63
|
+
issuer: env.HATK_OAUTH_ISSUER,
|
|
64
|
+
scopes: env.HATK_OAUTH_SCOPES ? env.HATK_OAUTH_SCOPES.split(',').map((s) => s.trim()) : ['read', 'write'],
|
|
65
|
+
clients: [],
|
|
66
|
+
}
|
|
67
|
+
: null;
|
|
68
|
+
registerCoreHandlers(collections, oauthConfig);
|
|
69
|
+
if (oauthConfig) {
|
|
70
|
+
await initOAuth(oauthConfig, plc, relay);
|
|
71
|
+
}
|
|
72
|
+
// Expose bridge for SvelteKit SSR
|
|
73
|
+
;
|
|
74
|
+
globalThis.__hatk_callXrpc = callXrpc;
|
|
75
|
+
globalThis.__hatk_parseSessionCookie = parseSessionCookie;
|
|
76
|
+
globalThis.__hatk_sessionCookieName = getSessionCookieName();
|
|
77
|
+
// Create the request handler
|
|
78
|
+
handler = createHandler({
|
|
79
|
+
collections,
|
|
80
|
+
publicDir: null,
|
|
81
|
+
oauth: oauthConfig,
|
|
82
|
+
admins,
|
|
83
|
+
onResync: undefined,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Ensure initialization has completed. Concurrent calls share the same promise.
|
|
88
|
+
*/
|
|
89
|
+
export function ensureInit(env) {
|
|
90
|
+
if (handler)
|
|
91
|
+
return Promise.resolve();
|
|
92
|
+
if (!initPromise) {
|
|
93
|
+
initPromise = initialize(env).catch((err) => {
|
|
94
|
+
initPromise = null;
|
|
95
|
+
throw err;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return initPromise;
|
|
99
|
+
}
|
|
100
|
+
/** Get the hatk request handler (only valid after init). */
|
|
101
|
+
export function getHandler() {
|
|
102
|
+
return handler;
|
|
103
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Worker entry point for hatk.
|
|
3
|
+
*
|
|
4
|
+
* Handles HTTP requests via the Workers fetch handler. The firehose indexer
|
|
5
|
+
* and backfill run in a companion Container — the Worker only serves the
|
|
6
|
+
* API and web UI.
|
|
7
|
+
*
|
|
8
|
+
* For SvelteKit apps, prefer using the handle hook from
|
|
9
|
+
* '@hatk/hatk/cloudflare/hooks' with adapter-cloudflare instead.
|
|
10
|
+
*/
|
|
11
|
+
import { type CloudflareEnv } from './init.ts';
|
|
12
|
+
interface ContainerBinding {
|
|
13
|
+
resync(did: string): Promise<void>;
|
|
14
|
+
fetch(request: Request): Promise<Response>;
|
|
15
|
+
}
|
|
16
|
+
interface Env extends CloudflareEnv {
|
|
17
|
+
CONTAINER: ContainerBinding;
|
|
18
|
+
}
|
|
19
|
+
interface ExecutionContext {
|
|
20
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
21
|
+
passThroughOnException(): void;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: {
|
|
24
|
+
fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
27
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/cloudflare/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAGtE,UAAU,gBAAgB;IACxB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C;AAED,UAAU,GAAI,SAAQ,aAAa;IACjC,SAAS,EAAE,gBAAgB,CAAA;CAC5B;AAED,UAAU,gBAAgB;IACxB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IAC1C,sBAAsB,IAAI,IAAI,CAAA;CAC/B;;mBAGsB,OAAO,OAAO,GAAG,OAAO,gBAAgB,GAAG,OAAO,CAAC,QAAQ,CAAC;;AADnF,wBA2CC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Worker entry point for hatk.
|
|
3
|
+
*
|
|
4
|
+
* Handles HTTP requests via the Workers fetch handler. The firehose indexer
|
|
5
|
+
* and backfill run in a companion Container — the Worker only serves the
|
|
6
|
+
* API and web UI.
|
|
7
|
+
*
|
|
8
|
+
* For SvelteKit apps, prefer using the handle hook from
|
|
9
|
+
* '@hatk/hatk/cloudflare/hooks' with adapter-cloudflare instead.
|
|
10
|
+
*/
|
|
11
|
+
import { ensureInit, getHandler } from "./init.js";
|
|
12
|
+
import { isHatkRoute } from "../adapter.js";
|
|
13
|
+
export default {
|
|
14
|
+
async fetch(request, env, ctx) {
|
|
15
|
+
try {
|
|
16
|
+
await ensureInit(env);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return new Response(JSON.stringify({ error: 'Initialization failed', detail: err.message }), {
|
|
20
|
+
status: 500,
|
|
21
|
+
headers: { 'Content-Type': 'application/json' },
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const url = new URL(request.url);
|
|
25
|
+
const handler = getHandler();
|
|
26
|
+
// Intercept admin resync to delegate to the Container via RPC
|
|
27
|
+
if (url.pathname === '/admin/repos/resync' && request.method === 'POST') {
|
|
28
|
+
try {
|
|
29
|
+
const body = await request.text();
|
|
30
|
+
const { dids } = body ? JSON.parse(body) : {};
|
|
31
|
+
if (Array.isArray(dids)) {
|
|
32
|
+
for (const did of dids) {
|
|
33
|
+
ctx.waitUntil(env.CONTAINER.resync(did));
|
|
34
|
+
}
|
|
35
|
+
return new Response(JSON.stringify({ resyncing: dids.length }), {
|
|
36
|
+
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return new Response(JSON.stringify({ error: err.message }), {
|
|
42
|
+
status: 500,
|
|
43
|
+
headers: { 'Content-Type': 'application/json' },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// hatk routes → handler
|
|
48
|
+
if (isHatkRoute(url.pathname)) {
|
|
49
|
+
return handler(request);
|
|
50
|
+
}
|
|
51
|
+
// Everything else → 404 (use cloudflare/hooks for SvelteKit integration)
|
|
52
|
+
return new Response('Not found', { status: 404 });
|
|
53
|
+
},
|
|
54
|
+
};
|
package/dist/config.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface OAuthConfig {
|
|
|
20
20
|
issuer: string;
|
|
21
21
|
scopes: string[];
|
|
22
22
|
clients: OAuthClientConfig[];
|
|
23
|
+
cookieName?: string;
|
|
23
24
|
}
|
|
24
25
|
export interface BackfillConfig {
|
|
25
26
|
signalCollections?: string[];
|
|
@@ -33,6 +34,7 @@ export interface HatkConfig {
|
|
|
33
34
|
relay: string;
|
|
34
35
|
plc: string;
|
|
35
36
|
port: number;
|
|
37
|
+
databaseEngine: 'duckdb' | 'sqlite';
|
|
36
38
|
database: string;
|
|
37
39
|
publicDir: string | null;
|
|
38
40
|
collections: string[];
|
|
@@ -41,7 +43,16 @@ export interface HatkConfig {
|
|
|
41
43
|
oauth: OAuthConfig | null;
|
|
42
44
|
admins: string[];
|
|
43
45
|
}
|
|
46
|
+
/** Input type for defineConfig — fields that have defaults are optional. */
|
|
47
|
+
export type HatkConfigInput = Partial<Omit<HatkConfig, 'oauth' | 'backfill'>> & {
|
|
48
|
+
oauth?: (Partial<OAuthConfig> & {
|
|
49
|
+
clients: OAuthClientConfig[];
|
|
50
|
+
}) | null;
|
|
51
|
+
backfill?: Partial<BackfillConfig>;
|
|
52
|
+
};
|
|
53
|
+
/** Identity function that provides type inference for hatk config files. */
|
|
54
|
+
export declare function defineConfig(config: HatkConfigInput): HatkConfigInput;
|
|
44
55
|
/** Derive HTTP URL from relay WebSocket URL (ws://host → http://host) */
|
|
45
56
|
export declare function relayHttpUrl(relay: string): string;
|
|
46
|
-
export declare function loadConfig(configPath: string): HatkConfig
|
|
57
|
+
export declare function loadConfig(configPath: string): Promise<HatkConfig>;
|
|
47
58
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|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