@prisma-next/contract-authoring 0.3.0-pr.90.2 → 0.3.0-pr.91.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builder-state.d.ts +1 -9
- package/dist/builder-state.d.ts.map +1 -1
- package/dist/contract-builder.d.ts +9 -15
- package/dist/contract-builder.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/builder-state.ts +0 -13
- package/src/contract-builder.ts +8 -69
- package/src/index.ts +0 -1
package/dist/builder-state.d.ts
CHANGED
|
@@ -65,18 +65,10 @@ export interface ModelBuilderState<Name extends string, Table extends string, Fi
|
|
|
65
65
|
readonly fields: Fields;
|
|
66
66
|
readonly relations: Relations;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
* Enum builder state containing the enum name and ordered list of values.
|
|
70
|
-
*/
|
|
71
|
-
export interface EnumBuilderState<Name extends string, Values extends readonly string[]> {
|
|
72
|
-
readonly name: Name;
|
|
73
|
-
readonly values: Values;
|
|
74
|
-
}
|
|
75
|
-
export 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>>>, Enums extends Record<string, EnumBuilderState<string, readonly string[]>> = Record<never, EnumBuilderState<string, readonly string[]>>, CoreHash extends string | undefined = string | undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
|
|
68
|
+
export interface ContractBuilderState<Target extends string | undefined = string | undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>, CoreHash extends string | undefined = string | undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
|
|
76
69
|
readonly target?: Target;
|
|
77
70
|
readonly tables: Tables;
|
|
78
71
|
readonly models: Models;
|
|
79
|
-
readonly enums: Enums;
|
|
80
72
|
readonly coreHash?: CoreHash;
|
|
81
73
|
readonly extensionPacks?: ExtensionPacks;
|
|
82
74
|
readonly capabilities?: Capabilities;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder-state.d.ts","sourceRoot":"","sources":["../src/builder-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,WAAW,kBAAkB,CACjC,IAAI,SAAS,MAAM,EACnB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM;IAEnB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,QA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IACnE,KAAK,IAAI,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;CACnD"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import type { TargetPackRef } from '@prisma-next/contract/framework-components';
|
|
2
|
-
import type { ColumnBuilderState, ContractBuilderState,
|
|
2
|
+
import type { ColumnBuilderState, ContractBuilderState, ModelBuilderState, RelationDefinition, TableBuilderState } from './builder-state';
|
|
3
3
|
import { ModelBuilder } from './model-builder';
|
|
4
4
|
import { TableBuilder } from './table-builder';
|
|
5
|
-
export 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>,
|
|
6
|
-
protected readonly state: ContractBuilderState<Target, Tables, Models,
|
|
7
|
-
constructor(state?: ContractBuilderState<Target, Tables, Models,
|
|
8
|
-
target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models,
|
|
9
|
-
capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models,
|
|
10
|
-
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,
|
|
11
|
-
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']>>,
|
|
12
|
-
|
|
13
|
-
* Define an enum type with ordered values.
|
|
14
|
-
* @param name The name of the enum type (e.g., 'Role', 'Status')
|
|
15
|
-
* @param values The ordered list of enum values (e.g., ['USER', 'ADMIN'])
|
|
16
|
-
*/
|
|
17
|
-
enum<EnumName extends string, Values extends readonly [string, ...string[]]>(name: EnumName, values: Values): ContractBuilder<Target, Tables, Models, Enums & Record<EnumName, EnumBuilderState<EnumName, Values>>, CoreHash, ExtensionPacks, Capabilities>;
|
|
18
|
-
coreHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, Enums, H, ExtensionPacks, Capabilities>;
|
|
5
|
+
export declare class ContractBuilder<Target extends string | undefined = undefined, Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = Record<never, never>, Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = Record<never, never>, CoreHash extends string | undefined = undefined, ExtensionPacks extends Record<string, unknown> | undefined = undefined, Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined> {
|
|
6
|
+
protected readonly state: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
7
|
+
constructor(state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);
|
|
8
|
+
target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
9
|
+
capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C>;
|
|
10
|
+
table<TableName extends string, T extends TableBuilder<TableName, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>(name: TableName, callback: (t: TableBuilder<TableName>) => T | undefined): ContractBuilder<Target, Tables & Record<TableName, ReturnType<T['build']>>, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
11
|
+
model<ModelName extends string, TableName extends string, M extends ModelBuilder<ModelName, TableName, Record<string, string>, Record<string, RelationDefinition>>>(name: ModelName, table: TableName, callback: (m: ModelBuilder<ModelName, TableName, Record<string, string>, Record<never, never>>) => M | undefined): ContractBuilder<Target, Tables, Models & Record<ModelName, ReturnType<M['build']>>, CoreHash, ExtensionPacks, Capabilities>;
|
|
12
|
+
coreHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
|
|
19
13
|
}
|
|
20
14
|
export declare function defineContract(): ContractBuilder;
|
|
21
15
|
//# sourceMappingURL=contract-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-builder.d.ts","sourceRoot":"","sources":["../src/contract-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"contract-builder.d.ts","sourceRoot":"","sources":["../src/contract-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAe,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE5D,qBAAa,eAAe,CAC1B,MAAM,SAAS,MAAM,GAAG,SAAS,GAAG,SAAS,EAC7C,MAAM,SAAS,MAAM,CACnB,MAAM,EACN,iBAAiB,CACf,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAC3D,SAAS,MAAM,EAAE,GAAG,SAAS,CAC9B,CACF,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxB,MAAM,SAAS,MAAM,CACnB,MAAM,EACN,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE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E,CAAC,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,GACtD,eAAe,CAChB,MAAM,EACN,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAClD,MAAM,EACN,QAAQ,EACR,cAAc,EACd,YAAY,CACb;IAoBD,KAAK,CACH,SAAS,SAAS,MAAM,EACxB,SAAS,SAAS,MAAM,EACxB,CAAC,SAAS,YAAY,CACpB,SAAS,EACT,SAAS,EACT,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CACnC,EAED,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,CACR,CAAC,EAAE,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,KAChF,CAAC,GAAG,SAAS,GACjB,eAAe,CAChB,MAAM,EACN,MAAM,EACN,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAClD,QAAQ,EACR,cAAc,EACd,YAAY,CACb;IAoBD,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvB,IAAI,EAAE,CAAC,GACN,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,EAAE,YAAY,CAAC;CAM5E;AAED,wBAAgB,cAAc,IAAI,eAAe,CAEhD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ColumnBuilder, ColumnBuilderState, ColumnTypeDescriptor, ContractBuilderState,
|
|
1
|
+
export type { ColumnBuilder, ColumnBuilderState, ColumnTypeDescriptor, ContractBuilderState, ForeignKeyDef, IndexDef, ModelBuilderState, RelationDefinition, TableBuilderState, UniqueConstraintDef, } from './builder-state';
|
|
2
2
|
export { ContractBuilder, defineContract } from './contract-builder';
|
|
3
3
|
export { ModelBuilder } from './model-builder';
|
|
4
4
|
export { createTable, TableBuilder } from './table-builder';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE5D,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,OAAO,GACR,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -186,8 +186,7 @@ var ContractBuilder = class _ContractBuilder {
|
|
|
186
186
|
constructor(state) {
|
|
187
187
|
this.state = state ?? {
|
|
188
188
|
tables: {},
|
|
189
|
-
models: {}
|
|
190
|
-
enums: {}
|
|
189
|
+
models: {}
|
|
191
190
|
};
|
|
192
191
|
}
|
|
193
192
|
target(packRef) {
|
|
@@ -222,21 +221,6 @@ var ContractBuilder = class _ContractBuilder {
|
|
|
222
221
|
models: { ...this.state.models, [name]: modelState }
|
|
223
222
|
});
|
|
224
223
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Define an enum type with ordered values.
|
|
227
|
-
* @param name The name of the enum type (e.g., 'Role', 'Status')
|
|
228
|
-
* @param values The ordered list of enum values (e.g., ['USER', 'ADMIN'])
|
|
229
|
-
*/
|
|
230
|
-
enum(name, values) {
|
|
231
|
-
const enumState = {
|
|
232
|
-
name,
|
|
233
|
-
values
|
|
234
|
-
};
|
|
235
|
-
return new _ContractBuilder({
|
|
236
|
-
...this.state,
|
|
237
|
-
enums: { ...this.state.enums, [name]: enumState }
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
224
|
coreHash(hash) {
|
|
241
225
|
return new _ContractBuilder({
|
|
242
226
|
...this.state,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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 {\n ColumnBuilderState,\n ColumnTypeDescriptor,\n ForeignKeyDef,\n IndexDef,\n TableBuilderState,\n UniqueConstraintDef,\n} from './builder-state';\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 column<\n ColName extends string,\n Descriptor extends ColumnTypeDescriptor,\n Nullable extends boolean | undefined = undefined,\n >(\n name: ColName,\n options: {\n type: Descriptor;\n nullable?: Nullable;\n },\n ): TableBuilder<\n Name,\n Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>\n >,\n PrimaryKey\n > {\n const nullable = (options.nullable ?? false) as Nullable extends true ? true : false;\n const { codecId, nativeType } = options.type;\n\n const columnState = {\n name,\n nullable,\n type: codecId,\n nativeType,\n } as ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>;\n const newColumns = { ...this._columns, [name]: columnState } as Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, Nullable extends true ? true : false, 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 EnumBuilderState,\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 Enums extends Record<string, EnumBuilderState<string, readonly string[]>> = Record<never, never>,\n CoreHash 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 Enums,\n CoreHash,\n ExtensionPacks,\n Capabilities\n >;\n\n constructor(\n state?: ContractBuilderState<\n Target,\n Tables,\n Models,\n Enums,\n CoreHash,\n ExtensionPacks,\n Capabilities\n >,\n ) {\n this.state =\n state ??\n ({\n tables: {},\n models: {},\n enums: {},\n } as ContractBuilderState<\n Target,\n Tables,\n Models,\n Enums,\n CoreHash,\n ExtensionPacks,\n Capabilities\n >);\n }\n\n target<T extends string>(\n packRef: TargetPackRef<string, T>,\n ): ContractBuilder<T, Tables, Models, Enums, CoreHash, ExtensionPacks, Capabilities> {\n return new ContractBuilder<T, Tables, Models, Enums, CoreHash, 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, Enums, CoreHash, ExtensionPacks, C> {\n return new ContractBuilder<Target, Tables, Models, Enums, CoreHash, 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 Enums,\n CoreHash,\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 Enums,\n CoreHash,\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 Enums,\n CoreHash,\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 Enums,\n CoreHash,\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 /**\n * Define an enum type with ordered values.\n * @param name The name of the enum type (e.g., 'Role', 'Status')\n * @param values The ordered list of enum values (e.g., ['USER', 'ADMIN'])\n */\n enum<EnumName extends string, Values extends readonly [string, ...string[]]>(\n name: EnumName,\n values: Values,\n ): ContractBuilder<\n Target,\n Tables,\n Models,\n Enums & Record<EnumName, EnumBuilderState<EnumName, Values>>,\n CoreHash,\n ExtensionPacks,\n Capabilities\n > {\n const enumState: EnumBuilderState<EnumName, Values> = {\n name,\n values,\n };\n\n return new ContractBuilder<\n Target,\n Tables,\n Models,\n Enums & Record<EnumName, EnumBuilderState<EnumName, Values>>,\n CoreHash,\n ExtensionPacks,\n Capabilities\n >({\n ...this.state,\n enums: { ...this.state.enums, [name]: enumState } as Enums &\n Record<EnumName, EnumBuilderState<EnumName, Values>>,\n });\n }\n\n coreHash<H extends string>(\n hash: H,\n ): ContractBuilder<Target, Tables, Models, Enums, H, ExtensionPacks, Capabilities> {\n return new ContractBuilder<Target, Tables, Models, Enums, H, ExtensionPacks, Capabilities>({\n ...this.state,\n coreHash: hash,\n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iBAQT;AAAA,MACA,GAAG,KAAK;AAAA,MACR,QAAQ,EAAE,GAAG,KAAK,MAAM,QAAQ,CAAC,IAAI,GAAG,WAAW;AAAA,IAErD,CAAC;AAAA,EACH;AAAA,EAEA,MAUE,MACA,OACA,UAWA;AACA,UAAM,eAAe,IAAI,aAAmC,MAAM,KAAK;AACvE,UAAM,SAAS,SAAS,YAAY;AACpC,UAAM,eAAe,kBAAkB,eAAe,SAAS;AAC/D,UAAM,aAAa,aAAa,MAAM;AAEtC,WAAO,IAAI,iBAQT;AAAA,MACA,GAAG,KAAK;AAAA,MACR,QAAQ,EAAE,GAAG,KAAK,MAAM,QAAQ,CAAC,IAAI,GAAG,WAAW;AAAA,IAErD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KACE,MACA,QASA;AACA,UAAM,YAAgD;AAAA,MACpD;AAAA,MACA;AAAA,IACF;AAEA,WAAO,IAAI,iBAQT;AAAA,MACA,GAAG,KAAK;AAAA,MACR,OAAO,EAAE,GAAG,KAAK,MAAM,OAAO,CAAC,IAAI,GAAG,UAAU;AAAA,IAElD,CAAC;AAAA,EACH;AAAA,EAEA,SACE,MACiF;AACjF,WAAO,IAAI,iBAAgF;AAAA,MACzF,GAAG,KAAK;AAAA,MACR,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AACF;AAEO,SAAS,iBAAkC;AAChD,SAAO,IAAI,gBAAgB;AAC7B;","names":[]}
|
|
1
|
+
{"version":3,"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 {\n ColumnBuilderState,\n ColumnTypeDescriptor,\n ForeignKeyDef,\n IndexDef,\n TableBuilderState,\n UniqueConstraintDef,\n} from './builder-state';\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 column<\n ColName extends string,\n Descriptor extends ColumnTypeDescriptor,\n Nullable extends boolean | undefined = undefined,\n >(\n name: ColName,\n options: {\n type: Descriptor;\n nullable?: Nullable;\n },\n ): TableBuilder<\n Name,\n Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>\n >,\n PrimaryKey\n > {\n const nullable = (options.nullable ?? false) as Nullable extends true ? true : false;\n const { codecId, nativeType } = options.type;\n\n const columnState = {\n name,\n nullable,\n type: codecId,\n nativeType,\n } as ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>;\n const newColumns = { ...this._columns, [name]: columnState } as Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, Nullable extends true ? true : false, 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 CoreHash 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 CoreHash,\n ExtensionPacks,\n Capabilities\n >;\n\n constructor(\n state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>,\n ) {\n this.state =\n state ??\n ({\n tables: {},\n models: {},\n } as ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);\n }\n\n target<T extends string>(\n packRef: TargetPackRef<string, T>,\n ): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities> {\n return new ContractBuilder<T, Tables, Models, CoreHash, 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, CoreHash, ExtensionPacks, C> {\n return new ContractBuilder<Target, Tables, Models, CoreHash, 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 CoreHash,\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 CoreHash,\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 CoreHash,\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 CoreHash,\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 coreHash<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 coreHash: hash,\n });\n }\n}\n\nexport function defineContract(): ContractBuilder {\n return new ContractBuilder();\n}\n"],"mappings":";AAEO,IAAM,eAAN,MAAM,cAKX;AAAA,EACiB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YACE,MACA,OACA,SAAiB,CAAC,GAClB,YAAuB,CAAC,GACxB;AACA,SAAK,QAAQ;AACb,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,MACE,WACA,YAC8E;AAC9E,WAAO,IA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AAK;AAAA,MACR,QAAQ,EAAE,GAAG,KAAK,MAAM,QAAQ,CAAC,IAAI,GAAG,WAAW;AAAA,IAErD,CAAC;AAAA,EACH;AAAA,EAEA,SACE,MAC0E;AAC1E,WAAO,IAAI,iBAAyE;AAAA,MAClF,GAAG,KAAK;AAAA,MACR,UAAU;AAAA,IACZ,CAAC;AAAA,EACH;AACF;AAEO,SAAS,iBAAkC;AAChD,SAAO,IAAI,gBAAgB;AAC7B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/contract-authoring",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.91.1",
|
|
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-pr.
|
|
9
|
+
"@prisma-next/contract": "0.3.0-pr.91.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@vitest/coverage-v8": "4.0.16",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"lint": "biome check . --error-on-warnings",
|
|
33
33
|
"lint:fix": "biome check --write .",
|
|
34
34
|
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
35
|
-
"clean": "
|
|
35
|
+
"clean": "rm -rf dist coverage .tmp-output"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/builder-state.ts
CHANGED
|
@@ -86,14 +86,6 @@ export interface ModelBuilderState<
|
|
|
86
86
|
readonly relations: Relations;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
/**
|
|
90
|
-
* Enum builder state containing the enum name and ordered list of values.
|
|
91
|
-
*/
|
|
92
|
-
export interface EnumBuilderState<Name extends string, Values extends readonly string[]> {
|
|
93
|
-
readonly name: Name;
|
|
94
|
-
readonly values: Values;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
89
|
export interface ContractBuilderState<
|
|
98
90
|
Target extends string | undefined = string | undefined,
|
|
99
91
|
Tables extends Record<
|
|
@@ -118,10 +110,6 @@ export interface ContractBuilderState<
|
|
|
118
110
|
never,
|
|
119
111
|
ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
|
|
120
112
|
>,
|
|
121
|
-
Enums extends Record<string, EnumBuilderState<string, readonly string[]>> = Record<
|
|
122
|
-
never,
|
|
123
|
-
EnumBuilderState<string, readonly string[]>
|
|
124
|
-
>,
|
|
125
113
|
CoreHash extends string | undefined = string | undefined,
|
|
126
114
|
ExtensionPacks extends Record<string, unknown> | undefined = undefined,
|
|
127
115
|
Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
@@ -129,7 +117,6 @@ export interface ContractBuilderState<
|
|
|
129
117
|
readonly target?: Target;
|
|
130
118
|
readonly tables: Tables;
|
|
131
119
|
readonly models: Models;
|
|
132
|
-
readonly enums: Enums;
|
|
133
120
|
readonly coreHash?: CoreHash;
|
|
134
121
|
readonly extensionPacks?: ExtensionPacks;
|
|
135
122
|
readonly capabilities?: Capabilities;
|
package/src/contract-builder.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { TargetPackRef } from '@prisma-next/contract/framework-components';
|
|
|
2
2
|
import type {
|
|
3
3
|
ColumnBuilderState,
|
|
4
4
|
ContractBuilderState,
|
|
5
|
-
EnumBuilderState,
|
|
6
5
|
ModelBuilderState,
|
|
7
6
|
RelationDefinition,
|
|
8
7
|
TableBuilderState,
|
|
@@ -24,7 +23,6 @@ export class ContractBuilder<
|
|
|
24
23
|
string,
|
|
25
24
|
ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>
|
|
26
25
|
> = Record<never, never>,
|
|
27
|
-
Enums extends Record<string, EnumBuilderState<string, readonly string[]>> = Record<never, never>,
|
|
28
26
|
CoreHash extends string | undefined = undefined,
|
|
29
27
|
ExtensionPacks extends Record<string, unknown> | undefined = undefined,
|
|
30
28
|
Capabilities extends Record<string, Record<string, boolean>> | undefined = undefined,
|
|
@@ -33,44 +31,26 @@ export class ContractBuilder<
|
|
|
33
31
|
Target,
|
|
34
32
|
Tables,
|
|
35
33
|
Models,
|
|
36
|
-
Enums,
|
|
37
34
|
CoreHash,
|
|
38
35
|
ExtensionPacks,
|
|
39
36
|
Capabilities
|
|
40
37
|
>;
|
|
41
38
|
|
|
42
39
|
constructor(
|
|
43
|
-
state?: ContractBuilderState<
|
|
44
|
-
Target,
|
|
45
|
-
Tables,
|
|
46
|
-
Models,
|
|
47
|
-
Enums,
|
|
48
|
-
CoreHash,
|
|
49
|
-
ExtensionPacks,
|
|
50
|
-
Capabilities
|
|
51
|
-
>,
|
|
40
|
+
state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>,
|
|
52
41
|
) {
|
|
53
42
|
this.state =
|
|
54
43
|
state ??
|
|
55
44
|
({
|
|
56
45
|
tables: {},
|
|
57
46
|
models: {},
|
|
58
|
-
|
|
59
|
-
} as ContractBuilderState<
|
|
60
|
-
Target,
|
|
61
|
-
Tables,
|
|
62
|
-
Models,
|
|
63
|
-
Enums,
|
|
64
|
-
CoreHash,
|
|
65
|
-
ExtensionPacks,
|
|
66
|
-
Capabilities
|
|
67
|
-
>);
|
|
47
|
+
} as ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);
|
|
68
48
|
}
|
|
69
49
|
|
|
70
50
|
target<T extends string>(
|
|
71
51
|
packRef: TargetPackRef<string, T>,
|
|
72
|
-
): ContractBuilder<T, Tables, Models,
|
|
73
|
-
return new ContractBuilder<T, Tables, Models,
|
|
52
|
+
): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities> {
|
|
53
|
+
return new ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities>({
|
|
74
54
|
...this.state,
|
|
75
55
|
target: packRef.targetId,
|
|
76
56
|
});
|
|
@@ -78,8 +58,8 @@ export class ContractBuilder<
|
|
|
78
58
|
|
|
79
59
|
capabilities<C extends Record<string, Record<string, boolean>>>(
|
|
80
60
|
capabilities: C,
|
|
81
|
-
): ContractBuilder<Target, Tables, Models,
|
|
82
|
-
return new ContractBuilder<Target, Tables, Models,
|
|
61
|
+
): ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C> {
|
|
62
|
+
return new ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C>({
|
|
83
63
|
...this.state,
|
|
84
64
|
capabilities,
|
|
85
65
|
});
|
|
@@ -99,7 +79,6 @@ export class ContractBuilder<
|
|
|
99
79
|
Target,
|
|
100
80
|
Tables & Record<TableName, ReturnType<T['build']>>,
|
|
101
81
|
Models,
|
|
102
|
-
Enums,
|
|
103
82
|
CoreHash,
|
|
104
83
|
ExtensionPacks,
|
|
105
84
|
Capabilities
|
|
@@ -113,7 +92,6 @@ export class ContractBuilder<
|
|
|
113
92
|
Target,
|
|
114
93
|
Tables & Record<TableName, ReturnType<T['build']>>,
|
|
115
94
|
Models,
|
|
116
|
-
Enums,
|
|
117
95
|
CoreHash,
|
|
118
96
|
ExtensionPacks,
|
|
119
97
|
Capabilities
|
|
@@ -143,7 +121,6 @@ export class ContractBuilder<
|
|
|
143
121
|
Target,
|
|
144
122
|
Tables,
|
|
145
123
|
Models & Record<ModelName, ReturnType<M['build']>>,
|
|
146
|
-
Enums,
|
|
147
124
|
CoreHash,
|
|
148
125
|
ExtensionPacks,
|
|
149
126
|
Capabilities
|
|
@@ -157,7 +134,6 @@ export class ContractBuilder<
|
|
|
157
134
|
Target,
|
|
158
135
|
Tables,
|
|
159
136
|
Models & Record<ModelName, ReturnType<M['build']>>,
|
|
160
|
-
Enums,
|
|
161
137
|
CoreHash,
|
|
162
138
|
ExtensionPacks,
|
|
163
139
|
Capabilities
|
|
@@ -168,47 +144,10 @@ export class ContractBuilder<
|
|
|
168
144
|
});
|
|
169
145
|
}
|
|
170
146
|
|
|
171
|
-
/**
|
|
172
|
-
* Define an enum type with ordered values.
|
|
173
|
-
* @param name The name of the enum type (e.g., 'Role', 'Status')
|
|
174
|
-
* @param values The ordered list of enum values (e.g., ['USER', 'ADMIN'])
|
|
175
|
-
*/
|
|
176
|
-
enum<EnumName extends string, Values extends readonly [string, ...string[]]>(
|
|
177
|
-
name: EnumName,
|
|
178
|
-
values: Values,
|
|
179
|
-
): ContractBuilder<
|
|
180
|
-
Target,
|
|
181
|
-
Tables,
|
|
182
|
-
Models,
|
|
183
|
-
Enums & Record<EnumName, EnumBuilderState<EnumName, Values>>,
|
|
184
|
-
CoreHash,
|
|
185
|
-
ExtensionPacks,
|
|
186
|
-
Capabilities
|
|
187
|
-
> {
|
|
188
|
-
const enumState: EnumBuilderState<EnumName, Values> = {
|
|
189
|
-
name,
|
|
190
|
-
values,
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
return new ContractBuilder<
|
|
194
|
-
Target,
|
|
195
|
-
Tables,
|
|
196
|
-
Models,
|
|
197
|
-
Enums & Record<EnumName, EnumBuilderState<EnumName, Values>>,
|
|
198
|
-
CoreHash,
|
|
199
|
-
ExtensionPacks,
|
|
200
|
-
Capabilities
|
|
201
|
-
>({
|
|
202
|
-
...this.state,
|
|
203
|
-
enums: { ...this.state.enums, [name]: enumState } as Enums &
|
|
204
|
-
Record<EnumName, EnumBuilderState<EnumName, Values>>,
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
147
|
coreHash<H extends string>(
|
|
209
148
|
hash: H,
|
|
210
|
-
): ContractBuilder<Target, Tables, Models,
|
|
211
|
-
return new ContractBuilder<Target, Tables, Models,
|
|
149
|
+
): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities> {
|
|
150
|
+
return new ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>({
|
|
212
151
|
...this.state,
|
|
213
152
|
coreHash: hash,
|
|
214
153
|
});
|