@rocicorp/zero 0.22.2025070200 → 0.22.2025070701

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 (48) hide show
  1. package/out/analyze-query/src/bin-analyze.js +1 -0
  2. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  3. package/out/{chunk-43L7S6AU.js → chunk-4XUYLHLN.js} +114 -113
  4. package/out/chunk-4XUYLHLN.js.map +7 -0
  5. package/out/{chunk-ODTJYJ37.js → chunk-7VV3XSWG.js} +3 -3
  6. package/out/{chunk-HTNKB2W7.js → chunk-XUGOP4Z4.js} +77 -55
  7. package/out/{chunk-HTNKB2W7.js.map → chunk-XUGOP4Z4.js.map} +2 -2
  8. package/out/{inspector-WSEHHWA3.js → inspector-DIXW3TGL.js} +2 -2
  9. package/out/react.js +3 -3
  10. package/out/react.js.map +2 -2
  11. package/out/replicache/src/btree/node.d.ts.map +1 -1
  12. package/out/replicache/src/subscriptions.d.ts.map +1 -1
  13. package/out/shared/src/binary-search.d.ts.map +1 -0
  14. package/out/solid.js +27 -7
  15. package/out/solid.js.map +2 -2
  16. package/out/zero-client/src/client/context.d.ts +3 -1
  17. package/out/zero-client/src/client/context.d.ts.map +1 -1
  18. package/out/zero-client/src/client/custom.d.ts +6 -6
  19. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  20. package/out/zero-client/src/client/options.d.ts +9 -2
  21. package/out/zero-client/src/client/options.d.ts.map +1 -1
  22. package/out/zero-client/src/client/query-manager.d.ts +2 -1
  23. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  24. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  25. package/out/zero-client/src/client/zero.d.ts +3 -3
  26. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  27. package/out/zero-react/src/zero-provider.d.ts +1 -1
  28. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  29. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  30. package/out/zero-solid/src/use-zero.d.ts +1 -1
  31. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  32. package/out/zero.js +3 -3
  33. package/out/zql/src/ivm/view-apply-change.d.ts +2 -3
  34. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  35. package/out/zql/src/ivm/view-apply-change.js +102 -74
  36. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  37. package/out/zql/src/query/query-delegate.d.ts +1 -0
  38. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  39. package/out/zqlite/src/query-delegate.d.ts +1 -0
  40. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  41. package/out/zqlite/src/query-delegate.js +1 -0
  42. package/out/zqlite/src/query-delegate.js.map +1 -1
  43. package/package.json +1 -1
  44. package/out/chunk-43L7S6AU.js.map +0 -7
  45. package/out/replicache/src/binary-search.d.ts.map +0 -1
  46. /package/out/{chunk-ODTJYJ37.js.map → chunk-7VV3XSWG.js.map} +0 -0
  47. /package/out/{inspector-WSEHHWA3.js.map → inspector-DIXW3TGL.js.map} +0 -0
  48. /package/out/{replicache → shared}/src/binary-search.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  clientToServer
3
- } from "./chunk-HTNKB2W7.js";
3
+ } from "./chunk-XUGOP4Z4.js";
4
4
  import {
5
5
  AbstractQuery,
6
6
  ExpressionBuilder,
@@ -15,7 +15,7 @@ import {
15
15
  staticParam,
16
16
  toStaticParam,
17
17
  valita_exports
18
- } from "./chunk-43L7S6AU.js";
18
+ } from "./chunk-4XUYLHLN.js";
19
19
 
20
20
  // ../zero-protocol/src/custom-queries.ts
21
21
  var transformRequestBodySchema = valita_exports.array(
@@ -337,4 +337,4 @@ export {
337
337
  querify,
338
338
  namedQuery
339
339
  };
340
- //# sourceMappingURL=chunk-ODTJYJ37.js.map
340
+ //# sourceMappingURL=chunk-7VV3XSWG.js.map
@@ -126,7 +126,7 @@ import {
126
126
  withWrite,
127
127
  withWriteNoImplicitCommit,
128
128
  wrapIterable
129
- } from "./chunk-43L7S6AU.js";
129
+ } from "./chunk-4XUYLHLN.js";
130
130
  import {
131
131
  __export
132
132
  } from "./chunk-424PT5DM.js";
@@ -7782,6 +7782,7 @@ var ZeroContext = class {
7782
7782
  #addCustomQuery;
7783
7783
  #updateQuery;
7784
7784
  #updateCustomQuery;
7785
+ #flushQueryChanges;
7785
7786
  #batchViewUpdates;
7786
7787
  #commitListeners = /* @__PURE__ */ new Set();
7787
7788
  #slowMaterializeThreshold;
@@ -7792,7 +7793,7 @@ var ZeroContext = class {
7792
7793
  * "complete" once the server has sent back the query result.
7793
7794
  */
7794
7795
  defaultQueryComplete = false;
7795
- constructor(lc, mainSources, addQuery, addCustomQuery, updateQuery, updateCustomQuery, batchViewUpdates, slowMaterializeThreshold, assertValidRunOptions3) {
7796
+ constructor(lc, mainSources, addQuery, addCustomQuery, updateQuery, updateCustomQuery, flushQueryChanges, batchViewUpdates, slowMaterializeThreshold, assertValidRunOptions3) {
7796
7797
  this.#mainSources = mainSources;
7797
7798
  this.#addQuery = addQuery;
7798
7799
  this.#updateQuery = updateQuery;
@@ -7802,6 +7803,7 @@ var ZeroContext = class {
7802
7803
  this.#slowMaterializeThreshold = slowMaterializeThreshold;
7803
7804
  this.assertValidRunOptions = assertValidRunOptions3;
7804
7805
  this.#addCustomQuery = addCustomQuery;
7806
+ this.#flushQueryChanges = flushQueryChanges;
7805
7807
  }
7806
7808
  getSource(name) {
7807
7809
  return this.#mainSources.getSource(name);
@@ -7823,6 +7825,9 @@ var ZeroContext = class {
7823
7825
  updateCustomQuery(customQueryID, ttl) {
7824
7826
  this.#updateCustomQuery(customQueryID.name, customQueryID.args, ttl);
7825
7827
  }
7828
+ flushQueryChanges() {
7829
+ this.#flushQueryChanges();
7830
+ }
7826
7831
  onQueryMaterialized(hash, ast, duration) {
7827
7832
  if (this.#slowMaterializeThreshold !== void 0 && duration > this.#slowMaterializeThreshold) {
7828
7833
  this.#lc.warn?.(
@@ -8186,6 +8191,7 @@ function makeSchemaQuery(lc, schema, ivmBranch, slowMaterializeThreshold) {
8186
8191
  () => emptyFunction,
8187
8192
  emptyFunction,
8188
8193
  emptyFunction,
8194
+ emptyFunction,
8189
8195
  (applyViewUpdates) => applyViewUpdates(),
8190
8196
  slowMaterializeThreshold,
8191
8197
  assertValidRunOptions
@@ -8533,7 +8539,7 @@ function makeMessage(message, context, logLevel) {
8533
8539
  }
8534
8540
 
8535
8541
  // ../zero-client/src/client/version.ts
8536
- var version2 = "0.22.2025070200";
8542
+ var version2 = "0.22.2025070701";
8537
8543
 
8538
8544
  // ../zero-client/src/client/log-options.ts
8539
8545
  var LevelFilterLogSink = class {
@@ -9022,13 +9028,17 @@ var QueryManager = class {
9022
9028
  #recentQueries = /* @__PURE__ */ new Set();
9023
9029
  #gotQueries = /* @__PURE__ */ new Set();
9024
9030
  #mutationTracker;
9031
+ #pendingQueryChanges = [];
9032
+ #queryChangeThrottleMs;
9025
9033
  #pendingRemovals = [];
9026
- constructor(mutationTracker, clientID, tables, send2, experimentalWatch, recentQueriesMaxSize) {
9034
+ #batchTimer;
9035
+ constructor(mutationTracker, clientID, tables, send2, experimentalWatch, recentQueriesMaxSize, queryChangeThrottleMs) {
9027
9036
  this.#clientID = clientID;
9028
9037
  this.#clientToServer = clientToServer(tables);
9029
9038
  this.#recentQueriesMaxSize = recentQueriesMaxSize;
9030
9039
  this.#send = send2;
9031
9040
  this.#mutationTracker = mutationTracker;
9041
+ this.#queryChangeThrottleMs = queryChangeThrottleMs;
9032
9042
  this.#mutationTracker.onAllMutationsConfirmed(() => {
9033
9043
  if (this.#pendingRemovals.length === 0) {
9034
9044
  return;
@@ -9167,21 +9177,14 @@ var QueryManager = class {
9167
9177
  ttl
9168
9178
  };
9169
9179
  this.#queries.set(queryId, entry);
9170
- this.#send([
9171
- "changeDesiredQueries",
9172
- {
9173
- desiredQueriesPatch: [
9174
- {
9175
- op: "put",
9176
- hash: queryId,
9177
- ast: normalized,
9178
- name,
9179
- args,
9180
- ttl: parseTTL(ttl)
9181
- }
9182
- ]
9183
- }
9184
- ]);
9180
+ this.#queueQueryChange({
9181
+ op: "put",
9182
+ hash: queryId,
9183
+ ast: normalized,
9184
+ name,
9185
+ args,
9186
+ ttl: parseTTL(ttl)
9187
+ });
9185
9188
  } else {
9186
9189
  ++entry.count;
9187
9190
  this.#updateEntry(entry, queryId, ttl);
@@ -9221,21 +9224,41 @@ var QueryManager = class {
9221
9224
  #updateEntry(entry, hash, ttl) {
9222
9225
  if (compareTTL(ttl, entry.ttl) > 0) {
9223
9226
  entry.ttl = ttl;
9227
+ this.#queueQueryChange({
9228
+ op: "put",
9229
+ hash,
9230
+ ast: entry.normalized,
9231
+ name: entry.name,
9232
+ args: entry.args,
9233
+ ttl: parseTTL(ttl)
9234
+ });
9235
+ }
9236
+ }
9237
+ #queueQueryChange(op) {
9238
+ this.#pendingQueryChanges.push(op);
9239
+ this.#scheduleBatch();
9240
+ }
9241
+ #scheduleBatch() {
9242
+ if (this.#batchTimer === void 0) {
9243
+ this.#batchTimer = setTimeout(
9244
+ () => this.flushBatch(),
9245
+ this.#queryChangeThrottleMs
9246
+ );
9247
+ }
9248
+ }
9249
+ flushBatch() {
9250
+ if (this.#batchTimer !== void 0) {
9251
+ clearTimeout(this.#batchTimer);
9252
+ this.#batchTimer = void 0;
9253
+ }
9254
+ if (this.#pendingQueryChanges.length > 0) {
9224
9255
  this.#send([
9225
9256
  "changeDesiredQueries",
9226
9257
  {
9227
- desiredQueriesPatch: [
9228
- {
9229
- op: "put",
9230
- hash,
9231
- ast: entry.normalized,
9232
- name: entry.name,
9233
- args: entry.args,
9234
- ttl: parseTTL(ttl)
9235
- }
9236
- ]
9258
+ desiredQueriesPatch: [...this.#pendingQueryChanges]
9237
9259
  }
9238
9260
  ]);
9261
+ this.#pendingQueryChanges.length = 0;
9239
9262
  }
9240
9263
  }
9241
9264
  #remove(entry, astHash, gotCallback) {
@@ -9251,12 +9274,7 @@ var QueryManager = class {
9251
9274
  assert(lruAstHash);
9252
9275
  this.#queries.delete(lruAstHash);
9253
9276
  this.#recentQueries.delete(lruAstHash);
9254
- this.#send([
9255
- "changeDesiredQueries",
9256
- {
9257
- desiredQueriesPatch: [{ op: "del", hash: lruAstHash }]
9258
- }
9259
- ]);
9277
+ this.#queueQueryChange({ op: "del", hash: lruAstHash });
9260
9278
  }
9261
9279
  }
9262
9280
  }
@@ -9631,29 +9649,29 @@ function mergePokes(pokeBuffer, schema, serverToClient2) {
9631
9649
  for (const [clientID, queriesPatch] of Object.entries(
9632
9650
  pokePart.desiredQueriesPatches
9633
9651
  )) {
9634
- mergedPatch.push(
9635
- ...queriesPatch.map(
9636
- (op) => queryPatchOpToReplicachePatchOp(
9652
+ for (const op of queriesPatch) {
9653
+ mergedPatch.push(
9654
+ queryPatchOpToReplicachePatchOp(
9637
9655
  op,
9638
9656
  (hash) => toDesiredQueriesKey(clientID, hash)
9639
9657
  )
9640
- )
9641
- );
9658
+ );
9659
+ }
9642
9660
  }
9643
9661
  }
9644
9662
  if (pokePart.gotQueriesPatch) {
9645
- mergedPatch.push(
9646
- ...pokePart.gotQueriesPatch.map(
9647
- (op) => queryPatchOpToReplicachePatchOp(op, toGotQueriesKey)
9648
- )
9649
- );
9663
+ for (const op of pokePart.gotQueriesPatch) {
9664
+ mergedPatch.push(
9665
+ queryPatchOpToReplicachePatchOp(op, toGotQueriesKey)
9666
+ );
9667
+ }
9650
9668
  }
9651
9669
  if (pokePart.rowsPatch) {
9652
- mergedPatch.push(
9653
- ...pokePart.rowsPatch.map(
9654
- (p) => rowsPatchOpToReplicachePatchOp(p, schema, serverToClient2)
9655
- )
9656
- );
9670
+ for (const p of pokePart.rowsPatch) {
9671
+ mergedPatch.push(
9672
+ rowsPatchOpToReplicachePatchOp(p, schema, serverToClient2)
9673
+ );
9674
+ }
9657
9675
  }
9658
9676
  }
9659
9677
  }
@@ -9676,12 +9694,13 @@ function queryPatchOpToReplicachePatchOp(op, toKey) {
9676
9694
  key: toKey(op.hash)
9677
9695
  };
9678
9696
  case "put":
9679
- default:
9680
9697
  return {
9681
9698
  op: "put",
9682
9699
  key: toKey(op.hash),
9683
9700
  value: null
9684
9701
  };
9702
+ default:
9703
+ unreachable(op);
9685
9704
  }
9686
9705
  }
9687
9706
  function rowsPatchOpToReplicachePatchOp(op, schema, serverToClient2) {
@@ -9721,7 +9740,7 @@ function rowsPatchOpToReplicachePatchOp(op, schema, serverToClient2) {
9721
9740
  constrain: serverToClient2.columns(op.tableName, op.constrain)
9722
9741
  };
9723
9742
  default:
9724
- throw new Error("to be implemented");
9743
+ unreachable(op);
9725
9744
  }
9726
9745
  }
9727
9746
  function rafFallback(callback) {
@@ -9802,6 +9821,7 @@ var DEFAULT_DISCONNECT_HIDDEN_DELAY_MS = 5e3;
9802
9821
  var CONNECT_TIMEOUT_MS = 1e4;
9803
9822
  var CHECK_CONNECTIVITY_ON_ERROR_FREQUENCY = 6;
9804
9823
  var NULL_LAST_MUTATION_ID_SENT = { clientID: "", id: -1 };
9824
+ var DEFAULT_QUERY_CHANGE_THROTTLE_MS = 10;
9805
9825
  function convertOnUpdateNeededReason(reason) {
9806
9826
  return { type: reason.type };
9807
9827
  }
@@ -10069,6 +10089,7 @@ var Zero = class _Zero {
10069
10089
  (queryName, queryArgs, ttl, gotCallback) => this.#queryManager.addCustom(queryName, queryArgs, ttl, gotCallback),
10070
10090
  (ast, ttl) => this.#queryManager.updateLegacy(ast, ttl),
10071
10091
  (name, args, ttl) => this.#queryManager.updateCustom(name, args, ttl),
10092
+ () => this.#queryManager.flushBatch(),
10072
10093
  batchViewUpdates,
10073
10094
  slowMaterializeThreshold,
10074
10095
  assertValidRunOptions2
@@ -10157,7 +10178,8 @@ var Zero = class _Zero {
10157
10178
  schema.tables,
10158
10179
  (msg) => this.#send(msg),
10159
10180
  rep.experimentalWatch.bind(rep),
10160
- maxRecentQueries
10181
+ maxRecentQueries,
10182
+ options.queryChangeThrottleMs ?? DEFAULT_QUERY_CHANGE_THROTTLE_MS
10161
10183
  );
10162
10184
  this.#clientToServer = clientToServer(schema.tables);
10163
10185
  this.#deleteClientsManager = new DeleteClientsManager(
@@ -11078,7 +11100,7 @@ var Zero = class _Zero {
11078
11100
  */
11079
11101
  async inspect() {
11080
11102
  BUNDLE_SIZE: {
11081
- const m = await import("./inspector-WSEHHWA3.js");
11103
+ const m = await import("./inspector-DIXW3TGL.js");
11082
11104
  return m.newInspector(this.#rep, this.#schema, async () => {
11083
11105
  await this.#connectResolver.promise;
11084
11106
  return this.#socket;
@@ -11216,4 +11238,4 @@ export {
11216
11238
  update_needed_reason_type_enum_exports,
11217
11239
  Zero
11218
11240
  };
11219
- //# sourceMappingURL=chunk-HTNKB2W7.js.map
11241
+ //# sourceMappingURL=chunk-XUGOP4Z4.js.map