@uncutsql/core 0.3.0 → 0.4.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/dist/index.cjs +888 -60
- package/dist/index.d.cts +273 -17
- package/dist/index.d.ts +273 -17
- package/dist/index.js +880 -61
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,12 +10,16 @@ export interface TableIdentity {
|
|
|
10
10
|
readonly schema?: string;
|
|
11
11
|
}
|
|
12
12
|
export interface Constraint {
|
|
13
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
14
|
+
readonly comment?: string;
|
|
13
15
|
readonly kind: string;
|
|
14
16
|
readonly properties: {
|
|
15
17
|
readonly [key: string]: SchemaValue;
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export interface DatabaseColumn {
|
|
21
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
22
|
+
readonly comment?: string;
|
|
19
23
|
readonly constraints: readonly Constraint[];
|
|
20
24
|
readonly dataType: SchemaValue;
|
|
21
25
|
readonly key: string;
|
|
@@ -23,6 +27,8 @@ export interface DatabaseColumn {
|
|
|
23
27
|
}
|
|
24
28
|
/** Standalone indexes belong to a table; keys are normalized within its namespace. */
|
|
25
29
|
export interface DatabaseIndex {
|
|
30
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
31
|
+
readonly comment?: string;
|
|
26
32
|
readonly key: string;
|
|
27
33
|
readonly name: string;
|
|
28
34
|
/**
|
|
@@ -38,6 +44,8 @@ export interface DatabaseIndex {
|
|
|
38
44
|
}
|
|
39
45
|
export interface DatabaseTable {
|
|
40
46
|
readonly columns: readonly DatabaseColumn[];
|
|
47
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
48
|
+
readonly comment?: string;
|
|
41
49
|
readonly constraints: readonly Constraint[];
|
|
42
50
|
readonly identity: TableIdentity;
|
|
43
51
|
readonly indexes?: readonly DatabaseIndex[];
|
|
@@ -48,7 +56,16 @@ export interface DatabaseTable {
|
|
|
48
56
|
};
|
|
49
57
|
}
|
|
50
58
|
export interface DatabaseView {
|
|
59
|
+
/**
|
|
60
|
+
* Comments of columns, keyed by output column name; each is non-empty. Absent and `{}` are the
|
|
61
|
+
* same value; writers omit the field when it would be empty.
|
|
62
|
+
*/
|
|
63
|
+
readonly columnComments?: {
|
|
64
|
+
readonly [column: string]: string;
|
|
65
|
+
};
|
|
51
66
|
readonly columns?: readonly string[];
|
|
67
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
68
|
+
readonly comment?: string;
|
|
52
69
|
readonly identity: TableIdentity;
|
|
53
70
|
readonly name: string;
|
|
54
71
|
/**
|
|
@@ -61,10 +78,17 @@ export interface DatabaseView {
|
|
|
61
78
|
readonly query: SchemaValue;
|
|
62
79
|
}
|
|
63
80
|
export interface DatabaseTrigger {
|
|
81
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
82
|
+
readonly comment?: string;
|
|
64
83
|
/** Dialect-normalized timing, event, condition and ordered actions. */
|
|
65
84
|
readonly definition: SchemaValue;
|
|
66
85
|
readonly identity: TableIdentity;
|
|
67
86
|
readonly name: string;
|
|
87
|
+
/**
|
|
88
|
+
* Where the name is unique. Absent: in its namespace (SQLite). `"target"`: on its target
|
|
89
|
+
* (PostgreSQL), so `identity` and `target` together are the key.
|
|
90
|
+
*/
|
|
91
|
+
readonly scope?: "target";
|
|
68
92
|
/** Normalized identity of the table or view that owns this trigger. */
|
|
69
93
|
readonly target: TableIdentity;
|
|
70
94
|
}
|
|
@@ -74,6 +98,8 @@ export interface SequenceOwner {
|
|
|
74
98
|
readonly table: TableIdentity;
|
|
75
99
|
}
|
|
76
100
|
export interface DatabaseSequence {
|
|
101
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
102
|
+
readonly comment?: string;
|
|
77
103
|
/**
|
|
78
104
|
* Dialect-normalized data type and parameters. Core compares it with `schemaValueEqual`
|
|
79
105
|
* and never interprets its keys.
|
|
@@ -87,6 +113,8 @@ export interface DatabaseSequence {
|
|
|
87
113
|
readonly owner?: SequenceOwner;
|
|
88
114
|
}
|
|
89
115
|
export interface DatabaseFunction {
|
|
116
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
117
|
+
readonly comment?: string;
|
|
90
118
|
/**
|
|
91
119
|
* Dialect-normalized language, arguments, result, attributes and body. Core compares it with
|
|
92
120
|
* `schemaValueEqual` and never interprets its keys.
|
|
@@ -108,6 +136,8 @@ export interface NamespaceIdentity {
|
|
|
108
136
|
readonly name: string;
|
|
109
137
|
}
|
|
110
138
|
export interface DatabaseNamespace {
|
|
139
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
140
|
+
readonly comment?: string;
|
|
111
141
|
readonly identity: NamespaceIdentity;
|
|
112
142
|
readonly name: string;
|
|
113
143
|
/** Namespaced keys retain vendor-specific features without teaching core their meaning. */
|
|
@@ -115,13 +145,40 @@ export interface DatabaseNamespace {
|
|
|
115
145
|
readonly [key: string]: SchemaValue;
|
|
116
146
|
};
|
|
117
147
|
}
|
|
148
|
+
export interface DatabaseExtension {
|
|
149
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
150
|
+
readonly comment?: string;
|
|
151
|
+
/** The name as the database stores it. Unique in a model. */
|
|
152
|
+
readonly name: string;
|
|
153
|
+
/** The namespace that holds the extension's objects; absent in dialects without namespaces. */
|
|
154
|
+
readonly schema?: string;
|
|
155
|
+
/** The pinned version. Absent: the server's default version at creation, never compared. */
|
|
156
|
+
readonly version?: string;
|
|
157
|
+
}
|
|
158
|
+
/** A named type that holds one of an ordered list of labels. */
|
|
159
|
+
export interface DatabaseEnum {
|
|
160
|
+
/** Documentation text: non-empty, compared exactly. Absent: no comment. */
|
|
161
|
+
readonly comment?: string;
|
|
162
|
+
readonly identity: TableIdentity;
|
|
163
|
+
readonly name: string;
|
|
164
|
+
/** Labels in sort order, unique, compared exactly (case and spaces count). May be empty. */
|
|
165
|
+
readonly values: readonly string[];
|
|
166
|
+
}
|
|
118
167
|
export interface DatabaseExternals {
|
|
168
|
+
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
169
|
+
readonly enums?: readonly DatabaseEnum[];
|
|
170
|
+
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
171
|
+
readonly extensions?: readonly DatabaseExtension[];
|
|
119
172
|
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
120
173
|
readonly functions?: readonly DatabaseFunction[];
|
|
121
174
|
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
122
175
|
readonly tables?: readonly DatabaseTable[];
|
|
123
176
|
}
|
|
124
177
|
export interface DatabaseSchema {
|
|
178
|
+
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
179
|
+
readonly enums?: readonly DatabaseEnum[];
|
|
180
|
+
/** Absent and `[]` are the same value; writers omit the field when it would be empty. */
|
|
181
|
+
readonly extensions?: readonly DatabaseExtension[];
|
|
125
182
|
/**
|
|
126
183
|
* Objects outside the managed scope that the model references. Diff, procedures and lowering
|
|
127
184
|
* never create, alter or drop them. Absent and `{}` are the same value.
|
|
@@ -138,6 +195,7 @@ export interface DatabaseSchema {
|
|
|
138
195
|
readonly views?: readonly DatabaseView[];
|
|
139
196
|
}
|
|
140
197
|
export declare const tableKey: (table: TableIdentity) => string;
|
|
198
|
+
export declare const triggerKey: (trigger: DatabaseTrigger) => string;
|
|
141
199
|
export declare const functionKey: (fn: Pick<DatabaseFunction, "identity" | "signature">) => string;
|
|
142
200
|
/** `schema.name(type, …)` for diagnostics; signature entries that are not strings print as JSON. */
|
|
143
201
|
export declare const functionLabel: (fn: Pick<DatabaseFunction, "identity" | "signature">) => string;
|
|
@@ -150,6 +208,69 @@ export interface ExternalObject {
|
|
|
150
208
|
}
|
|
151
209
|
/** The external objects of the models, tables before functions, each listed once by its key. */
|
|
152
210
|
export declare const externalObjects: (...databases: readonly DatabaseSchema[]) => readonly ExternalObject[];
|
|
211
|
+
export interface EnumObject {
|
|
212
|
+
readonly identity: TableIdentity;
|
|
213
|
+
/** `Enum schema.name` or `External enum schema.name`. */
|
|
214
|
+
readonly label: string;
|
|
215
|
+
}
|
|
216
|
+
/** The managed and external enums of the models, each listed once by its key. */
|
|
217
|
+
export declare const enumObjects: (...databases: readonly DatabaseSchema[]) => readonly EnumObject[];
|
|
218
|
+
/** The managed and external extensions of the models, each listed once by its name. */
|
|
219
|
+
export declare const extensionObjects: (...databases: readonly DatabaseSchema[]) => readonly DatabaseExtension[];
|
|
220
|
+
/** The object a comment belongs to. Table, column and other names are those of the after model. */
|
|
221
|
+
export type CommentTarget = {
|
|
222
|
+
readonly identity: TableIdentity;
|
|
223
|
+
readonly kind: "enum" | "sequence" | "table" | "view";
|
|
224
|
+
} |
|
|
225
|
+
/** `column` is a column key. */
|
|
226
|
+
{
|
|
227
|
+
readonly column: string;
|
|
228
|
+
readonly kind: "column";
|
|
229
|
+
readonly table: TableIdentity;
|
|
230
|
+
} |
|
|
231
|
+
/** `column` is an output column name. */
|
|
232
|
+
{
|
|
233
|
+
readonly column: string;
|
|
234
|
+
readonly kind: "viewColumn";
|
|
235
|
+
readonly view: TableIdentity;
|
|
236
|
+
} |
|
|
237
|
+
/** `index` is an index key. */
|
|
238
|
+
{
|
|
239
|
+
readonly index: string;
|
|
240
|
+
readonly kind: "index";
|
|
241
|
+
readonly table: TableIdentity;
|
|
242
|
+
} |
|
|
243
|
+
/** Core does not know constraint names: the constraint is its value, without its comment. */
|
|
244
|
+
{
|
|
245
|
+
readonly constraint: Constraint;
|
|
246
|
+
readonly kind: "constraint";
|
|
247
|
+
readonly table: TableIdentity;
|
|
248
|
+
} | {
|
|
249
|
+
readonly identity: TableIdentity;
|
|
250
|
+
readonly kind: "function";
|
|
251
|
+
readonly signature: readonly SchemaValue[];
|
|
252
|
+
} | {
|
|
253
|
+
readonly kind: "trigger";
|
|
254
|
+
readonly name: string;
|
|
255
|
+
readonly target: TableIdentity;
|
|
256
|
+
} | {
|
|
257
|
+
readonly identity: NamespaceIdentity;
|
|
258
|
+
readonly kind: "namespace";
|
|
259
|
+
} | {
|
|
260
|
+
readonly kind: "extension";
|
|
261
|
+
readonly name: string;
|
|
262
|
+
};
|
|
263
|
+
export interface CommentObject {
|
|
264
|
+
/** The relation or named object, for the location of a diagnostic. */
|
|
265
|
+
readonly identity: TableIdentity;
|
|
266
|
+
/** `Comment on table schema.name`, `Comment on column schema.table.column`, and so on. */
|
|
267
|
+
readonly label: string;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Every commented object of the models, externals included, and of `targets` (for example those of
|
|
271
|
+
* `SetComment` procedures), each listed once by its label. A dialect without comments refuses them.
|
|
272
|
+
*/
|
|
273
|
+
export declare const commentObjects: (databases: readonly DatabaseSchema[], targets?: readonly CommentTarget[]) => readonly CommentObject[];
|
|
153
274
|
export declare const namespaceKey: (namespace: NamespaceIdentity) => string;
|
|
154
275
|
/** The namespace that contains an object, or undefined when its identity has no schema level. */
|
|
155
276
|
export declare const namespaceOf: (identity: TableIdentity) => NamespaceIdentity | undefined;
|
|
@@ -267,6 +388,29 @@ export type FunctionChange = {
|
|
|
267
388
|
readonly after: DatabaseFunction;
|
|
268
389
|
readonly before: DatabaseFunction;
|
|
269
390
|
};
|
|
391
|
+
export interface EnumValueRename {
|
|
392
|
+
readonly after: string;
|
|
393
|
+
readonly before: string;
|
|
394
|
+
}
|
|
395
|
+
export type EnumChange = {
|
|
396
|
+
readonly _tag: "EnumAdded" | "EnumRemoved";
|
|
397
|
+
readonly enum: DatabaseEnum;
|
|
398
|
+
} | {
|
|
399
|
+
readonly _tag: "EnumRenamed" | "EnumChanged";
|
|
400
|
+
readonly after: DatabaseEnum;
|
|
401
|
+
readonly before: DatabaseEnum;
|
|
402
|
+
/** The accepted value renames. Other label differences are additions, removals or order. */
|
|
403
|
+
readonly values: readonly EnumValueRename[];
|
|
404
|
+
};
|
|
405
|
+
/** An extension that changes both its version and its schema has one change of each. */
|
|
406
|
+
export type ExtensionChange = {
|
|
407
|
+
readonly _tag: "ExtensionAdded" | "ExtensionRemoved";
|
|
408
|
+
readonly extension: DatabaseExtension;
|
|
409
|
+
} | {
|
|
410
|
+
readonly _tag: "ExtensionVersionChanged" | "ExtensionSchemaChanged";
|
|
411
|
+
readonly after: DatabaseExtension;
|
|
412
|
+
readonly before: DatabaseExtension;
|
|
413
|
+
};
|
|
270
414
|
/** A namespace change lists the namespace only; objects inside it keep their own changes. */
|
|
271
415
|
export type NamespaceChange = {
|
|
272
416
|
readonly _tag: "NamespaceAdded" | "NamespaceRemoved";
|
|
@@ -276,13 +420,20 @@ export type NamespaceChange = {
|
|
|
276
420
|
readonly after: DatabaseNamespace;
|
|
277
421
|
readonly before: DatabaseNamespace;
|
|
278
422
|
};
|
|
423
|
+
/** A changed comment of an object that both models hold. `target` names it in the after model. */
|
|
424
|
+
export interface CommentChange {
|
|
425
|
+
readonly _tag: "CommentChanged";
|
|
426
|
+
readonly after?: string;
|
|
427
|
+
readonly before?: string;
|
|
428
|
+
readonly target: CommentTarget;
|
|
429
|
+
}
|
|
279
430
|
export interface DropGuard {
|
|
280
431
|
/** Source column name. Omit to require an empty table. */
|
|
281
432
|
readonly column?: string;
|
|
282
433
|
readonly table: TableIdentity;
|
|
283
434
|
}
|
|
284
435
|
export interface DatabaseDiff {
|
|
285
|
-
readonly changes: readonly (NamespaceChange | TableChange | ViewChange | TriggerChange | SequenceChange | FunctionChange)[];
|
|
436
|
+
readonly changes: readonly (NamespaceChange | EnumChange | ExtensionChange | TableChange | ViewChange | TriggerChange | SequenceChange | FunctionChange | CommentChange)[];
|
|
286
437
|
readonly dropGuards?: readonly DropGuard[];
|
|
287
438
|
}
|
|
288
439
|
export declare const validateDatabase: (database: DatabaseSchema, side: DiffDiagnostic["side"]) => readonly DiffDiagnostic[];
|
|
@@ -292,6 +443,8 @@ export declare const validateDatabase: (database: DatabaseSchema, side: DiffDiag
|
|
|
292
443
|
* unique, including `public`) is the caller's to validate.
|
|
293
444
|
*/
|
|
294
445
|
export declare const checkManagedScope: (model: DatabaseSchema, managedSchemas: readonly string[]) => readonly DiffDiagnostic[];
|
|
446
|
+
/** Same kinds and properties in the same order; comments are compared by `diffComments`. */
|
|
447
|
+
export declare const constraintsEqual: (before: readonly Constraint[], after: readonly Constraint[]) => boolean;
|
|
295
448
|
export declare const compareTable: (before: DatabaseTable, after: DatabaseTable) => readonly TableAlteration[];
|
|
296
449
|
/** Table and column renames of a migration, keyed by the table's key before the rename. */
|
|
297
450
|
export interface SequenceRenames {
|
|
@@ -304,6 +457,28 @@ export declare const sequenceRenames: (changes: DatabaseDiff["changes"]) => Sequ
|
|
|
304
457
|
export declare const diffFunctions: (before: DatabaseSchema, after: DatabaseSchema) => readonly FunctionChange[];
|
|
305
458
|
/** Sequence changes. `renames` are the table and column renames the migration applies. */
|
|
306
459
|
export declare const diffSequences: (before: DatabaseSchema, after: DatabaseSchema, renames?: SequenceRenames) => readonly SequenceChange[];
|
|
460
|
+
/**
|
|
461
|
+
* Trigger changes, paired by `triggerKey`. `renames` are the table renames the migration applies: a
|
|
462
|
+
* trigger follows its renamed target. There are no trigger renames.
|
|
463
|
+
*/
|
|
464
|
+
export declare const diffTriggers: (before: DatabaseSchema, after: DatabaseSchema, renames?: SequenceRenames) => readonly TriggerChange[];
|
|
465
|
+
/** The enum and value renames of a migration, keyed by the enum's key before the rename. */
|
|
466
|
+
export interface EnumRenames {
|
|
467
|
+
readonly enums: ReadonlyMap<string, TableIdentity>;
|
|
468
|
+
/** Per enum, each renamed label before and after. */
|
|
469
|
+
readonly values: ReadonlyMap<string, ReadonlyMap<string, string>>;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Enum changes, paired by `tableKey`. A renamed enum has one `EnumRenamed`, whether or not its
|
|
473
|
+
* labels differ too. Removals and order are not judged here; external enums are ignored.
|
|
474
|
+
*/
|
|
475
|
+
export declare const diffEnums: (before: DatabaseSchema, after: DatabaseSchema, renames?: EnumRenames) => readonly EnumChange[];
|
|
476
|
+
/**
|
|
477
|
+
* Comment changes of the managed objects that both models hold. `changes` are the changes of the
|
|
478
|
+
* migration: their table, column, sequence and enum renames pair objects across a rename. Added and
|
|
479
|
+
* removed objects have no change here.
|
|
480
|
+
*/
|
|
481
|
+
export declare const diffComments: (before: DatabaseSchema, after: DatabaseSchema, changes?: DatabaseDiff["changes"]) => readonly CommentChange[];
|
|
307
482
|
/** Compare normalized relational models without parsing SQL or consulting a dialect. */
|
|
308
483
|
export declare const diffDatabases: (before: DatabaseSchema, after: DatabaseSchema) => Effect.Effect<DatabaseDiff, SchemaDiffError>;
|
|
309
484
|
interface TableProcedure {
|
|
@@ -319,6 +494,28 @@ export type MigrationProcedure = {
|
|
|
319
494
|
readonly _tag: "AlterNamespace";
|
|
320
495
|
readonly after: DatabaseNamespace;
|
|
321
496
|
readonly before: DatabaseNamespace;
|
|
497
|
+
} | {
|
|
498
|
+
readonly _tag: "CreateEnum" | "DropEnum";
|
|
499
|
+
readonly enum: DatabaseEnum;
|
|
500
|
+
} | {
|
|
501
|
+
readonly _tag: "RenameEnum" | "AlterEnum";
|
|
502
|
+
readonly after: DatabaseEnum;
|
|
503
|
+
readonly before: DatabaseEnum;
|
|
504
|
+
/** Labels to rename; other label differences are additions, removals or order. */
|
|
505
|
+
readonly values: readonly EnumValueRename[];
|
|
506
|
+
} | {
|
|
507
|
+
readonly _tag: "CreateExtension" | "DropExtension";
|
|
508
|
+
readonly extension: DatabaseExtension;
|
|
509
|
+
} | {
|
|
510
|
+
/** Changes the pinned version. */
|
|
511
|
+
readonly _tag: "UpdateExtension";
|
|
512
|
+
readonly after: DatabaseExtension;
|
|
513
|
+
readonly before: DatabaseExtension;
|
|
514
|
+
} | {
|
|
515
|
+
/** Changes the schema. */
|
|
516
|
+
readonly _tag: "MoveExtension";
|
|
517
|
+
readonly after: DatabaseExtension;
|
|
518
|
+
readonly before: DatabaseExtension;
|
|
322
519
|
} | {
|
|
323
520
|
readonly _tag: "CreateFunction" | "DropFunction";
|
|
324
521
|
readonly function: DatabaseFunction;
|
|
@@ -357,7 +554,13 @@ export type MigrationProcedure = {
|
|
|
357
554
|
readonly _tag: "AlterTable";
|
|
358
555
|
}) | (TableProcedure & {
|
|
359
556
|
readonly _tag: "RenameTable";
|
|
360
|
-
})
|
|
557
|
+
}) | {
|
|
558
|
+
/** Sets, changes or (without `after`) removes the comment of an object that both models hold. */
|
|
559
|
+
readonly _tag: "SetComment";
|
|
560
|
+
readonly after?: string;
|
|
561
|
+
readonly before?: string;
|
|
562
|
+
readonly target: CommentTarget;
|
|
563
|
+
};
|
|
361
564
|
export interface DatabaseMigration {
|
|
362
565
|
readonly dropGuards?: readonly DropGuard[];
|
|
363
566
|
readonly procedures: readonly MigrationProcedure[];
|
|
@@ -394,7 +597,7 @@ interface SemanticStructField extends SemanticElement {
|
|
|
394
597
|
}
|
|
395
598
|
/**
|
|
396
599
|
* Dialect-neutral, non-null database values. Numeric bounds are inclusive and exact decimal strings.
|
|
397
|
-
*
|
|
600
|
+
* Domains are equal when they are structurally equal, field and value order included.
|
|
398
601
|
*/
|
|
399
602
|
type SemanticValueDomain = {
|
|
400
603
|
readonly kind: "decimal" | "integer" | "real";
|
|
@@ -407,7 +610,14 @@ type SemanticValueDomain = {
|
|
|
407
610
|
readonly scale?: number;
|
|
408
611
|
};
|
|
409
612
|
} | {
|
|
410
|
-
readonly kind: "binary" | "boolean" | "date" | "json" | "opaque" | "
|
|
613
|
+
readonly kind: "binary" | "boolean" | "date" | "json" | "opaque" | "time" | "timestamp";
|
|
614
|
+
} | {
|
|
615
|
+
readonly kind: "text";
|
|
616
|
+
/**
|
|
617
|
+
* The only non-null values the type allows, in the type's order: unique, compared exactly,
|
|
618
|
+
* possibly empty. Absent: any text.
|
|
619
|
+
*/
|
|
620
|
+
readonly values?: readonly string[];
|
|
411
621
|
} | {
|
|
412
622
|
/** An ordered sequence. */
|
|
413
623
|
readonly element: SemanticElement;
|
|
@@ -443,6 +653,8 @@ interface SemanticInsertPolicy extends SemanticWritePolicy {
|
|
|
443
653
|
readonly omission: SemanticFact<"allowed" | "required">;
|
|
444
654
|
}
|
|
445
655
|
interface SemanticColumn {
|
|
656
|
+
/** The column's comment: non-empty, as the database stores it. */
|
|
657
|
+
readonly comment?: string;
|
|
446
658
|
/** A known null means there is no computed expression. */
|
|
447
659
|
readonly computed: SemanticFact<{
|
|
448
660
|
readonly storage: SemanticFact<"stored" | "virtual">;
|
|
@@ -482,6 +694,8 @@ interface SemanticForeignKey {
|
|
|
482
694
|
readonly target: SemanticForeignKeyTarget;
|
|
483
695
|
}
|
|
484
696
|
interface SemanticRelationIdentity {
|
|
697
|
+
/** The relation's comment: non-empty, as the database stores it. */
|
|
698
|
+
readonly comment?: string;
|
|
485
699
|
readonly identity: TableIdentity;
|
|
486
700
|
readonly kind: "table" | "view";
|
|
487
701
|
/** Original SQL relation name. */
|
|
@@ -579,24 +793,56 @@ interface ExecutionResult {
|
|
|
579
793
|
readonly lastAppliedId: number;
|
|
580
794
|
readonly rolledBackId?: number;
|
|
581
795
|
}
|
|
796
|
+
interface ReplayOptions {
|
|
797
|
+
/** External declarations of the generation lock, created as stand-ins before replay (ADR 0024). */
|
|
798
|
+
readonly externals?: DatabaseExternals;
|
|
799
|
+
/** A database to replay in instead of the driver's default; nothing is kept in it. */
|
|
800
|
+
readonly replayDatabase?: string;
|
|
801
|
+
}
|
|
802
|
+
interface ExtractOptions {
|
|
803
|
+
/** ADR 0024 managed schemas. Set only when configured and the dialect supports them. */
|
|
804
|
+
readonly managedSchemas?: readonly string[];
|
|
805
|
+
}
|
|
806
|
+
interface ExtractedPart {
|
|
807
|
+
/** The owning object, as written in messages. */
|
|
808
|
+
readonly name: string;
|
|
809
|
+
/** Directory segments, then the file stem, relative to the destination. Absent means `[name]`. */
|
|
810
|
+
readonly path?: readonly string[];
|
|
811
|
+
readonly sql: string;
|
|
812
|
+
}
|
|
813
|
+
interface ExtractOmission {
|
|
814
|
+
readonly category: "dependent" | "unmanaged" | "unsupported";
|
|
815
|
+
/** For `dependent`, the omitted object it depends on; otherwise an optional reason. */
|
|
816
|
+
readonly detail?: string;
|
|
817
|
+
/** For example "partitioned table", "policy", "column type ltree". */
|
|
818
|
+
readonly kind: string;
|
|
819
|
+
/** Qualified catalog name: schema.object, then the sub-object (column, constraint, index, trigger, policy). */
|
|
820
|
+
readonly name: string;
|
|
821
|
+
}
|
|
822
|
+
interface ExtractResult {
|
|
823
|
+
/** Informational lines printed after success. */
|
|
824
|
+
readonly notes?: readonly string[];
|
|
825
|
+
readonly omitted: readonly ExtractOmission[];
|
|
826
|
+
/** In load order: concatenated in this order, and sorted by path, the parts give the same order. */
|
|
827
|
+
readonly parts: readonly ExtractedPart[];
|
|
828
|
+
}
|
|
829
|
+
/** One line per omission, ordered by category (unsupported, unmanaged, dependent), then name. */
|
|
830
|
+
export declare const formatExtractOmissions: (omitted: readonly ExtractOmission[]) => readonly string[];
|
|
582
831
|
/** Optional execution capability, selected and wired by the consumer separately from syntax. */
|
|
583
832
|
interface MigrationExecutor<E extends Error = Error, R = never> {
|
|
584
833
|
/** Verify a replayed prefix against an existing target, then initialize its history. */
|
|
585
|
-
readonly adopt?: <V extends Error, RV>(target: string, prefix: readonly MigrationSource[], verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema) => Effect.Effect<void, V, RV>, desired?: DatabaseSchema) => Effect.Effect<void, E | V, R | RV>;
|
|
834
|
+
readonly adopt?: <V extends Error, RV>(target: string, prefix: readonly MigrationSource[], verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema) => Effect.Effect<void, V, RV>, desired?: DatabaseSchema, options?: ReplayOptions) => Effect.Effect<void, E | V, R | RV>;
|
|
586
835
|
readonly apply: <V extends Error, RV>(target: string, migrations: readonly MigrationSource[], desired: DatabaseSchema, verifySchema: (actual: DatabaseSchema, expected: DatabaseSchema, stage: "applied" | "desired") => Effect.Effect<void, V, RV>,
|
|
587
836
|
/** With a checkpoint, files start immediately after it (at it for rollback).
|
|
588
837
|
* Recheck the database position under the write transaction before executing. */
|
|
589
838
|
checkpoint?: MigrationCheckpoint) => Effect.Effect<ExecutionResult, E | V, R | RV>;
|
|
590
839
|
readonly checkpoint: (target: string) => Effect.Effect<MigrationCheckpoint, E, R>;
|
|
591
840
|
/** Replay a verified prefix on an empty database and render its state as one SQL migration. */
|
|
592
|
-
readonly compact?: (migrations: readonly MigrationSource[]) => Effect.Effect<string, E, R>;
|
|
841
|
+
readonly compact?: (migrations: readonly MigrationSource[], options?: ReplayOptions) => Effect.Effect<string, E, R>;
|
|
593
842
|
/** Equal to the `Dialect.name` that produced the lock. Core and the CLI compare it only for equality. */
|
|
594
843
|
readonly dialect: string;
|
|
595
|
-
/** Schema-only SQL
|
|
596
|
-
readonly extract?: (target: string) => Effect.Effect<
|
|
597
|
-
readonly name: string;
|
|
598
|
-
readonly sql: string;
|
|
599
|
-
}[], E, R>;
|
|
844
|
+
/** Schema-only SQL in parts, with the objects the driver left out. */
|
|
845
|
+
readonly extract?: (target: string, options?: ExtractOptions) => Effect.Effect<ExtractResult, E, R>;
|
|
600
846
|
/** Undo only the most recently applied migration. */
|
|
601
847
|
readonly rollback?: MigrationExecutor<E, R>["apply"];
|
|
602
848
|
}
|
|
@@ -615,10 +861,9 @@ export declare const migrationRun: (direction: "up" | "down", migrations: readon
|
|
|
615
861
|
export declare const continuesRun: (run: MigrationRun, migrations: readonly MigrationSource[], checkpoint: MigrationCheckpoint | undefined, tip: MigrationCheckpoint) => boolean;
|
|
616
862
|
/** The file to execute after the tip, or `undefined` when the run is complete. */
|
|
617
863
|
export declare const nextMigration: (run: MigrationRun, migrations: readonly MigrationSource[], tipId: number) => MigrationSource | undefined;
|
|
618
|
-
|
|
619
|
-
/** Added
|
|
864
|
+
interface DecisionQuestion {
|
|
865
|
+
/** Added names, column keys or enum labels, not guesses: none is selected automatically. */
|
|
620
866
|
readonly candidates: readonly string[];
|
|
621
|
-
readonly column?: string;
|
|
622
867
|
readonly id: string;
|
|
623
868
|
readonly question: string;
|
|
624
869
|
readonly resolution: {
|
|
@@ -629,8 +874,19 @@ export interface MigrationDecision {
|
|
|
629
874
|
readonly action: "rename";
|
|
630
875
|
readonly target: string;
|
|
631
876
|
};
|
|
877
|
+
}
|
|
878
|
+
/** A removed table, or a removed column when `column` is set. */
|
|
879
|
+
export interface TableMigrationDecision extends DecisionQuestion {
|
|
880
|
+
readonly column?: string;
|
|
632
881
|
readonly table: TableIdentity;
|
|
633
882
|
}
|
|
883
|
+
/** A removed enum, or a removed label when `value` is set. `drop_if_empty` does not apply. */
|
|
884
|
+
export interface EnumMigrationDecision extends DecisionQuestion {
|
|
885
|
+
/** The enum's identity before the migration. */
|
|
886
|
+
readonly enum: TableIdentity;
|
|
887
|
+
readonly value?: string;
|
|
888
|
+
}
|
|
889
|
+
export type MigrationDecision = TableMigrationDecision | EnumMigrationDecision;
|
|
634
890
|
export interface MigrationDecisions {
|
|
635
891
|
readonly after: DatabaseSchema;
|
|
636
892
|
readonly before: DatabaseSchema;
|
|
@@ -667,7 +923,7 @@ export interface SourceSpan {
|
|
|
667
923
|
readonly end: number;
|
|
668
924
|
readonly start: number;
|
|
669
925
|
}
|
|
670
|
-
export type SchemaSymbolKind = "column" | "function" | "index" | "namespace" | "table" | "trigger" | "view";
|
|
926
|
+
export type SchemaSymbolKind = "column" | "extension" | "function" | "index" | "namespace" | "table" | "trigger" | "type" | "view";
|
|
671
927
|
export interface SchemaSymbol {
|
|
672
928
|
readonly children: readonly SchemaSymbol[];
|
|
673
929
|
/** Short context shown next to the name, such as the written namespace. */
|
|
@@ -701,7 +957,7 @@ export interface SchemaReference extends SourceSpan {
|
|
|
701
957
|
readonly selection?: SourceSpan;
|
|
702
958
|
}
|
|
703
959
|
/** Where an unresolved identifier token was found. */
|
|
704
|
-
export type SchemaNameContext = "check" | "default" | "generated" | "index" | "query" | "table" | "trigger" | "view";
|
|
960
|
+
export type SchemaNameContext = "check" | "comment" | "default" | "generated" | "index" | "query" | "table" | "trigger" | "type" | "view";
|
|
705
961
|
/** An identifier token the service does not resolve. `nameKey` is built like `SchemaDeclaration.nameKey`. */
|
|
706
962
|
export interface SchemaNameUse extends SourceSpan {
|
|
707
963
|
readonly context: SchemaNameContext;
|
|
@@ -882,4 +1138,4 @@ interface DynamicGeneratorPlugin {
|
|
|
882
1138
|
export declare const decodeMapperPlugin: (value: unknown) => Effect.Effect<DynamicMapperPlugin, CodegenError>;
|
|
883
1139
|
/** Validate the generator value selected from a module by the consumer. */
|
|
884
1140
|
export declare const decodeGeneratorPlugin: (value: unknown) => Effect.Effect<DynamicGeneratorPlugin, CodegenError>;
|
|
885
|
-
export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionResult, GeneratedFile, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MapperDescriptor, MapperPlugin, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticValueDomain, SemanticWritePolicy };
|
|
1141
|
+
export type { ApplicationContract, ApplicationMapper, CodegenDiagnostic, ColumnIdentity, Dialect, DynamicGeneratorPlugin, DynamicMapperPlugin, ExecutionResult, ExtractOmission, ExtractOptions, ExtractResult, ExtractedPart, GeneratedFile, GenerationResult, Generator, GeneratorDescriptor, GeneratorPlugin, MapperDescriptor, MapperPlugin, MappingResult, MigrationCheckpoint, MigrationExecutor, MigrationRun, MigrationSource, ReplayOptions, SemanticColumn, SemanticColumnType, SemanticDatabaseSchema, SemanticDiagnostic, SemanticDiagnosticSubject, SemanticElement, SemanticFact, SemanticForeignKey, SemanticForeignKeyTarget, SemanticInsertPolicy, SemanticKey, SemanticRelation, SemanticSchemaResolution, SemanticStructField, SemanticValueDomain, SemanticWritePolicy };
|