@maverickcer/env-cap 0.4.0 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +12 -12
  2. package/dist/.dts/build/index.d.ts +2 -2
  3. package/dist/.dts/build/index.d.ts.map +1 -1
  4. package/dist/.dts/build/lifecycle-model.d.ts +110 -2
  5. package/dist/.dts/build/lifecycle-model.d.ts.map +1 -1
  6. package/dist/.dts/build/link.d.ts +8 -0
  7. package/dist/.dts/build/link.d.ts.map +1 -1
  8. package/dist/.dts/build/parse.d.ts +8 -0
  9. package/dist/.dts/build/parse.d.ts.map +1 -1
  10. package/dist/.dts/runtime/document.d.ts +40 -0
  11. package/dist/.dts/runtime/document.d.ts.map +1 -1
  12. package/dist/build-4SFAWO5Y.js +5148 -0
  13. package/dist/build-4SFAWO5Y.js.map +1 -0
  14. package/dist/build.cjs +5021 -6
  15. package/dist/build.cjs.map +1 -1
  16. package/dist/build.js +5020 -7
  17. package/dist/build.js.map +1 -1
  18. package/dist/chunk-BV5OERR3.js +11 -0
  19. package/dist/{chunk-QUSAQJ52.js.map → chunk-BV5OERR3.js.map} +1 -1
  20. package/dist/cli/index.js +580 -38
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/eslint-plugin/index.cjs +701 -1
  23. package/dist/eslint-plugin/index.cjs.map +1 -1
  24. package/dist/eslint-plugin/index.js +701 -1
  25. package/dist/eslint-plugin/index.js.map +1 -1
  26. package/dist/evidence.cjs +59 -1
  27. package/dist/evidence.cjs.map +1 -1
  28. package/dist/evidence.js +59 -1
  29. package/dist/evidence.js.map +1 -1
  30. package/dist/helpers.cjs +379 -1
  31. package/dist/helpers.cjs.map +1 -1
  32. package/dist/helpers.js +379 -1
  33. package/dist/helpers.js.map +1 -1
  34. package/dist/index.cjs +249 -2
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.js +249 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/node.cjs +27 -1
  39. package/dist/node.cjs.map +1 -1
  40. package/dist/node.js +27 -1
  41. package/dist/node.js.map +1 -1
  42. package/package.json +5 -3
  43. package/schemas/env-cap-report.schema.json +37 -3
  44. package/dist/build-ICYKXFRE.js +0 -12
  45. package/dist/build-ICYKXFRE.js.map +0 -1
  46. package/dist/chunk-QUSAQJ52.js +0 -3
package/dist/helpers.js CHANGED
@@ -1,4 +1,382 @@
1
- function describe(value){if(value===void 0)return "undefined";if(value===null)return "null";return `a ${typeof value}`}function toArray(separator=",",processors2=[]){return value=>{const items=Array.isArray(value)?value:typeof value==="string"&&value.trim()!==""?value.split(separator).map(item=>item.trim()):[];return items.map(item=>{return processors2.reduce((current,processor)=>processor(current),item)})}}function base64(){return value=>{try{return Buffer.from(String(value),"base64")}catch{throw new Error("Expected a valid base64 value.")}}}function toBigInt(){return value=>{try{return BigInt(String(value))}catch{throw new Error("Expected a bigint value.")}}}function toBoolean(){return value=>{if(typeof value==="boolean")return value;const normalized=String(value).trim().toLowerCase();if(["true","1","yes","on"].includes(normalized))return true;if(["false","0","no","off"].includes(normalized))return false;throw new Error(`Expected a boolean-like value (true/false/1/0/yes/no/on/off), received ${describe(value)}.`)}}function toDate(){return value=>{const result=new Date(String(value));if(Number.isNaN(result.getTime())){throw new Error("Expected a valid date.")}return result}}function toInteger(){return value=>{const parsed=toNumber()(value);if(!Number.isInteger(parsed)){throw new Error("Expected an integer value.")}return parsed}}function parseJSON(){return value=>{if(typeof value!=="string"){if(value===void 0){throw new Error("Expected a JSON string, received undefined.")}return value}try{return JSON.parse(value)}catch{throw new Error("Expected a valid JSON string, but parsing failed.")}}}function toLowerCase(){return value=>String(value??"").toLowerCase()}function toNumber(){return value=>{if(typeof value==="string"&&value.trim()===""){throw new Error("Expected a numeric value, received an empty string.")}const result=typeof value==="number"?value:Number(value);if(Number.isNaN(result)){throw new Error(`Expected a numeric value, received ${describe(value)}.`)}return result}}function toRegExp(){return value=>{try{return new RegExp(String(value))}catch{throw new Error("Expected a valid regular expression.")}}}function split(separator=","){return value=>{if(typeof value!=="string")return [];return value.split(separator).map(item=>item.trim())}}function toString(){return value=>{if(value===void 0||value===null)return "";return typeof value==="string"?value:String(value)}}function trim(){return value=>String(value??"").trim()}function toUpperCase(){return value=>String(value??"").toUpperCase()}function toURL(){return value=>{try{return new URL(String(value??""))}catch{throw new Error("Expected a valid absolute URL.")}}}function after(date){return (value,_rawEnv)=>value>date||"Expected date to be after required date."}function all(...validators2){return (value,rawEnv)=>{for(const validator of validators2){const result=validator(value,rawEnv);if(result!==true)return result}return true}}function any(...validators2){return (value,rawEnv)=>{for(const validator of validators2){if(validator(value,rawEnv)===true)return true}return "Value did not satisfy any validation."}}function before(date){return (value,_rawEnv)=>value<date||"Expected date to be before required date."}function custom(validator){return validator}function email(){return matches(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,"Expected a valid email address.")}function endsWith(suffix){return (value,_rawEnv)=>value.endsWith(suffix)||"Expected value to end with required suffix."}function finite(){return (value,_rawEnv)=>Number.isFinite(value)||"Expected a finite number."}function future(){return (value,_rawEnv)=>value>new Date||"Expected a future date."}function includes(text){return (value,_rawEnv)=>value.includes(text)||"Expected value to include required text."}function integer(){return (value,_rawEnv)=>Number.isInteger(value)||"Expected an integer value."}function length(expected){return (value,_rawEnv)=>value.length===expected||`Expected length ${expected}.`}function matches(pattern,message){return (value,_rawEnv)=>pattern.test(value)||(message??"Expected value to match required pattern.")}function max(maximum){return (value,_rawEnv)=>value<=maximum||`Expected a value less than or equal to ${maximum}.`}function maxItems(maximum){return (value,_rawEnv)=>value.length<=maximum||`Expected no more than ${maximum} items.`}function maxLength(length2){return (value,_rawEnv)=>value.length<=length2||`Expected a maximum length of ${length2}.`}function min(minimum){return (value,_rawEnv)=>value>=minimum||`Expected a value greater than or equal to ${minimum}.`}function minItems(minimum){return (value,_rawEnv)=>value.length>=minimum||`Expected at least ${minimum} items.`}function minLength(length2){return (value,_rawEnv)=>value.length>=length2||`Expected a minimum length of ${length2}.`}function negative(){return (value,_rawEnv)=>value<0||"Expected a negative value."}function not(validator){return (value,rawEnv)=>validator(value,rawEnv)===true?"Value must not satisfy this validation.":true}function oneOf(allowed){return (value,_rawEnv)=>allowed.includes(value)||`Expected one of: ${allowed.join(", ")}.`}function optional(validator){return (value,rawEnv)=>{if(value===void 0)return true;return validator(value,rawEnv)}}function past(){return (value,_rawEnv)=>value<new Date||"Expected a past date."}function positive(){return (value,_rawEnv)=>value>0||"Expected a positive value."}function range(minimum,maximum){return (value,_rawEnv)=>value>=minimum&&value<=maximum||`Expected a value greater than or equal to ${minimum} and less than or equal to ${maximum}.`}function refine(validator,message){return (value,rawEnv)=>validator(value,rawEnv)===true?true:message}function required(allowEmptyString=false){return (value,_rawEnv)=>{if(value===void 0||value===null){return "This variable is required."}if(!allowEmptyString&&typeof value==="string"&&value.length===0){return "This variable is required."}return true}}function safeInteger(){return (value,_rawEnv)=>Number.isSafeInteger(value)||"Expected a safe integer."}function unique(){return (value,_rawEnv)=>new Set(value).size===value.length||"Expected all items to be unique."}function url(){return (value,_rawEnv)=>{try{new URL(value);return true}catch{return "Expected a valid absolute URL."}}}function uuid(versions=[1,2,3,4,5,6,7,8]){return (value,_rawEnv)=>{const match=/^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f])[0-9a-f]{3}-([89ab])[0-9a-f]{3}-([0-9a-f]{12})$/i.exec(value);if(!match){return "Expected a valid UUID ."}const versionDigit=match[3];if(versionDigit===void 0){return "Expected a valid UUID ."}const version=Number.parseInt(versionDigit,16);if(!versions.includes(version)){return `Expected UUID version ${versions.join(", ")}.`}return true}}function uuidVersion(number){return uuid([number])}var processors={base64,parseJSON,split,toArray,toBigInt,toBoolean,toDate,toInteger,toLowerCase,toNumber,toRegExp,toString,toURL,toUpperCase,trim};var validators={after,all,any,before,custom,email,endsWith,enum:oneOf,finite,future,includes,integer,length,matches,max,maxItems,maxLength,min,minItems,minLength,negative,not,oneOf,optional,past,positive,range,refine,regex:matches,required,safeInteger,unique,url,uuid,uuidVersion};
1
+ // src/helpers/processors.ts
2
+ function describe(value) {
3
+ if (value === void 0) return "undefined";
4
+ if (value === null) return "null";
5
+ return `a ${typeof value}`;
6
+ }
7
+ function toArray(separator = ",", processors2 = []) {
8
+ return (value) => {
9
+ const items = Array.isArray(value) ? value : typeof value === "string" && value.trim() !== "" ? value.split(separator).map((item) => item.trim()) : [];
10
+ return items.map((item) => {
11
+ return processors2.reduce((current, processor) => processor(current), item);
12
+ });
13
+ };
14
+ }
15
+ function base64() {
16
+ return (value) => {
17
+ try {
18
+ return Buffer.from(String(value), "base64");
19
+ } catch {
20
+ throw new Error("Expected a valid base64 value.");
21
+ }
22
+ };
23
+ }
24
+ function toBigInt() {
25
+ return (value) => {
26
+ try {
27
+ return BigInt(String(value));
28
+ } catch {
29
+ throw new Error("Expected a bigint value.");
30
+ }
31
+ };
32
+ }
33
+ function toBoolean() {
34
+ return (value) => {
35
+ if (typeof value === "boolean") return value;
36
+ const normalized = String(value).trim().toLowerCase();
37
+ if (["true", "1", "yes", "on"].includes(normalized)) return true;
38
+ if (["false", "0", "no", "off"].includes(normalized)) return false;
39
+ throw new Error(
40
+ `Expected a boolean-like value (true/false/1/0/yes/no/on/off), received ${describe(value)}.`
41
+ );
42
+ };
43
+ }
44
+ function toDate() {
45
+ return (value) => {
46
+ const result = new Date(String(value));
47
+ if (Number.isNaN(result.getTime())) {
48
+ throw new Error("Expected a valid date.");
49
+ }
50
+ return result;
51
+ };
52
+ }
53
+ function toInteger() {
54
+ return (value) => {
55
+ const parsed = toNumber()(value);
56
+ if (!Number.isInteger(parsed)) {
57
+ throw new Error("Expected an integer value.");
58
+ }
59
+ return parsed;
60
+ };
61
+ }
62
+ function parseJSON() {
63
+ return (value) => {
64
+ if (typeof value !== "string") {
65
+ if (value === void 0) {
66
+ throw new Error("Expected a JSON string, received undefined.");
67
+ }
68
+ return value;
69
+ }
70
+ try {
71
+ return JSON.parse(value);
72
+ } catch {
73
+ throw new Error("Expected a valid JSON string, but parsing failed.");
74
+ }
75
+ };
76
+ }
77
+ function toLowerCase() {
78
+ return (value) => String(value ?? "").toLowerCase();
79
+ }
80
+ function toNumber() {
81
+ return (value) => {
82
+ if (typeof value === "string" && value.trim() === "") {
83
+ throw new Error("Expected a numeric value, received an empty string.");
84
+ }
85
+ const result = typeof value === "number" ? value : Number(value);
86
+ if (Number.isNaN(result)) {
87
+ throw new Error(`Expected a numeric value, received ${describe(value)}.`);
88
+ }
89
+ return result;
90
+ };
91
+ }
92
+ function toRegExp() {
93
+ return (value) => {
94
+ try {
95
+ return new RegExp(String(value));
96
+ } catch {
97
+ throw new Error("Expected a valid regular expression.");
98
+ }
99
+ };
100
+ }
101
+ function split(separator = ",") {
102
+ return (value) => {
103
+ if (typeof value !== "string") return [];
104
+ return value.split(separator).map((item) => item.trim());
105
+ };
106
+ }
107
+ function toString() {
108
+ return (value) => {
109
+ if (value === void 0 || value === null) return "";
110
+ return typeof value === "string" ? value : String(value);
111
+ };
112
+ }
113
+ function trim() {
114
+ return (value) => String(value ?? "").trim();
115
+ }
116
+ function toUpperCase() {
117
+ return (value) => String(value ?? "").toUpperCase();
118
+ }
119
+ function toURL() {
120
+ return (value) => {
121
+ try {
122
+ return new URL(String(value ?? ""));
123
+ } catch {
124
+ throw new Error("Expected a valid absolute URL.");
125
+ }
126
+ };
127
+ }
128
+
129
+ // src/helpers/validators.ts
130
+ function after(date) {
131
+ return (value, _rawEnv) => value > date || "Expected date to be after required date.";
132
+ }
133
+ function all(...validators2) {
134
+ return (value, rawEnv) => {
135
+ for (const validator of validators2) {
136
+ const result = validator(value, rawEnv);
137
+ if (result !== true) return result;
138
+ }
139
+ return true;
140
+ };
141
+ }
142
+ function any(...validators2) {
143
+ return (value, rawEnv) => {
144
+ for (const validator of validators2) {
145
+ if (validator(value, rawEnv) === true) return true;
146
+ }
147
+ return "Value did not satisfy any validation.";
148
+ };
149
+ }
150
+ function before(date) {
151
+ return (value, _rawEnv) => value < date || "Expected date to be before required date.";
152
+ }
153
+ function custom(validator) {
154
+ return validator;
155
+ }
156
+ function email() {
157
+ return matches(/^[^\s@]+@[^\s@]+\.[^\s@]+$/, "Expected a valid email address.");
158
+ }
159
+ function endsWith(suffix) {
160
+ return (value, _rawEnv) => value.endsWith(suffix) || "Expected value to end with required suffix.";
161
+ }
162
+ function finite() {
163
+ return (value, _rawEnv) => Number.isFinite(value) || "Expected a finite number.";
164
+ }
165
+ function future() {
166
+ return (value, _rawEnv) => value > /* @__PURE__ */ new Date() || "Expected a future date.";
167
+ }
168
+ function includes(text) {
169
+ return (value, _rawEnv) => value.includes(text) || "Expected value to include required text.";
170
+ }
171
+ function integer() {
172
+ return (value, _rawEnv) => Number.isInteger(value) || "Expected an integer value.";
173
+ }
174
+ function length(expected) {
175
+ return (value, _rawEnv) => value.length === expected || `Expected length ${expected}.`;
176
+ }
177
+ function matches(pattern, message) {
178
+ return (value, _rawEnv) => pattern.test(value) || (message ?? "Expected value to match required pattern.");
179
+ }
180
+ function max(maximum) {
181
+ return (value, _rawEnv) => value <= maximum || `Expected a value less than or equal to ${maximum}.`;
182
+ }
183
+ function maxItems(maximum) {
184
+ return (value, _rawEnv) => value.length <= maximum || `Expected no more than ${maximum} items.`;
185
+ }
186
+ function maxLength(length2) {
187
+ return (value, _rawEnv) => value.length <= length2 || `Expected a maximum length of ${length2}.`;
188
+ }
189
+ function min(minimum) {
190
+ return (value, _rawEnv) => value >= minimum || `Expected a value greater than or equal to ${minimum}.`;
191
+ }
192
+ function minItems(minimum) {
193
+ return (value, _rawEnv) => value.length >= minimum || `Expected at least ${minimum} items.`;
194
+ }
195
+ function minLength(length2) {
196
+ return (value, _rawEnv) => value.length >= length2 || `Expected a minimum length of ${length2}.`;
197
+ }
198
+ function negative() {
199
+ return (value, _rawEnv) => value < 0 || "Expected a negative value.";
200
+ }
201
+ function not(validator) {
202
+ return (value, rawEnv) => validator(value, rawEnv) === true ? "Value must not satisfy this validation." : true;
203
+ }
204
+ function oneOf(allowed) {
205
+ return (value, _rawEnv) => allowed.includes(value) || `Expected one of: ${allowed.join(", ")}.`;
206
+ }
207
+ function optional(validator) {
208
+ return (value, rawEnv) => {
209
+ if (value === void 0) return true;
210
+ return validator(value, rawEnv);
211
+ };
212
+ }
213
+ function past() {
214
+ return (value, _rawEnv) => value < /* @__PURE__ */ new Date() || "Expected a past date.";
215
+ }
216
+ function positive() {
217
+ return (value, _rawEnv) => value > 0 || "Expected a positive value.";
218
+ }
219
+ function range(minimum, maximum) {
220
+ return (value, _rawEnv) => value >= minimum && value <= maximum || `Expected a value greater than or equal to ${minimum} and less than or equal to ${maximum}.`;
221
+ }
222
+ function refine(validator, message) {
223
+ return (value, rawEnv) => validator(value, rawEnv) === true ? true : message;
224
+ }
225
+ function required(allowEmptyString = false) {
226
+ return (value, _rawEnv) => {
227
+ if (value === void 0 || value === null) {
228
+ return "This variable is required.";
229
+ }
230
+ if (!allowEmptyString && typeof value === "string" && value.length === 0) {
231
+ return "This variable is required.";
232
+ }
233
+ return true;
234
+ };
235
+ }
236
+ function safeInteger() {
237
+ return (value, _rawEnv) => Number.isSafeInteger(value) || "Expected a safe integer.";
238
+ }
239
+ function unique() {
240
+ return (value, _rawEnv) => new Set(value).size === value.length || "Expected all items to be unique.";
241
+ }
242
+ function url() {
243
+ return (value, _rawEnv) => {
244
+ try {
245
+ new URL(value);
246
+ return true;
247
+ } catch {
248
+ return "Expected a valid absolute URL.";
249
+ }
250
+ };
251
+ }
252
+ function uuid(versions = [1, 2, 3, 4, 5, 6, 7, 8]) {
253
+ return (value, _rawEnv) => {
254
+ const match = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f])[0-9a-f]{3}-([89ab])[0-9a-f]{3}-([0-9a-f]{12})$/i.exec(
255
+ value
256
+ );
257
+ if (!match) {
258
+ return "Expected a valid UUID .";
259
+ }
260
+ const versionDigit = match[3];
261
+ if (versionDigit === void 0) {
262
+ return "Expected a valid UUID .";
263
+ }
264
+ const version = Number.parseInt(versionDigit, 16);
265
+ if (!versions.includes(version)) {
266
+ return `Expected UUID version ${versions.join(", ")}.`;
267
+ }
268
+ return true;
269
+ };
270
+ }
271
+ function uuidVersion(number) {
272
+ return uuid([number]);
273
+ }
274
+
275
+ // src/helpers/index.ts
276
+ var processors = {
277
+ /** Decodes a base64 string into a `Buffer`. */
278
+ base64,
279
+ /** Parses a JSON string; passes non-string values through unchanged. */
280
+ parseJSON,
281
+ /** Splits a string on `separator` into a trimmed string array; returns `[]` for non-string input. */
282
+ split,
283
+ /** Splits a delimited string (or passes through an array) into items, running each through `processors` in order. */
284
+ toArray,
285
+ /** Coerces a value to a `bigint`. */
286
+ toBigInt,
287
+ /** Coerces common boolean-like strings (`true`/`1`/`yes`/`on`, and their opposites) into a real boolean. */
288
+ toBoolean,
289
+ /** Parses a value into a `Date`. */
290
+ toDate,
291
+ /** Coerces a value to a number and requires it to be an integer. */
292
+ toInteger,
293
+ /** Lowercases a string (coercing nullish values to `""` first). */
294
+ toLowerCase,
295
+ /** Coerces a value to a number, rejecting empty/whitespace-only strings instead of silently resolving to `0`. */
296
+ toNumber,
297
+ /** Compiles a value into a `RegExp`. */
298
+ toRegExp,
299
+ /** Coerces a value to a string, treating nullish values as `""`. */
300
+ toString,
301
+ /** Parses a value into a `URL`, treating nullish values as `""` first. */
302
+ toURL,
303
+ /** Uppercases a string (coercing nullish values to `""` first). */
304
+ toUpperCase,
305
+ /** Trims surrounding whitespace from a string (coercing nullish values to `""` first). */
306
+ trim
307
+ };
308
+ var validators = {
309
+ /** Passes when the date value is strictly after `date`. */
310
+ after,
311
+ /** Passes only when every wrapped validator passes; returns the first failing message. */
312
+ all,
313
+ /** Passes when at least one wrapped validator passes. */
314
+ any,
315
+ /** Passes when the date value is strictly before `date`. */
316
+ before,
317
+ /** Identity wrapper for a hand-written `Validator<T>` -- no behavior change, just a fluent entry point alongside the other helpers. */
318
+ custom,
319
+ /** Passes for a plausibly-shaped email address (`local@domain`). */
320
+ email,
321
+ /** Passes when the string ends with `suffix`. */
322
+ endsWith,
323
+ /** Alias for `oneOf` -- passes when the value is one of the `allowed` values. */
324
+ enum: oneOf,
325
+ /** Passes when the number is finite (rejects `Infinity`/`-Infinity`/`NaN`). */
326
+ finite,
327
+ /** Passes when the date is strictly after the current time. */
328
+ future,
329
+ /** Passes when the string contains `text` as a substring. */
330
+ includes,
331
+ /** Passes when the number is an integer. */
332
+ integer,
333
+ /** Passes when the string's length is exactly `expected`. */
334
+ length,
335
+ /** Passes when the string matches `pattern`; `message` overrides the default failure text. */
336
+ matches,
337
+ /** Passes when the number is less than or equal to `maximum`. */
338
+ max,
339
+ /** Passes when the array has at most `maximum` items. */
340
+ maxItems,
341
+ /** Passes when the string's length is at most `length`. */
342
+ maxLength,
343
+ /** Passes when the number is greater than or equal to `minimum`. */
344
+ min,
345
+ /** Passes when the array has at least `minimum` items. */
346
+ minItems,
347
+ /** Passes when the string's length is at least `length`. */
348
+ minLength,
349
+ /** Passes when the number is strictly negative. */
350
+ negative,
351
+ /** Inverts a validator: passes when the wrapped validator fails, and vice versa. */
352
+ not,
353
+ /** Passes when the value is one of the `allowed` values. */
354
+ oneOf,
355
+ /** Passes when the value is undefined, otherwise delegates to the provided validator. */
356
+ optional,
357
+ /** Passes when the date is strictly before the current time. */
358
+ past,
359
+ /** Passes when the number is strictly positive. */
360
+ positive,
361
+ /** Passes when the number is within `[minimum, maximum]` inclusive. */
362
+ range,
363
+ /** Runs the wrapped validator but replaces its failure message with `message`. */
364
+ refine,
365
+ /** Alias for `matches` -- passes when the string matches `pattern`. */
366
+ regex: matches,
367
+ /** Passes when the value is defined and, unless `allowEmptyString` is set, non-empty. */
368
+ required,
369
+ /** Passes when the number is a safe integer (`Number.isSafeInteger`). */
370
+ safeInteger,
371
+ /** Passes when every item in the array is unique. */
372
+ unique,
373
+ /** Passes when the string is a valid absolute URL. */
374
+ url,
375
+ /** Passes when the string is a valid UUID of one of the given `versions` (default: any of 1-8). */
376
+ uuid,
377
+ /** Shorthand for `uuid([version])` -- passes only for that exact UUID version. */
378
+ uuidVersion
379
+ };
2
380
 
3
381
  export { processors, validators };
4
382
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helpers/processors.ts","../src/helpers/validators.ts","../src/helpers/index.ts"],"names":["processors","validators","length"],"mappings":"AASA,SAAS,QAAA,CAAS,KAAA,CAAwB,CACxC,GAAI,KAAA,GAAU,MAAA,CAAW,OAAO,WAAA,CAChC,GAAI,KAAA,GAAU,IAAA,CAAM,OAAO,OAC3B,OAAO,CAAA,EAAA,EAAK,OAAO,KAAK,CAAA,CAC1B,CAGO,SAAS,OAAA,CACd,SAAA,CAA6B,GAAA,CAC7BA,WAAAA,CAAmC,EAAC,CACpB,CAChB,OAAQ,KAAA,EAAU,CAChB,MAAM,KAAA,CAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,CAC7B,KAAA,CACA,OAAO,KAAA,GAAU,QAAA,EAAY,KAAA,CAAM,IAAA,EAAK,GAAM,EAAA,CAC5C,KAAA,CAAM,KAAA,CAAM,SAAS,CAAA,CAAE,GAAA,CAAK,IAAA,EAAS,IAAA,CAAK,IAAA,EAAM,CAAA,CAChD,GAEN,OAAO,KAAA,CAAM,GAAA,CAAK,IAAA,EAAS,CACzB,OAAOA,WAAAA,CAAW,MAAA,CAAO,CAAC,OAAA,CAAS,SAAA,GAAc,SAAA,CAAU,OAAO,CAAA,CAAG,IAAI,CAC3E,CAAC,CACH,CACF,CAGO,SAAS,MAAA,EAA4B,CAC1C,OAAQ,KAAA,EAAU,CAChB,GAAI,CACF,OAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,CAAA,CAAG,QAAQ,CAC5C,CAAA,KAAQ,CACN,MAAM,IAAI,KAAA,CAAM,gCAAgC,CAClD,CACF,CACF,CAGO,SAAS,QAAA,EAA8B,CAC5C,OAAQ,KAAA,EAAU,CAChB,GAAI,CACF,OAAO,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC,CAC7B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AEA,MAAA,CAEA,OAAA,CAEA,GAAA,CAEA,QAAA,CAEA,UAEA,GAAA,CAEA,QAAA,CAEA,SAAA,CAEA,QAAA,CAEA,GAAA,CAEA,KAAA,CAEA,QAAA,CAEA,IAAA,CAEA,SAEA,KAAA,CAEA,MAAA,CAEA,KAAA,CAAO,OAAA,CAEP,QAAA,CAEA,WAAA,CAEA,MAAA,CAEA,GAAA,CAEA,KAEA,WACF","file":"helpers.js","sourcesContent":["import type { Processor } from \"../runtime/index.js\"\n\n/**\n * Convenience processors. Purely optional sugar over `Processor<T>` --\n * the runtime and generator never import from this module. Error messages\n * describe the *type* of an invalid value, never its content, so a\n * misconfigured secret is never echoed back through a thrown error.\n */\n\nfunction describe(value: unknown): string {\n if (value === undefined) return \"undefined\"\n if (value === null) return \"null\"\n return `a ${typeof value}`\n}\n\n/** Splits a delimited string (or passes through an array) into items, running each through `processors` in order. */\nexport function toArray<T>(\n separator: string | RegExp = \",\",\n processors: Processor<unknown>[] = [],\n): Processor<T[]> {\n return (value) => {\n const items = Array.isArray(value)\n ? value\n : typeof value === \"string\" && value.trim() !== \"\"\n ? value.split(separator).map((item) => item.trim())\n : []\n\n return items.map((item) => {\n return processors.reduce((current, processor) => processor(current), item) as T\n })\n }\n}\n\n/** Decodes a base64 string into a `Buffer`. */\nexport function base64(): Processor<Buffer> {\n return (value) => {\n try {\n return Buffer.from(String(value), \"base64\")\n } catch {\n throw new Error(\"Expected a valid base64 value.\")\n }\n }\n}\n\n/** Coerces a value to a `bigint`. */\nexport function toBigInt(): Processor<bigint> {\n return (value) => {\n try {\n return BigInt(String(value))\n } catch {\n throw new Error(\"Expected a bigint value.\")\n }\n }\n}\n\n/** Coerces common boolean-like strings (`true`/`1`/`yes`/`on`, and their opposites) into a real boolean. */\nexport function toBoolean(): Processor<boolean> {\n return (value) => {\n // Bypassing this fast-path is behaviorally equivalent, not a real gap:\n // `String(true)`/`String(false)` round-trip through the exact\n // \"true\"/\"false\" strings already recognized below, so falling through\n // to the general string-parsing path gives the identical result for a\n // real boolean input either way. Hand-verified: mutating this and\n // running the real suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n if (typeof value === \"boolean\") return value\n const normalized = String(value).trim().toLowerCase()\n if ([\"true\", \"1\", \"yes\", \"on\"].includes(normalized)) return true\n if ([\"false\", \"0\", \"no\", \"off\"].includes(normalized)) return false\n throw new Error(\n `Expected a boolean-like value (true/false/1/0/yes/no/on/off), received ${describe(value)}.`,\n )\n }\n}\n\n/** Parses a value into a `Date`. */\nexport function toDate(): Processor<Date> {\n return (value) => {\n const result = new Date(String(value))\n\n if (Number.isNaN(result.getTime())) {\n throw new Error(\"Expected a valid date.\")\n }\n\n return result\n }\n}\n\n/** Coerces a value to a number and requires it to be an integer. */\nexport function toInteger(): Processor<number> {\n return (value) => {\n const parsed = toNumber()(value)\n\n if (!Number.isInteger(parsed)) {\n throw new Error(\"Expected an integer value.\")\n }\n\n return parsed\n }\n}\n\n/** Parses a JSON string; passes non-string values through unchanged. */\nexport function parseJSON<T = unknown>(): Processor<T> {\n return (value) => {\n if (typeof value !== \"string\") {\n if (value === undefined) {\n throw new Error(\"Expected a JSON string, received undefined.\")\n }\n return value as T\n }\n try {\n return JSON.parse(value) as T\n } catch {\n throw new Error(\"Expected a valid JSON string, but parsing failed.\")\n }\n }\n}\n\n/** Lowercases a string (coercing nullish values to `\"\"` first). */\nexport function toLowerCase(): Processor<string> {\n return (value) => String(value ?? \"\").toLowerCase()\n}\n\n/** Coerces a value to a number, rejecting empty/whitespace-only strings instead of silently resolving to `0`. */\nexport function toNumber(): Processor<number> {\n return (value) => {\n // `Number(\"\")` is `0`, not `NaN` -- without this check a blank env var would\n // silently resolve to the number 0 instead of failing, slipping past\n // validators.required() too (that checks the processed value, not the raw string).\n if (typeof value === \"string\" && value.trim() === \"\") {\n throw new Error(\"Expected a numeric value, received an empty string.\")\n }\n // Bypassing this type-check (always going through `Number(value)`) is\n // behaviorally equivalent, not a real gap: `Number()` is idempotent on\n // an already-number input (`Number(x) === x` for every real number,\n // including NaN and -0), so the ternary's two branches always produce\n // the same result. Hand-verified: mutating this and running the real\n // suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n const result = typeof value === \"number\" ? value : Number(value)\n if (Number.isNaN(result)) {\n throw new Error(`Expected a numeric value, received ${describe(value)}.`)\n }\n return result\n }\n}\n\n/** Compiles a value into a `RegExp`. */\nexport function toRegExp(): Processor<RegExp> {\n return (value) => {\n try {\n return new RegExp(String(value))\n } catch {\n throw new Error(\"Expected a valid regular expression.\")\n }\n }\n}\n\n/** Splits a string on `separator` into a trimmed string array; returns `[]` for non-string input. */\nexport function split(separator = \",\"): Processor<string[]> {\n return (value) => {\n if (typeof value !== \"string\") return []\n\n return value.split(separator).map((item) => item.trim())\n }\n}\n\n/** Coerces a value to a string, treating nullish values as `\"\"`. */\nexport function toString(): Processor<string> {\n return (value) => {\n if (value === undefined || value === null) return \"\"\n // Bypassing this type-check (always going through `String(value)`) is\n // behaviorally equivalent, not a real gap: `String()` is idempotent on\n // an already-string input. Hand-verified: mutating this and running the\n // real suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n return typeof value === \"string\" ? value : String(value)\n }\n}\n\n/** Trims surrounding whitespace from a string (coercing nullish values to `\"\"` first). */\nexport function trim(): Processor<string> {\n return (value) => String(value ?? \"\").trim()\n}\n\n/** Uppercases a string (coercing nullish values to `\"\"` first). */\nexport function toUpperCase(): Processor<string> {\n return (value) => String(value ?? \"\").toUpperCase()\n}\n\n/** Parses a value into a `URL`, treating nullish values as `\"\"` first. */\nexport function toURL(): Processor<URL> {\n return (value) => {\n try {\n // The `\"\"` fallback for nullish input is behaviorally equivalent to\n // any other non-URL-shaped fallback string: `new URL(...)` throws for\n // BOTH \"\" and any garbage string, and both land in the same generic\n // catch below with the same message -- there is no distinguishable\n // outcome. Hand-verified: mutating this and running the real suite\n // passes unchanged.\n // Stryker disable next-line StringLiteral\n return new URL(String(value ?? \"\"))\n } catch {\n throw new Error(\"Expected a valid absolute URL.\")\n }\n }\n}\n","import type { Validator } from \"../runtime/index.js\"\n\n/** Passes when the date value is strictly after `date`. */\nexport function after(date: Date): Validator<Date> {\n return (value, _rawEnv) => value > date || \"Expected date to be after required date.\"\n}\n\n/** Passes only when every wrapped validator passes; returns the first failing message. */\nexport function all<T>(...validators: Validator<T>[]): Validator<T> {\n return (value, rawEnv) => {\n for (const validator of validators) {\n const result = validator(value, rawEnv)\n if (result !== true) return result\n }\n\n return true\n }\n}\n\n/** Passes when at least one wrapped validator passes. */\nexport function any<T>(...validators: Validator<T>[]): Validator<T> {\n return (value, rawEnv) => {\n for (const validator of validators) {\n if (validator(value, rawEnv) === true) return true\n }\n\n return \"Value did not satisfy any validation.\"\n }\n}\n\n/** Passes when the date value is strictly before `date`. */\nexport function before(date: Date): Validator<Date> {\n return (value, _rawEnv) => value < date || \"Expected date to be before required date.\"\n}\n\n/** Identity wrapper for a hand-written `Validator<T>` -- no behavior change, just a fluent entry point alongside the other helpers. */\nexport function custom<T>(validator: Validator<T>): Validator<T> {\n return validator\n}\n\n/** Passes for a plausibly-shaped email address (`local@domain`). */\nexport function email(): Validator<string> {\n return matches(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/, \"Expected a valid email address.\")\n}\n\n/** Passes when the string ends with `suffix`. */\nexport function endsWith(suffix: string): Validator<string> {\n return (value, _rawEnv) => value.endsWith(suffix) || \"Expected value to end with required suffix.\"\n}\n\n/** Passes when the number is finite (rejects `Infinity`/`-Infinity`/`NaN`). */\nexport function finite(): Validator<number> {\n return (value, _rawEnv) => Number.isFinite(value) || \"Expected a finite number.\"\n}\n\n/** Passes when the date is strictly after the current time. */\nexport function future(): Validator<Date> {\n return (value, _rawEnv) => value > new Date() || \"Expected a future date.\"\n}\n\n/** Passes when the string contains `text` as a substring. */\nexport function includes(text: string): Validator<string> {\n return (value, _rawEnv) => value.includes(text) || \"Expected value to include required text.\"\n}\n\n/** Passes when the number is an integer. */\nexport function integer(): Validator<number> {\n return (value, _rawEnv) => Number.isInteger(value) || \"Expected an integer value.\"\n}\n\n/** Passes when the string's length is exactly `expected`. */\nexport function length(expected: number): Validator<string> {\n return (value, _rawEnv) => value.length === expected || `Expected length ${expected}.`\n}\n\n/** Passes when the string matches `pattern`; `message` overrides the default failure text. */\nexport function matches(pattern: RegExp, message?: string): Validator<string> {\n return (value, _rawEnv) =>\n pattern.test(value) || (message ?? \"Expected value to match required pattern.\")\n}\n\n/** Passes when the number is less than or equal to `maximum`. */\nexport function max(maximum: number): Validator<number> {\n return (value, _rawEnv) =>\n value <= maximum || `Expected a value less than or equal to ${maximum}.`\n}\n\n/** Passes when the array has at most `maximum` items. */\nexport function maxItems<T>(maximum: number): Validator<T[]> {\n return (value, _rawEnv) => value.length <= maximum || `Expected no more than ${maximum} items.`\n}\n\n/** Passes when the string's length is at most `length`. */\nexport function maxLength(length: number): Validator<string> {\n return (value, _rawEnv) => value.length <= length || `Expected a maximum length of ${length}.`\n}\n\n/** Passes when the number is greater than or equal to `minimum`. */\nexport function min(minimum: number): Validator<number> {\n return (value, _rawEnv) =>\n value >= minimum || `Expected a value greater than or equal to ${minimum}.`\n}\n\n/** Passes when the array has at least `minimum` items. */\nexport function minItems<T>(minimum: number): Validator<T[]> {\n return (value, _rawEnv) => value.length >= minimum || `Expected at least ${minimum} items.`\n}\n\n/** Passes when the string's length is at least `length`. */\nexport function minLength(length: number): Validator<string> {\n return (value, _rawEnv) => value.length >= length || `Expected a minimum length of ${length}.`\n}\n\n/** Passes when the number is strictly negative. */\nexport function negative(): Validator<number> {\n return (value, _rawEnv) => value < 0 || \"Expected a negative value.\"\n}\n\n/** Inverts a validator: passes when the wrapped validator fails, and vice versa. */\nexport function not<T>(validator: Validator<T>): Validator<T> {\n return (value, rawEnv) =>\n validator(value, rawEnv) === true ? \"Value must not satisfy this validation.\" : true\n}\n\n/** Passes when the value is one of the `allowed` values. */\nexport function oneOf<T>(allowed: readonly T[]): Validator<T> {\n return (value, _rawEnv) => allowed.includes(value) || `Expected one of: ${allowed.join(\", \")}.`\n}\n\n/** Passes when the value is undefined, otherwise delegates to the provided validator. */\nexport function optional<T>(validator: Validator<T>): Validator<T | undefined> {\n return (value, rawEnv) => {\n if (value === undefined) return true\n return validator(value, rawEnv)\n }\n}\n\n/** Passes when the date is strictly before the current time. */\nexport function past(): Validator<Date> {\n return (value, _rawEnv) => value < new Date() || \"Expected a past date.\"\n}\n\n/** Passes when the number is strictly positive. */\nexport function positive(): Validator<number> {\n return (value, _rawEnv) => value > 0 || \"Expected a positive value.\"\n}\n\n/** Passes when the number is within `[minimum, maximum]` inclusive. */\nexport function range(minimum: number, maximum: number): Validator<number> {\n return (value, _rawEnv) =>\n (value >= minimum && value <= maximum) ||\n `Expected a value greater than or equal to ${minimum} and less than or equal to ${maximum}.`\n}\n\n/** Runs the wrapped validator but replaces its failure message with `message`. */\nexport function refine<T>(validator: Validator<T>, message: string): Validator<T> {\n return (value, rawEnv) => (validator(value, rawEnv) === true ? true : message)\n}\n\n/** Passes when the value is defined and, unless `allowEmptyString` is set, non-empty. */\nexport function required(allowEmptyString = false): Validator<unknown> {\n return (value, _rawEnv) => {\n if (value === undefined || value === null) {\n return \"This variable is required.\"\n }\n\n if (!allowEmptyString && typeof value === \"string\" && value.length === 0) {\n return \"This variable is required.\"\n }\n\n return true\n }\n}\n\n/** Passes when the number is a safe integer (`Number.isSafeInteger`). */\nexport function safeInteger(): Validator<number> {\n return (value, _rawEnv) => Number.isSafeInteger(value) || \"Expected a safe integer.\"\n}\n\n/** Passes when every item in the array is unique. */\nexport function unique<T>(): Validator<T[]> {\n return (value, _rawEnv) =>\n new Set(value).size === value.length || \"Expected all items to be unique.\"\n}\n\n/** Passes when the string is a valid absolute URL. */\nexport function url(): Validator<string> {\n return (value, _rawEnv) => {\n try {\n new URL(value)\n return true\n } catch {\n return \"Expected a valid absolute URL.\"\n }\n }\n}\n\n/** Passes when the string is a valid UUID of one of the given `versions` (default: any of 1-8). */\nexport function uuid(versions: readonly number[] = [1, 2, 3, 4, 5, 6, 7, 8]): Validator<string> {\n return (value, _rawEnv) => {\n const match =\n /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f])[0-9a-f]{3}-([89ab])[0-9a-f]{3}-([0-9a-f]{12})$/i.exec(\n value,\n )\n\n if (!match) {\n return \"Expected a valid UUID .\"\n }\n\n // Capture group 3 is mandatory in the pattern (no `?`), so a successful\n // match always captures it -- noUncheckedIndexedAccess can't see that\n // invariant through RegExpExecArray's numeric index signature. A real\n // guard (not a non-null assertion, forbidden in src/) satisfies the type\n // checker without hiding the possibility. Hand-verified: mutating this\n // whole guard (its condition, its block, and its message) and running\n // the real suite passes unchanged.\n const versionDigit = match[3]\n // Stryker disable next-line ConditionalExpression, BlockStatement\n if (versionDigit === undefined) {\n // Stryker disable next-line StringLiteral\n return \"Expected a valid UUID .\"\n }\n const version = Number.parseInt(versionDigit, 16)\n\n if (!versions.includes(version)) {\n return `Expected UUID version ${versions.join(\", \")}.`\n }\n\n return true\n }\n}\n\n/** Shorthand for `uuid([version])` -- passes only for that exact UUID version. */\nexport function uuidVersion(number: number): Validator<string> {\n return uuid([number])\n}\n","/**\n * Optional convenience helpers for common processor/validator patterns.\n * Entirely separate from the core runtime -- `defineEnv`/`validateEnv` have\n * no knowledge of this module and work identically without it.\n *\n * Usage: `processors.toNumber()`, `validators.range(1, 65535)`.\n *\n * Deliberately built from explicit named imports assembled into plain object\n * literals, not `export * as processors from \"./processors.js\"`. A bundler\n * (tsup/esbuild) lowers that `export * as` form into a namespace-construction\n * helper call it can't prove side-effect-free, which defeats tree-shaking in\n * a *second*, downstream bundling pass (a consumer's own bundler bundling\n * this already-bundled package): importing only `processors` would still\n * ship all of `validators`' code. A plain object literal of already-imported\n * bindings has no such call in the way, so `import { processors } from\n * \"env-cap/helpers\"` alone drops `validators` entirely.\n */\nimport {\n base64,\n parseJSON,\n split,\n toArray,\n toBigInt,\n toBoolean,\n toDate,\n toInteger,\n toLowerCase,\n toNumber,\n toRegExp,\n toString,\n toURL,\n toUpperCase,\n trim,\n} from \"./processors.js\"\nimport {\n after,\n all,\n any,\n before,\n custom,\n email,\n endsWith,\n finite,\n future,\n includes,\n integer as integerValidator,\n length,\n matches,\n max,\n maxItems,\n maxLength,\n min,\n minItems,\n minLength,\n negative,\n not,\n oneOf,\n optional,\n past,\n positive,\n range,\n refine,\n required,\n safeInteger,\n unique,\n url as urlValidator,\n uuid,\n uuidVersion,\n} from \"./validators.js\"\n\n/**\n * Convenience {@link runtime.Processor} implementations for common coercion\n * patterns (e.g. `processors.toNumber()`).\n *\n * @remarks\n * Naming matches `@maverickcer/data-cap`'s `helpers.processors` -- but these\n * throw with a formatted `Error` message on invalid input, where data-cap's\n * silently return `undefined`. Do not assume the same failure mode when\n * moving between packages.\n */\nexport const processors = {\n /** Decodes a base64 string into a `Buffer`. */\n base64,\n /** Parses a JSON string; passes non-string values through unchanged. */\n parseJSON,\n /** Splits a string on `separator` into a trimmed string array; returns `[]` for non-string input. */\n split,\n /** Splits a delimited string (or passes through an array) into items, running each through `processors` in order. */\n toArray,\n /** Coerces a value to a `bigint`. */\n toBigInt,\n /** Coerces common boolean-like strings (`true`/`1`/`yes`/`on`, and their opposites) into a real boolean. */\n toBoolean,\n /** Parses a value into a `Date`. */\n toDate,\n /** Coerces a value to a number and requires it to be an integer. */\n toInteger,\n /** Lowercases a string (coercing nullish values to `\"\"` first). */\n toLowerCase,\n /** Coerces a value to a number, rejecting empty/whitespace-only strings instead of silently resolving to `0`. */\n toNumber,\n /** Compiles a value into a `RegExp`. */\n toRegExp,\n /** Coerces a value to a string, treating nullish values as `\"\"`. */\n toString,\n /** Parses a value into a `URL`, treating nullish values as `\"\"` first. */\n toURL,\n /** Uppercases a string (coercing nullish values to `\"\"` first). */\n toUpperCase,\n /** Trims surrounding whitespace from a string (coercing nullish values to `\"\"` first). */\n trim,\n}\n/** Convenience {@link runtime.Validator} implementations for common validation patterns (e.g. `validators.range(1, 65535)`). */\nexport const validators = {\n /** Passes when the date value is strictly after `date`. */\n after,\n /** Passes only when every wrapped validator passes; returns the first failing message. */\n all,\n /** Passes when at least one wrapped validator passes. */\n any,\n /** Passes when the date value is strictly before `date`. */\n before,\n /** Identity wrapper for a hand-written `Validator<T>` -- no behavior change, just a fluent entry point alongside the other helpers. */\n custom,\n /** Passes for a plausibly-shaped email address (`local@domain`). */\n email,\n /** Passes when the string ends with `suffix`. */\n endsWith,\n /** Alias for `oneOf` -- passes when the value is one of the `allowed` values. */\n enum: oneOf,\n /** Passes when the number is finite (rejects `Infinity`/`-Infinity`/`NaN`). */\n finite,\n /** Passes when the date is strictly after the current time. */\n future,\n /** Passes when the string contains `text` as a substring. */\n includes,\n /** Passes when the number is an integer. */\n integer: integerValidator,\n /** Passes when the string's length is exactly `expected`. */\n length,\n /** Passes when the string matches `pattern`; `message` overrides the default failure text. */\n matches,\n /** Passes when the number is less than or equal to `maximum`. */\n max,\n /** Passes when the array has at most `maximum` items. */\n maxItems,\n /** Passes when the string's length is at most `length`. */\n maxLength,\n /** Passes when the number is greater than or equal to `minimum`. */\n min,\n /** Passes when the array has at least `minimum` items. */\n minItems,\n /** Passes when the string's length is at least `length`. */\n minLength,\n /** Passes when the number is strictly negative. */\n negative,\n /** Inverts a validator: passes when the wrapped validator fails, and vice versa. */\n not,\n /** Passes when the value is one of the `allowed` values. */\n oneOf,\n /** Passes when the value is undefined, otherwise delegates to the provided validator. */\n optional,\n /** Passes when the date is strictly before the current time. */\n past,\n /** Passes when the number is strictly positive. */\n positive,\n /** Passes when the number is within `[minimum, maximum]` inclusive. */\n range,\n /** Runs the wrapped validator but replaces its failure message with `message`. */\n refine,\n /** Alias for `matches` -- passes when the string matches `pattern`. */\n regex: matches,\n /** Passes when the value is defined and, unless `allowEmptyString` is set, non-empty. */\n required,\n /** Passes when the number is a safe integer (`Number.isSafeInteger`). */\n safeInteger,\n /** Passes when every item in the array is unique. */\n unique,\n /** Passes when the string is a valid absolute URL. */\n url: urlValidator,\n /** Passes when the string is a valid UUID of one of the given `versions` (default: any of 1-8). */\n uuid,\n /** Shorthand for `uuid([version])` -- passes only for that exact UUID version. */\n uuidVersion,\n}\n"]}
1
+ {"version":3,"sources":["../src/helpers/processors.ts","../src/helpers/validators.ts","../src/helpers/index.ts"],"names":["processors","validators","length"],"mappings":";AASA,SAAS,SAAS,KAAA,EAAwB;AACxC,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,WAAA;AAChC,EAAA,IAAI,KAAA,KAAU,MAAM,OAAO,MAAA;AAC3B,EAAA,OAAO,CAAA,EAAA,EAAK,OAAO,KAAK,CAAA,CAAA;AAC1B;AAGO,SAAS,OAAA,CACd,SAAA,GAA6B,GAAA,EAC7BA,WAAAA,GAAmC,EAAC,EACpB;AAChB,EAAA,OAAO,CAAC,KAAA,KAAU;AAChB,IAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAC7B,QACA,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,IAAA,EAAK,KAAM,KAC5C,KAAA,CAAM,KAAA,CAAM,SAAS,CAAA,CAAE,GAAA,CAAI,CAAC,SAAS,IAAA,CAAK,IAAA,EAAM,CAAA,GAChD,EAAC;AAEP,IAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,KAAS;AACzB,MAAA,OAAOA,WAAAA,CAAW,OAAO,CAAC,OAAA,EAAS,cAAc,SAAA,CAAU,OAAO,GAAG,IAAI,CAAA;AAAA,IAC3E,CAAC,CAAA;AAAA,EACH,CAAA;AACF;AAGO,SAAS,MAAA,GAA4B;AAC1C,EAAA,OAAO,CAAC,KAAA,KAAU;AAChB,IAAA,IAAI;AACF,MAAA,OAAO,MAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KAAK,GAAG,QAAQ,CAAA;AAAA,IAC5C,CAAA,CAAA,MAAQ;AACN,MAAA,MAAM,IAAI,MAAM,gCAAgC,CAAA;AAAA,IAClD;AAAA,EACF,C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A;AAAA,EAEA,WAAA;AAAA;AAAA,EAEA;AACF;AAEO,IAAM,UAAA,GAAa;AAAA;AAAA,EAExB,KAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,KAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,IAAA,EAAM,KAAA;AAAA;AAAA,EAEN,MAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,OAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,SAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,SAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,KAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,IAAA;AAAA;AAAA,EAEA,QAAA;AAAA;AAAA,EAEA,KAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,KAAA,EAAO,OAAA;AAAA;AAAA,EAEP,QAAA;AAAA;AAAA,EAEA,WAAA;AAAA;AAAA,EAEA,MAAA;AAAA;AAAA,EAEA,GAAA;AAAA;AAAA,EAEA,IAAA;AAAA;AAAA,EAEA;AACF","file":"helpers.js","sourcesContent":["import type { Processor } from \"../runtime/index.js\"\n\n/**\n * Convenience processors. Purely optional sugar over `Processor<T>` --\n * the runtime and generator never import from this module. Error messages\n * describe the *type* of an invalid value, never its content, so a\n * misconfigured secret is never echoed back through a thrown error.\n */\n\nfunction describe(value: unknown): string {\n if (value === undefined) return \"undefined\"\n if (value === null) return \"null\"\n return `a ${typeof value}`\n}\n\n/** Splits a delimited string (or passes through an array) into items, running each through `processors` in order. */\nexport function toArray<T>(\n separator: string | RegExp = \",\",\n processors: Processor<unknown>[] = [],\n): Processor<T[]> {\n return (value) => {\n const items = Array.isArray(value)\n ? value\n : typeof value === \"string\" && value.trim() !== \"\"\n ? value.split(separator).map((item) => item.trim())\n : []\n\n return items.map((item) => {\n return processors.reduce((current, processor) => processor(current), item) as T\n })\n }\n}\n\n/** Decodes a base64 string into a `Buffer`. */\nexport function base64(): Processor<Buffer> {\n return (value) => {\n try {\n return Buffer.from(String(value), \"base64\")\n } catch {\n throw new Error(\"Expected a valid base64 value.\")\n }\n }\n}\n\n/** Coerces a value to a `bigint`. */\nexport function toBigInt(): Processor<bigint> {\n return (value) => {\n try {\n return BigInt(String(value))\n } catch {\n throw new Error(\"Expected a bigint value.\")\n }\n }\n}\n\n/** Coerces common boolean-like strings (`true`/`1`/`yes`/`on`, and their opposites) into a real boolean. */\nexport function toBoolean(): Processor<boolean> {\n return (value) => {\n // Bypassing this fast-path is behaviorally equivalent, not a real gap:\n // `String(true)`/`String(false)` round-trip through the exact\n // \"true\"/\"false\" strings already recognized below, so falling through\n // to the general string-parsing path gives the identical result for a\n // real boolean input either way. Hand-verified: mutating this and\n // running the real suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n if (typeof value === \"boolean\") return value\n const normalized = String(value).trim().toLowerCase()\n if ([\"true\", \"1\", \"yes\", \"on\"].includes(normalized)) return true\n if ([\"false\", \"0\", \"no\", \"off\"].includes(normalized)) return false\n throw new Error(\n `Expected a boolean-like value (true/false/1/0/yes/no/on/off), received ${describe(value)}.`,\n )\n }\n}\n\n/** Parses a value into a `Date`. */\nexport function toDate(): Processor<Date> {\n return (value) => {\n const result = new Date(String(value))\n\n if (Number.isNaN(result.getTime())) {\n throw new Error(\"Expected a valid date.\")\n }\n\n return result\n }\n}\n\n/** Coerces a value to a number and requires it to be an integer. */\nexport function toInteger(): Processor<number> {\n return (value) => {\n const parsed = toNumber()(value)\n\n if (!Number.isInteger(parsed)) {\n throw new Error(\"Expected an integer value.\")\n }\n\n return parsed\n }\n}\n\n/** Parses a JSON string; passes non-string values through unchanged. */\nexport function parseJSON<T = unknown>(): Processor<T> {\n return (value) => {\n if (typeof value !== \"string\") {\n if (value === undefined) {\n throw new Error(\"Expected a JSON string, received undefined.\")\n }\n return value as T\n }\n try {\n return JSON.parse(value) as T\n } catch {\n throw new Error(\"Expected a valid JSON string, but parsing failed.\")\n }\n }\n}\n\n/** Lowercases a string (coercing nullish values to `\"\"` first). */\nexport function toLowerCase(): Processor<string> {\n return (value) => String(value ?? \"\").toLowerCase()\n}\n\n/** Coerces a value to a number, rejecting empty/whitespace-only strings instead of silently resolving to `0`. */\nexport function toNumber(): Processor<number> {\n return (value) => {\n // `Number(\"\")` is `0`, not `NaN` -- without this check a blank env var would\n // silently resolve to the number 0 instead of failing, slipping past\n // validators.required() too (that checks the processed value, not the raw string).\n if (typeof value === \"string\" && value.trim() === \"\") {\n throw new Error(\"Expected a numeric value, received an empty string.\")\n }\n // Bypassing this type-check (always going through `Number(value)`) is\n // behaviorally equivalent, not a real gap: `Number()` is idempotent on\n // an already-number input (`Number(x) === x` for every real number,\n // including NaN and -0), so the ternary's two branches always produce\n // the same result. Hand-verified: mutating this and running the real\n // suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n const result = typeof value === \"number\" ? value : Number(value)\n if (Number.isNaN(result)) {\n throw new Error(`Expected a numeric value, received ${describe(value)}.`)\n }\n return result\n }\n}\n\n/** Compiles a value into a `RegExp`. */\nexport function toRegExp(): Processor<RegExp> {\n return (value) => {\n try {\n return new RegExp(String(value))\n } catch {\n throw new Error(\"Expected a valid regular expression.\")\n }\n }\n}\n\n/** Splits a string on `separator` into a trimmed string array; returns `[]` for non-string input. */\nexport function split(separator = \",\"): Processor<string[]> {\n return (value) => {\n if (typeof value !== \"string\") return []\n\n return value.split(separator).map((item) => item.trim())\n }\n}\n\n/** Coerces a value to a string, treating nullish values as `\"\"`. */\nexport function toString(): Processor<string> {\n return (value) => {\n if (value === undefined || value === null) return \"\"\n // Bypassing this type-check (always going through `String(value)`) is\n // behaviorally equivalent, not a real gap: `String()` is idempotent on\n // an already-string input. Hand-verified: mutating this and running the\n // real suite passes unchanged.\n // Stryker disable next-line ConditionalExpression,StringLiteral\n return typeof value === \"string\" ? value : String(value)\n }\n}\n\n/** Trims surrounding whitespace from a string (coercing nullish values to `\"\"` first). */\nexport function trim(): Processor<string> {\n return (value) => String(value ?? \"\").trim()\n}\n\n/** Uppercases a string (coercing nullish values to `\"\"` first). */\nexport function toUpperCase(): Processor<string> {\n return (value) => String(value ?? \"\").toUpperCase()\n}\n\n/** Parses a value into a `URL`, treating nullish values as `\"\"` first. */\nexport function toURL(): Processor<URL> {\n return (value) => {\n try {\n // The `\"\"` fallback for nullish input is behaviorally equivalent to\n // any other non-URL-shaped fallback string: `new URL(...)` throws for\n // BOTH \"\" and any garbage string, and both land in the same generic\n // catch below with the same message -- there is no distinguishable\n // outcome. Hand-verified: mutating this and running the real suite\n // passes unchanged.\n // Stryker disable next-line StringLiteral\n return new URL(String(value ?? \"\"))\n } catch {\n throw new Error(\"Expected a valid absolute URL.\")\n }\n }\n}\n","import type { Validator } from \"../runtime/index.js\"\n\n/** Passes when the date value is strictly after `date`. */\nexport function after(date: Date): Validator<Date> {\n return (value, _rawEnv) => value > date || \"Expected date to be after required date.\"\n}\n\n/** Passes only when every wrapped validator passes; returns the first failing message. */\nexport function all<T>(...validators: Validator<T>[]): Validator<T> {\n return (value, rawEnv) => {\n for (const validator of validators) {\n const result = validator(value, rawEnv)\n if (result !== true) return result\n }\n\n return true\n }\n}\n\n/** Passes when at least one wrapped validator passes. */\nexport function any<T>(...validators: Validator<T>[]): Validator<T> {\n return (value, rawEnv) => {\n for (const validator of validators) {\n if (validator(value, rawEnv) === true) return true\n }\n\n return \"Value did not satisfy any validation.\"\n }\n}\n\n/** Passes when the date value is strictly before `date`. */\nexport function before(date: Date): Validator<Date> {\n return (value, _rawEnv) => value < date || \"Expected date to be before required date.\"\n}\n\n/** Identity wrapper for a hand-written `Validator<T>` -- no behavior change, just a fluent entry point alongside the other helpers. */\nexport function custom<T>(validator: Validator<T>): Validator<T> {\n return validator\n}\n\n/** Passes for a plausibly-shaped email address (`local@domain`). */\nexport function email(): Validator<string> {\n return matches(/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/, \"Expected a valid email address.\")\n}\n\n/** Passes when the string ends with `suffix`. */\nexport function endsWith(suffix: string): Validator<string> {\n return (value, _rawEnv) => value.endsWith(suffix) || \"Expected value to end with required suffix.\"\n}\n\n/** Passes when the number is finite (rejects `Infinity`/`-Infinity`/`NaN`). */\nexport function finite(): Validator<number> {\n return (value, _rawEnv) => Number.isFinite(value) || \"Expected a finite number.\"\n}\n\n/** Passes when the date is strictly after the current time. */\nexport function future(): Validator<Date> {\n return (value, _rawEnv) => value > new Date() || \"Expected a future date.\"\n}\n\n/** Passes when the string contains `text` as a substring. */\nexport function includes(text: string): Validator<string> {\n return (value, _rawEnv) => value.includes(text) || \"Expected value to include required text.\"\n}\n\n/** Passes when the number is an integer. */\nexport function integer(): Validator<number> {\n return (value, _rawEnv) => Number.isInteger(value) || \"Expected an integer value.\"\n}\n\n/** Passes when the string's length is exactly `expected`. */\nexport function length(expected: number): Validator<string> {\n return (value, _rawEnv) => value.length === expected || `Expected length ${expected}.`\n}\n\n/** Passes when the string matches `pattern`; `message` overrides the default failure text. */\nexport function matches(pattern: RegExp, message?: string): Validator<string> {\n return (value, _rawEnv) =>\n pattern.test(value) || (message ?? \"Expected value to match required pattern.\")\n}\n\n/** Passes when the number is less than or equal to `maximum`. */\nexport function max(maximum: number): Validator<number> {\n return (value, _rawEnv) =>\n value <= maximum || `Expected a value less than or equal to ${maximum}.`\n}\n\n/** Passes when the array has at most `maximum` items. */\nexport function maxItems<T>(maximum: number): Validator<T[]> {\n return (value, _rawEnv) => value.length <= maximum || `Expected no more than ${maximum} items.`\n}\n\n/** Passes when the string's length is at most `length`. */\nexport function maxLength(length: number): Validator<string> {\n return (value, _rawEnv) => value.length <= length || `Expected a maximum length of ${length}.`\n}\n\n/** Passes when the number is greater than or equal to `minimum`. */\nexport function min(minimum: number): Validator<number> {\n return (value, _rawEnv) =>\n value >= minimum || `Expected a value greater than or equal to ${minimum}.`\n}\n\n/** Passes when the array has at least `minimum` items. */\nexport function minItems<T>(minimum: number): Validator<T[]> {\n return (value, _rawEnv) => value.length >= minimum || `Expected at least ${minimum} items.`\n}\n\n/** Passes when the string's length is at least `length`. */\nexport function minLength(length: number): Validator<string> {\n return (value, _rawEnv) => value.length >= length || `Expected a minimum length of ${length}.`\n}\n\n/** Passes when the number is strictly negative. */\nexport function negative(): Validator<number> {\n return (value, _rawEnv) => value < 0 || \"Expected a negative value.\"\n}\n\n/** Inverts a validator: passes when the wrapped validator fails, and vice versa. */\nexport function not<T>(validator: Validator<T>): Validator<T> {\n return (value, rawEnv) =>\n validator(value, rawEnv) === true ? \"Value must not satisfy this validation.\" : true\n}\n\n/** Passes when the value is one of the `allowed` values. */\nexport function oneOf<T>(allowed: readonly T[]): Validator<T> {\n return (value, _rawEnv) => allowed.includes(value) || `Expected one of: ${allowed.join(\", \")}.`\n}\n\n/** Passes when the value is undefined, otherwise delegates to the provided validator. */\nexport function optional<T>(validator: Validator<T>): Validator<T | undefined> {\n return (value, rawEnv) => {\n if (value === undefined) return true\n return validator(value, rawEnv)\n }\n}\n\n/** Passes when the date is strictly before the current time. */\nexport function past(): Validator<Date> {\n return (value, _rawEnv) => value < new Date() || \"Expected a past date.\"\n}\n\n/** Passes when the number is strictly positive. */\nexport function positive(): Validator<number> {\n return (value, _rawEnv) => value > 0 || \"Expected a positive value.\"\n}\n\n/** Passes when the number is within `[minimum, maximum]` inclusive. */\nexport function range(minimum: number, maximum: number): Validator<number> {\n return (value, _rawEnv) =>\n (value >= minimum && value <= maximum) ||\n `Expected a value greater than or equal to ${minimum} and less than or equal to ${maximum}.`\n}\n\n/** Runs the wrapped validator but replaces its failure message with `message`. */\nexport function refine<T>(validator: Validator<T>, message: string): Validator<T> {\n return (value, rawEnv) => (validator(value, rawEnv) === true ? true : message)\n}\n\n/** Passes when the value is defined and, unless `allowEmptyString` is set, non-empty. */\nexport function required(allowEmptyString = false): Validator<unknown> {\n return (value, _rawEnv) => {\n if (value === undefined || value === null) {\n return \"This variable is required.\"\n }\n\n if (!allowEmptyString && typeof value === \"string\" && value.length === 0) {\n return \"This variable is required.\"\n }\n\n return true\n }\n}\n\n/** Passes when the number is a safe integer (`Number.isSafeInteger`). */\nexport function safeInteger(): Validator<number> {\n return (value, _rawEnv) => Number.isSafeInteger(value) || \"Expected a safe integer.\"\n}\n\n/** Passes when every item in the array is unique. */\nexport function unique<T>(): Validator<T[]> {\n return (value, _rawEnv) =>\n new Set(value).size === value.length || \"Expected all items to be unique.\"\n}\n\n/** Passes when the string is a valid absolute URL. */\nexport function url(): Validator<string> {\n return (value, _rawEnv) => {\n try {\n new URL(value)\n return true\n } catch {\n return \"Expected a valid absolute URL.\"\n }\n }\n}\n\n/** Passes when the string is a valid UUID of one of the given `versions` (default: any of 1-8). */\nexport function uuid(versions: readonly number[] = [1, 2, 3, 4, 5, 6, 7, 8]): Validator<string> {\n return (value, _rawEnv) => {\n const match =\n /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f])[0-9a-f]{3}-([89ab])[0-9a-f]{3}-([0-9a-f]{12})$/i.exec(\n value,\n )\n\n if (!match) {\n return \"Expected a valid UUID .\"\n }\n\n // Capture group 3 is mandatory in the pattern (no `?`), so a successful\n // match always captures it -- noUncheckedIndexedAccess can't see that\n // invariant through RegExpExecArray's numeric index signature. A real\n // guard (not a non-null assertion, forbidden in src/) satisfies the type\n // checker without hiding the possibility. Hand-verified: mutating this\n // whole guard (its condition, its block, and its message) and running\n // the real suite passes unchanged.\n const versionDigit = match[3]\n // Stryker disable next-line ConditionalExpression, BlockStatement\n if (versionDigit === undefined) {\n // Stryker disable next-line StringLiteral\n return \"Expected a valid UUID .\"\n }\n const version = Number.parseInt(versionDigit, 16)\n\n if (!versions.includes(version)) {\n return `Expected UUID version ${versions.join(\", \")}.`\n }\n\n return true\n }\n}\n\n/** Shorthand for `uuid([version])` -- passes only for that exact UUID version. */\nexport function uuidVersion(number: number): Validator<string> {\n return uuid([number])\n}\n","/**\n * Optional convenience helpers for common processor/validator patterns.\n * Entirely separate from the core runtime -- `defineEnv`/`validateEnv` have\n * no knowledge of this module and work identically without it.\n *\n * Usage: `processors.toNumber()`, `validators.range(1, 65535)`.\n *\n * Deliberately built from explicit named imports assembled into plain object\n * literals, not `export * as processors from \"./processors.js\"`. A bundler\n * (tsup/esbuild) lowers that `export * as` form into a namespace-construction\n * helper call it can't prove side-effect-free, which defeats tree-shaking in\n * a *second*, downstream bundling pass (a consumer's own bundler bundling\n * this already-bundled package): importing only `processors` would still\n * ship all of `validators`' code. A plain object literal of already-imported\n * bindings has no such call in the way, so `import { processors } from\n * \"env-cap/helpers\"` alone drops `validators` entirely.\n */\nimport {\n base64,\n parseJSON,\n split,\n toArray,\n toBigInt,\n toBoolean,\n toDate,\n toInteger,\n toLowerCase,\n toNumber,\n toRegExp,\n toString,\n toURL,\n toUpperCase,\n trim,\n} from \"./processors.js\"\nimport {\n after,\n all,\n any,\n before,\n custom,\n email,\n endsWith,\n finite,\n future,\n includes,\n integer as integerValidator,\n length,\n matches,\n max,\n maxItems,\n maxLength,\n min,\n minItems,\n minLength,\n negative,\n not,\n oneOf,\n optional,\n past,\n positive,\n range,\n refine,\n required,\n safeInteger,\n unique,\n url as urlValidator,\n uuid,\n uuidVersion,\n} from \"./validators.js\"\n\n/**\n * Convenience {@link runtime.Processor} implementations for common coercion\n * patterns (e.g. `processors.toNumber()`).\n *\n * @remarks\n * Naming matches `@maverickcer/data-cap`'s `helpers.processors` -- but these\n * throw with a formatted `Error` message on invalid input, where data-cap's\n * silently return `undefined`. Do not assume the same failure mode when\n * moving between packages.\n */\nexport const processors = {\n /** Decodes a base64 string into a `Buffer`. */\n base64,\n /** Parses a JSON string; passes non-string values through unchanged. */\n parseJSON,\n /** Splits a string on `separator` into a trimmed string array; returns `[]` for non-string input. */\n split,\n /** Splits a delimited string (or passes through an array) into items, running each through `processors` in order. */\n toArray,\n /** Coerces a value to a `bigint`. */\n toBigInt,\n /** Coerces common boolean-like strings (`true`/`1`/`yes`/`on`, and their opposites) into a real boolean. */\n toBoolean,\n /** Parses a value into a `Date`. */\n toDate,\n /** Coerces a value to a number and requires it to be an integer. */\n toInteger,\n /** Lowercases a string (coercing nullish values to `\"\"` first). */\n toLowerCase,\n /** Coerces a value to a number, rejecting empty/whitespace-only strings instead of silently resolving to `0`. */\n toNumber,\n /** Compiles a value into a `RegExp`. */\n toRegExp,\n /** Coerces a value to a string, treating nullish values as `\"\"`. */\n toString,\n /** Parses a value into a `URL`, treating nullish values as `\"\"` first. */\n toURL,\n /** Uppercases a string (coercing nullish values to `\"\"` first). */\n toUpperCase,\n /** Trims surrounding whitespace from a string (coercing nullish values to `\"\"` first). */\n trim,\n}\n/** Convenience {@link runtime.Validator} implementations for common validation patterns (e.g. `validators.range(1, 65535)`). */\nexport const validators = {\n /** Passes when the date value is strictly after `date`. */\n after,\n /** Passes only when every wrapped validator passes; returns the first failing message. */\n all,\n /** Passes when at least one wrapped validator passes. */\n any,\n /** Passes when the date value is strictly before `date`. */\n before,\n /** Identity wrapper for a hand-written `Validator<T>` -- no behavior change, just a fluent entry point alongside the other helpers. */\n custom,\n /** Passes for a plausibly-shaped email address (`local@domain`). */\n email,\n /** Passes when the string ends with `suffix`. */\n endsWith,\n /** Alias for `oneOf` -- passes when the value is one of the `allowed` values. */\n enum: oneOf,\n /** Passes when the number is finite (rejects `Infinity`/`-Infinity`/`NaN`). */\n finite,\n /** Passes when the date is strictly after the current time. */\n future,\n /** Passes when the string contains `text` as a substring. */\n includes,\n /** Passes when the number is an integer. */\n integer: integerValidator,\n /** Passes when the string's length is exactly `expected`. */\n length,\n /** Passes when the string matches `pattern`; `message` overrides the default failure text. */\n matches,\n /** Passes when the number is less than or equal to `maximum`. */\n max,\n /** Passes when the array has at most `maximum` items. */\n maxItems,\n /** Passes when the string's length is at most `length`. */\n maxLength,\n /** Passes when the number is greater than or equal to `minimum`. */\n min,\n /** Passes when the array has at least `minimum` items. */\n minItems,\n /** Passes when the string's length is at least `length`. */\n minLength,\n /** Passes when the number is strictly negative. */\n negative,\n /** Inverts a validator: passes when the wrapped validator fails, and vice versa. */\n not,\n /** Passes when the value is one of the `allowed` values. */\n oneOf,\n /** Passes when the value is undefined, otherwise delegates to the provided validator. */\n optional,\n /** Passes when the date is strictly before the current time. */\n past,\n /** Passes when the number is strictly positive. */\n positive,\n /** Passes when the number is within `[minimum, maximum]` inclusive. */\n range,\n /** Runs the wrapped validator but replaces its failure message with `message`. */\n refine,\n /** Alias for `matches` -- passes when the string matches `pattern`. */\n regex: matches,\n /** Passes when the value is defined and, unless `allowEmptyString` is set, non-empty. */\n required,\n /** Passes when the number is a safe integer (`Number.isSafeInteger`). */\n safeInteger,\n /** Passes when every item in the array is unique. */\n unique,\n /** Passes when the string is a valid absolute URL. */\n url: urlValidator,\n /** Passes when the string is a valid UUID of one of the given `versions` (default: any of 1-8). */\n uuid,\n /** Shorthand for `uuid([version])` -- passes only for that exact UUID version. */\n uuidVersion,\n}\n"]}