@effect-app/vue-components 2.7.7 → 2.7.8
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useForm as z } from "@tanstack/vue-form";
|
|
2
|
-
import { Data as Q, S
|
|
2
|
+
import { Data as Q, S, Effect as b, Array as g, Fiber as O, Option as D } from "effect-app";
|
|
3
3
|
import { runtimeFiberAsPromise as X } from "./vue-components.es16.js";
|
|
4
4
|
import { isObject as Y } from "./vue-components.es17.js";
|
|
5
|
-
import { computed as
|
|
5
|
+
import { computed as V, onUnmounted as W, onMounted as Z, onBeforeUnmount as C, watch as H, ref as ee, h as B } from "vue";
|
|
6
6
|
import te from "./vue-components.es18.js";
|
|
7
7
|
import re from "./vue-components.es19.js";
|
|
8
8
|
import ne from "./vue-components.es20.js";
|
|
@@ -11,34 +11,34 @@ import oe from "./vue-components.es6.js";
|
|
|
11
11
|
import ie from "./vue-components.es8.js";
|
|
12
12
|
import ae from "./vue-components.es21.js";
|
|
13
13
|
import { trace as q } from "./vue-components.es22.js";
|
|
14
|
-
import { context as
|
|
15
|
-
const
|
|
16
|
-
const i =
|
|
14
|
+
import { context as T } from "./vue-components.es23.js";
|
|
15
|
+
const A = (c) => {
|
|
16
|
+
const i = c.ast;
|
|
17
17
|
if (i._tag === "Union") {
|
|
18
18
|
const o = i.types.map((f) => {
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const l = S.make(f);
|
|
20
|
+
return A(l).ast;
|
|
21
21
|
}), p = {
|
|
22
22
|
...i,
|
|
23
23
|
types: o
|
|
24
24
|
};
|
|
25
|
-
return
|
|
25
|
+
return S.make(p);
|
|
26
26
|
}
|
|
27
27
|
if (i._tag === "Transformation") {
|
|
28
|
-
const o =
|
|
28
|
+
const o = S.make(i.from), p = S.make(i.to), f = A(o), l = A(p), d = {
|
|
29
29
|
...i,
|
|
30
30
|
from: f.ast,
|
|
31
|
-
to:
|
|
31
|
+
to: l.ast
|
|
32
32
|
};
|
|
33
|
-
return
|
|
33
|
+
return S.make(d);
|
|
34
34
|
}
|
|
35
35
|
if (i._tag === "TypeLiteral") {
|
|
36
36
|
const o = i.propertySignatures.map((f) => {
|
|
37
|
-
const
|
|
38
|
-
let d =
|
|
39
|
-
if (
|
|
40
|
-
const k =
|
|
41
|
-
d =
|
|
37
|
+
const l = f.type;
|
|
38
|
+
let d = l;
|
|
39
|
+
if (l._tag === "TypeLiteral" || l._tag === "Union" || l._tag === "Transformation") {
|
|
40
|
+
const k = S.make(l);
|
|
41
|
+
d = A(k).ast;
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
44
44
|
...f,
|
|
@@ -49,29 +49,29 @@ const _ = (l) => {
|
|
|
49
49
|
...i,
|
|
50
50
|
propertySignatures: o
|
|
51
51
|
};
|
|
52
|
-
return
|
|
52
|
+
return S.make(p);
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return c;
|
|
55
55
|
};
|
|
56
56
|
class le extends Q.TaggedError("FormErrors") {
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const M = (c) => function(o) {
|
|
59
59
|
return {
|
|
60
60
|
render() {
|
|
61
61
|
return B(o, {
|
|
62
|
-
form:
|
|
62
|
+
form: c,
|
|
63
63
|
...this.$attrs
|
|
64
64
|
}, this.$slots);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
}, ce = (
|
|
67
|
+
}, ce = (c) => function(o) {
|
|
68
68
|
return {
|
|
69
69
|
setup() {
|
|
70
|
-
const { fieldMap: p, form: f } =
|
|
71
|
-
const
|
|
70
|
+
const { fieldMap: p, form: f } = c, l = f.useStore((v) => v.errors), d = f.useStore((v) => v.fieldMeta), k = f.useStore((v) => v.errorMap), h = V(() => {
|
|
71
|
+
const v = g.filterMap(
|
|
72
72
|
Object.entries(d.value),
|
|
73
|
-
([x,
|
|
74
|
-
const a =
|
|
73
|
+
([x, w]) => {
|
|
74
|
+
const a = w.errors ?? [];
|
|
75
75
|
if (!a.length) return D.none();
|
|
76
76
|
const y = p.value.get(x);
|
|
77
77
|
return y ? D.some({
|
|
@@ -83,16 +83,16 @@ const U = (l) => function(o) {
|
|
|
83
83
|
}
|
|
84
84
|
), F = [];
|
|
85
85
|
if (k.value.onSubmit) {
|
|
86
|
-
for (const [x,
|
|
87
|
-
if (g.isArray(
|
|
88
|
-
for (const a of
|
|
86
|
+
for (const [x, w] of Object.entries(k.value.onSubmit))
|
|
87
|
+
if (g.isArray(w) && w.length)
|
|
88
|
+
for (const a of w) {
|
|
89
89
|
const y = a;
|
|
90
90
|
if (y?.path && g.isArray(y.path) && y.path.length) {
|
|
91
|
-
const
|
|
92
|
-
if (!p.value.has(
|
|
91
|
+
const _ = y.path.join(".");
|
|
92
|
+
if (!p.value.has(_)) {
|
|
93
93
|
F.push({
|
|
94
|
-
label:
|
|
95
|
-
inputId:
|
|
94
|
+
label: _,
|
|
95
|
+
inputId: _,
|
|
96
96
|
errors: [y.message].filter(Boolean)
|
|
97
97
|
});
|
|
98
98
|
break;
|
|
@@ -100,11 +100,11 @@ const U = (l) => function(o) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
return [...
|
|
103
|
+
return [...v, ...F];
|
|
104
104
|
});
|
|
105
105
|
return {
|
|
106
|
-
generalErrors:
|
|
107
|
-
errors:
|
|
106
|
+
generalErrors: l,
|
|
107
|
+
errors: h
|
|
108
108
|
};
|
|
109
109
|
},
|
|
110
110
|
render({ errors: p, generalErrors: f }) {
|
|
@@ -115,12 +115,12 @@ const U = (l) => function(o) {
|
|
|
115
115
|
}, this.$slots);
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
-
},
|
|
119
|
-
if (!
|
|
120
|
-
const p =
|
|
118
|
+
}, _e = (c, i, o) => {
|
|
119
|
+
if (!c) throw new Error("Schema is required");
|
|
120
|
+
const p = S.standardSchemaV1(c), f = S.decode(c), { meta: l } = se(c), d = V(() => {
|
|
121
121
|
if (o?.persistency?.id)
|
|
122
122
|
return o.persistency.id;
|
|
123
|
-
const e = window.location.pathname, t = Object.keys(
|
|
123
|
+
const e = window.location.pathname, t = Object.keys(l);
|
|
124
124
|
return `${e}-${t.join("-")}`;
|
|
125
125
|
}), k = () => {
|
|
126
126
|
const e = new URLSearchParams(window.location.search);
|
|
@@ -128,12 +128,12 @@ const U = (l) => function(o) {
|
|
|
128
128
|
const t = new URL(window.location.href);
|
|
129
129
|
t.search = e.toString(), window.history.replaceState({}, "", t.toString());
|
|
130
130
|
};
|
|
131
|
-
function
|
|
131
|
+
function h(e, t) {
|
|
132
132
|
for (const r in t)
|
|
133
|
-
g.isArray(t[r]) ? e[r] = t[r] : t[r] && Y(t[r]) ? (e[r] || (e[r] = {}),
|
|
133
|
+
g.isArray(t[r]) ? e[r] = t[r] : t[r] && Y(t[r]) ? (e[r] || (e[r] = {}), h(e[r], t[r])) : e[r] = t[r];
|
|
134
134
|
return e;
|
|
135
135
|
}
|
|
136
|
-
const
|
|
136
|
+
const v = (e) => {
|
|
137
137
|
const t = {};
|
|
138
138
|
if (typeof e?.make == "function")
|
|
139
139
|
try {
|
|
@@ -141,19 +141,19 @@ const U = (l) => function(o) {
|
|
|
141
141
|
if (e?.fields && typeof e.fields == "object") {
|
|
142
142
|
for (const [s, u] of Object.entries(e.fields))
|
|
143
143
|
if (n[s] === void 0) {
|
|
144
|
-
const m = u
|
|
145
|
-
|
|
144
|
+
const m = u?.ast, U = J(m);
|
|
145
|
+
U === "null" ? n[s] = null : U === "undefined" && (n[s] = void 0);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
return n;
|
|
149
149
|
} catch {
|
|
150
150
|
}
|
|
151
|
-
const r = e?.members || (e?.ast?._tag === "Union" && e.ast.types ? e.ast.types.map((n) =>
|
|
151
|
+
const r = e?.members || (e?.ast?._tag === "Union" && e.ast.types ? e.ast.types.map((n) => S.make(n)) : null);
|
|
152
152
|
if (r && g.isArray(r)) {
|
|
153
153
|
for (const n of r) {
|
|
154
|
-
const s =
|
|
154
|
+
const s = v(n);
|
|
155
155
|
if (Object.keys(s).length > 0 && n?.fields && Object.entries(n.fields).some(
|
|
156
|
-
([m,
|
|
156
|
+
([m, U]) => m === "_tag" || m === "type" || m === "kind" ? U?.ast?.defaultValue !== void 0 : !1
|
|
157
157
|
))
|
|
158
158
|
return s;
|
|
159
159
|
}
|
|
@@ -168,7 +168,7 @@ const U = (l) => function(o) {
|
|
|
168
168
|
} catch {
|
|
169
169
|
}
|
|
170
170
|
else {
|
|
171
|
-
const m = s
|
|
171
|
+
const m = s?.ast;
|
|
172
172
|
switch (J(m)) {
|
|
173
173
|
case "null":
|
|
174
174
|
t[n] = null;
|
|
@@ -178,26 +178,28 @@ const U = (l) => function(o) {
|
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
const u =
|
|
181
|
+
const u = v(s);
|
|
182
182
|
Object.keys(u).length > 0 && (t[n] && typeof t[n] == "object" ? Object.assign(t[n], u) : t[n] || (t[n] = u));
|
|
183
183
|
}
|
|
184
184
|
return t;
|
|
185
185
|
}, F = (e = {}) => {
|
|
186
186
|
let t = {};
|
|
187
187
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
let r = c;
|
|
189
|
+
r?.ast?._tag === "Refinement" && r?.from && (r = r.from);
|
|
190
|
+
const n = r.make(e);
|
|
191
|
+
t = S.encodeSync(A(r))(n);
|
|
190
192
|
} catch (r) {
|
|
191
193
|
window.location.hostname === "localhost" && console.warn("schema.make() failed, extracting defaults from AST:", r);
|
|
192
194
|
try {
|
|
193
|
-
const n =
|
|
194
|
-
t =
|
|
195
|
+
const n = v(c);
|
|
196
|
+
t = S.encodeSync(A(c))(n);
|
|
195
197
|
} catch (n) {
|
|
196
198
|
window.location.hostname === "localhost" && console.warn("Could not extract defaults from AST:", n);
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
|
-
return
|
|
200
|
-
}, x =
|
|
201
|
+
return h(t, e);
|
|
202
|
+
}, x = V(() => {
|
|
201
203
|
let e;
|
|
202
204
|
const t = o?.persistency;
|
|
203
205
|
if (
|
|
@@ -218,20 +220,20 @@ const U = (l) => function(o) {
|
|
|
218
220
|
if (t?.policies && t.policies.includes("querystring"))
|
|
219
221
|
try {
|
|
220
222
|
const n = new URLSearchParams(window.location.search).get(d.value);
|
|
221
|
-
k(), n && (e =
|
|
223
|
+
k(), n && (e = h(e || {}, JSON.parse(n)));
|
|
222
224
|
} catch (r) {
|
|
223
225
|
console.error(r);
|
|
224
226
|
}
|
|
225
227
|
return e ??= {}, F(
|
|
226
|
-
o?.persistency?.overrideDefaultValues ?
|
|
228
|
+
o?.persistency?.overrideDefaultValues ? h(i?.defaultValues || {}, e) : h(e, i?.defaultValues || {})
|
|
227
229
|
);
|
|
228
|
-
}),
|
|
230
|
+
}), w = (e, t) => e ? T.with(q.setSpan(T.active(), e), t) : t(), a = z({
|
|
229
231
|
...i,
|
|
230
232
|
validators: {
|
|
231
233
|
onSubmit: p,
|
|
232
234
|
...i?.validators || {}
|
|
233
235
|
},
|
|
234
|
-
onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) =>
|
|
236
|
+
onSubmit: i?.onSubmit ? ({ formApi: e, meta: t, value: r }) => w(t?.currentSpan, async () => {
|
|
235
237
|
const n = await b.runPromise(f(r)), s = i.onSubmit({
|
|
236
238
|
formApi: e,
|
|
237
239
|
meta: t,
|
|
@@ -248,19 +250,19 @@ const U = (l) => function(o) {
|
|
|
248
250
|
}) : void 0,
|
|
249
251
|
defaultValues: x.value
|
|
250
252
|
}), y = () => {
|
|
251
|
-
Object.keys(
|
|
253
|
+
Object.keys(l).forEach((e) => {
|
|
252
254
|
a.setFieldValue(e, void 0);
|
|
253
255
|
});
|
|
254
|
-
},
|
|
256
|
+
}, _ = (e) => e.reduce((t, r) => {
|
|
255
257
|
const n = r.split(".");
|
|
256
258
|
return n.reduce((s, u, m) => (m === n.length - 1 ? s[u] = a.getFieldValue(r) : s[u] = s[u] ?? {}, s[u]), t), t;
|
|
257
259
|
}, {}), j = (e) => {
|
|
258
260
|
if (e) {
|
|
259
261
|
if (g.isArray(e.keys))
|
|
260
|
-
return
|
|
262
|
+
return _(e.keys);
|
|
261
263
|
if (g.isArray(e.banKeys)) {
|
|
262
|
-
const t = Object.keys(
|
|
263
|
-
return
|
|
264
|
+
const t = Object.keys(l).filter((r) => e.banKeys?.includes(r));
|
|
265
|
+
return _(t);
|
|
264
266
|
}
|
|
265
267
|
return a.store.state.values;
|
|
266
268
|
}
|
|
@@ -305,10 +307,10 @@ const U = (l) => function(o) {
|
|
|
305
307
|
}))) : N(e?.meta), G = a.handleSubmit, L = ee(/* @__PURE__ */ new Map()), E = Object.assign(a, {
|
|
306
308
|
i18nNamespace: o?.i18nNamespace,
|
|
307
309
|
ignorePreventCloseEvents: o?.ignorePreventCloseEvents,
|
|
308
|
-
meta:
|
|
310
|
+
meta: l,
|
|
309
311
|
clear: y,
|
|
310
312
|
handleSubmit: (e) => {
|
|
311
|
-
const t = q.getSpan(
|
|
313
|
+
const t = q.getSpan(T.active());
|
|
312
314
|
return G({ currentSpan: t, ...e });
|
|
313
315
|
},
|
|
314
316
|
// /** @experimental */
|
|
@@ -322,16 +324,16 @@ const U = (l) => function(o) {
|
|
|
322
324
|
_paths: void 0,
|
|
323
325
|
_keys: void 0,
|
|
324
326
|
errorContext: R,
|
|
325
|
-
Form:
|
|
326
|
-
Input:
|
|
327
|
-
TaggedUnion:
|
|
327
|
+
Form: M(E)(ae),
|
|
328
|
+
Input: M(E)(o?.input ?? oe),
|
|
329
|
+
TaggedUnion: M(E)(ie),
|
|
328
330
|
Field: a.Field,
|
|
329
331
|
Errors: ce(R)(ne),
|
|
330
|
-
Array:
|
|
331
|
-
AutoGen:
|
|
332
|
+
Array: M(E)(te),
|
|
333
|
+
AutoGen: M(E)(re)
|
|
332
334
|
});
|
|
333
335
|
};
|
|
334
336
|
export {
|
|
335
337
|
le as FormErrors,
|
|
336
|
-
|
|
338
|
+
_e as useOmegaForm
|
|
337
339
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S as n, Option as L } from "effect-app";
|
|
2
|
-
import { getMetadataFromSchema as
|
|
3
|
-
import { useIntl as N, getTransformationFrom as
|
|
4
|
-
const
|
|
2
|
+
import { getMetadataFromSchema as q } from "@effect-app/vue/form";
|
|
3
|
+
import { useIntl as N, getTransformationFrom as w } from "./vue-components.es3.js";
|
|
4
|
+
const k = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKeyword" || i === n.Null.ast), g = (e) => !e || !n.AST.isUnion(e) ? !1 : e.types.find((i) => i._tag === "UndefinedKeyword") ? "undefined" : e.types.find((i) => i === n.Null.ast) ? "null" : !1, _ = (e) => {
|
|
5
5
|
const i = [];
|
|
6
6
|
for (const t of e)
|
|
7
7
|
if (n.AST.isUnion(t)) {
|
|
@@ -24,14 +24,14 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
24
24
|
});
|
|
25
25
|
if (c) {
|
|
26
26
|
for (const r of c) {
|
|
27
|
-
const p = i ? `${i}.${r.name.toString()}` : r.name.toString(), s =
|
|
27
|
+
const p = i ? `${i}.${r.name.toString()}` : r.name.toString(), s = g(r.type);
|
|
28
28
|
let a;
|
|
29
29
|
e._isNullableDiscriminatedUnion && r.name.toString() === "_tag" || e.required === !1 ? a = !1 : a = !s;
|
|
30
30
|
const f = r.type;
|
|
31
31
|
if (n.AST.isUnion(r.type)) {
|
|
32
32
|
const S = _(r.type.types).filter(
|
|
33
33
|
(l) => l._tag !== "UndefinedKeyword" && l !== n.Null.ast
|
|
34
|
-
).map(
|
|
34
|
+
).map(w);
|
|
35
35
|
if (S.some(
|
|
36
36
|
(l) => "propertySignatures" in l
|
|
37
37
|
)) {
|
|
@@ -68,28 +68,28 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
68
68
|
}, m.rest && m.rest.length > 0) {
|
|
69
69
|
const T = m.rest[0];
|
|
70
70
|
if (T.type._tag === "TypeLiteral" && "propertySignatures" in T.type)
|
|
71
|
-
for (const
|
|
72
|
-
const h = `${p}.${
|
|
71
|
+
for (const d of T.type.propertySignatures) {
|
|
72
|
+
const h = `${p}.${d.name.toString()}`, v = u({
|
|
73
73
|
parent: h,
|
|
74
|
-
property:
|
|
74
|
+
property: d.type,
|
|
75
75
|
meta: {
|
|
76
|
-
required: !d
|
|
77
|
-
nullableOrUndefined: d
|
|
76
|
+
required: !g(d.type),
|
|
77
|
+
nullableOrUndefined: g(d.type)
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
if (v && typeof v == "object" && "type" in v && (o[h] = v, v.type === "multiple" && n.AST.isTupleType(
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
for (const x of
|
|
84
|
-
const A = `${h}.${x.name.toString()}`,
|
|
80
|
+
if (v && typeof v == "object" && "type" in v && (o[h] = v, v.type === "multiple" && n.AST.isTupleType(d.type) && d.type.rest && d.type.rest.length > 0)) {
|
|
81
|
+
const O = d.type.rest[0];
|
|
82
|
+
if (O.type._tag === "TypeLiteral" && "propertySignatures" in O.type)
|
|
83
|
+
for (const x of O.type.propertySignatures) {
|
|
84
|
+
const A = `${h}.${x.name.toString()}`, U = u({
|
|
85
85
|
parent: A,
|
|
86
86
|
property: x.type,
|
|
87
87
|
meta: {
|
|
88
|
-
required: !
|
|
89
|
-
nullableOrUndefined:
|
|
88
|
+
required: !g(x.type),
|
|
89
|
+
nullableOrUndefined: g(x.type)
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
|
-
|
|
92
|
+
U && typeof U == "object" && "type" in U && (o[A] = U);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -122,31 +122,31 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
122
122
|
const m = y.type.rest[0].type;
|
|
123
123
|
if (m._tag === "TypeLiteral" && "propertySignatures" in m)
|
|
124
124
|
for (const T of m.propertySignatures) {
|
|
125
|
-
const
|
|
126
|
-
parent:
|
|
125
|
+
const d = `${l}.${T.name.toString()}`, h = u({
|
|
126
|
+
parent: d,
|
|
127
127
|
property: T.type,
|
|
128
128
|
meta: {
|
|
129
|
-
required: !
|
|
130
|
-
nullableOrUndefined:
|
|
129
|
+
required: !g(T.type),
|
|
130
|
+
nullableOrUndefined: g(T.type)
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
|
-
o[
|
|
133
|
+
o[d] = h;
|
|
134
134
|
}
|
|
135
135
|
else
|
|
136
136
|
o[l] = {
|
|
137
137
|
type: "multiple",
|
|
138
138
|
members: y.type.elements,
|
|
139
139
|
rest: y.type.rest,
|
|
140
|
-
required: !
|
|
141
|
-
nullableOrUndefined:
|
|
140
|
+
required: !g(y.type),
|
|
141
|
+
nullableOrUndefined: g(y.type)
|
|
142
142
|
};
|
|
143
143
|
} else {
|
|
144
144
|
const m = u({
|
|
145
145
|
parent: l,
|
|
146
146
|
property: y.type,
|
|
147
147
|
meta: {
|
|
148
|
-
required: !
|
|
149
|
-
nullableOrUndefined:
|
|
148
|
+
required: !g(y.type),
|
|
149
|
+
nullableOrUndefined: g(y.type)
|
|
150
150
|
}
|
|
151
151
|
});
|
|
152
152
|
o[l] = m;
|
|
@@ -167,7 +167,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
167
167
|
meta: {
|
|
168
168
|
// an empty string is valid for a S.String field, so we should not mark it as required
|
|
169
169
|
// TODO: handle this better via the createMeta minLength parsing
|
|
170
|
-
required: a && (r.type._tag !== "StringKeyword" ||
|
|
170
|
+
required: a && (r.type._tag !== "StringKeyword" || q(r.type).minLength),
|
|
171
171
|
nullableOrUndefined: s
|
|
172
172
|
}
|
|
173
173
|
});
|
|
@@ -177,7 +177,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
177
177
|
return o;
|
|
178
178
|
}
|
|
179
179
|
if (t) {
|
|
180
|
-
const r =
|
|
180
|
+
const r = k(t);
|
|
181
181
|
if (Object.hasOwnProperty.call(e, "required") || (e.required = !r), n.AST.isUnion(t)) {
|
|
182
182
|
const s = _(t.types), a = s.find(
|
|
183
183
|
(f) => f._tag !== "UndefinedKeyword" && f !== n.Null.ast
|
|
@@ -222,12 +222,12 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
222
222
|
), e);
|
|
223
223
|
}
|
|
224
224
|
return o;
|
|
225
|
-
},
|
|
225
|
+
}, M = (e) => {
|
|
226
226
|
const i = e.ast, t = {};
|
|
227
227
|
if (i._tag === "Transformation" || i._tag === "Refinement")
|
|
228
|
-
return
|
|
228
|
+
return M(n.make(i.from));
|
|
229
229
|
if (i._tag === "Union") {
|
|
230
|
-
const r = (i.types || []).filter((s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast).map(
|
|
230
|
+
const r = (i.types || []).filter((s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast).map(w);
|
|
231
231
|
if (r.every((s) => s._tag === "TypeLiteral" && "propertySignatures" in s) && r.length > 0) {
|
|
232
232
|
const s = [];
|
|
233
233
|
for (const a of r)
|
|
@@ -264,7 +264,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
264
264
|
}
|
|
265
265
|
return t;
|
|
266
266
|
}, P = (e) => n.extend(e, n.Struct({})), j = (e) => {
|
|
267
|
-
const i =
|
|
267
|
+
const i = M(e);
|
|
268
268
|
return { schema: e, meta: i };
|
|
269
269
|
}, F = (e) => {
|
|
270
270
|
const { trans: i } = N();
|
|
@@ -341,10 +341,12 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
341
341
|
case "boolean":
|
|
342
342
|
t = n.Boolean;
|
|
343
343
|
break;
|
|
344
|
-
// todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
|
|
345
344
|
case "unknown":
|
|
346
345
|
t = n.Unknown;
|
|
347
346
|
break;
|
|
347
|
+
default:
|
|
348
|
+
console.warn(`Unhandled field type: ${e}`), t = n.Unknown;
|
|
349
|
+
break;
|
|
348
350
|
}
|
|
349
351
|
return e.required ? t.pipe(
|
|
350
352
|
n.annotations({
|
|
@@ -356,7 +358,7 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
356
358
|
decode: (t) => t ?? i(),
|
|
357
359
|
encode: (t) => t
|
|
358
360
|
})
|
|
359
|
-
),
|
|
361
|
+
), E = [
|
|
360
362
|
"button",
|
|
361
363
|
"checkbox",
|
|
362
364
|
"color",
|
|
@@ -372,13 +374,13 @@ const E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKe
|
|
|
372
374
|
"text",
|
|
373
375
|
"time",
|
|
374
376
|
"url"
|
|
375
|
-
], R = (e) =>
|
|
377
|
+
], R = (e) => E.includes(e) ? e : "text";
|
|
376
378
|
export {
|
|
377
379
|
u as createMeta,
|
|
378
380
|
P as duplicateSchema,
|
|
379
381
|
F as generateInputStandardSchemaFromFieldMeta,
|
|
380
382
|
j as generateMetaFromSchema,
|
|
381
383
|
R as getInputType,
|
|
382
|
-
|
|
384
|
+
g as isNullableOrUndefined,
|
|
383
385
|
D as nullableInput
|
|
384
386
|
};
|
package/package.json
CHANGED
|
@@ -915,11 +915,16 @@ export const generateInputStandardSchemaFromFieldMeta = (
|
|
|
915
915
|
case "boolean":
|
|
916
916
|
schema = S.Boolean
|
|
917
917
|
break
|
|
918
|
-
// todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
|
|
919
918
|
|
|
920
919
|
case "unknown":
|
|
921
920
|
schema = S.Unknown
|
|
922
921
|
break
|
|
922
|
+
|
|
923
|
+
default:
|
|
924
|
+
// For any unhandled types, use Unknown schema to prevent undefined errors
|
|
925
|
+
console.warn(`Unhandled field type: ${meta}`)
|
|
926
|
+
schema = S.Unknown
|
|
927
|
+
break
|
|
923
928
|
}
|
|
924
929
|
if (!meta.required) {
|
|
925
930
|
schema = S.NullishOr(schema)
|
|
@@ -774,7 +774,7 @@ export const useOmegaForm = <
|
|
|
774
774
|
for (const [key, fieldSchema] of Object.entries(schemaObj.fields)) {
|
|
775
775
|
// Only fix fields that are undefined in the instance
|
|
776
776
|
if (instance[key] === undefined) {
|
|
777
|
-
const ast = (fieldSchema as any)
|
|
777
|
+
const ast = (fieldSchema as any)?.ast
|
|
778
778
|
const nullableOrUndefined = isNullableOrUndefined(ast)
|
|
779
779
|
if (nullableOrUndefined === "null") {
|
|
780
780
|
instance[key] = null
|
|
@@ -835,7 +835,7 @@ export const useOmegaForm = <
|
|
|
835
835
|
}
|
|
836
836
|
} else {
|
|
837
837
|
// TODO Should we put to null/undefined only leaves?
|
|
838
|
-
const ast = (fieldSchema as any)
|
|
838
|
+
const ast = (fieldSchema as any)?.ast
|
|
839
839
|
const nullableOrUndefined = isNullableOrUndefined(ast)
|
|
840
840
|
switch (nullableOrUndefined) {
|
|
841
841
|
case "null":
|
|
@@ -869,11 +869,16 @@ export const useOmegaForm = <
|
|
|
869
869
|
let result: Partial<From> = {}
|
|
870
870
|
|
|
871
871
|
try {
|
|
872
|
-
//
|
|
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
|
+
|
|
873
878
|
// First try to use schema.make() if available
|
|
874
879
|
// Note: Partial schemas don't have .make() method yet (https://github.com/Effect-TS/effect/issues/4222)
|
|
875
|
-
const decoded =
|
|
876
|
-
result = S.encodeSync(partialRecursive(
|
|
880
|
+
const decoded = schemaToUse.make(defaultValues)
|
|
881
|
+
result = S.encodeSync(partialRecursive(schemaToUse))(decoded)
|
|
877
882
|
} catch (error) {
|
|
878
883
|
// If make() fails, try to extract defaults from AST
|
|
879
884
|
if (window.location.hostname === "localhost") {
|