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