@vibeorm/dsl 3.0.0 → 4.0.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 +3 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +112 -80
- package/dist/index.js.map +7 -7
- package/dist/types.d.ts +28 -10
- package/package.json +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* through `defineRelations` (Drizzle-style), which keeps column references
|
|
6
6
|
* type-safe without inference-heavy model types.
|
|
7
7
|
*/
|
|
8
|
-
import type { ExclusionSpec, ExclusionEndpoint, CascadeAction, EnumStorage, ExtensionAttributeValue, PredicateIR, Provider, QualifiedSqlName, RlsContextIR, RlsContextRefIR, RlsPolicyIR } from "@vibeorm/schema";
|
|
8
|
+
import type { ExclusionSpec, ExclusionEndpoint, CascadeAction, EnumStorage, JsonSchemaRefIR, ExtensionAttributeValue, PredicateExpression, PredicateIR, Provider, QualifiedSqlName, RlsContextIR, RlsContextRefIR, RlsPolicyIR } from "@vibeorm/schema";
|
|
9
9
|
import type { ChainableEnumColumn } from "./column.ts";
|
|
10
10
|
/** Referential actions, re-exported from the IR so both sources agree. */
|
|
11
11
|
export type { CascadeAction };
|
|
@@ -74,6 +74,8 @@ export type DatetimeColumnConfig = BaseColumnConfig & {
|
|
|
74
74
|
};
|
|
75
75
|
export type JsonColumnConfig = BaseColumnConfig & {
|
|
76
76
|
default?: unknown;
|
|
77
|
+
/** Consumer-owned named runtime validator export; serialized as data in SchemaIR. */
|
|
78
|
+
jsonSchema?: JsonSchemaRefIR;
|
|
77
79
|
};
|
|
78
80
|
export type IdColumnConfig = BaseColumnConfig & {
|
|
79
81
|
type?: IdGeneratorType;
|
|
@@ -227,14 +229,14 @@ export type NamedCheckDef = {
|
|
|
227
229
|
readonly predicate: PredicateIR;
|
|
228
230
|
};
|
|
229
231
|
/**
|
|
230
|
-
* The `c` handed to a model's `checks` callback, returning named
|
|
232
|
+
* The `c` handed to a model's `checks` callback, returning typed or raw named CHECKs.
|
|
231
233
|
*
|
|
232
234
|
* @example
|
|
233
235
|
* checks: (c) => [
|
|
234
236
|
* c.named("dispatch_clock", c.gt(c.field("deadlineAt"), c.field("startedAt"))),
|
|
235
237
|
* ]
|
|
236
238
|
*/
|
|
237
|
-
export type ChecksCallback<TColumns extends string = string, TSchema extends SchemaDefinition = SchemaDefinition> = (c: PredicateBuilder<TColumns, TSchema>) => NamedCheckDef[];
|
|
239
|
+
export type ChecksCallback<TColumns extends string = string, TSchema extends SchemaDefinition = SchemaDefinition> = (c: PredicateBuilder<TColumns, TSchema>) => (NamedCheckDef | ModelCheckConfig)[];
|
|
238
240
|
/**
|
|
239
241
|
* Application-level row-scoping policy — the DSL twin of
|
|
240
242
|
* `@@policy([field], context: "key")`. The runtime fails closed on policied
|
|
@@ -373,7 +375,14 @@ export type PredicateFieldExpr<TColumn extends string = string, TKind extends Co
|
|
|
373
375
|
* use — because a foreign key and a comparison ask one question: are these two
|
|
374
376
|
* columns the same scalar family?
|
|
375
377
|
*/
|
|
376
|
-
|
|
378
|
+
/** Typed scalar operand produced by the schema predicate builder. */
|
|
379
|
+
export type PredicateExpr<TKind extends ColumnRefKind = ColumnRefKind> = PredicateExpression & {
|
|
380
|
+
readonly __kind: TKind;
|
|
381
|
+
};
|
|
382
|
+
type JsonPredicateColumns<TColumns extends string, TSchema extends SchemaDefinition> = {
|
|
383
|
+
[C in TColumns]: "Json" extends SchemaColumnRefKind<TSchema, C> ? C : never;
|
|
384
|
+
}[TColumns];
|
|
385
|
+
type ComparisonOperand<TKind extends ColumnRefKind> = PredicateLiteralByRefKind[TKind] | PredicateExpr<PairableRefKind[TKind]>;
|
|
377
386
|
/**
|
|
378
387
|
* The `c` handed to `checks` and to an index's `.where()`.
|
|
379
388
|
*
|
|
@@ -389,12 +398,21 @@ type ComparisonOperand<TKind extends ColumnRefKind> = PredicateLiteralByRefKind[
|
|
|
389
398
|
export type PredicateBuilder<TColumns extends string = string, TSchema extends SchemaDefinition = SchemaDefinition> = {
|
|
390
399
|
/** Reference one of the model's own fields, by LOGICAL name. */
|
|
391
400
|
field<C extends TColumns>(name: C): PredicateFieldExpr<C, SchemaColumnRefKind<TSchema, C>>;
|
|
392
|
-
eq<TKind extends ColumnRefKind>(left:
|
|
393
|
-
ne<TKind extends ColumnRefKind>(left:
|
|
394
|
-
gt<TKind extends ColumnRefKind>(left:
|
|
395
|
-
gte<TKind extends ColumnRefKind>(left:
|
|
396
|
-
lt<TKind extends ColumnRefKind>(left:
|
|
397
|
-
lte<TKind extends ColumnRefKind>(left:
|
|
401
|
+
eq<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
402
|
+
ne<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
403
|
+
gt<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
404
|
+
gte<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
405
|
+
lt<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
406
|
+
lte<TKind extends ColumnRefKind>(left: PredicateExpr<TKind>, right: ComparisonOperand<NoInfer<TKind>>): PredicateIR;
|
|
407
|
+
/** PostgreSQL/PGlite CHECK only. Extract text without asserting the JSON leaf's type. */
|
|
408
|
+
jsonText(params: {
|
|
409
|
+
field: JsonPredicateColumns<TColumns, TSchema>;
|
|
410
|
+
path: readonly string[];
|
|
411
|
+
}): PredicateExpr<"String">;
|
|
412
|
+
/** PostgreSQL/PGlite CHECK only. Character length, preserving SQL NULL. */
|
|
413
|
+
length(expression: PredicateExpr<"String" | "Id">): PredicateExpr<"Int">;
|
|
414
|
+
/** PostgreSQL/PGlite CHECK only. Require TRUE; UNKNOWN becomes FALSE. */
|
|
415
|
+
isTrue(predicate: PredicateIR): PredicateIR;
|
|
398
416
|
/** `col IN (…)`. Membership, not a set operation — every value is a literal. */
|
|
399
417
|
inList<TKind extends ColumnRefKind>(field: PredicateFieldExpr<string, TKind>, values: readonly PredicateLiteralByRefKind[TKind][]): PredicateIR;
|
|
400
418
|
/** `col NOT IN (…)`. NULL in the column stays UNKNOWN, as SQL defines it. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/dsl",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "TypeScript schema DSL for VibeORM v2 — compiles to canonical SchemaIR, with .prisma generation for interop",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"bun": ">=1.2.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@vibeorm/schema": "
|
|
47
|
-
"@vibeorm/sql": "
|
|
46
|
+
"@vibeorm/schema": "4.0.0",
|
|
47
|
+
"@vibeorm/sql": "4.0.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|