@rocicorp/zero 0.25.10-canary.9 → 0.25.11-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/out/replicache/src/persist/refresh.d.ts.map +1 -1
  2. package/out/replicache/src/persist/refresh.js +0 -8
  3. package/out/replicache/src/persist/refresh.js.map +1 -1
  4. package/out/replicache/src/process-scheduler.d.ts +23 -0
  5. package/out/replicache/src/process-scheduler.d.ts.map +1 -1
  6. package/out/replicache/src/process-scheduler.js +50 -1
  7. package/out/replicache/src/process-scheduler.js.map +1 -1
  8. package/out/replicache/src/replicache-impl.d.ts +8 -0
  9. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  10. package/out/replicache/src/replicache-impl.js +10 -1
  11. package/out/replicache/src/replicache-impl.js.map +1 -1
  12. package/out/zero/package.json.js +1 -1
  13. package/out/zero-cache/src/custom/fetch.d.ts +3 -3
  14. package/out/zero-cache/src/custom/fetch.d.ts.map +1 -1
  15. package/out/zero-cache/src/custom/fetch.js +116 -76
  16. package/out/zero-cache/src/custom/fetch.js.map +1 -1
  17. package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
  18. package/out/zero-cache/src/custom-queries/transform-query.js +0 -1
  19. package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
  20. package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
  21. package/out/zero-cache/src/server/anonymous-otel-start.js +1 -0
  22. package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
  23. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  24. package/out/zero-cache/src/server/change-streamer.js +6 -1
  25. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  26. package/out/zero-cache/src/server/inspector-delegate.d.ts.map +1 -1
  27. package/out/zero-cache/src/server/inspector-delegate.js +2 -2
  28. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  29. package/out/zero-cache/src/server/priority-op.d.ts +8 -0
  30. package/out/zero-cache/src/server/priority-op.d.ts.map +1 -0
  31. package/out/zero-cache/src/server/priority-op.js +29 -0
  32. package/out/zero-cache/src/server/priority-op.js.map +1 -0
  33. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  34. package/out/zero-cache/src/server/syncer.js +9 -2
  35. package/out/zero-cache/src/server/syncer.js.map +1 -1
  36. package/out/zero-cache/src/services/analyze.js +1 -1
  37. package/out/zero-cache/src/services/analyze.js.map +1 -1
  38. package/out/zero-cache/src/services/change-source/replica-schema.d.ts.map +1 -1
  39. package/out/zero-cache/src/services/change-source/replica-schema.js +5 -1
  40. package/out/zero-cache/src/services/change-source/replica-schema.js.map +1 -1
  41. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +1 -1
  42. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  43. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +10 -6
  44. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  45. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +2 -2
  46. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  47. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  48. package/out/zero-cache/src/services/mutagen/pusher.js +1 -3
  49. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  50. package/out/zero-cache/src/services/replicator/replication-status.d.ts +2 -1
  51. package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
  52. package/out/zero-cache/src/services/replicator/replication-status.js +7 -3
  53. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  54. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  55. package/out/zero-cache/src/services/view-syncer/cvr-store.js +60 -22
  56. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  57. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  58. package/out/zero-cache/src/services/view-syncer/cvr.js +2 -0
  59. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  60. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +1 -1
  61. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  62. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +2 -2
  63. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  64. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts +1 -1
  65. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  66. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +22 -11
  67. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  68. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +2 -1
  69. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  70. package/out/zero-cache/src/services/view-syncer/view-syncer.js +80 -52
  71. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  72. package/out/zero-cache/src/types/error-with-level.d.ts +1 -1
  73. package/out/zero-cache/src/types/error-with-level.d.ts.map +1 -1
  74. package/out/zero-cache/src/types/error-with-level.js +1 -1
  75. package/out/zero-cache/src/types/error-with-level.js.map +1 -1
  76. package/out/zero-client/src/client/connection-manager.d.ts +3 -0
  77. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  78. package/out/zero-client/src/client/connection-manager.js +10 -3
  79. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  80. package/out/zero-client/src/client/error.d.ts +5 -1
  81. package/out/zero-client/src/client/error.d.ts.map +1 -1
  82. package/out/zero-client/src/client/error.js +3 -3
  83. package/out/zero-client/src/client/error.js.map +1 -1
  84. package/out/zero-client/src/client/options.d.ts +1 -1
  85. package/out/zero-client/src/client/options.js.map +1 -1
  86. package/out/zero-client/src/client/version.js +1 -1
  87. package/out/zero-client/src/client/zero.d.ts +2 -1
  88. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  89. package/out/zero-client/src/client/zero.js +29 -3
  90. package/out/zero-client/src/client/zero.js.map +1 -1
  91. package/package.json +2 -2
@@ -155,7 +155,8 @@ class ViewSyncerService {
155
155
  );
156
156
  #inspectorDelegate;
157
157
  #config;
158
- constructor(config, lc, shard, taskID, clientGroupID, cvrDb, upstreamDb, pipelineDriver, versionChanges, drainCoordinator, slowHydrateThreshold, inspectorDelegate, customQueryTransformer, keepaliveMs = DEFAULT_KEEPALIVE_MS, setTimeoutFn = setTimeout.bind(globalThis)) {
158
+ #runPriorityOp;
159
+ constructor(config, lc, shard, taskID, clientGroupID, cvrDb, upstreamDb, pipelineDriver, versionChanges, drainCoordinator, slowHydrateThreshold, inspectorDelegate, customQueryTransformer, runPriorityOp, keepaliveMs = DEFAULT_KEEPALIVE_MS, setTimeoutFn = setTimeout.bind(globalThis)) {
159
160
  const queryConfig = config.query?.url ? config.query : config.getQueries;
160
161
  this.#config = config;
161
162
  this.id = clientGroupID;
@@ -181,6 +182,7 @@ class ViewSyncerService {
181
182
  () => this.#stateChanges.cancel()
182
183
  );
183
184
  this.#setTimeout = setTimeoutFn;
185
+ this.#runPriorityOp = runPriorityOp;
184
186
  this.keepalive();
185
187
  }
186
188
  #getHeaderOptions(forwardCookie) {
@@ -200,11 +202,14 @@ class ViewSyncerService {
200
202
  if (!this.#stateChanges.active) {
201
203
  this.#lc.debug?.("state changes are inactive");
202
204
  clearTimeout(this.#expiredQueriesTimer);
203
- throw new ProtocolErrorWithLevel({
204
- kind: Rehome,
205
- message: "Reconnect required",
206
- origin: ZeroCache
207
- });
205
+ throw new ProtocolErrorWithLevel(
206
+ {
207
+ kind: Rehome,
208
+ message: "Reconnect required",
209
+ origin: ZeroCache
210
+ },
211
+ "info"
212
+ );
208
213
  }
209
214
  if (await this.#checkForShutdownConditionsInLock()) {
210
215
  this.#lc.info?.(`closing clientGroupID=${this.id}`);
@@ -212,8 +217,12 @@ class ViewSyncerService {
212
217
  return;
213
218
  }
214
219
  if (!this.#cvr) {
215
- this.#lc.debug?.("loading CVR");
216
- this.#cvr = await this.#cvrStore.load(lc, this.#lastConnectTime);
220
+ this.#lc.debug?.("loading cvr");
221
+ this.#cvr = await this.#runPriorityOp(
222
+ lc,
223
+ "loading cvr",
224
+ () => this.#cvrStore.load(lc, this.#lastConnectTime)
225
+ );
217
226
  this.#ttlClock = this.#cvr.ttlClock;
218
227
  this.#ttlClockBase = Date.now();
219
228
  } else {
@@ -269,6 +278,7 @@ class ViewSyncerService {
269
278
  }
270
279
  lc.info?.(`resetting pipelines: ${result.message}`);
271
280
  this.#pipelines.reset(clientSchema);
281
+ this.#pipelinesSynced = false;
272
282
  }
273
283
  const version2 = this.#pipelines.advanceWithoutDiff();
274
284
  const cvrVer = versionString(cvr.version);
@@ -303,8 +313,9 @@ class ViewSyncerService {
303
313
  if (hasExpiredQueries(cvr)) {
304
314
  lc = lc.withContext("method", "#removeExpiredQueries");
305
315
  lc.debug?.("Queries have expired");
306
- await this.#syncQueryPipelineSet(lc, cvr);
307
- this.#pipelinesSynced = true;
316
+ if (this.#pipelinesSynced) {
317
+ await this.#syncQueryPipelineSet(lc, cvr);
318
+ }
308
319
  }
309
320
  this.#scheduleExpireEviction(lc, cvr);
310
321
  };
@@ -440,11 +451,14 @@ class ViewSyncerService {
440
451
  initConnectionMessage,
441
452
  async (lc2, clientID2, msg, cvr) => {
442
453
  if (cvr.clientSchema === null && !msg.clientSchema) {
443
- throw new ProtocolErrorWithLevel({
444
- kind: InvalidConnectionRequest,
445
- message: "The initConnection message for a new client group must include client schema.",
446
- origin: ZeroCache
447
- });
454
+ throw new ProtocolErrorWithLevel(
455
+ {
456
+ kind: InvalidConnectionRequest,
457
+ message: "The initConnection message for a new client group must include client schema.",
458
+ origin: ZeroCache
459
+ },
460
+ "warn"
461
+ );
448
462
  }
449
463
  await this.#handleConfigUpdate(
450
464
  lc2,
@@ -488,19 +502,21 @@ class ViewSyncerService {
488
502
  this.#ttlClockBase = now;
489
503
  return ttlClock;
490
504
  }
491
- async #flushUpdater(lc, updater) {
492
- const now = Date.now();
493
- const ttlClock = this.#getTTLClock(now);
494
- const { cvr, flushed } = await updater.flush(
495
- lc,
496
- this.#lastConnectTime,
497
- now,
498
- ttlClock
499
- );
500
- if (flushed) {
501
- this.#startTTLClockInterval(lc);
502
- }
503
- return cvr;
505
+ #flushUpdater(lc, updater) {
506
+ return this.#runPriorityOp(lc, "flushing cvr", async () => {
507
+ const now = Date.now();
508
+ const ttlClock = this.#getTTLClock(now);
509
+ const { cvr, flushed } = await updater.flush(
510
+ lc,
511
+ this.#lastConnectTime,
512
+ now,
513
+ ttlClock
514
+ );
515
+ if (flushed) {
516
+ this.#startTTLClockInterval(lc);
517
+ }
518
+ return cvr;
519
+ });
504
520
  }
505
521
  #startTTLClockInterval(lc) {
506
522
  this.#stopTTLClockInterval();
@@ -757,11 +773,16 @@ class ViewSyncerService {
757
773
  "Custom/named queries were requested but no `ZERO_QUERY_URL` is configured for Zero Cache."
758
774
  );
759
775
  }
760
- if (this.#customQueryTransformer && customQueries.size > 0) {
761
- const transformedCustomQueries = await this.#customQueryTransformer.transform(
762
- this.#getHeaderOptions(this.#queryConfig.forwardCookies),
763
- customQueries.values(),
764
- this.userQueryURL
776
+ const customQueryTransformer = this.#customQueryTransformer;
777
+ if (customQueryTransformer && customQueries.size > 0) {
778
+ const transformedCustomQueries = await this.#runPriorityOp(
779
+ lc,
780
+ "#hydrateUnchangedQueries transforming custom queries",
781
+ () => customQueryTransformer.transform(
782
+ this.#getHeaderOptions(this.#queryConfig.forwardCookies),
783
+ customQueries.values(),
784
+ this.userQueryURL
785
+ )
765
786
  );
766
787
  this.#processTransformedCustomQueries(
767
788
  lc,
@@ -790,7 +811,7 @@ class ViewSyncerService {
790
811
  transformationHash,
791
812
  transformedAst
792
813
  } of transformedQueries) {
793
- const timer = new TimeSliceTimer();
814
+ const timer = new TimeSliceTimer(lc);
794
815
  let count = 0;
795
816
  await startAsyncSpan(
796
817
  tracer,
@@ -936,16 +957,25 @@ class ViewSyncerService {
936
957
  );
937
958
  }
938
959
  let erroredQueryIDs;
939
- if (this.#customQueryTransformer && customQueries.size > 0) {
960
+ const customQueryTransformer = this.#customQueryTransformer;
961
+ if (customQueryTransformer && customQueries.size > 0) {
940
962
  const transformStart = performance.now();
941
963
  let transformedCustomQueries;
942
964
  try {
943
- transformedCustomQueries = await this.#customQueryTransformer.transform(
944
- this.#getHeaderOptions(true),
945
- customQueries.values(),
946
- this.userQueryURL
965
+ transformedCustomQueries = await this.#runPriorityOp(
966
+ lc,
967
+ "#syncQueryPipelineSet transforming custom queries",
968
+ () => customQueryTransformer.transform(
969
+ this.#getHeaderOptions(true),
970
+ customQueries.values(),
971
+ this.userQueryURL
972
+ )
947
973
  );
948
- this.#queryTransformations.add(1, { result: "success" });
974
+ if (!Array.isArray(transformedCustomQueries) && transformedCustomQueries.kind === TransformFailed) {
975
+ throw new ProtocolErrorWithLevel(transformedCustomQueries, "warn");
976
+ } else {
977
+ this.#queryTransformations.add(1, { result: "success" });
978
+ }
949
979
  } catch (e) {
950
980
  this.#queryTransformations.add(1, { result: "error" });
951
981
  throw e;
@@ -953,12 +983,6 @@ class ViewSyncerService {
953
983
  const transformDuration = (performance.now() - transformStart) / 1e3;
954
984
  this.#queryTransformationTime.record(transformDuration);
955
985
  }
956
- if (!Array.isArray(transformedCustomQueries) && transformedCustomQueries.kind === TransformFailed) {
957
- throw new ProtocolErrorWithLevel(
958
- transformedCustomQueries,
959
- getLogLevel(transformedCustomQueries.kind)
960
- );
961
- }
962
986
  const successfullyTransformed = /* @__PURE__ */ new Map();
963
987
  erroredQueryIDs = this.#processTransformedCustomQueries(
964
988
  lc,
@@ -1133,12 +1157,12 @@ class ViewSyncerService {
1133
1157
  }
1134
1158
  }
1135
1159
  let totalProcessTime = 0;
1136
- const timer = new TimeSliceTimer();
1160
+ const timer = new TimeSliceTimer(lc);
1137
1161
  const pipelines = this.#pipelines;
1138
1162
  const hydrations = this.#hydrations;
1139
1163
  const hydrationTime = this.#hydrationTime;
1140
1164
  const self = this;
1141
- await yieldProcess();
1165
+ await yieldProcess(lc);
1142
1166
  function* generateRowChanges(slowHydrateThreshold) {
1143
1167
  for (const q of addQueries) {
1144
1168
  lc = lc.withContext("hash", q.id).withContext("transformationHash", q.transformationHash);
@@ -1359,7 +1383,7 @@ class ViewSyncerService {
1359
1383
  "pipelines must be initialized (advancePipelines"
1360
1384
  );
1361
1385
  const start = performance.now();
1362
- const timer = new TimeSliceTimer();
1386
+ const timer = new TimeSliceTimer(lc);
1363
1387
  const { version: version2, numChanges, changes } = this.#pipelines.advance(timer);
1364
1388
  lc = lc.withContext("newVersion", version2);
1365
1389
  const updater = new CVRQueryDrivenUpdater(
@@ -1464,7 +1488,7 @@ function createHashToIDs(cvr) {
1464
1488
  return hashToIDs;
1465
1489
  }
1466
1490
  const timeSliceQueue = new Lock();
1467
- function yieldProcess() {
1491
+ function yieldProcess(_lc) {
1468
1492
  return timeSliceQueue.withLock(() => new Promise(setImmediate));
1469
1493
  }
1470
1494
  function contentsAndVersion(row) {
@@ -1552,8 +1576,12 @@ function hasExpiredQueries(cvr) {
1552
1576
  class TimeSliceTimer {
1553
1577
  #total = 0;
1554
1578
  #start = 0;
1579
+ #lc;
1580
+ constructor(lc) {
1581
+ this.#lc = lc;
1582
+ }
1555
1583
  async start() {
1556
- await yieldProcess();
1584
+ await yieldProcess(this.#lc);
1557
1585
  return this.startWithoutYielding();
1558
1586
  }
1559
1587
  startWithoutYielding() {
@@ -1563,7 +1591,7 @@ class TimeSliceTimer {
1563
1591
  }
1564
1592
  async yieldProcess(_msgForTesting) {
1565
1593
  this.#stopLap();
1566
- await yieldProcess();
1594
+ await yieldProcess(this.#lc);
1567
1595
  this.#startLap();
1568
1596
  }
1569
1597
  #startLap() {