@vibeorm/dsl 0.4.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -471
- package/dist/column.d.ts +150 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/enum.d.ts +27 -0
- package/dist/enum.d.ts.map +1 -0
- package/dist/generator/index.d.ts +5 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/prisma.d.ts +19 -0
- package/dist/generator/prisma.d.ts.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1546 -0
- package/dist/index.js.map +22 -0
- package/dist/model.d.ts +44 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/naming.d.ts +23 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/relation-plan.d.ts +101 -0
- package/dist/relation-plan.d.ts.map +1 -0
- package/dist/relation.d.ts +23 -0
- package/dist/relation.d.ts.map +1 -0
- package/dist/relations.d.ts +29 -0
- package/dist/relations.d.ts.map +1 -0
- package/dist/schema.d.ts +38 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/templates.d.ts +79 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/to-ir.d.ts +41 -0
- package/dist/to-ir.d.ts.map +1 -0
- package/dist/types.d.ts +286 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validate.d.ts +22 -0
- package/dist/validate.d.ts.map +1 -0
- package/package.json +29 -26
- package/src/column.ts +0 -389
- package/src/enum.ts +0 -71
- package/src/generator/index.ts +0 -5
- package/src/generator/prisma.ts +0 -728
- package/src/index.ts +0 -247
- package/src/model.ts +0 -330
- package/src/relation.ts +0 -75
- package/src/relations.ts +0 -293
- package/src/schema.ts +0 -184
- package/src/templates.ts +0 -134
- package/src/types.ts +0 -381
- package/src/validate.ts +0 -141
package/src/column.ts
DELETED
|
@@ -1,389 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Column type builders using chainable style with optional config-object fallback
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* // Chainable style (encouraged)
|
|
6
|
-
* dsl.string().optional()
|
|
7
|
-
* dsl.string().unique().index()
|
|
8
|
-
* dsl.int().default(42)
|
|
9
|
-
*
|
|
10
|
-
* // Object style (also supported)
|
|
11
|
-
* dsl.string({ optional: true })
|
|
12
|
-
* dsl.string({ unique: true, index: true })
|
|
13
|
-
* dsl.int({ default: 42 })
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import type {
|
|
17
|
-
BigIntColumnConfig,
|
|
18
|
-
BooleanColumnConfig,
|
|
19
|
-
BytesColumnConfig,
|
|
20
|
-
ColumnDef,
|
|
21
|
-
DatetimeColumnConfig,
|
|
22
|
-
DecimalColumnConfig,
|
|
23
|
-
FloatColumnConfig,
|
|
24
|
-
IdColumnConfig,
|
|
25
|
-
InlineEnumConfig,
|
|
26
|
-
IntColumnConfig,
|
|
27
|
-
JsonColumnConfig,
|
|
28
|
-
StringColumnConfig,
|
|
29
|
-
UnsupportedColumnConfig,
|
|
30
|
-
} from "./types.ts";
|
|
31
|
-
|
|
32
|
-
// ─── Clone Helper ─────────────────────
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Creates a shallow clone of a ColumnDef, producing fresh __config.
|
|
36
|
-
* Used to prevent shared mutation when columns are spread from templates.
|
|
37
|
-
*/
|
|
38
|
-
export function cloneColumnDef(col: ColumnDef): ColumnDef {
|
|
39
|
-
return {
|
|
40
|
-
__type: "column",
|
|
41
|
-
__columnType: col.__columnType,
|
|
42
|
-
__name: col.__name,
|
|
43
|
-
__config: { ...col.__config },
|
|
44
|
-
__enumValues: col.__enumValues,
|
|
45
|
-
__enumName: col.__enumName,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ─── Chainable Column Builder ─────────────────────
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Chainable column definition that allows method chaining for configuration.
|
|
53
|
-
* Implements ColumnDef for backwards compatibility.
|
|
54
|
-
*/
|
|
55
|
-
export class ChainableColumn<T extends ColumnDef["__columnType"]> implements ColumnDef<T> {
|
|
56
|
-
readonly __type = "column" as const;
|
|
57
|
-
readonly __columnType: T;
|
|
58
|
-
__config: ColumnDef["__config"];
|
|
59
|
-
__name?: string;
|
|
60
|
-
__enumValues?: readonly string[];
|
|
61
|
-
__enumName?: string;
|
|
62
|
-
|
|
63
|
-
constructor(columnType: T, config: ColumnDef["__config"] = {}) {
|
|
64
|
-
this.__columnType = columnType;
|
|
65
|
-
this.__config = { ...config };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Mark this column as optional (nullable)
|
|
70
|
-
*/
|
|
71
|
-
optional(): this {
|
|
72
|
-
this.__config.optional = true;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Add a unique constraint to this column
|
|
78
|
-
*/
|
|
79
|
-
unique(): this {
|
|
80
|
-
this.__config.unique = true;
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Add an index on this column
|
|
86
|
-
*/
|
|
87
|
-
index(): this {
|
|
88
|
-
this.__config.index = true;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Mark this column as an array type
|
|
94
|
-
*/
|
|
95
|
-
array(): this {
|
|
96
|
-
this.__config.array = true;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Set a default value for this column
|
|
102
|
-
*/
|
|
103
|
-
default<V>(value: V): this {
|
|
104
|
-
this.__config.default = value;
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Map this column to a different database column name
|
|
110
|
-
* @example dsl.string().map("user_name") // @map("user_name")
|
|
111
|
-
*/
|
|
112
|
-
map(dbColumnName: string): this {
|
|
113
|
-
this.__config.map = dbColumnName;
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Set default value using a database-native function
|
|
119
|
-
* @example dsl.string().dbgenerated("gen_random_uuid()")
|
|
120
|
-
*/
|
|
121
|
-
dbgenerated(expression: string): this {
|
|
122
|
-
this.__config.dbgenerated = expression;
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Add a triple-slash comment above this column in Prisma output.
|
|
128
|
-
* Useful for Zod generator annotations or documentation.
|
|
129
|
-
* @example dsl.string().comment("@zod.string.min(1).max(100)")
|
|
130
|
-
* @example dsl.string().comment("User's display name")
|
|
131
|
-
*/
|
|
132
|
-
comment(text: string): this {
|
|
133
|
-
this.__config.comment = text;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Chainable column for string with database-level type annotations
|
|
140
|
-
*/
|
|
141
|
-
export class ChainableStringColumn extends ChainableColumn<"string"> {
|
|
142
|
-
constructor(config: StringColumnConfig = {}) {
|
|
143
|
-
super("string", config);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Set maximum character length - generates @db.VarChar(n) in Prisma
|
|
148
|
-
* @example dsl.string().maxLength(255)
|
|
149
|
-
*/
|
|
150
|
-
maxLength(n: number): this {
|
|
151
|
-
(this.__config as StringColumnConfig).maxLength = n;
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Mark as database text type - generates @db.Text in Prisma
|
|
157
|
-
* @example dsl.string().text()
|
|
158
|
-
*/
|
|
159
|
-
text(): this {
|
|
160
|
-
(this.__config as StringColumnConfig).text = true;
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Chainable column for decimal with precision/scale
|
|
167
|
-
*/
|
|
168
|
-
export class ChainableDecimalColumn extends ChainableColumn<"decimal"> {
|
|
169
|
-
constructor(config: DecimalColumnConfig = {}) {
|
|
170
|
-
super("decimal", config);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Set decimal precision - generates @db.Decimal(precision, scale) in Prisma
|
|
175
|
-
* @example dsl.decimal().precision(10, 2) // 10 digits total, 2 after decimal
|
|
176
|
-
*/
|
|
177
|
-
precision(p: number, s?: number): this {
|
|
178
|
-
(this.__config as DecimalColumnConfig).precision = p;
|
|
179
|
-
if (s !== undefined) {
|
|
180
|
-
(this.__config as DecimalColumnConfig).scale = s;
|
|
181
|
-
}
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Chainable column for datetime with additional datetime-specific methods
|
|
188
|
-
*/
|
|
189
|
-
export class ChainableDatetimeColumn extends ChainableColumn<"datetime"> {
|
|
190
|
-
constructor(config: DatetimeColumnConfig = {}) {
|
|
191
|
-
super("datetime", config);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Enable timezone support (@db.Timestamptz in Prisma)
|
|
196
|
-
*/
|
|
197
|
-
tz(): this {
|
|
198
|
-
(this.__config as DatetimeColumnConfig).tz = true;
|
|
199
|
-
return this;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Mark as auto-updated on record update (@updatedAt in Prisma)
|
|
204
|
-
*/
|
|
205
|
-
updatedAt(): this {
|
|
206
|
-
(this.__config as DatetimeColumnConfig).updatedAt = true;
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Set default to current timestamp
|
|
212
|
-
*/
|
|
213
|
-
defaultNow(): this {
|
|
214
|
-
(this.__config as DatetimeColumnConfig).default = "now";
|
|
215
|
-
return this;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Chainable column for ID with id-specific methods
|
|
221
|
-
*/
|
|
222
|
-
export class ChainableIdColumn extends ChainableColumn<"id"> {
|
|
223
|
-
constructor(config: IdColumnConfig = {}) {
|
|
224
|
-
super("id", { ...config, type: config.type ?? "ulid" });
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Set the ID generator type
|
|
229
|
-
*/
|
|
230
|
-
type(idType: "ulid" | "cuid" | "uuid" | "autoincrement" | "none"): this {
|
|
231
|
-
(this.__config as IdColumnConfig).type = idType;
|
|
232
|
-
return this;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// ─── Column Factory Functions ─────────────────────
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Creates a String column
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* dsl.string() // String, required
|
|
243
|
-
* dsl.string().optional() // String?
|
|
244
|
-
* dsl.string().unique().index() // String with @unique and @index
|
|
245
|
-
* dsl.string({ optional: true }) // Object style also supported
|
|
246
|
-
*/
|
|
247
|
-
export function string(config: StringColumnConfig = {}): ChainableStringColumn {
|
|
248
|
-
return new ChainableStringColumn(config);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Creates an Int column
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* dsl.int() // Int, required
|
|
256
|
-
* dsl.int().optional() // Int?
|
|
257
|
-
* dsl.int().default(0) // Int with default
|
|
258
|
-
*/
|
|
259
|
-
export function int(config: IntColumnConfig = {}): ChainableColumn<"int"> {
|
|
260
|
-
return new ChainableColumn("int", config);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Creates a Float column
|
|
265
|
-
*/
|
|
266
|
-
export function float(config: FloatColumnConfig = {}): ChainableColumn<"float"> {
|
|
267
|
-
return new ChainableColumn("float", config);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Creates a Decimal column
|
|
272
|
-
*/
|
|
273
|
-
export function decimal(config: DecimalColumnConfig = {}): ChainableDecimalColumn {
|
|
274
|
-
return new ChainableDecimalColumn(config);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Creates a Boolean column
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* dsl.boolean() // Boolean, required
|
|
282
|
-
* dsl.boolean().default(true) // Boolean with default
|
|
283
|
-
*/
|
|
284
|
-
export function boolean(config: BooleanColumnConfig = {}): ChainableColumn<"boolean"> {
|
|
285
|
-
return new ChainableColumn("boolean", config);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Creates a DateTime column
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* dsl.datetime() // DateTime
|
|
293
|
-
* dsl.datetime().defaultNow() // DateTime @default(now())
|
|
294
|
-
* dsl.datetime().defaultNow().updatedAt() // DateTime @default(now()) @updatedAt
|
|
295
|
-
* dsl.datetime().tz() // DateTime @db.Timestamptz()
|
|
296
|
-
*/
|
|
297
|
-
export function datetime(config: DatetimeColumnConfig = {}): ChainableDatetimeColumn {
|
|
298
|
-
return new ChainableDatetimeColumn(config);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Creates a Json column
|
|
303
|
-
*/
|
|
304
|
-
export function json(config: JsonColumnConfig = {}): ChainableColumn<"json"> {
|
|
305
|
-
return new ChainableColumn("json", config);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Creates an ID column (primary key)
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* dsl.id() // String @id @default(ulid()) - default
|
|
313
|
-
* dsl.id().type("cuid") // String @id @default(cuid())
|
|
314
|
-
* dsl.id({ type: "uuid" }) // String @id @default(uuid())
|
|
315
|
-
*/
|
|
316
|
-
export function id(config: IdColumnConfig = {}): ChainableIdColumn {
|
|
317
|
-
return new ChainableIdColumn(config);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Creates a Bytes column
|
|
322
|
-
*/
|
|
323
|
-
export function bytes(config: BytesColumnConfig = {}): ChainableColumn<"bytes"> {
|
|
324
|
-
return new ChainableColumn("bytes", config);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Creates a BigInt column for arbitrarily large integers
|
|
329
|
-
*
|
|
330
|
-
* @example
|
|
331
|
-
* dsl.bigint() // BigInt, required
|
|
332
|
-
* dsl.bigint().optional() // BigInt?
|
|
333
|
-
* dsl.bigint().default(0) // BigInt with default
|
|
334
|
-
*/
|
|
335
|
-
export function bigint(config: BigIntColumnConfig = {}): ChainableColumn<"bigint"> {
|
|
336
|
-
return new ChainableColumn("bigint", config);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Creates an Unsupported column for database-specific types that Prisma can't represent
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* dsl.unsupported("tsvector") // For PostgreSQL full-text search
|
|
344
|
-
* dsl.unsupported("geometry(Point, 4326)") // For PostGIS
|
|
345
|
-
* dsl.unsupported("cidr") // For PostgreSQL network types
|
|
346
|
-
*/
|
|
347
|
-
export function unsupported(dbType: string): ChainableColumn<"unsupported"> {
|
|
348
|
-
const config: UnsupportedColumnConfig = { dbType };
|
|
349
|
-
return new ChainableColumn("unsupported", config);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Creates an inline Enum column
|
|
354
|
-
*
|
|
355
|
-
* For standalone enums that can be reused, use dsl.enum({ name, options }) instead.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* // Inline enum (one-off use)
|
|
359
|
-
* dsl.enum({ options: ["a", "b", "c"] })
|
|
360
|
-
* dsl.enum({ options: ["a", "b"] }).default("a")
|
|
361
|
-
* dsl.enum({ options: ["active", "inactive"] }).optional().index()
|
|
362
|
-
*/
|
|
363
|
-
export function enumCol<const T extends readonly string[]>(
|
|
364
|
-
config: InlineEnumConfig<T>
|
|
365
|
-
): ChainableColumn<"enum"> {
|
|
366
|
-
// Extract options from config, rest goes to __config
|
|
367
|
-
const { options, ...restConfig } = config;
|
|
368
|
-
const col = new ChainableColumn("enum", restConfig);
|
|
369
|
-
col.__enumValues = options;
|
|
370
|
-
// No __enumName for inline enums - will auto-generate name from model+field
|
|
371
|
-
return col;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// ─── Column Namespace Export ─────────────────────
|
|
375
|
-
|
|
376
|
-
export const column = {
|
|
377
|
-
string,
|
|
378
|
-
int,
|
|
379
|
-
bigint,
|
|
380
|
-
float,
|
|
381
|
-
decimal,
|
|
382
|
-
boolean,
|
|
383
|
-
datetime,
|
|
384
|
-
json,
|
|
385
|
-
id,
|
|
386
|
-
bytes,
|
|
387
|
-
unsupported,
|
|
388
|
-
enum: enumCol,
|
|
389
|
-
};
|
package/src/enum.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standalone enum support for @vibeorm/dsl
|
|
3
|
-
*
|
|
4
|
-
* Allows defining enums separately and reusing them across models.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* // Define standalone enum
|
|
8
|
-
* const Status = dsl.enum({
|
|
9
|
-
* name: "Status",
|
|
10
|
-
* options: ["active", "inactive", "pending"],
|
|
11
|
-
* });
|
|
12
|
-
*
|
|
13
|
-
* // Use in model via .field()
|
|
14
|
-
* const User = dsl.create({
|
|
15
|
-
* name: "User",
|
|
16
|
-
* schema: {
|
|
17
|
-
* ...dsl.base,
|
|
18
|
-
* status: Status.field().default("active"),
|
|
19
|
-
* },
|
|
20
|
-
* });
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { ChainableColumn } from "./column.ts";
|
|
24
|
-
import type { EnumFieldConfig } from "./types.ts";
|
|
25
|
-
|
|
26
|
-
// ─── Standalone Enum Config ─────────────────────
|
|
27
|
-
|
|
28
|
-
export type StandaloneEnumConfig<T extends readonly string[]> = {
|
|
29
|
-
name: string;
|
|
30
|
-
options: T;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// ─── Standalone Enum Definition ─────────────────────
|
|
34
|
-
|
|
35
|
-
export type EnumDef<T extends readonly string[] = readonly string[]> = {
|
|
36
|
-
__type: "enum";
|
|
37
|
-
__name: string;
|
|
38
|
-
__options: T;
|
|
39
|
-
field(config?: EnumFieldConfig<T>): ChainableColumn<"enum">;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// ─── Standalone Enum Factory ─────────────────────
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Creates a standalone enum that can be reused across models
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* const Status = createEnum({
|
|
49
|
-
* name: "Status",
|
|
50
|
-
* options: ["active", "inactive", "pending"],
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* // Use in model with chaining
|
|
54
|
-
* status: Status.field().default("active")
|
|
55
|
-
* status: Status.field().optional().index()
|
|
56
|
-
*/
|
|
57
|
-
export function createEnum<const T extends readonly string[]>(
|
|
58
|
-
config: StandaloneEnumConfig<T>
|
|
59
|
-
): EnumDef<T> {
|
|
60
|
-
return {
|
|
61
|
-
__type: "enum",
|
|
62
|
-
__name: config.name,
|
|
63
|
-
__options: config.options,
|
|
64
|
-
field(fieldConfig: EnumFieldConfig<T> = {}): ChainableColumn<"enum"> {
|
|
65
|
-
const col = new ChainableColumn("enum", fieldConfig);
|
|
66
|
-
col.__enumValues = config.options;
|
|
67
|
-
col.__enumName = config.name; // Reference to standalone enum
|
|
68
|
-
return col;
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|