@prisma-next/target-postgres 0.14.0-dev.5 → 0.14.0-dev.51
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-DzHOdWTl.mjs +364 -0
- package/dist/authoring-DzHOdWTl.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-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
- package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-BDVmvKAW.d.mts} +3 -2
- package/dist/codec-types-BDVmvKAW.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Dk2sxGLv.d.mts} +77 -4
- package/dist/codecs-Dk2sxGLv.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +117 -2
- 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 +4 -4
- package/dist/control-policy-DUFgy9jO.mjs +1103 -0
- package/dist/control-policy-DUFgy9jO.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +757 -35
- 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-DPzwBMhW.d.mts} +3 -3
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-ujxH2A7r.mjs} +63 -6
- package/dist/ddl-ujxH2A7r.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/descriptor-meta-CuGDsrG4.mjs +19 -0
- package/dist/descriptor-meta-CuGDsrG4.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs +313 -0
- package/dist/diff-database-schema-BmSmWcaY.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/issue-planner.d.mts +35 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +5 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- package/dist/nodes-CSkPX3rI.d.mts +120 -0
- package/dist/nodes-CSkPX3rI.d.mts.map +1 -0
- package/dist/{nodes-Bbhs2rwj.mjs → nodes-Dh__NS58.mjs} +56 -2
- package/dist/nodes-Dh__NS58.mjs.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-BKRnMgrB.mjs} +205 -31
- package/dist/op-factory-call-BKRnMgrB.mjs.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Dt-Jx5JS.d.mts} +46 -15
- package/dist/op-factory-call-Dt-Jx5JS.d.mts.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +115 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-BMBRPzsv.mjs +367 -0
- package/dist/planner-BMBRPzsv.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 +4 -6
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +8 -2
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-C0a7I1-e.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-C0a7I1-e.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-Dp6IO_gj.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-Dp6IO_gj.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-Cze3vMfe.mjs} +2 -2
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-Cze3vMfe.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.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 +55 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-3xfUgjnC.mjs} +44 -41
- package/dist/postgres-contract-view-3xfUgjnC.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-C9bTuMrd.d.mts +190 -0
- package/dist/postgres-database-schema-node-C9bTuMrd.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-D0jwzYDT.mjs} +21 -2
- package/dist/postgres-migration-D0jwzYDT.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DFaxuRyI.d.mts} +20 -7
- package/dist/postgres-migration-DFaxuRyI.d.mts.map +1 -0
- package/dist/postgres-native-enum-xdiqmBf_.mjs +41 -0
- package/dist/postgres-native-enum-xdiqmBf_.mjs.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-CajYAwny.mjs} +135 -7
- package/dist/postgres-schema-CajYAwny.mjs.map +1 -0
- package/dist/postgres-schema-DqnhQRvR.d.mts +226 -0
- package/dist/postgres-schema-DqnhQRvR.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-BgaSrxYN.mjs +249 -0
- package/dist/postgres-table-schema-node-BgaSrxYN.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-Bv1ZvjX8.mjs +22 -0
- package/dist/resolve-ddl-schema-Bv1ZvjX8.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +2 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +6 -8
- 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 +15 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/schema-node-kinds-ClScchhi.mjs +76 -0
- package/dist/schema-node-kinds-ClScchhi.mjs.map +1 -0
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +3 -2
- package/package.json +23 -17
- package/src/contract-free/checks.ts +73 -0
- package/src/contract-free/ddl.ts +45 -1
- package/src/core/authoring.ts +287 -2
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +141 -1
- package/src/core/ddl/nodes.ts +94 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +6 -1
- package/src/core/entity-kinds.ts +30 -0
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +149 -0
- package/src/core/migrations/control-policy.ts +70 -47
- package/src/core/migrations/diff-database-schema.ts +280 -0
- package/src/core/migrations/issue-planner.ts +647 -652
- package/src/core/migrations/op-factory-call.ts +109 -21
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/dependencies.ts +2 -1
- 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 +20 -58
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -216
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +297 -59
- 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 +26 -0
- package/src/core/migrations/runner.ts +10 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +47 -30
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +41 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +51 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +37 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +62 -14
- package/src/core/postgres-validators.ts +27 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1068 -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 +60 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +60 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +63 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +118 -0
- package/src/core/schema-ir/schema-node-kinds.ts +106 -0
- package/src/exports/contract-free.ts +7 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +4 -0
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/migration.ts +1 -0
- package/src/exports/op-factory-call.ts +1 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +1 -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/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
- 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 +0 -824
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.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/src/core/postgres-enum-type-schema.ts +0 -17
|
@@ -27,14 +27,18 @@ const BASE_IMPORTS = [{
|
|
|
27
27
|
symbol: "MigrationCLI"
|
|
28
28
|
}];
|
|
29
29
|
function renderCallsToTypeScript(calls, meta) {
|
|
30
|
-
const imports = buildImports(calls);
|
|
30
|
+
const imports = buildImports(calls, meta);
|
|
31
31
|
const operationsBody = calls.map((c) => renderCall(c)).join(",\n");
|
|
32
|
+
const hasStart = meta.from !== null;
|
|
33
|
+
const startField = hasStart ? [" override readonly startContractJson = startContract;"] : [];
|
|
32
34
|
return [
|
|
33
35
|
shebangLineFor(detectScaffoldRuntime()),
|
|
34
36
|
imports,
|
|
35
37
|
"",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
`export default class M extends Migration<${hasStart ? "Start" : "never"}, End> {`,
|
|
39
|
+
...startField,
|
|
40
|
+
" override readonly endContractJson = endContract;",
|
|
41
|
+
"",
|
|
38
42
|
" override get operations() {",
|
|
39
43
|
" return [",
|
|
40
44
|
indent(operationsBody, 6),
|
|
@@ -49,21 +53,46 @@ function renderCallsToTypeScript(calls, meta) {
|
|
|
49
53
|
function renderCall(call) {
|
|
50
54
|
return call.renderTypeScript();
|
|
51
55
|
}
|
|
52
|
-
function buildImports(calls) {
|
|
53
|
-
const requirements = [...BASE_IMPORTS];
|
|
56
|
+
function buildImports(calls, meta) {
|
|
57
|
+
const requirements = [...BASE_IMPORTS, ...contractImports(meta)];
|
|
54
58
|
for (const call of calls) for (const req of call.importRequirements()) requirements.push(req);
|
|
55
59
|
return renderImports(requirements);
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The committed contract-JSON imports the scaffold reads its from/to identity
|
|
63
|
+
* from. `end-contract.json` is always present; `start-contract.json` is added
|
|
64
|
+
* only for a non-baseline migration (`meta.from !== null`). The matching
|
|
65
|
+
* `Contract` type imports (aliased `Start`/`End`) feed the
|
|
66
|
+
* `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
|
|
67
|
+
* no start imports — `never` is the honest "no prior contract" Start.
|
|
68
|
+
*/
|
|
69
|
+
function contractImports(meta) {
|
|
70
|
+
const reqs = [{
|
|
71
|
+
moduleSpecifier: "./end-contract.json",
|
|
72
|
+
symbol: "endContract",
|
|
73
|
+
kind: "default",
|
|
74
|
+
attributes: { type: "json" }
|
|
75
|
+
}, {
|
|
76
|
+
moduleSpecifier: "./end-contract",
|
|
77
|
+
symbol: "Contract",
|
|
78
|
+
alias: "End",
|
|
79
|
+
typeOnly: true
|
|
80
|
+
}];
|
|
81
|
+
if (meta.from !== null) {
|
|
82
|
+
reqs.push({
|
|
83
|
+
moduleSpecifier: "./start-contract.json",
|
|
84
|
+
symbol: "startContract",
|
|
85
|
+
kind: "default",
|
|
86
|
+
attributes: { type: "json" }
|
|
87
|
+
});
|
|
88
|
+
reqs.push({
|
|
89
|
+
moduleSpecifier: "./start-contract",
|
|
90
|
+
symbol: "Contract",
|
|
91
|
+
alias: "Start",
|
|
92
|
+
typeOnly: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return reqs;
|
|
67
96
|
}
|
|
68
97
|
function indent(text, spaces) {
|
|
69
98
|
const pad = " ".repeat(spaces);
|
|
@@ -72,4 +101,4 @@ function indent(text, spaces) {
|
|
|
72
101
|
//#endregion
|
|
73
102
|
export { renderCallsToTypeScript as t };
|
|
74
103
|
|
|
75
|
-
//# sourceMappingURL=render-typescript-
|
|
104
|
+
//# sourceMappingURL=render-typescript-7yqILcwr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-typescript-7yqILcwr.mjs","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `OpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the facade re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls, meta);\n const operationsBody = calls.map((c) => renderCall(c)).join(',\\n');\n const hasStart = meta.from !== null;\n const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n `export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,\n ...startField,\n ' override readonly endContractJson = endContract;',\n '',\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction renderCall(call: OpFactoryCall): string {\n return call.renderTypeScript();\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\n/**\n * The committed contract-JSON imports the scaffold reads its from/to identity\n * from. `end-contract.json` is always present; `start-contract.json` is added\n * only for a non-baseline migration (`meta.from !== null`). The matching\n * `Contract` type imports (aliased `Start`/`End`) feed the\n * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with\n * no start imports — `never` is the honest \"no prior contract\" Start.\n */\nfunction contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {\n const reqs: ImportRequirement[] = [\n {\n moduleSpecifier: './end-contract.json',\n symbol: 'endContract',\n kind: 'default',\n attributes: { type: 'json' },\n },\n { moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },\n ];\n if (meta.from !== null) {\n reqs.push({\n moduleSpecifier: './start-contract.json',\n symbol: 'startContract',\n kind: 'default',\n attributes: { type: 'json' },\n });\n reqs.push({\n moduleSpecifier: './start-contract',\n symbol: 'Contract',\n alias: 'Start',\n typeOnly: true,\n });\n }\n return reqs;\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAAmC,QAAQ;AAAY,GAC1E;CAAE,iBAAiB;CAAmC,QAAQ;AAAe,CAC/E;AAEA,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,OAAO,IAAI;CACxC,MAAM,iBAAiB,MAAM,KAAK,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK;CACjE,MAAM,WAAW,KAAK,SAAS;CAC/B,MAAM,aAAa,WAAW,CAAC,wDAAwD,IAAI,CAAC;CAE5F,OAAO;EACL,eAAe,sBAAsB,CAAC;EACtC;EACA;EACA,4CAA4C,WAAW,UAAU,QAAQ;EACzE,GAAG;EACH;EACA;EACA;EACA;EACA,OAAO,gBAAgB,CAAC;EACxB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAS,WAAW,MAA6B;CAC/C,OAAO,KAAK,iBAAiB;AAC/B;AAEA,SAAS,aAAa,OAAqC,MAAmC;CAC5F,MAAM,eAAoC,CAAC,GAAG,cAAc,GAAG,gBAAgB,IAAI,CAAC;CACpF,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,KAAK,mBAAmB,GACxC,aAAa,KAAK,GAAG;CAGzB,OAAO,cAAc,YAAY;AACnC;;;;;;;;;AAUA,SAAS,gBAAgB,MAAyD;CAChF,MAAM,OAA4B,CAChC;EACE,iBAAiB;EACjB,QAAQ;EACR,MAAM;EACN,YAAY,EAAE,MAAM,OAAO;CAC7B,GACA;EAAE,iBAAiB;EAAkB,QAAQ;EAAY,OAAO;EAAO,UAAU;CAAK,CACxF;CACA,IAAI,KAAK,SAAS,MAAM;EACtB,KAAK,KAAK;GACR,iBAAiB;GACjB,QAAQ;GACR,MAAM;GACN,YAAY,EAAE,MAAM,OAAO;EAC7B,CAAC;EACD,KAAK,KAAK;GACR,iBAAiB;GACjB,QAAQ;GACR,OAAO;GACP,UAAU;EACZ,CAAC;CACH;CACA,OAAO;AACT;AAEA,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,MAAM;CAC7B,OAAO,KACJ,MAAM,IAAI,CAAC,CACX,KAAK,SAAU,KAAK,KAAK,IAAI,GAAG,MAAM,SAAS,IAAK,CAAC,CACrD,KAAK,IAAI;AACd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderCallsToTypeScript } from "./render-typescript-
|
|
1
|
+
import { t as renderCallsToTypeScript } from "./render-typescript-7yqILcwr.mjs";
|
|
2
2
|
export { renderCallsToTypeScript };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as DEFAULT_NAMESPACE_ID } from "./namespace-ids-xtp_ZY86.mjs";
|
|
2
|
+
import { r as isPostgresSchema } from "./postgres-schema-CajYAwny.mjs";
|
|
3
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
|
+
//#region src/core/migrations/resolve-ddl-schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Given the contract's storage and a namespace id, returns the live Postgres
|
|
7
|
+
* DDL schema name that namespace maps to. A named Postgres namespace dispatches
|
|
8
|
+
* to its `ddlSchemaName(storage)`; the unbound sentinel resolves to
|
|
9
|
+
* `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a
|
|
10
|
+
* bare object payload (used by some tests) falls back to the namespace id
|
|
11
|
+
* itself.
|
|
12
|
+
*/
|
|
13
|
+
function resolveDdlSchemaForNamespaceStorage(storage, namespaceId) {
|
|
14
|
+
if (namespaceId === UNBOUND_NAMESPACE_ID) return DEFAULT_NAMESPACE_ID;
|
|
15
|
+
const namespace = storage.namespaces[namespaceId];
|
|
16
|
+
if (namespace && isPostgresSchema(namespace)) return namespace.ddlSchemaName(storage);
|
|
17
|
+
return namespaceId;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { resolveDdlSchemaForNamespaceStorage as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=resolve-ddl-schema-Bv1ZvjX8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-ddl-schema-Bv1ZvjX8.mjs","names":[],"sources":["../src/core/migrations/resolve-ddl-schema.ts"],"sourcesContent":["import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { DEFAULT_NAMESPACE_ID } from '../namespace-ids';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Given the contract's storage and a namespace id, returns the live Postgres\n * DDL schema name that namespace maps to. A named Postgres namespace dispatches\n * to its `ddlSchemaName(storage)`; the unbound sentinel resolves to\n * `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a\n * bare object payload (used by some tests) falls back to the namespace id\n * itself.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return DEFAULT_NAMESPACE_ID;\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,oCACd,SACA,aACQ;CACR,IAAI,gBAAgB,sBAClB,OAAO;CAET,MAAM,YAAY,QAAQ,WAAW;CACrC,IAAI,aAAa,iBAAiB,SAAS,GACzC,OAAO,UAAU,cAAc,OAAO;CAExC,OAAO;AACT"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { t as PostgresContractView } from "./postgres-contract-view-C9j5cqP0.mjs";
|
|
1
2
|
import { AnyCodecDescriptor } from "@prisma-next/framework-components/codec";
|
|
2
|
-
import { Namespace } from "@prisma-next/framework-components/ir";
|
|
3
|
-
import {
|
|
3
|
+
import { AnyEntityKindDescriptor, Namespace } from "@prisma-next/framework-components/ir";
|
|
4
|
+
import { SqlNamespaceInput, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
4
5
|
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
5
6
|
import { Contract } from "@prisma-next/contract/types";
|
|
6
7
|
import { RuntimeTargetDescriptor, RuntimeTargetInstance } from "@prisma-next/framework-components/execution";
|
|
@@ -8,12 +9,9 @@ import { JsonObject } from "@prisma-next/utils/json";
|
|
|
8
9
|
|
|
9
10
|
//#region src/core/postgres-contract-serializer.d.ts
|
|
10
11
|
declare class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
11
|
-
constructor();
|
|
12
|
-
protected
|
|
13
|
-
protected hydrateSqlNamespaceEntry(nsId: string, raw: Namespace | Record<string, unknown>): Namespace | SqlNamespaceTablesInput;
|
|
12
|
+
constructor(extraPackEntityKinds?: readonly AnyEntityKindDescriptor[]);
|
|
13
|
+
protected hydrateSqlNamespaceEntry(nsId: string, raw: Record<string, unknown>): Namespace | SqlNamespaceInput;
|
|
14
14
|
serializeContract(contract: Contract<SqlStorage>): JsonObject;
|
|
15
|
-
private serializePostgresNamespace;
|
|
16
|
-
private serializeJsonValue;
|
|
17
15
|
}
|
|
18
16
|
//#endregion
|
|
19
17
|
//#region src/exports/runtime.d.ts
|
|
@@ -28,5 +26,5 @@ declare const postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<'sql', 'p
|
|
|
28
26
|
readonly codecs: () => readonly AnyCodecDescriptor[];
|
|
29
27
|
};
|
|
30
28
|
//#endregion
|
|
31
|
-
export { PostgresContractSerializer, PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
|
|
29
|
+
export { PostgresContractSerializer, PostgresContractView, PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
|
|
32
30
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;;cAqEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;cACrE,oBAAA,YAA+B,uBAAA;EAAA,UAUxB,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,MAAA,oBACJ,SAAA,GAAY,iBAAA;EAyBN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;AAAA;;;UClG7C,6BAAA,SAAsC,qBAAqB;;;;;AD2D5E;;cCnDM,+BAAA,EAAiC,uBAAA,oBAGrC,6BAAA;EAAA,SAES,MAAA,iBAAuB,kBAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-UwYdV8fD.mjs";
|
|
2
|
+
import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-3xfUgjnC.mjs";
|
|
3
3
|
//#region src/exports/runtime.ts
|
|
4
4
|
/**
|
|
5
5
|
* Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
|
|
@@ -18,6 +18,6 @@ const postgresRuntimeTargetDescriptor = {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
|
-
export { PostgresContractSerializer, postgresRuntimeTargetDescriptor as default };
|
|
21
|
+
export { PostgresContractSerializer, PostgresContractView, postgresRuntimeTargetDescriptor as default };
|
|
22
22
|
|
|
23
23
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';\n\nexport { PostgresContractSerializer } from '../core/postgres-contract-serializer';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMetaRuntime,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';\n\nexport { PostgresContractSerializer } from '../core/postgres-contract-serializer';\nexport { PostgresContractView } from '../core/postgres-contract-view';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMetaRuntime,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":";;;;;;;;;AAkBA,MAAM,kCAMF;CACF,GAAG;CACH,cAAc,CAAC;CACf,SAAwC;EACtC,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/core/migrations/resolve-ddl-schema.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Given the contract's storage and a namespace id, returns the live Postgres
|
|
6
|
+
* DDL schema name that namespace maps to. A named Postgres namespace dispatches
|
|
7
|
+
* to its `ddlSchemaName(storage)`; the unbound sentinel resolves to
|
|
8
|
+
* `DEFAULT_NAMESPACE_ID` (the search-path default for offline planning); a
|
|
9
|
+
* bare object payload (used by some tests) falls back to the namespace id
|
|
10
|
+
* itself.
|
|
11
|
+
*/
|
|
12
|
+
declare function resolveDdlSchemaForNamespaceStorage(storage: SqlStorage, namespaceId: string): string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { resolveDdlSchemaForNamespaceStorage };
|
|
15
|
+
//# sourceMappingURL=schema-ir-annotations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-ir-annotations.d.mts","names":[],"sources":["../src/core/migrations/resolve-ddl-schema.ts"],"mappings":";;;;;AAaA;;;;;;iBAAgB,mCAAA,CACd,OAAA,EAAS,UAAU,EACnB,WAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { relationalNodeEntityKind, relationalNodeGranularity } from "@prisma-next/sql-schema-ir/types";
|
|
2
|
+
//#region src/core/schema-ir/schema-node-kinds.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `nodeKind` discriminant for each Postgres schema-diff node. Each node
|
|
5
|
+
* carries a unique value; the static `is`/`assert` guards compare against these
|
|
6
|
+
* identifiers rather than spelling the string inline or using `instanceof`. The
|
|
7
|
+
* field is an enumerable own property carried on every node instance.
|
|
8
|
+
*/
|
|
9
|
+
const PostgresSchemaNodeKind = {
|
|
10
|
+
database: "postgres-database",
|
|
11
|
+
namespace: "postgres-namespace",
|
|
12
|
+
table: "postgres-table",
|
|
13
|
+
policy: "postgres-policy",
|
|
14
|
+
role: "postgres-role"
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The one real map from a Postgres-specific `nodeKind` to the
|
|
18
|
+
* framework-neutral {@link DiffSubjectGranularity} its diff issues carry —
|
|
19
|
+
* resolution is by `nodeKind` equality against this map, never a
|
|
20
|
+
* `nodeKind`-suffix string match and never anything stamped on the node.
|
|
21
|
+
*/
|
|
22
|
+
const POSTGRES_NODE_GRANULARITY = {
|
|
23
|
+
[PostgresSchemaNodeKind.database]: "structural",
|
|
24
|
+
[PostgresSchemaNodeKind.namespace]: "namespace",
|
|
25
|
+
[PostgresSchemaNodeKind.table]: "entity",
|
|
26
|
+
[PostgresSchemaNodeKind.policy]: "structural",
|
|
27
|
+
[PostgresSchemaNodeKind.role]: "structural"
|
|
28
|
+
};
|
|
29
|
+
function isPostgresSchemaNodeKind(nodeKind) {
|
|
30
|
+
return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);
|
|
31
|
+
}
|
|
32
|
+
/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */
|
|
33
|
+
function postgresNodeGranularity(nodeKind) {
|
|
34
|
+
return POSTGRES_NODE_GRANULARITY[nodeKind];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The subject granularity for any node kind that appears in a Postgres diff
|
|
38
|
+
* tree — the tree mixes Postgres-specific kinds (database/namespace/table/
|
|
39
|
+
* policy/role) with the relational leaf kinds (columns, constraints, indexes,
|
|
40
|
+
* …), so this dispatches to whichever family/target map owns the kind. Called
|
|
41
|
+
* on demand by consumers (the family verdict, the framework aggregate's
|
|
42
|
+
* unclaimed-elements sweep, via the {@link
|
|
43
|
+
* import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
|
|
44
|
+
* capability) — never stamped onto the issue or the node.
|
|
45
|
+
*/
|
|
46
|
+
function postgresDiffSubjectGranularity(nodeKind) {
|
|
47
|
+
return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeGranularity(nodeKind) : relationalNodeGranularity(nodeKind);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The one real map from a Postgres-specific `nodeKind` to its storage
|
|
51
|
+
* `entityKind` — the same vocabulary the contract storage's `entries`
|
|
52
|
+
* dictionary keys use. Only the whole-table kind has an entity of its own;
|
|
53
|
+
* database/namespace/policy/role nodes map to nothing here (a namespace is
|
|
54
|
+
* addressed by id, not by an `entries` kind; policies and roles are
|
|
55
|
+
* structural, never a sibling space's unclaimed entity).
|
|
56
|
+
*/
|
|
57
|
+
const POSTGRES_NODE_ENTITY_KIND = { [PostgresSchemaNodeKind.table]: "table" };
|
|
58
|
+
/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */
|
|
59
|
+
function postgresNodeEntityKind(nodeKind) {
|
|
60
|
+
return POSTGRES_NODE_ENTITY_KIND[nodeKind];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The storage `entityKind` for any node kind that appears in a Postgres diff
|
|
64
|
+
* tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the
|
|
65
|
+
* same way to whichever family/target map owns the kind. Called on demand by
|
|
66
|
+
* the framework aggregate's unclaimed-elements sweep via the {@link
|
|
67
|
+
* import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}
|
|
68
|
+
* capability — never stamped onto the issue or the node.
|
|
69
|
+
*/
|
|
70
|
+
function postgresDiffSubjectEntityKind(nodeKind) {
|
|
71
|
+
return isPostgresSchemaNodeKind(nodeKind) ? postgresNodeEntityKind(nodeKind) : relationalNodeEntityKind(nodeKind);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { postgresDiffSubjectEntityKind as n, postgresDiffSubjectGranularity as r, PostgresSchemaNodeKind as t };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=schema-node-kinds-ClScchhi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-node-kinds-ClScchhi.mjs","names":[],"sources":["../src/core/schema-ir/schema-node-kinds.ts"],"sourcesContent":["import type {\n DiffableNode,\n DiffSubjectGranularity,\n} from '@prisma-next/framework-components/control';\nimport {\n relationalNodeEntityKind,\n relationalNodeGranularity,\n type SqlSchemaIRNode,\n} from '@prisma-next/sql-schema-ir/types';\n\n/**\n * A Postgres schema-diff-tree node: a `SqlSchemaIRNode` that also implements\n * `DiffableNode` (the five `Postgres*SchemaNode` classes). `SqlSchemaIRNode`\n * alone is not a `DiffableNode` — its relational subclasses (`SqlColumnIR`, …)\n * carry no `id`/`isEqualTo`/`children` — so this intersection is the honest node\n * type the differ produces and the planner consumes (`SchemaDiff<SqlSchemaDiffNode>`).\n */\nexport type SqlSchemaDiffNode = SqlSchemaIRNode & DiffableNode;\n\n/**\n * The `nodeKind` discriminant for each Postgres schema-diff node. Each node\n * carries a unique value; the static `is`/`assert` guards compare against these\n * identifiers rather than spelling the string inline or using `instanceof`. The\n * field is an enumerable own property carried on every node instance.\n */\nexport const PostgresSchemaNodeKind = {\n database: 'postgres-database',\n namespace: 'postgres-namespace',\n table: 'postgres-table',\n policy: 'postgres-policy',\n role: 'postgres-role',\n} as const;\n\nexport type PostgresSchemaNodeKind =\n (typeof PostgresSchemaNodeKind)[keyof typeof PostgresSchemaNodeKind];\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to the\n * framework-neutral {@link DiffSubjectGranularity} its diff issues carry —\n * resolution is by `nodeKind` equality against this map, never a\n * `nodeKind`-suffix string match and never anything stamped on the node.\n */\nconst POSTGRES_NODE_GRANULARITY: Readonly<Record<PostgresSchemaNodeKind, DiffSubjectGranularity>> =\n {\n [PostgresSchemaNodeKind.database]: 'structural',\n [PostgresSchemaNodeKind.namespace]: 'namespace',\n [PostgresSchemaNodeKind.table]: 'entity',\n [PostgresSchemaNodeKind.policy]: 'structural',\n [PostgresSchemaNodeKind.role]: 'structural',\n };\n\nfunction isPostgresSchemaNodeKind(nodeKind: string): nodeKind is PostgresSchemaNodeKind {\n return Object.hasOwn(POSTGRES_NODE_GRANULARITY, nodeKind);\n}\n\n/** Looks up the subject granularity for a Postgres-specific `nodeKind`. */\nexport function postgresNodeGranularity(nodeKind: PostgresSchemaNodeKind): DiffSubjectGranularity {\n return POSTGRES_NODE_GRANULARITY[nodeKind];\n}\n\n/**\n * The subject granularity for any node kind that appears in a Postgres diff\n * tree — the tree mixes Postgres-specific kinds (database/namespace/table/\n * policy/role) with the relational leaf kinds (columns, constraints, indexes,\n * …), so this dispatches to whichever family/target map owns the kind. Called\n * on demand by consumers (the family verdict, the framework aggregate's\n * unclaimed-elements sweep, via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability) — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectGranularity(nodeKind: string): DiffSubjectGranularity {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeGranularity(nodeKind)\n : relationalNodeGranularity(nodeKind);\n}\n\n/**\n * The one real map from a Postgres-specific `nodeKind` to its storage\n * `entityKind` — the same vocabulary the contract storage's `entries`\n * dictionary keys use. Only the whole-table kind has an entity of its own;\n * database/namespace/policy/role nodes map to nothing here (a namespace is\n * addressed by id, not by an `entries` kind; policies and roles are\n * structural, never a sibling space's unclaimed entity).\n */\nconst POSTGRES_NODE_ENTITY_KIND: Partial<Readonly<Record<PostgresSchemaNodeKind, string>>> = {\n [PostgresSchemaNodeKind.table]: 'table',\n};\n\n/** Looks up the storage entityKind for a Postgres-specific `nodeKind`. */\nexport function postgresNodeEntityKind(nodeKind: PostgresSchemaNodeKind): string | undefined {\n return POSTGRES_NODE_ENTITY_KIND[nodeKind];\n}\n\n/**\n * The storage `entityKind` for any node kind that appears in a Postgres diff\n * tree — sibling of {@link postgresDiffSubjectGranularity}, dispatching the\n * same way to whichever family/target map owns the kind. Called on demand by\n * the framework aggregate's unclaimed-elements sweep via the {@link\n * import('@prisma-next/framework-components/control').SchemaSubjectClassifierCapable}\n * capability — never stamped onto the issue or the node.\n */\nexport function postgresDiffSubjectEntityKind(nodeKind: string): string | undefined {\n return isPostgresSchemaNodeKind(nodeKind)\n ? postgresNodeEntityKind(nodeKind)\n : relationalNodeEntityKind(nodeKind);\n}\n"],"mappings":";;;;;;;;AAyBA,MAAa,yBAAyB;CACpC,UAAU;CACV,WAAW;CACX,OAAO;CACP,QAAQ;CACR,MAAM;AACR;;;;;;;AAWA,MAAM,4BACJ;EACG,uBAAuB,WAAW;EAClC,uBAAuB,YAAY;EACnC,uBAAuB,QAAQ;EAC/B,uBAAuB,SAAS;EAChC,uBAAuB,OAAO;AACjC;AAEF,SAAS,yBAAyB,UAAsD;CACtF,OAAO,OAAO,OAAO,2BAA2B,QAAQ;AAC1D;;AAGA,SAAgB,wBAAwB,UAA0D;CAChG,OAAO,0BAA0B;AACnC;;;;;;;;;;;AAYA,SAAgB,+BAA+B,UAA0C;CACvF,OAAO,yBAAyB,QAAQ,IACpC,wBAAwB,QAAQ,IAChC,0BAA0B,QAAQ;AACxC;;;;;;;;;AAUA,MAAM,4BAAuF,GAC1F,uBAAuB,QAAQ,QAClC;;AAGA,SAAgB,uBAAuB,UAAsD;CAC3F,OAAO,0BAA0B;AACnC;;;;;;;;;AAUA,SAAgB,8BAA8B,UAAsC;CAClF,OAAO,yBAAyB,QAAQ,IACpC,uBAAuB,QAAQ,IAC/B,yBAAyB,QAAQ;AACvC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,141 +1,5 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { n as PostgresRlsPolicyInput, r as RlsPolicyOperation, t as PostgresRlsPolicy } from "./postgres-rls-policy--CSddvMR.mjs";
|
|
2
|
+
import { a as PostgresNamespaceSchemaNode, c as PostgresTableSchemaNodeInput, i as PostgresRoleSchemaNodeInput, l as PostgresPolicySchemaNode, n as PostgresDatabaseSchemaNodeInput, o as PostgresNamespaceSchemaNodeInput, r as PostgresRoleSchemaNode, s as PostgresTableSchemaNode, t as PostgresDatabaseSchemaNode, u as PostgresPolicySchemaNodeInput } from "./postgres-database-schema-node-C9bTuMrd.mjs";
|
|
2
3
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { SqlNamespaceEntries, SqlNamespaceTablesInput, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
6
|
-
|
|
7
|
-
//#region src/core/postgres-schema.d.ts
|
|
8
|
-
interface PostgresSchemaInput {
|
|
9
|
-
readonly id: string;
|
|
10
|
-
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
14
|
-
* SCHEMA …`). Each Postgres `SqlStorage` carries a
|
|
15
|
-
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
16
|
-
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
17
|
-
*
|
|
18
|
-
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
19
|
-
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
20
|
-
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
21
|
-
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
22
|
-
* The unbound singleton below overrides these methods to elide the
|
|
23
|
-
* prefix entirely — call sites stay polymorphic and never branch on
|
|
24
|
-
* `id === UNBOUND_NAMESPACE_ID`.
|
|
25
|
-
*/
|
|
26
|
-
declare class PostgresSchema extends NamespaceBase {
|
|
27
|
-
/**
|
|
28
|
-
* Stable singleton reference for the late-bound slot. Materialised
|
|
29
|
-
* lazily below the singleton subclass declaration so the static
|
|
30
|
-
* initialiser sees the subclass before assigning. Consumers always
|
|
31
|
-
* reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`
|
|
32
|
-
* — same identity).
|
|
33
|
-
*/
|
|
34
|
-
static unbound: PostgresUnboundSchema;
|
|
35
|
-
readonly kind: 'schema';
|
|
36
|
-
readonly id: string;
|
|
37
|
-
readonly entries: SqlNamespaceEntries;
|
|
38
|
-
constructor(input: PostgresSchemaInput);
|
|
39
|
-
get table(): Readonly<Record<string, StorageTable>>;
|
|
40
|
-
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* The bare schema qualifier as it would appear in a rendered SQL
|
|
43
|
-
* fragment (already quoted). The unbound-schema singleton overrides
|
|
44
|
-
* this to return `''`.
|
|
45
|
-
*/
|
|
46
|
-
qualifier(): string;
|
|
47
|
-
/**
|
|
48
|
-
* Qualify a table name with the schema prefix
|
|
49
|
-
* (`"<schema>"."<table>"`). The unbound-schema singleton overrides
|
|
50
|
-
* this to emit just `"<table>"` so the resolved DDL is unqualified
|
|
51
|
-
* and `search_path` decides where the object lands at runtime.
|
|
52
|
-
*/
|
|
53
|
-
qualifyTable(tableName: string): string;
|
|
54
|
-
/**
|
|
55
|
-
* Render a SQL string-literal containing the qualified-name form
|
|
56
|
-
* suitable for `to_regclass(...)` arguments (e.g. `'"public"."user"'`).
|
|
57
|
-
* The unbound singleton overrides this to elide the schema prefix
|
|
58
|
-
* (`'"user"'`) so `search_path` resolves the object at runtime.
|
|
59
|
-
*/
|
|
60
|
-
regclassLiteral(name: string): string;
|
|
61
|
-
/**
|
|
62
|
-
* Render a SQL expression that evaluates to this namespace's schema
|
|
63
|
-
* name at runtime, ready to drop into a `WHERE table_schema = …` /
|
|
64
|
-
* `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL
|
|
65
|
-
* literal (`'public'`); the unbound singleton overrides this to emit
|
|
66
|
-
* `current_schema()` so catalog queries match whichever schema the
|
|
67
|
-
* connection's `search_path` resolved at runtime.
|
|
68
|
-
*/
|
|
69
|
-
schemaSqlExpression(): string;
|
|
70
|
-
/**
|
|
71
|
-
* Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
|
|
72
|
-
* builder-built catalog check compares `n.nspname` / `table_schema`
|
|
73
|
-
* against. Named schemas bind the schema name as a text parameter; the
|
|
74
|
-
* unbound singleton overrides this to the opaque `current_schema()`
|
|
75
|
-
* expression so the live connection's `search_path` decides at runtime.
|
|
76
|
-
*/
|
|
77
|
-
schemaFilterExpression(): CfExpr;
|
|
78
|
-
/**
|
|
79
|
-
* Typed-AST counterpart of {@link qualifyTable}: the FROM source a
|
|
80
|
-
* builder-built check uses to address a user table in this namespace.
|
|
81
|
-
* Named schemas qualify (`"schema"."table"`); the unbound singleton
|
|
82
|
-
* overrides this to leave the table unqualified so `search_path`
|
|
83
|
-
* resolves it at runtime.
|
|
84
|
-
*/
|
|
85
|
-
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
86
|
-
/**
|
|
87
|
-
* The bare schema name a DDL planner should target when emitting
|
|
88
|
-
* statements that need to identify this namespace in the live
|
|
89
|
-
* database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
|
|
90
|
-
* catalog filters, planner conflict lookups). Named schemas resolve
|
|
91
|
-
* to their own id. The `PostgresUnboundSchema` singleton inherits
|
|
92
|
-
* this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
|
|
93
|
-
* through `qualifyTableName` route through the polymorphic
|
|
94
|
-
* `PostgresUnboundSchema` overrides and produce unqualified
|
|
95
|
-
* (search-path-resolved) output automatically.
|
|
96
|
-
*/
|
|
97
|
-
ddlSchemaName(_storage: SqlStorage): string;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Singleton subclass for the reserved sentinel namespace id
|
|
101
|
-
* (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding
|
|
102
|
-
* the connection's `search_path` resolves at runtime. Overrides
|
|
103
|
-
* qualifier emission to elide the schema prefix; call sites that consume
|
|
104
|
-
* `qualifier()` / `qualifyTable()` get unqualified output without
|
|
105
|
-
* branching on the namespace id.
|
|
106
|
-
*
|
|
107
|
-
* This is the target-side materialization of "the framework provides
|
|
108
|
-
* affordances; targets implement specifics": the framework names the
|
|
109
|
-
* sentinel; Postgres decides what late-bound means here (the table
|
|
110
|
-
* name, naked — the schema is supplied by the live connection's
|
|
111
|
-
* `search_path`).
|
|
112
|
-
*
|
|
113
|
-
* `ddlSchemaName` is inherited from `PostgresSchema` and returns
|
|
114
|
-
* `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
|
|
115
|
-
* route through the polymorphic factory and produce unqualified output
|
|
116
|
-
* automatically.
|
|
117
|
-
*/
|
|
118
|
-
declare class PostgresUnboundSchema extends PostgresSchema {
|
|
119
|
-
static readonly instance: PostgresUnboundSchema;
|
|
120
|
-
constructor(input?: PostgresSchemaInput);
|
|
121
|
-
qualifier(): string;
|
|
122
|
-
qualifyTable(tableName: string): string;
|
|
123
|
-
schemaSqlExpression(): string;
|
|
124
|
-
schemaFilterExpression(): CfExpr;
|
|
125
|
-
tableSource(tableName: string, alias?: string): PostgresTableSource;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Target-supplied `Namespace` factory the Postgres target plumbs
|
|
129
|
-
* through `defineContract({ createNamespace })` and the SQL PSL
|
|
130
|
-
* interpreter. Returns the unbound singleton for the framework
|
|
131
|
-
* sentinel and a fresh `PostgresSchema` for any other coordinate.
|
|
132
|
-
*
|
|
133
|
-
* The factory has no per-call state — every named id deterministically
|
|
134
|
-
* maps to a distinct schema instance — so callers can pass it through
|
|
135
|
-
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
136
|
-
* be value-stable for a given input set.
|
|
137
|
-
*/
|
|
138
|
-
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema;
|
|
139
|
-
//#endregion
|
|
140
|
-
export { type PostgresColumnDefault, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
141
|
-
//# sourceMappingURL=types.d.mts.map
|
|
4
|
+
import { a as postgresCreateNamespace, c as PostgresRoleInput, i as isPostgresSchema, n as PostgresSchema, r as PostgresUnboundSchema, s as PostgresRole, t as PostgresContract } from "./postgres-schema-DqnhQRvR.mjs";
|
|
5
|
+
export { type PostgresColumnDefault, type PostgresContract, PostgresDatabaseSchemaNode, type PostgresDatabaseSchemaNodeInput, PostgresNamespaceSchemaNode, type PostgresNamespaceSchemaNodeInput, PostgresPolicySchemaNode, type PostgresPolicySchemaNodeInput, PostgresRlsPolicy, type PostgresRlsPolicyInput, PostgresRole, type PostgresRoleInput, PostgresRoleSchemaNode, type PostgresRoleSchemaNodeInput, PostgresSchema, PostgresTableSchemaNode, type PostgresTableSchemaNodeInput, PostgresUnboundSchema, type RlsPolicyOperation, isPostgresSchema, postgresCreateNamespace };
|
package/dist/types.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-
|
|
2
|
-
|
|
1
|
+
import { f as PostgresRole, i as postgresCreateNamespace, n as PostgresUnboundSchema, p as PostgresRlsPolicy, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-CajYAwny.mjs";
|
|
2
|
+
import { a as PostgresDatabaseSchemaNode, i as PostgresNamespaceSchemaNode, n as PostgresRoleSchemaNode, r as PostgresPolicySchemaNode, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-BgaSrxYN.mjs";
|
|
3
|
+
export { PostgresDatabaseSchemaNode, PostgresNamespaceSchemaNode, PostgresPolicySchemaNode, PostgresRlsPolicy, PostgresRole, PostgresRoleSchemaNode, PostgresSchema, PostgresTableSchemaNode, PostgresUnboundSchema, isPostgresSchema, postgresCreateNamespace };
|
package/package.json
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.14.0-dev.
|
|
3
|
+
"version": "0.14.0-dev.51",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.14.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.14.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.14.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.14.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.14.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.14.0-dev.
|
|
15
|
-
"@prisma-next/
|
|
16
|
-
"@prisma-next/sql-
|
|
17
|
-
"@prisma-next/sql-
|
|
18
|
-
"@prisma-next/sql-
|
|
19
|
-
"@prisma-next/sql-
|
|
20
|
-
"@prisma-next/
|
|
21
|
-
"@prisma-next/utils": "0.14.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.14.0-dev.51",
|
|
10
|
+
"@prisma-next/contract": "0.14.0-dev.51",
|
|
11
|
+
"@prisma-next/errors": "0.14.0-dev.51",
|
|
12
|
+
"@prisma-next/family-sql": "0.14.0-dev.51",
|
|
13
|
+
"@prisma-next/framework-components": "0.14.0-dev.51",
|
|
14
|
+
"@prisma-next/migration-tools": "0.14.0-dev.51",
|
|
15
|
+
"@prisma-next/sql-contract": "0.14.0-dev.51",
|
|
16
|
+
"@prisma-next/sql-errors": "0.14.0-dev.51",
|
|
17
|
+
"@prisma-next/sql-operations": "0.14.0-dev.51",
|
|
18
|
+
"@prisma-next/sql-relational-core": "0.14.0-dev.51",
|
|
19
|
+
"@prisma-next/sql-schema-ir": "0.14.0-dev.51",
|
|
20
|
+
"@prisma-next/ts-render": "0.14.0-dev.51",
|
|
21
|
+
"@prisma-next/utils": "0.14.0-dev.51",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/
|
|
28
|
-
"@prisma-next/
|
|
29
|
-
"@prisma-next/
|
|
27
|
+
"@prisma-next/psl-parser": "0.14.0-dev.51",
|
|
28
|
+
"@prisma-next/psl-printer": "0.14.0-dev.51",
|
|
29
|
+
"@prisma-next/sql-contract-psl": "0.14.0-dev.51",
|
|
30
|
+
"@prisma-next/test-utils": "0.14.0-dev.51",
|
|
31
|
+
"@prisma-next/tsconfig": "0.14.0-dev.51",
|
|
32
|
+
"@prisma-next/tsdown": "0.14.0-dev.51",
|
|
30
33
|
"tsdown": "0.22.1",
|
|
31
34
|
"typescript": "5.9.3",
|
|
32
35
|
"vitest": "4.1.8"
|
|
@@ -53,6 +56,7 @@
|
|
|
53
56
|
"./data-transform": "./dist/data-transform.mjs",
|
|
54
57
|
"./ddl": "./dist/ddl.mjs",
|
|
55
58
|
"./default-normalizer": "./dist/default-normalizer.mjs",
|
|
59
|
+
"./diff-database-schema": "./dist/diff-database-schema.mjs",
|
|
56
60
|
"./errors": "./dist/errors.mjs",
|
|
57
61
|
"./issue-planner": "./dist/issue-planner.mjs",
|
|
58
62
|
"./migration": "./dist/migration.mjs",
|
|
@@ -68,7 +72,9 @@
|
|
|
68
72
|
"./planner-target-details": "./dist/planner-target-details.mjs",
|
|
69
73
|
"./render-ops": "./dist/render-ops.mjs",
|
|
70
74
|
"./render-typescript": "./dist/render-typescript.mjs",
|
|
75
|
+
"./rls-canonicalize": "./dist/rls-canonicalize.mjs",
|
|
71
76
|
"./runtime": "./dist/runtime.mjs",
|
|
77
|
+
"./schema-ir-annotations": "./dist/schema-ir-annotations.mjs",
|
|
72
78
|
"./sql-utils": "./dist/sql-utils.mjs",
|
|
73
79
|
"./types": "./dist/types.mjs",
|
|
74
80
|
"./package.json": "./package.json"
|
|
@@ -345,6 +345,79 @@ export function extensionExistsAst(extensionName: string): ExtensionExistsCheckB
|
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
export interface RlsPolicyExistsCheckBuilder {
|
|
349
|
+
policyPresent(): SelectAst;
|
|
350
|
+
policyAbsent(): SelectAst;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Typed RLS-policy existence check over `pg_policies`, with schema, table,
|
|
355
|
+
* and policy names bound as text parameters (never inlined). The `schema`
|
|
356
|
+
* coordinate is the resolved live-database schema name (e.g. `'public'`),
|
|
357
|
+
* compared against `pg_policies.schemaname` as a bound parameter.
|
|
358
|
+
*/
|
|
359
|
+
export function rlsPolicyExistsAst(options: {
|
|
360
|
+
readonly schema: string;
|
|
361
|
+
readonly table: string;
|
|
362
|
+
readonly policyName: string;
|
|
363
|
+
}): RlsPolicyExistsCheckBuilder {
|
|
364
|
+
const inner = () =>
|
|
365
|
+
exprSelect()
|
|
366
|
+
.from(cfTable('pg_policies'))
|
|
367
|
+
.project('one', cfExpr.lit(1))
|
|
368
|
+
.where(
|
|
369
|
+
cfExpr.allOf([
|
|
370
|
+
cfExpr.identifierRef('schemaname').eqParam(options.schema, PG_TEXT_CODEC_ID),
|
|
371
|
+
cfExpr.identifierRef('tablename').eqParam(options.table, PG_TEXT_CODEC_ID),
|
|
372
|
+
cfExpr.identifierRef('policyname').eqParam(options.policyName, PG_TEXT_CODEC_ID),
|
|
373
|
+
]),
|
|
374
|
+
);
|
|
375
|
+
return {
|
|
376
|
+
policyPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),
|
|
377
|
+
policyAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface RlsEnabledCheckBuilder {
|
|
382
|
+
rlsEnabled(): SelectAst;
|
|
383
|
+
rlsDisabled(): SelectAst;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Typed row-level-security enabled check over `pg_class` joined to
|
|
388
|
+
* `pg_namespace`, comparing `pg_class.relrowsecurity` against the expected
|
|
389
|
+
* boolean. Schema and table names are bound as text parameters.
|
|
390
|
+
*/
|
|
391
|
+
export function rlsEnabledAst(schema: string, table: string): RlsEnabledCheckBuilder {
|
|
392
|
+
const inner = (enabled: boolean) =>
|
|
393
|
+
exprSelect()
|
|
394
|
+
.from(cfTable('pg_class', 'c'))
|
|
395
|
+
.join(
|
|
396
|
+
cfTable('pg_namespace', 'n'),
|
|
397
|
+
cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'relnamespace')),
|
|
398
|
+
)
|
|
399
|
+
.project('one', cfExpr.lit(1))
|
|
400
|
+
.where(
|
|
401
|
+
cfExpr.allOf([
|
|
402
|
+
cfExpr.columnRef('n', 'nspname').eqParam(schema, PG_TEXT_CODEC_ID),
|
|
403
|
+
cfExpr.columnRef('c', 'relname').eqParam(table, PG_TEXT_CODEC_ID),
|
|
404
|
+
enabled
|
|
405
|
+
? cfExpr.columnRef('c', 'relrowsecurity')
|
|
406
|
+
: cfExpr.columnRef('c', 'relrowsecurity').not(),
|
|
407
|
+
]),
|
|
408
|
+
);
|
|
409
|
+
return {
|
|
410
|
+
rlsEnabled: () =>
|
|
411
|
+
exprSelect()
|
|
412
|
+
.project('result', cfExpr.exists(inner(true)))
|
|
413
|
+
.build(),
|
|
414
|
+
rlsDisabled: () =>
|
|
415
|
+
exprSelect()
|
|
416
|
+
.project('result', cfExpr.exists(inner(false)))
|
|
417
|
+
.build(),
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
348
421
|
export interface IndexExistsCheckBuilder {
|
|
349
422
|
indexPresent(): SelectAst;
|
|
350
423
|
indexAbsent(): SelectAst;
|