@rocicorp/zero 0.25.0-canary.11 → 0.25.0-canary.13

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 (164) hide show
  1. package/out/zero/package.json.js +1 -1
  2. package/out/zero/src/pg.js +4 -2
  3. package/out/zero/src/server.js +4 -2
  4. package/out/zero-cache/src/server/otel-diag-logger.js +1 -0
  5. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  6. package/out/zero-client/src/client/bindings.d.ts +2 -3
  7. package/out/zero-client/src/client/bindings.d.ts.map +1 -1
  8. package/out/zero-client/src/client/bindings.js.map +1 -1
  9. package/out/zero-client/src/client/connection-manager.d.ts +3 -3
  10. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  11. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  12. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  13. package/out/zero-client/src/client/connection.js +8 -1
  14. package/out/zero-client/src/client/connection.js.map +1 -1
  15. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  16. package/out/zero-client/src/client/custom.js +4 -3
  17. package/out/zero-client/src/client/custom.js.map +1 -1
  18. package/out/zero-client/src/client/error.d.ts +6 -1
  19. package/out/zero-client/src/client/error.d.ts.map +1 -1
  20. package/out/zero-client/src/client/error.js +2 -2
  21. package/out/zero-client/src/client/error.js.map +1 -1
  22. package/out/zero-client/src/client/make-mutate-property.d.ts +6 -9
  23. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
  24. package/out/zero-client/src/client/make-mutate-property.js +3 -8
  25. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  26. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  27. package/out/zero-client/src/client/mutator-proxy.d.ts +3 -2
  28. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
  29. package/out/zero-client/src/client/mutator-proxy.js +15 -3
  30. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  31. package/out/zero-client/src/client/options.d.ts +3 -3
  32. package/out/zero-client/src/client/options.d.ts.map +1 -1
  33. package/out/zero-client/src/client/options.js.map +1 -1
  34. package/out/zero-client/src/client/version.js +1 -1
  35. package/out/zero-client/src/client/zero.d.ts +1 -2
  36. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  37. package/out/zero-client/src/client/zero.js +8 -8
  38. package/out/zero-client/src/client/zero.js.map +1 -1
  39. package/out/zero-client/src/mod.d.ts +5 -7
  40. package/out/zero-client/src/mod.d.ts.map +1 -1
  41. package/out/zero-react/src/components/inspector.d.ts +1 -2
  42. package/out/zero-react/src/components/inspector.d.ts.map +1 -1
  43. package/out/zero-react/src/components/inspector.js.map +1 -1
  44. package/out/zero-react/src/components/zero-inspector.d.ts +1 -2
  45. package/out/zero-react/src/components/zero-inspector.d.ts.map +1 -1
  46. package/out/zero-react/src/components/zero-inspector.js.map +1 -1
  47. package/out/zero-react/src/use-query.d.ts +1 -2
  48. package/out/zero-react/src/use-query.d.ts.map +1 -1
  49. package/out/zero-react/src/use-query.js.map +1 -1
  50. package/out/zero-react/src/zero-provider.d.ts +4 -5
  51. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  52. package/out/zero-react/src/zero-provider.js.map +1 -1
  53. package/out/zero-schema/src/permissions.d.ts +3 -0
  54. package/out/zero-schema/src/permissions.d.ts.map +1 -1
  55. package/out/zero-schema/src/permissions.js.map +1 -1
  56. package/out/zero-server/src/mod.d.ts +1 -1
  57. package/out/zero-server/src/mod.d.ts.map +1 -1
  58. package/out/zero-server/src/process-mutations.d.ts +10 -6
  59. package/out/zero-server/src/process-mutations.d.ts.map +1 -1
  60. package/out/zero-server/src/process-mutations.js +9 -18
  61. package/out/zero-server/src/process-mutations.js.map +1 -1
  62. package/out/zero-server/src/push-processor.d.ts.map +1 -1
  63. package/out/zero-server/src/push-processor.js +10 -8
  64. package/out/zero-server/src/push-processor.js.map +1 -1
  65. package/out/zero-server/src/queries/process-queries.d.ts +14 -2
  66. package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
  67. package/out/zero-server/src/queries/process-queries.js +18 -15
  68. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  69. package/out/zero-solid/src/use-zero.d.ts +4 -5
  70. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  71. package/out/zero-solid/src/use-zero.js.map +1 -1
  72. package/out/zero-types/src/default-types.d.ts +2 -2
  73. package/out/zero-types/src/default-types.d.ts.map +1 -1
  74. package/out/zql/src/builder/builder.d.ts.map +1 -1
  75. package/out/zql/src/builder/builder.js +0 -1
  76. package/out/zql/src/builder/builder.js.map +1 -1
  77. package/out/zql/src/ivm/data.js +0 -11
  78. package/out/zql/src/ivm/data.js.map +1 -1
  79. package/out/zql/src/ivm/exists.d.ts +2 -2
  80. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  81. package/out/zql/src/ivm/exists.js +34 -20
  82. package/out/zql/src/ivm/exists.js.map +1 -1
  83. package/out/zql/src/ivm/fan-in.d.ts +1 -1
  84. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  85. package/out/zql/src/ivm/fan-in.js +4 -2
  86. package/out/zql/src/ivm/fan-in.js.map +1 -1
  87. package/out/zql/src/ivm/fan-out.d.ts +1 -1
  88. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  89. package/out/zql/src/ivm/fan-out.js +9 -3
  90. package/out/zql/src/ivm/fan-out.js.map +1 -1
  91. package/out/zql/src/ivm/filter-operators.d.ts +4 -6
  92. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  93. package/out/zql/src/ivm/filter-operators.js +14 -27
  94. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  95. package/out/zql/src/ivm/filter.d.ts +1 -1
  96. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  97. package/out/zql/src/ivm/filter.js +4 -2
  98. package/out/zql/src/ivm/filter.js.map +1 -1
  99. package/out/zql/src/ivm/flipped-join.d.ts +0 -1
  100. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  101. package/out/zql/src/ivm/flipped-join.js +0 -2
  102. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  103. package/out/zql/src/ivm/join.d.ts +2 -15
  104. package/out/zql/src/ivm/join.d.ts.map +1 -1
  105. package/out/zql/src/ivm/join.js +10 -83
  106. package/out/zql/src/ivm/join.js.map +1 -1
  107. package/out/zql/src/ivm/memory-source.d.ts +4 -3
  108. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  109. package/out/zql/src/ivm/memory-source.js +24 -23
  110. package/out/zql/src/ivm/memory-source.js.map +1 -1
  111. package/out/zql/src/ivm/operator.d.ts +0 -12
  112. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  113. package/out/zql/src/ivm/operator.js.map +1 -1
  114. package/out/zql/src/ivm/skip.d.ts +0 -1
  115. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  116. package/out/zql/src/ivm/skip.js +3 -11
  117. package/out/zql/src/ivm/skip.js.map +1 -1
  118. package/out/zql/src/ivm/take.d.ts +0 -1
  119. package/out/zql/src/ivm/take.d.ts.map +1 -1
  120. package/out/zql/src/ivm/take.js +0 -17
  121. package/out/zql/src/ivm/take.js.map +1 -1
  122. package/out/zql/src/ivm/union-fan-in.d.ts +0 -1
  123. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  124. package/out/zql/src/ivm/union-fan-in.js +0 -3
  125. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  126. package/out/zql/src/ivm/union-fan-out.d.ts +0 -1
  127. package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
  128. package/out/zql/src/ivm/union-fan-out.js +0 -3
  129. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  130. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  131. package/out/zql/src/ivm/view-apply-change.js +1 -2
  132. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  133. package/out/zql/src/mutate/custom.d.ts +2 -2
  134. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  135. package/out/zql/src/mutate/custom.js.map +1 -1
  136. package/out/zql/src/mutate/mutator-registry.d.ts +33 -15
  137. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  138. package/out/zql/src/mutate/mutator-registry.js +2 -8
  139. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  140. package/out/zql/src/mutate/mutator.d.ts +50 -25
  141. package/out/zql/src/mutate/mutator.d.ts.map +1 -1
  142. package/out/zql/src/mutate/mutator.js +2 -3
  143. package/out/zql/src/mutate/mutator.js.map +1 -1
  144. package/out/zql/src/query/create-builder.d.ts +2 -2
  145. package/out/zql/src/query/create-builder.d.ts.map +1 -1
  146. package/out/zql/src/query/create-builder.js +12 -3
  147. package/out/zql/src/query/create-builder.js.map +1 -1
  148. package/out/zql/src/query/measure-push-operator.d.ts +0 -1
  149. package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
  150. package/out/zql/src/query/measure-push-operator.js +0 -3
  151. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  152. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  153. package/out/zql/src/query/query-internals.js +2 -2
  154. package/out/zql/src/query/query-internals.js.map +1 -1
  155. package/out/zql/src/query/query-registry.d.ts +126 -58
  156. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  157. package/out/zql/src/query/query-registry.js +13 -21
  158. package/out/zql/src/query/query-registry.js.map +1 -1
  159. package/out/zql/src/query/query.d.ts +18 -5
  160. package/out/zql/src/query/query.d.ts.map +1 -1
  161. package/out/zqlite/src/table-source.d.ts.map +1 -1
  162. package/out/zqlite/src/table-source.js +6 -10
  163. package/out/zqlite/src/table-source.js.map +1 -1
  164. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"memory-source.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/memory-source.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AAG1D,OAAO,KAAK,EACV,SAAS,E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,OAAO,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,UAAU,EACnB,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,GAAG,SAAS;;;kBAcpD;AAiDD,OAAO,EAAC,kBAAkB,IAAI,yBAAyB,EAAC,CAAC;AAEzD,iBAAS,kBAAkB,CACzB,EAAC,GAAG,EAAE,MAAM,EAAC,EAAE,QAAQ,EACvB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,UAAU,GAClB,QAAQ,CAOV;AAED,OAAO,EAAC,qBAAqB,IAAI,4BAA4B,EAAC,CAAC;AAE/D,iBAAS,qBAAqB,CAC5B,EAAC,GAAG,EAAE,MAAM,EAAC,EAAE,QAAQ,EACvB,UAAU,EAAE,UAAU,GACrB,QAAQ,CAUV;AAeD,wBAAiB,wBAAwB,CACvC,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAK,MAAM;;;kBA0BtC;AAyDD,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,UAI7C"}
@@ -16,6 +16,7 @@ class MemorySource {
16
16
  #indexes = /* @__PURE__ */ new Map();
17
17
  #connections = [];
18
18
  #overlay;
19
+ #pushEpoch = 0;
19
20
  constructor(tableName, columns, primaryKey, primaryIndexData) {
20
21
  this.#tableName = tableName;
21
22
  this.#columns = columns;
@@ -64,7 +65,6 @@ class MemorySource {
64
65
  const input = {
65
66
  getSchema: () => schema,
66
67
  fetch: (req) => this.#fetch(req, connection),
67
- cleanup: (req) => this.#cleanup(req, connection),
68
68
  setOutput: (output) => {
69
69
  connection.output = output;
70
70
  },
@@ -82,7 +82,8 @@ class MemorySource {
82
82
  filters: transformedFilters.filters ? {
83
83
  condition: transformedFilters.filters,
84
84
  predicate: createPredicate(transformedFilters.filters)
85
- } : void 0
85
+ } : void 0,
86
+ lastPushedEpoch: 0
86
87
  };
87
88
  const schema = this.#getSchema(connection);
88
89
  assertOrderingIncludesPK(sort, this.#primaryKey);
@@ -119,10 +120,7 @@ class MemorySource {
119
120
  getIndexKeys() {
120
121
  return [...this.#indexes.keys()];
121
122
  }
122
- *#fetch(req, from) {
123
- const callingConnectionIndex = this.#connections.indexOf(from);
124
- assert(callingConnectionIndex !== -1, "Output not found");
125
- const conn = this.#connections[callingConnectionIndex];
123
+ *#fetch(req, conn) {
126
124
  const { sort: requestedSort, compareRows } = conn;
127
125
  const connectionComparator = (r1, r2) => compareRows(r1, r2) * (req.reverse ? -1 : 1);
128
126
  const pkConstraint = primaryKeyConstraintFromFilters(
@@ -139,7 +137,7 @@ class MemorySource {
139
137
  if (this.#primaryKey.length > 1 || !fetchOrPkConstraint || !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)) {
140
138
  indexSort.push(...requestedSort);
141
139
  }
142
- const index = this.#getOrCreateIndex(indexSort, from);
140
+ const index = this.#getOrCreateIndex(indexSort, conn);
143
141
  const { data, comparator: compare } = index;
144
142
  const indexComparator = (r1, r2) => compare(r1, r2) * (req.reverse ? -1 : 1);
145
143
  const startAt = req.start?.row;
@@ -169,7 +167,7 @@ class MemorySource {
169
167
  // rather than as the fetch constraint.
170
168
  req.constraint,
171
169
  this.#overlay,
172
- callingConnectionIndex,
170
+ conn.lastPushedEpoch,
173
171
  // Use indexComparator, generateWithOverlayInner has a subtle dependency
174
172
  // on this. Since generateWithConstraint is done after
175
173
  // generateWithOverlay, the generator consumed by generateWithOverlayInner
@@ -192,9 +190,6 @@ class MemorySource {
192
190
  );
193
191
  yield* conn.filters ? generateWithFilter(withConstraint, conn.filters.predicate) : withConstraint;
194
192
  }
195
- #cleanup(req, connection) {
196
- return this.#fetch(req, connection);
197
- }
198
193
  push(change) {
199
194
  for (const _ of this.genPush(change)) {
200
195
  }
@@ -210,7 +205,8 @@ class MemorySource {
210
205
  change,
211
206
  exists,
212
207
  setOverlay,
213
- writeChange
208
+ writeChange,
209
+ () => ++this.#pushEpoch
214
210
  );
215
211
  }
216
212
  #writeChange(change) {
@@ -253,7 +249,7 @@ function* generateWithFilter(it, filter) {
253
249
  }
254
250
  }
255
251
  }
256
- function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay, writeChange) {
252
+ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay, writeChange, getNextEpoch) {
257
253
  let shouldSplitEdit = false;
258
254
  if (change.type === "edit") {
259
255
  for (const { splitEditKeys } of connections) {
@@ -276,7 +272,8 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
276
272
  },
277
273
  exists,
278
274
  setOverlay,
279
- writeChange
275
+ writeChange,
276
+ getNextEpoch()
280
277
  );
281
278
  yield* genPushAndWrite(
282
279
  connections,
@@ -286,7 +283,8 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
286
283
  },
287
284
  exists,
288
285
  setOverlay,
289
- writeChange
286
+ writeChange,
287
+ getNextEpoch()
290
288
  );
291
289
  } else {
292
290
  yield* genPushAndWrite(
@@ -294,17 +292,18 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
294
292
  change,
295
293
  exists,
296
294
  setOverlay,
297
- writeChange
295
+ writeChange,
296
+ getNextEpoch()
298
297
  );
299
298
  }
300
299
  }
301
- function* genPushAndWrite(connections, change, exists, setOverlay, writeChange) {
302
- for (const x of genPush(connections, change, exists, setOverlay)) {
300
+ function* genPushAndWrite(connections, change, exists, setOverlay, writeChange, pushEpoch) {
301
+ for (const x of genPush(connections, change, exists, setOverlay, pushEpoch)) {
303
302
  yield x;
304
303
  }
305
304
  writeChange(change);
306
305
  }
307
- function* genPush(connections, change, exists, setOverlay) {
306
+ function* genPush(connections, change, exists, setOverlay, pushEpoch) {
308
307
  switch (change.type) {
309
308
  case "add":
310
309
  assert(
@@ -321,9 +320,11 @@ function* genPush(connections, change, exists, setOverlay) {
321
320
  default:
322
321
  unreachable();
323
322
  }
324
- for (const [outputIndex, { output, filters, input }] of connections.entries()) {
323
+ for (const conn of connections) {
324
+ const { output, filters, input } = conn;
325
325
  if (output) {
326
- setOverlay({ outputIndex, change });
326
+ conn.lastPushedEpoch = pushEpoch;
327
+ setOverlay({ epoch: pushEpoch, change });
327
328
  const outputChange = change.type === "edit" ? {
328
329
  type: change.type,
329
330
  oldNode: {
@@ -374,9 +375,9 @@ function* generateWithStart(nodes, start, compare) {
374
375
  }
375
376
  }
376
377
  }
377
- function* generateWithOverlay(startAt, rows, constraint, overlay, connectionIndex, compare, filterPredicate) {
378
+ function* generateWithOverlay(startAt, rows, constraint, overlay, lastPushedEpoch, compare, filterPredicate) {
378
379
  let overlayToApply = void 0;
379
- if (overlay && connectionIndex <= overlay.outputIndex) {
380
+ if (overlay && lastPushedEpoch >= overlay.epoch) {
380
381
  overlayToApply = overlay;
381
382
  }
382
383
  const overlays = computeOverlays(
@@ -1 +1 @@
1
- {"version":3,"file":"memory-source.js","sources":["../../../../../zql/src/ivm/memory-source.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {BTreeSet} from '../../../shared/src/btree-set.ts';\nimport {hasOwn} from '../../../shared/src/has-own.ts';\nimport {once} from '../../../shared/src/iterables.ts';\nimport type {\n Condition,\n Ordering,\n OrderPart,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport type {SchemaValue} from '../../../zero-types/src/schema-value.ts';\nimport type {DebugDelegate} from '../builder/debug-delegate.ts';\nimport {\n createPredicate,\n transformFilters,\n type NoSubqueryCondition,\n} from '../builder/filter.ts';\nimport {assertOrderingIncludesPK} from '../query/complete-ordering.ts';\nimport type {Change} from './change.ts';\nimport {\n constraintMatchesPrimaryKey,\n constraintMatchesRow,\n primaryKeyConstraintFromFilters,\n type Constraint,\n} from './constraint.ts';\nimport {\n compareValues,\n makeComparator,\n valuesEqual,\n type Comparator,\n type Node,\n} from './data.ts';\nimport {filterPush} from './filter-push.ts';\nimport {\n skipYields,\n type FetchRequest,\n type Input,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {\n Source,\n SourceChange,\n SourceChangeAdd,\n SourceChangeEdit,\n SourceChangeRemove,\n SourceInput,\n} from './source.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Overlay = {\n outputIndex: number;\n change: SourceChange;\n};\n\nexport type Overlays = {\n add: Row | undefined;\n remove: Row | undefined;\n};\n\ntype Index = {\n comparator: Comparator;\n data: BTreeSet<Row>;\n usedBy: Set<Connection>;\n};\n\nexport type Connection = {\n input: Input;\n output: Output | undefined;\n sort: Ordering;\n splitEditKeys: Set<string> | undefined;\n compareRows: Comparator;\n filters:\n | {\n condition: NoSubqueryCondition;\n predicate: (row: Row) => boolean;\n }\n | undefined;\n readonly debug?: DebugDelegate | undefined;\n};\n\n/**\n * A `MemorySource` is a source that provides data to the pipeline from an\n * in-memory data source.\n *\n * This data is kept in sorted order as downstream pipelines will always expect\n * the data they receive from `pull` to be in sorted order.\n */\nexport class MemorySource implements Source {\n readonly #tableName: string;\n readonly #columns: Record<string, SchemaValue>;\n readonly #primaryKey: PrimaryKey;\n readonly #primaryIndexSort: Ordering;\n readonly #indexes: Map<string, Index> = new Map();\n readonly #connections: Connection[] = [];\n\n #overlay: Overlay | undefined;\n\n constructor(\n tableName: string,\n columns: Record<string, SchemaValue>,\n primaryKey: PrimaryKey,\n primaryIndexData?: BTreeSet<Row>,\n ) {\n this.#tableName = tableName;\n this.#columns = columns;\n this.#primaryKey = primaryKey;\n this.#primaryIndexSort = primaryKey.map(k => [k, 'asc']);\n const comparator = makeBoundComparator(this.#primaryIndexSort);\n this.#indexes.set(JSON.stringify(this.#primaryIndexSort), {\n comparator,\n data: primaryIndexData ?? new BTreeSet<Row>(comparator),\n usedBy: new Set(),\n });\n }\n\n get tableSchema() {\n return {\n name: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n };\n }\n\n fork() {\n const primaryIndex = this.#getPrimaryIndex();\n return new MemorySource(\n this.#tableName,\n this.#columns,\n this.#primaryKey,\n primaryIndex.data.clone(),\n );\n }\n\n get data(): BTreeSet<Row> {\n return this.#getPrimaryIndex().data;\n }\n\n #getSchema(connection: Connection): SourceSchema {\n return {\n tableName: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n sort: connection.sort,\n system: 'client',\n relationships: {},\n isHidden: false,\n compareRows: connection.compareRows,\n };\n }\n\n connect(\n sort: Ordering,\n filters?: Condition,\n splitEditKeys?: Set<string>,\n ): SourceInput {\n const transformedFilters = transformFilters(filters);\n\n const input: SourceInput = {\n getSchema: () => schema,\n fetch: req => this.#fetch(req, connection),\n cleanup: req => this.#cleanup(req, connection),\n setOutput: output => {\n connection.output = output;\n },\n destroy: () => {\n this.#disconnect(input);\n },\n fullyAppliedFilters: !transformedFilters.conditionsRemoved,\n };\n\n const connection: Connection = {\n input,\n output: undefined,\n sort,\n splitEditKeys,\n compareRows: makeComparator(sort),\n filters: transformedFilters.filters\n ? {\n condition: transformedFilters.filters,\n predicate: createPredicate(transformedFilters.filters),\n }\n : undefined,\n };\n const schema = this.#getSchema(connection);\n assertOrderingIncludesPK(sort, this.#primaryKey);\n this.#connections.push(connection);\n return input;\n }\n\n #disconnect(input: Input): void {\n const idx = this.#connections.findIndex(c => c.input === input);\n assert(idx !== -1, 'Connection not found');\n this.#connections.splice(idx, 1);\n\n // TODO: We used to delete unused indexes here. But in common cases like\n // navigating into issue detail pages it caused a ton of constantly\n // building and destroying indexes.\n //\n // Perhaps some intelligent LRU or something is needed here but for now,\n // the opposite extreme of keeping all indexes for the lifetime of the\n // page seems better.\n }\n\n #getPrimaryIndex(): Index {\n const index = this.#indexes.get(JSON.stringify(this.#primaryIndexSort));\n assert(index, 'Primary index not found');\n return index;\n }\n\n #getOrCreateIndex(sort: Ordering, usedBy: Connection): Index {\n const key = JSON.stringify(sort);\n const index = this.#indexes.get(key);\n // Future optimization could use existing index if it's the same just sorted\n // in reverse of needed.\n if (index) {\n index.usedBy.add(usedBy);\n return index;\n }\n\n const comparator = makeBoundComparator(sort);\n\n // When creating these synchronously becomes a problem, a few options:\n // 1. Allow users to specify needed indexes up front\n // 2. Create indexes in a different thread asynchronously (this would require\n // modifying the BTree to be able to be passed over structured-clone, or using\n // a different library.)\n // 3. We could even theoretically do (2) on multiple threads and then merge the\n // results!\n const data = new BTreeSet<Row>(comparator);\n\n // I checked, there's no special path for adding data in bulk faster.\n // The constructor takes an array, but it just calls add/set over and over.\n for (const row of this.#getPrimaryIndex().data) {\n data.add(row);\n }\n\n const newIndex = {comparator, data, usedBy: new Set([usedBy])};\n this.#indexes.set(key, newIndex);\n return newIndex;\n }\n\n // For unit testing that we correctly clean up indexes.\n getIndexKeys(): string[] {\n return [...this.#indexes.keys()];\n }\n\n *#fetch(req: FetchRequest, from: Connection): Stream<Node | 'yield'> {\n const callingConnectionIndex = this.#connections.indexOf(from);\n assert(callingConnectionIndex !== -1, 'Output not found');\n const conn = this.#connections[callingConnectionIndex];\n const {sort: requestedSort, compareRows} = conn;\n const connectionComparator = (r1: Row, r2: Row) =>\n compareRows(r1, r2) * (req.reverse ? -1 : 1);\n\n const pkConstraint = primaryKeyConstraintFromFilters(\n conn.filters?.condition,\n this.#primaryKey,\n );\n // The primary key constraint will be more limiting than the constraint\n // so swap out to that if it exists.\n const fetchOrPkConstraint = pkConstraint ?? req.constraint;\n\n // If there is a constraint, we need an index sorted by it first.\n const indexSort: OrderPart[] = [];\n if (fetchOrPkConstraint) {\n for (const key of Object.keys(fetchOrPkConstraint)) {\n indexSort.push([key, 'asc']);\n }\n }\n\n // For the special case of constraining by PK, we don't need to worry about\n // any requested sort since there can only be one result. Otherwise we also\n // need the index sorted by the requested sort.\n if (\n this.#primaryKey.length > 1 ||\n !fetchOrPkConstraint ||\n !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)\n ) {\n indexSort.push(...requestedSort);\n }\n\n const index = this.#getOrCreateIndex(indexSort, from);\n const {data, comparator: compare} = index;\n const indexComparator = (r1: Row, r2: Row) =>\n compare(r1, r2) * (req.reverse ? -1 : 1);\n\n const startAt = req.start?.row;\n\n // If there is a constraint, we want to start our scan at the first row that\n // matches the constraint. But because the next OrderPart can be `desc`,\n // it's not true that {[constraintKey]: constraintValue} is the first\n // matching row. Because in that case, the other fields will all be\n // `undefined`, and in Zero `undefined` is always less than any other value.\n // So if the second OrderPart is descending then `undefined` values will\n // actually be the *last* row. We need a way to stay \"start at the first row\n // with this constraint value\". RowBound with the corresponding compareBound\n // comparator accomplishes this. The right thing is probably to teach the\n // btree library to support this concept.\n let scanStart: RowBound | undefined;\n\n if (fetchOrPkConstraint) {\n scanStart = {};\n for (const [key, dir] of indexSort) {\n if (hasOwn(fetchOrPkConstraint, key)) {\n scanStart[key] = fetchOrPkConstraint[key];\n } else {\n if (req.reverse) {\n scanStart[key] = dir === 'asc' ? maxValue : minValue;\n } else {\n scanStart[key] = dir === 'asc' ? minValue : maxValue;\n }\n }\n }\n } else {\n scanStart = startAt;\n }\n\n const rowsIterable = generateRows(data, scanStart, req.reverse);\n const withOverlay = generateWithOverlay(\n startAt,\n pkConstraint ? once(rowsIterable) : rowsIterable,\n // use `req.constraint` here and not `fetchOrPkConstraint` since `fetchOrPkConstraint` could be the\n // primary key constraint. The primary key constraint comes from filters and is acting as a filter\n // rather than as the fetch constraint.\n req.constraint,\n this.#overlay,\n callingConnectionIndex,\n // Use indexComparator, generateWithOverlayInner has a subtle dependency\n // on this. Since generateWithConstraint is done after\n // generateWithOverlay, the generator consumed by generateWithOverlayInner\n // does not end when the constraint stops matching and so the final\n // check to yield an add overlay if not yet yielded is not reached.\n // However, using the indexComparator the add overlay will be less than\n // the first row that does not match the constraint, and so any\n // not yet yielded add overlay will be yielded when the first row\n // not matching the constraint is reached.\n indexComparator,\n conn.filters?.predicate,\n );\n\n const withConstraint = generateWithConstraint(\n skipYields(\n generateWithStart(withOverlay, req.start, connectionComparator),\n ),\n // we use `req.constraint` and not `fetchOrPkConstraint` here because we need to\n // AND the constraint with what could have been the primary key constraint\n req.constraint,\n );\n\n yield* conn.filters\n ? generateWithFilter(withConstraint, conn.filters.predicate)\n : withConstraint;\n }\n\n #cleanup(req: FetchRequest, connection: Connection): Stream<Node> {\n return this.#fetch(req, connection) as Stream<Node>;\n }\n\n push(change: SourceChange): void {\n for (const _ of this.genPush(change)) {\n // Nothing to do.\n }\n }\n\n *genPush(change: SourceChange) {\n const primaryIndex = this.#getPrimaryIndex();\n const {data} = primaryIndex;\n const exists = (row: Row) => data.has(row);\n const setOverlay = (o: Overlay | undefined) => (this.#overlay = o);\n const writeChange = (c: SourceChange) => this.#writeChange(c);\n yield* genPushAndWriteWithSplitEdit(\n this.#connections,\n change,\n exists,\n setOverlay,\n writeChange,\n );\n }\n\n #writeChange(change: SourceChange) {\n for (const {data} of this.#indexes.values()) {\n switch (change.type) {\n case 'add': {\n const added = data.add(change.row);\n // must succeed since we checked has() above.\n assert(added);\n break;\n }\n case 'remove': {\n const removed = data.delete(change.row);\n // must succeed since we checked has() above.\n assert(removed);\n break;\n }\n case 'edit': {\n // TODO: We could see if the PK (form the index tree's perspective)\n // changed and if not we could use set.\n // We cannot just do `set` with the new value since the `oldRow` might\n // not map to the same entry as the new `row` in the index btree.\n const removed = data.delete(change.oldRow);\n // must succeed since we checked has() above.\n assert(removed);\n data.add(change.row);\n break;\n }\n default:\n unreachable(change);\n }\n }\n }\n}\n\nfunction* generateWithConstraint(\n it: Stream<Node>,\n constraint: Constraint | undefined,\n) {\n for (const node of it) {\n if (constraint && !constraintMatchesRow(constraint, node.row)) {\n break;\n }\n yield node;\n }\n}\n\nfunction* generateWithFilter(it: Stream<Node>, filter: (row: Row) => boolean) {\n for (const node of it) {\n if (filter(node.row)) {\n yield node;\n }\n }\n}\n\nexport function* genPushAndWriteWithSplitEdit(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n) {\n let shouldSplitEdit = false;\n if (change.type === 'edit') {\n for (const {splitEditKeys} of connections) {\n if (splitEditKeys) {\n for (const key of splitEditKeys) {\n if (!valuesEqual(change.row[key], change.oldRow[key])) {\n shouldSplitEdit = true;\n break;\n }\n }\n }\n }\n }\n\n if (change.type === 'edit' && shouldSplitEdit) {\n yield* genPushAndWrite(\n connections,\n {\n type: 'remove',\n row: change.oldRow,\n },\n exists,\n setOverlay,\n writeChange,\n );\n yield* genPushAndWrite(\n connections,\n {\n type: 'add',\n row: change.row,\n },\n exists,\n setOverlay,\n writeChange,\n );\n } else {\n yield* genPushAndWrite(\n connections,\n change,\n exists,\n setOverlay,\n writeChange,\n );\n }\n}\n\nfunction* genPushAndWrite(\n connections: readonly Connection[],\n change: SourceChangeAdd | SourceChangeRemove | SourceChangeEdit,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n) {\n for (const x of genPush(connections, change, exists, setOverlay)) {\n yield x;\n }\n writeChange(change);\n}\n\nfunction* genPush(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => void,\n) {\n switch (change.type) {\n case 'add':\n assert(\n !exists(change.row),\n () => `Row already exists ${stringify(change)}`,\n );\n break;\n case 'remove':\n assert(exists(change.row), () => `Row not found ${stringify(change)}`);\n break;\n case 'edit':\n assert(exists(change.oldRow), () => `Row not found ${stringify(change)}`);\n break;\n default:\n unreachable(change);\n }\n\n for (const [outputIndex, {output, filters, input}] of connections.entries()) {\n if (output) {\n setOverlay({outputIndex, change});\n const outputChange: Change =\n change.type === 'edit'\n ? {\n type: change.type,\n oldNode: {\n row: change.oldRow,\n relationships: {},\n },\n node: {\n row: change.row,\n relationships: {},\n },\n }\n : {\n type: change.type,\n node: {\n row: change.row,\n relationships: {},\n },\n };\n filterPush(outputChange, output, input, filters?.predicate);\n yield;\n }\n }\n\n setOverlay(undefined);\n}\n\nexport function* generateWithStart(\n nodes: Iterable<Node | 'yield'>,\n start: Start | undefined,\n compare: (r1: Row, r2: Row) => number,\n): Stream<Node | 'yield'> {\n if (!start) {\n yield* nodes;\n return;\n }\n let started = false;\n for (const node of nodes) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!started) {\n if (start.basis === 'at') {\n if (compare(node.row, start.row) >= 0) {\n started = true;\n }\n } else if (start.basis === 'after') {\n if (compare(node.row, start.row) > 0) {\n started = true;\n }\n }\n }\n if (started) {\n yield node;\n }\n }\n}\n\n/**\n * Takes an iterator and overlay.\n * Splices the overlay into the iterator at the correct position.\n *\n * @param startAt - if there is a lower bound to the stream. If the lower bound of the stream\n * is above the overlay, the overlay will be skipped.\n * @param rows - the stream into which the overlay should be spliced\n * @param constraint - constraint that was applied to the rowIterator and should\n * also be applied to the overlay.\n * @param overlay - the overlay values to splice in\n * @param compare - the comparator to use to find the position for the overlay\n */\nexport function* generateWithOverlay(\n startAt: Row | undefined,\n rows: Iterable<Row>,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n connectionIndex: number,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n) {\n let overlayToApply: Overlay | undefined = undefined;\n if (overlay && connectionIndex <= overlay.outputIndex) {\n overlayToApply = overlay;\n }\n const overlays = computeOverlays(\n startAt,\n constraint,\n overlayToApply,\n compare,\n filterPredicate,\n );\n yield* generateWithOverlayInner(rows, overlays, compare);\n}\n\nfunction computeOverlays(\n startAt: Row | undefined,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n): Overlays {\n let overlays: Overlays = {\n add: undefined,\n remove: undefined,\n };\n switch (overlay?.change.type) {\n case 'add':\n overlays = {\n add: overlay.change.row,\n remove: undefined,\n };\n break;\n case 'remove':\n overlays = {\n add: undefined,\n remove: overlay.change.row,\n };\n break;\n case 'edit':\n overlays = {\n add: overlay.change.row,\n remove: overlay.change.oldRow,\n };\n break;\n }\n\n if (startAt) {\n overlays = overlaysForStartAt(overlays, startAt, compare);\n }\n\n if (constraint) {\n overlays = overlaysForConstraint(overlays, constraint);\n }\n\n if (filterPredicate) {\n overlays = overlaysForFilterPredicate(overlays, filterPredicate);\n }\n\n return overlays;\n}\n\nexport {overlaysForStartAt as overlaysForStartAtForTest};\n\nfunction overlaysForStartAt(\n {add, remove}: Overlays,\n startAt: Row,\n compare: Comparator,\n): Overlays {\n const undefinedIfBeforeStartAt = (row: Row | undefined) =>\n row === undefined || compare(row, startAt) < 0 ? undefined : row;\n return {\n add: undefinedIfBeforeStartAt(add),\n remove: undefinedIfBeforeStartAt(remove),\n };\n}\n\nexport {overlaysForConstraint as overlaysForConstraintForTest};\n\nfunction overlaysForConstraint(\n {add, remove}: Overlays,\n constraint: Constraint,\n): Overlays {\n const undefinedIfDoesntMatchConstraint = (row: Row | undefined) =>\n row === undefined || !constraintMatchesRow(constraint, row)\n ? undefined\n : row;\n\n return {\n add: undefinedIfDoesntMatchConstraint(add),\n remove: undefinedIfDoesntMatchConstraint(remove),\n };\n}\n\nfunction overlaysForFilterPredicate(\n {add, remove}: Overlays,\n filterPredicate: (row: Row) => boolean | undefined,\n): Overlays {\n const undefinedIfDoesntMatchFilter = (row: Row | undefined) =>\n row === undefined || !filterPredicate(row) ? undefined : row;\n\n return {\n add: undefinedIfDoesntMatchFilter(add),\n remove: undefinedIfDoesntMatchFilter(remove),\n };\n}\n\nexport function* generateWithOverlayInner(\n rowIterator: Iterable<Row>,\n overlays: Overlays,\n compare: (r1: Row, r2: Row) => number,\n) {\n let addOverlayYielded = false;\n let removeOverlaySkipped = false;\n for (const row of rowIterator) {\n if (!addOverlayYielded && overlays.add) {\n const cmp = compare(overlays.add, row);\n if (cmp < 0) {\n addOverlayYielded = true;\n yield {row: overlays.add, relationships: {}};\n }\n }\n\n if (!removeOverlaySkipped && overlays.remove) {\n const cmp = compare(overlays.remove, row);\n if (cmp === 0) {\n removeOverlaySkipped = true;\n continue;\n }\n }\n yield {row, relationships: {}};\n }\n\n if (!addOverlayYielded && overlays.add) {\n yield {row: overlays.add, relationships: {}};\n }\n}\n\n/**\n * A location to begin scanning an index from. Can either be a specific value\n * or the min or max possible value for the type. This is used to start a scan\n * at the beginning of the rows matching a constraint.\n */\ntype Bound = Value | MinValue | MaxValue;\ntype RowBound = Record<string, Bound>;\nconst minValue = Symbol('min-value');\ntype MinValue = typeof minValue;\nconst maxValue = Symbol('max-value');\ntype MaxValue = typeof maxValue;\n\nfunction makeBoundComparator(sort: Ordering) {\n return (a: RowBound, b: RowBound) => {\n // Hot! Do not use destructuring\n for (const entry of sort) {\n const key = entry[0];\n const cmp = compareBounds(a[key], b[key]);\n if (cmp !== 0) {\n return entry[1] === 'asc' ? cmp : -cmp;\n }\n }\n return 0;\n };\n}\n\nfunction compareBounds(a: Bound, b: Bound): number {\n if (a === b) {\n return 0;\n }\n if (a === minValue) {\n return -1;\n }\n if (b === minValue) {\n return 1;\n }\n if (a === maxValue) {\n return 1;\n }\n if (b === maxValue) {\n return -1;\n }\n return compareValues(a, b);\n}\n\nfunction* generateRows(\n data: BTreeSet<Row>,\n scanStart: RowBound | undefined,\n reverse: boolean | undefined,\n) {\n yield* data[reverse ? 'valuesFromReversed' : 'valuesFrom'](\n scanStart as Row | undefined,\n );\n}\n\nexport function stringify(change: SourceChange) {\n return JSON.stringify(change, (_, v) =>\n typeof v === 'bigint' ? v.toString() : v,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA0FO,MAAM,aAA+B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAmC,IAAA;AAAA,EACnC,eAA6B,CAAA;AAAA,EAEtC;AAAA,EAEA,YACE,WACA,SACA,YACA,kBACA;AACA,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,cAAc;AACn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Content":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {BTreeSet} from '../../../shared/src/btree-set.ts';\nimport {hasOwn} from '../../../shared/src/has-own.ts';\nimport {once} from '../../../shared/src/iterables.ts';\nimport type {\n Condition,\n Ordering,\n OrderPart,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport type {SchemaValue} from '../../../zero-types/src/schema-value.ts';\nimport type {DebugDelegate} from '../builder/debug-delegate.ts';\nimport {\n createPredicate,\n transformFilters,\n type NoSubqueryCondition,\n} from '../builder/filter.ts';\nimport {assertOrderingIncludesPK} from '../query/complete-ordering.ts';\nimport type {Change} from './change.ts';\nimport {\n constraintMatchesPrimaryKey,\n constraintMatchesRow,\n primaryKeyConstraintFromFilters,\n type Constraint,\n} from './constraint.ts';\nimport {\n compareValues,\n makeComparator,\n valuesEqual,\n type Comparator,\n type Node,\n} from './data.ts';\nimport {filterPush} from './filter-push.ts';\nimport {\n skipYields,\n type FetchRequest,\n type Input,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {\n Source,\n SourceChange,\n SourceChangeAdd,\n SourceChangeEdit,\n SourceChangeRemove,\n SourceInput,\n} from './source.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Overlay = {\n epoch: number;\n change: SourceChange;\n};\n\nexport type Overlays = {\n add: Row | undefined;\n remove: Row | undefined;\n};\n\ntype Index = {\n comparator: Comparator;\n data: BTreeSet<Row>;\n usedBy: Set<Connection>;\n};\n\nexport type Connection = {\n input: Input;\n output: Output | undefined;\n sort: Ordering;\n splitEditKeys: Set<string> | undefined;\n compareRows: Comparator;\n filters:\n | {\n condition: NoSubqueryCondition;\n predicate: (row: Row) => boolean;\n }\n | undefined;\n readonly debug?: DebugDelegate | undefined;\n lastPushedEpoch: number;\n};\n\n/**\n * A `MemorySource` is a source that provides data to the pipeline from an\n * in-memory data source.\n *\n * This data is kept in sorted order as downstream pipelines will always expect\n * the data they receive from `pull` to be in sorted order.\n */\nexport class MemorySource implements Source {\n readonly #tableName: string;\n readonly #columns: Record<string, SchemaValue>;\n readonly #primaryKey: PrimaryKey;\n readonly #primaryIndexSort: Ordering;\n readonly #indexes: Map<string, Index> = new Map();\n readonly #connections: Connection[] = [];\n\n #overlay: Overlay | undefined;\n #pushEpoch = 0;\n\n constructor(\n tableName: string,\n columns: Record<string, SchemaValue>,\n primaryKey: PrimaryKey,\n primaryIndexData?: BTreeSet<Row>,\n ) {\n this.#tableName = tableName;\n this.#columns = columns;\n this.#primaryKey = primaryKey;\n this.#primaryIndexSort = primaryKey.map(k => [k, 'asc']);\n const comparator = makeBoundComparator(this.#primaryIndexSort);\n this.#indexes.set(JSON.stringify(this.#primaryIndexSort), {\n comparator,\n data: primaryIndexData ?? new BTreeSet<Row>(comparator),\n usedBy: new Set(),\n });\n }\n\n get tableSchema() {\n return {\n name: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n };\n }\n\n fork() {\n const primaryIndex = this.#getPrimaryIndex();\n return new MemorySource(\n this.#tableName,\n this.#columns,\n this.#primaryKey,\n primaryIndex.data.clone(),\n );\n }\n\n get data(): BTreeSet<Row> {\n return this.#getPrimaryIndex().data;\n }\n\n #getSchema(connection: Connection): SourceSchema {\n return {\n tableName: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n sort: connection.sort,\n system: 'client',\n relationships: {},\n isHidden: false,\n compareRows: connection.compareRows,\n };\n }\n\n connect(\n sort: Ordering,\n filters?: Condition,\n splitEditKeys?: Set<string>,\n ): SourceInput {\n const transformedFilters = transformFilters(filters);\n\n const input: SourceInput = {\n getSchema: () => schema,\n fetch: req => this.#fetch(req, connection),\n setOutput: output => {\n connection.output = output;\n },\n destroy: () => {\n this.#disconnect(input);\n },\n fullyAppliedFilters: !transformedFilters.conditionsRemoved,\n };\n\n const connection: Connection = {\n input,\n output: undefined,\n sort,\n splitEditKeys,\n compareRows: makeComparator(sort),\n filters: transformedFilters.filters\n ? {\n condition: transformedFilters.filters,\n predicate: createPredicate(transformedFilters.filters),\n }\n : undefined,\n lastPushedEpoch: 0,\n };\n const schema = this.#getSchema(connection);\n assertOrderingIncludesPK(sort, this.#primaryKey);\n this.#connections.push(connection);\n return input;\n }\n\n #disconnect(input: Input): void {\n const idx = this.#connections.findIndex(c => c.input === input);\n assert(idx !== -1, 'Connection not found');\n this.#connections.splice(idx, 1);\n\n // TODO: We used to delete unused indexes here. But in common cases like\n // navigating into issue detail pages it caused a ton of constantly\n // building and destroying indexes.\n //\n // Perhaps some intelligent LRU or something is needed here but for now,\n // the opposite extreme of keeping all indexes for the lifetime of the\n // page seems better.\n }\n\n #getPrimaryIndex(): Index {\n const index = this.#indexes.get(JSON.stringify(this.#primaryIndexSort));\n assert(index, 'Primary index not found');\n return index;\n }\n\n #getOrCreateIndex(sort: Ordering, usedBy: Connection): Index {\n const key = JSON.stringify(sort);\n const index = this.#indexes.get(key);\n // Future optimization could use existing index if it's the same just sorted\n // in reverse of needed.\n if (index) {\n index.usedBy.add(usedBy);\n return index;\n }\n\n const comparator = makeBoundComparator(sort);\n\n // When creating these synchronously becomes a problem, a few options:\n // 1. Allow users to specify needed indexes up front\n // 2. Create indexes in a different thread asynchronously (this would require\n // modifying the BTree to be able to be passed over structured-clone, or using\n // a different library.)\n // 3. We could even theoretically do (2) on multiple threads and then merge the\n // results!\n const data = new BTreeSet<Row>(comparator);\n\n // I checked, there's no special path for adding data in bulk faster.\n // The constructor takes an array, but it just calls add/set over and over.\n for (const row of this.#getPrimaryIndex().data) {\n data.add(row);\n }\n\n const newIndex = {comparator, data, usedBy: new Set([usedBy])};\n this.#indexes.set(key, newIndex);\n return newIndex;\n }\n\n // For unit testing that we correctly clean up indexes.\n getIndexKeys(): string[] {\n return [...this.#indexes.keys()];\n }\n\n *#fetch(req: FetchRequest, conn: Connection): Stream<Node | 'yield'> {\n const {sort: requestedSort, compareRows} = conn;\n const connectionComparator = (r1: Row, r2: Row) =>\n compareRows(r1, r2) * (req.reverse ? -1 : 1);\n\n const pkConstraint = primaryKeyConstraintFromFilters(\n conn.filters?.condition,\n this.#primaryKey,\n );\n // The primary key constraint will be more limiting than the constraint\n // so swap out to that if it exists.\n const fetchOrPkConstraint = pkConstraint ?? req.constraint;\n\n // If there is a constraint, we need an index sorted by it first.\n const indexSort: OrderPart[] = [];\n if (fetchOrPkConstraint) {\n for (const key of Object.keys(fetchOrPkConstraint)) {\n indexSort.push([key, 'asc']);\n }\n }\n\n // For the special case of constraining by PK, we don't need to worry about\n // any requested sort since there can only be one result. Otherwise we also\n // need the index sorted by the requested sort.\n if (\n this.#primaryKey.length > 1 ||\n !fetchOrPkConstraint ||\n !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)\n ) {\n indexSort.push(...requestedSort);\n }\n\n const index = this.#getOrCreateIndex(indexSort, conn);\n const {data, comparator: compare} = index;\n const indexComparator = (r1: Row, r2: Row) =>\n compare(r1, r2) * (req.reverse ? -1 : 1);\n\n const startAt = req.start?.row;\n\n // If there is a constraint, we want to start our scan at the first row that\n // matches the constraint. But because the next OrderPart can be `desc`,\n // it's not true that {[constraintKey]: constraintValue} is the first\n // matching row. Because in that case, the other fields will all be\n // `undefined`, and in Zero `undefined` is always less than any other value.\n // So if the second OrderPart is descending then `undefined` values will\n // actually be the *last* row. We need a way to stay \"start at the first row\n // with this constraint value\". RowBound with the corresponding compareBound\n // comparator accomplishes this. The right thing is probably to teach the\n // btree library to support this concept.\n let scanStart: RowBound | undefined;\n\n if (fetchOrPkConstraint) {\n scanStart = {};\n for (const [key, dir] of indexSort) {\n if (hasOwn(fetchOrPkConstraint, key)) {\n scanStart[key] = fetchOrPkConstraint[key];\n } else {\n if (req.reverse) {\n scanStart[key] = dir === 'asc' ? maxValue : minValue;\n } else {\n scanStart[key] = dir === 'asc' ? minValue : maxValue;\n }\n }\n }\n } else {\n scanStart = startAt;\n }\n\n const rowsIterable = generateRows(data, scanStart, req.reverse);\n const withOverlay = generateWithOverlay(\n startAt,\n pkConstraint ? once(rowsIterable) : rowsIterable,\n // use `req.constraint` here and not `fetchOrPkConstraint` since `fetchOrPkConstraint` could be the\n // primary key constraint. The primary key constraint comes from filters and is acting as a filter\n // rather than as the fetch constraint.\n req.constraint,\n this.#overlay,\n conn.lastPushedEpoch,\n // Use indexComparator, generateWithOverlayInner has a subtle dependency\n // on this. Since generateWithConstraint is done after\n // generateWithOverlay, the generator consumed by generateWithOverlayInner\n // does not end when the constraint stops matching and so the final\n // check to yield an add overlay if not yet yielded is not reached.\n // However, using the indexComparator the add overlay will be less than\n // the first row that does not match the constraint, and so any\n // not yet yielded add overlay will be yielded when the first row\n // not matching the constraint is reached.\n indexComparator,\n conn.filters?.predicate,\n );\n\n const withConstraint = generateWithConstraint(\n skipYields(\n generateWithStart(withOverlay, req.start, connectionComparator),\n ),\n // we use `req.constraint` and not `fetchOrPkConstraint` here because we need to\n // AND the constraint with what could have been the primary key constraint\n req.constraint,\n );\n\n yield* conn.filters\n ? generateWithFilter(withConstraint, conn.filters.predicate)\n : withConstraint;\n }\n\n push(change: SourceChange): void {\n for (const _ of this.genPush(change)) {\n // Nothing to do.\n }\n }\n\n *genPush(change: SourceChange) {\n const primaryIndex = this.#getPrimaryIndex();\n const {data} = primaryIndex;\n const exists = (row: Row) => data.has(row);\n const setOverlay = (o: Overlay | undefined) => (this.#overlay = o);\n const writeChange = (c: SourceChange) => this.#writeChange(c);\n yield* genPushAndWriteWithSplitEdit(\n this.#connections,\n change,\n exists,\n setOverlay,\n writeChange,\n () => ++this.#pushEpoch,\n );\n }\n\n #writeChange(change: SourceChange) {\n for (const {data} of this.#indexes.values()) {\n switch (change.type) {\n case 'add': {\n const added = data.add(change.row);\n // must succeed since we checked has() above.\n assert(added);\n break;\n }\n case 'remove': {\n const removed = data.delete(change.row);\n // must succeed since we checked has() above.\n assert(removed);\n break;\n }\n case 'edit': {\n // TODO: We could see if the PK (form the index tree's perspective)\n // changed and if not we could use set.\n // We cannot just do `set` with the new value since the `oldRow` might\n // not map to the same entry as the new `row` in the index btree.\n const removed = data.delete(change.oldRow);\n // must succeed since we checked has() above.\n assert(removed);\n data.add(change.row);\n break;\n }\n default:\n unreachable(change);\n }\n }\n }\n}\n\nfunction* generateWithConstraint(\n it: Stream<Node>,\n constraint: Constraint | undefined,\n) {\n for (const node of it) {\n if (constraint && !constraintMatchesRow(constraint, node.row)) {\n break;\n }\n yield node;\n }\n}\n\nfunction* generateWithFilter(it: Stream<Node>, filter: (row: Row) => boolean) {\n for (const node of it) {\n if (filter(node.row)) {\n yield node;\n }\n }\n}\n\nexport function* genPushAndWriteWithSplitEdit(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n getNextEpoch: () => number,\n) {\n let shouldSplitEdit = false;\n if (change.type === 'edit') {\n for (const {splitEditKeys} of connections) {\n if (splitEditKeys) {\n for (const key of splitEditKeys) {\n if (!valuesEqual(change.row[key], change.oldRow[key])) {\n shouldSplitEdit = true;\n break;\n }\n }\n }\n }\n }\n\n if (change.type === 'edit' && shouldSplitEdit) {\n yield* genPushAndWrite(\n connections,\n {\n type: 'remove',\n row: change.oldRow,\n },\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n yield* genPushAndWrite(\n connections,\n {\n type: 'add',\n row: change.row,\n },\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n } else {\n yield* genPushAndWrite(\n connections,\n change,\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n }\n}\n\nfunction* genPushAndWrite(\n connections: readonly Connection[],\n change: SourceChangeAdd | SourceChangeRemove | SourceChangeEdit,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n pushEpoch: number,\n) {\n for (const x of genPush(connections, change, exists, setOverlay, pushEpoch)) {\n yield x;\n }\n writeChange(change);\n}\n\nfunction* genPush(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => void,\n pushEpoch: number,\n) {\n switch (change.type) {\n case 'add':\n assert(\n !exists(change.row),\n () => `Row already exists ${stringify(change)}`,\n );\n break;\n case 'remove':\n assert(exists(change.row), () => `Row not found ${stringify(change)}`);\n break;\n case 'edit':\n assert(exists(change.oldRow), () => `Row not found ${stringify(change)}`);\n break;\n default:\n unreachable(change);\n }\n\n for (const conn of connections) {\n const {output, filters, input} = conn;\n if (output) {\n conn.lastPushedEpoch = pushEpoch;\n setOverlay({epoch: pushEpoch, change});\n const outputChange: Change =\n change.type === 'edit'\n ? {\n type: change.type,\n oldNode: {\n row: change.oldRow,\n relationships: {},\n },\n node: {\n row: change.row,\n relationships: {},\n },\n }\n : {\n type: change.type,\n node: {\n row: change.row,\n relationships: {},\n },\n };\n filterPush(outputChange, output, input, filters?.predicate);\n yield;\n }\n }\n\n setOverlay(undefined);\n}\n\nexport function* generateWithStart(\n nodes: Iterable<Node | 'yield'>,\n start: Start | undefined,\n compare: (r1: Row, r2: Row) => number,\n): Stream<Node | 'yield'> {\n if (!start) {\n yield* nodes;\n return;\n }\n let started = false;\n for (const node of nodes) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!started) {\n if (start.basis === 'at') {\n if (compare(node.row, start.row) >= 0) {\n started = true;\n }\n } else if (start.basis === 'after') {\n if (compare(node.row, start.row) > 0) {\n started = true;\n }\n }\n }\n if (started) {\n yield node;\n }\n }\n}\n\n/**\n * Takes an iterator and overlay.\n * Splices the overlay into the iterator at the correct position.\n *\n * @param startAt - if there is a lower bound to the stream. If the lower bound of the stream\n * is above the overlay, the overlay will be skipped.\n * @param rows - the stream into which the overlay should be spliced\n * @param constraint - constraint that was applied to the rowIterator and should\n * also be applied to the overlay.\n * @param overlay - the overlay values to splice in\n * @param compare - the comparator to use to find the position for the overlay\n */\nexport function* generateWithOverlay(\n startAt: Row | undefined,\n rows: Iterable<Row>,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n lastPushedEpoch: number,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n) {\n let overlayToApply: Overlay | undefined = undefined;\n if (overlay && lastPushedEpoch >= overlay.epoch) {\n overlayToApply = overlay;\n }\n const overlays = computeOverlays(\n startAt,\n constraint,\n overlayToApply,\n compare,\n filterPredicate,\n );\n yield* generateWithOverlayInner(rows, overlays, compare);\n}\n\nfunction computeOverlays(\n startAt: Row | undefined,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n): Overlays {\n let overlays: Overlays = {\n add: undefined,\n remove: undefined,\n };\n switch (overlay?.change.type) {\n case 'add':\n overlays = {\n add: overlay.change.row,\n remove: undefined,\n };\n break;\n case 'remove':\n overlays = {\n add: undefined,\n remove: overlay.change.row,\n };\n break;\n case 'edit':\n overlays = {\n add: overlay.change.row,\n remove: overlay.change.oldRow,\n };\n break;\n }\n\n if (startAt) {\n overlays = overlaysForStartAt(overlays, startAt, compare);\n }\n\n if (constraint) {\n overlays = overlaysForConstraint(overlays, constraint);\n }\n\n if (filterPredicate) {\n overlays = overlaysForFilterPredicate(overlays, filterPredicate);\n }\n\n return overlays;\n}\n\nexport {overlaysForStartAt as overlaysForStartAtForTest};\n\nfunction overlaysForStartAt(\n {add, remove}: Overlays,\n startAt: Row,\n compare: Comparator,\n): Overlays {\n const undefinedIfBeforeStartAt = (row: Row | undefined) =>\n row === undefined || compare(row, startAt) < 0 ? undefined : row;\n return {\n add: undefinedIfBeforeStartAt(add),\n remove: undefinedIfBeforeStartAt(remove),\n };\n}\n\nexport {overlaysForConstraint as overlaysForConstraintForTest};\n\nfunction overlaysForConstraint(\n {add, remove}: Overlays,\n constraint: Constraint,\n): Overlays {\n const undefinedIfDoesntMatchConstraint = (row: Row | undefined) =>\n row === undefined || !constraintMatchesRow(constraint, row)\n ? undefined\n : row;\n\n return {\n add: undefinedIfDoesntMatchConstraint(add),\n remove: undefinedIfDoesntMatchConstraint(remove),\n };\n}\n\nfunction overlaysForFilterPredicate(\n {add, remove}: Overlays,\n filterPredicate: (row: Row) => boolean | undefined,\n): Overlays {\n const undefinedIfDoesntMatchFilter = (row: Row | undefined) =>\n row === undefined || !filterPredicate(row) ? undefined : row;\n\n return {\n add: undefinedIfDoesntMatchFilter(add),\n remove: undefinedIfDoesntMatchFilter(remove),\n };\n}\n\nexport function* generateWithOverlayInner(\n rowIterator: Iterable<Row>,\n overlays: Overlays,\n compare: (r1: Row, r2: Row) => number,\n) {\n let addOverlayYielded = false;\n let removeOverlaySkipped = false;\n for (const row of rowIterator) {\n if (!addOverlayYielded && overlays.add) {\n const cmp = compare(overlays.add, row);\n if (cmp < 0) {\n addOverlayYielded = true;\n yield {row: overlays.add, relationships: {}};\n }\n }\n\n if (!removeOverlaySkipped && overlays.remove) {\n const cmp = compare(overlays.remove, row);\n if (cmp === 0) {\n removeOverlaySkipped = true;\n continue;\n }\n }\n yield {row, relationships: {}};\n }\n\n if (!addOverlayYielded && overlays.add) {\n yield {row: overlays.add, relationships: {}};\n }\n}\n\n/**\n * A location to begin scanning an index from. Can either be a specific value\n * or the min or max possible value for the type. This is used to start a scan\n * at the beginning of the rows matching a constraint.\n */\ntype Bound = Value | MinValue | MaxValue;\ntype RowBound = Record<string, Bound>;\nconst minValue = Symbol('min-value');\ntype MinValue = typeof minValue;\nconst maxValue = Symbol('max-value');\ntype MaxValue = typeof maxValue;\n\nfunction makeBoundComparator(sort: Ordering) {\n return (a: RowBound, b: RowBound) => {\n // Hot! Do not use destructuring\n for (const entry of sort) {\n const key = entry[0];\n const cmp = compareBounds(a[key], b[key]);\n if (cmp !== 0) {\n return entry[1] === 'asc' ? cmp : -cmp;\n }\n }\n return 0;\n };\n}\n\nfunction compareBounds(a: Bound, b: Bound): number {\n if (a === b) {\n return 0;\n }\n if (a === minValue) {\n return -1;\n }\n if (b === minValue) {\n return 1;\n }\n if (a === maxValue) {\n return 1;\n }\n if (b === maxValue) {\n return -1;\n }\n return compareValues(a, b);\n}\n\nfunction* generateRows(\n data: BTreeSet<Row>,\n scanStart: RowBound | undefined,\n reverse: boolean | undefined,\n) {\n yield* data[reverse ? 'valuesFromReversed' : 'valuesFrom'](\n scanStart as Row | undefined,\n );\n}\n\nexport function stringify(change: SourceChange) {\n return JSON.stringify(change, (_, v) =>\n typeof v === 'bigint' ? v.toString() : v,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA2FO,MAAM,aAA+B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAmC,IAAA;AAAA,EACnC,eAA6B,CAAA;AAAA,EAEtC;AAAA,EACA,aAAa;AAAA,EAEb,YACE,WACA,SACA,YACA,kBACA;AACA,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,oBAAoB,WAAW,IAAI,OAAK,CAAC,GAAG,KAAK,CAAC;AACvD,UAAM,aAAa,oBAAoB,KAAK,iBAAiB;AAC7D,SAAK,SAAS,IAAI,KAAK,UAAU,KAAK,iBAAiB,GAAG;AAAA,MACxD;AAAA,MACA,MAAM,oBAAoB,IAAI,SAAc,UAAU;AAAA,MACtD,4BAAY,IAAA;AAAA,IAAI,CACjB;AAAA,EACH;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,IAAA;AAAA,EAErB;AAAA,EAEA,OAAO;AACL,UAAM,eAAe,KAAK,iBAAA;AAC1B,WAAO,IAAI;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,aAAa,KAAK,MAAA;AAAA,IAAM;AAAA,EAE5B;AAAA,EAEA,IAAI,OAAsB;AACxB,WAAO,KAAK,mBAAmB;AAAA,E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MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,SAAO,cAAc,GAAG,CAAC;AAC3B;AAEA,UAAU,aACR,MACA,WACA,SACA;AACA,SAAO,KAAK,UAAU,uBAAuB,YAAY;AAAA,IACvD;AAAA,EAAA;AAEJ;AAEO,SAAS,UAAU,QAAsB;AAC9C,SAAO,KAAK;AAAA,IAAU;AAAA,IAAQ,CAAC,GAAG,MAChC,OAAO,MAAM,WAAW,EAAE,aAAa;AAAA,EAAA;AAE3C;"}
@@ -33,18 +33,6 @@ export interface Input extends InputBase {
33
33
  * - During push: If a fetch to an input yields 'yield', it can be skipped/ignored.
34
34
  */
35
35
  fetch(req: FetchRequest): Stream<Node | 'yield'>;
36
- /**
37
- * Cleanup maintained state. This is called when `output` will no longer need
38
- * the data returned by {@linkcode fetch}. The receiving operator should clean up any
39
- * resources it has allocated to service such requests.
40
- *
41
- * This is different from {@linkcode destroy} which means this input will no longer
42
- * be called at all, for any input.
43
- *
44
- * Returns the same thing as {@linkcode fetch}. This allows callers to properly
45
- * propagate the cleanup message through the graph.
46
- */
47
- cleanup(req: FetchRequest): Stream<Node>;
48
36
  }
49
37
  export type FetchRequest = {
50
38
  readonly constraint?: Constraint | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/operator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EA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CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"operator.js","sources":["../../../../../zql/src/ivm/operator.ts"],"sourcesContent":["import type {JSONValue} from '../../../shared/src/json.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport type {Constraint} from './constraint.ts';\nimport type {Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * Input to an operator.\n */\nexport interface InputBase {\n /** The schema of the data this input returns. */\n getSchema(): SourceSchema;\n\n /**\n * Completely destroy the input. Destroying an input\n * causes it to call destroy on its upstreams, fully\n * cleaning up a pipeline.\n */\n destroy(): void;\n}\n\nexport interface Input extends InputBase {\n /** Tell the input where to send its output. */\n setOutput(output: Output): void;\n\n /**\n * Fetch data. May modify the data in place.\n * Returns nodes sorted in order of `SourceSchema.compareRows`.\n *\n * The stream may contain 'yield' to indicate the operator has yielded control.\n *\n * Contract:\n * - During fetch: If an input yields 'yield', 'yield' must be yielded to the\n * caller of fetch immediately.\n * - During push: If a fetch to an input yields 'yield', it can be skipped/ignored.\n */\n fetch(req: FetchRequest): Stream<Node | 'yield'>;\n\n /**\n * Cleanup maintained state. This is called when `output` will no longer need\n * the data returned by {@linkcode fetch}. The receiving operator should clean up any\n * resources it has allocated to service such requests.\n *\n * This is different from {@linkcode destroy} which means this input will no longer\n * be called at all, for any input.\n *\n * Returns the same thing as {@linkcode fetch}. This allows callers to properly\n * propagate the cleanup message through the graph.\n */\n cleanup(req: FetchRequest): Stream<Node>;\n}\n\nexport type FetchRequest = {\n readonly constraint?: Constraint | undefined;\n /** If supplied, `start.row` must have previously been output by fetch or push. */\n readonly start?: Start | undefined;\n\n /** Whether to fetch in reverse order of the SourceSchema's sort. */\n readonly reverse?: boolean | undefined;\n};\n\nexport type Start = {\n readonly row: Row;\n readonly basis: 'at' | 'after';\n};\n\n/**\n * An output for an operator. Typically another Operator but can also be\n * the code running the pipeline.\n */\nexport interface Output {\n /**\n * Push incremental changes to data previously received with fetch().\n * Consumers must apply all pushed changes or incremental result will\n * be incorrect.\n * Callers must maintain some invariants for correct operation:\n * - Only add rows which do not already exist (by deep equality).\n * - Only remove rows which do exist (by deep equality).\n */\n push(change: Change, pusher: InputBase): void;\n}\n\n/**\n * An implementation of Output that throws if pushed to. It is used as the\n * initial value for for an operator's output before it is set.\n */\nexport const throwOutput: Output = {\n push(_change: Change): void {\n throw new Error('Output not set');\n },\n};\n\nexport function* skipYields(stream: Stream<Node | 'yield'>): Stream<Node> {\n for (const node of stream) {\n if (node !== 'yield') {\n yield node;\n }\n }\n}\n\n/**\n * Operators are arranged into pipelines.\n * They are stateful.\n * Each operator is an input to the next operator in the chain and an output\n * to the previous.\n */\nexport interface Operator extends Input, Output {}\n\n/**\n * Operators get access to storage that they can store their internal\n * state in.\n */\nexport interface Storage {\n set(key: string, value: JSONValue): void;\n get(key: string, def?: JSONValue): JSONValue | undefined;\n /**\n * If options is not specified, defaults to scanning all entries.\n */\n scan(options?: {prefix: string}): Stream<[string, JSONValue]>;\n del(key: string): void;\n}\n"],"names":[],"mappings":"AAwFO,MAAM,cAAsB;AAAA,EACjC,KAAK,SAAuB;AAC1B,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACF;AAEO,UAAU,WAAW,QAA8C;AACxE,aAAW,QAAQ,QAAQ;AACzB,QAAI,SAAS,SAAS;AACpB,YAAM;AAAA,IACR;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"operator.js","sources":["../../../../../zql/src/ivm/operator.ts"],"sourcesContent":["import type {JSONValue} from '../../../shared/src/json.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport type {Constraint} from './constraint.ts';\nimport type {Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * Input to an operator.\n */\nexport interface InputBase {\n /** The schema of the data this input returns. */\n getSchema(): SourceSchema;\n\n /**\n * Completely destroy the input. Destroying an input\n * causes it to call destroy on its upstreams, fully\n * cleaning up a pipeline.\n */\n destroy(): void;\n}\n\nexport interface Input extends InputBase {\n /** Tell the input where to send its output. */\n setOutput(output: Output): void;\n\n /**\n * Fetch data. May modify the data in place.\n * Returns nodes sorted in order of `SourceSchema.compareRows`.\n *\n * The stream may contain 'yield' to indicate the operator has yielded control.\n *\n * Contract:\n * - During fetch: If an input yields 'yield', 'yield' must be yielded to the\n * caller of fetch immediately.\n * - During push: If a fetch to an input yields 'yield', it can be skipped/ignored.\n */\n fetch(req: FetchRequest): Stream<Node | 'yield'>;\n}\n\nexport type FetchRequest = {\n readonly constraint?: Constraint | undefined;\n /** If supplied, `start.row` must have previously been output by fetch or push. */\n readonly start?: Start | undefined;\n\n /** Whether to fetch in reverse order of the SourceSchema's sort. */\n readonly reverse?: boolean | undefined;\n};\n\nexport type Start = {\n readonly row: Row;\n readonly basis: 'at' | 'after';\n};\n\n/**\n * An output for an operator. Typically another Operator but can also be\n * the code running the pipeline.\n */\nexport interface Output {\n /**\n * Push incremental changes to data previously received with fetch().\n * Consumers must apply all pushed changes or incremental result will\n * be incorrect.\n * Callers must maintain some invariants for correct operation:\n * - Only add rows which do not already exist (by deep equality).\n * - Only remove rows which do exist (by deep equality).\n */\n push(change: Change, pusher: InputBase): void;\n}\n\n/**\n * An implementation of Output that throws if pushed to. It is used as the\n * initial value for for an operator's output before it is set.\n */\nexport const throwOutput: Output = {\n push(_change: Change): void {\n throw new Error('Output not set');\n },\n};\n\nexport function* skipYields(stream: Stream<Node | 'yield'>): Stream<Node> {\n for (const node of stream) {\n if (node !== 'yield') {\n yield node;\n }\n }\n}\n\n/**\n * Operators are arranged into pipelines.\n * They are stateful.\n * Each operator is an input to the next operator in the chain and an output\n * to the previous.\n */\nexport interface Operator extends Input, Output {}\n\n/**\n * Operators get access to storage that they can store their internal\n * state in.\n */\nexport interface Storage {\n set(key: string, value: JSONValue): void;\n get(key: string, def?: JSONValue): JSONValue | undefined;\n /**\n * If options is not specified, defaults to scanning all entries.\n */\n scan(options?: {prefix: string}): Stream<[string, JSONValue]>;\n del(key: string): void;\n}\n"],"names":[],"mappings":"AA2EO,MAAM,cAAsB;AAAA,EACjC,KAAK,SAAuB;AAC1B,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACF;AAEO,UAAU,WAAW,QAA8C;AACxE,aAAW,QAAQ,QAAQ;AACzB,QAAI,SAAS,SAAS;AACpB,YAAM;AAAA,IACR;AAAA,EACF;AACF;"}
@@ -17,7 +17,6 @@ export declare class Skip implements Operator {
17
17
  constructor(input: Input, bound: Bound);
18
18
  getSchema(): SourceSchema;
19
19
  fetch(req: FetchRequest): Stream<Node | 'yield'>;
20
- cleanup(req: FetchRequest): Stream<Node>;
21
20
  setOutput(output: Output): void;
22
21
  destroy(): void;
23
22
  push(change: Change): void;
@@ -1 +1 @@
1
- {"version":3,"file":"skip.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAY,MAAM,EAA4B,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAa,IAAI,EAAC,MAAM,WAAW,CAAC;AAEhD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,MAAM,EAEZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,qBAAa,IAAK,YAAW,Q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,EAAE,MAAM,GAAG,IAAI;CA0E3B"}
@@ -14,27 +14,19 @@ class Skip {
14
14
  getSchema() {
15
15
  return this.#input.getSchema();
16
16
  }
17
- fetch(req) {
18
- return this.#fetchOrCleanup("fetch", req);
19
- }
20
- cleanup(req) {
21
- return this.#fetchOrCleanup("cleanup", req);
22
- }
23
- *#fetchOrCleanup(method, req) {
17
+ *fetch(req) {
24
18
  const start = this.#getStart(req);
25
19
  if (start === "empty") {
26
20
  return;
27
21
  }
28
- const nodes = this.#input[method]({ ...req, start });
22
+ const nodes = this.#input.fetch({ ...req, start });
29
23
  if (!req.reverse) {
30
24
  yield* nodes;
31
25
  return;
32
26
  }
33
27
  for (const node of nodes) {
34
28
  if (node === "yield") {
35
- if (method === "fetch") {
36
- yield node;
37
- }
29
+ yield node;
38
30
  continue;
39
31
  }
40
32
  if (!this.#shouldBePresent(node.row)) {
@@ -1 +1 @@
1
- {"version":3,"file":"skip.js","sources":["../../../../../zql/src/ivm/skip.ts"],"sourcesContent":["import type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {AddChange, Change, ChildChange, RemoveChange} from './change.ts';\nimport type {Comparator, Node} from './data.ts';\nimport {maybeSplitAndPushEditChange} from './maybe-split-and-push-edit-change.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Operator,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Bound = {\n row: Row;\n exclusive: boolean;\n};\n\n/**\n * Skip sets the start position for the pipeline. No rows before the bound will\n * be output.\n */\nexport class Skip implements Operator {\n readonly #input: Input;\n readonly #bound: Bound;\n readonly #comparator: Comparator;\n\n #output: Output = throwOutput;\n\n constructor(input: Input, bound: Bound) {\n this.#input = input;\n this.#bound = bound;\n this.#comparator = input.getSchema().compareRows;\n input.setOutput(this);\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n fetch(req: FetchRequest): Stream<Node | 'yield'> {\n return this.#fetchOrCleanup('fetch', req);\n }\n\n cleanup(req: FetchRequest): Stream<Node> {\n return this.#fetchOrCleanup('cleanup', req) as Stream<Node>;\n }\n\n *#fetchOrCleanup(method: 'fetch' | 'cleanup', req: FetchRequest) {\n const start = this.#getStart(req);\n if (start === 'empty') {\n return;\n }\n const nodes = this.#input[method]({...req, start});\n if (!req.reverse) {\n yield* nodes;\n return;\n }\n for (const node of nodes) {\n if (node === 'yield') {\n if (method === 'fetch') {\n yield node;\n }\n continue;\n }\n if (!this.#shouldBePresent(node.row)) {\n return;\n }\n yield node;\n }\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n #shouldBePresent(row: Row): boolean {\n const cmp = this.#comparator(this.#bound.row, row);\n return cmp < 0 || (cmp === 0 && !this.#bound.exclusive);\n }\n\n push(change: Change): void {\n const shouldBePresent = (row: Row) => this.#shouldBePresent(row);\n if (change.type === 'edit') {\n maybeSplitAndPushEditChange(change, shouldBePresent, this.#output, this);\n return;\n }\n\n change satisfies AddChange | RemoveChange | ChildChange;\n\n if (shouldBePresent(change.node.row)) {\n this.#output.push(change, this);\n }\n }\n\n #getStart(req: FetchRequest): Start | undefined | 'empty' {\n const boundStart = {\n row: this.#bound.row,\n basis: this.#bound.exclusive ? 'after' : 'at',\n } as const;\n\n if (!req.start) {\n if (req.reverse) {\n return undefined;\n }\n return boundStart;\n }\n\n const cmp = this.#comparator(this.#bound.row, req.start.row);\n\n if (!req.reverse) {\n // The skip bound is after the requested bound. The requested bound cannot\n // be relevant because even if it was basis: 'after', the skip bound is\n // itself after the requested bound. Return the skip bound.\n if (cmp > 0) {\n return boundStart;\n }\n\n // The skip bound and requested bound are equal. If either is exclusive,\n // return that bound with exclusive. Otherwise, return the skip bound.\n if (cmp === 0) {\n if (this.#bound.exclusive || req.start.basis === 'after') {\n return {\n row: this.#bound.row,\n basis: 'after',\n };\n }\n return boundStart;\n }\n\n return req.start;\n }\n\n req.reverse satisfies true;\n\n // bound is after the start, but request is for reverse so results\n // must be empty\n if (cmp > 0) {\n return 'empty';\n }\n\n if (cmp === 0) {\n // if both are inclusive, the result can be the single row at bound\n // return it as start\n if (!this.#bound.exclusive && req.start.basis === 'at') {\n return boundStart;\n }\n // otherwise the results must be empty, one or both are exclusive\n // in opposite directions\n return 'empty';\n }\n\n // bound is before the start, return start\n return req.start;\n }\n}\n"],"names":[],"mappings":";;AAwBO,MAAM,KAAyB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EAET,UAAkB;AAAA,EAElB,YAAY,OAAc,OAAc;AACtC,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,cAAc,MAAM,UAAA,EAAY;AACrC,UAAM,UAAU,IAAI;AAAA,EACtB;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,MAAM,KAA2C;AAC/C,WAAO,KAAK,gBAAgB,SAAS,GAAG;AAAA,EAC1C;AAAA,EAEA,QAAQ,KAAiC;AACvC,WAAO,KAAK,gBAAgB,WAAW,GAAG;AAAA,EAC5C;AAAA,EAEA,CAAC,gBAAgB,QAA6B,KAAmB;AAC/D,UAAM,QAAQ,KAAK,UAAU,GAAG;AAChC,QAAI,UAAU,SAAS;AACrB;AAAA,IACF;AACA,UAAM,QAAQ,KAAK,OAAO,MAAM,EAAE,EAAC,GAAG,KAAK,OAAM;AACjD,QAAI,CAAC,IAAI,SAAS;AAChB,aAAO;AACP;AAAA,IACF;AACA,eAAW,QAAQ,OAAO;AACxB,UAAI,SAAS,SAAS;AACpB,YAAI,WAAW,SAAS;AACtB,gBAAM;AAAA,QACR;AACA;AAAA,MACF;AACA,UAAI,CAAC,KAAK,iBAAiB,KAAK,GAAG,GAAG;AACpC;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,UAAU,QAAsB;AAC9B,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,UAAgB;AACd,SAAK,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A,WAAO,IAAI;AAAA,EACb;AACF;"}
1
+ {"version":3,"file":"skip.js","sources":["../../../../../zql/src/ivm/skip.ts"],"sourcesContent":["import type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {AddChange, Change, ChildChange, RemoveChange} from './change.ts';\nimport type {Comparator, Node} from './data.ts';\nimport {maybeSplitAndPushEditChange} from './maybe-split-and-push-edit-change.ts';\nimport {\n throwOutput,\n type FetchRequest,\n type Input,\n type Operator,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Bound = {\n row: Row;\n exclusive: boolean;\n};\n\n/**\n * Skip sets the start position for the pipeline. No rows before the bound will\n * be output.\n */\nexport class Skip implements Operator {\n readonly #input: Input;\n readonly #bound: Bound;\n readonly #comparator: Comparator;\n\n #output: Output = throwOutput;\n\n constructor(input: Input, bound: Bound) {\n this.#input = input;\n this.#bound = bound;\n this.#comparator = input.getSchema().compareRows;\n input.setOutput(this);\n }\n\n getSchema(): SourceSchema {\n return this.#input.getSchema();\n }\n\n *fetch(req: FetchRequest): Stream<Node | 'yield'> {\n const start = this.#getStart(req);\n if (start === 'empty') {\n return;\n }\n const nodes = this.#input.fetch({...req, start});\n if (!req.reverse) {\n yield* nodes;\n return;\n }\n for (const node of nodes) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!this.#shouldBePresent(node.row)) {\n return;\n }\n yield node;\n }\n }\n\n setOutput(output: Output): void {\n this.#output = output;\n }\n\n destroy(): void {\n this.#input.destroy();\n }\n\n #shouldBePresent(row: Row): boolean {\n const cmp = this.#comparator(this.#bound.row, row);\n return cmp < 0 || (cmp === 0 && !this.#bound.exclusive);\n }\n\n push(change: Change): void {\n const shouldBePresent = (row: Row) => this.#shouldBePresent(row);\n if (change.type === 'edit') {\n maybeSplitAndPushEditChange(change, shouldBePresent, this.#output, this);\n return;\n }\n\n change satisfies AddChange | RemoveChange | ChildChange;\n\n if (shouldBePresent(change.node.row)) {\n this.#output.push(change, this);\n }\n }\n\n #getStart(req: FetchRequest): Start | undefined | 'empty' {\n const boundStart = {\n row: this.#bound.row,\n basis: this.#bound.exclusive ? 'after' : 'at',\n } as const;\n\n if (!req.start) {\n if (req.reverse) {\n return undefined;\n }\n return boundStart;\n }\n\n const cmp = this.#comparator(this.#bound.row, req.start.row);\n\n if (!req.reverse) {\n // The skip bound is after the requested bound. The requested bound cannot\n // be relevant because even if it was basis: 'after', the skip bound is\n // itself after the requested bound. Return the skip bound.\n if (cmp > 0) {\n return boundStart;\n }\n\n // The skip bound and requested bound are equal. If either is exclusive,\n // return that bound with exclusive. Otherwise, return the skip bound.\n if (cmp === 0) {\n if (this.#bound.exclusive || req.start.basis === 'after') {\n return {\n row: this.#bound.row,\n basis: 'after',\n };\n }\n return boundStart;\n }\n\n return req.start;\n }\n\n req.reverse satisfies true;\n\n // bound is after the start, but request is for reverse so results\n // must be empty\n if (cmp > 0) {\n return 'empty';\n }\n\n if (cmp === 0) {\n // if both are inclusive, the result can be the single row at bound\n // return it as start\n if (!this.#bound.exclusive && req.start.basis === 'at') {\n return boundStart;\n }\n // otherwise the results must be empty, one or both are exclusive\n // in opposite directions\n return 'empty';\n }\n\n // bound is before the start, return start\n return req.start;\n }\n}\n"],"names":[],"mappings":";;AAwBO,MAAM,KAAyB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EAET,UAAkB;AAAA,EAElB,YAAY,OAAc,OAAc;AACtC,SAAK,SAAS;AACd,SAAK,SAAS;AACd,SAAK,cAAc,MAAM,UAAA,EAAY;AACrC,UAAM,UAAU,IAAI;AAAA,EACtB;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK,OAAO,UAAA;AAAA,EACrB;AAAA,EAEA,CAAC,MAAM,KAA2C;AAChD,UAAM,QAAQ,KAAK,UAAU,GAAG;AAChC,QAAI,UAAU,SAAS;AACrB;AAAA,IACF;AACA,UAAM,QAAQ,KAAK,OAAO,MAAM,EAAC,GAAG,KAAK,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xD,iBAAO;AAAA,YACL,KAAK,KAAK,OAAO;AAAA,YACjB,OAAO;AAAA,UAAA;AAAA,QAEX;AACA,eAAO;AAAA,MACT;AAEA,aAAO,IAAI;AAAA,IACb;AAEA,QAAI;AAIJ,QAAI,MAAM,GAAG;AACX,aAAO;AAAA,IACT;AAEA,QAAI,QAAQ,GAAG;AAGb,UAAI,CAAC,KAAK,OAAO,aAAa,IAAI,MAAM,UAAU,MAAM;AACtD,eAAO;AAAA,MACT;AAGA,aAAO;AAAA,IACT;AAGA,WAAO,IAAI;AAAA,EACb;AACF;"}
@@ -22,7 +22,6 @@ export declare class Take implements Operator {
22
22
  setOutput(output: Output): void;
23
23
  getSchema(): SourceSchema;
24
24
  fetch(req: FetchRequest): Stream<Node | 'yield'>;
25
- cleanup(req: FetchRequest): Stream<Node>;
26
25
  push(change: Change): void;
27
26
  destroy(): void;
28
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/take.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2CAA2C,CAAC;AAE1E,OAAO,EAAC,KAAK,MAAM,EAAqC,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAiC,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AACpE,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,OAAO,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAc,KAAK,MAAM,EAAC,MAAM,aAAa,CAAC;AAiBrD,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,qBAAa,IAAK,YAAW,QAAQ;;gBAYjC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,EACb,YAAY,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,IAAI,IAAI;CAGhB"}
@@ -133,23 +133,6 @@ class Take {
133
133
  }
134
134
  }
135
135
  }
136
- *cleanup(req) {
137
- assert(req.start === void 0, "Start should be undefined");
138
- assert(
139
- constraintMatchesPartitionKey(req.constraint, this.#partitionKey),
140
- "Constraint should match partition key"
141
- );
142
- const takeStateKey = getTakeStateKey(this.#partitionKey, req.constraint);
143
- this.#storage.del(takeStateKey);
144
- let size = 0;
145
- for (const inputNode of this.#input.cleanup(req)) {
146
- if (size === this.#limit) {
147
- return;
148
- }
149
- size++;
150
- yield inputNode;
151
- }
152
- }
153
136
  #getStateAndConstraint(row) {
154
137
  const takeStateKey = getTakeStateKey(this.#partitionKey, row);
155
138
  const takeState = this.#storage.get(takeStateKey);