@prisma-next/target-postgres 0.13.0 → 0.14.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{codec-ids-CTikp1if.mjs → codec-ids-BvytN2P8.mjs} +3 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-B1vOchLE.d.mts → codec-ids-CnXu9Qy3.d.mts} +3 -3
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-CnFiNML4.d.mts → codec-types-DHCkwPKE.d.mts} +3 -3
- package/dist/{codec-types-CnFiNML4.d.mts.map → codec-types-DHCkwPKE.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CBpEv4s5.d.mts → codecs--0A5_4Bq.d.mts} +26 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +28 -35
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +163 -15
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +4 -17
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +21 -27
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
- package/dist/data-transform-BOWpliq8.mjs.map +1 -0
- package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
- package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/ddl-QDyOSeLc.mjs +251 -0
- package/dist/ddl-QDyOSeLc.mjs.map +1 -0
- package/dist/ddl.d.mts +2 -2
- package/dist/ddl.mjs +2 -2
- package/dist/descriptor-meta-CpGygXpI.mjs +140 -0
- package/dist/descriptor-meta-CpGygXpI.mjs.map +1 -0
- package/dist/{issue-planner-Br0pt1Ea.mjs → issue-planner-DL6g3CmE.mjs} +52 -366
- package/dist/issue-planner-DL6g3CmE.mjs.map +1 -0
- package/dist/issue-planner.d.mts +8 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +5 -92
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/{nodes-DZk2JZG3.mjs → nodes-Bbhs2rwj.mjs} +31 -2
- package/dist/nodes-Bbhs2rwj.mjs.map +1 -0
- package/dist/{nodes-779hmCfL.d.mts → nodes-pLeLgdis.d.mts} +30 -3
- package/dist/nodes-pLeLgdis.d.mts.map +1 -0
- package/dist/{op-factory-call-D2aAUhmS.mjs → op-factory-call-D_p5vxwt.mjs} +601 -418
- package/dist/op-factory-call-D_p5vxwt.mjs.map +1 -0
- package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DmQEc3XV.d.mts} +119 -72
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +36 -15
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CAYPJObw.mjs → planner-Bs_baQax.mjs} +25 -45
- package/dist/planner-Bs_baQax.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-NSEhWL0L.mjs → planner-produced-postgres-migration-Cji5vxUf.mjs} +6 -4
- package/dist/planner-produced-postgres-migration-Cji5vxUf.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +5 -6
- package/dist/planner-produced-postgres-migration-QqHa2C2l.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
- package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
- package/dist/planner-sql-checks.d.mts +3 -49
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +2 -2
- package/dist/{planner-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
- package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
- package/dist/planner.d.mts +4 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-k3TAcPMY.mjs} +30 -37
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +1 -0
- package/dist/postgres-migration-B5jKrXv3.mjs +145 -0
- package/dist/postgres-migration-B5jKrXv3.mjs.map +1 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
- package/dist/{postgres-schema-BuxCxbvB.mjs → postgres-schema-COGZ1ark.mjs} +82 -23
- package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
- package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
- package/dist/render-ops-BREh1kHe.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -2
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/runtime.d.mts +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/table-source-BvFo7gVs.d.mts +15 -0
- package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
- package/dist/types.d.mts +34 -19
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -3
- package/package.json +17 -18
- package/src/contract-free/checks.ts +363 -0
- package/src/contract-free/ddl.ts +28 -1
- package/src/core/authoring.ts +43 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +1 -1
- package/src/core/codec-type-map.ts +2 -2
- package/src/core/codecs.ts +43 -48
- package/src/core/ddl/nodes.ts +59 -1
- package/src/core/migrations/control-policy.ts +17 -47
- package/src/core/migrations/issue-planner.ts +34 -70
- package/src/core/migrations/op-factory-call.ts +486 -215
- package/src/core/migrations/operations/columns.ts +175 -140
- package/src/core/migrations/operations/constraints.ts +79 -108
- package/src/core/migrations/operations/data-transform.ts +15 -18
- package/src/core/migrations/operations/dependencies.ts +16 -14
- package/src/core/migrations/operations/indexes.ts +31 -28
- package/src/core/migrations/operations/shared.ts +2 -2
- package/src/core/migrations/operations/tables.ts +13 -14
- package/src/core/migrations/planner-ddl-builders.ts +3 -4
- package/src/core/migrations/planner-identity-values.ts +4 -28
- package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
- package/src/core/migrations/planner-recipes.ts +44 -39
- package/src/core/migrations/planner-sql-checks.ts +3 -178
- package/src/core/migrations/planner-strategies.ts +76 -449
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +6 -6
- package/src/core/migrations/postgres-migration.ts +287 -7
- package/src/core/migrations/render-ops.ts +26 -13
- package/src/core/migrations/runner.ts +26 -20
- package/src/core/postgres-contract-serializer.ts +37 -54
- package/src/core/postgres-enum-type-schema.ts +17 -0
- package/src/core/postgres-schema.ts +86 -46
- package/src/exports/codecs.ts +2 -2
- package/src/exports/contract-free.ts +22 -1
- package/src/exports/control.ts +0 -22
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +1 -29
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/planner-sql-checks.ts +0 -7
- package/src/exports/types.ts +0 -1
- package/dist/codec-ids-B1vOchLE.d.mts.map +0 -1
- package/dist/codec-ids-CTikp1if.mjs.map +0 -1
- package/dist/codecs-CBpEv4s5.d.mts.map +0 -1
- package/dist/data-transform-D25tLeYU.mjs.map +0 -1
- package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
- package/dist/ddl-77SyXgFt.mjs +0 -30
- package/dist/ddl-77SyXgFt.mjs.map +0 -1
- package/dist/descriptor-meta-DKmj-IMN.mjs +0 -14
- package/dist/descriptor-meta-DKmj-IMN.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs +0 -130
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +0 -1
- package/dist/enum-planning-BCyvlFHk.mjs +0 -0
- package/dist/enum-planning-BCyvlFHk.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -86
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-Br0pt1Ea.mjs.map +0 -1
- package/dist/nodes-779hmCfL.d.mts.map +0 -1
- package/dist/nodes-DZk2JZG3.mjs.map +0 -1
- package/dist/op-factory-call-D2aAUhmS.mjs.map +0 -1
- package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
- package/dist/planner-CAYPJObw.mjs.map +0 -1
- package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
- package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +0 -1
- package/dist/planner-sql-checks-DAdhnI2c.mjs +0 -272
- package/dist/planner-sql-checks-DAdhnI2c.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +0 -1
- package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
- package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
- package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
- package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
- package/dist/postgres-migration-COore9Mz.mjs +0 -71
- package/dist/postgres-migration-COore9Mz.mjs.map +0 -1
- package/dist/postgres-migration-DZ_gLUOW.d.mts +0 -72
- package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
- package/dist/postgres-schema-BuxCxbvB.mjs.map +0 -1
- package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
- package/dist/shared-DarONYBZ.d.mts +0 -43
- package/dist/shared-DarONYBZ.d.mts.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -213
- package/src/core/migrations/operations/enums.ts +0 -114
- package/src/core/postgres-enum-type.ts +0 -89
- package/src/exports/enum-planning.ts +0 -11
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as PG_TEXT_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
|
|
2
2
|
import { n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { TableSource } from "@prisma-next/sql-relational-core/ast";
|
|
4
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
|
|
7
|
+
import { composeSqlEntityKinds } from "@prisma-next/sql-contract/entity-kinds";
|
|
8
|
+
import { cfExpr } from "@prisma-next/sql-relational-core/contract-free";
|
|
9
|
+
//#region src/core/ast/table-source.ts
|
|
10
|
+
var PostgresTableSource = class extends TableSource {
|
|
11
|
+
schema;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options.name, options.alias);
|
|
14
|
+
this.schema = options.schema;
|
|
15
|
+
this.freeze();
|
|
16
|
+
}
|
|
17
|
+
rewrite(rewriter) {
|
|
18
|
+
return rewriter.tableSource ? rewriter.tableSource(this) : this;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
5
22
|
//#region src/core/postgres-schema.ts
|
|
6
23
|
/**
|
|
7
24
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -9,7 +26,7 @@ import { StorageTable } from "@prisma-next/sql-contract/types";
|
|
|
9
26
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
10
27
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
11
28
|
*
|
|
12
|
-
* `entries` holds entity-kind
|
|
29
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
13
30
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
14
31
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
15
32
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -31,10 +48,13 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
31
48
|
constructor(input) {
|
|
32
49
|
super();
|
|
33
50
|
this.id = input.id;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
|
|
52
|
+
const valueSetRaw = dispatched["valueSet"];
|
|
53
|
+
const withPresence = valueSetRaw !== void 0 && Object.keys(valueSetRaw).length === 0 ? {
|
|
54
|
+
...dispatched,
|
|
55
|
+
valueSet: void 0
|
|
56
|
+
} : dispatched;
|
|
57
|
+
this.entries = Object.freeze(blindCast(withPresence));
|
|
38
58
|
Object.defineProperty(this, "kind", {
|
|
39
59
|
value: "schema",
|
|
40
60
|
writable: false,
|
|
@@ -43,6 +63,12 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
43
63
|
});
|
|
44
64
|
freezeNode(this);
|
|
45
65
|
}
|
|
66
|
+
get table() {
|
|
67
|
+
return this.entries.table ?? Object.freeze({});
|
|
68
|
+
}
|
|
69
|
+
get valueSet() {
|
|
70
|
+
return this.entries.valueSet;
|
|
71
|
+
}
|
|
46
72
|
/**
|
|
47
73
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
48
74
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -81,15 +107,39 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
81
107
|
return `'${escapeLiteral(this.id)}'`;
|
|
82
108
|
}
|
|
83
109
|
/**
|
|
110
|
+
* Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
|
|
111
|
+
* builder-built catalog check compares `n.nspname` / `table_schema`
|
|
112
|
+
* against. Named schemas bind the schema name as a text parameter; the
|
|
113
|
+
* unbound singleton overrides this to the opaque `current_schema()`
|
|
114
|
+
* expression so the live connection's `search_path` decides at runtime.
|
|
115
|
+
*/
|
|
116
|
+
schemaFilterExpression() {
|
|
117
|
+
return cfExpr.param(this.id, PG_TEXT_CODEC_ID);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Typed-AST counterpart of {@link qualifyTable}: the FROM source a
|
|
121
|
+
* builder-built check uses to address a user table in this namespace.
|
|
122
|
+
* Named schemas qualify (`"schema"."table"`); the unbound singleton
|
|
123
|
+
* overrides this to leave the table unqualified so `search_path`
|
|
124
|
+
* resolves it at runtime.
|
|
125
|
+
*/
|
|
126
|
+
tableSource(tableName, alias) {
|
|
127
|
+
return new PostgresTableSource({
|
|
128
|
+
name: tableName,
|
|
129
|
+
schema: this.id,
|
|
130
|
+
...ifDefined("alias", alias)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
84
134
|
* The bare schema name a DDL planner should target when emitting
|
|
85
135
|
* statements that need to identify this namespace in the live
|
|
86
136
|
* database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
|
|
87
137
|
* catalog filters, planner conflict lookups). Named schemas resolve
|
|
88
138
|
* to their own id. The `PostgresUnboundSchema` singleton inherits
|
|
89
139
|
* this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
|
|
90
|
-
* through `qualifyTableName`
|
|
91
|
-
*
|
|
92
|
-
*
|
|
140
|
+
* through `qualifyTableName` route through the polymorphic
|
|
141
|
+
* `PostgresUnboundSchema` overrides and produce unqualified
|
|
142
|
+
* (search-path-resolved) output automatically.
|
|
93
143
|
*/
|
|
94
144
|
ddlSchemaName(_storage) {
|
|
95
145
|
return this.id;
|
|
@@ -110,19 +160,16 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
110
160
|
* `search_path`).
|
|
111
161
|
*
|
|
112
162
|
* `ddlSchemaName` is inherited from `PostgresSchema` and returns
|
|
113
|
-
* `UNBOUND_NAMESPACE_ID`. Downstream helpers
|
|
114
|
-
*
|
|
115
|
-
*
|
|
163
|
+
* `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
|
|
164
|
+
* route through the polymorphic factory and produce unqualified output
|
|
165
|
+
* automatically.
|
|
116
166
|
*/
|
|
117
167
|
var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
|
|
118
168
|
static instance = new PostgresUnboundSchema();
|
|
119
169
|
constructor(input) {
|
|
120
170
|
super(input ?? {
|
|
121
171
|
id: UNBOUND_NAMESPACE_ID,
|
|
122
|
-
entries: {
|
|
123
|
-
table: {},
|
|
124
|
-
type: {}
|
|
125
|
-
}
|
|
172
|
+
entries: { table: {} }
|
|
126
173
|
});
|
|
127
174
|
}
|
|
128
175
|
qualifier() {
|
|
@@ -134,6 +181,18 @@ var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
|
|
|
134
181
|
schemaSqlExpression() {
|
|
135
182
|
return "current_schema()";
|
|
136
183
|
}
|
|
184
|
+
schemaFilterExpression() {
|
|
185
|
+
return cfExpr.raw("current_schema()", {
|
|
186
|
+
codecId: PG_TEXT_CODEC_ID,
|
|
187
|
+
nullable: false
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
tableSource(tableName, alias) {
|
|
191
|
+
return new PostgresTableSource({
|
|
192
|
+
name: tableName,
|
|
193
|
+
...ifDefined("alias", alias)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
137
196
|
};
|
|
138
197
|
PostgresSchema.unbound = PostgresUnboundSchema.instance;
|
|
139
198
|
/**
|
|
@@ -159,18 +218,18 @@ function isPostgresSchema(ns) {
|
|
|
159
218
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
160
219
|
* be value-stable for a given input set.
|
|
161
220
|
*/
|
|
162
|
-
function postgresCreateNamespace(input
|
|
221
|
+
function postgresCreateNamespace(input) {
|
|
163
222
|
const schemaInput = {
|
|
164
223
|
id: input.id,
|
|
165
224
|
entries: {
|
|
166
|
-
|
|
167
|
-
|
|
225
|
+
...input.entries,
|
|
226
|
+
table: input.entries["table"] ?? {}
|
|
168
227
|
}
|
|
169
228
|
};
|
|
170
229
|
if (input.id === UNBOUND_NAMESPACE_ID) return new PostgresUnboundSchema(schemaInput);
|
|
171
230
|
return new PostgresSchema(schemaInput);
|
|
172
231
|
}
|
|
173
232
|
//#endregion
|
|
174
|
-
export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
|
|
233
|
+
export { PostgresTableSource as a, postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
|
|
175
234
|
|
|
176
|
-
//# sourceMappingURL=postgres-schema-
|
|
235
|
+
//# sourceMappingURL=postgres-schema-COGZ1ark.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-COGZ1ark.mjs","names":[],"sources":["../src/core/ast/table-source.ts","../src/core/postgres-schema.ts"],"sourcesContent":["import {\n type AnyFromSource,\n type AstRewriter,\n TableSource,\n} from '@prisma-next/sql-relational-core/ast';\n\nexport class PostgresTableSource extends TableSource {\n readonly schema: string | undefined;\n\n constructor(options: {\n readonly name: string;\n readonly schema?: string;\n readonly alias?: string;\n }) {\n super(options.name, options.alias);\n this.schema = options.schema;\n this.freeze();\n }\n\n override rewrite(rewriter: AstRewriter): AnyFromSource {\n return rewriter.tableSource ? rewriter.tableSource(this) : this;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';\nimport type {\n SqlNamespaceEntries,\n SqlNamespaceTablesInput,\n SqlStorage,\n StorageTable,\n StorageValueSet,\n} from '@prisma-next/sql-contract/types';\nimport { type CfExpr, cfExpr } from '@prisma-next/sql-relational-core/contract-free';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PostgresTableSource } from './ast/table-source';\nimport { PG_TEXT_CODEC_ID } from './codec-ids';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Postgres target `Namespace` concretion — a Postgres schema (`CREATE\n * SCHEMA …`). Each Postgres `SqlStorage` carries a\n * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by\n * the Postgres PSL interpreter from `namespace { … }` AST buckets.\n *\n * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier\n * emission is the rendering seam: DDL / SQL emission asks the namespace\n * for its qualifier (`\"<schema>\"`) or for a qualified table name\n * (`\"<schema>\".\"<table>\"`) and consumes the result polymorphically.\n * The unbound singleton below overrides these methods to elide the\n * prefix entirely — call sites stay polymorphic and never branch on\n * `id === UNBOUND_NAMESPACE_ID`.\n */\nexport class PostgresSchema extends NamespaceBase {\n /**\n * Stable singleton reference for the late-bound slot. Materialised\n * lazily below the singleton subclass declaration so the static\n * initialiser sees the subclass before assigning. Consumers always\n * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`\n * — same identity).\n */\n static unbound: PostgresUnboundSchema;\n\n declare readonly kind: 'schema';\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n // Drop an empty valueSet so presence signals non-emptiness.\n const valueSetRaw = dispatched['valueSet'];\n const withPresence =\n valueSetRaw !== undefined && Object.keys(valueSetRaw).length === 0\n ? { ...dispatched, valueSet: undefined }\n : dispatched;\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(withPresence),\n );\n Object.defineProperty(this, 'kind', {\n value: 'schema',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\n }\n\n /**\n * The bare schema qualifier as it would appear in a rendered SQL\n * fragment (already quoted). The unbound-schema singleton overrides\n * this to return `''`.\n */\n qualifier(): string {\n return `\"${this.id}\"`;\n }\n\n /**\n * Qualify a table name with the schema prefix\n * (`\"<schema>\".\"<table>\"`). The unbound-schema singleton overrides\n * this to emit just `\"<table>\"` so the resolved DDL is unqualified\n * and `search_path` decides where the object lands at runtime.\n */\n qualifyTable(tableName: string): string {\n return `\"${this.id}\".\"${tableName}\"`;\n }\n\n /**\n * Render a SQL string-literal containing the qualified-name form\n * suitable for `to_regclass(...)` arguments (e.g. `'\"public\".\"user\"'`).\n * The unbound singleton overrides this to elide the schema prefix\n * (`'\"user\"'`) so `search_path` resolves the object at runtime.\n */\n regclassLiteral(name: string): string {\n return `'${escapeLiteral(this.qualifyTable(name))}'`;\n }\n\n /**\n * Render a SQL expression that evaluates to this namespace's schema\n * name at runtime, ready to drop into a `WHERE table_schema = …` /\n * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL\n * literal (`'public'`); the unbound singleton overrides this to emit\n * `current_schema()` so catalog queries match whichever schema the\n * connection's `search_path` resolved at runtime.\n */\n schemaSqlExpression(): string {\n return `'${escapeLiteral(this.id)}'`;\n }\n\n /**\n * Typed-AST counterpart of {@link schemaSqlExpression}: the expression a\n * builder-built catalog check compares `n.nspname` / `table_schema`\n * against. Named schemas bind the schema name as a text parameter; the\n * unbound singleton overrides this to the opaque `current_schema()`\n * expression so the live connection's `search_path` decides at runtime.\n */\n schemaFilterExpression(): CfExpr {\n return cfExpr.param(this.id, PG_TEXT_CODEC_ID);\n }\n\n /**\n * Typed-AST counterpart of {@link qualifyTable}: the FROM source a\n * builder-built check uses to address a user table in this namespace.\n * Named schemas qualify (`\"schema\".\"table\"`); the unbound singleton\n * overrides this to leave the table unqualified so `search_path`\n * resolves it at runtime.\n */\n tableSource(tableName: string, alias?: string): PostgresTableSource {\n return new PostgresTableSource({\n name: tableName,\n schema: this.id,\n ...ifDefined('alias', alias),\n });\n }\n\n /**\n * The bare schema name a DDL planner should target when emitting\n * statements that need to identify this namespace in the live\n * database (e.g. `CREATE TABLE \"<ddlSchemaName>\".\"<table>\" …`,\n * catalog filters, planner conflict lookups). Named schemas resolve\n * to their own id. The `PostgresUnboundSchema` singleton inherits\n * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch\n * through `qualifyTableName` route through the polymorphic\n * `PostgresUnboundSchema` overrides and produce unqualified\n * (search-path-resolved) output automatically.\n */\n ddlSchemaName(_storage: SqlStorage): string {\n return this.id;\n }\n}\n\n/**\n * Singleton subclass for the reserved sentinel namespace id\n * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding\n * the connection's `search_path` resolves at runtime. Overrides\n * qualifier emission to elide the schema prefix; call sites that consume\n * `qualifier()` / `qualifyTable()` get unqualified output without\n * branching on the namespace id.\n *\n * This is the target-side materialization of \"the framework provides\n * affordances; targets implement specifics\": the framework names the\n * sentinel; Postgres decides what late-bound means here (the table\n * name, naked — the schema is supplied by the live connection's\n * `search_path`).\n *\n * `ddlSchemaName` is inherited from `PostgresSchema` and returns\n * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`\n * route through the polymorphic factory and produce unqualified output\n * automatically.\n */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID, entries: { table: {} } });\n }\n\n override qualifier(): string {\n return '';\n }\n\n override qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n\n override schemaSqlExpression(): string {\n return 'current_schema()';\n }\n\n override schemaFilterExpression(): CfExpr {\n return cfExpr.raw('current_schema()', { codecId: PG_TEXT_CODEC_ID, nullable: false });\n }\n\n override tableSource(tableName: string, alias?: string): PostgresTableSource {\n return new PostgresTableSource({\n name: tableName,\n ...ifDefined('alias', alias),\n });\n }\n}\n\nPostgresSchema.unbound = PostgresUnboundSchema.instance;\n\n/**\n * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`\n * so callers can dispatch to the polymorphic emission methods without\n * branching at the call site. Uses the structural `kind` discriminator\n * (`'schema'`) rather than `instanceof` so the check survives realm /\n * bundle / hot-reload boundaries — matching the rest of the IR's\n * narrowing convention. `PostgresUnboundSchema` passes through because\n * it inherits the same `kind: 'schema'` from `PostgresSchema`.\n */\nexport function isPostgresSchema(ns: unknown): ns is PostgresSchema {\n return (ns as { kind?: unknown } | null | undefined)?.kind === 'schema';\n}\n\n/**\n * Target-supplied `Namespace` factory the Postgres target plumbs\n * through `defineContract({ createNamespace })` and the SQL PSL\n * interpreter. Returns the unbound singleton for the framework\n * sentinel and a fresh `PostgresSchema` for any other coordinate.\n *\n * The factory has no per-call state — every named id deterministically\n * maps to a distinct schema instance — so callers can pass it through\n * by reference and trust the resulting `SqlStorage.namespaces` map to\n * be value-stable for a given input set.\n */\nexport function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema {\n const schemaInput: PostgresSchemaInput = {\n id: input.id,\n entries: {\n ...input.entries,\n table: input.entries['table'] ?? {},\n },\n };\n if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(schemaInput);\n }\n return new PostgresSchema(schemaInput);\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,sBAAb,cAAyC,YAAY;CACnD;CAEA,YAAY,SAIT;EACD,MAAM,QAAQ,MAAM,QAAQ,KAAK;EACjC,KAAK,SAAS,QAAQ;EACtB,KAAK,OAAO;CACd;CAEA,QAAiB,UAAsC;EACrD,OAAO,SAAS,cAAc,SAAS,YAAY,IAAI,IAAI;CAC7D;AACF;;;;;;;;;;;;;;;;;ACkBA,IAAa,iBAAb,cAAoC,cAAc;;;;;;;;CAQhD,OAAO;CAGP;CACA;CAEA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAEhB,MAAM,aAAa,yBAAyB,MAAM,SAAS,sBAAsB,GAAG,OAAO;EAG3F,MAAM,cAAc,WAAW;EAC/B,MAAM,eACJ,gBAAgB,KAAA,KAAa,OAAO,KAAK,WAAW,CAAC,CAAC,WAAW,IAC7D;GAAE,GAAG;GAAY,UAAU,KAAA;EAAU,IACrC;EAEN,KAAK,UAAU,OAAO,OACpB,UAGE,YAAY,CAChB;EACA,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;EAChB,CAAC;EACD,WAAW,IAAI;CACjB;CAEA,IAAI,QAAgD;EAClD,OAAO,KAAK,QAAQ,SAAS,OAAO,OAAO,CAAC,CAAC;CAC/C;CAEA,IAAI,WAAkE;EACpE,OAAO,KAAK,QAAQ;CACtB;;;;;;CAOA,YAAoB;EAClB,OAAO,IAAI,KAAK,GAAG;CACrB;;;;;;;CAQA,aAAa,WAA2B;EACtC,OAAO,IAAI,KAAK,GAAG,KAAK,UAAU;CACpC;;;;;;;CAQA,gBAAgB,MAAsB;EACpC,OAAO,IAAI,cAAc,KAAK,aAAa,IAAI,CAAC,EAAE;CACpD;;;;;;;;;CAUA,sBAA8B;EAC5B,OAAO,IAAI,cAAc,KAAK,EAAE,EAAE;CACpC;;;;;;;;CASA,yBAAiC;EAC/B,OAAO,OAAO,MAAM,KAAK,IAAI,gBAAgB;CAC/C;;;;;;;;CASA,YAAY,WAAmB,OAAqC;EAClE,OAAO,IAAI,oBAAoB;GAC7B,MAAM;GACN,QAAQ,KAAK;GACb,GAAG,UAAU,SAAS,KAAK;EAC7B,CAAC;CACH;;;;;;;;;;;;CAaA,cAAc,UAA8B;EAC1C,OAAO,KAAK;CACd;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,wBAAb,MAAa,8BAA8B,eAAe;CACxD,OAAgB,WAAkC,IAAI,sBAAsB;CAE5E,YAAY,OAA6B;EACvC,MAAM,SAAS;GAAE,IAAI;GAAsB,SAAS,EAAE,OAAO,CAAC,EAAE;EAAE,CAAC;CACrE;CAEA,YAA6B;EAC3B,OAAO;CACT;CAEA,aAAsB,WAA2B;EAC/C,OAAO,IAAI,UAAU;CACvB;CAEA,sBAAuC;EACrC,OAAO;CACT;CAEA,yBAA0C;EACxC,OAAO,OAAO,IAAI,oBAAoB;GAAE,SAAS;GAAkB,UAAU;EAAM,CAAC;CACtF;CAEA,YAAqB,WAAmB,OAAqC;EAC3E,OAAO,IAAI,oBAAoB;GAC7B,MAAM;GACN,GAAG,UAAU,SAAS,KAAK;EAC7B,CAAC;CACH;AACF;AAEA,eAAe,UAAU,sBAAsB;;;;;;;;;;AAW/C,SAAgB,iBAAiB,IAAmC;CAClE,OAAQ,IAA8C,SAAS;AACjE;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,OAAgD;CACtF,MAAM,cAAmC;EACvC,IAAI,MAAM;EACV,SAAS;GACP,GAAG,MAAM;GACT,OAAO,MAAM,QAAQ,YAAY,CAAC;EACpC;CACF;CACA,IAAI,MAAM,OAAO,sBACf,OAAO,IAAI,sBAAsB,WAAW;CAE9C,OAAO,IAAI,eAAe,WAAW;AACvC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
2
|
+
import { isThenable } from "@prisma-next/utils/promise";
|
|
2
3
|
//#region src/core/migrations/render-ops.ts
|
|
3
4
|
/**
|
|
4
5
|
* Asserts an op materialised by an `OpFactoryCall` targets postgres. The
|
|
@@ -8,17 +9,21 @@ import { blindCast } from "@prisma-next/utils/casts";
|
|
|
8
9
|
* place to fail loudly with op metadata (`id` + `target.id`).
|
|
9
10
|
*/
|
|
10
11
|
function assertPostgresOp(op, callFactoryName) {
|
|
11
|
-
const targetId = op.target?.id;
|
|
12
|
+
const targetId = blindCast(op).target?.id;
|
|
12
13
|
if (targetId !== "postgres") throw new Error(`renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`);
|
|
13
14
|
}
|
|
14
15
|
function renderOps(calls, lowerer) {
|
|
15
16
|
return calls.map((c) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const opOrPromise = blindCast(c).toOp(lowerer);
|
|
18
|
+
if (isThenable(opOrPromise)) return opOrPromise.then((op) => {
|
|
19
|
+
assertPostgresOp(op, c.factoryName);
|
|
20
|
+
return op;
|
|
21
|
+
});
|
|
22
|
+
assertPostgresOp(opOrPromise, c.factoryName);
|
|
23
|
+
return opOrPromise;
|
|
19
24
|
});
|
|
20
25
|
}
|
|
21
26
|
//#endregion
|
|
22
27
|
export { renderOps as t };
|
|
23
28
|
|
|
24
|
-
//# sourceMappingURL=render-ops-
|
|
29
|
+
//# sourceMappingURL=render-ops-BREh1kHe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-ops-BREh1kHe.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\nimport type {\n MigrationPlanOperation,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { isThenable } from '@prisma-next/utils/promise';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string): asserts op is Op {\n const targetId = blindCast<\n { target?: { id?: string } },\n 'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'\n >(op).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(\n calls: readonly OpFactoryCall[],\n lowerer?: ExecuteRequestLowerer,\n): (Op | Promise<Op>)[] {\n return calls.map((c) => {\n const opOrPromise = blindCast<\n { toOp(lowerer?: ExecuteRequestLowerer): Op | Promise<Op> },\n 'PG OpFactoryCall.toOp accepts an optional ExecuteRequestLowerer; the framework interface omits it because not all targets need a lowerer — the PG target overrides with this extended signature'\n >(c).toOp(lowerer);\n if (isThenable(opOrPromise)) {\n return opOrPromise.then((op) => {\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n }\n assertPostgresOp(opOrPromise, c.factoryName);\n return opOrPromise;\n });\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,iBAAiB,IAA4B,iBAA2C;CAC/F,MAAM,WAAW,UAGf,EAAE,CAAC,CAAC,QAAQ;CACd,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAChI;AAEJ;AAEA,SAAgB,UACd,OACA,SACsB;CACtB,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,cAAc,UAGlB,CAAC,CAAC,CAAC,KAAK,OAAO;EACjB,IAAI,WAAW,WAAW,GACxB,OAAO,YAAY,MAAM,OAAO;GAC9B,iBAAiB,IAAI,EAAE,WAAW;GAClC,OAAO;EACT,CAAC;EAEH,iBAAiB,aAAa,EAAE,WAAW;EAC3C,OAAO;CACT,CAAC;AACH"}
|
package/dist/render-ops.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
4
|
-
import {
|
|
4
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
5
5
|
|
|
6
6
|
//#region src/core/migrations/render-ops.d.ts
|
|
7
7
|
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
8
|
-
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?:
|
|
8
|
+
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?: ExecuteRequestLowerer): (Op | Promise<Op>)[];
|
|
9
9
|
//#endregion
|
|
10
10
|
export { renderOps };
|
|
11
11
|
//# sourceMappingURL=render-ops.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;KAUK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,iBAqBpB,SAAA,CACd,KAAA,WAAgB,aAAA,IAChB,OAAA,GAAU,qBAAA,IACR,EAAA,GAAK,OAAA,CAAQ,EAAA"}
|
package/dist/render-ops.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderOps } from "./render-ops-
|
|
1
|
+
import { t as renderOps } from "./render-ops-BREh1kHe.mjs";
|
|
2
2
|
export { renderOps };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ import { JsonObject } from "@prisma-next/utils/json";
|
|
|
9
9
|
//#region src/core/postgres-contract-serializer.d.ts
|
|
10
10
|
declare class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
11
11
|
constructor();
|
|
12
|
+
protected get defaultNamespaceId(): string;
|
|
12
13
|
protected hydrateSqlNamespaceEntry(nsId: string, raw: Namespace | Record<string, unknown>): Namespace | SqlNamespaceTablesInput;
|
|
13
14
|
serializeContract(contract: Contract<SqlStorage>): JsonObject;
|
|
14
15
|
private serializePostgresNamespace;
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;cAkEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;;gBAM1D,kBAAA;EAAA,UAIJ,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,SAAA,GAAY,MAAA,oBAChB,SAAA,GAAY,uBAAA;EA0BN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;EAAA,QAuCpD,0BAAA;EAAA,QAyBA,kBAAA;AAAA;;;UChKO,6BAAA,SAAsC,qBAAqB;;;;;ADyD5E;;cCjDM,+BAAA,EAAiC,uBAAA,oBAGrC,6BAAA;EAAA,SAES,MAAA,iBAAuB,kBAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-
|
|
1
|
+
import { n as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-CpGygXpI.mjs";
|
|
2
|
+
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-k3TAcPMY.mjs";
|
|
3
3
|
//#region src/exports/runtime.ts
|
|
4
4
|
/**
|
|
5
5
|
* Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnyFromSource, AstRewriter, TableSource } from "@prisma-next/sql-relational-core/ast";
|
|
2
|
+
|
|
3
|
+
//#region src/core/ast/table-source.d.ts
|
|
4
|
+
declare class PostgresTableSource extends TableSource {
|
|
5
|
+
readonly schema: string | undefined;
|
|
6
|
+
constructor(options: {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly schema?: string;
|
|
9
|
+
readonly alias?: string;
|
|
10
|
+
});
|
|
11
|
+
rewrite(rewriter: AstRewriter): AnyFromSource;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { PostgresTableSource as t };
|
|
15
|
+
//# sourceMappingURL=table-source-BvFo7gVs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-source-BvFo7gVs.d.mts","names":[],"sources":["../src/core/ast/table-source.ts"],"mappings":";;;cAMa,mBAAA,SAA4B,WAAA;EAAA,SAC9B,MAAA;cAEG,OAAA;IAAA,SACD,IAAA;IAAA,SACA,MAAA;IAAA,SACA,KAAA;EAAA;EAOF,OAAA,CAAQ,QAAA,EAAU,WAAA,GAAc,aAAA;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
|
|
2
2
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
3
3
|
import { NamespaceBase } from "@prisma-next/framework-components/ir";
|
|
4
|
-
import {
|
|
4
|
+
import { CfExpr } from "@prisma-next/sql-relational-core/contract-free";
|
|
5
|
+
import { SqlNamespaceEntries, SqlNamespaceTablesInput, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
5
6
|
|
|
6
7
|
//#region src/core/postgres-schema.d.ts
|
|
7
8
|
interface PostgresSchemaInput {
|
|
8
9
|
readonly id: string;
|
|
9
|
-
readonly entries:
|
|
10
|
-
readonly table: Record<string, StorageTable | StorageTableInput>;
|
|
11
|
-
readonly type: Record<string, PostgresEnumType | PostgresEnumTypeInput>;
|
|
12
|
-
};
|
|
10
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -17,7 +15,7 @@ interface PostgresSchemaInput {
|
|
|
17
15
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
18
16
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
19
17
|
*
|
|
20
|
-
* `entries` holds entity-kind
|
|
18
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
21
19
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
22
20
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
23
21
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -36,11 +34,10 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
36
34
|
static unbound: PostgresUnboundSchema;
|
|
37
35
|
readonly kind: 'schema';
|
|
38
36
|
readonly id: string;
|
|
39
|
-
readonly entries:
|
|
40
|
-
readonly table: Readonly<Record<string, StorageTable>>;
|
|
41
|
-
readonly type: Readonly<Record<string, PostgresEnumType>>;
|
|
42
|
-
}>;
|
|
37
|
+
readonly entries: SqlNamespaceEntries;
|
|
43
38
|
constructor(input: PostgresSchemaInput);
|
|
39
|
+
get table(): Readonly<Record<string, StorageTable>>;
|
|
40
|
+
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
44
41
|
/**
|
|
45
42
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
46
43
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -70,6 +67,22 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
70
67
|
* connection's `search_path` resolved at runtime.
|
|
71
68
|
*/
|
|
72
69
|
schemaSqlExpression(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
|
|
72
|
+
* builder-built catalog check compares `n.nspname` / `table_schema`
|
|
73
|
+
* against. Named schemas bind the schema name as a text parameter; the
|
|
74
|
+
* unbound singleton overrides this to the opaque `current_schema()`
|
|
75
|
+
* expression so the live connection's `search_path` decides at runtime.
|
|
76
|
+
*/
|
|
77
|
+
schemaFilterExpression(): CfExpr;
|
|
78
|
+
/**
|
|
79
|
+
* Typed-AST counterpart of {@link qualifyTable}: the FROM source a
|
|
80
|
+
* builder-built check uses to address a user table in this namespace.
|
|
81
|
+
* Named schemas qualify (`"schema"."table"`); the unbound singleton
|
|
82
|
+
* overrides this to leave the table unqualified so `search_path`
|
|
83
|
+
* resolves it at runtime.
|
|
84
|
+
*/
|
|
85
|
+
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
73
86
|
/**
|
|
74
87
|
* The bare schema name a DDL planner should target when emitting
|
|
75
88
|
* statements that need to identify this namespace in the live
|
|
@@ -77,9 +90,9 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
77
90
|
* catalog filters, planner conflict lookups). Named schemas resolve
|
|
78
91
|
* to their own id. The `PostgresUnboundSchema` singleton inherits
|
|
79
92
|
* this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
|
|
80
|
-
* through `qualifyTableName`
|
|
81
|
-
*
|
|
82
|
-
*
|
|
93
|
+
* through `qualifyTableName` route through the polymorphic
|
|
94
|
+
* `PostgresUnboundSchema` overrides and produce unqualified
|
|
95
|
+
* (search-path-resolved) output automatically.
|
|
83
96
|
*/
|
|
84
97
|
ddlSchemaName(_storage: SqlStorage): string;
|
|
85
98
|
}
|
|
@@ -98,9 +111,9 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
98
111
|
* `search_path`).
|
|
99
112
|
*
|
|
100
113
|
* `ddlSchemaName` is inherited from `PostgresSchema` and returns
|
|
101
|
-
* `UNBOUND_NAMESPACE_ID`. Downstream helpers
|
|
102
|
-
*
|
|
103
|
-
*
|
|
114
|
+
* `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
|
|
115
|
+
* route through the polymorphic factory and produce unqualified output
|
|
116
|
+
* automatically.
|
|
104
117
|
*/
|
|
105
118
|
declare class PostgresUnboundSchema extends PostgresSchema {
|
|
106
119
|
static readonly instance: PostgresUnboundSchema;
|
|
@@ -108,6 +121,8 @@ declare class PostgresUnboundSchema extends PostgresSchema {
|
|
|
108
121
|
qualifier(): string;
|
|
109
122
|
qualifyTable(tableName: string): string;
|
|
110
123
|
schemaSqlExpression(): string;
|
|
124
|
+
schemaFilterExpression(): CfExpr;
|
|
125
|
+
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
111
126
|
}
|
|
112
127
|
/**
|
|
113
128
|
* Target-supplied `Namespace` factory the Postgres target plumbs
|
|
@@ -120,7 +135,7 @@ declare class PostgresUnboundSchema extends PostgresSchema {
|
|
|
120
135
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
121
136
|
* be value-stable for a given input set.
|
|
122
137
|
*/
|
|
123
|
-
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput
|
|
138
|
+
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema;
|
|
124
139
|
//#endregion
|
|
125
|
-
export { type PostgresColumnDefault,
|
|
140
|
+
export { type PostgresColumnDefault, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
126
141
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/core/postgres-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/core/postgres-schema.ts"],"mappings":";;;;;;;UAqBiB,mBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;;;;;;;;;;;cAiBxC,cAAA,SAAuB,aAAA;EAjBuB;AAiB3D;;;;;;EAjB2D,OAyBlD,OAAA,EAAS,qBAAA;EAAA,SAEC,IAAA;EAAA,SACR,EAAA;EAAA,SACA,OAAA,EAAS,mBAAA;cAEN,KAAA,EAAO,mBAAA;EAAA,IA4Bf,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,IAIjC,QAAA,IAAY,QAAA,CAAS,MAAA,SAAe,eAAA;EA+DQ;;;;;EAtDhD,SAAA;EA/CO;;;;;;EAyDP,YAAA,CAAa,SAAA;EAnDM;;;;;;EA6DnB,eAAA,CAAgB,IAAA;EA7BA;;;;;;;;EAyChB,mBAAA;EAWA;;;;;;;EAAA,sBAAA,IAA0B,MAAA;EA8BZ;;AAAoB;AAwBpC;;;;EA3CE,WAAA,CAAY,SAAA,UAAmB,KAAA,YAAiB,mBAAA;EA8Db;;;;;;;;;;;EA3CnC,aAAA,CAAc,QAAA,EAAU,UAAA;AAAA;;;;;;;;;;AA+CoD;AAkC9E;;;;;;;;AAAuF;cAzD1E,qBAAA,SAA8B,cAAA;EAAA,gBACzB,QAAA,EAAU,qBAAA;cAEd,KAAA,GAAQ,mBAAA;EAIX,SAAA;EAIA,YAAA,CAAa,SAAA;EAIb,mBAAA;EAIA,sBAAA,IAA0B,MAAA;EAI1B,WAAA,CAAY,SAAA,UAAmB,KAAA,YAAiB,mBAAA;AAAA;;;;;;;;;;;;iBAkC3C,uBAAA,CAAwB,KAAA,EAAO,uBAAA,GAA0B,cAAc"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
export { PostgresEnumType, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
1
|
+
import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-COGZ1ark.mjs";
|
|
2
|
+
export { PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-dev.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.
|
|
10
|
-
"@prisma-next/contract": "0.
|
|
11
|
-
"@prisma-next/errors": "0.
|
|
12
|
-
"@prisma-next/family-sql": "0.
|
|
13
|
-
"@prisma-next/framework-components": "0.
|
|
14
|
-
"@prisma-next/migration-tools": "0.
|
|
15
|
-
"@prisma-next/ts-render": "0.
|
|
16
|
-
"@prisma-next/sql-contract": "0.
|
|
17
|
-
"@prisma-next/sql-errors": "0.
|
|
18
|
-
"@prisma-next/sql-operations": "0.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.
|
|
21
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/cli": "0.14.0-dev.2",
|
|
10
|
+
"@prisma-next/contract": "0.14.0-dev.2",
|
|
11
|
+
"@prisma-next/errors": "0.14.0-dev.2",
|
|
12
|
+
"@prisma-next/family-sql": "0.14.0-dev.2",
|
|
13
|
+
"@prisma-next/framework-components": "0.14.0-dev.2",
|
|
14
|
+
"@prisma-next/migration-tools": "0.14.0-dev.2",
|
|
15
|
+
"@prisma-next/ts-render": "0.14.0-dev.2",
|
|
16
|
+
"@prisma-next/sql-contract": "0.14.0-dev.2",
|
|
17
|
+
"@prisma-next/sql-errors": "0.14.0-dev.2",
|
|
18
|
+
"@prisma-next/sql-operations": "0.14.0-dev.2",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.2",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.2",
|
|
21
|
+
"@prisma-next/utils": "0.14.0-dev.2",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.
|
|
28
|
-
"@prisma-next/tsconfig": "0.
|
|
29
|
-
"@prisma-next/tsdown": "0.
|
|
27
|
+
"@prisma-next/test-utils": "0.14.0-dev.2",
|
|
28
|
+
"@prisma-next/tsconfig": "0.14.0-dev.2",
|
|
29
|
+
"@prisma-next/tsdown": "0.14.0-dev.2",
|
|
30
30
|
"tsdown": "0.22.1",
|
|
31
31
|
"typescript": "5.9.3",
|
|
32
32
|
"vitest": "4.1.8"
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"./data-transform": "./dist/data-transform.mjs",
|
|
54
54
|
"./ddl": "./dist/ddl.mjs",
|
|
55
55
|
"./default-normalizer": "./dist/default-normalizer.mjs",
|
|
56
|
-
"./enum-planning": "./dist/enum-planning.mjs",
|
|
57
56
|
"./errors": "./dist/errors.mjs",
|
|
58
57
|
"./issue-planner": "./dist/issue-planner.mjs",
|
|
59
58
|
"./migration": "./dist/migration.mjs",
|