@prisma-next/target-postgres 0.10.0 → 0.11.0
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/control.mjs +4 -4
- package/dist/descriptor-meta-DLA2xV6B.mjs +126 -0
- package/dist/descriptor-meta-DLA2xV6B.mjs.map +1 -0
- package/dist/{issue-planner-qalHRCI2.mjs → issue-planner-OthDciOe.mjs} +5 -5
- package/dist/{issue-planner-qalHRCI2.mjs.map → issue-planner-OthDciOe.mjs.map} +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{op-factory-call-Zsrdty3k.mjs → op-factory-call-Bgb_ghPb.mjs} +3 -3
- package/dist/op-factory-call-Bgb_ghPb.mjs.map +1 -0
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +7 -0
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-C8yhbXOq.mjs → planner-DZG1dsSW.mjs} +4 -4
- package/dist/{planner-C8yhbXOq.mjs.map → planner-DZG1dsSW.mjs.map} +1 -1
- package/dist/{planner-ddl-builders-DINYrbJ3.mjs → planner-ddl-builders-DYMuN0w1.mjs} +2 -2
- package/dist/{planner-ddl-builders-DINYrbJ3.mjs.map → planner-ddl-builders-DYMuN0w1.mjs.map} +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-BqGLw7VT.mjs → planner-produced-postgres-migration-TJWH2m_x.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-BqGLw7VT.mjs.map → planner-produced-postgres-migration-TJWH2m_x.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-c9lpjPv1.d.mts → planner-produced-postgres-migration-p-VKkCia.d.mts} +2 -2
- package/dist/{planner-produced-postgres-migration-c9lpjPv1.d.mts.map → planner-produced-postgres-migration-p-VKkCia.d.mts.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-BM4sD6Xc.mjs → planner-sql-checks-K-mTBJDi.mjs} +2 -2
- package/dist/{planner-sql-checks-BM4sD6Xc.mjs.map → planner-sql-checks-K-mTBJDi.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.d.mts +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-CcZO9ukP.mjs → postgres-contract-serializer-CrET5Ov0.mjs} +41 -19
- package/dist/postgres-contract-serializer-CrET5Ov0.mjs.map +1 -0
- package/dist/{postgres-migration-jvsKgUDM.d.mts → postgres-migration-Fd4fQkBw.d.mts} +4 -4
- package/dist/{postgres-migration-jvsKgUDM.d.mts.map → postgres-migration-Fd4fQkBw.d.mts.map} +1 -1
- package/dist/{postgres-migration-C5os-tkl.mjs → postgres-migration-uADmx0dW.mjs} +4 -4
- package/dist/postgres-migration-uADmx0dW.mjs.map +1 -0
- package/dist/{postgres-schema-BosNxhWq.mjs → postgres-schema-CK82EuWq.mjs} +7 -2
- package/dist/postgres-schema-CK82EuWq.mjs.map +1 -0
- package/dist/{render-typescript-nRHbqLbI.mjs → render-typescript-CI1wbgUc.mjs} +5 -5
- package/dist/render-typescript-CI1wbgUc.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/{tables-DZ-5Yxi0.mjs → tables-CWxZgD0H.mjs} +2 -2
- package/dist/{tables-DZ-5Yxi0.mjs.map → tables-CWxZgD0H.mjs.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +17 -17
- package/src/core/authoring.ts +2 -0
- package/src/core/migrations/op-factory-call.ts +1 -1
- package/src/core/migrations/postgres-migration.ts +3 -3
- package/src/core/migrations/render-typescript.ts +4 -4
- package/src/core/postgres-contract-serializer.ts +76 -41
- package/src/core/postgres-schema.ts +7 -1
- package/src/exports/migration.ts +4 -4
- package/dist/descriptor-meta-zrZzWmJF.mjs +0 -91
- package/dist/descriptor-meta-zrZzWmJF.mjs.map +0 -1
- package/dist/op-factory-call-Zsrdty3k.mjs.map +0 -1
- package/dist/postgres-contract-serializer-CcZO9ukP.mjs.map +0 -1
- package/dist/postgres-migration-C5os-tkl.mjs.map +0 -1
- package/dist/postgres-schema-BosNxhWq.mjs.map +0 -1
- package/dist/render-typescript-nRHbqLbI.mjs.map +0 -1
|
@@ -1,26 +1,87 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
SqlContractSerializerBase,
|
|
4
|
+
type SqlEntityHydrationFactory,
|
|
5
|
+
} from '@prisma-next/family-sql/ir';
|
|
6
|
+
import {
|
|
7
|
+
type AuthoringEntityContext,
|
|
8
|
+
type AuthoringEntityTypeFactoryOutput,
|
|
9
|
+
type AuthoringEntityTypeNamespace,
|
|
10
|
+
isAuthoringEntityTypeDescriptor,
|
|
11
|
+
} from '@prisma-next/framework-components/authoring';
|
|
3
12
|
import {
|
|
4
13
|
type Namespace,
|
|
5
14
|
NamespaceBase,
|
|
6
15
|
UNBOUND_NAMESPACE_ID,
|
|
7
16
|
} from '@prisma-next/framework-components/ir';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
import type {
|
|
18
|
+
SqlNamespaceTablesInput,
|
|
19
|
+
SqlStorage,
|
|
20
|
+
SqlStorageTypeEntry,
|
|
11
21
|
StorageTable,
|
|
12
|
-
type StorageTableInput,
|
|
13
22
|
} from '@prisma-next/sql-contract/types';
|
|
14
23
|
import type { JsonObject } from '@prisma-next/utils/json';
|
|
15
|
-
import {
|
|
24
|
+
import type { Type } from 'arktype';
|
|
25
|
+
import { postgresAuthoringEntityTypes } from './authoring';
|
|
26
|
+
import type { PostgresEnumType } from './postgres-enum-type';
|
|
16
27
|
import { isPostgresSchema, PostgresSchema } from './postgres-schema';
|
|
17
28
|
|
|
29
|
+
const POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {
|
|
30
|
+
family: 'sql',
|
|
31
|
+
target: 'postgres',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function isAuthoringEntityTypeFactoryOutput(
|
|
35
|
+
output: unknown,
|
|
36
|
+
): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {
|
|
37
|
+
return (
|
|
38
|
+
typeof output === 'object' &&
|
|
39
|
+
output !== null &&
|
|
40
|
+
typeof (output as AuthoringEntityTypeFactoryOutput).factory === 'function'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Walks a pack's entity-type namespace tree and emits the maps the
|
|
46
|
+
* family base consumes — hydrators and validator-schema fragments, both
|
|
47
|
+
* keyed by the descriptor's `discriminator`.
|
|
48
|
+
*/
|
|
49
|
+
function collectEntityRegistryContributions(namespace: AuthoringEntityTypeNamespace): {
|
|
50
|
+
readonly entityTypeRegistry: ReadonlyMap<string, SqlEntityHydrationFactory>;
|
|
51
|
+
readonly validatorFragments: ReadonlyMap<string, Type<unknown>>;
|
|
52
|
+
} {
|
|
53
|
+
const entityTypeRegistry = new Map<string, SqlEntityHydrationFactory>();
|
|
54
|
+
const validatorFragments = new Map<string, Type<unknown>>();
|
|
55
|
+
const walk = (node: AuthoringEntityTypeNamespace): void => {
|
|
56
|
+
for (const value of Object.values(node)) {
|
|
57
|
+
if (isAuthoringEntityTypeDescriptor(value)) {
|
|
58
|
+
if (isAuthoringEntityTypeFactoryOutput(value.output)) {
|
|
59
|
+
const { factory } = value.output;
|
|
60
|
+
entityTypeRegistry.set(
|
|
61
|
+
value.discriminator,
|
|
62
|
+
(raw) => factory(raw, POSTGRES_AUTHORING_CTX) as SqlStorageTypeEntry,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (value.validatorSchema !== undefined) {
|
|
66
|
+
validatorFragments.set(value.discriminator, value.validatorSchema);
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === 'object' && value !== null) {
|
|
71
|
+
walk(value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
walk(namespace);
|
|
76
|
+
return { entityTypeRegistry, validatorFragments };
|
|
77
|
+
}
|
|
78
|
+
|
|
18
79
|
export class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
19
80
|
constructor() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
super(
|
|
81
|
+
const { entityTypeRegistry, validatorFragments } = collectEntityRegistryContributions(
|
|
82
|
+
postgresAuthoringEntityTypes,
|
|
83
|
+
);
|
|
84
|
+
super(entityTypeRegistry, validatorFragments);
|
|
24
85
|
}
|
|
25
86
|
|
|
26
87
|
protected override hydrateSqlNamespaceEntry(
|
|
@@ -30,38 +91,12 @@ export class PostgresContractSerializer extends SqlContractSerializerBase<Contra
|
|
|
30
91
|
if (raw instanceof NamespaceBase) {
|
|
31
92
|
return raw;
|
|
32
93
|
}
|
|
33
|
-
const
|
|
34
|
-
id
|
|
35
|
-
tables
|
|
36
|
-
types?: Record<string,
|
|
94
|
+
const hydrated = super.hydrateSqlNamespaceEntry(nsId, raw) as {
|
|
95
|
+
id: string;
|
|
96
|
+
tables: Readonly<Record<string, StorageTable>>;
|
|
97
|
+
types?: Readonly<Record<string, PostgresEnumType>>;
|
|
37
98
|
};
|
|
38
|
-
const id
|
|
39
|
-
const tables = Object.fromEntries(
|
|
40
|
-
Object.entries(obj.tables ?? {}).map(([tableName, table]) => [
|
|
41
|
-
tableName,
|
|
42
|
-
table instanceof StorageTable ? table : new StorageTable(table as StorageTableInput),
|
|
43
|
-
]),
|
|
44
|
-
);
|
|
45
|
-
const typeEntries = obj.types;
|
|
46
|
-
const hydratedNsTypes =
|
|
47
|
-
typeEntries !== undefined && Object.keys(typeEntries).length > 0
|
|
48
|
-
? Object.fromEntries(
|
|
49
|
-
Object.entries(typeEntries).map(([typeName, entry]) => {
|
|
50
|
-
if (entry instanceof PostgresEnumType) {
|
|
51
|
-
return [typeName, entry];
|
|
52
|
-
}
|
|
53
|
-
const plain = entry as Record<string, unknown>;
|
|
54
|
-
const name = typeof plain['name'] === 'string' ? plain['name'] : typeName;
|
|
55
|
-
const nativeType =
|
|
56
|
-
typeof plain['nativeType'] === 'string' ? plain['nativeType'] : name;
|
|
57
|
-
const values = Array.isArray(plain['values']) ? (plain['values'] as string[]) : [];
|
|
58
|
-
return [
|
|
59
|
-
typeName,
|
|
60
|
-
new PostgresEnumType({ name, nativeType, values } as PostgresEnumTypeInput),
|
|
61
|
-
];
|
|
62
|
-
}),
|
|
63
|
-
)
|
|
64
|
-
: undefined;
|
|
99
|
+
const { id, tables, types: hydratedNsTypes } = hydrated;
|
|
65
100
|
|
|
66
101
|
const emptyTables = Object.keys(tables).length === 0;
|
|
67
102
|
const emptyTypes = !hydratedNsTypes || Object.keys(hydratedNsTypes).length === 0;
|
|
@@ -41,7 +41,7 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
41
41
|
*/
|
|
42
42
|
static unbound: PostgresUnboundSchema;
|
|
43
43
|
|
|
44
|
-
readonly kind
|
|
44
|
+
declare readonly kind: 'schema';
|
|
45
45
|
readonly id: string;
|
|
46
46
|
readonly tables: Readonly<Record<string, StorageTable>>;
|
|
47
47
|
readonly types: Readonly<Record<string, PostgresEnumType>>;
|
|
@@ -65,6 +65,12 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
65
65
|
]),
|
|
66
66
|
),
|
|
67
67
|
);
|
|
68
|
+
Object.defineProperty(this, 'kind', {
|
|
69
|
+
value: 'schema',
|
|
70
|
+
writable: false,
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true,
|
|
73
|
+
});
|
|
68
74
|
freezeNode(this);
|
|
69
75
|
}
|
|
70
76
|
|
package/src/exports/migration.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Re-exported so a Postgres `migration.ts` only needs the single
|
|
2
|
-
// `@prisma-next/
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// `@prisma-next/postgres/migration` import for its base class and the
|
|
3
|
+
// CLI entrypoint, mirroring how `placeholder` is surfaced here. The
|
|
4
|
+
// renderer emits the entrypoint call as
|
|
5
5
|
// `MigrationCLI.run(import.meta.url, M)`.
|
|
6
6
|
export { MigrationCLI } from '@prisma-next/cli/migration-cli';
|
|
7
7
|
// Re-exported so user-edited migration.ts files only need to depend on
|
|
8
|
-
// `@prisma-next/
|
|
8
|
+
// `@prisma-next/postgres/migration` to fill in planner-emitted
|
|
9
9
|
// `placeholder("…")` slots, instead of pulling in `@prisma-next/errors`
|
|
10
10
|
// directly. The planner emits an import from this same module.
|
|
11
11
|
export { placeholder } from '@prisma-next/errors/migration';
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-DS-KLVRH.mjs";
|
|
2
|
-
import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
|
|
3
|
-
const postgresTargetDescriptorMeta = {
|
|
4
|
-
kind: "target",
|
|
5
|
-
familyId: "sql",
|
|
6
|
-
targetId: "postgres",
|
|
7
|
-
id: "postgres",
|
|
8
|
-
version: "0.0.1",
|
|
9
|
-
capabilities: {},
|
|
10
|
-
authoring: {
|
|
11
|
-
type: {},
|
|
12
|
-
field: {
|
|
13
|
-
text: {
|
|
14
|
-
kind: "fieldPreset",
|
|
15
|
-
output: {
|
|
16
|
-
codecId: "pg/text@1",
|
|
17
|
-
nativeType: "text"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
int: {
|
|
21
|
-
kind: "fieldPreset",
|
|
22
|
-
output: {
|
|
23
|
-
codecId: "pg/int4@1",
|
|
24
|
-
nativeType: "int4"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
bigint: {
|
|
28
|
-
kind: "fieldPreset",
|
|
29
|
-
output: {
|
|
30
|
-
codecId: "pg/int8@1",
|
|
31
|
-
nativeType: "int8"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
float: {
|
|
35
|
-
kind: "fieldPreset",
|
|
36
|
-
output: {
|
|
37
|
-
codecId: "pg/float8@1",
|
|
38
|
-
nativeType: "float8"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
decimal: {
|
|
42
|
-
kind: "fieldPreset",
|
|
43
|
-
output: {
|
|
44
|
-
codecId: "pg/numeric@1",
|
|
45
|
-
nativeType: "numeric"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
boolean: {
|
|
49
|
-
kind: "fieldPreset",
|
|
50
|
-
output: {
|
|
51
|
-
codecId: "pg/bool@1",
|
|
52
|
-
nativeType: "bool"
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
json: {
|
|
56
|
-
kind: "fieldPreset",
|
|
57
|
-
output: {
|
|
58
|
-
codecId: "pg/jsonb@1",
|
|
59
|
-
nativeType: "jsonb"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
bytes: {
|
|
63
|
-
kind: "fieldPreset",
|
|
64
|
-
output: {
|
|
65
|
-
codecId: "pg/bytea@1",
|
|
66
|
-
nativeType: "bytea"
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
dateTime: {
|
|
70
|
-
kind: "fieldPreset",
|
|
71
|
-
output: {
|
|
72
|
-
codecId: "pg/timestamptz@1",
|
|
73
|
-
nativeType: "timestamptz"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
temporal: temporalAuthoringPresets({
|
|
77
|
-
codecId: "pg/timestamptz@1",
|
|
78
|
-
nativeType: "timestamptz"
|
|
79
|
-
})
|
|
80
|
-
},
|
|
81
|
-
entityTypes: { enum: {
|
|
82
|
-
kind: "entity",
|
|
83
|
-
discriminator: "postgres-enum",
|
|
84
|
-
output: { factory: (input) => new PostgresEnumType(input) }
|
|
85
|
-
} }
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
//#endregion
|
|
89
|
-
export { postgresTargetDescriptorMeta as t };
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=descriptor-meta-zrZzWmJF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-zrZzWmJF.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringTypeNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport type { PostgresEnumStorageEntry } from '@prisma-next/sql-contract/types';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\n\nexport const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;\n\n/**\n * Entity type contributions surface as top-level helpers on the\n * composed-helpers shape (e.g. `helpers.enum({...})`), flattened\n * alongside the built-in `model` / `rel` helpers. Pack contributions\n * still ship via the contribution data structure\n * `authoring.entityTypes.<name>`; the composed-helpers template\n * performs the rename in the type system.\n *\n * `enum` is the first real consumer of the entities-namespace mechanism:\n * the factory constructs a `PostgresEnumType` IR-class instance from\n * the user-supplied input. Both authoring runtimes (TS DSL and PSL)\n * dispatch through this single contribution — PSL `enum Status { … }`\n * declarations are lowered by the interpreter into a factory call\n * with the parsed name + value list; TS DSL `helpers.enum({...})`\n * resolves through the same path. Removing this contribution makes\n * both surfaces fail with a \"no entity helper named `enum`\" type\n * error at the contract-definition site.\n */\n/**\n * The factory constructs a `PostgresEnumType` instance natively — the\n * `SqlStorage.types` slot accepts polymorphic IR (the framework\n * `StorageType` alphabet), so no cast is needed at the contribution\n * surface. The declared return type is the structural\n * `PostgresEnumStorageEntry` so the inferred contract type stays\n * portable (it names a type exported from\n * `@prisma-next/sql-contract/types`, a public surface every consumer\n * already imports). Sharpening the inferred contract type to surface\n * enum-specific narrowing through `EntityHelperFunction` is a\n * separable refinement and lives outside this PR.\n */\nexport const postgresAuthoringEntityTypes = {\n enum: {\n kind: 'entity',\n discriminator: 'postgres-enum',\n output: {\n factory: (input: PostgresEnumTypeInput): PostgresEnumStorageEntry =>\n new PostgresEnumType(input),\n },\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n */\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n} as const satisfies AuthoringFieldNamespace;\n","import type { CodecTypes } from '../exports/codec-types';\nimport {\n postgresAuthoringEntityTypes,\n postgresAuthoringFieldPresets,\n postgresAuthoringTypes,\n} from './authoring';\n\nconst postgresTargetDescriptorMetaBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n entityTypes: postgresAuthoringEntityTypes,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";;ACqBA,MAAa,+BAET;CAfF,MAAM;CACN,UAAU;CACV,UAAU;CACV,IAAI;CACJ,SAAS;CACT,cAAc,EAAE;CAChB,WAAW;EACT,MAAM,EAAA;EACN,OAAO;GD6CT,MAAM;IACJ,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,KAAK;IACH,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,QAAQ;IACN,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,OAAO;IACL,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,SAAS;IACP,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,SAAS;IACP,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,MAAM;IACJ,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,OAAO;IACL,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,UAAU;IACR,MAAM;IACN,QAAQ;KACN,SAAS;KACT,YAAY;KACb;IACF;GACD,UAAU,yBAAyB;IACjC,SAAS;IACT,YAAY;IACb,CAAC;GC/GO;EACP,aAAa,EDyBf,MAAM;GACJ,MAAM;GACN,eAAe;GACf,QAAQ,EACN,UAAU,UACR,IAAI,iBAAiB,MAAM,EAC9B;GACF,EChCc;EACd;CAKC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"op-factory-call-Zsrdty3k.mjs","names":[],"sources":["../src/core/migrations/op-factory-call.ts"],"sourcesContent":["/**\n * Postgres migration IR: one concrete `*Call` class per pure factory under\n * `operations/`, plus a shared `PostgresOpFactoryCallNode` abstract base.\n *\n * Every call class carries the literal arguments its backing factory would\n * receive, computes a human-readable `label` in its constructor, and\n * implements two polymorphic hooks:\n *\n * - `toOp()` — converts the IR node to a runtime\n * `SqlMigrationPlanOperation` by delegating to the matching pure factory\n * under `operations/`. `DataTransformCall.toOp()` always throws\n * `PN-MIG-2001` because a planner-generated data transform is an\n * unfilled authoring stub by construction.\n * - `renderTypeScript()` / `importRequirements()` — inherited from\n * `TsExpression`. Used by `renderCallsToTypeScript` to emit the call as\n * a TypeScript expression inside the scaffolded `migration.ts`.\n *\n * The abstract base and all concrete classes are package-private. External\n * consumers see only the framework-level `OpFactoryCall` interface and the\n * `PostgresOpFactoryCall` union.\n */\n\nimport { errorUnfilledPlaceholder } from '@prisma-next/errors/migration';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type {\n OpFactoryCall as FrameworkOpFactoryCall,\n MigrationOperationClass,\n} from '@prisma-next/framework-components/control';\nimport { type ImportRequirement, jsonToTsSource, TsExpression } from '@prisma-next/ts-render';\nimport {\n addColumn,\n alterColumnType,\n dropColumn,\n dropDefault,\n dropNotNull,\n setDefault,\n setNotNull,\n} from './operations/columns';\nimport { addForeignKey, addPrimaryKey, addUnique, dropConstraint } from './operations/constraints';\nimport { createExtension, createSchema } from './operations/dependencies';\nimport { addEnumValues, createEnumType, dropEnumType, renameType } from './operations/enums';\nimport { createIndex, dropIndex } from './operations/indexes';\nimport type { ColumnSpec, ForeignKeySpec } from './operations/shared';\nimport { createTable, dropTable } from './operations/tables';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nconst TARGET_MIGRATION_MODULE = '@prisma-next/target-postgres/migration';\n\nabstract class PostgresOpFactoryCallNode extends TsExpression implements FrameworkOpFactoryCall {\n abstract readonly factoryName: string;\n abstract readonly operationClass: MigrationOperationClass;\n abstract readonly label: string;\n abstract toOp(): Op;\n\n importRequirements(): readonly ImportRequirement[] {\n return [{ moduleSpecifier: TARGET_MIGRATION_MODULE, symbol: this.factoryName }];\n }\n\n protected freeze(): void {\n Object.freeze(this);\n }\n}\n\n// ============================================================================\n// Table\n// ============================================================================\n\nexport interface CreateTablePrimaryKey {\n readonly columns: readonly string[];\n}\n\nexport class CreateTableCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'createTable' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columns: readonly ColumnSpec[];\n readonly primaryKey: CreateTablePrimaryKey | undefined;\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n columns: readonly ColumnSpec[],\n primaryKey?: CreateTablePrimaryKey,\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columns = columns;\n this.primaryKey = primaryKey;\n this.label = `Create table \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return createTable(this.schemaName, this.tableName, this.columns, this.primaryKey);\n }\n\n renderTypeScript(): string {\n const args = [\n jsonToTsSource(this.schemaName),\n jsonToTsSource(this.tableName),\n jsonToTsSource(this.columns),\n ];\n if (this.primaryKey) args.push(jsonToTsSource(this.primaryKey));\n return `createTable(${args.join(', ')})`;\n }\n}\n\nexport class DropTableCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropTable' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.label = `Drop table \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropTable(this.schemaName, this.tableName);\n }\n\n renderTypeScript(): string {\n return `dropTable(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)})`;\n }\n}\n\n// ============================================================================\n// Column\n// ============================================================================\n\nexport class AddColumnCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'addColumn' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly column: ColumnSpec;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, column: ColumnSpec) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.column = column;\n this.label = `Add column \"${column.name}\" to \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return addColumn(this.schemaName, this.tableName, this.column);\n }\n\n renderTypeScript(): string {\n return `addColumn(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.column)})`;\n }\n}\n\nexport class DropColumnCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropColumn' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, columnName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.label = `Drop column \"${columnName}\" from \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropColumn(this.schemaName, this.tableName, this.columnName);\n }\n\n renderTypeScript(): string {\n return `dropColumn(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;\n }\n}\n\nexport interface AlterColumnTypeOptions {\n readonly qualifiedTargetType: string;\n readonly formatTypeExpected: string;\n readonly rawTargetTypeForLabel: string;\n readonly using?: string;\n}\n\nexport class AlterColumnTypeCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'alterColumnType' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly options: AlterColumnTypeOptions;\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n columnName: string,\n options: AlterColumnTypeOptions,\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.options = options;\n this.label = `Alter type of \"${tableName}\".\"${columnName}\" to ${options.rawTargetTypeForLabel}`;\n this.freeze();\n }\n\n toOp(): Op {\n return alterColumnType(this.schemaName, this.tableName, this.columnName, this.options);\n }\n\n renderTypeScript(): string {\n return `alterColumnType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)}, ${jsonToTsSource(this.options)})`;\n }\n}\n\nexport class SetNotNullCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'setNotNull' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, columnName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.label = `Set NOT NULL on \"${tableName}\".\"${columnName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return setNotNull(this.schemaName, this.tableName, this.columnName);\n }\n\n renderTypeScript(): string {\n return `setNotNull(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;\n }\n}\n\nexport class DropNotNullCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropNotNull' as const;\n readonly operationClass = 'widening' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, columnName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.label = `Drop NOT NULL on \"${tableName}\".\"${columnName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropNotNull(this.schemaName, this.tableName, this.columnName);\n }\n\n renderTypeScript(): string {\n return `dropNotNull(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;\n }\n}\n\nexport class SetDefaultCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'setDefault' as const;\n readonly operationClass: 'additive' | 'widening';\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly defaultSql: string;\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n columnName: string,\n defaultSql: string,\n operationClass: 'additive' | 'widening' = 'additive',\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.defaultSql = defaultSql;\n this.operationClass = operationClass;\n this.label = `Set default on \"${tableName}\".\"${columnName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return setDefault(\n this.schemaName,\n this.tableName,\n this.columnName,\n this.defaultSql,\n this.operationClass,\n );\n }\n\n renderTypeScript(): string {\n const args = [\n jsonToTsSource(this.schemaName),\n jsonToTsSource(this.tableName),\n jsonToTsSource(this.columnName),\n jsonToTsSource(this.defaultSql),\n ];\n if (this.operationClass !== 'additive') {\n args.push(jsonToTsSource(this.operationClass));\n }\n return `setDefault(${args.join(', ')})`;\n }\n}\n\nexport class DropDefaultCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropDefault' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly columnName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, columnName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.columnName = columnName;\n this.label = `Drop default on \"${tableName}\".\"${columnName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropDefault(this.schemaName, this.tableName, this.columnName);\n }\n\n renderTypeScript(): string {\n return `dropDefault(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.columnName)})`;\n }\n}\n\n// ============================================================================\n// Constraints\n// ============================================================================\n\nexport class AddPrimaryKeyCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'addPrimaryKey' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly constraintName: string;\n readonly columns: readonly string[];\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n constraintName: string,\n columns: readonly string[],\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.constraintName = constraintName;\n this.columns = columns;\n this.label = `Add primary key on \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return addPrimaryKey(this.schemaName, this.tableName, this.constraintName, this.columns);\n }\n\n renderTypeScript(): string {\n return `addPrimaryKey(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)}, ${jsonToTsSource(this.columns)})`;\n }\n}\n\nexport class AddUniqueCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'addUnique' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly constraintName: string;\n readonly columns: readonly string[];\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n constraintName: string,\n columns: readonly string[],\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.constraintName = constraintName;\n this.columns = columns;\n this.label = `Add unique constraint on \"${tableName}\" (${columns.join(', ')})`;\n this.freeze();\n }\n\n toOp(): Op {\n return addUnique(this.schemaName, this.tableName, this.constraintName, this.columns);\n }\n\n renderTypeScript(): string {\n return `addUnique(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.constraintName)}, ${jsonToTsSource(this.columns)})`;\n }\n}\n\nexport class AddForeignKeyCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'addForeignKey' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly fk: ForeignKeySpec;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, fk: ForeignKeySpec) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.fk = fk;\n this.label = `Add foreign key \"${fk.name}\" on \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return addForeignKey(this.schemaName, this.tableName, this.fk);\n }\n\n renderTypeScript(): string {\n return `addForeignKey(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.fk)})`;\n }\n}\n\nexport class DropConstraintCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropConstraint' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly constraintName: string;\n readonly kind: 'foreignKey' | 'unique' | 'primaryKey';\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n constraintName: string,\n kind: 'foreignKey' | 'unique' | 'primaryKey' = 'unique',\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.constraintName = constraintName;\n this.kind = kind;\n this.label = `Drop constraint \"${constraintName}\" on \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropConstraint(this.schemaName, this.tableName, this.constraintName, this.kind);\n }\n\n renderTypeScript(): string {\n const args = [\n jsonToTsSource(this.schemaName),\n jsonToTsSource(this.tableName),\n jsonToTsSource(this.constraintName),\n ];\n if (this.kind !== 'unique') {\n args.push(jsonToTsSource(this.kind));\n }\n return `dropConstraint(${args.join(', ')})`;\n }\n}\n\n// ============================================================================\n// Indexes\n// ============================================================================\n\nexport class CreateIndexCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'createIndex' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly indexName: string;\n readonly columns: readonly string[];\n // Named indexType (not typeName) to avoid collision with CreateEnumTypeCall.typeName,\n // which identifies a CREATE TYPE target and is read by `locationForCall` in issue-planner.ts.\n readonly indexType: string | undefined;\n readonly options: Record<string, unknown> | undefined;\n readonly label: string;\n\n constructor(\n schemaName: string,\n tableName: string,\n indexName: string,\n columns: readonly string[],\n extras?: { readonly type?: string; readonly options?: Record<string, unknown> },\n ) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.indexName = indexName;\n this.columns = columns;\n this.indexType = extras?.type;\n this.options = extras?.options;\n this.label = `Create index \"${indexName}\" on \"${tableName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n const extras: { type?: string; options?: Record<string, unknown> } = {};\n if (this.indexType !== undefined) extras.type = this.indexType;\n if (this.options !== undefined) extras.options = this.options;\n return createIndex(this.schemaName, this.tableName, this.indexName, this.columns, extras);\n }\n\n renderTypeScript(): string {\n const args = [\n jsonToTsSource(this.schemaName),\n jsonToTsSource(this.tableName),\n jsonToTsSource(this.indexName),\n jsonToTsSource(this.columns),\n ];\n if (this.indexType !== undefined || this.options !== undefined) {\n const extrasParts: string[] = [];\n if (this.indexType !== undefined) extrasParts.push(`type: ${jsonToTsSource(this.indexType)}`);\n if (this.options !== undefined) extrasParts.push(`options: ${jsonToTsSource(this.options)}`);\n args.push(`{ ${extrasParts.join(', ')} }`);\n }\n return `createIndex(${args.join(', ')})`;\n }\n}\n\nexport class DropIndexCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropIndex' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly tableName: string;\n readonly indexName: string;\n readonly label: string;\n\n constructor(schemaName: string, tableName: string, indexName: string) {\n super();\n this.schemaName = schemaName;\n this.tableName = tableName;\n this.indexName = indexName;\n this.label = `Drop index \"${indexName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropIndex(this.schemaName, this.tableName, this.indexName);\n }\n\n renderTypeScript(): string {\n return `dropIndex(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.tableName)}, ${jsonToTsSource(this.indexName)})`;\n }\n}\n\n// ============================================================================\n// Enum types\n// ============================================================================\n\nexport class CreateEnumTypeCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'createEnumType' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly typeName: string;\n readonly nativeType: string;\n readonly values: readonly string[];\n readonly label: string;\n\n constructor(\n schemaName: string,\n typeName: string,\n values: readonly string[],\n nativeType: string = typeName,\n ) {\n super();\n this.schemaName = schemaName;\n this.typeName = typeName;\n this.nativeType = nativeType;\n this.values = values;\n this.label = `Create enum type \"${typeName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return createEnumType(this.schemaName, this.typeName, this.values, this.nativeType);\n }\n\n renderTypeScript(): string {\n const nativeArg =\n this.nativeType === this.typeName ? '' : `, ${jsonToTsSource(this.nativeType)}`;\n return `createEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.values)}${nativeArg})`;\n }\n}\n\nexport class AddEnumValuesCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'addEnumValues' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly typeName: string;\n readonly nativeType: string;\n readonly values: readonly string[];\n readonly label: string;\n\n constructor(schemaName: string, typeName: string, nativeType: string, values: readonly string[]) {\n super();\n this.schemaName = schemaName;\n this.typeName = typeName;\n this.nativeType = nativeType;\n this.values = values;\n this.label = `Add values to enum type \"${typeName}\": ${values.join(', ')}`;\n this.freeze();\n }\n\n toOp(): Op {\n return addEnumValues(this.schemaName, this.typeName, this.nativeType, this.values);\n }\n\n renderTypeScript(): string {\n return `addEnumValues(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)}, ${jsonToTsSource(this.nativeType)}, ${jsonToTsSource(this.values)})`;\n }\n}\n\nexport class DropEnumTypeCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dropEnumType' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly typeName: string;\n readonly label: string;\n\n constructor(schemaName: string, typeName: string) {\n super();\n this.schemaName = schemaName;\n this.typeName = typeName;\n this.label = `Drop enum type \"${typeName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return dropEnumType(this.schemaName, this.typeName);\n }\n\n renderTypeScript(): string {\n return `dropEnumType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.typeName)})`;\n }\n}\n\nexport class RenameTypeCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'renameType' as const;\n readonly operationClass = 'destructive' as const;\n readonly schemaName: string;\n readonly fromName: string;\n readonly toName: string;\n readonly label: string;\n\n constructor(schemaName: string, fromName: string, toName: string) {\n super();\n this.schemaName = schemaName;\n this.fromName = fromName;\n this.toName = toName;\n this.label = `Rename type \"${fromName}\" to \"${toName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return renameType(this.schemaName, this.fromName, this.toName);\n }\n\n renderTypeScript(): string {\n return `renameType(${jsonToTsSource(this.schemaName)}, ${jsonToTsSource(this.fromName)}, ${jsonToTsSource(this.toName)})`;\n }\n}\n\n// ============================================================================\n// Raw SQL\n// ============================================================================\n\n/**\n * Laundered pre-built operation.\n *\n * Wraps an already-materialized `SqlMigrationPlanOperation` — typically one\n * produced by a SQL-family method or a codec control hook — so the planner\n * can carry it alongside IR nodes without reverse-engineering it into a\n * structured call class. Doubles as the user-facing escape hatch for raw\n * migrations: authors can pass a full op shape to `rawSql({...})`.\n *\n * `toOp()` returns the stored op unchanged. `renderTypeScript()` emits\n * `rawSql({...})` with the op serialized as a JSON literal — round-tripping\n * requires every field on the op to be JSON-serializable (no closures).\n */\nexport class RawSqlCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'rawSql' as const;\n readonly operationClass: MigrationOperationClass;\n readonly label: string;\n readonly op: Op;\n\n constructor(op: Op) {\n super();\n this.op = op;\n this.label = op.label;\n this.operationClass = op.operationClass;\n this.freeze();\n }\n\n toOp(): Op {\n return this.op;\n }\n\n renderTypeScript(): string {\n return `rawSql(${jsonToTsSource(this.op)})`;\n }\n}\n\n// ============================================================================\n// Database dependencies (structured DDL)\n// ============================================================================\n\nexport class CreateExtensionCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'createExtension' as const;\n readonly operationClass = 'additive' as const;\n readonly extensionName: string;\n readonly label: string;\n\n constructor(extensionName: string) {\n super();\n this.extensionName = extensionName;\n this.label = `Create extension \"${extensionName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return createExtension(this.extensionName);\n }\n\n renderTypeScript(): string {\n return `createExtension(${jsonToTsSource(this.extensionName)})`;\n }\n}\n\nexport class CreateSchemaCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'createSchema' as const;\n readonly operationClass = 'additive' as const;\n readonly schemaName: string;\n readonly label: string;\n\n constructor(schemaName: string) {\n super();\n this.schemaName = schemaName;\n this.label = `Create schema \"${schemaName}\"`;\n this.freeze();\n }\n\n toOp(): Op {\n return createSchema(this.schemaName);\n }\n\n renderTypeScript(): string {\n return `createSchema(${jsonToTsSource(this.schemaName)})`;\n }\n}\n\n// ============================================================================\n// Data transform\n// ============================================================================\n\n/**\n * A planner-generated data-transform stub. `checkSlot` and `runSlot` name\n * the unfilled authoring slots that the rendered `migration.ts` will expose\n * to the user via `placeholder(\"…\")` calls. `toOp()` always throws\n * `PN-MIG-2001`: the planner cannot lower a stubbed transform to a runtime\n * op — the user must fill the rendered `migration.ts` and re-emit.\n */\nexport class DataTransformCall extends PostgresOpFactoryCallNode {\n readonly factoryName = 'dataTransform' as const;\n readonly operationClass: MigrationOperationClass;\n readonly label: string;\n readonly checkSlot: string;\n readonly runSlot: string;\n\n constructor(\n label: string,\n checkSlot: string,\n runSlot: string,\n operationClass: MigrationOperationClass = 'data',\n ) {\n super();\n this.label = label;\n this.checkSlot = checkSlot;\n this.runSlot = runSlot;\n this.operationClass = operationClass;\n this.freeze();\n }\n\n toOp(): Op {\n throw errorUnfilledPlaceholder(this.label);\n }\n\n renderTypeScript(): string {\n return [\n `this.dataTransform(endContract, ${jsonToTsSource(this.label)}, {`,\n ` check: () => placeholder(${jsonToTsSource(this.checkSlot)}),`,\n ` run: () => placeholder(${jsonToTsSource(this.runSlot)}),`,\n '})',\n ].join('\\n');\n }\n\n override importRequirements(): readonly ImportRequirement[] {\n return [\n { moduleSpecifier: TARGET_MIGRATION_MODULE, symbol: 'placeholder' },\n {\n moduleSpecifier: './end-contract.json',\n symbol: 'endContract',\n kind: 'default',\n attributes: { type: 'json' },\n },\n ];\n }\n}\n\nexport type PostgresOpFactoryCall =\n | CreateTableCall\n | DropTableCall\n | AddColumnCall\n | DropColumnCall\n | AlterColumnTypeCall\n | SetNotNullCall\n | DropNotNullCall\n | SetDefaultCall\n | DropDefaultCall\n | AddPrimaryKeyCall\n | AddForeignKeyCall\n | AddUniqueCall\n | CreateIndexCall\n | DropIndexCall\n | DropConstraintCall\n | CreateEnumTypeCall\n | AddEnumValuesCall\n | DropEnumTypeCall\n | RenameTypeCall\n | RawSqlCall\n | CreateExtensionCall\n | CreateSchemaCall\n | DataTransformCall;\n\n/**\n * Stable identity key for reconciliation-level dedup.\n *\n * Two calls whose runtime ops would share the same `id` return the same\n * key, so a `Set<string>` can collapse them before they're emitted. The\n * current implementation delegates to `toOp().id`, which is the\n * authoritative identity; isolating dedup behind this helper lets a future\n * pass replace it with an allocation-free computation directly from the\n * call's fields without touching call sites.\n *\n * `DataTransformCall` intentionally has no sensible identity today — it\n * throws `PN-MIG-2001` on `toOp()`. Reconciliation never produces one; the\n * helper is unspecified for that variant and only meant for\n * reconciliation-emitted calls.\n */\nexport function identityKeyFor(call: PostgresOpFactoryCall): string {\n return call.toOp().id;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAM,0BAA0B;AAEhC,IAAe,4BAAf,cAAiD,aAA+C;CAM9F,qBAAmD;EACjD,OAAO,CAAC;GAAE,iBAAiB;GAAyB,QAAQ,KAAK;GAAa,CAAC;;CAGjF,SAAyB;EACvB,OAAO,OAAO,KAAK;;;AAYvB,IAAa,kBAAb,cAAqC,0BAA0B;CAC7D,cAAuB;CACvB,iBAA0B;CAC1B;CACA;CACA;CACA;CACA;CAEA,YACE,YACA,WACA,SACA,YACA;EACA,OAAO;EACP,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Content":["import type { Contract } from '@prisma-next/contract/types';\nimport { SqlContractSerializerBase } from '@prisma-next/family-sql/ir';\nimport {\n type Namespace,\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} from '@prisma-next/sql-contract/types';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n // Postgres entity types (enums) are namespace-level and hydrated in\n // hydrateSqlNamespaceEntry; there are no storage-level codec alias entities\n // specific to Postgres, so the registry is empty.\n super(new Map());\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 obj = raw as {\n id?: string;\n tables?: Record<string, unknown>;\n types?: Record<string, unknown>;\n };\n const id = obj.id ?? nsId;\n const tables = Object.fromEntries(\n Object.entries(obj.tables ?? {}).map(([tableName, table]) => [\n tableName,\n table instanceof StorageTable ? table : new StorageTable(table as StorageTableInput),\n ]),\n );\n const typeEntries = obj.types;\n const hydratedNsTypes =\n typeEntries !== undefined && Object.keys(typeEntries).length > 0\n ? Object.fromEntries(\n Object.entries(typeEntries).map(([typeName, entry]) => {\n if (entry instanceof PostgresEnumType) {\n return [typeName, entry];\n }\n const plain = entry as Record<string, unknown>;\n const name = typeof plain['name'] === 'string' ? plain['name'] : typeName;\n const nativeType =\n typeof plain['nativeType'] === 'string' ? plain['nativeType'] : name;\n const values = Array.isArray(plain['values']) ? (plain['values'] as string[]) : [];\n return [\n typeName,\n new PostgresEnumType({ name, nativeType, values } as PostgresEnumTypeInput),\n ];\n }),\n )\n : undefined;\n\n const emptyTables = Object.keys(tables).length === 0;\n const emptyTypes = !hydratedNsTypes || Object.keys(hydratedNsTypes).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyTypes) {\n return PostgresSchema.unbound;\n }\n return new PostgresSchema({\n id,\n tables,\n ...(hydratedNsTypes !== undefined ? { types: hydratedNsTypes } : {}),\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 // Family-level SqlNamespacePayload / SqlUnboundNamespace haven't\n // been promoted to a PostgresSchema instance yet (e.g. they came\n // straight from the TS builder, which uses the family-shared\n // SqlStorage constructor). Serialise them as postgres-schema /\n // postgres-unbound-schema so the round-trip through\n // deserializeContract hydrates them back into PostgresSchema\n // instances.\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n const nsTypes = (ns as { readonly types?: Readonly<Record<string, unknown>> }).types ?? {};\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n tables: Object.fromEntries(\n Object.entries(ns.tables).map(([tableName, table]) => [\n tableName,\n this.serializeJsonValue(table) as JsonObject,\n ]),\n ),\n types: Object.fromEntries(\n Object.entries(nsTypes).map(([typeName, entry]) => [\n typeName,\n this.serializeJsonValue(entry) as JsonObject,\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.tables)) {\n tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;\n }\n const typesOut: Record<string, JsonObject> = {};\n for (const [typeName, ty] of Object.entries(ns.types)) {\n typesOut[typeName] = this.serializeJsonValue(ty) as JsonObject;\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n tables: tablesOut,\n types: typesOut,\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;AAiBA,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,cAAc;EAIZ,sBAAM,IAAI,KAAK,CAAC;;CAGlB,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAET,MAAM,MAAM;EAKZ,MAAM,KAAK,IAAI,MAAM;EACrB,MAAM,SAAS,OAAO,YACpB,OAAO,QAAQ,IAAI,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,WAAW,CAC3D,WACA,iBAAiB,eAAe,QAAQ,IAAI,aAAa,MAA2B,CACrF,CAAC,CACH;EACD,MAAM,cAAc,IAAI;EACxB,MAAM,kBACJ,gBAAgB,KAAA,KAAa,OAAO,KAAK,YAAY,CAAC,SAAS,IAC3D,OAAO,YACL,OAAO,QAAQ,YAAY,CAAC,KAAK,CAAC,UAAU,WAAW;GACrD,IAAI,iBAAiB,kBACnB,OAAO,CAAC,UAAU,MAAM;GAE1B,MAAM,QAAQ;GACd,MAAM,OAAO,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU;GAIjE,OAAO,CACL,UACA,IAAI,iBAAiB;IAAE;IAAM,YAJ7B,OAAO,MAAM,kBAAkB,WAAW,MAAM,gBAAgB;IAIvB,QAH5B,MAAM,QAAQ,MAAM,UAAU,GAAI,MAAM,YAAyB,EAAE;IA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ACV;;CAGH,2BAAmC,IAAoB,eAAoC;EACzF,MAAM,YAAwC,EAAE;EAChD,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,OAAO,EACxD,UAAU,aAAa,KAAK,mBAAmB,MAAM;EAEvD,MAAM,WAAuC,EAAE;EAC/C,KAAK,MAAM,CAAC,UAAU,OAAO,OAAO,QAAQ,GAAG,MAAM,EACnD,SAAS,YAAY,KAAK,mBAAmB,GAAG;EAElD,OAAO;GACL,IAAI,GAAG;GACP,MAAM,gBAAgB,4BAA4B;GAClD,QAAQ;GACR,OAAO;GACR;;CAGH,mBAA2B,OAAyB;EAClD,OAAO,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-migration-C5os-tkl.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 type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\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 target-specific re-export of this\n * class from `@prisma-next/target-postgres/migration`, keeping the\n * authoring surface 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 ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,MAAM;EAIZ,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,MAAM,GAC5B,KAAA;;;;;;;CAQN,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,oCAAoC;EAE5C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-schema-BosNxhWq.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} from '@prisma-next/sql-contract/types';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly tables?: Record<string, StorageTable | StorageTableInput>;\n readonly types?: Record<string, PostgresEnumType | PostgresEnumTypeInput>;\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 * Qualifier emission is the rendering seam: DDL / SQL emission asks the\n * namespace for its qualifier (`\"<schema>\"`) or for a qualified table\n * name (`\"<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 readonly kind = 'schema' as const;\n readonly id: string;\n readonly tables: Readonly<Record<string, StorageTable>>;\n readonly types: Readonly<Record<string, PostgresEnumType>>;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n this.tables = Object.freeze(\n Object.fromEntries(\n Object.entries(input.tables ?? {}).map(([name, t]) => [\n name,\n t instanceof StorageTable ? t : new StorageTable(t),\n ]),\n ),\n );\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types ?? {}).map(([name, ty]) => [\n name,\n ty instanceof PostgresEnumType ? ty : new PostgresEnumType(ty),\n ]),\n ),\n );\n freezeNode(this);\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 unbound singleton overrides this to project\n * to `'public'` when a sibling public namespace exists in the same\n * contract — and falls back to the framework sentinel otherwise so\n * the planner can detect the missing-projection case explicitly.\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 */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID });\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 /**\n * The unbound slot has no schema name of its own, so DDL emission\n * projects it onto a sibling when one is available: if the contract\n * carries a `public` namespace, the late-bound slot resolves to\n * `'public'` (the default Postgres landing schema); otherwise it\n * resolves to the framework sentinel `UNBOUND_NAMESPACE_ID` so the\n * planner can recognise the unprojected case and route accordingly\n * (e.g. emit a conflict instead of silently picking a schema).\n */\n override ddlSchemaName(storage: SqlStorage): string {\n if (storage.namespaces['public'] !== undefined) {\n return 'public';\n }\n return UNBOUND_NAMESPACE_ID;\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 if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(input);\n }\n return new PostgresSchema(input);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,IAAa,iBAAb,cAAoC,cAAc;;;;;;;;CAQhD,OAAO;CAEP,OAAgB;CAChB;CACA;CACA;CAEA,YAAY,OAA4B;EACtC,OAAO;EACP,KAAK,KAAK,MAAM;EAChB,KAAK,SAAS,OAAO,OACnB,OAAO,YACL,OAAO,QAAQ,MAAM,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,OAAO,CACpD,MACA,aAAa,eAAe,IAAI,IAAI,aAAa,EAAE,CACpD,CAAC,CACH,CACF;EACD,KAAK,QAAQ,OAAO,OAClB,OAAO,YACL,OAAO,QAAQ,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,QAAQ,CACpD,MACA,cAAc,mBAAmB,KAAK,IAAI,iBAAiB,GAAG,CAC/D,CAAC,CACH,CACF;EACD,WAAW,KAAK;;;;;;;CAQlB,YAAoB;EAClB,OAAO,IAAI,KAAK,GAAG;;;;;;;;CASrB,aAAa,WAA2B;EACtC,OAAO,IAAI,KAAK,GAAG,KAAK,UAAU;;;;;;;;CASpC,gBAAgB,MAAsB;EACpC,OAAO,IAAI,cAAc,KAAK,aAAa,KAAK,CAAC,CAAC;;;;;;;;;;CAWpD,sBAA8B;EAC5B,OAAO,IAAI,cAAc,KAAK,GAAG,CAAC;;;;;;;;;;;;CAapC,cAAc,UAA8B;EAC1C,OAAO,KAAK;;;;;;;;;;;;;;;;;AAkBhB,IAAa,wBAAb,MAAa,8BAA8B,eAAe;CACxD,OAAgB,WAAkC,IAAI,uBAAuB;CAE7E,YAAY,OAA6B;EACvC,MAAM,SAAS,EAAE,IAAI,sBAAsB,CAAC;;CAG9C,YAA6B;EAC3B,OAAO;;CAGT,aAAsB,WAA2B;EAC/C,OAAO,IAAI,UAAU;;CAGvB,sBAAuC;EACrC,OAAO;;;;;;;;;;;CAYT,cAAuB,SAA6B;EAClD,IAAI,QAAQ,WAAW,cAAc,KAAA,GACnC,OAAO;EAET,OAAO;;;AAIX,eAAe,UAAU,sBAAsB;;;;;;;;;;AAW/C,SAAgB,iBAAiB,IAAmC;CAClE,OAAQ,IAA8C,SAAS;;;;;;;;;;;;;AAcjE,SAAgB,wBAAwB,OAAgD;CACtF,IAAI,MAAM,OAAO,sBACf,OAAO,IAAI,sBAAsB,MAAM;CAEzC,OAAO,IAAI,eAAe,MAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-typescript-nRHbqLbI.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, jsonToTsSource, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/target-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 target-owned 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/target-postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\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 buildImports(calls: ReadonlyArray<OpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\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\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n if (meta.labels && meta.labels.length > 0) {\n lines.push(` labels: ${jsonToTsSource(meta.labels)},`);\n }\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\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":";;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAA0C,QAAQ;CAAa,EAClF;CAAE,iBAAiB;CAA0C,QAAQ;CAAgB,CACtF;AAED,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,MAAM;CACnC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,kBAAkB,CAAC,CAAC,KAAK,MAAM;CAEzE,OAAO;EACL,eAAe,uBAAuB,CAAC;EACvC;EACA;EACA;EACA,oBAAoB,KAAK;EACzB;EACA;EACA,OAAO,gBAAgB,EAAE;EACzB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;;AAGd,SAAS,aAAa,OAA6C;CACjE,MAAM,eAAoC,CAAC,GAAG,aAAa;CAC3D,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,KAAK,oBAAoB,EACzC,aAAa,KAAK,IAAI;CAG1B,OAAO,cAAc,aAAa;;AAGpC,SAAS,oBAAoB,MAAmC;CAC9D,MAAM,QAAkB,EAAE;CAC1B,MAAM,KAAK,0BAA0B;CACrC,MAAM,KAAK,eAAe;CAC1B,MAAM,KAAK,eAAe,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG;CACvD,MAAM,KAAK,aAAa,KAAK,UAAU,KAAK,GAAG,CAAC,GAAG;CACnD,IAAI,KAAK,UAAU,KAAK,OAAO,SAAS,GACtC,MAAM,KAAK,iBAAiB,eAAe,KAAK,OAAO,CAAC,GAAG;CAE7D,MAAM,KAAK,SAAS;CACpB,MAAM,KAAK,MAAM;CACjB,MAAM,KAAK,GAAG;CACd,OAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,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