@prisma-next/adapter-postgres 0.11.0 → 0.12.0-dev.10
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 +13 -20
- package/dist/{adapter-DWa9-y1t.mjs → adapter-H8BiuXdq.mjs} +18 -5
- package/dist/adapter-H8BiuXdq.mjs.map +1 -0
- package/dist/adapter.d.mts +4 -1
- package/dist/adapter.d.mts.map +1 -1
- package/dist/adapter.mjs +2 -2
- package/dist/column-types.d.mts.map +1 -1
- package/dist/column-types.mjs.map +1 -1
- package/dist/control.d.mts +11 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +67 -6
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-ZIv9PU-5.mjs → descriptor-meta-C1wNCHkd.mjs} +5 -3
- package/dist/descriptor-meta-C1wNCHkd.mjs.map +1 -0
- package/dist/operation-types.d.mts.map +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -2
- package/dist/runtime.mjs.map +1 -1
- package/dist/{sql-renderer-DFMHmkt_.mjs → sql-renderer-DlZhVI9B.mjs} +12 -2
- package/dist/sql-renderer-DlZhVI9B.mjs.map +1 -0
- package/dist/types-B1eiuBHQ.d.mts.map +1 -1
- package/package.json +37 -26
- package/src/core/adapter.ts +25 -0
- package/src/core/control-adapter.ts +125 -11
- package/src/core/descriptor-meta.ts +2 -0
- package/src/core/sql-renderer.ts +33 -0
- package/src/exports/adapter.ts +1 -1
- package/src/exports/runtime.ts +2 -1
- package/dist/adapter-DWa9-y1t.mjs.map +0 -1
- package/dist/descriptor-meta-ZIv9PU-5.mjs.map +0 -1
- package/dist/sql-renderer-DFMHmkt_.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Provide PostgreSQL-specific adapter implementation, codecs, and capabilities. En
|
|
|
20
20
|
|
|
21
21
|
- **Adapter Implementation**: Implement `Adapter` SPI for PostgreSQL
|
|
22
22
|
- Lower SQL ASTs to PostgreSQL dialect SQL
|
|
23
|
-
- Render
|
|
23
|
+
- Render JSON aggregation (`json_agg`, `json_build_object`) and scalar subqueries
|
|
24
24
|
- Advertise PostgreSQL capabilities (`lateral`, `jsonAgg`)
|
|
25
25
|
- Normalize PostgreSQL EXPLAIN output
|
|
26
26
|
- Map PostgreSQL errors to `RuntimeError` envelope
|
|
@@ -89,8 +89,8 @@ flowchart TD
|
|
|
89
89
|
**Adapter (`adapter.ts`)**
|
|
90
90
|
- Main adapter implementation
|
|
91
91
|
- Lowers SQL ASTs to PostgreSQL SQL
|
|
92
|
-
- Renders joins (INNER, LEFT, RIGHT, FULL) with ON conditions
|
|
93
|
-
- Renders
|
|
92
|
+
- Renders joins (INNER, LEFT, RIGHT, FULL, LATERAL) with ON conditions
|
|
93
|
+
- Renders JSON aggregation (`json_agg`, `json_build_object`) and scalar subqueries
|
|
94
94
|
- Renders DML operations (INSERT, UPDATE, DELETE) with RETURNING clauses
|
|
95
95
|
- Advertises PostgreSQL capabilities (`lateral`, `jsonAgg`, `returning`)
|
|
96
96
|
- Maps PostgreSQL errors to `RuntimeError`
|
|
@@ -191,8 +191,8 @@ The adapter declares the following PostgreSQL capabilities:
|
|
|
191
191
|
|
|
192
192
|
- **`orderBy: true`** - Supports ORDER BY clauses
|
|
193
193
|
- **`limit: true`** - Supports LIMIT clauses
|
|
194
|
-
- **`lateral: true`** - Supports LATERAL joins
|
|
195
|
-
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`)
|
|
194
|
+
- **`lateral: true`** - Supports LATERAL joins
|
|
195
|
+
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`)
|
|
196
196
|
- **`returning: true`** - Supports RETURNING clauses for DML operations (INSERT, UPDATE, DELETE)
|
|
197
197
|
- **`sql.enums: true`** - Supports contract-defined enum storage types
|
|
198
198
|
|
|
@@ -205,29 +205,22 @@ The capabilities on the descriptor must match the capabilities in code. If they
|
|
|
205
205
|
|
|
206
206
|
See `docs/reference/capabilities.md` and `docs/architecture docs/subsystems/5. Adapters & Targets.md` for details.
|
|
207
207
|
|
|
208
|
-
##
|
|
208
|
+
## JSON Aggregation
|
|
209
209
|
|
|
210
|
-
The
|
|
210
|
+
The renderer lowers JSON-aggregation AST nodes to PostgreSQL's `json_agg`:
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
- When both `ORDER BY` and `LIMIT` are present, wraps the query in an inner SELECT that projects individual columns with aliases, then uses `json_agg(row_to_json(sub.*))` on the result
|
|
216
|
-
- Uses different aliases for the table (`{alias}_lateral`) and column (`{alias}`) to avoid ambiguity
|
|
217
|
-
|
|
218
|
-
**Capabilities Required:**
|
|
219
|
-
- `lateral: true` - Enables LATERAL join support
|
|
220
|
-
- `jsonAgg: true` - Enables `json_agg` function support
|
|
212
|
+
- `json_agg(json_build_object(...))` aggregates a row set into a JSON array of objects
|
|
213
|
+
- A scalar subquery (`SubqueryExpr`) in the SELECT list correlates against the outer row through its WHERE clause
|
|
214
|
+
- When the subquery carries an inner `ORDER BY` and `LIMIT`, its rows are wrapped in an inner SELECT, then aggregated with `json_agg(row_to_json(sub.*))`
|
|
221
215
|
|
|
222
216
|
**Example SQL Output:**
|
|
223
217
|
```sql
|
|
224
|
-
SELECT "user"."id" AS "id",
|
|
225
|
-
FROM "user"
|
|
226
|
-
LEFT JOIN LATERAL (
|
|
218
|
+
SELECT "user"."id" AS "id", (
|
|
227
219
|
SELECT json_agg(json_build_object('id', "post"."id", 'title', "post"."title")) AS "posts"
|
|
228
220
|
FROM "post"
|
|
229
221
|
WHERE "user"."id" = "post"."userId"
|
|
230
|
-
) AS "
|
|
222
|
+
) AS "posts"
|
|
223
|
+
FROM "user"
|
|
231
224
|
```
|
|
232
225
|
|
|
233
226
|
## DML Operations with RETURNING
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-
|
|
1
|
+
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DlZhVI9B.mjs";
|
|
2
2
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { parseContractMarkerRow } from "@prisma-next/sql-runtime";
|
|
4
4
|
//#region src/core/adapter.ts
|
|
@@ -8,12 +8,14 @@ const defaultCapabilities = Object.freeze({
|
|
|
8
8
|
limit: true,
|
|
9
9
|
lateral: true,
|
|
10
10
|
jsonAgg: true,
|
|
11
|
-
returning: true
|
|
11
|
+
returning: true,
|
|
12
|
+
distinctOn: true
|
|
12
13
|
},
|
|
13
14
|
sql: {
|
|
14
15
|
enums: true,
|
|
15
16
|
returning: true,
|
|
16
|
-
defaultInInsert: true
|
|
17
|
+
defaultInInsert: true,
|
|
18
|
+
lateral: true
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
var PostgresAdapterImpl = class {
|
|
@@ -34,6 +36,17 @@ var PostgresAdapterImpl = class {
|
|
|
34
36
|
return renderLoweredSql(ast, context.contract, this.codecLookup);
|
|
35
37
|
}
|
|
36
38
|
};
|
|
39
|
+
/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */
|
|
40
|
+
const postgresRawCodecInferer = { inferCodec(value) {
|
|
41
|
+
switch (typeof value) {
|
|
42
|
+
case "number": return Number.isSafeInteger(value) && value % 1 === 0 ? "pg/int4" : "pg/float8";
|
|
43
|
+
case "bigint": return "pg/int8";
|
|
44
|
+
case "string": return "pg/text";
|
|
45
|
+
case "boolean": return "pg/bool";
|
|
46
|
+
case "object": if (value instanceof Uint8Array) return "pg/bytea";
|
|
47
|
+
}
|
|
48
|
+
throw new Error("unsupported JS value type for raw-SQL interpolation: wrap this value in `param(...)` with an explicit codec");
|
|
49
|
+
} };
|
|
37
50
|
async function readPostgresMarker(queryable) {
|
|
38
51
|
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
52
|
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];
|
|
@@ -47,6 +60,6 @@ function createPostgresAdapter(options) {
|
|
|
47
60
|
return Object.freeze(new PostgresAdapterImpl(options));
|
|
48
61
|
}
|
|
49
62
|
//#endregion
|
|
50
|
-
export { createPostgresAdapter as t };
|
|
63
|
+
export { postgresRawCodecInferer as n, createPostgresAdapter as t };
|
|
51
64
|
|
|
52
|
-
//# sourceMappingURL=adapter-
|
|
65
|
+
//# sourceMappingURL=adapter-H8BiuXdq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-H8BiuXdq.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 RawSqlLiteral,\n SqlQueryable,\n} from '@prisma-next/sql-relational-core/ast';\nimport type { RawCodecInferer } from '@prisma-next/sql-relational-core/expression';\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 distinctOn: true,\n },\n sql: {\n enums: true,\n returning: true,\n defaultInInsert: true,\n lateral: 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\n/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */\nexport const postgresRawCodecInferer: RawCodecInferer = {\n inferCodec(value: RawSqlLiteral): string {\n switch (typeof value) {\n case 'number':\n return Number.isSafeInteger(value) && value % 1 === 0 ? 'pg/int4' : 'pg/float8';\n case 'bigint':\n return 'pg/int8';\n case 'string':\n return 'pg/text';\n case 'boolean':\n return 'pg/bool';\n case 'object':\n if (value instanceof Uint8Array) return 'pg/bytea';\n }\n throw new Error(\n 'unsupported JS value type for raw-SQL interpolation: wrap this value in `param(...)` with an explicit codec',\n );\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":";;;;AAiBA,MAAM,sBAAsB,OAAO,OAAO;CACxC,UAAU;EACR,SAAS;EACT,OAAO;EACP,SAAS;EACT,SAAS;EACT,WAAW;EACX,YAAY;CACd;CACA,KAAK;EACH,OAAO;EACP,WAAW;EACX,iBAAiB;EACjB,SAAS;CACX;AACF,CAAC;AAED,IAAM,sBAAN,MAEA;CAEE,WAAoB;CACpB,WAAoB;CAEpB;CACA;CAEA,YAAY,SAAkC;EAC5C,KAAK,cAAc,SAAS,eAAe,iCAAiC;EAC5E,KAAK,UAAU,OAAO,OAAO;GAC3B,IAAI,SAAS,aAAa;GAC1B,QAAQ;GACR,cAAc;GACd,aAAa,cAA4B,mBAAmB,SAAS;EACvE,CAAC;CACH;CAEA,MAAM,KAAkB,SAAqE;EAC3F,OAAO,iBAAiB,KAAK,QAAQ,UAAU,KAAK,WAAW;CACjE;AACF;;AAGA,MAAa,0BAA2C,EACtD,WAAW,OAA8B;CACvC,QAAQ,OAAO,OAAf;EACE,KAAK,UACH,OAAO,OAAO,cAAc,KAAK,KAAK,QAAQ,MAAM,IAAI,YAAY;EACtE,KAAK,UACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,UACH,IAAI,iBAAiB,YAAY,OAAO;CAC5C;CACA,MAAM,IAAI,MACR,6GACF;AACF,EACF;AAEA,eAAe,mBAAmB,WAAoD;CAKpF,KAAI,MAJiB,UAAU,MAC7B,uFACA,CAAC,mBAAmB,QAAQ,CAC9B,GACW,KAAK,WAAW,GACzB,OAAO,EAAE,MAAM,WAAW;CAO5B,MAAM,OAAM,MAJS,UAAU,MAC7B,wJACA,CAAC,YAAY,CACf,GACmB,KAAK;CACxB,IAAI,CAAC,KACH,OAAO,EAAE,MAAM,SAAS;CAG1B,OAAO;EAAE,MAAM;EAAW,QAAQ,uBAAuB,GAAG;CAAE;AAChE;AAEA,SAAgB,sBAAsB,SAAkC;CACtE,OAAO,OAAO,OAAO,IAAI,oBAAoB,OAAO,CAAC;AACvD"}
|
package/dist/adapter.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { c as PostgresContract, l as PostgresLoweredStatement, s as PostgresAdapterOptions } from "./types-B1eiuBHQ.mjs";
|
|
2
2
|
import { Adapter, AdapterProfile, AnyQueryAst, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
3
|
+
import { RawCodecInferer } from "@prisma-next/sql-relational-core/expression";
|
|
3
4
|
|
|
4
5
|
//#region src/core/adapter.d.ts
|
|
5
6
|
declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContract, PostgresLoweredStatement> {
|
|
@@ -10,7 +11,9 @@ declare class PostgresAdapterImpl implements Adapter<AnyQueryAst, PostgresContra
|
|
|
10
11
|
constructor(options?: PostgresAdapterOptions);
|
|
11
12
|
lower(ast: AnyQueryAst, context: LowererContext<PostgresContract>): PostgresLoweredStatement;
|
|
12
13
|
}
|
|
14
|
+
/** Codec-id lookup for bare-literal interpolations used by `fns.raw` on a postgres client. Contributed as the descriptor's static `rawCodecInferer` slot. */
|
|
15
|
+
declare const postgresRawCodecInferer: RawCodecInferer;
|
|
13
16
|
declare function createPostgresAdapter(options?: PostgresAdapterOptions): Readonly<PostgresAdapterImpl>;
|
|
14
17
|
//#endregion
|
|
15
|
-
export { createPostgresAdapter };
|
|
18
|
+
export { createPostgresAdapter, postgresRawCodecInferer };
|
|
16
19
|
//# sourceMappingURL=adapter.d.mts.map
|
package/dist/adapter.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.mts","names":[],"sources":["../src/core/adapter.ts"],"mappings":";;;;;cAkCM,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;;cAMzD,uBAAA,EAAyB,eAkBrC;AAAA,iBAuBe,qBAAA,CAAsB,OAAA,GAAU,sBAAA,GAAsB,QAAA,CAAA,mBAAA"}
|
package/dist/adapter.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPostgresAdapter } from "./adapter-
|
|
2
|
-
export { createPostgresAdapter };
|
|
1
|
+
import { n as postgresRawCodecInferer, t as createPostgresAdapter } from "./adapter-H8BiuXdq.mjs";
|
|
2
|
+
export { createPostgresAdapter, postgresRawCodecInferer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"mappings":";;;;cAgCa,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,UAAA,CAAW,MAAA,WAAiB,
|
|
1
|
+
{"version":3,"file":"column-types.d.mts","names":[],"sources":["../src/exports/column-types.ts"],"mappings":";;;;cAgCa,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,UAAA,CAAW,MAAA,WAAiB,oBAAoB;EAAA,SACrD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;AAAA,iBASlB,aAAA,CAAc,MAAA,WAAiB,oBAAoB;EAAA,SACxD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;AAAA,cASrB,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,YAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,YAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,aAAA,CACd,SAAA,UACA,KAAA,YACC,oBAAoB;EAAA,SACZ,UAAA;IAAA,SAAuB,SAAA;IAAA,SAA4B,KAAA;EAAA;AAAA;AAAA,cASjD,eAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,cAE5B,iBAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,UAAA,CAAW,SAAA,YAAqB,oBAAoB;EAAA,SACzD,UAAA;IAAA,SAAwB,SAAA;EAAA;AAAA;AAAA,iBASnB,YAAA,CAAa,SAAA,YAAqB,oBAAoB;EAAA,SAC3D,UAAA;IAAA,SAAwB,SAAA;EAAA;AAAA;AAAA,cAStB,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,SAAA,CAAU,MAAA,WAAiB,oBAAoB;EAAA,SACpD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;AAAA,iBASlB,YAAA,CAAa,MAAA,WAAiB,oBAAoB;EAAA,SACvD,UAAA;IAAA,SAAuB,MAAA;EAAA;AAAA;;;;;;cAcrB,WAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,cAAA,CAAe,SAAA,YAAqB,oBAAoB;EAAA,SAC7D,UAAA;IAAA,SAAwB,SAAA;EAAA;AAAA;;;AA7CS;AAS5C;;cAkDa,UAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;;;;cAK5B,WAAA;EAAA,SAG4B,OAAA;EAAA,SAAA,UAAA;AAAA;AAAA,iBAEzB,QAAA,wCAAA,CACd,IAAA,UACA,MAAA,EAAQ,MAAA,GACP,gBAAgB;AAAA,iBAIH,UAAA,yBAAA,CACd,QAAA,EAAU,QAAA,EACV,UAAA,WACC,oBAAA;EAAA,SAAkC,OAAA,EAAS,QAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
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 {\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';\nimport { PostgresEnumType } from '@prisma-next/target-postgres/types';\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): PostgresEnumType {\n return new PostgresEnumType({ name, nativeType: name, values });\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;
|
|
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 {\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';\nimport { PostgresEnumType } from '@prisma-next/target-postgres/types';\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): PostgresEnumType {\n return new PostgresEnumType({ name, nativeType: name, values });\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;AACd;AAEA,SAAgB,WAAW,QAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,SAAgB,cAAc,QAE5B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;AACd;AAEA,MAAa,eAAe;CAC1B,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,cACd,WACA,OAGA;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,UAAU,KAAA,IAAY,EAAE,UAAU,IAAI;GAAE;GAAW;EAAM;CACvE;AACF;AAEA,MAAa,kBAAkB;CAC7B,SAAS;CACT,YAAY;AACd;AAEA,MAAa,oBAAoB;CAC/B,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,WAAW,WAEzB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE;CACjE;AACF;AAEA,SAAgB,aAAa,WAE3B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE;CACjE;AACF;AAEA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,UAAU,QAExB;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;AAEA,SAAgB,aAAa,QAE3B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,YAAY,EAAE,OAAO;CACvB;AACF;;;;;;AAOA,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,eAAe,WAE7B;CACA,OAAO;EACL,SAAS;EACT,YAAY;EACZ,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE;CACjE;AACF;;;;;;AAOA,MAAa,aAAa;CACxB,SAAS;CACT,YAAY;AACd;;;;AAKA,MAAa,cAAc;CACzB,SAAS;CACT,YAAY;AACd;AAEA,SAAgB,SACd,MACA,QACkB;CAClB,OAAO,IAAI,iBAAiB;EAAE;EAAM,YAAY;EAAM;CAAO,CAAC;AAChE;AAEA,SAAgB,WACd,UACA,YACuD;CACvD,OAAO;EACL,SAAS;EACT;EACA,SAAS;CACX;AACF"}
|
package/dist/control.d.mts
CHANGED
|
@@ -4,9 +4,9 @@ import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@pr
|
|
|
4
4
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
5
5
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
6
6
|
import { SqlControlAdapterDescriptor } from "@prisma-next/family-sql/control";
|
|
7
|
-
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
7
|
+
import { Contract, ContractMarkerRecord, LedgerEntryRecord } from "@prisma-next/contract/types";
|
|
8
8
|
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
9
|
-
import { PostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
9
|
+
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
10
10
|
import { SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
11
11
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
12
12
|
|
|
@@ -44,7 +44,8 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
44
44
|
* the family-level schema verifier walk enum types without reaching
|
|
45
45
|
* into target-specific annotation layouts itself.
|
|
46
46
|
*/
|
|
47
|
-
readonly resolveExistingEnumValues: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry) => readonly string[] | null;
|
|
47
|
+
readonly resolveExistingEnumValues: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
48
|
+
readonly resolveExistingEnumValuesForContract: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
48
49
|
/**
|
|
49
50
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
50
51
|
*
|
|
@@ -70,6 +71,13 @@ declare class PostgresControlAdapter implements SqlControlAdapter<'postgres'> {
|
|
|
70
71
|
* map rather than raising "relation does not exist".
|
|
71
72
|
*/
|
|
72
73
|
readAllMarkers(driver: ControlDriverInstance<'sql', 'postgres'>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
74
|
+
/**
|
|
75
|
+
* Reads per-migration ledger rows for `space` from `prisma_contract.ledger`
|
|
76
|
+
* in apply order. Probes `information_schema.tables` first so a fresh
|
|
77
|
+
* database without the ledger table returns `[]` instead of raising
|
|
78
|
+
* "relation does not exist".
|
|
79
|
+
*/
|
|
80
|
+
readLedger(driver: ControlDriverInstance<'sql', 'postgres'>, space: string): Promise<readonly LedgerEntryRecord[]>;
|
|
73
81
|
/**
|
|
74
82
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
75
83
|
*
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-adapter.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;;;;cAwDa,sBAAA,YAAkC,iBAAA;EAAA,SACpC,QAAA;EAAA,SACA,QAAA;EAAA,iBAEQ,WAAA;EAiBQ;;;;;;;cARb,WAAA,GAAc,WAAA;EA8Cf;;;;EAAA,SAtCF,gBAAA,SAAgB,sBAAA;EAqDtB;;;;;EAAA,SA9CM,mBAAA,SAAmB,2BAAA;EAyKR;;;;;;EAAA,SAjKX,yBAAA,GACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAAA,SASO,oCAAA,GAAwC,QAAA,EAAU,QAAA,CAAS,UAAA,OAAW,MAAA,EAAA,WAAA,EAAA,QAAA,EAAA,wBAAA,EAAA,WAAA;EAhDlC;;;;;;;;EA2D7C,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;EA/BlD;;;;;;;;EA2CH,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,WACC,OAAA,CAAQ,oBAAA;EA1BgD;;;;;;EAiFrD,cAAA,CACJ,MAAA,EAAQ,qBAAA,sBACP,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAnFgD;;;;;;EAkJzE,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,KAAA,WACC,OAAA,UAAiB,iBAAA;EA9Hd;;;;;;;;;;;;;;;;;;;;;;;;EA4MA,UAAA,CACJ,MAAA,EAAQ,qBAAA,qBACR,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EA8BG;;;;;AAmfkB;;;EAnflB,QAAA,mBAAA;EC7VV;;;;AAAsD;;;EAAtD,QDkXU,oBAAA;;;;;;UAgEA,gBAAA;;;;UA8ZA,kBAAA;AAAA;;;cCh1BV,yBAAA,EAA2B,2BAA2B"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-
|
|
2
|
-
import { t as postgresAdapterDescriptorMeta } from "./descriptor-meta-
|
|
1
|
+
import { n as createPostgresBuiltinCodecLookup, t as renderLoweredSql } from "./sql-renderer-DlZhVI9B.mjs";
|
|
2
|
+
import { t as postgresAdapterDescriptorMeta } from "./descriptor-meta-C1wNCHkd.mjs";
|
|
3
3
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { SqlEscapeError, escapeLiteral, qualifyName, quoteIdentifier } from "@prisma-next/target-postgres/sql-utils";
|
|
5
5
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -8,10 +8,17 @@ import { parseMarkerRowSafely, withMarkerReadErrorHandling } from "@prisma-next/
|
|
|
8
8
|
import { parseContractMarkerRow } from "@prisma-next/family-sql/verify";
|
|
9
9
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
10
10
|
import { parsePostgresDefault, parsePostgresDefault as parsePostgresDefault$1 } from "@prisma-next/target-postgres/default-normalizer";
|
|
11
|
-
import { readExistingEnumValues } from "@prisma-next/target-postgres/enum-planning";
|
|
11
|
+
import { createResolveExistingEnumValues, enumStorageCompoundKey, readExistingEnumValues, readPostgresSchemaIrAnnotations } from "@prisma-next/target-postgres/enum-planning";
|
|
12
12
|
import { normalizeSchemaNativeType, normalizeSchemaNativeType as normalizeSchemaNativeType$1 } from "@prisma-next/target-postgres/native-type-normalizer";
|
|
13
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
13
14
|
import { timestampNowControlDescriptor } from "@prisma-next/family-sql/control";
|
|
14
15
|
import { builtinGeneratorRegistryMetadata, resolveBuiltinGeneratedColumnDescriptor } from "@prisma-next/ids";
|
|
16
|
+
//#region ../../../1-framework/3-tooling/migration/dist/exports/ledger-origin.mjs
|
|
17
|
+
function ledgerOriginFromStored(originCoreHash) {
|
|
18
|
+
if (originCoreHash === null || originCoreHash === "" || originCoreHash === "sha256:empty") return null;
|
|
19
|
+
return originCoreHash;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
15
22
|
//#region src/core/enum-control-hooks.ts
|
|
16
23
|
const ENUM_INTROSPECT_QUERY = `
|
|
17
24
|
SELECT
|
|
@@ -105,6 +112,7 @@ async function introspectPostgresEnumTypes(options) {
|
|
|
105
112
|
//#endregion
|
|
106
113
|
//#region src/core/control-adapter.ts
|
|
107
114
|
const POSTGRES_MARKER_TABLE = "prisma_contract.marker";
|
|
115
|
+
const POSTGRES_LEDGER_TABLE = "prisma_contract.ledger";
|
|
108
116
|
/**
|
|
109
117
|
* Postgres control plane adapter for control-plane operations like introspection.
|
|
110
118
|
* Provides target-specific implementations for control-plane domain actions.
|
|
@@ -140,7 +148,10 @@ var PostgresControlAdapter = class {
|
|
|
140
148
|
* the family-level schema verifier walk enum types without reaching
|
|
141
149
|
* into target-specific annotation layouts itself.
|
|
142
150
|
*/
|
|
143
|
-
resolveExistingEnumValues = (schema, enumType) =>
|
|
151
|
+
resolveExistingEnumValues = (schema, enumType, namespaceId) => {
|
|
152
|
+
return readExistingEnumValues(schema, namespaceId === UNBOUND_NAMESPACE_ID ? readPostgresSchemaIrAnnotations(schema).schema ?? "public" : namespaceId, enumType.nativeType);
|
|
153
|
+
};
|
|
154
|
+
resolveExistingEnumValuesForContract = (contract) => createResolveExistingEnumValues(contract.storage);
|
|
144
155
|
/**
|
|
145
156
|
* Lower a SQL query AST into a Postgres-flavored `{ sql, params }` payload.
|
|
146
157
|
*
|
|
@@ -215,6 +226,40 @@ var PostgresControlAdapter = class {
|
|
|
215
226
|
return rows;
|
|
216
227
|
}
|
|
217
228
|
/**
|
|
229
|
+
* Reads per-migration ledger rows for `space` from `prisma_contract.ledger`
|
|
230
|
+
* in apply order. Probes `information_schema.tables` first so a fresh
|
|
231
|
+
* database without the ledger table returns `[]` instead of raising
|
|
232
|
+
* "relation does not exist".
|
|
233
|
+
*/
|
|
234
|
+
async readLedger(driver, space) {
|
|
235
|
+
const ledgerContext = {
|
|
236
|
+
space,
|
|
237
|
+
markerLocation: POSTGRES_LEDGER_TABLE
|
|
238
|
+
};
|
|
239
|
+
if ((await withMarkerReadErrorHandling(() => driver.query(`select 1
|
|
240
|
+
from information_schema.tables
|
|
241
|
+
where table_schema = $1 and table_name = $2`, ["prisma_contract", "ledger"]), ledgerContext)).rows.length === 0) return [];
|
|
242
|
+
return (await withMarkerReadErrorHandling(() => driver.query(`select
|
|
243
|
+
space,
|
|
244
|
+
migration_name,
|
|
245
|
+
migration_hash,
|
|
246
|
+
origin_core_hash,
|
|
247
|
+
destination_core_hash,
|
|
248
|
+
operations,
|
|
249
|
+
created_at
|
|
250
|
+
from prisma_contract.ledger
|
|
251
|
+
where space = $1
|
|
252
|
+
order by id`, [space]), ledgerContext)).rows.map((row) => ({
|
|
253
|
+
space: row.space,
|
|
254
|
+
migrationName: row.migration_name,
|
|
255
|
+
migrationHash: row.migration_hash,
|
|
256
|
+
from: ledgerOriginFromStored(row.origin_core_hash),
|
|
257
|
+
to: row.destination_core_hash,
|
|
258
|
+
appliedAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at),
|
|
259
|
+
operationCount: Array.isArray(row.operations) ? row.operations.length : 0
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
218
263
|
* Introspects a Postgres database schema and returns a raw SqlSchemaIR.
|
|
219
264
|
*
|
|
220
265
|
* This is a pure schema discovery operation that queries the Postgres catalog
|
|
@@ -290,10 +335,24 @@ var PostgresControlAdapter = class {
|
|
|
290
335
|
const perSchema = await Promise.all(uniqueSchemas.map((s) => this.introspectSchema(driver, s)));
|
|
291
336
|
const mergedTables = {};
|
|
292
337
|
for (const ir of perSchema) for (const [tableName, table] of Object.entries(ir.tables)) mergedTables[tableName] = table;
|
|
338
|
+
const mergedStorageTypes = {};
|
|
339
|
+
for (let i = 0; i < perSchema.length; i++) {
|
|
340
|
+
const ir = perSchema[i];
|
|
341
|
+
const pg = blindCast(ir?.annotations?.["pg"])?.storageTypes;
|
|
342
|
+
if (!pg) continue;
|
|
343
|
+
for (const [key, value] of Object.entries(pg)) mergedStorageTypes[key] = value;
|
|
344
|
+
}
|
|
293
345
|
const firstAnnotations = perSchema[0]?.annotations;
|
|
346
|
+
const firstPg = blindCast(firstAnnotations?.["pg"]) ?? {};
|
|
294
347
|
return {
|
|
295
348
|
tables: mergedTables,
|
|
296
|
-
...ifDefined("annotations",
|
|
349
|
+
...ifDefined("annotations", {
|
|
350
|
+
...firstAnnotations,
|
|
351
|
+
pg: {
|
|
352
|
+
...firstPg,
|
|
353
|
+
...ifDefined("storageTypes", Object.keys(mergedStorageTypes).length > 0 ? mergedStorageTypes : void 0)
|
|
354
|
+
}
|
|
355
|
+
})
|
|
297
356
|
};
|
|
298
357
|
}
|
|
299
358
|
/**
|
|
@@ -532,10 +591,12 @@ var PostgresControlAdapter = class {
|
|
|
532
591
|
indexes
|
|
533
592
|
};
|
|
534
593
|
}
|
|
535
|
-
const
|
|
594
|
+
const rawStorageTypes = await introspectPostgresEnumTypes({
|
|
536
595
|
driver,
|
|
537
596
|
schemaName: schema
|
|
538
597
|
});
|
|
598
|
+
const storageTypes = {};
|
|
599
|
+
for (const [typeName, annotation] of Object.entries(rawStorageTypes)) storageTypes[enumStorageCompoundKey(schema, typeName)] = annotation;
|
|
539
600
|
return {
|
|
540
601
|
tables,
|
|
541
602
|
annotations: { pg: {
|