@minnowdb/core 0.7.0 → 0.7.2

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 (96) hide show
  1. package/dist/block-format/block.js +254 -325
  2. package/dist/block-format/checksum.js +30 -52
  3. package/dist/block-format/codecs.js +112 -125
  4. package/dist/block-format/column.js +187 -205
  5. package/dist/block-format/index.js +5 -1
  6. package/dist/block-format/physical.js +371 -387
  7. package/dist/block-format/types.js +4 -1
  8. package/dist/block-format/unicode.js +30 -39
  9. package/dist/date-value.js +67 -78
  10. package/dist/engine/artifact-cache.js +106 -116
  11. package/dist/engine/batch.js +36 -44
  12. package/dist/engine/buffered-writer.js +156 -158
  13. package/dist/engine/byte-estimates.js +20 -22
  14. package/dist/engine/cache-limits.js +24 -25
  15. package/dist/engine/cancellation.js +5 -3
  16. package/dist/engine/catalog.js +64 -73
  17. package/dist/engine/client.js +715 -780
  18. package/dist/engine/database.js +15942 -19313
  19. package/dist/engine/defaults.js +104 -111
  20. package/dist/engine/errors.js +113 -128
  21. package/dist/engine/fts.js +233 -280
  22. package/dist/engine/group-index.js +287 -321
  23. package/dist/engine/index.js +23 -12
  24. package/dist/engine/join-index.js +177 -186
  25. package/dist/engine/keyed-live.js +168 -173
  26. package/dist/engine/live-api.js +0 -1
  27. package/dist/engine/live-equal.js +32 -37
  28. package/dist/engine/live.js +603 -647
  29. package/dist/engine/memory.js +109 -111
  30. package/dist/engine/optimizer.d.ts +19 -1
  31. package/dist/engine/optimizer.js +2691 -2933
  32. package/dist/engine/point-read.js +122 -182
  33. package/dist/engine/query-api.js +12 -3
  34. package/dist/engine/query-cache.js +61 -69
  35. package/dist/engine/query.d.ts +6 -0
  36. package/dist/engine/query.js +8511 -9980
  37. package/dist/engine/result-wire.js +221 -252
  38. package/dist/engine/schema-wire.js +97 -112
  39. package/dist/engine/schema.js +1099 -1254
  40. package/dist/engine/sort-keys.js +315 -389
  41. package/dist/engine/sql-domains.js +646 -769
  42. package/dist/engine/sql-driver.js +0 -1
  43. package/dist/engine/sql-functions.js +1031 -1125
  44. package/dist/engine/sql-json.js +199 -218
  45. package/dist/engine/sql-semantics.js +572 -639
  46. package/dist/engine/typed-live.js +271 -293
  47. package/dist/engine/vector.js +4484 -5145
  48. package/dist/engine/worker-host.d.ts +8 -63
  49. package/dist/engine/worker-host.js +28 -1130
  50. package/dist/engine/worker-indexeddb.d.ts +1 -0
  51. package/dist/engine/worker-indexeddb.js +3 -0
  52. package/dist/engine/worker-memory.d.ts +1 -0
  53. package/dist/engine/worker-memory.js +3 -0
  54. package/dist/engine/worker-opfs.d.ts +1 -0
  55. package/dist/engine/worker-opfs.js +3 -0
  56. package/dist/engine/worker-server.d.ts +93 -0
  57. package/dist/engine/worker-server.js +999 -0
  58. package/dist/engine/worker-store-indexeddb.d.ts +2 -0
  59. package/dist/engine/worker-store-indexeddb.js +11 -0
  60. package/dist/engine/worker-store-memory.d.ts +2 -0
  61. package/dist/engine/worker-store-memory.js +6 -0
  62. package/dist/engine/worker-store-opfs.d.ts +2 -0
  63. package/dist/engine/worker-store-opfs.js +9 -0
  64. package/dist/engine/worker.js +0 -12
  65. package/dist/engine/write-block-planner.js +93 -100
  66. package/dist/plan/index.js +15 -16
  67. package/dist/plan/model.d.ts +6 -0
  68. package/dist/plan/model.js +20 -27
  69. package/dist/storage/index.js +0 -12
  70. package/dist/storage/indexeddb.js +11784 -13171
  71. package/dist/storage/memory.js +1198 -1241
  72. package/dist/storage/opfs/files.js +238 -295
  73. package/dist/storage/opfs/index.js +9 -3
  74. package/dist/storage/opfs/leader.js +4386 -4856
  75. package/dist/storage/opfs/rpc.js +223 -259
  76. package/dist/storage/opfs/snapshot-ledger.js +219 -260
  77. package/dist/storage/opfs/store.js +884 -1003
  78. package/dist/storage/persistence.js +59 -74
  79. package/dist/storage/snapshot-stream.js +788 -826
  80. package/dist/storage/snapshot.js +36 -37
  81. package/dist/storage/toolkit/extents.js +444 -520
  82. package/dist/storage/toolkit/index.js +28 -29
  83. package/dist/storage/toolkit/record-core.js +5804 -6377
  84. package/dist/storage/toolkit/sync-file.js +34 -42
  85. package/dist/storage/toolkit/wal.js +92 -127
  86. package/dist/storage/toolkit/wire.js +232 -256
  87. package/dist/storage/types.js +2948 -3250
  88. package/dist/testing/block-store-conformance.js +1556 -1629
  89. package/dist/testing/index.js +310 -291
  90. package/dist/testing/opfs-shim.js +280 -312
  91. package/dist/testing/simulator.js +496 -534
  92. package/dist/testing/sqllogictest.js +425 -365
  93. package/dist/transactions/index.js +1464 -1712
  94. package/dist/worker-protocol/index.js +70 -69
  95. package/package.json +20 -2
  96. package/sql-feature-matrix.json +2 -2
@@ -1,280 +1,244 @@
1
- import { BlockReadBatchTooLargeError, CompactionBacklogError, CompactionJobConflictError, GarbageCollectionJobConflictError, IndexedDbSchemaUpgradeBlockedError, LeaseConflictError, LeaseExpiredError, LeaseOwnerConflictError, OpfsUncertainOutcomeError, PostingBuildConflictError, SnapshotImportConflictError, SnapshotManifestMissingError, StorageCorruptionError, StorageFormatVersionError, StorageResourceLimitError, TableInUseError, TableRecordConflictError, TempOwnerConflictError, TransactionRecordConflictError, UniqueKeyBuildConflictError, UniqueKeyConflictError, UniqueIndexCoverageError, WriteConflictError, SchemaConflictError, } from "../types.js";
1
+ import { BlockReadBatchTooLargeError, CompactionBacklogError, CompactionJobConflictError, GarbageCollectionJobConflictError, IndexedDbSchemaUpgradeBlockedError, LeaseConflictError, LeaseExpiredError, LeaseOwnerConflictError, OpfsUncertainOutcomeError, PostingBuildConflictError, SnapshotImportConflictError, SnapshotManifestMissingError, StorageCorruptionError, StorageFormatVersionError, StorageResourceLimitError, TableInUseError, TableRecordConflictError, TempOwnerConflictError, TransactionRecordConflictError, UniqueKeyBuildConflictError, UniqueKeyConflictError, UniqueIndexCoverageError, WriteConflictError, SchemaConflictError } from "../types.js";
2
2
  import { dateIsoString } from "../../date-value.js";
3
- /** One legal maximum payload plus bounded envelope/catalog metadata. */
4
- export const MAX_OPFS_RPC_MESSAGE_BYTES = 66 * 1024 * 1024;
5
- export const MAX_OPFS_RPC_IDENTIFIER_CHARACTERS = 1024;
3
+ const MAX_OPFS_RPC_MESSAGE_BYTES = 66 * 1024 * 1024;
4
+ const MAX_OPFS_RPC_IDENTIFIER_CHARACTERS = 1024;
6
5
  const MAX_OPFS_RPC_DEPTH = 64;
7
- const MAX_OPFS_RPC_NODES = 1_100_000;
6
+ const MAX_OPFS_RPC_NODES = 11e5;
8
7
  function exactKeys(value, keys) {
9
- const actual = Object.keys(value);
10
- return actual.length === keys.length && keys.every((key) => Object.hasOwn(value, key));
8
+ const actual = Object.keys(value);
9
+ return actual.length === keys.length && keys.every((key) => Object.hasOwn(value, key));
11
10
  }
12
11
  function boundedRpcString(value) {
13
- return (typeof value === "string" &&
14
- value.length > 0 &&
15
- value.length <= MAX_OPFS_RPC_IDENTIFIER_CHARACTERS);
12
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_OPFS_RPC_IDENTIFIER_CHARACTERS;
16
13
  }
17
- /** Conservative retained/transfer-byte estimate with total depth/cardinality refusal. */
18
- export function estimateRpcValueBytes(value) {
19
- const seen = new WeakSet();
20
- let nodes = 0;
21
- const visit = (current, depth) => {
22
- nodes += 1;
23
- if (nodes > MAX_OPFS_RPC_NODES || depth > MAX_OPFS_RPC_DEPTH) {
24
- throw new RangeError("OPFS RPC value exceeds its structural limit");
25
- }
26
- if (current === null || current === undefined || typeof current === "boolean")
27
- return 8;
28
- if (typeof current === "number" || typeof current === "bigint")
29
- return 16;
30
- if (typeof current === "string")
31
- return 16 + current.length * 2;
32
- if (typeof current !== "object")
33
- throw new TypeError("OPFS RPC value is not cloneable data");
34
- if (seen.has(current))
35
- throw new TypeError("OPFS RPC value must not contain cycles");
36
- seen.add(current);
37
- if (typeof SharedArrayBuffer !== "undefined" && current instanceof SharedArrayBuffer) {
38
- throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
39
- }
40
- if (current instanceof ArrayBuffer)
41
- return 32 + current.byteLength;
42
- if (ArrayBuffer.isView(current)) {
43
- if (typeof SharedArrayBuffer !== "undefined" && current.buffer instanceof SharedArrayBuffer) {
44
- throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
45
- }
46
- return 48 + current.byteLength;
47
- }
48
- if (current instanceof Date)
49
- return 32;
50
- let bytes = 32;
51
- if (Array.isArray(current)) {
52
- for (const item of current)
53
- bytes += visit(item, depth + 1);
54
- }
55
- else {
56
- if (Object.getPrototypeOf(current) !== Object.prototype &&
57
- Object.getPrototypeOf(current) !== null) {
58
- throw new TypeError("OPFS RPC value has an unsupported prototype");
59
- }
60
- for (const [key, item] of Object.entries(current)) {
61
- bytes += key.length * 2 + visit(item, depth + 1);
62
- }
63
- }
64
- if (!Number.isSafeInteger(bytes) || bytes > MAX_OPFS_RPC_MESSAGE_BYTES) {
65
- throw new RangeError("OPFS RPC message exceeds its byte limit");
66
- }
67
- return bytes;
68
- };
69
- const bytes = visit(value, 0);
70
- if (bytes > MAX_OPFS_RPC_MESSAGE_BYTES) {
71
- throw new RangeError("OPFS RPC message exceeds its byte limit");
14
+ function estimateRpcValueBytes(value) {
15
+ const seen = /* @__PURE__ */ new WeakSet();
16
+ let nodes = 0;
17
+ const visit = (current, depth) => {
18
+ nodes += 1;
19
+ if (nodes > MAX_OPFS_RPC_NODES || depth > MAX_OPFS_RPC_DEPTH) {
20
+ throw new RangeError("OPFS RPC value exceeds its structural limit");
72
21
  }
73
- return bytes;
22
+ if (current === null || current === void 0 || typeof current === "boolean")
23
+ return 8;
24
+ if (typeof current === "number" || typeof current === "bigint")
25
+ return 16;
26
+ if (typeof current === "string")
27
+ return 16 + current.length * 2;
28
+ if (typeof current !== "object")
29
+ throw new TypeError("OPFS RPC value is not cloneable data");
30
+ if (seen.has(current))
31
+ throw new TypeError("OPFS RPC value must not contain cycles");
32
+ seen.add(current);
33
+ if (typeof SharedArrayBuffer !== "undefined" && current instanceof SharedArrayBuffer) {
34
+ throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
35
+ }
36
+ if (current instanceof ArrayBuffer)
37
+ return 32 + current.byteLength;
38
+ if (ArrayBuffer.isView(current)) {
39
+ if (typeof SharedArrayBuffer !== "undefined" && current.buffer instanceof SharedArrayBuffer) {
40
+ throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
41
+ }
42
+ return 48 + current.byteLength;
43
+ }
44
+ if (current instanceof Date)
45
+ return 32;
46
+ let bytes2 = 32;
47
+ if (Array.isArray(current)) {
48
+ for (const item of current)
49
+ bytes2 += visit(item, depth + 1);
50
+ } else {
51
+ if (Object.getPrototypeOf(current) !== Object.prototype && Object.getPrototypeOf(current) !== null) {
52
+ throw new TypeError("OPFS RPC value has an unsupported prototype");
53
+ }
54
+ for (const [key, item] of Object.entries(current)) {
55
+ bytes2 += key.length * 2 + visit(item, depth + 1);
56
+ }
57
+ }
58
+ if (!Number.isSafeInteger(bytes2) || bytes2 > MAX_OPFS_RPC_MESSAGE_BYTES) {
59
+ throw new RangeError("OPFS RPC message exceeds its byte limit");
60
+ }
61
+ return bytes2;
62
+ };
63
+ const bytes = visit(value, 0);
64
+ if (bytes > MAX_OPFS_RPC_MESSAGE_BYTES) {
65
+ throw new RangeError("OPFS RPC message exceeds its byte limit");
66
+ }
67
+ return bytes;
74
68
  }
75
69
  function validSerializedError(value) {
70
+ if (typeof value !== "object" || value === null || Array.isArray(value))
71
+ return false;
72
+ const record = value;
73
+ const allowed = record.props === void 0 ? record.domException === void 0 ? ["name", "message"] : ["name", "message", "domException"] : record.domException === void 0 ? ["name", "message", "props"] : ["name", "message", "domException", "props"];
74
+ return exactKeys(record, allowed) && boundedRpcString(record.name) && typeof record.message === "string" && record.message.length <= MAX_OPFS_RPC_IDENTIFIER_CHARACTERS * 4 && (record.domException === void 0 || record.domException === true) && (record.props === void 0 || typeof record.props === "object" && record.props !== null && !Array.isArray(record.props));
75
+ }
76
+ function parseStoreRpcMessage(value, knownMethods) {
77
+ try {
76
78
  if (typeof value !== "object" || value === null || Array.isArray(value))
77
- return false;
79
+ return void 0;
78
80
  const record = value;
79
- const allowed = record.props === undefined
80
- ? record.domException === undefined
81
- ? ["name", "message"]
82
- : ["name", "message", "domException"]
83
- : record.domException === undefined
84
- ? ["name", "message", "props"]
85
- : ["name", "message", "domException", "props"];
86
- return (exactKeys(record, allowed) &&
87
- boundedRpcString(record.name) &&
88
- typeof record.message === "string" &&
89
- record.message.length <= MAX_OPFS_RPC_IDENTIFIER_CHARACTERS * 4 &&
90
- (record.domException === undefined || record.domException === true) &&
91
- (record.props === undefined ||
92
- (typeof record.props === "object" && record.props !== null && !Array.isArray(record.props))));
93
- }
94
- /** Total non-throwing parser for same-origin-but-untrusted BroadcastChannel traffic. */
95
- export function parseStoreRpcMessage(value, knownMethods) {
96
- try {
97
- if (typeof value !== "object" || value === null || Array.isArray(value))
98
- return undefined;
99
- const record = value;
100
- estimateRpcValueBytes(record);
101
- switch (record.kind) {
102
- case "op":
103
- if (!exactKeys(record, ["kind", "requestId", "from", "method", "args"]) ||
104
- !boundedRpcString(record.requestId) ||
105
- !boundedRpcString(record.from) ||
106
- !boundedRpcString(record.method) ||
107
- !knownMethods.has(record.method) ||
108
- !Array.isArray(record.args) ||
109
- estimateRpcValueBytes(record.args) > MAX_OPFS_RPC_MESSAGE_BYTES)
110
- return undefined;
111
- return record;
112
- case "result":
113
- if (!boundedRpcString(record.requestId) || typeof record.ok !== "boolean")
114
- return undefined;
115
- if (record.ok) {
116
- if (!exactKeys(record, ["kind", "requestId", "ok", "value"]))
117
- return undefined;
118
- estimateRpcValueBytes(record.value);
119
- }
120
- else if (!exactKeys(record, ["kind", "requestId", "ok", "error"]) ||
121
- !validSerializedError(record.error))
122
- return undefined;
123
- return record;
124
- case "busy":
125
- return exactKeys(record, ["kind", "requestId"]) && boundedRpcString(record.requestId)
126
- ? record
127
- : undefined;
128
- case "leader":
129
- case "released":
130
- return exactKeys(record, ["kind", "leaderId"]) && boundedRpcString(record.leaderId)
131
- ? record
132
- : undefined;
133
- case "ping":
134
- return exactKeys(record, ["kind"]) ? record : undefined;
135
- case "bid":
136
- return exactKeys(record, ["kind", "bidderId", "foreground"]) &&
137
- boundedRpcString(record.bidderId) &&
138
- typeof record.foreground === "boolean"
139
- ? record
140
- : undefined;
141
- case "yield":
142
- return exactKeys(record, ["kind", "to"]) && boundedRpcString(record.to)
143
- ? record
144
- : undefined;
145
- default:
146
- return undefined;
147
- }
148
- }
149
- catch {
150
- return undefined;
81
+ estimateRpcValueBytes(record);
82
+ switch (record.kind) {
83
+ case "op":
84
+ if (!exactKeys(record, ["kind", "requestId", "from", "method", "args"]) || !boundedRpcString(record.requestId) || !boundedRpcString(record.from) || !boundedRpcString(record.method) || !knownMethods.has(record.method) || !Array.isArray(record.args) || estimateRpcValueBytes(record.args) > MAX_OPFS_RPC_MESSAGE_BYTES)
85
+ return void 0;
86
+ return record;
87
+ case "result":
88
+ if (!boundedRpcString(record.requestId) || typeof record.ok !== "boolean")
89
+ return void 0;
90
+ if (record.ok) {
91
+ if (!exactKeys(record, ["kind", "requestId", "ok", "value"]))
92
+ return void 0;
93
+ estimateRpcValueBytes(record.value);
94
+ } else if (!exactKeys(record, ["kind", "requestId", "ok", "error"]) || !validSerializedError(record.error))
95
+ return void 0;
96
+ return record;
97
+ case "busy":
98
+ return exactKeys(record, ["kind", "requestId"]) && boundedRpcString(record.requestId) ? record : void 0;
99
+ case "leader":
100
+ case "released":
101
+ return exactKeys(record, ["kind", "leaderId"]) && boundedRpcString(record.leaderId) ? record : void 0;
102
+ case "ping":
103
+ return exactKeys(record, ["kind"]) ? record : void 0;
104
+ case "bid":
105
+ return exactKeys(record, ["kind", "bidderId", "foreground"]) && boundedRpcString(record.bidderId) && typeof record.foreground === "boolean" ? record : void 0;
106
+ case "yield":
107
+ return exactKeys(record, ["kind", "to"]) && boundedRpcString(record.to) ? record : void 0;
108
+ default:
109
+ return void 0;
151
110
  }
111
+ } catch {
112
+ return void 0;
113
+ }
152
114
  }
153
115
  function hex(bytes) {
154
- let result = "";
155
- for (const byte of bytes)
156
- result += byte.toString(16).padStart(2, "0");
157
- return result;
116
+ let result = "";
117
+ for (const byte of bytes)
118
+ result += byte.toString(16).padStart(2, "0");
119
+ return result;
158
120
  }
159
- /** Collision-resistant bounded identity; large byte leaves become SHA-256 descriptors. */
160
- export async function fingerprintStoreRequest(method, args) {
161
- const retainedBytes = estimateRpcValueBytes(args);
162
- const seen = new WeakSet();
163
- const normalize = async (value, depth) => {
164
- if (depth > MAX_OPFS_RPC_DEPTH)
165
- throw new RangeError("OPFS RPC value exceeds its depth limit");
166
- if (typeof value === "bigint")
167
- return ["bigint", value.toString()];
168
- if (value === undefined)
169
- return ["undefined"];
170
- if (typeof value === "number") {
171
- return ["number", Object.is(value, -0) ? "-0" : String(value)];
172
- }
173
- if (value === null || typeof value !== "object")
174
- return value;
175
- if (seen.has(value))
176
- throw new TypeError("OPFS RPC value must not contain cycles");
177
- seen.add(value);
178
- if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
179
- const { byteLength } = value;
180
- let digestInput;
181
- if (value instanceof ArrayBuffer)
182
- digestInput = value;
183
- else if (!(value.buffer instanceof ArrayBuffer)) {
184
- throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
185
- }
186
- else if (value.byteOffset === 0 && value.byteLength === value.buffer.byteLength) {
187
- digestInput = value.buffer;
188
- }
189
- else {
190
- digestInput = value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
191
- }
192
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", digestInput));
193
- return ["bytes", value.constructor.name, byteLength, hex(digest)];
194
- }
195
- if (value instanceof Date)
196
- return ["date", dateIsoString(value)];
197
- if (Array.isArray(value)) {
198
- return Promise.all(value.map((item) => normalize(item, depth + 1)));
199
- }
200
- const entries = [];
201
- for (const key of Object.keys(value).sort()) {
202
- entries.push([key, await normalize(value[key], depth + 1)]);
203
- }
204
- return ["object", entries];
205
- };
206
- const canonical = JSON.stringify([method, await normalize(args, 0)]);
207
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)));
208
- return { signature: `${String(retainedBytes)}:${hex(digest)}`, retainedBytes };
121
+ async function fingerprintStoreRequest(method, args) {
122
+ const retainedBytes = estimateRpcValueBytes(args);
123
+ const seen = /* @__PURE__ */ new WeakSet();
124
+ const normalize = async (value, depth) => {
125
+ if (depth > MAX_OPFS_RPC_DEPTH)
126
+ throw new RangeError("OPFS RPC value exceeds its depth limit");
127
+ if (typeof value === "bigint")
128
+ return ["bigint", value.toString()];
129
+ if (value === void 0)
130
+ return ["undefined"];
131
+ if (typeof value === "number") {
132
+ return ["number", Object.is(value, -0) ? "-0" : String(value)];
133
+ }
134
+ if (value === null || typeof value !== "object")
135
+ return value;
136
+ if (seen.has(value))
137
+ throw new TypeError("OPFS RPC value must not contain cycles");
138
+ seen.add(value);
139
+ if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
140
+ const { byteLength } = value;
141
+ let digestInput;
142
+ if (value instanceof ArrayBuffer)
143
+ digestInput = value;
144
+ else if (!(value.buffer instanceof ArrayBuffer)) {
145
+ throw new TypeError("OPFS RPC values must not use SharedArrayBuffer");
146
+ } else if (value.byteOffset === 0 && value.byteLength === value.buffer.byteLength) {
147
+ digestInput = value.buffer;
148
+ } else {
149
+ digestInput = value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
150
+ }
151
+ const digest2 = new Uint8Array(await crypto.subtle.digest("SHA-256", digestInput));
152
+ return ["bytes", value.constructor.name, byteLength, hex(digest2)];
153
+ }
154
+ if (value instanceof Date)
155
+ return ["date", dateIsoString(value)];
156
+ if (Array.isArray(value)) {
157
+ return Promise.all(value.map((item) => normalize(item, depth + 1)));
158
+ }
159
+ const entries = [];
160
+ for (const key of Object.keys(value).sort()) {
161
+ entries.push([key, await normalize(value[key], depth + 1)]);
162
+ }
163
+ return ["object", entries];
164
+ };
165
+ const canonical = JSON.stringify([method, await normalize(args, 0)]);
166
+ const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical)));
167
+ return { signature: `${String(retainedBytes)}:${hex(digest)}`, retainedBytes };
209
168
  }
210
169
  const errorRegistry = new Map([
211
- BlockReadBatchTooLargeError,
212
- CompactionBacklogError,
213
- WriteConflictError,
214
- SchemaConflictError,
215
- UniqueKeyConflictError,
216
- UniqueIndexCoverageError,
217
- TableRecordConflictError,
218
- TransactionRecordConflictError,
219
- LeaseConflictError,
220
- LeaseExpiredError,
221
- LeaseOwnerConflictError,
222
- CompactionJobConflictError,
223
- GarbageCollectionJobConflictError,
224
- IndexedDbSchemaUpgradeBlockedError,
225
- TempOwnerConflictError,
226
- StorageResourceLimitError,
227
- TableInUseError,
228
- SnapshotManifestMissingError,
229
- SnapshotImportConflictError,
230
- UniqueKeyBuildConflictError,
231
- PostingBuildConflictError,
232
- StorageCorruptionError,
233
- StorageFormatVersionError,
234
- OpfsUncertainOutcomeError,
170
+ BlockReadBatchTooLargeError,
171
+ CompactionBacklogError,
172
+ WriteConflictError,
173
+ SchemaConflictError,
174
+ UniqueKeyConflictError,
175
+ UniqueIndexCoverageError,
176
+ TableRecordConflictError,
177
+ TransactionRecordConflictError,
178
+ LeaseConflictError,
179
+ LeaseExpiredError,
180
+ LeaseOwnerConflictError,
181
+ CompactionJobConflictError,
182
+ GarbageCollectionJobConflictError,
183
+ IndexedDbSchemaUpgradeBlockedError,
184
+ TempOwnerConflictError,
185
+ StorageResourceLimitError,
186
+ TableInUseError,
187
+ SnapshotManifestMissingError,
188
+ SnapshotImportConflictError,
189
+ UniqueKeyBuildConflictError,
190
+ PostingBuildConflictError,
191
+ StorageCorruptionError,
192
+ StorageFormatVersionError,
193
+ OpfsUncertainOutcomeError
235
194
  ].map((constructor) => [constructor.name, constructor]));
236
- export function serializeStoreError(error) {
237
- if (error instanceof DOMException) {
238
- return { name: error.name, message: error.message, domException: true };
239
- }
240
- if (!(error instanceof Error))
241
- return { name: "Error", message: String(error) };
242
- const props = {};
243
- for (const key of Object.keys(error)) {
244
- const value = error[key];
245
- try {
246
- structuredClone(value);
247
- props[key] = value;
248
- }
249
- catch {
250
- // A non-cloneable field would poison the whole message; drop it.
251
- }
195
+ function serializeStoreError(error) {
196
+ if (error instanceof DOMException) {
197
+ return { name: error.name, message: error.message, domException: true };
198
+ }
199
+ if (!(error instanceof Error))
200
+ return { name: "Error", message: String(error) };
201
+ const props = {};
202
+ for (const key of Object.keys(error)) {
203
+ const value = error[key];
204
+ try {
205
+ structuredClone(value);
206
+ props[key] = value;
207
+ } catch {
252
208
  }
253
- return {
254
- name: error.name,
255
- message: error.message,
256
- ...(Object.keys(props).length === 0 ? {} : { props }),
257
- };
209
+ }
210
+ return {
211
+ name: error.name,
212
+ message: error.message,
213
+ ...Object.keys(props).length === 0 ? {} : { props }
214
+ };
258
215
  }
259
- export function rehydrateStoreError(serialized) {
260
- if (serialized.domException === true) {
261
- return new DOMException(serialized.message, serialized.name);
262
- }
263
- const constructor = errorRegistry.get(serialized.name);
264
- const error = constructor === undefined
265
- ? new Error(serialized.message)
266
- : Object.create(constructor.prototype);
267
- Object.defineProperty(error, "message", {
268
- value: serialized.message,
269
- writable: true,
270
- configurable: true,
271
- });
272
- Object.defineProperty(error, "name", {
273
- value: serialized.name,
274
- writable: true,
275
- configurable: true,
276
- });
277
- if (serialized.props !== undefined)
278
- Object.assign(error, serialized.props);
279
- return error;
216
+ function rehydrateStoreError(serialized) {
217
+ if (serialized.domException === true) {
218
+ return new DOMException(serialized.message, serialized.name);
219
+ }
220
+ const constructor = errorRegistry.get(serialized.name);
221
+ const error = constructor === void 0 ? new Error(serialized.message) : Object.create(constructor.prototype);
222
+ Object.defineProperty(error, "message", {
223
+ value: serialized.message,
224
+ writable: true,
225
+ configurable: true
226
+ });
227
+ Object.defineProperty(error, "name", {
228
+ value: serialized.name,
229
+ writable: true,
230
+ configurable: true
231
+ });
232
+ if (serialized.props !== void 0)
233
+ Object.assign(error, serialized.props);
234
+ return error;
280
235
  }
236
+ export {
237
+ MAX_OPFS_RPC_IDENTIFIER_CHARACTERS,
238
+ MAX_OPFS_RPC_MESSAGE_BYTES,
239
+ estimateRpcValueBytes,
240
+ fingerprintStoreRequest,
241
+ parseStoreRpcMessage,
242
+ rehydrateStoreError,
243
+ serializeStoreError
244
+ };