@sequenceholdings/orm 2.1.1 → 2.3.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 +5876 -4198
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +5876 -4198
- 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 +1275 -264
- 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 +1268 -265
- 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 +1103 -322
- 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 +1090 -323
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +93 -11
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +226 -15
- package/dist/ir.d.ts +226 -15
- package/dist/ir.js +88 -12
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +116 -10
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.d.cts +11 -3
- package/dist/predicate-v2.d.ts +11 -3
- package/dist/predicate-v2.js +116 -10
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +158 -22
- 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 +158 -22
- 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.cjs
CHANGED
|
@@ -205,6 +205,7 @@ function compileCheckExpression(source, columns) {
|
|
|
205
205
|
// src/constants.ts
|
|
206
206
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
207
207
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
208
|
+
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
208
209
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
209
210
|
var CELL_PART_SUFFIX = {
|
|
210
211
|
at: "__at",
|
|
@@ -537,6 +538,8 @@ var canonicalLinkSchema = zod.z.object({
|
|
|
537
538
|
kind: zod.z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
538
539
|
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
539
540
|
target: identifier2.optional(),
|
|
541
|
+
/** Owning namespace of an imported target; omitted for local links. */
|
|
542
|
+
namespace: identifier2.max(41).optional(),
|
|
540
543
|
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
541
544
|
on: columnIdentifier,
|
|
542
545
|
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
@@ -638,11 +641,12 @@ var canonicalForeignKeySchema = zod.z.object({
|
|
|
638
641
|
}).strict();
|
|
639
642
|
var canonicalTableSchema = zod.z.object({
|
|
640
643
|
table: identifier2,
|
|
644
|
+
displayName: zod.z.string().trim().min(1).max(120).optional(),
|
|
641
645
|
description: zod.z.string().max(2e3).optional(),
|
|
642
646
|
/** Table-level rename hint (new in v2). */
|
|
643
647
|
renamedFrom: identifier2.optional(),
|
|
644
|
-
/** Synced/reflected read-only tables (`source:
|
|
645
|
-
source: zod.z.string().regex(
|
|
648
|
+
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
649
|
+
source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
646
650
|
columns: zod.z.array(canonicalColumnSchema).default([]),
|
|
647
651
|
primaryKey: zod.z.array(columnIdentifier).min(1).max(8).optional(),
|
|
648
652
|
links: zod.z.array(canonicalLinkSchema).default([]),
|
|
@@ -795,7 +799,9 @@ function validateCellMetadata(table, index, ctx) {
|
|
|
795
799
|
}
|
|
796
800
|
}
|
|
797
801
|
}
|
|
798
|
-
zod.z.object({
|
|
802
|
+
var exportGateSchema = zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string().min(1) }).strict(), zod.z.object({ role: zod.z.string().min(1) }).strict()]);
|
|
803
|
+
var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
804
|
+
var localDefinitionSchema = zod.z.object({
|
|
799
805
|
definition_format: zod.z.literal(CANONICAL_FORMAT),
|
|
800
806
|
namespace: identifier2.max(41),
|
|
801
807
|
description: zod.z.string().max(2e3).optional(),
|
|
@@ -803,6 +809,8 @@ zod.z.object({
|
|
|
803
809
|
tables: zod.z.array(canonicalTableSchema).min(0).max(500),
|
|
804
810
|
/** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
|
|
805
811
|
views: zod.z.array(canonicalViewSchema).max(500).optional(),
|
|
812
|
+
/** Target-owned cross-namespace access contract, using existing namespace grants. */
|
|
813
|
+
exports: zod.z.record(identifier2, relationExportSchema).optional(),
|
|
806
814
|
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
807
815
|
capabilities: zod.z.object({
|
|
808
816
|
roles: zod.z.unknown().optional(),
|
|
@@ -829,7 +837,16 @@ zod.z.object({
|
|
|
829
837
|
}
|
|
830
838
|
}
|
|
831
839
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
840
|
+
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
841
|
+
for (const name of Object.keys(definition.exports ?? {})) {
|
|
842
|
+
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
843
|
+
}
|
|
832
844
|
for (const [tableIndex, table] of definition.tables.entries()) {
|
|
845
|
+
for (const [linkIndex, link] of table.links.entries()) {
|
|
846
|
+
if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
|
|
847
|
+
ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
|
|
848
|
+
}
|
|
849
|
+
}
|
|
833
850
|
const names = /* @__PURE__ */ new Set([
|
|
834
851
|
...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
|
|
835
852
|
...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
|
|
@@ -999,11 +1016,19 @@ zod.z.object({
|
|
|
999
1016
|
};
|
|
1000
1017
|
for (const view of views) visit(view.view, []);
|
|
1001
1018
|
});
|
|
1019
|
+
localDefinitionSchema.safeExtend({
|
|
1020
|
+
/** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
|
|
1021
|
+
imports: zod.z.array(localDefinitionSchema).max(32).optional()
|
|
1022
|
+
});
|
|
1002
1023
|
|
|
1003
1024
|
// src/ir/index.ts
|
|
1004
|
-
var IR_VERSION =
|
|
1025
|
+
var IR_VERSION = 5;
|
|
1005
1026
|
var LEGACY_IR_VERSION = 1;
|
|
1006
|
-
var
|
|
1027
|
+
var GUARDED_IR_VERSION = 2;
|
|
1028
|
+
var COMPOSED_IR_VERSION = 3;
|
|
1029
|
+
var SQL_IR_VERSION = 4;
|
|
1030
|
+
var RUNTIME_SQL_IR_VERSION = 5;
|
|
1031
|
+
var irVersionSchema = zod.z.union([zod.z.literal(LEGACY_IR_VERSION), zod.z.literal(GUARDED_IR_VERSION), zod.z.literal(COMPOSED_IR_VERSION), zod.z.literal(SQL_IR_VERSION), zod.z.literal(RUNTIME_SQL_IR_VERSION)]);
|
|
1007
1032
|
var operationVersionSchema = zod.z.object({ irVersion: irVersionSchema });
|
|
1008
1033
|
function requiredArtifactIrVersion(operations) {
|
|
1009
1034
|
let required = LEGACY_IR_VERSION;
|
|
@@ -1016,14 +1041,20 @@ function requiredArtifactIrVersion(operations) {
|
|
|
1016
1041
|
var CLAIMS_CONTRACT = {
|
|
1017
1042
|
sub: "string",
|
|
1018
1043
|
org: "string?",
|
|
1044
|
+
ext_subject: "string?",
|
|
1045
|
+
ext_email: "string?",
|
|
1019
1046
|
roles: "string[]",
|
|
1020
1047
|
capabilities: "string[]"
|
|
1021
1048
|
};
|
|
1049
|
+
var EXTERNAL_POLICY_CLAIM_KEYS = ["ext_subject", "ext_email"];
|
|
1050
|
+
function isExternalPolicyClaimKey(key) {
|
|
1051
|
+
return EXTERNAL_POLICY_CLAIM_KEYS.includes(key);
|
|
1052
|
+
}
|
|
1022
1053
|
var scalarLiteral = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]);
|
|
1023
1054
|
var valueIrSchema = zod.z.discriminatedUnion("kind", [
|
|
1024
1055
|
zod.z.object({ kind: zod.z.literal("literal"), value: zod.z.union([scalarLiteral, zod.z.array(scalarLiteral)]) }),
|
|
1025
1056
|
zod.z.object({ kind: zod.z.literal("variable"), name: zod.z.string() }),
|
|
1026
|
-
zod.z.object({ kind: zod.z.literal("claim"), key: zod.z.enum(["sub", "org"]) })
|
|
1057
|
+
zod.z.object({ kind: zod.z.literal("claim"), key: zod.z.enum(["sub", "org", ...EXTERNAL_POLICY_CLAIM_KEYS]) })
|
|
1027
1058
|
]);
|
|
1028
1059
|
var CMP_OPS = [
|
|
1029
1060
|
"eq",
|
|
@@ -1055,8 +1086,8 @@ var predIrSchema = zod.z.lazy(
|
|
|
1055
1086
|
value: zod.z.number(),
|
|
1056
1087
|
where: predIrSchema.optional()
|
|
1057
1088
|
}),
|
|
1058
|
-
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string() }),
|
|
1059
|
-
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string() }),
|
|
1089
|
+
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1090
|
+
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1060
1091
|
zod.z.object({ kind: zod.z.literal("dynamicFilter"), slot: zod.z.string() }),
|
|
1061
1092
|
zod.z.object({ kind: zod.z.literal("const"), value: zod.z.boolean() })
|
|
1062
1093
|
])
|
|
@@ -1283,7 +1314,31 @@ var variableIrSchema = zod.z.object({
|
|
|
1283
1314
|
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
1284
1315
|
defaultValue: variableDefaultIrSchema.optional()
|
|
1285
1316
|
});
|
|
1317
|
+
var sqlColumnSchema = zod.z.object({ name: zod.z.string(), type: zod.z.enum(["text", "boolean", "integer", "bigint", "numeric", "double", "uuid", "date", "timestamptz"]), nullable: zod.z.boolean() });
|
|
1286
1318
|
var compiledOperationSchema = zod.z.object({
|
|
1319
|
+
language: zod.z.literal("sql").optional(),
|
|
1320
|
+
/** Server-compiled object catalog and permission ceiling, never caller SQL. */
|
|
1321
|
+
sqlQuery: zod.z.object({
|
|
1322
|
+
catalog: zod.z.object({
|
|
1323
|
+
identity: zod.z.string(),
|
|
1324
|
+
objects: zod.z.array(zod.z.object({
|
|
1325
|
+
ref: zod.z.string(),
|
|
1326
|
+
table: zod.z.string(),
|
|
1327
|
+
columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
|
|
1328
|
+
scan: zod.z.string().min(1),
|
|
1329
|
+
read: zod.z.array(zod.z.string()).min(1)
|
|
1330
|
+
}).strict()).min(1).max(256)
|
|
1331
|
+
}).strict(),
|
|
1332
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1333
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1334
|
+
}).strict().optional(),
|
|
1335
|
+
sql: zod.z.object({
|
|
1336
|
+
text: zod.z.string().min(1).max(1048576),
|
|
1337
|
+
columns: zod.z.array(sqlColumnSchema).min(1).max(256),
|
|
1338
|
+
parameters: zod.z.array(zod.z.string()).max(128),
|
|
1339
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1340
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1341
|
+
}).strict().optional(),
|
|
1287
1342
|
irVersion: irVersionSchema,
|
|
1288
1343
|
name: zod.z.string(),
|
|
1289
1344
|
opHash: zod.z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
@@ -1295,8 +1350,16 @@ var compiledOperationSchema = zod.z.object({
|
|
|
1295
1350
|
variables: zod.z.array(variableIrSchema),
|
|
1296
1351
|
/** Every table the op touches — data-token scoping + audit. */
|
|
1297
1352
|
tableSet: zod.z.array(zod.z.string()).min(1),
|
|
1298
|
-
roots: zod.z.array(rootIrSchema)
|
|
1353
|
+
roots: zod.z.array(rootIrSchema)
|
|
1299
1354
|
}).superRefine((operation, ctx) => {
|
|
1355
|
+
if (operation.language === "sql") {
|
|
1356
|
+
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) {
|
|
1358
|
+
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1359
|
+
}
|
|
1360
|
+
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
1361
|
+
ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
|
|
1362
|
+
}
|
|
1300
1363
|
for (const [index, root] of operation.roots.entries()) {
|
|
1301
1364
|
if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
|
|
1302
1365
|
if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
|
|
@@ -1343,11 +1406,16 @@ var resolvedMetaIrSchema = zod.z.object({
|
|
|
1343
1406
|
});
|
|
1344
1407
|
var tableMetaIrSchema = zod.z.object({
|
|
1345
1408
|
table: zod.z.string(),
|
|
1409
|
+
namespace: zod.z.string().optional(),
|
|
1410
|
+
dependencies: zod.z.array(zod.z.string()).optional(),
|
|
1411
|
+
foreignReferences: zod.z.array(zod.z.object({ column: zod.z.string(), target: zod.z.string(), targetColumn: zod.z.string() })).optional(),
|
|
1412
|
+
exportRead: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1413
|
+
exportWrite: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1346
1414
|
schema: zod.z.string(),
|
|
1347
1415
|
typename: zod.z.string(),
|
|
1348
1416
|
/**
|
|
1349
1417
|
* True when statements over this relation evaluate a claims-gated synced
|
|
1350
|
-
* view: synced twins (`source:
|
|
1418
|
+
* view: synced twins (`source: schema.table`) materialize as views whose baked
|
|
1351
1419
|
* policy reads `current_setting('request.jwt.claims')`, and namespace views
|
|
1352
1420
|
* inherit the gate transitively through their declared dependencies. The
|
|
1353
1421
|
* executor must stamp that GUC (transaction-scoped) before any statement
|
|
@@ -1406,10 +1474,18 @@ var compiledArtifactSchema = zod.z.object({
|
|
|
1406
1474
|
irVersion: irVersionSchema,
|
|
1407
1475
|
namespace: zod.z.string(),
|
|
1408
1476
|
schemaHash: zod.z.string(),
|
|
1477
|
+
ownSchemaHash: zod.z.string().optional(),
|
|
1478
|
+
dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1479
|
+
readPolicies: zod.z.record(zod.z.string(), predIrSchema).optional(),
|
|
1409
1480
|
opsHash: zod.z.string(),
|
|
1481
|
+
/** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
|
|
1482
|
+
unbackedTables: zod.z.array(zod.z.string()).optional(),
|
|
1410
1483
|
tables: zod.z.record(zod.z.string(), tableMetaIrSchema),
|
|
1411
1484
|
operations: zod.z.record(zod.z.string(), compiledOperationSchema)
|
|
1412
1485
|
}).superRefine((artifact, ctx) => {
|
|
1486
|
+
if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
|
|
1487
|
+
ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
|
|
1488
|
+
}
|
|
1413
1489
|
for (const [name, operation] of Object.entries(artifact.operations)) {
|
|
1414
1490
|
if (operation.irVersion > artifact.irVersion) {
|
|
1415
1491
|
ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });
|
|
@@ -1425,7 +1501,7 @@ var IrVersionError = class extends Error {
|
|
|
1425
1501
|
function normalizeIr(raw) {
|
|
1426
1502
|
if (!raw || typeof raw !== "object") throw new IrVersionError(void 0);
|
|
1427
1503
|
const version = raw.irVersion;
|
|
1428
|
-
if (version
|
|
1504
|
+
if (!irVersionSchema.safeParse(version).success) throw new IrVersionError(version);
|
|
1429
1505
|
return compiledArtifactSchema.parse(raw);
|
|
1430
1506
|
}
|
|
1431
1507
|
function indexByHash(artifact) {
|
|
@@ -1438,15 +1514,21 @@ exports.CELLS_FIELD = CELLS_FIELD;
|
|
|
1438
1514
|
exports.CELL_PARTS = CELL_PARTS;
|
|
1439
1515
|
exports.CLAIMS_CONTRACT = CLAIMS_CONTRACT;
|
|
1440
1516
|
exports.CMP_OPS = CMP_OPS;
|
|
1517
|
+
exports.COMPOSED_IR_VERSION = COMPOSED_IR_VERSION;
|
|
1441
1518
|
exports.DATE_BUCKETS = DATE_BUCKETS;
|
|
1519
|
+
exports.EXTERNAL_POLICY_CLAIM_KEYS = EXTERNAL_POLICY_CLAIM_KEYS;
|
|
1520
|
+
exports.GUARDED_IR_VERSION = GUARDED_IR_VERSION;
|
|
1442
1521
|
exports.INPUT_REF_KINDS = INPUT_REF_KINDS;
|
|
1443
1522
|
exports.IR_VERSION = IR_VERSION;
|
|
1444
1523
|
exports.IrVersionError = IrVersionError;
|
|
1445
1524
|
exports.LEGACY_IR_VERSION = LEGACY_IR_VERSION;
|
|
1525
|
+
exports.RUNTIME_SQL_IR_VERSION = RUNTIME_SQL_IR_VERSION;
|
|
1526
|
+
exports.SQL_IR_VERSION = SQL_IR_VERSION;
|
|
1446
1527
|
exports.cellColumnName = cellColumnName;
|
|
1447
1528
|
exports.compiledArtifactSchema = compiledArtifactSchema;
|
|
1448
1529
|
exports.compiledOperationSchema = compiledOperationSchema;
|
|
1449
1530
|
exports.indexByHash = indexByHash;
|
|
1531
|
+
exports.isExternalPolicyClaimKey = isExternalPolicyClaimKey;
|
|
1450
1532
|
exports.limitIrSchema = limitIrSchema;
|
|
1451
1533
|
exports.normalizeIr = normalizeIr;
|
|
1452
1534
|
exports.orderIrSchema = orderIrSchema;
|