@prisma-next/target-postgres 0.14.0-dev.4 → 0.14.0-dev.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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
package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-BegduLr6.mjs}
RENAMED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-
|
|
1
|
+
import { _ as PG_TEXT_CODEC_ID, f as PG_INT_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
|
|
2
|
+
import { a as policyEntityKind, o as roleEntityKind, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-BLIHBEfX.mjs";
|
|
3
|
+
import { t as postgresAuthoringEntityTypes } from "./authoring-BX1WHIdN.mjs";
|
|
3
4
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
|
-
import {
|
|
5
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
6
|
+
import { buildSqlSchemaQualifiedView } from "@prisma-next/sql-contract/contract-view";
|
|
5
7
|
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
6
8
|
import { isAuthoringEntityTypeDescriptor } from "@prisma-next/framework-components/authoring";
|
|
7
9
|
//#region src/core/postgres-contract-serializer.ts
|
|
8
10
|
const POSTGRES_AUTHORING_CTX = {
|
|
9
11
|
family: "sql",
|
|
10
|
-
target: "postgres"
|
|
12
|
+
target: "postgres",
|
|
13
|
+
enumInferenceCodecs: {
|
|
14
|
+
text: PG_TEXT_CODEC_ID,
|
|
15
|
+
int: PG_INT_CODEC_ID
|
|
16
|
+
}
|
|
11
17
|
};
|
|
12
18
|
function isAuthoringEntityTypeFactoryOutput(output) {
|
|
13
|
-
return typeof output === "object" && output !== null && typeof output.factory === "function";
|
|
19
|
+
return typeof output === "object" && output !== null && "factory" in output && typeof output.factory === "function";
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Walks a pack's entity-type namespace tree and emits hydration factories
|
|
@@ -36,20 +42,20 @@ function collectStorageTypesHydrators(namespace) {
|
|
|
36
42
|
return registry;
|
|
37
43
|
}
|
|
38
44
|
var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
39
|
-
constructor() {
|
|
45
|
+
constructor(extraPackEntityKinds = []) {
|
|
40
46
|
const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);
|
|
41
|
-
super(storageTypesHydrators
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
super(storageTypesHydrators, [
|
|
48
|
+
policyEntityKind,
|
|
49
|
+
roleEntityKind,
|
|
50
|
+
...extraPackEntityKinds
|
|
51
|
+
]);
|
|
45
52
|
}
|
|
46
53
|
hydrateSqlNamespaceEntry(nsId, raw) {
|
|
47
|
-
if (raw instanceof NamespaceBase) return raw;
|
|
48
54
|
const { id, entries } = blindCast(super.hydrateSqlNamespaceEntry(nsId, raw));
|
|
55
|
+
const allSlotsEmpty = Object.values(entries).every((slot) => slot === void 0 || Object.keys(slot).length === 0);
|
|
56
|
+
if (id === UNBOUND_NAMESPACE_ID && allSlotsEmpty) return PostgresSchema.unbound;
|
|
49
57
|
const valueSetSlot = entries["valueSet"];
|
|
50
58
|
const hasValueSets = valueSetSlot !== void 0 && Object.keys(valueSetSlot).length > 0;
|
|
51
|
-
const emptyTables = Object.keys(entries["table"] ?? {}).length === 0;
|
|
52
|
-
if (id === UNBOUND_NAMESPACE_ID && emptyTables && !hasValueSets) return PostgresSchema.unbound;
|
|
53
59
|
return new PostgresSchema({
|
|
54
60
|
id,
|
|
55
61
|
entries: {
|
|
@@ -66,7 +72,7 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
66
72
|
else namespacesJson[nsId] = {
|
|
67
73
|
id: nsId,
|
|
68
74
|
kind: nsId === UNBOUND_NAMESPACE_ID ? "postgres-unbound-schema" : "postgres-schema",
|
|
69
|
-
entries: { table: Object.fromEntries(Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [tableName, this.
|
|
75
|
+
entries: { table: Object.fromEntries(Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [tableName, this.serializeJsonObject(table)])) }
|
|
70
76
|
};
|
|
71
77
|
const storageOut = {
|
|
72
78
|
storageHash: String(storage.storageHash),
|
|
@@ -74,34 +80,55 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
74
80
|
};
|
|
75
81
|
if (storage.types !== void 0) {
|
|
76
82
|
const typesOut = {};
|
|
77
|
-
for (const [name, entry] of Object.entries(storage.types)) typesOut[name] = this.
|
|
83
|
+
for (const [name, entry] of Object.entries(storage.types)) typesOut[name] = this.serializeJsonObject(entry);
|
|
78
84
|
storageOut["types"] = typesOut;
|
|
79
85
|
}
|
|
80
|
-
return {
|
|
86
|
+
return blindCast({
|
|
81
87
|
...rest,
|
|
82
88
|
storage: storageOut
|
|
83
|
-
};
|
|
89
|
+
});
|
|
84
90
|
}
|
|
85
91
|
serializePostgresNamespace(ns, isUnboundSlot) {
|
|
86
92
|
const tablesOut = {};
|
|
87
|
-
for (const [tableName, table] of Object.entries(ns.table)) tablesOut[tableName] = this.
|
|
93
|
+
for (const [tableName, table] of Object.entries(ns.table)) tablesOut[tableName] = this.serializeJsonObject(table);
|
|
88
94
|
const valueSetEntries = ns.valueSet;
|
|
89
95
|
const valueSetOut = {};
|
|
90
|
-
if (valueSetEntries !== void 0) for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) valueSetOut[valueSetName] =
|
|
96
|
+
if (valueSetEntries !== void 0) for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) valueSetOut[valueSetName] = this.serializeJsonObject(valueSet);
|
|
97
|
+
const roleOut = {};
|
|
98
|
+
for (const [roleName, role] of Object.entries(ns.role)) roleOut[roleName] = this.serializeJsonObject(role);
|
|
99
|
+
const policyOut = {};
|
|
100
|
+
for (const [policyName, policy] of Object.entries(ns.policy)) policyOut[policyName] = this.serializeJsonObject(policy);
|
|
91
101
|
return {
|
|
92
102
|
id: ns.id,
|
|
93
103
|
kind: isUnboundSlot ? "postgres-unbound-schema" : "postgres-schema",
|
|
94
104
|
entries: {
|
|
95
105
|
table: tablesOut,
|
|
96
|
-
...Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}
|
|
106
|
+
...Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {},
|
|
107
|
+
...Object.keys(roleOut).length > 0 ? { role: roleOut } : {},
|
|
108
|
+
...Object.keys(policyOut).length > 0 ? { policy: policyOut } : {}
|
|
97
109
|
}
|
|
98
110
|
};
|
|
99
111
|
}
|
|
112
|
+
serializeJsonObject(value) {
|
|
113
|
+
return blindCast(this.serializeJsonValue(value));
|
|
114
|
+
}
|
|
100
115
|
serializeJsonValue(value) {
|
|
101
|
-
return JSON.parse(JSON.stringify(value));
|
|
116
|
+
return blindCast(JSON.parse(JSON.stringify(value)));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/core/postgres-contract-view.ts
|
|
121
|
+
const PostgresContractView = {
|
|
122
|
+
/** Wrap an already-deserialized Postgres contract in a schema-qualified view. */
|
|
123
|
+
from(contract) {
|
|
124
|
+
return buildSqlSchemaQualifiedView(contract);
|
|
125
|
+
},
|
|
126
|
+
/** Deserialize a Postgres contract JSON envelope and wrap it in a view. */
|
|
127
|
+
fromJson(json) {
|
|
128
|
+
return buildSqlSchemaQualifiedView(new PostgresContractSerializer().deserializeContract(json));
|
|
102
129
|
}
|
|
103
130
|
};
|
|
104
131
|
//#endregion
|
|
105
|
-
export { PostgresContractSerializer as t };
|
|
132
|
+
export { PostgresContractSerializer as n, PostgresContractView as t };
|
|
106
133
|
|
|
107
|
-
//# sourceMappingURL=postgres-contract-
|
|
134
|
+
//# sourceMappingURL=postgres-contract-view-BegduLr6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-contract-view-BegduLr6.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/core/postgres-contract-view.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type AnyEntityKindDescriptor,\n type Namespace,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject, JsonValue } from '@prisma-next/utils/json';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport { PG_INT_CODEC_ID, PG_TEXT_CODEC_ID } from './codec-ids';\nimport { policyEntityKind, roleEntityKind } from './entity-kinds';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n enumInferenceCodecs: { text: PG_TEXT_CODEC_ID, int: PG_INT_CODEC_ID },\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n 'factory' in output &&\n typeof output.factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits hydration factories\n * keyed by the descriptor's `discriminator`. Used for `storage.types`\n * (codec-triple hydration). Namespace entries hydration dispatches by\n * entries key, not discriminator — handled by `hydrateNamespaceEntities`.\n */\nfunction collectStorageTypesHydrators(\n namespace: AuthoringEntityTypeNamespace,\n): ReadonlyMap<string, SqlEntityHydrationFactory> {\n const registry = new Map<string, SqlEntityHydrationFactory>();\n const walk = (node: AuthoringEntityTypeNamespace): void => {\n for (const value of Object.values(node)) {\n if (isAuthoringEntityTypeDescriptor(value)) {\n if (isAuthoringEntityTypeFactoryOutput(value.output)) {\n const { factory } = value.output;\n registry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return registry;\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor(extraPackEntityKinds: readonly AnyEntityKindDescriptor[] = []) {\n const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n super(storageTypesHydrators, [policyEntityKind, roleEntityKind, ...extraPackEntityKinds]);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Record<string, unknown>,\n ): Namespace | SqlNamespaceInput {\n const hydrated = blindCast<\n SqlNamespaceInput,\n 'raw is always plain JSON, so super.hydrateSqlNamespaceEntry returns SqlNamespaceInput'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n const allSlotsEmpty = Object.values(entries).every(\n (slot) => slot === undefined || Object.keys(slot).length === 0,\n );\n if (id === UNBOUND_NAMESPACE_ID && allSlotsEmpty) {\n return PostgresSchema.unbound;\n }\n const valueSetSlot = entries['valueSet'];\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n return new PostgresSchema({\n id,\n entries: {\n ...entries,\n table: entries['table'] ?? {},\n ...(hasValueSets ? { valueSet: valueSetSlot } : {}),\n },\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: Object.fromEntries(\n Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [\n tableName,\n this.serializeJsonObject(table),\n ]),\n ),\n },\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonObject(entry);\n }\n storageOut['types'] = typesOut;\n }\n return blindCast<\n JsonObject,\n 'contract minus storage plus a JSON-shaped storageOut is a JsonObject'\n >({\n ...rest,\n storage: storageOut,\n });\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.table)) {\n tablesOut[tableName] = this.serializeJsonObject(table);\n }\n const valueSetEntries = ns.valueSet;\n const valueSetOut: Record<string, JsonObject> = {};\n if (valueSetEntries !== undefined) {\n for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) {\n valueSetOut[valueSetName] = this.serializeJsonObject(valueSet);\n }\n }\n const roleOut: Record<string, JsonObject> = {};\n for (const [roleName, role] of Object.entries(ns.role)) {\n roleOut[roleName] = this.serializeJsonObject(role);\n }\n const policyOut: Record<string, JsonObject> = {};\n for (const [policyName, policy] of Object.entries(ns.policy)) {\n policyOut[policyName] = this.serializeJsonObject(policy);\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: tablesOut,\n ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),\n ...(Object.keys(roleOut).length > 0 ? { role: roleOut } : {}),\n ...(Object.keys(policyOut).length > 0 ? { policy: policyOut } : {}),\n },\n };\n }\n\n private serializeJsonObject(value: unknown): JsonObject {\n return blindCast<\n JsonObject,\n 'serializeJsonValue round-trips an IR node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(value));\n }\n\n private serializeJsonValue(value: unknown): JsonValue {\n return blindCast<JsonValue, 'JSON.parse(JSON.stringify(x)) yields a JsonValue'>(\n JSON.parse(JSON.stringify(value)),\n );\n }\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport {\n buildSqlSchemaQualifiedView,\n type SqlSchemaQualifiedView,\n} from '@prisma-next/sql-contract/contract-view';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { PostgresContractSerializer } from './postgres-contract-serializer';\n\n/**\n * A schema-qualified Postgres contract view: the deserialized contract\n * intersected with a single `namespace` member holding every schema by id. It is\n * substitutable for `Contract` (carries `storage`, `domain`, …) and reaches each\n * schema's entities through `view.namespace.<schema>`:\n *\n * ```ts\n * const view = PostgresContractView.fromJson<Contract>(contractJson);\n * view.namespace.public.table.users // typed table leaf in the public schema\n * view.namespace.auth.table.users // the auth schema's own users table\n * view.namespace.public.entries.policy.X // pack-contributed kind (RLS / #771 path)\n * view.namespace.__unbound__.table.X // default schema, keyed by its raw id\n * view.storage // the full contract is still present\n * ```\n *\n * This mirrors the runtime `db.enums.<ns>` keying exactly (the default schema\n * keeps its literal `__unbound__` id). Schema names are NOT promoted to the\n * contract root, so there is no collision with contract envelope fields — a\n * schema named `storage` is `view.namespace.storage`, while `view.storage`\n * stays the contract's `storage`.\n */\nexport type PostgresContractView<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> =\n SqlSchemaQualifiedView<TContract>;\n\nexport const PostgresContractView = {\n /** Wrap an already-deserialized Postgres contract in a schema-qualified view. */\n from<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n ): PostgresContractView<TContract> {\n return buildSqlSchemaQualifiedView(contract);\n },\n\n /** Deserialize a Postgres contract JSON envelope and wrap it in a view. */\n fromJson<TContract extends Contract<SqlStorage> = Contract<SqlStorage>>(\n json: unknown,\n ): PostgresContractView<TContract> {\n const contract = new PostgresContractSerializer().deserializeContract<TContract>(json);\n return buildSqlSchemaQualifiedView(contract);\n },\n};\n"],"mappings":";;;;;;;;;AAwBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;CACR,qBAAqB;EAAE,MAAM;EAAkB,KAAK;CAAgB;AACtE;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,aAAa,UACb,OAAO,OAAO,YAAY;AAE9B;;;;;;;AAQA,SAAS,6BACP,WACgD;CAChD,MAAM,2BAAW,IAAI,IAAuC;CAC5D,MAAM,QAAQ,SAA6C;EACzD,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GAAG;GACvC,IAAI,gCAAgC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I,EAAE,UAAU,YAAY,IAAI,CAAC;IACvE,GAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IAAI,EAAE,MAAM,QAAQ,IAAI,CAAC;IAC3D,GAAI,OAAO,KAAK,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,QAAQ,UAAU,IAAI,CAAC;GACnE;EACF;CACF;CAEA,oBAA4B,OAA4B;EACtD,OAAO,UAGL,KAAK,mBAAmB,KAAK,CAAC;CAClC;CAEA,mBAA2B,OAA2B;EACpD,OAAO,UACL,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,CAClC;CACF;AACF;;;AC7JA,MAAa,uBAAuB;;CAElC,KACE,UACiC;EACjC,OAAO,4BAA4B,QAAQ;CAC7C;;CAGA,SACE,MACiC;EAEjC,OAAO,4BADU,IAAI,2BAA2B,CAAC,CAAC,oBAA+B,IACvC,CAAC;CAC7C;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
2
|
+
import { SqlSchemaQualifiedView } from "@prisma-next/sql-contract/contract-view";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/core/postgres-contract-view.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A schema-qualified Postgres contract view: the deserialized contract
|
|
8
|
+
* intersected with a single `namespace` member holding every schema by id. It is
|
|
9
|
+
* substitutable for `Contract` (carries `storage`, `domain`, …) and reaches each
|
|
10
|
+
* schema's entities through `view.namespace.<schema>`:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const view = PostgresContractView.fromJson<Contract>(contractJson);
|
|
14
|
+
* view.namespace.public.table.users // typed table leaf in the public schema
|
|
15
|
+
* view.namespace.auth.table.users // the auth schema's own users table
|
|
16
|
+
* view.namespace.public.entries.policy.X // pack-contributed kind (RLS / #771 path)
|
|
17
|
+
* view.namespace.__unbound__.table.X // default schema, keyed by its raw id
|
|
18
|
+
* view.storage // the full contract is still present
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* This mirrors the runtime `db.enums.<ns>` keying exactly (the default schema
|
|
22
|
+
* keeps its literal `__unbound__` id). Schema names are NOT promoted to the
|
|
23
|
+
* contract root, so there is no collision with contract envelope fields — a
|
|
24
|
+
* schema named `storage` is `view.namespace.storage`, while `view.storage`
|
|
25
|
+
* stays the contract's `storage`.
|
|
26
|
+
*/
|
|
27
|
+
type PostgresContractView<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> = SqlSchemaQualifiedView<TContract>;
|
|
28
|
+
declare const PostgresContractView: {
|
|
29
|
+
/** Wrap an already-deserialized Postgres contract in a schema-qualified view. */from<TContract extends Contract<SqlStorage>>(contract: TContract): PostgresContractView<TContract>; /** Deserialize a Postgres contract JSON envelope and wrap it in a view. */
|
|
30
|
+
fromJson<TContract extends Contract<SqlStorage> = Contract<SqlStorage<string>>>(json: unknown): PostgresContractView<TContract>;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { PostgresContractView as t };
|
|
34
|
+
//# sourceMappingURL=postgres-contract-view-C9j5cqP0.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-contract-view-C9j5cqP0.d.mts","names":[],"sources":["../src/core/postgres-contract-view.ts"],"mappings":";;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;KAAY,oBAAA,mBAAuC,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,KACjF,sBAAA,CAAuB,SAAA;AAAA,cAEZ,oBAAA;EAeZ,wGAbwB,QAAA,CAAS,UAAA,GAAW,QAAA,EAC/B,SAAA,GACT,oBAAA,CAAqB,SAAA,GAFQ;6BAOL,QAAA,CAAS,UAAA,IAAW,QAAA,CAAA,UAAA,WAAA,IAAA,YAE5C,oBAAA,CAAqB,SAAA;AAAA"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { r as RlsPolicyOperation } from "./postgres-rls-policy--CSddvMR.mjs";
|
|
2
|
+
import { PrimaryKey, SqlAnnotations, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIRNode, SqlTableIRInput, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
3
|
+
import { DiffableNode } from "@prisma-next/framework-components/control";
|
|
4
|
+
|
|
5
|
+
//#region src/core/schema-ir/postgres-policy-schema-node.d.ts
|
|
6
|
+
interface PostgresPolicySchemaNodeInput {
|
|
7
|
+
/** Full wire name: `<prefix>_<8hex>`. */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** User-supplied prefix (the part before the `_<8hex>` suffix). */
|
|
10
|
+
readonly prefix: string;
|
|
11
|
+
/** Name of the table this policy attaches to, by name within the same schema. */
|
|
12
|
+
readonly tableName: string;
|
|
13
|
+
/** Namespace coordinate (schema name). */
|
|
14
|
+
readonly namespaceId: string;
|
|
15
|
+
readonly operation: RlsPolicyOperation;
|
|
16
|
+
/** Sorted role names rendered in `TO <roles>`. */
|
|
17
|
+
readonly roles: readonly string[];
|
|
18
|
+
/** USING predicate SQL string, if present. */
|
|
19
|
+
readonly using?: string;
|
|
20
|
+
/** WITH CHECK predicate SQL string, if present. */
|
|
21
|
+
readonly withCheck?: string;
|
|
22
|
+
/** `true` = `AS PERMISSIVE`, `false` = `AS RESTRICTIVE`. */
|
|
23
|
+
readonly permissive: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Schema-diff leaf node for a Postgres row-level security policy.
|
|
27
|
+
*
|
|
28
|
+
* This is a derived, transient node walked by the differ — it is NEVER serialized.
|
|
29
|
+
* Built by project-from-contract and project-from-database from their respective
|
|
30
|
+
* `PostgresRlsPolicy` contract entities / introspected rows.
|
|
31
|
+
*
|
|
32
|
+
* `id` is the wire name (`<prefix>_<sha256(body)[0..8]>`), so name-equality is
|
|
33
|
+
* body-equality. `isEqualTo` compares names only — never byte-compare predicate
|
|
34
|
+
* bodies, because Postgres reprints them.
|
|
35
|
+
*/
|
|
36
|
+
declare class PostgresPolicySchemaNode extends SqlSchemaIRNode implements DiffableNode {
|
|
37
|
+
readonly nodeKind: "postgres-policy";
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly prefix: string;
|
|
40
|
+
readonly tableName: string;
|
|
41
|
+
readonly namespaceId: string;
|
|
42
|
+
readonly operation: RlsPolicyOperation;
|
|
43
|
+
readonly roles: readonly string[];
|
|
44
|
+
readonly using?: string;
|
|
45
|
+
readonly withCheck?: string;
|
|
46
|
+
readonly permissive: boolean;
|
|
47
|
+
constructor(input: PostgresPolicySchemaNodeInput);
|
|
48
|
+
get id(): string;
|
|
49
|
+
children(): readonly DiffableNode[];
|
|
50
|
+
isEqualTo(other: DiffableNode): boolean;
|
|
51
|
+
static is(node: SqlSchemaIRNode): node is PostgresPolicySchemaNode;
|
|
52
|
+
static assert(node: SqlSchemaIRNode | undefined): asserts node is PostgresPolicySchemaNode;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/core/schema-ir/postgres-table-schema-node.d.ts
|
|
56
|
+
interface PostgresTableSchemaNodeInput extends SqlTableIRInput {
|
|
57
|
+
readonly policies?: readonly PostgresPolicySchemaNode[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Postgres-specific table schema-diff node. Carries all `SqlTableIR` fields
|
|
61
|
+
* plus `policies`, and implements `DiffableNode` so the table instance is
|
|
62
|
+
* directly the diff-tree node — no separate wrapper needed.
|
|
63
|
+
*
|
|
64
|
+
* Extends `SqlSchemaIRNode` directly rather than `SqlTableIR` because
|
|
65
|
+
* `SqlTableIR` calls `freezeNode` in its own constructor, which prevents
|
|
66
|
+
* subclass field initialisation.
|
|
67
|
+
*
|
|
68
|
+
* `id` is the table name. `children()` returns the policy nodes on this table.
|
|
69
|
+
* `isEqualTo` is identity — two table nodes are equal iff their ids (names)
|
|
70
|
+
* match. Columns are not compared here; they become child nodes later.
|
|
71
|
+
*/
|
|
72
|
+
declare class PostgresTableSchemaNode extends SqlSchemaIRNode implements DiffableNode {
|
|
73
|
+
readonly nodeKind: "postgres-table";
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly columns: Readonly<Record<string, SqlColumnIR>>;
|
|
76
|
+
readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>;
|
|
77
|
+
readonly uniques: ReadonlyArray<SqlUniqueIR>;
|
|
78
|
+
readonly indexes: ReadonlyArray<SqlIndexIR>;
|
|
79
|
+
readonly primaryKey?: PrimaryKey;
|
|
80
|
+
readonly annotations?: SqlAnnotations;
|
|
81
|
+
readonly checks?: ReadonlyArray<SqlCheckConstraintIR>;
|
|
82
|
+
readonly policies: readonly PostgresPolicySchemaNode[];
|
|
83
|
+
constructor(input: PostgresTableSchemaNodeInput);
|
|
84
|
+
get id(): string;
|
|
85
|
+
isEqualTo(other: DiffableNode): boolean;
|
|
86
|
+
children(): readonly DiffableNode[];
|
|
87
|
+
static is(node: SqlSchemaIRNode): node is PostgresTableSchemaNode;
|
|
88
|
+
static assert(node: SqlSchemaIRNode): asserts node is PostgresTableSchemaNode;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/core/schema-ir/postgres-namespace-schema-node.d.ts
|
|
92
|
+
interface PostgresNamespaceSchemaNodeInput {
|
|
93
|
+
readonly schemaName: string;
|
|
94
|
+
readonly tables: Readonly<Record<string, PostgresTableSchemaNode>>;
|
|
95
|
+
readonly nativeEnumTypeNames: readonly string[];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* One-per-Postgres-schema diff-tree node. Groups the tables belonging to a
|
|
99
|
+
* single namespace and satisfies the `SqlSchemaIR` shape so legacy per-schema
|
|
100
|
+
* consumers (verifySqlSchema, the relational planner, toSchemaView) can
|
|
101
|
+
* accept it unchanged in Unit 6.
|
|
102
|
+
*
|
|
103
|
+
* `id` is the schema name. `isEqualTo` is identity — two namespace nodes are
|
|
104
|
+
* equal iff their ids (schema names) match. `children()` returns the table
|
|
105
|
+
* nodes. Per-schema metadata is carried on the typed `nativeEnumTypeNames`
|
|
106
|
+
* field, not an annotations bag.
|
|
107
|
+
*/
|
|
108
|
+
declare class PostgresNamespaceSchemaNode extends SqlSchemaIRNode implements DiffableNode {
|
|
109
|
+
readonly nodeKind: "postgres-namespace";
|
|
110
|
+
readonly schemaName: string;
|
|
111
|
+
readonly tables: Readonly<Record<string, PostgresTableSchemaNode>>;
|
|
112
|
+
readonly nativeEnumTypeNames: readonly string[];
|
|
113
|
+
constructor(input: PostgresNamespaceSchemaNodeInput);
|
|
114
|
+
get id(): string;
|
|
115
|
+
isEqualTo(other: DiffableNode): boolean;
|
|
116
|
+
children(): readonly DiffableNode[];
|
|
117
|
+
static is(node: SqlSchemaIRNode): node is PostgresNamespaceSchemaNode;
|
|
118
|
+
static assert(node: SqlSchemaIRNode): asserts node is PostgresNamespaceSchemaNode;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/core/schema-ir/postgres-role-schema-node.d.ts
|
|
122
|
+
interface PostgresRoleSchemaNodeInput {
|
|
123
|
+
readonly name: string;
|
|
124
|
+
/**
|
|
125
|
+
* Namespace coordinate. Roles are cluster-scoped; callers pass
|
|
126
|
+
* `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`.
|
|
127
|
+
*/
|
|
128
|
+
readonly namespaceId: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Schema-diff leaf node for a Postgres database role.
|
|
132
|
+
*
|
|
133
|
+
* This is a derived, transient node walked by the differ — it is NEVER serialized.
|
|
134
|
+
* Built by project-from-contract and project-from-database from their respective
|
|
135
|
+
* `PostgresRole` contract entities / introspected rows.
|
|
136
|
+
*
|
|
137
|
+
* Roles are cluster-scoped, so `id` is the role name alone. `isEqualTo` compares
|
|
138
|
+
* names — name-equality is role-equality for cluster-scoped objects.
|
|
139
|
+
*/
|
|
140
|
+
declare class PostgresRoleSchemaNode extends SqlSchemaIRNode implements DiffableNode {
|
|
141
|
+
readonly nodeKind: "postgres-role";
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly namespaceId: string;
|
|
144
|
+
constructor(input: PostgresRoleSchemaNodeInput);
|
|
145
|
+
get id(): string;
|
|
146
|
+
children(): readonly DiffableNode[];
|
|
147
|
+
isEqualTo(other: DiffableNode): boolean;
|
|
148
|
+
static is(node: SqlSchemaIRNode): node is PostgresRoleSchemaNode;
|
|
149
|
+
static assert(node: SqlSchemaIRNode): asserts node is PostgresRoleSchemaNode;
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/core/schema-ir/postgres-database-schema-node.d.ts
|
|
153
|
+
interface PostgresDatabaseSchemaNodeInput {
|
|
154
|
+
readonly namespaces: Readonly<Record<string, PostgresNamespaceSchemaNode>>;
|
|
155
|
+
readonly roles: readonly PostgresRoleSchemaNode[];
|
|
156
|
+
readonly existingSchemas: readonly string[];
|
|
157
|
+
readonly pgVersion: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The root of the Postgres schema-diff tree: one node per database.
|
|
161
|
+
*
|
|
162
|
+
* `id` is the fixed sentinel `'database'` — the root has no siblings and
|
|
163
|
+
* the value is never emitted into migration paths. `isEqualTo` is identity
|
|
164
|
+
* (roots always share the `'database'` id). `children()` returns namespace
|
|
165
|
+
* nodes only; roles are held on the root but not yielded (role diffing is a
|
|
166
|
+
* later slice).
|
|
167
|
+
*/
|
|
168
|
+
declare class PostgresDatabaseSchemaNode extends SqlSchemaIRNode implements DiffableNode {
|
|
169
|
+
readonly nodeKind: "postgres-database";
|
|
170
|
+
readonly namespaces: Readonly<Record<string, PostgresNamespaceSchemaNode>>;
|
|
171
|
+
readonly roles: readonly PostgresRoleSchemaNode[];
|
|
172
|
+
readonly existingSchemas: readonly string[];
|
|
173
|
+
readonly pgVersion: string;
|
|
174
|
+
constructor(input: PostgresDatabaseSchemaNodeInput);
|
|
175
|
+
get id(): string;
|
|
176
|
+
isEqualTo(other: DiffableNode): boolean;
|
|
177
|
+
children(): readonly DiffableNode[];
|
|
178
|
+
static is(node: SqlSchemaIRNode): node is PostgresDatabaseSchemaNode;
|
|
179
|
+
static assert(node: SqlSchemaIRNode): asserts node is PostgresDatabaseSchemaNode;
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
export { PostgresNamespaceSchemaNode as a, PostgresTableSchemaNodeInput as c, PostgresRoleSchemaNodeInput as i, PostgresPolicySchemaNode as l, PostgresDatabaseSchemaNodeInput as n, PostgresNamespaceSchemaNodeInput as o, PostgresRoleSchemaNode as r, PostgresTableSchemaNode as s, PostgresDatabaseSchemaNode as t, PostgresPolicySchemaNodeInput as u };
|
|
183
|
+
//# sourceMappingURL=postgres-database-schema-node-os8ogEap.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-database-schema-node-os8ogEap.d.mts","names":[],"sources":["../src/core/schema-ir/postgres-policy-schema-node.ts","../src/core/schema-ir/postgres-table-schema-node.ts","../src/core/schema-ir/postgres-namespace-schema-node.ts","../src/core/schema-ir/postgres-role-schema-node.ts","../src/core/schema-ir/postgres-database-schema-node.ts"],"mappings":";;;;;UAOiB,6BAAA;;WAEN,IAAA;EAFmC;EAAA,SAInC,MAAA;EAK6B;EAAA,SAH7B,SAAA;EAFA;EAAA,SAIA,WAAA;EAAA,SACA,SAAA,EAAW,kBAAkB;EAA7B;EAAA,SAEA,KAAA;EAAA;EAAA,SAEA,KAAA;EAEA;EAAA,SAAA,SAAA;EAEU;EAAA,SAAV,UAAA;AAAA;;;;;;;;;;;;cAcE,wBAAA,SAAiC,eAAA,YAA2B,YAAA;EAAA,SACrD,QAAA;EAAA,SACT,IAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA,EAAW,kBAAA;EAAA,SACX,KAAA;EAAA,SACQ,KAAA;EAAA,SACA,SAAA;EAAA,SACR,UAAA;cAE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AA,EAAM,eAAA,WAA0B,IAAA,IAAQ,0BAAA;AAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as installExtension, E as SetNotNullCall, S as DropTableCall, T as SetDefaultCall, _ as DropConstraintCall, b as DropNotNullCall, c as AlterColumnTypeCall, f as CreateSchemaCall, g as DropColumnCall, h as DropCheckConstraintCall, n as AddColumnCall, o as AddPrimaryKeyCall, p as CreateTableCall, r as AddForeignKeyCall, s as AddUniqueCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropDefaultCall, y as DropIndexCall } from "./op-factory-call-t65c4jyY.mjs";
|
|
2
2
|
import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
|
|
3
|
+
import { t as PostgresContractView } from "./postgres-contract-view-BegduLr6.mjs";
|
|
3
4
|
import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
|
|
4
5
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
6
|
+
import { MigrationContractViews } from "@prisma-next/migration-tools/migration";
|
|
5
7
|
//#region src/core/migrations/postgres-migration.ts
|
|
6
8
|
/**
|
|
7
9
|
* Target-owned base class for Postgres migrations.
|
|
@@ -39,11 +41,28 @@ var PostgresMigration = class extends Migration {
|
|
|
39
41
|
* throws in that case to surface the misuse.
|
|
40
42
|
*/
|
|
41
43
|
controlAdapter;
|
|
44
|
+
#endView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
|
|
45
|
+
#startView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
|
|
42
46
|
constructor(stack) {
|
|
43
47
|
super(stack);
|
|
44
48
|
this.controlAdapter = stack?.adapter ? stack.adapter.create(stack) : void 0;
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
51
|
+
* The typed, schema-qualified Postgres view over this migration's end-state
|
|
52
|
+
* contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
|
|
53
|
+
* if no `endContractJson` was provided.
|
|
54
|
+
*/
|
|
55
|
+
get endContract() {
|
|
56
|
+
return this.#endView.endContract;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The typed Postgres view over this migration's start-state contract, or
|
|
60
|
+
* `null` for a baseline migration (no `startContractJson`).
|
|
61
|
+
*/
|
|
62
|
+
get startContract() {
|
|
63
|
+
return this.#startView.startContract;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
47
66
|
* Instance-method wrapper around the free `dataTransform` factory that
|
|
48
67
|
* supplies the stored control adapter. Authors call this from inside
|
|
49
68
|
* `get operations()`; the adapter argument is hidden from the call site.
|
|
@@ -142,4 +161,4 @@ var PostgresMigration = class extends Migration {
|
|
|
142
161
|
//#endregion
|
|
143
162
|
export { PostgresMigration as t };
|
|
144
163
|
|
|
145
|
-
//# sourceMappingURL=postgres-migration-
|
|
164
|
+
//# sourceMappingURL=postgres-migration-BfMmK6tv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-BfMmK6tv.mjs","names":["SqlMigration","#endView","#startView"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport { MigrationContractViews } from '@prisma-next/migration-tools/migration';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { PostgresContractView } from '../postgres-contract-view';\nimport {\n AddCheckConstraintCall,\n AddColumnCall,\n AddForeignKeyCall,\n AddPrimaryKeyCall,\n AddUniqueCall,\n AlterColumnTypeCall,\n type AlterColumnTypeOptions,\n CreateIndexCall,\n CreateSchemaCall,\n CreateTableCall,\n DropCheckConstraintCall,\n DropColumnCall,\n DropConstraintCall,\n DropDefaultCall,\n DropIndexCall,\n DropNotNullCall,\n DropTableCall,\n SetDefaultCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport { installExtension } from './operations/dependencies';\nimport type { CreateIndexExtras } from './operations/indexes';\nimport type { ForeignKeySpec } from './operations/shared';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n *\n * Every method requires an explicit `schema`. Postgres migrations name their\n * schema deliberately — there is no default and no `search_path`-relative\n * option. A migration that left the schema unspecified would resolve against\n * whatever `search_path` the connection happened to carry, and that ambiguity\n * is an antipattern in a migration. (The unbound/unspecified namespace concept\n * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)\n */\nexport abstract class PostgresMigration<\n Start extends Contract<SqlStorage> = Contract<SqlStorage>,\n End extends Contract<SqlStorage> = Contract<SqlStorage>,\n> extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n #endView = new MigrationContractViews<PostgresContractView<End>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<End>(json),\n );\n #startView = new MigrationContractViews<PostgresContractView<Start>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<Start>(json),\n );\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * The typed, schema-qualified Postgres view over this migration's end-state\n * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws\n * if no `endContractJson` was provided.\n */\n get endContract(): PostgresContractView<End> {\n return this.#endView.endContract;\n }\n\n /**\n * The typed Postgres view over this migration's start-state contract, or\n * `null` for a baseline migration (no `startContractJson`).\n */\n get startContract(): PostgresContractView<Start> | null {\n return this.#startView.startContract;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createTable(options: {\n readonly schema: string;\n readonly table: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateTableCall(\n options.schema,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);\n }\n\n protected addColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: DdlColumn;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected addPrimaryKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddPrimaryKeyCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addUnique(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddUniqueCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addForeignKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly foreignKey: ForeignKeySpec;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(\n this.controlAdapter,\n );\n }\n\n protected addCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly column: string;\n readonly values: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddCheckConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.column,\n options.values,\n ).toOp(this.controlAdapter);\n }\n\n protected dropCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.kind ?? 'unique',\n ).toOp(this.controlAdapter);\n }\n\n protected dropTable(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);\n }\n\n protected dropColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected alterColumnType(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly options: AlterColumnTypeOptions;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AlterColumnTypeCall(\n options.schema,\n options.table,\n options.column,\n options.options,\n ).toOp(this.controlAdapter);\n }\n\n protected setNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected setDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly defaultSql: string;\n readonly operationClass?: 'additive' | 'widening';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetDefaultCall(\n options.schema,\n options.table,\n options.column,\n options.defaultSql,\n options.operationClass,\n ).toOp(this.controlAdapter);\n }\n\n protected dropDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropDefaultCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected createIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n readonly columns: readonly string[];\n readonly extras?: CreateIndexExtras;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateIndexCall(\n options.schema,\n options.table,\n options.index,\n options.columns,\n options.extras,\n ).toOp(this.controlAdapter);\n }\n\n protected dropIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropIndexCall(options.schema, options.table, options.index).toOp(\n this.controlAdapter,\n );\n }\n\n protected installExtension(options: {\n readonly extensionName: string;\n readonly invariantId: string;\n readonly id: string;\n readonly label?: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return installExtension(options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAsB,oBAAtB,cAGUA,UAAgE;CACxE,WAAoB;;;;;;;CAQpB;CAEA,WAAW,IAAI,uBACb,MACA,sBACC,SAAS,qBAAqB,SAAc,IAAI,CACnD;CACA,aAAa,IAAI,uBACf,MACA,sBACC,SAAS,qBAAqB,SAAgB,IAAI,CACrD;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,IAAI,cAAyC;EAC3C,OAAO,KAAKC,SAAS;CACvB;;;;;CAMA,IAAI,gBAAoD;EACtD,OAAO,KAAKC,WAAW;CACzB;;;;;;CAOA,cACE,UACA,MACA,SAC+D;EAC/D,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;;;;;;CAOA,YAAsB,SAM4C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;E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,CAAC,KAAK,KAAK,cAAc;CAC5B;CAEA,YAAsB,SAI4C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,gBAAgB,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC,KACxE,KAAK,cACP;CACF;CAEA,YAAsB,SAM4C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,gBACT,QAAQ,QACR,QAAQ,OACR,QAAQ,OACR,QAAQ,SACR,QAAQ,MACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;CAEA,UAAoB,SAI8C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,cAAc,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,KACrE,KAAK,cACP;CACF;CAEA,iBAA2B,SAKuC;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,iBAAiB,SAAS,KAAK,cAAc;CACtD;AACF"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { t as PostgresPlanTargetDetails } from "./planner-target-details-
|
|
2
|
-
import { n as DataTransformOptions } from "./data-transform-
|
|
3
|
-
import { s as AlterColumnTypeOptions, w as ForeignKeySpec } from "./op-factory-call-
|
|
1
|
+
import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
|
|
2
|
+
import { n as DataTransformOptions } from "./data-transform-qKy1U5V9.mjs";
|
|
3
|
+
import { s as AlterColumnTypeOptions, w as ForeignKeySpec } from "./op-factory-call-CJWUxyUW.mjs";
|
|
4
|
+
import { t as PostgresContractView } from "./postgres-contract-view-C9j5cqP0.mjs";
|
|
4
5
|
import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
|
|
5
6
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
6
7
|
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
7
|
-
import { Migration } from "@prisma-next/family-sql/migration";
|
|
8
8
|
import { ControlStack } from "@prisma-next/framework-components/control";
|
|
9
|
+
import { Migration } from "@prisma-next/family-sql/migration";
|
|
9
10
|
import { Contract } from "@prisma-next/contract/types";
|
|
10
11
|
import { ExecuteRequestLowerer, SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
|
|
11
12
|
|
|
@@ -43,7 +44,8 @@ interface CreateIndexExtras {
|
|
|
43
44
|
* is an antipattern in a migration. (The unbound/unspecified namespace concept
|
|
44
45
|
* remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
|
|
45
46
|
*/
|
|
46
|
-
declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDetails, 'postgres'> {
|
|
47
|
+
declare abstract class PostgresMigration<Start extends Contract<SqlStorage> = Contract<SqlStorage>, End extends Contract<SqlStorage> = Contract<SqlStorage>> extends Migration<PostgresPlanTargetDetails, 'postgres', Start, End> {
|
|
48
|
+
#private;
|
|
47
49
|
readonly targetId: "postgres";
|
|
48
50
|
/**
|
|
49
51
|
* Materialized Postgres control adapter, created once per migration
|
|
@@ -53,6 +55,17 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
53
55
|
*/
|
|
54
56
|
protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
|
|
55
57
|
constructor(stack?: ControlStack<'sql', 'postgres'>);
|
|
58
|
+
/**
|
|
59
|
+
* The typed, schema-qualified Postgres view over this migration's end-state
|
|
60
|
+
* contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
|
|
61
|
+
* if no `endContractJson` was provided.
|
|
62
|
+
*/
|
|
63
|
+
get endContract(): PostgresContractView<End>;
|
|
64
|
+
/**
|
|
65
|
+
* The typed Postgres view over this migration's start-state contract, or
|
|
66
|
+
* `null` for a baseline migration (no `startContractJson`).
|
|
67
|
+
*/
|
|
68
|
+
get startContract(): PostgresContractView<Start> | null;
|
|
56
69
|
/**
|
|
57
70
|
* Instance-method wrapper around the free `dataTransform` factory that
|
|
58
71
|
* supplies the stored control adapter. Authors call this from inside
|
|
@@ -178,4 +191,4 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
178
191
|
}
|
|
179
192
|
//#endregion
|
|
180
193
|
export { PostgresMigration as t };
|
|
181
|
-
//# sourceMappingURL=postgres-migration-
|
|
194
|
+
//# sourceMappingURL=postgres-migration-D7kNVWVG.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-D7kNVWVG.d.mts","names":[],"sources":["../src/core/migrations/operations/indexes.ts","../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;UAmBiB,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;AAF3B;;;;;;;;AAE2B;;;;AC2C3B;;;;;;;;;;;;;;;AD7CA,uBC6CsB,iBAAA,eACN,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,eAClC,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,WACpC,SAAA,CAAa,yBAAA,cAAuC,KAAA,EAAO,GAAA;EAAA;WAC1D,QAAA;EA4CiC;;;;;;EAAA,mBApCvB,cAAA,EAAgB,iBAAA;cAavB,KAAA,GAAQ,YAAA;EAoCjB;;;;;EAAA,IArBC,WAAA,IAAe,oBAAA,CAAqB,GAAA;EA2DF;;;;EAAA,IAnDlC,aAAA,IAAiB,oBAAA,CAAqB,KAAA;EA8D9B;;;;;EAAA,UArDF,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAgFzB;;;;;EAAA,UApEF,WAAA,CAAY,OAAA;IAAA,SACX,MAAA;IAAA,SACA,KAAA;IAAA,SACA,WAAA;IAAA,SACA,OAAA,WAAkB,SAAA;IA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,UAS5B,gBAAA,CAAiB,OAAA;IAAA,SAChB,aAAA;IAAA,SACA,WAAA;IAAA,SACA,EAAA;IAAA,SACA,KAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { SqlNode } from "@prisma-next/sql-contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/core/postgres-rls-policy.d.ts
|
|
4
|
+
type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';
|
|
5
|
+
interface PostgresRlsPolicyInput {
|
|
6
|
+
/** Full wire name: `<prefix>_<8hex>`. Stored as-is; hashing is not this class's job. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** User-supplied prefix (the part before the `_<8hex>` suffix). */
|
|
9
|
+
readonly prefix: string;
|
|
10
|
+
/** Name of the table this policy attaches to, by name within the same schema. */
|
|
11
|
+
readonly tableName: string;
|
|
12
|
+
/** Namespace coordinate (schema name). Policies are schema-scoped. */
|
|
13
|
+
readonly namespaceId: string;
|
|
14
|
+
readonly operation: RlsPolicyOperation;
|
|
15
|
+
/** Sorted role names rendered in `TO <roles>`. Plain strings in this slice. */
|
|
16
|
+
readonly roles: readonly string[];
|
|
17
|
+
/** USING predicate SQL string, if present. */
|
|
18
|
+
readonly using?: string;
|
|
19
|
+
/** WITH CHECK predicate SQL string, if present. */
|
|
20
|
+
readonly withCheck?: string;
|
|
21
|
+
/** `true` = `AS PERMISSIVE`, `false` = `AS RESTRICTIVE`. */
|
|
22
|
+
readonly permissive: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Postgres contract-IR class for a row-level security policy (`CREATE POLICY … ON …`).
|
|
26
|
+
*
|
|
27
|
+
* This is an authored, serialized Contract-IR entity — it is registered as an entity
|
|
28
|
+
* kind, extends `SqlNode`, and is stored in `contract.json`. It is NOT a DiffableNode;
|
|
29
|
+
* the schema-diff tree uses `PostgresPolicySchemaNode` for that role.
|
|
30
|
+
*
|
|
31
|
+
* Target-only concept — no SQL-family abstract. Extends `SqlNode` directly.
|
|
32
|
+
* Frozen at construction via `freezeNode(this)`. The `kind: 'policy'`
|
|
33
|
+
* discriminant is enumerable (overrides SqlNode's non-enumerable `'sql'`) so it
|
|
34
|
+
* survives JSON serialization and enables dispatch. The literal matches the
|
|
35
|
+
* entries key (one-string rule: node.kind === entries key === entity kind).
|
|
36
|
+
*/
|
|
37
|
+
declare class PostgresRlsPolicy extends SqlNode {
|
|
38
|
+
readonly kind: "policy";
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly prefix: string;
|
|
41
|
+
readonly tableName: string;
|
|
42
|
+
readonly namespaceId: string;
|
|
43
|
+
readonly operation: RlsPolicyOperation;
|
|
44
|
+
readonly roles: readonly string[];
|
|
45
|
+
readonly using?: string;
|
|
46
|
+
readonly withCheck?: string;
|
|
47
|
+
readonly permissive: boolean;
|
|
48
|
+
constructor(input: PostgresRlsPolicyInput);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { PostgresRlsPolicyInput as n, RlsPolicyOperation as r, PostgresRlsPolicy as t };
|
|
52
|
+
//# sourceMappingURL=postgres-rls-policy--CSddvMR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-rls-policy--CSddvMR.d.mts","names":[],"sources":["../src/core/postgres-rls-policy.ts"],"mappings":";;;KAGY,kBAAA;AAAA,UAEK,sBAAA;EAFL;EAAA,SAID,IAAA;;WAEA,MAAA;EANmB;EAAA,SAQnB,SAAA;EAN4B;EAAA,SAQ5B,WAAA;EAAA,SACA,SAAA,EAAW,kBAAkB;EAP7B;EAAA,SASA,KAAA;EALA;EAAA,SAOA,KAAA;EAJA;EAAA,SAMA,SAAA;EAJA;EAAA,SAMA,UAAA;AAAA;;;AAAU;AAgBrB;;;;;;;;;;cAAa,iBAAA,SAA0B,OAAA;EAAA,SACnB,IAAA;EAAA,SACT,IAAA;EAAA,SACA,MAAA;EAAA,SACA,SAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA,EAAW,kBAAA;EAAA,SACX,KAAA;EAAA,SACQ,KAAA;EAAA,SACA,SAAA;EAAA,SACR,UAAA;cAEG,KAAA,EAAO,sBAAA;AAAA"}
|