@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/predicate-v2.cjs
CHANGED
|
@@ -34,6 +34,7 @@ var PolicyCompileError = class extends Error {
|
|
|
34
34
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
35
35
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
36
36
|
var CAPABILITY_KEY_PATTERN = /^(?:org\/|app\/[a-z][a-z0-9-]{0,63}\/)?[a-z0-9-]{1,64}$/;
|
|
37
|
+
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
37
38
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
38
39
|
var CELL_PART_SUFFIX = {
|
|
39
40
|
at: "__at",
|
|
@@ -563,6 +564,8 @@ var canonicalLinkSchema = zod.z.object({
|
|
|
563
564
|
kind: zod.z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
564
565
|
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
565
566
|
target: identifier2.optional(),
|
|
567
|
+
/** Owning namespace of an imported target; omitted for local links. */
|
|
568
|
+
namespace: identifier2.max(41).optional(),
|
|
566
569
|
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
567
570
|
on: columnIdentifier,
|
|
568
571
|
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
@@ -664,11 +667,12 @@ var canonicalForeignKeySchema = zod.z.object({
|
|
|
664
667
|
}).strict();
|
|
665
668
|
var canonicalTableSchema = zod.z.object({
|
|
666
669
|
table: identifier2,
|
|
670
|
+
displayName: zod.z.string().trim().min(1).max(120).optional(),
|
|
667
671
|
description: zod.z.string().max(2e3).optional(),
|
|
668
672
|
/** Table-level rename hint (new in v2). */
|
|
669
673
|
renamedFrom: identifier2.optional(),
|
|
670
|
-
/** Synced/reflected read-only tables (`source:
|
|
671
|
-
source: zod.z.string().regex(
|
|
674
|
+
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
675
|
+
source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
672
676
|
columns: zod.z.array(canonicalColumnSchema).default([]),
|
|
673
677
|
primaryKey: zod.z.array(columnIdentifier).min(1).max(8).optional(),
|
|
674
678
|
links: zod.z.array(canonicalLinkSchema).default([]),
|
|
@@ -821,7 +825,9 @@ function validateCellMetadata(table, index, ctx) {
|
|
|
821
825
|
}
|
|
822
826
|
}
|
|
823
827
|
}
|
|
824
|
-
zod.z.object({
|
|
828
|
+
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()]);
|
|
829
|
+
var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
830
|
+
var localDefinitionSchema = zod.z.object({
|
|
825
831
|
definition_format: zod.z.literal(CANONICAL_FORMAT),
|
|
826
832
|
namespace: identifier2.max(41),
|
|
827
833
|
description: zod.z.string().max(2e3).optional(),
|
|
@@ -829,6 +835,8 @@ zod.z.object({
|
|
|
829
835
|
tables: zod.z.array(canonicalTableSchema).min(0).max(500),
|
|
830
836
|
/** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
|
|
831
837
|
views: zod.z.array(canonicalViewSchema).max(500).optional(),
|
|
838
|
+
/** Target-owned cross-namespace access contract, using existing namespace grants. */
|
|
839
|
+
exports: zod.z.record(identifier2, relationExportSchema).optional(),
|
|
832
840
|
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
833
841
|
capabilities: zod.z.object({
|
|
834
842
|
roles: zod.z.unknown().optional(),
|
|
@@ -855,7 +863,16 @@ zod.z.object({
|
|
|
855
863
|
}
|
|
856
864
|
}
|
|
857
865
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
866
|
+
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
867
|
+
for (const name of Object.keys(definition.exports ?? {})) {
|
|
868
|
+
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
869
|
+
}
|
|
858
870
|
for (const [tableIndex, table] of definition.tables.entries()) {
|
|
871
|
+
for (const [linkIndex, link] of table.links.entries()) {
|
|
872
|
+
if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
|
|
873
|
+
ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
|
|
874
|
+
}
|
|
875
|
+
}
|
|
859
876
|
const names = /* @__PURE__ */ new Set([
|
|
860
877
|
...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
|
|
861
878
|
...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
|
|
@@ -1025,11 +1042,18 @@ zod.z.object({
|
|
|
1025
1042
|
};
|
|
1026
1043
|
for (const view of views) visit(view.view, []);
|
|
1027
1044
|
});
|
|
1045
|
+
localDefinitionSchema.safeExtend({
|
|
1046
|
+
/** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
|
|
1047
|
+
imports: zod.z.array(localDefinitionSchema).max(32).optional()
|
|
1048
|
+
});
|
|
1028
1049
|
|
|
1029
1050
|
// src/ir/index.ts
|
|
1030
|
-
var IR_VERSION = 2;
|
|
1031
1051
|
var LEGACY_IR_VERSION = 1;
|
|
1032
|
-
var
|
|
1052
|
+
var GUARDED_IR_VERSION = 2;
|
|
1053
|
+
var COMPOSED_IR_VERSION = 3;
|
|
1054
|
+
var SQL_IR_VERSION = 4;
|
|
1055
|
+
var RUNTIME_SQL_IR_VERSION = 5;
|
|
1056
|
+
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)]);
|
|
1033
1057
|
zod.z.object({ irVersion: irVersionSchema });
|
|
1034
1058
|
var CLAIMS_CONTRACT = {
|
|
1035
1059
|
sub: "string",
|
|
@@ -1073,8 +1097,8 @@ var predIrSchema = zod.z.lazy(
|
|
|
1073
1097
|
value: zod.z.number(),
|
|
1074
1098
|
where: predIrSchema.optional()
|
|
1075
1099
|
}),
|
|
1076
|
-
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string() }),
|
|
1077
|
-
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string() }),
|
|
1100
|
+
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1101
|
+
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1078
1102
|
zod.z.object({ kind: zod.z.literal("dynamicFilter"), slot: zod.z.string() }),
|
|
1079
1103
|
zod.z.object({ kind: zod.z.literal("const"), value: zod.z.boolean() })
|
|
1080
1104
|
])
|
|
@@ -1301,7 +1325,31 @@ var variableIrSchema = zod.z.object({
|
|
|
1301
1325
|
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
1302
1326
|
defaultValue: variableDefaultIrSchema.optional()
|
|
1303
1327
|
});
|
|
1328
|
+
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() });
|
|
1304
1329
|
var compiledOperationSchema = zod.z.object({
|
|
1330
|
+
language: zod.z.literal("sql").optional(),
|
|
1331
|
+
/** Server-compiled object catalog and permission ceiling, never caller SQL. */
|
|
1332
|
+
sqlQuery: zod.z.object({
|
|
1333
|
+
catalog: zod.z.object({
|
|
1334
|
+
identity: zod.z.string(),
|
|
1335
|
+
objects: zod.z.array(zod.z.object({
|
|
1336
|
+
ref: zod.z.string(),
|
|
1337
|
+
table: zod.z.string(),
|
|
1338
|
+
columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
|
|
1339
|
+
scan: zod.z.string().min(1),
|
|
1340
|
+
read: zod.z.array(zod.z.string()).min(1)
|
|
1341
|
+
}).strict()).min(1).max(256)
|
|
1342
|
+
}).strict(),
|
|
1343
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1344
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1345
|
+
}).strict().optional(),
|
|
1346
|
+
sql: zod.z.object({
|
|
1347
|
+
text: zod.z.string().min(1).max(1048576),
|
|
1348
|
+
columns: zod.z.array(sqlColumnSchema).min(1).max(256),
|
|
1349
|
+
parameters: zod.z.array(zod.z.string()).max(128),
|
|
1350
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1351
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1352
|
+
}).strict().optional(),
|
|
1305
1353
|
irVersion: irVersionSchema,
|
|
1306
1354
|
name: zod.z.string(),
|
|
1307
1355
|
opHash: zod.z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
@@ -1313,8 +1361,16 @@ var compiledOperationSchema = zod.z.object({
|
|
|
1313
1361
|
variables: zod.z.array(variableIrSchema),
|
|
1314
1362
|
/** Every table the op touches — data-token scoping + audit. */
|
|
1315
1363
|
tableSet: zod.z.array(zod.z.string()).min(1),
|
|
1316
|
-
roots: zod.z.array(rootIrSchema)
|
|
1364
|
+
roots: zod.z.array(rootIrSchema)
|
|
1317
1365
|
}).superRefine((operation, ctx) => {
|
|
1366
|
+
if (operation.language === "sql") {
|
|
1367
|
+
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1368
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
|
|
1369
|
+
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1370
|
+
}
|
|
1371
|
+
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
1372
|
+
ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
|
|
1373
|
+
}
|
|
1318
1374
|
for (const [index, root] of operation.roots.entries()) {
|
|
1319
1375
|
if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
|
|
1320
1376
|
if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
|
|
@@ -1361,11 +1417,16 @@ var resolvedMetaIrSchema = zod.z.object({
|
|
|
1361
1417
|
});
|
|
1362
1418
|
var tableMetaIrSchema = zod.z.object({
|
|
1363
1419
|
table: zod.z.string(),
|
|
1420
|
+
namespace: zod.z.string().optional(),
|
|
1421
|
+
dependencies: zod.z.array(zod.z.string()).optional(),
|
|
1422
|
+
foreignReferences: zod.z.array(zod.z.object({ column: zod.z.string(), target: zod.z.string(), targetColumn: zod.z.string() })).optional(),
|
|
1423
|
+
exportRead: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1424
|
+
exportWrite: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1364
1425
|
schema: zod.z.string(),
|
|
1365
1426
|
typename: zod.z.string(),
|
|
1366
1427
|
/**
|
|
1367
1428
|
* True when statements over this relation evaluate a claims-gated synced
|
|
1368
|
-
* view: synced twins (`source:
|
|
1429
|
+
* view: synced twins (`source: schema.table`) materialize as views whose baked
|
|
1369
1430
|
* policy reads `current_setting('request.jwt.claims')`, and namespace views
|
|
1370
1431
|
* inherit the gate transitively through their declared dependencies. The
|
|
1371
1432
|
* executor must stamp that GUC (transaction-scoped) before any statement
|
|
@@ -1424,10 +1485,18 @@ zod.z.object({
|
|
|
1424
1485
|
irVersion: irVersionSchema,
|
|
1425
1486
|
namespace: zod.z.string(),
|
|
1426
1487
|
schemaHash: zod.z.string(),
|
|
1488
|
+
ownSchemaHash: zod.z.string().optional(),
|
|
1489
|
+
dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1490
|
+
readPolicies: zod.z.record(zod.z.string(), predIrSchema).optional(),
|
|
1427
1491
|
opsHash: zod.z.string(),
|
|
1492
|
+
/** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
|
|
1493
|
+
unbackedTables: zod.z.array(zod.z.string()).optional(),
|
|
1428
1494
|
tables: zod.z.record(zod.z.string(), tableMetaIrSchema),
|
|
1429
1495
|
operations: zod.z.record(zod.z.string(), compiledOperationSchema)
|
|
1430
1496
|
}).superRefine((artifact, ctx) => {
|
|
1497
|
+
if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
|
|
1498
|
+
ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
|
|
1499
|
+
}
|
|
1431
1500
|
for (const [name, operation] of Object.entries(artifact.operations)) {
|
|
1432
1501
|
if (operation.irVersion > artifact.irVersion) {
|
|
1433
1502
|
ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });
|