@prisma-next/target-postgres 0.13.0-dev.15 → 0.13.0-dev.17

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 (74) hide show
  1. package/dist/control.mjs +17 -20
  2. package/dist/control.mjs.map +1 -1
  3. package/dist/{data-transform-D25tLeYU.mjs → data-transform-BOWpliq8.mjs} +9 -17
  4. package/dist/data-transform-BOWpliq8.mjs.map +1 -0
  5. package/dist/{data-transform-DGOqcLrf.d.mts → data-transform-DDgWdB5o.d.mts} +2 -2
  6. package/dist/data-transform-DDgWdB5o.d.mts.map +1 -0
  7. package/dist/data-transform.d.mts +1 -1
  8. package/dist/data-transform.mjs +1 -1
  9. package/dist/{enum-planning-DTMrPLkN.mjs → enum-planning-CHWGiz0L.mjs} +2 -2
  10. package/dist/{enum-planning-DTMrPLkN.mjs.map → enum-planning-CHWGiz0L.mjs.map} +1 -1
  11. package/dist/enum-planning.mjs +1 -1
  12. package/dist/{issue-planner-B0A7RFN2.mjs → issue-planner-BtknIL8A.mjs} +13 -6
  13. package/dist/issue-planner-BtknIL8A.mjs.map +1 -0
  14. package/dist/issue-planner.d.mts +1 -1
  15. package/dist/issue-planner.d.mts.map +1 -1
  16. package/dist/issue-planner.mjs +1 -1
  17. package/dist/migration.d.mts +2 -2
  18. package/dist/migration.mjs +3 -3
  19. package/dist/{op-factory-call-DMA86_2D.d.mts → op-factory-call-DEvD9sbB.d.mts} +5 -5
  20. package/dist/op-factory-call-DEvD9sbB.d.mts.map +1 -0
  21. package/dist/{op-factory-call-Clp7Zr1z.mjs → op-factory-call-QFiNG9lu.mjs} +17 -9
  22. package/dist/op-factory-call-QFiNG9lu.mjs.map +1 -0
  23. package/dist/op-factory-call.d.mts +1 -1
  24. package/dist/op-factory-call.mjs +1 -1
  25. package/dist/{planner-DID7RZCQ.mjs → planner-Bx4NB1Du.mjs} +5 -5
  26. package/dist/planner-Bx4NB1Du.mjs.map +1 -0
  27. package/dist/{planner-produced-postgres-migration-B4EDvLdz.d.mts → planner-produced-postgres-migration-CIX9peJN.d.mts} +5 -6
  28. package/dist/planner-produced-postgres-migration-CIX9peJN.d.mts.map +1 -0
  29. package/dist/{planner-produced-postgres-migration-B8gZBPOR.mjs → planner-produced-postgres-migration-LZZMczh2.mjs} +6 -4
  30. package/dist/planner-produced-postgres-migration-LZZMczh2.mjs.map +1 -0
  31. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  32. package/dist/planner-produced-postgres-migration.mjs +1 -1
  33. package/dist/{planner-sql-checks-DRD5E8A1.mjs → planner-sql-checks-CrAbk7gX.mjs} +2 -2
  34. package/dist/{planner-sql-checks-DRD5E8A1.mjs.map → planner-sql-checks-CrAbk7gX.mjs.map} +1 -1
  35. package/dist/planner-sql-checks.mjs +1 -1
  36. package/dist/planner.d.mts +4 -4
  37. package/dist/planner.d.mts.map +1 -1
  38. package/dist/planner.mjs +1 -1
  39. package/dist/{postgres-contract-serializer-DCg7YaP3.mjs → postgres-contract-serializer-DFpLrLiH.mjs} +2 -2
  40. package/dist/{postgres-contract-serializer-DCg7YaP3.mjs.map → postgres-contract-serializer-DFpLrLiH.mjs.map} +1 -1
  41. package/dist/{postgres-migration-BCQEjFHK.mjs → postgres-migration-FeZUzZOH.mjs} +3 -3
  42. package/dist/{postgres-migration-BCQEjFHK.mjs.map → postgres-migration-FeZUzZOH.mjs.map} +1 -1
  43. package/dist/{postgres-migration-DZ_gLUOW.d.mts → postgres-migration-h_DA3LRq.d.mts} +5 -5
  44. package/dist/postgres-migration-h_DA3LRq.d.mts.map +1 -0
  45. package/dist/{postgres-schema-BVTA2QH7.mjs → postgres-schema-BAgkIU9u.mjs} +2 -2
  46. package/dist/postgres-schema-BAgkIU9u.mjs.map +1 -0
  47. package/dist/{render-ops-BpjstrKQ.mjs → render-ops-BREh1kHe.mjs} +10 -5
  48. package/dist/render-ops-BREh1kHe.mjs.map +1 -0
  49. package/dist/render-ops.d.mts +2 -2
  50. package/dist/render-ops.d.mts.map +1 -1
  51. package/dist/render-ops.mjs +1 -1
  52. package/dist/runtime.mjs +1 -1
  53. package/dist/types.mjs +1 -1
  54. package/package.json +17 -17
  55. package/src/core/migrations/issue-planner.ts +24 -3
  56. package/src/core/migrations/op-factory-call.ts +22 -9
  57. package/src/core/migrations/operations/data-transform.ts +15 -18
  58. package/src/core/migrations/planner-produced-postgres-migration.ts +15 -7
  59. package/src/core/migrations/planner.ts +6 -4
  60. package/src/core/migrations/postgres-migration.ts +3 -3
  61. package/src/core/migrations/render-ops.ts +26 -13
  62. package/src/core/migrations/runner.ts +26 -16
  63. package/src/core/postgres-schema.ts +1 -1
  64. package/dist/data-transform-D25tLeYU.mjs.map +0 -1
  65. package/dist/data-transform-DGOqcLrf.d.mts.map +0 -1
  66. package/dist/issue-planner-B0A7RFN2.mjs.map +0 -1
  67. package/dist/op-factory-call-Clp7Zr1z.mjs.map +0 -1
  68. package/dist/op-factory-call-DMA86_2D.d.mts.map +0 -1
  69. package/dist/planner-DID7RZCQ.mjs.map +0 -1
  70. package/dist/planner-produced-postgres-migration-B4EDvLdz.d.mts.map +0 -1
  71. package/dist/planner-produced-postgres-migration-B8gZBPOR.mjs.map +0 -1
  72. package/dist/postgres-migration-DZ_gLUOW.d.mts.map +0 -1
  73. package/dist/postgres-schema-BVTA2QH7.mjs.map +0 -1
  74. package/dist/render-ops-BpjstrKQ.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-contract-serializer-DCg7YaP3.mjs","names":["rawRecord"],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceTablesInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport type { Type } from 'arktype';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport type { PostgresEnumType } from './postgres-enum-type';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n typeof (output as AuthoringEntityTypeFactoryOutput).factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits the maps the\n * family base consumes — hydrators and validator-schema fragments, both\n * keyed by the descriptor's `discriminator`.\n */\nfunction collectEntityRegistryContributions(namespace: AuthoringEntityTypeNamespace): {\n readonly entityTypeRegistry: ReadonlyMap<string, SqlEntityHydrationFactory>;\n readonly validatorFragments: ReadonlyMap<string, Type<unknown>>;\n} {\n const entityTypeRegistry = new Map<string, SqlEntityHydrationFactory>();\n const validatorFragments = new Map<string, Type<unknown>>();\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 entityTypeRegistry.set(value.discriminator, (raw) =>\n factory(raw, POSTGRES_AUTHORING_CTX),\n );\n }\n if (value.validatorSchema !== undefined) {\n validatorFragments.set(value.discriminator, value.validatorSchema);\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return { entityTypeRegistry, validatorFragments };\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n const { entityTypeRegistry, validatorFragments } = collectEntityRegistryContributions(\n postgresAuthoringEntityTypes,\n );\n super(entityTypeRegistry, validatorFragments);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = blindCast<\n SqlNamespaceTablesInput,\n 'super.hydrateSqlNamespaceEntry returns the tables form when raw is not a NamespaceBase'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n // Extract the postgres-specific `type` slot directly from raw input.\n // The family base handles the `table` slot; the postgres target owns `type`.\n const rawRecord = raw as Record<string, unknown>;\n const rawEntries = rawRecord['entries'];\n let typeSlot: Record<string, PostgresEnumType> | undefined;\n if (rawEntries !== null && typeof rawEntries === 'object' && !Array.isArray(rawEntries)) {\n const rawTypeSlot = (rawEntries as Record<string, unknown>)['type'];\n if (rawTypeSlot !== null && typeof rawTypeSlot === 'object' && !Array.isArray(rawTypeSlot)) {\n const enumFactory = this.entityTypeRegistry.get('postgres-enum');\n typeSlot = Object.fromEntries(\n Object.entries(rawTypeSlot as Record<string, unknown>).map(([name, entry]) => [\n name,\n blindCast<PostgresEnumType, 'postgres-enum factory returns PostgresEnumType'>(\n enumFactory !== undefined ? enumFactory(entry) : entry,\n ),\n ]),\n );\n }\n }\n\n const valueSetSlot = entries.valueSet;\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n const emptyTables = Object.keys(entries.table).length === 0;\n const emptyTypes = !typeSlot || Object.keys(typeSlot).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyTypes && !hasValueSets) {\n return PostgresSchema.unbound;\n }\n return new PostgresSchema({\n id,\n entries: {\n table: entries.table,\n type: typeSlot ?? {},\n ...(hasValueSets ? { valueSet: valueSetSlot } : {}),\n },\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: Object.fromEntries(\n Object.entries(ns.entries.table).map(([tableName, table]) => [\n tableName,\n this.serializeJsonValue(table) as JsonObject,\n ]),\n ),\n },\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonValue(entry) as JsonObject;\n }\n storageOut['types'] = typesOut;\n }\n return {\n ...rest,\n storage: storageOut,\n } as unknown as JsonObject;\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.entries.table)) {\n tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;\n }\n const typeOut: Record<string, JsonObject> = {};\n for (const [typeName, ty] of Object.entries(ns.entries.type)) {\n typeOut[typeName] = this.serializeJsonValue(ty) as JsonObject;\n }\n const valueSetEntries = ns.entries.valueSet;\n const valueSetOut: Record<string, JsonObject> = {};\n if (valueSetEntries !== undefined) {\n for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) {\n valueSetOut[valueSetName] = blindCast<\n JsonObject,\n 'serializeJsonValue round-trips the value-set node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(valueSet));\n }\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: tablesOut,\n type: typeOut,\n ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),\n },\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;;AAwBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,OAAQ,OAA4C,YAAY;AAEpE;;;;;;AAOA,SAAS,mCAAmC,WAG1C;CACA,MAAM,qCAAqB,IAAI,IAAuC;CACtE,MAAM,qCAAqB,IAAI,IAA2B;CAC1D,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,mBAAmB,IAAI,MAAM,gBAAgB,QAC3C,QAAQ,KAAK,sBAAsB,CACrC;IACF;IACA,IAAI,MAAM,oBAAoB,KAAA,GAC5B,mBAAmB,IAAI,MAAM,eAAe,MAAM,eAAe;IAEnE;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,KAAK,KAAK;EAEd;CACF;CACA,KAAK,SAAS;CACd,OAAO;EAAE;EAAoB;CAAmB;AAClD;AAEA,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,cAAc;EACZ,MAAM,EAAE,oBAAoB,uBAAuB,mCACjD,4BACF;EACA,MAAM,oBAAoB,kBAAkB;CAC9C;CAEA,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAMT,MAAM,EAAE,IAAI,YAJK,UAGf,MAAM,yBAAyB,MAAM,GAAG,CACX;EAK/B,MAAM,aAAaA,IAAU;EAC7B,IAAI;EACJ,IAAI,eAAe,QAAQ,OAAO,eAAe,YAAY,CAAC,MAAM,QAAQ,UAAU,GAAG;GACvF,MAAM,cA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AAsC;GAC1C,aAAa,OAAO,QAAQ,WAAW;GACvC,YAAY;EACd;EACA,IAAI,QAAQ,UAAU,KAAA,GAAW;GAC/B,MAAM,WAAuC,CAAC;GAC9C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,KAAK,GACtD,SAAS,QAAQ,KAAK,mBAAmB,KAAK;GAEhD,WAAW,WAAW;EACxB;EACA,OAAO;GACL,GAAG;GACH,SAAS;EACX;CACF;CAEA,2BAAmC,IAAoB,eAAoC;EACzF,MAAM,YAAwC,CAAC;EAC/C,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,QAAQ,KAAK,GAC9D,UAAU,aAAa,KAAK,mBAAmB,KAAK;EAEtD,MAAM,UAAsC,CAAC;EAC7C,KAAK,MAAM,CAAC,UAAU,OAAO,OAAO,QAAQ,GAAG,QAAQ,IAAI,GACzD,QAAQ,YAAY,KAAK,mBAAmB,EAAE;EAEhD,MAAM,kBAAkB,GAAG,QAAQ;EACnC,MAAM,cAA0C,CAAC;EACjD,IAAI,oBAAoB,KAAA,GACtB,KAAK,MAAM,CAAC,cAAc,aAAa,OAAO,QAAQ,eAAe,GACnE,YAAY,gBAAgB,UAG1B,KAAK,mBAAmB,QAAQ,CAAC;EAGvC,OAAO;GACL,IAAI,GAAG;GACP,MAAM,gBAAgB,4BAA4B;GAClD,SAAS;IACP,OAAO;IACP,MAAM;IACN,GAAI,OAAO,KAAK,WAAW,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,YAAY,IAAI,CAAC;GACzE;EACF;CACF;CAEA,mBAA2B,OAAyB;EAClD,OAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;CACzC;AACF"}
1
+ {"version":3,"file":"postgres-contract-serializer-DFpLrLiH.mjs","names":["rawRecord"],"sources":["../src/core/postgres-contract-serializer.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport {\n SqlContractSerializerBase,\n type SqlEntityHydrationFactory,\n} from '@prisma-next/family-sql/ir';\nimport {\n type AuthoringEntityContext,\n type AuthoringEntityTypeFactoryOutput,\n type AuthoringEntityTypeNamespace,\n isAuthoringEntityTypeDescriptor,\n} from '@prisma-next/framework-components/authoring';\nimport {\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceTablesInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport type { Type } from 'arktype';\nimport { postgresAuthoringEntityTypes } from './authoring';\nimport type { PostgresEnumType } from './postgres-enum-type';\nimport { isPostgresSchema, PostgresSchema } from './postgres-schema';\n\nconst POSTGRES_AUTHORING_CTX: AuthoringEntityContext = {\n family: 'sql',\n target: 'postgres',\n};\n\nfunction isAuthoringEntityTypeFactoryOutput(\n output: unknown,\n): output is AuthoringEntityTypeFactoryOutput<unknown, unknown> {\n return (\n typeof output === 'object' &&\n output !== null &&\n typeof (output as AuthoringEntityTypeFactoryOutput).factory === 'function'\n );\n}\n\n/**\n * Walks a pack's entity-type namespace tree and emits the maps the\n * family base consumes — hydrators and validator-schema fragments, both\n * keyed by the descriptor's `discriminator`.\n */\nfunction collectEntityRegistryContributions(namespace: AuthoringEntityTypeNamespace): {\n readonly entityTypeRegistry: ReadonlyMap<string, SqlEntityHydrationFactory>;\n readonly validatorFragments: ReadonlyMap<string, Type<unknown>>;\n} {\n const entityTypeRegistry = new Map<string, SqlEntityHydrationFactory>();\n const validatorFragments = new Map<string, Type<unknown>>();\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 entityTypeRegistry.set(value.discriminator, (raw) =>\n factory(raw, POSTGRES_AUTHORING_CTX),\n );\n }\n if (value.validatorSchema !== undefined) {\n validatorFragments.set(value.discriminator, value.validatorSchema);\n }\n continue;\n }\n if (typeof value === 'object' && value !== null) {\n walk(value);\n }\n }\n };\n walk(namespace);\n return { entityTypeRegistry, validatorFragments };\n}\n\nexport class PostgresContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n const { entityTypeRegistry, validatorFragments } = collectEntityRegistryContributions(\n postgresAuthoringEntityTypes,\n );\n super(entityTypeRegistry, validatorFragments);\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = blindCast<\n SqlNamespaceTablesInput,\n 'super.hydrateSqlNamespaceEntry returns the tables form when raw is not a NamespaceBase'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n const { id, entries } = hydrated;\n\n // Extract the postgres-specific `type` slot directly from raw input.\n // The family base handles the `table` slot; the postgres target owns `type`.\n const rawRecord = raw as Record<string, unknown>;\n const rawEntries = rawRecord['entries'];\n let typeSlot: Record<string, PostgresEnumType> | undefined;\n if (rawEntries !== null && typeof rawEntries === 'object' && !Array.isArray(rawEntries)) {\n const rawTypeSlot = (rawEntries as Record<string, unknown>)['type'];\n if (rawTypeSlot !== null && typeof rawTypeSlot === 'object' && !Array.isArray(rawTypeSlot)) {\n const enumFactory = this.entityTypeRegistry.get('postgres-enum');\n typeSlot = Object.fromEntries(\n Object.entries(rawTypeSlot as Record<string, unknown>).map(([name, entry]) => [\n name,\n blindCast<PostgresEnumType, 'postgres-enum factory returns PostgresEnumType'>(\n enumFactory !== undefined ? enumFactory(entry) : entry,\n ),\n ]),\n );\n }\n }\n\n const valueSetSlot = entries.valueSet;\n const hasValueSets = valueSetSlot !== undefined && Object.keys(valueSetSlot).length > 0;\n const emptyTables = Object.keys(entries.table).length === 0;\n const emptyTypes = !typeSlot || Object.keys(typeSlot).length === 0;\n if (id === UNBOUND_NAMESPACE_ID && emptyTables && emptyTypes && !hasValueSets) {\n return PostgresSchema.unbound;\n }\n return new PostgresSchema({\n id,\n entries: {\n table: entries.table,\n type: typeSlot ?? {},\n ...(hasValueSets ? { valueSet: valueSetSlot } : {}),\n },\n });\n }\n\n override serializeContract(contract: Contract<SqlStorage>): JsonObject {\n const { storage, ...rest } = contract;\n const namespacesJson: Record<string, JsonObject> = {};\n for (const [nsId, ns] of Object.entries(storage.namespaces)) {\n if (isPostgresSchema(ns)) {\n namespacesJson[nsId] = this.serializePostgresNamespace(ns, ns.id === UNBOUND_NAMESPACE_ID);\n } else {\n const isUnboundSlot = nsId === UNBOUND_NAMESPACE_ID;\n namespacesJson[nsId] = {\n id: nsId,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: Object.fromEntries(\n Object.entries(ns.entries.table).map(([tableName, table]) => [\n tableName,\n this.serializeJsonValue(table) as JsonObject,\n ]),\n ),\n },\n };\n }\n }\n const storageOut: Record<string, unknown> = {\n storageHash: String(storage.storageHash),\n namespaces: namespacesJson,\n };\n if (storage.types !== undefined) {\n const typesOut: Record<string, JsonObject> = {};\n for (const [name, entry] of Object.entries(storage.types)) {\n typesOut[name] = this.serializeJsonValue(entry) as JsonObject;\n }\n storageOut['types'] = typesOut;\n }\n return {\n ...rest,\n storage: storageOut,\n } as unknown as JsonObject;\n }\n\n private serializePostgresNamespace(ns: PostgresSchema, isUnboundSlot: boolean): JsonObject {\n const tablesOut: Record<string, JsonObject> = {};\n for (const [tableName, table] of Object.entries(ns.entries.table)) {\n tablesOut[tableName] = this.serializeJsonValue(table) as JsonObject;\n }\n const typeOut: Record<string, JsonObject> = {};\n for (const [typeName, ty] of Object.entries(ns.entries.type)) {\n typeOut[typeName] = this.serializeJsonValue(ty) as JsonObject;\n }\n const valueSetEntries = ns.entries.valueSet;\n const valueSetOut: Record<string, JsonObject> = {};\n if (valueSetEntries !== undefined) {\n for (const [valueSetName, valueSet] of Object.entries(valueSetEntries)) {\n valueSetOut[valueSetName] = blindCast<\n JsonObject,\n 'serializeJsonValue round-trips the value-set node through JSON, yielding a JsonObject'\n >(this.serializeJsonValue(valueSet));\n }\n }\n return {\n id: ns.id,\n kind: isUnboundSlot ? 'postgres-unbound-schema' : 'postgres-schema',\n entries: {\n table: tablesOut,\n type: typeOut,\n ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),\n },\n };\n }\n\n private serializeJsonValue(value: unknown): unknown {\n return JSON.parse(JSON.stringify(value)) as unknown;\n }\n}\n"],"mappings":";;;;;;;AAwBA,MAAM,yBAAiD;CACrD,QAAQ;CACR,QAAQ;AACV;AAEA,SAAS,mCACP,QAC8D;CAC9D,OACE,OAAO,WAAW,YAClB,WAAW,QACX,OAAQ,OAA4C,YAAY;AAEpE;;;;;;AAOA,SAAS,mCAAmC,WAG1C;CACA,MAAM,qCAAqB,IAAI,IAAuC;CACtE,MAAM,qCAAqB,IAAI,IAA2B;CAC1D,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,mBAAmB,IAAI,MAAM,gBAAgB,QAC3C,QAAQ,KAAK,sBAAsB,CACrC;IACF;IACA,IAAI,MAAM,oBAAoB,KAAA,GAC5B,mBAAmB,IAAI,MAAM,eAAe,MAAM,eAAe;IAEnE;GACF;GACA,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,KAAK,KAAK;EAEd;CACF;CACA,KAAK,SAAS;CACd,OAAO;EAAE;EAAoB;CAAmB;AAClD;AAEA,IAAa,6BAAb,cAAgD,0BAAgD;CAC9F,cAAc;EACZ,MAAM,EAAE,oBAAoB,uBAAuB,mCACjD,4BACF;EACA,MAAM,oBAAoB,kBAAkB;CAC9C;CAEA,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAMT,MAAM,EAAE,I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"}
@@ -1,6 +1,6 @@
1
- import { d as CreateSchemaCall, f as CreateTableCall } from "./op-factory-call-Clp7Zr1z.mjs";
1
+ import { d as CreateSchemaCall, f as CreateTableCall } from "./op-factory-call-QFiNG9lu.mjs";
2
2
  import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
3
- import { t as dataTransform } from "./data-transform-D25tLeYU.mjs";
3
+ import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
4
4
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
5
5
  import { Migration } from "@prisma-next/family-sql/migration";
6
6
  //#region src/core/migrations/postgres-migration.ts
@@ -68,4 +68,4 @@ var PostgresMigration = class extends Migration {
68
68
  //#endregion
69
69
  export { PostgresMigration as t };
70
70
 
71
- //# sourceMappingURL=postgres-migration-BCQEjFHK.mjs.map
71
+ //# sourceMappingURL=postgres-migration-FeZUzZOH.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-migration-BCQEjFHK.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { CreateSchemaCall, CreateTableCall } from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): 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 }): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateTableCall(\n options.schema ?? UNBOUND_NAMESPACE_ID,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,cACE,UACA,MACA,SACsD;EACtD,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;;;;;;CAOA,YAAsB,SAMmC;EACvD,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,gBACT,QAAQ,UAAU,sBAClB,QAAQ,OACR,QAAQ,SACR,QAAQ,WACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;;;;;;CAOA,aAAuB,SAGkC;EACvD,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,iBAAiB,QAAQ,MAAM,CAAC,CAAC,KAAK,KAAK,cAAc;CACtE;AACF"}
1
+ {"version":3,"file":"postgres-migration-FeZUzZOH.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport { CreateSchemaCall, CreateTableCall } from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createTable(options: {\n readonly schema?: string;\n readonly table: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateTableCall(\n options.schema ?? UNBOUND_NAMESPACE_ID,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,cACE,UACA,MACA,SAC+D;EAC/D,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;;;;;;CAOA,YAAsB,SAM4C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,gBACT,QAAQ,UAAU,sBAClB,QAAQ,OACR,QAAQ,SACR,QAAQ,WACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;;;;;;CAOA,aAAuB,SAG2C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,iBAAiB,QAAQ,MAAM,CAAC,CAAC,KAAK,KAAK,cAAc;CACtE;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
2
- import { n as DataTransformOptions } from "./data-transform-DGOqcLrf.mjs";
2
+ import { n as DataTransformOptions } from "./data-transform-DDgWdB5o.mjs";
3
3
  import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
4
4
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
5
5
  import { SqlStorage } from "@prisma-next/sql-contract/types";
@@ -44,7 +44,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
44
44
  * supplies the stored control adapter. Authors call this from inside
45
45
  * `get operations()`; the adapter argument is hidden from the call site.
46
46
  */
47
- protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
47
+ protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
48
48
  /**
49
49
  * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
50
50
  * the supplied options and lowers it through the stored control adapter.
@@ -56,7 +56,7 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
56
56
  readonly ifNotExists?: boolean;
57
57
  readonly columns: readonly DdlColumn[];
58
58
  readonly constraints?: readonly DdlTableConstraint[];
59
- }): SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
59
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
60
60
  /**
61
61
  * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
62
62
  * the supplied options and lowers it through the stored control adapter.
@@ -65,8 +65,8 @@ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDet
65
65
  protected createSchema(options: {
66
66
  readonly schema: string;
67
67
  readonly ifNotExists?: boolean;
68
- }): SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
68
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
69
69
  }
70
70
  //#endregion
71
71
  export { PostgresMigration as t };
72
- //# sourceMappingURL=postgres-migration-DZ_gLUOW.d.mts.map
72
+ //# sourceMappingURL=postgres-migration-h_DA3LRq.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-h_DA3LRq.d.mts","names":[],"sources":["../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;;AAiCA;;;;;;;;;;;;;;;;;;uBAAsB,iBAAA,SAA0B,SAAA,CAC9C,yBAAA;EAAA,SAGS,QAAA;EAmEL;;;;;;EAAA,mBA3De,cAAA,EAAgB,iBAAA;cAEvB,KAAA,GAAQ,YAAA;EAFe;;;;;EAAA,UAiBzB,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,GACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAJK;;;;;EAAA,UAgBhC,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;EAJ3B;;;;;EAAA,UAqBD,YAAA,CAAa,OAAA;IAAA,SACZ,MAAA;IAAA,SACA,WAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
@@ -38,7 +38,7 @@ var PostgresSchema = class extends NamespaceBase {
38
38
  table,
39
39
  type,
40
40
  valueSet: Object.freeze(Object.fromEntries(Object.entries(valueSetInput).map(([k, v]) => [k, new StorageValueSet({
41
- kind: "value-set",
41
+ kind: "valueSet",
42
42
  values: v.values
43
43
  })])))
44
44
  }) : Object.freeze({
@@ -184,4 +184,4 @@ function postgresCreateNamespace(input, enumTypes) {
184
184
  //#endregion
185
185
  export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
186
186
 
187
- //# sourceMappingURL=postgres-schema-BVTA2QH7.mjs.map
187
+ //# sourceMappingURL=postgres-schema-BAgkIU9u.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-schema-BAgkIU9u.mjs","names":[],"sources":["../src/core/postgres-schema.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport {\n type PostgresEnumStorageEntry,\n type SqlNamespaceTablesInput,\n type SqlStorage,\n StorageTable,\n type StorageTableInput,\n StorageValueSet,\n type StorageValueSetInput,\n} from '@prisma-next/sql-contract/types';\nimport { PostgresEnumType, type PostgresEnumTypeInput } from './postgres-enum-type';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly entries: {\n readonly table: Record<string, StorageTable | StorageTableInput>;\n readonly type: Record<string, PostgresEnumType | PostgresEnumTypeInput>;\n readonly valueSet?: Record<string, StorageValueSet | StorageValueSetInput>;\n };\n}\n\n/**\n * Postgres target `Namespace` concretion — a Postgres schema (`CREATE\n * SCHEMA …`). Each Postgres `SqlStorage` carries a\n * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by\n * the Postgres PSL interpreter from `namespace { … }` AST buckets.\n *\n * `entries` holds entity-kind slot maps (`table`, `type`). Qualifier\n * emission is the rendering seam: DDL / SQL emission asks the namespace\n * for its qualifier (`\"<schema>\"`) or for a qualified table name\n * (`\"<schema>\".\"<table>\"`) and consumes the result polymorphically.\n * The unbound singleton below overrides these methods to elide the\n * prefix entirely — call sites stay polymorphic and never branch on\n * `id === UNBOUND_NAMESPACE_ID`.\n */\nexport class PostgresSchema extends NamespaceBase {\n /**\n * Stable singleton reference for the late-bound slot. Materialised\n * lazily below the singleton subclass declaration so the static\n * initialiser sees the subclass before assigning. Consumers always\n * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`\n * — same identity).\n */\n static unbound: PostgresUnboundSchema;\n\n declare readonly kind: 'schema';\n readonly id: string;\n readonly entries: Readonly<{\n readonly table: Readonly<Record<string, StorageTable>>;\n readonly type: Readonly<Record<string, PostgresEnumType>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n }>;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n const table = Object.freeze(\n Object.fromEntries(\n Object.entries(input.entries.table).map(([k, v]) => [\n k,\n v instanceof StorageTable ? v : new StorageTable(v as StorageTableInput),\n ]),\n ),\n );\n const type = Object.freeze(\n Object.fromEntries(\n Object.entries(input.entries.type).map(([k, v]) => [\n k,\n v instanceof PostgresEnumType ? v : new PostgresEnumType(v as PostgresEnumTypeInput),\n ]),\n ),\n );\n const valueSetInput = input.entries.valueSet;\n this.entries =\n valueSetInput !== undefined && Object.keys(valueSetInput).length > 0\n ? Object.freeze({\n table,\n type,\n valueSet: Object.freeze(\n Object.fromEntries(\n Object.entries(valueSetInput).map(([k, v]) => [\n k,\n new StorageValueSet({ kind: 'valueSet', values: v.values }),\n ]),\n ),\n ),\n })\n : Object.freeze({ table, type });\n Object.defineProperty(this, 'kind', {\n value: 'schema',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n /**\n * The bare schema qualifier as it would appear in a rendered SQL\n * fragment (already quoted). The unbound-schema singleton overrides\n * this to return `''`.\n */\n qualifier(): string {\n return `\"${this.id}\"`;\n }\n\n /**\n * Qualify a table name with the schema prefix\n * (`\"<schema>\".\"<table>\"`). The unbound-schema singleton overrides\n * this to emit just `\"<table>\"` so the resolved DDL is unqualified\n * and `search_path` decides where the object lands at runtime.\n */\n qualifyTable(tableName: string): string {\n return `\"${this.id}\".\"${tableName}\"`;\n }\n\n /**\n * Render a SQL string-literal containing the qualified-name form\n * suitable for `to_regclass(...)` arguments (e.g. `'\"public\".\"user\"'`).\n * The unbound singleton overrides this to elide the schema prefix\n * (`'\"user\"'`) so `search_path` resolves the object at runtime.\n */\n regclassLiteral(name: string): string {\n return `'${escapeLiteral(this.qualifyTable(name))}'`;\n }\n\n /**\n * Render a SQL expression that evaluates to this namespace's schema\n * name at runtime, ready to drop into a `WHERE table_schema = …` /\n * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL\n * literal (`'public'`); the unbound singleton overrides this to emit\n * `current_schema()` so catalog queries match whichever schema the\n * connection's `search_path` resolved at runtime.\n */\n schemaSqlExpression(): string {\n return `'${escapeLiteral(this.id)}'`;\n }\n\n /**\n * The bare schema name a DDL planner should target when emitting\n * statements that need to identify this namespace in the live\n * database (e.g. `CREATE TABLE \"<ddlSchemaName>\".\"<table>\" …`,\n * catalog filters, planner conflict lookups). Named schemas resolve\n * to their own id. The `PostgresUnboundSchema` singleton inherits\n * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch\n * through `qualifyTableName` / `toRegclassLiteral` route through the\n * polymorphic `PostgresUnboundSchema` overrides and produce\n * unqualified (search-path-resolved) output automatically.\n */\n ddlSchemaName(_storage: SqlStorage): string {\n return this.id;\n }\n}\n\n/**\n * Singleton subclass for the reserved sentinel namespace id\n * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding\n * the connection's `search_path` resolves at runtime. Overrides\n * qualifier emission to elide the schema prefix; call sites that consume\n * `qualifier()` / `qualifyTable()` get unqualified output without\n * branching on the namespace id.\n *\n * This is the target-side materialization of \"the framework provides\n * affordances; targets implement specifics\": the framework names the\n * sentinel; Postgres decides what late-bound means here (the table\n * name, naked — the schema is supplied by the live connection's\n * `search_path`).\n *\n * `ddlSchemaName` is inherited from `PostgresSchema` and returns\n * `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,\n * `toRegclassLiteral`) route through the polymorphic factory and\n * produce unqualified output automatically.\n */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID, entries: { table: {}, type: {} } });\n }\n\n override qualifier(): string {\n return '';\n }\n\n override qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n\n override schemaSqlExpression(): string {\n return 'current_schema()';\n }\n}\n\nPostgresSchema.unbound = PostgresUnboundSchema.instance;\n\n/**\n * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`\n * so callers can dispatch to the polymorphic emission methods without\n * branching at the call site. Uses the structural `kind` discriminator\n * (`'schema'`) rather than `instanceof` so the check survives realm /\n * bundle / hot-reload boundaries — matching the rest of the IR's\n * narrowing convention. `PostgresUnboundSchema` passes through because\n * it inherits the same `kind: 'schema'` from `PostgresSchema`.\n */\nexport function isPostgresSchema(ns: unknown): ns is PostgresSchema {\n return (ns as { kind?: unknown } | null | undefined)?.kind === 'schema';\n}\n\n/**\n * Target-supplied `Namespace` factory the Postgres target plumbs\n * through `defineContract({ createNamespace })` and the SQL PSL\n * interpreter. Returns the unbound singleton for the framework\n * sentinel and a fresh `PostgresSchema` for any other coordinate.\n *\n * The factory has no per-call state — every named id deterministically\n * maps to a distinct schema instance — so callers can pass it through\n * by reference and trust the resulting `SqlStorage.namespaces` map to\n * be value-stable for a given input set.\n */\nexport function postgresCreateNamespace(\n input: SqlNamespaceTablesInput,\n enumTypes?: Readonly<Record<string, PostgresEnumStorageEntry>>,\n): PostgresSchema {\n const schemaInput: PostgresSchemaInput = {\n id: input.id,\n entries: {\n table: input.entries.table,\n type: (enumTypes ?? {}) as Record<string, PostgresEnumTypeInput>,\n ...(input.entries.valueSet !== undefined ? { valueSet: input.entries.valueSet } : {}),\n },\n };\n if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(schemaInput);\n }\n return new PostgresSchema(schemaInput);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,IAAa,iBAAb,cAAoC,cAAc;;;;;;;;CAQhD,OAAO;CAGP;CACA;CAMA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAChB,MAAM,QAAQ,OAAO,OACnB,OAAO,YACL,OAAO,QAAQ,MAAM,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAClD,GACA,aAAa,eAAe,IAAI,IAAI,aAAa,CAAsB,CACzE,CAAC,CACH,CACF;EACA,MAAM,OAAO,OAAO,OAClB,OAAO,YACL,OAAO,QAAQ,MAAM,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CACjD,GACA,aAAa,mBAAmB,IAAI,IAAI,iBAAiB,CAA0B,CACrF,CAAC,CACH,CACF;EACA,MAAM,gBAAgB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OAAQ,IAA8C,SAAS;AACjE;;;;;;;;;;;;AAaA,SAAgB,wBACd,OACA,WACgB;CAChB,MAAM,cAAmC;EACvC,IAAI,MAAM;EACV,SAAS;GACP,OAAO,MAAM,QAAQ;GACrB,MAAO,aAAa,CAAC;GACrB,GAAI,MAAM,QAAQ,aAAa,KAAA,IAAY,EAAE,UAAU,MAAM,QAAQ,SAAS,IAAI,CAAC;EACrF;CACF;CACA,IAAI,MAAM,OAAO,sBACf,OAAO,IAAI,sBAAsB,WAAW;CAE9C,OAAO,IAAI,eAAe,WAAW;AACvC"}
@@ -1,4 +1,5 @@
1
1
  import { blindCast } from "@prisma-next/utils/casts";
2
+ import { isThenable } from "@prisma-next/utils/promise";
2
3
  //#region src/core/migrations/render-ops.ts
3
4
  /**
4
5
  * Asserts an op materialised by an `OpFactoryCall` targets postgres. The
@@ -8,17 +9,21 @@ import { blindCast } from "@prisma-next/utils/casts";
8
9
  * place to fail loudly with op metadata (`id` + `target.id`).
9
10
  */
10
11
  function assertPostgresOp(op, callFactoryName) {
11
- const targetId = op.target?.id;
12
+ const targetId = blindCast(op).target?.id;
12
13
  if (targetId !== "postgres") throw new Error(`renderOps: expected postgres op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`);
13
14
  }
14
15
  function renderOps(calls, lowerer) {
15
16
  return calls.map((c) => {
16
- const op = blindCast(c).toOp(lowerer);
17
- assertPostgresOp(op, c.factoryName);
18
- return op;
17
+ const opOrPromise = blindCast(c).toOp(lowerer);
18
+ if (isThenable(opOrPromise)) return opOrPromise.then((op) => {
19
+ assertPostgresOp(op, c.factoryName);
20
+ return op;
21
+ });
22
+ assertPostgresOp(opOrPromise, c.factoryName);
23
+ return opOrPromise;
19
24
  });
20
25
  }
21
26
  //#endregion
22
27
  export { renderOps as t };
23
28
 
24
- //# sourceMappingURL=render-ops-BpjstrKQ.mjs.map
29
+ //# sourceMappingURL=render-ops-BREh1kHe.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-ops-BREh1kHe.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';\nimport type {\n MigrationPlanOperation,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { isThenable } from '@prisma-next/utils/promise';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;\n\n/**\n * Asserts an op materialised by an `OpFactoryCall` targets postgres. The\n * extension surface lets any contributor emit calls, so this is the\n * integration boundary where a stray non-postgres op would otherwise\n * silently flow through to postgres-shaped renderers — exactly the\n * place to fail loudly with op metadata (`id` + `target.id`).\n */\nfunction assertPostgresOp(op: MigrationPlanOperation, callFactoryName: string): asserts op is Op {\n const targetId = blindCast<\n { target?: { id?: string } },\n 'op.target is present on concrete SqlMigrationPlanOperation but absent on the framework MigrationPlanOperation base'\n >(op).target?.id;\n if (targetId !== 'postgres') {\n throw new Error(\n `renderOps: expected postgres op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the postgres planner path; check the call's target binding.`,\n );\n }\n}\n\nexport function renderOps(\n calls: readonly OpFactoryCall[],\n lowerer?: ExecuteRequestLowerer,\n): (Op | Promise<Op>)[] {\n return calls.map((c) => {\n const opOrPromise = blindCast<\n { toOp(lowerer?: ExecuteRequestLowerer): Op | Promise<Op> },\n 'PG OpFactoryCall.toOp accepts an optional ExecuteRequestLowerer; the framework interface omits it because not all targets need a lowerer — the PG target overrides with this extended signature'\n >(c).toOp(lowerer);\n if (isThenable(opOrPromise)) {\n return opOrPromise.then((op) => {\n assertPostgresOp(op, c.factoryName);\n return op;\n });\n }\n assertPostgresOp(opOrPromise, c.factoryName);\n return opOrPromise;\n });\n}\n"],"mappings":";;;;;;;;;;AAmBA,SAAS,iBAAiB,IAA4B,iBAA2C;CAC/F,MAAM,WAAW,UAGf,EAAE,CAAC,CAAC,QAAQ;CACd,IAAI,aAAa,YACf,MAAM,IAAI,MACR,sDAAsD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAChI;AAEJ;AAEA,SAAgB,UACd,OACA,SACsB;CACtB,OAAO,MAAM,KAAK,MAAM;EACtB,MAAM,cAAc,UAGlB,CAAC,CAAC,CAAC,KAAK,OAAO;EACjB,IAAI,WAAW,WAAW,GACxB,OAAO,YAAY,MAAM,OAAO;GAC9B,iBAAiB,IAAI,EAAE,WAAW;GAClC,OAAO;EACT,CAAC;EAEH,iBAAiB,aAAa,EAAE,WAAW;EAC3C,OAAO;CACT,CAAC;AACH"}
@@ -1,11 +1,11 @@
1
1
  import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
2
2
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
3
3
  import { OpFactoryCall } from "@prisma-next/framework-components/control";
4
- import { Lowerer } from "@prisma-next/family-sql/control-adapter";
4
+ import { ExecuteRequestLowerer } from "@prisma-next/family-sql/control-adapter";
5
5
 
6
6
  //#region src/core/migrations/render-ops.d.ts
7
7
  type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
8
- declare function renderOps(calls: readonly OpFactoryCall[], lowerer?: Lowerer): Op[];
8
+ declare function renderOps(calls: readonly OpFactoryCall[], lowerer?: ExecuteRequestLowerer): (Op | Promise<Op>)[];
9
9
  //#endregion
10
10
  export { renderOps };
11
11
  //# sourceMappingURL=render-ops.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;KAMK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,iBAqBpB,SAAA,CAAU,KAAA,WAAgB,aAAA,IAAiB,OAAA,GAAU,OAAA,GAAU,EAAA"}
1
+ {"version":3,"file":"render-ops.d.mts","names":[],"sources":["../src/core/migrations/render-ops.ts"],"mappings":";;;;;;KAUK,EAAA,GAAK,yBAAyB,CAAC,yBAAA;AAAA,iBAqBpB,SAAA,CACd,KAAA,WAAgB,aAAA,IAChB,OAAA,GAAU,qBAAA,IACR,EAAA,GAAK,OAAA,CAAQ,EAAA"}
@@ -1,2 +1,2 @@
1
- import { t as renderOps } from "./render-ops-BpjstrKQ.mjs";
1
+ import { t as renderOps } from "./render-ops-BREh1kHe.mjs";
2
2
  export { renderOps };
package/dist/runtime.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-My8_s4cs.mjs";
2
- import { t as PostgresContractSerializer } from "./postgres-contract-serializer-DCg7YaP3.mjs";
2
+ import { t as PostgresContractSerializer } from "./postgres-contract-serializer-DFpLrLiH.mjs";
3
3
  //#region src/exports/runtime.ts
4
4
  /**
5
5
  * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
package/dist/types.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
2
- import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-BVTA2QH7.mjs";
2
+ import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-BAgkIU9u.mjs";
3
3
  export { PostgresEnumType, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.13.0-dev.15",
3
+ "version": "0.13.0-dev.17",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Postgres target pack for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/cli": "0.13.0-dev.15",
10
- "@prisma-next/contract": "0.13.0-dev.15",
11
- "@prisma-next/errors": "0.13.0-dev.15",
12
- "@prisma-next/family-sql": "0.13.0-dev.15",
13
- "@prisma-next/framework-components": "0.13.0-dev.15",
14
- "@prisma-next/migration-tools": "0.13.0-dev.15",
15
- "@prisma-next/ts-render": "0.13.0-dev.15",
16
- "@prisma-next/sql-contract": "0.13.0-dev.15",
17
- "@prisma-next/sql-errors": "0.13.0-dev.15",
18
- "@prisma-next/sql-operations": "0.13.0-dev.15",
19
- "@prisma-next/sql-relational-core": "0.13.0-dev.15",
20
- "@prisma-next/sql-schema-ir": "0.13.0-dev.15",
21
- "@prisma-next/utils": "0.13.0-dev.15",
9
+ "@prisma-next/cli": "0.13.0-dev.17",
10
+ "@prisma-next/contract": "0.13.0-dev.17",
11
+ "@prisma-next/errors": "0.13.0-dev.17",
12
+ "@prisma-next/family-sql": "0.13.0-dev.17",
13
+ "@prisma-next/framework-components": "0.13.0-dev.17",
14
+ "@prisma-next/migration-tools": "0.13.0-dev.17",
15
+ "@prisma-next/ts-render": "0.13.0-dev.17",
16
+ "@prisma-next/sql-contract": "0.13.0-dev.17",
17
+ "@prisma-next/sql-errors": "0.13.0-dev.17",
18
+ "@prisma-next/sql-operations": "0.13.0-dev.17",
19
+ "@prisma-next/sql-relational-core": "0.13.0-dev.17",
20
+ "@prisma-next/sql-schema-ir": "0.13.0-dev.17",
21
+ "@prisma-next/utils": "0.13.0-dev.17",
22
22
  "@standard-schema/spec": "^1.1.0",
23
23
  "arktype": "^2.2.0",
24
24
  "pathe": "^2.0.3"
25
25
  },
26
26
  "devDependencies": {
27
- "@prisma-next/test-utils": "0.13.0-dev.15",
28
- "@prisma-next/tsconfig": "0.13.0-dev.15",
29
- "@prisma-next/tsdown": "0.13.0-dev.15",
27
+ "@prisma-next/test-utils": "0.13.0-dev.17",
28
+ "@prisma-next/tsconfig": "0.13.0-dev.17",
29
+ "@prisma-next/tsdown": "0.13.0-dev.17",
30
30
  "tsdown": "0.22.1",
31
31
  "typescript": "5.9.3",
32
32
  "vitest": "4.1.8"
@@ -8,7 +8,7 @@
8
8
  * through `mapIssueToCall` for the default case.
9
9
  */
10
10
 
11
- import type { Contract } from '@prisma-next/contract/types';
11
+ import type { Contract, JsonValue } from '@prisma-next/contract/types';
12
12
  import type {
13
13
  CodecControlHooks,
14
14
  MigrationOperationPolicy,
@@ -25,9 +25,11 @@ import type {
25
25
  StorageTable,
26
26
  StorageTypeInstance,
27
27
  } from '@prisma-next/sql-contract/types';
28
- import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
28
+ import type { CodecRef, DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';
29
29
  import * as contractFree from '@prisma-next/sql-relational-core/contract-free';
30
30
  import type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
31
+ import { blindCast } from '@prisma-next/utils/casts';
32
+ import { ifDefined } from '@prisma-next/utils/defined';
31
33
  import type { Result } from '@prisma-next/utils/result';
32
34
  import { notOk, ok } from '@prisma-next/utils/result';
33
35
  import { PostgresEnumType } from '../postgres-enum-type';
@@ -65,6 +67,7 @@ import {
65
67
  type StrategyContext,
66
68
  tableAt,
67
69
  } from './planner-strategies';
70
+ import { resolveColumnTypeMetadata } from './planner-type-resolution';
68
71
 
69
72
  export type { CallMigrationStrategy, StrategyContext };
70
73
 
@@ -214,9 +217,27 @@ function toDdlColumn(
214
217
  ): DdlColumn {
215
218
  const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);
216
219
  const ddlDefault = postgresDefaultToDdlColumnDefault(column.default);
220
+ const resolved = resolveColumnTypeMetadata(
221
+ column,
222
+ storageTypes as Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,
223
+ );
224
+ const codecRef: CodecRef | undefined = resolved.codecId
225
+ ? {
226
+ codecId: resolved.codecId,
227
+ ...(resolved.typeParams !== undefined
228
+ ? {
229
+ typeParams: blindCast<
230
+ JsonValue,
231
+ 'resolved.typeParams is JsonValue-shaped storage metadata; the narrowed (non-undefined) value lands in CodecRef.typeParams which is JsonValue'
232
+ >(resolved.typeParams),
233
+ }
234
+ : {}),
235
+ }
236
+ : undefined;
217
237
  return contractFree.col(name, typeSql, {
218
238
  ...(!column.nullable ? { notNull: true } : {}),
219
- ...(ddlDefault ? { default: ddlDefault } : {}),
239
+ ...ifDefined('default', ddlDefault),
240
+ ...ifDefined('codecRef', codecRef),
220
241
  });
221
242
  }
222
243
 
@@ -22,7 +22,7 @@
22
22
 
23
23
  import { errorUnfilledPlaceholder } from '@prisma-next/errors/migration';
24
24
  import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
25
- import type { Lowerer } from '@prisma-next/family-sql/control-adapter';
25
+ import type { ExecuteRequestLowerer, Lowerer } from '@prisma-next/family-sql/control-adapter';
26
26
  import type {
27
27
  OpFactoryCall as FrameworkOpFactoryCall,
28
28
  MigrationOperationClass,
@@ -36,6 +36,7 @@ import type {
36
36
  import { FunctionColumnDefault, LiteralColumnDefault } from '@prisma-next/sql-relational-core/ast';
37
37
  import { type ImportRequirement, jsonToTsSource, TsExpression } from '@prisma-next/ts-render';
38
38
  import { blindCast } from '@prisma-next/utils/casts';
39
+ import { ifDefined } from '@prisma-next/utils/defined';
39
40
  import * as contractFreeDdl from '../../contract-free/ddl';
40
41
  import { escapeLiteral, quoteIdentifier } from '../sql-utils';
41
42
  import type { PostgresColumnDefault } from '../types';
@@ -85,7 +86,7 @@ abstract class PostgresOpFactoryCallNode extends TsExpression implements Framewo
85
86
  abstract readonly factoryName: string;
86
87
  abstract readonly operationClass: MigrationOperationClass;
87
88
  abstract readonly label: string;
88
- abstract toOp(lowerer?: Lowerer): Op;
89
+ abstract toOp(lowerer?: Lowerer): Op | Promise<Op>;
89
90
 
90
91
  importRequirements(): readonly ImportRequirement[] {
91
92
  return [{ moduleSpecifier: POSTGRES_MIGRATION_FACADE, symbol: this.factoryName }];
@@ -213,7 +214,7 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
213
214
  this.freeze();
214
215
  }
215
216
 
216
- toOp(lowerer?: Lowerer): Op {
217
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
217
218
  if (lowerer === undefined) {
218
219
  throw new Error(
219
220
  `CreateTableCall.toOp: a DDL lowerer is required on the Postgres planner path (table "${this.tableName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
@@ -223,9 +224,9 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
223
224
  ...(this.schemaName !== UNBOUND_NAMESPACE_ID ? { schema: this.schemaName } : {}),
224
225
  table: this.tableName,
225
226
  columns: this.columns,
226
- ...(this.constraints ? { constraints: this.constraints } : {}),
227
+ ...ifDefined('constraints', this.constraints),
227
228
  });
228
- const { sql } = lowerer.lower(ddlNode, { contract: {} });
229
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
229
230
  const schemaName = this.schemaName;
230
231
  const tableName = this.tableName;
231
232
  return {
@@ -240,7 +241,13 @@ export class CreateTableCall extends PostgresOpFactoryCallNode {
240
241
  `SELECT to_regclass(${toRegclassLiteral(schemaName, tableName)}) IS NULL`,
241
242
  ),
242
243
  ],
243
- execute: [step(`create table "${tableName}"`, sql)],
244
+ execute: [
245
+ {
246
+ description: `create table "${tableName}"`,
247
+ sql: statement.sql,
248
+ params: statement.params ?? [],
249
+ },
250
+ ],
244
251
  postcheck: [
245
252
  step(
246
253
  `verify table "${tableName}" exists`,
@@ -1016,14 +1023,14 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
1016
1023
  this.freeze();
1017
1024
  }
1018
1025
 
1019
- toOp(lowerer?: Lowerer): Op {
1026
+ async toOp(lowerer?: ExecuteRequestLowerer): Promise<Op> {
1020
1027
  if (lowerer === undefined) {
1021
1028
  throw new Error(
1022
1029
  `CreateSchemaCall.toOp: a DDL lowerer is required on the Postgres planner path (schema "${this.schemaName}"). Pass the control adapter to createPostgresMigrationPlanner.`,
1023
1030
  );
1024
1031
  }
1025
1032
  const ddlNode = contractFreeDdl.createSchema({ schema: this.schemaName, ifNotExists: true });
1026
- const { sql } = lowerer.lower(ddlNode, { contract: {} });
1033
+ const statement = await lowerer.lowerToExecuteRequest(ddlNode);
1027
1034
  const schemaName = this.schemaName;
1028
1035
  return {
1029
1036
  id: `schema.${schemaName}`,
@@ -1031,7 +1038,13 @@ export class CreateSchemaCall extends PostgresOpFactoryCallNode {
1031
1038
  operationClass: 'additive',
1032
1039
  target: { id: 'postgres' },
1033
1040
  precheck: [],
1034
- execute: [step(`Create schema "${schemaName}"`, sql)],
1041
+ execute: [
1042
+ {
1043
+ description: `Create schema "${schemaName}"`,
1044
+ sql: statement.sql,
1045
+ params: statement.params ?? [],
1046
+ },
1047
+ ],
1035
1048
  postcheck: [],
1036
1049
  };
1037
1050
  }
@@ -61,8 +61,8 @@ import type {
61
61
  SqlMigrationPlanOperationStep,
62
62
  } from '@prisma-next/family-sql/control';
63
63
  import type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';
64
- import type { SerializedQueryPlan } from '@prisma-next/framework-components/control';
65
64
  import type { SqlStorage } from '@prisma-next/sql-contract/types';
65
+ import type { SqlExecuteRequest } from '@prisma-next/sql-relational-core/ast';
66
66
  import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
67
67
  import { ifDefined } from '@prisma-next/utils/defined';
68
68
  import type { PostgresPlanTargetDetails } from '../planner-target-details';
@@ -96,25 +96,29 @@ export interface DataTransformOptions {
96
96
  readonly run: DataTransformClosure | readonly DataTransformClosure[];
97
97
  }
98
98
 
99
- export function dataTransform<TContract extends Contract<SqlStorage>>(
99
+ export async function dataTransform<TContract extends Contract<SqlStorage>>(
100
100
  contract: TContract,
101
101
  name: string,
102
102
  options: DataTransformOptions,
103
103
  adapter: SqlControlAdapter<'postgres'>,
104
- ): SqlMigrationPlanOperation<PostgresPlanTargetDetails> {
104
+ ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {
105
105
  const runClosures: readonly DataTransformClosure[] = Array.isArray(options.run)
106
106
  ? options.run
107
107
  : [options.run as DataTransformClosure];
108
108
 
109
- const checkPlan = options.check ? invokeAndLower(options.check, contract, adapter, name) : null;
110
- const runPlans = runClosures.map((closure) => invokeAndLower(closure, contract, adapter, name));
109
+ const checkPlan = options.check
110
+ ? await invokeAndLower(options.check, contract, adapter, name)
111
+ : null;
112
+ const runPlans = await Promise.all(
113
+ runClosures.map((closure) => invokeAndLower(closure, contract, adapter, name)),
114
+ );
111
115
 
112
116
  const precheck: readonly SqlMigrationPlanOperationStep[] = checkPlan
113
117
  ? [
114
118
  {
115
119
  description: `Check ${name} has work to do`,
116
120
  sql: `SELECT EXISTS (${checkPlan.sql}) AS ok`,
117
- params: checkPlan.params,
121
+ params: checkPlan.params ?? [],
118
122
  },
119
123
  ]
120
124
  : [];
@@ -122,7 +126,7 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
122
126
  const execute: readonly SqlMigrationPlanOperationStep[] = runPlans.map((plan) => ({
123
127
  description: `Run ${name}`,
124
128
  sql: plan.sql,
125
- params: plan.params,
129
+ params: plan.params ?? [],
126
130
  }));
127
131
 
128
132
  const postcheck: readonly SqlMigrationPlanOperationStep[] = checkPlan
@@ -130,7 +134,7 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
130
134
  {
131
135
  description: `Verify ${name} resolved all violations`,
132
136
  sql: `SELECT NOT EXISTS (${checkPlan.sql}) AS ok`,
133
- params: checkPlan.params,
137
+ params: checkPlan.params ?? [],
134
138
  },
135
139
  ]
136
140
  : [];
@@ -147,23 +151,16 @@ export function dataTransform<TContract extends Contract<SqlStorage>>(
147
151
  };
148
152
  }
149
153
 
150
- function invokeAndLower(
154
+ async function invokeAndLower(
151
155
  closure: DataTransformClosure,
152
156
  contract: Contract<SqlStorage>,
153
157
  adapter: SqlControlAdapter<'postgres'>,
154
158
  name: string,
155
- ): SerializedQueryPlan {
159
+ ): Promise<SqlExecuteRequest> {
156
160
  const result = closure();
157
161
  const plan = isBuildable(result) ? result.build() : result;
158
162
  assertContractMatches(plan, contract, name);
159
- const lowered = adapter.lower(plan.ast, { contract });
160
- const params = lowered.params.map((slot) => {
161
- if (slot.kind === 'literal') return slot.value;
162
- throw new Error(
163
- `data-transform: bind-site slot '${slot.name}' is not allowed in migration plans`,
164
- );
165
- });
166
- return { sql: lowered.sql, params };
163
+ return adapter.lowerToExecuteRequest(plan.ast, { contract });
167
164
  }
168
165
 
169
166
  function isBuildable(value: unknown): value is Buildable {
@@ -24,7 +24,7 @@
24
24
  */
25
25
 
26
26
  import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';
27
- import type { Lowerer } from '@prisma-next/family-sql/control-adapter';
27
+ import type { ExecuteRequestLowerer } from '@prisma-next/family-sql/control-adapter';
28
28
  import type {
29
29
  MigrationPlanWithAuthoringSurface,
30
30
  OpFactoryCall,
@@ -35,8 +35,6 @@ import { PostgresMigration } from './postgres-migration';
35
35
  import { renderOps } from './render-ops';
36
36
  import { renderCallsToTypeScript } from './render-typescript';
37
37
 
38
- type Op = SqlMigrationPlanOperation<PostgresPlanTargetDetails>;
39
-
40
38
  export class TypeScriptRenderablePostgresMigration
41
39
  extends PostgresMigration
42
40
  implements MigrationPlanWithAuthoringSurface
@@ -44,13 +42,19 @@ export class TypeScriptRenderablePostgresMigration
44
42
  readonly #calls: readonly OpFactoryCall[];
45
43
  readonly #meta: MigrationMeta;
46
44
  readonly #spaceId: string;
47
- readonly #lowerer: Lowerer | undefined;
45
+ readonly #lowerer: ExecuteRequestLowerer | undefined;
46
+ #operationsCache:
47
+ | readonly (
48
+ | SqlMigrationPlanOperation<PostgresPlanTargetDetails>
49
+ | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
50
+ )[]
51
+ | undefined;
48
52
 
49
53
  constructor(
50
54
  calls: readonly OpFactoryCall[],
51
55
  meta: MigrationMeta,
52
56
  spaceId: string,
53
- lowerer?: Lowerer,
57
+ lowerer?: ExecuteRequestLowerer,
54
58
  ) {
55
59
  super();
56
60
  this.#calls = calls;
@@ -59,8 +63,12 @@ export class TypeScriptRenderablePostgresMigration
59
63
  this.#lowerer = lowerer;
60
64
  }
61
65
 
62
- override get operations(): readonly Op[] {
63
- return renderOps(this.#calls, this.#lowerer);
66
+ override get operations(): readonly (
67
+ | SqlMigrationPlanOperation<PostgresPlanTargetDetails>
68
+ | Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>
69
+ )[] {
70
+ this.#operationsCache ??= renderOps(this.#calls, this.#lowerer);
71
+ return this.#operationsCache;
64
72
  }
65
73
 
66
74
  override describe(): MigrationMeta {