@prisma-next/adapter-postgres 0.5.0-dev.7 → 0.5.0-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -16
- package/dist/adapter-MsS4g_NL.mjs +47 -0
- package/dist/adapter-MsS4g_NL.mjs.map +1 -0
- package/dist/adapter.d.mts +3 -4
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +2 -3
- package/dist/column-types.d.mts +19 -24
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +20 -60
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +83 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +74 -14
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-RTDzyrae.mjs → descriptor-meta-C2VasIft.mjs} +36 -27
- package/dist/descriptor-meta-C2VasIft.mjs.map +1 -0
- package/dist/operation-types.d.mts +11 -10
- package/dist/operation-types.d.mts.map +1 -1
- package/dist/operation-types.mjs +1 -1
- package/dist/runtime.d.mts +3 -11
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +19 -81
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sql-renderer-pEaSP82_.mjs → sql-renderer-_cLtu1Av.mjs} +95 -48
- package/dist/sql-renderer-_cLtu1Av.mjs.map +1 -0
- package/dist/{types-CfRPdAk8.d.mts → types-B1eiuBHQ.d.mts} +12 -1
- package/dist/types-B1eiuBHQ.d.mts.map +1 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +24 -23
- package/src/core/adapter.ts +17 -42
- package/src/core/codec-lookup.ts +19 -0
- package/src/core/control-adapter.ts +119 -1
- package/src/core/control-mutation-defaults.ts +24 -18
- package/src/core/descriptor-meta.ts +39 -19
- package/src/core/sql-renderer.ts +111 -66
- package/src/core/types.ts +11 -0
- package/src/exports/column-types.ts +21 -61
- package/src/exports/control.ts +3 -2
- package/src/exports/runtime.ts +27 -66
- package/src/types/operation-types.ts +19 -9
- package/dist/adapter-hNElNHo4.mjs +0 -60
- package/dist/adapter-hNElNHo4.mjs.map +0 -1
- package/dist/descriptor-meta-RTDzyrae.mjs.map +0 -1
- package/dist/sql-renderer-pEaSP82_.mjs.map +0 -1
- package/dist/types-CfRPdAk8.d.mts.map +0 -1
- package/src/core/json-schema-validator.ts +0 -54
- package/src/core/standard-schema.ts +0 -71
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { CodecExpression, Expression, TraitExpression } from "@prisma-next/sql-relational-core/expression";
|
|
1
2
|
import { SqlQueryOperationTypes } from "@prisma-next/sql-contract/types";
|
|
2
3
|
|
|
3
4
|
//#region src/types/operation-types.d.ts
|
|
4
|
-
type
|
|
5
|
+
type CodecTypesBase = Record<string, {
|
|
6
|
+
readonly input: unknown;
|
|
7
|
+
readonly output: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
type QueryOperationTypes<CT extends CodecTypesBase> = SqlQueryOperationTypes<CT, {
|
|
5
10
|
readonly ilike: {
|
|
6
|
-
readonly
|
|
11
|
+
readonly self: {
|
|
7
12
|
readonly traits: readonly ['textual'];
|
|
8
|
-
readonly nullable: false;
|
|
9
|
-
}, {
|
|
10
|
-
readonly codecId: 'pg/text@1';
|
|
11
|
-
readonly nullable: false;
|
|
12
|
-
}];
|
|
13
|
-
readonly returns: {
|
|
14
|
-
readonly codecId: 'pg/bool@1';
|
|
15
|
-
readonly nullable: false;
|
|
16
13
|
};
|
|
14
|
+
readonly impl: (self: TraitExpression<readonly ['textual'], false, CT>, pattern: CodecExpression<'pg/text@1', false, CT>) => Expression<{
|
|
15
|
+
codecId: 'pg/bool@1';
|
|
16
|
+
nullable: false;
|
|
17
|
+
}>;
|
|
17
18
|
};
|
|
18
19
|
}>;
|
|
19
20
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"
|
|
1
|
+
{"version":3,"file":"operation-types.d.mts","names":[],"sources":["../src/types/operation-types.ts"],"mappings":";;;;KAOK,cAAA,GAAiB,MAAA;EAAA,SAA0B,KAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAE7D,mBAAA,YAA+B,cAAA,IAAkB,sBAAA,CAC3D,EAAA;EAAA,SAEW,KAAA;IAAA,SACE,IAAA;MAAA,SAAiB,MAAA;IAAA;IAAA,SACjB,IAAA,GACP,IAAA,EAAM,eAAA,8BAA6C,EAAA,GACnD,OAAA,EAAS,eAAA,qBAAoC,EAAA,MAC1C,UAAA;MAAa,OAAA;MAAsB,QAAA;IAAA;EAAA;AAAA"}
|
package/dist/operation-types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-
|
|
1
|
+
import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-B1eiuBHQ.mjs";
|
|
2
|
+
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
2
3
|
import { Adapter, AnyQueryAst } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
|
|
4
|
-
import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
|
|
5
|
-
import { JsonSchemaValidateFn } from "@prisma-next/sql-relational-core/query-lane-context";
|
|
6
5
|
|
|
7
6
|
//#region src/exports/runtime.d.ts
|
|
8
7
|
interface SqlRuntimeAdapter extends RuntimeAdapterInstance<'sql', 'postgres'>, Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}
|
|
9
|
-
/**
|
|
10
|
-
* Helper returned by the JSON/JSONB `init` hook.
|
|
11
|
-
* Contains a compiled JSON Schema validate function for runtime conformance checks.
|
|
12
|
-
*/
|
|
13
|
-
type JsonCodecHelper = {
|
|
14
|
-
readonly validate: JsonSchemaValidateFn;
|
|
15
|
-
};
|
|
16
8
|
declare const postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter>;
|
|
17
9
|
//#endregion
|
|
18
|
-
export {
|
|
10
|
+
export { SqlRuntimeAdapter, postgresRuntimeAdapterDescriptor as default };
|
|
19
11
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"mappings":";;;;;;UAaiB,iBAAA,SACP,sBAAA,qBACN,OAAA,CAAQ,WAAA,EAAa,gBAAA,EAAkB,wBAAA;AAAA,cAgBrC,gCAAA,EAAkC,2BAAA,aAAwC,iBAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,99 +1,37 @@
|
|
|
1
|
-
import { t as createPostgresAdapter } from "./adapter-
|
|
2
|
-
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
|
|
1
|
+
import { t as createPostgresAdapter } from "./adapter-MsS4g_NL.mjs";
|
|
2
|
+
import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-C2VasIft.mjs";
|
|
3
|
+
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
4
|
+
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
6
5
|
import { builtinGeneratorIds } from "@prisma-next/ids";
|
|
6
|
+
import { timestampNowRuntimeGenerator } from "@prisma-next/family-sql/runtime";
|
|
7
7
|
import { generateId } from "@prisma-next/ids/runtime";
|
|
8
|
-
import { type } from "arktype";
|
|
9
|
-
import Ajv from "ajv";
|
|
10
|
-
|
|
11
|
-
//#region src/core/json-schema-validator.ts
|
|
12
|
-
/**
|
|
13
|
-
* Shared Ajv instance for all JSON Schema validators.
|
|
14
|
-
* Reusing a single instance avoids ~50-100KB memory overhead per compiled schema.
|
|
15
|
-
*/
|
|
16
|
-
let sharedAjv;
|
|
17
|
-
function getSharedAjv() {
|
|
18
|
-
if (!sharedAjv) sharedAjv = new Ajv({
|
|
19
|
-
allErrors: false,
|
|
20
|
-
strict: false
|
|
21
|
-
});
|
|
22
|
-
return sharedAjv;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Compiles a JSON Schema object into a reusable validate function using Ajv.
|
|
26
|
-
*
|
|
27
|
-
* The returned function validates a value against the schema and returns
|
|
28
|
-
* a structured result with error details on failure.
|
|
29
|
-
*
|
|
30
|
-
* Uses a shared Ajv instance and fail-fast mode (`allErrors: false`)
|
|
31
|
-
* to minimize memory and CPU overhead.
|
|
32
|
-
*
|
|
33
|
-
* @param schema - A JSON Schema object (draft-07 compatible)
|
|
34
|
-
* @returns A validate function
|
|
35
|
-
*/
|
|
36
|
-
function compileJsonSchemaValidator(schema) {
|
|
37
|
-
const validate = getSharedAjv().compile(schema);
|
|
38
|
-
return (value) => {
|
|
39
|
-
if (validate(value)) return { valid: true };
|
|
40
|
-
return {
|
|
41
|
-
valid: false,
|
|
42
|
-
errors: validate.errors.map((err) => ({
|
|
43
|
-
path: err.instancePath || "/",
|
|
44
|
-
message: err.message ?? "unknown validation error",
|
|
45
|
-
keyword: err.keyword
|
|
46
|
-
}))
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
8
|
//#region src/exports/runtime.ts
|
|
53
|
-
function createPostgresCodecRegistry() {
|
|
54
|
-
const registry = createCodecRegistry();
|
|
55
|
-
for (const definition of Object.values(codecDefinitions)) registry.register(definition.codec);
|
|
56
|
-
return registry;
|
|
57
|
-
}
|
|
58
|
-
const jsonTypeParamsSchema = type({
|
|
59
|
-
schemaJson: "object",
|
|
60
|
-
"type?": "string"
|
|
61
|
-
});
|
|
62
9
|
function createPostgresMutationDefaultGenerators() {
|
|
63
|
-
return builtinGeneratorIds.map((id) => ({
|
|
10
|
+
return [...builtinGeneratorIds.map((id) => ({
|
|
64
11
|
id,
|
|
65
12
|
generate: (params) => {
|
|
66
13
|
return generateId(params ? {
|
|
67
14
|
id,
|
|
68
15
|
params
|
|
69
16
|
} : { id });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
function initJsonCodecHelper(params) {
|
|
74
|
-
return { validate: compileJsonSchemaValidator(params.schemaJson) };
|
|
17
|
+
},
|
|
18
|
+
stability: "field"
|
|
19
|
+
})), timestampNowRuntimeGenerator()];
|
|
75
20
|
}
|
|
76
|
-
const parameterizedCodecDescriptors = [{
|
|
77
|
-
codecId: PG_JSON_CODEC_ID,
|
|
78
|
-
paramsSchema: jsonTypeParamsSchema,
|
|
79
|
-
init: initJsonCodecHelper
|
|
80
|
-
}, {
|
|
81
|
-
codecId: PG_JSONB_CODEC_ID,
|
|
82
|
-
paramsSchema: jsonTypeParamsSchema,
|
|
83
|
-
init: initJsonCodecHelper
|
|
84
|
-
}];
|
|
85
21
|
const postgresRuntimeAdapterDescriptor = {
|
|
86
22
|
...postgresAdapterDescriptorMeta,
|
|
87
|
-
codecs:
|
|
88
|
-
|
|
89
|
-
queryOperations: () => postgresQueryOperations,
|
|
23
|
+
codecs: () => Array.from(postgresCodecRegistry.values()),
|
|
24
|
+
queryOperations: () => postgresQueryOperations(),
|
|
90
25
|
mutationDefaultGenerators: createPostgresMutationDefaultGenerators,
|
|
91
|
-
create(
|
|
92
|
-
return createPostgresAdapter(
|
|
26
|
+
create(stack) {
|
|
27
|
+
return createPostgresAdapter({ codecLookup: extractCodecLookup([
|
|
28
|
+
stack.target,
|
|
29
|
+
stack.adapter,
|
|
30
|
+
...stack.extensionPacks
|
|
31
|
+
]) });
|
|
93
32
|
}
|
|
94
33
|
};
|
|
95
|
-
var runtime_default = postgresRuntimeAdapterDescriptor;
|
|
96
|
-
|
|
97
34
|
//#endregion
|
|
98
|
-
export {
|
|
35
|
+
export { postgresRuntimeAdapterDescriptor as default };
|
|
36
|
+
|
|
99
37
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport { timestampNowRuntimeGenerator } from '@prisma-next/family-sql/runtime';\nimport { extractCodecLookup } from '@prisma-next/framework-components/control';\nimport type { RuntimeAdapterInstance } from '@prisma-next/framework-components/execution';\nimport { builtinGeneratorIds } from '@prisma-next/ids';\nimport { generateId } from '@prisma-next/ids/runtime';\nimport type { Adapter, AnyQueryAst } from '@prisma-next/sql-relational-core/ast';\nimport type { SqlRuntimeAdapterDescriptor } from '@prisma-next/sql-runtime';\nimport { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';\nimport { createPostgresAdapter } from '../core/adapter';\nimport { postgresAdapterDescriptorMeta, postgresQueryOperations } from '../core/descriptor-meta';\nimport type { PostgresContract, PostgresLoweredStatement } from '../core/types';\n\nexport interface SqlRuntimeAdapter\n extends RuntimeAdapterInstance<'sql', 'postgres'>,\n Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}\n\nfunction createPostgresMutationDefaultGenerators() {\n return [\n ...builtinGeneratorIds.map((id) => ({\n id,\n generate: (params?: Record<string, unknown>) => {\n const spec: GeneratedValueSpec = params ? { id, params } : { id };\n return generateId(spec);\n },\n stability: 'field' as const,\n })),\n timestampNowRuntimeGenerator(),\n ];\n}\n\nconst postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter> =\n {\n ...postgresAdapterDescriptorMeta,\n codecs: () => Array.from(postgresCodecRegistry.values()),\n queryOperations: () => postgresQueryOperations(),\n mutationDefaultGenerators: createPostgresMutationDefaultGenerators,\n create(stack): SqlRuntimeAdapter {\n // The runtime `ExecutionStack` does not (yet) carry a pre-assembled `codecLookup` field the way the control `ControlStack` does, so we derive an equivalent lookup here from the stack's component metadata (target + adapter + extension packs) using the same assembly helper that `createControlStack` uses. This keeps the renderer fed with the same codec set on both planes — including extension-contributed codecs like\n // `pg/vector@1` from `@prisma-next/extension-pgvector`.\n const codecLookup = extractCodecLookup([\n stack.target,\n stack.adapter,\n ...stack.extensionPacks,\n ]);\n return createPostgresAdapter({ codecLookup });\n },\n };\n\nexport default postgresRuntimeAdapterDescriptor;\n"],"mappings":";;;;;;;;AAiBA,SAAS,0CAA0C;CACjD,OAAO,CACL,GAAG,oBAAoB,KAAK,QAAQ;EAClC;EACA,WAAW,WAAqC;GAE9C,OAAO,WAD0B,SAAS;IAAE;IAAI;IAAQ,GAAG,EAAE,IAAI,CAC1C;;EAEzB,WAAW;EACZ,EAAE,EACH,8BAA8B,CAC/B;;AAGH,MAAM,mCACJ;CACE,GAAG;CACH,cAAc,MAAM,KAAK,sBAAsB,QAAQ,CAAC;CACxD,uBAAuB,yBAAyB;CAChD,2BAA2B;CAC3B,OAAO,OAA0B;EAQ/B,OAAO,sBAAsB,EAAE,aALX,mBAAmB;GACrC,MAAM;GACN,MAAM;GACN,GAAG,MAAM;GACV,CACyC,EAAE,CAAC;;CAEhD"}
|
|
@@ -1,57 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { extractCodecLookup } from "@prisma-next/framework-components/control";
|
|
2
|
+
import { postgresCodecRegistry } from "@prisma-next/target-postgres/codecs";
|
|
3
|
+
import { LiteralExpr, collectOrderedParamRefs } from "@prisma-next/sql-relational-core/ast";
|
|
3
4
|
import { escapeLiteral, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
4
|
-
|
|
5
|
+
//#region src/core/codec-lookup.ts
|
|
6
|
+
/**
|
|
7
|
+
* Build a {@link CodecLookup} populated with the Postgres-builtin codec definitions only.
|
|
8
|
+
*
|
|
9
|
+
* This is the default lookup used by `createPostgresAdapter()` and `new PostgresControlAdapter()` when called without a stack-derived lookup (e.g. from tests, or one-off scripts that don't compose a full stack).
|
|
10
|
+
*
|
|
11
|
+
* Extension codecs (e.g. `pg/vector@1` from `@prisma-next/extension-pgvector`) are intentionally NOT included here: a bare adapter cannot see extensions. Stack-composed paths (`SqlControlAdapterDescriptor.create(stack)` / `SqlRuntimeAdapterDescriptor.create(stack)`) supply the broader, extension-inclusive lookup at construction time.
|
|
12
|
+
*/
|
|
13
|
+
function createPostgresBuiltinCodecLookup() {
|
|
14
|
+
return extractCodecLookup([{
|
|
15
|
+
id: "postgres-builtin-codecs",
|
|
16
|
+
types: { codecTypes: { codecDescriptors: Array.from(postgresCodecRegistry.values()) } }
|
|
17
|
+
}]);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
5
20
|
//#region src/core/sql-renderer.ts
|
|
6
|
-
const VECTOR_CODEC_ID = "pg/vector@1";
|
|
7
21
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
22
|
+
* Postgres native types whose unknown-OID parameter inference is reliable in arbitrary expression positions. Parameters bound to a codec whose `meta.db.sql.postgres.nativeType` falls in this set are emitted as plain `$N`; everything else (including `json`, `jsonb`, extension types like `vector`, and unknown user types) is emitted as `$N::<nativeType>` so the planner picks an unambiguous overload.
|
|
23
|
+
*
|
|
24
|
+
* `json` / `jsonb` are intentionally excluded despite being Postgres builtins: their operator overloads make context inference unreliable in expression positions (e.g. `$1 -> 'key'` is ambiguous between the two).
|
|
10
25
|
*
|
|
11
|
-
*
|
|
12
|
-
* TML-2310 ("Move SQL param-cast metadata onto codec descriptors").
|
|
13
|
-
* Until that lands the cast lives on the renderer rather than the codec.
|
|
26
|
+
* Spellings match the on-disk `meta.db.sql.postgres.nativeType` values in `@prisma-next/target-postgres`'s codec definitions, not the `udt_name` abbreviations that ADR 205 used as illustrative shorthand. The lookup-based cast policy compares against these strings directly.
|
|
14
27
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
const POSTGRES_INFERRABLE_NATIVE_TYPES = new Set([
|
|
29
|
+
"integer",
|
|
30
|
+
"smallint",
|
|
31
|
+
"bigint",
|
|
32
|
+
"real",
|
|
33
|
+
"double precision",
|
|
34
|
+
"numeric",
|
|
35
|
+
"boolean",
|
|
36
|
+
"text",
|
|
37
|
+
"character",
|
|
38
|
+
"character varying",
|
|
39
|
+
"timestamp",
|
|
40
|
+
"timestamp without time zone",
|
|
41
|
+
"timestamp with time zone",
|
|
42
|
+
"time",
|
|
43
|
+
"timetz",
|
|
44
|
+
"interval",
|
|
45
|
+
"bit",
|
|
46
|
+
"bit varying"
|
|
47
|
+
]);
|
|
48
|
+
function renderTypedParam(index, codecId, codecLookup) {
|
|
49
|
+
if (codecId === void 0) return `$${index}`;
|
|
50
|
+
if (codecLookup.get(codecId) === void 0) throw new Error(`Postgres lowering: ParamRef carries codecId "${codecId}" but the assembled codec lookup has no entry for it. This usually indicates a missing extension pack in the runtime stack — register the pack that contributes this codec (e.g. \`extensionPacks: [pgvectorRuntime]\`), or use the codec directly from \`@prisma-next/target-postgres/codecs\` if it's a builtin.`);
|
|
51
|
+
const dbRecord = codecLookup.metaFor(codecId)?.db;
|
|
52
|
+
const sqlBlock = isRecord(dbRecord) ? dbRecord["sql"] : void 0;
|
|
53
|
+
const dialectBlock = isRecord(sqlBlock) ? sqlBlock["postgres"] : void 0;
|
|
54
|
+
const nativeType = isRecord(dialectBlock) ? dialectBlock["nativeType"] : void 0;
|
|
55
|
+
if (typeof nativeType === "string" && !POSTGRES_INFERRABLE_NATIVE_TYPES.has(nativeType)) return `$${index}::${nativeType}`;
|
|
56
|
+
return `$${index}`;
|
|
19
57
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
return cast ? `$${index}::${cast}` : `$${index}`;
|
|
58
|
+
function isRecord(value) {
|
|
59
|
+
return typeof value === "object" && value !== null;
|
|
23
60
|
}
|
|
24
61
|
/**
|
|
25
62
|
* Render a SQL query AST to a Postgres-flavored `{ sql, params }` payload.
|
|
26
63
|
*
|
|
27
|
-
* Shared between the runtime (`PostgresAdapterImpl.lower`) and control
|
|
28
|
-
* (`PostgresControlAdapter.lower`) entrypoints so emit-time and run-time
|
|
29
|
-
* paths produce byte-identical output for the same AST.
|
|
64
|
+
* Shared between the runtime (`PostgresAdapterImpl.lower`) and control (`PostgresControlAdapter.lower`) entrypoints so emit-time and run-time paths produce byte-identical output for the same AST.
|
|
30
65
|
*/
|
|
31
|
-
function renderLoweredSql(ast, contract) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const params =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
66
|
+
function renderLoweredSql(ast, contract, codecLookup) {
|
|
67
|
+
const orderedRefs = collectOrderedParamRefs(ast);
|
|
68
|
+
const indexMap = /* @__PURE__ */ new Map();
|
|
69
|
+
const params = orderedRefs.map((ref, i) => {
|
|
70
|
+
indexMap.set(ref, i + 1);
|
|
71
|
+
return ref.value;
|
|
72
|
+
});
|
|
73
|
+
const pim = {
|
|
74
|
+
indexMap,
|
|
75
|
+
codecLookup
|
|
76
|
+
};
|
|
40
77
|
const node = ast;
|
|
41
78
|
let sql;
|
|
42
79
|
switch (node.kind) {
|
|
43
80
|
case "select":
|
|
44
|
-
sql = renderSelect(node, contract,
|
|
81
|
+
sql = renderSelect(node, contract, pim);
|
|
45
82
|
break;
|
|
46
83
|
case "insert":
|
|
47
|
-
sql = renderInsert(node, contract,
|
|
84
|
+
sql = renderInsert(node, contract, pim);
|
|
48
85
|
break;
|
|
49
86
|
case "update":
|
|
50
|
-
sql = renderUpdate(node, contract,
|
|
87
|
+
sql = renderUpdate(node, contract, pim);
|
|
51
88
|
break;
|
|
52
89
|
case "delete":
|
|
53
|
-
sql = renderDelete(node, contract,
|
|
90
|
+
sql = renderDelete(node, contract, pim);
|
|
54
91
|
break;
|
|
92
|
+
// v8 ignore next 4
|
|
55
93
|
default: throw new Error(`Unsupported AST node kind: ${node.kind}`);
|
|
56
94
|
}
|
|
57
95
|
return Object.freeze({
|
|
@@ -81,6 +119,16 @@ function renderProjection(projection, contract, pim) {
|
|
|
81
119
|
return `${renderExpr(item.expr, contract, pim)} AS ${alias}`;
|
|
82
120
|
}).join(", ");
|
|
83
121
|
}
|
|
122
|
+
function renderReturning(items, contract, pim) {
|
|
123
|
+
return items.map((item) => {
|
|
124
|
+
if (item.expr.kind === "column-ref") {
|
|
125
|
+
const rendered = renderColumn(item.expr);
|
|
126
|
+
return item.expr.column === item.alias ? rendered : `${rendered} AS ${quoteIdentifier(item.alias)}`;
|
|
127
|
+
}
|
|
128
|
+
if (item.expr.kind === "literal") return `${renderLiteral(item.expr)} AS ${quoteIdentifier(item.alias)}`;
|
|
129
|
+
return `${renderExpr(item.expr, contract, pim)} AS ${quoteIdentifier(item.alias)}`;
|
|
130
|
+
}).join(", ");
|
|
131
|
+
}
|
|
84
132
|
function renderDistinctPrefix(distinct, distinctOn, contract, pim) {
|
|
85
133
|
if (distinctOn && distinctOn.length > 0) return `DISTINCT ON (${distinctOn.map((expr) => renderExpr(expr, contract, pim)).join(", ")}) `;
|
|
86
134
|
if (distinct) return "DISTINCT ";
|
|
@@ -95,6 +143,7 @@ function renderSource(source, contract, pim) {
|
|
|
95
143
|
return `${table} AS ${quoteIdentifier(node.alias)}`;
|
|
96
144
|
}
|
|
97
145
|
case "derived-table-source": return `(${renderSelect(node.query, contract, pim)}) AS ${quoteIdentifier(node.alias)}`;
|
|
146
|
+
// v8 ignore next 4
|
|
98
147
|
default: throw new Error(`Unsupported source node kind: ${node.kind}`);
|
|
99
148
|
}
|
|
100
149
|
}
|
|
@@ -114,15 +163,9 @@ function renderNullCheck(expr, contract, pim) {
|
|
|
114
163
|
return expr.isNull ? `${renderedExpr} IS NULL` : `${renderedExpr} IS NOT NULL`;
|
|
115
164
|
}
|
|
116
165
|
/**
|
|
117
|
-
* Atomic expression kinds whose rendered SQL is already self-delimited
|
|
118
|
-
* (a column reference, parameter, literal, function call, aggregate, etc.)
|
|
119
|
-
* and therefore does not need surrounding parentheses when used as the
|
|
120
|
-
* left operand of a postfix predicate like `IS NULL` or `IS NOT NULL`,
|
|
121
|
-
* or as either operand of a binary infix operator.
|
|
166
|
+
* Atomic expression kinds whose rendered SQL is already self-delimited (a column reference, parameter, literal, function call, aggregate, etc.) and therefore does not need surrounding parentheses when used as the left operand of a postfix predicate like `IS NULL` or `IS NOT NULL`, or as either operand of a binary infix operator.
|
|
122
167
|
*
|
|
123
|
-
* Anything not in this set is treated as composite (binary, AND/OR/NOT,
|
|
124
|
-
* EXISTS, nested IS NULL, subqueries, operation templates) and gets
|
|
125
|
-
* wrapped to preserve grouping.
|
|
168
|
+
* Anything not in this set is treated as composite (binary, AND/OR/NOT, EXISTS, nested IS NULL, subqueries, operation templates) and gets wrapped to preserve grouping.
|
|
126
169
|
*/
|
|
127
170
|
function isAtomicExpressionKind(kind) {
|
|
128
171
|
switch (kind) {
|
|
@@ -239,13 +282,14 @@ function renderExpr(expr, contract, pim) {
|
|
|
239
282
|
case "param-ref": return renderParamRef(node, pim);
|
|
240
283
|
case "literal": return renderLiteral(node);
|
|
241
284
|
case "list": return renderListLiteral(node, contract, pim);
|
|
285
|
+
// v8 ignore next 4
|
|
242
286
|
default: throw new Error(`Unsupported expression node kind: ${node.kind}`);
|
|
243
287
|
}
|
|
244
288
|
}
|
|
245
289
|
function renderParamRef(ref, pim) {
|
|
246
|
-
const index = pim.get(ref);
|
|
290
|
+
const index = pim.indexMap.get(ref);
|
|
247
291
|
if (index === void 0) throw new Error("ParamRef not found in index map");
|
|
248
|
-
return renderTypedParam(index, ref.codecId);
|
|
292
|
+
return renderTypedParam(index, ref.codecId, pim.codecLookup);
|
|
249
293
|
}
|
|
250
294
|
function renderLiteral(expr) {
|
|
251
295
|
if (typeof expr.value === "string") return `'${escapeLiteral(expr.value)}'`;
|
|
@@ -296,6 +340,7 @@ function renderInsertValue(value, pim) {
|
|
|
296
340
|
switch (value.kind) {
|
|
297
341
|
case "param-ref": return renderParamRef(value, pim);
|
|
298
342
|
case "column-ref": return renderColumn(value);
|
|
343
|
+
// v8 ignore next 4
|
|
299
344
|
default: throw new Error(`Unsupported value node in INSERT: ${value.kind}`);
|
|
300
345
|
}
|
|
301
346
|
}
|
|
@@ -335,9 +380,10 @@ function renderInsert(ast, contract, pim) {
|
|
|
335
380
|
});
|
|
336
381
|
return ` ON CONFLICT (${conflictColumns.join(", ")}) DO UPDATE SET ${updates.join(", ")}`;
|
|
337
382
|
}
|
|
383
|
+
// v8 ignore next 4
|
|
338
384
|
default: throw new Error(`Unsupported onConflict action: ${action.kind}`);
|
|
339
385
|
}
|
|
340
|
-
})() : ""}${ast.returning?.length ? ` RETURNING ${ast.returning
|
|
386
|
+
})() : ""}${ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : ""}`;
|
|
341
387
|
}
|
|
342
388
|
function renderUpdate(ast, contract, pim) {
|
|
343
389
|
const table = quoteIdentifier(ast.table.name);
|
|
@@ -353,18 +399,19 @@ function renderUpdate(ast, contract, pim) {
|
|
|
353
399
|
case "column-ref":
|
|
354
400
|
value = renderColumn(val);
|
|
355
401
|
break;
|
|
402
|
+
// v8 ignore next 4
|
|
356
403
|
default: throw new Error(`Unsupported value node in UPDATE: ${val.kind}`);
|
|
357
404
|
}
|
|
358
405
|
return `${column} = ${value}`;
|
|
359
406
|
});
|
|
360
407
|
const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : "";
|
|
361
|
-
const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning
|
|
408
|
+
const returningClause = ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : "";
|
|
362
409
|
return `UPDATE ${table} SET ${setClauses.join(", ")}${whereClause}${returningClause}`;
|
|
363
410
|
}
|
|
364
411
|
function renderDelete(ast, contract, pim) {
|
|
365
|
-
return `DELETE FROM ${quoteIdentifier(ast.table.name)}${ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : ""}${ast.returning?.length ? ` RETURNING ${ast.returning
|
|
412
|
+
return `DELETE FROM ${quoteIdentifier(ast.table.name)}${ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : ""}${ast.returning?.length ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}` : ""}`;
|
|
366
413
|
}
|
|
367
|
-
|
|
368
414
|
//#endregion
|
|
369
|
-
export { renderLoweredSql as t };
|
|
370
|
-
|
|
415
|
+
export { createPostgresBuiltinCodecLookup as n, renderLoweredSql as t };
|
|
416
|
+
|
|
417
|
+
//# sourceMappingURL=sql-renderer-_cLtu1Av.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-renderer-_cLtu1Av.mjs","names":[],"sources":["../src/core/codec-lookup.ts","../src/core/sql-renderer.ts"],"sourcesContent":["import type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport { extractCodecLookup } from '@prisma-next/framework-components/control';\nimport { postgresCodecRegistry } from '@prisma-next/target-postgres/codecs';\n\n/**\n * Build a {@link CodecLookup} populated with the Postgres-builtin codec definitions only.\n *\n * This is the default lookup used by `createPostgresAdapter()` and `new PostgresControlAdapter()` when called without a stack-derived lookup (e.g. from tests, or one-off scripts that don't compose a full stack).\n *\n * Extension codecs (e.g. `pg/vector@1` from `@prisma-next/extension-pgvector`) are intentionally NOT included here: a bare adapter cannot see extensions. Stack-composed paths (`SqlControlAdapterDescriptor.create(stack)` / `SqlRuntimeAdapterDescriptor.create(stack)`) supply the broader, extension-inclusive lookup at construction time.\n */\nexport function createPostgresBuiltinCodecLookup(): CodecLookup {\n return extractCodecLookup([\n {\n id: 'postgres-builtin-codecs',\n types: { codecTypes: { codecDescriptors: Array.from(postgresCodecRegistry.values()) } },\n },\n ]);\n}\n","import type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport {\n type AggregateExpr,\n type AnyExpression,\n type AnyFromSource,\n type AnyQueryAst,\n type BinaryExpr,\n type ColumnRef,\n collectOrderedParamRefs,\n type DeleteAst,\n type InsertAst,\n type InsertValue,\n type JoinAst,\n type JoinOnExpr,\n type JsonArrayAggExpr,\n type JsonObjectExpr,\n type ListExpression,\n LiteralExpr,\n type NullCheckExpr,\n type OperationExpr,\n type OrderByItem,\n type ParamRef,\n type ProjectionItem,\n type SelectAst,\n type SubqueryExpr,\n type UpdateAst,\n} from '@prisma-next/sql-relational-core/ast';\nimport { escapeLiteral, quoteIdentifier } from '@prisma-next/target-postgres/sql-utils';\nimport type { PostgresContract } from './types';\n\n/**\n * Postgres native types whose unknown-OID parameter inference is reliable in arbitrary expression positions. Parameters bound to a codec whose `meta.db.sql.postgres.nativeType` falls in this set are emitted as plain `$N`; everything else (including `json`, `jsonb`, extension types like `vector`, and unknown user types) is emitted as `$N::<nativeType>` so the planner picks an unambiguous overload.\n *\n * `json` / `jsonb` are intentionally excluded despite being Postgres builtins: their operator overloads make context inference unreliable in expression positions (e.g. `$1 -> 'key'` is ambiguous between the two).\n *\n * Spellings match the on-disk `meta.db.sql.postgres.nativeType` values in `@prisma-next/target-postgres`'s codec definitions, not the `udt_name` abbreviations that ADR 205 used as illustrative shorthand. The lookup-based cast policy compares against these strings directly.\n */\nconst POSTGRES_INFERRABLE_NATIVE_TYPES: ReadonlySet<string> = new Set([\n // Numeric\n 'integer',\n 'smallint',\n 'bigint',\n 'real',\n 'double precision',\n 'numeric',\n // Boolean\n 'boolean',\n // Strings\n 'text',\n 'character',\n 'character varying',\n // Temporal\n 'timestamp',\n 'timestamp without time zone',\n 'timestamp with time zone',\n 'time',\n 'timetz',\n 'interval',\n // Bit strings\n 'bit',\n 'bit varying',\n]);\n\nfunction renderTypedParam(\n index: number,\n codecId: string | undefined,\n codecLookup: CodecLookup,\n): string {\n if (codecId === undefined) {\n return `$${index}`;\n }\n if (codecLookup.get(codecId) === undefined) {\n throw new Error(\n `Postgres lowering: ParamRef carries codecId \"${codecId}\" but the ` +\n 'assembled codec lookup has no entry for it. This usually indicates ' +\n 'a missing extension pack in the runtime stack — register the pack ' +\n 'that contributes this codec (e.g. `extensionPacks: [pgvectorRuntime]`), ' +\n 'or use the codec directly from `@prisma-next/target-postgres/codecs` ' +\n \"if it's a builtin.\",\n );\n }\n // The framework `CodecLookup.metaFor` returns the family-agnostic `CodecMeta` whose `db` is `Record<string, unknown>`. The SQL family populates a narrower shape with `db.sql.<dialect>.nativeType: string`; navigate that path defensively and string-check the leaf.\n const meta = codecLookup.metaFor(codecId);\n const dbRecord = meta?.db;\n const sqlBlock = isRecord(dbRecord) ? dbRecord['sql'] : undefined;\n const dialectBlock = isRecord(sqlBlock) ? sqlBlock['postgres'] : undefined;\n const nativeType = isRecord(dialectBlock) ? dialectBlock['nativeType'] : undefined;\n if (typeof nativeType === 'string' && !POSTGRES_INFERRABLE_NATIVE_TYPES.has(nativeType)) {\n return `$${index}::${nativeType}`;\n }\n return `$${index}`;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\n/**\n * Per-render carrier threaded through every helper. Bundles the param-index map (for `$N` numbering) and the assembled-stack `codecLookup` (for cast policy at the `renderTypedParam` chokepoint). Carrying both on a single value keeps helper signatures stable.\n */\ninterface ParamIndexMap {\n readonly indexMap: Map<ParamRef, number>;\n readonly codecLookup: CodecLookup;\n}\n\n/**\n * Render a SQL query AST to a Postgres-flavored `{ sql, params }` payload.\n *\n * Shared between the runtime (`PostgresAdapterImpl.lower`) and control (`PostgresControlAdapter.lower`) entrypoints so emit-time and run-time paths produce byte-identical output for the same AST.\n */\nexport function renderLoweredSql(\n ast: AnyQueryAst,\n contract: PostgresContract,\n codecLookup: CodecLookup,\n): { readonly sql: string; readonly params: readonly unknown[] } {\n const orderedRefs = collectOrderedParamRefs(ast);\n const indexMap = new Map<ParamRef, number>();\n const params: unknown[] = orderedRefs.map((ref, i) => {\n indexMap.set(ref, i + 1);\n return ref.value;\n });\n const pim: ParamIndexMap = { indexMap, codecLookup };\n\n const node = ast;\n let sql: string;\n switch (node.kind) {\n case 'select':\n sql = renderSelect(node, contract, pim);\n break;\n case 'insert':\n sql = renderInsert(node, contract, pim);\n break;\n case 'update':\n sql = renderUpdate(node, contract, pim);\n break;\n case 'delete':\n sql = renderDelete(node, contract, pim);\n break;\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported AST node kind: ${(node satisfies never as { kind: string }).kind}`,\n );\n }\n\n return Object.freeze({ sql, params: Object.freeze(params) });\n}\n\nfunction renderSelect(ast: SelectAst, contract: PostgresContract, pim: ParamIndexMap): string {\n const selectClause = `SELECT ${renderDistinctPrefix(ast.distinct, ast.distinctOn, contract, pim)}${renderProjection(\n ast.projection,\n contract,\n pim,\n )}`;\n const fromClause = `FROM ${renderSource(ast.from, contract, pim)}`;\n\n const joinsClause = ast.joins?.length\n ? ast.joins.map((join) => renderJoin(join, contract, pim)).join(' ')\n : '';\n\n const whereClause = ast.where ? `WHERE ${renderWhere(ast.where, contract, pim)}` : '';\n const groupByClause = ast.groupBy?.length\n ? `GROUP BY ${ast.groupBy.map((expr) => renderExpr(expr, contract, pim)).join(', ')}`\n : '';\n const havingClause = ast.having ? `HAVING ${renderWhere(ast.having, contract, pim)}` : '';\n const orderClause = ast.orderBy?.length\n ? `ORDER BY ${ast.orderBy\n .map((order) => {\n const expr = renderExpr(order.expr, contract, pim);\n return `${expr} ${order.dir.toUpperCase()}`;\n })\n .join(', ')}`\n : '';\n const limitClause = typeof ast.limit === 'number' ? `LIMIT ${ast.limit}` : '';\n const offsetClause = typeof ast.offset === 'number' ? `OFFSET ${ast.offset}` : '';\n\n const clauses = [\n selectClause,\n fromClause,\n joinsClause,\n whereClause,\n groupByClause,\n havingClause,\n orderClause,\n limitClause,\n offsetClause,\n ]\n .filter((part) => part.length > 0)\n .join(' ');\n return clauses.trim();\n}\n\nfunction renderProjection(\n projection: ReadonlyArray<ProjectionItem>,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n return projection\n .map((item) => {\n const alias = quoteIdentifier(item.alias);\n if (item.expr.kind === 'literal') {\n return `${renderLiteral(item.expr)} AS ${alias}`;\n }\n return `${renderExpr(item.expr, contract, pim)} AS ${alias}`;\n })\n .join(', ');\n}\n\nfunction renderReturning(\n items: ReadonlyArray<ProjectionItem>,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n return items\n .map((item) => {\n if (item.expr.kind === 'column-ref') {\n const rendered = renderColumn(item.expr);\n return item.expr.column === item.alias\n ? rendered\n : `${rendered} AS ${quoteIdentifier(item.alias)}`;\n }\n if (item.expr.kind === 'literal') {\n return `${renderLiteral(item.expr)} AS ${quoteIdentifier(item.alias)}`;\n }\n return `${renderExpr(item.expr, contract, pim)} AS ${quoteIdentifier(item.alias)}`;\n })\n .join(', ');\n}\n\nfunction renderDistinctPrefix(\n distinct: true | undefined,\n distinctOn: ReadonlyArray<AnyExpression> | undefined,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n if (distinctOn && distinctOn.length > 0) {\n const rendered = distinctOn.map((expr) => renderExpr(expr, contract, pim)).join(', ');\n return `DISTINCT ON (${rendered}) `;\n }\n if (distinct) {\n return 'DISTINCT ';\n }\n return '';\n}\n\nfunction renderSource(\n source: AnyFromSource,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const node = source;\n switch (node.kind) {\n case 'table-source': {\n const table = quoteIdentifier(node.name);\n if (!node.alias) {\n return table;\n }\n return `${table} AS ${quoteIdentifier(node.alias)}`;\n }\n case 'derived-table-source':\n return `(${renderSelect(node.query, contract, pim)}) AS ${quoteIdentifier(node.alias)}`;\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported source node kind: ${(node satisfies never as { kind: string }).kind}`,\n );\n }\n}\n\nfunction assertScalarSubquery(query: SelectAst): void {\n if (query.projection.length !== 1) {\n throw new Error('Subquery expressions must project exactly one column');\n }\n}\n\nfunction renderSubqueryExpr(\n expr: SubqueryExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n assertScalarSubquery(expr.query);\n return `(${renderSelect(expr.query, contract, pim)})`;\n}\n\nfunction renderWhere(expr: AnyExpression, contract: PostgresContract, pim: ParamIndexMap): string {\n return renderExpr(expr, contract, pim);\n}\n\nfunction renderNullCheck(\n expr: NullCheckExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const rendered = renderExpr(expr.expr, contract, pim);\n const renderedExpr = isAtomicExpressionKind(expr.expr.kind) ? rendered : `(${rendered})`;\n return expr.isNull ? `${renderedExpr} IS NULL` : `${renderedExpr} IS NOT NULL`;\n}\n\n/**\n * Atomic expression kinds whose rendered SQL is already self-delimited (a column reference, parameter, literal, function call, aggregate, etc.) and therefore does not need surrounding parentheses when used as the left operand of a postfix predicate like `IS NULL` or `IS NOT NULL`, or as either operand of a binary infix operator.\n *\n * Anything not in this set is treated as composite (binary, AND/OR/NOT, EXISTS, nested IS NULL, subqueries, operation templates) and gets wrapped to preserve grouping.\n */\nfunction isAtomicExpressionKind(kind: AnyExpression['kind']): boolean {\n switch (kind) {\n case 'column-ref':\n case 'identifier-ref':\n case 'param-ref':\n case 'literal':\n case 'aggregate':\n case 'json-object':\n case 'json-array-agg':\n case 'list':\n return true;\n case 'subquery':\n case 'operation':\n case 'binary':\n case 'and':\n case 'or':\n case 'exists':\n case 'null-check':\n case 'not':\n return false;\n }\n}\n\nfunction renderBinary(expr: BinaryExpr, contract: PostgresContract, pim: ParamIndexMap): string {\n if (expr.right.kind === 'list' && expr.right.values.length === 0) {\n if (expr.op === 'in') {\n return 'FALSE';\n }\n if (expr.op === 'notIn') {\n return 'TRUE';\n }\n }\n\n const leftExpr = expr.left;\n const left = renderExpr(leftExpr, contract, pim);\n const leftRendered =\n leftExpr.kind === 'operation' || leftExpr.kind === 'subquery' ? `(${left})` : left;\n\n const rightNode = expr.right;\n let right: string;\n switch (rightNode.kind) {\n case 'list':\n right = renderListLiteral(rightNode, contract, pim);\n break;\n case 'literal':\n right = renderLiteral(rightNode);\n break;\n case 'column-ref':\n right = renderColumn(rightNode);\n break;\n case 'param-ref':\n right = renderParamRef(rightNode, pim);\n break;\n default:\n right = renderExpr(rightNode, contract, pim);\n break;\n }\n\n const operatorMap: Record<BinaryExpr['op'], string> = {\n eq: '=',\n neq: '!=',\n gt: '>',\n lt: '<',\n gte: '>=',\n lte: '<=',\n like: 'LIKE',\n in: 'IN',\n notIn: 'NOT IN',\n };\n\n return `${leftRendered} ${operatorMap[expr.op]} ${right}`;\n}\n\nfunction renderListLiteral(\n expr: ListExpression,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n if (expr.values.length === 0) {\n return '(NULL)';\n }\n const values = expr.values\n .map((v) => {\n if (v.kind === 'param-ref') return renderParamRef(v, pim);\n if (v.kind === 'literal') return renderLiteral(v);\n return renderExpr(v, contract, pim);\n })\n .join(', ');\n return `(${values})`;\n}\n\nfunction renderColumn(ref: ColumnRef): string {\n if (ref.table === 'excluded') {\n return `excluded.${quoteIdentifier(ref.column)}`;\n }\n return `${quoteIdentifier(ref.table)}.${quoteIdentifier(ref.column)}`;\n}\n\nfunction renderAggregateExpr(\n expr: AggregateExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const fn = expr.fn.toUpperCase();\n if (!expr.expr) {\n return `${fn}(*)`;\n }\n return `${fn}(${renderExpr(expr.expr, contract, pim)})`;\n}\n\nfunction renderJsonObjectExpr(\n expr: JsonObjectExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const args = expr.entries\n .flatMap((entry): [string, string] => {\n const key = `'${escapeLiteral(entry.key)}'`;\n if (entry.value.kind === 'literal') {\n return [key, renderLiteral(entry.value)];\n }\n return [key, renderExpr(entry.value, contract, pim)];\n })\n .join(', ');\n return `json_build_object(${args})`;\n}\n\nfunction renderOrderByItems(\n items: ReadonlyArray<OrderByItem>,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n return items\n .map((item) => `${renderExpr(item.expr, contract, pim)} ${item.dir.toUpperCase()}`)\n .join(', ');\n}\n\nfunction renderJsonArrayAggExpr(\n expr: JsonArrayAggExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const aggregateOrderBy =\n expr.orderBy && expr.orderBy.length > 0\n ? ` ORDER BY ${renderOrderByItems(expr.orderBy, contract, pim)}`\n : '';\n const aggregated = `json_agg(${renderExpr(expr.expr, contract, pim)}${aggregateOrderBy})`;\n if (expr.onEmpty === 'emptyArray') {\n return `coalesce(${aggregated}, json_build_array())`;\n }\n return aggregated;\n}\n\nfunction renderExpr(expr: AnyExpression, contract: PostgresContract, pim: ParamIndexMap): string {\n const node = expr;\n switch (node.kind) {\n case 'column-ref':\n return renderColumn(node);\n case 'identifier-ref':\n return quoteIdentifier(node.name);\n case 'operation':\n return renderOperation(node, contract, pim);\n case 'subquery':\n return renderSubqueryExpr(node, contract, pim);\n case 'aggregate':\n return renderAggregateExpr(node, contract, pim);\n case 'json-object':\n return renderJsonObjectExpr(node, contract, pim);\n case 'json-array-agg':\n return renderJsonArrayAggExpr(node, contract, pim);\n case 'binary':\n return renderBinary(node, contract, pim);\n case 'and':\n if (node.exprs.length === 0) {\n return 'TRUE';\n }\n return `(${node.exprs.map((part) => renderExpr(part, contract, pim)).join(' AND ')})`;\n case 'or':\n if (node.exprs.length === 0) {\n return 'FALSE';\n }\n return `(${node.exprs.map((part) => renderExpr(part, contract, pim)).join(' OR ')})`;\n case 'exists': {\n const notKeyword = node.notExists ? 'NOT ' : '';\n const subquery = renderSelect(node.subquery, contract, pim);\n return `${notKeyword}EXISTS (${subquery})`;\n }\n case 'null-check':\n return renderNullCheck(node, contract, pim);\n case 'not':\n return `NOT (${renderExpr(node.expr, contract, pim)})`;\n case 'param-ref':\n return renderParamRef(node, pim);\n case 'literal':\n return renderLiteral(node);\n case 'list':\n return renderListLiteral(node, contract, pim);\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported expression node kind: ${(node satisfies never as { kind: string }).kind}`,\n );\n }\n}\n\nfunction renderParamRef(ref: ParamRef, pim: ParamIndexMap): string {\n const index = pim.indexMap.get(ref);\n if (index === undefined) {\n throw new Error('ParamRef not found in index map');\n }\n return renderTypedParam(index, ref.codecId, pim.codecLookup);\n}\n\nfunction renderLiteral(expr: LiteralExpr): string {\n if (typeof expr.value === 'string') {\n return `'${escapeLiteral(expr.value)}'`;\n }\n if (typeof expr.value === 'number' || typeof expr.value === 'boolean') {\n return String(expr.value);\n }\n if (typeof expr.value === 'bigint') {\n return String(expr.value);\n }\n if (expr.value === null) {\n return 'NULL';\n }\n if (expr.value === undefined) {\n return 'NULL';\n }\n if (expr.value instanceof Date) {\n return `'${escapeLiteral(expr.value.toISOString())}'`;\n }\n if (Array.isArray(expr.value)) {\n return `ARRAY[${expr.value.map((v: unknown) => renderLiteral(new LiteralExpr(v))).join(', ')}]`;\n }\n const json = JSON.stringify(expr.value);\n if (json === undefined) {\n return 'NULL';\n }\n return `'${escapeLiteral(json)}'`;\n}\n\nfunction renderOperation(\n expr: OperationExpr,\n contract: PostgresContract,\n pim: ParamIndexMap,\n): string {\n const self = renderExpr(expr.self, contract, pim);\n const args = expr.args.map((arg) => {\n return renderExpr(arg, contract, pim);\n });\n\n // Resolve `{{self}}` and `{{argN}}` from the original template in a single pass. Doing this with sequential `String.prototype.replace` calls is unsafe: a substituted fragment can itself contain text that matches a later token (e.g. an arg literal containing the substring `{{arg1}}`), and the next iteration would corrupt it. A single regex callback never re-scans already-substituted output.\n return expr.lowering.template.replace(\n /\\{\\{self\\}\\}|\\{\\{arg(\\d+)\\}\\}/g,\n (token, argIndex: string | undefined) => {\n if (token === '{{self}}') {\n return self;\n }\n const arg = args[Number(argIndex)];\n if (arg === undefined) {\n throw new Error(\n `Operation lowering template for \"${expr.method}\" referenced missing argument {{arg${argIndex}}}; template has ${args.length} arg(s)`,\n );\n }\n return arg;\n },\n );\n}\n\nfunction renderJoin(join: JoinAst, contract: PostgresContract, pim: ParamIndexMap): string {\n const joinType = join.joinType.toUpperCase();\n const lateral = join.lateral ? 'LATERAL ' : '';\n const source = renderSource(join.source, contract, pim);\n const onClause = renderJoinOn(join.on, contract, pim);\n return `${joinType} JOIN ${lateral}${source} ON ${onClause}`;\n}\n\nfunction renderJoinOn(on: JoinOnExpr, contract: PostgresContract, pim: ParamIndexMap): string {\n if (on.kind === 'eq-col-join-on') {\n const left = renderColumn(on.left);\n const right = renderColumn(on.right);\n return `${left} = ${right}`;\n }\n return renderWhere(on, contract, pim);\n}\n\nfunction getInsertColumnOrder(\n rows: ReadonlyArray<Record<string, InsertValue>>,\n contract: PostgresContract,\n tableName: string,\n): string[] {\n const orderedColumns: string[] = [];\n const seenColumns = new Set<string>();\n\n for (const row of rows) {\n for (const column of Object.keys(row)) {\n if (seenColumns.has(column)) {\n continue;\n }\n seenColumns.add(column);\n orderedColumns.push(column);\n }\n }\n\n if (orderedColumns.length > 0) {\n return orderedColumns;\n }\n\n const table = contract.storage.tables[tableName];\n if (!table) {\n throw new Error(`INSERT target table not found in contract storage: ${tableName}`);\n }\n return Object.keys(table.columns);\n}\n\nfunction renderInsertValue(value: InsertValue | undefined, pim: ParamIndexMap): string {\n if (!value || value.kind === 'default-value') {\n return 'DEFAULT';\n }\n\n switch (value.kind) {\n case 'param-ref':\n return renderParamRef(value, pim);\n case 'column-ref':\n return renderColumn(value);\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported value node in INSERT: ${(value satisfies never as { kind: string }).kind}`,\n );\n }\n}\n\nfunction renderInsert(ast: InsertAst, contract: PostgresContract, pim: ParamIndexMap): string {\n const table = quoteIdentifier(ast.table.name);\n const rows = ast.rows;\n if (rows.length === 0) {\n throw new Error('INSERT requires at least one row');\n }\n const hasExplicitValues = rows.some((row) => Object.keys(row).length > 0);\n const insertClause = (() => {\n if (!hasExplicitValues) {\n if (rows.length === 1) {\n return `INSERT INTO ${table} DEFAULT VALUES`;\n }\n\n const defaultColumns = getInsertColumnOrder(rows, contract, ast.table.name);\n if (defaultColumns.length === 0) {\n return `INSERT INTO ${table} VALUES ${rows.map(() => '()').join(', ')}`;\n }\n\n const quotedColumns = defaultColumns.map((column) => quoteIdentifier(column));\n const defaultRow = `(${defaultColumns.map(() => 'DEFAULT').join(', ')})`;\n return `INSERT INTO ${table} (${quotedColumns.join(', ')}) VALUES ${rows\n .map(() => defaultRow)\n .join(', ')}`;\n }\n\n const columnOrder = getInsertColumnOrder(rows, contract, ast.table.name);\n const columns = columnOrder.map((column) => quoteIdentifier(column));\n const values = rows\n .map((row) => {\n const renderedRow = columnOrder.map((column) => renderInsertValue(row[column], pim));\n return `(${renderedRow.join(', ')})`;\n })\n .join(', ');\n\n return `INSERT INTO ${table} (${columns.join(', ')}) VALUES ${values}`;\n })();\n const onConflictClause = ast.onConflict\n ? (() => {\n const conflictColumns = ast.onConflict.columns.map((col) => quoteIdentifier(col.column));\n if (conflictColumns.length === 0) {\n throw new Error('INSERT onConflict requires at least one conflict column');\n }\n\n const action = ast.onConflict.action;\n switch (action.kind) {\n case 'do-nothing':\n return ` ON CONFLICT (${conflictColumns.join(', ')}) DO NOTHING`;\n case 'do-update-set': {\n const updateEntries = Object.entries(action.set);\n if (updateEntries.length === 0) {\n throw new Error('INSERT onConflict do-update-set requires at least one assignment');\n }\n const updates = updateEntries.map(([colName, value]) => {\n const target = quoteIdentifier(colName);\n if (value.kind === 'param-ref') {\n return `${target} = ${renderParamRef(value, pim)}`;\n }\n return `${target} = ${renderColumn(value)}`;\n });\n return ` ON CONFLICT (${conflictColumns.join(', ')}) DO UPDATE SET ${updates.join(', ')}`;\n }\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported onConflict action: ${(action satisfies never as { kind: string }).kind}`,\n );\n }\n })()\n : '';\n const returningClause = ast.returning?.length\n ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}`\n : '';\n\n return `${insertClause}${onConflictClause}${returningClause}`;\n}\n\nfunction renderUpdate(ast: UpdateAst, contract: PostgresContract, pim: ParamIndexMap): string {\n const table = quoteIdentifier(ast.table.name);\n const setEntries = Object.entries(ast.set);\n if (setEntries.length === 0) {\n throw new Error('UPDATE requires at least one SET assignment');\n }\n const setClauses = setEntries.map(([col, val]) => {\n const column = quoteIdentifier(col);\n let value: string;\n switch (val.kind) {\n case 'param-ref':\n value = renderParamRef(val, pim);\n break;\n case 'column-ref':\n value = renderColumn(val);\n break;\n // v8 ignore next 4\n default:\n throw new Error(\n `Unsupported value node in UPDATE: ${(val satisfies never as { kind: string }).kind}`,\n );\n }\n return `${column} = ${value}`;\n });\n\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : '';\n const returningClause = ast.returning?.length\n ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}`\n : '';\n\n return `UPDATE ${table} SET ${setClauses.join(', ')}${whereClause}${returningClause}`;\n}\n\nfunction renderDelete(ast: DeleteAst, contract: PostgresContract, pim: ParamIndexMap): string {\n const table = quoteIdentifier(ast.table.name);\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract, pim)}` : '';\n const returningClause = ast.returning?.length\n ? ` RETURNING ${renderReturning(ast.returning, contract, pim)}`\n : '';\n\n return `DELETE FROM ${table}${whereClause}${returningClause}`;\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,mCAAgD;CAC9D,OAAO,mBAAmB,CACxB;EACE,IAAI;EACJ,OAAO,EAAE,YAAY,EAAE,kBAAkB,MAAM,KAAK,sBAAsB,QAAQ,CAAC,EAAE,EAAE;EACxF,CACF,CAAC;;;;;;;;;;;ACoBJ,MAAM,mCAAwD,IAAI,IAAI;CAEpE;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACD,CAAC;AAEF,SAAS,iBACP,OACA,S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c,gBAAgB,IAAI,WAAW,UAAU,IAAI,KAC3D"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { BinaryExpr, ColumnRef, DefaultValueExpr, Direction, LoweredStatement, ParamRef, SelectAst } from "@prisma-next/sql-relational-core/ast";
|
|
2
2
|
import { Contract } from "@prisma-next/contract/types";
|
|
3
|
+
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
3
4
|
import { SqlStorage, StorageColumn, StorageTable } from "@prisma-next/sql-contract/types";
|
|
4
5
|
|
|
5
6
|
//#region src/core/types.d.ts
|
|
6
7
|
interface PostgresAdapterOptions {
|
|
7
8
|
readonly profileId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Codec lookup used by the SQL renderer to resolve per-codec metadata at
|
|
11
|
+
* lower-time. Defaults to a Postgres-builtins-only lookup when omitted —
|
|
12
|
+
* see {@link createPostgresBuiltinCodecLookup} in `./codec-lookup`.
|
|
13
|
+
*
|
|
14
|
+
* Stack-aware callers (`SqlRuntimeAdapterDescriptor.create(stack)` /
|
|
15
|
+
* `SqlControlAdapterDescriptor.create(stack)`) supply the assembled stack
|
|
16
|
+
* lookup so extension codecs are visible to the renderer.
|
|
17
|
+
*/
|
|
18
|
+
readonly codecLookup?: CodecLookup;
|
|
8
19
|
}
|
|
9
20
|
type PostgresContract = Contract<SqlStorage> & {
|
|
10
21
|
readonly target: 'postgres';
|
|
@@ -17,4 +28,4 @@ interface OrderClause {
|
|
|
17
28
|
type PostgresLoweredStatement = LoweredStatement;
|
|
18
29
|
//#endregion
|
|
19
30
|
export { OrderClause as a, PostgresContract as c, StorageColumn as d, StorageTable as f, Expr as i, PostgresLoweredStatement as l, ColumnRef as n, ParamRef as o, Direction as r, PostgresAdapterOptions as s, BinaryExpr as t, SelectAst as u };
|
|
20
|
-
//# sourceMappingURL=types-
|
|
31
|
+
//# sourceMappingURL=types-B1eiuBHQ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-B1eiuBHQ.d.mts","names":[],"sources":["../src/core/types.ts"],"mappings":";;;;;;UAoBiB,sBAAA;EAAA,SACN,SAAA;EADM;;;;;;;;;EAAA,SAWN,WAAA,GAAc,WAAA;AAAA;AAAA,KAGb,gBAAA,GAAmB,QAAA,CAAS,UAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAErD,IAAA,GAAO,SAAA,GAAY,QAAA,GAAW,gBAAA;AAAA,UAEzB,WAAA;EAAA,SACN,IAAA,EAAM,SAAA;EAAA,SACN,GAAA,EAAK,SAAA;AAAA;AAAA,KAGJ,wBAAA,GAA2B,gBAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-
|
|
1
|
+
import { a as OrderClause, c as PostgresContract, d as StorageColumn, f as StorageTable, i as Expr, l as PostgresLoweredStatement, n as ColumnRef, o as ParamRef, r as Direction, s as PostgresAdapterOptions, t as BinaryExpr, u as SelectAst } from "./types-B1eiuBHQ.mjs";
|
|
2
2
|
export { type BinaryExpr, type ColumnRef, type Direction, type Expr, type OrderClause, type ParamRef, type PostgresAdapterOptions, type PostgresContract, type PostgresLoweredStatement, type SelectAst, type StorageColumn, type StorageTable };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|