@sequenceholdings/orm 2.4.0 → 2.5.0

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 (59) hide show
  1. package/dist/authoring.cjs +53 -7
  2. package/dist/authoring.cjs.map +1 -1
  3. package/dist/authoring.d.cts +11 -7
  4. package/dist/authoring.d.ts +11 -7
  5. package/dist/authoring.js +53 -7
  6. package/dist/authoring.js.map +1 -1
  7. package/dist/canonical.cjs +48 -2
  8. package/dist/canonical.cjs.map +1 -1
  9. package/dist/canonical.d.cts +72 -72
  10. package/dist/canonical.d.ts +72 -72
  11. package/dist/canonical.js +48 -2
  12. package/dist/canonical.js.map +1 -1
  13. package/dist/cli.cjs +237 -20
  14. package/dist/cli.cjs.map +1 -1
  15. package/dist/cli.js +237 -20
  16. package/dist/cli.js.map +1 -1
  17. package/dist/client.cjs +1 -1
  18. package/dist/client.cjs.map +1 -1
  19. package/dist/client.d.cts +1 -1
  20. package/dist/client.d.ts +1 -1
  21. package/dist/client.js +1 -1
  22. package/dist/client.js.map +1 -1
  23. package/dist/compiler.cjs +386 -14
  24. package/dist/compiler.cjs.map +1 -1
  25. package/dist/compiler.d.cts +16 -3
  26. package/dist/compiler.d.ts +16 -3
  27. package/dist/compiler.js +386 -15
  28. package/dist/compiler.js.map +1 -1
  29. package/dist/{constants-C6EG6Wq7.d.cts → constants-Dou1RkTo.d.cts} +7 -2
  30. package/dist/{constants-C6EG6Wq7.d.ts → constants-Dou1RkTo.d.ts} +7 -2
  31. package/dist/dynamic-input.d.cts +1 -1
  32. package/dist/dynamic-input.d.ts +1 -1
  33. package/dist/index.cjs +329 -130
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +66 -58
  36. package/dist/index.d.ts +66 -58
  37. package/dist/index.js +329 -131
  38. package/dist/index.js.map +1 -1
  39. package/dist/ir.cjs +50 -3
  40. package/dist/ir.cjs.map +1 -1
  41. package/dist/ir.d.cts +71 -71
  42. package/dist/ir.d.ts +71 -71
  43. package/dist/ir.js +50 -3
  44. package/dist/ir.js.map +1 -1
  45. package/dist/predicate-v2.cjs +50 -3
  46. package/dist/predicate-v2.cjs.map +1 -1
  47. package/dist/predicate-v2.d.cts +1 -1
  48. package/dist/predicate-v2.d.ts +1 -1
  49. package/dist/predicate-v2.js +50 -3
  50. package/dist/predicate-v2.js.map +1 -1
  51. package/dist/sdl.cjs +53 -3
  52. package/dist/sdl.cjs.map +1 -1
  53. package/dist/sdl.d.cts +3 -1
  54. package/dist/sdl.d.ts +3 -1
  55. package/dist/sdl.js +53 -3
  56. package/dist/sdl.js.map +1 -1
  57. package/package.json +1 -1
  58. package/dist/{definition-DjfC7Lll.d.cts → definition-B99BsOAO.d.cts} +4 -4
  59. package/dist/{definition-DjfC7Lll.d.ts → definition-B99BsOAO.d.ts} +4 -4
@@ -220,6 +220,7 @@ function compileCheckExpression(source, columns) {
220
220
  }
221
221
 
222
222
  // src/constants.ts
223
+ var NAMESPACE_PATTERN = /^(?!(?:events|native_sources)$)[a-z][a-z0-9_]{0,40}$/;
223
224
  var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
224
225
  var MAX_IDENTIFIER_LENGTH = 63;
225
226
  var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
@@ -382,6 +383,7 @@ function validateResolvedView({ view, tables, views = [] }) {
382
383
  function validateSource({ scope, source, table }) {
383
384
  const { fail } = scope;
384
385
  if (source.kind === "etl" && table.source === void 0) fail(`etl source '${source.name}' must reference a synced table`);
386
+ if (source.kind === "etl" && table.primaryKey?.length === 0) fail(`etl source '${source.name}' cannot use an unkeyed synced table for resolved row identity`);
385
387
  if (source.kind !== "etl" && (table.internal !== true || table.cellMetadata !== true)) {
386
388
  fail(`${source.kind} source '${source.name}' must reference an internal table with cell metadata`);
387
389
  }
@@ -830,7 +832,7 @@ var canonicalTableSchema = zod.z.object({
830
832
  /** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
831
833
  source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
832
834
  columns: zod.z.array(canonicalColumnSchema).default([]),
833
- primaryKey: zod.z.array(columnIdentifier).min(1).max(8).optional(),
835
+ primaryKey: zod.z.array(columnIdentifier).max(8).optional(),
834
836
  links: zod.z.array(canonicalLinkSchema).default([]),
835
837
  indexes: zod.z.array(canonicalIndexSchema).default([]),
836
838
  /** Omitted by old definitions, preserving their existing content hashes. */
@@ -866,6 +868,29 @@ var canonicalTableSchema = zod.z.object({
866
868
  * data plane. Omitted otherwise.
867
869
  */
868
870
  materializes: identifier2.optional()
871
+ }).superRefine((table, ctx) => {
872
+ if (table.primaryKey?.length !== 0) return;
873
+ const fail = (message, path = ["primaryKey"]) => ctx.addIssue({ code: "custom", path, message: `unkeyed table '${table.table}' ${message}` });
874
+ if (table.source === void 0 || table.columns.length === 0) {
875
+ fail("requires a typed synced source");
876
+ }
877
+ if ([table.policies.write, table.policies.insert, table.policies.update].some((policy) => policy !== void 0)) {
878
+ fail("is read-only and cannot declare write policies", ["policies"]);
879
+ }
880
+ const ownedCollections = [table.indexes, table.actions, table.checks, table.foreignKeys, table.cowMutations];
881
+ const ownedMetadata = [table.cellMetadata, table.internal, table.materializes, table.renamedFrom];
882
+ if (ownedCollections.some((items) => items !== void 0 && items.length > 0) || ownedMetadata.some((value) => value !== void 0)) {
883
+ fail("cannot declare owned storage, constraints or identity operations");
884
+ }
885
+ for (const [index, column] of table.columns.entries()) {
886
+ const ownedColumnMetadata = [column.default, column.defaultFn, column.onUpdateFn, column.renamedFrom, column.cast, column.cell];
887
+ if (column.unique || ownedColumnMetadata.some((value) => value !== void 0)) {
888
+ fail("cannot declare column uniqueness, mutation defaults or migration metadata", ["columns", index]);
889
+ }
890
+ }
891
+ for (const [index, link] of table.links.entries()) {
892
+ if (link.enforce || link.kind === "toMany") fail("cannot provide an identity for this link", ["links", index]);
893
+ }
869
894
  });
870
895
  var MAX_VIEW_QUERY = 1e5;
871
896
  var MAX_RESOLVED_VIEW_QUERY = 5e6;
@@ -922,6 +947,26 @@ var canonicalViewSchema = zod.z.object({
922
947
  }
923
948
  }
924
949
  });
950
+ function validateUnkeyedLinkIdentities({ definition, ctx }) {
951
+ const tables = new Map(definition.tables.map((table) => [table.table, table]));
952
+ const relations = [
953
+ ...definition.tables.map((table, index) => ({ kind: "tables", index, links: table.links })),
954
+ ...(definition.views ?? []).map((view, index) => ({ kind: "views", index, links: view.links }))
955
+ ];
956
+ for (const relation of relations) {
957
+ for (const [linkIndex, link] of relation.links.entries()) {
958
+ if (link.kind !== "toOne" || link.namespace !== void 0 && link.namespace !== definition.namespace) continue;
959
+ const target = link.target === void 0 ? void 0 : tables.get(link.target);
960
+ if (target?.source !== void 0 && target.primaryKey?.length === 0) {
961
+ ctx.addIssue({
962
+ code: "custom",
963
+ path: [relation.kind, relation.index, "links", linkIndex],
964
+ message: `link '${link.name}' cannot use unkeyed table '${target.table}' as a to-one identity`
965
+ });
966
+ }
967
+ }
968
+ }
969
+ }
925
970
  var CELL_PART_TYPES = {
926
971
  at: "timestamptz",
927
972
  by: "text",
@@ -985,7 +1030,7 @@ var exportGateSchema = zod.z.union([zod.z.literal(true), zod.z.object({ capabili
985
1030
  var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
986
1031
  var localDefinitionSchema = zod.z.object({
987
1032
  definition_format: zod.z.literal(CANONICAL_FORMAT),
988
- namespace: identifier2.max(41),
1033
+ namespace: identifier2.max(41).regex(NAMESPACE_PATTERN, "invalid or reserved ORM namespace"),
989
1034
  description: zod.z.string().max(2e3).optional(),
990
1035
  enums: zod.z.array(canonicalEnumSchema).default([]),
991
1036
  tables: zod.z.array(canonicalTableSchema).min(0).max(500),
@@ -1019,6 +1064,7 @@ var localDefinitionSchema = zod.z.object({
1019
1064
  }
1020
1065
  }
1021
1066
  const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
1067
+ validateUnkeyedLinkIdentities({ definition, ctx });
1022
1068
  const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
1023
1069
  for (const name of Object.keys(definition.exports ?? {})) {
1024
1070
  if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });