@prisma-next/target-postgres 0.14.0-dev.31 → 0.14.0-dev.33

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.
Files changed (45) hide show
  1. package/dist/{descriptor-meta-runtime-D5zHFKUz.mjs → authoring-CZmSQriw.mjs} +2 -10
  2. package/dist/authoring-CZmSQriw.mjs.map +1 -0
  3. package/dist/control.mjs +4 -4
  4. package/dist/{descriptor-meta-Dvvpu_jU.mjs → descriptor-meta-Du6olWQI.mjs} +3 -2
  5. package/dist/{descriptor-meta-Dvvpu_jU.mjs.map → descriptor-meta-Du6olWQI.mjs.map} +1 -1
  6. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  7. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  8. package/dist/migration.d.mts +1 -1
  9. package/dist/migration.mjs +1 -1
  10. package/dist/pack.mjs +1 -1
  11. package/dist/{planner-BnNEtGYM.mjs → planner-D3Pl8LXU.mjs} +2 -2
  12. package/dist/{planner-BnNEtGYM.mjs.map → planner-D3Pl8LXU.mjs.map} +1 -1
  13. package/dist/{planner-produced-postgres-migration-BO-frvvN.d.mts → planner-produced-postgres-migration-BauTSigX.d.mts} +3 -3
  14. package/dist/{planner-produced-postgres-migration-BO-frvvN.d.mts.map → planner-produced-postgres-migration-BauTSigX.d.mts.map} +1 -1
  15. package/dist/{planner-produced-postgres-migration-DzvdQ-7K.mjs → planner-produced-postgres-migration-Bbv8RYKJ.mjs} +3 -3
  16. package/dist/{planner-produced-postgres-migration-DzvdQ-7K.mjs.map → planner-produced-postgres-migration-Bbv8RYKJ.mjs.map} +1 -1
  17. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  18. package/dist/planner-produced-postgres-migration.mjs +1 -1
  19. package/dist/planner.d.mts +1 -1
  20. package/dist/planner.mjs +1 -1
  21. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  22. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  23. package/dist/{postgres-contract-serializer-tGMiJcl4.mjs → postgres-contract-view-D12LEXT5.mjs} +16 -3
  24. package/dist/postgres-contract-view-D12LEXT5.mjs.map +1 -0
  25. package/dist/{postgres-migration-C8JZyTSJ.mjs → postgres-migration-DEefginX.mjs} +20 -1
  26. package/dist/postgres-migration-DEefginX.mjs.map +1 -0
  27. package/dist/{postgres-migration-Cs7zMOe1.d.mts → postgres-migration-UtGCjw5j.d.mts} +15 -2
  28. package/dist/postgres-migration-UtGCjw5j.d.mts.map +1 -0
  29. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  30. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  31. package/dist/render-typescript.mjs +1 -1
  32. package/dist/runtime.d.mts +2 -1
  33. package/dist/runtime.d.mts.map +1 -1
  34. package/dist/runtime.mjs +3 -3
  35. package/dist/runtime.mjs.map +1 -1
  36. package/package.json +19 -19
  37. package/src/core/migrations/postgres-migration.ts +34 -4
  38. package/src/core/migrations/render-typescript.ts +42 -15
  39. package/src/core/postgres-contract-view.ts +48 -0
  40. package/src/exports/runtime.ts +1 -0
  41. package/dist/descriptor-meta-runtime-D5zHFKUz.mjs.map +0 -1
  42. package/dist/postgres-contract-serializer-tGMiJcl4.mjs.map +0 -1
  43. package/dist/postgres-migration-C8JZyTSJ.mjs.map +0 -1
  44. package/dist/postgres-migration-Cs7zMOe1.d.mts.map +0 -1
  45. package/dist/render-typescript-KMgosran.mjs.map +0 -1
@@ -1,7 +1,9 @@
1
1
  import { A as installExtension, E as SetNotNullCall, S as DropTableCall, T as SetDefaultCall, _ as DropConstraintCall, b as DropNotNullCall, c as AlterColumnTypeCall, f as CreateSchemaCall, g as DropColumnCall, h as DropCheckConstraintCall, n as AddColumnCall, o as AddPrimaryKeyCall, p as CreateTableCall, r as AddForeignKeyCall, s as AddUniqueCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropDefaultCall, y as DropIndexCall } from "./op-factory-call-DIdBDwmO.mjs";
2
2
  import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
3
+ import { t as PostgresContractView } from "./postgres-contract-view-D12LEXT5.mjs";
3
4
  import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
4
5
  import { Migration } from "@prisma-next/family-sql/migration";
6
+ import { MigrationContractViews } from "@prisma-next/migration-tools/migration";
5
7
  //#region src/core/migrations/postgres-migration.ts
6
8
  /**
7
9
  * Target-owned base class for Postgres migrations.
@@ -39,11 +41,28 @@ var PostgresMigration = class extends Migration {
39
41
  * throws in that case to surface the misuse.
40
42
  */
41
43
  controlAdapter;
44
+ #endView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
45
+ #startView = new MigrationContractViews(this, "PostgresMigration", (json) => PostgresContractView.fromJson(json));
42
46
  constructor(stack) {
43
47
  super(stack);
44
48
  this.controlAdapter = stack?.adapter ? stack.adapter.create(stack) : void 0;
45
49
  }
46
50
  /**
51
+ * The typed, schema-qualified Postgres view over this migration's end-state
52
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
53
+ * if no `endContractJson` was provided.
54
+ */
55
+ get endContract() {
56
+ return this.#endView.endContract;
57
+ }
58
+ /**
59
+ * The typed Postgres view over this migration's start-state contract, or
60
+ * `null` for a baseline migration (no `startContractJson`).
61
+ */
62
+ get startContract() {
63
+ return this.#startView.startContract;
64
+ }
65
+ /**
47
66
  * Instance-method wrapper around the free `dataTransform` factory that
48
67
  * supplies the stored control adapter. Authors call this from inside
49
68
  * `get operations()`; the adapter argument is hidden from the call site.
@@ -142,4 +161,4 @@ var PostgresMigration = class extends Migration {
142
161
  //#endregion
143
162
  export { PostgresMigration as t };
144
163
 
145
- //# sourceMappingURL=postgres-migration-C8JZyTSJ.mjs.map
164
+ //# sourceMappingURL=postgres-migration-DEefginX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-DEefginX.mjs","names":["SqlMigration","#endView","#startView"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport { MigrationContractViews } from '@prisma-next/migration-tools/migration';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { PostgresContractView } from '../postgres-contract-view';\nimport {\n AddCheckConstraintCall,\n AddColumnCall,\n AddForeignKeyCall,\n AddPrimaryKeyCall,\n AddUniqueCall,\n AlterColumnTypeCall,\n type AlterColumnTypeOptions,\n CreateIndexCall,\n CreateSchemaCall,\n CreateTableCall,\n DropCheckConstraintCall,\n DropColumnCall,\n DropConstraintCall,\n DropDefaultCall,\n DropIndexCall,\n DropNotNullCall,\n DropTableCall,\n SetDefaultCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport { installExtension } from './operations/dependencies';\nimport type { CreateIndexExtras } from './operations/indexes';\nimport type { ForeignKeySpec } from './operations/shared';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n *\n * Every method requires an explicit `schema`. Postgres migrations name their\n * schema deliberately — there is no default and no `search_path`-relative\n * option. A migration that left the schema unspecified would resolve against\n * whatever `search_path` the connection happened to carry, and that ambiguity\n * is an antipattern in a migration. (The unbound/unspecified namespace concept\n * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)\n */\nexport abstract class PostgresMigration<\n Start extends Contract<SqlStorage> = Contract<SqlStorage>,\n End extends Contract<SqlStorage> = Contract<SqlStorage>,\n> extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n #endView = new MigrationContractViews<PostgresContractView<End>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<End>(json),\n );\n #startView = new MigrationContractViews<PostgresContractView<Start>>(\n this,\n 'PostgresMigration',\n (json) => PostgresContractView.fromJson<Start>(json),\n );\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * The typed, schema-qualified Postgres view over this migration's end-state\n * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws\n * if no `endContractJson` was provided.\n */\n get endContract(): PostgresContractView<End> {\n return this.#endView.endContract;\n }\n\n /**\n * The typed Postgres view over this migration's start-state contract, or\n * `null` for a baseline migration (no `startContractJson`).\n */\n get startContract(): PostgresContractView<Start> | null {\n return this.#startView.startContract;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createTable(options: {\n readonly schema: string;\n readonly table: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateTableCall(\n options.schema,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);\n }\n\n protected addColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: DdlColumn;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected addPrimaryKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddPrimaryKeyCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addUnique(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddUniqueCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addForeignKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly foreignKey: ForeignKeySpec;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(\n this.controlAdapter,\n );\n }\n\n protected addCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly column: string;\n readonly values: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddCheckConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.column,\n options.values,\n ).toOp(this.controlAdapter);\n }\n\n protected dropCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.kind ?? 'unique',\n ).toOp(this.controlAdapter);\n }\n\n protected dropTable(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);\n }\n\n protected dropColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected alterColumnType(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly options: AlterColumnTypeOptions;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AlterColumnTypeCall(\n options.schema,\n options.table,\n options.column,\n options.options,\n ).toOp(this.controlAdapter);\n }\n\n protected setNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected setDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly defaultSql: string;\n readonly operationClass?: 'additive' | 'widening';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetDefaultCall(\n options.schema,\n options.table,\n options.column,\n options.defaultSql,\n options.operationClass,\n ).toOp(this.controlAdapter);\n }\n\n protected dropDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropDefaultCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected createIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n readonly columns: readonly string[];\n readonly extras?: CreateIndexExtras;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateIndexCall(\n options.schema,\n options.table,\n options.index,\n options.columns,\n options.extras,\n ).toOp(this.controlAdapter);\n }\n\n protected dropIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropIndexCall(options.schema, options.table, options.index).toOp(\n this.controlAdapter,\n );\n }\n\n protected installExtension(options: {\n readonly extensionName: string;\n readonly invariantId: string;\n readonly id: string;\n readonly label?: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return installExtension(options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,IAAsB,oBAAtB,cAGUA,UAAgE;CACxE,WAAoB;;;;;;;CAQpB;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;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
2
2
  import { n as DataTransformOptions } from "./data-transform-qKy1U5V9.mjs";
3
3
  import { s as AlterColumnTypeOptions, w as ForeignKeySpec } from "./op-factory-call-DPJR7tJc.mjs";
4
+ import { t as PostgresContractView } from "./postgres-contract-view-C9j5cqP0.mjs";
4
5
  import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
5
6
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
6
7
  import { SqlStorage } from "@prisma-next/sql-contract/types";
@@ -43,7 +44,8 @@ interface CreateIndexExtras {
43
44
  * is an antipattern in a migration. (The unbound/unspecified namespace concept
44
45
  * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
45
46
  */
46
- declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDetails, 'postgres'> {
47
+ declare abstract class PostgresMigration<Start extends Contract<SqlStorage> = Contract<SqlStorage>, End extends Contract<SqlStorage> = Contract<SqlStorage>> extends Migration<PostgresPlanTargetDetails, 'postgres', Start, End> {
48
+ #private;
47
49
  readonly targetId: "postgres";
48
50
  /**
49
51
  * Materialized Postgres control adapter, created once per migration
@@ -53,6 +55,17 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
53
55
  */
54
56
  protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
55
57
  constructor(stack?: ControlStack<'sql', 'postgres'>);
58
+ /**
59
+ * The typed, schema-qualified Postgres view over this migration's end-state
60
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
61
+ * if no `endContractJson` was provided.
62
+ */
63
+ get endContract(): PostgresContractView<End>;
64
+ /**
65
+ * The typed Postgres view over this migration's start-state contract, or
66
+ * `null` for a baseline migration (no `startContractJson`).
67
+ */
68
+ get startContract(): PostgresContractView<Start> | null;
56
69
  /**
57
70
  * Instance-method wrapper around the free `dataTransform` factory that
58
71
  * supplies the stored control adapter. Authors call this from inside
@@ -178,4 +191,4 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
178
191
  }
179
192
  //#endregion
180
193
  export { PostgresMigration as t };
181
- //# sourceMappingURL=postgres-migration-Cs7zMOe1.d.mts.map
194
+ //# sourceMappingURL=postgres-migration-UtGCjw5j.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-UtGCjw5j.d.mts","names":[],"sources":["../src/core/migrations/operations/indexes.ts","../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;UAmBiB,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;AAF3B;;;;;;;;AAE2B;;;;AC2C3B;;;;;;;;;;;;;;;AD7CA,uBC6CsB,iBAAA,eACN,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,eAClC,QAAA,CAAS,UAAA,IAAc,QAAA,CAAS,UAAA,WACpC,SAAA,CAAa,yBAAA,cAAuC,KAAA,EAAO,GAAA;EAAA;WAC1D,QAAA;EA4CiC;;;;;;EAAA,mBApCvB,cAAA,EAAgB,iBAAA;cAavB,KAAA,GAAQ,YAAA;EAoCjB;;;;;EAAA,IArBC,WAAA,IAAe,oBAAA,CAAqB,GAAA;EA2DF;;;;EAAA,IAnDlC,aAAA,IAAiB,oBAAA,CAAqB,KAAA;EA8D9B;;;;;EAAA,UArDF,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAgFzB;;;;;EAAA,UApEF,WAAA,CAAY,OAAA;IAAA,SACX,MAAA;IAAA,SACA,KAAA;IAAA,SACA,WAAA;IAAA,SACA,OAAA,WAAkB,SAAA;IAAA,SAClB,WAAA,YAAuB,kBAAA;EAAA,IAC9B,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EA4HA;;;;;EAAA,U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EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
@@ -27,14 +27,18 @@ const BASE_IMPORTS = [{
27
27
  symbol: "MigrationCLI"
28
28
  }];
29
29
  function renderCallsToTypeScript(calls, meta) {
30
- const imports = buildImports(calls);
30
+ const imports = buildImports(calls, meta);
31
31
  const operationsBody = calls.map((c) => renderCall(c)).join(",\n");
32
+ const hasStart = meta.from !== null;
33
+ const startField = hasStart ? [" override readonly startContractJson = startContract;"] : [];
32
34
  return [
33
35
  shebangLineFor(detectScaffoldRuntime()),
34
36
  imports,
35
37
  "",
36
- "export default class M extends Migration {",
37
- buildDescribeMethod(meta),
38
+ `export default class M extends Migration<${hasStart ? "Start" : "never"}, End> {`,
39
+ ...startField,
40
+ " override readonly endContractJson = endContract;",
41
+ "",
38
42
  " override get operations() {",
39
43
  " return [",
40
44
  indent(operationsBody, 6),
@@ -49,21 +53,46 @@ function renderCallsToTypeScript(calls, meta) {
49
53
  function renderCall(call) {
50
54
  return call.renderTypeScript();
51
55
  }
52
- function buildImports(calls) {
53
- const requirements = [...BASE_IMPORTS];
56
+ function buildImports(calls, meta) {
57
+ const requirements = [...BASE_IMPORTS, ...contractImports(meta)];
54
58
  for (const call of calls) for (const req of call.importRequirements()) requirements.push(req);
55
59
  return renderImports(requirements);
56
60
  }
57
- function buildDescribeMethod(meta) {
58
- const lines = [];
59
- lines.push(" override describe() {");
60
- lines.push(" return {");
61
- lines.push(` from: ${JSON.stringify(meta.from)},`);
62
- lines.push(` to: ${JSON.stringify(meta.to)},`);
63
- lines.push(" };");
64
- lines.push(" }");
65
- lines.push("");
66
- return lines.join("\n");
61
+ /**
62
+ * The committed contract-JSON imports the scaffold reads its from/to identity
63
+ * from. `end-contract.json` is always present; `start-contract.json` is added
64
+ * only for a non-baseline migration (`meta.from !== null`). The matching
65
+ * `Contract` type imports (aliased `Start`/`End`) feed the
66
+ * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
67
+ * no start imports — `never` is the honest "no prior contract" Start.
68
+ */
69
+ function contractImports(meta) {
70
+ const reqs = [{
71
+ moduleSpecifier: "./end-contract.json",
72
+ symbol: "endContract",
73
+ kind: "default",
74
+ attributes: { type: "json" }
75
+ }, {
76
+ moduleSpecifier: "./end-contract",
77
+ symbol: "Contract",
78
+ alias: "End",
79
+ typeOnly: true
80
+ }];
81
+ if (meta.from !== null) {
82
+ reqs.push({
83
+ moduleSpecifier: "./start-contract.json",
84
+ symbol: "startContract",
85
+ kind: "default",
86
+ attributes: { type: "json" }
87
+ });
88
+ reqs.push({
89
+ moduleSpecifier: "./start-contract",
90
+ symbol: "Contract",
91
+ alias: "Start",
92
+ typeOnly: true
93
+ });
94
+ }
95
+ return reqs;
67
96
  }
68
97
  function indent(text, spaces) {
69
98
  const pad = " ".repeat(spaces);
@@ -72,4 +101,4 @@ function indent(text, spaces) {
72
101
  //#endregion
73
102
  export { renderCallsToTypeScript as t };
74
103
 
75
- //# sourceMappingURL=render-typescript-KMgosran.mjs.map
104
+ //# sourceMappingURL=render-typescript-7yqILcwr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-typescript-7yqILcwr.mjs","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `OpFactoryCall` renders itself via `renderTypeScript()` and\n * declares its own `importRequirements()`; this file just composes the module\n * source around those contributions. The design mirrors the Mongo target's\n * `render-typescript.ts` deliberately — byte-for-byte alignment isn't required\n * (different factory module specifiers, different base-class name) but the\n * shape is, so future consolidation to a framework-level helper is mechanical.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the facade re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls, meta);\n const operationsBody = calls.map((c) => renderCall(c)).join(',\\n');\n const hasStart = meta.from !== null;\n const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n `export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,\n ...startField,\n ' override readonly endContractJson = endContract;',\n '',\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction renderCall(call: OpFactoryCall): string {\n return call.renderTypeScript();\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\n/**\n * The committed contract-JSON imports the scaffold reads its from/to identity\n * from. `end-contract.json` is always present; `start-contract.json` is added\n * only for a non-baseline migration (`meta.from !== null`). The matching\n * `Contract` type imports (aliased `Start`/`End`) feed the\n * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with\n * no start imports — `never` is the honest \"no prior contract\" Start.\n */\nfunction contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {\n const reqs: ImportRequirement[] = [\n {\n moduleSpecifier: './end-contract.json',\n symbol: 'endContract',\n kind: 'default',\n attributes: { type: 'json' },\n },\n { moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },\n ];\n if (meta.from !== null) {\n reqs.push({\n moduleSpecifier: './start-contract.json',\n symbol: 'startContract',\n kind: 'default',\n attributes: { type: 'json' },\n });\n reqs.push({\n moduleSpecifier: './start-contract',\n symbol: 'Contract',\n alias: 'Start',\n typeOnly: true,\n });\n }\n return reqs;\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAAmC,QAAQ;AAAY,GAC1E;CAAE,iBAAiB;CAAmC,QAAQ;AAAe,CAC/E;AAEA,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,OAAO,IAAI;CACxC,MAAM,iBAAiB,MAAM,KAAK,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK;CACjE,MAAM,WAAW,KAAK,SAAS;CAC/B,MAAM,aAAa,WAAW,CAAC,wDAAwD,IAAI,CAAC;CAE5F,OAAO;EACL,eAAe,sBAAsB,CAAC;EACtC;EACA;EACA,4CAA4C,WAAW,UAAU,QAAQ;EACzE,GAAG;EACH;EACA;EACA;EACA;EACA,OAAO,gBAAgB,CAAC;EACxB;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAS,WAAW,MAA6B;CAC/C,OAAO,KAAK,iBAAiB;AAC/B;AAEA,SAAS,aAAa,OAAqC,MAAmC;CAC5F,MAAM,eAAoC,CAAC,GAAG,cAAc,GAAG,gBAAgB,IAAI,CAAC;CACpF,KAAK,MAAM,QAAQ,OACjB,KAAK,MAAM,OAAO,KAAK,mBAAmB,GACxC,aAAa,KAAK,GAAG;CAGzB,OAAO,cAAc,YAAY;AACnC;;;;;;;;;AAUA,SAAS,gBAAgB,MAAyD;CAChF,MAAM,OAA4B,CAChC;EACE,iBAAiB;EACjB,QAAQ;EACR,MAAM;EACN,YAAY,EAAE,MAAM,OAAO;CAC7B,GACA;EAAE,iBAAiB;EAAkB,QAAQ;EAAY,OAAO;EAAO,UAAU;CAAK,CACxF;CACA,IAAI,KAAK,SAAS,MAAM;EACtB,KAAK,KAAK;GACR,iBAAiB;GACjB,QAAQ;GACR,MAAM;GACN,YAAY,EAAE,MAAM,OAAO;EAC7B,CAAC;EACD,KAAK,KAAK;GACR,iBAAiB;GACjB,QAAQ;GACR,OAAO;GACP,UAAU;EACZ,CAAC;CACH;CACA,OAAO;AACT;AAEA,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,MAAM;CAC7B,OAAO,KACJ,MAAM,IAAI,CAAC,CACX,KAAK,SAAU,KAAK,KAAK,IAAI,GAAG,MAAM,SAAS,IAAK,CAAC,CACrD,KAAK,IAAI;AACd"}
@@ -1,2 +1,2 @@
1
- import { t as renderCallsToTypeScript } from "./render-typescript-KMgosran.mjs";
1
+ import { t as renderCallsToTypeScript } from "./render-typescript-7yqILcwr.mjs";
2
2
  export { renderCallsToTypeScript };
@@ -1,3 +1,4 @@
1
+ import { t as PostgresContractView } from "./postgres-contract-view-C9j5cqP0.mjs";
1
2
  import { AnyCodecDescriptor } from "@prisma-next/framework-components/codec";
2
3
  import { AnyEntityKindDescriptor, Namespace } from "@prisma-next/framework-components/ir";
3
4
  import { SqlNamespaceInput, SqlStorage } from "@prisma-next/sql-contract/types";
@@ -28,5 +29,5 @@ declare const postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<'sql', 'p
28
29
  readonly codecs: () => readonly AnyCodecDescriptor[];
29
30
  };
30
31
  //#endregion
31
- export { PostgresContractSerializer, PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
32
+ export { PostgresContractSerializer, PostgresContractView, PostgresRuntimeTargetInstance, postgresRuntimeTargetDescriptor as default };
32
33
  //# sourceMappingURL=runtime.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;cAmEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;cACrE,oBAAA,YAA+B,uBAAA;EAAA,UAKxB,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,MAAA,oBACJ,SAAA,GAAY,iBAAA;EAyBN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;EAAA,QA0CpD,0BAAA;EAAA,QAgCA,mBAAA;EAAA,QAOA,kBAAA;AAAA;;;UC7KO,6BAAA,SAAsC,qBAAqB;;;;;AD0D5E;;cClDM,+BAAA,EAAiC,uBAAA,oBAGrC,6BAAA;EAAA,SAES,MAAA,iBAAuB,kBAAA;AAAA"}
1
+ {"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/core/postgres-contract-serializer.ts","../src/exports/runtime.ts"],"mappings":";;;;;;;;;;cAmEa,0BAAA,SAAmC,yBAAA,CAA0B,QAAA,CAAS,UAAA;cACrE,oBAAA,YAA+B,uBAAA;EAAA,UAKxB,wBAAA,CACjB,IAAA,UACA,GAAA,EAAK,MAAA,oBACJ,SAAA,GAAY,iBAAA;EAyBN,iBAAA,CAAkB,QAAA,EAAU,QAAA,CAAS,UAAA,IAAc,UAAA;EAAA,QA0CpD,0BAAA;EAAA,QAgCA,mBAAA;EAAA,QAOA,kBAAA;AAAA;;;UC5KO,6BAAA,SAAsC,qBAAqB;;;;;ADyD5E;;cCjDM,+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-D5zHFKUz.mjs";
2
- import { t as PostgresContractSerializer } from "./postgres-contract-serializer-tGMiJcl4.mjs";
1
+ import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-UwYdV8fD.mjs";
2
+ import { n as PostgresContractSerializer, t as PostgresContractView } from "./postgres-contract-view-D12LEXT5.mjs";
3
3
  //#region src/exports/runtime.ts
4
4
  /**
5
5
  * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
@@ -18,6 +18,6 @@ const postgresRuntimeTargetDescriptor = {
18
18
  }
19
19
  };
20
20
  //#endregion
21
- export { PostgresContractSerializer, postgresRuntimeTargetDescriptor as default };
21
+ export { PostgresContractSerializer, PostgresContractView, postgresRuntimeTargetDescriptor as default };
22
22
 
23
23
  //# sourceMappingURL=runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';\n\nexport { PostgresContractSerializer } from '../core/postgres-contract-serializer';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMetaRuntime,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":";;;;;;;;;AAiBA,MAAM,kCAMF;CACF,GAAG;CACH,cAAc,CAAC;CACf,SAAwC;EACtC,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;AACF"}
1
+ {"version":3,"file":"runtime.mjs","names":[],"sources":["../src/exports/runtime.ts"],"sourcesContent":["import type { AnyCodecDescriptor } from '@prisma-next/framework-components/codec';\nimport type {\n RuntimeTargetDescriptor,\n RuntimeTargetInstance,\n} from '@prisma-next/framework-components/execution';\nimport { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';\n\nexport { PostgresContractSerializer } from '../core/postgres-contract-serializer';\nexport { PostgresContractView } from '../core/postgres-contract-view';\n\nexport interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}\n\n/**\n * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that\n * `@prisma-next/sql-runtime` consumers narrow to at composition time.\n *\n * The target itself contributes no codecs — postgres-specific codecs ship from the postgres adapter and from extension packs (pgvector, arktype-json, etc.).\n */\nconst postgresRuntimeTargetDescriptor: RuntimeTargetDescriptor<\n 'sql',\n 'postgres',\n PostgresRuntimeTargetInstance\n> & {\n readonly codecs: () => readonly AnyCodecDescriptor[];\n} = {\n ...postgresTargetDescriptorMetaRuntime,\n codecs: () => [],\n create(): PostgresRuntimeTargetInstance {\n return {\n familyId: 'sql',\n targetId: 'postgres',\n };\n },\n};\n\nexport default postgresRuntimeTargetDescriptor;\n"],"mappings":";;;;;;;;;AAkBA,MAAM,kCAMF;CACF,GAAG;CACH,cAAc,CAAC;CACf,SAAwC;EACtC,OAAO;GACL,UAAU;GACV,UAAU;EACZ;CACF;AACF"}
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.14.0-dev.31",
3
+ "version": "0.14.0-dev.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Postgres target pack for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/cli": "0.14.0-dev.31",
10
- "@prisma-next/contract": "0.14.0-dev.31",
11
- "@prisma-next/errors": "0.14.0-dev.31",
12
- "@prisma-next/family-sql": "0.14.0-dev.31",
13
- "@prisma-next/framework-components": "0.14.0-dev.31",
14
- "@prisma-next/migration-tools": "0.14.0-dev.31",
15
- "@prisma-next/ts-render": "0.14.0-dev.31",
16
- "@prisma-next/sql-contract": "0.14.0-dev.31",
17
- "@prisma-next/sql-errors": "0.14.0-dev.31",
18
- "@prisma-next/sql-operations": "0.14.0-dev.31",
19
- "@prisma-next/sql-relational-core": "0.14.0-dev.31",
20
- "@prisma-next/sql-schema-ir": "0.14.0-dev.31",
21
- "@prisma-next/utils": "0.14.0-dev.31",
9
+ "@prisma-next/cli": "0.14.0-dev.33",
10
+ "@prisma-next/contract": "0.14.0-dev.33",
11
+ "@prisma-next/errors": "0.14.0-dev.33",
12
+ "@prisma-next/family-sql": "0.14.0-dev.33",
13
+ "@prisma-next/framework-components": "0.14.0-dev.33",
14
+ "@prisma-next/migration-tools": "0.14.0-dev.33",
15
+ "@prisma-next/ts-render": "0.14.0-dev.33",
16
+ "@prisma-next/sql-contract": "0.14.0-dev.33",
17
+ "@prisma-next/sql-errors": "0.14.0-dev.33",
18
+ "@prisma-next/sql-operations": "0.14.0-dev.33",
19
+ "@prisma-next/sql-relational-core": "0.14.0-dev.33",
20
+ "@prisma-next/sql-schema-ir": "0.14.0-dev.33",
21
+ "@prisma-next/utils": "0.14.0-dev.33",
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/psl-parser": "0.14.0-dev.31",
28
- "@prisma-next/sql-contract-psl": "0.14.0-dev.31",
29
- "@prisma-next/test-utils": "0.14.0-dev.31",
30
- "@prisma-next/tsconfig": "0.14.0-dev.31",
31
- "@prisma-next/tsdown": "0.14.0-dev.31",
27
+ "@prisma-next/psl-parser": "0.14.0-dev.33",
28
+ "@prisma-next/sql-contract-psl": "0.14.0-dev.33",
29
+ "@prisma-next/test-utils": "0.14.0-dev.33",
30
+ "@prisma-next/tsconfig": "0.14.0-dev.33",
31
+ "@prisma-next/tsdown": "0.14.0-dev.33",
32
32
  "tsdown": "0.22.1",
33
33
  "typescript": "5.9.3",
34
34
  "vitest": "4.1.8"
@@ -3,9 +3,11 @@ import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control'
3
3
  import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
4
4
  import { Migration as SqlMigration } from '@prisma-next/family-sql/migration';
5
5
  import type { ControlStack } from '@prisma-next/framework-components/control';
6
+ import { MigrationContractViews } from '@prisma-next/migration-tools/migration';
6
7
  import type { SqlStorage } from '@prisma-next/sql-contract/types';
7
8
  import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
8
9
  import { errorPostgresMigrationStackMissing } from '../errors';
10
+ import { PostgresContractView } from '../postgres-contract-view';
9
11
  import {
10
12
  AddCheckConstraintCall,
11
13
  AddColumnCall,
@@ -60,10 +62,10 @@ import type { PostgresPlanTargetDetails } from './planner-target-details';
60
62
  * is an antipattern in a migration. (The unbound/unspecified namespace concept
61
63
  * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
62
64
  */
63
- export abstract class PostgresMigration extends SqlMigration<
64
- PostgresPlanTargetDetails,
65
- 'postgres'
66
- > {
65
+ export abstract class PostgresMigration<
66
+ Start extends Contract<SqlStorage> = Contract<SqlStorage>,
67
+ End extends Contract<SqlStorage> = Contract<SqlStorage>,
68
+ > extends SqlMigration<PostgresPlanTargetDetails, 'postgres', Start, End> {
67
69
  readonly targetId = 'postgres' as const;
68
70
 
69
71
  /**
@@ -74,6 +76,17 @@ export abstract class PostgresMigration extends SqlMigration<
74
76
  */
75
77
  protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
76
78
 
79
+ #endView = new MigrationContractViews<PostgresContractView<End>>(
80
+ this,
81
+ 'PostgresMigration',
82
+ (json) => PostgresContractView.fromJson<End>(json),
83
+ );
84
+ #startView = new MigrationContractViews<PostgresContractView<Start>>(
85
+ this,
86
+ 'PostgresMigration',
87
+ (json) => PostgresContractView.fromJson<Start>(json),
88
+ );
89
+
77
90
  constructor(stack?: ControlStack<'sql', 'postgres'>) {
78
91
  super(stack);
79
92
  // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;
@@ -84,6 +97,23 @@ export abstract class PostgresMigration extends SqlMigration<
84
97
  : undefined;
85
98
  }
86
99
 
100
+ /**
101
+ * The typed, schema-qualified Postgres view over this migration's end-state
102
+ * contract — `this.endContract.namespace.<schema>.table.<name>`, etc. Throws
103
+ * if no `endContractJson` was provided.
104
+ */
105
+ get endContract(): PostgresContractView<End> {
106
+ return this.#endView.endContract;
107
+ }
108
+
109
+ /**
110
+ * The typed Postgres view over this migration's start-state contract, or
111
+ * `null` for a baseline migration (no `startContractJson`).
112
+ */
113
+ get startContract(): PostgresContractView<Start> | null {
114
+ return this.#startView.startContract;
115
+ }
116
+
87
117
  /**
88
118
  * Instance-method wrapper around the free `dataTransform` factory that
89
119
  * supplies the stored control adapter. Authors call this from inside
@@ -45,15 +45,19 @@ export function renderCallsToTypeScript(
45
45
  calls: ReadonlyArray<OpFactoryCall>,
46
46
  meta: RenderMigrationMeta,
47
47
  ): string {
48
- const imports = buildImports(calls);
48
+ const imports = buildImports(calls, meta);
49
49
  const operationsBody = calls.map((c) => renderCall(c)).join(',\n');
50
+ const hasStart = meta.from !== null;
51
+ const startField = hasStart ? [' override readonly startContractJson = startContract;'] : [];
50
52
 
51
53
  return [
52
54
  shebangLineFor(detectScaffoldRuntime()),
53
55
  imports,
54
56
  '',
55
- 'export default class M extends Migration {',
56
- buildDescribeMethod(meta),
57
+ `export default class M extends Migration<${hasStart ? 'Start' : 'never'}, End> {`,
58
+ ...startField,
59
+ ' override readonly endContractJson = endContract;',
60
+ '',
57
61
  ' override get operations() {',
58
62
  ' return [',
59
63
  indent(operationsBody, 6),
@@ -70,8 +74,8 @@ function renderCall(call: OpFactoryCall): string {
70
74
  return call.renderTypeScript();
71
75
  }
72
76
 
73
- function buildImports(calls: ReadonlyArray<OpFactoryCall>): string {
74
- const requirements: ImportRequirement[] = [...BASE_IMPORTS];
77
+ function buildImports(calls: ReadonlyArray<OpFactoryCall>, meta: RenderMigrationMeta): string {
78
+ const requirements: ImportRequirement[] = [...BASE_IMPORTS, ...contractImports(meta)];
75
79
  for (const call of calls) {
76
80
  for (const req of call.importRequirements()) {
77
81
  requirements.push(req);
@@ -80,16 +84,39 @@ function buildImports(calls: ReadonlyArray<OpFactoryCall>): string {
80
84
  return renderImports(requirements);
81
85
  }
82
86
 
83
- function buildDescribeMethod(meta: RenderMigrationMeta): string {
84
- const lines: string[] = [];
85
- lines.push(' override describe() {');
86
- lines.push(' return {');
87
- lines.push(` from: ${JSON.stringify(meta.from)},`);
88
- lines.push(` to: ${JSON.stringify(meta.to)},`);
89
- lines.push(' };');
90
- lines.push(' }');
91
- lines.push('');
92
- return lines.join('\n');
87
+ /**
88
+ * The committed contract-JSON imports the scaffold reads its from/to identity
89
+ * from. `end-contract.json` is always present; `start-contract.json` is added
90
+ * only for a non-baseline migration (`meta.from !== null`). The matching
91
+ * `Contract` type imports (aliased `Start`/`End`) feed the
92
+ * `Migration<Start, End>` generics. Baseline emits `Migration<never, End>` with
93
+ * no start imports — `never` is the honest "no prior contract" Start.
94
+ */
95
+ function contractImports(meta: RenderMigrationMeta): readonly ImportRequirement[] {
96
+ const reqs: ImportRequirement[] = [
97
+ {
98
+ moduleSpecifier: './end-contract.json',
99
+ symbol: 'endContract',
100
+ kind: 'default',
101
+ attributes: { type: 'json' },
102
+ },
103
+ { moduleSpecifier: './end-contract', symbol: 'Contract', alias: 'End', typeOnly: true },
104
+ ];
105
+ if (meta.from !== null) {
106
+ reqs.push({
107
+ moduleSpecifier: './start-contract.json',
108
+ symbol: 'startContract',
109
+ kind: 'default',
110
+ attributes: { type: 'json' },
111
+ });
112
+ reqs.push({
113
+ moduleSpecifier: './start-contract',
114
+ symbol: 'Contract',
115
+ alias: 'Start',
116
+ typeOnly: true,
117
+ });
118
+ }
119
+ return reqs;
93
120
  }
94
121
 
95
122
  function indent(text: string, spaces: number): string {
@@ -0,0 +1,48 @@
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import {
3
+ buildSqlSchemaQualifiedView,
4
+ type SqlSchemaQualifiedView,
5
+ } from '@prisma-next/sql-contract/contract-view';
6
+ import type { SqlStorage } from '@prisma-next/sql-contract/types';
7
+ import { PostgresContractSerializer } from './postgres-contract-serializer';
8
+
9
+ /**
10
+ * A schema-qualified Postgres contract view: the deserialized contract
11
+ * intersected with a single `namespace` member holding every schema by id. It is
12
+ * substitutable for `Contract` (carries `storage`, `domain`, …) and reaches each
13
+ * schema's entities through `view.namespace.<schema>`:
14
+ *
15
+ * ```ts
16
+ * const view = PostgresContractView.fromJson<Contract>(contractJson);
17
+ * view.namespace.public.table.users // typed table leaf in the public schema
18
+ * view.namespace.auth.table.users // the auth schema's own users table
19
+ * view.namespace.public.entries.policy.X // pack-contributed kind (RLS / #771 path)
20
+ * view.namespace.__unbound__.table.X // default schema, keyed by its raw id
21
+ * view.storage // the full contract is still present
22
+ * ```
23
+ *
24
+ * This mirrors the runtime `db.enums.<ns>` keying exactly (the default schema
25
+ * keeps its literal `__unbound__` id). Schema names are NOT promoted to the
26
+ * contract root, so there is no collision with contract envelope fields — a
27
+ * schema named `storage` is `view.namespace.storage`, while `view.storage`
28
+ * stays the contract's `storage`.
29
+ */
30
+ export type PostgresContractView<TContract extends Contract<SqlStorage> = Contract<SqlStorage>> =
31
+ SqlSchemaQualifiedView<TContract>;
32
+
33
+ export const PostgresContractView = {
34
+ /** Wrap an already-deserialized Postgres contract in a schema-qualified view. */
35
+ from<TContract extends Contract<SqlStorage>>(
36
+ contract: TContract,
37
+ ): PostgresContractView<TContract> {
38
+ return buildSqlSchemaQualifiedView(contract);
39
+ },
40
+
41
+ /** Deserialize a Postgres contract JSON envelope and wrap it in a view. */
42
+ fromJson<TContract extends Contract<SqlStorage> = Contract<SqlStorage>>(
43
+ json: unknown,
44
+ ): PostgresContractView<TContract> {
45
+ const contract = new PostgresContractSerializer().deserializeContract<TContract>(json);
46
+ return buildSqlSchemaQualifiedView(contract);
47
+ },
48
+ };
@@ -6,6 +6,7 @@ import type {
6
6
  import { postgresTargetDescriptorMetaRuntime } from '../core/descriptor-meta-runtime';
7
7
 
8
8
  export { PostgresContractSerializer } from '../core/postgres-contract-serializer';
9
+ export { PostgresContractView } from '../core/postgres-contract-view';
9
10
 
10
11
  export interface PostgresRuntimeTargetInstance extends RuntimeTargetInstance<'sql', 'postgres'> {}
11
12
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor-meta-runtime-D5zHFKUz.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta-runtime.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { PostgresRlsPolicySchema, PostgresRoleSchema } from './postgres-validators';\nimport { computeContentHash, normalizePredicate } from './rls/canonicalize';\nimport { PostgresRlsPolicy } from './schema-ir/postgres-rls-policy';\nimport { PostgresRole, type PostgresRoleInput } from './schema-ir/postgres-role';\n\nexport const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;\n\nexport interface RlsPolicyExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n}\n\nfunction readRefParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'ref' ? param.identifier : undefined;\n}\n\nfunction readValueParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'value' ? param.raw : undefined;\n}\n\nfunction readListRefParams(block: PslExtensionBlock, key: string): string[] {\n const param = block.parameters[key];\n if (param?.kind !== 'list') return [];\n return param.items.flatMap((item) => (item.kind === 'ref' ? [item.identifier] : []));\n}\n\nfunction unwrapQuotedString(raw: string): string {\n if (raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2) {\n return raw.slice(1, -1).replace(/\\\\\"/g, '\"');\n }\n return raw;\n}\n\nfunction lowerRlsPolicyFromBlock(\n block: RlsPolicyExtensionBlock,\n _ctx: AuthoringEntityContext,\n): PostgresRlsPolicy {\n const prefix = block.name;\n const targetModelName = readRefParam(block, 'target') ?? '';\n const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);\n const roles = [...readListRefParams(block, 'roles')].sort();\n const using = unwrapQuotedString(readValueParam(block, 'using') ?? '');\n\n const wireHash = computeContentHash({\n using: normalizePredicate(using),\n roles,\n operation: 'select',\n permissive: true,\n });\n const wireName = `${prefix}_${wireHash}`;\n\n return new PostgresRlsPolicy({\n name: wireName,\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation: 'select',\n roles,\n using,\n permissive: true,\n });\n}\n\nexport const postgresAuthoringEntityTypes = {\n role: {\n kind: 'entity',\n discriminator: 'role',\n validatorSchema: PostgresRoleSchema,\n output: {\n factory: (input: PostgresRoleInput): PostgresRole => new PostgresRole(input),\n },\n },\n policy: {\n kind: 'entity',\n discriminator: 'policy',\n validatorSchema: PostgresRlsPolicySchema,\n output: {\n factory: lowerRlsPolicyFromBlock,\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 *\n * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the\n * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target\n * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from\n * the family pack instead.\n */\n/**\n * PSL block descriptor for `policy_select`.\n *\n * The parser learns the block shape from this descriptor; lowering from\n * `PslExtensionBlock` to `PostgresRlsPolicy` is wired in the PSL\n * interpreter (a later dispatch). The `discriminator` matches\n * `PostgresRlsPolicy.kind` so the parsed block node carries the same\n * discriminant as the IR class it will lower to.\n *\n * The `roles` list uses `scope:'cross-space'` because same-namespace\n * role ref resolution requires PSL namespace entries keyed by `refKind`\n * (i.e. `'role'`), which in turn requires the role block discriminator to\n * equal `'role'`. Aligning discriminator with refKind is tracked for\n * slice 4 (cross-space roles). Until then cross-space passes validation\n * unconditionally and the authored role names flow through unchanged.\n */\nexport const postgresAuthoringPslBlockDescriptors = {\n policy_select: {\n kind: 'pslBlock',\n keyword: 'policy_select',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: { kind: 'ref', refKind: 'model', scope: 'same-namespace', required: true },\n roles: {\n kind: 'list',\n of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },\n },\n using: { kind: 'value', codecId: 'pg/text@1', required: true },\n },\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\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: /* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n uuidNative: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n },\n },\n id: {\n uuidv4Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","// Runtime-safe slice of the postgres target descriptor metadata.\n//\n// This file exists separately from ./descriptor-meta on purpose: the runtime\n// plane reads only `kind/familyId/targetId/id/version/capabilities` (plus the\n// `__codecTypes` phantom). The `authoring` slot lives on the pack/control\n// descriptor only, because authoring contributions are consumed at\n// contract-construction time by `assembleAuthoringContributions` (control\n// plane) and the PSL interpreter — never at runtime.\n//\n// Keeping the runtime closure free of the `./authoring` import is what lets\n// the bundler tree-shake `@prisma-next/family-sql/control` (and its\n// transitive `verify-sql-schema` chunk) out of the runtime entry. Do not\n// add an `authoring` field here — if you need to, the pack/control meta in\n// `./descriptor-meta` is the right place. See TML-2766 for context.\nimport type { CodecTypes } from '../exports/codec-types';\n\nconst postgresTargetDescriptorMetaRuntimeBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n} as const;\n\nexport const postgresTargetDescriptorMetaRuntime: typeof postgresTargetDescriptorMetaRuntimeBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaRuntimeBase;\n"],"mappings":";;;;AAcA,MAAa,yBAAyB,CAAC;AAMvC,SAAS,aAAa,OAA0B,KAAiC;CAC/E,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,SAAS,QAAQ,MAAM,aAAa,KAAA;AACpD;AAEA,SAAS,eAAe,OAA0B,KAAiC;CACjF,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,SAAS,UAAU,MAAM,MAAM,KAAA;AAC/C;AAEA,SAAS,kBAAkB,OAA0B,KAAuB;CAC1E,MAAM,QAAQ,MAAM,WAAW;CAC/B,IAAI,OAAO,SAAS,QAAQ,OAAO,CAAC;CACp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V,IAAI;CACJ,SAAS;CACT,cAAc,CAAC;AAKb"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"postgres-contract-serializer-tGMiJcl4.mjs","names":[],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type AnyEntityKindDescriptor,\n type Namespace,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject, JsonValue } from '@prisma-next/utils/json';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport { policyEntityKind, roleEntityKind } from './entity-kinds';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n 'factory' in output &&\n typeof output.factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits hydration factories\n * keyed by the descriptor's `discriminator`. Used for `storage.types`\n * (codec-triple hydration). Namespace entries hydration dispatches by\n * entries key, not discriminator — handled by `hydrateNamespaceEntities`.\n */\nfunction collectStorageTypesHydrators(\n namespace: AuthoringEntityTypeNamespace,\n): ReadonlyMap<string, SqlEntityHydrationFactory> {\n const registry = new Map<string, SqlEntityHydrationFactory>();\n const walk = (node: AuthoringEntityTypeNamespace): void => {\n for (const value of Object.values(node)) {\n if (isAuthoringEntityTypeDescriptor(value)) {\n if (isAuthoringEntityTypeFactoryOutput(value.output)) {\n const { factory } = value.output;\n registry.set(value.discriminator, (raw) => factory(raw, POSTGRES_AUTHORING_CTX));\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return registry;\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor(extraPackEntityKinds: readonly AnyEntityKindDescriptor[] = []) {\n const storageTypesHydrators = collectStorageTypesHydrators(postgresAuthoringEntityTypes);\n super(storageTypesHydrators, [policyEntityKind, roleEntityKind, ...extraPackEntityKinds]);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Record<string, unknown>,\n ): Namespace | SqlNamespaceInput {\n const hydrated = blindCast<\n SqlNamespaceInput,\n 'raw is always plain JSON, so super.hydrateSqlNamespaceEntry returns SqlNamespaceInput'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n const allSlotsEmpty = Object.values(entries).every(\n (slot) => slot === undefined || Object.keys(slot).length === 0,\n );\n if (id === UNBOUND_NAMESPACE_ID && allSlotsEmpty) {\n return PostgresSchema.unbound;\n }\n const valueSetSlot = entries['valueSet'];\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n return new PostgresSchema({\n id,\n entries: {\n ...entries,\n table: entries['table'] ?? {},\n ...(hasValueSets ? { valueSet: valueSetSlot } : {}),\n },\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: Object.fromEntries(\n Object.entries(ns.entries.table ?? {}).map(([tableName, table]) => [\n tableName,\n this.serializeJsonObject(table),\n ]),\n ),\n },\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonObject(entry);\n }\n storageOut['types'] = typesOut;\n }\n return blindCast<\n JsonObject,\n 'contract minus storage plus a JSON-shaped storageOut is a JsonObject'\n >({\n ...rest,\n storage: storageOut,\n });\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.table)) {\n tablesOut[tableName] = this.serializeJsonObject(table);\n }\n const valueSetEntries = ns.valueSet;\n const valueSetOut: Record<string, JsonObject> = {};\n if (valueSetEntries !== undefined) {\n for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) {\n valueSetOut[valueSetName] = this.serializeJsonObject(valueSet);\n }\n }\n const roleOut: Record<string, JsonObject> = {};\n for (const [roleName, role] of Object.entries(ns.role)) {\n roleOut[roleName] = this.serializeJsonObject(role);\n }\n const policyOut: Record<string, JsonObject> = {};\n for (const [policyName, policy] of Object.entries(ns.policy)) {\n policyOut[policyName] = this.serializeJsonObject(policy);\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: tablesOut,\n ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),\n ...(Object.keys(roleOut).length > 0 ? { role: roleOut } : {}),\n ...(Object.keys(policyOut).length > 0 ? { policy: policyOut } : {}),\n },\n };\n }\n\n private serializeJsonObject(value: unknown): JsonObject {\n return blindCast<\n JsonObject,\n 'serializeJsonValue round-trips an IR node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(value));\n }\n\n private serializeJsonValue(value: unknown): JsonValue {\n return blindCast<JsonValue, 'JSON.parse(JSON.stringify(x)) yields a JsonValue'>(\n JSON.parse(JSON.stringify(value)),\n );\n }\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,aAAa,UACb,OAAO,OAAO,YAAY;AAE9B;;;;;;;AAQA,SAAS,6BACP,WACgD;CAChD,MAAM,2BAAW,IAAI,IAAuC;CAC5D,MAAM,QAAQ,SAA6C;EACzD,KAAK,MAAM,SAAS,OAAO,OAAO,IAAI,GAAG;GACvC,IAAI,gCAAgC,KAAK,GAAG;IAC1C,IAAI,mCAAmC,MAAM,MAAM,GAAG;KACpD,MAAM,EAAE,YAAY,MAAM;KAC1B,SAAS,IAAI,MAAM,gBAAgB,QAAQ,QAAQ,KAAK,sBAAsB,CAAC;IACjF;IACA;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,KAAK,KAAK;EAEd;CACF;CACA,KAAK,SAAS;CACd,OAAO;AACT;AAEA,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,YAAY,uBAA2D,CAAC,GAAG;EACzE,MAAM,wBAAwB,6BAA6B,4BAA4B;EACvF,MAAM,uBAAuB;GAAC;GAAkB;GAAgB,GAAG;EAAoB,CAAC;CAC1F;CAEA,yBACE,MACA,KAC+B;EAK/B,MAAM,EAAE,IAAI,YAJK,UAGf,MAAM,yBAAyB,MAAM,GAAG,CACX;EAE/B,MAAM,gBAAgB,OAAO,OAAO,OAAO,CAAC,CAAC,OAC1C,SAAS,SAAS,KAAA,KAAa,OAAO,KAAK,IAAI,CAAC,CAAC,WAAW,CAC/D;EACA,IAAI,OAAO,wBAAwB,eACjC,OAAO,eAAe;EAExB,MAAM,eAAe,QAAQ;EAC7B,MAAM,eAAe,iBAAiB,KAAA,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