@prisma-next/adapter-postgres 0.4.0-dev.9 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-hNElNHo4.mjs +60 -0
- package/dist/adapter-hNElNHo4.mjs.map +1 -0
- package/dist/adapter.d.mts +2 -8
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs +1 -1
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +3 -70
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +19 -160
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-DemWrTfB.mjs → descriptor-meta-RTDzyrae.mjs} +33 -9
- package/dist/descriptor-meta-RTDzyrae.mjs.map +1 -0
- package/dist/operation-types.d.mts +21 -0
- package/dist/operation-types.d.mts.map +1 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +8 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/{adapter-7pXt8ej9.mjs → sql-renderer-pEaSP82_.mjs} +102 -101
- package/dist/sql-renderer-pEaSP82_.mjs.map +1 -0
- package/dist/{types-DxaTd7aP.d.mts → types-CfRPdAk8.d.mts} +1 -1
- package/dist/{types-DxaTd7aP.d.mts.map → types-CfRPdAk8.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +22 -16
- package/src/core/adapter.ts +4 -626
- package/src/core/control-adapter.ts +21 -47
- package/src/core/descriptor-meta.ts +25 -5
- package/src/core/enum-control-hooks.ts +7 -2
- package/src/core/json-schema-validator.ts +2 -1
- package/src/core/sql-renderer.ts +710 -0
- package/src/exports/column-types.ts +1 -1
- package/src/exports/control.ts +9 -4
- package/src/exports/operation-types.ts +1 -0
- package/src/exports/runtime.ts +5 -4
- package/src/types/operation-types.ts +11 -0
- package/dist/adapter-7pXt8ej9.mjs.map +0 -1
- package/dist/codec-ids-BwjcIf74.mjs +0 -29
- package/dist/codec-ids-BwjcIf74.mjs.map +0 -1
- package/dist/codec-types.d.mts +0 -107
- package/dist/codec-types.d.mts.map +0 -1
- package/dist/codec-types.mjs +0 -3
- package/dist/codecs-C3wlpdV7.mjs +0 -385
- package/dist/codecs-C3wlpdV7.mjs.map +0 -1
- package/dist/descriptor-meta-DemWrTfB.mjs.map +0 -1
- package/dist/sql-utils-CSfAGEwF.mjs +0 -78
- package/dist/sql-utils-CSfAGEwF.mjs.map +0 -1
- package/src/core/codec-ids.ts +0 -30
- package/src/core/codecs.ts +0 -645
- package/src/core/default-normalizer.ts +0 -145
- package/src/core/json-schema-type-expression.ts +0 -131
- package/src/core/sql-utils.ts +0 -111
- package/src/exports/codec-types.ts +0 -44
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { t as renderLoweredSql } from "./sql-renderer-pEaSP82_.mjs";
|
|
2
|
+
import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
+
import { codecDefinitions } from "@prisma-next/target-postgres/codecs";
|
|
4
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
5
|
+
|
|
6
|
+
//#region src/core/adapter.ts
|
|
7
|
+
const defaultCapabilities = Object.freeze({
|
|
8
|
+
postgres: {
|
|
9
|
+
orderBy: true,
|
|
10
|
+
limit: true,
|
|
11
|
+
lateral: true,
|
|
12
|
+
jsonAgg: true,
|
|
13
|
+
returning: true
|
|
14
|
+
},
|
|
15
|
+
sql: {
|
|
16
|
+
enums: true,
|
|
17
|
+
returning: true,
|
|
18
|
+
defaultInInsert: true
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const parameterizedCodecs = Object.values(codecDefinitions).map((definition) => definition.codec).filter((codec) => codec.paramsSchema !== void 0).map((codec) => Object.freeze({
|
|
22
|
+
codecId: codec.id,
|
|
23
|
+
paramsSchema: codec.paramsSchema,
|
|
24
|
+
...ifDefined("init", codec.init)
|
|
25
|
+
}));
|
|
26
|
+
var PostgresAdapterImpl = class {
|
|
27
|
+
familyId = "sql";
|
|
28
|
+
targetId = "postgres";
|
|
29
|
+
profile;
|
|
30
|
+
codecRegistry = (() => {
|
|
31
|
+
const registry = createCodecRegistry();
|
|
32
|
+
for (const definition of Object.values(codecDefinitions)) registry.register(definition.codec);
|
|
33
|
+
return registry;
|
|
34
|
+
})();
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.profile = Object.freeze({
|
|
37
|
+
id: options?.profileId ?? "postgres/default@1",
|
|
38
|
+
target: "postgres",
|
|
39
|
+
capabilities: defaultCapabilities,
|
|
40
|
+
codecs: () => this.codecRegistry,
|
|
41
|
+
readMarkerStatement: () => ({
|
|
42
|
+
sql: "select core_hash, profile_hash, contract_json, canonical_version, updated_at, app_tag, meta from prisma_contract.marker where id = $1",
|
|
43
|
+
params: [1]
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
parameterizedCodecs() {
|
|
48
|
+
return parameterizedCodecs;
|
|
49
|
+
}
|
|
50
|
+
lower(ast, context) {
|
|
51
|
+
return renderLoweredSql(ast, context.contract);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function createPostgresAdapter(options) {
|
|
55
|
+
return Object.freeze(new PostgresAdapterImpl(options));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { createPostgresAdapter as t };
|
|
60
|
+
//# sourceMappingURL=adapter-hNElNHo4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-hNElNHo4.mjs","names":["parameterizedCodecs: ReadonlyArray<CodecParamsDescriptor>"],"sources":["../src/core/adapter.ts"],"sourcesContent":["import {\n type Adapter,\n type AdapterProfile,\n type AnyQueryAst,\n type CodecParamsDescriptor,\n createCodecRegistry,\n type LowererContext,\n} from '@prisma-next/sql-relational-core/ast';\nimport { codecDefinitions } from '@prisma-next/target-postgres/codecs';\nimport { ifDefined } from '@prisma-next/utils/defined';\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 },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n },\n});\n\ntype AdapterCodec = (typeof codecDefinitions)[keyof typeof codecDefinitions]['codec'];\ntype ParameterizedCodec = AdapterCodec & {\n readonly paramsSchema: NonNullable<AdapterCodec['paramsSchema']>;\n};\n\nconst parameterizedCodecs: ReadonlyArray<CodecParamsDescriptor> = Object.values(codecDefinitions)\n .map((definition) => definition.codec)\n .filter((codec): codec is ParameterizedCodec => codec.paramsSchema !== undefined)\n .map((codec) =>\n Object.freeze({\n codecId: codec.id,\n paramsSchema: codec.paramsSchema,\n ...ifDefined('init', codec.init),\n }),\n );\n\nclass PostgresAdapterImpl\n implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement>\n{\n // These fields make the adapter instance structurally compatible with\n // 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 codecRegistry = (() => {\n const registry = createCodecRegistry();\n for (const definition of Object.values(codecDefinitions)) {\n registry.register(definition.codec);\n }\n return registry;\n })();\n\n constructor(options?: PostgresAdapterOptions) {\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n codecs: () => this.codecRegistry,\n readMarkerStatement: () => ({\n sql: 'select core_hash, profile_hash, contract_json, canonical_version, updated_at, app_tag, meta from prisma_contract.marker where id = $1',\n params: [1],\n }),\n });\n }\n\n parameterizedCodecs(): ReadonlyArray<CodecParamsDescriptor> {\n return parameterizedCodecs;\n }\n\n lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement {\n return renderLoweredSql(ast, context.contract);\n }\n}\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;;;AAaA,MAAM,sBAAsB,OAAO,OAAO;CACxC,UAAU;EACR,SAAS;EACT,OAAO;EACP,SAAS;EACT,SAAS;EACT,WAAW;EACZ;CACD,KAAK;EACH,OAAO;EACP,WAAW;EACX,iBAAiB;EAClB;CACF,CAAC;AAOF,MAAMA,sBAA4D,OAAO,OAAO,iBAAiB,CAC9F,KAAK,eAAe,WAAW,MAAM,CACrC,QAAQ,UAAuC,MAAM,iBAAiB,OAAU,CAChF,KAAK,UACJ,OAAO,OAAO;CACZ,SAAS,MAAM;CACf,cAAc,MAAM;CACpB,GAAG,UAAU,QAAQ,MAAM,KAAK;CACjC,CAAC,CACH;AAEH,IAAM,sBAAN,MAEA;CAGE,AAAS,WAAW;CACpB,AAAS,WAAW;CAEpB,AAAS;CACT,AAAiB,uBAAuB;EACtC,MAAM,WAAW,qBAAqB;AACtC,OAAK,MAAM,cAAc,OAAO,OAAO,iBAAiB,CACtD,UAAS,SAAS,WAAW,MAAM;AAErC,SAAO;KACL;CAEJ,YAAY,SAAkC;AAC5C,OAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,cAAc,KAAK;GACnB,4BAA4B;IAC1B,KAAK;IACL,QAAQ,CAAC,EAAE;IACZ;GACF,CAAC;;CAGJ,sBAA4D;AAC1D,SAAO;;CAGT,MAAM,KAAkB,SAAqE;AAC3F,SAAO,iBAAiB,KAAK,QAAQ,SAAS;;;AAIlD,SAAgB,sBAAsB,SAAkC;AACtE,QAAO,OAAO,OAAO,IAAI,oBAAoB,QAAQ,CAAC"}
|
package/dist/adapter.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-
|
|
1
|
+
import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-CfRPdAk8.mjs";
|
|
2
2
|
import { Adapter, AdapterProfile, AnyQueryAst, CodecParamsDescriptor, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
|
|
4
4
|
//#region src/core/adapter.d.ts
|
|
@@ -9,13 +9,7 @@ declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContra
|
|
|
9
9
|
private readonly codecRegistry;
|
|
10
10
|
constructor(options?: PostgresAdapterOptions);
|
|
11
11
|
parameterizedCodecs(): ReadonlyArray<CodecParamsDescriptor>;
|
|
12
|
-
lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>):
|
|
13
|
-
profileId: string;
|
|
14
|
-
body: Readonly<{
|
|
15
|
-
sql: string;
|
|
16
|
-
params: unknown[];
|
|
17
|
-
}>;
|
|
18
|
-
}>;
|
|
12
|
+
lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
|
|
19
13
|
}
|
|
20
14
|
declare function createPostgresAdapter(options?: PostgresAdapterOptions): Readonly<PostgresAdapterImpl>;
|
|
21
15
|
//#endregion
|
package/dist/adapter.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":[],"mappings":";;;;cA4CM,mBAAA,YACO,QAAQ,aAAa,kBAAkB;;EAD9C,SAAA,QAAA,EAAA,UACJ;EAAmB,SAAA,OAAA,EAOD,cAPC,CAAA,UAAA,CAAA;EAAa,iBAAA,aAAA;EAAkB,WAAA,CAAA,OAAA,CAAA,EAgB5B,sBAhB4B;EAOhC,mBAAA,CAAA,CAAA,EAsBK,aAtBL,CAsBmB,qBAtBnB,CAAA;EASI,KAAA,CAAA,GAAA,EAiBX,WAjBW,EAAA,OAAA,EAiBW,cAjBX,CAiB0B,gBAjB1B,CAAA,CAAA,EAiB8C,wBAjB9C;;AAaC,iBAST,qBAAA,CATS,OAAA,CAAA,EASuB,sBATvB,CAAA,EAS6C,QAT7C,CAS6C,mBAT7C,CAAA"}
|
package/dist/adapter.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;KAEK,6BAAA;;;AAFsB;AAc3B;;;;ACwBA;AAKA;AAUA;AAUa,KDjDD,kBAAA,GCoD6B;EAE5B,SAAA,WAG4B,CAAA,EAAA;IAE5B,SAG4B,OAAA,CAAA,EAAA,MAAA;IAE5B,SAAA,UAG4B,CAAA,EDhEf,6BCgEe;EAE5B,CAAA;EAKG,SAAA,UAAa,CAAA,EAAA,OAG1B;AAUH,CAAA;;;AA/Da,cAAA,UAG4B,EAAA;EAEzB,SAAA,OAAU,EAAA,WAAkB;EAU5B,SAAA,UAAa,EAAA,
|
|
1
|
+
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;KAEK,6BAAA;;;AAFsB;AAc3B;;;;ACwBA;AAKA;AAUA;AAUa,KDjDD,kBAAA,GCoD6B;EAE5B,SAAA,WAG4B,CAAA,EAAA;IAE5B,SAG4B,OAAA,CAAA,EAAA,MAAA;IAE5B,SAAA,UAG4B,CAAA,EDhEf,6BCgEe;EAE5B,CAAA;EAKG,SAAA,UAAa,CAAA,EAAA,OAG1B;AAUH,CAAA;;;AA/Da,cAAA,UAG4B,EAAA;EAEzB,SAAA,OAAU,EAAA,WAAkB;EAU5B,SAAA,UAAa,EAAA,MAAkB;AAU/C,CAAA;AAKa,iBAzBG,UAAA,CA4ByB,MAAA,EAAA,MAAA,CAAA,EA5BG,oBA4BH,GAAA;EAE5B,SAA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G_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
2
|
|
|
3
3
|
//#region src/core/standard-schema.ts
|
|
4
4
|
function isObjectLike(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.mjs","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":["type UnknownRecord = Record<string, unknown>;\n\ntype StandardSchemaJsonSchemaField = {\n readonly output?: unknown;\n};\n\n/**\n * Runtime view of the Standard Schema protocol.\n * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,\n * and `.expression` for an optional TypeScript type expression string (Arktype-specific).\n *\n * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads\n * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.\n */\nexport type StandardSchemaLike = {\n readonly '~standard'?: {\n readonly version?: number;\n readonly jsonSchema?: StandardSchemaJsonSchemaField;\n };\n readonly expression?: unknown;\n};\n\nfunction isObjectLike(value: unknown): value is UnknownRecord {\n return (typeof value === 'object' || typeof value === 'function') && value !== null;\n}\n\nfunction resolveOutputJsonSchemaField(schema: StandardSchemaLike): unknown {\n const jsonSchema = schema['~standard']?.jsonSchema;\n if (!jsonSchema) {\n return undefined;\n }\n\n if (typeof jsonSchema.output === 'function') {\n return jsonSchema.output({\n target: 'draft-07',\n });\n }\n\n return jsonSchema.output;\n}\n\nexport function extractStandardSchemaOutputJsonSchema(\n schema: StandardSchemaLike,\n): UnknownRecord | undefined {\n const outputSchema = resolveOutputJsonSchemaField(schema);\n if (!isObjectLike(outputSchema)) {\n return undefined;\n }\n\n return outputSchema;\n}\n\nexport function extractStandardSchemaTypeExpression(\n schema: StandardSchemaLike,\n): string | undefined {\n const expression = schema.expression;\n if (typeof expression !== 'string') {\n return undefined;\n }\n\n const trimmedExpression = expression.trim();\n if (trimmedExpression.length === 0) {\n return undefined;\n }\n\n return trimmedExpression;\n}\n\nexport function isStandardSchemaLike(value: unknown): value is StandardSchemaLike {\n return isObjectLike(value) && isObjectLike((value as StandardSchemaLike)['~standard']);\n}\n","/**\n * Column type descriptors for Postgres adapter.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring.\n * They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';\nimport type { StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_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 '../core/codec-ids';\nimport {\n extractStandardSchemaOutputJsonSchema,\n extractStandardSchemaTypeExpression,\n isStandardSchemaLike,\n type StandardSchemaLike,\n} from '../core/standard-schema';\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\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\nexport const jsonColumn = {\n codecId: PG_JSON_CODEC_ID,\n nativeType: 'json',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const jsonbColumn = {\n codecId: PG_JSONB_CODEC_ID,\n nativeType: 'jsonb',\n} as const satisfies ColumnTypeDescriptor;\n\ntype JsonSchemaTypeParams = {\n readonly schemaJson: Record<string, unknown>;\n readonly type?: string;\n};\n\nfunction createJsonTypeParams(schema: StandardSchemaLike): JsonSchemaTypeParams {\n const outputSchema = extractStandardSchemaOutputJsonSchema(schema);\n if (!outputSchema) {\n throw new Error('JSON schema must expose ~standard.jsonSchema.output()');\n }\n\n const expression = extractStandardSchemaTypeExpression(schema);\n if (expression) {\n return { schemaJson: outputSchema, type: expression };\n }\n\n return { schemaJson: outputSchema };\n}\n\nfunction createJsonColumnFactory(\n codecId: string,\n nativeType: string,\n staticDescriptor: ColumnTypeDescriptor,\n) {\n return (schema?: StandardSchemaLike): ColumnTypeDescriptor => {\n if (!schema) {\n return staticDescriptor;\n }\n\n if (!isStandardSchemaLike(schema)) {\n throw new Error(`${nativeType}(schema) expects a Standard Schema value`);\n }\n\n return {\n codecId,\n nativeType,\n typeParams: createJsonTypeParams(schema),\n };\n };\n}\n\nconst _json = createJsonColumnFactory(PG_JSON_CODEC_ID, 'json', jsonColumn);\nconst _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, 'jsonb', jsonbColumn);\n\nexport function json(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _json(schema);\n}\n\nexport function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _jsonb(schema);\n}\n\nexport function enumType<const Values extends readonly string[]>(\n name: string,\n values: Values,\n): StorageTypeInstance & { readonly typeParams: { readonly values: Values } } {\n return {\n codecId: PG_ENUM_CODEC_ID,\n nativeType: name,\n typeParams: { values },\n } as const;\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":";;;AAsBA,SAAS,aAAa,OAAwC;AAC5D,SAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,eAAe,UAAU;;AAGjF,SAAS,6BAA6B,QAAqC;CACzE,MAAM,aAAa,OAAO,cAAc;AACxC,KAAI,CAAC,WACH;AAGF,KAAI,OAAO,WAAW,WAAW,WAC/B,QAAO,WAAW,OAAO,EACvB,QAAQ,YACT,CAAC;AAGJ,QAAO,WAAW;;AAGpB,SAAgB,sCACd,QAC2B;CAC3B,MAAM,eAAe,6BAA6B,OAAO;AACzD,KAAI,CAAC,aAAa,aAAa,CAC7B;AAGF,QAAO;;AAGT,SAAgB,oCACd,QACoB;CACpB,MAAM,aAAa,OAAO;AAC1B,KAAI,OAAO,eAAe,SACxB;CAGF,MAAM,oBAAoB,WAAW,MAAM;AAC3C,KAAI,kBAAkB,WAAW,EAC/B;AAGF,QAAO;;AAGT,SAAgB,qBAAqB,OAA6C;AAChF,QAAO,aAAa,MAAM,IAAI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;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;AAGH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;CACb;AAOD,SAAS,qBAAqB,QAAkD;CAC9E,MAAM,eAAe,sCAAsC,OAAO;AAClE,KAAI,CAAC,aACH,OAAM,IAAI,MAAM,wDAAwD;CAG1E,MAAM,aAAa,oCAAoC,OAAO;AAC9D,KAAI,WACF,QAAO;EAAE,YAAY;EAAc,MAAM;EAAY;AAGvD,QAAO,EAAE,YAAY,cAAc;;AAGrC,SAAS,wBACP,SACA,YACA,kBACA;AACA,SAAQ,WAAsD;AAC5D,MAAI,CAAC,OACH,QAAO;AAGT,MAAI,CAAC,qBAAqB,OAAO,CAC/B,OAAM,IAAI,MAAM,GAAG,WAAW,0CAA0C;AAG1E,SAAO;GACL;GACA;GACA,YAAY,qBAAqB,OAAO;GACzC;;;AAIL,MAAM,QAAQ,wBAAwB,kBAAkB,QAAQ,WAAW;AAC3E,MAAM,SAAS,wBAAwB,mBAAmB,SAAS,YAAY;AAE/E,SAAgB,KAAK,QAAmD;AACtE,QAAO,MAAM,OAAO;;AAGtB,SAAgB,MAAM,QAAmD;AACvE,QAAO,OAAO,OAAO;;AAGvB,SAAgB,SACd,MACA,QAC4E;AAC5E,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,WACd,UACA,YACuD;AACvD,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACV"}
|
|
1
|
+
{"version":3,"file":"column-types.mjs","names":[],"sources":["../src/core/standard-schema.ts","../src/exports/column-types.ts"],"sourcesContent":["type UnknownRecord = Record<string, unknown>;\n\ntype StandardSchemaJsonSchemaField = {\n readonly output?: unknown;\n};\n\n/**\n * Runtime view of the Standard Schema protocol.\n * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,\n * and `.expression` for an optional TypeScript type expression string (Arktype-specific).\n *\n * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads\n * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.\n */\nexport type StandardSchemaLike = {\n readonly '~standard'?: {\n readonly version?: number;\n readonly jsonSchema?: StandardSchemaJsonSchemaField;\n };\n readonly expression?: unknown;\n};\n\nfunction isObjectLike(value: unknown): value is UnknownRecord {\n return (typeof value === 'object' || typeof value === 'function') && value !== null;\n}\n\nfunction resolveOutputJsonSchemaField(schema: StandardSchemaLike): unknown {\n const jsonSchema = schema['~standard']?.jsonSchema;\n if (!jsonSchema) {\n return undefined;\n }\n\n if (typeof jsonSchema.output === 'function') {\n return jsonSchema.output({\n target: 'draft-07',\n });\n }\n\n return jsonSchema.output;\n}\n\nexport function extractStandardSchemaOutputJsonSchema(\n schema: StandardSchemaLike,\n): UnknownRecord | undefined {\n const outputSchema = resolveOutputJsonSchemaField(schema);\n if (!isObjectLike(outputSchema)) {\n return undefined;\n }\n\n return outputSchema;\n}\n\nexport function extractStandardSchemaTypeExpression(\n schema: StandardSchemaLike,\n): string | undefined {\n const expression = schema.expression;\n if (typeof expression !== 'string') {\n return undefined;\n }\n\n const trimmedExpression = expression.trim();\n if (trimmedExpression.length === 0) {\n return undefined;\n }\n\n return trimmedExpression;\n}\n\nexport function isStandardSchemaLike(value: unknown): value is StandardSchemaLike {\n return isObjectLike(value) && isObjectLike((value as StandardSchemaLike)['~standard']);\n}\n","/**\n * Column type descriptors for Postgres adapter.\n *\n * These descriptors provide both codecId and nativeType for use in contract authoring.\n * They are derived from the same source of truth as codec definitions and manifests.\n */\n\nimport type { ColumnTypeDescriptor } from '@prisma-next/contract-authoring';\nimport type { StorageTypeInstance } from '@prisma-next/sql-contract/types';\nimport {\n PG_BIT_CODEC_ID,\n PG_BOOL_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 {\n extractStandardSchemaOutputJsonSchema,\n extractStandardSchemaTypeExpression,\n isStandardSchemaLike,\n type StandardSchemaLike,\n} from '../core/standard-schema';\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\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\nexport const jsonColumn = {\n codecId: PG_JSON_CODEC_ID,\n nativeType: 'json',\n} as const satisfies ColumnTypeDescriptor;\n\nexport const jsonbColumn = {\n codecId: PG_JSONB_CODEC_ID,\n nativeType: 'jsonb',\n} as const satisfies ColumnTypeDescriptor;\n\ntype JsonSchemaTypeParams = {\n readonly schemaJson: Record<string, unknown>;\n readonly type?: string;\n};\n\nfunction createJsonTypeParams(schema: StandardSchemaLike): JsonSchemaTypeParams {\n const outputSchema = extractStandardSchemaOutputJsonSchema(schema);\n if (!outputSchema) {\n throw new Error('JSON schema must expose ~standard.jsonSchema.output()');\n }\n\n const expression = extractStandardSchemaTypeExpression(schema);\n if (expression) {\n return { schemaJson: outputSchema, type: expression };\n }\n\n return { schemaJson: outputSchema };\n}\n\nfunction createJsonColumnFactory(\n codecId: string,\n nativeType: string,\n staticDescriptor: ColumnTypeDescriptor,\n) {\n return (schema?: StandardSchemaLike): ColumnTypeDescriptor => {\n if (!schema) {\n return staticDescriptor;\n }\n\n if (!isStandardSchemaLike(schema)) {\n throw new Error(`${nativeType}(schema) expects a Standard Schema value`);\n }\n\n return {\n codecId,\n nativeType,\n typeParams: createJsonTypeParams(schema),\n };\n };\n}\n\nconst _json = createJsonColumnFactory(PG_JSON_CODEC_ID, 'json', jsonColumn);\nconst _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, 'jsonb', jsonbColumn);\n\nexport function json(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _json(schema);\n}\n\nexport function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor {\n return _jsonb(schema);\n}\n\nexport function enumType<const Values extends readonly string[]>(\n name: string,\n values: Values,\n): StorageTypeInstance & { readonly typeParams: { readonly values: Values } } {\n return {\n codecId: PG_ENUM_CODEC_ID,\n nativeType: name,\n typeParams: { values },\n } as const;\n}\n\nexport function enumColumn<TypeName extends string>(\n typeName: TypeName,\n nativeType: string,\n): ColumnTypeDescriptor & { readonly typeRef: TypeName } {\n return {\n codecId: PG_EN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;AAG1E,SAAO;GACL;GACA;GACA,YAAY,qBAAqB,OAAO;GACzC;;;AAIL,MAAM,QAAQ,wBAAwB,kBAAkB,QAAQ,WAAW;AAC3E,MAAM,SAAS,wBAAwB,mBAAmB,SAAS,YAAY;AAE/E,SAAgB,KAAK,QAAmD;AACtE,QAAO,MAAM,OAAO;;AAGtB,SAAgB,MAAM,QAAmD;AACvE,QAAO,OAAO,OAAO;;AAGvB,SAAgB,SACd,MACA,QAC4E;AAC5E,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,WACd,UACA,YACuD;AACvD,QAAO;EACL,SAAS;EACT;EACA,SAAS;EACV"}
|
package/dist/control.d.mts
CHANGED
|
@@ -1,75 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
2
|
+
import { parsePostgresDefault } from "@prisma-next/target-postgres/default-normalizer";
|
|
3
|
+
import { normalizeSchemaNativeType } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
2
4
|
import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
|
|
3
5
|
|
|
4
|
-
//#region src/core/sql-utils.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Shared SQL utility functions for the Postgres adapter.
|
|
8
|
-
*
|
|
9
|
-
* These functions handle safe SQL identifier and literal escaping
|
|
10
|
-
* with security validations to prevent injection and encoding issues.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Error thrown when an invalid SQL identifier or literal is detected.
|
|
14
|
-
* Boundary layers map this to structured envelopes.
|
|
15
|
-
*/
|
|
16
|
-
declare class SqlEscapeError extends Error {
|
|
17
|
-
readonly value: string;
|
|
18
|
-
readonly kind: 'identifier' | 'literal';
|
|
19
|
-
constructor(message: string, value: string, kind: 'identifier' | 'literal');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Validates and quotes a PostgreSQL identifier (table, column, type, schema names).
|
|
23
|
-
*
|
|
24
|
-
* Security validations:
|
|
25
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
26
|
-
* - Rejects empty identifiers
|
|
27
|
-
* - Warns on identifiers exceeding PostgreSQL's 63-character limit
|
|
28
|
-
*
|
|
29
|
-
* @throws {SqlEscapeError} If the identifier contains null bytes or is empty
|
|
30
|
-
*/
|
|
31
|
-
declare function quoteIdentifier(identifier: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* Escapes a string literal for safe use in SQL statements.
|
|
34
|
-
*
|
|
35
|
-
* Security validations:
|
|
36
|
-
* - Rejects null bytes which could cause truncation or unexpected behavior
|
|
37
|
-
*
|
|
38
|
-
* Note: This assumes PostgreSQL's `standard_conforming_strings` is ON (default since PG 9.1).
|
|
39
|
-
* Backslashes are treated as literal characters, not escape sequences.
|
|
40
|
-
*
|
|
41
|
-
* @throws {SqlEscapeError} If the value contains null bytes
|
|
42
|
-
*/
|
|
43
|
-
declare function escapeLiteral(value: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Builds a qualified name (schema.object) with proper quoting.
|
|
46
|
-
*/
|
|
47
|
-
declare function qualifyName(schemaName: string, objectName: string): string;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/core/default-normalizer.d.ts
|
|
50
|
-
/**
|
|
51
|
-
* Parses a raw Postgres column default expression into a normalized ColumnDefault.
|
|
52
|
-
* This enables semantic comparison between contract defaults and introspected schema defaults.
|
|
53
|
-
*
|
|
54
|
-
* Used by the migration diff layer to normalize raw database defaults during comparison,
|
|
55
|
-
* keeping the introspection layer focused on faithful data capture.
|
|
56
|
-
*
|
|
57
|
-
* @param rawDefault - Raw default expression from information_schema.columns.column_default
|
|
58
|
-
* @param nativeType - Native column type, used for type-aware parsing (bigint tagging, JSON detection)
|
|
59
|
-
* @returns Normalized ColumnDefault or undefined if the expression cannot be parsed
|
|
60
|
-
*/
|
|
61
|
-
declare function parsePostgresDefault(rawDefault: string, nativeType?: string): ColumnDefault | undefined;
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/core/control-adapter.d.ts
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Normalizes a Postgres schema native type to its canonical form for comparison.
|
|
67
|
-
*
|
|
68
|
-
* Uses a pre-computed lookup map for simple prefix replacements (O(1))
|
|
69
|
-
* and handles complex temporal type normalization separately.
|
|
70
|
-
*/
|
|
71
|
-
declare function normalizeSchemaNativeType(nativeType: string): string;
|
|
72
|
-
//#endregion
|
|
73
6
|
//#region src/exports/control.d.ts
|
|
74
7
|
declare const postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'>;
|
|
75
8
|
//#endregion
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;cAgBM,2BAA2B"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,137 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as renderLoweredSql } from "./sql-renderer-pEaSP82_.mjs";
|
|
2
|
+
import { r as pgEnumControlHooks, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-RTDzyrae.mjs";
|
|
3
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
4
|
+
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
5
|
+
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
6
|
+
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
4
7
|
import { builtinGeneratorRegistryMetadata, resolveBuiltinGeneratedColumnDescriptor } from "@prisma-next/ids";
|
|
5
8
|
|
|
6
|
-
//#region src/core/default-normalizer.ts
|
|
7
|
-
/**
|
|
8
|
-
* Pre-compiled regex patterns for performance.
|
|
9
|
-
* These are compiled once at module load time rather than on each function call.
|
|
10
|
-
*/
|
|
11
|
-
const NEXTVAL_PATTERN = /^nextval\s*\(/i;
|
|
12
|
-
const NOW_FUNCTION_PATTERN = /^(now\s*\(\s*\)|CURRENT_TIMESTAMP)$/i;
|
|
13
|
-
const CLOCK_TIMESTAMP_PATTERN = /^clock_timestamp\s*\(\s*\)$/i;
|
|
14
|
-
const TIMESTAMP_CAST_SUFFIX = /::timestamp(?:tz|\s+(?:with|without)\s+time\s+zone)?$/i;
|
|
15
|
-
const TEXT_CAST_SUFFIX = /::text$/i;
|
|
16
|
-
const NOW_LITERAL_PATTERN = /^'now'$/i;
|
|
17
|
-
const UUID_PATTERN = /^gen_random_uuid\s*\(\s*\)$/i;
|
|
18
|
-
const UUID_OSSP_PATTERN = /^uuid_generate_v4\s*\(\s*\)$/i;
|
|
19
|
-
const NULL_PATTERN = /^NULL(?:::.+)?$/i;
|
|
20
|
-
const TRUE_PATTERN = /^true$/i;
|
|
21
|
-
const FALSE_PATTERN = /^false$/i;
|
|
22
|
-
const NUMERIC_PATTERN = /^-?\d+(\.\d+)?$/;
|
|
23
|
-
const STRING_LITERAL_PATTERN = /^'((?:[^']|'')*)'(?:::(?:"[^"]+"|[\w\s]+)(?:\(\d+\))?)?$/;
|
|
24
|
-
/**
|
|
25
|
-
* Returns the canonical expression for a timestamp default function, or undefined
|
|
26
|
-
* if the expression is not a recognized timestamp default.
|
|
27
|
-
*
|
|
28
|
-
* Keeps now()/CURRENT_TIMESTAMP and clock_timestamp() distinct:
|
|
29
|
-
* - now(), CURRENT_TIMESTAMP, ('now'::text)::timestamp... → 'now()'
|
|
30
|
-
* - clock_timestamp(), clock_timestamp()::timestamptz → 'clock_timestamp()'
|
|
31
|
-
*
|
|
32
|
-
* These are semantically different in Postgres: now() returns the transaction
|
|
33
|
-
* start time (constant within a transaction), while clock_timestamp() returns
|
|
34
|
-
* the actual wall-clock time (can differ across rows in a single INSERT).
|
|
35
|
-
*/
|
|
36
|
-
function canonicalizeTimestampDefault(expr) {
|
|
37
|
-
if (NOW_FUNCTION_PATTERN.test(expr)) return "now()";
|
|
38
|
-
if (CLOCK_TIMESTAMP_PATTERN.test(expr)) return "clock_timestamp()";
|
|
39
|
-
if (!TIMESTAMP_CAST_SUFFIX.test(expr)) return void 0;
|
|
40
|
-
let inner = expr.replace(TIMESTAMP_CAST_SUFFIX, "").trim();
|
|
41
|
-
if (inner.startsWith("(") && inner.endsWith(")")) inner = inner.slice(1, -1).trim();
|
|
42
|
-
if (NOW_FUNCTION_PATTERN.test(inner)) return "now()";
|
|
43
|
-
if (CLOCK_TIMESTAMP_PATTERN.test(inner)) return "clock_timestamp()";
|
|
44
|
-
inner = inner.replace(TEXT_CAST_SUFFIX, "").trim();
|
|
45
|
-
if (NOW_LITERAL_PATTERN.test(inner)) return "now()";
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Parses a raw Postgres column default expression into a normalized ColumnDefault.
|
|
49
|
-
* This enables semantic comparison between contract defaults and introspected schema defaults.
|
|
50
|
-
*
|
|
51
|
-
* Used by the migration diff layer to normalize raw database defaults during comparison,
|
|
52
|
-
* keeping the introspection layer focused on faithful data capture.
|
|
53
|
-
*
|
|
54
|
-
* @param rawDefault - Raw default expression from information_schema.columns.column_default
|
|
55
|
-
* @param nativeType - Native column type, used for type-aware parsing (bigint tagging, JSON detection)
|
|
56
|
-
* @returns Normalized ColumnDefault or undefined if the expression cannot be parsed
|
|
57
|
-
*/
|
|
58
|
-
function parsePostgresDefault(rawDefault, nativeType) {
|
|
59
|
-
const trimmed = rawDefault.trim();
|
|
60
|
-
const normalizedType = nativeType?.toLowerCase();
|
|
61
|
-
const isBigInt = normalizedType === "bigint" || normalizedType === "int8";
|
|
62
|
-
if (NEXTVAL_PATTERN.test(trimmed)) return {
|
|
63
|
-
kind: "function",
|
|
64
|
-
expression: "autoincrement()"
|
|
65
|
-
};
|
|
66
|
-
const canonicalTimestamp = canonicalizeTimestampDefault(trimmed);
|
|
67
|
-
if (canonicalTimestamp) return {
|
|
68
|
-
kind: "function",
|
|
69
|
-
expression: canonicalTimestamp
|
|
70
|
-
};
|
|
71
|
-
if (UUID_PATTERN.test(trimmed)) return {
|
|
72
|
-
kind: "function",
|
|
73
|
-
expression: "gen_random_uuid()"
|
|
74
|
-
};
|
|
75
|
-
if (UUID_OSSP_PATTERN.test(trimmed)) return {
|
|
76
|
-
kind: "function",
|
|
77
|
-
expression: "gen_random_uuid()"
|
|
78
|
-
};
|
|
79
|
-
if (NULL_PATTERN.test(trimmed)) return {
|
|
80
|
-
kind: "literal",
|
|
81
|
-
value: null
|
|
82
|
-
};
|
|
83
|
-
if (TRUE_PATTERN.test(trimmed)) return {
|
|
84
|
-
kind: "literal",
|
|
85
|
-
value: true
|
|
86
|
-
};
|
|
87
|
-
if (FALSE_PATTERN.test(trimmed)) return {
|
|
88
|
-
kind: "literal",
|
|
89
|
-
value: false
|
|
90
|
-
};
|
|
91
|
-
if (NUMERIC_PATTERN.test(trimmed)) {
|
|
92
|
-
const num = Number(trimmed);
|
|
93
|
-
if (!Number.isFinite(num)) return void 0;
|
|
94
|
-
if (isBigInt && !Number.isSafeInteger(num)) return {
|
|
95
|
-
kind: "literal",
|
|
96
|
-
value: trimmed
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
kind: "literal",
|
|
100
|
-
value: num
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const stringMatch = trimmed.match(STRING_LITERAL_PATTERN);
|
|
104
|
-
if (stringMatch?.[1] !== void 0) {
|
|
105
|
-
const unescaped = stringMatch[1].replace(/''/g, "'");
|
|
106
|
-
if (normalizedType === "json" || normalizedType === "jsonb") try {
|
|
107
|
-
return {
|
|
108
|
-
kind: "literal",
|
|
109
|
-
value: JSON.parse(unescaped)
|
|
110
|
-
};
|
|
111
|
-
} catch {}
|
|
112
|
-
if (isBigInt && NUMERIC_PATTERN.test(unescaped)) {
|
|
113
|
-
const num = Number(unescaped);
|
|
114
|
-
if (Number.isSafeInteger(num)) return {
|
|
115
|
-
kind: "literal",
|
|
116
|
-
value: num
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
kind: "literal",
|
|
120
|
-
value: unescaped
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
kind: "literal",
|
|
125
|
-
value: unescaped
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
kind: "function",
|
|
130
|
-
expression: trimmed
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
//#endregion
|
|
135
9
|
//#region src/core/control-adapter.ts
|
|
136
10
|
/**
|
|
137
11
|
* Postgres control plane adapter for control-plane operations like introspection.
|
|
@@ -144,13 +18,24 @@ var PostgresControlAdapter = class {
|
|
|
144
18
|
* Target-specific normalizer for raw Postgres default expressions.
|
|
145
19
|
* Used by schema verification to normalize raw defaults before comparison.
|
|
146
20
|
*/
|
|
147
|
-
normalizeDefault = parsePostgresDefault;
|
|
21
|
+
normalizeDefault = parsePostgresDefault$1;
|
|
148
22
|
/**
|
|
149
23
|
* Target-specific normalizer for Postgres schema native type names.
|
|
150
24
|
* Used by schema verification to normalize introspected type names
|
|
151
25
|
* before comparison with contract native types.
|
|
152
26
|
*/
|
|
153
|
-
normalizeNativeType = normalizeSchemaNativeType;
|
|
27
|
+
normalizeNativeType = normalizeSchemaNativeType$1;
|
|
28
|
+
/**
|
|
29
|
+
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
30
|
+
*
|
|
31
|
+
* Delegates to the shared `renderLoweredSql` renderer so the control adapter
|
|
32
|
+
* emits byte-identical SQL to `PostgresAdapterImpl.lower()` for the same AST
|
|
33
|
+
* and contract. Used at migration plan/emit time (e.g. by `dataTransform`)
|
|
34
|
+
* without instantiating the runtime adapter.
|
|
35
|
+
*/
|
|
36
|
+
lower(ast, context) {
|
|
37
|
+
return renderLoweredSql(ast, context.contract);
|
|
38
|
+
}
|
|
154
39
|
/**
|
|
155
40
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
156
41
|
*
|
|
@@ -407,32 +292,6 @@ var PostgresControlAdapter = class {
|
|
|
407
292
|
return ((await driver.query("SELECT version() AS version", [])).rows[0]?.version ?? "").match(/PostgreSQL (\d+\.\d+)/)?.[1] ?? "unknown";
|
|
408
293
|
}
|
|
409
294
|
};
|
|
410
|
-
/**
|
|
411
|
-
* Pre-computed lookup map for simple prefix-based type normalization.
|
|
412
|
-
* Maps short Postgres type names to their canonical SQL names.
|
|
413
|
-
* Using a Map for O(1) lookup instead of multiple startsWith checks.
|
|
414
|
-
*/
|
|
415
|
-
const TYPE_PREFIX_MAP = new Map([
|
|
416
|
-
["varchar", "character varying"],
|
|
417
|
-
["bpchar", "character"],
|
|
418
|
-
["varbit", "bit varying"]
|
|
419
|
-
]);
|
|
420
|
-
/**
|
|
421
|
-
* Normalizes a Postgres schema native type to its canonical form for comparison.
|
|
422
|
-
*
|
|
423
|
-
* Uses a pre-computed lookup map for simple prefix replacements (O(1))
|
|
424
|
-
* and handles complex temporal type normalization separately.
|
|
425
|
-
*/
|
|
426
|
-
function normalizeSchemaNativeType(nativeType) {
|
|
427
|
-
const trimmed = nativeType.trim();
|
|
428
|
-
for (const [prefix, replacement] of TYPE_PREFIX_MAP) if (trimmed.startsWith(prefix)) return replacement + trimmed.slice(prefix.length);
|
|
429
|
-
if (trimmed.includes(" with time zone")) {
|
|
430
|
-
if (trimmed.startsWith("timestamp")) return `timestamptz${trimmed.slice(9).replace(" with time zone", "")}`;
|
|
431
|
-
if (trimmed.startsWith("time")) return `timetz${trimmed.slice(4).replace(" with time zone", "")}`;
|
|
432
|
-
}
|
|
433
|
-
if (trimmed.includes(" without time zone")) return trimmed.replace(" without time zone", "");
|
|
434
|
-
return trimmed;
|
|
435
|
-
}
|
|
436
295
|
function normalizeFormattedType(formattedType, dataType, udtName) {
|
|
437
296
|
if (formattedType === "integer") return "int4";
|
|
438
297
|
if (formattedType === "smallint") return "int2";
|
|
@@ -738,7 +597,7 @@ const postgresAdapterDescriptor = {
|
|
|
738
597
|
defaultFunctionRegistry: createPostgresDefaultFunctionRegistry(),
|
|
739
598
|
generatorDescriptors: createPostgresMutationDefaultGeneratorDescriptors()
|
|
740
599
|
},
|
|
741
|
-
create() {
|
|
600
|
+
create(_stack) {
|
|
742
601
|
return new PostgresControlAdapter();
|
|
743
602
|
}
|
|
744
603
|
};
|