@prisma-next/contract-authoring 0.3.0-pr.94.3 → 0.3.0-pr.95.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.
- package/dist/builder-state.d.ts +89 -0
- package/dist/builder-state.d.ts.map +1 -0
- package/dist/contract-builder.d.ts +15 -0
- package/dist/contract-builder.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +241 -0
- package/dist/index.js.map +1 -0
- package/dist/model-builder.d.ts +38 -0
- package/dist/model-builder.d.ts.map +1 -0
- package/dist/table-builder.d.ts +32 -0
- package/dist/table-builder.d.ts.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +10 -15
- package/dist/index.d.mts +0 -207
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -205
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column type descriptor containing both codec ID and native type.
|
|
3
|
+
* Used when defining columns with descriptor objects instead of string IDs.
|
|
4
|
+
*/
|
|
5
|
+
export type ColumnTypeDescriptor = {
|
|
6
|
+
readonly codecId: string;
|
|
7
|
+
readonly nativeType: string;
|
|
8
|
+
};
|
|
9
|
+
export interface ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> {
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
readonly nullable: Nullable;
|
|
12
|
+
readonly type: Type;
|
|
13
|
+
readonly nativeType: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Unique constraint definition for table builder.
|
|
17
|
+
*/
|
|
18
|
+
export interface UniqueConstraintDef {
|
|
19
|
+
readonly columns: readonly string[];
|
|
20
|
+
readonly name?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Index definition for table builder.
|
|
24
|
+
*/
|
|
25
|
+
export interface IndexDef {
|
|
26
|
+
readonly columns: readonly string[];
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Foreign key definition for table builder.
|
|
31
|
+
*/
|
|
32
|
+
export interface ForeignKeyDef {
|
|
33
|
+
readonly columns: readonly string[];
|
|
34
|
+
readonly references: {
|
|
35
|
+
readonly table: string;
|
|
36
|
+
readonly columns: readonly string[];
|
|
37
|
+
};
|
|
38
|
+
readonly name?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
|
|
41
|
+
readonly name: Name;
|
|
42
|
+
readonly columns: Columns;
|
|
43
|
+
readonly primaryKey?: PrimaryKey;
|
|
44
|
+
readonly primaryKeyName?: string;
|
|
45
|
+
readonly uniques: readonly UniqueConstraintDef[];
|
|
46
|
+
readonly indexes: readonly IndexDef[];
|
|
47
|
+
readonly foreignKeys: readonly ForeignKeyDef[];
|
|
48
|
+
}
|
|
49
|
+
export type RelationDefinition = {
|
|
50
|
+
readonly to: string;
|
|
51
|
+
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
52
|
+
readonly on: {
|
|
53
|
+
readonly parentCols: readonly string[];
|
|
54
|
+
readonly childCols: readonly string[];
|
|
55
|
+
};
|
|
56
|
+
readonly through?: {
|
|
57
|
+
readonly table: string;
|
|
58
|
+
readonly parentCols: readonly string[];
|
|
59
|
+
readonly childCols: readonly string[];
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
|
|
63
|
+
readonly name: Name;
|
|
64
|
+
readonly table: Table;
|
|
65
|
+
readonly fields: Fields;
|
|
66
|
+
readonly relations: Relations;
|
|
67
|
+
}
|
|
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> {
|
|
69
|
+
readonly target?: Target;
|
|
70
|
+
readonly tables: Tables;
|
|
71
|
+
readonly models: Models;
|
|
72
|
+
readonly coreHash?: CoreHash;
|
|
73
|
+
readonly extensionPacks?: ExtensionPacks;
|
|
74
|
+
readonly capabilities?: Capabilities;
|
|
75
|
+
/**
|
|
76
|
+
* Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
|
|
77
|
+
* Populated when extension packs are registered during contract building.
|
|
78
|
+
* Used to track which extension packs are included in the contract.
|
|
79
|
+
* Can be undefined or empty if no extension packs are registered.
|
|
80
|
+
* Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
|
|
81
|
+
*/
|
|
82
|
+
readonly extensionNamespaces?: readonly string[];
|
|
83
|
+
}
|
|
84
|
+
export interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
|
|
85
|
+
nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
|
|
86
|
+
type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
|
|
87
|
+
build(): ColumnBuilderState<Name, Nullable, Type>;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=builder-state.d.ts.map
|
|
@@ -0,0 +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;IACz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C;IACrC;;;;;;OAMG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClD;AAED,MAAM,WAAW,aAAa,CAAC,IAAI,SAAS,MAAM,EAAE,QAAQ,SAAS,OAAO,EAAE,IAAI,SAAS,MAAM;IAC/F,QAAQ,CAAC,KAAK,SAAS,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACjF,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IACnE,KAAK,IAAI,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TargetPackRef } from '@prisma-next/contract/framework-components';
|
|
2
|
+
import type { ColumnBuilderState, ContractBuilderState, ModelBuilderState, RelationDefinition, TableBuilderState } from './builder-state';
|
|
3
|
+
import { ModelBuilder } from './model-builder';
|
|
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>, 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>;
|
|
13
|
+
}
|
|
14
|
+
export declare function defineContract(): ContractBuilder;
|
|
15
|
+
//# sourceMappingURL=contract-builder.d.ts.map
|
|
@@ -0,0 +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,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,C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,CAAC;CAM5E;AAED,wBAAgB,cAAc,IAAI,eAAe,CAEhD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { ColumnBuilder, ColumnBuilderState, ColumnTypeDescriptor, ContractBuilderState, ForeignKeyDef, IndexDef, ModelBuilderState, RelationDefinition, TableBuilderState, UniqueConstraintDef, } from './builder-state';
|
|
2
|
+
export { ContractBuilder, defineContract } from './contract-builder';
|
|
3
|
+
export { ModelBuilder } from './model-builder';
|
|
4
|
+
export { createTable, TableBuilder } from './table-builder';
|
|
5
|
+
export type { BuildModelFields, BuildModels, BuildRelations, BuildStorage, BuildStorageColumn, BuildStorageTables, ExtractColumns, ExtractModelFields, ExtractModelRelations, ExtractPrimaryKey, Mutable, } from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,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
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// src/model-builder.ts
|
|
2
|
+
var ModelBuilder = class _ModelBuilder {
|
|
3
|
+
_name;
|
|
4
|
+
_table;
|
|
5
|
+
_fields;
|
|
6
|
+
_relations;
|
|
7
|
+
constructor(name, table, fields = {}, relations = {}) {
|
|
8
|
+
this._name = name;
|
|
9
|
+
this._table = table;
|
|
10
|
+
this._fields = fields;
|
|
11
|
+
this._relations = relations;
|
|
12
|
+
}
|
|
13
|
+
field(fieldName, columnName) {
|
|
14
|
+
return new _ModelBuilder(
|
|
15
|
+
this._name,
|
|
16
|
+
this._table,
|
|
17
|
+
{
|
|
18
|
+
...this._fields,
|
|
19
|
+
[fieldName]: columnName
|
|
20
|
+
},
|
|
21
|
+
this._relations
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
relation(name, options) {
|
|
25
|
+
if (options.on.parentTable !== this._table) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Relation "${name}" parentTable "${options.on.parentTable}" does not match model table "${this._table}"`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (options.cardinality === "N:M") {
|
|
31
|
+
if (!options.through) {
|
|
32
|
+
throw new Error(`Relation "${name}" with cardinality "N:M" requires through field`);
|
|
33
|
+
}
|
|
34
|
+
if (options.on.childTable !== options.through.table) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Relation "${name}" childTable "${options.on.childTable}" does not match through.table "${options.through.table}"`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
if (options.on.childTable !== options.toTable) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Relation "${name}" childTable "${options.on.childTable}" does not match toTable "${options.toTable}"`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const relationDef = {
|
|
47
|
+
to: options.toModel,
|
|
48
|
+
cardinality: options.cardinality,
|
|
49
|
+
on: {
|
|
50
|
+
parentCols: options.on.parentColumns,
|
|
51
|
+
childCols: options.on.childColumns
|
|
52
|
+
},
|
|
53
|
+
...options.through ? {
|
|
54
|
+
through: {
|
|
55
|
+
table: options.through.table,
|
|
56
|
+
parentCols: options.through.parentColumns,
|
|
57
|
+
childCols: options.through.childColumns
|
|
58
|
+
}
|
|
59
|
+
} : void 0
|
|
60
|
+
};
|
|
61
|
+
return new _ModelBuilder(this._name, this._table, this._fields, {
|
|
62
|
+
...this._relations,
|
|
63
|
+
[name]: relationDef
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
build() {
|
|
67
|
+
return {
|
|
68
|
+
name: this._name,
|
|
69
|
+
table: this._table,
|
|
70
|
+
fields: this._fields,
|
|
71
|
+
relations: this._relations
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/table-builder.ts
|
|
77
|
+
function createTable(name) {
|
|
78
|
+
return new TableBuilder(name, {}, void 0, void 0, [], [], []);
|
|
79
|
+
}
|
|
80
|
+
var TableBuilder = class _TableBuilder {
|
|
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;
|
|
102
|
+
}
|
|
103
|
+
column(name, options) {
|
|
104
|
+
const nullable = options.nullable ?? false;
|
|
105
|
+
const { codecId, nativeType } = options.type;
|
|
106
|
+
const columnState = {
|
|
107
|
+
name,
|
|
108
|
+
nullable,
|
|
109
|
+
type: codecId,
|
|
110
|
+
nativeType
|
|
111
|
+
};
|
|
112
|
+
const newColumns = { ...this._columns, [name]: columnState };
|
|
113
|
+
return new _TableBuilder(
|
|
114
|
+
this._state.name,
|
|
115
|
+
newColumns,
|
|
116
|
+
this._state.primaryKey,
|
|
117
|
+
this._state.primaryKeyName,
|
|
118
|
+
this._state.uniques,
|
|
119
|
+
this._state.indexes,
|
|
120
|
+
this._state.foreignKeys
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
primaryKey(columns, name) {
|
|
124
|
+
return new _TableBuilder(
|
|
125
|
+
this._state.name,
|
|
126
|
+
this._state.columns,
|
|
127
|
+
columns,
|
|
128
|
+
name,
|
|
129
|
+
this._state.uniques,
|
|
130
|
+
this._state.indexes,
|
|
131
|
+
this._state.foreignKeys
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
unique(columns, name) {
|
|
135
|
+
const constraint = name ? { columns, name } : { columns };
|
|
136
|
+
return new _TableBuilder(
|
|
137
|
+
this._state.name,
|
|
138
|
+
this._state.columns,
|
|
139
|
+
this._state.primaryKey,
|
|
140
|
+
this._state.primaryKeyName,
|
|
141
|
+
[...this._state.uniques, constraint],
|
|
142
|
+
this._state.indexes,
|
|
143
|
+
this._state.foreignKeys
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
index(columns, name) {
|
|
147
|
+
const indexDef = name ? { columns, name } : { columns };
|
|
148
|
+
return new _TableBuilder(
|
|
149
|
+
this._state.name,
|
|
150
|
+
this._state.columns,
|
|
151
|
+
this._state.primaryKey,
|
|
152
|
+
this._state.primaryKeyName,
|
|
153
|
+
this._state.uniques,
|
|
154
|
+
[...this._state.indexes, indexDef],
|
|
155
|
+
this._state.foreignKeys
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
foreignKey(columns, references, name) {
|
|
159
|
+
const fkDef = name ? { columns, references, name } : { columns, references };
|
|
160
|
+
return new _TableBuilder(
|
|
161
|
+
this._state.name,
|
|
162
|
+
this._state.columns,
|
|
163
|
+
this._state.primaryKey,
|
|
164
|
+
this._state.primaryKeyName,
|
|
165
|
+
this._state.uniques,
|
|
166
|
+
this._state.indexes,
|
|
167
|
+
[...this._state.foreignKeys, fkDef]
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
build() {
|
|
171
|
+
return {
|
|
172
|
+
name: this._name,
|
|
173
|
+
columns: this._columns,
|
|
174
|
+
...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {},
|
|
175
|
+
...this._state.primaryKeyName !== void 0 ? { primaryKeyName: this._state.primaryKeyName } : {},
|
|
176
|
+
uniques: this._state.uniques,
|
|
177
|
+
indexes: this._state.indexes,
|
|
178
|
+
foreignKeys: this._state.foreignKeys
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/contract-builder.ts
|
|
184
|
+
var ContractBuilder = class _ContractBuilder {
|
|
185
|
+
state;
|
|
186
|
+
constructor(state) {
|
|
187
|
+
this.state = state ?? {
|
|
188
|
+
tables: {},
|
|
189
|
+
models: {}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
target(packRef) {
|
|
193
|
+
return new _ContractBuilder({
|
|
194
|
+
...this.state,
|
|
195
|
+
target: packRef.targetId
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
capabilities(capabilities) {
|
|
199
|
+
return new _ContractBuilder({
|
|
200
|
+
...this.state,
|
|
201
|
+
capabilities
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
table(name, callback) {
|
|
205
|
+
const tableBuilder = createTable(name);
|
|
206
|
+
const result = callback(tableBuilder);
|
|
207
|
+
const finalBuilder = result instanceof TableBuilder ? result : tableBuilder;
|
|
208
|
+
const tableState = finalBuilder.build();
|
|
209
|
+
return new _ContractBuilder({
|
|
210
|
+
...this.state,
|
|
211
|
+
tables: { ...this.state.tables, [name]: tableState }
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
model(name, table, callback) {
|
|
215
|
+
const modelBuilder = new ModelBuilder(name, table);
|
|
216
|
+
const result = callback(modelBuilder);
|
|
217
|
+
const finalBuilder = result instanceof ModelBuilder ? result : modelBuilder;
|
|
218
|
+
const modelState = finalBuilder.build();
|
|
219
|
+
return new _ContractBuilder({
|
|
220
|
+
...this.state,
|
|
221
|
+
models: { ...this.state.models, [name]: modelState }
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
coreHash(hash) {
|
|
225
|
+
return new _ContractBuilder({
|
|
226
|
+
...this.state,
|
|
227
|
+
coreHash: hash
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function defineContract() {
|
|
232
|
+
return new ContractBuilder();
|
|
233
|
+
}
|
|
234
|
+
export {
|
|
235
|
+
ContractBuilder,
|
|
236
|
+
ModelBuilder,
|
|
237
|
+
TableBuilder,
|
|
238
|
+
createTable,
|
|
239
|
+
defineContract
|
|
240
|
+
};
|
|
241
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 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,G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;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ModelBuilderState, RelationDefinition } from './builder-state';
|
|
2
|
+
export declare class ModelBuilder<Name extends string, Table extends string, Fields extends Record<string, string> = Record<never, never>, Relations extends Record<string, RelationDefinition> = Record<never, never>> {
|
|
3
|
+
private readonly _name;
|
|
4
|
+
private readonly _table;
|
|
5
|
+
private readonly _fields;
|
|
6
|
+
private readonly _relations;
|
|
7
|
+
constructor(name: Name, table: Table, fields?: Fields, relations?: Relations);
|
|
8
|
+
field<FieldName extends string, ColumnName extends string>(fieldName: FieldName, columnName: ColumnName): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations>;
|
|
9
|
+
relation<RelationName extends string, ToModel extends string, ToTable extends string>(name: RelationName, options: {
|
|
10
|
+
toModel: ToModel;
|
|
11
|
+
toTable: ToTable;
|
|
12
|
+
cardinality: '1:1' | '1:N' | 'N:1';
|
|
13
|
+
on: {
|
|
14
|
+
parentTable: Table;
|
|
15
|
+
parentColumns: readonly string[];
|
|
16
|
+
childTable: ToTable;
|
|
17
|
+
childColumns: readonly string[];
|
|
18
|
+
};
|
|
19
|
+
}): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
|
|
20
|
+
relation<RelationName extends string, ToModel extends string, ToTable extends string, JunctionTable extends string>(name: RelationName, options: {
|
|
21
|
+
toModel: ToModel;
|
|
22
|
+
toTable: ToTable;
|
|
23
|
+
cardinality: 'N:M';
|
|
24
|
+
through: {
|
|
25
|
+
table: JunctionTable;
|
|
26
|
+
parentColumns: readonly string[];
|
|
27
|
+
childColumns: readonly string[];
|
|
28
|
+
};
|
|
29
|
+
on: {
|
|
30
|
+
parentTable: Table;
|
|
31
|
+
parentColumns: readonly string[];
|
|
32
|
+
childTable: JunctionTable;
|
|
33
|
+
childColumns: readonly string[];
|
|
34
|
+
};
|
|
35
|
+
}): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
|
|
36
|
+
build(): ModelBuilderState<Name, Table, Fields, Relations>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=model-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-builder.d.ts","sourceRoot":"","sources":["../src/model-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE7E,qBAAa,YAAY,CACvB,IAAI,SAAS,MAAM,EACnB,KAAK,SAAS,MAAM,EACpB,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC5D,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;IAE3E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;gBAGrC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE,MAAqB,EAC7B,SAAS,GAAE,SAA2B;IAQxC,KAAK,CAAC,SAAS,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,EACvD,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,GACrB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE,SAAS,CAAC;IAY/E,QAAQ,CAAC,YAAY,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EAClF,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;QACnC,EAAE,EAAE;YACF,WAAW,EAAE,KAAK,CAAC;YACnB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;YACjC,UAAU,EAAE,OAAO,CAAC;YACpB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;SACjC,CAAC;KACH,GACA,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAC1F,QAAQ,CACN,YAAY,SAAS,MAAM,EAC3B,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,MAAM,EACtB,aAAa,SAAS,MAAM,EAE5B,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,EAAE,KAAK,CAAC;QACnB,OAAO,EAAE;YACP,KAAK,EAAE,aAAa,CAAC;YACrB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;YACjC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;SACjC,CAAC;QACF,EAAE,EAAE;YACF,WAAW,EAAE,KAAK,CAAC;YACnB,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;YACjC,UAAU,EAAE,aAAa,CAAC;YAC1B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;SACjC,CAAC;KACH,GACA,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IA0E1F,KAAK,IAAI,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC;CAQ3D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
*/
|
|
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> {
|
|
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();
|
|
19
|
+
column<ColName extends string, Descriptor extends ColumnTypeDescriptor, Nullable extends boolean | undefined = undefined>(name: ColName, options: {
|
|
20
|
+
type: Descriptor;
|
|
21
|
+
nullable?: Nullable;
|
|
22
|
+
}): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>>, PrimaryKey>;
|
|
23
|
+
primaryKey<PK extends readonly string[]>(columns: PK, name?: string): TableBuilder<Name, Columns, PK>;
|
|
24
|
+
unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
25
|
+
index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
26
|
+
foreignKey(columns: readonly string[], references: {
|
|
27
|
+
table: string;
|
|
28
|
+
columns: readonly string[];
|
|
29
|
+
}, name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
30
|
+
build(): TableBuilderState<Name, Columns, PrimaryKey>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=table-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-builder.d.ts","sourceRoot":"","sources":["../src/table-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAgBzB;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAE/E;AAED;;;GAGG;AACH,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,MAAM,CAAuD;IAE9E,0CAA0C;gBAExC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,OAAO,EAAE,SAAS,mBAAmB,EAAE,EACvC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,WAAW,EAAE,SAAS,aAAa,EAAE;IAavC,OAAO,KAAK,KAAK,GAEhB;IAED,OAAO,KAAK,QAAQ,GAEnB;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,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;IA0BD,UAAU,CAAC,EAAE,SAAS,SAAS,MAAM,EAAE,EACrC,OAAO,EAAE,EAAE,EACX,IAAI,CAAC,EAAE,MAAM,GACZ,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;IAYlC,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC;IAa1F,KAAK,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC;IAazF,UAAU,CACR,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,EACzD,IAAI,CAAC,EAAE,MAAM,GACZ,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC;IAa1C,KAAK,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC;CAatD"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ColumnBuilderState, ModelBuilderState, RelationDefinition, TableBuilderState } from './builder-state';
|
|
2
|
+
export type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
|
|
3
|
+
readonly nativeType: string;
|
|
4
|
+
readonly codecId: Type;
|
|
5
|
+
readonly nullable: Nullable;
|
|
6
|
+
};
|
|
7
|
+
export type ExtractColumns<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, infer C, readonly string[] | undefined> ? C : never;
|
|
8
|
+
export type ExtractPrimaryKey<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, infer PK> ? PK : never;
|
|
9
|
+
export type BuildStorage<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
|
|
10
|
+
readonly tables: {
|
|
11
|
+
readonly [K in keyof Tables]: {
|
|
12
|
+
readonly columns: {
|
|
13
|
+
readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type BuildStorageTables<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
|
|
19
|
+
readonly [K in keyof Tables]: {
|
|
20
|
+
readonly columns: {
|
|
21
|
+
readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type Mutable<T> = {
|
|
26
|
+
-readonly [K in keyof T]-?: T[K];
|
|
27
|
+
};
|
|
28
|
+
export type BuildModelFields<Fields extends Record<string, string>> = {
|
|
29
|
+
readonly [K in keyof Fields]: {
|
|
30
|
+
readonly column: Fields[K];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type ExtractModelFields<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>> ? F : never;
|
|
34
|
+
export type ExtractModelRelations<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, Record<string, string>, infer R> ? R : never;
|
|
35
|
+
export type BuildModels<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = {
|
|
36
|
+
readonly [K in keyof Models]: {
|
|
37
|
+
readonly storage: {
|
|
38
|
+
readonly table: Models[K]['table'];
|
|
39
|
+
};
|
|
40
|
+
readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type BuildRelations<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = {
|
|
44
|
+
readonly [K in keyof Models as Models[K]['table']]: ExtractModelRelations<Models[K]>;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,kBAAkB,CAAC,QAAQ,SAAS,OAAO,EAAE,IAAI,SAAS,MAAM,IAAI;IAC9E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,iBAAiB,CACzB,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC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
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/contract-authoring",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.95.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=20"
|
|
8
|
-
},
|
|
9
6
|
"description": "Target-agnostic contract authoring builder core for Prisma Next",
|
|
10
7
|
"dependencies": {
|
|
11
8
|
"ts-toolbelt": "^9.6.0",
|
|
12
|
-
"@prisma-next/contract": "0.3.0-pr.
|
|
9
|
+
"@prisma-next/contract": "0.3.0-pr.95.2"
|
|
13
10
|
},
|
|
14
11
|
"devDependencies": {
|
|
15
|
-
"
|
|
12
|
+
"tsup": "8.5.1",
|
|
16
13
|
"typescript": "5.9.3",
|
|
17
14
|
"vitest": "4.0.16",
|
|
18
|
-
"@prisma-next/tsconfig": "0.0.0"
|
|
19
|
-
"@prisma-next/tsdown": "0.0.0"
|
|
15
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
20
16
|
},
|
|
21
17
|
"files": [
|
|
22
18
|
"dist",
|
|
23
19
|
"src"
|
|
24
20
|
],
|
|
25
21
|
"exports": {
|
|
26
|
-
".":
|
|
27
|
-
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
28
26
|
},
|
|
29
|
-
"main": "./dist/index.mjs",
|
|
30
|
-
"module": "./dist/index.mjs",
|
|
31
|
-
"types": "./dist/index.d.mts",
|
|
32
27
|
"scripts": {
|
|
33
|
-
"build": "
|
|
28
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
34
29
|
"test": "vitest run",
|
|
35
30
|
"test:coverage": "vitest run --coverage",
|
|
36
|
-
"typecheck": "tsc --noEmit",
|
|
31
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
37
32
|
"lint": "biome check . --error-on-warnings",
|
|
38
33
|
"lint:fix": "biome check --write .",
|
|
39
34
|
"lint:fix:unsafe": "biome check --write --unsafe .",
|
package/dist/index.d.mts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { TargetPackRef } from "@prisma-next/contract/framework-components";
|
|
2
|
-
|
|
3
|
-
//#region src/builder-state.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Column type descriptor containing both codec ID and native type.
|
|
7
|
-
* Used when defining columns with descriptor objects instead of string IDs.
|
|
8
|
-
*/
|
|
9
|
-
type ColumnTypeDescriptor = {
|
|
10
|
-
readonly codecId: string;
|
|
11
|
-
readonly nativeType: string;
|
|
12
|
-
};
|
|
13
|
-
interface ColumnBuilderState<Name extends string, Nullable extends boolean, Type extends string> {
|
|
14
|
-
readonly name: Name;
|
|
15
|
-
readonly nullable: Nullable;
|
|
16
|
-
readonly type: Type;
|
|
17
|
-
readonly nativeType: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Unique constraint definition for table builder.
|
|
21
|
-
*/
|
|
22
|
-
interface UniqueConstraintDef {
|
|
23
|
-
readonly columns: readonly string[];
|
|
24
|
-
readonly name?: string;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Index definition for table builder.
|
|
28
|
-
*/
|
|
29
|
-
interface IndexDef {
|
|
30
|
-
readonly columns: readonly string[];
|
|
31
|
-
readonly name?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Foreign key definition for table builder.
|
|
35
|
-
*/
|
|
36
|
-
interface ForeignKeyDef {
|
|
37
|
-
readonly columns: readonly string[];
|
|
38
|
-
readonly references: {
|
|
39
|
-
readonly table: string;
|
|
40
|
-
readonly columns: readonly string[];
|
|
41
|
-
};
|
|
42
|
-
readonly name?: string;
|
|
43
|
-
}
|
|
44
|
-
interface TableBuilderState<Name extends string, Columns extends Record<string, ColumnBuilderState<string, boolean, string>>, PrimaryKey extends readonly string[] | undefined> {
|
|
45
|
-
readonly name: Name;
|
|
46
|
-
readonly columns: Columns;
|
|
47
|
-
readonly primaryKey?: PrimaryKey;
|
|
48
|
-
readonly primaryKeyName?: string;
|
|
49
|
-
readonly uniques: readonly UniqueConstraintDef[];
|
|
50
|
-
readonly indexes: readonly IndexDef[];
|
|
51
|
-
readonly foreignKeys: readonly ForeignKeyDef[];
|
|
52
|
-
}
|
|
53
|
-
type RelationDefinition = {
|
|
54
|
-
readonly to: string;
|
|
55
|
-
readonly cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';
|
|
56
|
-
readonly on: {
|
|
57
|
-
readonly parentCols: readonly string[];
|
|
58
|
-
readonly childCols: readonly string[];
|
|
59
|
-
};
|
|
60
|
-
readonly through?: {
|
|
61
|
-
readonly table: string;
|
|
62
|
-
readonly parentCols: readonly string[];
|
|
63
|
-
readonly childCols: readonly string[];
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
interface ModelBuilderState<Name extends string, Table extends string, Fields extends Record<string, string>, Relations extends Record<string, RelationDefinition>> {
|
|
67
|
-
readonly name: Name;
|
|
68
|
-
readonly table: Table;
|
|
69
|
-
readonly fields: Fields;
|
|
70
|
-
readonly relations: Relations;
|
|
71
|
-
}
|
|
72
|
-
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> {
|
|
73
|
-
readonly target?: Target;
|
|
74
|
-
readonly tables: Tables;
|
|
75
|
-
readonly models: Models;
|
|
76
|
-
readonly coreHash?: CoreHash;
|
|
77
|
-
readonly extensionPacks?: ExtensionPacks;
|
|
78
|
-
readonly capabilities?: Capabilities;
|
|
79
|
-
/**
|
|
80
|
-
* Array of extension pack namespace identifiers (e.g., ['pgvector', 'postgis']).
|
|
81
|
-
* Populated when extension packs are registered during contract building.
|
|
82
|
-
* Used to track which extension packs are included in the contract.
|
|
83
|
-
* Can be undefined or empty if no extension packs are registered.
|
|
84
|
-
* Namespace format matches the extension pack ID (e.g., 'pgvector', not 'pgvector@1.0.0').
|
|
85
|
-
*/
|
|
86
|
-
readonly extensionNamespaces?: readonly string[];
|
|
87
|
-
}
|
|
88
|
-
interface ColumnBuilder<Name extends string, Nullable extends boolean, Type extends string> {
|
|
89
|
-
nullable<Value extends boolean>(value?: Value): ColumnBuilder<Name, Value, Type>;
|
|
90
|
-
type<Id extends string>(id: Id): ColumnBuilder<Name, Nullable, Id>;
|
|
91
|
-
build(): ColumnBuilderState<Name, Nullable, Type>;
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/model-builder.d.ts
|
|
95
|
-
declare class ModelBuilder<Name extends string, Table extends string, Fields extends Record<string, string> = Record<never, never>, Relations extends Record<string, RelationDefinition> = Record<never, never>> {
|
|
96
|
-
private readonly _name;
|
|
97
|
-
private readonly _table;
|
|
98
|
-
private readonly _fields;
|
|
99
|
-
private readonly _relations;
|
|
100
|
-
constructor(name: Name, table: Table, fields?: Fields, relations?: Relations);
|
|
101
|
-
field<FieldName extends string, ColumnName extends string>(fieldName: FieldName, columnName: ColumnName): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations>;
|
|
102
|
-
relation<RelationName extends string, ToModel extends string, ToTable extends string>(name: RelationName, options: {
|
|
103
|
-
toModel: ToModel;
|
|
104
|
-
toTable: ToTable;
|
|
105
|
-
cardinality: '1:1' | '1:N' | 'N:1';
|
|
106
|
-
on: {
|
|
107
|
-
parentTable: Table;
|
|
108
|
-
parentColumns: readonly string[];
|
|
109
|
-
childTable: ToTable;
|
|
110
|
-
childColumns: readonly string[];
|
|
111
|
-
};
|
|
112
|
-
}): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
|
|
113
|
-
relation<RelationName extends string, ToModel extends string, ToTable extends string, JunctionTable extends string>(name: RelationName, options: {
|
|
114
|
-
toModel: ToModel;
|
|
115
|
-
toTable: ToTable;
|
|
116
|
-
cardinality: 'N:M';
|
|
117
|
-
through: {
|
|
118
|
-
table: JunctionTable;
|
|
119
|
-
parentColumns: readonly string[];
|
|
120
|
-
childColumns: readonly string[];
|
|
121
|
-
};
|
|
122
|
-
on: {
|
|
123
|
-
parentTable: Table;
|
|
124
|
-
parentColumns: readonly string[];
|
|
125
|
-
childTable: JunctionTable;
|
|
126
|
-
childColumns: readonly string[];
|
|
127
|
-
};
|
|
128
|
-
}): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;
|
|
129
|
-
build(): ModelBuilderState<Name, Table, Fields, Relations>;
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/table-builder.d.ts
|
|
133
|
-
/**
|
|
134
|
-
* Creates a new table builder with the given name.
|
|
135
|
-
* This is the preferred way to create a TableBuilder - it ensures
|
|
136
|
-
* type parameters are inferred correctly without unsafe casts.
|
|
137
|
-
*/
|
|
138
|
-
declare function createTable<Name extends string>(name: Name): TableBuilder<Name>;
|
|
139
|
-
/**
|
|
140
|
-
* Builder for defining table structure with type-safe chaining.
|
|
141
|
-
* Use `createTable(name)` to create instances.
|
|
142
|
-
*/
|
|
143
|
-
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> {
|
|
144
|
-
private readonly _state;
|
|
145
|
-
/** @internal Use createTable() instead */
|
|
146
|
-
constructor(name: Name, columns: Columns, primaryKey: PrimaryKey, primaryKeyName: string | undefined, uniques: readonly UniqueConstraintDef[], indexes: readonly IndexDef[], foreignKeys: readonly ForeignKeyDef[]);
|
|
147
|
-
private get _name();
|
|
148
|
-
private get _columns();
|
|
149
|
-
private get _primaryKey();
|
|
150
|
-
column<ColName extends string, Descriptor extends ColumnTypeDescriptor, Nullable extends boolean | undefined = undefined>(name: ColName, options: {
|
|
151
|
-
type: Descriptor;
|
|
152
|
-
nullable?: Nullable;
|
|
153
|
-
}): TableBuilder<Name, Columns & Record<ColName, ColumnBuilderState<ColName, Nullable extends true ? true : false, Descriptor['codecId']>>, PrimaryKey>;
|
|
154
|
-
primaryKey<PK extends readonly string[]>(columns: PK, name?: string): TableBuilder<Name, Columns, PK>;
|
|
155
|
-
unique(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
156
|
-
index(columns: readonly string[], name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
157
|
-
foreignKey(columns: readonly string[], references: {
|
|
158
|
-
table: string;
|
|
159
|
-
columns: readonly string[];
|
|
160
|
-
}, name?: string): TableBuilder<Name, Columns, PrimaryKey>;
|
|
161
|
-
build(): TableBuilderState<Name, Columns, PrimaryKey>;
|
|
162
|
-
}
|
|
163
|
-
//#endregion
|
|
164
|
-
//#region src/contract-builder.d.ts
|
|
165
|
-
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> {
|
|
166
|
-
protected readonly state: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
167
|
-
constructor(state?: ContractBuilderState<Target, Tables, Models, CoreHash, ExtensionPacks, Capabilities>);
|
|
168
|
-
target<T extends string>(packRef: TargetPackRef<string, T>): ContractBuilder<T, Tables, Models, CoreHash, ExtensionPacks, Capabilities>;
|
|
169
|
-
capabilities<C extends Record<string, Record<string, boolean>>>(capabilities: C): ContractBuilder<Target, Tables, Models, CoreHash, ExtensionPacks, C>;
|
|
170
|
-
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>;
|
|
171
|
-
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>;
|
|
172
|
-
coreHash<H extends string>(hash: H): ContractBuilder<Target, Tables, Models, H, ExtensionPacks, Capabilities>;
|
|
173
|
-
}
|
|
174
|
-
declare function defineContract(): ContractBuilder;
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region src/types.d.ts
|
|
177
|
-
type BuildStorageColumn<Nullable extends boolean, Type extends string> = {
|
|
178
|
-
readonly nativeType: string;
|
|
179
|
-
readonly codecId: Type;
|
|
180
|
-
readonly nullable: Nullable;
|
|
181
|
-
};
|
|
182
|
-
type ExtractColumns<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, infer C, readonly string[] | undefined> ? C : never;
|
|
183
|
-
type ExtractPrimaryKey<T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>> = T extends TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, infer PK> ? PK : never;
|
|
184
|
-
type BuildStorage<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = {
|
|
185
|
-
readonly tables: { readonly [K in keyof Tables]: {
|
|
186
|
-
readonly columns: { readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never };
|
|
187
|
-
} };
|
|
188
|
-
};
|
|
189
|
-
type BuildStorageTables<Tables extends Record<string, TableBuilderState<string, Record<string, ColumnBuilderState<string, boolean, string>>, readonly string[] | undefined>>> = { readonly [K in keyof Tables]: {
|
|
190
|
-
readonly columns: { readonly [ColK in keyof ExtractColumns<Tables[K]>]: ExtractColumns<Tables[K]>[ColK] extends ColumnBuilderState<string, infer Null, infer TType> ? BuildStorageColumn<Null & boolean, TType> : never };
|
|
191
|
-
} };
|
|
192
|
-
type Mutable<T> = { -readonly [K in keyof T]-?: T[K] };
|
|
193
|
-
type BuildModelFields<Fields extends Record<string, string>> = { readonly [K in keyof Fields]: {
|
|
194
|
-
readonly column: Fields[K];
|
|
195
|
-
} };
|
|
196
|
-
type ExtractModelFields<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, infer F, Record<string, RelationDefinition>> ? F : never;
|
|
197
|
-
type ExtractModelRelations<T extends ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>> = T extends ModelBuilderState<string, string, Record<string, string>, infer R> ? R : never;
|
|
198
|
-
type BuildModels<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = { readonly [K in keyof Models]: {
|
|
199
|
-
readonly storage: {
|
|
200
|
-
readonly table: Models[K]['table'];
|
|
201
|
-
};
|
|
202
|
-
readonly fields: BuildModelFields<ExtractModelFields<Models[K]>>;
|
|
203
|
-
} };
|
|
204
|
-
type BuildRelations<Models extends Record<string, ModelBuilderState<string, string, Record<string, string>, Record<string, RelationDefinition>>>> = { readonly [K in keyof Models as Models[K]['table']]: ExtractModelRelations<Models[K]> };
|
|
205
|
-
//#endregion
|
|
206
|
-
export { type BuildModelFields, type BuildModels, type BuildRelations, type BuildStorage, type BuildStorageColumn, type BuildStorageTables, type ColumnBuilder, type ColumnBuilderState, type ColumnTypeDescriptor, ContractBuilder, type ContractBuilderState, type ExtractColumns, type ExtractModelFields, type ExtractModelRelations, type ExtractPrimaryKey, type ForeignKeyDef, type IndexDef, ModelBuilder, type ModelBuilderState, type Mutable, type RelationDefinition, TableBuilder, type TableBuilderState, type UniqueConstraintDef, createTable, defineContract };
|
|
207
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/builder-state.ts","../src/model-builder.ts","../src/table-builder.ts","../src/contract-builder.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAIA;AAKiB,KALL,oBAAA,GAKuB;EAKlB,SAAA,OAAA,EAAA,MAAA;EACI,SAAA,UAAA,EAAA,MAAA;CACJ;AAAI,UAPJ,kBAOI,CAAA,aAAA,MAAA,EAAA,iBAAA,OAAA,EAAA,aAAA,MAAA,CAAA,CAAA;EAOJ,SAAA,IAAA,EATA,IASA;EAQA,SAAA,QAAQ,EAhBJ,QAgBI;EAQR,SAAA,IAAA,EAvBA,IAuBa;EASb,SAAA,UAAA,EAAiB,MAAA;;;;;AAOV,UAhCP,mBAAA,CAgCO;EAEK,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EACA,SAAA,IAAA,CAAA,EAAA,MAAA;;;AAI7B;AAcA;AAGiB,UAhDA,QAAA,CAgDA;EACkB,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EAAf,SAAA,IAAA,CAAA,EAAA,MAAA;;;;;AAKW,UA9Cd,aAAA,CA8Cc;EAGd,SAAA,OAAA,EAAA,SAAoB,MAAA,EAAA;EAMhB,SAAA,UAAA,EAAA;IAAf,SAAA,KAAA,EAAA,MAAA;IAFF,SAAA,O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IoBR,qBJpBQ,CIoBc,MJpBd,CIoBqB,CJpBrB,CAAA,CAAA,EAA1D"}
|
package/dist/index.mjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
//#region src/model-builder.ts
|
|
2
|
-
var ModelBuilder = class ModelBuilder {
|
|
3
|
-
_name;
|
|
4
|
-
_table;
|
|
5
|
-
_fields;
|
|
6
|
-
_relations;
|
|
7
|
-
constructor(name, table, fields = {}, relations = {}) {
|
|
8
|
-
this._name = name;
|
|
9
|
-
this._table = table;
|
|
10
|
-
this._fields = fields;
|
|
11
|
-
this._relations = relations;
|
|
12
|
-
}
|
|
13
|
-
field(fieldName, columnName) {
|
|
14
|
-
return new ModelBuilder(this._name, this._table, {
|
|
15
|
-
...this._fields,
|
|
16
|
-
[fieldName]: columnName
|
|
17
|
-
}, this._relations);
|
|
18
|
-
}
|
|
19
|
-
relation(name, options) {
|
|
20
|
-
if (options.on.parentTable !== this._table) throw new Error(`Relation "${name}" parentTable "${options.on.parentTable}" does not match model table "${this._table}"`);
|
|
21
|
-
if (options.cardinality === "N:M") {
|
|
22
|
-
if (!options.through) throw new Error(`Relation "${name}" with cardinality "N:M" requires through field`);
|
|
23
|
-
if (options.on.childTable !== options.through.table) throw new Error(`Relation "${name}" childTable "${options.on.childTable}" does not match through.table "${options.through.table}"`);
|
|
24
|
-
} else if (options.on.childTable !== options.toTable) throw new Error(`Relation "${name}" childTable "${options.on.childTable}" does not match toTable "${options.toTable}"`);
|
|
25
|
-
const relationDef = {
|
|
26
|
-
to: options.toModel,
|
|
27
|
-
cardinality: options.cardinality,
|
|
28
|
-
on: {
|
|
29
|
-
parentCols: options.on.parentColumns,
|
|
30
|
-
childCols: options.on.childColumns
|
|
31
|
-
},
|
|
32
|
-
...options.through ? { through: {
|
|
33
|
-
table: options.through.table,
|
|
34
|
-
parentCols: options.through.parentColumns,
|
|
35
|
-
childCols: options.through.childColumns
|
|
36
|
-
} } : void 0
|
|
37
|
-
};
|
|
38
|
-
return new ModelBuilder(this._name, this._table, this._fields, {
|
|
39
|
-
...this._relations,
|
|
40
|
-
[name]: relationDef
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
build() {
|
|
44
|
-
return {
|
|
45
|
-
name: this._name,
|
|
46
|
-
table: this._table,
|
|
47
|
-
fields: this._fields,
|
|
48
|
-
relations: this._relations
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/table-builder.ts
|
|
55
|
-
/**
|
|
56
|
-
* Creates a new table builder with the given name.
|
|
57
|
-
* This is the preferred way to create a TableBuilder - it ensures
|
|
58
|
-
* type parameters are inferred correctly without unsafe casts.
|
|
59
|
-
*/
|
|
60
|
-
function createTable(name) {
|
|
61
|
-
return new TableBuilder(name, {}, void 0, void 0, [], [], []);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Builder for defining table structure with type-safe chaining.
|
|
65
|
-
* Use `createTable(name)` to create instances.
|
|
66
|
-
*/
|
|
67
|
-
var TableBuilder = class TableBuilder {
|
|
68
|
-
_state;
|
|
69
|
-
/** @internal Use createTable() instead */
|
|
70
|
-
constructor(name, columns, primaryKey, primaryKeyName, uniques, indexes, foreignKeys) {
|
|
71
|
-
this._state = {
|
|
72
|
-
name,
|
|
73
|
-
columns,
|
|
74
|
-
primaryKey,
|
|
75
|
-
primaryKeyName,
|
|
76
|
-
uniques,
|
|
77
|
-
indexes,
|
|
78
|
-
foreignKeys
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
get _name() {
|
|
82
|
-
return this._state.name;
|
|
83
|
-
}
|
|
84
|
-
get _columns() {
|
|
85
|
-
return this._state.columns;
|
|
86
|
-
}
|
|
87
|
-
get _primaryKey() {
|
|
88
|
-
return this._state.primaryKey;
|
|
89
|
-
}
|
|
90
|
-
column(name, options) {
|
|
91
|
-
const nullable = options.nullable ?? false;
|
|
92
|
-
const { codecId, nativeType } = options.type;
|
|
93
|
-
const columnState = {
|
|
94
|
-
name,
|
|
95
|
-
nullable,
|
|
96
|
-
type: codecId,
|
|
97
|
-
nativeType
|
|
98
|
-
};
|
|
99
|
-
const newColumns = {
|
|
100
|
-
...this._columns,
|
|
101
|
-
[name]: columnState
|
|
102
|
-
};
|
|
103
|
-
return new TableBuilder(this._state.name, newColumns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, this._state.indexes, this._state.foreignKeys);
|
|
104
|
-
}
|
|
105
|
-
primaryKey(columns, name) {
|
|
106
|
-
return new TableBuilder(this._state.name, this._state.columns, columns, name, this._state.uniques, this._state.indexes, this._state.foreignKeys);
|
|
107
|
-
}
|
|
108
|
-
unique(columns, name) {
|
|
109
|
-
const constraint = name ? {
|
|
110
|
-
columns,
|
|
111
|
-
name
|
|
112
|
-
} : { columns };
|
|
113
|
-
return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, [...this._state.uniques, constraint], this._state.indexes, this._state.foreignKeys);
|
|
114
|
-
}
|
|
115
|
-
index(columns, name) {
|
|
116
|
-
const indexDef = name ? {
|
|
117
|
-
columns,
|
|
118
|
-
name
|
|
119
|
-
} : { columns };
|
|
120
|
-
return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, [...this._state.indexes, indexDef], this._state.foreignKeys);
|
|
121
|
-
}
|
|
122
|
-
foreignKey(columns, references, name) {
|
|
123
|
-
const fkDef = name ? {
|
|
124
|
-
columns,
|
|
125
|
-
references,
|
|
126
|
-
name
|
|
127
|
-
} : {
|
|
128
|
-
columns,
|
|
129
|
-
references
|
|
130
|
-
};
|
|
131
|
-
return new TableBuilder(this._state.name, this._state.columns, this._state.primaryKey, this._state.primaryKeyName, this._state.uniques, this._state.indexes, [...this._state.foreignKeys, fkDef]);
|
|
132
|
-
}
|
|
133
|
-
build() {
|
|
134
|
-
return {
|
|
135
|
-
name: this._name,
|
|
136
|
-
columns: this._columns,
|
|
137
|
-
...this._primaryKey !== void 0 ? { primaryKey: this._primaryKey } : {},
|
|
138
|
-
...this._state.primaryKeyName !== void 0 ? { primaryKeyName: this._state.primaryKeyName } : {},
|
|
139
|
-
uniques: this._state.uniques,
|
|
140
|
-
indexes: this._state.indexes,
|
|
141
|
-
foreignKeys: this._state.foreignKeys
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region src/contract-builder.ts
|
|
148
|
-
var ContractBuilder = class ContractBuilder {
|
|
149
|
-
state;
|
|
150
|
-
constructor(state) {
|
|
151
|
-
this.state = state ?? {
|
|
152
|
-
tables: {},
|
|
153
|
-
models: {}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
target(packRef) {
|
|
157
|
-
return new ContractBuilder({
|
|
158
|
-
...this.state,
|
|
159
|
-
target: packRef.targetId
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
capabilities(capabilities) {
|
|
163
|
-
return new ContractBuilder({
|
|
164
|
-
...this.state,
|
|
165
|
-
capabilities
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
table(name, callback) {
|
|
169
|
-
const tableBuilder = createTable(name);
|
|
170
|
-
const result = callback(tableBuilder);
|
|
171
|
-
const tableState = (result instanceof TableBuilder ? result : tableBuilder).build();
|
|
172
|
-
return new ContractBuilder({
|
|
173
|
-
...this.state,
|
|
174
|
-
tables: {
|
|
175
|
-
...this.state.tables,
|
|
176
|
-
[name]: tableState
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
model(name, table, callback) {
|
|
181
|
-
const modelBuilder = new ModelBuilder(name, table);
|
|
182
|
-
const result = callback(modelBuilder);
|
|
183
|
-
const modelState = (result instanceof ModelBuilder ? result : modelBuilder).build();
|
|
184
|
-
return new ContractBuilder({
|
|
185
|
-
...this.state,
|
|
186
|
-
models: {
|
|
187
|
-
...this.state.models,
|
|
188
|
-
[name]: modelState
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
coreHash(hash) {
|
|
193
|
-
return new ContractBuilder({
|
|
194
|
-
...this.state,
|
|
195
|
-
coreHash: hash
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
function defineContract() {
|
|
200
|
-
return new ContractBuilder();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
//#endregion
|
|
204
|
-
export { ContractBuilder, ModelBuilder, TableBuilder, createTable, defineContract };
|
|
205
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["relationDef: RelationDefinition","constraint: UniqueConstraintDef","indexDef: IndexDef","fkDef: ForeignKeyDef"],"sources":["../src/model-builder.ts","../src/table-builder.ts","../src/contract-builder.ts"],"sourcesContent":["import type { ModelBuilderState, RelationDefinition } from './builder-state';\n\nexport class ModelBuilder<\n Name extends string,\n Table extends string,\n Fields extends Record<string, string> = Record<never, never>,\n Relations extends Record<string, RelationDefinition> = Record<never, never>,\n> {\n private readonly _name: Name;\n private readonly _table: Table;\n private readonly _fields: Fields;\n private readonly _relations: Relations;\n\n constructor(\n name: Name,\n table: Table,\n fields: Fields = {} as Fields,\n relations: Relations = {} as Relations,\n ) {\n this._name = name;\n this._table = table;\n this._fields = fields;\n this._relations = relations;\n }\n\n field<FieldName extends string, ColumnName extends string>(\n fieldName: FieldName,\n columnName: ColumnName,\n ): ModelBuilder<Name, Table, Fields & Record<FieldName, ColumnName>, Relations> {\n return new ModelBuilder(\n this._name,\n this._table,\n {\n ...this._fields,\n [fieldName]: columnName,\n } as Fields & Record<FieldName, ColumnName>,\n this._relations,\n );\n }\n\n relation<RelationName extends string, ToModel extends string, ToTable extends string>(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: '1:1' | '1:N' | 'N:1';\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: ToTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;\n relation<\n RelationName extends string,\n ToModel extends string,\n ToTable extends string,\n JunctionTable extends string,\n >(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: 'N:M';\n through: {\n table: JunctionTable;\n parentColumns: readonly string[];\n childColumns: readonly string[];\n };\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: JunctionTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>>;\n relation<\n RelationName extends string,\n ToModel extends string,\n ToTable extends string,\n JunctionTable extends string = never,\n >(\n name: RelationName,\n options: {\n toModel: ToModel;\n toTable: ToTable;\n cardinality: '1:1' | '1:N' | 'N:1' | 'N:M';\n through?: {\n table: JunctionTable;\n parentColumns: readonly string[];\n childColumns: readonly string[];\n };\n on: {\n parentTable: Table;\n parentColumns: readonly string[];\n childTable: ToTable | JunctionTable;\n childColumns: readonly string[];\n };\n },\n ): ModelBuilder<Name, Table, Fields, Relations & Record<RelationName, RelationDefinition>> {\n // Validate parentTable matches model's table\n if (options.on.parentTable !== this._table) {\n throw new Error(\n `Relation \"${name}\" parentTable \"${options.on.parentTable}\" does not match model table \"${this._table}\"`,\n );\n }\n\n // Validate childTable matches toTable (for non-N:M) or through.table (for N:M)\n if (options.cardinality === 'N:M') {\n if (!options.through) {\n throw new Error(`Relation \"${name}\" with cardinality \"N:M\" requires through field`);\n }\n if (options.on.childTable !== options.through.table) {\n throw new Error(\n `Relation \"${name}\" childTable \"${options.on.childTable}\" does not match through.table \"${options.through.table}\"`,\n );\n }\n } else {\n if (options.on.childTable !== options.toTable) {\n throw new Error(\n `Relation \"${name}\" childTable \"${options.on.childTable}\" does not match toTable \"${options.toTable}\"`,\n );\n }\n }\n\n const relationDef: RelationDefinition = {\n to: options.toModel,\n cardinality: options.cardinality,\n on: {\n parentCols: options.on.parentColumns,\n childCols: options.on.childColumns,\n },\n ...(options.through\n ? {\n through: {\n table: options.through.table,\n parentCols: options.through.parentColumns,\n childCols: options.through.childColumns,\n },\n }\n : undefined),\n };\n\n return new ModelBuilder(this._name, this._table, this._fields, {\n ...this._relations,\n [name]: relationDef,\n } as Relations & Record<RelationName, RelationDefinition>);\n }\n\n build(): ModelBuilderState<Name, Table, Fields, Relations> {\n return {\n name: this._name,\n table: this._table,\n fields: this._fields,\n relations: this._relations,\n };\n }\n}\n","import type {\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":";AAEA,IAAa,eAAb,MAAa,aAKX;CACA,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,YACE,MACA,OACA,SAAiB,EAAE,EACnB,YAAuB,EAAE,EACzB;AACA,OAAK,QAAQ;AACb,OAAK,SAAS;AACd,OAAK,UAAU;AACf,OAAK,aAAa;;CAGpB,MACE,WACA,YAC8E;AAC9E,SAAO,IAAI,aACT,KAAK,OACL,KAAK,QACL;GACE,GAAG,KAAK;IACP,YAAY;GACd,EACD,KAAK,WACN;;CAyCH,SAME,MACA,SAgByF;AAEzF,MAAI,QAAQ,GAAG,gBAAgB,KAAK,OAClC,OAAM,IAAI,MACR,aAAa,KAAK,iBAAiB,QAAQ,GAAG,YAAY,gCAAgC,KAAK,OAAO,GACvG;AAIH,MAAI,QAAQ,gBAAgB,OAAO;AACjC,OAAI,CAAC,QAAQ,QACX,OAAM,IAAI,MAAM,aAAa,KAAK,iDAAiD;AAErF,OAAI,QAAQ,GAAG,eAAe,QAAQ,QAAQ,MAC5C,OAAM,IAAI,MACR,aAAa,KAAK,gBAAgB,QAAQ,GAAG,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