@rocicorp/zero 0.22.2025080201 → 0.23.2025081200

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 (114) hide show
  1. package/out/analyze-query/src/bin-analyze.js +5 -8
  2. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  3. package/out/{chunk-LENWM5WE.js → chunk-6TQKR5IL.js} +323 -203
  4. package/out/chunk-6TQKR5IL.js.map +7 -0
  5. package/out/chunk-MKB4RXL3.js +15 -0
  6. package/out/chunk-MKB4RXL3.js.map +7 -0
  7. package/out/chunk-SGW2EIVJ.js +192 -0
  8. package/out/chunk-SGW2EIVJ.js.map +7 -0
  9. package/out/{chunk-QVKOYV54.js → chunk-YTS56A64.js} +200 -134
  10. package/out/chunk-YTS56A64.js.map +7 -0
  11. package/out/{chunk-PDLFYV2P.js → chunk-ZJ4VVIKN.js} +6 -4
  12. package/out/chunk-ZJ4VVIKN.js.map +7 -0
  13. package/out/expo.js +356 -0
  14. package/out/expo.js.map +7 -0
  15. package/out/{inspector-AF3UI76B.js → inspector-RB55U26N.js} +86 -26
  16. package/out/inspector-RB55U26N.js.map +7 -0
  17. package/out/{inspector-ENPS6L3H.js → inspector-YIRP3TTL.js} +1 -1
  18. package/out/{inspector-ENPS6L3H.js.map → inspector-YIRP3TTL.js.map} +1 -1
  19. package/out/react.js +7 -4
  20. package/out/react.js.map +2 -2
  21. package/out/replicache/src/kv/sqlite-store.d.ts +117 -0
  22. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -0
  23. package/out/shared/src/centroid.d.ts +10 -0
  24. package/out/shared/src/centroid.d.ts.map +1 -0
  25. package/out/shared/src/dotenv.js +5 -0
  26. package/out/shared/src/dotenv.js.map +1 -1
  27. package/out/shared/src/tdigest.d.ts +42 -0
  28. package/out/shared/src/tdigest.d.ts.map +1 -0
  29. package/out/solid.js +13 -9
  30. package/out/solid.js.map +2 -2
  31. package/out/zero/package.json +7 -4
  32. package/out/zero/src/expo.d.ts +2 -0
  33. package/out/zero/src/expo.d.ts.map +1 -0
  34. package/out/zero/src/zero-cache-dev.js.map +1 -1
  35. package/out/zero-cache/src/auth/write-authorizer.d.ts +1 -0
  36. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  37. package/out/zero-cache/src/auth/write-authorizer.js +10 -5
  38. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  39. package/out/zero-cache/src/config/zero-config.d.ts +0 -10
  40. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  41. package/out/zero-cache/src/config/zero-config.js +0 -5
  42. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  43. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  44. package/out/zero-cache/src/services/mutagen/mutagen.js +1 -0
  45. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  46. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  47. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +2 -1
  48. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  49. package/out/zero-cache/src/types/pg.d.ts +9 -0
  50. package/out/zero-cache/src/types/pg.d.ts.map +1 -1
  51. package/out/zero-cache/src/types/pg.js +78 -1
  52. package/out/zero-cache/src/types/pg.js.map +1 -1
  53. package/out/zero-client/src/client/context.d.ts +11 -11
  54. package/out/zero-client/src/client/context.d.ts.map +1 -1
  55. package/out/zero-client/src/client/custom.d.ts +6 -6
  56. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  57. package/out/zero-client/src/client/inspector/inspector.d.ts +10 -1
  58. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  59. package/out/zero-client/src/client/inspector/types.d.ts +8 -0
  60. package/out/zero-client/src/client/inspector/types.d.ts.map +1 -1
  61. package/out/zero-client/src/client/measure-push-operator.d.ts +17 -0
  62. package/out/zero-client/src/client/measure-push-operator.d.ts.map +1 -0
  63. package/out/zero-client/src/client/options.d.ts +2 -2
  64. package/out/zero-client/src/client/options.d.ts.map +1 -1
  65. package/out/zero-client/src/client/query-manager.d.ts +18 -5
  66. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  67. package/out/zero-client/src/client/zero.d.ts +4 -4
  68. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  69. package/out/zero-client/src/mod.d.ts +1 -1
  70. package/out/zero-client/src/mod.d.ts.map +1 -1
  71. package/out/zero-expo/src/mod.d.ts +2 -0
  72. package/out/zero-expo/src/mod.d.ts.map +1 -0
  73. package/out/zero-expo/src/store.d.ts +4 -0
  74. package/out/zero-expo/src/store.d.ts.map +1 -0
  75. package/out/zero-react/src/components/inspector.d.ts +1 -1
  76. package/out/zero-react/src/components/inspector.d.ts.map +1 -1
  77. package/out/zero-react/src/components/zero-inspector.d.ts +1 -1
  78. package/out/zero-react/src/components/zero-inspector.d.ts.map +1 -1
  79. package/out/zero-react/src/zero-provider.d.ts +4 -4
  80. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  81. package/out/zero-schema/src/permissions.d.ts +15 -0
  82. package/out/zero-schema/src/permissions.d.ts.map +1 -1
  83. package/out/zero-schema/src/table-schema.d.ts +1 -8
  84. package/out/zero-schema/src/table-schema.d.ts.map +1 -1
  85. package/out/zero-schema/src/table-schema.js.map +1 -1
  86. package/out/zero-solid/src/use-zero.d.ts +4 -4
  87. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  88. package/out/zero.js +5 -3
  89. package/out/zql/src/builder/builder.d.ts +3 -2
  90. package/out/zql/src/builder/builder.d.ts.map +1 -1
  91. package/out/zql/src/builder/builder.js +9 -8
  92. package/out/zql/src/builder/builder.js.map +1 -1
  93. package/out/zql/src/ivm/operator.d.ts +1 -1
  94. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  95. package/out/zql/src/ivm/operator.js +0 -1
  96. package/out/zql/src/ivm/operator.js.map +1 -1
  97. package/out/zql/src/query/metrics-delegate.d.ts +10 -0
  98. package/out/zql/src/query/metrics-delegate.d.ts.map +1 -0
  99. package/out/zql/src/query/metrics-delegate.js +2 -0
  100. package/out/zql/src/query/metrics-delegate.js.map +1 -0
  101. package/out/zql/src/query/query-delegate.d.ts +7 -2
  102. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  103. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  104. package/out/zql/src/query/query-impl.js +17 -14
  105. package/out/zql/src/query/query-impl.js.map +1 -1
  106. package/out/zqlite/src/query-delegate.d.ts +7 -6
  107. package/out/zqlite/src/query-delegate.d.ts.map +1 -1
  108. package/out/zqlite/src/query-delegate.js +5 -2
  109. package/out/zqlite/src/query-delegate.js.map +1 -1
  110. package/package.json +7 -4
  111. package/out/chunk-LENWM5WE.js.map +0 -7
  112. package/out/chunk-PDLFYV2P.js.map +0 -7
  113. package/out/chunk-QVKOYV54.js.map +0 -7
  114. package/out/inspector-AF3UI76B.js.map +0 -7
@@ -1,60 +1,22 @@
1
+ import {
2
+ assert,
3
+ assertArray,
4
+ assertBoolean,
5
+ assertDeepFrozen,
6
+ assertNumber,
7
+ assertObject,
8
+ assertString,
9
+ deepFreeze,
10
+ hasOwn,
11
+ isProd,
12
+ throwInvalidType,
13
+ unreachable
14
+ } from "./chunk-SGW2EIVJ.js";
1
15
  import {
2
16
  __export,
3
17
  __reExport
4
18
  } from "./chunk-424PT5DM.js";
5
19
 
6
- // ../shared/src/asserts.ts
7
- function assert(b, msg = "Assertion failed") {
8
- if (!b) {
9
- throw new Error(typeof msg === "string" ? msg : msg());
10
- }
11
- }
12
- function assertString(v2) {
13
- assertType(v2, "string");
14
- }
15
- function assertNumber(v2) {
16
- assertType(v2, "number");
17
- }
18
- function assertBoolean(v2) {
19
- assertType(v2, "boolean");
20
- }
21
- function assertType(v2, t) {
22
- if (typeof v2 !== t) {
23
- throwInvalidType(v2, t);
24
- }
25
- }
26
- function assertObject(v2) {
27
- if (v2 === null) {
28
- throwInvalidType(v2, "object");
29
- }
30
- assertType(v2, "object");
31
- }
32
- function assertArray(v2) {
33
- if (!Array.isArray(v2)) {
34
- throwInvalidType(v2, "array");
35
- }
36
- }
37
- function invalidType(v2, t) {
38
- let s = "Invalid type: ";
39
- if (v2 === null || v2 === void 0) {
40
- s += v2;
41
- } else {
42
- s += `${typeof v2} \`${v2}\``;
43
- }
44
- return s + `, expected ${t}`;
45
- }
46
- function throwInvalidType(v2, t) {
47
- throw new Error(invalidType(v2, t));
48
- }
49
- function assertNotNull(v2) {
50
- if (v2 === null) {
51
- throw new Error("Expected non-null value");
52
- }
53
- }
54
- function unreachable(_) {
55
- throw new Error("Unreachable");
56
- }
57
-
58
20
  // ../shared/src/valita.ts
59
21
  var valita_exports = {};
60
22
  __export(valita_exports, {
@@ -296,12 +258,6 @@ var V6 = 6;
296
258
  var V7 = 7;
297
259
  var Latest = V7;
298
260
 
299
- // ../shared/src/config.ts
300
- var isProd = process.env.NODE_ENV === "production";
301
-
302
- // ../shared/src/has-own.ts
303
- var { hasOwn } = Object;
304
-
305
261
  // ../shared/src/json.ts
306
262
  function deepEqual(a, b) {
307
263
  if (a === b) {
@@ -599,123 +555,6 @@ function wrapIterable(iter) {
599
555
  return new IterWrapper(iter);
600
556
  }
601
557
 
602
- // ../replicache/src/frozen-json.ts
603
- var deepFrozenObjects = /* @__PURE__ */ new WeakSet();
604
- function deepFreeze(v2) {
605
- if (isProd) {
606
- return v2;
607
- }
608
- deepFreezeInternal(v2, []);
609
- return v2;
610
- }
611
- function deepFreezeInternal(v2, seen) {
612
- switch (typeof v2) {
613
- case "undefined":
614
- throw new TypeError("Unexpected value undefined");
615
- case "boolean":
616
- case "number":
617
- case "string":
618
- return;
619
- case "object": {
620
- if (v2 === null) {
621
- return;
622
- }
623
- if (deepFrozenObjects.has(v2)) {
624
- return;
625
- }
626
- deepFrozenObjects.add(v2);
627
- if (seen.includes(v2)) {
628
- throwInvalidType(v2, "Cyclic JSON object");
629
- }
630
- seen.push(v2);
631
- Object.freeze(v2);
632
- if (Array.isArray(v2)) {
633
- deepFreezeArray(v2, seen);
634
- } else {
635
- deepFreezeObject(v2, seen);
636
- }
637
- seen.pop();
638
- return;
639
- }
640
- default:
641
- throwInvalidType(v2, "JSON value");
642
- }
643
- }
644
- function deepFreezeArray(v2, seen) {
645
- for (const item of v2) {
646
- deepFreezeInternal(item, seen);
647
- }
648
- }
649
- function deepFreezeObject(v2, seen) {
650
- for (const k in v2) {
651
- if (hasOwn(v2, k)) {
652
- const value = v2[k];
653
- if (value !== void 0) {
654
- deepFreezeInternal(value, seen);
655
- }
656
- }
657
- }
658
- }
659
- function assertDeepFrozen(v2) {
660
- if (isProd) {
661
- return;
662
- }
663
- if (!isDeepFrozen(v2, [])) {
664
- throw new Error("Expected frozen object");
665
- }
666
- }
667
- function isDeepFrozen(v2, seen) {
668
- switch (typeof v2) {
669
- case "boolean":
670
- case "number":
671
- case "string":
672
- return true;
673
- case "object":
674
- if (v2 === null) {
675
- return true;
676
- }
677
- if (deepFrozenObjects.has(v2)) {
678
- return true;
679
- }
680
- if (!Object.isFrozen(v2)) {
681
- return false;
682
- }
683
- if (seen.includes(v2)) {
684
- throwInvalidType(v2, "Cyclic JSON object");
685
- }
686
- seen.push(v2);
687
- if (Array.isArray(v2)) {
688
- for (const item of v2) {
689
- if (!isDeepFrozen(item, seen)) {
690
- seen.pop();
691
- return false;
692
- }
693
- }
694
- } else {
695
- for (const k in v2) {
696
- if (hasOwn(v2, k)) {
697
- const value = v2[k];
698
- if (value !== void 0 && !isDeepFrozen(value, seen)) {
699
- seen.pop();
700
- return false;
701
- }
702
- }
703
- }
704
- }
705
- deepFrozenObjects.add(v2);
706
- seen.pop();
707
- return true;
708
- default:
709
- throwInvalidType(v2, "JSON value");
710
- }
711
- }
712
- function deepFreezeAllowUndefined(v2) {
713
- if (v2 === void 0) {
714
- return void 0;
715
- }
716
- return deepFreeze(v2);
717
- }
718
-
719
558
  // ../replicache/src/btree/node.ts
720
559
  var NODE_LEVEL = 0;
721
560
  var NODE_ENTRIES = 1;
@@ -3969,6 +3808,283 @@ function sourceNameFromKey(key) {
3969
3808
  return key.slice(ENTITIES_KEY_PREFIX.length, slash);
3970
3809
  }
3971
3810
 
3811
+ // ../shared/src/centroid.ts
3812
+ var Centroid = class {
3813
+ mean;
3814
+ weight;
3815
+ constructor(mean, weight) {
3816
+ this.mean = mean;
3817
+ this.weight = weight;
3818
+ }
3819
+ add(r) {
3820
+ if (r.weight < 0) {
3821
+ throw new Error("centroid weight cannot be less than zero");
3822
+ }
3823
+ if (this.weight !== 0) {
3824
+ this.weight += r.weight;
3825
+ this.mean += r.weight * (r.mean - this.mean) / this.weight;
3826
+ } else {
3827
+ this.weight = r.weight;
3828
+ this.mean = r.mean;
3829
+ }
3830
+ }
3831
+ };
3832
+ function sortCentroidList(centroids) {
3833
+ centroids.sort((a, b) => a.mean - b.mean);
3834
+ }
3835
+
3836
+ // ../shared/src/tdigest.ts
3837
+ var TDigest = class {
3838
+ compression;
3839
+ #maxProcessed;
3840
+ #maxUnprocessed;
3841
+ #processed;
3842
+ #unprocessed;
3843
+ #cumulative;
3844
+ #processedWeight;
3845
+ #unprocessedWeight;
3846
+ #min;
3847
+ #max;
3848
+ constructor(compression = 1e3) {
3849
+ this.compression = compression;
3850
+ this.#maxProcessed = processedSize(0, this.compression);
3851
+ this.#maxUnprocessed = unprocessedSize(0, this.compression);
3852
+ this.reset();
3853
+ }
3854
+ reset() {
3855
+ this.#processed = [];
3856
+ this.#unprocessed = [];
3857
+ this.#cumulative = [];
3858
+ this.#processedWeight = 0;
3859
+ this.#unprocessedWeight = 0;
3860
+ this.#min = Number.MAX_VALUE;
3861
+ this.#max = -Number.MAX_VALUE;
3862
+ }
3863
+ add(mean, weight = 1) {
3864
+ this.addCentroid(new Centroid(mean, weight));
3865
+ }
3866
+ /** AddCentroidList can quickly add multiple centroids. */
3867
+ addCentroidList(centroidList) {
3868
+ for (const c of centroidList) {
3869
+ this.addCentroid(c);
3870
+ }
3871
+ }
3872
+ /**
3873
+ * AddCentroid adds a single centroid.
3874
+ * Weights which are not a number or are <= 0 are ignored, as are NaN means.
3875
+ */
3876
+ addCentroid(c) {
3877
+ if (Number.isNaN(c.mean) || c.weight <= 0 || Number.isNaN(c.weight) || !Number.isFinite(c.weight)) {
3878
+ return;
3879
+ }
3880
+ this.#unprocessed.push(new Centroid(c.mean, c.weight));
3881
+ this.#unprocessedWeight += c.weight;
3882
+ if (this.#processed.length > this.#maxProcessed || this.#unprocessed.length > this.#maxUnprocessed) {
3883
+ this.#process();
3884
+ }
3885
+ }
3886
+ /**
3887
+ * Merges the supplied digest into this digest. Functionally equivalent to
3888
+ * calling t.AddCentroidList(t2.Centroids(nil)), but avoids making an extra
3889
+ * copy of the CentroidList.
3890
+ **/
3891
+ merge(t2) {
3892
+ t2.#process();
3893
+ this.addCentroidList(t2.#processed);
3894
+ }
3895
+ #process() {
3896
+ if (this.#unprocessed.length > 0 || this.#processed.length > this.#maxProcessed) {
3897
+ this.#unprocessed.push(...this.#processed);
3898
+ sortCentroidList(this.#unprocessed);
3899
+ this.#processed.length = 0;
3900
+ this.#processed.push(this.#unprocessed[0]);
3901
+ this.#processedWeight += this.#unprocessedWeight;
3902
+ this.#unprocessedWeight = 0;
3903
+ let soFar = this.#unprocessed[0].weight;
3904
+ let limit = this.#processedWeight * this.#integratedQ(1);
3905
+ for (let i = 1; i < this.#unprocessed.length; i++) {
3906
+ const centroid = this.#unprocessed[i];
3907
+ const projected = soFar + centroid.weight;
3908
+ if (projected <= limit) {
3909
+ soFar = projected;
3910
+ this.#processed[this.#processed.length - 1].add(centroid);
3911
+ } else {
3912
+ const k1 = this.#integratedLocation(soFar / this.#processedWeight);
3913
+ limit = this.#processedWeight * this.#integratedQ(k1 + 1);
3914
+ soFar += centroid.weight;
3915
+ this.#processed.push(centroid);
3916
+ }
3917
+ }
3918
+ this.#min = Math.min(this.#min, this.#processed[0].mean);
3919
+ this.#max = Math.max(
3920
+ this.#max,
3921
+ this.#processed[this.#processed.length - 1].mean
3922
+ );
3923
+ this.#unprocessed.length = 0;
3924
+ }
3925
+ }
3926
+ /**
3927
+ * Centroids returns a copy of processed centroids.
3928
+ * Useful when aggregating multiple t-digests.
3929
+ *
3930
+ * Centroids are appended to the passed CentroidList; if you're re-using a
3931
+ * buffer, be sure to pass cl[:0].
3932
+ */
3933
+ centroids(cl = []) {
3934
+ this.#process();
3935
+ return cl.concat(this.#processed);
3936
+ }
3937
+ count() {
3938
+ this.#process();
3939
+ return this.#processedWeight;
3940
+ }
3941
+ #updateCumulative() {
3942
+ if (this.#cumulative.length > 0 && this.#cumulative[this.#cumulative.length - 1] === this.#processedWeight) {
3943
+ return;
3944
+ }
3945
+ const n = this.#processed.length + 1;
3946
+ if (this.#cumulative.length > n) {
3947
+ this.#cumulative.length = n;
3948
+ }
3949
+ let prev = 0;
3950
+ for (let i = 0; i < this.#processed.length; i++) {
3951
+ const centroid = this.#processed[i];
3952
+ const cur = centroid.weight;
3953
+ this.#cumulative[i] = prev + cur / 2;
3954
+ prev += cur;
3955
+ }
3956
+ this.#cumulative[this.#processed.length] = prev;
3957
+ }
3958
+ // Quantile returns the (approximate) quantile of
3959
+ // the distribution. Accepted values for q are between 0 and 1.
3960
+ // Returns NaN if Count is zero or bad inputs.
3961
+ quantile(q) {
3962
+ this.#process();
3963
+ this.#updateCumulative();
3964
+ if (q < 0 || q > 1 || this.#processed.length === 0) {
3965
+ return NaN;
3966
+ }
3967
+ if (this.#processed.length === 1) {
3968
+ return this.#processed[0].mean;
3969
+ }
3970
+ const index = q * this.#processedWeight;
3971
+ if (index <= this.#processed[0].weight / 2) {
3972
+ return this.#min + 2 * index / this.#processed[0].weight * (this.#processed[0].mean - this.#min);
3973
+ }
3974
+ const lower = binarySearch(
3975
+ this.#cumulative.length,
3976
+ (i) => -this.#cumulative[i] + index
3977
+ );
3978
+ if (lower + 1 !== this.#cumulative.length) {
3979
+ const z12 = index - this.#cumulative[lower - 1];
3980
+ const z22 = this.#cumulative[lower] - index;
3981
+ return weightedAverage(
3982
+ this.#processed[lower - 1].mean,
3983
+ z22,
3984
+ this.#processed[lower].mean,
3985
+ z12
3986
+ );
3987
+ }
3988
+ const z1 = index - this.#processedWeight - this.#processed[lower - 1].weight / 2;
3989
+ const z2 = this.#processed[lower - 1].weight / 2 - z1;
3990
+ return weightedAverage(
3991
+ this.#processed[this.#processed.length - 1].mean,
3992
+ z1,
3993
+ this.#max,
3994
+ z2
3995
+ );
3996
+ }
3997
+ /**
3998
+ * CDF returns the cumulative distribution function for a given value x.
3999
+ */
4000
+ cdf(x) {
4001
+ this.#process();
4002
+ this.#updateCumulative();
4003
+ switch (this.#processed.length) {
4004
+ case 0:
4005
+ return 0;
4006
+ case 1: {
4007
+ const width = this.#max - this.#min;
4008
+ if (x <= this.#min) {
4009
+ return 0;
4010
+ }
4011
+ if (x >= this.#max) {
4012
+ return 1;
4013
+ }
4014
+ if (x - this.#min <= width) {
4015
+ return 0.5;
4016
+ }
4017
+ return (x - this.#min) / width;
4018
+ }
4019
+ }
4020
+ if (x <= this.#min) {
4021
+ return 0;
4022
+ }
4023
+ if (x >= this.#max) {
4024
+ return 1;
4025
+ }
4026
+ const m0 = this.#processed[0].mean;
4027
+ if (x <= m0) {
4028
+ if (m0 - this.#min > 0) {
4029
+ return (x - this.#min) / (m0 - this.#min) * this.#processed[0].weight / this.#processedWeight / 2;
4030
+ }
4031
+ return 0;
4032
+ }
4033
+ const mn = this.#processed[this.#processed.length - 1].mean;
4034
+ if (x >= mn) {
4035
+ if (this.#max - mn > 0) {
4036
+ return 1 - (this.#max - x) / (this.#max - mn) * this.#processed[this.#processed.length - 1].weight / this.#processedWeight / 2;
4037
+ }
4038
+ return 1;
4039
+ }
4040
+ const upper = binarySearch(
4041
+ this.#processed.length,
4042
+ // Treat equals as greater than, so we can use the upper index
4043
+ // This is equivalent to:
4044
+ // i => this.#processed[i].mean > x ? -1 : 1,
4045
+ (i) => x - this.#processed[i].mean || 1
4046
+ );
4047
+ const z1 = x - this.#processed[upper - 1].mean;
4048
+ const z2 = this.#processed[upper].mean - x;
4049
+ return weightedAverage(
4050
+ this.#cumulative[upper - 1],
4051
+ z2,
4052
+ this.#cumulative[upper],
4053
+ z1
4054
+ ) / this.#processedWeight;
4055
+ }
4056
+ #integratedQ(k) {
4057
+ return (Math.sin(
4058
+ Math.min(k, this.compression) * Math.PI / this.compression - Math.PI / 2
4059
+ ) + 1) / 2;
4060
+ }
4061
+ #integratedLocation(q) {
4062
+ return this.compression * (Math.asin(2 * q - 1) + Math.PI / 2) / Math.PI;
4063
+ }
4064
+ };
4065
+ function weightedAverage(x1, w1, x2, w2) {
4066
+ if (x1 <= x2) {
4067
+ return weightedAverageSorted(x1, w1, x2, w2);
4068
+ }
4069
+ return weightedAverageSorted(x2, w2, x1, w1);
4070
+ }
4071
+ function weightedAverageSorted(x1, w1, x2, w2) {
4072
+ const x = (x1 * w1 + x2 * w2) / (w1 + w2);
4073
+ return Math.max(x1, Math.min(x, x2));
4074
+ }
4075
+ function processedSize(size, compression) {
4076
+ if (size === 0) {
4077
+ return Math.ceil(compression) * 2;
4078
+ }
4079
+ return size;
4080
+ }
4081
+ function unprocessedSize(size, compression) {
4082
+ if (size === 0) {
4083
+ return Math.ceil(compression) * 8;
4084
+ }
4085
+ return size;
4086
+ }
4087
+
3972
4088
  // ../zero-schema/src/table-schema.ts
3973
4089
  function isOneHop(r) {
3974
4090
  return r.length === 1;
@@ -5909,14 +6025,15 @@ function transformFilters(filters) {
5909
6025
  }
5910
6026
 
5911
6027
  // ../zql/src/builder/builder.ts
5912
- function buildPipeline(ast, delegate) {
6028
+ function buildPipeline(ast, delegate, queryID) {
5913
6029
  return buildPipelineInternal(
5914
6030
  delegate.mapAst ? delegate.mapAst(ast) : ast,
5915
6031
  delegate,
6032
+ queryID,
5916
6033
  ""
5917
6034
  );
5918
6035
  }
5919
- function buildPipelineInternal(ast, delegate, name, partitionKey) {
6036
+ function buildPipelineInternal(ast, delegate, queryID, name, partitionKey) {
5920
6037
  const source = delegate.getSource(ast.table);
5921
6038
  if (!source) {
5922
6039
  throw new Error(`Source not found: ${ast.table}`);
@@ -5941,13 +6058,14 @@ function buildPipelineInternal(ast, delegate, name, partitionKey) {
5941
6058
  }
5942
6059
  }
5943
6060
  const conn = source.connect(must(ast.orderBy), ast.where, splitEditKeys);
5944
- let end = delegate.decorateInput(conn, `${name}:source(${ast.table})`);
6061
+ let end = delegate.decorateSourceInput(conn, queryID);
6062
+ end = delegate.decorateInput(end, `${name}:source(${ast.table})`);
5945
6063
  const { fullyAppliedFilters } = conn;
5946
6064
  if (ast.start) {
5947
6065
  end = delegate.decorateInput(new Skip(end, ast.start), `${name}:skip)`);
5948
6066
  }
5949
6067
  for (const csq of csqsFromCondition) {
5950
- end = applyCorrelatedSubQuery(csq, delegate, end, name, true);
6068
+ end = applyCorrelatedSubQuery(csq, delegate, queryID, end, name, true);
5951
6069
  }
5952
6070
  if (ast.where && !fullyAppliedFilters) {
5953
6071
  end = applyWhere(end, ast.where, delegate, name);
@@ -5961,7 +6079,7 @@ function buildPipelineInternal(ast, delegate, name, partitionKey) {
5961
6079
  }
5962
6080
  if (ast.related) {
5963
6081
  for (const csq of ast.related) {
5964
- end = applyCorrelatedSubQuery(csq, delegate, end, name, false);
6082
+ end = applyCorrelatedSubQuery(csq, delegate, queryID, end, name, false);
5965
6083
  }
5966
6084
  }
5967
6085
  return end;
@@ -6043,7 +6161,7 @@ function isNotAndDoesNotContainSubquery(condition) {
6043
6161
  function applySimpleCondition(input, condition) {
6044
6162
  return new Filter(input, createPredicate(condition));
6045
6163
  }
6046
- function applyCorrelatedSubQuery(sq, delegate, end, name, fromCondition) {
6164
+ function applyCorrelatedSubQuery(sq, delegate, queryID, end, name, fromCondition) {
6047
6165
  if (sq.subquery.limit === 0 && fromCondition) {
6048
6166
  return end;
6049
6167
  }
@@ -6051,6 +6169,7 @@ function applyCorrelatedSubQuery(sq, delegate, end, name, fromCondition) {
6051
6169
  const child = buildPipelineInternal(
6052
6170
  sq.subquery,
6053
6171
  delegate,
6172
+ queryID,
6054
6173
  `${name}.${sq.subquery.alias}`,
6055
6174
  sq.correlation.childField
6056
6175
  );
@@ -6795,7 +6914,6 @@ var QueryImpl = class _QueryImpl extends AbstractQuery {
6795
6914
  this._delegate,
6796
6915
  "materialize requires a query delegate to be set"
6797
6916
  );
6798
- const t0 = Date.now();
6799
6917
  let factory;
6800
6918
  if (typeof factoryOrTTL === "function") {
6801
6919
  factory = factoryOrTTL;
@@ -6803,27 +6921,33 @@ var QueryImpl = class _QueryImpl extends AbstractQuery {
6803
6921
  ttl = factoryOrTTL ?? DEFAULT_TTL_MS;
6804
6922
  }
6805
6923
  const ast = this._completeAst();
6924
+ const queryID = this.customQueryID ? hashOfNameAndArgs(this.customQueryID.name, this.customQueryID.args) : this.hash();
6806
6925
  const queryCompleteResolver = resolver();
6807
6926
  let queryComplete = delegate.defaultQueryComplete;
6927
+ const updateTTL = (newTTL) => {
6928
+ this.customQueryID ? delegate.updateCustomQuery(this.customQueryID, newTTL) : delegate.updateServerQuery(ast, newTTL);
6929
+ };
6808
6930
  const gotCallback = (got) => {
6809
6931
  if (got) {
6810
- const t1 = Date.now();
6811
- delegate.onQueryMaterialized(this.hash(), ast, t1 - t0);
6932
+ delegate.addMetric(
6933
+ "query-materialization-end-to-end",
6934
+ performance.now() - t0,
6935
+ queryID,
6936
+ ast
6937
+ );
6812
6938
  queryComplete = true;
6813
6939
  queryCompleteResolver.resolve(true);
6814
6940
  }
6815
6941
  };
6816
- const removeServerQuery = this.customQueryID ? delegate.addCustomQuery(this.customQueryID, ttl, gotCallback) : delegate.addServerQuery(ast, ttl, gotCallback);
6817
- const updateTTL = (newTTL) => {
6818
- this.customQueryID ? delegate.updateCustomQuery(this.customQueryID, newTTL) : delegate.updateServerQuery(ast, newTTL);
6819
- };
6820
- const input = buildPipeline(ast, delegate);
6821
6942
  let removeCommitObserver;
6822
6943
  const onDestroy = () => {
6823
6944
  input.destroy();
6824
6945
  removeCommitObserver?.();
6825
- removeServerQuery();
6946
+ removeAddedQuery();
6826
6947
  };
6948
+ const t0 = performance.now();
6949
+ const removeAddedQuery = this.customQueryID ? delegate.addCustomQuery(this.customQueryID, ttl, gotCallback) : delegate.addServerQuery(ast, ttl, gotCallback);
6950
+ const input = buildPipeline(ast, delegate, queryID);
6827
6951
  const view = delegate.batchViewUpdates(
6828
6952
  () => (factory ?? arrayViewFactory)(
6829
6953
  this,
@@ -6837,6 +6961,11 @@ var QueryImpl = class _QueryImpl extends AbstractQuery {
6837
6961
  updateTTL
6838
6962
  )
6839
6963
  );
6964
+ delegate.addMetric(
6965
+ "query-materialization-client",
6966
+ performance.now() - t0,
6967
+ queryID
6968
+ );
6840
6969
  return view;
6841
6970
  }
6842
6971
  run(options) {
@@ -6930,23 +7059,12 @@ function isCompoundKey(field) {
6930
7059
  }
6931
7060
 
6932
7061
  export {
6933
- assert,
6934
- assertString,
6935
- assertNumber,
6936
- assertObject,
6937
- assertArray,
6938
- assertNotNull,
6939
- unreachable,
6940
- isProd,
6941
- hasOwn,
6942
7062
  deepEqual,
6943
7063
  assertJSONValue,
6944
7064
  assertJSONObject,
6945
7065
  stringCompare,
6946
7066
  compareCookies,
6947
7067
  assertCookie,
6948
- deepFreeze,
6949
- deepFreezeAllowUndefined,
6950
7068
  parse,
6951
7069
  test,
6952
7070
  readonly,
@@ -7042,6 +7160,7 @@ export {
7042
7160
  compareValues,
7043
7161
  makeComparator,
7044
7162
  valuesEqual,
7163
+ throwOutput,
7045
7164
  filterPush,
7046
7165
  ExpressionBuilder,
7047
7166
  createPredicate,
@@ -7072,6 +7191,7 @@ export {
7072
7191
  toGotQueriesKey,
7073
7192
  toMutationResponseKey,
7074
7193
  toPrimaryKeyString,
7075
- sourceNameFromKey
7194
+ sourceNameFromKey,
7195
+ TDigest
7076
7196
  };
7077
- //# sourceMappingURL=chunk-LENWM5WE.js.map
7197
+ //# sourceMappingURL=chunk-6TQKR5IL.js.map