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

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 (169) hide show
  1. package/out/shared/src/record-proxy.d.ts +13 -0
  2. package/out/shared/src/record-proxy.d.ts.map +1 -0
  3. package/out/shared/src/record-proxy.js +59 -0
  4. package/out/shared/src/record-proxy.js.map +1 -0
  5. package/out/zero/package.json.js +1 -1
  6. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  7. package/out/zero-cache/src/auth/write-authorizer.js +20 -13
  8. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  9. package/out/zero-cache/src/config/zero-config.d.ts +8 -0
  10. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  11. package/out/zero-cache/src/config/zero-config.js +12 -0
  12. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  13. package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
  14. package/out/zero-cache/src/server/otel-start.js +1 -5
  15. package/out/zero-cache/src/server/otel-start.js.map +1 -1
  16. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  17. package/out/zero-cache/src/server/syncer.js +6 -1
  18. package/out/zero-cache/src/server/syncer.js.map +1 -1
  19. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +8 -9
  20. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  21. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +17 -11
  22. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  23. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +2 -2
  24. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  25. package/out/zero-cache/src/services/view-syncer/snapshotter.js +19 -4
  26. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  27. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  28. package/out/zero-cache/src/services/view-syncer/view-syncer.js +1 -7
  29. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  30. package/out/zero-client/src/client/crud.d.ts +3 -3
  31. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  32. package/out/zero-client/src/client/crud.js +23 -13
  33. package/out/zero-client/src/client/crud.js.map +1 -1
  34. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  35. package/out/zero-client/src/client/custom.js +4 -11
  36. package/out/zero-client/src/client/custom.js.map +1 -1
  37. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  38. package/out/zero-client/src/client/ivm-branch.js +20 -13
  39. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  40. package/out/zero-client/src/client/make-mutate-property.d.ts +1 -1
  41. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
  42. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  43. package/out/zero-client/src/client/make-replicache-mutators.d.ts.map +1 -1
  44. package/out/zero-client/src/client/make-replicache-mutators.js +10 -6
  45. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  46. package/out/zero-client/src/client/version.js +1 -1
  47. package/out/zero-client/src/client/zero.js +1 -1
  48. package/out/zero-client/src/client/zero.js.map +1 -1
  49. package/out/zero-server/src/custom.d.ts +2 -2
  50. package/out/zero-server/src/custom.d.ts.map +1 -1
  51. package/out/zero-server/src/custom.js +52 -32
  52. package/out/zero-server/src/custom.js.map +1 -1
  53. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  54. package/out/zero-server/src/zql-database.js +1 -5
  55. package/out/zero-server/src/zql-database.js.map +1 -1
  56. package/out/zero-solid/src/solid-view.d.ts +1 -1
  57. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  58. package/out/zero-solid/src/solid-view.js +2 -0
  59. package/out/zero-solid/src/solid-view.js.map +1 -1
  60. package/out/zero-types/src/schema.d.ts +4 -4
  61. package/out/zql/src/builder/builder.d.ts.map +1 -1
  62. package/out/zql/src/builder/builder.js +1 -11
  63. package/out/zql/src/builder/builder.js.map +1 -1
  64. package/out/zql/src/error.js +1 -10
  65. package/out/zql/src/error.js.map +1 -1
  66. package/out/zql/src/ivm/array-view.d.ts +1 -1
  67. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  68. package/out/zql/src/ivm/array-view.js +2 -0
  69. package/out/zql/src/ivm/array-view.js.map +1 -1
  70. package/out/zql/src/ivm/exists.d.ts +3 -2
  71. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  72. package/out/zql/src/ivm/exists.js +25 -23
  73. package/out/zql/src/ivm/exists.js.map +1 -1
  74. package/out/zql/src/ivm/fan-in.d.ts +3 -3
  75. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  76. package/out/zql/src/ivm/fan-in.js +6 -5
  77. package/out/zql/src/ivm/fan-in.js.map +1 -1
  78. package/out/zql/src/ivm/fan-out.d.ts +2 -2
  79. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  80. package/out/zql/src/ivm/fan-out.js +5 -5
  81. package/out/zql/src/ivm/fan-out.js.map +1 -1
  82. package/out/zql/src/ivm/filter-operators.d.ts +5 -5
  83. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  84. package/out/zql/src/ivm/filter-operators.js +8 -8
  85. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  86. package/out/zql/src/ivm/filter-push.d.ts +2 -1
  87. package/out/zql/src/ivm/filter-push.d.ts.map +1 -1
  88. package/out/zql/src/ivm/filter-push.js +5 -5
  89. package/out/zql/src/ivm/filter-push.js.map +1 -1
  90. package/out/zql/src/ivm/filter.d.ts +2 -2
  91. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  92. package/out/zql/src/ivm/filter.js +4 -4
  93. package/out/zql/src/ivm/filter.js.map +1 -1
  94. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  95. package/out/zql/src/ivm/flipped-join.js +100 -83
  96. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  97. package/out/zql/src/ivm/join.d.ts.map +1 -1
  98. package/out/zql/src/ivm/join.js +52 -50
  99. package/out/zql/src/ivm/join.js.map +1 -1
  100. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  101. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  102. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +4 -4
  103. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  104. package/out/zql/src/ivm/memory-source.d.ts +3 -3
  105. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  106. package/out/zql/src/ivm/memory-source.js +7 -4
  107. package/out/zql/src/ivm/memory-source.js.map +1 -1
  108. package/out/zql/src/ivm/operator.d.ts +10 -3
  109. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  110. package/out/zql/src/ivm/operator.js.map +1 -1
  111. package/out/zql/src/ivm/push-accumulated.d.ts +1 -1
  112. package/out/zql/src/ivm/push-accumulated.d.ts.map +1 -1
  113. package/out/zql/src/ivm/push-accumulated.js +8 -8
  114. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  115. package/out/zql/src/ivm/skip.d.ts +1 -1
  116. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  117. package/out/zql/src/ivm/skip.js +8 -3
  118. package/out/zql/src/ivm/skip.js.map +1 -1
  119. package/out/zql/src/ivm/source.d.ts +15 -7
  120. package/out/zql/src/ivm/source.d.ts.map +1 -1
  121. package/out/zql/src/ivm/stream.d.ts +2 -0
  122. package/out/zql/src/ivm/stream.d.ts.map +1 -1
  123. package/out/zql/src/ivm/stream.js +5 -14
  124. package/out/zql/src/ivm/stream.js.map +1 -1
  125. package/out/zql/src/ivm/take.d.ts +1 -1
  126. package/out/zql/src/ivm/take.d.ts.map +1 -1
  127. package/out/zql/src/ivm/take.js +164 -147
  128. package/out/zql/src/ivm/take.js.map +1 -1
  129. package/out/zql/src/ivm/union-fan-in.d.ts +2 -2
  130. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  131. package/out/zql/src/ivm/union-fan-in.js +7 -7
  132. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  133. package/out/zql/src/ivm/union-fan-out.d.ts +1 -1
  134. package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
  135. package/out/zql/src/ivm/union-fan-out.js +3 -3
  136. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  137. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  138. package/out/zql/src/mutate/mutator-registry.js +1 -0
  139. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  140. package/out/zql/src/mutate/mutator.d.ts +10 -0
  141. package/out/zql/src/mutate/mutator.d.ts.map +1 -1
  142. package/out/zql/src/mutate/mutator.js.map +1 -1
  143. package/out/zql/src/planner/planner-builder.d.ts +2 -1
  144. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  145. package/out/zql/src/planner/planner-builder.js +5 -5
  146. package/out/zql/src/planner/planner-builder.js.map +1 -1
  147. package/out/zql/src/planner/planner-graph.d.ts +3 -1
  148. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  149. package/out/zql/src/planner/planner-graph.js +5 -5
  150. package/out/zql/src/planner/planner-graph.js.map +1 -1
  151. package/out/zql/src/query/create-builder.d.ts.map +1 -1
  152. package/out/zql/src/query/create-builder.js +7 -36
  153. package/out/zql/src/query/create-builder.js.map +1 -1
  154. package/out/zql/src/query/measure-push-operator.d.ts +1 -1
  155. package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
  156. package/out/zql/src/query/measure-push-operator.js +2 -2
  157. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  158. package/out/zqlite/src/internal/sql-inline.d.ts +13 -0
  159. package/out/zqlite/src/internal/sql-inline.d.ts.map +1 -0
  160. package/out/zqlite/src/internal/sql-inline.js +45 -0
  161. package/out/zqlite/src/internal/sql-inline.js.map +1 -0
  162. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  163. package/out/zqlite/src/sqlite-cost-model.js +2 -2
  164. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  165. package/out/zqlite/src/table-source.d.ts +3 -2
  166. package/out/zqlite/src/table-source.d.ts.map +1 -1
  167. package/out/zqlite/src/table-source.js +5 -2
  168. package/out/zqlite/src/table-source.js.map +1 -1
  169. package/package.json +1 -1
@@ -3,6 +3,7 @@ import type { Row } from '../../../zero-protocol/src/data.ts';
3
3
  import type { TableSchema } from '../../../zero-types/src/schema.ts';
4
4
  import type { DebugDelegate } from '../builder/debug-delegate.ts';
5
5
  import type { Input } from './operator.ts';
6
+ import type { Stream } from './stream.ts';
6
7
  export type SourceChangeAdd = {
7
8
  type: 'add';
8
9
  row: Row;
@@ -54,18 +55,25 @@ export interface Source {
54
55
  connect(sort: Ordering, filters?: Condition, splitEditKeys?: Set<string>, debug?: DebugDelegate): SourceInput;
55
56
  /**
56
57
  * Pushes a change into the source and into all connected outputs.
58
+ *
59
+ * The returned stream can yield 'yield' to yield control to the caller
60
+ * for purposes of responsiveness.
61
+ *
62
+ * Once the stream is exhausted, the change will have been pushed into all
63
+ * connected inputs and committed to the source.
57
64
  */
58
- push(change: SourceChange): void;
65
+ push(change: SourceChange): Stream<'yield'>;
59
66
  /**
60
67
  * Pushes a change into the source.
61
- * Iterating the returned iterator will push the
62
- * change into one connected input at a time.
63
68
  *
64
- * Once the iterator is exhausted, the change will
65
- * have been pushed into all connected inputs and
66
- * committed to the source.
69
+ * Iterating the returned stream will push the change into one connected input
70
+ * at a time, yielding `undefined` between each, and yielding `'yield'` to
71
+ * yield control to the caller for purposes of responsiveness.
72
+ *
73
+ * Once the stream is exhausted, the change will have been pushed
74
+ * into all connected inputs and committed to the source.
67
75
  */
68
- genPush(change: SourceChange): Iterable<void>;
76
+ genPush(change: SourceChange): Stream<'yield' | undefined>;
69
77
  }
70
78
  export interface SourceInput extends Input {
71
79
  readonly fullyAppliedFilters: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.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AE,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAE5C;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;CACvC"}
@@ -8,4 +8,6 @@
8
8
  export type Stream<T> = Iterable<T>;
9
9
  export declare function take<T>(stream: Stream<T>, limit: number): Stream<T>;
10
10
  export declare function first<T>(stream: Stream<T>): T | undefined;
11
+ export declare function consume<T>(stream: Stream<T>): void;
12
+ export declare function drainGenerator<Yield, Return>(gen: Generator<Yield, Return, unknown>): Return;
11
13
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/stream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;AAEpC,wBAAiB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAWpE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAKzD"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/stream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;AAEpC,wBAAiB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAWpE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAKzD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAE3C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAC1C,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,GACrC,MAAM,CAMR"}
@@ -1,23 +1,14 @@
1
- function* take(stream, limit) {
2
- if (limit < 1) {
3
- return;
4
- }
5
- let count = 0;
6
- for (const v of stream) {
7
- yield v;
8
- if (++count === limit) {
9
- break;
10
- }
11
- }
12
- }
13
1
  function first(stream) {
14
2
  const it = stream[Symbol.iterator]();
15
3
  const { value } = it.next();
16
4
  it.return?.();
17
5
  return value;
18
6
  }
7
+ function consume(stream) {
8
+ [...stream];
9
+ }
19
10
  export {
20
- first,
21
- take
11
+ consume,
12
+ first
22
13
  };
23
14
  //# sourceMappingURL=stream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sources":["../../../../../zql/src/ivm/stream.ts"],"sourcesContent":["/**\n * streams are lazy forward-only iterables.\n * Once a stream reaches the end it can't be restarted.\n * They are iterable, not iterator, so that they can be used in for-each,\n * and so that we know when consumer has stopped iterating the stream. This allows us\n * to clean up resources like sql statements.\n */\nexport type Stream<T> = Iterable<T>;\n\nexport function* take<T>(stream: Stream<T>, limit: number): Stream<T> {\n if (limit < 1) {\n return;\n }\n let count = 0;\n for (const v of stream) {\n yield v;\n if (++count === limit) {\n break;\n }\n }\n}\n\nexport function first<T>(stream: Stream<T>): T | undefined {\n const it = stream[Symbol.iterator]();\n const {value} = it.next();\n it.return?.();\n return value;\n}\n"],"names":[],"mappings":"AASO,UAAU,KAAQ,QAAmB,OAA0B;AACpE,MAAI,QAAQ,GAAG;AACb;AAAA,EACF;AACA,MAAI,QAAQ;AACZ,aAAW,KAAK,QAAQ;AACtB,UAAM;AACN,QAAI,EAAE,UAAU,OAAO;AACrB;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,MAAS,QAAkC;AACzD,QAAM,KAAK,OAAO,OAAO,QAAQ,EAAA;AACjC,QAAM,EAAC,MAAA,IAAS,GAAG,KAAA;AACnB,KAAG,SAAA;AACH,SAAO;AACT;"}
1
+ {"version":3,"file":"stream.js","sources":["../../../../../zql/src/ivm/stream.ts"],"sourcesContent":["/**\n * streams are lazy forward-only iterables.\n * Once a stream reaches the end it can't be restarted.\n * They are iterable, not iterator, so that they can be used in for-each,\n * and so that we know when consumer has stopped iterating the stream. This allows us\n * to clean up resources like sql statements.\n */\nexport type Stream<T> = Iterable<T>;\n\nexport function* take<T>(stream: Stream<T>, limit: number): Stream<T> {\n if (limit < 1) {\n return;\n }\n let count = 0;\n for (const v of stream) {\n yield v;\n if (++count === limit) {\n break;\n }\n }\n}\n\nexport function first<T>(stream: Stream<T>): T | undefined {\n const it = stream[Symbol.iterator]();\n const {value} = it.next();\n it.return?.();\n return value;\n}\n\nexport function consume<T>(stream: Stream<T>) {\n [...stream];\n}\n\nexport function drainGenerator<Yield, Return>(\n gen: Generator<Yield, Return, unknown>,\n): Return {\n let result = gen.next();\n while (!result.done) {\n result = gen.next();\n }\n return result.value;\n}\n"],"names":[],"mappings":"AAsBO,SAAS,MAAS,QAAkC;AACzD,QAAM,KAAK,OAAO,OAAO,QAAQ,EAAA;AACjC,QAAM,EAAC,MAAA,IAAS,GAAG,KAAA;AACnB,KAAG,SAAA;AACH,SAAO;AACT;AAEO,SAAS,QAAW,QAAmB;AAC5C,GAAC,GAAG,MAAM;AACZ;"}
@@ -22,7 +22,7 @@ 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
- push(change: Change): void;
25
+ push(change: Change): Stream<'yield'>;
26
26
  destroy(): void;
27
27
  }
28
28
  //# sourceMappingURL=take.d.ts.map
@@ -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,CAAC,EAAE,YAAY;IAgB7B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,SAAS,IAAI,YAAY;IAIxB,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;IAyJjD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAsb1B,OAAO,IAAI,IAAI;CAGhB"}
1
+ {"version":3,"file":"take.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/take.ts"],"names":[],"mappings":"AAGA,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,EAEL,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;AAiBxC,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,CAAC,EAAE,YAAY;IAgB7B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,SAAS,IAAI,YAAY;IAIxB,KAAK,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;IAyJhD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IA0ctC,OAAO,IAAI,IAAI;CAGhB"}
@@ -1,10 +1,8 @@
1
1
  import { assert, unreachable } from "../../../shared/src/asserts.js";
2
2
  import { hasOwn } from "../../../shared/src/has-own.js";
3
- import { must } from "../../../shared/src/must.js";
4
3
  import { assertOrderingIncludesPK } from "../query/complete-ordering.js";
5
4
  import { compareValues } from "./data.js";
6
- import { throwOutput, skipYields } from "./operator.js";
7
- import { first, take } from "./stream.js";
5
+ import { throwOutput } from "./operator.js";
8
6
  const MAX_BOUND_KEY = "maxBound";
9
7
  class Take {
10
8
  #input;
@@ -146,9 +144,9 @@ class Take {
146
144
  }
147
145
  return { takeState, takeStateKey, maxBound, constraint };
148
146
  }
149
- push(change) {
147
+ *push(change) {
150
148
  if (change.type === "edit") {
151
- this.#pushEditChange(change);
149
+ yield* this.#pushEditChange(change);
152
150
  return;
153
151
  }
154
152
  const { takeState, takeStateKey, maxBound, constraint } = this.#getStateAndConstraint(change.node.row);
@@ -164,7 +162,7 @@ class Take {
164
162
  takeState.bound === void 0 || compareRows(takeState.bound, change.node.row) < 0 ? change.node.row : takeState.bound,
165
163
  maxBound
166
164
  );
167
- this.#output.push(change, this);
165
+ yield* this.#output.push(change, this);
168
166
  return;
169
167
  }
170
168
  if (takeState.bound === void 0 || compareRows(change.node.row, takeState.bound) >= 0) {
@@ -173,34 +171,41 @@ class Take {
173
171
  let beforeBoundNode;
174
172
  let boundNode;
175
173
  if (this.#limit === 1) {
176
- boundNode = must(
177
- first(
178
- skipYields(
179
- this.#input.fetch({
180
- start: {
181
- row: takeState.bound,
182
- basis: "at"
183
- },
184
- constraint
185
- })
186
- )
187
- )
188
- );
174
+ for (const node of this.#input.fetch({
175
+ start: {
176
+ row: takeState.bound,
177
+ basis: "at"
178
+ },
179
+ constraint
180
+ })) {
181
+ if (node === "yield") {
182
+ yield node;
183
+ continue;
184
+ }
185
+ boundNode = node;
186
+ break;
187
+ }
189
188
  } else {
190
- [boundNode, beforeBoundNode] = take(
191
- skipYields(
192
- this.#input.fetch({
193
- start: {
194
- row: takeState.bound,
195
- basis: "at"
196
- },
197
- constraint,
198
- reverse: true
199
- })
200
- ),
201
- 2
202
- );
189
+ for (const node of this.#input.fetch({
190
+ start: {
191
+ row: takeState.bound,
192
+ basis: "at"
193
+ },
194
+ constraint,
195
+ reverse: true
196
+ })) {
197
+ if (node === "yield") {
198
+ yield node;
199
+ continue;
200
+ } else if (boundNode === void 0) {
201
+ boundNode = node;
202
+ } else {
203
+ beforeBoundNode = node;
204
+ break;
205
+ }
206
+ }
203
207
  }
208
+ assert(boundNode !== void 0);
204
209
  const removeChange = {
205
210
  type: "remove",
206
211
  node: boundNode
@@ -211,10 +216,8 @@ class Take {
211
216
  beforeBoundNode === void 0 || compareRows(change.node.row, beforeBoundNode.row) > 0 ? change.node.row : beforeBoundNode.row,
212
217
  maxBound
213
218
  );
214
- this.#withRowHiddenFromFetch(change.node.row, () => {
215
- this.#output.push(removeChange, this);
216
- });
217
- this.#output.push(change, this);
219
+ yield* this.#pushWithRowHiddenFromFetch(change.node.row, removeChange);
220
+ yield* this.#output.push(change, this);
218
221
  } else if (change.type === "remove") {
219
222
  if (takeState.bound === void 0) {
220
223
  return;
@@ -223,19 +226,22 @@ class Take {
223
226
  if (compToBound > 0) {
224
227
  return;
225
228
  }
226
- const [beforeBoundNode] = take(
227
- skipYields(
228
- this.#input.fetch({
229
- start: {
230
- row: takeState.bound,
231
- basis: "after"
232
- },
233
- constraint,
234
- reverse: true
235
- })
236
- ),
237
- 1
238
- );
229
+ let beforeBoundNode;
230
+ for (const node of this.#input.fetch({
231
+ start: {
232
+ row: takeState.bound,
233
+ basis: "after"
234
+ },
235
+ constraint,
236
+ reverse: true
237
+ })) {
238
+ if (node === "yield") {
239
+ yield node;
240
+ continue;
241
+ }
242
+ beforeBoundNode = node;
243
+ break;
244
+ }
239
245
  let newBound;
240
246
  if (beforeBoundNode) {
241
247
  const push = compareRows(beforeBoundNode.row, takeState.bound) > 0;
@@ -245,15 +251,17 @@ class Take {
245
251
  };
246
252
  }
247
253
  if (!newBound?.push) {
248
- for (const node of skipYields(
249
- this.#input.fetch({
250
- start: {
251
- row: takeState.bound,
252
- basis: "at"
253
- },
254
- constraint
255
- })
256
- )) {
254
+ for (const node of this.#input.fetch({
255
+ start: {
256
+ row: takeState.bound,
257
+ basis: "at"
258
+ },
259
+ constraint
260
+ })) {
261
+ if (node === "yield") {
262
+ yield node;
263
+ continue;
264
+ }
257
265
  const push = compareRows(node.row, takeState.bound) > 0;
258
266
  newBound = {
259
267
  node,
@@ -265,14 +273,14 @@ class Take {
265
273
  }
266
274
  }
267
275
  if (newBound?.push) {
268
- this.#output.push(change, this);
276
+ yield* this.#output.push(change, this);
269
277
  this.#setTakeState(
270
278
  takeStateKey,
271
279
  takeState.size,
272
280
  newBound.node.row,
273
281
  maxBound
274
282
  );
275
- this.#output.push(
283
+ yield* this.#output.push(
276
284
  {
277
285
  type: "add",
278
286
  node: newBound.node
@@ -287,14 +295,14 @@ class Take {
287
295
  newBound?.node.row,
288
296
  maxBound
289
297
  );
290
- this.#output.push(change, this);
298
+ yield* this.#output.push(change, this);
291
299
  } else if (change.type === "child") {
292
300
  if (takeState.bound && compareRows(change.node.row, takeState.bound) <= 0) {
293
- this.#output.push(change, this);
301
+ yield* this.#output.push(change, this);
294
302
  }
295
303
  }
296
304
  }
297
- #pushEditChange(change) {
305
+ *#pushEditChange(change) {
298
306
  assert(
299
307
  !this.#partitionKeyComparator || this.#partitionKeyComparator(change.oldNode.row, change.node.row) === 0,
300
308
  "Unexpected change of partition key"
@@ -307,64 +315,71 @@ class Take {
307
315
  const { compareRows } = this.getSchema();
308
316
  const oldCmp = compareRows(change.oldNode.row, takeState.bound);
309
317
  const newCmp = compareRows(change.node.row, takeState.bound);
310
- const replaceBoundAndForwardChange = () => {
311
- this.#setTakeState(
318
+ const that = this;
319
+ const replaceBoundAndForwardChange = function* () {
320
+ that.#setTakeState(
312
321
  takeStateKey,
313
322
  takeState.size,
314
323
  change.node.row,
315
324
  maxBound
316
325
  );
317
- this.#output.push(change, this);
326
+ yield* that.#output.push(change, that);
318
327
  };
319
328
  if (oldCmp === 0) {
320
329
  if (newCmp === 0) {
321
- this.#output.push(change, this);
330
+ yield* this.#output.push(change, this);
322
331
  return;
323
332
  }
324
333
  if (newCmp < 0) {
325
334
  if (this.#limit === 1) {
326
- replaceBoundAndForwardChange();
335
+ yield* replaceBoundAndForwardChange();
327
336
  return;
328
337
  }
329
- const beforeBoundNode = must(
330
- first(
331
- skipYields(
332
- this.#input.fetch({
333
- start: {
334
- row: takeState.bound,
335
- basis: "after"
336
- },
337
- constraint,
338
- reverse: true
339
- })
340
- )
341
- )
342
- );
338
+ let beforeBoundNode;
339
+ for (const node of this.#input.fetch({
340
+ start: {
341
+ row: takeState.bound,
342
+ basis: "after"
343
+ },
344
+ constraint,
345
+ reverse: true
346
+ })) {
347
+ if (node === "yield") {
348
+ yield node;
349
+ continue;
350
+ }
351
+ beforeBoundNode = node;
352
+ break;
353
+ }
354
+ assert(beforeBoundNode !== void 0);
343
355
  this.#setTakeState(
344
356
  takeStateKey,
345
357
  takeState.size,
346
358
  beforeBoundNode.row,
347
359
  maxBound
348
360
  );
349
- this.#output.push(change, this);
361
+ yield* this.#output.push(change, this);
350
362
  return;
351
363
  }
352
364
  assert(newCmp > 0, "New comparison must be greater than 0");
353
- const newBoundNode = must(
354
- first(
355
- skipYields(
356
- this.#input.fetch({
357
- start: {
358
- row: takeState.bound,
359
- basis: "at"
360
- },
361
- constraint
362
- })
363
- )
364
- )
365
- );
365
+ let newBoundNode;
366
+ for (const node of this.#input.fetch({
367
+ start: {
368
+ row: takeState.bound,
369
+ basis: "at"
370
+ },
371
+ constraint
372
+ })) {
373
+ if (node === "yield") {
374
+ yield node;
375
+ continue;
376
+ }
377
+ newBoundNode = node;
378
+ break;
379
+ }
380
+ assert(newBoundNode !== void 0);
366
381
  if (compareRows(newBoundNode.row, change.node.row) === 0) {
367
- replaceBoundAndForwardChange();
382
+ yield* replaceBoundAndForwardChange();
368
383
  return;
369
384
  }
370
385
  this.#setTakeState(
@@ -373,16 +388,11 @@ class Take {
373
388
  newBoundNode.row,
374
389
  maxBound
375
390
  );
376
- this.#withRowHiddenFromFetch(newBoundNode.row, () => {
377
- this.#output.push(
378
- {
379
- type: "remove",
380
- node: change.oldNode
381
- },
382
- this
383
- );
391
+ yield* this.#pushWithRowHiddenFromFetch(newBoundNode.row, {
392
+ type: "remove",
393
+ node: change.oldNode
384
394
  });
385
- this.#output.push(
395
+ yield* this.#output.push(
386
396
  {
387
397
  type: "add",
388
398
  node: newBoundNode
@@ -397,35 +407,39 @@ class Take {
397
407
  return;
398
408
  }
399
409
  assert(newCmp < 0, "New comparison must be less than 0");
400
- const [oldBoundNode, newBoundNode] = take(
401
- skipYields(
402
- this.#input.fetch({
403
- start: {
404
- row: takeState.bound,
405
- basis: "at"
406
- },
407
- constraint,
408
- reverse: true
409
- })
410
- ),
411
- 2
412
- );
410
+ let oldBoundNode;
411
+ let newBoundNode;
412
+ for (const node of this.#input.fetch({
413
+ start: {
414
+ row: takeState.bound,
415
+ basis: "at"
416
+ },
417
+ constraint,
418
+ reverse: true
419
+ })) {
420
+ if (node === "yield") {
421
+ yield node;
422
+ continue;
423
+ } else if (oldBoundNode === void 0) {
424
+ oldBoundNode = node;
425
+ } else {
426
+ newBoundNode = node;
427
+ break;
428
+ }
429
+ }
430
+ assert(oldBoundNode !== void 0);
431
+ assert(newBoundNode !== void 0);
413
432
  this.#setTakeState(
414
433
  takeStateKey,
415
434
  takeState.size,
416
435
  newBoundNode.row,
417
436
  maxBound
418
437
  );
419
- this.#withRowHiddenFromFetch(change.node.row, () => {
420
- this.#output.push(
421
- {
422
- type: "remove",
423
- node: oldBoundNode
424
- },
425
- this
426
- );
438
+ yield* this.#pushWithRowHiddenFromFetch(change.node.row, {
439
+ type: "remove",
440
+ node: oldBoundNode
427
441
  });
428
- this.#output.push(
442
+ yield* this.#output.push(
429
443
  {
430
444
  type: "add",
431
445
  node: change.node
@@ -437,28 +451,31 @@ class Take {
437
451
  if (oldCmp < 0) {
438
452
  assert(newCmp !== 0, "Invalid state. Row has duplicate primary key");
439
453
  if (newCmp < 0) {
440
- this.#output.push(change, this);
454
+ yield* this.#output.push(change, this);
441
455
  return;
442
456
  }
443
457
  assert(newCmp > 0, "New comparison must be greater than 0");
444
- const afterBoundNode = must(
445
- first(
446
- skipYields(
447
- this.#input.fetch({
448
- start: {
449
- row: takeState.bound,
450
- basis: "after"
451
- },
452
- constraint
453
- })
454
- )
455
- )
456
- );
458
+ let afterBoundNode;
459
+ for (const node of this.#input.fetch({
460
+ start: {
461
+ row: takeState.bound,
462
+ basis: "after"
463
+ },
464
+ constraint
465
+ })) {
466
+ if (node === "yield") {
467
+ yield node;
468
+ continue;
469
+ }
470
+ afterBoundNode = node;
471
+ break;
472
+ }
473
+ assert(afterBoundNode !== void 0);
457
474
  if (compareRows(afterBoundNode.row, change.node.row) === 0) {
458
- replaceBoundAndForwardChange();
475
+ yield* replaceBoundAndForwardChange();
459
476
  return;
460
477
  }
461
- this.#output.push(
478
+ yield* this.#output.push(
462
479
  {
463
480
  type: "remove",
464
481
  node: change.oldNode
@@ -471,7 +488,7 @@ class Take {
471
488
  afterBoundNode.row,
472
489
  maxBound
473
490
  );
474
- this.#output.push(
491
+ yield* this.#output.push(
475
492
  {
476
493
  type: "add",
477
494
  node: afterBoundNode
@@ -482,10 +499,10 @@ class Take {
482
499
  }
483
500
  unreachable();
484
501
  }
485
- #withRowHiddenFromFetch(row, fn) {
502
+ *#pushWithRowHiddenFromFetch(row, change) {
486
503
  this.#rowHiddenFromFetch = row;
487
504
  try {
488
- fn();
505
+ yield* this.#output.push(change, this);
489
506
  } finally {
490
507
  this.#rowHiddenFromFetch = void 0;
491
508
  }