@sequenceholdings/orm 0.1.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 +37 -0
- package/dist/cli.cjs +2369 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +9 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.js +2364 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.cjs +223 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +171 -0
- package/dist/client.d.ts +171 -0
- package/dist/client.js +217 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +2308 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +830 -0
- package/dist/index.d.ts +830 -0
- package/dist/index.js +2204 -0
- package/dist/index.js.map +1 -0
- package/package.json +70 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { generateDrizzleJson } from 'drizzle-kit/api';
|
|
3
|
+
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom Roles & Capabilities manifest grammar — the `capabilities.roles`
|
|
7
|
+
* block and the `capabilities.uses` pin set. This is a VERBATIM mirror of the
|
|
8
|
+
* platform's canonical grammar so an ORM namespace declares roles/capabilities
|
|
9
|
+
* the exact same way an artifact or managed function does; apply feeds it to
|
|
10
|
+
* the shared `reconcileHostRegistryOnActivation` reconciler untouched.
|
|
11
|
+
*
|
|
12
|
+
* Canonical sources — keep the grammar in sync by hand (schema shape, key
|
|
13
|
+
* regexes, limits, and superRefine rules). The behavioral guards in
|
|
14
|
+
* definitions.test.ts exercise this copy (inherit cycle, unknown grant,
|
|
15
|
+
* pin-names-role, key collision) so a drifted rule fails there:
|
|
16
|
+
* atlas/src/server/services/custom-roles/manifest-block.ts (server)
|
|
17
|
+
* shared/services/artifact-studio/src/manifest-custom-roles.ts (CLI)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Manifest-declared custom roles & capabilities. Roles and capabilities are
|
|
22
|
+
* both `custom_role` FGA objects; deploy reconciliation turns this block into
|
|
23
|
+
* the structural waterfall edges (role→capability / senior→junior `assignee`
|
|
24
|
+
* userset tuples) — nothing else. The host floor is enforced app-layer at the
|
|
25
|
+
* resolution points, never in the model. Runtime grants (user/group/org →
|
|
26
|
+
* role) are NEVER declared here — they are written through host-admin-gated
|
|
27
|
+
* endpoints.
|
|
28
|
+
*/
|
|
29
|
+
declare const customRolesBlockSchema: z.ZodObject<{
|
|
30
|
+
definitions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
31
|
+
description: z.ZodOptional<z.ZodString>;
|
|
32
|
+
default: z.ZodDefault<z.ZodBoolean>;
|
|
33
|
+
inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
34
|
+
grants: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
35
|
+
}, z.core.$strip>>>;
|
|
36
|
+
capabilities: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
37
|
+
description: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
type CustomRolesBlock = z.infer<typeof customRolesBlockSchema>;
|
|
41
|
+
/** True when the block declares at least one role or capability. */
|
|
42
|
+
declare function customRolesDeclared(block: CustomRolesBlock | null | undefined): boolean;
|
|
43
|
+
declare const capabilityPinsSchema: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
44
|
+
interface ParsedCapabilityPin {
|
|
45
|
+
scope: 'org' | 'host';
|
|
46
|
+
key: string;
|
|
47
|
+
}
|
|
48
|
+
/** Split a pin into its scope and key. Assumes the pin grammar validated. */
|
|
49
|
+
declare function parseCapabilityPin(pin: string): ParsedCapabilityPin;
|
|
50
|
+
/**
|
|
51
|
+
* Cross-field pin validation (the `uses` array and the roles block are
|
|
52
|
+
* siblings under `capabilities`). Purely structural — registry existence
|
|
53
|
+
* checks are server-side, at activation, where atomicity lives.
|
|
54
|
+
*/
|
|
55
|
+
declare function validateCapabilityPins({ uses, roles, }: {
|
|
56
|
+
uses: readonly string[];
|
|
57
|
+
roles: CustomRolesBlock | null | undefined;
|
|
58
|
+
}): string[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The reserved `namespace.yaml` — namespace-level settings beside the table
|
|
62
|
+
* files. `capabilities` is the platform's Custom Roles manifest block, authored
|
|
63
|
+
* exactly as an artifact or managed function authors it:
|
|
64
|
+
* - `capabilities.roles.capabilities` declares namespace-scoped capabilities
|
|
65
|
+
* (published on the namespace's registry scope + pinned at apply),
|
|
66
|
+
* - `capabilities.roles.definitions` declares roles (grants + inherits) that
|
|
67
|
+
* bundle those capabilities,
|
|
68
|
+
* - `capabilities.uses` attaches EXISTING capabilities — `org/<key>` for an
|
|
69
|
+
* org capability (namespaces never create org entities), or a bare `<key>`
|
|
70
|
+
* already published on the namespace scope.
|
|
71
|
+
* Apply feeds this block straight to the shared attachment reconciler, so the
|
|
72
|
+
* capabilities are grantable in Custom Roles and enter claim resolution.
|
|
73
|
+
*/
|
|
74
|
+
declare const namespaceConfigSchema: z.ZodObject<{
|
|
75
|
+
namespace: z.ZodString;
|
|
76
|
+
description: z.ZodOptional<z.ZodString>;
|
|
77
|
+
capabilities: z.ZodOptional<z.ZodObject<{
|
|
78
|
+
roles: z.ZodOptional<z.ZodObject<{
|
|
79
|
+
definitions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
80
|
+
description: z.ZodOptional<z.ZodString>;
|
|
81
|
+
default: z.ZodDefault<z.ZodBoolean>;
|
|
82
|
+
inherits: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
83
|
+
grants: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
84
|
+
}, z.core.$strip>>>;
|
|
85
|
+
capabilities: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
86
|
+
description: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>>>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
uses: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
|
|
90
|
+
}, z.core.$strict>>;
|
|
91
|
+
}, z.core.$strict>;
|
|
92
|
+
type NamespaceConfig = z.output<typeof namespaceConfigSchema>;
|
|
93
|
+
|
|
94
|
+
declare const actionParamSchema: z.ZodObject<{
|
|
95
|
+
type: z.ZodEnum<{
|
|
96
|
+
bigint: "bigint";
|
|
97
|
+
boolean: "boolean";
|
|
98
|
+
uuid: "uuid";
|
|
99
|
+
text: "text";
|
|
100
|
+
integer: "integer";
|
|
101
|
+
numeric: "numeric";
|
|
102
|
+
double: "double";
|
|
103
|
+
timestamptz: "timestamptz";
|
|
104
|
+
date: "date";
|
|
105
|
+
jsonb: "jsonb";
|
|
106
|
+
}>;
|
|
107
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
description: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, z.core.$strict>;
|
|
110
|
+
interface ValidatesEntry {
|
|
111
|
+
readonly source: string;
|
|
112
|
+
readonly table: string;
|
|
113
|
+
readonly param: string;
|
|
114
|
+
}
|
|
115
|
+
declare const AUDIT_ACTIONS: readonly ["create", "update", "delete"];
|
|
116
|
+
declare const actionSchema: z.ZodObject<{
|
|
117
|
+
description: z.ZodOptional<z.ZodString>;
|
|
118
|
+
requires: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
|
|
119
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
120
|
+
type: z.ZodEnum<{
|
|
121
|
+
bigint: "bigint";
|
|
122
|
+
boolean: "boolean";
|
|
123
|
+
uuid: "uuid";
|
|
124
|
+
text: "text";
|
|
125
|
+
integer: "integer";
|
|
126
|
+
numeric: "numeric";
|
|
127
|
+
double: "double";
|
|
128
|
+
timestamptz: "timestamptz";
|
|
129
|
+
date: "date";
|
|
130
|
+
jsonb: "jsonb";
|
|
131
|
+
}>;
|
|
132
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
description: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, z.core.$strict>>>;
|
|
135
|
+
validates: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<ValidatesEntry, string>>>>;
|
|
136
|
+
executes: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
137
|
+
returns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
138
|
+
bigint: "bigint";
|
|
139
|
+
boolean: "boolean";
|
|
140
|
+
uuid: "uuid";
|
|
141
|
+
text: "text";
|
|
142
|
+
integer: "integer";
|
|
143
|
+
numeric: "numeric";
|
|
144
|
+
double: "double";
|
|
145
|
+
timestamptz: "timestamptz";
|
|
146
|
+
date: "date";
|
|
147
|
+
jsonb: "jsonb";
|
|
148
|
+
}>>>;
|
|
149
|
+
audit: z.ZodOptional<z.ZodObject<{
|
|
150
|
+
action: z.ZodEnum<{
|
|
151
|
+
create: "create";
|
|
152
|
+
update: "update";
|
|
153
|
+
delete: "delete";
|
|
154
|
+
}>;
|
|
155
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
156
|
+
}, z.core.$strict>>;
|
|
157
|
+
}, z.core.$strict>;
|
|
158
|
+
type ActionDefinition = z.output<typeof actionSchema>;
|
|
159
|
+
declare function extractNamedParams(sql: string): string[];
|
|
160
|
+
|
|
161
|
+
declare const COLUMN_TYPES: readonly ["uuid", "text", "integer", "bigint", "numeric", "double", "boolean", "timestamptz", "date", "jsonb"];
|
|
162
|
+
type ColumnType = (typeof COLUMN_TYPES)[number];
|
|
163
|
+
declare const columnTypeSchema: z.ZodEnum<{
|
|
164
|
+
bigint: "bigint";
|
|
165
|
+
boolean: "boolean";
|
|
166
|
+
uuid: "uuid";
|
|
167
|
+
text: "text";
|
|
168
|
+
integer: "integer";
|
|
169
|
+
numeric: "numeric";
|
|
170
|
+
double: "double";
|
|
171
|
+
timestamptz: "timestamptz";
|
|
172
|
+
date: "date";
|
|
173
|
+
jsonb: "jsonb";
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* True when the default is one of the allowlisted SQL function calls for its
|
|
177
|
+
* type — the ONLY defaults the engine may emit as raw SQL. Everything else
|
|
178
|
+
* is a literal value; in particular a text default that happens to end in
|
|
179
|
+
* `()` is data, never code.
|
|
180
|
+
*/
|
|
181
|
+
declare const isFunctionDefault: (value: ColumnDefault, type: ColumnType) => boolean;
|
|
182
|
+
type ColumnDefault = string | number | boolean;
|
|
183
|
+
interface ColumnDefinition {
|
|
184
|
+
readonly type: ColumnType;
|
|
185
|
+
readonly primary_key?: boolean;
|
|
186
|
+
readonly nullable?: boolean;
|
|
187
|
+
readonly unique?: boolean;
|
|
188
|
+
readonly default?: ColumnDefault;
|
|
189
|
+
readonly description?: string;
|
|
190
|
+
readonly renamed_from?: string;
|
|
191
|
+
readonly cast?: string;
|
|
192
|
+
readonly deprecated?: boolean;
|
|
193
|
+
}
|
|
194
|
+
declare const columnSchema: z.ZodObject<{
|
|
195
|
+
type: z.ZodEnum<{
|
|
196
|
+
bigint: "bigint";
|
|
197
|
+
boolean: "boolean";
|
|
198
|
+
uuid: "uuid";
|
|
199
|
+
text: "text";
|
|
200
|
+
integer: "integer";
|
|
201
|
+
numeric: "numeric";
|
|
202
|
+
double: "double";
|
|
203
|
+
timestamptz: "timestamptz";
|
|
204
|
+
date: "date";
|
|
205
|
+
jsonb: "jsonb";
|
|
206
|
+
}>;
|
|
207
|
+
primary_key: z.ZodOptional<z.ZodBoolean>;
|
|
208
|
+
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
209
|
+
unique: z.ZodOptional<z.ZodBoolean>;
|
|
210
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
211
|
+
description: z.ZodOptional<z.ZodString>;
|
|
212
|
+
renamed_from: z.ZodOptional<z.ZodString>;
|
|
213
|
+
cast: z.ZodOptional<z.ZodString>;
|
|
214
|
+
deprecated: z.ZodOptional<z.ZodBoolean>;
|
|
215
|
+
}, z.core.$strict>;
|
|
216
|
+
declare function castParts(cast: string): {
|
|
217
|
+
column: string;
|
|
218
|
+
type: string;
|
|
219
|
+
} | null;
|
|
220
|
+
|
|
221
|
+
declare const linkSchema: z.ZodObject<{
|
|
222
|
+
to: z.ZodString;
|
|
223
|
+
on: z.ZodString;
|
|
224
|
+
enforce: z.ZodOptional<z.ZodBoolean>;
|
|
225
|
+
description: z.ZodOptional<z.ZodString>;
|
|
226
|
+
}, z.core.$strict>;
|
|
227
|
+
declare const indexSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodObject<{
|
|
228
|
+
columns: z.ZodArray<z.ZodString>;
|
|
229
|
+
unique: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
+
name: z.ZodOptional<z.ZodString>;
|
|
231
|
+
}, z.core.$strict>]>, z.ZodTransform<{
|
|
232
|
+
columns: string[];
|
|
233
|
+
unique?: boolean | undefined;
|
|
234
|
+
name?: string | undefined;
|
|
235
|
+
}, string[] | {
|
|
236
|
+
columns: string[];
|
|
237
|
+
unique?: boolean | undefined;
|
|
238
|
+
name?: string | undefined;
|
|
239
|
+
}>>;
|
|
240
|
+
declare const tableFileSchema: z.ZodObject<{
|
|
241
|
+
namespace: z.ZodString;
|
|
242
|
+
table: z.ZodString;
|
|
243
|
+
description: z.ZodOptional<z.ZodString>;
|
|
244
|
+
columns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
245
|
+
type: z.ZodEnum<{
|
|
246
|
+
bigint: "bigint";
|
|
247
|
+
boolean: "boolean";
|
|
248
|
+
uuid: "uuid";
|
|
249
|
+
text: "text";
|
|
250
|
+
integer: "integer";
|
|
251
|
+
numeric: "numeric";
|
|
252
|
+
double: "double";
|
|
253
|
+
timestamptz: "timestamptz";
|
|
254
|
+
date: "date";
|
|
255
|
+
jsonb: "jsonb";
|
|
256
|
+
}>;
|
|
257
|
+
primary_key: z.ZodOptional<z.ZodBoolean>;
|
|
258
|
+
nullable: z.ZodOptional<z.ZodBoolean>;
|
|
259
|
+
unique: z.ZodOptional<z.ZodBoolean>;
|
|
260
|
+
default: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
261
|
+
description: z.ZodOptional<z.ZodString>;
|
|
262
|
+
renamed_from: z.ZodOptional<z.ZodString>;
|
|
263
|
+
cast: z.ZodOptional<z.ZodString>;
|
|
264
|
+
deprecated: z.ZodOptional<z.ZodBoolean>;
|
|
265
|
+
}, z.core.$strict>>>;
|
|
266
|
+
source: z.ZodOptional<z.ZodString>;
|
|
267
|
+
links: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
268
|
+
to: z.ZodString;
|
|
269
|
+
on: z.ZodString;
|
|
270
|
+
enforce: z.ZodOptional<z.ZodBoolean>;
|
|
271
|
+
description: z.ZodOptional<z.ZodString>;
|
|
272
|
+
}, z.core.$strict>>>;
|
|
273
|
+
indexes: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodObject<{
|
|
274
|
+
columns: z.ZodArray<z.ZodString>;
|
|
275
|
+
unique: z.ZodOptional<z.ZodBoolean>;
|
|
276
|
+
name: z.ZodOptional<z.ZodString>;
|
|
277
|
+
}, z.core.$strict>]>, z.ZodTransform<{
|
|
278
|
+
columns: string[];
|
|
279
|
+
unique?: boolean | undefined;
|
|
280
|
+
name?: string | undefined;
|
|
281
|
+
}, string[] | {
|
|
282
|
+
columns: string[];
|
|
283
|
+
unique?: boolean | undefined;
|
|
284
|
+
name?: string | undefined;
|
|
285
|
+
}>>>>;
|
|
286
|
+
policies: z.ZodOptional<z.ZodObject<{
|
|
287
|
+
read: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
|
|
288
|
+
write: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
|
|
289
|
+
}, z.core.$strict>>;
|
|
290
|
+
actions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
291
|
+
description: z.ZodOptional<z.ZodString>;
|
|
292
|
+
requires: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>>;
|
|
293
|
+
params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
294
|
+
type: z.ZodEnum<{
|
|
295
|
+
bigint: "bigint";
|
|
296
|
+
boolean: "boolean";
|
|
297
|
+
uuid: "uuid";
|
|
298
|
+
text: "text";
|
|
299
|
+
integer: "integer";
|
|
300
|
+
numeric: "numeric";
|
|
301
|
+
double: "double";
|
|
302
|
+
timestamptz: "timestamptz";
|
|
303
|
+
date: "date";
|
|
304
|
+
jsonb: "jsonb";
|
|
305
|
+
}>;
|
|
306
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
307
|
+
description: z.ZodOptional<z.ZodString>;
|
|
308
|
+
}, z.core.$strict>>>;
|
|
309
|
+
validates: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<ValidatesEntry, string>>>>;
|
|
310
|
+
executes: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
311
|
+
returns: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
312
|
+
bigint: "bigint";
|
|
313
|
+
boolean: "boolean";
|
|
314
|
+
uuid: "uuid";
|
|
315
|
+
text: "text";
|
|
316
|
+
integer: "integer";
|
|
317
|
+
numeric: "numeric";
|
|
318
|
+
double: "double";
|
|
319
|
+
timestamptz: "timestamptz";
|
|
320
|
+
date: "date";
|
|
321
|
+
jsonb: "jsonb";
|
|
322
|
+
}>>>;
|
|
323
|
+
audit: z.ZodOptional<z.ZodObject<{
|
|
324
|
+
action: z.ZodEnum<{
|
|
325
|
+
create: "create";
|
|
326
|
+
update: "update";
|
|
327
|
+
delete: "delete";
|
|
328
|
+
}>;
|
|
329
|
+
resource: z.ZodOptional<z.ZodString>;
|
|
330
|
+
}, z.core.$strict>>;
|
|
331
|
+
}, z.core.$strict>>>;
|
|
332
|
+
}, z.core.$strict>;
|
|
333
|
+
type TableFile = z.output<typeof tableFileSchema>;
|
|
334
|
+
type LinkDefinition = z.output<typeof linkSchema>;
|
|
335
|
+
type IndexDefinition = z.output<typeof indexSchema>;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The namespace's Custom Roles manifest block — the platform grammar, verbatim
|
|
339
|
+
* (see custom-roles-block.ts). `roles` declares capabilities + roles (grants,
|
|
340
|
+
* inherits); `uses` attaches existing capabilities. Reconciled into the Custom
|
|
341
|
+
* Roles attachment set at apply, so it's grantable and enters claim resolution.
|
|
342
|
+
*/
|
|
343
|
+
interface NamespaceCapabilities {
|
|
344
|
+
readonly roles: CustomRolesBlock;
|
|
345
|
+
readonly uses: readonly string[];
|
|
346
|
+
}
|
|
347
|
+
interface NamespaceDefinition {
|
|
348
|
+
readonly namespace: string;
|
|
349
|
+
readonly description: string | null;
|
|
350
|
+
readonly capabilities: NamespaceCapabilities;
|
|
351
|
+
readonly tables: readonly TableFile[];
|
|
352
|
+
}
|
|
353
|
+
/** The capability claim keys the block declares — bare declarations plus every attach. */
|
|
354
|
+
declare function declaredCapabilityKeys(capabilities: NamespaceCapabilities): Set<string>;
|
|
355
|
+
interface DefinitionFile {
|
|
356
|
+
readonly file: string;
|
|
357
|
+
readonly table: TableFile;
|
|
358
|
+
}
|
|
359
|
+
declare function buildNamespaceDefinition(files: readonly DefinitionFile[], config?: NamespaceConfig): NamespaceDefinition;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Emit the `Tables` type for a namespace — the generic parameter for
|
|
363
|
+
* `createOrmClient<…Tables>`. A `type` alias, deliberately not an
|
|
364
|
+
* `interface`: object type literals carry the implicit index signature that
|
|
365
|
+
* satisfies the client's `Record<string, Record<string, unknown>>`
|
|
366
|
+
* constraint; interfaces don't. Derived from the definitions alone (no
|
|
367
|
+
* database), so generation is deterministic and runs offline.
|
|
368
|
+
*/
|
|
369
|
+
declare function generateNamespaceTypes(definition: NamespaceDefinition): string;
|
|
370
|
+
declare function typesInterfaceName(namespace: string): string;
|
|
371
|
+
declare function actionsInterfaceName(namespace: string): string;
|
|
372
|
+
|
|
373
|
+
declare function buildActionParamsSchema(action: ActionDefinition): z.ZodType<Record<string, unknown>>;
|
|
374
|
+
/** Declared param names in signature order — the function's arg order and the executor's positional-call order. */
|
|
375
|
+
declare const actionParamOrder: (action: ActionDefinition) => string[];
|
|
376
|
+
/** The plpgsql argument name for a declared param — prefixed so it can never collide with a column of the same name inside the executes body. */
|
|
377
|
+
declare const actionParamArg: (name: string) => string;
|
|
378
|
+
/**
|
|
379
|
+
* Compile an action's `executes` (one statement or the ordered list) into the
|
|
380
|
+
* statements of its Postgres function body: `claim('x')`/`capability('k')`
|
|
381
|
+
* become the compiled fail-closed claims expressions (the same SQL policies
|
|
382
|
+
* use), and each `:param` becomes its `p_<name>` plpgsql argument — quoted
|
|
383
|
+
* literals pass through verbatim. A call shape outside the grammar (bad quoting,
|
|
384
|
+
* wrong args) fails loudly here; the build also rejects it in `executesIssues`.
|
|
385
|
+
*/
|
|
386
|
+
declare function compileActionStatements(action: ActionDefinition, renderParam?: (name: string) => string): string[];
|
|
387
|
+
/** Compiled `requires` gate — a SQL boolean over the transaction claims, or null when unguarded. */
|
|
388
|
+
declare function compileActionRequires(action: ActionDefinition): string | null;
|
|
389
|
+
|
|
390
|
+
declare const COMPARE_OPS: readonly ["=", "!=", "<", "<=", ">", ">="];
|
|
391
|
+
type CompareOp = (typeof COMPARE_OPS)[number];
|
|
392
|
+
type Operand = {
|
|
393
|
+
kind: 'column';
|
|
394
|
+
name: string;
|
|
395
|
+
} | {
|
|
396
|
+
kind: 'claim';
|
|
397
|
+
key: string;
|
|
398
|
+
} | {
|
|
399
|
+
kind: 'literal';
|
|
400
|
+
value: string | number | boolean | null;
|
|
401
|
+
};
|
|
402
|
+
type Predicate = {
|
|
403
|
+
kind: 'and';
|
|
404
|
+
operands: readonly Predicate[];
|
|
405
|
+
} | {
|
|
406
|
+
kind: 'or';
|
|
407
|
+
operands: readonly Predicate[];
|
|
408
|
+
} | {
|
|
409
|
+
kind: 'not';
|
|
410
|
+
operand: Predicate;
|
|
411
|
+
} | {
|
|
412
|
+
kind: 'compare';
|
|
413
|
+
op: CompareOp;
|
|
414
|
+
left: Operand;
|
|
415
|
+
right: Operand;
|
|
416
|
+
} | {
|
|
417
|
+
kind: 'capability';
|
|
418
|
+
key: string;
|
|
419
|
+
};
|
|
420
|
+
interface ParsedPredicate {
|
|
421
|
+
readonly source: string;
|
|
422
|
+
readonly ast: Predicate;
|
|
423
|
+
}
|
|
424
|
+
declare function walkPredicate(predicate: Predicate, visit: (node: Predicate) => void): void;
|
|
425
|
+
declare function predicateOperands(predicate: Predicate): Operand[];
|
|
426
|
+
declare function referencedColumns(predicate: Predicate): string[];
|
|
427
|
+
declare function referencedCapabilities(predicate: Predicate): string[];
|
|
428
|
+
|
|
429
|
+
/** Column name → declared type, so claim comparisons can cast to the column's side. */
|
|
430
|
+
type PredicateColumnTypes = Readonly<Record<string, ColumnType>>;
|
|
431
|
+
/** Predicate AST → a parenthesized SQL boolean expression. Never interpolates raw policy text. */
|
|
432
|
+
declare function compilePredicate(predicate: Predicate, columnTypes?: PredicateColumnTypes): string;
|
|
433
|
+
|
|
434
|
+
/** Claims are stamped per transaction by the Data API (`set_config('request.jwt.claims', …, true)`). */
|
|
435
|
+
declare const CLAIMS_SETTING = "request.jwt.claims";
|
|
436
|
+
/** Claims JSON key holding the caller's granted capability pins (a string array). */
|
|
437
|
+
declare const CAPABILITIES_CLAIM_KEY = "capabilities";
|
|
438
|
+
declare const quoteIdentifier: (name: string) => string;
|
|
439
|
+
declare const quoteLiteral: (value: string) => string;
|
|
440
|
+
declare const claimExpression: (key: string) => string;
|
|
441
|
+
/** NULL claims (or a missing capabilities array) coalesce to false — capability checks fail closed. */
|
|
442
|
+
declare const capabilityExpression: (key: string) => string;
|
|
443
|
+
|
|
444
|
+
/** Namespace names become Postgres identifiers (`orm_<ns>` schema, `orm_<ns>_consumer` role) — the tight grammar is a security control, not cosmetics. */
|
|
445
|
+
declare const NAMESPACE_PATTERN: RegExp;
|
|
446
|
+
declare const IDENTIFIER_PATTERN: RegExp;
|
|
447
|
+
declare const MAX_IDENTIFIER_LENGTH = 63;
|
|
448
|
+
/**
|
|
449
|
+
* The Data API carries a delegated, attenuated data token on this header (not
|
|
450
|
+
* `Authorization`, which stays the app-user/session bearer). One definition
|
|
451
|
+
* shared by the client transport, the server's caller resolver, and the
|
|
452
|
+
* function-invoke minter, so all three agree.
|
|
453
|
+
*/
|
|
454
|
+
declare const ORM_DATA_TOKEN_HEADER = "x-sequence-data-token";
|
|
455
|
+
/**
|
|
456
|
+
* The SEPARATE header the invoke proxy uses to hand a managed function its
|
|
457
|
+
* *service* data token — the escalation path. A function receives BOTH this and
|
|
458
|
+
* `ORM_DATA_TOKEN_HEADER`; the default `createOrmClient` reads the user token,
|
|
459
|
+
* the deliberately-named `createServiceOrmClient` reads THIS one. Two distinct
|
|
460
|
+
* headers so reaching for the service identity is always an explicit act, never
|
|
461
|
+
* an accidental default. Both are sent to the Data API on `ORM_DATA_TOKEN_HEADER`
|
|
462
|
+
* — the server stays mode-agnostic and resolves whatever sub the token carries.
|
|
463
|
+
*/
|
|
464
|
+
declare const ORM_SERVICE_DATA_TOKEN_HEADER = "x-sequence-data-token-service";
|
|
465
|
+
/**
|
|
466
|
+
* Custom Roles & Capabilities claim keys as policies reference them: a
|
|
467
|
+
* host-scoped registry key, or an org pin's `org/<key>`. Matches the registry
|
|
468
|
+
* key grammar EXACTLY (`[a-z0-9-]`, 1–64 chars, no `_` — the FGA object-id
|
|
469
|
+
* delimiter) so any capability that's declarable/attachable in namespace.yaml
|
|
470
|
+
* can also be referenced here — a stricter pattern would let a valid key
|
|
471
|
+
* register yet fail at apply (e.g. `org/2fa`, a one-char or digit-led key).
|
|
472
|
+
*/
|
|
473
|
+
declare const CAPABILITY_KEY_PATTERN: RegExp;
|
|
474
|
+
declare const CLAIM_KEY_PATTERN: RegExp;
|
|
475
|
+
/** Qualified reference to a table outside the defining file: `<schema>.<table>`. */
|
|
476
|
+
declare const QUALIFIED_TABLE_PATTERN: RegExp;
|
|
477
|
+
/** Synced reflected sources are restricted to the gold layer. */
|
|
478
|
+
declare const SYNCED_SOURCE_PATTERN: RegExp;
|
|
479
|
+
declare const ORM_SCHEMA_PREFIX = "orm_";
|
|
480
|
+
declare const CONSUMER_ROLE_SUFFIX = "_consumer";
|
|
481
|
+
declare const ormSchemaName: (namespace: string) => string;
|
|
482
|
+
declare const consumerRoleName: (namespace: string) => string;
|
|
483
|
+
declare const DEFINITION_FILE_EXTENSIONS: readonly [".yml", ".yaml"];
|
|
484
|
+
/** Reserved basenames for the namespace-level config file (description, org capability pins). */
|
|
485
|
+
declare const NAMESPACE_CONFIG_FILENAMES: Set<string>;
|
|
486
|
+
declare const HASH_DOMAIN = "sequence-orm-definitions\0";
|
|
487
|
+
/**
|
|
488
|
+
* The one size guard the package owns: a per-file byte cap where the loader
|
|
489
|
+
* reads untrusted YAML into memory — a real failure mode, not a product
|
|
490
|
+
* limit. Counts of tables/indexes/params and policy/SQL lengths are
|
|
491
|
+
* deliberately uncapped; Postgres enforces its own limits loudly at apply.
|
|
492
|
+
*/
|
|
493
|
+
declare const MAX_DEFINITION_FILE_BYTES: number;
|
|
494
|
+
/** `/api/data/<ns>/actions/…` and `/api/data/<ns>/query` share the table path segment. */
|
|
495
|
+
declare const RESERVED_TABLE_NAMES: Set<string>;
|
|
496
|
+
/**
|
|
497
|
+
* The Data API's query-string grammar owns these parameter names — a column
|
|
498
|
+
* with one of them could never be filtered over the wire, so definitions
|
|
499
|
+
* refuse it up front ("validate rejects only what can never work").
|
|
500
|
+
*/
|
|
501
|
+
declare const RESERVED_COLUMN_NAMES: Set<string>;
|
|
502
|
+
|
|
503
|
+
/** drizzle-kit's serialized schema — the diff/replay artifact the registry stores. */
|
|
504
|
+
type NamespaceSnapshot = ReturnType<typeof generateDrizzleJson>;
|
|
505
|
+
declare function generateSnapshot(definition: NamespaceDefinition, previousId?: string): NamespaceSnapshot;
|
|
506
|
+
declare const emptySnapshot: (namespace: string) => NamespaceSnapshot;
|
|
507
|
+
/**
|
|
508
|
+
* Persisted snapshots (registry version rows, committed migrations/meta)
|
|
509
|
+
* outlive drizzle-kit upgrades. `upPgSnapshot` migrates older snapshot
|
|
510
|
+
* formats to the kit's current one; a snapshot that still isn't current
|
|
511
|
+
* after upgrading came from a NEWER kit than this one — fail loudly rather
|
|
512
|
+
* than let the diff silently misread it.
|
|
513
|
+
*/
|
|
514
|
+
declare function normalizeSnapshot(snapshot: NamespaceSnapshot): NamespaceSnapshot;
|
|
515
|
+
declare function diffStatements(previous: NamespaceSnapshot, current: NamespaceSnapshot): Promise<string[]>;
|
|
516
|
+
interface MigrationHints {
|
|
517
|
+
/** ALTER RENAME / ALTER TYPE USING statements to run before the kit diff. */
|
|
518
|
+
readonly statements: string[];
|
|
519
|
+
/** Previous snapshot rewritten so the kit diff never sees the rename/cast. */
|
|
520
|
+
readonly adjusted: NamespaceSnapshot;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Renames and casts are declared in the YAML, never inferred: we emit the
|
|
524
|
+
* statement ourselves and rewrite the previous snapshot to match, so
|
|
525
|
+
* drizzle-kit never faces a create+drop ambiguity (its API resolves those
|
|
526
|
+
* interactively — fatal in a service).
|
|
527
|
+
*/
|
|
528
|
+
declare function applyMigrationHints(previous: NamespaceSnapshot, definition: NamespaceDefinition): MigrationHints;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Whether a kit-emitted statement is one the security pass owns (and so is
|
|
532
|
+
* excluded from the convergence verdict). Exported for direct testing of the
|
|
533
|
+
* classification, which is load-bearing: a false positive silently drops a real
|
|
534
|
+
* pending statement and lets a non-converged schema pass.
|
|
535
|
+
*/
|
|
536
|
+
declare function isOwnedStatement(statement: string): boolean;
|
|
537
|
+
/**
|
|
538
|
+
* The kit-owned statements a live database would still need to match the
|
|
539
|
+
* definition — drizzle-kit's `pushSchema` introspection diffed against the
|
|
540
|
+
* built entities. Empty means the schema converged: what the rehearsal (or
|
|
541
|
+
* any verification) uses as the introspect-level proof that executing the
|
|
542
|
+
* plan actually produced the desired state, not merely that it didn't error.
|
|
543
|
+
*/
|
|
544
|
+
declare function pendingKitStatements({ definition, db, }: {
|
|
545
|
+
definition: NamespaceDefinition;
|
|
546
|
+
/** A drizzle PgDatabase over the target — typed loose because pushSchema's own parameter is `PgDatabase<any>`. */
|
|
547
|
+
db: unknown;
|
|
548
|
+
}): Promise<string[]>;
|
|
549
|
+
|
|
550
|
+
interface DrizzleEntities {
|
|
551
|
+
/** The in-memory schema bag drizzle-kit snapshots (`generateDrizzleJson(imports)`). */
|
|
552
|
+
readonly imports: Record<string, unknown>;
|
|
553
|
+
/** Tables by definition name — the typed handles query execution uses. */
|
|
554
|
+
readonly tables: Record<string, PgTableWithColumns<never>>;
|
|
555
|
+
readonly schemaName: string;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Definitions → runtime Drizzle entities. Tables build in dependency order so
|
|
559
|
+
* enforced links can reference their target's built column; policies attach in
|
|
560
|
+
* the table's extras with predicates compiled from the parsed AST — raw policy
|
|
561
|
+
* text never reaches SQL. Tables without policies stay RLS-enabled: default deny.
|
|
562
|
+
*/
|
|
563
|
+
declare function buildDrizzleEntities(definition: NamespaceDefinition): DrizzleEntities;
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* SQLSTATEs the action function raises for the two application-level denials
|
|
567
|
+
* that Postgres has no native code for. Custom 5-char classes (unused by
|
|
568
|
+
* Postgres) so the executor maps them precisely: requires → 403, validates →
|
|
569
|
+
* 422. RLS `WITH CHECK`, constraints, and bad values keep their native codes.
|
|
570
|
+
*/
|
|
571
|
+
declare const ACTION_REQUIRES_DENIED_SQLSTATE = "ORMRQ";
|
|
572
|
+
declare const ACTION_VALIDATES_FAILED_SQLSTATE = "ORMVL";
|
|
573
|
+
/** Internal function name for a declared action — the `action_` prefix is what the reconcile sweep drops. */
|
|
574
|
+
declare const actionFunctionName: (actionName: string) => string;
|
|
575
|
+
/**
|
|
576
|
+
* Every declared action becomes a `SECURITY INVOKER` Postgres function, so the
|
|
577
|
+
* apply-time `CREATE FUNCTION` is where Postgres validates the SQL (with
|
|
578
|
+
* `check_function_bodies` on, a bad column/table reference fails the apply and
|
|
579
|
+
* the action never goes live) and the invoke path is a single `SELECT fn(...)`
|
|
580
|
+
* under the consumer role — no client-side statement rewriting at call time.
|
|
581
|
+
*
|
|
582
|
+
* Actions carry no data and are absent from the drizzle snapshot, so instead
|
|
583
|
+
* of diffing them we reconcile: a leading sweep drops every `action_*` function
|
|
584
|
+
* in the schema (clearing removed/renamed/retyped ones — a signature change
|
|
585
|
+
* can't `CREATE OR REPLACE`), then each current action is created fresh. Runs
|
|
586
|
+
* last in the plan because the bodies reference tables the earlier DDL creates.
|
|
587
|
+
*/
|
|
588
|
+
declare function actionFunctionStatements(definition: NamespaceDefinition): string[];
|
|
589
|
+
/**
|
|
590
|
+
* PREPARE each action's executes at apply so Postgres parses and plans it
|
|
591
|
+
* against the live schema — catching unknown columns/tables/types that a
|
|
592
|
+
* plpgsql function body does NOT check at CREATE (it defers to first invoke).
|
|
593
|
+
* A failed PREPARE aborts the apply, so a broken action never goes live. Runs
|
|
594
|
+
* on the migration connection with the namespace on search_path; the prepared
|
|
595
|
+
* statements die with that connection, so no DEALLOCATE is needed.
|
|
596
|
+
*/
|
|
597
|
+
declare function actionPrepareChecks(definition: NamespaceDefinition): string[];
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The security statements the kit never sees — FORCE row security (so
|
|
601
|
+
* policies bind the table owner too), the row policies themselves, and the
|
|
602
|
+
* grants that let the Data API's consumer role reach the namespace.
|
|
603
|
+
*
|
|
604
|
+
* Policies deliberately bypass drizzle-kit's diff: its API resolves
|
|
605
|
+
* create+drop pairs interactively (fatal in a service), and they are cheap
|
|
606
|
+
* and fully determined by the definition — so every apply drops and
|
|
607
|
+
* recreates them. Writes compile to command-scoped policies, never FOR ALL:
|
|
608
|
+
* permissive policies OR together, so an all-commands policy would let
|
|
609
|
+
* write-capable callers SELECT rows the read policy hides.
|
|
610
|
+
*/
|
|
611
|
+
declare function securityStatements(definition: NamespaceDefinition): string[];
|
|
612
|
+
|
|
613
|
+
declare const sqlTypeName: (type: ColumnType) => string;
|
|
614
|
+
|
|
615
|
+
declare const STATEMENT_KINDS: readonly ["hint", "ddl", "security", "function"];
|
|
616
|
+
type StatementKind = (typeof STATEMENT_KINDS)[number];
|
|
617
|
+
interface CompiledStatement {
|
|
618
|
+
readonly kind: StatementKind;
|
|
619
|
+
readonly sql: string;
|
|
620
|
+
}
|
|
621
|
+
interface PlannedMigration {
|
|
622
|
+
readonly namespace: string;
|
|
623
|
+
readonly schema: string;
|
|
624
|
+
readonly statements: readonly CompiledStatement[];
|
|
625
|
+
/** Snapshot of the desired state — persisted by the registry, previous input to the next plan. */
|
|
626
|
+
readonly snapshot: NamespaceSnapshot;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Desired definition + the previously applied snapshot → ordered statements.
|
|
630
|
+
* The owned policies on pre-existing tables drop first (Postgres refuses to
|
|
631
|
+
* alter or drop a column a live policy depends on), hints (declared
|
|
632
|
+
* renames/casts) rewrite the previous snapshot, drizzle-kit diffs the
|
|
633
|
+
* remainder, and the owned security statements (FORCE RLS, recreated
|
|
634
|
+
* policies, consumer grants) close every migration.
|
|
635
|
+
*/
|
|
636
|
+
declare function planMigration({ definition, previousSnapshot, }: {
|
|
637
|
+
definition: NamespaceDefinition;
|
|
638
|
+
previousSnapshot?: NamespaceSnapshot;
|
|
639
|
+
}): Promise<PlannedMigration>;
|
|
640
|
+
/** Full-create plan (empty previous snapshot) — what `plan` prints and first apply runs. */
|
|
641
|
+
declare const compileNamespace: (definition: NamespaceDefinition) => Promise<PlannedMigration>;
|
|
642
|
+
|
|
643
|
+
declare class OrmDefinitionError extends Error {
|
|
644
|
+
readonly file?: string | undefined;
|
|
645
|
+
readonly name = "OrmDefinitionError";
|
|
646
|
+
constructor(message: string, file?: string | undefined);
|
|
647
|
+
}
|
|
648
|
+
declare class PredicateParseError extends Error {
|
|
649
|
+
readonly position: number;
|
|
650
|
+
readonly name = "PredicateParseError";
|
|
651
|
+
constructor(message: string, position: number);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
655
|
+
[key: string]: JsonValue;
|
|
656
|
+
};
|
|
657
|
+
/** Key-sorted, undefined-skipped JSON — identical definitions hash identically regardless of YAML key order. */
|
|
658
|
+
declare function stableJson(value: unknown): string;
|
|
659
|
+
declare function canonicalizeDefinition(definition: NamespaceDefinition): JsonValue;
|
|
660
|
+
declare function computeDefinitionHash(definition: NamespaceDefinition): string;
|
|
661
|
+
|
|
662
|
+
interface LoadedNamespace {
|
|
663
|
+
readonly definition: NamespaceDefinition;
|
|
664
|
+
readonly contentHash: string;
|
|
665
|
+
readonly files: readonly string[];
|
|
666
|
+
}
|
|
667
|
+
declare function parseTableFile(file: string, contents: string): DefinitionFile;
|
|
668
|
+
interface DefinitionSource {
|
|
669
|
+
readonly path: string;
|
|
670
|
+
readonly contents: string;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Raw sources → validated definition, splitting the reserved namespace
|
|
674
|
+
* config file from the table files. The one parse path for the loader and
|
|
675
|
+
* the registry, so a local directory and an uploaded bundle can't diverge.
|
|
676
|
+
*/
|
|
677
|
+
declare function parseDefinitionSources(sources: readonly DefinitionSource[]): NamespaceDefinition;
|
|
678
|
+
declare function loadNamespaceDefinition(dir: string): Promise<LoadedNamespace>;
|
|
679
|
+
|
|
680
|
+
interface DestructiveStatement {
|
|
681
|
+
readonly sql: string;
|
|
682
|
+
readonly reason: string;
|
|
683
|
+
}
|
|
684
|
+
declare function classifyDestructive(statements: readonly CompiledStatement[]): DestructiveStatement[];
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* The reviewed migration a registration carries: replay-only environments
|
|
688
|
+
* (production, banksouth) execute nothing that doesn't match one of these.
|
|
689
|
+
* Statements are recomputed at load and verified to reproduce the committed
|
|
690
|
+
* file byte-for-byte, so the payload can never drift from what review saw.
|
|
691
|
+
*/
|
|
692
|
+
interface CommittedMigration {
|
|
693
|
+
readonly name: string;
|
|
694
|
+
readonly ordinal: number;
|
|
695
|
+
readonly previous_content_hash: string | null;
|
|
696
|
+
readonly destructive: boolean;
|
|
697
|
+
readonly checksum: string;
|
|
698
|
+
readonly statements: readonly CompiledStatement[];
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Load the workspace tip as a registration payload. Returns null when there
|
|
702
|
+
* is no workspace (dev-loop registrations stay migration-less); throws when
|
|
703
|
+
* a workspace exists but is stale or drifted — a half-true artifact is worse
|
|
704
|
+
* than none.
|
|
705
|
+
*/
|
|
706
|
+
declare function loadCommittedTipMigration(dir: string, loaded: LoadedNamespace): Promise<CommittedMigration | null>;
|
|
707
|
+
/**
|
|
708
|
+
* One link in the committed history: a migration's content hash and the hash it
|
|
709
|
+
* was diffed FROM. This is an ancestry record, NOT executable SQL — a
|
|
710
|
+
* registration carries the whole chain so a replay-only environment can prove
|
|
711
|
+
* that its active version is a reviewed ancestor of the target (and thus that a
|
|
712
|
+
* direct catch-up diff is in-lineage) even over migrations that were never
|
|
713
|
+
* registered there (batched deploys, skipped releases). The catch-up apply then
|
|
714
|
+
* runs the engine's own direct diff, never any SQL from this chain.
|
|
715
|
+
*/
|
|
716
|
+
interface CommittedChainEntry {
|
|
717
|
+
readonly name: string;
|
|
718
|
+
readonly contentHash: string;
|
|
719
|
+
readonly previousContentHash: string | null;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* The committed hash chain for a definitions directory, oldest-first, taken from
|
|
723
|
+
* the journal (already integrity-checked by `orm validate` / `diff --check`).
|
|
724
|
+
* The tip must match the loaded definitions — a registration carries this so
|
|
725
|
+
* replay-only environments can verify catch-up ancestry without those
|
|
726
|
+
* intervening versions being registered. Empty when there is no workspace.
|
|
727
|
+
*/
|
|
728
|
+
declare function loadCommittedMigrations(dir: string, loaded: LoadedNamespace): Promise<CommittedChainEntry[]>;
|
|
729
|
+
|
|
730
|
+
interface DiffOptions {
|
|
731
|
+
readonly dir: string;
|
|
732
|
+
readonly allowDestructive: boolean;
|
|
733
|
+
readonly check: boolean;
|
|
734
|
+
readonly log: (line: string) => void;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* `orm diff` — append the next committed migration for a definitions
|
|
738
|
+
* directory, diffed against the workspace's tip snapshot. `--check` is the
|
|
739
|
+
* CI gate: no database, no credentials — verify checksums, the snapshot
|
|
740
|
+
* chain, that the definitions match the journal tip, and that regenerating
|
|
741
|
+
* the tip reproduces the committed file byte-for-byte.
|
|
742
|
+
*/
|
|
743
|
+
declare function diffCommand({ dir, allowDestructive, check, log }: DiffOptions): Promise<number>;
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* The committed migration workspace inside a definitions directory:
|
|
747
|
+
*
|
|
748
|
+
* <dir>/migrations/NNNN_<hash12>.sql reviewable statements
|
|
749
|
+
* <dir>/migrations/meta/NNNN.snapshot.json desired-state snapshot after NNNN
|
|
750
|
+
* <dir>/migrations/meta/journal.json ordered index with checksums
|
|
751
|
+
*
|
|
752
|
+
* `orm diff` appends to it; `orm diff --check` (the CI gate) verifies it
|
|
753
|
+
* matches the definitions with no database and no credentials. Everything
|
|
754
|
+
* here is deterministic from (previous snapshot, definition) so the gate
|
|
755
|
+
* can regenerate and byte-compare.
|
|
756
|
+
*/
|
|
757
|
+
declare const MIGRATIONS_DIRNAME = "migrations";
|
|
758
|
+
declare const journalEntrySchema: z.ZodObject<{
|
|
759
|
+
ordinal: z.ZodNumber;
|
|
760
|
+
name: z.ZodString;
|
|
761
|
+
content_hash: z.ZodString;
|
|
762
|
+
previous_content_hash: z.ZodNullable<z.ZodString>;
|
|
763
|
+
checksum: z.ZodString;
|
|
764
|
+
snapshot_checksum: z.ZodString;
|
|
765
|
+
destructive: z.ZodBoolean;
|
|
766
|
+
}, z.core.$strip>;
|
|
767
|
+
declare const journalSchema: z.ZodObject<{
|
|
768
|
+
version: z.ZodLiteral<1>;
|
|
769
|
+
namespace: z.ZodString;
|
|
770
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
771
|
+
ordinal: z.ZodNumber;
|
|
772
|
+
name: z.ZodString;
|
|
773
|
+
content_hash: z.ZodString;
|
|
774
|
+
previous_content_hash: z.ZodNullable<z.ZodString>;
|
|
775
|
+
checksum: z.ZodString;
|
|
776
|
+
snapshot_checksum: z.ZodString;
|
|
777
|
+
destructive: z.ZodBoolean;
|
|
778
|
+
}, z.core.$strip>>;
|
|
779
|
+
}, z.core.$strip>;
|
|
780
|
+
type MigrationJournal = z.infer<typeof journalSchema>;
|
|
781
|
+
type JournalEntry = z.infer<typeof journalEntrySchema>;
|
|
782
|
+
interface MigrationWorkspace {
|
|
783
|
+
readonly journal: MigrationJournal;
|
|
784
|
+
/** Snapshot at the journal tip — the previous input for the next diff. */
|
|
785
|
+
readonly tipSnapshot: NamespaceSnapshot | undefined;
|
|
786
|
+
}
|
|
787
|
+
declare const emptyJournal: (namespace: string) => MigrationJournal;
|
|
788
|
+
declare function readMigrationWorkspace(dir: string, namespace: string): Promise<MigrationWorkspace>;
|
|
789
|
+
declare function readSnapshot(dir: string, ordinal: number): Promise<NamespaceSnapshot>;
|
|
790
|
+
declare function readMigrationSql(dir: string, entry: JournalEntry): Promise<string>;
|
|
791
|
+
declare const checksumOf: (text: string) => string;
|
|
792
|
+
declare const migrationName: (ordinal: number, contentHash: string) => string;
|
|
793
|
+
declare function renderMigrationSql({ name, namespace, contentHash, plan, }: {
|
|
794
|
+
name: string;
|
|
795
|
+
namespace: string;
|
|
796
|
+
contentHash: string;
|
|
797
|
+
plan: PlannedMigration;
|
|
798
|
+
}): string;
|
|
799
|
+
interface WrittenMigration {
|
|
800
|
+
readonly name: string;
|
|
801
|
+
readonly ordinal: number;
|
|
802
|
+
readonly destructive: boolean;
|
|
803
|
+
}
|
|
804
|
+
declare function writeMigration({ dir, workspace, plan, contentHash, destructive, }: {
|
|
805
|
+
dir: string;
|
|
806
|
+
workspace: MigrationWorkspace;
|
|
807
|
+
plan: PlannedMigration;
|
|
808
|
+
contentHash: string;
|
|
809
|
+
destructive: boolean;
|
|
810
|
+
}): Promise<WrittenMigration>;
|
|
811
|
+
|
|
812
|
+
declare function parsePredicate(source: string): ParsedPredicate;
|
|
813
|
+
|
|
814
|
+
declare const identifierSchema: z.ZodString;
|
|
815
|
+
declare const namespaceSchema: z.ZodString;
|
|
816
|
+
/** `<table>` for a table in the same namespace, `<schema>.<table>` for anything else. */
|
|
817
|
+
declare const tableReferenceSchema: z.ZodString;
|
|
818
|
+
declare const isQualifiedReference: (reference: string) => boolean;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Rehydrate a stored canonical definition (see hash.ts) back into a validated
|
|
822
|
+
* NamespaceDefinition — predicates re-parse from their source strings, every
|
|
823
|
+
* invariant re-checks. The registry is never trusted blindly: callers compare
|
|
824
|
+
* computeDefinitionHash(result) against the stored content hash.
|
|
825
|
+
*/
|
|
826
|
+
declare function parseCanonicalDefinition(value: unknown): NamespaceDefinition;
|
|
827
|
+
|
|
828
|
+
declare const parsedPredicateSchema: z.ZodPipe<z.ZodString, z.ZodTransform<ParsedPredicate, string>>;
|
|
829
|
+
|
|
830
|
+
export { ACTION_REQUIRES_DENIED_SQLSTATE, ACTION_VALIDATES_FAILED_SQLSTATE, AUDIT_ACTIONS, type ActionDefinition, CAPABILITIES_CLAIM_KEY, CAPABILITY_KEY_PATTERN, CLAIMS_SETTING, CLAIM_KEY_PATTERN, COLUMN_TYPES, COMPARE_OPS, CONSUMER_ROLE_SUFFIX, type ColumnDefault, type ColumnDefinition, type ColumnType, type CommittedChainEntry, type CommittedMigration, type CompareOp, type CompiledStatement, type CustomRolesBlock, DEFINITION_FILE_EXTENSIONS, type DefinitionFile, type DefinitionSource, type DestructiveStatement, type DiffOptions, type DrizzleEntities, HASH_DOMAIN, IDENTIFIER_PATTERN, type IndexDefinition, type JournalEntry, type LinkDefinition, type LoadedNamespace, MAX_DEFINITION_FILE_BYTES, MAX_IDENTIFIER_LENGTH, MIGRATIONS_DIRNAME, type MigrationJournal, type MigrationWorkspace, NAMESPACE_CONFIG_FILENAMES, NAMESPACE_PATTERN, type NamespaceCapabilities, type NamespaceConfig, type NamespaceDefinition, type NamespaceSnapshot, ORM_DATA_TOKEN_HEADER, ORM_SCHEMA_PREFIX, ORM_SERVICE_DATA_TOKEN_HEADER, type Operand, OrmDefinitionError, type ParsedPredicate, type PlannedMigration, type Predicate, PredicateParseError, QUALIFIED_TABLE_PATTERN, RESERVED_COLUMN_NAMES, RESERVED_TABLE_NAMES, STATEMENT_KINDS, SYNCED_SOURCE_PATTERN, type StatementKind, type TableFile, type ValidatesEntry, type WrittenMigration, actionFunctionName, actionFunctionStatements, actionParamArg, actionParamOrder, actionParamSchema, actionPrepareChecks, actionSchema, actionsInterfaceName, applyMigrationHints, buildActionParamsSchema, buildDrizzleEntities, buildNamespaceDefinition, canonicalizeDefinition, capabilityExpression, capabilityPinsSchema, castParts, checksumOf, claimExpression, classifyDestructive, columnSchema, columnTypeSchema, compileActionRequires, compileActionStatements, compileNamespace, compilePredicate, computeDefinitionHash, consumerRoleName, customRolesBlockSchema, customRolesDeclared, declaredCapabilityKeys, diffCommand, diffStatements, emptyJournal, emptySnapshot, extractNamedParams, generateNamespaceTypes, generateSnapshot, identifierSchema, isFunctionDefault, isOwnedStatement, isQualifiedReference, loadCommittedMigrations, loadCommittedTipMigration, loadNamespaceDefinition, migrationName, namespaceConfigSchema, namespaceSchema, normalizeSnapshot, ormSchemaName, parseCanonicalDefinition, parseCapabilityPin, parseDefinitionSources, parsePredicate, parseTableFile, parsedPredicateSchema, pendingKitStatements, planMigration, predicateOperands, quoteIdentifier, quoteLiteral, readMigrationSql, readMigrationWorkspace, readSnapshot, referencedCapabilities, referencedColumns, renderMigrationSql, securityStatements, sqlTypeName, stableJson, tableFileSchema, tableReferenceSchema, typesInterfaceName, validateCapabilityPins, walkPredicate, writeMigration };
|