ascertain 1.2.127 → 2.0.0-rc.1
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/LICENSE +1 -1
- package/README.md +6 -1
- package/build/index.cjs +18 -22
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +330 -4
- package/build/index.js +5 -6
- package/build/index.js.map +1 -1
- package/package.json +28 -21
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2019-
|
|
3
|
+
Copyright (c) 2019-2025 Ivan Zakharchanka
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
[![Downloads][downloads-image]][npm-url]
|
|
11
11
|
[![Snyk][snyk-image]][snyk-url]
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
[Documentation](https://3axap4ehko.github.io/ascertain/)
|
|
15
|
+
|
|
13
16
|
## Features
|
|
14
17
|
|
|
15
18
|
- Type-safe validation: Ensures your data conforms to predefined schemas.
|
|
@@ -25,6 +28,8 @@
|
|
|
25
28
|
- Regular Expressions: Regular expressions are used to validate that a value matches a specified string pattern.
|
|
26
29
|
- Object Types: Non-null objects are used as templates for expected properties, where each property of the object must match the corresponding schema definition.
|
|
27
30
|
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
## Usage Example
|
|
29
34
|
|
|
30
35
|
### Schema compilation
|
|
@@ -180,7 +185,7 @@ const validate = ascertain<typeof data>(schema, data, '[DATA]');
|
|
|
180
185
|
|
|
181
186
|
## License
|
|
182
187
|
License [The MIT License](http://opensource.org/licenses/MIT)
|
|
183
|
-
Copyright (c) 2019-
|
|
188
|
+
Copyright (c) 2019-2025 Ivan Zakharchanka
|
|
184
189
|
|
|
185
190
|
[npm-url]: https://www.npmjs.com/package/ascertain
|
|
186
191
|
[downloads-image]: https://img.shields.io/npm/dw/ascertain.svg?maxAge=43200
|
package/build/index.cjs
CHANGED
|
@@ -5,47 +5,44 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
$keys
|
|
12
|
+
get $keys () {
|
|
13
13
|
return $keys;
|
|
14
14
|
},
|
|
15
|
-
$strict
|
|
15
|
+
get $strict () {
|
|
16
16
|
return $strict;
|
|
17
17
|
},
|
|
18
|
-
$values
|
|
18
|
+
get $values () {
|
|
19
19
|
return $values;
|
|
20
20
|
},
|
|
21
|
-
and
|
|
21
|
+
get and () {
|
|
22
22
|
return and;
|
|
23
23
|
},
|
|
24
|
-
as
|
|
24
|
+
get as () {
|
|
25
25
|
return as;
|
|
26
26
|
},
|
|
27
|
-
asError
|
|
27
|
+
get asError () {
|
|
28
28
|
return asError;
|
|
29
29
|
},
|
|
30
|
-
ascertain
|
|
30
|
+
get ascertain () {
|
|
31
31
|
return ascertain;
|
|
32
32
|
},
|
|
33
|
-
compile
|
|
33
|
+
get compile () {
|
|
34
34
|
return compile;
|
|
35
35
|
},
|
|
36
|
-
|
|
37
|
-
return formatError;
|
|
38
|
-
},
|
|
39
|
-
fromBase64: function() {
|
|
36
|
+
get fromBase64 () {
|
|
40
37
|
return fromBase64;
|
|
41
38
|
},
|
|
42
|
-
optional
|
|
39
|
+
get optional () {
|
|
43
40
|
return optional;
|
|
44
41
|
},
|
|
45
|
-
or
|
|
42
|
+
get or () {
|
|
46
43
|
return or;
|
|
47
44
|
},
|
|
48
|
-
tuple
|
|
45
|
+
get tuple () {
|
|
49
46
|
return tuple;
|
|
50
47
|
}
|
|
51
48
|
});
|
|
@@ -114,19 +111,18 @@ const as = {
|
|
|
114
111
|
json: (value)=>{
|
|
115
112
|
try {
|
|
116
113
|
return JSON.parse(value);
|
|
117
|
-
} catch
|
|
114
|
+
} catch {
|
|
118
115
|
return asError(`Invalid value ${value}, expected a valid JSON string`);
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
118
|
base64: (value)=>{
|
|
122
119
|
try {
|
|
123
120
|
return fromBase64(value);
|
|
124
|
-
} catch
|
|
121
|
+
} catch {
|
|
125
122
|
return asError(`Invalid value ${value}, expected a valid base64 string`);
|
|
126
123
|
}
|
|
127
124
|
}
|
|
128
125
|
};
|
|
129
|
-
const formatError = (value, expected, path, subject)=>`Invalid ${subject} ${JSON.stringify(value)} for path ${path}, expected ${expected}.`;
|
|
130
126
|
class Context {
|
|
131
127
|
registry = [];
|
|
132
128
|
varIndex = 0;
|
|
@@ -277,14 +273,14 @@ ${codeGenExpectNoErrors(errorsAlias)}
|
|
|
277
273
|
return `
|
|
278
274
|
const ${valueAlias} = ${valuePath};
|
|
279
275
|
const ${registryAlias} = ctx.registry[${index}];
|
|
280
|
-
if (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for "path", expected symbol\`); }
|
|
276
|
+
if (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for path "${path}", expected symbol\`); }
|
|
281
277
|
if (${valueAlias} !== ${registryAlias}) { throw new TypeError(\`Invalid value \${${valueAlias}.toString()} for path "${path}", expected ${schema.toString()}\`); }
|
|
282
278
|
`;
|
|
283
279
|
} else if (schema === null || schema === undefined) {
|
|
284
280
|
const valueAlias = context.unique('v');
|
|
285
281
|
return `
|
|
286
282
|
const ${valueAlias} = ${valuePath};
|
|
287
|
-
if (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\`Invalid value ${valueAlias} for path "${path}", expected nullable\`); }
|
|
283
|
+
if (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\`Invalid value \${JSON.stringify(${valueAlias})} for path "${path}", expected nullable\`); }
|
|
288
284
|
`;
|
|
289
285
|
} else {
|
|
290
286
|
const valueAlias = context.unique('v');
|
|
@@ -294,7 +290,7 @@ const ${valueAlias} = ${valuePath};
|
|
|
294
290
|
const ${value} = ${JSON.stringify(schema)};
|
|
295
291
|
${codeGenExpectNonError(valueAlias, path)}
|
|
296
292
|
if (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for path "${path}", expected ${typeof schema}\`); }
|
|
297
|
-
if (${valueAlias} !== ${value}) { throw new TypeError(\`Invalid value
|
|
293
|
+
if (${valueAlias} !== ${value}) { throw new TypeError(\`Invalid value \${JSON.stringify(${valueAlias})} for path "${path}", expected ${JSON.stringify(schema)}\`); }
|
|
298
294
|
`;
|
|
299
295
|
}
|
|
300
296
|
};
|
package/build/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["abstract class Operator<T> {\n constructor(public readonly schemas: Schema<T>[]) {\n if (schemas.length === 0) {\n throw new TypeError(`Operation schema ${this.constructor.name} must have at least one element`);\n }\n }\n}\n\nexport const $keys = Symbol.for('@@keys');\nexport const $values = Symbol.for('@@values');\nexport const $strict = Symbol.for('@@strict');\n\nexport type Schema<T> =\n T extends Record<string | number | symbol, unknown>\n ? { [K in keyof T]?: Schema<T[K]> | unknown } & { [$keys]?: Schema<keyof T> } & { [$values]?: Schema<T[keyof T]> } & { [$strict]?: boolean }\n : T extends Array<infer A>\n ? Schema<A>[] | unknown\n : unknown;\n\nclass Or<T> extends Operator<T> {}\nexport const or = <T>(...schemas: Schema<T>[]) => new Or(schemas);\n\nclass And<T> extends Operator<T> {}\nexport const and = <T>(...schemas: Schema<T>[]) => new And(schemas);\n\nclass Optional<T> extends Operator<T> {\n constructor(schema: Schema<T>) {\n super([schema]);\n }\n}\nexport const optional = <T>(schema: Schema<T>) => new Optional(schema);\n\nclass Tuple<T> extends Operator<T> {}\nexport const tuple = <T>(...schemas: Schema<T>[]) => new Tuple(schemas);\n\nexport const fromBase64 = typeof Buffer === 'undefined' ? (value: string) => atob(value) : (value: string) => Buffer.from(value, 'base64').toString('utf-8');\n\nconst MULTIPLIERS = {\n ms: 1,\n s: 1000,\n m: 60000,\n h: 3600000,\n d: 86400000,\n w: 604800000,\n};\n\nexport const asError = <T>(message: string) => new TypeError(message) as unknown as T;\n\nexport const as = {\n string: (value: string | undefined): string => {\n return typeof value === 'string' ? value : asError(`Invalid value \"${value}\", expected a string`);\n },\n number: (value: string | undefined): number => {\n const result = parseFloat(value as string);\n return Number.isNaN(result) ? asError(`Invalid value ${value}, expected a valid number`) : result;\n },\n date: (value: string | undefined): Date => {\n const result = Date.parse(value as string);\n const date = new Date(result);\n return Number.isNaN(date.valueOf()) ? asError(`Invalid value \"${value}\", expected a valid date format`) : date;\n },\n time: (value: string | undefined, conversionFactor = 1): number => {\n const matches = value?.match(/^(\\d*\\.?\\d*)(ms|s|m|h|d|w)?$/);\n if (matches) {\n const [, amount, unit = 'ms'] = matches;\n return parseInt(`${(parseFloat(amount) * MULTIPLIERS[unit as keyof typeof MULTIPLIERS]) / conversionFactor}`);\n }\n return asError(`Invalid value ${value}, expected a valid time format`);\n },\n boolean: (value: string | undefined): boolean =>\n /^(0|1|true|false|enabled|disabled)$/i.test(value as string)\n ? /^(1|true|enabled)$/i.test(value as string)\n : asError(`Invalid value ${value}, expected a boolean like`),\n array: (value: string | undefined, delimiter: string): string[] => value?.split?.(delimiter) ?? asError(`Invalid value ${value}, expected an array`),\n json: <T = object>(value: string | undefined): T => {\n try {\n return JSON.parse(value as string);\n } catch (e) {\n return asError(`Invalid value ${value}, expected a valid JSON string`);\n }\n },\n base64: (value: string | undefined): string => {\n try {\n return fromBase64(value as string);\n } catch (e) {\n return asError(`Invalid value ${value}, expected a valid base64 string`);\n }\n },\n};\n\nexport interface ErrorFormatter {\n (value: unknown, expected: unknown, path: string, subject: string): string;\n}\n\nexport const formatError: ErrorFormatter = (value, expected, path, subject) =>\n `Invalid ${subject} ${JSON.stringify(value)} for path ${path}, expected ${expected}.`;\n\nclass Context {\n public readonly registry: unknown[] = [];\n private varIndex = 0;\n\n register(value: unknown): number {\n if (!this.registry.includes(value)) {\n this.registry.push(value);\n }\n return this.registry.indexOf(value);\n }\n\n unique(prefix: string) {\n return `${prefix}$$${this.varIndex++}`;\n }\n}\n\nconst codeGenCollectErrors = (errorsAlias: string, code: string, extra: string = '') => `try {${code}} catch (e) {${errorsAlias}.push(e.message);${extra}}`;\nconst codeGenExpectNoErrors = (errorsAlias: string) => `if (${errorsAlias}.length !== 0) { throw new TypeError(${errorsAlias}.join('\\\\n')); }`;\nconst codeGenExpectNonError = (valueAlias: string, path: string) =>\n `if (${valueAlias} instanceof Error) { throw new TypeError(\\`\\${${valueAlias}.message} for path \"${path}\".\\`); }`;\nconst codeGenExpectNonNullable = (valueAlias: string, path: string) =>\n `if (${valueAlias} === null || ${valueAlias} === undefined) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected non-nullable.\\`); }`;\nconst codeGenExpectObject = (valueAlias: string, path: string, instanceOf: string) =>\n `if (typeof ${valueAlias} !== 'object') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected an instance of ${instanceOf}\\`); }`;\nconst codeGenExpectArray = (valueAlias: string, path: string) =>\n `if (!Array.isArray(${valueAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}.constructor?.name} for path \"${path}\", expected an instance of Array.\\`); }`;\n\nconst codeGen = <T>(schema: Schema<T>, context: Context, valuePath: string, path: string): string => {\n if (schema instanceof And) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas.map((s) => `try { ${codeGen(s, context, valueAlias, path)} } catch (e) { ${errorsAlias}.push(e.message); }`).join('\\n');\n return `// And\n const ${errorsAlias} = [];\n const ${valueAlias} = ${valuePath};\n ${code}\n ${codeGenExpectNoErrors(errorsAlias)}\n`;\n } else if (schema instanceof Or) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas\n .map((s) => codeGen(s, context, valueAlias, path))\n .reduceRight((result, code) => codeGenCollectErrors(errorsAlias, code, result), codeGenExpectNoErrors(errorsAlias));\n return `// Or\nconst ${errorsAlias} = [];\nconst ${valueAlias} = ${valuePath};\n${code}\n `;\n } else if (schema instanceof Optional) {\n const valueAlias = context.unique('v');\n return `// Optional\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== undefined && ${valueAlias} !== null) { ${codeGen(schema.schemas[0], context, valueAlias, path)} }\n`;\n } else if (schema instanceof Tuple) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code: string[] = [\n '// Tuple',\n `const ${valueAlias} = ${valuePath};`,\n `const ${errorsAlias} = [];`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n `if (${valueAlias}.length > ${schema.schemas.length}) { throw new TypeError(\\`Invalid tuple length \\${${valueAlias}.length} for path \"${path}\", expected ${schema.schemas.length}.\\`); }`,\n ...schema.schemas.map((s, idx) => codeGenCollectErrors(errorsAlias, codeGen(s, context, `${valueAlias}[${idx}]`, `${path}[${idx}]`))),\n codeGenExpectNoErrors(errorsAlias),\n ];\n return code.join('\\n');\n } else if (typeof schema === 'function') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n `const ${registryAlias} = ctx.registry[${index}];`,\n codeGenExpectNonNullable(valueAlias, path),\n ];\n if ((schema as unknown) !== Error && !(schema?.prototype instanceof Error)) {\n code.push(codeGenExpectNonError(valueAlias, path));\n }\n\n code.push(\n `if (typeof ${valueAlias} === 'object' && !(${valueAlias} instanceof ${registryAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected an instance of ${schema?.name}\\`); }`,\n `if (typeof ${valueAlias} !== 'object' && ${valueAlias}?.constructor !== ${registryAlias}) { throw new TypeError(\\`Invalid type \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected type ${schema?.name}\\`); }`,\n `if (Number.isNaN(${valueAlias}?.valueOf?.())) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected a valid ${schema?.name}\\`); }`,\n );\n return code.join('\\n');\n } else if (Array.isArray(schema)) {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectNonError(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n ];\n if (schema.length > 0) {\n const value = context.unique('val');\n const key = context.unique('key');\n const errorsAlias = context.unique('err');\n code.push(`const ${errorsAlias} = [];`);\n code.push(\n ...schema.map(\n (s) => `${valueAlias}.forEach((${value},${key}) => { ${codeGenCollectErrors(errorsAlias, codeGen(s, context, value, `${path}[\\${${key}}]`))} });`,\n ),\n );\n\n code.push(codeGenExpectNoErrors(errorsAlias));\n }\n return code.join('\\n');\n } else if (typeof schema === 'object' && schema !== null) {\n if (schema instanceof RegExp) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\n${codeGenExpectNonNullable(valueAlias, path)}\n${codeGenExpectNonError(valueAlias, path)}\nif (!${schema.toString()}.test('' + ${valueAlias})) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected to match ${schema.toString()}\\`); }\n`;\n } else {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Object'),\n codeGenExpectNonError(valueAlias, path),\n ];\n if ($keys in schema) {\n const keysAlias = context.unique('k');\n const errorsAlias = context.unique('err');\n const kAlias = context.unique('k');\n code.push(`\nconst ${keysAlias} = Object.keys(${valueAlias});\nconst ${errorsAlias} = [];\n${keysAlias}.forEach(${kAlias} => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$keys], context, kAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($values in schema) {\n const vAlias = context.unique('val');\n const kAlias = context.unique('k');\n const entriesAlias = context.unique('en');\n const errorsAlias = context.unique('err');\n code.push(`\nconst ${entriesAlias} = Object.entries(${valueAlias});\nconst ${errorsAlias} = [];\n${entriesAlias}.forEach(([${kAlias},${vAlias}]) => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$values], context, vAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($strict in schema && schema[$strict]) {\n const keysAlias = context.unique('k');\n const kAlias = context.unique('k');\n const extraAlias = context.unique('ex');\n code.push(`const ${keysAlias} = new Set(${JSON.stringify(Object.keys(schema))});`);\n code.push(`const ${extraAlias} = Object.keys(${valueAlias}).filter(${kAlias} => !${keysAlias}.has(${kAlias}));`);\n code.push(`if (${extraAlias}.length !== 0) { throw new TypeError(\\`Extra properties: \\${${extraAlias}}, are not allowed for path \"${path}\"\\`); }`);\n }\n code.push(...Object.entries(schema).map(([key, s]) => codeGen(s, context, `${valueAlias}['${key}']`, `${path}.${key}`)));\n return `${code.join('\\n')}`;\n }\n } else if (typeof schema === 'symbol') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${registryAlias} = ctx.registry[${index}];\nif (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for \"path\", expected symbol\\`); }\nif (${valueAlias} !== ${registryAlias}) { throw new TypeError(\\`Invalid value \\${${valueAlias}.toString()} for path \"${path}\", expected ${schema.toString()}\\`); }\n `;\n } else if (schema === null || schema === undefined) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\\`Invalid value ${valueAlias} for path \"${path}\", expected nullable\\`); }\n `;\n } else {\n const valueAlias = context.unique('v');\n const value = context.unique('val');\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${value} = ${JSON.stringify(schema)};\n${codeGenExpectNonError(valueAlias, path)}\nif (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected ${typeof schema}\\`); }\nif (${valueAlias} !== ${value}) { throw new TypeError(\\`Invalid value ${JSON.stringify(valueAlias)} for path \"${path}\", expected ${JSON.stringify(schema)}\\`); }\n`;\n }\n};\n\nexport const compile = <T>(schema: Schema<T>, rootName: string) => {\n const context = new Context();\n const code = codeGen(schema, context, 'data', rootName);\n const validator = new Function('ctx', 'data', code);\n return (data: T) => validator(context, data);\n};\n\nexport const ascertain = <T>(schema: Schema<T>, data: T, rootName = '[root]') => {\n compile(schema, rootName)(data);\n};\n"],"names":["$keys","$strict","$values","and","as","asError","ascertain","compile","formatError","fromBase64","optional","or","tuple","Operator","constructor","schemas","length","TypeError","name","Symbol","for","Or","And","Optional","schema","Tuple","Buffer","value","atob","from","toString","MULTIPLIERS","ms","s","m","h","d","w","message","string","number","result","parseFloat","Number","isNaN","date","Date","parse","valueOf","time","conversionFactor","matches","match","amount","unit","parseInt","boolean","test","array","delimiter","split","json","JSON","e","base64","expected","path","subject","stringify","Context","registry","varIndex","register","includes","push","indexOf","unique","prefix","codeGenCollectErrors","errorsAlias","code","extra","codeGenExpectNoErrors","codeGenExpectNonError","valueAlias","codeGenExpectNonNullable","codeGenExpectObject","instanceOf","codeGenExpectArray","codeGen","context","valuePath","map","join","reduceRight","idx","index","registryAlias","Error","prototype","Array","isArray","key","RegExp","keysAlias","kAlias","vAlias","entriesAlias","extraAlias","Object","keys","entries","undefined","rootName","validator","Function","data"],"mapp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C5B,EAAEhE,MAAM,GAAG,EAAEmC,KAAKM,SAAS,CAAC5C,QAAQ;AAC1C,EAAE2D,sBAAsBC,YAAYlB,MAAM;WAC/B,EAAEkB,WAAW,MAAM,EAAE,OAAO5D,OAAO,kDAAkD,EAAE4D,WAAW,YAAY,EAAElB,KAAK,YAAY,EAAE,OAAO1C,OAAO;IACxJ,EAAE4D,WAAW,KAAK,EAAEzD,MAAM,wCAAwC,EAAEmC,KAAKM,SAAS,CAACgB,YAAY,WAAW,EAAElB,KAAK,YAAY,EAAEJ,KAAKM,SAAS,CAAC5C,QAAQ;AAC1J,CAAC;IACC;AACF;AAEO,MAAMjB,UAAU,CAAIiB,QAAmByF;IAC5C,MAAMvB,UAAU,IAAIrB;IACpB,MAAMW,OAAOS,QAAQjE,QAAQkE,SAAS,QAAQuB;IAC9C,MAAMC,YAAY,IAAIC,SAAS,OAAO,QAAQnC;IAC9C,OAAO,CAACoC,OAAYF,UAAUxB,SAAS0B;AACzC;AAEO,MAAM9G,YAAY,CAAIkB,QAAmB4F,MAASH,WAAW,QAAQ;IAC1E1G,QAAQiB,QAAQyF,UAAUG;AAC5B"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Abstract base class for schema operators.\n *\n * Provides a common constructor that enforces having at least one schema.\n *\n * @template T - The type of data the operator validates.\n * @abstract\n * @internal\n */\nabstract class Operator<T> {\n constructor(public readonly schemas: Schema<T>[]) {\n if (schemas.length === 0) {\n throw new TypeError(`Operation schema ${this.constructor.name} must have at least one element`);\n }\n }\n}\n\n// https://standardschema.dev/\n\n/**\n * Symbol for validating object keys against a schema.\n */\nexport const $keys = Symbol.for('@@keys');\n/**\n * Symbol for validating object values against a schema.\n */\nexport const $values = Symbol.for('@@values');\n/**\n * Symbol for enforcing strict object validation (no extra properties allowed).\n */\nexport const $strict = Symbol.for('@@strict');\n\n/**\n * Represents a schema for validating data.\n *\n * Schemas can be defined for various data types, including objects, arrays, and primitives.\n *\n * @template T - The type of data the schema validates.\n */\nexport type Schema<T> =\n T extends Record<string | number | symbol, unknown>\n ? { [K in keyof T]?: Schema<T[K]> | unknown } & { [$keys]?: Schema<keyof T> } & { [$values]?: Schema<T[keyof T]> } & { [$strict]?: boolean }\n : T extends Array<infer A>\n ? Schema<A>[] | unknown\n : unknown;\n\nclass Or<T> extends Operator<T> {}\n/**\n * Operator for validating data against any of the provided schemas (logical OR).\n *\n * Creates a schema that accepts data matching any one of the provided schemas.\n * This is useful for creating union types or alternative validation paths.\n *\n * @template T - The type of data the operator validates.\n * @param schemas - Multiple schemas where at least one must match the data.\n * @returns A schema that validates data against any of the provided schemas.\n *\n * @example\n * ```typescript\n * import { or, ascertain } from 'ascertain';\n *\n * // Create a schema that accepts either a string or number\n * const stringOrNumber = or(String, Number);\n *\n * ascertain(stringOrNumber, \"hello\", \"value\"); // ✓ Valid\n * ascertain(stringOrNumber, 42, \"value\"); // ✓ Valid\n * ascertain(stringOrNumber, true, \"value\"); // ✗ Throws error\n *\n * // Union of literal values\n * const statusSchema = or('pending', 'completed', 'failed');\n * ascertain(statusSchema, 'pending', \"status\"); // ✓ Valid\n *\n * // Complex schema combinations\n * const userIdSchema = or(Number, { id: Number, temp: Boolean });\n * ascertain(userIdSchema, 123, \"userId\"); // ✓ Valid\n * ascertain(userIdSchema, { id: 456, temp: true }, \"userId\"); // ✓ Valid\n * ```\n */\nexport const or = <T>(...schemas: Schema<T>[]) => new Or(schemas);\n\nclass And<T> extends Operator<T> {}\n/**\n * Operator for validating data against all provided schemas (logical AND).\n *\n * Creates a schema that requires data to match every one of the provided schemas.\n * This is useful for combining multiple validation requirements or adding constraints.\n *\n * @template T - The type of data the operator validates.\n * @param schemas - Multiple schemas that all must match the data.\n * @returns A schema that validates data against all of the provided schemas.\n *\n * @example\n * ```typescript\n * import { and, ascertain } from 'ascertain';\n *\n * // Combine object schema with additional constraints\n * const userSchema = and(\n * { name: String, age: Number },\n * { age: Number } // Additional constraint\n * );\n *\n * ascertain(userSchema, { name: \"John\", age: 25 }, \"user\"); // ✓ Valid\n *\n * // Ensure an object is both a Date and has specific methods\n * const validDateSchema = and(Date, { toISOString: Function });\n * ascertain(validDateSchema, new Date(), \"date\"); // ✓ Valid\n *\n * // Multiple validation layers\n * const positiveNumberSchema = and(Number, (n: number) => n > 0);\n * ascertain(positiveNumberSchema, 42, \"count\"); // ✓ Valid\n * ascertain(positiveNumberSchema, -5, \"count\"); // ✗ Throws error\n * ```\n */\nexport const and = <T>(...schemas: Schema<T>[]) => new And(schemas);\n\nclass Optional<T> extends Operator<T> {\n constructor(schema: Schema<T>) {\n super([schema]);\n }\n}\n/**\n * Operator for making a schema optional (nullable).\n *\n * Creates a schema that accepts the provided schema or null/undefined values.\n * This is useful for optional object properties or nullable fields.\n *\n * @template T - The type of data the operator validates.\n * @param schema - The schema to make optional.\n * @returns A schema that validates data against the provided schema or accepts null/undefined.\n *\n * @example\n * ```typescript\n * import { optional, ascertain } from 'ascertain';\n *\n * // Optional string field\n * const userSchema = {\n * name: String,\n * nickname: optional(String),\n * age: Number\n * };\n *\n * // All of these are valid\n * ascertain(userSchema, {\n * name: \"John\",\n * nickname: \"Johnny\",\n * age: 30\n * }, \"user\"); // ✓ Valid\n *\n * ascertain(userSchema, {\n * name: \"Jane\",\n * nickname: null,\n * age: 25\n * }, \"user\"); // ✓ Valid\n *\n * ascertain(userSchema, {\n * name: \"Bob\",\n * age: 35\n * // nickname is undefined\n * }, \"user\"); // ✓ Valid\n *\n * // Optional complex objects\n * const profileSchema = {\n * id: Number,\n * settings: optional({\n * theme: String,\n * notifications: Boolean\n * })\n * };\n * ```\n */\nexport const optional = <T>(schema: Schema<T>) => new Optional(schema);\n\nclass Tuple<T> extends Operator<T> {}\n/**\n * Operator for validating data against a fixed-length tuple of schemas.\n *\n * Creates a schema that validates arrays with a specific length and type for each position.\n * This is useful for coordinate pairs, RGB values, or any fixed-structure data.\n *\n * @template T - The type of data the operator validates (a tuple of types).\n * @param schemas - Schemas for each position in the tuple, in order.\n * @returns A schema that validates data as a tuple with the specified structure.\n *\n * @example\n * ```typescript\n * import { tuple, ascertain } from 'ascertain';\n *\n * // 2D coordinate tuple\n * const pointSchema = tuple(Number, Number);\n * ascertain(pointSchema, [10, 20], \"point\"); // ✓ Valid\n * ascertain(pointSchema, [1.5, 2.7], \"point\"); // ✓ Valid\n * ascertain(pointSchema, [10], \"point\"); // ✗ Throws error (too short)\n * ascertain(pointSchema, [10, 20, 30], \"point\"); // ✗ Throws error (too long)\n *\n * // RGB color tuple\n * const colorSchema = tuple(Number, Number, Number);\n * ascertain(colorSchema, [255, 128, 0], \"color\"); // ✓ Valid\n *\n * // Mixed type tuple\n * const userInfoSchema = tuple(String, Number, Boolean);\n * ascertain(userInfoSchema, [\"Alice\", 25, true], \"userInfo\"); // ✓ Valid\n *\n * // Nested tuple\n * const lineSchema = tuple(\n * tuple(Number, Number), // start point\n * tuple(Number, Number) // end point\n * );\n * ascertain(lineSchema, [[0, 0], [10, 10]], \"line\"); // ✓ Valid\n * ```\n */\nexport const tuple = <T>(...schemas: Schema<T>[]) => new Tuple(schemas);\n\nexport const fromBase64 = typeof Buffer === 'undefined' ? (value: string) => atob(value) : (value: string) => Buffer.from(value, 'base64').toString('utf-8');\n\nconst MULTIPLIERS = {\n ms: 1,\n s: 1000,\n m: 60000,\n h: 3600000,\n d: 86400000,\n w: 604800000,\n};\n\nexport const asError = <T>(message: string) => new TypeError(message) as unknown as T;\n\nexport const as = {\n /**\n * Attempts to convert a value to a string.\n *\n * @param value - The value to convert.\n * @returns The value as a string, or a TypeError if not a string.\n */\n string: (value: string | undefined): string => {\n return typeof value === 'string' ? value : asError(`Invalid value \"${value}\", expected a string`);\n },\n /**\n * Attempts to convert a value to a number.\n *\n * @param value - The value to convert (expected to be a string representation of a number).\n * @returns The value as a number, or a TypeError if not a valid number.\n */\n number: (value: string | undefined): number => {\n const result = parseFloat(value as string);\n return Number.isNaN(result) ? asError(`Invalid value ${value}, expected a valid number`) : result;\n },\n /**\n * Attempts to convert a value to a Date object.\n *\n * @param value - The value to convert (expected to be a string representation of a date).\n * @returns The value as a Date object, or a TypeError if not a valid date.\n */\n date: (value: string | undefined): Date => {\n const result = Date.parse(value as string);\n const date = new Date(result);\n return Number.isNaN(date.valueOf()) ? asError(`Invalid value \"${value}\", expected a valid date format`) : date;\n },\n /**\n * Attempts to convert a value to a time duration in milliseconds.\n *\n * @param value - The value to convert (e.g., \"5s\" for 5 seconds).\n * @param conversionFactor - Optional factor to divide the result by (default is 1).\n * @returns The time duration in milliseconds, or a TypeError if the format is invalid.\n */\n time: (value: string | undefined, conversionFactor = 1): number => {\n const matches = value?.match(/^(\\d*\\.?\\d*)(ms|s|m|h|d|w)?$/);\n if (matches) {\n const [, amount, unit = 'ms'] = matches;\n return parseInt(`${(parseFloat(amount) * MULTIPLIERS[unit as keyof typeof MULTIPLIERS]) / conversionFactor}`);\n }\n return asError(`Invalid value ${value}, expected a valid time format`);\n },\n /**\n * Attempts to convert a value to a boolean.\n *\n * @param value - The boolean like value to convert (e.g., \"true\", \"1\", \"enabled\").\n * @returns The value as a boolean, or a TypeError if it could not be converted to a boolean.\n */\n boolean: (value: string | undefined): boolean =>\n /^(0|1|true|false|enabled|disabled)$/i.test(value as string)\n ? /^(1|true|enabled)$/i.test(value as string)\n : asError(`Invalid value ${value}, expected a boolean like`),\n /**\n * Attempts to convert a string into an array of strings by splitting it using the given delimiter.\n *\n * @param value - The string value to attempt to split into an array.\n * @param delimiter - The character or string used to separate elements in the input string.\n * @returns An array of strings if the conversion is successful, or a TypeError if the value is not a string.\n */\n array: (value: string | undefined, delimiter: string): string[] => value?.split?.(delimiter) ?? asError(`Invalid value ${value}, expected an array`),\n /**\n * Attempts to parse a JSON string into a JavaScript object.\n *\n * @template T - The expected type of the parsed JSON object.\n * @param value - The JSON string to attempt to parse.\n * @returns The parsed JSON object if successful, or a TypeError if the value is not valid JSON.\n */\n json: <T = object>(value: string | undefined): T => {\n try {\n return JSON.parse(value as string);\n } catch {\n return asError(`Invalid value ${value}, expected a valid JSON string`);\n }\n },\n /**\n * Attempts to decode a base64-encoded string.\n *\n * @param value - The base64-encoded string to attempt to decode.\n * @returns The decoded string if successful, or a TypeError if the value is not valid base64.\n */\n base64: (value: string | undefined): string => {\n try {\n return fromBase64(value as string);\n } catch {\n return asError(`Invalid value ${value}, expected a valid base64 string`);\n }\n },\n};\n\n/**\n * A class representing the context for schema validation.\n *\n * Stores a registry of values encountered during validation and provides methods for managing it.\n * @internal\n */\nclass Context {\n public readonly registry: unknown[] = [];\n private varIndex = 0;\n\n register(value: unknown): number {\n if (!this.registry.includes(value)) {\n this.registry.push(value);\n }\n return this.registry.indexOf(value);\n }\n\n unique(prefix: string) {\n return `${prefix}$$${this.varIndex++}`;\n }\n}\n\nconst codeGenCollectErrors = (errorsAlias: string, code: string, extra: string = '') => `try {${code}} catch (e) {${errorsAlias}.push(e.message);${extra}}`;\nconst codeGenExpectNoErrors = (errorsAlias: string) => `if (${errorsAlias}.length !== 0) { throw new TypeError(${errorsAlias}.join('\\\\n')); }`;\nconst codeGenExpectNonError = (valueAlias: string, path: string) =>\n `if (${valueAlias} instanceof Error) { throw new TypeError(\\`\\${${valueAlias}.message} for path \"${path}\".\\`); }`;\nconst codeGenExpectNonNullable = (valueAlias: string, path: string) =>\n `if (${valueAlias} === null || ${valueAlias} === undefined) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected non-nullable.\\`); }`;\nconst codeGenExpectObject = (valueAlias: string, path: string, instanceOf: string) =>\n `if (typeof ${valueAlias} !== 'object') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected an instance of ${instanceOf}\\`); }`;\nconst codeGenExpectArray = (valueAlias: string, path: string) =>\n `if (!Array.isArray(${valueAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}.constructor?.name} for path \"${path}\", expected an instance of Array.\\`); }`;\n\nconst codeGen = <T>(schema: Schema<T>, context: Context, valuePath: string, path: string): string => {\n if (schema instanceof And) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas.map((s) => `try { ${codeGen(s, context, valueAlias, path)} } catch (e) { ${errorsAlias}.push(e.message); }`).join('\\n');\n return `// And\n const ${errorsAlias} = [];\n const ${valueAlias} = ${valuePath};\n ${code}\n ${codeGenExpectNoErrors(errorsAlias)}\n`;\n } else if (schema instanceof Or) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas\n .map((s) => codeGen(s, context, valueAlias, path))\n .reduceRight((result, code) => codeGenCollectErrors(errorsAlias, code, result), codeGenExpectNoErrors(errorsAlias));\n return `// Or\nconst ${errorsAlias} = [];\nconst ${valueAlias} = ${valuePath};\n${code}\n `;\n } else if (schema instanceof Optional) {\n const valueAlias = context.unique('v');\n return `// Optional\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== undefined && ${valueAlias} !== null) { ${codeGen(schema.schemas[0], context, valueAlias, path)} }\n`;\n } else if (schema instanceof Tuple) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code: string[] = [\n '// Tuple',\n `const ${valueAlias} = ${valuePath};`,\n `const ${errorsAlias} = [];`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n `if (${valueAlias}.length > ${schema.schemas.length}) { throw new TypeError(\\`Invalid tuple length \\${${valueAlias}.length} for path \"${path}\", expected ${schema.schemas.length}.\\`); }`,\n ...schema.schemas.map((s, idx) => codeGenCollectErrors(errorsAlias, codeGen(s, context, `${valueAlias}[${idx}]`, `${path}[${idx}]`))),\n codeGenExpectNoErrors(errorsAlias),\n ];\n return code.join('\\n');\n } else if (typeof schema === 'function') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n `const ${registryAlias} = ctx.registry[${index}];`,\n codeGenExpectNonNullable(valueAlias, path),\n ];\n if ((schema as unknown) !== Error && !(schema?.prototype instanceof Error)) {\n code.push(codeGenExpectNonError(valueAlias, path));\n }\n\n code.push(\n `if (typeof ${valueAlias} === 'object' && !(${valueAlias} instanceof ${registryAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected an instance of ${schema?.name}\\`); }`,\n `if (typeof ${valueAlias} !== 'object' && ${valueAlias}?.constructor !== ${registryAlias}) { throw new TypeError(\\`Invalid type \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected type ${schema?.name}\\`); }`,\n `if (Number.isNaN(${valueAlias}?.valueOf?.())) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected a valid ${schema?.name}\\`); }`,\n );\n return code.join('\\n');\n } else if (Array.isArray(schema)) {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectNonError(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n ];\n if (schema.length > 0) {\n const value = context.unique('val');\n const key = context.unique('key');\n const errorsAlias = context.unique('err');\n code.push(`const ${errorsAlias} = [];`);\n code.push(\n ...schema.map(\n (s) => `${valueAlias}.forEach((${value},${key}) => { ${codeGenCollectErrors(errorsAlias, codeGen(s, context, value, `${path}[\\${${key}}]`))} });`,\n ),\n );\n\n code.push(codeGenExpectNoErrors(errorsAlias));\n }\n return code.join('\\n');\n } else if (typeof schema === 'object' && schema !== null) {\n if (schema instanceof RegExp) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\n${codeGenExpectNonNullable(valueAlias, path)}\n${codeGenExpectNonError(valueAlias, path)}\nif (!${schema.toString()}.test('' + ${valueAlias})) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected to match ${schema.toString()}\\`); }\n`;\n } else {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Object'),\n codeGenExpectNonError(valueAlias, path),\n ];\n if ($keys in schema) {\n const keysAlias = context.unique('k');\n const errorsAlias = context.unique('err');\n const kAlias = context.unique('k');\n code.push(`\nconst ${keysAlias} = Object.keys(${valueAlias});\nconst ${errorsAlias} = [];\n${keysAlias}.forEach(${kAlias} => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$keys], context, kAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($values in schema) {\n const vAlias = context.unique('val');\n const kAlias = context.unique('k');\n const entriesAlias = context.unique('en');\n const errorsAlias = context.unique('err');\n code.push(`\nconst ${entriesAlias} = Object.entries(${valueAlias});\nconst ${errorsAlias} = [];\n${entriesAlias}.forEach(([${kAlias},${vAlias}]) => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$values], context, vAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($strict in schema && schema[$strict]) {\n const keysAlias = context.unique('k');\n const kAlias = context.unique('k');\n const extraAlias = context.unique('ex');\n code.push(`const ${keysAlias} = new Set(${JSON.stringify(Object.keys(schema))});`);\n code.push(`const ${extraAlias} = Object.keys(${valueAlias}).filter(${kAlias} => !${keysAlias}.has(${kAlias}));`);\n code.push(`if (${extraAlias}.length !== 0) { throw new TypeError(\\`Extra properties: \\${${extraAlias}}, are not allowed for path \"${path}\"\\`); }`);\n }\n code.push(...Object.entries(schema).map(([key, s]) => codeGen(s, context, `${valueAlias}['${key}']`, `${path}.${key}`)));\n return `${code.join('\\n')}`;\n }\n } else if (typeof schema === 'symbol') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${registryAlias} = ctx.registry[${index}];\nif (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected symbol\\`); }\nif (${valueAlias} !== ${registryAlias}) { throw new TypeError(\\`Invalid value \\${${valueAlias}.toString()} for path \"${path}\", expected ${schema.toString()}\\`); }\n `;\n } else if (schema === null || schema === undefined) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\\`Invalid value \\${JSON.stringify(${valueAlias})} for path \"${path}\", expected nullable\\`); }\n `;\n } else {\n const valueAlias = context.unique('v');\n const value = context.unique('val');\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${value} = ${JSON.stringify(schema)};\n${codeGenExpectNonError(valueAlias, path)}\nif (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected ${typeof schema}\\`); }\nif (${valueAlias} !== ${value}) { throw new TypeError(\\`Invalid value \\${JSON.stringify(${valueAlias})} for path \"${path}\", expected ${JSON.stringify(schema)}\\`); }\n`;\n }\n};\n\n/**\n * Compiles a schema into a validation function.\n *\n * This function takes a schema definition and generates a JavaScript function\n * that can be used to validate data against the schema.\n *\n * @template T - The type of data the schema validates.\n * @param schema - The schema to compile.\n * @param rootName - A name for the root of the data structure (used in error messages).\n * @returns A validation function that takes data as input and throws a TypeError if the data does not conform to the schema.\n *\n * @example\n * ```typescript\n * import { compile, optional, and, or } from 'ascertain';\n *\n * const userSchema = {\n * name: String,\n * age: Number,\n * email: optional(String),\n * role: or('admin', 'user', 'guest')\n * };\n *\n * const validateUser = compile(userSchema, 'User');\n *\n * // Valid data - no error thrown\n * validateUser({\n * name: 'John Doe',\n * age: 30,\n * email: 'john@example.com',\n * role: 'user'\n * });\n *\n * // Invalid data - throws TypeError\n * try {\n * validateUser({\n * name: 123, // Invalid: should be string\n * age: 'thirty' // Invalid: should be number\n * });\n * } catch (error) {\n * console.error(error.message); // Detailed validation errors\n * }\n * ```\n */\nexport const compile = <T>(schema: Schema<T>, rootName: string) => {\n const context = new Context();\n const code = codeGen(schema, context, 'data', rootName);\n const validator = new Function('ctx', 'data', code);\n return (data: T) => validator(context, data);\n};\n\n/**\n * Asserts that data conforms to a given schema.\n *\n * This function is a convenient wrapper around `compile`. It compiles the schema\n * and immediately validates the provided data against it.\n *\n * @template T - The type of data the schema validates.\n * @param schema - The schema to validate against.\n * @param data - The data to validate.\n * @param rootName - A name for the root of the data structure (used in error messages, defaults to '[root]').\n * @throws `{TypeError}` If the data does not conform to the schema.\n *\n * @example\n * ```typescript\n * import { ascertain, optional, and, or } from 'ascertain';\n *\n * const userSchema = {\n * name: String,\n * age: Number,\n * email: optional(String),\n * active: Boolean\n * };\n *\n * const userData = {\n * name: 'Alice',\n * age: 25,\n * email: 'alice@example.com',\n * active: true\n * };\n *\n * // Validate data - throws if invalid, otherwise continues silently\n * ascertain(userSchema, userData, 'UserData');\n * console.log('User data is valid!');\n *\n * // Example with invalid data\n * try {\n * ascertain(userSchema, {\n * name: 'Bob',\n * age: 'twenty-five', // Invalid: should be number\n * active: true\n * }, 'UserData');\n * } catch (error) {\n * console.error('Validation failed:', error.message);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Array validation\n * const numbersSchema = [Number];\n * const numbers = [1, 2, 3, 4, 5];\n *\n * ascertain(numbersSchema, numbers, 'Numbers');\n *\n * // Tuple validation\n * const coordinateSchema = tuple(Number, Number);\n * const point = [10, 20];\n *\n * ascertain(coordinateSchema, point, 'Point');\n * ```\n */\nexport const ascertain = <T>(schema: Schema<T>, data: T, rootName = '[root]') => {\n compile(schema, rootName)(data);\n};\n"],"names":["$keys","$strict","$values","and","as","asError","ascertain","compile","fromBase64","optional","or","tuple","Operator","schemas","length","TypeError","name","Symbol","for","Or","And","Optional","schema","Tuple","Buffer","value","atob","from","toString","MULTIPLIERS","ms","s","m","h","d","w","message","string","number","result","parseFloat","Number","isNaN","date","Date","parse","valueOf","time","conversionFactor","matches","match","amount","unit","parseInt","boolean","test","array","delimiter","split","json","JSON","base64","Context","registry","varIndex","register","includes","push","indexOf","unique","prefix","codeGenCollectErrors","errorsAlias","code","extra","codeGenExpectNoErrors","codeGenExpectNonError","valueAlias","path","codeGenExpectNonNullable","codeGenExpectObject","instanceOf","codeGenExpectArray","codeGen","context","valuePath","map","join","reduceRight","idx","index","registryAlias","Error","prototype","Array","isArray","key","RegExp","keysAlias","kAlias","vAlias","entriesAlias","extraAlias","stringify","Object","keys","entries","undefined","rootName","validator","Function","data"],"mappings":";;;;;;;;;;;QAsBaA;eAAAA;;QAQAC;eAAAA;;QAJAC;eAAAA;;QAuFAC;eAAAA;;QAgHAC;eAAAA;;QAFAC;eAAAA;;QAqZAC;eAAAA;;QApEAC;eAAAA;;QA5VAC;eAAAA;;QA1CAC;eAAAA;;QA5FAC;eAAAA;;QAoIAC;eAAAA;;;AAzMb,MAAeC;;IACb,YAAY,AAAgBC,OAAoB,CAAE;aAAtBA,UAAAA;QAC1B,IAAIA,QAAQC,MAAM,KAAK,GAAG;YACxB,MAAM,IAAIC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAACC,IAAI,CAAC,+BAA+B,CAAC;QAChG;IACF;AACF;AAOO,MAAMhB,QAAQiB,OAAOC,GAAG,CAAC;AAIzB,MAAMhB,UAAUe,OAAOC,GAAG,CAAC;AAI3B,MAAMjB,UAAUgB,OAAOC,GAAG,CAAC;AAgBlC,MAAMC,WAAcP;AAAa;AAgC1B,MAAMF,KAAK,CAAI,GAAGG,UAAyB,IAAIM,GAAGN;AAEzD,MAAMO,YAAeR;AAAa;AAiC3B,MAAMT,MAAM,CAAI,GAAGU,UAAyB,IAAIO,IAAIP;AAE3D,MAAMQ,iBAAoBT;IACxB,YAAYU,MAAiB,CAAE;QAC7B,KAAK,CAAC;YAACA;SAAO;IAChB;AACF;AAmDO,MAAMb,WAAW,CAAIa,SAAsB,IAAID,SAASC;AAE/D,MAAMC,cAAiBX;AAAa;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AG,EAAEQ,UAAU;MAC5B,EAAE5D,MAAM,GAAG,EAAEmC,KAAK2C,SAAS,CAACjF,QAAQ;AAC1C,EAAEsD,sBAAsBC,YAAYC,MAAM;WAC/B,EAAED,WAAW,MAAM,EAAE,OAAOvD,OAAO,kDAAkD,EAAEuD,WAAW,YAAY,EAAEC,KAAK,YAAY,EAAE,OAAOxD,OAAO;IACxJ,EAAEuD,WAAW,KAAK,EAAEpD,MAAM,0DAA0D,EAAEoD,WAAW,aAAa,EAAEC,KAAK,YAAY,EAAElB,KAAK2C,SAAS,CAACjF,QAAQ;AAC9J,CAAC;IACC;AACF;AA6CO,MAAMf,UAAU,CAAIe,QAAmBsF;IAC5C,MAAMxB,UAAU,IAAItB;IACpB,MAAMW,OAAOU,QAAQ7D,QAAQ8D,SAAS,QAAQwB;IAC9C,MAAMC,YAAY,IAAIC,SAAS,OAAO,QAAQrC;IAC9C,OAAO,CAACsC,OAAYF,UAAUzB,SAAS2B;AACzC;AA+DO,MAAMzG,YAAY,CAAIgB,QAAmByF,MAASH,WAAW,QAAQ;IAC1ErG,QAAQe,QAAQsF,UAAUG;AAC5B"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for schema operators.
|
|
3
|
+
*
|
|
4
|
+
* Provides a common constructor that enforces having at least one schema.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of data the operator validates.
|
|
7
|
+
* @abstract
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
1
10
|
declare abstract class Operator<T> {
|
|
2
11
|
readonly schemas: Schema<T>[];
|
|
3
12
|
constructor(schemas: Schema<T>[]);
|
|
4
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Symbol for validating object keys against a schema.
|
|
16
|
+
*/
|
|
5
17
|
export declare const $keys: unique symbol;
|
|
18
|
+
/**
|
|
19
|
+
* Symbol for validating object values against a schema.
|
|
20
|
+
*/
|
|
6
21
|
export declare const $values: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* Symbol for enforcing strict object validation (no extra properties allowed).
|
|
24
|
+
*/
|
|
7
25
|
export declare const $strict: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* Represents a schema for validating data.
|
|
28
|
+
*
|
|
29
|
+
* Schemas can be defined for various data types, including objects, arrays, and primitives.
|
|
30
|
+
*
|
|
31
|
+
* @template T - The type of data the schema validates.
|
|
32
|
+
*/
|
|
8
33
|
export type Schema<T> = T extends Record<string | number | symbol, unknown> ? {
|
|
9
34
|
[K in keyof T]?: Schema<T[K]> | unknown;
|
|
10
35
|
} & {
|
|
@@ -16,33 +41,334 @@ export type Schema<T> = T extends Record<string | number | symbol, unknown> ? {
|
|
|
16
41
|
} : T extends Array<infer A> ? Schema<A>[] | unknown : unknown;
|
|
17
42
|
declare class Or<T> extends Operator<T> {
|
|
18
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Operator for validating data against any of the provided schemas (logical OR).
|
|
46
|
+
*
|
|
47
|
+
* Creates a schema that accepts data matching any one of the provided schemas.
|
|
48
|
+
* This is useful for creating union types or alternative validation paths.
|
|
49
|
+
*
|
|
50
|
+
* @template T - The type of data the operator validates.
|
|
51
|
+
* @param schemas - Multiple schemas where at least one must match the data.
|
|
52
|
+
* @returns A schema that validates data against any of the provided schemas.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { or, ascertain } from 'ascertain';
|
|
57
|
+
*
|
|
58
|
+
* // Create a schema that accepts either a string or number
|
|
59
|
+
* const stringOrNumber = or(String, Number);
|
|
60
|
+
*
|
|
61
|
+
* ascertain(stringOrNumber, "hello", "value"); // ✓ Valid
|
|
62
|
+
* ascertain(stringOrNumber, 42, "value"); // ✓ Valid
|
|
63
|
+
* ascertain(stringOrNumber, true, "value"); // ✗ Throws error
|
|
64
|
+
*
|
|
65
|
+
* // Union of literal values
|
|
66
|
+
* const statusSchema = or('pending', 'completed', 'failed');
|
|
67
|
+
* ascertain(statusSchema, 'pending', "status"); // ✓ Valid
|
|
68
|
+
*
|
|
69
|
+
* // Complex schema combinations
|
|
70
|
+
* const userIdSchema = or(Number, { id: Number, temp: Boolean });
|
|
71
|
+
* ascertain(userIdSchema, 123, "userId"); // ✓ Valid
|
|
72
|
+
* ascertain(userIdSchema, { id: 456, temp: true }, "userId"); // ✓ Valid
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
19
75
|
export declare const or: <T>(...schemas: Schema<T>[]) => Or<T>;
|
|
20
76
|
declare class And<T> extends Operator<T> {
|
|
21
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Operator for validating data against all provided schemas (logical AND).
|
|
80
|
+
*
|
|
81
|
+
* Creates a schema that requires data to match every one of the provided schemas.
|
|
82
|
+
* This is useful for combining multiple validation requirements or adding constraints.
|
|
83
|
+
*
|
|
84
|
+
* @template T - The type of data the operator validates.
|
|
85
|
+
* @param schemas - Multiple schemas that all must match the data.
|
|
86
|
+
* @returns A schema that validates data against all of the provided schemas.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { and, ascertain } from 'ascertain';
|
|
91
|
+
*
|
|
92
|
+
* // Combine object schema with additional constraints
|
|
93
|
+
* const userSchema = and(
|
|
94
|
+
* { name: String, age: Number },
|
|
95
|
+
* { age: Number } // Additional constraint
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* ascertain(userSchema, { name: "John", age: 25 }, "user"); // ✓ Valid
|
|
99
|
+
*
|
|
100
|
+
* // Ensure an object is both a Date and has specific methods
|
|
101
|
+
* const validDateSchema = and(Date, { toISOString: Function });
|
|
102
|
+
* ascertain(validDateSchema, new Date(), "date"); // ✓ Valid
|
|
103
|
+
*
|
|
104
|
+
* // Multiple validation layers
|
|
105
|
+
* const positiveNumberSchema = and(Number, (n: number) => n > 0);
|
|
106
|
+
* ascertain(positiveNumberSchema, 42, "count"); // ✓ Valid
|
|
107
|
+
* ascertain(positiveNumberSchema, -5, "count"); // ✗ Throws error
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
22
110
|
export declare const and: <T>(...schemas: Schema<T>[]) => And<T>;
|
|
23
111
|
declare class Optional<T> extends Operator<T> {
|
|
24
112
|
constructor(schema: Schema<T>);
|
|
25
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Operator for making a schema optional (nullable).
|
|
116
|
+
*
|
|
117
|
+
* Creates a schema that accepts the provided schema or null/undefined values.
|
|
118
|
+
* This is useful for optional object properties or nullable fields.
|
|
119
|
+
*
|
|
120
|
+
* @template T - The type of data the operator validates.
|
|
121
|
+
* @param schema - The schema to make optional.
|
|
122
|
+
* @returns A schema that validates data against the provided schema or accepts null/undefined.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* import { optional, ascertain } from 'ascertain';
|
|
127
|
+
*
|
|
128
|
+
* // Optional string field
|
|
129
|
+
* const userSchema = {
|
|
130
|
+
* name: String,
|
|
131
|
+
* nickname: optional(String),
|
|
132
|
+
* age: Number
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* // All of these are valid
|
|
136
|
+
* ascertain(userSchema, {
|
|
137
|
+
* name: "John",
|
|
138
|
+
* nickname: "Johnny",
|
|
139
|
+
* age: 30
|
|
140
|
+
* }, "user"); // ✓ Valid
|
|
141
|
+
*
|
|
142
|
+
* ascertain(userSchema, {
|
|
143
|
+
* name: "Jane",
|
|
144
|
+
* nickname: null,
|
|
145
|
+
* age: 25
|
|
146
|
+
* }, "user"); // ✓ Valid
|
|
147
|
+
*
|
|
148
|
+
* ascertain(userSchema, {
|
|
149
|
+
* name: "Bob",
|
|
150
|
+
* age: 35
|
|
151
|
+
* // nickname is undefined
|
|
152
|
+
* }, "user"); // ✓ Valid
|
|
153
|
+
*
|
|
154
|
+
* // Optional complex objects
|
|
155
|
+
* const profileSchema = {
|
|
156
|
+
* id: Number,
|
|
157
|
+
* settings: optional({
|
|
158
|
+
* theme: String,
|
|
159
|
+
* notifications: Boolean
|
|
160
|
+
* })
|
|
161
|
+
* };
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
26
164
|
export declare const optional: <T>(schema: Schema<T>) => Optional<T>;
|
|
27
165
|
declare class Tuple<T> extends Operator<T> {
|
|
28
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Operator for validating data against a fixed-length tuple of schemas.
|
|
169
|
+
*
|
|
170
|
+
* Creates a schema that validates arrays with a specific length and type for each position.
|
|
171
|
+
* This is useful for coordinate pairs, RGB values, or any fixed-structure data.
|
|
172
|
+
*
|
|
173
|
+
* @template T - The type of data the operator validates (a tuple of types).
|
|
174
|
+
* @param schemas - Schemas for each position in the tuple, in order.
|
|
175
|
+
* @returns A schema that validates data as a tuple with the specified structure.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* import { tuple, ascertain } from 'ascertain';
|
|
180
|
+
*
|
|
181
|
+
* // 2D coordinate tuple
|
|
182
|
+
* const pointSchema = tuple(Number, Number);
|
|
183
|
+
* ascertain(pointSchema, [10, 20], "point"); // ✓ Valid
|
|
184
|
+
* ascertain(pointSchema, [1.5, 2.7], "point"); // ✓ Valid
|
|
185
|
+
* ascertain(pointSchema, [10], "point"); // ✗ Throws error (too short)
|
|
186
|
+
* ascertain(pointSchema, [10, 20, 30], "point"); // ✗ Throws error (too long)
|
|
187
|
+
*
|
|
188
|
+
* // RGB color tuple
|
|
189
|
+
* const colorSchema = tuple(Number, Number, Number);
|
|
190
|
+
* ascertain(colorSchema, [255, 128, 0], "color"); // ✓ Valid
|
|
191
|
+
*
|
|
192
|
+
* // Mixed type tuple
|
|
193
|
+
* const userInfoSchema = tuple(String, Number, Boolean);
|
|
194
|
+
* ascertain(userInfoSchema, ["Alice", 25, true], "userInfo"); // ✓ Valid
|
|
195
|
+
*
|
|
196
|
+
* // Nested tuple
|
|
197
|
+
* const lineSchema = tuple(
|
|
198
|
+
* tuple(Number, Number), // start point
|
|
199
|
+
* tuple(Number, Number) // end point
|
|
200
|
+
* );
|
|
201
|
+
* ascertain(lineSchema, [[0, 0], [10, 10]], "line"); // ✓ Valid
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
29
204
|
export declare const tuple: <T>(...schemas: Schema<T>[]) => Tuple<T>;
|
|
30
205
|
export declare const fromBase64: (value: string) => string;
|
|
31
206
|
export declare const asError: <T>(message: string) => T;
|
|
32
207
|
export declare const as: {
|
|
208
|
+
/**
|
|
209
|
+
* Attempts to convert a value to a string.
|
|
210
|
+
*
|
|
211
|
+
* @param value - The value to convert.
|
|
212
|
+
* @returns The value as a string, or a TypeError if not a string.
|
|
213
|
+
*/
|
|
33
214
|
string: (value: string | undefined) => string;
|
|
215
|
+
/**
|
|
216
|
+
* Attempts to convert a value to a number.
|
|
217
|
+
*
|
|
218
|
+
* @param value - The value to convert (expected to be a string representation of a number).
|
|
219
|
+
* @returns The value as a number, or a TypeError if not a valid number.
|
|
220
|
+
*/
|
|
34
221
|
number: (value: string | undefined) => number;
|
|
222
|
+
/**
|
|
223
|
+
* Attempts to convert a value to a Date object.
|
|
224
|
+
*
|
|
225
|
+
* @param value - The value to convert (expected to be a string representation of a date).
|
|
226
|
+
* @returns The value as a Date object, or a TypeError if not a valid date.
|
|
227
|
+
*/
|
|
35
228
|
date: (value: string | undefined) => Date;
|
|
229
|
+
/**
|
|
230
|
+
* Attempts to convert a value to a time duration in milliseconds.
|
|
231
|
+
*
|
|
232
|
+
* @param value - The value to convert (e.g., "5s" for 5 seconds).
|
|
233
|
+
* @param conversionFactor - Optional factor to divide the result by (default is 1).
|
|
234
|
+
* @returns The time duration in milliseconds, or a TypeError if the format is invalid.
|
|
235
|
+
*/
|
|
36
236
|
time: (value: string | undefined, conversionFactor?: number) => number;
|
|
237
|
+
/**
|
|
238
|
+
* Attempts to convert a value to a boolean.
|
|
239
|
+
*
|
|
240
|
+
* @param value - The boolean like value to convert (e.g., "true", "1", "enabled").
|
|
241
|
+
* @returns The value as a boolean, or a TypeError if it could not be converted to a boolean.
|
|
242
|
+
*/
|
|
37
243
|
boolean: (value: string | undefined) => boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Attempts to convert a string into an array of strings by splitting it using the given delimiter.
|
|
246
|
+
*
|
|
247
|
+
* @param value - The string value to attempt to split into an array.
|
|
248
|
+
* @param delimiter - The character or string used to separate elements in the input string.
|
|
249
|
+
* @returns An array of strings if the conversion is successful, or a TypeError if the value is not a string.
|
|
250
|
+
*/
|
|
38
251
|
array: (value: string | undefined, delimiter: string) => string[];
|
|
252
|
+
/**
|
|
253
|
+
* Attempts to parse a JSON string into a JavaScript object.
|
|
254
|
+
*
|
|
255
|
+
* @template T - The expected type of the parsed JSON object.
|
|
256
|
+
* @param value - The JSON string to attempt to parse.
|
|
257
|
+
* @returns The parsed JSON object if successful, or a TypeError if the value is not valid JSON.
|
|
258
|
+
*/
|
|
39
259
|
json: <T = object>(value: string | undefined) => T;
|
|
260
|
+
/**
|
|
261
|
+
* Attempts to decode a base64-encoded string.
|
|
262
|
+
*
|
|
263
|
+
* @param value - The base64-encoded string to attempt to decode.
|
|
264
|
+
* @returns The decoded string if successful, or a TypeError if the value is not valid base64.
|
|
265
|
+
*/
|
|
40
266
|
base64: (value: string | undefined) => string;
|
|
41
267
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
268
|
+
/**
|
|
269
|
+
* Compiles a schema into a validation function.
|
|
270
|
+
*
|
|
271
|
+
* This function takes a schema definition and generates a JavaScript function
|
|
272
|
+
* that can be used to validate data against the schema.
|
|
273
|
+
*
|
|
274
|
+
* @template T - The type of data the schema validates.
|
|
275
|
+
* @param schema - The schema to compile.
|
|
276
|
+
* @param rootName - A name for the root of the data structure (used in error messages).
|
|
277
|
+
* @returns A validation function that takes data as input and throws a TypeError if the data does not conform to the schema.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* import { compile, optional, and, or } from 'ascertain';
|
|
282
|
+
*
|
|
283
|
+
* const userSchema = {
|
|
284
|
+
* name: String,
|
|
285
|
+
* age: Number,
|
|
286
|
+
* email: optional(String),
|
|
287
|
+
* role: or('admin', 'user', 'guest')
|
|
288
|
+
* };
|
|
289
|
+
*
|
|
290
|
+
* const validateUser = compile(userSchema, 'User');
|
|
291
|
+
*
|
|
292
|
+
* // Valid data - no error thrown
|
|
293
|
+
* validateUser({
|
|
294
|
+
* name: 'John Doe',
|
|
295
|
+
* age: 30,
|
|
296
|
+
* email: 'john@example.com',
|
|
297
|
+
* role: 'user'
|
|
298
|
+
* });
|
|
299
|
+
*
|
|
300
|
+
* // Invalid data - throws TypeError
|
|
301
|
+
* try {
|
|
302
|
+
* validateUser({
|
|
303
|
+
* name: 123, // Invalid: should be string
|
|
304
|
+
* age: 'thirty' // Invalid: should be number
|
|
305
|
+
* });
|
|
306
|
+
* } catch (error) {
|
|
307
|
+
* console.error(error.message); // Detailed validation errors
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
46
311
|
export declare const compile: <T>(schema: Schema<T>, rootName: string) => (data: T) => any;
|
|
312
|
+
/**
|
|
313
|
+
* Asserts that data conforms to a given schema.
|
|
314
|
+
*
|
|
315
|
+
* This function is a convenient wrapper around `compile`. It compiles the schema
|
|
316
|
+
* and immediately validates the provided data against it.
|
|
317
|
+
*
|
|
318
|
+
* @template T - The type of data the schema validates.
|
|
319
|
+
* @param schema - The schema to validate against.
|
|
320
|
+
* @param data - The data to validate.
|
|
321
|
+
* @param rootName - A name for the root of the data structure (used in error messages, defaults to '[root]').
|
|
322
|
+
* @throws `{TypeError}` If the data does not conform to the schema.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* import { ascertain, optional, and, or } from 'ascertain';
|
|
327
|
+
*
|
|
328
|
+
* const userSchema = {
|
|
329
|
+
* name: String,
|
|
330
|
+
* age: Number,
|
|
331
|
+
* email: optional(String),
|
|
332
|
+
* active: Boolean
|
|
333
|
+
* };
|
|
334
|
+
*
|
|
335
|
+
* const userData = {
|
|
336
|
+
* name: 'Alice',
|
|
337
|
+
* age: 25,
|
|
338
|
+
* email: 'alice@example.com',
|
|
339
|
+
* active: true
|
|
340
|
+
* };
|
|
341
|
+
*
|
|
342
|
+
* // Validate data - throws if invalid, otherwise continues silently
|
|
343
|
+
* ascertain(userSchema, userData, 'UserData');
|
|
344
|
+
* console.log('User data is valid!');
|
|
345
|
+
*
|
|
346
|
+
* // Example with invalid data
|
|
347
|
+
* try {
|
|
348
|
+
* ascertain(userSchema, {
|
|
349
|
+
* name: 'Bob',
|
|
350
|
+
* age: 'twenty-five', // Invalid: should be number
|
|
351
|
+
* active: true
|
|
352
|
+
* }, 'UserData');
|
|
353
|
+
* } catch (error) {
|
|
354
|
+
* console.error('Validation failed:', error.message);
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* // Array validation
|
|
361
|
+
* const numbersSchema = [Number];
|
|
362
|
+
* const numbers = [1, 2, 3, 4, 5];
|
|
363
|
+
*
|
|
364
|
+
* ascertain(numbersSchema, numbers, 'Numbers');
|
|
365
|
+
*
|
|
366
|
+
* // Tuple validation
|
|
367
|
+
* const coordinateSchema = tuple(Number, Number);
|
|
368
|
+
* const point = [10, 20];
|
|
369
|
+
*
|
|
370
|
+
* ascertain(coordinateSchema, point, 'Point');
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
47
373
|
export declare const ascertain: <T>(schema: Schema<T>, data: T, rootName?: string) => void;
|
|
48
374
|
export {};
|
package/build/index.js
CHANGED
|
@@ -63,19 +63,18 @@ export const as = {
|
|
|
63
63
|
json: (value)=>{
|
|
64
64
|
try {
|
|
65
65
|
return JSON.parse(value);
|
|
66
|
-
} catch
|
|
66
|
+
} catch {
|
|
67
67
|
return asError(`Invalid value ${value}, expected a valid JSON string`);
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
base64: (value)=>{
|
|
71
71
|
try {
|
|
72
72
|
return fromBase64(value);
|
|
73
|
-
} catch
|
|
73
|
+
} catch {
|
|
74
74
|
return asError(`Invalid value ${value}, expected a valid base64 string`);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
export const formatError = (value, expected, path, subject)=>`Invalid ${subject} ${JSON.stringify(value)} for path ${path}, expected ${expected}.`;
|
|
79
78
|
class Context {
|
|
80
79
|
registry = [];
|
|
81
80
|
varIndex = 0;
|
|
@@ -226,14 +225,14 @@ ${codeGenExpectNoErrors(errorsAlias)}
|
|
|
226
225
|
return `
|
|
227
226
|
const ${valueAlias} = ${valuePath};
|
|
228
227
|
const ${registryAlias} = ctx.registry[${index}];
|
|
229
|
-
if (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for "path", expected symbol\`); }
|
|
228
|
+
if (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for path "${path}", expected symbol\`); }
|
|
230
229
|
if (${valueAlias} !== ${registryAlias}) { throw new TypeError(\`Invalid value \${${valueAlias}.toString()} for path "${path}", expected ${schema.toString()}\`); }
|
|
231
230
|
`;
|
|
232
231
|
} else if (schema === null || schema === undefined) {
|
|
233
232
|
const valueAlias = context.unique('v');
|
|
234
233
|
return `
|
|
235
234
|
const ${valueAlias} = ${valuePath};
|
|
236
|
-
if (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\`Invalid value ${valueAlias} for path "${path}", expected nullable\`); }
|
|
235
|
+
if (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\`Invalid value \${JSON.stringify(${valueAlias})} for path "${path}", expected nullable\`); }
|
|
237
236
|
`;
|
|
238
237
|
} else {
|
|
239
238
|
const valueAlias = context.unique('v');
|
|
@@ -243,7 +242,7 @@ const ${valueAlias} = ${valuePath};
|
|
|
243
242
|
const ${value} = ${JSON.stringify(schema)};
|
|
244
243
|
${codeGenExpectNonError(valueAlias, path)}
|
|
245
244
|
if (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\`Invalid type \${typeof ${valueAlias}} for path "${path}", expected ${typeof schema}\`); }
|
|
246
|
-
if (${valueAlias} !== ${value}) { throw new TypeError(\`Invalid value
|
|
245
|
+
if (${valueAlias} !== ${value}) { throw new TypeError(\`Invalid value \${JSON.stringify(${valueAlias})} for path "${path}", expected ${JSON.stringify(schema)}\`); }
|
|
247
246
|
`;
|
|
248
247
|
}
|
|
249
248
|
};
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["abstract class Operator<T> {\n constructor(public readonly schemas: Schema<T>[]) {\n if (schemas.length === 0) {\n throw new TypeError(`Operation schema ${this.constructor.name} must have at least one element`);\n }\n }\n}\n\nexport const $keys = Symbol.for('@@keys');\nexport const $values = Symbol.for('@@values');\nexport const $strict = Symbol.for('@@strict');\n\nexport type Schema<T> =\n T extends Record<string | number | symbol, unknown>\n ? { [K in keyof T]?: Schema<T[K]> | unknown } & { [$keys]?: Schema<keyof T> } & { [$values]?: Schema<T[keyof T]> } & { [$strict]?: boolean }\n : T extends Array<infer A>\n ? Schema<A>[] | unknown\n : unknown;\n\nclass Or<T> extends Operator<T> {}\nexport const or = <T>(...schemas: Schema<T>[]) => new Or(schemas);\n\nclass And<T> extends Operator<T> {}\nexport const and = <T>(...schemas: Schema<T>[]) => new And(schemas);\n\nclass Optional<T> extends Operator<T> {\n constructor(schema: Schema<T>) {\n super([schema]);\n }\n}\nexport const optional = <T>(schema: Schema<T>) => new Optional(schema);\n\nclass Tuple<T> extends Operator<T> {}\nexport const tuple = <T>(...schemas: Schema<T>[]) => new Tuple(schemas);\n\nexport const fromBase64 = typeof Buffer === 'undefined' ? (value: string) => atob(value) : (value: string) => Buffer.from(value, 'base64').toString('utf-8');\n\nconst MULTIPLIERS = {\n ms: 1,\n s: 1000,\n m: 60000,\n h: 3600000,\n d: 86400000,\n w: 604800000,\n};\n\nexport const asError = <T>(message: string) => new TypeError(message) as unknown as T;\n\nexport const as = {\n string: (value: string | undefined): string => {\n return typeof value === 'string' ? value : asError(`Invalid value \"${value}\", expected a string`);\n },\n number: (value: string | undefined): number => {\n const result = parseFloat(value as string);\n return Number.isNaN(result) ? asError(`Invalid value ${value}, expected a valid number`) : result;\n },\n date: (value: string | undefined): Date => {\n const result = Date.parse(value as string);\n const date = new Date(result);\n return Number.isNaN(date.valueOf()) ? asError(`Invalid value \"${value}\", expected a valid date format`) : date;\n },\n time: (value: string | undefined, conversionFactor = 1): number => {\n const matches = value?.match(/^(\\d*\\.?\\d*)(ms|s|m|h|d|w)?$/);\n if (matches) {\n const [, amount, unit = 'ms'] = matches;\n return parseInt(`${(parseFloat(amount) * MULTIPLIERS[unit as keyof typeof MULTIPLIERS]) / conversionFactor}`);\n }\n return asError(`Invalid value ${value}, expected a valid time format`);\n },\n boolean: (value: string | undefined): boolean =>\n /^(0|1|true|false|enabled|disabled)$/i.test(value as string)\n ? /^(1|true|enabled)$/i.test(value as string)\n : asError(`Invalid value ${value}, expected a boolean like`),\n array: (value: string | undefined, delimiter: string): string[] => value?.split?.(delimiter) ?? asError(`Invalid value ${value}, expected an array`),\n json: <T = object>(value: string | undefined): T => {\n try {\n return JSON.parse(value as string);\n } catch (e) {\n return asError(`Invalid value ${value}, expected a valid JSON string`);\n }\n },\n base64: (value: string | undefined): string => {\n try {\n return fromBase64(value as string);\n } catch (e) {\n return asError(`Invalid value ${value}, expected a valid base64 string`);\n }\n },\n};\n\nexport interface ErrorFormatter {\n (value: unknown, expected: unknown, path: string, subject: string): string;\n}\n\nexport const formatError: ErrorFormatter = (value, expected, path, subject) =>\n `Invalid ${subject} ${JSON.stringify(value)} for path ${path}, expected ${expected}.`;\n\nclass Context {\n public readonly registry: unknown[] = [];\n private varIndex = 0;\n\n register(value: unknown): number {\n if (!this.registry.includes(value)) {\n this.registry.push(value);\n }\n return this.registry.indexOf(value);\n }\n\n unique(prefix: string) {\n return `${prefix}$$${this.varIndex++}`;\n }\n}\n\nconst codeGenCollectErrors = (errorsAlias: string, code: string, extra: string = '') => `try {${code}} catch (e) {${errorsAlias}.push(e.message);${extra}}`;\nconst codeGenExpectNoErrors = (errorsAlias: string) => `if (${errorsAlias}.length !== 0) { throw new TypeError(${errorsAlias}.join('\\\\n')); }`;\nconst codeGenExpectNonError = (valueAlias: string, path: string) =>\n `if (${valueAlias} instanceof Error) { throw new TypeError(\\`\\${${valueAlias}.message} for path \"${path}\".\\`); }`;\nconst codeGenExpectNonNullable = (valueAlias: string, path: string) =>\n `if (${valueAlias} === null || ${valueAlias} === undefined) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected non-nullable.\\`); }`;\nconst codeGenExpectObject = (valueAlias: string, path: string, instanceOf: string) =>\n `if (typeof ${valueAlias} !== 'object') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected an instance of ${instanceOf}\\`); }`;\nconst codeGenExpectArray = (valueAlias: string, path: string) =>\n `if (!Array.isArray(${valueAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}.constructor?.name} for path \"${path}\", expected an instance of Array.\\`); }`;\n\nconst codeGen = <T>(schema: Schema<T>, context: Context, valuePath: string, path: string): string => {\n if (schema instanceof And) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas.map((s) => `try { ${codeGen(s, context, valueAlias, path)} } catch (e) { ${errorsAlias}.push(e.message); }`).join('\\n');\n return `// And\n const ${errorsAlias} = [];\n const ${valueAlias} = ${valuePath};\n ${code}\n ${codeGenExpectNoErrors(errorsAlias)}\n`;\n } else if (schema instanceof Or) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas\n .map((s) => codeGen(s, context, valueAlias, path))\n .reduceRight((result, code) => codeGenCollectErrors(errorsAlias, code, result), codeGenExpectNoErrors(errorsAlias));\n return `// Or\nconst ${errorsAlias} = [];\nconst ${valueAlias} = ${valuePath};\n${code}\n `;\n } else if (schema instanceof Optional) {\n const valueAlias = context.unique('v');\n return `// Optional\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== undefined && ${valueAlias} !== null) { ${codeGen(schema.schemas[0], context, valueAlias, path)} }\n`;\n } else if (schema instanceof Tuple) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code: string[] = [\n '// Tuple',\n `const ${valueAlias} = ${valuePath};`,\n `const ${errorsAlias} = [];`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n `if (${valueAlias}.length > ${schema.schemas.length}) { throw new TypeError(\\`Invalid tuple length \\${${valueAlias}.length} for path \"${path}\", expected ${schema.schemas.length}.\\`); }`,\n ...schema.schemas.map((s, idx) => codeGenCollectErrors(errorsAlias, codeGen(s, context, `${valueAlias}[${idx}]`, `${path}[${idx}]`))),\n codeGenExpectNoErrors(errorsAlias),\n ];\n return code.join('\\n');\n } else if (typeof schema === 'function') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n `const ${registryAlias} = ctx.registry[${index}];`,\n codeGenExpectNonNullable(valueAlias, path),\n ];\n if ((schema as unknown) !== Error && !(schema?.prototype instanceof Error)) {\n code.push(codeGenExpectNonError(valueAlias, path));\n }\n\n code.push(\n `if (typeof ${valueAlias} === 'object' && !(${valueAlias} instanceof ${registryAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected an instance of ${schema?.name}\\`); }`,\n `if (typeof ${valueAlias} !== 'object' && ${valueAlias}?.constructor !== ${registryAlias}) { throw new TypeError(\\`Invalid type \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected type ${schema?.name}\\`); }`,\n `if (Number.isNaN(${valueAlias}?.valueOf?.())) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected a valid ${schema?.name}\\`); }`,\n );\n return code.join('\\n');\n } else if (Array.isArray(schema)) {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectNonError(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n ];\n if (schema.length > 0) {\n const value = context.unique('val');\n const key = context.unique('key');\n const errorsAlias = context.unique('err');\n code.push(`const ${errorsAlias} = [];`);\n code.push(\n ...schema.map(\n (s) => `${valueAlias}.forEach((${value},${key}) => { ${codeGenCollectErrors(errorsAlias, codeGen(s, context, value, `${path}[\\${${key}}]`))} });`,\n ),\n );\n\n code.push(codeGenExpectNoErrors(errorsAlias));\n }\n return code.join('\\n');\n } else if (typeof schema === 'object' && schema !== null) {\n if (schema instanceof RegExp) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\n${codeGenExpectNonNullable(valueAlias, path)}\n${codeGenExpectNonError(valueAlias, path)}\nif (!${schema.toString()}.test('' + ${valueAlias})) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected to match ${schema.toString()}\\`); }\n`;\n } else {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Object'),\n codeGenExpectNonError(valueAlias, path),\n ];\n if ($keys in schema) {\n const keysAlias = context.unique('k');\n const errorsAlias = context.unique('err');\n const kAlias = context.unique('k');\n code.push(`\nconst ${keysAlias} = Object.keys(${valueAlias});\nconst ${errorsAlias} = [];\n${keysAlias}.forEach(${kAlias} => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$keys], context, kAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($values in schema) {\n const vAlias = context.unique('val');\n const kAlias = context.unique('k');\n const entriesAlias = context.unique('en');\n const errorsAlias = context.unique('err');\n code.push(`\nconst ${entriesAlias} = Object.entries(${valueAlias});\nconst ${errorsAlias} = [];\n${entriesAlias}.forEach(([${kAlias},${vAlias}]) => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$values], context, vAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($strict in schema && schema[$strict]) {\n const keysAlias = context.unique('k');\n const kAlias = context.unique('k');\n const extraAlias = context.unique('ex');\n code.push(`const ${keysAlias} = new Set(${JSON.stringify(Object.keys(schema))});`);\n code.push(`const ${extraAlias} = Object.keys(${valueAlias}).filter(${kAlias} => !${keysAlias}.has(${kAlias}));`);\n code.push(`if (${extraAlias}.length !== 0) { throw new TypeError(\\`Extra properties: \\${${extraAlias}}, are not allowed for path \"${path}\"\\`); }`);\n }\n code.push(...Object.entries(schema).map(([key, s]) => codeGen(s, context, `${valueAlias}['${key}']`, `${path}.${key}`)));\n return `${code.join('\\n')}`;\n }\n } else if (typeof schema === 'symbol') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${registryAlias} = ctx.registry[${index}];\nif (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for \"path\", expected symbol\\`); }\nif (${valueAlias} !== ${registryAlias}) { throw new TypeError(\\`Invalid value \\${${valueAlias}.toString()} for path \"${path}\", expected ${schema.toString()}\\`); }\n `;\n } else if (schema === null || schema === undefined) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\\`Invalid value ${valueAlias} for path \"${path}\", expected nullable\\`); }\n `;\n } else {\n const valueAlias = context.unique('v');\n const value = context.unique('val');\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${value} = ${JSON.stringify(schema)};\n${codeGenExpectNonError(valueAlias, path)}\nif (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected ${typeof schema}\\`); }\nif (${valueAlias} !== ${value}) { throw new TypeError(\\`Invalid value ${JSON.stringify(valueAlias)} for path \"${path}\", expected ${JSON.stringify(schema)}\\`); }\n`;\n }\n};\n\nexport const compile = <T>(schema: Schema<T>, rootName: string) => {\n const context = new Context();\n const code = codeGen(schema, context, 'data', rootName);\n const validator = new Function('ctx', 'data', code);\n return (data: T) => validator(context, data);\n};\n\nexport const ascertain = <T>(schema: Schema<T>, data: T, rootName = '[root]') => {\n compile(schema, rootName)(data);\n};\n"],"names":["Operator","constructor","schemas","length","TypeError","name","$keys","Symbol","for","$values","$strict","Or","or","And","and","Optional","schema","optional","Tuple","tuple","fromBase64","Buffer","value","atob","from","toString","MULTIPLIERS","ms","s","m","h","d","w","asError","message","as","string","number","result","parseFloat","Number","isNaN","date","Date","parse","valueOf","time","conversionFactor","matches","match","amount","unit","parseInt","boolean","test","array","delimiter","split","json","JSON","e","base64","formatError","expected","path","subject","stringify","Context","registry","varIndex","register","includes","push","indexOf","unique","prefix","codeGenCollectErrors","errorsAlias","code","extra","codeGenExpectNoErrors","codeGenExpectNonError","valueAlias","codeGenExpectNonNullable","codeGenExpectObject","instanceOf","codeGenExpectArray","codeGen","context","valuePath","map","join","reduceRight","idx","index","registryAlias","Error","prototype","Array","isArray","key","RegExp","keysAlias","kAlias","vAlias","entriesAlias","extraAlias","Object","keys","entries","undefined","compile","rootName","validator","Function","data","ascertain"],"mappings":"AAAA,MAAeA;;IACbC,YAAY,AAAgBC,OAAoB,CAAE;aAAtBA,UAAAA;QAC1B,IAAIA,QAAQC,MAAM,KAAK,GAAG;YACxB,MAAM,IAAIC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAACH,WAAW,CA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AC;IACC;AACF;AAEA,OAAO,MAAM+F,UAAU,CAAI/F,QAAmBgG;IAC5C,MAAMxB,UAAU,IAAIrB;IACpB,MAAMW,OAAOS,QAAQvE,QAAQwE,SAAS,QAAQwB;IAC9C,MAAMC,YAAY,IAAIC,SAAS,OAAO,QAAQpC;IAC9C,OAAO,CAACqC,OAAYF,UAAUzB,SAAS2B;AACzC,EAAE;AAEF,OAAO,MAAMC,YAAY,CAAIpG,QAAmBmG,MAASH,WAAW,QAAQ;IAC1ED,QAAQ/F,QAAQgG,UAAUG;AAC5B,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Abstract base class for schema operators.\n *\n * Provides a common constructor that enforces having at least one schema.\n *\n * @template T - The type of data the operator validates.\n * @abstract\n * @internal\n */\nabstract class Operator<T> {\n constructor(public readonly schemas: Schema<T>[]) {\n if (schemas.length === 0) {\n throw new TypeError(`Operation schema ${this.constructor.name} must have at least one element`);\n }\n }\n}\n\n// https://standardschema.dev/\n\n/**\n * Symbol for validating object keys against a schema.\n */\nexport const $keys = Symbol.for('@@keys');\n/**\n * Symbol for validating object values against a schema.\n */\nexport const $values = Symbol.for('@@values');\n/**\n * Symbol for enforcing strict object validation (no extra properties allowed).\n */\nexport const $strict = Symbol.for('@@strict');\n\n/**\n * Represents a schema for validating data.\n *\n * Schemas can be defined for various data types, including objects, arrays, and primitives.\n *\n * @template T - The type of data the schema validates.\n */\nexport type Schema<T> =\n T extends Record<string | number | symbol, unknown>\n ? { [K in keyof T]?: Schema<T[K]> | unknown } & { [$keys]?: Schema<keyof T> } & { [$values]?: Schema<T[keyof T]> } & { [$strict]?: boolean }\n : T extends Array<infer A>\n ? Schema<A>[] | unknown\n : unknown;\n\nclass Or<T> extends Operator<T> {}\n/**\n * Operator for validating data against any of the provided schemas (logical OR).\n *\n * Creates a schema that accepts data matching any one of the provided schemas.\n * This is useful for creating union types or alternative validation paths.\n *\n * @template T - The type of data the operator validates.\n * @param schemas - Multiple schemas where at least one must match the data.\n * @returns A schema that validates data against any of the provided schemas.\n *\n * @example\n * ```typescript\n * import { or, ascertain } from 'ascertain';\n *\n * // Create a schema that accepts either a string or number\n * const stringOrNumber = or(String, Number);\n *\n * ascertain(stringOrNumber, \"hello\", \"value\"); // ✓ Valid\n * ascertain(stringOrNumber, 42, \"value\"); // ✓ Valid\n * ascertain(stringOrNumber, true, \"value\"); // ✗ Throws error\n *\n * // Union of literal values\n * const statusSchema = or('pending', 'completed', 'failed');\n * ascertain(statusSchema, 'pending', \"status\"); // ✓ Valid\n *\n * // Complex schema combinations\n * const userIdSchema = or(Number, { id: Number, temp: Boolean });\n * ascertain(userIdSchema, 123, \"userId\"); // ✓ Valid\n * ascertain(userIdSchema, { id: 456, temp: true }, \"userId\"); // ✓ Valid\n * ```\n */\nexport const or = <T>(...schemas: Schema<T>[]) => new Or(schemas);\n\nclass And<T> extends Operator<T> {}\n/**\n * Operator for validating data against all provided schemas (logical AND).\n *\n * Creates a schema that requires data to match every one of the provided schemas.\n * This is useful for combining multiple validation requirements or adding constraints.\n *\n * @template T - The type of data the operator validates.\n * @param schemas - Multiple schemas that all must match the data.\n * @returns A schema that validates data against all of the provided schemas.\n *\n * @example\n * ```typescript\n * import { and, ascertain } from 'ascertain';\n *\n * // Combine object schema with additional constraints\n * const userSchema = and(\n * { name: String, age: Number },\n * { age: Number } // Additional constraint\n * );\n *\n * ascertain(userSchema, { name: \"John\", age: 25 }, \"user\"); // ✓ Valid\n *\n * // Ensure an object is both a Date and has specific methods\n * const validDateSchema = and(Date, { toISOString: Function });\n * ascertain(validDateSchema, new Date(), \"date\"); // ✓ Valid\n *\n * // Multiple validation layers\n * const positiveNumberSchema = and(Number, (n: number) => n > 0);\n * ascertain(positiveNumberSchema, 42, \"count\"); // ✓ Valid\n * ascertain(positiveNumberSchema, -5, \"count\"); // ✗ Throws error\n * ```\n */\nexport const and = <T>(...schemas: Schema<T>[]) => new And(schemas);\n\nclass Optional<T> extends Operator<T> {\n constructor(schema: Schema<T>) {\n super([schema]);\n }\n}\n/**\n * Operator for making a schema optional (nullable).\n *\n * Creates a schema that accepts the provided schema or null/undefined values.\n * This is useful for optional object properties or nullable fields.\n *\n * @template T - The type of data the operator validates.\n * @param schema - The schema to make optional.\n * @returns A schema that validates data against the provided schema or accepts null/undefined.\n *\n * @example\n * ```typescript\n * import { optional, ascertain } from 'ascertain';\n *\n * // Optional string field\n * const userSchema = {\n * name: String,\n * nickname: optional(String),\n * age: Number\n * };\n *\n * // All of these are valid\n * ascertain(userSchema, {\n * name: \"John\",\n * nickname: \"Johnny\",\n * age: 30\n * }, \"user\"); // ✓ Valid\n *\n * ascertain(userSchema, {\n * name: \"Jane\",\n * nickname: null,\n * age: 25\n * }, \"user\"); // ✓ Valid\n *\n * ascertain(userSchema, {\n * name: \"Bob\",\n * age: 35\n * // nickname is undefined\n * }, \"user\"); // ✓ Valid\n *\n * // Optional complex objects\n * const profileSchema = {\n * id: Number,\n * settings: optional({\n * theme: String,\n * notifications: Boolean\n * })\n * };\n * ```\n */\nexport const optional = <T>(schema: Schema<T>) => new Optional(schema);\n\nclass Tuple<T> extends Operator<T> {}\n/**\n * Operator for validating data against a fixed-length tuple of schemas.\n *\n * Creates a schema that validates arrays with a specific length and type for each position.\n * This is useful for coordinate pairs, RGB values, or any fixed-structure data.\n *\n * @template T - The type of data the operator validates (a tuple of types).\n * @param schemas - Schemas for each position in the tuple, in order.\n * @returns A schema that validates data as a tuple with the specified structure.\n *\n * @example\n * ```typescript\n * import { tuple, ascertain } from 'ascertain';\n *\n * // 2D coordinate tuple\n * const pointSchema = tuple(Number, Number);\n * ascertain(pointSchema, [10, 20], \"point\"); // ✓ Valid\n * ascertain(pointSchema, [1.5, 2.7], \"point\"); // ✓ Valid\n * ascertain(pointSchema, [10], \"point\"); // ✗ Throws error (too short)\n * ascertain(pointSchema, [10, 20, 30], \"point\"); // ✗ Throws error (too long)\n *\n * // RGB color tuple\n * const colorSchema = tuple(Number, Number, Number);\n * ascertain(colorSchema, [255, 128, 0], \"color\"); // ✓ Valid\n *\n * // Mixed type tuple\n * const userInfoSchema = tuple(String, Number, Boolean);\n * ascertain(userInfoSchema, [\"Alice\", 25, true], \"userInfo\"); // ✓ Valid\n *\n * // Nested tuple\n * const lineSchema = tuple(\n * tuple(Number, Number), // start point\n * tuple(Number, Number) // end point\n * );\n * ascertain(lineSchema, [[0, 0], [10, 10]], \"line\"); // ✓ Valid\n * ```\n */\nexport const tuple = <T>(...schemas: Schema<T>[]) => new Tuple(schemas);\n\nexport const fromBase64 = typeof Buffer === 'undefined' ? (value: string) => atob(value) : (value: string) => Buffer.from(value, 'base64').toString('utf-8');\n\nconst MULTIPLIERS = {\n ms: 1,\n s: 1000,\n m: 60000,\n h: 3600000,\n d: 86400000,\n w: 604800000,\n};\n\nexport const asError = <T>(message: string) => new TypeError(message) as unknown as T;\n\nexport const as = {\n /**\n * Attempts to convert a value to a string.\n *\n * @param value - The value to convert.\n * @returns The value as a string, or a TypeError if not a string.\n */\n string: (value: string | undefined): string => {\n return typeof value === 'string' ? value : asError(`Invalid value \"${value}\", expected a string`);\n },\n /**\n * Attempts to convert a value to a number.\n *\n * @param value - The value to convert (expected to be a string representation of a number).\n * @returns The value as a number, or a TypeError if not a valid number.\n */\n number: (value: string | undefined): number => {\n const result = parseFloat(value as string);\n return Number.isNaN(result) ? asError(`Invalid value ${value}, expected a valid number`) : result;\n },\n /**\n * Attempts to convert a value to a Date object.\n *\n * @param value - The value to convert (expected to be a string representation of a date).\n * @returns The value as a Date object, or a TypeError if not a valid date.\n */\n date: (value: string | undefined): Date => {\n const result = Date.parse(value as string);\n const date = new Date(result);\n return Number.isNaN(date.valueOf()) ? asError(`Invalid value \"${value}\", expected a valid date format`) : date;\n },\n /**\n * Attempts to convert a value to a time duration in milliseconds.\n *\n * @param value - The value to convert (e.g., \"5s\" for 5 seconds).\n * @param conversionFactor - Optional factor to divide the result by (default is 1).\n * @returns The time duration in milliseconds, or a TypeError if the format is invalid.\n */\n time: (value: string | undefined, conversionFactor = 1): number => {\n const matches = value?.match(/^(\\d*\\.?\\d*)(ms|s|m|h|d|w)?$/);\n if (matches) {\n const [, amount, unit = 'ms'] = matches;\n return parseInt(`${(parseFloat(amount) * MULTIPLIERS[unit as keyof typeof MULTIPLIERS]) / conversionFactor}`);\n }\n return asError(`Invalid value ${value}, expected a valid time format`);\n },\n /**\n * Attempts to convert a value to a boolean.\n *\n * @param value - The boolean like value to convert (e.g., \"true\", \"1\", \"enabled\").\n * @returns The value as a boolean, or a TypeError if it could not be converted to a boolean.\n */\n boolean: (value: string | undefined): boolean =>\n /^(0|1|true|false|enabled|disabled)$/i.test(value as string)\n ? /^(1|true|enabled)$/i.test(value as string)\n : asError(`Invalid value ${value}, expected a boolean like`),\n /**\n * Attempts to convert a string into an array of strings by splitting it using the given delimiter.\n *\n * @param value - The string value to attempt to split into an array.\n * @param delimiter - The character or string used to separate elements in the input string.\n * @returns An array of strings if the conversion is successful, or a TypeError if the value is not a string.\n */\n array: (value: string | undefined, delimiter: string): string[] => value?.split?.(delimiter) ?? asError(`Invalid value ${value}, expected an array`),\n /**\n * Attempts to parse a JSON string into a JavaScript object.\n *\n * @template T - The expected type of the parsed JSON object.\n * @param value - The JSON string to attempt to parse.\n * @returns The parsed JSON object if successful, or a TypeError if the value is not valid JSON.\n */\n json: <T = object>(value: string | undefined): T => {\n try {\n return JSON.parse(value as string);\n } catch {\n return asError(`Invalid value ${value}, expected a valid JSON string`);\n }\n },\n /**\n * Attempts to decode a base64-encoded string.\n *\n * @param value - The base64-encoded string to attempt to decode.\n * @returns The decoded string if successful, or a TypeError if the value is not valid base64.\n */\n base64: (value: string | undefined): string => {\n try {\n return fromBase64(value as string);\n } catch {\n return asError(`Invalid value ${value}, expected a valid base64 string`);\n }\n },\n};\n\n/**\n * A class representing the context for schema validation.\n *\n * Stores a registry of values encountered during validation and provides methods for managing it.\n * @internal\n */\nclass Context {\n public readonly registry: unknown[] = [];\n private varIndex = 0;\n\n register(value: unknown): number {\n if (!this.registry.includes(value)) {\n this.registry.push(value);\n }\n return this.registry.indexOf(value);\n }\n\n unique(prefix: string) {\n return `${prefix}$$${this.varIndex++}`;\n }\n}\n\nconst codeGenCollectErrors = (errorsAlias: string, code: string, extra: string = '') => `try {${code}} catch (e) {${errorsAlias}.push(e.message);${extra}}`;\nconst codeGenExpectNoErrors = (errorsAlias: string) => `if (${errorsAlias}.length !== 0) { throw new TypeError(${errorsAlias}.join('\\\\n')); }`;\nconst codeGenExpectNonError = (valueAlias: string, path: string) =>\n `if (${valueAlias} instanceof Error) { throw new TypeError(\\`\\${${valueAlias}.message} for path \"${path}\".\\`); }`;\nconst codeGenExpectNonNullable = (valueAlias: string, path: string) =>\n `if (${valueAlias} === null || ${valueAlias} === undefined) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected non-nullable.\\`); }`;\nconst codeGenExpectObject = (valueAlias: string, path: string, instanceOf: string) =>\n `if (typeof ${valueAlias} !== 'object') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected an instance of ${instanceOf}\\`); }`;\nconst codeGenExpectArray = (valueAlias: string, path: string) =>\n `if (!Array.isArray(${valueAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}.constructor?.name} for path \"${path}\", expected an instance of Array.\\`); }`;\n\nconst codeGen = <T>(schema: Schema<T>, context: Context, valuePath: string, path: string): string => {\n if (schema instanceof And) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas.map((s) => `try { ${codeGen(s, context, valueAlias, path)} } catch (e) { ${errorsAlias}.push(e.message); }`).join('\\n');\n return `// And\n const ${errorsAlias} = [];\n const ${valueAlias} = ${valuePath};\n ${code}\n ${codeGenExpectNoErrors(errorsAlias)}\n`;\n } else if (schema instanceof Or) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code = schema.schemas\n .map((s) => codeGen(s, context, valueAlias, path))\n .reduceRight((result, code) => codeGenCollectErrors(errorsAlias, code, result), codeGenExpectNoErrors(errorsAlias));\n return `// Or\nconst ${errorsAlias} = [];\nconst ${valueAlias} = ${valuePath};\n${code}\n `;\n } else if (schema instanceof Optional) {\n const valueAlias = context.unique('v');\n return `// Optional\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== undefined && ${valueAlias} !== null) { ${codeGen(schema.schemas[0], context, valueAlias, path)} }\n`;\n } else if (schema instanceof Tuple) {\n const valueAlias = context.unique('v');\n const errorsAlias = context.unique('err');\n const code: string[] = [\n '// Tuple',\n `const ${valueAlias} = ${valuePath};`,\n `const ${errorsAlias} = [];`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n `if (${valueAlias}.length > ${schema.schemas.length}) { throw new TypeError(\\`Invalid tuple length \\${${valueAlias}.length} for path \"${path}\", expected ${schema.schemas.length}.\\`); }`,\n ...schema.schemas.map((s, idx) => codeGenCollectErrors(errorsAlias, codeGen(s, context, `${valueAlias}[${idx}]`, `${path}[${idx}]`))),\n codeGenExpectNoErrors(errorsAlias),\n ];\n return code.join('\\n');\n } else if (typeof schema === 'function') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n `const ${registryAlias} = ctx.registry[${index}];`,\n codeGenExpectNonNullable(valueAlias, path),\n ];\n if ((schema as unknown) !== Error && !(schema?.prototype instanceof Error)) {\n code.push(codeGenExpectNonError(valueAlias, path));\n }\n\n code.push(\n `if (typeof ${valueAlias} === 'object' && !(${valueAlias} instanceof ${registryAlias})) { throw new TypeError(\\`Invalid instance of \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected an instance of ${schema?.name}\\`); }`,\n `if (typeof ${valueAlias} !== 'object' && ${valueAlias}?.constructor !== ${registryAlias}) { throw new TypeError(\\`Invalid type \\${${valueAlias}?.constructor?.name} for path \"${path}\", expected type ${schema?.name}\\`); }`,\n `if (Number.isNaN(${valueAlias}?.valueOf?.())) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected a valid ${schema?.name}\\`); }`,\n );\n return code.join('\\n');\n } else if (Array.isArray(schema)) {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectNonError(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Array'),\n codeGenExpectArray(valueAlias, path),\n ];\n if (schema.length > 0) {\n const value = context.unique('val');\n const key = context.unique('key');\n const errorsAlias = context.unique('err');\n code.push(`const ${errorsAlias} = [];`);\n code.push(\n ...schema.map(\n (s) => `${valueAlias}.forEach((${value},${key}) => { ${codeGenCollectErrors(errorsAlias, codeGen(s, context, value, `${path}[\\${${key}}]`))} });`,\n ),\n );\n\n code.push(codeGenExpectNoErrors(errorsAlias));\n }\n return code.join('\\n');\n } else if (typeof schema === 'object' && schema !== null) {\n if (schema instanceof RegExp) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\n${codeGenExpectNonNullable(valueAlias, path)}\n${codeGenExpectNonError(valueAlias, path)}\nif (!${schema.toString()}.test('' + ${valueAlias})) { throw new TypeError(\\`Invalid value \\${${valueAlias}} for path \"${path}\", expected to match ${schema.toString()}\\`); }\n`;\n } else {\n const valueAlias = context.unique('v');\n const code: string[] = [\n `const ${valueAlias} = ${valuePath};`,\n codeGenExpectNonNullable(valueAlias, path),\n codeGenExpectObject(valueAlias, path, 'Object'),\n codeGenExpectNonError(valueAlias, path),\n ];\n if ($keys in schema) {\n const keysAlias = context.unique('k');\n const errorsAlias = context.unique('err');\n const kAlias = context.unique('k');\n code.push(`\nconst ${keysAlias} = Object.keys(${valueAlias});\nconst ${errorsAlias} = [];\n${keysAlias}.forEach(${kAlias} => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$keys], context, kAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($values in schema) {\n const vAlias = context.unique('val');\n const kAlias = context.unique('k');\n const entriesAlias = context.unique('en');\n const errorsAlias = context.unique('err');\n code.push(`\nconst ${entriesAlias} = Object.entries(${valueAlias});\nconst ${errorsAlias} = [];\n${entriesAlias}.forEach(([${kAlias},${vAlias}]) => { ${codeGenCollectErrors(errorsAlias, codeGen(schema[$values], context, vAlias, `${path}[\\${${kAlias}}]`))} });\n${codeGenExpectNoErrors(errorsAlias)}\n`);\n }\n if ($strict in schema && schema[$strict]) {\n const keysAlias = context.unique('k');\n const kAlias = context.unique('k');\n const extraAlias = context.unique('ex');\n code.push(`const ${keysAlias} = new Set(${JSON.stringify(Object.keys(schema))});`);\n code.push(`const ${extraAlias} = Object.keys(${valueAlias}).filter(${kAlias} => !${keysAlias}.has(${kAlias}));`);\n code.push(`if (${extraAlias}.length !== 0) { throw new TypeError(\\`Extra properties: \\${${extraAlias}}, are not allowed for path \"${path}\"\\`); }`);\n }\n code.push(...Object.entries(schema).map(([key, s]) => codeGen(s, context, `${valueAlias}['${key}']`, `${path}.${key}`)));\n return `${code.join('\\n')}`;\n }\n } else if (typeof schema === 'symbol') {\n const index = context.register(schema);\n const valueAlias = context.unique('v');\n const registryAlias = context.unique('r');\n\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${registryAlias} = ctx.registry[${index}];\nif (typeof ${valueAlias} !== 'symbol') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected symbol\\`); }\nif (${valueAlias} !== ${registryAlias}) { throw new TypeError(\\`Invalid value \\${${valueAlias}.toString()} for path \"${path}\", expected ${schema.toString()}\\`); }\n `;\n } else if (schema === null || schema === undefined) {\n const valueAlias = context.unique('v');\n return `\nconst ${valueAlias} = ${valuePath};\nif (${valueAlias} !== null && ${valueAlias} !== undefined ) { throw new TypeError(\\`Invalid value \\${JSON.stringify(${valueAlias})} for path \"${path}\", expected nullable\\`); }\n `;\n } else {\n const valueAlias = context.unique('v');\n const value = context.unique('val');\n return `\nconst ${valueAlias} = ${valuePath};\nconst ${value} = ${JSON.stringify(schema)};\n${codeGenExpectNonError(valueAlias, path)}\nif (typeof ${valueAlias} !== '${typeof schema}') { throw new TypeError(\\`Invalid type \\${typeof ${valueAlias}} for path \"${path}\", expected ${typeof schema}\\`); }\nif (${valueAlias} !== ${value}) { throw new TypeError(\\`Invalid value \\${JSON.stringify(${valueAlias})} for path \"${path}\", expected ${JSON.stringify(schema)}\\`); }\n`;\n }\n};\n\n/**\n * Compiles a schema into a validation function.\n *\n * This function takes a schema definition and generates a JavaScript function\n * that can be used to validate data against the schema.\n *\n * @template T - The type of data the schema validates.\n * @param schema - The schema to compile.\n * @param rootName - A name for the root of the data structure (used in error messages).\n * @returns A validation function that takes data as input and throws a TypeError if the data does not conform to the schema.\n *\n * @example\n * ```typescript\n * import { compile, optional, and, or } from 'ascertain';\n *\n * const userSchema = {\n * name: String,\n * age: Number,\n * email: optional(String),\n * role: or('admin', 'user', 'guest')\n * };\n *\n * const validateUser = compile(userSchema, 'User');\n *\n * // Valid data - no error thrown\n * validateUser({\n * name: 'John Doe',\n * age: 30,\n * email: 'john@example.com',\n * role: 'user'\n * });\n *\n * // Invalid data - throws TypeError\n * try {\n * validateUser({\n * name: 123, // Invalid: should be string\n * age: 'thirty' // Invalid: should be number\n * });\n * } catch (error) {\n * console.error(error.message); // Detailed validation errors\n * }\n * ```\n */\nexport const compile = <T>(schema: Schema<T>, rootName: string) => {\n const context = new Context();\n const code = codeGen(schema, context, 'data', rootName);\n const validator = new Function('ctx', 'data', code);\n return (data: T) => validator(context, data);\n};\n\n/**\n * Asserts that data conforms to a given schema.\n *\n * This function is a convenient wrapper around `compile`. It compiles the schema\n * and immediately validates the provided data against it.\n *\n * @template T - The type of data the schema validates.\n * @param schema - The schema to validate against.\n * @param data - The data to validate.\n * @param rootName - A name for the root of the data structure (used in error messages, defaults to '[root]').\n * @throws `{TypeError}` If the data does not conform to the schema.\n *\n * @example\n * ```typescript\n * import { ascertain, optional, and, or } from 'ascertain';\n *\n * const userSchema = {\n * name: String,\n * age: Number,\n * email: optional(String),\n * active: Boolean\n * };\n *\n * const userData = {\n * name: 'Alice',\n * age: 25,\n * email: 'alice@example.com',\n * active: true\n * };\n *\n * // Validate data - throws if invalid, otherwise continues silently\n * ascertain(userSchema, userData, 'UserData');\n * console.log('User data is valid!');\n *\n * // Example with invalid data\n * try {\n * ascertain(userSchema, {\n * name: 'Bob',\n * age: 'twenty-five', // Invalid: should be number\n * active: true\n * }, 'UserData');\n * } catch (error) {\n * console.error('Validation failed:', error.message);\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Array validation\n * const numbersSchema = [Number];\n * const numbers = [1, 2, 3, 4, 5];\n *\n * ascertain(numbersSchema, numbers, 'Numbers');\n *\n * // Tuple validation\n * const coordinateSchema = tuple(Number, Number);\n * const point = [10, 20];\n *\n * ascertain(coordinateSchema, point, 'Point');\n * ```\n */\nexport const ascertain = <T>(schema: Schema<T>, data: T, rootName = '[root]') => {\n compile(schema, rootName)(data);\n};\n"],"names":["Operator","schemas","length","TypeError","name","$keys","Symbol","for","$values","$strict","Or","or","And","and","Optional","schema","optional","Tuple","tuple","fromBase64","Buffer","value","atob","from","toString","MULTIPLIERS","ms","s","m","h","d","w","asError","message","as","string","number","result","parseFloat","Number","isNaN","date","Date","parse","valueOf","time","conversionFactor","matches","match","amount","unit","parseInt","boolean","test","array","delimiter","split","json","JSON","base64","Context","registry","varIndex","register","includes","push","indexOf","unique","prefix","codeGenCollectErrors","errorsAlias","code","extra","codeGenExpectNoErrors","codeGenExpectNonError","valueAlias","path","codeGenExpectNonNullable","codeGenExpectObject","instanceOf","codeGenExpectArray","codeGen","context","valuePath","map","join","reduceRight","idx","index","registryAlias","Error","prototype","Array","isArray","key","RegExp","keysAlias","kAlias","vAlias","entriesAlias","extraAlias","stringify","Object","keys","entries","undefined","compile","rootName","validator","Function","data","ascertain"],"mappings":"AASA,MAAeA;;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AMW,OAAOU,QAAQlE,QAAQmE,SAAS,QAAQyB;IAC9C,MAAMC,YAAY,IAAIC,SAAS,OAAO,QAAQtC;IAC9C,OAAO,CAACuC,OAAYF,UAAU1B,SAAS4B;AACzC,EAAE;AA+DF,OAAO,MAAMC,YAAY,CAAIhG,QAAmB+F,MAASH,WAAW,QAAQ;IAC1ED,QAAQ3F,QAAQ4F,UAAUG;AAC5B,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ascertain",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.1",
|
|
4
4
|
"description": "0-Deps, simple, fast, for browser and node js object schema validator",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -14,13 +14,6 @@
|
|
|
14
14
|
"build",
|
|
15
15
|
"src/index.js"
|
|
16
16
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "rm -rf build && NODE_ENV=production inop src/ build -i __tests__ && tsc --declaration --emitDeclarationOnly",
|
|
19
|
-
"lint": "eslint src",
|
|
20
|
-
"test": "NODE_ENV=test jest --bail",
|
|
21
|
-
"test:cov": "CI=1 NODE_ENV=test jest",
|
|
22
|
-
"prepare": "husky"
|
|
23
|
-
},
|
|
24
17
|
"repository": {
|
|
25
18
|
"type": "git",
|
|
26
19
|
"url": "git+https://github.com/3axap4eHko/ascertain.git"
|
|
@@ -45,25 +38,39 @@
|
|
|
45
38
|
},
|
|
46
39
|
"homepage": "https://github.com/3axap4eHko/ascertain#readme",
|
|
47
40
|
"devDependencies": {
|
|
48
|
-
"@eslint/eslintrc": "^3.3.1",
|
|
49
41
|
"@eslint/js": "^9.31.0",
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@typescript-eslint/
|
|
54
|
-
"@
|
|
42
|
+
"@types/node": "^24.0.13",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
44
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
45
|
+
"@typescript-eslint/typescript-estree": "^8.36.0",
|
|
46
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
47
|
+
"@vuepress/bundler-vite": "2.0.0-rc.24",
|
|
48
|
+
"@vuepress/theme-default": "2.0.0-rc.112",
|
|
55
49
|
"eslint": "^9.31.0",
|
|
56
|
-
"eslint-config-
|
|
57
|
-
"eslint-config-prettier": "^9.1.0",
|
|
58
|
-
"eslint-plugin-import": "^2.32.0",
|
|
50
|
+
"eslint-config-prettier": "^10.1.5",
|
|
59
51
|
"eslint-plugin-prettier": "^5.5.1",
|
|
52
|
+
"handlebars": "^4.7.8",
|
|
60
53
|
"husky": "^9.1.7",
|
|
61
54
|
"inop": "^0.7.8",
|
|
62
|
-
"jest": "^29.7.0",
|
|
63
55
|
"overtake": "^0.1.2",
|
|
64
56
|
"prettier": "^3.6.2",
|
|
57
|
+
"recast": "^0.23.11",
|
|
58
|
+
"sass-embedded": "^1.89.2",
|
|
65
59
|
"ts-node": "^10.9.2",
|
|
66
|
-
"typescript": "^5.8.3"
|
|
60
|
+
"typescript": "^5.8.3",
|
|
61
|
+
"typescript-eslint": "^8.36.0",
|
|
62
|
+
"vitest": "^3.2.4",
|
|
63
|
+
"vue": "^3.5.17",
|
|
64
|
+
"vuepress": "2.0.0-rc.24"
|
|
67
65
|
},
|
|
68
|
-
"
|
|
69
|
-
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "rm -rf build && NODE_ENV=production inop src/ build -i __tests__ && tsc --declaration --emitDeclarationOnly",
|
|
68
|
+
"lint": "eslint src",
|
|
69
|
+
"test": "NODE_ENV=test vitest run",
|
|
70
|
+
"docs:build": "vuepress build docs",
|
|
71
|
+
"docs:clean-dev": "vuepress dev docs --clean-cache",
|
|
72
|
+
"docs:dev": "vuepress dev docs",
|
|
73
|
+
"docs:gen": "node --loader ts-node/esm ./scripts/docgen.ts src/index.ts",
|
|
74
|
+
"docs:update-package": "pnpm dlx vp-update"
|
|
75
|
+
}
|
|
76
|
+
}
|