@prisma-next/target-postgres 0.13.0-dev.27 → 0.13.0-dev.29
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-C_-Hj6bL.mjs → codec-ids-BvytN2P8.mjs} +2 -3
- package/dist/codec-ids-BvytN2P8.mjs.map +1 -0
- package/dist/{codec-ids-BzrFF-I4.d.mts → codec-ids-CnXu9Qy3.d.mts} +2 -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-B0WT0obB.d.mts → codec-types-DHCkwPKE.d.mts} +2 -3
- package/dist/codec-types-DHCkwPKE.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-CX56Smsj.d.mts → codecs--0A5_4Bq.d.mts} +3 -23
- package/dist/codecs--0A5_4Bq.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +2 -38
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.mjs +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +7 -10
- package/dist/control.mjs.map +1 -1
- package/dist/{descriptor-meta-C7O6XHfh.mjs → descriptor-meta-BKma_hQ5.mjs} +2 -2
- package/dist/{descriptor-meta-C7O6XHfh.mjs.map → descriptor-meta-BKma_hQ5.mjs.map} +1 -1
- package/dist/{descriptor-meta-runtime-BToWdas9.mjs → descriptor-meta-runtime-e5f2tscJ.mjs} +2 -39
- package/dist/descriptor-meta-runtime-e5f2tscJ.mjs.map +1 -0
- package/dist/{issue-planner-CK-XWGB0.mjs → issue-planner-DsjB7xDj.mjs} +17 -227
- 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 +1 -11
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +3 -3
- package/dist/{op-factory-call-DxjpXw-A.d.mts → op-factory-call-CdtMyrlU.d.mts} +3 -48
- package/dist/{op-factory-call-DxjpXw-A.d.mts.map → op-factory-call-CdtMyrlU.d.mts.map} +1 -1
- package/dist/{op-factory-call-CHvtj70z.mjs → op-factory-call-CjR846f7.mjs} +4 -159
- 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 +2 -18
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-4FbY_95H.mjs → planner-_FOL4I21.mjs} +9 -41
- 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-qfkCkGVe.mjs → planner-produced-postgres-migration-BmCpyWLJ.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-qfkCkGVe.mjs.map → planner-produced-postgres-migration-BmCpyWLJ.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-BLgdXLsA.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.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-CTxVcCVW.mjs → postgres-contract-serializer-CyAe8ZFv.mjs} +12 -29
- package/dist/postgres-contract-serializer-CyAe8ZFv.mjs.map +1 -0
- package/dist/{postgres-migration-DF5ApLqQ.mjs → postgres-migration-dG-J0aI8.mjs} +2 -2
- package/dist/{postgres-migration-DF5ApLqQ.mjs.map → postgres-migration-dG-J0aI8.mjs.map} +1 -1
- package/dist/{postgres-schema-C7c9rhGk.mjs → postgres-schema-CTKYiTHu.mjs} +7 -21
- package/dist/postgres-schema-CTKYiTHu.mjs.map +1 -0
- package/dist/runtime.d.mts +0 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/types.d.mts +5 -25
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -4
- package/package.json +17 -18
- package/src/core/authoring.ts +1 -44
- package/src/core/codec-helpers.ts +0 -17
- package/src/core/codec-ids.ts +0 -1
- package/src/core/codec-type-map.ts +0 -2
- package/src/core/codecs.ts +0 -49
- package/src/core/migrations/control-policy.ts +3 -45
- package/src/core/migrations/issue-planner.ts +9 -52
- package/src/core/migrations/op-factory-call.ts +2 -124
- 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-recipes.ts +2 -6
- package/src/core/migrations/planner-sql-checks.ts +2 -6
- package/src/core/migrations/planner-strategies.ts +13 -353
- package/src/core/migrations/planner-type-resolution.ts +2 -20
- package/src/core/migrations/planner.ts +0 -2
- package/src/core/migrations/runner.ts +0 -4
- package/src/core/postgres-contract-serializer.ts +9 -67
- package/src/core/postgres-schema.ts +6 -37
- package/src/exports/codecs.ts +0 -2
- package/src/exports/control.ts +0 -15
- package/src/exports/migration.ts +0 -6
- package/src/exports/op-factory-call.ts +0 -4
- package/src/exports/types.ts +0 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +0 -1
- package/dist/codec-ids-C_-Hj6bL.mjs.map +0 -1
- package/dist/codec-types-B0WT0obB.d.mts.map +0 -1
- package/dist/codecs-CX56Smsj.d.mts.map +0 -1
- package/dist/descriptor-meta-runtime-BToWdas9.mjs.map +0 -1
- package/dist/enum-planning-D8z4FH7y.mjs +0 -129
- package/dist/enum-planning-D8z4FH7y.mjs.map +0 -1
- package/dist/enum-planning.d.mts +0 -92
- package/dist/enum-planning.d.mts.map +0 -1
- package/dist/enum-planning.mjs +0 -2
- package/dist/issue-planner-CK-XWGB0.mjs.map +0 -1
- package/dist/op-factory-call-CHvtj70z.mjs.map +0 -1
- package/dist/planner-4FbY_95H.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-sql-checks-BLgdXLsA.mjs.map +0 -1
- package/dist/planner-type-resolution-836DExFN.mjs.map +0 -1
- package/dist/postgres-contract-serializer-CTxVcCVW.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-enum-type-schema-DZBTtvBF.mjs +0 -20
- package/dist/postgres-enum-type-schema-DZBTtvBF.mjs.map +0 -1
- package/dist/postgres-schema-C7c9rhGk.mjs.map +0 -1
- package/src/core/migrations/enum-planning.ts +0 -217
- 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 -10
|
@@ -1,4 +1,4 @@
|
|
|
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
3
|
import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
|
|
4
4
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
@@ -72,4 +72,4 @@ var PostgresMigration = class extends Migration {
|
|
|
72
72
|
//#endregion
|
|
73
73
|
export { PostgresMigration as t };
|
|
74
74
|
|
|
75
|
-
//# sourceMappingURL=postgres-migration-
|
|
75
|
+
//# sourceMappingURL=postgres-migration-dG-J0aI8.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-migration-
|
|
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,4 +1,3 @@
|
|
|
1
|
-
import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
|
|
2
1
|
import { n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
2
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
3
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -11,7 +10,7 @@ import { StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
|
|
|
11
10
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
12
11
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
13
12
|
*
|
|
14
|
-
* `entries` holds entity-kind maps (`table`, `
|
|
13
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
15
14
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
16
15
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
17
16
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -35,16 +34,11 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
35
34
|
this.id = input.id;
|
|
36
35
|
const carried = {};
|
|
37
36
|
let table = Object.freeze({});
|
|
38
|
-
let type = Object.freeze({});
|
|
39
37
|
let valueSet;
|
|
40
38
|
for (const [kind, rawMap] of Object.entries(input.entries)) if (kind === "table") {
|
|
41
39
|
const tableMap = {};
|
|
42
40
|
for (const [name, v] of Object.entries(blindCast(rawMap))) tableMap[name] = new StorageTable(v);
|
|
43
41
|
table = Object.freeze(tableMap);
|
|
44
|
-
} else if (kind === "type") {
|
|
45
|
-
const typeMap = {};
|
|
46
|
-
for (const [name, v] of Object.entries(blindCast(rawMap))) typeMap[name] = new PostgresEnumType(v);
|
|
47
|
-
type = Object.freeze(typeMap);
|
|
48
42
|
} else if (kind === "valueSet") {
|
|
49
43
|
const vsMap = {};
|
|
50
44
|
for (const [name, v] of Object.entries(blindCast(rawMap))) vsMap[name] = new StorageValueSet(v);
|
|
@@ -53,7 +47,6 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
53
47
|
this.entries = Object.freeze({
|
|
54
48
|
...carried,
|
|
55
49
|
table,
|
|
56
|
-
type,
|
|
57
50
|
...ifDefined("valueSet", valueSet)
|
|
58
51
|
});
|
|
59
52
|
Object.defineProperty(this, "kind", {
|
|
@@ -65,13 +58,10 @@ var PostgresSchema = class extends NamespaceBase {
|
|
|
65
58
|
freezeNode(this);
|
|
66
59
|
}
|
|
67
60
|
get table() {
|
|
68
|
-
return this.entries
|
|
69
|
-
}
|
|
70
|
-
get type() {
|
|
71
|
-
return this.entries.type ?? Object.freeze({});
|
|
61
|
+
return this.entries["table"] ?? Object.freeze({});
|
|
72
62
|
}
|
|
73
63
|
get valueSet() {
|
|
74
|
-
return this.entries
|
|
64
|
+
return this.entries["valueSet"];
|
|
75
65
|
}
|
|
76
66
|
/**
|
|
77
67
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
@@ -149,10 +139,7 @@ var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
|
|
|
149
139
|
constructor(input) {
|
|
150
140
|
super(input ?? {
|
|
151
141
|
id: UNBOUND_NAMESPACE_ID,
|
|
152
|
-
entries: {
|
|
153
|
-
table: {},
|
|
154
|
-
type: {}
|
|
155
|
-
}
|
|
142
|
+
entries: { table: {} }
|
|
156
143
|
});
|
|
157
144
|
}
|
|
158
145
|
qualifier() {
|
|
@@ -189,13 +176,12 @@ function isPostgresSchema(ns) {
|
|
|
189
176
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
190
177
|
* be value-stable for a given input set.
|
|
191
178
|
*/
|
|
192
|
-
function postgresCreateNamespace(input
|
|
179
|
+
function postgresCreateNamespace(input) {
|
|
193
180
|
const schemaInput = {
|
|
194
181
|
id: input.id,
|
|
195
182
|
entries: {
|
|
196
183
|
...input.entries,
|
|
197
|
-
table: input.entries["table"] ?? {}
|
|
198
|
-
type: blindCast(enumTypes ?? {})
|
|
184
|
+
table: input.entries["table"] ?? {}
|
|
199
185
|
}
|
|
200
186
|
};
|
|
201
187
|
if (input.id === UNBOUND_NAMESPACE_ID) return new PostgresUnboundSchema(schemaInput);
|
|
@@ -204,4 +190,4 @@ function postgresCreateNamespace(input, enumTypes) {
|
|
|
204
190
|
//#endregion
|
|
205
191
|
export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
|
|
206
192
|
|
|
207
|
-
//# 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"}
|
package/dist/runtime.d.mts
CHANGED
|
@@ -8,9 +8,7 @@ import { JsonObject } from "@prisma-next/utils/json";
|
|
|
8
8
|
|
|
9
9
|
//#region src/core/postgres-contract-serializer.d.ts
|
|
10
10
|
declare class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {
|
|
11
|
-
private readonly enumFactory;
|
|
12
11
|
constructor();
|
|
13
|
-
protected hydrateEntriesKind(key: string, innerMap: unknown): Record<string, unknown> | undefined;
|
|
14
12
|
protected hydrateSqlNamespaceEntry(nsId: string, raw: Namespace | Record<string, unknown>): Namespace | SqlNamespaceTablesInput;
|
|
15
13
|
serializeContract(contract: Contract<SqlStorage>): JsonObject;
|
|
16
14
|
private serializePostgresNamespace;
|
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
|
package/dist/types.d.mts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
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
|
-
//#region src/core/postgres-enum-type-schema.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Arktype validator for a `postgres-enum` entry under
|
|
9
|
-
* `storage.namespaces[id].entries.type[name]`. Registered by the Postgres
|
|
10
|
-
* target pack against the `'type'` entries key so the family-layer namespace
|
|
11
|
-
* validator accepts (and rejects) entries of this kind.
|
|
12
|
-
*/
|
|
13
|
-
declare const PostgresEnumTypeSchema: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
14
|
-
kind: "postgres-enum";
|
|
15
|
-
values: readonly string[];
|
|
16
|
-
name?: string;
|
|
17
|
-
nativeType?: string;
|
|
18
|
-
control?: "managed" | "tolerated" | "external" | "observed";
|
|
19
|
-
}, {}>;
|
|
20
|
-
//#endregion
|
|
21
5
|
//#region src/core/postgres-schema.d.ts
|
|
22
|
-
type PostgresNamespaceEntries = SqlNamespaceEntries & {
|
|
23
|
-
readonly type?: Readonly<Record<string, PostgresEnumType>>;
|
|
24
|
-
};
|
|
25
6
|
interface PostgresSchemaInput {
|
|
26
7
|
readonly id: string;
|
|
27
8
|
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
@@ -32,7 +13,7 @@ interface PostgresSchemaInput {
|
|
|
32
13
|
* `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
|
|
33
14
|
* the Postgres PSL interpreter from `namespace { … }` AST buckets.
|
|
34
15
|
*
|
|
35
|
-
* `entries` holds entity-kind maps (`table`, `
|
|
16
|
+
* `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
|
|
36
17
|
* emission is the rendering seam: DDL / SQL emission asks the namespace
|
|
37
18
|
* for its qualifier (`"<schema>"`) or for a qualified table name
|
|
38
19
|
* (`"<schema>"."<table>"`) and consumes the result polymorphically.
|
|
@@ -51,10 +32,9 @@ declare class PostgresSchema extends NamespaceBase {
|
|
|
51
32
|
static unbound: PostgresUnboundSchema;
|
|
52
33
|
readonly kind: 'schema';
|
|
53
34
|
readonly id: string;
|
|
54
|
-
readonly entries:
|
|
35
|
+
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
55
36
|
constructor(input: PostgresSchemaInput);
|
|
56
37
|
get table(): Readonly<Record<string, StorageTable>>;
|
|
57
|
-
get type(): Readonly<Record<string, PostgresEnumType>>;
|
|
58
38
|
get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
|
|
59
39
|
/**
|
|
60
40
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
@@ -135,7 +115,7 @@ declare class PostgresUnboundSchema extends PostgresSchema {
|
|
|
135
115
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
136
116
|
* be value-stable for a given input set.
|
|
137
117
|
*/
|
|
138
|
-
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput
|
|
118
|
+
declare function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema;
|
|
139
119
|
//#endregion
|
|
140
|
-
export { type PostgresColumnDefault,
|
|
120
|
+
export { type PostgresColumnDefault, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
141
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-
|
|
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,4 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-C7c9rhGk.mjs";
|
|
4
|
-
export { PostgresEnumType, PostgresEnumTypeSchema, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
|
1
|
+
import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-CTKYiTHu.mjs";
|
|
2
|
+
export { PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.13.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.13.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.13.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.13.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.13.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.13.0-dev.
|
|
15
|
-
"@prisma-next/ts-render": "0.13.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.13.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.13.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.13.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.13.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.13.0-dev.
|
|
21
|
-
"@prisma-next/utils": "0.13.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.13.0-dev.29",
|
|
10
|
+
"@prisma-next/contract": "0.13.0-dev.29",
|
|
11
|
+
"@prisma-next/errors": "0.13.0-dev.29",
|
|
12
|
+
"@prisma-next/family-sql": "0.13.0-dev.29",
|
|
13
|
+
"@prisma-next/framework-components": "0.13.0-dev.29",
|
|
14
|
+
"@prisma-next/migration-tools": "0.13.0-dev.29",
|
|
15
|
+
"@prisma-next/ts-render": "0.13.0-dev.29",
|
|
16
|
+
"@prisma-next/sql-contract": "0.13.0-dev.29",
|
|
17
|
+
"@prisma-next/sql-errors": "0.13.0-dev.29",
|
|
18
|
+
"@prisma-next/sql-operations": "0.13.0-dev.29",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.13.0-dev.29",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.13.0-dev.29",
|
|
21
|
+
"@prisma-next/utils": "0.13.0-dev.29",
|
|
22
22
|
"@standard-schema/spec": "^1.1.0",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"pathe": "^2.0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@prisma-next/test-utils": "0.13.0-dev.
|
|
28
|
-
"@prisma-next/tsconfig": "0.13.0-dev.
|
|
29
|
-
"@prisma-next/tsdown": "0.13.0-dev.
|
|
27
|
+
"@prisma-next/test-utils": "0.13.0-dev.29",
|
|
28
|
+
"@prisma-next/tsconfig": "0.13.0-dev.29",
|
|
29
|
+
"@prisma-next/tsdown": "0.13.0-dev.29",
|
|
30
30
|
"tsdown": "0.22.1",
|
|
31
31
|
"typescript": "5.9.3",
|
|
32
32
|
"vitest": "4.1.8"
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"./data-transform": "./dist/data-transform.mjs",
|
|
54
54
|
"./ddl": "./dist/ddl.mjs",
|
|
55
55
|
"./default-normalizer": "./dist/default-normalizer.mjs",
|
|
56
|
-
"./enum-planning": "./dist/enum-planning.mjs",
|
|
57
56
|
"./errors": "./dist/errors.mjs",
|
|
58
57
|
"./issue-planner": "./dist/issue-planner.mjs",
|
|
59
58
|
"./migration": "./dist/migration.mjs",
|
package/src/core/authoring.ts
CHANGED
|
@@ -4,53 +4,10 @@ import type {
|
|
|
4
4
|
AuthoringFieldNamespace,
|
|
5
5
|
AuthoringTypeNamespace,
|
|
6
6
|
} from '@prisma-next/framework-components/authoring';
|
|
7
|
-
import type { PostgresEnumStorageEntry } from '@prisma-next/sql-contract/types';
|
|
8
|
-
import { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';
|
|
9
|
-
import { PostgresEnumTypeSchema } from './postgres-enum-type-schema';
|
|
10
7
|
|
|
11
8
|
export const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
* Entity type contributions surface as top-level helpers on the
|
|
15
|
-
* composed-helpers shape (e.g. `helpers.enum({...})`), flattened
|
|
16
|
-
* alongside the built-in `model` / `rel` helpers. Pack contributions
|
|
17
|
-
* still ship via the contribution data structure
|
|
18
|
-
* `authoring.entityTypes.<name>`; the composed-helpers template
|
|
19
|
-
* performs the rename in the type system.
|
|
20
|
-
*
|
|
21
|
-
* `enum` is the first real consumer of the entities-namespace mechanism:
|
|
22
|
-
* the factory constructs a `PostgresEnumType` IR-class instance from
|
|
23
|
-
* the user-supplied input. Both authoring runtimes (TS DSL and PSL)
|
|
24
|
-
* dispatch through this single contribution — PSL `enum Status { … }`
|
|
25
|
-
* declarations are lowered by the interpreter into a factory call
|
|
26
|
-
* with the parsed name + value list; TS DSL `helpers.enum({...})`
|
|
27
|
-
* resolves through the same path. Removing this contribution makes
|
|
28
|
-
* both surfaces fail with a "no entity helper named `enum`" type
|
|
29
|
-
* error at the contract-definition site.
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* The factory constructs a `PostgresEnumType` instance natively — the
|
|
33
|
-
* `SqlStorage.types` slot accepts polymorphic IR (the framework
|
|
34
|
-
* `StorageType` alphabet), so no cast is needed at the contribution
|
|
35
|
-
* surface. The declared return type is the structural
|
|
36
|
-
* `PostgresEnumStorageEntry` so the inferred contract type stays
|
|
37
|
-
* portable (it names a type exported from
|
|
38
|
-
* `@prisma-next/sql-contract/types`, a public surface every consumer
|
|
39
|
-
* already imports). Sharpening the inferred contract type to surface
|
|
40
|
-
* enum-specific narrowing through `EntityHelperFunction` is a
|
|
41
|
-
* separable refinement and lives outside this PR.
|
|
42
|
-
*/
|
|
43
|
-
export const postgresAuthoringEntityTypes = {
|
|
44
|
-
enum: {
|
|
45
|
-
kind: 'entity',
|
|
46
|
-
discriminator: 'postgres-enum',
|
|
47
|
-
validatorSchema: PostgresEnumTypeSchema,
|
|
48
|
-
output: {
|
|
49
|
-
factory: (input: PostgresEnumTypeInput): PostgresEnumStorageEntry =>
|
|
50
|
-
new PostgresEnumType(input),
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
} as const satisfies AuthoringEntityTypeNamespace;
|
|
10
|
+
export const postgresAuthoringEntityTypes = {} as const satisfies AuthoringEntityTypeNamespace;
|
|
54
11
|
|
|
55
12
|
/**
|
|
56
13
|
* Field presets contributed by the Postgres target pack.
|
|
@@ -109,23 +109,6 @@ export const pgIntervalDecode = (wire: string | Record<string, unknown>): string
|
|
|
109
109
|
return JSON.stringify(wire);
|
|
110
110
|
};
|
|
111
111
|
|
|
112
|
-
export const pgEnumRenderOutputType = (typeParams: {
|
|
113
|
-
readonly values?: readonly unknown[];
|
|
114
|
-
}): string => {
|
|
115
|
-
const values = typeParams.values;
|
|
116
|
-
if (!Array.isArray(values)) {
|
|
117
|
-
throw new Error(
|
|
118
|
-
`renderOutputType: expected array "values" in typeParams for enum, got ${typeof values}`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
if (!values.every((v): v is string => typeof v === 'string')) {
|
|
122
|
-
throw new Error(`renderOutputType: expected string[] "values" in typeParams for enum`);
|
|
123
|
-
}
|
|
124
|
-
return values
|
|
125
|
-
.map((value) => `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`)
|
|
126
|
-
.join(' | ');
|
|
127
|
-
};
|
|
128
|
-
|
|
129
112
|
export const pgJsonEncode = (value: string | JsonValue): string => JSON.stringify(value);
|
|
130
113
|
export const pgJsonDecode = (wire: string | JsonValue): JsonValue =>
|
|
131
114
|
typeof wire === 'string' ? JSON.parse(wire) : wire;
|
package/src/core/codec-ids.ts
CHANGED
|
@@ -8,7 +8,6 @@ export {
|
|
|
8
8
|
} from '@prisma-next/sql-relational-core/ast';
|
|
9
9
|
export const PG_TEXT_CODEC_ID = 'pg/text@1' as const;
|
|
10
10
|
export const PG_TEXT_ARRAY_CODEC_ID = 'pg/text-array@1' as const;
|
|
11
|
-
export const PG_ENUM_CODEC_ID = 'pg/enum@1' as const;
|
|
12
11
|
export const PG_CHAR_CODEC_ID = 'pg/char@1' as const;
|
|
13
12
|
export const PG_VARCHAR_CODEC_ID = 'pg/varchar@1' as const;
|
|
14
13
|
export const PG_INT_CODEC_ID = 'pg/int@1' as const;
|
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
pgBoolDescriptor,
|
|
22
22
|
pgByteaDescriptor,
|
|
23
23
|
pgCharDescriptor,
|
|
24
|
-
pgEnumDescriptor,
|
|
25
24
|
pgFloat4Descriptor,
|
|
26
25
|
pgFloat8Descriptor,
|
|
27
26
|
pgFloatDescriptor,
|
|
@@ -71,7 +70,6 @@ export const codecDescriptorMap = {
|
|
|
71
70
|
bytea: pgByteaDescriptor,
|
|
72
71
|
uuid: pgUuidDescriptor,
|
|
73
72
|
interval: pgIntervalDescriptor,
|
|
74
|
-
enum: pgEnumDescriptor,
|
|
75
73
|
json: pgJsonDescriptor,
|
|
76
74
|
jsonb: pgJsonbDescriptor,
|
|
77
75
|
} as const;
|
package/src/core/codecs.ts
CHANGED
|
@@ -40,7 +40,6 @@ import { blindCast } from '@prisma-next/utils/casts';
|
|
|
40
40
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
41
41
|
import { type as arktype } from 'arktype';
|
|
42
42
|
import {
|
|
43
|
-
pgEnumRenderOutputType,
|
|
44
43
|
pgIntervalDecode,
|
|
45
44
|
pgJsonbDecode,
|
|
46
45
|
pgJsonbEncode,
|
|
@@ -60,7 +59,6 @@ import {
|
|
|
60
59
|
PG_BOOL_CODEC_ID,
|
|
61
60
|
PG_BYTEA_CODEC_ID,
|
|
62
61
|
PG_CHAR_CODEC_ID,
|
|
63
|
-
PG_ENUM_CODEC_ID,
|
|
64
62
|
PG_FLOAT_CODEC_ID,
|
|
65
63
|
PG_FLOAT4_CODEC_ID,
|
|
66
64
|
PG_FLOAT8_CODEC_ID,
|
|
@@ -86,7 +84,6 @@ import {
|
|
|
86
84
|
type LengthParams = { readonly length?: number };
|
|
87
85
|
type PrecisionParams = { readonly precision?: number };
|
|
88
86
|
type NumericParams = { readonly precision: number; readonly scale?: number };
|
|
89
|
-
type EnumParams = { readonly values?: readonly string[] };
|
|
90
87
|
|
|
91
88
|
const lengthParamsSchema = arktype({
|
|
92
89
|
'length?': 'number.integer > 0',
|
|
@@ -875,51 +872,6 @@ export const pgIntervalColumn = (params: PrecisionParams = {}) =>
|
|
|
875
872
|
pgIntervalColumn satisfies ColumnHelperFor<PgIntervalDescriptor>;
|
|
876
873
|
pgIntervalColumn satisfies ColumnHelperForStrict<PgIntervalDescriptor>;
|
|
877
874
|
|
|
878
|
-
const enumParamsSchema = arktype({
|
|
879
|
-
'values?': 'string[]',
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
export class PgEnumCodec extends CodecImpl<
|
|
883
|
-
typeof PG_ENUM_CODEC_ID,
|
|
884
|
-
readonly ['equality', 'order'],
|
|
885
|
-
string,
|
|
886
|
-
string
|
|
887
|
-
> {
|
|
888
|
-
async encode(value: string, _ctx: CodecCallContext): Promise<string> {
|
|
889
|
-
return value;
|
|
890
|
-
}
|
|
891
|
-
async decode(wire: string, _ctx: CodecCallContext): Promise<string> {
|
|
892
|
-
return wire;
|
|
893
|
-
}
|
|
894
|
-
encodeJson(value: string): JsonValue {
|
|
895
|
-
return value;
|
|
896
|
-
}
|
|
897
|
-
decodeJson(json: JsonValue): string {
|
|
898
|
-
return json as string;
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
export class PgEnumDescriptor extends CodecDescriptorImpl<EnumParams> {
|
|
903
|
-
override readonly codecId = PG_ENUM_CODEC_ID;
|
|
904
|
-
override readonly traits = ['equality', 'order'] as const;
|
|
905
|
-
override readonly targetTypes = ['enum'] as const;
|
|
906
|
-
override readonly paramsSchema = enumParamsSchema satisfies StandardSchemaV1<EnumParams>;
|
|
907
|
-
override renderOutputType(params: EnumParams): string | undefined {
|
|
908
|
-
return pgEnumRenderOutputType(params);
|
|
909
|
-
}
|
|
910
|
-
override factory(_params: EnumParams): (ctx: CodecInstanceContext) => PgEnumCodec {
|
|
911
|
-
return () => new PgEnumCodec(this);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
export const pgEnumDescriptor = new PgEnumDescriptor();
|
|
916
|
-
|
|
917
|
-
export const pgEnumColumn = (params: EnumParams = {}) =>
|
|
918
|
-
column(pgEnumDescriptor.factory(params), pgEnumDescriptor.codecId, params, 'enum');
|
|
919
|
-
|
|
920
|
-
pgEnumColumn satisfies ColumnHelperFor<PgEnumDescriptor>;
|
|
921
|
-
pgEnumColumn satisfies ColumnHelperForStrict<PgEnumDescriptor>;
|
|
922
|
-
|
|
923
875
|
export class PgJsonCodec extends CodecImpl<
|
|
924
876
|
typeof PG_JSON_CODEC_ID,
|
|
925
877
|
readonly [],
|
|
@@ -1120,7 +1072,6 @@ export const codecDescriptors: readonly AnyCodecDescriptor[] = [
|
|
|
1120
1072
|
pgByteaDescriptor,
|
|
1121
1073
|
pgUuidDescriptor,
|
|
1122
1074
|
pgIntervalDescriptor,
|
|
1123
|
-
pgEnumDescriptor,
|
|
1124
1075
|
pgJsonDescriptor,
|
|
1125
1076
|
pgJsonbDescriptor,
|
|
1126
1077
|
pgTextArrayDescriptor,
|
|
@@ -2,11 +2,7 @@ import type { Contract } from '@prisma-next/contract/types';
|
|
|
2
2
|
import type { ControlPolicySubject } from '@prisma-next/family-sql/control';
|
|
3
3
|
import type { SchemaIssue } from '@prisma-next/framework-components/control';
|
|
4
4
|
import { entityAt, UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
5
|
-
import {
|
|
6
|
-
isPostgresEnumStorageEntry,
|
|
7
|
-
type SqlStorage,
|
|
8
|
-
type StorageTable,
|
|
9
|
-
} from '@prisma-next/sql-contract/types';
|
|
5
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
10
6
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
11
7
|
import { isPostgresSchema } from '../postgres-schema';
|
|
12
8
|
import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
@@ -24,7 +20,6 @@ import type { PostgresOpFactoryCall } from './op-factory-call';
|
|
|
24
20
|
*/
|
|
25
21
|
const OBJECT_CREATION_FACTORIES: ReadonlySet<string> = new Set<string>([
|
|
26
22
|
'createTable',
|
|
27
|
-
'createEnumType',
|
|
28
23
|
'createSchema',
|
|
29
24
|
]);
|
|
30
25
|
|
|
@@ -79,7 +74,6 @@ interface PostgresCallFields {
|
|
|
79
74
|
readonly schemaName?: string;
|
|
80
75
|
readonly tableName?: string;
|
|
81
76
|
readonly columnName?: string;
|
|
82
|
-
readonly typeName?: string;
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
function postgresCallFields(call: PostgresOpFactoryCall): PostgresCallFields {
|
|
@@ -87,7 +81,6 @@ function postgresCallFields(call: PostgresOpFactoryCall): PostgresCallFields {
|
|
|
87
81
|
...ifDefined('schemaName', 'schemaName' in call ? call.schemaName : undefined),
|
|
88
82
|
...ifDefined('tableName', 'tableName' in call ? call.tableName : undefined),
|
|
89
83
|
...ifDefined('columnName', 'columnName' in call ? call.columnName : undefined),
|
|
90
|
-
...ifDefined('typeName', 'typeName' in call ? call.typeName : undefined),
|
|
91
84
|
};
|
|
92
85
|
}
|
|
93
86
|
|
|
@@ -100,10 +93,6 @@ export function formatPostgresControlPolicySubjectLabel(
|
|
|
100
93
|
const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);
|
|
101
94
|
return `${factoryName}(${ddlSchema}.${subject.table})`;
|
|
102
95
|
}
|
|
103
|
-
if (subject?.typeName) {
|
|
104
|
-
const ddlSchema = ddlSchemaNameForNamespace(contract, subject.namespaceId);
|
|
105
|
-
return `${factoryName}(${ddlSchema}.${subject.typeName})`;
|
|
106
|
-
}
|
|
107
96
|
return factoryName;
|
|
108
97
|
}
|
|
109
98
|
|
|
@@ -121,33 +110,17 @@ export function resolvePostgresCallControlPolicySubject(
|
|
|
121
110
|
};
|
|
122
111
|
}
|
|
123
112
|
|
|
124
|
-
if (callFields.typeName && call.factoryName !== 'addColumn') {
|
|
125
|
-
const namespaceId = callFields.schemaName
|
|
126
|
-
? resolveNamespaceIdForDdlSchema(contract, callFields.schemaName)
|
|
127
|
-
: UNBOUND_NAMESPACE_ID;
|
|
128
|
-
const ns = contract.storage.namespaces[namespaceId];
|
|
129
|
-
const rawEnum = isPostgresSchema(ns) ? ns.type[callFields.typeName] : undefined;
|
|
130
|
-
const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;
|
|
131
|
-
return {
|
|
132
|
-
namespaceId,
|
|
133
|
-
...ifDefined('explicitNodeControlPolicy', controlPolicy),
|
|
134
|
-
typeName: callFields.typeName,
|
|
135
|
-
createsNewObject,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
113
|
if (callFields.tableName) {
|
|
140
114
|
const namespaceId = resolveNamespaceIdForTable(
|
|
141
115
|
contract,
|
|
142
116
|
callFields.tableName,
|
|
143
117
|
callFields.schemaName,
|
|
144
118
|
);
|
|
145
|
-
const
|
|
119
|
+
const tableControlPolicy = entityAt<StorageTable>(contract.storage, {
|
|
146
120
|
namespaceId,
|
|
147
121
|
entityKind: 'table',
|
|
148
122
|
entityName: callFields.tableName,
|
|
149
|
-
});
|
|
150
|
-
const tableControlPolicy = table?.control;
|
|
123
|
+
})?.control;
|
|
151
124
|
return {
|
|
152
125
|
namespaceId,
|
|
153
126
|
...ifDefined('explicitNodeControlPolicy', tableControlPolicy),
|
|
@@ -178,7 +151,6 @@ export function resolvePostgresCallControlPolicySubject(
|
|
|
178
151
|
const POSTGRES_ISSUE_CREATION_FACTORY: Readonly<Record<string, string>> = Object.freeze({
|
|
179
152
|
missing_schema: 'createSchema',
|
|
180
153
|
missing_table: 'createTable',
|
|
181
|
-
type_missing: 'createEnumType',
|
|
182
154
|
});
|
|
183
155
|
|
|
184
156
|
export function resolvePostgresIssueCreationFactoryName(issue: SchemaIssue): string | undefined {
|
|
@@ -209,20 +181,6 @@ export function resolvePostgresIssueControlPolicySubject(
|
|
|
209
181
|
return { namespaceId: issue.namespaceId, createsNewObject };
|
|
210
182
|
}
|
|
211
183
|
|
|
212
|
-
if ('typeName' in issue && issue.typeName) {
|
|
213
|
-
const namespaceId =
|
|
214
|
-
'namespaceId' in issue && issue.namespaceId ? issue.namespaceId : UNBOUND_NAMESPACE_ID;
|
|
215
|
-
const ns = contract.storage.namespaces[namespaceId];
|
|
216
|
-
const rawEnum = isPostgresSchema(ns) ? ns.type[issue.typeName] : undefined;
|
|
217
|
-
const controlPolicy = isPostgresEnumStorageEntry(rawEnum) ? rawEnum.control : undefined;
|
|
218
|
-
return {
|
|
219
|
-
namespaceId,
|
|
220
|
-
...ifDefined('explicitNodeControlPolicy', controlPolicy),
|
|
221
|
-
typeName: issue.typeName,
|
|
222
|
-
createsNewObject,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
184
|
if ('table' in issue && issue.table) {
|
|
227
185
|
const namespaceId =
|
|
228
186
|
'namespaceId' in issue && issue.namespaceId
|