@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.
- package/dist/block-format/block.js +254 -325
- package/dist/block-format/checksum.js +30 -52
- package/dist/block-format/codecs.js +112 -125
- package/dist/block-format/column.js +187 -205
- package/dist/block-format/index.js +5 -1
- package/dist/block-format/physical.js +371 -387
- package/dist/block-format/types.js +4 -1
- package/dist/block-format/unicode.js +30 -39
- package/dist/date-value.js +67 -78
- package/dist/engine/artifact-cache.js +106 -116
- package/dist/engine/batch.js +36 -44
- package/dist/engine/buffered-writer.js +156 -158
- package/dist/engine/byte-estimates.js +20 -22
- package/dist/engine/cache-limits.js +24 -25
- package/dist/engine/cancellation.js +5 -3
- package/dist/engine/catalog.js +64 -73
- package/dist/engine/client.js +715 -780
- package/dist/engine/database.js +15942 -19313
- package/dist/engine/defaults.js +104 -111
- package/dist/engine/errors.js +113 -128
- package/dist/engine/fts.js +233 -280
- package/dist/engine/group-index.js +287 -321
- package/dist/engine/index.js +23 -12
- package/dist/engine/join-index.js +177 -186
- package/dist/engine/keyed-live.js +168 -173
- package/dist/engine/live-api.js +0 -1
- package/dist/engine/live-equal.js +32 -37
- package/dist/engine/live.js +603 -647
- package/dist/engine/memory.js +109 -111
- package/dist/engine/optimizer.d.ts +19 -1
- package/dist/engine/optimizer.js +2691 -2933
- package/dist/engine/point-read.js +122 -182
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +6 -0
- package/dist/engine/query.js +8511 -9980
- package/dist/engine/result-wire.js +221 -252
- package/dist/engine/schema-wire.js +97 -112
- package/dist/engine/schema.js +1099 -1254
- package/dist/engine/sort-keys.js +315 -389
- package/dist/engine/sql-domains.js +646 -769
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.js +1031 -1125
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.js +572 -639
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.js +4484 -5145
- package/dist/engine/worker-host.d.ts +8 -63
- package/dist/engine/worker-host.js +28 -1130
- package/dist/engine/worker-indexeddb.d.ts +1 -0
- package/dist/engine/worker-indexeddb.js +3 -0
- package/dist/engine/worker-memory.d.ts +1 -0
- package/dist/engine/worker-memory.js +3 -0
- package/dist/engine/worker-opfs.d.ts +1 -0
- package/dist/engine/worker-opfs.js +3 -0
- package/dist/engine/worker-server.d.ts +93 -0
- package/dist/engine/worker-server.js +999 -0
- package/dist/engine/worker-store-indexeddb.d.ts +2 -0
- package/dist/engine/worker-store-indexeddb.js +11 -0
- package/dist/engine/worker-store-memory.d.ts +2 -0
- package/dist/engine/worker-store-memory.js +6 -0
- package/dist/engine/worker-store-opfs.d.ts +2 -0
- package/dist/engine/worker-store-opfs.js +9 -0
- package/dist/engine/worker.js +0 -12
- package/dist/engine/write-block-planner.js +93 -100
- package/dist/plan/index.js +15 -16
- package/dist/plan/model.d.ts +6 -0
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11784 -13171
- package/dist/storage/memory.js +1198 -1241
- package/dist/storage/opfs/files.js +238 -295
- package/dist/storage/opfs/index.js +9 -3
- package/dist/storage/opfs/leader.js +4386 -4856
- package/dist/storage/opfs/rpc.js +223 -259
- package/dist/storage/opfs/snapshot-ledger.js +219 -260
- package/dist/storage/opfs/store.js +884 -1003
- package/dist/storage/persistence.js +59 -74
- package/dist/storage/snapshot-stream.js +788 -826
- package/dist/storage/snapshot.js +36 -37
- package/dist/storage/toolkit/extents.js +444 -520
- package/dist/storage/toolkit/index.js +28 -29
- package/dist/storage/toolkit/record-core.js +5804 -6377
- package/dist/storage/toolkit/sync-file.js +34 -42
- package/dist/storage/toolkit/wal.js +92 -127
- package/dist/storage/toolkit/wire.js +232 -256
- package/dist/storage/types.js +2948 -3250
- package/dist/testing/block-store-conformance.js +1556 -1629
- package/dist/testing/index.js +310 -291
- package/dist/testing/opfs-shim.js +280 -312
- package/dist/testing/simulator.js +496 -534
- package/dist/testing/sqllogictest.js +425 -365
- package/dist/transactions/index.js +1464 -1712
- package/dist/worker-protocol/index.js +70 -69
- package/package.json +20 -2
- package/sql-feature-matrix.json +2 -2
package/dist/storage/opfs/rpc.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
4
|
-
|
|
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 =
|
|
6
|
+
const MAX_OPFS_RPC_NODES = 11e5;
|
|
8
7
|
function exactKeys(value, keys) {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
+
return void 0;
|
|
78
80
|
const record = value;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
116
|
+
let result = "";
|
|
117
|
+
for (const byte of bytes)
|
|
118
|
+
result += byte.toString(16).padStart(2, "0");
|
|
119
|
+
return result;
|
|
158
120
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
name: error.name,
|
|
212
|
+
message: error.message,
|
|
213
|
+
...Object.keys(props).length === 0 ? {} : { props }
|
|
214
|
+
};
|
|
258
215
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
+
};
|