@prisma-next/adapter-postgres 0.4.0-dev.9 → 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.
Files changed (54) hide show
  1. package/dist/adapter-hNElNHo4.mjs +60 -0
  2. package/dist/adapter-hNElNHo4.mjs.map +1 -0
  3. package/dist/adapter.d.mts +2 -8
  4. package/dist/adapter.d.mts.map +1 -1
  5. package/dist/adapter.mjs +1 -1
  6. package/dist/column-types.d.mts.map +1 -1
  7. package/dist/column-types.mjs +1 -1
  8. package/dist/column-types.mjs.map +1 -1
  9. package/dist/control.d.mts +3 -70
  10. package/dist/control.d.mts.map +1 -1
  11. package/dist/control.mjs +19 -160
  12. package/dist/control.mjs.map +1 -1
  13. package/dist/{descriptor-meta-DemWrTfB.mjs → descriptor-meta-RTDzyrae.mjs} +33 -9
  14. package/dist/descriptor-meta-RTDzyrae.mjs.map +1 -0
  15. package/dist/operation-types.d.mts +21 -0
  16. package/dist/operation-types.d.mts.map +1 -0
  17. package/dist/operation-types.mjs +1 -0
  18. package/dist/runtime.d.mts +1 -1
  19. package/dist/runtime.mjs +8 -7
  20. package/dist/runtime.mjs.map +1 -1
  21. package/dist/{adapter-7pXt8ej9.mjs → sql-renderer-pEaSP82_.mjs} +102 -101
  22. package/dist/sql-renderer-pEaSP82_.mjs.map +1 -0
  23. package/dist/{types-DxaTd7aP.d.mts → types-CfRPdAk8.d.mts} +1 -1
  24. package/dist/{types-DxaTd7aP.d.mts.map → types-CfRPdAk8.d.mts.map} +1 -1
  25. package/dist/types.d.mts +1 -1
  26. package/package.json +22 -16
  27. package/src/core/adapter.ts +4 -626
  28. package/src/core/control-adapter.ts +21 -47
  29. package/src/core/descriptor-meta.ts +25 -5
  30. package/src/core/enum-control-hooks.ts +7 -2
  31. package/src/core/json-schema-validator.ts +2 -1
  32. package/src/core/sql-renderer.ts +710 -0
  33. package/src/exports/column-types.ts +1 -1
  34. package/src/exports/control.ts +9 -4
  35. package/src/exports/operation-types.ts +1 -0
  36. package/src/exports/runtime.ts +5 -4
  37. package/src/types/operation-types.ts +11 -0
  38. package/dist/adapter-7pXt8ej9.mjs.map +0 -1
  39. package/dist/codec-ids-BwjcIf74.mjs +0 -29
  40. package/dist/codec-ids-BwjcIf74.mjs.map +0 -1
  41. package/dist/codec-types.d.mts +0 -107
  42. package/dist/codec-types.d.mts.map +0 -1
  43. package/dist/codec-types.mjs +0 -3
  44. package/dist/codecs-C3wlpdV7.mjs +0 -385
  45. package/dist/codecs-C3wlpdV7.mjs.map +0 -1
  46. package/dist/descriptor-meta-DemWrTfB.mjs.map +0 -1
  47. package/dist/sql-utils-CSfAGEwF.mjs +0 -78
  48. package/dist/sql-utils-CSfAGEwF.mjs.map +0 -1
  49. package/src/core/codec-ids.ts +0 -30
  50. package/src/core/codecs.ts +0 -645
  51. package/src/core/default-normalizer.ts +0 -145
  52. package/src/core/json-schema-type-expression.ts +0 -131
  53. package/src/core/sql-utils.ts +0 -111
  54. 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';
@@ -1,4 +1,5 @@
1
1
  import type { CodecControlHooks, ExpandNativeTypeInput } from '@prisma-next/family-sql/control';
2
+ import type { SqlOperationDescriptor } from '@prisma-next/sql-operations';
2
3
  import {
3
4
  PG_BIT_CODEC_ID,
4
5
  PG_BOOL_CODEC_ID,
@@ -28,8 +29,8 @@ import {
28
29
  SQL_TEXT_CODEC_ID,
29
30
  SQL_TIMESTAMP_CODEC_ID,
30
31
  SQL_VARCHAR_CODEC_ID,
31
- } from './codec-ids';
32
- import { codecDefinitions } from './codecs';
32
+ } from '@prisma-next/target-postgres/codec-ids';
33
+ import { codecDefinitions } from '@prisma-next/target-postgres/codecs';
33
34
  import { pgEnumControlHooks } from './enum-control-hooks';
34
35
 
35
36
  // ============================================================================
@@ -39,7 +40,7 @@ import { pgEnumControlHooks } from './enum-control-hooks';
39
40
  /** Creates a type import spec for codec types */
40
41
  const codecTypeImport = (named: string) =>
41
42
  ({
42
- package: '@prisma-next/adapter-postgres/codec-types',
43
+ package: '@prisma-next/target-postgres/codec-types',
43
44
  named,
44
45
  alias: named,
45
46
  }) as const;
@@ -127,6 +128,18 @@ const identityHooks: CodecControlHooks = { expandNativeType: ({ nativeType }) =>
127
128
  // Descriptor metadata
128
129
  // ============================================================================
129
130
 
131
+ export const postgresQueryOperations: readonly SqlOperationDescriptor[] = [
132
+ {
133
+ method: 'ilike',
134
+ args: [
135
+ { traits: ['textual'], nullable: false },
136
+ { codecId: PG_TEXT_CODEC_ID, nullable: false },
137
+ ],
138
+ returns: { codecId: PG_BOOL_CODEC_ID, nullable: false },
139
+ lowering: { targetFamily: 'sql', strategy: 'infix', template: '{{self}} ILIKE {{arg0}}' },
140
+ },
141
+ ];
142
+
130
143
  export const postgresAdapterDescriptorMeta = {
131
144
  kind: 'adapter',
132
145
  familyId: 'sql',
@@ -151,13 +164,13 @@ export const postgresAdapterDescriptorMeta = {
151
164
  codecTypes: {
152
165
  codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
153
166
  import: {
154
- package: '@prisma-next/adapter-postgres/codec-types',
167
+ package: '@prisma-next/target-postgres/codec-types',
155
168
  named: 'CodecTypes',
156
169
  alias: 'PgTypes',
157
170
  },
158
171
  typeImports: [
159
172
  {
160
- package: '@prisma-next/adapter-postgres/codec-types',
173
+ package: '@prisma-next/target-postgres/codec-types',
161
174
  named: 'JsonValue',
162
175
  alias: 'JsonValue',
163
176
  },
@@ -255,5 +268,12 @@ export const postgresAdapterDescriptorMeta = {
255
268
  { typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },
256
269
  { typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },
257
270
  ],
271
+ queryOperationTypes: {
272
+ import: {
273
+ package: '@prisma-next/adapter-postgres/operation-types',
274
+ named: 'QueryOperationTypes',
275
+ alias: 'PgAdapterQueryOps',
276
+ },
277
+ },
258
278
  },
259
279
  } as const;
@@ -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 './codec-ids';
7
- import { escapeLiteral, qualifyName, quoteIdentifier, validateEnumValueLength } from './sql-utils';
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
- const errors: JsonSchemaValidationError[] = (validate.errors ?? []).map((err) => ({
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,