@rocicorp/zero 0.12.2025012902 → 0.12.2025013000

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 (51) hide show
  1. package/out/advanced.js +1 -1
  2. package/out/{chunk-HQA4Z25K.js → chunk-UEPZPKPV.js} +125 -171
  3. package/out/{chunk-HQA4Z25K.js.map → chunk-UEPZPKPV.js.map} +4 -4
  4. package/out/{chunk-QAAJZ32T.js → chunk-ZVLXEWWB.js} +71 -11
  5. package/out/chunk-ZVLXEWWB.js.map +7 -0
  6. package/out/solid.js +2 -2
  7. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  8. package/out/zero-cache/src/services/change-source/pg/change-source.js +86 -117
  9. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  10. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  11. package/out/zero-cache/src/services/change-streamer/storer.js +3 -2
  12. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  13. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +1 -1
  14. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  15. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  16. package/out/zero-cache/src/services/view-syncer/view-syncer.js +26 -2
  17. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  18. package/out/zero.js +2 -2
  19. package/out/zql/src/ivm/change.d.ts +4 -4
  20. package/out/zql/src/ivm/change.d.ts.map +1 -1
  21. package/out/zql/src/ivm/change.js +1 -4
  22. package/out/zql/src/ivm/change.js.map +1 -1
  23. package/out/zql/src/ivm/data.d.ts +2 -1
  24. package/out/zql/src/ivm/data.d.ts.map +1 -1
  25. package/out/zql/src/ivm/data.js +7 -0
  26. package/out/zql/src/ivm/data.js.map +1 -1
  27. package/out/zql/src/ivm/exists.d.ts +3 -2
  28. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  29. package/out/zql/src/ivm/exists.js +55 -64
  30. package/out/zql/src/ivm/exists.js.map +1 -1
  31. package/out/zql/src/ivm/filter-push.js +1 -1
  32. package/out/zql/src/ivm/filter-push.js.map +1 -1
  33. package/out/zql/src/ivm/filter.d.ts +2 -3
  34. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  35. package/out/zql/src/ivm/filter.js +12 -7
  36. package/out/zql/src/ivm/filter.js.map +1 -1
  37. package/out/zql/src/ivm/join.d.ts +4 -1
  38. package/out/zql/src/ivm/join.d.ts.map +1 -1
  39. package/out/zql/src/ivm/join.js +32 -25
  40. package/out/zql/src/ivm/join.js.map +1 -1
  41. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  42. package/out/zql/src/ivm/skip.js +1 -2
  43. package/out/zql/src/ivm/skip.js.map +1 -1
  44. package/out/zql/src/ivm/take.d.ts.map +1 -1
  45. package/out/zql/src/ivm/take.js +4 -3
  46. package/out/zql/src/ivm/take.js.map +1 -1
  47. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  48. package/out/zql/src/ivm/view-apply-change.js +4 -10
  49. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  50. package/package.json +2 -1
  51. package/out/chunk-QAAJZ32T.js.map +0 -7
package/out/advanced.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-ULOTOBTC.js";
2
2
  import {
3
3
  applyChange
4
- } from "./chunk-QAAJZ32T.js";
4
+ } from "./chunk-ZVLXEWWB.js";
5
5
  import "./chunk-424PT5DM.js";
6
6
  export {
7
7
  applyChange
@@ -10,10 +10,15 @@ import {
10
10
  assertNumber,
11
11
  assertObject,
12
12
  assertString,
13
+ compareValues,
14
+ drainStreams,
15
+ makeComparator,
13
16
  must,
17
+ normalizeUndefined,
14
18
  throwInvalidType,
15
- unreachable
16
- } from "./chunk-QAAJZ32T.js";
19
+ unreachable,
20
+ valuesEqual
21
+ } from "./chunk-ZVLXEWWB.js";
17
22
  import {
18
23
  __export,
19
24
  __reExport
@@ -8939,63 +8944,6 @@ function isTwoHop(r) {
8939
8944
  return r.length === 2;
8940
8945
  }
8941
8946
 
8942
- // ../zql/src/ivm/change.ts
8943
- function rowForChange(change) {
8944
- const { type } = change;
8945
- return type === "child" ? change.row : change.node.row;
8946
- }
8947
-
8948
- // ../zql/src/ivm/data.ts
8949
- import { compareUTF8 as compareUTF84 } from "compare-utf8";
8950
- function compareValues(a, b) {
8951
- a = normalizeUndefined(a);
8952
- b = normalizeUndefined(b);
8953
- if (a === b) {
8954
- return 0;
8955
- }
8956
- if (a === null) {
8957
- return -1;
8958
- }
8959
- if (b === null) {
8960
- return 1;
8961
- }
8962
- if (typeof a === "boolean") {
8963
- assertBoolean(b);
8964
- return a ? 1 : -1;
8965
- }
8966
- if (typeof a === "number") {
8967
- assertNumber(b);
8968
- return a - b;
8969
- }
8970
- if (typeof a === "string") {
8971
- assertString(b);
8972
- return compareUTF84(a, b);
8973
- }
8974
- throw new Error(`Unsupported type: ${a}`);
8975
- }
8976
- function normalizeUndefined(v2) {
8977
- return v2 ?? null;
8978
- }
8979
- function makeComparator(order, reverse) {
8980
- return (a, b) => {
8981
- for (const ord of order) {
8982
- const field = ord[0];
8983
- const comp = compareValues(a[field], b[field]);
8984
- if (comp !== 0) {
8985
- const result = ord[1] === "asc" ? comp : -comp;
8986
- return reverse ? -result : result;
8987
- }
8988
- }
8989
- return 0;
8990
- };
8991
- }
8992
- function valuesEqual(a, b) {
8993
- if (a == null || b == null) {
8994
- return false;
8995
- }
8996
- return a === b;
8997
- }
8998
-
8999
8947
  // ../zql/src/ivm/operator.ts
9000
8948
  var throwOutput = {
9001
8949
  push(_change) {
@@ -9056,17 +9004,19 @@ var Exists = class {
9056
9004
  }
9057
9005
  *fetch(req) {
9058
9006
  for (const node of this.#input.fetch(req)) {
9059
- if (this.#filter(node.row)) {
9007
+ if (this.#filter(node)) {
9060
9008
  yield node;
9061
9009
  }
9062
9010
  }
9063
9011
  }
9064
9012
  *cleanup(req) {
9065
9013
  for (const node of this.#input.cleanup(req)) {
9066
- if (this.#filter(node.row)) {
9014
+ if (this.#filter(node)) {
9067
9015
  yield node;
9016
+ } else {
9017
+ drainStreams(node);
9068
9018
  }
9069
- this.#delSize(node.row);
9019
+ this.#delSize(node);
9070
9020
  }
9071
9021
  }
9072
9022
  push(change) {
@@ -9079,12 +9029,12 @@ var Exists = class {
9079
9029
  return;
9080
9030
  }
9081
9031
  case "remove": {
9082
- const size = this.#getSize(change.node.row);
9032
+ const size = this.#getSize(change.node);
9083
9033
  if (size === void 0) {
9084
9034
  return;
9085
9035
  }
9086
9036
  this.#pushWithFilter(change, size);
9087
- this.#delSize(change.node.row);
9037
+ this.#delSize(change.node);
9088
9038
  return;
9089
9039
  }
9090
9040
  case "child":
@@ -9094,13 +9044,13 @@ var Exists = class {
9094
9044
  }
9095
9045
  switch (change.child.change.type) {
9096
9046
  case "add": {
9097
- let size = this.#getSize(change.row);
9047
+ let size = this.#getSize(change.node);
9098
9048
  if (size !== void 0) {
9099
9049
  size++;
9100
- this.#setCachedSize(change.row, size);
9101
- this.#setSize(change.row, size);
9050
+ this.#setCachedSize(change.node, size);
9051
+ this.#setSize(change.node, size);
9102
9052
  } else {
9103
- size = this.#fetchSize(change.row);
9053
+ size = this.#fetchSize(change.node);
9104
9054
  }
9105
9055
  if (size === 1) {
9106
9056
  const type = this.#not ? "remove" : "add";
@@ -9109,7 +9059,7 @@ var Exists = class {
9109
9059
  }
9110
9060
  this.#output.push({
9111
9061
  type,
9112
- node: this.#fetchNodeForRow(change.row)
9062
+ node: change.node
9113
9063
  });
9114
9064
  } else {
9115
9065
  this.#pushWithFilter(change, size);
@@ -9117,16 +9067,16 @@ var Exists = class {
9117
9067
  return;
9118
9068
  }
9119
9069
  case "remove": {
9120
- let size = this.#getSize(change.row);
9070
+ let size = this.#getSize(change.node);
9121
9071
  if (size !== void 0) {
9122
9072
  if (size === 0) {
9123
9073
  return;
9124
9074
  }
9125
9075
  size--;
9126
- this.#setCachedSize(change.row, size);
9127
- this.#setSize(change.row, size);
9076
+ this.#setCachedSize(change.node, size);
9077
+ this.#setSize(change.node, size);
9128
9078
  } else {
9129
- size = this.#fetchSize(change.row);
9079
+ size = this.#fetchSize(change.node);
9130
9080
  }
9131
9081
  if (size === 0) {
9132
9082
  const type = this.#not ? "add" : "remove";
@@ -9135,7 +9085,7 @@ var Exists = class {
9135
9085
  }
9136
9086
  this.#output.push({
9137
9087
  type,
9138
- node: this.#fetchNodeForRow(change.row)
9088
+ node: change.node
9139
9089
  });
9140
9090
  } else {
9141
9091
  this.#pushWithFilter(change, size);
@@ -9149,106 +9099,90 @@ var Exists = class {
9149
9099
  }
9150
9100
  }
9151
9101
  /**
9152
- * Returns whether or not the change's row's this.#relationshipName
9102
+ * Returns whether or not the node's this.#relationshipName
9153
9103
  * relationship passes the exist/not exists filter condition.
9154
9104
  * If the optional `size` is passed it is used.
9155
9105
  * Otherwise, if there is a stored size for the row it is used.
9156
- * Otherwise the size is computed by fetching a node for the row from
9157
- * this.#input (this computed size is also stored).
9106
+ * Otherwise the size is computed by streaming the node's
9107
+ * relationship with this.#relationshipName (this computed size is also
9108
+ * stored).
9158
9109
  */
9159
- #filter(row, size) {
9160
- const exists = (size ?? this.#getOrFetchSize(row)) > 0;
9110
+ #filter(node, size) {
9111
+ const exists = (size ?? this.#getOrFetchSize(node)) > 0;
9161
9112
  return this.#not ? !exists : exists;
9162
9113
  }
9163
9114
  /**
9164
9115
  * Pushes a change if this.#filter is true for its row.
9165
9116
  */
9166
9117
  #pushWithFilter(change, size) {
9167
- const row = rowForChange(change);
9168
- if (this.#filter(row, size)) {
9118
+ if (this.#filter(change.node, size)) {
9169
9119
  this.#output.push(change);
9170
9120
  }
9171
9121
  }
9172
- #getSize(row) {
9173
- return this.#storage.get(this.#makeSizeStorageKey(row));
9122
+ #getSize(node) {
9123
+ return this.#storage.get(this.#makeSizeStorageKey(node));
9174
9124
  }
9175
- #setSize(row, size) {
9176
- this.#storage.set(this.#makeSizeStorageKey(row), size);
9125
+ #setSize(node, size) {
9126
+ this.#storage.set(this.#makeSizeStorageKey(node), size);
9177
9127
  }
9178
- #setCachedSize(row, size) {
9128
+ #setCachedSize(node, size) {
9179
9129
  if (this.#skipCache) {
9180
9130
  return;
9181
9131
  }
9182
- this.#storage.set(this.#makeCacheStorageKey(row), size);
9132
+ this.#storage.set(this.#makeCacheStorageKey(node), size);
9183
9133
  }
9184
- #getCachedSize(row) {
9134
+ #getCachedSize(node) {
9185
9135
  if (this.#skipCache) {
9186
9136
  return void 0;
9187
9137
  }
9188
- return this.#storage.get(this.#makeCacheStorageKey(row));
9138
+ return this.#storage.get(this.#makeCacheStorageKey(node));
9189
9139
  }
9190
- #delSize(row) {
9191
- this.#storage.del(this.#makeSizeStorageKey(row));
9140
+ #delSize(node) {
9141
+ this.#storage.del(this.#makeSizeStorageKey(node));
9192
9142
  if (!this.#skipCache) {
9193
- const cacheKey = this.#makeCacheStorageKey(row);
9143
+ const cacheKey = this.#makeCacheStorageKey(node);
9194
9144
  if (first(this.#storage.scan({ prefix: `${cacheKey}/` })) === void 0) {
9195
9145
  this.#storage.del(cacheKey);
9196
9146
  }
9197
9147
  }
9198
9148
  }
9199
- #getOrFetchSize(row) {
9200
- const size = this.#getSize(row);
9149
+ #getOrFetchSize(node) {
9150
+ const size = this.#getSize(node);
9201
9151
  if (size !== void 0) {
9202
9152
  return size;
9203
9153
  }
9204
- return this.#fetchSize(row);
9154
+ return this.#fetchSize(node);
9205
9155
  }
9206
- #fetchSize(row) {
9207
- const cachedSize = this.#getCachedSize(row);
9156
+ #fetchSize(node) {
9157
+ const cachedSize = this.#getCachedSize(node);
9208
9158
  if (cachedSize !== void 0) {
9209
- this.#setSize(row, cachedSize);
9159
+ this.#setSize(node, cachedSize);
9210
9160
  return cachedSize;
9211
9161
  }
9212
- const relationship = this.#fetchNodeForRow(row).relationships[this.#relationshipName];
9162
+ const relationship = node.relationships[this.#relationshipName];
9213
9163
  assert(relationship);
9214
9164
  let size = 0;
9215
- for (const _relatedNode of relationship) {
9165
+ for (const _relatedNode of relationship()) {
9216
9166
  size++;
9217
9167
  }
9218
- this.#setCachedSize(row, size);
9219
- this.#setSize(row, size);
9168
+ this.#setCachedSize(node, size);
9169
+ this.#setSize(node, size);
9220
9170
  return size;
9221
9171
  }
9222
- #fetchNodeForRow(row) {
9223
- const fetched = must(
9224
- first(
9225
- this.#input.fetch({
9226
- start: { row, basis: "at" }
9227
- })
9228
- )
9229
- );
9230
- assert(
9231
- this.getSchema().compareRows(row, fetched.row) === 0,
9232
- () => `fetchNodeForRow returned unexpected row, expected ${JSON.stringify(
9233
- row
9234
- )}, received ${JSON.stringify(fetched.row)}`
9235
- );
9236
- return fetched;
9237
- }
9238
- #makeCacheStorageKey(row) {
9172
+ #makeCacheStorageKey(node) {
9239
9173
  return `row/${JSON.stringify(
9240
- this.#getKeyValues(row, this.#parentJoinKey)
9174
+ this.#getKeyValues(node, this.#parentJoinKey)
9241
9175
  )}`;
9242
9176
  }
9243
- #makeSizeStorageKey(row) {
9244
- return `row/${this.#skipCache ? "" : JSON.stringify(this.#getKeyValues(row, this.#parentJoinKey))}/${JSON.stringify(
9245
- this.#getKeyValues(row, this.#input.getSchema().primaryKey)
9177
+ #makeSizeStorageKey(node) {
9178
+ return `row/${this.#skipCache ? "" : JSON.stringify(this.#getKeyValues(node, this.#parentJoinKey))}/${JSON.stringify(
9179
+ this.#getKeyValues(node, this.#input.getSchema().primaryKey)
9246
9180
  )}`;
9247
9181
  }
9248
- #getKeyValues(row, def) {
9182
+ #getKeyValues(node, def) {
9249
9183
  const values = [];
9250
9184
  for (const key of def) {
9251
- values.push(normalizeUndefined(row[key]));
9185
+ values.push(normalizeUndefined(node.row[key]));
9252
9186
  }
9253
9187
  return values;
9254
9188
  }
@@ -9383,7 +9317,7 @@ function filterPush(change, output, predicate) {
9383
9317
  }
9384
9318
  break;
9385
9319
  case "child":
9386
- if (predicate(change.row)) {
9320
+ if (predicate(change.node.row)) {
9387
9321
  output.push(change);
9388
9322
  }
9389
9323
  break;
@@ -9414,16 +9348,19 @@ var Filter = class {
9414
9348
  getSchema() {
9415
9349
  return this.#input.getSchema();
9416
9350
  }
9417
- fetch(req) {
9418
- return this.#filter(this.#input.fetch(req));
9419
- }
9420
- cleanup(req) {
9421
- return this.#filter(this.#input.cleanup(req));
9351
+ *fetch(req) {
9352
+ for (const node of this.#input.fetch(req)) {
9353
+ if (this.#predicate(node.row)) {
9354
+ yield node;
9355
+ }
9356
+ }
9422
9357
  }
9423
- *#filter(stream) {
9424
- for (const node of stream) {
9358
+ *cleanup(req) {
9359
+ for (const node of this.#input.cleanup(req)) {
9425
9360
  if (this.#predicate(node.row)) {
9426
9361
  yield node;
9362
+ } else {
9363
+ drainStreams(node);
9427
9364
  }
9428
9365
  }
9429
9366
  }
@@ -9581,7 +9518,11 @@ var Join = class {
9581
9518
  for (const parentNode of parentNodes) {
9582
9519
  const childChange = {
9583
9520
  type: "child",
9584
- row: parentNode.row,
9521
+ node: this.#processParentNode(
9522
+ parentNode.row,
9523
+ parentNode.relationships,
9524
+ "fetch"
9525
+ ),
9585
9526
  child: {
9586
9527
  relationshipName: this.#relationshipName,
9587
9528
  change: change2
@@ -9596,7 +9537,7 @@ var Join = class {
9596
9537
  pushChildChange(change.node.row, change);
9597
9538
  break;
9598
9539
  case "child":
9599
- pushChildChange(change.row, change);
9540
+ pushChildChange(change.node.row, change);
9600
9541
  break;
9601
9542
  case "edit": {
9602
9543
  const childRow = change.node.row;
@@ -9620,35 +9561,49 @@ var Join = class {
9620
9561
  }
9621
9562
  }
9622
9563
  #processParentNode(parentNodeRow, parentNodeRelations, mode) {
9623
- const storageKey = makeStorageKey(
9624
- this.#parentKey,
9625
- this.#parent.getSchema().primaryKey,
9626
- parentNodeRow
9627
- );
9628
9564
  let method = mode;
9629
- if (mode === "cleanup") {
9630
- const [, second] = take(
9631
- this.#storage.scan({
9632
- prefix: makeStorageKeyPrefix(parentNodeRow, this.#parentKey)
9633
- }),
9634
- 2
9635
- );
9636
- method = second ? "fetch" : "cleanup";
9637
- }
9638
- const childStream = this.#child[method]({
9639
- constraint: Object.fromEntries(
9640
- this.#childKey.map((key, i) => [
9641
- key,
9642
- parentNodeRow[this.#parentKey[i]]
9643
- ])
9644
- )
9645
- });
9646
- if (mode === "fetch") {
9647
- this.#storage.set(storageKey, true);
9648
- } else {
9649
- mode;
9650
- this.#storage.del(storageKey);
9651
- }
9565
+ let storageUpdated = false;
9566
+ const childStream = () => {
9567
+ if (!storageUpdated) {
9568
+ if (mode === "cleanup") {
9569
+ this.#storage.del(
9570
+ makeStorageKey(
9571
+ this.#parentKey,
9572
+ this.#parent.getSchema().primaryKey,
9573
+ parentNodeRow
9574
+ )
9575
+ );
9576
+ const empty = [
9577
+ ...take(
9578
+ this.#storage.scan({
9579
+ prefix: makeStorageKeyPrefix(parentNodeRow, this.#parentKey)
9580
+ }),
9581
+ 1
9582
+ )
9583
+ ].length === 0;
9584
+ method = empty ? "cleanup" : "fetch";
9585
+ }
9586
+ storageUpdated = true;
9587
+ if (mode === "fetch") {
9588
+ this.#storage.set(
9589
+ makeStorageKey(
9590
+ this.#parentKey,
9591
+ this.#parent.getSchema().primaryKey,
9592
+ parentNodeRow
9593
+ ),
9594
+ true
9595
+ );
9596
+ }
9597
+ }
9598
+ return this.#child[method]({
9599
+ constraint: Object.fromEntries(
9600
+ this.#childKey.map((key, i) => [
9601
+ key,
9602
+ parentNodeRow[this.#parentKey[i]]
9603
+ ])
9604
+ )
9605
+ });
9606
+ };
9652
9607
  return {
9653
9608
  row: parentNodeRow,
9654
9609
  relationships: {
@@ -9736,8 +9691,7 @@ var Skip = class {
9736
9691
  return;
9737
9692
  }
9738
9693
  change;
9739
- const changeRow = change.type === "child" ? change.row : change.node.row;
9740
- if (shouldBePresent(changeRow)) {
9694
+ if (shouldBePresent(change.node.row)) {
9741
9695
  this.#output.push(change);
9742
9696
  }
9743
9697
  }
@@ -9917,7 +9871,7 @@ var Take = class {
9917
9871
  this.#pushEditChange(change);
9918
9872
  return;
9919
9873
  }
9920
- const { takeState, takeStateKey, maxBound, constraint } = this.#getStateAndConstraint(rowForChange(change));
9874
+ const { takeState, takeStateKey, maxBound, constraint } = this.#getStateAndConstraint(change.node.row);
9921
9875
  if (!takeState) {
9922
9876
  return;
9923
9877
  }
@@ -10042,7 +9996,7 @@ var Take = class {
10042
9996
  );
10043
9997
  this.#output.push(change);
10044
9998
  } else if (change.type === "child") {
10045
- if (takeState.bound && compareRows(change.row, takeState.bound) <= 0) {
9999
+ if (takeState.bound && compareRows(change.node.row, takeState.bound) <= 0) {
10046
10000
  this.#output.push(change);
10047
10001
  }
10048
10002
  }
@@ -12793,9 +12747,9 @@ function* generateRows(data, scanStart, reverse) {
12793
12747
  }
12794
12748
 
12795
12749
  // ../zql/src/ivm/memory-storage.ts
12796
- import { compareUTF8 as compareUTF85 } from "compare-utf8";
12750
+ import { compareUTF8 as compareUTF84 } from "compare-utf8";
12797
12751
  function comparator(a, b) {
12798
- return compareUTF85(a[0], b[0]);
12752
+ return compareUTF84(a[0], b[0]);
12799
12753
  }
12800
12754
  var MemoryStorage = class {
12801
12755
  #data = new BTreeSet(comparator);
@@ -13418,7 +13372,7 @@ function makeMessage(message, context, logLevel) {
13418
13372
  }
13419
13373
 
13420
13374
  // ../zero-client/src/client/version.ts
13421
- var version2 = "0.12.2025012902";
13375
+ var version2 = "0.12.2025013000";
13422
13376
 
13423
13377
  // ../zero-client/src/client/log-options.ts
13424
13378
  var LevelFilterLogSink = class {
@@ -15485,4 +15439,4 @@ export {
15485
15439
  escapeLike,
15486
15440
  Zero
15487
15441
  };
15488
- //# sourceMappingURL=chunk-HQA4Z25K.js.map
15442
+ //# sourceMappingURL=chunk-UEPZPKPV.js.map