From 2153c7b57d05419fb8b913daf31b40ff6956e37f Mon Sep 17 00:00:00 2001 From: Davide Di Pumpo Date: Thu, 23 Oct 2025 19:28:39 +0200 Subject: [PATCH] Fixes nullable nested unions meta creation --- .changeset/rotten-oranges-ask.md | 5 ++++ .../components/OmegaForm/OmegaFormStuff.ts | 29 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .changeset/rotten-oranges-ask.md diff --git a/.changeset/rotten-oranges-ask.md b/.changeset/rotten-oranges-ask.md new file mode 100644 index 0000000000..5deaec7c2c --- /dev/null +++ b/.changeset/rotten-oranges-ask.md @@ -0,0 +1,5 @@ +--- +"@effect-app/vue-components": patch +--- + +Fixes nullable nested unions meta creation diff --git a/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts b/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts index 8831cbbbac..1d4df881a9 100644 --- a/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts +++ b/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts @@ -304,6 +304,21 @@ const isNullableOrUndefined = (property: false | S.AST.AST | undefined) => { return false } +// Helper function to recursively unwrap nested unions (e.g., S.NullOr(S.NullOr(X)) -> X) +const unwrapNestedUnions = (types: readonly S.AST.AST[]): readonly S.AST.AST[] => { + const result: S.AST.AST[] = [] + for (const type of types) { + if (S.AST.isUnion(type)) { + // Recursively unwrap nested unions + const unwrapped = unwrapNestedUnions(type.types) + result.push(...unwrapped) + } else { + result.push(type) + } + } + return result +} + export const createMeta = ( { meta = {}, parent = "", property, propertySignatures }: CreateMeta, acc: Partial> = {} @@ -333,9 +348,9 @@ export const createMeta = ( const typeToProcess = p.type if (S.AST.isUnion(p.type)) { - const nonNullTypes = p - .type - .types + // First unwrap any nested unions, then filter out null/undefined + const unwrappedTypes = unwrapNestedUnions(p.type.types) + const nonNullTypes = unwrappedTypes .filter( (t) => t._tag !== "UndefinedKeyword" && t !== S.Null.ast ) @@ -548,7 +563,9 @@ export const createMeta = ( } if (S.AST.isUnion(property)) { - const nonNullType = property.types.find( + // First unwrap any nested unions, then filter out null/undefined + const unwrappedTypes = unwrapNestedUnions(property.types) + const nonNullType = unwrappedTypes.find( (t) => t._tag !== "UndefinedKeyword" && t !== S.Null.ast )! @@ -560,11 +577,11 @@ export const createMeta = ( }) } - if (property.types.every(S.AST.isLiteral)) { + if (unwrappedTypes.every(S.AST.isLiteral)) { return { ...meta, type: "select", - members: property.types.map((t) => t.literal) + members: unwrappedTypes.map((t) => t.literal) } as FieldMeta }