@prisma-next/sql-relational-core 0.13.0-dev.3 → 0.13.0-dev.31
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/{ddl-types-D3vlEjMA.d.mts → ddl-types-CrjJ5Mlu.d.mts} +5 -1
- package/dist/ddl-types-CrjJ5Mlu.d.mts.map +1 -0
- package/dist/{ddl-types-X9_XHUl0.mjs → ddl-types-DAox2c8w.mjs} +4 -1
- package/dist/ddl-types-DAox2c8w.mjs.map +1 -0
- package/dist/exports/ast.d.mts +9 -1
- package/dist/exports/ast.d.mts.map +1 -1
- package/dist/exports/ast.mjs +1 -1
- package/dist/exports/codec-descriptor-registry.d.mts.map +1 -1
- package/dist/exports/codec-descriptor-registry.mjs +2 -13
- package/dist/exports/codec-descriptor-registry.mjs.map +1 -1
- package/dist/exports/contract-free.d.mts +3 -1
- package/dist/exports/contract-free.d.mts.map +1 -1
- package/dist/exports/contract-free.mjs +1 -1
- package/dist/exports/contract-free.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +11 -11
- package/src/ast/ddl-types.ts +5 -0
- package/src/ast/driver-types.ts +8 -0
- package/src/codec-ref-for-column.ts +2 -35
- package/src/contract-free/column.ts +2 -0
- package/dist/ddl-types-D3vlEjMA.d.mts.map +0 -1
- package/dist/ddl-types-X9_XHUl0.mjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { o as CodecRef } from "./codec-types-DFLA6Hmj.mjs";
|
|
1
2
|
import { d as AnyParamRef } from "./types-BbGUx5Bi.mjs";
|
|
2
3
|
import { ColumnDefaultLiteralInputValue } from "@prisma-next/contract/types";
|
|
3
4
|
import { ReferentialAction } from "@prisma-next/sql-contract/types";
|
|
@@ -43,12 +44,15 @@ declare class DdlColumn {
|
|
|
43
44
|
readonly notNull?: boolean | undefined;
|
|
44
45
|
readonly primaryKey?: boolean | undefined;
|
|
45
46
|
readonly default?: AnyDdlColumnDefault | undefined;
|
|
47
|
+
/** Codec identity for this column. When present, the DDL walker resolves the codec via `codecLookup.get(codecRef.codecId)` and calls `codec.encode(default.value, {})` to obtain the wire value before inlining the literal default into the DDL string. When absent, literal defaults follow RawSqlLiteral wire-scalar semantics (string / number / boolean / bigint / null / Uint8Array / Date inlined directly). */
|
|
48
|
+
readonly codecRef?: CodecRef | undefined;
|
|
46
49
|
constructor(options: {
|
|
47
50
|
readonly name: string;
|
|
48
51
|
readonly type: string;
|
|
49
52
|
readonly notNull?: boolean;
|
|
50
53
|
readonly primaryKey?: boolean;
|
|
51
54
|
readonly default?: AnyDdlColumnDefault;
|
|
55
|
+
readonly codecRef?: CodecRef;
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
declare abstract class DdlNode {
|
|
@@ -123,4 +127,4 @@ declare class UniqueConstraint {
|
|
|
123
127
|
type DdlTableConstraint = PrimaryKeyConstraint | ForeignKeyConstraint | UniqueConstraint;
|
|
124
128
|
//#endregion
|
|
125
129
|
export { DdlColumnRenderContext as a, ForeignKeyConstraint as c, PrimaryKeyConstraint as d, UniqueConstraint as f, DdlColumnDefaultVisitor as i, FunctionColumnDefault as l, DdlColumn as n, DdlNode as o, isDdlNode as p, DdlColumnDefault as r, DdlTableConstraint as s, AnyDdlColumnDefault as t, LiteralColumnDefault as u };
|
|
126
|
-
//# sourceMappingURL=ddl-types-
|
|
130
|
+
//# sourceMappingURL=ddl-types-CrjJ5Mlu.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddl-types-CrjJ5Mlu.d.mts","names":[],"sources":["../src/ast/ddl-types.ts"],"mappings":";;;;;;;;AAeA;;;;AACqB;AAGrB;;UAJiB,sBAAA;EAAA,SACN,UAAU;AAAA;AAAA,UAGJ,uBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,oBAAA,EAAsB,GAAA,EAAK,sBAAA,GAAyB,CAAA;EAClE,QAAA,CAAS,IAAA,EAAM,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SAAoB,OAAA;IAAA,SAAqC,IAAA;EAAA;AAAA;;;AAhGkB;AAKzF;;;;cAyGa,oBAAA;EAAA,SACF,IAAA;EAAA,SACA,OAAA,EAAS,aAAA;EAAA,SACT,QAAA;EAAA,SACA,UAAA,EAAY,aAAA;EAAA,SACZ,QAAA,EAAU,iBAAA;EAAA,SACV,QAAA,EAAU,iBAAA;EAAA,SACV,IAAA;cAEG,OAAA;IAAA,SACD,OAAA;IAAA,SACA,QAAA;IAAA,SACA,UAAA;IAAA,SACA,QAAA,GAAW,iBAAA;IAAA,SACX,QAAA,GAAW,iBAAA;IAAA,SACX,IAAA;EAAA;AAAA;;;;AA9G4E;AAKzF;;;cA4Ha,gBAAA;EAAA,SACF,IAAA;EAAA,SACA,OAAA,EAAS,aAAa;EAAA,SACtB,IAAA;cAEG,OAAA;IAAA,SAAoB,OAAA;IAAA,SAAqC,IAAA;EAAA;AAAA;AAAA,KAO3D,kBAAA,GAAqB,oBAAA,GAAuB,oBAAA,GAAuB,gBAAA"}
|
|
@@ -36,12 +36,15 @@ var DdlColumn = class {
|
|
|
36
36
|
notNull;
|
|
37
37
|
primaryKey;
|
|
38
38
|
default;
|
|
39
|
+
/** Codec identity for this column. When present, the DDL walker resolves the codec via `codecLookup.get(codecRef.codecId)` and calls `codec.encode(default.value, {})` to obtain the wire value before inlining the literal default into the DDL string. When absent, literal defaults follow RawSqlLiteral wire-scalar semantics (string / number / boolean / bigint / null / Uint8Array / Date inlined directly). */
|
|
40
|
+
codecRef;
|
|
39
41
|
constructor(options) {
|
|
40
42
|
this.name = options.name;
|
|
41
43
|
this.type = options.type;
|
|
42
44
|
this.notNull = options.notNull;
|
|
43
45
|
this.primaryKey = options.primaryKey;
|
|
44
46
|
this.default = options.default;
|
|
47
|
+
this.codecRef = options.codecRef;
|
|
45
48
|
Object.freeze(this);
|
|
46
49
|
}
|
|
47
50
|
};
|
|
@@ -127,4 +130,4 @@ var UniqueConstraint = class {
|
|
|
127
130
|
//#endregion
|
|
128
131
|
export { FunctionColumnDefault as a, UniqueConstraint as c, ForeignKeyConstraint as i, isDdlNode as l, DdlColumnDefault as n, LiteralColumnDefault as o, DdlNode as r, PrimaryKeyConstraint as s, DdlColumn as t };
|
|
129
132
|
|
|
130
|
-
//# sourceMappingURL=ddl-types-
|
|
133
|
+
//# sourceMappingURL=ddl-types-DAox2c8w.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddl-types-DAox2c8w.mjs","names":[],"sources":["../src/ast/ddl-types.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport { isColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { CodecRef } from './codec-types';\nimport type { AnyParamRef } from './types';\n\n/**\n * Render-time context the column-default visitor needs to make dialect\n * decisions that depend on the parent column. Today only the parent\n * column's native type (`\"jsonb\"`, `\"text\"`, …) — the Postgres renderer\n * uses it to decide whether to emit a `::jsonb` / `::json` cast on JSON\n * literal defaults so the emitted DDL matches the column type without\n * relying on Postgres's implicit text → jsonb cast at default-evaluation\n * time. Additional fields can join without re-shaping the interface.\n */\nexport interface DdlColumnRenderContext {\n readonly nativeType: string;\n}\n\nexport interface DdlColumnDefaultVisitor<R> {\n literal(node: LiteralColumnDefault, ctx: DdlColumnRenderContext): R;\n function(node: FunctionColumnDefault, ctx: DdlColumnRenderContext): R;\n}\n\nexport abstract class DdlColumnDefault {\n abstract readonly kind: string;\n abstract accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R;\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\nexport class LiteralColumnDefault extends DdlColumnDefault {\n readonly kind = 'literal' as const;\n readonly value: ColumnDefaultLiteralInputValue;\n\n constructor(value: ColumnDefaultLiteralInputValue) {\n super();\n if (!isColumnDefaultLiteralInputValue(value)) {\n throw new Error('Invalid column default literal value');\n }\n this.value = value;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.literal(this, ctx);\n }\n}\n\nexport class FunctionColumnDefault extends DdlColumnDefault {\n readonly kind = 'function' as const;\n readonly expression: string;\n\n constructor(expression: string) {\n super();\n this.expression = expression;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.function(this, ctx);\n }\n}\n\nexport type AnyDdlColumnDefault = LiteralColumnDefault | FunctionColumnDefault;\n\nexport class DdlColumn {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean | undefined;\n readonly primaryKey?: boolean | undefined;\n readonly default?: AnyDdlColumnDefault | undefined;\n /** Codec identity for this column. When present, the DDL walker resolves the codec via `codecLookup.get(codecRef.codecId)` and calls `codec.encode(default.value, {})` to obtain the wire value before inlining the literal default into the DDL string. When absent, literal defaults follow RawSqlLiteral wire-scalar semantics (string / number / boolean / bigint / null / Uint8Array / Date inlined directly). */\n readonly codecRef?: CodecRef | undefined;\n\n constructor(options: {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n readonly codecRef?: CodecRef;\n }) {\n this.name = options.name;\n this.type = options.type;\n this.notNull = options.notNull;\n this.primaryKey = options.primaryKey;\n this.default = options.default;\n this.codecRef = options.codecRef;\n Object.freeze(this);\n }\n}\n\nexport abstract class DdlNode {\n abstract readonly kind: string;\n\n /**\n * Structural brand: every DDL node answers `true`. Lets {@link isDdlNode}\n * recognise any `DdlNode` subclass — including target-contributed kinds —\n * without a central kind registry that subclasses would have to register\n * into.\n */\n isDdlNode(): true {\n return true;\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n\n collectParamRefs(): AnyParamRef[] {\n return [];\n }\n}\n\nexport function isDdlNode(value: unknown): value is DdlNode {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'isDdlNode' in value &&\n typeof value.isDdlNode === 'function'\n );\n}\n\n// ---------------------------------------------------------------------------\n// Table-level constraint nodes\n// ---------------------------------------------------------------------------\n\n/**\n * A composite (or single-column) PRIMARY KEY constraint on a `CreateTable`\n * node. When `name` is set, the adapter renders `CONSTRAINT <name> PRIMARY KEY\n * (…)`; otherwise it renders an anonymous `PRIMARY KEY (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class PrimaryKeyConstraint {\n readonly kind = 'primary-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A FOREIGN KEY constraint on a `CreateTable` node. `onDelete` and `onUpdate`\n * use the same `ReferentialAction` vocabulary already used by the migration\n * planner and the contract IR — no parallel string enum.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class ForeignKeyConstraint {\n readonly kind = 'foreign-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly refTable: string;\n readonly refColumns: ReadonlyArray<string>;\n readonly onDelete: ReferentialAction | undefined;\n readonly onUpdate: ReferentialAction | undefined;\n readonly name: string | undefined;\n\n constructor(options: {\n readonly columns: readonly string[];\n readonly refTable: string;\n readonly refColumns: readonly string[];\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly name?: string;\n }) {\n this.columns = Object.freeze([...options.columns]);\n this.refTable = options.refTable;\n this.refColumns = Object.freeze([...options.refColumns]);\n this.onDelete = options.onDelete;\n this.onUpdate = options.onUpdate;\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A table-level UNIQUE constraint on a `CreateTable` node. When `name` is\n * set, the adapter renders `CONSTRAINT <name> UNIQUE (…)`; otherwise it\n * renders an anonymous `UNIQUE (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class UniqueConstraint {\n readonly kind = 'unique' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\nexport type DdlTableConstraint = PrimaryKeyConstraint | ForeignKeyConstraint | UniqueConstraint;\n"],"mappings":";;AAwBA,IAAsB,mBAAtB,MAAuC;CAIrC,SAAyB;EACvB,OAAO,OAAO,IAAI;CACpB;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,OAAuC;EACjD,MAAM;EACN,IAAI,CAAC,iCAAiC,KAAK,GACzC,MAAM,IAAI,MAAM,sCAAsC;EAExD,KAAK,QAAQ;EACb,KAAK,OAAO;CACd;CAEA,OAAmB,SAAqC,KAAgC;EACtF,OAAO,QAAQ,QAAQ,MAAM,GAAG;CAClC;AACF;AAEA,IAAa,wBAAb,cAA2C,iBAAiB;CAC1D,OAAgB;CAChB;CAEA,YAAY,YAAoB;EAC9B,MAAM;EACN,KAAK,aAAa;EAClB,KAAK,OAAO;CACd;CAEA,OAAmB,SAAqC,KAAgC;EACtF,OAAO,QAAQ,SAAS,MAAM,GAAG;CACnC;AACF;AAIA,IAAa,YAAb,MAAuB;CACrB;CACA;CACA;CACA;CACA;;CAEA;CAEA,YAAY,SAOT;EACD,KAAK,OAAO,QAAQ;EACpB,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ;EACvB,KAAK,aAAa,QAAQ;EAC1B,KAAK,UAAU,QAAQ;EACvB,KAAK,WAAW,QAAQ;EACxB,OAAO,OAAO,IAAI;CACpB;AACF;AAEA,IAAsB,UAAtB,MAA8B;;;;;;;CAS5B,YAAkB;EAChB,OAAO;CACT;CAEA,SAAyB;EACvB,OAAO,OAAO,IAAI;CACpB;CAEA,mBAAkC;EAChC,OAAO,CAAC;CACV;AACF;AAEA,SAAgB,UAAU,OAAkC;CAC1D,OACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,OAAO,MAAM,cAAc;AAE/B;;;;;;;;AAaA,IAAa,uBAAb,MAAkC;CAChC,OAAgB;CAChB;CACA;CAEA,YAAY,SAA0E;EACpF,KAAK,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;EACjD,KAAK,OAAO,QAAQ;EACpB,OAAO,OAAO,IAAI;CACpB;AACF;;;;;;;;AASA,IAAa,uBAAb,MAAkC;CAChC,OAAgB;CAChB;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAOT;EACD,KAAK,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;EACjD,KAAK,WAAW,QAAQ;EACxB,KAAK,aAAa,OAAO,OAAO,CAAC,GAAG,QAAQ,UAAU,CAAC;EACvD,KAAK,WAAW,QAAQ;EACxB,KAAK,WAAW,QAAQ;EACxB,KAAK,OAAO,QAAQ;EACpB,OAAO,OAAO,IAAI;CACpB;AACF;;;;;;;;AASA,IAAa,mBAAb,MAA8B;CAC5B,OAAgB;CAChB;CACA;CAEA,YAAY,SAA0E;EACpF,KAAK,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;EACjD,KAAK,OAAO,QAAQ;EACpB,OAAO,OAAO,IAAI;CACpB;AACF"}
|
package/dist/exports/ast.d.mts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { a as CodecMeta, c as ContractCodecRegistry, d as DescriptorCodecTraits, f as ExtractCodecTypes, h as SqlColumnRef, i as CodecDescriptor, l as DescriptorCodecId, m as SqlCodecInstanceContext, n as Codec, o as CodecRef, p as SqlCodecCallContext, r as CodecCallContext, s as CodecTrait, t as AnyCodecDescriptor, u as DescriptorCodecInput } from "../codec-types-DFLA6Hmj.mjs";
|
|
2
2
|
import { $ as RawSqlExpr, A as InsertAst, B as LiteralExpr, C as EqColJoinOn, D as ExpressionRewriter, E as ExpressionFolder, F as JsonArrayAggExpr, G as OperationExpr, H as LoweredStatement, I as JsonObjectEntry, J as ParamRef, K as OrExpr, L as JsonObjectExpr, M as InsertValue, N as JoinAst, O as ExpressionSource, P as JoinOnExpr, Q as RawExpr, R as LimitOffsetValue, S as DoUpdateSetConflictAction, T as ExprVisitor, U as NotExpr, V as LoweredParam, W as NullCheckExpr, X as ProjectionExpr, Y as PreparedParamRef, Z as ProjectionItem, _ as DefaultValueExpr, a as AndExpr, at as TableSource, b as Direction, c as AnyInsertOnConflictAction, ct as WhereArg, d as AnyParamRef, dt as isQueryAst, et as RawSqlLiteral, f as AnyQueryAst, ft as isWhereExpr, g as ColumnRef, h as BinaryOp, i as AggregateOpFn, it as TableRef, j as InsertOnConflict, k as IdentifierRef, l as AnyInsertValue, lt as WindowFn, m as BinaryExpr, mt as whereExprKinds, n as AggregateExpr, nt as SelectAstOptions, o as AnyExpression, ot as ToWhereExpr, p as AstRewriter, pt as queryAstKinds, q as OrderByItem, r as AggregateFn, rt as SubqueryExpr, s as AnyFromSource, st as UpdateAst, t as AggregateCountFn, tt as SelectAst, u as AnyOperationArg, ut as WindowFuncExpr, v as DeleteAst, w as ExistsExpr, x as DoNothingConflictAction, y as DerivedTableSource, z as ListExpression } from "../types-BbGUx5Bi.mjs";
|
|
3
|
-
import { a as DdlColumnRenderContext, c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, i as DdlColumnDefaultVisitor, l as FunctionColumnDefault, n as DdlColumn, o as DdlNode, p as isDdlNode, r as DdlColumnDefault, s as DdlTableConstraint, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "../ddl-types-
|
|
3
|
+
import { a as DdlColumnRenderContext, c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, i as DdlColumnDefaultVisitor, l as FunctionColumnDefault, n as DdlColumn, o as DdlNode, p as isDdlNode, r as DdlColumnDefault, s as DdlTableConstraint, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "../ddl-types-CrjJ5Mlu.mjs";
|
|
4
4
|
import { ContractMarkerRecord, JsonValue } from "@prisma-next/contract/types";
|
|
5
5
|
import { CodecCallContext as CodecCallContext$1, CodecDescriptorImpl, CodecImpl, CodecInstanceContext } from "@prisma-next/framework-components/codec";
|
|
6
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
7
|
|
|
8
8
|
//#region src/ast/driver-types.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A fully lowered SQL statement ready for a driver to execute: SQL text plus
|
|
11
|
+
* driver-ready (codec-encoded) parameter values. The output of the control
|
|
12
|
+
* adapter's `lowerToExecuteRequest`, handed to a driver via `SqlQueryable.query`
|
|
13
|
+
* or `execute`. Inline-substituted positions (e.g. DDL `DEFAULT`
|
|
14
|
+
* clauses) carry no param; `params` holds the wire values for the `$N`/`?`
|
|
15
|
+
* positions, in order.
|
|
16
|
+
*/
|
|
9
17
|
interface SqlExecuteRequest {
|
|
10
18
|
readonly sql: string;
|
|
11
19
|
readonly params?: readonly unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.mts","names":[],"sources":["../../src/ast/driver-types.ts","../../src/ast/adapter-types.ts","../../src/ast/sql-codec-helpers.ts","../../src/ast/sql-codecs.ts","../../src/ast/util.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ast.d.mts","names":[],"sources":["../../src/ast/driver-types.ts","../../src/ast/adapter-types.ts","../../src/ast/sql-codec-helpers.ts","../../src/ast/sql-codecs.ts","../../src/ast/util.ts"],"mappings":";;;;;;;;;;;;;;;;UAQiB,iBAAA;EAAA,SACN,GAAA;EAAA,SACA,MAAM;AAAA;AAAA,UAGA,sBAAA;EAAA,SACN,GAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;IACP,GAAA;IACA,GAAA,CAAI,KAAA;EAAA;AAAA;AAAA,UAIS,cAAA,OAAqB,MAAA;EAAA,SAC3B,IAAA,EAAM,aAAA,CAAc,GAAA;EAAA,SACpB,QAAA;EAAA,UACC,GAAA;AAAA;AAAA,UAGK,gBAAA,OAAuB,MAAA;EA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AA,GAAc,aAAA,CAAc,WAAA"}
|
package/dist/exports/ast.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, l as isDdlNode, n as DdlColumnDefault, o as LiteralColumnDefault, r as DdlNode, s as PrimaryKeyConstraint, t as DdlColumn } from "../ddl-types-
|
|
1
|
+
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, l as isDdlNode, n as DdlColumnDefault, o as LiteralColumnDefault, r as DdlNode, s as PrimaryKeyConstraint, t as DdlColumn } from "../ddl-types-DAox2c8w.mjs";
|
|
2
2
|
import { A as SelectAst, C as OrExpr, D as ProjectionItem, E as PreparedParamRef, F as isQueryAst, I as isWhereExpr, L as queryAstKinds, M as TableSource, N as UpdateAst, O as RawExpr, P as WindowFuncExpr, R as whereExprKinds, S as OperationExpr, T as ParamRef, _ as JsonObjectExpr, a as DefaultValueExpr, b as NotExpr, c as DoNothingConflictAction, d as ExistsExpr, f as IdentifierRef, g as JsonArrayAggExpr, h as JoinAst, i as ColumnRef, j as SubqueryExpr, k as RawSqlExpr, l as DoUpdateSetConflictAction, m as InsertOnConflict, n as AndExpr, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as DerivedTableSource, t as AggregateExpr, u as EqColJoinOn, v as ListExpression, w as OrderByItem, x as NullCheckExpr, y as LiteralExpr } from "../types-D72v8s92.mjs";
|
|
3
3
|
import { n as compact, t as collectOrderedParamRefs } from "../util-DQQgv2j1.mjs";
|
|
4
4
|
import { CodecDescriptorImpl, CodecImpl, column, voidParamsSchema } from "@prisma-next/framework-components/codec";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec-descriptor-registry.d.mts","names":[],"sources":["../../src/codec-descriptor-registry.ts","../../src/codec-ref-for-column.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;;iBAAgB,4BAAA,CACd,cAAA,EAAgB,aAAA,CAAc,kBAAA,GAC9B,OAAA,GAAU,UAAA,GACT,uBAAA;;;;;;;AAHH;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"codec-descriptor-registry.d.mts","names":[],"sources":["../../src/codec-descriptor-registry.ts","../../src/codec-ref-for-column.ts"],"mappings":";;;;;;;;;AAgBA;;;;;;;iBAAgB,4BAAA,CACd,cAAA,EAAgB,aAAA,CAAc,kBAAA,GAC9B,OAAA,GAAU,UAAA,GACT,uBAAA;;;;;;;AAHH;;;;;;;;;;;iBCIgB,wBAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,SAAA,UACA,UAAA,WACC,QAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveStorageTable } from "@prisma-next/sql-contract/resolve-storage-table";
|
|
2
|
-
import {
|
|
2
|
+
import { isStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
3
3
|
//#region src/codec-ref-for-column.ts
|
|
4
4
|
/**
|
|
5
5
|
* Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.
|
|
@@ -22,19 +22,8 @@ function codecRefForStorageColumn(storage, namespaceId, tableName, columnName) {
|
|
|
22
22
|
const columnDef = resolved.table.columns[columnName];
|
|
23
23
|
if (!columnDef) return void 0;
|
|
24
24
|
if (columnDef.typeRef !== void 0) {
|
|
25
|
-
|
|
26
|
-
if (!instance) for (const ns of Object.values(storage.namespaces)) {
|
|
27
|
-
const nsEntry = ns.entries.type?.[columnDef.typeRef];
|
|
28
|
-
if (nsEntry !== void 0) {
|
|
29
|
-
instance = nsEntry;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
25
|
+
const instance = storage.types?.[columnDef.typeRef];
|
|
33
26
|
if (!instance) return void 0;
|
|
34
|
-
if (isPostgresEnumStorageEntry(instance)) return {
|
|
35
|
-
codecId: instance.codecId,
|
|
36
|
-
typeParams: { values: instance.values }
|
|
37
|
-
};
|
|
38
27
|
if (isStorageTypeInstance(instance)) {
|
|
39
28
|
const instanceParams = instance.typeParams;
|
|
40
29
|
return instanceParams !== void 0 && Object.keys(instanceParams).length > 0 ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec-descriptor-registry.mjs","names":[],"sources":["../../src/codec-ref-for-column.ts","../../src/codec-descriptor-registry.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';\nimport {
|
|
1
|
+
{"version":3,"file":"codec-descriptor-registry.mjs","names":[],"sources":["../../src/codec-ref-for-column.ts","../../src/codec-descriptor-registry.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport type { CodecRef } from '@prisma-next/framework-components/codec';\nimport { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';\nimport { isStorageTypeInstance, type SqlStorage } from '@prisma-next/sql-contract/types';\n\n/**\n * Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.\n *\n * Resolution rules over namespace `entries.table[table].columns[column]`:\n *\n * - `typeRef` column → `{codecId, typeParams}` from `storage.types[typeRef]` (multiple columns sharing the typeRef share one ref → one memoised codec).\n * - inline `typeParams` column → `{codecId, typeParams}` from the column itself.\n * - non-parameterized column → `{codecId}` with `typeParams` undefined.\n *\n * Returns `undefined` when the table or column is unknown, or when a `typeRef` column references a `storage.types` entry that does not exist.\n *\n * `namespaceId` leads the coordinate args and is always supplied: every\n * model/table sits in an explicit namespace, so the table is resolved strictly\n * within that namespace (see {@link resolveStorageTable}).\n */\nexport function codecRefForStorageColumn(\n storage: SqlStorage,\n namespaceId: string,\n tableName: string,\n columnName: string,\n): CodecRef | undefined {\n const resolved = resolveStorageTable(storage, tableName, namespaceId);\n if (resolved === undefined) return undefined;\n const tableDef = resolved.table;\n const columnDef = tableDef.columns[columnName];\n if (!columnDef) return undefined;\n if (columnDef.typeRef !== undefined) {\n const instance = storage.types?.[columnDef.typeRef];\n if (!instance) return undefined;\n if (isStorageTypeInstance(instance)) {\n const instanceParams = instance.typeParams;\n const hasParamKeys = instanceParams !== undefined && Object.keys(instanceParams).length > 0;\n return hasParamKeys\n ? { codecId: instance.codecId, typeParams: instanceParams as JsonValue }\n : { codecId: instance.codecId };\n }\n return undefined;\n }\n if (columnDef.typeParams !== undefined && Object.keys(columnDef.typeParams).length > 0) {\n return { codecId: columnDef.codecId, typeParams: columnDef.typeParams as JsonValue };\n }\n return { codecId: columnDef.codecId };\n}\n","import type { CodecDescriptor, CodecRef } from '@prisma-next/framework-components/codec';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { AnyCodecDescriptor } from './ast/codec-types';\nimport { codecRefForStorageColumn } from './codec-ref-for-column';\nimport type { CodecDescriptorRegistry } from './query-lane-context';\n\n/**\n * Build a {@link CodecDescriptorRegistry} from a flat descriptor list.\n *\n * Used by:\n * - Each codec-shipping package's `core/registry.ts` to expose a package-scoped registry as the public consumer surface (replacing raw descriptor-array exports). See ADR 208.\n * - The runtime's `buildExecutionContext` to construct the contract-bound combined registry from every contributor's `codecs:` slot.\n *\n * The descriptor map is heterogeneous in `P` — each codec id has its own params shape. The public {@link CodecDescriptorRegistry} interface widens to `CodecDescriptor<unknown>` and consumers narrow per codec id at the call site (the descriptor's `paramsSchema` validates JSON-sourced params before the factory ever sees them, so the runtime narrow is safe). The cast at registration goes through `unknown` because\n * `CodecDescriptor<P>` is invariant in `P` (the `factory` and `renderOutputType` slots use `P` contravariantly).\n */\nexport function buildCodecDescriptorRegistry(\n allDescriptors: ReadonlyArray<AnyCodecDescriptor>,\n storage?: SqlStorage,\n): CodecDescriptorRegistry {\n type AnyDescriptor = CodecDescriptor<unknown>;\n const byId = new Map<string, AnyDescriptor>();\n const byTargetType = new Map<string, Array<AnyDescriptor>>();\n\n for (const descriptor of allDescriptors) {\n if (byId.has(descriptor.codecId)) {\n throw new Error(\n `Duplicate codec descriptor id: '${descriptor.codecId}' — registered twice during registry construction. ` +\n 'Each codecId must be contributed by exactly one component (target / adapter / extension pack).',\n );\n }\n const widened = descriptor as unknown as AnyDescriptor;\n byId.set(descriptor.codecId, widened);\n for (const targetType of descriptor.targetTypes) {\n const list = byTargetType.get(targetType);\n if (list) {\n list.push(widened);\n } else {\n byTargetType.set(targetType, [widened]);\n }\n }\n }\n\n return {\n descriptorFor(codecId: string): AnyDescriptor | undefined {\n return byId.get(codecId);\n },\n codecRefForColumn(namespaceId: string, table: string, column: string): CodecRef | undefined {\n if (!storage) return undefined;\n return codecRefForStorageColumn(storage, namespaceId, table, column);\n },\n *values(): IterableIterator<AnyDescriptor> {\n yield* byId.values();\n },\n byTargetType(targetType: string): readonly AnyDescriptor[] {\n return byTargetType.get(targetType) ?? Object.freeze([]);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,SAAgB,yBACd,SACA,aACA,WACA,YACsB;CACtB,MAAM,WAAW,oBAAoB,SAAS,WAAW,WAAW;CACpE,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAEnC,MAAM,YADW,SAAS,MACC,QAAQ;CACnC,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,IAAI,UAAU,YAAY,KAAA,GAAW;EACnC,MAAM,WAAW,QAAQ,QAAQ,UAAU;EAC3C,IAAI,CAAC,UAAU,OAAO,KAAA;EACtB,IAAI,sBAAsB,QAAQ,GAAG;GACnC,MAAM,iBAAiB,SAAS;GAEhC,OADqB,mBAAmB,KAAA,KAAa,OAAO,KAAK,cAAc,CAAC,CAAC,SAAS,IAEtF;IAAE,SAAS,SAAS;IAAS,YAAY;GAA4B,IACrE,EAAE,SAAS,SAAS,QAAQ;EAClC;EACA;CACF;CACA,IAAI,UAAU,eAAe,KAAA,KAAa,OAAO,KAAK,UAAU,UAAU,CAAC,CAAC,SAAS,GACnF,OAAO;EAAE,SAAS,UAAU;EAAS,YAAY,UAAU;CAAwB;CAErF,OAAO,EAAE,SAAS,UAAU,QAAQ;AACtC;;;;;;;;;;;;;AC/BA,SAAgB,6BACd,gBACA,SACyB;CAEzB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,MAAM,+BAAe,IAAI,IAAkC;CAE3D,KAAK,MAAM,cAAc,gBAAgB;EACvC,IAAI,KAAK,IAAI,WAAW,OAAO,GAC7B,MAAM,IAAI,MACR,mCAAmC,WAAW,QAAQ,kJAExD;EAEF,MAAM,UAAU;EAChB,KAAK,IAAI,WAAW,SAAS,OAAO;EACpC,KAAK,MAAM,cAAc,WAAW,aAAa;GAC/C,MAAM,OAAO,aAAa,IAAI,UAAU;GACxC,IAAI,MACF,KAAK,KAAK,OAAO;QAEjB,aAAa,IAAI,YAAY,CAAC,OAAO,CAAC;EAE1C;CACF;CAEA,OAAO;EACL,cAAc,SAA4C;GACxD,OAAO,KAAK,IAAI,OAAO;EACzB;EACA,kBAAkB,aAAqB,OAAe,QAAsC;GAC1F,IAAI,CAAC,SAAS,OAAO,KAAA;GACrB,OAAO,yBAAyB,SAAS,aAAa,OAAO,MAAM;EACrE;EACA,CAAC,SAA0C;GACzC,OAAO,KAAK,OAAO;EACrB;EACA,aAAa,YAA8C;GACzD,OAAO,aAAa,IAAI,UAAU,KAAK,OAAO,OAAO,CAAC,CAAC;EACzD;CACF;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { o as CodecRef } from "../codec-types-DFLA6Hmj.mjs";
|
|
1
2
|
import { A as InsertAst, Z as ProjectionItem, at as TableSource, g as ColumnRef, o as AnyExpression, q as OrderByItem, st as UpdateAst, tt as SelectAst } from "../types-BbGUx5Bi.mjs";
|
|
2
|
-
import { c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, l as FunctionColumnDefault, n as DdlColumn, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "../ddl-types-
|
|
3
|
+
import { c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, l as FunctionColumnDefault, n as DdlColumn, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "../ddl-types-CrjJ5Mlu.mjs";
|
|
3
4
|
import { ColumnDefaultLiteralInputValue } from "@prisma-next/contract/types";
|
|
4
5
|
import { ReferentialAction } from "@prisma-next/sql-contract/types";
|
|
5
6
|
|
|
@@ -8,6 +9,7 @@ interface DdlColumnOptions {
|
|
|
8
9
|
readonly notNull?: boolean;
|
|
9
10
|
readonly primaryKey?: boolean;
|
|
10
11
|
readonly default?: AnyDdlColumnDefault;
|
|
12
|
+
readonly codecRef?: CodecRef;
|
|
11
13
|
}
|
|
12
14
|
declare function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault;
|
|
13
15
|
declare function fn(expression: string): FunctionColumnDefault;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-free.d.mts","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract-free.d.mts","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"mappings":";;;;;;;UAaiB,gBAAA;EAAA,SACN,OAAA;EAAA,SACA,UAAA;EAAA,SACA,OAAA,GAAU,mBAAA;EAAA,SACV,QAAA,GAAW,QAAQ;AAAA;AAAA,iBAGd,GAAA,CAAI,KAAA,EAAO,8BAAA,GAAiC,oBAAoB;AAAA,iBAIhE,EAAA,CAAG,UAAA,WAAqB,qBAAqB;AAAA,iBAI7C,GAAA,CAAI,IAAA,UAAc,IAAA,UAAc,OAAA,GAAU,gBAAA,GAAmB,SAAS;AA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AA,EAAQ,MAAA,GACP,WAAA,CAAY,MAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, o as LiteralColumnDefault, s as PrimaryKeyConstraint, t as DdlColumn } from "../ddl-types-
|
|
1
|
+
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, o as LiteralColumnDefault, s as PrimaryKeyConstraint, t as DdlColumn } from "../ddl-types-DAox2c8w.mjs";
|
|
2
2
|
import { A as SelectAst, C as OrExpr, D as ProjectionItem, N as UpdateAst, T as ParamRef, i as ColumnRef, m as InsertOnConflict, n as AndExpr, p as InsertAst, r as BinaryExpr, w as OrderByItem, x as NullCheckExpr } from "../types-D72v8s92.mjs";
|
|
3
3
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
4
|
//#region src/contract-free/column.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-free.mjs","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { AnyDdlColumnDefault } from '../ast/ddl-types';\nimport {\n DdlColumn,\n ForeignKeyConstraint,\n FunctionColumnDefault,\n LiteralColumnDefault,\n PrimaryKeyConstraint,\n UniqueConstraint,\n} from '../ast/ddl-types';\n\nexport interface DdlColumnOptions {\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n}\n\nexport function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault {\n return new LiteralColumnDefault(value);\n}\n\nexport function fn(expression: string): FunctionColumnDefault {\n return new FunctionColumnDefault(expression);\n}\n\nexport function col(name: string, type: string, options?: DdlColumnOptions): DdlColumn {\n return new DdlColumn({ name, type, ...options });\n}\n\nexport function primaryKey(\n columns: readonly string[],\n options?: { readonly name?: string },\n): PrimaryKeyConstraint {\n return new PrimaryKeyConstraint({ columns, ...options });\n}\n\nexport function foreignKey(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n options?: {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n },\n): ForeignKeyConstraint {\n return new ForeignKeyConstraint({ columns, refTable, refColumns, ...options });\n}\n\nexport function unique(\n columns: readonly string[],\n options?: { readonly name?: string },\n): UniqueConstraint {\n return new UniqueConstraint({ columns, ...options });\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport {\n AndExpr,\n type AnyExpression,\n BinaryExpr,\n ColumnRef,\n InsertAst,\n InsertOnConflict,\n type InsertValue,\n NullCheckExpr,\n OrderByItem,\n OrExpr,\n ParamRef,\n ProjectionItem,\n SelectAst,\n type TableSource,\n UpdateAst,\n} from '../ast/types';\n\nexport interface ColumnDescriptor {\n readonly codecId: string;\n readonly nullable: boolean;\n}\n\nexport type ColumnSchema = Record<string, ColumnDescriptor>;\n\n/**\n * A composable WHERE / ON expression. Wraps an `AnyExpression` and exposes\n * fluent boolean combinators, mirroring the spirit of `sql-builder`'s\n * `Expression` interface without the contract-bound type machinery.\n */\nexport class CfExpr {\n constructor(readonly ast: AnyExpression) {}\n\n and(other: CfExpr): CfExpr {\n return new CfExpr(AndExpr.of([this.ast, other.ast]));\n }\n\n or(other: CfExpr): CfExpr {\n return new CfExpr(OrExpr.of([this.ast, other.ast]));\n }\n\n not(): CfExpr {\n return new CfExpr(this.ast.not());\n }\n}\n\n/**\n * Per-column authoring handle exposed as a keyed property on a {@link TableHandle}.\n * Carries codec metadata baked at declaration time so no codec ID, table name, or\n * column name needs to be repeated at the call site.\n */\nexport interface ColumnProxy {\n readonly codecId: string;\n readonly nullable: boolean;\n readonly columnName: string;\n readonly tableName: string;\n eq(value: unknown): CfExpr;\n neq(value: unknown): CfExpr;\n isNull(): CfExpr;\n isNotNull(): CfExpr;\n toRef(): ColumnRef;\n toProjectionItem(alias?: string): ProjectionItem;\n}\n\n/**\n * Object passed to the {@link CfConflictClause.doUpdate} callback. Each key\n * resolves to a `ColumnRef` for the corresponding `excluded.<column>`, so the\n * upsert conflict-update branch can copy proposed values without re-binding\n * parameters.\n */\nexport type ExcludedProxy<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: ColumnRef;\n};\n\nexport type TableInsertRow<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: unknown;\n};\n\nexport type TableSetValues<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]?: unknown;\n};\n\n/**\n * Fluent authoring handle for a fixed control-plane table. Column proxies are\n * exposed as keyed properties so `handle.columnName.eq(value)` composes without\n * threading codec IDs, table names, or column refs at the call site.\n */\nexport type TableHandle<Schema extends ColumnSchema> = {\n readonly source: TableSource;\n insert(row: TableInsertRow<Schema>): CfInsertQuery<Schema>;\n upsert(row: TableInsertRow<Schema>): CfUpsertBuilder<Schema>;\n update(): CfUpdateQuery<Schema>;\n select(...columns: ReadonlyArray<ColumnProxy>): CfSelectQuery;\n} & {\n readonly [K in keyof Schema]: ColumnProxy;\n};\n\nexport class CfInsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfInsertQuery<Schema> {\n return new CfInsertQuery(\n this.src,\n this.schema,\n this.rowValues,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const ast = InsertAst.into(this.src).withRows([row]);\n return this.returningItems ? ast.withReturning(this.returningItems) : ast;\n }\n}\n\nexport class CfUpsertBuilder<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n ) {}\n\n onConflict(...columns: ReadonlyArray<ColumnProxy>): CfConflictClause<Schema> {\n return new CfConflictClause(this.src, this.schema, this.rowValues, [...columns]);\n }\n}\n\nexport class CfConflictClause<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n ) {}\n\n doUpdate(\n setOrCallback:\n | TableSetValues<Schema>\n | ((excluded: ExcludedProxy<Schema>) => TableSetValues<Schema>),\n ): CfUpsertQuery<Schema> {\n const set =\n typeof setOrCallback === 'function'\n ? setOrCallback(buildExcludedProxy(this.schema))\n : setOrCallback;\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, set);\n }\n\n doNothing(): CfUpsertQuery<Schema> {\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, undefined);\n }\n}\n\nexport class CfUpsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n private readonly updateSet: TableSetValues<Schema> | undefined,\n ) {}\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const conflictRefs = this.conflictCols.map((col) => col.toRef());\n const onConflict =\n this.updateSet === undefined\n ? InsertOnConflict.on(conflictRefs).doNothing()\n : InsertOnConflict.on(conflictRefs).doUpdateSet(buildSetMap(this.schema, this.updateSet));\n return InsertAst.into(this.src).withRows([row]).withOnConflict(onConflict);\n }\n}\n\nexport class CfUpdateQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly setValues: TableSetValues<Schema> | undefined = undefined,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n set(values: TableSetValues<Schema>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, values, this.whereExpr, this.returningItems);\n }\n\n where(expr: CfExpr): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, this.setValues, expr, this.returningItems);\n }\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(\n this.src,\n this.schema,\n this.setValues,\n this.whereExpr,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): UpdateAst {\n const set = buildSetMap(this.schema, this.setValues);\n const base = UpdateAst.table(this.src).withSet(set);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.returningItems ? withWhere.withReturning(this.returningItems) : withWhere;\n }\n}\n\nexport class CfSelectQuery {\n constructor(\n private readonly src: TableSource,\n private readonly projectionItems: ReadonlyArray<ProjectionItem>,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly orderByItems: ReadonlyArray<OrderByItem> = [],\n ) {}\n\n where(expr: CfExpr): CfSelectQuery {\n return new CfSelectQuery(this.src, this.projectionItems, expr, this.orderByItems);\n }\n\n orderBy(column: ColumnProxy, dir: 'asc' | 'desc' = 'asc'): CfSelectQuery {\n const item = dir === 'asc' ? OrderByItem.asc(column.toRef()) : OrderByItem.desc(column.toRef());\n return new CfSelectQuery(this.src, this.projectionItems, this.whereExpr, [\n ...this.orderByItems,\n item,\n ]);\n }\n\n build(): SelectAst {\n const base = SelectAst.from(this.src).withProjection(this.projectionItems);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.orderByItems.length > 0 ? withWhere.withOrderBy(this.orderByItems) : withWhere;\n }\n}\n\n/**\n * Declare a control-plane table once, binding column codecs at declaration time.\n * Returns a `TableHandle` whose column properties compose expressions directly\n * without per-call-site codec or column-name threading.\n *\n * ```ts\n * const marker = pgTable({ name: 'marker', schema: 'prisma_contract' }, {\n * space: text(),\n * core_hash: text(),\n * updated_at: timestamptz(),\n * });\n *\n * const query = marker.update()\n * .set({ core_hash: newHash, updated_at: NOW })\n * .where(marker.space.eq(space).and(marker.core_hash.eq(expectedFrom)))\n * .returning(marker.space)\n * .build();\n * ```\n */\nexport function table<Schema extends ColumnSchema>(\n source: TableSource,\n schema: Schema,\n): TableHandle<Schema> {\n const proxies: Record<string, ColumnProxy> = {};\n for (const [col, desc] of Object.entries(schema)) {\n proxies[col] = makeColumnProxy(source.alias ?? source.name, col, desc);\n }\n\n const handle = {\n ...proxies,\n source,\n insert: (row: TableInsertRow<Schema>) => new CfInsertQuery(source, schema, row),\n upsert: (row: TableInsertRow<Schema>) => new CfUpsertBuilder(source, schema, row),\n update: () => new CfUpdateQuery(source, schema),\n select: (...cols: ReadonlyArray<ColumnProxy>) =>\n new CfSelectQuery(\n source,\n cols.map((col) => col.toProjectionItem()),\n ),\n };\n\n return blindCast<\n TableHandle<Schema>,\n 'Column proxies are dynamically built from Schema keys — TypeScript cannot verify the per-key ColumnProxy constraint at the spread call site. Construction is correct by construction: every key maps to makeColumnProxy(source.name, key, schema[key]).'\n >(handle);\n}\n\nfunction makeColumnProxy(\n tableName: string,\n columnName: string,\n desc: ColumnDescriptor,\n): ColumnProxy {\n const ref = ColumnRef.of(tableName, columnName);\n return {\n codecId: desc.codecId,\n nullable: desc.nullable,\n columnName,\n tableName,\n eq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNull(ref))\n : new CfExpr(BinaryExpr.eq(ref, toSetExpression(value, desc))),\n neq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNotNull(ref))\n : new CfExpr(BinaryExpr.neq(ref, toSetExpression(value, desc))),\n isNull: () => new CfExpr(NullCheckExpr.isNull(ref)),\n isNotNull: () => new CfExpr(NullCheckExpr.isNotNull(ref)),\n toRef: () => ref,\n toProjectionItem: (alias = columnName) =>\n ProjectionItem.of(alias, ref, { codecId: desc.codecId }),\n };\n}\n\nfunction buildExcludedProxy<Schema extends ColumnSchema>(schema: Schema): ExcludedProxy<Schema> {\n return blindCast<\n ExcludedProxy<Schema>,\n 'Object.fromEntries cannot preserve per-key ColumnRef types — correct by construction: every key maps to ColumnRef.of(\"excluded\", key).'\n >(Object.fromEntries(Object.keys(schema).map((col) => [col, ColumnRef.of('excluded', col)])));\n}\n\nfunction isExpressionSource(value: unknown): value is { toExpr(): AnyExpression } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof value.toExpr === 'function'\n );\n}\n\nfunction toInsertValue(value: unknown, desc: ColumnDescriptor): InsertValue {\n if (isExpressionSource(value)) {\n const expr = value.toExpr();\n if (\n expr.kind === 'column-ref' ||\n expr.kind === 'param-ref' ||\n expr.kind === 'prepared-param-ref' ||\n expr.kind === 'raw-expr'\n ) {\n return expr;\n }\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction toSetExpression(value: unknown, desc: ColumnDescriptor): AnyExpression {\n if (isExpressionSource(value)) {\n return value.toExpr();\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction buildInsertRow<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableInsertRow<Schema>,\n): Record<string, InsertValue> {\n const row: Record<string, InsertValue> = {};\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableInsertRow<Schema> maps Schema keys to unknown; indexing by the same string keys is correct by construction'\n >(values);\n for (const [col, desc] of Object.entries(schema)) {\n row[col] = toInsertValue(rawValues[col], desc);\n }\n return row;\n}\n\nfunction buildSetMap<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableSetValues<Schema> | undefined,\n): Record<string, AnyExpression> {\n if (values === undefined) return {};\n const set: Record<string, AnyExpression> = {};\n const rawSchema = blindCast<\n Record<string, ColumnDescriptor>,\n 'Schema extends ColumnSchema = Record<string, ColumnDescriptor>; runtime key access is correct by construction'\n >(schema);\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableSetValues<Schema> maps Schema keys to unknown; iterating with Object.entries is correct by construction'\n >(values);\n for (const [col, value] of Object.entries(rawValues)) {\n const desc = rawSchema[col];\n if (desc !== undefined) {\n set[col] = toSetEx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ChE;AAEA,SAAS,eACP,QACA,QAC6B;CAC7B,MAAM,MAAmC,CAAC;CAC1C,MAAM,YAAY,UAGhB,MAAM;CACR,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,GAC7C,IAAI,OAAO,cAAc,UAAU,MAAM,IAAI;CAE/C,OAAO;AACT;AAEA,SAAS,YACP,QACA,QAC+B;CAC/B,IAAI,WAAW,KAAA,GAAW,OAAO,CAAC;CAClC,MAAM,MAAqC,CAAC;CAC5C,MAAM,YAAY,UAGhB,MAAM;CACR,MAAM,YAAY,UAGhB,MAAM;CACR,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,UAAU;EACvB,IAAI,SAAS,KAAA,GACX,IAAI,OAAO,gBAAgB,OAAO,IAAI;CAE1C;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"contract-free.mjs","names":[],"sources":["../../src/contract-free/column.ts","../../src/contract-free/table.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { CodecRef } from '../ast/codec-types';\nimport type { AnyDdlColumnDefault } from '../ast/ddl-types';\nimport {\n DdlColumn,\n ForeignKeyConstraint,\n FunctionColumnDefault,\n LiteralColumnDefault,\n PrimaryKeyConstraint,\n UniqueConstraint,\n} from '../ast/ddl-types';\n\nexport interface DdlColumnOptions {\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n readonly codecRef?: CodecRef;\n}\n\nexport function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault {\n return new LiteralColumnDefault(value);\n}\n\nexport function fn(expression: string): FunctionColumnDefault {\n return new FunctionColumnDefault(expression);\n}\n\nexport function col(name: string, type: string, options?: DdlColumnOptions): DdlColumn {\n return new DdlColumn({ name, type, ...options });\n}\n\nexport function primaryKey(\n columns: readonly string[],\n options?: { readonly name?: string },\n): PrimaryKeyConstraint {\n return new PrimaryKeyConstraint({ columns, ...options });\n}\n\nexport function foreignKey(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n options?: {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n },\n): ForeignKeyConstraint {\n return new ForeignKeyConstraint({ columns, refTable, refColumns, ...options });\n}\n\nexport function unique(\n columns: readonly string[],\n options?: { readonly name?: string },\n): UniqueConstraint {\n return new UniqueConstraint({ columns, ...options });\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport {\n AndExpr,\n type AnyExpression,\n BinaryExpr,\n ColumnRef,\n InsertAst,\n InsertOnConflict,\n type InsertValue,\n NullCheckExpr,\n OrderByItem,\n OrExpr,\n ParamRef,\n ProjectionItem,\n SelectAst,\n type TableSource,\n UpdateAst,\n} from '../ast/types';\n\nexport interface ColumnDescriptor {\n readonly codecId: string;\n readonly nullable: boolean;\n}\n\nexport type ColumnSchema = Record<string, ColumnDescriptor>;\n\n/**\n * A composable WHERE / ON expression. Wraps an `AnyExpression` and exposes\n * fluent boolean combinators, mirroring the spirit of `sql-builder`'s\n * `Expression` interface without the contract-bound type machinery.\n */\nexport class CfExpr {\n constructor(readonly ast: AnyExpression) {}\n\n and(other: CfExpr): CfExpr {\n return new CfExpr(AndExpr.of([this.ast, other.ast]));\n }\n\n or(other: CfExpr): CfExpr {\n return new CfExpr(OrExpr.of([this.ast, other.ast]));\n }\n\n not(): CfExpr {\n return new CfExpr(this.ast.not());\n }\n}\n\n/**\n * Per-column authoring handle exposed as a keyed property on a {@link TableHandle}.\n * Carries codec metadata baked at declaration time so no codec ID, table name, or\n * column name needs to be repeated at the call site.\n */\nexport interface ColumnProxy {\n readonly codecId: string;\n readonly nullable: boolean;\n readonly columnName: string;\n readonly tableName: string;\n eq(value: unknown): CfExpr;\n neq(value: unknown): CfExpr;\n isNull(): CfExpr;\n isNotNull(): CfExpr;\n toRef(): ColumnRef;\n toProjectionItem(alias?: string): ProjectionItem;\n}\n\n/**\n * Object passed to the {@link CfConflictClause.doUpdate} callback. Each key\n * resolves to a `ColumnRef` for the corresponding `excluded.<column>`, so the\n * upsert conflict-update branch can copy proposed values without re-binding\n * parameters.\n */\nexport type ExcludedProxy<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: ColumnRef;\n};\n\nexport type TableInsertRow<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]: unknown;\n};\n\nexport type TableSetValues<Schema extends ColumnSchema> = {\n readonly [K in keyof Schema]?: unknown;\n};\n\n/**\n * Fluent authoring handle for a fixed control-plane table. Column proxies are\n * exposed as keyed properties so `handle.columnName.eq(value)` composes without\n * threading codec IDs, table names, or column refs at the call site.\n */\nexport type TableHandle<Schema extends ColumnSchema> = {\n readonly source: TableSource;\n insert(row: TableInsertRow<Schema>): CfInsertQuery<Schema>;\n upsert(row: TableInsertRow<Schema>): CfUpsertBuilder<Schema>;\n update(): CfUpdateQuery<Schema>;\n select(...columns: ReadonlyArray<ColumnProxy>): CfSelectQuery;\n} & {\n readonly [K in keyof Schema]: ColumnProxy;\n};\n\nexport class CfInsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfInsertQuery<Schema> {\n return new CfInsertQuery(\n this.src,\n this.schema,\n this.rowValues,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const ast = InsertAst.into(this.src).withRows([row]);\n return this.returningItems ? ast.withReturning(this.returningItems) : ast;\n }\n}\n\nexport class CfUpsertBuilder<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n ) {}\n\n onConflict(...columns: ReadonlyArray<ColumnProxy>): CfConflictClause<Schema> {\n return new CfConflictClause(this.src, this.schema, this.rowValues, [...columns]);\n }\n}\n\nexport class CfConflictClause<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n ) {}\n\n doUpdate(\n setOrCallback:\n | TableSetValues<Schema>\n | ((excluded: ExcludedProxy<Schema>) => TableSetValues<Schema>),\n ): CfUpsertQuery<Schema> {\n const set =\n typeof setOrCallback === 'function'\n ? setOrCallback(buildExcludedProxy(this.schema))\n : setOrCallback;\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, set);\n }\n\n doNothing(): CfUpsertQuery<Schema> {\n return new CfUpsertQuery(this.src, this.schema, this.rowValues, this.conflictCols, undefined);\n }\n}\n\nexport class CfUpsertQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly rowValues: TableInsertRow<Schema>,\n private readonly conflictCols: ReadonlyArray<ColumnProxy>,\n private readonly updateSet: TableSetValues<Schema> | undefined,\n ) {}\n\n build(): InsertAst {\n const row = buildInsertRow(this.schema, this.rowValues);\n const conflictRefs = this.conflictCols.map((col) => col.toRef());\n const onConflict =\n this.updateSet === undefined\n ? InsertOnConflict.on(conflictRefs).doNothing()\n : InsertOnConflict.on(conflictRefs).doUpdateSet(buildSetMap(this.schema, this.updateSet));\n return InsertAst.into(this.src).withRows([row]).withOnConflict(onConflict);\n }\n}\n\nexport class CfUpdateQuery<Schema extends ColumnSchema> {\n constructor(\n private readonly src: TableSource,\n private readonly schema: Schema,\n private readonly setValues: TableSetValues<Schema> | undefined = undefined,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly returningItems: ReadonlyArray<ProjectionItem> | undefined = undefined,\n ) {}\n\n set(values: TableSetValues<Schema>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, values, this.whereExpr, this.returningItems);\n }\n\n where(expr: CfExpr): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(this.src, this.schema, this.setValues, expr, this.returningItems);\n }\n\n returning(...columns: ReadonlyArray<ColumnProxy>): CfUpdateQuery<Schema> {\n return new CfUpdateQuery(\n this.src,\n this.schema,\n this.setValues,\n this.whereExpr,\n columns.map((col) => col.toProjectionItem()),\n );\n }\n\n build(): UpdateAst {\n const set = buildSetMap(this.schema, this.setValues);\n const base = UpdateAst.table(this.src).withSet(set);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.returningItems ? withWhere.withReturning(this.returningItems) : withWhere;\n }\n}\n\nexport class CfSelectQuery {\n constructor(\n private readonly src: TableSource,\n private readonly projectionItems: ReadonlyArray<ProjectionItem>,\n private readonly whereExpr: CfExpr | undefined = undefined,\n private readonly orderByItems: ReadonlyArray<OrderByItem> = [],\n ) {}\n\n where(expr: CfExpr): CfSelectQuery {\n return new CfSelectQuery(this.src, this.projectionItems, expr, this.orderByItems);\n }\n\n orderBy(column: ColumnProxy, dir: 'asc' | 'desc' = 'asc'): CfSelectQuery {\n const item = dir === 'asc' ? OrderByItem.asc(column.toRef()) : OrderByItem.desc(column.toRef());\n return new CfSelectQuery(this.src, this.projectionItems, this.whereExpr, [\n ...this.orderByItems,\n item,\n ]);\n }\n\n build(): SelectAst {\n const base = SelectAst.from(this.src).withProjection(this.projectionItems);\n const withWhere = this.whereExpr ? base.withWhere(this.whereExpr.ast) : base;\n return this.orderByItems.length > 0 ? withWhere.withOrderBy(this.orderByItems) : withWhere;\n }\n}\n\n/**\n * Declare a control-plane table once, binding column codecs at declaration time.\n * Returns a `TableHandle` whose column properties compose expressions directly\n * without per-call-site codec or column-name threading.\n *\n * ```ts\n * const marker = pgTable({ name: 'marker', schema: 'prisma_contract' }, {\n * space: text(),\n * core_hash: text(),\n * updated_at: timestamptz(),\n * });\n *\n * const query = marker.update()\n * .set({ core_hash: newHash, updated_at: NOW })\n * .where(marker.space.eq(space).and(marker.core_hash.eq(expectedFrom)))\n * .returning(marker.space)\n * .build();\n * ```\n */\nexport function table<Schema extends ColumnSchema>(\n source: TableSource,\n schema: Schema,\n): TableHandle<Schema> {\n const proxies: Record<string, ColumnProxy> = {};\n for (const [col, desc] of Object.entries(schema)) {\n proxies[col] = makeColumnProxy(source.alias ?? source.name, col, desc);\n }\n\n const handle = {\n ...proxies,\n source,\n insert: (row: TableInsertRow<Schema>) => new CfInsertQuery(source, schema, row),\n upsert: (row: TableInsertRow<Schema>) => new CfUpsertBuilder(source, schema, row),\n update: () => new CfUpdateQuery(source, schema),\n select: (...cols: ReadonlyArray<ColumnProxy>) =>\n new CfSelectQuery(\n source,\n cols.map((col) => col.toProjectionItem()),\n ),\n };\n\n return blindCast<\n TableHandle<Schema>,\n 'Column proxies are dynamically built from Schema keys — TypeScript cannot verify the per-key ColumnProxy constraint at the spread call site. Construction is correct by construction: every key maps to makeColumnProxy(source.name, key, schema[key]).'\n >(handle);\n}\n\nfunction makeColumnProxy(\n tableName: string,\n columnName: string,\n desc: ColumnDescriptor,\n): ColumnProxy {\n const ref = ColumnRef.of(tableName, columnName);\n return {\n codecId: desc.codecId,\n nullable: desc.nullable,\n columnName,\n tableName,\n eq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNull(ref))\n : new CfExpr(BinaryExpr.eq(ref, toSetExpression(value, desc))),\n neq: (value) =>\n value === null\n ? new CfExpr(NullCheckExpr.isNotNull(ref))\n : new CfExpr(BinaryExpr.neq(ref, toSetExpression(value, desc))),\n isNull: () => new CfExpr(NullCheckExpr.isNull(ref)),\n isNotNull: () => new CfExpr(NullCheckExpr.isNotNull(ref)),\n toRef: () => ref,\n toProjectionItem: (alias = columnName) =>\n ProjectionItem.of(alias, ref, { codecId: desc.codecId }),\n };\n}\n\nfunction buildExcludedProxy<Schema extends ColumnSchema>(schema: Schema): ExcludedProxy<Schema> {\n return blindCast<\n ExcludedProxy<Schema>,\n 'Object.fromEntries cannot preserve per-key ColumnRef types — correct by construction: every key maps to ColumnRef.of(\"excluded\", key).'\n >(Object.fromEntries(Object.keys(schema).map((col) => [col, ColumnRef.of('excluded', col)])));\n}\n\nfunction isExpressionSource(value: unknown): value is { toExpr(): AnyExpression } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'toExpr' in value &&\n typeof value.toExpr === 'function'\n );\n}\n\nfunction toInsertValue(value: unknown, desc: ColumnDescriptor): InsertValue {\n if (isExpressionSource(value)) {\n const expr = value.toExpr();\n if (\n expr.kind === 'column-ref' ||\n expr.kind === 'param-ref' ||\n expr.kind === 'prepared-param-ref' ||\n expr.kind === 'raw-expr'\n ) {\n return expr;\n }\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction toSetExpression(value: unknown, desc: ColumnDescriptor): AnyExpression {\n if (isExpressionSource(value)) {\n return value.toExpr();\n }\n return ParamRef.of(value, { codec: { codecId: desc.codecId } });\n}\n\nfunction buildInsertRow<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableInsertRow<Schema>,\n): Record<string, InsertValue> {\n const row: Record<string, InsertValue> = {};\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableInsertRow<Schema> maps Schema keys to unknown; indexing by the same string keys is correct by construction'\n >(values);\n for (const [col, desc] of Object.entries(schema)) {\n row[col] = toInsertValue(rawValues[col], desc);\n }\n return row;\n}\n\nfunction buildSetMap<Schema extends ColumnSchema>(\n schema: Schema,\n values: TableSetValues<Schema> | undefined,\n): Record<string, AnyExpression> {\n if (values === undefined) return {};\n const set: Record<string, AnyExpression> = {};\n const rawSchema = blindCast<\n Record<string, ColumnDescriptor>,\n 'Schema extends ColumnSchema = Record<string, ColumnDescriptor>; runtime key access is correct by construction'\n >(schema);\n const rawValues = blindCast<\n Record<string, unknown>,\n 'TableSetValues<Schema> maps Schema keys to unknown; iterating with Object.entries is correct by construction'\n >(values);\n for (const [col, value] of Object.entries(rawValues)) {\n const desc = rawSchema[col];\n if (desc !== undefined) {\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AE,CAAC;AAChE;AAEA,SAAS,eACP,QACA,QAC6B;CAC7B,MAAM,MAAmC,CAAC;CAC1C,MAAM,YAAY,UAGhB,MAAM;CACR,KAAK,MAAM,CAAC,KAAK,SAAS,OAAO,QAAQ,MAAM,GAC7C,IAAI,OAAO,cAAc,UAAU,MAAM,IAAI;CAE/C,OAAO;AACT;AAEA,SAAS,YACP,QACA,QAC+B;CAC/B,IAAI,WAAW,KAAA,GAAW,OAAO,CAAC;CAClC,MAAM,MAAqC,CAAC;CAC5C,MAAM,YAAY,UAGhB,MAAM;CACR,MAAM,YAAY,UAGhB,MAAM;CACR,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,GAAG;EACpD,MAAM,OAAO,UAAU;EACvB,IAAI,SAAS,KAAA,GACX,IAAI,OAAO,gBAAgB,OAAO,IAAI;CAE1C;CACA,OAAO;AACT"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as CodecMeta, c as ContractCodecRegistry, d as DescriptorCodecTraits, f as ExtractCodecTypes, h as SqlColumnRef, i as CodecDescriptor, l as DescriptorCodecId, m as SqlCodecInstanceContext, n as Codec, o as CodecRef, p as SqlCodecCallContext, r as CodecCallContext, s as CodecTrait, t as AnyCodecDescriptor, u as DescriptorCodecInput } from "./codec-types-DFLA6Hmj.mjs";
|
|
2
2
|
import { $ as RawSqlExpr, A as InsertAst, B as LiteralExpr, C as EqColJoinOn, D as ExpressionRewriter, E as ExpressionFolder, F as JsonArrayAggExpr, G as OperationExpr, H as LoweredStatement, I as JsonObjectEntry, J as ParamRef, K as OrExpr, L as JsonObjectExpr, M as InsertValue, N as JoinAst, O as ExpressionSource, P as JoinOnExpr, Q as RawExpr, R as LimitOffsetValue, S as DoUpdateSetConflictAction, T as ExprVisitor, U as NotExpr, V as LoweredParam, W as NullCheckExpr, X as ProjectionExpr, Y as PreparedParamRef, Z as ProjectionItem, _ as DefaultValueExpr, a as AndExpr, at as TableSource, b as Direction, c as AnyInsertOnConflictAction, ct as WhereArg, d as AnyParamRef, dt as isQueryAst, et as RawSqlLiteral, f as AnyQueryAst, ft as isWhereExpr, g as ColumnRef, h as BinaryOp, i as AggregateOpFn, it as TableRef, j as InsertOnConflict, k as IdentifierRef, l as AnyInsertValue, lt as WindowFn, m as BinaryExpr, mt as whereExprKinds, n as AggregateExpr, nt as SelectAstOptions, o as AnyExpression, ot as ToWhereExpr, p as AstRewriter, pt as queryAstKinds, q as OrderByItem, r as AggregateFn, rt as SubqueryExpr, s as AnyFromSource, st as UpdateAst, t as AggregateCountFn, tt as SelectAst, u as AnyOperationArg, ut as WindowFuncExpr, v as DeleteAst, w as ExistsExpr, x as DoNothingConflictAction, y as DerivedTableSource, z as ListExpression } from "./types-BbGUx5Bi.mjs";
|
|
3
|
-
import { a as DdlColumnRenderContext, c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, i as DdlColumnDefaultVisitor, l as FunctionColumnDefault, n as DdlColumn, o as DdlNode, p as isDdlNode, r as DdlColumnDefault, s as DdlTableConstraint, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "./ddl-types-
|
|
3
|
+
import { a as DdlColumnRenderContext, c as ForeignKeyConstraint, d as PrimaryKeyConstraint, f as UniqueConstraint, i as DdlColumnDefaultVisitor, l as FunctionColumnDefault, n as DdlColumn, o as DdlNode, p as isDdlNode, r as DdlColumnDefault, s as DdlTableConstraint, t as AnyDdlColumnDefault, u as LiteralColumnDefault } from "./ddl-types-CrjJ5Mlu.mjs";
|
|
4
4
|
import { Adapter, AdapterProfile, AdapterTarget, Lowerer, LowererContext, MarkerReadResult, PreparedExecuteRequest, SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SqlCharCodec, SqlCharDescriptor, SqlConnection, SqlDriver, SqlDriverState, SqlExecuteRequest, SqlExplainResult, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlQueryResult, SqlQueryable, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlTransaction, SqlVarcharCodec, SqlVarcharDescriptor, collectOrderedParamRefs, compact, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType } from "./exports/ast.mjs";
|
|
5
5
|
import { a as MutationDefaultsOptions, i as MutationDefaultsOp, n as CodecDescriptorRegistry, o as TypeHelperRegistry, r as ExecutionContext, t as AppliedMutationDefault } from "./query-lane-context-CY0-e8Qo.mjs";
|
|
6
6
|
import { t as SqlExecutionPlan } from "./sql-execution-plan-JwVeAzXt.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, l as isDdlNode, n as DdlColumnDefault, o as LiteralColumnDefault, r as DdlNode, s as PrimaryKeyConstraint, t as DdlColumn } from "./ddl-types-
|
|
1
|
+
import { a as FunctionColumnDefault, c as UniqueConstraint, i as ForeignKeyConstraint, l as isDdlNode, n as DdlColumnDefault, o as LiteralColumnDefault, r as DdlNode, s as PrimaryKeyConstraint, t as DdlColumn } from "./ddl-types-DAox2c8w.mjs";
|
|
2
2
|
import { A as SelectAst, C as OrExpr, D as ProjectionItem, E as PreparedParamRef, F as isQueryAst, I as isWhereExpr, L as queryAstKinds, M as TableSource, N as UpdateAst, O as RawExpr, P as WindowFuncExpr, R as whereExprKinds, S as OperationExpr, T as ParamRef, _ as JsonObjectExpr, a as DefaultValueExpr, b as NotExpr, c as DoNothingConflictAction, d as ExistsExpr, f as IdentifierRef, g as JsonArrayAggExpr, h as JoinAst, i as ColumnRef, j as SubqueryExpr, k as RawSqlExpr, l as DoUpdateSetConflictAction, m as InsertOnConflict, n as AndExpr, o as DeleteAst, p as InsertAst, r as BinaryExpr, s as DerivedTableSource, t as AggregateExpr, u as EqColJoinOn, v as ListExpression, w as OrderByItem, x as NullCheckExpr, y as LiteralExpr } from "./types-D72v8s92.mjs";
|
|
3
3
|
import { n as compact, t as collectOrderedParamRefs } from "./util-DQQgv2j1.mjs";
|
|
4
4
|
import { SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC_ID, SQL_TIMESTAMP_CODEC_ID, SQL_VARCHAR_CODEC_ID, SqlCharCodec, SqlCharDescriptor, SqlFloatCodec, SqlFloatDescriptor, SqlIntCodec, SqlIntDescriptor, SqlTextCodec, SqlTextDescriptor, SqlTimestampCodec, SqlTimestampDescriptor, SqlVarcharCodec, SqlVarcharDescriptor, sqlCharColumn, sqlCharDecode, sqlCharDescriptor, sqlCharEncode, sqlCharRenderOutputType, sqlFloatColumn, sqlFloatDecode, sqlFloatDescriptor, sqlFloatEncode, sqlIntColumn, sqlIntDecode, sqlIntDescriptor, sqlIntEncode, sqlTextColumn, sqlTextDecode, sqlTextDescriptor, sqlTextEncode, sqlTimestampColumn, sqlTimestampDecode, sqlTimestampDecodeJson, sqlTimestampDescriptor, sqlTimestampEncode, sqlTimestampEncodeJson, sqlTimestampRenderOutputType, sqlVarcharColumn, sqlVarcharDecode, sqlVarcharDescriptor, sqlVarcharEncode, sqlVarcharRenderOutputType } from "./exports/ast.mjs";
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-relational-core",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "AST types, query lane context, and type utilities for Prisma Next SQL lanes",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/contract": "0.13.0-dev.
|
|
10
|
-
"@prisma-next/framework-components": "0.13.0-dev.
|
|
11
|
-
"@prisma-next/operations": "0.13.0-dev.
|
|
12
|
-
"@prisma-next/sql-contract": "0.13.0-dev.
|
|
13
|
-
"@prisma-next/sql-operations": "0.13.0-dev.
|
|
14
|
-
"@prisma-next/utils": "0.13.0-dev.
|
|
9
|
+
"@prisma-next/contract": "0.13.0-dev.31",
|
|
10
|
+
"@prisma-next/framework-components": "0.13.0-dev.31",
|
|
11
|
+
"@prisma-next/operations": "0.13.0-dev.31",
|
|
12
|
+
"@prisma-next/sql-contract": "0.13.0-dev.31",
|
|
13
|
+
"@prisma-next/sql-operations": "0.13.0-dev.31",
|
|
14
|
+
"@prisma-next/utils": "0.13.0-dev.31",
|
|
15
15
|
"@standard-schema/spec": "^1.1.0",
|
|
16
16
|
"arktype": "^2.2.0",
|
|
17
17
|
"ts-toolbelt": "^9.6.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@prisma-next/sql-contract-ts": "0.13.0-dev.
|
|
21
|
-
"@prisma-next/test-utils": "0.13.0-dev.
|
|
22
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
23
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
20
|
+
"@prisma-next/sql-contract-ts": "0.13.0-dev.31",
|
|
21
|
+
"@prisma-next/test-utils": "0.13.0-dev.31",
|
|
22
|
+
"@prisma-next/tsconfig": "0.13.0-dev.31",
|
|
23
|
+
"@prisma-next/tsdown": "0.13.0-dev.31",
|
|
24
24
|
"tsdown": "0.22.1",
|
|
25
25
|
"typescript": "5.9.3",
|
|
26
26
|
"vitest": "4.1.8"
|
package/src/ast/ddl-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
2
2
|
import { isColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
3
3
|
import type { ReferentialAction } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import type { CodecRef } from './codec-types';
|
|
4
5
|
import type { AnyParamRef } from './types';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -71,6 +72,8 @@ export class DdlColumn {
|
|
|
71
72
|
readonly notNull?: boolean | undefined;
|
|
72
73
|
readonly primaryKey?: boolean | undefined;
|
|
73
74
|
readonly default?: AnyDdlColumnDefault | undefined;
|
|
75
|
+
/** Codec identity for this column. When present, the DDL walker resolves the codec via `codecLookup.get(codecRef.codecId)` and calls `codec.encode(default.value, {})` to obtain the wire value before inlining the literal default into the DDL string. When absent, literal defaults follow RawSqlLiteral wire-scalar semantics (string / number / boolean / bigint / null / Uint8Array / Date inlined directly). */
|
|
76
|
+
readonly codecRef?: CodecRef | undefined;
|
|
74
77
|
|
|
75
78
|
constructor(options: {
|
|
76
79
|
readonly name: string;
|
|
@@ -78,12 +81,14 @@ export class DdlColumn {
|
|
|
78
81
|
readonly notNull?: boolean;
|
|
79
82
|
readonly primaryKey?: boolean;
|
|
80
83
|
readonly default?: AnyDdlColumnDefault;
|
|
84
|
+
readonly codecRef?: CodecRef;
|
|
81
85
|
}) {
|
|
82
86
|
this.name = options.name;
|
|
83
87
|
this.type = options.type;
|
|
84
88
|
this.notNull = options.notNull;
|
|
85
89
|
this.primaryKey = options.primaryKey;
|
|
86
90
|
this.default = options.default;
|
|
91
|
+
this.codecRef = options.codecRef;
|
|
87
92
|
Object.freeze(this);
|
|
88
93
|
}
|
|
89
94
|
}
|
package/src/ast/driver-types.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fully lowered SQL statement ready for a driver to execute: SQL text plus
|
|
3
|
+
* driver-ready (codec-encoded) parameter values. The output of the control
|
|
4
|
+
* adapter's `lowerToExecuteRequest`, handed to a driver via `SqlQueryable.query`
|
|
5
|
+
* or `execute`. Inline-substituted positions (e.g. DDL `DEFAULT`
|
|
6
|
+
* clauses) carry no param; `params` holds the wire values for the `$N`/`?`
|
|
7
|
+
* positions, in order.
|
|
8
|
+
*/
|
|
1
9
|
export interface SqlExecuteRequest {
|
|
2
10
|
readonly sql: string;
|
|
3
11
|
readonly params?: readonly unknown[];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import type { JsonValue } from '@prisma-next/contract/types';
|
|
2
2
|
import type { CodecRef } from '@prisma-next/framework-components/codec';
|
|
3
3
|
import { resolveStorageTable } from '@prisma-next/sql-contract/resolve-storage-table';
|
|
4
|
-
import {
|
|
5
|
-
isPostgresEnumStorageEntry,
|
|
6
|
-
isStorageTypeInstance,
|
|
7
|
-
type SqlStorage,
|
|
8
|
-
} from '@prisma-next/sql-contract/types';
|
|
4
|
+
import { isStorageTypeInstance, type SqlStorage } from '@prisma-next/sql-contract/types';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Derive the canonical {@link CodecRef} for a `(table, column)` pair against a {@link SqlStorage}. This is the build-time path every column-bound `ParamRef` / `ProjectionItem` uses to stamp its `codec` slot before the AST is handed to the runtime — the runtime resolver then materialises a memoised {@link import('@prisma-next/sql-relational-core/ast').Codec} for the same `CodecRef` via `forCodecRef`.
|
|
@@ -34,38 +30,9 @@ export function codecRefForStorageColumn(
|
|
|
34
30
|
const columnDef = tableDef.columns[columnName];
|
|
35
31
|
if (!columnDef) return undefined;
|
|
36
32
|
if (columnDef.typeRef !== undefined) {
|
|
37
|
-
|
|
38
|
-
if (!instance) {
|
|
39
|
-
for (const ns of Object.values(storage.namespaces)) {
|
|
40
|
-
const typeSlot = (ns.entries as { type?: Record<string, unknown> }).type;
|
|
41
|
-
const nsEntry = typeSlot?.[columnDef.typeRef];
|
|
42
|
-
if (nsEntry !== undefined) {
|
|
43
|
-
instance = nsEntry;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
33
|
+
const instance = storage.types?.[columnDef.typeRef];
|
|
48
34
|
if (!instance) return undefined;
|
|
49
|
-
if (isPostgresEnumStorageEntry(instance)) {
|
|
50
|
-
// Canonical path: the entry is a live `PostgresEnumType` IR
|
|
51
|
-
// instance reached through the per-target serializer's
|
|
52
|
-
// hydration. Raw JSON envelopes carrying `kind: 'postgres-enum'`
|
|
53
|
-
// never reach this site — `SqlStorage.normaliseTypeEntry`
|
|
54
|
-
// rejects them upstream (F09). Read `codecId` and `values` off
|
|
55
|
-
// the structural shape (enumerable own properties on the live
|
|
56
|
-
// instance) so the dispatch stays layered against the family
|
|
57
|
-
// alphabet rather than a target-specific class import.
|
|
58
|
-
return {
|
|
59
|
-
codecId: instance.codecId,
|
|
60
|
-
typeParams: { values: instance.values } as unknown as JsonValue,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
35
|
if (isStorageTypeInstance(instance)) {
|
|
64
|
-
// Empty-state canonicalization: a `StorageTypeInstance` with absent
|
|
65
|
-
// (or empty) `typeParams` produces a `CodecRef` with no `typeParams`
|
|
66
|
-
// field. Equivalent to the non-parameterized-column branch below.
|
|
67
|
-
// Carrying `{}` here would break content-keyed memoisation and trip
|
|
68
|
-
// the runtime validator against non-parameterized codec descriptors.
|
|
69
36
|
const instanceParams = instance.typeParams;
|
|
70
37
|
const hasParamKeys = instanceParams !== undefined && Object.keys(instanceParams).length > 0;
|
|
71
38
|
return hasParamKeys
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
2
2
|
import type { ReferentialAction } from '@prisma-next/sql-contract/types';
|
|
3
|
+
import type { CodecRef } from '../ast/codec-types';
|
|
3
4
|
import type { AnyDdlColumnDefault } from '../ast/ddl-types';
|
|
4
5
|
import {
|
|
5
6
|
DdlColumn,
|
|
@@ -14,6 +15,7 @@ export interface DdlColumnOptions {
|
|
|
14
15
|
readonly notNull?: boolean;
|
|
15
16
|
readonly primaryKey?: boolean;
|
|
16
17
|
readonly default?: AnyDdlColumnDefault;
|
|
18
|
+
readonly codecRef?: CodecRef;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export function lit(value: ColumnDefaultLiteralInputValue): LiteralColumnDefault {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ddl-types-D3vlEjMA.d.mts","names":[],"sources":["../src/ast/ddl-types.ts"],"mappings":";;;;;;;AAcA;;;;AACqB;AAGrB;;UAJiB,sBAAA;EAAA,SACN,UAAU;AAAA;AAAA,UAGJ,uBAAA;EACf,OAAA,CAAQ,IAAA,EAAM,oBAAA,EAAsB,GAAA,EAAK,sBAAA,GAAyB,CAAA;EAClE,QAAA,CAAS,IAAA,EAAM,qBAAA,EAAuB,GAAA,EAAK,sBAAA,GAAyB,CAAA;AAAA;AAAA,uBAGhD,gBAAA;EAAA,kBACF,IAAA;EAAA,SACT,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBAAA,GAAyB,CAAA;EAAA,UAE5E,MAAA;AAAA;AAAA,cAKC,oBAAA,SAA6B,gBAAA;EAAA,SAC/B,IAAA;EAAA,SACA,KAAA,EAAO,8BAAA;cAEJ,KAAA,EAAO,8BAAA;EASV,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBAAA,GAAyB,CAAA;AAAA;AAAA,cAK3E,qBAAA,SAA8B,gBAAA;EAAA,SAChC,IAAA;EAAA,SACA,UAAA;cAEG,UAAA;EAMH,MAAA,IAAU,OAAA,EAAS,uBAAA,CAAwB,CAAA,GAAI,GAAA,EAAK,sBAAA,GAAyB,CAAA;AAAA;AAAA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1
|
-
{"version":3,"file":"ddl-types-X9_XHUl0.mjs","names":[],"sources":["../src/ast/ddl-types.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport { isColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport type { AnyParamRef } from './types';\n\n/**\n * Render-time context the column-default visitor needs to make dialect\n * decisions that depend on the parent column. Today only the parent\n * column's native type (`\"jsonb\"`, `\"text\"`, …) — the Postgres renderer\n * uses it to decide whether to emit a `::jsonb` / `::json` cast on JSON\n * literal defaults so the emitted DDL matches the column type without\n * relying on Postgres's implicit text → jsonb cast at default-evaluation\n * time. Additional fields can join without re-shaping the interface.\n */\nexport interface DdlColumnRenderContext {\n readonly nativeType: string;\n}\n\nexport interface DdlColumnDefaultVisitor<R> {\n literal(node: LiteralColumnDefault, ctx: DdlColumnRenderContext): R;\n function(node: FunctionColumnDefault, ctx: DdlColumnRenderContext): R;\n}\n\nexport abstract class DdlColumnDefault {\n abstract readonly kind: string;\n abstract accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R;\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\nexport class LiteralColumnDefault extends DdlColumnDefault {\n readonly kind = 'literal' as const;\n readonly value: ColumnDefaultLiteralInputValue;\n\n constructor(value: ColumnDefaultLiteralInputValue) {\n super();\n if (!isColumnDefaultLiteralInputValue(value)) {\n throw new Error('Invalid column default literal value');\n }\n this.value = value;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.literal(this, ctx);\n }\n}\n\nexport class FunctionColumnDefault extends DdlColumnDefault {\n readonly kind = 'function' as const;\n readonly expression: string;\n\n constructor(expression: string) {\n super();\n this.expression = expression;\n this.freeze();\n }\n\n override accept<R>(visitor: DdlColumnDefaultVisitor<R>, ctx: DdlColumnRenderContext): R {\n return visitor.function(this, ctx);\n }\n}\n\nexport type AnyDdlColumnDefault = LiteralColumnDefault | FunctionColumnDefault;\n\nexport class DdlColumn {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean | undefined;\n readonly primaryKey?: boolean | undefined;\n readonly default?: AnyDdlColumnDefault | undefined;\n\n constructor(options: {\n readonly name: string;\n readonly type: string;\n readonly notNull?: boolean;\n readonly primaryKey?: boolean;\n readonly default?: AnyDdlColumnDefault;\n }) {\n this.name = options.name;\n this.type = options.type;\n this.notNull = options.notNull;\n this.primaryKey = options.primaryKey;\n this.default = options.default;\n Object.freeze(this);\n }\n}\n\nexport abstract class DdlNode {\n abstract readonly kind: string;\n\n /**\n * Structural brand: every DDL node answers `true`. Lets {@link isDdlNode}\n * recognise any `DdlNode` subclass — including target-contributed kinds —\n * without a central kind registry that subclasses would have to register\n * into.\n */\n isDdlNode(): true {\n return true;\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n\n collectParamRefs(): AnyParamRef[] {\n return [];\n }\n}\n\nexport function isDdlNode(value: unknown): value is DdlNode {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'isDdlNode' in value &&\n typeof value.isDdlNode === 'function'\n );\n}\n\n// ---------------------------------------------------------------------------\n// Table-level constraint nodes\n// ---------------------------------------------------------------------------\n\n/**\n * A composite (or single-column) PRIMARY KEY constraint on a `CreateTable`\n * node. When `name` is set, the adapter renders `CONSTRAINT <name> PRIMARY KEY\n * (…)`; otherwise it renders an anonymous `PRIMARY KEY (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class PrimaryKeyConstraint {\n readonly kind = 'primary-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A FOREIGN KEY constraint on a `CreateTable` node. `onDelete` and `onUpdate`\n * use the same `ReferentialAction` vocabulary already used by the migration\n * planner and the contract IR — no parallel string enum.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class ForeignKeyConstraint {\n readonly kind = 'foreign-key' as const;\n readonly columns: ReadonlyArray<string>;\n readonly refTable: string;\n readonly refColumns: ReadonlyArray<string>;\n readonly onDelete: ReferentialAction | undefined;\n readonly onUpdate: ReferentialAction | undefined;\n readonly name: string | undefined;\n\n constructor(options: {\n readonly columns: readonly string[];\n readonly refTable: string;\n readonly refColumns: readonly string[];\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly name?: string;\n }) {\n this.columns = Object.freeze([...options.columns]);\n this.refTable = options.refTable;\n this.refColumns = Object.freeze([...options.refColumns]);\n this.onDelete = options.onDelete;\n this.onUpdate = options.onUpdate;\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\n/**\n * A table-level UNIQUE constraint on a `CreateTable` node. When `name` is\n * set, the adapter renders `CONSTRAINT <name> UNIQUE (…)`; otherwise it\n * renders an anonymous `UNIQUE (…)`.\n *\n * Frozen on construction — immutable after creation.\n */\nexport class UniqueConstraint {\n readonly kind = 'unique' as const;\n readonly columns: ReadonlyArray<string>;\n readonly name: string | undefined;\n\n constructor(options: { readonly columns: readonly string[]; readonly name?: string }) {\n this.columns = Object.freeze([...options.columns]);\n this.name = options.name;\n Object.freeze(this);\n }\n}\n\nexport type DdlTableConstraint = PrimaryKeyConstraint | ForeignKeyConstraint | UniqueConstraint;\n"],"mappings":";;AAuBA,IAAsB,mBAAtB,MAAuC;CAIrC,SAAyB;EACvB,OAAO,OAAO,IAAI;CACpB;AACF;AAEA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD,OAAgB;CAChB;CAEA,YAAY,OAAuC;EACjD,MAAM;EACN,IAAI,CAAC,iCAAiC,KAAK,GACzC,MAAM,IAAI,MAAM,sCAAsC;EAExD,KAAK,QAAQ;EACb,KAAK,OAAO;CACd;CAEA,OAAmB,SAAqC,KAAgC;EACtF,OAAO,QAAQ,QAAQ,MAAM,GAAG;CA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