@sedrino/db-schema 0.1.1

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,1222 @@
1
+ import { z } from 'zod';
2
+ import { Client } from '@libsql/client';
3
+
4
+ declare const foreignKeyActionSchema: z.ZodEnum<{
5
+ cascade: "cascade";
6
+ restrict: "restrict";
7
+ "set null": "set null";
8
+ "set default": "set default";
9
+ "no action": "no action";
10
+ }>;
11
+ declare const fieldReferenceSpecSchema: z.ZodObject<{
12
+ table: z.ZodString;
13
+ field: z.ZodString;
14
+ onDelete: z.ZodOptional<z.ZodEnum<{
15
+ cascade: "cascade";
16
+ restrict: "restrict";
17
+ "set null": "set null";
18
+ "set default": "set default";
19
+ "no action": "no action";
20
+ }>>;
21
+ onUpdate: z.ZodOptional<z.ZodEnum<{
22
+ cascade: "cascade";
23
+ restrict: "restrict";
24
+ "set null": "set null";
25
+ "set default": "set default";
26
+ "no action": "no action";
27
+ }>>;
28
+ }, z.core.$strip>;
29
+ declare const logicalTypeSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ kind: z.ZodLiteral<"id">;
31
+ prefix: z.ZodString;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ kind: z.ZodLiteral<"string">;
34
+ format: z.ZodOptional<z.ZodEnum<{
35
+ email: "email";
36
+ url: "url";
37
+ slug: "slug";
38
+ }>>;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ kind: z.ZodLiteral<"text">;
41
+ }, z.core.$strip>, z.ZodObject<{
42
+ kind: z.ZodLiteral<"boolean">;
43
+ }, z.core.$strip>, z.ZodObject<{
44
+ kind: z.ZodLiteral<"integer">;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ kind: z.ZodLiteral<"number">;
47
+ }, z.core.$strip>, z.ZodObject<{
48
+ kind: z.ZodLiteral<"enum">;
49
+ values: z.ZodArray<z.ZodString>;
50
+ }, z.core.$strip>, z.ZodObject<{
51
+ kind: z.ZodLiteral<"json">;
52
+ tsType: z.ZodString;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ kind: z.ZodLiteral<"temporal.instant">;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ kind: z.ZodLiteral<"temporal.plainDate">;
57
+ }, z.core.$strip>], "kind">;
58
+ declare const storageSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
59
+ strategy: z.ZodLiteral<"sqlite.text">;
60
+ column: z.ZodString;
61
+ }, z.core.$strip>, z.ZodObject<{
62
+ strategy: z.ZodLiteral<"sqlite.integer">;
63
+ column: z.ZodString;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ strategy: z.ZodLiteral<"sqlite.real">;
66
+ column: z.ZodString;
67
+ }, z.core.$strip>, z.ZodObject<{
68
+ strategy: z.ZodLiteral<"sqlite.temporalInstantEpochMs">;
69
+ column: z.ZodString;
70
+ }, z.core.$strip>, z.ZodObject<{
71
+ strategy: z.ZodLiteral<"sqlite.temporalPlainDateText">;
72
+ column: z.ZodString;
73
+ }, z.core.$strip>], "strategy">;
74
+ declare const defaultSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
75
+ kind: z.ZodLiteral<"literal">;
76
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
77
+ }, z.core.$strip>, z.ZodObject<{
78
+ kind: z.ZodLiteral<"now">;
79
+ }, z.core.$strip>, z.ZodObject<{
80
+ kind: z.ZodLiteral<"generatedId">;
81
+ prefix: z.ZodString;
82
+ }, z.core.$strip>], "kind">;
83
+ declare const fieldSpecSchema: z.ZodObject<{
84
+ id: z.ZodString;
85
+ name: z.ZodString;
86
+ logical: z.ZodDiscriminatedUnion<[z.ZodObject<{
87
+ kind: z.ZodLiteral<"id">;
88
+ prefix: z.ZodString;
89
+ }, z.core.$strip>, z.ZodObject<{
90
+ kind: z.ZodLiteral<"string">;
91
+ format: z.ZodOptional<z.ZodEnum<{
92
+ email: "email";
93
+ url: "url";
94
+ slug: "slug";
95
+ }>>;
96
+ }, z.core.$strip>, z.ZodObject<{
97
+ kind: z.ZodLiteral<"text">;
98
+ }, z.core.$strip>, z.ZodObject<{
99
+ kind: z.ZodLiteral<"boolean">;
100
+ }, z.core.$strip>, z.ZodObject<{
101
+ kind: z.ZodLiteral<"integer">;
102
+ }, z.core.$strip>, z.ZodObject<{
103
+ kind: z.ZodLiteral<"number">;
104
+ }, z.core.$strip>, z.ZodObject<{
105
+ kind: z.ZodLiteral<"enum">;
106
+ values: z.ZodArray<z.ZodString>;
107
+ }, z.core.$strip>, z.ZodObject<{
108
+ kind: z.ZodLiteral<"json">;
109
+ tsType: z.ZodString;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ kind: z.ZodLiteral<"temporal.instant">;
112
+ }, z.core.$strip>, z.ZodObject<{
113
+ kind: z.ZodLiteral<"temporal.plainDate">;
114
+ }, z.core.$strip>], "kind">;
115
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
116
+ strategy: z.ZodLiteral<"sqlite.text">;
117
+ column: z.ZodString;
118
+ }, z.core.$strip>, z.ZodObject<{
119
+ strategy: z.ZodLiteral<"sqlite.integer">;
120
+ column: z.ZodString;
121
+ }, z.core.$strip>, z.ZodObject<{
122
+ strategy: z.ZodLiteral<"sqlite.real">;
123
+ column: z.ZodString;
124
+ }, z.core.$strip>, z.ZodObject<{
125
+ strategy: z.ZodLiteral<"sqlite.temporalInstantEpochMs">;
126
+ column: z.ZodString;
127
+ }, z.core.$strip>, z.ZodObject<{
128
+ strategy: z.ZodLiteral<"sqlite.temporalPlainDateText">;
129
+ column: z.ZodString;
130
+ }, z.core.$strip>], "strategy">;
131
+ nullable: z.ZodDefault<z.ZodBoolean>;
132
+ default: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
133
+ kind: z.ZodLiteral<"literal">;
134
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
135
+ }, z.core.$strip>, z.ZodObject<{
136
+ kind: z.ZodLiteral<"now">;
137
+ }, z.core.$strip>, z.ZodObject<{
138
+ kind: z.ZodLiteral<"generatedId">;
139
+ prefix: z.ZodString;
140
+ }, z.core.$strip>], "kind">>;
141
+ primaryKey: z.ZodDefault<z.ZodBoolean>;
142
+ unique: z.ZodDefault<z.ZodBoolean>;
143
+ description: z.ZodOptional<z.ZodString>;
144
+ references: z.ZodOptional<z.ZodObject<{
145
+ table: z.ZodString;
146
+ field: z.ZodString;
147
+ onDelete: z.ZodOptional<z.ZodEnum<{
148
+ cascade: "cascade";
149
+ restrict: "restrict";
150
+ "set null": "set null";
151
+ "set default": "set default";
152
+ "no action": "no action";
153
+ }>>;
154
+ onUpdate: z.ZodOptional<z.ZodEnum<{
155
+ cascade: "cascade";
156
+ restrict: "restrict";
157
+ "set null": "set null";
158
+ "set default": "set default";
159
+ "no action": "no action";
160
+ }>>;
161
+ }, z.core.$strip>>;
162
+ }, z.core.$strip>;
163
+ declare const indexSpecSchema: z.ZodObject<{
164
+ name: z.ZodOptional<z.ZodString>;
165
+ fields: z.ZodArray<z.ZodString>;
166
+ }, z.core.$strip>;
167
+ declare const uniqueSpecSchema: z.ZodObject<{
168
+ name: z.ZodOptional<z.ZodString>;
169
+ fields: z.ZodArray<z.ZodString>;
170
+ }, z.core.$strip>;
171
+ declare const tableSpecSchema: z.ZodObject<{
172
+ id: z.ZodString;
173
+ name: z.ZodString;
174
+ description: z.ZodOptional<z.ZodString>;
175
+ fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
176
+ id: z.ZodString;
177
+ name: z.ZodString;
178
+ logical: z.ZodDiscriminatedUnion<[z.ZodObject<{
179
+ kind: z.ZodLiteral<"id">;
180
+ prefix: z.ZodString;
181
+ }, z.core.$strip>, z.ZodObject<{
182
+ kind: z.ZodLiteral<"string">;
183
+ format: z.ZodOptional<z.ZodEnum<{
184
+ email: "email";
185
+ url: "url";
186
+ slug: "slug";
187
+ }>>;
188
+ }, z.core.$strip>, z.ZodObject<{
189
+ kind: z.ZodLiteral<"text">;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ kind: z.ZodLiteral<"boolean">;
192
+ }, z.core.$strip>, z.ZodObject<{
193
+ kind: z.ZodLiteral<"integer">;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ kind: z.ZodLiteral<"number">;
196
+ }, z.core.$strip>, z.ZodObject<{
197
+ kind: z.ZodLiteral<"enum">;
198
+ values: z.ZodArray<z.ZodString>;
199
+ }, z.core.$strip>, z.ZodObject<{
200
+ kind: z.ZodLiteral<"json">;
201
+ tsType: z.ZodString;
202
+ }, z.core.$strip>, z.ZodObject<{
203
+ kind: z.ZodLiteral<"temporal.instant">;
204
+ }, z.core.$strip>, z.ZodObject<{
205
+ kind: z.ZodLiteral<"temporal.plainDate">;
206
+ }, z.core.$strip>], "kind">;
207
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
208
+ strategy: z.ZodLiteral<"sqlite.text">;
209
+ column: z.ZodString;
210
+ }, z.core.$strip>, z.ZodObject<{
211
+ strategy: z.ZodLiteral<"sqlite.integer">;
212
+ column: z.ZodString;
213
+ }, z.core.$strip>, z.ZodObject<{
214
+ strategy: z.ZodLiteral<"sqlite.real">;
215
+ column: z.ZodString;
216
+ }, z.core.$strip>, z.ZodObject<{
217
+ strategy: z.ZodLiteral<"sqlite.temporalInstantEpochMs">;
218
+ column: z.ZodString;
219
+ }, z.core.$strip>, z.ZodObject<{
220
+ strategy: z.ZodLiteral<"sqlite.temporalPlainDateText">;
221
+ column: z.ZodString;
222
+ }, z.core.$strip>], "strategy">;
223
+ nullable: z.ZodDefault<z.ZodBoolean>;
224
+ default: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
225
+ kind: z.ZodLiteral<"literal">;
226
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
227
+ }, z.core.$strip>, z.ZodObject<{
228
+ kind: z.ZodLiteral<"now">;
229
+ }, z.core.$strip>, z.ZodObject<{
230
+ kind: z.ZodLiteral<"generatedId">;
231
+ prefix: z.ZodString;
232
+ }, z.core.$strip>], "kind">>;
233
+ primaryKey: z.ZodDefault<z.ZodBoolean>;
234
+ unique: z.ZodDefault<z.ZodBoolean>;
235
+ description: z.ZodOptional<z.ZodString>;
236
+ references: z.ZodOptional<z.ZodObject<{
237
+ table: z.ZodString;
238
+ field: z.ZodString;
239
+ onDelete: z.ZodOptional<z.ZodEnum<{
240
+ cascade: "cascade";
241
+ restrict: "restrict";
242
+ "set null": "set null";
243
+ "set default": "set default";
244
+ "no action": "no action";
245
+ }>>;
246
+ onUpdate: z.ZodOptional<z.ZodEnum<{
247
+ cascade: "cascade";
248
+ restrict: "restrict";
249
+ "set null": "set null";
250
+ "set default": "set default";
251
+ "no action": "no action";
252
+ }>>;
253
+ }, z.core.$strip>>;
254
+ }, z.core.$strip>>>;
255
+ indexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
256
+ name: z.ZodOptional<z.ZodString>;
257
+ fields: z.ZodArray<z.ZodString>;
258
+ }, z.core.$strip>>>;
259
+ uniques: z.ZodDefault<z.ZodArray<z.ZodObject<{
260
+ name: z.ZodOptional<z.ZodString>;
261
+ fields: z.ZodArray<z.ZodString>;
262
+ }, z.core.$strip>>>;
263
+ }, z.core.$strip>;
264
+ declare const schemaDocumentSchema: z.ZodObject<{
265
+ version: z.ZodLiteral<1>;
266
+ dialect: z.ZodLiteral<"sqlite">;
267
+ schemaId: z.ZodString;
268
+ tables: z.ZodDefault<z.ZodArray<z.ZodObject<{
269
+ id: z.ZodString;
270
+ name: z.ZodString;
271
+ description: z.ZodOptional<z.ZodString>;
272
+ fields: z.ZodDefault<z.ZodArray<z.ZodObject<{
273
+ id: z.ZodString;
274
+ name: z.ZodString;
275
+ logical: z.ZodDiscriminatedUnion<[z.ZodObject<{
276
+ kind: z.ZodLiteral<"id">;
277
+ prefix: z.ZodString;
278
+ }, z.core.$strip>, z.ZodObject<{
279
+ kind: z.ZodLiteral<"string">;
280
+ format: z.ZodOptional<z.ZodEnum<{
281
+ email: "email";
282
+ url: "url";
283
+ slug: "slug";
284
+ }>>;
285
+ }, z.core.$strip>, z.ZodObject<{
286
+ kind: z.ZodLiteral<"text">;
287
+ }, z.core.$strip>, z.ZodObject<{
288
+ kind: z.ZodLiteral<"boolean">;
289
+ }, z.core.$strip>, z.ZodObject<{
290
+ kind: z.ZodLiteral<"integer">;
291
+ }, z.core.$strip>, z.ZodObject<{
292
+ kind: z.ZodLiteral<"number">;
293
+ }, z.core.$strip>, z.ZodObject<{
294
+ kind: z.ZodLiteral<"enum">;
295
+ values: z.ZodArray<z.ZodString>;
296
+ }, z.core.$strip>, z.ZodObject<{
297
+ kind: z.ZodLiteral<"json">;
298
+ tsType: z.ZodString;
299
+ }, z.core.$strip>, z.ZodObject<{
300
+ kind: z.ZodLiteral<"temporal.instant">;
301
+ }, z.core.$strip>, z.ZodObject<{
302
+ kind: z.ZodLiteral<"temporal.plainDate">;
303
+ }, z.core.$strip>], "kind">;
304
+ storage: z.ZodDiscriminatedUnion<[z.ZodObject<{
305
+ strategy: z.ZodLiteral<"sqlite.text">;
306
+ column: z.ZodString;
307
+ }, z.core.$strip>, z.ZodObject<{
308
+ strategy: z.ZodLiteral<"sqlite.integer">;
309
+ column: z.ZodString;
310
+ }, z.core.$strip>, z.ZodObject<{
311
+ strategy: z.ZodLiteral<"sqlite.real">;
312
+ column: z.ZodString;
313
+ }, z.core.$strip>, z.ZodObject<{
314
+ strategy: z.ZodLiteral<"sqlite.temporalInstantEpochMs">;
315
+ column: z.ZodString;
316
+ }, z.core.$strip>, z.ZodObject<{
317
+ strategy: z.ZodLiteral<"sqlite.temporalPlainDateText">;
318
+ column: z.ZodString;
319
+ }, z.core.$strip>], "strategy">;
320
+ nullable: z.ZodDefault<z.ZodBoolean>;
321
+ default: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
322
+ kind: z.ZodLiteral<"literal">;
323
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
324
+ }, z.core.$strip>, z.ZodObject<{
325
+ kind: z.ZodLiteral<"now">;
326
+ }, z.core.$strip>, z.ZodObject<{
327
+ kind: z.ZodLiteral<"generatedId">;
328
+ prefix: z.ZodString;
329
+ }, z.core.$strip>], "kind">>;
330
+ primaryKey: z.ZodDefault<z.ZodBoolean>;
331
+ unique: z.ZodDefault<z.ZodBoolean>;
332
+ description: z.ZodOptional<z.ZodString>;
333
+ references: z.ZodOptional<z.ZodObject<{
334
+ table: z.ZodString;
335
+ field: z.ZodString;
336
+ onDelete: z.ZodOptional<z.ZodEnum<{
337
+ cascade: "cascade";
338
+ restrict: "restrict";
339
+ "set null": "set null";
340
+ "set default": "set default";
341
+ "no action": "no action";
342
+ }>>;
343
+ onUpdate: z.ZodOptional<z.ZodEnum<{
344
+ cascade: "cascade";
345
+ restrict: "restrict";
346
+ "set null": "set null";
347
+ "set default": "set default";
348
+ "no action": "no action";
349
+ }>>;
350
+ }, z.core.$strip>>;
351
+ }, z.core.$strip>>>;
352
+ indexes: z.ZodDefault<z.ZodArray<z.ZodObject<{
353
+ name: z.ZodOptional<z.ZodString>;
354
+ fields: z.ZodArray<z.ZodString>;
355
+ }, z.core.$strip>>>;
356
+ uniques: z.ZodDefault<z.ZodArray<z.ZodObject<{
357
+ name: z.ZodOptional<z.ZodString>;
358
+ fields: z.ZodArray<z.ZodString>;
359
+ }, z.core.$strip>>>;
360
+ }, z.core.$strip>>>;
361
+ }, z.core.$strip>;
362
+ type ForeignKeyAction = z.infer<typeof foreignKeyActionSchema>;
363
+ type FieldReferenceSpec = z.infer<typeof fieldReferenceSpecSchema>;
364
+ type LogicalTypeSpec = z.infer<typeof logicalTypeSpecSchema>;
365
+ type StorageSpec = z.infer<typeof storageSpecSchema>;
366
+ type DefaultSpec = z.infer<typeof defaultSpecSchema>;
367
+ type FieldSpec = z.infer<typeof fieldSpecSchema>;
368
+ type IndexSpec = z.infer<typeof indexSpecSchema>;
369
+ type UniqueSpec = z.infer<typeof uniqueSpecSchema>;
370
+ type TableSpec = z.infer<typeof tableSpecSchema>;
371
+ type DatabaseSchemaDocument = z.infer<typeof schemaDocumentSchema>;
372
+ type SchemaValidationIssue = {
373
+ path: string;
374
+ message: string;
375
+ };
376
+
377
+ type MigrationMeta = {
378
+ id: string;
379
+ name: string;
380
+ description?: string;
381
+ };
382
+ type MigrationOperation = {
383
+ kind: "createTable";
384
+ table: TableSpec;
385
+ } | {
386
+ kind: "dropTable";
387
+ tableName: string;
388
+ } | {
389
+ kind: "renameTable";
390
+ from: string;
391
+ to: string;
392
+ } | {
393
+ kind: "addField";
394
+ tableName: string;
395
+ field: FieldSpec;
396
+ } | {
397
+ kind: "dropField";
398
+ tableName: string;
399
+ fieldName: string;
400
+ } | {
401
+ kind: "renameField";
402
+ tableName: string;
403
+ from: string;
404
+ to: string;
405
+ } | {
406
+ kind: "addIndex";
407
+ tableName: string;
408
+ index: IndexSpec;
409
+ } | {
410
+ kind: "dropIndex";
411
+ tableName: string;
412
+ indexName: string;
413
+ } | {
414
+ kind: "addUnique";
415
+ tableName: string;
416
+ unique: UniqueSpec;
417
+ } | {
418
+ kind: "dropUnique";
419
+ tableName: string;
420
+ uniqueName: string;
421
+ };
422
+ type MigrationDefinition = {
423
+ meta: MigrationMeta;
424
+ buildOperations(): MigrationOperation[];
425
+ };
426
+ type FieldOptions = {
427
+ column?: string;
428
+ description?: string;
429
+ storage?: StorageSpec;
430
+ references?: FieldReferenceSpec;
431
+ };
432
+ declare class MutableFieldBuilder {
433
+ private field;
434
+ constructor(field: FieldSpec);
435
+ required(): this;
436
+ nullable(): this;
437
+ unique(): this;
438
+ default(value: string | number | boolean | null): this;
439
+ defaultNow(): this;
440
+ references(reference: FieldReferenceSpec): this;
441
+ description(description: string): this;
442
+ column(column: string): this;
443
+ build(): {
444
+ id: string;
445
+ name: string;
446
+ logical: {
447
+ kind: "id";
448
+ prefix: string;
449
+ } | {
450
+ kind: "string";
451
+ format?: "email" | "url" | "slug" | undefined;
452
+ } | {
453
+ kind: "text";
454
+ } | {
455
+ kind: "boolean";
456
+ } | {
457
+ kind: "integer";
458
+ } | {
459
+ kind: "number";
460
+ } | {
461
+ kind: "enum";
462
+ values: string[];
463
+ } | {
464
+ kind: "json";
465
+ tsType: string;
466
+ } | {
467
+ kind: "temporal.instant";
468
+ } | {
469
+ kind: "temporal.plainDate";
470
+ };
471
+ storage: {
472
+ strategy: "sqlite.text";
473
+ column: string;
474
+ } | {
475
+ strategy: "sqlite.integer";
476
+ column: string;
477
+ } | {
478
+ strategy: "sqlite.real";
479
+ column: string;
480
+ } | {
481
+ strategy: "sqlite.temporalInstantEpochMs";
482
+ column: string;
483
+ } | {
484
+ strategy: "sqlite.temporalPlainDateText";
485
+ column: string;
486
+ };
487
+ nullable: boolean;
488
+ primaryKey: boolean;
489
+ unique: boolean;
490
+ default?: {
491
+ kind: "literal";
492
+ value: string | number | boolean | null;
493
+ } | {
494
+ kind: "now";
495
+ } | {
496
+ kind: "generatedId";
497
+ prefix: string;
498
+ } | undefined;
499
+ description?: string | undefined;
500
+ references?: {
501
+ table: string;
502
+ field: string;
503
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
504
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
505
+ } | undefined;
506
+ };
507
+ }
508
+ declare class TableCreateBuilder {
509
+ private readonly tableName;
510
+ private readonly fields;
511
+ private readonly indexes;
512
+ private readonly uniques;
513
+ private descriptionText?;
514
+ constructor(tableName: string);
515
+ description(text: string): this;
516
+ private addField;
517
+ id(fieldName: string, options: Omit<FieldOptions, "storage"> & {
518
+ prefix: string;
519
+ }): MutableFieldBuilder;
520
+ string(fieldName: string, options?: FieldOptions & {
521
+ format?: "email" | "url" | "slug";
522
+ }): MutableFieldBuilder;
523
+ text(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
524
+ boolean(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
525
+ integer(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
526
+ number(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
527
+ enum(fieldName: string, values: string[], options?: FieldOptions): MutableFieldBuilder;
528
+ json(fieldName: string, tsType: string, options?: FieldOptions): MutableFieldBuilder;
529
+ temporalInstant(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
530
+ temporalPlainDate(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
531
+ reference(fieldName: string, options: Omit<FieldOptions, "references"> & {
532
+ references: FieldReferenceSpec;
533
+ }): MutableFieldBuilder;
534
+ index(fields: string[], options?: {
535
+ name?: string;
536
+ }): this;
537
+ unique(fields: string[], options?: {
538
+ name?: string;
539
+ }): this;
540
+ build(): TableSpec;
541
+ }
542
+ declare class TableAlterBuilder {
543
+ private readonly tableName;
544
+ readonly operations: MigrationOperation[];
545
+ constructor(tableName: string);
546
+ private addField;
547
+ string(fieldName: string, options?: FieldOptions & {
548
+ format?: "email" | "url" | "slug";
549
+ }): MutableFieldBuilder;
550
+ text(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
551
+ boolean(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
552
+ integer(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
553
+ number(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
554
+ enum(fieldName: string, values: string[], options?: FieldOptions): MutableFieldBuilder;
555
+ json(fieldName: string, tsType: string, options?: FieldOptions): MutableFieldBuilder;
556
+ temporalInstant(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
557
+ temporalPlainDate(fieldName: string, options?: FieldOptions): MutableFieldBuilder;
558
+ reference(fieldName: string, options: Omit<FieldOptions, "references"> & {
559
+ references: FieldReferenceSpec;
560
+ }): MutableFieldBuilder;
561
+ dropField(fieldName: string): this;
562
+ renameField(from: string, to: string): this;
563
+ addIndex(fields: string[], options?: {
564
+ name?: string;
565
+ }): this;
566
+ dropIndex(indexName: string): this;
567
+ addUnique(fields: string[], options?: {
568
+ name?: string;
569
+ }): this;
570
+ dropUnique(uniqueName: string): this;
571
+ }
572
+ declare class MigrationBuilderImpl {
573
+ readonly operations: MigrationOperation[];
574
+ createTable(name: string, callback: (table: TableCreateBuilder) => void): this;
575
+ dropTable(tableName: string): this;
576
+ renameTable(from: string, to: string): this;
577
+ alterTable(tableName: string, callback: (table: TableAlterBuilder) => void): this;
578
+ }
579
+ declare function createMigration(meta: MigrationMeta, callback: (migration: MigrationBuilderImpl) => void): MigrationDefinition;
580
+
581
+ type PlannedMigration = {
582
+ migrationId: string;
583
+ migrationName: string;
584
+ fromSchemaHash: string;
585
+ toSchemaHash: string;
586
+ operations: MigrationOperation[];
587
+ nextSchema: DatabaseSchemaDocument;
588
+ sql: {
589
+ statements: string[];
590
+ warnings: string[];
591
+ };
592
+ };
593
+ declare function planMigration(args: {
594
+ currentSchema?: DatabaseSchemaDocument;
595
+ migration: MigrationDefinition;
596
+ }): PlannedMigration;
597
+ declare function materializeSchema(args: {
598
+ baseSchema?: DatabaseSchemaDocument;
599
+ migrations: MigrationDefinition[];
600
+ }): {
601
+ schema: {
602
+ version: 1;
603
+ dialect: "sqlite";
604
+ schemaId: string;
605
+ tables: {
606
+ id: string;
607
+ name: string;
608
+ fields: {
609
+ id: string;
610
+ name: string;
611
+ logical: {
612
+ kind: "id";
613
+ prefix: string;
614
+ } | {
615
+ kind: "string";
616
+ format?: "email" | "url" | "slug" | undefined;
617
+ } | {
618
+ kind: "text";
619
+ } | {
620
+ kind: "boolean";
621
+ } | {
622
+ kind: "integer";
623
+ } | {
624
+ kind: "number";
625
+ } | {
626
+ kind: "enum";
627
+ values: string[];
628
+ } | {
629
+ kind: "json";
630
+ tsType: string;
631
+ } | {
632
+ kind: "temporal.instant";
633
+ } | {
634
+ kind: "temporal.plainDate";
635
+ };
636
+ storage: {
637
+ strategy: "sqlite.text";
638
+ column: string;
639
+ } | {
640
+ strategy: "sqlite.integer";
641
+ column: string;
642
+ } | {
643
+ strategy: "sqlite.real";
644
+ column: string;
645
+ } | {
646
+ strategy: "sqlite.temporalInstantEpochMs";
647
+ column: string;
648
+ } | {
649
+ strategy: "sqlite.temporalPlainDateText";
650
+ column: string;
651
+ };
652
+ nullable: boolean;
653
+ primaryKey: boolean;
654
+ unique: boolean;
655
+ default?: {
656
+ kind: "literal";
657
+ value: string | number | boolean | null;
658
+ } | {
659
+ kind: "now";
660
+ } | {
661
+ kind: "generatedId";
662
+ prefix: string;
663
+ } | undefined;
664
+ description?: string | undefined;
665
+ references?: {
666
+ table: string;
667
+ field: string;
668
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
669
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
670
+ } | undefined;
671
+ }[];
672
+ indexes: {
673
+ fields: string[];
674
+ name?: string | undefined;
675
+ }[];
676
+ uniques: {
677
+ fields: string[];
678
+ name?: string | undefined;
679
+ }[];
680
+ description?: string | undefined;
681
+ }[];
682
+ };
683
+ plans: PlannedMigration[];
684
+ };
685
+ declare function applyOperationsToSchema(schemaInput: DatabaseSchemaDocument, operations: MigrationOperation[]): {
686
+ version: 1;
687
+ dialect: "sqlite";
688
+ schemaId: string;
689
+ tables: {
690
+ id: string;
691
+ name: string;
692
+ fields: {
693
+ id: string;
694
+ name: string;
695
+ logical: {
696
+ kind: "id";
697
+ prefix: string;
698
+ } | {
699
+ kind: "string";
700
+ format?: "email" | "url" | "slug" | undefined;
701
+ } | {
702
+ kind: "text";
703
+ } | {
704
+ kind: "boolean";
705
+ } | {
706
+ kind: "integer";
707
+ } | {
708
+ kind: "number";
709
+ } | {
710
+ kind: "enum";
711
+ values: string[];
712
+ } | {
713
+ kind: "json";
714
+ tsType: string;
715
+ } | {
716
+ kind: "temporal.instant";
717
+ } | {
718
+ kind: "temporal.plainDate";
719
+ };
720
+ storage: {
721
+ strategy: "sqlite.text";
722
+ column: string;
723
+ } | {
724
+ strategy: "sqlite.integer";
725
+ column: string;
726
+ } | {
727
+ strategy: "sqlite.real";
728
+ column: string;
729
+ } | {
730
+ strategy: "sqlite.temporalInstantEpochMs";
731
+ column: string;
732
+ } | {
733
+ strategy: "sqlite.temporalPlainDateText";
734
+ column: string;
735
+ };
736
+ nullable: boolean;
737
+ primaryKey: boolean;
738
+ unique: boolean;
739
+ default?: {
740
+ kind: "literal";
741
+ value: string | number | boolean | null;
742
+ } | {
743
+ kind: "now";
744
+ } | {
745
+ kind: "generatedId";
746
+ prefix: string;
747
+ } | undefined;
748
+ description?: string | undefined;
749
+ references?: {
750
+ table: string;
751
+ field: string;
752
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
753
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
754
+ } | undefined;
755
+ }[];
756
+ indexes: {
757
+ fields: string[];
758
+ name?: string | undefined;
759
+ }[];
760
+ uniques: {
761
+ fields: string[];
762
+ name?: string | undefined;
763
+ }[];
764
+ description?: string | undefined;
765
+ }[];
766
+ };
767
+
768
+ declare function compileSchemaToDrizzle(schema: DatabaseSchemaDocument): string;
769
+
770
+ declare function compileSchemaToSqlite(schema: DatabaseSchemaDocument): string;
771
+ declare function renderSqliteMigration(operations: MigrationOperation[]): {
772
+ statements: string[];
773
+ warnings: string[];
774
+ };
775
+
776
+ type SchemaStateRow = {
777
+ schemaHash: string;
778
+ schemaJson: string;
779
+ };
780
+ type ApplyMigrationsResult = {
781
+ appliedPlans: PlannedMigration[];
782
+ skippedMigrationIds: string[];
783
+ currentSchema: DatabaseSchemaDocument;
784
+ currentSchemaHash: string;
785
+ };
786
+ type LibsqlConnectionOptions = {
787
+ url: string;
788
+ authToken?: string;
789
+ };
790
+ declare function createLibsqlClient(options: LibsqlConnectionOptions): Client;
791
+ declare function applyMigrations(args: {
792
+ client?: Client;
793
+ connection?: LibsqlConnectionOptions;
794
+ migrations: MigrationDefinition[];
795
+ baseSchema?: DatabaseSchemaDocument;
796
+ }): Promise<{
797
+ appliedPlans: PlannedMigration[];
798
+ skippedMigrationIds: string[];
799
+ currentSchema: {
800
+ version: 1;
801
+ dialect: "sqlite";
802
+ schemaId: string;
803
+ tables: {
804
+ id: string;
805
+ name: string;
806
+ fields: {
807
+ id: string;
808
+ name: string;
809
+ logical: {
810
+ kind: "id";
811
+ prefix: string;
812
+ } | {
813
+ kind: "string";
814
+ format?: "email" | "url" | "slug" | undefined;
815
+ } | {
816
+ kind: "text";
817
+ } | {
818
+ kind: "boolean";
819
+ } | {
820
+ kind: "integer";
821
+ } | {
822
+ kind: "number";
823
+ } | {
824
+ kind: "enum";
825
+ values: string[];
826
+ } | {
827
+ kind: "json";
828
+ tsType: string;
829
+ } | {
830
+ kind: "temporal.instant";
831
+ } | {
832
+ kind: "temporal.plainDate";
833
+ };
834
+ storage: {
835
+ strategy: "sqlite.text";
836
+ column: string;
837
+ } | {
838
+ strategy: "sqlite.integer";
839
+ column: string;
840
+ } | {
841
+ strategy: "sqlite.real";
842
+ column: string;
843
+ } | {
844
+ strategy: "sqlite.temporalInstantEpochMs";
845
+ column: string;
846
+ } | {
847
+ strategy: "sqlite.temporalPlainDateText";
848
+ column: string;
849
+ };
850
+ nullable: boolean;
851
+ primaryKey: boolean;
852
+ unique: boolean;
853
+ default?: {
854
+ kind: "literal";
855
+ value: string | number | boolean | null;
856
+ } | {
857
+ kind: "now";
858
+ } | {
859
+ kind: "generatedId";
860
+ prefix: string;
861
+ } | undefined;
862
+ description?: string | undefined;
863
+ references?: {
864
+ table: string;
865
+ field: string;
866
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
867
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
868
+ } | undefined;
869
+ }[];
870
+ indexes: {
871
+ fields: string[];
872
+ name?: string | undefined;
873
+ }[];
874
+ uniques: {
875
+ fields: string[];
876
+ name?: string | undefined;
877
+ }[];
878
+ description?: string | undefined;
879
+ }[];
880
+ };
881
+ currentSchemaHash: string;
882
+ }>;
883
+ declare function listAppliedMigrations(client: Client): Promise<{
884
+ migrationId: string;
885
+ migrationName: string;
886
+ schemaHash: string;
887
+ appliedAt: number;
888
+ }[]>;
889
+ declare function getSchemaState(client: Client): Promise<SchemaStateRow | null>;
890
+
891
+ type DbProjectLayout = {
892
+ dbDir: string;
893
+ migrationsDir: string;
894
+ schemaDir: string;
895
+ snapshotPath: string;
896
+ drizzlePath: string;
897
+ };
898
+ declare function resolveDbProjectLayout(dbDir?: string): DbProjectLayout;
899
+ declare function loadMigrationDefinitionsFromDirectory(migrationsDir: string): Promise<MigrationDefinition[]>;
900
+ declare function materializeProjectMigrations(layout: DbProjectLayout): Promise<{
901
+ migrations: MigrationDefinition[];
902
+ schema: {
903
+ version: 1;
904
+ dialect: "sqlite";
905
+ schemaId: string;
906
+ tables: {
907
+ id: string;
908
+ name: string;
909
+ fields: {
910
+ id: string;
911
+ name: string;
912
+ logical: {
913
+ kind: "id";
914
+ prefix: string;
915
+ } | {
916
+ kind: "string";
917
+ format?: "email" | "url" | "slug" | undefined;
918
+ } | {
919
+ kind: "text";
920
+ } | {
921
+ kind: "boolean";
922
+ } | {
923
+ kind: "integer";
924
+ } | {
925
+ kind: "number";
926
+ } | {
927
+ kind: "enum";
928
+ values: string[];
929
+ } | {
930
+ kind: "json";
931
+ tsType: string;
932
+ } | {
933
+ kind: "temporal.instant";
934
+ } | {
935
+ kind: "temporal.plainDate";
936
+ };
937
+ storage: {
938
+ strategy: "sqlite.text";
939
+ column: string;
940
+ } | {
941
+ strategy: "sqlite.integer";
942
+ column: string;
943
+ } | {
944
+ strategy: "sqlite.real";
945
+ column: string;
946
+ } | {
947
+ strategy: "sqlite.temporalInstantEpochMs";
948
+ column: string;
949
+ } | {
950
+ strategy: "sqlite.temporalPlainDateText";
951
+ column: string;
952
+ };
953
+ nullable: boolean;
954
+ primaryKey: boolean;
955
+ unique: boolean;
956
+ default?: {
957
+ kind: "literal";
958
+ value: string | number | boolean | null;
959
+ } | {
960
+ kind: "now";
961
+ } | {
962
+ kind: "generatedId";
963
+ prefix: string;
964
+ } | undefined;
965
+ description?: string | undefined;
966
+ references?: {
967
+ table: string;
968
+ field: string;
969
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
970
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
971
+ } | undefined;
972
+ }[];
973
+ indexes: {
974
+ fields: string[];
975
+ name?: string | undefined;
976
+ }[];
977
+ uniques: {
978
+ fields: string[];
979
+ name?: string | undefined;
980
+ }[];
981
+ description?: string | undefined;
982
+ }[];
983
+ };
984
+ plans: PlannedMigration[];
985
+ }>;
986
+ declare function writeSchemaSnapshot(schema: DatabaseSchemaDocument, snapshotPath: string): Promise<void>;
987
+ declare function writeDrizzleSchema(schema: DatabaseSchemaDocument, drizzlePath: string): Promise<void>;
988
+
989
+ declare function createEmptySchema(schemaId?: string): {
990
+ version: 1;
991
+ dialect: "sqlite";
992
+ schemaId: string;
993
+ tables: {
994
+ id: string;
995
+ name: string;
996
+ fields: {
997
+ id: string;
998
+ name: string;
999
+ logical: {
1000
+ kind: "id";
1001
+ prefix: string;
1002
+ } | {
1003
+ kind: "string";
1004
+ format?: "email" | "url" | "slug" | undefined;
1005
+ } | {
1006
+ kind: "text";
1007
+ } | {
1008
+ kind: "boolean";
1009
+ } | {
1010
+ kind: "integer";
1011
+ } | {
1012
+ kind: "number";
1013
+ } | {
1014
+ kind: "enum";
1015
+ values: string[];
1016
+ } | {
1017
+ kind: "json";
1018
+ tsType: string;
1019
+ } | {
1020
+ kind: "temporal.instant";
1021
+ } | {
1022
+ kind: "temporal.plainDate";
1023
+ };
1024
+ storage: {
1025
+ strategy: "sqlite.text";
1026
+ column: string;
1027
+ } | {
1028
+ strategy: "sqlite.integer";
1029
+ column: string;
1030
+ } | {
1031
+ strategy: "sqlite.real";
1032
+ column: string;
1033
+ } | {
1034
+ strategy: "sqlite.temporalInstantEpochMs";
1035
+ column: string;
1036
+ } | {
1037
+ strategy: "sqlite.temporalPlainDateText";
1038
+ column: string;
1039
+ };
1040
+ nullable: boolean;
1041
+ primaryKey: boolean;
1042
+ unique: boolean;
1043
+ default?: {
1044
+ kind: "literal";
1045
+ value: string | number | boolean | null;
1046
+ } | {
1047
+ kind: "now";
1048
+ } | {
1049
+ kind: "generatedId";
1050
+ prefix: string;
1051
+ } | undefined;
1052
+ description?: string | undefined;
1053
+ references?: {
1054
+ table: string;
1055
+ field: string;
1056
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1057
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1058
+ } | undefined;
1059
+ }[];
1060
+ indexes: {
1061
+ fields: string[];
1062
+ name?: string | undefined;
1063
+ }[];
1064
+ uniques: {
1065
+ fields: string[];
1066
+ name?: string | undefined;
1067
+ }[];
1068
+ description?: string | undefined;
1069
+ }[];
1070
+ };
1071
+ declare function parseSchemaDocument(input: unknown): DatabaseSchemaDocument;
1072
+ declare function validateSchemaDocument(input: unknown): {
1073
+ schema: DatabaseSchemaDocument;
1074
+ issues: SchemaValidationIssue[];
1075
+ };
1076
+ declare function assertValidSchemaDocument(input: unknown): DatabaseSchemaDocument;
1077
+ declare function schemaHash(input: DatabaseSchemaDocument): string;
1078
+ declare function findTable(schema: DatabaseSchemaDocument, tableName: string): {
1079
+ id: string;
1080
+ name: string;
1081
+ fields: {
1082
+ id: string;
1083
+ name: string;
1084
+ logical: {
1085
+ kind: "id";
1086
+ prefix: string;
1087
+ } | {
1088
+ kind: "string";
1089
+ format?: "email" | "url" | "slug" | undefined;
1090
+ } | {
1091
+ kind: "text";
1092
+ } | {
1093
+ kind: "boolean";
1094
+ } | {
1095
+ kind: "integer";
1096
+ } | {
1097
+ kind: "number";
1098
+ } | {
1099
+ kind: "enum";
1100
+ values: string[];
1101
+ } | {
1102
+ kind: "json";
1103
+ tsType: string;
1104
+ } | {
1105
+ kind: "temporal.instant";
1106
+ } | {
1107
+ kind: "temporal.plainDate";
1108
+ };
1109
+ storage: {
1110
+ strategy: "sqlite.text";
1111
+ column: string;
1112
+ } | {
1113
+ strategy: "sqlite.integer";
1114
+ column: string;
1115
+ } | {
1116
+ strategy: "sqlite.real";
1117
+ column: string;
1118
+ } | {
1119
+ strategy: "sqlite.temporalInstantEpochMs";
1120
+ column: string;
1121
+ } | {
1122
+ strategy: "sqlite.temporalPlainDateText";
1123
+ column: string;
1124
+ };
1125
+ nullable: boolean;
1126
+ primaryKey: boolean;
1127
+ unique: boolean;
1128
+ default?: {
1129
+ kind: "literal";
1130
+ value: string | number | boolean | null;
1131
+ } | {
1132
+ kind: "now";
1133
+ } | {
1134
+ kind: "generatedId";
1135
+ prefix: string;
1136
+ } | undefined;
1137
+ description?: string | undefined;
1138
+ references?: {
1139
+ table: string;
1140
+ field: string;
1141
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1142
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1143
+ } | undefined;
1144
+ }[];
1145
+ indexes: {
1146
+ fields: string[];
1147
+ name?: string | undefined;
1148
+ }[];
1149
+ uniques: {
1150
+ fields: string[];
1151
+ name?: string | undefined;
1152
+ }[];
1153
+ description?: string | undefined;
1154
+ } | null;
1155
+ declare function findField(table: {
1156
+ fields: FieldSpec[];
1157
+ }, fieldName: string): {
1158
+ id: string;
1159
+ name: string;
1160
+ logical: {
1161
+ kind: "id";
1162
+ prefix: string;
1163
+ } | {
1164
+ kind: "string";
1165
+ format?: "email" | "url" | "slug" | undefined;
1166
+ } | {
1167
+ kind: "text";
1168
+ } | {
1169
+ kind: "boolean";
1170
+ } | {
1171
+ kind: "integer";
1172
+ } | {
1173
+ kind: "number";
1174
+ } | {
1175
+ kind: "enum";
1176
+ values: string[];
1177
+ } | {
1178
+ kind: "json";
1179
+ tsType: string;
1180
+ } | {
1181
+ kind: "temporal.instant";
1182
+ } | {
1183
+ kind: "temporal.plainDate";
1184
+ };
1185
+ storage: {
1186
+ strategy: "sqlite.text";
1187
+ column: string;
1188
+ } | {
1189
+ strategy: "sqlite.integer";
1190
+ column: string;
1191
+ } | {
1192
+ strategy: "sqlite.real";
1193
+ column: string;
1194
+ } | {
1195
+ strategy: "sqlite.temporalInstantEpochMs";
1196
+ column: string;
1197
+ } | {
1198
+ strategy: "sqlite.temporalPlainDateText";
1199
+ column: string;
1200
+ };
1201
+ nullable: boolean;
1202
+ primaryKey: boolean;
1203
+ unique: boolean;
1204
+ default?: {
1205
+ kind: "literal";
1206
+ value: string | number | boolean | null;
1207
+ } | {
1208
+ kind: "now";
1209
+ } | {
1210
+ kind: "generatedId";
1211
+ prefix: string;
1212
+ } | undefined;
1213
+ description?: string | undefined;
1214
+ references?: {
1215
+ table: string;
1216
+ field: string;
1217
+ onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1218
+ onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
1219
+ } | undefined;
1220
+ } | null;
1221
+
1222
+ export { type ApplyMigrationsResult, type DatabaseSchemaDocument, type DbProjectLayout, type DefaultSpec, type FieldReferenceSpec, type FieldSpec, type ForeignKeyAction, type IndexSpec, type LibsqlConnectionOptions, type LogicalTypeSpec, type MigrationDefinition, type MigrationMeta, type MigrationOperation, type PlannedMigration, type SchemaValidationIssue, type StorageSpec, type TableSpec, type UniqueSpec, applyMigrations, applyOperationsToSchema, assertValidSchemaDocument, compileSchemaToDrizzle, compileSchemaToSqlite, createEmptySchema, createLibsqlClient, createMigration, defaultSpecSchema, fieldReferenceSpecSchema, fieldSpecSchema, findField, findTable, foreignKeyActionSchema, getSchemaState, indexSpecSchema, listAppliedMigrations, loadMigrationDefinitionsFromDirectory, logicalTypeSpecSchema, materializeProjectMigrations, materializeSchema, parseSchemaDocument, planMigration, renderSqliteMigration, resolveDbProjectLayout, schemaDocumentSchema, schemaHash, storageSpecSchema, tableSpecSchema, uniqueSpecSchema, validateSchemaDocument, writeDrizzleSchema, writeSchemaSnapshot };