okmodel 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -1
- package/dist/adapters/capabilities.d.ts +62 -0
- package/dist/adapters/error.d.ts +91 -0
- package/dist/adapters/failure.d.ts +39 -0
- package/dist/adapters/pg/batch.d.ts +36 -0
- package/dist/adapters/pg/call.d.ts +59 -0
- package/dist/adapters/pg/pglite.d.ts +21 -0
- package/dist/adapters/pg/postgres-extra.d.ts +43 -0
- package/dist/adapters/pg/postgresjs.d.ts +95 -0
- package/dist/adapters/pg/result.d.ts +30 -0
- package/dist/contracts/catalog/build.d.ts +18 -0
- package/dist/contracts/catalog/document.d.ts +79 -0
- package/dist/contracts/catalog/enum.d.ts +35 -0
- package/dist/contracts/catalog/identifier.d.ts +71 -0
- package/dist/contracts/catalog/identity.d.ts +98 -0
- package/dist/contracts/catalog/index.d.ts +11 -0
- package/dist/contracts/catalog/json.d.ts +17 -0
- package/dist/contracts/catalog/object.d.ts +142 -0
- package/dist/contracts/catalog/order.d.ts +43 -0
- package/dist/contracts/catalog/rewrite.d.ts +18 -0
- package/dist/contracts/catalog/types.d.ts +292 -0
- package/dist/contracts/catalog/words.d.ts +13 -0
- package/dist/contracts/connection.d.ts +33 -0
- package/dist/contracts/driver.d.ts +163 -0
- package/dist/contracts/error.d.ts +298 -0
- package/dist/contracts/index.d.ts +11 -0
- package/dist/contracts/index.js +16 -0
- package/dist/contracts/internal.d.ts +15 -0
- package/dist/contracts/internal.js +68 -0
- package/dist/contracts/nearest.d.ts +15 -0
- package/dist/contracts/rows.d.ts +84 -0
- package/dist/contracts/sha256.d.ts +14 -0
- package/dist/contracts/utf8.d.ts +33 -0
- package/dist/dialects/pg/array-literal.d.ts +25 -0
- package/dist/dialects/pg/bool.d.ts +46 -0
- package/dist/dialects/pg/column.d.ts +386 -0
- package/dist/dialects/pg/compile.d.ts +81 -0
- package/dist/dialects/pg/custom.d.ts +21 -0
- package/dist/dialects/pg/ddl.d.ts +70 -0
- package/dist/dialects/pg/decimal.d.ts +62 -0
- package/dist/dialects/pg/declarations.d.ts +34 -0
- package/dist/dialects/pg/emit.d.ts +18 -0
- package/dist/dialects/pg/enum.d.ts +30 -0
- package/dist/dialects/pg/errors.d.ts +30 -0
- package/dist/dialects/pg/finite.d.ts +15 -0
- package/dist/dialects/pg/geometry.d.ts +55 -0
- package/dist/dialects/pg/index.d.ts +45 -0
- package/dist/dialects/pg/index.js +1821 -0
- package/dist/dialects/pg/integer.d.ts +96 -0
- package/dist/dialects/pg/introspect.d.ts +43 -0
- package/dist/dialects/pg/json.d.ts +43 -0
- package/dist/dialects/pg/keys.d.ts +32 -0
- package/dist/dialects/pg/misuse.d.ts +31 -0
- package/dist/dialects/pg/model.d.ts +71 -0
- package/dist/dialects/pg/namespace.d.ts +63 -0
- package/dist/dialects/pg/network.d.ts +28 -0
- package/dist/dialects/pg/operators.d.ts +71 -0
- package/dist/dialects/pg/ops/between.d.ts +10 -0
- package/dist/dialects/pg/ops/contains.d.ts +8 -0
- package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
- package/dist/dialects/pg/ops/eq.d.ts +9 -0
- package/dist/dialects/pg/ops/every.d.ts +9 -0
- package/dist/dialects/pg/ops/gt.d.ts +9 -0
- package/dist/dialects/pg/ops/gte.d.ts +9 -0
- package/dist/dialects/pg/ops/has.d.ts +9 -0
- package/dist/dialects/pg/ops/ilike.d.ts +8 -0
- package/dist/dialects/pg/ops/inList.d.ts +9 -0
- package/dist/dialects/pg/ops/inc.d.ts +13 -0
- package/dist/dialects/pg/ops/like.d.ts +8 -0
- package/dist/dialects/pg/ops/lt.d.ts +9 -0
- package/dist/dialects/pg/ops/lte.d.ts +9 -0
- package/dist/dialects/pg/ops/none.d.ts +9 -0
- package/dist/dialects/pg/ops/not.d.ts +9 -0
- package/dist/dialects/pg/ops/notIn.d.ts +9 -0
- package/dist/dialects/pg/ops/or.d.ts +9 -0
- package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
- package/dist/dialects/pg/quote.d.ts +24 -0
- package/dist/dialects/pg/range.d.ts +50 -0
- package/dist/dialects/pg/relations.d.ts +45 -0
- package/dist/dialects/pg/schema.d.ts +77 -0
- package/dist/dialects/pg/search.d.ts +23 -0
- package/dist/dialects/pg/table.d.ts +201 -0
- package/dist/dialects/pg/temporal.d.ts +211 -0
- package/dist/dialects/pg/text.d.ts +44 -0
- package/dist/dialects/pg/time.d.ts +46 -0
- package/dist/okm.js +2 -0
- package/dist/okmodel.js +2 -0
- package/dist/runtime/client.d.ts +47 -0
- package/dist/runtime/conflict.d.ts +38 -0
- package/dist/runtime/drift-detail.d.ts +32 -0
- package/dist/runtime/drift.d.ts +29 -0
- package/dist/runtime/include.d.ts +15 -0
- package/dist/runtime/pg/pglite.d.ts +25 -0
- package/dist/runtime/pg/pglite.js +48 -0
- package/dist/runtime/pg/postgresjs.d.ts +29 -0
- package/dist/runtime/pg/postgresjs.js +62 -0
- package/dist/runtime/plan.d.ts +167 -0
- package/dist/runtime/tx.d.ts +29 -0
- package/dist/runtime/types.d.ts +369 -0
- package/dist/runtime/write.d.ts +48 -0
- package/dist/shared/4j72449d.js +37 -0
- package/dist/shared/79ggp945.js +148 -0
- package/dist/shared/7ck0dtry.js +259 -0
- package/dist/shared/8b04d28c.js +14 -0
- package/dist/shared/ax16zpvm.js +171 -0
- package/dist/shared/ckb1p0a4.js +566 -0
- package/dist/shared/cn0n68ft.js +16 -0
- package/dist/shared/dynq16vb.js +81 -0
- package/dist/shared/f5thc1s0.js +1050 -0
- package/dist/shared/fgqgsb5z.js +281 -0
- package/dist/shared/g2v6gnc8.js +347 -0
- package/dist/shared/g5fhqmwe.js +188 -0
- package/dist/shared/gk7cs7sp.js +566 -0
- package/dist/shared/hd293j9g.js +98 -0
- package/dist/shared/j5cn2963.js +701 -0
- package/dist/shared/kynx7vbm.js +1490 -0
- package/dist/shared/mkjmqjv4.js +456 -0
- package/dist/shared/mtkwv8wx.js +18 -0
- package/dist/shared/ngk8gj61.js +40 -0
- package/dist/shared/p0cbr3g2.js +79 -0
- package/dist/shared/px90pf9p.js +396 -0
- package/dist/shared/qk3hxfja.js +83 -0
- package/dist/shared/tb4ze1tr.js +119 -0
- package/dist/shared/vkm3q4x1.js +30 -0
- package/dist/shared/w8samvk1.js +18 -0
- package/dist/shared/xy79j5hq.js +177 -0
- package/dist/shared/y9m15dfv.js +888 -0
- package/dist/shared/ycwz42az.js +412 -0
- package/dist/shared/zhc5vmgf.js +257 -0
- package/dist/tooling/cli.d.ts +1 -0
- package/dist/tooling/cli.js +193 -0
- package/dist/tooling/errors/registry.d.ts +33 -0
- package/dist/tooling/migrate/apply.d.ts +86 -0
- package/dist/tooling/migrate/commands.d.ts +21 -0
- package/dist/tooling/migrate/config.d.ts +48 -0
- package/dist/tooling/migrate/dev.d.ts +16 -0
- package/dist/tooling/migrate/equal.d.ts +15 -0
- package/dist/tooling/migrate/files.d.ts +19 -0
- package/dist/tooling/migrate/index.d.ts +7 -0
- package/dist/tooling/migrate/index.js +7 -0
- package/dist/tooling/migrate/plan.d.ts +76 -0
- package/dist/tooling/migrate/policy.d.ts +78 -0
- package/dist/tooling/migrate/project.d.ts +69 -0
- package/dist/tooling/migrate/status.d.ts +74 -0
- package/dist/tooling/migrate/values.d.ts +29 -0
- package/package.json +94 -7
- package/dist/index.js +0 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column builder shared by every Postgres type.
|
|
3
|
+
*
|
|
4
|
+
* Modifiers allocate a new builder when called. Importing this module does
|
|
5
|
+
* not build a codec table. `.validate()` stays a slot for P26.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReferentialAction } from "../../contracts/catalog/types.js";
|
|
8
|
+
/** Flags that decide the row, insert, and update shapes of one column. */
|
|
9
|
+
export type ColumnFlags = {
|
|
10
|
+
readonly nullable: boolean;
|
|
11
|
+
readonly hasDefault: boolean;
|
|
12
|
+
readonly generated: boolean;
|
|
13
|
+
readonly guarded: boolean;
|
|
14
|
+
readonly hidden: boolean;
|
|
15
|
+
readonly omitWrite: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** Flags for a required column with no default. */
|
|
18
|
+
export type PlainFlags = {
|
|
19
|
+
readonly nullable: false;
|
|
20
|
+
readonly hasDefault: false;
|
|
21
|
+
readonly generated: false;
|
|
22
|
+
readonly guarded: false;
|
|
23
|
+
readonly hidden: false;
|
|
24
|
+
readonly omitWrite: false;
|
|
25
|
+
};
|
|
26
|
+
/** Flags for {@link id}. Insert and update omit it. */
|
|
27
|
+
export type IdFlags = {
|
|
28
|
+
readonly nullable: false;
|
|
29
|
+
readonly hasDefault: true;
|
|
30
|
+
readonly generated: false;
|
|
31
|
+
readonly guarded: true;
|
|
32
|
+
readonly hidden: false;
|
|
33
|
+
readonly omitWrite: true;
|
|
34
|
+
};
|
|
35
|
+
/** Flags for {@link identity}. The database fills the value. */
|
|
36
|
+
export type IdentityFlags = {
|
|
37
|
+
readonly nullable: false;
|
|
38
|
+
readonly hasDefault: true;
|
|
39
|
+
readonly generated: false;
|
|
40
|
+
readonly guarded: false;
|
|
41
|
+
readonly hidden: false;
|
|
42
|
+
readonly omitWrite: true;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Turns one flag on.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam TFlags - Current flags
|
|
48
|
+
* @typeParam K - Flag to set
|
|
49
|
+
*/
|
|
50
|
+
export type FlagTrue<TFlags extends ColumnFlags, K extends keyof ColumnFlags> = {
|
|
51
|
+
readonly [P in keyof TFlags]: P extends K ? true : TFlags[P];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Marks a column generated, which also counts as having a default.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam TFlags - Current flags
|
|
57
|
+
*/
|
|
58
|
+
export type WithGenerated<TFlags extends ColumnFlags> = {
|
|
59
|
+
readonly [P in keyof TFlags]: P extends "generated" | "hasDefault" ? true : TFlags[P];
|
|
60
|
+
};
|
|
61
|
+
/** How a default expression is spelled in the catalog. */
|
|
62
|
+
export type SqlForm = "raw" | "quote" | "json" | "jsonb" | "cast";
|
|
63
|
+
/**
|
|
64
|
+
* A foreign key declared on a column.
|
|
65
|
+
*
|
|
66
|
+
* `columns` names the target columns. When it is omitted, `schema()` uses
|
|
67
|
+
* that table's primary key.
|
|
68
|
+
*/
|
|
69
|
+
export type ReferenceModifier = {
|
|
70
|
+
readonly table: string;
|
|
71
|
+
readonly onDelete?: ReferentialAction;
|
|
72
|
+
readonly onUpdate?: ReferentialAction;
|
|
73
|
+
readonly columns?: readonly string[];
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Options for {@link ColumnBuilder.references}.
|
|
77
|
+
*/
|
|
78
|
+
export type ReferenceOptions = {
|
|
79
|
+
readonly onDelete?: ReferentialAction;
|
|
80
|
+
readonly onUpdate?: ReferentialAction;
|
|
81
|
+
readonly columns?: readonly string[];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Validation rules, stored when a later prompt adds `.validate()`.
|
|
85
|
+
*/
|
|
86
|
+
export type ValidateModifier = {
|
|
87
|
+
readonly rules: readonly unknown[];
|
|
88
|
+
};
|
|
89
|
+
/** Nested readonly arrays of rank `D`. Ranks above 3 stay `unknown[]`. */
|
|
90
|
+
export type ArrayOf<T, D extends number> = D extends 0 ? T : D extends 1 ? readonly T[] : D extends 2 ? readonly (readonly T[])[] : D extends 3 ? readonly (readonly (readonly T[])[])[] : readonly unknown[];
|
|
91
|
+
/**
|
|
92
|
+
* Value stored on a column, including null when the column is nullable.
|
|
93
|
+
*
|
|
94
|
+
* Hidden columns are absent from the default row (`never`).
|
|
95
|
+
*
|
|
96
|
+
* @typeParam TFlags - Column flags
|
|
97
|
+
* @typeParam TValue - Scalar or array value
|
|
98
|
+
*/
|
|
99
|
+
export type ColumnRow<TFlags extends ColumnFlags, TValue> = TFlags["hidden"] extends true ? never : TFlags["nullable"] extends true ? TValue | null : TValue;
|
|
100
|
+
/** Whether insert requires the value, allows it to be omitted, or drops it. */
|
|
101
|
+
export type InsertKind<TFlags extends ColumnFlags> = TFlags["omitWrite"] extends true ? "omit" : TFlags["generated"] extends true ? "omit" : TFlags["guarded"] extends true ? "omit" : TFlags["hasDefault"] extends true ? "optional" : TFlags["nullable"] extends true ? "optional" : "required";
|
|
102
|
+
/**
|
|
103
|
+
* Insert shape of one column.
|
|
104
|
+
*
|
|
105
|
+
* `undefined` means the field is omitted. `never` means it is not writable.
|
|
106
|
+
*
|
|
107
|
+
* @typeParam TFlags - Column flags
|
|
108
|
+
* @typeParam TValue - Scalar or array value
|
|
109
|
+
*/
|
|
110
|
+
export type ColumnInsert<TFlags extends ColumnFlags, TValue> = InsertKind<TFlags> extends "omit" ? never : InsertKind<TFlags> extends "optional" ? TFlags["nullable"] extends true ? TValue | null | undefined : TValue | undefined : TValue;
|
|
111
|
+
/**
|
|
112
|
+
* Update shape of one column. Writable values are optional.
|
|
113
|
+
*
|
|
114
|
+
* @typeParam TFlags - Column flags
|
|
115
|
+
* @typeParam TValue - Scalar or array value
|
|
116
|
+
*/
|
|
117
|
+
export type ColumnUpdate<TFlags extends ColumnFlags, TValue> = InsertKind<TFlags> extends "omit" ? never : TFlags["nullable"] extends true ? TValue | null | undefined : TValue | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Row shape of a builder.
|
|
120
|
+
*
|
|
121
|
+
* @typeParam TBuilder - Column builder
|
|
122
|
+
*/
|
|
123
|
+
export type ColumnRowOf<TBuilder> = TBuilder extends ColumnBuilder<infer TValue, infer TFlags> ? ColumnRow<TFlags, TValue> : never;
|
|
124
|
+
/**
|
|
125
|
+
* Insert shape of a builder.
|
|
126
|
+
*
|
|
127
|
+
* @typeParam TBuilder - Column builder
|
|
128
|
+
*/
|
|
129
|
+
export type ColumnInsertOf<TBuilder> = TBuilder extends ColumnBuilder<infer TValue, infer TFlags> ? ColumnInsert<TFlags, TValue> : never;
|
|
130
|
+
/**
|
|
131
|
+
* Update shape of a builder.
|
|
132
|
+
*
|
|
133
|
+
* @typeParam TBuilder - Column builder
|
|
134
|
+
*/
|
|
135
|
+
export type ColumnUpdateOf<TBuilder> = TBuilder extends ColumnBuilder<infer TValue, infer TFlags> ? ColumnUpdate<TFlags, TValue> : never;
|
|
136
|
+
/** Runtime definition a modifier updates and compile reads. */
|
|
137
|
+
export type ColumnState<TValue> = {
|
|
138
|
+
readonly baseType: string;
|
|
139
|
+
readonly dims: number;
|
|
140
|
+
readonly nullable: boolean;
|
|
141
|
+
readonly hasDefault: boolean;
|
|
142
|
+
readonly defaultSql: string | undefined;
|
|
143
|
+
readonly defaultValue: unknown;
|
|
144
|
+
readonly identity: {
|
|
145
|
+
readonly always: boolean;
|
|
146
|
+
} | undefined;
|
|
147
|
+
readonly generated: {
|
|
148
|
+
readonly stored: boolean;
|
|
149
|
+
readonly expression: string;
|
|
150
|
+
} | undefined;
|
|
151
|
+
readonly unique: {
|
|
152
|
+
readonly reason: string | undefined;
|
|
153
|
+
readonly global: boolean | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
readonly picklist: {
|
|
156
|
+
readonly values: readonly string[];
|
|
157
|
+
readonly check: boolean;
|
|
158
|
+
} | undefined;
|
|
159
|
+
readonly guarded: boolean;
|
|
160
|
+
readonly hidden: boolean;
|
|
161
|
+
readonly omitWrite: boolean;
|
|
162
|
+
readonly renamedFrom: string | undefined;
|
|
163
|
+
readonly sqlName: string | undefined;
|
|
164
|
+
readonly comment: string | undefined;
|
|
165
|
+
readonly extension: string | undefined;
|
|
166
|
+
readonly typeDependency: string | undefined;
|
|
167
|
+
/** Ordered enum labels. Absent on every column that is not an enum. */
|
|
168
|
+
readonly enumLabels: readonly string[] | undefined;
|
|
169
|
+
readonly domain: {
|
|
170
|
+
readonly base: string;
|
|
171
|
+
readonly check: string;
|
|
172
|
+
} | undefined;
|
|
173
|
+
readonly primaryKey: boolean;
|
|
174
|
+
readonly typeLabel: string | undefined;
|
|
175
|
+
readonly references: ReferenceModifier | undefined;
|
|
176
|
+
readonly validate: ValidateModifier | undefined;
|
|
177
|
+
readonly sqlForm: SqlForm;
|
|
178
|
+
readonly encode: (value: TValue) => string;
|
|
179
|
+
readonly decode: (wire: string) => TValue;
|
|
180
|
+
readonly elementEncode: (value: unknown) => string;
|
|
181
|
+
readonly elementDecode: (wire: string) => unknown;
|
|
182
|
+
};
|
|
183
|
+
/** Fields a scalar builder sets. Flags are passed beside the codec. */
|
|
184
|
+
export type OpenColumn<TValue> = {
|
|
185
|
+
readonly baseType: string;
|
|
186
|
+
readonly nullable: boolean;
|
|
187
|
+
readonly hasDefault: boolean;
|
|
188
|
+
readonly generated: boolean;
|
|
189
|
+
readonly guarded: boolean;
|
|
190
|
+
readonly hidden: boolean;
|
|
191
|
+
readonly omitWrite: boolean;
|
|
192
|
+
readonly encode: (value: TValue) => string;
|
|
193
|
+
readonly decode: (wire: string) => TValue;
|
|
194
|
+
readonly sqlForm: SqlForm;
|
|
195
|
+
readonly defaultSql?: string;
|
|
196
|
+
readonly identity?: {
|
|
197
|
+
readonly always: boolean;
|
|
198
|
+
};
|
|
199
|
+
readonly extension?: string;
|
|
200
|
+
readonly typeDependency?: string;
|
|
201
|
+
readonly enumLabels?: readonly string[];
|
|
202
|
+
readonly domain?: {
|
|
203
|
+
readonly base: string;
|
|
204
|
+
readonly check: string;
|
|
205
|
+
};
|
|
206
|
+
readonly primaryKey?: boolean;
|
|
207
|
+
readonly typeLabel?: string;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Chainable column definition.
|
|
211
|
+
*
|
|
212
|
+
* Call {@link ColumnBuilder.encode} and {@link ColumnBuilder.decode} for the
|
|
213
|
+
* codec. Catalog compilation lives in `compileColumn` so a caller that only
|
|
214
|
+
* encodes does not load it.
|
|
215
|
+
*
|
|
216
|
+
* @typeParam TValue - TypeScript value
|
|
217
|
+
* @typeParam TFlags - Nullability, defaults, generation, and exposure
|
|
218
|
+
*/
|
|
219
|
+
export declare class ColumnBuilder<TValue, TFlags extends ColumnFlags> {
|
|
220
|
+
/** Phantom value, so the class carries `TValue`. */
|
|
221
|
+
readonly "~value": TValue;
|
|
222
|
+
/** Phantom flags. */
|
|
223
|
+
readonly "~flags": TFlags;
|
|
224
|
+
/** Definition. Modifiers replace the builder instead of mutating it. */
|
|
225
|
+
readonly state: ColumnState<TValue>;
|
|
226
|
+
/**
|
|
227
|
+
* @param state - Definition
|
|
228
|
+
*/
|
|
229
|
+
constructor(state: ColumnState<TValue>);
|
|
230
|
+
/**
|
|
231
|
+
* Encodes a value to the text the catalog and the driver store.
|
|
232
|
+
*
|
|
233
|
+
* @param value - Application value
|
|
234
|
+
* @returns Wire text
|
|
235
|
+
*/
|
|
236
|
+
encode(value: TValue): string;
|
|
237
|
+
/**
|
|
238
|
+
* Decodes wire text to the application value.
|
|
239
|
+
*
|
|
240
|
+
* @param wire - Text from {@link encode}
|
|
241
|
+
* @returns Application value
|
|
242
|
+
*/
|
|
243
|
+
decode(wire: string): TValue;
|
|
244
|
+
/**
|
|
245
|
+
* Allows SQL NULL.
|
|
246
|
+
*
|
|
247
|
+
* @returns The same column, nullable
|
|
248
|
+
*/
|
|
249
|
+
nullable(): ColumnBuilder<TValue, FlagTrue<TFlags, "nullable">>;
|
|
250
|
+
/**
|
|
251
|
+
* Stores a JavaScript default. The catalog receives its SQL spelling.
|
|
252
|
+
*
|
|
253
|
+
* @param value - Default value
|
|
254
|
+
* @returns The same column, with a default
|
|
255
|
+
*/
|
|
256
|
+
default(value: TFlags["nullable"] extends true ? TValue | null : TValue): ColumnBuilder<TValue, FlagTrue<TFlags, "hasDefault">>;
|
|
257
|
+
/**
|
|
258
|
+
* Stores a SQL default expression as written.
|
|
259
|
+
*
|
|
260
|
+
* @param expression - SQL expression
|
|
261
|
+
* @returns The same column, with a default
|
|
262
|
+
*/
|
|
263
|
+
defaultSql(expression: string): ColumnBuilder<TValue, FlagTrue<TFlags, "hasDefault">>;
|
|
264
|
+
/**
|
|
265
|
+
* Records a unique constraint. Tenancy later reads `global`.
|
|
266
|
+
*
|
|
267
|
+
* @param options - Exemption reason, and whether the unique ignores the tenant key
|
|
268
|
+
* @returns The same column
|
|
269
|
+
*/
|
|
270
|
+
unique(options?: {
|
|
271
|
+
readonly reason?: string;
|
|
272
|
+
readonly global?: boolean;
|
|
273
|
+
}): ColumnBuilder<TValue, TFlags>;
|
|
274
|
+
/**
|
|
275
|
+
* Narrows a string column to a literal union.
|
|
276
|
+
*
|
|
277
|
+
* `{ check: false }` keeps the list in the type and skips the catalog CHECK.
|
|
278
|
+
* An empty list or a repeated value is OKM1060.
|
|
279
|
+
*
|
|
280
|
+
* @param values - Allowed literals, in stored order
|
|
281
|
+
* @param options - Whether the catalog gets a CHECK
|
|
282
|
+
* @returns The column typed as that union
|
|
283
|
+
*/
|
|
284
|
+
picklist<const TValues extends readonly (TValue & string)[]>(values: TValues, options?: {
|
|
285
|
+
readonly check?: boolean;
|
|
286
|
+
}): ColumnBuilder<TValues[number], TFlags>;
|
|
287
|
+
/**
|
|
288
|
+
* Stores a generated expression. Insert and update omit the column.
|
|
289
|
+
*
|
|
290
|
+
* @param expression - SQL expression
|
|
291
|
+
* @param options - `stored` defaults to true
|
|
292
|
+
* @returns The same column, generated
|
|
293
|
+
*/
|
|
294
|
+
generated(expression: string, options?: {
|
|
295
|
+
readonly stored?: boolean;
|
|
296
|
+
}): ColumnBuilder<TValue, WithGenerated<TFlags>>;
|
|
297
|
+
/**
|
|
298
|
+
* Omits the column from insert and update input.
|
|
299
|
+
*
|
|
300
|
+
* @returns The same column, guarded
|
|
301
|
+
*/
|
|
302
|
+
guarded(): ColumnBuilder<TValue, FlagTrue<TFlags, "guarded">>;
|
|
303
|
+
/**
|
|
304
|
+
* Excludes the column from the default row.
|
|
305
|
+
*
|
|
306
|
+
* @returns The same column, hidden
|
|
307
|
+
*/
|
|
308
|
+
hidden(): ColumnBuilder<TValue, FlagTrue<TFlags, "hidden">>;
|
|
309
|
+
/**
|
|
310
|
+
* Points this column at another table.
|
|
311
|
+
*
|
|
312
|
+
* `schema()` checks that the table exists (OKM1020). The argument stays a
|
|
313
|
+
* string so the column type does not cycle through `Register`.
|
|
314
|
+
*
|
|
315
|
+
* @param table - Target table name
|
|
316
|
+
* @param options - Referential actions and target columns
|
|
317
|
+
* @returns The same column, with the reference stored
|
|
318
|
+
*/
|
|
319
|
+
references(table: string, options?: ReferenceOptions): ColumnBuilder<TValue, TFlags>;
|
|
320
|
+
/**
|
|
321
|
+
* Records the previous SQL name. Migrations read it later.
|
|
322
|
+
*
|
|
323
|
+
* @param name - Previous column name
|
|
324
|
+
* @returns The same column
|
|
325
|
+
*/
|
|
326
|
+
renamedFrom(name: string): ColumnBuilder<TValue, TFlags>;
|
|
327
|
+
/**
|
|
328
|
+
* Sets the catalog column name when it differs from the field name.
|
|
329
|
+
*
|
|
330
|
+
* @param name - SQL identifier
|
|
331
|
+
* @returns The same column
|
|
332
|
+
*/
|
|
333
|
+
sqlName(name: string): ColumnBuilder<TValue, TFlags>;
|
|
334
|
+
/**
|
|
335
|
+
* Stores a comment. The catalog column object has no comment field yet,
|
|
336
|
+
* so compile returns it beside the column.
|
|
337
|
+
*
|
|
338
|
+
* @param text - Comment text
|
|
339
|
+
* @returns The same column
|
|
340
|
+
*/
|
|
341
|
+
comment(text: string): ColumnBuilder<TValue, TFlags>;
|
|
342
|
+
/**
|
|
343
|
+
* Wraps the value in an array. `dims` defaults to one more rank, starting at 1.
|
|
344
|
+
*
|
|
345
|
+
* @param options - Explicit rank from 1 to 6
|
|
346
|
+
* @returns An array column
|
|
347
|
+
*/
|
|
348
|
+
array<const D extends number = 1>(options?: {
|
|
349
|
+
readonly dims?: D;
|
|
350
|
+
}): ColumnBuilder<ArrayOf<TValue, D>, TFlags>;
|
|
351
|
+
}
|
|
352
|
+
/** Codec and SQL type, without the flag booleans {@link required} fills in. */
|
|
353
|
+
export type RequiredBody<TValue> = Omit<OpenColumn<TValue>, "nullable" | "hasDefault" | "generated" | "guarded" | "hidden" | "omitWrite">;
|
|
354
|
+
/**
|
|
355
|
+
* Starts a required scalar column.
|
|
356
|
+
*
|
|
357
|
+
* @typeParam TValue - TypeScript value
|
|
358
|
+
* @param body - Type and codec
|
|
359
|
+
* @returns A builder with {@link PlainFlags}
|
|
360
|
+
*/
|
|
361
|
+
export declare function required<TValue>(body: RequiredBody<TValue>): ColumnBuilder<TValue, PlainFlags>;
|
|
362
|
+
/**
|
|
363
|
+
* Starts a scalar column.
|
|
364
|
+
*
|
|
365
|
+
* @typeParam TValue - TypeScript value
|
|
366
|
+
* @typeParam TFlags - Flags the caller names
|
|
367
|
+
* @param input - Type, codec, and flags
|
|
368
|
+
* @returns A builder
|
|
369
|
+
*/
|
|
370
|
+
export declare function openColumn<TValue, TFlags extends ColumnFlags>(input: OpenColumn<TValue>): ColumnBuilder<TValue, TFlags>;
|
|
371
|
+
/**
|
|
372
|
+
* SQL type name, with `[]` repeated for each array rank.
|
|
373
|
+
*
|
|
374
|
+
* @param baseType - Scalar SQL type
|
|
375
|
+
* @param dims - Array rank, 0 for a scalar
|
|
376
|
+
* @returns Catalog `dataType`
|
|
377
|
+
*/
|
|
378
|
+
export declare function formatType(baseType: string, dims: number): string;
|
|
379
|
+
/**
|
|
380
|
+
* SQL spelling of a default value.
|
|
381
|
+
*
|
|
382
|
+
* @param state - Column definition
|
|
383
|
+
* @param value - Application value
|
|
384
|
+
* @returns A default expression
|
|
385
|
+
*/
|
|
386
|
+
export declare function sqlOf<TValue>(state: ColumnState<TValue>, value: TValue): string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compiles one column builder into catalog objects.
|
|
3
|
+
*
|
|
4
|
+
* The column factory lives here, not on the builder, so encoding a value
|
|
5
|
+
* does not load constraint naming.
|
|
6
|
+
*/
|
|
7
|
+
import type { ColumnObject, ConstraintObject, ObjectIdentity, ObjectRef, Owner, Provenance } from "../../contracts/catalog/types.js";
|
|
8
|
+
/** Column fields {@link compileColumn} reads. Builders satisfy this structurally. */
|
|
9
|
+
export type CompilableColumn = {
|
|
10
|
+
readonly state: {
|
|
11
|
+
readonly baseType: string;
|
|
12
|
+
readonly dims: number;
|
|
13
|
+
readonly nullable: boolean;
|
|
14
|
+
readonly defaultSql: string | undefined;
|
|
15
|
+
readonly identity: {
|
|
16
|
+
readonly always: boolean;
|
|
17
|
+
} | undefined;
|
|
18
|
+
readonly generated: {
|
|
19
|
+
readonly stored: boolean;
|
|
20
|
+
readonly expression: string;
|
|
21
|
+
} | undefined;
|
|
22
|
+
readonly unique: {
|
|
23
|
+
readonly reason: string | undefined;
|
|
24
|
+
readonly global: boolean | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly picklist: {
|
|
27
|
+
readonly values: readonly string[];
|
|
28
|
+
readonly check: boolean;
|
|
29
|
+
} | undefined;
|
|
30
|
+
readonly guarded: boolean;
|
|
31
|
+
readonly hidden: boolean;
|
|
32
|
+
readonly renamedFrom: string | undefined;
|
|
33
|
+
readonly sqlName: string | undefined;
|
|
34
|
+
readonly comment: string | undefined;
|
|
35
|
+
readonly extension: string | undefined;
|
|
36
|
+
readonly typeDependency: string | undefined;
|
|
37
|
+
readonly enumLabels: readonly string[] | undefined;
|
|
38
|
+
readonly domain: {
|
|
39
|
+
readonly base: string;
|
|
40
|
+
readonly check: string;
|
|
41
|
+
} | undefined;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** Where the column is compiled. */
|
|
45
|
+
export type CompileColumnInput = {
|
|
46
|
+
readonly parent: ObjectRef;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly provenance: Provenance;
|
|
49
|
+
readonly owner?: Owner;
|
|
50
|
+
readonly dependencies?: readonly ObjectIdentity[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Catalog column plus the constraints and notes the column object cannot store.
|
|
54
|
+
*/
|
|
55
|
+
export type CompiledColumn = {
|
|
56
|
+
readonly column: ColumnObject;
|
|
57
|
+
readonly check?: ConstraintObject;
|
|
58
|
+
readonly unique?: ConstraintObject;
|
|
59
|
+
readonly guarded: boolean;
|
|
60
|
+
readonly hidden: boolean;
|
|
61
|
+
readonly renamedFrom?: string;
|
|
62
|
+
readonly comment?: string;
|
|
63
|
+
readonly uniqueReason?: string;
|
|
64
|
+
readonly uniqueGlobal?: boolean;
|
|
65
|
+
readonly domain?: {
|
|
66
|
+
readonly base: string;
|
|
67
|
+
readonly check: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Compiles a column into the catalog column definition.
|
|
72
|
+
*
|
|
73
|
+
* `citext` and `ltree` record an extension dependency. Enums and domains
|
|
74
|
+
* record a type dependency. A picklist with `check` adds a CHECK constraint.
|
|
75
|
+
* `.unique()` adds a unique constraint.
|
|
76
|
+
*
|
|
77
|
+
* @param builder - Column definition
|
|
78
|
+
* @param input - Parent table, field name, and provenance
|
|
79
|
+
* @returns The column and any constraints
|
|
80
|
+
*/
|
|
81
|
+
export declare function compileColumn(builder: CompilableColumn, input: CompileColumnInput): CompiledColumn;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A column whose SQL type and codec are supplied by the caller.
|
|
3
|
+
*
|
|
4
|
+
* The spec writes `tsType` in the options object. The type parameter is that
|
|
5
|
+
* type; a runtime `tsType` field cannot carry it.
|
|
6
|
+
*/
|
|
7
|
+
import { type ColumnBuilder, type PlainFlags, type SqlForm } from "./column.js";
|
|
8
|
+
/**
|
|
9
|
+
* Custom column.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam TValue - TypeScript value
|
|
12
|
+
* @param spec - SQL type, codec, and optional extension
|
|
13
|
+
* @returns A column using that codec
|
|
14
|
+
*/
|
|
15
|
+
export declare function custom<TValue>(spec: {
|
|
16
|
+
readonly sqlType: string;
|
|
17
|
+
readonly encode: (value: TValue) => string;
|
|
18
|
+
readonly decode: (wire: string) => TValue;
|
|
19
|
+
readonly extension?: string;
|
|
20
|
+
readonly sqlForm?: SqlForm;
|
|
21
|
+
}): ColumnBuilder<TValue, PlainFlags>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres DDL for a catalog.
|
|
3
|
+
*
|
|
4
|
+
* Planning and scratch comparison both render through here, so a statement
|
|
5
|
+
* has one spelling.
|
|
6
|
+
*/
|
|
7
|
+
import type { Catalog, CatalogObject, ColumnObject, SequenceObject, TableObject } from "../../contracts/catalog/types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Quotes one identifier.
|
|
10
|
+
*
|
|
11
|
+
* @param name - Identifier already checked by the catalog
|
|
12
|
+
* @returns A double-quoted identifier
|
|
13
|
+
*/
|
|
14
|
+
export declare function quoteIdent(name: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Renders a catalog as create statements in dependency order.
|
|
17
|
+
*
|
|
18
|
+
* Columns and primary keys are folded into `CREATE TABLE`. An identity
|
|
19
|
+
* sequence is created by the column, not as its own statement.
|
|
20
|
+
*
|
|
21
|
+
* @param source - Catalog to apply
|
|
22
|
+
* @param schema - Concrete schema name
|
|
23
|
+
* @returns SQL statements
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderCatalog(source: Catalog, schema: string): readonly string[];
|
|
26
|
+
/**
|
|
27
|
+
* SQL that drops one object.
|
|
28
|
+
*
|
|
29
|
+
* A column or constraint drop is an `ALTER TABLE`. Dropping a table does not
|
|
30
|
+
* use `CASCADE`.
|
|
31
|
+
*
|
|
32
|
+
* @param object - Object to drop
|
|
33
|
+
* @param schema - Concrete schema name
|
|
34
|
+
* @returns The statement, or `undefined` when the object is not dropped alone
|
|
35
|
+
*/
|
|
36
|
+
export declare function dropObjectSql(object: CatalogObject, schema: string): string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* SQL that creates one object that is not folded into a new table.
|
|
39
|
+
*
|
|
40
|
+
* @param object - Object to create
|
|
41
|
+
* @param schema - Concrete schema name
|
|
42
|
+
* @returns The statement
|
|
43
|
+
*/
|
|
44
|
+
export declare function createObjectSql(object: CatalogObject, schema: string): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* In-place column changes: type, nullability, and default.
|
|
47
|
+
*
|
|
48
|
+
* @param before - Column already applied
|
|
49
|
+
* @param after - Column the plan must reach
|
|
50
|
+
* @param schema - Concrete schema name
|
|
51
|
+
* @returns Statements, empty when the definitions match
|
|
52
|
+
*/
|
|
53
|
+
export declare function alterColumnSql(before: ColumnObject, after: ColumnObject, schema: string): readonly string[];
|
|
54
|
+
/**
|
|
55
|
+
* Reports whether a sequence is the one an identity column creates.
|
|
56
|
+
*
|
|
57
|
+
* @param sequence - Sequence object
|
|
58
|
+
* @param source - Catalog that may own it
|
|
59
|
+
* @returns `true` when a column depends on the sequence and declares identity
|
|
60
|
+
*/
|
|
61
|
+
export declare function identitySequence(sequence: SequenceObject, source: Catalog): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* `CREATE TABLE` for one table, including its columns and primary key.
|
|
64
|
+
*
|
|
65
|
+
* @param tableObject - Table to create
|
|
66
|
+
* @param source - Catalog that holds the columns
|
|
67
|
+
* @param schema - Concrete schema name
|
|
68
|
+
* @returns The statement
|
|
69
|
+
*/
|
|
70
|
+
export declare function createTableSql(tableObject: TableObject, source: Catalog, schema: string): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* numeric, real, and double precision.
|
|
3
|
+
*/
|
|
4
|
+
import { type ColumnBuilder, type PlainFlags } from "./column.js";
|
|
5
|
+
/** How a numeric value is represented in TypeScript. */
|
|
6
|
+
export type NumericAs = "string" | "number";
|
|
7
|
+
/** TypeScript value for a numeric codec mode. */
|
|
8
|
+
export type NumericValue<TAs extends NumericAs> = TAs extends "number" ? number : string;
|
|
9
|
+
/**
|
|
10
|
+
* Exact numeric. The default codec is a decimal string.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam TAs - `string` or `number`
|
|
13
|
+
* @param precision - Total digits, with `scale`
|
|
14
|
+
* @param scale - Digits after the decimal point
|
|
15
|
+
* @param options - Codec selection
|
|
16
|
+
* @returns A numeric column
|
|
17
|
+
*/
|
|
18
|
+
export declare function numeric<const TAs extends NumericAs = "string">(precision?: number, scale?: number, options?: {
|
|
19
|
+
readonly as?: TAs;
|
|
20
|
+
}): ColumnBuilder<NumericValue<TAs>, PlainFlags>;
|
|
21
|
+
/**
|
|
22
|
+
* Single-precision float.
|
|
23
|
+
*
|
|
24
|
+
* @returns A real column
|
|
25
|
+
*/
|
|
26
|
+
export declare function real(): ColumnBuilder<number, PlainFlags>;
|
|
27
|
+
/**
|
|
28
|
+
* Double-precision float.
|
|
29
|
+
*
|
|
30
|
+
* @returns A double precision column
|
|
31
|
+
*/
|
|
32
|
+
export declare function double(): ColumnBuilder<number, PlainFlags>;
|
|
33
|
+
/**
|
|
34
|
+
* Encodes a canonical numeric literal.
|
|
35
|
+
*
|
|
36
|
+
* @param value - Decimal text
|
|
37
|
+
* @returns The same spelling when it is a numeric literal
|
|
38
|
+
*/
|
|
39
|
+
export declare function encodeNumericString(value: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Decodes a numeric literal to the same string.
|
|
42
|
+
*
|
|
43
|
+
* @param wire - Decimal text
|
|
44
|
+
* @returns The same spelling
|
|
45
|
+
*/
|
|
46
|
+
export declare function decodeNumericString(wire: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Encodes a finite number as a numeric literal.
|
|
49
|
+
*
|
|
50
|
+
* @param value - Finite number
|
|
51
|
+
* @returns Decimal text
|
|
52
|
+
*/
|
|
53
|
+
export declare function encodeNumericNumber(value: number): string;
|
|
54
|
+
/**
|
|
55
|
+
* Decodes a numeric literal to a number.
|
|
56
|
+
*
|
|
57
|
+
* Precision past a JavaScript number is lost. The string codec is the default.
|
|
58
|
+
*
|
|
59
|
+
* @param wire - Decimal text
|
|
60
|
+
* @returns A number
|
|
61
|
+
*/
|
|
62
|
+
export declare function decodeNumericNumber(wire: string): number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renames read off a built schema.
|
|
3
|
+
*
|
|
4
|
+
* Enum labels are a catalog type, not a side file. `renamedFrom` stays on the
|
|
5
|
+
* schema because a rename is an author declaration, not a stored object.
|
|
6
|
+
*/
|
|
7
|
+
import type { AnyTable } from "./table.js";
|
|
8
|
+
/** A rename the author declared on a table or a column. */
|
|
9
|
+
export type DeclaredRename = {
|
|
10
|
+
readonly kind: "table";
|
|
11
|
+
readonly from: string;
|
|
12
|
+
readonly to: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "column";
|
|
15
|
+
readonly table: string;
|
|
16
|
+
readonly from: string;
|
|
17
|
+
readonly to: string;
|
|
18
|
+
};
|
|
19
|
+
/** Renames collected from one schema. */
|
|
20
|
+
export type SchemaDeclarations = {
|
|
21
|
+
readonly renames: readonly DeclaredRename[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Reads declared renames.
|
|
25
|
+
*
|
|
26
|
+
* SQL names follow `sqlName`, then snake_case when the schema asked for it.
|
|
27
|
+
*
|
|
28
|
+
* @param source - Built schema
|
|
29
|
+
* @returns Rename declarations, in table order
|
|
30
|
+
*/
|
|
31
|
+
export declare function schemaDeclarations(source: {
|
|
32
|
+
readonly tables: readonly AnyTable[];
|
|
33
|
+
readonly casing: "snake" | undefined;
|
|
34
|
+
}): SchemaDeclarations;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes `.okm/types.d.ts` text from a schema.
|
|
3
|
+
*
|
|
4
|
+
* The CLI that writes the file arrives later. This function is the text.
|
|
5
|
+
* Field shapes match the inferred `~row`, `~insert`, and `~update` types.
|
|
6
|
+
*/
|
|
7
|
+
import { type BuiltSchema } from "./schema.js";
|
|
8
|
+
import { type AnyTable } from "./table.js";
|
|
9
|
+
/**
|
|
10
|
+
* Emits row, insert, and update interfaces for every table.
|
|
11
|
+
*
|
|
12
|
+
* Names come from the table name: `tasks` becomes `Tasks`, `TasksInsert`,
|
|
13
|
+
* and `TasksUpdate`.
|
|
14
|
+
*
|
|
15
|
+
* @param source - Schema from {@link schema}
|
|
16
|
+
* @returns Declaration text
|
|
17
|
+
*/
|
|
18
|
+
export declare function emitRowTypes(source: BuiltSchema<readonly AnyTable[]>): string;
|