@effect-app/vue-components 2.10.5 → 2.10.7
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.
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +1 -0
- package/dist/vue-components.es10.js +126 -121
- package/dist/vue-components.es12.js +208 -205
- package/dist/vue-components.es6.js +32 -32
- package/package.json +3 -3
- package/src/components/OmegaForm/OmegaFormStuff.ts +12 -17
- package/src/components/OmegaForm/OmegaInput.vue +3 -17
- package/src/components/OmegaForm/useOmegaForm.ts +24 -1
|
@@ -25,6 +25,7 @@ export declare class FormErrors<From> extends FormErrors_base<{
|
|
|
25
25
|
}>;
|
|
26
26
|
}> {
|
|
27
27
|
}
|
|
28
|
+
export declare const useErrorLabel: (form: OF<any, any>) => (propsName: string) => string;
|
|
28
29
|
export type Policies = "local" | "session" | "querystring";
|
|
29
30
|
export type defaultValuesPriorityUnion = "tanstack" | "persistency" | "schema";
|
|
30
31
|
export type OmegaConfig<T> = {
|
|
@@ -1,233 +1,238 @@
|
|
|
1
1
|
import { useForm as B } from "@tanstack/vue-form";
|
|
2
|
-
import { Data as K, S as
|
|
2
|
+
import { Data as K, S as V, Effect as f, Fiber as $, Option as P, Array as F } from "effect-app";
|
|
3
3
|
import { runtimeFiberAsPromise as T } from "./vue-components.es17.js";
|
|
4
|
-
import { computed as
|
|
4
|
+
import { computed as x, onUnmounted as W, onMounted as z, onBeforeUnmount as G, watch as D, ref as Z, h as H } from "vue";
|
|
5
|
+
import { useIntl as Q } from "./vue-components.es3.js";
|
|
5
6
|
import X from "./vue-components.es18.js";
|
|
6
7
|
import Y from "./vue-components.es19.js";
|
|
7
|
-
import
|
|
8
|
-
import { generateMetaFromSchema as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import { trace as
|
|
13
|
-
import { context as
|
|
14
|
-
class
|
|
8
|
+
import C from "./vue-components.es20.js";
|
|
9
|
+
import { generateMetaFromSchema as ee, deepMerge as R, defaultsValueFromSchema as re } from "./vue-components.es12.js";
|
|
10
|
+
import te from "./vue-components.es6.js";
|
|
11
|
+
import se from "./vue-components.es8.js";
|
|
12
|
+
import ne from "./vue-components.es21.js";
|
|
13
|
+
import { trace as N } from "./vue-components.es22.js";
|
|
14
|
+
import { context as U } from "./vue-components.es23.js";
|
|
15
|
+
class oe extends K.TaggedError("FormErrors") {
|
|
15
16
|
}
|
|
16
|
-
const g = (
|
|
17
|
+
const g = (i) => function(n) {
|
|
17
18
|
return {
|
|
18
19
|
render() {
|
|
19
20
|
return H(n, {
|
|
20
|
-
form:
|
|
21
|
+
form: i,
|
|
21
22
|
...this.$attrs
|
|
22
23
|
}, this.$slots);
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
|
-
},
|
|
26
|
+
}, ie = (i) => {
|
|
27
|
+
const { formatMessage: l } = Q(), n = (a) => a.replace(/([A-Z])/g, " $1").replace(/^./, (d) => d.toUpperCase()).trim(), m = (a) => l ? l({ id: `general.fields.${a}`, defaultMessage: n(a) }) : n(a);
|
|
28
|
+
return (a) => i.i18nNamespace ? l({ id: `${i.i18nNamespace}.fields.${a}`, defaultMessage: m(a) }) : m(a);
|
|
29
|
+
}, ae = (i) => function(n) {
|
|
26
30
|
return {
|
|
27
31
|
setup() {
|
|
28
|
-
const { fieldMap:
|
|
29
|
-
const
|
|
30
|
-
Object.entries(
|
|
31
|
-
([
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
const
|
|
35
|
-
return
|
|
36
|
-
label:
|
|
37
|
-
inputId:
|
|
32
|
+
const { fieldMap: m, form: p } = i, a = p.useStore((s) => s.errors), d = p.useStore((s) => s.fieldMeta), M = p.useStore((s) => s.errorMap), j = ie(p), A = x(() => {
|
|
33
|
+
const s = F.filterMap(
|
|
34
|
+
Object.entries(d.value),
|
|
35
|
+
([E, v]) => {
|
|
36
|
+
const h = v.errors ?? [];
|
|
37
|
+
if (!h.length) return P.none();
|
|
38
|
+
const u = m.value.get(E);
|
|
39
|
+
return u ? P.some({
|
|
40
|
+
label: u.label,
|
|
41
|
+
inputId: u.id,
|
|
38
42
|
// Only show the first error
|
|
39
|
-
errors: [
|
|
43
|
+
errors: [h[0]?.message].filter(Boolean)
|
|
40
44
|
}) : P.none();
|
|
41
45
|
}
|
|
42
|
-
),
|
|
46
|
+
), O = [];
|
|
43
47
|
if (M.value.onSubmit) {
|
|
44
|
-
for (const [
|
|
45
|
-
if (F.isArray(
|
|
46
|
-
for (const
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
51
|
-
|
|
52
|
-
label:
|
|
53
|
-
inputId:
|
|
54
|
-
errors: [
|
|
48
|
+
for (const [E, v] of Object.entries(M.value.onSubmit))
|
|
49
|
+
if (F.isArray(v) && v.length)
|
|
50
|
+
for (const h of v) {
|
|
51
|
+
const u = h;
|
|
52
|
+
if (u?.path && F.isArray(u.path) && u.path.length) {
|
|
53
|
+
const y = u.path.join(".");
|
|
54
|
+
if (!m.value.has(y)) {
|
|
55
|
+
O.push({
|
|
56
|
+
label: j(y),
|
|
57
|
+
inputId: y,
|
|
58
|
+
errors: [u.message].filter(Boolean)
|
|
55
59
|
});
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
|
-
return [...
|
|
65
|
+
return [...s, ...O];
|
|
62
66
|
});
|
|
63
67
|
return {
|
|
64
|
-
generalErrors:
|
|
65
|
-
errors:
|
|
68
|
+
generalErrors: a,
|
|
69
|
+
errors: A
|
|
66
70
|
};
|
|
67
71
|
},
|
|
68
|
-
render({ errors:
|
|
72
|
+
render({ errors: m, generalErrors: p }) {
|
|
69
73
|
return H(n, {
|
|
70
|
-
errors:
|
|
71
|
-
generalErrors:
|
|
74
|
+
errors: m,
|
|
75
|
+
generalErrors: p,
|
|
72
76
|
...this.$attrs
|
|
73
77
|
}, this.$slots);
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
|
-
},
|
|
77
|
-
if (!
|
|
78
|
-
const
|
|
80
|
+
}, b = (i, l) => i.includes(l), ge = (i, l, n) => {
|
|
81
|
+
if (!i) throw new Error("Schema is required");
|
|
82
|
+
const m = V.standardSchemaV1(i), p = V.decode(i), { meta: a } = ee(i), d = x(() => {
|
|
79
83
|
if (n?.persistency?.id)
|
|
80
84
|
return n.persistency.id;
|
|
81
|
-
const e = window.location.pathname, r = Object.keys(
|
|
85
|
+
const e = window.location.pathname, r = Object.keys(a);
|
|
82
86
|
return `${e}-${r.join("-")}`;
|
|
83
87
|
}), M = () => {
|
|
84
88
|
const e = new URLSearchParams(window.location.search);
|
|
85
|
-
e.delete(
|
|
89
|
+
e.delete(d.value);
|
|
86
90
|
const r = new URL(window.location.href);
|
|
87
91
|
r.search = e.toString(), window.history.replaceState({}, "", r.toString());
|
|
88
|
-
}, j =
|
|
92
|
+
}, j = x(() => {
|
|
89
93
|
let e;
|
|
90
94
|
const r = n?.persistency;
|
|
91
95
|
if (
|
|
92
96
|
// query string has higher priority than local/session storage
|
|
93
|
-
r?.policies && !e && (
|
|
97
|
+
r?.policies && !e && (b(r.policies, "local") || b(r.policies, "session"))
|
|
94
98
|
) {
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
99
|
+
const o = b(r.policies, "local") ? localStorage : sessionStorage;
|
|
100
|
+
if (o)
|
|
97
101
|
try {
|
|
98
102
|
const t = JSON.parse(
|
|
99
|
-
|
|
103
|
+
o.getItem(d.value) || "{}"
|
|
100
104
|
);
|
|
101
|
-
|
|
105
|
+
o.removeItem(d.value), e = t;
|
|
102
106
|
} catch (t) {
|
|
103
107
|
console.error(t);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
|
-
if (r?.policies &&
|
|
110
|
+
if (r?.policies && b(r.policies, "querystring"))
|
|
107
111
|
try {
|
|
108
|
-
const t = new URLSearchParams(window.location.search).get(
|
|
109
|
-
M(), t && (e =
|
|
110
|
-
} catch (
|
|
111
|
-
console.error(
|
|
112
|
+
const t = new URLSearchParams(window.location.search).get(d.value);
|
|
113
|
+
M(), t && (e = R(e || {}, JSON.parse(t)));
|
|
114
|
+
} catch (o) {
|
|
115
|
+
console.error(o);
|
|
112
116
|
}
|
|
113
117
|
e ??= {};
|
|
114
|
-
const
|
|
115
|
-
tanstack:
|
|
118
|
+
const c = {
|
|
119
|
+
tanstack: l?.defaultValues || {},
|
|
116
120
|
persistency: e,
|
|
117
|
-
schema:
|
|
121
|
+
schema: re(i)
|
|
118
122
|
};
|
|
119
123
|
return (n?.defaultValuesPriority || ["tanstack", "persistency", "schema"]).reverse().reduce(
|
|
120
|
-
(
|
|
124
|
+
(o, t) => Object.keys(o).length ? R(o, c[t]) : c[t],
|
|
121
125
|
{}
|
|
122
126
|
);
|
|
123
|
-
}),
|
|
124
|
-
...
|
|
127
|
+
}), A = (e, r) => e ? U.with(N.setSpan(U.active(), e), r) : r(), s = B({
|
|
128
|
+
...l,
|
|
125
129
|
validators: {
|
|
126
|
-
onSubmit:
|
|
127
|
-
...
|
|
130
|
+
onSubmit: m,
|
|
131
|
+
...l?.validators || {}
|
|
128
132
|
},
|
|
129
|
-
onSubmit:
|
|
130
|
-
const
|
|
133
|
+
onSubmit: l?.onSubmit ? ({ formApi: e, meta: r, value: c }) => A(r?.currentSpan, async () => {
|
|
134
|
+
const o = await f.runPromise(p(c)), t = l.onSubmit({
|
|
131
135
|
formApi: e,
|
|
132
136
|
meta: r,
|
|
133
|
-
value:
|
|
137
|
+
value: o
|
|
134
138
|
});
|
|
135
|
-
return
|
|
139
|
+
return $.isFiber(t) && $.isRuntimeFiber(t) ? await T(t) : f.isEffect(t) ? await f.runPromise(
|
|
136
140
|
t.pipe(
|
|
137
141
|
// meta?.currentSpan
|
|
138
142
|
// ? Effect.withParentSpan(meta.currentSpan)
|
|
139
143
|
// : (_) => _,
|
|
140
|
-
|
|
144
|
+
f.flatMap((S) => $.join(S))
|
|
141
145
|
)
|
|
142
146
|
) : t;
|
|
143
147
|
}) : void 0,
|
|
144
148
|
defaultValues: j.value
|
|
145
149
|
}), O = () => {
|
|
146
|
-
Object.keys(
|
|
147
|
-
|
|
150
|
+
Object.keys(a).forEach((e) => {
|
|
151
|
+
s.setFieldValue(e, void 0);
|
|
148
152
|
});
|
|
149
|
-
},
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
}, {}),
|
|
153
|
+
}, E = (e) => e.reduce((r, c) => {
|
|
154
|
+
const o = c.split(".");
|
|
155
|
+
return o.reduce((t, S, _) => (_ === o.length - 1 ? t[S] = s.getFieldValue(c) : t[S] = t[S] ?? {}, t[S]), r), r;
|
|
156
|
+
}, {}), v = (e) => {
|
|
153
157
|
if (e) {
|
|
154
158
|
if (F.isArray(e.keys))
|
|
155
|
-
return
|
|
159
|
+
return E(e.keys);
|
|
156
160
|
if (F.isArray(e.banKeys)) {
|
|
157
|
-
const r = Object.keys(
|
|
158
|
-
return
|
|
161
|
+
const r = Object.keys(a).filter((c) => e.banKeys?.includes(c));
|
|
162
|
+
return E(r);
|
|
159
163
|
}
|
|
160
|
-
return
|
|
164
|
+
return s.store.state.values;
|
|
161
165
|
}
|
|
162
|
-
},
|
|
166
|
+
}, h = () => {
|
|
163
167
|
const e = n?.persistency;
|
|
164
|
-
if (!(!e?.policies || e.policies.length === 0) && (
|
|
165
|
-
const r =
|
|
168
|
+
if (!(!e?.policies || e.policies.length === 0) && (b(e.policies, "local") || b(e.policies, "session"))) {
|
|
169
|
+
const r = b(e.policies, "local") ? localStorage : sessionStorage;
|
|
166
170
|
if (!r) return;
|
|
167
|
-
const
|
|
168
|
-
return r.setItem(
|
|
171
|
+
const c = v(e);
|
|
172
|
+
return r.setItem(d.value, JSON.stringify(c));
|
|
169
173
|
}
|
|
170
|
-
},
|
|
174
|
+
}, u = () => {
|
|
171
175
|
const e = n?.persistency;
|
|
172
|
-
if (!(!e?.policies || e.policies.length === 0) &&
|
|
173
|
-
const r =
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
176
|
+
if (!(!e?.policies || e.policies.length === 0) && b(e.policies, "querystring")) {
|
|
177
|
+
const r = v(e), c = new URLSearchParams(window.location.search);
|
|
178
|
+
c.set(d.value, JSON.stringify(r));
|
|
179
|
+
const o = new URL(window.location.href);
|
|
180
|
+
o.search = c.toString(), window.history.replaceState({}, "", o.toString());
|
|
177
181
|
}
|
|
178
|
-
},
|
|
179
|
-
|
|
182
|
+
}, y = (e) => {
|
|
183
|
+
s.store.state.isDirty && e.preventDefault();
|
|
180
184
|
};
|
|
181
|
-
if (
|
|
182
|
-
window.addEventListener("beforeunload",
|
|
183
|
-
}),
|
|
184
|
-
window.removeEventListener("beforeunload",
|
|
185
|
+
if (W(h), z(() => {
|
|
186
|
+
window.addEventListener("beforeunload", h), window.addEventListener("blur", u), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.addEventListener("beforeunload", y);
|
|
187
|
+
}), G(() => {
|
|
188
|
+
window.removeEventListener("beforeunload", h), window.removeEventListener("blur", u), n?.preventWindowExit && n.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", y);
|
|
185
189
|
}), n?.preventWindowExit === "prevent-and-reset") {
|
|
186
|
-
const e =
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
const e = s.useStore((t) => t.isSubmitting), r = s.useStore((t) => t.submissionAttempts), c = s.useStore((t) => t.canSubmit), o = s.useStore((t) => t.values);
|
|
191
|
+
D([e, r], ([t, S], [_]) => {
|
|
192
|
+
_ && !t && S > 0 && c.value && s.reset(o.value);
|
|
189
193
|
});
|
|
190
194
|
}
|
|
191
|
-
const k = (e) =>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
(r) =>
|
|
195
|
+
const k = (e) => f.currentSpan.pipe(
|
|
196
|
+
f.option,
|
|
197
|
+
f.flatMap(
|
|
198
|
+
(r) => f.promise(() => s.handleSubmit(P.isSome(r) ? { currentSpan: r.value, ...e } : e))
|
|
195
199
|
)
|
|
196
|
-
), J = (e) => e?.checkErrors ? k(e?.meta).pipe(
|
|
197
|
-
const r =
|
|
200
|
+
), J = (e) => e?.checkErrors ? k(e?.meta).pipe(f.flatMap(f.fnUntraced(function* () {
|
|
201
|
+
const r = s.getAllErrors();
|
|
198
202
|
if (Object.keys(r.fields).length || r.form.errors.length)
|
|
199
|
-
return yield* new
|
|
200
|
-
}))) : k(e?.meta), q =
|
|
203
|
+
return yield* new oe({ form: r.form, fields: r.fields });
|
|
204
|
+
}))) : k(e?.meta), q = s.handleSubmit, L = Z(/* @__PURE__ */ new Map()), w = Object.assign(s, {
|
|
201
205
|
i18nNamespace: n?.i18nNamespace,
|
|
202
206
|
ignorePreventCloseEvents: n?.ignorePreventCloseEvents,
|
|
203
|
-
meta:
|
|
207
|
+
meta: a,
|
|
204
208
|
clear: O,
|
|
205
209
|
handleSubmit: (e) => {
|
|
206
|
-
const r =
|
|
210
|
+
const r = N.getSpan(U.active());
|
|
207
211
|
return q({ currentSpan: r, ...e });
|
|
208
212
|
},
|
|
209
213
|
// /** @experimental */
|
|
210
214
|
handleSubmitEffect: J,
|
|
211
215
|
registerField: (e) => {
|
|
212
|
-
|
|
216
|
+
D(e, (r) => L.value.set(r.name, { label: r.label, id: r.id }), { immediate: !0 }), W(() => L.value.delete(e.value.name));
|
|
213
217
|
}
|
|
214
|
-
}), I = { form: w, fieldMap:
|
|
218
|
+
}), I = { form: w, fieldMap: L };
|
|
215
219
|
return Object.assign(w, {
|
|
216
220
|
// Type-level properties for performance optimization (not used at runtime)
|
|
217
221
|
_paths: void 0,
|
|
218
222
|
_keys: void 0,
|
|
219
|
-
_schema:
|
|
223
|
+
_schema: i,
|
|
220
224
|
errorContext: I,
|
|
221
|
-
Form: g(w)(
|
|
222
|
-
Input: g(w)(n?.input ??
|
|
223
|
-
TaggedUnion: g(w)(
|
|
224
|
-
Field:
|
|
225
|
-
Errors:
|
|
225
|
+
Form: g(w)(ne),
|
|
226
|
+
Input: g(w)(n?.input ?? te),
|
|
227
|
+
TaggedUnion: g(w)(se),
|
|
228
|
+
Field: s.Field,
|
|
229
|
+
Errors: ae(I)(C),
|
|
226
230
|
Array: g(w)(X),
|
|
227
231
|
AutoGen: g(w)(Y)
|
|
228
232
|
});
|
|
229
233
|
};
|
|
230
234
|
export {
|
|
231
|
-
|
|
232
|
-
|
|
235
|
+
oe as FormErrors,
|
|
236
|
+
ie as useErrorLabel,
|
|
237
|
+
ge as useOmegaForm
|
|
233
238
|
};
|
|
@@ -1,270 +1,273 @@
|
|
|
1
|
-
import { S as
|
|
1
|
+
import { S as r, Option as q } from "effect-app";
|
|
2
2
|
import { getMetadataFromSchema as k } from "@effect-app/vue/form";
|
|
3
|
-
import { useIntl as V, getTransformationFrom as
|
|
3
|
+
import { useIntl as V, getTransformationFrom as _ } from "./vue-components.es3.js";
|
|
4
4
|
import { isObject as E } from "./vue-components.es16.js";
|
|
5
|
-
const $ = (e) =>
|
|
5
|
+
const $ = (e) => r.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKeyword" || n === r.Null.ast), g = (e) => !e || !r.AST.isUnion(e) ? !1 : e.types.find((n) => n._tag === "UndefinedKeyword") ? "undefined" : e.types.find((n) => n === r.Null.ast) ? "null" : !1, L = (e) => {
|
|
6
6
|
const n = [];
|
|
7
7
|
for (const t of e)
|
|
8
|
-
if (
|
|
9
|
-
const
|
|
10
|
-
n.push(...
|
|
8
|
+
if (r.AST.isUnion(t)) {
|
|
9
|
+
const p = L(t.types);
|
|
10
|
+
n.push(...p);
|
|
11
11
|
} else
|
|
12
12
|
n.push(t);
|
|
13
13
|
return n;
|
|
14
|
-
},
|
|
14
|
+
}, f = ({ meta: e = {}, parent: n = "", property: t, propertySignatures: p }, o = {}) => {
|
|
15
15
|
if (t && t._tag === "Transformation")
|
|
16
|
-
return
|
|
16
|
+
return f({
|
|
17
17
|
parent: n,
|
|
18
18
|
meta: e,
|
|
19
19
|
property: t.from
|
|
20
20
|
});
|
|
21
21
|
if (t?._tag === "TypeLiteral" && "propertySignatures" in t)
|
|
22
|
-
return
|
|
22
|
+
return f({
|
|
23
23
|
meta: e,
|
|
24
24
|
propertySignatures: t.propertySignatures
|
|
25
25
|
});
|
|
26
|
-
if (
|
|
27
|
-
for (const s of
|
|
28
|
-
const
|
|
26
|
+
if (p) {
|
|
27
|
+
for (const s of p) {
|
|
28
|
+
const i = n ? `${n}.${s.name.toString()}` : s.name.toString(), l = g(s.type);
|
|
29
29
|
let a;
|
|
30
|
-
e._isNullableDiscriminatedUnion && s.name.toString() === "_tag" || e.required === !1 ? a = !1 : a = !
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
(u) => u._tag !== "UndefinedKeyword" && u !==
|
|
35
|
-
).map(
|
|
36
|
-
if (
|
|
30
|
+
e._isNullableDiscriminatedUnion && s.name.toString() === "_tag" || e.required === !1 ? a = !1 : a = !l;
|
|
31
|
+
const m = s.type;
|
|
32
|
+
if (r.AST.isUnion(s.type)) {
|
|
33
|
+
const c = L(s.type.types).filter(
|
|
34
|
+
(u) => u._tag !== "UndefinedKeyword" && u !== r.Null.ast
|
|
35
|
+
).map(_);
|
|
36
|
+
if (c.some(
|
|
37
37
|
(u) => "propertySignatures" in u
|
|
38
38
|
)) {
|
|
39
|
-
if (!
|
|
40
|
-
const u =
|
|
41
|
-
parent:
|
|
39
|
+
if (!l) {
|
|
40
|
+
const u = f({
|
|
41
|
+
parent: i,
|
|
42
42
|
property: s.type,
|
|
43
|
-
meta: { required: a, nullableOrUndefined:
|
|
43
|
+
meta: { required: a, nullableOrUndefined: l }
|
|
44
44
|
});
|
|
45
|
-
o[
|
|
45
|
+
o[i] = u;
|
|
46
46
|
}
|
|
47
|
-
for (const u of
|
|
47
|
+
for (const u of c)
|
|
48
48
|
if ("propertySignatures" in u) {
|
|
49
|
-
const y =
|
|
49
|
+
const y = l && c.length > 1;
|
|
50
50
|
Object.assign(
|
|
51
51
|
o,
|
|
52
|
-
|
|
53
|
-
parent:
|
|
52
|
+
f({
|
|
53
|
+
parent: i,
|
|
54
54
|
propertySignatures: u.propertySignatures,
|
|
55
55
|
meta: y ? { _isNullableDiscriminatedUnion: !0 } : {}
|
|
56
56
|
})
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
59
|
} else {
|
|
60
|
-
const u =
|
|
60
|
+
const u = c.filter(r.AST.isTupleType);
|
|
61
61
|
if (u.length > 0) {
|
|
62
62
|
const y = u[0];
|
|
63
|
-
if (o[
|
|
63
|
+
if (o[i] = {
|
|
64
64
|
type: "multiple",
|
|
65
65
|
members: y.elements,
|
|
66
66
|
rest: y.rest,
|
|
67
67
|
required: a,
|
|
68
|
-
nullableOrUndefined:
|
|
68
|
+
nullableOrUndefined: l
|
|
69
69
|
}, y.rest && y.rest.length > 0) {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
for (const
|
|
73
|
-
const h = `${
|
|
70
|
+
const S = y.rest[0];
|
|
71
|
+
if (S.type._tag === "TypeLiteral" && "propertySignatures" in S.type)
|
|
72
|
+
for (const d of S.type.propertySignatures) {
|
|
73
|
+
const h = `${i}.${d.name.toString()}`, T = f({
|
|
74
74
|
parent: h,
|
|
75
|
-
property:
|
|
75
|
+
property: d.type,
|
|
76
76
|
meta: {
|
|
77
|
-
required: !g(
|
|
78
|
-
nullableOrUndefined: g(
|
|
77
|
+
required: !g(d.type),
|
|
78
|
+
nullableOrUndefined: g(d.type)
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
for (const A of
|
|
85
|
-
const
|
|
86
|
-
parent:
|
|
81
|
+
if (T && typeof T == "object" && "type" in T && (o[h] = T, T.type === "multiple" && r.AST.isTupleType(d.type) && d.type.rest && d.type.rest.length > 0)) {
|
|
82
|
+
const w = d.type.rest[0];
|
|
83
|
+
if (w.type._tag === "TypeLiteral" && "propertySignatures" in w.type)
|
|
84
|
+
for (const A of w.type.propertySignatures) {
|
|
85
|
+
const M = `${h}.${A.name.toString()}`, O = f({
|
|
86
|
+
parent: M,
|
|
87
87
|
property: A.type,
|
|
88
88
|
meta: {
|
|
89
89
|
required: !g(A.type),
|
|
90
90
|
nullableOrUndefined: g(A.type)
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
O && typeof O == "object" && "type" in O && (o[
|
|
93
|
+
O && typeof O == "object" && "type" in O && (o[M] = O);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
} else {
|
|
99
|
-
const y =
|
|
100
|
-
parent:
|
|
99
|
+
const y = f({
|
|
100
|
+
parent: i,
|
|
101
101
|
property: s.type,
|
|
102
|
-
meta: { required: a, nullableOrUndefined:
|
|
102
|
+
meta: { required: a, nullableOrUndefined: l }
|
|
103
103
|
});
|
|
104
|
-
o[
|
|
104
|
+
o[i] = y;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
} else
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const y =
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
107
|
+
} else {
|
|
108
|
+
const b = _(m);
|
|
109
|
+
if ("propertySignatures" in b)
|
|
110
|
+
Object.assign(
|
|
111
|
+
o,
|
|
112
|
+
f({
|
|
113
|
+
parent: i,
|
|
114
|
+
propertySignatures: b.propertySignatures,
|
|
115
|
+
meta: { required: a, nullableOrUndefined: l }
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
else if (r.AST.isTupleType(s.type))
|
|
119
|
+
if (s.type.rest.length > 0 && s.type.rest[0].type._tag === "TypeLiteral" && "propertySignatures" in s.type.rest[0].type) {
|
|
120
|
+
const v = s.type.rest[0].type;
|
|
121
|
+
if (v._tag === "TypeLiteral" && "propertySignatures" in v)
|
|
122
|
+
for (const u of v.propertySignatures) {
|
|
123
|
+
const y = `${i}.${u.name.toString()}`;
|
|
124
|
+
if (r.AST.isTupleType(u.type) && u.type.rest.length > 0) {
|
|
125
|
+
const S = u.type.rest[0].type;
|
|
126
|
+
if (S._tag === "TypeLiteral" && "propertySignatures" in S)
|
|
127
|
+
for (const d of S.propertySignatures) {
|
|
128
|
+
const h = `${y}.${d.name.toString()}`, T = f({
|
|
129
|
+
parent: h,
|
|
130
|
+
property: d.type,
|
|
131
|
+
meta: {
|
|
132
|
+
required: !g(d.type),
|
|
133
|
+
nullableOrUndefined: g(d.type)
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
o[h] = T;
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
o[y] = {
|
|
140
|
+
type: "multiple",
|
|
141
|
+
members: u.type.elements,
|
|
142
|
+
rest: u.type.rest,
|
|
143
|
+
required: !g(u.type),
|
|
144
|
+
nullableOrUndefined: g(u.type)
|
|
145
|
+
};
|
|
146
|
+
} else {
|
|
147
|
+
const S = f({
|
|
148
|
+
parent: y,
|
|
149
|
+
property: u.type,
|
|
150
|
+
meta: {
|
|
151
|
+
required: !g(u.type),
|
|
152
|
+
nullableOrUndefined: g(u.type)
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
o[y] = S;
|
|
156
|
+
}
|
|
154
157
|
}
|
|
158
|
+
} else
|
|
159
|
+
o[i] = {
|
|
160
|
+
type: "multiple",
|
|
161
|
+
members: s.type.elements,
|
|
162
|
+
rest: s.type.rest,
|
|
163
|
+
required: a,
|
|
164
|
+
nullableOrUndefined: l
|
|
165
|
+
};
|
|
166
|
+
else {
|
|
167
|
+
const c = f({
|
|
168
|
+
parent: i,
|
|
169
|
+
property: s.type,
|
|
170
|
+
meta: {
|
|
171
|
+
// an empty string is valid for a S.String field, so we should not mark it as required
|
|
172
|
+
// TODO: handle this better via the createMeta minLength parsing
|
|
173
|
+
required: a && (s.type._tag !== "StringKeyword" || k(s.type).minLength),
|
|
174
|
+
nullableOrUndefined: l
|
|
155
175
|
}
|
|
156
|
-
|
|
157
|
-
o[
|
|
158
|
-
|
|
159
|
-
members: s.type.elements,
|
|
160
|
-
rest: s.type.rest,
|
|
161
|
-
required: a,
|
|
162
|
-
nullableOrUndefined: p
|
|
163
|
-
};
|
|
164
|
-
else {
|
|
165
|
-
const T = m({
|
|
166
|
-
parent: r,
|
|
167
|
-
property: s.type,
|
|
168
|
-
meta: {
|
|
169
|
-
// an empty string is valid for a S.String field, so we should not mark it as required
|
|
170
|
-
// TODO: handle this better via the createMeta minLength parsing
|
|
171
|
-
required: a && (s.type._tag !== "StringKeyword" || k(s.type).minLength),
|
|
172
|
-
nullableOrUndefined: p
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
o[r] = T;
|
|
176
|
+
});
|
|
177
|
+
o[i] = c;
|
|
178
|
+
}
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
return o;
|
|
179
182
|
}
|
|
180
183
|
if (t) {
|
|
181
184
|
const s = $(t);
|
|
182
|
-
if (Object.hasOwnProperty.call(e, "required") || (e.required = !s),
|
|
183
|
-
const
|
|
184
|
-
(
|
|
185
|
+
if (Object.hasOwnProperty.call(e, "required") || (e.required = !s), r.AST.isUnion(t)) {
|
|
186
|
+
const l = L(t.types), a = l.find(
|
|
187
|
+
(m) => m._tag !== "UndefinedKeyword" && m !== r.Null.ast
|
|
185
188
|
);
|
|
186
|
-
return "propertySignatures" in a ?
|
|
189
|
+
return "propertySignatures" in a ? f({
|
|
187
190
|
propertySignatures: a.propertySignatures,
|
|
188
191
|
parent: n,
|
|
189
192
|
meta: e
|
|
190
|
-
}) :
|
|
193
|
+
}) : l.every(r.AST.isLiteral) ? {
|
|
191
194
|
...e,
|
|
192
195
|
type: "select",
|
|
193
|
-
members:
|
|
196
|
+
members: l.map((m) => m.literal)
|
|
194
197
|
} : {
|
|
195
198
|
...e,
|
|
196
|
-
...
|
|
199
|
+
...f({
|
|
197
200
|
parent: n,
|
|
198
201
|
meta: e,
|
|
199
202
|
property: a
|
|
200
203
|
})
|
|
201
204
|
};
|
|
202
205
|
}
|
|
203
|
-
if (
|
|
206
|
+
if (r.AST.isTupleType(t))
|
|
204
207
|
return {
|
|
205
208
|
...e,
|
|
206
209
|
type: "multiple",
|
|
207
210
|
members: t.elements,
|
|
208
211
|
rest: t.rest
|
|
209
212
|
};
|
|
210
|
-
const
|
|
213
|
+
const i = r.AST.getAnnotation(
|
|
211
214
|
t,
|
|
212
|
-
|
|
213
|
-
).pipe(
|
|
214
|
-
return e = { ...e, ...
|
|
215
|
+
r.AST.JSONSchemaAnnotationId
|
|
216
|
+
).pipe(q.getOrElse(() => ({})));
|
|
217
|
+
return e = { ...e, ...i }, "from" in t ? f({
|
|
215
218
|
parent: n,
|
|
216
219
|
meta: e,
|
|
217
220
|
property: t.from
|
|
218
|
-
}) : (e.type =
|
|
221
|
+
}) : (e.type = r.AST.getAnnotation(
|
|
219
222
|
t,
|
|
220
|
-
|
|
223
|
+
r.AST.TitleAnnotationId
|
|
221
224
|
).pipe(
|
|
222
|
-
|
|
225
|
+
q.getOrElse(() => "unknown")
|
|
223
226
|
), e);
|
|
224
227
|
}
|
|
225
228
|
return o;
|
|
226
229
|
}, N = (e) => {
|
|
227
|
-
const n = e.ast, t = {},
|
|
230
|
+
const n = e.ast, t = {}, p = {};
|
|
228
231
|
if (n._tag === "Transformation" || n._tag === "Refinement")
|
|
229
|
-
return N(
|
|
232
|
+
return N(r.make(n.from));
|
|
230
233
|
if (n._tag === "Union") {
|
|
231
|
-
const
|
|
232
|
-
if (
|
|
234
|
+
const i = (n.types || []).filter((a) => a._tag !== "UndefinedKeyword" && a !== r.Null.ast).map(_);
|
|
235
|
+
if (i.every((a) => a._tag === "TypeLiteral" && "propertySignatures" in a) && i.length > 0) {
|
|
233
236
|
const a = [];
|
|
234
|
-
for (const
|
|
235
|
-
if ("propertySignatures" in
|
|
236
|
-
const
|
|
237
|
-
(
|
|
237
|
+
for (const m of i)
|
|
238
|
+
if ("propertySignatures" in m) {
|
|
239
|
+
const b = m.propertySignatures.find(
|
|
240
|
+
(v) => v.name.toString() === "_tag"
|
|
238
241
|
);
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
propertySignatures:
|
|
242
|
+
b && r.AST.isLiteral(b.type) && a.push(b.type.literal);
|
|
243
|
+
const c = f({
|
|
244
|
+
propertySignatures: m.propertySignatures
|
|
242
245
|
});
|
|
243
|
-
Object.assign(t,
|
|
246
|
+
Object.assign(t, c);
|
|
244
247
|
}
|
|
245
248
|
return a.length > 0 && (t._tag = {
|
|
246
249
|
type: "select",
|
|
247
250
|
members: a,
|
|
248
251
|
required: !0
|
|
249
|
-
}), { meta: t, defaultValues:
|
|
252
|
+
}), { meta: t, defaultValues: p };
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
if ("propertySignatures" in n) {
|
|
253
|
-
const o =
|
|
256
|
+
const o = f({
|
|
254
257
|
propertySignatures: n.propertySignatures
|
|
255
258
|
});
|
|
256
|
-
if (Object.values(o).every((
|
|
257
|
-
return { meta: o, defaultValues:
|
|
258
|
-
const s = (
|
|
259
|
-
for (const a in
|
|
260
|
-
const
|
|
261
|
-
|
|
259
|
+
if (Object.values(o).every((i) => i && "type" in i))
|
|
260
|
+
return { meta: o, defaultValues: p };
|
|
261
|
+
const s = (i, l = "") => {
|
|
262
|
+
for (const a in i) {
|
|
263
|
+
const m = l ? `${l}.${a}` : a;
|
|
264
|
+
i[a] && typeof i[a] == "object" && "type" in i[a] ? t[m] = i[a] : i[a] && typeof i[a] == "object" && s(i[a], m);
|
|
262
265
|
}
|
|
263
266
|
};
|
|
264
267
|
s(o);
|
|
265
268
|
}
|
|
266
|
-
return { meta: t, defaultValues:
|
|
267
|
-
}, B = (e) =>
|
|
269
|
+
return { meta: t, defaultValues: p };
|
|
270
|
+
}, B = (e) => r.extend(e, r.Struct({})), J = (e) => {
|
|
268
271
|
const { meta: n } = N(e);
|
|
269
272
|
return { schema: e, meta: n };
|
|
270
273
|
}, z = (e) => {
|
|
@@ -272,48 +275,48 @@ const $ = (e) => i.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKe
|
|
|
272
275
|
let t;
|
|
273
276
|
switch (e.type) {
|
|
274
277
|
case "string":
|
|
275
|
-
t =
|
|
278
|
+
t = r.String.annotations({
|
|
276
279
|
message: () => n("validation.empty")
|
|
277
|
-
}), e.format === "email" && (t =
|
|
280
|
+
}), e.format === "email" && (t = r.compose(
|
|
278
281
|
t,
|
|
279
|
-
|
|
282
|
+
r.Email.annotations({
|
|
280
283
|
message: () => n("validation.email.invalid")
|
|
281
284
|
})
|
|
282
285
|
)), e.required && (t = t.annotations({
|
|
283
286
|
message: () => n("validation.empty")
|
|
284
|
-
}).pipe(
|
|
287
|
+
}).pipe(r.minLength(1)).annotations({
|
|
285
288
|
message: () => n("validation.empty")
|
|
286
|
-
})), typeof e.maxLength == "number" && (t = t.pipe(
|
|
289
|
+
})), typeof e.maxLength == "number" && (t = t.pipe(r.maxLength(e.maxLength)).annotations({
|
|
287
290
|
message: () => n("validation.string.maxLength", {
|
|
288
291
|
maxLength: e.maxLength
|
|
289
292
|
})
|
|
290
|
-
})), typeof e.minLength == "number" && (t = t.pipe(
|
|
293
|
+
})), typeof e.minLength == "number" && (t = t.pipe(r.minLength(e.minLength)).annotations({
|
|
291
294
|
message: () => n("validation.string.minLength", {
|
|
292
295
|
minLength: e.minLength
|
|
293
296
|
})
|
|
294
297
|
}));
|
|
295
298
|
break;
|
|
296
299
|
case "number":
|
|
297
|
-
t =
|
|
300
|
+
t = r.Number.annotations({
|
|
298
301
|
message: () => n("validation.empty")
|
|
299
302
|
}), e.required && t.annotations({
|
|
300
303
|
message: () => n("validation.empty")
|
|
301
|
-
}), typeof e.minimum == "number" && (t = t.pipe(
|
|
304
|
+
}), typeof e.minimum == "number" && (t = t.pipe(r.greaterThanOrEqualTo(e.minimum)).annotations({
|
|
302
305
|
message: () => n(e.minimum === 0 ? "validation.number.positive" : "validation.number.min", {
|
|
303
306
|
minimum: e.minimum,
|
|
304
307
|
isExclusive: !0
|
|
305
308
|
})
|
|
306
|
-
})), typeof e.maximum == "number" && (t = t.pipe(
|
|
309
|
+
})), typeof e.maximum == "number" && (t = t.pipe(r.lessThanOrEqualTo(e.maximum)).annotations({
|
|
307
310
|
message: () => n("validation.number.max", {
|
|
308
311
|
maximum: e.maximum,
|
|
309
312
|
isExclusive: !0
|
|
310
313
|
})
|
|
311
|
-
})), typeof e.exclusiveMinimum == "number" && (t = t.pipe(
|
|
314
|
+
})), typeof e.exclusiveMinimum == "number" && (t = t.pipe(r.greaterThan(e.exclusiveMinimum)).annotations({
|
|
312
315
|
message: () => n(e.exclusiveMinimum === 0 ? "validation.number.positive" : "validation.number.min", {
|
|
313
316
|
minimum: e.exclusiveMinimum,
|
|
314
317
|
isExclusive: !1
|
|
315
318
|
})
|
|
316
|
-
})), typeof e.exclusiveMaximum == "number" && (t = t.pipe(
|
|
319
|
+
})), typeof e.exclusiveMaximum == "number" && (t = t.pipe(r.lessThan(e.exclusiveMaximum)).annotations({
|
|
317
320
|
message: () => n("validation.number.max", {
|
|
318
321
|
maximum: e.exclusiveMaximum,
|
|
319
322
|
isExclusive: !1
|
|
@@ -321,7 +324,7 @@ const $ = (e) => i.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKe
|
|
|
321
324
|
}));
|
|
322
325
|
break;
|
|
323
326
|
case "select":
|
|
324
|
-
t =
|
|
327
|
+
t = r.Literal(...e.members).annotations({
|
|
325
328
|
message: () => ({
|
|
326
329
|
message: n("validation.not_a_valid", {
|
|
327
330
|
type: "select",
|
|
@@ -332,7 +335,7 @@ const $ = (e) => i.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKe
|
|
|
332
335
|
});
|
|
333
336
|
break;
|
|
334
337
|
case "multiple":
|
|
335
|
-
t =
|
|
338
|
+
t = r.Array(r.String).annotations({
|
|
336
339
|
message: () => n("validation.not_a_valid", {
|
|
337
340
|
type: "multiple",
|
|
338
341
|
message: e.members.join(", ")
|
|
@@ -340,22 +343,22 @@ const $ = (e) => i.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKe
|
|
|
340
343
|
});
|
|
341
344
|
break;
|
|
342
345
|
case "boolean":
|
|
343
|
-
t =
|
|
346
|
+
t = r.Boolean;
|
|
344
347
|
break;
|
|
345
348
|
case "unknown":
|
|
346
|
-
t =
|
|
349
|
+
t = r.Unknown;
|
|
347
350
|
break;
|
|
348
351
|
default:
|
|
349
|
-
console.warn(`Unhandled field type: ${e}`), t =
|
|
352
|
+
console.warn(`Unhandled field type: ${e}`), t = r.Unknown;
|
|
350
353
|
break;
|
|
351
354
|
}
|
|
352
355
|
return e.required ? t.pipe(
|
|
353
|
-
|
|
356
|
+
r.annotations({
|
|
354
357
|
message: () => n("validation.empty")
|
|
355
358
|
})
|
|
356
|
-
) : t =
|
|
357
|
-
}, C = (e, n) =>
|
|
358
|
-
|
|
359
|
+
) : t = r.NullishOr(t), r.standardSchemaV1(t);
|
|
360
|
+
}, C = (e, n) => r.NullOr(e).pipe(
|
|
361
|
+
r.transform(r.typeSchema(e), {
|
|
359
362
|
decode: (t) => t ?? n(),
|
|
360
363
|
encode: (t) => t
|
|
361
364
|
})
|
|
@@ -378,71 +381,71 @@ const $ = (e) => i.AST.isUnion(e) && e.types.find((n) => n._tag === "UndefinedKe
|
|
|
378
381
|
], G = (e) => K.includes(e) ? e : "text";
|
|
379
382
|
function j(e, n) {
|
|
380
383
|
const t = { ...e };
|
|
381
|
-
for (const
|
|
382
|
-
Array.isArray(n[
|
|
384
|
+
for (const p in n)
|
|
385
|
+
Array.isArray(n[p]) ? t[p] = n[p] : n[p] && E(n[p]) ? t[p] = j(t[p], n[p]) : t[p] = n[p];
|
|
383
386
|
return t;
|
|
384
387
|
}
|
|
385
|
-
function
|
|
388
|
+
function U(e) {
|
|
386
389
|
return e && "fields" in e && typeof e.fields == "object";
|
|
387
390
|
}
|
|
388
391
|
function F(e) {
|
|
389
392
|
return e && "members" in e && Array.isArray(e.members);
|
|
390
393
|
}
|
|
391
|
-
const
|
|
394
|
+
const x = (e, n = {}) => {
|
|
392
395
|
const t = e.ast;
|
|
393
396
|
if (t?.defaultValue)
|
|
394
397
|
return t.defaultValue();
|
|
395
398
|
if (g(e.ast) === "null")
|
|
396
399
|
return null;
|
|
397
400
|
if (g(e.ast) !== "undefined") {
|
|
398
|
-
if (
|
|
399
|
-
const
|
|
401
|
+
if (U(e)) {
|
|
402
|
+
const p = {};
|
|
400
403
|
for (const [o, s] of Object.entries(e.fields)) {
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
404
|
+
const i = s?.ast;
|
|
405
|
+
if (i?.defaultValue)
|
|
403
406
|
try {
|
|
404
|
-
|
|
407
|
+
p[o] = i.defaultValue();
|
|
405
408
|
continue;
|
|
406
409
|
} catch {
|
|
407
410
|
}
|
|
408
|
-
const
|
|
409
|
-
|
|
411
|
+
const l = x(s, n[o] || {});
|
|
412
|
+
l !== void 0 && (p[o] = l);
|
|
410
413
|
}
|
|
411
|
-
return { ...
|
|
414
|
+
return { ...p, ...n };
|
|
412
415
|
}
|
|
413
|
-
if (e?.from &&
|
|
414
|
-
return
|
|
416
|
+
if (e?.from && U(e.from))
|
|
417
|
+
return x(e.from, n);
|
|
415
418
|
if (F(e)) {
|
|
416
|
-
const
|
|
417
|
-
const a =
|
|
418
|
-
(!o[
|
|
419
|
+
const p = e.members.reduce((o, s) => (U(s) && Object.entries(s.fields).forEach(([i, l]) => {
|
|
420
|
+
const a = l.ast, m = o[i]?.ast;
|
|
421
|
+
(!o[i] || a?.defaultValue && !m?.defaultValue) && (o[i] = l);
|
|
419
422
|
}), o), {});
|
|
420
|
-
return Object.entries(
|
|
423
|
+
return Object.entries(p).reduce((o, [s, i]) => (o[s] = x(i, n[s] || {}), o), n);
|
|
421
424
|
}
|
|
422
425
|
if (Object.keys(n).length === 0)
|
|
423
426
|
switch (e.ast._tag) {
|
|
424
427
|
case "Refinement":
|
|
425
|
-
return
|
|
428
|
+
return x(r.make(e.ast.from), n);
|
|
426
429
|
case "Transformation": {
|
|
427
|
-
const
|
|
428
|
-
return
|
|
430
|
+
const p = r.make(e.ast.from);
|
|
431
|
+
return x(p, n);
|
|
429
432
|
}
|
|
430
433
|
case "TypeLiteral": {
|
|
431
|
-
const
|
|
434
|
+
const p = { ...n };
|
|
432
435
|
for (const o of t.propertySignatures) {
|
|
433
|
-
const s = o.name.toString(),
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
+
const s = o.name.toString(), i = o.type;
|
|
437
|
+
if (i._tag === "Transformation" && i.defaultValue) {
|
|
438
|
+
p[s] = i.defaultValue();
|
|
436
439
|
continue;
|
|
437
440
|
}
|
|
438
|
-
if (
|
|
439
|
-
|
|
441
|
+
if (i.defaultValue) {
|
|
442
|
+
p[s] = i.defaultValue();
|
|
440
443
|
continue;
|
|
441
444
|
}
|
|
442
|
-
const
|
|
443
|
-
a !== void 0 && (
|
|
445
|
+
const l = r.make(i), a = x(l, n[s] || {});
|
|
446
|
+
a !== void 0 && (p[s] = a);
|
|
444
447
|
}
|
|
445
|
-
return
|
|
448
|
+
return p;
|
|
446
449
|
}
|
|
447
450
|
case "StringKeyword":
|
|
448
451
|
return "";
|
|
@@ -452,9 +455,9 @@ const v = (e, n = {}) => {
|
|
|
452
455
|
}
|
|
453
456
|
};
|
|
454
457
|
export {
|
|
455
|
-
|
|
458
|
+
f as createMeta,
|
|
456
459
|
j as deepMerge,
|
|
457
|
-
|
|
460
|
+
x as defaultsValueFromSchema,
|
|
458
461
|
B as duplicateSchema,
|
|
459
462
|
z as generateInputStandardSchemaFromFieldMeta,
|
|
460
463
|
J as generateMetaFromSchema,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import B from "./vue-components.
|
|
5
|
-
const
|
|
1
|
+
import { defineComponent as y, computed as o, useAttrs as F, inject as $, createBlock as u, openBlock as i, resolveDynamicComponent as k, withCtx as m, createCommentVNode as A, mergeProps as M, unref as S, createSlots as w, renderSlot as f, normalizeProps as d, guardReactiveProps as c } from "vue";
|
|
2
|
+
import { generateInputStandardSchemaFromFieldMeta as P } from "./vue-components.es12.js";
|
|
3
|
+
import j from "./vue-components.es7.js";
|
|
4
|
+
import { useErrorLabel as B } from "./vue-components.es10.js";
|
|
5
|
+
const D = /* @__PURE__ */ y({
|
|
6
6
|
inheritAttrs: !1,
|
|
7
7
|
__name: "OmegaInput",
|
|
8
8
|
props: {
|
|
@@ -12,51 +12,51 @@ const U = /* @__PURE__ */ F({
|
|
|
12
12
|
name: {},
|
|
13
13
|
inputClass: {}
|
|
14
14
|
},
|
|
15
|
-
setup(
|
|
16
|
-
const e =
|
|
15
|
+
setup(a) {
|
|
16
|
+
const e = a, l = o(() => e.name), v = F(), p = o(() => {
|
|
17
17
|
if (e.inputClass !== null)
|
|
18
|
-
return e.inputClass !== void 0 ? e.inputClass :
|
|
19
|
-
}),
|
|
18
|
+
return e.inputClass !== void 0 ? e.inputClass : v.class;
|
|
19
|
+
}), n = $(
|
|
20
20
|
"getMetaFromArray",
|
|
21
21
|
null
|
|
22
|
-
),
|
|
23
|
-
if (!
|
|
22
|
+
), r = o(() => n?.value && n.value(e.name) ? n.value(l.value) : e.form.meta[l.value]), g = o(() => {
|
|
23
|
+
if (!r.value)
|
|
24
24
|
throw console.log(e.name, Object.keys(e.form.meta), e.form.meta), new Error("Meta is undefined");
|
|
25
|
-
return
|
|
26
|
-
}),
|
|
27
|
-
return (
|
|
28
|
-
name:
|
|
25
|
+
return P(r.value);
|
|
26
|
+
}), C = B(e.form);
|
|
27
|
+
return (t, E) => (i(), u(k(a.form.Field), {
|
|
28
|
+
name: a.name,
|
|
29
29
|
validators: {
|
|
30
|
-
onChange:
|
|
31
|
-
...
|
|
30
|
+
onChange: g.value,
|
|
31
|
+
...a.validators
|
|
32
32
|
}
|
|
33
33
|
}, {
|
|
34
|
-
default:
|
|
35
|
-
|
|
36
|
-
field:
|
|
37
|
-
state:
|
|
38
|
-
register:
|
|
39
|
-
label:
|
|
40
|
-
meta:
|
|
41
|
-
}),
|
|
42
|
-
default:
|
|
43
|
-
|
|
34
|
+
default: m(({ field: b, state: h }) => [
|
|
35
|
+
r.value ? (i(), u(j, M({ key: 0 }, { ...t.$attrs, ...t.$props, inputClass: p.value }, {
|
|
36
|
+
field: b,
|
|
37
|
+
state: h,
|
|
38
|
+
register: a.form.registerField,
|
|
39
|
+
label: a.label ?? S(C)(l.value),
|
|
40
|
+
meta: r.value
|
|
41
|
+
}), w({
|
|
42
|
+
default: m((s) => [
|
|
43
|
+
f(t.$slots, "default", d(c(s)))
|
|
44
44
|
]),
|
|
45
45
|
_: 2
|
|
46
46
|
}, [
|
|
47
|
-
|
|
47
|
+
t.$slots.label ? {
|
|
48
48
|
name: "label",
|
|
49
|
-
fn:
|
|
50
|
-
|
|
49
|
+
fn: m((s) => [
|
|
50
|
+
f(t.$slots, "label", d(c(s)))
|
|
51
51
|
]),
|
|
52
52
|
key: "0"
|
|
53
53
|
} : void 0
|
|
54
|
-
]), 1040, ["field", "state", "register", "label", "meta"])) :
|
|
54
|
+
]), 1040, ["field", "state", "register", "label", "meta"])) : A("", !0)
|
|
55
55
|
]),
|
|
56
56
|
_: 3
|
|
57
57
|
}, 8, ["name", "validators"]));
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
export {
|
|
61
|
-
|
|
61
|
+
D as default
|
|
62
62
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-app/vue-components",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.7",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@mdi/js": "^7.4.47",
|
|
6
6
|
"effect": "^3.19.3",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"highlight.js": "^11.11.1",
|
|
54
54
|
"mitt": "^3.0.1",
|
|
55
55
|
"vue3-highlightjs": "^1.0.5",
|
|
56
|
-
"
|
|
57
|
-
"effect-app": "
|
|
56
|
+
"effect-app": "3.15.0",
|
|
57
|
+
"@effect-app/vue": "2.93.5"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "pnpm build:run",
|
|
@@ -8,12 +8,6 @@ import { getTransformationFrom, useIntl } from "../../utils"
|
|
|
8
8
|
import { type OmegaFieldInternalApi } from "./InputProps"
|
|
9
9
|
import { type OF, type OmegaFormReturn } from "./useOmegaForm"
|
|
10
10
|
|
|
11
|
-
type Compute<T> =
|
|
12
|
-
& {
|
|
13
|
-
[K in keyof T]: T[K]
|
|
14
|
-
}
|
|
15
|
-
& {}
|
|
16
|
-
|
|
17
11
|
export type FieldPath<T> = unknown extends T ? string
|
|
18
12
|
// technically we cannot have primitive at the root
|
|
19
13
|
: T extends string | boolean | number | null | undefined | symbol | bigint ? ""
|
|
@@ -507,18 +501,19 @@ export const createMeta = <T = any>(
|
|
|
507
501
|
acc[key as NestedKeyOf<T>] = newMeta as FieldMeta
|
|
508
502
|
}
|
|
509
503
|
}
|
|
510
|
-
} else if ("propertySignatures" in typeToProcess) {
|
|
511
|
-
Object.assign(
|
|
512
|
-
acc,
|
|
513
|
-
createMeta<T>({
|
|
514
|
-
parent: key,
|
|
515
|
-
propertySignatures: typeToProcess.propertySignatures,
|
|
516
|
-
meta: { required: isRequired, nullableOrUndefined }
|
|
517
|
-
})
|
|
518
|
-
)
|
|
519
504
|
} else {
|
|
520
|
-
//
|
|
521
|
-
|
|
505
|
+
// Unwrap transformations (like ExtendedClass) to check for propertySignatures
|
|
506
|
+
const unwrappedTypeToProcess = getTransformationFrom(typeToProcess)
|
|
507
|
+
if ("propertySignatures" in unwrappedTypeToProcess) {
|
|
508
|
+
Object.assign(
|
|
509
|
+
acc,
|
|
510
|
+
createMeta<T>({
|
|
511
|
+
parent: key,
|
|
512
|
+
propertySignatures: unwrappedTypeToProcess.propertySignatures,
|
|
513
|
+
meta: { required: isRequired, nullableOrUndefined }
|
|
514
|
+
})
|
|
515
|
+
)
|
|
516
|
+
} else if (S.AST.isTupleType(p.type)) {
|
|
522
517
|
// Check if it has struct elements
|
|
523
518
|
const hasStructElements = p.type.rest.length > 0
|
|
524
519
|
&& p.type.rest[0].type._tag === "TypeLiteral"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
:field="field"
|
|
15
15
|
:state="state"
|
|
16
16
|
:register="form.registerField"
|
|
17
|
-
:label="label ??
|
|
17
|
+
:label="label ?? errori18n(propsName)"
|
|
18
18
|
:meta="meta"
|
|
19
19
|
>
|
|
20
20
|
<template
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
>
|
|
42
42
|
import { type DeepKeys } from "@tanstack/vue-form"
|
|
43
43
|
import { computed, inject, type Ref, useAttrs } from "vue"
|
|
44
|
-
import { useIntl } from "../../utils"
|
|
45
44
|
import { type FieldMeta, generateInputStandardSchemaFromFieldMeta, type OmegaInputPropsBase } from "./OmegaFormStuff"
|
|
46
45
|
import OmegaInternalInput from "./OmegaInternalInput.vue"
|
|
46
|
+
import { useErrorLabel } from "./useOmegaForm"
|
|
47
47
|
|
|
48
48
|
const props = defineProps<OmegaInputPropsBase<From, To, Name>>()
|
|
49
49
|
|
|
@@ -88,19 +88,5 @@ const schema = computed(() => {
|
|
|
88
88
|
return generateInputStandardSchemaFromFieldMeta(meta.value)
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
const
|
|
92
|
-
const humanize = (str: string) => {
|
|
93
|
-
return str
|
|
94
|
-
.replace(/([A-Z])/g, " $1") // Add space before capital letters
|
|
95
|
-
.replace(/^./, (char) => char.toUpperCase()) // Capitalize the first letter
|
|
96
|
-
.trim() // Remove leading/trailing spaces
|
|
97
|
-
}
|
|
98
|
-
const fallback = () =>
|
|
99
|
-
formatMessage
|
|
100
|
-
? formatMessage({ id: `general.fields.${propsName.value}`, defaultMessage: humanize(props.name) })
|
|
101
|
-
: humanize(props.name)
|
|
102
|
-
const i18n = () =>
|
|
103
|
-
props.form.i18nNamespace
|
|
104
|
-
? formatMessage({ id: `${props.form.i18nNamespace}.fields.${propsName.value}`, defaultMessage: fallback() })
|
|
105
|
-
: fallback()
|
|
91
|
+
const errori18n = useErrorLabel(props.form)
|
|
106
92
|
</script>
|
|
@@ -6,6 +6,7 @@ import { type DeepKeys, DeepValue, type FormAsyncValidateOrFn, type FormValidate
|
|
|
6
6
|
import { Array, Data, Effect, Fiber, Option, Order, S } from "effect-app"
|
|
7
7
|
import { runtimeFiberAsPromise, UnionToTuples } from "effect-app/utils"
|
|
8
8
|
import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from "vue"
|
|
9
|
+
import { useIntl } from "../../utils"
|
|
9
10
|
import { MergedInputProps } from "./InputProps"
|
|
10
11
|
import OmegaArray from "./OmegaArray.vue"
|
|
11
12
|
import OmegaAutoGen from "./OmegaAutoGen.vue"
|
|
@@ -63,6 +64,26 @@ const fHoc = (form: OF<any, any>) => {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
export const useErrorLabel = (form: OF<any, any>) => {
|
|
68
|
+
const { formatMessage } = useIntl()
|
|
69
|
+
const humanize = (str: string) => {
|
|
70
|
+
return str
|
|
71
|
+
.replace(/([A-Z])/g, " $1") // Add space before capital letters
|
|
72
|
+
.replace(/^./, (char) => char.toUpperCase()) // Capitalize the first letter
|
|
73
|
+
.trim() // Remove leading/trailing spaces
|
|
74
|
+
}
|
|
75
|
+
const fallback = (propsName: string) =>
|
|
76
|
+
formatMessage
|
|
77
|
+
? formatMessage({ id: `general.fields.${propsName}`, defaultMessage: humanize(propsName) })
|
|
78
|
+
: humanize(propsName)
|
|
79
|
+
const i18n = (propsName: string) =>
|
|
80
|
+
form.i18nNamespace
|
|
81
|
+
? formatMessage({ id: `${form.i18nNamespace}.fields.${propsName}`, defaultMessage: fallback(propsName) })
|
|
82
|
+
: fallback(propsName)
|
|
83
|
+
|
|
84
|
+
return i18n
|
|
85
|
+
}
|
|
86
|
+
|
|
66
87
|
const eHoc = (errorProps: {
|
|
67
88
|
form: OF<any, any>
|
|
68
89
|
fieldMap: Ref<Map<string, { id: string; label: string }>>
|
|
@@ -77,6 +98,8 @@ const eHoc = (errorProps: {
|
|
|
77
98
|
const fieldMeta = form.useStore((state) => state.fieldMeta)
|
|
78
99
|
const errorMap = form.useStore((state) => state.errorMap)
|
|
79
100
|
|
|
101
|
+
const errorLabel = useErrorLabel(form)
|
|
102
|
+
|
|
80
103
|
const errors = computed(() => {
|
|
81
104
|
// Collect errors from fieldMeta (field-level errors for registered fields)
|
|
82
105
|
const fieldErrors = Array.filterMap(
|
|
@@ -114,7 +137,7 @@ const eHoc = (errorProps: {
|
|
|
114
137
|
// Registered fields will already have their errors from fieldMeta
|
|
115
138
|
if (!fieldMap.value.has(fieldPath)) {
|
|
116
139
|
submitErrors.push({
|
|
117
|
-
label: fieldPath,
|
|
140
|
+
label: errorLabel(fieldPath),
|
|
118
141
|
inputId: fieldPath,
|
|
119
142
|
errors: [issAny.message].filter(Boolean)
|
|
120
143
|
})
|