@sequenceholdings/orm 2.1.1 → 2.2.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 (68) hide show
  1. package/README.md +3 -1
  2. package/dist/authoring.cjs +284 -99
  3. package/dist/authoring.cjs.map +1 -1
  4. package/dist/authoring.d.cts +31 -8
  5. package/dist/authoring.d.ts +31 -8
  6. package/dist/authoring.js +282 -100
  7. package/dist/authoring.js.map +1 -1
  8. package/dist/canonical.cjs +51 -3
  9. package/dist/canonical.cjs.map +1 -1
  10. package/dist/canonical.d.cts +838 -12
  11. package/dist/canonical.d.ts +838 -12
  12. package/dist/canonical.js +47 -4
  13. package/dist/canonical.js.map +1 -1
  14. package/dist/cli.cjs +5838 -4197
  15. package/dist/cli.cjs.map +1 -1
  16. package/dist/cli.js +5838 -4197
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client.cjs +49 -32
  19. package/dist/client.cjs.map +1 -1
  20. package/dist/client.d.cts +49 -6
  21. package/dist/client.d.ts +49 -6
  22. package/dist/client.js +49 -32
  23. package/dist/client.js.map +1 -1
  24. package/dist/compiler.cjs +1237 -263
  25. package/dist/compiler.cjs.map +1 -1
  26. package/dist/compiler.d.cts +57 -3
  27. package/dist/compiler.d.ts +57 -3
  28. package/dist/compiler.js +1230 -264
  29. package/dist/compiler.js.map +1 -1
  30. package/dist/{constants-YoFGjIBM.d.cts → constants-C6EG6Wq7.d.cts} +1 -1
  31. package/dist/{constants-YoFGjIBM.d.ts → constants-C6EG6Wq7.d.ts} +1 -1
  32. package/dist/definition-DjfC7Lll.d.cts +91 -0
  33. package/dist/definition-DjfC7Lll.d.ts +91 -0
  34. package/dist/dynamic-input.cjs +2 -1
  35. package/dist/dynamic-input.cjs.map +1 -1
  36. package/dist/dynamic-input.d.cts +9 -2
  37. package/dist/dynamic-input.d.ts +9 -2
  38. package/dist/dynamic-input.js +2 -1
  39. package/dist/dynamic-input.js.map +1 -1
  40. package/dist/index.cjs +1094 -321
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +479 -19
  43. package/dist/index.d.ts +479 -19
  44. package/dist/index.js +1083 -322
  45. package/dist/index.js.map +1 -1
  46. package/dist/ir.cjs +84 -10
  47. package/dist/ir.cjs.map +1 -1
  48. package/dist/ir.d.cts +138 -13
  49. package/dist/ir.d.ts +138 -13
  50. package/dist/ir.js +81 -11
  51. package/dist/ir.js.map +1 -1
  52. package/dist/predicate-v2.cjs +78 -9
  53. package/dist/predicate-v2.cjs.map +1 -1
  54. package/dist/predicate-v2.d.cts +1 -1
  55. package/dist/predicate-v2.d.ts +1 -1
  56. package/dist/predicate-v2.js +78 -9
  57. package/dist/predicate-v2.js.map +1 -1
  58. package/dist/sdl.cjs +156 -21
  59. package/dist/sdl.cjs.map +1 -1
  60. package/dist/sdl.d.cts +8 -1
  61. package/dist/sdl.d.ts +8 -1
  62. package/dist/sdl.js +156 -21
  63. package/dist/sdl.js.map +1 -1
  64. package/package.json +5 -4
  65. package/src/codegen-gql/server-fns.cjs +2 -2
  66. package/templates/orm-namespace/AGENTS.md +10 -0
  67. package/templates/orm-namespace/CLAUDE.md +1 -84
  68. package/templates/orm-namespace/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { ClaimKey, PredIr } from './ir.cjs';
2
2
  import { P as PolicyExpression } from './policy-1iZbGnZZ.cjs';
3
3
  import 'zod';
4
- import './constants-YoFGjIBM.cjs';
4
+ import './constants-C6EG6Wq7.cjs';
5
5
 
6
6
  declare const POLICY_COMPARE_OPS: readonly ["=", "!=", "<", "<=", ">", ">="];
7
7
  type PolicyCompareOp = (typeof POLICY_COMPARE_OPS)[number];
@@ -1,7 +1,7 @@
1
1
  import { ClaimKey, PredIr } from './ir.js';
2
2
  import { P as PolicyExpression } from './policy-1iZbGnZZ.js';
3
3
  import 'zod';
4
- import './constants-YoFGjIBM.js';
4
+ import './constants-C6EG6Wq7.js';
5
5
 
6
6
  declare const POLICY_COMPARE_OPS: readonly ["=", "!=", "<", "<=", ">", ">="];
7
7
  type PolicyCompareOp = (typeof POLICY_COMPARE_OPS)[number];
@@ -32,6 +32,7 @@ var PolicyCompileError = class extends Error {
32
32
  var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
33
33
  var MAX_IDENTIFIER_LENGTH = 63;
34
34
  var CAPABILITY_KEY_PATTERN = /^(?:org\/|app\/[a-z][a-z0-9-]{0,63}\/)?[a-z0-9-]{1,64}$/;
35
+ var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
35
36
  var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
36
37
  var CELL_PART_SUFFIX = {
37
38
  at: "__at",
@@ -561,6 +562,8 @@ var canonicalLinkSchema = z.object({
561
562
  kind: z.enum(["toOne", "toMany", "toPlatformUser"]),
562
563
  /** Target table name (namespace-local). Absent for toPlatformUser. */
563
564
  target: identifier2.optional(),
565
+ /** Owning namespace of an imported target; omitted for local links. */
566
+ namespace: identifier2.max(41).optional(),
564
567
  /** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
565
568
  on: columnIdentifier,
566
569
  /** Referenced column on the target (default: target's PK / platform user `sub`). */
@@ -662,11 +665,12 @@ var canonicalForeignKeySchema = z.object({
662
665
  }).strict();
663
666
  var canonicalTableSchema = z.object({
664
667
  table: identifier2,
668
+ displayName: z.string().trim().min(1).max(120).optional(),
665
669
  description: z.string().max(2e3).optional(),
666
670
  /** Table-level rename hint (new in v2). */
667
671
  renamedFrom: identifier2.optional(),
668
- /** Synced/reflected read-only tables (`source: gold.*`) — v1 semantics. */
669
- source: z.string().regex(/^gold\.[a-z][a-z0-9_]*$/).optional(),
672
+ /** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
673
+ source: z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
670
674
  columns: z.array(canonicalColumnSchema).default([]),
671
675
  primaryKey: z.array(columnIdentifier).min(1).max(8).optional(),
672
676
  links: z.array(canonicalLinkSchema).default([]),
@@ -819,7 +823,9 @@ function validateCellMetadata(table, index, ctx) {
819
823
  }
820
824
  }
821
825
  }
822
- z.object({
826
+ var exportGateSchema = z.union([z.literal(true), z.object({ capability: z.string().min(1) }).strict(), z.object({ role: z.string().min(1) }).strict()]);
827
+ var relationExportSchema = z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
828
+ var localDefinitionSchema = z.object({
823
829
  definition_format: z.literal(CANONICAL_FORMAT),
824
830
  namespace: identifier2.max(41),
825
831
  description: z.string().max(2e3).optional(),
@@ -827,6 +833,8 @@ z.object({
827
833
  tables: z.array(canonicalTableSchema).min(0).max(500),
828
834
  /** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
829
835
  views: z.array(canonicalViewSchema).max(500).optional(),
836
+ /** Target-owned cross-namespace access contract, using existing namespace grants. */
837
+ exports: z.record(identifier2, relationExportSchema).optional(),
830
838
  /** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
831
839
  capabilities: z.object({
832
840
  roles: z.unknown().optional(),
@@ -853,7 +861,16 @@ z.object({
853
861
  }
854
862
  }
855
863
  const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
864
+ const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
865
+ for (const name of Object.keys(definition.exports ?? {})) {
866
+ if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
867
+ }
856
868
  for (const [tableIndex, table] of definition.tables.entries()) {
869
+ for (const [linkIndex, link] of table.links.entries()) {
870
+ if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
871
+ ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
872
+ }
873
+ }
857
874
  const names = /* @__PURE__ */ new Set([
858
875
  ...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
859
876
  ...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
@@ -1023,11 +1040,18 @@ z.object({
1023
1040
  };
1024
1041
  for (const view of views) visit(view.view, []);
1025
1042
  });
1043
+ localDefinitionSchema.safeExtend({
1044
+ /** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
1045
+ imports: z.array(localDefinitionSchema).max(32).optional()
1046
+ });
1026
1047
 
1027
1048
  // src/ir/index.ts
1028
- var IR_VERSION = 2;
1029
1049
  var LEGACY_IR_VERSION = 1;
1030
- var irVersionSchema = z.union([z.literal(LEGACY_IR_VERSION), z.literal(IR_VERSION)]);
1050
+ var GUARDED_IR_VERSION = 2;
1051
+ var COMPOSED_IR_VERSION = 3;
1052
+ var SQL_IR_VERSION = 4;
1053
+ var RUNTIME_SQL_IR_VERSION = 5;
1054
+ var irVersionSchema = z.union([z.literal(LEGACY_IR_VERSION), z.literal(GUARDED_IR_VERSION), z.literal(COMPOSED_IR_VERSION), z.literal(SQL_IR_VERSION), z.literal(RUNTIME_SQL_IR_VERSION)]);
1031
1055
  z.object({ irVersion: irVersionSchema });
1032
1056
  var CLAIMS_CONTRACT = {
1033
1057
  sub: "string",
@@ -1071,8 +1095,8 @@ var predIrSchema = z.lazy(
1071
1095
  value: z.number(),
1072
1096
  where: predIrSchema.optional()
1073
1097
  }),
1074
- z.object({ kind: z.literal("capability"), key: z.string() }),
1075
- z.object({ kind: z.literal("role"), key: z.string() }),
1098
+ z.object({ kind: z.literal("capability"), key: z.string(), namespace: z.string().optional() }),
1099
+ z.object({ kind: z.literal("role"), key: z.string(), namespace: z.string().optional() }),
1076
1100
  z.object({ kind: z.literal("dynamicFilter"), slot: z.string() }),
1077
1101
  z.object({ kind: z.literal("const"), value: z.boolean() })
1078
1102
  ])
@@ -1299,7 +1323,31 @@ var variableIrSchema = z.object({
1299
1323
  /** Absent = no default declared; see {@link variableDefaultIrSchema}. */
1300
1324
  defaultValue: variableDefaultIrSchema.optional()
1301
1325
  });
1326
+ var sqlColumnSchema = z.object({ name: z.string(), type: z.enum(["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz"]), nullable: z.boolean() });
1302
1327
  var compiledOperationSchema = z.object({
1328
+ language: z.literal("sql").optional(),
1329
+ /** Server-compiled object catalog and permission ceiling, never caller SQL. */
1330
+ sqlQuery: z.object({
1331
+ catalog: z.object({
1332
+ identity: z.string(),
1333
+ objects: z.array(z.object({
1334
+ ref: z.string(),
1335
+ table: z.string(),
1336
+ columns: z.array(sqlColumnSchema.extend({ type: z.string() })).min(1),
1337
+ scan: z.string().min(1),
1338
+ read: z.array(z.string()).min(1)
1339
+ }).strict()).min(1).max(256)
1340
+ }).strict(),
1341
+ read: z.array(z.string()).min(1).max(256),
1342
+ maxRows: z.number().int().min(1).max(1e4)
1343
+ }).strict().optional(),
1344
+ sql: z.object({
1345
+ text: z.string().min(1).max(1048576),
1346
+ columns: z.array(sqlColumnSchema).min(1).max(256),
1347
+ parameters: z.array(z.string()).max(128),
1348
+ read: z.array(z.string()).min(1).max(256),
1349
+ maxRows: z.number().int().min(1).max(1e4)
1350
+ }).strict().optional(),
1303
1351
  irVersion: irVersionSchema,
1304
1352
  name: z.string(),
1305
1353
  opHash: z.string().regex(/^sha256:[0-9a-f]{64}$/),
@@ -1311,8 +1359,16 @@ var compiledOperationSchema = z.object({
1311
1359
  variables: z.array(variableIrSchema),
1312
1360
  /** Every table the op touches — data-token scoping + audit. */
1313
1361
  tableSet: z.array(z.string()).min(1),
1314
- roots: z.array(rootIrSchema).min(1)
1362
+ roots: z.array(rootIrSchema)
1315
1363
  }).superRefine((operation, ctx) => {
1364
+ if (operation.language === "sql") {
1365
+ const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
1366
+ if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
1367
+ ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
1368
+ }
1369
+ } else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
1370
+ ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
1371
+ }
1316
1372
  for (const [index, root] of operation.roots.entries()) {
1317
1373
  if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
1318
1374
  if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
@@ -1359,11 +1415,16 @@ var resolvedMetaIrSchema = z.object({
1359
1415
  });
1360
1416
  var tableMetaIrSchema = z.object({
1361
1417
  table: z.string(),
1418
+ namespace: z.string().optional(),
1419
+ dependencies: z.array(z.string()).optional(),
1420
+ foreignReferences: z.array(z.object({ column: z.string(), target: z.string(), targetColumn: z.string() })).optional(),
1421
+ exportRead: z.union([z.literal(true), z.object({ capability: z.string() }), z.object({ role: z.string() })]).optional(),
1422
+ exportWrite: z.union([z.literal(true), z.object({ capability: z.string() }), z.object({ role: z.string() })]).optional(),
1362
1423
  schema: z.string(),
1363
1424
  typename: z.string(),
1364
1425
  /**
1365
1426
  * True when statements over this relation evaluate a claims-gated synced
1366
- * view: synced twins (`source: gold.*`) materialize as views whose baked
1427
+ * view: synced twins (`source: schema.table`) materialize as views whose baked
1367
1428
  * policy reads `current_setting('request.jwt.claims')`, and namespace views
1368
1429
  * inherit the gate transitively through their declared dependencies. The
1369
1430
  * executor must stamp that GUC (transaction-scoped) before any statement
@@ -1422,10 +1483,18 @@ z.object({
1422
1483
  irVersion: irVersionSchema,
1423
1484
  namespace: z.string(),
1424
1485
  schemaHash: z.string(),
1486
+ ownSchemaHash: z.string().optional(),
1487
+ dependencies: z.record(z.string(), z.string()).optional(),
1488
+ readPolicies: z.record(z.string(), predIrSchema).optional(),
1425
1489
  opsHash: z.string(),
1490
+ /** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
1491
+ unbackedTables: z.array(z.string()).optional(),
1426
1492
  tables: z.record(z.string(), tableMetaIrSchema),
1427
1493
  operations: z.record(z.string(), compiledOperationSchema)
1428
1494
  }).superRefine((artifact, ctx) => {
1495
+ if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
1496
+ ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
1497
+ }
1429
1498
  for (const [name, operation] of Object.entries(artifact.operations)) {
1430
1499
  if (operation.irVersion > artifact.irVersion) {
1431
1500
  ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });