@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/sdl.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { B as BUCKETABLE_COLUMN_TYPES, C as CELL_TYPENAMES, a as CUSTOM_SCALARS, D as DATE_BUCKET_ENUM, N as NUMERICISH_COLUMN_TYPES, O as ORDER_BY_ENUM, b as ORDER_BY_ENUM_VALUES, P as PLATFORM_USER_TYPENAME, T as TableNames, V as VARIABLE_SCALAR_NAMES, c as camelCase, d as cellsTypename, e as columnTypeForScalar, f as comparisonExpName, g as enumTypeName, h as fieldName, i as graphqlScalarFor, p as pascalCase, t as tableNames, j as typeName } from './naming-CU9ThP_E.cjs';
2
2
  import { CanonicalDefinition, CanonicalRelation, CanonicalColumn } from './canonical.cjs';
3
3
  import { z } from 'zod';
4
- import './constants-C6EG6Wq7.cjs';
4
+ import './constants-Dou1RkTo.cjs';
5
5
  import './policy-1iZbGnZZ.cjs';
6
6
 
7
7
  /**
@@ -37,6 +37,8 @@ interface GenerateSdlOptions {
37
37
  * released CLI; operations always compile against the default shape.
38
38
  */
39
39
  stringOnlyPatternOperators?: boolean;
40
+ /** Reproduce earlier SDL for the server's compatibility check only. */
41
+ omitReadBudgetDirective?: boolean;
40
42
  }
41
43
  declare function generateSdl(canonical: CanonicalDefinition, options?: GenerateSdlOptions): string;
42
44
  /** Columns a resolved-table mutation may write: authored data columns, never the view's system columns. */
package/dist/sdl.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { B as BUCKETABLE_COLUMN_TYPES, C as CELL_TYPENAMES, a as CUSTOM_SCALARS, D as DATE_BUCKET_ENUM, N as NUMERICISH_COLUMN_TYPES, O as ORDER_BY_ENUM, b as ORDER_BY_ENUM_VALUES, P as PLATFORM_USER_TYPENAME, T as TableNames, V as VARIABLE_SCALAR_NAMES, c as camelCase, d as cellsTypename, e as columnTypeForScalar, f as comparisonExpName, g as enumTypeName, h as fieldName, i as graphqlScalarFor, p as pascalCase, t as tableNames, j as typeName } from './naming-CPfx7EfF.js';
2
2
  import { CanonicalDefinition, CanonicalRelation, CanonicalColumn } from './canonical.js';
3
3
  import { z } from 'zod';
4
- import './constants-C6EG6Wq7.js';
4
+ import './constants-Dou1RkTo.js';
5
5
  import './policy-1iZbGnZZ.js';
6
6
 
7
7
  /**
@@ -37,6 +37,8 @@ interface GenerateSdlOptions {
37
37
  * released CLI; operations always compile against the default shape.
38
38
  */
39
39
  stringOnlyPatternOperators?: boolean;
40
+ /** Reproduce earlier SDL for the server's compatibility check only. */
41
+ omitReadBudgetDirective?: boolean;
40
42
  }
41
43
  declare function generateSdl(canonical: CanonicalDefinition, options?: GenerateSdlOptions): string;
42
44
  /** Columns a resolved-table mutation may write: authored data columns, never the view's system columns. */
package/dist/sdl.js CHANGED
@@ -202,8 +202,10 @@ function compileCheckExpression(source, columns) {
202
202
  }
203
203
 
204
204
  // src/constants.ts
205
+ var NAMESPACE_PATTERN = /^(?!(?:events|native_sources)$)[a-z][a-z0-9_]{0,40}$/;
205
206
  var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
206
207
  var MAX_IDENTIFIER_LENGTH = 63;
208
+ var MAX_PERSISTED_READ_ROWS = 50001;
207
209
  var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
208
210
  var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
209
211
  var CELL_PART_SUFFIX = {
@@ -356,6 +358,7 @@ function validateResolvedView({ view, tables, views = [] }) {
356
358
  function validateSource({ scope, source, table }) {
357
359
  const { fail } = scope;
358
360
  if (source.kind === "etl" && table.source === void 0) fail(`etl source '${source.name}' must reference a synced table`);
361
+ if (source.kind === "etl" && table.primaryKey?.length === 0) fail(`etl source '${source.name}' cannot use an unkeyed synced table for resolved row identity`);
359
362
  if (source.kind !== "etl" && (table.internal !== true || table.cellMetadata !== true)) {
360
363
  fail(`${source.kind} source '${source.name}' must reference an internal table with cell metadata`);
361
364
  }
@@ -647,7 +650,7 @@ var canonicalTableSchema = z.object({
647
650
  /** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
648
651
  source: z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
649
652
  columns: z.array(canonicalColumnSchema).default([]),
650
- primaryKey: z.array(columnIdentifier).min(1).max(8).optional(),
653
+ primaryKey: z.array(columnIdentifier).max(8).optional(),
651
654
  links: z.array(canonicalLinkSchema).default([]),
652
655
  indexes: z.array(canonicalIndexSchema).default([]),
653
656
  /** Omitted by old definitions, preserving their existing content hashes. */
@@ -683,6 +686,29 @@ var canonicalTableSchema = z.object({
683
686
  * data plane. Omitted otherwise.
684
687
  */
685
688
  materializes: identifier2.optional()
689
+ }).superRefine((table, ctx) => {
690
+ if (table.primaryKey?.length !== 0) return;
691
+ const fail = (message, path = ["primaryKey"]) => ctx.addIssue({ code: "custom", path, message: `unkeyed table '${table.table}' ${message}` });
692
+ if (table.source === void 0 || table.columns.length === 0) {
693
+ fail("requires a typed synced source");
694
+ }
695
+ if ([table.policies.write, table.policies.insert, table.policies.update].some((policy) => policy !== void 0)) {
696
+ fail("is read-only and cannot declare write policies", ["policies"]);
697
+ }
698
+ const ownedCollections = [table.indexes, table.actions, table.checks, table.foreignKeys, table.cowMutations];
699
+ const ownedMetadata = [table.cellMetadata, table.internal, table.materializes, table.renamedFrom];
700
+ if (ownedCollections.some((items) => items !== void 0 && items.length > 0) || ownedMetadata.some((value) => value !== void 0)) {
701
+ fail("cannot declare owned storage, constraints or identity operations");
702
+ }
703
+ for (const [index, column] of table.columns.entries()) {
704
+ const ownedColumnMetadata = [column.default, column.defaultFn, column.onUpdateFn, column.renamedFrom, column.cast, column.cell];
705
+ if (column.unique || ownedColumnMetadata.some((value) => value !== void 0)) {
706
+ fail("cannot declare column uniqueness, mutation defaults or migration metadata", ["columns", index]);
707
+ }
708
+ }
709
+ for (const [index, link] of table.links.entries()) {
710
+ if (link.enforce || link.kind === "toMany") fail("cannot provide an identity for this link", ["links", index]);
711
+ }
686
712
  });
687
713
  var MAX_VIEW_QUERY = 1e5;
688
714
  var MAX_RESOLVED_VIEW_QUERY = 5e6;
@@ -739,6 +765,26 @@ var canonicalViewSchema = z.object({
739
765
  }
740
766
  }
741
767
  });
768
+ function validateUnkeyedLinkIdentities({ definition, ctx }) {
769
+ const tables = new Map(definition.tables.map((table) => [table.table, table]));
770
+ const relations = [
771
+ ...definition.tables.map((table, index) => ({ kind: "tables", index, links: table.links })),
772
+ ...(definition.views ?? []).map((view, index) => ({ kind: "views", index, links: view.links }))
773
+ ];
774
+ for (const relation of relations) {
775
+ for (const [linkIndex, link] of relation.links.entries()) {
776
+ if (link.kind !== "toOne" || link.namespace !== void 0 && link.namespace !== definition.namespace) continue;
777
+ const target = link.target === void 0 ? void 0 : tables.get(link.target);
778
+ if (target?.source !== void 0 && target.primaryKey?.length === 0) {
779
+ ctx.addIssue({
780
+ code: "custom",
781
+ path: [relation.kind, relation.index, "links", linkIndex],
782
+ message: `link '${link.name}' cannot use unkeyed table '${target.table}' as a to-one identity`
783
+ });
784
+ }
785
+ }
786
+ }
787
+ }
742
788
  var CELL_PART_TYPES = {
743
789
  at: "timestamptz",
744
790
  by: "text",
@@ -802,7 +848,7 @@ var exportGateSchema = z.union([z.literal(true), z.object({ capability: z.string
802
848
  var relationExportSchema = z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
803
849
  var localDefinitionSchema = z.object({
804
850
  definition_format: z.literal(CANONICAL_FORMAT),
805
- namespace: identifier2.max(41),
851
+ namespace: identifier2.max(41).regex(NAMESPACE_PATTERN, "invalid or reserved ORM namespace"),
806
852
  description: z.string().max(2e3).optional(),
807
853
  enums: z.array(canonicalEnumSchema).default([]),
808
854
  tables: z.array(canonicalTableSchema).min(0).max(500),
@@ -836,6 +882,7 @@ var localDefinitionSchema = z.object({
836
882
  }
837
883
  }
838
884
  const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
885
+ validateUnkeyedLinkIdentities({ definition, ctx });
839
886
  const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
840
887
  for (const name of Object.keys(definition.exports ?? {})) {
841
888
  if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
@@ -1197,6 +1244,11 @@ var CELL_TYPENAMES = {
1197
1244
  function cellsTypename(typename) {
1198
1245
  return `${typename}Cells`;
1199
1246
  }
1247
+
1248
+ // src/client/sql.ts
1249
+ var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
1250
+
1251
+ // src/ir/index.ts
1200
1252
  var LEGACY_IR_VERSION = 1;
1201
1253
  var GUARDED_IR_VERSION = 2;
1202
1254
  var COMPOSED_IR_VERSION = 3;
@@ -1264,7 +1316,7 @@ var limitIrSchema = z.object({
1264
1316
  variable: z.string().optional(),
1265
1317
  value: z.number().int().positive().optional(),
1266
1318
  default: z.number().int().positive(),
1267
- max: z.number().int().positive()
1319
+ max: z.number().int().positive().max(MAX_PERSISTED_READ_ROWS)
1268
1320
  });
1269
1321
  var selectionIrSchema = z.lazy(
1270
1322
  () => z.object({
@@ -1509,7 +1561,8 @@ var compiledOperationSchema = z.object({
1509
1561
  }).superRefine((operation, ctx) => {
1510
1562
  if (operation.language === "sql") {
1511
1563
  const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
1512
- if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
1564
+ const builtin = operation.name === "BuiltinSqlRead" && operation.opHash === BUILTIN_SQL_READ_HASH && operation.requires === null;
1565
+ if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !builtin && !operation.requires?.capability) {
1513
1566
  ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
1514
1567
  }
1515
1568
  } else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
@@ -1790,6 +1843,9 @@ function generateSdl(canonical, options = {}) {
1790
1843
  blocks.push(
1791
1844
  '"""Gates an operation behind a platform capability or custom role \u2014 checked by the data plane before execution."""\ndirective @requires(capability: String, role: String) on QUERY | MUTATION'
1792
1845
  );
1846
+ if (!options.omitReadBudgetDirective) blocks.push(
1847
+ '"""Sets a document-authored ceiling of 1\u201350001 rows for one flat select root. Runtime variables cannot raise it."""\ndirective @readBudget(maxRows: Int!) on QUERY'
1848
+ );
1793
1849
  blocks.push("directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT");
1794
1850
  blocks.push(
1795
1851
  '"""Abort the entire mutation unless this root affects exactly the document-authored number of rows. Mutation roots only; cannot be conditional."""\ndirective @assertAffectedRows(exactly: Int!) on FIELD'