@vibeorm/dsl 4.1.0 → 4.3.0

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 CHANGED
@@ -63,13 +63,13 @@ To go to the IR yourself: `dsl.toIR({ schema })` returns a `SchemaIR`, optionall
63
63
 
64
64
  `dsl.enum` has two forms: with a `name` it creates a reusable enum whose `.field()` yields a column, without one it creates an inline single-use enum column.
65
65
 
66
- Id strategies are `dsl.id({ type: "ulid" | "uuid" | "cuid" | "nanoid" | "autoincrement" | "none" })`. The default is `"ulid"`, a `String` column generated in the app; `"autoincrement"` makes it an `Int`.
66
+ Id strategies are `dsl.id({ type: "ulid" | "uuid" | "cuid" | "nanoid" | "autoincrement" | "none" })`. The default is `"ulid"`, a `String` column generated in the app; `"autoincrement"` makes it an `Int`. A key the database mints takes `type: "none"` with a database default: `dsl.id({ type: "none" }).uuid().dbgenerated("uuidv7()")` is Prisma's `String @id @db.Uuid @default(dbgenerated("uuidv7()"))`.
67
67
 
68
68
  ## Chainable modifiers
69
69
 
70
70
  On every column: `.optional()`, `.unique()`, `.index()`, `.array()`, `.default(value)`, `.map("db_col")`, `.dbgenerated("expr")`, `.comment("...")`.
71
71
 
72
- Kind-specific: `.maxLength(n)` and `.text()` on strings, `.precision(p, s)` on decimals, `.defaultNow()`, `.updatedAt()` and `.tz()` on datetimes. `.tz({ precision: 3 })` declares `@db.Timestamptz(3)`: it stores exactly what a JavaScript `Date` holds, so a database-written time reads back unchanged and `findPage` can order by the column without an assertion.
72
+ Kind-specific: `.maxLength(n)`, `.text()` and `.uuid()` on strings (`.uuid()` also on ids), `.precision(p, s)` on decimals, `.defaultNow()`, `.updatedAt()` and `.tz()` on datetimes. `.tz({ precision: 3 })` declares `@db.Timestamptz(3)`: it stores exactly what a JavaScript `Date` holds, so a database-written time reads back unchanged and `findPage` can order by the column without an assertion. `.uuid()` declares `@db.Uuid`: PostgreSQL's native uuid type (the value stays a `string`); SQLite stores it as `TEXT`; MySQL has no uuid type and refuses the schema with `VIBE_UNSUPPORTED_CAPABILITY`.
73
73
 
74
74
  ### Database defaults
75
75
 
package/dist/column.d.ts CHANGED
@@ -8,8 +8,8 @@
8
8
  * dsl.int().default(42)
9
9
  * dsl.string({ optional: true })
10
10
  */
11
- import type { EnumStorage, JsonSchemaRefIR } from "@vibeorm/schema";
12
- import type { BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, ColumnDef, ColumnType, DatetimeColumnConfig, DecimalColumnConfig, ExtensionTypeConfig, FloatColumnConfig, IdColumnConfig, IdGeneratorType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, StringColumnConfig } from "./types.ts";
11
+ import type { EnumStorage, GeneratedColumnOptions, JsonSchemaRefIR, ValidatorRefIR } from "@vibeorm/schema";
12
+ import type { BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CheckRuleOptions, ColumnCheckShape, ColumnDef, ColumnType, DatetimeColumnConfig, DecimalColumnConfig, ExtensionTypeConfig, FloatColumnConfig, IdColumnConfig, IdGeneratorType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, LocalDateColumnConfig, StringColumnConfig } from "./types.ts";
13
13
  /**
14
14
  * Shallow-clones a column definition with a fresh `__config`, so columns
15
15
  * spread from a template are never shared between models.
@@ -19,6 +19,7 @@ export declare function cloneColumnDef(params: {
19
19
  }): ColumnDef;
20
20
  type ColumnDefaultValues = {
21
21
  string: string;
22
+ localDate: string;
22
23
  int: number;
23
24
  bigint: bigint | number;
24
25
  float: number;
@@ -55,8 +56,56 @@ export declare class ChainableColumn<T extends ColumnType = ColumnType> implemen
55
56
  map(dbColumnName: string): this;
56
57
  /** `@default(dbgenerated("expression"))` — database-native default. */
57
58
  dbgenerated(expression: string): this;
59
+ /** Declare a stored database expression, distinct from a default and never client-writable. */
60
+ generated(options: GeneratedColumnOptions): this;
61
+ /** Bind synchronous write validation without changing the column's public scalar type. */
62
+ validate(reference: T extends "json" | "unsupported" ? never : ValidatorRefIR): this;
58
63
  /** Emits a `///` doc comment above the column. */
59
64
  comment(text: string): this;
65
+ /**
66
+ * Record a one-column CHECK rule. Copy-on-write: `cloneColumnDef` copies the
67
+ * config shallowly, so a pushed array would leak into every model built from
68
+ * the same template column.
69
+ */
70
+ protected addCheckRule(params: {
71
+ rule: string;
72
+ check: ColumnCheckShape;
73
+ options: CheckRuleOptions | undefined;
74
+ }): this;
75
+ }
76
+ /** Column kinds that take numeric check rules. */
77
+ export type NumericColumnType = "int" | "bigint" | "float" | "decimal";
78
+ /**
79
+ * The literal a numeric rule takes, per column kind. Decimal takes exact
80
+ * decimal TEXT (`"19.99"`): a JavaScript number cannot carry an exact decimal.
81
+ */
82
+ export type NumericRuleLiteral = {
83
+ readonly int: number;
84
+ readonly bigint: bigint | number;
85
+ readonly float: number;
86
+ readonly decimal: string;
87
+ };
88
+ /**
89
+ * A numeric column with one-column CHECK rules. Each rule becomes a named CHECK
90
+ * `<Table>_<column>_<rule>_check`; `{ name }` replaces the name. A comparison
91
+ * passes on NULL, so on an optional column the rule holds the values that are set.
92
+ */
93
+ export declare class ChainableNumericColumn<T extends NumericColumnType> extends ChainableColumn<T> {
94
+ /** The zero literal of this column kind. */
95
+ private zero;
96
+ /** `CHECK ("col" >= 0)`, rule word `nonNegative`. */
97
+ nonNegative(options?: CheckRuleOptions): this;
98
+ /** `CHECK ("col" > 0)`, rule word `positive`. */
99
+ positive(options?: CheckRuleOptions): this;
100
+ /** `CHECK ("col" >= value)`, rule word `atLeast`. */
101
+ atLeast(value: NumericRuleLiteral[T], options?: CheckRuleOptions): this;
102
+ /** `CHECK ("col" <= value)`, rule word `atMost`. */
103
+ atMost(value: NumericRuleLiteral[T], options?: CheckRuleOptions): this;
104
+ /** `CHECK ("col" >= min AND "col" <= max)`, rule word `range`. Both bounds are included. */
105
+ range(range: CheckRuleOptions & {
106
+ readonly min: NumericRuleLiteral[T];
107
+ readonly max: NumericRuleLiteral[T];
108
+ }): this;
60
109
  }
61
110
  /** String column with database-level type annotations. */
62
111
  export declare class ChainableStringColumn extends ChainableColumn<"string"> {
@@ -65,11 +114,24 @@ export declare class ChainableStringColumn extends ChainableColumn<"string"> {
65
114
  maxLength(n: number): this;
66
115
  /** `@db.Text` */
67
116
  text(): this;
117
+ /**
118
+ * `@db.Uuid` — PostgreSQL's native 128-bit uuid column; values stay strings.
119
+ * SQLite stores the string as TEXT; MySQL has no uuid type and refuses it.
120
+ */
121
+ uuid(): this;
68
122
  /** `@collation("...")` — explicit column collation (mysql-rendered; inert on postgres/sqlite). */
69
123
  collation(name: string): this;
124
+ /** `CHECK ("col" IN (values))`, rule word `allowed`. */
125
+ oneOf(values: readonly string[], options?: CheckRuleOptions): this;
126
+ /**
127
+ * `CHECK (length("col") <= max)`, rule word `length` — a CHECK on any text
128
+ * column, PostgreSQL/PGlite only. `.maxLength(n)` instead changes the column
129
+ * TYPE to `VarChar(n)` and works on every dialect.
130
+ */
131
+ lengthAtMost(max: number, options?: CheckRuleOptions): this;
70
132
  }
71
133
  /** Decimal column carrying precision/scale. */
72
- export declare class ChainableDecimalColumn extends ChainableColumn<"decimal"> {
134
+ export declare class ChainableDecimalColumn extends ChainableNumericColumn<"decimal"> {
73
135
  constructor(config?: DecimalColumnConfig);
74
136
  /** `@db.Decimal(precision, scale)` */
75
137
  precision(p: number, s?: number): this;
@@ -96,6 +158,12 @@ export declare class ChainableIdColumn extends ChainableColumn<"id"> {
96
158
  constructor(config?: IdColumnConfig);
97
159
  /** Sets the id generator strategy (default `"ulid"`). */
98
160
  type(idType: IdGeneratorType): this;
161
+ /**
162
+ * `@db.Uuid` — store a String id in PostgreSQL's native uuid column. Pair it
163
+ * with an app-side strategy (`type: "uuid"`), or with `type: "none"` and a
164
+ * database default: `dsl.id({ type: "none" }).uuid().dbgenerated("uuidv7()")`.
165
+ */
166
+ uuid(): this;
99
167
  }
100
168
  /** Enum column whose `default()` is constrained to the declared options. */
101
169
  export declare class ChainableEnumColumn<T extends readonly string[] = readonly string[]> extends ChainableColumn<"enum"> {
@@ -105,8 +173,12 @@ export declare class ChainableEnumColumn<T extends readonly string[] = readonly
105
173
  enumName?: string;
106
174
  storage?: EnumStorage;
107
175
  });
176
+ /** The declared members, typed as the option tuple (presence tables read it). */
177
+ __enumValues?: T;
108
178
  /** Sets the default to one of the declared options. */
109
179
  default(value: T[number] | readonly T[number][]): this;
180
+ /** `CHECK ("col" IN (members))` — a subset of the enum's members, rule word `allowed`. */
181
+ oneOf(values: readonly T[number][], options?: CheckRuleOptions): this;
110
182
  }
111
183
  /**
112
184
  * String column.
@@ -118,14 +190,20 @@ export declare class ChainableEnumColumn<T extends readonly string[] = readonly
118
190
  */
119
191
  export declare function string(config?: StringColumnConfig): ChainableStringColumn;
120
192
  /** Integer column with database-generated values independent of primary-key membership. */
121
- export declare class ChainableIntegerColumn<T extends "int" | "bigint"> extends ChainableColumn<T> {
193
+ export declare class ChainableIntegerColumn<T extends "int" | "bigint"> extends ChainableNumericColumn<T> {
122
194
  /** Assign values from the database sequence; does not imply a key or uniqueness. */
123
195
  autoincrement(): this;
124
196
  }
197
+ /** A Gregorian calendar day as canonical YYYY-MM-DD text, not a JavaScript Date. */
198
+ export declare function localDate({ ...config }?: LocalDateColumnConfig): ChainableColumn<"localDate">;
125
199
  /** Int column. */
126
200
  export declare function int(config?: IntColumnConfig): ChainableIntegerColumn<"int">;
201
+ /** Float column with numeric check rules. */
202
+ export declare class ChainableFloatColumn extends ChainableNumericColumn<"float"> {
203
+ constructor(config?: FloatColumnConfig);
204
+ }
127
205
  /** Float column. */
128
- export declare function float(config?: FloatColumnConfig): ChainableColumn<"float">;
206
+ export declare function float(config?: FloatColumnConfig): ChainableFloatColumn;
129
207
  /** Decimal column. */
130
208
  export declare function decimal(config?: DecimalColumnConfig): ChainableDecimalColumn;
131
209
  /** Boolean column. */
@@ -165,6 +243,7 @@ export declare function json(config?: JsonColumnConfig): ChainableJsonColumn;
165
243
  * dsl.id() // String @id @default(ulid())
166
244
  * dsl.id({ type: "uuid" }) // String @id @default(uuid())
167
245
  * dsl.id().type("autoincrement") // Int @id @default(autoincrement())
246
+ * dsl.id({ type: "none" }).uuid().dbgenerated("uuidv7()") // String @id @db.Uuid @default(dbgenerated("uuidv7()"))
168
247
  */
169
248
  export declare function id(config?: IdColumnConfig): ChainableIdColumn;
170
249
  /** Bytes column. */
package/dist/index.d.ts CHANGED
@@ -33,19 +33,23 @@
33
33
  * const prisma = dsl.generate.prisma(schema); // .prisma text
34
34
  */
35
35
  import type { ExtensionRegistry, Provider, SchemaIR } from "@vibeorm/schema";
36
- import type { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableIdColumn, ChainableIntegerColumn, ChainableJsonColumn, ChainableStringColumn } from "./column.ts";
36
+ import type { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableFloatColumn, ChainableIdColumn, ChainableIntegerColumn, ChainableJsonColumn, ChainableStringColumn } from "./column.ts";
37
37
  import type { StandaloneEnumConfig } from "./enum.ts";
38
38
  import { defineRelations, defineRelationsPart, mergeRelations } from "./relations.ts";
39
39
  import { defineRls } from "./schema.ts";
40
40
  import type { SchemaOptions } from "./schema.ts";
41
41
  import type { TemplatesApi } from "./templates.ts";
42
42
  import type { ValidationError } from "./validate.ts";
43
- import type { BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, ModelDef, PrismaGeneratorConfig, SchemaDef, SchemaDefinition, SchemaInput, StringColumnConfig } from "./types.ts";
44
- export { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableIdColumn, ChainableIntegerColumn, ChainableJsonColumn, ChainableStringColumn, cloneColumnDef, } from "./column.ts";
43
+ import type { BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, LocalDateColumnConfig, ModelDef, PrismaGeneratorConfig, SchemaDef, SchemaDefinition, SchemaInput, StringColumnConfig } from "./types.ts";
44
+ export { ChainableColumn, ChainableDatetimeColumn, ChainableDecimalColumn, ChainableEnumColumn, ChainableFloatColumn, ChainableIdColumn, ChainableIntegerColumn, ChainableJsonColumn, ChainableNumericColumn, ChainableStringColumn, cloneColumnDef, } from "./column.ts";
45
+ export type { NumericColumnType, NumericRuleLiteral } from "./column.ts";
46
+ export { localDate } from "./column.ts";
45
47
  export { createEnum } from "./enum.ts";
46
48
  export { generatePrisma } from "./generator/prisma.ts";
47
49
  export { create, createIndexBuilder, evaluateIndexes, getColumnNames } from "./model.ts";
48
- export { compileChecks, compileIndexPredicate, createPredicateBuilder, evaluateChecks } from "./predicate.ts";
50
+ export { createRowRuleBuilder, compileRowRules } from "./row-rules.ts";
51
+ export type { RowRuleBuilder, RowRuleDeclaration } from "./row-rules.ts";
52
+ export { compileChecks, compileIndexPredicate, compileModelChecks, createChecksBuilder, createPredicateBuilder, evaluateChecks } from "./predicate.ts";
49
53
  export { children, createChildrenBuilder } from "./relation.ts";
50
54
  export { detectOneToOnePairs, planSchema, resolveRelationType } from "./relation-plan.ts";
51
55
  export { defineRelations, defineRelationsPart, mergeRelations } from "./relations.ts";
@@ -53,13 +57,14 @@ export { defineRls, domain, schema } from "./schema.ts";
53
57
  export { base, baseWithWorkspace, fields, templates, withActive, withAudit, withExternalId, withMetadata, withNameDescription, } from "./templates.ts";
54
58
  export { toIR } from "./to-ir.ts";
55
59
  export { validateSchema } from "./validate.ts";
60
+ export type { GeneratedColumnOptions, ValidatorRefIR } from "@vibeorm/schema";
56
61
  export type { StandaloneEnumConfig } from "./enum.ts";
57
- export type { EvaluatedCheck, PredicateModel } from "./predicate.ts";
62
+ export type { CheckModelContext, EvaluatedCheck, PredicateModel } from "./predicate.ts";
58
63
  export type { MergedOneToOneSide, PlannedIndex, PlannedRelation, PlannedRelationKind, SchemaPlan, } from "./relation-plan.ts";
59
64
  export type { SchemaOptions } from "./schema.ts";
60
65
  export type { ActiveTemplate, AuditTemplate, BaseTemplate, BaseWithWorkspaceTemplate, ExternalIdTemplate, FieldsTemplate, MetadataTemplate, NameDescriptionTemplate, TemplatesApi, } from "./templates.ts";
61
66
  export type { ValidationError } from "./validate.ts";
62
- export type { DefineRlsOptions, MergedRelations, RlsColumnKind, RlsContextRef, RlsContextRefs, RlsDef, RlsPolicies, BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CascadeAction, ChildrenBuilder, ChildrenDef, ChildrenRelationConfig, ChildrenSchemaCallback, ColumnDef, ColumnKeys, ColumnRef, ColumnRefKind, ColumnRefKindOf, ColumnType, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, EnumFieldConfig, EnumStorage, EnumValues, ExtensionAttributeUse, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, IdGeneratorType, IndexBuilder, IndexCallback, IndexDef, IndexOptions, ChecksCallback, ModelCheckConfig, ModelPolicyConfig, NamedCheckDef, PartialIndexDef, PredicateBuilder, PredicateExpr, PredicateFieldExpr, UniqueIndexOptions, IndexType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, ManyRelationDefConfig, ModelColumnRefs, ModelDef, OneRelationDefConfig, PrismaGeneratorConfig, RelationRefInput, RelationTarget, RelationsBuilder, RelationsMap, RelationsOutput, SchemaColumnNames, SchemaDef, SchemaDefinition, SchemaInput, StoredRelationDef, StringColumnConfig, ThroughRef, UnsupportedColumnConfig, } from "./types.ts";
67
+ export type { DefineRlsOptions, MergedRelations, RlsColumnKind, RlsContextRef, RlsContextRefs, RlsDef, RlsPolicies, BaseColumnConfig, BigIntColumnConfig, BooleanColumnConfig, BytesColumnConfig, CascadeAction, ChildrenBuilder, ChildrenDef, ChildrenRelationConfig, ChildrenSchemaCallback, ColumnDef, ColumnKeys, ColumnRef, ColumnRefKind, ColumnRefKindOf, ColumnType, CreateModelConfig, DatetimeColumnConfig, DecimalColumnConfig, EnumDef, EnumFieldConfig, EnumStorage, EnumValues, ExtensionAttributeUse, ExtensionTypeConfig, FloatColumnConfig, GeneratorOutput, IdColumnConfig, IdGeneratorType, IndexBuilder, IndexCallback, IndexDef, IndexKey, UnsortedIndexKey, SortedIndexKey, RawIndexExpression, IndexOptions, ChecksBuilder, ChecksCallback, CheckRuleOptions, ColumnCheckRule, ColumnCheckShape, OrderCheckOptions, PresenceCheckConfig, PresenceState, ModelCheckConfig, ModelPolicyConfig, NamedCheckDef, PartialIndexDef, PredicateBuilder, PredicateExpr, PredicateFieldExpr, PredicateNumericKind, PredicateNumericLiteral, PredicateNumericOperand, UniqueIndexOptions, IndexType, InlineEnumConfig, IntColumnConfig, JsonColumnConfig, LocalDateColumnConfig, ManyRelationDefConfig, ModelColumnRefs, ModelDef, OneRelationDefConfig, PrismaGeneratorConfig, RelationRefInput, RelationTarget, RelationsBuilder, RelationsMap, RelationsOutput, SchemaColumnNames, SchemaDef, SchemaDefinition, SchemaInput, StoredRelationDef, StringColumnConfig, ThroughRef, UnsupportedColumnConfig, } from "./types.ts";
63
68
  /**
64
69
  * Creates an enum: standalone (reusable, has a `name`) or inline (one-off).
65
70
  *
@@ -82,9 +87,10 @@ export type GenerateApi = {
82
87
  */
83
88
  export type DslApi = {
84
89
  readonly string: (config?: StringColumnConfig) => ChainableStringColumn;
90
+ readonly localDate: (config?: LocalDateColumnConfig) => ChainableColumn<"localDate">;
85
91
  readonly int: (config?: IntColumnConfig) => ChainableIntegerColumn<"int">;
86
92
  readonly bigint: (config?: BigIntColumnConfig) => ChainableIntegerColumn<"bigint">;
87
- readonly float: (config?: FloatColumnConfig) => ChainableColumn<"float">;
93
+ readonly float: (config?: FloatColumnConfig) => ChainableFloatColumn;
88
94
  readonly decimal: (config?: DecimalColumnConfig) => ChainableDecimalColumn;
89
95
  readonly boolean: (config?: BooleanColumnConfig) => ChainableColumn<"boolean">;
90
96
  readonly datetime: (config?: DatetimeColumnConfig) => ChainableDatetimeColumn;