@prisma-next/contract-authoring 0.3.0-dev.34 → 0.3.0-dev.36

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,10 @@ 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)
17
19
 
18
20
  ## Package Status
19
21
 
@@ -0,0 +1,283 @@
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
+ * Column type descriptor containing both codec ID and native type.
8
+ * Used when defining columns with descriptor objects instead of string IDs.
9
+ *
10
+ * For parameterized types (e.g., `vector(1536)`), the `typeParams` field
11
+ * carries codec-owned parameters that affect both TypeScript type generation
12
+ * and native DDL output.
13
+ */
14
+ type ColumnTypeDescriptor = {
15
+ readonly codecId: string;
16
+ readonly nativeType: string;
17
+ readonly typeParams?: Record<string, unknown>;
18
+ readonly typeRef?: string;
19
+ };
20
+ /**
21
+ * Base column properties shared by all column states.
22
+ */
23
+ type ColumnBuilderStateBase<Name extends string, Type extends string> = {
24
+ readonly name: Name;
25
+ readonly type: Type;
26
+ readonly nativeType: string;
27
+ readonly typeParams?: Record<string, unknown>;
28
+ readonly typeRef?: string;
29
+ };
30
+ type StorageTypeInstanceState = {
31
+ readonly codecId: string;
32
+ readonly nativeType: string;
33
+ readonly typeParams: Record<string, unknown>;
34
+ };
35
+ /**
36
+ * Descriptive error type shown when attempting to use both nullable and default.
37
+ * This string literal appears in TypeScript error messages for better DX.
38
+ */
39
+ type NullableColumnCannotHaveDefault = "Error: A nullable column cannot have a default value. Remove 'nullable: true' or remove 'default'.";
40
+ /**
41
+ * Column builder state with enforced nullable/default mutual exclusivity.
42
+ *
43
+ * Invariant: A column with a default value is always NOT NULL.
44
+ * This is enforced at the type level via conditional types:
45
+ * - Nullable columns (`nullable: true`) cannot have a `default` property
46
+ * - Non-nullable columns (`nullable: false`) can optionally have a `default` property
47
+ */
48
+ type ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> = ColumnBuilderStateBase<Name, Type> & (Nullable extends true ? {
49
+ readonly nullable: true;
50
+ readonly default?: NullableColumnCannotHaveDefault;
51
+ } : {
52
+ readonly nullable: false;
53
+ readonly default?: ColumnDefault;
54
+ readonly executionDefault?: ExecutionMutationDefaultValue;
55
+ });
56
+ /**
57
+ * Unique constraint definition for table builder.
58
+ */
59
+ interface UniqueConstraintDef {
60
+ readonly columns: readonly string[];
61
+ readonly name?: string;
62
+ }
63
+ /**
64
+ * Index definition for table builder.
65
+ */
66
+ interface IndexDef {
67
+ readonly columns: readonly string[];
68
+ readonly name?: string;
69
+ }
70
+ /**
71
+ * Foreign key definition for table builder.
72
+ */
73
+ interface ForeignKeyDef {
74
+ readonly columns: readonly string[];
75
+ readonly references: {
76
+ readonly table: string;
77
+ readonly columns: readonly string[];
78
+ };
79
+ readonly name?: string;
80
+ }
81
+ interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
82
+ readonly name: Name;
83
+ readonly columns: Columns;
84
+ readonly primaryKey?: PrimaryKey;
85
+ readonly primaryKeyName?: string;
86
+ readonly uniques: readonly UniqueConstraintDef[];
87
+ readonly indexes: readonly IndexDef[];
88
+ readonly foreignKeys: readonly ForeignKeyDef[];
89
+ }
90
+ type RelationDefinition = {
91
+ readonly to: string;
92
+ readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
93
+ readonly on: {
94
+ readonly parentCols: readonly string[];
95
+ readonly childCols: readonly string[];
96
+ };
97
+ readonly through?: {
98
+ readonly table: string;
99
+ readonly parentCols: readonly string[];
100
+ readonly childCols: readonly string[];
101
+ };
102
+ };
103
+ interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
104
+ readonly name: Name;
105
+ readonly table: Table;
106
+ readonly fields: Fields;
107
+ readonly relations: Relations;
108
+ }
109
+ 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> {
110
+ readonly target?: Target;
111
+ readonly tables: Tables;
112
+ readonly models: Models;
113
+ readonly storageHash?: StorageHash;
114
+ readonly extensionPacks?: ExtensionPacks;
115
+ readonly capabilities?: Capabilities;
116
+ readonly storageTypes?: Record<string, StorageTypeInstanceState>;
117
+ /**
118
+ * Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
119
+ * Populated when extension packs are registered during contract building.
120
+ * Used to track which extension packs are included in the contract.
121
+ * Can be undefined or empty if no extension packs are registered.
122
+ * Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
123
+ */
124
+ readonly extensionNamespaces?: readonly string[];
125
+ }
126
+ interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
127
+ nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
128
+ type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
129
+ build(): ColumnBuilderState<Name, Nullable, Type>;
130
+ }
131
+ //#endregion
132
+ //#region src/model-builder.d.ts
133
+ 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>> {
134
+ private readonly _name;
135
+ private readonly _table;
136
+ private readonly _fields;
137
+ private readonly _relations;
138
+ constructor(name: Name, table: Table, fields?: Fields, relations?: Relations);
139
+ field<FieldName extends string, ColumnName extends string>(fieldName: FieldName, columnName: ColumnName): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations>;
140
+ relation<RelationName extends string, ToModel extends string, ToTable extends string>(name: RelationName, options: {
141
+ toModel: ToModel;
142
+ toTable: ToTable;
143
+ cardinality: '1:1' | '1:N' | 'N:1';
144
+ on: {
145
+ parentTable: Table;
146
+ parentColumns: readonly string[];
147
+ childTable: ToTable;
148
+ childColumns: readonly string[];
149
+ };
150
+ }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
151
+ relation<RelationName extends string, ToModel extends string, ToTable extends string, JunctionTable extends string>(name: RelationName, options: {
152
+ toModel: ToModel;
153
+ toTable: ToTable;
154
+ cardinality: 'N:M';
155
+ through: {
156
+ table: JunctionTable;
157
+ parentColumns: readonly string[];
158
+ childColumns: readonly string[];
159
+ };
160
+ on: {
161
+ parentTable: Table;
162
+ parentColumns: readonly string[];
163
+ childTable: JunctionTable;
164
+ childColumns: readonly string[];
165
+ };
166
+ }): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
167
+ build(): ModelBuilderState<Name, Table, Fields, Relations>;
168
+ }
169
+ //#endregion
170
+ //#region src/table-builder.d.ts
171
+ /**
172
+ * Column options for nullable columns.
173
+ * Nullable columns cannot have a default value.
174
+ */
175
+ interface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
176
+ type: Descriptor;
177
+ nullable: true;
178
+ typeParams?: Record<string, unknown>;
179
+ default?: NullableColumnCannotHaveDefault;
180
+ }
181
+ /**
182
+ * Column options for non-nullable columns.
183
+ * Non-nullable columns can optionally have a default value.
184
+ */
185
+ interface NonNullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {
186
+ type: Descriptor;
187
+ nullable?: false;
188
+ typeParams?: Record<string, unknown>;
189
+ default?: ColumnDefault;
190
+ }
191
+ type GeneratedColumnOptions<Descriptor extends ColumnTypeDescriptor> = Omit<NonNullableColumnOptions<Descriptor>, 'default' | 'nullable'> & {
192
+ /**
193
+ * Generated columns are always non-nullable and use mutation-time defaults
194
+ * that the runtime injects when the column is omitted from insert input.
195
+ */
196
+ nullable?: false;
197
+ generated: ExecutionMutationDefaultValue;
198
+ };
199
+ /**
200
+ * Creates a new table builder with the given name.
201
+ * This is the preferred way to create a TableBuilder - it ensures
202
+ * type parameters are inferred correctly without unsafe casts.
203
+ */
204
+ declare function createTable<Name extends string>(name: Name): TableBuilder<Name>;
205
+ /**
206
+ * Builder for defining table structure with type-safe chaining.
207
+ * Use `createTable(name)` to create instances.
208
+ */
209
+ 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> {
210
+ private readonly _state;
211
+ /** @internal Use createTable() instead */
212
+ constructor(name: Name, columns: Columns, primaryKey: PrimaryKey, primaryKeyName: string | undefined, uniques: readonly UniqueConstraintDef[], indexes: readonly IndexDef[], foreignKeys: readonly ForeignKeyDef[]);
213
+ private get _name();
214
+ private get _columns();
215
+ private get _primaryKey();
216
+ /**
217
+ * Add a nullable column to the table.
218
+ * Nullable columns cannot have a default value.
219
+ */
220
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: NullableColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, true, Descriptor['codecId']>>, PrimaryKey>;
221
+ /**
222
+ * Add a non-nullable column to the table.
223
+ * Non-nullable columns can optionally have a default value.
224
+ */
225
+ column<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: NonNullableColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>, PrimaryKey>;
226
+ generated<ColName extends string, Descriptor extends ColumnTypeDescriptor>(name: ColName, options: GeneratedColumnOptions<Descriptor>): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, false, Descriptor['codecId']>>, PrimaryKey>;
227
+ private columnInternal;
228
+ primaryKey<PK extends readonly string[]>(columns: PK, name?: string): TableBuilder<Name, Columns, PK>;
229
+ unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
230
+ index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
231
+ foreignKey(columns: readonly string[], references: {
232
+ table: string;
233
+ columns: readonly string[];
234
+ }, name?: string): TableBuilder<Name, Columns, PrimaryKey>;
235
+ build(): TableBuilderState<Name, Columns, PrimaryKey>;
236
+ }
237
+ //#endregion
238
+ //#region src/contract-builder.d.ts
239
+ 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> {
240
+ protected readonly state: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>;
241
+ constructor(state?: ContractBuilderState<Target, Tables, Models, StorageHash, ExtensionPacks, Capabilities>);
242
+ target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, StorageHash, ExtensionPacks, Capabilities>;
243
+ capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, StorageHash, ExtensionPacks, C>;
244
+ 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>;
245
+ 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>;
246
+ storageHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
247
+ }
248
+ declare function defineContract(): ContractBuilder;
249
+ //#endregion
250
+ //#region src/types.d.ts
251
+ type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
252
+ readonly nativeType: string;
253
+ readonly codecId: Type;
254
+ readonly nullable: Nullable;
255
+ readonly typeParams?: Record<string, unknown>;
256
+ readonly typeRef?: string;
257
+ };
258
+ 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;
259
+ 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;
260
+ type BuildStorage<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
261
+ readonly tables: { readonly [K in keyof Tables]: {
262
+ 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 };
263
+ } };
264
+ };
265
+ type BuildStorageTables<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = { readonly [K in keyof Tables]: {
266
+ 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 };
267
+ } };
268
+ type Mutable<T> = { -readonly [K in keyof T]-?: T[K] };
269
+ type BuildModelFields<Fields extends Record<string, string>> = { readonly [K in keyof Fields]: {
270
+ readonly column: Fields[K];
271
+ } };
272
+ 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;
273
+ 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;
274
+ type BuildModels<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = { readonly [K in keyof Models]: {
275
+ readonly storage: {
276
+ readonly table: Models[K]['table'];
277
+ };
278
+ readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
279
+ } };
280
+ 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]> };
281
+ //#endregion
282
+ 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 IndexDef, ModelBuilder, type ModelBuilderState, type Mutable, type RelationDefinition, TableBuilder, type TableBuilderState, type UniqueConstraintDef, createTable, defineContract };
283
+ //# 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":";;;;;;;;AAUA;AAKE;;;;AAS4B,KAdlB,oBAAA,GAckB;EAIlB,SAAA,OAAA,EAAA,MAAA;EAUA,SAAA,UAAA,EAAA,MAAA;EAWA,SAAA,UAAA,CAAA,EApCY,MAoCM,CAAA,MAAA,EAAA,OAAA,CAAA;EAIH,SAAA,OAAA,CAAA,EAAA,MAAA;CAAM;;;;KAjC5B,sBAsCsB,CAAA,aAAA,MAAA,EAAA,aAAA,MAAA,CAAA,GAAA;EACS,SAAA,IAAA,EAtCnB,IAsCmB;EAA6B,SAAA,IAAA,EArChD,IAqCgD;EAMhD,SAAA,UAAA,EAAA,MAAmB;EAQnB,SAAA,UAAQ,CAAA,EAjDD,MAiDC,CAAA,MAAA,EAAA,OAAA,CAAA;EAQR,SAAA,OAAa,CAAA,EAAA,MAAA;AAS9B,CAAA;AAEiC,KAhErB,wBAAA,GAgEqB;EAAf,SAAA,OAAA,EAAA,MAAA;EAGD,SAAA,UAAA,EAAA,MAAA;EACG,SAAA,UAAA,EAjEG,MAiEH,CAAA,MAAA,EAAA,OAAA,CAAA;CACI;;;;;AAOZ,KAlEA,+BAAA,GAkEkB,oGAAA;AAc9B;;;;;;;;AAS+B,KA9EnB,kBA8EmB,CAAA,aAAA,MAAA,EAAA,iBAAA,OAAA,EAAA,aAAA,MAAA,CAAA,GA1E3B,sBA0E2B,CA1EJ,IA0EI,EA1EE,IA0EF,CAAA,GAAA,CAzE5B,QAyE4B,SAAA,IAAA,GAAA;EAGd,SAAA,QAAA,EAAA,IAAoB;EAMhB,SAAA,OAAA,CAAA,EAjF+B,+BAiF/B;CAAf,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MvB,CIN8B,CJM9B,CAAA,CAAA,OAAA,CAAA;EACC,CAAA;EACC,SAAA,MAAA,EIPE,gBJOF,CIPmB,kBJOnB,CIPsC,MJOtC,CIP6C,CJO7C,CAAA,CAAA,CAAA;AACG,CAAA,EAAS;AAGd,KIPL,cJOK,CAAoB,eINpB,MJMoB,CAAA,MAAA,EIJjC,iBJIiC,CAAA,MAAA,EAAA,MAAA,EIJC,MJID,CAAA,MAAA,EAAA,MAAA,CAAA,EIJyB,MJIzB,CAAA,MAAA,EIJwC,kBJIxC,CAAA,CAAA,CAAA,CAAA,GAAA,iBAMhB,MIPE,MJOF,IIPY,MJOZ,CIPmB,CJOnB,CAAA,CAAA,OAAA,CAAA,GIPiC,qBJOjC,CIPuD,MJOvD,CIP8D,CJO9D,CAAA,CAAA,EAAf"}
package/dist/index.mjs ADDED
@@ -0,0 +1,221 @@
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, name) {
139
+ const fkDef = name ? {
140
+ columns,
141
+ references,
142
+ name
143
+ } : {
144
+ columns,
145
+ references
146
+ };
147
+ 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]);
148
+ }
149
+ build() {
150
+ return {
151
+ name: this._name,
152
+ columns: this._columns,
153
+ ...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {},
154
+ ...this._state.primaryKeyName !== void 0 ? { primaryKeyName: this._state.primaryKeyName } : {},
155
+ uniques: this._state.uniques,
156
+ indexes: this._state.indexes,
157
+ foreignKeys: this._state.foreignKeys
158
+ };
159
+ }
160
+ };
161
+
162
+ //#endregion
163
+ //#region src/contract-builder.ts
164
+ var ContractBuilder = class ContractBuilder {
165
+ state;
166
+ constructor(state) {
167
+ this.state = state ?? {
168
+ tables: {},
169
+ models: {}
170
+ };
171
+ }
172
+ target(packRef) {
173
+ return new ContractBuilder({
174
+ ...this.state,
175
+ target: packRef.targetId
176
+ });
177
+ }
178
+ capabilities(capabilities) {
179
+ return new ContractBuilder({
180
+ ...this.state,
181
+ capabilities
182
+ });
183
+ }
184
+ table(name, callback) {
185
+ const tableBuilder = createTable(name);
186
+ const result = callback(tableBuilder);
187
+ const tableState = (result instanceof TableBuilder ? result : tableBuilder).build();
188
+ return new ContractBuilder({
189
+ ...this.state,
190
+ tables: {
191
+ ...this.state.tables,
192
+ [name]: tableState
193
+ }
194
+ });
195
+ }
196
+ model(name, table, callback) {
197
+ const modelBuilder = new ModelBuilder(name, table);
198
+ const result = callback(modelBuilder);
199
+ const modelState = (result instanceof ModelBuilder ? result : modelBuilder).build();
200
+ return new ContractBuilder({
201
+ ...this.state,
202
+ models: {
203
+ ...this.state.models,
204
+ [name]: modelState
205
+ }
206
+ });
207
+ }
208
+ storageHash(hash) {
209
+ return new ContractBuilder({
210
+ ...this.state,
211
+ storageHash: hash
212
+ });
213
+ }
214
+ };
215
+ function defineContract() {
216
+ return new ContractBuilder();
217
+ }
218
+
219
+ //#endregion
220
+ export { ContractBuilder, ModelBuilder, TableBuilder, createTable, defineContract };
221
+ //# 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 IndexDef,\n NullableColumnCannotHaveDefault,\n TableBuilderState,\n UniqueConstraintDef,\n} from './builder-state';\n\n/**\n * Column options for nullable columns.\n * Nullable columns cannot have a default value.\n */\ninterface NullableColumnOptions<Descriptor extends ColumnTypeDescriptor> {\n type: Descriptor;\n nullable: true;\n typeParams?: Record<string, unknown>;\n default?: NullableColumnCannotHaveDefault;\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/**\n * Column options that enforce nullable/default mutual exclusivity.\n *\n * Invariant: A column with a default value is always NOT NULL.\n * - If `nullable: true`, the `default` property is forbidden\n * - If `nullable` is `false` or omitted, the `default` property is allowed\n */\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 /**\n * Add a nullable column to the table.\n * Nullable columns cannot have a default value.\n */\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 // The type safety is enforced at the call site via overloads:\n // - NullableColumnOptions forbids `default` when `nullable: true`\n // - NonNullableColumnOptions allows `default` when `nullable` is false/omitted\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 name?: string,\n ): TableBuilder<Name, Columns, PrimaryKey> {\n const fkDef: ForeignKeyDef = name ? { columns, references, name } : { columns, references };\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 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\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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AAS,SAAS,aAAa;EAErC,MAAM,cADe,kBAAkB,eAAe,SAAS,cAC/B,OAAO;AAEvC,SAAO,IAAI,gBAOT;GACA,GAAG,KAAK;GACR,QAAQ;IAAE,GAAG,KAAK,MAAM;KAAS,OAAO;IAAY;GAErD,CAAC;;CAGJ,YACE,MAC0E;AAC1E,SAAO,IAAI,gBAAyE;GAClF,GAAG,KAAK;GACR,aAAa;GACd,CAAC;;;AAIN,SAAgB,iBAAkC;AAChD,QAAO,IAAI,iBAAiB"}
package/package.json CHANGED
@@ -1,31 +1,39 @@
1
1
  {
2
2
  "name": "@prisma-next/contract-authoring",
3
- "version": "0.3.0-dev.34",
3
+ "version": "0.3.0-dev.36",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Target-agnostic contract authoring builder core for Prisma Next",
7
7
  "dependencies": {
8
8
  "ts-toolbelt": "^9.6.0",
9
- "@prisma-next/contract": "0.3.0-dev.34"
9
+ "@prisma-next/contract": "0.3.0-dev.36",
10
+ "@prisma-next/utils": "0.3.0-dev.36"
10
11
  },
11
12
  "devDependencies": {
12
- "tsup": "8.5.1",
13
+ "tsdown": "0.18.4",
13
14
  "typescript": "5.9.3",
14
- "vitest": "4.0.16",
15
- "@prisma-next/tsconfig": "0.0.0"
15
+ "vitest": "4.0.17",
16
+ "@prisma-next/tsconfig": "0.0.0",
17
+ "@prisma-next/tsdown": "0.0.0"
16
18
  },
17
19
  "files": [
18
20
  "dist",
19
21
  "src"
20
22
  ],
21
23
  "exports": {
22
- ".": {
23
- "types": "./dist/index.d.ts",
24
- "import": "./dist/index.js"
25
- }
24
+ ".": "./dist/index.mjs",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "./dist/index.mjs",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/prisma/prisma-next.git",
33
+ "directory": "packages/1-framework/2-authoring/contract"
26
34
  },
27
35
  "scripts": {
28
- "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
36
+ "build": "tsdown",
29
37
  "test": "vitest run",
30
38
  "test:coverage": "vitest run --coverage",
31
39
  "typecheck": "tsc --project tsconfig.json --noEmit",