@rocicorp/zero 0.3.2024102501 → 0.3.2024102600

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 (80) hide show
  1. package/out/{chunk-2RUT5EQV.js → chunk-F5QR3K72.js} +2 -7
  2. package/out/chunk-F5QR3K72.js.map +7 -0
  3. package/out/chunk-HARIWJ2J.js +8 -0
  4. package/out/{chunk-2RUT5EQV.js.map → chunk-HARIWJ2J.js.map} +1 -1
  5. package/out/chunk-NKGIR6IA.js +1 -0
  6. package/out/chunk-NKGIR6IA.js.map +7 -0
  7. package/out/chunk-RCVGGCMG.js +288 -0
  8. package/out/chunk-RCVGGCMG.js.map +7 -0
  9. package/out/internal.js +9 -0
  10. package/out/internal.js.map +7 -0
  11. package/out/react.js +2 -1
  12. package/out/react.js.map +1 -1
  13. package/out/replicache/src/version.d.ts.map +1 -1
  14. package/out/replicache/src/version.js +2 -1
  15. package/out/replicache/src/version.js.map +1 -1
  16. package/out/solid.js +82 -0
  17. package/out/solid.js.map +7 -0
  18. package/out/zero/src/internal.d.ts +2 -0
  19. package/out/zero/src/internal.d.ts.map +1 -0
  20. package/out/zero/src/solid.d.ts +2 -0
  21. package/out/zero/src/solid.d.ts.map +1 -0
  22. package/out/zero-cache/src/config/config-query.d.ts +1 -1
  23. package/out/zero-cache/src/config/config-query.d.ts.map +1 -1
  24. package/out/zero-cache/src/server/life-cycle.d.ts +1 -0
  25. package/out/zero-cache/src/server/life-cycle.d.ts.map +1 -1
  26. package/out/zero-cache/src/server/life-cycle.js +10 -9
  27. package/out/zero-cache/src/server/life-cycle.js.map +1 -1
  28. package/out/zero-cache/src/server/main.js +2 -0
  29. package/out/zero-cache/src/server/main.js.map +1 -1
  30. package/out/zero-cache/src/server/task-state-watcher.d.ts +14 -0
  31. package/out/zero-cache/src/server/task-state-watcher.d.ts.map +1 -0
  32. package/out/zero-cache/src/server/task-state-watcher.js +75 -0
  33. package/out/zero-cache/src/server/task-state-watcher.js.map +1 -0
  34. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  35. package/out/zero-cache/src/services/view-syncer/view-syncer.js +10 -4
  36. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  37. package/out/zero-client/src/client/version.d.ts.map +1 -1
  38. package/out/zero-client/src/client/version.js +2 -1
  39. package/out/zero-client/src/client/version.js.map +1 -1
  40. package/out/zero-client/src/client/zero.d.ts +1 -0
  41. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  42. package/out/zero-client/src/client/zero.js +3 -0
  43. package/out/zero-client/src/client/zero.js.map +1 -1
  44. package/out/zero-client/src/mod.d.ts +2 -2
  45. package/out/zero-client/src/mod.d.ts.map +1 -1
  46. package/out/zero-client/src/mod.js +2 -1
  47. package/out/zero-client/src/mod.js.map +1 -1
  48. package/out/zero-internal/src/mod.d.ts +7 -0
  49. package/out/zero-internal/src/mod.d.ts.map +1 -0
  50. package/out/zero-solid/src/mod.d.ts +2 -0
  51. package/out/zero-solid/src/mod.d.ts.map +1 -0
  52. package/out/zero-solid/src/solid-view.d.ts +10 -0
  53. package/out/zero-solid/src/solid-view.d.ts.map +1 -0
  54. package/out/zero-solid/src/use-query.d.ts +5 -0
  55. package/out/zero-solid/src/use-query.d.ts.map +1 -0
  56. package/out/zero.js +53 -287
  57. package/out/zero.js.map +4 -4
  58. package/out/zql/src/zql/ivm/array-view.d.ts +1 -10
  59. package/out/zql/src/zql/ivm/array-view.d.ts.map +1 -1
  60. package/out/zql/src/zql/ivm/array-view.js +2 -158
  61. package/out/zql/src/zql/ivm/array-view.js.map +1 -1
  62. package/out/zql/src/zql/ivm/view-apply-change.d.ts +5 -0
  63. package/out/zql/src/zql/ivm/view-apply-change.d.ts.map +1 -0
  64. package/out/zql/src/zql/ivm/view-apply-change.js +156 -0
  65. package/out/zql/src/zql/ivm/view-apply-change.js.map +1 -0
  66. package/out/zql/src/zql/ivm/view.d.ts +15 -0
  67. package/out/zql/src/zql/ivm/view.d.ts.map +1 -0
  68. package/out/zql/src/zql/ivm/view.js +2 -0
  69. package/out/zql/src/zql/ivm/view.js.map +1 -0
  70. package/out/zql/src/zql/query/query-impl.d.ts +4 -1
  71. package/out/zql/src/zql/query/query-impl.d.ts.map +1 -1
  72. package/out/zql/src/zql/query/query-impl.js +22 -8
  73. package/out/zql/src/zql/query/query-impl.js.map +1 -1
  74. package/out/zql/src/zql/query/query.d.ts +2 -0
  75. package/out/zql/src/zql/query/query.d.ts.map +1 -1
  76. package/out/zql/src/zql/query/schema.d.ts +1 -0
  77. package/out/zql/src/zql/query/schema.d.ts.map +1 -1
  78. package/out/zql/src/zql/query/schema.js +3 -0
  79. package/out/zql/src/zql/query/schema.js.map +1 -1
  80. package/package.json +9 -1
@@ -0,0 +1,10 @@
1
+ import { type Change, type Format, type Input, type Output, type Query, type QueryType, type Smash, type TableSchema, type View } from '../../zero-internal/src/mod.js';
2
+ export declare class SolidView<V extends View> implements Output {
3
+ #private;
4
+ constructor(input: Input, format?: Format, onDestroy?: () => void);
5
+ get data(): V;
6
+ destroy(): void;
7
+ push(change: Change): void;
8
+ }
9
+ export declare function solidViewFactory<TSchema extends TableSchema, TReturn extends QueryType>(_query: Query<TSchema, TReturn>, input: Input, format: Format, onDestroy: () => void): SolidView<Smash<TReturn>>;
10
+ //# sourceMappingURL=solid-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid-view.d.ts","sourceRoot":"","sources":["../../../../zero-solid/src/solid-view.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,MAAM,EAEX,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,IAAI,EACV,MAAM,gCAAgC,CAAC;AAExC,qBAAa,SAAS,CAAC,CAAC,SAAS,IAAI,CAAE,YAAW,MAAM;;gBAWpD,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE,MAA6C,EACrD,SAAS,GAAE,MAAM,IAAe;IAyBlC,IAAI,IAAI,IACmB,CAAC,CAC3B;IAED,OAAO;IAIP,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAa3B;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,SAAS,WAAW,EAC3B,OAAO,SAAS,SAAS,EAEzB,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAC/B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,IAAI,GACpB,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAI3B"}
@@ -0,0 +1,5 @@
1
+ import { type Accessor } from 'solid-js';
2
+ import type { TableSchema } from '../../zql/src/zql/query/schema.js';
3
+ import type { Query, QueryType, Smash } from '../../zql/src/zql/query/query.js';
4
+ export declare function useQuery<TSchema extends TableSchema, TReturn extends QueryType>(querySignal: () => Query<TSchema, TReturn>): Accessor<Smash<TReturn>>;
5
+ //# sourceMappingURL=use-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../../../zero-solid/src/use-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,QAAQ,EAAwB,MAAM,UAAU,CAAC;AAC9D,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAC,MAAM,kCAAkC,CAAC;AAG9E,wBAAgB,QAAQ,CACtB,OAAO,SAAS,WAAW,EAC3B,OAAO,SAAS,SAAS,EACzB,WAAW,EAAE,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAWtE"}
package/out/zero.js CHANGED
@@ -1,74 +1,28 @@
1
1
  import {
2
- __export,
3
- __reExport,
4
2
  hasOwn
5
- } from "./chunk-2RUT5EQV.js";
3
+ } from "./chunk-HARIWJ2J.js";
4
+ import {
5
+ applyChange,
6
+ assert,
7
+ assertArray,
8
+ assertBoolean,
9
+ assertNotNull,
10
+ assertNotUndefined,
11
+ assertNumber,
12
+ assertObject,
13
+ assertString,
14
+ must,
15
+ throwInvalidType,
16
+ unreachable
17
+ } from "./chunk-RCVGGCMG.js";
18
+ import {
19
+ __export,
20
+ __reExport
21
+ } from "./chunk-F5QR3K72.js";
6
22
 
7
23
  // ../replicache/src/mod.ts
8
24
  import { consoleLogSink as consoleLogSink3 } from "@rocicorp/logger";
9
25
 
10
- // ../shared/src/asserts.ts
11
- function assert(b, msg = "Assertion failed") {
12
- if (!b) {
13
- throw new Error(msg);
14
- }
15
- }
16
- function assertString(v2) {
17
- assertType(v2, "string");
18
- }
19
- function assertNumber(v2) {
20
- assertType(v2, "number");
21
- }
22
- function assertBoolean(v2) {
23
- assertType(v2, "boolean");
24
- }
25
- function assertType(v2, t2) {
26
- if (typeof v2 !== t2) {
27
- throwInvalidType(v2, t2);
28
- }
29
- }
30
- function assertObject(v2) {
31
- if (v2 === null) {
32
- throwInvalidType(v2, "object");
33
- }
34
- assertType(v2, "object");
35
- }
36
- function assertArray(v2) {
37
- if (!Array.isArray(v2)) {
38
- throwInvalidType(v2, "array");
39
- }
40
- }
41
- function invalidType(v2, t2) {
42
- let s = "Invalid type: ";
43
- if (v2 === null || v2 === void 0) {
44
- s += v2;
45
- } else {
46
- s += `${typeof v2} \`${v2}\``;
47
- }
48
- return s + `, expected ${t2}`;
49
- }
50
- function throwInvalidType(v2, t2) {
51
- throw new Error(invalidType(v2, t2));
52
- }
53
- function assertNotNull(v2) {
54
- if (v2 === null) {
55
- throw new Error("Expected non-null value");
56
- }
57
- }
58
- function assertUndefined(v2, msg = "Expected undefined value") {
59
- if (v2 !== void 0) {
60
- throw new Error(msg);
61
- }
62
- }
63
- function assertNotUndefined(v2, msg = "Expected non undefined value") {
64
- if (v2 === void 0) {
65
- throw new Error(msg);
66
- }
67
- }
68
- function unreachable(_) {
69
- throw new Error("Unreachable");
70
- }
71
-
72
26
  // ../shared/src/config.ts
73
27
  var isProd = process.env.NODE_ENV === "production";
74
28
 
@@ -9227,14 +9181,6 @@ async function anyPendingMutationsInClientGroups(perdag) {
9227
9181
  // ../zql/src/zql/query/query-impl.ts
9228
9182
  import { resolver as resolver7 } from "@rocicorp/resolver";
9229
9183
 
9230
- // ../shared/src/must.ts
9231
- function must(v2, msg) {
9232
- if (v2 == null) {
9233
- throw new Error(msg ?? `Unexpected ${v2} value`);
9234
- }
9235
- return v2;
9236
- }
9237
-
9238
9184
  // ../zql/src/zql/ivm/maybe-split-and-push-edit-change.ts
9239
9185
  function maybeSplitAndPushEditChange(change, predicate, output) {
9240
9186
  const oldWasPresent = predicate(change.oldRow);
@@ -10437,7 +10383,6 @@ var ArrayView = class {
10437
10383
  this.#format = format;
10438
10384
  this.#input.setOutput(this);
10439
10385
  this.#root = { "": format.singular ? void 0 : [] };
10440
- assertOrderingIncludesPK(this.#schema.sort, this.#schema.primaryKey);
10441
10386
  this.#hydrate();
10442
10387
  }
10443
10388
  get data() {
@@ -10457,7 +10402,6 @@ var ArrayView = class {
10457
10402
  }
10458
10403
  }
10459
10404
  destroy() {
10460
- this.#input.destroy();
10461
10405
  this.onDestroy?.();
10462
10406
  }
10463
10407
  #hydrate() {
@@ -10485,207 +10429,6 @@ var ArrayView = class {
10485
10429
  this.#fireListeners();
10486
10430
  }
10487
10431
  };
10488
- function applyChange(parentEntry, change, schema, relationship, format) {
10489
- if (schema.isHidden) {
10490
- switch (change.type) {
10491
- case "add":
10492
- case "remove":
10493
- for (const [relationship2, children] of Object.entries(
10494
- change.node.relationships
10495
- )) {
10496
- const childSchema = must(schema.relationships[relationship2]);
10497
- for (const node of children) {
10498
- applyChange(
10499
- parentEntry,
10500
- { type: change.type, node },
10501
- childSchema,
10502
- relationship2,
10503
- format
10504
- );
10505
- }
10506
- }
10507
- return;
10508
- case "edit":
10509
- return;
10510
- case "child": {
10511
- const childSchema = must(
10512
- schema.relationships[change.child.relationshipName]
10513
- );
10514
- applyChange(
10515
- parentEntry,
10516
- change.child.change,
10517
- childSchema,
10518
- relationship,
10519
- format
10520
- );
10521
- return;
10522
- }
10523
- default:
10524
- unreachable(change);
10525
- }
10526
- }
10527
- const { singular, relationships: childFormats } = format;
10528
- switch (change.type) {
10529
- case "add": {
10530
- const newEntry = {
10531
- ...change.node.row
10532
- };
10533
- if (singular) {
10534
- assertUndefined(
10535
- parentEntry[relationship],
10536
- "single output already exists"
10537
- );
10538
- parentEntry[relationship] = newEntry;
10539
- } else {
10540
- const view = parentEntry[relationship];
10541
- assertArray(view);
10542
- const { pos, found } = binarySearch3(view, newEntry, schema.compareRows);
10543
- assert(!found, "node already exists");
10544
- view.splice(pos, 0, newEntry);
10545
- }
10546
- for (const [relationship2, children] of Object.entries(
10547
- change.node.relationships
10548
- )) {
10549
- const childSchema = must(schema.relationships[relationship2]);
10550
- const childFormat = must(childFormats[relationship2]);
10551
- const newView = childFormat.singular ? void 0 : [];
10552
- newEntry[relationship2] = newView;
10553
- for (const node of children) {
10554
- applyChange(
10555
- newEntry,
10556
- { type: "add", node },
10557
- childSchema,
10558
- relationship2,
10559
- childFormat
10560
- );
10561
- }
10562
- }
10563
- break;
10564
- }
10565
- case "remove": {
10566
- if (singular) {
10567
- assertObject(parentEntry[relationship]);
10568
- parentEntry[relationship] = void 0;
10569
- } else {
10570
- assertArray(parentEntry[relationship]);
10571
- const view = parentEntry[relationship];
10572
- const { pos, found } = binarySearch3(
10573
- view,
10574
- change.node.row,
10575
- schema.compareRows
10576
- );
10577
- assert(found, "node does not exist");
10578
- view.splice(pos, 1);
10579
- }
10580
- break;
10581
- }
10582
- case "child": {
10583
- let existing;
10584
- if (singular) {
10585
- assertObject(parentEntry[relationship]);
10586
- existing = parentEntry[relationship];
10587
- } else {
10588
- assertArray(parentEntry[relationship]);
10589
- const list = parentEntry[relationship];
10590
- const { pos, found } = binarySearch3(list, change.row, schema.compareRows);
10591
- assert(found, "node does not exist");
10592
- existing = list[pos];
10593
- }
10594
- const childSchema = must(
10595
- schema.relationships[change.child.relationshipName]
10596
- );
10597
- const childFormat = must(
10598
- format.relationships[change.child.relationshipName]
10599
- );
10600
- applyChange(
10601
- existing,
10602
- change.child.change,
10603
- childSchema,
10604
- change.child.relationshipName,
10605
- childFormat
10606
- );
10607
- break;
10608
- }
10609
- case "edit": {
10610
- if (singular) {
10611
- assertObject(parentEntry[relationship]);
10612
- parentEntry[relationship] = {
10613
- ...parentEntry[relationship],
10614
- ...change.row
10615
- };
10616
- } else {
10617
- assertArray(parentEntry[relationship]);
10618
- const view = parentEntry[relationship];
10619
- if (schema.compareRows(change.oldRow, change.row) === 0) {
10620
- const { pos, found } = binarySearch3(
10621
- view,
10622
- change.oldRow,
10623
- schema.compareRows
10624
- );
10625
- assert(found, "node does not exists");
10626
- view[pos] = makeEntryPreserveRelationships(
10627
- change.row,
10628
- view[pos],
10629
- schema.relationships
10630
- );
10631
- } else {
10632
- const { pos, found } = binarySearch3(
10633
- view,
10634
- change.oldRow,
10635
- schema.compareRows
10636
- );
10637
- assert(found, "node does not exists");
10638
- const oldEntry = view[pos];
10639
- view.splice(pos, 1);
10640
- {
10641
- const { pos: pos2, found: found2 } = binarySearch3(
10642
- view,
10643
- change.row,
10644
- schema.compareRows
10645
- );
10646
- assert(!found2, "node already exists");
10647
- view.splice(
10648
- pos2,
10649
- 0,
10650
- makeEntryPreserveRelationships(
10651
- change.row,
10652
- oldEntry,
10653
- schema.relationships
10654
- )
10655
- );
10656
- }
10657
- }
10658
- }
10659
- break;
10660
- }
10661
- default:
10662
- unreachable(change);
10663
- }
10664
- }
10665
- function binarySearch3(view, target, comparator) {
10666
- let low = 0;
10667
- let high = view.length - 1;
10668
- while (low <= high) {
10669
- const mid = low + high >>> 1;
10670
- const comparison = comparator(view[mid], target);
10671
- if (comparison < 0) {
10672
- low = mid + 1;
10673
- } else if (comparison > 0) {
10674
- high = mid - 1;
10675
- } else {
10676
- return { pos: mid, found: true };
10677
- }
10678
- }
10679
- return { pos: low, found: false };
10680
- }
10681
- function makeEntryPreserveRelationships(row, entry, relationships) {
10682
- const result = { ...row };
10683
- for (const relationship in relationships) {
10684
- assert(!(relationship in row), "Relationship already exists");
10685
- result[relationship] = entry[relationship];
10686
- }
10687
- return result;
10688
- }
10689
10432
 
10690
10433
  // ../shared/src/sorted-entries.ts
10691
10434
  function sortedEntries(object16) {
@@ -10693,6 +10436,9 @@ function sortedEntries(object16) {
10693
10436
  }
10694
10437
 
10695
10438
  // ../zql/src/zql/query/schema.ts
10439
+ function createTableSchema(schema) {
10440
+ return schema;
10441
+ }
10696
10442
  function isFieldRelationship(relationship) {
10697
10443
  return relationship.junction === void 0;
10698
10444
  }
@@ -11080,20 +10826,27 @@ var QueryImpl = class extends AbstractQuery {
11080
10826
  _newQuery(schema, ast, format) {
11081
10827
  return newQueryWithDetails(this.#delegate, schema, ast, format);
11082
10828
  }
11083
- materialize() {
10829
+ materialize(factory) {
11084
10830
  const ast = this._completeAst();
11085
10831
  const removeServerQuery = this.#delegate.addServerQuery(ast);
11086
- const view = new ArrayView(
11087
- buildPipeline(ast, this.#delegate, void 0),
11088
- this.#format
11089
- );
11090
- const removeCommitObserver = this.#delegate.onTransactionCommit(() => {
11091
- view.flush();
11092
- });
11093
- view.onDestroy = () => {
11094
- removeCommitObserver();
10832
+ const input = buildPipeline(ast, this.#delegate, void 0);
10833
+ const schema = input.getSchema();
10834
+ assertOrderingIncludesPK(schema.sort, schema.primaryKey);
10835
+ let removeCommitObserver;
10836
+ const onDestroy = () => {
10837
+ input.destroy();
10838
+ removeCommitObserver?.();
11095
10839
  removeServerQuery();
11096
10840
  };
10841
+ const view = (factory ?? arrayViewFactory)(
10842
+ this,
10843
+ input,
10844
+ this.#format,
10845
+ onDestroy,
10846
+ (cb) => {
10847
+ removeCommitObserver = this.#delegate.onTransactionCommit(cb);
10848
+ }
10849
+ );
11097
10850
  return view;
11098
10851
  }
11099
10852
  preload() {
@@ -11131,6 +10884,14 @@ function addPrimaryKeysToAst(schema, ast) {
11131
10884
  orderBy: addPrimaryKeys(schema, ast.orderBy)
11132
10885
  };
11133
10886
  }
10887
+ function arrayViewFactory(_query, input, format, onDestroy, onTransactionCommit) {
10888
+ const v2 = new ArrayView(input, format);
10889
+ v2.onDestroy = onDestroy;
10890
+ onTransactionCommit(() => {
10891
+ v2.flush();
10892
+ });
10893
+ return v2;
10894
+ }
11134
10895
 
11135
10896
  // ../zql/src/zql/query/escape-like.ts
11136
10897
  function escapeLike(val) {
@@ -14285,7 +14046,7 @@ function makeMessage(message, context, logLevel) {
14285
14046
  }
14286
14047
 
14287
14048
  // ../zero-client/src/client/version.ts
14288
- var version2 = "0.0.0";
14049
+ var version2 = "0.3.2024102600+0464d7";
14289
14050
 
14290
14051
  // ../zero-client/src/client/log-options.ts
14291
14052
  var LevelFilterLogSink = class {
@@ -15092,6 +14853,9 @@ function rowsPatchOpToReplicachePatchOp(op, schema) {
15092
14853
  }
15093
14854
 
15094
14855
  // ../zero-client/src/client/zero.ts
14856
+ function createSchema(schema) {
14857
+ return schema;
14858
+ }
15095
14859
  var onSetConnectionStateSymbol = Symbol();
15096
14860
  var exposedToTestingSymbol = Symbol();
15097
14861
  var createLogOptionsSymbol = Symbol();
@@ -16246,6 +16010,8 @@ export {
16246
16010
  QueryImpl,
16247
16011
  TransactionClosedError,
16248
16012
  Zero,
16013
+ createSchema,
16014
+ createTableSchema,
16249
16015
  dropAllDatabases,
16250
16016
  dropDatabase,
16251
16017
  escapeLike,