@prisma-next/target-postgres 0.14.0-dev.3 → 0.14.0-dev.31
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/canonicalize-Bn3BM1Cn.mjs +46 -0
- package/dist/canonicalize-Bn3BM1Cn.mjs.map +1 -0
- package/dist/canonicalize-CAbXtVtB.d.mts +37 -0
- package/dist/canonicalize-CAbXtVtB.d.mts.map +1 -0
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-CueCoGD0.d.mts} +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts.map → codec-types-CueCoGD0.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Ca8upop6.d.mts} +12 -1
- package/dist/codecs-Ca8upop6.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +34 -1
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +8 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +3 -3
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +11 -10
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-qKy1U5V9.d.mts} +2 -2
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-qKy1U5V9.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-CGf6UABz.mjs} +62 -5
- package/dist/ddl-CGf6UABz.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/{default-normalizer-DyyCHQWs.mjs → default-normalizer-CzV8-QSu.mjs} +58 -2
- package/dist/default-normalizer-CzV8-QSu.mjs.map +1 -0
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +1 -1
- package/dist/descriptor-meta-Dvvpu_jU.mjs +17 -0
- package/dist/descriptor-meta-Dvvpu_jU.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-D5zHFKUz.mjs +228 -0
- package/dist/descriptor-meta-runtime-D5zHFKUz.mjs.map +1 -0
- package/dist/{issue-planner-DL6g3CmE.mjs → issue-planner-D5H1VuVP.mjs} +11 -9
- package/dist/issue-planner-D5H1VuVP.mjs.map +1 -0
- package/dist/issue-planner.d.mts +3 -3
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +3 -3
- package/dist/migration.mjs +2 -2
- package/dist/nodes-CSkPX3rI.d.mts +120 -0
- package/dist/nodes-CSkPX3rI.d.mts.map +1 -0
- package/dist/{nodes-Bbhs2rwj.mjs → nodes-Dh__NS58.mjs} +56 -2
- package/dist/nodes-Dh__NS58.mjs.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DIdBDwmO.mjs} +199 -28
- package/dist/op-factory-call-DIdBDwmO.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-DPJR7tJc.d.mts} +44 -13
- package/dist/op-factory-call-DPJR7tJc.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +74 -2
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-Bs_baQax.mjs → planner-BnNEtGYM.mjs} +156 -24
- package/dist/planner-BnNEtGYM.mjs.map +1 -0
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-B8Nn6nHN.mjs} +12 -27
- package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +2 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BO-frvvN.d.mts} +3 -3
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BO-frvvN.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-DzvdQ-7K.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-DzvdQ-7K.mjs.map} +1 -1
- 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 → planner-sql-checks-CyjaoKhm.mjs} +2 -2
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CyjaoKhm.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +31 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-serializer-tGMiJcl4.mjs} +30 -21
- package/dist/postgres-contract-serializer-tGMiJcl4.mjs.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-C8JZyTSJ.mjs} +2 -2
- package/dist/{postgres-migration-B5jKrXv3.mjs.map → postgres-migration-C8JZyTSJ.mjs.map} +1 -1
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-Cs7zMOe1.d.mts} +5 -5
- package/dist/{postgres-migration-Y4YBJqkS.d.mts.map → postgres-migration-Cs7zMOe1.d.mts.map} +1 -1
- package/dist/postgres-rls-policy-12wAEQhs.d.mts +60 -0
- package/dist/postgres-rls-policy-12wAEQhs.d.mts.map +1 -0
- package/dist/postgres-schema-DJUEkWg-.d.mts +190 -0
- package/dist/postgres-schema-DJUEkWg-.d.mts.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DLcc3W2-.mjs} +138 -5
- package/dist/postgres-schema-DLcc3W2-.mjs.map +1 -0
- package/dist/postgres-schema-ir-BJl_a3J7.d.mts +102 -0
- package/dist/postgres-schema-ir-BJl_a3J7.d.mts.map +1 -0
- package/dist/postgres-schema-ir-I_FiUndw.mjs +133 -0
- package/dist/postgres-schema-ir-I_FiUndw.mjs.map +1 -0
- package/dist/postgres-schema-ir-annotations-BbDSiwx2.mjs +14 -0
- package/dist/postgres-schema-ir-annotations-BbDSiwx2.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/rls-canonicalize.d.mts +2 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +5 -5
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/schema-ir-annotations.d.mts +8 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +3 -2
- package/package.json +21 -17
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/ddl.ts +45 -1
- package/src/core/authoring.ts +115 -1
- package/src/core/codecs.ts +35 -1
- package/src/core/ddl/nodes.ts +94 -2
- package/src/core/default-normalizer.ts +60 -2
- package/src/core/descriptor-meta.ts +4 -0
- package/src/core/entity-kinds.ts +16 -0
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/contract-to-postgres-schema-ir.ts +91 -0
- package/src/core/migrations/control-policy.ts +3 -0
- package/src/core/migrations/diff-postgres-schema.ts +55 -0
- package/src/core/migrations/issue-planner.ts +8 -0
- package/src/core/migrations/op-factory-call.ts +106 -21
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/rls.ts +106 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +15 -56
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-strategies.ts +3 -11
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +84 -1
- package/src/core/migrations/verify-postgres-namespaces.ts +12 -15
- package/src/core/postgres-contract-serializer.ts +48 -33
- package/src/core/postgres-schema.ts +37 -13
- package/src/core/postgres-validators.ts +20 -0
- package/src/core/rls/canonicalize.ts +48 -0
- package/src/core/schema-ir/postgres-rls-policy.ts +101 -0
- package/src/core/schema-ir/postgres-role.ts +52 -0
- package/src/core/schema-ir/postgres-schema-ir-annotations.ts +22 -0
- package/src/core/schema-ir/postgres-schema-ir.ts +138 -0
- package/src/core/schema-ir/postgres-table-ir.ts +96 -0
- package/src/exports/contract-free.ts +7 -1
- package/src/exports/control.ts +11 -12
- package/src/exports/ddl.ts +4 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner.ts +5 -0
- package/src/exports/rls-canonicalize.ts +6 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/types.ts +20 -0
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
- package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
- package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
- package/dist/nodes-pLeLgdis.d.mts +0 -67
- package/dist/nodes-pLeLgdis.d.mts.map +0 -1
- package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
- package/dist/planner-Bs_baQax.mjs.map +0 -1
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
- package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
|
@@ -2,10 +2,125 @@ import { _ as PG_TEXT_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
|
|
|
2
2
|
import { n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
3
|
import { TableSource } from "@prisma-next/sql-relational-core/ast";
|
|
4
4
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
5
|
+
import { type } from "arktype";
|
|
5
6
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
-
import {
|
|
7
|
+
import { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
|
|
8
|
+
import { SqlNamespaceBase, SqlNode } from "@prisma-next/sql-contract/types";
|
|
7
9
|
import { composeSqlEntityKinds } from "@prisma-next/sql-contract/entity-kinds";
|
|
8
10
|
import { cfExpr } from "@prisma-next/sql-relational-core/contract-free";
|
|
11
|
+
//#region src/core/postgres-validators.ts
|
|
12
|
+
const PostgresRoleSchema = type({
|
|
13
|
+
kind: "'role'",
|
|
14
|
+
name: "string",
|
|
15
|
+
namespaceId: "string"
|
|
16
|
+
});
|
|
17
|
+
const PostgresRlsPolicySchema = type({
|
|
18
|
+
kind: "'policy'",
|
|
19
|
+
name: "string",
|
|
20
|
+
prefix: "string",
|
|
21
|
+
tableName: "string",
|
|
22
|
+
namespaceId: "string",
|
|
23
|
+
operation: "'select' | 'insert' | 'update' | 'delete' | 'all'",
|
|
24
|
+
roles: type.string.array().readonly(),
|
|
25
|
+
"using?": "string",
|
|
26
|
+
"withCheck?": "string",
|
|
27
|
+
permissive: "boolean"
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/core/schema-ir/postgres-rls-policy.ts
|
|
31
|
+
/**
|
|
32
|
+
* Postgres IR class for a row-level security policy (`CREATE POLICY … ON …`).
|
|
33
|
+
*
|
|
34
|
+
* Target-only concept — no SQL-family abstract. Extends `SqlNode` directly.
|
|
35
|
+
* Frozen at construction via `freezeNode(this)`. The `kind: 'policy'`
|
|
36
|
+
* discriminant is enumerable (overrides SqlNode's non-enumerable `'sql'`) so it
|
|
37
|
+
* survives JSON serialization and enables dispatch. The literal matches the
|
|
38
|
+
* entries key (one-string rule: node.kind === entries key === entity kind).
|
|
39
|
+
*/
|
|
40
|
+
var PostgresRlsPolicy = class extends SqlNode {
|
|
41
|
+
kind = "policy";
|
|
42
|
+
name;
|
|
43
|
+
prefix;
|
|
44
|
+
tableName;
|
|
45
|
+
namespaceId;
|
|
46
|
+
operation;
|
|
47
|
+
roles;
|
|
48
|
+
permissive;
|
|
49
|
+
constructor(input) {
|
|
50
|
+
super();
|
|
51
|
+
this.name = input.name;
|
|
52
|
+
this.prefix = input.prefix;
|
|
53
|
+
this.tableName = input.tableName;
|
|
54
|
+
this.namespaceId = input.namespaceId;
|
|
55
|
+
this.operation = input.operation;
|
|
56
|
+
this.roles = Object.freeze([...input.roles]);
|
|
57
|
+
if (input.using !== void 0) this.using = input.using;
|
|
58
|
+
if (input.withCheck !== void 0) this.withCheck = input.withCheck;
|
|
59
|
+
this.permissive = input.permissive;
|
|
60
|
+
freezeNode(this);
|
|
61
|
+
}
|
|
62
|
+
get id() {
|
|
63
|
+
return this.name;
|
|
64
|
+
}
|
|
65
|
+
children() {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Equality by wire name only. The wire name is `<prefix>_<sha256(body)[0..8]>`,
|
|
70
|
+
* so name-equality IS body-equality — two policies with different bodies
|
|
71
|
+
* have different hashes and therefore different names. We deliberately
|
|
72
|
+
* skip comparing bodies directly because Postgres reprints predicate
|
|
73
|
+
* expressions (e.g. strips outer parentheses), so a byte-compare against
|
|
74
|
+
* the authored body would produce false mismatches on a clean re-verify.
|
|
75
|
+
*/
|
|
76
|
+
isEqualTo(other) {
|
|
77
|
+
if (!isPostgresRlsPolicy(other)) throw new Error(`PostgresRlsPolicy.isEqualTo: expected a PostgresRlsPolicy, got ${other.constructor?.name ?? typeof other}`);
|
|
78
|
+
return this.name === other.name;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function isPostgresRlsPolicy(node) {
|
|
82
|
+
return node !== void 0 && "kind" in node && node.kind === "policy";
|
|
83
|
+
}
|
|
84
|
+
function assertPostgresRlsPolicy(node) {
|
|
85
|
+
if (!isPostgresRlsPolicy(node)) {
|
|
86
|
+
const kind = node !== void 0 && "kind" in node ? String(node.kind) : typeof node;
|
|
87
|
+
throw new Error(`planPostgresSchemaDiff: expected a PostgresRlsPolicy on the policy-diff path but got ${kind}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/core/schema-ir/postgres-role.ts
|
|
92
|
+
/**
|
|
93
|
+
* Postgres IR class for a database role (`CREATE ROLE …`).
|
|
94
|
+
*
|
|
95
|
+
* Roles are cluster-scoped, so their namespace coordinate is always
|
|
96
|
+
* `UNBOUND_NAMESPACE_ID`. Target-only concept — no SQL-family abstract.
|
|
97
|
+
* Extends `SqlNode` directly, frozen at construction via `freezeNode(this)`.
|
|
98
|
+
* The `kind: 'role'` discriminant is enumerable so it survives JSON.
|
|
99
|
+
* Matches the entries key (one-string rule).
|
|
100
|
+
*/
|
|
101
|
+
var PostgresRole = class PostgresRole extends SqlNode {
|
|
102
|
+
kind = "role";
|
|
103
|
+
name;
|
|
104
|
+
namespaceId;
|
|
105
|
+
constructor(input) {
|
|
106
|
+
super();
|
|
107
|
+
this.name = input.name;
|
|
108
|
+
this.namespaceId = input.namespaceId;
|
|
109
|
+
freezeNode(this);
|
|
110
|
+
}
|
|
111
|
+
/** Roles are cluster-unique; the name alone is sufficient as the id. */
|
|
112
|
+
get id() {
|
|
113
|
+
return this.name;
|
|
114
|
+
}
|
|
115
|
+
children() {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
isEqualTo(other) {
|
|
119
|
+
if (!(other instanceof PostgresRole)) throw new Error(`PostgresRole.isEqualTo: expected a PostgresRole, got ${other.constructor?.name ?? typeof other}`);
|
|
120
|
+
return this.name === other.name;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
9
124
|
//#region src/core/ast/table-source.ts
|
|
10
125
|
var PostgresTableSource = class extends TableSource {
|
|
11
126
|
schema;
|
|
@@ -19,6 +134,18 @@ var PostgresTableSource = class extends TableSource {
|
|
|
19
134
|
}
|
|
20
135
|
};
|
|
21
136
|
//#endregion
|
|
137
|
+
//#region src/core/entity-kinds.ts
|
|
138
|
+
const policyEntityKind = {
|
|
139
|
+
kind: "policy",
|
|
140
|
+
schema: PostgresRlsPolicySchema,
|
|
141
|
+
construct: (input) => new PostgresRlsPolicy(input)
|
|
142
|
+
};
|
|
143
|
+
const roleEntityKind = {
|
|
144
|
+
kind: "role",
|
|
145
|
+
schema: PostgresRoleSchema,
|
|
146
|
+
construct: (input) => new PostgresRole(input)
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
22
149
|
//#region src/core/postgres-schema.ts
|
|
23
150
|
/**
|
|
24
151
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -34,7 +161,7 @@ var PostgresTableSource = class extends TableSource {
|
|
|
34
161
|
* prefix entirely — call sites stay polymorphic and never branch on
|
|
35
162
|
* `id === UNBOUND_NAMESPACE_ID`.
|
|
36
163
|
*/
|
|
37
|
-
var PostgresSchema = class extends
|
|
164
|
+
var PostgresSchema = class extends SqlNamespaceBase {
|
|
38
165
|
/**
|
|
39
166
|
* Stable singleton reference for the late-bound slot. Materialised
|
|
40
167
|
* lazily below the singleton subclass declaration so the static
|
|
@@ -48,7 +175,7 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
48
175
|
constructor(input) {
|
|
49
176
|
super();
|
|
50
177
|
this.id = input.id;
|
|
51
|
-
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
|
|
178
|
+
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds([policyEntityKind, roleEntityKind]), "carry");
|
|
52
179
|
const valueSetRaw = dispatched["valueSet"];
|
|
53
180
|
const withPresence = valueSetRaw !== void 0 && Object.keys(valueSetRaw).length === 0 ? {
|
|
54
181
|
...dispatched,
|
|
@@ -69,6 +196,12 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
69
196
|
get valueSet() {
|
|
70
197
|
return this.entries.valueSet;
|
|
71
198
|
}
|
|
199
|
+
get policy() {
|
|
200
|
+
return this.entries.policy ?? Object.freeze({});
|
|
201
|
+
}
|
|
202
|
+
get role() {
|
|
203
|
+
return this.entries.role ?? Object.freeze({});
|
|
204
|
+
}
|
|
72
205
|
/**
|
|
73
206
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
74
207
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -230,6 +363,6 @@ function postgresCreateNamespace(input) {
|
|
|
230
363
|
return new PostgresSchema(schemaInput);
|
|
231
364
|
}
|
|
232
365
|
//#endregion
|
|
233
|
-
export {
|
|
366
|
+
export { policyEntityKind as a, PostgresRole as c, isPostgresRlsPolicy as d, PostgresRlsPolicySchema as f, postgresCreateNamespace as i, PostgresRlsPolicy as l, PostgresUnboundSchema as n, roleEntityKind as o, PostgresRoleSchema as p, isPostgresSchema as r, PostgresTableSource as s, PostgresSchema as t, assertPostgresRlsPolicy as u };
|
|
234
367
|
|
|
235
|
-
//# sourceMappingURL=postgres-schema-
|
|
368
|
+
//# sourceMappingURL=postgres-schema-DLcc3W2-.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-DLcc3W2-.mjs","names":[],"sources":["../src/core/postgres-validators.ts","../src/core/schema-ir/postgres-rls-policy.ts","../src/core/schema-ir/postgres-role.ts","../src/core/ast/table-source.ts","../src/core/entity-kinds.ts","../src/core/postgres-schema.ts"],"sourcesContent":["import { type } from 'arktype';\n\nexport const PostgresRoleSchema = type({\n kind: \"'role'\",\n name: 'string',\n namespaceId: 'string',\n});\n\nexport const PostgresRlsPolicySchema = type({\n kind: \"'policy'\",\n name: 'string',\n prefix: 'string',\n tableName: 'string',\n namespaceId: 'string',\n operation: \"'select' | 'insert' | 'update' | 'delete' | 'all'\",\n roles: type.string.array().readonly(),\n 'using?': 'string',\n 'withCheck?': 'string',\n permissive: 'boolean',\n});\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from '@prisma-next/sql-contract/types';\n\nexport type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';\n\nexport interface PostgresRlsPolicyInput {\n /** Full wire name: `<prefix>_<8hex>`. Stored as-is; hashing is not this class's job. */\n readonly name: string;\n /** User-supplied prefix (the part before the `_<8hex>` suffix). */\n readonly prefix: string;\n /** Name of the table this policy attaches to, by name within the same schema. */\n readonly tableName: string;\n /** Namespace coordinate (schema name). Policies are schema-scoped. */\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n /** Sorted role names rendered in `TO <roles>`. Plain strings in this slice. */\n readonly roles: readonly string[];\n /** USING predicate SQL string, if present. */\n readonly using?: string;\n /** WITH CHECK predicate SQL string, if present. */\n readonly withCheck?: string;\n /** `true` = `AS PERMISSIVE`, `false` = `AS RESTRICTIVE`. */\n readonly permissive: boolean;\n}\n\n/**\n * Postgres IR class for a row-level security policy (`CREATE POLICY … ON …`).\n *\n * Target-only concept — no SQL-family abstract. Extends `SqlNode` directly.\n * Frozen at construction via `freezeNode(this)`. The `kind: 'policy'`\n * discriminant is enumerable (overrides SqlNode's non-enumerable `'sql'`) so it\n * survives JSON serialization and enables dispatch. The literal matches the\n * entries key (one-string rule: node.kind === entries key === entity kind).\n */\nexport class PostgresRlsPolicy extends SqlNode implements DiffableNode {\n override readonly kind = 'policy' as const;\n readonly name: string;\n readonly prefix: string;\n readonly tableName: string;\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n declare readonly using?: string;\n declare readonly withCheck?: string;\n readonly permissive: boolean;\n\n constructor(input: PostgresRlsPolicyInput) {\n super();\n this.name = input.name;\n this.prefix = input.prefix;\n this.tableName = input.tableName;\n this.namespaceId = input.namespaceId;\n this.operation = input.operation;\n this.roles = Object.freeze([...input.roles]);\n if (input.using !== undefined) this.using = input.using;\n if (input.withCheck !== undefined) this.withCheck = input.withCheck;\n this.permissive = input.permissive;\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n /**\n * Equality by wire name only. The wire name is `<prefix>_<sha256(body)[0..8]>`,\n * so name-equality IS body-equality — two policies with different bodies\n * have different hashes and therefore different names. We deliberately\n * skip comparing bodies directly because Postgres reprints predicate\n * expressions (e.g. strips outer parentheses), so a byte-compare against\n * the authored body would produce false mismatches on a clean re-verify.\n */\n isEqualTo(other: DiffableNode): boolean {\n if (!isPostgresRlsPolicy(other)) {\n throw new Error(\n `PostgresRlsPolicy.isEqualTo: expected a PostgresRlsPolicy, got ${other.constructor?.name ?? typeof other}`,\n );\n }\n return this.name === other.name;\n }\n}\n\nexport function isPostgresRlsPolicy(node: DiffableNode | undefined): node is PostgresRlsPolicy {\n return node !== undefined && 'kind' in node && node.kind === 'policy';\n}\n\nexport function assertPostgresRlsPolicy(\n node: DiffableNode | undefined,\n): asserts node is PostgresRlsPolicy {\n if (!isPostgresRlsPolicy(node)) {\n const kind = node !== undefined && 'kind' in node ? String(node.kind) : typeof node;\n throw new Error(\n `planPostgresSchemaDiff: expected a PostgresRlsPolicy on the policy-diff path but got ${kind}`,\n );\n }\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from '@prisma-next/sql-contract/types';\n\nexport interface PostgresRoleInput {\n readonly name: string;\n /**\n * Namespace coordinate. Roles are cluster-scoped; pass `UNBOUND_NAMESPACE_ID`\n * from `@prisma-next/framework-components/ir`.\n */\n readonly namespaceId: string;\n}\n\n/**\n * Postgres IR class for a database role (`CREATE ROLE …`).\n *\n * Roles are cluster-scoped, so their namespace coordinate is always\n * `UNBOUND_NAMESPACE_ID`. Target-only concept — no SQL-family abstract.\n * Extends `SqlNode` directly, frozen at construction via `freezeNode(this)`.\n * The `kind: 'role'` discriminant is enumerable so it survives JSON.\n * Matches the entries key (one-string rule).\n */\nexport class PostgresRole extends SqlNode implements DiffableNode {\n override readonly kind = 'role' as const;\n readonly name: string;\n readonly namespaceId: string;\n\n constructor(input: PostgresRoleInput) {\n super();\n this.name = input.name;\n this.namespaceId = input.namespaceId;\n freezeNode(this);\n }\n\n /** Roles are cluster-unique; the name alone is sufficient as the id. */\n get id(): string {\n return this.name;\n }\n\n children(): readonly DiffableNode[] {\n return [];\n }\n\n isEqualTo(other: DiffableNode): boolean {\n if (!(other instanceof PostgresRole)) {\n throw new Error(\n `PostgresRole.isEqualTo: expected a PostgresRole, got ${other.constructor?.name ?? typeof other}`,\n );\n }\n return this.name === other.name;\n }\n}\n","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 type { EntityKindDescriptor } from '@prisma-next/framework-components/ir';\nimport { PostgresRlsPolicySchema, PostgresRoleSchema } from './postgres-validators';\nimport { PostgresRlsPolicy, type PostgresRlsPolicyInput } from './schema-ir/postgres-rls-policy';\nimport { PostgresRole, type PostgresRoleInput } from './schema-ir/postgres-role';\n\nexport const policyEntityKind: EntityKindDescriptor<PostgresRlsPolicyInput, PostgresRlsPolicy> = {\n kind: 'policy',\n schema: PostgresRlsPolicySchema,\n construct: (input) => new PostgresRlsPolicy(input),\n};\n\nexport const roleEntityKind: EntityKindDescriptor<PostgresRoleInput, PostgresRole> = {\n kind: 'role',\n schema: PostgresRoleSchema,\n construct: (input) => new PostgresRole(input),\n};\n","import type { Contract } from '@prisma-next/contract/types';\nimport {\n freezeNode,\n hydrateNamespaceEntities,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';\nimport {\n SqlNamespaceBase,\n type SqlNamespaceEntries,\n type SqlNamespaceInput,\n type SqlStorage,\n type StorageTable,\n type StorageValueSet,\n} from '@prisma-next/sql-contract/types';\n\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 { policyEntityKind, roleEntityKind } from './entity-kinds';\nimport type { PostgresRlsPolicy } from './schema-ir/postgres-rls-policy';\nimport type { PostgresRole } from './schema-ir/postgres-role';\nimport { escapeLiteral } from './sql-utils';\n\nexport type PostgresContract = Contract<SqlStorage> & { readonly target: 'postgres' };\n\nexport type PostgresNamespaceEntries = SqlNamespaceEntries & {\n readonly policy?: Readonly<Record<string, PostgresRlsPolicy>>;\n readonly role?: Readonly<Record<string, PostgresRole>>;\n};\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 SqlNamespaceBase {\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: PostgresNamespaceEntries;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(\n input.entries,\n composeSqlEntityKinds([policyEntityKind, roleEntityKind]),\n 'carry',\n );\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 PostgresNamespaceEntries,\n 'composeSqlEntityKinds([policyEntityKind, roleEntityKind]) supplies table→StorageTable, valueSet→StorageValueSet, policy→PostgresRlsPolicy, role→PostgresRole descriptors'\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 get policy(): Readonly<Record<string, PostgresRlsPolicy>> {\n return this.entries.policy ?? Object.freeze({});\n }\n\n get role(): Readonly<Record<string, PostgresRole>> {\n return this.entries.role ?? Object.freeze({});\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: SqlNamespaceInput): 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":";;;;;;;;;;;AAEA,MAAa,qBAAqB,KAAK;CACrC,MAAM;CACN,MAAM;CACN,aAAa;AACf,CAAC;AAED,MAAa,0BAA0B,KAAK;CAC1C,MAAM;CACN,MAAM;CACN,QAAQ;CACR,WAAW;CACX,aAAa;CACb,WAAW;CACX,OAAO,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACpC,UAAU;CACV,cAAc;CACd,YAAY;AACd,CAAC;;;;;;;;;;;;ACgBD,IAAa,oBAAb,cAAuC,QAAgC;CACrE,OAAyB;CACzB;CACA;CACA;CACA;CACA;CACA;CAGA;CAEA,YAAY,OAA+B;E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Q,IAA8C,SAAS;AACjE;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,OAA0C;CAChF,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"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { t as PostgresRlsPolicy } from "./postgres-rls-policy-12wAEQhs.mjs";
|
|
2
|
+
import { o as PostgresRole } from "./postgres-schema-DJUEkWg-.mjs";
|
|
3
|
+
import { PrimaryKey, SqlAnnotations, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlSchemaIRNode, SqlSchemaTarget, SqlTableIRInput, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
|
+
import { DiffableNode } from "@prisma-next/framework-components/control";
|
|
5
|
+
|
|
6
|
+
//#region src/core/schema-ir/postgres-table-ir.d.ts
|
|
7
|
+
interface PostgresTableIRInput extends SqlTableIRInput {
|
|
8
|
+
readonly rlsPolicies?: readonly PostgresRlsPolicy[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Postgres-specific table IR node. Carries all `SqlTableIR` fields plus
|
|
12
|
+
* `rlsPolicies`, and implements `DiffableNode` so the table instance is
|
|
13
|
+
* directly the diff-tree node — no separate wrapper needed.
|
|
14
|
+
*
|
|
15
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because
|
|
16
|
+
* `SqlTableIR` calls `freezeNode` in its own constructor, which prevents
|
|
17
|
+
* subclass field initialisation. Same pattern as `PostgresSchemaIR`.
|
|
18
|
+
*
|
|
19
|
+
* `id` is the table name. `children()` returns the policies on this table.
|
|
20
|
+
* `isEqualTo` is always true — table-level attributes are not diffed yet.
|
|
21
|
+
*/
|
|
22
|
+
declare class PostgresTableIR extends SqlSchemaIRNode implements DiffableNode {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly columns: Readonly<Record<string, SqlColumnIR>>;
|
|
25
|
+
readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;
|
|
26
|
+
readonly uniques: ReadonlyArray<SqlUniqueIR>;
|
|
27
|
+
readonly indexes: ReadonlyArray<SqlIndexIR>;
|
|
28
|
+
readonly primaryKey?: PrimaryKey;
|
|
29
|
+
readonly annotations?: SqlAnnotations;
|
|
30
|
+
readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;
|
|
31
|
+
readonly rlsPolicies: readonly PostgresRlsPolicy[];
|
|
32
|
+
constructor(input: PostgresTableIRInput);
|
|
33
|
+
get id(): string;
|
|
34
|
+
isEqualTo(_other: DiffableNode): boolean;
|
|
35
|
+
children(): readonly DiffableNode[];
|
|
36
|
+
}
|
|
37
|
+
declare function isPostgresTableIR(node: DiffableNode): node is PostgresTableIR;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/core/schema-ir/postgres-schema-ir.d.ts
|
|
40
|
+
interface PostgresSchemaIRInput {
|
|
41
|
+
readonly tables: Record<string, PostgresTableIR | (SqlTableIRInput & {
|
|
42
|
+
rlsPolicies?: readonly PostgresRlsPolicy[];
|
|
43
|
+
})>;
|
|
44
|
+
readonly pgSchemaName: string;
|
|
45
|
+
readonly pgVersion: string;
|
|
46
|
+
readonly roles: readonly PostgresRole[];
|
|
47
|
+
readonly existingSchemas: readonly string[];
|
|
48
|
+
readonly nativeEnumTypeNames: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Postgres-specific schema IR. Mirrors the structure of `SqlSchemaIR`
|
|
52
|
+
* (same `tables` + optional `annotations` fields) and adds typed fields for
|
|
53
|
+
* data the postgres adapter collects during introspection.
|
|
54
|
+
*
|
|
55
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlSchemaIR` because
|
|
56
|
+
* `SqlSchemaIR` calls `freezeNode` in its constructor, which prevents
|
|
57
|
+
* subclass field initialisation. `PostgresSchemaIR` replicates the minimal
|
|
58
|
+
* `SqlSchemaIR` structure and freezes itself at the end of its own
|
|
59
|
+
* constructor.
|
|
60
|
+
*
|
|
61
|
+
* `tables` holds `PostgresTableIR` instances which carry their own RLS
|
|
62
|
+
* policies. `children()` returns the tables directly — the table instances
|
|
63
|
+
* ARE the diff-tree nodes.
|
|
64
|
+
*
|
|
65
|
+
* Nothing RLS-specific leaks into the sql-family layer.
|
|
66
|
+
*/
|
|
67
|
+
declare class PostgresSchemaIR extends SqlSchemaIRNode implements DiffableNode {
|
|
68
|
+
readonly nodeTarget: SqlSchemaTarget;
|
|
69
|
+
readonly tables: Readonly<Record<string, PostgresTableIR>>;
|
|
70
|
+
readonly annotations?: SqlAnnotations;
|
|
71
|
+
readonly pgSchemaName: string;
|
|
72
|
+
readonly pgVersion: string;
|
|
73
|
+
readonly roles: readonly PostgresRole[];
|
|
74
|
+
readonly existingSchemas: readonly string[];
|
|
75
|
+
readonly nativeEnumTypeNames: readonly string[];
|
|
76
|
+
constructor(input: PostgresSchemaIRInput);
|
|
77
|
+
get id(): string;
|
|
78
|
+
get rlsPolicies(): readonly PostgresRlsPolicy[];
|
|
79
|
+
isEqualTo(_other: DiffableNode): boolean;
|
|
80
|
+
children(): readonly DiffableNode[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Structural guard for `PostgresSchemaIR`, narrowing on the `nodeTarget`
|
|
84
|
+
* discriminant rather than `instanceof`. `nodeTarget` is an enumerable own field
|
|
85
|
+
* (a plain class-field initializer), so it survives the `{ ...schema, tables }`
|
|
86
|
+
* spread the multi-space verify path (`projectSchemaToSpace`) produces — that
|
|
87
|
+
* projected object is not a class instance but retains every enumerable own
|
|
88
|
+
* property. The family-level `kind = 'sql-schema-ir'` discriminator is unusable
|
|
89
|
+
* here: it is shared by every SQL schema-IR node and is non-enumerable (dropped
|
|
90
|
+
* by the spread).
|
|
91
|
+
*/
|
|
92
|
+
declare function isPostgresSchemaIR(schema: SqlSchemaIR): schema is PostgresSchemaIR;
|
|
93
|
+
declare function assertPostgresSchemaIR(schema: SqlSchemaIR): asserts schema is PostgresSchemaIR;
|
|
94
|
+
/**
|
|
95
|
+
* Returns `schema` as-is when it is a real `PostgresSchemaIR` instance, or
|
|
96
|
+
* reconstructs one when `projectSchemaToSpace` has spread the class into a
|
|
97
|
+
* plain object (losing prototype methods).
|
|
98
|
+
*/
|
|
99
|
+
declare function ensurePostgresSchemaIR(schema: PostgresSchemaIR): PostgresSchemaIR;
|
|
100
|
+
//#endregion
|
|
101
|
+
export { isPostgresSchemaIR as a, isPostgresTableIR as c, ensurePostgresSchemaIR as i, PostgresSchemaIRInput as n, PostgresTableIR as o, assertPostgresSchemaIR as r, PostgresTableIRInput as s, PostgresSchemaIR as t };
|
|
102
|
+
//# sourceMappingURL=postgres-schema-ir-BJl_a3J7.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-ir-BJl_a3J7.d.mts","names":[],"sources":["../src/core/schema-ir/postgres-table-ir.ts","../src/core/schema-ir/postgres-schema-ir.ts"],"mappings":";;;;;;UAeiB,oBAAA,SAA6B,eAAe;EAAA,SAClD,WAAA,YAAuB,iBAAA;AAAA;AADlC;;;;;;;;AACmD;AAenD;;;AAhBA,cAgBa,eAAA,SAAwB,eAAA,YAA2B,YAAA;EAAA,SACrD,IAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,WAAA;EAAA,SACjC,WAAA,EAAa,aAAA,CAAc,eAAA;EAAA,SAC3B,OAAA,EAAS,aAAA,CAAc,WAAA;EAAA,SACvB,OAAA,EAAS,aAAA,CAAc,UAAA;EAAA,SACf,UAAA,GAAa,UAAA;EAAA,SACb,WAAA,GAAc,cAAA;EAAA,SACd,MAAA,GAAS,aAAA,CAAc,oBAAA;EAAA,SAC/B,WAAA,WAAsB,iBAAA;cAEnB,KAAA,EAAO,oBAAA;EAAA,IAsCf,EAAA;EAIJ,SAAA,CAAU,MAAA,EAAQ,YAAA;EAIlB,QAAA,aAAqB,YAAA;AAAA;AAAA,iBAKP,iBAAA,CAAkB,IAAA,EAAM,YAAA,GAAe,IAAA,IAAQ,eAAe;;;UC/E7D,qBAAA;EAAA,SACN,MAAA,EAAQ,MAAA,SAEf,eAAA,IAAmB,eAAA;IAAoB,WAAA,YAAuB,iBAAA;EAAA;EAAA,SAEvD,YAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA,WAAgB,YAAA;EAAA,SAChB,eAAA;EAAA,SACA,mBAAA;AAAA;ADQX;;;;;;;;;;;;;;;;;AAAA,cCYa,gBAAA,SAAyB,eAAA,YAA2B,YAAA;EAAA,SACtD,UAAA,EAAY,eAAA;EAAA,SACZ,MAAA,EAAQ,QAAA,CAAS,MAAA,SAAe,eAAA;EAAA,SACxB,WAAA,GAAc,cAAA;EAAA,SACtB,YAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA,WAAgB,YAAA;EAAA,SAChB,eAAA;EAAA,SACA,mBAAA;cAEG,KAAA,EAAO,qBAAA;EAAA,IAgCf,EAAA;EAAA,IAIA,WAAA,aAAwB,iBAAA;EAI5B,SAAA,CAAU,MAAA,EAAQ,YAAA;EAIlB,QAAA,aAAqB,YAAA;AAAA;;;;;;;;;;;iBAeP,kBAAA,CAAmB,MAAA,EAAQ,WAAA,GAAc,MAAA,IAAU,gBAAgB;AAAA,iBAInE,sBAAA,CAAuB,MAAA,EAAQ,WAAA,WAAsB,MAAA,IAAU,gBAAgB;;;;;;iBAa/E,sBAAA,CAAuB,MAAA,EAAQ,gBAAA,GAAmB,gBAAgB"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
2
|
+
import { freezeNode } from "@prisma-next/framework-components/ir";
|
|
3
|
+
import { PrimaryKey, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIRNode, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
|
+
//#region src/core/schema-ir/postgres-table-ir.ts
|
|
5
|
+
/**
|
|
6
|
+
* Postgres-specific table IR node. Carries all `SqlTableIR` fields plus
|
|
7
|
+
* `rlsPolicies`, and implements `DiffableNode` so the table instance is
|
|
8
|
+
* directly the diff-tree node — no separate wrapper needed.
|
|
9
|
+
*
|
|
10
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because
|
|
11
|
+
* `SqlTableIR` calls `freezeNode` in its own constructor, which prevents
|
|
12
|
+
* subclass field initialisation. Same pattern as `PostgresSchemaIR`.
|
|
13
|
+
*
|
|
14
|
+
* `id` is the table name. `children()` returns the policies on this table.
|
|
15
|
+
* `isEqualTo` is always true — table-level attributes are not diffed yet.
|
|
16
|
+
*/
|
|
17
|
+
var PostgresTableIR = class extends SqlSchemaIRNode {
|
|
18
|
+
name;
|
|
19
|
+
columns;
|
|
20
|
+
foreignKeys;
|
|
21
|
+
uniques;
|
|
22
|
+
indexes;
|
|
23
|
+
rlsPolicies;
|
|
24
|
+
constructor(input) {
|
|
25
|
+
super();
|
|
26
|
+
this.name = input.name;
|
|
27
|
+
this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([key, col]) => [key, col instanceof SqlColumnIR ? col : new SqlColumnIR(col)])));
|
|
28
|
+
this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk)));
|
|
29
|
+
this.uniques = Object.freeze(input.uniques.map((u) => u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u)));
|
|
30
|
+
this.indexes = Object.freeze(input.indexes.map((i) => i instanceof SqlIndexIR ? i : new SqlIndexIR(i)));
|
|
31
|
+
if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey);
|
|
32
|
+
if (input.annotations !== void 0) this.annotations = input.annotations;
|
|
33
|
+
if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((c) => c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c)));
|
|
34
|
+
this.rlsPolicies = Object.freeze([...input.rlsPolicies ?? []]);
|
|
35
|
+
freezeNode(this);
|
|
36
|
+
}
|
|
37
|
+
get id() {
|
|
38
|
+
return this.name;
|
|
39
|
+
}
|
|
40
|
+
isEqualTo(_other) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
children() {
|
|
44
|
+
return this.rlsPolicies;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function isPostgresTableIR(node) {
|
|
48
|
+
return node instanceof PostgresTableIR;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/core/schema-ir/postgres-schema-ir.ts
|
|
52
|
+
/**
|
|
53
|
+
* Postgres-specific schema IR. Mirrors the structure of `SqlSchemaIR`
|
|
54
|
+
* (same `tables` + optional `annotations` fields) and adds typed fields for
|
|
55
|
+
* data the postgres adapter collects during introspection.
|
|
56
|
+
*
|
|
57
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlSchemaIR` because
|
|
58
|
+
* `SqlSchemaIR` calls `freezeNode` in its constructor, which prevents
|
|
59
|
+
* subclass field initialisation. `PostgresSchemaIR` replicates the minimal
|
|
60
|
+
* `SqlSchemaIR` structure and freezes itself at the end of its own
|
|
61
|
+
* constructor.
|
|
62
|
+
*
|
|
63
|
+
* `tables` holds `PostgresTableIR` instances which carry their own RLS
|
|
64
|
+
* policies. `children()` returns the tables directly — the table instances
|
|
65
|
+
* ARE the diff-tree nodes.
|
|
66
|
+
*
|
|
67
|
+
* Nothing RLS-specific leaks into the sql-family layer.
|
|
68
|
+
*/
|
|
69
|
+
var PostgresSchemaIR = class extends SqlSchemaIRNode {
|
|
70
|
+
nodeTarget = "postgres";
|
|
71
|
+
tables;
|
|
72
|
+
pgSchemaName;
|
|
73
|
+
pgVersion;
|
|
74
|
+
roles;
|
|
75
|
+
existingSchemas;
|
|
76
|
+
nativeEnumTypeNames;
|
|
77
|
+
constructor(input) {
|
|
78
|
+
super();
|
|
79
|
+
this.tables = Object.freeze(Object.fromEntries(Object.entries(input.tables).map(([key, t]) => [key, t instanceof PostgresTableIR ? t : new PostgresTableIR(t)])));
|
|
80
|
+
this.pgSchemaName = input.pgSchemaName;
|
|
81
|
+
this.pgVersion = input.pgVersion;
|
|
82
|
+
this.roles = Object.freeze([...input.roles]);
|
|
83
|
+
this.existingSchemas = Object.freeze([...input.existingSchemas]);
|
|
84
|
+
this.nativeEnumTypeNames = Object.freeze([...input.nativeEnumTypeNames]);
|
|
85
|
+
this.annotations = { pg: {
|
|
86
|
+
schema: input.pgSchemaName,
|
|
87
|
+
...input.nativeEnumTypeNames.length > 0 && { nativeEnumTypeNames: input.nativeEnumTypeNames },
|
|
88
|
+
...input.existingSchemas.length > 0 && { existingSchemas: input.existingSchemas }
|
|
89
|
+
} };
|
|
90
|
+
freezeNode(this);
|
|
91
|
+
}
|
|
92
|
+
get id() {
|
|
93
|
+
return this.pgSchemaName;
|
|
94
|
+
}
|
|
95
|
+
get rlsPolicies() {
|
|
96
|
+
return Object.values(this.tables).flatMap((t) => t.rlsPolicies);
|
|
97
|
+
}
|
|
98
|
+
isEqualTo(_other) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
children() {
|
|
102
|
+
return Object.values(this.tables);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Structural guard for `PostgresSchemaIR`, narrowing on the `nodeTarget`
|
|
107
|
+
* discriminant rather than `instanceof`. `nodeTarget` is an enumerable own field
|
|
108
|
+
* (a plain class-field initializer), so it survives the `{ ...schema, tables }`
|
|
109
|
+
* spread the multi-space verify path (`projectSchemaToSpace`) produces — that
|
|
110
|
+
* projected object is not a class instance but retains every enumerable own
|
|
111
|
+
* property. The family-level `kind = 'sql-schema-ir'` discriminator is unusable
|
|
112
|
+
* here: it is shared by every SQL schema-IR node and is non-enumerable (dropped
|
|
113
|
+
* by the spread).
|
|
114
|
+
*/
|
|
115
|
+
function isPostgresSchemaIR(schema) {
|
|
116
|
+
return schema.nodeTarget === "postgres";
|
|
117
|
+
}
|
|
118
|
+
function assertPostgresSchemaIR(schema) {
|
|
119
|
+
if (!isPostgresSchemaIR(schema)) throw new Error(`planPostgresSchemaDiff: expected a PostgresSchemaIR but got nodeTarget=${String(schema.nodeTarget ?? typeof schema)}`);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns `schema` as-is when it is a real `PostgresSchemaIR` instance, or
|
|
123
|
+
* reconstructs one when `projectSchemaToSpace` has spread the class into a
|
|
124
|
+
* plain object (losing prototype methods).
|
|
125
|
+
*/
|
|
126
|
+
function ensurePostgresSchemaIR(schema) {
|
|
127
|
+
if (schema instanceof PostgresSchemaIR) return schema;
|
|
128
|
+
return new PostgresSchemaIR(blindCast(schema));
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { PostgresTableIR as a, isPostgresSchemaIR as i, assertPostgresSchemaIR as n, isPostgresTableIR as o, ensurePostgresSchemaIR as r, PostgresSchemaIR as t };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=postgres-schema-ir-I_FiUndw.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-ir-I_FiUndw.mjs","names":[],"sources":["../src/core/schema-ir/postgres-table-ir.ts","../src/core/schema-ir/postgres-schema-ir.ts"],"sourcesContent":["import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport {\n PrimaryKey,\n type SqlAnnotations,\n SqlCheckConstraintIR,\n SqlColumnIR,\n SqlForeignKeyIR,\n SqlIndexIR,\n SqlSchemaIRNode,\n type SqlTableIRInput,\n SqlUniqueIR,\n} from '@prisma-next/sql-schema-ir/types';\nimport type { PostgresRlsPolicy } from './postgres-rls-policy';\n\nexport interface PostgresTableIRInput extends SqlTableIRInput {\n readonly rlsPolicies?: readonly PostgresRlsPolicy[];\n}\n\n/**\n * Postgres-specific table IR node. Carries all `SqlTableIR` fields plus\n * `rlsPolicies`, and implements `DiffableNode` so the table instance is\n * directly the diff-tree node — no separate wrapper needed.\n *\n * Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because\n * `SqlTableIR` calls `freezeNode` in its own constructor, which prevents\n * subclass field initialisation. Same pattern as `PostgresSchemaIR`.\n *\n * `id` is the table name. `children()` returns the policies on this table.\n * `isEqualTo` is always true — table-level attributes are not diffed yet.\n */\nexport class PostgresTableIR extends SqlSchemaIRNode implements DiffableNode {\n readonly name: string;\n readonly columns: Readonly<Record<string, SqlColumnIR>>;\n readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;\n readonly uniques: ReadonlyArray<SqlUniqueIR>;\n readonly indexes: ReadonlyArray<SqlIndexIR>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly annotations?: SqlAnnotations;\n declare readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;\n readonly rlsPolicies: readonly PostgresRlsPolicy[];\n\n constructor(input: PostgresTableIRInput) {\n super();\n this.name = input.name;\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([key, col]) => [\n key,\n col instanceof SqlColumnIR ? col : new SqlColumnIR(col),\n ]),\n ),\n );\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk))),\n );\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u))),\n );\n this.indexes = Object.freeze(\n input.indexes.map((i) => (i instanceof SqlIndexIR ? i : new SqlIndexIR(i))),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n if (input.annotations !== undefined) this.annotations = input.annotations;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(\n input.checks.map((c) =>\n c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c),\n ),\n );\n }\n this.rlsPolicies = Object.freeze([...(input.rlsPolicies ?? [])]);\n freezeNode(this);\n }\n\n get id(): string {\n return this.name;\n }\n\n isEqualTo(_other: DiffableNode): boolean {\n return true;\n }\n\n children(): readonly DiffableNode[] {\n return this.rlsPolicies;\n }\n}\n\nexport function isPostgresTableIR(node: DiffableNode): node is PostgresTableIR {\n return node instanceof PostgresTableIR;\n}\n","import type { DiffableNode } from '@prisma-next/framework-components/control';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport {\n type SqlAnnotations,\n type SqlSchemaIR,\n SqlSchemaIRNode,\n type SqlSchemaTarget,\n type SqlTableIRInput,\n} from '@prisma-next/sql-schema-ir/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { PostgresRlsPolicy } from './postgres-rls-policy';\nimport type { PostgresRole } from './postgres-role';\nimport { PostgresTableIR } from './postgres-table-ir';\n\nexport interface PostgresSchemaIRInput {\n readonly tables: Record<\n string,\n PostgresTableIR | (SqlTableIRInput & { rlsPolicies?: readonly PostgresRlsPolicy[] })\n >;\n readonly pgSchemaName: string;\n readonly pgVersion: string;\n readonly roles: readonly PostgresRole[];\n readonly existingSchemas: readonly string[];\n readonly nativeEnumTypeNames: readonly string[];\n}\n\n/**\n * Postgres-specific schema IR. Mirrors the structure of `SqlSchemaIR`\n * (same `tables` + optional `annotations` fields) and adds typed fields for\n * data the postgres adapter collects during introspection.\n *\n * Extends `SqlSchemaIRNode` directly rather than `SqlSchemaIR` because\n * `SqlSchemaIR` calls `freezeNode` in its constructor, which prevents\n * subclass field initialisation. `PostgresSchemaIR` replicates the minimal\n * `SqlSchemaIR` structure and freezes itself at the end of its own\n * constructor.\n *\n * `tables` holds `PostgresTableIR` instances which carry their own RLS\n * policies. `children()` returns the tables directly — the table instances\n * ARE the diff-tree nodes.\n *\n * Nothing RLS-specific leaks into the sql-family layer.\n */\nexport class PostgresSchemaIR extends SqlSchemaIRNode implements DiffableNode {\n readonly nodeTarget: SqlSchemaTarget = 'postgres';\n readonly tables: Readonly<Record<string, PostgresTableIR>>;\n declare readonly annotations?: SqlAnnotations;\n readonly pgSchemaName: string;\n readonly pgVersion: string;\n readonly roles: readonly PostgresRole[];\n readonly existingSchemas: readonly string[];\n readonly nativeEnumTypeNames: readonly string[];\n\n constructor(input: PostgresSchemaIRInput) {\n super();\n this.tables = Object.freeze(\n Object.fromEntries(\n Object.entries(input.tables).map(([key, t]) => [\n key,\n t instanceof PostgresTableIR ? t : new PostgresTableIR(t),\n ]),\n ),\n );\n this.pgSchemaName = input.pgSchemaName;\n this.pgVersion = input.pgVersion;\n this.roles = Object.freeze([...input.roles]);\n this.existingSchemas = Object.freeze([...input.existingSchemas]);\n this.nativeEnumTypeNames = Object.freeze([...input.nativeEnumTypeNames]);\n // Populate the annotations.pg bag with only the subset the family layer\n // reads (nativeEnumTypeNames for PSL inference, existingSchemas for\n // namespace presence checks).\n this.annotations = {\n pg: {\n schema: input.pgSchemaName,\n ...(input.nativeEnumTypeNames.length > 0 && {\n nativeEnumTypeNames: input.nativeEnumTypeNames,\n }),\n ...(input.existingSchemas.length > 0 && {\n existingSchemas: input.existingSchemas,\n }),\n },\n };\n freezeNode(this);\n }\n\n get id(): string {\n return this.pgSchemaName;\n }\n\n get rlsPolicies(): readonly PostgresRlsPolicy[] {\n return Object.values(this.tables).flatMap((t) => t.rlsPolicies);\n }\n\n isEqualTo(_other: DiffableNode): boolean {\n return true;\n }\n\n children(): readonly DiffableNode[] {\n return Object.values(this.tables);\n }\n}\n\n/**\n * Structural guard for `PostgresSchemaIR`, narrowing on the `nodeTarget`\n * discriminant rather than `instanceof`. `nodeTarget` is an enumerable own field\n * (a plain class-field initializer), so it survives the `{ ...schema, tables }`\n * spread the multi-space verify path (`projectSchemaToSpace`) produces — that\n * projected object is not a class instance but retains every enumerable own\n * property. The family-level `kind = 'sql-schema-ir'` discriminator is unusable\n * here: it is shared by every SQL schema-IR node and is non-enumerable (dropped\n * by the spread).\n */\nexport function isPostgresSchemaIR(schema: SqlSchemaIR): schema is PostgresSchemaIR {\n return schema.nodeTarget === 'postgres';\n}\n\nexport function assertPostgresSchemaIR(schema: SqlSchemaIR): asserts schema is PostgresSchemaIR {\n if (!isPostgresSchemaIR(schema)) {\n throw new Error(\n `planPostgresSchemaDiff: expected a PostgresSchemaIR but got nodeTarget=${String(schema.nodeTarget ?? typeof schema)}`,\n );\n }\n}\n\n/**\n * Returns `schema` as-is when it is a real `PostgresSchemaIR` instance, or\n * reconstructs one when `projectSchemaToSpace` has spread the class into a\n * plain object (losing prototype methods).\n */\nexport function ensurePostgresSchemaIR(schema: PostgresSchemaIR): PostgresSchemaIR {\n if (schema instanceof PostgresSchemaIR) return schema;\n return new PostgresSchemaIR(\n blindCast<\n PostgresSchemaIRInput,\n 'spread objects from projectSchemaToSpace preserve all own-enumerable fields'\n >(schema),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,IAAa,kBAAb,cAAqC,gBAAwC;CAC3E;CACA;CACA;CACA;CACA;CAIA;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,UAAU,OAAO,OACpB,OAAO,YACL,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,SAAS,CAChD,KACA,eAAe,cAAc,MAAM,IAAI,YAAY,GAAG,CACxD,CAAC,CACH,CACF;EACA,KAAK,cAAc,OAAO,OACxB,MAAM,YAAY,KAAK,OAAQ,cAAc,kBAAkB,KAAK,IAAI,gBAAgB,EAAE,CAAE,CAC9F;EACA,KAAK,UAAU,OAAO,OACpB,MAAM,QAAQ,KAAK,MAAO,aAAa,cAAc,IAAI,IAAI,YAAY,CAAC,CAAE,CAC9E;EACA,KAAK,UAAU,OAAO,OACpB,MAAM,QAAQ,KA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;GACF,QAAQ,MAAM;GACd,GAAI,MAAM,oBAAoB,SAAS,KAAK,EAC1C,qBAAqB,MAAM,oBAC7B;GACA,GAAI,MAAM,gBAAgB,SAAS,KAAK,EACtC,iBAAiB,MAAM,gBACzB;EACF,EACF;EACA,WAAW,IAAI;CACjB;CAEA,IAAI,KAAa;EACf,OAAO,KAAK;CACd;CAEA,IAAI,cAA4C;EAC9C,OAAO,OAAO,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,WAAW;CAChE;CAEA,UAAU,QAA+B;EACvC,OAAO;CACT;CAEA,WAAoC;EAClC,OAAO,OAAO,OAAO,KAAK,MAAM;CAClC;AACF;;;;;;;;;;;AAYA,SAAgB,mBAAmB,QAAiD;CAClF,OAAO,OAAO,eAAe;AAC/B;AAEA,SAAgB,uBAAuB,QAAyD;CAC9F,IAAI,CAAC,mBAAmB,MAAM,GAC5B,MAAM,IAAI,MACR,0EAA0E,OAAO,OAAO,cAAc,OAAO,MAAM,GACrH;AAEJ;;;;;;AAOA,SAAgB,uBAAuB,QAA4C;CACjF,IAAI,kBAAkB,kBAAkB,OAAO;CAC/C,OAAO,IAAI,iBACT,UAGE,MAAM,CACV;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { r as isPostgresSchema } from "./postgres-schema-DLcc3W2-.mjs";
|
|
2
|
+
import { i as isPostgresSchemaIR } from "./postgres-schema-ir-I_FiUndw.mjs";
|
|
3
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
|
+
//#region src/core/schema-ir/postgres-schema-ir-annotations.ts
|
|
5
|
+
function resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schemaIr) {
|
|
6
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) return (schemaIr && isPostgresSchemaIR(schemaIr) ? schemaIr.pgSchemaName : void 0) ?? "public";
|
|
7
|
+
const namespace = storage.namespaces[namespaceId];
|
|
8
|
+
if (namespace && isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
|
|
9
|
+
return namespaceId;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { resolveDdlSchemaForNamespaceStorage as t };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=postgres-schema-ir-annotations-BbDSiwx2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-ir-annotations-BbDSiwx2.mjs","names":[],"sources":["../src/core/schema-ir/postgres-schema-ir-annotations.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { isPostgresSchema } from '../postgres-schema';\nimport { isPostgresSchemaIR } from './postgres-schema-ir';\n\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (\n (schemaIr && isPostgresSchemaIR(schemaIr) ? schemaIr.pgSchemaName : undefined) ?? 'public'\n );\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n"],"mappings":";;;;AAMA,SAAgB,oCACd,SACA,aACA,UACQ;CACR,IAAI,gBAAgB,sBAClB,QACG,YAAY,mBAAmB,QAAQ,IAAI,SAAS,eAAe,KAAA,MAAc;CAGtF,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,aAAa,iBAAiB,SAAS,GACzC,OAAO,UAAU,cAAc,OAAO;CAExC,OAAO;AACT"}
|
package/dist/render-ops.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyCodecDescriptor } from "@prisma-next/framework-components/codec";
|
|
2
|
-
import { Namespace } from "@prisma-next/framework-components/ir";
|
|
3
|
-
import {
|
|
2
|
+
import { AnyEntityKindDescriptor, Namespace } from "@prisma-next/framework-components/ir";
|
|
3
|
+
import { SqlNamespaceInput, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
4
4
|
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
5
5
|
import { Contract } from "@prisma-next/contract/types";
|
|
6
6
|
import { RuntimeTargetDescriptor, RuntimeTargetInstance } from "@prisma-next/framework-components/execution";
|
|
@@ -8,11 +8,11 @@ import { JsonObject } from "@prisma-next/utils/json";
|
|
|
8
8
|
|
|
9
9
|
//#region src/core/postgres-contract-serializer.d.ts
|
|
10
10
|
declare class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
11
|
-
constructor();
|
|
12
|
-
protected
|
|
13
|
-
protected hydrateSqlNamespaceEntry(nsId: string, raw: Namespace | Record<string, unknown>): Namespace | SqlNamespaceTablesInput;
|
|
11
|
+
constructor(extraPackEntityKinds?: readonly AnyEntityKindDescriptor[]);
|
|
12
|
+
protected hydrateSqlNamespaceEntry(nsId: string, raw: Record<string, unknown>): Namespace | SqlNamespaceInput;
|
|
14
13
|
serializeContract(contract: Contract<SqlStorage>): JsonObject;
|
|
15
14
|
private serializePostgresNamespace;
|
|
15
|
+
private serializeJsonObject;
|
|
16
16
|
private serializeJsonValue;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
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":";;;;;;;;;cAmEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;cACrE,oBAAA,YAA+B,uBAAA;EAAA,UAKxB,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,MAAA,oBACJ,SAAA,GAAY,iBAAA;EAyBN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;EAAA,QA0CpD,0BAAA;EAAA,QAgCA,mBAAA;EAAA,QAOA,kBAAA;AAAA;;;UC7KO,6BAAA,SAAsC,qBAAqB;;;;;AD0D5E;;cClDM,+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 { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-D5zHFKUz.mjs";
|
|
2
|
+
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-tGMiJcl4.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,8 @@
|
|
|
1
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
2
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
3
|
+
|
|
4
|
+
//#region src/core/schema-ir/postgres-schema-ir-annotations.d.ts
|
|
5
|
+
declare function resolveDdlSchemaForNamespaceStorage(storage: SqlStorage, namespaceId: string, schemaIr?: SqlSchemaIR): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { resolveDdlSchemaForNamespaceStorage };
|
|
8
|
+
//# sourceMappingURL=schema-ir-annotations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-ir-annotations.d.mts","names":[],"sources":["../src/core/schema-ir/postgres-schema-ir-annotations.ts"],"mappings":";;;;iBAMgB,mCAAA,CACd,OAAA,EAAS,UAAA,EACT,WAAA,UACA,QAAA,GAAW,WAAW"}
|