@rocicorp/zero 0.17.2025031100 → 0.17.2025031200

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.
@@ -0,0 +1,45 @@
1
+ // ../zql/src/query/ttl.ts
2
+ var DEFAULT_TTL = "none";
3
+ var multiplier = {
4
+ s: 1e3,
5
+ m: 60 * 1e3,
6
+ h: 60 * 60 * 1e3,
7
+ d: 24 * 60 * 60 * 1e3,
8
+ y: 365 * 24 * 60 * 60 * 1e3
9
+ };
10
+ function parseTTL(ttl) {
11
+ if (typeof ttl === "number") {
12
+ return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;
13
+ }
14
+ if (ttl === "none") {
15
+ return 0;
16
+ }
17
+ if (ttl === "forever") {
18
+ return -1;
19
+ }
20
+ const multi = multiplier[ttl[ttl.length - 1]];
21
+ return Number(ttl.slice(0, -1)) * multi;
22
+ }
23
+ function compareTTL(a, b) {
24
+ const ap = parseTTL(a);
25
+ const bp = parseTTL(b);
26
+ if (ap === -1 && bp !== -1) {
27
+ return 1;
28
+ }
29
+ if (ap !== -1 && bp === -1) {
30
+ return -1;
31
+ }
32
+ return ap - bp;
33
+ }
34
+
35
+ // ../shared/src/has-own.ts
36
+ var objectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
37
+ var hasOwn = Object.hasOwn || ((object, key) => objectPrototypeHasOwnProperty.call(object, key));
38
+
39
+ export {
40
+ hasOwn,
41
+ DEFAULT_TTL,
42
+ parseTTL,
43
+ compareTTL
44
+ };
45
+ //# sourceMappingURL=chunk-2Y24MEEQ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../zql/src/query/ttl.ts", "../../shared/src/has-own.ts"],
4
+ "sourcesContent": ["export type TimeUnit = 's' | 'm' | 'h' | 'd' | 'y';\n\n/**\n * Time To Live. This is used for query expiration.\n * - `forever` means the query will never expire.\n * - `none` means the query will expire immediately.\n * - A number means the query will expire after that many milliseconds.\n * - A negative number means the query will never expire, this is same as 'forever'.\n * - A string like `1s` means the query will expire after that many seconds.\n * - A string like `1m` means the query will expire after that many minutes.\n * - A string like `1h` means the query will expire after that many hours.\n * - A string like `1d` means the query will expire after that many days.\n * - A string like `1y` means the query will expire after that many years.\n */\nexport type TTL = `${number}${TimeUnit}` | 'forever' | 'none' | number;\n\nexport const DEFAULT_TTL: TTL = 'none';\n\nconst multiplier = {\n s: 1000,\n m: 60 * 1000,\n h: 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n y: 365 * 24 * 60 * 60 * 1000,\n} as const;\n\nexport function parseTTL(ttl: TTL): number {\n if (typeof ttl === 'number') {\n return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;\n }\n if (ttl === 'none') {\n return 0;\n }\n if (ttl === 'forever') {\n return -1;\n }\n const multi = multiplier[ttl[ttl.length - 1] as TimeUnit];\n return Number(ttl.slice(0, -1)) * multi;\n}\n\nexport function compareTTL(a: TTL, b: TTL): number {\n const ap = parseTTL(a);\n const bp = parseTTL(b);\n if (ap === -1 && bp !== -1) {\n return 1;\n }\n if (ap !== -1 && bp === -1) {\n return -1;\n }\n return ap - bp;\n}\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\nconst objectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;\n\n/**\n * Object.hasOwn polyfill\n */\nexport const hasOwn: (object: any, key: PropertyKey) => boolean =\n (Object as any).hasOwn ||\n ((object, key) => objectPrototypeHasOwnProperty.call(object, key));\n"],
5
+ "mappings": ";AAgBO,IAAM,cAAmB;AAEhC,IAAM,aAAa;AAAA,EACjB,GAAG;AAAA,EACH,GAAG,KAAK;AAAA,EACR,GAAG,KAAK,KAAK;AAAA,EACb,GAAG,KAAK,KAAK,KAAK;AAAA,EAClB,GAAG,MAAM,KAAK,KAAK,KAAK;AAC1B;AAEO,SAAS,SAAS,KAAkB;AACzC,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,SAAS,GAAG,KAAK,MAAM,IAAI,KAAK;AAAA,EACzE;AACA,MAAI,QAAQ,QAAQ;AAClB,WAAO;AAAA,EACT;AACA,MAAI,QAAQ,WAAW;AACrB,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,WAAW,IAAI,IAAI,SAAS,CAAC,CAAa;AACxD,SAAO,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI;AACpC;AAEO,SAAS,WAAW,GAAQ,GAAgB;AACjD,QAAM,KAAK,SAAS,CAAC;AACrB,QAAM,KAAK,SAAS,CAAC;AACrB,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,MAAM,OAAO,IAAI;AAC1B,WAAO;AAAA,EACT;AACA,SAAO,KAAK;AACd;;;ACjDA,IAAM,gCAAgC,OAAO,UAAU;AAKhD,IAAM,SACV,OAAe,WACf,CAAC,QAAQ,QAAQ,8BAA8B,KAAK,QAAQ,GAAG;",
6
+ "names": []
7
+ }
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  DEFAULT_TTL,
3
- hasOwn
4
- } from "./chunk-HLTH2AYN.js";
3
+ compareTTL,
4
+ hasOwn,
5
+ parseTTL
6
+ } from "./chunk-2Y24MEEQ.js";
5
7
  import {
6
8
  applyChange,
7
9
  assert,
@@ -9219,9 +9221,7 @@ var Exists = class {
9219
9221
  case "remove": {
9220
9222
  let size = this.#getSize(change.node);
9221
9223
  if (size !== void 0) {
9222
- if (size === 0) {
9223
- return;
9224
- }
9224
+ assert(size > 0);
9225
9225
  size--;
9226
9226
  this.#setSize(change.node, size);
9227
9227
  } else {
@@ -9617,6 +9617,7 @@ var Join = class {
9617
9617
  #relationshipName;
9618
9618
  #schema;
9619
9619
  #output = throwOutput;
9620
+ #inprogressChildChange;
9620
9621
  constructor({
9621
9622
  parent,
9622
9623
  child,
@@ -9749,25 +9750,34 @@ var Join = class {
9749
9750
  }
9750
9751
  #pushChild(change) {
9751
9752
  const pushChildChange = (childRow, change2) => {
9752
- const parentNodes = this.#parent.fetch({
9753
- constraint: Object.fromEntries(
9754
- this.#parentKey.map((key, i) => [key, childRow[this.#childKey[i]]])
9755
- )
9756
- });
9757
- for (const parentNode of parentNodes) {
9758
- const childChange = {
9759
- type: "child",
9760
- node: this.#processParentNode(
9761
- parentNode.row,
9762
- parentNode.relationships,
9763
- "fetch"
9764
- ),
9765
- child: {
9766
- relationshipName: this.#relationshipName,
9767
- change: change2
9768
- }
9769
- };
9770
- this.#output.push(childChange);
9753
+ this.#inprogressChildChange = {
9754
+ change: change2,
9755
+ position: void 0
9756
+ };
9757
+ try {
9758
+ const parentNodes = this.#parent.fetch({
9759
+ constraint: Object.fromEntries(
9760
+ this.#parentKey.map((key, i) => [key, childRow[this.#childKey[i]]])
9761
+ )
9762
+ });
9763
+ for (const parentNode of parentNodes) {
9764
+ this.#inprogressChildChange.position = parentNode.row;
9765
+ const childChange = {
9766
+ type: "child",
9767
+ node: this.#processParentNode(
9768
+ parentNode.row,
9769
+ parentNode.relationships,
9770
+ "fetch"
9771
+ ),
9772
+ child: {
9773
+ relationshipName: this.#relationshipName,
9774
+ change: change2
9775
+ }
9776
+ };
9777
+ this.#output.push(childChange);
9778
+ }
9779
+ } finally {
9780
+ this.#inprogressChildChange = void 0;
9771
9781
  }
9772
9782
  };
9773
9783
  switch (change.type) {
@@ -9792,6 +9802,81 @@ var Join = class {
9792
9802
  unreachable(change);
9793
9803
  }
9794
9804
  }
9805
+ *#generateChildStreamWithOverlay(stream, overlay) {
9806
+ let applied = false;
9807
+ let editOldApplied = false;
9808
+ let editNewApplied = false;
9809
+ for (const child of stream) {
9810
+ let yieldChild = true;
9811
+ if (!applied) {
9812
+ switch (overlay.type) {
9813
+ case "add": {
9814
+ if (this.#child.getSchema().compareRows(overlay.node.row, child.row) === 0) {
9815
+ applied = true;
9816
+ yieldChild = false;
9817
+ }
9818
+ break;
9819
+ }
9820
+ case "remove": {
9821
+ if (this.#child.getSchema().compareRows(overlay.node.row, child.row) < 0) {
9822
+ applied = true;
9823
+ yield overlay.node;
9824
+ }
9825
+ break;
9826
+ }
9827
+ case "edit": {
9828
+ if (this.#child.getSchema().compareRows(overlay.oldNode.row, child.row) < 0) {
9829
+ editOldApplied = true;
9830
+ if (editNewApplied) {
9831
+ applied = true;
9832
+ }
9833
+ yield overlay.oldNode;
9834
+ }
9835
+ if (this.#child.getSchema().compareRows(overlay.node.row, child.row) === 0) {
9836
+ editNewApplied = true;
9837
+ if (editOldApplied) {
9838
+ applied = true;
9839
+ }
9840
+ yieldChild = false;
9841
+ }
9842
+ break;
9843
+ }
9844
+ case "child": {
9845
+ if (this.#child.getSchema().compareRows(overlay.node.row, child.row) === 0) {
9846
+ applied = true;
9847
+ yield {
9848
+ row: child.row,
9849
+ relationships: {
9850
+ ...child.relationships,
9851
+ [overlay.child.relationshipName]: () => this.#generateChildStreamWithOverlay(
9852
+ child.relationships[overlay.child.relationshipName](),
9853
+ overlay.child.change
9854
+ )
9855
+ }
9856
+ };
9857
+ yieldChild = false;
9858
+ }
9859
+ break;
9860
+ }
9861
+ }
9862
+ }
9863
+ if (yieldChild) {
9864
+ yield child;
9865
+ }
9866
+ }
9867
+ if (!applied) {
9868
+ if (overlay.type === "remove") {
9869
+ applied = true;
9870
+ yield overlay.node;
9871
+ } else if (overlay.type === "edit") {
9872
+ assert(editNewApplied);
9873
+ editOldApplied = true;
9874
+ applied = true;
9875
+ yield overlay.oldNode;
9876
+ }
9877
+ }
9878
+ assert(applied);
9879
+ }
9795
9880
  #processParentNode(parentNodeRow, parentNodeRelations, mode) {
9796
9881
  let method = mode;
9797
9882
  let storageUpdated = false;
@@ -9827,7 +9912,7 @@ var Join = class {
9827
9912
  );
9828
9913
  }
9829
9914
  }
9830
- return this.#child[method]({
9915
+ const stream = this.#child[method]({
9831
9916
  constraint: Object.fromEntries(
9832
9917
  this.#childKey.map((key, i) => [
9833
9918
  key,
@@ -9835,6 +9920,19 @@ var Join = class {
9835
9920
  ])
9836
9921
  )
9837
9922
  });
9923
+ if (this.#inprogressChildChange && this.#isJoinMatch(
9924
+ parentNodeRow,
9925
+ this.#inprogressChildChange.change.node.row
9926
+ ) && this.#inprogressChildChange.position && this.#schema.compareRows(
9927
+ parentNodeRow,
9928
+ this.#inprogressChildChange.position
9929
+ ) > 0) {
9930
+ return this.#generateChildStreamWithOverlay(
9931
+ stream,
9932
+ this.#inprogressChildChange.change
9933
+ );
9934
+ }
9935
+ return stream;
9838
9936
  };
9839
9937
  return {
9840
9938
  row: parentNodeRow,
@@ -9844,6 +9942,14 @@ var Join = class {
9844
9942
  }
9845
9943
  };
9846
9944
  }
9945
+ #isJoinMatch(parent, child) {
9946
+ for (let i = 0; i < this.#parentKey.length; i++) {
9947
+ if (!valuesEqual(parent[this.#parentKey[i]], child[this.#childKey[i]])) {
9948
+ return false;
9949
+ }
9950
+ }
9951
+ return true;
9952
+ }
9847
9953
  };
9848
9954
  function makeStorageKeyForValues(values) {
9849
9955
  const json2 = JSON.stringify(["pKeySet", ...values]);
@@ -10153,6 +10259,7 @@ var Take = class {
10153
10259
  type: "remove",
10154
10260
  node: boundNode
10155
10261
  };
10262
+ this.#output.push(change);
10156
10263
  this.#setTakeState(
10157
10264
  takeStateKey,
10158
10265
  takeState.size,
@@ -10160,7 +10267,6 @@ var Take = class {
10160
10267
  maxBound
10161
10268
  );
10162
10269
  this.#output.push(removeChange);
10163
- this.#output.push(change);
10164
10270
  } else if (change.type === "remove") {
10165
10271
  if (takeState.bound === void 0) {
10166
10272
  return;
@@ -10207,13 +10313,13 @@ var Take = class {
10207
10313
  }
10208
10314
  }
10209
10315
  if (newBound?.push) {
10316
+ this.#output.push(change);
10210
10317
  this.#setTakeState(
10211
10318
  takeStateKey,
10212
10319
  takeState.size,
10213
10320
  newBound.node.row,
10214
10321
  maxBound
10215
10322
  );
10216
- this.#output.push(change);
10217
10323
  this.#output.push({
10218
10324
  type: "add",
10219
10325
  node: newBound.node
@@ -10308,10 +10414,6 @@ var Take = class {
10308
10414
  newBoundNode.row,
10309
10415
  maxBound
10310
10416
  );
10311
- this.#output.push({
10312
- type: "remove",
10313
- node: change.oldNode
10314
- });
10315
10417
  this.#output.push({
10316
10418
  type: "add",
10317
10419
  node: newBoundNode
@@ -10335,6 +10437,10 @@ var Take = class {
10335
10437
  }),
10336
10438
  2
10337
10439
  );
10440
+ this.#output.push({
10441
+ type: "add",
10442
+ node: change.node
10443
+ });
10338
10444
  this.#setTakeState(
10339
10445
  takeStateKey,
10340
10446
  takeState.size,
@@ -10345,10 +10451,6 @@ var Take = class {
10345
10451
  type: "remove",
10346
10452
  node: oldBoundNode
10347
10453
  });
10348
- this.#output.push({
10349
- type: "add",
10350
- node: change.node
10351
- });
10352
10454
  return;
10353
10455
  }
10354
10456
  if (oldCmp < 0) {
@@ -10373,16 +10475,16 @@ var Take = class {
10373
10475
  replaceBoundAndForwardChange();
10374
10476
  return;
10375
10477
  }
10478
+ this.#output.push({
10479
+ type: "remove",
10480
+ node: change.oldNode
10481
+ });
10376
10482
  this.#setTakeState(
10377
10483
  takeStateKey,
10378
10484
  takeState.size,
10379
10485
  afterBoundNode.row,
10380
10486
  maxBound
10381
10487
  );
10382
- this.#output.push({
10383
- type: "remove",
10384
- node: change.oldNode
10385
- });
10386
10488
  this.#output.push({
10387
10489
  type: "add",
10388
10490
  node: afterBoundNode
@@ -11992,40 +12094,6 @@ function escapeLike(val) {
11992
12094
  return val.replace(/[%_]/g, "\\$&");
11993
12095
  }
11994
12096
 
11995
- // ../zql/src/query/ttl.ts
11996
- var DEFAULT_TTL2 = "none";
11997
- var multiplier = {
11998
- s: 1e3,
11999
- m: 60 * 1e3,
12000
- h: 60 * 60 * 1e3,
12001
- d: 24 * 60 * 60 * 1e3,
12002
- y: 365 * 24 * 60 * 60 * 1e3
12003
- };
12004
- function parseTTL(ttl) {
12005
- if (typeof ttl === "number") {
12006
- return Number.isNaN(ttl) ? 0 : !Number.isFinite(ttl) || ttl < 0 ? -1 : ttl;
12007
- }
12008
- if (ttl === "none") {
12009
- return 0;
12010
- }
12011
- if (ttl === "forever") {
12012
- return -1;
12013
- }
12014
- const multi = multiplier[ttl[ttl.length - 1]];
12015
- return Number(ttl.slice(0, -1)) * multi;
12016
- }
12017
- function compareTTL(a, b) {
12018
- const ap = parseTTL(a);
12019
- const bp = parseTTL(b);
12020
- if (ap === -1 && bp !== -1) {
12021
- return 1;
12022
- }
12023
- if (ap !== -1 && bp === -1) {
12024
- return -1;
12025
- }
12026
- return ap - bp;
12027
- }
12028
-
12029
12097
  // ../zero-client/src/client/zero.ts
12030
12098
  import { LogContext as LogContext4 } from "@rocicorp/logger";
12031
12099
  import { resolver as resolver8 } from "@rocicorp/resolver";
@@ -14340,7 +14408,7 @@ function makeMessage(message, context, logLevel) {
14340
14408
  }
14341
14409
 
14342
14410
  // ../zero-client/src/client/version.ts
14343
- var version2 = "0.17.2025031100";
14411
+ var version2 = "0.17.2025031200";
14344
14412
 
14345
14413
  // ../zero-client/src/client/log-options.ts
14346
14414
  var LevelFilterLogSink = class {
@@ -16559,7 +16627,6 @@ export {
16559
16627
  NOBODY_CAN,
16560
16628
  definePermissions,
16561
16629
  escapeLike,
16562
- DEFAULT_TTL2 as DEFAULT_TTL,
16563
16630
  Zero
16564
16631
  };
16565
- //# sourceMappingURL=chunk-2TJNN7K4.js.map
16632
+ //# sourceMappingURL=chunk-VNV6U5BQ.js.map