Skip to content

Commit 286fc43

Browse files
committed
Fix: Refinement Schemas Support
1 parent 5fb77ce commit 286fc43

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

.changeset/brown-trees-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect-app/vue-components": patch
3+
---
4+
5+
Fix: Refinement Schemas Support

packages/vue-components/src/components/OmegaForm/useOmegaForm.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ export const useOmegaForm = <
774774
for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
775775
// Only fix fields that are undefined in the instance
776776
if (instance[key] === undefined) {
777-
const ast = (fieldSchema as any).ast
777+
const ast = (fieldSchema as any)?.ast
778778
const nullableOrUndefined = isNullableOrUndefined(ast)
779779
if (nullableOrUndefined === "null") {
780780
instance[key] = null
@@ -835,7 +835,7 @@ export const useOmegaForm = <
835835
}
836836
} else {
837837
// TODO Should we put to null/undefined only leaves?
838-
const ast = (fieldSchema as any).ast
838+
const ast = (fieldSchema as any)?.ast
839839
const nullableOrUndefined = isNullableOrUndefined(ast)
840840
switch (nullableOrUndefined) {
841841
case "null":
@@ -869,11 +869,16 @@ export const useOmegaForm = <
869869
let result: Partial<From> = {}
870870

871871
try {
872-
// First try to use schema.make() if available
872+
// For filtered schemas (created with S.filter), use the original unfiltered schema's make method
873+
let schemaToUse = schema as any
874+
if (schemaToUse?.ast?._tag === "Refinement" && schemaToUse?.from) {
875+
schemaToUse = schemaToUse.from
876+
}
877+
873878
// First try to use schema.make() if available
874879
// Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
875-
const decoded = (schema as any).make(defaultValues)
876-
result = S.encodeSync(partialRecursive(extractDefaultsFromAST(schema)))(decoded)
880+
const decoded = schemaToUse.make(defaultValues)
881+
result = S.encodeSync(partialRecursive(schemaToUse))(decoded)
877882
} catch (error) {
878883
// If make() fails, try to extract defaults from AST
879884
if (window.location.hostname === "localhost") {

0 commit comments

Comments
 (0)