@prisma-next/target-postgres 0.13.0-dev.16 → 0.13.0-dev.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/control.mjs +3 -3
- package/dist/{enum-planning-DTMrPLkN.mjs → enum-planning-CHWGiz0L.mjs} +2 -2
- package/dist/{enum-planning-DTMrPLkN.mjs.map → enum-planning-CHWGiz0L.mjs.map} +1 -1
- package/dist/enum-planning.mjs +1 -1
- package/dist/{issue-planner-399UDGjU.mjs → issue-planner-BtknIL8A.mjs} +5 -5
- package/dist/{issue-planner-399UDGjU.mjs.map → issue-planner-BtknIL8A.mjs.map} +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{op-factory-call-1URu-iTb.mjs → op-factory-call-QFiNG9lu.mjs} +2 -2
- package/dist/{op-factory-call-1URu-iTb.mjs.map → op-factory-call-QFiNG9lu.mjs.map} +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/{planner-Dh6oTlSF.mjs → planner-Bx4NB1Du.mjs} +5 -5
- package/dist/{planner-Dh6oTlSF.mjs.map → planner-Bx4NB1Du.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-CzP4ttHe.mjs → planner-produced-postgres-migration-LZZMczh2.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-CzP4ttHe.mjs.map → planner-produced-postgres-migration-LZZMczh2.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-DRD5E8A1.mjs → planner-sql-checks-CrAbk7gX.mjs} +2 -2
- package/dist/{planner-sql-checks-DRD5E8A1.mjs.map → planner-sql-checks-CrAbk7gX.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-serializer-DCg7YaP3.mjs → postgres-contract-serializer-DFpLrLiH.mjs} +2 -2
- package/dist/{postgres-contract-serializer-DCg7YaP3.mjs.map → postgres-contract-serializer-DFpLrLiH.mjs.map} +1 -1
- package/dist/{postgres-migration-DYLAgHBj.mjs → postgres-migration-FeZUzZOH.mjs} +2 -2
- package/dist/{postgres-migration-DYLAgHBj.mjs.map → postgres-migration-FeZUzZOH.mjs.map} +1 -1
- package/dist/{postgres-schema-BVTA2QH7.mjs → postgres-schema-BAgkIU9u.mjs} +2 -2
- package/dist/postgres-schema-BAgkIU9u.mjs.map +1 -0
- package/dist/runtime.mjs +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +17 -17
- package/src/core/postgres-schema.ts +1 -1
- package/dist/postgres-schema-BVTA2QH7.mjs.map +0 -1
package/dist/control.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-DKmj-IMN.mjs";
|
|
2
|
-
import { o as resolveDdlSchemaForNamespaceStorage, t as createResolveExistingEnumValues } from "./enum-planning-
|
|
2
|
+
import { o as resolveDdlSchemaForNamespaceStorage, t as createResolveExistingEnumValues } from "./enum-planning-CHWGiz0L.mjs";
|
|
3
3
|
import { t as parsePostgresDefault } from "./default-normalizer-DyyCHQWs.mjs";
|
|
4
4
|
import { t as normalizeSchemaNativeType } from "./native-type-normalizer-Bc9XJzWC.mjs";
|
|
5
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
5
|
+
import { t as createPostgresMigrationPlanner } from "./planner-Bx4NB1Du.mjs";
|
|
6
6
|
import { a as renderDefaultLiteral } from "./planner-ddl-builders-Cw2n2llW.mjs";
|
|
7
|
-
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-
|
|
7
|
+
import { t as PostgresContractSerializer } from "./postgres-contract-serializer-DFpLrLiH.mjs";
|
|
8
8
|
import { contractToSchemaIR, extractCodecControlHooks, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
|
|
9
9
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
10
10
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./codec-ids-CTikp1if.mjs";
|
|
2
|
-
import { r as isPostgresSchema } from "./postgres-schema-
|
|
2
|
+
import { r as isPostgresSchema } from "./postgres-schema-BAgkIU9u.mjs";
|
|
3
3
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
4
|
import { arraysEqual } from "@prisma-next/family-sql/schema-verify";
|
|
5
5
|
//#region src/core/migrations/enum-planning.ts
|
|
@@ -126,4 +126,4 @@ function getDesiredEnumValues(typeInstance) {
|
|
|
126
126
|
//#endregion
|
|
127
127
|
export { readPostgresSchemaIrAnnotations as a, readExistingEnumValues as i, determineEnumDiff as n, resolveDdlSchemaForNamespaceStorage as o, getDesiredEnumValues as r, createResolveExistingEnumValues as t };
|
|
128
128
|
|
|
129
|
-
//# sourceMappingURL=enum-planning-
|
|
129
|
+
//# sourceMappingURL=enum-planning-CHWGiz0L.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum-planning-DTMrPLkN.mjs","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"sourcesContent":["/**\n * Pure planning helpers for Postgres enum types: the diff/rebuild logic\n * that the verifier and planner use to walk `PostgresEnumType` instances\n * natively. Op builders live in `./operations/enums.ts`.\n */\n\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '../codec-ids';\nimport type { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.enumTypes[schemaName][nativeType]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/**\n * Live enum types keyed by `(schemaName, nativeType)` as a nested map, so two\n * schemas sharing a native enum name stay distinct without packing the pair\n * into a string. This is the same `(namespace, entityName)` coordinate the\n * contract side addresses entities by.\n */\ntype PgEnumTypesMap = Readonly<Record<string, Readonly<Record<string, PgStorageTypeEntry>>>>;\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly enumTypes?: PgEnumTypesMap;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgEnumTypesMap(value: unknown): PgEnumTypesMap | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const bySchema: Record<string, Record<string, PgStorageTypeEntry>> = {};\n for (const [schemaName, byTypeRaw] of Object.entries(value)) {\n if (byTypeRaw === null || typeof byTypeRaw !== 'object' || Array.isArray(byTypeRaw)) {\n continue;\n }\n const byType: Record<string, PgStorageTypeEntry> = {};\n for (const [nativeType, entryValue] of Object.entries(byTypeRaw)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n byType[nativeType] = entry;\n }\n }\n if (Object.keys(byType).length > 0) {\n bySchema[schemaName] = byType;\n }\n }\n return Object.keys(bySchema).length > 0 ? bySchema : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const enumTypes = readPgEnumTypesMap(Reflect.get(raw, 'enumTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(enumTypes !== undefined ? { enumTypes } : {}),\n };\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\n\n/**\n * Categorisation of how an existing enum type's values relate to the\n * desired set in the contract.\n */\nexport type EnumDiff =\n | { readonly kind: 'unchanged' }\n | { readonly kind: 'add_values'; readonly values: readonly string[] }\n | { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };\n\n/**\n * Reads existing enum values for `(schemaName, nativeType)` from the\n * Postgres-introspected `schema.annotations.pg.enumTypes` map, addressed by\n * the `(schema, nativeType)` coordinate.\n *\n * Schema IR's enum entries are always codec-typed\n * (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector\n * writes that shape, and the Contract→Schema IR projector resolves\n * `PostgresEnumType` instances down to the same codec-typed triple before\n * they ever land in Schema IR. There is no second on-disk shape to\n * accept here.\n *\n * Returns `null` when no enum entry exists for the given native type.\n */\nexport function readExistingEnumValues(\n schema: SqlSchemaIR,\n schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const enumTypes = readPostgresSchemaIrAnnotations(schema).enumTypes;\n const existing = enumTypes?.[schemaName]?.[nativeType];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n const enumValues = existing.typeParams?.values;\n if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {\n return null;\n }\n return enumValues;\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to\n * desired values.\n *\n * Postgres enums can only have values added (not removed or reordered)\n * without a full type rebuild involving temp type creation and column\n * migration; `'rebuild'` covers the value-removal and reorder cases.\n */\nexport function determineEnumDiff(\n existing: readonly string[],\n desired: readonly string[],\n): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n return { kind: 'add_values', values: missingValues };\n}\n\n/**\n * Convenience accessor — returns the enum's desired values from a\n * `PostgresEnumType` IR instance.\n */\nexport function getDesiredEnumValues(typeInstance: PostgresEnumType): readonly string[] {\n return typeInstance.values;\n}\n"],"mappings":";;;;;;;;;;AAqCA,SAAS,mBAAmB,OAAoC;CAC9D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,SAAS,uBAAuB,OAAgD;CAC9E,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE;CAEF,MAAM,UAAU,QAAQ,IAAI,OAAO,SAAS;CAC5C,MAAM,gBAAgB,QAAQ,IAAI,OAAO,YAAY;CACrD,MAAM,aACJ,kBAAkB,KAAA,KAClB,kBAAkB,QAClB,OAAO,kBAAkB,YACzB,CAAC,MAAM,QAAQ,aAAa,IACxB,EAAE,QAAQ,QAAQ,IAAI,eAAe,QAAQ,EAAE,IAC/C,KAAA;CACN,OAAO;EACL,GAAI,OAAO,YAAY,WAAW,EAAE,QAAQ,IAAI,CAAC;EACjD,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;CACnD;AACF;AAEA,SAAS,mBAAmB,OAA4C;CACtE,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE;CAEF,MAAM,WAA+D,CAAC;CACtE,KAAK,MAAM,CAAC,YAAY,cAAc,OAAO,QAAQ,KAAK,GAAG;EAC3D,IAAI,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,GAChF;EAEF,MAAM,SAA6C,CAAC;EACpD,KAAK,MAAM,CAAC,YAAY,eAAe,OAAO,QAAQ,SAAS,GAAG;GAChE,MAAM,QAAQ,uBAAuB,UAAU;GAC/C,IAAI,UAAU,KAAA,GACZ,OAAO,cAAc;EAEzB;EACA,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAC/B,SAAS,cAAc;CAE3B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,UAAU,OAAO,GAC/B,OAAO,EAAE,MAAM,YAAY;CAE7B,MAAM,cAAc,IAAI,IAAI,QAAQ;CACpC,MAAM,aAAa,IAAI,IAAI,OAAO;CAClC,MAAM,gBAAgB,QAAQ,QAAQ,UAAU,CAAC,YAAY,IAAI,KAAK,CAAC;CACvE,MAAM,gBAAgB,SAAS,QAAQ,UAAU,CAAC,WAAW,IAAI,KAAK,CAAC;CACvE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,OAAO;CAC5F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;CAAc;CAE1C,OAAO;EAAE,MAAM;EAAc,QAAQ;CAAc;AACrD;;;;;AAMA,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa;AACtB"}
|
|
1
|
+
{"version":3,"file":"enum-planning-CHWGiz0L.mjs","names":[],"sources":["../src/core/migrations/enum-planning.ts"],"sourcesContent":["/**\n * Pure planning helpers for Postgres enum types: the diff/rebuild logic\n * that the verifier and planner use to walk `PostgresEnumType` instances\n * natively. Op builders live in `./operations/enums.ts`.\n */\n\nimport { arraysEqual } from '@prisma-next/family-sql/schema-verify';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport type { PostgresEnumStorageEntry, SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';\nimport { PG_ENUM_CODEC_ID } from '../codec-ids';\nimport type { PostgresEnumType } from '../postgres-enum-type';\nimport { isPostgresSchema } from '../postgres-schema';\n\n/**\n * Codec-typed enum entry shape stored under\n * `schema.annotations.pg.enumTypes[schemaName][nativeType]`.\n */\ninterface PgStorageTypeEntry {\n readonly codecId?: string;\n readonly typeParams?: { readonly values?: unknown };\n}\n\n/**\n * Live enum types keyed by `(schemaName, nativeType)` as a nested map, so two\n * schemas sharing a native enum name stay distinct without packing the pair\n * into a string. This is the same `(namespace, entityName)` coordinate the\n * contract side addresses entities by.\n */\ntype PgEnumTypesMap = Readonly<Record<string, Readonly<Record<string, PgStorageTypeEntry>>>>;\n\n/** Postgres-specific subtree on family `SqlSchemaIR.annotations`. */\nexport interface PostgresSchemaIrAnnotations {\n readonly schema?: string;\n readonly enumTypes?: PgEnumTypesMap;\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n return typeof value === 'string' ? value : undefined;\n}\n\nfunction readPgStorageTypeEntry(value: unknown): PgStorageTypeEntry | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const codecId = Reflect.get(value, 'codecId');\n const typeParamsRaw = Reflect.get(value, 'typeParams');\n const typeParams =\n typeParamsRaw !== undefined &&\n typeParamsRaw !== null &&\n typeof typeParamsRaw === 'object' &&\n !Array.isArray(typeParamsRaw)\n ? { values: Reflect.get(typeParamsRaw, 'values') }\n : undefined;\n return {\n ...(typeof codecId === 'string' ? { codecId } : {}),\n ...(typeParams !== undefined ? { typeParams } : {}),\n };\n}\n\nfunction readPgEnumTypesMap(value: unknown): PgEnumTypesMap | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const bySchema: Record<string, Record<string, PgStorageTypeEntry>> = {};\n for (const [schemaName, byTypeRaw] of Object.entries(value)) {\n if (byTypeRaw === null || typeof byTypeRaw !== 'object' || Array.isArray(byTypeRaw)) {\n continue;\n }\n const byType: Record<string, PgStorageTypeEntry> = {};\n for (const [nativeType, entryValue] of Object.entries(byTypeRaw)) {\n const entry = readPgStorageTypeEntry(entryValue);\n if (entry !== undefined) {\n byType[nativeType] = entry;\n }\n }\n if (Object.keys(byType).length > 0) {\n bySchema[schemaName] = byType;\n }\n }\n return Object.keys(bySchema).length > 0 ? bySchema : undefined;\n}\n\n/**\n * Reads the Postgres annotation envelope (`schema.annotations.pg`) from\n * family Schema IR. `SqlAnnotations` is an open target-pack extensibility\n * map (`Record<string, unknown>`); this accessor narrows the `pg` slot at\n * runtime so Postgres code can read introspection fields without casts.\n */\nexport function readPostgresSchemaIrAnnotations(schema: SqlSchemaIR): PostgresSchemaIrAnnotations {\n const raw = schema.annotations?.['pg'];\n if (raw === undefined || raw === null || typeof raw !== 'object' || Array.isArray(raw)) {\n return {};\n }\n const schemaField = readOptionalString(Reflect.get(raw, 'schema'));\n const enumTypes = readPgEnumTypesMap(Reflect.get(raw, 'enumTypes'));\n return {\n ...(schemaField !== undefined ? { schema: schemaField } : {}),\n ...(enumTypes !== undefined ? { enumTypes } : {}),\n };\n}\n\n/**\n * Resolves the live-schema name a namespace's enums are introspected under,\n * for keying `readExistingEnumValues` lookups. The unbound namespace's\n * `ddlSchemaName` is a planner-emit sentinel (`__unbound__`) that never names a\n * real schema, so for the unbound coordinate we read the *introspected* schema\n * recorded on `annotations.pg.schema` (the live `current_schema()` the adapter\n * walked) — that is the schema the enum's `storageTypes` entry is keyed under.\n * Named namespaces resolve to their own DDL schema, which matches the\n * per-schema introspection key directly.\n */\nexport function resolveDdlSchemaForNamespaceStorage(\n storage: SqlStorage,\n namespaceId: string,\n schemaIr?: SqlSchemaIR,\n): string {\n if (namespaceId === UNBOUND_NAMESPACE_ID) {\n return (schemaIr ? readPostgresSchemaIrAnnotations(schemaIr).schema : undefined) ?? 'public';\n }\n const namespace = storage.namespaces[namespaceId];\n if (namespace && isPostgresSchema(namespace)) {\n return namespace.ddlSchemaName(storage);\n }\n return namespaceId;\n}\n\n/** Contract-scoped bridge for the family verifier's enum value resolver. */\nexport function createResolveExistingEnumValues(\n storage: SqlStorage,\n): (\n schema: SqlSchemaIR,\n enumType: PostgresEnumStorageEntry,\n namespaceId: string,\n) => readonly string[] | null {\n return (schema, enumType, namespaceId) =>\n readExistingEnumValues(\n schema,\n resolveDdlSchemaForNamespaceStorage(storage, namespaceId, schema),\n enumType.nativeType,\n );\n}\n\n/**\n * Categorisation of how an existing enum type's values relate to the\n * desired set in the contract.\n */\nexport type EnumDiff =\n | { readonly kind: 'unchanged' }\n | { readonly kind: 'add_values'; readonly values: readonly string[] }\n | { readonly kind: 'rebuild'; readonly removedValues: readonly string[] };\n\n/**\n * Reads existing enum values for `(schemaName, nativeType)` from the\n * Postgres-introspected `schema.annotations.pg.enumTypes` map, addressed by\n * the `(schema, nativeType)` coordinate.\n *\n * Schema IR's enum entries are always codec-typed\n * (`{codecId: PG_ENUM_CODEC_ID, typeParams.values}`): the introspector\n * writes that shape, and the Contract→Schema IR projector resolves\n * `PostgresEnumType` instances down to the same codec-typed triple before\n * they ever land in Schema IR. There is no second on-disk shape to\n * accept here.\n *\n * Returns `null` when no enum entry exists for the given native type.\n */\nexport function readExistingEnumValues(\n schema: SqlSchemaIR,\n schemaName: string,\n nativeType: string,\n): readonly string[] | null {\n const enumTypes = readPostgresSchemaIrAnnotations(schema).enumTypes;\n const existing = enumTypes?.[schemaName]?.[nativeType];\n if (!existing || existing.codecId !== PG_ENUM_CODEC_ID) {\n return null;\n }\n const enumValues = existing.typeParams?.values;\n if (!Array.isArray(enumValues) || !enumValues.every((v) => typeof v === 'string')) {\n return null;\n }\n return enumValues;\n}\n\n/**\n * Determines what changes are needed to transform existing enum values to\n * desired values.\n *\n * Postgres enums can only have values added (not removed or reordered)\n * without a full type rebuild involving temp type creation and column\n * migration; `'rebuild'` covers the value-removal and reorder cases.\n */\nexport function determineEnumDiff(\n existing: readonly string[],\n desired: readonly string[],\n): EnumDiff {\n if (arraysEqual(existing, desired)) {\n return { kind: 'unchanged' };\n }\n const existingSet = new Set(existing);\n const desiredSet = new Set(desired);\n const missingValues = desired.filter((value) => !existingSet.has(value));\n const removedValues = existing.filter((value) => !desiredSet.has(value));\n const orderMismatch =\n missingValues.length === 0 && removedValues.length === 0 && !arraysEqual(existing, desired);\n if (removedValues.length > 0 || orderMismatch) {\n return { kind: 'rebuild', removedValues };\n }\n return { kind: 'add_values', values: missingValues };\n}\n\n/**\n * Convenience accessor — returns the enum's desired values from a\n * `PostgresEnumType` IR instance.\n */\nexport function getDesiredEnumValues(typeInstance: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AO;CAClC,MAAM,gBAAgB,QAAQ,QAAQ,UAAU,CAAC,YAAY,IAAI,KAAK,CAAC;CACvE,MAAM,gBAAgB,SAAS,QAAQ,UAAU,CAAC,WAAW,IAAI,KAAK,CAAC;CACvE,MAAM,gBACJ,cAAc,WAAW,KAAK,cAAc,WAAW,KAAK,CAAC,YAAY,UAAU,OAAO;CAC5F,IAAI,cAAc,SAAS,KAAK,eAC9B,OAAO;EAAE,MAAM;EAAW;CAAc;CAE1C,OAAO;EAAE,MAAM;EAAc,QAAQ;CAAc;AACrD;;;;;AAMA,SAAgB,qBAAqB,cAAmD;CACtF,OAAO,aAAa;AACtB"}
|
package/dist/enum-planning.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as readPostgresSchemaIrAnnotations, i as readExistingEnumValues, n as determineEnumDiff, o as resolveDdlSchemaForNamespaceStorage, r as getDesiredEnumValues, t as createResolveExistingEnumValues } from "./enum-planning-
|
|
1
|
+
import { a as readPostgresSchemaIrAnnotations, i as readExistingEnumValues, n as determineEnumDiff, o as resolveDdlSchemaForNamespaceStorage, r as getDesiredEnumValues, t as createResolveExistingEnumValues } from "./enum-planning-CHWGiz0L.mjs";
|
|
2
2
|
export { createResolveExistingEnumValues, determineEnumDiff, getDesiredEnumValues, readExistingEnumValues, readPostgresSchemaIrAnnotations, resolveDdlSchemaForNamespaceStorage };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as PostgresEnumType } from "./postgres-enum-type-DPKqCBem.mjs";
|
|
2
2
|
import { i as quoteIdentifier } from "./sql-utils-DcfMz4MQ.mjs";
|
|
3
|
-
import { r as isPostgresSchema } from "./postgres-schema-
|
|
4
|
-
import { i as readExistingEnumValues, n as determineEnumDiff, o as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-
|
|
3
|
+
import { r as isPostgresSchema } from "./postgres-schema-BAgkIU9u.mjs";
|
|
4
|
+
import { i as readExistingEnumValues, n as determineEnumDiff, o as resolveDdlSchemaForNamespaceStorage } from "./enum-planning-CHWGiz0L.mjs";
|
|
5
5
|
import { t as resolveColumnTypeMetadata } from "./planner-type-resolution-836DExFN.mjs";
|
|
6
|
-
import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-
|
|
7
|
-
import { C as RenameTypeCall, E as postgresDefaultToDdlColumnDefault, S as RawSqlCall, T as SetNotNullCall, _ as DropDefaultCall, a as AddPrimaryKeyCall, b as DropNotNullCall, c as CreateEnumTypeCall, d as CreateSchemaCall, f as CreateTableCall, g as DropConstraintCall, h as DropColumnCall, i as AddForeignKeyCall, m as DropCheckConstraintCall, n as AddColumnCall, o as AddUniqueCall, p as DataTransformCall, r as AddEnumValuesCall, s as AlterColumnTypeCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropEnumTypeCall, w as SetDefaultCall, x as DropTableCall, y as DropIndexCall } from "./op-factory-call-
|
|
6
|
+
import { a as columnNullabilityCheck, c as qualifyTableName, i as columnHasNoDefaultCheck, r as columnExistsCheck, t as buildExpectedFormatType, u as tableIsEmptyCheck } from "./planner-sql-checks-CrAbk7gX.mjs";
|
|
7
|
+
import { C as RenameTypeCall, E as postgresDefaultToDdlColumnDefault, S as RawSqlCall, T as SetNotNullCall, _ as DropDefaultCall, a as AddPrimaryKeyCall, b as DropNotNullCall, c as CreateEnumTypeCall, d as CreateSchemaCall, f as CreateTableCall, g as DropConstraintCall, h as DropColumnCall, i as AddForeignKeyCall, m as DropCheckConstraintCall, n as AddColumnCall, o as AddUniqueCall, p as DataTransformCall, r as AddEnumValuesCall, s as AlterColumnTypeCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropEnumTypeCall, w as SetDefaultCall, x as DropTableCall, y as DropIndexCall } from "./op-factory-call-QFiNG9lu.mjs";
|
|
8
8
|
import { n as buildColumnDefaultSql, r as buildColumnTypeSql, t as buildAddColumnSql } from "./planner-ddl-builders-Cw2n2llW.mjs";
|
|
9
9
|
import { n as resolveIdentityValue } from "./planner-identity-values-BIpa5p2I.mjs";
|
|
10
10
|
import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-CiVaAQP-.mjs";
|
|
@@ -1142,4 +1142,4 @@ function planIssues(options) {
|
|
|
1142
1142
|
//#endregion
|
|
1143
1143
|
export { postgresPlannerStrategies as n, planIssues as t };
|
|
1144
1144
|
|
|
1145
|
-
//# sourceMappingURL=issue-planner-
|
|
1145
|
+
//# sourceMappingURL=issue-planner-BtknIL8A.mjs.map
|