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