@prisma-next/target-postgres 0.14.0-dev.15 → 0.14.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 (66) hide show
  1. package/dist/codecs.mjs.map +1 -1
  2. package/dist/contract-free.d.mts +8 -3
  3. package/dist/contract-free.d.mts.map +1 -1
  4. package/dist/contract-free.mjs +2 -2
  5. package/dist/control.mjs +2 -2
  6. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  7. package/dist/{ddl-BlsTIBeP.mjs → ddl-D1K9soOg.mjs} +11 -4
  8. package/dist/{ddl-BlsTIBeP.mjs.map → ddl-D1K9soOg.mjs.map} +1 -1
  9. package/dist/ddl.d.mts +2 -2
  10. package/dist/ddl.mjs +2 -2
  11. package/dist/{issue-planner-CwoeupPM.mjs → issue-planner-DSQ07ihi.mjs} +5 -6
  12. package/dist/issue-planner-DSQ07ihi.mjs.map +1 -0
  13. package/dist/issue-planner.d.mts +1 -1
  14. package/dist/issue-planner.mjs +1 -1
  15. package/dist/migration.d.mts +2 -2
  16. package/dist/migration.mjs +2 -2
  17. package/dist/{nodes-YvdohJ2X.d.mts → nodes-CSkPX3rI.d.mts} +19 -3
  18. package/dist/nodes-CSkPX3rI.d.mts.map +1 -0
  19. package/dist/{nodes-DhDIIhBT.mjs → nodes-Dh__NS58.mjs} +14 -2
  20. package/dist/nodes-Dh__NS58.mjs.map +1 -0
  21. package/dist/{op-factory-call-tMksrGIq.mjs → op-factory-call-BZFhzxUH.mjs} +55 -26
  22. package/dist/op-factory-call-BZFhzxUH.mjs.map +1 -0
  23. package/dist/{op-factory-call-DXHAIisl.d.mts → op-factory-call-CQ4P40QC.d.mts} +8 -10
  24. package/dist/op-factory-call-CQ4P40QC.d.mts.map +1 -0
  25. package/dist/op-factory-call.d.mts +1 -1
  26. package/dist/op-factory-call.mjs +1 -1
  27. package/dist/{planner-BbSZJVW7.mjs → planner-Cu8YdghT.mjs} +4 -4
  28. package/dist/{planner-BbSZJVW7.mjs.map → planner-Cu8YdghT.mjs.map} +1 -1
  29. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-C1IsRjVl.mjs} +2 -25
  30. package/dist/planner-ddl-builders-C1IsRjVl.mjs.map +1 -0
  31. package/dist/planner-ddl-builders.d.mts +2 -4
  32. package/dist/planner-ddl-builders.d.mts.map +1 -1
  33. package/dist/planner-ddl-builders.mjs +2 -2
  34. package/dist/{planner-produced-postgres-migration-DfM5lBv1.d.mts → planner-produced-postgres-migration-CNTSCMl7.d.mts} +2 -2
  35. package/dist/{planner-produced-postgres-migration-DfM5lBv1.d.mts.map → planner-produced-postgres-migration-CNTSCMl7.d.mts.map} +1 -1
  36. package/dist/{planner-produced-postgres-migration-C0FHnEsV.mjs → planner-produced-postgres-migration-SkStEa6Q.mjs} +2 -2
  37. package/dist/{planner-produced-postgres-migration-C0FHnEsV.mjs.map → planner-produced-postgres-migration-SkStEa6Q.mjs.map} +1 -1
  38. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  39. package/dist/planner-produced-postgres-migration.mjs +1 -1
  40. package/dist/planner.d.mts +1 -1
  41. package/dist/planner.mjs +1 -1
  42. package/dist/{postgres-migration-BJWxullf.mjs → postgres-migration-BcDtTMs5.mjs} +2 -2
  43. package/dist/{postgres-migration-BJWxullf.mjs.map → postgres-migration-BcDtTMs5.mjs.map} +1 -1
  44. package/dist/{postgres-migration-D22a2y0l.d.mts → postgres-migration-DJNJHcdP.d.mts} +2 -2
  45. package/dist/{postgres-migration-D22a2y0l.d.mts.map → postgres-migration-DJNJHcdP.d.mts.map} +1 -1
  46. package/package.json +19 -19
  47. package/src/contract-free/ddl.ts +10 -1
  48. package/src/core/codecs.ts +1 -1
  49. package/src/core/ddl/nodes.ts +26 -1
  50. package/src/core/migrations/bound-schema.ts +10 -0
  51. package/src/core/migrations/op-factory-call.ts +10 -21
  52. package/src/core/migrations/operations/columns.ts +24 -12
  53. package/src/core/migrations/operations/data-transform.ts +6 -0
  54. package/src/core/migrations/operations/shared.ts +0 -30
  55. package/src/core/migrations/planner-ddl-builders.ts +1 -55
  56. package/src/core/migrations/planner-recipes.ts +31 -13
  57. package/src/core/migrations/planner-strategies.ts +3 -11
  58. package/src/exports/contract-free.ts +7 -1
  59. package/src/exports/ddl.ts +1 -0
  60. package/src/exports/planner-ddl-builders.ts +0 -2
  61. package/dist/issue-planner-CwoeupPM.mjs.map +0 -1
  62. package/dist/nodes-DhDIIhBT.mjs.map +0 -1
  63. package/dist/nodes-YvdohJ2X.d.mts.map +0 -1
  64. package/dist/op-factory-call-DXHAIisl.d.mts.map +0 -1
  65. package/dist/op-factory-call-tMksrGIq.mjs.map +0 -1
  66. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"planner-ddl-builders-B2wOwLqI.mjs","names":[],"sources":["../src/core/migrations/planner-ddl-builders.ts"],"sourcesContent":["import type { CodecControlHooks } from '@prisma-next/family-sql/control';\nimport type {\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\nimport type { PostgresColumnDefault } from '../types';\nimport { resolveColumnTypeMetadata } from './planner-type-resolution';\n\nexport function buildCreateTableSql(\n qualifiedTableName: string,\n table: StorageTable,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const columnDefinitions = Object.entries(table.columns).map(\n ([columnName, column]: [string, StorageColumn]) => {\n const parts = [\n quoteIdentifier(columnName),\n buildColumnTypeSql(column, codecHooks, storageTypes),\n buildColumnDefaultSql(column.default, column),\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n },\n );\n\n const constraintDefinitions: string[] = [];\n if (table.primaryKey) {\n constraintDefinitions.push(\n `PRIMARY KEY (${table.primaryKey.columns.map(quoteIdentifier).join(', ')})`,\n );\n }\n\n const allDefinitions = [...columnDefinitions, ...constraintDefinitions];\n return `CREATE TABLE ${qualifiedTableName} (\\n ${allDefinitions.join(',\\n ')}\\n)`;\n}\n\n/**\n * Pattern for safe PostgreSQL type names.\n * Allows letters, digits, underscores, spaces (for \"double precision\", \"character varying\"),\n * and trailing [] for array types.\n */\nconst SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*(\\[\\])?$/;\n\nfunction assertSafeNativeType(nativeType: string): void {\n if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {\n throw new Error(\n `Unsafe native type name in contract: \"${nativeType}\". ` +\n 'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*(\\\\[\\\\])?$/',\n );\n }\n}\n\n/**\n * Sanity check against accidental SQL injection from malformed contract files.\n * Rejects semicolons, SQL comment tokens, and dollar-quoting.\n * Not a comprehensive security boundary — the contract is developer-authored.\n */\nfunction assertSafeDefaultExpression(expression: string): void {\n if (expression.includes(';') || /--|\\/\\*|\\$\\$|\\bSELECT\\b/i.test(expression)) {\n throw new Error(\n `Unsafe default expression in contract: \"${expression}\". ` +\n 'Default expressions must not contain semicolons, SQL comment tokens, dollar-quoting, or subqueries.',\n );\n }\n}\n\n/**\n * Renders the SQL type for a column in DDL context.\n *\n * @param allowPseudoTypes - When true (default), autoincrement integer columns\n * produce SERIAL/BIGSERIAL/SMALLSERIAL pseudo-types. Set to false for contexts\n * like ALTER COLUMN TYPE where pseudo-types are invalid.\n */\nexport function buildColumnTypeSql(\n column: StorageColumn,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n storageTypes: Record<string, StorageTypeInstance> = {},\n allowPseudoTypes = true,\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n\n if (allowPseudoTypes) {\n const columnDefault = column.default;\n if (columnDefault?.kind === 'function' && columnDefault.expression === 'autoincrement()') {\n if (resolved.nativeType === 'int4' || resolved.nativeType === 'integer') {\n return 'SERIAL';\n }\n if (resolved.nativeType === 'int8' || resolved.nativeType === 'bigint') {\n return 'BIGSERIAL';\n }\n if (resolved.nativeType === 'int2' || resolved.nativeType === 'smallint') {\n return 'SMALLSERIAL';\n }\n }\n }\n\n const expanded = expandParameterizedTypeSql(resolved, codecHooks);\n if (expanded !== null) {\n return expanded;\n }\n\n if (column.typeRef) {\n return quoteIdentifier(resolved.nativeType);\n }\n\n assertSafeNativeType(resolved.nativeType);\n return resolved.nativeType;\n}\n\nfunction expandParameterizedTypeSql(\n column: Pick<StorageColumn, 'nativeType' | 'codecId' | 'typeParams'>,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n): string | null {\n if (!column.typeParams || Object.keys(column.typeParams).length === 0) {\n return null;\n }\n\n if (!column.codecId) {\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" but has no codecId. ` +\n 'Ensure the column is associated with a codec.',\n );\n }\n\n const hooks = codecHooks.get(column.codecId);\n if (!hooks?.expandNativeType) {\n if (hooks?.planTypeOperations) {\n return null;\n }\n throw new Error(\n `Column declares typeParams for nativeType \"${column.nativeType}\" ` +\n `but no expandNativeType hook is registered for codecId \"${column.codecId}\". ` +\n 'Ensure the extension providing this codec is included in extensionPacks.',\n );\n }\n\n const expanded = hooks.expandNativeType({\n nativeType: column.nativeType,\n codecId: column.codecId,\n ...ifDefined('typeParams', column.typeParams),\n });\n\n return expanded !== column.nativeType ? expanded : null;\n}\n\n/** Autoincrement columns use SERIAL types, so this returns empty for them. */\nexport function buildColumnDefaultSql(\n columnDefault: PostgresColumnDefault | undefined,\n column?: StorageColumn,\n): string {\n if (!columnDefault) {\n return '';\n }\n\n switch (columnDefault.kind) {\n case 'literal':\n return `DEFAULT ${renderDefaultLiteral(columnDefault.value, column)}`;\n case 'function': {\n if (columnDefault.expression === 'autoincrement()') {\n return '';\n }\n assertSafeDefaultExpression(columnDefault.expression);\n return `DEFAULT (${columnDefault.expression})`;\n }\n case 'sequence':\n return `DEFAULT nextval('${escapeLiteral(quoteIdentifier(columnDefault.name))}'::regclass)`;\n }\n}\n\nexport function renderDefaultLiteral(value: unknown, column?: StorageColumn): string {\n const isJsonColumn = column?.nativeType === 'json' || column?.nativeType === 'jsonb';\n\n if (value instanceof Date) {\n return `'${escapeLiteral(value.toISOString())}'`;\n }\n if (typeof value === 'string') {\n return `'${escapeLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (value === null) {\n return 'NULL';\n }\n const json = JSON.stringify(value);\n if (isJsonColumn) {\n return `'${escapeLiteral(json)}'::${column.nativeType}`;\n }\n return `'${escapeLiteral(json)}'`;\n}\n\nexport function buildAddColumnSql(\n qualifiedTableName: string,\n columnName: string,\n column: StorageColumn,\n codecHooks: ReadonlyMap<string, CodecControlHooks>,\n temporaryDefault?: string | null,\n storageTypes: Record<string, StorageTypeInstance> = {},\n): string {\n const typeSql = buildColumnTypeSql(column, codecHooks, storageTypes);\n const defaultSql =\n buildColumnDefaultSql(column.default, column) ||\n (temporaryDefault ? `DEFAULT ${temporaryDefault}` : '');\n const parts = [\n `ALTER TABLE ${qualifiedTableName}`,\n `ADD COLUMN ${quoteIdentifier(columnName)} ${typeSql}`,\n defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n return parts.join(' ');\n}\n"],"mappings":";;;;AAWA,SAAgB,oBACd,oBACA,OACA,YACA,eAAoD,CAAC,GAC7C;CACR,MAAM,oBAAoB,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KACrD,CAAC,YAAY,YAAqC;EAOjD,OANc;GACZ,gBAAgB,UAAU;GAC1B,mBAAmB,QAAQ,YAAY,YAAY;GACnD,sBAAsB,OAAO,SAAS,MAAM;GAC5C,OAAO,WAAW,KAAK;EACzB,CAAC,CAAC,OAAO,OACE,CAAC,CAAC,KAAK,GAAG;CACvB,CACF;CAEA,MAAM,wBAAkC,CAAC;CACzC,IAAI,MAAM,YACR,sBAAsB,KACpB,gBAAg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