@kurotako/ir 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.
@@ -0,0 +1,576 @@
1
+ import * as v from 'valibot';
2
+
3
+ /**
4
+ * Valibot schemas — the single source of truth for the IR format.
5
+ *
6
+ * `types.ts` derives every type alias from these schemas via `v.InferOutput`;
7
+ * `validate.ts` runs `v.safeParse` against them before the cross-reference pass.
8
+ * Every schema stays plain and JSON-serializable by construction: only object,
9
+ * array, record, picklist, variant and primitives — no `Date`, `RegExp`, classes
10
+ * or functions. This is what keeps `--emit-ir` and `parseIR` trivial.
11
+ */
12
+
13
+ /** Recursive JSON value. Hand-written because `v.lazy` needs an explicit type. */
14
+ type JsonValue = null | boolean | number | string | JsonValue[] | {
15
+ [key: string]: JsonValue;
16
+ };
17
+ declare const JsonValueSchema: v.GenericSchema<JsonValue>;
18
+ declare const ScalarTypeSchema: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
19
+ declare const StringFormatSchema: v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>;
20
+ declare const ReferentialActionSchema: v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>;
21
+ declare const IndexTypeSchema: v.PicklistSchema<["btree", "hash", "gin", "gist", "brin", "spgist"], undefined>;
22
+ declare const FieldTypeSchema: v.VariantSchema<"kind", [v.ObjectSchema<{
23
+ readonly kind: v.LiteralSchema<"scalar", undefined>;
24
+ readonly scalar: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
25
+ }, undefined>, v.ObjectSchema<{
26
+ readonly kind: v.LiteralSchema<"enum", undefined>;
27
+ readonly ref: v.StringSchema<undefined>;
28
+ }, undefined>, v.ObjectSchema<{
29
+ readonly kind: v.LiteralSchema<"unknown", undefined>;
30
+ readonly hint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
31
+ }, undefined>], undefined>;
32
+ declare const ConstraintsSchema: v.ObjectSchema<{
33
+ readonly min: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
34
+ readonly max: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
35
+ readonly minLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
36
+ readonly maxLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
37
+ readonly regex: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
38
+ readonly format: v.OptionalSchema<v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>, undefined>;
39
+ readonly unique: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
40
+ }, undefined>;
41
+ declare const DefaultValueSchema: v.VariantSchema<"kind", [v.ObjectSchema<{
42
+ readonly kind: v.LiteralSchema<"value", undefined>;
43
+ readonly value: v.GenericSchema<JsonValue>;
44
+ }, undefined>, v.ObjectSchema<{
45
+ readonly kind: v.LiteralSchema<"expr", undefined>;
46
+ readonly expr: v.StringSchema<undefined>;
47
+ readonly args: v.OptionalSchema<v.ArraySchema<v.GenericSchema<JsonValue>, undefined>, undefined>;
48
+ }, undefined>], undefined>;
49
+ declare const FieldSchema: v.ObjectSchema<{
50
+ readonly name: v.StringSchema<undefined>;
51
+ readonly type: v.VariantSchema<"kind", [v.ObjectSchema<{
52
+ readonly kind: v.LiteralSchema<"scalar", undefined>;
53
+ readonly scalar: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
54
+ }, undefined>, v.ObjectSchema<{
55
+ readonly kind: v.LiteralSchema<"enum", undefined>;
56
+ readonly ref: v.StringSchema<undefined>;
57
+ }, undefined>, v.ObjectSchema<{
58
+ readonly kind: v.LiteralSchema<"unknown", undefined>;
59
+ readonly hint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
60
+ }, undefined>], undefined>;
61
+ readonly list: v.BooleanSchema<undefined>;
62
+ readonly optional: v.BooleanSchema<undefined>;
63
+ readonly nullable: v.BooleanSchema<undefined>;
64
+ readonly constraints: v.ObjectSchema<{
65
+ readonly min: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
66
+ readonly max: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
67
+ readonly minLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
68
+ readonly maxLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
69
+ readonly regex: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
70
+ readonly format: v.OptionalSchema<v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>, undefined>;
71
+ readonly unique: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
72
+ }, undefined>;
73
+ readonly default: v.OptionalSchema<v.VariantSchema<"kind", [v.ObjectSchema<{
74
+ readonly kind: v.LiteralSchema<"value", undefined>;
75
+ readonly value: v.GenericSchema<JsonValue>;
76
+ }, undefined>, v.ObjectSchema<{
77
+ readonly kind: v.LiteralSchema<"expr", undefined>;
78
+ readonly expr: v.StringSchema<undefined>;
79
+ readonly args: v.OptionalSchema<v.ArraySchema<v.GenericSchema<JsonValue>, undefined>, undefined>;
80
+ }, undefined>], undefined>, undefined>;
81
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
82
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
83
+ }, undefined>;
84
+ declare const RelationTargetSchema: v.ObjectSchema<{
85
+ readonly namespace: v.StringSchema<undefined>;
86
+ readonly entity: v.StringSchema<undefined>;
87
+ }, undefined>;
88
+ declare const RelationSchema: v.ObjectSchema<{
89
+ readonly name: v.StringSchema<undefined>;
90
+ readonly target: v.ObjectSchema<{
91
+ readonly namespace: v.StringSchema<undefined>;
92
+ readonly entity: v.StringSchema<undefined>;
93
+ }, undefined>;
94
+ readonly cardinality: v.PicklistSchema<["one", "many"], undefined>;
95
+ readonly optional: v.BooleanSchema<undefined>;
96
+ readonly owning: v.BooleanSchema<undefined>;
97
+ readonly backRelation: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
98
+ readonly fkFields: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
99
+ readonly references: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
100
+ readonly onDelete: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
101
+ readonly onUpdate: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
102
+ }, undefined>;
103
+ declare const EnumValueSchema: v.ObjectSchema<{
104
+ readonly name: v.StringSchema<undefined>;
105
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
106
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
107
+ }, undefined>;
108
+ declare const EnumDefSchema: v.ObjectSchema<{
109
+ readonly name: v.StringSchema<undefined>;
110
+ readonly values: v.ArraySchema<v.ObjectSchema<{
111
+ readonly name: v.StringSchema<undefined>;
112
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
113
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
114
+ }, undefined>, undefined>;
115
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
116
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
117
+ }, undefined>;
118
+ declare const IndexDefSchema: v.ObjectSchema<{
119
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
120
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
121
+ readonly type: v.OptionalSchema<v.PicklistSchema<["btree", "hash", "gin", "gist", "brin", "spgist"], undefined>, undefined>;
122
+ }, undefined>;
123
+ declare const CompositeUniqueSchema: v.ObjectSchema<{
124
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
125
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
126
+ }, undefined>;
127
+ declare const EntitySchema: v.ObjectSchema<{
128
+ readonly name: v.StringSchema<undefined>;
129
+ readonly fields: v.ArraySchema<v.ObjectSchema<{
130
+ readonly name: v.StringSchema<undefined>;
131
+ readonly type: v.VariantSchema<"kind", [v.ObjectSchema<{
132
+ readonly kind: v.LiteralSchema<"scalar", undefined>;
133
+ readonly scalar: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
134
+ }, undefined>, v.ObjectSchema<{
135
+ readonly kind: v.LiteralSchema<"enum", undefined>;
136
+ readonly ref: v.StringSchema<undefined>;
137
+ }, undefined>, v.ObjectSchema<{
138
+ readonly kind: v.LiteralSchema<"unknown", undefined>;
139
+ readonly hint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
140
+ }, undefined>], undefined>;
141
+ readonly list: v.BooleanSchema<undefined>;
142
+ readonly optional: v.BooleanSchema<undefined>;
143
+ readonly nullable: v.BooleanSchema<undefined>;
144
+ readonly constraints: v.ObjectSchema<{
145
+ readonly min: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
146
+ readonly max: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
147
+ readonly minLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
148
+ readonly maxLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
149
+ readonly regex: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
150
+ readonly format: v.OptionalSchema<v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>, undefined>;
151
+ readonly unique: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
152
+ }, undefined>;
153
+ readonly default: v.OptionalSchema<v.VariantSchema<"kind", [v.ObjectSchema<{
154
+ readonly kind: v.LiteralSchema<"value", undefined>;
155
+ readonly value: v.GenericSchema<JsonValue>;
156
+ }, undefined>, v.ObjectSchema<{
157
+ readonly kind: v.LiteralSchema<"expr", undefined>;
158
+ readonly expr: v.StringSchema<undefined>;
159
+ readonly args: v.OptionalSchema<v.ArraySchema<v.GenericSchema<JsonValue>, undefined>, undefined>;
160
+ }, undefined>], undefined>, undefined>;
161
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
162
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
163
+ }, undefined>, undefined>;
164
+ readonly relations: v.ArraySchema<v.ObjectSchema<{
165
+ readonly name: v.StringSchema<undefined>;
166
+ readonly target: v.ObjectSchema<{
167
+ readonly namespace: v.StringSchema<undefined>;
168
+ readonly entity: v.StringSchema<undefined>;
169
+ }, undefined>;
170
+ readonly cardinality: v.PicklistSchema<["one", "many"], undefined>;
171
+ readonly optional: v.BooleanSchema<undefined>;
172
+ readonly owning: v.BooleanSchema<undefined>;
173
+ readonly backRelation: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
174
+ readonly fkFields: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
175
+ readonly references: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
176
+ readonly onDelete: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
177
+ readonly onUpdate: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
178
+ }, undefined>, undefined>;
179
+ readonly enums: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
180
+ readonly name: v.StringSchema<undefined>;
181
+ readonly values: v.ArraySchema<v.ObjectSchema<{
182
+ readonly name: v.StringSchema<undefined>;
183
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
184
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
185
+ }, undefined>, undefined>;
186
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
187
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
188
+ }, undefined>, undefined>, undefined>;
189
+ readonly primaryKey: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
190
+ readonly indexes: v.ArraySchema<v.ObjectSchema<{
191
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
192
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
193
+ readonly type: v.OptionalSchema<v.PicklistSchema<["btree", "hash", "gin", "gist", "brin", "spgist"], undefined>, undefined>;
194
+ }, undefined>, undefined>;
195
+ readonly uniques: v.ArraySchema<v.ObjectSchema<{
196
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
197
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
198
+ }, undefined>, undefined>;
199
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
200
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
201
+ }, undefined>;
202
+ declare const SourceIrSchema: v.ObjectSchema<{
203
+ readonly namespace: v.StringSchema<undefined>;
204
+ readonly parser: v.StringSchema<undefined>;
205
+ readonly parserVersion: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
206
+ readonly entities: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
207
+ readonly name: v.StringSchema<undefined>;
208
+ readonly fields: v.ArraySchema<v.ObjectSchema<{
209
+ readonly name: v.StringSchema<undefined>;
210
+ readonly type: v.VariantSchema<"kind", [v.ObjectSchema<{
211
+ readonly kind: v.LiteralSchema<"scalar", undefined>;
212
+ readonly scalar: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
213
+ }, undefined>, v.ObjectSchema<{
214
+ readonly kind: v.LiteralSchema<"enum", undefined>;
215
+ readonly ref: v.StringSchema<undefined>;
216
+ }, undefined>, v.ObjectSchema<{
217
+ readonly kind: v.LiteralSchema<"unknown", undefined>;
218
+ readonly hint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
219
+ }, undefined>], undefined>;
220
+ readonly list: v.BooleanSchema<undefined>;
221
+ readonly optional: v.BooleanSchema<undefined>;
222
+ readonly nullable: v.BooleanSchema<undefined>;
223
+ readonly constraints: v.ObjectSchema<{
224
+ readonly min: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
225
+ readonly max: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
226
+ readonly minLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
227
+ readonly maxLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
228
+ readonly regex: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
229
+ readonly format: v.OptionalSchema<v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>, undefined>;
230
+ readonly unique: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
231
+ }, undefined>;
232
+ readonly default: v.OptionalSchema<v.VariantSchema<"kind", [v.ObjectSchema<{
233
+ readonly kind: v.LiteralSchema<"value", undefined>;
234
+ readonly value: v.GenericSchema<JsonValue>;
235
+ }, undefined>, v.ObjectSchema<{
236
+ readonly kind: v.LiteralSchema<"expr", undefined>;
237
+ readonly expr: v.StringSchema<undefined>;
238
+ readonly args: v.OptionalSchema<v.ArraySchema<v.GenericSchema<JsonValue>, undefined>, undefined>;
239
+ }, undefined>], undefined>, undefined>;
240
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
241
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
242
+ }, undefined>, undefined>;
243
+ readonly relations: v.ArraySchema<v.ObjectSchema<{
244
+ readonly name: v.StringSchema<undefined>;
245
+ readonly target: v.ObjectSchema<{
246
+ readonly namespace: v.StringSchema<undefined>;
247
+ readonly entity: v.StringSchema<undefined>;
248
+ }, undefined>;
249
+ readonly cardinality: v.PicklistSchema<["one", "many"], undefined>;
250
+ readonly optional: v.BooleanSchema<undefined>;
251
+ readonly owning: v.BooleanSchema<undefined>;
252
+ readonly backRelation: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
253
+ readonly fkFields: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
254
+ readonly references: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
255
+ readonly onDelete: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
256
+ readonly onUpdate: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
257
+ }, undefined>, undefined>;
258
+ readonly enums: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
259
+ readonly name: v.StringSchema<undefined>;
260
+ readonly values: v.ArraySchema<v.ObjectSchema<{
261
+ readonly name: v.StringSchema<undefined>;
262
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
263
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
264
+ }, undefined>, undefined>;
265
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
266
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
267
+ }, undefined>, undefined>, undefined>;
268
+ readonly primaryKey: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
269
+ readonly indexes: v.ArraySchema<v.ObjectSchema<{
270
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
271
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
272
+ readonly type: v.OptionalSchema<v.PicklistSchema<["btree", "hash", "gin", "gist", "brin", "spgist"], undefined>, undefined>;
273
+ }, undefined>, undefined>;
274
+ readonly uniques: v.ArraySchema<v.ObjectSchema<{
275
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
276
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
277
+ }, undefined>, undefined>;
278
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
279
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
280
+ }, undefined>, undefined>;
281
+ readonly enums: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
282
+ readonly name: v.StringSchema<undefined>;
283
+ readonly values: v.ArraySchema<v.ObjectSchema<{
284
+ readonly name: v.StringSchema<undefined>;
285
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
286
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
287
+ }, undefined>, undefined>;
288
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
289
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
290
+ }, undefined>, undefined>;
291
+ }, undefined>;
292
+ declare const IrSchema: v.ObjectSchema<{
293
+ readonly irVersion: v.StringSchema<undefined>;
294
+ readonly sources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
295
+ readonly namespace: v.StringSchema<undefined>;
296
+ readonly parser: v.StringSchema<undefined>;
297
+ readonly parserVersion: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
298
+ readonly entities: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
299
+ readonly name: v.StringSchema<undefined>;
300
+ readonly fields: v.ArraySchema<v.ObjectSchema<{
301
+ readonly name: v.StringSchema<undefined>;
302
+ readonly type: v.VariantSchema<"kind", [v.ObjectSchema<{
303
+ readonly kind: v.LiteralSchema<"scalar", undefined>;
304
+ readonly scalar: v.PicklistSchema<["string", "boolean", "int", "bigint", "float", "decimal", "date", "datetime", "uuid", "bytes", "json"], undefined>;
305
+ }, undefined>, v.ObjectSchema<{
306
+ readonly kind: v.LiteralSchema<"enum", undefined>;
307
+ readonly ref: v.StringSchema<undefined>;
308
+ }, undefined>, v.ObjectSchema<{
309
+ readonly kind: v.LiteralSchema<"unknown", undefined>;
310
+ readonly hint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
311
+ }, undefined>], undefined>;
312
+ readonly list: v.BooleanSchema<undefined>;
313
+ readonly optional: v.BooleanSchema<undefined>;
314
+ readonly nullable: v.BooleanSchema<undefined>;
315
+ readonly constraints: v.ObjectSchema<{
316
+ readonly min: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
317
+ readonly max: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
318
+ readonly minLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
319
+ readonly maxLength: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
320
+ readonly regex: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
321
+ readonly format: v.OptionalSchema<v.PicklistSchema<["email", "url", "uuid", "cuid", "cuid2", "ulid", "datetime", "date", "time", "duration", "ipv4", "ipv6"], undefined>, undefined>;
322
+ readonly unique: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
323
+ }, undefined>;
324
+ readonly default: v.OptionalSchema<v.VariantSchema<"kind", [v.ObjectSchema<{
325
+ readonly kind: v.LiteralSchema<"value", undefined>;
326
+ readonly value: v.GenericSchema<JsonValue>;
327
+ }, undefined>, v.ObjectSchema<{
328
+ readonly kind: v.LiteralSchema<"expr", undefined>;
329
+ readonly expr: v.StringSchema<undefined>;
330
+ readonly args: v.OptionalSchema<v.ArraySchema<v.GenericSchema<JsonValue>, undefined>, undefined>;
331
+ }, undefined>], undefined>, undefined>;
332
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
333
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
334
+ }, undefined>, undefined>;
335
+ readonly relations: v.ArraySchema<v.ObjectSchema<{
336
+ readonly name: v.StringSchema<undefined>;
337
+ readonly target: v.ObjectSchema<{
338
+ readonly namespace: v.StringSchema<undefined>;
339
+ readonly entity: v.StringSchema<undefined>;
340
+ }, undefined>;
341
+ readonly cardinality: v.PicklistSchema<["one", "many"], undefined>;
342
+ readonly optional: v.BooleanSchema<undefined>;
343
+ readonly owning: v.BooleanSchema<undefined>;
344
+ readonly backRelation: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
345
+ readonly fkFields: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
346
+ readonly references: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
347
+ readonly onDelete: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
348
+ readonly onUpdate: v.OptionalSchema<v.PicklistSchema<["cascade", "restrict", "setNull", "setDefault", "noAction"], undefined>, undefined>;
349
+ }, undefined>, undefined>;
350
+ readonly enums: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
351
+ readonly name: v.StringSchema<undefined>;
352
+ readonly values: v.ArraySchema<v.ObjectSchema<{
353
+ readonly name: v.StringSchema<undefined>;
354
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
355
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
356
+ }, undefined>, undefined>;
357
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
358
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
359
+ }, undefined>, undefined>, undefined>;
360
+ readonly primaryKey: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
361
+ readonly indexes: v.ArraySchema<v.ObjectSchema<{
362
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
363
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
364
+ readonly type: v.OptionalSchema<v.PicklistSchema<["btree", "hash", "gin", "gist", "brin", "spgist"], undefined>, undefined>;
365
+ }, undefined>, undefined>;
366
+ readonly uniques: v.ArraySchema<v.ObjectSchema<{
367
+ readonly fields: v.ArraySchema<v.StringSchema<undefined>, undefined>;
368
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
369
+ }, undefined>, undefined>;
370
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
371
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
372
+ }, undefined>, undefined>;
373
+ readonly enums: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
374
+ readonly name: v.StringSchema<undefined>;
375
+ readonly values: v.ArraySchema<v.ObjectSchema<{
376
+ readonly name: v.StringSchema<undefined>;
377
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
378
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
379
+ }, undefined>, undefined>;
380
+ readonly doc: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
381
+ readonly dbName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
382
+ }, undefined>, undefined>;
383
+ }, undefined>, undefined>;
384
+ }, undefined>;
385
+
386
+ /**
387
+ * Type surface of the IR. Every alias is `v.InferOutput<typeof …Schema>` — the
388
+ * schemas in `schemas.ts` are the single source of truth, there is no
389
+ * hand-written interface here.
390
+ */
391
+
392
+ type IR = v.InferOutput<typeof IrSchema>;
393
+ type SourceIR = v.InferOutput<typeof SourceIrSchema>;
394
+ type Entity = v.InferOutput<typeof EntitySchema>;
395
+ type Field = v.InferOutput<typeof FieldSchema>;
396
+ type FieldType = v.InferOutput<typeof FieldTypeSchema>;
397
+ type ScalarType = v.InferOutput<typeof ScalarTypeSchema>;
398
+ type StringFormat = v.InferOutput<typeof StringFormatSchema>;
399
+ type ReferentialAction = v.InferOutput<typeof ReferentialActionSchema>;
400
+ type IndexType = v.InferOutput<typeof IndexTypeSchema>;
401
+ type Constraints = v.InferOutput<typeof ConstraintsSchema>;
402
+ type DefaultValue = v.InferOutput<typeof DefaultValueSchema>;
403
+ type Relation = v.InferOutput<typeof RelationSchema>;
404
+ type RelationTarget = v.InferOutput<typeof RelationTargetSchema>;
405
+ type EnumDef = v.InferOutput<typeof EnumDefSchema>;
406
+ type EnumValue = v.InferOutput<typeof EnumValueSchema>;
407
+ type IndexDef = v.InferOutput<typeof IndexDefSchema>;
408
+ type CompositeUnique = v.InferOutput<typeof CompositeUniqueSchema>;
409
+
410
+ type IrIssueCode = 'version_incompatible' | 'namespace_key_mismatch' | 'entity_key_mismatch' | 'duplicate_field' | 'duplicate_enum_value' | 'unresolved_enum_ref' | 'unresolved_field_ref' | 'unresolved_relation_target' | 'unresolved_back_relation' | 'invalid_constraint' | 'invalid_regex' | 'shape';
411
+ interface IrIssue {
412
+ path: string;
413
+ code: IrIssueCode;
414
+ message: string;
415
+ }
416
+ type IrValidation<T> = {
417
+ ok: true;
418
+ value: T;
419
+ } | {
420
+ ok: false;
421
+ issues: IrIssue[];
422
+ };
423
+ declare class IrValidationError extends Error {
424
+ readonly issues: IrIssue[];
425
+ constructor(issues: IrIssue[]);
426
+ }
427
+ declare function validateSourceIR(value: unknown): IrValidation<SourceIR>;
428
+ declare function validateIR(value: unknown): IrValidation<IR>;
429
+ declare function assertIR(value: unknown): asserts value is IR;
430
+ declare function assertSourceIR(value: unknown): asserts value is SourceIR;
431
+ declare function parseIR(json: string): IR;
432
+
433
+ declare class IrBuildError extends Error {
434
+ readonly path: string;
435
+ readonly issues: IrIssue[] | undefined;
436
+ constructor(path: string, message: string, issues?: IrIssue[]);
437
+ }
438
+ interface EnumBuilder {
439
+ value(name: string, opts?: {
440
+ dbName?: string;
441
+ doc?: string;
442
+ }): this;
443
+ doc(text: string): this;
444
+ dbName(name: string): this;
445
+ }
446
+ interface FieldBuilder {
447
+ scalar(t: ScalarType): this;
448
+ enum(ref: string): this;
449
+ unknown(hint?: string): this;
450
+ list(): this;
451
+ optional(): this;
452
+ nullable(): this;
453
+ primary(): this;
454
+ unique(): this;
455
+ min(n: number): this;
456
+ max(n: number): this;
457
+ minLength(n: number): this;
458
+ maxLength(n: number): this;
459
+ regex(src: string): this;
460
+ format(f: StringFormat): this;
461
+ default(d: DefaultValue): this;
462
+ doc(text: string): this;
463
+ dbName(name: string): this;
464
+ }
465
+ interface RelationBuilder {
466
+ to(namespace: string, entity: string): this;
467
+ one(): this;
468
+ many(): this;
469
+ optional(): this;
470
+ owning(): this;
471
+ backRelation(name: string): this;
472
+ fkFields(...fields: string[]): this;
473
+ references(...fields: string[]): this;
474
+ onDelete(action: ReferentialAction): this;
475
+ onUpdate(action: ReferentialAction): this;
476
+ }
477
+ interface EntityBuilder {
478
+ field(name: string, def: (f: FieldBuilder) => void): this;
479
+ relation(name: string, def: (r: RelationBuilder) => void): this;
480
+ localEnum(name: string, def: (e: EnumBuilder) => void): this;
481
+ primaryKey(...fields: string[]): this;
482
+ index(fields: string[], opts?: {
483
+ name?: string;
484
+ type?: IndexType;
485
+ }): this;
486
+ unique(fields: string[], opts?: {
487
+ name?: string;
488
+ }): this;
489
+ doc(text: string): this;
490
+ dbName(name: string): this;
491
+ }
492
+ interface SourceIrBuilder {
493
+ addEnum(name: string, def: (e: EnumBuilder) => void): this;
494
+ addEntity(name: string, def: (e: EntityBuilder) => void): this;
495
+ build(): SourceIR;
496
+ }
497
+ declare function createSourceIR(init: {
498
+ namespace: string;
499
+ parser: string;
500
+ parserVersion?: string;
501
+ }): SourceIrBuilder;
502
+
503
+ /**
504
+ * Traversal / resolution helpers. All pure, none throw — they return `undefined`
505
+ * on a miss. `resolveEnum` implements the entity-local → source-level precedence
506
+ * in one place so every generator agrees.
507
+ */
508
+
509
+ declare function getSource(ir: IR, namespace: string): SourceIR | undefined;
510
+ declare function resolveEntity(ir: IR, namespace: string, name: string): Entity | undefined;
511
+ /** Entity-local enums shadow source-level enums of the same name. */
512
+ declare function resolveEnum(source: SourceIR, entity: Entity | undefined, ref: string): EnumDef | undefined;
513
+ /**
514
+ * A relation is cross-source when its target namespace is anything other than
515
+ * the entity's own namespace — including the "absent" (empty) namespace, which
516
+ * v1 drivers treat as an unresolved cross-source reference.
517
+ */
518
+ declare function isCrossSource(fromNamespace: string, rel: Relation): boolean;
519
+ /**
520
+ * Resolve the target entity of a relation. Returns `undefined` when the target
521
+ * namespace is absent or not present in the IR, or when the entity is missing.
522
+ */
523
+ declare function resolveRelationTarget(ir: IR, fromNamespace: string, rel: Relation): Entity | undefined;
524
+ declare function iterEntities(ir: IR): Iterable<{
525
+ namespace: string;
526
+ entity: Entity;
527
+ }>;
528
+ declare function iterFields(entity: Entity): Iterable<Field>;
529
+ /** Fields named by `entity.primaryKey`, in declaration order. */
530
+ declare function primaryKeyFields(entity: Entity): Field[];
531
+ /** Closed set of scalar TS type tokens `scalarTsType` may return for a scalar. */
532
+ type ScalarTsType = 'string' | 'number' | 'bigint' | 'boolean' | 'Date' | 'Uint8Array' | 'JsonValue' | 'unknown';
533
+ /**
534
+ * The value is assigned by the DB/server (an `expr` default: `now()`,
535
+ * `autoincrement()`, `uuid()`, `dbgenerated("…")`, …) and is never supplied on a
536
+ * create payload.
537
+ */
538
+ declare function isDbAssigned(field: Field): boolean;
539
+ /**
540
+ * Fields to include in a "create" payload: `entity.fields` minus the ones whose
541
+ * only value source is db-side (a primary-key member that is `isDbAssigned`).
542
+ */
543
+ declare function createFields(entity: Entity): Field[];
544
+ /**
545
+ * A create-payload field the caller may omit:
546
+ * `field.optional || field.default != null || isDbAssigned(field)`.
547
+ */
548
+ declare function isCreateOptional(field: Field): boolean;
549
+ /**
550
+ * Fields to include in an "update" payload: `entity.fields` minus primary-key
551
+ * members; the caller treats every one as optional (partial).
552
+ */
553
+ declare function updateFields(entity: Entity): Field[];
554
+ /**
555
+ * The TS type a non-nullable, non-list value of this field maps to, as a source
556
+ * string every generator's typed output must agree on. Returns a `ScalarTsType`
557
+ * token for scalars (`bytes -> 'Uint8Array'`, `json -> 'JsonValue'`, `decimal`
558
+ * kept as `'string'` to preserve precision — runtime representation stays each
559
+ * generator's choice), the enum type name for `{ kind: 'enum' }` (identifiers are
560
+ * never prefixed, ADR-0004), and `'unknown'` for `{ kind: 'unknown' }`.
561
+ */
562
+ declare function scalarTsType(type: FieldType): string;
563
+
564
+ /**
565
+ * IR format version. Orthogonal to the npm semver of `@kurotako/ir`
566
+ * (independent versioning): a single string, bumped only on a breaking change
567
+ * to the format itself.
568
+ */
569
+ declare const IR_VERSION = "1";
570
+ /**
571
+ * Whether an IR produced against `irVersion` can be consumed by this build.
572
+ * v1 rule: strict equality.
573
+ */
574
+ declare function isCompatible(irVersion: string): boolean;
575
+
576
+ export { type CompositeUnique, CompositeUniqueSchema, type Constraints, ConstraintsSchema, type DefaultValue, DefaultValueSchema, type Entity, type EntityBuilder, EntitySchema, type EnumBuilder, type EnumDef, EnumDefSchema, type EnumValue, EnumValueSchema, type Field, type FieldBuilder, FieldSchema, type FieldType, FieldTypeSchema, type IR, IR_VERSION, type IndexDef, IndexDefSchema, type IndexType, IndexTypeSchema, IrBuildError, type IrIssue, type IrIssueCode, IrSchema, type IrValidation, IrValidationError, type JsonValue, JsonValueSchema, type ReferentialAction, ReferentialActionSchema, type Relation, type RelationBuilder, RelationSchema, type RelationTarget, RelationTargetSchema, type ScalarTsType, type ScalarType, ScalarTypeSchema, type SourceIR, type SourceIrBuilder, SourceIrSchema, type StringFormat, StringFormatSchema, assertIR, assertSourceIR, createFields, createSourceIR, getSource, isCompatible, isCreateOptional, isCrossSource, isDbAssigned, iterEntities, iterFields, parseIR, primaryKeyFields, resolveEntity, resolveEnum, resolveRelationTarget, scalarTsType, updateFields, validateIR, validateSourceIR };