@prisma-next/target-postgres 0.13.0-dev.3 → 0.13.0-dev.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{codec-ids-CTikp1if.mjs → codec-ids-BvytN2P8.mjs} +3 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-B1vOchLE.d.mts → codec-ids-CnXu9Qy3.d.mts} +3 -3
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-CnFiNML4.d.mts → codec-types-DHCkwPKE.d.mts} +3 -3
- package/dist/{codec-types-CnFiNML4.d.mts.map → codec-types-DHCkwPKE.d.mts.map} +1 -1
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CBpEv4s5.d.mts → codecs--0A5_4Bq.d.mts} +26 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +28 -35
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +17 -2
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +3 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +21 -27
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
- package/dist/data-transform-BOWpliq8.mjs.map +1 -0
- package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
- package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
- package/dist/data-transform.d.mts +1 -1
- package/dist/data-transform.mjs +1 -1
- package/dist/{ddl-77SyXgFt.mjs → ddl-DY2R_Yqz.mjs} +18 -3
- package/dist/ddl-DY2R_Yqz.mjs.map +1 -0
- package/dist/ddl.d.mts +2 -2
- package/dist/ddl.mjs +2 -2
- package/dist/{descriptor-meta-DKmj-IMN.mjs → descriptor-meta-BKma_hQ5.mjs} +2 -2
- package/dist/{descriptor-meta-DKmj-IMN.mjs.map → descriptor-meta-BKma_hQ5.mjs.map} +1 -1
- package/dist/descriptor-meta-runtime-e5f2tscJ.mjs +131 -0
- package/dist/descriptor-meta-runtime-e5f2tscJ.mjs.map +1 -0
- package/dist/{issue-planner-Br0pt1Ea.mjs → issue-planner-DsjB7xDj.mjs} +48 -252
- package/dist/issue-planner-DsjB7xDj.mjs.map +1 -0
- package/dist/issue-planner.d.mts +8 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +4 -15
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/{nodes-DZk2JZG3.mjs → nodes-Bbhs2rwj.mjs} +31 -2
- package/dist/nodes-Bbhs2rwj.mjs.map +1 -0
- package/dist/{nodes-779hmCfL.d.mts → nodes-pLeLgdis.d.mts} +30 -3
- package/dist/nodes-pLeLgdis.d.mts.map +1 -0
- package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-CdtMyrlU.d.mts} +12 -56
- package/dist/op-factory-call-CdtMyrlU.d.mts.map +1 -0
- package/dist/{op-factory-call-D2aAUhmS.mjs → op-factory-call-CjR846f7.mjs} +70 -198
- package/dist/op-factory-call-CjR846f7.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +36 -15
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CAYPJObw.mjs → planner-_FOL4I21.mjs} +25 -45
- package/dist/planner-_FOL4I21.mjs.map +1 -0
- package/dist/{planner-ddl-builders-Cw2n2llW.mjs → planner-ddl-builders-B2wOwLqI.mjs} +2 -2
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -4
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-identity-values-BIpa5p2I.mjs → planner-identity-values-CJPha2Sz.mjs} +3 -9
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -0
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-NSEhWL0L.mjs → planner-produced-postgres-migration-BmCpyWLJ.mjs} +6 -4
- package/dist/planner-produced-postgres-migration-BmCpyWLJ.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-wLhnJMMA.d.mts} +5 -6
- package/dist/planner-produced-postgres-migration-wLhnJMMA.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-DAdhnI2c.mjs → planner-sql-checks-CJJtPfDH.mjs} +3 -3
- package/dist/planner-sql-checks-CJJtPfDH.mjs.map +1 -0
- 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-type-resolution-836DExFN.mjs → planner-type-resolution-Bt2f_q-F.mjs} +1 -6
- package/dist/planner-type-resolution-Bt2f_q-F.mjs.map +1 -0
- package/dist/planner.d.mts +4 -4
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-CyAe8ZFv.mjs} +27 -37
- package/dist/postgres-contract-serializer-CyAe8ZFv.mjs.map +1 -0
- package/dist/{postgres-migration-DZ_gLUOW.d.mts → postgres-migration-DLXL0GBf.d.mts} +10 -5
- package/dist/postgres-migration-DLXL0GBf.d.mts.map +1 -0
- package/dist/{postgres-migration-COore9Mz.mjs → postgres-migration-dG-J0aI8.mjs} +7 -3
- package/dist/postgres-migration-dG-J0aI8.mjs.map +1 -0
- package/dist/{postgres-schema-BuxCxbvB.mjs → postgres-schema-CTKYiTHu.mjs} +30 -13
- package/dist/postgres-schema-CTKYiTHu.mjs.map +1 -0
- package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
- package/dist/render-ops-BREh1kHe.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -2
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{shared-DarONYBZ.d.mts → shared-jcsbXxiW.d.mts} +2 -20
- package/dist/shared-jcsbXxiW.d.mts.map +1 -0
- package/dist/types.d.mts +8 -13
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -3
- package/package.json +17 -18
- package/src/contract-free/ddl.ts +28 -1
- package/src/core/authoring.ts +43 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +1 -1
- package/src/core/codec-type-map.ts +2 -2
- package/src/core/codecs.ts +43 -48
- package/src/core/ddl/nodes.ts +59 -1
- package/src/core/migrations/control-policy.ts +17 -47
- package/src/core/migrations/issue-planner.ts +34 -70
- package/src/core/migrations/op-factory-call.ts +89 -142
- package/src/core/migrations/operations/data-transform.ts +15 -18
- package/src/core/migrations/planner-ddl-builders.ts +3 -4
- package/src/core/migrations/planner-identity-values.ts +4 -28
- package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
- package/src/core/migrations/planner-recipes.ts +2 -6
- package/src/core/migrations/planner-sql-checks.ts +2 -6
- package/src/core/migrations/planner-strategies.ts +51 -376
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +6 -6
- package/src/core/migrations/postgres-migration.ts +19 -4
- package/src/core/migrations/render-ops.ts +26 -13
- package/src/core/migrations/runner.ts +26 -20
- package/src/core/postgres-contract-serializer.ts +32 -54
- package/src/core/postgres-enum-type-schema.ts +17 -0
- package/src/core/postgres-schema.ts +56 -34
- package/src/exports/codecs.ts +2 -2
- package/src/exports/contract-free.ts +1 -1
- package/src/exports/control.ts +0 -22
- package/src/exports/ddl.ts +4 -0
- package/src/exports/migration.ts +0 -7
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/types.ts +0 -1
- package/dist/codec-ids-B1vOchLE.d.mts.map +0 -1
- package/dist/codec-ids-CTikp1if.mjs.map +0 -1
- package/dist/codecs-CBpEv4s5.d.mts.map +0 -1
- package/dist/data-transform-D25tLeYU.mjs.map +0 -1
- package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
- package/dist/ddl-77SyXgFt.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs +0 -130
- package/dist/descriptor-meta-runtime-My8_s4cs.mjs.map +0 -1
- package/dist/enum-planning-BCyvlFHk.mjs +0 -0
- package/dist/enum-planning-BCyvlFHk.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -86
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-Br0pt1Ea.mjs.map +0 -1
- package/dist/nodes-779hmCfL.d.mts.map +0 -1
- package/dist/nodes-DZk2JZG3.mjs.map +0 -1
- package/dist/op-factory-call-D2aAUhmS.mjs.map +0 -1
- package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
- package/dist/planner-CAYPJObw.mjs.map +0 -1
- package/dist/planner-ddl-builders-Cw2n2llW.mjs.map +0 -1
- package/dist/planner-identity-values-BIpa5p2I.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-NSEhWL0L.mjs.map +0 -1
- package/dist/planner-sql-checks-DAdhnI2c.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-DYTyXjPf.mjs.map +0 -1
- package/dist/postgres-enum-type-BVn63a89.d.mts +0 -72
- package/dist/postgres-enum-type-BVn63a89.d.mts.map +0 -1
- package/dist/postgres-enum-type-DPKqCBem.mjs +0 -62
- package/dist/postgres-enum-type-DPKqCBem.mjs.map +0 -1
- package/dist/postgres-migration-COore9Mz.mjs.map +0 -1
- package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
- package/dist/postgres-schema-BuxCxbvB.mjs.map +0 -1
- package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
- package/dist/shared-DarONYBZ.d.mts.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -213
- package/src/core/migrations/operations/enums.ts +0 -114
- package/src/core/postgres-enum-type.ts +0 -89
- package/src/exports/enum-planning.ts +0 -11
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
2
1
|
//#region src/core/migrations/planner-type-resolution.ts
|
|
3
2
|
function resolveColumnTypeMetadata(column, storageTypes) {
|
|
4
3
|
if (!column.typeRef) return column;
|
|
5
4
|
const referencedType = storageTypes[column.typeRef];
|
|
6
5
|
if (!referencedType) return column;
|
|
7
|
-
if (isPostgresEnumStorageEntry(referencedType)) return {
|
|
8
|
-
codecId: referencedType.codecId,
|
|
9
|
-
nativeType: referencedType.nativeType
|
|
10
|
-
};
|
|
11
6
|
return {
|
|
12
7
|
codecId: referencedType.codecId,
|
|
13
8
|
nativeType: referencedType.nativeType,
|
|
@@ -17,4 +12,4 @@ function resolveColumnTypeMetadata(column, storageTypes) {
|
|
|
17
12
|
//#endregion
|
|
18
13
|
export { resolveColumnTypeMetadata as t };
|
|
19
14
|
|
|
20
|
-
//# sourceMappingURL=planner-type-resolution-
|
|
15
|
+
//# sourceMappingURL=planner-type-resolution-Bt2f_q-F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner-type-resolution-Bt2f_q-F.mjs","names":[],"sources":["../src/core/migrations/planner-type-resolution.ts"],"sourcesContent":["import type { StorageColumn, StorageTypeInstance } from '@prisma-next/sql-contract/types';\n\nexport type ResolvedColumnTypeMetadata = Pick<\n StorageColumn,\n 'nativeType' | 'codecId' | 'typeParams'\n>;\n\nexport function resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Readonly<Record<string, StorageTypeInstance>>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n return column;\n }\n\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n"],"mappings":";AAOA,SAAgB,0BACd,QACA,cAC4B;CAC5B,IAAI,CAAC,OAAO,SACV,OAAO;CAGT,MAAM,iBAAiB,aAAa,OAAO;CAC3C,IAAI,CAAC,gBACH,OAAO;CAGT,OAAO;EACL,SAAS,eAAe;EACxB,YAAY,eAAe;EAC3B,YAAY,eAAe;CAC7B;AACF"}
|
package/dist/planner.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-
|
|
1
|
+
import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-wLhnJMMA.mjs";
|
|
2
2
|
import { MigrationOperationPolicy, SqlPlannerConflict, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
5
|
-
import {
|
|
5
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
6
6
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
7
7
|
|
|
8
8
|
//#region src/core/migrations/planner.d.ts
|
|
9
|
-
declare function createPostgresMigrationPlanner(lowerer:
|
|
9
|
+
declare function createPostgresMigrationPlanner(lowerer: ExecuteRequestLowerer): PostgresMigrationPlanner;
|
|
10
10
|
/**
|
|
11
11
|
* Result of `PostgresMigrationPlanner.plan()`. A discriminated union whose
|
|
12
12
|
* success variant carries a `TypeScriptRenderablePostgresMigration` — a
|
|
@@ -37,7 +37,7 @@ type PostgresPlanResult = {
|
|
|
37
37
|
*/
|
|
38
38
|
declare class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postgres'> {
|
|
39
39
|
#private;
|
|
40
|
-
constructor(lowerer?:
|
|
40
|
+
constructor(lowerer?: ExecuteRequestLowerer);
|
|
41
41
|
plan(options: {
|
|
42
42
|
readonly contract: unknown;
|
|
43
43
|
readonly schema: unknown;
|
package/dist/planner.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"mappings":";;;;;;;;iBAqDgB,8BAAA,CACd,OAAA,EAAS,qBAAA,GACR,wBAAwB;;AAF3B;;;;;;KAaY,kBAAA;EAAA,SAEG,IAAA;EAAA,SACA,IAAA,EAAM,qCAAA;EAAA,SACN,QAAA,YAAoB,kBAAA;AAAA,IAE/B,uBAAA;;;;;;;;;;;;;;AAAuB;AAkB3B;;cAAa,wBAAA,YAAoC,gBAAA;EAAA;cAGnC,OAAA,GAAU,qBAAA;EAItB,IAAA,CAAK,OAAA;IAAA,SACM,QAAA;IAAA,SACA,MAAA;IAAA,SACA,MAAA,EAAQ,wBAAA;IA6BR;;;;;;;;;;;;;;IAAA,SAdA,YAAA,EAAc,QAAA;IAAA,SACd,UAAA;IAAA,SACA,mBAAA,EAAqB,aAAA,CAAc,8BAAA;IADnC;;;;;IAAA,SAOA,OAAA;EAAA,IACP,kBAAA;EAIJ,cAAA,CACE,OAAA,EAAS,wBAAA,EACT,OAAA,WACC,iCAAA;EAAA,QAYK,OAAA;EAAA,QAmGA,oBAAA;EAAA,QAaA,mBAAA;AAAA"}
|
package/dist/planner.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
1
|
+
import { t as createPostgresMigrationPlanner } from "./planner-_FOL4I21.mjs";
|
|
2
2
|
export { createPostgresMigrationPlanner };
|
package/dist/{postgres-contract-serializer-DYTyXjPf.mjs → postgres-contract-serializer-CyAe8ZFv.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-runtime-
|
|
2
|
-
import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-
|
|
3
|
-
import { NamespaceBase, UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
1
|
+
import { n as postgresAuthoringEntityTypes } from "./descriptor-meta-runtime-e5f2tscJ.mjs";
|
|
2
|
+
import { r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-CTKYiTHu.mjs";
|
|
4
3
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
|
+
import { NamespaceBase, UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
5
5
|
import { SqlContractSerializerBase } from "@prisma-next/family-sql/ir";
|
|
6
6
|
import { isAuthoringEntityTypeDescriptor } from "@prisma-next/framework-components/authoring";
|
|
7
7
|
//#region src/core/postgres-contract-serializer.ts
|
|
@@ -13,57 +13,46 @@ function isAuthoringEntityTypeFactoryOutput(output) {
|
|
|
13
13
|
return typeof output === "object" && output !== null && typeof output.factory === "function";
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Walks a pack's entity-type namespace tree and emits
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Walks a pack's entity-type namespace tree and emits hydration factories
|
|
17
|
+
* keyed by the descriptor's `discriminator`. Used for `storage.types`
|
|
18
|
+
* (codec-triple hydration). Namespace entries hydration dispatches by
|
|
19
|
+
* entries key, not discriminator — handled by `hydrateEntriesKind`.
|
|
19
20
|
*/
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
const validatorFragments = /* @__PURE__ */ new Map();
|
|
21
|
+
function collectStorageTypesHydrators(namespace) {
|
|
22
|
+
const registry = /* @__PURE__ */ new Map();
|
|
23
23
|
const walk = (node) => {
|
|
24
24
|
for (const value of Object.values(node)) {
|
|
25
25
|
if (isAuthoringEntityTypeDescriptor(value)) {
|
|
26
26
|
if (isAuthoringEntityTypeFactoryOutput(value.output)) {
|
|
27
27
|
const { factory } = value.output;
|
|
28
|
-
|
|
28
|
+
registry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));
|
|
29
29
|
}
|
|
30
|
-
if (value.validatorSchema !== void 0) validatorFragments.set(value.discriminator, value.validatorSchema);
|
|
31
30
|
continue;
|
|
32
31
|
}
|
|
33
32
|
if (typeof value === "object" && value !== null) walk(value);
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
walk(namespace);
|
|
37
|
-
return
|
|
38
|
-
entityTypeRegistry,
|
|
39
|
-
validatorFragments
|
|
40
|
-
};
|
|
36
|
+
return registry;
|
|
41
37
|
}
|
|
42
38
|
var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
43
39
|
constructor() {
|
|
44
|
-
const
|
|
45
|
-
super(
|
|
40
|
+
const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);
|
|
41
|
+
super(storageTypesHydrators);
|
|
46
42
|
}
|
|
47
43
|
hydrateSqlNamespaceEntry(nsId, raw) {
|
|
48
44
|
if (raw instanceof NamespaceBase) return raw;
|
|
49
45
|
const { id, entries } = blindCast(super.hydrateSqlNamespaceEntry(nsId, raw));
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (rawTypeSlot !== null && typeof rawTypeSlot === "object" && !Array.isArray(rawTypeSlot)) {
|
|
55
|
-
const enumFactory = this.entityTypeRegistry.get("postgres-enum");
|
|
56
|
-
typeSlot = Object.fromEntries(Object.entries(rawTypeSlot).map(([name, entry]) => [name, blindCast(enumFactory !== void 0 ? enumFactory(entry) : entry)]));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const emptyTables = Object.keys(entries.table).length === 0;
|
|
60
|
-
const emptyTypes = !typeSlot || Object.keys(typeSlot).length === 0;
|
|
61
|
-
if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyTypes) return PostgresSchema.unbound;
|
|
46
|
+
const valueSetSlot = entries["valueSet"];
|
|
47
|
+
const hasValueSets = valueSetSlot !== void 0 && Object.keys(valueSetSlot).length > 0;
|
|
48
|
+
const emptyTables = Object.keys(entries["table"] ?? {}).length === 0;
|
|
49
|
+
if (id === UNBOUND_NAMESPACE_ID && emptyTables && !hasValueSets) return PostgresSchema.unbound;
|
|
62
50
|
return new PostgresSchema({
|
|
63
51
|
id,
|
|
64
52
|
entries: {
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
...entries,
|
|
54
|
+
table: entries["table"] ?? {},
|
|
55
|
+
...hasValueSets ? { valueSet: valueSetSlot } : {}
|
|
67
56
|
}
|
|
68
57
|
});
|
|
69
58
|
}
|
|
@@ -74,7 +63,7 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
74
63
|
else namespacesJson[nsId] = {
|
|
75
64
|
id: nsId,
|
|
76
65
|
kind: nsId === UNBOUND_NAMESPACE_ID ? "postgres-unbound-schema" : "postgres-schema",
|
|
77
|
-
entries: { table: Object.fromEntries(Object.entries(ns.entries.table).map(([tableName, table]) => [tableName, this.serializeJsonValue(table)])) }
|
|
66
|
+
entries: { table: Object.fromEntries(Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [tableName, this.serializeJsonValue(table)])) }
|
|
78
67
|
};
|
|
79
68
|
const storageOut = {
|
|
80
69
|
storageHash: String(storage.storageHash),
|
|
@@ -92,15 +81,16 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
92
81
|
}
|
|
93
82
|
serializePostgresNamespace(ns, isUnboundSlot) {
|
|
94
83
|
const tablesOut = {};
|
|
95
|
-
for (const [tableName, table] of Object.entries(ns.
|
|
96
|
-
const
|
|
97
|
-
|
|
84
|
+
for (const [tableName, table] of Object.entries(ns.table)) tablesOut[tableName] = this.serializeJsonValue(table);
|
|
85
|
+
const valueSetEntries = ns.valueSet;
|
|
86
|
+
const valueSetOut = {};
|
|
87
|
+
if (valueSetEntries !== void 0) for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) valueSetOut[valueSetName] = blindCast(this.serializeJsonValue(valueSet));
|
|
98
88
|
return {
|
|
99
89
|
id: ns.id,
|
|
100
90
|
kind: isUnboundSlot ? "postgres-unbound-schema" : "postgres-schema",
|
|
101
91
|
entries: {
|
|
102
92
|
table: tablesOut,
|
|
103
|
-
|
|
93
|
+
...Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}
|
|
104
94
|
}
|
|
105
95
|
};
|
|
106
96
|
}
|
|
@@ -111,4 +101,4 @@ var PostgresContractSerializer = class extends SqlContractSerializerBase {
|
|
|
111
101
|
//#endregion
|
|
112
102
|
export { PostgresContractSerializer as t };
|
|
113
103
|
|
|
114
|
-
//# sourceMappingURL=postgres-contract-serializer-
|
|
104
|
+
//# sourceMappingURL=postgres-contract-serializer-CyAe8ZFv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-contract-serializer-CyAe8ZFv.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.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 Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceTablesInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n typeof (output as AuthoringEntityTypeFactoryOutput).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 `hydrateEntriesKind`.\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() {\n const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n super(storageTypesHydrators);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = blindCast<\n SqlNamespaceTablesInput,\n 'super.hydrateSqlNamespaceEntry returns SqlNamespaceTablesInput when raw is not a NamespaceBase'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n const valueSetSlot = entries['valueSet'];\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n const emptyTables = Object.keys(entries['table'] ?? {}).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && !hasValueSets) {\n return PostgresSchema.unbound;\n }\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.serializeJsonValue(table) as JsonObject,\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.serializeJsonValue(entry) as JsonObject;\n }\n storageOut['types'] = typesOut;\n }\n return {\n ...rest,\n storage: storageOut,\n } as unknown as JsonObject;\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.serializeJsonValue(table) as JsonObject;\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] = blindCast<\n JsonObject,\n 'serializeJsonValue round-trips the value-set node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(valueSet));\n }\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 },\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,OAAQ,OAA4C,YAAY;AAEpE;;;;;;;AAQA,SAAS,6BACP,WACgD;CAChD,MAAM,2BAAW,IAAI,IAAuC;CAC5D,MAAM,QAAQ,SAA6C;EACzD,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GAAG;GACvC,IAAI,gCAAgC,KAAK,GAAG;IAC1C,IAAI,mCAAmC,MAAM,MAAM,GAAG;KACpD,MAAM,EAAE,YAAY,MAAM;KAC1B,SAAS,IAAI,MAAM,gBAAgB,QAAQ,QAAQ,KAAK,sBAAsB,CAAC;IACjF;IACA;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,KAAK,KAAK;EAEd;CACF;CACA,KAAK,SAAS;CACd,OAAO;AACT;AAEA,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,cAAc;EACZ,MAAM,wBAAwB,6BAA6B,4BAA4B;EACvF,MAAM,qBAAqB;CAC7B;CAEA,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAMT,MAAM,EAAE,IAAI,YAJK,UAGf,MAAM,yBAAyB,MAAM,GAAG,CACX;EAE/B,MAAM,eAAe,QAAQ;EAC7B,MAAM,eAAe,iBAAiB,KAAA,KAAa,OAAO,KAAK,YAAY,CAAC,CAAC,SAAS;EACtF,MAAM,cAAc,OAAO,KAAK,QAAQ,YAAY,CAAC,CAAC,CAAC,CAAC,WAAW;EACnE,IAAI,OAAO,wBAAwB,eAAe,CAAC,cACjD,OAAO,eAAe;EAExB,OAAO,IAAI,eAAe;GACxB;GACA,SAAS;IACP,GAAG;IACH,OAAO,QAAQ,YAAY,CAAC;IAC5B,GAAI,eAAe,EAAE,UAAU,aAAa,IAAI,CAAC;GACnD;EACF,CAAC;CACH;CAEA,kBAA2B,UAA4C;EACrE,MAAM,EAAE,SAAS,GAAG,SAAS;EAC7B,MAAM,iBAA6C,CAAC;EACpD,KAAK,MAAM,CAAC,MAAM,OAAO,OAAO,QAAQ,QAAQ,UAAU,GACxD,IAAI,iBAAiB,EAAE,GACrB,eAAe,QAAQ,KAAK,2BAA2B,IAAI,GAAG,OAAO,oBAAoB;OAGzF,eAAe,QAAQ;GACrB,IAAI;GACJ,MAHoB,SAAS,uBAGP,4BAA4B;GAClD,SAAS,EACP,OAAO,OAAO,YACZ,OAAO,QAAQ,GAAG,QAAQ,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,WAAW,CACjE,WACA,KAAK,mBAAmB,KAAK,CAC/B,CAAC,CACH,EACF;EACF;EAGJ,MAAM,aAAsC;GAC1C,aAAa,OAAO,QAAQ,WAAW;GACvC,YAAY;EACd;EACA,IAAI,QAAQ,UAAU,KAAA,GAAW;GAC/B,MAAM,WAAuC,CAAC;GAC9C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,KAAK,GACtD,SAAS,QAAQ,KAAK,mBAAmB,KAAK;GAEhD,WAAW,WAAW;EACxB;EACA,OAAO;GACL,GAAG;GACH,SAAS;EACX;CACF;CAEA,2BAAmC,IAAoB,eAAoC;EACzF,MAAM,YAAwC,CAAC;EAC/C,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,KAAK,GACtD,UAAU,aAAa,KAAK,mBAAmB,KAAK;EAEtD,MAAM,kBAAkB,GAAG;EAC3B,MAAM,cAA0C,CAAC;EACjD,IAAI,oBAAoB,KAAA,GACtB,KAAK,MAAM,CAAC,cAAc,aAAa,OAAO,QAAQ,eAAe,GACnE,YAAY,gBAAgB,UAG1B,KAAK,mBAAmB,QAAQ,CAAC;EAGvC,OAAO;GACL,IAAI,GAAG;GACP,MAAM,gBAAgB,4BAA4B;GAClD,SAAS;IACP,OAAO;IACP,GAAI,OAAO,KAAK,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,YAAY,IAAI,CAAC;GACzE;EACF;CACF;CAEA,mBAA2B,OAAyB;EAClD,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;CACzC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
|
-
import { n as DataTransformOptions } from "./data-transform-
|
|
2
|
+
import { n as DataTransformOptions } from "./data-transform-DDgWdB5o.mjs";
|
|
3
3
|
import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
|
|
4
4
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
5
5
|
import { SqlStorage } from "@prisma-next/sql-contract/types";
|
|
@@ -44,7 +44,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
44
44
|
* supplies the stored control adapter. Authors call this from inside
|
|
45
45
|
* `get operations()`; the adapter argument is hidden from the call site.
|
|
46
46
|
*/
|
|
47
|
-
protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
47
|
+
protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
48
48
|
/**
|
|
49
49
|
* Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
|
|
50
50
|
* the supplied options and lowers it through the stored control adapter.
|
|
@@ -56,7 +56,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
56
56
|
readonly ifNotExists?: boolean;
|
|
57
57
|
readonly columns: readonly DdlColumn[];
|
|
58
58
|
readonly constraints?: readonly DdlTableConstraint[];
|
|
59
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
59
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
60
60
|
/**
|
|
61
61
|
* Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
|
|
62
62
|
* the supplied options and lowers it through the stored control adapter.
|
|
@@ -65,8 +65,13 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
|
|
|
65
65
|
protected createSchema(options: {
|
|
66
66
|
readonly schema: string;
|
|
67
67
|
readonly ifNotExists?: boolean;
|
|
68
|
-
}): SqlMigrationPlanOperation<PostgresPlanTargetDetails
|
|
68
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
69
|
+
protected addColumn(options: {
|
|
70
|
+
readonly schema?: string;
|
|
71
|
+
readonly table: string;
|
|
72
|
+
readonly column: DdlColumn;
|
|
73
|
+
}): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
|
|
69
74
|
}
|
|
70
75
|
//#endregion
|
|
71
76
|
export { PostgresMigration as t };
|
|
72
|
-
//# sourceMappingURL=postgres-migration-
|
|
77
|
+
//# sourceMappingURL=postgres-migration-DLXL0GBf.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-DLXL0GBf.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,SAAA,CAC9C,yBAAA;EAAA,SAGS,QAAA;EAmEL;;;;;;EAAA,mBA3De,cAAA,EAAgB,iBAAA;cAEvB,KAAA,GAAQ,YAAA;EAd0B;;;;;EAAA,UA6BpC,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAnBjB;;;;;EAAA,UA+BV,WAAA,CAAY,OAAA;IAAA,SACX,MAAA;IAAA,SACA,KAAA;IAAA,SACA,WAAA;IAAA,SACA,OAAA,WAAkB,SAAA;IAAA,SAClB,WAAA,YAAuB,kBAAA;EAAA,IAC9B,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAlB3B;;;;;EAAA,UAmCD,YAAA,CAAa,OAAA;IAAA,SACZ,MAAA;IAAA,SACA,WAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAAA,UAO5B,SAAA,CAAU,OAAA;IAAA,SACT,MAAA;IAAA,SACA,KAAA;IAAA,SACA,MAAA,EAAQ,SAAA;EAAA,IACf,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as CreateSchemaCall, n as AddColumnCall, u as CreateTableCall } from "./op-factory-call-CjR846f7.mjs";
|
|
2
2
|
import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
|
|
3
|
-
import { t as dataTransform } from "./data-transform-
|
|
3
|
+
import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
|
|
4
4
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
5
5
|
import { Migration } from "@prisma-next/family-sql/migration";
|
|
6
6
|
//#region src/core/migrations/postgres-migration.ts
|
|
@@ -64,8 +64,12 @@ var PostgresMigration = class extends Migration {
|
|
|
64
64
|
if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
|
|
65
65
|
return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);
|
|
66
66
|
}
|
|
67
|
+
addColumn(options) {
|
|
68
|
+
if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
|
|
69
|
+
return new AddColumnCall(options.schema ?? UNBOUND_NAMESPACE_ID, options.table, options.column).toOp(this.controlAdapter);
|
|
70
|
+
}
|
|
67
71
|
};
|
|
68
72
|
//#endregion
|
|
69
73
|
export { PostgresMigration as t };
|
|
70
74
|
|
|
71
|
-
//# sourceMappingURL=postgres-migration-
|
|
75
|
+
//# sourceMappingURL=postgres-migration-dG-J0aI8.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-migration-dG-J0aI8.mjs","names":["SqlMigration"],"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 { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\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 { AddColumnCall, CreateSchemaCall, CreateTableCall } from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\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 */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\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 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 * 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 ?? UNBOUND_NAMESPACE_ID,\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(\n options.schema ?? UNBOUND_NAMESPACE_ID,\n options.table,\n options.column,\n ).toOp(this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;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;EAE3C,OAAO,IAAI,gBACT,QAAQ,UAAU,sBAClB,QAAQ,OACR,QAAQ,SACR,QAAQ,WACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;;;;;;CAOA,aAAuB,SAG2C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,iBAAiB,QAAQ,MAAM,CAAC,CAAC,KAAK,KAAK,cAAc;CACtE;CAEA,UAAoB,SAI8C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,cACT,QAAQ,UAAU,sBAClB,QAAQ,OACR,QAAQ,MACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;AACF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
|
|
2
1
|
import { n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
2
|
+
import { blindCast } from "@prisma-next/utils/casts";
|
|
3
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
3
4
|
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode } from "@prisma-next/framework-components/ir";
|
|
4
|
-
import { StorageTable } from "@prisma-next/sql-contract/types";
|
|
5
|
+
import { StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
5
6
|
//#region src/core/postgres-schema.ts
|
|
6
7
|
/**
|
|
7
8
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -9,7 +10,7 @@ import { StorageTable } from "@prisma-next/sql-contract/types";
|
|
|
9
10
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
10
11
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
11
12
|
*
|
|
12
|
-
* `entries` holds entity-kind
|
|
13
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
13
14
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
14
15
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
15
16
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -31,9 +32,22 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
31
32
|
constructor(input) {
|
|
32
33
|
super();
|
|
33
34
|
this.id = input.id;
|
|
35
|
+
const carried = {};
|
|
36
|
+
let table = Object.freeze({});
|
|
37
|
+
let valueSet;
|
|
38
|
+
for (const [kind, rawMap] of Object.entries(input.entries)) if (kind === "table") {
|
|
39
|
+
const tableMap = {};
|
|
40
|
+
for (const [name, v] of Object.entries(blindCast(rawMap))) tableMap[name] = new StorageTable(v);
|
|
41
|
+
table = Object.freeze(tableMap);
|
|
42
|
+
} else if (kind === "valueSet") {
|
|
43
|
+
const vsMap = {};
|
|
44
|
+
for (const [name, v] of Object.entries(blindCast(rawMap))) vsMap[name] = new StorageValueSet(v);
|
|
45
|
+
if (Object.keys(vsMap).length > 0) valueSet = Object.freeze(vsMap);
|
|
46
|
+
} else carried[kind] = Object.freeze(rawMap);
|
|
34
47
|
this.entries = Object.freeze({
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
...carried,
|
|
49
|
+
table,
|
|
50
|
+
...ifDefined("valueSet", valueSet)
|
|
37
51
|
});
|
|
38
52
|
Object.defineProperty(this, "kind", {
|
|
39
53
|
value: "schema",
|
|
@@ -43,6 +57,12 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
43
57
|
});
|
|
44
58
|
freezeNode(this);
|
|
45
59
|
}
|
|
60
|
+
get table() {
|
|
61
|
+
return this.entries["table"] ?? Object.freeze({});
|
|
62
|
+
}
|
|
63
|
+
get valueSet() {
|
|
64
|
+
return this.entries["valueSet"];
|
|
65
|
+
}
|
|
46
66
|
/**
|
|
47
67
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
48
68
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -119,10 +139,7 @@ var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
|
|
|
119
139
|
constructor(input) {
|
|
120
140
|
super(input ?? {
|
|
121
141
|
id: UNBOUND_NAMESPACE_ID,
|
|
122
|
-
entries: {
|
|
123
|
-
table: {},
|
|
124
|
-
type: {}
|
|
125
|
-
}
|
|
142
|
+
entries: { table: {} }
|
|
126
143
|
});
|
|
127
144
|
}
|
|
128
145
|
qualifier() {
|
|
@@ -159,12 +176,12 @@ function isPostgresSchema(ns) {
|
|
|
159
176
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
160
177
|
* be value-stable for a given input set.
|
|
161
178
|
*/
|
|
162
|
-
function postgresCreateNamespace(input
|
|
179
|
+
function postgresCreateNamespace(input) {
|
|
163
180
|
const schemaInput = {
|
|
164
181
|
id: input.id,
|
|
165
182
|
entries: {
|
|
166
|
-
|
|
167
|
-
|
|
183
|
+
...input.entries,
|
|
184
|
+
table: input.entries["table"] ?? {}
|
|
168
185
|
}
|
|
169
186
|
};
|
|
170
187
|
if (input.id === UNBOUND_NAMESPACE_ID) return new PostgresUnboundSchema(schemaInput);
|
|
@@ -173,4 +190,4 @@ function postgresCreateNamespace(input, enumTypes) {
|
|
|
173
190
|
//#endregion
|
|
174
191
|
export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
|
|
175
192
|
|
|
176
|
-
//# sourceMappingURL=postgres-schema-
|
|
193
|
+
//# sourceMappingURL=postgres-schema-CTKYiTHu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-schema-CTKYiTHu.mjs","names":[],"sources":["../src/core/postgres-schema.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport {\n type SqlNamespaceTablesInput,\n type SqlStorage,\n StorageTable,\n type StorageTableInput,\n StorageValueSet,\n type StorageValueSetInput,\n} from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Postgres target `Namespace` concretion — a Postgres schema (`CREATE\n * SCHEMA …`). Each Postgres `SqlStorage` carries a\n * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by\n * the Postgres PSL interpreter from `namespace { … }` AST buckets.\n *\n * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier\n * emission is the rendering seam: DDL / SQL emission asks the namespace\n * for its qualifier (`\"<schema>\"`) or for a qualified table name\n * (`\"<schema>\".\"<table>\"`) and consumes the result polymorphically.\n * The unbound singleton below overrides these methods to elide the\n * prefix entirely — call sites stay polymorphic and never branch on\n * `id === UNBOUND_NAMESPACE_ID`.\n */\nexport class PostgresSchema extends NamespaceBase {\n /**\n * Stable singleton reference for the late-bound slot. Materialised\n * lazily below the singleton subclass declaration so the static\n * initialiser sees the subclass before assigning. Consumers always\n * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`\n * — same identity).\n */\n static unbound: PostgresUnboundSchema;\n\n declare readonly kind: 'schema';\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n\n const carried: Record<string, Readonly<Record<string, unknown>>> = {};\n let table: Readonly<Record<string, StorageTable>> = Object.freeze({});\n let valueSet: Readonly<Record<string, StorageValueSet>> | undefined;\n for (const [kind, rawMap] of Object.entries(input.entries)) {\n if (kind === 'table') {\n const tableMap: Record<string, StorageTable> = {};\n for (const [name, v] of Object.entries(\n blindCast<\n Record<string, StorageTableInput>,\n 'entries[table] holds StorageTableInput by construction'\n >(rawMap),\n )) {\n tableMap[name] = new StorageTable(v);\n }\n table = Object.freeze(tableMap);\n } else if (kind === 'valueSet') {\n const vsMap: Record<string, StorageValueSet> = {};\n for (const [name, v] of Object.entries(\n blindCast<\n Record<string, StorageValueSetInput>,\n 'entries[valueSet] holds StorageValueSetInput by construction'\n >(rawMap),\n )) {\n vsMap[name] = new StorageValueSet(v);\n }\n if (Object.keys(vsMap).length > 0) {\n valueSet = Object.freeze(vsMap);\n }\n } else {\n carried[kind] = Object.freeze(rawMap);\n }\n }\n\n this.entries = Object.freeze({\n ...carried,\n table,\n ...ifDefined('valueSet', valueSet),\n });\n Object.defineProperty(this, 'kind', {\n value: 'schema',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries['table'] ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries['valueSet'] as Readonly<Record<string, StorageValueSet>> | undefined;\n }\n\n /**\n * The bare schema qualifier as it would appear in a rendered SQL\n * fragment (already quoted). The unbound-schema singleton overrides\n * this to return `''`.\n */\n qualifier(): string {\n return `\"${this.id}\"`;\n }\n\n /**\n * Qualify a table name with the schema prefix\n * (`\"<schema>\".\"<table>\"`). The unbound-schema singleton overrides\n * this to emit just `\"<table>\"` so the resolved DDL is unqualified\n * and `search_path` decides where the object lands at runtime.\n */\n qualifyTable(tableName: string): string {\n return `\"${this.id}\".\"${tableName}\"`;\n }\n\n /**\n * Render a SQL string-literal containing the qualified-name form\n * suitable for `to_regclass(...)` arguments (e.g. `'\"public\".\"user\"'`).\n * The unbound singleton overrides this to elide the schema prefix\n * (`'\"user\"'`) so `search_path` resolves the object at runtime.\n */\n regclassLiteral(name: string): string {\n return `'${escapeLiteral(this.qualifyTable(name))}'`;\n }\n\n /**\n * Render a SQL expression that evaluates to this namespace's schema\n * name at runtime, ready to drop into a `WHERE table_schema = …` /\n * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL\n * literal (`'public'`); the unbound singleton overrides this to emit\n * `current_schema()` so catalog queries match whichever schema the\n * connection's `search_path` resolved at runtime.\n */\n schemaSqlExpression(): string {\n return `'${escapeLiteral(this.id)}'`;\n }\n\n /**\n * The bare schema name a DDL planner should target when emitting\n * statements that need to identify this namespace in the live\n * database (e.g. `CREATE TABLE \"<ddlSchemaName>\".\"<table>\" …`,\n * catalog filters, planner conflict lookups). Named schemas resolve\n * to their own id. The `PostgresUnboundSchema` singleton inherits\n * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch\n * through `qualifyTableName` / `toRegclassLiteral` route through the\n * polymorphic `PostgresUnboundSchema` overrides and produce\n * unqualified (search-path-resolved) output automatically.\n */\n ddlSchemaName(_storage: SqlStorage): string {\n return this.id;\n }\n}\n\n/**\n * Singleton subclass for the reserved sentinel namespace id\n * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding\n * the connection's `search_path` resolves at runtime. Overrides\n * qualifier emission to elide the schema prefix; call sites that consume\n * `qualifier()` / `qualifyTable()` get unqualified output without\n * branching on the namespace id.\n *\n * This is the target-side materialization of \"the framework provides\n * affordances; targets implement specifics\": the framework names the\n * sentinel; Postgres decides what late-bound means here (the table\n * name, naked — the schema is supplied by the live connection's\n * `search_path`).\n *\n * `ddlSchemaName` is inherited from `PostgresSchema` and returns\n * `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,\n * `toRegclassLiteral`) route through the polymorphic factory and\n * produce unqualified output automatically.\n */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID, entries: { table: {} } });\n }\n\n override qualifier(): string {\n return '';\n }\n\n override qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n\n override schemaSqlExpression(): string {\n return 'current_schema()';\n }\n}\n\nPostgresSchema.unbound = PostgresUnboundSchema.instance;\n\n/**\n * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`\n * so callers can dispatch to the polymorphic emission methods without\n * branching at the call site. Uses the structural `kind` discriminator\n * (`'schema'`) rather than `instanceof` so the check survives realm /\n * bundle / hot-reload boundaries — matching the rest of the IR's\n * narrowing convention. `PostgresUnboundSchema` passes through because\n * it inherits the same `kind: 'schema'` from `PostgresSchema`.\n */\nexport function isPostgresSchema(ns: unknown): ns is PostgresSchema {\n return (ns as { kind?: unknown } | null | undefined)?.kind === 'schema';\n}\n\n/**\n * Target-supplied `Namespace` factory the Postgres target plumbs\n * through `defineContract({ createNamespace })` and the SQL PSL\n * interpreter. Returns the unbound singleton for the framework\n * sentinel and a fresh `PostgresSchema` for any other coordinate.\n *\n * The factory has no per-call state — every named id deterministically\n * maps to a distinct schema instance — so callers can pass it through\n * by reference and trust the resulting `SqlStorage.namespaces` map to\n * be value-stable for a given input set.\n */\nexport function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema {\n const schemaInput: PostgresSchemaInput = {\n id: input.id,\n entries: {\n ...input.entries,\n table: input.entries['table'] ?? {},\n },\n };\n if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(schemaInput);\n }\n return new PostgresSchema(schemaInput);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,IAAa,iBAAb,cAAoC,cAAc;;;;;;;;CAQhD,OAAO;CAGP;CACA;CAEA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAEhB,MAAM,UAA6D,CAAC;EACpE,IAAI,QAAgD,OAAO,OAAO,CAAC,CAAC;EACpE,IAAI;EACJ,KAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,MAAM,OAAO,GACvD,IAAI,SAAS,SAAS;GACpB,MAAM,WAAyC,CAAC;GAChD,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAC7B,UAGE,MAAM,CACV,GACE,SAAS,QAAQ,IAAI,aAAa,CAAC;GAErC,QAAQ,OAAO,OAAO,QAAQ;EAChC,OAAO,IAAI,SAAS,YAAY;GAC9B,MAAM,QAAyC,CAAC;GAChD,KAAK,MAAM,CAAC,MAAM,MAAM,OAAO,QAC7B,UAGE,MAAM,CACV,GACE,MAAM,QAAQ,IAAI,gBAAgB,CAAC;GAErC,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,GAC9B,WAAW,OAAO,OAAO,KAAK;EAElC,OACE,QAAQ,QAAQ,OAAO,OAAO,MAAM;EAIxC,KAAK,UAAU,OAAO,OAAO;GAC3B,GAAG;GACH;GACA,GAAG,UAAU,YAAY,QAAQ;EACnC,CAAC;EACD,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;EAChB,CAAC;EACD,WAAW,IAAI;CACjB;CAEA,IAAI,QAAgD;EAClD,OAAO,KAAK,QAAQ,YAAY,OAAO,OAAO,CAAC,CAAC;CAClD;CAEA,IAAI,WAAkE;EACpE,OAAO,KAAK,QAAQ;CACtB;;;;;;CAOA,YAAoB;EAClB,OAAO,IAAI,KAAK,GAAG;CACrB;;;;;;;CAQA,aAAa,WAA2B;EACtC,OAAO,IAAI,KAAK,GAAG,KAAK,UAAU;CACpC;;;;;;;CAQA,gBAAgB,MAAsB;EACpC,OAAO,IAAI,cAAc,KAAK,aAAa,IAAI,CAAC,EAAE;CACpD;;;;;;;;;CAUA,sBAA8B;EAC5B,OAAO,IAAI,cAAc,KAAK,EAAE,EAAE;CACpC;;;;;;;;;;;;CAaA,cAAc,UAA8B;EAC1C,OAAO,KAAK;CACd;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,wBAAb,MAAa,8BAA8B,eAAe;CACxD,OAAgB,WAAkC,IAAI,sBAAsB;CAE5E,YAAY,OAA6B;EACvC,MAAM,SAAS;GAAE,IAAI;GAAsB,SAAS,EAAE,OAAO,CAAC,EAAE;EAAE,CAAC;CACrE;CAEA,YAA6B;EAC3B,OAAO;CACT;CAEA,aAAsB,WAA2B;EAC/C,OAAO,IAAI,UAAU;CACvB;CAEA,sBAAuC;EACrC,OAAO;CACT;AACF;AAEA,eAAe,UAAU,sBAAsB;;;;;;;;;;AAW/C,SAAgB,iBAAiB,IAAmC;CAClE,OAAQ,IAA8C,SAAS;AACjE;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,OAAgD;CACtF,MAAM,cAAmC;EACvC,IAAI,MAAM;EACV,SAAS;GACP,GAAG,MAAM;GACT,OAAO,MAAM,QAAQ,YAAY,CAAC;EACpC;CACF;CACA,IAAI,MAAM,OAAO,sBACf,OAAO,IAAI,sBAAsB,WAAW;CAE9C,OAAO,IAAI,eAAe,WAAW;AACvC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
2
|
+
import { isThenable } from "@prisma-next/utils/promise";
|
|
2
3
|
//#region src/core/migrations/render-ops.ts
|
|
3
4
|
/**
|
|
4
5
|
* Asserts an op materialised by an `OpFactoryCall` targets postgres. The
|
|
@@ -8,17 +9,21 @@ import { blindCast } from "@prisma-next/utils/casts";
|
|
|
8
9
|
* place to fail loudly with op metadata (`id` + `target.id`).
|
|
9
10
|
*/
|
|
10
11
|
function assertPostgresOp(op, callFactoryName) {
|
|
11
|
-
const targetId = op.target?.id;
|
|
12
|
+
const targetId = blindCast(op).target?.id;
|
|
12
13
|
if (targetId !== "postgres") throw new Error(`renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`);
|
|
13
14
|
}
|
|
14
15
|
function renderOps(calls, lowerer) {
|
|
15
16
|
return calls.map((c) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const opOrPromise = blindCast(c).toOp(lowerer);
|
|
18
|
+
if (isThenable(opOrPromise)) return opOrPromise.then((op) => {
|
|
19
|
+
assertPostgresOp(op, c.factoryName);
|
|
20
|
+
return op;
|
|
21
|
+
});
|
|
22
|
+
assertPostgresOp(opOrPromise, c.factoryName);
|
|
23
|
+
return opOrPromise;
|
|
19
24
|
});
|
|
20
25
|
}
|
|
21
26
|
//#endregion
|
|
22
27
|
export { renderOps as t };
|
|
23
28
|
|
|
24
|
-
//# sourceMappingURL=render-ops-
|
|
29
|
+
//# sourceMappingURL=render-ops-BREh1kHe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-ops-BREh1kHe.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\nimport type {\n MigrationPlanOperation,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { isThenable } from '@prisma-next/utils/promise';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string): asserts op is Op {\n const targetId = blindCast<\n { target?: { id?: string } },\n 'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'\n >(op).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(\n calls: readonly OpFactoryCall[],\n lowerer?: ExecuteRequestLowerer,\n): (Op | Promise<Op>)[] {\n return calls.map((c) => {\n const opOrPromise = blindCast<\n { toOp(lowerer?: ExecuteRequestLowerer): Op | Promise<Op> },\n 'PG OpFactoryCall.toOp accepts an optional ExecuteRequestLowerer; the framework interface omits it because not all targets need a lowerer — the PG target overrides with this extended signature'\n >(c).toOp(lowerer);\n if (isThenable(opOrPromise)) {\n return opOrPromise.then((op) => {\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n }\n assertPostgresOp(opOrPromise, c.factoryName);\n return opOrPromise;\n });\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,iBAAiB,IAA4B,iBAA2C;CAC/F,MAAM,WAAW,UAGf,EAAE,CAAC,CAAC,QAAQ;CACd,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAChI;AAEJ;AAEA,SAAgB,UACd,OACA,SACsB;CACtB,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,cAAc,UAGlB,CAAC,CAAC,CAAC,KAAK,OAAO;EACjB,IAAI,WAAW,WAAW,GACxB,OAAO,YAAY,MAAM,OAAO;GAC9B,iBAAiB,IAAI,EAAE,WAAW;GAClC,OAAO;EACT,CAAC;EAEH,iBAAiB,aAAa,EAAE,WAAW;EAC3C,OAAO;CACT,CAAC;AACH"}
|
package/dist/render-ops.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
|
|
2
2
|
import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
|
|
3
3
|
import { OpFactoryCall } from "@prisma-next/framework-components/control";
|
|
4
|
-
import {
|
|
4
|
+
import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
|
|
5
5
|
|
|
6
6
|
//#region src/core/migrations/render-ops.d.ts
|
|
7
7
|
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
8
|
-
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?:
|
|
8
|
+
declare function renderOps(calls: readonly OpFactoryCall[], lowerer?: ExecuteRequestLowerer): (Op | Promise<Op>)[];
|
|
9
9
|
//#endregion
|
|
10
10
|
export { renderOps };
|
|
11
11
|
//# sourceMappingURL=render-ops.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;KAUK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,iBAqBpB,SAAA,CACd,KAAA,WAAgB,aAAA,IAChB,OAAA,GAAU,qBAAA,IACR,EAAA,GAAK,OAAA,CAAQ,EAAA"}
|
package/dist/render-ops.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as renderOps } from "./render-ops-
|
|
1
|
+
import { t as renderOps } from "./render-ops-BREh1kHe.mjs";
|
|
2
2
|
export { renderOps };
|
package/dist/runtime.d.mts.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":";;;;;;;;;cAiEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;;YAM9D,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,SAAA,GAAY,MAAA,oBAChB,SAAA,GAAY,uBAAA;EA0BN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;EAAA,QAuCpD,0BAAA;EAAA,QAyBA,kBAAA;AAAA;;;UC3JO,6BAAA,SAAsC,qBAAqB;;;;;ADwD5E;;cChDM,+BAAA,EAAiC,uBAAA,oBAGrC,6BAAA;EAAA,SAES,MAAA,iBAAuB,kBAAA;AAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-
|
|
2
|
-
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-
|
|
1
|
+
import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-e5f2tscJ.mjs";
|
|
2
|
+
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-CyAe8ZFv.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
|
|
@@ -4,24 +4,6 @@ import { ReferentialAction } from "@prisma-next/sql-contract/types";
|
|
|
4
4
|
|
|
5
5
|
//#region src/core/migrations/operations/shared.d.ts
|
|
6
6
|
type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
|
|
7
|
-
/**
|
|
8
|
-
* Literal-args shape for a column definition consumed by `addColumn` and
|
|
9
|
-
* similar operations. Fully materialized: codec expansion and default
|
|
10
|
-
* rendering have already happened in the wrapper.
|
|
11
|
-
*
|
|
12
|
-
* - `typeSql` is the column's DDL type string (e.g. `"integer"`, `"SERIAL"`,
|
|
13
|
-
* `"varchar(100)"`), already produced by `buildColumnTypeSql` in the
|
|
14
|
-
* call-factory wrapper.
|
|
15
|
-
* - `defaultSql` is the full `DEFAULT …` clause (e.g. `"DEFAULT 42"`) or an
|
|
16
|
-
* empty string when the column has no default, matching
|
|
17
|
-
* `buildColumnDefaultSql`'s output.
|
|
18
|
-
*/
|
|
19
|
-
interface ColumnSpec {
|
|
20
|
-
readonly name: string;
|
|
21
|
-
readonly typeSql: string;
|
|
22
|
-
readonly defaultSql: string;
|
|
23
|
-
readonly nullable: boolean;
|
|
24
|
-
}
|
|
25
7
|
/**
|
|
26
8
|
* Literal-args shape for a foreign key definition. `references.schema`
|
|
27
9
|
* carries the target table's namespace (schema) coordinate so the rendered
|
|
@@ -39,5 +21,5 @@ interface ForeignKeySpec {
|
|
|
39
21
|
readonly onUpdate?: ReferentialAction;
|
|
40
22
|
}
|
|
41
23
|
//#endregion
|
|
42
|
-
export {
|
|
43
|
-
//# sourceMappingURL=shared-
|
|
24
|
+
export { Op as n, ForeignKeySpec as t };
|
|
25
|
+
//# sourceMappingURL=shared-jcsbXxiW.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-jcsbXxiW.d.mts","names":[],"sources":["../src/core/migrations/operations/shared.ts"],"mappings":";;;;;KAMY,EAAA,GAAK,yBAAyB,CAAC,yBAAA;;;;AAmCJ;;UATtB,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;IAAA,SACE,MAAA;IAAA,SACA,KAAA;IAAA,SACA,OAAA;EAAA;EAAA,SAEF,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAiB;AAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { n as PostgresEnumTypeInput, t as PostgresEnumType } from "./postgres-enum-type-BVn63a89.mjs";
|
|
2
1
|
import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
|
|
3
2
|
import { NamespaceBase } from "@prisma-next/framework-components/ir";
|
|
4
|
-
import {
|
|
3
|
+
import { SqlNamespaceTablesInput, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
5
4
|
|
|
6
5
|
//#region src/core/postgres-schema.d.ts
|
|
7
6
|
interface PostgresSchemaInput {
|
|
8
7
|
readonly id: string;
|
|
9
|
-
readonly entries:
|
|
10
|
-
readonly table: Record<string, StorageTable | StorageTableInput>;
|
|
11
|
-
readonly type: Record<string, PostgresEnumType | PostgresEnumTypeInput>;
|
|
12
|
-
};
|
|
8
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
11
|
* Postgres target `Namespace` concretion — a Postgres schema (`CREATE
|
|
@@ -17,7 +13,7 @@ interface PostgresSchemaInput {
|
|
|
17
13
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
18
14
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
19
15
|
*
|
|
20
|
-
* `entries` holds entity-kind
|
|
16
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
21
17
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
22
18
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
23
19
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -36,11 +32,10 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
36
32
|
static unbound: PostgresUnboundSchema;
|
|
37
33
|
readonly kind: 'schema';
|
|
38
34
|
readonly id: string;
|
|
39
|
-
readonly entries: Readonly<
|
|
40
|
-
readonly table: Readonly<Record<string, StorageTable>>;
|
|
41
|
-
readonly type: Readonly<Record<string, PostgresEnumType>>;
|
|
42
|
-
}>;
|
|
35
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
43
36
|
constructor(input: PostgresSchemaInput);
|
|
37
|
+
get table(): Readonly<Record<string, StorageTable>>;
|
|
38
|
+
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
44
39
|
/**
|
|
45
40
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
46
41
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -120,7 +115,7 @@ declare class PostgresUnboundSchema extends PostgresSchema {
|
|
|
120
115
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
121
116
|
* be value-stable for a given input set.
|
|
122
117
|
*/
|
|
123
|
-
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput
|
|
118
|
+
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema;
|
|
124
119
|
//#endregion
|
|
125
|
-
export { type PostgresColumnDefault,
|
|
120
|
+
export { type PostgresColumnDefault, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
126
121
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/core/postgres-schema.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/core/postgres-schema.ts"],"mappings":";;;;;UAiBiB,mBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;;;;;;;;;;;cAiBxC,cAAA,SAAuB,aAAA;EAjBuB;AAiB3D;;;;;;EAjB2D,OAyBlD,OAAA,EAAS,qBAAA;EAAA,SAEC,IAAA;EAAA,SACR,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;cAEvC,KAAA,EAAO,mBAAA;EAAA,IAmDf,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,IAIjC,QAAA,IAAY,QAAA,CAAS,MAAA,SAAe,eAAA;EAAf;;;;;EASzB,SAAA;EA9EkC;;;;;;EAwFlC,YAAA,CAAa,SAAA;EA5Ec;;;;;;EAsF3B,eAAA,CAAgB,IAAA;EAjCH;;;;;;;;EA6Cb,mBAAA;EAtBa;;;;;;;;AAqCqB;AAwBpC;;EAxBE,aAAA,CAAc,QAAA,EAAU,UAAA;AAAA;;;;;;;;;;;;;;;;AAuCI;AA+B9B;;;cA9Ca,qBAAA,SAA8B,cAAA;EAAA,gBACzB,QAAA,EAAU,qBAAA;cAEd,KAAA,GAAQ,mBAAA;EAIX,SAAA;EAIA,YAAA,CAAa,SAAA;EAIb,mBAAA;AAAA;;;;;;;;;;;;iBA+BK,uBAAA,CAAwB,KAAA,EAAO,uBAAA,GAA0B,cAAc"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
export { PostgresEnumType, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
1
|
+
import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-CTKYiTHu.mjs";
|
|
2
|
+
export { PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|