@rocicorp/zero 0.17.2025031401 → 0.17.2025031904

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 (52) hide show
  1. package/out/advanced.js +1 -1
  2. package/out/{chunk-UZE45UK4.js → chunk-BPGCXNAT.js} +83 -85
  3. package/out/chunk-BPGCXNAT.js.map +7 -0
  4. package/out/{chunk-SVJISXWE.js → chunk-MJCITZ5S.js} +80 -74
  5. package/out/chunk-MJCITZ5S.js.map +7 -0
  6. package/out/replicache/src/persist/refresh.d.ts.map +1 -1
  7. package/out/replicache/src/replicache-options.d.ts +2 -1
  8. package/out/replicache/src/replicache-options.d.ts.map +1 -1
  9. package/out/shared/src/custom-key-map.d.ts +2 -2
  10. package/out/shared/src/custom-key-map.d.ts.map +1 -1
  11. package/out/shared/src/custom-key-map.js.map +1 -1
  12. package/out/shared/src/custom-key-set.d.ts +2 -2
  13. package/out/shared/src/custom-key-set.d.ts.map +1 -1
  14. package/out/shared/src/custom-key-set.js.map +1 -1
  15. package/out/solid.js +4 -25
  16. package/out/solid.js.map +2 -2
  17. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  18. package/out/zero-cache/src/config/zero-config.js +2 -0
  19. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  20. package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
  21. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  22. package/out/zero-client/src/client/custom.d.ts +13 -9
  23. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  24. package/out/zero-client/src/client/ivm-branch.d.ts +2 -1
  25. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  26. package/out/zero-client/src/client/zero-rep.d.ts +2 -1
  27. package/out/zero-client/src/client/zero-rep.d.ts.map +1 -1
  28. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  29. package/out/zero-schema/src/builder/schema-builder.d.ts +0 -1
  30. package/out/zero-schema/src/builder/schema-builder.d.ts.map +1 -1
  31. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  32. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  33. package/out/zero.js +2 -2
  34. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  35. package/out/zql/src/ivm/array-view.js +2 -3
  36. package/out/zql/src/ivm/array-view.js.map +1 -1
  37. package/out/zql/src/ivm/take.d.ts +3 -0
  38. package/out/zql/src/ivm/take.d.ts.map +1 -1
  39. package/out/zql/src/ivm/take.js +33 -7
  40. package/out/zql/src/ivm/take.js.map +1 -1
  41. package/out/zql/src/ivm/view-apply-change.d.ts +5 -1
  42. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  43. package/out/zql/src/ivm/view-apply-change.js +68 -71
  44. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  45. package/out/zql/src/query/query-impl.d.ts +1 -1
  46. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  47. package/out/zql/src/query/query-impl.js.map +1 -1
  48. package/out/zql/src/query/query.d.ts +1 -1
  49. package/out/zql/src/query/query.d.ts.map +1 -1
  50. package/package.json +3 -4
  51. package/out/chunk-SVJISXWE.js.map +0 -7
  52. package/out/chunk-UZE45UK4.js.map +0 -7
package/out/advanced.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-ULOTOBTC.js";
2
2
  import {
3
3
  applyChange
4
- } from "./chunk-SVJISXWE.js";
4
+ } from "./chunk-MJCITZ5S.js";
5
5
  import "./chunk-424PT5DM.js";
6
6
  export {
7
7
  applyChange
@@ -21,7 +21,7 @@ import {
21
21
  throwInvalidType,
22
22
  unreachable,
23
23
  valuesEqual
24
- } from "./chunk-SVJISXWE.js";
24
+ } from "./chunk-MJCITZ5S.js";
25
25
  import {
26
26
  __export,
27
27
  __reExport
@@ -6315,7 +6315,7 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
6315
6315
  return;
6316
6316
  }
6317
6317
  let memdagBaseSnapshotPersisted = false;
6318
- const zeroDataForMemdagBaseSnapshot = getZeroData && await getZeroData(memdagBaseSnapshot.chunk.hash);
6318
+ const zeroDataForMemdagBaseSnapshot = getZeroData && await getZeroData("rebase", memdagBaseSnapshot.chunk.hash);
6319
6319
  await withWrite(perdag, async (perdagWrite) => {
6320
6320
  const [mainClientGroup, latestPerdagMainClientGroupHeadCommit] = await getClientGroupInfo(perdagWrite, mainClientGroupID);
6321
6321
  let newMainClientGroupHeadHash = latestPerdagMainClientGroupHeadCommit.chunk.hash;
@@ -6368,7 +6368,7 @@ async function persistDD31(lc, clientID, memdag, perdag, mutators, closed, forma
6368
6368
  }
6369
6369
  let zeroDataForPerdagHeadCommit;
6370
6370
  if (!memdagBaseSnapshotPersisted) {
6371
- zeroDataForPerdagHeadCommit = getZeroData && await getZeroData(newMainClientGroupHeadHash, {
6371
+ zeroDataForPerdagHeadCommit = getZeroData && await getZeroData("rebase", newMainClientGroupHeadHash, {
6372
6372
  openLazySourceRead: perdagWrite
6373
6373
  });
6374
6374
  }
@@ -6575,9 +6575,13 @@ async function refresh(lc, memdag, perdag, clientID, mutators, diffConfig, close
6575
6575
  await Promise.all(ps);
6576
6576
  let newMemdagHeadHash = perdagClientGroupHeadHash;
6577
6577
  if (newMemdagMutations.length > 0) {
6578
- const zeroData2 = await zero?.getTxData?.(newMemdagHeadHash, {
6579
- openLazyRead: memdagWrite
6580
- });
6578
+ const zeroData2 = await zero?.getTxData?.(
6579
+ "rebase",
6580
+ newMemdagHeadHash,
6581
+ {
6582
+ openLazyRead: memdagWrite
6583
+ }
6584
+ );
6581
6585
  for (let i = newMemdagMutations.length - 1; i >= 0; i--) {
6582
6586
  newMemdagHeadHash = (await rebaseMutationAndPutCommit(
6583
6587
  newMemdagMutations[i],
@@ -7620,7 +7624,7 @@ var ReplicacheImpl = class {
7620
7624
  void this.#schedulePersist();
7621
7625
  return;
7622
7626
  }
7623
- const zeroData2 = await this.#zero?.getTxData?.(syncHead);
7627
+ const zeroData2 = await this.#zero?.getTxData?.("rebase", syncHead);
7624
7628
  for (const mutation of replayMutations) {
7625
7629
  if (this.#subscriptions.hasPendingSubscriptionRuns) {
7626
7630
  await Promise.resolve();
@@ -8186,7 +8190,7 @@ var ReplicacheImpl = class {
8186
8190
  clientID,
8187
8191
  await dbWrite.getMutationID(),
8188
8192
  "initial",
8189
- await this.#zero?.getTxData(headHash, {
8193
+ await this.#zero?.getTxData("initial", headHash, {
8190
8194
  openLazyRead: dagWrite
8191
8195
  }),
8192
8196
  dbWrite,
@@ -10128,6 +10132,8 @@ var Take = class {
10128
10132
  #limit;
10129
10133
  #partitionKey;
10130
10134
  #partitionKeyComparator;
10135
+ // Fetch overlay needed for some split push cases.
10136
+ #rowHiddenFromFetch;
10131
10137
  #output = throwOutput;
10132
10138
  constructor(input, storage, limit, partitionKey) {
10133
10139
  assert(limit >= 0);
@@ -10163,6 +10169,12 @@ var Take = class {
10163
10169
  if (this.getSchema().compareRows(takeState.bound, inputNode.row) < 0) {
10164
10170
  return;
10165
10171
  }
10172
+ if (this.#rowHiddenFromFetch && this.getSchema().compareRows(
10173
+ this.#rowHiddenFromFetch,
10174
+ inputNode.row
10175
+ ) === 0) {
10176
+ continue;
10177
+ }
10166
10178
  yield inputNode;
10167
10179
  }
10168
10180
  return;
@@ -10305,14 +10317,16 @@ var Take = class {
10305
10317
  type: "remove",
10306
10318
  node: boundNode
10307
10319
  };
10308
- this.#output.push(change);
10309
10320
  this.#setTakeState(
10310
10321
  takeStateKey,
10311
10322
  takeState.size,
10312
10323
  beforeBoundNode === void 0 || compareRows(change.node.row, beforeBoundNode.row) > 0 ? change.node.row : beforeBoundNode.row,
10313
10324
  maxBound
10314
10325
  );
10315
- this.#output.push(removeChange);
10326
+ this.#withRowHiddenFromFetch(change.node.row, () => {
10327
+ this.#output.push(removeChange);
10328
+ });
10329
+ this.#output.push(change);
10316
10330
  } else if (change.type === "remove") {
10317
10331
  if (takeState.bound === void 0) {
10318
10332
  return;
@@ -10483,19 +10497,21 @@ var Take = class {
10483
10497
  }),
10484
10498
  2
10485
10499
  );
10486
- this.#output.push({
10487
- type: "add",
10488
- node: change.node
10489
- });
10490
10500
  this.#setTakeState(
10491
10501
  takeStateKey,
10492
10502
  takeState.size,
10493
10503
  newBoundNode.row,
10494
10504
  maxBound
10495
10505
  );
10506
+ this.#withRowHiddenFromFetch(change.node.row, () => {
10507
+ this.#output.push({
10508
+ type: "remove",
10509
+ node: oldBoundNode
10510
+ });
10511
+ });
10496
10512
  this.#output.push({
10497
- type: "remove",
10498
- node: oldBoundNode
10513
+ type: "add",
10514
+ node: change.node
10499
10515
  });
10500
10516
  return;
10501
10517
  }
@@ -10539,6 +10555,14 @@ var Take = class {
10539
10555
  }
10540
10556
  unreachable();
10541
10557
  }
10558
+ #withRowHiddenFromFetch(row, fn) {
10559
+ this.#rowHiddenFromFetch = row;
10560
+ try {
10561
+ fn();
10562
+ } finally {
10563
+ this.#rowHiddenFromFetch = void 0;
10564
+ }
10565
+ }
10542
10566
  #setTakeState(takeStateKey, size, bound, maxBound) {
10543
10567
  this.#storage.set(takeStateKey, {
10544
10568
  size,
@@ -11074,7 +11098,6 @@ var ArrayView = class {
11074
11098
  onDestroy;
11075
11099
  #dirty = false;
11076
11100
  #complete = false;
11077
- #refCountMap = /* @__PURE__ */ new WeakMap();
11078
11101
  constructor(input, format = { singular: false, relationships: {} }, queryComplete = true) {
11079
11102
  this.#input = input;
11080
11103
  this.#schema = input.getSchema();
@@ -11124,22 +11147,14 @@ var ArrayView = class {
11124
11147
  { type: "add", node },
11125
11148
  this.#schema,
11126
11149
  "",
11127
- this.#format,
11128
- this.#refCountMap
11150
+ this.#format
11129
11151
  );
11130
11152
  }
11131
11153
  this.flush();
11132
11154
  }
11133
11155
  push(change) {
11134
11156
  this.#dirty = true;
11135
- applyChange(
11136
- this.#root,
11137
- change,
11138
- this.#schema,
11139
- "",
11140
- this.#format,
11141
- this.#refCountMap
11142
- );
11157
+ applyChange(this.#root, change, this.#schema, "", this.#format);
11143
11158
  }
11144
11159
  flush() {
11145
11160
  if (!this.#dirty) {
@@ -13682,7 +13697,14 @@ var IVMSourceBranch = class _IVMSourceBranch {
13682
13697
  /**
13683
13698
  * Fork the branch and patch it up to match the desired head.
13684
13699
  */
13685
- async forkToHead(store, desiredHead, readOptions) {
13700
+ async forkToHead(reason, store, desiredHead, readOptions) {
13701
+ if (reason === "initial") {
13702
+ assert(
13703
+ this.hash === desiredHead,
13704
+ "main branch must be at desired head for `initial`"
13705
+ );
13706
+ return this;
13707
+ }
13686
13708
  const fork = this.fork();
13687
13709
  if (fork.hash === desiredHead) {
13688
13710
  return fork;
@@ -14103,7 +14125,12 @@ var TransactionImpl = class {
14103
14125
  this.mutate = makeSchemaCRUD(
14104
14126
  schema,
14105
14127
  repTx,
14106
- must(
14128
+ // CRUD operators should not mutate the IVM store directly
14129
+ // for `initial`. The IVM store will be updated via calls to `advance`
14130
+ // after the transaction has been committed to the Replicache b-tree.
14131
+ // Mutating the IVM store in the mutator would cause us to synchronously
14132
+ // notify listeners of IVM while we're inside of the Replicache DB transaction.
14133
+ repTx.reason === "initial" ? void 0 : must(
14107
14134
  castedRepTx[zeroData],
14108
14135
  "zero was not set on replicache internal options!"
14109
14136
  )
@@ -14499,7 +14526,7 @@ function makeMessage(message, context, logLevel) {
14499
14526
  }
14500
14527
 
14501
14528
  // ../zero-client/src/client/version.ts
14502
- var version2 = "0.17.2025031401";
14529
+ var version2 = "0.17.2025031904";
14503
14530
 
14504
14531
  // ../zero-client/src/client/log-options.ts
14505
14532
  var LevelFilterLogSink = class {
@@ -15451,11 +15478,12 @@ var ZeroRep = class {
15451
15478
  this.#store = store;
15452
15479
  this.#context.processChanges(void 0, hash2, diffs);
15453
15480
  }
15454
- getTxData = (desiredHead, readOptions) => {
15481
+ getTxData = (reason, desiredHead, readOptions) => {
15455
15482
  if (!this.#customMutatorsEnabled) {
15456
15483
  return;
15457
15484
  }
15458
15485
  return this.#ivmMain.forkToHead(
15486
+ reason,
15459
15487
  must(this.#store),
15460
15488
  desiredHead,
15461
15489
  readOptions
@@ -15656,45 +15684,19 @@ var Zero = class {
15656
15684
  [CRUD_MUTATION_NAME]: makeCRUDMutator(schema)
15657
15685
  };
15658
15686
  this.#ivmMain = new IVMSourceBranch(schema.tables);
15659
- function assertUnique(key) {
15660
- assert(
15661
- replicacheMutators[key] === void 0,
15662
- `A mutator, or mutator namespace, has already been defined for ${key}`
15663
- );
15664
- }
15665
15687
  const lc = new LogContext4(logOptions.logLevel, {}, logOptions.logSink);
15666
- if (options.mutators) {
15667
- for (const [namespaceOrKey, mutatorOrMutators] of Object.entries(
15668
- options.mutators
15688
+ for (const [namespace, mutatorsForNamespace] of Object.entries(
15689
+ options.mutators ?? {}
15690
+ )) {
15691
+ for (const [name, mutator] of Object.entries(
15692
+ mutatorsForNamespace
15669
15693
  )) {
15670
- if (typeof mutatorOrMutators === "function") {
15671
- const key = namespaceOrKey;
15672
- assertUnique(key);
15673
- replicacheMutators[key] = makeReplicacheMutator(
15674
- lc,
15675
- mutatorOrMutators,
15676
- schema,
15677
- slowMaterializeThreshold
15678
- );
15679
- continue;
15680
- }
15681
- if (typeof mutatorOrMutators === "object") {
15682
- for (const [name, mutator] of Object.entries(mutatorOrMutators)) {
15683
- const key = customMutatorKey(
15684
- namespaceOrKey,
15685
- name
15686
- );
15687
- assertUnique(key);
15688
- replicacheMutators[key] = makeReplicacheMutator(
15689
- lc,
15690
- mutator,
15691
- schema,
15692
- slowMaterializeThreshold
15693
- );
15694
- }
15695
- continue;
15696
- }
15697
- unreachable(mutatorOrMutators);
15694
+ replicacheMutators[customMutatorKey(namespace, name)] = makeReplicacheMutator(
15695
+ lc,
15696
+ mutator,
15697
+ schema,
15698
+ slowMaterializeThreshold
15699
+ );
15698
15700
  }
15699
15701
  }
15700
15702
  this.storageKey = storageKey ?? "";
@@ -15768,23 +15770,19 @@ var Zero = class {
15768
15770
  if (options.mutators) {
15769
15771
  mutate = {};
15770
15772
  mutateBatch = void 0;
15771
- for (const [namespaceOrKey, mutatorsOrMutator] of Object.entries(
15772
- options.mutators
15773
+ }
15774
+ for (const [namespace, mutatorsForNamespace] of Object.entries(
15775
+ options.mutators ?? {}
15776
+ )) {
15777
+ let existing = mutate[namespace];
15778
+ if (existing === void 0) {
15779
+ existing = {};
15780
+ mutate[namespace] = existing;
15781
+ }
15782
+ for (const name of Object.keys(
15783
+ mutatorsForNamespace
15773
15784
  )) {
15774
- if (typeof mutatorsOrMutator === "function") {
15775
- mutate[namespaceOrKey] = must(rep.mutate[namespaceOrKey]);
15776
- continue;
15777
- }
15778
- let existing = mutate[namespaceOrKey];
15779
- if (existing === void 0) {
15780
- existing = {};
15781
- mutate[namespaceOrKey] = existing;
15782
- }
15783
- for (const name of Object.keys(mutatorsOrMutator)) {
15784
- existing[name] = must(
15785
- rep.mutate[customMutatorKey(namespaceOrKey, name)]
15786
- );
15787
- }
15785
+ existing[name] = must(rep.mutate[customMutatorKey(namespace, name)]);
15788
15786
  }
15789
15787
  }
15790
15788
  this.mutate = mutate;
@@ -16804,4 +16802,4 @@ export {
16804
16802
  escapeLike,
16805
16803
  Zero
16806
16804
  };
16807
- //# sourceMappingURL=chunk-UZE45UK4.js.map
16805
+ //# sourceMappingURL=chunk-BPGCXNAT.js.map