@prisma-next/contract-authoring 0.3.0-dev.5 → 0.3.0-dev.50

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 CHANGED
@@ -12,8 +12,11 @@ This package provides generic builder primitives that can be composed with targe
12
12
 
13
13
  - **Generic Builder Core**: Provides target-agnostic builder state types and builder classes (`TableBuilder`, `ModelBuilder`, `ContractBuilder`)
14
14
  - **State Management**: Manages builder state for tables, columns, models, and relations without target-specific logic
15
+ - **Storage Type State**: Captures target-agnostic storage type entries and column `typeRef` metadata for family-specific composition
15
16
  - **Type Helpers**: Provides generic type-level helpers for transforming builder states into contract structures
16
17
  - **Composition Surface**: Enables target-family specific packages (e.g., `@prisma-next/sql-contract-ts`) to compose generic core with family-specific types
18
+ - **Defaults**: Reuses shared contract `ColumnDefault` for db-agnostic defaults (literal, function, and client-generated descriptors)
19
+ - **Foreign Keys Configuration**: Provides a `foreignKeys()` method on the base `ContractBuilder` to configure FK constraint and index emission behavior
17
20
 
18
21
  ## Package Status
19
22
 
@@ -33,7 +36,7 @@ This package was created in Phase 2 of the contract authoring extraction. It con
33
36
 
34
37
  ## Exports
35
38
 
36
- - Builder state types: `ColumnBuilderState`, `TableBuilderState`, `ModelBuilderState`, `ContractBuilderState`, `RelationDefinition`, `ColumnBuilder`
39
+ - Builder state types: `ColumnBuilderState`, `TableBuilderState`, `ModelBuilderState`, `ContractBuilderState`, `ForeignKeysConfigState`, `RelationDefinition`, `ColumnBuilder`
37
40
  - Builder classes: `TableBuilder`, `ModelBuilder`, `ContractBuilder`
38
41
  - Type helpers: `BuildStorageColumn`, `BuildStorage`, `BuildModels`, `BuildRelations`, extract helpers, `Mutable`
39
42
  - Factory function: `defineContract()` (generic)
@@ -0,0 +1,295 @@
1
+ import { ColumnDefault, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
2
+ import { TargetPackRef } from "@prisma-next/contract/framework-components";
3
+
4
+ //#region src/builder-state.d.ts
5
+
6
+ /**
7
+ * Duplicated from sql-contract to avoid cross-layer dependency
8
+ * (framework authoring cannot depend on the SQL domain's contract package).
9
+ */
10
+ type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
11
+ /**
12
+ * Column type descriptor containing both codec ID and native type.
13
+ * Used when defining columns with descriptor objects instead of string IDs.
14
+ *
15
+ * For parameterized types (e.g., `vector(1536)`), the `typeParams` field
16
+ * carries codec-owned parameters that affect both TypeScript type generation
17
+ * and native DDL output.
18
+ */
19
+ type ColumnTypeDescriptor = {
20
+ readonly codecId: string;
21
+ readonly nativeType: string;
22
+ readonly typeParams?: Record<string, unknown>;
23
+ readonly typeRef?: string;
24
+ };
25
+ /**
26
+ * Base column properties shared by all column states.
27
+ */
28
+ type ColumnBuilderStateBase<Name extends string, Type extends string> = {
29
+ readonly name: Name;
30
+ readonly type: Type;
31
+ readonly nativeType: string;
32
+ readonly typeParams?: Record<string, unknown>;
33
+ readonly typeRef?: string;
34
+ };
35
+ type StorageTypeInstanceState = {
36
+ readonly codecId: string;
37
+ readonly nativeType: string;
38
+ readonly typeParams: Record<string, unknown>;
39
+ };
40
+ /**
41
+ * Column builder state.
42
+ *
43
+ * Both nullable and non-nullable columns can define defaults to match database behavior.
44
+ */
45
+ type ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> = ColumnBuilderStateBase<Name, Type> & (Nullable extends true ? {
46
+ readonly nullable: true;
47
+ readonly default?: ColumnDefault;
48
+ } : {
49
+ readonly nullable: false;
50
+ readonly default?: ColumnDefault;
51
+ readonly executionDefault?: ExecutionMutationDefaultValue;
52
+ });
53
+ /**
54
+ * Unique constraint definition for table builder.
55
+ */
56
+ interface UniqueConstraintDef {
57
+ readonly columns: readonly string[];
58
+ readonly name?: string;
59
+ }
60
+ /**
61
+ * Index definition for table builder.
62
+ */
63
+ interface IndexDef {
64
+ readonly columns: readonly string[];
65
+ readonly name?: string;
66
+ }
67
+ /**
68
+ * Options for configuring a foreign key's name and referential actions.
69
+ */
70
+ type ForeignKeyOptions = {
71
+ readonly name?: string;
72
+ readonly onDelete?: ReferentialAction;
73
+ readonly onUpdate?: ReferentialAction;
74
+ };
75
+ /**
76
+ * Foreign key definition for table builder.
77
+ */
78
+ interface ForeignKeyDef extends ForeignKeyOptions {
79
+ readonly columns: readonly string[];
80
+ readonly references: {
81
+ readonly table: string;
82
+ readonly columns: readonly string[];
83
+ };
84
+ readonly constraint?: boolean;
85
+ readonly index?: boolean;
86
+ }
87
+ interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
88
+ readonly name: Name;
89
+ readonly columns: Columns;
90
+ readonly primaryKey?: PrimaryKey;
91
+ readonly primaryKeyName?: string;
92
+ readonly uniques: readonly UniqueConstraintDef[];
93
+ readonly indexes: readonly IndexDef[];
94
+ readonly foreignKeys: readonly ForeignKeyDef[];
95
+ }
96
+ type RelationDefinition = {
97
+ readonly to: string;
98
+ readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
99
+ readonly on: {
100
+ readonly parentCols: readonly string[];
101
+ readonly childCols: readonly string[];
102
+ };
103
+ readonly through?: {
104
+ readonly table: string;
105
+ readonly parentCols: readonly string[];
106
+ readonly childCols: readonly string[];
107
+ };
108
+ };
109
+ interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
110
+ readonly name: Name;
111
+ readonly table: Table;
112
+ readonly fields: Fields;
113
+ readonly relations: Relations;
114
+ }
115
+ interface ForeignKeyDefaultsState {
116
+ readonly constraint: boolean;
117
+ readonly index: boolean;
118
+ }
119
+ 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>>>, StorageHash extends string | undefined = string | undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
120
+ readonly target?: Target;
121
+ readonly tables: Tables;
122
+ readonly models: Models;
123
+ readonly storageHash?: StorageHash;
124
+ readonly extensionPacks?: ExtensionPacks;
125
+ readonly capabilities?: Capabilities;
126
+ readonly storageTypes?: Record<string, StorageTypeInstanceState>;
127
+ readonly foreignKeyDefaults?: ForeignKeyDefaultsState;
128
+ /**
129
+ * Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
130
+ * Populated when extension packs are registered during contract building.
131
+ * Used to track which extension packs are included in the contract.
132
+ * Can be undefined or empty if no extension packs are registered.
133
+ * Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
134
+ */
135
+ readonly extensionNamespaces?: readonly string[];
136
+ }
137
+ interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
138
+ nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
139
+ type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
140
+ build(): ColumnBuilderState<Name, Nullable, Type>;
141
+ }
142
+ //#endregion
143
+ //#region src/model-builder.d.ts
144
+ 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>> {
145
+ private readonly _name;
146
+ private readonly _table;
147
+ private readonly _fields;
148
+ private readonly _relations;
149
+ constructor(name: Name, table: Table, fields?: Fields, relations?: Relations);
150
+ field<FieldName extends string, ColumnName extends string>(fieldName: FieldName, columnName: ColumnName): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations>;
151
+ relation<RelationName extends string, ToModel extends string, ToTable extends string>(name: RelationName, options: {
152
+ toModel: ToModel;
153
+ toTable: ToTable;
154
+ cardinality: '1:1' | '1:N' | 'N:1';
155
+ on: {
156
+ parentTable: Table;
157
+ parentColumns: readonly string[];
158
+ childTable: ToTable;
159
+ childColumns: readonly string[];
160
+ };
161
+ }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
162
+ relation<RelationName extends string, ToModel extends string, ToTable extends string, JunctionTable extends string>(name: RelationName, options: {
163
+ toModel: ToModel;
164
+ toTable: ToTable;
165
+ cardinality: 'N:M';
166
+ through: {
167
+ table: JunctionTable;
168
+ parentColumns: readonly string[];
169
+ childColumns: readonly string[];
170
+ };
171
+ on: {
172
+ parentTable: Table;
173
+ parentColumns: readonly string[];
174
+ childTable: JunctionTable;
175
+ childColumns: readonly string[];
176
+ };
177
+ }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
178
+ build(): ModelBuilderState<Name, Table, Fields, Relations>;
179
+ }
180
+ //#endregion
181
+ //#region src/table-builder.d.ts
182
+ /**
183
+ * Column options for nullable columns.
184
+ */
185
+ interface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
186
+ type: Descriptor;
187
+ nullable: true;
188
+ typeParams?: Record<string, unknown>;
189
+ default?: ColumnDefault;
190
+ }
191
+ /**
192
+ * Column options for non-nullable columns.
193
+ * Non-nullable columns can optionally have a default value.
194
+ */
195
+ interface NonNullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
196
+ type: Descriptor;
197
+ nullable?: false;
198
+ typeParams?: Record<string, unknown>;
199
+ default?: ColumnDefault;
200
+ }
201
+ type GeneratedColumnOptions<Descriptor extends ColumnTypeDescriptor> = Omit<NonNullableColumnOptions<Descriptor>, 'default' | 'nullable'> & {
202
+ /**
203
+ * Generated columns are always non-nullable and use mutation-time defaults
204
+ * that the runtime injects when the column is omitted from insert input.
205
+ */
206
+ nullable?: false;
207
+ generated: ExecutionMutationDefaultValue;
208
+ };
209
+ /**
210
+ * Creates a new table builder with the given name.
211
+ * This is the preferred way to create a TableBuilder - it ensures
212
+ * type parameters are inferred correctly without unsafe casts.
213
+ */
214
+ declare function createTable<Name extends string>(name: Name): TableBuilder<Name>;
215
+ /**
216
+ * Builder for defining table structure with type-safe chaining.
217
+ * Use `createTable(name)` to create instances.
218
+ */
219
+ 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> {
220
+ private readonly _state;
221
+ /** @internal Use createTable() instead */
222
+ constructor(name: Name, columns: Columns, primaryKey: PrimaryKey, primaryKeyName: string | undefined, uniques: readonly UniqueConstraintDef[], indexes: readonly IndexDef[], foreignKeys: readonly ForeignKeyDef[]);
223
+ private get _name();
224
+ private get _columns();
225
+ private get _primaryKey();
226
+ /** Add a nullable column to the table. */
227
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: NullableColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, true, Descriptor['codecId']>>, PrimaryKey>;
228
+ /**
229
+ * Add a non-nullable column to the table.
230
+ * Non-nullable columns can optionally have a default value.
231
+ */
232
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: NonNullableColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>, PrimaryKey>;
233
+ generated<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: GeneratedColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>, PrimaryKey>;
234
+ private columnInternal;
235
+ primaryKey<PK extends readonly string[]>(columns: PK, name?: string): TableBuilder<Name, Columns, PK>;
236
+ unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
237
+ index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
238
+ foreignKey(columns: readonly string[], references: {
239
+ table: string;
240
+ columns: readonly string[];
241
+ }, opts?: string | (ForeignKeyOptions & {
242
+ constraint?: boolean;
243
+ index?: boolean;
244
+ })): TableBuilder<Name, Columns, PrimaryKey>;
245
+ build(): TableBuilderState<Name, Columns, PrimaryKey>;
246
+ }
247
+ //#endregion
248
+ //#region src/contract-builder.d.ts
249
+ 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>, StorageHash extends string | undefined = undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
250
+ protected readonly state: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>;
251
+ constructor(state?: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>);
252
+ target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities>;
253
+ capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C>;
254
+ 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, StorageHash, ExtensionPacks, Capabilities>;
255
+ 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']>>, StorageHash, ExtensionPacks, Capabilities>;
256
+ storageHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
257
+ foreignKeyDefaults(config: ForeignKeyDefaultsState): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>;
258
+ }
259
+ declare function defineContract(): ContractBuilder;
260
+ //#endregion
261
+ //#region src/types.d.ts
262
+ type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
263
+ readonly nativeType: string;
264
+ readonly codecId: Type;
265
+ readonly nullable: Nullable;
266
+ readonly typeParams?: Record<string, unknown>;
267
+ readonly typeRef?: string;
268
+ readonly default?: ColumnDefault;
269
+ };
270
+ 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;
271
+ 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;
272
+ type BuildStorage<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
273
+ readonly tables: { readonly [K in keyof Tables]: {
274
+ readonly columns: { readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never };
275
+ } };
276
+ };
277
+ type BuildStorageTables<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = { readonly [K in keyof Tables]: {
278
+ readonly columns: { readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never };
279
+ } };
280
+ type Mutable<T> = { -readonly [K in keyof T]-?: T[K] };
281
+ type BuildModelFields<Fields extends Record<string, string>> = { readonly [K in keyof Fields]: {
282
+ readonly column: Fields[K];
283
+ } };
284
+ 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;
285
+ 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;
286
+ type BuildModels<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = { readonly [K in keyof Models]: {
287
+ readonly storage: {
288
+ readonly table: Models[K]['table'];
289
+ };
290
+ readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
291
+ } };
292
+ type BuildRelations<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = { readonly [K in keyof Models as Models[K]['table']]: ExtractModelRelations<Models[K]> };
293
+ //#endregion
294
+ 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, type ForeignKeyDef, type ForeignKeyDefaultsState, type ForeignKeyOptions, type IndexDef, ModelBuilder, type ModelBuilderState, type Mutable, type RelationDefinition, TableBuilder, type TableBuilderState, type UniqueConstraintDef, createTable, defineContract };
295
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/builder-state.ts","../src/model-builder.ts","../src/table-builder.ts","../src/contract-builder.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAMA;AAUY,KAVA,iBAAA,GAUoB,UAGR,GAAM,UAAA,GAAA,SAAA,GAAA,SAAA,GAAA,YAAA;AAE5B;;;;;AAaF;AAWA;;AAIiC,KAjCrB,oBAAA,GAiCqB;EAA7B,SAAA,OAAA,EAAA,MAAA;EACD,SAAA,UAAA,EAA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,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,KAAA,EAAA,CAAA,GAAA,CAAA,GAAA,KAAA;AACkB,KIfvB,WJeuB,CAAA,eIdlB,MJckB,CAAA,MAAA,EIZ/B,iBJY+B,CAAA,MAAA,EAAA,MAAA,EIZG,MJYH,CAAA,MAAA,EAAA,MAAA,CAAA,EIZ2B,MJY3B,CAAA,MAAA,EIZ0C,kBJY1C,CAAA,CAAA,CAAA,CAAA,GAAA,iBAAf,MITG,MJSH,GAAA;EAEH,SAAA,OAAA,EAAA;IACC,SAAA,KAAA,EIXsB,MJWtB,CIX6B,CJW7B,CAAA,CAAA,OAAA,CAAA;EACC,CAAA;EACG,SAAA,MAAA,EIZD,gBJYC,CIZgB,kBJYhB,CIZmC,MJYnC,CIZ0C,CJY1C,CAAA,CAAA,CAAA;AAAS,CAAA,EAG/B;AAKiB,KIhBL,cJgBK,CAAoB,eIfpB,MJeoB,CAAA,MAAA,EIbjC,iBJaiC,CAAA,MAAA,EAAA,MAAA,EIbC,MJaD,CAAA,MAAA,EAAA,MAAA,CAAA,EIbyB,MJazB,CAAA,MAAA,EIbwC,kBJaxC,CAAA,CAAA,CAAA,CAAA,GAAA,iBAMhB,MIhBE,MJgBF,IIhBY,MJgBZ,CIhBmB,CJgBnB,CAAA,CAAA,OAAA,CAAA,GIhBiC,qBJgBjC,CIhBuD,MJgBvD,CIhB8D,CJgB9D,CAAA,CAAA,EAAf"}
package/dist/index.mjs ADDED
@@ -0,0 +1,229 @@
1
+ import { ifDefined } from "@prisma-next/utils/defined";
2
+
3
+ //#region src/model-builder.ts
4
+ var ModelBuilder = class ModelBuilder {
5
+ _name;
6
+ _table;
7
+ _fields;
8
+ _relations;
9
+ constructor(name, table, fields = {}, relations = {}) {
10
+ this._name = name;
11
+ this._table = table;
12
+ this._fields = fields;
13
+ this._relations = relations;
14
+ }
15
+ field(fieldName, columnName) {
16
+ return new ModelBuilder(this._name, this._table, {
17
+ ...this._fields,
18
+ [fieldName]: columnName
19
+ }, this._relations);
20
+ }
21
+ relation(name, options) {
22
+ if (options.on.parentTable !== this._table) throw new Error(`Relation "${name}" parentTable "${options.on.parentTable}" does not match model table "${this._table}"`);
23
+ if (options.cardinality === "N:M") {
24
+ if (!options.through) throw new Error(`Relation "${name}" with cardinality "N:M" requires through field`);
25
+ if (options.on.childTable !== options.through.table) throw new Error(`Relation "${name}" childTable "${options.on.childTable}" does not match through.table "${options.through.table}"`);
26
+ } else if (options.on.childTable !== options.toTable) throw new Error(`Relation "${name}" childTable "${options.on.childTable}" does not match toTable "${options.toTable}"`);
27
+ const relationDef = {
28
+ to: options.toModel,
29
+ cardinality: options.cardinality,
30
+ on: {
31
+ parentCols: options.on.parentColumns,
32
+ childCols: options.on.childColumns
33
+ },
34
+ ...options.through ? { through: {
35
+ table: options.through.table,
36
+ parentCols: options.through.parentColumns,
37
+ childCols: options.through.childColumns
38
+ } } : void 0
39
+ };
40
+ return new ModelBuilder(this._name, this._table, this._fields, {
41
+ ...this._relations,
42
+ [name]: relationDef
43
+ });
44
+ }
45
+ build() {
46
+ return {
47
+ name: this._name,
48
+ table: this._table,
49
+ fields: this._fields,
50
+ relations: this._relations
51
+ };
52
+ }
53
+ };
54
+
55
+ //#endregion
56
+ //#region src/table-builder.ts
57
+ /**
58
+ * Creates a new table builder with the given name.
59
+ * This is the preferred way to create a TableBuilder - it ensures
60
+ * type parameters are inferred correctly without unsafe casts.
61
+ */
62
+ function createTable(name) {
63
+ return new TableBuilder(name, {}, void 0, void 0, [], [], []);
64
+ }
65
+ /**
66
+ * Builder for defining table structure with type-safe chaining.
67
+ * Use `createTable(name)` to create instances.
68
+ */
69
+ var TableBuilder = class TableBuilder {
70
+ _state;
71
+ /** @internal Use createTable() instead */
72
+ constructor(name, columns, primaryKey, primaryKeyName, uniques, indexes, foreignKeys) {
73
+ this._state = {
74
+ name,
75
+ columns,
76
+ primaryKey,
77
+ primaryKeyName,
78
+ uniques,
79
+ indexes,
80
+ foreignKeys
81
+ };
82
+ }
83
+ get _name() {
84
+ return this._state.name;
85
+ }
86
+ get _columns() {
87
+ return this._state.columns;
88
+ }
89
+ get _primaryKey() {
90
+ return this._state.primaryKey;
91
+ }
92
+ /**
93
+ * Implementation of the column method.
94
+ */
95
+ column(name, options) {
96
+ return this.columnInternal(name, options);
97
+ }
98
+ generated(name, options) {
99
+ const { generated, ...columnOptions } = options;
100
+ return this.columnInternal(name, columnOptions, generated);
101
+ }
102
+ columnInternal(name, options, executionDefault) {
103
+ const nullable = options.nullable ?? false;
104
+ const { codecId, nativeType, typeParams: descriptorTypeParams, typeRef } = options.type;
105
+ const columnState = {
106
+ name,
107
+ nullable,
108
+ type: codecId,
109
+ nativeType,
110
+ ...ifDefined("typeParams", options.typeParams ?? descriptorTypeParams),
111
+ ...ifDefined("typeRef", typeRef),
112
+ ...ifDefined("default", "default" in options ? options.default : void 0),
113
+ ...ifDefined("executionDefault", executionDefault)
114
+ };
115
+ const newColumns = {
116
+ ...this._columns,
117
+ [name]: columnState
118
+ };
119
+ return new TableBuilder(this._state.name, newColumns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, this._state.indexes, this._state.foreignKeys);
120
+ }
121
+ primaryKey(columns, name) {
122
+ return new TableBuilder(this._state.name, this._state.columns, columns, name, this._state.uniques, this._state.indexes, this._state.foreignKeys);
123
+ }
124
+ unique(columns, name) {
125
+ const constraint = name ? {
126
+ columns,
127
+ name
128
+ } : { columns };
129
+ return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, [...this._state.uniques, constraint], this._state.indexes, this._state.foreignKeys);
130
+ }
131
+ index(columns, name) {
132
+ const indexDef = name ? {
133
+ columns,
134
+ name
135
+ } : { columns };
136
+ return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, [...this._state.indexes, indexDef], this._state.foreignKeys);
137
+ }
138
+ foreignKey(columns, references, opts) {
139
+ const resolved = typeof opts === "string" ? { name: opts } : opts;
140
+ const fkDef = {
141
+ columns,
142
+ references,
143
+ ...ifDefined("name", resolved?.name),
144
+ ...ifDefined("onDelete", resolved?.onDelete),
145
+ ...ifDefined("onUpdate", resolved?.onUpdate),
146
+ ...ifDefined("constraint", resolved?.constraint),
147
+ ...ifDefined("index", resolved?.index)
148
+ };
149
+ return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, this._state.indexes, [...this._state.foreignKeys, fkDef]);
150
+ }
151
+ build() {
152
+ return {
153
+ name: this._name,
154
+ columns: this._columns,
155
+ ...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {},
156
+ ...this._state.primaryKeyName !== void 0 ? { primaryKeyName: this._state.primaryKeyName } : {},
157
+ uniques: this._state.uniques,
158
+ indexes: this._state.indexes,
159
+ foreignKeys: this._state.foreignKeys
160
+ };
161
+ }
162
+ };
163
+
164
+ //#endregion
165
+ //#region src/contract-builder.ts
166
+ var ContractBuilder = class ContractBuilder {
167
+ state;
168
+ constructor(state) {
169
+ this.state = state ?? {
170
+ tables: {},
171
+ models: {}
172
+ };
173
+ }
174
+ target(packRef) {
175
+ return new ContractBuilder({
176
+ ...this.state,
177
+ target: packRef.targetId
178
+ });
179
+ }
180
+ capabilities(capabilities) {
181
+ return new ContractBuilder({
182
+ ...this.state,
183
+ capabilities
184
+ });
185
+ }
186
+ table(name, callback) {
187
+ const tableBuilder = createTable(name);
188
+ const result = callback(tableBuilder);
189
+ const tableState = (result instanceof TableBuilder ? result : tableBuilder).build();
190
+ return new ContractBuilder({
191
+ ...this.state,
192
+ tables: {
193
+ ...this.state.tables,
194
+ [name]: tableState
195
+ }
196
+ });
197
+ }
198
+ model(name, table, callback) {
199
+ const modelBuilder = new ModelBuilder(name, table);
200
+ const result = callback(modelBuilder);
201
+ const modelState = (result instanceof ModelBuilder ? result : modelBuilder).build();
202
+ return new ContractBuilder({
203
+ ...this.state,
204
+ models: {
205
+ ...this.state.models,
206
+ [name]: modelState
207
+ }
208
+ });
209
+ }
210
+ storageHash(hash) {
211
+ return new ContractBuilder({
212
+ ...this.state,
213
+ storageHash: hash
214
+ });
215
+ }
216
+ foreignKeyDefaults(config) {
217
+ return new ContractBuilder({
218
+ ...this.state,
219
+ foreignKeyDefaults: config
220
+ });
221
+ }
222
+ };
223
+ function defineContract() {
224
+ return new ContractBuilder();
225
+ }
226
+
227
+ //#endregion
228
+ export { ContractBuilder, ModelBuilder, TableBuilder, createTable, defineContract };
229
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["relationDef: RelationDefinition","constraint: UniqueConstraintDef","indexDef: IndexDef","fkDef: ForeignKeyDef"],"sources":["../src/model-builder.ts","../src/table-builder.ts","../src/contract-builder.ts"],"sourcesContent":["import type { ModelBuilderState, RelationDefinition } from './builder-state';\n\nexport class ModelBuilder<\n Name extends string,\n Table extends string,\n Fields extends Record<string, string> = Record<never, never>,\n Relations extends Record<string, RelationDefinition> = Record<never, never>,\n> {\n private readonly _name: Name;\n private readonly _table: Table;\n private readonly _fields: Fields;\n private readonly _relations: Relations;\n\n constructor(\n name: Name,\n table: Table,\n fields: Fields = {} as Fields,\n relations: Relations = {} as Relations,\n ) {\n this._name = name;\n this._table = table;\n this._fields = fields;\n this._relations = relations;\n }\n\n field<FieldName extends string, ColumnName extends string>(\n fieldName: FieldName,\n columnName: ColumnName,\n ): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations> {\n return new ModelBuilder(\n this._name,\n this._table,\n {\n ...this._fields,\n [fieldName]: columnName,\n } as Fields & Record<FieldName, ColumnName>,\n this._relations,\n );\n }\n\n relation<RelationName extends string, ToModel extends string, ToTable extends string>(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: '1:1' | '1:N' | 'N:1';\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: ToTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;\n relation<\n RelationName extends string,\n ToModel extends string,\n ToTable extends string,\n JunctionTable extends string,\n >(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: 'N:M';\n through: {\n table: JunctionTable;\n parentColumns: readonly string[];\n childColumns: readonly string[];\n };\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: JunctionTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;\n relation<\n RelationName extends string,\n ToModel extends string,\n ToTable extends string,\n JunctionTable extends string = never,\n >(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';\n through?: {\n table: JunctionTable;\n parentColumns: readonly string[];\n childColumns: readonly string[];\n };\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: ToTable | JunctionTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>> {\n // Validate parentTable matches model's table\n if (options.on.parentTable !== this._table) {\n throw new Error(\n `Relation \"${name}\" parentTable \"${options.on.parentTable}\" does not match model table \"${this._table}\"`,\n );\n }\n\n // Validate childTable matches toTable (for non-N:M) or through.table (for N:M)\n if (options.cardinality === 'N:M') {\n if (!options.through) {\n throw new Error(`Relation \"${name}\" with cardinality \"N:M\" requires through field`);\n }\n if (options.on.childTable !== options.through.table) {\n throw new Error(\n `Relation \"${name}\" childTable \"${options.on.childTable}\" does not match through.table \"${options.through.table}\"`,\n );\n }\n } else {\n if (options.on.childTable !== options.toTable) {\n throw new Error(\n `Relation \"${name}\" childTable \"${options.on.childTable}\" does not match toTable \"${options.toTable}\"`,\n );\n }\n }\n\n const relationDef: RelationDefinition = {\n to: options.toModel,\n cardinality: options.cardinality,\n on: {\n parentCols: options.on.parentColumns,\n childCols: options.on.childColumns,\n },\n ...(options.through\n ? {\n through: {\n table: options.through.table,\n parentCols: options.through.parentColumns,\n childCols: options.through.childColumns,\n },\n }\n : undefined),\n };\n\n return new ModelBuilder(this._name, this._table, this._fields, {\n ...this._relations,\n [name]: relationDef,\n } as Relations & Record<RelationName, RelationDefinition>);\n }\n\n build(): ModelBuilderState<Name, Table, Fields, Relations> {\n return {\n name: this._name,\n table: this._table,\n fields: this._fields,\n relations: this._relations,\n };\n }\n}\n","import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type {\n ColumnBuilderState,\n ColumnTypeDescriptor,\n ForeignKeyDef,\n ForeignKeyOptions,\n IndexDef,\n TableBuilderState,\n UniqueConstraintDef,\n} from './builder-state';\n\n/**\n * Column options for nullable columns.\n */\ninterface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {\n type: Descriptor;\n nullable: true;\n typeParams?: Record<string, unknown>;\n default?: ColumnDefault;\n}\n\n/**\n * Column options for non-nullable columns.\n * Non-nullable columns can optionally have a default value.\n */\ninterface NonNullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {\n type: Descriptor;\n nullable?: false;\n typeParams?: Record<string, unknown>;\n default?: ColumnDefault;\n}\n\ntype GeneratedColumnOptions<Descriptor extends ColumnTypeDescriptor> = Omit<\n NonNullableColumnOptions<Descriptor>,\n 'default' | 'nullable'\n> & {\n /**\n * Generated columns are always non-nullable and use mutation-time defaults\n * that the runtime injects when the column is omitted from insert input.\n */\n nullable?: false;\n generated: ExecutionMutationDefaultValue;\n};\n\n/** Column options for any column nullability. */\ntype ColumnOptions<Descriptor extends ColumnTypeDescriptor> =\n | NullableColumnOptions<Descriptor>\n | NonNullableColumnOptions<Descriptor>;\n\ntype NullableFromOptions<TOptions> = TOptions extends { nullable: true } ? true : false;\n\ninterface TableBuilderInternalState<\n Name extends string,\n Columns extends Record<string, ColumnBuilderState<string, boolean, string>>,\n PrimaryKey extends readonly string[] | undefined,\n> {\n readonly name: Name;\n readonly columns: Columns;\n readonly primaryKey: PrimaryKey;\n readonly primaryKeyName: string | undefined;\n readonly uniques: readonly UniqueConstraintDef[];\n readonly indexes: readonly IndexDef[];\n readonly foreignKeys: readonly ForeignKeyDef[];\n}\n\n/**\n * Creates a new table builder with the given name.\n * This is the preferred way to create a TableBuilder - it ensures\n * type parameters are inferred correctly without unsafe casts.\n */\nexport function createTable<Name extends string>(name: Name): TableBuilder<Name> {\n return new TableBuilder(name, {}, undefined, undefined, [], [], []);\n}\n\n/**\n * Builder for defining table structure with type-safe chaining.\n * Use `createTable(name)` to create instances.\n */\nexport class TableBuilder<\n Name extends string,\n Columns extends Record<string, ColumnBuilderState<string, boolean, string>> = Record<\n never,\n ColumnBuilderState<string, boolean, string>\n >,\n PrimaryKey extends readonly string[] | undefined = undefined,\n> {\n private readonly _state: TableBuilderInternalState<Name, Columns, PrimaryKey>;\n\n /** @internal Use createTable() instead */\n constructor(\n name: Name,\n columns: Columns,\n primaryKey: PrimaryKey,\n primaryKeyName: string | undefined,\n uniques: readonly UniqueConstraintDef[],\n indexes: readonly IndexDef[],\n foreignKeys: readonly ForeignKeyDef[],\n ) {\n this._state = {\n name,\n columns,\n primaryKey,\n primaryKeyName,\n uniques,\n indexes,\n foreignKeys,\n };\n }\n\n private get _name(): Name {\n return this._state.name;\n }\n\n private get _columns(): Columns {\n return this._state.columns;\n }\n\n private get _primaryKey(): PrimaryKey {\n return this._state.primaryKey;\n }\n\n /** Add a nullable column to the table. */\n column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(\n name: ColName,\n options: NullableColumnOptions<Descriptor>,\n ): TableBuilder<\n Name,\n Columns & Record<ColName, ColumnBuilderState<ColName, true, Descriptor['codecId']>>,\n PrimaryKey\n >;\n\n /**\n * Add a non-nullable column to the table.\n * Non-nullable columns can optionally have a default value.\n */\n column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(\n name: ColName,\n options: NonNullableColumnOptions<Descriptor>,\n ): TableBuilder<\n Name,\n Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,\n PrimaryKey\n >;\n\n /**\n * Implementation of the column method.\n */\n column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(\n name: ColName,\n options: ColumnOptions<Descriptor>,\n ): TableBuilder<\n Name,\n Columns & Record<ColName, ColumnBuilderState<ColName, boolean, Descriptor['codecId']>>,\n PrimaryKey\n > {\n return this.columnInternal(name, options);\n }\n\n generated<ColName extends string, Descriptor extends ColumnTypeDescriptor>(\n name: ColName,\n options: GeneratedColumnOptions<Descriptor>,\n ): TableBuilder<\n Name,\n Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>,\n PrimaryKey\n > {\n const { generated, ...columnOptions } = options;\n return this.columnInternal(name, columnOptions, generated);\n }\n\n private columnInternal<\n ColName extends string,\n Descriptor extends ColumnTypeDescriptor,\n Options extends ColumnOptions<Descriptor>,\n >(\n name: ColName,\n options: Options,\n executionDefault?: ExecutionMutationDefaultValue,\n ): TableBuilder<\n Name,\n Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>\n >,\n PrimaryKey\n > {\n const nullable = options.nullable ?? false;\n const { codecId, nativeType, typeParams: descriptorTypeParams, typeRef } = options.type;\n const typeParams = options.typeParams ?? descriptorTypeParams;\n\n const columnState = {\n name,\n nullable,\n type: codecId,\n nativeType,\n ...ifDefined('typeParams', typeParams),\n ...ifDefined('typeRef', typeRef),\n ...ifDefined('default', 'default' in options ? options.default : undefined),\n ...ifDefined('executionDefault', executionDefault),\n } as ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>;\n const newColumns = { ...this._columns, [name]: columnState } as Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, NullableFromOptions<Options>, Descriptor['codecId']>\n >;\n return new TableBuilder(\n this._state.name,\n newColumns,\n this._state.primaryKey,\n this._state.primaryKeyName,\n this._state.uniques,\n this._state.indexes,\n this._state.foreignKeys,\n );\n }\n\n primaryKey<PK extends readonly string[]>(\n columns: PK,\n name?: string,\n ): TableBuilder<Name, Columns, PK> {\n return new TableBuilder(\n this._state.name,\n this._state.columns,\n columns,\n name,\n this._state.uniques,\n this._state.indexes,\n this._state.foreignKeys,\n );\n }\n\n unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {\n const constraint: UniqueConstraintDef = name ? { columns, name } : { columns };\n return new TableBuilder(\n this._state.name,\n this._state.columns,\n this._state.primaryKey,\n this._state.primaryKeyName,\n [...this._state.uniques, constraint],\n this._state.indexes,\n this._state.foreignKeys,\n );\n }\n\n index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {\n const indexDef: IndexDef = name ? { columns, name } : { columns };\n return new TableBuilder(\n this._state.name,\n this._state.columns,\n this._state.primaryKey,\n this._state.primaryKeyName,\n this._state.uniques,\n [...this._state.indexes, indexDef],\n this._state.foreignKeys,\n );\n }\n\n foreignKey(\n columns: readonly string[],\n references: { table: string; columns: readonly string[] },\n opts?: string | (ForeignKeyOptions & { constraint?: boolean; index?: boolean }),\n ): TableBuilder<Name, Columns, PrimaryKey> {\n const resolved = typeof opts === 'string' ? { name: opts } : opts;\n const fkDef: ForeignKeyDef = {\n columns,\n references,\n ...ifDefined('name', resolved?.name),\n ...ifDefined('onDelete', resolved?.onDelete),\n ...ifDefined('onUpdate', resolved?.onUpdate),\n ...ifDefined('constraint', resolved?.constraint),\n ...ifDefined('index', resolved?.index),\n };\n return new TableBuilder(\n this._state.name,\n this._state.columns,\n this._state.primaryKey,\n this._state.primaryKeyName,\n this._state.uniques,\n this._state.indexes,\n [...this._state.foreignKeys, fkDef],\n );\n }\n\n build(): TableBuilderState<Name, Columns, PrimaryKey> {\n return {\n name: this._name,\n columns: this._columns,\n ...(this._primaryKey !== undefined ? { primaryKey: this._primaryKey } : {}),\n ...(this._state.primaryKeyName !== undefined\n ? { primaryKeyName: this._state.primaryKeyName }\n : {}),\n uniques: this._state.uniques,\n indexes: this._state.indexes,\n foreignKeys: this._state.foreignKeys,\n } as TableBuilderState<Name, Columns, PrimaryKey>;\n }\n}\n","import type { TargetPackRef } from '@prisma-next/contract/framework-components';\nimport type {\n ColumnBuilderState,\n ContractBuilderState,\n ForeignKeyDefaultsState,\n ModelBuilderState,\n RelationDefinition,\n TableBuilderState,\n} from './builder-state';\nimport { ModelBuilder } from './model-builder';\nimport { createTable, TableBuilder } from './table-builder';\n\nexport class ContractBuilder<\n Target extends string | undefined = undefined,\n Tables extends Record<\n string,\n TableBuilderState<\n string,\n Record<string, ColumnBuilderState<string, boolean, string>>,\n readonly string[] | undefined\n >\n > = Record<never, never>,\n Models extends Record<\n string,\n ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>\n > = Record<never, never>,\n StorageHash extends string | undefined = undefined,\n ExtensionPacks extends Record<string, unknown> | undefined = undefined,\n Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,\n> {\n protected readonly state: ContractBuilderState<\n Target,\n Tables,\n Models,\n StorageHash,\n ExtensionPacks,\n Capabilities\n >;\n\n constructor(\n state?: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>,\n ) {\n this.state =\n state ??\n ({\n tables: {},\n models: {},\n } as ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>);\n }\n\n target<T extends string>(\n packRef: TargetPackRef<string, T>,\n ): ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities> {\n return new ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities>({\n ...this.state,\n target: packRef.targetId,\n });\n }\n\n capabilities<C extends Record<string, Record<string, boolean>>>(\n capabilities: C,\n ): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C> {\n return new ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C>({\n ...this.state,\n capabilities,\n });\n }\n\n table<\n TableName extends string,\n T extends TableBuilder<\n TableName,\n Record<string, ColumnBuilderState<string, boolean, string>>,\n readonly string[] | undefined\n >,\n >(\n name: TableName,\n callback: (t: TableBuilder<TableName>) => T | undefined,\n ): ContractBuilder<\n Target,\n Tables & Record<TableName, ReturnType<T['build']>>,\n Models,\n StorageHash,\n ExtensionPacks,\n Capabilities\n > {\n const tableBuilder = createTable(name);\n const result = callback(tableBuilder);\n const finalBuilder = result instanceof TableBuilder ? result : tableBuilder;\n const tableState = finalBuilder.build();\n\n return new ContractBuilder<\n Target,\n Tables & Record<TableName, ReturnType<T['build']>>,\n Models,\n StorageHash,\n ExtensionPacks,\n Capabilities\n >({\n ...this.state,\n tables: { ...this.state.tables, [name]: tableState } as Tables &\n Record<TableName, ReturnType<T['build']>>,\n });\n }\n\n model<\n ModelName extends string,\n TableName extends string,\n M extends ModelBuilder<\n ModelName,\n TableName,\n Record<string, string>,\n Record<string, RelationDefinition>\n >,\n >(\n name: ModelName,\n table: TableName,\n callback: (\n m: ModelBuilder<ModelName, TableName, Record<string, string>, Record<never, never>>,\n ) => M | undefined,\n ): ContractBuilder<\n Target,\n Tables,\n Models & Record<ModelName, ReturnType<M['build']>>,\n StorageHash,\n ExtensionPacks,\n Capabilities\n > {\n const modelBuilder = new ModelBuilder<ModelName, TableName>(name, table);\n const result = callback(modelBuilder);\n const finalBuilder = result instanceof ModelBuilder ? result : modelBuilder;\n const modelState = finalBuilder.build();\n\n return new ContractBuilder<\n Target,\n Tables,\n Models & Record<ModelName, ReturnType<M['build']>>,\n StorageHash,\n ExtensionPacks,\n Capabilities\n >({\n ...this.state,\n models: { ...this.state.models, [name]: modelState } as Models &\n Record<ModelName, ReturnType<M['build']>>,\n });\n }\n\n storageHash<H extends string>(\n hash: H,\n ): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities> {\n return new ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>({\n ...this.state,\n storageHash: hash,\n });\n }\n\n foreignKeyDefaults(\n config: ForeignKeyDefaultsState,\n ): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities> {\n return new ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>({\n ...this.state,\n foreignKeyDefaults: config,\n });\n }\n}\n\nexport function defineContract(): ContractBuilder {\n return new ContractBuilder();\n}\n"],"mappings":";;;AAEA,IAAa,eAAb,MAAa,aAKX;CACA,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YACE,MACA,OACA,SAAiB,EAAE,EACnB,YAAuB,EAAE,EACzB;AACA,OAAK,QAAQ;AACb,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,aAAa;;CAGpB,MACE,WACA,YAC8E;AAC9E,SAAO,IAAI,aACT,KAAK,OACL,KAAK,QACL;GACE,GAAG,KAAK;IACP,YAAY;GACd,EACD,KAAK,WACN;;CAyCH,SAME,MACA,SAgByF;AAEzF,MAAI,QAAQ,GAAG,gBAAgB,KAAK,OAClC,OAAM,IAAI,MACR,aAAa,KAAK,iBAAiB,QAAQ,GAAG,YAAY,gCAAgC,KAAK,OAAO,GACvG;AAIH,MAAI,QAAQ,gBAAgB,OAAO;AACjC,OAAI,CAAC,QAAQ,QACX,OAAM,IAAI,MAAM,aAAa,KAAK,iDAAiD;AAErF,OAAI,QAAQ,GAAG,eAAe,QAAQ,QAAQ,MAC5C,OAAM,IAAI,MACR,aAAa,KAAK,gBAAgB,QAAQ,GAAG,WAAW,kCAAkC,QAAQ,QAAQ,MAAM,GACjH;aAGC,QAAQ,GAAG,eAAe,QAAQ,QACpC,OAAM,IAAI,MACR,aAAa,KAAK,gBAAgB,QAAQ,GAAG,WAAW,4BAA4B,QAAQ,QAAQ,GACrG;EAIL,MAAMA,cAAkC;GACtC,IAAI,QAAQ;GACZ,aAAa,QAAQ;GACrB,IAAI;IACF,YAAY,QAAQ,GAAG;IACvB,WAAW,QAAQ,GAAG;IACvB;GACD,GAAI,QAAQ,UACR,EACE,SAAS;IACP,OAAO,QAAQ,QAAQ;IACvB,YAAY,QAAQ,QAAQ;IAC5B,WAAW,QAAQ,QAAQ;IAC5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