@prisma-next/contract-authoring 0.3.0-dev.4 → 0.3.0-dev.41

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,295 @@
1
+ import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
2
+ import { ifDefined } from '@prisma-next/utils/defined';
3
+ import type {
4
+ ColumnBuilderState,
5
+ ColumnTypeDescriptor,
6
+ ForeignKeyDef,
7
+ IndexDef,
8
+ TableBuilderState,
9
+ UniqueConstraintDef,
10
+ } from './builder-state';
11
+
12
+ /**
13
+ * Column options for nullable columns.
14
+ */
15
+ interface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
16
+ type: Descriptor;
17
+ nullable: true;
18
+ typeParams?: Record<string, unknown>;
19
+ default?: ColumnDefault;
20
+ }
21
+
22
+ /**
23
+ * Column options for non-nullable columns.
24
+ * Non-nullable columns can optionally have a default value.
25
+ */
26
+ interface NonNullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
27
+ type: Descriptor;
28
+ nullable?: false;
29
+ typeParams?: Record<string, unknown>;
30
+ default?: ColumnDefault;
31
+ }
32
+
33
+ type GeneratedColumnOptions<Descriptor extends ColumnTypeDescriptor> = Omit<
34
+ NonNullableColumnOptions<Descriptor>,
35
+ 'default' | 'nullable'
36
+ > & {
37
+ /**
38
+ * Generated columns are always non-nullable and use mutation-time defaults
39
+ * that the runtime injects when the column is omitted from insert input.
40
+ */
41
+ nullable?: false;
42
+ generated: ExecutionMutationDefaultValue;
43
+ };
44
+
45
+ /** Column options for any column nullability. */
46
+ type ColumnOptions<Descriptor extends ColumnTypeDescriptor> =
47
+ | NullableColumnOptions<Descriptor>
48
+ | NonNullableColumnOptions<Descriptor>;
49
+
50
+ type NullableFromOptions<TOptions> = TOptions extends { nullable: true } ? true : false;
51
+
52
+ interface TableBuilderInternalState<
53
+ Name extends string,
54
+ Columns extends Record<string, ColumnBuilderState<string, boolean, string>>,
55
+ PrimaryKey extends readonly string[] | undefined,
56
+ > {
57
+ readonly name: Name;
58
+ readonly columns: Columns;
59
+ readonly primaryKey: PrimaryKey;
60
+ readonly primaryKeyName: string | undefined;
61
+ readonly uniques: readonly UniqueConstraintDef[];
62
+ readonly indexes: readonly IndexDef[];
63
+ readonly foreignKeys: readonly ForeignKeyDef[];
64
+ }
65
+
66
+ /**
67
+ * Creates a new table builder with the given name.
68
+ * This is the preferred way to create a TableBuilder - it ensures
69
+ * type parameters are inferred correctly without unsafe casts.
70
+ */
71
+ export function createTable<Name extends string>(name: Name): TableBuilder<Name> {
72
+ return new TableBuilder(name, {}, undefined, undefined, [], [], []);
73
+ }
74
+
75
+ /**
76
+ * Builder for defining table structure with type-safe chaining.
77
+ * Use `createTable(name)` to create instances.
78
+ */
79
+ export class TableBuilder<
80
+ Name extends string,
81
+ Columns extends Record<string, ColumnBuilderState<string, boolean, string>> = Record<
82
+ never,
83
+ ColumnBuilderState<string, boolean, string>
84
+ >,
85
+ PrimaryKey extends readonly string[] | undefined = undefined,
86
+ > {
87
+ private readonly _state: TableBuilderInternalState<Name, Columns, PrimaryKey>;
88
+
89
+ /** @internal Use createTable() instead */
90
+ constructor(
91
+ name: Name,
92
+ columns: Columns,
93
+ primaryKey: PrimaryKey,
94
+ primaryKeyName: string | undefined,
95
+ uniques: readonly UniqueConstraintDef[],
96
+ indexes: readonly IndexDef[],
97
+ foreignKeys: readonly ForeignKeyDef[],
98
+ ) {
99
+ this._state = {
100
+ name,
101
+ columns,
102
+ primaryKey,
103
+ primaryKeyName,
104
+ uniques,
105
+ indexes,
106
+ foreignKeys,
107
+ };
108
+ }
109
+
110
+ private get _name(): Name {
111
+ return this._state.name;
112
+ }
113
+
114
+ private get _columns(): Columns {
115
+ return this._state.columns;
116
+ }
117
+
118
+ private get _primaryKey(): PrimaryKey {
119
+ return this._state.primaryKey;
120
+ }
121
+
122
+ /** Add a nullable column to the table. */
123
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
124
+ name: ColName,
125
+ options: NullableColumnOptions<Descriptor>,
126
+ ): TableBuilder<
127
+ Name,
128
+ Columns & Record<ColName, ColumnBuilderState<ColName, true, Descriptor['codecId']>>,
129
+ PrimaryKey
130
+ >;
131
+
132
+ /**
133
+ * Add a non-nullable column to the table.
134
+ * Non-nullable columns can optionally have a default value.
135
+ */
136
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
137
+ name: ColName,
138
+ options: NonNullableColumnOptions<Descriptor>,
139
+ ): TableBuilder<
140
+ Name,
141
+ Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,
142
+ PrimaryKey
143
+ >;
144
+
145
+ /**
146
+ * Implementation of the column method.
147
+ */
148
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
149
+ name: ColName,
150
+ options: ColumnOptions<Descriptor>,
151
+ ): TableBuilder<
152
+ Name,
153
+ Columns & Record<ColName, ColumnBuilderState<ColName, boolean, Descriptor['codecId']>>,
154
+ PrimaryKey
155
+ > {
156
+ return this.columnInternal(name, options);
157
+ }
158
+
159
+ generated<ColName extends string, Descriptor extends ColumnTypeDescriptor>(
160
+ name: ColName,
161
+ options: GeneratedColumnOptions<Descriptor>,
162
+ ): TableBuilder<
163
+ Name,
164
+ Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,
165
+ PrimaryKey
166
+ > {
167
+ const { generated, ...columnOptions } = options;
168
+ return this.columnInternal(name, columnOptions, generated);
169
+ }
170
+
171
+ private columnInternal<
172
+ ColName extends string,
173
+ Descriptor extends ColumnTypeDescriptor,
174
+ Options extends ColumnOptions<Descriptor>,
175
+ >(
176
+ name: ColName,
177
+ options: Options,
178
+ executionDefault?: ExecutionMutationDefaultValue,
179
+ ): TableBuilder<
180
+ Name,
181
+ Columns &
182
+ Record<
183
+ ColName,
184
+ ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>
185
+ >,
186
+ PrimaryKey
187
+ > {
188
+ const nullable = options.nullable ?? false;
189
+ const { codecId, nativeType, typeParams: descriptorTypeParams, typeRef } = options.type;
190
+ const typeParams = options.typeParams ?? descriptorTypeParams;
191
+
192
+ const columnState = {
193
+ name,
194
+ nullable,
195
+ type: codecId,
196
+ nativeType,
197
+ ...ifDefined('typeParams', typeParams),
198
+ ...ifDefined('typeRef', typeRef),
199
+ ...ifDefined('default', 'default' in options ? options.default : undefined),
200
+ ...ifDefined('executionDefault', executionDefault),
201
+ } as ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>;
202
+ const newColumns = { ...this._columns, [name]: columnState } as Columns &
203
+ Record<
204
+ ColName,
205
+ ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>
206
+ >;
207
+ return new TableBuilder(
208
+ this._state.name,
209
+ newColumns,
210
+ this._state.primaryKey,
211
+ this._state.primaryKeyName,
212
+ this._state.uniques,
213
+ this._state.indexes,
214
+ this._state.foreignKeys,
215
+ );
216
+ }
217
+
218
+ primaryKey<PK extends readonly string[]>(
219
+ columns: PK,
220
+ name?: string,
221
+ ): TableBuilder<Name, Columns, PK> {
222
+ return new TableBuilder(
223
+ this._state.name,
224
+ this._state.columns,
225
+ columns,
226
+ name,
227
+ this._state.uniques,
228
+ this._state.indexes,
229
+ this._state.foreignKeys,
230
+ );
231
+ }
232
+
233
+ unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {
234
+ const constraint: UniqueConstraintDef = name ? { columns, name } : { columns };
235
+ return new TableBuilder(
236
+ this._state.name,
237
+ this._state.columns,
238
+ this._state.primaryKey,
239
+ this._state.primaryKeyName,
240
+ [...this._state.uniques, constraint],
241
+ this._state.indexes,
242
+ this._state.foreignKeys,
243
+ );
244
+ }
245
+
246
+ index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {
247
+ const indexDef: IndexDef = name ? { columns, name } : { columns };
248
+ return new TableBuilder(
249
+ this._state.name,
250
+ this._state.columns,
251
+ this._state.primaryKey,
252
+ this._state.primaryKeyName,
253
+ this._state.uniques,
254
+ [...this._state.indexes, indexDef],
255
+ this._state.foreignKeys,
256
+ );
257
+ }
258
+
259
+ foreignKey(
260
+ columns: readonly string[],
261
+ references: { table: string; columns: readonly string[] },
262
+ opts?: { name?: string; constraint?: boolean; index?: boolean },
263
+ ): TableBuilder<Name, Columns, PrimaryKey> {
264
+ const fkDef: ForeignKeyDef = {
265
+ columns,
266
+ references,
267
+ ...(opts?.name !== undefined && { name: opts.name }),
268
+ ...(opts?.constraint !== undefined && { constraint: opts.constraint }),
269
+ ...(opts?.index !== undefined && { index: opts.index }),
270
+ };
271
+ return new TableBuilder(
272
+ this._state.name,
273
+ this._state.columns,
274
+ this._state.primaryKey,
275
+ this._state.primaryKeyName,
276
+ this._state.uniques,
277
+ this._state.indexes,
278
+ [...this._state.foreignKeys, fkDef],
279
+ );
280
+ }
281
+
282
+ build(): TableBuilderState<Name, Columns, PrimaryKey> {
283
+ return {
284
+ name: this._name,
285
+ columns: this._columns,
286
+ ...(this._primaryKey !== undefined ? { primaryKey: this._primaryKey } : {}),
287
+ ...(this._state.primaryKeyName !== undefined
288
+ ? { primaryKeyName: this._state.primaryKeyName }
289
+ : {}),
290
+ uniques: this._state.uniques,
291
+ indexes: this._state.indexes,
292
+ foreignKeys: this._state.foreignKeys,
293
+ } as TableBuilderState<Name, Columns, PrimaryKey>;
294
+ }
295
+ }
package/src/types.ts ADDED
@@ -0,0 +1,133 @@
1
+ import type { ColumnDefault } from '@prisma-next/contract/types';
2
+ import type {
3
+ ColumnBuilderState,
4
+ ModelBuilderState,
5
+ RelationDefinition,
6
+ TableBuilderState,
7
+ } from './builder-state';
8
+
9
+ export type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
10
+ readonly nativeType: string;
11
+ readonly codecId: Type;
12
+ readonly nullable: Nullable;
13
+ readonly typeParams?: Record<string, unknown>;
14
+ readonly typeRef?: string;
15
+ readonly default?: ColumnDefault;
16
+ };
17
+
18
+ export type ExtractColumns<
19
+ T extends TableBuilderState<
20
+ string,
21
+ Record<string, ColumnBuilderState<string, boolean, string>>,
22
+ readonly string[] | undefined
23
+ >,
24
+ > = T extends TableBuilderState<string, infer C, readonly string[] | undefined> ? C : never;
25
+
26
+ export type ExtractPrimaryKey<
27
+ T extends TableBuilderState<
28
+ string,
29
+ Record<string, ColumnBuilderState<string, boolean, string>>,
30
+ readonly string[] | undefined
31
+ >,
32
+ > =
33
+ T extends TableBuilderState<
34
+ string,
35
+ Record<string, ColumnBuilderState<string, boolean, string>>,
36
+ infer PK
37
+ >
38
+ ? PK
39
+ : never;
40
+
41
+ export type BuildStorage<
42
+ Tables extends Record<
43
+ string,
44
+ TableBuilderState<
45
+ string,
46
+ Record<string, ColumnBuilderState<string, boolean, string>>,
47
+ readonly string[] | undefined
48
+ >
49
+ >,
50
+ > = {
51
+ readonly tables: {
52
+ readonly [K in keyof Tables]: {
53
+ readonly columns: {
54
+ readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<
55
+ Tables[K]
56
+ >[ColK] extends ColumnBuilderState<string, infer Null, infer TType>
57
+ ? BuildStorageColumn<Null & boolean, TType>
58
+ : never;
59
+ };
60
+ };
61
+ };
62
+ };
63
+
64
+ export type BuildStorageTables<
65
+ Tables extends Record<
66
+ string,
67
+ TableBuilderState<
68
+ string,
69
+ Record<string, ColumnBuilderState<string, boolean, string>>,
70
+ readonly string[] | undefined
71
+ >
72
+ >,
73
+ > = {
74
+ readonly [K in keyof Tables]: {
75
+ readonly columns: {
76
+ readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<
77
+ Tables[K]
78
+ >[ColK] extends ColumnBuilderState<string, infer Null, infer TType>
79
+ ? BuildStorageColumn<Null & boolean, TType>
80
+ : never;
81
+ };
82
+ };
83
+ };
84
+
85
+ export type Mutable<T> = {
86
+ -readonly [K in keyof T]-?: T[K];
87
+ };
88
+
89
+ export type BuildModelFields<Fields extends Record<string, string>> = {
90
+ readonly [K in keyof Fields]: { readonly column: Fields[K] };
91
+ };
92
+
93
+ export type ExtractModelFields<
94
+ T extends ModelBuilderState<
95
+ string,
96
+ string,
97
+ Record<string, string>,
98
+ Record<string, RelationDefinition>
99
+ >,
100
+ > =
101
+ T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>>
102
+ ? F
103
+ : never;
104
+
105
+ export type ExtractModelRelations<
106
+ T extends ModelBuilderState<
107
+ string,
108
+ string,
109
+ Record<string, string>,
110
+ Record<string, RelationDefinition>
111
+ >,
112
+ > = T extends ModelBuilderState<string, string, Record<string, string>, infer R> ? R : never;
113
+
114
+ export type BuildModels<
115
+ Models extends Record<
116
+ string,
117
+ ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
118
+ >,
119
+ > = {
120
+ readonly [K in keyof Models]: {
121
+ readonly storage: { readonly table: Models[K]['table'] };
122
+ readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
123
+ };
124
+ };
125
+
126
+ export type BuildRelations<
127
+ Models extends Record<
128
+ string,
129
+ ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
130
+ >,
131
+ > = {
132
+ readonly [K in keyof Models as Models[K]['table']]: ExtractModelRelations<Models[K]>;
133
+ };
package/dist/index.d.ts DELETED
@@ -1,175 +0,0 @@
1
- import { TargetPackRef } from '@prisma-next/contract/framework-components';
2
-
3
- /**
4
- * Column type descriptor containing both codec ID and native type.
5
- * Used when defining columns with descriptor objects instead of string IDs.
6
- */
7
- type ColumnTypeDescriptor = {
8
- readonly codecId: string;
9
- readonly nativeType: string;
10
- };
11
- interface ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> {
12
- readonly name: Name;
13
- readonly nullable: Nullable;
14
- readonly type: Type;
15
- readonly nativeType: string;
16
- }
17
- interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
18
- readonly name: Name;
19
- readonly columns: Columns;
20
- readonly primaryKey?: PrimaryKey;
21
- }
22
- type RelationDefinition = {
23
- readonly to: string;
24
- readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
25
- readonly on: {
26
- readonly parentCols: readonly string[];
27
- readonly childCols: readonly string[];
28
- };
29
- readonly through?: {
30
- readonly table: string;
31
- readonly parentCols: readonly string[];
32
- readonly childCols: readonly string[];
33
- };
34
- };
35
- interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
36
- readonly name: Name;
37
- readonly table: Table;
38
- readonly fields: Fields;
39
- readonly relations: Relations;
40
- }
41
- interface ContractBuilderState<Target extends string | undefined = string | undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>, CoreHash extends string | undefined = string | undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
42
- readonly target?: Target;
43
- readonly tables: Tables;
44
- readonly models: Models;
45
- readonly coreHash?: CoreHash;
46
- readonly extensionPacks?: ExtensionPacks;
47
- readonly capabilities?: Capabilities;
48
- /**
49
- * Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
50
- * Populated when extension packs are registered during contract building.
51
- * Used to track which extension packs are included in the contract.
52
- * Can be undefined or empty if no extension packs are registered.
53
- * Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
54
- */
55
- readonly extensionNamespaces?: readonly string[];
56
- }
57
- interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
58
- nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
59
- type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
60
- build(): ColumnBuilderState<Name, Nullable, Type>;
61
- }
62
-
63
- declare class ModelBuilder<Name extends string, Table extends string, Fields extends Record<string, string> = Record<never, never>, Relations extends Record<string, RelationDefinition> = Record<never, never>> {
64
- private readonly _name;
65
- private readonly _table;
66
- private readonly _fields;
67
- private readonly _relations;
68
- constructor(name: Name, table: Table, fields?: Fields, relations?: Relations);
69
- field<FieldName extends string, ColumnName extends string>(fieldName: FieldName, columnName: ColumnName): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations>;
70
- relation<RelationName extends string, ToModel extends string, ToTable extends string>(name: RelationName, options: {
71
- toModel: ToModel;
72
- toTable: ToTable;
73
- cardinality: '1:1' | '1:N' | 'N:1';
74
- on: {
75
- parentTable: Table;
76
- parentColumns: readonly string[];
77
- childTable: ToTable;
78
- childColumns: readonly string[];
79
- };
80
- }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
81
- relation<RelationName extends string, ToModel extends string, ToTable extends string, JunctionTable extends string>(name: RelationName, options: {
82
- toModel: ToModel;
83
- toTable: ToTable;
84
- cardinality: 'N:M';
85
- through: {
86
- table: JunctionTable;
87
- parentColumns: readonly string[];
88
- childColumns: readonly string[];
89
- };
90
- on: {
91
- parentTable: Table;
92
- parentColumns: readonly string[];
93
- childTable: JunctionTable;
94
- childColumns: readonly string[];
95
- };
96
- }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
97
- build(): ModelBuilderState<Name, Table, Fields, Relations>;
98
- }
99
-
100
- declare class TableBuilder<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>> = Record<never, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined = undefined> {
101
- private readonly _name;
102
- private readonly _columns;
103
- private readonly _primaryKey;
104
- constructor(name: Name, columns?: Columns, primaryKey?: PrimaryKey);
105
- column<ColName extends string, Descriptor extends ColumnTypeDescriptor, Nullable extends boolean | undefined = undefined>(name: ColName, options: {
106
- type: Descriptor;
107
- nullable?: Nullable;
108
- }): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>>, PrimaryKey>;
109
- primaryKey<PK extends readonly string[]>(columns: PK, _name?: string): TableBuilder<Name, Columns, PK>;
110
- unique(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
111
- index(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
112
- foreignKey(_columns: readonly string[], _references: {
113
- table: string;
114
- columns: readonly string[];
115
- }, _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
116
- build(): TableBuilderState<Name, Columns, PrimaryKey>;
117
- }
118
-
119
- declare class ContractBuilder<Target extends string | undefined = undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, never>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, never>, CoreHash extends string | undefined = undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
120
- protected readonly state: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
121
- constructor(state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);
122
- target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
123
- capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C>;
124
- table<TableName extends string, T extends TableBuilder<TableName, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>(name: TableName, callback: (t: TableBuilder<TableName>) => T | undefined): ContractBuilder<Target, Tables & Record<TableName, ReturnType<T['build']>>, Models, CoreHash, ExtensionPacks, Capabilities>;
125
- model<ModelName extends string, TableName extends string, M extends ModelBuilder<ModelName, TableName, Record<string, string>, Record<string, RelationDefinition>>>(name: ModelName, table: TableName, callback: (m: ModelBuilder<ModelName, TableName, Record<string, string>, Record<never, never>>) => M | undefined): ContractBuilder<Target, Tables, Models & Record<ModelName, ReturnType<M['build']>>, CoreHash, ExtensionPacks, Capabilities>;
126
- coreHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
127
- }
128
- declare function defineContract(): ContractBuilder;
129
-
130
- type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
131
- readonly nativeType: string;
132
- readonly codecId: Type;
133
- readonly nullable: Nullable;
134
- };
135
- type ExtractColumns<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, infer C, readonly string[] | undefined> ? C : never;
136
- type ExtractPrimaryKey<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, infer PK> ? PK : never;
137
- type BuildStorage<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
138
- readonly tables: {
139
- readonly [K in keyof Tables]: {
140
- readonly columns: {
141
- readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never;
142
- };
143
- };
144
- };
145
- };
146
- type BuildStorageTables<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
147
- readonly [K in keyof Tables]: {
148
- readonly columns: {
149
- readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never;
150
- };
151
- };
152
- };
153
- type Mutable<T> = {
154
- -readonly [K in keyof T]-?: T[K];
155
- };
156
- type BuildModelFields<Fields extends Record<string, string>> = {
157
- readonly [K in keyof Fields]: {
158
- readonly column: Fields[K];
159
- };
160
- };
161
- type ExtractModelFields<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>> ? F : never;
162
- type ExtractModelRelations<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, Record<string, string>, infer R> ? R : never;
163
- type BuildModels<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = {
164
- readonly [K in keyof Models]: {
165
- readonly storage: {
166
- readonly table: Models[K]['table'];
167
- };
168
- readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
169
- };
170
- };
171
- type BuildRelations<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = {
172
- readonly [K in keyof Models as Models[K]['table']]: ExtractModelRelations<Models[K]>;
173
- };
174
-
175
- export { type BuildModelFields, type BuildModels, type BuildRelations, type BuildStorage, type BuildStorageColumn, type BuildStorageTables, type ColumnBuilder, type ColumnBuilderState, type ColumnTypeDescriptor, ContractBuilder, type ContractBuilderState, type ExtractColumns, type ExtractModelFields, type ExtractModelRelations, type ExtractPrimaryKey, ModelBuilder, type ModelBuilderState, type Mutable, type RelationDefinition, TableBuilder, type TableBuilderState, defineContract };