From 2af45232c81c5457af2784244ccf13e5b243d744 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Tue, 8 Oct 2024 10:15:57 +0200 Subject: [PATCH] support rq --- .changeset/slimy-actors-film.md | 5 +++++ packages/vue/src/form.ts | 27 ++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 .changeset/slimy-actors-film.md diff --git a/.changeset/slimy-actors-film.md b/.changeset/slimy-actors-film.md new file mode 100644 index 000000000..9c9392578 --- /dev/null +++ b/.changeset/slimy-actors-film.md @@ -0,0 +1,5 @@ +--- +"@effect-app/vue": patch +--- + +support req diff --git a/packages/vue/src/form.ts b/packages/vue/src/form.ts index 6e58316ab..320bd5677 100644 --- a/packages/vue/src/form.ts +++ b/packages/vue/src/form.ts @@ -3,10 +3,8 @@ import type { ParseError } from "@effect/schema/ParseResult" import { createIntl, type IntlFormatters } from "@formatjs/intl" import type {} from "intl-messageformat" import type { Unbranded } from "@effect-app/schema/brand" -import { Either, Option, pipe, S } from "effect-app" +import { Either, Option, pipe, S, Struct } from "effect-app" import type { Schema } from "effect-app/schema" - -import type { Struct } from "@effect/schema/Schema" import type { IsUnion } from "effect-app/utils" import type { Ref } from "vue" import { capitalize, ref, watch } from "vue" @@ -190,7 +188,7 @@ export function buildFieldInfoFromFields< From extends Record, To extends Record >( - schema: Schema & { fields?: Struct.Fields } + schema: Schema & { fields?: S.Struct.Fields } ) { return buildFieldInfoFromFieldsRoot(schema).fields } @@ -199,7 +197,7 @@ export function buildFieldInfoFromFieldsRoot< From extends Record, To extends Record >( - schema: Schema & { fields?: Struct.Fields } + schema: Schema & { fields?: S.Struct.Fields } ): NestedFieldInfo { const ast = getTypeLiteralAST(schema.ast) @@ -371,25 +369,28 @@ function buildFieldInfo( export const buildFormFromSchema = < From extends Record, To extends Record, + C extends Record, OnSubmitA >( - s: Schema< - To, - From, - never - >, - state: Ref, + s: + & Schema< + To, + From, + never + > + & { new(c: C): any; fields: S.Struct.Fields }, + state: Ref>, onSubmit: (a: To) => Promise ) => { const fields = buildFieldInfoFromFieldsRoot(s).fields - const parse = S.decodeSync(s) + const parse = S.decodeUnknownSync(S.Struct(Struct.omit(s.fields, "_tag")) as any) const isDirty = ref(false) const isValid = ref(true) const submit1 = (onSubmit: (a: To) => Promise) => async >(e: T) => { const r = await e if (!r.valid) return - return onSubmit(parse(state.value)) + return onSubmit(new s(parse(state.value))) } const submit = submit1(onSubmit)