@prisma-next/target-postgres 0.5.0-dev.5 → 0.5.0-dev.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/{codec-ids-CojIXVf9.mjs → codec-ids-ckQX9Kcg.mjs} +3 -2
  2. package/dist/{codec-ids-CojIXVf9.mjs.map → codec-ids-ckQX9Kcg.mjs.map} +1 -1
  3. package/dist/codec-ids.d.mts +2 -1
  4. package/dist/codec-ids.d.mts.map +1 -1
  5. package/dist/codec-ids.mjs +2 -2
  6. package/dist/codec-types.d.mts +1 -1
  7. package/dist/codec-types.mjs +1 -1
  8. package/dist/{codecs-D-F2KJqt.d.mts → codecs-B03dFv94.d.mts} +64 -30
  9. package/dist/codecs-B03dFv94.d.mts.map +1 -0
  10. package/dist/{codecs-BoahtY_Q.mjs → codecs-D0oXyJIH.mjs} +24 -104
  11. package/dist/codecs-D0oXyJIH.mjs.map +1 -0
  12. package/dist/codecs.d.mts +1 -1
  13. package/dist/codecs.mjs +1 -1
  14. package/dist/control.mjs +20 -62
  15. package/dist/control.mjs.map +1 -1
  16. package/dist/{data-transform-VfEGzXWt.mjs → data-transform-Be_i_DBc.mjs} +24 -5
  17. package/dist/data-transform-Be_i_DBc.mjs.map +1 -0
  18. package/dist/data-transform-CrpmG4uJ.d.mts +39 -0
  19. package/dist/data-transform-CrpmG4uJ.d.mts.map +1 -0
  20. package/dist/data-transform.d.mts +1 -1
  21. package/dist/data-transform.mjs +1 -1
  22. package/dist/issue-planner.d.mts +1 -1
  23. package/dist/migration.d.mts +2 -2
  24. package/dist/migration.mjs +2 -2
  25. package/dist/pack.d.mts +1 -1
  26. package/dist/{planner-CLUvVhUN.mjs → planner-Cm-ZLutk.mjs} +6 -6
  27. package/dist/planner-Cm-ZLutk.mjs.map +1 -0
  28. package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs → planner-produced-postgres-migration-Bi-RWO4-.mjs} +3 -4
  29. package/dist/{planner-produced-postgres-migration-DSSPq8QS.mjs.map → planner-produced-postgres-migration-Bi-RWO4-.mjs.map} +1 -1
  30. package/dist/{planner-produced-postgres-migration-CRRTno6Z.d.mts → planner-produced-postgres-migration-M3EfhWSS.d.mts} +2 -2
  31. package/dist/planner-produced-postgres-migration-M3EfhWSS.d.mts.map +1 -0
  32. package/dist/planner-produced-postgres-migration.d.mts +3 -2
  33. package/dist/planner-produced-postgres-migration.mjs +1 -1
  34. package/dist/planner.d.mts +17 -10
  35. package/dist/planner.d.mts.map +1 -1
  36. package/dist/planner.mjs +1 -1
  37. package/dist/{postgres-migration-BjA3Zmts.d.mts → postgres-migration-BFjbb25b.d.mts} +4 -3
  38. package/dist/postgres-migration-BFjbb25b.d.mts.map +1 -0
  39. package/dist/{postgres-migration-qtmtbONe.mjs → postgres-migration-BS9vQW97.mjs} +2 -2
  40. package/dist/postgres-migration-BS9vQW97.mjs.map +1 -0
  41. package/dist/{render-typescript-1rF_SB4g.mjs → render-typescript-Co3Emwgz.mjs} +1 -2
  42. package/dist/render-typescript-Co3Emwgz.mjs.map +1 -0
  43. package/dist/render-typescript.d.mts +1 -2
  44. package/dist/render-typescript.d.mts.map +1 -1
  45. package/dist/render-typescript.mjs +1 -1
  46. package/dist/{statement-builders-BPnmt6wx.mjs → statement-builders-CHqCtSfe.mjs} +13 -8
  47. package/dist/statement-builders-CHqCtSfe.mjs.map +1 -0
  48. package/dist/statement-builders.d.mts +10 -3
  49. package/dist/statement-builders.d.mts.map +1 -1
  50. package/dist/statement-builders.mjs +2 -2
  51. package/package.json +16 -16
  52. package/src/core/codec-ids.ts +1 -0
  53. package/src/core/codecs.ts +53 -40
  54. package/src/core/migrations/operations/data-transform.ts +86 -21
  55. package/src/core/migrations/planner-produced-postgres-migration.ts +0 -1
  56. package/src/core/migrations/planner.ts +17 -11
  57. package/src/core/migrations/postgres-migration.ts +3 -6
  58. package/src/core/migrations/render-typescript.ts +1 -5
  59. package/src/core/migrations/runner.ts +43 -112
  60. package/src/core/migrations/statement-builders.ts +22 -6
  61. package/src/exports/statement-builders.ts +1 -1
  62. package/dist/codecs-BoahtY_Q.mjs.map +0 -1
  63. package/dist/codecs-D-F2KJqt.d.mts.map +0 -1
  64. package/dist/data-transform-CxFRBIUp.d.mts +0 -32
  65. package/dist/data-transform-CxFRBIUp.d.mts.map +0 -1
  66. package/dist/data-transform-VfEGzXWt.mjs.map +0 -1
  67. package/dist/planner-CLUvVhUN.mjs.map +0 -1
  68. package/dist/planner-produced-postgres-migration-CRRTno6Z.d.mts.map +0 -1
  69. package/dist/postgres-migration-BjA3Zmts.d.mts.map +0 -1
  70. package/dist/postgres-migration-qtmtbONe.mjs.map +0 -1
  71. package/dist/render-typescript-1rF_SB4g.mjs.map +0 -1
  72. package/dist/statement-builders-BPnmt6wx.mjs.map +0 -1
  73. package/src/core/json-schema-type-expression.ts +0 -131
@@ -1 +1 @@
1
- {"version":3,"file":"planner-produced-postgres-migration-DSSPq8QS.mjs","names":["#calls","#meta"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { MigrationPlanWithAuthoringSurface } from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly PostgresOpFactoryCall[];\n readonly #meta: MigrationMeta;\n\n constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('kind', this.#meta.kind),\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE,CAASA;CACT,CAASC;CAET,YAAY,OAAyC,MAAqB;AACxE,SAAO;AACP,QAAKD,QAAS;AACd,QAAKC,OAAQ;;CAGf,IAAa,aAA4B;AACvC,SAAO,UAAU,MAAKD,MAAO;;CAG/B,AAAS,WAA0B;AACjC,SAAO,MAAKC;;CAGd,mBAA2B;AACzB,SAAO,wBAAwB,MAAKD,OAAQ;GAC1C,MAAM,MAAKC,KAAM;GACjB,IAAI,MAAKA,KAAM;GACf,GAAG,UAAU,QAAQ,MAAKA,KAAM,KAAK;GACrC,GAAG,UAAU,UAAU,MAAKA,KAAM,OAAO;GAC1C,CAAC"}
1
+ {"version":3,"file":"planner-produced-postgres-migration-Bi-RWO4-.mjs","names":["#calls","#meta"],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":["/**\n * Planner-produced Postgres migration.\n *\n * Returned by `PostgresMigrationPlanner.plan(...)` and `emptyMigration(...)`.\n * Holds the migration IR (`PostgresOpFactoryCall[]`) alongside\n * `MigrationMeta` and exposes both the runtime-ops view (`get operations`)\n * and the TypeScript authoring view (`renderTypeScript()`). Satisfies\n * `MigrationPlanWithAuthoringSurface` so the CLI can uniformly serialize any\n * planner result back to `migration.ts`.\n *\n * Extends the family-level `SqlMigration` alias rather than the target-local\n * migration base directly — mirrors Mongo's `PlannerProducedMongoMigration`\n * shape and keeps CLI wiring one step removed from target internals.\n *\n * Placeholder-bearing plans: `renderTypeScript()` always succeeds and embeds\n * `() => placeholder(\"slot\")` at each stub. `operations`, in contrast, is\n * _not safe to enumerate_ on a stub-bearing plan — `DataTransformCall.toOp()`\n * throws `PN-MIG-2001` because a planner-stubbed closure cannot be lowered\n * to a runtime op. Callers that know a plan may carry stubs must render to\n * `migration.ts`, let the user fill the slots, and re-load the edited\n * migration before enumerating ops. The walk-schema planner does not emit\n * `DataTransformCall`s today, so this asymmetry is invisible until the\n * issue-planner integration lands in Phase 2.\n */\n\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { MigrationPlanWithAuthoringSurface } from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\nimport { PostgresMigration } from './postgres-migration';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\nexport class TypeScriptRenderablePostgresMigration\n extends PostgresMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly PostgresOpFactoryCall[];\n readonly #meta: MigrationMeta;\n\n constructor(calls: readonly PostgresOpFactoryCall[], meta: MigrationMeta) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n ...ifDefined('labels', this.#meta.labels),\n });\n }\n}\n"],"mappings":";;;;;;AAqCA,IAAa,wCAAb,cACU,kBAEV;CACE,CAASA;CACT,CAASC;CAET,YAAY,OAAyC,MAAqB;AACxE,SAAO;AACP,QAAKD,QAAS;AACd,QAAKC,OAAQ;;CAGf,IAAa,aAA4B;AACvC,SAAO,UAAU,MAAKD,MAAO;;CAG/B,AAAS,WAA0B;AACjC,SAAO,MAAKC;;CAGd,mBAA2B;AACzB,SAAO,wBAAwB,MAAKD,OAAQ;GAC1C,MAAM,MAAKC,KAAM;GACjB,IAAI,MAAKA,KAAM;GACf,GAAG,UAAU,UAAU,MAAKA,KAAM,OAAO;GAC1C,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-DH-azLu-.mjs";
2
2
  import { b as PostgresOpFactoryCall } from "./op-factory-call-C3bWXKSP.mjs";
3
- import { t as PostgresMigration } from "./postgres-migration-BjA3Zmts.mjs";
3
+ import { t as PostgresMigration } from "./postgres-migration-BFjbb25b.mjs";
4
4
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
5
5
  import { MigrationPlanWithAuthoringSurface } from "@prisma-next/framework-components/control";
6
6
  import { MigrationMeta } from "@prisma-next/migration-tools/migration";
@@ -17,4 +17,4 @@ declare class TypeScriptRenderablePostgresMigration extends PostgresMigration im
17
17
  }
18
18
  //#endregion
19
19
  export { TypeScriptRenderablePostgresMigration as t };
20
- //# sourceMappingURL=planner-produced-postgres-migration-CRRTno6Z.d.mts.map
20
+ //# sourceMappingURL=planner-produced-postgres-migration-M3EfhWSS.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planner-produced-postgres-migration-M3EfhWSS.d.mts","names":[],"sources":["../src/core/migrations/planner-produced-postgres-migration.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAmCK,EAAA,GAAK,0BAA0B;cAEvB,qCAAA,SACH,iBAAA,YACG;;8BAKiB,+BAA+B;6BAMvB;cAIf"}
@@ -1,5 +1,6 @@
1
+ import "./data-transform-CrpmG4uJ.mjs";
1
2
  import "./shared-Bxkt8pNO.mjs";
2
3
  import "./op-factory-call-C3bWXKSP.mjs";
3
- import "./postgres-migration-BjA3Zmts.mjs";
4
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-CRRTno6Z.mjs";
4
+ import "./postgres-migration-BFjbb25b.mjs";
5
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-M3EfhWSS.mjs";
5
6
  export { TypeScriptRenderablePostgresMigration };
@@ -1,3 +1,3 @@
1
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-DSSPq8QS.mjs";
1
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-Bi-RWO4-.mjs";
2
2
 
3
3
  export { TypeScriptRenderablePostgresMigration };
@@ -1,10 +1,12 @@
1
+ import "./data-transform-CrpmG4uJ.mjs";
1
2
  import "./shared-Bxkt8pNO.mjs";
2
3
  import "./op-factory-call-C3bWXKSP.mjs";
3
- import "./postgres-migration-BjA3Zmts.mjs";
4
- import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-CRRTno6Z.mjs";
4
+ import "./postgres-migration-BFjbb25b.mjs";
5
+ import { t as TypeScriptRenderablePostgresMigration } from "./planner-produced-postgres-migration-M3EfhWSS.mjs";
5
6
  import { MigrationOperationPolicy, SqlPlannerFailureResult } from "@prisma-next/family-sql/control";
6
- import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
7
+ import { Contract } from "@prisma-next/contract/types";
7
8
  import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
9
+ import { MigrationPlanWithAuthoringSurface, MigrationPlanner, MigrationScaffoldContext } from "@prisma-next/framework-components/control";
8
10
 
9
11
  //#region src/core/migrations/planner.d.ts
10
12
  interface PlannerConfig {
@@ -45,16 +47,21 @@ declare class PostgresMigrationPlanner implements MigrationPlanner<'sql', 'postg
45
47
  readonly contract: unknown;
46
48
  readonly schema: unknown;
47
49
  readonly policy: MigrationOperationPolicy;
48
- readonly fromHash?: string;
49
50
  /**
50
51
  * The "from" contract (state the planner assumes the database starts
51
- * at). Only `migration plan` supplies this; `db update` / `db init`
52
- * reconcile against the live schema with no old contract. When present
53
- * alongside the `'data'` operation class, strategies that need from/to
54
- * column shape comparisons (unsafe type change, nullability tightening)
55
- * activate.
52
+ * at), or `null` for reconciliation flows. Only `migration plan` ever
53
+ * supplies a non-null value; `db update` / `db init` reconcile against
54
+ * the live schema and pass `null`. When present alongside the
55
+ * `'data'` operation class, strategies that need from/to column-shape
56
+ * comparisons (unsafe type change, nullability tightening) activate.
57
+ *
58
+ * Typed as the framework `Contract | null` to satisfy the
59
+ * `MigrationPlanner` interface contract; `planSql` narrows to the SQL
60
+ * shape via `SqlMigrationPlannerPlanOptions`. Used to populate
61
+ * `describe().from` on the produced plan as
62
+ * `fromContract?.storage.storageHash ?? null`.
56
63
  */
57
- readonly fromContract?: unknown;
64
+ readonly fromContract: Contract | null;
58
65
  readonly schemaName?: string;
59
66
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
60
67
  }): PostgresPlanResult;
@@ -1 +1 @@
1
- {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;UAkCU,aAAA;;;iBAQM,8BAAA,UACN,QAAQ,iBACf;;AA3B2F;AAyB9F;;;;;AAgBY,KAAA,kBAAA,GAAkB;EAoBjB,SAAA,IAAA,EAAA,SAAA;EAC0B,SAAA,IAAA,EApBQ,qCAoBR;CAKlB,GAxBjB,uBAwBiB;;;;;;;;;;;;;;;;;cANR,wBAAA,YAAoC;;sBACV;;;;qBAKlB;;;;;;;;;;;;kCAYa,cAAc;MAC1C;0BAIoB,2BAA2B"}
1
+ {"version":3,"file":"planner.d.mts","names":[],"sources":["../src/core/migrations/planner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAmCU,aAAA;;;iBAQM,8BAAA,UACN,QAAQ,iBACf;;;AA3B2F;AAyB9F;;;;AAE2B,KAcf,kBAAA,GAde;EAcf,SAAA,IAAA,EAAA,SAAkB;EAoBjB,SAAA,IAAA,EAnBkC,qCAmBT;CACC,GAnBnC,uBAmBmC;;;;;;;;;;;;;;;;;cAD1B,wBAAA,YAAoC;;sBACV;;;;qBAKlB;;;;;;;;;;;;;;;2BAeM;;kCAEO,cAAc;MAC1C;0BAIoB,2BAA2B"}
package/dist/planner.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  import "./issue-planner-CFjB0_oO.mjs";
2
- import { t as createPostgresMigrationPlanner } from "./planner-CLUvVhUN.mjs";
2
+ import { t as createPostgresMigrationPlanner } from "./planner-Cm-ZLutk.mjs";
3
3
 
4
4
  export { createPostgresMigrationPlanner };
@@ -1,5 +1,6 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-DH-azLu-.mjs";
2
- import { n as DataTransformOptions, r as PostgresDataTransformOperation } from "./data-transform-CxFRBIUp.mjs";
2
+ import { n as DataTransformOptions } from "./data-transform-CrpmG4uJ.mjs";
3
+ import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
3
4
  import { Migration } from "@prisma-next/family-sql/migration";
4
5
  import { Contract } from "@prisma-next/contract/types";
5
6
  import { SqlStorage } from "@prisma-next/sql-contract/types";
@@ -43,8 +44,8 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
43
44
  * supplies the stored control adapter. Authors call this from inside
44
45
  * `get operations()`; the adapter argument is hidden from the call site.
45
46
  */
46
- protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): PostgresDataTransformOperation;
47
+ protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
47
48
  }
48
49
  //#endregion
49
50
  export { PostgresMigration as t };
50
- //# sourceMappingURL=postgres-migration-BjA3Zmts.d.mts.map
51
+ //# sourceMappingURL=postgres-migration-BFjbb25b.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-BFjbb25b.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AA8BA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,UAC9C;;;;;;;;qCAWmC;sBAEf;;;;;;4CAesB,SAAS,uBACvC,kCAED,uBACR,0BAA0B"}
@@ -1,5 +1,5 @@
1
1
  import { t as errorPostgresMigrationStackMissing } from "./errors-AFvEPZ1R.mjs";
2
- import { t as dataTransform } from "./data-transform-VfEGzXWt.mjs";
2
+ import { t as dataTransform } from "./data-transform-Be_i_DBc.mjs";
3
3
  import { Migration } from "@prisma-next/family-sql/migration";
4
4
 
5
5
  //#region src/core/migrations/postgres-migration.ts
@@ -49,4 +49,4 @@ var PostgresMigration = class extends Migration {
49
49
 
50
50
  //#endregion
51
51
  export { PostgresMigration as t };
52
- //# sourceMappingURL=postgres-migration-qtmtbONe.mjs.map
52
+ //# sourceMappingURL=postgres-migration-BS9vQW97.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-BS9vQW97.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a target-specific re-export of this\n * class from `@prisma-next/target-postgres/migration`, keeping the\n * authoring surface target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,AAAS,WAAW;;;;;;;CAQpB,AAAmB;CAEnB,YAAY,OAAyC;AACnD,QAAM,MAAM;AAIZ,OAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,MAAM,GAC5B;;;;;;;CAQN,AAAU,cACR,UACA,MACA,SACsD;AACtD,MAAI,CAAC,KAAK,eACR,OAAM,oCAAoC;AAE5C,SAAO,cAAc,UAAU,MAAM,SAAS,KAAK,eAAe"}
@@ -68,7 +68,6 @@ function buildDescribeMethod(meta) {
68
68
  lines.push(" return {");
69
69
  lines.push(` from: ${JSON.stringify(meta.from)},`);
70
70
  lines.push(` to: ${JSON.stringify(meta.to)},`);
71
- if (meta.kind) lines.push(` kind: ${JSON.stringify(meta.kind)},`);
72
71
  if (meta.labels && meta.labels.length > 0) lines.push(` labels: ${jsonToTsSource(meta.labels)},`);
73
72
  lines.push(" };");
74
73
  lines.push(" }");
@@ -82,4 +81,4 @@ function indent(text, spaces) {
82
81
 
83
82
  //#endregion
84
83
  export { renderCallsToTypeScript as t };
85
- //# sourceMappingURL=render-typescript-1rF_SB4g.mjs.map
84
+ //# sourceMappingURL=render-typescript-Co3Emwgz.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-typescript-Co3Emwgz.mjs","names":["BASE_IMPORTS: readonly ImportRequirement[]","requirements: ImportRequirement[]","lines: string[]"],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the Postgres migration IR.\n *\n * Each `PostgresOpFactoryCall` 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 { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, jsonToTsSource, renderImports } from '@prisma-next/ts-render';\nimport type { PostgresOpFactoryCall } from './op-factory-call';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n readonly labels?: readonly string[];\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/target-postgres/migration` so an authored Postgres\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint:\n *\n * - `Migration` — the target-owned re-export fixes the `SqlMigration`\n * generic to `PostgresPlanTargetDetails` and the abstract `targetId`\n * to `'postgres'`, so user-authored migrations don't need to thread\n * target-details or redeclare `targetId`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n * The migration file owns this dependency directly: pulling CLI\n * machinery in at script run time is acceptable because the script's\n * whole purpose is to be invoked from the project that owns the\n * config.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/target-postgres/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<PostgresOpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction buildImports(calls: ReadonlyArray<PostgresOpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n if (meta.labels && meta.labels.length > 0) {\n lines.push(` labels: ${jsonToTsSource(meta.labels)},`);\n }\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAMA,eAA6C,CACjD;CAAE,iBAAiB;CAA0C,QAAQ;CAAa,EAClF;CAAE,iBAAiB;CAA0C,QAAQ;CAAgB,CACtF;AAED,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,MAAM;CACnC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,kBAAkB,CAAC,CAAC,KAAK,MAAM;AAEzE,QAAO;EACL,eAAe,uBAAuB,CAAC;EACvC;EACA;EACA;EACA,oBAAoB,KAAK;EACzB;EACA;EACA,OAAO,gBAAgB,EAAE;EACzB;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;;AAGd,SAAS,aAAa,OAAqD;CACzE,MAAMC,eAAoC,CAAC,GAAG,aAAa;AAC3D,MAAK,MAAM,QAAQ,MACjB,MAAK,MAAM,OAAO,KAAK,oBAAoB,CACzC,cAAa,KAAK,IAAI;AAG1B,QAAO,cAAc,aAAa;;AAGpC,SAAS,oBAAoB,MAAmC;CAC9D,MAAMC,QAAkB,EAAE;AAC1B,OAAM,KAAK,0BAA0B;AACrC,OAAM,KAAK,eAAe;AAC1B,OAAM,KAAK,eAAe,KAAK,UAAU,KAAK,KAAK,CAAC,GAAG;AACvD,OAAM,KAAK,aAAa,KAAK,UAAU,KAAK,GAAG,CAAC,GAAG;AACnD,KAAI,KAAK,UAAU,KAAK,OAAO,SAAS,EACtC,OAAM,KAAK,iBAAiB,eAAe,KAAK,OAAO,CAAC,GAAG;AAE7D,OAAM,KAAK,SAAS;AACpB,OAAM,KAAK,MAAM;AACjB,OAAM,KAAK,GAAG;AACd,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,OAAO,MAAc,QAAwB;CACpD,MAAM,MAAM,IAAI,OAAO,OAAO;AAC9B,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,SAAU,KAAK,MAAM,GAAG,GAAG,MAAM,SAAS,KAAM,CACrD,KAAK,KAAK"}
@@ -4,9 +4,8 @@ import { b as PostgresOpFactoryCall } from "./op-factory-call-C3bWXKSP.mjs";
4
4
  //#region src/core/migrations/render-typescript.d.ts
5
5
 
6
6
  interface RenderMigrationMeta {
7
- readonly from: string;
7
+ readonly from: string | null;
8
8
  readonly to: string;
9
- readonly kind?: string;
10
9
  readonly labels?: readonly string[];
11
10
  }
12
11
  declare function renderCallsToTypeScript(calls: ReadonlyArray<PostgresOpFactoryCall>, meta: RenderMigrationMeta): string;
@@ -1 +1 @@
1
- {"version":3,"file":"render-typescript.d.mts","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;UAeiB,mBAAA;;;;;;iBA8BD,uBAAA,QACP,cAAc,8BACf"}
1
+ {"version":3,"file":"render-typescript.d.mts","names":[],"sources":["../src/core/migrations/render-typescript.ts"],"sourcesContent":[],"mappings":";;;;;UAeiB,mBAAA;;;;;iBA6BD,uBAAA,QACP,cAAc,8BACf"}
@@ -1,3 +1,3 @@
1
- import { t as renderCallsToTypeScript } from "./render-typescript-1rF_SB4g.mjs";
1
+ import { t as renderCallsToTypeScript } from "./render-typescript-Co3Emwgz.mjs";
2
2
 
3
3
  export { renderCallsToTypeScript };
@@ -12,7 +12,8 @@ const ensureMarkerTableStatement = {
12
12
  canonical_version int,
13
13
  updated_at timestamptz not null default now(),
14
14
  app_tag text,
15
- meta jsonb not null default '{}'
15
+ meta jsonb not null default '{}',
16
+ invariants text[] not null default '{}'
16
17
  )`,
17
18
  params: []
18
19
  };
@@ -30,7 +31,7 @@ const ensureLedgerTableStatement = {
30
31
  )`,
31
32
  params: []
32
33
  };
33
- function buildWriteMarkerStatements(input) {
34
+ function buildMergeMarkerStatements(input) {
34
35
  const params = [
35
36
  1,
36
37
  input.storageHash,
@@ -38,7 +39,8 @@ function buildWriteMarkerStatements(input) {
38
39
  jsonParam(input.contractJson),
39
40
  input.canonicalVersion ?? null,
40
41
  input.appTag ?? null,
41
- jsonParam(input.meta ?? {})
42
+ jsonParam(input.meta ?? {}),
43
+ input.invariants
42
44
  ];
43
45
  return {
44
46
  insert: {
@@ -50,7 +52,8 @@ function buildWriteMarkerStatements(input) {
50
52
  canonical_version,
51
53
  updated_at,
52
54
  app_tag,
53
- meta
55
+ meta,
56
+ invariants
54
57
  ) values (
55
58
  $1,
56
59
  $2,
@@ -59,7 +62,8 @@ function buildWriteMarkerStatements(input) {
59
62
  $5,
60
63
  now(),
61
64
  $6,
62
- $7::jsonb
65
+ $7::jsonb,
66
+ $8::text[]
63
67
  )`,
64
68
  params
65
69
  },
@@ -71,7 +75,8 @@ function buildWriteMarkerStatements(input) {
71
75
  canonical_version = $5,
72
76
  updated_at = now(),
73
77
  app_tag = $6,
74
- meta = $7::jsonb
78
+ meta = $7::jsonb,
79
+ invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)
75
80
  where id = $1`,
76
81
  params
77
82
  }
@@ -112,5 +117,5 @@ function jsonParam(value) {
112
117
  }
113
118
 
114
119
  //#endregion
115
- export { ensurePrismaContractSchemaStatement as a, ensureMarkerTableStatement as i, buildWriteMarkerStatements as n, ensureLedgerTableStatement as r, buildLedgerInsertStatement as t };
116
- //# sourceMappingURL=statement-builders-BPnmt6wx.mjs.map
120
+ export { ensurePrismaContractSchemaStatement as a, ensureMarkerTableStatement as i, buildMergeMarkerStatements as n, ensureLedgerTableStatement as r, buildLedgerInsertStatement as t };
121
+ //# sourceMappingURL=statement-builders-CHqCtSfe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statement-builders-CHqCtSfe.mjs","names":["ensurePrismaContractSchemaStatement: SqlStatement","ensureMarkerTableStatement: SqlStatement","ensureLedgerTableStatement: SqlStatement","params: readonly unknown[]"],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":["export interface SqlStatement {\n readonly sql: string;\n readonly params: readonly unknown[];\n}\n\nexport const ensurePrismaContractSchemaStatement: SqlStatement = {\n sql: 'create schema if not exists prisma_contract',\n params: [],\n};\n\nexport const ensureMarkerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.marker (\n id smallint primary key default 1,\n core_hash text not null,\n profile_hash text not null,\n contract_json jsonb,\n canonical_version int,\n updated_at timestamptz not null default now(),\n app_tag text,\n meta jsonb not null default '{}',\n invariants text[] not null default '{}'\n )`,\n params: [],\n};\n\nexport const ensureLedgerTableStatement: SqlStatement = {\n sql: `create table if not exists prisma_contract.ledger (\n id bigserial primary key,\n created_at timestamptz not null default now(),\n origin_core_hash text,\n origin_profile_hash text,\n destination_core_hash text not null,\n destination_profile_hash text,\n contract_json_before jsonb,\n contract_json_after jsonb,\n operations jsonb not null\n )`,\n params: [],\n};\n\nexport interface MergeMarkerInput {\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson?: unknown;\n readonly canonicalVersion?: number | null;\n readonly appTag?: string | null;\n readonly meta?: Record<string, unknown>;\n /**\n * Invariants to merge into `marker.invariants`. INSERT writes them as\n * the initial value (callers are expected to pass a sorted, deduped\n * array). UPDATE merges them with the existing column server-side via\n * a single atomic SQL expression.\n */\n readonly invariants: readonly string[];\n}\n\nexport function buildMergeMarkerStatements(input: MergeMarkerInput): {\n readonly insert: SqlStatement;\n readonly update: SqlStatement;\n} {\n const params: readonly unknown[] = [\n 1,\n input.storageHash,\n input.profileHash,\n jsonParam(input.contractJson),\n input.canonicalVersion ?? null,\n input.appTag ?? null,\n jsonParam(input.meta ?? {}),\n input.invariants,\n ];\n\n return {\n insert: {\n sql: `insert into prisma_contract.marker (\n id,\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta,\n invariants\n ) values (\n $1,\n $2,\n $3,\n $4::jsonb,\n $5,\n now(),\n $6,\n $7::jsonb,\n $8::text[]\n )`,\n params,\n },\n update: {\n // `invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)`\n // reads the current column value under the UPDATE's row lock, unions\n // with the incoming array, dedupes, and sorts ascending — single\n // statement, atomic, no read-then-write window.\n sql: `update prisma_contract.marker set\n core_hash = $2,\n profile_hash = $3,\n contract_json = $4::jsonb,\n canonical_version = $5,\n updated_at = now(),\n app_tag = $6,\n meta = $7::jsonb,\n invariants = array(select distinct unnest(invariants || $8::text[]) order by 1)\n where id = $1`,\n params,\n },\n };\n}\n\nexport interface LedgerInsertInput {\n readonly originStorageHash?: string | null;\n readonly originProfileHash?: string | null;\n readonly destinationStorageHash: string;\n readonly destinationProfileHash?: string | null;\n readonly contractJsonBefore?: unknown;\n readonly contractJsonAfter?: unknown;\n readonly operations: unknown;\n}\n\nexport function buildLedgerInsertStatement(input: LedgerInsertInput): SqlStatement {\n return {\n sql: `insert into prisma_contract.ledger (\n origin_core_hash,\n origin_profile_hash,\n destination_core_hash,\n destination_profile_hash,\n contract_json_before,\n contract_json_after,\n operations\n ) values (\n $1,\n $2,\n $3,\n $4,\n $5::jsonb,\n $6::jsonb,\n $7::jsonb\n )`,\n params: [\n input.originStorageHash ?? null,\n input.originProfileHash ?? null,\n input.destinationStorageHash,\n input.destinationProfileHash ?? null,\n jsonParam(input.contractJsonBefore),\n jsonParam(input.contractJsonAfter),\n jsonParam(input.operations),\n ],\n };\n}\n\nfunction jsonParam(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n"],"mappings":";AAKA,MAAaA,sCAAoD;CAC/D,KAAK;CACL,QAAQ,EAAE;CACX;AAED,MAAaC,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AAED,MAAaC,6BAA2C;CACtD,KAAK;;;;;;;;;;;CAWL,QAAQ,EAAE;CACX;AAkBD,SAAgB,2BAA2B,OAGzC;CACA,MAAMC,SAA6B;EACjC;EACA,MAAM;EACN,MAAM;EACN,UAAU,MAAM,aAAa;EAC7B,MAAM,oBAAoB;EAC1B,MAAM,UAAU;EAChB,UAAU,MAAM,QAAQ,EAAE,CAAC;EAC3B,MAAM;EACP;AAED,QAAO;EACL,QAAQ;GACN,KAAK;;;;;;;;;;;;;;;;;;;;;GAqBL;GACD;EACD,QAAQ;GAKN,KAAK;;;;;;;;;;GAUL;GACD;EACF;;AAaH,SAAgB,2BAA2B,OAAwC;AACjF,QAAO;EACL,KAAK;;;;;;;;;;;;;;;;;EAiBL,QAAQ;GACN,MAAM,qBAAqB;GAC3B,MAAM,qBAAqB;GAC3B,MAAM;GACN,MAAM,0BAA0B;GAChC,UAAU,MAAM,mBAAmB;GACnC,UAAU,MAAM,kBAAkB;GAClC,UAAU,MAAM,WAAW;GAC5B;EACF;;AAGH,SAAS,UAAU,OAAwB;AACzC,QAAO,KAAK,UAAU,SAAS,KAAK"}
@@ -6,18 +6,25 @@ interface SqlStatement {
6
6
  declare const ensurePrismaContractSchemaStatement: SqlStatement;
7
7
  declare const ensureMarkerTableStatement: SqlStatement;
8
8
  declare const ensureLedgerTableStatement: SqlStatement;
9
- interface WriteMarkerInput {
9
+ interface MergeMarkerInput {
10
10
  readonly storageHash: string;
11
11
  readonly profileHash: string;
12
12
  readonly contractJson?: unknown;
13
13
  readonly canonicalVersion?: number | null;
14
14
  readonly appTag?: string | null;
15
15
  readonly meta?: Record<string, unknown>;
16
+ /**
17
+ * Invariants to merge into `marker.invariants`. INSERT writes them as
18
+ * the initial value (callers are expected to pass a sorted, deduped
19
+ * array). UPDATE merges them with the existing column server-side via
20
+ * a single atomic SQL expression.
21
+ */
22
+ readonly invariants: readonly string[];
16
23
  }
17
- declare function buildWriteMarkerStatements(input: WriteMarkerInput): {
24
+ declare function buildMergeMarkerStatements(input: MergeMarkerInput): {
18
25
  readonly insert: SqlStatement;
19
26
  readonly update: SqlStatement;
20
27
  };
21
28
  //#endregion
22
- export { type SqlStatement, buildWriteMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
29
+ export { type SqlStatement, buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
23
30
  //# sourceMappingURL=statement-builders.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":[],"mappings":";UAAiB,YAAA;EAAA,SAAA,GAAA,EAAA,MAAY;EAKhB,SAAA,MAAA,EAAA,SAAA,OAAA,EAAA;AAKb;AAca,cAnBA,mCAmB4B,EAnBS,YAgCjD;AAEgB,cA7BJ,0BAmCW,EAnCiB,YAmCjB;AAGR,cAxBH,0BAwB6B,EAxBD,YAwBC;AAAQ,UATjC,gBAAA,CASiC;EAC/B,SAAA,WAAA,EAAA,MAAA;EACA,SAAA,WAAA,EAAA,MAAA;EAAY,SAAA,YAAA,CAAA,EAAA,OAAA;;;kBALb;;iBAGF,0BAAA,QAAkC;mBAC/B;mBACA"}
1
+ {"version":3,"file":"statement-builders.d.mts","names":[],"sources":["../src/core/migrations/statement-builders.ts"],"sourcesContent":[],"mappings":";UAAiB,YAAA;EAAA,SAAA,GAAA,EAAA,MAAY;EAKhB,SAAA,MAAA,EAAA,SAAA,OAAA,EAAA;AAKb;AAea,cApBA,mCAoB4B,EApBS,YAiCjD;AAEgB,cA9BJ,0BAoCW,EApCiB,YAoCjB;AAUR,cA/BH,0BA+B6B,EA/BD,YA+BC;AAAQ,UAhBjC,gBAAA,CAgBiC;EAC/B,SAAA,WAAA,EAAA,MAAA;EACA,SAAA,WAAA,EAAA,MAAA;EAAY,SAAA,YAAA,CAAA,EAAA,OAAA;;;kBAZb;;;;;;;;;iBAUF,0BAAA,QAAkC;mBAC/B;mBACA"}
@@ -1,3 +1,3 @@
1
- import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as buildWriteMarkerStatements, r as ensureLedgerTableStatement } from "./statement-builders-BPnmt6wx.mjs";
1
+ import { a as ensurePrismaContractSchemaStatement, i as ensureMarkerTableStatement, n as buildMergeMarkerStatements, r as ensureLedgerTableStatement } from "./statement-builders-CHqCtSfe.mjs";
2
2
 
3
- export { buildWriteMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
3
+ export { buildMergeMarkerStatements, ensureLedgerTableStatement, ensureMarkerTableStatement, ensurePrismaContractSchemaStatement };
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.5.0-dev.5",
3
+ "version": "0.5.0-dev.51",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Postgres target pack for Prisma Next",
7
7
  "dependencies": {
8
8
  "arktype": "^2.0.0",
9
9
  "pathe": "^2.0.3",
10
- "@prisma-next/cli": "0.5.0-dev.5",
11
- "@prisma-next/contract": "0.5.0-dev.5",
12
- "@prisma-next/errors": "0.5.0-dev.5",
13
- "@prisma-next/framework-components": "0.5.0-dev.5",
14
- "@prisma-next/migration-tools": "0.5.0-dev.5",
15
- "@prisma-next/ts-render": "0.5.0-dev.5",
16
- "@prisma-next/sql-errors": "0.5.0-dev.5",
17
- "@prisma-next/family-sql": "0.5.0-dev.5",
18
- "@prisma-next/sql-operations": "0.5.0-dev.5",
19
- "@prisma-next/sql-contract": "0.5.0-dev.5",
20
- "@prisma-next/sql-relational-core": "0.5.0-dev.5",
21
- "@prisma-next/utils": "0.5.0-dev.5",
22
- "@prisma-next/sql-schema-ir": "0.5.0-dev.5"
10
+ "@prisma-next/contract": "0.5.0-dev.51",
11
+ "@prisma-next/errors": "0.5.0-dev.51",
12
+ "@prisma-next/family-sql": "0.5.0-dev.51",
13
+ "@prisma-next/framework-components": "0.5.0-dev.51",
14
+ "@prisma-next/migration-tools": "0.5.0-dev.51",
15
+ "@prisma-next/sql-errors": "0.5.0-dev.51",
16
+ "@prisma-next/cli": "0.5.0-dev.51",
17
+ "@prisma-next/ts-render": "0.5.0-dev.51",
18
+ "@prisma-next/sql-operations": "0.5.0-dev.51",
19
+ "@prisma-next/sql-relational-core": "0.5.0-dev.51",
20
+ "@prisma-next/sql-schema-ir": "0.5.0-dev.51",
21
+ "@prisma-next/utils": "0.5.0-dev.51",
22
+ "@prisma-next/sql-contract": "0.5.0-dev.51"
23
23
  },
24
24
  "devDependencies": {
25
25
  "tsdown": "0.18.4",
26
26
  "typescript": "5.9.3",
27
27
  "vitest": "4.0.17",
28
28
  "@prisma-next/test-utils": "0.0.1",
29
- "@prisma-next/tsdown": "0.0.0",
30
- "@prisma-next/tsconfig": "0.0.0"
29
+ "@prisma-next/tsconfig": "0.0.0",
30
+ "@prisma-next/tsdown": "0.0.0"
31
31
  },
32
32
  "files": [
33
33
  "dist",
@@ -28,3 +28,4 @@ export const PG_TIMETZ_CODEC_ID = 'pg/timetz@1' as const;
28
28
  export const PG_INTERVAL_CODEC_ID = 'pg/interval@1' as const;
29
29
  export const PG_JSON_CODEC_ID = 'pg/json@1' as const;
30
30
  export const PG_JSONB_CODEC_ID = 'pg/jsonb@1' as const;
31
+ export const PG_BYTEA_CODEC_ID = 'pg/bytea@1' as const;
@@ -19,6 +19,7 @@ import { type as arktype } from 'arktype';
19
19
  import {
20
20
  PG_BIT_CODEC_ID,
21
21
  PG_BOOL_CODEC_ID,
22
+ PG_BYTEA_CODEC_ID,
22
23
  PG_CHAR_CODEC_ID,
23
24
  PG_ENUM_CODEC_ID,
24
25
  PG_FLOAT_CODEC_ID,
@@ -40,7 +41,6 @@ import {
40
41
  PG_VARBIT_CODEC_ID,
41
42
  PG_VARCHAR_CODEC_ID,
42
43
  } from './codec-ids';
43
- import { renderTypeScriptTypeFromJsonSchema } from './json-schema-type-expression';
44
44
 
45
45
  const lengthParamsSchema = arktype({
46
46
  length: 'number.integer > 0',
@@ -85,19 +85,13 @@ function renderPrecision(typeName: string, typeParams: Record<string, unknown>):
85
85
  return `${typeName}<${precision}>`;
86
86
  }
87
87
 
88
- function renderJsonOutputType(typeParams: Record<string, unknown>): string {
89
- const typeName = typeParams['type'];
90
- if (typeof typeName === 'string' && typeName.trim().length > 0) {
91
- return typeName.trim();
92
- }
93
- const schema = typeParams['schemaJson'];
94
- if (schema && typeof schema === 'object') {
95
- return renderTypeScriptTypeFromJsonSchema(schema);
96
- }
97
- throw new Error(
98
- `renderOutputType: JSON codec typeParams must contain "type" (string) or "schemaJson" (object), got keys: ${Object.keys(typeParams).join(', ')}`,
99
- );
100
- }
88
+ // Phase C: postgres' raw json/jsonb codecs no longer carry a
89
+ // `renderOutputType` slot — the schema-typed JSON surface that drove
90
+ // `typeParams: { schemaJson, type? }` retired in favor of the per-library
91
+ // extension package (`@prisma-next/extension-arktype-json`). Untyped
92
+ // json/jsonb columns have no typeParams; the framework emit path falls
93
+ // through to the generic `CodecTypes['pg/jsonb@1']['output']` accessor
94
+ // (which resolves to `JsonValue` via the codec-types map).
101
95
 
102
96
  function aliasCodec<
103
97
  Id extends string,
@@ -339,22 +333,15 @@ const pgFloat8Codec = codec({
339
333
  const pgTimestampCodec = codec<
340
334
  typeof PG_TIMESTAMP_CODEC_ID,
341
335
  readonly ['equality', 'order'],
342
- string | Date,
343
- string | Date
336
+ Date,
337
+ Date
344
338
  >({
345
339
  typeId: PG_TIMESTAMP_CODEC_ID,
346
340
  targetTypes: ['timestamp'],
347
341
  traits: ['equality', 'order'],
348
- encode: (value: string | Date): string => {
349
- if (value instanceof Date) return value.toISOString();
350
- if (typeof value === 'string') return value;
351
- return String(value);
352
- },
353
- decode: (wire: string | Date): string => {
354
- if (wire instanceof Date) return wire.toISOString();
355
- return wire;
356
- },
357
- encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),
342
+ encode: (value: Date): Date => value,
343
+ decode: (wire: Date): Date => wire,
344
+ encodeJson: (value: Date) => value.toISOString(),
358
345
  decodeJson: (json) => {
359
346
  if (typeof json !== 'string') {
360
347
  throw new Error(`Expected ISO date string for pg/timestamp@1, got ${typeof json}`);
@@ -381,22 +368,15 @@ const pgTimestampCodec = codec<
381
368
  const pgTimestamptzCodec = codec<
382
369
  typeof PG_TIMESTAMPTZ_CODEC_ID,
383
370
  readonly ['equality', 'order'],
384
- string | Date,
385
- string | Date
371
+ Date,
372
+ Date
386
373
  >({
387
374
  typeId: PG_TIMESTAMPTZ_CODEC_ID,
388
375
  targetTypes: ['timestamptz'],
389
376
  traits: ['equality', 'order'],
390
- encode: (value: string | Date): string => {
391
- if (value instanceof Date) return value.toISOString();
392
- if (typeof value === 'string') return value;
393
- return String(value);
394
- },
395
- decode: (wire: string | Date): string => {
396
- if (wire instanceof Date) return wire.toISOString();
397
- return wire;
398
- },
399
- encodeJson: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),
377
+ encode: (value: Date): Date => value,
378
+ decode: (wire: Date): Date => wire,
379
+ encodeJson: (value: Date) => value.toISOString(),
400
380
  decodeJson: (json) => {
401
381
  if (typeof json !== 'string') {
402
382
  throw new Error(`Expected ISO date string for pg/timestamptz@1, got ${typeof json}`);
@@ -523,6 +503,40 @@ const pgVarbitCodec = codec<
523
503
  },
524
504
  });
525
505
 
506
+ const pgByteaCodec = codec({
507
+ typeId: PG_BYTEA_CODEC_ID,
508
+ targetTypes: ['bytea'],
509
+ traits: ['equality'],
510
+ encode: (value: Uint8Array): Uint8Array => value,
511
+ decode: (wire: Uint8Array): Uint8Array =>
512
+ // Postgres node drivers commonly return Buffer instances (which extend
513
+ // Uint8Array) — normalize to a plain Uint8Array view so engine-agnostic
514
+ // consumers don't accidentally observe Buffer-specific APIs.
515
+ wire instanceof Uint8Array && wire.constructor === Uint8Array
516
+ ? wire
517
+ : new Uint8Array(wire.buffer, wire.byteOffset, wire.byteLength),
518
+ encodeJson: (value: Uint8Array): string => Buffer.from(value).toString('base64'),
519
+ decodeJson: (json): Uint8Array => {
520
+ if (typeof json !== 'string') {
521
+ throw new Error(`Expected base64 string for pg/bytea@1, got ${typeof json}`);
522
+ }
523
+ const decoded = Buffer.from(json, 'base64');
524
+ if (decoded.toString('base64') !== json) {
525
+ throw new Error(`Invalid base64 string for pg/bytea@1 (length: ${json.length})`);
526
+ }
527
+ return new Uint8Array(decoded);
528
+ },
529
+ meta: {
530
+ db: {
531
+ sql: {
532
+ postgres: {
533
+ nativeType: 'bytea',
534
+ },
535
+ },
536
+ },
537
+ },
538
+ });
539
+
526
540
  const pgEnumCodec = codec({
527
541
  typeId: PG_ENUM_CODEC_ID,
528
542
  targetTypes: ['enum'],
@@ -576,7 +590,6 @@ const pgJsonCodec = codec({
576
590
  encode: (value: string | JsonValue): string => JSON.stringify(value),
577
591
  decode: (wire: string | JsonValue): JsonValue =>
578
592
  typeof wire === 'string' ? JSON.parse(wire) : wire,
579
- renderOutputType: renderJsonOutputType,
580
593
  meta: {
581
594
  db: {
582
595
  sql: {
@@ -595,7 +608,6 @@ const pgJsonbCodec = codec({
595
608
  encode: (value: string | JsonValue): string => JSON.stringify(value),
596
609
  decode: (wire: string | JsonValue): JsonValue =>
597
610
  typeof wire === 'string' ? JSON.parse(wire) : wire,
598
- renderOutputType: renderJsonOutputType,
599
611
  meta: {
600
612
  db: {
601
613
  sql: {
@@ -633,6 +645,7 @@ const codecs = defineCodecs()
633
645
  .add('bool', pgBoolCodec)
634
646
  .add('bit', pgBitCodec)
635
647
  .add('bit varying', pgVarbitCodec)
648
+ .add('bytea', pgByteaCodec)
636
649
  .add('interval', pgIntervalCodec)
637
650
  .add('enum', pgEnumCodec)
638
651
  .add('json', pgJsonCodec)