@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.
- package/README.md +3 -1
- package/dist/authoring.cjs +284 -99
- package/dist/authoring.cjs.map +1 -1
- package/dist/authoring.d.cts +31 -8
- package/dist/authoring.d.ts +31 -8
- package/dist/authoring.js +282 -100
- package/dist/authoring.js.map +1 -1
- package/dist/canonical.cjs +51 -3
- package/dist/canonical.cjs.map +1 -1
- package/dist/canonical.d.cts +838 -12
- package/dist/canonical.d.ts +838 -12
- package/dist/canonical.js +47 -4
- package/dist/canonical.js.map +1 -1
- package/dist/cli.cjs +5838 -4197
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +5838 -4197
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +49 -32
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +49 -6
- package/dist/client.d.ts +49 -6
- package/dist/client.js +49 -32
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +1237 -263
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +57 -3
- package/dist/compiler.d.ts +57 -3
- package/dist/compiler.js +1230 -264
- package/dist/compiler.js.map +1 -1
- package/dist/{constants-YoFGjIBM.d.cts → constants-C6EG6Wq7.d.cts} +1 -1
- package/dist/{constants-YoFGjIBM.d.ts → constants-C6EG6Wq7.d.ts} +1 -1
- package/dist/definition-DjfC7Lll.d.cts +91 -0
- package/dist/definition-DjfC7Lll.d.ts +91 -0
- package/dist/dynamic-input.cjs +2 -1
- package/dist/dynamic-input.cjs.map +1 -1
- package/dist/dynamic-input.d.cts +9 -2
- package/dist/dynamic-input.d.ts +9 -2
- package/dist/dynamic-input.js +2 -1
- package/dist/dynamic-input.js.map +1 -1
- package/dist/index.cjs +1094 -321
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +479 -19
- package/dist/index.d.ts +479 -19
- package/dist/index.js +1083 -322
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +84 -10
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +138 -13
- package/dist/ir.d.ts +138 -13
- package/dist/ir.js +81 -11
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +78 -9
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.d.cts +1 -1
- package/dist/predicate-v2.d.ts +1 -1
- package/dist/predicate-v2.js +78 -9
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +156 -21
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.d.cts +8 -1
- package/dist/sdl.d.ts +8 -1
- package/dist/sdl.js +156 -21
- package/dist/sdl.js.map +1 -1
- package/package.json +5 -4
- package/src/codegen-gql/server-fns.cjs +2 -2
- package/templates/orm-namespace/AGENTS.md +10 -0
- package/templates/orm-namespace/CLAUDE.md +1 -84
- package/templates/orm-namespace/package.json +1 -1
package/dist/ir.js
CHANGED
|
@@ -203,6 +203,7 @@ function compileCheckExpression(source, columns) {
|
|
|
203
203
|
// src/constants.ts
|
|
204
204
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
205
205
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
206
|
+
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
206
207
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
207
208
|
var CELL_PART_SUFFIX = {
|
|
208
209
|
at: "__at",
|
|
@@ -535,6 +536,8 @@ var canonicalLinkSchema = z.object({
|
|
|
535
536
|
kind: z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
536
537
|
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
537
538
|
target: identifier2.optional(),
|
|
539
|
+
/** Owning namespace of an imported target; omitted for local links. */
|
|
540
|
+
namespace: identifier2.max(41).optional(),
|
|
538
541
|
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
539
542
|
on: columnIdentifier,
|
|
540
543
|
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
@@ -636,11 +639,12 @@ var canonicalForeignKeySchema = z.object({
|
|
|
636
639
|
}).strict();
|
|
637
640
|
var canonicalTableSchema = z.object({
|
|
638
641
|
table: identifier2,
|
|
642
|
+
displayName: z.string().trim().min(1).max(120).optional(),
|
|
639
643
|
description: z.string().max(2e3).optional(),
|
|
640
644
|
/** Table-level rename hint (new in v2). */
|
|
641
645
|
renamedFrom: identifier2.optional(),
|
|
642
|
-
/** Synced/reflected read-only tables (`source:
|
|
643
|
-
source: z.string().regex(
|
|
646
|
+
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
647
|
+
source: z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
644
648
|
columns: z.array(canonicalColumnSchema).default([]),
|
|
645
649
|
primaryKey: z.array(columnIdentifier).min(1).max(8).optional(),
|
|
646
650
|
links: z.array(canonicalLinkSchema).default([]),
|
|
@@ -793,7 +797,9 @@ function validateCellMetadata(table, index, ctx) {
|
|
|
793
797
|
}
|
|
794
798
|
}
|
|
795
799
|
}
|
|
796
|
-
z.object({
|
|
800
|
+
var exportGateSchema = z.union([z.literal(true), z.object({ capability: z.string().min(1) }).strict(), z.object({ role: z.string().min(1) }).strict()]);
|
|
801
|
+
var relationExportSchema = z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
802
|
+
var localDefinitionSchema = z.object({
|
|
797
803
|
definition_format: z.literal(CANONICAL_FORMAT),
|
|
798
804
|
namespace: identifier2.max(41),
|
|
799
805
|
description: z.string().max(2e3).optional(),
|
|
@@ -801,6 +807,8 @@ z.object({
|
|
|
801
807
|
tables: z.array(canonicalTableSchema).min(0).max(500),
|
|
802
808
|
/** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
|
|
803
809
|
views: z.array(canonicalViewSchema).max(500).optional(),
|
|
810
|
+
/** Target-owned cross-namespace access contract, using existing namespace grants. */
|
|
811
|
+
exports: z.record(identifier2, relationExportSchema).optional(),
|
|
804
812
|
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
805
813
|
capabilities: z.object({
|
|
806
814
|
roles: z.unknown().optional(),
|
|
@@ -827,7 +835,16 @@ z.object({
|
|
|
827
835
|
}
|
|
828
836
|
}
|
|
829
837
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
838
|
+
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
839
|
+
for (const name of Object.keys(definition.exports ?? {})) {
|
|
840
|
+
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
841
|
+
}
|
|
830
842
|
for (const [tableIndex, table] of definition.tables.entries()) {
|
|
843
|
+
for (const [linkIndex, link] of table.links.entries()) {
|
|
844
|
+
if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
|
|
845
|
+
ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
|
|
846
|
+
}
|
|
847
|
+
}
|
|
831
848
|
const names = /* @__PURE__ */ new Set([
|
|
832
849
|
...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
|
|
833
850
|
...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
|
|
@@ -997,11 +1014,19 @@ z.object({
|
|
|
997
1014
|
};
|
|
998
1015
|
for (const view of views) visit(view.view, []);
|
|
999
1016
|
});
|
|
1017
|
+
localDefinitionSchema.safeExtend({
|
|
1018
|
+
/** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
|
|
1019
|
+
imports: z.array(localDefinitionSchema).max(32).optional()
|
|
1020
|
+
});
|
|
1000
1021
|
|
|
1001
1022
|
// src/ir/index.ts
|
|
1002
|
-
var IR_VERSION =
|
|
1023
|
+
var IR_VERSION = 5;
|
|
1003
1024
|
var LEGACY_IR_VERSION = 1;
|
|
1004
|
-
var
|
|
1025
|
+
var GUARDED_IR_VERSION = 2;
|
|
1026
|
+
var COMPOSED_IR_VERSION = 3;
|
|
1027
|
+
var SQL_IR_VERSION = 4;
|
|
1028
|
+
var RUNTIME_SQL_IR_VERSION = 5;
|
|
1029
|
+
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)]);
|
|
1005
1030
|
var operationVersionSchema = z.object({ irVersion: irVersionSchema });
|
|
1006
1031
|
function requiredArtifactIrVersion(operations) {
|
|
1007
1032
|
let required = LEGACY_IR_VERSION;
|
|
@@ -1053,8 +1078,8 @@ var predIrSchema = z.lazy(
|
|
|
1053
1078
|
value: z.number(),
|
|
1054
1079
|
where: predIrSchema.optional()
|
|
1055
1080
|
}),
|
|
1056
|
-
z.object({ kind: z.literal("capability"), key: z.string() }),
|
|
1057
|
-
z.object({ kind: z.literal("role"), key: z.string() }),
|
|
1081
|
+
z.object({ kind: z.literal("capability"), key: z.string(), namespace: z.string().optional() }),
|
|
1082
|
+
z.object({ kind: z.literal("role"), key: z.string(), namespace: z.string().optional() }),
|
|
1058
1083
|
z.object({ kind: z.literal("dynamicFilter"), slot: z.string() }),
|
|
1059
1084
|
z.object({ kind: z.literal("const"), value: z.boolean() })
|
|
1060
1085
|
])
|
|
@@ -1281,7 +1306,31 @@ var variableIrSchema = z.object({
|
|
|
1281
1306
|
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
1282
1307
|
defaultValue: variableDefaultIrSchema.optional()
|
|
1283
1308
|
});
|
|
1309
|
+
var sqlColumnSchema = z.object({ name: z.string(), type: z.enum(["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz"]), nullable: z.boolean() });
|
|
1284
1310
|
var compiledOperationSchema = z.object({
|
|
1311
|
+
language: z.literal("sql").optional(),
|
|
1312
|
+
/** Server-compiled object catalog and permission ceiling, never caller SQL. */
|
|
1313
|
+
sqlQuery: z.object({
|
|
1314
|
+
catalog: z.object({
|
|
1315
|
+
identity: z.string(),
|
|
1316
|
+
objects: z.array(z.object({
|
|
1317
|
+
ref: z.string(),
|
|
1318
|
+
table: z.string(),
|
|
1319
|
+
columns: z.array(sqlColumnSchema.extend({ type: z.string() })).min(1),
|
|
1320
|
+
scan: z.string().min(1),
|
|
1321
|
+
read: z.array(z.string()).min(1)
|
|
1322
|
+
}).strict()).min(1).max(256)
|
|
1323
|
+
}).strict(),
|
|
1324
|
+
read: z.array(z.string()).min(1).max(256),
|
|
1325
|
+
maxRows: z.number().int().min(1).max(1e4)
|
|
1326
|
+
}).strict().optional(),
|
|
1327
|
+
sql: z.object({
|
|
1328
|
+
text: z.string().min(1).max(1048576),
|
|
1329
|
+
columns: z.array(sqlColumnSchema).min(1).max(256),
|
|
1330
|
+
parameters: z.array(z.string()).max(128),
|
|
1331
|
+
read: z.array(z.string()).min(1).max(256),
|
|
1332
|
+
maxRows: z.number().int().min(1).max(1e4)
|
|
1333
|
+
}).strict().optional(),
|
|
1285
1334
|
irVersion: irVersionSchema,
|
|
1286
1335
|
name: z.string(),
|
|
1287
1336
|
opHash: z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
@@ -1293,8 +1342,16 @@ var compiledOperationSchema = z.object({
|
|
|
1293
1342
|
variables: z.array(variableIrSchema),
|
|
1294
1343
|
/** Every table the op touches — data-token scoping + audit. */
|
|
1295
1344
|
tableSet: z.array(z.string()).min(1),
|
|
1296
|
-
roots: z.array(rootIrSchema)
|
|
1345
|
+
roots: z.array(rootIrSchema)
|
|
1297
1346
|
}).superRefine((operation, ctx) => {
|
|
1347
|
+
if (operation.language === "sql") {
|
|
1348
|
+
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1349
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
|
|
1350
|
+
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1351
|
+
}
|
|
1352
|
+
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
1353
|
+
ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
|
|
1354
|
+
}
|
|
1298
1355
|
for (const [index, root] of operation.roots.entries()) {
|
|
1299
1356
|
if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
|
|
1300
1357
|
if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
|
|
@@ -1341,11 +1398,16 @@ var resolvedMetaIrSchema = z.object({
|
|
|
1341
1398
|
});
|
|
1342
1399
|
var tableMetaIrSchema = z.object({
|
|
1343
1400
|
table: z.string(),
|
|
1401
|
+
namespace: z.string().optional(),
|
|
1402
|
+
dependencies: z.array(z.string()).optional(),
|
|
1403
|
+
foreignReferences: z.array(z.object({ column: z.string(), target: z.string(), targetColumn: z.string() })).optional(),
|
|
1404
|
+
exportRead: z.union([z.literal(true), z.object({ capability: z.string() }), z.object({ role: z.string() })]).optional(),
|
|
1405
|
+
exportWrite: z.union([z.literal(true), z.object({ capability: z.string() }), z.object({ role: z.string() })]).optional(),
|
|
1344
1406
|
schema: z.string(),
|
|
1345
1407
|
typename: z.string(),
|
|
1346
1408
|
/**
|
|
1347
1409
|
* True when statements over this relation evaluate a claims-gated synced
|
|
1348
|
-
* view: synced twins (`source:
|
|
1410
|
+
* view: synced twins (`source: schema.table`) materialize as views whose baked
|
|
1349
1411
|
* policy reads `current_setting('request.jwt.claims')`, and namespace views
|
|
1350
1412
|
* inherit the gate transitively through their declared dependencies. The
|
|
1351
1413
|
* executor must stamp that GUC (transaction-scoped) before any statement
|
|
@@ -1404,10 +1466,18 @@ var compiledArtifactSchema = z.object({
|
|
|
1404
1466
|
irVersion: irVersionSchema,
|
|
1405
1467
|
namespace: z.string(),
|
|
1406
1468
|
schemaHash: z.string(),
|
|
1469
|
+
ownSchemaHash: z.string().optional(),
|
|
1470
|
+
dependencies: z.record(z.string(), z.string()).optional(),
|
|
1471
|
+
readPolicies: z.record(z.string(), predIrSchema).optional(),
|
|
1407
1472
|
opsHash: z.string(),
|
|
1473
|
+
/** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
|
|
1474
|
+
unbackedTables: z.array(z.string()).optional(),
|
|
1408
1475
|
tables: z.record(z.string(), tableMetaIrSchema),
|
|
1409
1476
|
operations: z.record(z.string(), compiledOperationSchema)
|
|
1410
1477
|
}).superRefine((artifact, ctx) => {
|
|
1478
|
+
if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
|
|
1479
|
+
ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
|
|
1480
|
+
}
|
|
1411
1481
|
for (const [name, operation] of Object.entries(artifact.operations)) {
|
|
1412
1482
|
if (operation.irVersion > artifact.irVersion) {
|
|
1413
1483
|
ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });
|
|
@@ -1423,7 +1493,7 @@ var IrVersionError = class extends Error {
|
|
|
1423
1493
|
function normalizeIr(raw) {
|
|
1424
1494
|
if (!raw || typeof raw !== "object") throw new IrVersionError(void 0);
|
|
1425
1495
|
const version = raw.irVersion;
|
|
1426
|
-
if (version
|
|
1496
|
+
if (!irVersionSchema.safeParse(version).success) throw new IrVersionError(version);
|
|
1427
1497
|
return compiledArtifactSchema.parse(raw);
|
|
1428
1498
|
}
|
|
1429
1499
|
function indexByHash(artifact) {
|
|
@@ -1432,6 +1502,6 @@ function indexByHash(artifact) {
|
|
|
1432
1502
|
return map;
|
|
1433
1503
|
}
|
|
1434
1504
|
|
|
1435
|
-
export { CELLS_FIELD, CELL_PARTS, CLAIMS_CONTRACT, CMP_OPS, DATE_BUCKETS, INPUT_REF_KINDS, IR_VERSION, IrVersionError, LEGACY_IR_VERSION, cellColumnName, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, prefetchPlanIrSchema, requiredArtifactIrVersion, resolvedMetaIrSchema, resolvedSourceIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema };
|
|
1505
|
+
export { CELLS_FIELD, CELL_PARTS, CLAIMS_CONTRACT, CMP_OPS, COMPOSED_IR_VERSION, DATE_BUCKETS, GUARDED_IR_VERSION, INPUT_REF_KINDS, IR_VERSION, IrVersionError, LEGACY_IR_VERSION, RUNTIME_SQL_IR_VERSION, SQL_IR_VERSION, cellColumnName, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, prefetchPlanIrSchema, requiredArtifactIrVersion, resolvedMetaIrSchema, resolvedSourceIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema };
|
|
1436
1506
|
//# sourceMappingURL=ir.js.map
|
|
1437
1507
|
//# sourceMappingURL=ir.js.map
|