@prisma-next/adapter-postgres 0.5.0-dev.30 → 0.5.0-dev.41

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/README.md CHANGED
@@ -131,10 +131,13 @@ 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
137
+ (`@prisma-next/extension-arktype-json` for arktype). The
138
+ schema-accepting `json(schema)` / `jsonb(schema)` overloads
139
+ previously shipped here retired in Phase C of the
140
+ codec-registry-unification project.
138
141
 
139
142
  ## Dependencies
140
143
 
@@ -156,7 +159,7 @@ flowchart TD
156
159
  - [ADR 068 - Error mapping to RuntimeError](../../../../docs/architecture%20docs/adrs/ADR%20068%20-%20Error%20mapping%20to%20RuntimeError.md)
157
160
  - [ADR 112 - Target Extension Packs](../../../../docs/architecture%20docs/adrs/ADR%20112%20-%20Target%20Extension%20Packs.md)
158
161
  - [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)
162
+ - [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
163
 
161
164
  ## Usage
162
165
 
@@ -277,7 +280,8 @@ Both `json` and `jsonb` accept any valid JSON value:
277
280
  ### Authoring helpers
278
281
 
279
282
  ```typescript
280
- import { json, jsonb } from '@prisma-next/adapter-postgres/column-types';
283
+ import { jsonbColumn } from '@prisma-next/adapter-postgres/column-types';
284
+ import { arktypeJson } from '@prisma-next/extension-arktype-json/column-types';
281
285
  import { type as arktype } from 'arktype';
282
286
 
283
287
  const auditPayloadSchema = arktype({
@@ -287,26 +291,28 @@ const auditPayloadSchema = arktype({
287
291
 
288
292
  table('event', (t) =>
289
293
  t
290
- .column('payload', { type: jsonb(auditPayloadSchema), nullable: false })
291
- .column('raw', { type: json(), nullable: true }),
294
+ // Schema-typed JSONB via the per-library extension package.
295
+ .column('payload', { type: arktypeJson(auditPayloadSchema), nullable: false })
296
+ // Untyped raw JSONB via the adapter's static descriptor.
297
+ .column('raw', { type: jsonbColumn, nullable: true }),
292
298
  );
293
299
  ```
294
300
 
295
301
  ### Typed fallback behavior
296
302
 
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`.
303
+ - For schema-typed columns, use a per-library extension package
304
+ (e.g. `@prisma-next/extension-arktype-json`). The emit-path renderer
305
+ reads the schema's `expression` from typeParams and produces a concrete
306
+ TS type in `contract.d.ts`.
307
+ - For untyped columns (`jsonColumn`, `jsonbColumn`), the emitted type
308
+ falls back to `JsonValue`.
299
309
  - Runtime values still encode/decode as JSON-compatible values.
300
310
 
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
311
  ## Exports
306
312
 
307
313
  - `./adapter`: Adapter implementation (`createPostgresAdapter`)
308
314
  - `./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.)
315
+ - `./column-types`: Column type descriptors and authoring helpers (`jsonColumn`, `jsonbColumn`, `enumType`, `enumColumn`, `textColumn`, `int4Column`, etc.)
310
316
  - `./types`: PostgreSQL-specific types
311
317
  - `./control`: Control-plane entry point (adapter descriptor)
312
318
  - `./runtime`: Runtime-plane entry point (runtime adapter descriptor)
@@ -1,27 +1,8 @@
1
1
  import { StorageTypeInstance } from "@prisma-next/sql-contract/types";
2
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
5
+
25
6
  declare const textColumn: {
26
7
  readonly codecId: "pg/text@1";
27
8
  readonly nativeType: "text";
@@ -99,16 +80,27 @@ declare function intervalColumn(precision?: number): ColumnTypeDescriptor & {
99
80
  readonly precision: number;
100
81
  };
101
82
  };
83
+ /**
84
+ * Postgres `json` column descriptor — untyped raw JSON.
85
+ *
86
+ * For schema-typed JSON columns, use the per-library extension package
87
+ * (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for
88
+ * arktype). The schema-accepting `json(schema)` / `jsonb(schema)`
89
+ * overloads previously shipped from this module retired in Phase C of
90
+ * the codec-registry-unification project — see spec § AC-7.
91
+ */
102
92
  declare const jsonColumn: {
103
93
  readonly codecId: "pg/json@1";
104
94
  readonly nativeType: "json";
105
95
  };
96
+ /**
97
+ * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement
98
+ * note as {@link jsonColumn}.
99
+ */
106
100
  declare const jsonbColumn: {
107
101
  readonly codecId: "pg/jsonb@1";
108
102
  readonly nativeType: "jsonb";
109
103
  };
110
- declare function json(schema?: StandardSchemaLike): ColumnTypeDescriptor;
111
- declare function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor;
112
104
  declare function enumType<const Values extends readonly string[]>(name: string, values: Values): StorageTypeInstance & {
113
105
  readonly typeParams: {
114
106
  readonly values: Values;
@@ -118,5 +110,5 @@ declare function enumColumn<TypeName extends string>(typeName: TypeName, nativeT
118
110
  readonly typeRef: TypeName;
119
111
  };
120
112
  //#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 };
113
+ export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
122
114
  //# 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;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,SAAA,UAG4B,EAAA;IAE5B,SAAA,MAG4B,EAAA,MAAA;EAE5B,CAAA;AAKb,CAAA;AAaa,iBAhDG,aAAA,CAmDyB,MAAA,EAAA,MAAA,CAAA,EAnDM,oBAmDN,GAAA;EAE5B,SAAA,UAAA,EAG4B;IAEzB,SAAU,MAAA,EAAA,MAAsB;EAUhC,CAAA;AAUhB,CAAA;AAKgB,cAzEH,UAyE8B,EAAA;EAU3B,SAAA,OAAY,EAAA,WAAkB;EAU9B,SAAA,UAAc,EAAA,MAAA;AAU9B,CAAA;AAKa,cAvGA,UA0G4B,EAAA;EA8CzB,SAAI,OAAA,EAAA,WAAU;EAId,SAAK,UAAA,EAAU,MAAA;AAI/B,CAAA;AAEU,cA7JG,UA6JH,EAAA;EACP,SAAA,OAAA,EAAA,WAAA;EAAgE,SAAA,UAAA,EAAA,MAAA;CAAM;AAQzD,cAjKH,YAiKa,EAAA;EACd,SAAA,OAAA,EAAA,aAAA;EAET,SAAA,UAAA,EAAA,QAAA;CAA2C;AAAQ,cA/JzC,YA+JyC,EAAA;;;;iBA1JtC,aAAA,qCAGb;;;;;;cAUU;;;;cAKA;;;;iBAKG,UAAA,sBAAgC;;;;;iBAUhC,YAAA,sBAAkC;;;;;cAUrC;;;;iBAKG,SAAA,kBAA2B;;;;;iBAU3B,YAAA,kBAA8B;;;;;iBAU9B,cAAA,sBAAoC;;;;;cAUvC;;;;cAKA;;;;iBAiDG,IAAA,UAAc,qBAAqB;iBAInC,KAAA,UAAe,qBAAqB;iBAIpC,uEAEN,SACP;;qBAAgE;;;iBAQnD,8CACJ,+BAET;oBAA2C"}
1
+ {"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"sourcesContent":[],"mappings":";;;;;AA8Da,cA9BA,UAiC4B,EAAA;EAE5B,SAAA,OAG4B,EAAA,WAAA;EAE5B,SAAA,UAG4B,EAAA,MAAA;AAEzC,CAAA;AAKgB,iBA7CA,UAAA,CAgDb,MAAA,EAAA,MAAA,CAAA,EAhDyC,oBAgDrB,GAAA;EAUV,SAAA,UAG4B,EAAA;IAE5B,SAAA,MAAA,EAG4B,MAAA;EAEzB,CAAA;AAUhB,CAAA;AAUa,iBA9EG,aAAA,CAiFyB,MAAA,EAAA,MAAA,CAAA,EAjFM,oBAiFN,GAAA;EAEzB,SAAA,UAAS,EAAA;IAUT,SAAA,MAAY,EAAA,MAAkB;EAU9B,CAAA;AAmBhB,CAAA;AASa,cAzHA,UA4H4B,EAAA;EAEzB,SAAA,OAAQ,EAAA,WAAA;EAEd,SAAA,UAAA,EAAA,MAAA;CACP;AAAgE,cA5HtD,UA4HsD,EAAA;EAAM,SAAA,OAAA,EAAA,WAAA;EAQzD,SAAA,UAAU,EAAA,MAAA;CACd;AAET,cAlIU,UAkIV,EAAA;EAA2C,SAAA,OAAA,EAAA,WAAA;EAAQ,SAAA,UAAA,EAAA,MAAA;;cA7HzC;;;;cAKA;;;;iBAKG,aAAA,qCAGb;;;;;;cAUU;;;;cAKA;;;;iBAKG,UAAA,sBAAgC;;;;;iBAUhC,YAAA,sBAAkC;;;;;cAUrC;;;;iBAKG,SAAA,kBAA2B;;;;;iBAU3B,YAAA,kBAA8B;;;;;iBAU9B,cAAA,sBAAoC;;;;;;;;;;;;;;cAmBvC;;;;;;;;cASA;;;;iBAKG,uEAEN,SACP;;qBAAgE;;;iBAQnD,8CACJ,+BAET;oBAA2C"}
@@ -1,32 +1,5 @@
1
1
  import { PG_BIT_CODEC_ID, PG_BOOL_CODEC_ID, PG_ENUM_CODEC_ID, PG_FLOAT4_CODEC_ID, PG_FLOAT8_CODEC_ID, PG_INT2_CODEC_ID, PG_INT4_CODEC_ID, PG_INT8_CODEC_ID, PG_INTERVAL_CODEC_ID, PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID, PG_NUMERIC_CODEC_ID, PG_TEXT_CODEC_ID, PG_TIMESTAMPTZ_CODEC_ID, PG_TIMESTAMP_CODEC_ID, PG_TIMETZ_CODEC_ID, PG_TIME_CODEC_ID, PG_VARBIT_CODEC_ID, SQL_CHAR_CODEC_ID, SQL_VARCHAR_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
2
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
30
3
  //#region src/exports/column-types.ts
31
4
  const textColumn = {
32
5
  codecId: PG_TEXT_CODEC_ID,
@@ -123,43 +96,27 @@ function intervalColumn(precision) {
123
96
  ...precision === void 0 ? {} : { typeParams: { precision } }
124
97
  };
125
98
  }
99
+ /**
100
+ * Postgres `json` column descriptor — untyped raw JSON.
101
+ *
102
+ * For schema-typed JSON columns, use the per-library extension package
103
+ * (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for
104
+ * arktype). The schema-accepting `json(schema)` / `jsonb(schema)`
105
+ * overloads previously shipped from this module retired in Phase C of
106
+ * the codec-registry-unification project — see spec § AC-7.
107
+ */
126
108
  const jsonColumn = {
127
109
  codecId: PG_JSON_CODEC_ID,
128
110
  nativeType: "json"
129
111
  };
112
+ /**
113
+ * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement
114
+ * note as {@link jsonColumn}.
115
+ */
130
116
  const jsonbColumn = {
131
117
  codecId: PG_JSONB_CODEC_ID,
132
118
  nativeType: "jsonb"
133
119
  };
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
120
  function enumType(name, values) {
164
121
  return {
165
122
  codecId: PG_ENUM_CODEC_ID,
@@ -176,5 +133,5 @@ function enumColumn(typeName, nativeType) {
176
133
  }
177
134
 
178
135
  //#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 };
136
+ export { bitColumn, boolColumn, charColumn, enumColumn, enumType, float4Column, float8Column, int2Column, int4Column, int8Column, intervalColumn, jsonColumn, jsonbColumn, numericColumn, textColumn, timeColumn, timestampColumn, timestamptzColumn, timetzColumn, varbitColumn, varcharColumn };
180
137
  //# 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,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,aAAc,MAA6B,aAAa;;;;;AC/BxF,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;AAED,SAAgB,WAAW,QAEzB;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,cAAc,QAE5B;AACA,QAAO;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;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,UAAU,SAAY,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;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;AAGH,SAAgB,aAAa,WAE3B;AACA,QAAO;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,SAAgB,UAAU,QAExB;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,aAAa,QAE3B;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,eAAe,WAE7B;AACA,QAAO;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/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.\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';\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\n/**\n * Postgres `json` column descriptor — untyped raw JSON.\n *\n * For schema-typed JSON columns, use the per-library extension package\n * (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for\n * arktype). The schema-accepting `json(schema)` / `jsonb(schema)`\n * overloads previously shipped from this module retired in Phase C of\n * 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\n * 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;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,cAAc,QAE5B;AACA,QAAO;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;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,UAAU,SAAY,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;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;AAGH,SAAgB,aAAa,WAE3B;AACA,QAAO;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,SAAgB,UAAU,QAExB;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,aAAa,QAE3B;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,QAAQ;EACvB;;AAGH,SAAgB,eAAe,WAE7B;AACA,QAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,SAAY,EAAE,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE;EACjE;;;;;;;;;;;AAYH,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;CACb;;;;;AAMD,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;CACb;AAED,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"}
@@ -2,18 +2,10 @@ import { c as PostgresContract, l as PostgresLoweredStatement } from "./types-tL
2
2
  import { Adapter, AnyQueryAst } from "@prisma-next/sql-relational-core/ast";
3
3
  import { SqlRuntimeAdapterDescriptor } from "@prisma-next/sql-runtime";
4
4
  import { RuntimeAdapterInstance } from "@prisma-next/framework-components/execution";
5
- import { JsonSchemaValidateFn } from "@prisma-next/sql-relational-core/query-lane-context";
6
5
 
7
6
  //#region src/exports/runtime.d.ts
8
7
  interface SqlRuntimeAdapter extends RuntimeAdapterInstance<'sql', 'postgres'>, Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}
9
- /**
10
- * Helper returned by the JSON/JSONB `init` hook.
11
- * Contains a compiled JSON Schema validate function for runtime conformance checks.
12
- */
13
- type JsonCodecHelper = {
14
- readonly validate: JsonSchemaValidateFn;
15
- };
16
8
  declare const postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter>;
17
9
  //#endregion
18
- export { JsonCodecHelper, SqlRuntimeAdapter, postgresRuntimeAdapterDescriptor as default };
10
+ export { SqlRuntimeAdapter, postgresRuntimeAdapterDescriptor as default };
19
11
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;;UAsBiB,iBAAA,SACP,2CACN,QAAQ,aAAa,kBAAkB;AAF3C;;;;AACU,KAuBE,eAAA,GAvBF;EACN,SAAA,QAAA,EAsB+C,oBAtB/C;CAAO;AAsBX,cA+BM,gCA/B6C,EA+BX,2BA/B+B,CAAA,UAAA,EA+BS,iBA/BT,CAAA"}
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;UAgBiB,iBAAA,SACP,2CACN,QAAQ,aAAa,kBAAkB;AAF3C,cAmCM,gCAlCJ,EAkCsC,2BAlCtC,CAAA,UAAA,EAkC8E,iBAlC9E,CAAA"}
package/dist/runtime.mjs CHANGED
@@ -2,64 +2,16 @@ import { t as createPostgresAdapter } from "./adapter-_L4wXA4O.mjs";
2
2
  import { n as postgresQueryOperations, t as postgresAdapterDescriptorMeta } from "./descriptor-meta-Dxnoq_rr.mjs";
3
3
  import { createCodecRegistry } from "@prisma-next/sql-relational-core/ast";
4
4
  import { codecDefinitions } from "@prisma-next/target-postgres/codecs";
5
- import { PG_JSONB_CODEC_ID, PG_JSON_CODEC_ID } from "@prisma-next/target-postgres/codec-ids";
6
5
  import { builtinGeneratorIds } from "@prisma-next/ids";
7
6
  import { extractCodecLookup } from "@prisma-next/framework-components/control";
8
7
  import { generateId } from "@prisma-next/ids/runtime";
9
- import { type } from "arktype";
10
- import Ajv from "ajv";
11
8
 
12
- //#region src/core/json-schema-validator.ts
13
- /**
14
- * Shared Ajv instance for all JSON Schema validators.
15
- * Reusing a single instance avoids ~50-100KB memory overhead per compiled schema.
16
- */
17
- let sharedAjv;
18
- function getSharedAjv() {
19
- if (!sharedAjv) sharedAjv = new Ajv({
20
- allErrors: false,
21
- strict: false
22
- });
23
- return sharedAjv;
24
- }
25
- /**
26
- * Compiles a JSON Schema object into a reusable validate function using Ajv.
27
- *
28
- * The returned function validates a value against the schema and returns
29
- * a structured result with error details on failure.
30
- *
31
- * Uses a shared Ajv instance and fail-fast mode (`allErrors: false`)
32
- * to minimize memory and CPU overhead.
33
- *
34
- * @param schema - A JSON Schema object (draft-07 compatible)
35
- * @returns A validate function
36
- */
37
- function compileJsonSchemaValidator(schema) {
38
- const validate = getSharedAjv().compile(schema);
39
- return (value) => {
40
- if (validate(value)) return { valid: true };
41
- return {
42
- valid: false,
43
- errors: validate.errors.map((err) => ({
44
- path: err.instancePath || "/",
45
- message: err.message ?? "unknown validation error",
46
- keyword: err.keyword
47
- }))
48
- };
49
- };
50
- }
51
-
52
- //#endregion
53
9
  //#region src/exports/runtime.ts
54
10
  function createPostgresCodecRegistry() {
55
11
  const registry = createCodecRegistry();
56
12
  for (const definition of Object.values(codecDefinitions)) registry.register(definition.codec);
57
13
  return registry;
58
14
  }
59
- const jsonTypeParamsSchema = type({
60
- schemaJson: "object",
61
- "type?": "string"
62
- });
63
15
  function createPostgresMutationDefaultGenerators() {
64
16
  return builtinGeneratorIds.map((id) => ({
65
17
  id,
@@ -71,18 +23,18 @@ function createPostgresMutationDefaultGenerators() {
71
23
  }
72
24
  }));
73
25
  }
74
- function initJsonCodecHelper(params) {
75
- return { validate: compileJsonSchemaValidator(params.schemaJson) };
76
- }
77
- const parameterizedCodecDescriptors = [{
78
- codecId: PG_JSON_CODEC_ID,
79
- paramsSchema: jsonTypeParamsSchema,
80
- init: initJsonCodecHelper
81
- }, {
82
- codecId: PG_JSONB_CODEC_ID,
83
- paramsSchema: jsonTypeParamsSchema,
84
- init: initJsonCodecHelper
85
- }];
26
+ /**
27
+ * Phase C of codec-registry-unification: the postgres adapter retains
28
+ * only static raw-JSON / raw-JSONB column descriptors. Schema-typed JSON
29
+ * columns ship from per-library extension packages now —
30
+ * `@prisma-next/extension-arktype-json` for arktype, future zod / valibot
31
+ * extensions when each lands. The previously-shipped
32
+ * `parameterizedCodecDescriptors` for `pg/json@1` / `pg/jsonb@1` retired
33
+ * with the schema-typed surface; the unified descriptor map auto-lifts
34
+ * the raw json/jsonb codecs from `codecs:` via the synthesis bridge for
35
+ * codec-id-keyed metadata reads.
36
+ */
37
+ const parameterizedCodecDescriptors = [];
86
38
  const postgresRuntimeAdapterDescriptor = {
87
39
  ...postgresAdapterDescriptorMeta,
88
40
  codecs: createPostgresCodecRegistry,
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":["sharedAjv: Ajv | undefined","arktype","postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter>"],"sources":["../src/core/json-schema-validator.ts","../src/exports/runtime.ts"],"sourcesContent":["import type {\n JsonSchemaValidateFn,\n JsonSchemaValidationError,\n JsonSchemaValidationResult,\n} from '@prisma-next/sql-relational-core/query-lane-context';\nimport Ajv from 'ajv';\n\nexport type { JsonSchemaValidateFn, JsonSchemaValidationError, JsonSchemaValidationResult };\n\n/**\n * Shared Ajv instance for all JSON Schema validators.\n * Reusing a single instance avoids ~50-100KB memory overhead per compiled schema.\n */\nlet sharedAjv: Ajv | undefined;\n\nfunction getSharedAjv(): Ajv {\n if (!sharedAjv) {\n sharedAjv = new Ajv({ allErrors: false, strict: false });\n }\n return sharedAjv;\n}\n\n/**\n * Compiles a JSON Schema object into a reusable validate function using Ajv.\n *\n * The returned function validates a value against the schema and returns\n * a structured result with error details on failure.\n *\n * Uses a shared Ajv instance and fail-fast mode (`allErrors: false`)\n * to minimize memory and CPU overhead.\n *\n * @param schema - A JSON Schema object (draft-07 compatible)\n * @returns A validate function\n */\nexport function compileJsonSchemaValidator(schema: Record<string, unknown>): JsonSchemaValidateFn {\n const ajv = getSharedAjv();\n const validate = ajv.compile(schema);\n\n return (value: unknown): JsonSchemaValidationResult => {\n const valid = validate(value);\n if (valid) {\n return { valid: true };\n }\n\n // biome-ignore lint/style/noNonNullAssertion: Ajv guarantees `errors` is populated whenever `validate(...)` returns false.\n const errors: JsonSchemaValidationError[] = validate.errors!.map((err) => ({\n path: err.instancePath || '/',\n message: err.message ?? 'unknown validation error',\n keyword: err.keyword,\n }));\n\n return { valid: false, errors };\n };\n}\n","import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport { extractCodecLookup } from '@prisma-next/framework-components/control';\nimport type { RuntimeAdapterInstance } from '@prisma-next/framework-components/execution';\nimport { builtinGeneratorIds } from '@prisma-next/ids';\nimport { generateId } from '@prisma-next/ids/runtime';\nimport type { Adapter, AnyQueryAst, CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeAdapterDescriptor,\n} from '@prisma-next/sql-runtime';\nimport { PG_JSON_CODEC_ID, PG_JSONB_CODEC_ID } from '@prisma-next/target-postgres/codec-ids';\nimport { codecDefinitions } from '@prisma-next/target-postgres/codecs';\nimport { type as arktype } from 'arktype';\nimport { createPostgresAdapter } from '../core/adapter';\nimport { postgresAdapterDescriptorMeta, postgresQueryOperations } from '../core/descriptor-meta';\nimport {\n compileJsonSchemaValidator,\n type JsonSchemaValidateFn,\n} from '../core/json-schema-validator';\nimport type { PostgresContract, PostgresLoweredStatement } from '../core/types';\n\nexport interface SqlRuntimeAdapter\n extends RuntimeAdapterInstance<'sql', 'postgres'>,\n Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}\n\nfunction createPostgresCodecRegistry(): CodecRegistry {\n const registry = createCodecRegistry();\n for (const definition of Object.values(codecDefinitions)) {\n registry.register(definition.codec);\n }\n return registry;\n}\n\nconst jsonTypeParamsSchema = arktype({\n schemaJson: 'object',\n 'type?': 'string',\n});\n\n/** The inferred type params shape from the arktype schema. */\ntype JsonTypeParams = typeof jsonTypeParamsSchema.infer;\n\n/**\n * Helper returned by the JSON/JSONB `init` hook.\n * Contains a compiled JSON Schema validate function for runtime conformance checks.\n */\nexport type JsonCodecHelper = { readonly validate: JsonSchemaValidateFn };\n\nfunction createPostgresMutationDefaultGenerators() {\n return builtinGeneratorIds.map((id) => ({\n id,\n generate: (params?: Record<string, unknown>) => {\n const spec: GeneratedValueSpec = params ? { id, params } : { id };\n return generateId(spec);\n },\n }));\n}\n\nfunction initJsonCodecHelper(params: JsonTypeParams): JsonCodecHelper {\n return { validate: compileJsonSchemaValidator(params.schemaJson as Record<string, unknown>) };\n}\n\nconst parameterizedCodecDescriptors = [\n {\n codecId: PG_JSON_CODEC_ID,\n paramsSchema: jsonTypeParamsSchema,\n init: initJsonCodecHelper,\n },\n {\n codecId: PG_JSONB_CODEC_ID,\n paramsSchema: jsonTypeParamsSchema,\n init: initJsonCodecHelper,\n },\n] as const satisfies ReadonlyArray<\n RuntimeParameterizedCodecDescriptor<JsonTypeParams, JsonCodecHelper>\n>;\n\nconst postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter> =\n {\n ...postgresAdapterDescriptorMeta,\n codecs: createPostgresCodecRegistry,\n parameterizedCodecs: () => parameterizedCodecDescriptors,\n queryOperations: () => postgresQueryOperations(),\n mutationDefaultGenerators: createPostgresMutationDefaultGenerators,\n create(stack): SqlRuntimeAdapter {\n // The runtime `ExecutionStack` does not (yet) carry a pre-assembled\n // `codecLookup` field the way the control `ControlStack` does, so we\n // derive an equivalent lookup here from the stack's component metadata\n // (target + adapter + extension packs) using the same assembly helper\n // that `createControlStack` uses. This keeps the renderer fed with the\n // same codec set on both planes — including extension-contributed\n // codecs like `pg/vector@1` from `@prisma-next/extension-pgvector`.\n const codecLookup = extractCodecLookup([\n stack.target,\n stack.adapter,\n ...stack.extensionPacks,\n ]);\n return createPostgresAdapter({ codecLookup });\n },\n };\n\nexport default postgresRuntimeAdapterDescriptor;\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,IAAIA;AAEJ,SAAS,eAAoB;AAC3B,KAAI,CAAC,UACH,aAAY,IAAI,IAAI;EAAE,WAAW;EAAO,QAAQ;EAAO,CAAC;AAE1D,QAAO;;;;;;;;;;;;;;AAeT,SAAgB,2BAA2B,QAAuD;CAEhG,MAAM,WADM,cAAc,CACL,QAAQ,OAAO;AAEpC,SAAQ,UAA+C;AAErD,MADc,SAAS,MAAM,CAE3B,QAAO,EAAE,OAAO,MAAM;AAUxB,SAAO;GAAE,OAAO;GAAO,QANqB,SAAS,OAAQ,KAAK,SAAS;IACzE,MAAM,IAAI,gBAAgB;IAC1B,SAAS,IAAI,WAAW;IACxB,SAAS,IAAI;IACd,EAAE;GAE4B;;;;;;ACzBnC,SAAS,8BAA6C;CACpD,MAAM,WAAW,qBAAqB;AACtC,MAAK,MAAM,cAAc,OAAO,OAAO,iBAAiB,CACtD,UAAS,SAAS,WAAW,MAAM;AAErC,QAAO;;AAGT,MAAM,uBAAuBC,KAAQ;CACnC,YAAY;CACZ,SAAS;CACV,CAAC;AAWF,SAAS,0CAA0C;AACjD,QAAO,oBAAoB,KAAK,QAAQ;EACtC;EACA,WAAW,WAAqC;AAE9C,UAAO,WAD0B,SAAS;IAAE;IAAI;IAAQ,GAAG,EAAE,IAAI,CAC1C;;EAE1B,EAAE;;AAGL,SAAS,oBAAoB,QAAyC;AACpE,QAAO,EAAE,UAAU,2BAA2B,OAAO,WAAsC,EAAE;;AAG/F,MAAM,gCAAgC,CACpC;CACE,SAAS;CACT,cAAc;CACd,MAAM;CACP,EACD;CACE,SAAS;CACT,cAAc;CACd,MAAM;CACP,CACF;AAID,MAAMC,mCACJ;CACE,GAAG;CACH,QAAQ;CACR,2BAA2B;CAC3B,uBAAuB,yBAAyB;CAChD,2BAA2B;CAC3B,OAAO,OAA0B;AAa/B,SAAO,sBAAsB,EAAE,aALX,mBAAmB;GACrC,MAAM;GACN,MAAM;GACN,GAAG,MAAM;GACV,CAAC,EAC0C,CAAC;;CAEhD;AAEH,sBAAe"}
1
+ {"version":3,"file":"runtime.mjs","names":["parameterizedCodecDescriptors: ReadonlyArray<RuntimeParameterizedCodecDescriptor>","postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter>"],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { GeneratedValueSpec } from '@prisma-next/contract/types';\nimport { extractCodecLookup } from '@prisma-next/framework-components/control';\nimport type { RuntimeAdapterInstance } from '@prisma-next/framework-components/execution';\nimport { builtinGeneratorIds } from '@prisma-next/ids';\nimport { generateId } from '@prisma-next/ids/runtime';\nimport type { Adapter, AnyQueryAst, CodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry } from '@prisma-next/sql-relational-core/ast';\nimport type {\n RuntimeParameterizedCodecDescriptor,\n SqlRuntimeAdapterDescriptor,\n} from '@prisma-next/sql-runtime';\nimport { codecDefinitions } from '@prisma-next/target-postgres/codecs';\nimport { createPostgresAdapter } from '../core/adapter';\nimport { postgresAdapterDescriptorMeta, postgresQueryOperations } from '../core/descriptor-meta';\nimport type { PostgresContract, PostgresLoweredStatement } from '../core/types';\n\nexport interface SqlRuntimeAdapter\n extends RuntimeAdapterInstance<'sql', 'postgres'>,\n Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {}\n\nfunction createPostgresCodecRegistry(): CodecRegistry {\n const registry = createCodecRegistry();\n for (const definition of Object.values(codecDefinitions)) {\n registry.register(definition.codec);\n }\n return registry;\n}\n\nfunction createPostgresMutationDefaultGenerators() {\n return builtinGeneratorIds.map((id) => ({\n id,\n generate: (params?: Record<string, unknown>) => {\n const spec: GeneratedValueSpec = params ? { id, params } : { id };\n return generateId(spec);\n },\n }));\n}\n\n/**\n * Phase C of codec-registry-unification: the postgres adapter retains\n * only static raw-JSON / raw-JSONB column descriptors. Schema-typed JSON\n * columns ship from per-library extension packages now —\n * `@prisma-next/extension-arktype-json` for arktype, future zod / valibot\n * extensions when each lands. The previously-shipped\n * `parameterizedCodecDescriptors` for `pg/json@1` / `pg/jsonb@1` retired\n * with the schema-typed surface; the unified descriptor map auto-lifts\n * the raw json/jsonb codecs from `codecs:` via the synthesis bridge for\n * codec-id-keyed metadata reads.\n */\nconst parameterizedCodecDescriptors: ReadonlyArray<RuntimeParameterizedCodecDescriptor> = [];\n\nconst postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter> =\n {\n ...postgresAdapterDescriptorMeta,\n codecs: createPostgresCodecRegistry,\n parameterizedCodecs: () => parameterizedCodecDescriptors,\n queryOperations: () => postgresQueryOperations(),\n mutationDefaultGenerators: createPostgresMutationDefaultGenerators,\n create(stack): SqlRuntimeAdapter {\n // The runtime `ExecutionStack` does not (yet) carry a pre-assembled\n // `codecLookup` field the way the control `ControlStack` does, so we\n // derive an equivalent lookup here from the stack's component metadata\n // (target + adapter + extension packs) using the same assembly helper\n // that `createControlStack` uses. This keeps the renderer fed with the\n // same codec set on both planes — including extension-contributed\n // codecs like `pg/vector@1` from `@prisma-next/extension-pgvector`.\n const codecLookup = extractCodecLookup([\n stack.target,\n stack.adapter,\n ...stack.extensionPacks,\n ]);\n return createPostgresAdapter({ codecLookup });\n },\n };\n\nexport default postgresRuntimeAdapterDescriptor;\n"],"mappings":";;;;;;;;;AAoBA,SAAS,8BAA6C;CACpD,MAAM,WAAW,qBAAqB;AACtC,MAAK,MAAM,cAAc,OAAO,OAAO,iBAAiB,CACtD,UAAS,SAAS,WAAW,MAAM;AAErC,QAAO;;AAGT,SAAS,0CAA0C;AACjD,QAAO,oBAAoB,KAAK,QAAQ;EACtC;EACA,WAAW,WAAqC;AAE9C,UAAO,WAD0B,SAAS;IAAE;IAAI;IAAQ,GAAG,EAAE,IAAI,CAC1C;;EAE1B,EAAE;;;;;;;;;;;;;AAcL,MAAMA,gCAAoF,EAAE;AAE5F,MAAMC,mCACJ;CACE,GAAG;CACH,QAAQ;CACR,2BAA2B;CAC3B,uBAAuB,yBAAyB;CAChD,2BAA2B;CAC3B,OAAO,OAA0B;AAa/B,SAAO,sBAAsB,EAAE,aALX,mBAAmB;GACrC,MAAM;GACN,MAAM;GACN,GAAG,MAAM;GACV,CAAC,EAC0C,CAAC;;CAEhD;AAEH,sBAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/adapter-postgres",
3
- "version": "0.5.0-dev.30",
3
+ "version": "0.5.0-dev.41",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -8,35 +8,34 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "ajv": "^8.18.0",
12
11
  "arktype": "^2.0.0",
13
- "@prisma-next/contract-authoring": "0.5.0-dev.30",
14
- "@prisma-next/contract": "0.5.0-dev.30",
15
- "@prisma-next/family-sql": "0.5.0-dev.30",
16
- "@prisma-next/framework-components": "0.5.0-dev.30",
17
- "@prisma-next/ids": "0.5.0-dev.30",
18
- "@prisma-next/sql-contract": "0.5.0-dev.30",
19
- "@prisma-next/sql-contract-ts": "0.5.0-dev.30",
20
- "@prisma-next/sql-operations": "0.5.0-dev.30",
21
- "@prisma-next/sql-relational-core": "0.5.0-dev.30",
22
- "@prisma-next/sql-contract-psl": "0.5.0-dev.30",
23
- "@prisma-next/sql-schema-ir": "0.5.0-dev.30",
24
- "@prisma-next/target-postgres": "0.5.0-dev.30",
25
- "@prisma-next/sql-runtime": "0.5.0-dev.30",
26
- "@prisma-next/utils": "0.5.0-dev.30"
12
+ "@prisma-next/contract": "0.5.0-dev.41",
13
+ "@prisma-next/family-sql": "0.5.0-dev.41",
14
+ "@prisma-next/contract-authoring": "0.5.0-dev.41",
15
+ "@prisma-next/sql-contract": "0.5.0-dev.41",
16
+ "@prisma-next/sql-contract-psl": "0.5.0-dev.41",
17
+ "@prisma-next/framework-components": "0.5.0-dev.41",
18
+ "@prisma-next/ids": "0.5.0-dev.41",
19
+ "@prisma-next/sql-operations": "0.5.0-dev.41",
20
+ "@prisma-next/sql-contract-ts": "0.5.0-dev.41",
21
+ "@prisma-next/sql-runtime": "0.5.0-dev.41",
22
+ "@prisma-next/sql-relational-core": "0.5.0-dev.41",
23
+ "@prisma-next/sql-schema-ir": "0.5.0-dev.41",
24
+ "@prisma-next/target-postgres": "0.5.0-dev.41",
25
+ "@prisma-next/utils": "0.5.0-dev.41"
27
26
  },
28
27
  "devDependencies": {
29
28
  "pathe": "^2.0.3",
30
29
  "tsdown": "0.18.4",
31
30
  "typescript": "5.9.3",
32
31
  "vitest": "4.0.17",
33
- "@prisma-next/cli": "0.5.0-dev.30",
34
- "@prisma-next/errors": "0.5.0-dev.30",
35
- "@prisma-next/extension-pgvector": "0.5.0-dev.30",
36
- "@prisma-next/tsconfig": "0.0.0",
32
+ "@prisma-next/driver-postgres": "0.5.0-dev.41",
33
+ "@prisma-next/cli": "0.5.0-dev.41",
34
+ "@prisma-next/errors": "0.5.0-dev.41",
37
35
  "@prisma-next/test-utils": "0.0.1",
36
+ "@prisma-next/tsconfig": "0.0.0",
38
37
  "@prisma-next/tsdown": "0.0.0",
39
- "@prisma-next/driver-postgres": "0.5.0-dev.30"
38
+ "@prisma-next/extension-pgvector": "0.5.0-dev.41"
40
39
  },
41
40
  "exports": {
42
41
  "./adapter": "./dist/adapter.mjs",
@@ -29,12 +29,6 @@ import {
29
29
  SQL_CHAR_CODEC_ID,
30
30
  SQL_VARCHAR_CODEC_ID,
31
31
  } from '@prisma-next/target-postgres/codec-ids';
32
- import {
33
- extractStandardSchemaOutputJsonSchema,
34
- extractStandardSchemaTypeExpression,
35
- isStandardSchemaLike,
36
- type StandardSchemaLike,
37
- } from '../core/standard-schema';
38
32
 
39
33
  export const textColumn = {
40
34
  codecId: PG_TEXT_CODEC_ID,
@@ -164,68 +158,29 @@ export function intervalColumn(precision?: number): ColumnTypeDescriptor & {
164
158
  } as const;
165
159
  }
166
160
 
161
+ /**
162
+ * Postgres `json` column descriptor — untyped raw JSON.
163
+ *
164
+ * For schema-typed JSON columns, use the per-library extension package
165
+ * (`@prisma-next/extension-arktype-json` ships `arktypeJson(schema)` for
166
+ * arktype). The schema-accepting `json(schema)` / `jsonb(schema)`
167
+ * overloads previously shipped from this module retired in Phase C of
168
+ * the codec-registry-unification project — see spec § AC-7.
169
+ */
167
170
  export const jsonColumn = {
168
171
  codecId: PG_JSON_CODEC_ID,
169
172
  nativeType: 'json',
170
173
  } as const satisfies ColumnTypeDescriptor;
171
174
 
175
+ /**
176
+ * Postgres `jsonb` column descriptor — untyped raw JSONB. Same retirement
177
+ * note as {@link jsonColumn}.
178
+ */
172
179
  export const jsonbColumn = {
173
180
  codecId: PG_JSONB_CODEC_ID,
174
181
  nativeType: 'jsonb',
175
182
  } as const satisfies ColumnTypeDescriptor;
176
183
 
177
- type JsonSchemaTypeParams = {
178
- readonly schemaJson: Record<string, unknown>;
179
- readonly type?: string;
180
- };
181
-
182
- function createJsonTypeParams(schema: StandardSchemaLike): JsonSchemaTypeParams {
183
- const outputSchema = extractStandardSchemaOutputJsonSchema(schema);
184
- if (!outputSchema) {
185
- throw new Error('JSON schema must expose ~standard.jsonSchema.output()');
186
- }
187
-
188
- const expression = extractStandardSchemaTypeExpression(schema);
189
- if (expression) {
190
- return { schemaJson: outputSchema, type: expression };
191
- }
192
-
193
- return { schemaJson: outputSchema };
194
- }
195
-
196
- function createJsonColumnFactory(
197
- codecId: string,
198
- nativeType: string,
199
- staticDescriptor: ColumnTypeDescriptor,
200
- ) {
201
- return (schema?: StandardSchemaLike): ColumnTypeDescriptor => {
202
- if (!schema) {
203
- return staticDescriptor;
204
- }
205
-
206
- if (!isStandardSchemaLike(schema)) {
207
- throw new Error(`${nativeType}(schema) expects a Standard Schema value`);
208
- }
209
-
210
- return {
211
- codecId,
212
- nativeType,
213
- typeParams: createJsonTypeParams(schema),
214
- };
215
- };
216
- }
217
-
218
- const _json = createJsonColumnFactory(PG_JSON_CODEC_ID, 'json', jsonColumn);
219
- const _jsonb = createJsonColumnFactory(PG_JSONB_CODEC_ID, 'jsonb', jsonbColumn);
220
-
221
- export function json(schema?: StandardSchemaLike): ColumnTypeDescriptor {
222
- return _json(schema);
223
- }
224
-
225
- export function jsonb(schema?: StandardSchemaLike): ColumnTypeDescriptor {
226
- return _jsonb(schema);
227
- }
228
-
229
184
  export function enumType<const Values extends readonly string[]>(
230
185
  name: string,
231
186
  values: Values,
@@ -9,15 +9,9 @@ import type {
9
9
  RuntimeParameterizedCodecDescriptor,
10
10
  SqlRuntimeAdapterDescriptor,
11
11
  } from '@prisma-next/sql-runtime';
12
- import { PG_JSON_CODEC_ID, PG_JSONB_CODEC_ID } from '@prisma-next/target-postgres/codec-ids';
13
12
  import { codecDefinitions } from '@prisma-next/target-postgres/codecs';
14
- import { type as arktype } from 'arktype';
15
13
  import { createPostgresAdapter } from '../core/adapter';
16
14
  import { postgresAdapterDescriptorMeta, postgresQueryOperations } from '../core/descriptor-meta';
17
- import {
18
- compileJsonSchemaValidator,
19
- type JsonSchemaValidateFn,
20
- } from '../core/json-schema-validator';
21
15
  import type { PostgresContract, PostgresLoweredStatement } from '../core/types';
22
16
 
23
17
  export interface SqlRuntimeAdapter
@@ -32,20 +26,6 @@ function createPostgresCodecRegistry(): CodecRegistry {
32
26
  return registry;
33
27
  }
34
28
 
35
- const jsonTypeParamsSchema = arktype({
36
- schemaJson: 'object',
37
- 'type?': 'string',
38
- });
39
-
40
- /** The inferred type params shape from the arktype schema. */
41
- type JsonTypeParams = typeof jsonTypeParamsSchema.infer;
42
-
43
- /**
44
- * Helper returned by the JSON/JSONB `init` hook.
45
- * Contains a compiled JSON Schema validate function for runtime conformance checks.
46
- */
47
- export type JsonCodecHelper = { readonly validate: JsonSchemaValidateFn };
48
-
49
29
  function createPostgresMutationDefaultGenerators() {
50
30
  return builtinGeneratorIds.map((id) => ({
51
31
  id,
@@ -56,24 +36,18 @@ function createPostgresMutationDefaultGenerators() {
56
36
  }));
57
37
  }
58
38
 
59
- function initJsonCodecHelper(params: JsonTypeParams): JsonCodecHelper {
60
- return { validate: compileJsonSchemaValidator(params.schemaJson as Record<string, unknown>) };
61
- }
62
-
63
- const parameterizedCodecDescriptors = [
64
- {
65
- codecId: PG_JSON_CODEC_ID,
66
- paramsSchema: jsonTypeParamsSchema,
67
- init: initJsonCodecHelper,
68
- },
69
- {
70
- codecId: PG_JSONB_CODEC_ID,
71
- paramsSchema: jsonTypeParamsSchema,
72
- init: initJsonCodecHelper,
73
- },
74
- ] as const satisfies ReadonlyArray<
75
- RuntimeParameterizedCodecDescriptor<JsonTypeParams, JsonCodecHelper>
76
- >;
39
+ /**
40
+ * Phase C of codec-registry-unification: the postgres adapter retains
41
+ * only static raw-JSON / raw-JSONB column descriptors. Schema-typed JSON
42
+ * columns ship from per-library extension packages now —
43
+ * `@prisma-next/extension-arktype-json` for arktype, future zod / valibot
44
+ * extensions when each lands. The previously-shipped
45
+ * `parameterizedCodecDescriptors` for `pg/json@1` / `pg/jsonb@1` retired
46
+ * with the schema-typed surface; the unified descriptor map auto-lifts
47
+ * the raw json/jsonb codecs from `codecs:` via the synthesis bridge for
48
+ * codec-id-keyed metadata reads.
49
+ */
50
+ const parameterizedCodecDescriptors: ReadonlyArray<RuntimeParameterizedCodecDescriptor> = [];
77
51
 
78
52
  const postgresRuntimeAdapterDescriptor: SqlRuntimeAdapterDescriptor<'postgres', SqlRuntimeAdapter> =
79
53
  {
@@ -1,54 +0,0 @@
1
- import type {
2
- JsonSchemaValidateFn,
3
- JsonSchemaValidationError,
4
- JsonSchemaValidationResult,
5
- } from '@prisma-next/sql-relational-core/query-lane-context';
6
- import Ajv from 'ajv';
7
-
8
- export type { JsonSchemaValidateFn, JsonSchemaValidationError, JsonSchemaValidationResult };
9
-
10
- /**
11
- * Shared Ajv instance for all JSON Schema validators.
12
- * Reusing a single instance avoids ~50-100KB memory overhead per compiled schema.
13
- */
14
- let sharedAjv: Ajv | undefined;
15
-
16
- function getSharedAjv(): Ajv {
17
- if (!sharedAjv) {
18
- sharedAjv = new Ajv({ allErrors: false, strict: false });
19
- }
20
- return sharedAjv;
21
- }
22
-
23
- /**
24
- * Compiles a JSON Schema object into a reusable validate function using Ajv.
25
- *
26
- * The returned function validates a value against the schema and returns
27
- * a structured result with error details on failure.
28
- *
29
- * Uses a shared Ajv instance and fail-fast mode (`allErrors: false`)
30
- * to minimize memory and CPU overhead.
31
- *
32
- * @param schema - A JSON Schema object (draft-07 compatible)
33
- * @returns A validate function
34
- */
35
- export function compileJsonSchemaValidator(schema: Record<string, unknown>): JsonSchemaValidateFn {
36
- const ajv = getSharedAjv();
37
- const validate = ajv.compile(schema);
38
-
39
- return (value: unknown): JsonSchemaValidationResult => {
40
- const valid = validate(value);
41
- if (valid) {
42
- return { valid: true };
43
- }
44
-
45
- // biome-ignore lint/style/noNonNullAssertion: Ajv guarantees `errors` is populated whenever `validate(...)` returns false.
46
- const errors: JsonSchemaValidationError[] = validate.errors!.map((err) => ({
47
- path: err.instancePath || '/',
48
- message: err.message ?? 'unknown validation error',
49
- keyword: err.keyword,
50
- }));
51
-
52
- return { valid: false, errors };
53
- };
54
- }
@@ -1,71 +0,0 @@
1
- type UnknownRecord = Record<string, unknown>;
2
-
3
- type StandardSchemaJsonSchemaField = {
4
- readonly output?: unknown;
5
- };
6
-
7
- /**
8
- * Runtime view of the Standard Schema protocol.
9
- * Reads `~standard.jsonSchema.output` for the serializable JSON Schema representation,
10
- * and `.expression` for an optional TypeScript type expression string (Arktype-specific).
11
- *
12
- * This differs from the compile-time `StandardSchemaLike` in `codec-types.ts`, which reads
13
- * `~standard.types.output` for TypeScript type narrowing in contract.d.ts.
14
- */
15
- export type StandardSchemaLike = {
16
- readonly '~standard'?: {
17
- readonly version?: number;
18
- readonly jsonSchema?: StandardSchemaJsonSchemaField;
19
- };
20
- readonly expression?: unknown;
21
- };
22
-
23
- function isObjectLike(value: unknown): value is UnknownRecord {
24
- return (typeof value === 'object' || typeof value === 'function') && value !== null;
25
- }
26
-
27
- function resolveOutputJsonSchemaField(schema: StandardSchemaLike): unknown {
28
- const jsonSchema = schema['~standard']?.jsonSchema;
29
- if (!jsonSchema) {
30
- return undefined;
31
- }
32
-
33
- if (typeof jsonSchema.output === 'function') {
34
- return jsonSchema.output({
35
- target: 'draft-07',
36
- });
37
- }
38
-
39
- return jsonSchema.output;
40
- }
41
-
42
- export function extractStandardSchemaOutputJsonSchema(
43
- schema: StandardSchemaLike,
44
- ): UnknownRecord | undefined {
45
- const outputSchema = resolveOutputJsonSchemaField(schema);
46
- if (!isObjectLike(outputSchema)) {
47
- return undefined;
48
- }
49
-
50
- return outputSchema;
51
- }
52
-
53
- export function extractStandardSchemaTypeExpression(
54
- schema: StandardSchemaLike,
55
- ): string | undefined {
56
- const expression = schema.expression;
57
- if (typeof expression !== 'string') {
58
- return undefined;
59
- }
60
-
61
- const trimmedExpression = expression.trim();
62
- if (trimmedExpression.length === 0) {
63
- return undefined;
64
- }
65
-
66
- return trimmedExpression;
67
- }
68
-
69
- export function isStandardSchemaLike(value: unknown): value is StandardSchemaLike {
70
- return isObjectLike(value) && isObjectLike((value as StandardSchemaLike)['~standard']);
71
- }