@rocicorp/zero 1.10.0-canary.21 → 1.10.0-canary.22

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 (224) hide show
  1. package/out/analyze-query/src/analyze-cli.js +2 -2
  2. package/out/analyze-query/src/analyze-cli.js.map +1 -1
  3. package/out/replicache/src/dag/gc.d.ts.map +1 -1
  4. package/out/replicache/src/dag/gc.js +2 -1
  5. package/out/replicache/src/dag/gc.js.map +1 -1
  6. package/out/replicache/src/dag/invalid-ref-count-error.d.ts +12 -0
  7. package/out/replicache/src/dag/invalid-ref-count-error.d.ts.map +1 -0
  8. package/out/replicache/src/dag/invalid-ref-count-error.js +19 -0
  9. package/out/replicache/src/dag/invalid-ref-count-error.js.map +1 -0
  10. package/out/replicache/src/dag/store-impl.d.ts +12 -2
  11. package/out/replicache/src/dag/store-impl.d.ts.map +1 -1
  12. package/out/replicache/src/dag/store-impl.js +22 -8
  13. package/out/replicache/src/dag/store-impl.js.map +1 -1
  14. package/out/replicache/src/kv/expo-sqlite/store.d.ts.map +1 -1
  15. package/out/replicache/src/kv/expo-sqlite/store.js +1 -1
  16. package/out/replicache/src/kv/expo-sqlite/store.js.map +1 -1
  17. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts +15 -5
  18. package/out/replicache/src/kv/idb-store-with-mem-fallback.d.ts.map +1 -1
  19. package/out/replicache/src/kv/idb-store-with-mem-fallback.js +25 -25
  20. package/out/replicache/src/kv/idb-store-with-mem-fallback.js.map +1 -1
  21. package/out/replicache/src/kv/idb-store.d.ts +9 -0
  22. package/out/replicache/src/kv/idb-store.d.ts.map +1 -1
  23. package/out/replicache/src/kv/idb-store.js +14 -2
  24. package/out/replicache/src/kv/idb-store.js.map +1 -1
  25. package/out/replicache/src/kv/mem-store.d.ts +1 -0
  26. package/out/replicache/src/kv/mem-store.d.ts.map +1 -1
  27. package/out/replicache/src/kv/mem-store.js +3 -0
  28. package/out/replicache/src/kv/mem-store.js.map +1 -1
  29. package/out/replicache/src/kv/op-sqlite/store.d.ts.map +1 -1
  30. package/out/replicache/src/kv/op-sqlite/store.js +1 -1
  31. package/out/replicache/src/kv/op-sqlite/store.js.map +1 -1
  32. package/out/replicache/src/kv/sqlite-store.d.ts +2 -1
  33. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  34. package/out/replicache/src/kv/sqlite-store.js +6 -1
  35. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  36. package/out/replicache/src/kv/store.d.ts +6 -0
  37. package/out/replicache/src/kv/store.d.ts.map +1 -1
  38. package/out/replicache/src/persist/collect-idb-databases.d.ts +10 -5
  39. package/out/replicache/src/persist/collect-idb-databases.d.ts.map +1 -1
  40. package/out/replicache/src/persist/collect-idb-databases.js +16 -9
  41. package/out/replicache/src/persist/collect-idb-databases.js.map +1 -1
  42. package/out/replicache/src/replicache-impl.d.ts +14 -3
  43. package/out/replicache/src/replicache-impl.d.ts.map +1 -1
  44. package/out/replicache/src/replicache-impl.js +104 -9
  45. package/out/replicache/src/replicache-impl.js.map +1 -1
  46. package/out/shared/src/arrays.js +1 -15
  47. package/out/shared/src/arrays.js.map +1 -1
  48. package/out/shared/src/hash.d.ts +1 -0
  49. package/out/shared/src/hash.d.ts.map +1 -1
  50. package/out/shared/src/hash.js +10 -28
  51. package/out/shared/src/hash.js.map +1 -1
  52. package/out/shared/src/iterables.d.ts +2 -0
  53. package/out/shared/src/iterables.d.ts.map +1 -1
  54. package/out/shared/src/iterables.js +18 -1
  55. package/out/shared/src/iterables.js.map +1 -1
  56. package/out/shared/src/json.d.ts.map +1 -1
  57. package/out/shared/src/json.js +2 -2
  58. package/out/shared/src/json.js.map +1 -1
  59. package/out/shared/src/ring-buffer.d.ts +8 -0
  60. package/out/shared/src/ring-buffer.d.ts.map +1 -1
  61. package/out/shared/src/ring-buffer.js +22 -1
  62. package/out/shared/src/ring-buffer.js.map +1 -1
  63. package/out/shared/src/xxhash32.d.ts +36 -0
  64. package/out/shared/src/xxhash32.d.ts.map +1 -0
  65. package/out/shared/src/xxhash32.js +51 -0
  66. package/out/shared/src/xxhash32.js.map +1 -0
  67. package/out/z2s/src/compiler.js +1 -1
  68. package/out/zero/package.js +1 -1
  69. package/out/zero/package.js.map +1 -1
  70. package/out/zero-cache/src/auth/read-authorizer.js +1 -1
  71. package/out/zero-cache/src/custom-queries/transform-query.js +1 -1
  72. package/out/zero-cache/src/server/inspector-delegate.js +3 -2
  73. package/out/zero-cache/src/server/inspector-delegate.js.map +1 -1
  74. package/out/zero-cache/src/services/change-source/custom/change-source.js +2 -2
  75. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  76. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +3 -3
  77. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  78. package/out/zero-cache/src/services/mutagen/pusher.js +1 -1
  79. package/out/zero-cache/src/services/run-ast.js +1 -1
  80. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  81. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +6 -10
  82. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  83. package/out/zero-cache/src/services/view-syncer/query-covering.d.ts.map +1 -1
  84. package/out/zero-cache/src/services/view-syncer/query-covering.js.map +1 -1
  85. package/out/zero-cache/src/workers/connection.js +3 -3
  86. package/out/zero-cache/src/workers/connection.js.map +1 -1
  87. package/out/zero-client/src/client/connection-manager.d.ts +20 -0
  88. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  89. package/out/zero-client/src/client/connection-manager.js +32 -14
  90. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  91. package/out/zero-client/src/client/connection-status-enum.d.ts +2 -0
  92. package/out/zero-client/src/client/connection-status-enum.d.ts.map +1 -1
  93. package/out/zero-client/src/client/connection-status-enum.js +3 -1
  94. package/out/zero-client/src/client/connection-status-enum.js.map +1 -1
  95. package/out/zero-client/src/client/connection.d.ts +6 -0
  96. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  97. package/out/zero-client/src/client/connection.js +2 -1
  98. package/out/zero-client/src/client/connection.js.map +1 -1
  99. package/out/zero-client/src/client/context.d.ts +8 -11
  100. package/out/zero-client/src/client/context.d.ts.map +1 -1
  101. package/out/zero-client/src/client/context.js +11 -15
  102. package/out/zero-client/src/client/context.js.map +1 -1
  103. package/out/zero-client/src/client/custom.js +2 -2
  104. package/out/zero-client/src/client/custom.js.map +1 -1
  105. package/out/zero-client/src/client/error.js +1 -1
  106. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
  107. package/out/zero-client/src/client/mutator-proxy.js +2 -1
  108. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  109. package/out/zero-client/src/client/options.d.ts +3 -0
  110. package/out/zero-client/src/client/options.d.ts.map +1 -1
  111. package/out/zero-client/src/client/options.js.map +1 -1
  112. package/out/zero-client/src/client/query-manager.d.ts +2 -0
  113. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  114. package/out/zero-client/src/client/query-manager.js +48 -9
  115. package/out/zero-client/src/client/query-manager.js.map +1 -1
  116. package/out/zero-client/src/client/version.js +1 -1
  117. package/out/zero-client/src/client/zero.d.ts +18 -3
  118. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  119. package/out/zero-client/src/client/zero.js +59 -12
  120. package/out/zero-client/src/client/zero.js.map +1 -1
  121. package/out/zero-client/src/types/query-result.d.ts +2 -0
  122. package/out/zero-client/src/types/query-result.d.ts.map +1 -1
  123. package/out/zero-protocol/src/ast.d.ts +64 -1
  124. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  125. package/out/zero-protocol/src/ast.js +223 -51
  126. package/out/zero-protocol/src/ast.js.map +1 -1
  127. package/out/zero-protocol/src/query-hash-visitor.d.ts +81 -0
  128. package/out/zero-protocol/src/query-hash-visitor.d.ts.map +1 -0
  129. package/out/zero-protocol/src/query-hash-visitor.js +324 -0
  130. package/out/zero-protocol/src/query-hash-visitor.js.map +1 -0
  131. package/out/zero-protocol/src/query-hash.d.ts +7 -2
  132. package/out/zero-protocol/src/query-hash.d.ts.map +1 -1
  133. package/out/zero-protocol/src/query-hash.js +12 -9
  134. package/out/zero-protocol/src/query-hash.js.map +1 -1
  135. package/out/zero-react/src/use-query.d.ts +5 -4
  136. package/out/zero-react/src/use-query.d.ts.map +1 -1
  137. package/out/zero-react/src/use-query.js +86 -9
  138. package/out/zero-react/src/use-query.js.map +1 -1
  139. package/out/zero-solid/src/solid-view.d.ts +10 -0
  140. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  141. package/out/zero-solid/src/solid-view.js +27 -0
  142. package/out/zero-solid/src/solid-view.js.map +1 -1
  143. package/out/zero-solid/src/use-query.js +5 -3
  144. package/out/zero-solid/src/use-query.js.map +1 -1
  145. package/out/zql/src/ivm/array-view.d.ts +10 -0
  146. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  147. package/out/zql/src/ivm/array-view.js +20 -8
  148. package/out/zql/src/ivm/array-view.js.map +1 -1
  149. package/out/zql/src/ivm/cap.d.ts.map +1 -1
  150. package/out/zql/src/ivm/cap.js +5 -3
  151. package/out/zql/src/ivm/cap.js.map +1 -1
  152. package/out/zql/src/ivm/deferred-input.d.ts.map +1 -1
  153. package/out/zql/src/ivm/deferred-input.js +3 -2
  154. package/out/zql/src/ivm/deferred-input.js.map +1 -1
  155. package/out/zql/src/ivm/exists.d.ts +1 -1
  156. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  157. package/out/zql/src/ivm/exists.js +1 -1
  158. package/out/zql/src/ivm/exists.js.map +1 -1
  159. package/out/zql/src/ivm/fan-in.d.ts +2 -2
  160. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  161. package/out/zql/src/ivm/fan-in.js +6 -5
  162. package/out/zql/src/ivm/fan-in.js.map +1 -1
  163. package/out/zql/src/ivm/fan-out.d.ts +2 -2
  164. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  165. package/out/zql/src/ivm/fan-out.js.map +1 -1
  166. package/out/zql/src/ivm/filter-operators.d.ts +4 -4
  167. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  168. package/out/zql/src/ivm/filter-operators.js +10 -8
  169. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  170. package/out/zql/src/ivm/filter.d.ts +2 -2
  171. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  172. package/out/zql/src/ivm/filter.js +7 -4
  173. package/out/zql/src/ivm/filter.js.map +1 -1
  174. package/out/zql/src/ivm/flipped-join.js +2 -2
  175. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  176. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  177. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  178. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +6 -4
  179. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  180. package/out/zql/src/ivm/memory-source.d.ts +2 -2
  181. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  182. package/out/zql/src/ivm/memory-source.js +9 -9
  183. package/out/zql/src/ivm/memory-source.js.map +1 -1
  184. package/out/zql/src/ivm/take.d.ts.map +1 -1
  185. package/out/zql/src/ivm/take.js +3 -4
  186. package/out/zql/src/ivm/take.js.map +1 -1
  187. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  188. package/out/zql/src/ivm/union-fan-in.js +9 -7
  189. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  190. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  191. package/out/zql/src/ivm/view-apply-change.js +3 -3
  192. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  193. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  194. package/out/zql/src/mutate/mutator-registry.js +2 -2
  195. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  196. package/out/zql/src/query/query-delegate-base.d.ts +2 -0
  197. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  198. package/out/zql/src/query/query-delegate-base.js +58 -31
  199. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  200. package/out/zql/src/query/query-delegate.d.ts +11 -1
  201. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  202. package/out/zql/src/query/query-impl.d.ts +25 -14
  203. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  204. package/out/zql/src/query/query-impl.js +414 -94
  205. package/out/zql/src/query/query-impl.js.map +1 -1
  206. package/out/zql/src/query/query-internals.d.ts +21 -11
  207. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  208. package/out/zql/src/query/query-internals.js.map +1 -1
  209. package/out/zql/src/query/query-transitions.d.ts +171 -0
  210. package/out/zql/src/query/query-transitions.d.ts.map +1 -0
  211. package/out/zql/src/query/query-transitions.js +207 -0
  212. package/out/zql/src/query/query-transitions.js.map +1 -0
  213. package/out/zql/src/query/query.d.ts +7 -1
  214. package/out/zql/src/query/query.d.ts.map +1 -1
  215. package/out/zql/src/query/runnable-query-impl.d.ts +3 -2
  216. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -1
  217. package/out/zql/src/query/runnable-query-impl.js +23 -2
  218. package/out/zql/src/query/runnable-query-impl.js.map +1 -1
  219. package/out/zql/src/query/typed-view.d.ts +1 -1
  220. package/out/zql/src/query/typed-view.d.ts.map +1 -1
  221. package/out/zqlite/src/table-source.d.ts.map +1 -1
  222. package/out/zqlite/src/table-source.js +7 -5
  223. package/out/zqlite/src/table-source.js.map +1 -1
  224. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AACvE,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,iCAAiC,CAAC;AAE1D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E,gBAAgB,EAAE,MAAM,CAAC,GAWnC,CAAC;IAGpB,cAAc,CACZ,YAAY,EAAE,IAAI,GAAG,SAAS,EAC9B,OAAO,EAAE,IAAI,EACb,OAAO,EAAE,WAAW;CA2BvB"}
@@ -19,7 +19,7 @@ var ZeroContext = class extends QueryDelegateBase {
19
19
  flushQueryChanges;
20
20
  #batchViewUpdates;
21
21
  #commitListeners = /* @__PURE__ */ new Set();
22
- #pipelinesReady = true;
22
+ #pipelinesReady = false;
23
23
  #pendingPipelines = /* @__PURE__ */ new Set();
24
24
  assertValidRunOptions;
25
25
  /**
@@ -57,23 +57,18 @@ var ZeroContext = class extends QueryDelegateBase {
57
57
  };
58
58
  }
59
59
  /**
60
- * Stop building pipelines for materialized queries until
61
- * {@link markPipelinesReady} is called. Views materialized in the meantime
62
- * are empty and `unknown`, exactly as they would be over empty sources.
63
- */
64
- deferPipelines() {
65
- this.#pipelinesReady = false;
66
- }
67
- /**
68
- * Build and hydrate every pipeline deferred since {@link deferPipelines},
69
- * in materialization order, as a single view-update batch. A pipeline that
70
- * fails to build is logged and its view reports an error; the rest are
71
- * still built.
60
+ * Build and hydrate every pipeline deferred since construction, in
61
+ * materialization order, as a single view-update batch. Views materialized
62
+ * before this is called are empty and `unknown` in the meantime, exactly as
63
+ * they would be over empty sources. A pipeline that fails to build is
64
+ * logged and its view reports an error; the rest are still built.
65
+ *
66
+ * Returns `this` so it can be chained onto the constructor call.
72
67
  */
73
68
  markPipelinesReady() {
74
- if (this.#pipelinesReady) return;
69
+ if (this.#pipelinesReady) return this;
75
70
  this.#pipelinesReady = true;
76
- if (this.#pendingPipelines.size === 0) return;
71
+ if (this.#pendingPipelines.size === 0) return this;
77
72
  const pending = [...this.#pendingPipelines];
78
73
  this.#pendingPipelines.clear();
79
74
  this.batchViewUpdates(() => {
@@ -87,6 +82,7 @@ var ZeroContext = class extends QueryDelegateBase {
87
82
  this.#endTransaction();
88
83
  }
89
84
  });
85
+ return this;
90
86
  }
91
87
  mapAst(ast) {
92
88
  return ast;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["#lc","#mainSources","#batchViewUpdates","#commitListeners","#pendingPipelines","#pipelinesReady","#endTransaction"],"sources":["../../../../../zero-client/src/client/context.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport type {DebugDelegate} from '../../../zql/src/builder/debug-delegate.ts';\nimport type {Input} from '../../../zql/src/ivm/operator.ts';\nimport type {Source, SourceInput} from '../../../zql/src/ivm/source.ts';\nimport {MeasurePushOperator} from '../../../zql/src/query/measure-push-operator.ts';\nimport type {MetricsDelegate} from '../../../zql/src/query/metrics-delegate.ts';\nimport {QueryDelegateBase} from '../../../zql/src/query/query-delegate-base.ts';\nimport type {CommitListener} from '../../../zql/src/query/query-delegate.ts';\nimport type {RunOptions} from '../../../zql/src/query/query.ts';\nimport {type IVMSourceBranch} from './ivm-branch.ts';\nimport type {QueryManager} from './query-manager.ts';\n\nexport type AddQuery = QueryManager['addLegacy'];\nexport type AddCustomQuery = QueryManager['addCustom'];\n\nexport type UpdateQuery = QueryManager['updateLegacy'];\nexport type UpdateCustomQuery = QueryManager['updateCustom'];\nexport type FlushQueryChanges = QueryManager['flushBatch'];\n\n/**\n * ZeroContext glues together zql and Replicache. It listens to changes in\n * Replicache data and pushes them into IVM and on tells the server about new\n * queries.\n */\nexport class ZeroContext extends QueryDelegateBase {\n readonly #lc: LogContext;\n\n // It is a bummer to have to maintain separate MemorySources here and copy the\n // data in from the Replicache db. But we want the data to be accessible via\n // pipelines *synchronously* and the core Replicache infra is all async. So\n // that needs to be fixed.\n readonly #mainSources: IVMSourceBranch;\n\n readonly addServerQuery: AddQuery;\n readonly addCustomQuery: AddCustomQuery;\n readonly updateServerQuery: UpdateQuery;\n readonly updateCustomQuery: UpdateCustomQuery;\n readonly flushQueryChanges: () => void;\n readonly #batchViewUpdates: (applyViewUpdates: () => void) => void;\n readonly #commitListeners: Set<CommitListener> = new Set();\n\n // Pipeline construction is deferred between `deferPipelines()` and\n // `markPipelinesReady()`. Zero calls the former at construction and the\n // latter once the replica has been loaded into the IVM sources, so cold\n // boot loads the sources once instead of pushing every row through every\n // already-materialized pipeline.\n #pipelinesReady = true;\n readonly #pendingPipelines: Set<() => void> = new Set();\n\n readonly assertValidRunOptions: (options?: RunOptions) => void;\n\n /**\n * Client-side queries start out as \"unknown\" and are then updated to\n * \"complete\" once the server has sent back the query result.\n */\n readonly defaultQueryComplete = false;\n\n readonly addMetric: MetricsDelegate['addMetric'];\n\n constructor(\n lc: LogContext,\n mainSources: IVMSourceBranch,\n addQuery: AddQuery,\n addCustomQuery: AddCustomQuery,\n updateQuery: UpdateQuery,\n updateCustomQuery: UpdateCustomQuery,\n flushQueryChanges: () => void,\n batchViewUpdates: (applyViewUpdates: () => void) => void,\n addMetric: MetricsDelegate['addMetric'],\n assertValidRunOptions: (options?: RunOptions) => void,\n ) {\n super();\n this.#lc = lc;\n this.#mainSources = mainSources;\n this.addServerQuery = addQuery;\n this.updateServerQuery = updateQuery;\n this.updateCustomQuery = updateCustomQuery;\n this.#batchViewUpdates = batchViewUpdates;\n this.assertValidRunOptions = assertValidRunOptions;\n this.addCustomQuery = addCustomQuery;\n this.flushQueryChanges = flushQueryChanges;\n this.addMetric = addMetric;\n }\n\n applyFiltersAnyway?: boolean | undefined;\n\n debug?: DebugDelegate | undefined;\n\n getSource(name: string): Source | undefined {\n return this.#mainSources.getSource(name);\n }\n\n override get pipelinesReady(): boolean {\n return this.#pipelinesReady;\n }\n\n override onPipelinesReady(cb: () => void): () => void {\n assert(\n !this.#pipelinesReady,\n 'onPipelinesReady called while pipelines are ready',\n );\n this.#pendingPipelines.add(cb);\n return () => {\n this.#pendingPipelines.delete(cb);\n };\n }\n\n /**\n * Stop building pipelines for materialized queries until\n * {@link markPipelinesReady} is called. Views materialized in the meantime\n * are empty and `unknown`, exactly as they would be over empty sources.\n */\n deferPipelines(): void {\n this.#pipelinesReady = false;\n }\n\n /**\n * Build and hydrate every pipeline deferred since {@link deferPipelines},\n * in materialization order, as a single view-update batch. A pipeline that\n * fails to build is logged and its view reports an error; the rest are\n * still built.\n */\n markPipelinesReady(): void {\n if (this.#pipelinesReady) {\n return;\n }\n this.#pipelinesReady = true;\n if (this.#pendingPipelines.size === 0) {\n return;\n }\n const pending = [...this.#pendingPipelines];\n this.#pendingPipelines.clear();\n this.batchViewUpdates(() => {\n try {\n for (const attach of pending) {\n try {\n attach();\n } catch (e) {\n // The failing view has already been marked as errored; keep\n // building the others rather than aborting startup.\n this.#lc.error?.(\n ErrorKind.Internal,\n 'Failed to build a deferred query pipeline',\n e,\n );\n }\n }\n } finally {\n this.#endTransaction();\n }\n });\n }\n\n mapAst(ast: AST): AST {\n return ast;\n }\n\n override decorateSourceInput(input: SourceInput, queryID: string): Input {\n return new MeasurePushOperator(input, queryID, this, 'query-update-client');\n }\n\n onTransactionCommit(cb: CommitListener): () => void {\n this.#commitListeners.add(cb);\n return () => {\n this.#commitListeners.delete(cb);\n };\n }\n\n override batchViewUpdates<T>(applyViewUpdates: () => T) {\n let result: T | undefined;\n let viewChangesPerformed = false;\n this.#batchViewUpdates(() => {\n result = applyViewUpdates();\n viewChangesPerformed = true;\n });\n assert(\n viewChangesPerformed,\n 'batchViewUpdates must call applyViewUpdates synchronously.',\n );\n return result as T;\n }\n\n processChanges(\n expectedHead: Hash | undefined,\n newHead: Hash,\n changes: NoIndexDiff,\n ) {\n this.batchViewUpdates(() => {\n try {\n this.#mainSources.advance(expectedHead, newHead, changes);\n } finally {\n this.#endTransaction();\n }\n });\n }\n\n #endTransaction() {\n for (const listener of this.#commitListeners) {\n try {\n listener();\n } catch (e) {\n // We should not fatal the inner-workings of Zero due to the user's application\n // code throwing an error.\n // Hence we wrap notifications in a try-catch block.\n this.#lc.error?.(\n ErrorKind.Internal,\n 'Failed notifying a commit listener of IVM updates',\n e,\n );\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,cAAb,cAAiC,kBAAkB;CACjD;CAMA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA,mCAAiD,IAAI,IAAI;CAOzD,kBAAkB;CAClB,oCAA8C,IAAI,IAAI;CAEtD;;;;;CAMA,uBAAgC;CAEhC;CAEA,YACE,IACA,aACA,UACA,gBACA,aACA,mBACA,mBACA,kBACA,WACA,uBACA;EACA,MAAM;EACN,KAAKA,MAAM;EACX,KAAKC,eAAe;EACpB,KAAK,iBAAiB;EACtB,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;EACzB,KAAKC,oBAAoB;EACzB,KAAK,wBAAwB;EAC7B,KAAK,iBAAiB;EACtB,KAAK,oBAAoB;EACzB,KAAK,YAAY;CACnB;CAEA;CAEA;CAEA,UAAU,MAAkC;EAC1C,OAAO,KAAKD,aAAa,UAAU,IAAI;CACzC;CAEA,IAAa,iBAA0B;EACrC,OAAO,KAAKI;CACd;CAEA,iBAA0B,IAA4B;EACpD,OACE,CAAC,KAAKA,iBACN,mDACF;EACA,KAAKD,kBAAkB,IAAI,EAAE;EAC7B,aAAa;GACX,KAAKA,kBAAkB,OAAO,EAAE;EAClC;CACF;;;;;;CAOA,iBAAuB;EACrB,KAAKC,kBAAkB;CACzB;;;;;;;CAQA,qBAA2B;EACzB,IAAI,KAAKA,iBACP;EAEF,KAAKA,kBAAkB;EACvB,IAAI,KAAKD,kBAAkB,SAAS,GAClC;EAEF,MAAM,UAAU,CAAC,GAAG,KAAKA,iBAAiB;EAC1C,KAAKA,kBAAkB,MAAM;EAC7B,KAAK,uBAAuB;GAC1B,IAAI;IACF,KAAK,MAAM,UAAU,SACnB,IAAI;KACF,OAAO;IACT,SAAS,GAAG;KAGV,KAAKJ,IAAI,QACP,UACA,6CACA,CACF;IACF;GAEJ,UAAU;IACR,KAAKM,gBAAgB;GACvB;EACF,CAAC;CACH;CAEA,OAAO,KAAe;EACpB,OAAO;CACT;CAEA,oBAA6B,OAAoB,SAAwB;EACvE,OAAO,IAAI,oBAAoB,OAAO,SAAS,MAAM,qBAAqB;CAC5E;CAEA,oBAAoB,IAAgC;EAClD,KAAKH,iBAAiB,IAAI,EAAE;EAC5B,aAAa;GACX,KAAKA,iBAAiB,OAAO,EAAE;EACjC;CACF;CAEA,iBAA6B,kBAA2B;EACtD,IAAI;EACJ,IAAI,uBAAuB;EAC3B,KAAKD,wBAAwB;GAC3B,SAAS,iBAAiB;GAC1B,uBAAuB;EACzB,CAAC;EACD,OACE,sBACA,4DACF;EACA,OAAO;CACT;CAEA,eACE,cACA,SACA,SACA;EACA,KAAK,uBAAuB;GAC1B,IAAI;IACF,KAAKD,aAAa,QAAQ,cAAc,SAAS,OAAO;GAC1D,UAAU;IACR,KAAKK,gBAAgB;GACvB;EACF,CAAC;CACH;CAEA,kBAAkB;EAChB,KAAK,MAAM,YAAY,KAAKH,kBAC1B,IAAI;GACF,SAAS;EACX,SAAS,GAAG;GAIV,KAAKH,IAAI,QACP,UACA,qDACA,CACF;EACF;CAEJ;AACF"}
1
+ {"version":3,"file":"context.js","names":["#lc","#mainSources","#batchViewUpdates","#commitListeners","#pendingPipelines","#pipelinesReady","#endTransaction"],"sources":["../../../../../zero-client/src/client/context.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {NoIndexDiff} from '../../../replicache/src/btree/node.ts';\nimport type {Hash} from '../../../replicache/src/hash.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {AST} from '../../../zero-protocol/src/ast.ts';\nimport {ErrorKind} from '../../../zero-protocol/src/error-kind.ts';\nimport type {DebugDelegate} from '../../../zql/src/builder/debug-delegate.ts';\nimport type {Input} from '../../../zql/src/ivm/operator.ts';\nimport type {Source, SourceInput} from '../../../zql/src/ivm/source.ts';\nimport {MeasurePushOperator} from '../../../zql/src/query/measure-push-operator.ts';\nimport type {MetricsDelegate} from '../../../zql/src/query/metrics-delegate.ts';\nimport {QueryDelegateBase} from '../../../zql/src/query/query-delegate-base.ts';\nimport type {CommitListener} from '../../../zql/src/query/query-delegate.ts';\nimport type {RunOptions} from '../../../zql/src/query/query.ts';\nimport {type IVMSourceBranch} from './ivm-branch.ts';\nimport type {QueryManager} from './query-manager.ts';\n\nexport type AddQuery = QueryManager['addLegacy'];\nexport type AddCustomQuery = QueryManager['addCustom'];\n\nexport type UpdateQuery = QueryManager['updateLegacy'];\nexport type UpdateCustomQuery = QueryManager['updateCustom'];\nexport type FlushQueryChanges = QueryManager['flushBatch'];\n\n/**\n * ZeroContext glues together zql and Replicache. It listens to changes in\n * Replicache data and pushes them into IVM and on tells the server about new\n * queries.\n */\nexport class ZeroContext extends QueryDelegateBase {\n readonly #lc: LogContext;\n\n // It is a bummer to have to maintain separate MemorySources here and copy the\n // data in from the Replicache db. But we want the data to be accessible via\n // pipelines *synchronously* and the core Replicache infra is all async. So\n // that needs to be fixed.\n readonly #mainSources: IVMSourceBranch;\n\n readonly addServerQuery: AddQuery;\n readonly addCustomQuery: AddCustomQuery;\n readonly updateServerQuery: UpdateQuery;\n readonly updateCustomQuery: UpdateCustomQuery;\n readonly flushQueryChanges: () => void;\n readonly #batchViewUpdates: (applyViewUpdates: () => void) => void;\n readonly #commitListeners: Set<CommitListener> = new Set();\n\n // Pipeline construction is deferred until `markPipelinesReady()` is called.\n // Zero calls it once the replica has been loaded into the IVM sources, so\n // cold boot loads the sources once instead of pushing every row through\n // every already-materialized pipeline. Contexts whose sources are already\n // populated at construction (custom mutator transactions, tests) call it\n // right away.\n #pipelinesReady = false;\n readonly #pendingPipelines: Set<() => void> = new Set();\n\n readonly assertValidRunOptions: (options?: RunOptions) => void;\n\n /**\n * Client-side queries start out as \"unknown\" and are then updated to\n * \"complete\" once the server has sent back the query result.\n */\n readonly defaultQueryComplete = false;\n\n readonly addMetric: MetricsDelegate['addMetric'];\n\n constructor(\n lc: LogContext,\n mainSources: IVMSourceBranch,\n addQuery: AddQuery,\n addCustomQuery: AddCustomQuery,\n updateQuery: UpdateQuery,\n updateCustomQuery: UpdateCustomQuery,\n flushQueryChanges: () => void,\n batchViewUpdates: (applyViewUpdates: () => void) => void,\n addMetric: MetricsDelegate['addMetric'],\n assertValidRunOptions: (options?: RunOptions) => void,\n ) {\n super();\n this.#lc = lc;\n this.#mainSources = mainSources;\n this.addServerQuery = addQuery;\n this.updateServerQuery = updateQuery;\n this.updateCustomQuery = updateCustomQuery;\n this.#batchViewUpdates = batchViewUpdates;\n this.assertValidRunOptions = assertValidRunOptions;\n this.addCustomQuery = addCustomQuery;\n this.flushQueryChanges = flushQueryChanges;\n this.addMetric = addMetric;\n }\n\n applyFiltersAnyway?: boolean | undefined;\n\n debug?: DebugDelegate | undefined;\n\n getSource(name: string): Source | undefined {\n return this.#mainSources.getSource(name);\n }\n\n override get pipelinesReady(): boolean {\n return this.#pipelinesReady;\n }\n\n override onPipelinesReady(cb: () => void): () => void {\n assert(\n !this.#pipelinesReady,\n 'onPipelinesReady called while pipelines are ready',\n );\n this.#pendingPipelines.add(cb);\n return () => {\n this.#pendingPipelines.delete(cb);\n };\n }\n\n /**\n * Build and hydrate every pipeline deferred since construction, in\n * materialization order, as a single view-update batch. Views materialized\n * before this is called are empty and `unknown` in the meantime, exactly as\n * they would be over empty sources. A pipeline that fails to build is\n * logged and its view reports an error; the rest are still built.\n *\n * Returns `this` so it can be chained onto the constructor call.\n */\n markPipelinesReady(): this {\n if (this.#pipelinesReady) {\n return this;\n }\n this.#pipelinesReady = true;\n if (this.#pendingPipelines.size === 0) {\n return this;\n }\n const pending = [...this.#pendingPipelines];\n this.#pendingPipelines.clear();\n this.batchViewUpdates(() => {\n try {\n for (const attach of pending) {\n try {\n attach();\n } catch (e) {\n // The failing view has already been marked as errored; keep\n // building the others rather than aborting startup.\n this.#lc.error?.(\n ErrorKind.Internal,\n 'Failed to build a deferred query pipeline',\n e,\n );\n }\n }\n } finally {\n this.#endTransaction();\n }\n });\n return this;\n }\n\n mapAst(ast: AST): AST {\n return ast;\n }\n\n override decorateSourceInput(input: SourceInput, queryID: string): Input {\n return new MeasurePushOperator(input, queryID, this, 'query-update-client');\n }\n\n onTransactionCommit(cb: CommitListener): () => void {\n this.#commitListeners.add(cb);\n return () => {\n this.#commitListeners.delete(cb);\n };\n }\n\n override batchViewUpdates<T>(applyViewUpdates: () => T) {\n let result: T | undefined;\n let viewChangesPerformed = false;\n this.#batchViewUpdates(() => {\n result = applyViewUpdates();\n viewChangesPerformed = true;\n });\n assert(\n viewChangesPerformed,\n 'batchViewUpdates must call applyViewUpdates synchronously.',\n );\n return result as T;\n }\n\n processChanges(\n expectedHead: Hash | undefined,\n newHead: Hash,\n changes: NoIndexDiff,\n ) {\n this.batchViewUpdates(() => {\n try {\n this.#mainSources.advance(expectedHead, newHead, changes);\n } finally {\n this.#endTransaction();\n }\n });\n }\n\n #endTransaction() {\n for (const listener of this.#commitListeners) {\n try {\n listener();\n } catch (e) {\n // We should not fatal the inner-workings of Zero due to the user's application\n // code throwing an error.\n // Hence we wrap notifications in a try-catch block.\n this.#lc.error?.(\n ErrorKind.Internal,\n 'Failed notifying a commit listener of IVM updates',\n e,\n );\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AA6BA,IAAa,cAAb,cAAiC,kBAAkB;CACjD;CAMA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA,mCAAiD,IAAI,IAAI;CAQzD,kBAAkB;CAClB,oCAA8C,IAAI,IAAI;CAEtD;;;;;CAMA,uBAAgC;CAEhC;CAEA,YACE,IACA,aACA,UACA,gBACA,aACA,mBACA,mBACA,kBACA,WACA,uBACA;EACA,MAAM;EACN,KAAKA,MAAM;EACX,KAAKC,eAAe;EACpB,KAAK,iBAAiB;EACtB,KAAK,oBAAoB;EACzB,KAAK,oBAAoB;EACzB,KAAKC,oBAAoB;EACzB,KAAK,wBAAwB;EAC7B,KAA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C1D,UAAU;IACR,KAAKK,gBAAgB;GACvB;EACF,CAAC;CACH;CAEA,kBAAkB;EAChB,KAAK,MAAM,YAAY,KAAKH,kBAC1B,IAAI;GACF,SAAS;EACX,SAAS,GAAG;GAIV,KAAKH,IAAI,QACP,UACA,qDACA,CACF;EACF;CAEJ;AACF"}
@@ -53,10 +53,10 @@ function makeReplicacheMutator(lc, mutator, schema, context) {
53
53
  };
54
54
  }
55
55
  function assertValidRunOptions(options) {
56
- assert(options?.type !== "complete", "Cannot wait for complete results in custom mutations");
56
+ assert(options?.type !== "complete" && options?.type !== "cached", "Cannot wait for cached or complete results in custom mutations");
57
57
  }
58
58
  function newZeroContext(lc, ivmBranch) {
59
- return new ZeroContext(lc, ivmBranch, () => emptyFunction, () => emptyFunction, emptyFunction, emptyFunction, emptyFunction, (applyViewUpdates) => applyViewUpdates(), emptyFunction, assertValidRunOptions);
59
+ return new ZeroContext(lc, ivmBranch, () => emptyFunction, () => emptyFunction, emptyFunction, emptyFunction, emptyFunction, (applyViewUpdates) => applyViewUpdates(), emptyFunction, assertValidRunOptions).markPipelinesReady();
60
60
  }
61
61
  //#endregion
62
62
  export { TransactionImpl, makeReplicacheMutator };
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","names":["#repTx","#zeroContext"],"sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n makeTransactionMutate,\n type TransactionMutate,\n} from '../../../zql/src/mutate/crud.ts';\nimport type {\n ClientTransaction,\n Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport {createRunnableBuilder} from '../../../zql/src/query/create-builder.ts';\nimport {\n type HumanReadable,\n type Query,\n type RunOptions,\n} from '../../../zql/src/query/query.ts';\nimport type {ConditionalSchemaQuery} from '../../../zql/src/query/schema-query.ts';\nimport type {ClientID} from '../types/client-state.ts';\nimport {ZeroContext} from './context.ts';\nimport {makeCRUDExecutor} from './crud.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {WriteTransaction} from './replicache-types.ts';\n\n/**\n * The shape which a user's custom mutator definitions must conform to.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type CustomMutatorDefs = {\n // oxlint-disable-next-line no-explicit-any\n [namespaceOrKey: string]: CustomMutatorImpl<any> | CustomMutatorDefs;\n};\n\nexport type MutatorResultDetails =\n | {\n readonly type: 'success';\n }\n | {\n readonly type: 'error';\n readonly error:\n | {\n readonly type: 'app';\n readonly message: string;\n readonly details: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'zero';\n readonly message: string;\n };\n };\n\nexport type MutatorResultSuccessDetails = Extract<\n MutatorResultDetails,\n {type: 'success'}\n>;\nexport type MutatorResultErrorDetails = Extract<\n MutatorResultDetails,\n {type: 'error'}\n>;\n\nexport type MutatorResult = {\n client: Promise<MutatorResultDetails & {}>;\n server: Promise<MutatorResultDetails & {}>;\n} & {};\n\nexport type CustomMutatorImpl<\n S extends Schema,\n TWrappedTransaction = unknown,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs = any,\n Context = unknown,\n> = (\n tx: Transaction<S, TWrappedTransaction>,\n // TODO: many args. See commit: 52657c2f934b4a458d628ea77e56ce92b61eb3c6 which did have many args.\n // The issue being that it will be a protocol change to support varargs.\n args: TArgs,\n ctx: Context,\n) => Promise<void>;\n\n/**\n * The shape exposed on the `Zero.mutate` instance.\n * The signature of a custom mutator takes a `transaction` as its first arg\n * but the user does not provide this arg when calling the mutator.\n *\n * This utility strips the `tx` arg from the user's custom mutator signatures.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type MakeCustomMutatorInterfaces<\n S extends Schema,\n MD extends CustomMutatorDefs,\n TContext,\n> = {\n readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<void>\n ? (...args: Args) => MutatorResult\n : MD[NamespaceOrName] extends CustomMutatorDefs\n ? MakeCustomMutatorInterfaces<S, MD[NamespaceOrName], TContext>\n : never;\n};\n\nexport type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (\n tx: ClientTransaction<TSchema>,\n ...args: infer Args\n) => Promise<void>\n ? (...args: Args) => MutatorResult\n : never;\n\nexport class TransactionImpl<\n TSchema extends Schema = DefaultSchema,\n> implements ClientTransaction<TSchema> {\n readonly location = 'client';\n readonly mutate: TransactionMutate<TSchema>;\n /**\n * @deprecated Use {@linkcode createBuilder} with `tx.run(zql.table.where(...))` instead.\n */\n readonly query: ConditionalSchemaQuery<TSchema>;\n\n readonly #repTx: WriteTransaction;\n readonly #zeroContext: ZeroContext;\n\n constructor(lc: LogContext, repTx: WriteTransaction, schema: TSchema) {\n must(repTx.reason === 'initial' || repTx.reason === 'rebase');\n const txData = getZeroTxData(repTx);\n const ivmBranch = txData.ivmSources as IVMSourceBranch;\n\n this.#repTx = repTx;\n\n const executor = makeCRUDExecutor(repTx, schema, ivmBranch);\n this.mutate = makeTransactionMutate(schema, executor);\n\n const zeroContext = newZeroContext(\n lc,\n txData.ivmSources as IVMSourceBranch,\n );\n\n this.query = createRunnableBuilder(zeroContext, schema);\n\n this.#zeroContext = zeroContext;\n }\n\n get clientID(): ClientID {\n return this.#repTx.clientID;\n }\n\n get mutationID(): number {\n return this.#repTx.mutationID;\n }\n\n get reason(): 'optimistic' | 'rebase' {\n return this.#repTx.reason === 'initial' ? 'optimistic' : 'rebase';\n }\n\n get token(): string | undefined {\n return (this.#repTx as WriteTransactionImpl)[zeroData]?.token;\n }\n\n run<TTable extends keyof TSchema['tables'] & string, TReturn>(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return this.#zeroContext.run(query, options);\n }\n}\n\nexport function getZeroTxData(repTx: WriteTransaction): ZeroTxData {\n const txData = must(\n (repTx as WriteTransactionImpl)[zeroData],\n 'zero was not set on replicache internal options!',\n );\n return txData as ZeroTxData;\n}\n\nexport function makeReplicacheMutator<\n S extends Schema,\n TWrappedTransaction,\n Context,\n>(\n lc: LogContext,\n mutator: CustomMutatorImpl<S, TWrappedTransaction>,\n schema: S,\n context: Context,\n): (repTx: WriteTransaction, args: ReadonlyJSONValue) => Promise<void> {\n return async (\n repTx: WriteTransaction,\n args: ReadonlyJSONValue,\n ): Promise<void> => {\n const tx = new TransactionImpl(lc, repTx, schema);\n await mutator(tx, args, context);\n };\n}\n\nfunction assertValidRunOptions(options: RunOptions | undefined): void {\n // TODO(arv): We should enforce this with the type system too.\n assert(\n options?.type !== 'complete',\n 'Cannot wait for complete results in custom mutations',\n );\n}\n\nfunction newZeroContext(lc: LogContext, ivmBranch: IVMSourceBranch) {\n return new ZeroContext(\n lc,\n ivmBranch,\n () => emptyFunction,\n () => emptyFunction,\n emptyFunction,\n emptyFunction,\n emptyFunction,\n applyViewUpdates => applyViewUpdates(),\n emptyFunction,\n assertValidRunOptions,\n );\n}\n"],"mappings":";;;;;;;;;;AAoHA,IAAa,kBAAb,MAEwC;CACtC,WAAoB;CACpB;;;;CAIA;CAEA;CACA;CAEA,YAAY,IAAgB,OAAyB,QAAiB;EACpE,KAAK,MAAM,WAAW,aAAa,MAAM,WAAW,QAAQ;EAC5D,MAAM,SAAS,cAAc,KAAK;EAClC,MAAM,YAAY,OAAO;EAEzB,KAAKA,SAAS;EAEd,MAAM,WAAW,iBAAiB,OAAO,QAAQ,SAAS;EAC1D,KAAK,SAAS,sBAAsB,QAAQ,QAAQ;EAEpD,MAAM,cAAc,eAClB,IACA,OAAO,UACT;EAEA,KAAK,QAAQ,sBAAsB,aAAa,MAAM;EAEtD,KAAKC,eAAe;CACtB;CAEA,IAAI,WAAqB;EACvB,OAAO,KAAKD,OAAO;CACrB;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAKA,OAAO;CACrB;CAEA,IAAI,SAAkC;EACpC,OAAO,KAAKA,OAAO,WAAW,YAAY,eAAe;CAC3D;CAEA,IAAI,QAA4B;EAC9B,OAAQ,KAAKA,OAAgC,WAAW;CAC1D;CAEA,IACE,OACA,SACiC;EACjC,OAAO,KAAKC,aAAa,IAAI,OAAO,OAAO;CAC7C;AACF;AAEA,SAAgB,cAAc,OAAqC;CAKjE,OAJe,KACZ,MAA+B,WAChC,kDAEK;AACT;AAEA,SAAgB,sBAKd,IACA,SACA,QACA,SACqE;CACrE,OAAO,OACL,OACA,SACkB;EAElB,MAAM,QAAQ,IADC,gBAAgB,IAAI,OAAO,MAC5B,GAAI,MAAM,OAAO;CACjC;AACF;AAEA,SAAS,sBAAsB,SAAuC;CAEpE,OACE,SAAS,SAAS,YAClB,sDACF;AACF;AAEA,SAAS,eAAe,IAAgB,WAA4B;CAClE,OAAO,IAAI,YACT,IACA,iBACM,qBACA,eACN,eACA,eACA,gBACA,qBAAoB,iBAAiB,GACrC,eACA,qBACF;AACF"}
1
+ {"version":3,"file":"custom.js","names":["#repTx","#zeroContext"],"sources":["../../../../../zero-client/src/client/custom.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {ZeroTxData} from '../../../replicache/src/replicache-options.ts';\nimport type {WriteTransactionImpl} from '../../../replicache/src/transactions.ts';\nimport {zeroData} from '../../../replicache/src/transactions.ts';\nimport {assert} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport {emptyFunction} from '../../../shared/src/sentinels.ts';\nimport type {DefaultSchema} from '../../../zero-types/src/default-types.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport {\n makeTransactionMutate,\n type TransactionMutate,\n} from '../../../zql/src/mutate/crud.ts';\nimport type {\n ClientTransaction,\n Transaction,\n} from '../../../zql/src/mutate/custom.ts';\nimport {createRunnableBuilder} from '../../../zql/src/query/create-builder.ts';\nimport {\n type HumanReadable,\n type Query,\n type RunOptions,\n} from '../../../zql/src/query/query.ts';\nimport type {ConditionalSchemaQuery} from '../../../zql/src/query/schema-query.ts';\nimport type {ClientID} from '../types/client-state.ts';\nimport {ZeroContext} from './context.ts';\nimport {makeCRUDExecutor} from './crud.ts';\nimport type {IVMSourceBranch} from './ivm-branch.ts';\nimport type {WriteTransaction} from './replicache-types.ts';\n\n/**\n * The shape which a user's custom mutator definitions must conform to.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type CustomMutatorDefs = {\n // oxlint-disable-next-line no-explicit-any\n [namespaceOrKey: string]: CustomMutatorImpl<any> | CustomMutatorDefs;\n};\n\nexport type MutatorResultDetails =\n | {\n readonly type: 'success';\n }\n | {\n readonly type: 'error';\n readonly error:\n | {\n readonly type: 'app';\n readonly message: string;\n readonly details: ReadonlyJSONValue | undefined;\n }\n | {\n readonly type: 'zero';\n readonly message: string;\n };\n };\n\nexport type MutatorResultSuccessDetails = Extract<\n MutatorResultDetails,\n {type: 'success'}\n>;\nexport type MutatorResultErrorDetails = Extract<\n MutatorResultDetails,\n {type: 'error'}\n>;\n\nexport type MutatorResult = {\n client: Promise<MutatorResultDetails & {}>;\n server: Promise<MutatorResultDetails & {}>;\n} & {};\n\nexport type CustomMutatorImpl<\n S extends Schema,\n TWrappedTransaction = unknown,\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n TArgs = any,\n Context = unknown,\n> = (\n tx: Transaction<S, TWrappedTransaction>,\n // TODO: many args. See commit: 52657c2f934b4a458d628ea77e56ce92b61eb3c6 which did have many args.\n // The issue being that it will be a protocol change to support varargs.\n args: TArgs,\n ctx: Context,\n) => Promise<void>;\n\n/**\n * The shape exposed on the `Zero.mutate` instance.\n * The signature of a custom mutator takes a `transaction` as its first arg\n * but the user does not provide this arg when calling the mutator.\n *\n * This utility strips the `tx` arg from the user's custom mutator signatures.\n * Supports arbitrary depth nesting of namespaces.\n */\nexport type MakeCustomMutatorInterfaces<\n S extends Schema,\n MD extends CustomMutatorDefs,\n TContext,\n> = {\n readonly [NamespaceOrName in keyof MD]: MD[NamespaceOrName] extends (\n tx: Transaction<S>,\n ...args: infer Args\n ) => Promise<void>\n ? (...args: Args) => MutatorResult\n : MD[NamespaceOrName] extends CustomMutatorDefs\n ? MakeCustomMutatorInterfaces<S, MD[NamespaceOrName], TContext>\n : never;\n};\n\nexport type MakeCustomMutatorInterface<TSchema extends Schema, F> = F extends (\n tx: ClientTransaction<TSchema>,\n ...args: infer Args\n) => Promise<void>\n ? (...args: Args) => MutatorResult\n : never;\n\nexport class TransactionImpl<\n TSchema extends Schema = DefaultSchema,\n> implements ClientTransaction<TSchema> {\n readonly location = 'client';\n readonly mutate: TransactionMutate<TSchema>;\n /**\n * @deprecated Use {@linkcode createBuilder} with `tx.run(zql.table.where(...))` instead.\n */\n readonly query: ConditionalSchemaQuery<TSchema>;\n\n readonly #repTx: WriteTransaction;\n readonly #zeroContext: ZeroContext;\n\n constructor(lc: LogContext, repTx: WriteTransaction, schema: TSchema) {\n must(repTx.reason === 'initial' || repTx.reason === 'rebase');\n const txData = getZeroTxData(repTx);\n const ivmBranch = txData.ivmSources as IVMSourceBranch;\n\n this.#repTx = repTx;\n\n const executor = makeCRUDExecutor(repTx, schema, ivmBranch);\n this.mutate = makeTransactionMutate(schema, executor);\n\n const zeroContext = newZeroContext(\n lc,\n txData.ivmSources as IVMSourceBranch,\n );\n\n this.query = createRunnableBuilder(zeroContext, schema);\n\n this.#zeroContext = zeroContext;\n }\n\n get clientID(): ClientID {\n return this.#repTx.clientID;\n }\n\n get mutationID(): number {\n return this.#repTx.mutationID;\n }\n\n get reason(): 'optimistic' | 'rebase' {\n return this.#repTx.reason === 'initial' ? 'optimistic' : 'rebase';\n }\n\n get token(): string | undefined {\n return (this.#repTx as WriteTransactionImpl)[zeroData]?.token;\n }\n\n run<TTable extends keyof TSchema['tables'] & string, TReturn>(\n query: Query<TTable, TSchema, TReturn>,\n options?: RunOptions,\n ): Promise<HumanReadable<TReturn>> {\n return this.#zeroContext.run(query, options);\n }\n}\n\nexport function getZeroTxData(repTx: WriteTransaction): ZeroTxData {\n const txData = must(\n (repTx as WriteTransactionImpl)[zeroData],\n 'zero was not set on replicache internal options!',\n );\n return txData as ZeroTxData;\n}\n\nexport function makeReplicacheMutator<\n S extends Schema,\n TWrappedTransaction,\n Context,\n>(\n lc: LogContext,\n mutator: CustomMutatorImpl<S, TWrappedTransaction>,\n schema: S,\n context: Context,\n): (repTx: WriteTransaction, args: ReadonlyJSONValue) => Promise<void> {\n return async (\n repTx: WriteTransaction,\n args: ReadonlyJSONValue,\n ): Promise<void> => {\n const tx = new TransactionImpl(lc, repTx, schema);\n await mutator(tx, args, context);\n };\n}\n\nfunction assertValidRunOptions(options: RunOptions | undefined): void {\n // TODO(arv): We should enforce this with the type system too.\n assert(\n options?.type !== 'complete' && options?.type !== 'cached',\n 'Cannot wait for cached or complete results in custom mutations',\n );\n}\n\nfunction newZeroContext(lc: LogContext, ivmBranch: IVMSourceBranch) {\n // The forked branch is already populated, so there is nothing to defer.\n return new ZeroContext(\n lc,\n ivmBranch,\n () => emptyFunction,\n () => emptyFunction,\n emptyFunction,\n emptyFunction,\n emptyFunction,\n applyViewUpdates => applyViewUpdates(),\n emptyFunction,\n assertValidRunOptions,\n ).markPipelinesReady();\n}\n"],"mappings":";;;;;;;;;;AAoHA,IAAa,kBAAb,MAEwC;CACtC,WAAoB;CACpB;;;;CAIA;CAEA;CACA;CAEA,YAAY,IAAgB,OAAyB,QAAiB;EACpE,KAAK,MAAM,WAAW,aAAa,MAAM,WAAW,QAAQ;EAC5D,MAAM,SAAS,cAAc,KAAK;EAClC,MAAM,YAAY,OAAO;EAEzB,KAAKA,SAAS;EAEd,MAAM,WAAW,iBAAiB,OAAO,QAAQ,SAAS;EAC1D,KAAK,SAAS,sBAAsB,QAAQ,QAAQ;EAEpD,MAAM,cAAc,eAClB,IACA,OAAO,UACT;EAEA,KAAK,QAAQ,sBAAsB,aAAa,MAAM;EAEtD,KAAKC,eAAe;CACtB;CAEA,IAAI,WAAqB;EACvB,OAAO,KAAKD,OAAO;CACrB;CAEA,IAAI,aAAqB;EACvB,OAAO,KAAKA,OAAO;CACrB;CAEA,IAAI,SAAkC;EACpC,OAAO,KAAKA,OAAO,WAAW,YAAY,eAAe;CAC3D;CAEA,IAAI,QAA4B;EAC9B,OAAQ,KAAKA,OAAgC,WAAW;CAC1D;CAEA,IACE,OACA,SACiC;EACjC,OAAO,KAAKC,aAAa,IAAI,OAAO,OAAO;CAC7C;AACF;AAEA,SAAgB,cAAc,OAAqC;CAKjE,OAJe,KACZ,MAA+B,WAChC,kDAEK;AACT;AAEA,SAAgB,sBAKd,IACA,SACA,QACA,SACqE;CACrE,OAAO,OACL,OACA,SACkB;EAElB,MAAM,QAAQ,IADC,gBAAgB,IAAI,OAAO,MAC5B,GAAI,MAAM,OAAO;CACjC;AACF;AAEA,SAAS,sBAAsB,SAAuC;CAEpE,OACE,SAAS,SAAS,cAAc,SAAS,SAAS,UAClD,gEACF;AACF;AAEA,SAAS,eAAe,IAAgB,WAA4B;CAElE,OAAO,IAAI,YACT,IACA,iBACM,qBACA,eACN,eACA,eACA,gBACA,qBAAoB,iBAAiB,GACrC,eACA,qBACF,EAAE,mBAAmB;AACvB"}
@@ -128,6 +128,6 @@ function getErrorConnectionTransition(ex) {
128
128
  };
129
129
  }
130
130
  //#endregion
131
- export { ClientError, NO_STATUS_TRANSITION, getBackoffParams, getErrorConnectionTransition, isAuthError, isClientError, isServerError, isZeroError };
131
+ export { ClientError, NO_STATUS_TRANSITION, getBackoffParams, getErrorConnectionTransition, isClientError, isServerError, isZeroError };
132
132
 
133
133
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutator-proxy.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAInE,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAc,KAAK,SAAS,EAAC,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAuB3D,qBAAa,YAAY;;gBAOrB,EAAE,EAAE,UAAU,EACd,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe;IAYlC,IAAI,sBAAsB,IAAI,SAAS,GAAG,SAAS,CAElD;IA0CD,iBAAiB,CACf,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,EAAE,GAAG,CAAC,iBAAiB,CAAC,KAAK;QAC/C,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACzB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;KAC1B,EACD,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,aAAa;CA4GjE"}
1
+ {"version":3,"file":"mutator-proxy.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAInE,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAc,KAAK,SAAS,EAAC,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAuB3D,qBAAa,YAAY;;gBAOrB,EAAE,EAAE,UAAU,EACd,iBAAiB,EAAE,iBAAiB,EACpC,eAAe,EAAE,eAAe;IAYlC,IAAI,sBAAsB,IAAI,SAAS,GAAG,SAAS,CAElD;IA2CD,iBAAiB,CACf,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,EAAE,GAAG,CAAC,iBAAiB,CAAC,KAAK;QAC/C,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACzB,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;KAC1B,EACD,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,aAAa;CA4GjE"}
@@ -1,6 +1,6 @@
1
1
  import { unreachable } from "../../../shared/src/asserts.js";
2
2
  import { wrapWithApplicationError } from "../../../zero-protocol/src/application-error.js";
3
- import { Closed, Connected, Connecting, Disconnected, Error, NeedsAuth } from "./connection-status-enum.js";
3
+ import { Closed, Connected, Connecting, Disconnected, Error, Initializing, NeedsAuth } from "./connection-status-enum.js";
4
4
  import { ClientClosed, Offline } from "./client-error-kind-enum.js";
5
5
  import { isZeroError } from "./error.js";
6
6
  //#region ../zero-client/src/client/mutator-proxy.ts
@@ -50,6 +50,7 @@ var MutatorProxy = class {
50
50
  };
51
51
  this.#mutationTracker.rejectAllOutstandingMutations(state.reason);
52
52
  break;
53
+ case Initializing:
53
54
  case Connected:
54
55
  case Connecting:
55
56
  case NeedsAuth:
@@ -1 +1 @@
1
- {"version":3,"file":"mutator-proxy.js","names":["#lc","#connectionManager","#mutationTracker","#onConnectionStateChange","#mutationRejection","#makeZeroErrorResultDetails","#makeApplicationErrorResultDetails","#normalizeResultPromise"],"sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {ApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {wrapWithApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport type {\n ConnectionManager,\n ConnectionManagerState,\n} from './connection-manager.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport type {\n MutatorResult,\n MutatorResultErrorDetails,\n MutatorResultSuccessDetails,\n} from './custom.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\nconst successResultDetails = {\n type: 'success',\n} as const satisfies MutatorResultSuccessDetails;\nconst successResult = () => successResultDetails;\n\nfunction getStateDescription(error: ZeroError): string {\n switch (error.kind) {\n case ClientErrorKind.Offline:\n return 'offline';\n case ClientErrorKind.ClientClosed:\n return 'closed';\n default:\n return 'in error state';\n }\n}\n\ntype CachedMutationRejection = {\n readonly error: ZeroError;\n readonly promise: Promise<MutatorResultErrorDetails>;\n};\n\nexport class MutatorProxy {\n readonly #lc: LogContext;\n readonly #connectionManager: ConnectionManager;\n readonly #mutationTracker: MutationTracker;\n #mutationRejection: CachedMutationRejection | undefined;\n\n constructor(\n lc: LogContext,\n connectionManager: ConnectionManager,\n mutationTracker: MutationTracker,\n ) {\n this.#lc = lc;\n this.#connectionManager = connectionManager;\n this.#mutationTracker = mutationTracker;\n\n this.#connectionManager.subscribe(state =>\n this.#onConnectionStateChange(state),\n );\n this.#onConnectionStateChange(connectionManager.state);\n }\n\n get mutationRejectionError(): ZeroError | undefined {\n return this.#mutationRejection?.error;\n }\n\n /**\n * Called when the connection state changes.\n *\n * If the connection state is disconnected, error, or closed, the\n * mutation rejection error is set and all outstanding `.server` promises in\n * the mutation tracker are rejected with the error.\n */\n #onConnectionStateChange(state: ConnectionManagerState) {\n // we short circuit the rejection if the error is due to a missing cacheURL\n // this allows local writes to continue\n if (\n state.name === ConnectionStatus.Disconnected &&\n state.reason.kind === ClientErrorKind.NoSocketOrigin\n ) {\n this.#mutationRejection = undefined;\n return;\n }\n\n switch (state.name) {\n case ConnectionStatus.Disconnected:\n case ConnectionStatus.Error:\n case ConnectionStatus.Closed:\n this.#mutationRejection = {\n error: state.reason,\n promise: Promise.resolve(\n this.#makeZeroErrorResultDetails(state.reason),\n ),\n };\n this.#mutationTracker.rejectAllOutstandingMutations(state.reason);\n break;\n case ConnectionStatus.Connected:\n case ConnectionStatus.Connecting:\n case ConnectionStatus.NeedsAuth:\n this.#mutationRejection = undefined;\n return;\n default:\n unreachable(state);\n }\n }\n\n wrapCustomMutator<\n F extends (...args: [] | [ReadonlyJSONValue]) => {\n client: Promise<unknown>;\n server: Promise<unknown>;\n },\n >(name: string, f: F): (...args: Parameters<F>) => MutatorResult {\n return (...args) => {\n if (this.#mutationRejection) {\n const error = this.#mutationRejection.error;\n this.#lc.warn?.(\n `Mutation \"${name}\" rejected because Zero is ${getStateDescription(error)}. Details: ${error.message}. See also: https://zero.rocicorp.dev/docs/connection.`,\n );\n return {\n client: this.#mutationRejection.promise,\n server: this.#mutationRejection.promise,\n } as const satisfies MutatorResult;\n }\n\n let result: {\n client: Promise<unknown>;\n server: Promise<unknown>;\n };\n\n const cachedMutationPromises: Partial<\n Record<'client' | 'server', Promise<MutatorResultErrorDetails>>\n > = {};\n\n const wrapErrorFor =\n (origin: 'client' | 'server') =>\n (error: unknown): Promise<MutatorResultErrorDetails> => {\n const cachedPromise = cachedMutationPromises[origin];\n if (cachedPromise) {\n return cachedPromise;\n }\n\n if (isZeroError(error)) {\n this.#lc.error?.(`Mutator \"${name}\" error on ${origin}`, error);\n\n const zeroErrorPromise = this.#makeZeroErrorResultDetails(error);\n cachedMutationPromises[origin] = zeroErrorPromise;\n return zeroErrorPromise;\n }\n\n const applicationError = wrapWithApplicationError(error);\n this.#lc.error?.(\n `Mutator \"${name}\" app error on ${origin}`,\n applicationError,\n );\n\n const applicationErrorPromise =\n this.#makeApplicationErrorResultDetails(applicationError);\n cachedMutationPromises[origin] = applicationErrorPromise;\n return applicationErrorPromise;\n };\n\n try {\n result = f(...args);\n } catch (error) {\n const clientPromise = wrapErrorFor('client')(error);\n const serverPromise = wrapErrorFor('server')(error);\n\n return {\n client: clientPromise,\n server: serverPromise,\n } as const satisfies MutatorResult;\n }\n\n const client = this.#normalizeResultPromise(\n result.client,\n wrapErrorFor('client'),\n );\n const server = this.#normalizeResultPromise(\n result.server,\n wrapErrorFor('server'),\n );\n\n return {\n client,\n server,\n };\n };\n }\n\n #normalizeResultPromise(\n promise: Promise<unknown>,\n wrapError: (error: unknown) => Promise<MutatorResultErrorDetails>,\n ) {\n return promise.then<MutatorResultSuccessDetails, MutatorResultErrorDetails>(\n successResult,\n wrapError,\n );\n }\n\n #makeZeroErrorResultDetails(zeroError: ZeroError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'zero',\n message: zeroError.message,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n\n #makeApplicationErrorResultDetails(applicationError: ApplicationError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'app',\n message: applicationError.message,\n details: applicationError.details,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n}\n"],"mappings":";;;;;;AAmBA,IAAM,uBAAuB,EAC3B,MAAM,UACR;AACA,IAAM,sBAAsB;AAE5B,SAAS,oBAAoB,OAA0B;CACrD,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAOA,IAAa,eAAb,MAA0B;CACxB;CACA;CACA;CACA;CAEA,YACE,IACA,mBACA,iBACA;EACA,KAAKA,MAAM;EACX,KAAKC,qBAAqB;EAC1B,KAAKC,mBAAmB;EAExB,KAAKD,mBAAmB,WAAU,UAChC,KAAKE,yBAAyB,KAAK,CACrC;EACA,KAAKA,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BAAuB,UAAU;IACjC,OAAO;GACT;GAEF,IAAI;IACF,SAAS,EAAE,GAAG,IAAI;GACpB,SAAS,OAAO;IAId,OAAO;KACL,QAJoB,aAAa,QAAQ,EAAE,KAInC;KACR,QAJoB,aAAa,QAAQ,EAAE,KAInC;IACV;GACF;GAWA,OAAO;IACL,QAVa,KAAKC,wBAClB,OAAO,QACP,aAAa,QAAQ,CAQrB;IACA,QAPa,KAAKA,wBAClB,OAAO,QACP,aAAa,QAAQ,CAKrB;GACF;EACF;CACF;CAEA,wBACE,SACA,WACA;EACA,OAAO,QAAQ,KACb,eACA,SACF;CACF;CAEA,4BAA4B,WAAsB;EAChD,OAAO,QAAQ,QAAQ;GACrB,MAAM;GACN,OAAO;IACL,MAAM;IACN,SAAS,UAAU;GACrB;EACF,CAA8C;CAChD;CAEA,mCAAmC,kBAAoC;EACrE,OAAO,QAAQ,QAAQ;GACrB,MAAM;GACN,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB;IAC1B,SAAS,iBAAiB;GAC5B;EACF,CAA8C;CAChD;AACF"}
1
+ {"version":3,"file":"mutator-proxy.js","names":["#lc","#connectionManager","#mutationTracker","#onConnectionStateChange","#mutationRejection","#makeZeroErrorResultDetails","#makeApplicationErrorResultDetails","#normalizeResultPromise"],"sources":["../../../../../zero-client/src/client/mutator-proxy.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport {unreachable} from '../../../shared/src/asserts.ts';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport type {ApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {wrapWithApplicationError} from '../../../zero-protocol/src/application-error.ts';\nimport {ClientErrorKind} from './client-error-kind.ts';\nimport type {\n ConnectionManager,\n ConnectionManagerState,\n} from './connection-manager.ts';\nimport {ConnectionStatus} from './connection-status.ts';\nimport type {\n MutatorResult,\n MutatorResultErrorDetails,\n MutatorResultSuccessDetails,\n} from './custom.ts';\nimport {isZeroError, type ZeroError} from './error.ts';\nimport type {MutationTracker} from './mutation-tracker.ts';\n\nconst successResultDetails = {\n type: 'success',\n} as const satisfies MutatorResultSuccessDetails;\nconst successResult = () => successResultDetails;\n\nfunction getStateDescription(error: ZeroError): string {\n switch (error.kind) {\n case ClientErrorKind.Offline:\n return 'offline';\n case ClientErrorKind.ClientClosed:\n return 'closed';\n default:\n return 'in error state';\n }\n}\n\ntype CachedMutationRejection = {\n readonly error: ZeroError;\n readonly promise: Promise<MutatorResultErrorDetails>;\n};\n\nexport class MutatorProxy {\n readonly #lc: LogContext;\n readonly #connectionManager: ConnectionManager;\n readonly #mutationTracker: MutationTracker;\n #mutationRejection: CachedMutationRejection | undefined;\n\n constructor(\n lc: LogContext,\n connectionManager: ConnectionManager,\n mutationTracker: MutationTracker,\n ) {\n this.#lc = lc;\n this.#connectionManager = connectionManager;\n this.#mutationTracker = mutationTracker;\n\n this.#connectionManager.subscribe(state =>\n this.#onConnectionStateChange(state),\n );\n this.#onConnectionStateChange(connectionManager.state);\n }\n\n get mutationRejectionError(): ZeroError | undefined {\n return this.#mutationRejection?.error;\n }\n\n /**\n * Called when the connection state changes.\n *\n * If the connection state is disconnected, error, or closed, the\n * mutation rejection error is set and all outstanding `.server` promises in\n * the mutation tracker are rejected with the error.\n */\n #onConnectionStateChange(state: ConnectionManagerState) {\n // we short circuit the rejection if the error is due to a missing cacheURL\n // this allows local writes to continue\n if (\n state.name === ConnectionStatus.Disconnected &&\n state.reason.kind === ClientErrorKind.NoSocketOrigin\n ) {\n this.#mutationRejection = undefined;\n return;\n }\n\n switch (state.name) {\n case ConnectionStatus.Disconnected:\n case ConnectionStatus.Error:\n case ConnectionStatus.Closed:\n this.#mutationRejection = {\n error: state.reason,\n promise: Promise.resolve(\n this.#makeZeroErrorResultDetails(state.reason),\n ),\n };\n this.#mutationTracker.rejectAllOutstandingMutations(state.reason);\n break;\n case ConnectionStatus.Initializing:\n case ConnectionStatus.Connected:\n case ConnectionStatus.Connecting:\n case ConnectionStatus.NeedsAuth:\n this.#mutationRejection = undefined;\n return;\n default:\n unreachable(state);\n }\n }\n\n wrapCustomMutator<\n F extends (...args: [] | [ReadonlyJSONValue]) => {\n client: Promise<unknown>;\n server: Promise<unknown>;\n },\n >(name: string, f: F): (...args: Parameters<F>) => MutatorResult {\n return (...args) => {\n if (this.#mutationRejection) {\n const error = this.#mutationRejection.error;\n this.#lc.warn?.(\n `Mutation \"${name}\" rejected because Zero is ${getStateDescription(error)}. Details: ${error.message}. See also: https://zero.rocicorp.dev/docs/connection.`,\n );\n return {\n client: this.#mutationRejection.promise,\n server: this.#mutationRejection.promise,\n } as const satisfies MutatorResult;\n }\n\n let result: {\n client: Promise<unknown>;\n server: Promise<unknown>;\n };\n\n const cachedMutationPromises: Partial<\n Record<'client' | 'server', Promise<MutatorResultErrorDetails>>\n > = {};\n\n const wrapErrorFor =\n (origin: 'client' | 'server') =>\n (error: unknown): Promise<MutatorResultErrorDetails> => {\n const cachedPromise = cachedMutationPromises[origin];\n if (cachedPromise) {\n return cachedPromise;\n }\n\n if (isZeroError(error)) {\n this.#lc.error?.(`Mutator \"${name}\" error on ${origin}`, error);\n\n const zeroErrorPromise = this.#makeZeroErrorResultDetails(error);\n cachedMutationPromises[origin] = zeroErrorPromise;\n return zeroErrorPromise;\n }\n\n const applicationError = wrapWithApplicationError(error);\n this.#lc.error?.(\n `Mutator \"${name}\" app error on ${origin}`,\n applicationError,\n );\n\n const applicationErrorPromise =\n this.#makeApplicationErrorResultDetails(applicationError);\n cachedMutationPromises[origin] = applicationErrorPromise;\n return applicationErrorPromise;\n };\n\n try {\n result = f(...args);\n } catch (error) {\n const clientPromise = wrapErrorFor('client')(error);\n const serverPromise = wrapErrorFor('server')(error);\n\n return {\n client: clientPromise,\n server: serverPromise,\n } as const satisfies MutatorResult;\n }\n\n const client = this.#normalizeResultPromise(\n result.client,\n wrapErrorFor('client'),\n );\n const server = this.#normalizeResultPromise(\n result.server,\n wrapErrorFor('server'),\n );\n\n return {\n client,\n server,\n };\n };\n }\n\n #normalizeResultPromise(\n promise: Promise<unknown>,\n wrapError: (error: unknown) => Promise<MutatorResultErrorDetails>,\n ) {\n return promise.then<MutatorResultSuccessDetails, MutatorResultErrorDetails>(\n successResult,\n wrapError,\n );\n }\n\n #makeZeroErrorResultDetails(zeroError: ZeroError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'zero',\n message: zeroError.message,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n\n #makeApplicationErrorResultDetails(applicationError: ApplicationError) {\n return Promise.resolve({\n type: 'error',\n error: {\n type: 'app',\n message: applicationError.message,\n details: applicationError.details,\n },\n } as const satisfies MutatorResultErrorDetails);\n }\n}\n"],"mappings":";;;;;;AAmBA,IAAM,uBAAuB,EAC3B,MAAM,UACR;AACA,IAAM,sBAAsB;AAE5B,SAAS,oBAAoB,OAA0B;CACrD,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAOA,IAAa,eAAb,MAA0B;CACxB;CACA;CACA;CACA;CAEA,YACE,IACA,mBACA,iBACA;EACA,KAAKA,MAAM;EACX,KAAKC,qBAAqB;EAC1B,KAAKC,mBAAmB;EAExB,KAAKD,mBAAmB,WAAU,UAChC,KAAKE,yBAAyB,KAAK,CACrC;EACA,KAAKA,yBAAyB,kBAAkB,KAAK;CACvD;CAEA,IAAI,yBAAgD;EAClD,OAAO,KAAKC,oBAAoB;CAClC;;;;;;;;CASA,yBAAyB,OAA+B;EAGtD,IACE,MAAM,SAAS,kBACf,MAAM,OAAO,SAAS,kBACtB;GACA,KAAKA,qBAAqB,KAAA;GAC1B;EACF;EAEA,QAAQ,MAAM,MAAd;GACE,KAAK;GACL,KAAK;GACL,KAAK;IACH,KAAKA,qBAAqB;KACxB,OAAO,MAAM;KACb,SAAS,QAAQ,QACf,KAAKC,4BAA4B,MAAM,MAAM,CAC/C;IACF;IACA,KAAKH,iBAAiB,8BAA8B,MAAM,MAAM;IACh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AAsB;EAChD,OAAO,QAAQ,QAAQ;GACrB,MAAM;GACN,OAAO;IACL,MAAM;IACN,SAAS,UAAU;GACrB;EACF,CAA8C;CAChD;CAEA,mCAAmC,kBAAoC;EACrE,OAAO,QAAQ,QAAQ;GACrB,MAAM;GACN,OAAO;IACL,MAAM;IACN,SAAS,iBAAiB;IAC1B,SAAS,iBAAiB;GAC5B;EACF,CAA8C;CAChD;AACF"}
@@ -213,6 +213,9 @@ export type ZeroOptions<S extends BaseDefaultSchema = DefaultSchema, MD extends
213
213
  * - the local persistent synchronization state has been garbage collected.
214
214
  * This can happen if the client has no pending mutations and has not been
215
215
  * used for a while (e.g. the client's tab has been hidden for a long time).
216
+ * - the local persistent synchronization state was found to be corrupt.
217
+ * Replicache tries to drop the local database so that a reload starts
218
+ * fresh. The callback is called even if that fails.
216
219
  * - zero-cache fails to find the server side synchronization state for
217
220
  * this client.
218
221
  * - zero-cache rejects this client's persisted synchronization state,
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../../zero-client/src/client/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,EAAE,OAAO,EAAC,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,KAAK,CAAC,MAAM,+BAA+B,CAAC;AACnD,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACd,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,6CAA6C,CAAC;AACpF,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AACnD,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,iBAAiB,GAAG,aAAa,EAC3C,EAAE,SAAS,iBAAiB,GAAG,SAAS,GA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;CACzB,GAAG,CAAC,OAAO,SAAS,cAAc,GAC/B,EAAE,GACF;IACE,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC,CAAC;AAEP;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,CAAC,SAAS,iBAAiB,EAC3B,EAAE,SAAS,iBAAiB,GAAG,SAAS,EACxC,OAAO,SAAS,kBAAkB,IAChC,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAEhC,KAAK,sBAAsB,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC1B,CAAC;IAAC,IAAI,EAAE,sBAAsB,CAAC,cAAc,CAAA;CAAC,GAAG,sBAAsB,CAAC,GACxE,CAAC;IACC,IAAI,EAAE,sBAAsB,CAAC,mBAAmB,CAAC;CAClD,GAAG,sBAAsB,CAAC,GAC3B,CAAC;IACC,IAAI,EAAE,sBAAsB,CAAC,yBAAyB,CAAC;CACxD,GAAG,sBAAsB,CAAC,CAAC;AAEhC,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAKzE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","names":[],"sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel, LogSink} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n BaseDefaultContext,\n BaseDefaultSchema,\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {AnyMutatorRegistry} from '../../../zql/src/mutate/mutator-registry.ts';\nimport type {CustomMutatorDefs} from './custom.ts';\nimport {UpdateNeededReasonType} from './update-needed-reason-type.ts';\n\n/**\n * Configuration for {@linkcode Zero}.\n */\nexport type ZeroOptions<\n S extends BaseDefaultSchema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C extends BaseDefaultContext = DefaultContext,\n> = {\n /**\n * URL to the zero-cache. This can be a simple hostname, e.g.\n * - \"https://myapp-myteam.zero.ms\"\n * or a prefix with a single path component, e.g.\n * - \"https://myapp-myteam.zero.ms/zero\"\n * - \"https://myapp-myteam.zero.ms/db\"\n *\n * The latter is useful for configuring routing rules (e.g. \"/zero/\\*\") when\n * the zero-cache is hosted on the same domain as the application. **Note that\n * only a single path segment is allowed (e.g. it cannot be \"/proxy/zero/\\*\")**.\n */\n cacheURL?: string | null | undefined;\n\n /**\n * @deprecated Use {@linkcode cacheURL} instead.\n */\n server?: string | null | undefined;\n\n /**\n * A token to identify and authenticate the user.\n *\n * Set `auth` to `null` or `undefined` if there is no logged in user.\n *\n * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n *\n * Transitions between authenticated and logged-out states recreate the Zero\n * instance instead.\n *\n * When `auth` changes while connected, Zero refreshes server-side auth context\n * and re-transforms queries without reconnecting.\n *\n * When a 401 or 403 HTTP status code is received from your server, Zero will\n * transition to the `needs-auth` connection state. The app should call\n * `zero.connection.connect({auth: newToken})` with a new token to reconnect.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user.\n *\n * Omit this, or set to `null`, for logged-out clients.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n */\n userID?: string | null | undefined;\n\n /**\n * Distinguishes the storage used by this Zero instance from that of other\n * instances with the same userID. Useful in the case where the app wants to\n * have multiple Zero instances for the same user for different parts of the\n * app.\n */\n storageKey?: string | undefined;\n\n /**\n * Determines the level of detail at which Zero logs messages about\n * its operation. Messages are logged to the `console`.\n *\n * When this is set to `'debug'`, `'info'` and `'error'` messages are also\n * logged. When set to `'info'`, `'info'` and `'error'` but not\n * `'debug'` messages are logged. When set to `'error'` only `'error'`\n * messages are logged.\n *\n * Default is `'error'`.\n */\n logLevel?: LogLevel | undefined;\n\n /**\n * Destination for Zero's log output. When omitted, logs are written with\n * `console.log`/`info`/`warn`/`error` etc.\n *\n * Provide a custom {@linkcode LogSink} to redirect logs — for example, to\n * `process.stderr` in a CLI so that the tool's structured stdout output\n * isn't polluted by log lines.\n *\n * Note: this overrides only the console sink. When analytics logging is\n * enabled, the Datadog sink is still installed alongside this one.\n */\n logSink?: LogSink | undefined;\n\n /**\n * This defines the schema of the tables used in Zero and their relationships\n * to one another.\n */\n schema: S;\n\n /**\n * `mutators` is a map of custom mutator definitions. The keys are\n * namespaces or names of the mutators. The values are the mutator\n * implementations. Client side mutators must be idempotent as a\n * mutation can be rebased multiple times when folding in authoritative\n * changes from the server to the client.\n *\n * Define mutators using the `defineMutator` function to create type-safe,\n * parameterized mutations. Mutators can be top-level or grouped in namespaces.\n *\n * @example\n * ```ts\n * import {defineMutator} from '@rocicorp/zero';\n *\n * const z = new Zero({\n * schema,\n * userID,\n * mutators: {\n * // Top-level mutator\n * increment: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.counter.update({id: args.id, value: tx.query.counter.where('id', '=', args.id).value + 1})\n * ),\n * // Namespace with multiple mutators\n * issues: {\n * create: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {title: string}}) =>\n * tx.mutate.issues.insert({id: nanoid(), title: args.title, status: 'open'})\n * ),\n * close: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.issues.update({id: args.id, status: 'closed'})\n * ),\n * },\n * },\n * });\n *\n * // Usage\n * await z.mutate.increment({id: 'counter-1'}).client;\n * await z.mutate.issues.create({title: 'New issue'}).client;\n * await z.mutate.issues.close({id: 'issue-123'}).client;\n * ```\n */\n mutators?: MD extends CustomMutatorDefs ? MD : AnyMutatorRegistry | undefined;\n\n /**\n * Custom URL for mutation requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n mutateURL?: string | undefined;\n\n /**\n * Custom headers to include in mutation requests sent to your API server.\n * These headers are passed through zero-cache to the mutate endpoint.\n */\n mutateHeaders?: Record<string, string> | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n *\n * @deprecated Use {@linkcode queryURL} instead.\n */\n getQueriesURL?: string | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n queryURL?: string | undefined;\n\n /**\n * Custom headers to include in query requests sent to your API server.\n * These headers are passed through zero-cache to the query endpoint.\n */\n queryHeaders?: Record<string, string> | undefined;\n\n /**\n * Optional callback that returns a W3C `traceparent` header value for\n * distributed tracing. Called before sending WebSocket messages that\n * trigger API server calls (`push`, `changeDesiredQueries`,\n * `initConnection`).\n *\n * This enables end-to-end trace correlation from your frontend through\n * zero-cache to your API server.\n *\n * @example\n * ```ts\n * import {propagation, context} from '@opentelemetry/api';\n *\n * new Zero({\n * getTraceparent: () => {\n * const carrier: Record<string, string> = {};\n * propagation.inject(context.active(), carrier);\n * return carrier.traceparent;\n * },\n * });\n * ```\n */\n getTraceparent?: (() => string | undefined) | undefined;\n\n /**\n * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@linkcode Connection.state.subscribe} on the Zero instance instead. e.g.\n * ```ts\n * const zero = new Zero({...});\n * zero.connection.state.subscribe((state) => {\n * console.log('Connection state:', state.name);\n * });\n * ```\n *\n * Or use a hook like {@linkcode useConnectionState} to subscribe to state changes.\n */\n onOnlineChange?: ((online: boolean) => void) | undefined;\n\n /**\n * `onUpdateNeeded` is called when a client code update is needed.\n *\n * See {@link UpdateNeededReason} for why updates can be needed.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from\n * reloading automatically. You may want to display a toast to inform the end\n * user there is a new version of your app available and prompt them to\n * refresh.\n */\n onUpdateNeeded?: ((reason: UpdateNeededReason) => void) | undefined;\n\n /**\n * `onClientStateNotFound` is called when this client is no longer able\n * to sync with zero-cache due to missing synchronization state. This\n * can be because:\n * - the local persistent synchronization state has been garbage collected.\n * This can happen if the client has no pending mutations and has not been\n * used for a while (e.g. the client's tab has been hidden for a long time).\n * - zero-cache fails to find the server side synchronization state for\n * this client.\n * - zero-cache rejects this client's persisted synchronization state,\n * requiring the local Replicache database to be reset.\n *\n * The current `Zero` instance should be treated as dead and replaced, not\n * reconnected.\n *\n * The default behavior for the Zero client is to reload the page\n * (using `location.reload()`). The React and SolidJS providers will replace\n * the client in-place, without a full page reload.\n *\n * Provide your own function to prevent this functionality.\n */\n onClientStateNotFound?: (() => void) | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance whose tab has become hidden.\n *\n * Instances in hidden tabs are disconnected to save resources.\n *\n * Default is 5 minutes.\n */\n hiddenTabDisconnectDelay?: number | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance when the connection to the server has timed out.\n *\n * Default is 1 minute.\n */\n disconnectTimeoutMs?: number | undefined;\n\n /**\n * The timeout in milliseconds for ping operations. This value is used for:\n * - How long to wait in idle before sending a ping to the server\n * - How long to wait for a pong response after sending a ping\n *\n * Total time to detect a dead connection is 2 × pingTimeoutMs.\n *\n * Default is 5_000.\n */\n pingTimeoutMs?: number | undefined;\n\n /**\n * Determines what kind of storage implementation to use on the client.\n *\n * Defaults to `'idb'` which means that Zero uses an IndexedDB storage\n * implementation. This allows the data to be persisted on the client and\n * enables faster syncs between application restarts.\n *\n * By setting this to `'mem'`, Zero uses an in memory storage and\n * the data is not persisted on the client.\n *\n * You can also set this to a function that is used to create new KV stores,\n * allowing a custom implementation of the underlying storage layer.\n */\n kvStore?: 'mem' | 'idb' | StoreProvider | undefined;\n\n /**\n * The maximum number of bytes to allow in a single header.\n *\n * Zero adds some extra information to headers on initialization if possible.\n * This speeds up data synchronization. This number should be kept less than\n * or equal to the maximum header size allowed by the zero-cache and any load\n * balancers.\n *\n * Default value: 8kb.\n */\n maxHeaderLength?: number | undefined;\n\n /**\n * The maximum amount of milliseconds to wait for a materialization to\n * complete (including network/server time) before printing a warning to the\n * console.\n *\n * Default value: 5_000.\n */\n slowMaterializeThreshold?: number | undefined;\n\n /**\n * UI rendering libraries will often provide a utility for batching multiple\n * state updates into a single render. Some examples are React's\n * `unstable_batchedUpdates`, and solid-js's `batch`.\n *\n * This option enables integrating these batch utilities with Zero.\n *\n * When `batchViewUpdates` is provided, Zero will call it whenever\n * it updates query view state with an `applyViewUpdates` function\n * that performs the actual state updates.\n *\n * Zero updates query view state when:\n * 1. creating a new view\n * 2. updating all existing queries' views to a new consistent state\n *\n * When creating a new view, that single view's creation will be wrapped\n * in a `batchViewUpdates` call.\n *\n * When updating existing queries, all queries will be updated in a single\n * `batchViewUpdates` call, so that the transition to the new consistent\n * state can be done in a single render.\n *\n * Implementations must always call `applyViewUpdates` synchronously.\n */\n batchViewUpdates?: ((applyViewUpdates: () => void) => void) | undefined;\n\n /**\n * The maximum number of recent queries, no longer subscribed to by a preload\n * or view, to continue syncing.\n *\n * Defaults is 0.\n *\n * @deprecated Use ttl instead\n */\n maxRecentQueries?: number | undefined;\n\n /**\n * Changes to queries are sent to server in batches. This option controls\n * the number of milliseconds to wait before sending the next batch.\n *\n * Defaults is 10.\n */\n queryChangeThrottleMs?: number | undefined;\n\n /**\n * Context is passed to queries when they are executed.\n */\n context?: C | undefined;\n} & (unknown extends DefaultContext\n ? {}\n : {\n context: C;\n });\n\n/**\n * @deprecated Use {@link ZeroOptions} instead.\n */\nexport type ZeroAdvancedOptions<\n S extends BaseDefaultSchema,\n MD extends CustomMutatorDefs | undefined,\n Context extends BaseDefaultContext,\n> = ZeroOptions<S, MD, Context>;\n\ntype UpdateNeededReasonBase = {\n message?: string;\n};\n\nexport type UpdateNeededReason =\n | ({type: UpdateNeededReasonType.NewClientGroup} & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.VersionNotSupported;\n } & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.SchemaVersionNotSupported;\n } & UpdateNeededReasonBase);\n\nexport const updateNeededReasonTypeSchema: v.Type<UpdateNeededReason['type']> =\n v.literalUnion(\n UpdateNeededReasonType.NewClientGroup,\n UpdateNeededReasonType.VersionNotSupported,\n UpdateNeededReasonType.SchemaVersionNotSupported,\n );\n"],"mappings":";;;AA+YA,IAAa,+BACX,aACE,gBACA,qBACA,yBACF"}
1
+ {"version":3,"file":"options.js","names":[],"sources":["../../../../../zero-client/src/client/options.ts"],"sourcesContent":["import type {LogLevel, LogSink} from '@rocicorp/logger';\nimport type {StoreProvider} from '../../../replicache/src/kv/store.ts';\nimport * as v from '../../../shared/src/valita.ts';\nimport type {\n BaseDefaultContext,\n BaseDefaultSchema,\n DefaultContext,\n DefaultSchema,\n} from '../../../zero-types/src/default-types.ts';\nimport type {AnyMutatorRegistry} from '../../../zql/src/mutate/mutator-registry.ts';\nimport type {CustomMutatorDefs} from './custom.ts';\nimport {UpdateNeededReasonType} from './update-needed-reason-type.ts';\n\n/**\n * Configuration for {@linkcode Zero}.\n */\nexport type ZeroOptions<\n S extends BaseDefaultSchema = DefaultSchema,\n MD extends CustomMutatorDefs | undefined = undefined,\n C extends BaseDefaultContext = DefaultContext,\n> = {\n /**\n * URL to the zero-cache. This can be a simple hostname, e.g.\n * - \"https://myapp-myteam.zero.ms\"\n * or a prefix with a single path component, e.g.\n * - \"https://myapp-myteam.zero.ms/zero\"\n * - \"https://myapp-myteam.zero.ms/db\"\n *\n * The latter is useful for configuring routing rules (e.g. \"/zero/\\*\") when\n * the zero-cache is hosted on the same domain as the application. **Note that\n * only a single path segment is allowed (e.g. it cannot be \"/proxy/zero/\\*\")**.\n */\n cacheURL?: string | null | undefined;\n\n /**\n * @deprecated Use {@linkcode cacheURL} instead.\n */\n server?: string | null | undefined;\n\n /**\n * A token to identify and authenticate the user.\n *\n * Set `auth` to `null` or `undefined` if there is no logged in user.\n *\n * The call to `connect` is handled automatically by the ZeroProvider component\n * for React and SolidJS when the `auth` prop changes.\n *\n * Transitions between authenticated and logged-out states recreate the Zero\n * instance instead.\n *\n * When `auth` changes while connected, Zero refreshes server-side auth context\n * and re-transforms queries without reconnecting.\n *\n * When a 401 or 403 HTTP status code is received from your server, Zero will\n * transition to the `needs-auth` connection state. The app should call\n * `zero.connection.connect({auth: newToken})` with a new token to reconnect.\n */\n auth?: string | null | undefined;\n\n /**\n * A unique identifier for the user.\n *\n * Omit this, or set to `null`, for logged-out clients.\n *\n * Each userID gets its own client-side storage so that the app can switch\n * between users without losing state.\n */\n userID?: string | null | undefined;\n\n /**\n * Distinguishes the storage used by this Zero instance from that of other\n * instances with the same userID. Useful in the case where the app wants to\n * have multiple Zero instances for the same user for different parts of the\n * app.\n */\n storageKey?: string | undefined;\n\n /**\n * Determines the level of detail at which Zero logs messages about\n * its operation. Messages are logged to the `console`.\n *\n * When this is set to `'debug'`, `'info'` and `'error'` messages are also\n * logged. When set to `'info'`, `'info'` and `'error'` but not\n * `'debug'` messages are logged. When set to `'error'` only `'error'`\n * messages are logged.\n *\n * Default is `'error'`.\n */\n logLevel?: LogLevel | undefined;\n\n /**\n * Destination for Zero's log output. When omitted, logs are written with\n * `console.log`/`info`/`warn`/`error` etc.\n *\n * Provide a custom {@linkcode LogSink} to redirect logs — for example, to\n * `process.stderr` in a CLI so that the tool's structured stdout output\n * isn't polluted by log lines.\n *\n * Note: this overrides only the console sink. When analytics logging is\n * enabled, the Datadog sink is still installed alongside this one.\n */\n logSink?: LogSink | undefined;\n\n /**\n * This defines the schema of the tables used in Zero and their relationships\n * to one another.\n */\n schema: S;\n\n /**\n * `mutators` is a map of custom mutator definitions. The keys are\n * namespaces or names of the mutators. The values are the mutator\n * implementations. Client side mutators must be idempotent as a\n * mutation can be rebased multiple times when folding in authoritative\n * changes from the server to the client.\n *\n * Define mutators using the `defineMutator` function to create type-safe,\n * parameterized mutations. Mutators can be top-level or grouped in namespaces.\n *\n * @example\n * ```ts\n * import {defineMutator} from '@rocicorp/zero';\n *\n * const z = new Zero({\n * schema,\n * userID,\n * mutators: {\n * // Top-level mutator\n * increment: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.counter.update({id: args.id, value: tx.query.counter.where('id', '=', args.id).value + 1})\n * ),\n * // Namespace with multiple mutators\n * issues: {\n * create: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {title: string}}) =>\n * tx.mutate.issues.insert({id: nanoid(), title: args.title, status: 'open'})\n * ),\n * close: defineMutator(({tx, args}: {tx: Transaction<Schema>, args: {id: string}}) =>\n * tx.mutate.issues.update({id: args.id, status: 'closed'})\n * ),\n * },\n * },\n * });\n *\n * // Usage\n * await z.mutate.increment({id: 'counter-1'}).client;\n * await z.mutate.issues.create({title: 'New issue'}).client;\n * await z.mutate.issues.close({id: 'issue-123'}).client;\n * ```\n */\n mutators?: MD extends CustomMutatorDefs ? MD : AnyMutatorRegistry | undefined;\n\n /**\n * Custom URL for mutation requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n mutateURL?: string | undefined;\n\n /**\n * Custom headers to include in mutation requests sent to your API server.\n * These headers are passed through zero-cache to the mutate endpoint.\n */\n mutateHeaders?: Record<string, string> | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n *\n * @deprecated Use {@linkcode queryURL} instead.\n */\n getQueriesURL?: string | undefined;\n\n /**\n * Custom URL for query requests sent to your API server.\n * If not provided, uses the default configured in zero-cache.\n */\n queryURL?: string | undefined;\n\n /**\n * Custom headers to include in query requests sent to your API server.\n * These headers are passed through zero-cache to the query endpoint.\n */\n queryHeaders?: Record<string, string> | undefined;\n\n /**\n * Optional callback that returns a W3C `traceparent` header value for\n * distributed tracing. Called before sending WebSocket messages that\n * trigger API server calls (`push`, `changeDesiredQueries`,\n * `initConnection`).\n *\n * This enables end-to-end trace correlation from your frontend through\n * zero-cache to your API server.\n *\n * @example\n * ```ts\n * import {propagation, context} from '@opentelemetry/api';\n *\n * new Zero({\n * getTraceparent: () => {\n * const carrier: Record<string, string> = {};\n * propagation.inject(context.active(), carrier);\n * return carrier.traceparent;\n * },\n * });\n * ```\n */\n getTraceparent?: (() => string | undefined) | undefined;\n\n /**\n * `onOnlineChange` is called when the Zero instance's online status changes.\n *\n * @deprecated Use {@linkcode Connection.state.subscribe} on the Zero instance instead. e.g.\n * ```ts\n * const zero = new Zero({...});\n * zero.connection.state.subscribe((state) => {\n * console.log('Connection state:', state.name);\n * });\n * ```\n *\n * Or use a hook like {@linkcode useConnectionState} to subscribe to state changes.\n */\n onOnlineChange?: ((online: boolean) => void) | undefined;\n\n /**\n * `onUpdateNeeded` is called when a client code update is needed.\n *\n * See {@link UpdateNeededReason} for why updates can be needed.\n *\n * The default behavior is to reload the page (using `location.reload()`).\n * Provide your own function to prevent the page from\n * reloading automatically. You may want to display a toast to inform the end\n * user there is a new version of your app available and prompt them to\n * refresh.\n */\n onUpdateNeeded?: ((reason: UpdateNeededReason) => void) | undefined;\n\n /**\n * `onClientStateNotFound` is called when this client is no longer able\n * to sync with zero-cache due to missing synchronization state. This\n * can be because:\n * - the local persistent synchronization state has been garbage collected.\n * This can happen if the client has no pending mutations and has not been\n * used for a while (e.g. the client's tab has been hidden for a long time).\n * - the local persistent synchronization state was found to be corrupt.\n * Replicache tries to drop the local database so that a reload starts\n * fresh. The callback is called even if that fails.\n * - zero-cache fails to find the server side synchronization state for\n * this client.\n * - zero-cache rejects this client's persisted synchronization state,\n * requiring the local Replicache database to be reset.\n *\n * The current `Zero` instance should be treated as dead and replaced, not\n * reconnected.\n *\n * The default behavior for the Zero client is to reload the page\n * (using `location.reload()`). The React and SolidJS providers will replace\n * the client in-place, without a full page reload.\n *\n * Provide your own function to prevent this functionality.\n */\n onClientStateNotFound?: (() => void) | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance whose tab has become hidden.\n *\n * Instances in hidden tabs are disconnected to save resources.\n *\n * Default is 5 minutes.\n */\n hiddenTabDisconnectDelay?: number | undefined;\n\n /**\n * The number of milliseconds to wait before disconnecting a Zero\n * instance when the connection to the server has timed out.\n *\n * Default is 1 minute.\n */\n disconnectTimeoutMs?: number | undefined;\n\n /**\n * The timeout in milliseconds for ping operations. This value is used for:\n * - How long to wait in idle before sending a ping to the server\n * - How long to wait for a pong response after sending a ping\n *\n * Total time to detect a dead connection is 2 × pingTimeoutMs.\n *\n * Default is 5_000.\n */\n pingTimeoutMs?: number | undefined;\n\n /**\n * Determines what kind of storage implementation to use on the client.\n *\n * Defaults to `'idb'` which means that Zero uses an IndexedDB storage\n * implementation. This allows the data to be persisted on the client and\n * enables faster syncs between application restarts.\n *\n * By setting this to `'mem'`, Zero uses an in memory storage and\n * the data is not persisted on the client.\n *\n * You can also set this to a function that is used to create new KV stores,\n * allowing a custom implementation of the underlying storage layer.\n */\n kvStore?: 'mem' | 'idb' | StoreProvider | undefined;\n\n /**\n * The maximum number of bytes to allow in a single header.\n *\n * Zero adds some extra information to headers on initialization if possible.\n * This speeds up data synchronization. This number should be kept less than\n * or equal to the maximum header size allowed by the zero-cache and any load\n * balancers.\n *\n * Default value: 8kb.\n */\n maxHeaderLength?: number | undefined;\n\n /**\n * The maximum amount of milliseconds to wait for a materialization to\n * complete (including network/server time) before printing a warning to the\n * console.\n *\n * Default value: 5_000.\n */\n slowMaterializeThreshold?: number | undefined;\n\n /**\n * UI rendering libraries will often provide a utility for batching multiple\n * state updates into a single render. Some examples are React's\n * `unstable_batchedUpdates`, and solid-js's `batch`.\n *\n * This option enables integrating these batch utilities with Zero.\n *\n * When `batchViewUpdates` is provided, Zero will call it whenever\n * it updates query view state with an `applyViewUpdates` function\n * that performs the actual state updates.\n *\n * Zero updates query view state when:\n * 1. creating a new view\n * 2. updating all existing queries' views to a new consistent state\n *\n * When creating a new view, that single view's creation will be wrapped\n * in a `batchViewUpdates` call.\n *\n * When updating existing queries, all queries will be updated in a single\n * `batchViewUpdates` call, so that the transition to the new consistent\n * state can be done in a single render.\n *\n * Implementations must always call `applyViewUpdates` synchronously.\n */\n batchViewUpdates?: ((applyViewUpdates: () => void) => void) | undefined;\n\n /**\n * The maximum number of recent queries, no longer subscribed to by a preload\n * or view, to continue syncing.\n *\n * Defaults is 0.\n *\n * @deprecated Use ttl instead\n */\n maxRecentQueries?: number | undefined;\n\n /**\n * Changes to queries are sent to server in batches. This option controls\n * the number of milliseconds to wait before sending the next batch.\n *\n * Defaults is 10.\n */\n queryChangeThrottleMs?: number | undefined;\n\n /**\n * Context is passed to queries when they are executed.\n */\n context?: C | undefined;\n} & (unknown extends DefaultContext\n ? {}\n : {\n context: C;\n });\n\n/**\n * @deprecated Use {@link ZeroOptions} instead.\n */\nexport type ZeroAdvancedOptions<\n S extends BaseDefaultSchema,\n MD extends CustomMutatorDefs | undefined,\n Context extends BaseDefaultContext,\n> = ZeroOptions<S, MD, Context>;\n\ntype UpdateNeededReasonBase = {\n message?: string;\n};\n\nexport type UpdateNeededReason =\n | ({type: UpdateNeededReasonType.NewClientGroup} & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.VersionNotSupported;\n } & UpdateNeededReasonBase)\n | ({\n type: UpdateNeededReasonType.SchemaVersionNotSupported;\n } & UpdateNeededReasonBase);\n\nexport const updateNeededReasonTypeSchema: v.Type<UpdateNeededReason['type']> =\n v.literalUnion(\n UpdateNeededReasonType.NewClientGroup,\n UpdateNeededReasonType.VersionNotSupported,\n UpdateNeededReasonType.SchemaVersionNotSupported,\n );\n"],"mappings":";;;AAkZA,IAAa,+BACX,aACE,gBACA,qBACA,yBACF"}
@@ -69,8 +69,10 @@ export declare class QueryManager implements InspectorDelegate {
69
69
  message: string;
70
70
  }>): void;
71
71
  addCustom(ast: AST, { name, args }: CustomQueryID, ttl: TTL, gotCallback?: GotCallback): () => void;
72
+ /** @deprecated */
72
73
  addLegacy(ast: AST, ttl: TTL, gotCallback?: GotCallback): () => void;
73
74
  updateCustom({ name, args }: CustomQueryID, ttl: TTL): void;
75
+ /** @deprecated */
74
76
  updateLegacy(ast: AST, ttl: TTL): void;
75
77
  flushBatch(): void;
76
78
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"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AW,CAAC,EAAE,WAAW,GAAG,MAAM,IAAI;IAsFpE,YAAY,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG;IAMlD,kBAAkB;IAClB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAsC/B,UAAU;IAwCV;;OAEG;IACH,IAAI,OAAO,IAAI,YAAY,CAE1B;IAED,SAAS,CAAC,CAAC,SAAS,MAAM,eAAe,EACvC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,MAAM,EACb,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAC1B,IAAI;IA2DP,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAIlE;;OAEG;IACH,uBAAuB,IAAI,QAAQ,CAAC,MAAM,CAAC;CAG5C"}
@@ -2,12 +2,13 @@ import { assert, unreachable } from "../../../shared/src/asserts.js";
2
2
  import { must } from "../../../shared/src/must.js";
3
3
  import { mapAST, normalizeAST } from "../../../zero-protocol/src/ast.js";
4
4
  import { clientToServer, serverToClient } from "../../../zero-schema/src/name-mapper.js";
5
- import { hashOfAST, hashOfNameAndArgs } from "../../../zero-protocol/src/query-hash.js";
5
+ import { hashNameAndArgs } from "../../../zero-protocol/src/query-hash-visitor.js";
6
6
  import { TransformFailed } from "../../../zero-protocol/src/error-kind-enum.js";
7
7
  import { ZeroCache } from "../../../zero-protocol/src/error-origin-enum.js";
8
8
  import { Internal } from "../../../zero-protocol/src/error-reason-enum.js";
9
9
  import { ProtocolError } from "../../../zero-protocol/src/error.js";
10
10
  import "./error.js";
11
+ import { hashOfAST } from "../../../zero-protocol/src/query-hash.js";
11
12
  import { clampTTL, compareTTL } from "../../../zql/src/query/ttl.js";
12
13
  import { desiredQueriesPrefixForClient } from "./keys.js";
13
14
  import { difference } from "../../../shared/src/set-utils.js";
@@ -29,6 +30,8 @@ var QueryManager = class {
29
30
  #recentQueries = /* @__PURE__ */ new Set();
30
31
  #gotQueries = /* @__PURE__ */ new Set();
31
32
  #gotQueriesAuthoritative = false;
33
+ #cachedQueries = /* @__PURE__ */ new Set();
34
+ #awaitingPersistedGotDiff = true;
32
35
  #mutationTracker;
33
36
  #pendingQueryChanges = [];
34
37
  #queryChangeThrottleMs;
@@ -58,19 +61,32 @@ var QueryManager = class {
58
61
  for (const removal of pendingRemovals) removal();
59
62
  });
60
63
  experimentalWatch((diff) => {
64
+ const persisted = this.#awaitingPersistedGotDiff;
65
+ this.#awaitingPersistedGotDiff = false;
66
+ let thrown;
67
+ const fire = (queryHash, got) => {
68
+ const e = this.#fireGotCallbacks(queryHash, got);
69
+ thrown ??= e;
70
+ };
61
71
  for (const diffOp of diff) {
62
72
  const queryHash = diffOp.key.substring(2);
63
73
  switch (diffOp.op) {
64
74
  case "add":
65
75
  this.#gotQueries.add(queryHash);
66
- if (this.#gotQueriesAuthoritative) this.#fireGotCallbacks(queryHash, true);
76
+ if (this.#gotQueriesAuthoritative) fire(queryHash, true);
77
+ else if (persisted) {
78
+ this.#cachedQueries.add(queryHash);
79
+ fire(queryHash, "cached");
80
+ }
67
81
  break;
68
82
  case "del":
69
83
  this.#gotQueries.delete(queryHash);
70
- this.#fireGotCallbacks(queryHash, false);
84
+ this.#cachedQueries.delete(queryHash);
85
+ fire(queryHash, false);
71
86
  break;
72
87
  }
73
88
  }
89
+ if (thrown) throw thrown.error;
74
90
  }, {
75
91
  prefix: "g/",
76
92
  initialValuesInFirstDiff: true
@@ -86,9 +102,21 @@ var QueryManager = class {
86
102
  mapClientASTToServer(ast) {
87
103
  return mapAST(ast, this.#clientToServer);
88
104
  }
105
+ /**
106
+ * Notifies every subscriber of the query. A throwing subscriber does not
107
+ * keep the others from being notified; the first error is returned so the
108
+ * caller can rethrow it once its own bookkeeping is consistent.
109
+ */
89
110
  #fireGotCallbacks(queryHash, got) {
90
- const gotCallbacks = this.#queries.get(queryHash)?.gotCallbacks ?? [];
91
- for (const gotCallback of gotCallbacks) gotCallback(got);
111
+ const entry = this.#queries.get(queryHash);
112
+ if (!entry) return;
113
+ let thrown;
114
+ for (const gotCallback of [...entry.gotCallbacks]) try {
115
+ gotCallback(got);
116
+ } catch (error) {
117
+ thrown ??= { error };
118
+ }
119
+ return thrown;
92
120
  }
93
121
  /**
94
122
  * Trust `#gotQueries`. Called once the first poke after a (re)connect has
@@ -100,11 +128,20 @@ var QueryManager = class {
100
128
  markGotQueriesAuthoritative() {
101
129
  if (this.#gotQueriesAuthoritative) return;
102
130
  this.#gotQueriesAuthoritative = true;
103
- for (const queryHash of this.#queries.keys()) if (this.#gotQueries.has(queryHash)) this.#fireGotCallbacks(queryHash, true);
131
+ this.#cachedQueries.clear();
132
+ this.#awaitingPersistedGotDiff = false;
133
+ let thrown;
134
+ for (const queryHash of this.#queries.keys()) if (this.#gotQueries.has(queryHash)) {
135
+ const e = this.#fireGotCallbacks(queryHash, true);
136
+ thrown ??= e;
137
+ }
138
+ if (thrown) throw thrown.error;
104
139
  }
105
140
  /** Called on disconnect. The next connect must re-confirm `#gotQueries`. */
106
141
  clearGotQueriesAuthoritative() {
142
+ if (!this.#gotQueriesAuthoritative) return;
107
143
  this.#gotQueriesAuthoritative = false;
144
+ for (const queryHash of this.#gotQueries) this.#cachedQueries.add(queryHash);
108
145
  }
109
146
  /**
110
147
  * Get the queries that need to be registered with the server.
@@ -181,9 +218,10 @@ var QueryManager = class {
181
218
  }
182
219
  addCustom(ast, { name, args }, ttl, gotCallback) {
183
220
  const normalized = normalizeAST(ast);
184
- const queryId = hashOfNameAndArgs(name, args);
221
+ const queryId = hashNameAndArgs(name, args);
185
222
  return this.#add(queryId, normalized, name, args, ttl, gotCallback);
186
223
  }
224
+ /** @deprecated */
187
225
  addLegacy(ast, ttl, gotCallback) {
188
226
  const normalized = normalizeAST(ast);
189
227
  const astHash = hashOfAST(normalized);
@@ -218,7 +256,7 @@ var QueryManager = class {
218
256
  this.#updateEntry(entry, queryId, ttl);
219
257
  if (gotCallback) entry.gotCallbacks.push(gotCallback);
220
258
  }
221
- if (gotCallback) gotCallback(this.#gotQueriesAuthoritative && this.#gotQueries.has(queryId));
259
+ if (gotCallback) gotCallback(this.#gotQueriesAuthoritative ? this.#gotQueries.has(queryId) : this.#cachedQueries.has(queryId) && "cached");
222
260
  let removed = false;
223
261
  const cleanupCb = () => {
224
262
  if (removed) return;
@@ -232,10 +270,11 @@ var QueryManager = class {
232
270
  return cleanupCb;
233
271
  }
234
272
  updateCustom({ name, args }, ttl) {
235
- const queryID = hashOfNameAndArgs(name, args);
273
+ const queryID = hashNameAndArgs(name, args);
236
274
  const entry = must(this.#queries.get(queryID));
237
275
  this.#updateEntry(entry, queryID, ttl);
238
276
  }
277
+ /** @deprecated */
239
278
  updateLegacy(ast, ttl) {
240
279
  const queryID = hashOfAST(normalizeAST(ast));
241
280
  const entry = must(this.#queries.get(queryID));