@moyodb/sdk 1.4.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/README.md +2 -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-B0duqlUs.js → indexing-DdpU69Fd.js} +302 -69
- package/dist/chunks/{indexing-B0duqlUs.js.map → indexing-DdpU69Fd.js.map} +1 -1
- package/dist/codec.d.ts.map +1 -1
- package/dist/compression.d.ts.map +1 -1
- package/dist/engine/README.md +2 -2
- package/dist/engine/moyodb_engine.d.ts +2 -2
- package/dist/engine/moyodb_engine.js +22 -22
- package/dist/engine/moyodb_engine_bg.wasm +0 -0
- package/dist/engine/moyodb_engine_bg.wasm.d.ts +2 -2
- package/dist/engine/package.json +1 -1
- package/dist/engine/snippets/{moyodb-engine-1d53039816cbc2f7 → 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 +1329 -931
- package/dist/moyodb-sdk.js.map +1 -1
- package/dist/node-engine.js +382 -47
- package/dist/node-engine.js.map +1 -1
- package/dist/node.js +332 -44
- 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-client.d.ts.map +1 -1
- package/dist/worker-server.d.ts.map +1 -1
- package/dist/worker.d.ts +10 -3
- package/dist/worker.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/assets/browser-worker-Bj2ErRvC.js +0 -4
- package/dist/assets/browser-worker-Bj2ErRvC.js.map +0 -1
- package/dist/assets/shared-worker-CMeTcusa.js +0 -2
- package/dist/assets/shared-worker-CMeTcusa.js.map +0 -1
|
@@ -1187,6 +1187,8 @@ var COMPOUND_ESCAPE = 0;
|
|
|
1187
1187
|
var COMPOUND_ESCAPE_CONT = 255;
|
|
1188
1188
|
var COMPOUND_TERM = 0;
|
|
1189
1189
|
var F64_MASK = BigInt("0xffffffffffffffff");
|
|
1190
|
+
var sortableNumberBytes = /* @__PURE__ */ new Uint8Array(9);
|
|
1191
|
+
var sortableNumberView = new DataView(sortableNumberBytes.buffer);
|
|
1190
1192
|
function utf8Encode(value) {
|
|
1191
1193
|
return encoder.encode(value);
|
|
1192
1194
|
}
|
|
@@ -1214,11 +1216,11 @@ function isCompoundKeyPartList(value) {
|
|
|
1214
1216
|
return Array.isArray(value);
|
|
1215
1217
|
}
|
|
1216
1218
|
function indexKey(value) {
|
|
1217
|
-
if (isCompoundKeyPartList(value)) return
|
|
1219
|
+
if (isCompoundKeyPartList(value)) return encodeCompoundKeyList(value);
|
|
1218
1220
|
return encodeCompoundKeyPart(value);
|
|
1219
1221
|
}
|
|
1220
1222
|
function compoundKey(...parts) {
|
|
1221
|
-
return
|
|
1223
|
+
return encodeCompoundKeyList(parts);
|
|
1222
1224
|
}
|
|
1223
1225
|
function encodeIndexScalar(value) {
|
|
1224
1226
|
return encodeCompoundKeyPart(value);
|
|
@@ -1228,37 +1230,55 @@ function encodeCompoundKeyParts(parts) {
|
|
|
1228
1230
|
}
|
|
1229
1231
|
function splitCompoundKey(key) {
|
|
1230
1232
|
const parts = [];
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
const
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
index
|
|
1242
|
-
|
|
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");
|
|
1243
1255
|
}
|
|
1244
|
-
if (
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
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;
|
|
1249
1269
|
}
|
|
1250
|
-
|
|
1270
|
+
parts.push(part);
|
|
1251
1271
|
}
|
|
1252
|
-
if (current.length !== 0) throw new TypeError("compound key terminated unexpectedly");
|
|
1253
1272
|
return parts;
|
|
1254
1273
|
}
|
|
1255
1274
|
function prefixSuccessor(prefix) {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
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;
|
|
1262
1282
|
}
|
|
1263
1283
|
function prefixRange(prefix) {
|
|
1264
1284
|
const upper = prefixSuccessor(prefix);
|
|
@@ -1274,17 +1294,7 @@ function encodeCompoundKeyPart(value) {
|
|
|
1274
1294
|
if (value === null) return Uint8Array.of(TYPE_NULL);
|
|
1275
1295
|
if (typeof value === "boolean") return Uint8Array.of(value ? TYPE_TRUE : TYPE_FALSE);
|
|
1276
1296
|
if (typeof value === "number") return encodeSortableNumber(value);
|
|
1277
|
-
if (typeof value === "string")
|
|
1278
|
-
for (const character of value) {
|
|
1279
|
-
const codePoint = character.codePointAt(0);
|
|
1280
|
-
if (codePoint >= 55296 && codePoint <= 57343) throw new TypeError("compound key string parts must contain valid Unicode scalar values");
|
|
1281
|
-
}
|
|
1282
|
-
const body = utf8Encode(value);
|
|
1283
|
-
const out = new Uint8Array(1 + body.length);
|
|
1284
|
-
out[0] = TYPE_STRING;
|
|
1285
|
-
out.set(body, 1);
|
|
1286
|
-
return out;
|
|
1287
|
-
}
|
|
1297
|
+
if (typeof value === "string") return encodeStringKey(value);
|
|
1288
1298
|
if (value instanceof Uint8Array) {
|
|
1289
1299
|
const out = new Uint8Array(1 + value.length);
|
|
1290
1300
|
out[0] = TYPE_BYTES;
|
|
@@ -1293,16 +1303,64 @@ function encodeCompoundKeyPart(value) {
|
|
|
1293
1303
|
}
|
|
1294
1304
|
throw new TypeError("compound key parts must be string, number, boolean, null, or Uint8Array");
|
|
1295
1305
|
}
|
|
1296
|
-
function
|
|
1306
|
+
function encodeCompoundKeyList(parts) {
|
|
1297
1307
|
let length = 0;
|
|
1298
|
-
for (
|
|
1299
|
-
|
|
1300
|
-
|
|
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;
|
|
1301
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));
|
|
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;
|
|
1302
1350
|
const out = new Uint8Array(length);
|
|
1303
1351
|
let offset = 0;
|
|
1304
|
-
for (
|
|
1305
|
-
|
|
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) {
|
|
1306
1364
|
out[offset] = COMPOUND_ESCAPE;
|
|
1307
1365
|
out[offset + 1] = COMPOUND_ESCAPE_CONT;
|
|
1308
1366
|
offset += 2;
|
|
@@ -1310,23 +1368,83 @@ function encodeCompoundBytes(parts) {
|
|
|
1310
1368
|
out[offset] = byte;
|
|
1311
1369
|
offset += 1;
|
|
1312
1370
|
}
|
|
1313
|
-
out[offset] = COMPOUND_TERM;
|
|
1314
|
-
out[offset + 1] = COMPOUND_TERM;
|
|
1315
|
-
offset += 2;
|
|
1316
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);
|
|
1317
1384
|
return out;
|
|
1318
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
|
+
}
|
|
1319
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) {
|
|
1320
1441
|
if (!Number.isFinite(value)) throw new TypeError("compound key number parts must be finite");
|
|
1321
1442
|
const normalized = Object.is(value, -0) ? 0 : value;
|
|
1322
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(9);
|
|
1323
|
-
const view = new DataView(buffer);
|
|
1324
1443
|
view.setUint8(0, TYPE_NUMBER);
|
|
1325
1444
|
view.setFloat64(1, normalized, false);
|
|
1326
1445
|
let bits = view.getBigUint64(1, false);
|
|
1327
1446
|
bits = (bits & 1n << 63n) !== 0n ? ~bits & F64_MASK : bits ^ 1n << 63n;
|
|
1328
1447
|
view.setBigUint64(1, bits, false);
|
|
1329
|
-
return new Uint8Array(buffer);
|
|
1330
1448
|
}
|
|
1331
1449
|
//#endregion
|
|
1332
1450
|
//#region src/indexing.ts
|
|
@@ -1412,37 +1530,50 @@ function decodeIndexMetadataValue(bytes) {
|
|
|
1412
1530
|
}
|
|
1413
1531
|
}
|
|
1414
1532
|
function encodeIndexEntryKey(logicalIndexKey, primaryKey) {
|
|
1415
|
-
|
|
1533
|
+
const out = new Uint8Array(compoundEncodedLength(logicalIndexKey) + compoundEncodedLength(primaryKey));
|
|
1534
|
+
writeCompoundPart(out, writeCompoundPart(out, 0, logicalIndexKey), primaryKey);
|
|
1535
|
+
return out;
|
|
1416
1536
|
}
|
|
1417
1537
|
function decodeIndexEntryKey(bytes) {
|
|
1418
|
-
let parts;
|
|
1419
1538
|
try {
|
|
1420
|
-
|
|
1539
|
+
return decodeTwoPartIndexKey(bytes);
|
|
1421
1540
|
} catch (error) {
|
|
1541
|
+
if (error instanceof SerializationError) throw error;
|
|
1422
1542
|
throw new SerializationError(`invalid index entry key encoding: ${String(error)}`);
|
|
1423
1543
|
}
|
|
1424
|
-
if (parts.length !== 2) throw new SerializationError("invalid index entry key encoding");
|
|
1425
|
-
return {
|
|
1426
|
-
logicalKey: parts[0],
|
|
1427
|
-
primaryKey: parts[1]
|
|
1428
|
-
};
|
|
1429
1544
|
}
|
|
1430
1545
|
function indexKeyExactRange(logicalIndexKey) {
|
|
1431
|
-
|
|
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");
|
|
1432
1563
|
}
|
|
1433
1564
|
function indexRangeToPhysicalRange(range = {}) {
|
|
1434
|
-
|
|
1565
|
+
assertValidScanRange(range);
|
|
1435
1566
|
const physical = {};
|
|
1436
1567
|
if (range.reverse !== void 0) physical.reverse = range.reverse;
|
|
1437
1568
|
if (range.limit !== void 0) physical.limit = range.limit;
|
|
1438
|
-
if (range.gte) physical.gte =
|
|
1569
|
+
if (range.gte) physical.gte = encodeCompoundPrefix(range.gte);
|
|
1439
1570
|
if (range.gt) {
|
|
1440
|
-
const lower =
|
|
1571
|
+
const lower = advanceEncodedPrefix(encodeCompoundPrefix(range.gt));
|
|
1441
1572
|
if (lower) physical.gte = lower;
|
|
1442
1573
|
}
|
|
1443
|
-
if (range.lt) physical.lt =
|
|
1574
|
+
if (range.lt) physical.lt = encodeCompoundPrefix(range.lt);
|
|
1444
1575
|
if (range.lte) {
|
|
1445
|
-
const upper =
|
|
1576
|
+
const upper = advanceEncodedPrefix(encodeCompoundPrefix(range.lte));
|
|
1446
1577
|
if (upper) physical.lt = upper;
|
|
1447
1578
|
}
|
|
1448
1579
|
return physical;
|
|
@@ -1573,11 +1704,113 @@ function describeValue(value) {
|
|
|
1573
1704
|
if (Array.isArray(value)) return "array";
|
|
1574
1705
|
return typeof value;
|
|
1575
1706
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
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
|
+
}
|
|
1579
1812
|
}
|
|
1580
1813
|
//#endregion
|
|
1581
|
-
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 };
|
|
1582
1815
|
|
|
1583
|
-
//# sourceMappingURL=indexing-
|
|
1816
|
+
//# sourceMappingURL=indexing-DdpU69Fd.js.map
|