@hatk/hatk 0.0.1-alpha.10 → 0.0.1-alpha.101

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 (222) hide show
  1. package/dist/adapter.d.ts +19 -0
  2. package/dist/adapter.d.ts.map +1 -0
  3. package/dist/adapter.js +113 -0
  4. package/dist/backfill.d.ts +32 -2
  5. package/dist/backfill.d.ts.map +1 -1
  6. package/dist/backfill.js +154 -51
  7. package/dist/car.d.ts +20 -0
  8. package/dist/car.d.ts.map +1 -1
  9. package/dist/car.js +108 -0
  10. package/dist/cli.js +247 -1043
  11. package/dist/config.d.ts +145 -1
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +61 -8
  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} +94 -6
  30. package/dist/database/db.d.ts.map +1 -0
  31. package/dist/database/db.js +1833 -0
  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} +122 -34
  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/database/schema.d.ts +91 -0
  45. package/dist/database/schema.d.ts.map +1 -0
  46. package/dist/{schema.js → database/schema.js} +153 -54
  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 +126 -0
  50. package/dist/feeds.d.ts +26 -8
  51. package/dist/feeds.d.ts.map +1 -1
  52. package/dist/feeds.js +72 -16
  53. package/dist/hooks.d.ts +102 -0
  54. package/dist/hooks.d.ts.map +1 -0
  55. package/dist/hooks.js +186 -0
  56. package/dist/hydrate.d.ts +55 -6
  57. package/dist/hydrate.d.ts.map +1 -1
  58. package/dist/hydrate.js +21 -20
  59. package/dist/indexer.d.ts +194 -3
  60. package/dist/indexer.d.ts.map +1 -1
  61. package/dist/indexer.js +620 -92
  62. package/dist/jetstream.d.ts +118 -0
  63. package/dist/jetstream.d.ts.map +1 -0
  64. package/dist/jetstream.js +238 -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/lex-types.d.ts +2 -0
  69. package/dist/lex-types.d.ts.map +1 -1
  70. package/dist/lexicon-resolve.d.ts.map +1 -1
  71. package/dist/lexicon-resolve.js +27 -112
  72. package/dist/lexicons/com/atproto/label/defs.json +75 -0
  73. package/dist/lexicons/com/atproto/moderation/defs.json +30 -0
  74. package/dist/lexicons/com/atproto/repo/strongRef.json +21 -0
  75. package/dist/lexicons/dev/hatk/applyWrites.json +87 -0
  76. package/dist/lexicons/dev/hatk/createRecord.json +40 -0
  77. package/dist/lexicons/dev/hatk/createReport.json +48 -0
  78. package/dist/lexicons/dev/hatk/deleteRecord.json +25 -0
  79. package/dist/lexicons/dev/hatk/describeCollections.json +41 -0
  80. package/dist/lexicons/dev/hatk/describeFeeds.json +29 -0
  81. package/dist/lexicons/dev/hatk/describeLabels.json +45 -0
  82. package/dist/lexicons/dev/hatk/getFeed.json +30 -0
  83. package/dist/lexicons/dev/hatk/getPreferences.json +19 -0
  84. package/dist/lexicons/dev/hatk/getRecord.json +26 -0
  85. package/dist/lexicons/dev/hatk/getRecords.json +32 -0
  86. package/dist/lexicons/dev/hatk/putPreference.json +28 -0
  87. package/dist/lexicons/dev/hatk/putRecord.json +41 -0
  88. package/dist/lexicons/dev/hatk/searchRecords.json +32 -0
  89. package/dist/lexicons/dev/hatk/uploadBlob.json +23 -0
  90. package/dist/logger.d.ts +29 -0
  91. package/dist/logger.d.ts.map +1 -1
  92. package/dist/logger.js +29 -0
  93. package/dist/main.js +196 -75
  94. package/dist/mst.d.ts +15 -0
  95. package/dist/mst.d.ts.map +1 -1
  96. package/dist/mst.js +13 -0
  97. package/dist/oauth/db.d.ts +27 -1
  98. package/dist/oauth/db.d.ts.map +1 -1
  99. package/dist/oauth/db.js +80 -19
  100. package/dist/oauth/discovery.d.ts +10 -0
  101. package/dist/oauth/discovery.d.ts.map +1 -1
  102. package/dist/oauth/discovery.js +54 -2
  103. package/dist/oauth/server.d.ts +131 -1
  104. package/dist/oauth/server.d.ts.map +1 -1
  105. package/dist/oauth/server.js +504 -39
  106. package/dist/oauth/service-describe.d.ts +42 -0
  107. package/dist/oauth/service-describe.d.ts.map +1 -0
  108. package/dist/oauth/service-describe.js +108 -0
  109. package/dist/oauth/session.d.ts +32 -0
  110. package/dist/oauth/session.d.ts.map +1 -0
  111. package/dist/oauth/session.js +131 -0
  112. package/dist/opengraph.d.ts +10 -0
  113. package/dist/opengraph.d.ts.map +1 -1
  114. package/dist/opengraph.js +94 -42
  115. package/dist/pds-proxy.d.ts +92 -0
  116. package/dist/pds-proxy.d.ts.map +1 -0
  117. package/dist/pds-proxy.js +396 -0
  118. package/dist/private-collections.d.ts +13 -0
  119. package/dist/private-collections.d.ts.map +1 -0
  120. package/dist/private-collections.js +27 -0
  121. package/dist/push.d.ts +54 -0
  122. package/dist/push.d.ts.map +1 -0
  123. package/dist/push.js +367 -0
  124. package/dist/renderer.d.ts +27 -0
  125. package/dist/renderer.d.ts.map +1 -0
  126. package/dist/renderer.js +46 -0
  127. package/dist/resolve-hatk.d.ts +6 -0
  128. package/dist/resolve-hatk.d.ts.map +1 -0
  129. package/dist/resolve-hatk.js +20 -0
  130. package/dist/response.d.ts +16 -0
  131. package/dist/response.d.ts.map +1 -0
  132. package/dist/response.js +69 -0
  133. package/dist/scanner.d.ts +21 -0
  134. package/dist/scanner.d.ts.map +1 -0
  135. package/dist/scanner.js +88 -0
  136. package/dist/seed.d.ts +19 -0
  137. package/dist/seed.d.ts.map +1 -1
  138. package/dist/seed.js +43 -4
  139. package/dist/server-init.d.ts +8 -0
  140. package/dist/server-init.d.ts.map +1 -0
  141. package/dist/server-init.js +62 -0
  142. package/dist/server.d.ts +34 -3
  143. package/dist/server.d.ts.map +1 -1
  144. package/dist/server.js +1033 -649
  145. package/dist/setup.d.ts +28 -1
  146. package/dist/setup.d.ts.map +1 -1
  147. package/dist/setup.js +50 -3
  148. package/dist/spaces/blob.d.ts +112 -0
  149. package/dist/spaces/blob.d.ts.map +1 -0
  150. package/dist/spaces/blob.js +460 -0
  151. package/dist/spaces/credential.d.ts +66 -0
  152. package/dist/spaces/credential.d.ts.map +1 -0
  153. package/dist/spaces/credential.js +175 -0
  154. package/dist/spaces/engine.d.ts +97 -0
  155. package/dist/spaces/engine.d.ts.map +1 -0
  156. package/dist/spaces/engine.js +563 -0
  157. package/dist/spaces/guard.d.ts +41 -0
  158. package/dist/spaces/guard.d.ts.map +1 -0
  159. package/dist/spaces/guard.js +79 -0
  160. package/dist/spaces/identity.d.ts +37 -0
  161. package/dist/spaces/identity.d.ts.map +1 -0
  162. package/dist/spaces/identity.js +88 -0
  163. package/dist/spaces/index.d.ts +55 -0
  164. package/dist/spaces/index.d.ts.map +1 -0
  165. package/dist/spaces/index.js +133 -0
  166. package/dist/spaces/notify.d.ts +60 -0
  167. package/dist/spaces/notify.d.ts.map +1 -0
  168. package/dist/spaces/notify.js +128 -0
  169. package/dist/spaces/records.d.ts +37 -0
  170. package/dist/spaces/records.d.ts.map +1 -0
  171. package/dist/spaces/records.js +63 -0
  172. package/dist/spaces/signature.d.ts +36 -0
  173. package/dist/spaces/signature.d.ts.map +1 -0
  174. package/dist/spaces/signature.js +83 -0
  175. package/dist/spaces/store.d.ts +51 -0
  176. package/dist/spaces/store.d.ts.map +1 -0
  177. package/dist/spaces/store.js +99 -0
  178. package/dist/spaces/uri.d.ts +60 -0
  179. package/dist/spaces/uri.d.ts.map +1 -0
  180. package/dist/spaces/uri.js +97 -0
  181. package/dist/spaces/verify.d.ts +46 -0
  182. package/dist/spaces/verify.d.ts.map +1 -0
  183. package/dist/spaces/verify.js +94 -0
  184. package/dist/spaces/viewer.d.ts +51 -0
  185. package/dist/spaces/viewer.d.ts.map +1 -0
  186. package/dist/spaces/viewer.js +167 -0
  187. package/dist/spaces/visibility.d.ts +57 -0
  188. package/dist/spaces/visibility.d.ts.map +1 -0
  189. package/dist/spaces/visibility.js +81 -0
  190. package/dist/templates/feed.tpl +18 -0
  191. package/dist/templates/hook.tpl +5 -0
  192. package/dist/templates/label.tpl +15 -0
  193. package/dist/templates/og.tpl +17 -0
  194. package/dist/templates/seed.tpl +11 -0
  195. package/dist/templates/setup.tpl +5 -0
  196. package/dist/templates/test-feed.tpl +19 -0
  197. package/dist/templates/test-xrpc.tpl +19 -0
  198. package/dist/templates/xrpc.tpl +53 -0
  199. package/dist/test.d.ts +3 -1
  200. package/dist/test.d.ts.map +1 -1
  201. package/dist/test.js +60 -36
  202. package/dist/views.js +1 -1
  203. package/dist/vite-plugin.d.ts +1 -1
  204. package/dist/vite-plugin.d.ts.map +1 -1
  205. package/dist/vite-plugin.js +254 -66
  206. package/dist/xrpc.d.ts +122 -12
  207. package/dist/xrpc.d.ts.map +1 -1
  208. package/dist/xrpc.js +270 -55
  209. package/package.json +28 -9
  210. package/public/admin-auth.js +271 -306
  211. package/public/admin.html +177 -61
  212. package/dist/db.d.ts.map +0 -1
  213. package/dist/db.js +0 -1361
  214. package/dist/fts.d.ts.map +0 -1
  215. package/dist/oauth/hooks.d.ts +0 -10
  216. package/dist/oauth/hooks.d.ts.map +0 -1
  217. package/dist/oauth/hooks.js +0 -40
  218. package/dist/schema.d.ts +0 -51
  219. package/dist/schema.d.ts.map +0 -1
  220. package/dist/test-browser.d.ts +0 -14
  221. package/dist/test-browser.d.ts.map +0 -1
  222. package/dist/test-browser.js +0 -26
package/dist/car.js CHANGED
@@ -78,6 +78,114 @@ export class LazyBlockMap {
78
78
  this.offsets.clear();
79
79
  }
80
80
  }
81
+ /**
82
+ * Parses a CARv1 stream incrementally from a `ReadableStream`.
83
+ *
84
+ * Instead of buffering the entire CAR into a single ArrayBuffer, this reads
85
+ * chunks from the stream and parses blocks as they arrive. Each block's data
86
+ * is `.slice()`d into its own small `Uint8Array`, allowing V8 to GC individual
87
+ * blocks as they're consumed during the MST walk.
88
+ *
89
+ * This is critical for backfill where multiple workers download 30-90MB CARs
90
+ * concurrently — buffered downloads cause OOMs because `ArrayBuffer` memory
91
+ * is "external" to V8's heap and not controlled by `--max-old-space-size`.
92
+ *
93
+ * @param body - The response body stream (e.g. `res.body` from `fetch()`)
94
+ * @returns `roots` — root CID strings; `blocks` — map of CID → block data; `byteLength` — total bytes read
95
+ */
96
+ export async function parseCarStream(body) {
97
+ const reader = body.getReader();
98
+ // Growable buffer with position tracking. We reuse a single allocation and
99
+ // compact (shift data to front) when the read position passes the midpoint,
100
+ // avoiding per-chunk allocations and subarray references that pin old memory.
101
+ let buf = new Uint8Array(64 * 1024);
102
+ let pos = 0; // read cursor
103
+ let len = 0; // bytes of valid data in buf
104
+ let byteLength = 0;
105
+ // Ensure at least `need` bytes are available at buf[pos..pos+need)
106
+ async function fill(need) {
107
+ while (len - pos < need) {
108
+ const { done, value } = await reader.read();
109
+ if (done)
110
+ return len - pos >= need;
111
+ byteLength += value.length;
112
+ // Compact: shift remaining data to front when read cursor passes midpoint
113
+ if (pos > 0 && pos > buf.length >>> 1) {
114
+ buf.copyWithin(0, pos, len);
115
+ len -= pos;
116
+ pos = 0;
117
+ }
118
+ // Grow if needed
119
+ const required = len + value.length;
120
+ if (required > buf.length) {
121
+ const newBuf = new Uint8Array(Math.max(required, buf.length * 2));
122
+ newBuf.set(buf.subarray(0, len));
123
+ buf = newBuf;
124
+ }
125
+ buf.set(value, len);
126
+ len += value.length;
127
+ }
128
+ return true;
129
+ }
130
+ function consume(n) {
131
+ pos += n;
132
+ }
133
+ // Read a varint starting at buf[pos]
134
+ function readVarintFromBuf() {
135
+ let value = 0;
136
+ let shift = 0;
137
+ let p = pos;
138
+ while (p < len) {
139
+ const byte = buf[p++];
140
+ value |= (byte & 0x7f) << shift;
141
+ if ((byte & 0x80) === 0)
142
+ return [value, p - pos];
143
+ shift += 7;
144
+ if (shift > 35)
145
+ throw new Error('Varint too long');
146
+ }
147
+ throw new Error('Unexpected end of varint');
148
+ }
149
+ // Parse header: varint(headerLen) + CBOR(header)
150
+ if (!(await fill(1)))
151
+ throw new Error('Empty CAR stream');
152
+ // Prefetch up to 10 bytes for the varint; readVarintFromBuf bounds to `len`
153
+ await fill(10);
154
+ const [headerLen, headerVarintSize] = readVarintFromBuf();
155
+ consume(headerVarintSize);
156
+ if (!(await fill(headerLen)))
157
+ throw new Error('Truncated CAR header');
158
+ // .slice() copies out of the reusable buffer
159
+ const headerSlice = buf.slice(pos, pos + headerLen);
160
+ const { value: header } = cborDecode(headerSlice);
161
+ consume(headerLen);
162
+ const roots = (header.roots || []).map((root) => root?.$link ?? cidToString(root));
163
+ // Parse blocks
164
+ const blocks = new Map();
165
+ while (true) {
166
+ if (!(await fill(1)))
167
+ break;
168
+ // Prefetch up to 10 bytes for the varint; readVarintFromBuf bounds to `len`
169
+ await fill(10);
170
+ const [blockLen, blockVarintSize] = readVarintFromBuf();
171
+ consume(blockVarintSize);
172
+ if (blockLen === 0)
173
+ break;
174
+ if (!(await fill(blockLen)))
175
+ throw new Error('Truncated CAR block');
176
+ const [cidBytes, afterCid] = parseCidFromBytes(buf, pos);
177
+ const cid = cidToString(cidBytes);
178
+ const cidLen = afterCid - pos;
179
+ // .slice() creates an independent copy — the buffer can be reused
180
+ const data = buf.slice(afterCid, afterCid + blockLen - cidLen);
181
+ blocks.set(cid, data);
182
+ consume(blockLen);
183
+ }
184
+ reader.releaseLock();
185
+ // Release the internal buffer
186
+ buf = null;
187
+ return { roots, blocks, byteLength };
188
+ }
81
189
  /**
82
190
  * Parses a CARv1 binary frame into its root CIDs and a lazy block map.
83
191
  *