@rocicorp/zero 0.6.2024111800 → 0.6.2024112000

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 (83) hide show
  1. package/out/{chunk-N4TOAWSH.js → chunk-W4HNSZIF.js} +149 -54
  2. package/out/chunk-W4HNSZIF.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/db/create.d.ts.map +1 -1
  11. package/out/zero-cache/src/db/create.js +1 -3
  12. package/out/zero-cache/src/db/create.js.map +1 -1
  13. package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
  14. package/out/zero-cache/src/db/pg-to-lite.js +12 -3
  15. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  16. package/out/zero-cache/src/server/main.js +1 -1
  17. package/out/zero-cache/src/server/main.js.map +1 -1
  18. package/out/zero-cache/src/server/syncer.d.ts +1 -1
  19. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  20. package/out/zero-cache/src/server/syncer.js +15 -5
  21. package/out/zero-cache/src/server/syncer.js.map +1 -1
  22. package/out/zero-cache/src/services/change-streamer/pg/schema/shard.js +1 -1
  23. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  24. package/out/zero-cache/src/services/mutagen/mutagen.js +1 -3
  25. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  26. package/out/zero-cache/src/services/mutagen/write-authorizer.d.ts.map +1 -1
  27. package/out/zero-cache/src/services/mutagen/write-authorizer.js +22 -42
  28. package/out/zero-cache/src/services/mutagen/write-authorizer.js.map +1 -1
  29. package/out/zero-cache/src/services/replicator/incremental-sync.d.ts.map +1 -1
  30. package/out/zero-cache/src/services/replicator/incremental-sync.js +2 -3
  31. package/out/zero-cache/src/services/replicator/incremental-sync.js.map +1 -1
  32. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  33. package/out/zero-cache/src/services/view-syncer/cvr.js +8 -2
  34. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  35. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +80 -15
  36. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts.map +1 -1
  37. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  38. package/out/zero-cache/src/services/view-syncer/view-syncer.js +1 -3
  39. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  40. package/out/zero-cache/src/workers/replicator.d.ts +1 -0
  41. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  42. package/out/zero-cache/src/workers/replicator.js +4 -1
  43. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  44. package/out/zero-protocol/src/ast.d.ts +75 -18
  45. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  46. package/out/zero-protocol/src/ast.js +36 -13
  47. package/out/zero-protocol/src/ast.js.map +1 -1
  48. package/out/zero-protocol/src/change-desired-queries.d.ts +32 -6
  49. package/out/zero-protocol/src/change-desired-queries.d.ts.map +1 -1
  50. package/out/zero-protocol/src/connect.d.ts +32 -6
  51. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  52. package/out/zero-protocol/src/down.d.ts +32 -6
  53. package/out/zero-protocol/src/down.d.ts.map +1 -1
  54. package/out/zero-protocol/src/poke.d.ts +64 -12
  55. package/out/zero-protocol/src/poke.d.ts.map +1 -1
  56. package/out/zero-protocol/src/queries-patch.d.ts +48 -9
  57. package/out/zero-protocol/src/queries-patch.d.ts.map +1 -1
  58. package/out/zero-protocol/src/up.d.ts +32 -6
  59. package/out/zero-protocol/src/up.d.ts.map +1 -1
  60. package/out/zero-schema/src/authorization.d.ts +6 -6
  61. package/out/zero-schema/src/authorization.d.ts.map +1 -1
  62. package/out/zero-schema/src/compiled-authorization.d.ts +224 -42
  63. package/out/zero-schema/src/compiled-authorization.d.ts.map +1 -1
  64. package/out/zero.js +1 -1
  65. package/out/zql/src/builder/builder.d.ts.map +1 -1
  66. package/out/zql/src/builder/builder.js +10 -12
  67. package/out/zql/src/builder/builder.js.map +1 -1
  68. package/out/zql/src/builder/filter.d.ts.map +1 -1
  69. package/out/zql/src/builder/filter.js +20 -5
  70. package/out/zql/src/builder/filter.js.map +1 -1
  71. package/out/zql/src/query/expression.d.ts +4 -2
  72. package/out/zql/src/query/expression.d.ts.map +1 -1
  73. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  74. package/out/zqlite/src/table-source.d.ts +1 -1
  75. package/out/zqlite/src/table-source.d.ts.map +1 -1
  76. package/out/zqlite/src/table-source.js +38 -10
  77. package/out/zqlite/src/table-source.js.map +1 -1
  78. package/package.json +1 -1
  79. package/out/chunk-N4TOAWSH.js.map +0 -7
  80. package/out/zql/src/builder/error.d.ts +0 -3
  81. package/out/zql/src/builder/error.d.ts.map +0 -1
  82. package/out/zql/src/builder/error.js +0 -3
  83. 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));
@@ -11380,6 +11464,14 @@ var ExpressionBuilder = class {
11380
11464
  cmp(field, opOrValue, value) {
11381
11465
  return cmp(field, opOrValue, value);
11382
11466
  }
11467
+ cmpLit(left, op, right) {
11468
+ return {
11469
+ type: "simple",
11470
+ left: isParameter2(left) ? left : { type: "literal", value: left },
11471
+ right: isParameter2(right) ? right : { type: "literal", value: right },
11472
+ op
11473
+ };
11474
+ }
11383
11475
  and = and;
11384
11476
  or = or;
11385
11477
  not = not2;
@@ -11425,12 +11517,12 @@ function not2(expression) {
11425
11517
  related: expression.related,
11426
11518
  op: negateOperator(expression.op)
11427
11519
  };
11428
- default:
11520
+ case "simple":
11429
11521
  return {
11430
11522
  type: "simple",
11431
11523
  op: negateOperator(expression.op),
11432
- field: expression.field,
11433
- value: expression.value
11524
+ left: expression.left,
11525
+ right: expression.right
11434
11526
  };
11435
11527
  }
11436
11528
  }
@@ -11444,11 +11536,14 @@ function cmp(field, opOrValue, value) {
11444
11536
  }
11445
11537
  return {
11446
11538
  type: "simple",
11447
- field,
11448
- op,
11449
- value
11539
+ left: { type: "column", name: field },
11540
+ right: isParameter2(value) ? value : { type: "literal", value },
11541
+ op
11450
11542
  };
11451
11543
  }
11544
+ function isParameter2(value) {
11545
+ return typeof value === "object" && value?.type === "static";
11546
+ }
11452
11547
  var TRUE = {
11453
11548
  type: "and",
11454
11549
  conditions: []
@@ -12010,13 +12105,13 @@ function compileRowConfig(rowRules) {
12010
12105
  return void 0;
12011
12106
  }
12012
12107
  return {
12013
- select: compileInstanceRules(rowRules.select),
12014
- insert: compileInstanceRules(rowRules.insert),
12015
- update: compileInstanceRules(rowRules.update),
12016
- delete: compileInstanceRules(rowRules.delete)
12108
+ select: compileRules(rowRules.select),
12109
+ insert: compileRules(rowRules.insert),
12110
+ update: compileRules(rowRules.update),
12111
+ delete: compileRules(rowRules.delete)
12017
12112
  };
12018
12113
  }
12019
- function compileInstanceRules(rules) {
12114
+ function compileRules(rules) {
12020
12115
  if (!rules) {
12021
12116
  return void 0;
12022
12117
  }
@@ -12037,10 +12132,10 @@ function compileCellConfig(cellRules) {
12037
12132
  const ret = {};
12038
12133
  for (const [columnName, rules] of Object.entries(cellRules)) {
12039
12134
  ret[columnName] = {
12040
- select: compileInstanceRules(rules.select),
12041
- insert: compileInstanceRules(rules.insert),
12042
- update: compileInstanceRules(rules.update),
12043
- delete: compileInstanceRules(rules.delete)
12135
+ select: compileRules(rules.select),
12136
+ insert: compileRules(rules.insert),
12137
+ update: compileRules(rules.update),
12138
+ delete: compileRules(rules.delete)
12044
12139
  };
12045
12140
  }
12046
12141
  return ret;
@@ -15141,7 +15236,7 @@ function makeMessage(message, context, logLevel) {
15141
15236
  }
15142
15237
 
15143
15238
  // ../zero-client/src/client/version.ts
15144
- var version2 = "0.6.2024111800+725d79";
15239
+ var version2 = "0.6.2024112000+47c38e";
15145
15240
 
15146
15241
  // ../zero-client/src/client/log-options.ts
15147
15242
  var LevelFilterLogSink = class {
@@ -17115,4 +17210,4 @@ export {
17115
17210
  escapeLike,
17116
17211
  Zero
17117
17212
  };
17118
- //# sourceMappingURL=chunk-N4TOAWSH.js.map
17213
+ //# sourceMappingURL=chunk-W4HNSZIF.js.map