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