@vibeorm/dsl 0.3.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/schema.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema composer — combines models, standalone enums and relations into the
|
|
3
|
+
* `SchemaDef` that `toIR()` and `generate.prisma()` both consume.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const schema = dsl.schema({ User, Workspace }, { relations });
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // grouped by domain, plus a standalone enum
|
|
10
|
+
* const schema = dsl.schema({
|
|
11
|
+
* Status,
|
|
12
|
+
* shipping: { Carrier, CarrierService },
|
|
13
|
+
* }, { relations });
|
|
14
|
+
*/
|
|
15
|
+
import type { ModelDef, RelationsMap, SchemaDef, SchemaInput } from "./types.ts";
|
|
16
|
+
export type SchemaOptions = {
|
|
17
|
+
/** Relations produced by `defineRelations()` / `mergeRelations()`. */
|
|
18
|
+
relations?: RelationsMap;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Composes a schema from models (optionally grouped), standalone enums and
|
|
22
|
+
* the relations declared by `defineRelations()`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function schema(input: SchemaInput, options?: SchemaOptions): SchemaDef;
|
|
25
|
+
/**
|
|
26
|
+
* Groups models under a domain name, for organising large schemas.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const shipping = dsl.domain({ name: "Shipping", models: { Carrier } });
|
|
30
|
+
*/
|
|
31
|
+
export declare function domain(params: {
|
|
32
|
+
name: string;
|
|
33
|
+
models: Record<string, ModelDef>;
|
|
34
|
+
}): {
|
|
35
|
+
name: string;
|
|
36
|
+
models: Record<string, ModelDef>;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAW,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI1F,MAAM,MAAM,aAAa,GAAG;IAC1B,sEAAsE;IACtE,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B,CAAC;AA+EF;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAY7E;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;CAAE,GAAG;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClC,CAGA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in column templates for common model shapes.
|
|
3
|
+
*
|
|
4
|
+
* Every member is a getter, so each spread produces fresh column instances and
|
|
5
|
+
* two models never share mutable column state.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const User = dsl.create({
|
|
9
|
+
* name: "User",
|
|
10
|
+
* schema: { ...dsl.templates.base, email: dsl.string().unique() },
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
import type { ChainableColumn, ChainableDatetimeColumn, ChainableIdColumn, ChainableStringColumn } from "./column.ts";
|
|
14
|
+
export type BaseTemplate = {
|
|
15
|
+
readonly id: ChainableIdColumn;
|
|
16
|
+
readonly createdAt: ChainableDatetimeColumn;
|
|
17
|
+
readonly updatedAt: ChainableDatetimeColumn;
|
|
18
|
+
readonly deletedAt: ChainableDatetimeColumn;
|
|
19
|
+
};
|
|
20
|
+
export type BaseWithWorkspaceTemplate = BaseTemplate & {
|
|
21
|
+
readonly workspaceId: ChainableStringColumn;
|
|
22
|
+
};
|
|
23
|
+
export type MetadataTemplate = {
|
|
24
|
+
readonly metadata: ChainableColumn<"json">;
|
|
25
|
+
readonly settings: ChainableColumn<"json">;
|
|
26
|
+
};
|
|
27
|
+
export type ActiveTemplate = {
|
|
28
|
+
readonly isActive: ChainableColumn<"boolean">;
|
|
29
|
+
};
|
|
30
|
+
export type AuditTemplate = {
|
|
31
|
+
readonly createdById: ChainableStringColumn;
|
|
32
|
+
readonly updatedById: ChainableStringColumn;
|
|
33
|
+
};
|
|
34
|
+
export type ExternalIdTemplate = {
|
|
35
|
+
readonly externalId: ChainableStringColumn;
|
|
36
|
+
};
|
|
37
|
+
export type NameDescriptionTemplate = {
|
|
38
|
+
readonly name: ChainableStringColumn;
|
|
39
|
+
readonly description: ChainableStringColumn;
|
|
40
|
+
};
|
|
41
|
+
export type FieldsTemplate = {
|
|
42
|
+
readonly datetime: ChainableDatetimeColumn;
|
|
43
|
+
readonly id: ChainableIdColumn;
|
|
44
|
+
readonly title: ChainableStringColumn;
|
|
45
|
+
readonly description: ChainableStringColumn;
|
|
46
|
+
readonly externalId: ChainableStringColumn;
|
|
47
|
+
readonly metadata: ChainableColumn<"json">;
|
|
48
|
+
readonly settings: ChainableColumn<"json">;
|
|
49
|
+
readonly isActive: ChainableColumn<"boolean">;
|
|
50
|
+
};
|
|
51
|
+
export type TemplatesApi = {
|
|
52
|
+
readonly base: BaseTemplate;
|
|
53
|
+
readonly baseWithWorkspace: BaseWithWorkspaceTemplate;
|
|
54
|
+
readonly withMetadata: MetadataTemplate;
|
|
55
|
+
readonly withActive: ActiveTemplate;
|
|
56
|
+
readonly withAudit: AuditTemplate;
|
|
57
|
+
readonly withExternalId: ExternalIdTemplate;
|
|
58
|
+
readonly withNameDescription: NameDescriptionTemplate;
|
|
59
|
+
readonly fields: FieldsTemplate;
|
|
60
|
+
};
|
|
61
|
+
/** `id` (ULID), `createdAt`, `updatedAt`, `deletedAt`. */
|
|
62
|
+
export declare const base: BaseTemplate;
|
|
63
|
+
/** `base` plus an indexed `workspaceId`. */
|
|
64
|
+
export declare const baseWithWorkspace: BaseWithWorkspaceTemplate;
|
|
65
|
+
/** Optional `metadata` / `settings` JSON columns. */
|
|
66
|
+
export declare const withMetadata: MetadataTemplate;
|
|
67
|
+
/** `isActive` boolean defaulting to true. */
|
|
68
|
+
export declare const withActive: ActiveTemplate;
|
|
69
|
+
/** Optional, indexed `createdById` / `updatedById`. */
|
|
70
|
+
export declare const withAudit: AuditTemplate;
|
|
71
|
+
/** Indexed `externalId` for integrations. */
|
|
72
|
+
export declare const withExternalId: ExternalIdTemplate;
|
|
73
|
+
/** `name` plus optional `description`. */
|
|
74
|
+
export declare const withNameDescription: NameDescriptionTemplate;
|
|
75
|
+
/** Pre-configured single columns, for cherry-picking. */
|
|
76
|
+
export declare const fields: FieldsTemplate;
|
|
77
|
+
/** Every template, as exposed on `dsl.templates`. */
|
|
78
|
+
export declare const templates: TemplatesApi;
|
|
79
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,uBAAuB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,uBAAuB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,uBAAuB,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,YAAY,GAAG;IACrD,QAAQ,CAAC,WAAW,EAAE,qBAAqB,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;CAC5C,CAAC;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AAkB,CAAC;IAC5C,QAAQ,CAAC,mBAAmB,EAAE,uBAAuB,CAAC;IACtD,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACjC,CAAC;AAIF,0DAA0D;AAC1D,eAAO,MAAM,IAAI,EAAE,YAalB,CAAC;AAEF,4CAA4C;AAC5C,eAAO,MAAM,iBAAiB,EAAE,yBAgB/B,CAAC;AAIF,qDAAqD;AACrD,eAAO,MAAM,YAAY,EAAE,gBAO1B,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,UAAU,EAAE,cAIxB,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,SAAS,EAAE,aAOvB,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,cAAc,EAAE,kBAI5B,CAAC;AAEF,0CAA0C;AAC1C,eAAO,MAAM,mBAAmB,EAAE,uBAOjC,CAAC;AAIF,yDAAyD;AACzD,eAAO,MAAM,MAAM,EAAE,cAyBpB,CAAC;AAIF,qDAAqD;AACrD,eAAO,MAAM,SAAS,EAAE,YASvB,CAAC"}
|
package/dist/to-ir.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL → canonical `SchemaIR`.
|
|
3
|
+
*
|
|
4
|
+
* The DSL compiles straight to IR (no `.prisma` round-trip). It reads the same
|
|
5
|
+
* schema plan the Prisma generator renders, so one logical schema produces the
|
|
6
|
+
* same IR whether it arrives as `.prisma` text or as TypeScript.
|
|
7
|
+
*
|
|
8
|
+
* Mapping decisions, all mirroring what parsing `generate.prisma(schema)` yields:
|
|
9
|
+
* - `dsl.id()` → `isId` + a `DefaultValueIR` per strategy (`ulid` / `cuid` /
|
|
10
|
+
* `uuid` / `nanoid` app-side, `autoincrement` for serial ints, which is the
|
|
11
|
+
* only strategy typed `Int`; `"none"` emits no default).
|
|
12
|
+
* - `dsl.datetime({ default: "now" })` → `{ kind: "now" }`; `.updatedAt()` →
|
|
13
|
+
* `isUpdatedAt`; `.tz()` → native type `Timestamptz`.
|
|
14
|
+
* - `.maxLength(n)` / `.text()` / `.precision(p, s)` → native types
|
|
15
|
+
* `VarChar(n)` / `Text` / `Decimal(p, s)`.
|
|
16
|
+
* - `.map()` / model `map` → `dbName`; `.comment()` → `documentation`.
|
|
17
|
+
* - `dsl.unsupported("tsvector")` → `isUnsupported: true` + native type
|
|
18
|
+
* `"tsvector"` over a nominal `String` base. The flag is what keeps the column
|
|
19
|
+
* OUT of the queryable surface — it is kept in the IR for schema fidelity
|
|
20
|
+
* (convert, migrate DDL), never projected or written.
|
|
21
|
+
* - inline enums become schema-level enums named `${Model}${Column}`.
|
|
22
|
+
* - relation types are derived structurally by `resolveRelationType`.
|
|
23
|
+
*/
|
|
24
|
+
import type { ExtensionRegistry, Provider, SchemaIR } from "@vibeorm/schema";
|
|
25
|
+
import type { SchemaDef } from "./types.ts";
|
|
26
|
+
/**
|
|
27
|
+
* Compiles a composed DSL schema to the canonical `SchemaIR`, then validates it.
|
|
28
|
+
*
|
|
29
|
+
* @throws VibeError `VIBE_SCHEMA_INVALID` when the resulting IR fails
|
|
30
|
+
* `assertValidSchemaIR` (unknown relation targets, missing primary keys, …).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const ir = dsl.toIR({ schema: dsl.schema({ User }, { relations }) });
|
|
34
|
+
* const sqlite = dsl.toIR({ schema, provider: "sqlite" });
|
|
35
|
+
*/
|
|
36
|
+
export declare function toIR(params: {
|
|
37
|
+
schema: SchemaDef;
|
|
38
|
+
provider?: Provider;
|
|
39
|
+
extensions?: ExtensionRegistry;
|
|
40
|
+
}): SchemaIR;
|
|
41
|
+
//# sourceMappingURL=to-ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-ir.d.ts","sourceRoot":"","sources":["../src/to-ir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAQH,OAAO,KAAK,EAIV,iBAAiB,EAMjB,QAAQ,EAER,QAAQ,EAET,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAMV,SAAS,EAEV,MAAM,YAAY,CAAC;AAuUpB;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE;IAC3B,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC,GAAG,QAAQ,CAkCX"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for @vibeorm/dsl.
|
|
3
|
+
*
|
|
4
|
+
* Models hold columns (and inline children); relations are declared separately
|
|
5
|
+
* through `defineRelations` (Drizzle-style), which keeps column references
|
|
6
|
+
* type-safe without inference-heavy model types.
|
|
7
|
+
*/
|
|
8
|
+
import type { CascadeAction, ExtensionAttributeValue } from "@vibeorm/schema";
|
|
9
|
+
import type { ChainableEnumColumn } from "./column.ts";
|
|
10
|
+
/** Referential actions, re-exported from the IR so both sources agree. */
|
|
11
|
+
export type { CascadeAction };
|
|
12
|
+
/** Column kinds the DSL can declare. */
|
|
13
|
+
export type ColumnType = "string" | "int" | "bigint" | "float" | "decimal" | "boolean" | "datetime" | "json" | "id" | "bytes" | "enum" | "unsupported";
|
|
14
|
+
/** Primary-key generator strategies for `dsl.id()`. */
|
|
15
|
+
export type IdGeneratorType = "ulid" | "cuid" | "uuid" | "nanoid" | "autoincrement" | "none";
|
|
16
|
+
/** PostgreSQL index types Prisma can express via `@@index(..., type: X)`. */
|
|
17
|
+
export type IndexType = "BTree" | "Hash" | "Gin" | "Gist" | "SpGist" | "Brin";
|
|
18
|
+
/** Options every column kind accepts. */
|
|
19
|
+
export type BaseColumnConfig = {
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
index?: boolean;
|
|
22
|
+
unique?: boolean;
|
|
23
|
+
array?: boolean;
|
|
24
|
+
/** `@map("column_name")` — database column name when it differs. */
|
|
25
|
+
map?: string;
|
|
26
|
+
/** `@default(dbgenerated("..."))` — database-native default expression. */
|
|
27
|
+
dbgenerated?: string;
|
|
28
|
+
/** Emitted as a `///` doc comment above the column (Zod generators, docs). */
|
|
29
|
+
comment?: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
export type StringColumnConfig = BaseColumnConfig & {
|
|
33
|
+
default?: string;
|
|
34
|
+
/** `@db.VarChar(n)` */
|
|
35
|
+
maxLength?: number;
|
|
36
|
+
/** `@db.Text` */
|
|
37
|
+
text?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type IntColumnConfig = BaseColumnConfig & {
|
|
40
|
+
default?: number;
|
|
41
|
+
};
|
|
42
|
+
export type FloatColumnConfig = BaseColumnConfig & {
|
|
43
|
+
default?: number;
|
|
44
|
+
};
|
|
45
|
+
export type DecimalColumnConfig = BaseColumnConfig & {
|
|
46
|
+
default?: string;
|
|
47
|
+
/** `@db.Decimal(precision, scale)` */
|
|
48
|
+
precision?: number;
|
|
49
|
+
/** `@db.Decimal(precision, scale)` */
|
|
50
|
+
scale?: number;
|
|
51
|
+
};
|
|
52
|
+
export type BooleanColumnConfig = BaseColumnConfig & {
|
|
53
|
+
default?: boolean;
|
|
54
|
+
};
|
|
55
|
+
export type DatetimeColumnConfig = BaseColumnConfig & {
|
|
56
|
+
default?: "now";
|
|
57
|
+
updatedAt?: boolean;
|
|
58
|
+
/** `@db.Timestamptz` */
|
|
59
|
+
tz?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type JsonColumnConfig = BaseColumnConfig & {
|
|
62
|
+
default?: unknown;
|
|
63
|
+
};
|
|
64
|
+
export type IdColumnConfig = BaseColumnConfig & {
|
|
65
|
+
type?: IdGeneratorType;
|
|
66
|
+
};
|
|
67
|
+
export type BytesColumnConfig = BaseColumnConfig;
|
|
68
|
+
export type BigIntColumnConfig = BaseColumnConfig & {
|
|
69
|
+
default?: bigint | number;
|
|
70
|
+
};
|
|
71
|
+
export type UnsupportedColumnConfig = BaseColumnConfig & {
|
|
72
|
+
/** Raw database type, e.g. "tsvector" or "geometry(Point, 4326)". */
|
|
73
|
+
dbType: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Config for `dsl.extensionType()` — a column typed by a registered extension
|
|
77
|
+
* (`Vector(1536)`). Lowered to a native type by the extension registry at
|
|
78
|
+
* `toIR` time, exactly like the .prisma parser does.
|
|
79
|
+
*/
|
|
80
|
+
export type ExtensionTypeConfig = BaseColumnConfig & {
|
|
81
|
+
/** Type name as the extension registers it, e.g. "Vector". */
|
|
82
|
+
type: string;
|
|
83
|
+
/** Positional type arguments (`Vector(1536)` → [1536]). */
|
|
84
|
+
args?: readonly (string | number)[];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* One extension model attribute on a `dsl.create` model — the DSL twin of
|
|
88
|
+
* `@@search([title, body], name: "x")`. Routed through the same
|
|
89
|
+
* `ExtensionModelAttribute.parse` hook as the .prisma parser, so both sources
|
|
90
|
+
* produce identical IR.
|
|
91
|
+
*/
|
|
92
|
+
export type ExtensionAttributeUse = {
|
|
93
|
+
/** Attribute name without `@@`, e.g. "search". */
|
|
94
|
+
readonly attribute: string;
|
|
95
|
+
/** The positional field list (`[title, body]`). */
|
|
96
|
+
readonly fields?: readonly string[];
|
|
97
|
+
/** Named arguments (`name: "x"`, `weights: [2, 1]`). */
|
|
98
|
+
readonly args?: Readonly<Record<string, ExtensionAttributeValue>>;
|
|
99
|
+
};
|
|
100
|
+
/** Inline (one-off) enum column config. */
|
|
101
|
+
export type InlineEnumConfig<T extends readonly string[] = readonly string[]> = BaseColumnConfig & {
|
|
102
|
+
options: T;
|
|
103
|
+
default?: T[number];
|
|
104
|
+
};
|
|
105
|
+
/** Field config for a column created from a standalone enum. */
|
|
106
|
+
export type EnumFieldConfig<T extends readonly string[] = readonly string[]> = BaseColumnConfig & {
|
|
107
|
+
default?: T[number];
|
|
108
|
+
};
|
|
109
|
+
/** A reusable, named enum. `field()` produces a chainable enum column. */
|
|
110
|
+
export type EnumDef<T extends readonly string[] = readonly string[]> = {
|
|
111
|
+
readonly __type: "enum";
|
|
112
|
+
readonly __name: string;
|
|
113
|
+
readonly __options: T;
|
|
114
|
+
field(config?: EnumFieldConfig<T>): ChainableEnumColumn<T>;
|
|
115
|
+
};
|
|
116
|
+
/** The structural shape every column builder satisfies. */
|
|
117
|
+
export type ColumnDef<T extends ColumnType = ColumnType> = {
|
|
118
|
+
readonly __type: "column";
|
|
119
|
+
readonly __columnType: T;
|
|
120
|
+
__name?: string;
|
|
121
|
+
__config: BaseColumnConfig;
|
|
122
|
+
__enumValues?: readonly string[];
|
|
123
|
+
/** Resolved enum name — assigned by `dsl.schema()` for inline enums. */
|
|
124
|
+
__enumName?: string;
|
|
125
|
+
};
|
|
126
|
+
export type ChildrenRelationConfig = {
|
|
127
|
+
name: string;
|
|
128
|
+
schema: SchemaDefinition | ChildrenSchemaCallback;
|
|
129
|
+
};
|
|
130
|
+
export type ChildrenDef = {
|
|
131
|
+
readonly __type: "children";
|
|
132
|
+
readonly __name: string;
|
|
133
|
+
readonly __schema: SchemaDefinition | ChildrenSchemaCallback;
|
|
134
|
+
};
|
|
135
|
+
/** Builder handed to a model's schema callback; only exposes `children()`. */
|
|
136
|
+
export type ChildrenBuilder = {
|
|
137
|
+
children(config: ChildrenRelationConfig): ChildrenDef;
|
|
138
|
+
};
|
|
139
|
+
/** A model's schema: columns plus optional inline children. */
|
|
140
|
+
export type SchemaDefinition = Record<string, ColumnDef | ChildrenDef>;
|
|
141
|
+
export type ChildrenSchemaCallback = (s: ChildrenBuilder) => SchemaDefinition;
|
|
142
|
+
export type IndexDef = {
|
|
143
|
+
readonly __type: "index" | "unique";
|
|
144
|
+
readonly __columns: readonly string[];
|
|
145
|
+
readonly __indexType?: IndexType;
|
|
146
|
+
};
|
|
147
|
+
/** Options accepted by the array form of `i.on([...], options)`. */
|
|
148
|
+
export type IndexOptions = {
|
|
149
|
+
type?: IndexType;
|
|
150
|
+
};
|
|
151
|
+
/** Index builder; column names are constrained to the model's own columns. */
|
|
152
|
+
export type IndexBuilder<TColumns extends string = string> = {
|
|
153
|
+
on<T extends TColumns>(...columns: T[]): IndexDef;
|
|
154
|
+
on<T extends TColumns>(columns: T[], options: IndexOptions): IndexDef;
|
|
155
|
+
/** Alias of `on(...)` — reads better next to `unique(...)`. */
|
|
156
|
+
index<T extends TColumns>(...columns: T[]): IndexDef;
|
|
157
|
+
unique<T extends TColumns>(...columns: T[]): IndexDef;
|
|
158
|
+
gin<T extends TColumns>(...columns: T[]): IndexDef;
|
|
159
|
+
gist<T extends TColumns>(...columns: T[]): IndexDef;
|
|
160
|
+
hash<T extends TColumns>(...columns: T[]): IndexDef;
|
|
161
|
+
brin<T extends TColumns>(...columns: T[]): IndexDef;
|
|
162
|
+
};
|
|
163
|
+
export type IndexCallback<TColumns extends string = string> = (i: IndexBuilder<TColumns>) => IndexDef[];
|
|
164
|
+
/** A model. `TSchema` is preserved so relations can reference real columns. */
|
|
165
|
+
export type ModelDef<TSchema extends SchemaDefinition = SchemaDefinition> = {
|
|
166
|
+
readonly __type: "model";
|
|
167
|
+
readonly __name: string;
|
|
168
|
+
readonly __schema: TSchema | ChildrenSchemaCallback;
|
|
169
|
+
readonly __indexes?: IndexCallback;
|
|
170
|
+
readonly __columns: Map<string, ColumnDef>;
|
|
171
|
+
readonly __children: Map<string, ModelDef>;
|
|
172
|
+
/** `@@map("table_name")` */
|
|
173
|
+
readonly __map?: string;
|
|
174
|
+
/** `@@id([...])` — compound primary key. */
|
|
175
|
+
readonly __primaryKey?: readonly string[];
|
|
176
|
+
/** Extension attributes declared on the model (`@@search`-style). */
|
|
177
|
+
readonly __extensions?: readonly ExtensionAttributeUse[];
|
|
178
|
+
};
|
|
179
|
+
/** Keys of a model schema whose value is a column (children excluded). */
|
|
180
|
+
export type ColumnKeys<T> = {
|
|
181
|
+
[K in keyof T]: T[K] extends ColumnDef ? K : never;
|
|
182
|
+
}[keyof T];
|
|
183
|
+
/** Valid column names of a model schema, for index callbacks. */
|
|
184
|
+
export type SchemaColumnNames<T> = Extract<ColumnKeys<T>, string>;
|
|
185
|
+
/** Config accepted by `dsl.create()`. */
|
|
186
|
+
export type CreateModelConfig<TSchema extends SchemaDefinition = SchemaDefinition> = {
|
|
187
|
+
name: string;
|
|
188
|
+
schema: TSchema | ((s: ChildrenBuilder) => TSchema);
|
|
189
|
+
indexes?: IndexCallback<SchemaColumnNames<TSchema>>;
|
|
190
|
+
/** `@@map("table_name")` — database table name when it differs. */
|
|
191
|
+
map?: string;
|
|
192
|
+
/** `@@id([...])` — compound primary key columns. */
|
|
193
|
+
primaryKey?: SchemaColumnNames<TSchema>[];
|
|
194
|
+
/** Extension model attributes (`@@search`-style declarations). */
|
|
195
|
+
extensions?: readonly ExtensionAttributeUse[];
|
|
196
|
+
};
|
|
197
|
+
/** A reference to `Model.column`, used for relation `from` / `to`. */
|
|
198
|
+
export type ColumnRef<TModel extends string = string, TColumn extends string = string> = {
|
|
199
|
+
readonly __type: "columnRef";
|
|
200
|
+
readonly __model: TModel;
|
|
201
|
+
readonly __column: TColumn;
|
|
202
|
+
through<TJunction extends string, TJunctionCol extends string>(junction: ColumnRef<TJunction, TJunctionCol>): ThroughRef<TModel, TColumn, TJunction, TJunctionCol>;
|
|
203
|
+
};
|
|
204
|
+
/** A column reference routed through a junction model (many-to-many). */
|
|
205
|
+
export type ThroughRef<TModel extends string = string, TColumn extends string = string, TJunction extends string = string, TJunctionCol extends string = string> = {
|
|
206
|
+
readonly __type: "throughRef";
|
|
207
|
+
readonly __model: TModel;
|
|
208
|
+
readonly __column: TColumn;
|
|
209
|
+
readonly __junction: TJunction;
|
|
210
|
+
readonly __junctionColumn: TJunctionCol;
|
|
211
|
+
};
|
|
212
|
+
/** Config for `r.one.Model({ from, to })`. */
|
|
213
|
+
export type OneRelationDefConfig<TFrom extends ColumnRef | ThroughRef = ColumnRef, TTo extends ColumnRef | ThroughRef = ColumnRef> = {
|
|
214
|
+
from: TFrom;
|
|
215
|
+
to: TTo;
|
|
216
|
+
optional?: boolean;
|
|
217
|
+
/** `@relation("Name")` — disambiguates multiple relations between a pair. */
|
|
218
|
+
alias?: string;
|
|
219
|
+
onDelete?: CascadeAction;
|
|
220
|
+
onUpdate?: CascadeAction;
|
|
221
|
+
};
|
|
222
|
+
/** Config for `r.many.Model({ from, to })`. */
|
|
223
|
+
export type ManyRelationDefConfig<TFrom extends ColumnRef | ThroughRef = ColumnRef | ThroughRef, TTo extends ColumnRef | ThroughRef = ColumnRef | ThroughRef> = {
|
|
224
|
+
from: TFrom;
|
|
225
|
+
to: TTo;
|
|
226
|
+
optional?: boolean;
|
|
227
|
+
alias?: string;
|
|
228
|
+
onDelete?: CascadeAction;
|
|
229
|
+
onUpdate?: CascadeAction;
|
|
230
|
+
};
|
|
231
|
+
/** A relation as stored by `defineRelations`. */
|
|
232
|
+
export type StoredRelationDef = {
|
|
233
|
+
readonly __type: "storedRelation";
|
|
234
|
+
readonly __relationType: "one" | "many";
|
|
235
|
+
readonly __targetModel: string;
|
|
236
|
+
readonly __fromModel: string;
|
|
237
|
+
readonly __fromColumn: string;
|
|
238
|
+
readonly __toModel: string;
|
|
239
|
+
readonly __toColumn: string;
|
|
240
|
+
readonly __throughJunction?: string;
|
|
241
|
+
readonly __throughFromCol?: string;
|
|
242
|
+
readonly __throughToCol?: string;
|
|
243
|
+
readonly __optional: boolean;
|
|
244
|
+
readonly __alias?: string;
|
|
245
|
+
readonly __onDelete?: CascadeAction;
|
|
246
|
+
readonly __onUpdate?: CascadeAction;
|
|
247
|
+
};
|
|
248
|
+
/** `{ ModelName: { relationName: StoredRelationDef } }`. */
|
|
249
|
+
export type RelationsMap = Record<string, Record<string, StoredRelationDef>>;
|
|
250
|
+
/** Column names of a `ModelDef`, extracted from its schema type. */
|
|
251
|
+
export type ExtractModelColumns<T> = T extends ModelDef<infer TSchema> ? Extract<keyof TSchema, string> : never;
|
|
252
|
+
/** `r.User.id`, `r.User.email`, … */
|
|
253
|
+
export type ModelColumnRefs<TModelName extends string, TModel extends ModelDef> = {
|
|
254
|
+
[C in ExtractModelColumns<TModel>]: ColumnRef<TModelName, C>;
|
|
255
|
+
};
|
|
256
|
+
/** The `r` handed to a `defineRelations` callback. */
|
|
257
|
+
export type RelationsBuilder<TSchema extends Record<string, ModelDef>> = {
|
|
258
|
+
one: {
|
|
259
|
+
[K in keyof TSchema & string]: <TFrom extends ColumnRef | ThroughRef, TTo extends ColumnRef | ThroughRef>(config: OneRelationDefConfig<TFrom, TTo>) => StoredRelationDef;
|
|
260
|
+
};
|
|
261
|
+
many: {
|
|
262
|
+
[K in keyof TSchema & string]: <TFrom extends ColumnRef | ThroughRef, TTo extends ColumnRef | ThroughRef>(config: ManyRelationDefConfig<TFrom, TTo>) => StoredRelationDef;
|
|
263
|
+
};
|
|
264
|
+
} & {
|
|
265
|
+
[K in keyof TSchema & string]: ModelColumnRefs<K, TSchema[K]>;
|
|
266
|
+
};
|
|
267
|
+
/** Return type of a `defineRelations` callback. */
|
|
268
|
+
export type RelationsOutput<TSchema extends Record<string, ModelDef>> = {
|
|
269
|
+
[K in keyof TSchema]?: Record<string, StoredRelationDef>;
|
|
270
|
+
};
|
|
271
|
+
/** Models and standalone enums, optionally grouped into nested objects. */
|
|
272
|
+
export type SchemaInput = Record<string, ModelDef | EnumDef | Record<string, ModelDef | EnumDef>>;
|
|
273
|
+
/** A composed schema: the DSL's own currency, compiled by `toIR`. */
|
|
274
|
+
export type SchemaDef = {
|
|
275
|
+
readonly __type: "schema";
|
|
276
|
+
readonly __models: Map<string, ModelDef>;
|
|
277
|
+
readonly __enums: Map<string, readonly string[]>;
|
|
278
|
+
readonly __relations: RelationsMap;
|
|
279
|
+
};
|
|
280
|
+
export type PrismaGeneratorConfig = {
|
|
281
|
+
output?: string;
|
|
282
|
+
};
|
|
283
|
+
export type GeneratorOutput = {
|
|
284
|
+
prisma?: string;
|
|
285
|
+
};
|
|
286
|
+
//# sourceMapp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I,MAAM,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACzD,CAAC;AAIF,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GAAG,MAAM,CAC9B,MAAM,EACN,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,CACxD,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IACjD,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;CACpC,CAAC;AAIF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL-level schema checks, run before compiling to IR.
|
|
3
|
+
*
|
|
4
|
+
* These catch authoring mistakes in DSL terms (a relation pointing at a column
|
|
5
|
+
* that does not exist, an ambiguous self-relation) and return them as a list —
|
|
6
|
+
* structural IR rules live in `@vibeorm/schema`'s `validateSchemaIR`, which
|
|
7
|
+
* `toIR()` always enforces.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const issues = dsl.validateSchema(schema);
|
|
11
|
+
* if (issues.some((i) => i.type === "error")) throw new Error("bad schema");
|
|
12
|
+
*/
|
|
13
|
+
import type { SchemaDef } from "./types.ts";
|
|
14
|
+
export type ValidationError = {
|
|
15
|
+
type: "error" | "warning";
|
|
16
|
+
message: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
relation?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Validates a composed schema; an empty array means no issues were found. */
|
|
21
|
+
export declare function validateSchema(schema: SchemaDef): ValidationError[];
|
|
22
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAqB,MAAM,YAAY,CAAC;AAI/D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,eAAe,EAAE,CAqGnE"}
|
package/package.json
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/dsl",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript DSL for
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "TypeScript schema DSL for VibeORM v2 — compiles to canonical SchemaIR, with .prisma generation for interop",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"orm",
|
|
8
|
-
"dsl",
|
|
9
|
-
"prisma",
|
|
10
|
-
"schema",
|
|
11
7
|
"typescript",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
8
|
+
"sql",
|
|
9
|
+
"database",
|
|
10
|
+
"bun",
|
|
11
|
+
"type-safe",
|
|
12
|
+
"schema",
|
|
13
|
+
"dsl",
|
|
14
|
+
"code-first",
|
|
15
|
+
"prisma"
|
|
14
16
|
],
|
|
17
|
+
"homepage": "https://github.com/vibeorm/vibeorm/tree/master/packages/dsl#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/vibeorm/vibeorm/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/vibeorm/vibeorm.git",
|
|
24
|
+
"directory": "packages/dsl"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "VibeORM contributors",
|
|
15
28
|
"type": "module",
|
|
16
29
|
"exports": {
|
|
17
30
|
".": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
20
33
|
}
|
|
21
34
|
},
|
|
22
35
|
"files": [
|
|
23
|
-
"
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
24
38
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"url": "https://github.com/vibeorm/vibeorm.git",
|
|
28
|
-
"directory": "packages/dsl"
|
|
39
|
+
"engines": {
|
|
40
|
+
"bun": ">=1.2.0"
|
|
29
41
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"url": "https://github.com/vibeorm/vibeorm/issues"
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@vibeorm/schema": "2.0.0-alpha.1"
|
|
33
44
|
},
|
|
34
45
|
"publishConfig": {
|
|
35
46
|
"access": "public"
|
|
36
|
-
},
|
|
37
|
-
"engines": {
|
|
38
|
-
"bun": ">=1.1.0"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@types/bun": "latest",
|
|
42
|
-
"prisma": "^7.3.0",
|
|
43
|
-
"typescript": "^5.9.3"
|
|
44
47
|
}
|
|
45
48
|
}
|