@rocicorp/zero 0.7.2024112700 → 0.7.2024120101

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 (92) hide show
  1. package/out/{chunk-HDEKBM3G.js → chunk-5S7LFUZ4.js} +77 -104
  2. package/out/{chunk-HDEKBM3G.js.map → chunk-5S7LFUZ4.js.map} +3 -3
  3. package/out/solid.js +1 -1
  4. package/out/zero-cache/src/auth/load-schema.d.ts +2 -2
  5. package/out/zero-cache/src/auth/load-schema.d.ts.map +1 -1
  6. package/out/zero-cache/src/auth/load-schema.js +5 -4
  7. package/out/zero-cache/src/auth/load-schema.js.map +1 -1
  8. package/out/zero-cache/src/auth/read-authorizer.d.ts +25 -0
  9. package/out/zero-cache/src/auth/read-authorizer.d.ts.map +1 -0
  10. package/out/zero-cache/src/auth/read-authorizer.js +126 -0
  11. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -0
  12. package/out/zero-cache/src/auth/write-authorizer.d.ts +2 -2
  13. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  14. package/out/zero-cache/src/auth/write-authorizer.js +4 -4
  15. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  16. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  17. package/out/zero-cache/src/server/syncer.js +3 -3
  18. package/out/zero-cache/src/server/syncer.js.map +1 -1
  19. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +2 -2
  20. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  21. package/out/zero-cache/src/services/mutagen/mutagen.js +2 -2
  22. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  23. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +9 -1
  24. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  25. package/out/zero-cache/src/services/view-syncer/cvr.js +6 -1
  26. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  27. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +9 -1
  28. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  29. package/out/zero-cache/src/services/view-syncer/view-syncer.js +99 -32
  30. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  31. package/out/zero-cache/src/workers/connection.d.ts +2 -3
  32. package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
  33. package/out/zero-cache/src/workers/connection.js +4 -3
  34. package/out/zero-cache/src/workers/connection.js.map +1 -1
  35. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  36. package/out/zero-cache/src/workers/syncer.js +6 -1
  37. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  38. package/out/zero-client/src/mod.d.ts +1 -1
  39. package/out/zero-client/src/mod.d.ts.map +1 -1
  40. package/out/zero-protocol/src/ast.d.ts +9 -9
  41. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  42. package/out/zero-protocol/src/ast.js +11 -12
  43. package/out/zero-protocol/src/ast.js.map +1 -1
  44. package/out/zero-schema/src/build-schema.d.ts.map +1 -1
  45. package/out/zero-schema/src/build-schema.js +10 -10
  46. package/out/zero-schema/src/build-schema.js.map +1 -1
  47. package/out/zero-schema/src/{compiled-authorization.d.ts → compiled-permissions.d.ts} +4 -4
  48. package/out/zero-schema/src/compiled-permissions.d.ts.map +1 -0
  49. package/out/zero-schema/src/{compiled-authorization.js → compiled-permissions.js} +2 -2
  50. package/out/zero-schema/src/compiled-permissions.js.map +1 -0
  51. package/out/zero-schema/src/mod.d.ts +1 -1
  52. package/out/zero-schema/src/mod.d.ts.map +1 -1
  53. package/out/zero-schema/src/normalize-table-schema.d.ts +19 -8
  54. package/out/zero-schema/src/normalize-table-schema.d.ts.map +1 -1
  55. package/out/zero-schema/src/normalize-table-schema.js +9 -25
  56. package/out/zero-schema/src/normalize-table-schema.js.map +1 -1
  57. package/out/zero-schema/src/normalized-schema.d.ts +6 -1
  58. package/out/zero-schema/src/normalized-schema.d.ts.map +1 -1
  59. package/out/zero-schema/src/normalized-schema.js.map +1 -1
  60. package/out/zero-schema/src/permissions.d.ts +32 -0
  61. package/out/zero-schema/src/permissions.d.ts.map +1 -0
  62. package/out/zero-schema/src/schema-config.d.ts +19 -301
  63. package/out/zero-schema/src/schema-config.d.ts.map +1 -1
  64. package/out/zero-schema/src/schema-config.js +57 -19
  65. package/out/zero-schema/src/schema-config.js.map +1 -1
  66. package/out/zero-schema/src/table-schema.d.ts +12 -8
  67. package/out/zero-schema/src/table-schema.d.ts.map +1 -1
  68. package/out/zero-schema/src/table-schema.js +15 -2
  69. package/out/zero-schema/src/table-schema.js.map +1 -1
  70. package/out/zero.js +3 -3
  71. package/out/zql/src/builder/builder.d.ts.map +1 -1
  72. package/out/zql/src/builder/builder.js +3 -4
  73. package/out/zql/src/builder/builder.js.map +1 -1
  74. package/out/zql/src/ivm/join.d.ts +1 -1
  75. package/out/zql/src/ivm/join.d.ts.map +1 -1
  76. package/out/zql/src/ivm/join.js.map +1 -1
  77. package/out/zql/src/ivm/memory-source.js +3 -3
  78. package/out/zql/src/ivm/memory-source.js.map +1 -1
  79. package/out/zql/src/query/auth-query.d.ts +0 -4
  80. package/out/zql/src/query/auth-query.d.ts.map +1 -1
  81. package/out/zql/src/query/auth-query.js +0 -4
  82. package/out/zql/src/query/auth-query.js.map +1 -1
  83. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  84. package/out/zql/src/query/query-impl.js +26 -32
  85. package/out/zql/src/query/query-impl.js.map +1 -1
  86. package/out/zqlite/src/table-source.js +6 -3
  87. package/out/zqlite/src/table-source.js.map +1 -1
  88. package/package.json +1 -1
  89. package/out/zero-schema/src/authorization.d.ts +0 -32
  90. package/out/zero-schema/src/authorization.d.ts.map +0 -1
  91. package/out/zero-schema/src/compiled-authorization.d.ts.map +0 -1
  92. package/out/zero-schema/src/compiled-authorization.js.map +0 -1
@@ -3106,13 +3106,13 @@ var DataNodeImpl = class extends NodeImpl {
3106
3106
  }
3107
3107
  }
3108
3108
  };
3109
- function readonlySplice(array9, start, deleteCount, ...items) {
3110
- const arr = array9.slice(0, start);
3109
+ function readonlySplice(array10, start, deleteCount, ...items) {
3110
+ const arr = array10.slice(0, start);
3111
3111
  for (let i = 0; i < items.length; i++) {
3112
3112
  arr.push(items[i]);
3113
3113
  }
3114
- for (let i = start + deleteCount; i < array9.length; i++) {
3115
- arr.push(array9[i]);
3114
+ for (let i = start + deleteCount; i < array10.length; i++) {
3115
+ arr.push(array10[i]);
3116
3116
  }
3117
3117
  return arr;
3118
3118
  }
@@ -8091,14 +8091,14 @@ function diffBinarySearch(diff2, prefix, compareKey) {
8091
8091
  }
8092
8092
 
8093
8093
  // ../shared/src/random-values.ts
8094
- function getNonCryptoRandomValues(array9) {
8095
- if (array9 === null) {
8094
+ function getNonCryptoRandomValues(array10) {
8095
+ if (array10 === null) {
8096
8096
  throw new TypeError("array cannot be null");
8097
8097
  }
8098
- for (let i = 0; i < array9.length; i++) {
8099
- array9[i] = Math.floor(Math.random() * 256);
8098
+ for (let i = 0; i < array10.length; i++) {
8099
+ array10[i] = Math.floor(Math.random() * 256);
8100
8100
  }
8101
- return array9;
8101
+ return array10;
8102
8102
  }
8103
8103
 
8104
8104
  // ../replicache/src/sync/request-id.ts
@@ -9284,10 +9284,10 @@ function createTableSchema(schema) {
9284
9284
  return schema;
9285
9285
  }
9286
9286
  function isFieldRelationship(relationship) {
9287
- return relationship.junction === void 0;
9287
+ return !isJunctionRelationship(relationship);
9288
9288
  }
9289
9289
  function isJunctionRelationship(relationship) {
9290
- return !isFieldRelationship(relationship);
9290
+ return Array.isArray(relationship);
9291
9291
  }
9292
9292
 
9293
9293
  // ../shared/src/sorted-entries.ts
@@ -9338,24 +9338,13 @@ function normalizeTableSchemaWithCache(tableSchema, expectedName, tableSchemaCac
9338
9338
  );
9339
9339
  return normalizedTableSchema;
9340
9340
  }
9341
- function isSorted(arr) {
9342
- for (let i = 1; i < arr.length; i++) {
9343
- if (arr[i - 1] >= arr[i]) {
9344
- return false;
9345
- }
9346
- }
9347
- return true;
9348
- }
9349
9341
  function assertNoDuplicates(arr) {
9350
- for (let i = 1; i < arr.length; i++) {
9351
- assert(arr[i - 1] !== arr[i], "Primary key must not contain duplicates");
9352
- }
9342
+ assert(
9343
+ new Set(arr).size === arr.length,
9344
+ "Primary key must not contain duplicates"
9345
+ );
9353
9346
  }
9354
9347
  function normalizePrimaryKey(arr) {
9355
- if (isSorted(arr)) {
9356
- return arr;
9357
- }
9358
- arr = [...arr].sort();
9359
9348
  assertNoDuplicates(arr);
9360
9349
  return arr;
9361
9350
  }
@@ -9396,26 +9385,25 @@ function normalizeRelationship(relationship, tableSchemaCache) {
9396
9385
  return normalizeJunctionRelationship(relationship, tableSchemaCache);
9397
9386
  }
9398
9387
  function normalizeFieldRelationship(relationship, tableSchemaCache) {
9388
+ assert(
9389
+ relationship.sourceField.length === relationship.destField.length,
9390
+ "Source and destination fields must have the same length"
9391
+ );
9399
9392
  return {
9400
- source: relationship.source,
9401
- dest: {
9402
- field: relationship.dest.field,
9403
- schema: normalizeLazyTableSchema(
9404
- relationship.dest.schema,
9405
- tableSchemaCache
9406
- )
9407
- }
9408
- };
9409
- }
9410
- function normalizeJunctionRelationship(relationship, tableSchemaCache) {
9411
- return {
9412
- ...normalizeFieldRelationship(relationship, tableSchemaCache),
9413
- junction: normalizeFieldRelationship(
9414
- relationship.junction,
9393
+ sourceField: relationship.sourceField,
9394
+ destField: relationship.destField,
9395
+ destSchema: normalizeLazyTableSchema(
9396
+ relationship.destSchema,
9415
9397
  tableSchemaCache
9416
9398
  )
9417
9399
  };
9418
9400
  }
9401
+ function normalizeJunctionRelationship(relationship, tableSchemaCache) {
9402
+ return [
9403
+ normalizeFieldRelationship(relationship[0], tableSchemaCache),
9404
+ normalizeFieldRelationship(relationship[1], tableSchemaCache)
9405
+ ];
9406
+ }
9419
9407
  function normalizeLazyTableSchema(tableSchema, buildCache) {
9420
9408
  const tableSchemaInstance = typeof tableSchema === "function" ? tableSchema() : tableSchema;
9421
9409
  return normalizeTableSchemaWithCache(
@@ -9592,8 +9580,8 @@ var negateOperatorMap = {
9592
9580
  function negateOperator(op) {
9593
9581
  return must(negateOperatorMap[op]);
9594
9582
  }
9595
- function filterUndefined(array9) {
9596
- return array9.filter((e) => e !== void 0);
9583
+ function filterUndefined(array10) {
9584
+ return array10.filter((e) => e !== void 0);
9597
9585
  }
9598
9586
  function filterTrue(conditions) {
9599
9587
  return conditions.filter((c) => !isAlwaysTrue(c));
@@ -9722,12 +9710,13 @@ var disjunctionSchema = readonlyObject({
9722
9710
  type: valita_exports.literal("or"),
9723
9711
  conditions: readonlyArray(conditionSchema)
9724
9712
  });
9713
+ var compoundKeySchema = valita_exports.tuple([valita_exports.string()]).concat(valita_exports.array(valita_exports.string()));
9714
+ var correlationSchema = readonlyObject({
9715
+ parentField: compoundKeySchema,
9716
+ childField: compoundKeySchema
9717
+ });
9725
9718
  var correlatedSubquerySchemaOmitSubquery = readonlyObject({
9726
- correlation: valita_exports.object({
9727
- parentField: valita_exports.string(),
9728
- childField: valita_exports.string(),
9729
- op: valita_exports.literal("=")
9730
- }),
9719
+ correlation: correlationSchema,
9731
9720
  hidden: valita_exports.boolean().optional()
9732
9721
  });
9733
9722
  var correlatedSubquerySchema = correlatedSubquerySchemaOmitSubquery.extend({
@@ -9761,11 +9750,7 @@ function normalizeAST(ast) {
9761
9750
  related: ast.related ? sortedRelated(
9762
9751
  ast.related.map(
9763
9752
  (r) => ({
9764
- correlation: {
9765
- parentField: r.correlation.parentField,
9766
- childField: r.correlation.childField,
9767
- op: r.correlation.op
9768
- },
9753
+ correlation: r.correlation,
9769
9754
  hidden: r.hidden,
9770
9755
  subquery: normalizeAST(r.subquery)
9771
9756
  })
@@ -11340,12 +11325,7 @@ function buildPipelineInternal(ast, delegate, partitionKey) {
11340
11325
  end = applyWhere(end, ast.where, appliedFilters, delegate);
11341
11326
  }
11342
11327
  if (ast.limit) {
11343
- end = new Take(
11344
- end,
11345
- delegate.createStorage(),
11346
- ast.limit,
11347
- partitionKey === void 0 ? void 0 : [partitionKey]
11348
- );
11328
+ end = new Take(end, delegate.createStorage(), ast.limit, partitionKey);
11349
11329
  }
11350
11330
  if (ast.related) {
11351
11331
  for (const csq of ast.related) {
@@ -11397,9 +11377,8 @@ function applyCorrelatedSubQuery(sq, delegate, end) {
11397
11377
  parent: end,
11398
11378
  child,
11399
11379
  storage: delegate.createStorage(),
11400
- // TODO: Compound keys in the AST
11401
- parentKey: [sq.correlation.parentField],
11402
- childKey: [sq.correlation.childField],
11380
+ parentKey: sq.correlation.parentField,
11381
+ childKey: sq.correlation.childField,
11403
11382
  relationshipName: sq.subquery.alias,
11404
11383
  hidden: sq.hidden ?? false
11405
11384
  });
@@ -11688,10 +11667,8 @@ var AbstractQuery = class {
11688
11667
  }
11689
11668
  const related = this.#schema.relationships[relationship];
11690
11669
  assert(related, "Invalid relationship");
11691
- const fieldRelationship = related;
11692
- const junctionRelationship = related;
11693
- if (isFieldRelationship(fieldRelationship)) {
11694
- const destSchema = fieldRelationship.dest.schema;
11670
+ if (isFieldRelationship(related)) {
11671
+ const { destSchema } = related;
11695
11672
  const sq = cb(
11696
11673
  this._newQuery(
11697
11674
  destSchema,
@@ -11710,9 +11687,8 @@ var AbstractQuery = class {
11710
11687
  ...this.#ast.related ?? [],
11711
11688
  {
11712
11689
  correlation: {
11713
- parentField: fieldRelationship.source,
11714
- childField: fieldRelationship.dest.field,
11715
- op: "="
11690
+ parentField: related.sourceField,
11691
+ childField: related.destField
11716
11692
  },
11717
11693
  subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
11718
11694
  }
@@ -11727,9 +11703,11 @@ var AbstractQuery = class {
11727
11703
  }
11728
11704
  );
11729
11705
  }
11730
- if (isJunctionRelationship(junctionRelationship)) {
11731
- const destSchema = junctionRelationship.dest.schema;
11732
- const junctionSchema = junctionRelationship.junction.dest.schema;
11706
+ if (isJunctionRelationship(related)) {
11707
+ assert(related.length === 2, "Invalid relationship");
11708
+ const [firstRelation, secondRelation] = related;
11709
+ const { destSchema } = secondRelation;
11710
+ const junctionSchema = firstRelation.destSchema;
11733
11711
  const sq = cb(
11734
11712
  this._newQuery(
11735
11713
  destSchema,
@@ -11748,9 +11726,8 @@ var AbstractQuery = class {
11748
11726
  ...this.#ast.related ?? [],
11749
11727
  {
11750
11728
  correlation: {
11751
- parentField: junctionRelationship.source,
11752
- childField: junctionRelationship.junction.source,
11753
- op: "="
11729
+ parentField: firstRelation.sourceField,
11730
+ childField: firstRelation.destField
11754
11731
  },
11755
11732
  subquery: {
11756
11733
  table: junctionSchema.tableName,
@@ -11759,9 +11736,8 @@ var AbstractQuery = class {
11759
11736
  related: [
11760
11737
  {
11761
11738
  correlation: {
11762
- parentField: junctionRelationship.junction.dest.field,
11763
- childField: junctionRelationship.dest.field,
11764
- op: "="
11739
+ parentField: secondRelation.sourceField,
11740
+ childField: secondRelation.destField
11765
11741
  },
11766
11742
  hidden: true,
11767
11743
  subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
@@ -11845,10 +11821,8 @@ var AbstractQuery = class {
11845
11821
  _exists = (relationship, cb = (q) => q) => {
11846
11822
  const related = this.#schema.relationships[relationship];
11847
11823
  assert(related, "Invalid relationship");
11848
- const fieldRelationship = related;
11849
- const junctionRelationship = related;
11850
- if (isFieldRelationship(fieldRelationship)) {
11851
- const destSchema = fieldRelationship.dest.schema;
11824
+ if (isFieldRelationship(related)) {
11825
+ const { destSchema } = related;
11852
11826
  const sq = cb(
11853
11827
  this._newQuery(
11854
11828
  destSchema,
@@ -11863,18 +11837,19 @@ var AbstractQuery = class {
11863
11837
  type: "correlatedSubquery",
11864
11838
  related: {
11865
11839
  correlation: {
11866
- parentField: fieldRelationship.source,
11867
- childField: fieldRelationship.dest.field,
11868
- op: "="
11840
+ parentField: related.sourceField,
11841
+ childField: related.destField
11869
11842
  },
11870
11843
  subquery: addPrimaryKeysToAst(destSchema, sq.#ast)
11871
11844
  },
11872
11845
  op: "EXISTS"
11873
11846
  };
11874
11847
  }
11875
- if (isJunctionRelationship(junctionRelationship)) {
11876
- const destSchema = junctionRelationship.dest.schema;
11877
- const junctionSchema = junctionRelationship.junction.dest.schema;
11848
+ if (isJunctionRelationship(related)) {
11849
+ assert(related.length === 2, "Invalid relationship");
11850
+ const [firstRelation, secondRelation] = related;
11851
+ const { destSchema } = secondRelation;
11852
+ const junctionSchema = firstRelation.destSchema;
11878
11853
  const queryToDest = cb(
11879
11854
  this._newQuery(
11880
11855
  destSchema,
@@ -11889,9 +11864,8 @@ var AbstractQuery = class {
11889
11864
  type: "correlatedSubquery",
11890
11865
  related: {
11891
11866
  correlation: {
11892
- parentField: junctionRelationship.source,
11893
- childField: junctionRelationship.junction.source,
11894
- op: "="
11867
+ parentField: firstRelation.sourceField,
11868
+ childField: firstRelation.destField
11895
11869
  },
11896
11870
  subquery: {
11897
11871
  table: junctionSchema.tableName,
@@ -11901,9 +11875,8 @@ var AbstractQuery = class {
11901
11875
  type: "correlatedSubquery",
11902
11876
  related: {
11903
11877
  correlation: {
11904
- parentField: junctionRelationship.junction.dest.field,
11905
- childField: junctionRelationship.dest.field,
11906
- op: "="
11878
+ parentField: secondRelation.sourceField,
11879
+ childField: secondRelation.destField
11907
11880
  },
11908
11881
  subquery: addPrimaryKeysToAst(destSchema, queryToDest.#ast)
11909
11882
  },
@@ -12056,17 +12029,17 @@ var AuthQuery = class _AuthQuery extends AbstractQuery {
12056
12029
  }
12057
12030
  };
12058
12031
 
12059
- // ../zero-schema/src/authorization.ts
12060
- async function defineAuthorization(schema, definer) {
12032
+ // ../zero-schema/src/permissions.ts
12033
+ async function definePermissions(schema, definer) {
12061
12034
  const normalizedSchema = normalizeSchema(schema);
12062
12035
  const expressionBuilders = {};
12063
12036
  for (const [name, tableSchema] of Object.entries(normalizedSchema.tables)) {
12064
12037
  expressionBuilders[name] = new AuthQuery(tableSchema).expressionBuilder();
12065
12038
  }
12066
12039
  const config = await definer();
12067
- return compileAuthorization(config, expressionBuilders);
12040
+ return compilePermissions(config, expressionBuilders);
12068
12041
  }
12069
- function compileAuthorization(authz, expressionBuilders) {
12042
+ function compilePermissions(authz, expressionBuilders) {
12070
12043
  if (!authz) {
12071
12044
  return void 0;
12072
12045
  }
@@ -14381,17 +14354,17 @@ var MemorySource = class {
14381
14354
  switch (change.type) {
14382
14355
  case "add":
14383
14356
  if (data.has(change.row)) {
14384
- throw new Error(`Row already exists: ` + JSON.stringify(change));
14357
+ throw new Error(`Row already exists ${JSON.stringify(change)}`);
14385
14358
  }
14386
14359
  break;
14387
14360
  case "remove":
14388
14361
  if (!data.has(change.row)) {
14389
- throw new Error(`Row not found: ` + JSON.stringify(change));
14362
+ throw new Error(`Row not found ${JSON.stringify(change)}`);
14390
14363
  }
14391
14364
  break;
14392
14365
  case "edit":
14393
14366
  if (!data.has(change.oldRow)) {
14394
- throw new Error(`Row not found: ` + JSON.stringify(change));
14367
+ throw new Error(`Row not found ${JSON.stringify(change)}`);
14395
14368
  }
14396
14369
  break;
14397
14370
  default:
@@ -15246,7 +15219,7 @@ function makeMessage(message, context, logLevel) {
15246
15219
  }
15247
15220
 
15248
15221
  // ../zero-client/src/client/version.ts
15249
- var version2 = "0.7.2024112700+dfe437";
15222
+ var version2 = "0.7.2024120101+5cb996";
15250
15223
 
15251
15224
  // ../zero-client/src/client/log-options.ts
15252
15225
  var LevelFilterLogSink = class {
@@ -17231,9 +17204,9 @@ export {
17231
17204
  dropDatabase,
17232
17205
  dropAllDatabases,
17233
17206
  createTableSchema,
17234
- defineAuthorization,
17207
+ definePermissions,
17235
17208
  createSchema,
17236
17209
  escapeLike,
17237
17210
  Zero
17238
17211
  };
17239
- //# sourceMappingURL=chunk-HDEKBM3G.js.map
17212
+ //# sourceMappingURL=chunk-5S7LFUZ4.js.map