@aztec/kv-store 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (155) hide show
  1. package/README.md +10 -1
  2. package/dest/bench/shared_map_bench.d.ts +19 -0
  3. package/dest/bench/shared_map_bench.d.ts.map +1 -0
  4. package/dest/bench/shared_map_bench.js +91 -0
  5. package/dest/deprecated/indexeddb/array.d.ts +22 -0
  6. package/dest/deprecated/indexeddb/array.d.ts.map +1 -0
  7. package/dest/deprecated/indexeddb/index.d.ts +7 -0
  8. package/dest/deprecated/indexeddb/index.d.ts.map +1 -0
  9. package/dest/deprecated/indexeddb/index.js +8 -0
  10. package/dest/deprecated/indexeddb/map.d.ts +38 -0
  11. package/dest/deprecated/indexeddb/map.d.ts.map +1 -0
  12. package/dest/{indexeddb → deprecated/indexeddb}/map.js +12 -2
  13. package/dest/deprecated/indexeddb/multi_map.d.ts +14 -0
  14. package/dest/deprecated/indexeddb/multi_map.d.ts.map +1 -0
  15. package/dest/{indexeddb → deprecated/indexeddb}/multi_map.js +3 -2
  16. package/dest/deprecated/indexeddb/set.d.ts +17 -0
  17. package/dest/deprecated/indexeddb/set.d.ts.map +1 -0
  18. package/dest/deprecated/indexeddb/singleton.d.ts +17 -0
  19. package/dest/deprecated/indexeddb/singleton.d.ts.map +1 -0
  20. package/dest/deprecated/indexeddb/store.d.ts +98 -0
  21. package/dest/deprecated/indexeddb/store.d.ts.map +1 -0
  22. package/dest/{indexeddb → deprecated/indexeddb}/store.js +2 -0
  23. package/dest/interfaces/array_test_suite.d.ts +1 -1
  24. package/dest/interfaces/array_test_suite.d.ts.map +1 -1
  25. package/dest/interfaces/array_test_suite.js +33 -34
  26. package/dest/interfaces/index.d.ts +2 -2
  27. package/dest/interfaces/index.d.ts.map +1 -1
  28. package/dest/interfaces/map_test_suite.d.ts +1 -1
  29. package/dest/interfaces/map_test_suite.d.ts.map +1 -1
  30. package/dest/interfaces/map_test_suite.js +32 -33
  31. package/dest/interfaces/multi_map_test_suite.d.ts +1 -1
  32. package/dest/interfaces/multi_map_test_suite.d.ts.map +1 -1
  33. package/dest/interfaces/multi_map_test_suite.js +68 -69
  34. package/dest/interfaces/set_test_suite.d.ts +1 -1
  35. package/dest/interfaces/set_test_suite.d.ts.map +1 -1
  36. package/dest/interfaces/set_test_suite.js +13 -14
  37. package/dest/interfaces/singleton_test_suite.d.ts +1 -1
  38. package/dest/interfaces/singleton_test_suite.d.ts.map +1 -1
  39. package/dest/interfaces/singleton_test_suite.js +6 -7
  40. package/dest/lmdb/index.d.ts +2 -2
  41. package/dest/lmdb/index.d.ts.map +1 -1
  42. package/dest/lmdb/index.js +2 -2
  43. package/dest/lmdb/store.d.ts +3 -3
  44. package/dest/lmdb/store.d.ts.map +1 -1
  45. package/dest/lmdb/store.js +12 -8
  46. package/dest/lmdb-v2/factory.d.ts +30 -4
  47. package/dest/lmdb-v2/factory.d.ts.map +1 -1
  48. package/dest/lmdb-v2/factory.js +62 -10
  49. package/dest/lmdb-v2/read_transaction.js +21 -19
  50. package/dest/lmdb-v2/store.d.ts +2 -2
  51. package/dest/lmdb-v2/store.d.ts.map +1 -1
  52. package/dest/lmdb-v2/store.js +4 -4
  53. package/dest/sqlite-opfs/array.d.ts +21 -0
  54. package/dest/sqlite-opfs/array.d.ts.map +1 -0
  55. package/dest/sqlite-opfs/array.js +128 -0
  56. package/dest/sqlite-opfs/errors.d.ts +54 -0
  57. package/dest/sqlite-opfs/errors.d.ts.map +1 -0
  58. package/dest/sqlite-opfs/errors.js +77 -0
  59. package/dest/sqlite-opfs/index.d.ts +14 -0
  60. package/dest/sqlite-opfs/index.d.ts.map +1 -0
  61. package/dest/sqlite-opfs/index.js +16 -0
  62. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts +32 -0
  63. package/dest/sqlite-opfs/internal/ordered-binary-browser.d.ts.map +1 -0
  64. package/dest/sqlite-opfs/internal/ordered-binary-browser.js +448 -0
  65. package/dest/sqlite-opfs/manage.d.ts +22 -0
  66. package/dest/sqlite-opfs/manage.d.ts.map +1 -0
  67. package/dest/sqlite-opfs/manage.js +38 -0
  68. package/dest/sqlite-opfs/map.d.ts +35 -0
  69. package/dest/sqlite-opfs/map.d.ts.map +1 -0
  70. package/dest/sqlite-opfs/map.js +163 -0
  71. package/dest/sqlite-opfs/messages.d.ts +66 -0
  72. package/dest/sqlite-opfs/messages.d.ts.map +1 -0
  73. package/dest/sqlite-opfs/messages.js +5 -0
  74. package/dest/sqlite-opfs/multi_map.d.ts +16 -0
  75. package/dest/sqlite-opfs/multi_map.d.ts.map +1 -0
  76. package/dest/sqlite-opfs/multi_map.js +67 -0
  77. package/dest/sqlite-opfs/pool_integrity.d.ts +20 -0
  78. package/dest/sqlite-opfs/pool_integrity.d.ts.map +1 -0
  79. package/dest/sqlite-opfs/pool_integrity.js +282 -0
  80. package/dest/sqlite-opfs/pool_lock.d.ts +8 -0
  81. package/dest/sqlite-opfs/pool_lock.d.ts.map +1 -0
  82. package/dest/sqlite-opfs/pool_lock.js +47 -0
  83. package/dest/sqlite-opfs/set.d.ts +13 -0
  84. package/dest/sqlite-opfs/set.d.ts.map +1 -0
  85. package/dest/sqlite-opfs/set.js +19 -0
  86. package/dest/sqlite-opfs/singleton.d.ts +13 -0
  87. package/dest/sqlite-opfs/singleton.d.ts.map +1 -0
  88. package/dest/sqlite-opfs/singleton.js +48 -0
  89. package/dest/sqlite-opfs/store.d.ts +84 -0
  90. package/dest/sqlite-opfs/store.d.ts.map +1 -0
  91. package/dest/sqlite-opfs/store.js +317 -0
  92. package/dest/sqlite-opfs/worker.d.ts +2 -0
  93. package/dest/sqlite-opfs/worker.d.ts.map +1 -0
  94. package/dest/sqlite-opfs/worker.js +275 -0
  95. package/dest/stores/l2_tips_store.d.ts +7 -13
  96. package/dest/stores/l2_tips_store.d.ts.map +1 -1
  97. package/dest/stores/l2_tips_store.js +24 -43
  98. package/package.json +24 -22
  99. package/src/bench/shared_map_bench.ts +111 -0
  100. package/src/{indexeddb → deprecated/indexeddb}/array.ts +2 -2
  101. package/src/deprecated/indexeddb/index.ts +12 -0
  102. package/src/{indexeddb → deprecated/indexeddb}/map.ts +16 -4
  103. package/src/{indexeddb → deprecated/indexeddb}/multi_map.ts +6 -4
  104. package/src/{indexeddb → deprecated/indexeddb}/set.ts +2 -2
  105. package/src/{indexeddb → deprecated/indexeddb}/singleton.ts +2 -2
  106. package/src/{indexeddb → deprecated/indexeddb}/store.ts +10 -9
  107. package/src/interfaces/array_test_suite.ts +33 -35
  108. package/src/interfaces/index.ts +1 -1
  109. package/src/interfaces/map_test_suite.ts +32 -34
  110. package/src/interfaces/multi_map_test_suite.ts +65 -67
  111. package/src/interfaces/set_test_suite.ts +13 -15
  112. package/src/interfaces/singleton_test_suite.ts +6 -8
  113. package/src/lmdb/index.ts +3 -3
  114. package/src/lmdb/store.ts +12 -8
  115. package/src/lmdb-v2/factory.ts +86 -10
  116. package/src/lmdb-v2/read_transaction.ts +23 -23
  117. package/src/lmdb-v2/store.ts +4 -2
  118. package/src/sqlite-opfs/array.ts +124 -0
  119. package/src/sqlite-opfs/errors.ts +94 -0
  120. package/src/sqlite-opfs/index.ts +27 -0
  121. package/src/sqlite-opfs/internal/ordered-binary-browser.js +465 -0
  122. package/src/sqlite-opfs/manage.ts +46 -0
  123. package/src/sqlite-opfs/map.ts +163 -0
  124. package/src/sqlite-opfs/messages.ts +39 -0
  125. package/src/sqlite-opfs/multi_map.ts +74 -0
  126. package/src/sqlite-opfs/pool_integrity.ts +327 -0
  127. package/src/sqlite-opfs/pool_lock.ts +62 -0
  128. package/src/sqlite-opfs/set.ts +29 -0
  129. package/src/sqlite-opfs/singleton.ts +48 -0
  130. package/src/sqlite-opfs/store.ts +330 -0
  131. package/src/sqlite-opfs/worker.ts +259 -0
  132. package/src/stores/l2_tips_store.ts +20 -41
  133. package/dest/config.d.ts +0 -17
  134. package/dest/config.d.ts.map +0 -1
  135. package/dest/config.js +0 -26
  136. package/dest/indexeddb/array.d.ts +0 -22
  137. package/dest/indexeddb/array.d.ts.map +0 -1
  138. package/dest/indexeddb/index.d.ts +0 -7
  139. package/dest/indexeddb/index.d.ts.map +0 -1
  140. package/dest/indexeddb/index.js +0 -16
  141. package/dest/indexeddb/map.d.ts +0 -32
  142. package/dest/indexeddb/map.d.ts.map +0 -1
  143. package/dest/indexeddb/multi_map.d.ts +0 -14
  144. package/dest/indexeddb/multi_map.d.ts.map +0 -1
  145. package/dest/indexeddb/set.d.ts +0 -17
  146. package/dest/indexeddb/set.d.ts.map +0 -1
  147. package/dest/indexeddb/singleton.d.ts +0 -17
  148. package/dest/indexeddb/singleton.d.ts.map +0 -1
  149. package/dest/indexeddb/store.d.ts +0 -96
  150. package/dest/indexeddb/store.d.ts.map +0 -1
  151. package/src/config.ts +0 -36
  152. package/src/indexeddb/index.ts +0 -31
  153. /package/dest/{indexeddb → deprecated/indexeddb}/array.js +0 -0
  154. /package/dest/{indexeddb → deprecated/indexeddb}/set.js +0 -0
  155. /package/dest/{indexeddb → deprecated/indexeddb}/singleton.js +0 -0
@@ -0,0 +1,128 @@
1
+ var _computedKey;
2
+ import { Encoder } from '#msgpackr';
3
+ import { toBufferKey } from '#ordered-binary';
4
+ import { hash } from 'ohash';
5
+ _computedKey = Symbol.asyncIterator;
6
+ /**
7
+ * Persistent array backed by SQLite. Entries share a common `key` (the array name)
8
+ * and are ordered by `key_count`, which doubles as the 1-indexed slot number.
9
+ */ export class SQLiteOPFSAztecArray {
10
+ store;
11
+ #name;
12
+ #container;
13
+ #encoder;
14
+ constructor(store, name){
15
+ this.store = store;
16
+ this.#encoder = new Encoder();
17
+ this.#name = name;
18
+ this.#container = `array:${name}`;
19
+ }
20
+ async lengthAsync() {
21
+ const rows = await this.store.allAsync('SELECT COUNT(*) FROM data WHERE container = ? AND key = ?', [
22
+ this.#container,
23
+ this.#encodedKey()
24
+ ]);
25
+ return Number(rows[0]?.[0] ?? 0);
26
+ }
27
+ async push(...vals) {
28
+ if (vals.length === 0) {
29
+ return this.lengthAsync();
30
+ }
31
+ return await this.store.transactionAsync(async ()=>{
32
+ let length = await this.lengthAsync();
33
+ for (const val of vals){
34
+ await this.store.runAsync(`INSERT INTO data (slot, container, key, key_count, hash, value)
35
+ VALUES (?, ?, ?, ?, ?, ?)`, [
36
+ this.#slot(length),
37
+ this.#container,
38
+ this.#encodedKey(),
39
+ length + 1,
40
+ hash(val),
41
+ this.#encoder.pack(val)
42
+ ]);
43
+ length += 1;
44
+ }
45
+ return length;
46
+ });
47
+ }
48
+ async pop() {
49
+ return await this.store.transactionAsync(async ()=>{
50
+ const length = await this.lengthAsync();
51
+ if (length === 0) {
52
+ return undefined;
53
+ }
54
+ const slot = this.#slot(length - 1);
55
+ const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
56
+ slot
57
+ ]);
58
+ await this.store.runAsync('DELETE FROM data WHERE slot = ?', [
59
+ slot
60
+ ]);
61
+ const raw = rows[0]?.[0];
62
+ return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
63
+ });
64
+ }
65
+ async atAsync(index) {
66
+ const length = await this.lengthAsync();
67
+ const resolved = index < 0 ? length + index : index;
68
+ if (resolved < 0 || resolved >= length) {
69
+ return undefined;
70
+ }
71
+ const rows = await this.store.allAsync('SELECT value FROM data WHERE slot = ? LIMIT 1', [
72
+ this.#slot(resolved)
73
+ ]);
74
+ const raw = rows[0]?.[0];
75
+ return raw instanceof Uint8Array ? this.#encoder.unpack(raw) : undefined;
76
+ }
77
+ async setAt(index, val) {
78
+ return await this.store.transactionAsync(async ()=>{
79
+ const length = await this.lengthAsync();
80
+ const resolved = index < 0 ? length + index : index;
81
+ if (resolved < 0 || resolved >= length) {
82
+ return false;
83
+ }
84
+ await this.store.runAsync(`INSERT OR REPLACE INTO data (slot, container, key, key_count, hash, value)
85
+ VALUES (?, ?, ?, ?, ?, ?)`, [
86
+ this.#slot(resolved),
87
+ this.#container,
88
+ this.#encodedKey(),
89
+ resolved + 1,
90
+ hash(val),
91
+ this.#encoder.pack(val)
92
+ ]);
93
+ return true;
94
+ });
95
+ }
96
+ async *entriesAsync() {
97
+ const rows = await this.store.allAsync('SELECT key_count, value FROM data WHERE container = ? AND key = ? ORDER BY key_count ASC', [
98
+ this.#container,
99
+ this.#encodedKey()
100
+ ]);
101
+ for (const row of rows){
102
+ const keyCount = Number(row[0]);
103
+ const raw = row[1];
104
+ if (raw instanceof Uint8Array) {
105
+ yield [
106
+ keyCount - 1,
107
+ this.#encoder.unpack(raw)
108
+ ];
109
+ }
110
+ }
111
+ }
112
+ async *valuesAsync() {
113
+ for await (const [, val] of this.entriesAsync()){
114
+ yield val;
115
+ }
116
+ }
117
+ [_computedKey]() {
118
+ return this.valuesAsync();
119
+ }
120
+ #encodedKey() {
121
+ return toBufferKey([
122
+ this.#name
123
+ ]);
124
+ }
125
+ #slot(index) {
126
+ return `array:${this.#name}:slot:${index}`;
127
+ }
128
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Typed error surface for sqlite3mc-backed page-level encryption failures.
3
+ *
4
+ * Three concrete failure modes are surfaced:
5
+ *
6
+ * - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
7
+ * - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
8
+ * `:memory:` store, which sqlite3mc does not support).
9
+ * - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
10
+ * both "wrong key supplied" and "no key supplied to an encrypted DB".
11
+ */
12
+ export type SqliteEncryptionErrorCode = 'invalid_key_length' | 'encryption_not_supported_for_ephemeral' | 'decrypt_failed';
13
+ /**
14
+ * Error thrown by sqlite-opfs when an encryption operation fails.
15
+ **/
16
+ export declare class SqliteEncryptionError extends Error {
17
+ readonly code: SqliteEncryptionErrorCode;
18
+ constructor(code: SqliteEncryptionErrorCode, message: string, opts?: {
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ /**
23
+ * Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
24
+ * strings.
25
+ **/
26
+ export declare function isDecryptFailureMessage(message: string): boolean;
27
+ /**
28
+ * Error thrown by sqlite-opfs when the on-disk database image is corrupt
29
+ * (`SQLITE_CORRUPT`, result code 11 — "database disk image is malformed").
30
+ *
31
+ * Distinct from {@link SqliteEncryptionError}: no key recovers a corrupt image,
32
+ * so there is nothing to retry. The only escape is to delete the store and start
33
+ * fresh, so consumers pattern-match on `instanceof SqliteCorruptionError` to wipe
34
+ * and reopen rather than surfacing a dead-end error.
35
+ **/
36
+ export declare class SqliteCorruptionError extends Error {
37
+ constructor(message: string, opts?: {
38
+ cause?: unknown;
39
+ });
40
+ }
41
+ /** Error thrown when another browser context already owns a store's OPFS pool. */
42
+ export declare class SqlitePoolBusyError extends Error {
43
+ readonly poolDirectory: string;
44
+ constructor(poolDirectory: string);
45
+ }
46
+ /** Error thrown when the browser context does not expose the Web Locks API required by the OPFS SAH pool. */
47
+ export declare class SqliteWebLocksUnavailableError extends Error {
48
+ constructor();
49
+ }
50
+ /**
51
+ * Returns `true` if `message` matches one of the known SQLite corruption strings.
52
+ **/
53
+ export declare function isCorruptionMessage(message: string): boolean;
54
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc3FsaXRlLW9wZnMvZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7O0dBVUc7QUFDSCxNQUFNLE1BQU0seUJBQXlCLEdBQ2pDLG9CQUFvQixHQUNwQix3Q0FBd0MsR0FDeEMsZ0JBQWdCLENBQUM7QUFFckI7O0lBRUk7QUFDSixxQkFBYSxxQkFBc0IsU0FBUSxLQUFLO0lBQzlDLFFBQVEsQ0FBQyxJQUFJLEVBQUUseUJBQXlCLENBQUM7SUFFekMsWUFBWSxJQUFJLEVBQUUseUJBQXlCLEVBQUUsT0FBTyxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRTtRQUFFLEtBQUssQ0FBQyxFQUFFLE9BQU8sQ0FBQTtLQUFFLEVBSXZGO0NBQ0Y7QUFVRDs7O0lBR0k7QUFDSix3QkFBZ0IsdUJBQXVCLENBQUMsT0FBTyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBRWhFO0FBRUQ7Ozs7Ozs7O0lBUUk7QUFDSixxQkFBYSxxQkFBc0IsU0FBUSxLQUFLO0lBQzlDLFlBQVksT0FBTyxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsRUFBRTtRQUFFLEtBQUssQ0FBQyxFQUFFLE9BQU8sQ0FBQTtLQUFFLEVBR3REO0NBQ0Y7QUFFRCxrRkFBa0Y7QUFDbEYscUJBQWEsbUJBQW9CLFNBQVEsS0FBSzthQUNoQixhQUFhLEVBQUUsTUFBTTtJQUFqRCxZQUE0QixhQUFhLEVBQUUsTUFBTSxFQUdoRDtDQUNGO0FBRUQsNkdBQTZHO0FBQzdHLHFCQUFhLDhCQUErQixTQUFRLEtBQUs7SUFDdkQsY0FHQztDQUNGO0FBYUQ7O0lBRUk7QUFDSix3QkFBZ0IsbUJBQW1CLENBQUMsT0FBTyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBRTVEIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB,wCAAwC,GACxC,gBAAgB,CAAC;AAErB;;IAEI;AACJ,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IAEzC,YAAY,IAAI,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIvF;CACF;AAUD;;;IAGI;AACJ,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;;;;;IAQI;AACJ,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGtD;CACF;AAED,kFAAkF;AAClF,qBAAa,mBAAoB,SAAQ,KAAK;aAChB,aAAa,EAAE,MAAM;IAAjD,YAA4B,aAAa,EAAE,MAAM,EAGhD;CACF;AAED,6GAA6G;AAC7G,qBAAa,8BAA+B,SAAQ,KAAK;IACvD,cAGC;CACF;AAaD;;IAEI;AACJ,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Typed error surface for sqlite3mc-backed page-level encryption failures.
3
+ *
4
+ * Three concrete failure modes are surfaced:
5
+ *
6
+ * - `invalid_key_length`: caller-side pre-flight (key not 32 bytes).
7
+ * - `encryption_not_supported_for_ephemeral`: caller-side pre-flight (encryption was requested on an ephemeral
8
+ * `:memory:` store, which sqlite3mc does not support).
9
+ * - `decrypt_failed`: runtime failure raised when sqlite3mc cannot decode page 1 of an existing database. Covers
10
+ * both "wrong key supplied" and "no key supplied to an encrypted DB".
11
+ */ /**
12
+ * Error thrown by sqlite-opfs when an encryption operation fails.
13
+ **/ export class SqliteEncryptionError extends Error {
14
+ code;
15
+ constructor(code, message, opts){
16
+ super(message, opts?.cause !== undefined ? {
17
+ cause: opts.cause
18
+ } : undefined);
19
+ this.name = 'SqliteEncryptionError';
20
+ this.code = code;
21
+ }
22
+ }
23
+ /**
24
+ * Strings raised by sqlite3mc when page 1 cannot be decoded.
25
+ **/ const SQLITE3MC_DECRYPT_ERROR_PATTERNS = [
26
+ /file is not a database/i,
27
+ /file is encrypted or is not a database/i
28
+ ];
29
+ /**
30
+ * Returns `true` if `message` matches one of the known sqlite3mc decrypt-failure
31
+ * strings.
32
+ **/ export function isDecryptFailureMessage(message) {
33
+ return SQLITE3MC_DECRYPT_ERROR_PATTERNS.some((p)=>p.test(message));
34
+ }
35
+ /**
36
+ * Error thrown by sqlite-opfs when the on-disk database image is corrupt
37
+ * (`SQLITE_CORRUPT`, result code 11 — "database disk image is malformed").
38
+ *
39
+ * Distinct from {@link SqliteEncryptionError}: no key recovers a corrupt image,
40
+ * so there is nothing to retry. The only escape is to delete the store and start
41
+ * fresh, so consumers pattern-match on `instanceof SqliteCorruptionError` to wipe
42
+ * and reopen rather than surfacing a dead-end error.
43
+ **/ export class SqliteCorruptionError extends Error {
44
+ constructor(message, opts){
45
+ super(message, opts?.cause !== undefined ? {
46
+ cause: opts.cause
47
+ } : undefined);
48
+ this.name = 'SqliteCorruptionError';
49
+ }
50
+ }
51
+ /** Error thrown when another browser context already owns a store's OPFS pool. */ export class SqlitePoolBusyError extends Error {
52
+ poolDirectory;
53
+ constructor(poolDirectory){
54
+ super(`SQLite-OPFS pool "${poolDirectory}" is already in use by another store instance`), this.poolDirectory = poolDirectory;
55
+ this.name = 'SqlitePoolBusyError';
56
+ }
57
+ }
58
+ /** Error thrown when the browser context does not expose the Web Locks API required by the OPFS SAH pool. */ export class SqliteWebLocksUnavailableError extends Error {
59
+ constructor(){
60
+ super('SQLite-OPFS requires the Web Locks API, but it is unavailable in this browser context');
61
+ this.name = 'SqliteWebLocksUnavailableError';
62
+ }
63
+ }
64
+ /**
65
+ * Strings/codes raised by SQLite when a database image is corrupt. Kept disjoint
66
+ * from {@link SQLITE3MC_DECRYPT_ERROR_PATTERNS}: "file is not a database"
67
+ * (SQLITE_NOTADB) is the decrypt signal, whereas a malformed image is the
68
+ * genuinely-unrecoverable SQLITE_CORRUPT.
69
+ **/ const SQLITE_CORRUPTION_ERROR_PATTERNS = [
70
+ /database disk image is malformed/i,
71
+ /\bSQLITE_CORRUPT\b/i
72
+ ];
73
+ /**
74
+ * Returns `true` if `message` matches one of the known SQLite corruption strings.
75
+ **/ export function isCorruptionMessage(message) {
76
+ return SQLITE_CORRUPTION_ERROR_PATTERNS.some((p)=>p.test(message));
77
+ }
@@ -0,0 +1,14 @@
1
+ import { AztecSQLiteOPFSStore } from './store.js';
2
+ export { AztecSQLiteOPFSStore } from './store.js';
3
+ export { SqliteCorruptionError, SqliteEncryptionError, SqlitePoolBusyError, SqliteWebLocksUnavailableError, } from './errors.js';
4
+ export type { SqliteEncryptionErrorCode } from './errors.js';
5
+ export { OPFS_POOL_DIR_PREFIX, deletePoolDirectory, deleteStore, listStores, storePoolDirectory } from './manage.js';
6
+ export declare function openTmpStore(ephemeral?: boolean): Promise<AztecSQLiteOPFSStore>;
7
+ /**
8
+ * Convenience helper for tests and consumers that want an encrypted sqlite-opfs
9
+ * store without dealing with the full `open()` parameter order. Key must be 32
10
+ * bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
11
+ * on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
12
+ */
13
+ export declare function openEncryptedStore(encryptionKey: Uint8Array, name?: string, poolDirectory?: string): Promise<AztecSQLiteOPFSStore>;
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zcWxpdGUtb3Bmcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsb0JBQW9CLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFFbEQsT0FBTyxFQUFFLG9CQUFvQixFQUFFLE1BQU0sWUFBWSxDQUFDO0FBQ2xELE9BQU8sRUFDTCxxQkFBcUIsRUFDckIscUJBQXFCLEVBQ3JCLG1CQUFtQixFQUNuQiw4QkFBOEIsR0FDL0IsTUFBTSxhQUFhLENBQUM7QUFDckIsWUFBWSxFQUFFLHlCQUF5QixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBQzdELE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxtQkFBbUIsRUFBRSxXQUFXLEVBQUUsVUFBVSxFQUFFLGtCQUFrQixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRXJILHdCQUFnQixZQUFZLENBQUMsU0FBUyxHQUFFLE9BQWUsR0FBRyxPQUFPLENBQUMsb0JBQW9CLENBQUMsQ0FFdEY7QUFFRDs7Ozs7R0FLRztBQUNILHdCQUFnQixrQkFBa0IsQ0FBQyxhQUFhLEVBQUUsVUFBVSxFQUFFLElBQUksQ0FBQyxFQUFFLE1BQU0sRUFBRSxhQUFhLENBQUMsRUFBRSxNQUFNLGlDQUVsRyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sqlite-opfs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,8BAA8B,GAC/B,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,WAAW,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAErH,wBAAgB,YAAY,CAAC,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAEtF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,iCAElG"}
@@ -0,0 +1,16 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { AztecSQLiteOPFSStore } from './store.js';
3
+ export { AztecSQLiteOPFSStore } from './store.js';
4
+ export { SqliteCorruptionError, SqliteEncryptionError, SqlitePoolBusyError, SqliteWebLocksUnavailableError } from './errors.js';
5
+ export { OPFS_POOL_DIR_PREFIX, deletePoolDirectory, deleteStore, listStores, storePoolDirectory } from './manage.js';
6
+ export function openTmpStore(ephemeral = false) {
7
+ return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), undefined, ephemeral);
8
+ }
9
+ /**
10
+ * Convenience helper for tests and consumers that want an encrypted sqlite-opfs
11
+ * store without dealing with the full `open()` parameter order. Key must be 32
12
+ * bytes. Creates a fresh persistent store (sqlite3mc does not support encryption
13
+ * on ephemeral `:memory:` databases) in an auto-generated OPFS directory.
14
+ */ export function openEncryptedStore(encryptionKey, name, poolDirectory) {
15
+ return AztecSQLiteOPFSStore.open(createLogger('kv-store:sqlite-opfs'), name, false, poolDirectory, encryptionKey);
16
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Vendored from `ordered-binary@1.5.3/index.js` with one targeted edit:
3
+ * the `readString` definition (originally a dynamically-generated
4
+ * unrolled-loop function) is replaced with a hand-written interpreted
5
+ * equivalent that does the same work without code-generation-from-strings.
6
+ *
7
+ * Why vendor: upstream has no CSP-safe build, and the codegen is a
8
+ * module-init-time string-passed-to-evaluator that trips MV3 CSP
9
+ * (`script-src 'self' 'wasm-unsafe-eval'`). The codegen is a perf
10
+ * optimization on the string-decoding path only — the interpreted
11
+ * version is functionally identical, just slower per call.
12
+ *
13
+ * Parity with upstream is enforced by `ordered-binary-browser.test.ts`,
14
+ * which compares byte-exact output for a representative key set on every
15
+ * Node-mode test run. If `ordered-binary` is bumped, re-vendor by
16
+ * recopying upstream and reapplying the patch in the section marked
17
+ * `// CSP PATCH BEGIN` ... `// CSP PATCH END`.
18
+ */
19
+ export declare function writeKey(key: any, target: any, position: any, inSequence: any): any;
20
+ export declare function readKey(buffer: any, start: any, end: any, inSequence: any): any;
21
+ export declare const enableNullTermination: () => boolean;
22
+ export declare const encoder: {
23
+ writeKey: typeof writeKey;
24
+ readKey: typeof readKey;
25
+ enableNullTermination: () => boolean;
26
+ };
27
+ export declare const toBufferKey: (key: any) => any;
28
+ export declare const fromBufferKey: (sourceBuffer: any) => any;
29
+ export declare function compareKeys(a: any, b: any): any;
30
+ export declare const MINIMUM_KEY: null;
31
+ export declare const MAXIMUM_KEY: Uint8Array<ArrayBuffer>;
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3JkZXJlZC1iaW5hcnktYnJvd3Nlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3NxbGl0ZS1vcGZzL2ludGVybmFsL29yZGVyZWQtYmluYXJ5LWJyb3dzZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0E7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBaUJHO0FBNEJILHdCQUFnQixRQUFRLENBQUMsR0FBRyxLQUFBLEVBQUUsTUFBTSxLQUFBLEVBQUUsUUFBUSxLQUFBLEVBQUUsVUFBVSxLQUFBLE9Bd0p6RDtBQUdELHdCQUFnQixPQUFPLENBQUMsTUFBTSxLQUFBLEVBQUUsS0FBSyxLQUFBLEVBQUUsR0FBRyxLQUFBLEVBQUUsVUFBVSxLQUFBLE9BK0ZyRDtBQUNELGVBQU8sTUFBTSxxQkFBcUIsZUFBK0IsQ0FBQztBQUVsRSxlQUFPLE1BQU0sT0FBTzs7OztDQUluQixDQUFDO0FBS0YsZUFBTyxNQUFNLFdBQVcsbUJBdUJ2QixDQUFDO0FBQ0YsZUFBTyxNQUFNLGFBQWEsNEJBRXpCLENBQUM7QUErRUYsd0JBQWdCLFdBQVcsQ0FBQyxDQUFDLEtBQUEsRUFBRSxDQUFDLEtBQUEsT0EwQy9CO0FBUUQsZUFBTyxNQUFNLFdBQVcsTUFBTyxDQUFDO0FBQ2hDLGVBQU8sTUFBTSxXQUFXLHlCQUF5QixDQUFDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordered-binary-browser.d.ts","sourceRoot":"","sources":["../../../src/sqlite-opfs/internal/ordered-binary-browser.js"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AA4BH,wBAAgB,QAAQ,CAAC,GAAG,KAAA,EAAE,MAAM,KAAA,EAAE,QAAQ,KAAA,EAAE,UAAU,KAAA,OAwJzD;AAGD,wBAAgB,OAAO,CAAC,MAAM,KAAA,EAAE,KAAK,KAAA,EAAE,GAAG,KAAA,EAAE,UAAU,KAAA,OA+FrD;AACD,eAAO,MAAM,qBAAqB,eAA+B,CAAC;AAElE,eAAO,MAAM,OAAO;;;;CAInB,CAAC;AAKF,eAAO,MAAM,WAAW,mBAuBvB,CAAC;AACF,eAAO,MAAM,aAAa,4BAEzB,CAAC;AA+EF,wBAAgB,WAAW,CAAC,CAAC,KAAA,EAAE,CAAC,KAAA,OA0C/B;AAQD,eAAO,MAAM,WAAW,MAAO,CAAC;AAChC,eAAO,MAAM,WAAW,yBAAyB,CAAC"}