@prisma-next/adapter-postgres 0.13.0-dev.28 → 0.13.0-dev.29

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.
@@ -1,4 +1,4 @@
1
- import { n as renderLoweredSql, r as createPostgresBuiltinCodecLookup, t as PostgresControlAdapter } from "./control-adapter-q2YvnCKu.mjs";
1
+ import { n as renderLoweredSql, r as createPostgresBuiltinCodecLookup, t as PostgresControlAdapter } from "./control-adapter-DmSBWLEm.mjs";
2
2
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
3
3
  import { isDdlNode } from "@prisma-next/sql-relational-core/ast";
4
4
  //#region src/core/adapter.ts
@@ -62,4 +62,4 @@ function createPostgresAdapter(options) {
62
62
  //#endregion
63
63
  export { postgresRawCodecInferer as n, createPostgresAdapter as t };
64
64
 
65
- //# sourceMappingURL=adapter-BzKXNDcB.mjs.map
65
+ //# sourceMappingURL=adapter-CmADcToh.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter-BzKXNDcB.mjs","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":["import type { CodecRegistry } from '@prisma-next/framework-components/codec';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type {\n Adapter,\n AdapterProfile,\n AnyQueryAst,\n LowererContext,\n RawSqlLiteral,\n SqlQueryable,\n} from '@prisma-next/sql-relational-core/ast';\nimport { isDdlNode } from '@prisma-next/sql-relational-core/ast';\nimport type { RawCodecInferer } from '@prisma-next/sql-relational-core/expression';\nimport type { PostgresDdlNode } from '@prisma-next/target-postgres/ddl';\nimport { createPostgresBuiltinCodecLookup } from './codec-lookup';\nimport { PostgresControlAdapter } from './control-adapter';\nimport { renderLoweredSql } from './sql-renderer';\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 distinctOn: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n lateral: true,\n },\n});\n\nclass PostgresAdapterImpl\n implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement>\n{\n // These fields make the adapter instance structurally compatible with RuntimeAdapterInstance<'sql', 'postgres'> without introducing a runtime-plane dependency.\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n readonly profile: AdapterProfile<'postgres'>;\n private readonly codecLookup: CodecRegistry;\n\n constructor(options?: PostgresAdapterOptions) {\n this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();\n const controlAdapter = new PostgresControlAdapter(this.codecLookup);\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n readMarker: (queryable: SqlQueryable) =>\n controlAdapter.readMarkerDiscriminated(\n {\n familyId: 'sql',\n targetId: 'postgres',\n query: async <Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ) => {\n const result = await queryable.query<Row>(sql, params);\n return { rows: [...result.rows] };\n },\n close: async () => {},\n },\n APP_SPACE_ID,\n ),\n });\n }\n\n lower(\n ast: AnyQueryAst | PostgresDdlNode,\n context: LowererContext<PostgresContract>,\n ): PostgresLoweredStatement {\n if (isDdlNode(ast)) {\n throw new Error(\n 'lower() does not lower DDL on the runtime adapter — DDL lowering is a control-plane concern handled by the control adapter.',\n );\n }\n return renderLoweredSql(ast, context.contract, this.codecLookup);\n }\n}\n\n/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */\nexport const postgresRawCodecInferer: RawCodecInferer = {\n inferCodec(value: RawSqlLiteral): string {\n switch (typeof value) {\n case 'number':\n return Number.isSafeInteger(value) && value % 1 === 0 ? 'pg/int4' : 'pg/float8';\n case 'bigint':\n return 'pg/int8';\n case 'string':\n return 'pg/text';\n case 'boolean':\n return 'pg/bool';\n case 'object':\n if (value instanceof Uint8Array) return 'pg/bytea';\n }\n throw new Error(\n 'unsupported JS value type for raw-SQL interpolation: wrap this value in `param(...)` with an explicit codec',\n );\n },\n};\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;AAkBA,MAAM,sBAAsB,OAAO,OAAO;CACxC,UAAU;EACR,SAAS;EACT,OAAO;EACP,SAAS;EACT,SAAS;EACT,WAAW;EACX,YAAY;CACd;CACA,KAAK;EACH,OAAO;EACP,WAAW;EACX,iBAAiB;EACjB,SAAS;CACX;AACF,CAAC;AAED,IAAM,sBAAN,MAEA;CAEE,WAAoB;CACpB,WAAoB;CAEpB;CACA;CAEA,YAAY,SAAkC;EAC5C,KAAK,cAAc,SAAS,eAAe,iCAAiC;EAC5E,MAAM,iBAAiB,IAAI,uBAAuB,KAAK,WAAW;EAClE,KAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,aAAa,cACX,eAAe,wBACb;IACE,UAAU;IACV,UAAU;IACV,OAAO,OACL,KACA,WACG;KAEH,OAAO,EAAE,MAAM,CAAC,IAAG,MADE,UAAU,MAAW,KAAK,MAAM,EAAA,CAC3B,IAAI,EAAE;IAClC;IACA,OAAO,YAAY,CAAC;GACtB,GACA,YACF;EACJ,CAAC;CACH;CAEA,MACE,KACA,SAC0B;EAC1B,IAAI,UAAU,GAAG,GACf,MAAM,IAAI,MACR,6HACF;EAEF,OAAO,iBAAiB,KAAK,QAAQ,UAAU,KAAK,WAAW;CACjE;AACF;;AAGA,MAAa,0BAA2C,EACtD,WAAW,OAA8B;CACvC,QAAQ,OAAO,OAAf;EACE,KAAK,UACH,OAAO,OAAO,cAAc,KAAK,KAAK,QAAQ,MAAM,IAAI,YAAY;EACtE,KAAK,UACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,UACH,IAAI,iBAAiB,YAAY,OAAO;CAC5C;CACA,MAAM,IAAI,MACR,6GACF;AACF,EACF;AAEA,SAAgB,sBAAsB,SAAkC;CACtE,OAAO,OAAO,OAAO,IAAI,oBAAoB,OAAO,CAAC;AACvD"}
1
+ {"version":3,"file":"adapter-CmADcToh.mjs","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":["import type { CodecRegistry } from '@prisma-next/framework-components/codec';\nimport { APP_SPACE_ID } from '@prisma-next/framework-components/control';\nimport type {\n Adapter,\n AdapterProfile,\n AnyQueryAst,\n LowererContext,\n RawSqlLiteral,\n SqlQueryable,\n} from '@prisma-next/sql-relational-core/ast';\nimport { isDdlNode } from '@prisma-next/sql-relational-core/ast';\nimport type { RawCodecInferer } from '@prisma-next/sql-relational-core/expression';\nimport type { PostgresDdlNode } from '@prisma-next/target-postgres/ddl';\nimport { createPostgresBuiltinCodecLookup } from './codec-lookup';\nimport { PostgresControlAdapter } from './control-adapter';\nimport { renderLoweredSql } from './sql-renderer';\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 distinctOn: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n lateral: true,\n },\n});\n\nclass PostgresAdapterImpl\n implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement>\n{\n // These fields make the adapter instance structurally compatible with RuntimeAdapterInstance<'sql', 'postgres'> without introducing a runtime-plane dependency.\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n readonly profile: AdapterProfile<'postgres'>;\n private readonly codecLookup: CodecRegistry;\n\n constructor(options?: PostgresAdapterOptions) {\n this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();\n const controlAdapter = new PostgresControlAdapter(this.codecLookup);\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n readMarker: (queryable: SqlQueryable) =>\n controlAdapter.readMarkerDiscriminated(\n {\n familyId: 'sql',\n targetId: 'postgres',\n query: async <Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ) => {\n const result = await queryable.query<Row>(sql, params);\n return { rows: [...result.rows] };\n },\n close: async () => {},\n },\n APP_SPACE_ID,\n ),\n });\n }\n\n lower(\n ast: AnyQueryAst | PostgresDdlNode,\n context: LowererContext<PostgresContract>,\n ): PostgresLoweredStatement {\n if (isDdlNode(ast)) {\n throw new Error(\n 'lower() does not lower DDL on the runtime adapter — DDL lowering is a control-plane concern handled by the control adapter.',\n );\n }\n return renderLoweredSql(ast, context.contract, this.codecLookup);\n }\n}\n\n/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */\nexport const postgresRawCodecInferer: RawCodecInferer = {\n inferCodec(value: RawSqlLiteral): string {\n switch (typeof value) {\n case 'number':\n return Number.isSafeInteger(value) && value % 1 === 0 ? 'pg/int4' : 'pg/float8';\n case 'bigint':\n return 'pg/int8';\n case 'string':\n return 'pg/text';\n case 'boolean':\n return 'pg/bool';\n case 'object':\n if (value instanceof Uint8Array) return 'pg/bytea';\n }\n throw new Error(\n 'unsupported JS value type for raw-SQL interpolation: wrap this value in `param(...)` with an explicit codec',\n );\n },\n};\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;AAkBA,MAAM,sBAAsB,OAAO,OAAO;CACxC,UAAU;EACR,SAAS;EACT,OAAO;EACP,SAAS;EACT,SAAS;EACT,WAAW;EACX,YAAY;CACd;CACA,KAAK;EACH,OAAO;EACP,WAAW;EACX,iBAAiB;EACjB,SAAS;CACX;AACF,CAAC;AAED,IAAM,sBAAN,MAEA;CAEE,WAAoB;CACpB,WAAoB;CAEpB;CACA;CAEA,YAAY,SAAkC;EAC5C,KAAK,cAAc,SAAS,eAAe,iCAAiC;EAC5E,MAAM,iBAAiB,IAAI,uBAAuB,KAAK,WAAW;EAClE,KAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,aAAa,cACX,eAAe,wBACb;IACE,UAAU;IACV,UAAU;IACV,OAAO,OACL,KACA,WACG;KAEH,OAAO,EAAE,MAAM,CAAC,IAAG,MADE,UAAU,MAAW,KAAK,MAAM,EAAA,CAC3B,IAAI,EAAE;IAClC;IACA,OAAO,YAAY,CAAC;GACtB,GACA,YACF;EACJ,CAAC;CACH;CAEA,MACE,KACA,SAC0B;EAC1B,IAAI,UAAU,GAAG,GACf,MAAM,IAAI,MACR,6HACF;EAEF,OAAO,iBAAiB,KAAK,QAAQ,UAAU,KAAK,WAAW;CACjE;AACF;;AAGA,MAAa,0BAA2C,EACtD,WAAW,OAA8B;CACvC,QAAQ,OAAO,OAAf;EACE,KAAK,UACH,OAAO,OAAO,cAAc,KAAK,KAAK,QAAQ,MAAM,IAAI,YAAY;EACtE,KAAK,UACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,UACH,IAAI,iBAAiB,YAAY,OAAO;CAC5C;CACA,MAAM,IAAI,MACR,6GACF;AACF,EACF;AAEA,SAAgB,sBAAsB,SAAkC;CACtE,OAAO,OAAO,OAAO,IAAI,oBAAoB,OAAO,CAAC;AACvD"}
package/dist/adapter.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-BzKXNDcB.mjs";
1
+ import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-CmADcToh.mjs";
2
2
  export { createPostgresAdapter, postgresRawCodecInferer };
@@ -1,4 +1,3 @@
1
- import { PostgresEnumType } from "@prisma-next/target-postgres/types";
2
1
  import { ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
3
2
 
4
3
  //#region src/exports/column-types.d.ts
@@ -104,10 +103,6 @@ declare const jsonbColumn: {
104
103
  readonly codecId: "pg/jsonb@1";
105
104
  readonly nativeType: "jsonb";
106
105
  };
107
- declare function enumType<const Values extends readonly string[]>(name: string, values: Values): PostgresEnumType;
108
- declare function enumColumn<TypeName extends string>(typeName: TypeName, nativeType: string): ColumnTypeDescriptor & {
109
- readonly typeRef: TypeName;
110
- };
111
106
  //#endregion
112
- export { bitColumn, boolColumn, byteaColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
107
+ export { bitColumn, boolColumn, byteaColumn, charColumn, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
113
108
  //# sourceMappingURL=column-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"mappings":";;;;cAgCa,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,UAAA,CAAW,MAAA,WAAiB,oBAAoB;EAAA,SACrD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;AAAA,iBASlB,aAAA,CAAc,MAAA,WAAiB,oBAAoB;EAAA,SACxD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;AAAA,cASrB,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,YAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,YAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iB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SAAuB,MAAA;EAAA;AAAA;;;;;;cAcrB,WAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,cAAA,CAAe,SAAA,YAAqB,oBAAoB;EAAA,SAC7D,UAAA;IAAA,SAAwB,SAAA;EAAA;AAAA;;;AA7CS;AAS5C;;cAkDa,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;;;;cAK5B,WAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA"}
@@ -1,5 +1,4 @@
1
- import { PG_BIT_CODEC_ID, PG_BOOL_CODEC_ID, PG_BYTEA_CODEC_ID, PG_ENUM_CODEC_ID, PG_FLOAT4_CODEC_ID, PG_FLOAT8_CODEC_ID, PG_INT2_CODEC_ID, PG_INT4_CODEC_ID, PG_INT8_CODEC_ID, PG_INTERVAL_CODEC_ID, PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID, PG_NUMERIC_CODEC_ID, PG_TEXT_CODEC_ID, PG_TIMESTAMPTZ_CODEC_ID, PG_TIMESTAMP_CODEC_ID, PG_TIMETZ_CODEC_ID, PG_TIME_CODEC_ID, PG_VARBIT_CODEC_ID, SQL_CHAR_CODEC_ID, SQL_VARCHAR_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
2
- import { PostgresEnumType } from "@prisma-next/target-postgres/types";
1
+ import { PG_BIT_CODEC_ID, PG_BOOL_CODEC_ID, PG_BYTEA_CODEC_ID, PG_FLOAT4_CODEC_ID, PG_FLOAT8_CODEC_ID, PG_INT2_CODEC_ID, PG_INT4_CODEC_ID, PG_INT8_CODEC_ID, PG_INTERVAL_CODEC_ID, PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID, PG_NUMERIC_CODEC_ID, PG_TEXT_CODEC_ID, PG_TIMESTAMPTZ_CODEC_ID, PG_TIMESTAMP_CODEC_ID, PG_TIMETZ_CODEC_ID, PG_TIME_CODEC_ID, PG_VARBIT_CODEC_ID, SQL_CHAR_CODEC_ID, SQL_VARCHAR_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
3
2
  //#region src/exports/column-types.ts
4
3
  const textColumn = {
5
4
  codecId: PG_TEXT_CODEC_ID,
@@ -121,21 +120,7 @@ const jsonbColumn = {
121
120
  codecId: PG_JSONB_CODEC_ID,
122
121
  nativeType: "jsonb"
123
122
  };
124
- function enumType(name, values) {
125
- return new PostgresEnumType({
126
- name,
127
- nativeType: name,
128
- values
129
- });
130
- }
131
- function enumColumn(typeName, nativeType) {
132
- return {
133
- codecId: PG_ENUM_CODEC_ID,
134
- nativeType,
135
- typeRef: typeName
136
- };
137
- }
138
123
  //#endregion
139
- export { bitColumn, boolColumn, byteaColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
124
+ export { bitColumn, boolColumn, byteaColumn, charColumn, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
140
125
 
141
126
  //# sourceMappingURL=column-types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for Postgres adapter.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring. They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_BYTEA_CODEC_ID,\n PG_ENUM_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n SQL_CHAR_CODEC_ID,\n SQL_VARCHAR_CODEC_ID,\n} from '@prisma-next/target-postgres/codec-ids';\nimport { PostgresEnumType } from '@prisma-next/target-postgres/types';\n\nexport const textColumn = {\n codecId: PG_TEXT_CODEC_ID,\n nativeType: 'text',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function charColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_CHAR_CODEC_ID,\n nativeType: 'character',\n typeParams: { length },\n } as const;\n}\n\nexport function varcharColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_VARCHAR_CODEC_ID,\n nativeType: 'character varying',\n typeParams: { length },\n } as const;\n}\n\nexport const int4Column = {\n codecId: PG_INT4_CODEC_ID,\n nativeType: 'int4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int2Column = {\n codecId: PG_INT2_CODEC_ID,\n nativeType: 'int2',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int8Column = {\n codecId: PG_INT8_CODEC_ID,\n nativeType: 'int8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float4Column = {\n codecId: PG_FLOAT4_CODEC_ID,\n nativeType: 'float4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float8Column = {\n codecId: PG_FLOAT8_CODEC_ID,\n nativeType: 'float8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function numericColumn(\n precision: number,\n scale?: number,\n): ColumnTypeDescriptor & {\n readonly typeParams: { readonly precision: number; readonly scale?: number };\n} {\n return {\n codecId: PG_NUMERIC_CODEC_ID,\n nativeType: 'numeric',\n typeParams: scale === undefined ? { precision } : { precision, scale },\n } as const;\n}\n\nexport const timestampColumn = {\n codecId: PG_TIMESTAMP_CODEC_ID,\n nativeType: 'timestamp',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const timestamptzColumn = {\n codecId: PG_TIMESTAMPTZ_CODEC_ID,\n nativeType: 'timestamptz',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function timeColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIME_CODEC_ID,\n nativeType: 'time',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport function timetzColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIMETZ_CODEC_ID,\n nativeType: 'timetz',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport const boolColumn = {\n codecId: PG_BOOL_CODEC_ID,\n nativeType: 'bool',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function bitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_BIT_CODEC_ID,\n nativeType: 'bit',\n typeParams: { length },\n } as const;\n}\n\nexport function varbitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_VARBIT_CODEC_ID,\n nativeType: 'bit varying',\n typeParams: { length },\n } as const;\n}\n\n/**\n * Postgres `bytea` column descriptor — variable-length binary string.\n *\n * Round-trips as `Uint8Array` on the JS side. The pg wire-protocol text encoding (`\\x` followed by hex-encoded bytes, canonical for Postgres ≥ 9.0) and binary encoding are both handled by the underlying driver; the codec only normalizes the JS-side representation to a plain `Uint8Array` view.\n */\nexport const byteaColumn = {\n codecId: PG_BYTEA_CODEC_ID,\n nativeType: 'bytea',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function intervalColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_INTERVAL_CODEC_ID,\n nativeType: 'interval',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\n/**\n * Postgres `json` column descriptor — untyped raw JSON.\n *\n * For schema-typed JSON columns, use the per-library extension package (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for arktype). The schema-accepting `json(schema)` / `jsonb(schema)` overloads previously shipped from this module retired in Phase C of the codec-registry-unification project — see spec § AC-7.\n */\nexport const jsonColumn = {\n codecId: PG_JSON_CODEC_ID,\n nativeType: 'json',\n} as const satisfies ColumnTypeDescriptor;\n\n/**\n * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement note as {@link jsonColumn}.\n */\nexport const jsonbColumn = {\n codecId: PG_JSONB_CODEC_ID,\n nativeType: 'jsonb',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function enumType<const Values extends readonly string[]>(\n name: string,\n values: Values,\n): PostgresEnumType {\n return new PostgresEnumType({ name, nativeType: name, values });\n}\n\nexport function enumColumn<TypeName extends string>(\n typeName: TypeName,\n nativeType: string,\n): ColumnTypeDescriptor & { readonly typeRef: TypeName } {\n return {\n codecId: PG_ENUM_CODEC_ID,\n nativeType,\n typeRef: typeName,\n };\n}\n"],"mappings":";;;AAgCA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,WAAW,QAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,SAAgB,cAAc,QAE5B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;AACd;AAEA,MAAa,eAAe;CAC1B,SAAS;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;AACF"}
1
+ {"version":3,"file":"column-types.mjs","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":["/**\n * Column type descriptors for Postgres adapter.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring. They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/framework-components/codec';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_CODEC_ID,\n PG_BYTEA_CODEC_ID,\n PG_FLOAT4_CODEC_ID,\n PG_FLOAT8_CODEC_ID,\n PG_INT2_CODEC_ID,\n PG_INT4_CODEC_ID,\n PG_INT8_CODEC_ID,\n PG_INTERVAL_CODEC_ID,\n PG_JSON_CODEC_ID,\n PG_JSONB_CODEC_ID,\n PG_NUMERIC_CODEC_ID,\n PG_TEXT_CODEC_ID,\n PG_TIME_CODEC_ID,\n PG_TIMESTAMP_CODEC_ID,\n PG_TIMESTAMPTZ_CODEC_ID,\n PG_TIMETZ_CODEC_ID,\n PG_VARBIT_CODEC_ID,\n SQL_CHAR_CODEC_ID,\n SQL_VARCHAR_CODEC_ID,\n} from '@prisma-next/target-postgres/codec-ids';\n\nexport const textColumn = {\n codecId: PG_TEXT_CODEC_ID,\n nativeType: 'text',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function charColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_CHAR_CODEC_ID,\n nativeType: 'character',\n typeParams: { length },\n } as const;\n}\n\nexport function varcharColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: SQL_VARCHAR_CODEC_ID,\n nativeType: 'character varying',\n typeParams: { length },\n } as const;\n}\n\nexport const int4Column = {\n codecId: PG_INT4_CODEC_ID,\n nativeType: 'int4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int2Column = {\n codecId: PG_INT2_CODEC_ID,\n nativeType: 'int2',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const int8Column = {\n codecId: PG_INT8_CODEC_ID,\n nativeType: 'int8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float4Column = {\n codecId: PG_FLOAT4_CODEC_ID,\n nativeType: 'float4',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const float8Column = {\n codecId: PG_FLOAT8_CODEC_ID,\n nativeType: 'float8',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function numericColumn(\n precision: number,\n scale?: number,\n): ColumnTypeDescriptor & {\n readonly typeParams: { readonly precision: number; readonly scale?: number };\n} {\n return {\n codecId: PG_NUMERIC_CODEC_ID,\n nativeType: 'numeric',\n typeParams: scale === undefined ? { precision } : { precision, scale },\n } as const;\n}\n\nexport const timestampColumn = {\n codecId: PG_TIMESTAMP_CODEC_ID,\n nativeType: 'timestamp',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const timestamptzColumn = {\n codecId: PG_TIMESTAMPTZ_CODEC_ID,\n nativeType: 'timestamptz',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function timeColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIME_CODEC_ID,\n nativeType: 'time',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport function timetzColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_TIMETZ_CODEC_ID,\n nativeType: 'timetz',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\nexport const boolColumn = {\n codecId: PG_BOOL_CODEC_ID,\n nativeType: 'bool',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function bitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_BIT_CODEC_ID,\n nativeType: 'bit',\n typeParams: { length },\n } as const;\n}\n\nexport function varbitColumn(length: number): ColumnTypeDescriptor & {\n readonly typeParams: { readonly length: number };\n} {\n return {\n codecId: PG_VARBIT_CODEC_ID,\n nativeType: 'bit varying',\n typeParams: { length },\n } as const;\n}\n\n/**\n * Postgres `bytea` column descriptor — variable-length binary string.\n *\n * Round-trips as `Uint8Array` on the JS side. The pg wire-protocol text encoding (`\\x` followed by hex-encoded bytes, canonical for Postgres ≥ 9.0) and binary encoding are both handled by the underlying driver; the codec only normalizes the JS-side representation to a plain `Uint8Array` view.\n */\nexport const byteaColumn = {\n codecId: PG_BYTEA_CODEC_ID,\n nativeType: 'bytea',\n} as const satisfies ColumnTypeDescriptor;\n\nexport function intervalColumn(precision?: number): ColumnTypeDescriptor & {\n readonly typeParams?: { readonly precision: number };\n} {\n return {\n codecId: PG_INTERVAL_CODEC_ID,\n nativeType: 'interval',\n ...(precision === undefined ? {} : { typeParams: { precision } }),\n } as const;\n}\n\n/**\n * Postgres `json` column descriptor — untyped raw JSON.\n *\n * For schema-typed JSON columns, use the per-library extension package (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for arktype). The schema-accepting `json(schema)` / `jsonb(schema)` overloads previously shipped from this module retired in Phase C of the codec-registry-unification project — see spec § AC-7.\n */\nexport const jsonColumn = {\n codecId: PG_JSON_CODEC_ID,\n nativeType: 'json',\n} as const satisfies ColumnTypeDescriptor;\n\n/**\n * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement note as {@link jsonColumn}.\n */\nexport const jsonbColumn = {\n codecId: PG_JSONB_CODEC_ID,\n nativeType: 'jsonb',\n} as const satisfies ColumnTypeDescriptor;\n"],"mappings":";;AA8BA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,WAAW,QAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,SAAgB,cAAc,QAE5B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,aA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7,12 @@ import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
7
7
  import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
8
8
  import { PostgresTableSource, buildControlTableBootstrapQueries, buildSignMarkerBootstrapQueries, int4, int8, jsonb, pgTable, text, textArray, timestamptz } from "@prisma-next/target-postgres/contract-free";
9
9
  import { parsePostgresDefault } from "@prisma-next/target-postgres/default-normalizer";
10
- import { createResolveExistingEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations } from "@prisma-next/target-postgres/enum-planning";
11
10
  import { normalizeSchemaNativeType } from "@prisma-next/target-postgres/native-type-normalizer";
12
11
  import { escapeLiteral, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
13
12
  import { blindCast } from "@prisma-next/utils/casts";
14
13
  import { ifDefined } from "@prisma-next/utils/defined";
15
14
  import { createAstCodecRegistry, deriveParamMetadata, encodeParamsWithMetadata } from "@prisma-next/sql-runtime";
16
- import { PG_ENUM_CODEC_ID, PG_TIMESTAMPTZ_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
15
+ import { PG_TIMESTAMPTZ_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
17
16
  import { runtimeError } from "@prisma-next/framework-components/runtime";
18
17
  //#region src/core/codec-lookup.ts
19
18
  /**
@@ -45,97 +44,6 @@ async function encodeControlQueryParams(lowered, ast, codecs = CONTROL_CODECS) {
45
44
  }), deriveParamMetadata(ast), {}, codecs);
46
45
  }
47
46
  //#endregion
48
- //#region src/core/enum-control-hooks.ts
49
- const ENUM_INTROSPECT_QUERY = `
50
- SELECT
51
- n.nspname AS schema_name,
52
- t.typname AS type_name,
53
- array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values
54
- FROM pg_type t
55
- JOIN pg_namespace n ON t.typnamespace = n.oid
56
- JOIN pg_enum e ON t.oid = e.enumtypid
57
- WHERE n.nspname = $1
58
- GROUP BY n.nspname, t.typname
59
- ORDER BY n.nspname, t.typname
60
- `;
61
- function isStringArray(value) {
62
- return Array.isArray(value) && value.every((entry) => typeof entry === "string");
63
- }
64
- /**
65
- * Parses a PostgreSQL array value into a JavaScript string array.
66
- *
67
- * The `pg` library returns `array_agg` results either as a JS array
68
- * (when type parsers are configured) or as a string in PostgreSQL array
69
- * literal format (`{value1,value2,...}`). Handles PG's quoting rules:
70
- * - Elements containing commas, quotes, backslashes, or whitespace are
71
- * double-quoted.
72
- * - Inside quoted elements, `\"` represents `"` and `\\` represents `\`.
73
- *
74
- * Returns `null` when the input cannot be parsed as a PG array.
75
- */
76
- function parsePostgresArray(value) {
77
- if (isStringArray(value)) return value;
78
- if (typeof value === "string" && value.startsWith("{") && value.endsWith("}")) {
79
- const inner = value.slice(1, -1);
80
- if (inner === "") return [];
81
- return parseArrayElements(inner);
82
- }
83
- return null;
84
- }
85
- function parseArrayElements(input) {
86
- const result = [];
87
- let i = 0;
88
- while (i < input.length) {
89
- if (input[i] === ",") {
90
- i++;
91
- continue;
92
- }
93
- if (input[i] === "\"") {
94
- i++;
95
- let element = "";
96
- while (i < input.length && input[i] !== "\"") {
97
- if (input[i] === "\\" && i + 1 < input.length) {
98
- i++;
99
- element += input[i];
100
- } else element += input[i];
101
- i++;
102
- }
103
- i++;
104
- result.push(element);
105
- } else {
106
- const nextComma = input.indexOf(",", i);
107
- if (nextComma === -1) {
108
- result.push(input.slice(i).trim());
109
- i = input.length;
110
- } else {
111
- result.push(input.slice(i, nextComma).trim());
112
- i = nextComma;
113
- }
114
- }
115
- }
116
- return result;
117
- }
118
- /**
119
- * Reads enum types from the live Postgres schema and returns them in
120
- * the codec-typed annotation shape consumed by `control-adapter.ts`
121
- * (which writes them under `schema.annotations.pg.storageTypes`).
122
- */
123
- async function introspectPostgresEnumTypes(options) {
124
- const namespace = options.schemaName ?? "public";
125
- const result = await options.driver.query(ENUM_INTROSPECT_QUERY, [namespace]);
126
- const types = {};
127
- for (const row of result.rows) {
128
- const values = parsePostgresArray(row.values);
129
- if (!values) throw new Error(`Failed to parse enum values for type "${row.type_name}": unexpected format: ${JSON.stringify(row.values)}`);
130
- types[row.type_name] = {
131
- codecId: PG_ENUM_CODEC_ID,
132
- nativeType: row.type_name,
133
- typeParams: { values }
134
- };
135
- }
136
- return types;
137
- }
138
- //#endregion
139
47
  //#region src/core/marker-ledger.ts
140
48
  const marker = pgTable({
141
49
  name: "marker",
@@ -303,20 +211,14 @@ function renderLimitOffset(keyword, value, contract, pim) {
303
211
  return `${keyword} ${renderExpr(value, contract, pim)}`;
304
212
  }
305
213
  function renderSelect(ast, contract, pim) {
306
- const selectClause = `SELECT ${renderDistinctPrefix(ast.distinct, ast.distinctOn, contract, pim)}${renderProjection(ast.projection, contract, pim)}`;
307
- const fromClause = `FROM ${renderSource(ast.from, contract, pim)}`;
308
- const joinsClause = ast.joins?.length ? ast.joins.map((join) => renderJoin(join, contract, pim)).join(" ") : "";
309
- const whereClause = ast.where ? `WHERE ${renderWhere(ast.where, contract, pim)}` : "";
310
- const groupByClause = ast.groupBy?.length ? `GROUP BY ${ast.groupBy.map((expr) => renderExpr(expr, contract, pim)).join(", ")}` : "";
311
- const havingClause = ast.having ? `HAVING ${renderWhere(ast.having, contract, pim)}` : "";
312
214
  const sourcesByRef = collectTableSources(ast);
313
215
  return [
314
- selectClause,
315
- fromClause,
316
- joinsClause,
317
- whereClause,
318
- groupByClause,
319
- havingClause,
216
+ `SELECT ${renderDistinctPrefix(ast.distinct, ast.distinctOn, sourcesByRef, contract, pim)}${renderProjection(ast.projection, contract, pim)}`,
217
+ `FROM ${renderSource(ast.from, contract, pim)}`,
218
+ ast.joins?.length ? ast.joins.map((join) => renderJoin(join, contract, pim)).join(" ") : "",
219
+ ast.where ? `WHERE ${renderWhere(ast.where, contract, pim)}` : "",
220
+ ast.groupBy?.length ? `GROUP BY ${ast.groupBy.map((expr) => renderExpr(expr, contract, pim)).join(", ")}` : "",
221
+ ast.having ? `HAVING ${renderWhere(ast.having, contract, pim)}` : "",
320
222
  ast.orderBy?.length ? `ORDER BY ${ast.orderBy.map((order) => {
321
223
  return `${renderOrderByExpr(order.expr, sourcesByRef, contract, pim)} ${order.dir.toUpperCase()}`;
322
224
  }).join(", ")}` : "",
@@ -407,8 +309,8 @@ function renderReturning(items, contract, pim) {
407
309
  return `${renderExpr(item.expr, contract, pim)} AS ${quoteIdentifier(item.alias)}`;
408
310
  }).join(", ");
409
311
  }
410
- function renderDistinctPrefix(distinct, distinctOn, contract, pim) {
411
- if (distinctOn && distinctOn.length > 0) return `DISTINCT ON (${distinctOn.map((expr) => renderExpr(expr, contract, pim)).join(", ")}) `;
312
+ function renderDistinctPrefix(distinct, distinctOn, sourcesByRef, contract, pim) {
313
+ if (distinctOn && distinctOn.length > 0) return `DISTINCT ON (${distinctOn.map((expr) => renderOrderByExpr(expr, sourcesByRef, contract, pim)).join(", ")}) `;
412
314
  if (distinct) return "DISTINCT ";
413
315
  return "";
414
316
  }
@@ -754,16 +656,6 @@ var PostgresControlAdapter = class {
754
656
  * before comparison with contract native types.
755
657
  */
756
658
  normalizeNativeType = normalizeSchemaNativeType;
757
- /**
758
- * Bridges native `PostgresEnumStorageEntry` IR walks against the Postgres
759
- * introspection shape (`schema.annotations.pg.storageTypes`). Lets
760
- * the family-level schema verifier walk enum types without reaching
761
- * into target-specific annotation layouts itself.
762
- */
763
- resolveExistingEnumValues = (schema, enumType, namespaceId) => {
764
- return readExistingEnumValues(schema, namespaceId === UNBOUND_NAMESPACE_ID ? readPostgresSchemaIrAnnotations(schema).schema ?? "public" : namespaceId, enumType.nativeType);
765
- };
766
- resolveExistingEnumValuesForContract = (contract) => createResolveExistingEnumValues(contract.storage);
767
659
  bootstrapControlTableQueries() {
768
660
  return buildControlTableBootstrapQueries();
769
661
  }
@@ -1036,26 +928,13 @@ var PostgresControlAdapter = class {
1036
928
  for (const schema of uniqueSchemas) perSchema.push(await this.introspectSchema(driver, schema));
1037
929
  const mergedTables = {};
1038
930
  for (const ir of perSchema) for (const [tableName, table] of Object.entries(ir.tables)) mergedTables[tableName] = table;
1039
- const mergedEnumTypes = {};
1040
- for (const ir of perSchema) {
1041
- const enumTypes = blindCast(ir?.annotations?.["pg"])?.enumTypes;
1042
- if (!enumTypes) continue;
1043
- for (const [schemaName, byType] of Object.entries(enumTypes)) {
1044
- const merged = mergedEnumTypes[schemaName] ?? {};
1045
- Object.assign(merged, byType);
1046
- mergedEnumTypes[schemaName] = merged;
1047
- }
1048
- }
1049
931
  const firstAnnotations = perSchema[0]?.annotations;
1050
932
  const firstPg = blindCast(firstAnnotations?.["pg"]) ?? {};
1051
933
  return {
1052
934
  tables: mergedTables,
1053
935
  ...ifDefined("annotations", {
1054
936
  ...firstAnnotations,
1055
- pg: {
1056
- ...firstPg,
1057
- ...ifDefined("enumTypes", Object.keys(mergedEnumTypes).length > 0 ? mergedEnumTypes : void 0)
1058
- }
937
+ pg: { ...firstPg }
1059
938
  })
1060
939
  };
1061
940
  }
@@ -1314,17 +1193,18 @@ var PostgresControlAdapter = class {
1314
1193
  ...ifDefined("checks", checksForTable.length > 0 ? checksForTable : void 0)
1315
1194
  };
1316
1195
  }
1317
- const rawEnumTypes = await introspectPostgresEnumTypes({
1318
- driver,
1319
- schemaName: schema
1320
- });
1321
- const enumTypes = Object.keys(rawEnumTypes).length > 0 ? { [schema]: rawEnumTypes } : {};
1196
+ const nativeEnumTypeNames = (await driver.query(`SELECT t.typname
1197
+ FROM pg_catalog.pg_type t
1198
+ JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
1199
+ WHERE t.typtype = 'e'
1200
+ AND n.nspname = $1
1201
+ ORDER BY t.typname`, [schema])).rows.map((r) => r.typname);
1322
1202
  return {
1323
1203
  tables,
1324
1204
  annotations: { pg: {
1325
1205
  schema,
1326
1206
  version: await this.getPostgresVersion(driver),
1327
- ...ifDefined("enumTypes", Object.keys(enumTypes).length > 0 ? enumTypes : void 0)
1207
+ ...nativeEnumTypeNames.length > 0 && { nativeEnumTypeNames }
1328
1208
  } }
1329
1209
  };
1330
1210
  }
@@ -1590,4 +1470,4 @@ async function pgRenderDdlExecuteRequest(ast, codecLookup) {
1590
1470
  //#endregion
1591
1471
  export { renderLoweredSql as n, createPostgresBuiltinCodecLookup as r, PostgresControlAdapter as t };
1592
1472
 
1593
- //# sourceMappingURL=control-adapter-q2YvnCKu.mjs.map
1473
+ //# sourceMappingURL=control-adapter-DmSBWLEm.mjs.map