@moyodb/sdk 1.3.0 → 1.5.0
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/CONTRIBUTING.md +46 -0
- package/README.md +4 -2
- package/dist/assets/browser-worker-p7uX85l-.js +4 -0
- package/dist/assets/browser-worker-p7uX85l-.js.map +1 -0
- package/dist/assets/shared-worker-BALTqEUe.js +2 -0
- package/dist/assets/shared-worker-BALTqEUe.js.map +1 -0
- package/dist/chunks/{indexing-CKtbpaZn.js → indexing-DdpU69Fd.js} +344 -185
- package/dist/chunks/indexing-DdpU69Fd.js.map +1 -0
- package/dist/codec.d.ts.map +1 -1
- package/dist/compression.d.ts.map +1 -1
- package/dist/demo.d.ts.map +1 -1
- package/dist/engine/README.md +4 -2
- package/dist/engine/moyodb_engine.d.ts +4 -2
- package/dist/engine/moyodb_engine.js +45 -22
- package/dist/engine/moyodb_engine_bg.wasm +0 -0
- package/dist/engine/moyodb_engine_bg.wasm.d.ts +3 -2
- package/dist/engine/package.json +1 -1
- package/dist/engine/snippets/{moyodb-engine-54a406e33b0fb849 → moyodb-engine-1f8134232168280b}/js/opfs_shim.js +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/indexing.d.ts +7 -0
- package/dist/indexing.d.ts.map +1 -1
- package/dist/moyodb-sdk.js +1265 -872
- package/dist/moyodb-sdk.js.map +1 -1
- package/dist/node-engine.js +411 -81
- package/dist/node-engine.js.map +1 -1
- package/dist/node.js +354 -74
- package/dist/node.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/subscriptions.d.ts.map +1 -1
- package/dist/worker-api.d.ts +2 -5
- package/dist/worker-api.d.ts.map +1 -1
- package/dist/worker-client.d.ts.map +1 -1
- package/dist/worker-protocol.d.ts +7 -2
- package/dist/worker-protocol.d.ts.map +1 -1
- package/dist/worker-server.d.ts.map +1 -1
- package/dist/worker.d.ts +12 -5
- package/dist/worker.d.ts.map +1 -1
- package/package.json +5 -3
- package/dist/assets/browser-worker-DBt51gsS.js +0 -4
- package/dist/assets/browser-worker-DBt51gsS.js.map +0 -1
- package/dist/assets/shared-worker-NdniRuEL.js +0 -2
- package/dist/assets/shared-worker-NdniRuEL.js.map +0 -1
- package/dist/chunks/indexing-CKtbpaZn.js.map +0 -1
|
@@ -143,22 +143,21 @@ function deserializeWorkerError(error) {
|
|
|
143
143
|
const deserialized = new Error(error.message);
|
|
144
144
|
deserialized.name = error.name || error.code || "Error";
|
|
145
145
|
if (error.stack) deserialized.stack = error.stack;
|
|
146
|
-
if (error.code)
|
|
147
|
-
value: error.code,
|
|
148
|
-
enumerable: true,
|
|
149
|
-
configurable: true
|
|
150
|
-
});
|
|
146
|
+
if (error.code) defineErrorCode(deserialized, error.code);
|
|
151
147
|
return deserialized;
|
|
152
148
|
}
|
|
153
149
|
function workerProtocolError(name, message, code = name) {
|
|
154
150
|
const error = new Error(message);
|
|
155
151
|
error.name = name;
|
|
152
|
+
defineErrorCode(error, code);
|
|
153
|
+
return error;
|
|
154
|
+
}
|
|
155
|
+
function defineErrorCode(error, code) {
|
|
156
156
|
Object.defineProperty(error, "code", {
|
|
157
157
|
value: code,
|
|
158
158
|
enumerable: true,
|
|
159
159
|
configurable: true
|
|
160
160
|
});
|
|
161
|
-
return error;
|
|
162
161
|
}
|
|
163
162
|
function prepareWorkerCommandPayload(command, args) {
|
|
164
163
|
if (command === "autocommit") {
|
|
@@ -263,7 +262,7 @@ function decodeWorkerCommandPayload(command, args) {
|
|
|
263
262
|
if (command === "getMany" || command === "deleteMany") {
|
|
264
263
|
const [txId, store, keys] = args;
|
|
265
264
|
if (!Array.isArray(keys)) {
|
|
266
|
-
if (!
|
|
265
|
+
if (!isPackedPayload(keys, PACKED_BINARY_LIST_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed binary-list argument");
|
|
267
266
|
return [
|
|
268
267
|
txId,
|
|
269
268
|
store,
|
|
@@ -274,11 +273,11 @@ function decodeWorkerCommandPayload(command, args) {
|
|
|
274
273
|
if (command === "putMany") {
|
|
275
274
|
const [txId, store, entries, options] = args;
|
|
276
275
|
if (!Array.isArray(entries)) {
|
|
277
|
-
if (!
|
|
276
|
+
if (!isPackedPayload(entries, PACKED_BINARY_LIST_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany argument");
|
|
278
277
|
return [
|
|
279
278
|
txId,
|
|
280
279
|
store,
|
|
281
|
-
|
|
280
|
+
unpackPutManyPayload(entries, false),
|
|
282
281
|
options
|
|
283
282
|
];
|
|
284
283
|
}
|
|
@@ -286,21 +285,21 @@ function decodeWorkerCommandPayload(command, args) {
|
|
|
286
285
|
if (command === "applyBatch") {
|
|
287
286
|
const [txId, store, ops] = args;
|
|
288
287
|
if (!Array.isArray(ops)) {
|
|
289
|
-
if (!
|
|
288
|
+
if (!isPackedPayload(ops, PACKED_BATCH_OPS_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed batch argument");
|
|
290
289
|
return [
|
|
291
290
|
txId,
|
|
292
291
|
store,
|
|
293
|
-
|
|
292
|
+
unpackBatchPayload(ops, false)
|
|
294
293
|
];
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
return args;
|
|
298
297
|
}
|
|
299
298
|
function packedBinaryListBytes(value) {
|
|
300
|
-
return
|
|
299
|
+
return isPackedPayload(value, PACKED_BINARY_LIST_V1) ? value.bytes : null;
|
|
301
300
|
}
|
|
302
301
|
function packedBatchOpsBytes(value) {
|
|
303
|
-
return
|
|
302
|
+
return isPackedPayload(value, PACKED_BATCH_OPS_V1) ? value.bytes : null;
|
|
304
303
|
}
|
|
305
304
|
function unpackPackedBinaryList(bytes) {
|
|
306
305
|
return unpackBinaryList({
|
|
@@ -309,22 +308,22 @@ function unpackPackedBinaryList(bytes) {
|
|
|
309
308
|
});
|
|
310
309
|
}
|
|
311
310
|
function unpackPackedBinaryPairKeys(bytes) {
|
|
312
|
-
return
|
|
311
|
+
return unpackPutManyPayload({
|
|
313
312
|
__moyodbPacked: PACKED_BINARY_LIST_V1,
|
|
314
313
|
bytes
|
|
315
|
-
});
|
|
314
|
+
}, true);
|
|
316
315
|
}
|
|
317
316
|
function unpackPackedBatchOps(bytes) {
|
|
318
|
-
return
|
|
317
|
+
return unpackBatchPayload({
|
|
319
318
|
__moyodbPacked: PACKED_BATCH_OPS_V1,
|
|
320
319
|
bytes
|
|
321
|
-
});
|
|
320
|
+
}, false);
|
|
322
321
|
}
|
|
323
322
|
function unpackPackedBatchOpKeys(bytes) {
|
|
324
|
-
return
|
|
323
|
+
return unpackBatchPayload({
|
|
325
324
|
__moyodbPacked: PACKED_BATCH_OPS_V1,
|
|
326
325
|
bytes
|
|
327
|
-
});
|
|
326
|
+
}, true);
|
|
328
327
|
}
|
|
329
328
|
function packedOptionalValues(bytes) {
|
|
330
329
|
return {
|
|
@@ -355,13 +354,13 @@ function unpackPackedOptionalValues(bytes) {
|
|
|
355
354
|
return items;
|
|
356
355
|
}
|
|
357
356
|
function prepareWorkerResponsePayload(command, result) {
|
|
358
|
-
if ((command === "scan" || command === "scanByIndex") && (isPackedEngineScanRows(result) ||
|
|
357
|
+
if ((command === "scan" || command === "scanByIndex") && (isPackedEngineScanRows(result) || isPackedPayload(result, PACKED_SCAN_ROWS_V1))) return {
|
|
359
358
|
result,
|
|
360
359
|
transfer: collectDirectBinaryTransferable(result.bytes)
|
|
361
360
|
};
|
|
362
361
|
if (command === "scanPage") {
|
|
363
362
|
const page = result;
|
|
364
|
-
if (isRecord(page) && (isPackedEngineScanRows(page.rows) ||
|
|
363
|
+
if (isRecord(page) && (isPackedEngineScanRows(page.rows) || isPackedPayload(page.rows, PACKED_SCAN_ROWS_V1))) return {
|
|
365
364
|
result: page,
|
|
366
365
|
transfer: collectDirectBinaryTransferable(page.rows.bytes)
|
|
367
366
|
};
|
|
@@ -376,13 +375,13 @@ function prepareWorkerResponsePayload(command, result) {
|
|
|
376
375
|
};
|
|
377
376
|
}
|
|
378
377
|
}
|
|
379
|
-
if (command === "getMany" &&
|
|
378
|
+
if (command === "getMany" && isPackedPayload(result, PACKED_OPTIONAL_VALUES_V1)) return {
|
|
380
379
|
result,
|
|
381
380
|
transfer: collectDirectBinaryTransferable(result.bytes)
|
|
382
381
|
};
|
|
383
382
|
if (command === "scanByIndexPage") {
|
|
384
383
|
const page = result;
|
|
385
|
-
if (isRecord(page) &&
|
|
384
|
+
if (isRecord(page) && isPackedPayload(page.rows, PACKED_SCAN_ROWS_V1)) return {
|
|
386
385
|
result: page,
|
|
387
386
|
transfer: collectTransferablesForValue(page)
|
|
388
387
|
};
|
|
@@ -444,7 +443,7 @@ function prepareWorkerResponsePayload(command, result) {
|
|
|
444
443
|
function decodeWorkerResponsePayload(command, result) {
|
|
445
444
|
if (command === "scanPage") {
|
|
446
445
|
if (!isRecord(result) || typeof result.done !== "boolean" || typeof result.bytes !== "number" || !Number.isSafeInteger(result.bytes) || result.bytes < 4 || result.cursorId !== void 0 && (typeof result.cursorId !== "number" || !Number.isSafeInteger(result.cursorId) || result.cursorId <= 0) || (result.done ? result.cursorId !== void 0 : result.cursorId === void 0)) throw workerProtocolError("WorkerProtocolError", "invalid scan page response");
|
|
447
|
-
const rows = isPackedEngineScanRows(result.rows) ? unpackPackedScanRows(result.rows.bytes) :
|
|
446
|
+
const rows = isPackedEngineScanRows(result.rows) ? unpackPackedScanRows(result.rows.bytes) : isPackedPayload(result.rows, PACKED_SCAN_ROWS_V1) ? unpackScanRows(result.rows) : result.rows;
|
|
448
447
|
if (!Array.isArray(rows)) throw workerProtocolError("WorkerProtocolError", "invalid scan page rows");
|
|
449
448
|
let bytes = 4;
|
|
450
449
|
for (const row of rows) {
|
|
@@ -460,17 +459,17 @@ function decodeWorkerResponsePayload(command, result) {
|
|
|
460
459
|
};
|
|
461
460
|
}
|
|
462
461
|
if ((command === "scan" || command === "scanByIndex") && isPackedEngineScanRows(result)) return unpackPackedScanRows(result.bytes);
|
|
463
|
-
if (command === "getMany" &&
|
|
464
|
-
if (command === "getMany" &&
|
|
462
|
+
if (command === "getMany" && isPackedPayload(result, PACKED_NULLABLE_BINARY_LIST_V1)) return unpackNullableBinaryList(result);
|
|
463
|
+
if (command === "getMany" && isPackedPayload(result, PACKED_OPTIONAL_VALUES_V1)) return unpackPackedOptionalValues(result.bytes);
|
|
465
464
|
if (command === "getMany" && !Array.isArray(result)) throw workerProtocolError("WorkerProtocolError", "invalid packed getMany response");
|
|
466
465
|
if (command === "scanByIndexPage") {
|
|
467
|
-
if (!isRecord(result) || !Array.isArray(result.rows) && !
|
|
466
|
+
if (!isRecord(result) || !Array.isArray(result.rows) && !isPackedPayload(result.rows, PACKED_SCAN_ROWS_V1) || result.cursor !== null && !(result.cursor instanceof Uint8Array)) throw workerProtocolError("WorkerProtocolError", "invalid packed index scan page response");
|
|
468
467
|
return {
|
|
469
|
-
rows:
|
|
468
|
+
rows: isPackedPayload(result.rows, PACKED_SCAN_ROWS_V1) ? unpackScanRows(result.rows) : result.rows,
|
|
470
469
|
cursor: result.cursor
|
|
471
470
|
};
|
|
472
471
|
}
|
|
473
|
-
if ((command === "scan" || command === "scanByIndex") &&
|
|
472
|
+
if ((command === "scan" || command === "scanByIndex") && isPackedPayload(result, PACKED_SCAN_ROWS_V1)) return unpackScanRows(result);
|
|
474
473
|
if ((command === "scan" || command === "scanByIndex") && !Array.isArray(result)) throw workerProtocolError("WorkerProtocolError", "invalid packed scan response");
|
|
475
474
|
return result;
|
|
476
475
|
}
|
|
@@ -709,7 +708,7 @@ function unpackBinaryList(payload) {
|
|
|
709
708
|
if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed binary-list payload has trailing bytes");
|
|
710
709
|
return items;
|
|
711
710
|
}
|
|
712
|
-
function
|
|
711
|
+
function unpackPutManyPayload(payload, keysOnly) {
|
|
713
712
|
const bytes = payload.bytes;
|
|
714
713
|
if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany payload");
|
|
715
714
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
@@ -729,38 +728,13 @@ function unpackBinaryPairs(payload) {
|
|
|
729
728
|
if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany key exceeds payload length");
|
|
730
729
|
const valueEnd = keyEnd + valueLength;
|
|
731
730
|
if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany value exceeds payload length");
|
|
732
|
-
entries[index] =
|
|
731
|
+
if (keysOnly) entries[index] = bytes.subarray(readOffset, keyEnd);
|
|
732
|
+
else entries[index] = [bytes.subarray(readOffset, keyEnd), bytes.subarray(keyEnd, valueEnd)];
|
|
733
733
|
readOffset = valueEnd;
|
|
734
734
|
}
|
|
735
735
|
if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has trailing bytes");
|
|
736
736
|
return entries;
|
|
737
737
|
}
|
|
738
|
-
function unpackBinaryPairKeys(payload) {
|
|
739
|
-
const bytes = payload.bytes;
|
|
740
|
-
if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany payload");
|
|
741
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
742
|
-
const itemCount = view.getUint32(0, true);
|
|
743
|
-
if (itemCount % 2 !== 0) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has an odd item count");
|
|
744
|
-
const payloadOffset = checkedAdd(4, checkedByteCount(itemCount, 4, "packed putMany metadata"), "packed putMany header");
|
|
745
|
-
if (payloadOffset > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany metadata exceeds payload length");
|
|
746
|
-
const entryCount = itemCount / 2;
|
|
747
|
-
const keys = new Array(entryCount);
|
|
748
|
-
let metadataOffset = 4;
|
|
749
|
-
let readOffset = payloadOffset;
|
|
750
|
-
for (let index = 0; index < entryCount; index += 1) {
|
|
751
|
-
const keyLength = view.getUint32(metadataOffset, true);
|
|
752
|
-
const valueLength = view.getUint32(metadataOffset + 4, true);
|
|
753
|
-
metadataOffset += 8;
|
|
754
|
-
const keyEnd = readOffset + keyLength;
|
|
755
|
-
if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany key exceeds payload length");
|
|
756
|
-
const valueEnd = keyEnd + valueLength;
|
|
757
|
-
if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany value exceeds payload length");
|
|
758
|
-
keys[index] = bytes.subarray(readOffset, keyEnd);
|
|
759
|
-
readOffset = valueEnd;
|
|
760
|
-
}
|
|
761
|
-
if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has trailing bytes");
|
|
762
|
-
return keys;
|
|
763
|
-
}
|
|
764
738
|
function packNullableBinaryList(items) {
|
|
765
739
|
const count = items.length;
|
|
766
740
|
const metadataBytes = checkedByteCount(count, 5, "packed nullable binary-list metadata");
|
|
@@ -941,7 +915,7 @@ function packBatchOps(ops) {
|
|
|
941
915
|
bytes
|
|
942
916
|
};
|
|
943
917
|
}
|
|
944
|
-
function
|
|
918
|
+
function unpackBatchPayload(payload, keysOnly) {
|
|
945
919
|
const bytes = payload.bytes;
|
|
946
920
|
if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed batch payload");
|
|
947
921
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
@@ -971,69 +945,22 @@ function unpackBatchOps(payload) {
|
|
|
971
945
|
if (kind !== BATCH_OP_PUT) throw workerProtocolError("WorkerProtocolError", `packed batch operation has invalid kind byte: ${kind}`);
|
|
972
946
|
const valueEnd = readOffset + valueLength;
|
|
973
947
|
if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch value exceeds payload length");
|
|
974
|
-
ops[index] = {
|
|
948
|
+
if (keysOnly) ops[index] = {
|
|
975
949
|
kind: "put",
|
|
976
|
-
key
|
|
977
|
-
value: bytes.subarray(readOffset, valueEnd)
|
|
950
|
+
key
|
|
978
951
|
};
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch payload has trailing bytes");
|
|
982
|
-
return ops;
|
|
983
|
-
}
|
|
984
|
-
function unpackBatchOpKeys(payload) {
|
|
985
|
-
const bytes = payload.bytes;
|
|
986
|
-
if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed batch payload");
|
|
987
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
988
|
-
const count = view.getUint32(0, true);
|
|
989
|
-
const payloadOffset = checkedAdd(4, checkedByteCount(count, 9, "packed batch metadata"), "packed batch header");
|
|
990
|
-
if (payloadOffset > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch metadata exceeds payload length");
|
|
991
|
-
const ops = new Array(count);
|
|
992
|
-
let metadataOffset = 4;
|
|
993
|
-
let readOffset = payloadOffset;
|
|
994
|
-
for (let index = 0; index < count; index += 1) {
|
|
995
|
-
const kind = view.getUint8(metadataOffset);
|
|
996
|
-
const keyLength = view.getUint32(metadataOffset + 1, true);
|
|
997
|
-
const valueLength = view.getUint32(metadataOffset + 5, true);
|
|
998
|
-
metadataOffset += 9;
|
|
999
|
-
const keyEnd = readOffset + keyLength;
|
|
1000
|
-
if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch key exceeds payload length");
|
|
1001
|
-
const key = bytes.subarray(readOffset, keyEnd);
|
|
1002
|
-
readOffset = keyEnd;
|
|
1003
|
-
if (kind === BATCH_OP_DELETE) {
|
|
1004
|
-
if (valueLength !== 0) throw workerProtocolError("WorkerProtocolError", "packed delete operation has a value payload");
|
|
1005
|
-
ops[index] = {
|
|
1006
|
-
kind: "delete",
|
|
1007
|
-
key
|
|
1008
|
-
};
|
|
1009
|
-
continue;
|
|
1010
|
-
}
|
|
1011
|
-
if (kind !== BATCH_OP_PUT) throw workerProtocolError("WorkerProtocolError", `packed batch operation has invalid kind byte: ${kind}`);
|
|
1012
|
-
const valueEnd = readOffset + valueLength;
|
|
1013
|
-
if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch value exceeds payload length");
|
|
1014
|
-
ops[index] = {
|
|
952
|
+
else ops[index] = {
|
|
1015
953
|
kind: "put",
|
|
1016
|
-
key
|
|
954
|
+
key,
|
|
955
|
+
value: bytes.subarray(readOffset, valueEnd)
|
|
1017
956
|
};
|
|
1018
957
|
readOffset = valueEnd;
|
|
1019
958
|
}
|
|
1020
959
|
if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch payload has trailing bytes");
|
|
1021
960
|
return ops;
|
|
1022
961
|
}
|
|
1023
|
-
function
|
|
1024
|
-
return isRecord(value) && value.__moyodbPacked ===
|
|
1025
|
-
}
|
|
1026
|
-
function isPackedNullableBinaryList(value) {
|
|
1027
|
-
return isRecord(value) && value.__moyodbPacked === PACKED_NULLABLE_BINARY_LIST_V1 && value.bytes instanceof Uint8Array;
|
|
1028
|
-
}
|
|
1029
|
-
function isPackedScanRows(value) {
|
|
1030
|
-
return isRecord(value) && value.__moyodbPacked === PACKED_SCAN_ROWS_V1 && value.bytes instanceof Uint8Array;
|
|
1031
|
-
}
|
|
1032
|
-
function isPackedBatchOps(value) {
|
|
1033
|
-
return isRecord(value) && value.__moyodbPacked === PACKED_BATCH_OPS_V1 && value.bytes instanceof Uint8Array;
|
|
1034
|
-
}
|
|
1035
|
-
function isPackedOptionalValues(value) {
|
|
1036
|
-
return isRecord(value) && value.__moyodbPacked === PACKED_OPTIONAL_VALUES_V1 && value.bytes instanceof Uint8Array;
|
|
962
|
+
function isPackedPayload(value, tag) {
|
|
963
|
+
return isRecord(value) && value.__moyodbPacked === tag && value.bytes instanceof Uint8Array;
|
|
1037
964
|
}
|
|
1038
965
|
function checkedByteCount(count, itemBytes, what) {
|
|
1039
966
|
if (!Number.isSafeInteger(count) || count < 0) throw workerProtocolError("WorkerProtocolError", `${what} count is invalid: ${count}`);
|
|
@@ -1247,7 +1174,7 @@ function normalizeError(error) {
|
|
|
1247
1174
|
}
|
|
1248
1175
|
//#endregion
|
|
1249
1176
|
//#region src/codec.ts
|
|
1250
|
-
var encoder
|
|
1177
|
+
var encoder = new TextEncoder();
|
|
1251
1178
|
var decoder = new TextDecoder();
|
|
1252
1179
|
var jsonDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
1253
1180
|
var TYPE_NULL = 16;
|
|
@@ -1260,8 +1187,10 @@ var COMPOUND_ESCAPE = 0;
|
|
|
1260
1187
|
var COMPOUND_ESCAPE_CONT = 255;
|
|
1261
1188
|
var COMPOUND_TERM = 0;
|
|
1262
1189
|
var F64_MASK = BigInt("0xffffffffffffffff");
|
|
1190
|
+
var sortableNumberBytes = /* @__PURE__ */ new Uint8Array(9);
|
|
1191
|
+
var sortableNumberView = new DataView(sortableNumberBytes.buffer);
|
|
1263
1192
|
function utf8Encode(value) {
|
|
1264
|
-
return encoder
|
|
1193
|
+
return encoder.encode(value);
|
|
1265
1194
|
}
|
|
1266
1195
|
function utf8Decode(bytes) {
|
|
1267
1196
|
return decoder.decode(bytes);
|
|
@@ -1287,11 +1216,11 @@ function isCompoundKeyPartList(value) {
|
|
|
1287
1216
|
return Array.isArray(value);
|
|
1288
1217
|
}
|
|
1289
1218
|
function indexKey(value) {
|
|
1290
|
-
if (isCompoundKeyPartList(value)) return
|
|
1219
|
+
if (isCompoundKeyPartList(value)) return encodeCompoundKeyList(value);
|
|
1291
1220
|
return encodeCompoundKeyPart(value);
|
|
1292
1221
|
}
|
|
1293
1222
|
function compoundKey(...parts) {
|
|
1294
|
-
return
|
|
1223
|
+
return encodeCompoundKeyList(parts);
|
|
1295
1224
|
}
|
|
1296
1225
|
function encodeIndexScalar(value) {
|
|
1297
1226
|
return encodeCompoundKeyPart(value);
|
|
@@ -1301,37 +1230,55 @@ function encodeCompoundKeyParts(parts) {
|
|
|
1301
1230
|
}
|
|
1302
1231
|
function splitCompoundKey(key) {
|
|
1303
1232
|
const parts = [];
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
const
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
index
|
|
1315
|
-
|
|
1233
|
+
let index = 0;
|
|
1234
|
+
while (index < key.length) {
|
|
1235
|
+
const start = index;
|
|
1236
|
+
let length = 0;
|
|
1237
|
+
let closed = false;
|
|
1238
|
+
for (; index < key.length; index += 1) {
|
|
1239
|
+
if (key[index] !== COMPOUND_ESCAPE) {
|
|
1240
|
+
length += 1;
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
const next = key[index + 1];
|
|
1244
|
+
if (next === COMPOUND_ESCAPE_CONT) {
|
|
1245
|
+
length += 1;
|
|
1246
|
+
index += 1;
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
if (next === COMPOUND_TERM) {
|
|
1250
|
+
index += 2;
|
|
1251
|
+
closed = true;
|
|
1252
|
+
break;
|
|
1253
|
+
}
|
|
1254
|
+
throw new TypeError("invalid compound key encoding");
|
|
1316
1255
|
}
|
|
1317
|
-
if (
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1256
|
+
if (!closed) throw new TypeError("compound key terminated unexpectedly");
|
|
1257
|
+
const part = new Uint8Array(length);
|
|
1258
|
+
let offset = 0;
|
|
1259
|
+
for (let cursor = start; cursor < index - 2; cursor += 1) {
|
|
1260
|
+
const byte = key[cursor];
|
|
1261
|
+
if (byte !== COMPOUND_ESCAPE) {
|
|
1262
|
+
part[offset] = byte;
|
|
1263
|
+
offset += 1;
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
part[offset] = COMPOUND_ESCAPE;
|
|
1267
|
+
offset += 1;
|
|
1268
|
+
cursor += 1;
|
|
1322
1269
|
}
|
|
1323
|
-
|
|
1270
|
+
parts.push(part);
|
|
1324
1271
|
}
|
|
1325
|
-
if (current.length !== 0) throw new TypeError("compound key terminated unexpectedly");
|
|
1326
1272
|
return parts;
|
|
1327
1273
|
}
|
|
1328
1274
|
function prefixSuccessor(prefix) {
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1275
|
+
let end = prefix.length;
|
|
1276
|
+
while (end > 0 && prefix[end - 1] === 255) end -= 1;
|
|
1277
|
+
if (end === 0) return null;
|
|
1278
|
+
const out = new Uint8Array(end);
|
|
1279
|
+
out.set(end === prefix.length ? prefix : prefix.subarray(0, end));
|
|
1280
|
+
out[end - 1] += 1;
|
|
1281
|
+
return out;
|
|
1335
1282
|
}
|
|
1336
1283
|
function prefixRange(prefix) {
|
|
1337
1284
|
const upper = prefixSuccessor(prefix);
|
|
@@ -1347,17 +1294,7 @@ function encodeCompoundKeyPart(value) {
|
|
|
1347
1294
|
if (value === null) return Uint8Array.of(TYPE_NULL);
|
|
1348
1295
|
if (typeof value === "boolean") return Uint8Array.of(value ? TYPE_TRUE : TYPE_FALSE);
|
|
1349
1296
|
if (typeof value === "number") return encodeSortableNumber(value);
|
|
1350
|
-
if (typeof value === "string")
|
|
1351
|
-
for (const character of value) {
|
|
1352
|
-
const codePoint = character.codePointAt(0);
|
|
1353
|
-
if (codePoint >= 55296 && codePoint <= 57343) throw new TypeError("compound key string parts must contain valid Unicode scalar values");
|
|
1354
|
-
}
|
|
1355
|
-
const body = utf8Encode(value);
|
|
1356
|
-
const out = new Uint8Array(1 + body.length);
|
|
1357
|
-
out[0] = TYPE_STRING;
|
|
1358
|
-
out.set(body, 1);
|
|
1359
|
-
return out;
|
|
1360
|
-
}
|
|
1297
|
+
if (typeof value === "string") return encodeStringKey(value);
|
|
1361
1298
|
if (value instanceof Uint8Array) {
|
|
1362
1299
|
const out = new Uint8Array(1 + value.length);
|
|
1363
1300
|
out[0] = TYPE_BYTES;
|
|
@@ -1366,16 +1303,64 @@ function encodeCompoundKeyPart(value) {
|
|
|
1366
1303
|
}
|
|
1367
1304
|
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1368
1305
|
}
|
|
1369
|
-
function
|
|
1306
|
+
function encodeCompoundKeyList(parts) {
|
|
1370
1307
|
let length = 0;
|
|
1371
|
-
for (
|
|
1372
|
-
|
|
1373
|
-
|
|
1308
|
+
for (let index = 0; index < parts.length; index += 1) length += compoundPartEncodedLength(parts[index]);
|
|
1309
|
+
const out = new Uint8Array(length);
|
|
1310
|
+
let offset = 0;
|
|
1311
|
+
for (let index = 0; index < parts.length; index += 1) offset = writeCompoundPart$1(out, offset, parts[index]);
|
|
1312
|
+
return out;
|
|
1313
|
+
}
|
|
1314
|
+
function compoundPartEncodedLength(value) {
|
|
1315
|
+
if (value === null || typeof value === "boolean") return 3;
|
|
1316
|
+
if (typeof value === "number") {
|
|
1317
|
+
writeSortableNumber(sortableNumberView, value);
|
|
1318
|
+
return escapedByteLength(sortableNumberBytes) + 2;
|
|
1319
|
+
}
|
|
1320
|
+
if (typeof value === "string") return 1 + walkUtf8(value, null, 0, true) + 2;
|
|
1321
|
+
if (value instanceof Uint8Array) return 1 + escapedByteLength(value) + 2;
|
|
1322
|
+
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1323
|
+
}
|
|
1324
|
+
function writeCompoundPart$1(out, offset, value) {
|
|
1325
|
+
if (value === null) {
|
|
1326
|
+
out[offset] = TYPE_NULL;
|
|
1327
|
+
return writeTerminator(out, offset + 1);
|
|
1328
|
+
}
|
|
1329
|
+
if (typeof value === "boolean") {
|
|
1330
|
+
out[offset] = value ? TYPE_TRUE : TYPE_FALSE;
|
|
1331
|
+
return writeTerminator(out, offset + 1);
|
|
1332
|
+
}
|
|
1333
|
+
if (typeof value === "number") {
|
|
1334
|
+
writeSortableNumber(sortableNumberView, value);
|
|
1335
|
+
return writeTerminator(out, writeEscapedBytes(out, offset, sortableNumberBytes));
|
|
1336
|
+
}
|
|
1337
|
+
if (typeof value === "string") {
|
|
1338
|
+
out[offset] = TYPE_STRING;
|
|
1339
|
+
return writeTerminator(out, walkUtf8(value, out, offset + 1, true));
|
|
1340
|
+
}
|
|
1341
|
+
if (value instanceof Uint8Array) {
|
|
1342
|
+
out[offset] = TYPE_BYTES;
|
|
1343
|
+
return writeTerminator(out, writeEscapedBytes(out, offset + 1, value));
|
|
1374
1344
|
}
|
|
1345
|
+
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1346
|
+
}
|
|
1347
|
+
function encodeCompoundBytes(parts) {
|
|
1348
|
+
let length = 0;
|
|
1349
|
+
for (let index = 0; index < parts.length; index += 1) length += escapedByteLength(parts[index]) + 2;
|
|
1375
1350
|
const out = new Uint8Array(length);
|
|
1376
1351
|
let offset = 0;
|
|
1377
|
-
for (
|
|
1378
|
-
|
|
1352
|
+
for (let index = 0; index < parts.length; index += 1) offset = writeTerminator(out, writeEscapedBytes(out, offset, parts[index]));
|
|
1353
|
+
return out;
|
|
1354
|
+
}
|
|
1355
|
+
function escapedByteLength(bytes) {
|
|
1356
|
+
let extra = 0;
|
|
1357
|
+
for (let index = 0; index < bytes.length; index += 1) if (bytes[index] === COMPOUND_ESCAPE) extra += 1;
|
|
1358
|
+
return bytes.length + extra;
|
|
1359
|
+
}
|
|
1360
|
+
function writeEscapedBytes(out, offset, bytes) {
|
|
1361
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
1362
|
+
const byte = bytes[index];
|
|
1363
|
+
if (byte === COMPOUND_ESCAPE) {
|
|
1379
1364
|
out[offset] = COMPOUND_ESCAPE;
|
|
1380
1365
|
out[offset + 1] = COMPOUND_ESCAPE_CONT;
|
|
1381
1366
|
offset += 2;
|
|
@@ -1383,27 +1368,86 @@ function encodeCompoundBytes(parts) {
|
|
|
1383
1368
|
out[offset] = byte;
|
|
1384
1369
|
offset += 1;
|
|
1385
1370
|
}
|
|
1386
|
-
out[offset] = COMPOUND_TERM;
|
|
1387
|
-
out[offset + 1] = COMPOUND_TERM;
|
|
1388
|
-
offset += 2;
|
|
1389
1371
|
}
|
|
1372
|
+
return offset;
|
|
1373
|
+
}
|
|
1374
|
+
function writeTerminator(out, offset) {
|
|
1375
|
+
out[offset] = COMPOUND_TERM;
|
|
1376
|
+
out[offset + 1] = COMPOUND_TERM;
|
|
1377
|
+
return offset + 2;
|
|
1378
|
+
}
|
|
1379
|
+
function encodeStringKey(value) {
|
|
1380
|
+
const length = walkUtf8(value, null, 0, false);
|
|
1381
|
+
const out = new Uint8Array(1 + length);
|
|
1382
|
+
out[0] = TYPE_STRING;
|
|
1383
|
+
walkUtf8(value, out, 1, false);
|
|
1390
1384
|
return out;
|
|
1391
1385
|
}
|
|
1386
|
+
function walkUtf8(value, out, offset, escapeNul) {
|
|
1387
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1388
|
+
const code = value.charCodeAt(index);
|
|
1389
|
+
if (code <= 127) {
|
|
1390
|
+
if (escapeNul && code === 0) {
|
|
1391
|
+
if (out !== null) {
|
|
1392
|
+
out[offset] = COMPOUND_ESCAPE;
|
|
1393
|
+
out[offset + 1] = COMPOUND_ESCAPE_CONT;
|
|
1394
|
+
}
|
|
1395
|
+
offset += 2;
|
|
1396
|
+
} else {
|
|
1397
|
+
if (out !== null) out[offset] = code;
|
|
1398
|
+
offset += 1;
|
|
1399
|
+
}
|
|
1400
|
+
continue;
|
|
1401
|
+
}
|
|
1402
|
+
if (code <= 2047) {
|
|
1403
|
+
if (out !== null) {
|
|
1404
|
+
out[offset] = 192 | code >> 6;
|
|
1405
|
+
out[offset + 1] = 128 | code & 63;
|
|
1406
|
+
}
|
|
1407
|
+
offset += 2;
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
if (code >= 55296 && code <= 56319) {
|
|
1411
|
+
const next = value.charCodeAt(index + 1);
|
|
1412
|
+
if (next >= 56320 && next <= 57343) {
|
|
1413
|
+
const point = (code - 55296 << 10) + (next - 56320) + 65536;
|
|
1414
|
+
if (out !== null) {
|
|
1415
|
+
out[offset] = 240 | point >> 18;
|
|
1416
|
+
out[offset + 1] = 128 | point >> 12 & 63;
|
|
1417
|
+
out[offset + 2] = 128 | point >> 6 & 63;
|
|
1418
|
+
out[offset + 3] = 128 | point & 63;
|
|
1419
|
+
}
|
|
1420
|
+
offset += 4;
|
|
1421
|
+
index += 1;
|
|
1422
|
+
continue;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
if (code >= 55296 && code <= 57343) throw new TypeError("compound key string parts must contain valid Unicode scalar values");
|
|
1426
|
+
if (out !== null) {
|
|
1427
|
+
out[offset] = 224 | code >> 12;
|
|
1428
|
+
out[offset + 1] = 128 | code >> 6 & 63;
|
|
1429
|
+
out[offset + 2] = 128 | code & 63;
|
|
1430
|
+
}
|
|
1431
|
+
offset += 3;
|
|
1432
|
+
}
|
|
1433
|
+
return offset;
|
|
1434
|
+
}
|
|
1392
1435
|
function encodeSortableNumber(value) {
|
|
1436
|
+
const bytes = /* @__PURE__ */ new Uint8Array(9);
|
|
1437
|
+
writeSortableNumber(new DataView(bytes.buffer), value);
|
|
1438
|
+
return bytes;
|
|
1439
|
+
}
|
|
1440
|
+
function writeSortableNumber(view, value) {
|
|
1393
1441
|
if (!Number.isFinite(value)) throw new TypeError("compound key number parts must be finite");
|
|
1394
1442
|
const normalized = Object.is(value, -0) ? 0 : value;
|
|
1395
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(9);
|
|
1396
|
-
const view = new DataView(buffer);
|
|
1397
1443
|
view.setUint8(0, TYPE_NUMBER);
|
|
1398
1444
|
view.setFloat64(1, normalized, false);
|
|
1399
1445
|
let bits = view.getBigUint64(1, false);
|
|
1400
1446
|
bits = (bits & 1n << 63n) !== 0n ? ~bits & F64_MASK : bits ^ 1n << 63n;
|
|
1401
1447
|
view.setBigUint64(1, bits, false);
|
|
1402
|
-
return new Uint8Array(buffer);
|
|
1403
1448
|
}
|
|
1404
1449
|
//#endregion
|
|
1405
1450
|
//#region src/indexing.ts
|
|
1406
|
-
var encoder = new TextEncoder();
|
|
1407
1451
|
var fatalDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
1408
1452
|
var MISSING = Symbol("moyodb.indexing.missing");
|
|
1409
1453
|
var FNV64_OFFSET = BigInt("0xcbf29ce484222325");
|
|
@@ -1486,37 +1530,50 @@ function decodeIndexMetadataValue(bytes) {
|
|
|
1486
1530
|
}
|
|
1487
1531
|
}
|
|
1488
1532
|
function encodeIndexEntryKey(logicalIndexKey, primaryKey) {
|
|
1489
|
-
|
|
1533
|
+
const out = new Uint8Array(compoundEncodedLength(logicalIndexKey) + compoundEncodedLength(primaryKey));
|
|
1534
|
+
writeCompoundPart(out, writeCompoundPart(out, 0, logicalIndexKey), primaryKey);
|
|
1535
|
+
return out;
|
|
1490
1536
|
}
|
|
1491
1537
|
function decodeIndexEntryKey(bytes) {
|
|
1492
|
-
let parts;
|
|
1493
1538
|
try {
|
|
1494
|
-
|
|
1539
|
+
return decodeTwoPartIndexKey(bytes);
|
|
1495
1540
|
} catch (error) {
|
|
1541
|
+
if (error instanceof SerializationError) throw error;
|
|
1496
1542
|
throw new SerializationError(`invalid index entry key encoding: ${String(error)}`);
|
|
1497
1543
|
}
|
|
1498
|
-
if (parts.length !== 2) throw new SerializationError("invalid index entry key encoding");
|
|
1499
|
-
return {
|
|
1500
|
-
logicalKey: parts[0],
|
|
1501
|
-
primaryKey: parts[1]
|
|
1502
|
-
};
|
|
1503
1544
|
}
|
|
1504
1545
|
function indexKeyExactRange(logicalIndexKey) {
|
|
1505
|
-
|
|
1546
|
+
const gte = encodeCompoundPrefix(logicalIndexKey);
|
|
1547
|
+
const lt = advanceEncodedPrefix(gte.slice());
|
|
1548
|
+
return lt ? {
|
|
1549
|
+
gte,
|
|
1550
|
+
lt
|
|
1551
|
+
} : { gte };
|
|
1552
|
+
}
|
|
1553
|
+
/** WASM `usize` is 32-bit, so this is the largest limit the engine can accept. */
|
|
1554
|
+
var MAX_ENGINE_SCAN_LIMIT = 4294967295;
|
|
1555
|
+
/**
|
|
1556
|
+
* Bounds and limits follow the engine `RangeSpec` contract.
|
|
1557
|
+
* Conflicting bounds and a limit the engine cannot store are `InvalidRangeError`.
|
|
1558
|
+
*/
|
|
1559
|
+
function assertValidScanRange(range = {}) {
|
|
1560
|
+
if (range.gt !== void 0 && range.gte !== void 0) throw new InvalidRangeError("range cannot include both gt and gte");
|
|
1561
|
+
if (range.lt !== void 0 && range.lte !== void 0) throw new InvalidRangeError("range cannot include both lt and lte");
|
|
1562
|
+
if (range.limit !== void 0 && (!Number.isSafeInteger(range.limit) || range.limit < 0 || range.limit > 4294967295)) throw new InvalidRangeError("limit must be an integer between 0 and 4294967295");
|
|
1506
1563
|
}
|
|
1507
1564
|
function indexRangeToPhysicalRange(range = {}) {
|
|
1508
|
-
|
|
1565
|
+
assertValidScanRange(range);
|
|
1509
1566
|
const physical = {};
|
|
1510
1567
|
if (range.reverse !== void 0) physical.reverse = range.reverse;
|
|
1511
1568
|
if (range.limit !== void 0) physical.limit = range.limit;
|
|
1512
|
-
if (range.gte) physical.gte =
|
|
1569
|
+
if (range.gte) physical.gte = encodeCompoundPrefix(range.gte);
|
|
1513
1570
|
if (range.gt) {
|
|
1514
|
-
const lower =
|
|
1571
|
+
const lower = advanceEncodedPrefix(encodeCompoundPrefix(range.gt));
|
|
1515
1572
|
if (lower) physical.gte = lower;
|
|
1516
1573
|
}
|
|
1517
|
-
if (range.lt) physical.lt =
|
|
1574
|
+
if (range.lt) physical.lt = encodeCompoundPrefix(range.lt);
|
|
1518
1575
|
if (range.lte) {
|
|
1519
|
-
const upper =
|
|
1576
|
+
const upper = advanceEncodedPrefix(encodeCompoundPrefix(range.lte));
|
|
1520
1577
|
if (upper) physical.lt = upper;
|
|
1521
1578
|
}
|
|
1522
1579
|
return physical;
|
|
@@ -1602,7 +1659,7 @@ function serializeIndexKeyPath(def) {
|
|
|
1602
1659
|
}
|
|
1603
1660
|
function makeInternalIndexStoreName(store, name) {
|
|
1604
1661
|
const candidate = `${INTERNAL_INDEX_STORE_PREFIX}${base64Url(utf8Encode(store))}:${base64Url(utf8Encode(name))}`;
|
|
1605
|
-
if (
|
|
1662
|
+
if (utf8Encode(candidate).length <= 255) return candidate;
|
|
1606
1663
|
return `${INTERNAL_INDEX_STORE_PREFIX}h:${fnv1a64Hex(utf8Encode(`${store}\u0000${name}`))}`;
|
|
1607
1664
|
}
|
|
1608
1665
|
function base64Url(bytes) {
|
|
@@ -1647,11 +1704,113 @@ function describeValue(value) {
|
|
|
1647
1704
|
if (Array.isArray(value)) return "array";
|
|
1648
1705
|
return typeof value;
|
|
1649
1706
|
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1707
|
+
var INDEX_KEY_ESCAPE = 0;
|
|
1708
|
+
var INDEX_KEY_ESCAPE_CONT = 255;
|
|
1709
|
+
var INDEX_KEY_TERM = 0;
|
|
1710
|
+
function compoundEncodedLength(part) {
|
|
1711
|
+
let zeros = 0;
|
|
1712
|
+
const length = part.length;
|
|
1713
|
+
for (let index = 0; index < length; index += 1) if (part[index] === INDEX_KEY_ESCAPE) zeros += 1;
|
|
1714
|
+
return length + zeros + 2;
|
|
1715
|
+
}
|
|
1716
|
+
function writeCompoundPart(out, offset, part) {
|
|
1717
|
+
const length = part.length;
|
|
1718
|
+
for (let index = 0; index < length; index += 1) {
|
|
1719
|
+
const byte = part[index];
|
|
1720
|
+
if (byte === INDEX_KEY_ESCAPE) {
|
|
1721
|
+
out[offset] = INDEX_KEY_ESCAPE;
|
|
1722
|
+
out[offset + 1] = INDEX_KEY_ESCAPE_CONT;
|
|
1723
|
+
offset += 2;
|
|
1724
|
+
} else {
|
|
1725
|
+
out[offset] = byte;
|
|
1726
|
+
offset += 1;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
out[offset] = INDEX_KEY_TERM;
|
|
1730
|
+
out[offset + 1] = INDEX_KEY_TERM;
|
|
1731
|
+
return offset + 2;
|
|
1732
|
+
}
|
|
1733
|
+
function encodeCompoundPrefix(part) {
|
|
1734
|
+
const out = new Uint8Array(compoundEncodedLength(part));
|
|
1735
|
+
writeCompoundPart(out, 0, part);
|
|
1736
|
+
return out;
|
|
1737
|
+
}
|
|
1738
|
+
function advanceEncodedPrefix(prefix) {
|
|
1739
|
+
for (let index = prefix.length - 1; index >= 0; index -= 1) if (prefix[index] !== 255) {
|
|
1740
|
+
prefix[index] += 1;
|
|
1741
|
+
return index + 1 === prefix.length ? prefix : prefix.subarray(0, index + 1);
|
|
1742
|
+
}
|
|
1743
|
+
return null;
|
|
1744
|
+
}
|
|
1745
|
+
function decodeTwoPartIndexKey(bytes) {
|
|
1746
|
+
const cursor = {
|
|
1747
|
+
unescaped: 0,
|
|
1748
|
+
end: 0
|
|
1749
|
+
};
|
|
1750
|
+
if (!readCompoundPart(bytes, 0, cursor)) throw new SerializationError("invalid index entry key encoding");
|
|
1751
|
+
const logicalLength = cursor.unescaped;
|
|
1752
|
+
const primaryStart = cursor.end;
|
|
1753
|
+
if (!readCompoundPart(bytes, primaryStart, cursor)) throw new SerializationError("invalid index entry key encoding");
|
|
1754
|
+
const primaryLength = cursor.unescaped;
|
|
1755
|
+
let end = cursor.end;
|
|
1756
|
+
if (end !== bytes.length) for (;;) {
|
|
1757
|
+
if (!readCompoundPart(bytes, end, cursor)) throw new SerializationError("invalid index entry key encoding");
|
|
1758
|
+
if (cursor.end <= end) throw new TypeError("invalid compound key encoding");
|
|
1759
|
+
end = cursor.end;
|
|
1760
|
+
if (end === bytes.length) throw new SerializationError("invalid index entry key encoding");
|
|
1761
|
+
}
|
|
1762
|
+
const logicalKey = new Uint8Array(logicalLength);
|
|
1763
|
+
const primaryKey = new Uint8Array(primaryLength);
|
|
1764
|
+
copyUnescapedPart(bytes, 0, logicalKey);
|
|
1765
|
+
copyUnescapedPart(bytes, primaryStart, primaryKey);
|
|
1766
|
+
return {
|
|
1767
|
+
logicalKey,
|
|
1768
|
+
primaryKey
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
function readCompoundPart(bytes, start, cursor) {
|
|
1772
|
+
if (start >= bytes.length) return false;
|
|
1773
|
+
let unescaped = 0;
|
|
1774
|
+
for (let index = start; index < bytes.length; index += 1) {
|
|
1775
|
+
if (bytes[index] !== INDEX_KEY_ESCAPE) {
|
|
1776
|
+
unescaped += 1;
|
|
1777
|
+
continue;
|
|
1778
|
+
}
|
|
1779
|
+
const next = bytes[index + 1];
|
|
1780
|
+
if (next === INDEX_KEY_ESCAPE_CONT) {
|
|
1781
|
+
unescaped += 1;
|
|
1782
|
+
index += 1;
|
|
1783
|
+
continue;
|
|
1784
|
+
}
|
|
1785
|
+
if (next === INDEX_KEY_TERM) {
|
|
1786
|
+
cursor.unescaped = unescaped;
|
|
1787
|
+
cursor.end = index + 2;
|
|
1788
|
+
return true;
|
|
1789
|
+
}
|
|
1790
|
+
throw new TypeError("invalid compound key encoding");
|
|
1791
|
+
}
|
|
1792
|
+
throw new TypeError("compound key terminated unexpectedly");
|
|
1793
|
+
}
|
|
1794
|
+
function copyUnescapedPart(bytes, start, out) {
|
|
1795
|
+
const needed = out.length;
|
|
1796
|
+
let offset = 0;
|
|
1797
|
+
for (let index = start; offset < needed; index += 1) {
|
|
1798
|
+
const byte = bytes[index];
|
|
1799
|
+
if (byte !== INDEX_KEY_ESCAPE) {
|
|
1800
|
+
out[offset] = byte;
|
|
1801
|
+
offset += 1;
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
if (bytes[index + 1] === INDEX_KEY_ESCAPE_CONT) {
|
|
1805
|
+
out[offset] = INDEX_KEY_ESCAPE;
|
|
1806
|
+
offset += 1;
|
|
1807
|
+
index += 1;
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1653
1812
|
}
|
|
1654
1813
|
//#endregion
|
|
1655
|
-
export {
|
|
1814
|
+
export { SerializationError as $, jsonDecode as A, isWorkerProtocolResponseMessage as At, CorruptionError as B, unpackPackedBinaryList as Bt, serializeNormalizedIndexDefinitions as C, isWorkerCommand as Ct, encodeCompoundKeyParts as D, isWorkerProtocolRequestBatchMessage as Dt, compoundKeyRange as E, isWorkerProtocolReadyMessage as Et, u64Key as F, prepareWorkerCommandPayload as Ft, InternalError as G, clampTimerDelayMs as Gt, DatabaseClosedError as H, unpackPackedOptionalValues as Ht, utf8Decode as I, prepareWorkerResponsePayload as It, KeyTooLargeError as J, InvalidOpenOptionsError as K, compareStringsByCodeUnit as Kt, utf8Encode as L, serializeWorkerError as Lt, prefixRange as M, packedBinaryListBytes as Mt, prefixSuccessor as N, packedOptionalValues as Nt, encodeIndexScalar as O, isWorkerProtocolRequestMessage as Ot, splitCompoundKey as P, packedScanRows as Pt, ReservedStoreNameError as Q, ChangeFeedCompactedError as R, unpackPackedBatchOpKeys as Rt, normalizeIndexDefinitions as S, isAutocommitCommand as St, compoundKey as T, isWorkerProtocolReadyEnvelope as Tt, IndexNotFoundError as U, unpackPackedScanRows as Ut, DatabaseBusyError as V, unpackPackedBinaryPairKeys as Vt, InjectedFailureError as W, workerProtocolError as Wt, ReadonlyTransactionError as X, MoyoDbError as Y, RecoveryRequiredError as Z, indexDefinitionIdentity as _, WORKER_PROTOCOL_RESPONSE_BATCH as _t, cloneNormalizedIndexDefinitions as a, TransactionConflictError as at, indexesForStore as b, decodeWorkerResponsePayload as bt, decodeIndexEntryKey as c, ValueTooLargeError as ct, encodeIndexEntryKey as d, normalizeError as dt, StorageError as et, encodeIndexMetadataKey as f, MAX_WORKER_BATCH_BYTES as ft, findIndexDefinition as g, WORKER_PROTOCOL_RESPONSE as gt, extractLogicalIndexKeyFromDocument as h, WORKER_PROTOCOL_REQUEST_BATCH as ht, assertValidScanRange as i, TransactionClosedError as it, jsonEncode as j, packedBatchOpsBytes as jt, indexKey as k, isWorkerProtocolResponseBatchMessage as kt, decodeIndexMetadataValue as l, VersionError as lt, extractLogicalIndexKey as m, WORKER_PROTOCOL_REQUEST as mt, MAX_ENGINE_SCAN_LIMIT as n, StoreNameTooLongError as nt, compareNormalizedIndexDefinitions as o, UniqueIndexConstraintError as ot, encodeIndexMetadataValue as p, WORKER_PROTOCOL_READY as pt, InvalidRangeError as q, isRecord as qt, assertPublicStoreName as r, StoreNotFoundError as rt, createIndexKeyExtractor as s, UnsupportedPlatformError as st, INDEX_METADATA_STORE as t, StoreExistsError as tt, decodeIndexedDocument as u, WriteTransactionAlreadyOpenError as ut, indexKeyExactRange as v, captureWorkerPayload as vt, toPublicIndexDefinitions as w, isWorkerProtocolEnvelope as wt, isInternalStoreName as x, deserializeWorkerError as xt, indexRangeToPhysicalRange as y, decodeWorkerCommandPayload as yt, ConstraintError as z, unpackPackedBatchOps as zt };
|
|
1656
1815
|
|
|
1657
|
-
//# sourceMappingURL=indexing-
|
|
1816
|
+
//# sourceMappingURL=indexing-DdpU69Fd.js.map
|