@vibeorm/dsl 4.2.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/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"> {
@@ -72,9 +121,17 @@ export declare class ChainableStringColumn extends ChainableColumn<"string"> {
72
121
  uuid(): this;
73
122
  /** `@collation("...")` — explicit column collation (mysql-rendered; inert on postgres/sqlite). */
74
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;
75
132
  }
76
133
  /** Decimal column carrying precision/scale. */
77
- export declare class ChainableDecimalColumn extends ChainableColumn<"decimal"> {
134
+ export declare class ChainableDecimalColumn extends ChainableNumericColumn<"decimal"> {
78
135
  constructor(config?: DecimalColumnConfig);
79
136
  /** `@db.Decimal(precision, scale)` */
80
137
  precision(p: number, s?: number): this;
@@ -116,8 +173,12 @@ export declare class ChainableEnumColumn<T extends readonly string[] = readonly
116
173
  enumName?: string;
117
174
  storage?: EnumStorage;
118
175
  });
176
+ /** The declared members, typed as the option tuple (presence tables read it). */
177
+ __enumValues?: T;
119
178
  /** Sets the default to one of the declared options. */
120
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;
121
182
  }
122
183
  /**
123
184
  * String column.
@@ -129,14 +190,20 @@ export declare class ChainableEnumColumn<T extends readonly string[] = readonly
129
190
  */
130
191
  export declare function string(config?: StringColumnConfig): ChainableStringColumn;
131
192
  /** Integer column with database-generated values independent of primary-key membership. */
132
- export declare class ChainableIntegerColumn<T extends "int" | "bigint"> extends ChainableColumn<T> {
193
+ export declare class ChainableIntegerColumn<T extends "int" | "bigint"> extends ChainableNumericColumn<T> {
133
194
  /** Assign values from the database sequence; does not imply a key or uniqueness. */
134
195
  autoincrement(): this;
135
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">;
136
199
  /** Int column. */
137
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
+ }
138
205
  /** Float column. */
139
- export declare function float(config?: FloatColumnConfig): ChainableColumn<"float">;
206
+ export declare function float(config?: FloatColumnConfig): ChainableFloatColumn;
140
207
  /** Decimal column. */
141
208
  export declare function decimal(config?: DecimalColumnConfig): ChainableDecimalColumn;
142
209
  /** Boolean 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;