@prisma-next/adapter-postgres 0.5.0-dev.9 → 0.5.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 (48) hide show
  1. package/README.md +14 -16
  2. package/dist/adapter-CBaRvhQF.mjs +52 -0
  3. package/dist/adapter-CBaRvhQF.mjs.map +1 -0
  4. package/dist/adapter.d.mts +3 -4
  5. package/dist/adapter.d.mts.map +1 -1
  6. package/dist/adapter.mjs +2 -3
  7. package/dist/column-types.d.mts +19 -24
  8. package/dist/column-types.d.mts.map +1 -1
  9. package/dist/column-types.mjs +20 -60
  10. package/dist/column-types.mjs.map +1 -1
  11. package/dist/control.d.mts +83 -3
  12. package/dist/control.d.mts.map +1 -1
  13. package/dist/control.mjs +117 -29
  14. package/dist/control.mjs.map +1 -1
  15. package/dist/{descriptor-meta-RTDzyrae.mjs → descriptor-meta-CyjnYUWG.mjs} +35 -27
  16. package/dist/descriptor-meta-CyjnYUWG.mjs.map +1 -0
  17. package/dist/operation-types.d.mts +11 -10
  18. package/dist/operation-types.d.mts.map +1 -1
  19. package/dist/operation-types.mjs +1 -1
  20. package/dist/runtime.d.mts +3 -11
  21. package/dist/runtime.d.mts.map +1 -1
  22. package/dist/runtime.mjs +19 -81
  23. package/dist/runtime.mjs.map +1 -1
  24. package/dist/{sql-renderer-pEaSP82_.mjs → sql-renderer-wTVSEy5H.mjs} +109 -48
  25. package/dist/sql-renderer-wTVSEy5H.mjs.map +1 -0
  26. package/dist/{types-CfRPdAk8.d.mts → types-B1eiuBHQ.d.mts} +12 -1
  27. package/dist/types-B1eiuBHQ.d.mts.map +1 -0
  28. package/dist/types.d.mts +1 -1
  29. package/dist/types.mjs +1 -1
  30. package/package.json +23 -23
  31. package/src/core/adapter.ts +36 -43
  32. package/src/core/codec-lookup.ts +19 -0
  33. package/src/core/control-adapter.ts +252 -98
  34. package/src/core/control-mutation-defaults.ts +24 -18
  35. package/src/core/descriptor-meta.ts +27 -20
  36. package/src/core/sql-renderer.ts +129 -66
  37. package/src/core/types.ts +11 -0
  38. package/src/exports/column-types.ts +21 -61
  39. package/src/exports/control.ts +3 -2
  40. package/src/exports/runtime.ts +27 -66
  41. package/src/types/operation-types.ts +19 -9
  42. package/dist/adapter-hNElNHo4.mjs +0 -60
  43. package/dist/adapter-hNElNHo4.mjs.map +0 -1
  44. package/dist/descriptor-meta-RTDzyrae.mjs.map +0 -1
  45. package/dist/sql-renderer-pEaSP82_.mjs.map +0 -1
  46. package/dist/types-CfRPdAk8.d.mts.map +0 -1
  47. package/src/core/json-schema-validator.ts +0 -54
  48. package/src/core/standard-schema.ts +0 -71
package/README.md CHANGED
@@ -131,10 +131,9 @@ flowchart TD
131
131
  - Exports column descriptors for built-in types and enum helpers (`enumType`, `enumColumn(typeRef, nativeType)`)
132
132
  - Parameterized helpers: `charColumn(length)`, `varcharColumn(length)`, `numericColumn(precision, scale?)`, `bitColumn(length)`, `varbitColumn(length)`, `timeColumn(precision?)`, `timetzColumn(precision?)`, `intervalColumn(precision?)`
133
133
 
134
- - Exports JSON helpers:
135
- - `jsonColumn`, `jsonbColumn`
136
- - `json(schema?)`, `jsonb(schema?)` where `schema` is a Standard Schema value (e.g., Arktype)
137
- - When a schema is provided, `typeParams` metadata is derived from the schema's `~standard` interface
134
+ - Exports raw JSON helpers:
135
+ - `jsonColumn`, `jsonbColumn` — untyped raw JSON / JSONB column descriptors
136
+ - For schema-typed JSON columns, use the per-library extension package (`@prisma-next/extension-arktype-json` for arktype). The schema-accepting `json(schema)` / `jsonb(schema)` overloads previously shipped here retired in Phase C of the codec-registry-unification project.
138
137
 
139
138
  ## Dependencies
140
139
 
@@ -156,7 +155,7 @@ flowchart TD
156
155
  - [ADR 068 - Error mapping to RuntimeError](../../../../docs/architecture%20docs/adrs/ADR%20068%20-%20Error%20mapping%20to%20RuntimeError.md)
157
156
  - [ADR 112 - Target Extension Packs](../../../../docs/architecture%20docs/adrs/ADR%20112%20-%20Target%20Extension%20Packs.md)
158
157
  - [ADR 114 - Extension codecs & branded types](../../../../docs/architecture%20docs/adrs/ADR%20114%20-%20Extension%20codecs%20&%20branded%20types.md)
159
- - [ADR 163 - Postgres JSON and JSONB typed columns](../../../../docs/architecture%20docs/adrs/ADR%20163%20-%20Postgres%20JSON%20and%20JSONB%20typed%20columns.md)
158
+ - [ADR 168 - Postgres JSON and JSONB typed columns](../../../../docs/architecture%20docs/adrs/ADR%20168%20-%20Postgres%20JSON%20and%20JSONB%20typed%20columns.md). Schema-typed JSON columns now ship from per-library extension packages (`@prisma-next/extension-arktype-json` for arktype); see [ADR 208 - Higher-order codecs for parameterized types](../../../../docs/architecture%20docs/adrs/ADR%20208%20-%20Higher-order%20codecs%20for%20parameterized%20types.md).
160
159
 
161
160
  ## Usage
162
161
 
@@ -277,7 +276,8 @@ Both `json` and `jsonb` accept any valid JSON value:
277
276
  ### Authoring helpers
278
277
 
279
278
  ```typescript
280
- import { json, jsonb } from '@prisma-next/adapter-postgres/column-types';
279
+ import { jsonbColumn } from '@prisma-next/adapter-postgres/column-types';
280
+ import { arktypeJson } from '@prisma-next/extension-arktype-json/column-types';
281
281
  import { type as arktype } from 'arktype';
282
282
 
283
283
  const auditPayloadSchema = arktype({
@@ -287,26 +287,24 @@ const auditPayloadSchema = arktype({
287
287
 
288
288
  table('event', (t) =>
289
289
  t
290
- .column('payload', { type: jsonb(auditPayloadSchema), nullable: false })
291
- .column('raw', { type: json(), nullable: true }),
290
+ // Schema-typed JSONB via the per-library extension package.
291
+ .column('payload', { type: arktypeJson(auditPayloadSchema), nullable: false })
292
+ // Untyped raw JSONB via the adapter's static descriptor.
293
+ .column('raw', { type: jsonbColumn, nullable: true }),
292
294
  );
293
295
  ```
294
296
 
295
297
  ### Typed fallback behavior
296
298
 
297
- - If a schema value is provided, emitted `contract.d.ts` derives a concrete type from that schema.
298
- - If no schema is provided, emitted type falls back to `JsonValue`.
299
+ - For schema-typed columns, use a per-library extension package (e.g. `@prisma-next/extension-arktype-json`). The emit-path renderer reads the schema's `expression` from typeParams and produces a concrete TS type in `contract.d.ts`.
300
+ - For untyped columns (`jsonColumn`, `jsonbColumn`), the emitted type falls back to `JsonValue`.
299
301
  - Runtime values still encode/decode as JSON-compatible values.
300
302
 
301
- ### Standard Schema integration
302
-
303
- `json(schema)` and `jsonb(schema)` accept Standard Schema values. Arktype schemas work out of the box via their Standard Schema adapter (`schema['~standard']`).
304
-
305
303
  ## Exports
306
304
 
307
305
  - `./adapter`: Adapter implementation (`createPostgresAdapter`)
308
- - `./codec-types`: PostgreSQL codec types (`CodecTypes`, `JsonValue`, `dataTypes`)
309
- - `./column-types`: Column type descriptors and authoring helpers (`json`, `jsonb`, `jsonColumn`, `jsonbColumn`, `enumType`, `enumColumn`, `textColumn`, `int4Column`, etc.)
306
+ - `./codec-types`: PostgreSQL codec types (`CodecTypes`, `JsonValue`)
307
+ - `./column-types`: Column type descriptors and authoring helpers (`jsonColumn`, `jsonbColumn`, `enumType`, `enumColumn`, `textColumn`, `int4Column`, etc.)
310
308
  - `./types`: PostgreSQL-specific types
311
309
  - `./control`: Control-plane entry point (adapter descriptor)
312
310
  - `./runtime`: Runtime-plane entry point (runtime adapter descriptor)
@@ -0,0 +1,52 @@
1
+ import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-wTVSEy5H.mjs";
2
+ import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
3
+ import { parseContractMarkerRow } from "@prisma-next/sql-runtime";
4
+ //#region src/core/adapter.ts
5
+ const defaultCapabilities = Object.freeze({
6
+ postgres: {
7
+ orderBy: true,
8
+ limit: true,
9
+ lateral: true,
10
+ jsonAgg: true,
11
+ returning: true
12
+ },
13
+ sql: {
14
+ enums: true,
15
+ returning: true,
16
+ defaultInInsert: true
17
+ }
18
+ });
19
+ var PostgresAdapterImpl = class {
20
+ familyId = "sql";
21
+ targetId = "postgres";
22
+ profile;
23
+ codecLookup;
24
+ constructor(options) {
25
+ this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();
26
+ this.profile = Object.freeze({
27
+ id: options?.profileId ?? "postgres/default@1",
28
+ target: "postgres",
29
+ capabilities: defaultCapabilities,
30
+ readMarker: (queryable) => readPostgresMarker(queryable)
31
+ });
32
+ }
33
+ lower(ast, context) {
34
+ return renderLoweredSql(ast, context.contract, this.codecLookup);
35
+ }
36
+ };
37
+ async function readPostgresMarker(queryable) {
38
+ if ((await queryable.query("select 1 from information_schema.tables where table_schema = $1 and table_name = $2", ["prisma_contract", "marker"])).rows.length === 0) return { kind: "no-table" };
39
+ const row = (await queryable.query("select core_hash, profile_hash, contract_json, canonical_version, updated_at, app_tag, meta, invariants from prisma_contract.marker where space = $1", [APP_SPACE_ID])).rows[0];
40
+ if (!row) return { kind: "absent" };
41
+ return {
42
+ kind: "present",
43
+ record: parseContractMarkerRow(row)
44
+ };
45
+ }
46
+ function createPostgresAdapter(options) {
47
+ return Object.freeze(new PostgresAdapterImpl(options));
48
+ }
49
+ //#endregion
50
+ export { createPostgresAdapter as t };
51
+
52
+ //# sourceMappingURL=adapter-CBaRvhQF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-CBaRvhQF.mjs","names":[],"sources":["../src/core/adapter.ts"],"sourcesContent":["import type { CodecLookup } 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 MarkerReadResult,\n SqlQueryable,\n} from '@prisma-next/sql-relational-core/ast';\nimport { parseContractMarkerRow } from '@prisma-next/sql-runtime';\nimport { createPostgresBuiltinCodecLookup } from './codec-lookup';\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\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: CodecLookup;\n\n constructor(options?: PostgresAdapterOptions) {\n this.codecLookup = options?.codecLookup ?? createPostgresBuiltinCodecLookup();\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n readMarker: (queryable: SqlQueryable) => readPostgresMarker(queryable),\n });\n }\n\n lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement {\n return renderLoweredSql(ast, context.contract, this.codecLookup);\n }\n}\n\nasync function readPostgresMarker(queryable: SqlQueryable): Promise<MarkerReadResult> {\n const exists = await queryable.query(\n 'select 1 from information_schema.tables where table_schema = $1 and table_name = $2',\n ['prisma_contract', 'marker'],\n );\n if (exists.rows.length === 0) {\n return { kind: 'no-table' };\n }\n\n const result = await queryable.query(\n 'select core_hash, profile_hash, contract_json, canonical_version, updated_at, app_tag, meta, invariants from prisma_contract.marker where space = $1',\n [APP_SPACE_ID],\n );\n const row = result.rows[0];\n if (!row) {\n return { kind: 'absent' };\n }\n // Postgres' driver hydrates `text[]` columns as native JS arrays, so the row is already in the shape the shared parser expects.\n return { kind: 'present', record: parseContractMarkerRow(row) };\n}\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;AAeA,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;AAEF,IAAM,sBAAN,MAEA;CAEE,WAAoB;CACpB,WAAoB;CAEpB;CACA;CAEA,YAAY,SAAkC;EAC5C,KAAK,cAAc,SAAS,eAAe,kCAAkC;EAC7E,KAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,aAAa,cAA4B,mBAAmB,UAAU;GACvE,CAAC;;CAGJ,MAAM,KAAkB,SAAqE;EAC3F,OAAO,iBAAiB,KAAK,QAAQ,UAAU,KAAK,YAAY;;;AAIpE,eAAe,mBAAmB,WAAoD;CAKpF,KAAI,MAJiB,UAAU,MAC7B,uFACA,CAAC,mBAAmB,SAAS,CAC9B,EACU,KAAK,WAAW,GACzB,OAAO,EAAE,MAAM,YAAY;CAO7B,MAAM,OAAM,MAJS,UAAU,MAC7B,wJACA,CAAC,aAAa,CACf,EACkB,KAAK;CACxB,IAAI,CAAC,KACH,OAAO,EAAE,MAAM,UAAU;CAG3B,OAAO;EAAE,MAAM;EAAW,QAAQ,uBAAuB,IAAI;EAAE;;AAGjE,SAAgB,sBAAsB,SAAkC;CACtE,OAAO,OAAO,OAAO,IAAI,oBAAoB,QAAQ,CAAC"}
@@ -1,14 +1,13 @@
1
- import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-CfRPdAk8.mjs";
2
- import { Adapter, AdapterProfile, AnyQueryAst, CodecParamsDescriptor, LowererContext } from "@prisma-next/sql-relational-core/ast";
1
+ import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-B1eiuBHQ.mjs";
2
+ import { Adapter, AdapterProfile, AnyQueryAst, LowererContext } from "@prisma-next/sql-relational-core/ast";
3
3
 
4
4
  //#region src/core/adapter.d.ts
5
5
  declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {
6
6
  readonly familyId: "sql";
7
7
  readonly targetId: "postgres";
8
8
  readonly profile: AdapterProfile<'postgres'>;
9
- private readonly codecRegistry;
9
+ private readonly codecLookup;
10
10
  constructor(options?: PostgresAdapterOptions);
11
- parameterizedCodecs(): ReadonlyArray<CodecParamsDescriptor>;
12
11
  lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
13
12
  }
14
13
  declare function createPostgresAdapter(options?: PostgresAdapterOptions): Readonly<PostgresAdapterImpl>;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"mappings":";;;;cA8BM,mBAAA,YACO,OAAA,CAAQ,WAAA,EAAa,gBAAA,EAAkB,wBAAA;EAAA,SAGzC,QAAA;EAAA,SACA,QAAA;EAAA,SAEA,OAAA,EAAS,cAAA;EAAA,iBACD,WAAA;cAEL,OAAA,GAAU,sBAAA;EAUtB,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,CAAe,gBAAA,IAAoB,wBAAA;AAAA;AAAA,iBA0BtD,qBAAA,CAAsB,OAAA,GAAU,sBAAA,GAAsB,QAAA,CAAA,mBAAA"}
package/dist/adapter.mjs CHANGED
@@ -1,3 +1,2 @@
1
- import { t as createPostgresAdapter } from "./adapter-hNElNHo4.mjs";
2
-
3
- export { createPostgresAdapter };
1
+ import { t as createPostgresAdapter } from "./adapter-CBaRvhQF.mjs";
2
+ export { createPostgresAdapter };
@@ -1,26 +1,6 @@
1
+ import { ColumnTypeDescriptor } from "@prisma-next/framework-components/codec";
1
2
  import { StorageTypeInstance } from "@prisma-next/sql-contract/types";
2
- import { ColumnTypeDescriptor } from "@prisma-next/contract-authoring";
3
3
 
4
- //#region src/core/standard-schema.d.ts
5
- type StandardSchemaJsonSchemaField = {
6
- readonly output?: unknown;
7
- };
8
- /**
9
- * Runtime view of the Standard Schema protocol.
10
- * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,
11
- * and `.expression` for an optional TypeScript type expression string (Arktype-specific).
12
- *
13
- * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads
14
- * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.
15
- */
16
- type StandardSchemaLike = {
17
- readonly '~standard'?: {
18
- readonly version?: number;
19
- readonly jsonSchema?: StandardSchemaJsonSchemaField;
20
- };
21
- readonly expression?: unknown;
22
- };
23
- //#endregion
24
4
  //#region src/exports/column-types.d.ts
25
5
  declare const textColumn: {
26
6
  readonly codecId: "pg/text@1";
@@ -94,21 +74,36 @@ declare function varbitColumn(length: number): ColumnTypeDescriptor & {
94
74
  readonly length: number;
95
75
  };
96
76
  };
77
+ /**
78
+ * Postgres `bytea` column descriptor — variable-length binary string.
79
+ *
80
+ * 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.
81
+ */
82
+ declare const byteaColumn: {
83
+ readonly codecId: "pg/bytea@1";
84
+ readonly nativeType: "bytea";
85
+ };
97
86
  declare function intervalColumn(precision?: number): ColumnTypeDescriptor & {
98
87
  readonly typeParams?: {
99
88
  readonly precision: number;
100
89
  };
101
90
  };
91
+ /**
92
+ * Postgres `json` column descriptor — untyped raw JSON.
93
+ *
94
+ * 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.
95
+ */
102
96
  declare const jsonColumn: {
103
97
  readonly codecId: "pg/json@1";
104
98
  readonly nativeType: "json";
105
99
  };
100
+ /**
101
+ * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement note as {@link jsonColumn}.
102
+ */
106
103
  declare const jsonbColumn: {
107
104
  readonly codecId: "pg/jsonb@1";
108
105
  readonly nativeType: "jsonb";
109
106
  };
110
- declare function json(schema?: StandardSchemaLike): ColumnTypeDescriptor;
111
- declare function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor;
112
107
  declare function enumType<const Values extends readonly string[]>(name: string, values: Values): StorageTypeInstance & {
113
108
  readonly typeParams: {
114
109
  readonly values: Values;
@@ -118,5 +113,5 @@ declare function enumColumn<TypeName extends string>(typeName: TypeName, nativeT
118
113
  readonly typeRef: TypeName;
119
114
  };
120
115
  //#endregion
121
- export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, json, jsonColumn, jsonb, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
116
+ export { bitColumn, boolColumn, byteaColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
122
117
  //# sourceMappingURL=column-types.d.mts.map
@@ -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;AAc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CHAR_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
2
-
3
- //#region src/core/standard-schema.ts
4
- function isObjectLike(value) {
5
- return (typeof value === "object" || typeof value === "function") && value !== null;
6
- }
7
- function resolveOutputJsonSchemaField(schema) {
8
- const jsonSchema = schema["~standard"]?.jsonSchema;
9
- if (!jsonSchema) return;
10
- if (typeof jsonSchema.output === "function") return jsonSchema.output({ target: "draft-07" });
11
- return jsonSchema.output;
12
- }
13
- function extractStandardSchemaOutputJsonSchema(schema) {
14
- const outputSchema = resolveOutputJsonSchemaField(schema);
15
- if (!isObjectLike(outputSchema)) return;
16
- return outputSchema;
17
- }
18
- function extractStandardSchemaTypeExpression(schema) {
19
- const expression = schema.expression;
20
- if (typeof expression !== "string") return;
21
- const trimmedExpression = expression.trim();
22
- if (trimmedExpression.length === 0) return;
23
- return trimmedExpression;
24
- }
25
- function isStandardSchemaLike(value) {
26
- return isObjectLike(value) && isObjectLike(value["~standard"]);
27
- }
28
-
29
- //#endregion
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";
30
2
  //#region src/exports/column-types.ts
31
3
  const textColumn = {
32
4
  codecId: PG_TEXT_CODEC_ID,
@@ -116,6 +88,15 @@ function varbitColumn(length) {
116
88
  typeParams: { length }
117
89
  };
118
90
  }
91
+ /**
92
+ * Postgres `bytea` column descriptor — variable-length binary string.
93
+ *
94
+ * 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.
95
+ */
96
+ const byteaColumn = {
97
+ codecId: PG_BYTEA_CODEC_ID,
98
+ nativeType: "bytea"
99
+ };
119
100
  function intervalColumn(precision) {
120
101
  return {
121
102
  codecId: PG_INTERVAL_CODEC_ID,
@@ -123,43 +104,22 @@ function intervalColumn(precision) {
123
104
  ...precision === void 0 ? {} : { typeParams: { precision } }
124
105
  };
125
106
  }
107
+ /**
108
+ * Postgres `json` column descriptor — untyped raw JSON.
109
+ *
110
+ * 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.
111
+ */
126
112
  const jsonColumn = {
127
113
  codecId: PG_JSON_CODEC_ID,
128
114
  nativeType: "json"
129
115
  };
116
+ /**
117
+ * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement note as {@link jsonColumn}.
118
+ */
130
119
  const jsonbColumn = {
131
120
  codecId: PG_JSONB_CODEC_ID,
132
121
  nativeType: "jsonb"
133
122
  };
134
- function createJsonTypeParams(schema) {
135
- const outputSchema = extractStandardSchemaOutputJsonSchema(schema);
136
- if (!outputSchema) throw new Error("JSON schema must expose ~standard.jsonSchema.output()");
137
- const expression = extractStandardSchemaTypeExpression(schema);
138
- if (expression) return {
139
- schemaJson: outputSchema,
140
- type: expression
141
- };
142
- return { schemaJson: outputSchema };
143
- }
144
- function createJsonColumnFactory(codecId, nativeType, staticDescriptor) {
145
- return (schema) => {
146
- if (!schema) return staticDescriptor;
147
- if (!isStandardSchemaLike(schema)) throw new Error(`${nativeType}(schema) expects a Standard Schema value`);
148
- return {
149
- codecId,
150
- nativeType,
151
- typeParams: createJsonTypeParams(schema)
152
- };
153
- };
154
- }
155
- const _json = createJsonColumnFactory(PG_JSON_CODEC_ID, "json", jsonColumn);
156
- const _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, "jsonb", jsonbColumn);
157
- function json(schema) {
158
- return _json(schema);
159
- }
160
- function jsonb(schema) {
161
- return _jsonb(schema);
162
- }
163
123
  function enumType(name, values) {
164
124
  return {
165
125
  codecId: PG_ENUM_CODEC_ID,
@@ -174,7 +134,7 @@ function enumColumn(typeName, nativeType) {
174
134
  typeRef: typeName
175
135
  };
176
136
  }
177
-
178
137
  //#endregion
179
- export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, json, jsonColumn, jsonb, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
138
+ export { bitColumn, boolColumn, byteaColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
139
+
180
140
  //# sourceMappingURL=column-types.mjs.map
@@ -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 '@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_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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D;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/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 type { StorageTypeInstance } from '@prisma-next/sql-contract/types';\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';\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): 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":";;AAgCA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,WAAW,QAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,cAAc,QAE5B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;AAED,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;CACb;AAED,SAAgB,cACd,WACA,OAGA;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,UAAU,KAAA,IAAY,EAAE,WAAW,GAAG;GAAE;GAAW;GAAO;EACvE;;AAGH,MAAa,kBAAkB;CAC7B,SAAS;CACT,YAAY;CACb;AAED,MAAa,oBAAoB;CAC/B,SAAS;CACT,YAAY;CACb;AAED,SAAgB,WAAW,WAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;AAGH,SAAgB,aAAa,WAE3B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;AAGH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,UAAU,QAExB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,aAAa,QAE3B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;;;;;;AAQH,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,eAAe,WAE7B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;;;;;;AAQH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;;;;AAKD,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,SACd,MACA,QAC4E;CAC5E,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,WACd,UACA,YACuD;CACvD,OAAO;EACL,SAAS;EACT;EACA,SAAS;EACV"}
@@ -1,10 +1,90 @@
1
+ import { ControlDriverInstance } from "@prisma-next/framework-components/control";
2
+ import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
1
3
  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";
4
+ import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
5
+ import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
4
6
  import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
7
+ import { ContractMarkerRecord } from "@prisma-next/contract/types";
8
+ import { CodecLookup } from "@prisma-next/framework-components/codec";
9
+ import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
10
+ import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
5
11
 
12
+ //#region src/core/control-adapter.d.ts
13
+ /**
14
+ * Postgres control plane adapter for control-plane operations like introspection.
15
+ * Provides target-specific implementations for control-plane domain actions.
16
+ */
17
+ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
18
+ readonly familyId: "sql";
19
+ readonly targetId: "postgres";
20
+ private readonly codecLookup;
21
+ /**
22
+ * @param codecLookup - Codec lookup used by the SQL renderer to resolve
23
+ * per-codec metadata at lower-time. Defaults to a Postgres-builtins-only
24
+ * lookup when omitted. Stack-aware callers
25
+ * (`SqlControlAdapterDescriptor.create(stack)`) supply
26
+ * `stack.codecLookup` so extension codecs are visible to the renderer.
27
+ */
28
+ constructor(codecLookup?: CodecLookup);
29
+ /**
30
+ * Target-specific normalizer for raw Postgres default expressions.
31
+ * Used by schema verification to normalize raw defaults before comparison.
32
+ */
33
+ readonly normalizeDefault: typeof parsePostgresDefault$1;
34
+ /**
35
+ * Target-specific normalizer for Postgres schema native type names.
36
+ * Used by schema verification to normalize introspected type names
37
+ * before comparison with contract native types.
38
+ */
39
+ readonly normalizeNativeType: typeof normalizeSchemaNativeType$1;
40
+ /**
41
+ * Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
42
+ *
43
+ * Delegates to the shared `renderLoweredSql` renderer so the control adapter
44
+ * emits byte-identical SQL to `PostgresAdapterImpl.lower()` for the same AST
45
+ * and contract. Used at migration plan/emit time (e.g. by `dataTransform`)
46
+ * without instantiating the runtime adapter.
47
+ */
48
+ lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
49
+ /**
50
+ * Reads the contract marker from `prisma_contract.marker`. Probes
51
+ * `information_schema.tables` first so a fresh database (where the
52
+ * `prisma_contract` schema doesn't yet exist) returns `null` instead of a
53
+ * "relation does not exist" error — some Postgres wire-protocol clients
54
+ * (e.g. PGlite's TCP proxy) don't fully recover from extended-protocol
55
+ * parse errors, so we probe before reading.
56
+ */
57
+ readMarker(driver: ControlDriverInstance<'sql', 'postgres'>, space: string): Promise<ContractMarkerRecord | null>;
58
+ /**
59
+ * Reads every row from `prisma_contract.marker` and returns them keyed
60
+ * by `space`. Mirrors the existence probe in {@link readMarker}: a
61
+ * fresh database without the `prisma_contract` schema returns an empty
62
+ * map rather than raising "relation does not exist".
63
+ */
64
+ readAllMarkers(driver: ControlDriverInstance<'sql', 'postgres'>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
65
+ /**
66
+ * Introspects a Postgres database schema and returns a raw SqlSchemaIR.
67
+ *
68
+ * This is a pure schema discovery operation that queries the Postgres catalog
69
+ * and returns the schema structure without type mapping or contract enrichment.
70
+ * Type mapping and enrichment are handled separately by enrichment helpers.
71
+ *
72
+ * Uses batched queries to minimize database round trips (6 queries instead of 5T+1).
73
+ *
74
+ * @param driver - ControlDriverInstance<'sql', 'postgres'> instance for executing queries
75
+ * @param contract - Optional contract for contract-guided introspection (filtering, optimization)
76
+ * @param schema - Schema name to introspect (defaults to 'public')
77
+ * @returns Promise resolving to SqlSchemaIR representing the live database schema
78
+ */
79
+ introspect(driver: ControlDriverInstance<'sql', 'postgres'>, _contract?: unknown, schema?: string): Promise<SqlSchemaIR>;
80
+ /**
81
+ * Gets the Postgres version from the database.
82
+ */
83
+ private getPostgresVersion;
84
+ }
85
+ //#endregion
6
86
  //#region src/exports/control.d.ts
7
87
  declare const postgresAdapterDescriptor: SqlControlAdapterDescriptor<'postgres'>;
8
88
  //#endregion
9
- export { SqlEscapeError, postgresAdapterDescriptor as default, escapeLiteral, normalizeSchemaNativeType, parsePostgresDefault, qualifyName, quoteIdentifier };
89
+ export { PostgresControlAdapter, SqlEscapeError, postgresAdapterDescriptor as default, escapeLiteral, normalizeSchemaNativeType, parsePostgresDefault, qualifyName, quoteIdentifier };
10
90
  //# sourceMappingURL=control.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/exports/control.ts"],"sourcesContent":[],"mappings":";;;;;;cAgBM,2BAA2B"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;cAgCa,sBAAA,YAAkC,iBAAA;EAAA,SACpC,QAAA;EAAA,SACA,QAAA;EAAA,iBAEQ,WAAA;EAiBQ;;;;;;;cARb,WAAA,GAAc,WAAA;EAuFhB;;;;EAAA,SA/ED,gBAAA,SAAgB,sBAAA;EA4Id;;;;;EAAA,SArIF,mBAAA,SAAmB,2BAAA;EA3BnB;;;;;;;;EAqCT,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;EAV/B;;;;;;;;EAsBtB,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,WACC,OAAA,CAAQ,oBAAA;EAFT;;;;;;EAgDI,cAAA,CACJ,MAAA,EAAQ,qBAAA,sBACP,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAA5B;;;;;;;;;;;;;;EAwDG,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,SAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;;AC1LmC;;UDkkBhC,kBAAA;AAAA;;;cCzjBV,yBAAA,EAA2B,2BAAA"}