@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/sdl.cjs
CHANGED
|
@@ -206,6 +206,7 @@ function compileCheckExpression(source, columns) {
|
|
|
206
206
|
// src/constants.ts
|
|
207
207
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
208
208
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
209
|
+
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
209
210
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
210
211
|
var CELL_PART_SUFFIX = {
|
|
211
212
|
at: "__at",
|
|
@@ -538,6 +539,8 @@ var canonicalLinkSchema = zod.z.object({
|
|
|
538
539
|
kind: zod.z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
539
540
|
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
540
541
|
target: identifier2.optional(),
|
|
542
|
+
/** Owning namespace of an imported target; omitted for local links. */
|
|
543
|
+
namespace: identifier2.max(41).optional(),
|
|
541
544
|
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
542
545
|
on: columnIdentifier,
|
|
543
546
|
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
@@ -639,11 +642,12 @@ var canonicalForeignKeySchema = zod.z.object({
|
|
|
639
642
|
}).strict();
|
|
640
643
|
var canonicalTableSchema = zod.z.object({
|
|
641
644
|
table: identifier2,
|
|
645
|
+
displayName: zod.z.string().trim().min(1).max(120).optional(),
|
|
642
646
|
description: zod.z.string().max(2e3).optional(),
|
|
643
647
|
/** Table-level rename hint (new in v2). */
|
|
644
648
|
renamedFrom: identifier2.optional(),
|
|
645
|
-
/** Synced/reflected read-only tables (`source:
|
|
646
|
-
source: zod.z.string().regex(
|
|
649
|
+
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
650
|
+
source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
647
651
|
columns: zod.z.array(canonicalColumnSchema).default([]),
|
|
648
652
|
primaryKey: zod.z.array(columnIdentifier).min(1).max(8).optional(),
|
|
649
653
|
links: zod.z.array(canonicalLinkSchema).default([]),
|
|
@@ -796,7 +800,9 @@ function validateCellMetadata(table, index, ctx) {
|
|
|
796
800
|
}
|
|
797
801
|
}
|
|
798
802
|
}
|
|
799
|
-
var
|
|
803
|
+
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()]);
|
|
804
|
+
var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
805
|
+
var localDefinitionSchema = zod.z.object({
|
|
800
806
|
definition_format: zod.z.literal(CANONICAL_FORMAT),
|
|
801
807
|
namespace: identifier2.max(41),
|
|
802
808
|
description: zod.z.string().max(2e3).optional(),
|
|
@@ -804,6 +810,8 @@ var canonicalDefinitionSchema = zod.z.object({
|
|
|
804
810
|
tables: zod.z.array(canonicalTableSchema).min(0).max(500),
|
|
805
811
|
/** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
|
|
806
812
|
views: zod.z.array(canonicalViewSchema).max(500).optional(),
|
|
813
|
+
/** Target-owned cross-namespace access contract, using existing namespace grants. */
|
|
814
|
+
exports: zod.z.record(identifier2, relationExportSchema).optional(),
|
|
807
815
|
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
808
816
|
capabilities: zod.z.object({
|
|
809
817
|
roles: zod.z.unknown().optional(),
|
|
@@ -830,7 +838,16 @@ var canonicalDefinitionSchema = zod.z.object({
|
|
|
830
838
|
}
|
|
831
839
|
}
|
|
832
840
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
841
|
+
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
842
|
+
for (const name of Object.keys(definition.exports ?? {})) {
|
|
843
|
+
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
844
|
+
}
|
|
833
845
|
for (const [tableIndex, table] of definition.tables.entries()) {
|
|
846
|
+
for (const [linkIndex, link] of table.links.entries()) {
|
|
847
|
+
if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
|
|
848
|
+
ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
|
|
849
|
+
}
|
|
850
|
+
}
|
|
834
851
|
const names = /* @__PURE__ */ new Set([
|
|
835
852
|
...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
|
|
836
853
|
...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
|
|
@@ -1000,6 +1017,10 @@ var canonicalDefinitionSchema = zod.z.object({
|
|
|
1000
1017
|
};
|
|
1001
1018
|
for (const view of views) visit(view.view, []);
|
|
1002
1019
|
});
|
|
1020
|
+
var canonicalDefinitionSchema = localDefinitionSchema.safeExtend({
|
|
1021
|
+
/** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
|
|
1022
|
+
imports: zod.z.array(localDefinitionSchema).max(32).optional()
|
|
1023
|
+
});
|
|
1003
1024
|
function canonicalRelations(definition) {
|
|
1004
1025
|
const views = (definition.views ?? []).map((view) => ({
|
|
1005
1026
|
table: view.view,
|
|
@@ -1043,6 +1064,11 @@ function normalizeCanonical(definition) {
|
|
|
1043
1064
|
dependencies: [...view.dependencies].sort()
|
|
1044
1065
|
}));
|
|
1045
1066
|
}
|
|
1067
|
+
if (definition.imports?.length) {
|
|
1068
|
+
normalized.imports = definition.imports.map(normalizeCanonical).sort((a, b) => a.namespace.localeCompare(b.namespace));
|
|
1069
|
+
} else {
|
|
1070
|
+
delete normalized.imports;
|
|
1071
|
+
}
|
|
1046
1072
|
return normalized;
|
|
1047
1073
|
}
|
|
1048
1074
|
|
|
@@ -1173,9 +1199,12 @@ var CELL_TYPENAMES = {
|
|
|
1173
1199
|
function cellsTypename(typename) {
|
|
1174
1200
|
return `${typename}Cells`;
|
|
1175
1201
|
}
|
|
1176
|
-
var IR_VERSION = 2;
|
|
1177
1202
|
var LEGACY_IR_VERSION = 1;
|
|
1178
|
-
var
|
|
1203
|
+
var GUARDED_IR_VERSION = 2;
|
|
1204
|
+
var COMPOSED_IR_VERSION = 3;
|
|
1205
|
+
var SQL_IR_VERSION = 4;
|
|
1206
|
+
var RUNTIME_SQL_IR_VERSION = 5;
|
|
1207
|
+
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)]);
|
|
1179
1208
|
zod.z.object({ irVersion: irVersionSchema });
|
|
1180
1209
|
var scalarLiteral = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]);
|
|
1181
1210
|
var valueIrSchema = zod.z.discriminatedUnion("kind", [
|
|
@@ -1213,8 +1242,8 @@ var predIrSchema = zod.z.lazy(
|
|
|
1213
1242
|
value: zod.z.number(),
|
|
1214
1243
|
where: predIrSchema.optional()
|
|
1215
1244
|
}),
|
|
1216
|
-
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string() }),
|
|
1217
|
-
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string() }),
|
|
1245
|
+
zod.z.object({ kind: zod.z.literal("capability"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1246
|
+
zod.z.object({ kind: zod.z.literal("role"), key: zod.z.string(), namespace: zod.z.string().optional() }),
|
|
1218
1247
|
zod.z.object({ kind: zod.z.literal("dynamicFilter"), slot: zod.z.string() }),
|
|
1219
1248
|
zod.z.object({ kind: zod.z.literal("const"), value: zod.z.boolean() })
|
|
1220
1249
|
])
|
|
@@ -1441,7 +1470,31 @@ var variableIrSchema = zod.z.object({
|
|
|
1441
1470
|
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
1442
1471
|
defaultValue: variableDefaultIrSchema.optional()
|
|
1443
1472
|
});
|
|
1473
|
+
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() });
|
|
1444
1474
|
var compiledOperationSchema = zod.z.object({
|
|
1475
|
+
language: zod.z.literal("sql").optional(),
|
|
1476
|
+
/** Server-compiled object catalog and permission ceiling, never caller SQL. */
|
|
1477
|
+
sqlQuery: zod.z.object({
|
|
1478
|
+
catalog: zod.z.object({
|
|
1479
|
+
identity: zod.z.string(),
|
|
1480
|
+
objects: zod.z.array(zod.z.object({
|
|
1481
|
+
ref: zod.z.string(),
|
|
1482
|
+
table: zod.z.string(),
|
|
1483
|
+
columns: zod.z.array(sqlColumnSchema.extend({ type: zod.z.string() })).min(1),
|
|
1484
|
+
scan: zod.z.string().min(1),
|
|
1485
|
+
read: zod.z.array(zod.z.string()).min(1)
|
|
1486
|
+
}).strict()).min(1).max(256)
|
|
1487
|
+
}).strict(),
|
|
1488
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1489
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1490
|
+
}).strict().optional(),
|
|
1491
|
+
sql: zod.z.object({
|
|
1492
|
+
text: zod.z.string().min(1).max(1048576),
|
|
1493
|
+
columns: zod.z.array(sqlColumnSchema).min(1).max(256),
|
|
1494
|
+
parameters: zod.z.array(zod.z.string()).max(128),
|
|
1495
|
+
read: zod.z.array(zod.z.string()).min(1).max(256),
|
|
1496
|
+
maxRows: zod.z.number().int().min(1).max(1e4)
|
|
1497
|
+
}).strict().optional(),
|
|
1445
1498
|
irVersion: irVersionSchema,
|
|
1446
1499
|
name: zod.z.string(),
|
|
1447
1500
|
opHash: zod.z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
@@ -1453,8 +1506,16 @@ var compiledOperationSchema = zod.z.object({
|
|
|
1453
1506
|
variables: zod.z.array(variableIrSchema),
|
|
1454
1507
|
/** Every table the op touches — data-token scoping + audit. */
|
|
1455
1508
|
tableSet: zod.z.array(zod.z.string()).min(1),
|
|
1456
|
-
roots: zod.z.array(rootIrSchema)
|
|
1509
|
+
roots: zod.z.array(rootIrSchema)
|
|
1457
1510
|
}).superRefine((operation, ctx) => {
|
|
1511
|
+
if (operation.language === "sql") {
|
|
1512
|
+
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1513
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !operation.requires?.capability) {
|
|
1514
|
+
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1515
|
+
}
|
|
1516
|
+
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|
|
1517
|
+
ctx.addIssue({ code: "custom", message: "GraphQL operations require roots and cannot carry SQL" });
|
|
1518
|
+
}
|
|
1458
1519
|
for (const [index, root] of operation.roots.entries()) {
|
|
1459
1520
|
if (root.kind !== "mutation" || root.assertAffectedRows === void 0) continue;
|
|
1460
1521
|
if (operation.irVersion < 2 || operation.kind !== "mutation" || root.includeIf !== void 0) {
|
|
@@ -1501,11 +1562,16 @@ var resolvedMetaIrSchema = zod.z.object({
|
|
|
1501
1562
|
});
|
|
1502
1563
|
var tableMetaIrSchema = zod.z.object({
|
|
1503
1564
|
table: zod.z.string(),
|
|
1565
|
+
namespace: zod.z.string().optional(),
|
|
1566
|
+
dependencies: zod.z.array(zod.z.string()).optional(),
|
|
1567
|
+
foreignReferences: zod.z.array(zod.z.object({ column: zod.z.string(), target: zod.z.string(), targetColumn: zod.z.string() })).optional(),
|
|
1568
|
+
exportRead: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1569
|
+
exportWrite: zod.z.union([zod.z.literal(true), zod.z.object({ capability: zod.z.string() }), zod.z.object({ role: zod.z.string() })]).optional(),
|
|
1504
1570
|
schema: zod.z.string(),
|
|
1505
1571
|
typename: zod.z.string(),
|
|
1506
1572
|
/**
|
|
1507
1573
|
* True when statements over this relation evaluate a claims-gated synced
|
|
1508
|
-
* view: synced twins (`source:
|
|
1574
|
+
* view: synced twins (`source: schema.table`) materialize as views whose baked
|
|
1509
1575
|
* policy reads `current_setting('request.jwt.claims')`, and namespace views
|
|
1510
1576
|
* inherit the gate transitively through their declared dependencies. The
|
|
1511
1577
|
* executor must stamp that GUC (transaction-scoped) before any statement
|
|
@@ -1564,10 +1630,18 @@ zod.z.object({
|
|
|
1564
1630
|
irVersion: irVersionSchema,
|
|
1565
1631
|
namespace: zod.z.string(),
|
|
1566
1632
|
schemaHash: zod.z.string(),
|
|
1633
|
+
ownSchemaHash: zod.z.string().optional(),
|
|
1634
|
+
dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
1635
|
+
readPolicies: zod.z.record(zod.z.string(), predIrSchema).optional(),
|
|
1567
1636
|
opsHash: zod.z.string(),
|
|
1637
|
+
/** Apply-observed synced objects without a serving backing; not part of the authored schema hash. */
|
|
1638
|
+
unbackedTables: zod.z.array(zod.z.string()).optional(),
|
|
1568
1639
|
tables: zod.z.record(zod.z.string(), tableMetaIrSchema),
|
|
1569
1640
|
operations: zod.z.record(zod.z.string(), compiledOperationSchema)
|
|
1570
1641
|
}).superRefine((artifact, ctx) => {
|
|
1642
|
+
if (Object.keys(artifact.dependencies ?? {}).length > 0 && artifact.irVersion < COMPOSED_IR_VERSION) {
|
|
1643
|
+
ctx.addIssue({ code: "custom", path: ["irVersion"], message: "cross-namespace dependencies require IR v3" });
|
|
1644
|
+
}
|
|
1571
1645
|
for (const [name, operation] of Object.entries(artifact.operations)) {
|
|
1572
1646
|
if (operation.irVersion > artifact.irVersion) {
|
|
1573
1647
|
ctx.addIssue({ code: "custom", path: ["operations", name, "irVersion"], message: "operation requires a newer IR version than its artifact" });
|
|
@@ -1575,6 +1649,70 @@ zod.z.object({
|
|
|
1575
1649
|
}
|
|
1576
1650
|
});
|
|
1577
1651
|
|
|
1652
|
+
// src/errors.ts
|
|
1653
|
+
var OrmDefinitionError = class extends Error {
|
|
1654
|
+
constructor(message, file) {
|
|
1655
|
+
super(file ? `${file}: ${message}` : message);
|
|
1656
|
+
this.file = file;
|
|
1657
|
+
}
|
|
1658
|
+
name = "OrmDefinitionError";
|
|
1659
|
+
};
|
|
1660
|
+
function stableJson(value) {
|
|
1661
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1662
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
1663
|
+
const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([a], [b]) => a < b ? -1 : 1).map(([key, entryValue]) => `${JSON.stringify(key)}:${stableJson(entryValue)}`);
|
|
1664
|
+
return `{${entries.join(",")}}`;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// src/canonical/composition.ts
|
|
1668
|
+
function localContract(definition) {
|
|
1669
|
+
return normalizeCanonical(localDefinitionSchema.parse(definition));
|
|
1670
|
+
}
|
|
1671
|
+
function composeNamespace(definition) {
|
|
1672
|
+
const all = [localContract(definition), ...definition.imports ?? []];
|
|
1673
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1674
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
1675
|
+
const enums = /* @__PURE__ */ new Map();
|
|
1676
|
+
for (const owner of all) {
|
|
1677
|
+
if (namespaces.has(owner.namespace)) throw new OrmDefinitionError(`duplicate imported namespace '${owner.namespace}'`);
|
|
1678
|
+
namespaces.add(owner.namespace);
|
|
1679
|
+
for (const value of owner.enums) {
|
|
1680
|
+
const previous = enums.get(value.name);
|
|
1681
|
+
if (previous && stableJson(previous) !== stableJson(value)) {
|
|
1682
|
+
throw new OrmDefinitionError(`conflicting imported enum '${value.name}'`);
|
|
1683
|
+
}
|
|
1684
|
+
enums.set(value.name, value);
|
|
1685
|
+
}
|
|
1686
|
+
for (const relation of canonicalRelations(owner)) {
|
|
1687
|
+
if (owners.has(relation.table)) throw new OrmDefinitionError(`ambiguous imported relation '${relation.table}'`);
|
|
1688
|
+
owners.set(relation.table, owner);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
for (const owner of definition.imports?.length ? all : []) {
|
|
1692
|
+
for (const relation of canonicalRelations(owner)) {
|
|
1693
|
+
for (const link of relation.links) {
|
|
1694
|
+
if (link.kind === "toPlatformUser") continue;
|
|
1695
|
+
const target = owners.get(link.target ?? "");
|
|
1696
|
+
if (!target || target.namespace !== (link.namespace ?? owner.namespace)) {
|
|
1697
|
+
throw new OrmDefinitionError(`link '${owner.namespace}/${relation.table}.${link.name}' has no matching imported target`);
|
|
1698
|
+
}
|
|
1699
|
+
if (target.namespace !== owner.namespace && !target.exports?.[link.target ?? ""]) {
|
|
1700
|
+
throw new OrmDefinitionError(`target '${target.namespace}/${link.target}' is not exported`);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
return {
|
|
1706
|
+
owners,
|
|
1707
|
+
definition: {
|
|
1708
|
+
...localContract(definition),
|
|
1709
|
+
tables: all.flatMap((item) => item.tables),
|
|
1710
|
+
views: all.flatMap((item) => item.views ?? []),
|
|
1711
|
+
enums: [...enums.values()]
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1578
1716
|
// src/sdl/generate.ts
|
|
1579
1717
|
var SdlGenerationError = class extends Error {
|
|
1580
1718
|
constructor(message) {
|
|
@@ -1595,7 +1733,7 @@ var PLATFORM_USER_FIELDS = [
|
|
|
1595
1733
|
{ name: "accountEnabled", gqlType: "Boolean", nullable: false }
|
|
1596
1734
|
];
|
|
1597
1735
|
function generateSdl(canonical, options = {}) {
|
|
1598
|
-
const def = normalizeCanonical(canonicalDefinitionSchema.parse(canonical));
|
|
1736
|
+
const def = composeNamespace(normalizeCanonical(canonicalDefinitionSchema.parse(canonical))).definition;
|
|
1599
1737
|
const exposed = canonicalRelations(def).filter((table) => table.source === void 0 && table.internal !== true);
|
|
1600
1738
|
const cellsByTable = new Map(exposed.map((table) => [table.table, trackedCells(table)]));
|
|
1601
1739
|
const tables = exposed.map((table) => ({ ...table, columns: table.columns.filter((column) => column.cell === void 0) }));
|
|
@@ -1668,11 +1806,12 @@ function generateSdl(canonical, options = {}) {
|
|
|
1668
1806
|
for (const value of entry.values) assertEnumValue(value, `enum "${enumName}"`);
|
|
1669
1807
|
blocks.push(renderEnum(enumTypeName(enumName), entry.values));
|
|
1670
1808
|
}
|
|
1809
|
+
const patternTypes = options.stringOnlyPatternOperators ? STRING_PATTERN_COMPARISON_TYPES : PATTERN_COMPARISON_TYPES;
|
|
1671
1810
|
for (const scalar of [...usedComparisonScalars].sort()) {
|
|
1672
|
-
blocks.push(renderComparisonExp(scalar));
|
|
1811
|
+
blocks.push(renderComparisonExp({ gqlTypeName: scalar, patternTypes }));
|
|
1673
1812
|
}
|
|
1674
1813
|
for (const enumName of [...usedEnums].sort()) {
|
|
1675
|
-
blocks.push(renderComparisonExp(enumTypeName(enumName)));
|
|
1814
|
+
blocks.push(renderComparisonExp({ gqlTypeName: enumTypeName(enumName), patternTypes }));
|
|
1676
1815
|
}
|
|
1677
1816
|
if (hasPlatformUser) blocks.push(...renderPlatformUserBlocks());
|
|
1678
1817
|
for (const table of tables) {
|
|
@@ -1726,7 +1865,9 @@ function descriptionLines(text, indent) {
|
|
|
1726
1865
|
const escaped = text.replace(/"""/g, '\\"""');
|
|
1727
1866
|
return [`${indent}"""`, ...escaped.split("\n").map((line) => `${indent}${line}`), `${indent}"""`];
|
|
1728
1867
|
}
|
|
1729
|
-
|
|
1868
|
+
var PATTERN_COMPARISON_TYPES = /* @__PURE__ */ new Set(["String", "Int", "bigint", "uuid"]);
|
|
1869
|
+
var STRING_PATTERN_COMPARISON_TYPES = /* @__PURE__ */ new Set(["String"]);
|
|
1870
|
+
function renderComparisonExp({ gqlTypeName, patternTypes }) {
|
|
1730
1871
|
const fields = [
|
|
1731
1872
|
["_eq", gqlTypeName],
|
|
1732
1873
|
["_neq", gqlTypeName],
|
|
@@ -1738,7 +1879,7 @@ function renderComparisonExp(gqlTypeName) {
|
|
|
1738
1879
|
["_nin", `[${gqlTypeName}!]`],
|
|
1739
1880
|
["_isNull", "Boolean"]
|
|
1740
1881
|
];
|
|
1741
|
-
if (gqlTypeName
|
|
1882
|
+
if (patternTypes.has(gqlTypeName)) {
|
|
1742
1883
|
fields.push(["_like", "String"], ["_ilike", "String"]);
|
|
1743
1884
|
}
|
|
1744
1885
|
if (gqlTypeName === "jsonb") {
|
|
@@ -2237,12 +2378,6 @@ function renderCowMutationFields(table, names) {
|
|
|
2237
2378
|
}
|
|
2238
2379
|
return lines;
|
|
2239
2380
|
}
|
|
2240
|
-
function stableJson(value) {
|
|
2241
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
2242
|
-
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
2243
|
-
const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([a], [b]) => a < b ? -1 : 1).map(([key, entryValue]) => `${JSON.stringify(key)}:${stableJson(entryValue)}`);
|
|
2244
|
-
return `{${entries.join(",")}}`;
|
|
2245
|
-
}
|
|
2246
2381
|
|
|
2247
2382
|
// src/codegen-gql/errors.ts
|
|
2248
2383
|
var CodegenGqlError = class extends Error {
|
|
@@ -2313,7 +2448,7 @@ function normalizeRequires(requires) {
|
|
|
2313
2448
|
|
|
2314
2449
|
// src/codegen-gql/type-policies.ts
|
|
2315
2450
|
function generateTypePolicies(canonical) {
|
|
2316
|
-
const def = normalizeCanonical(canonicalDefinitionSchema.parse(canonical));
|
|
2451
|
+
const def = composeNamespace(normalizeCanonical(canonicalDefinitionSchema.parse(canonical))).definition;
|
|
2317
2452
|
const entries = [];
|
|
2318
2453
|
let hasPlatformUser = false;
|
|
2319
2454
|
for (const table of canonicalRelations(def)) {
|