@rocicorp/zero 0.24.2025091100 → 0.24.2025091200

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 (109) hide show
  1. package/out/{chunk-V2KPKXLX.js → chunk-6XNI6IVJ.js} +217 -133
  2. package/out/chunk-6XNI6IVJ.js.map +7 -0
  3. package/out/chunk-ASRS2LFV.js +35 -0
  4. package/out/chunk-ASRS2LFV.js.map +7 -0
  5. package/out/{chunk-MLYQCVBG.js → chunk-K5ZSWG54.js} +324 -318
  6. package/out/chunk-K5ZSWG54.js.map +7 -0
  7. package/out/{chunk-FH5Q72JS.js → chunk-KXV3BZ4U.js} +3 -3
  8. package/out/{inspector-NC6TPMRA.js → inspector-ZZSIUMBB.js} +36 -6
  9. package/out/inspector-ZZSIUMBB.js.map +7 -0
  10. package/out/react-native.js +276 -278
  11. package/out/react-native.js.map +4 -4
  12. package/out/react.js +13 -25
  13. package/out/react.js.map +2 -2
  14. package/out/replicache/src/deleted-clients.d.ts +17 -10
  15. package/out/replicache/src/deleted-clients.d.ts.map +1 -1
  16. package/out/replicache/src/kv/expo-sqlite/store.d.ts +11 -0
  17. package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -0
  18. package/out/replicache/src/kv/idb-store.d.ts.map +1 -1
  19. package/out/replicache/src/kv/mem-store.d.ts.map +1 -1
  20. package/out/replicache/src/kv/op-sqlite/store.d.ts +14 -0
  21. package/out/replicache/src/kv/op-sqlite/store.d.ts.map +1 -0
  22. package/out/replicache/src/kv/op-sqlite/types.d.ts +13 -0
  23. package/out/replicache/src/kv/op-sqlite/types.d.ts.map +1 -0
  24. package/out/replicache/src/kv/read-impl.d.ts.map +1 -1
  25. package/out/replicache/src/kv/sqlite-store.d.ts +37 -63
  26. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  27. package/out/replicache/src/kv/throw-if-closed.d.ts +12 -0
  28. package/out/replicache/src/kv/throw-if-closed.d.ts.map +1 -0
  29. package/out/replicache/src/kv/write-impl-base.d.ts.map +1 -1
  30. package/out/replicache/src/kv/write-impl.d.ts.map +1 -1
  31. package/out/replicache/src/persist/client-gc.d.ts.map +1 -1
  32. package/out/replicache/src/persist/client-group-gc.d.ts +2 -3
  33. package/out/replicache/src/persist/client-group-gc.d.ts.map +1 -1
  34. package/out/replicache/src/persist/clients.d.ts +2 -1
  35. package/out/replicache/src/persist/clients.d.ts.map +1 -1
  36. package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
  37. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  38. package/out/solid.js +4 -4
  39. package/out/zero/package.json +1 -1
  40. package/out/zero/src/zero-cache-dev.js +4 -0
  41. package/out/zero/src/zero-cache-dev.js.map +1 -1
  42. package/out/zero-cache/src/config/normalize.d.ts +1 -0
  43. package/out/zero-cache/src/config/normalize.d.ts.map +1 -1
  44. package/out/zero-cache/src/config/normalize.js +6 -0
  45. package/out/zero-cache/src/config/normalize.js.map +1 -1
  46. package/out/zero-cache/src/config/zero-config.d.ts +3 -0
  47. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  48. package/out/zero-cache/src/config/zero-config.js +35 -1
  49. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  50. package/out/zero-cache/src/server/inspector-delegate.d.ts +9 -0
  51. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  52. package/out/zero-cache/src/server/inspector-delegate.js +18 -0
  53. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  54. package/out/zero-cache/src/server/syncer.js +2 -2
  55. package/out/zero-cache/src/server/syncer.js.map +1 -1
  56. package/out/zero-cache/src/services/analyze.d.ts +1 -1
  57. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  58. package/out/zero-cache/src/services/analyze.js +6 -6
  59. package/out/zero-cache/src/services/analyze.js.map +1 -1
  60. package/out/zero-cache/src/services/heapz.d.ts +1 -1
  61. package/out/zero-cache/src/services/heapz.d.ts.map +1 -1
  62. package/out/zero-cache/src/services/heapz.js +2 -2
  63. package/out/zero-cache/src/services/heapz.js.map +1 -1
  64. package/out/zero-cache/src/services/mutagen/pusher.d.ts +8 -0
  65. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  66. package/out/zero-cache/src/services/statz.d.ts +1 -1
  67. package/out/zero-cache/src/services/statz.d.ts.map +1 -1
  68. package/out/zero-cache/src/services/statz.js +3 -3
  69. package/out/zero-cache/src/services/statz.js.map +1 -1
  70. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +1 -1
  71. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  72. package/out/zero-cache/src/services/view-syncer/view-syncer.js +29 -1
  73. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  74. package/out/zero-client/src/client/active-clients-manager.d.ts +2 -1
  75. package/out/zero-client/src/client/active-clients-manager.d.ts.map +1 -1
  76. package/out/zero-client/src/client/delete-clients-manager.d.ts +3 -3
  77. package/out/zero-client/src/client/delete-clients-manager.d.ts.map +1 -1
  78. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  79. package/out/zero-client/src/client/zero.d.ts +2 -2
  80. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  81. package/out/zero-protocol/src/down.d.ts +5 -0
  82. package/out/zero-protocol/src/down.d.ts.map +1 -1
  83. package/out/zero-protocol/src/inspect-down.d.ts +17 -0
  84. package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
  85. package/out/zero-protocol/src/inspect-down.js +5 -1
  86. package/out/zero-protocol/src/inspect-down.js.map +1 -1
  87. package/out/zero-protocol/src/inspect-up.d.ts +39 -10
  88. package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
  89. package/out/zero-protocol/src/inspect-up.js +10 -3
  90. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  91. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  92. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  93. package/out/zero-protocol/src/protocol-version.js +2 -1
  94. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  95. package/out/zero-protocol/src/up.d.ts +10 -1
  96. package/out/zero-protocol/src/up.d.ts.map +1 -1
  97. package/out/zero-react/src/use-query.d.ts.map +1 -1
  98. package/out/zero-react-native/src/mod.d.ts +2 -2
  99. package/out/zero-react-native/src/mod.d.ts.map +1 -1
  100. package/out/zero.js +4 -4
  101. package/package.json +1 -1
  102. package/out/chunk-MKB4RXL3.js +0 -15
  103. package/out/chunk-MKB4RXL3.js.map +0 -7
  104. package/out/chunk-MLYQCVBG.js.map +0 -7
  105. package/out/chunk-V2KPKXLX.js.map +0 -7
  106. package/out/inspector-NC6TPMRA.js.map +0 -7
  107. package/out/replicache/src/expo/store.d.ts +0 -4
  108. package/out/replicache/src/expo/store.d.ts.map +0 -1
  109. /package/out/{chunk-FH5Q72JS.js.map → chunk-KXV3BZ4U.js.map} +0 -0
@@ -258,308 +258,6 @@ async function mustGetHeadHash(name, store) {
258
258
  return hash2;
259
259
  }
260
260
 
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
- }
562
-
563
261
  // ../shared/src/json.ts
564
262
  function deepEqual(a, b) {
565
263
  if (a === b) {
@@ -700,6 +398,41 @@ function isJSONArray(v2, path2) {
700
398
  return true;
701
399
  }
702
400
 
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
+
703
436
  // ../replicache/src/size-of-value.ts
704
437
  var SIZE_TAG = 1;
705
438
  var SIZE_INT32 = 4;
@@ -1568,11 +1301,62 @@ function assertCookie(v2) {
1568
1301
  if (v2 === null || typeof v2 === "string" || typeof v2 === "number") {
1569
1302
  return;
1570
1303
  }
1571
- assertJSONObject(v2);
1572
- if (typeof v2.order === "string" || typeof v2.order === "number") {
1573
- return;
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");
1574
1349
  }
1575
- throw new Error("Invalid cookie");
1350
+ if (v2.length > 0) {
1351
+ assertString(v2[0]);
1352
+ for (let i = 1; i < v2.length; i++) {
1353
+ assertString(v2[i]);
1354
+ }
1355
+ }
1356
+ }
1357
+ function createChunk(data, refs, chunkHasher) {
1358
+ const hash2 = chunkHasher();
1359
+ return new Chunk(hash2, data, refs);
1576
1360
  }
1577
1361
 
1578
1362
  // ../replicache/src/db/meta-type-enum.ts
@@ -2085,6 +1869,222 @@ function readIndexesForRead(commit, dagRead, formatVersion) {
2085
1869
  return m;
2086
1870
  }
2087
1871
 
1872
+ // ../replicache/src/with-transactions.ts
1873
+ function withRead(store, fn) {
1874
+ return using(store.read(), fn);
1875
+ }
1876
+ function withWriteNoImplicitCommit(store, fn) {
1877
+ return using(store.write(), fn);
1878
+ }
1879
+ function withWrite(store, fn) {
1880
+ return using(store.write(), async (write) => {
1881
+ const result = await fn(write);
1882
+ await write.commit();
1883
+ return result;
1884
+ });
1885
+ }
1886
+ async function using(x, fn) {
1887
+ const write = await x;
1888
+ try {
1889
+ return await fn(write);
1890
+ } finally {
1891
+ write.release();
1892
+ }
1893
+ }
1894
+
1895
+ // ../replicache/src/index-defs.ts
1896
+ var indexDefinitionSchema = readonlyObject({
1897
+ prefix: valita_exports.string().optional(),
1898
+ jsonPointer: valita_exports.string(),
1899
+ allowEmpty: valita_exports.boolean().optional()
1900
+ });
1901
+ var indexDefinitionsSchema = readonlyRecord(
1902
+ indexDefinitionSchema
1903
+ );
1904
+ function indexDefinitionEqual(a, b) {
1905
+ return a.jsonPointer === b.jsonPointer && (a.allowEmpty ?? false) === (b.allowEmpty ?? false) && (a.prefix ?? "") === (b.prefix ?? "");
1906
+ }
1907
+ function indexDefinitionsEqual(a, b) {
1908
+ if (Object.keys(a).length !== Object.keys(b).length) {
1909
+ return false;
1910
+ }
1911
+ for (const [aKey, aValue] of Object.entries(a)) {
1912
+ const bValue = b[aKey];
1913
+ if (!bValue || !indexDefinitionEqual(aValue, bValue)) {
1914
+ return false;
1915
+ }
1916
+ }
1917
+ return true;
1918
+ }
1919
+
1920
+ // ../replicache/src/persist/client-groups.ts
1921
+ var clientGroupSchema = readonlyObject({
1922
+ /**
1923
+ * The hash of the commit in the perdag last persisted to this client group.
1924
+ * Should only be updated by clients assigned to this client group.
1925
+ */
1926
+ headHash: hashSchema,
1927
+ /**
1928
+ * Set of mutator names common to all clients assigned to this client group.
1929
+ */
1930
+ mutatorNames: readonlyArray(valita_exports.string()),
1931
+ /**
1932
+ * Index definitions common to all clients assigned to this client group.
1933
+ */
1934
+ indexes: indexDefinitionsSchema,
1935
+ /**
1936
+ * The highest mutation ID of every client assigned to this client group.
1937
+ * Should only be updated by clients assigned to this client group. Read by
1938
+ * other clients to determine if there are unacknowledged pending mutations
1939
+ * for them to try to recover. This is redundant with information in the
1940
+ * commit graph at `headHash`, but allows other clients to determine if there
1941
+ * are unacknowledged pending mutations without having to load the commit
1942
+ * graph.
1943
+ */
1944
+ mutationIDs: readonlyRecord(valita_exports.number()),
1945
+ /**
1946
+ * The highest lastMutationID received from the server for every client
1947
+ * assigned to this client group.
1948
+ *
1949
+ * Should be updated by the clients assigned to this client group whenever
1950
+ * they persist to this client group. Read by other clients to determine if
1951
+ * there are unacknowledged pending mutations for them to recover and
1952
+ * *updated* by other clients upon successfully recovering pending mutations
1953
+ * to avoid redundant pushes of pending mutations.
1954
+ *
1955
+ * Note: This will be the same as the `lastMutationIDs` of the base snapshot
1956
+ * of the client group's commit graph when written by clients assigned to this
1957
+ * client group. However, when written by another client recovering mutations
1958
+ * it may be different because the other client does not update the commit
1959
+ * graph.
1960
+ */
1961
+ lastServerAckdMutationIDs: valita_exports.record(valita_exports.number()),
1962
+ /**
1963
+ * If the server deletes this client group it can signal that the client group
1964
+ * was deleted. If that happens we mark this client group as disabled so that
1965
+ * we do not use it again when creating new clients.
1966
+ */
1967
+ disabled: valita_exports.boolean()
1968
+ });
1969
+ var CLIENT_GROUPS_HEAD_NAME = "client-groups";
1970
+ function assertClientGroup(value) {
1971
+ assert2(value, clientGroupSchema);
1972
+ }
1973
+ function chunkDataToClientGroupMap(chunkData) {
1974
+ assertObject(chunkData);
1975
+ const clientGroups = /* @__PURE__ */ new Map();
1976
+ for (const [key, value] of Object.entries(chunkData)) {
1977
+ if (value !== void 0) {
1978
+ assertClientGroup(value);
1979
+ clientGroups.set(key, value);
1980
+ }
1981
+ }
1982
+ return clientGroups;
1983
+ }
1984
+ function clientGroupMapToChunkData(clientGroups, dagWrite) {
1985
+ const chunkData = {};
1986
+ for (const [clientGroupID, clientGroup] of clientGroups.entries()) {
1987
+ dagWrite.assertValidHash(clientGroup.headHash);
1988
+ chunkData[clientGroupID] = {
1989
+ ...clientGroup,
1990
+ mutatorNames: [...clientGroup.mutatorNames.values()]
1991
+ };
1992
+ }
1993
+ return deepFreeze(chunkData);
1994
+ }
1995
+ async function getClientGroupsAtHash(hash2, dagRead) {
1996
+ const chunk = await dagRead.getChunk(hash2);
1997
+ return chunkDataToClientGroupMap(chunk?.data);
1998
+ }
1999
+ async function getClientGroups(dagRead) {
2000
+ const hash2 = await dagRead.getHead(CLIENT_GROUPS_HEAD_NAME);
2001
+ if (!hash2) {
2002
+ return /* @__PURE__ */ new Map();
2003
+ }
2004
+ return getClientGroupsAtHash(hash2, dagRead);
2005
+ }
2006
+ async function setClientGroups(clientGroups, dagWrite) {
2007
+ const currClientGroups = await getClientGroups(dagWrite);
2008
+ for (const [clientGroupID, clientGroup] of clientGroups) {
2009
+ const currClientGroup = currClientGroups.get(clientGroupID);
2010
+ validateClientGroupUpdate(clientGroup, currClientGroup);
2011
+ }
2012
+ return setValidatedClientGroups(clientGroups, dagWrite);
2013
+ }
2014
+ async function setClientGroup(clientGroupID, clientGroup, dagWrite) {
2015
+ const currClientGroups = await getClientGroups(dagWrite);
2016
+ const currClientGroup = currClientGroups.get(clientGroupID);
2017
+ validateClientGroupUpdate(clientGroup, currClientGroup);
2018
+ const newClientGroups = new Map(currClientGroups);
2019
+ newClientGroups.set(clientGroupID, clientGroup);
2020
+ return setValidatedClientGroups(newClientGroups, dagWrite);
2021
+ }
2022
+ function validateClientGroupUpdate(clientGroup, currClientGroup) {
2023
+ const mutatorNamesSet = new Set(clientGroup.mutatorNames);
2024
+ assert(
2025
+ mutatorNamesSet.size === clientGroup.mutatorNames.length,
2026
+ "A client group's mutatorNames must be a set."
2027
+ );
2028
+ if (currClientGroup !== void 0) {
2029
+ assert(
2030
+ indexDefinitionsEqual(currClientGroup.indexes, clientGroup.indexes),
2031
+ "A client group's index definitions must never change."
2032
+ );
2033
+ assert(
2034
+ mutatorNamesEqual(mutatorNamesSet, currClientGroup.mutatorNames),
2035
+ "A client group's mutatorNames must never change."
2036
+ );
2037
+ }
2038
+ }
2039
+ async function setValidatedClientGroups(clientGroups, dagWrite) {
2040
+ const chunkData = clientGroupMapToChunkData(clientGroups, dagWrite);
2041
+ const refs = /* @__PURE__ */ new Set();
2042
+ for (const clientGroup of clientGroups.values()) {
2043
+ refs.add(clientGroup.headHash);
2044
+ }
2045
+ const chunk = dagWrite.createChunk(chunkData, toRefs(refs));
2046
+ await dagWrite.putChunk(chunk);
2047
+ await dagWrite.setHead(CLIENT_GROUPS_HEAD_NAME, chunk.hash);
2048
+ return clientGroups;
2049
+ }
2050
+ function mutatorNamesEqual(mutatorNamesSet, mutatorNames) {
2051
+ if (mutatorNames.length !== mutatorNamesSet.size) {
2052
+ return false;
2053
+ }
2054
+ for (const mutatorName of mutatorNames) {
2055
+ if (!mutatorNamesSet.has(mutatorName)) {
2056
+ return false;
2057
+ }
2058
+ }
2059
+ return true;
2060
+ }
2061
+ async function getClientGroup(id, dagRead) {
2062
+ const clientGroups = await getClientGroups(dagRead);
2063
+ return clientGroups.get(id);
2064
+ }
2065
+ function clientGroupHasPendingMutations(clientGroup) {
2066
+ for (const [clientID, mutationID] of Object.entries(
2067
+ clientGroup.mutationIDs
2068
+ )) {
2069
+ const lastServerAckdMutationID = clientGroup.lastServerAckdMutationIDs[clientID];
2070
+ if (lastServerAckdMutationID === void 0 && mutationID !== 0 || lastServerAckdMutationID < mutationID) {
2071
+ return true;
2072
+ }
2073
+ }
2074
+ return false;
2075
+ }
2076
+ async function disableClientGroup(clientGroupID, dagWrite) {
2077
+ const clientGroup = await getClientGroup(clientGroupID, dagWrite);
2078
+ if (!clientGroup) {
2079
+ return;
2080
+ }
2081
+ const disabledClientGroup = {
2082
+ ...clientGroup,
2083
+ disabled: true
2084
+ };
2085
+ await setClientGroup(clientGroupID, disabledClientGroup, dagWrite);
2086
+ }
2087
+
2088
2088
  // ../replicache/src/async-iterable-to-array.ts
2089
2089
  async function asyncIterableToArray(it) {
2090
2090
  const arr = [];
@@ -3756,10 +3756,15 @@ 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
+ });
3759
3763
  var inspectDownBodySchema = valita_exports.union(
3760
3764
  inspectQueriesDownSchema,
3761
3765
  inspectMetricsDownSchema,
3762
- inspectVersionDownSchema
3766
+ inspectVersionDownSchema,
3767
+ inspectAuthenticatedDownSchema
3763
3768
  );
3764
3769
  var inspectDownMessageSchema = valita_exports.tuple([
3765
3770
  valita_exports.literal("inspect"),
@@ -7222,16 +7227,6 @@ export {
7222
7227
  ChunkNotFoundError,
7223
7228
  mustGetChunk,
7224
7229
  mustGetHeadHash,
7225
- withRead,
7226
- withWriteNoImplicitCommit,
7227
- withWrite,
7228
- using,
7229
- getClientGroups,
7230
- setClientGroups,
7231
- setClientGroup,
7232
- getClientGroup,
7233
- clientGroupHasPendingMutations,
7234
- disableClientGroup,
7235
7230
  binarySearch,
7236
7231
  joinIterables,
7237
7232
  once,
@@ -7268,6 +7263,16 @@ export {
7268
7263
  newWriteSnapshotDD31,
7269
7264
  clientGroupIDSchema,
7270
7265
  clientIDSchema,
7266
+ withRead,
7267
+ withWriteNoImplicitCommit,
7268
+ withWrite,
7269
+ using,
7270
+ getClientGroups,
7271
+ setClientGroups,
7272
+ setClientGroup,
7273
+ getClientGroup,
7274
+ clientGroupHasPendingMutations,
7275
+ disableClientGroup,
7271
7276
  makeClientID,
7272
7277
  assertClientV6,
7273
7278
  getClients,
@@ -7323,6 +7328,7 @@ export {
7323
7328
  inspectQueriesDownSchema,
7324
7329
  inspectMetricsDownSchema,
7325
7330
  inspectVersionDownSchema,
7331
+ inspectAuthenticatedDownSchema,
7326
7332
  inspectDownMessageSchema,
7327
7333
  primaryKeySchema,
7328
7334
  primaryKeyValueRecordSchema,
@@ -7338,4 +7344,4 @@ export {
7338
7344
  sourceNameFromKey,
7339
7345
  TDigest
7340
7346
  };
7341
- //# sourceMappingURL=chunk-MLYQCVBG.js.map
7347
+ //# sourceMappingURL=chunk-K5ZSWG54.js.map