@moyodb/sdk 1.1.0 → 1.4.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.
Files changed (59) hide show
  1. package/CONTRIBUTING.md +46 -0
  2. package/README.md +144 -0
  3. package/dist/assets/browser-worker-Bj2ErRvC.js +4 -0
  4. package/dist/assets/browser-worker-Bj2ErRvC.js.map +1 -0
  5. package/dist/assets/shared-worker-CMeTcusa.js +2 -0
  6. package/dist/assets/shared-worker-CMeTcusa.js.map +1 -0
  7. package/dist/chunks/{indexing-BzmFhWXs.js → indexing-B0duqlUs.js} +131 -124
  8. package/dist/chunks/indexing-B0duqlUs.js.map +1 -0
  9. package/dist/compression.d.ts +16 -2
  10. package/dist/compression.d.ts.map +1 -1
  11. package/dist/demo.d.ts.map +1 -1
  12. package/dist/engine/README.md +32 -3
  13. package/dist/engine/moyodb_engine.d.ts +36 -10
  14. package/dist/engine/moyodb_engine.js +261 -51
  15. package/dist/engine/moyodb_engine_bg.wasm +0 -0
  16. package/dist/engine/moyodb_engine_bg.wasm.d.ts +18 -10
  17. package/dist/engine/package.json +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/indexing.d.ts.map +1 -1
  20. package/dist/internal.d.ts +6 -0
  21. package/dist/internal.d.ts.map +1 -1
  22. package/dist/moyodb-sdk.js +1069 -835
  23. package/dist/moyodb-sdk.js.map +1 -1
  24. package/dist/node-engine.js +731 -111
  25. package/dist/node-engine.js.map +1 -1
  26. package/dist/node-storage.d.mts +4 -0
  27. package/dist/node-storage.mjs +38 -3
  28. package/dist/node-worker-client.d.ts +1 -0
  29. package/dist/node-worker-client.d.ts.map +1 -1
  30. package/dist/node-worker.mjs +2 -1
  31. package/dist/node.d.ts.map +1 -1
  32. package/dist/node.js +302 -67
  33. package/dist/node.js.map +1 -1
  34. package/dist/registry.d.ts.map +1 -1
  35. package/dist/shared-worker-client.d.ts +4 -0
  36. package/dist/shared-worker-client.d.ts.map +1 -1
  37. package/dist/shared-worker.d.ts.map +1 -1
  38. package/dist/snappy.d.ts +3 -0
  39. package/dist/snappy.d.ts.map +1 -0
  40. package/dist/sql-parser.d.ts.map +1 -1
  41. package/dist/types.d.ts +33 -3
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/worker-api.d.ts +19 -6
  44. package/dist/worker-api.d.ts.map +1 -1
  45. package/dist/worker-client.d.ts +7 -2
  46. package/dist/worker-client.d.ts.map +1 -1
  47. package/dist/worker-protocol.d.ts +18 -3
  48. package/dist/worker-protocol.d.ts.map +1 -1
  49. package/dist/worker-server.d.ts.map +1 -1
  50. package/dist/worker.d.ts +33 -4
  51. package/dist/worker.d.ts.map +1 -1
  52. package/package.json +6 -5
  53. package/dist/assets/browser-worker-DP6Mjz7c.js +0 -4
  54. package/dist/assets/browser-worker-DP6Mjz7c.js.map +0 -1
  55. package/dist/assets/shared-worker-DKzhauVf.js +0 -2
  56. package/dist/assets/shared-worker-DKzhauVf.js.map +0 -1
  57. package/dist/chunks/indexing-BzmFhWXs.js.map +0 -1
  58. package/dist/engine/snippets/moyodb-engine-cff0a0e2441a7a8f/js/opfs_shim.js +0 -513
  59. /package/dist/engine/snippets/{moyodb-engine-8ebe6af0cc2e81b7 → moyodb-engine-1d53039816cbc2f7}/js/opfs_shim.js +0 -0
@@ -6,6 +6,15 @@ function compareStringsByCodeUnit(left, right) {
6
6
  if (left < right) return -1;
7
7
  return left > right ? 1 : 0;
8
8
  }
9
+ /**
10
+ * Delays above 2^31-1 do not fit in the platform timer word. Node fires them
11
+ * after 1ms; other runtimes can wrap them to zero. Clamp instead of aborting.
12
+ */
13
+ var MAX_TIMER_DELAY_MS = 2147483647;
14
+ function clampTimerDelayMs(delayMs) {
15
+ if (!Number.isFinite(delayMs) || delayMs <= 0) return 0;
16
+ return delayMs > 2147483647 ? MAX_TIMER_DELAY_MS : delayMs;
17
+ }
9
18
  var WORKER_PROTOCOL_READY = "moyodb:worker-protocol:ready";
10
19
  var WORKER_PROTOCOL_REQUEST = "moyodb:worker-protocol:request";
11
20
  var WORKER_PROTOCOL_RESPONSE = "moyodb:worker-protocol:response";
@@ -33,6 +42,8 @@ var WORKER_COMMANDS = [
33
42
  "deleteMany",
34
43
  "applyBatch",
35
44
  "scan",
45
+ "scanPage",
46
+ "closeCursor",
36
47
  "getByIndex",
37
48
  "scanByIndex",
38
49
  "scanByIndexPage",
@@ -74,6 +85,7 @@ function isAutocommitCommand(value) {
74
85
  var PACKED_BINARY_LIST_V1 = "moyodb:packed-binary-list:v1";
75
86
  var PACKED_NULLABLE_BINARY_LIST_V1 = "moyodb:packed-nullable-binary-list:v1";
76
87
  var PACKED_SCAN_ROWS_V1 = "moyodb:packed-scan-rows:v1";
88
+ var PACKED_ENGINE_SCAN_ROWS_V1 = "moyodb:packed-engine-scan-rows:v1";
77
89
  var PACKED_BATCH_OPS_V1 = "moyodb:packed-batch-ops:v1";
78
90
  var PACKED_OPTIONAL_VALUES_V1 = "moyodb:packed-optional-values:v1";
79
91
  var BATCH_OP_DELETE = 0;
@@ -131,22 +143,21 @@ function deserializeWorkerError(error) {
131
143
  const deserialized = new Error(error.message);
132
144
  deserialized.name = error.name || error.code || "Error";
133
145
  if (error.stack) deserialized.stack = error.stack;
134
- if (error.code) Object.defineProperty(deserialized, "code", {
135
- value: error.code,
136
- enumerable: true,
137
- configurable: true
138
- });
146
+ if (error.code) defineErrorCode(deserialized, error.code);
139
147
  return deserialized;
140
148
  }
141
149
  function workerProtocolError(name, message, code = name) {
142
150
  const error = new Error(message);
143
151
  error.name = name;
152
+ defineErrorCode(error, code);
153
+ return error;
154
+ }
155
+ function defineErrorCode(error, code) {
144
156
  Object.defineProperty(error, "code", {
145
157
  value: code,
146
158
  enumerable: true,
147
159
  configurable: true
148
160
  });
149
- return error;
150
161
  }
151
162
  function prepareWorkerCommandPayload(command, args) {
152
163
  if (command === "autocommit") {
@@ -251,7 +262,7 @@ function decodeWorkerCommandPayload(command, args) {
251
262
  if (command === "getMany" || command === "deleteMany") {
252
263
  const [txId, store, keys] = args;
253
264
  if (!Array.isArray(keys)) {
254
- if (!isPackedBinaryList(keys)) throw workerProtocolError("WorkerProtocolError", "invalid packed binary-list argument");
265
+ if (!isPackedPayload(keys, PACKED_BINARY_LIST_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed binary-list argument");
255
266
  return [
256
267
  txId,
257
268
  store,
@@ -262,11 +273,11 @@ function decodeWorkerCommandPayload(command, args) {
262
273
  if (command === "putMany") {
263
274
  const [txId, store, entries, options] = args;
264
275
  if (!Array.isArray(entries)) {
265
- if (!isPackedBinaryList(entries)) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany argument");
276
+ if (!isPackedPayload(entries, PACKED_BINARY_LIST_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany argument");
266
277
  return [
267
278
  txId,
268
279
  store,
269
- unpackBinaryPairs(entries),
280
+ unpackPutManyPayload(entries, false),
270
281
  options
271
282
  ];
272
283
  }
@@ -274,21 +285,21 @@ function decodeWorkerCommandPayload(command, args) {
274
285
  if (command === "applyBatch") {
275
286
  const [txId, store, ops] = args;
276
287
  if (!Array.isArray(ops)) {
277
- if (!isPackedBatchOps(ops)) throw workerProtocolError("WorkerProtocolError", "invalid packed batch argument");
288
+ if (!isPackedPayload(ops, PACKED_BATCH_OPS_V1)) throw workerProtocolError("WorkerProtocolError", "invalid packed batch argument");
278
289
  return [
279
290
  txId,
280
291
  store,
281
- unpackBatchOps(ops)
292
+ unpackBatchPayload(ops, false)
282
293
  ];
283
294
  }
284
295
  }
285
296
  return args;
286
297
  }
287
298
  function packedBinaryListBytes(value) {
288
- return isPackedBinaryList(value) ? value.bytes : null;
299
+ return isPackedPayload(value, PACKED_BINARY_LIST_V1) ? value.bytes : null;
289
300
  }
290
301
  function packedBatchOpsBytes(value) {
291
- return isPackedBatchOps(value) ? value.bytes : null;
302
+ return isPackedPayload(value, PACKED_BATCH_OPS_V1) ? value.bytes : null;
292
303
  }
293
304
  function unpackPackedBinaryList(bytes) {
294
305
  return unpackBinaryList({
@@ -296,29 +307,23 @@ function unpackPackedBinaryList(bytes) {
296
307
  bytes
297
308
  });
298
309
  }
299
- function unpackPackedBinaryPairs(bytes) {
300
- return unpackBinaryPairs({
301
- __moyodbPacked: PACKED_BINARY_LIST_V1,
302
- bytes
303
- });
304
- }
305
310
  function unpackPackedBinaryPairKeys(bytes) {
306
- return unpackBinaryPairKeys({
311
+ return unpackPutManyPayload({
307
312
  __moyodbPacked: PACKED_BINARY_LIST_V1,
308
313
  bytes
309
- });
314
+ }, true);
310
315
  }
311
316
  function unpackPackedBatchOps(bytes) {
312
- return unpackBatchOps({
317
+ return unpackBatchPayload({
313
318
  __moyodbPacked: PACKED_BATCH_OPS_V1,
314
319
  bytes
315
- });
320
+ }, false);
316
321
  }
317
322
  function unpackPackedBatchOpKeys(bytes) {
318
- return unpackBatchOpKeys({
323
+ return unpackBatchPayload({
319
324
  __moyodbPacked: PACKED_BATCH_OPS_V1,
320
325
  bytes
321
- });
326
+ }, true);
322
327
  }
323
328
  function packedOptionalValues(bytes) {
324
329
  return {
@@ -349,12 +354,37 @@ function unpackPackedOptionalValues(bytes) {
349
354
  return items;
350
355
  }
351
356
  function prepareWorkerResponsePayload(command, result) {
352
- if (command === "getMany" && isPackedOptionalValues(result)) return {
357
+ if ((command === "scan" || command === "scanByIndex") && (isPackedEngineScanRows(result) || isPackedPayload(result, PACKED_SCAN_ROWS_V1))) return {
358
+ result,
359
+ transfer: collectDirectBinaryTransferable(result.bytes)
360
+ };
361
+ if (command === "scanPage") {
362
+ const page = result;
363
+ if (isRecord(page) && (isPackedEngineScanRows(page.rows) || isPackedPayload(page.rows, PACKED_SCAN_ROWS_V1))) return {
364
+ result: page,
365
+ transfer: collectDirectBinaryTransferable(page.rows.bytes)
366
+ };
367
+ if (isRecord(page) && Array.isArray(page.rows)) {
368
+ const packed = packScanRows(page.rows);
369
+ return {
370
+ result: {
371
+ ...page,
372
+ rows: packed ?? page.rows
373
+ },
374
+ transfer: packed ? [packed.bytes.buffer] : collectTransferablesForValue(page.rows)
375
+ };
376
+ }
377
+ }
378
+ if (command === "getMany" && isPackedPayload(result, PACKED_OPTIONAL_VALUES_V1)) return {
353
379
  result,
354
380
  transfer: collectDirectBinaryTransferable(result.bytes)
355
381
  };
356
382
  if (command === "scanByIndexPage") {
357
383
  const page = result;
384
+ if (isRecord(page) && isPackedPayload(page.rows, PACKED_SCAN_ROWS_V1)) return {
385
+ result: page,
386
+ transfer: collectTransferablesForValue(page)
387
+ };
358
388
  if (isRecord(page) && Array.isArray(page.rows)) {
359
389
  const packed = page.rows.length > 0 ? packScanRows(page.rows) : null;
360
390
  const response = {
@@ -411,20 +441,71 @@ function prepareWorkerResponsePayload(command, result) {
411
441
  };
412
442
  }
413
443
  function decodeWorkerResponsePayload(command, result) {
414
- if (command === "getMany" && isPackedNullableBinaryList(result)) return unpackNullableBinaryList(result);
415
- if (command === "getMany" && isPackedOptionalValues(result)) return unpackPackedOptionalValues(result.bytes);
444
+ if (command === "scanPage") {
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");
446
+ const rows = isPackedEngineScanRows(result.rows) ? unpackPackedScanRows(result.rows.bytes) : isPackedPayload(result.rows, PACKED_SCAN_ROWS_V1) ? unpackScanRows(result.rows) : result.rows;
447
+ if (!Array.isArray(rows)) throw workerProtocolError("WorkerProtocolError", "invalid scan page rows");
448
+ let bytes = 4;
449
+ for (const row of rows) {
450
+ if (!isRecord(row) || !(row.key instanceof Uint8Array) || !(row.value instanceof Uint8Array)) throw workerProtocolError("WorkerProtocolError", "invalid scan page row");
451
+ bytes += 8 + row.key.byteLength + row.value.byteLength;
452
+ }
453
+ if (bytes !== result.bytes) throw workerProtocolError("WorkerProtocolError", "scan page byte count mismatch");
454
+ return {
455
+ rows,
456
+ cursorId: result.cursorId,
457
+ done: result.done,
458
+ bytes: result.bytes
459
+ };
460
+ }
461
+ if ((command === "scan" || command === "scanByIndex") && isPackedEngineScanRows(result)) return unpackPackedScanRows(result.bytes);
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);
416
464
  if (command === "getMany" && !Array.isArray(result)) throw workerProtocolError("WorkerProtocolError", "invalid packed getMany response");
417
465
  if (command === "scanByIndexPage") {
418
- if (!isRecord(result) || !Array.isArray(result.rows) && !isPackedScanRows(result.rows) || result.cursor !== null && !(result.cursor instanceof Uint8Array)) throw workerProtocolError("WorkerProtocolError", "invalid packed index scan page response");
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");
419
467
  return {
420
- rows: isPackedScanRows(result.rows) ? unpackScanRows(result.rows) : result.rows,
468
+ rows: isPackedPayload(result.rows, PACKED_SCAN_ROWS_V1) ? unpackScanRows(result.rows) : result.rows,
421
469
  cursor: result.cursor
422
470
  };
423
471
  }
424
- if ((command === "scan" || command === "scanByIndex") && isPackedScanRows(result)) return unpackScanRows(result);
472
+ if ((command === "scan" || command === "scanByIndex") && isPackedPayload(result, PACKED_SCAN_ROWS_V1)) return unpackScanRows(result);
425
473
  if ((command === "scan" || command === "scanByIndex") && !Array.isArray(result)) throw workerProtocolError("WorkerProtocolError", "invalid packed scan response");
426
474
  return result;
427
475
  }
476
+ function packedScanRows(bytes) {
477
+ return {
478
+ __moyodbPacked: PACKED_ENGINE_SCAN_ROWS_V1,
479
+ bytes
480
+ };
481
+ }
482
+ function isPackedEngineScanRows(value) {
483
+ return isRecord(value) && value.__moyodbPacked === PACKED_ENGINE_SCAN_ROWS_V1 && value.bytes instanceof Uint8Array;
484
+ }
485
+ function unpackPackedScanRows(bytes) {
486
+ if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid engine scan packet");
487
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
488
+ const count = view.getUint32(0, true);
489
+ if (count > (bytes.byteLength - 4) / 8) throw workerProtocolError("WorkerProtocolError", "engine scan row count exceeds packet length");
490
+ const rows = new Array(count);
491
+ let offset = 4;
492
+ for (let index = 0; index < count; index += 1) {
493
+ if (offset + 8 > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "truncated engine scan row");
494
+ const keyLength = view.getUint32(offset, true);
495
+ const valueLength = view.getUint32(offset + 4, true);
496
+ const keyStart = offset + 8;
497
+ const valueStart = keyStart + keyLength;
498
+ const end = valueStart + valueLength;
499
+ if (end > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "engine scan row exceeds packet length");
500
+ rows[index] = {
501
+ key: bytes.subarray(keyStart, valueStart),
502
+ value: bytes.subarray(valueStart, end)
503
+ };
504
+ offset = end;
505
+ }
506
+ if (offset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "engine scan packet has trailing bytes");
507
+ return rows;
508
+ }
428
509
  function collectTransferablesForValue(value) {
429
510
  const direct = directBinaryTransferable(value);
430
511
  if (direct !== null) return [direct];
@@ -627,7 +708,7 @@ function unpackBinaryList(payload) {
627
708
  if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed binary-list payload has trailing bytes");
628
709
  return items;
629
710
  }
630
- function unpackBinaryPairs(payload) {
711
+ function unpackPutManyPayload(payload, keysOnly) {
631
712
  const bytes = payload.bytes;
632
713
  if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany payload");
633
714
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -647,38 +728,13 @@ function unpackBinaryPairs(payload) {
647
728
  if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany key exceeds payload length");
648
729
  const valueEnd = keyEnd + valueLength;
649
730
  if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany value exceeds payload length");
650
- entries[index] = [bytes.subarray(readOffset, keyEnd), bytes.subarray(keyEnd, valueEnd)];
731
+ if (keysOnly) entries[index] = bytes.subarray(readOffset, keyEnd);
732
+ else entries[index] = [bytes.subarray(readOffset, keyEnd), bytes.subarray(keyEnd, valueEnd)];
651
733
  readOffset = valueEnd;
652
734
  }
653
735
  if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has trailing bytes");
654
736
  return entries;
655
737
  }
656
- function unpackBinaryPairKeys(payload) {
657
- const bytes = payload.bytes;
658
- if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed putMany payload");
659
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
660
- const itemCount = view.getUint32(0, true);
661
- if (itemCount % 2 !== 0) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has an odd item count");
662
- const payloadOffset = checkedAdd(4, checkedByteCount(itemCount, 4, "packed putMany metadata"), "packed putMany header");
663
- if (payloadOffset > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany metadata exceeds payload length");
664
- const entryCount = itemCount / 2;
665
- const keys = new Array(entryCount);
666
- let metadataOffset = 4;
667
- let readOffset = payloadOffset;
668
- for (let index = 0; index < entryCount; index += 1) {
669
- const keyLength = view.getUint32(metadataOffset, true);
670
- const valueLength = view.getUint32(metadataOffset + 4, true);
671
- metadataOffset += 8;
672
- const keyEnd = readOffset + keyLength;
673
- if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany key exceeds payload length");
674
- const valueEnd = keyEnd + valueLength;
675
- if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany value exceeds payload length");
676
- keys[index] = bytes.subarray(readOffset, keyEnd);
677
- readOffset = valueEnd;
678
- }
679
- if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed putMany payload has trailing bytes");
680
- return keys;
681
- }
682
738
  function packNullableBinaryList(items) {
683
739
  const count = items.length;
684
740
  const metadataBytes = checkedByteCount(count, 5, "packed nullable binary-list metadata");
@@ -859,7 +915,7 @@ function packBatchOps(ops) {
859
915
  bytes
860
916
  };
861
917
  }
862
- function unpackBatchOps(payload) {
918
+ function unpackBatchPayload(payload, keysOnly) {
863
919
  const bytes = payload.bytes;
864
920
  if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed batch payload");
865
921
  const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
@@ -889,69 +945,22 @@ function unpackBatchOps(payload) {
889
945
  if (kind !== BATCH_OP_PUT) throw workerProtocolError("WorkerProtocolError", `packed batch operation has invalid kind byte: ${kind}`);
890
946
  const valueEnd = readOffset + valueLength;
891
947
  if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch value exceeds payload length");
892
- ops[index] = {
948
+ if (keysOnly) ops[index] = {
893
949
  kind: "put",
894
- key,
895
- value: bytes.subarray(readOffset, valueEnd)
950
+ key
896
951
  };
897
- readOffset = valueEnd;
898
- }
899
- if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch payload has trailing bytes");
900
- return ops;
901
- }
902
- function unpackBatchOpKeys(payload) {
903
- const bytes = payload.bytes;
904
- if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4) throw workerProtocolError("WorkerProtocolError", "invalid packed batch payload");
905
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
906
- const count = view.getUint32(0, true);
907
- const payloadOffset = checkedAdd(4, checkedByteCount(count, 9, "packed batch metadata"), "packed batch header");
908
- if (payloadOffset > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch metadata exceeds payload length");
909
- const ops = new Array(count);
910
- let metadataOffset = 4;
911
- let readOffset = payloadOffset;
912
- for (let index = 0; index < count; index += 1) {
913
- const kind = view.getUint8(metadataOffset);
914
- const keyLength = view.getUint32(metadataOffset + 1, true);
915
- const valueLength = view.getUint32(metadataOffset + 5, true);
916
- metadataOffset += 9;
917
- const keyEnd = readOffset + keyLength;
918
- if (keyEnd > U32_MAX || keyEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch key exceeds payload length");
919
- const key = bytes.subarray(readOffset, keyEnd);
920
- readOffset = keyEnd;
921
- if (kind === BATCH_OP_DELETE) {
922
- if (valueLength !== 0) throw workerProtocolError("WorkerProtocolError", "packed delete operation has a value payload");
923
- ops[index] = {
924
- kind: "delete",
925
- key
926
- };
927
- continue;
928
- }
929
- if (kind !== BATCH_OP_PUT) throw workerProtocolError("WorkerProtocolError", `packed batch operation has invalid kind byte: ${kind}`);
930
- const valueEnd = readOffset + valueLength;
931
- if (valueEnd > U32_MAX || valueEnd > bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch value exceeds payload length");
932
- ops[index] = {
952
+ else ops[index] = {
933
953
  kind: "put",
934
- key
954
+ key,
955
+ value: bytes.subarray(readOffset, valueEnd)
935
956
  };
936
957
  readOffset = valueEnd;
937
958
  }
938
959
  if (readOffset !== bytes.byteLength) throw workerProtocolError("WorkerProtocolError", "packed batch payload has trailing bytes");
939
960
  return ops;
940
961
  }
941
- function isPackedBinaryList(value) {
942
- return isRecord(value) && value.__moyodbPacked === PACKED_BINARY_LIST_V1 && value.bytes instanceof Uint8Array;
943
- }
944
- function isPackedNullableBinaryList(value) {
945
- return isRecord(value) && value.__moyodbPacked === PACKED_NULLABLE_BINARY_LIST_V1 && value.bytes instanceof Uint8Array;
946
- }
947
- function isPackedScanRows(value) {
948
- return isRecord(value) && value.__moyodbPacked === PACKED_SCAN_ROWS_V1 && value.bytes instanceof Uint8Array;
949
- }
950
- function isPackedBatchOps(value) {
951
- return isRecord(value) && value.__moyodbPacked === PACKED_BATCH_OPS_V1 && value.bytes instanceof Uint8Array;
952
- }
953
- function isPackedOptionalValues(value) {
954
- 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;
955
964
  }
956
965
  function checkedByteCount(count, itemBytes, what) {
957
966
  if (!Number.isSafeInteger(count) || count < 0) throw workerProtocolError("WorkerProtocolError", `${what} count is invalid: ${count}`);
@@ -1165,7 +1174,7 @@ function normalizeError(error) {
1165
1174
  }
1166
1175
  //#endregion
1167
1176
  //#region src/codec.ts
1168
- var encoder$1 = new TextEncoder();
1177
+ var encoder = new TextEncoder();
1169
1178
  var decoder = new TextDecoder();
1170
1179
  var jsonDecoder = new TextDecoder("utf-8", { fatal: true });
1171
1180
  var TYPE_NULL = 16;
@@ -1179,7 +1188,7 @@ var COMPOUND_ESCAPE_CONT = 255;
1179
1188
  var COMPOUND_TERM = 0;
1180
1189
  var F64_MASK = BigInt("0xffffffffffffffff");
1181
1190
  function utf8Encode(value) {
1182
- return encoder$1.encode(value);
1191
+ return encoder.encode(value);
1183
1192
  }
1184
1193
  function utf8Decode(bytes) {
1185
1194
  return decoder.decode(bytes);
@@ -1321,7 +1330,6 @@ function encodeSortableNumber(value) {
1321
1330
  }
1322
1331
  //#endregion
1323
1332
  //#region src/indexing.ts
1324
- var encoder = new TextEncoder();
1325
1333
  var fatalDecoder = new TextDecoder("utf-8", { fatal: true });
1326
1334
  var MISSING = Symbol("moyodb.indexing.missing");
1327
1335
  var FNV64_OFFSET = BigInt("0xcbf29ce484222325");
@@ -1520,7 +1528,7 @@ function serializeIndexKeyPath(def) {
1520
1528
  }
1521
1529
  function makeInternalIndexStoreName(store, name) {
1522
1530
  const candidate = `${INTERNAL_INDEX_STORE_PREFIX}${base64Url(utf8Encode(store))}:${base64Url(utf8Encode(name))}`;
1523
- if (encoder.encode(candidate).length <= 255) return candidate;
1531
+ if (utf8Encode(candidate).length <= 255) return candidate;
1524
1532
  return `${INTERNAL_INDEX_STORE_PREFIX}h:${fnv1a64Hex(utf8Encode(`${store}\u0000${name}`))}`;
1525
1533
  }
1526
1534
  function base64Url(bytes) {
@@ -1546,10 +1554,9 @@ function decodeIndexedDocument(bytes) {
1546
1554
  function resolveKeyPath(root, keyPath) {
1547
1555
  let current = root;
1548
1556
  for (const segment of keyPath.split(".")) {
1549
- if (current === null || current === void 0) return MISSING;
1550
- const target = Object(current);
1551
- if (!Object.hasOwn(target, segment)) return MISSING;
1552
- current = Reflect.get(target, segment);
1557
+ if (current === null || typeof current !== "object") return MISSING;
1558
+ if (!Object.hasOwn(current, segment)) return MISSING;
1559
+ current = Reflect.get(current, segment);
1553
1560
  }
1554
1561
  return current;
1555
1562
  }
@@ -1571,6 +1578,6 @@ function validateIndexRangeShape(range) {
1571
1578
  if (range.lt !== void 0 && range.lte !== void 0) throw new TypeError("index range cannot specify both lt and lte");
1572
1579
  }
1573
1580
  //#endregion
1574
- export { StoreExistsError as $, prefixRange as A, packedBinaryListBytes as At, DatabaseClosedError as B, unpackPackedOptionalValues as Bt, compoundKey as C, isWorkerProtocolReadyEnvelope as Ct, indexKey as D, isWorkerProtocolResponseBatchMessage as Dt, encodeIndexScalar as E, isWorkerProtocolRequestMessage as Et, utf8Encode as F, unpackPackedBatchOpKeys as Ft, InvalidRangeError as G, InjectedFailureError as H, compareStringsByCodeUnit as Ht, ChangeFeedCompactedError as I, unpackPackedBatchOps as It, ReadonlyTransactionError as J, KeyTooLargeError as K, ConstraintError as L, unpackPackedBinaryList as Lt, splitCompoundKey as M, prepareWorkerCommandPayload as Mt, u64Key as N, prepareWorkerResponsePayload as Nt, jsonDecode as O, isWorkerProtocolResponseMessage as Ot, utf8Decode as P, serializeWorkerError as Pt, StorageError as Q, CorruptionError as R, unpackPackedBinaryPairKeys as Rt, toPublicIndexDefinitions as S, isWorkerProtocolEnvelope as St, encodeCompoundKeyParts as T, isWorkerProtocolRequestBatchMessage as Tt, InternalError as U, isRecord as Ut, IndexNotFoundError as V, workerProtocolError as Vt, InvalidOpenOptionsError as W, ReservedStoreNameError as X, RecoveryRequiredError as Y, SerializationError as Z, indexRangeToPhysicalRange as _, decodeWorkerCommandPayload as _t, createIndexKeyExtractor as a, UnsupportedPlatformError as at, normalizeIndexDefinitions as b, isAutocommitCommand as bt, decodeIndexedDocument as c, WriteTransactionAlreadyOpenError as ct, encodeIndexMetadataValue as d, WORKER_PROTOCOL_READY as dt, StoreNameTooLongError as et, extractLogicalIndexKey as f, WORKER_PROTOCOL_REQUEST as ft, indexKeyExactRange as g, captureWorkerPayload as gt, indexDefinitionIdentity as h, WORKER_PROTOCOL_RESPONSE_BATCH as ht, compareNormalizedIndexDefinitions as i, UniqueIndexConstraintError as it, prefixSuccessor as j, packedOptionalValues as jt, jsonEncode as k, packedBatchOpsBytes as kt, encodeIndexEntryKey as l, normalizeError as lt, findIndexDefinition as m, WORKER_PROTOCOL_RESPONSE as mt, assertPublicStoreName as n, TransactionClosedError as nt, decodeIndexEntryKey as o, ValueTooLargeError as ot, extractLogicalIndexKeyFromDocument as p, WORKER_PROTOCOL_REQUEST_BATCH as pt, MoyoDbError as q, cloneNormalizedIndexDefinitions as r, TransactionConflictError as rt, decodeIndexMetadataValue as s, VersionError as st, INDEX_METADATA_STORE as t, StoreNotFoundError as tt, encodeIndexMetadataKey as u, MAX_WORKER_BATCH_BYTES as ut, indexesForStore as v, decodeWorkerResponsePayload as vt, compoundKeyRange as w, isWorkerProtocolReadyMessage as wt, serializeNormalizedIndexDefinitions as x, isWorkerCommand as xt, isInternalStoreName as y, deserializeWorkerError as yt, DatabaseBusyError as z, unpackPackedBinaryPairs as zt };
1581
+ export { StoreExistsError as $, prefixRange as A, packedBinaryListBytes as At, DatabaseClosedError as B, unpackPackedOptionalValues as Bt, compoundKey as C, isWorkerProtocolReadyEnvelope as Ct, indexKey as D, isWorkerProtocolResponseBatchMessage as Dt, encodeIndexScalar as E, isWorkerProtocolRequestMessage as Et, utf8Encode as F, serializeWorkerError as Ft, InvalidRangeError as G, isRecord as Gt, InjectedFailureError as H, workerProtocolError as Ht, ChangeFeedCompactedError as I, unpackPackedBatchOpKeys as It, ReadonlyTransactionError as J, KeyTooLargeError as K, ConstraintError as L, unpackPackedBatchOps as Lt, splitCompoundKey as M, packedScanRows as Mt, u64Key as N, prepareWorkerCommandPayload as Nt, jsonDecode as O, isWorkerProtocolResponseMessage as Ot, utf8Decode as P, prepareWorkerResponsePayload as Pt, StorageError as Q, CorruptionError as R, unpackPackedBinaryList as Rt, toPublicIndexDefinitions as S, isWorkerProtocolEnvelope as St, encodeCompoundKeyParts as T, isWorkerProtocolRequestBatchMessage as Tt, InternalError as U, clampTimerDelayMs as Ut, IndexNotFoundError as V, unpackPackedScanRows as Vt, InvalidOpenOptionsError as W, compareStringsByCodeUnit as Wt, ReservedStoreNameError as X, RecoveryRequiredError as Y, SerializationError as Z, indexRangeToPhysicalRange as _, decodeWorkerCommandPayload as _t, createIndexKeyExtractor as a, UnsupportedPlatformError as at, normalizeIndexDefinitions as b, isAutocommitCommand as bt, decodeIndexedDocument as c, WriteTransactionAlreadyOpenError as ct, encodeIndexMetadataValue as d, WORKER_PROTOCOL_READY as dt, StoreNameTooLongError as et, extractLogicalIndexKey as f, WORKER_PROTOCOL_REQUEST as ft, indexKeyExactRange as g, captureWorkerPayload as gt, indexDefinitionIdentity as h, WORKER_PROTOCOL_RESPONSE_BATCH as ht, compareNormalizedIndexDefinitions as i, UniqueIndexConstraintError as it, prefixSuccessor as j, packedOptionalValues as jt, jsonEncode as k, packedBatchOpsBytes as kt, encodeIndexEntryKey as l, normalizeError as lt, findIndexDefinition as m, WORKER_PROTOCOL_RESPONSE as mt, assertPublicStoreName as n, TransactionClosedError as nt, decodeIndexEntryKey as o, ValueTooLargeError as ot, extractLogicalIndexKeyFromDocument as p, WORKER_PROTOCOL_REQUEST_BATCH as pt, MoyoDbError as q, cloneNormalizedIndexDefinitions as r, TransactionConflictError as rt, decodeIndexMetadataValue as s, VersionError as st, INDEX_METADATA_STORE as t, StoreNotFoundError as tt, encodeIndexMetadataKey as u, MAX_WORKER_BATCH_BYTES as ut, indexesForStore as v, decodeWorkerResponsePayload as vt, compoundKeyRange as w, isWorkerProtocolReadyMessage as wt, serializeNormalizedIndexDefinitions as x, isWorkerCommand as xt, isInternalStoreName as y, deserializeWorkerError as yt, DatabaseBusyError as z, unpackPackedBinaryPairKeys as zt };
1575
1582
 
1576
- //# sourceMappingURL=indexing-BzmFhWXs.js.map
1583
+ //# sourceMappingURL=indexing-B0duqlUs.js.map