@rocicorp/zero 0.23.2025082900 → 0.23.2025082901

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 (69) hide show
  1. package/out/{chunk-A2FIESI3.js → chunk-G442PJSB.js} +463 -469
  2. package/out/chunk-G442PJSB.js.map +7 -0
  3. package/out/{chunk-S6YBPIPL.js → chunk-MRT7XNEQ.js} +4059 -4060
  4. package/out/chunk-MRT7XNEQ.js.map +7 -0
  5. package/out/{chunk-Y44KA7XV.js → chunk-YBQT4PQG.js} +3 -3
  6. package/out/{inspector-GW44RI34.js → inspector-4ALIZXAU.js} +6 -36
  7. package/out/inspector-4ALIZXAU.js.map +7 -0
  8. package/out/react-native.js +21 -19
  9. package/out/react-native.js.map +3 -3
  10. package/out/react.js +2 -2
  11. package/out/replicache/src/expo/store.d.ts +5 -0
  12. package/out/replicache/src/expo/store.d.ts.map +1 -0
  13. package/out/replicache/src/get-kv-store-provider.d.ts +4 -0
  14. package/out/replicache/src/get-kv-store-provider.d.ts.map +1 -0
  15. package/out/replicache/src/http-status-unauthorized.d.ts +2 -0
  16. package/out/replicache/src/http-status-unauthorized.d.ts.map +1 -0
  17. package/out/replicache/src/make-idb-name.d.ts +10 -0
  18. package/out/replicache/src/make-idb-name.d.ts.map +1 -0
  19. package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
  20. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  21. package/out/replicache/src/replicache-options.d.ts +3 -3
  22. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  23. package/out/replicache/src/report-error.d.ts +6 -0
  24. package/out/replicache/src/report-error.d.ts.map +1 -0
  25. package/out/solid.js +3 -3
  26. package/out/zero/package.json +1 -1
  27. package/out/zero-cache/src/server/inspector-delegate.d.ts +0 -9
  28. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  29. package/out/zero-cache/src/server/inspector-delegate.js +0 -18
  30. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  31. package/out/zero-cache/src/server/syncer.js +2 -2
  32. package/out/zero-cache/src/server/syncer.js.map +1 -1
  33. package/out/zero-cache/src/services/mutagen/pusher.d.ts +0 -8
  34. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  35. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +1 -1
  36. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  37. package/out/zero-cache/src/services/view-syncer/view-syncer.js +0 -28
  38. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  39. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  40. package/out/zero-client/src/mod.d.ts +2 -2
  41. package/out/zero-client/src/mod.d.ts.map +1 -1
  42. package/out/zero-protocol/src/down.d.ts +0 -5
  43. package/out/zero-protocol/src/down.d.ts.map +1 -1
  44. package/out/zero-protocol/src/inspect-down.d.ts +0 -17
  45. package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
  46. package/out/zero-protocol/src/inspect-down.js +1 -5
  47. package/out/zero-protocol/src/inspect-down.js.map +1 -1
  48. package/out/zero-protocol/src/inspect-up.d.ts +10 -39
  49. package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
  50. package/out/zero-protocol/src/inspect-up.js +3 -10
  51. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  52. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  53. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  54. package/out/zero-protocol/src/protocol-version.js +1 -2
  55. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  56. package/out/zero-protocol/src/up.d.ts +1 -10
  57. package/out/zero-protocol/src/up.d.ts.map +1 -1
  58. package/out/zero-react-native/src/mod.d.ts +2 -1
  59. package/out/zero-react-native/src/mod.d.ts.map +1 -1
  60. package/out/zero.js +3 -3
  61. package/package.json +1 -1
  62. package/out/chunk-A2FIESI3.js.map +0 -7
  63. package/out/chunk-S6YBPIPL.js.map +0 -7
  64. package/out/inspector-GW44RI34.js.map +0 -7
  65. package/out/replicache/src/replicache.d.ts +0 -298
  66. package/out/replicache/src/replicache.d.ts.map +0 -1
  67. package/out/zero-react-native/src/store.d.ts +0 -4
  68. package/out/zero-react-native/src/store.d.ts.map +0 -1
  69. /package/out/{chunk-Y44KA7XV.js.map → chunk-YBQT4PQG.js.map} +0 -0
@@ -17,6 +17,12 @@ import {
17
17
  __reExport
18
18
  } from "./chunk-424PT5DM.js";
19
19
 
20
+ // ../replicache/src/format-version-enum.ts
21
+ var DD31 = 5;
22
+ var V6 = 6;
23
+ var V7 = 7;
24
+ var Latest = V7;
25
+
20
26
  // ../shared/src/valita.ts
21
27
  var valita_exports = {};
22
28
  __export(valita_exports, {
@@ -252,11 +258,307 @@ async function mustGetHeadHash(name, store) {
252
258
  return hash2;
253
259
  }
254
260
 
255
- // ../replicache/src/format-version-enum.ts
256
- var DD31 = 5;
257
- var V6 = 6;
258
- var V7 = 7;
259
- var Latest = V7;
261
+ // ../replicache/src/with-transactions.ts
262
+ function withRead(store, fn) {
263
+ return using(store.read(), fn);
264
+ }
265
+ function withWriteNoImplicitCommit(store, fn) {
266
+ return using(store.write(), fn);
267
+ }
268
+ function withWrite(store, fn) {
269
+ return using(store.write(), async (write) => {
270
+ const result = await fn(write);
271
+ await write.commit();
272
+ return result;
273
+ });
274
+ }
275
+ async function using(x, fn) {
276
+ const write = await x;
277
+ try {
278
+ return await fn(write);
279
+ } finally {
280
+ write.release();
281
+ }
282
+ }
283
+
284
+ // ../replicache/src/dag/chunk.ts
285
+ function asRefs(sortedRefs) {
286
+ return sortedRefs;
287
+ }
288
+ function toRefs(refs) {
289
+ if (Array.isArray(refs)) {
290
+ refs.sort();
291
+ for (let i = 1; i < refs.length; i++) {
292
+ assert(refs[i - 1] !== refs[i], "Refs must not have duplicates");
293
+ }
294
+ return asRefs(refs);
295
+ }
296
+ const refsArray = [...refs];
297
+ refsArray.sort();
298
+ return asRefs(refsArray);
299
+ }
300
+ var Chunk = class {
301
+ hash;
302
+ data;
303
+ /**
304
+ * Meta is an array of refs. If there are no refs we do not write a meta
305
+ * chunk.
306
+ */
307
+ meta;
308
+ constructor(hash2, data, refs) {
309
+ assert(
310
+ !refs.includes(hash2),
311
+ "Chunk cannot reference itself"
312
+ );
313
+ assertDeepFrozen(data);
314
+ this.hash = hash2;
315
+ this.data = data;
316
+ this.meta = refs;
317
+ }
318
+ };
319
+ function assertRefs(v2) {
320
+ if (!Array.isArray(v2)) {
321
+ throw new Error("Refs must be an array");
322
+ }
323
+ if (v2.length > 0) {
324
+ assertString(v2[0]);
325
+ for (let i = 1; i < v2.length; i++) {
326
+ assertString(v2[i]);
327
+ }
328
+ }
329
+ }
330
+ function createChunk(data, refs, chunkHasher) {
331
+ const hash2 = chunkHasher();
332
+ return new Chunk(hash2, data, refs);
333
+ }
334
+
335
+ // ../shared/src/random-uint64.ts
336
+ function randomUint64() {
337
+ const high = Math.floor(Math.random() * 4294967295);
338
+ const low = Math.floor(Math.random() * 4294967295);
339
+ return BigInt(high) << 32n | BigInt(low);
340
+ }
341
+
342
+ // ../replicache/src/hash.ts
343
+ var STRING_LENGTH = 22;
344
+ var hashRe = /^[0-9a-v-]+$/;
345
+ var emptyUUID = "0".repeat(STRING_LENGTH);
346
+ var emptyHash = emptyUUID;
347
+ var newRandomHash = makeNewRandomHashFunctionInternal();
348
+ function toStringAndSlice(n, len) {
349
+ return n.toString(32).slice(-len).padStart(len, "0");
350
+ }
351
+ function makeNewRandomHashFunctionInternal() {
352
+ let base = "";
353
+ let i = 0;
354
+ return () => {
355
+ if (!base) {
356
+ base = toStringAndSlice(randomUint64(), 12);
357
+ }
358
+ const tail = toStringAndSlice(i++, 10);
359
+ return base + tail;
360
+ };
361
+ }
362
+ function isHash(value) {
363
+ return typeof value === "string" && hashRe.test(value);
364
+ }
365
+ function assertHash(value) {
366
+ assert2(value, hashSchema);
367
+ }
368
+ var hashSchema = valita_exports.string().assert(isHash, "Invalid hash");
369
+
370
+ // ../replicache/src/index-defs.ts
371
+ var indexDefinitionSchema = readonlyObject({
372
+ prefix: valita_exports.string().optional(),
373
+ jsonPointer: valita_exports.string(),
374
+ allowEmpty: valita_exports.boolean().optional()
375
+ });
376
+ var indexDefinitionsSchema = readonlyRecord(
377
+ indexDefinitionSchema
378
+ );
379
+ function indexDefinitionEqual(a, b) {
380
+ return a.jsonPointer === b.jsonPointer && (a.allowEmpty ?? false) === (b.allowEmpty ?? false) && (a.prefix ?? "") === (b.prefix ?? "");
381
+ }
382
+ function indexDefinitionsEqual(a, b) {
383
+ if (Object.keys(a).length !== Object.keys(b).length) {
384
+ return false;
385
+ }
386
+ for (const [aKey, aValue] of Object.entries(a)) {
387
+ const bValue = b[aKey];
388
+ if (!bValue || !indexDefinitionEqual(aValue, bValue)) {
389
+ return false;
390
+ }
391
+ }
392
+ return true;
393
+ }
394
+
395
+ // ../replicache/src/persist/client-groups.ts
396
+ var clientGroupSchema = readonlyObject({
397
+ /**
398
+ * The hash of the commit in the perdag last persisted to this client group.
399
+ * Should only be updated by clients assigned to this client group.
400
+ */
401
+ headHash: hashSchema,
402
+ /**
403
+ * Set of mutator names common to all clients assigned to this client group.
404
+ */
405
+ mutatorNames: readonlyArray(valita_exports.string()),
406
+ /**
407
+ * Index definitions common to all clients assigned to this client group.
408
+ */
409
+ indexes: indexDefinitionsSchema,
410
+ /**
411
+ * The highest mutation ID of every client assigned to this client group.
412
+ * Should only be updated by clients assigned to this client group. Read by
413
+ * other clients to determine if there are unacknowledged pending mutations
414
+ * for them to try to recover. This is redundant with information in the
415
+ * commit graph at `headHash`, but allows other clients to determine if there
416
+ * are unacknowledged pending mutations without having to load the commit
417
+ * graph.
418
+ */
419
+ mutationIDs: readonlyRecord(valita_exports.number()),
420
+ /**
421
+ * The highest lastMutationID received from the server for every client
422
+ * assigned to this client group.
423
+ *
424
+ * Should be updated by the clients assigned to this client group whenever
425
+ * they persist to this client group. Read by other clients to determine if
426
+ * there are unacknowledged pending mutations for them to recover and
427
+ * *updated* by other clients upon successfully recovering pending mutations
428
+ * to avoid redundant pushes of pending mutations.
429
+ *
430
+ * Note: This will be the same as the `lastMutationIDs` of the base snapshot
431
+ * of the client group's commit graph when written by clients assigned to this
432
+ * client group. However, when written by another client recovering mutations
433
+ * it may be different because the other client does not update the commit
434
+ * graph.
435
+ */
436
+ lastServerAckdMutationIDs: valita_exports.record(valita_exports.number()),
437
+ /**
438
+ * If the server deletes this client group it can signal that the client group
439
+ * was deleted. If that happens we mark this client group as disabled so that
440
+ * we do not use it again when creating new clients.
441
+ */
442
+ disabled: valita_exports.boolean()
443
+ });
444
+ var CLIENT_GROUPS_HEAD_NAME = "client-groups";
445
+ function assertClientGroup(value) {
446
+ assert2(value, clientGroupSchema);
447
+ }
448
+ function chunkDataToClientGroupMap(chunkData) {
449
+ assertObject(chunkData);
450
+ const clientGroups = /* @__PURE__ */ new Map();
451
+ for (const [key, value] of Object.entries(chunkData)) {
452
+ if (value !== void 0) {
453
+ assertClientGroup(value);
454
+ clientGroups.set(key, value);
455
+ }
456
+ }
457
+ return clientGroups;
458
+ }
459
+ function clientGroupMapToChunkData(clientGroups, dagWrite) {
460
+ const chunkData = {};
461
+ for (const [clientGroupID, clientGroup] of clientGroups.entries()) {
462
+ dagWrite.assertValidHash(clientGroup.headHash);
463
+ chunkData[clientGroupID] = {
464
+ ...clientGroup,
465
+ mutatorNames: [...clientGroup.mutatorNames.values()]
466
+ };
467
+ }
468
+ return deepFreeze(chunkData);
469
+ }
470
+ async function getClientGroupsAtHash(hash2, dagRead) {
471
+ const chunk = await dagRead.getChunk(hash2);
472
+ return chunkDataToClientGroupMap(chunk?.data);
473
+ }
474
+ async function getClientGroups(dagRead) {
475
+ const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
476
+ if (!hash2) {
477
+ return /* @__PURE__ */ new Map();
478
+ }
479
+ return getClientGroupsAtHash(hash2, dagRead);
480
+ }
481
+ async function setClientGroups(clientGroups, dagWrite) {
482
+ const currClientGroups = await getClientGroups(dagWrite);
483
+ for (const [clientGroupID, clientGroup] of clientGroups) {
484
+ const currClientGroup = currClientGroups.get(clientGroupID);
485
+ validateClientGroupUpdate(clientGroup, currClientGroup);
486
+ }
487
+ return setValidatedClientGroups(clientGroups, dagWrite);
488
+ }
489
+ async function setClientGroup(clientGroupID, clientGroup, dagWrite) {
490
+ const currClientGroups = await getClientGroups(dagWrite);
491
+ const currClientGroup = currClientGroups.get(clientGroupID);
492
+ validateClientGroupUpdate(clientGroup, currClientGroup);
493
+ const newClientGroups = new Map(currClientGroups);
494
+ newClientGroups.set(clientGroupID, clientGroup);
495
+ return setValidatedClientGroups(newClientGroups, dagWrite);
496
+ }
497
+ function validateClientGroupUpdate(clientGroup, currClientGroup) {
498
+ const mutatorNamesSet = new Set(clientGroup.mutatorNames);
499
+ assert(
500
+ mutatorNamesSet.size === clientGroup.mutatorNames.length,
501
+ "A client group's mutatorNames must be a set."
502
+ );
503
+ if (currClientGroup !== void 0) {
504
+ assert(
505
+ indexDefinitionsEqual(currClientGroup.indexes, clientGroup.indexes),
506
+ "A client group's index definitions must never change."
507
+ );
508
+ assert(
509
+ mutatorNamesEqual(mutatorNamesSet, currClientGroup.mutatorNames),
510
+ "A client group's mutatorNames must never change."
511
+ );
512
+ }
513
+ }
514
+ async function setValidatedClientGroups(clientGroups, dagWrite) {
515
+ const chunkData = clientGroupMapToChunkData(clientGroups, dagWrite);
516
+ const refs = /* @__PURE__ */ new Set();
517
+ for (const clientGroup of clientGroups.values()) {
518
+ refs.add(clientGroup.headHash);
519
+ }
520
+ const chunk = dagWrite.createChunk(chunkData, toRefs(refs));
521
+ await dagWrite.putChunk(chunk);
522
+ await dagWrite.setHead(CLIENT_GROUPS_HEAD_NAME, chunk.hash);
523
+ return clientGroups;
524
+ }
525
+ function mutatorNamesEqual(mutatorNamesSet, mutatorNames) {
526
+ if (mutatorNames.length !== mutatorNamesSet.size) {
527
+ return false;
528
+ }
529
+ for (const mutatorName of mutatorNames) {
530
+ if (!mutatorNamesSet.has(mutatorName)) {
531
+ return false;
532
+ }
533
+ }
534
+ return true;
535
+ }
536
+ async function getClientGroup(id, dagRead) {
537
+ const clientGroups = await getClientGroups(dagRead);
538
+ return clientGroups.get(id);
539
+ }
540
+ function clientGroupHasPendingMutations(clientGroup) {
541
+ for (const [clientID, mutationID] of Object.entries(
542
+ clientGroup.mutationIDs
543
+ )) {
544
+ const lastServerAckdMutationID = clientGroup.lastServerAckdMutationIDs[clientID];
545
+ if (lastServerAckdMutationID === void 0 && mutationID !== 0 || lastServerAckdMutationID < mutationID) {
546
+ return true;
547
+ }
548
+ }
549
+ return false;
550
+ }
551
+ async function disableClientGroup(clientGroupID, dagWrite) {
552
+ const clientGroup = await getClientGroup(clientGroupID, dagWrite);
553
+ if (!clientGroup) {
554
+ return;
555
+ }
556
+ const disabledClientGroup = {
557
+ ...clientGroup,
558
+ disabled: true
559
+ };
560
+ await setClientGroup(clientGroupID, disabledClientGroup, dagWrite);
561
+ }
260
562
 
261
563
  // ../shared/src/json.ts
262
564
  function deepEqual(a, b) {
@@ -398,41 +700,6 @@ function isJSONArray(v2, path2) {
398
700
  return true;
399
701
  }
400
702
 
401
- // ../shared/src/random-uint64.ts
402
- function randomUint64() {
403
- const high = Math.floor(Math.random() * 4294967295);
404
- const low = Math.floor(Math.random() * 4294967295);
405
- return BigInt(high) << 32n | BigInt(low);
406
- }
407
-
408
- // ../replicache/src/hash.ts
409
- var STRING_LENGTH = 22;
410
- var hashRe = /^[0-9a-v-]+$/;
411
- var emptyUUID = "0".repeat(STRING_LENGTH);
412
- var emptyHash = emptyUUID;
413
- var newRandomHash = makeNewRandomHashFunctionInternal();
414
- function toStringAndSlice(n, len) {
415
- return n.toString(32).slice(-len).padStart(len, "0");
416
- }
417
- function makeNewRandomHashFunctionInternal() {
418
- let base = "";
419
- let i = 0;
420
- return () => {
421
- if (!base) {
422
- base = toStringAndSlice(randomUint64(), 12);
423
- }
424
- const tail = toStringAndSlice(i++, 10);
425
- return base + tail;
426
- };
427
- }
428
- function isHash(value) {
429
- return typeof value === "string" && hashRe.test(value);
430
- }
431
- function assertHash(value) {
432
- assert2(value, hashSchema);
433
- }
434
- var hashSchema = valita_exports.string().assert(isHash, "Invalid hash");
435
-
436
703
  // ../replicache/src/size-of-value.ts
437
704
  var SIZE_TAG = 1;
438
705
  var SIZE_INT32 = 4;
@@ -1287,76 +1554,25 @@ function compareCookies(a, b) {
1287
1554
  const cva = getCompareValue(a);
1288
1555
  const cvb = getCompareValue(b);
1289
1556
  if (typeof cva === "string" || typeof cvb === "string") {
1290
- return stringCompare(String(cva), String(cvb));
1291
- }
1292
- return cva - cvb;
1293
- }
1294
- function getCompareValue(cookie) {
1295
- if (typeof cookie === "string" || typeof cookie === "number") {
1296
- return cookie;
1297
- }
1298
- return cookie.order;
1299
- }
1300
- function assertCookie(v2) {
1301
- if (v2 === null || typeof v2 === "string" || typeof v2 === "number") {
1302
- return;
1303
- }
1304
- assertJSONObject(v2);
1305
- if (typeof v2.order === "string" || typeof v2.order === "number") {
1306
- return;
1307
- }
1308
- throw new Error("Invalid cookie");
1309
- }
1310
-
1311
- // ../replicache/src/dag/chunk.ts
1312
- function asRefs(sortedRefs) {
1313
- return sortedRefs;
1314
- }
1315
- function toRefs(refs) {
1316
- if (Array.isArray(refs)) {
1317
- refs.sort();
1318
- for (let i = 1; i < refs.length; i++) {
1319
- assert(refs[i - 1] !== refs[i], "Refs must not have duplicates");
1320
- }
1321
- return asRefs(refs);
1322
- }
1323
- const refsArray = [...refs];
1324
- refsArray.sort();
1325
- return asRefs(refsArray);
1326
- }
1327
- var Chunk = class {
1328
- hash;
1329
- data;
1330
- /**
1331
- * Meta is an array of refs. If there are no refs we do not write a meta
1332
- * chunk.
1333
- */
1334
- meta;
1335
- constructor(hash2, data, refs) {
1336
- assert(
1337
- !refs.includes(hash2),
1338
- "Chunk cannot reference itself"
1339
- );
1340
- assertDeepFrozen(data);
1341
- this.hash = hash2;
1342
- this.data = data;
1343
- this.meta = refs;
1344
- }
1345
- };
1346
- function assertRefs(v2) {
1347
- if (!Array.isArray(v2)) {
1348
- throw new Error("Refs must be an array");
1349
- }
1350
- if (v2.length > 0) {
1351
- assertString(v2[0]);
1352
- for (let i = 1; i < v2.length; i++) {
1353
- assertString(v2[i]);
1354
- }
1557
+ return stringCompare(String(cva), String(cvb));
1355
1558
  }
1559
+ return cva - cvb;
1356
1560
  }
1357
- function createChunk(data, refs, chunkHasher) {
1358
- const hash2 = chunkHasher();
1359
- return new Chunk(hash2, data, refs);
1561
+ function getCompareValue(cookie) {
1562
+ if (typeof cookie === "string" || typeof cookie === "number") {
1563
+ return cookie;
1564
+ }
1565
+ return cookie.order;
1566
+ }
1567
+ function assertCookie(v2) {
1568
+ if (v2 === null || typeof v2 === "string" || typeof v2 === "number") {
1569
+ return;
1570
+ }
1571
+ assertJSONObject(v2);
1572
+ if (typeof v2.order === "string" || typeof v2.order === "number") {
1573
+ return;
1574
+ }
1575
+ throw new Error("Invalid cookie");
1360
1576
  }
1361
1577
 
1362
1578
  // ../replicache/src/db/meta-type-enum.ts
@@ -1730,359 +1946,143 @@ function getIndexKeys(primary, value, jsonPointer, allowEmpty) {
1730
1946
  const values = Array.isArray(target) ? target : [target];
1731
1947
  const indexKeys = [];
1732
1948
  for (const value2 of values) {
1733
- if (typeof value2 === "string") {
1734
- indexKeys.push(encodeIndexKey([value2, primary]));
1735
- } else {
1736
- throw new Error("Unsupported target type");
1737
- }
1738
- }
1739
- return indexKeys;
1740
- }
1741
- var KEY_VERSION_0 = "\0";
1742
- var KEY_SEPARATOR = "\0";
1743
- function encodeIndexKey(indexKey) {
1744
- const secondary = indexKey[0];
1745
- const primary = indexKey[1];
1746
- if (secondary.includes("\0")) {
1747
- throw new Error("Secondary key cannot contain null byte");
1748
- }
1749
- return KEY_VERSION_0 + secondary + KEY_SEPARATOR + primary;
1750
- }
1751
- function encodeIndexScanKey(secondary, primary) {
1752
- const k = encodeIndexKey([secondary, primary || ""]);
1753
- if (primary === void 0) {
1754
- return k.slice(0, k.length - 1);
1755
- }
1756
- return k;
1757
- }
1758
- function decodeIndexKey(encodedIndexKey) {
1759
- if (encodedIndexKey[0] !== KEY_VERSION_0) {
1760
- throw new Error("Invalid version");
1761
- }
1762
- const versionLen = KEY_VERSION_0.length;
1763
- const separatorLen = KEY_SEPARATOR.length;
1764
- const separatorOffset = encodedIndexKey.indexOf(KEY_SEPARATOR, versionLen);
1765
- if (separatorOffset === -1) {
1766
- throw new Error("Invalid formatting");
1767
- }
1768
- const secondary = encodedIndexKey.slice(versionLen, separatorOffset);
1769
- const primary = encodedIndexKey.slice(separatorOffset + separatorLen);
1770
- return [secondary, primary];
1771
- }
1772
- function evaluateJSONPointer(value, pointer) {
1773
- function parseIndex(s) {
1774
- if (s.startsWith("+") || s.startsWith("0") && s.length !== 1) {
1775
- return void 0;
1776
- }
1777
- return parseInt(s, 10);
1778
- }
1779
- if (pointer === "") {
1780
- return value;
1781
- }
1782
- if (!pointer.startsWith("/")) {
1783
- throw new Error(`Invalid JSON pointer: ${pointer}`);
1784
- }
1785
- const tokens = pointer.split("/").slice(1).map((x) => x.replace(/~1/g, "/").replace(/~0/g, "~"));
1786
- let target = value;
1787
- for (const token of tokens) {
1788
- let targetOpt;
1789
- if (Array.isArray(target)) {
1790
- const i = parseIndex(token);
1791
- if (i === void 0) {
1792
- return void 0;
1793
- }
1794
- targetOpt = target[i];
1795
- } else if (target === null) {
1796
- return void 0;
1797
- } else if (typeof target === "object") {
1798
- target = target;
1799
- targetOpt = target[token];
1800
- }
1801
- if (targetOpt === void 0) {
1802
- return void 0;
1803
- }
1804
- target = targetOpt;
1805
- }
1806
- return target;
1807
- }
1808
-
1809
- // ../replicache/src/db/read.ts
1810
- var Read = class {
1811
- #dagRead;
1812
- map;
1813
- indexes;
1814
- constructor(dagRead, map, indexes) {
1815
- this.#dagRead = dagRead;
1816
- this.map = map;
1817
- this.indexes = indexes;
1818
- }
1819
- has(key) {
1820
- return this.map.has(key);
1821
- }
1822
- get(key) {
1823
- return this.map.get(key);
1824
- }
1825
- isEmpty() {
1826
- return this.map.isEmpty();
1827
- }
1828
- getMapForIndex(indexName) {
1829
- const idx = this.indexes.get(indexName);
1830
- if (idx === void 0) {
1831
- throw new Error(`Unknown index name: ${indexName}`);
1832
- }
1833
- return idx.map;
1834
- }
1835
- get closed() {
1836
- return this.#dagRead.closed;
1837
- }
1838
- close() {
1839
- this.#dagRead.release();
1840
- }
1841
- };
1842
- function readFromDefaultHead(dagRead, formatVersion) {
1843
- return readFromHead(DEFAULT_HEAD_NAME, dagRead, formatVersion);
1844
- }
1845
- async function readFromHead(name, dagRead, formatVersion) {
1846
- const commit = await commitFromHead(name, dagRead);
1847
- return readFromCommit(commit, dagRead, formatVersion);
1848
- }
1849
- async function readFromHash(hash2, dagRead, formatVersion) {
1850
- const commit = await commitFromHash(hash2, dagRead);
1851
- return readFromCommit(commit, dagRead, formatVersion);
1852
- }
1853
- function readFromCommit(commit, dagRead, formatVersion) {
1854
- const indexes = readIndexesForRead(commit, dagRead, formatVersion);
1855
- const map = new BTreeRead(dagRead, formatVersion, commit.valueHash);
1856
- return new Read(dagRead, map, indexes);
1857
- }
1858
- function readIndexesForRead(commit, dagRead, formatVersion) {
1859
- const m = /* @__PURE__ */ new Map();
1860
- for (const index of commit.indexes) {
1861
- m.set(
1862
- index.definition.name,
1863
- new IndexRead(
1864
- index,
1865
- new BTreeRead(dagRead, formatVersion, index.valueHash)
1866
- )
1867
- );
1868
- }
1869
- return m;
1870
- }
1871
-
1872
- // ../replicache/src/index-defs.ts
1873
- var indexDefinitionSchema = readonlyObject({
1874
- prefix: valita_exports.string().optional(),
1875
- jsonPointer: valita_exports.string(),
1876
- allowEmpty: valita_exports.boolean().optional()
1877
- });
1878
- var indexDefinitionsSchema = readonlyRecord(
1879
- indexDefinitionSchema
1880
- );
1881
- function indexDefinitionEqual(a, b) {
1882
- return a.jsonPointer === b.jsonPointer && (a.allowEmpty ?? false) === (b.allowEmpty ?? false) && (a.prefix ?? "") === (b.prefix ?? "");
1883
- }
1884
- function indexDefinitionsEqual(a, b) {
1885
- if (Object.keys(a).length !== Object.keys(b).length) {
1886
- return false;
1887
- }
1888
- for (const [aKey, aValue] of Object.entries(a)) {
1889
- const bValue = b[aKey];
1890
- if (!bValue || !indexDefinitionEqual(aValue, bValue)) {
1891
- return false;
1892
- }
1893
- }
1894
- return true;
1895
- }
1896
-
1897
- // ../replicache/src/persist/client-groups.ts
1898
- var clientGroupSchema = readonlyObject({
1899
- /**
1900
- * The hash of the commit in the perdag last persisted to this client group.
1901
- * Should only be updated by clients assigned to this client group.
1902
- */
1903
- headHash: hashSchema,
1904
- /**
1905
- * Set of mutator names common to all clients assigned to this client group.
1906
- */
1907
- mutatorNames: readonlyArray(valita_exports.string()),
1908
- /**
1909
- * Index definitions common to all clients assigned to this client group.
1910
- */
1911
- indexes: indexDefinitionsSchema,
1912
- /**
1913
- * The highest mutation ID of every client assigned to this client group.
1914
- * Should only be updated by clients assigned to this client group. Read by
1915
- * other clients to determine if there are unacknowledged pending mutations
1916
- * for them to try to recover. This is redundant with information in the
1917
- * commit graph at `headHash`, but allows other clients to determine if there
1918
- * are unacknowledged pending mutations without having to load the commit
1919
- * graph.
1920
- */
1921
- mutationIDs: readonlyRecord(valita_exports.number()),
1922
- /**
1923
- * The highest lastMutationID received from the server for every client
1924
- * assigned to this client group.
1925
- *
1926
- * Should be updated by the clients assigned to this client group whenever
1927
- * they persist to this client group. Read by other clients to determine if
1928
- * there are unacknowledged pending mutations for them to recover and
1929
- * *updated* by other clients upon successfully recovering pending mutations
1930
- * to avoid redundant pushes of pending mutations.
1931
- *
1932
- * Note: This will be the same as the `lastMutationIDs` of the base snapshot
1933
- * of the client group's commit graph when written by clients assigned to this
1934
- * client group. However, when written by another client recovering mutations
1935
- * it may be different because the other client does not update the commit
1936
- * graph.
1937
- */
1938
- lastServerAckdMutationIDs: valita_exports.record(valita_exports.number()),
1939
- /**
1940
- * If the server deletes this client group it can signal that the client group
1941
- * was deleted. If that happens we mark this client group as disabled so that
1942
- * we do not use it again when creating new clients.
1943
- */
1944
- disabled: valita_exports.boolean()
1945
- });
1946
- var CLIENT_GROUPS_HEAD_NAME = "client-groups";
1947
- function assertClientGroup(value) {
1948
- assert2(value, clientGroupSchema);
1949
- }
1950
- function chunkDataToClientGroupMap(chunkData) {
1951
- assertObject(chunkData);
1952
- const clientGroups = /* @__PURE__ */ new Map();
1953
- for (const [key, value] of Object.entries(chunkData)) {
1954
- if (value !== void 0) {
1955
- assertClientGroup(value);
1956
- clientGroups.set(key, value);
1957
- }
1958
- }
1959
- return clientGroups;
1960
- }
1961
- function clientGroupMapToChunkData(clientGroups, dagWrite) {
1962
- const chunkData = {};
1963
- for (const [clientGroupID, clientGroup] of clientGroups.entries()) {
1964
- dagWrite.assertValidHash(clientGroup.headHash);
1965
- chunkData[clientGroupID] = {
1966
- ...clientGroup,
1967
- mutatorNames: [...clientGroup.mutatorNames.values()]
1968
- };
1949
+ if (typeof value2 === "string") {
1950
+ indexKeys.push(encodeIndexKey([value2, primary]));
1951
+ } else {
1952
+ throw new Error("Unsupported target type");
1953
+ }
1969
1954
  }
1970
- return deepFreeze(chunkData);
1971
- }
1972
- async function getClientGroupsAtHash(hash2, dagRead) {
1973
- const chunk = await dagRead.getChunk(hash2);
1974
- return chunkDataToClientGroupMap(chunk?.data);
1955
+ return indexKeys;
1975
1956
  }
1976
- async function getClientGroups(dagRead) {
1977
- const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
1978
- if (!hash2) {
1979
- return /* @__PURE__ */ new Map();
1957
+ var KEY_VERSION_0 = "\0";
1958
+ var KEY_SEPARATOR = "\0";
1959
+ function encodeIndexKey(indexKey) {
1960
+ const secondary = indexKey[0];
1961
+ const primary = indexKey[1];
1962
+ if (secondary.includes("\0")) {
1963
+ throw new Error("Secondary key cannot contain null byte");
1980
1964
  }
1981
- return getClientGroupsAtHash(hash2, dagRead);
1965
+ return KEY_VERSION_0 + secondary + KEY_SEPARATOR + primary;
1982
1966
  }
1983
- async function setClientGroups(clientGroups, dagWrite) {
1984
- const currClientGroups = await getClientGroups(dagWrite);
1985
- for (const [clientGroupID, clientGroup] of clientGroups) {
1986
- const currClientGroup = currClientGroups.get(clientGroupID);
1987
- validateClientGroupUpdate(clientGroup, currClientGroup);
1967
+ function encodeIndexScanKey(secondary, primary) {
1968
+ const k = encodeIndexKey([secondary, primary || ""]);
1969
+ if (primary === void 0) {
1970
+ return k.slice(0, k.length - 1);
1988
1971
  }
1989
- return setValidatedClientGroups(clientGroups, dagWrite);
1990
- }
1991
- async function setClientGroup(clientGroupID, clientGroup, dagWrite) {
1992
- const currClientGroups = await getClientGroups(dagWrite);
1993
- const currClientGroup = currClientGroups.get(clientGroupID);
1994
- validateClientGroupUpdate(clientGroup, currClientGroup);
1995
- const newClientGroups = new Map(currClientGroups);
1996
- newClientGroups.set(clientGroupID, clientGroup);
1997
- return setValidatedClientGroups(newClientGroups, dagWrite);
1972
+ return k;
1998
1973
  }
1999
- function validateClientGroupUpdate(clientGroup, currClientGroup) {
2000
- const mutatorNamesSet = new Set(clientGroup.mutatorNames);
2001
- assert(
2002
- mutatorNamesSet.size === clientGroup.mutatorNames.length,
2003
- "A client group's mutatorNames must be a set."
2004
- );
2005
- if (currClientGroup !== void 0) {
2006
- assert(
2007
- indexDefinitionsEqual(currClientGroup.indexes, clientGroup.indexes),
2008
- "A client group's index definitions must never change."
2009
- );
2010
- assert(
2011
- mutatorNamesEqual(mutatorNamesSet, currClientGroup.mutatorNames),
2012
- "A client group's mutatorNames must never change."
2013
- );
1974
+ function decodeIndexKey(encodedIndexKey) {
1975
+ if (encodedIndexKey[0] !== KEY_VERSION_0) {
1976
+ throw new Error("Invalid version");
2014
1977
  }
2015
- }
2016
- async function setValidatedClientGroups(clientGroups, dagWrite) {
2017
- const chunkData = clientGroupMapToChunkData(clientGroups, dagWrite);
2018
- const refs = /* @__PURE__ */ new Set();
2019
- for (const clientGroup of clientGroups.values()) {
2020
- refs.add(clientGroup.headHash);
1978
+ const versionLen = KEY_VERSION_0.length;
1979
+ const separatorLen = KEY_SEPARATOR.length;
1980
+ const separatorOffset = encodedIndexKey.indexOf(KEY_SEPARATOR, versionLen);
1981
+ if (separatorOffset === -1) {
1982
+ throw new Error("Invalid formatting");
2021
1983
  }
2022
- const chunk = dagWrite.createChunk(chunkData, toRefs(refs));
2023
- await dagWrite.putChunk(chunk);
2024
- await dagWrite.setHead(CLIENT_GROUPS_HEAD_NAME, chunk.hash);
2025
- return clientGroups;
1984
+ const secondary = encodedIndexKey.slice(versionLen, separatorOffset);
1985
+ const primary = encodedIndexKey.slice(separatorOffset + separatorLen);
1986
+ return [secondary, primary];
2026
1987
  }
2027
- function mutatorNamesEqual(mutatorNamesSet, mutatorNames) {
2028
- if (mutatorNames.length !== mutatorNamesSet.size) {
2029
- return false;
1988
+ function evaluateJSONPointer(value, pointer) {
1989
+ function parseIndex(s) {
1990
+ if (s.startsWith("+") || s.startsWith("0") && s.length !== 1) {
1991
+ return void 0;
1992
+ }
1993
+ return parseInt(s, 10);
2030
1994
  }
2031
- for (const mutatorName of mutatorNames) {
2032
- if (!mutatorNamesSet.has(mutatorName)) {
2033
- return false;
1995
+ if (pointer === "") {
1996
+ return value;
1997
+ }
1998
+ if (!pointer.startsWith("/")) {
1999
+ throw new Error(`Invalid JSON pointer: ${pointer}`);
2000
+ }
2001
+ const tokens = pointer.split("/").slice(1).map((x) => x.replace(/~1/g, "/").replace(/~0/g, "~"));
2002
+ let target = value;
2003
+ for (const token of tokens) {
2004
+ let targetOpt;
2005
+ if (Array.isArray(target)) {
2006
+ const i = parseIndex(token);
2007
+ if (i === void 0) {
2008
+ return void 0;
2009
+ }
2010
+ targetOpt = target[i];
2011
+ } else if (target === null) {
2012
+ return void 0;
2013
+ } else if (typeof target === "object") {
2014
+ target = target;
2015
+ targetOpt = target[token];
2034
2016
  }
2017
+ if (targetOpt === void 0) {
2018
+ return void 0;
2019
+ }
2020
+ target = targetOpt;
2035
2021
  }
2036
- return true;
2037
- }
2038
- async function getClientGroup(id, dagRead) {
2039
- const clientGroups = await getClientGroups(dagRead);
2040
- return clientGroups.get(id);
2022
+ return target;
2041
2023
  }
2042
- function clientGroupHasPendingMutations(clientGroup) {
2043
- for (const [clientID, mutationID] of Object.entries(
2044
- clientGroup.mutationIDs
2045
- )) {
2046
- const lastServerAckdMutationID = clientGroup.lastServerAckdMutationIDs[clientID];
2047
- if (lastServerAckdMutationID === void 0 && mutationID !== 0 || lastServerAckdMutationID < mutationID) {
2048
- return true;
2024
+
2025
+ // ../replicache/src/db/read.ts
2026
+ var Read = class {
2027
+ #dagRead;
2028
+ map;
2029
+ indexes;
2030
+ constructor(dagRead, map, indexes) {
2031
+ this.#dagRead = dagRead;
2032
+ this.map = map;
2033
+ this.indexes = indexes;
2034
+ }
2035
+ has(key) {
2036
+ return this.map.has(key);
2037
+ }
2038
+ get(key) {
2039
+ return this.map.get(key);
2040
+ }
2041
+ isEmpty() {
2042
+ return this.map.isEmpty();
2043
+ }
2044
+ getMapForIndex(indexName) {
2045
+ const idx = this.indexes.get(indexName);
2046
+ if (idx === void 0) {
2047
+ throw new Error(`Unknown index name: ${indexName}`);
2049
2048
  }
2049
+ return idx.map;
2050
2050
  }
2051
- return false;
2052
- }
2053
- async function disableClientGroup(clientGroupID, dagWrite) {
2054
- const clientGroup = await getClientGroup(clientGroupID, dagWrite);
2055
- if (!clientGroup) {
2056
- return;
2051
+ get closed() {
2052
+ return this.#dagRead.closed;
2057
2053
  }
2058
- const disabledClientGroup = {
2059
- ...clientGroup,
2060
- disabled: true
2061
- };
2062
- await setClientGroup(clientGroupID, disabledClientGroup, dagWrite);
2054
+ close() {
2055
+ this.#dagRead.release();
2056
+ }
2057
+ };
2058
+ function readFromDefaultHead(dagRead, formatVersion) {
2059
+ return readFromHead(DEFAULT_HEAD_NAME, dagRead, formatVersion);
2063
2060
  }
2064
-
2065
- // ../replicache/src/with-transactions.ts
2066
- function withRead(store, fn) {
2067
- return using(store.read(), fn);
2061
+ async function readFromHead(name, dagRead, formatVersion) {
2062
+ const commit = await commitFromHead(name, dagRead);
2063
+ return readFromCommit(commit, dagRead, formatVersion);
2068
2064
  }
2069
- function withWriteNoImplicitCommit(store, fn) {
2070
- return using(store.write(), fn);
2065
+ async function readFromHash(hash2, dagRead, formatVersion) {
2066
+ const commit = await commitFromHash(hash2, dagRead);
2067
+ return readFromCommit(commit, dagRead, formatVersion);
2071
2068
  }
2072
- function withWrite(store, fn) {
2073
- return using(store.write(), async (write) => {
2074
- const result = await fn(write);
2075
- await write.commit();
2076
- return result;
2077
- });
2069
+ function readFromCommit(commit, dagRead, formatVersion) {
2070
+ const indexes = readIndexesForRead(commit, dagRead, formatVersion);
2071
+ const map = new BTreeRead(dagRead, formatVersion, commit.valueHash);
2072
+ return new Read(dagRead, map, indexes);
2078
2073
  }
2079
- async function using(x, fn) {
2080
- const write = await x;
2081
- try {
2082
- return await fn(write);
2083
- } finally {
2084
- write.release();
2074
+ function readIndexesForRead(commit, dagRead, formatVersion) {
2075
+ const m = /* @__PURE__ */ new Map();
2076
+ for (const index of commit.indexes) {
2077
+ m.set(
2078
+ index.definition.name,
2079
+ new IndexRead(
2080
+ index,
2081
+ new BTreeRead(dagRead, formatVersion, index.valueHash)
2082
+ )
2083
+ );
2085
2084
  }
2085
+ return m;
2086
2086
  }
2087
2087
 
2088
2088
  // ../replicache/src/async-iterable-to-array.ts
@@ -3756,15 +3756,10 @@ var inspectVersionDownSchema = inspectBaseDownSchema.extend({
3756
3756
  op: valita_exports.literal("version"),
3757
3757
  value: valita_exports.string()
3758
3758
  });
3759
- var inspectAuthenticatedDownSchema = inspectBaseDownSchema.extend({
3760
- op: valita_exports.literal("authenticated"),
3761
- value: valita_exports.boolean()
3762
- });
3763
3759
  var inspectDownBodySchema = valita_exports.union(
3764
3760
  inspectQueriesDownSchema,
3765
3761
  inspectMetricsDownSchema,
3766
- inspectVersionDownSchema,
3767
- inspectAuthenticatedDownSchema
3762
+ inspectVersionDownSchema
3768
3763
  );
3769
3764
  var inspectDownMessageSchema = valita_exports.tuple([
3770
3765
  valita_exports.literal("inspect"),
@@ -7197,6 +7192,10 @@ export {
7197
7192
  stringCompare,
7198
7193
  compareCookies,
7199
7194
  assertCookie,
7195
+ DD31,
7196
+ V6,
7197
+ V7,
7198
+ Latest,
7200
7199
  parse,
7201
7200
  test,
7202
7201
  readonly,
@@ -7213,14 +7212,22 @@ export {
7213
7212
  ChunkNotFoundError,
7214
7213
  mustGetChunk,
7215
7214
  mustGetHeadHash,
7216
- DD31,
7217
- V6,
7218
- V7,
7219
- Latest,
7215
+ withRead,
7216
+ withWriteNoImplicitCommit,
7217
+ withWrite,
7218
+ using,
7219
+ getClientGroups,
7220
+ setClientGroups,
7221
+ setClientGroup,
7222
+ getClientGroup,
7223
+ clientGroupHasPendingMutations,
7224
+ disableClientGroup,
7225
+ binarySearch,
7220
7226
  joinIterables,
7221
7227
  once,
7222
7228
  wrapIterable,
7223
7229
  getSizeOfValue,
7230
+ BTreeRead,
7224
7231
  DEFAULT_HEAD_NAME,
7225
7232
  commitIsLocalDD31,
7226
7233
  localMutations,
@@ -7237,32 +7244,18 @@ export {
7237
7244
  isLocalMetaDD31,
7238
7245
  assertSnapshotMetaDD31,
7239
7246
  assertSnapshotCommitDD31,
7240
- binarySearch,
7241
- BTreeRead,
7247
+ asyncIterableToArray,
7248
+ diff,
7242
7249
  encodeIndexScanKey,
7243
7250
  decodeIndexKey,
7244
7251
  readFromDefaultHead,
7245
7252
  readFromHash,
7246
- asyncIterableToArray,
7247
- diff,
7248
7253
  DiffsMap,
7249
7254
  diff2,
7250
7255
  diffCommits,
7251
7256
  addDiffsForIndexes,
7252
7257
  newWriteLocal,
7253
7258
  newWriteSnapshotDD31,
7254
- getClientGroups,
7255
- setClientGroups,
7256
- setClientGroup,
7257
- getClientGroup,
7258
- clientGroupHasPendingMutations,
7259
- disableClientGroup,
7260
- withRead,
7261
- withWriteNoImplicitCommit,
7262
- withWrite,
7263
- using,
7264
- jsonSchema,
7265
- jsonObjectSchema,
7266
7259
  clientGroupIDSchema,
7267
7260
  clientIDSchema,
7268
7261
  makeClientID,
@@ -7278,7 +7271,8 @@ export {
7278
7271
  getClientGroupIDForClient,
7279
7272
  setClient,
7280
7273
  setClients,
7281
- getNonCryptoRandomValues,
7274
+ jsonSchema,
7275
+ jsonObjectSchema,
7282
7276
  must,
7283
7277
  rowSchema,
7284
7278
  toStaticParam,
@@ -7315,10 +7309,10 @@ export {
7315
7309
  defaultFormat,
7316
7310
  newQuerySymbol,
7317
7311
  AbstractQuery,
7312
+ getNonCryptoRandomValues,
7318
7313
  inspectQueriesDownSchema,
7319
7314
  inspectMetricsDownSchema,
7320
7315
  inspectVersionDownSchema,
7321
- inspectAuthenticatedDownSchema,
7322
7316
  inspectDownMessageSchema,
7323
7317
  primaryKeySchema,
7324
7318
  primaryKeyValueRecordSchema,
@@ -7334,4 +7328,4 @@ export {
7334
7328
  sourceNameFromKey,
7335
7329
  TDigest
7336
7330
  };
7337
- //# sourceMappingURL=chunk-A2FIESI3.js.map
7331
+ //# sourceMappingURL=chunk-G442PJSB.js.map