@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.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;
|
|
@@ -1055,8 +1080,8 @@ var predIrSchema = zod.z.lazy(
|
|
|
1055
1080
|
value: zod.z.number(),
|
|
1056
1081
|
where: predIrSchema.optional()
|
|
1057
1082
|
}),
|
|
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() }),
|
|
1083
|
+
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1084
|
+
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1060
1085
|
zod.z.object({ kind: zod.z.literal("dynamicFilter"), slot: zod.z.string() }),
|
|
1061
1086
|
zod.z.object({ kind: zod.z.literal("const"), value: zod.z.boolean() })
|
|
1062
1087
|
])
|
|
@@ -1283,7 +1308,31 @@ var variableIrSchema = zod.z.object({
|
|
|
1283
1308
|
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
1284
1309
|
defaultValue: variableDefaultIrSchema.optional()
|
|
1285
1310
|
});
|
|
1311
|
+
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
1312
|
var compiledOperationSchema = zod.z.object({
|
|
1313
|
+
language: zod.z.literal("sql").optional(),
|
|
1314
|
+
/** Server-compiled object catalog and permission ceiling, never caller SQL. */
|
|
1315
|
+
sqlQuery: zod.z.object({
|
|
1316
|
+
catalog: zod.z.object({
|
|
1317
|
+
identity: zod.z.string(),
|
|
1318
|
+
objects: zod.z.array(zod.z.object({
|
|
1319
|
+
ref: zod.z.string(),
|
|
1320
|
+
table: zod.z.string(),
|
|
1321
|
+
columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
|
|
1322
|
+
scan: zod.z.string().min(1),
|
|
1323
|
+
read: zod.z.array(zod.z.string()).min(1)
|
|
1324
|
+
}).strict()).min(1).max(256)
|
|
1325
|
+
}).strict(),
|
|
1326
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1327
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1328
|
+
}).strict().optional(),
|
|
1329
|
+
sql: zod.z.object({
|
|
1330
|
+
text: zod.z.string().min(1).max(1048576),
|
|
1331
|
+
columns: zod.z.array(sqlColumnSchema).min(1).max(256),
|
|
1332
|
+
parameters: zod.z.array(zod.z.string()).max(128),
|
|
1333
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1334
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1335
|
+
}).strict().optional(),
|
|
1287
1336
|
irVersion: irVersionSchema,
|
|
1288
1337
|
name: zod.z.string(),
|
|
1289
1338
|
opHash: zod.z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
@@ -1295,8 +1344,16 @@ var compiledOperationSchema = zod.z.object({
|
|
|
1295
1344
|
variables: zod.z.array(variableIrSchema),
|
|
1296
1345
|
/** Every table the op touches — data-token scoping + audit. */
|
|
1297
1346
|
tableSet: zod.z.array(zod.z.string()).min(1),
|
|
1298
|
-
roots: zod.z.array(rootIrSchema)
|
|
1347
|
+
roots: zod.z.array(rootIrSchema)
|
|
1299
1348
|
}).superRefine((operation, ctx) => {
|
|
1349
|
+
if (operation.language === "sql") {
|
|
1350
|
+
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1351
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
|
|
1352
|
+
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1353
|
+
}
|
|
1354
|
+
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
1355
|
+
ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
|
|
1356
|
+
}
|
|
1300
1357
|
for (const [index, root] of operation.roots.entries()) {
|
|
1301
1358
|
if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
|
|
1302
1359
|
if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
|
|
@@ -1343,11 +1400,16 @@ var resolvedMetaIrSchema = zod.z.object({
|
|
|
1343
1400
|
});
|
|
1344
1401
|
var tableMetaIrSchema = zod.z.object({
|
|
1345
1402
|
table: zod.z.string(),
|
|
1403
|
+
namespace: zod.z.string().optional(),
|
|
1404
|
+
dependencies: zod.z.array(zod.z.string()).optional(),
|
|
1405
|
+
foreignReferences: zod.z.array(zod.z.object({ column: zod.z.string(), target: zod.z.string(), targetColumn: zod.z.string() })).optional(),
|
|
1406
|
+
exportRead: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1407
|
+
exportWrite: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1346
1408
|
schema: zod.z.string(),
|
|
1347
1409
|
typename: zod.z.string(),
|
|
1348
1410
|
/**
|
|
1349
1411
|
* True when statements over this relation evaluate a claims-gated synced
|
|
1350
|
-
* view: synced twins (`source:
|
|
1412
|
+
* view: synced twins (`source: schema.table`) materialize as views whose baked
|
|
1351
1413
|
* policy reads `current_setting('request.jwt.claims')`, and namespace views
|
|
1352
1414
|
* inherit the gate transitively through their declared dependencies. The
|
|
1353
1415
|
* executor must stamp that GUC (transaction-scoped) before any statement
|
|
@@ -1406,10 +1468,18 @@ var compiledArtifactSchema = zod.z.object({
|
|
|
1406
1468
|
irVersion: irVersionSchema,
|
|
1407
1469
|
namespace: zod.z.string(),
|
|
1408
1470
|
schemaHash: zod.z.string(),
|
|
1471
|
+
ownSchemaHash: zod.z.string().optional(),
|
|
1472
|
+
dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1473
|
+
readPolicies: zod.z.record(zod.z.string(), predIrSchema).optional(),
|
|
1409
1474
|
opsHash: zod.z.string(),
|
|
1475
|
+
/** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
|
|
1476
|
+
unbackedTables: zod.z.array(zod.z.string()).optional(),
|
|
1410
1477
|
tables: zod.z.record(zod.z.string(), tableMetaIrSchema),
|
|
1411
1478
|
operations: zod.z.record(zod.z.string(), compiledOperationSchema)
|
|
1412
1479
|
}).superRefine((artifact, ctx) => {
|
|
1480
|
+
if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
|
|
1481
|
+
ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
|
|
1482
|
+
}
|
|
1413
1483
|
for (const [name, operation] of Object.entries(artifact.operations)) {
|
|
1414
1484
|
if (operation.irVersion > artifact.irVersion) {
|
|
1415
1485
|
ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });
|
|
@@ -1425,7 +1495,7 @@ var IrVersionError = class extends Error {
|
|
|
1425
1495
|
function normalizeIr(raw) {
|
|
1426
1496
|
if (!raw || typeof raw !== "object") throw new IrVersionError(void 0);
|
|
1427
1497
|
const version = raw.irVersion;
|
|
1428
|
-
if (version
|
|
1498
|
+
if (!irVersionSchema.safeParse(version).success) throw new IrVersionError(version);
|
|
1429
1499
|
return compiledArtifactSchema.parse(raw);
|
|
1430
1500
|
}
|
|
1431
1501
|
function indexByHash(artifact) {
|
|
@@ -1438,11 +1508,15 @@ exports.CELLS_FIELD = CELLS_FIELD;
|
|
|
1438
1508
|
exports.CELL_PARTS = CELL_PARTS;
|
|
1439
1509
|
exports.CLAIMS_CONTRACT = CLAIMS_CONTRACT;
|
|
1440
1510
|
exports.CMP_OPS = CMP_OPS;
|
|
1511
|
+
exports.COMPOSED_IR_VERSION = COMPOSED_IR_VERSION;
|
|
1441
1512
|
exports.DATE_BUCKETS = DATE_BUCKETS;
|
|
1513
|
+
exports.GUARDED_IR_VERSION = GUARDED_IR_VERSION;
|
|
1442
1514
|
exports.INPUT_REF_KINDS = INPUT_REF_KINDS;
|
|
1443
1515
|
exports.IR_VERSION = IR_VERSION;
|
|
1444
1516
|
exports.IrVersionError = IrVersionError;
|
|
1445
1517
|
exports.LEGACY_IR_VERSION = LEGACY_IR_VERSION;
|
|
1518
|
+
exports.RUNTIME_SQL_IR_VERSION = RUNTIME_SQL_IR_VERSION;
|
|
1519
|
+
exports.SQL_IR_VERSION = SQL_IR_VERSION;
|
|
1446
1520
|
exports.cellColumnName = cellColumnName;
|
|
1447
1521
|
exports.compiledArtifactSchema = compiledArtifactSchema;
|
|
1448
1522
|
exports.compiledOperationSchema = compiledOperationSchema;
|