@elaraai/e3-web 0.0.0-stage → 1.0.86

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 (303) hide show
  1. package/LICENSE.md +54 -0
  2. package/README.md +395 -2
  3. package/dist/src/app.d.ts +91 -0
  4. package/dist/src/app.d.ts.map +1 -0
  5. package/dist/src/app.js +112 -0
  6. package/dist/src/app.js.map +1 -0
  7. package/dist/src/bridge/bridge.spec.d.ts +6 -0
  8. package/dist/src/bridge/bridge.spec.d.ts.map +1 -0
  9. package/dist/src/bridge/bridge.spec.js +56 -0
  10. package/dist/src/bridge/bridge.spec.js.map +1 -0
  11. package/dist/src/bridge/page.d.ts +149 -0
  12. package/dist/src/bridge/page.d.ts.map +1 -0
  13. package/dist/src/bridge/page.js +328 -0
  14. package/dist/src/bridge/page.js.map +1 -0
  15. package/dist/src/bridge/protocol.d.ts +181 -0
  16. package/dist/src/bridge/protocol.d.ts.map +1 -0
  17. package/dist/src/bridge/protocol.js +113 -0
  18. package/dist/src/bridge/protocol.js.map +1 -0
  19. package/dist/src/bridge/worker.d.ts +124 -0
  20. package/dist/src/bridge/worker.d.ts.map +1 -0
  21. package/dist/src/bridge/worker.js +185 -0
  22. package/dist/src/bridge/worker.js.map +1 -0
  23. package/dist/src/browser/bridge.page.d.ts +12 -0
  24. package/dist/src/browser/bridge.page.d.ts.map +1 -0
  25. package/dist/src/browser/bridge.page.js +79 -0
  26. package/dist/src/browser/bridge.page.js.map +1 -0
  27. package/dist/src/browser/bridge.spec.d.ts +6 -0
  28. package/dist/src/browser/bridge.spec.d.ts.map +1 -0
  29. package/dist/src/browser/bridge.spec.js +105 -0
  30. package/dist/src/browser/bridge.spec.js.map +1 -0
  31. package/dist/src/browser/bridge.worker.d.ts +6 -0
  32. package/dist/src/browser/bridge.worker.d.ts.map +1 -0
  33. package/dist/src/browser/bridge.worker.js +35 -0
  34. package/dist/src/browser/bridge.worker.js.map +1 -0
  35. package/dist/src/browser/compliance.d.ts +68 -0
  36. package/dist/src/browser/compliance.d.ts.map +1 -0
  37. package/dist/src/browser/compliance.js +30 -0
  38. package/dist/src/browser/compliance.js.map +1 -0
  39. package/dist/src/browser/compliance.page.d.ts +6 -0
  40. package/dist/src/browser/compliance.page.d.ts.map +1 -0
  41. package/dist/src/browser/compliance.page.js +204 -0
  42. package/dist/src/browser/compliance.page.js.map +1 -0
  43. package/dist/src/browser/compliance.spec.d.ts +6 -0
  44. package/dist/src/browser/compliance.spec.d.ts.map +1 -0
  45. package/dist/src/browser/compliance.spec.js +147 -0
  46. package/dist/src/browser/compliance.spec.js.map +1 -0
  47. package/dist/src/browser/e3-api-1.spec.d.ts +6 -0
  48. package/dist/src/browser/e3-api-1.spec.d.ts.map +1 -0
  49. package/dist/src/browser/e3-api-1.spec.js +12 -0
  50. package/dist/src/browser/e3-api-1.spec.js.map +1 -0
  51. package/dist/src/browser/e3-api-2.spec.d.ts +6 -0
  52. package/dist/src/browser/e3-api-2.spec.d.ts.map +1 -0
  53. package/dist/src/browser/e3-api-2.spec.js +12 -0
  54. package/dist/src/browser/e3-api-2.spec.js.map +1 -0
  55. package/dist/src/browser/e3-api-3.spec.d.ts +6 -0
  56. package/dist/src/browser/e3-api-3.spec.d.ts.map +1 -0
  57. package/dist/src/browser/e3-api-3.spec.js +12 -0
  58. package/dist/src/browser/e3-api-3.spec.js.map +1 -0
  59. package/dist/src/browser/e3-api-parts.spec.d.ts +6 -0
  60. package/dist/src/browser/e3-api-parts.spec.d.ts.map +1 -0
  61. package/dist/src/browser/e3-api-parts.spec.js +45 -0
  62. package/dist/src/browser/e3-api-parts.spec.js.map +1 -0
  63. package/dist/src/browser/e3-api.d.ts +28 -0
  64. package/dist/src/browser/e3-api.d.ts.map +1 -0
  65. package/dist/src/browser/e3-api.js +144 -0
  66. package/dist/src/browser/e3-api.js.map +1 -0
  67. package/dist/src/browser/e3-client.worker.d.ts +6 -0
  68. package/dist/src/browser/e3-client.worker.d.ts.map +1 -0
  69. package/dist/src/browser/e3-client.worker.js +19 -0
  70. package/dist/src/browser/e3-client.worker.js.map +1 -0
  71. package/dist/src/browser/e3-forward.d.ts +27 -0
  72. package/dist/src/browser/e3-forward.d.ts.map +1 -0
  73. package/dist/src/browser/e3-forward.js +81 -0
  74. package/dist/src/browser/e3-forward.js.map +1 -0
  75. package/dist/src/browser/e3-forward.spec.d.ts +6 -0
  76. package/dist/src/browser/e3-forward.spec.d.ts.map +1 -0
  77. package/dist/src/browser/e3-forward.spec.js +84 -0
  78. package/dist/src/browser/e3-forward.spec.js.map +1 -0
  79. package/dist/src/browser/e3-port.worker.d.ts +6 -0
  80. package/dist/src/browser/e3-port.worker.d.ts.map +1 -0
  81. package/dist/src/browser/e3-port.worker.js +21 -0
  82. package/dist/src/browser/e3-port.worker.js.map +1 -0
  83. package/dist/src/browser/e3-unit.worker.d.ts +6 -0
  84. package/dist/src/browser/e3-unit.worker.d.ts.map +1 -0
  85. package/dist/src/browser/e3-unit.worker.js +18 -0
  86. package/dist/src/browser/e3-unit.worker.js.map +1 -0
  87. package/dist/src/browser/e3-wire.d.ts +43 -0
  88. package/dist/src/browser/e3-wire.d.ts.map +1 -0
  89. package/dist/src/browser/e3-wire.js +32 -0
  90. package/dist/src/browser/e3-wire.js.map +1 -0
  91. package/dist/src/browser/e3.page.d.ts +21 -0
  92. package/dist/src/browser/e3.page.d.ts.map +1 -0
  93. package/dist/src/browser/e3.page.js +119 -0
  94. package/dist/src/browser/e3.page.js.map +1 -0
  95. package/dist/src/browser/e3.spec.d.ts +6 -0
  96. package/dist/src/browser/e3.spec.d.ts.map +1 -0
  97. package/dist/src/browser/e3.spec.js +358 -0
  98. package/dist/src/browser/e3.spec.js.map +1 -0
  99. package/dist/src/browser/e3.worker.d.ts +6 -0
  100. package/dist/src/browser/e3.worker.d.ts.map +1 -0
  101. package/dist/src/browser/e3.worker.js +38 -0
  102. package/dist/src/browser/e3.worker.js.map +1 -0
  103. package/dist/src/browser/harness.d.ts +175 -0
  104. package/dist/src/browser/harness.d.ts.map +1 -0
  105. package/dist/src/browser/harness.js +375 -0
  106. package/dist/src/browser/harness.js.map +1 -0
  107. package/dist/src/browser/page.d.ts +47 -0
  108. package/dist/src/browser/page.d.ts.map +1 -0
  109. package/dist/src/browser/page.js +47 -0
  110. package/dist/src/browser/page.js.map +1 -0
  111. package/dist/src/browser/repository.page.d.ts +85 -0
  112. package/dist/src/browser/repository.page.d.ts.map +1 -0
  113. package/dist/src/browser/repository.page.js +271 -0
  114. package/dist/src/browser/repository.page.js.map +1 -0
  115. package/dist/src/browser/runner.page.d.ts +6 -0
  116. package/dist/src/browser/runner.page.d.ts.map +1 -0
  117. package/dist/src/browser/runner.page.js +62 -0
  118. package/dist/src/browser/runner.page.js.map +1 -0
  119. package/dist/src/browser/runner.spec.d.ts +6 -0
  120. package/dist/src/browser/runner.spec.d.ts.map +1 -0
  121. package/dist/src/browser/runner.spec.js +46 -0
  122. package/dist/src/browser/runner.spec.js.map +1 -0
  123. package/dist/src/browser/storage.page.d.ts +6 -0
  124. package/dist/src/browser/storage.page.d.ts.map +1 -0
  125. package/dist/src/browser/storage.page.js +289 -0
  126. package/dist/src/browser/storage.page.js.map +1 -0
  127. package/dist/src/browser/storage.spec.d.ts +6 -0
  128. package/dist/src/browser/storage.spec.d.ts.map +1 -0
  129. package/dist/src/browser/storage.spec.js +211 -0
  130. package/dist/src/browser/storage.spec.js.map +1 -0
  131. package/dist/src/browser/unit.worker.d.ts +6 -0
  132. package/dist/src/browser/unit.worker.d.ts.map +1 -0
  133. package/dist/src/browser/unit.worker.js +17 -0
  134. package/dist/src/browser/unit.worker.js.map +1 -0
  135. package/dist/src/execution/WebTaskRunner.d.ts +159 -0
  136. package/dist/src/execution/WebTaskRunner.d.ts.map +1 -0
  137. package/dist/src/execution/WebTaskRunner.js +581 -0
  138. package/dist/src/execution/WebTaskRunner.js.map +1 -0
  139. package/dist/src/execution/WebTaskRunner.spec.d.ts +6 -0
  140. package/dist/src/execution/WebTaskRunner.spec.d.ts.map +1 -0
  141. package/dist/src/execution/WebTaskRunner.spec.js +91 -0
  142. package/dist/src/execution/WebTaskRunner.spec.js.map +1 -0
  143. package/dist/src/execution/e3-platform.d.ts +41 -0
  144. package/dist/src/execution/e3-platform.d.ts.map +1 -0
  145. package/dist/src/execution/e3-platform.js +52 -0
  146. package/dist/src/execution/e3-platform.js.map +1 -0
  147. package/dist/src/execution/in-process.d.ts +32 -0
  148. package/dist/src/execution/in-process.d.ts.map +1 -0
  149. package/dist/src/execution/in-process.js +89 -0
  150. package/dist/src/execution/in-process.js.map +1 -0
  151. package/dist/src/execution/pool.d.ts +172 -0
  152. package/dist/src/execution/pool.d.ts.map +1 -0
  153. package/dist/src/execution/pool.js +352 -0
  154. package/dist/src/execution/pool.js.map +1 -0
  155. package/dist/src/execution/pool.spec.d.ts +6 -0
  156. package/dist/src/execution/pool.spec.d.ts.map +1 -0
  157. package/dist/src/execution/pool.spec.js +252 -0
  158. package/dist/src/execution/pool.spec.js.map +1 -0
  159. package/dist/src/execution/protocol.d.ts +108 -0
  160. package/dist/src/execution/protocol.d.ts.map +1 -0
  161. package/dist/src/execution/protocol.js +27 -0
  162. package/dist/src/execution/protocol.js.map +1 -0
  163. package/dist/src/execution/unit-server.d.ts +131 -0
  164. package/dist/src/execution/unit-server.d.ts.map +1 -0
  165. package/dist/src/execution/unit-server.js +142 -0
  166. package/dist/src/execution/unit-server.js.map +1 -0
  167. package/dist/src/index.d.ts +39 -0
  168. package/dist/src/index.d.ts.map +1 -0
  169. package/dist/src/index.js +37 -0
  170. package/dist/src/index.js.map +1 -0
  171. package/dist/src/index.spec.d.ts +6 -0
  172. package/dist/src/index.spec.d.ts.map +1 -0
  173. package/dist/src/index.spec.js +212 -0
  174. package/dist/src/index.spec.js.map +1 -0
  175. package/dist/src/node.d.ts +12 -0
  176. package/dist/src/node.d.ts.map +1 -0
  177. package/dist/src/node.js +12 -0
  178. package/dist/src/node.js.map +1 -0
  179. package/dist/src/storage/WebStateStore.d.ts +64 -0
  180. package/dist/src/storage/WebStateStore.d.ts.map +1 -0
  181. package/dist/src/storage/WebStateStore.js +237 -0
  182. package/dist/src/storage/WebStateStore.js.map +1 -0
  183. package/dist/src/storage/WebStorage.d.ts +225 -0
  184. package/dist/src/storage/WebStorage.d.ts.map +1 -0
  185. package/dist/src/storage/WebStorage.js +1462 -0
  186. package/dist/src/storage/WebStorage.js.map +1 -0
  187. package/dist/src/storage/adapters.d.ts +610 -0
  188. package/dist/src/storage/adapters.d.ts.map +1 -0
  189. package/dist/src/storage/adapters.js +246 -0
  190. package/dist/src/storage/adapters.js.map +1 -0
  191. package/dist/src/storage/indexeddb.d.ts +93 -0
  192. package/dist/src/storage/indexeddb.d.ts.map +1 -0
  193. package/dist/src/storage/indexeddb.js +384 -0
  194. package/dist/src/storage/indexeddb.js.map +1 -0
  195. package/dist/src/storage/indexeddb.spec.d.ts +6 -0
  196. package/dist/src/storage/indexeddb.spec.d.ts.map +1 -0
  197. package/dist/src/storage/indexeddb.spec.js +77 -0
  198. package/dist/src/storage/indexeddb.spec.js.map +1 -0
  199. package/dist/src/storage/memory.d.ts +275 -0
  200. package/dist/src/storage/memory.d.ts.map +1 -0
  201. package/dist/src/storage/memory.js +724 -0
  202. package/dist/src/storage/memory.js.map +1 -0
  203. package/dist/src/storage/memory.spec.d.ts +6 -0
  204. package/dist/src/storage/memory.spec.d.ts.map +1 -0
  205. package/dist/src/storage/memory.spec.js +71 -0
  206. package/dist/src/storage/memory.spec.js.map +1 -0
  207. package/dist/src/storage/node-files.d.ts +38 -0
  208. package/dist/src/storage/node-files.d.ts.map +1 -0
  209. package/dist/src/storage/node-files.js +148 -0
  210. package/dist/src/storage/node-files.js.map +1 -0
  211. package/dist/src/storage/node-files.spec.d.ts +6 -0
  212. package/dist/src/storage/node-files.spec.d.ts.map +1 -0
  213. package/dist/src/storage/node-files.spec.js +40 -0
  214. package/dist/src/storage/node-files.spec.js.map +1 -0
  215. package/dist/src/storage/opfs.d.ts +145 -0
  216. package/dist/src/storage/opfs.d.ts.map +1 -0
  217. package/dist/src/storage/opfs.js +514 -0
  218. package/dist/src/storage/opfs.js.map +1 -0
  219. package/dist/src/storage/opfs.spec.d.ts +6 -0
  220. package/dist/src/storage/opfs.spec.d.ts.map +1 -0
  221. package/dist/src/storage/opfs.spec.js +51 -0
  222. package/dist/src/storage/opfs.spec.js.map +1 -0
  223. package/dist/src/storage/record-keys.d.ts +78 -0
  224. package/dist/src/storage/record-keys.d.ts.map +1 -0
  225. package/dist/src/storage/record-keys.js +71 -0
  226. package/dist/src/storage/record-keys.js.map +1 -0
  227. package/dist/src/storage/stores.spec.d.ts +6 -0
  228. package/dist/src/storage/stores.spec.d.ts.map +1 -0
  229. package/dist/src/storage/stores.spec.js +326 -0
  230. package/dist/src/storage/stores.spec.js.map +1 -0
  231. package/dist/src/storage/web-locks.d.ts +103 -0
  232. package/dist/src/storage/web-locks.d.ts.map +1 -0
  233. package/dist/src/storage/web-locks.js +228 -0
  234. package/dist/src/storage/web-locks.js.map +1 -0
  235. package/dist/src/testing/adapter-contract.d.ts +116 -0
  236. package/dist/src/testing/adapter-contract.d.ts.map +1 -0
  237. package/dist/src/testing/adapter-contract.js +769 -0
  238. package/dist/src/testing/adapter-contract.js.map +1 -0
  239. package/dist/src/testing/assert.d.ts +75 -0
  240. package/dist/src/testing/assert.d.ts.map +1 -0
  241. package/dist/src/testing/assert.js +146 -0
  242. package/dist/src/testing/assert.js.map +1 -0
  243. package/dist/src/testing/assert.spec.d.ts +6 -0
  244. package/dist/src/testing/assert.spec.d.ts.map +1 -0
  245. package/dist/src/testing/assert.spec.js +62 -0
  246. package/dist/src/testing/assert.spec.js.map +1 -0
  247. package/dist/src/testing/bridge-contract.d.ts +55 -0
  248. package/dist/src/testing/bridge-contract.d.ts.map +1 -0
  249. package/dist/src/testing/bridge-contract.js +376 -0
  250. package/dist/src/testing/bridge-contract.js.map +1 -0
  251. package/dist/src/testing/bridge-handler.d.ts +35 -0
  252. package/dist/src/testing/bridge-handler.d.ts.map +1 -0
  253. package/dist/src/testing/bridge-handler.js +108 -0
  254. package/dist/src/testing/bridge-handler.js.map +1 -0
  255. package/dist/src/testing/callers.d.ts +29 -0
  256. package/dist/src/testing/callers.d.ts.map +1 -0
  257. package/dist/src/testing/callers.js +24 -0
  258. package/dist/src/testing/callers.js.map +1 -0
  259. package/dist/src/testing/e3-fixtures.d.ts +38 -0
  260. package/dist/src/testing/e3-fixtures.d.ts.map +1 -0
  261. package/dist/src/testing/e3-fixtures.js +126 -0
  262. package/dist/src/testing/e3-fixtures.js.map +1 -0
  263. package/dist/src/testing/hold-platform.d.ts +33 -0
  264. package/dist/src/testing/hold-platform.d.ts.map +1 -0
  265. package/dist/src/testing/hold-platform.js +41 -0
  266. package/dist/src/testing/hold-platform.js.map +1 -0
  267. package/dist/src/testing/runner-cases.d.ts +112 -0
  268. package/dist/src/testing/runner-cases.d.ts.map +1 -0
  269. package/dist/src/testing/runner-cases.js +959 -0
  270. package/dist/src/testing/runner-cases.js.map +1 -0
  271. package/dist/src/testing/runner-fixtures.d.ts +13 -0
  272. package/dist/src/testing/runner-fixtures.d.ts.map +1 -0
  273. package/dist/src/testing/runner-fixtures.js +173 -0
  274. package/dist/src/testing/runner-fixtures.js.map +1 -0
  275. package/dist/src/testing/test-platform.d.ts +73 -0
  276. package/dist/src/testing/test-platform.d.ts.map +1 -0
  277. package/dist/src/testing/test-platform.js +143 -0
  278. package/dist/src/testing/test-platform.js.map +1 -0
  279. package/dist/src/transfer/WebTransferBackend.d.ts +780 -0
  280. package/dist/src/transfer/WebTransferBackend.d.ts.map +1 -0
  281. package/dist/src/transfer/WebTransferBackend.js +1140 -0
  282. package/dist/src/transfer/WebTransferBackend.js.map +1 -0
  283. package/dist/src/transfer/WebTransferBackend.spec.d.ts +6 -0
  284. package/dist/src/transfer/WebTransferBackend.spec.d.ts.map +1 -0
  285. package/dist/src/transfer/WebTransferBackend.spec.js +582 -0
  286. package/dist/src/transfer/WebTransferBackend.spec.js.map +1 -0
  287. package/dist/src/transfer/endpoints.d.ts +46 -0
  288. package/dist/src/transfer/endpoints.d.ts.map +1 -0
  289. package/dist/src/transfer/endpoints.js +157 -0
  290. package/dist/src/transfer/endpoints.js.map +1 -0
  291. package/dist/src/units.d.ts +51 -0
  292. package/dist/src/units.d.ts.map +1 -0
  293. package/dist/src/units.js +74 -0
  294. package/dist/src/units.js.map +1 -0
  295. package/dist/src/worker.d.ts +126 -0
  296. package/dist/src/worker.d.ts.map +1 -0
  297. package/dist/src/worker.js +186 -0
  298. package/dist/src/worker.js.map +1 -0
  299. package/dist/src/worker.spec.d.ts +6 -0
  300. package/dist/src/worker.spec.d.ts.map +1 -0
  301. package/dist/src/worker.spec.js +195 -0
  302. package/dist/src/worker.spec.js.map +1 -0
  303. package/package.json +76 -3
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * A records transaction was used past its life: its work awaited something
7
+ * other than the transaction's own operations, or went on using the
8
+ * transaction once it had finished.
9
+ */
10
+ export class RecordsTransactionError extends Error {
11
+ constructor(reason) {
12
+ super(`records transaction: ${reason} — a transaction's work awaits its own operations and nothing else`);
13
+ this.name = 'RecordsTransactionError';
14
+ }
15
+ }
16
+ // =============================================================================
17
+ // Files
18
+ // =============================================================================
19
+ /**
20
+ * How many bytes a files adapter's read yields at a time, unless the adapter
21
+ * is made with another size: 1 MiB.
22
+ */
23
+ export const FILE_READ_CHUNK = 1024 * 1024;
24
+ /**
25
+ * A files adapter's read size, checked: a whole number of bytes greater than
26
+ * zero.
27
+ *
28
+ * @param options - How the adapter reads
29
+ * @returns The size its reads yield at a time
30
+ * @throws {RangeError} When the size given is not a whole number of bytes
31
+ * greater than zero
32
+ */
33
+ export function readChunkOf(options) {
34
+ const readChunk = options.readChunk ?? FILE_READ_CHUNK;
35
+ if (!(Number.isSafeInteger(readChunk) && readChunk > 0)) {
36
+ throw new RangeError(`a files adapter's read size is a whole number of bytes greater than zero, not ${readChunk}`);
37
+ }
38
+ return readChunk;
39
+ }
40
+ /**
41
+ * A file, or the directory a file is written into, is not there.
42
+ */
43
+ export class FileNotFoundError extends Error {
44
+ path;
45
+ /**
46
+ * @param path - The path that names nothing
47
+ */
48
+ constructor(path) {
49
+ super(`no such file or directory: ${path}`);
50
+ this.path = path;
51
+ this.name = 'FileNotFoundError';
52
+ }
53
+ }
54
+ // =============================================================================
55
+ // Shared
56
+ // =============================================================================
57
+ /**
58
+ * An adapter was used after it was closed.
59
+ */
60
+ export class AdapterClosedError extends Error {
61
+ adapter;
62
+ /**
63
+ * @param adapter - What was closed: `records`, `locks`, …
64
+ */
65
+ constructor(adapter) {
66
+ super(`the ${adapter} adapter is closed`);
67
+ this.adapter = adapter;
68
+ this.name = 'AdapterClosedError';
69
+ }
70
+ }
71
+ /**
72
+ * Compares two keys in the order records and blobs keep: part by part, a part
73
+ * by its UTF-16 code units, and a key before every key it is a prefix of.
74
+ *
75
+ * @param a - A key
76
+ * @param b - Another key
77
+ * @returns Less than zero when `a` sorts first, more when `b` does, and zero
78
+ * when they are the same key
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * [['b'], ['a', 'b'], ['a']].sort(compareKeys); // [['a'], ['a', 'b'], ['b']]
83
+ * ```
84
+ */
85
+ export function compareKeys(a, b) {
86
+ const common = Math.min(a.length, b.length);
87
+ for (let i = 0; i < common; i++) {
88
+ const x = a[i];
89
+ const y = b[i];
90
+ if (x !== y)
91
+ return x < y ? -1 : 1;
92
+ }
93
+ return a.length - b.length;
94
+ }
95
+ /**
96
+ * Answers whether a key is under a prefix: begins with the prefix's parts, or
97
+ * is the prefix.
98
+ *
99
+ * @param key - The key
100
+ * @param prefix - The prefix
101
+ * @returns Whether the key begins with every part of the prefix
102
+ */
103
+ export function isUnder(key, prefix) {
104
+ if (key.length < prefix.length)
105
+ return false;
106
+ for (let i = 0; i < prefix.length; i++) {
107
+ if (key[i] !== prefix[i])
108
+ return false;
109
+ }
110
+ return true;
111
+ }
112
+ /**
113
+ * Checks a record key is a list of strings.
114
+ *
115
+ * @param key - The key
116
+ * @throws {TypeError} When it is not
117
+ */
118
+ export function checkRecordKey(key) {
119
+ if (!Array.isArray(key) || !key.every((part) => typeof part === 'string')) {
120
+ throw new TypeError(`a record key is a list of strings, not ${describeKey(key)}`);
121
+ }
122
+ }
123
+ /**
124
+ * Checks a blob key has a part, and that none of its parts is empty.
125
+ *
126
+ * @param key - The key
127
+ * @throws {TypeError} When it has none, or an empty one
128
+ */
129
+ export function checkBlobKey(key) {
130
+ checkBlobPrefix(key);
131
+ if (key.length === 0)
132
+ throw new TypeError('a blob key has at least one part');
133
+ }
134
+ /**
135
+ * Checks a blob prefix: a list of strings none of which is empty, or `[]`.
136
+ *
137
+ * @param prefix - The prefix
138
+ * @throws {TypeError} When a part is not a string, or is empty
139
+ */
140
+ export function checkBlobPrefix(prefix) {
141
+ if (!Array.isArray(prefix) || !prefix.every((part) => typeof part === 'string' && part.length > 0)) {
142
+ throw new TypeError(`a blob key is a list of strings none of which is empty, not ${describeKey(prefix)}`);
143
+ }
144
+ }
145
+ /**
146
+ * Checks what a scan asks: a limit, when there is one, is a whole number
147
+ * greater than zero.
148
+ *
149
+ * @param options - The scan's options
150
+ * @throws {TypeError} When a bound is not a list of strings
151
+ * @throws {RangeError} When the limit is not a whole number greater than zero
152
+ */
153
+ export function checkScan(options) {
154
+ if (options.after !== undefined)
155
+ checkRecordKey(options.after);
156
+ if (options.before !== undefined)
157
+ checkRecordKey(options.before);
158
+ const { limit } = options;
159
+ if (limit !== undefined && !(Number.isSafeInteger(limit) && limit > 0)) {
160
+ throw new RangeError(`a scan's limit is a whole number greater than zero, not ${limit}`);
161
+ }
162
+ }
163
+ /**
164
+ * Checks a byte range: its offset and length are whole numbers of zero or
165
+ * more.
166
+ *
167
+ * @param offset - The byte the range starts at
168
+ * @param length - How many bytes it holds
169
+ * @throws {RangeError} When either is not
170
+ */
171
+ export function checkRange(offset, length) {
172
+ for (const [what, value] of [['offset', offset], ['length', length]]) {
173
+ if (!(Number.isSafeInteger(value) && value >= 0)) {
174
+ throw new RangeError(`a range's ${what} is a whole number of zero or more, not ${value}`);
175
+ }
176
+ }
177
+ }
178
+ /**
179
+ * Checks how a lock is asked for: its mode is `exclusive` or `shared`, and a
180
+ * timeout, when there is one, is a whole number of milliseconds, zero or more.
181
+ *
182
+ * @param mode - How the lock is to be held
183
+ * @param options - Whether to wait for it, and how long
184
+ * @throws {TypeError} When the mode is neither
185
+ * @throws {RangeError} When the timeout is not a whole number of zero or more
186
+ */
187
+ export function checkLockRequest(mode, options) {
188
+ if (mode !== 'exclusive' && mode !== 'shared') {
189
+ throw new TypeError(`a lock is held exclusive or shared, not ${describeKey(mode)}`);
190
+ }
191
+ const { timeout } = options;
192
+ if (timeout !== undefined && !(Number.isSafeInteger(timeout) && timeout >= 0)) {
193
+ throw new RangeError(`a lock's timeout is a whole number of milliseconds, zero or more, not ${timeout}`);
194
+ }
195
+ }
196
+ /**
197
+ * A copy of bytes that shares no memory with them, and holds only them: what a
198
+ * store keeps, so a caller that changes its bytes after a write, or those a
199
+ * read returned, changes nothing stored.
200
+ *
201
+ * @param bytes - The bytes
202
+ * @returns A copy of exactly those bytes
203
+ */
204
+ export function copyBytes(bytes) {
205
+ return bytes.slice();
206
+ }
207
+ /**
208
+ * What `answer` returns, as a promise that rejects with what it throws: so a
209
+ * method that answers at once fails as every method does, by rejecting.
210
+ *
211
+ * @param answer - What answers
212
+ * @returns Its answer
213
+ */
214
+ export function attempt(answer) {
215
+ try {
216
+ return Promise.resolve(answer());
217
+ }
218
+ catch (err) {
219
+ return Promise.reject(err instanceof Error ? err : new Error(`${err}`));
220
+ }
221
+ }
222
+ /**
223
+ * The bytes a source yields, a chunk at a time: the one chunk of bytes given
224
+ * whole, or each chunk of a stream.
225
+ *
226
+ * @param data - The source
227
+ * @returns Its chunks, in order
228
+ */
229
+ export async function* chunksOf(data) {
230
+ if (data instanceof Uint8Array) {
231
+ yield data;
232
+ return;
233
+ }
234
+ for await (const chunk of data)
235
+ yield chunk;
236
+ }
237
+ /** A key as a message names it. */
238
+ function describeKey(key) {
239
+ try {
240
+ return JSON.stringify(key) ?? String(key);
241
+ }
242
+ catch {
243
+ return String(key);
244
+ }
245
+ }
246
+ //# sourceMappingURL=adapters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../../src/storage/adapters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqMH;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,wBAAwB,MAAM,oEAAoE,CAAC,CAAC;QAC1G,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAiPD,gFAAgF;AAChF,QAAQ;AACR,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAa3C;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqB;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,eAAe,CAAC;IACvD,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC,iFAAiF,SAAS,EAAE,CAAC,CAAC;IACrH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAsED;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAId;IAH5B;;OAEG;IACH,YAA4B,IAAY;QACtC,KAAK,CAAC,8BAA8B,IAAI,EAAE,CAAC,CAAC;QADlB,SAAI,GAAJ,IAAI,CAAQ;QAEtC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED,gFAAgF;A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AO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,GAAa,EAAE,CAAC,CAAC,CAAC;IACpF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAgB;IAC9C,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC;QACX,OAAO;IACT,CAAC;IACD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI;QAAE,MAAM,KAAK,CAAC;AAC9C,CAAC;AAED,mCAAmC;AACnC,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Copyright (c) 2025 Elara AI Pty Ltd
3
+ * Licensed under BSL 1.1. See LICENSE for details.
4
+ */
5
+ /**
6
+ * Records in IndexedDB.
7
+ *
8
+ * A database holds one object store of records, each keyed by its
9
+ * {@link RecordKey} — an array of strings, which IndexedDB orders part by
10
+ * part — and holding its bytes. A transaction is an IndexedDB `readwrite`
11
+ * transaction, so transactions over one database, from any tab, run one after
12
+ * another wherever they touch the same records.
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+ import { type RecordEntry, type RecordKey, type RecordScan, type RecordsAdapter, type RecordsTransaction } from './adapters.js';
17
+ /**
18
+ * How {@link openIndexedDbRecords} and {@link deleteIndexedDbRecords} reach
19
+ * IndexedDB.
20
+ */
21
+ export interface IndexedDbOptions {
22
+ /** The IndexedDB to open the database in: the global `indexedDB` unless
23
+ * given */
24
+ readonly factory?: IDBFactory;
25
+ /**
26
+ * How long a request IndexedDB holds up for a connection elsewhere waits
27
+ * for it to close before it is refused, in milliseconds: 5 s unless given.
28
+ * A connection that closes as it is asked, its last transactions still
29
+ * finishing, lets the request through well within it.
30
+ */
31
+ readonly blockedMs?: number;
32
+ }
33
+ /**
34
+ * Opens the records of a database, making the database when it is not there.
35
+ *
36
+ * @param name - The database's name
37
+ * @param options - The IndexedDB to open it in, and how long an open held up
38
+ * waits
39
+ * @returns The records
40
+ * @throws {Error} When the page has no IndexedDB, or the database will not
41
+ * open: a connection elsewhere holds it at an older version, and does not
42
+ * close within {@link IndexedDbOptions.blockedMs}, say, which the message
43
+ * names
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const records = await openIndexedDbRecords('e3');
48
+ * await records.transact(async (tx) => { tx.put(['refs', 'main'], bytes); });
49
+ * ```
50
+ */
51
+ export declare function openIndexedDbRecords(name: string, options?: IndexedDbOptions): Promise<IndexedDbRecords>;
52
+ /**
53
+ * Deletes a database, and every record in it, once every connection to it has
54
+ * closed: an adapter over it closes its connection when asked to.
55
+ *
56
+ * @param name - The database's name
57
+ * @param options - The IndexedDB it is in, and how long a deletion held up
58
+ * waits
59
+ * @throws {Error} When a connection elsewhere holds the database and does not
60
+ * close within {@link IndexedDbOptions.blockedMs}, naming it: the deletion
61
+ * goes through once it closes
62
+ */
63
+ export declare function deleteIndexedDbRecords(name: string, options?: IndexedDbOptions): Promise<void>;
64
+ /**
65
+ * Records in an IndexedDB database: the {@link RecordsAdapter} of a browser.
66
+ *
67
+ * @remarks
68
+ * A transaction is one IndexedDB `readwrite` transaction, which IndexedDB
69
+ * commits the moment it has nothing to do. Work that awaits anything but the
70
+ * transaction's own operations lets it commit early, and is refused with
71
+ * {@link RecordsTransactionError}: an operation after that throws it, and so
72
+ * does the transaction once its work finishes — what the work wrote before
73
+ * the early commit has applied.
74
+ */
75
+ export declare class IndexedDbRecords implements RecordsAdapter {
76
+ private readonly db;
77
+ private readonly factory;
78
+ private closed;
79
+ /**
80
+ * @param db - The open database
81
+ * @param factory - The IndexedDB it is in, which orders keys
82
+ * @internal
83
+ */
84
+ constructor(db: IDBDatabase, factory: IDBFactory);
85
+ /** A transaction over the records, unless the adapter is closed. */
86
+ private transaction;
87
+ get(key: RecordKey): Promise<Uint8Array | null>;
88
+ scan(prefix: RecordKey, options?: RecordScan): Promise<RecordEntry[]>;
89
+ keys(prefix: RecordKey, options?: RecordScan): Promise<RecordKey[]>;
90
+ transact<T>(work: (tx: RecordsTransaction) => Promise<T>): Promise<T>;
91
+ close(): Promise<void>;
92
+ }
93
+ //# sourceMappingURL=indexeddb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../../../src/storage/indexeddb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAYvB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;gBACY;IACZ,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AA4DD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAWlH;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIxG;AAyFD;;;;;;;;;;GAUG;AACH,qBAA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