@rocicorp/zero 0.6.2024111701 → 0.6.2024111900

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 (58) hide show
  1. package/out/{chunk-NBTG5EEV.js → chunk-7E5TITAZ.js} +135 -48
  2. package/out/chunk-7E5TITAZ.js.map +7 -0
  3. package/out/shared/src/valita.d.ts.map +1 -1
  4. package/out/shared/src/valita.js +53 -4
  5. package/out/shared/src/valita.js.map +1 -1
  6. package/out/solid.js +1 -1
  7. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  8. package/out/zero-cache/src/config/zero-config.js +12 -4
  9. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  10. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js +1 -1
  11. package/out/zero-cache/src/services/mutagen/write-authorizer.d.ts.map +1 -1
  12. package/out/zero-cache/src/services/mutagen/write-authorizer.js +15 -35
  13. package/out/zero-cache/src/services/mutagen/write-authorizer.js.map +1 -1
  14. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  15. package/out/zero-cache/src/services/view-syncer/cvr.js +8 -2
  16. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  17. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +80 -15
  18. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts.map +1 -1
  19. package/out/zero-protocol/src/ast.d.ts +75 -18
  20. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  21. package/out/zero-protocol/src/ast.js +36 -13
  22. package/out/zero-protocol/src/ast.js.map +1 -1
  23. package/out/zero-protocol/src/change-desired-queries.d.ts +32 -6
  24. package/out/zero-protocol/src/change-desired-queries.d.ts.map +1 -1
  25. package/out/zero-protocol/src/connect.d.ts +32 -6
  26. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  27. package/out/zero-protocol/src/down.d.ts +32 -6
  28. package/out/zero-protocol/src/down.d.ts.map +1 -1
  29. package/out/zero-protocol/src/poke.d.ts +64 -12
  30. package/out/zero-protocol/src/poke.d.ts.map +1 -1
  31. package/out/zero-protocol/src/queries-patch.d.ts +48 -9
  32. package/out/zero-protocol/src/queries-patch.d.ts.map +1 -1
  33. package/out/zero-protocol/src/up.d.ts +32 -6
  34. package/out/zero-protocol/src/up.d.ts.map +1 -1
  35. package/out/zero-schema/src/compiled-authorization.d.ts +224 -42
  36. package/out/zero-schema/src/compiled-authorization.d.ts.map +1 -1
  37. package/out/zero.js +1 -1
  38. package/out/zql/src/builder/builder.d.ts.map +1 -1
  39. package/out/zql/src/builder/builder.js +10 -12
  40. package/out/zql/src/builder/builder.js.map +1 -1
  41. package/out/zql/src/builder/filter.d.ts.map +1 -1
  42. package/out/zql/src/builder/filter.js +20 -5
  43. package/out/zql/src/builder/filter.js.map +1 -1
  44. package/out/zql/src/ivm/memory-source.js +4 -4
  45. package/out/zql/src/ivm/memory-source.js.map +1 -1
  46. package/out/zql/src/query/expression.d.ts +3 -2
  47. package/out/zql/src/query/expression.d.ts.map +1 -1
  48. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  49. package/out/zqlite/src/table-source.d.ts +1 -1
  50. package/out/zqlite/src/table-source.d.ts.map +1 -1
  51. package/out/zqlite/src/table-source.js +38 -10
  52. package/out/zqlite/src/table-source.js.map +1 -1
  53. package/package.json +1 -1
  54. package/out/chunk-NBTG5EEV.js.map +0 -7
  55. package/out/zql/src/builder/error.d.ts +0 -3
  56. package/out/zql/src/builder/error.d.ts.map +0 -1
  57. package/out/zql/src/builder/error.js +0 -3
  58. package/out/zql/src/builder/error.js.map +0 -1
@@ -1535,7 +1535,7 @@ function displayList(word, expected, toDisplay2 = (x) => String(x)) {
1535
1535
  }
1536
1536
  return `${expected.slice(0, -2).map(toDisplay2).join(", ")}, ${suffix}`;
1537
1537
  }
1538
- function getMessage(err2, v2) {
1538
+ function getMessage(err2, v2, schema, mode) {
1539
1539
  const firstIssue = err2.issues[0];
1540
1540
  const { path: path2 } = firstIssue;
1541
1541
  const atPath = path2?.length ? ` at ${path2.join(".")}` : "";
@@ -1570,7 +1570,7 @@ function getMessage(err2, v2) {
1570
1570
  firstIssue.keys
1571
1571
  )}${atPath}`;
1572
1572
  case "invalid_union":
1573
- return `Invalid union value${atPath}`;
1573
+ return schema.name === "union" ? getDeepestUnionParseError(v2, schema, mode ?? "strict") : `Invalid union value${atPath}`;
1574
1574
  case "custom_error": {
1575
1575
  const { error } = firstIssue;
1576
1576
  const message = !error ? "unknown" : typeof error === "string" ? error : error.message ?? "unknown";
@@ -1578,6 +1578,43 @@ function getMessage(err2, v2) {
1578
1578
  }
1579
1579
  }
1580
1580
  }
1581
+ function getDeepestUnionParseError(value, schema, mode) {
1582
+ const failures = [];
1583
+ for (const type of schema.options) {
1584
+ const r = type.try(value, { mode });
1585
+ if (!r.ok) {
1586
+ failures.push({ type, err: r });
1587
+ }
1588
+ }
1589
+ if (failures.length) {
1590
+ failures.sort(pathCmp);
1591
+ if (failures.length === 1 || pathCmp(failures[0], failures[1]) < 0) {
1592
+ return getMessage(failures[0].err, value, failures[0].type, mode);
1593
+ }
1594
+ }
1595
+ try {
1596
+ const str = JSON.stringify(value);
1597
+ return `Invalid union value: ${str}`;
1598
+ } catch (e) {
1599
+ return `Invalid union value`;
1600
+ }
1601
+ }
1602
+ function pathCmp(a, b) {
1603
+ const aPath = a.err.issues[0].path;
1604
+ const bPath = b.err.issues[0].path;
1605
+ if (aPath.length !== bPath.length) {
1606
+ return bPath.length - aPath.length;
1607
+ }
1608
+ for (let i = 0; i < aPath.length; i++) {
1609
+ if (bPath[i] > aPath[i]) {
1610
+ return -1;
1611
+ }
1612
+ if (bPath[i] < aPath[i]) {
1613
+ return 1;
1614
+ }
1615
+ }
1616
+ return 0;
1617
+ }
1581
1618
  function parse(value, schema, mode) {
1582
1619
  const res = test(value, schema, mode);
1583
1620
  if (!res.ok) {
@@ -1594,7 +1631,10 @@ function assert2(value, schema, mode) {
1594
1631
  function test(value, schema, mode) {
1595
1632
  const res = schema.try(value, mode ? { mode } : void 0);
1596
1633
  if (!res.ok) {
1597
- return { ok: false, error: getMessage(res, value) };
1634
+ return {
1635
+ ok: false,
1636
+ error: getMessage(res, value, schema, mode)
1637
+ };
1598
1638
  }
1599
1639
  return res;
1600
1640
  }
@@ -1612,7 +1652,7 @@ function testOptional(value, schema, mode) {
1612
1652
  return res;
1613
1653
  }
1614
1654
  const err2 = new v.ValitaError(res);
1615
- return { ok: false, error: getMessage(err2, value) };
1655
+ return { ok: false, error: getMessage(err2, value, schema, mode) };
1616
1656
  }
1617
1657
  function readonly(t2) {
1618
1658
  return t2;
@@ -9488,23 +9528,36 @@ var simpleOperatorSchema = valita_exports.union(
9488
9528
  likeOpsSchema,
9489
9529
  inOpsSchema
9490
9530
  );
9491
- var simpleConditionSchema = valita_exports.object({
9492
- type: valita_exports.literal("simple"),
9493
- op: simpleOperatorSchema,
9494
- field: selectorSchema,
9531
+ var literalReferenceSchema = valita_exports.object({
9532
+ type: valita_exports.literal("literal"),
9495
9533
  value: valita_exports.union(
9496
9534
  valita_exports.string(),
9497
9535
  valita_exports.number(),
9498
9536
  valita_exports.boolean(),
9499
9537
  valita_exports.null(),
9500
- readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean())),
9501
- valita_exports.object({
9502
- type: valita_exports.literal("static"),
9503
- anchor: valita_exports.union(valita_exports.literal("authData"), valita_exports.literal("preMutationRow")),
9504
- field: valita_exports.string()
9505
- })
9538
+ readonlyArray(valita_exports.union(valita_exports.string(), valita_exports.number(), valita_exports.boolean()))
9506
9539
  )
9507
9540
  });
9541
+ var columnReferenceSchema = valita_exports.object({
9542
+ type: valita_exports.literal("column"),
9543
+ name: valita_exports.string()
9544
+ });
9545
+ var parameterReferenceSchema = valita_exports.object({
9546
+ type: valita_exports.literal("static"),
9547
+ anchor: valita_exports.union(valita_exports.literal("authData"), valita_exports.literal("preMutationRow")),
9548
+ field: valita_exports.string()
9549
+ });
9550
+ var conditionValueSchema = valita_exports.union(
9551
+ literalReferenceSchema,
9552
+ columnReferenceSchema,
9553
+ parameterReferenceSchema
9554
+ );
9555
+ var simpleConditionSchema = valita_exports.object({
9556
+ type: valita_exports.literal("simple"),
9557
+ op: simpleOperatorSchema,
9558
+ left: conditionValueSchema,
9559
+ right: valita_exports.union(parameterReferenceSchema, literalReferenceSchema)
9560
+ });
9508
9561
  var correlatedSubqueryConditionOperatorSchema = valita_exports.union(
9509
9562
  valita_exports.literal("EXISTS"),
9510
9563
  valita_exports.literal("NOT EXISTS")
@@ -9601,10 +9654,7 @@ function cmpCondition(a, b) {
9601
9654
  if (b.type !== "simple") {
9602
9655
  return -1;
9603
9656
  }
9604
- return compareUTF8MaybeNull(a.field, b.field) || compareUTF8MaybeNull(a.op, b.op) || // Comparing the same field with the same op more than once doesn't make logical
9605
- // sense, but is technically possible. Assume the values are of the same type and
9606
- // sort by their String forms.
9607
- compareUTF8MaybeNull(String(a.value), String(b.value));
9657
+ return compareValuePosition(a.left, b.left) || compareUTF8MaybeNull(a.op, b.op) || compareValuePosition(a.right, b.right);
9608
9658
  }
9609
9659
  if (b.type === "simple") {
9610
9660
  return 1;
@@ -9630,6 +9680,23 @@ function cmpCondition(a, b) {
9630
9680
  }
9631
9681
  return a.conditions.length - b.conditions.length;
9632
9682
  }
9683
+ function compareValuePosition(a, b) {
9684
+ if (a.type !== b.type) {
9685
+ return compareUTF83(a.type, b.type);
9686
+ }
9687
+ switch (a.type) {
9688
+ case "literal":
9689
+ assert(b.type === "literal");
9690
+ return compareUTF8MaybeNull(String(a.value), String(b.value));
9691
+ case "column":
9692
+ assert(b.type === "column");
9693
+ return compareUTF83(a.name, b.name);
9694
+ case "static":
9695
+ throw new Error(
9696
+ "Static parameters should be resolved before normalization"
9697
+ );
9698
+ }
9699
+ }
9633
9700
  function cmpRelated(a, b) {
9634
9701
  return compareUTF83(must(a.subquery.alias), must(b.subquery.alias));
9635
9702
  }
@@ -10933,10 +11000,6 @@ function getTakeStateKey(partitionValue) {
10933
11000
  return JSON.stringify(["take", normalizeUndefined(partitionValue)]);
10934
11001
  }
10935
11002
 
10936
- // ../zql/src/builder/error.ts
10937
- var MissingParameterError = class extends Error {
10938
- };
10939
-
10940
11003
  // ../zql/src/builder/like.ts
10941
11004
  function getLikePredicate(pattern, flags) {
10942
11005
  const op = getLikeOp(String(pattern), flags);
@@ -10987,19 +11050,40 @@ function patternToRegExp(source, flags = "") {
10987
11050
 
10988
11051
  // ../zql/src/builder/filter.ts
10989
11052
  function createPredicate(condition) {
11053
+ const { left } = condition;
11054
+ const { right } = condition;
11055
+ assert(
11056
+ right.type !== "static",
11057
+ "static values should be resolved before creating predicates"
11058
+ );
11059
+ assert(
11060
+ left.type !== "static",
11061
+ "static values should be resolved before creating predicates"
11062
+ );
10990
11063
  switch (condition.op) {
10991
11064
  case "IS":
10992
11065
  case "IS NOT": {
10993
- const impl2 = createIsPredicate(condition.value, condition.op);
10994
- return (row) => impl2(row[condition.field]);
11066
+ const impl2 = createIsPredicate(right.value, condition.op);
11067
+ if (left.type === "literal") {
11068
+ const result = impl2(left.value);
11069
+ return () => result;
11070
+ }
11071
+ return (row) => impl2(row[left.name]);
10995
11072
  }
10996
11073
  }
10997
- if (condition.value === null || condition.value === void 0) {
11074
+ if (right.value === null || right.value === void 0) {
10998
11075
  return (_row) => false;
10999
11076
  }
11000
- const impl = createPredicateImpl(condition.value, condition.op);
11077
+ const impl = createPredicateImpl(right.value, condition.op);
11078
+ if (left.type === "literal") {
11079
+ if (left.value === null || left.value === void 0) {
11080
+ return (_row) => false;
11081
+ }
11082
+ const result = impl(left.value);
11083
+ return () => result;
11084
+ }
11001
11085
  return (row) => {
11002
- const lhs = row[condition.field];
11086
+ const lhs = row[left.name];
11003
11087
  if (lhs === null || lhs === void 0) {
11004
11088
  return false;
11005
11089
  }
@@ -11081,7 +11165,8 @@ function bindStaticParameters(ast, staticQueryParameters) {
11081
11165
  if (condition.type === "simple") {
11082
11166
  return {
11083
11167
  ...condition,
11084
- value: bindValue(condition.value)
11168
+ left: bindValue(condition.left),
11169
+ right: bindValue(condition.right)
11085
11170
  };
11086
11171
  }
11087
11172
  if (condition.type === "correlatedSubquery") {
@@ -11104,19 +11189,18 @@ function bindStaticParameters(ast, staticQueryParameters) {
11104
11189
  staticQueryParameters,
11105
11190
  "Static query params do not exist"
11106
11191
  )[value.anchor];
11107
- assert(anchor !== void 0, `Missing parameter: ${value.anchor}`);
11108
- const resolvedValue = anchor[value.field];
11109
- if (resolvedValue == null) {
11110
- throw new MissingParameterError();
11111
- }
11112
- return resolvedValue;
11192
+ const resolvedValue = anchor?.[value.field] ?? null;
11193
+ return {
11194
+ type: "literal",
11195
+ value: resolvedValue
11196
+ };
11113
11197
  }
11114
11198
  return value;
11115
11199
  };
11116
11200
  return visit(ast);
11117
11201
  }
11118
11202
  function isParameter(value) {
11119
- return typeof value === "object" && value !== null && "type" in value;
11203
+ return value.type === "static";
11120
11204
  }
11121
11205
  function buildPipelineInternal(ast, delegate, staticQueryParameters, partitionKey) {
11122
11206
  const source = delegate.getSource(ast.table);
@@ -11154,7 +11238,7 @@ function applyWhere(input, condition, appliedFilters, delegate) {
11154
11238
  return applyOr(input, condition, appliedFilters, delegate);
11155
11239
  case "correlatedSubquery":
11156
11240
  return applyCorrelatedSubqueryCondition(input, condition, delegate);
11157
- default:
11241
+ case "simple":
11158
11242
  return applySimpleCondition(input, condition, appliedFilters);
11159
11243
  }
11160
11244
  }
@@ -11229,7 +11313,7 @@ function gatherCorrelatedSubqueryQueriesFromCondition(condition) {
11229
11313
  }
11230
11314
  return csqs;
11231
11315
  }
11232
- var EXISTS_LIMIT = 5;
11316
+ var EXISTS_LIMIT = 3;
11233
11317
  function assertOrderingIncludesPK(ordering, pk) {
11234
11318
  const orderingFields = ordering.map(([field]) => field);
11235
11319
  const missingFields = pk.filter((pkField) => !orderingFields.includes(pkField));
@@ -11425,12 +11509,12 @@ function not2(expression) {
11425
11509
  related: expression.related,
11426
11510
  op: negateOperator(expression.op)
11427
11511
  };
11428
- default:
11512
+ case "simple":
11429
11513
  return {
11430
11514
  type: "simple",
11431
11515
  op: negateOperator(expression.op),
11432
- field: expression.field,
11433
- value: expression.value
11516
+ left: expression.left,
11517
+ right: expression.right
11434
11518
  };
11435
11519
  }
11436
11520
  }
@@ -11444,11 +11528,14 @@ function cmp(field, opOrValue, value) {
11444
11528
  }
11445
11529
  return {
11446
11530
  type: "simple",
11447
- field,
11448
- op,
11449
- value
11531
+ left: { type: "column", name: field },
11532
+ right: isParameter2(value) ? value : { type: "literal", value },
11533
+ op
11450
11534
  };
11451
11535
  }
11536
+ function isParameter2(value) {
11537
+ return typeof value === "object" && value?.type === "static";
11538
+ }
11452
11539
  var TRUE = {
11453
11540
  type: "and",
11454
11541
  conditions: []
@@ -14260,11 +14347,11 @@ var MemorySource = class {
14260
14347
  overlay,
14261
14348
  comparator
14262
14349
  );
14263
- const withFilters = conn.optionalFilters.length ? generateWithFilter(withOverlay, matchesFilters) : withOverlay;
14264
- yield* generateWithConstraint(
14265
- generateWithStart(withFilters, req, comparator),
14350
+ const withConstraint = generateWithConstraint(
14351
+ generateWithStart(withOverlay, req, comparator),
14266
14352
  req.constraint
14267
14353
  );
14354
+ yield* conn.optionalFilters.length ? generateWithFilter(withConstraint, matchesFilters) : withConstraint;
14268
14355
  }
14269
14356
  #cleanup(req, connection) {
14270
14357
  return this.#fetch(req, connection);
@@ -15141,7 +15228,7 @@ function makeMessage(message, context, logLevel) {
15141
15228
  }
15142
15229
 
15143
15230
  // ../zero-client/src/client/version.ts
15144
- var version2 = "0.6.2024111701+c7a3b0";
15231
+ var version2 = "0.6.2024111900+a6527c";
15145
15232
 
15146
15233
  // ../zero-client/src/client/log-options.ts
15147
15234
  var LevelFilterLogSink = class {
@@ -17115,4 +17202,4 @@ export {
17115
17202
  escapeLike,
17116
17203
  Zero
17117
17204
  };
17118
- //# sourceMappingURL=chunk-NBTG5EEV.js.map
17205
+ //# sourceMappingURL=chunk-7E5TITAZ.js.map