@golemui/gui-validators 1.5.0-rc.0 → 1.5.0-rc.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 1.5.0-rc.1 (2026-09-07)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **gui-validators:** report the required message when a required files value is absent ([#355](https://github.com/golemui/golemui/pull/355))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Mud Scientist @mudscientist
10
+
11
+ ## 1.5.0-rc.0 (2026-09-04)
12
+
13
+ ### 🚀 Features
14
+
15
+ - **gui-components:** add file upload widgets ([#332](https://github.com/golemui/golemui/pull/332))
16
+
17
+ ### ❤️ Thank You
18
+
19
+ - Raúl Jiménez @Elecash
20
+
1
21
  ## 1.4.0 (2026-08-26)
2
22
 
3
23
  This was a version bump only for gui-validators to align it with other projects, there were no code changes.
package/index.js CHANGED
@@ -1,19 +1,19 @@
1
- import { filterTap as _, standardValidate as q, isStandardValidateSuccess as L } from "@golemui/core";
1
+ import { standardValidate as I, isStandardValidateSuccess as b, filterTap as A } from "@golemui/core";
2
2
  import "@standard-schema/spec";
3
3
  import { iso as g } from "zod";
4
- import { uuid as A, url as T, ipv6 as $, ipv4 as j, hostname as D, email as N, any as f, superRefine as y, optional as R, array as p, refine as u, minLength as b, maxLength as I, boolean as M, number as E, int as P, minimum as G, maximum as J, string as w, regex as B } from "zod/mini";
5
- const l = {
4
+ import { uuid as _, url as T, ipv6 as $, ipv4 as j, hostname as D, email as N, any as a, superRefine as h, array as l, refine as u, minLength as x, maxLength as M, optional as R, boolean as q, number as S, int as P, minimum as G, maximum as J, string as w, regex as B } from "zod/mini";
5
+ const k = {
6
6
  email: { schema: N() },
7
7
  hostname: { schema: D() },
8
8
  ipv4: { schema: j() },
9
9
  ipv6: { schema: $() },
10
10
  url: { schema: T() },
11
- uuid: { schema: A() },
11
+ uuid: { schema: _() },
12
12
  date: { schema: g.date() },
13
13
  time: { schema: g.time() },
14
14
  "date-time": { schema: g.datetime({ local: !0, offset: !0 }) },
15
15
  duration: { schema: g.duration() }
16
- }, S = Object.keys(l), C = ["uploading", "uploaded", "error"], te = (i) => (t, e) => {
16
+ }, L = Object.keys(k), C = ["uploading", "uploaded", "error"], ne = (m) => (t, e) => {
17
17
  switch (t.type) {
18
18
  case "string":
19
19
  return K(t, e);
@@ -29,11 +29,11 @@ const l = {
29
29
  case "files":
30
30
  return Z(t, e);
31
31
  case "custom": {
32
- if (!i)
32
+ if (!m)
33
33
  throw new Error(
34
34
  'Validator type "custom" requires a customValidators object, but it was not supplied.'
35
35
  );
36
- return z(t, i);
36
+ return v(t, m);
37
37
  }
38
38
  default: {
39
39
  const c = t;
@@ -43,12 +43,12 @@ const l = {
43
43
  }
44
44
  }
45
45
  };
46
- function o(i, t) {
47
- if (i !== void 0)
48
- return typeof i == "string" ? i : t?.translate(i.key, i.params, i.default) ?? i.default;
46
+ function o(m, t) {
47
+ if (m !== void 0)
48
+ return typeof m == "string" ? m : t?.translate(m.key, m.params, m.default) ?? m.default;
49
49
  }
50
- function K(i, t) {
51
- return a(i, (e) => {
50
+ function K(m, t) {
51
+ return f(m, (e) => {
52
52
  const c = o(e.messages?.invalid, t);
53
53
  let r = c ? w(c) : w();
54
54
  if (e.required === !0) {
@@ -58,83 +58,83 @@ function K(i, t) {
58
58
  if (typeof e.minLength == "number") {
59
59
  const s = o(e.messages?.minLength, t), n = e.minLength;
60
60
  r = r.check(
61
- s ? u((m) => m.length >= n, { error: s }) : b(n)
61
+ s ? u((i) => i.length >= n, { error: s }) : x(n)
62
62
  );
63
63
  }
64
64
  if (typeof e.maxLength == "number") {
65
65
  const s = o(e.messages?.maxLength, t), n = e.maxLength;
66
66
  r = r.check(
67
- s ? u((m) => m.length <= n, { error: s }) : I(n)
67
+ s ? u((i) => i.length <= n, { error: s }) : M(n)
68
68
  );
69
69
  }
70
70
  if (typeof e.pattern == "string") {
71
71
  const s = o(e.messages?.pattern, t), n = new RegExp(e.pattern);
72
72
  r = r.check(
73
- s ? u((m) => n.test(m), { error: s }) : B(n)
73
+ s ? u((i) => n.test(i), { error: s }) : B(n)
74
74
  );
75
75
  }
76
76
  if (e.enum) {
77
77
  const s = e.enum, n = o(e.messages?.enum, t);
78
- r = r.check(u((m) => s.includes(m), n ? { error: n } : void 0));
78
+ r = r.check(u((i) => s.includes(i), n ? { error: n } : void 0));
79
79
  }
80
80
  if (e.const !== void 0) {
81
81
  const s = o(e.messages?.const, t);
82
82
  r = r.check(u((n) => n === e.const, s ? { error: s } : void 0));
83
83
  }
84
84
  if (e.format !== void 0)
85
- if (S.includes(e.format)) {
85
+ if (L.includes(e.format)) {
86
86
  const s = o(e.messages?.format, t);
87
87
  r = r.check(
88
- s ? y((n, m) => {
89
- const d = q(
90
- l[e.format].schema,
88
+ s ? h((n, i) => {
89
+ const d = I(
90
+ k[e.format].schema,
91
91
  n
92
92
  );
93
- L(d) || m.addIssue({ code: "custom", path: [], message: s });
94
- }) : l[e.format].schema
93
+ b(d) || i.addIssue({ code: "custom", path: [], message: s });
94
+ }) : k[e.format].schema
95
95
  );
96
96
  } else
97
97
  throw new Error(
98
- `Unknown string validation format: ${JSON.stringify(e.format)}. The "format" property must be one of: ${S.map((s) => `"${s}"`).join(", ")}.`
98
+ `Unknown string validation format: ${JSON.stringify(e.format)}. The "format" property must be one of: ${L.map((s) => `"${s}"`).join(", ")}.`
99
99
  );
100
100
  return r;
101
101
  });
102
102
  }
103
- const Q = (i, t) => {
103
+ const Q = (m, t) => {
104
104
  if (t === 0)
105
105
  return !1;
106
- const e = i / t;
106
+ const e = m / t;
107
107
  return Math.abs(e - Math.round(e)) < 1e-10;
108
108
  };
109
- function W(i, t) {
110
- return a(i, (e) => {
109
+ function W(m, t) {
110
+ return f(m, (e) => {
111
111
  const c = o(e.messages?.invalid, t);
112
- let r = c ? E(c) : E();
112
+ let r = c ? S(c) : S();
113
113
  if (e.type === "integer" && (r = r.check(P())), e.minimum !== void 0) {
114
114
  const s = o(e.messages?.minimum, t), n = e.minimum;
115
- r = r.check(s ? u((m) => m >= n, { error: s }) : G(n));
115
+ r = r.check(s ? u((i) => i >= n, { error: s }) : G(n));
116
116
  }
117
117
  if (e.maximum !== void 0) {
118
118
  const s = o(e.messages?.maximum, t), n = e.maximum;
119
- r = r.check(s ? u((m) => m <= n, { error: s }) : J(n));
119
+ r = r.check(s ? u((i) => i <= n, { error: s }) : J(n));
120
120
  }
121
121
  if (e.exclusiveMinimum !== void 0) {
122
122
  const s = o(e.messages?.exclusiveMinimum, t), n = e.exclusiveMinimum;
123
- r = r.check(u((m) => m > n, s ? { error: s } : void 0));
123
+ r = r.check(u((i) => i > n, s ? { error: s } : void 0));
124
124
  }
125
125
  if (e.exclusiveMaximum !== void 0) {
126
126
  const s = o(e.messages?.exclusiveMaximum, t), n = e.exclusiveMaximum;
127
- r = r.check(u((m) => m < n, s ? { error: s } : void 0));
127
+ r = r.check(u((i) => i < n, s ? { error: s } : void 0));
128
128
  }
129
129
  if (e.multipleOf !== void 0) {
130
130
  const s = o(e.messages?.multipleOf, t), n = e.multipleOf;
131
131
  r = r.check(
132
- u((m) => Q(m, n), s ? { error: s } : void 0)
132
+ u((i) => Q(i, n), s ? { error: s } : void 0)
133
133
  );
134
134
  }
135
135
  if (e.enum) {
136
136
  const s = e.enum, n = o(e.messages?.enum, t);
137
- r = r.check(u((m) => s.includes(m), n ? { error: n } : void 0));
137
+ r = r.check(u((i) => s.includes(i), n ? { error: n } : void 0));
138
138
  }
139
139
  if (e.const !== void 0) {
140
140
  const s = o(e.messages?.const, t);
@@ -143,10 +143,10 @@ function W(i, t) {
143
143
  return r;
144
144
  });
145
145
  }
146
- function H(i, t) {
147
- return a(i, (e) => {
146
+ function H(m, t) {
147
+ return f(m, (e) => {
148
148
  const c = o(e.messages?.invalid, t);
149
- let r = c ? M(c) : M();
149
+ let r = c ? q(c) : q();
150
150
  if (e.const !== void 0) {
151
151
  const s = o(e.messages?.const, t);
152
152
  r = r.check(u((n) => n === e.const, s ? { error: s } : void 0));
@@ -154,10 +154,10 @@ function H(i, t) {
154
154
  return r;
155
155
  });
156
156
  }
157
- function X(i, t) {
158
- return a(i, (e) => {
157
+ function X(m, t) {
158
+ return f(m, (e) => {
159
159
  const c = o(e.messages?.invalid, t);
160
- let r = c ? p(f(), c) : p(f());
160
+ let r = c ? l(a(), c) : l(a());
161
161
  if (e.required === !0) {
162
162
  const s = o(e.messages?.required, t) ?? "This field is required";
163
163
  r = r.check(u((n) => n.length > 0, { error: s }));
@@ -165,103 +165,115 @@ function X(i, t) {
165
165
  if (typeof e.minItems == "number") {
166
166
  const s = o(e.messages?.minItems, t), n = e.minItems;
167
167
  r = r.check(
168
- s ? u((m) => m.length >= n, { error: s }) : b(n)
168
+ s ? u((i) => i.length >= n, { error: s }) : x(n)
169
169
  );
170
170
  }
171
171
  if (typeof e.maxItems == "number") {
172
172
  const s = o(e.messages?.maxItems, t), n = e.maxItems;
173
173
  r = r.check(
174
- s ? u((m) => m.length <= n, { error: s }) : I(n)
174
+ s ? u((i) => i.length <= n, { error: s }) : M(n)
175
175
  );
176
176
  }
177
177
  return r;
178
178
  });
179
179
  }
180
- const V = "This field is required", U = "Invalid file", O = "Wait for the upload to finish";
181
- function k(i) {
182
- if (i === null || typeof i != "object")
180
+ const V = "This field is required", U = "Invalid file", F = "Wait for the upload to finish";
181
+ function y(m) {
182
+ if (m === null || typeof m != "object")
183
183
  return !1;
184
- const t = i;
184
+ const t = m;
185
185
  return typeof t.id == "string" && typeof t.name == "string" && typeof t.size == "number" && typeof t.type == "string" && typeof t.status == "string" && C.includes(t.status);
186
186
  }
187
- function Y(i, t) {
188
- const e = o(i.messages?.invalid, t) ?? U, c = o(i.messages?.required, t) ?? V, r = o(i.messages?.pendingUploads, t) ?? O, s = i.blockPendingUploads !== !1;
189
- return f().check(
190
- y((n, m) => {
187
+ function Y(m, t) {
188
+ const e = o(m.messages?.invalid, t) ?? U, c = o(m.messages?.required, t) ?? V, r = o(m.messages?.pendingUploads, t) ?? F, s = m.blockPendingUploads !== !1;
189
+ return a().check(
190
+ h((n, i) => {
191
191
  if (n == null) {
192
- i.required === !0 && m.addIssue({ code: "custom", message: c });
192
+ m.required === !0 && i.addIssue({ code: "custom", message: c });
193
193
  return;
194
194
  }
195
- if (!k(n)) {
196
- m.addIssue({ code: "custom", message: e });
195
+ if (!y(n)) {
196
+ i.addIssue({ code: "custom", message: e });
197
197
  return;
198
198
  }
199
- s && n.status !== "uploaded" && m.addIssue({ code: "custom", message: r });
199
+ s && n.status !== "uploaded" && i.addIssue({ code: "custom", message: r });
200
200
  })
201
201
  );
202
202
  }
203
- function Z(i, t) {
204
- return a(i, (e) => {
205
- const c = o(e.messages?.invalid, t) ?? U;
206
- let r = p(f(), c).check(
207
- u((s) => s.every(k), { error: c })
208
- );
209
- if (e.required === !0) {
210
- const s = o(e.messages?.required, t) ?? V;
211
- r = r.check(u((n) => n.length > 0, { error: s }));
212
- }
213
- if (typeof e.minItems == "number") {
214
- const s = o(e.messages?.minItems, t), n = e.minItems;
215
- r = r.check(
216
- s ? u((m) => m.length >= n, { error: s }) : b(n)
217
- );
218
- }
219
- if (typeof e.maxItems == "number") {
220
- const s = o(e.messages?.maxItems, t), n = e.maxItems;
221
- r = r.check(
222
- s ? u((m) => m.length <= n, { error: s }) : I(n)
223
- );
224
- }
225
- if (e.blockPendingUploads !== !1) {
226
- const s = o(e.messages?.pendingUploads, t) ?? O;
227
- r = r.check(
228
- u(
229
- (n) => n.every((m) => !k(m) || m.status === "uploaded"),
230
- { error: s }
231
- )
203
+ function Z(m, t) {
204
+ const e = o(m.messages?.required, t) ?? V, c = z(m, t, e);
205
+ return a().check(
206
+ h((r, s) => {
207
+ if (r == null) {
208
+ m.required === !0 && s.addIssue({ code: "custom", message: e });
209
+ return;
210
+ }
211
+ const n = I(
212
+ c,
213
+ r
232
214
  );
233
- }
234
- return r;
235
- });
215
+ if (!b(n))
216
+ for (const i of n.issues)
217
+ s.addIssue({ code: "custom", message: i.message });
218
+ })
219
+ );
220
+ }
221
+ function z(m, t, e) {
222
+ const c = o(m.messages?.invalid, t) ?? U;
223
+ let r = l(a(), c).check(
224
+ u((s) => s.every(y), { error: c })
225
+ );
226
+ if (m.required === !0 && (r = r.check(u((s) => s.length > 0, { error: e }))), typeof m.minItems == "number") {
227
+ const s = o(m.messages?.minItems, t), n = m.minItems;
228
+ r = r.check(
229
+ s ? u((i) => i.length >= n, { error: s }) : x(n)
230
+ );
231
+ }
232
+ if (typeof m.maxItems == "number") {
233
+ const s = o(m.messages?.maxItems, t), n = m.maxItems;
234
+ r = r.check(
235
+ s ? u((i) => i.length <= n, { error: s }) : M(n)
236
+ );
237
+ }
238
+ if (m.blockPendingUploads !== !1) {
239
+ const s = o(m.messages?.pendingUploads, t) ?? F;
240
+ r = r.check(
241
+ u(
242
+ (n) => n.every((i) => !y(i) || i.status === "uploaded"),
243
+ { error: s }
244
+ )
245
+ );
246
+ }
247
+ return r;
236
248
  }
237
- function z(i, t) {
238
- return a(i, (e) => {
239
- let c = f();
240
- return _(
249
+ function v(m, t) {
250
+ return f(m, (e) => {
251
+ let c = a();
252
+ return A(
241
253
  Object.keys(e),
242
254
  // filter non-custom validator keys
243
255
  (r) => r !== "type" && r !== "required",
244
256
  (r) => {
245
257
  const s = e[r], n = t[r];
246
258
  if (!n) {
247
- const d = Object.keys(t).map((h) => `"${h}"`).join(", ");
259
+ const d = Object.keys(t).map((p) => `"${p}"`).join(", ");
248
260
  throw new Error(
249
261
  `Unknown custom validator rule "${r}". Registered rules: ${d || "(none)"}.`
250
262
  );
251
263
  }
252
- const m = n(s);
264
+ const i = n(s);
253
265
  c = c.check(
254
- y((d, h) => {
255
- const x = q(
256
- m,
266
+ h((d, p) => {
267
+ const E = I(
268
+ i,
257
269
  d
258
270
  );
259
- if (!L(x)) {
260
- const F = x.issues[0];
261
- h.addIssue({
271
+ if (!b(E)) {
272
+ const O = E.issues[0];
273
+ p.addIssue({
262
274
  code: "custom",
263
275
  path: [],
264
- message: F?.message || `Validation failed for ${r}`
276
+ message: O?.message || `Validation failed for ${r}`
265
277
  });
266
278
  }
267
279
  })
@@ -270,10 +282,10 @@ function z(i, t) {
270
282
  ), c;
271
283
  });
272
284
  }
273
- function a(i, t) {
274
- const e = t(i);
275
- return i.required ? e : R(e);
285
+ function f(m, t) {
286
+ const e = t(m);
287
+ return m.required ? e : R(e);
276
288
  }
277
289
  export {
278
- te as initValidators
290
+ ne as initValidators
279
291
  };
package/index.umd.cjs CHANGED
@@ -1 +1 @@
1
- (function(d,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@golemui/core"),require("@standard-schema/spec"),require("zod"),require("zod/mini")):typeof define=="function"&&define.amd?define(["exports","@golemui/core","@standard-schema/spec","zod","zod/mini"],f):(d=typeof globalThis<"u"?globalThis:d||self,f(d["gui-validators"]={},d.core,null,d.zod,d.mini))})(this,(function(d,f,j,h,o){"use strict";const p={email:{schema:o.email()},hostname:{schema:o.hostname()},ipv4:{schema:o.ipv4()},ipv6:{schema:o.ipv6()},url:{schema:o.url()},uuid:{schema:o.uuid()},date:{schema:h.iso.date()},time:{schema:h.iso.time()},"date-time":{schema:h.iso.datetime({local:!0,offset:!0})},duration:{schema:h.iso.duration()}},k=Object.keys(p),S=["uploading","uploaded","error"],q=c=>(t,e)=>{switch(t.type){case"string":return E(t,e);case"integer":case"number":return w(t,e);case"boolean":return V(t,e);case"array":return O(t,e);case"file":return T(t,e);case"files":return U(t,e);case"custom":{if(!c)throw new Error('Validator type "custom" requires a customValidators object, but it was not supplied.');return F(t,c)}default:{const a=t;throw new Error(`Unknown validator config: ${JSON.stringify(a)}. The "type" property must be one of: "string", "number", "integer", "boolean", "array", "file", "files", "custom".`)}}};function m(c,t){if(c!==void 0)return typeof c=="string"?c:t?.translate(c.key,c.params,c.default)??c.default}function E(c,t){return i(c,e=>{const a=m(e.messages?.invalid,t);let r=a?o.string(a):o.string();if(e.required===!0){const s=m(e.messages?.required,t)??"This field is required";r=r.check(o.refine(n=>n.length>0,{error:s}))}if(typeof e.minLength=="number"){const s=m(e.messages?.minLength,t),n=e.minLength;r=r.check(s?o.refine(u=>u.length>=n,{error:s}):o.minLength(n))}if(typeof e.maxLength=="number"){const s=m(e.messages?.maxLength,t),n=e.maxLength;r=r.check(s?o.refine(u=>u.length<=n,{error:s}):o.maxLength(n))}if(typeof e.pattern=="string"){const s=m(e.messages?.pattern,t),n=new RegExp(e.pattern);r=r.check(s?o.refine(u=>n.test(u),{error:s}):o.regex(n))}if(e.enum){const s=e.enum,n=m(e.messages?.enum,t);r=r.check(o.refine(u=>s.includes(u),n?{error:n}:void 0))}if(e.const!==void 0){const s=m(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}if(e.format!==void 0)if(k.includes(e.format)){const s=m(e.messages?.format,t);r=r.check(s?o.superRefine((n,u)=>{const g=f.standardValidate(p[e.format].schema,n);f.isStandardValidateSuccess(g)||u.addIssue({code:"custom",path:[],message:s})}):p[e.format].schema)}else throw new Error(`Unknown string validation format: ${JSON.stringify(e.format)}. The "format" property must be one of: ${k.map(s=>`"${s}"`).join(", ")}.`);return r})}const L=(c,t)=>{if(t===0)return!1;const e=c/t;return Math.abs(e-Math.round(e))<1e-10};function w(c,t){return i(c,e=>{const a=m(e.messages?.invalid,t);let r=a?o.number(a):o.number();if(e.type==="integer"&&(r=r.check(o.int())),e.minimum!==void 0){const s=m(e.messages?.minimum,t),n=e.minimum;r=r.check(s?o.refine(u=>u>=n,{error:s}):o.minimum(n))}if(e.maximum!==void 0){const s=m(e.messages?.maximum,t),n=e.maximum;r=r.check(s?o.refine(u=>u<=n,{error:s}):o.maximum(n))}if(e.exclusiveMinimum!==void 0){const s=m(e.messages?.exclusiveMinimum,t),n=e.exclusiveMinimum;r=r.check(o.refine(u=>u>n,s?{error:s}:void 0))}if(e.exclusiveMaximum!==void 0){const s=m(e.messages?.exclusiveMaximum,t),n=e.exclusiveMaximum;r=r.check(o.refine(u=>u<n,s?{error:s}:void 0))}if(e.multipleOf!==void 0){const s=m(e.messages?.multipleOf,t),n=e.multipleOf;r=r.check(o.refine(u=>L(u,n),s?{error:s}:void 0))}if(e.enum){const s=e.enum,n=m(e.messages?.enum,t);r=r.check(o.refine(u=>s.includes(u),n?{error:n}:void 0))}if(e.const!==void 0){const s=m(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}return r})}function V(c,t){return i(c,e=>{const a=m(e.messages?.invalid,t);let r=a?o.boolean(a):o.boolean();if(e.const!==void 0){const s=m(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}return r})}function O(c,t){return i(c,e=>{const a=m(e.messages?.invalid,t);let r=a?o.array(o.any(),a):o.array(o.any());if(e.required===!0){const s=m(e.messages?.required,t)??"This field is required";r=r.check(o.refine(n=>n.length>0,{error:s}))}if(typeof e.minItems=="number"){const s=m(e.messages?.minItems,t),n=e.minItems;r=r.check(s?o.refine(u=>u.length>=n,{error:s}):o.minLength(n))}if(typeof e.maxItems=="number"){const s=m(e.messages?.maxItems,t),n=e.maxItems;r=r.check(s?o.refine(u=>u.length<=n,{error:s}):o.maxLength(n))}return r})}const b="This field is required",x="Invalid file",I="Wait for the upload to finish";function l(c){if(c===null||typeof c!="object")return!1;const t=c;return typeof t.id=="string"&&typeof t.name=="string"&&typeof t.size=="number"&&typeof t.type=="string"&&typeof t.status=="string"&&S.includes(t.status)}function T(c,t){const e=m(c.messages?.invalid,t)??x,a=m(c.messages?.required,t)??b,r=m(c.messages?.pendingUploads,t)??I,s=c.blockPendingUploads!==!1;return o.any().check(o.superRefine((n,u)=>{if(n==null){c.required===!0&&u.addIssue({code:"custom",message:a});return}if(!l(n)){u.addIssue({code:"custom",message:e});return}s&&n.status!=="uploaded"&&u.addIssue({code:"custom",message:r})}))}function U(c,t){return i(c,e=>{const a=m(e.messages?.invalid,t)??x;let r=o.array(o.any(),a).check(o.refine(s=>s.every(l),{error:a}));if(e.required===!0){const s=m(e.messages?.required,t)??b;r=r.check(o.refine(n=>n.length>0,{error:s}))}if(typeof e.minItems=="number"){const s=m(e.messages?.minItems,t),n=e.minItems;r=r.check(s?o.refine(u=>u.length>=n,{error:s}):o.minLength(n))}if(typeof e.maxItems=="number"){const s=m(e.messages?.maxItems,t),n=e.maxItems;r=r.check(s?o.refine(u=>u.length<=n,{error:s}):o.maxLength(n))}if(e.blockPendingUploads!==!1){const s=m(e.messages?.pendingUploads,t)??I;r=r.check(o.refine(n=>n.every(u=>!l(u)||u.status==="uploaded"),{error:s}))}return r})}function F(c,t){return i(c,e=>{let a=o.any();return f.filterTap(Object.keys(e),r=>r!=="type"&&r!=="required",r=>{const s=e[r],n=t[r];if(!n){const g=Object.keys(t).map(y=>`"${y}"`).join(", ");throw new Error(`Unknown custom validator rule "${r}". Registered rules: ${g||"(none)"}.`)}const u=n(s);a=a.check(o.superRefine((g,y)=>{const M=f.standardValidate(u,g);if(!f.isStandardValidateSuccess(M)){const _=M.issues[0];y.addIssue({code:"custom",path:[],message:_?.message||`Validation failed for ${r}`})}}))}),a})}function i(c,t){const e=t(c);return c.required?e:o.optional(e)}d.initValidators=q,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@golemui/core"),require("@standard-schema/spec"),require("zod"),require("zod/mini")):typeof define=="function"&&define.amd?define(["exports","@golemui/core","@standard-schema/spec","zod","zod/mini"],d):(i=typeof globalThis<"u"?globalThis:i||self,d(i["gui-validators"]={},i.core,null,i.zod,i.mini))})(this,(function(i,d,j,h,o){"use strict";const p={email:{schema:o.email()},hostname:{schema:o.hostname()},ipv4:{schema:o.ipv4()},ipv6:{schema:o.ipv6()},url:{schema:o.url()},uuid:{schema:o.uuid()},date:{schema:h.iso.date()},time:{schema:h.iso.time()},"date-time":{schema:h.iso.datetime({local:!0,offset:!0})},duration:{schema:h.iso.duration()}},k=Object.keys(p),S=["uploading","uploaded","error"],q=u=>(t,e)=>{switch(t.type){case"string":return E(t,e);case"integer":case"number":return L(t,e);case"boolean":return w(t,e);case"array":return O(t,e);case"file":return T(t,e);case"files":return U(t,e);case"custom":{if(!u)throw new Error('Validator type "custom" requires a customValidators object, but it was not supplied.');return A(t,u)}default:{const m=t;throw new Error(`Unknown validator config: ${JSON.stringify(m)}. The "type" property must be one of: "string", "number", "integer", "boolean", "array", "file", "files", "custom".`)}}};function a(u,t){if(u!==void 0)return typeof u=="string"?u:t?.translate(u.key,u.params,u.default)??u.default}function E(u,t){return f(u,e=>{const m=a(e.messages?.invalid,t);let r=m?o.string(m):o.string();if(e.required===!0){const s=a(e.messages?.required,t)??"This field is required";r=r.check(o.refine(n=>n.length>0,{error:s}))}if(typeof e.minLength=="number"){const s=a(e.messages?.minLength,t),n=e.minLength;r=r.check(s?o.refine(c=>c.length>=n,{error:s}):o.minLength(n))}if(typeof e.maxLength=="number"){const s=a(e.messages?.maxLength,t),n=e.maxLength;r=r.check(s?o.refine(c=>c.length<=n,{error:s}):o.maxLength(n))}if(typeof e.pattern=="string"){const s=a(e.messages?.pattern,t),n=new RegExp(e.pattern);r=r.check(s?o.refine(c=>n.test(c),{error:s}):o.regex(n))}if(e.enum){const s=e.enum,n=a(e.messages?.enum,t);r=r.check(o.refine(c=>s.includes(c),n?{error:n}:void 0))}if(e.const!==void 0){const s=a(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}if(e.format!==void 0)if(k.includes(e.format)){const s=a(e.messages?.format,t);r=r.check(s?o.superRefine((n,c)=>{const g=d.standardValidate(p[e.format].schema,n);d.isStandardValidateSuccess(g)||c.addIssue({code:"custom",path:[],message:s})}):p[e.format].schema)}else throw new Error(`Unknown string validation format: ${JSON.stringify(e.format)}. The "format" property must be one of: ${k.map(s=>`"${s}"`).join(", ")}.`);return r})}const V=(u,t)=>{if(t===0)return!1;const e=u/t;return Math.abs(e-Math.round(e))<1e-10};function L(u,t){return f(u,e=>{const m=a(e.messages?.invalid,t);let r=m?o.number(m):o.number();if(e.type==="integer"&&(r=r.check(o.int())),e.minimum!==void 0){const s=a(e.messages?.minimum,t),n=e.minimum;r=r.check(s?o.refine(c=>c>=n,{error:s}):o.minimum(n))}if(e.maximum!==void 0){const s=a(e.messages?.maximum,t),n=e.maximum;r=r.check(s?o.refine(c=>c<=n,{error:s}):o.maximum(n))}if(e.exclusiveMinimum!==void 0){const s=a(e.messages?.exclusiveMinimum,t),n=e.exclusiveMinimum;r=r.check(o.refine(c=>c>n,s?{error:s}:void 0))}if(e.exclusiveMaximum!==void 0){const s=a(e.messages?.exclusiveMaximum,t),n=e.exclusiveMaximum;r=r.check(o.refine(c=>c<n,s?{error:s}:void 0))}if(e.multipleOf!==void 0){const s=a(e.messages?.multipleOf,t),n=e.multipleOf;r=r.check(o.refine(c=>V(c,n),s?{error:s}:void 0))}if(e.enum){const s=e.enum,n=a(e.messages?.enum,t);r=r.check(o.refine(c=>s.includes(c),n?{error:n}:void 0))}if(e.const!==void 0){const s=a(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}return r})}function w(u,t){return f(u,e=>{const m=a(e.messages?.invalid,t);let r=m?o.boolean(m):o.boolean();if(e.const!==void 0){const s=a(e.messages?.const,t);r=r.check(o.refine(n=>n===e.const,s?{error:s}:void 0))}return r})}function O(u,t){return f(u,e=>{const m=a(e.messages?.invalid,t);let r=m?o.array(o.any(),m):o.array(o.any());if(e.required===!0){const s=a(e.messages?.required,t)??"This field is required";r=r.check(o.refine(n=>n.length>0,{error:s}))}if(typeof e.minItems=="number"){const s=a(e.messages?.minItems,t),n=e.minItems;r=r.check(s?o.refine(c=>c.length>=n,{error:s}):o.minLength(n))}if(typeof e.maxItems=="number"){const s=a(e.messages?.maxItems,t),n=e.maxItems;r=r.check(s?o.refine(c=>c.length<=n,{error:s}):o.maxLength(n))}return r})}const b="This field is required",I="Invalid file",x="Wait for the upload to finish";function l(u){if(u===null||typeof u!="object")return!1;const t=u;return typeof t.id=="string"&&typeof t.name=="string"&&typeof t.size=="number"&&typeof t.type=="string"&&typeof t.status=="string"&&S.includes(t.status)}function T(u,t){const e=a(u.messages?.invalid,t)??I,m=a(u.messages?.required,t)??b,r=a(u.messages?.pendingUploads,t)??x,s=u.blockPendingUploads!==!1;return o.any().check(o.superRefine((n,c)=>{if(n==null){u.required===!0&&c.addIssue({code:"custom",message:m});return}if(!l(n)){c.addIssue({code:"custom",message:e});return}s&&n.status!=="uploaded"&&c.addIssue({code:"custom",message:r})}))}function U(u,t){const e=a(u.messages?.required,t)??b,m=F(u,t,e);return o.any().check(o.superRefine((r,s)=>{if(r==null){u.required===!0&&s.addIssue({code:"custom",message:e});return}const n=d.standardValidate(m,r);if(!d.isStandardValidateSuccess(n))for(const c of n.issues)s.addIssue({code:"custom",message:c.message})}))}function F(u,t,e){const m=a(u.messages?.invalid,t)??I;let r=o.array(o.any(),m).check(o.refine(s=>s.every(l),{error:m}));if(u.required===!0&&(r=r.check(o.refine(s=>s.length>0,{error:e}))),typeof u.minItems=="number"){const s=a(u.messages?.minItems,t),n=u.minItems;r=r.check(s?o.refine(c=>c.length>=n,{error:s}):o.minLength(n))}if(typeof u.maxItems=="number"){const s=a(u.messages?.maxItems,t),n=u.maxItems;r=r.check(s?o.refine(c=>c.length<=n,{error:s}):o.maxLength(n))}if(u.blockPendingUploads!==!1){const s=a(u.messages?.pendingUploads,t)??x;r=r.check(o.refine(n=>n.every(c=>!l(c)||c.status==="uploaded"),{error:s}))}return r}function A(u,t){return f(u,e=>{let m=o.any();return d.filterTap(Object.keys(e),r=>r!=="type"&&r!=="required",r=>{const s=e[r],n=t[r];if(!n){const g=Object.keys(t).map(y=>`"${y}"`).join(", ");throw new Error(`Unknown custom validator rule "${r}". Registered rules: ${g||"(none)"}.`)}const c=n(s);m=m.check(o.superRefine((g,y)=>{const M=d.standardValidate(c,g);if(!d.isStandardValidateSuccess(M)){const _=M.issues[0];y.addIssue({code:"custom",path:[],message:_?.message||`Validation failed for ${r}`})}}))}),m})}function f(u,t){const e=t(u);return u.required?e:o.optional(e)}i.initValidators=q,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
@@ -76,7 +76,8 @@ export interface FileValidator extends BaseValidator {
76
76
  }
77
77
  /**
78
78
  * Validates the envelope array stored by the `multiFileUpload` widget
79
- * (`FileItem[]`). `required` means non-empty, like `array`.
79
+ * (`FileItem[]`). `required` means non-empty, like `array`. An absent value
80
+ * (`undefined` or `null`) counts as empty.
80
81
  */
81
82
  export interface FilesValidator extends BaseValidator {
82
83
  type: 'files';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemui/gui-validators",
3
- "version": "1.5.0-rc.0",
3
+ "version": "1.5.0-rc.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,7 +26,7 @@
26
26
  "peerDependencies": {
27
27
  "zod": "^4.0.0",
28
28
  "@standard-schema/spec": "^1.0.0",
29
- "@golemui/core": "1.5.0-rc.0"
29
+ "@golemui/core": "1.5.0-rc.2"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",