@hatk/hatk 0.0.1-alpha.8 → 0.0.1-alpha.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/adapter.d.ts +19 -0
  2. package/dist/adapter.d.ts.map +1 -0
  3. package/dist/adapter.js +111 -0
  4. package/dist/backfill.d.ts +29 -2
  5. package/dist/backfill.d.ts.map +1 -1
  6. package/dist/backfill.js +136 -51
  7. package/dist/car.d.ts +42 -10
  8. package/dist/car.d.ts.map +1 -1
  9. package/dist/car.js +154 -14
  10. package/dist/cli.js +243 -1043
  11. package/dist/config.d.ts +82 -1
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +44 -9
  14. package/dist/database/adapter-factory.d.ts +6 -0
  15. package/dist/database/adapter-factory.d.ts.map +1 -0
  16. package/dist/database/adapter-factory.js +20 -0
  17. package/dist/database/adapters/duckdb-search.d.ts +12 -0
  18. package/dist/database/adapters/duckdb-search.d.ts.map +1 -0
  19. package/dist/database/adapters/duckdb-search.js +27 -0
  20. package/dist/database/adapters/duckdb.d.ts +25 -0
  21. package/dist/database/adapters/duckdb.d.ts.map +1 -0
  22. package/dist/database/adapters/duckdb.js +161 -0
  23. package/dist/database/adapters/sqlite-search.d.ts +16 -0
  24. package/dist/database/adapters/sqlite-search.d.ts.map +1 -0
  25. package/dist/database/adapters/sqlite-search.js +76 -0
  26. package/dist/database/adapters/sqlite.d.ts +18 -0
  27. package/dist/database/adapters/sqlite.d.ts.map +1 -0
  28. package/dist/database/adapters/sqlite.js +88 -0
  29. package/dist/{db.d.ts → database/db.d.ts} +57 -6
  30. package/dist/database/db.d.ts.map +1 -0
  31. package/dist/{db.js → database/db.js} +755 -552
  32. package/dist/database/dialect.d.ts +45 -0
  33. package/dist/database/dialect.d.ts.map +1 -0
  34. package/dist/database/dialect.js +72 -0
  35. package/dist/{fts.d.ts → database/fts.d.ts} +7 -0
  36. package/dist/database/fts.d.ts.map +1 -0
  37. package/dist/{fts.js → database/fts.js} +116 -32
  38. package/dist/database/index.d.ts +7 -0
  39. package/dist/database/index.d.ts.map +1 -0
  40. package/dist/database/index.js +6 -0
  41. package/dist/database/ports.d.ts +50 -0
  42. package/dist/database/ports.d.ts.map +1 -0
  43. package/dist/database/ports.js +1 -0
  44. package/dist/{schema.d.ts → database/schema.d.ts} +14 -3
  45. package/dist/database/schema.d.ts.map +1 -0
  46. package/dist/{schema.js → database/schema.js} +81 -41
  47. package/dist/dev-entry.d.ts +8 -0
  48. package/dist/dev-entry.d.ts.map +1 -0
  49. package/dist/dev-entry.js +125 -0
  50. package/dist/feeds.d.ts +12 -8
  51. package/dist/feeds.d.ts.map +1 -1
  52. package/dist/feeds.js +51 -6
  53. package/dist/hooks.d.ts +85 -0
  54. package/dist/hooks.d.ts.map +1 -0
  55. package/dist/hooks.js +163 -0
  56. package/dist/hydrate.d.ts +7 -6
  57. package/dist/hydrate.d.ts.map +1 -1
  58. package/dist/hydrate.js +4 -16
  59. package/dist/indexer.d.ts +133 -3
  60. package/dist/indexer.d.ts.map +1 -1
  61. package/dist/indexer.js +406 -66
  62. package/dist/jetstream.d.ts +118 -0
  63. package/dist/jetstream.d.ts.map +1 -0
  64. package/dist/jetstream.js +225 -0
  65. package/dist/labels.d.ts +36 -0
  66. package/dist/labels.d.ts.map +1 -1
  67. package/dist/labels.js +71 -6
  68. package/dist/lexicon-resolve.d.ts.map +1 -1
  69. package/dist/lexicon-resolve.js +27 -112
  70. package/dist/lexicons/com/atproto/label/defs.json +75 -0
  71. package/dist/lexicons/com/atproto/moderation/defs.json +30 -0
  72. package/dist/lexicons/com/atproto/repo/strongRef.json +21 -0
  73. package/dist/lexicons/dev/hatk/applyWrites.json +87 -0
  74. package/dist/lexicons/dev/hatk/createRecord.json +40 -0
  75. package/dist/lexicons/dev/hatk/createReport.json +48 -0
  76. package/dist/lexicons/dev/hatk/deleteRecord.json +25 -0
  77. package/dist/lexicons/dev/hatk/describeCollections.json +41 -0
  78. package/dist/lexicons/dev/hatk/describeFeeds.json +29 -0
  79. package/dist/lexicons/dev/hatk/describeLabels.json +45 -0
  80. package/dist/lexicons/dev/hatk/getFeed.json +30 -0
  81. package/dist/lexicons/dev/hatk/getPreferences.json +19 -0
  82. package/dist/lexicons/dev/hatk/getRecord.json +26 -0
  83. package/dist/lexicons/dev/hatk/getRecords.json +32 -0
  84. package/dist/lexicons/dev/hatk/putPreference.json +28 -0
  85. package/dist/lexicons/dev/hatk/putRecord.json +41 -0
  86. package/dist/lexicons/dev/hatk/searchRecords.json +32 -0
  87. package/dist/lexicons/dev/hatk/uploadBlob.json +23 -0
  88. package/dist/logger.d.ts +29 -0
  89. package/dist/logger.d.ts.map +1 -1
  90. package/dist/logger.js +29 -0
  91. package/dist/main.js +169 -74
  92. package/dist/mst.d.ts +18 -1
  93. package/dist/mst.d.ts.map +1 -1
  94. package/dist/mst.js +19 -8
  95. package/dist/oauth/db.d.ts +3 -1
  96. package/dist/oauth/db.d.ts.map +1 -1
  97. package/dist/oauth/db.js +56 -19
  98. package/dist/oauth/discovery.d.ts.map +1 -1
  99. package/dist/oauth/discovery.js +13 -1
  100. package/dist/oauth/server.d.ts +92 -1
  101. package/dist/oauth/server.d.ts.map +1 -1
  102. package/dist/oauth/server.js +352 -37
  103. package/dist/oauth/service-describe.d.ts +31 -0
  104. package/dist/oauth/service-describe.d.ts.map +1 -0
  105. package/dist/oauth/service-describe.js +61 -0
  106. package/dist/oauth/session.d.ts +32 -0
  107. package/dist/oauth/session.d.ts.map +1 -0
  108. package/dist/oauth/session.js +131 -0
  109. package/dist/opengraph.d.ts +10 -0
  110. package/dist/opengraph.d.ts.map +1 -1
  111. package/dist/opengraph.js +80 -40
  112. package/dist/pds-proxy.d.ts +82 -0
  113. package/dist/pds-proxy.d.ts.map +1 -0
  114. package/dist/pds-proxy.js +356 -0
  115. package/dist/private-collections.d.ts +8 -0
  116. package/dist/private-collections.d.ts.map +1 -0
  117. package/dist/private-collections.js +22 -0
  118. package/dist/push.d.ts +54 -0
  119. package/dist/push.d.ts.map +1 -0
  120. package/dist/push.js +367 -0
  121. package/dist/renderer.d.ts +27 -0
  122. package/dist/renderer.d.ts.map +1 -0
  123. package/dist/renderer.js +46 -0
  124. package/dist/resolve-hatk.d.ts +6 -0
  125. package/dist/resolve-hatk.d.ts.map +1 -0
  126. package/dist/resolve-hatk.js +20 -0
  127. package/dist/response.d.ts +16 -0
  128. package/dist/response.d.ts.map +1 -0
  129. package/dist/response.js +69 -0
  130. package/dist/scanner.d.ts +21 -0
  131. package/dist/scanner.d.ts.map +1 -0
  132. package/dist/scanner.js +88 -0
  133. package/dist/seed.d.ts +19 -0
  134. package/dist/seed.d.ts.map +1 -1
  135. package/dist/seed.js +43 -4
  136. package/dist/server-init.d.ts +8 -0
  137. package/dist/server-init.d.ts.map +1 -0
  138. package/dist/server-init.js +62 -0
  139. package/dist/server.d.ts +26 -3
  140. package/dist/server.d.ts.map +1 -1
  141. package/dist/server.js +858 -638
  142. package/dist/setup.d.ts +28 -1
  143. package/dist/setup.d.ts.map +1 -1
  144. package/dist/setup.js +50 -3
  145. package/dist/templates/feed.tpl +14 -0
  146. package/dist/templates/hook.tpl +5 -0
  147. package/dist/templates/label.tpl +15 -0
  148. package/dist/templates/og.tpl +17 -0
  149. package/dist/templates/seed.tpl +11 -0
  150. package/dist/templates/setup.tpl +5 -0
  151. package/dist/templates/test-feed.tpl +19 -0
  152. package/dist/templates/test-xrpc.tpl +19 -0
  153. package/dist/templates/xrpc.tpl +41 -0
  154. package/dist/test.d.ts +1 -1
  155. package/dist/test.d.ts.map +1 -1
  156. package/dist/test.js +41 -32
  157. package/dist/views.js +1 -1
  158. package/dist/vite-plugin.d.ts +1 -1
  159. package/dist/vite-plugin.d.ts.map +1 -1
  160. package/dist/vite-plugin.js +254 -66
  161. package/dist/xrpc.d.ts +84 -11
  162. package/dist/xrpc.d.ts.map +1 -1
  163. package/dist/xrpc.js +211 -41
  164. package/package.json +17 -9
  165. package/public/admin-auth.js +271 -306
  166. package/public/admin.html +177 -61
  167. package/dist/db.d.ts.map +0 -1
  168. package/dist/fts.d.ts.map +0 -1
  169. package/dist/oauth/hooks.d.ts +0 -10
  170. package/dist/oauth/hooks.d.ts.map +0 -1
  171. package/dist/oauth/hooks.js +0 -40
  172. package/dist/schema.d.ts.map +0 -1
  173. package/dist/test-browser.d.ts +0 -14
  174. package/dist/test-browser.d.ts.map +0 -1
  175. package/dist/test-browser.js +0 -26
package/dist/xrpc.js CHANGED
@@ -6,12 +6,40 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
+ /**
10
+ * XRPC method handler system for serving AT Protocol endpoints.
11
+ *
12
+ * Place handler modules in the `xrpc/` directory, nested by NSID segments
13
+ * (e.g. `xrpc/app/bsky/feed/getAuthorFeed.ts` → `app.bsky.feed.getAuthorFeed`).
14
+ * Each module default-exports a `{ handler }` function that receives an
15
+ * {@link XrpcContext} with database access, query params, pagination, and
16
+ * viewer auth.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // xrpc/xyz/statusphere/getStatuses.ts
21
+ * import { defineXrpc } from '../../hatk.generated.ts'
22
+ *
23
+ * export default defineXrpc('xyz.statusphere.getStatuses', async (ctx) => {
24
+ * const rows = await ctx.db.query('SELECT * FROM statusphere_status LIMIT ?', [ctx.limit])
25
+ * return { statuses: rows }
26
+ * })
27
+ * ```
28
+ */
9
29
  import { resolve, relative } from 'node:path';
10
30
  import { readdirSync, statSync } from 'node:fs';
11
- import { log } from "./logger.js";
12
- import { querySQL, runSQL, packCursor, unpackCursor, isTakendownDid, filterTakendownDids, searchRecords, findUriByFields, lookupByFieldBatch, countByFieldBatch, queryLabelsForUris, } from "./db.js";
13
- import { resolveRecords } from "./hydrate.js";
14
- import { getLexicon } from "./schema.js";
31
+ import { log, emit, timer } from "./logger.js";
32
+ import { querySQL, runSQL, packCursor, unpackCursor, isTakendownDid, filterTakendownDids, searchRecords, findUriByFields, } from "./database/db.js";
33
+ import { resolveRecords, buildBaseContext } from "./hydrate.js";
34
+ import { getLexicon } from "./database/schema.js";
35
+ import { createHmac } from 'node:crypto';
36
+ import { pdsCreateRecord, pdsPutRecord, pdsDeleteRecord, pdsApplyWrites, pdsXrpc } from "./pds-proxy.js";
37
+ let _oauthConfig = null;
38
+ /** Set the OAuth config used for record write helpers. Called once during boot. */
39
+ export function configureOAuth(config) {
40
+ _oauthConfig = config;
41
+ }
42
+ /** Thrown from XRPC handlers to return a 400 response with an error message. */
15
43
  export class InvalidRequestError extends Error {
16
44
  status = 400;
17
45
  errorName;
@@ -20,6 +48,7 @@ export class InvalidRequestError extends Error {
20
48
  this.errorName = errorName;
21
49
  }
22
50
  }
51
+ /** Thrown from XRPC handlers to return a 404 response. */
23
52
  export class NotFoundError extends InvalidRequestError {
24
53
  status = 404;
25
54
  constructor(message = 'Not found') {
@@ -27,21 +56,124 @@ export class NotFoundError extends InvalidRequestError {
27
56
  }
28
57
  }
29
58
  let _relayUrl = '';
59
+ let _cdn = null;
60
+ /** Set the relay URL used for blob URL generation. Called once during boot. */
61
+ /** True when the relay is a loopback URL — a dev PDS rather than the network. */
62
+ export function isLocalRelay() {
63
+ try {
64
+ const host = new URL(_relayUrl).hostname;
65
+ return host === 'localhost' || host === '127.0.0.1' || host === '[::1]' || host === '::1' || host.endsWith('.localhost');
66
+ }
67
+ catch {
68
+ return false;
69
+ }
70
+ }
30
71
  export function configureRelay(relay) {
31
72
  _relayUrl = relay;
32
73
  }
74
+ /** Set the CDN config for imgproxy URL signing. Called once during boot. */
75
+ export function configureCdn(cdn) {
76
+ if (cdn) {
77
+ _cdn = {
78
+ url: cdn.url.replace(/\/$/, ''),
79
+ key: Buffer.from(cdn.key, 'hex'),
80
+ salt: Buffer.from(cdn.salt, 'hex'),
81
+ };
82
+ }
83
+ else {
84
+ _cdn = null;
85
+ }
86
+ }
87
+ /** Sign an imgproxy path with HMAC-SHA256 (URL-safe base64). */
88
+ function signPath(path) {
89
+ const hmac = createHmac('sha256', _cdn.key);
90
+ hmac.update(_cdn.salt);
91
+ hmac.update(path);
92
+ const sig = hmac.digest('base64url');
93
+ return `/${sig}${path}`;
94
+ }
95
+ /**
96
+ * Generate a CDN URL for a blob ref. Uses the PDS directly in local dev,
97
+ * a configured imgproxy CDN if available, or the Bluesky CDN as fallback.
98
+ */
33
99
  export function blobUrl(did, ref, preset = 'avatar') {
34
100
  if (!ref)
35
101
  return undefined;
36
102
  const p = typeof ref === 'string' ? JSON.parse(ref) : ref;
37
103
  if (!p?.ref?.$link)
38
104
  return undefined;
39
- if (_relayUrl.includes('localhost:2583')) {
40
- return `http://localhost:2583/xrpc/com.atproto.sync.getBlob?did=${did}&cid=${p.ref.$link}`;
105
+ // A local network has no image CDN. Serve blobs through the dev proxy
106
+ // (see /blob/ in server.ts), which fetches from each repo's own PDS — on a
107
+ // multi-PDS dev stack the repos are not all behind the relay being tailed.
108
+ if (isLocalRelay()) {
109
+ return `/blob/${did}/${p.ref.$link}`;
110
+ }
111
+ if (_cdn) {
112
+ const path = `/${preset}/plain/${did}/${p.ref.$link}`;
113
+ return `${_cdn.url}${signPath(path)}`;
41
114
  }
42
115
  return `https://cdn.bsky.app/img/${preset}/plain/${did}/${p.ref.$link}@jpeg`;
43
116
  }
117
+ /** Build a full XrpcContext from request parameters. Reuses buildBaseContext for shared fields. */
118
+ export function buildXrpcContext(params, cursor, limit, viewer, input) {
119
+ const base = buildBaseContext(viewer);
120
+ return {
121
+ ...base,
122
+ db: { query: querySQL, run: runSQL },
123
+ params,
124
+ input: input || {},
125
+ cursor,
126
+ limit,
127
+ packCursor,
128
+ unpackCursor,
129
+ isTakendown: isTakendownDid,
130
+ filterTakendownDids,
131
+ search: searchRecords,
132
+ resolve: resolveRecords,
133
+ exists: async (collection, filters) => {
134
+ const conditions = Object.entries(filters).map(([field, value]) => ({ field, value }));
135
+ const uri = await findUriByFields(collection, conditions);
136
+ return uri !== null;
137
+ },
138
+ createRecord: async (collection, record, opts) => {
139
+ if (!_oauthConfig)
140
+ throw new Error('No OAuth config — cannot write to PDS');
141
+ if (!viewer)
142
+ throw new Error('Authentication required to write records');
143
+ return pdsCreateRecord(_oauthConfig, viewer, { collection, record, rkey: opts?.rkey });
144
+ },
145
+ putRecord: async (collection, rkey, record) => {
146
+ if (!_oauthConfig)
147
+ throw new Error('No OAuth config — cannot write to PDS');
148
+ if (!viewer)
149
+ throw new Error('Authentication required to write records');
150
+ return pdsPutRecord(_oauthConfig, viewer, { collection, rkey, record });
151
+ },
152
+ deleteRecord: async (collection, rkey) => {
153
+ if (!_oauthConfig)
154
+ throw new Error('No OAuth config — cannot write to PDS');
155
+ if (!viewer)
156
+ throw new Error('Authentication required to write records');
157
+ await pdsDeleteRecord(_oauthConfig, viewer, { collection, rkey });
158
+ },
159
+ applyWrites: async (writes) => {
160
+ if (!_oauthConfig)
161
+ throw new Error('No OAuth config — cannot write to PDS');
162
+ if (!viewer)
163
+ throw new Error('Authentication required to write records');
164
+ return pdsApplyWrites(_oauthConfig, viewer, { writes });
165
+ },
166
+ pds: async (nsid, options) => {
167
+ if (!_oauthConfig)
168
+ throw new Error('No OAuth config — cannot call the PDS');
169
+ if (!viewer)
170
+ throw new Error('Authentication required to call the PDS');
171
+ return pdsXrpc(_oauthConfig, viewer, nsid, options);
172
+ },
173
+ };
174
+ }
44
175
  const handlers = new Map();
176
+ /** Recursively collect .ts/.js files in a directory, skipping files prefixed with `_`. */
45
177
  function walkDir(dir) {
46
178
  const results = [];
47
179
  try {
@@ -58,6 +190,11 @@ function walkDir(dir) {
58
190
  catch { }
59
191
  return results.sort();
60
192
  }
193
+ /**
194
+ * Discover and load XRPC handler modules from the `xrpc/` directory.
195
+ * Directory nesting maps to NSID segments. Parameters are validated and
196
+ * coerced against the matching lexicon definition.
197
+ */
61
198
  export async function initXrpc(xrpcDir) {
62
199
  const files = walkDir(xrpcDir);
63
200
  if (files.length === 0)
@@ -65,7 +202,7 @@ export async function initXrpc(xrpcDir) {
65
202
  for (const scriptPath of files) {
66
203
  const rel = relative(xrpcDir, scriptPath).replace(/\.(ts|js)$/, '');
67
204
  const name = rel.replace(/[\\/]/g, '.');
68
- const mod = await import(__rewriteRelativeImportExtension(scriptPath));
205
+ const mod = await import(__rewriteRelativeImportExtension(/* @vite-ignore */ `${scriptPath}?t=${Date.now()}`));
69
206
  const handler = mod.default;
70
207
  // Extract param schema from lexicon for validation and defaults
71
208
  const lexicon = getLexicon(name);
@@ -89,51 +226,84 @@ export async function initXrpc(xrpcDir) {
89
226
  throw new InvalidRequestError(`Missing required parameter: ${param}`, 'InvalidRequest');
90
227
  }
91
228
  }
92
- const ctx = {
93
- db: { query: querySQL, run: runSQL },
94
- params,
95
- input: input || {},
96
- cursor,
97
- limit,
98
- viewer,
99
- packCursor,
100
- unpackCursor,
101
- isTakendown: isTakendownDid,
102
- filterTakendownDids,
103
- search: searchRecords,
104
- resolve: resolveRecords,
105
- lookup: async (collection, field, values) => {
106
- if (values.length === 0)
107
- return new Map();
108
- const unique = [...new Set(values.filter(Boolean))];
109
- return lookupByFieldBatch(collection, field, unique);
110
- },
111
- count: async (collection, field, values) => {
112
- if (values.length === 0)
113
- return new Map();
114
- const unique = [...new Set(values.filter(Boolean))];
115
- return countByFieldBatch(collection, field, unique);
116
- },
117
- exists: async (collection, filters) => {
118
- const conditions = Object.entries(filters).map(([field, value]) => ({ field, value }));
119
- const uri = await findUriByFields(collection, conditions);
120
- return uri !== null;
121
- },
122
- labels: queryLabelsForUris,
123
- blobUrl,
124
- };
229
+ const ctx = buildXrpcContext(params, cursor, limit, viewer, input);
125
230
  return handler.handler(ctx);
126
231
  },
127
232
  });
128
233
  log(`[xrpc] discovered: ${name}`);
129
234
  }
130
235
  }
236
+ /** Register a single XRPC handler from a scanned server/ module. */
237
+ export function registerXrpcHandler(nsid, handlerModule) {
238
+ const lexicon = getLexicon(nsid);
239
+ const paramsDef = lexicon?.defs?.main?.parameters;
240
+ const requiredParams = paramsDef?.required || [];
241
+ const paramProperties = paramsDef?.properties || {};
242
+ handlers.set(nsid, {
243
+ name: nsid,
244
+ execute: async (params, cursor, limit, viewer, input) => {
245
+ for (const [key, def] of Object.entries(paramProperties)) {
246
+ if (params[key] == null && def.default != null) {
247
+ params[key] = String(def.default);
248
+ }
249
+ if (params[key] != null && def.type === 'integer') {
250
+ params[key] = Number(params[key]);
251
+ }
252
+ }
253
+ for (const param of requiredParams) {
254
+ if (!params[param]) {
255
+ throw new InvalidRequestError(`Missing required parameter: ${param}`, 'InvalidRequest');
256
+ }
257
+ }
258
+ const ctx = buildXrpcContext(params, cursor, limit, viewer, input);
259
+ return handlerModule.handler(ctx);
260
+ },
261
+ });
262
+ }
263
+ /** Execute a registered XRPC handler by name. Returns null if no handler matches. */
131
264
  export async function executeXrpc(name, params, cursor, limit, viewer, input) {
132
265
  const handler = handlers.get(name);
133
266
  if (!handler)
134
267
  return null;
135
- return handler.execute(params, cursor, limit, viewer || null, input);
268
+ const elapsed = timer();
269
+ try {
270
+ const result = await handler.execute(params, cursor, limit, viewer || null, input);
271
+ emit('xrpc', name, { duration_ms: elapsed(), params, cursor, limit, viewer: viewer?.did });
272
+ return result;
273
+ }
274
+ catch (err) {
275
+ emit('xrpc', name, { duration_ms: elapsed(), params, cursor, limit, viewer: viewer?.did, error: err.message });
276
+ throw err;
277
+ }
278
+ }
279
+ /** Call a registered XRPC handler directly (no HTTP). For use in SSR renderers. */
280
+ export async function callXrpc(nsid, params = {}, input) {
281
+ const viewer = globalThis.__hatk_viewer ?? null;
282
+ // In externalized module context (e.g. SSR), delegate to the runner's callXrpc via globalThis.
283
+ // The runner's module instance has all registered handlers; this (Node's) instance may not.
284
+ if (handlers.size === 0 && globalThis.__hatk_callXrpc) {
285
+ return globalThis.__hatk_callXrpc(nsid, params, input);
286
+ }
287
+ const stringParams = {};
288
+ for (const [k, v] of Object.entries(params)) {
289
+ if (v != null)
290
+ stringParams[k] = String(v);
291
+ }
292
+ const limit = params.limit ? Number(params.limit) : 20;
293
+ const cursor = params.cursor ?? undefined;
294
+ const result = await executeXrpc(nsid, stringParams, cursor, limit, viewer, input);
295
+ if (result === null)
296
+ throw new Error(`No XRPC handler registered for ${nsid}`);
297
+ return result;
298
+ }
299
+ /**
300
+ * Register a core XRPC handler directly (no XrpcContext wrapping).
301
+ * Used for built-in dev.hatk.* handlers that manage their own dependencies.
302
+ */
303
+ export function registerCoreXrpcHandler(nsid, fn) {
304
+ handlers.set(nsid, { name: nsid, execute: fn });
136
305
  }
306
+ /** Return all registered XRPC method names. */
137
307
  export function listXrpc() {
138
308
  return Array.from(handlers.keys());
139
309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatk/hatk",
3
- "version": "0.0.1-alpha.8",
3
+ "version": "0.0.1-alpha.81",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "hatk": "dist/cli.js"
@@ -20,27 +20,35 @@
20
20
  "./xrpc-client": "./dist/xrpc-client.js",
21
21
  "./views": "./dist/views.js",
22
22
  "./seed": "./dist/seed.js",
23
+ "./hooks": "./dist/hooks.js",
23
24
  "./setup": "./dist/setup.js",
24
25
  "./test": "./dist/test.js",
25
- "./test/browser": "./dist/test-browser.js",
26
- "./vite-plugin": "./dist/vite-plugin.js"
26
+ "./config": "./dist/config.js",
27
+ "./vite-plugin": "./dist/vite-plugin.js",
28
+ "./renderer": "./dist/renderer.js"
27
29
  },
28
30
  "scripts": {
29
- "build": "tsc -p tsconfig.build.json",
30
- "prepublishOnly": "npm run build"
31
+ "clean": "rm -rf dist",
32
+ "build": "npm run clean && tsc -p tsconfig.build.json && cp -r src/templates dist/templates && cp -r src/lexicons dist/lexicons",
33
+ "prepublishOnly": "npm run build",
34
+ "test": "vitest run"
31
35
  },
32
36
  "dependencies": {
33
- "@bigmoves/lexicon": "^0.2.1",
37
+ "@bigmoves/lexicon": "^0.2.2",
34
38
  "@duckdb/node-api": "^1.4.4-r.1",
35
39
  "@hatk/oauth-client": "*",
36
40
  "@resvg/resvg-js": "^2.6.2",
37
- "satori": "^0.19.2",
41
+ "better-sqlite3": "^12.6.2",
42
+ "satori": "^0.28.1",
38
43
  "vitest": "^4",
39
44
  "yaml": "^2.7.0"
40
45
  },
41
46
  "devDependencies": {
42
- "@playwright/test": "^1.58.2",
47
+ "@types/better-sqlite3": "^7.6.13",
43
48
  "@types/react": "^19.2.14",
44
- "vite": "^6"
49
+ "vite": "^8.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "vite": "^8.0.0"
45
53
  }
46
54
  }