@rocicorp/zero 0.8.2024121203 → 0.9.2024121900

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 (145) hide show
  1. package/out/advanced.js +1 -1
  2. package/out/{chunk-5CHRDZZ4.js → chunk-3L5FRWGX.js} +100 -72
  3. package/out/{chunk-5CHRDZZ4.js.map → chunk-3L5FRWGX.js.map} +4 -4
  4. package/out/{chunk-6HXO6VMP.js → chunk-Y6OVFUGE.js} +12 -10
  5. package/out/chunk-Y6OVFUGE.js.map +7 -0
  6. package/out/replicache/src/set-interval-with-signal.d.ts.map +1 -1
  7. package/out/shared/src/set-utils.d.ts +20 -5
  8. package/out/shared/src/set-utils.d.ts.map +1 -1
  9. package/out/shared/src/set-utils.js +17 -7
  10. package/out/shared/src/set-utils.js.map +1 -1
  11. package/out/shared/src/sleep.d.ts.map +1 -1
  12. package/out/shared/src/sleep.js +5 -1
  13. package/out/shared/src/sleep.js.map +1 -1
  14. package/out/solid.js +2 -2
  15. package/out/zero/src/zero-cache-dev.js +5 -8
  16. package/out/zero/src/zero-cache-dev.js.map +1 -1
  17. package/out/zero-cache/src/auth/jwt.d.ts +5 -0
  18. package/out/zero-cache/src/auth/jwt.d.ts.map +1 -0
  19. package/out/zero-cache/src/auth/jwt.js +37 -0
  20. package/out/zero-cache/src/auth/jwt.js.map +1 -0
  21. package/out/zero-cache/src/auth/write-authorizer.d.ts +3 -3
  22. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  23. package/out/zero-cache/src/auth/write-authorizer.js +9 -8
  24. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  25. package/out/zero-cache/src/config/zero-config.d.ts +188 -4
  26. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  27. package/out/zero-cache/src/config/zero-config.js +48 -4
  28. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  29. package/out/zero-cache/src/db/queries.d.ts +24 -0
  30. package/out/zero-cache/src/db/queries.d.ts.map +1 -0
  31. package/out/zero-cache/src/db/queries.js +60 -0
  32. package/out/zero-cache/src/db/queries.js.map +1 -0
  33. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  34. package/out/zero-cache/src/server/life-cycle.js +1 -3
  35. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  36. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  37. package/out/zero-cache/src/server/main.js +4 -5
  38. package/out/zero-cache/src/server/main.js.map +1 -1
  39. package/out/zero-cache/src/server/multi/config.d.ts +18 -4
  40. package/out/zero-cache/src/server/multi/config.d.ts.map +1 -1
  41. package/out/zero-cache/src/server/multi/main.js +2 -2
  42. package/out/zero-cache/src/server/multi/main.js.map +1 -1
  43. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  44. package/out/zero-cache/src/server/syncer.js +1 -1
  45. package/out/zero-cache/src/server/syncer.js.map +1 -1
  46. package/out/zero-cache/src/services/change-streamer/pg/change-source.d.ts.map +1 -1
  47. package/out/zero-cache/src/services/change-streamer/pg/change-source.js +9 -7
  48. package/out/zero-cache/src/services/change-streamer/pg/change-source.js.map +1 -1
  49. package/out/zero-cache/src/services/dispatcher/{dispatcher.d.ts → sync-dispatcher.d.ts} +3 -6
  50. package/out/zero-cache/src/services/dispatcher/sync-dispatcher.d.ts.map +1 -0
  51. package/out/zero-cache/src/services/dispatcher/{dispatcher.js → sync-dispatcher.js} +7 -12
  52. package/out/zero-cache/src/services/dispatcher/sync-dispatcher.js.map +1 -0
  53. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
  54. package/out/zero-cache/src/services/view-syncer/client-handler.js +2 -0
  55. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  56. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +6 -4
  57. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  58. package/out/zero-cache/src/services/view-syncer/cvr-store.js +140 -63
  59. package/out/zero-cache/src/services/view-syncer/cvr-store.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 +29 -6
  63. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  64. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  65. package/out/zero-cache/src/services/view-syncer/snapshotter.js +5 -5
  66. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  67. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  68. package/out/zero-cache/src/services/view-syncer/view-syncer.js +50 -24
  69. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  70. package/out/zero-cache/src/types/error-for-client.d.ts +9 -2
  71. package/out/zero-cache/src/types/error-for-client.d.ts.map +1 -1
  72. package/out/zero-cache/src/types/error-for-client.js +14 -3
  73. package/out/zero-cache/src/types/error-for-client.js.map +1 -1
  74. package/out/zero-cache/src/types/lite.d.ts.map +1 -1
  75. package/out/zero-cache/src/types/lite.js +1 -0
  76. package/out/zero-cache/src/types/lite.js.map +1 -1
  77. package/out/zero-cache/src/types/pg.d.ts.map +1 -1
  78. package/out/zero-cache/src/types/pg.js +5 -0
  79. package/out/zero-cache/src/types/pg.js.map +1 -1
  80. package/out/zero-cache/src/workers/connection.js +2 -2
  81. package/out/zero-cache/src/workers/connection.js.map +1 -1
  82. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  83. package/out/zero-cache/src/workers/replicator.js +2 -0
  84. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  85. package/out/zero-cache/src/workers/syncer.d.ts +0 -2
  86. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  87. package/out/zero-cache/src/workers/syncer.js +7 -15
  88. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  89. package/out/zero-client/src/client/options.d.ts +7 -0
  90. package/out/zero-client/src/client/options.d.ts.map +1 -1
  91. package/out/zero-client/src/client/query-manager.d.ts +1 -1
  92. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  93. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  94. package/out/zero-client/src/mod.d.ts +6 -5
  95. package/out/zero-client/src/mod.d.ts.map +1 -1
  96. package/out/zero-protocol/src/data.d.ts +1 -1
  97. package/out/zero-protocol/src/data.d.ts.map +1 -1
  98. package/out/zero-protocol/src/data.js +1 -1
  99. package/out/zero-protocol/src/data.js.map +1 -1
  100. package/out/zero-protocol/src/down.d.ts +1 -1
  101. package/out/zero-protocol/src/poke.d.ts +2 -2
  102. package/out/zero-protocol/src/push.d.ts +21 -21
  103. package/out/zero-protocol/src/row-patch.d.ts +2 -2
  104. package/out/zero-protocol/src/up.d.ts +3 -3
  105. package/out/zero-schema/src/column.d.ts +27 -0
  106. package/out/zero-schema/src/column.d.ts.map +1 -0
  107. package/out/zero-schema/src/table-schema.d.ts +0 -28
  108. package/out/zero-schema/src/table-schema.d.ts.map +1 -1
  109. package/out/zero-schema/src/table-schema.js +0 -39
  110. package/out/zero-schema/src/table-schema.js.map +1 -1
  111. package/out/zero.js +4 -4
  112. package/out/zql/src/ivm/constraint.js +2 -2
  113. package/out/zql/src/ivm/constraint.js.map +1 -1
  114. package/out/zql/src/ivm/data.d.ts.map +1 -1
  115. package/out/zql/src/ivm/data.js +2 -3
  116. package/out/zql/src/ivm/data.js.map +1 -1
  117. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  118. package/out/zql/src/ivm/exists.js +5 -1
  119. package/out/zql/src/ivm/exists.js.map +1 -1
  120. package/out/zql/src/ivm/memory-source.d.ts +2 -2
  121. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  122. package/out/zql/src/ivm/view-apply-change.js +13 -9
  123. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  124. package/out/zql/src/ivm/view.d.ts +3 -3
  125. package/out/zql/src/ivm/view.d.ts.map +1 -1
  126. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  127. package/out/zql/src/query/query-impl.js.map +1 -1
  128. package/out/zql/src/query/query.d.ts +5 -5
  129. package/out/zql/src/query/query.d.ts.map +1 -1
  130. package/out/zqlite/src/db.d.ts +3 -2
  131. package/out/zqlite/src/db.d.ts.map +1 -1
  132. package/out/zqlite/src/db.js +25 -13
  133. package/out/zqlite/src/db.js.map +1 -1
  134. package/out/zqlite/src/runtime-debug.d.ts +17 -0
  135. package/out/zqlite/src/runtime-debug.d.ts.map +1 -0
  136. package/out/zqlite/src/runtime-debug.js +29 -0
  137. package/out/zqlite/src/runtime-debug.js.map +1 -0
  138. package/out/zqlite/src/table-source.d.ts +5 -5
  139. package/out/zqlite/src/table-source.d.ts.map +1 -1
  140. package/out/zqlite/src/table-source.js +21 -11
  141. package/out/zqlite/src/table-source.js.map +1 -1
  142. package/package.json +2 -1
  143. package/out/chunk-6HXO6VMP.js.map +0 -7
  144. package/out/zero-cache/src/services/dispatcher/dispatcher.d.ts.map +0 -1
  145. package/out/zero-cache/src/services/dispatcher/dispatcher.js.map +0 -1
package/out/advanced.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-ULOTOBTC.js";
2
2
  import {
3
3
  applyChange
4
- } from "./chunk-6HXO6VMP.js";
4
+ } from "./chunk-Y6OVFUGE.js";
5
5
  import "./chunk-F5QR3K72.js";
6
6
  export {
7
7
  applyChange
@@ -14,7 +14,7 @@ import {
14
14
  must,
15
15
  throwInvalidType,
16
16
  unreachable
17
- } from "./chunk-6HXO6VMP.js";
17
+ } from "./chunk-Y6OVFUGE.js";
18
18
  import {
19
19
  __export,
20
20
  __reExport
@@ -1036,6 +1036,10 @@ import { resolver as resolver3 } from "@rocicorp/resolver";
1036
1036
  var promiseVoid2 = Promise.resolve();
1037
1037
  var promiseNever = new Promise(() => void 0);
1038
1038
  function sleep(ms, signal) {
1039
+ const newAbortError = () => new AbortError("Aborted");
1040
+ if (signal?.aborted) {
1041
+ return Promise.reject(newAbortError());
1042
+ }
1039
1043
  if (ms === 0) {
1040
1044
  return promiseVoid2;
1041
1045
  }
@@ -1044,7 +1048,7 @@ function sleep(ms, signal) {
1044
1048
  if (signal) {
1045
1049
  handleAbort = () => {
1046
1050
  clearTimeout(id);
1047
- reject(new AbortError("Aborted"));
1051
+ reject(newAbortError());
1048
1052
  };
1049
1053
  signal.addEventListener("abort", handleAbort, { once: true });
1050
1054
  }
@@ -7748,10 +7752,12 @@ async function throttle(timeMs, abortSignal) {
7748
7752
 
7749
7753
  // ../replicache/src/set-interval-with-signal.ts
7750
7754
  function setIntervalWithSignal(fn, ms, signal) {
7751
- const interval = setInterval(fn, ms);
7752
- signal.addEventListener("abort", () => {
7753
- clearInterval(interval);
7754
- });
7755
+ if (!signal.aborted) {
7756
+ const interval = setInterval(fn, ms);
7757
+ signal.addEventListener("abort", () => {
7758
+ clearInterval(interval);
7759
+ });
7760
+ }
7755
7761
  }
7756
7762
 
7757
7763
  // ../replicache/src/subscriptions.ts
@@ -9291,46 +9297,53 @@ function getKVStoreProvider(lc, kvStore) {
9291
9297
  // ../replicache/src/mod.ts
9292
9298
  import { consoleLogSink as consoleLogSink3 } from "@rocicorp/logger";
9293
9299
 
9300
+ // ../zero-schema/src/column.ts
9301
+ var column_exports = {};
9302
+ __export(column_exports, {
9303
+ boolean: () => boolean3,
9304
+ enumeration: () => enumeration,
9305
+ json: () => json,
9306
+ number: () => number4,
9307
+ string: () => string7
9308
+ });
9309
+ function string7(optional = false) {
9310
+ return {
9311
+ type: "string",
9312
+ optional,
9313
+ customType: null
9314
+ };
9315
+ }
9316
+ function number4(optional = false) {
9317
+ return {
9318
+ type: "number",
9319
+ optional,
9320
+ customType: null
9321
+ };
9322
+ }
9323
+ function boolean3(optional = false) {
9324
+ return {
9325
+ type: "boolean",
9326
+ optional,
9327
+ customType: null
9328
+ };
9329
+ }
9330
+ function json(optional = false) {
9331
+ return {
9332
+ type: "json",
9333
+ optional,
9334
+ customType: null
9335
+ };
9336
+ }
9337
+ function enumeration(optional = false) {
9338
+ return {
9339
+ type: "string",
9340
+ kind: "enum",
9341
+ customType: null,
9342
+ optional
9343
+ };
9344
+ }
9345
+
9294
9346
  // ../zero-schema/src/table-schema.ts
9295
- var column = {
9296
- string(optional = false) {
9297
- return {
9298
- type: "string",
9299
- optional,
9300
- customType: null
9301
- };
9302
- },
9303
- number(optional = false) {
9304
- return {
9305
- type: "number",
9306
- optional,
9307
- customType: null
9308
- };
9309
- },
9310
- boolean(optional = false) {
9311
- return {
9312
- type: "boolean",
9313
- optional,
9314
- customType: null
9315
- };
9316
- },
9317
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9318
- json(optional = false) {
9319
- return {
9320
- type: "json",
9321
- optional,
9322
- customType: null
9323
- };
9324
- },
9325
- enumeration(optional = false) {
9326
- return {
9327
- type: "string",
9328
- kind: "enum",
9329
- customType: null,
9330
- optional
9331
- };
9332
- }
9333
- };
9334
9347
  function createTableSchema(schema) {
9335
9348
  return schema;
9336
9349
  }
@@ -9416,8 +9429,8 @@ function normalizeColumns(columns, primaryKey) {
9416
9429
  );
9417
9430
  }
9418
9431
  }
9419
- for (const [name, column2] of sortedEntries(columns)) {
9420
- rv[name] = normalizeColumn(column2);
9432
+ for (const [name, column] of sortedEntries(columns)) {
9433
+ rv[name] = normalizeColumn(column);
9421
9434
  }
9422
9435
  return rv;
9423
9436
  }
@@ -9698,7 +9711,7 @@ function areEqual(arr1, arr2) {
9698
9711
 
9699
9712
  // ../zero-protocol/src/data.ts
9700
9713
  var valueSchema = valita_exports.union(jsonSchema, valita_exports.undefined());
9701
- var rowSchema = valita_exports.record(valueSchema);
9714
+ var rowSchema = readonlyRecord(valueSchema);
9702
9715
 
9703
9716
  // ../zero-protocol/src/ast.ts
9704
9717
  var selectorSchema = valita_exports.string();
@@ -10008,9 +10021,7 @@ function makeComparator(order, reverse) {
10008
10021
  };
10009
10022
  }
10010
10023
  function valuesEqual(a, b) {
10011
- a = normalizeUndefined(a);
10012
- b = normalizeUndefined(b);
10013
- if (a === null || b === null) {
10024
+ if (a == null || b == null) {
10014
10025
  return false;
10015
10026
  }
10016
10027
  return a === b;
@@ -10131,7 +10142,9 @@ var Exists = class {
10131
10142
  case "remove": {
10132
10143
  let size = this.#getSize(change.row);
10133
10144
  if (size !== void 0) {
10134
- assert(size > 0);
10145
+ if (size === 0) {
10146
+ return;
10147
+ }
10135
10148
  size--;
10136
10149
  this.#setCachedSize(change.row, size);
10137
10150
  this.#setSize(change.row, size);
@@ -10665,8 +10678,8 @@ var Join = class {
10665
10678
  }
10666
10679
  };
10667
10680
  function makeStorageKeyForValues(values) {
10668
- const json = JSON.stringify(["pKeySet", ...values]);
10669
- return json.substring(1, json.length - 1) + ",";
10681
+ const json2 = JSON.stringify(["pKeySet", ...values]);
10682
+ return json2.substring(1, json2.length - 1) + ",";
10670
10683
  }
10671
10684
  function makeStorageKeyPrefix(row, key) {
10672
10685
  return makeStorageKeyForValues(key.map((k) => row[k]));
@@ -14365,8 +14378,8 @@ var EmptyBTree = (() => {
14365
14378
 
14366
14379
  // ../zql/src/ivm/constraint.ts
14367
14380
  function constraintMatchesRow(constraint, row) {
14368
- for (const [key, value] of Object.entries(constraint)) {
14369
- if (!valuesEqual(row[key], value)) {
14381
+ for (const key in constraint) {
14382
+ if (!valuesEqual(row[key], constraint[key])) {
14370
14383
  return false;
14371
14384
  }
14372
14385
  }
@@ -15441,7 +15454,7 @@ function makeMessage(message, context, logLevel) {
15441
15454
  }
15442
15455
 
15443
15456
  // ../zero-client/src/client/version.ts
15444
- var version2 = "0.8.2024121203+dd79de";
15457
+ var version2 = "0.9.2024121900+535718";
15445
15458
 
15446
15459
  // ../zero-client/src/client/log-options.ts
15447
15460
  var LevelFilterLogSink = class {
@@ -15732,9 +15745,12 @@ var QueryManager = class {
15732
15745
  #clientID;
15733
15746
  #send;
15734
15747
  #queries = /* @__PURE__ */ new Map();
15748
+ #recentQueriesMaxSize;
15749
+ #recentQueries = /* @__PURE__ */ new Set();
15735
15750
  #gotQueries = /* @__PURE__ */ new Set();
15736
- constructor(clientID, send2, experimentalWatch) {
15751
+ constructor(clientID, send2, experimentalWatch, recentQueriesMaxSize) {
15737
15752
  this.#clientID = clientID;
15753
+ this.#recentQueriesMaxSize = recentQueriesMaxSize;
15738
15754
  this.#send = send2;
15739
15755
  experimentalWatch(
15740
15756
  (diff2) => {
@@ -15815,6 +15831,7 @@ var QueryManager = class {
15815
15831
  const normalized = normalizeAST(ast);
15816
15832
  const astHash = hashOfAST(normalized);
15817
15833
  let entry = this.#queries.get(astHash);
15834
+ this.#recentQueries.delete(astHash);
15818
15835
  if (!entry) {
15819
15836
  entry = {
15820
15837
  normalized,
@@ -15843,22 +15860,31 @@ var QueryManager = class {
15843
15860
  return;
15844
15861
  }
15845
15862
  removed = true;
15846
- this.#remove(astHash);
15863
+ this.#remove(astHash, gotCallback);
15847
15864
  };
15848
15865
  }
15849
- #remove(astHash) {
15866
+ #remove(astHash, gotCallback) {
15850
15867
  const entry = must(this.#queries.get(astHash));
15868
+ if (gotCallback) {
15869
+ const index = entry.gotCallbacks.indexOf(gotCallback);
15870
+ entry.gotCallbacks.splice(index, 1);
15871
+ }
15851
15872
  --entry.count;
15852
15873
  if (entry.count === 0) {
15853
- this.#queries.delete(astHash);
15854
- this.#send([
15855
- "changeDesiredQueries",
15856
- {
15857
- desiredQueriesPatch: [{ op: "del", hash: astHash }]
15858
- }
15859
- ]);
15874
+ this.#recentQueries.add(astHash);
15875
+ if (this.#recentQueries.size > this.#recentQueriesMaxSize) {
15876
+ const lruAstHash = this.#recentQueries.values().next().value;
15877
+ assert(lruAstHash);
15878
+ this.#queries.delete(lruAstHash);
15879
+ this.#recentQueries.delete(lruAstHash);
15880
+ this.#send([
15881
+ "changeDesiredQueries",
15882
+ {
15883
+ desiredQueriesPatch: [{ op: "del", hash: lruAstHash }]
15884
+ }
15885
+ ]);
15886
+ }
15860
15887
  }
15861
- return true;
15862
15888
  }
15863
15889
  };
15864
15890
 
@@ -16440,7 +16466,8 @@ var Zero = class {
16440
16466
  hiddenTabDisconnectDelay = DEFAULT_DISCONNECT_HIDDEN_DELAY_MS,
16441
16467
  kvStore = "idb",
16442
16468
  schema,
16443
- batchViewUpdates = (applyViewUpdates) => applyViewUpdates()
16469
+ batchViewUpdates = (applyViewUpdates) => applyViewUpdates(),
16470
+ maxRecentQueries = 0
16444
16471
  } = options;
16445
16472
  if (!userID) {
16446
16473
  throw new Error("ZeroOptions.userID must not be empty.");
@@ -16532,7 +16559,8 @@ var Zero = class {
16532
16559
  this.#queryManager = new QueryManager(
16533
16560
  rep.clientID,
16534
16561
  (msg) => this.#sendChangeDesiredQueries(msg),
16535
- rep.experimentalWatch.bind(rep)
16562
+ rep.experimentalWatch.bind(rep),
16563
+ maxRecentQueries
16536
16564
  );
16537
16565
  this.#zeroContext = new ZeroContext(
16538
16566
  normalizedSchema.tables,
@@ -17435,7 +17463,7 @@ export {
17435
17463
  makeIDBName,
17436
17464
  dropDatabase,
17437
17465
  dropAllDatabases,
17438
- column,
17466
+ column_exports,
17439
17467
  createTableSchema,
17440
17468
  ANYONE_CAN,
17441
17469
  NOBODY_CAN,
@@ -17444,4 +17472,4 @@ export {
17444
17472
  escapeLike,
17445
17473
  Zero
17446
17474
  };
17447
- //# sourceMappingURL=chunk-5CHRDZZ4.js.map
17475
+ //# sourceMappingURL=chunk-3L5FRWGX.js.map