@voltro/client 0.52.0 → 0.53.0

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/form.d.ts CHANGED
@@ -1,5 +1,17 @@
1
+ import { ParseResult } from 'effect';
1
2
  import { Schema } from 'effect';
2
3
 
4
+ /**
5
+ * Walk a ParseError's issue tree into structured, PATH-PRESERVING issues.
6
+ * Every leaf keeps its full path (`address.city`, `entries.0.startsAt`) —
7
+ * nothing collapses to the top-level segment.
8
+ */
9
+ export declare const decodeFieldIssues: (error: ParseResult.ParseError) => ReadonlyArray<FieldIssue>;
10
+
11
+ /** The document's locale per the framework contract (`<html lang>`); `'en'`
12
+ * outside a browser. Primary subtag only (`de-AT` → `de`). */
13
+ export declare const documentLocale: () => string;
14
+
3
15
  export declare interface FieldDescriptor {
4
16
  /** Property name on the input object. */
5
17
  readonly name: string;
@@ -16,17 +28,56 @@ export declare interface FieldDescriptor {
16
28
  /** The resolved JSON-Schema node — carries `maxLength` / `pattern` /
17
29
  * `minimum` / `format` / `description` for widgets + validation hints. */
18
30
  readonly jsonSchema: Readonly<Record<string, unknown>>;
31
+ /** Dotted parent path for a nested-struct member (`'address'` for
32
+ * `address.city`) — the SECTION a renderer groups it under. Top-level
33
+ * fields carry none. Overridable via `formField({ section })`. */
34
+ readonly section?: string;
35
+ /** Human label for the section (humanised path tail). */
36
+ readonly sectionLabel?: string;
37
+ /** Help text — the Schema `description` annotation. */
38
+ readonly description?: string;
39
+ /** Declared ordering (`formField({ order })`); fields sort by it, stable
40
+ * against declaration order. */
41
+ readonly order?: number;
42
+ /** For `widget: 'array'` (array of structs): the ITEM's field descriptors,
43
+ * names relative to one item (`startsAt`, not `entries.0.startsAt`). */
44
+ readonly item?: ReadonlyArray<FieldDescriptor>;
45
+ /** For `widget: 'reference'`: the referenced TABLE — a renderer binds a
46
+ * query-backed picker to it; the VALUE stays the id (or id list). Comes
47
+ * from `formField({ reference: 'stores' })`. */
48
+ readonly reference?: string;
19
49
  }
20
50
 
21
51
  export declare interface FieldErrors {
22
52
  readonly [field: string]: string;
23
53
  }
24
54
 
55
+ /** One structured validation issue. `path` is the dotted field path
56
+ * (`'email'`, `'address.city'`, `'entries.0.startsAt'`); `id` is the stable
57
+ * message id (`'validation.minLength'`); `params` feed its template;
58
+ * `fallback` is a rendered English default so an unknown id still shows a
59
+ * sentence, never a bare key. */
60
+ export declare interface FieldIssue {
61
+ readonly path: string;
62
+ readonly id: string;
63
+ readonly params?: Readonly<Record<string, unknown>>;
64
+ readonly fallback: string;
65
+ }
66
+
25
67
  export declare interface FieldOption {
26
68
  readonly value: string;
27
69
  readonly label: string;
28
70
  }
29
71
 
72
+ /** One display section of a form: `name` is the section path (`'address'`),
73
+ * `undefined` for the top-level run of unsectioned fields. Contiguous in
74
+ * display order, so a renderer can walk sections top to bottom. */
75
+ export declare interface FieldSection {
76
+ readonly name: string | undefined;
77
+ readonly label: string | undefined;
78
+ readonly fields: ReadonlyArray<FieldDescriptor>;
79
+ }
80
+
30
81
  /** DOM id of the JSON script the 422 re-render embeds (survives the
31
82
  * `interactive:'none'` strip — it is neither `type="module"` nor `src`). */
32
83
  export declare const FORM_FLASH_SCRIPT_ID = "__voltro_form_flash__";
@@ -68,6 +119,27 @@ export declare const formDataToInput: (schema: Schema.Schema.Any, entries: Itera
68
119
  * uploads are a declared limit of the no-JS path. */
69
120
  export declare type FormEntry = readonly [name: string, value: string];
70
121
 
122
+ /** UI metadata for one schema field, as an annotations object:
123
+ *
124
+ * Schema.String.annotations(formField({ section: 'contact', order: 2 }))
125
+ *
126
+ * Rides the JSON-Schema annotation (merged, not replaced — verified), so it
127
+ * survives the same normalisation every other descriptor fact does. */
128
+ export declare const formField: (meta: {
129
+ readonly label?: string;
130
+ readonly section?: string;
131
+ readonly order?: number;
132
+ readonly widget?: WidgetKind;
133
+ /** Mark the field a REFERENCE to a table: `formField({ reference: 'stores' })`
134
+ * → `widget: 'reference'` carrying the target, value = the id (or id
135
+ * list, for a multi-reference feeding a target's `relations:`). */
136
+ readonly reference?: string;
137
+ }) => {
138
+ readonly jsonSchema: {
139
+ readonly "x-voltro": typeof meta;
140
+ };
141
+ };
142
+
71
143
  /**
72
144
  * The error/values payload a failed no-JS form POST carries back into the
73
145
  * 422 re-render. Keyed by `formKey` so a page with several forms re-fills
@@ -87,6 +159,21 @@ export declare interface FormFlashPayload {
87
159
  readonly formError?: string;
88
160
  }
89
161
 
162
+ /**
163
+ * Group an ordered field list into contiguous sections — the structure a
164
+ * form (or its skeleton — the placeholder must have the SHAPE of the real
165
+ * thing, title rows included) renders. Pure; feeds `<FormSkeleton>`,
166
+ * `<AutoForm>` layouts and `form.section(...)` alike.
167
+ */
168
+ export declare const formSections: (fields: ReadonlyArray<FieldDescriptor>) => ReadonlyArray<FieldSection>;
169
+
170
+ /**
171
+ * Render one issue id to display text: app resolver first (its `undefined`
172
+ * falls through), then the built-in catalog for the locale's primary subtag,
173
+ * then English, then the issue's own fallback sentence.
174
+ */
175
+ export declare const resolveValidationMessage: (issue: Pick<FieldIssue, "id" | "params" | "fallback">, options?: ValidateOptions) => string;
176
+
90
177
  /**
91
178
  * Derive table COLUMNS from a query's output `Schema` — an
92
179
  * `Schema.Array(Schema.Struct({...}))`. Drills into the array's element and maps
@@ -103,25 +190,39 @@ export declare const schemaToColumns: (schema: Schema.Schema.Any) => ReadonlyArr
103
190
  export declare const schemaToFields: (schema: Schema.Schema.Any) => ReadonlyArray<FieldDescriptor>;
104
191
 
105
192
  /**
106
- * Validate `values` against an input `schema`, returning the first error per
107
- * top-level field (`{ [field]: message }`) the shape `<AutoForm>` and custom
108
- * widgets render inline. Uses the same `decodeUnknownEither` + `ArrayFormatter`
109
- * path the store's `.validate(...)` uses, so client and server speak ONE
110
- * schema. `{ errors: 'all' }` collects every field's error in one pass.
111
- *
112
- * Client-side validation is non-authoritative UX — the server re-validates the
113
- * same schema on the mutation; this just gives instant inline feedback.
193
+ * Validate `values` against an input `schema`. Uses the same
194
+ * `decodeUnknownEither` path the store's `.validate(...)` uses, so client and
195
+ * server speak ONE schema; `{ errors: 'all' }` collects every field in one
196
+ * pass. Client-side validation is non-authoritative UX the server
197
+ * re-validates the same schema on the mutation.
114
198
  */
115
- export declare const validateFields: (schema: Schema.Schema.Any, values: unknown) => ValidationResult;
199
+ export declare const validateFields: (schema: Schema.Schema.Any, values: unknown, options?: ValidateOptions) => ValidationResult;
200
+
201
+ export declare interface ValidateOptions {
202
+ /** BCP-47-ish tag; only the primary subtag is read. Default: the document's
203
+ * `<html lang>`, else `'en'`. */
204
+ readonly locale?: string;
205
+ readonly messages?: ValidationMessageResolver;
206
+ }
207
+
208
+ /** Resolve one message id to display text. Return `undefined` to fall through
209
+ * to the built-in en/de defaults — so a resolver only has to know the ids it
210
+ * overrides. Wire it to `@voltro/i18n` in one line:
211
+ * `messages: (id, params) => t(id, params)`. */
212
+ export declare type ValidationMessageResolver = (id: string, params: Readonly<Record<string, unknown>> | undefined, fallback: string) => string | undefined;
116
213
 
117
214
  export declare interface ValidationResult {
118
215
  readonly valid: boolean;
216
+ /** Display text per field path — what `<AutoForm>` and custom widgets
217
+ * render inline. First issue per field wins. */
119
218
  readonly errors: FieldErrors;
219
+ /** Every issue, structured — for widget kits that translate themselves. */
220
+ readonly issues: ReadonlyArray<FieldIssue>;
120
221
  }
121
222
 
122
223
  /** The default widget kinds the framework can render from a schema. `'custom'`
123
224
  * means "no default widget" — the field needs a render-prop (a nested object,
124
225
  * an array of objects, or a multi-branch union). Mirrors innovation/01's set. */
125
- export declare type WidgetKind = 'text' | 'textarea' | 'number' | 'checkbox' | 'switch' | 'select' | 'radio' | 'async-select' | 'multi-select' | 'date' | 'datetime' | 'daterange' | 'file' | 'hidden' | 'custom';
226
+ export declare type WidgetKind = 'text' | 'textarea' | 'number' | 'checkbox' | 'switch' | 'select' | 'radio' | 'async-select' | 'multi-select' | 'date' | 'datetime' | 'daterange' | 'file' | 'hidden' | 'array' | 'reference' | 'custom';
126
227
 
127
228
  export { }
package/dist/form.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./formData-Bw07C0wr.js";
2
- export { c as FORM_FLASH_SCRIPT_ID, i as FORM_KEY_FIELD, o as FORM_PATH_PREFIX, n as FORM_REDIRECT_FIELD, e as formActionPath, a as formDataToInput, t as schemaToColumns, r as schemaToFields, s as validateFields };
1
+ import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./formData-BO7zkG_F.js";
2
+ export { f as FORM_FLASH_SCRIPT_ID, s as FORM_KEY_FIELD, u as FORM_PATH_PREFIX, i as FORM_REDIRECT_FIELD, d as decodeFieldIssues, t as documentLocale, e as formActionPath, c as formDataToInput, n as formField, r as formSections, a as resolveValidationMessage, l as schemaToColumns, o as schemaToFields, p as validateFields };
@@ -0,0 +1,386 @@
1
+ import { JSONSchema as e, Schema as t } from "effect";
2
+ import * as n from "effect/SchemaAST";
3
+ //#region src/schemaFields.ts
4
+ var r = (e) => ({ jsonSchema: { "x-voltro": e } }), i = "#/$defs/", a = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), o = (e, t) => {
5
+ let n = e;
6
+ for (let e = 0; e < 8; e += 1) {
7
+ let e = n.$ref;
8
+ if (typeof e != "string" || !e.startsWith(i)) return n;
9
+ let r = t[e.slice(8)];
10
+ if (!r || typeof r != "object") return n;
11
+ n = r;
12
+ }
13
+ return n;
14
+ }, s = (e) => {
15
+ if (!e || typeof e != "object") return !1;
16
+ let t = e;
17
+ if (t.type === "null" || t.const === null) return !0;
18
+ let n = t.enum;
19
+ return Array.isArray(n) && n.length === 1 && n[0] === null;
20
+ }, c = (e, t) => {
21
+ let n = e.type;
22
+ if (Array.isArray(n) && n.includes("null")) {
23
+ let t = n.filter((e) => e !== "null");
24
+ return {
25
+ node: {
26
+ ...e,
27
+ type: t.length === 1 ? t[0] : t
28
+ },
29
+ nullable: !0
30
+ };
31
+ }
32
+ for (let n of ["anyOf", "oneOf"]) {
33
+ let r = e[n];
34
+ if (!Array.isArray(r)) continue;
35
+ let i = r.filter((e) => !s(e));
36
+ if (i.length !== r.length) return i.length === 1 ? {
37
+ node: o(i[0], t),
38
+ nullable: !0
39
+ } : {
40
+ node: {
41
+ ...e,
42
+ [n]: i
43
+ },
44
+ nullable: !0
45
+ };
46
+ }
47
+ return {
48
+ node: e,
49
+ nullable: !1
50
+ };
51
+ }, l = (e) => e.map((e) => ({
52
+ value: String(e),
53
+ label: a(String(e))
54
+ })), u = (e) => {
55
+ let t = e.enum;
56
+ if (Array.isArray(t) && t.length > 0) return {
57
+ widget: "select",
58
+ options: l(t)
59
+ };
60
+ let n = e.type, r = Array.isArray(n) ? n.find((e) => e !== "null") : n, i = e.format;
61
+ switch (r) {
62
+ case "string": return i === "date" ? { widget: "date" } : i === "date-time" ? { widget: "datetime" } : { widget: "text" };
63
+ case "integer":
64
+ case "number": return { widget: "number" };
65
+ case "boolean": return { widget: "checkbox" };
66
+ case "array": return { widget: "multi-select" };
67
+ default: return { widget: "custom" };
68
+ }
69
+ }, d = (e) => {
70
+ let t = e.$ref;
71
+ if (typeof t != "string" || !t.startsWith(i)) return;
72
+ let n = t.slice(8);
73
+ if (/DateTime/i.test(n) || /Timestamp/i.test(n)) return "datetime";
74
+ if (/Date/.test(n)) return "date";
75
+ }, f = (e) => typeof e["x-voltro"] == "object" && e["x-voltro"] !== null ? e["x-voltro"] : {}, p = 4, m = (e, t, n, r = "", i, s = 0) => Object.entries(e).flatMap(([e, l]) => {
76
+ let { node: h, nullable: g } = c(o(l, n), n), _ = o(h, n), v = f(_), y = r === "" ? e : `${r}.${e}`, b = _.properties;
77
+ if (_.type === "object" && b !== void 0 && s < p && v.widget === void 0) return m(b, new Set(Array.isArray(_.required) ? _.required : []), n, y, {
78
+ path: v.section ?? y,
79
+ label: v.label ?? a(e)
80
+ }, s + 1);
81
+ let x = d(l), { widget: S, options: C } = u(_);
82
+ x !== void 0 && (S = x);
83
+ let w;
84
+ if (_.type === "array") {
85
+ let e = _.items;
86
+ if (typeof e == "object" && e && !Array.isArray(e)) {
87
+ let t = o(e, n), r = t.properties;
88
+ t.type === "object" && r !== void 0 && (S = "array", w = m(r, new Set(Array.isArray(t.required) ? t.required : []), n));
89
+ }
90
+ }
91
+ v.widget !== void 0 && (S = v.widget), v.reference !== void 0 && v.widget === void 0 && (S = "reference");
92
+ let T = typeof _.description == "string" ? _.description : void 0, E = v.section ?? i?.path;
93
+ return [{
94
+ name: y,
95
+ label: v.label ?? a(e),
96
+ widget: S,
97
+ required: t.has(e),
98
+ nullable: g,
99
+ ...C ? { options: C } : {},
100
+ jsonSchema: _,
101
+ ...E === void 0 ? {} : {
102
+ section: E,
103
+ sectionLabel: i?.label ?? a(E)
104
+ },
105
+ ...T === void 0 ? {} : { description: T },
106
+ ...v.order === void 0 ? {} : { order: v.order },
107
+ ...w === void 0 ? {} : { item: w },
108
+ ...v.reference === void 0 ? {} : { reference: v.reference }
109
+ }];
110
+ }), h = (e) => e.map((e, t) => [e, t]).sort((e, t) => (e[0].order ?? e[1]) - (t[0].order ?? t[1]) || e[1] - t[1]).map(([e]) => e), g = (t) => {
111
+ try {
112
+ return e.make(t);
113
+ } catch {
114
+ return;
115
+ }
116
+ }, _ = (e) => {
117
+ let t = g(e);
118
+ if (t === void 0) return [];
119
+ let n = t.$defs ?? {}, r = o(t, n), i = r.properties;
120
+ return i ? h(m(i, new Set(Array.isArray(r.required) ? r.required : []), n)) : [];
121
+ }, v = (e) => {
122
+ let t = g(e);
123
+ if (t === void 0) return [];
124
+ let n = t.$defs ?? {}, r = o(t, n);
125
+ if (r.type !== "array") return [];
126
+ let i = r.items;
127
+ if (!i || typeof i != "object") return [];
128
+ let a = o(i, n), s = a.properties;
129
+ return s ? m(s, new Set(Array.isArray(a.required) ? a.required : []), n) : [];
130
+ }, y = (e) => {
131
+ let t = [];
132
+ for (let n of e) {
133
+ let e = t[t.length - 1];
134
+ if (e !== void 0 && e.name === n.section) {
135
+ e.fields.push(n);
136
+ continue;
137
+ }
138
+ t.push({
139
+ name: n.section,
140
+ label: n.sectionLabel,
141
+ fields: [n]
142
+ });
143
+ }
144
+ return t;
145
+ }, b = {
146
+ en: {
147
+ "validation.required": "Required",
148
+ "validation.invalid": "Invalid value",
149
+ "validation.minLength": "Must be at least {min} characters",
150
+ "validation.maxLength": "Must be at most {max} characters",
151
+ "validation.pattern": "Invalid format",
152
+ "validation.minValue": "Must be at least {min}",
153
+ "validation.maxValue": "Must be at most {max}",
154
+ "validation.minItems": "Add at least {min}",
155
+ "validation.maxItems": "No more than {max}",
156
+ "validation.integer": "Must be a whole number",
157
+ "validation.checking": "Still checking…"
158
+ },
159
+ de: {
160
+ "validation.required": "Pflichtfeld",
161
+ "validation.invalid": "Ungültiger Wert",
162
+ "validation.minLength": "Mindestens {min} Zeichen",
163
+ "validation.maxLength": "Höchstens {max} Zeichen",
164
+ "validation.pattern": "Ungültiges Format",
165
+ "validation.minValue": "Mindestens {min}",
166
+ "validation.maxValue": "Höchstens {max}",
167
+ "validation.minItems": "Mindestens {min}",
168
+ "validation.maxItems": "Höchstens {max}",
169
+ "validation.integer": "Ganze Zahl erforderlich",
170
+ "validation.checking": "Prüfung läuft…"
171
+ }
172
+ }, x = (e, t) => e.replace(/\{(\w+)\}/g, (e, n) => {
173
+ let r = t?.[n];
174
+ return r === void 0 ? e : String(r);
175
+ }), S = () => {
176
+ let e = globalThis.document?.documentElement?.lang ?? "";
177
+ return e === "" ? "en" : e;
178
+ }, C = (e, t) => {
179
+ let n = t?.messages?.(e.id, e.params, e.fallback);
180
+ if (n !== void 0) return n;
181
+ let r = b[(t?.locale ?? S()).toLowerCase().split("-")[0] ?? "en"]?.[e.id] ?? b.en?.[e.id];
182
+ return r === void 0 ? e.fallback : x(r, e.params);
183
+ }, w = (e) => {
184
+ let t = /^([a-z][\w-]*(?:\.[\w-]+)+)\|(\{.*\})$/.exec(e);
185
+ if (t !== null && t[1] !== void 0 && t[2] !== void 0) try {
186
+ return {
187
+ id: t[1],
188
+ params: JSON.parse(t[2]),
189
+ fallback: e
190
+ };
191
+ } catch {}
192
+ return /^[a-z][\w-]*(?:\.[\w-]+)+$/.test(e) ? {
193
+ id: e,
194
+ fallback: e
195
+ } : {
196
+ id: "validation.custom",
197
+ fallback: e
198
+ };
199
+ }, T = (e) => {
200
+ let r = e[n.SchemaIdAnnotationId], i = e[n.JSONSchemaAnnotationId] ?? {};
201
+ switch (r) {
202
+ case t.MinLengthSchemaId: return {
203
+ id: "validation.minLength",
204
+ params: { min: i.minLength }
205
+ };
206
+ case t.MaxLengthSchemaId: return {
207
+ id: "validation.maxLength",
208
+ params: { max: i.maxLength }
209
+ };
210
+ case t.PatternSchemaId: return {
211
+ id: "validation.pattern",
212
+ params: { pattern: i.pattern }
213
+ };
214
+ case t.GreaterThanOrEqualToSchemaId: return {
215
+ id: "validation.minValue",
216
+ params: { min: i.minimum }
217
+ };
218
+ case t.LessThanOrEqualToSchemaId: return {
219
+ id: "validation.maxValue",
220
+ params: { max: i.maximum }
221
+ };
222
+ case t.GreaterThanSchemaId: return {
223
+ id: "validation.minValue",
224
+ params: {
225
+ min: i.exclusiveMinimum,
226
+ exclusive: !0
227
+ }
228
+ };
229
+ case t.LessThanSchemaId: return {
230
+ id: "validation.maxValue",
231
+ params: {
232
+ max: i.exclusiveMaximum,
233
+ exclusive: !0
234
+ }
235
+ };
236
+ case t.IntSchemaId: return { id: "validation.integer" };
237
+ case t.MinItemsSchemaId: return {
238
+ id: "validation.minItems",
239
+ params: { min: i.minItems }
240
+ };
241
+ case t.MaxItemsSchemaId: return {
242
+ id: "validation.maxItems",
243
+ params: { max: i.maxItems }
244
+ };
245
+ case t.BetweenSchemaId: return {
246
+ id: "validation.minValue",
247
+ params: {
248
+ min: i.minimum,
249
+ max: i.maximum
250
+ }
251
+ };
252
+ default: return { id: "validation.invalid" };
253
+ }
254
+ }, E = (e, t) => {
255
+ let r = e[n.MessageAnnotationId];
256
+ if (typeof r == "function") try {
257
+ let e = r(t);
258
+ if (typeof e == "string") return e;
259
+ if (typeof e == "object" && e && typeof e.message == "string") return e.message;
260
+ } catch {}
261
+ }, D = (e) => Array.isArray(e) ? e.map((e) => String(e)) : [String(e)], O = (e) => {
262
+ let t = [], n = (e, n, r, i) => {
263
+ t.push({
264
+ path: e.join("."),
265
+ id: n,
266
+ ...r === void 0 ? {} : { params: r },
267
+ fallback: i
268
+ });
269
+ }, r = (e, t) => {
270
+ let r = w(t);
271
+ n(e, r.id, r.params, r.fallback);
272
+ }, i = (e, t) => {
273
+ switch (e._tag) {
274
+ case "Composite": {
275
+ let n = e.issues;
276
+ if (n === void 0) return;
277
+ for (let e of Array.isArray(n) ? n : [n]) i(e, t);
278
+ return;
279
+ }
280
+ case "Pointer":
281
+ e.issue !== void 0 && i(e.issue, [...t, ...D(e.path)]);
282
+ return;
283
+ case "Refinement": {
284
+ if (e.kind === "From") {
285
+ e.issue !== void 0 && i(e.issue, t);
286
+ return;
287
+ }
288
+ let a = e.ast?.annotations ?? {}, o = E(a, e);
289
+ if (o !== void 0) return r(t, o);
290
+ let s = T(a);
291
+ if (s.id !== "validation.invalid") {
292
+ n(t, s.id, s.params, k(e));
293
+ return;
294
+ }
295
+ if (e.issue !== void 0 && (e.issue._tag === "Pointer" || e.issue._tag === "Composite" || e.issue._tag === "Type")) {
296
+ i(e.issue, t);
297
+ return;
298
+ }
299
+ n(t, "validation.invalid", void 0, k(e));
300
+ return;
301
+ }
302
+ case "Transformation":
303
+ e.issue !== void 0 && i(e.issue, t);
304
+ return;
305
+ case "Missing":
306
+ n(t, "validation.required", void 0, "Required");
307
+ return;
308
+ case "Type": {
309
+ if (typeof e.message == "string" && e.message.length > 0) return r(t, e.message);
310
+ let i = e.ast?.annotations, a = i === void 0 ? void 0 : E(i, e);
311
+ if (a !== void 0) return r(t, a);
312
+ n(t, "validation.invalid", void 0, k(e));
313
+ return;
314
+ }
315
+ default:
316
+ n(t, "validation.invalid", void 0, k(e));
317
+ return;
318
+ }
319
+ };
320
+ return i(e.issue, []), t;
321
+ }, k = (e) => typeof e.message == "string" && e.message.length > 0 ? e.message : "Invalid value", A = (e, n, r) => {
322
+ let i = t.decodeUnknownEither(e, { errors: "all" })(n);
323
+ if (i._tag === "Right") return {
324
+ valid: !0,
325
+ errors: {},
326
+ issues: []
327
+ };
328
+ let a = O(i.left), o = {};
329
+ for (let e of a) e.path !== "" && !(e.path in o) && (o[e.path] = C(e, r));
330
+ return {
331
+ valid: !1,
332
+ errors: o,
333
+ issues: a
334
+ };
335
+ }, j = "__voltro_form_flash__", M = "/form/", N = (e) => `${M}${encodeURIComponent(e)}`, P = "__voltro_form", F = "__voltro_redirect", I = (e) => {
336
+ let t = Number(e);
337
+ return Number.isNaN(t) ? e : t;
338
+ }, L = (e) => {
339
+ let t = e.jsonSchema.items;
340
+ if (!t || typeof t != "object") return;
341
+ let n = t.type;
342
+ return typeof n == "string" ? n : void 0;
343
+ }, R = (e, t) => {
344
+ switch (e.widget) {
345
+ case "number": return t === "" ? void 0 : I(t);
346
+ case "date":
347
+ case "datetime": return t === "" ? void 0 : t;
348
+ default: return t;
349
+ }
350
+ }, z = (e, t) => {
351
+ let n = /* @__PURE__ */ new Map();
352
+ for (let [e, r] of t) {
353
+ let t = n.get(e);
354
+ t === void 0 ? n.set(e, [r]) : t.push(r);
355
+ }
356
+ let r = {}, i = (e, t) => {
357
+ let n = e.split("."), i = r;
358
+ for (let e of n.slice(0, -1)) {
359
+ let t = i[e];
360
+ if (typeof t != "object" || !t) {
361
+ let t = {};
362
+ i[e] = t, i = t;
363
+ } else i = t;
364
+ }
365
+ i[n[n.length - 1]] = t;
366
+ };
367
+ for (let t of _(e)) {
368
+ if (t.widget === "array") continue;
369
+ let e = n.get(t.name);
370
+ if (t.widget === "checkbox" || t.widget === "switch") {
371
+ i(t.name, e !== void 0);
372
+ continue;
373
+ }
374
+ if (t.widget === "multi-select") {
375
+ let n = L(t), r = e ?? [];
376
+ i(t.name, n === "number" || n === "integer" ? r.filter((e) => e !== "").map(I) : r.filter((e) => e !== ""));
377
+ continue;
378
+ }
379
+ if (e === void 0) continue;
380
+ let r = R(t, e[0]);
381
+ r !== void 0 && i(t.name, r);
382
+ }
383
+ return r;
384
+ };
385
+ //#endregion
386
+ export { N as a, S as c, r as d, y as f, F as i, C as l, _ as m, P as n, z as o, v as p, M as r, O as s, j as t, A as u };