Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-oranges-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/vue-components": patch
---

Fixes nullable nested unions meta creation
29 changes: 23 additions & 6 deletions packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T = any>(
{ meta = {}, parent = "", property, propertySignatures }: CreateMeta,
acc: Partial<MetaRecord<T>> = {}
Expand Down Expand Up @@ -333,9 +348,9 @@ export const createMeta = <T = any>(

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
)
Expand Down Expand Up @@ -548,7 +563,9 @@ export const createMeta = <T = any>(
}

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
)!

Expand All @@ -560,11 +577,11 @@ export const createMeta = <T = any>(
})
}

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
}

Expand Down