@prisma-next/adapter-postgres 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,288 @@
1
+ import {
2
+ codecDefinitions
3
+ } from "./chunk-CPAKRHXM.js";
4
+
5
+ // src/core/adapter.ts
6
+ import { createCodecRegistry, isOperationExpr } from "@prisma-next/sql-relational-core/ast";
7
+ var defaultCapabilities = Object.freeze({
8
+ postgres: {
9
+ orderBy: true,
10
+ limit: true,
11
+ lateral: true,
12
+ jsonAgg: true,
13
+ returning: true
14
+ }
15
+ });
16
+ var PostgresAdapterImpl = class {
17
+ profile;
18
+ codecRegistry = (() => {
19
+ const registry = createCodecRegistry();
20
+ for (const definition of Object.values(codecDefinitions)) {
21
+ registry.register(definition.codec);
22
+ }
23
+ return registry;
24
+ })();
25
+ constructor(options) {
26
+ this.profile = Object.freeze({
27
+ id: options?.profileId ?? "postgres/default@1",
28
+ target: "postgres",
29
+ capabilities: defaultCapabilities,
30
+ codecs: () => this.codecRegistry
31
+ });
32
+ }
33
+ lower(ast, context) {
34
+ let sql;
35
+ const params = context.params ? [...context.params] : [];
36
+ if (ast.kind === "select") {
37
+ sql = renderSelect(ast, context.contract);
38
+ } else if (ast.kind === "insert") {
39
+ sql = renderInsert(ast, context.contract);
40
+ } else if (ast.kind === "update") {
41
+ sql = renderUpdate(ast, context.contract);
42
+ } else if (ast.kind === "delete") {
43
+ sql = renderDelete(ast, context.contract);
44
+ } else {
45
+ throw new Error(`Unsupported AST kind: ${ast.kind}`);
46
+ }
47
+ return Object.freeze({
48
+ profileId: this.profile.id,
49
+ body: Object.freeze({ sql, params })
50
+ });
51
+ }
52
+ };
53
+ function renderSelect(ast, contract) {
54
+ const selectClause = `SELECT ${renderProjection(ast, contract)}`;
55
+ const fromClause = `FROM ${quoteIdentifier(ast.from.name)}`;
56
+ const joinsClause = ast.joins?.length ? ast.joins.map((join) => renderJoin(join, contract)).join(" ") : "";
57
+ const includesClause = ast.includes?.length ? ast.includes.map((include) => renderInclude(include, contract)).join(" ") : "";
58
+ const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : "";
59
+ const orderClause = ast.orderBy?.length ? ` ORDER BY ${ast.orderBy.map((order) => {
60
+ const expr = renderExpr(order.expr, contract);
61
+ return `${expr} ${order.dir.toUpperCase()}`;
62
+ }).join(", ")}` : "";
63
+ const limitClause = typeof ast.limit === "number" ? ` LIMIT ${ast.limit}` : "";
64
+ const clauses = [joinsClause, includesClause].filter(Boolean).join(" ");
65
+ return `${selectClause} ${fromClause}${clauses ? ` ${clauses}` : ""}${whereClause}${orderClause}${limitClause}`.trim();
66
+ }
67
+ function renderProjection(ast, contract) {
68
+ return ast.project.map((item) => {
69
+ const expr = item.expr;
70
+ if (expr.kind === "includeRef") {
71
+ const tableAlias = `${expr.alias}_lateral`;
72
+ return `${quoteIdentifier(tableAlias)}.${quoteIdentifier(expr.alias)} AS ${quoteIdentifier(item.alias)}`;
73
+ }
74
+ if (expr.kind === "operation") {
75
+ const operation = renderOperation(expr, contract);
76
+ const alias2 = quoteIdentifier(item.alias);
77
+ return `${operation} AS ${alias2}`;
78
+ }
79
+ if (expr.kind === "literal") {
80
+ const literal = renderLiteral(expr);
81
+ const alias2 = quoteIdentifier(item.alias);
82
+ return `${literal} AS ${alias2}`;
83
+ }
84
+ const column = renderColumn(expr);
85
+ const alias = quoteIdentifier(item.alias);
86
+ return `${column} AS ${alias}`;
87
+ }).join(", ");
88
+ }
89
+ function renderWhere(expr, contract) {
90
+ if (expr.kind === "exists") {
91
+ const notKeyword = expr.not ? "NOT " : "";
92
+ const subquery = renderSelect(expr.subquery, contract);
93
+ return `${notKeyword}EXISTS (${subquery})`;
94
+ }
95
+ return renderBinary(expr, contract);
96
+ }
97
+ function renderBinary(expr, contract) {
98
+ const leftExpr = expr.left;
99
+ const left = renderExpr(leftExpr, contract);
100
+ const rightExpr = expr.right;
101
+ const right = rightExpr.kind === "col" ? renderColumn(rightExpr) : renderParam(rightExpr, contract);
102
+ const leftRendered = isOperationExpr(leftExpr) ? `(${left})` : left;
103
+ return `${leftRendered} = ${right}`;
104
+ }
105
+ function renderColumn(ref) {
106
+ return `${quoteIdentifier(ref.table)}.${quoteIdentifier(ref.column)}`;
107
+ }
108
+ function renderExpr(expr, contract) {
109
+ if (isOperationExpr(expr)) {
110
+ return renderOperation(expr, contract);
111
+ }
112
+ return renderColumn(expr);
113
+ }
114
+ function renderParam(ref, contract, tableName, columnName) {
115
+ if (contract && tableName && columnName) {
116
+ const tableMeta = contract.storage.tables[tableName];
117
+ const columnMeta = tableMeta?.columns[columnName];
118
+ if (columnMeta?.type === "pg/vector@1") {
119
+ return `$${ref.index}::vector`;
120
+ }
121
+ }
122
+ return `$${ref.index}`;
123
+ }
124
+ function renderLiteral(expr) {
125
+ if (typeof expr.value === "string") {
126
+ return `'${expr.value.replace(/'/g, "''")}'`;
127
+ }
128
+ if (typeof expr.value === "number" || typeof expr.value === "boolean") {
129
+ return String(expr.value);
130
+ }
131
+ if (expr.value === null) {
132
+ return "NULL";
133
+ }
134
+ if (Array.isArray(expr.value)) {
135
+ return `ARRAY[${expr.value.map((v) => renderLiteral({ kind: "literal", value: v })).join(", ")}]`;
136
+ }
137
+ return JSON.stringify(expr.value);
138
+ }
139
+ function renderOperation(expr, contract) {
140
+ const self = renderExpr(expr.self, contract);
141
+ const isVectorOperation = expr.forTypeId === "pg/vector@1";
142
+ const args = expr.args.map((arg) => {
143
+ if (arg.kind === "col") {
144
+ return renderColumn(arg);
145
+ }
146
+ if (arg.kind === "param") {
147
+ return isVectorOperation ? `$${arg.index}::vector` : renderParam(arg, contract);
148
+ }
149
+ if (arg.kind === "literal") {
150
+ return renderLiteral(arg);
151
+ }
152
+ if (arg.kind === "operation") {
153
+ return renderOperation(arg, contract);
154
+ }
155
+ const _exhaustive = arg;
156
+ throw new Error(`Unsupported argument kind: ${_exhaustive.kind}`);
157
+ });
158
+ let result = expr.lowering.template;
159
+ result = result.replace(/\$\{self\}/g, self);
160
+ for (let i = 0; i < args.length; i++) {
161
+ result = result.replace(new RegExp(`\\$\\{arg${i}\\}`, "g"), args[i] ?? "");
162
+ }
163
+ if (expr.lowering.strategy === "function") {
164
+ return result;
165
+ }
166
+ return result;
167
+ }
168
+ function renderJoin(join, _contract) {
169
+ const joinType = join.joinType.toUpperCase();
170
+ const table = quoteIdentifier(join.table.name);
171
+ const onClause = renderJoinOn(join.on);
172
+ return `${joinType} JOIN ${table} ON ${onClause}`;
173
+ }
174
+ function renderJoinOn(on) {
175
+ if (on.kind === "eqCol") {
176
+ const left = renderColumn(on.left);
177
+ const right = renderColumn(on.right);
178
+ return `${left} = ${right}`;
179
+ }
180
+ throw new Error(`Unsupported join ON expression kind: ${on.kind}`);
181
+ }
182
+ function renderInclude(include, contract) {
183
+ const alias = include.alias;
184
+ const childProjection = include.child.project.map((item) => {
185
+ const expr = renderExpr(item.expr, contract);
186
+ return `'${item.alias}', ${expr}`;
187
+ }).join(", ");
188
+ const jsonBuildObject = `json_build_object(${childProjection})`;
189
+ const onCondition = renderJoinOn(include.child.on);
190
+ let whereClause = ` WHERE ${onCondition}`;
191
+ if (include.child.where) {
192
+ whereClause += ` AND ${renderWhere(include.child.where, contract)}`;
193
+ }
194
+ const childOrderBy = include.child.orderBy?.length ? ` ORDER BY ${include.child.orderBy.map(
195
+ (order) => `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`
196
+ ).join(", ")}` : "";
197
+ const childLimit = typeof include.child.limit === "number" ? ` LIMIT ${include.child.limit}` : "";
198
+ const childTable = quoteIdentifier(include.child.table.name);
199
+ let subquery;
200
+ if (typeof include.child.limit === "number") {
201
+ const columnAliasMap = /* @__PURE__ */ new Map();
202
+ for (const item of include.child.project) {
203
+ if (item.expr.kind === "col") {
204
+ const columnKey = `${item.expr.table}.${item.expr.column}`;
205
+ columnAliasMap.set(columnKey, item.alias);
206
+ }
207
+ }
208
+ const innerColumns = include.child.project.map((item) => {
209
+ const expr = renderExpr(item.expr, contract);
210
+ return `${expr} AS ${quoteIdentifier(item.alias)}`;
211
+ }).join(", ");
212
+ const childOrderByWithAliases = include.child.orderBy?.length ? ` ORDER BY ${include.child.orderBy.map((order) => {
213
+ if (order.expr.kind === "col") {
214
+ const columnKey = `${order.expr.table}.${order.expr.column}`;
215
+ const alias2 = columnAliasMap.get(columnKey);
216
+ if (alias2) {
217
+ return `${quoteIdentifier(alias2)} ${order.dir.toUpperCase()}`;
218
+ }
219
+ }
220
+ return `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`;
221
+ }).join(", ")}` : "";
222
+ const innerSelect = `SELECT ${innerColumns} FROM ${childTable}${whereClause}${childOrderByWithAliases}${childLimit}`;
223
+ subquery = `(SELECT json_agg(row_to_json(sub.*)) AS ${quoteIdentifier(alias)} FROM (${innerSelect}) sub)`;
224
+ } else if (childOrderBy) {
225
+ subquery = `(SELECT json_agg(${jsonBuildObject}${childOrderBy}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;
226
+ } else {
227
+ subquery = `(SELECT json_agg(${jsonBuildObject}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;
228
+ }
229
+ const tableAlias = `${alias}_lateral`;
230
+ return `LEFT JOIN LATERAL ${subquery} AS ${quoteIdentifier(tableAlias)} ON true`;
231
+ }
232
+ function quoteIdentifier(identifier) {
233
+ return `"${identifier.replace(/"/g, '""')}"`;
234
+ }
235
+ function renderInsert(ast, contract) {
236
+ const table = quoteIdentifier(ast.table.name);
237
+ const columns = Object.keys(ast.values).map((col) => quoteIdentifier(col));
238
+ const tableMeta = contract.storage.tables[ast.table.name];
239
+ const values = Object.entries(ast.values).map(([colName, val]) => {
240
+ if (val.kind === "param") {
241
+ const columnMeta = tableMeta?.columns[colName];
242
+ const isVector = columnMeta?.type === "pg/vector@1";
243
+ return isVector ? `$${val.index}::vector` : `$${val.index}`;
244
+ }
245
+ if (val.kind === "col") {
246
+ return `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;
247
+ }
248
+ throw new Error(`Unsupported value kind in INSERT: ${val.kind}`);
249
+ });
250
+ const insertClause = `INSERT INTO ${table} (${columns.join(", ")}) VALUES (${values.join(", ")})`;
251
+ const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : "";
252
+ return `${insertClause}${returningClause}`;
253
+ }
254
+ function renderUpdate(ast, contract) {
255
+ const table = quoteIdentifier(ast.table.name);
256
+ const tableMeta = contract.storage.tables[ast.table.name];
257
+ const setClauses = Object.entries(ast.set).map(([col, val]) => {
258
+ const column = quoteIdentifier(col);
259
+ let value;
260
+ if (val.kind === "param") {
261
+ const columnMeta = tableMeta?.columns[col];
262
+ const isVector = columnMeta?.type === "pg/vector@1";
263
+ value = isVector ? `$${val.index}::vector` : `$${val.index}`;
264
+ } else if (val.kind === "col") {
265
+ value = `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;
266
+ } else {
267
+ throw new Error(`Unsupported value kind in UPDATE: ${val.kind}`);
268
+ }
269
+ return `${column} = ${value}`;
270
+ });
271
+ const whereClause = ` WHERE ${renderBinary(ast.where, contract)}`;
272
+ const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : "";
273
+ return `UPDATE ${table} SET ${setClauses.join(", ")}${whereClause}${returningClause}`;
274
+ }
275
+ function renderDelete(ast, contract) {
276
+ const table = quoteIdentifier(ast.table.name);
277
+ const whereClause = ` WHERE ${renderBinary(ast.where, contract)}`;
278
+ const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : "";
279
+ return `DELETE FROM ${table}${whereClause}${returningClause}`;
280
+ }
281
+ function createPostgresAdapter(options) {
282
+ return Object.freeze(new PostgresAdapterImpl(options));
283
+ }
284
+
285
+ export {
286
+ createPostgresAdapter
287
+ };
288
+ //# sourceMappingURL=chunk-NOYZK3LL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterProfile,\n BinaryExpr,\n ColumnRef,\n DeleteAst,\n ExistsExpr,\n IncludeRef,\n InsertAst,\n JoinAst,\n LiteralExpr,\n LowererContext,\n OperationExpr,\n ParamRef,\n QueryAst,\n SelectAst,\n UpdateAst,\n} from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry, isOperationExpr } from '@prisma-next/sql-relational-core/ast';\nimport { codecDefinitions } from './codecs';\nimport type { PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement } from './types';\n\nconst defaultCapabilities = Object.freeze({\n postgres: {\n orderBy: true,\n limit: true,\n lateral: true,\n jsonAgg: true,\n returning: true,\n },\n});\n\nclass PostgresAdapterImpl implements Adapter<QueryAst, PostgresContract, PostgresLoweredStatement> {\n readonly profile: AdapterProfile<'postgres'>;\n private readonly codecRegistry = (() => {\n const registry = createCodecRegistry();\n for (const definition of Object.values(codecDefinitions)) {\n registry.register(definition.codec);\n }\n return registry;\n })();\n\n constructor(options?: PostgresAdapterOptions) {\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n codecs: () => this.codecRegistry,\n });\n }\n\n lower(ast: QueryAst, context: LowererContext<PostgresContract>) {\n let sql: string;\n const params = context.params ? [...context.params] : [];\n\n if (ast.kind === 'select') {\n sql = renderSelect(ast, context.contract);\n } else if (ast.kind === 'insert') {\n sql = renderInsert(ast, context.contract);\n } else if (ast.kind === 'update') {\n sql = renderUpdate(ast, context.contract);\n } else if (ast.kind === 'delete') {\n sql = renderDelete(ast, context.contract);\n } else {\n throw new Error(`Unsupported AST kind: ${(ast as { kind: string }).kind}`);\n }\n\n return Object.freeze({\n profileId: this.profile.id,\n body: Object.freeze({ sql, params }),\n });\n }\n}\n\nfunction renderSelect(ast: SelectAst, contract?: PostgresContract): string {\n const selectClause = `SELECT ${renderProjection(ast, contract)}`;\n const fromClause = `FROM ${quoteIdentifier(ast.from.name)}`;\n\n const joinsClause = ast.joins?.length\n ? ast.joins.map((join) => renderJoin(join, contract)).join(' ')\n : '';\n const includesClause = ast.includes?.length\n ? ast.includes.map((include) => renderInclude(include, contract)).join(' ')\n : '';\n\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : '';\n const orderClause = ast.orderBy?.length\n ? ` ORDER BY ${ast.orderBy\n .map((order) => {\n const expr = renderExpr(order.expr as ColumnRef | OperationExpr, contract);\n return `${expr} ${order.dir.toUpperCase()}`;\n })\n .join(', ')}`\n : '';\n const limitClause = typeof ast.limit === 'number' ? ` LIMIT ${ast.limit}` : '';\n\n const clauses = [joinsClause, includesClause].filter(Boolean).join(' ');\n return `${selectClause} ${fromClause}${clauses ? ` ${clauses}` : ''}${whereClause}${orderClause}${limitClause}`.trim();\n}\n\nfunction renderProjection(ast: SelectAst, contract?: PostgresContract): string {\n return ast.project\n .map((item) => {\n const expr = item.expr as ColumnRef | IncludeRef | OperationExpr | LiteralExpr;\n if (expr.kind === 'includeRef') {\n // For include references, select the column from the LATERAL join alias\n // The LATERAL subquery returns a single column (the JSON array) with the alias\n // The table is aliased as {alias}_lateral, and the column inside is aliased as the include alias\n // We select it using table_alias.column_alias\n const tableAlias = `${expr.alias}_lateral`;\n return `${quoteIdentifier(tableAlias)}.${quoteIdentifier(expr.alias)} AS ${quoteIdentifier(item.alias)}`;\n }\n if (expr.kind === 'operation') {\n const operation = renderOperation(expr, contract);\n const alias = quoteIdentifier(item.alias);\n return `${operation} AS ${alias}`;\n }\n if (expr.kind === 'literal') {\n const literal = renderLiteral(expr);\n const alias = quoteIdentifier(item.alias);\n return `${literal} AS ${alias}`;\n }\n const column = renderColumn(expr as ColumnRef);\n const alias = quoteIdentifier(item.alias);\n return `${column} AS ${alias}`;\n })\n .join(', ');\n}\n\nfunction renderWhere(expr: BinaryExpr | ExistsExpr, contract?: PostgresContract): string {\n if (expr.kind === 'exists') {\n const notKeyword = expr.not ? 'NOT ' : '';\n const subquery = renderSelect(expr.subquery, contract);\n return `${notKeyword}EXISTS (${subquery})`;\n }\n return renderBinary(expr, contract);\n}\n\nfunction renderBinary(expr: BinaryExpr, contract?: PostgresContract): string {\n const leftExpr = expr.left as ColumnRef | OperationExpr;\n const left = renderExpr(leftExpr, contract);\n // Handle both ParamRef and ColumnRef on the right side\n // (ColumnRef can appear in EXISTS subqueries for correlation)\n const rightExpr = expr.right as ParamRef | ColumnRef;\n const right =\n rightExpr.kind === 'col'\n ? renderColumn(rightExpr)\n : renderParam(rightExpr as ParamRef, contract);\n // Only wrap in parentheses if it's an operation expression\n const leftRendered = isOperationExpr(leftExpr) ? `(${left})` : left;\n return `${leftRendered} = ${right}`;\n}\n\nfunction renderColumn(ref: ColumnRef): string {\n return `${quoteIdentifier(ref.table)}.${quoteIdentifier(ref.column)}`;\n}\n\nfunction renderExpr(expr: ColumnRef | OperationExpr, contract?: PostgresContract): string {\n if (isOperationExpr(expr)) {\n return renderOperation(expr, contract);\n }\n return renderColumn(expr);\n}\n\nfunction renderParam(\n ref: ParamRef,\n contract?: PostgresContract,\n tableName?: string,\n columnName?: string,\n): string {\n // Cast vector parameters to vector type for PostgreSQL\n if (contract && tableName && columnName) {\n const tableMeta = contract.storage.tables[tableName];\n const columnMeta = tableMeta?.columns[columnName];\n if (columnMeta?.type === 'pg/vector@1') {\n return `$${ref.index}::vector`;\n }\n }\n return `$${ref.index}`;\n}\n\nfunction renderLiteral(expr: LiteralExpr): string {\n if (typeof expr.value === 'string') {\n return `'${expr.value.replace(/'/g, \"''\")}'`;\n }\n if (typeof expr.value === 'number' || typeof expr.value === 'boolean') {\n return String(expr.value);\n }\n if (expr.value === null) {\n return 'NULL';\n }\n if (Array.isArray(expr.value)) {\n return `ARRAY[${expr.value.map((v: unknown) => renderLiteral({ kind: 'literal', value: v })).join(', ')}]`;\n }\n return JSON.stringify(expr.value);\n}\n\nfunction renderOperation(expr: OperationExpr, contract?: PostgresContract): string {\n const self = renderExpr(expr.self, contract);\n // For vector operations, cast param arguments to vector type\n const isVectorOperation = expr.forTypeId === 'pg/vector@1';\n const args = expr.args.map((arg: ColumnRef | ParamRef | LiteralExpr | OperationExpr) => {\n if (arg.kind === 'col') {\n return renderColumn(arg);\n }\n if (arg.kind === 'param') {\n // Cast vector operation parameters to vector type\n return isVectorOperation ? `$${arg.index}::vector` : renderParam(arg, contract);\n }\n if (arg.kind === 'literal') {\n return renderLiteral(arg);\n }\n if (arg.kind === 'operation') {\n return renderOperation(arg, contract);\n }\n const _exhaustive: never = arg;\n throw new Error(`Unsupported argument kind: ${(_exhaustive as { kind: string }).kind}`);\n });\n\n let result = expr.lowering.template;\n result = result.replace(/\\$\\{self\\}/g, self);\n for (let i = 0; i < args.length; i++) {\n result = result.replace(new RegExp(`\\\\$\\\\{arg${i}\\\\}`, 'g'), args[i] ?? '');\n }\n\n if (expr.lowering.strategy === 'function') {\n return result;\n }\n\n return result;\n}\n\nfunction renderJoin(join: JoinAst, _contract?: PostgresContract): string {\n const joinType = join.joinType.toUpperCase();\n const table = quoteIdentifier(join.table.name);\n const onClause = renderJoinOn(join.on);\n return `${joinType} JOIN ${table} ON ${onClause}`;\n}\n\nfunction renderJoinOn(on: JoinAst['on']): string {\n if (on.kind === 'eqCol') {\n const left = renderColumn(on.left);\n const right = renderColumn(on.right);\n return `${left} = ${right}`;\n }\n throw new Error(`Unsupported join ON expression kind: ${on.kind}`);\n}\n\nfunction renderInclude(\n include: NonNullable<SelectAst['includes']>[number],\n contract?: PostgresContract,\n): string {\n const alias = include.alias;\n\n // Build the lateral subquery\n const childProjection = include.child.project\n .map((item: { alias: string; expr: ColumnRef | OperationExpr }) => {\n const expr = renderExpr(item.expr, contract);\n return `'${item.alias}', ${expr}`;\n })\n .join(', ');\n\n const jsonBuildObject = `json_build_object(${childProjection})`;\n\n // Build the ON condition from the include's ON clause - this goes in the WHERE clause\n const onCondition = renderJoinOn(include.child.on);\n\n // Build WHERE clause: combine ON condition with any additional WHERE clauses\n let whereClause = ` WHERE ${onCondition}`;\n if (include.child.where) {\n whereClause += ` AND ${renderWhere(include.child.where, contract)}`;\n }\n\n // Add ORDER BY if present - it goes inside json_agg() call\n const childOrderBy = include.child.orderBy?.length\n ? ` ORDER BY ${include.child.orderBy\n .map(\n (order: { expr: ColumnRef | OperationExpr; dir: string }) =>\n `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`,\n )\n .join(', ')}`\n : '';\n\n // Add LIMIT if present\n const childLimit = typeof include.child.limit === 'number' ? ` LIMIT ${include.child.limit}` : '';\n\n // Build the lateral subquery\n // When ORDER BY is present without LIMIT, it goes inside json_agg() call: json_agg(expr ORDER BY ...)\n // When LIMIT is present (with or without ORDER BY), we need to wrap in a subquery\n const childTable = quoteIdentifier(include.child.table.name);\n let subquery: string;\n if (typeof include.child.limit === 'number') {\n // With LIMIT, we need to wrap in a subquery\n // Select individual columns in inner query, then aggregate\n // Create a map of column references to their aliases for ORDER BY\n // Only ColumnRef can be mapped (OperationExpr doesn't have table/column properties)\n const columnAliasMap = new Map<string, string>();\n for (const item of include.child.project) {\n if (item.expr.kind === 'col') {\n const columnKey = `${item.expr.table}.${item.expr.column}`;\n columnAliasMap.set(columnKey, item.alias);\n }\n }\n\n const innerColumns = include.child.project\n .map((item: { alias: string; expr: ColumnRef | OperationExpr }) => {\n const expr = renderExpr(item.expr, contract);\n return `${expr} AS ${quoteIdentifier(item.alias)}`;\n })\n .join(', ');\n\n // For ORDER BY, use column aliases if the column is in the SELECT list\n const childOrderByWithAliases = include.child.orderBy?.length\n ? ` ORDER BY ${include.child.orderBy\n .map((order: { expr: ColumnRef | OperationExpr; dir: string }) => {\n if (order.expr.kind === 'col') {\n const columnKey = `${order.expr.table}.${order.expr.column}`;\n const alias = columnAliasMap.get(columnKey);\n if (alias) {\n return `${quoteIdentifier(alias)} ${order.dir.toUpperCase()}`;\n }\n }\n return `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`;\n })\n .join(', ')}`\n : '';\n\n const innerSelect = `SELECT ${innerColumns} FROM ${childTable}${whereClause}${childOrderByWithAliases}${childLimit}`;\n subquery = `(SELECT json_agg(row_to_json(sub.*)) AS ${quoteIdentifier(alias)} FROM (${innerSelect}) sub)`;\n } else if (childOrderBy) {\n // With ORDER BY but no LIMIT, ORDER BY goes inside json_agg()\n subquery = `(SELECT json_agg(${jsonBuildObject}${childOrderBy}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;\n } else {\n // No ORDER BY or LIMIT\n subquery = `(SELECT json_agg(${jsonBuildObject}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;\n }\n\n // Return the LATERAL join with ON true (the condition is in the WHERE clause)\n // The subquery returns a single column (the JSON array) with the alias\n // We use a different alias for the table to avoid ambiguity when selecting the column\n const tableAlias = `${alias}_lateral`;\n return `LEFT JOIN LATERAL ${subquery} AS ${quoteIdentifier(tableAlias)} ON true`;\n}\n\nfunction quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction renderInsert(ast: InsertAst, contract: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const columns = Object.keys(ast.values).map((col) => quoteIdentifier(col));\n const tableMeta = contract.storage.tables[ast.table.name];\n const values = Object.entries(ast.values).map(([colName, val]) => {\n if (val.kind === 'param') {\n const columnMeta = tableMeta?.columns[colName];\n const isVector = columnMeta?.type === 'pg/vector@1';\n return isVector ? `$${val.index}::vector` : `$${val.index}`;\n }\n if (val.kind === 'col') {\n return `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;\n }\n throw new Error(`Unsupported value kind in INSERT: ${(val as { kind: string }).kind}`);\n });\n\n const insertClause = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${values.join(', ')})`;\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `${insertClause}${returningClause}`;\n}\n\nfunction renderUpdate(ast: UpdateAst, contract: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const tableMeta = contract.storage.tables[ast.table.name];\n const setClauses = Object.entries(ast.set).map(([col, val]) => {\n const column = quoteIdentifier(col);\n let value: string;\n if (val.kind === 'param') {\n const columnMeta = tableMeta?.columns[col];\n const isVector = columnMeta?.type === 'pg/vector@1';\n value = isVector ? `$${val.index}::vector` : `$${val.index}`;\n } else if (val.kind === 'col') {\n value = `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;\n } else {\n throw new Error(`Unsupported value kind in UPDATE: ${(val as { kind: string }).kind}`);\n }\n return `${column} = ${value}`;\n });\n\n const whereClause = ` WHERE ${renderBinary(ast.where, contract)}`;\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `UPDATE ${table} SET ${setClauses.join(', ')}${whereClause}${returningClause}`;\n}\n\nfunction renderDelete(ast: DeleteAst, contract?: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const whereClause = ` WHERE ${renderBinary(ast.where, contract)}`;\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `DELETE FROM ${table}${whereClause}${returningClause}`;\n}\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;;AAkBA,SAAS,qBAAqB,uBAAuB;AAIrD,IAAM,sBAAsB,OAAO,OAAO;AAAA,EACxC,UAAU;AAAA,IACR,SAAS;AAAA,IACT,OAAO;AAAA,IACP,SAAS;AAAA,IACT,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF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AM,QAAQ,gBAAgB,IAAI,MAAM,IAAI;AAC5C,QAAM,cAAc,UAAU,aAAa,IAAI,OAAO,QAAQ,CAAC;AAC/D,QAAM,kBAAkB,IAAI,WAAW,SACnC,cAAc,IAAI,UAAU,IAAI,CAAC,QAAQ,GAAG,gBAAgB,IAAI,KAAK,CAAC,IAAI,gBAAgB,IAAI,MAAM,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC,KACnH;AAEJ,SAAO,eAAe,KAAK,GAAG,WAAW,GAAG,eAAe;AAC7D;AAEO,SAAS,sBAAsB,SAAkC;AACtE,SAAO,OAAO,OAAO,IAAI,oBAAoB,OAAO,CAAC;AACvD;","names":["alias"]}
@@ -0,0 +1,38 @@
1
+ import * as _prisma_next_sql_relational_core_ast from '@prisma-next/sql-relational-core/ast';
2
+
3
+ /**
4
+ * Unified codec definitions for Postgres adapter.
5
+ *
6
+ * This file contains a single source of truth for all codec information:
7
+ * - Scalar names
8
+ * - Type IDs
9
+ * - Codec implementations (runtime)
10
+ * - Type information (compile-time)
11
+ *
12
+ * This structure is used both at runtime (to populate the registry) and
13
+ * at compile time (to derive CodecTypes).
14
+ */
15
+ declare const codecs: _prisma_next_sql_relational_core_ast.CodecDefBuilder<{
16
+ text: _prisma_next_sql_relational_core_ast.Codec<"pg/text@1", string, string>;
17
+ int4: _prisma_next_sql_relational_core_ast.Codec<"pg/int4@1", number, number>;
18
+ int2: _prisma_next_sql_relational_core_ast.Codec<"pg/int2@1", number, number>;
19
+ int8: _prisma_next_sql_relational_core_ast.Codec<"pg/int8@1", number, number>;
20
+ float4: _prisma_next_sql_relational_core_ast.Codec<"pg/float4@1", number, number>;
21
+ float8: _prisma_next_sql_relational_core_ast.Codec<"pg/float8@1", number, number>;
22
+ timestamp: _prisma_next_sql_relational_core_ast.Codec<"pg/timestamp@1", string | Date, string>;
23
+ timestamptz: _prisma_next_sql_relational_core_ast.Codec<"pg/timestamptz@1", string | Date, string>;
24
+ } & Record<"bool", _prisma_next_sql_relational_core_ast.Codec<"pg/bool@1", boolean, boolean>>>;
25
+ declare const dataTypes: {
26
+ readonly text: "pg/text@1";
27
+ readonly int4: "pg/int4@1";
28
+ readonly int2: "pg/int2@1";
29
+ readonly int8: "pg/int8@1";
30
+ readonly float4: "pg/float4@1";
31
+ readonly float8: "pg/float8@1";
32
+ readonly timestamp: "pg/timestamp@1";
33
+ readonly timestamptz: "pg/timestamptz@1";
34
+ readonly bool: "pg/bool@1";
35
+ };
36
+ type CodecTypes = typeof codecs.CodecTypes;
37
+
38
+ export { type CodecTypes, dataTypes };
@@ -0,0 +1,7 @@
1
+ import {
2
+ dataTypes
3
+ } from "./chunk-CPAKRHXM.js";
4
+ export {
5
+ dataTypes
6
+ };
7
+ //# sourceMappingURL=codec-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,96 @@
1
+ import { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
2
+
3
+ /**
4
+ * Specifies how to import TypeScript types from a package.
5
+ * Used in extension pack manifests to declare codec and operation type imports.
6
+ */
7
+ interface TypesImportSpec {
8
+ readonly package: string;
9
+ readonly named: string;
10
+ readonly alias: string;
11
+ }
12
+ type ArgSpecManifest = {
13
+ readonly kind: 'typeId';
14
+ readonly type: string;
15
+ } | {
16
+ readonly kind: 'param';
17
+ } | {
18
+ readonly kind: 'literal';
19
+ };
20
+ type ReturnSpecManifest = {
21
+ readonly kind: 'typeId';
22
+ readonly type: string;
23
+ } | {
24
+ readonly kind: 'builtin';
25
+ readonly type: 'number' | 'boolean' | 'string';
26
+ };
27
+ interface LoweringSpecManifest {
28
+ readonly targetFamily: 'sql';
29
+ readonly strategy: 'infix' | 'function';
30
+ readonly template: string;
31
+ }
32
+ interface OperationManifest {
33
+ readonly for: string;
34
+ readonly method: string;
35
+ readonly args: ReadonlyArray<ArgSpecManifest>;
36
+ readonly returns: ReturnSpecManifest;
37
+ readonly lowering: LoweringSpecManifest;
38
+ readonly capabilities?: ReadonlyArray<string>;
39
+ }
40
+ interface ExtensionPackManifest {
41
+ readonly id: string;
42
+ readonly version: string;
43
+ readonly targets?: Record<string, {
44
+ readonly minVersion?: string;
45
+ }>;
46
+ readonly capabilities?: Record<string, unknown>;
47
+ readonly types?: {
48
+ readonly codecTypes?: {
49
+ readonly import: TypesImportSpec;
50
+ };
51
+ readonly operationTypes?: {
52
+ readonly import: TypesImportSpec;
53
+ };
54
+ readonly storage?: readonly {
55
+ readonly typeId: string;
56
+ readonly familyId: string;
57
+ readonly targetId: string;
58
+ readonly nativeType?: string;
59
+ }[];
60
+ };
61
+ readonly operations?: ReadonlyArray<OperationManifest>;
62
+ }
63
+
64
+ /**
65
+ * Base interface for control-plane adapter instances.
66
+ * Families extend this with family-specific adapter interfaces.
67
+ *
68
+ * @template TFamilyId - The family ID (e.g., 'sql', 'document')
69
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
70
+ */
71
+ interface ControlAdapterInstance<TFamilyId extends string = string, TTargetId extends string = string> {
72
+ readonly familyId: TFamilyId;
73
+ readonly targetId: TTargetId;
74
+ }
75
+ /**
76
+ * Descriptor for a control-plane adapter pack (e.g., Postgres adapter).
77
+ *
78
+ * @template TFamilyId - The family ID (e.g., 'sql', 'document')
79
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
80
+ * @template TAdapterInstance - The adapter instance type
81
+ */
82
+ interface ControlAdapterDescriptor<TFamilyId extends string, TTargetId extends string, TAdapterInstance extends ControlAdapterInstance<TFamilyId, TTargetId> = ControlAdapterInstance<TFamilyId, TTargetId>> {
83
+ readonly kind: 'adapter';
84
+ readonly id: string;
85
+ readonly familyId: TFamilyId;
86
+ readonly targetId: TTargetId;
87
+ readonly manifest: ExtensionPackManifest;
88
+ create(): TAdapterInstance;
89
+ }
90
+
91
+ /**
92
+ * Postgres adapter descriptor for CLI config.
93
+ */
94
+ declare const postgresAdapterDescriptor: ControlAdapterDescriptor<'sql', 'postgres', SqlControlAdapter<'postgres'>>;
95
+
96
+ export { postgresAdapterDescriptor as default };