@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/dist/column.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column builders. Chainable style is encouraged; the config-object form is
|
|
3
|
+
* equivalent and fully supported.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* dsl.string().optional()
|
|
7
|
+
* dsl.string().unique().index()
|
|
8
|
+
* dsl.int().default(42)
|
|
9
|
+
* dsl.string({ optional: true })
|
|
10
|
+
*/
|
|
11
|
+
import type { BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, ColumnDef, ColumnType, DatetimeColumnConfig, DecimalColumnConfig, ExtensionTypeConfig, FloatColumnConfig, IdColumnConfig, IdGeneratorType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, StringColumnConfig } from "./types.ts";
|
|
12
|
+
/**
|
|
13
|
+
* Shallow-clones a column definition with a fresh `__config`, so columns
|
|
14
|
+
* spread from a template are never shared between models.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cloneColumnDef(params: {
|
|
17
|
+
column: ColumnDef;
|
|
18
|
+
}): ColumnDef;
|
|
19
|
+
/** Chainable column builder shared by every column kind. */
|
|
20
|
+
export declare class ChainableColumn<T extends ColumnType = ColumnType> implements ColumnDef<T> {
|
|
21
|
+
readonly __type: "column";
|
|
22
|
+
readonly __columnType: T;
|
|
23
|
+
__config: BaseColumnConfig;
|
|
24
|
+
__name?: string;
|
|
25
|
+
__enumValues?: readonly string[];
|
|
26
|
+
__enumName?: string;
|
|
27
|
+
constructor(columnType: T, config?: BaseColumnConfig);
|
|
28
|
+
/** Marks the column nullable (`Type?`). */
|
|
29
|
+
optional(): this;
|
|
30
|
+
/** Adds a `@unique` constraint. */
|
|
31
|
+
unique(): this;
|
|
32
|
+
/** Adds a single-column index. */
|
|
33
|
+
index(): this;
|
|
34
|
+
/** Marks the column as a list (`Type[]`). */
|
|
35
|
+
array(): this;
|
|
36
|
+
/** Sets a literal default value. */
|
|
37
|
+
default(value: unknown): this;
|
|
38
|
+
/** `@map("db_column")` — database column name when it differs. */
|
|
39
|
+
map(dbColumnName: string): this;
|
|
40
|
+
/** `@default(dbgenerated("expression"))` — database-native default. */
|
|
41
|
+
dbgenerated(expression: string): this;
|
|
42
|
+
/** Emits a `///` doc comment above the column. */
|
|
43
|
+
comment(text: string): this;
|
|
44
|
+
}
|
|
45
|
+
/** String column with database-level type annotations. */
|
|
46
|
+
export declare class ChainableStringColumn extends ChainableColumn<"string"> {
|
|
47
|
+
constructor(config?: StringColumnConfig);
|
|
48
|
+
/** `@db.VarChar(n)` */
|
|
49
|
+
maxLength(n: number): this;
|
|
50
|
+
/** `@db.Text` */
|
|
51
|
+
text(): this;
|
|
52
|
+
}
|
|
53
|
+
/** Decimal column carrying precision/scale. */
|
|
54
|
+
export declare class ChainableDecimalColumn extends ChainableColumn<"decimal"> {
|
|
55
|
+
constructor(config?: DecimalColumnConfig);
|
|
56
|
+
/** `@db.Decimal(precision, scale)` */
|
|
57
|
+
precision(p: number, s?: number): this;
|
|
58
|
+
}
|
|
59
|
+
/** DateTime column with timestamp-specific helpers. */
|
|
60
|
+
export declare class ChainableDatetimeColumn extends ChainableColumn<"datetime"> {
|
|
61
|
+
constructor(config?: DatetimeColumnConfig);
|
|
62
|
+
/** `@db.Timestamptz` — timezone-aware timestamp. */
|
|
63
|
+
tz(): this;
|
|
64
|
+
/** `@updatedAt` — refreshed on every update. */
|
|
65
|
+
updatedAt(): this;
|
|
66
|
+
/** `@default(now())` */
|
|
67
|
+
defaultNow(): this;
|
|
68
|
+
}
|
|
69
|
+
/** Primary-key column with a generator strategy. */
|
|
70
|
+
export declare class ChainableIdColumn extends ChainableColumn<"id"> {
|
|
71
|
+
constructor(config?: IdColumnConfig);
|
|
72
|
+
/** Sets the id generator strategy (default `"ulid"`). */
|
|
73
|
+
type(idType: IdGeneratorType): this;
|
|
74
|
+
}
|
|
75
|
+
/** Enum column whose `default()` is constrained to the declared options. */
|
|
76
|
+
export declare class ChainableEnumColumn<T extends readonly string[] = readonly string[]> extends ChainableColumn<"enum"> {
|
|
77
|
+
constructor(params: {
|
|
78
|
+
options: T;
|
|
79
|
+
config?: BaseColumnConfig;
|
|
80
|
+
enumName?: string;
|
|
81
|
+
});
|
|
82
|
+
/** Sets the default to one of the declared options. */
|
|
83
|
+
default(value: T[number]): this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* String column.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* dsl.string() // String
|
|
90
|
+
* dsl.string().optional() // String?
|
|
91
|
+
* dsl.string().unique().index() // String @unique + @@index
|
|
92
|
+
*/
|
|
93
|
+
export declare function string(config?: StringColumnConfig): ChainableStringColumn;
|
|
94
|
+
/** Int column. */
|
|
95
|
+
export declare function int(config?: IntColumnConfig): ChainableColumn<"int">;
|
|
96
|
+
/** Float column. */
|
|
97
|
+
export declare function float(config?: FloatColumnConfig): ChainableColumn<"float">;
|
|
98
|
+
/** Decimal column. */
|
|
99
|
+
export declare function decimal(config?: DecimalColumnConfig): ChainableDecimalColumn;
|
|
100
|
+
/** Boolean column. */
|
|
101
|
+
export declare function boolean(config?: BooleanColumnConfig): ChainableColumn<"boolean">;
|
|
102
|
+
/**
|
|
103
|
+
* DateTime column.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* dsl.datetime().defaultNow().updatedAt().tz()
|
|
107
|
+
*/
|
|
108
|
+
export declare function datetime(config?: DatetimeColumnConfig): ChainableDatetimeColumn;
|
|
109
|
+
/** Json column. */
|
|
110
|
+
export declare function json(config?: JsonColumnConfig): ChainableColumn<"json">;
|
|
111
|
+
/**
|
|
112
|
+
* Primary-key column.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* dsl.id() // String @id @default(ulid())
|
|
116
|
+
* dsl.id({ type: "uuid" }) // String @id @default(uuid())
|
|
117
|
+
* dsl.id().type("autoincrement") // Int @id @default(autoincrement())
|
|
118
|
+
*/
|
|
119
|
+
export declare function id(config?: IdColumnConfig): ChainableIdColumn;
|
|
120
|
+
/** Bytes column. */
|
|
121
|
+
export declare function bytes(config?: BytesColumnConfig): ChainableColumn<"bytes">;
|
|
122
|
+
/** BigInt column, for values beyond 32-bit ints. */
|
|
123
|
+
export declare function bigint(config?: BigIntColumnConfig): ChainableColumn<"bigint">;
|
|
124
|
+
/**
|
|
125
|
+
* Column with a database-native type Prisma cannot model.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* dsl.unsupported("tsvector")
|
|
129
|
+
* dsl.unsupported("geometry(Point, 4326)")
|
|
130
|
+
*/
|
|
131
|
+
export declare function unsupported(dbType: string): ChainableColumn<"unsupported">;
|
|
132
|
+
/**
|
|
133
|
+
* Column typed by a registered extension — the DSL twin of writing
|
|
134
|
+
* `embedding Vector(1536)` in .prisma. The extension registry lowers it to a
|
|
135
|
+
* native database type at `toIR` time; like `Unsupported`, it stays out of the
|
|
136
|
+
* core queryable surface (the extension's client plane covers it).
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* embedding: dsl.extensionType({ type: "Vector", args: [1536] })
|
|
140
|
+
*/
|
|
141
|
+
export declare function extensionType(config: ExtensionTypeConfig): ChainableColumn<"unsupported">;
|
|
142
|
+
/**
|
|
143
|
+
* Inline (one-off) enum column. For a reusable enum use
|
|
144
|
+
* `dsl.enum({ name, options })` and its `.field()`.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* dsl.enum({ options: ["low", "high"] }).default("low")
|
|
148
|
+
*/
|
|
149
|
+
export declare function enumCol<const T extends readonly string[]>(config: InlineEnumConfig<T>): ChainableEnumColumn<T>;
|
|
150
|
+
//# sourceMappingURL=column.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,mBAAmB,EACnB,mBAAm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E;AAED,sBAAsB;AACtB,wBAAgB,OAAO,CAAC,MAAM,GAAE,mBAAwB,GAAG,sBAAsB,CAEhF;AAED,sBAAsB;AACtB,wBAAgB,OAAO,CAAC,MAAM,GAAE,mBAAwB,GAAG,eAAe,CAAC,SAAS,CAAC,CAEpF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,GAAE,oBAAyB,GAAG,uBAAuB,CAEnF;AAED,mBAAmB;AACnB,wBAAgB,IAAI,CAAC,MAAM,GAAE,gBAAqB,GAAG,eAAe,CAAC,MAAM,CAAC,CAE3E;AAED;;;;;;;GAOG;AACH,wBAAgB,EAAE,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAEjE;AAED,oBAAoB;AACpB,wBAAgB,KAAK,CAAC,MAAM,GAAE,iBAAsB,GAAG,eAAe,CAAC,OAAO,CAAC,CAE9E;AAED,oDAAoD;AACpD,wBAAgB,MAAM,CAAC,MAAM,GAAE,kBAAuB,GAAG,eAAe,CAAC,QAAQ,CAAC,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,aAAa,CAAC,CAG1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAAC,aAAa,CAAC,CAQzF;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EACvD,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC1B,mBAAmB,CAAC,CAAC,CAAC,CAIxB"}
|
package/dist/enum.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone (named, reusable) enums.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const Status = dsl.enum({ name: "Status", options: ["active", "inactive"] });
|
|
6
|
+
*
|
|
7
|
+
* const User = dsl.create({
|
|
8
|
+
* name: "User",
|
|
9
|
+
* schema: { id: dsl.id(), status: Status.field().default("active") },
|
|
10
|
+
* });
|
|
11
|
+
*/
|
|
12
|
+
import type { EnumDef } from "./types.ts";
|
|
13
|
+
/** Config for a standalone enum — a `name` is what makes it standalone. */
|
|
14
|
+
export type StandaloneEnumConfig<T extends readonly string[] = readonly string[]> = {
|
|
15
|
+
name: string;
|
|
16
|
+
options: T;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates a reusable enum. Its `field()` yields a chainable enum column that
|
|
20
|
+
* references the enum by name, so every use shares one schema-level enum.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const Status = createEnum({ name: "Status", options: ["active", "inactive"] });
|
|
24
|
+
* status: Status.field().optional().index()
|
|
25
|
+
*/
|
|
26
|
+
export declare function createEnum<const T extends readonly string[]>(config: StandaloneEnumConfig<T>): EnumDef<T>;
|
|
27
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../src/enum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,YAAY,CAAC;AAI3D,2EAA2E;AAC3E,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,IAAI;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC;AAIF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,EAC1D,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC,CAUZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma schema text generator.
|
|
3
|
+
*
|
|
4
|
+
* Renders the schema plan (`relation-plan.ts`) — including the 1:1 merge pass —
|
|
5
|
+
* as `.prisma` models and enums. Only models and enums are emitted: datasource
|
|
6
|
+
* and generator blocks stay in the project's own base schema.
|
|
7
|
+
*
|
|
8
|
+
* The plan is shared with `toIR()`, so the text produced here parses back to
|
|
9
|
+
* the same IR the DSL compiles to directly.
|
|
10
|
+
*/
|
|
11
|
+
import type { PrismaGeneratorConfig, SchemaDef } from "../types.ts";
|
|
12
|
+
/**
|
|
13
|
+
* Generates Prisma schema text (models + enums) for a composed schema.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const prisma = dsl.generate.prisma(dsl.schema({ User }, { relations }));
|
|
17
|
+
*/
|
|
18
|
+
export declare function generatePrisma(schema: SchemaDef, _config?: PrismaGeneratorConfig): string;
|
|
19
|
+
//# sourceMappingURL=prisma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/generator/prisma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAIV,qBAAqB,EACrB,SAAS,EAEV,MAAM,aAAa,CAAC;AA+PrB;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAyB7F"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vibeorm/dsl — the TypeScript schema DSL.
|
|
3
|
+
*
|
|
4
|
+
* Models and relations are written in TypeScript and compiled straight to the
|
|
5
|
+
* canonical `SchemaIR` (`dsl.toIR`). `.prisma` text generation is kept for
|
|
6
|
+
* interop and `vibeorm convert`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { dsl } from "@vibeorm/dsl";
|
|
10
|
+
*
|
|
11
|
+
* const Workspace = dsl.create({
|
|
12
|
+
* name: "Workspace",
|
|
13
|
+
* schema: { ...dsl.templates.base, name: dsl.string() },
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const User = dsl.create({
|
|
17
|
+
* name: "User",
|
|
18
|
+
* schema: {
|
|
19
|
+
* ...dsl.templates.base,
|
|
20
|
+
* email: dsl.string().unique(),
|
|
21
|
+
* workspaceId: dsl.string().index(),
|
|
22
|
+
* },
|
|
23
|
+
* indexes: (i) => [i.unique("workspaceId", "email")],
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const relations = dsl.defineRelations({ Workspace, User }, (r) => ({
|
|
27
|
+
* Workspace: { users: r.many.User({ from: r.Workspace.id, to: r.User.workspaceId }) },
|
|
28
|
+
* User: { workspace: r.one.Workspace({ from: r.User.workspaceId, to: r.Workspace.id }) },
|
|
29
|
+
* }));
|
|
30
|
+
*
|
|
31
|
+
* const schema = dsl.schema({ Workspace, User }, { relations });
|
|
32
|
+
* const ir = dsl.toIR({ schema }); // canonical IR
|
|
33
|
+
* const prisma = dsl.generate.prisma(schema); // .prisma text
|
|
34
|
+
*/
|
|
35
|
+
import type { ExtensionRegistry, Provider, SchemaIR } from "@vibeorm/schema";
|
|
36
|
+
import type { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableIdColumn, ChainableStringColumn } from "./column.ts";
|
|
37
|
+
import type { StandaloneEnumConfig } from "./enum.ts";
|
|
38
|
+
import type { SchemaOptions } from "./schema.ts";
|
|
39
|
+
import type { TemplatesApi } from "./templates.ts";
|
|
40
|
+
import type { ValidationError } from "./validate.ts";
|
|
41
|
+
import type { BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, ModelDef, PrismaGeneratorConfig, RelationsBuilder, RelationsMap, RelationsOutput, SchemaDef, SchemaDefinition, SchemaInput, StringColumnConfig } from "./types.ts";
|
|
42
|
+
export { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableIdColumn, ChainableStringColumn, cloneColumnDef, } from "./column.ts";
|
|
43
|
+
export { createEnum } from "./enum.ts";
|
|
44
|
+
export { generatePrisma } from "./generator/prisma.ts";
|
|
45
|
+
export { create, createIndexBuilder, evaluateIndexes, getColumnNames } from "./model.ts";
|
|
46
|
+
export { children, createChildrenBuilder } from "./relation.ts";
|
|
47
|
+
export { detectOneToOnePairs, planSchema, resolveRelationType } from "./relation-plan.ts";
|
|
48
|
+
export { defineRelations, defineRelationsPart, mergeRelations } from "./relations.ts";
|
|
49
|
+
export { domain, schema } from "./schema.ts";
|
|
50
|
+
export { base, baseWithWorkspace, fields, templates, withActive, withAudit, withExternalId, withMetadata, withNameDescription, } from "./templates.ts";
|
|
51
|
+
export { toIR } from "./to-ir.ts";
|
|
52
|
+
export { validateSchema } from "./validate.ts";
|
|
53
|
+
export type { StandaloneEnumConfig } from "./enum.ts";
|
|
54
|
+
export type { MergedOneToOneSide, PlannedIndex, PlannedRelation, PlannedRelationKind, SchemaPlan, } from "./relation-plan.ts";
|
|
55
|
+
export type { SchemaOptions } from "./schema.ts";
|
|
56
|
+
export type { ActiveTemplate, AuditTemplate, BaseTemplate, BaseWithWorkspaceTemplate, ExternalIdTemplate, FieldsTemplate, MetadataTemplate, NameDescriptionTemplate, TemplatesApi, } from "./templates.ts";
|
|
57
|
+
export type { ValidationError } from "./validate.ts";
|
|
58
|
+
export type { BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CascadeAction, ChildrenBuilder, ChildrenDef, ChildrenRelationConfig, ChildrenSchemaCallback, ColumnDef, ColumnKeys, ColumnRef, ColumnType, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, EnumFieldConfig, ExtensionAttributeUse, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, IdGeneratorType, IndexBuilder, IndexCallback, IndexDef, IndexOptions, IndexType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, ManyRelationDefConfig, ModelColumnRefs, ModelDef, OneRelationDefConfig, PrismaGeneratorConfig, RelationsBuilder, RelationsMap, RelationsOutput, SchemaColumnNames, SchemaDef, SchemaDefinition, SchemaInput, StoredRelationDef, StringColumnConfig, ThroughRef, UnsupportedColumnConfig, } from "./types.ts";
|
|
59
|
+
/**
|
|
60
|
+
* Creates an enum: standalone (reusable, has a `name`) or inline (one-off).
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* const Status = dsl.enum({ name: "Status", options: ["active", "inactive"] });
|
|
64
|
+
* priority: dsl.enum({ options: ["low", "high"], default: "low" })
|
|
65
|
+
*/
|
|
66
|
+
export type EnumFactory = {
|
|
67
|
+
<const T extends readonly string[]>(config: StandaloneEnumConfig<T>): EnumDef<T>;
|
|
68
|
+
<const T extends readonly string[]>(config: InlineEnumConfig<T>): ChainableEnumColumn<T>;
|
|
69
|
+
};
|
|
70
|
+
/** `dsl.generate(schema)` plus the per-format generators. */
|
|
71
|
+
export type GenerateApi = {
|
|
72
|
+
(schema: SchemaDef): GeneratorOutput;
|
|
73
|
+
prisma: (schema: SchemaDef, config?: PrismaGeneratorConfig) => string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The `dsl` namespace surface. Every member carries an explicit signature —
|
|
77
|
+
* the package is built under `isolatedDeclarations`.
|
|
78
|
+
*/
|
|
79
|
+
export type DslApi = {
|
|
80
|
+
readonly string: (config?: StringColumnConfig) => ChainableStringColumn;
|
|
81
|
+
readonly int: (config?: IntColumnConfig) => ChainableColumn<"int">;
|
|
82
|
+
readonly bigint: (config?: BigIntColumnConfig) => ChainableColumn<"bigint">;
|
|
83
|
+
readonly float: (config?: FloatColumnConfig) => ChainableColumn<"float">;
|
|
84
|
+
readonly decimal: (config?: DecimalColumnConfig) => ChainableDecimalColumn;
|
|
85
|
+
readonly boolean: (config?: BooleanColumnConfig) => ChainableColumn<"boolean">;
|
|
86
|
+
readonly datetime: (config?: DatetimeColumnConfig) => ChainableDatetimeColumn;
|
|
87
|
+
readonly json: (config?: JsonColumnConfig) => ChainableColumn<"json">;
|
|
88
|
+
readonly id: (config?: IdColumnConfig) => ChainableIdColumn;
|
|
89
|
+
readonly bytes: (config?: BytesColumnConfig) => ChainableColumn<"bytes">;
|
|
90
|
+
readonly unsupported: (dbType: string) => ChainableColumn<"unsupported">;
|
|
91
|
+
readonly extensionType: (config: ExtensionTypeConfig) => ChainableColumn<"unsupported">;
|
|
92
|
+
readonly enum: EnumFactory;
|
|
93
|
+
readonly create: <const TSchema extends SchemaDefinition>(config: CreateModelConfig<TSchema>) => ModelDef<TSchema>;
|
|
94
|
+
readonly defineRelations: <TSchema extends Record<string, ModelDef>>(models: TSchema, callback: (r: RelationsBuilder<TSchema>) => RelationsOutput<TSchema>) => RelationsMap;
|
|
95
|
+
readonly defineRelationsPart: <TSchema extends Record<string, ModelDef>>(models: TSchema, callback: (r: RelationsBuilder<TSchema>) => Partial<RelationsOutput<TSchema>>) => RelationsMap;
|
|
96
|
+
readonly mergeRelations: (...parts: RelationsMap[]) => RelationsMap;
|
|
97
|
+
readonly schema: (input: SchemaInput, options?: SchemaOptions) => SchemaDef;
|
|
98
|
+
readonly domain: (params: {
|
|
99
|
+
name: string;
|
|
100
|
+
models: Record<string, ModelDef>;
|
|
101
|
+
}) => {
|
|
102
|
+
name: string;
|
|
103
|
+
models: Record<string, ModelDef>;
|
|
104
|
+
};
|
|
105
|
+
readonly toIR: (params: {
|
|
106
|
+
schema: SchemaDef;
|
|
107
|
+
provider?: Provider;
|
|
108
|
+
extensions?: ExtensionRegistry;
|
|
109
|
+
}) => SchemaIR;
|
|
110
|
+
readonly validateSchema: (schema: SchemaDef) => ValidationError[];
|
|
111
|
+
readonly generate: GenerateApi;
|
|
112
|
+
readonly templates: TemplatesApi;
|
|
113
|
+
};
|
|
114
|
+
/** The DSL namespace: columns, models, relations, schemas and output. */
|
|
115
|
+
export declare const dsl: DslApi;
|
|
116
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAiB7E,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAKtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAIpB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,sBAAs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