@sequenceholdings/orm 0.1.0 → 0.1.2
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 +1 -1
- package/dist/authoring.cjs +794 -0
- package/dist/authoring.cjs.map +1 -0
- package/dist/authoring.d.cts +274 -0
- package/dist/authoring.d.ts +274 -0
- package/dist/authoring.js +763 -0
- package/dist/authoring.js.map +1 -0
- package/dist/canonical.cjs +146 -0
- package/dist/canonical.cjs.map +1 -0
- package/dist/canonical.d.cts +369 -0
- package/dist/canonical.d.ts +369 -0
- package/dist/canonical.js +131 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.cjs +6208 -1693
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +8 -1
- package/dist/cli.d.ts +8 -1
- package/dist/cli.js +6262 -1749
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +120 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +74 -2
- package/dist/client.d.ts +74 -2
- package/dist/client.js +116 -1
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +3001 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +581 -0
- package/dist/compiler.d.ts +581 -0
- package/dist/compiler.js +2947 -0
- package/dist/compiler.js.map +1 -0
- package/dist/index.cjs +1730 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -56
- package/dist/index.d.ts +126 -56
- package/dist/index.js +1643 -324
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +407 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +1179 -0
- package/dist/ir.d.ts +1179 -0
- package/dist/ir.js +388 -0
- package/dist/ir.js.map +1 -0
- package/dist/naming-CTvWSRTf.d.ts +79 -0
- package/dist/naming-DRyinU4u.d.cts +79 -0
- package/dist/sdl.cjs +833 -0
- package/dist/sdl.cjs.map +1 -0
- package/dist/sdl.d.cts +96 -0
- package/dist/sdl.d.ts +96 -0
- package/dist/sdl.js +809 -0
- package/dist/sdl.js.map +1 -0
- package/package.json +36 -3
- package/src/codegen-gql/apollo-hooks.cjs +98 -0
- package/src/codegen-gql/server-fns.cjs +101 -0
- package/templates/README.md +13 -0
- package/templates/orm-namespace/CLAUDE.md +81 -0
- package/templates/orm-namespace/codegen.ts +22 -0
- package/templates/orm-namespace/gitignore +5 -0
- package/templates/orm-namespace/graphql/example/queries.ts +56 -0
- package/templates/orm-namespace/package.json +24 -0
- package/templates/orm-namespace/schema/tables.ts +71 -0
- package/templates/orm-namespace/sequence.config.ts +32 -0
- package/templates/orm-namespace/tsconfig.json +15 -0
package/dist/ir.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/ir/index.ts
|
|
4
|
+
var CANONICAL_FORMAT = 2;
|
|
5
|
+
var IDENTIFIER_RE = /^[a-z][a-z0-9_]*$/;
|
|
6
|
+
var identifier = z.string().min(1).max(63).regex(IDENTIFIER_RE);
|
|
7
|
+
var COLUMN_TYPES = [
|
|
8
|
+
"uuid",
|
|
9
|
+
"text",
|
|
10
|
+
"integer",
|
|
11
|
+
"bigint",
|
|
12
|
+
"numeric",
|
|
13
|
+
"double",
|
|
14
|
+
"boolean",
|
|
15
|
+
"timestamptz",
|
|
16
|
+
"date",
|
|
17
|
+
"jsonb"
|
|
18
|
+
];
|
|
19
|
+
var columnTypeSchema = z.enum(COLUMN_TYPES);
|
|
20
|
+
var canonicalEnumSchema = z.object({
|
|
21
|
+
name: identifier,
|
|
22
|
+
values: z.array(z.string().min(1).max(63)).min(1).max(100)
|
|
23
|
+
});
|
|
24
|
+
var canonicalColumnSchema = z.object({
|
|
25
|
+
/** Property name in TS (camelCase); columnName is the Postgres name. */
|
|
26
|
+
name: z.string().min(1).max(63),
|
|
27
|
+
columnName: identifier,
|
|
28
|
+
type: z.union([columnTypeSchema, z.object({ enum: identifier })]),
|
|
29
|
+
nullable: z.boolean().default(true),
|
|
30
|
+
unique: z.boolean().default(false),
|
|
31
|
+
/** Literal default, or one of the allowlisted SQL functions. */
|
|
32
|
+
default: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),
|
|
33
|
+
defaultFn: z.enum(["gen_random_uuid()", "now()"]).optional(),
|
|
34
|
+
description: z.string().max(500).optional(),
|
|
35
|
+
/** Migration hints — same semantics as v1. */
|
|
36
|
+
renamedFrom: identifier.optional(),
|
|
37
|
+
cast: z.string().max(200).optional(),
|
|
38
|
+
deprecated: z.boolean().default(false)
|
|
39
|
+
});
|
|
40
|
+
var canonicalLinkSchema = z.object({
|
|
41
|
+
name: z.string().min(1).max(63),
|
|
42
|
+
kind: z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
43
|
+
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
44
|
+
target: identifier.optional(),
|
|
45
|
+
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
46
|
+
on: identifier,
|
|
47
|
+
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
48
|
+
references: identifier.optional(),
|
|
49
|
+
/** enforce: true emits a real FK constraint (same-namespace toOne only). */
|
|
50
|
+
enforce: z.boolean().default(false),
|
|
51
|
+
description: z.string().max(500).optional()
|
|
52
|
+
});
|
|
53
|
+
var canonicalIndexSchema = z.object({
|
|
54
|
+
columns: z.array(identifier).min(1),
|
|
55
|
+
unique: z.boolean().default(false),
|
|
56
|
+
name: identifier.optional()
|
|
57
|
+
});
|
|
58
|
+
var policyVariantSchema = z.object({
|
|
59
|
+
/** Claims-only guard (capability()/role()/claim() comparisons — no columns). */
|
|
60
|
+
when: z.string().min(1).max(1e3),
|
|
61
|
+
/** Exactly one of: allow-all bypass, or a row predicate. */
|
|
62
|
+
allow: z.literal(true).optional(),
|
|
63
|
+
policy: z.string().min(1).max(2e3).optional()
|
|
64
|
+
}).refine((v) => v.allow === true !== (typeof v.policy === "string"), {
|
|
65
|
+
message: "A variant declares exactly one of allow: true or policy"
|
|
66
|
+
});
|
|
67
|
+
var policyExpressionSchema = z.union([
|
|
68
|
+
z.string().min(1).max(2e3),
|
|
69
|
+
z.object({
|
|
70
|
+
default: z.string().min(1).max(2e3),
|
|
71
|
+
variants: z.array(policyVariantSchema).max(10).default([])
|
|
72
|
+
})
|
|
73
|
+
]);
|
|
74
|
+
var canonicalPoliciesSchema = z.object({
|
|
75
|
+
read: policyExpressionSchema.optional(),
|
|
76
|
+
write: policyExpressionSchema.optional()
|
|
77
|
+
});
|
|
78
|
+
var canonicalActionSchema = z.object({
|
|
79
|
+
name: identifier,
|
|
80
|
+
requires: z.string().max(1e3).optional(),
|
|
81
|
+
params: z.record(z.string(), z.object({
|
|
82
|
+
type: columnTypeSchema,
|
|
83
|
+
nullable: z.boolean().default(false)
|
|
84
|
+
})).default({}),
|
|
85
|
+
executes: z.string().min(1).max(1e4),
|
|
86
|
+
returns: z.enum(["rows", "rowsAffected", "scalar"]).default("rowsAffected"),
|
|
87
|
+
audit: z.object({ action: z.string(), resource: z.string() }).optional()
|
|
88
|
+
});
|
|
89
|
+
var canonicalTableSchema = z.object({
|
|
90
|
+
table: identifier,
|
|
91
|
+
description: z.string().max(2e3).optional(),
|
|
92
|
+
/** Table-level rename hint (new in v2). */
|
|
93
|
+
renamedFrom: identifier.optional(),
|
|
94
|
+
/** Synced/reflected read-only tables (`source: gold.*`) — v1 semantics. */
|
|
95
|
+
source: z.string().regex(/^gold\.[a-z][a-z0-9_]*$/).optional(),
|
|
96
|
+
columns: z.array(canonicalColumnSchema).default([]),
|
|
97
|
+
primaryKey: z.array(identifier).min(1).max(8).optional(),
|
|
98
|
+
links: z.array(canonicalLinkSchema).default([]),
|
|
99
|
+
indexes: z.array(canonicalIndexSchema).default([]),
|
|
100
|
+
policies: canonicalPoliciesSchema.default({}),
|
|
101
|
+
actions: z.array(canonicalActionSchema).default([])
|
|
102
|
+
});
|
|
103
|
+
z.object({
|
|
104
|
+
definition_format: z.literal(CANONICAL_FORMAT),
|
|
105
|
+
namespace: identifier.max(41),
|
|
106
|
+
description: z.string().max(2e3).optional(),
|
|
107
|
+
enums: z.array(canonicalEnumSchema).default([]),
|
|
108
|
+
tables: z.array(canonicalTableSchema).min(0).max(500),
|
|
109
|
+
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
110
|
+
capabilities: z.object({
|
|
111
|
+
roles: z.unknown().optional(),
|
|
112
|
+
uses: z.array(z.string()).default([])
|
|
113
|
+
}).default({ uses: [] })
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// src/ir/index.ts
|
|
117
|
+
var IR_VERSION = 1;
|
|
118
|
+
var CLAIMS_CONTRACT = {
|
|
119
|
+
sub: "string",
|
|
120
|
+
org: "string?",
|
|
121
|
+
roles: "string[]",
|
|
122
|
+
capabilities: "string[]"
|
|
123
|
+
};
|
|
124
|
+
var scalarLiteral = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
125
|
+
var valueIrSchema = z.discriminatedUnion("kind", [
|
|
126
|
+
z.object({ kind: z.literal("literal"), value: z.union([scalarLiteral, z.array(scalarLiteral)]) }),
|
|
127
|
+
z.object({ kind: z.literal("variable"), name: z.string() }),
|
|
128
|
+
z.object({ kind: z.literal("claim"), key: z.enum(["sub", "org"]) })
|
|
129
|
+
]);
|
|
130
|
+
var CMP_OPS = [
|
|
131
|
+
"eq",
|
|
132
|
+
"neq",
|
|
133
|
+
"gt",
|
|
134
|
+
"gte",
|
|
135
|
+
"lt",
|
|
136
|
+
"lte",
|
|
137
|
+
"in",
|
|
138
|
+
"nin",
|
|
139
|
+
"like",
|
|
140
|
+
"ilike",
|
|
141
|
+
"isNull",
|
|
142
|
+
"contains",
|
|
143
|
+
"hasKey"
|
|
144
|
+
];
|
|
145
|
+
var predIrSchema = z.lazy(
|
|
146
|
+
() => z.discriminatedUnion("kind", [
|
|
147
|
+
z.object({ kind: z.literal("and"), operands: z.array(predIrSchema).min(1) }),
|
|
148
|
+
z.object({ kind: z.literal("or"), operands: z.array(predIrSchema).min(1) }),
|
|
149
|
+
z.object({ kind: z.literal("not"), operand: predIrSchema }),
|
|
150
|
+
z.object({ kind: z.literal("cmp"), op: z.enum(CMP_OPS), column: z.string(), value: valueIrSchema }),
|
|
151
|
+
z.object({ kind: z.literal("exists"), link: z.string(), where: predIrSchema }),
|
|
152
|
+
z.object({
|
|
153
|
+
kind: z.literal("aggPredicate"),
|
|
154
|
+
link: z.string(),
|
|
155
|
+
fn: z.literal("count"),
|
|
156
|
+
op: z.enum(["eq", "neq", "gt", "gte", "lt", "lte"]),
|
|
157
|
+
value: z.number(),
|
|
158
|
+
where: predIrSchema.optional()
|
|
159
|
+
}),
|
|
160
|
+
z.object({ kind: z.literal("capability"), key: z.string() }),
|
|
161
|
+
z.object({ kind: z.literal("role"), key: z.string() }),
|
|
162
|
+
z.object({ kind: z.literal("dynamicFilter"), slot: z.string() }),
|
|
163
|
+
z.object({ kind: z.literal("const"), value: z.boolean() })
|
|
164
|
+
])
|
|
165
|
+
);
|
|
166
|
+
var orderIrSchema = z.discriminatedUnion("kind", [
|
|
167
|
+
z.object({
|
|
168
|
+
kind: z.literal("column"),
|
|
169
|
+
column: z.string(),
|
|
170
|
+
/** Order through a to-one link: `link` is set and `column` is on the target. */
|
|
171
|
+
link: z.string().optional(),
|
|
172
|
+
direction: z.enum(["asc", "desc"]),
|
|
173
|
+
nulls: z.enum(["first", "last"]).optional()
|
|
174
|
+
}),
|
|
175
|
+
/** §4f: `$orderBy: [FooOrderBy!]` variable — validated + lowered at runtime. */
|
|
176
|
+
z.object({ kind: z.literal("dynamic"), slot: z.string() })
|
|
177
|
+
]);
|
|
178
|
+
var limitIrSchema = z.object({
|
|
179
|
+
/** Fixed value or a variable, clamped to [1, max]; absent → default. */
|
|
180
|
+
variable: z.string().optional(),
|
|
181
|
+
value: z.number().int().positive().optional(),
|
|
182
|
+
default: z.number().int().positive(),
|
|
183
|
+
max: z.number().int().positive()
|
|
184
|
+
});
|
|
185
|
+
var selectionIrSchema = z.lazy(
|
|
186
|
+
() => z.object({
|
|
187
|
+
typename: z.string(),
|
|
188
|
+
columns: z.array(z.object({ alias: z.string(), column: z.string() })),
|
|
189
|
+
relations: z.array(z.object({
|
|
190
|
+
alias: z.string(),
|
|
191
|
+
link: z.string(),
|
|
192
|
+
selection: selectionIrSchema,
|
|
193
|
+
where: predIrSchema.optional(),
|
|
194
|
+
orderBy: z.array(orderIrSchema).optional(),
|
|
195
|
+
limit: limitIrSchema.optional(),
|
|
196
|
+
offset: z.object({ variable: z.string().optional(), value: z.number().int().optional() }).optional()
|
|
197
|
+
})),
|
|
198
|
+
aggregates: z.array(z.object({
|
|
199
|
+
alias: z.string(),
|
|
200
|
+
link: z.string().optional(),
|
|
201
|
+
where: predIrSchema.optional(),
|
|
202
|
+
count: z.object({ columns: z.array(z.string()).optional(), distinct: z.boolean().optional() }).optional(),
|
|
203
|
+
sum: z.array(z.string()).optional(),
|
|
204
|
+
avg: z.array(z.string()).optional(),
|
|
205
|
+
nodes: selectionIrSchema.optional()
|
|
206
|
+
}))
|
|
207
|
+
})
|
|
208
|
+
);
|
|
209
|
+
var includeIfSchema = z.object({ variable: z.string(), negated: z.boolean() });
|
|
210
|
+
var selectRootSchema = z.object({
|
|
211
|
+
kind: z.literal("select"),
|
|
212
|
+
alias: z.string(),
|
|
213
|
+
table: z.string(),
|
|
214
|
+
selection: selectionIrSchema,
|
|
215
|
+
/** Composed at compile time: AND(policy, documentWhere?, dynamicFilter?). */
|
|
216
|
+
where: predIrSchema,
|
|
217
|
+
orderBy: z.array(orderIrSchema).default([]),
|
|
218
|
+
distinctOn: z.union([z.array(z.string()), z.object({ slot: z.string() })]).optional(),
|
|
219
|
+
limit: limitIrSchema,
|
|
220
|
+
offset: z.object({ variable: z.string().optional(), value: z.number().int().optional() }).optional(),
|
|
221
|
+
includeIf: includeIfSchema.optional()
|
|
222
|
+
});
|
|
223
|
+
var byPkRootSchema = z.object({
|
|
224
|
+
kind: z.literal("byPk"),
|
|
225
|
+
alias: z.string(),
|
|
226
|
+
table: z.string(),
|
|
227
|
+
selection: selectionIrSchema,
|
|
228
|
+
pk: z.array(z.object({ column: z.string(), value: valueIrSchema })).min(1),
|
|
229
|
+
/** Policy predicate — ANDed with the PK match. */
|
|
230
|
+
where: predIrSchema,
|
|
231
|
+
includeIf: includeIfSchema.optional()
|
|
232
|
+
});
|
|
233
|
+
var aggregateRootSchema = z.object({
|
|
234
|
+
kind: z.literal("aggregate"),
|
|
235
|
+
alias: z.string(),
|
|
236
|
+
table: z.string(),
|
|
237
|
+
where: predIrSchema,
|
|
238
|
+
count: z.object({ columns: z.array(z.string()).optional(), distinct: z.boolean().optional() }).optional(),
|
|
239
|
+
sum: z.array(z.string()).optional(),
|
|
240
|
+
avg: z.array(z.string()).optional(),
|
|
241
|
+
nodes: selectionIrSchema.optional(),
|
|
242
|
+
includeIf: includeIfSchema.optional()
|
|
243
|
+
});
|
|
244
|
+
var writeValuesSchema = z.union([
|
|
245
|
+
z.object({ slot: z.string() }),
|
|
246
|
+
z.object({ entries: z.array(z.object({ column: z.string(), value: valueIrSchema })) })
|
|
247
|
+
]);
|
|
248
|
+
var onConflictIrSchema = z.union([
|
|
249
|
+
z.object({ slot: z.string() }),
|
|
250
|
+
z.object({ constraint: z.string(), updateColumns: z.array(z.string()) })
|
|
251
|
+
]);
|
|
252
|
+
var mutationRootSchema = z.object({
|
|
253
|
+
kind: z.literal("mutation"),
|
|
254
|
+
op: z.enum(["insert", "insertOne", "update", "updateByPk", "delete", "deleteByPk"]),
|
|
255
|
+
alias: z.string(),
|
|
256
|
+
table: z.string(),
|
|
257
|
+
/** insert/insertOne: rows come from a slot ($object/$objects) or literals. */
|
|
258
|
+
objects: z.union([
|
|
259
|
+
z.object({ slot: z.string() }),
|
|
260
|
+
z.object({ rows: z.array(z.array(z.object({ column: z.string(), value: valueIrSchema }))) })
|
|
261
|
+
]).optional(),
|
|
262
|
+
/** Server-pinned columns (e.g. author_sub ← claim('sub')) merged into every inserted row. */
|
|
263
|
+
pinnedColumns: z.array(z.object({ column: z.string(), value: valueIrSchema })).default([]),
|
|
264
|
+
onConflict: onConflictIrSchema.optional(),
|
|
265
|
+
set: writeValuesSchema.optional(),
|
|
266
|
+
append: writeValuesSchema.optional(),
|
|
267
|
+
inc: writeValuesSchema.optional(),
|
|
268
|
+
/** update/delete row filter: AND(writePolicy, documentWhere/pk, dynamicFilter?). */
|
|
269
|
+
where: predIrSchema.optional(),
|
|
270
|
+
pk: z.array(z.object({ column: z.string(), value: valueIrSchema })).optional(),
|
|
271
|
+
/** WITH CHECK analogue evaluated against NEW row values (insert/update). */
|
|
272
|
+
insertCheck: predIrSchema.optional(),
|
|
273
|
+
returning: selectionIrSchema.nullable(),
|
|
274
|
+
affectedRows: z.boolean().default(false),
|
|
275
|
+
includeIf: includeIfSchema.optional()
|
|
276
|
+
});
|
|
277
|
+
var actionRootSchema = z.object({
|
|
278
|
+
kind: z.literal("action"),
|
|
279
|
+
alias: z.string(),
|
|
280
|
+
name: z.string(),
|
|
281
|
+
params: z.array(z.object({ name: z.string(), value: valueIrSchema })),
|
|
282
|
+
returns: z.enum(["rows", "rowsAffected", "scalar"])
|
|
283
|
+
});
|
|
284
|
+
var rootIrSchema = z.discriminatedUnion("kind", [
|
|
285
|
+
selectRootSchema,
|
|
286
|
+
byPkRootSchema,
|
|
287
|
+
aggregateRootSchema,
|
|
288
|
+
mutationRootSchema,
|
|
289
|
+
actionRootSchema
|
|
290
|
+
]);
|
|
291
|
+
var INPUT_REF_KINDS = [
|
|
292
|
+
"boolExp",
|
|
293
|
+
"orderBy",
|
|
294
|
+
"selectColumn",
|
|
295
|
+
"insertInput",
|
|
296
|
+
"setInput",
|
|
297
|
+
"appendInput",
|
|
298
|
+
"onConflict"
|
|
299
|
+
];
|
|
300
|
+
var variableDefaultIrSchema = z.object({
|
|
301
|
+
value: z.union([scalarLiteral, z.array(scalarLiteral)])
|
|
302
|
+
});
|
|
303
|
+
var variableIrSchema = z.object({
|
|
304
|
+
name: z.string(),
|
|
305
|
+
type: z.union([
|
|
306
|
+
z.object({ kind: z.literal("scalar"), scalar: z.enum(COLUMN_TYPES) }),
|
|
307
|
+
/** `values` is the declared membership whitelist — the executor validates against it. */
|
|
308
|
+
z.object({ kind: z.literal("enum"), name: z.string(), values: z.array(z.string()).min(1) }),
|
|
309
|
+
/** §4f dynamic slot: validated against `tables[table]` whitelists at runtime. */
|
|
310
|
+
z.object({ kind: z.literal("inputRef"), input: z.enum(INPUT_REF_KINDS), table: z.string() })
|
|
311
|
+
]),
|
|
312
|
+
nullable: z.boolean(),
|
|
313
|
+
list: z.boolean(),
|
|
314
|
+
/** Absent = no default declared; see {@link variableDefaultIrSchema}. */
|
|
315
|
+
defaultValue: variableDefaultIrSchema.optional()
|
|
316
|
+
});
|
|
317
|
+
var compiledOperationSchema = z.object({
|
|
318
|
+
irVersion: z.literal(IR_VERSION),
|
|
319
|
+
name: z.string(),
|
|
320
|
+
opHash: z.string().regex(/^sha256:[0-9a-f]{64}$/),
|
|
321
|
+
kind: z.enum(["query", "mutation", "action"]),
|
|
322
|
+
requires: z.object({
|
|
323
|
+
capability: z.string().optional(),
|
|
324
|
+
role: z.string().optional()
|
|
325
|
+
}).nullable(),
|
|
326
|
+
variables: z.array(variableIrSchema),
|
|
327
|
+
/** Every table the op touches — data-token scoping + audit. */
|
|
328
|
+
tableSet: z.array(z.string()).min(1),
|
|
329
|
+
roots: z.array(rootIrSchema).min(1)
|
|
330
|
+
});
|
|
331
|
+
var tableMetaIrSchema = z.object({
|
|
332
|
+
table: z.string(),
|
|
333
|
+
schema: z.string(),
|
|
334
|
+
typename: z.string(),
|
|
335
|
+
columns: z.array(z.object({
|
|
336
|
+
name: z.string(),
|
|
337
|
+
columnName: z.string(),
|
|
338
|
+
type: z.union([z.enum(COLUMN_TYPES), z.object({ enum: z.string(), values: z.array(z.string()) })]),
|
|
339
|
+
nullable: z.boolean()
|
|
340
|
+
})),
|
|
341
|
+
primaryKey: z.array(z.string()).min(1),
|
|
342
|
+
links: z.array(z.object({
|
|
343
|
+
name: z.string(),
|
|
344
|
+
kind: z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
345
|
+
target: z.string(),
|
|
346
|
+
on: z.string(),
|
|
347
|
+
references: z.string()
|
|
348
|
+
})),
|
|
349
|
+
/** §4f whitelists: what dynamic inputs may reference. */
|
|
350
|
+
filterable: z.array(z.string()),
|
|
351
|
+
orderable: z.array(z.string()),
|
|
352
|
+
insertable: z.array(z.string()),
|
|
353
|
+
settable: z.array(z.string()),
|
|
354
|
+
appendable: z.array(z.string()),
|
|
355
|
+
constraints: z.array(z.object({ name: z.string(), columns: z.array(z.string()) })),
|
|
356
|
+
/** Depth/node caps for dynamic filter trees on this table. */
|
|
357
|
+
dynamicFilterMaxDepth: z.number().int().positive().default(6),
|
|
358
|
+
dynamicFilterMaxNodes: z.number().int().positive().default(64)
|
|
359
|
+
});
|
|
360
|
+
var compiledArtifactSchema = z.object({
|
|
361
|
+
irVersion: z.literal(IR_VERSION),
|
|
362
|
+
namespace: z.string(),
|
|
363
|
+
schemaHash: z.string(),
|
|
364
|
+
opsHash: z.string(),
|
|
365
|
+
tables: z.record(z.string(), tableMetaIrSchema),
|
|
366
|
+
operations: z.record(z.string(), compiledOperationSchema)
|
|
367
|
+
});
|
|
368
|
+
var IrVersionError = class extends Error {
|
|
369
|
+
constructor(found) {
|
|
370
|
+
super(`Unsupported IR version ${String(found)} \u2014 this executor supports up to ${IR_VERSION}. Upgrade @sequenceholdings/orm or re-push the namespace.`);
|
|
371
|
+
this.name = "IrVersionError";
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
function normalizeIr(raw) {
|
|
375
|
+
if (!raw || typeof raw !== "object") throw new IrVersionError(void 0);
|
|
376
|
+
const version = raw.irVersion;
|
|
377
|
+
if (version !== IR_VERSION) throw new IrVersionError(version);
|
|
378
|
+
return compiledArtifactSchema.parse(raw);
|
|
379
|
+
}
|
|
380
|
+
function indexByHash(artifact) {
|
|
381
|
+
const map = /* @__PURE__ */ new Map();
|
|
382
|
+
for (const op of Object.values(artifact.operations)) map.set(op.opHash, op);
|
|
383
|
+
return map;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export { CLAIMS_CONTRACT, CMP_OPS, INPUT_REF_KINDS, IR_VERSION, IrVersionError, compiledArtifactSchema, compiledOperationSchema, indexByHash, limitIrSchema, normalizeIr, orderIrSchema, predIrSchema, rootIrSchema, selectionIrSchema, tableMetaIrSchema, valueIrSchema, variableDefaultIrSchema, variableIrSchema };
|
|
387
|
+
//# sourceMappingURL=ir.js.map
|
|
388
|
+
//# sourceMappingURL=ir.js.map
|
package/dist/ir.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/canonical/v2.ts","../src/ir/index.ts"],"names":["z"],"mappings":";;;AAaO,IAAM,gBAAA,GAAmB,CAAA;AAGzB,IAAM,aAAA,GAAgB,mBAAA;AAC7B,IAAM,UAAA,GAAa,CAAA,CAAE,MAAA,EAAO,CAAE,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,EAAE,CAAA,CAAE,KAAA,CAAM,aAAa,CAAA;AAGzD,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,SAAA;AAAA,EAAW,QAAA;AAAA,EAAU,SAAA;AAAA,EAAW,QAAA;AAAA,EAChD,SAAA;AAAA,EAAW,aAAA;AAAA,EAAe,MAAA;AAAA,EAAQ;AACpC,CAAA;AAGA,IAAM,gBAAA,GAAmB,CAAA,CAAE,IAAA,CAAK,YAAY,CAAA;AAGrC,IAAM,mBAAA,GAAsB,EAAE,MAAA,CAAO;AAAA,EAC1C,IAAA,EAAM,UAAA;AAAA,EACN,QAAQ,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,MAAA,GAAS,GAAA,CAAI,CAAC,CAAA,CAAE,GAAA,CAAI,EAAE,CAAC,CAAA,CAAE,IAAI,CA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ir.js","sourcesContent":["/**\n * Canonical namespace definition v2 — the data-only JSON a consumer's\n * TypeScript schema serializes to. This is v2's equivalent of the v1 YAML\n * `NamespaceDefinition`: the CLI's jiti loader produces it, the content hash\n * is computed over it, the server re-validates it (consumer TS never runs\n * server-side), and the SDL generator / GraphQL compiler / migration engine\n * all consume it.\n *\n * FROZEN CONTRACT (week 1): downstream tracks build against these shapes.\n * Additive evolution only; `definition_format` discriminates on the wire.\n */\nimport { z } from 'zod'\n\nexport const CANONICAL_FORMAT = 2 as const\n\n/** Identifier grammar shared with v1 (`^[a-z][a-z0-9_]*$`, ≤63 bytes). */\nexport const IDENTIFIER_RE = /^[a-z][a-z0-9_]*$/\nconst identifier = z.string().min(1).max(63).regex(IDENTIFIER_RE)\n\n/** The 10 v1 column types, unchanged in v2. */\nexport const COLUMN_TYPES = [\n 'uuid', 'text', 'integer', 'bigint', 'numeric', 'double',\n 'boolean', 'timestamptz', 'date', 'jsonb',\n] as const\nexport type ColumnType = (typeof COLUMN_TYPES)[number]\n\nconst columnTypeSchema = z.enum(COLUMN_TYPES)\n\n/** Enum columns reference a namespace-level `defineEnum` by name. */\nexport const canonicalEnumSchema = z.object({\n name: identifier,\n values: z.array(z.string().min(1).max(63)).min(1).max(100),\n})\nexport type CanonicalEnum = z.infer<typeof canonicalEnumSchema>\n\nexport const canonicalColumnSchema = z.object({\n /** Property name in TS (camelCase); columnName is the Postgres name. */\n name: z.string().min(1).max(63),\n columnName: identifier,\n type: z.union([columnTypeSchema, z.object({ enum: identifier })]),\n nullable: z.boolean().default(true),\n unique: z.boolean().default(false),\n /** Literal default, or one of the allowlisted SQL functions. */\n default: z.union([z.string(), z.number(), z.boolean(), z.null()]).optional(),\n defaultFn: z.enum(['gen_random_uuid()', 'now()']).optional(),\n description: z.string().max(500).optional(),\n /** Migration hints — same semantics as v1. */\n renamedFrom: identifier.optional(),\n cast: z.string().max(200).optional(),\n deprecated: z.boolean().default(false),\n})\nexport type CanonicalColumn = z.infer<typeof canonicalColumnSchema>\n\nexport const canonicalLinkSchema = z.object({\n name: z.string().min(1).max(63),\n kind: z.enum(['toOne', 'toMany', 'toPlatformUser']),\n /** Target table name (namespace-local). Absent for toPlatformUser. */\n target: identifier.optional(),\n /** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */\n on: identifier,\n /** Referenced column on the target (default: target's PK / platform user `sub`). */\n references: identifier.optional(),\n /** enforce: true emits a real FK constraint (same-namespace toOne only). */\n enforce: z.boolean().default(false),\n description: z.string().max(500).optional(),\n})\nexport type CanonicalLink = z.infer<typeof canonicalLinkSchema>\n\nexport const canonicalIndexSchema = z.object({\n columns: z.array(identifier).min(1),\n unique: z.boolean().default(false),\n name: identifier.optional(),\n})\n\n/**\n * Policy expressions stay DSL SOURCE STRINGS in the canonical form — parsing\n * and claim-key validation happen in both CLI and server via the shared\n * predicate parser. Variants follow §4c permissive-union semantics.\n */\nexport const policyVariantSchema = z.object({\n /** Claims-only guard (capability()/role()/claim() comparisons — no columns). */\n when: z.string().min(1).max(1000),\n /** Exactly one of: allow-all bypass, or a row predicate. */\n allow: z.literal(true).optional(),\n policy: z.string().min(1).max(2000).optional(),\n}).refine((v) => (v.allow === true) !== (typeof v.policy === 'string'), {\n message: 'A variant declares exactly one of allow: true or policy',\n})\n\nexport const policyExpressionSchema = z.union([\n z.string().min(1).max(2000),\n z.object({\n default: z.string().min(1).max(2000),\n variants: z.array(policyVariantSchema).max(10).default([]),\n }),\n])\nexport type PolicyExpression = z.infer<typeof policyExpressionSchema>\n\nexport const canonicalPoliciesSchema = z.object({\n read: policyExpressionSchema.optional(),\n write: policyExpressionSchema.optional(),\n})\n\n/** Actions carry over from v1 as compiled named-SQL ops (plan: resolved OQ-1). */\nexport const canonicalActionSchema = z.object({\n name: identifier,\n requires: z.string().max(1000).optional(),\n params: z.record(z.string(), z.object({\n type: columnTypeSchema,\n nullable: z.boolean().default(false),\n })).default({}),\n executes: z.string().min(1).max(10_000),\n returns: z.enum(['rows', 'rowsAffected', 'scalar']).default('rowsAffected'),\n audit: z.object({ action: z.string(), resource: z.string() }).optional(),\n})\n\nexport const canonicalTableSchema = z.object({\n table: identifier,\n description: z.string().max(2000).optional(),\n /** Table-level rename hint (new in v2). */\n renamedFrom: identifier.optional(),\n /** Synced/reflected read-only tables (`source: gold.*`) — v1 semantics. */\n source: z.string().regex(/^gold\\.[a-z][a-z0-9_]*$/).optional(),\n columns: z.array(canonicalColumnSchema).default([]),\n primaryKey: z.array(identifier).min(1).max(8).optional(),\n links: z.array(canonicalLinkSchema).default([]),\n indexes: z.array(canonicalIndexSchema).default([]),\n policies: canonicalPoliciesSchema.default({}),\n actions: z.array(canonicalActionSchema).default([]),\n})\nexport type CanonicalTable = z.infer<typeof canonicalTableSchema>\n\nexport const canonicalDefinitionSchema = z.object({\n definition_format: z.literal(CANONICAL_FORMAT),\n namespace: identifier.max(41),\n description: z.string().max(2000).optional(),\n enums: z.array(canonicalEnumSchema).default([]),\n tables: z.array(canonicalTableSchema).min(0).max(500),\n /** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */\n capabilities: z.object({\n roles: z.unknown().optional(),\n uses: z.array(z.string()).default([]),\n }).default({ uses: [] }),\n})\nexport type CanonicalDefinition = z.infer<typeof canonicalDefinitionSchema>\n\n/**\n * Deterministic serialization discipline: tables sorted by name, columns in\n * declaration order (order is meaningful for DDL), links/indexes/actions\n * sorted by name, object keys emitted in schema order. `serializeNamespace`\n * (authoring layer) and the server-side re-validation both normalize through\n * this function before hashing so CLI and server hash identical bytes.\n */\nexport function normalizeCanonical(definition: CanonicalDefinition): CanonicalDefinition {\n const sortByName = <T extends { name: string }>(items: T[]): T[] =>\n [...items].sort((a, b) => a.name.localeCompare(b.name))\n return {\n ...definition,\n enums: sortByName(definition.enums),\n tables: [...definition.tables]\n .sort((a, b) => a.table.localeCompare(b.table))\n .map((t) => ({\n ...t,\n links: sortByName(t.links),\n indexes: [...t.indexes].sort((a, b) =>\n (a.name ?? a.columns.join('_')).localeCompare(b.name ?? b.columns.join('_'))),\n actions: sortByName(t.actions),\n })),\n }\n}\n","/**\n * Compiled-operation IR — THE frozen contract between the GraphQL compiler\n * (push time, CLI preview + canonical server compile) and the data-plane\n * executor (runtime). The artifact is inert, validated JSON: no generated\n * code ever crosses the registry (plan §4).\n *\n * Design invariants:\n * - Policies are BAKED IN at compile time: every table-touching node carries\n * its read policy AND-ed into `where` (or `writePolicy`/`insertCheck` for\n * mutation targets). Execution needs only (IR, claims, variables).\n * - §4f dynamic slots: a variable typed with a generated input type\n * (BoolExp/OrderBy/SelectColumn/InsertInput/SetInput/AppendInput/OnConflict)\n * marks a dynamic slot. The executor validates the runtime value against\n * the artifact's per-table whitelist metadata, lowers it to Drizzle, and\n * ANDs it with the baked policy — the policy is non-negotiable regardless\n * of what the client sends.\n * - `capability`/`role` predicate leaves resolve to booleans against the\n * caller's claims BEFORE execution, pruning dead branches per caller.\n * - Versioned via `irVersion` + `normalizeIr` (the normalizeSnapshot\n * pattern): executor upgrades decouple from artifact re-pushes.\n */\nimport { z } from 'zod'\nimport { COLUMN_TYPES, type ColumnType } from '../canonical/v2.js'\n\nexport const IR_VERSION = 1 as const\n\n// ---------------------------------------------------------------------------\n// Values & claims\n// ---------------------------------------------------------------------------\n\n/** The exact claim keys the platform stamps — mirrors claims.ts. */\nexport const CLAIMS_CONTRACT = {\n sub: 'string',\n org: 'string?',\n roles: 'string[]',\n capabilities: 'string[]',\n} as const\nexport type ClaimKey = 'sub' | 'org'\n\nconst scalarLiteral = z.union([z.string(), z.number(), z.boolean(), z.null()])\n\nexport const valueIrSchema = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('literal'), value: z.union([scalarLiteral, z.array(scalarLiteral)]) }),\n z.object({ kind: z.literal('variable'), name: z.string() }),\n z.object({ kind: z.literal('claim'), key: z.enum(['sub', 'org']) }),\n])\nexport type ValueIr = z.infer<typeof valueIrSchema>\n\n// ---------------------------------------------------------------------------\n// Predicates\n// ---------------------------------------------------------------------------\n\nexport const CMP_OPS = [\n 'eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'in', 'nin',\n 'like', 'ilike', 'isNull', 'contains', 'hasKey',\n] as const\nexport type CmpOp = (typeof CMP_OPS)[number]\n\nexport type PredIr =\n | { kind: 'and'; operands: PredIr[] }\n | { kind: 'or'; operands: PredIr[] }\n | { kind: 'not'; operand: PredIr }\n | { kind: 'cmp'; op: CmpOp; column: string; value: ValueIr }\n /** EXISTS through a declared link; `where` runs against the target table. */\n | { kind: 'exists'; link: string; where: PredIr }\n /** Aggregation predicate (Hasura `rel_aggregate: { count: { predicate } }`). */\n | { kind: 'aggPredicate'; link: string; fn: 'count'; op: Exclude<CmpOp, 'in' | 'nin' | 'like' | 'ilike' | 'isNull' | 'contains' | 'hasKey'>; value: number; where?: PredIr }\n /** Boolean claims leaves — pre-resolved against claims before execution. */\n | { kind: 'capability'; key: string }\n | { kind: 'role'; key: string }\n /** §4f: a client-supplied BoolExp variable lands here, validated + lowered at runtime. */\n | { kind: 'dynamicFilter'; slot: string }\n | { kind: 'const'; value: boolean }\n\nexport const predIrSchema: z.ZodType<PredIr> = z.lazy(() =>\n z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('and'), operands: z.array(predIrSchema).min(1) }),\n z.object({ kind: z.literal('or'), operands: z.array(predIrSchema).min(1) }),\n z.object({ kind: z.literal('not'), operand: predIrSchema }),\n z.object({ kind: z.literal('cmp'), op: z.enum(CMP_OPS), column: z.string(), value: valueIrSchema }),\n z.object({ kind: z.literal('exists'), link: z.string(), where: predIrSchema }),\n z.object({\n kind: z.literal('aggPredicate'), link: z.string(), fn: z.literal('count'),\n op: z.enum(['eq', 'neq', 'gt', 'gte', 'lt', 'lte']), value: z.number(),\n where: predIrSchema.optional(),\n }),\n z.object({ kind: z.literal('capability'), key: z.string() }),\n z.object({ kind: z.literal('role'), key: z.string() }),\n z.object({ kind: z.literal('dynamicFilter'), slot: z.string() }),\n z.object({ kind: z.literal('const'), value: z.boolean() }),\n ]),\n) as z.ZodType<PredIr>\n\n// ---------------------------------------------------------------------------\n// Ordering / paging\n// ---------------------------------------------------------------------------\n\nexport const orderIrSchema = z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal('column'),\n column: z.string(),\n /** Order through a to-one link: `link` is set and `column` is on the target. */\n link: z.string().optional(),\n direction: z.enum(['asc', 'desc']),\n nulls: z.enum(['first', 'last']).optional(),\n }),\n /** §4f: `$orderBy: [FooOrderBy!]` variable — validated + lowered at runtime. */\n z.object({ kind: z.literal('dynamic'), slot: z.string() }),\n])\nexport type OrderIr = z.infer<typeof orderIrSchema>\n\nexport const limitIrSchema = z.object({\n /** Fixed value or a variable, clamped to [1, max]; absent → default. */\n variable: z.string().optional(),\n value: z.number().int().positive().optional(),\n default: z.number().int().positive(),\n max: z.number().int().positive(),\n})\nexport type LimitIr = z.infer<typeof limitIrSchema>\n\n// ---------------------------------------------------------------------------\n// Selections\n// ---------------------------------------------------------------------------\n\nexport interface SelectionIr {\n /** GraphQL type name for __typename synthesis + Apollo normalization. */\n typename: string\n columns: Array<{ alias: string; column: string }>\n relations: Array<{\n alias: string\n link: string\n selection: SelectionIr\n /** Fixed shape from the document; policy for the target table is ALSO\n * injected by the compiler into this `where` — never trust it absent. */\n where?: PredIr\n orderBy?: OrderIr[]\n limit?: LimitIr\n offset?: { variable?: string; value?: number }\n }>\n aggregates: Array<{\n alias: string\n /** Absent link = same-table aggregate (used by aggregate roots). */\n link?: string\n where?: PredIr\n count?: { columns?: string[]; distinct?: boolean }\n sum?: string[]\n avg?: string[]\n /** `nodes { }` selection inside an aggregate block. */\n nodes?: SelectionIr\n }>\n}\n\nconst selectionIrSchema: z.ZodType<SelectionIr> = z.lazy(() =>\n z.object({\n typename: z.string(),\n columns: z.array(z.object({ alias: z.string(), column: z.string() })),\n relations: z.array(z.object({\n alias: z.string(),\n link: z.string(),\n selection: selectionIrSchema,\n where: predIrSchema.optional(),\n orderBy: z.array(orderIrSchema).optional(),\n limit: limitIrSchema.optional(),\n offset: z.object({ variable: z.string().optional(), value: z.number().int().optional() }).optional(),\n })),\n aggregates: z.array(z.object({\n alias: z.string(),\n link: z.string().optional(),\n where: predIrSchema.optional(),\n count: z.object({ columns: z.array(z.string()).optional(), distinct: z.boolean().optional() }).optional(),\n sum: z.array(z.string()).optional(),\n avg: z.array(z.string()).optional(),\n nodes: selectionIrSchema.optional(),\n })),\n }),\n) as z.ZodType<SelectionIr>\n\nexport { selectionIrSchema }\n\n// ---------------------------------------------------------------------------\n// Roots\n// ---------------------------------------------------------------------------\n\n/** `@include(if: $var)` / `@skip(if: $var)` on a root field. */\nconst includeIfSchema = z.object({ variable: z.string(), negated: z.boolean() })\n\nconst selectRootSchema = z.object({\n kind: z.literal('select'),\n alias: z.string(),\n table: z.string(),\n selection: selectionIrSchema,\n /** Composed at compile time: AND(policy, documentWhere?, dynamicFilter?). */\n where: predIrSchema,\n orderBy: z.array(orderIrSchema).default([]),\n distinctOn: z.union([z.array(z.string()), z.object({ slot: z.string() })]).optional(),\n limit: limitIrSchema,\n offset: z.object({ variable: z.string().optional(), value: z.number().int().optional() }).optional(),\n includeIf: includeIfSchema.optional(),\n})\n\nconst byPkRootSchema = z.object({\n kind: z.literal('byPk'),\n alias: z.string(),\n table: z.string(),\n selection: selectionIrSchema,\n pk: z.array(z.object({ column: z.string(), value: valueIrSchema })).min(1),\n /** Policy predicate — ANDed with the PK match. */\n where: predIrSchema,\n includeIf: includeIfSchema.optional(),\n})\n\nconst aggregateRootSchema = z.object({\n kind: z.literal('aggregate'),\n alias: z.string(),\n table: z.string(),\n where: predIrSchema,\n count: z.object({ columns: z.array(z.string()).optional(), distinct: z.boolean().optional() }).optional(),\n sum: z.array(z.string()).optional(),\n avg: z.array(z.string()).optional(),\n nodes: selectionIrSchema.optional(),\n includeIf: includeIfSchema.optional(),\n})\n\n/** Column → value map for _set/_append/_inc, or a §4f whole-input slot. */\nconst writeValuesSchema = z.union([\n z.object({ slot: z.string() }),\n z.object({ entries: z.array(z.object({ column: z.string(), value: valueIrSchema })) }),\n])\n\nconst onConflictIrSchema = z.union([\n z.object({ slot: z.string() }),\n z.object({ constraint: z.string(), updateColumns: z.array(z.string()) }),\n])\n\nconst mutationRootSchema = z.object({\n kind: z.literal('mutation'),\n op: z.enum(['insert', 'insertOne', 'update', 'updateByPk', 'delete', 'deleteByPk']),\n alias: z.string(),\n table: z.string(),\n /** insert/insertOne: rows come from a slot ($object/$objects) or literals. */\n objects: z.union([\n z.object({ slot: z.string() }),\n z.object({ rows: z.array(z.array(z.object({ column: z.string(), value: valueIrSchema }))) }),\n ]).optional(),\n /** Server-pinned columns (e.g. author_sub ← claim('sub')) merged into every inserted row. */\n pinnedColumns: z.array(z.object({ column: z.string(), value: valueIrSchema })).default([]),\n onConflict: onConflictIrSchema.optional(),\n set: writeValuesSchema.optional(),\n append: writeValuesSchema.optional(),\n inc: writeValuesSchema.optional(),\n /** update/delete row filter: AND(writePolicy, documentWhere/pk, dynamicFilter?). */\n where: predIrSchema.optional(),\n pk: z.array(z.object({ column: z.string(), value: valueIrSchema })).optional(),\n /** WITH CHECK analogue evaluated against NEW row values (insert/update). */\n insertCheck: predIrSchema.optional(),\n returning: selectionIrSchema.nullable(),\n affectedRows: z.boolean().default(false),\n includeIf: includeIfSchema.optional(),\n})\n\nconst actionRootSchema = z.object({\n kind: z.literal('action'),\n alias: z.string(),\n name: z.string(),\n params: z.array(z.object({ name: z.string(), value: valueIrSchema })),\n returns: z.enum(['rows', 'rowsAffected', 'scalar']),\n})\n\nexport const rootIrSchema = z.discriminatedUnion('kind', [\n selectRootSchema, byPkRootSchema, aggregateRootSchema, mutationRootSchema, actionRootSchema,\n])\nexport type RootIr = z.infer<typeof rootIrSchema>\n\n// ---------------------------------------------------------------------------\n// Variables (§4f dynamic slots) & operations\n// ---------------------------------------------------------------------------\n\nexport const INPUT_REF_KINDS = [\n 'boolExp', 'orderBy', 'selectColumn', 'insertInput', 'setInput', 'appendInput', 'onConflict',\n] as const\nexport type InputRefKind = (typeof INPUT_REF_KINDS)[number]\n\n/**\n * A declared GraphQL variable default, persisted verbatim so an omitted\n * variable resolves to it instead of silently becoming NULL. Wrapped in an\n * object so an explicit `= null` stays distinguishable from \"no default\".\n * Only shapes `ValueIr` can carry are representable — the restrict pass\n * rejects anything else (including §4f slot defaults) at compile time.\n */\nexport const variableDefaultIrSchema = z.object({\n value: z.union([scalarLiteral, z.array(scalarLiteral)]),\n})\nexport type VariableDefaultIr = z.infer<typeof variableDefaultIrSchema>\n\nexport const variableIrSchema = z.object({\n name: z.string(),\n type: z.union([\n z.object({ kind: z.literal('scalar'), scalar: z.enum(COLUMN_TYPES) }),\n /** `values` is the declared membership whitelist — the executor validates against it. */\n z.object({ kind: z.literal('enum'), name: z.string(), values: z.array(z.string()).min(1) }),\n /** §4f dynamic slot: validated against `tables[table]` whitelists at runtime. */\n z.object({ kind: z.literal('inputRef'), input: z.enum(INPUT_REF_KINDS), table: z.string() }),\n ]),\n nullable: z.boolean(),\n list: z.boolean(),\n /** Absent = no default declared; see {@link variableDefaultIrSchema}. */\n defaultValue: variableDefaultIrSchema.optional(),\n})\nexport type VariableIr = z.infer<typeof variableIrSchema>\n\nexport const compiledOperationSchema = z.object({\n irVersion: z.literal(IR_VERSION),\n name: z.string(),\n opHash: z.string().regex(/^sha256:[0-9a-f]{64}$/),\n kind: z.enum(['query', 'mutation', 'action']),\n requires: z.object({\n capability: z.string().optional(),\n role: z.string().optional(),\n }).nullable(),\n variables: z.array(variableIrSchema),\n /** Every table the op touches — data-token scoping + audit. */\n tableSet: z.array(z.string()).min(1),\n roots: z.array(rootIrSchema).min(1),\n})\nexport type CompiledOperation = z.infer<typeof compiledOperationSchema>\n\n// ---------------------------------------------------------------------------\n// Artifact: per-table runtime metadata + the operation set\n// ---------------------------------------------------------------------------\n\n/**\n * Runtime whitelist metadata per table — everything the executor needs to\n * build Drizzle table objects, validate §4f dynamic inputs, and lower them.\n * Derived from the canonical definition at compile time.\n */\nexport const tableMetaIrSchema = z.object({\n table: z.string(),\n schema: z.string(),\n typename: z.string(),\n columns: z.array(z.object({\n name: z.string(),\n columnName: z.string(),\n type: z.union([z.enum(COLUMN_TYPES), z.object({ enum: z.string(), values: z.array(z.string()) })]),\n nullable: z.boolean(),\n })),\n primaryKey: z.array(z.string()).min(1),\n links: z.array(z.object({\n name: z.string(),\n kind: z.enum(['toOne', 'toMany', 'toPlatformUser']),\n target: z.string(),\n on: z.string(),\n references: z.string(),\n })),\n /** §4f whitelists: what dynamic inputs may reference. */\n filterable: z.array(z.string()),\n orderable: z.array(z.string()),\n insertable: z.array(z.string()),\n settable: z.array(z.string()),\n appendable: z.array(z.string()),\n constraints: z.array(z.object({ name: z.string(), columns: z.array(z.string()) })),\n /** Depth/node caps for dynamic filter trees on this table. */\n dynamicFilterMaxDepth: z.number().int().positive().default(6),\n dynamicFilterMaxNodes: z.number().int().positive().default(64),\n})\nexport type TableMetaIr = z.infer<typeof tableMetaIrSchema>\n\nexport const compiledArtifactSchema = z.object({\n irVersion: z.literal(IR_VERSION),\n namespace: z.string(),\n schemaHash: z.string(),\n opsHash: z.string(),\n tables: z.record(z.string(), tableMetaIrSchema),\n operations: z.record(z.string(), compiledOperationSchema),\n})\nexport type CompiledArtifact = z.infer<typeof compiledArtifactSchema>\n\n// ---------------------------------------------------------------------------\n// Versioning shim\n// ---------------------------------------------------------------------------\n\nexport class IrVersionError extends Error {\n constructor(found: unknown) {\n super(`Unsupported IR version ${String(found)} — this executor supports up to ${IR_VERSION}. ` +\n 'Upgrade @sequenceholdings/orm or re-push the namespace.')\n this.name = 'IrVersionError'\n }\n}\n\n/**\n * Validate + normalize a raw registry artifact (the normalizeSnapshot\n * pattern): future IR versions add upgrade branches here so executor\n * upgrades decouple from artifact re-pushes. Never trust registry jsonb —\n * the data plane calls this on every artifact load.\n */\nexport function normalizeIr(raw: unknown): CompiledArtifact {\n if (!raw || typeof raw !== 'object') throw new IrVersionError(undefined)\n const version = (raw as { irVersion?: unknown }).irVersion\n if (version !== IR_VERSION) throw new IrVersionError(version)\n return compiledArtifactSchema.parse(raw)\n}\n\n/** Index an artifact's operations by opHash (the wire selector). */\nexport function indexByHash(artifact: CompiledArtifact): Map<string, CompiledOperation> {\n const map = new Map<string, CompiledOperation>()\n for (const op of Object.values(artifact.operations)) map.set(op.opHash, op)\n return map\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ColumnType } from './canonical.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* graphql-default (Hasura-style) camelCase naming for the v2 SDL generator.
|
|
5
|
+
*
|
|
6
|
+
* Verified against the bios marketplace corpus
|
|
7
|
+
* (~/test/apps/marketplace/src/graphql, 871 ops):
|
|
8
|
+
* - input types are singular PascalCase + suffix (`VideoClipBoolExp`,
|
|
9
|
+
* `UserOrderBy`, `ProfileInsertInput`, `ThirdPartyIntegrationOnConflict`)
|
|
10
|
+
* - roots keep the table's plurality camelCased (`videoClips`, `profileByPk`,
|
|
11
|
+
* `profileAggregate`, `insertProfileOne`, `updateUserByPk`)
|
|
12
|
+
* - order enum values: ASC / ASC_NULLS_FIRST / ... / DESC_NULLS_LAST
|
|
13
|
+
* - SelectColumn / UpdateColumn enum values are camelCase field names
|
|
14
|
+
* (`distinctOn: [role]`, `updateColumns: [sceneFile, buyerTagId]`)
|
|
15
|
+
* - constraint enum values are raw Postgres constraint names
|
|
16
|
+
* (`static_ad_pkey`, `audience_profile_id_name_key`)
|
|
17
|
+
* - mutation args keep `_set` / `_append` / `_inc` underscores; everything
|
|
18
|
+
* else camelCases (`pkColumns`, `updateColumns`, `distinctOn`,
|
|
19
|
+
* `affectedRows`, `returning`)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** `deal_comments` → `dealComments`. Preserves already-camelCase input. */
|
|
23
|
+
declare function camelCase(name: string): string;
|
|
24
|
+
/** `deal_comments` → `DealComments`. */
|
|
25
|
+
declare function pascalCase(name: string): string;
|
|
26
|
+
/** GraphQL object type name: `deal_comments` → `DealComment` (last word singularized). */
|
|
27
|
+
declare function typeName(table: string): string;
|
|
28
|
+
/** Column → GraphQL field name: `author_sub` → `authorSub`. */
|
|
29
|
+
declare function fieldName(column: string): string;
|
|
30
|
+
/** Postgres enum name → GraphQL enum type name: `deal_status` → `DealStatus`. */
|
|
31
|
+
declare function enumTypeName(name: string): string;
|
|
32
|
+
/** GraphQL type → comparison input name: `String` → `StringComparisonExp`, `uuid` → `UuidComparisonExp`. */
|
|
33
|
+
declare function comparisonExpName(gqlTypeName: string): string;
|
|
34
|
+
declare function graphqlScalarFor(type: ColumnType): string;
|
|
35
|
+
declare function columnTypeForScalar(scalarName: string): ColumnType | undefined;
|
|
36
|
+
/** Every GraphQL scalar name usable as a variable type — for diagnostics. */
|
|
37
|
+
declare const VARIABLE_SCALAR_NAMES: readonly string[];
|
|
38
|
+
/** The custom scalars every generated schema declares (plan §3). */
|
|
39
|
+
declare const CUSTOM_SCALARS: readonly ["bigint", "date", "jsonb", "numeric", "timestamptz", "uuid"];
|
|
40
|
+
/** Column types eligible for sum/avg aggregates and `_inc` updates. */
|
|
41
|
+
declare const NUMERICISH_COLUMN_TYPES: readonly ColumnType[];
|
|
42
|
+
declare const ORDER_BY_ENUM = "OrderBy";
|
|
43
|
+
declare const ORDER_BY_ENUM_VALUES: readonly ["ASC", "ASC_NULLS_FIRST", "ASC_NULLS_LAST", "DESC", "DESC_NULLS_FIRST", "DESC_NULLS_LAST"];
|
|
44
|
+
/** The built-in read-only platform users entity (plan §4b). */
|
|
45
|
+
declare const PLATFORM_USER_TYPENAME = "PlatformUser";
|
|
46
|
+
/** Every generated GraphQL name derived from one table name. */
|
|
47
|
+
interface TableNames {
|
|
48
|
+
typename: string;
|
|
49
|
+
selectRoot: string;
|
|
50
|
+
byPkRoot: string;
|
|
51
|
+
aggregateRoot: string;
|
|
52
|
+
insertRoot: string;
|
|
53
|
+
insertOneRoot: string;
|
|
54
|
+
updateRoot: string;
|
|
55
|
+
updateByPkRoot: string;
|
|
56
|
+
deleteRoot: string;
|
|
57
|
+
deleteByPkRoot: string;
|
|
58
|
+
boolExp: string;
|
|
59
|
+
orderBy: string;
|
|
60
|
+
selectColumn: string;
|
|
61
|
+
insertInput: string;
|
|
62
|
+
setInput: string;
|
|
63
|
+
appendInput: string;
|
|
64
|
+
incInput: string;
|
|
65
|
+
onConflict: string;
|
|
66
|
+
pkColumnsInput: string;
|
|
67
|
+
constraintEnum: string;
|
|
68
|
+
updateColumnEnum: string;
|
|
69
|
+
mutationResponse: string;
|
|
70
|
+
aggregate: string;
|
|
71
|
+
aggregateFields: string;
|
|
72
|
+
sumFields: string;
|
|
73
|
+
avgFields: string;
|
|
74
|
+
aggregateBoolExp: string;
|
|
75
|
+
aggregateBoolExpCount: string;
|
|
76
|
+
}
|
|
77
|
+
declare function tableNames(table: string): TableNames;
|
|
78
|
+
|
|
79
|
+
export { CUSTOM_SCALARS as C, NUMERICISH_COLUMN_TYPES as N, ORDER_BY_ENUM as O, PLATFORM_USER_TYPENAME as P, type TableNames as T, VARIABLE_SCALAR_NAMES as V, ORDER_BY_ENUM_VALUES as a, columnTypeForScalar as b, camelCase as c, comparisonExpName as d, enumTypeName as e, fieldName as f, graphqlScalarFor as g, typeName as h, pascalCase as p, tableNames as t };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ColumnType } from './canonical.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* graphql-default (Hasura-style) camelCase naming for the v2 SDL generator.
|
|
5
|
+
*
|
|
6
|
+
* Verified against the bios marketplace corpus
|
|
7
|
+
* (~/test/apps/marketplace/src/graphql, 871 ops):
|
|
8
|
+
* - input types are singular PascalCase + suffix (`VideoClipBoolExp`,
|
|
9
|
+
* `UserOrderBy`, `ProfileInsertInput`, `ThirdPartyIntegrationOnConflict`)
|
|
10
|
+
* - roots keep the table's plurality camelCased (`videoClips`, `profileByPk`,
|
|
11
|
+
* `profileAggregate`, `insertProfileOne`, `updateUserByPk`)
|
|
12
|
+
* - order enum values: ASC / ASC_NULLS_FIRST / ... / DESC_NULLS_LAST
|
|
13
|
+
* - SelectColumn / UpdateColumn enum values are camelCase field names
|
|
14
|
+
* (`distinctOn: [role]`, `updateColumns: [sceneFile, buyerTagId]`)
|
|
15
|
+
* - constraint enum values are raw Postgres constraint names
|
|
16
|
+
* (`static_ad_pkey`, `audience_profile_id_name_key`)
|
|
17
|
+
* - mutation args keep `_set` / `_append` / `_inc` underscores; everything
|
|
18
|
+
* else camelCases (`pkColumns`, `updateColumns`, `distinctOn`,
|
|
19
|
+
* `affectedRows`, `returning`)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** `deal_comments` → `dealComments`. Preserves already-camelCase input. */
|
|
23
|
+
declare function camelCase(name: string): string;
|
|
24
|
+
/** `deal_comments` → `DealComments`. */
|
|
25
|
+
declare function pascalCase(name: string): string;
|
|
26
|
+
/** GraphQL object type name: `deal_comments` → `DealComment` (last word singularized). */
|
|
27
|
+
declare function typeName(table: string): string;
|
|
28
|
+
/** Column → GraphQL field name: `author_sub` → `authorSub`. */
|
|
29
|
+
declare function fieldName(column: string): string;
|
|
30
|
+
/** Postgres enum name → GraphQL enum type name: `deal_status` → `DealStatus`. */
|
|
31
|
+
declare function enumTypeName(name: string): string;
|
|
32
|
+
/** GraphQL type → comparison input name: `String` → `StringComparisonExp`, `uuid` → `UuidComparisonExp`. */
|
|
33
|
+
declare function comparisonExpName(gqlTypeName: string): string;
|
|
34
|
+
declare function graphqlScalarFor(type: ColumnType): string;
|
|
35
|
+
declare function columnTypeForScalar(scalarName: string): ColumnType | undefined;
|
|
36
|
+
/** Every GraphQL scalar name usable as a variable type — for diagnostics. */
|
|
37
|
+
declare const VARIABLE_SCALAR_NAMES: readonly string[];
|
|
38
|
+
/** The custom scalars every generated schema declares (plan §3). */
|
|
39
|
+
declare const CUSTOM_SCALARS: readonly ["bigint", "date", "jsonb", "numeric", "timestamptz", "uuid"];
|
|
40
|
+
/** Column types eligible for sum/avg aggregates and `_inc` updates. */
|
|
41
|
+
declare const NUMERICISH_COLUMN_TYPES: readonly ColumnType[];
|
|
42
|
+
declare const ORDER_BY_ENUM = "OrderBy";
|
|
43
|
+
declare const ORDER_BY_ENUM_VALUES: readonly ["ASC", "ASC_NULLS_FIRST", "ASC_NULLS_LAST", "DESC", "DESC_NULLS_FIRST", "DESC_NULLS_LAST"];
|
|
44
|
+
/** The built-in read-only platform users entity (plan §4b). */
|
|
45
|
+
declare const PLATFORM_USER_TYPENAME = "PlatformUser";
|
|
46
|
+
/** Every generated GraphQL name derived from one table name. */
|
|
47
|
+
interface TableNames {
|
|
48
|
+
typename: string;
|
|
49
|
+
selectRoot: string;
|
|
50
|
+
byPkRoot: string;
|
|
51
|
+
aggregateRoot: string;
|
|
52
|
+
insertRoot: string;
|
|
53
|
+
insertOneRoot: string;
|
|
54
|
+
updateRoot: string;
|
|
55
|
+
updateByPkRoot: string;
|
|
56
|
+
deleteRoot: string;
|
|
57
|
+
deleteByPkRoot: string;
|
|
58
|
+
boolExp: string;
|
|
59
|
+
orderBy: string;
|
|
60
|
+
selectColumn: string;
|
|
61
|
+
insertInput: string;
|
|
62
|
+
setInput: string;
|
|
63
|
+
appendInput: string;
|
|
64
|
+
incInput: string;
|
|
65
|
+
onConflict: string;
|
|
66
|
+
pkColumnsInput: string;
|
|
67
|
+
constraintEnum: string;
|
|
68
|
+
updateColumnEnum: string;
|
|
69
|
+
mutationResponse: string;
|
|
70
|
+
aggregate: string;
|
|
71
|
+
aggregateFields: string;
|
|
72
|
+
sumFields: string;
|
|
73
|
+
avgFields: string;
|
|
74
|
+
aggregateBoolExp: string;
|
|
75
|
+
aggregateBoolExpCount: string;
|
|
76
|
+
}
|
|
77
|
+
declare function tableNames(table: string): TableNames;
|
|
78
|
+
|
|
79
|
+
export { CUSTOM_SCALARS as C, NUMERICISH_COLUMN_TYPES as N, ORDER_BY_ENUM as O, PLATFORM_USER_TYPENAME as P, type TableNames as T, VARIABLE_SCALAR_NAMES as V, ORDER_BY_ENUM_VALUES as a, columnTypeForScalar as b, camelCase as c, comparisonExpName as d, enumTypeName as e, fieldName as f, graphqlScalarFor as g, typeName as h, pascalCase as p, tableNames as t };
|