@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
package/dist/ir.cjs CHANGED
@@ -203,8 +203,10 @@ function compileCheckExpression(source, columns) {
203
203
  }
204
204
 
205
205
  // src/constants.ts
206
+ var NAMESPACE_PATTERN = /^(?!(?:events|native_sources)$)[a-z][a-z0-9_]{0,40}$/;
206
207
  var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
207
208
  var MAX_IDENTIFIER_LENGTH = 63;
209
+ var MAX_PERSISTED_READ_ROWS = 50001;
208
210
  var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
209
211
  var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
210
212
  var CELL_PART_SUFFIX = {
@@ -357,6 +359,7 @@ function validateResolvedView({ view, tables, views = [] }) {
357
359
  function validateSource({ scope, source, table }) {
358
360
  const { fail } = scope;
359
361
  if (source.kind === "etl" && table.source === void 0) fail(`etl source '${source.name}' must reference a synced table`);
362
+ if (source.kind === "etl" && table.primaryKey?.length === 0) fail(`etl source '${source.name}' cannot use an unkeyed synced table for resolved row identity`);
360
363
  if (source.kind !== "etl" && (table.internal !== true || table.cellMetadata !== true)) {
361
364
  fail(`${source.kind} source '${source.name}' must reference an internal table with cell metadata`);
362
365
  }
@@ -648,7 +651,7 @@ var canonicalTableSchema = zod.z.object({
648
651
  /** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
649
652
  source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
650
653
  columns: zod.z.array(canonicalColumnSchema).default([]),
651
- primaryKey: zod.z.array(columnIdentifier).min(1).max(8).optional(),
654
+ primaryKey: zod.z.array(columnIdentifier).max(8).optional(),
652
655
  links: zod.z.array(canonicalLinkSchema).default([]),
653
656
  indexes: zod.z.array(canonicalIndexSchema).default([]),
654
657
  /** Omitted by old definitions, preserving their existing content hashes. */
@@ -684,6 +687,29 @@ var canonicalTableSchema = zod.z.object({
684
687
  * data plane. Omitted otherwise.
685
688
  */
686
689
  materializes: identifier2.optional()
690
+ }).superRefine((table, ctx) => {
691
+ if (table.primaryKey?.length !== 0) return;
692
+ const fail = (message, path = ["primaryKey"]) => ctx.addIssue({ code: "custom", path, message: `unkeyed table '${table.table}' ${message}` });
693
+ if (table.source === void 0 || table.columns.length === 0) {
694
+ fail("requires a typed synced source");
695
+ }
696
+ if ([table.policies.write, table.policies.insert, table.policies.update].some((policy) => policy !== void 0)) {
697
+ fail("is read-only and cannot declare write policies", ["policies"]);
698
+ }
699
+ const ownedCollections = [table.indexes, table.actions, table.checks, table.foreignKeys, table.cowMutations];
700
+ const ownedMetadata = [table.cellMetadata, table.internal, table.materializes, table.renamedFrom];
701
+ if (ownedCollections.some((items) => items !== void 0 && items.length > 0) || ownedMetadata.some((value) => value !== void 0)) {
702
+ fail("cannot declare owned storage, constraints or identity operations");
703
+ }
704
+ for (const [index, column] of table.columns.entries()) {
705
+ const ownedColumnMetadata = [column.default, column.defaultFn, column.onUpdateFn, column.renamedFrom, column.cast, column.cell];
706
+ if (column.unique || ownedColumnMetadata.some((value) => value !== void 0)) {
707
+ fail("cannot declare column uniqueness, mutation defaults or migration metadata", ["columns", index]);
708
+ }
709
+ }
710
+ for (const [index, link] of table.links.entries()) {
711
+ if (link.enforce || link.kind === "toMany") fail("cannot provide an identity for this link", ["links", index]);
712
+ }
687
713
  });
688
714
  var MAX_VIEW_QUERY = 1e5;
689
715
  var MAX_RESOLVED_VIEW_QUERY = 5e6;
@@ -740,6 +766,26 @@ var canonicalViewSchema = zod.z.object({
740
766
  }
741
767
  }
742
768
  });
769
+ function validateUnkeyedLinkIdentities({ definition, ctx }) {
770
+ const tables = new Map(definition.tables.map((table) => [table.table, table]));
771
+ const relations = [
772
+ ...definition.tables.map((table, index) => ({ kind: "tables", index, links: table.links })),
773
+ ...(definition.views ?? []).map((view, index) => ({ kind: "views", index, links: view.links }))
774
+ ];
775
+ for (const relation of relations) {
776
+ for (const [linkIndex, link] of relation.links.entries()) {
777
+ if (link.kind !== "toOne" || link.namespace !== void 0 && link.namespace !== definition.namespace) continue;
778
+ const target = link.target === void 0 ? void 0 : tables.get(link.target);
779
+ if (target?.source !== void 0 && target.primaryKey?.length === 0) {
780
+ ctx.addIssue({
781
+ code: "custom",
782
+ path: [relation.kind, relation.index, "links", linkIndex],
783
+ message: `link '${link.name}' cannot use unkeyed table '${target.table}' as a to-one identity`
784
+ });
785
+ }
786
+ }
787
+ }
788
+ }
743
789
  var CELL_PART_TYPES = {
744
790
  at: "timestamptz",
745
791
  by: "text",
@@ -803,7 +849,7 @@ var exportGateSchema = zod.z.union([zod.z.literal(true), zod.z.object({ capabili
803
849
  var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
804
850
  var localDefinitionSchema = zod.z.object({
805
851
  definition_format: zod.z.literal(CANONICAL_FORMAT),
806
- namespace: identifier2.max(41),
852
+ namespace: identifier2.max(41).regex(NAMESPACE_PATTERN, "invalid or reserved ORM namespace"),
807
853
  description: zod.z.string().max(2e3).optional(),
808
854
  enums: zod.z.array(canonicalEnumSchema).default([]),
809
855
  tables: zod.z.array(canonicalTableSchema).min(0).max(500),
@@ -837,6 +883,7 @@ var localDefinitionSchema = zod.z.object({
837
883
  }
838
884
  }
839
885
  const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
886
+ validateUnkeyedLinkIdentities({ definition, ctx });
840
887
  const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
841
888
  for (const name of Object.keys(definition.exports ?? {})) {
842
889
  if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
@@ -1021,6 +1068,9 @@ localDefinitionSchema.safeExtend({
1021
1068
  imports: zod.z.array(localDefinitionSchema).max(32).optional()
1022
1069
  });
1023
1070
 
1071
+ // src/client/sql.ts
1072
+ var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
1073
+
1024
1074
  // src/ir/index.ts
1025
1075
  var IR_VERSION = 5;
1026
1076
  var LEGACY_IR_VERSION = 1;
@@ -1109,7 +1159,7 @@ var limitIrSchema = zod.z.object({
1109
1159
  variable: zod.z.string().optional(),
1110
1160
  value: zod.z.number().int().positive().optional(),
1111
1161
  default: zod.z.number().int().positive(),
1112
- max: zod.z.number().int().positive()
1162
+ max: zod.z.number().int().positive().max(MAX_PERSISTED_READ_ROWS)
1113
1163
  });
1114
1164
  var selectionIrSchema = zod.z.lazy(
1115
1165
  () => zod.z.object({
@@ -1354,7 +1404,8 @@ var compiledOperationSchema = zod.z.object({
1354
1404
  }).superRefine((operation, ctx) => {
1355
1405
  if (operation.language === "sql") {
1356
1406
  const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
1357
- if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
1407
+ const builtin = operation.name === "BuiltinSqlRead" && operation.opHash === BUILTIN_SQL_READ_HASH && operation.requires === null;
1408
+ if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !builtin && !operation.requires?.capability) {
1358
1409
  ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
1359
1410
  }
1360
1411
  } else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {