@prisma-next/target-postgres 0.14.0-dev.4 → 0.14.0-dev.40
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/authoring-BX1WHIdN.mjs +220 -0
- package/dist/authoring-BX1WHIdN.mjs.map +1 -0
- 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 +639 -21
- 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-BmLIe1z_.mjs} +62 -5
- package/dist/ddl-BmLIe1z_.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-Dug8Fez9.mjs} +119 -2
- package/dist/default-normalizer-Dug8Fez9.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-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/descriptor-meta-tjatyhtZ.mjs +18 -0
- package/dist/descriptor-meta-tjatyhtZ.mjs.map +1 -0
- package/dist/{issue-planner-DL6g3CmE.mjs → issue-planner-DbFvaAgu.mjs} +35 -10
- package/dist/issue-planner-DbFvaAgu.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 +5 -5
- package/dist/migration.mjs +4 -4
- 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-DmQEc3XV.d.mts → op-factory-call-CJWUxyUW.d.mts} +44 -13
- package/dist/op-factory-call-CJWUxyUW.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-t65c4jyY.mjs} +201 -28
- package/dist/op-factory-call-t65c4jyY.mjs.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-CG2pLHk-.mjs +640 -0
- package/dist/planner-CG2pLHk-.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-Cji5vxUf.mjs → planner-produced-postgres-migration-BolD0Mvc.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-BolD0Mvc.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-Cz9--XOT.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-Cz9--XOT.d.mts.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-DE9c4519.mjs} +2 -2
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-DE9c4519.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 +82 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-BegduLr6.mjs} +50 -23
- package/dist/postgres-contract-view-BegduLr6.mjs.map +1 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/postgres-database-schema-node-os8ogEap.d.mts +183 -0
- package/dist/postgres-database-schema-node-os8ogEap.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-BfMmK6tv.mjs} +21 -2
- package/dist/postgres-migration-BfMmK6tv.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-D7kNVWVG.d.mts} +19 -6
- package/dist/postgres-migration-D7kNVWVG.d.mts.map +1 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-BLIHBEfX.mjs} +108 -5
- package/dist/postgres-schema-BLIHBEfX.mjs.map +1 -0
- package/dist/postgres-schema-BywoeKlt.d.mts +189 -0
- package/dist/postgres-schema-BywoeKlt.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-1nNc8XDT.mjs +248 -0
- package/dist/postgres-table-schema-node-1nNc8XDT.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
- package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/resolve-ddl-schema-CL1RR1mx.mjs +20 -0
- package/dist/resolve-ddl-schema-CL1RR1mx.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +2 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +7 -6
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-ir-annotations.d.mts +14 -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 +22 -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 +122 -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-database-schema-node.ts +125 -0
- package/src/core/migrations/control-policy.ts +3 -0
- package/src/core/migrations/diff-database-schema.ts +191 -0
- package/src/core/migrations/issue-planner.ts +44 -3
- package/src/core/migrations/op-factory-call.ts +109 -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 +165 -33
- package/src/core/migrations/postgres-migration.ts +34 -4
- package/src/core/migrations/render-typescript.ts +42 -15
- package/src/core/migrations/resolve-ddl-schema.ts +24 -0
- package/src/core/migrations/runner.ts +13 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +24 -19
- package/src/core/postgres-contract-serializer.ts +50 -33
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +37 -0
- package/src/core/postgres-schema.ts +37 -13
- package/src/core/postgres-validators.ts +20 -0
- package/src/core/psl-infer/infer-psl-contract.ts +834 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +157 -0
- package/src/core/rls/canonicalize.ts +48 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +63 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +93 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +66 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +107 -0
- package/src/core/schema-ir/schema-node-kinds.ts +28 -0
- package/src/exports/contract-free.ts +7 -1
- package/src/exports/control.ts +39 -12
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +1 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner.ts +2 -0
- package/src/exports/rls-canonicalize.ts +6 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/types.ts +28 -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 +0 -324
- 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-migration-B5jKrXv3.mjs.map +0 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/render-typescript-KMgosran.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
|
@@ -2,10 +2,95 @@ 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-rls-policy.ts
|
|
12
|
+
/**
|
|
13
|
+
* Postgres contract-IR class for a row-level security policy (`CREATE POLICY … ON …`).
|
|
14
|
+
*
|
|
15
|
+
* This is an authored, serialized Contract-IR entity — it is registered as an entity
|
|
16
|
+
* kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
|
|
17
|
+
* the schema-diff tree uses `PostgresPolicySchemaNode` for that role.
|
|
18
|
+
*
|
|
19
|
+
* Target-only concept — no SQL-family abstract. Extends `SqlNode` directly.
|
|
20
|
+
* Frozen at construction via `freezeNode(this)`. The `kind: 'policy'`
|
|
21
|
+
* discriminant is enumerable (overrides SqlNode's non-enumerable `'sql'`) so it
|
|
22
|
+
* survives JSON serialization and enables dispatch. The literal matches the
|
|
23
|
+
* entries key (one-string rule: node.kind === entries key === entity kind).
|
|
24
|
+
*/
|
|
25
|
+
var PostgresRlsPolicy = class extends SqlNode {
|
|
26
|
+
kind = "policy";
|
|
27
|
+
name;
|
|
28
|
+
prefix;
|
|
29
|
+
tableName;
|
|
30
|
+
namespaceId;
|
|
31
|
+
operation;
|
|
32
|
+
roles;
|
|
33
|
+
permissive;
|
|
34
|
+
constructor(input) {
|
|
35
|
+
super();
|
|
36
|
+
this.name = input.name;
|
|
37
|
+
this.prefix = input.prefix;
|
|
38
|
+
this.tableName = input.tableName;
|
|
39
|
+
this.namespaceId = input.namespaceId;
|
|
40
|
+
this.operation = input.operation;
|
|
41
|
+
this.roles = Object.freeze([...input.roles]);
|
|
42
|
+
if (input.using !== void 0) this.using = input.using;
|
|
43
|
+
if (input.withCheck !== void 0) this.withCheck = input.withCheck;
|
|
44
|
+
this.permissive = input.permissive;
|
|
45
|
+
freezeNode(this);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/core/postgres-role.ts
|
|
50
|
+
/**
|
|
51
|
+
* Postgres contract-IR class for a database role (`CREATE ROLE …`).
|
|
52
|
+
*
|
|
53
|
+
* This is an authored, serialized Contract-IR entity — it is registered as an entity
|
|
54
|
+
* kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
|
|
55
|
+
* the schema-diff tree uses `PostgresRoleSchemaNode` for that role.
|
|
56
|
+
*
|
|
57
|
+
* Roles are cluster-scoped, so their namespace coordinate is always
|
|
58
|
+
* `UNBOUND_NAMESPACE_ID`. Target-only concept — no SQL-family abstract.
|
|
59
|
+
* Extends `SqlNode` directly, frozen at construction via `freezeNode(this)`.
|
|
60
|
+
* The `kind: 'role'` discriminant is enumerable so it survives JSON.
|
|
61
|
+
* Matches the entries key (one-string rule).
|
|
62
|
+
*/
|
|
63
|
+
var PostgresRole = class extends SqlNode {
|
|
64
|
+
kind = "role";
|
|
65
|
+
name;
|
|
66
|
+
namespaceId;
|
|
67
|
+
constructor(input) {
|
|
68
|
+
super();
|
|
69
|
+
this.name = input.name;
|
|
70
|
+
this.namespaceId = input.namespaceId;
|
|
71
|
+
freezeNode(this);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/core/postgres-validators.ts
|
|
76
|
+
const PostgresRoleSchema = type({
|
|
77
|
+
kind: "'role'",
|
|
78
|
+
name: "string",
|
|
79
|
+
namespaceId: "string"
|
|
80
|
+
});
|
|
81
|
+
const PostgresRlsPolicySchema = type({
|
|
82
|
+
kind: "'policy'",
|
|
83
|
+
name: "string",
|
|
84
|
+
prefix: "string",
|
|
85
|
+
tableName: "string",
|
|
86
|
+
namespaceId: "string",
|
|
87
|
+
operation: "'select' | 'insert' | 'update' | 'delete' | 'all'",
|
|
88
|
+
roles: type.string.array().readonly(),
|
|
89
|
+
"using?": "string",
|
|
90
|
+
"withCheck?": "string",
|
|
91
|
+
permissive: "boolean"
|
|
92
|
+
});
|
|
93
|
+
//#endregion
|
|
9
94
|
//#region src/core/ast/table-source.ts
|
|
10
95
|
var PostgresTableSource = class extends TableSource {
|
|
11
96
|
schema;
|
|
@@ -19,6 +104,18 @@ var PostgresTableSource = class extends TableSource {
|
|
|
19
104
|
}
|
|
20
105
|
};
|
|
21
106
|
//#endregion
|
|
107
|
+
//#region src/core/entity-kinds.ts
|
|
108
|
+
const policyEntityKind = {
|
|
109
|
+
kind: "policy",
|
|
110
|
+
schema: PostgresRlsPolicySchema,
|
|
111
|
+
construct: (input) => new PostgresRlsPolicy(input)
|
|
112
|
+
};
|
|
113
|
+
const roleEntityKind = {
|
|
114
|
+
kind: "role",
|
|
115
|
+
schema: PostgresRoleSchema,
|
|
116
|
+
construct: (input) => new PostgresRole(input)
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
22
119
|
//#region src/core/postgres-schema.ts
|
|
23
120
|
/**
|
|
24
121
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -34,7 +131,7 @@ var PostgresTableSource = class extends TableSource {
|
|
|
34
131
|
* prefix entirely — call sites stay polymorphic and never branch on
|
|
35
132
|
* `id === UNBOUND_NAMESPACE_ID`.
|
|
36
133
|
*/
|
|
37
|
-
var PostgresSchema = class extends
|
|
134
|
+
var PostgresSchema = class extends SqlNamespaceBase {
|
|
38
135
|
/**
|
|
39
136
|
* Stable singleton reference for the late-bound slot. Materialised
|
|
40
137
|
* lazily below the singleton subclass declaration so the static
|
|
@@ -48,7 +145,7 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
48
145
|
constructor(input) {
|
|
49
146
|
super();
|
|
50
147
|
this.id = input.id;
|
|
51
|
-
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
|
|
148
|
+
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds([policyEntityKind, roleEntityKind]), "carry");
|
|
52
149
|
const valueSetRaw = dispatched["valueSet"];
|
|
53
150
|
const withPresence = valueSetRaw !== void 0 && Object.keys(valueSetRaw).length === 0 ? {
|
|
54
151
|
...dispatched,
|
|
@@ -69,6 +166,12 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
69
166
|
get valueSet() {
|
|
70
167
|
return this.entries.valueSet;
|
|
71
168
|
}
|
|
169
|
+
get policy() {
|
|
170
|
+
return this.entries.policy ?? Object.freeze({});
|
|
171
|
+
}
|
|
172
|
+
get role() {
|
|
173
|
+
return this.entries.role ?? Object.freeze({});
|
|
174
|
+
}
|
|
72
175
|
/**
|
|
73
176
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
74
177
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -230,6 +333,6 @@ function postgresCreateNamespace(input) {
|
|
|
230
333
|
return new PostgresSchema(schemaInput);
|
|
231
334
|
}
|
|
232
335
|
//#endregion
|
|
233
|
-
export {
|
|
336
|
+
export { policyEntityKind as a, PostgresRlsPolicySchema as c, PostgresRlsPolicy as d, postgresCreateNamespace as i, PostgresRoleSchema as l, PostgresUnboundSchema as n, roleEntityKind as o, isPostgresSchema as r, PostgresTableSource as s, PostgresSchema as t, PostgresRole as u };
|
|
234
337
|
|
|
235
|
-
//# sourceMappingURL=postgres-schema-
|
|
338
|
+
//# sourceMappingURL=postgres-schema-BLIHBEfX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-BLIHBEfX.mjs","names":[],"sources":["../src/core/postgres-rls-policy.ts","../src/core/postgres-role.ts","../src/core/postgres-validators.ts","../src/core/ast/table-source.ts","../src/core/entity-kinds.ts","../src/core/postgres-schema.ts"],"sourcesContent":["import { 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 contract-IR class for a row-level security policy (`CREATE POLICY … ON …`).\n *\n * This is an authored, serialized Contract-IR entity — it is registered as an entity\n * kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;\n * the schema-diff tree uses `PostgresPolicySchemaNode` for that role.\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 {\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","import { 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 contract-IR class for a database role (`CREATE ROLE …`).\n *\n * This is an authored, serialized Contract-IR entity — it is registered as an entity\n * kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;\n * the schema-diff tree uses `PostgresRoleSchemaNode` for that 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 {\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","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 {\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 { PostgresRlsPolicy, type PostgresRlsPolicyInput } from './postgres-rls-policy';\nimport { PostgresRole, type PostgresRoleInput } from './postgres-role';\nimport { PostgresRlsPolicySchema, PostgresRoleSchema } from './postgres-validators';\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 './postgres-rls-policy';\nimport type { PostgresRole } from './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":";;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,oBAAb,cAAuC,QAAQ;CAC7C,OAAyB;CACzB;CACA;CACA;CACA;CACA;CACA;CAGA;CAEA,YAAY,OAA+B;EACzC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,SAAS,MAAM;EACpB,KAAK,YAAY,MAAM;EACvB,KAAK,cAAc,MAAM;EACzB,KAAK,YAAY,MAAM;EACvB,KAAK,QAAQ,OAAO,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC;EAC3C,IAAI,MAAM,UAAU,KAAA,GAAW,KAAK,QAAQ,MAAM;EAClD,IAAI,MAAM,cAAc,KAAA,GAAW,KAAK,YAAY,MAAM;EAC1D,KAAK,aAAa,MAAM;EACxB,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;ACtCA,IAAa,eAAb,cAAkC,QAAQ;CACxC,OAAyB;CACzB;CACA;CAEA,YAAY,OAA0B;EACpC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,cAAc,MAAM;EACzB,WAAW,IAAI;CACjB;AACF;;;AClCA,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;;;ACbD,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;;;ACjBA,MAAa,mBAAoF;CAC/F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,kBAAkB,KAAK;AACnD;AAEA,MAAa,iBAAwE;CACnF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;;;;;;;;;;;;;;;;;ACqCA,IAAa,iBAAb,cAAoC,iBAAiB;;;;;;;;CAQnD,OAAO;CAGP;CACA;CAEA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAEhB,MAAM,aAAa,yBACjB,MAAM,SACN,sBAAsB,CAAC,kBAAkB,cAAc,CAAC,GACxD,OACF;EAGA,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;CAEA,IAAI,SAAsD;EACxD,OAAO,KAAK,QAAQ,UAAU,OAAO,OAAO,CAAC,CAAC;CAChD;CAEA,IAAI,OAA+C;EACjD,OAAO,KAAK,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAAC;CAC9C;;;;;;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,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,189 @@
|
|
|
1
|
+
import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
|
|
2
|
+
import { t as PostgresRlsPolicy } from "./postgres-rls-policy--CSddvMR.mjs";
|
|
3
|
+
import { SqlNamespaceBase, SqlNamespaceEntries, SqlNamespaceInput, SqlNode, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
4
|
+
import { CfExpr } from "@prisma-next/sql-relational-core/contract-free";
|
|
5
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
6
|
+
|
|
7
|
+
//#region src/core/postgres-role.d.ts
|
|
8
|
+
interface PostgresRoleInput {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Namespace coordinate. Roles are cluster-scoped; pass `UNBOUND_NAMESPACE_ID`
|
|
12
|
+
* from `@prisma-next/framework-components/ir`.
|
|
13
|
+
*/
|
|
14
|
+
readonly namespaceId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Postgres contract-IR class for a database role (`CREATE ROLE …`).
|
|
18
|
+
*
|
|
19
|
+
* This is an authored, serialized Contract-IR entity — it is registered as an entity
|
|
20
|
+
* kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
|
|
21
|
+
* the schema-diff tree uses `PostgresRoleSchemaNode` for that role.
|
|
22
|
+
*
|
|
23
|
+
* Roles are cluster-scoped, so their namespace coordinate is always
|
|
24
|
+
* `UNBOUND_NAMESPACE_ID`. Target-only concept — no SQL-family abstract.
|
|
25
|
+
* Extends `SqlNode` directly, frozen at construction via `freezeNode(this)`.
|
|
26
|
+
* The `kind: 'role'` discriminant is enumerable so it survives JSON.
|
|
27
|
+
* Matches the entries key (one-string rule).
|
|
28
|
+
*/
|
|
29
|
+
declare class PostgresRole extends SqlNode {
|
|
30
|
+
readonly kind: "role";
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly namespaceId: string;
|
|
33
|
+
constructor(input: PostgresRoleInput);
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/core/postgres-schema.d.ts
|
|
37
|
+
type PostgresContract = Contract<SqlStorage> & {
|
|
38
|
+
readonly target: 'postgres';
|
|
39
|
+
};
|
|
40
|
+
type PostgresNamespaceEntries = SqlNamespaceEntries & {
|
|
41
|
+
readonly policy?: Readonly<Record<string, PostgresRlsPolicy>>;
|
|
42
|
+
readonly role?: Readonly<Record<string, PostgresRole>>;
|
|
43
|
+
};
|
|
44
|
+
interface PostgresSchemaInput {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
50
|
+
* SCHEMA …`). Each Postgres `SqlStorage` carries a
|
|
51
|
+
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
52
|
+
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
53
|
+
*
|
|
54
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
55
|
+
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
56
|
+
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
57
|
+
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
58
|
+
* The unbound singleton below overrides these methods to elide the
|
|
59
|
+
* prefix entirely — call sites stay polymorphic and never branch on
|
|
60
|
+
* `id === UNBOUND_NAMESPACE_ID`.
|
|
61
|
+
*/
|
|
62
|
+
declare class PostgresSchema extends SqlNamespaceBase {
|
|
63
|
+
/**
|
|
64
|
+
* Stable singleton reference for the late-bound slot. Materialised
|
|
65
|
+
* lazily below the singleton subclass declaration so the static
|
|
66
|
+
* initialiser sees the subclass before assigning. Consumers always
|
|
67
|
+
* reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`
|
|
68
|
+
* — same identity).
|
|
69
|
+
*/
|
|
70
|
+
static unbound: PostgresUnboundSchema;
|
|
71
|
+
readonly kind: 'schema';
|
|
72
|
+
readonly id: string;
|
|
73
|
+
readonly entries: PostgresNamespaceEntries;
|
|
74
|
+
constructor(input: PostgresSchemaInput);
|
|
75
|
+
get table(): Readonly<Record<string, StorageTable>>;
|
|
76
|
+
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
77
|
+
get policy(): Readonly<Record<string, PostgresRlsPolicy>>;
|
|
78
|
+
get role(): Readonly<Record<string, PostgresRole>>;
|
|
79
|
+
/**
|
|
80
|
+
* The bare schema qualifier as it would appear in a rendered SQL
|
|
81
|
+
* fragment (already quoted). The unbound-schema singleton overrides
|
|
82
|
+
* this to return `''`.
|
|
83
|
+
*/
|
|
84
|
+
qualifier(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Qualify a table name with the schema prefix
|
|
87
|
+
* (`"<schema>"."<table>"`). The unbound-schema singleton overrides
|
|
88
|
+
* this to emit just `"<table>"` so the resolved DDL is unqualified
|
|
89
|
+
* and `search_path` decides where the object lands at runtime.
|
|
90
|
+
*/
|
|
91
|
+
qualifyTable(tableName: string): string;
|
|
92
|
+
/**
|
|
93
|
+
* Render a SQL string-literal containing the qualified-name form
|
|
94
|
+
* suitable for `to_regclass(...)` arguments (e.g. `'"public"."user"'`).
|
|
95
|
+
* The unbound singleton overrides this to elide the schema prefix
|
|
96
|
+
* (`'"user"'`) so `search_path` resolves the object at runtime.
|
|
97
|
+
*/
|
|
98
|
+
regclassLiteral(name: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Render a SQL expression that evaluates to this namespace's schema
|
|
101
|
+
* name at runtime, ready to drop into a `WHERE table_schema = …` /
|
|
102
|
+
* `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL
|
|
103
|
+
* literal (`'public'`); the unbound singleton overrides this to emit
|
|
104
|
+
* `current_schema()` so catalog queries match whichever schema the
|
|
105
|
+
* connection's `search_path` resolved at runtime.
|
|
106
|
+
*/
|
|
107
|
+
schemaSqlExpression(): string;
|
|
108
|
+
/**
|
|
109
|
+
* Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
|
|
110
|
+
* builder-built catalog check compares `n.nspname` / `table_schema`
|
|
111
|
+
* against. Named schemas bind the schema name as a text parameter; the
|
|
112
|
+
* unbound singleton overrides this to the opaque `current_schema()`
|
|
113
|
+
* expression so the live connection's `search_path` decides at runtime.
|
|
114
|
+
*/
|
|
115
|
+
schemaFilterExpression(): CfExpr;
|
|
116
|
+
/**
|
|
117
|
+
* Typed-AST counterpart of {@link qualifyTable}: the FROM source a
|
|
118
|
+
* builder-built check uses to address a user table in this namespace.
|
|
119
|
+
* Named schemas qualify (`"schema"."table"`); the unbound singleton
|
|
120
|
+
* overrides this to leave the table unqualified so `search_path`
|
|
121
|
+
* resolves it at runtime.
|
|
122
|
+
*/
|
|
123
|
+
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
124
|
+
/**
|
|
125
|
+
* The bare schema name a DDL planner should target when emitting
|
|
126
|
+
* statements that need to identify this namespace in the live
|
|
127
|
+
* database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
|
|
128
|
+
* catalog filters, planner conflict lookups). Named schemas resolve
|
|
129
|
+
* to their own id. The `PostgresUnboundSchema` singleton inherits
|
|
130
|
+
* this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
|
|
131
|
+
* through `qualifyTableName` route through the polymorphic
|
|
132
|
+
* `PostgresUnboundSchema` overrides and produce unqualified
|
|
133
|
+
* (search-path-resolved) output automatically.
|
|
134
|
+
*/
|
|
135
|
+
ddlSchemaName(_storage: SqlStorage): string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Singleton subclass for the reserved sentinel namespace id
|
|
139
|
+
* (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding
|
|
140
|
+
* the connection's `search_path` resolves at runtime. Overrides
|
|
141
|
+
* qualifier emission to elide the schema prefix; call sites that consume
|
|
142
|
+
* `qualifier()` / `qualifyTable()` get unqualified output without
|
|
143
|
+
* branching on the namespace id.
|
|
144
|
+
*
|
|
145
|
+
* This is the target-side materialization of "the framework provides
|
|
146
|
+
* affordances; targets implement specifics": the framework names the
|
|
147
|
+
* sentinel; Postgres decides what late-bound means here (the table
|
|
148
|
+
* name, naked — the schema is supplied by the live connection's
|
|
149
|
+
* `search_path`).
|
|
150
|
+
*
|
|
151
|
+
* `ddlSchemaName` is inherited from `PostgresSchema` and returns
|
|
152
|
+
* `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
|
|
153
|
+
* route through the polymorphic factory and produce unqualified output
|
|
154
|
+
* automatically.
|
|
155
|
+
*/
|
|
156
|
+
declare class PostgresUnboundSchema extends PostgresSchema {
|
|
157
|
+
static readonly instance: PostgresUnboundSchema;
|
|
158
|
+
constructor(input?: PostgresSchemaInput);
|
|
159
|
+
qualifier(): string;
|
|
160
|
+
qualifyTable(tableName: string): string;
|
|
161
|
+
schemaSqlExpression(): string;
|
|
162
|
+
schemaFilterExpression(): CfExpr;
|
|
163
|
+
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`
|
|
167
|
+
* so callers can dispatch to the polymorphic emission methods without
|
|
168
|
+
* branching at the call site. Uses the structural `kind` discriminator
|
|
169
|
+
* (`'schema'`) rather than `instanceof` so the check survives realm /
|
|
170
|
+
* bundle / hot-reload boundaries — matching the rest of the IR's
|
|
171
|
+
* narrowing convention. `PostgresUnboundSchema` passes through because
|
|
172
|
+
* it inherits the same `kind: 'schema'` from `PostgresSchema`.
|
|
173
|
+
*/
|
|
174
|
+
declare function isPostgresSchema(ns: unknown): ns is PostgresSchema;
|
|
175
|
+
/**
|
|
176
|
+
* Target-supplied `Namespace` factory the Postgres target plumbs
|
|
177
|
+
* through `defineContract({ createNamespace })` and the SQL PSL
|
|
178
|
+
* interpreter. Returns the unbound singleton for the framework
|
|
179
|
+
* sentinel and a fresh `PostgresSchema` for any other coordinate.
|
|
180
|
+
*
|
|
181
|
+
* The factory has no per-call state — every named id deterministically
|
|
182
|
+
* maps to a distinct schema instance — so callers can pass it through
|
|
183
|
+
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
184
|
+
* be value-stable for a given input set.
|
|
185
|
+
*/
|
|
186
|
+
declare function postgresCreateNamespace(input: SqlNamespaceInput): PostgresSchema;
|
|
187
|
+
//#endregion
|
|
188
|
+
export { postgresCreateNamespace as a, isPostgresSchema as i, PostgresSchema as n, PostgresRole as o, PostgresUnboundSchema as r, PostgresRoleInput as s, PostgresContract as t };
|
|
189
|
+
//# sourceMappingURL=postgres-schema-BywoeKlt.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-BywoeKlt.d.mts","names":[],"sources":["../src/core/postgres-role.ts","../src/core/postgres-schema.ts"],"mappings":";;;;;;;UAGiB,iBAAA;EAAA,SACN,IAAA;;;;;WAKA,WAAW;AAAA;;;AAAA;AAgBtB;;;;;;;;;;cAAa,YAAA,SAAqB,OAAO;EAAA,SACrB,IAAA;EAAA,SACT,IAAA;EAAA,SACA,WAAA;cAEG,KAAA,EAAO,iBAAA;AAAA;;;KCJT,gBAAA,GAAmB,QAAQ,CAAC,UAAA;EAAA,SAAyB,MAAA;AAAA;AAAA,KAErD,wBAAA,GAA2B,mBAAA;EAAA,SAC5B,MAAA,GAAS,QAAA,CAAS,MAAA,SAAe,iBAAA;EAAA,SACjC,IAAA,GAAO,QAAA,CAAS,MAAA,SAAe,YAAA;AAAA;AAAA,UAGzB,mBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;;;;ADLf;;;;ACJtC;;;cA0Ba,cAAA,SAAuB,gBAAA;EA1BL;;;;AAAwC;AAEvE;;EAF+B,OAkCtB,OAAA,EAAS,qBAAA;EAAA,SAEC,IAAA;EAAA,SACR,EAAA;EAAA,SACA,OAAA,EAAS,wBAAA;cAEN,KAAA,EAAO,mBAAA;EAAA,IAgCf,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,IAIjC,QAAA,IAAY,QAAA,CAAS,MAAA,SAAe,eAAA;EAAA,IAIpC,MAAA,IAAU,QAAA,CAAS,MAAA,SAAe,iBAAA;EAAA,IAIlC,IAAA,IAAQ,QAAA,CAAS,MAAA,SAAe,YAAA;EAhFZ;;;;;EAyFxB,SAAA;EAzFS;;;;;AAA2C;EAmGpD,YAAA,CAAa,SAAA;EAhGqB;;;;;;EA0GlC,eAAA,CAAgB,IAAA;EAxGU;;;;;;;;EAoH1B,mBAAA;EAnGW;;;;;;;EA8GX,sBAAA,IAA0B,MAAA;EAhEb;;;;;;;EA2Eb,WAAA,CAAY,SAAA,UAAmB,KAAA,YAAiB,mBAAA;EA/D3B;;;;;;;;;;;EAkFrB,aAAA,CAAc,QAAA,EAAU,UAAA;AAAA;;;;;;;;;;;;;;;;;;;;cAwBb,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;;;;;;;;;;iBAmB3C,gBAAA,CAAiB,EAAA,YAAc,EAAA,IAAM,cAAc;AA1CnE;;;;;;;;;;;AAAA,iBAyDgB,uBAAA,CAAwB,KAAA,EAAO,iBAAA,GAAoB,cAAc"}
|
|
@@ -0,0 +1,248 @@
|
|
|
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/schema-node-kinds.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `nodeKind` discriminant for each Postgres schema-diff node. Each node
|
|
7
|
+
* carries a unique value; the static `is`/`assert` guards compare against these
|
|
8
|
+
* identifiers rather than spelling the string inline or using `instanceof`. The
|
|
9
|
+
* field is an enumerable own property carried on every node instance.
|
|
10
|
+
*/
|
|
11
|
+
const PostgresSchemaNodeKind = {
|
|
12
|
+
database: "postgres-database",
|
|
13
|
+
namespace: "postgres-namespace",
|
|
14
|
+
table: "postgres-table",
|
|
15
|
+
policy: "postgres-policy",
|
|
16
|
+
role: "postgres-role"
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/core/schema-ir/postgres-database-schema-node.ts
|
|
20
|
+
/**
|
|
21
|
+
* The root of the Postgres schema-diff tree: one node per database.
|
|
22
|
+
*
|
|
23
|
+
* `id` is the fixed sentinel `'database'` — the root has no siblings and
|
|
24
|
+
* the value is never emitted into migration paths. `isEqualTo` is identity
|
|
25
|
+
* (roots always share the `'database'` id). `children()` returns namespace
|
|
26
|
+
* nodes only; roles are held on the root but not yielded (role diffing is a
|
|
27
|
+
* later slice).
|
|
28
|
+
*/
|
|
29
|
+
var PostgresDatabaseSchemaNode = class PostgresDatabaseSchemaNode extends SqlSchemaIRNode {
|
|
30
|
+
nodeKind = PostgresSchemaNodeKind.database;
|
|
31
|
+
namespaces;
|
|
32
|
+
roles;
|
|
33
|
+
existingSchemas;
|
|
34
|
+
pgVersion;
|
|
35
|
+
constructor(input) {
|
|
36
|
+
super();
|
|
37
|
+
this.namespaces = Object.freeze({ ...input.namespaces });
|
|
38
|
+
this.roles = Object.freeze([...input.roles]);
|
|
39
|
+
this.existingSchemas = Object.freeze([...input.existingSchemas]);
|
|
40
|
+
this.pgVersion = input.pgVersion;
|
|
41
|
+
freezeNode(this);
|
|
42
|
+
}
|
|
43
|
+
get id() {
|
|
44
|
+
return "database";
|
|
45
|
+
}
|
|
46
|
+
isEqualTo(other) {
|
|
47
|
+
return this.id === other.id;
|
|
48
|
+
}
|
|
49
|
+
children() {
|
|
50
|
+
return Object.values(this.namespaces);
|
|
51
|
+
}
|
|
52
|
+
static is(node) {
|
|
53
|
+
return node.nodeKind === PostgresSchemaNodeKind.database;
|
|
54
|
+
}
|
|
55
|
+
static assert(node) {
|
|
56
|
+
if (!PostgresDatabaseSchemaNode.is(node)) throw new Error(`Expected a PostgresDatabaseSchemaNode but got nodeKind=${node.nodeKind ?? "undefined"}`);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/core/schema-ir/postgres-namespace-schema-node.ts
|
|
61
|
+
/**
|
|
62
|
+
* One-per-Postgres-schema diff-tree node. Groups the tables belonging to a
|
|
63
|
+
* single namespace and satisfies the `SqlSchemaIR` shape so legacy per-schema
|
|
64
|
+
* consumers (verifySqlSchema, the relational planner, toSchemaView) can
|
|
65
|
+
* accept it unchanged in Unit 6.
|
|
66
|
+
*
|
|
67
|
+
* `id` is the schema name. `isEqualTo` is identity — two namespace nodes are
|
|
68
|
+
* equal iff their ids (schema names) match. `children()` returns the table
|
|
69
|
+
* nodes. Per-schema metadata is carried on the typed `nativeEnumTypeNames`
|
|
70
|
+
* field, not an annotations bag.
|
|
71
|
+
*/
|
|
72
|
+
var PostgresNamespaceSchemaNode = class PostgresNamespaceSchemaNode extends SqlSchemaIRNode {
|
|
73
|
+
nodeKind = PostgresSchemaNodeKind.namespace;
|
|
74
|
+
schemaName;
|
|
75
|
+
tables;
|
|
76
|
+
nativeEnumTypeNames;
|
|
77
|
+
constructor(input) {
|
|
78
|
+
super();
|
|
79
|
+
this.schemaName = input.schemaName;
|
|
80
|
+
this.tables = Object.freeze({ ...input.tables });
|
|
81
|
+
this.nativeEnumTypeNames = Object.freeze([...input.nativeEnumTypeNames]);
|
|
82
|
+
freezeNode(this);
|
|
83
|
+
}
|
|
84
|
+
get id() {
|
|
85
|
+
return this.schemaName;
|
|
86
|
+
}
|
|
87
|
+
isEqualTo(other) {
|
|
88
|
+
return this.id === other.id;
|
|
89
|
+
}
|
|
90
|
+
children() {
|
|
91
|
+
return Object.values(this.tables);
|
|
92
|
+
}
|
|
93
|
+
static is(node) {
|
|
94
|
+
return node.nodeKind === PostgresSchemaNodeKind.namespace;
|
|
95
|
+
}
|
|
96
|
+
static assert(node) {
|
|
97
|
+
if (!PostgresNamespaceSchemaNode.is(node)) throw new Error(`Expected a PostgresNamespaceSchemaNode but got nodeKind=${node.nodeKind ?? "undefined"}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/core/schema-ir/postgres-policy-schema-node.ts
|
|
102
|
+
/**
|
|
103
|
+
* Schema-diff leaf node for a Postgres row-level security policy.
|
|
104
|
+
*
|
|
105
|
+
* This is a derived, transient node walked by the differ — it is NEVER serialized.
|
|
106
|
+
* Built by project-from-contract and project-from-database from their respective
|
|
107
|
+
* `PostgresRlsPolicy` contract entities / introspected rows.
|
|
108
|
+
*
|
|
109
|
+
* `id` is the wire name (`<prefix>_<sha256(body)[0..8]>`), so name-equality is
|
|
110
|
+
* body-equality. `isEqualTo` compares names only — never byte-compare predicate
|
|
111
|
+
* bodies, because Postgres reprints them.
|
|
112
|
+
*/
|
|
113
|
+
var PostgresPolicySchemaNode = class PostgresPolicySchemaNode extends SqlSchemaIRNode {
|
|
114
|
+
nodeKind = PostgresSchemaNodeKind.policy;
|
|
115
|
+
name;
|
|
116
|
+
prefix;
|
|
117
|
+
tableName;
|
|
118
|
+
namespaceId;
|
|
119
|
+
operation;
|
|
120
|
+
roles;
|
|
121
|
+
permissive;
|
|
122
|
+
constructor(input) {
|
|
123
|
+
super();
|
|
124
|
+
this.name = input.name;
|
|
125
|
+
this.prefix = input.prefix;
|
|
126
|
+
this.tableName = input.tableName;
|
|
127
|
+
this.namespaceId = input.namespaceId;
|
|
128
|
+
this.operation = input.operation;
|
|
129
|
+
this.roles = Object.freeze([...input.roles]);
|
|
130
|
+
if (input.using !== void 0) this.using = input.using;
|
|
131
|
+
if (input.withCheck !== void 0) this.withCheck = input.withCheck;
|
|
132
|
+
this.permissive = input.permissive;
|
|
133
|
+
freezeNode(this);
|
|
134
|
+
}
|
|
135
|
+
get id() {
|
|
136
|
+
return this.name;
|
|
137
|
+
}
|
|
138
|
+
children() {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
isEqualTo(other) {
|
|
142
|
+
const node = blindCast(other);
|
|
143
|
+
PostgresPolicySchemaNode.assert(node);
|
|
144
|
+
return this.id === node.id;
|
|
145
|
+
}
|
|
146
|
+
static is(node) {
|
|
147
|
+
return node.nodeKind === PostgresSchemaNodeKind.policy;
|
|
148
|
+
}
|
|
149
|
+
static assert(node) {
|
|
150
|
+
if (node === void 0 || !PostgresPolicySchemaNode.is(node)) throw new Error(`Expected a PostgresPolicySchemaNode but got nodeKind=${node?.nodeKind ?? "undefined"}`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/core/schema-ir/postgres-role-schema-node.ts
|
|
155
|
+
/**
|
|
156
|
+
* Schema-diff leaf node for a Postgres database role.
|
|
157
|
+
*
|
|
158
|
+
* This is a derived, transient node walked by the differ — it is NEVER serialized.
|
|
159
|
+
* Built by project-from-contract and project-from-database from their respective
|
|
160
|
+
* `PostgresRole` contract entities / introspected rows.
|
|
161
|
+
*
|
|
162
|
+
* Roles are cluster-scoped, so `id` is the role name alone. `isEqualTo` compares
|
|
163
|
+
* names — name-equality is role-equality for cluster-scoped objects.
|
|
164
|
+
*/
|
|
165
|
+
var PostgresRoleSchemaNode = class PostgresRoleSchemaNode extends SqlSchemaIRNode {
|
|
166
|
+
nodeKind = PostgresSchemaNodeKind.role;
|
|
167
|
+
name;
|
|
168
|
+
namespaceId;
|
|
169
|
+
constructor(input) {
|
|
170
|
+
super();
|
|
171
|
+
this.name = input.name;
|
|
172
|
+
this.namespaceId = input.namespaceId;
|
|
173
|
+
freezeNode(this);
|
|
174
|
+
}
|
|
175
|
+
get id() {
|
|
176
|
+
return this.name;
|
|
177
|
+
}
|
|
178
|
+
children() {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
isEqualTo(other) {
|
|
182
|
+
const node = blindCast(other);
|
|
183
|
+
PostgresRoleSchemaNode.assert(node);
|
|
184
|
+
return this.id === node.id;
|
|
185
|
+
}
|
|
186
|
+
static is(node) {
|
|
187
|
+
return node.nodeKind === PostgresSchemaNodeKind.role;
|
|
188
|
+
}
|
|
189
|
+
static assert(node) {
|
|
190
|
+
if (!PostgresRoleSchemaNode.is(node)) throw new Error(`Expected a PostgresRoleSchemaNode but got nodeKind=${node.nodeKind ?? "undefined"}`);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/core/schema-ir/postgres-table-schema-node.ts
|
|
195
|
+
/**
|
|
196
|
+
* Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields
|
|
197
|
+
* plus `policies`, and implements `DiffableNode` so the table instance is
|
|
198
|
+
* directly the diff-tree node — no separate wrapper needed.
|
|
199
|
+
*
|
|
200
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because
|
|
201
|
+
* `SqlTableIR` calls `freezeNode` in its own constructor, which prevents
|
|
202
|
+
* subclass field initialisation.
|
|
203
|
+
*
|
|
204
|
+
* `id` is the table name. `children()` returns the policy nodes on this table.
|
|
205
|
+
* `isEqualTo` is identity — two table nodes are equal iff their ids (names)
|
|
206
|
+
* match. Columns are not compared here; they become child nodes later.
|
|
207
|
+
*/
|
|
208
|
+
var PostgresTableSchemaNode = class PostgresTableSchemaNode extends SqlSchemaIRNode {
|
|
209
|
+
nodeKind = PostgresSchemaNodeKind.table;
|
|
210
|
+
name;
|
|
211
|
+
columns;
|
|
212
|
+
foreignKeys;
|
|
213
|
+
uniques;
|
|
214
|
+
indexes;
|
|
215
|
+
policies;
|
|
216
|
+
constructor(input) {
|
|
217
|
+
super();
|
|
218
|
+
this.name = input.name;
|
|
219
|
+
this.columns = Object.freeze(Object.fromEntries(Object.entries(input.columns).map(([key, col]) => [key, col instanceof SqlColumnIR ? col : new SqlColumnIR(col)])));
|
|
220
|
+
this.foreignKeys = Object.freeze(input.foreignKeys.map((fk) => fk instanceof SqlForeignKeyIR ? fk : new SqlForeignKeyIR(fk)));
|
|
221
|
+
this.uniques = Object.freeze(input.uniques.map((u) => u instanceof SqlUniqueIR ? u : new SqlUniqueIR(u)));
|
|
222
|
+
this.indexes = Object.freeze(input.indexes.map((i) => i instanceof SqlIndexIR ? i : new SqlIndexIR(i)));
|
|
223
|
+
if (input.primaryKey !== void 0) this.primaryKey = input.primaryKey instanceof PrimaryKey ? input.primaryKey : new PrimaryKey(input.primaryKey);
|
|
224
|
+
if (input.annotations !== void 0) this.annotations = input.annotations;
|
|
225
|
+
if (input.checks !== void 0 && input.checks.length > 0) this.checks = Object.freeze(input.checks.map((c) => c instanceof SqlCheckConstraintIR ? c : new SqlCheckConstraintIR(c)));
|
|
226
|
+
this.policies = Object.freeze([...input.policies ?? []]);
|
|
227
|
+
freezeNode(this);
|
|
228
|
+
}
|
|
229
|
+
get id() {
|
|
230
|
+
return this.name;
|
|
231
|
+
}
|
|
232
|
+
isEqualTo(other) {
|
|
233
|
+
return this.id === other.id;
|
|
234
|
+
}
|
|
235
|
+
children() {
|
|
236
|
+
return this.policies;
|
|
237
|
+
}
|
|
238
|
+
static is(node) {
|
|
239
|
+
return node.nodeKind === PostgresSchemaNodeKind.table;
|
|
240
|
+
}
|
|
241
|
+
static assert(node) {
|
|
242
|
+
if (!PostgresTableSchemaNode.is(node)) throw new Error(`Expected a PostgresTableSchemaNode but got nodeKind=${node.nodeKind ?? "undefined"}`);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
//#endregion
|
|
246
|
+
export { PostgresDatabaseSchemaNode as a, PostgresNamespaceSchemaNode as i, PostgresRoleSchemaNode as n, PostgresPolicySchemaNode as r, PostgresTableSchemaNode as t };
|
|
247
|
+
|
|
248
|
+
//# sourceMappingURL=postgres-table-schema-node-1nNc8XDT.mjs.map
|