@prisma-next/contract-authoring 0.3.0-dev.9 → 0.3.0-pr.100.2

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.
@@ -1,21 +1,56 @@
1
1
  /**
2
2
  * Column type descriptor containing both codec ID and native type.
3
3
  * Used when defining columns with descriptor objects instead of string IDs.
4
+ *
5
+ * For parameterized types (e.g., `vector(1536)`), the `typeParams` field
6
+ * carries codec-owned parameters that affect both TypeScript type generation
7
+ * and native DDL output.
4
8
  */
5
9
  export type ColumnTypeDescriptor = {
6
10
  readonly codecId: string;
7
11
  readonly nativeType: string;
12
+ readonly typeParams?: Record<string, unknown>;
8
13
  };
9
14
  export interface ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> {
10
15
  readonly name: Name;
11
16
  readonly nullable: Nullable;
12
17
  readonly type: Type;
13
18
  readonly nativeType: string;
19
+ readonly typeParams?: Record<string, unknown>;
20
+ }
21
+ /**
22
+ * Unique constraint definition for table builder.
23
+ */
24
+ export interface UniqueConstraintDef {
25
+ readonly columns: readonly string[];
26
+ readonly name?: string;
27
+ }
28
+ /**
29
+ * Index definition for table builder.
30
+ */
31
+ export interface IndexDef {
32
+ readonly columns: readonly string[];
33
+ readonly name?: string;
34
+ }
35
+ /**
36
+ * Foreign key definition for table builder.
37
+ */
38
+ export interface ForeignKeyDef {
39
+ readonly columns: readonly string[];
40
+ readonly references: {
41
+ readonly table: string;
42
+ readonly columns: readonly string[];
43
+ };
44
+ readonly name?: string;
14
45
  }
15
46
  export interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
16
47
  readonly name: Name;
17
48
  readonly columns: Columns;
18
49
  readonly primaryKey?: PrimaryKey;
50
+ readonly primaryKeyName?: string;
51
+ readonly uniques: readonly UniqueConstraintDef[];
52
+ readonly indexes: readonly IndexDef[];
53
+ readonly foreignKeys: readonly ForeignKeyDef[];
19
54
  }
20
55
  export type RelationDefinition = {
21
56
  readonly to: string;
@@ -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,MAAM,WAAW,iBAAiB,CAChC,IAAI,SAAS,MAAM,EACnB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAC3E,UAAU,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS;IAEhD,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACpD,QAAQ,CAAC,EAAE,EAAE;QACX,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;QACvC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;KACvC,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,EA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AAE,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,6 +1,6 @@
1
- export type { ColumnBuilder, ColumnBuilderState, ColumnTypeDescriptor, ContractBuilderState, ModelBuilderState, RelationDefinition, TableBuilderState, } from './builder-state';
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
- export { TableBuilder } from './table-builder';
4
+ export { createTable, TableBuilder } from './table-builder';
5
5
  export type { BuildModelFields, BuildModels, BuildRelations, BuildStorage, BuildStorageColumn, BuildStorageTables, ExtractColumns, ExtractModelFields, ExtractModelRelations, ExtractPrimaryKey, Mutable, } from './types';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -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,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,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,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,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"}
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
@@ -74,47 +74,110 @@ var ModelBuilder = class _ModelBuilder {
74
74
  };
75
75
 
76
76
  // src/table-builder.ts
77
+ function createTable(name) {
78
+ return new TableBuilder(name, {}, void 0, void 0, [], [], []);
79
+ }
77
80
  var TableBuilder = class _TableBuilder {
78
- _name;
79
- _columns;
80
- _primaryKey;
81
- constructor(name, columns = {}, primaryKey) {
82
- this._name = name;
83
- this._columns = columns;
84
- this._primaryKey = primaryKey;
81
+ _state;
82
+ /** @internal Use createTable() instead */
83
+ constructor(name, columns, primaryKey, primaryKeyName, uniques, indexes, foreignKeys) {
84
+ this._state = {
85
+ name,
86
+ columns,
87
+ primaryKey,
88
+ primaryKeyName,
89
+ uniques,
90
+ indexes,
91
+ foreignKeys
92
+ };
93
+ }
94
+ get _name() {
95
+ return this._state.name;
96
+ }
97
+ get _columns() {
98
+ return this._state.columns;
99
+ }
100
+ get _primaryKey() {
101
+ return this._state.primaryKey;
85
102
  }
86
103
  column(name, options) {
87
104
  const nullable = options.nullable ?? false;
88
- const { codecId, nativeType } = options.type;
105
+ const { codecId, nativeType, typeParams: descriptorTypeParams } = options.type;
106
+ const typeParams = options.typeParams ?? descriptorTypeParams;
89
107
  const columnState = {
90
108
  name,
91
109
  nullable,
92
110
  type: codecId,
93
- nativeType
111
+ nativeType,
112
+ ...typeParams ? { typeParams } : {}
94
113
  };
114
+ const newColumns = { ...this._columns, [name]: columnState };
95
115
  return new _TableBuilder(
96
- this._name,
97
- { ...this._columns, [name]: columnState },
98
- this._primaryKey
116
+ this._state.name,
117
+ newColumns,
118
+ this._state.primaryKey,
119
+ this._state.primaryKeyName,
120
+ this._state.uniques,
121
+ this._state.indexes,
122
+ this._state.foreignKeys
99
123
  );
100
124
  }
101
- primaryKey(columns, _name) {
102
- return new _TableBuilder(this._name, this._columns, columns);
125
+ primaryKey(columns, name) {
126
+ return new _TableBuilder(
127
+ this._state.name,
128
+ this._state.columns,
129
+ columns,
130
+ name,
131
+ this._state.uniques,
132
+ this._state.indexes,
133
+ this._state.foreignKeys
134
+ );
103
135
  }
104
- unique(_columns, _name) {
105
- return this;
136
+ unique(columns, name) {
137
+ const constraint = name ? { columns, name } : { columns };
138
+ return new _TableBuilder(
139
+ this._state.name,
140
+ this._state.columns,
141
+ this._state.primaryKey,
142
+ this._state.primaryKeyName,
143
+ [...this._state.uniques, constraint],
144
+ this._state.indexes,
145
+ this._state.foreignKeys
146
+ );
106
147
  }
107
- index(_columns, _name) {
108
- return this;
148
+ index(columns, name) {
149
+ const indexDef = name ? { columns, name } : { columns };
150
+ return new _TableBuilder(
151
+ this._state.name,
152
+ this._state.columns,
153
+ this._state.primaryKey,
154
+ this._state.primaryKeyName,
155
+ this._state.uniques,
156
+ [...this._state.indexes, indexDef],
157
+ this._state.foreignKeys
158
+ );
109
159
  }
110
- foreignKey(_columns, _references, _name) {
111
- return this;
160
+ foreignKey(columns, references, name) {
161
+ const fkDef = name ? { columns, references, name } : { columns, references };
162
+ return new _TableBuilder(
163
+ this._state.name,
164
+ this._state.columns,
165
+ this._state.primaryKey,
166
+ this._state.primaryKeyName,
167
+ this._state.uniques,
168
+ this._state.indexes,
169
+ [...this._state.foreignKeys, fkDef]
170
+ );
112
171
  }
113
172
  build() {
114
173
  return {
115
174
  name: this._name,
116
175
  columns: this._columns,
117
- ...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {}
176
+ ...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {},
177
+ ...this._state.primaryKeyName !== void 0 ? { primaryKeyName: this._state.primaryKeyName } : {},
178
+ uniques: this._state.uniques,
179
+ indexes: this._state.indexes,
180
+ foreignKeys: this._state.foreignKeys
118
181
  };
119
182
  }
120
183
  };
@@ -141,7 +204,7 @@ var ContractBuilder = class _ContractBuilder {
141
204
  });
142
205
  }
143
206
  table(name, callback) {
144
- const tableBuilder = new TableBuilder(name);
207
+ const tableBuilder = createTable(name);
145
208
  const result = callback(tableBuilder);
146
209
  const finalBuilder = result instanceof TableBuilder ? result : tableBuilder;
147
210
  const tableState = finalBuilder.build();
@@ -174,6 +237,7 @@ export {
174
237
  ContractBuilder,
175
238
  ModelBuilder,
176
239
  TableBuilder,
240
+ createTable,
177
241
  defineContract
178
242
  };
179
243
  //# sourceMappingURL=index.js.map
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 { ColumnBuilderState, ColumnTypeDescriptor, TableBuilderState } from './builder-state';\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 _name: Name;\n private readonly _columns: Columns;\n private readonly _primaryKey: PrimaryKey;\n\n constructor(name: Name, columns: Columns = {} as Columns, primaryKey?: PrimaryKey) {\n this._name = name;\n this._columns = columns;\n this._primaryKey = primaryKey as 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 return new TableBuilder(\n this._name,\n { ...this._columns, [name]: columnState } as Columns &\n Record<\n ColName,\n ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>\n >,\n this._primaryKey,\n );\n }\n\n primaryKey<PK extends readonly string[]>(\n columns: PK,\n _name?: string,\n ): TableBuilder<Name, Columns, PK> {\n return new TableBuilder(this._name, this._columns, columns);\n }\n\n unique(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey> {\n return this;\n }\n\n index(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey> {\n return this;\n }\n\n foreignKey(\n _columns: readonly string[],\n _references: { table: string; columns: readonly string[] },\n _name?: string,\n ): TableBuilder<Name, Columns, PrimaryKey> {\n return this;\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 } 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 { 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 = new TableBuilder<TableName>(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;A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I,iBAAyE;AAAA,MAClF,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 typeParams?: Record<string, unknown>;\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, typeParams: descriptorTypeParams } = options.type;\n const typeParams = options.typeParams ?? descriptorTypeParams;\n\n const columnState = {\n name,\n nullable,\n type: codecId,\n nativeType,\n ...(typeParams ? { typeParams } : {}),\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,IAAI;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,QACE,GAAG,KAAK;AAAA,QACR,CAAC,SAAS,GAAG;AAAA,MACf;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAwCA,SAME,MACA,SAgByF;AAEzF,QAAI,QAAQ,GAAG,gBAAgB,KAAK,QAAQ;AAC1C,YAAM,IAAI;AAAA,QACR,aAAa,IAAI,kBAAkB,QAAQ,GAAG,WAAW,iCAAiC,KAAK,MAAM;AAAA,MACvG;AAAA,IACF;AAGA,QAAI,QAAQ,gBAAgB,OAAO;AACjC,UAAI,CAAC,QAAQ,SAAS;AACpB,cAAM,IAAI,MAAM,aAAa,IAAI,iDAAiD;AAAA,MACpF;AACA,UAAI,QAAQ,GAAG,eAAe,QAAQ,QAAQ,OAAO;AACnD,cAAM,IAAI;AAAA,UACR,aAAa,IAAI,iBAAiB,QAAQ,GAAG,UAAU,mCAAmC,QAAQ,QAAQ,KAAK;AAAA,QACjH;AAAA,MACF;AAAA,IACF,OAAO;AACL,UAAI,QAA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AClB,CAAC;AAAA,EACH;AAAA,EAEA,aACE,cACsE;AACtE,WAAO,IAAI,iBAAqE;AAAA,MAC9E,GAAG,KAAK;AAAA,MACR;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAQE,MACA,UAQA;AACA,UAAM,eAAe,YAAY,IAAI;AACrC,UAAM,SAAS,SAAS,YAAY;AACpC,UAAM,eAAe,kBAAkB,eAAe,SAAS;AAC/D,UAAM,aAAa,aAAa,MAAM;AAEtC,WAAO,IAAI,iBAOT;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,UAUA;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,iBAOT;AAAA,MACA,GAAG,KAAK;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":[]}
@@ -1,20 +1,33 @@
1
- import type { ColumnBuilderState, ColumnTypeDescriptor, TableBuilderState } from './builder-state';
1
+ import type { ColumnBuilderState, ColumnTypeDescriptor, ForeignKeyDef, IndexDef, TableBuilderState, UniqueConstraintDef } from './builder-state';
2
+ /**
3
+ * Creates a new table builder with the given name.
4
+ * This is the preferred way to create a TableBuilder - it ensures
5
+ * type parameters are inferred correctly without unsafe casts.
6
+ */
7
+ export declare function createTable<Name extends string>(name: Name): TableBuilder<Name>;
8
+ /**
9
+ * Builder for defining table structure with type-safe chaining.
10
+ * Use `createTable(name)` to create instances.
11
+ */
2
12
  export 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> {
3
- private readonly _name;
4
- private readonly _columns;
5
- private readonly _primaryKey;
6
- constructor(name: Name, columns?: Columns, primaryKey?: PrimaryKey);
13
+ private readonly _state;
14
+ /** @internal Use createTable() instead */
15
+ constructor(name: Name, columns: Columns, primaryKey: PrimaryKey, primaryKeyName: string | undefined, uniques: readonly UniqueConstraintDef[], indexes: readonly IndexDef[], foreignKeys: readonly ForeignKeyDef[]);
16
+ private get _name();
17
+ private get _columns();
18
+ private get _primaryKey();
7
19
  column<ColName extends string, Descriptor extends ColumnTypeDescriptor, Nullable extends boolean | undefined = undefined>(name: ColName, options: {
8
20
  type: Descriptor;
9
21
  nullable?: Nullable;
22
+ typeParams?: Record<string, unknown>;
10
23
  }): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>>, PrimaryKey>;
11
- primaryKey<PK extends readonly string[]>(columns: PK, _name?: string): TableBuilder<Name, Columns, PK>;
12
- unique(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
13
- index(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
14
- foreignKey(_columns: readonly string[], _references: {
24
+ primaryKey<PK extends readonly string[]>(columns: PK, name?: string): TableBuilder<Name, Columns, PK>;
25
+ unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
26
+ index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
27
+ foreignKey(columns: readonly string[], references: {
15
28
  table: string;
16
29
  columns: readonly string[];
17
- }, _name?: string): TableBuilder<Name, Columns, PrimaryKey>;
30
+ }, name?: string): TableBuilder<Name, Columns, PrimaryKey>;
18
31
  build(): TableBuilderState<Name, Columns, PrimaryKey>;
19
32
  }
20
33
  //# sourceMappingURL=table-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"table-builder.d.ts","sourceRoot":"","sources":["../src/table-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEnG,qBAAa,YAAY,CACvB,IAAI,SAAS,MAAM,EACnB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAClF,KAAK,EACL,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAC5C,EACD,UAAU,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,SAAS;IAE5D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;gBAE7B,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,OAAuB,EAAE,UAAU,CAAC,EAAE,UAAU;IAMjF,MAAM,CACJ,OAAO,SAAS,MAAM,EACtB,UAAU,SAAS,oBAAoB,EACvC,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EAEhD,IAAI,EAAE,OAAO,EACb,OAAO,EAAE;QACP,IAAI,EAAE,UAAU,CAAC;QACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACrB,GACA,YAAY,CACb,IAAI,EACJ,OAAO,GACL,MAAM,CACJ,OAAO,EACP,kBAAkB,CAAC,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,CACzF,EACH,UAAU,CACX;IAqBD,UAAU,CAAC,EAA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MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAC9F,IACC;IACF,QAAQ,EAAE,CAAC,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;CACrF,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@prisma-next/contract-authoring",
3
- "version": "0.3.0-dev.9",
3
+ "version": "0.3.0-pr.100.2",
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.9"
9
+ "@prisma-next/contract": "0.3.0-pr.100.2"
10
10
  },
11
11
  "devDependencies": {
12
- "@vitest/coverage-v8": "4.0.16",
13
12
  "tsup": "8.5.1",
14
13
  "typescript": "5.9.3",
15
- "vitest": "4.0.16"
14
+ "vitest": "4.0.16",
15
+ "@prisma-next/tsconfig": "0.0.0"
16
16
  },
17
17
  "files": [
18
18
  "dist",
@@ -29,9 +29,9 @@
29
29
  "test": "vitest run",
30
30
  "test:coverage": "vitest run --coverage",
31
31
  "typecheck": "tsc --project tsconfig.json --noEmit",
32
- "lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
33
- "lint:fix": "biome check --write . --config-path ../../../../biome.json",
34
- "lint:fix:unsafe": "biome check --write --unsafe . --config-path ../../../../biome.json",
35
- "clean": "node ../../../../scripts/clean.mjs"
32
+ "lint": "biome check . --error-on-warnings",
33
+ "lint:fix": "biome check --write .",
34
+ "lint:fix:unsafe": "biome check --write --unsafe .",
35
+ "clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
36
36
  }
37
37
  }
@@ -1,10 +1,15 @@
1
1
  /**
2
2
  * Column type descriptor containing both codec ID and native type.
3
3
  * Used when defining columns with descriptor objects instead of string IDs.
4
+ *
5
+ * For parameterized types (e.g., `vector(1536)`), the `typeParams` field
6
+ * carries codec-owned parameters that affect both TypeScript type generation
7
+ * and native DDL output.
4
8
  */
5
9
  export type ColumnTypeDescriptor = {
6
10
  readonly codecId: string;
7
11
  readonly nativeType: string;
12
+ readonly typeParams?: Record<string, unknown>;
8
13
  };
9
14
 
10
15
  export interface ColumnBuilderState<
@@ -16,6 +21,35 @@ export interface ColumnBuilderState<
16
21
  readonly nullable: Nullable;
17
22
  readonly type: Type;
18
23
  readonly nativeType: string;
24
+ readonly typeParams?: Record<string, unknown>;
25
+ }
26
+
27
+ /**
28
+ * Unique constraint definition for table builder.
29
+ */
30
+ export interface UniqueConstraintDef {
31
+ readonly columns: readonly string[];
32
+ readonly name?: string;
33
+ }
34
+
35
+ /**
36
+ * Index definition for table builder.
37
+ */
38
+ export interface IndexDef {
39
+ readonly columns: readonly string[];
40
+ readonly name?: string;
41
+ }
42
+
43
+ /**
44
+ * Foreign key definition for table builder.
45
+ */
46
+ export interface ForeignKeyDef {
47
+ readonly columns: readonly string[];
48
+ readonly references: {
49
+ readonly table: string;
50
+ readonly columns: readonly string[];
51
+ };
52
+ readonly name?: string;
19
53
  }
20
54
 
21
55
  export interface TableBuilderState<
@@ -26,6 +60,10 @@ export interface TableBuilderState<
26
60
  readonly name: Name;
27
61
  readonly columns: Columns;
28
62
  readonly primaryKey?: PrimaryKey;
63
+ readonly primaryKeyName?: string;
64
+ readonly uniques: readonly UniqueConstraintDef[];
65
+ readonly indexes: readonly IndexDef[];
66
+ readonly foreignKeys: readonly ForeignKeyDef[];
29
67
  }
30
68
 
31
69
  export type RelationDefinition = {
@@ -7,7 +7,7 @@ import type {
7
7
  TableBuilderState,
8
8
  } from './builder-state';
9
9
  import { ModelBuilder } from './model-builder';
10
- import { TableBuilder } from './table-builder';
10
+ import { createTable, TableBuilder } from './table-builder';
11
11
 
12
12
  export class ContractBuilder<
13
13
  Target extends string | undefined = undefined,
@@ -83,7 +83,7 @@ export class ContractBuilder<
83
83
  ExtensionPacks,
84
84
  Capabilities
85
85
  > {
86
- const tableBuilder = new TableBuilder<TableName>(name);
86
+ const tableBuilder = createTable(name);
87
87
  const result = callback(tableBuilder);
88
88
  const finalBuilder = result instanceof TableBuilder ? result : tableBuilder;
89
89
  const tableState = finalBuilder.build();
package/src/index.ts CHANGED
@@ -3,14 +3,17 @@ export type {
3
3
  ColumnBuilderState,
4
4
  ColumnTypeDescriptor,
5
5
  ContractBuilderState,
6
+ ForeignKeyDef,
7
+ IndexDef,
6
8
  ModelBuilderState,
7
9
  RelationDefinition,
8
10
  TableBuilderState,
11
+ UniqueConstraintDef,
9
12
  } from './builder-state';
10
13
 
11
14
  export { ContractBuilder, defineContract } from './contract-builder';
12
15
  export { ModelBuilder } from './model-builder';
13
- export { TableBuilder } from './table-builder';
16
+ export { createTable, TableBuilder } from './table-builder';
14
17
 
15
18
  export type {
16
19
  BuildModelFields,
@@ -1,5 +1,39 @@
1
- import type { ColumnBuilderState, ColumnTypeDescriptor, TableBuilderState } from './builder-state';
1
+ import type {
2
+ ColumnBuilderState,
3
+ ColumnTypeDescriptor,
4
+ ForeignKeyDef,
5
+ IndexDef,
6
+ TableBuilderState,
7
+ UniqueConstraintDef,
8
+ } from './builder-state';
2
9
 
10
+ interface TableBuilderInternalState<
11
+ Name extends string,
12
+ Columns extends Record<string, ColumnBuilderState<string, boolean, string>>,
13
+ PrimaryKey extends readonly string[] | undefined,
14
+ > {
15
+ readonly name: Name;
16
+ readonly columns: Columns;
17
+ readonly primaryKey: PrimaryKey;
18
+ readonly primaryKeyName: string | undefined;
19
+ readonly uniques: readonly UniqueConstraintDef[];
20
+ readonly indexes: readonly IndexDef[];
21
+ readonly foreignKeys: readonly ForeignKeyDef[];
22
+ }
23
+
24
+ /**
25
+ * Creates a new table builder with the given name.
26
+ * This is the preferred way to create a TableBuilder - it ensures
27
+ * type parameters are inferred correctly without unsafe casts.
28
+ */
29
+ export function createTable<Name extends string>(name: Name): TableBuilder<Name> {
30
+ return new TableBuilder(name, {}, undefined, undefined, [], [], []);
31
+ }
32
+
33
+ /**
34
+ * Builder for defining table structure with type-safe chaining.
35
+ * Use `createTable(name)` to create instances.
36
+ */
3
37
  export class TableBuilder<
4
38
  Name extends string,
5
39
  Columns extends Record<string, ColumnBuilderState<string, boolean, string>> = Record<
@@ -8,14 +42,39 @@ export class TableBuilder<
8
42
  >,
9
43
  PrimaryKey extends readonly string[] | undefined = undefined,
10
44
  > {
11
- private readonly _name: Name;
12
- private readonly _columns: Columns;
13
- private readonly _primaryKey: PrimaryKey;
45
+ private readonly _state: TableBuilderInternalState<Name, Columns, PrimaryKey>;
46
+
47
+ /** @internal Use createTable() instead */
48
+ constructor(
49
+ name: Name,
50
+ columns: Columns,
51
+ primaryKey: PrimaryKey,
52
+ primaryKeyName: string | undefined,
53
+ uniques: readonly UniqueConstraintDef[],
54
+ indexes: readonly IndexDef[],
55
+ foreignKeys: readonly ForeignKeyDef[],
56
+ ) {
57
+ this._state = {
58
+ name,
59
+ columns,
60
+ primaryKey,
61
+ primaryKeyName,
62
+ uniques,
63
+ indexes,
64
+ foreignKeys,
65
+ };
66
+ }
67
+
68
+ private get _name(): Name {
69
+ return this._state.name;
70
+ }
71
+
72
+ private get _columns(): Columns {
73
+ return this._state.columns;
74
+ }
14
75
 
15
- constructor(name: Name, columns: Columns = {} as Columns, primaryKey?: PrimaryKey) {
16
- this._name = name;
17
- this._columns = columns;
18
- this._primaryKey = primaryKey as PrimaryKey;
76
+ private get _primaryKey(): PrimaryKey {
77
+ return this._state.primaryKey;
19
78
  }
20
79
 
21
80
  column<
@@ -27,6 +86,7 @@ export class TableBuilder<
27
86
  options: {
28
87
  type: Descriptor;
29
88
  nullable?: Nullable;
89
+ typeParams?: Record<string, unknown>;
30
90
  },
31
91
  ): TableBuilder<
32
92
  Name,
@@ -38,46 +98,88 @@ export class TableBuilder<
38
98
  PrimaryKey
39
99
  > {
40
100
  const nullable = (options.nullable ?? false) as Nullable extends true ? true : false;
41
- const { codecId, nativeType } = options.type;
101
+ const { codecId, nativeType, typeParams: descriptorTypeParams } = options.type;
102
+ const typeParams = options.typeParams ?? descriptorTypeParams;
42
103
 
43
104
  const columnState = {
44
105
  name,
45
106
  nullable,
46
107
  type: codecId,
47
108
  nativeType,
109
+ ...(typeParams ? { typeParams } : {}),
48
110
  } as ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>;
111
+ const newColumns = { ...this._columns, [name]: columnState } as Columns &
112
+ Record<
113
+ ColName,
114
+ ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>
115
+ >;
49
116
  return new TableBuilder(
50
- this._name,
51
- { ...this._columns, [name]: columnState } as Columns &
52
- Record<
53
- ColName,
54
- ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>
55
- >,
56
- this._primaryKey,
117
+ this._state.name,
118
+ newColumns,
119
+ this._state.primaryKey,
120
+ this._state.primaryKeyName,
121
+ this._state.uniques,
122
+ this._state.indexes,
123
+ this._state.foreignKeys,
57
124
  );
58
125
  }
59
126
 
60
127
  primaryKey<PK extends readonly string[]>(
61
128
  columns: PK,
62
- _name?: string,
129
+ name?: string,
63
130
  ): TableBuilder<Name, Columns, PK> {
64
- return new TableBuilder(this._name, this._columns, columns);
131
+ return new TableBuilder(
132
+ this._state.name,
133
+ this._state.columns,
134
+ columns,
135
+ name,
136
+ this._state.uniques,
137
+ this._state.indexes,
138
+ this._state.foreignKeys,
139
+ );
65
140
  }
66
141
 
67
- unique(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey> {
68
- return this;
142
+ unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {
143
+ const constraint: UniqueConstraintDef = name ? { columns, name } : { columns };
144
+ return new TableBuilder(
145
+ this._state.name,
146
+ this._state.columns,
147
+ this._state.primaryKey,
148
+ this._state.primaryKeyName,
149
+ [...this._state.uniques, constraint],
150
+ this._state.indexes,
151
+ this._state.foreignKeys,
152
+ );
69
153
  }
70
154
 
71
- index(_columns: readonly string[], _name?: string): TableBuilder<Name, Columns, PrimaryKey> {
72
- return this;
155
+ index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey> {
156
+ const indexDef: IndexDef = name ? { columns, name } : { columns };
157
+ return new TableBuilder(
158
+ this._state.name,
159
+ this._state.columns,
160
+ this._state.primaryKey,
161
+ this._state.primaryKeyName,
162
+ this._state.uniques,
163
+ [...this._state.indexes, indexDef],
164
+ this._state.foreignKeys,
165
+ );
73
166
  }
74
167
 
75
168
  foreignKey(
76
- _columns: readonly string[],
77
- _references: { table: string; columns: readonly string[] },
78
- _name?: string,
169
+ columns: readonly string[],
170
+ references: { table: string; columns: readonly string[] },
171
+ name?: string,
79
172
  ): TableBuilder<Name, Columns, PrimaryKey> {
80
- return this;
173
+ const fkDef: ForeignKeyDef = name ? { columns, references, name } : { columns, references };
174
+ return new TableBuilder(
175
+ this._state.name,
176
+ this._state.columns,
177
+ this._state.primaryKey,
178
+ this._state.primaryKeyName,
179
+ this._state.uniques,
180
+ this._state.indexes,
181
+ [...this._state.foreignKeys, fkDef],
182
+ );
81
183
  }
82
184
 
83
185
  build(): TableBuilderState<Name, Columns, PrimaryKey> {
@@ -85,6 +187,12 @@ export class TableBuilder<
85
187
  name: this._name,
86
188
  columns: this._columns,
87
189
  ...(this._primaryKey !== undefined ? { primaryKey: this._primaryKey } : {}),
190
+ ...(this._state.primaryKeyName !== undefined
191
+ ? { primaryKeyName: this._state.primaryKeyName }
192
+ : {}),
193
+ uniques: this._state.uniques,
194
+ indexes: this._state.indexes,
195
+ foreignKeys: this._state.foreignKeys,
88
196
  } as TableBuilderState<Name, Columns, PrimaryKey>;
89
197
  }
90
198
  }
package/src/types.ts CHANGED
@@ -25,13 +25,14 @@ export type ExtractPrimaryKey<
25
25
  Record<string, ColumnBuilderState<string, boolean, string>>,
26
26
  readonly string[] | undefined
27
27
  >,
28
- > = T extends TableBuilderState<
29
- string,
30
- Record<string, ColumnBuilderState<string, boolean, string>>,
31
- infer PK
32
- >
33
- ? PK
34
- : never;
28
+ > =
29
+ T extends TableBuilderState<
30
+ string,
31
+ Record<string, ColumnBuilderState<string, boolean, string>>,
32
+ infer PK
33
+ >
34
+ ? PK
35
+ : never;
35
36
 
36
37
  export type BuildStorage<
37
38
  Tables extends Record<
@@ -92,9 +93,10 @@ export type ExtractModelFields<
92
93
  Record<string, string>,
93
94
  Record<string, RelationDefinition>
94
95
  >,
95
- > = T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>>
96
- ? F
97
- : never;
96
+ > =
97
+ T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>>
98
+ ? F
99
+ : never;
98
100
 
99
101
  export type ExtractModelRelations<
100
102
  T extends ModelBuilderState<