@prisma-next/adapter-postgres 0.4.1 → 0.5.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.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-BB9XPAFi.mjs → descriptor-meta-RTDzyrae.mjs} +7 -7
- package/dist/descriptor-meta-RTDzyrae.mjs.map +1 -0
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +7 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/{adapter-Du9Hr9Rl.mjs → sql-renderer-pEaSP82_.mjs} +102 -100
- package/dist/sql-renderer-pEaSP82_.mjs.map +1 -0
- package/dist/{types-TyL62f9Y.d.mts → types-CfRPdAk8.d.mts} +1 -1
- package/dist/{types-TyL62f9Y.d.mts.map → types-CfRPdAk8.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +21 -16
- package/src/core/adapter.ts +4 -625
- package/src/core/control-adapter.ts +21 -47
- package/src/core/descriptor-meta.ts +5 -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/runtime.ts +3 -3
- package/dist/adapter-Du9Hr9Rl.mjs.map +0 -1
- package/dist/codec-ids-5g4Gwrgm.mjs +0 -29
- package/dist/codec-ids-5g4Gwrgm.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-DiPlMi3-.mjs +0 -385
- package/dist/codecs-DiPlMi3-.mjs.map +0 -1
- package/dist/descriptor-meta-BB9XPAFi.mjs.map +0 -1
- package/dist/sql-utils-DkUJyZmA.mjs +0 -78
- package/dist/sql-utils-DkUJyZmA.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
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
|
|
2
2
|
import type { ControlDriverInstance } from '@prisma-next/framework-components/control';
|
|
3
|
+
import type {
|
|
4
|
+
AnyQueryAst,
|
|
5
|
+
LoweredStatement,
|
|
6
|
+
LowererContext,
|
|
7
|
+
} from '@prisma-next/sql-relational-core/ast';
|
|
3
8
|
import type {
|
|
4
9
|
DependencyIR,
|
|
5
10
|
PrimaryKey,
|
|
@@ -11,9 +16,12 @@ import type {
|
|
|
11
16
|
SqlTableIR,
|
|
12
17
|
SqlUniqueIR,
|
|
13
18
|
} from '@prisma-next/sql-schema-ir/types';
|
|
19
|
+
import { parsePostgresDefault } from '@prisma-next/target-postgres/default-normalizer';
|
|
20
|
+
import { normalizeSchemaNativeType } from '@prisma-next/target-postgres/native-type-normalizer';
|
|
14
21
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
15
|
-
import { parsePostgresDefault } from './default-normalizer';
|
|
16
22
|
import { pgEnumControlHooks } from './enum-control-hooks';
|
|
23
|
+
import { renderLoweredSql } from './sql-renderer';
|
|
24
|
+
import type { PostgresContract } from './types';
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
* Postgres control plane adapter for control-plane operations like introspection.
|
|
@@ -36,6 +44,18 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
36
44
|
*/
|
|
37
45
|
readonly normalizeNativeType = normalizeSchemaNativeType;
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
49
|
+
*
|
|
50
|
+
* Delegates to the shared `renderLoweredSql` renderer so the control adapter
|
|
51
|
+
* emits byte-identical SQL to `PostgresAdapterImpl.lower()` for the same AST
|
|
52
|
+
* and contract. Used at migration plan/emit time (e.g. by `dataTransform`)
|
|
53
|
+
* without instantiating the runtime adapter.
|
|
54
|
+
*/
|
|
55
|
+
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement {
|
|
56
|
+
return renderLoweredSql(ast, context.contract as PostgresContract);
|
|
57
|
+
}
|
|
58
|
+
|
|
39
59
|
/**
|
|
40
60
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
41
61
|
*
|
|
@@ -453,52 +473,6 @@ export class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
453
473
|
}
|
|
454
474
|
}
|
|
455
475
|
|
|
456
|
-
/**
|
|
457
|
-
* Pre-computed lookup map for simple prefix-based type normalization.
|
|
458
|
-
* Maps short Postgres type names to their canonical SQL names.
|
|
459
|
-
* Using a Map for O(1) lookup instead of multiple startsWith checks.
|
|
460
|
-
*/
|
|
461
|
-
const TYPE_PREFIX_MAP: ReadonlyMap<string, string> = new Map([
|
|
462
|
-
['varchar', 'character varying'],
|
|
463
|
-
['bpchar', 'character'],
|
|
464
|
-
['varbit', 'bit varying'],
|
|
465
|
-
]);
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Normalizes a Postgres schema native type to its canonical form for comparison.
|
|
469
|
-
*
|
|
470
|
-
* Uses a pre-computed lookup map for simple prefix replacements (O(1))
|
|
471
|
-
* and handles complex temporal type normalization separately.
|
|
472
|
-
*/
|
|
473
|
-
export function normalizeSchemaNativeType(nativeType: string): string {
|
|
474
|
-
const trimmed = nativeType.trim();
|
|
475
|
-
|
|
476
|
-
// Fast path: check simple prefix replacements using the lookup map
|
|
477
|
-
for (const [prefix, replacement] of TYPE_PREFIX_MAP) {
|
|
478
|
-
if (trimmed.startsWith(prefix)) {
|
|
479
|
-
return replacement + trimmed.slice(prefix.length);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// Temporal types with time zone handling
|
|
484
|
-
// Check for 'with time zone' suffix first (more specific)
|
|
485
|
-
if (trimmed.includes(' with time zone')) {
|
|
486
|
-
if (trimmed.startsWith('timestamp')) {
|
|
487
|
-
return `timestamptz${trimmed.slice(9).replace(' with time zone', '')}`;
|
|
488
|
-
}
|
|
489
|
-
if (trimmed.startsWith('time')) {
|
|
490
|
-
return `timetz${trimmed.slice(4).replace(' with time zone', '')}`;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
// Handle 'without time zone' suffix - just strip it
|
|
495
|
-
if (trimmed.includes(' without time zone')) {
|
|
496
|
-
return trimmed.replace(' without time zone', '');
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
return trimmed;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
476
|
function normalizeFormattedType(formattedType: string, dataType: string, udtName: string): string {
|
|
503
477
|
if (formattedType === 'integer') {
|
|
504
478
|
return 'int4';
|
|
@@ -29,8 +29,8 @@ import {
|
|
|
29
29
|
SQL_TEXT_CODEC_ID,
|
|
30
30
|
SQL_TIMESTAMP_CODEC_ID,
|
|
31
31
|
SQL_VARCHAR_CODEC_ID,
|
|
32
|
-
} from '
|
|
33
|
-
import { codecDefinitions } from '
|
|
32
|
+
} from '@prisma-next/target-postgres/codec-ids';
|
|
33
|
+
import { codecDefinitions } from '@prisma-next/target-postgres/codecs';
|
|
34
34
|
import { pgEnumControlHooks } from './enum-control-hooks';
|
|
35
35
|
|
|
36
36
|
// ============================================================================
|
|
@@ -40,7 +40,7 @@ import { pgEnumControlHooks } from './enum-control-hooks';
|
|
|
40
40
|
/** Creates a type import spec for codec types */
|
|
41
41
|
const codecTypeImport = (named: string) =>
|
|
42
42
|
({
|
|
43
|
-
package: '@prisma-next/
|
|
43
|
+
package: '@prisma-next/target-postgres/codec-types',
|
|
44
44
|
named,
|
|
45
45
|
alias: named,
|
|
46
46
|
}) as const;
|
|
@@ -164,13 +164,13 @@ export const postgresAdapterDescriptorMeta = {
|
|
|
164
164
|
codecTypes: {
|
|
165
165
|
codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
|
|
166
166
|
import: {
|
|
167
|
-
package: '@prisma-next/
|
|
167
|
+
package: '@prisma-next/target-postgres/codec-types',
|
|
168
168
|
named: 'CodecTypes',
|
|
169
169
|
alias: 'PgTypes',
|
|
170
170
|
},
|
|
171
171
|
typeImports: [
|
|
172
172
|
{
|
|
173
|
-
package: '@prisma-next/
|
|
173
|
+
package: '@prisma-next/target-postgres/codec-types',
|
|
174
174
|
named: 'JsonValue',
|
|
175
175
|
alias: 'JsonValue',
|
|
176
176
|
},
|
|
@@ -3,8 +3,13 @@ import type { CodecControlHooks, SqlMigrationPlanOperation } from '@prisma-next/
|
|
|
3
3
|
import { arraysEqual } from '@prisma-next/family-sql/schema-verify';
|
|
4
4
|
import type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';
|
|
5
5
|
import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
6
|
-
import { PG_ENUM_CODEC_ID } from '
|
|
7
|
-
import {
|
|
6
|
+
import { PG_ENUM_CODEC_ID } from '@prisma-next/target-postgres/codec-ids';
|
|
7
|
+
import {
|
|
8
|
+
escapeLiteral,
|
|
9
|
+
qualifyName,
|
|
10
|
+
quoteIdentifier,
|
|
11
|
+
validateEnumValueLength,
|
|
12
|
+
} from '@prisma-next/target-postgres/sql-utils';
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* Postgres enum control hooks.
|
|
@@ -42,7 +42,8 @@ export function compileJsonSchemaValidator(schema: Record<string, unknown>): Jso
|
|
|
42
42
|
return { valid: true };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
// biome-ignore lint/style/noNonNullAssertion: Ajv guarantees `errors` is populated whenever `validate(...)` returns false.
|
|
46
|
+
const errors: JsonSchemaValidationError[] = validate.errors!.map((err) => ({
|
|
46
47
|
path: err.instancePath || '/',
|
|
47
48
|
message: err.message ?? 'unknown validation error',
|
|
48
49
|
keyword: err.keyword,
|