bguard 0.0.4 → 0.0.5
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/lib/{CommonSchema-DeTBsQhn.d.mts → CommonSchema-BIe85W_A.d.mts} +3 -1
- package/lib/{CommonSchema-DeTBsQhn.d.ts → CommonSchema-BIe85W_A.d.ts} +3 -1
- package/lib/InferType.d.mts +18 -0
- package/lib/InferType.d.ts +18 -0
- package/lib/InferType.js +19 -0
- package/lib/InferType.js.map +1 -0
- package/lib/InferType.mjs +1 -0
- package/lib/InferType.mjs.map +1 -0
- package/lib/__tests__/ArraySchema.test.d.mts +2 -0
- package/lib/__tests__/ArraySchema.test.d.ts +2 -0
- package/lib/__tests__/ArraySchema.test.js +201 -0
- package/lib/__tests__/ArraySchema.test.js.map +1 -0
- package/lib/__tests__/ArraySchema.test.mjs +199 -0
- package/lib/__tests__/ArraySchema.test.mjs.map +1 -0
- package/lib/__tests__/BooleanSchema.test.d.mts +2 -0
- package/lib/__tests__/BooleanSchema.test.d.ts +2 -0
- package/lib/__tests__/BooleanSchema.test.js +219 -0
- package/lib/__tests__/BooleanSchema.test.js.map +1 -0
- package/lib/__tests__/BooleanSchema.test.mjs +217 -0
- package/lib/__tests__/BooleanSchema.test.mjs.map +1 -0
- package/lib/__tests__/CommonSchema.test.d.mts +2 -0
- package/lib/__tests__/CommonSchema.test.d.ts +2 -0
- package/lib/__tests__/CommonSchema.test.js +253 -0
- package/lib/__tests__/CommonSchema.test.js.map +1 -0
- package/lib/__tests__/CommonSchema.test.mjs +251 -0
- package/lib/__tests__/CommonSchema.test.mjs.map +1 -0
- package/lib/__tests__/MixTypes.test.d.mts +2 -0
- package/lib/__tests__/MixTypes.test.d.ts +2 -0
- package/lib/__tests__/MixTypes.test.js +165 -0
- package/lib/__tests__/MixTypes.test.js.map +1 -0
- package/lib/__tests__/MixTypes.test.mjs +163 -0
- package/lib/__tests__/MixTypes.test.mjs.map +1 -0
- package/lib/__tests__/NumberSchema.test.d.mts +2 -0
- package/lib/__tests__/NumberSchema.test.d.ts +2 -0
- package/lib/__tests__/NumberSchema.test.js +253 -0
- package/lib/__tests__/NumberSchema.test.js.map +1 -0
- package/lib/__tests__/NumberSchema.test.mjs +251 -0
- package/lib/__tests__/NumberSchema.test.mjs.map +1 -0
- package/lib/__tests__/ObjectSchema.test.d.mts +2 -0
- package/lib/__tests__/ObjectSchema.test.d.ts +2 -0
- package/lib/__tests__/ObjectSchema.test.js +356 -0
- package/lib/__tests__/ObjectSchema.test.js.map +1 -0
- package/lib/__tests__/ObjectSchema.test.mjs +354 -0
- package/lib/__tests__/ObjectSchema.test.mjs.map +1 -0
- package/lib/__tests__/StringSchema.test.d.mts +2 -0
- package/lib/__tests__/StringSchema.test.d.ts +2 -0
- package/lib/__tests__/StringSchema.test.js +228 -0
- package/lib/__tests__/StringSchema.test.js.map +1 -0
- package/lib/__tests__/StringSchema.test.mjs +226 -0
- package/lib/__tests__/StringSchema.test.mjs.map +1 -0
- package/lib/asserts/array/index.d.mts +18 -2
- package/lib/asserts/array/index.d.ts +18 -2
- package/lib/asserts/boolean/index.d.mts +16 -2
- package/lib/asserts/boolean/index.d.ts +16 -2
- package/lib/asserts/common/equalTo.d.mts +1 -1
- package/lib/asserts/common/equalTo.d.ts +1 -1
- package/lib/asserts/common/index.d.mts +1 -1
- package/lib/asserts/common/index.d.ts +1 -1
- package/lib/asserts/number/index.d.mts +16 -2
- package/lib/asserts/number/index.d.ts +16 -2
- package/lib/asserts/number/max.d.mts +1 -1
- package/lib/asserts/number/max.d.ts +1 -1
- package/lib/asserts/number/maxExcluded.d.mts +1 -1
- package/lib/asserts/number/maxExcluded.d.ts +1 -1
- package/lib/asserts/number/min.d.mts +1 -1
- package/lib/asserts/number/min.d.ts +1 -1
- package/lib/asserts/number/minExcluded.d.mts +1 -1
- package/lib/asserts/number/minExcluded.d.ts +1 -1
- package/lib/asserts/number/negative.d.mts +1 -1
- package/lib/asserts/number/negative.d.ts +1 -1
- package/lib/asserts/number/positive.d.mts +1 -1
- package/lib/asserts/number/positive.d.ts +1 -1
- package/lib/asserts/object/index.d.mts +21 -2
- package/lib/asserts/object/index.d.ts +21 -2
- package/lib/asserts/string/email.d.mts +1 -1
- package/lib/asserts/string/email.d.ts +1 -1
- package/lib/asserts/string/index.d.mts +16 -2
- package/lib/asserts/string/index.d.ts +16 -2
- package/lib/asserts/string/maxLength.d.mts +1 -1
- package/lib/asserts/string/maxLength.d.ts +1 -1
- package/lib/asserts/string/minLength.d.mts +1 -1
- package/lib/asserts/string/minLength.d.ts +1 -1
- package/lib/asserts/string/regExp.d.mts +1 -1
- package/lib/asserts/string/regExp.d.ts +1 -1
- package/lib/core.d.mts +1 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.js +111 -0
- package/lib/core.js.map +1 -0
- package/lib/core.mjs +83 -0
- package/lib/core.mjs.map +1 -0
- package/lib/exceptions.d.mts +12 -0
- package/lib/exceptions.d.ts +12 -0
- package/lib/exceptions.js +52 -0
- package/lib/exceptions.js.map +1 -0
- package/lib/exceptions.mjs +25 -0
- package/lib/exceptions.mjs.map +1 -0
- package/lib/index.d.mts +14 -51
- package/lib/index.d.ts +14 -51
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +4 -1
- package/lib/parseSchema.d.mts +37 -0
- package/lib/parseSchema.d.ts +37 -0
- package/lib/parseSchema.js +119 -0
- package/lib/parseSchema.js.map +1 -0
- package/lib/parseSchema.mjs +92 -0
- package/lib/parseSchema.mjs.map +1 -0
- package/lib/schemas/ArraySchema.d.mts +13 -0
- package/lib/schemas/ArraySchema.d.ts +13 -0
- package/lib/schemas/ArraySchema.js +85 -0
- package/lib/schemas/ArraySchema.js.map +1 -0
- package/lib/schemas/ArraySchema.mjs +58 -0
- package/lib/schemas/ArraySchema.mjs.map +1 -0
- package/lib/{index-nzqBrOHf.d.mts → schemas/BooleanSchema.d.mts} +2 -14
- package/lib/{index-B1yBez0g.d.ts → schemas/BooleanSchema.d.ts} +2 -14
- package/lib/schemas/BooleanSchema.js +113 -0
- package/lib/schemas/BooleanSchema.js.map +1 -0
- package/lib/schemas/BooleanSchema.mjs +86 -0
- package/lib/schemas/BooleanSchema.mjs.map +1 -0
- package/lib/schemas/CommonSchema.d.mts +1 -0
- package/lib/schemas/CommonSchema.d.ts +1 -0
- package/lib/schemas/CommonSchema.js +67 -0
- package/lib/schemas/CommonSchema.js.map +1 -0
- package/lib/schemas/CommonSchema.mjs +40 -0
- package/lib/schemas/CommonSchema.mjs.map +1 -0
- package/lib/{index-B63cXDOm.d.mts → schemas/NumberSchema.d.mts} +2 -14
- package/lib/{index-CK_g_aEC.d.ts → schemas/NumberSchema.d.ts} +2 -14
- package/lib/schemas/NumberSchema.js +107 -0
- package/lib/schemas/NumberSchema.js.map +1 -0
- package/lib/schemas/NumberSchema.mjs +80 -0
- package/lib/schemas/NumberSchema.mjs.map +1 -0
- package/lib/schemas/ObjectSchema.d.mts +12 -0
- package/lib/schemas/ObjectSchema.d.ts +12 -0
- package/lib/schemas/ObjectSchema.js +89 -0
- package/lib/schemas/ObjectSchema.js.map +1 -0
- package/lib/schemas/ObjectSchema.mjs +62 -0
- package/lib/schemas/ObjectSchema.mjs.map +1 -0
- package/lib/{index-aBEYpJdZ.d.mts → schemas/StringSchema.d.mts} +2 -14
- package/lib/{index-BEyBEBSm.d.ts → schemas/StringSchema.d.ts} +2 -14
- package/lib/schemas/StringSchema.js +107 -0
- package/lib/schemas/StringSchema.js.map +1 -0
- package/lib/schemas/StringSchema.mjs +80 -0
- package/lib/schemas/StringSchema.mjs.map +1 -0
- package/package.json +28 -27
- package/lib/index-D3R2euaT.d.mts +0 -29
- package/lib/index-DPkImfCy.d.ts +0 -29
- package/lib/index-DitgsWDO.d.ts +0 -27
- package/lib/index-T3KBmyyn.d.mts +0 -27
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/exceptions.ts
|
|
2
|
+
var ValidationError = class extends Error {
|
|
3
|
+
expected;
|
|
4
|
+
received;
|
|
5
|
+
pathToError;
|
|
6
|
+
message;
|
|
7
|
+
constructor(expected, received, pathToError, message) {
|
|
8
|
+
super();
|
|
9
|
+
this.expected = expected;
|
|
10
|
+
this.received = received;
|
|
11
|
+
this.pathToError = pathToError;
|
|
12
|
+
this.message = message;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function throwException(expected, received, pathToError, message) {
|
|
16
|
+
throw new ValidationError(expected, received, pathToError, message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/asserts/common/equalTo.ts
|
|
20
|
+
var equalTo = (expected) => (received, pathToError) => {
|
|
21
|
+
if (expected !== received)
|
|
22
|
+
throwException(expected, received, pathToError, "The received value is not equal to expected");
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/core.ts
|
|
26
|
+
var ctxSymbol = Symbol("contextSymbol");
|
|
27
|
+
|
|
28
|
+
// src/schemas/CommonSchema.ts
|
|
29
|
+
var CommonSchema = class {
|
|
30
|
+
[ctxSymbol];
|
|
31
|
+
constructor(ctx) {
|
|
32
|
+
this[ctxSymbol] = ctx;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @param validators - One or more custom validation functions.
|
|
36
|
+
* @returns {this} The schema instance with the added custom validation.
|
|
37
|
+
*/
|
|
38
|
+
custom(...validators) {
|
|
39
|
+
this[ctxSymbol].requiredValidations.push(...validators);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Marks the schema as nullable, allowing the value to be `null`.
|
|
44
|
+
*
|
|
45
|
+
* @returns {WithNull<this>} The schema instance marked as nullable.
|
|
46
|
+
*/
|
|
47
|
+
nullable() {
|
|
48
|
+
this[ctxSymbol].isNullable = true;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Marks the schema as optional, allowing the value to be `undefined`.
|
|
53
|
+
*
|
|
54
|
+
* @returns {WithUndefined<this>}} The schema instance marked as optional.
|
|
55
|
+
*/
|
|
56
|
+
optional() {
|
|
57
|
+
this[ctxSymbol].isOptional = true;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/schemas/StringSchema.ts
|
|
63
|
+
var StringSchema = class extends CommonSchema {
|
|
64
|
+
_string = 1;
|
|
65
|
+
/**
|
|
66
|
+
* Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
|
|
67
|
+
*
|
|
68
|
+
* @param expectedValue - The value that the schema must exactly match.
|
|
69
|
+
* @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
|
|
70
|
+
*
|
|
71
|
+
* @example - string().equalTo('hello'); // Infers the type 'hello'
|
|
72
|
+
*/
|
|
73
|
+
equalTo(expectedValue) {
|
|
74
|
+
return this.custom(equalTo(expectedValue));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
StringSchema
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=StringSchema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exceptions.ts","../../src/asserts/common/equalTo.ts","../../src/core.ts","../../src/schemas/CommonSchema.ts","../../src/schemas/StringSchema.ts"],"sourcesContent":["export class ValidationError extends Error {\n expected: unknown;\n received: unknown;\n pathToError: string;\n message: string;\n constructor(expected: unknown, received: unknown, pathToError: string, message: string) {\n super();\n this.expected = expected;\n this.received = received;\n this.pathToError = pathToError;\n this.message = message;\n }\n}\n\nexport class BuildSchemaError extends Error {}\n\nexport function throwException(expected: unknown, received: unknown, pathToError: string, message: string): never {\n throw new ValidationError(expected, received, pathToError, message);\n}\n","import { throwException } from '../../exceptions';\nimport { RequiredValidation } from '../../schemas/CommonSchema';\n\n/**\n * Creates a custom assertion that checks if a value is equal to the expected value.\n *\n * This assertion can be used within a `.custom` method to enforce that a value strictly matches the expected value.\n * It will throw a `ValidationError` if the values are not equal.\n *\n * @param {unknown} expected - The value that the received value is expected to match.\n * @returns {RequiredValidation} A function that takes the received value and the path to the error,\n * and throws a `ValidationError` if the received value does not equal the expected value.\n *\n * @throws {ValidationError} If the received value does not match the expected value.\n *\n * @example\n * import { number, equalTo } from 'bguard';\n *\n * // Define a schema with a custom assertion\n * const schema = number().custom(equalTo(5));\n *\n * // This will pass\n * parseSchema(schema, 5);\n *\n * // This will throw a ValidationError\n * parseSchema(schema, 3);\n */\nexport const equalTo =\n (expected: unknown): RequiredValidation =>\n (received: number, pathToError: string) => {\n if (expected !== received)\n throwException(expected, received, pathToError, 'The received value is not equal to expected');\n };\n","export const ctxSymbol = Symbol('contextSymbol');\n\nimport { throwException } from './exceptions';\nimport type { CommonSchema } from './schemas/CommonSchema';\n\nexport function innerCheck(schema: CommonSchema, receivedValue: unknown, pathToError: string) {\n const ctx = schema[ctxSymbol];\n if (receivedValue === undefined) {\n if (!ctx.isOptional) throwException('Required', receivedValue, pathToError, 'The required value is missing');\n return receivedValue;\n }\n\n if (receivedValue === null) {\n if (!ctx.isNullable) throwException('Not null', receivedValue, pathToError, 'Value should not be null');\n return receivedValue;\n }\n\n if (ctx.array) {\n if (!Array.isArray(receivedValue))\n throwException('Array', receivedValue, pathToError, 'Expected an array but received a different type');\n const schema = ctx.array;\n\n receivedValue.forEach((elem, i) => {\n innerCheck(schema, elem, `${pathToError}[${i}]`);\n });\n\n return receivedValue;\n }\n\n const typeOfVal = typeof receivedValue;\n\n if (ctx.object) {\n if (typeOfVal !== 'object')\n throwException('Object', receivedValue, pathToError, 'Expected an object but received a different type');\n if (Array.isArray(receivedValue))\n throwException(\n 'Object',\n receivedValue,\n pathToError,\n 'Expected an object but received an array. Invalid type of data',\n );\n const shapeSchema = ctx.object;\n for (const keyPerReceivedValue of Object.keys(receivedValue)) {\n if (shapeSchema[keyPerReceivedValue] === undefined)\n throwException('Not allowed', keyPerReceivedValue, pathToError, 'This key is not allowed in the object');\n }\n\n for (const [keyOfSchema, valueOfSchema] of Object.entries(shapeSchema)) {\n const receivedObjectValuePropery = (receivedValue as Record<string, unknown>)[keyOfSchema];\n if (receivedObjectValuePropery === undefined) {\n if (!valueOfSchema[ctxSymbol].isOptional)\n throwException(\n 'Required',\n receivedObjectValuePropery,\n pathToError,\n 'Missing required property in the object',\n );\n }\n innerCheck(valueOfSchema, receivedObjectValuePropery, `${pathToError}.${keyOfSchema}`);\n }\n\n return receivedValue;\n }\n\n if (ctx.type.length) {\n if (!ctx.type.includes(typeOfVal)) throwException(ctx.type, typeOfVal, pathToError, 'Invalid type of data');\n }\n\n ctx.requiredValidations.forEach((requiredValidation) => {\n requiredValidation(receivedValue, pathToError);\n });\n\n return receivedValue;\n}\n","import { ctxSymbol } from '../core';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type RequiredValidation = (received: any, pathToError: string) => void;\nexport type ObjectShapeSchemaType = Record<string, CommonSchema>;\n\nexport type PrimitiveType = 'number' | 'string' | 'boolean' | 'undefined' | 'object' | 'function' | 'symbol' | 'bigint';\nexport interface ValidatorContext {\n type: PrimitiveType[];\n isNullable?: boolean;\n isOptional?: boolean;\n requiredValidations: RequiredValidation[];\n array?: CommonSchema;\n object?: ObjectShapeSchemaType;\n}\n\nexport class CommonSchema {\n [ctxSymbol]: ValidatorContext;\n constructor(ctx: ValidatorContext) {\n this[ctxSymbol] = ctx;\n }\n\n /**\n * @param validators - One or more custom validation functions.\n * @returns {this} The schema instance with the added custom validation.\n */\n custom(...validators: RequiredValidation[]): this {\n this[ctxSymbol].requiredValidations.push(...validators);\n return this;\n }\n\n /**\n * Marks the schema as nullable, allowing the value to be `null`.\n *\n * @returns {WithNull<this>} The schema instance marked as nullable.\n */\n nullable(): WithNull<this> {\n this[ctxSymbol].isNullable = true;\n return this as WithNull<this>;\n }\n\n /**\n * Marks the schema as optional, allowing the value to be `undefined`.\n *\n * @returns {WithUndefined<this>}} The schema instance marked as optional.\n */\n optional(): WithUndefined<this> {\n this[ctxSymbol].isOptional = true;\n return this as WithUndefined<this>;\n }\n}\n\nexport type WithNull<T extends CommonSchema> = T & { validation_null: true };\nexport type WithUndefined<T extends CommonSchema> = T & { validation_undefined: true };\n\ntype TypeMapping = {\n number: number;\n string: string;\n boolean: boolean;\n undefined: undefined;\n object: object;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n function: Function;\n symbol: symbol;\n bigint: bigint;\n};\n\nexport type WithMix<Y = unknown> = CommonSchema & { validation_mix: Y };\nexport type ExtractFromMix<T> = T extends WithMix<infer X> ? X : never;\n\nexport type MapMixTypes<T extends PrimitiveType[]> = T extends (infer U)[]\n ? U extends keyof TypeMapping\n ? TypeMapping[U]\n : never\n : never;\n","import { equalTo } from '../asserts/common/equalTo';\nimport { CommonSchema } from './CommonSchema';\n\nexport class StringSchema extends CommonSchema {\n _string = 1;\n\n /**\n * Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.\n *\n * @param expectedValue - The value that the schema must exactly match.\n * @returns - The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type\n *\n * @example - string().equalTo('hello'); // Infers the type 'hello'\n */\n equalTo<Y extends string>(expectedValue: Y): WithString<this, Y> {\n return this.custom(equalTo(expectedValue)) as WithString<this, Y>;\n }\n}\n\nexport type WithString<T extends StringSchema, Y = string> = T & { validation_string: Y };\nexport type ExtractFromString<T> = T extends WithString<StringSchema, infer Y> ? Y : never;\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY,UAAmB,UAAmB,aAAqB,SAAiB;AACtF,UAAM;AACN,SAAK,WAAW;AAChB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,UAAU;AAAA,EACjB;AACF;AAIO,SAAS,eAAe,UAAmB,UAAmB,aAAqB,SAAwB;AAChH,QAAM,IAAI,gBAAgB,UAAU,UAAU,aAAa,OAAO;AACpE;;;ACSO,IAAM,UACX,CAAC,aACD,CAAC,UAAkB,gBAAwB;AACzC,MAAI,aAAa;AACf,mBAAe,UAAU,UAAU,aAAa,6CAA6C;AACjG;;;AChCK,IAAM,YAAY,OAAO,eAAe;;;ACgBxC,IAAM,eAAN,MAAmB;AAAA,EACxB,CAAC,SAAS;AAAA,EACV,YAAY,KAAuB;AACjC,SAAK,SAAS,IAAI;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,YAAwC;AAChD,SAAK,SAAS,EAAE,oBAAoB,KAAK,GAAG,UAAU;AACtD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAA2B;AACzB,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAgC;AAC9B,SAAK,SAAS,EAAE,aAAa;AAC7B,WAAO;AAAA,EACT;AACF;;;AC/CO,IAAM,eAAN,cAA2B,aAAa;AAAA,EAC7C,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUV,QAA0B,eAAuC;AAC/D,WAAO,KAAK,OAAO,QAAQ,aAAa,CAAC;AAAA,EAC3C;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "bguard",
|
|
3
3
|
"private": false,
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.5",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.mjs",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
@@ -78,13 +78,7 @@
|
|
|
78
78
|
},
|
|
79
79
|
"tsup": {
|
|
80
80
|
"entry": [
|
|
81
|
-
"src
|
|
82
|
-
"src/asserts/common/*",
|
|
83
|
-
"src/asserts/array/*",
|
|
84
|
-
"src/asserts/object/*",
|
|
85
|
-
"src/asserts/boolean/*",
|
|
86
|
-
"src/asserts/string/*",
|
|
87
|
-
"src/asserts/number/*"
|
|
81
|
+
"src/**"
|
|
88
82
|
],
|
|
89
83
|
"splitting": false,
|
|
90
84
|
"sourcemap": true,
|
|
@@ -99,31 +93,38 @@
|
|
|
99
93
|
"exports": {
|
|
100
94
|
".": {
|
|
101
95
|
"import": "./lib/index.mjs",
|
|
102
|
-
"require": "./lib/index.js"
|
|
96
|
+
"require": "./lib/index.js",
|
|
97
|
+
"types": "./lib/index.d.ts"
|
|
103
98
|
},
|
|
104
|
-
"./
|
|
105
|
-
"import": "./lib/asserts/string
|
|
106
|
-
"require": "./lib/asserts/string
|
|
99
|
+
"./string/*": {
|
|
100
|
+
"import": "./lib/asserts/string/*.js",
|
|
101
|
+
"require": "./lib/asserts/string/*.js",
|
|
102
|
+
"types": "./lib/asserts/common/*.d.ts"
|
|
107
103
|
},
|
|
108
|
-
"./
|
|
109
|
-
"import": "./lib/asserts/boolean
|
|
110
|
-
"require": "./lib/asserts/boolean
|
|
104
|
+
"./boolean/*": {
|
|
105
|
+
"import": "./lib/asserts/boolean/*.js",
|
|
106
|
+
"require": "./lib/asserts/boolean/*.js",
|
|
107
|
+
"types": "./lib/index.d.ts"
|
|
111
108
|
},
|
|
112
|
-
"./
|
|
113
|
-
"import": "./lib/asserts/number
|
|
114
|
-
"require": "./lib/asserts/number
|
|
109
|
+
"./number/*": {
|
|
110
|
+
"import": "./lib/asserts/number/*.js",
|
|
111
|
+
"require": "./lib/asserts/number/*.js",
|
|
112
|
+
"types": "./lib/asserts/common/*.d.ts"
|
|
115
113
|
},
|
|
116
|
-
"./
|
|
117
|
-
"import": "./lib/asserts/array
|
|
118
|
-
"require": "./lib/asserts/array
|
|
114
|
+
"./array/*": {
|
|
115
|
+
"import": "./lib/asserts/array/*.js",
|
|
116
|
+
"require": "./lib/asserts/array/*.js",
|
|
117
|
+
"types": "./lib/asserts/common/*.d.ts"
|
|
119
118
|
},
|
|
120
|
-
"./
|
|
121
|
-
"import": "./lib/asserts/object
|
|
122
|
-
"require": "./lib/asserts/object
|
|
119
|
+
"./object/*": {
|
|
120
|
+
"import": "./lib/asserts/object/*.js",
|
|
121
|
+
"require": "./lib/asserts/object/*.js",
|
|
122
|
+
"types": "./lib/asserts/common/*.d.ts"
|
|
123
123
|
},
|
|
124
|
-
"./
|
|
125
|
-
"import": "./lib/asserts/common
|
|
126
|
-
"require": "./lib/asserts/common
|
|
124
|
+
"./common/*": {
|
|
125
|
+
"import": "./lib/asserts/common/*.js",
|
|
126
|
+
"require": "./lib/asserts/common/*.js",
|
|
127
|
+
"types": "./lib/asserts/common/*.d.ts"
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
}
|
package/lib/index-D3R2euaT.d.mts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from './CommonSchema-DeTBsQhn.mjs';
|
|
2
|
-
|
|
3
|
-
declare class ObjectSchema extends CommonSchema {
|
|
4
|
-
_object: number;
|
|
5
|
-
constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
|
|
6
|
-
private validateObjectEntry;
|
|
7
|
-
}
|
|
8
|
-
type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
|
|
9
|
-
validation_object: Y;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new schema for validating objects where each property must match the specified schema.
|
|
14
|
-
*
|
|
15
|
-
* @template T
|
|
16
|
-
* @param {T} shapeSchema - The schema that each property of the object must match.
|
|
17
|
-
* @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const schema = object({
|
|
21
|
-
* name: string(),
|
|
22
|
-
* age: number()
|
|
23
|
-
* });
|
|
24
|
-
* parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
|
|
25
|
-
* parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
|
|
26
|
-
*/
|
|
27
|
-
declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
|
|
28
|
-
|
|
29
|
-
export { ObjectSchema as O, type WithObject as W, object as o };
|
package/lib/index-DPkImfCy.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext, O as ObjectShapeSchemaType } from './CommonSchema-DeTBsQhn.js';
|
|
2
|
-
|
|
3
|
-
declare class ObjectSchema extends CommonSchema {
|
|
4
|
-
_object: number;
|
|
5
|
-
constructor(ctx: ValidatorContext, shapeSchema: ObjectShapeSchemaType);
|
|
6
|
-
private validateObjectEntry;
|
|
7
|
-
}
|
|
8
|
-
type WithObject<Y extends ObjectShapeSchemaType> = ObjectSchema & {
|
|
9
|
-
validation_object: Y;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new schema for validating objects where each property must match the specified schema.
|
|
14
|
-
*
|
|
15
|
-
* @template T
|
|
16
|
-
* @param {T} shapeSchema - The schema that each property of the object must match.
|
|
17
|
-
* @returns {WithObject<T>} A new instance of `ObjectSchema` for validating objects with properties matching the specified schema.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* const schema = object({
|
|
21
|
-
* name: string(),
|
|
22
|
-
* age: number()
|
|
23
|
-
* });
|
|
24
|
-
* parseSchema(schema, { name: 'John', age: 30 }); // Validates successfully
|
|
25
|
-
* parseSchema(schema, { name: 'John', age: '30' }); // Throws a validation error
|
|
26
|
-
*/
|
|
27
|
-
declare function object<T extends ObjectShapeSchemaType>(shapeSchema: T): WithObject<T>;
|
|
28
|
-
|
|
29
|
-
export { ObjectSchema as O, type WithObject as W, object as o };
|
package/lib/index-DitgsWDO.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext } from './CommonSchema-DeTBsQhn.js';
|
|
2
|
-
|
|
3
|
-
declare class ArraySchema extends CommonSchema {
|
|
4
|
-
_array: number;
|
|
5
|
-
constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
|
|
6
|
-
private validateArrayEntry;
|
|
7
|
-
}
|
|
8
|
-
type WithArray<Y extends CommonSchema> = ArraySchema & {
|
|
9
|
-
validation_array: Y;
|
|
10
|
-
};
|
|
11
|
-
type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
15
|
-
*
|
|
16
|
-
* @template T
|
|
17
|
-
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
18
|
-
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const schema = array(string());
|
|
22
|
-
* parseSchema(schema, ['hello', 'world']); // Validates successfully
|
|
23
|
-
* parseSchema(schema, ['hello', 123]); // Throws a validation error
|
|
24
|
-
*/
|
|
25
|
-
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
26
|
-
|
|
27
|
-
export { ArraySchema as A, type ExtractFromArray as E, array as a };
|
package/lib/index-T3KBmyyn.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { C as CommonSchema, V as ValidatorContext } from './CommonSchema-DeTBsQhn.mjs';
|
|
2
|
-
|
|
3
|
-
declare class ArraySchema extends CommonSchema {
|
|
4
|
-
_array: number;
|
|
5
|
-
constructor(ctx: ValidatorContext, arraySchema: CommonSchema);
|
|
6
|
-
private validateArrayEntry;
|
|
7
|
-
}
|
|
8
|
-
type WithArray<Y extends CommonSchema> = ArraySchema & {
|
|
9
|
-
validation_array: Y;
|
|
10
|
-
};
|
|
11
|
-
type ExtractFromArray<T> = T extends WithArray<infer X> ? X : never;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new schema for validating arrays where each element must match the specified schema.
|
|
15
|
-
*
|
|
16
|
-
* @template T
|
|
17
|
-
* @param {T} arraySchema - The schema that each element of the array must match.
|
|
18
|
-
* @returns {WithArray<T>} A new instance of `ArraySchema` for validating arrays of elements that match the specified schema.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const schema = array(string());
|
|
22
|
-
* parseSchema(schema, ['hello', 'world']); // Validates successfully
|
|
23
|
-
* parseSchema(schema, ['hello', 123]); // Throws a validation error
|
|
24
|
-
*/
|
|
25
|
-
declare function array<T extends CommonSchema>(arraySchema: T): WithArray<T>;
|
|
26
|
-
|
|
27
|
-
export { ArraySchema as A, type ExtractFromArray as E, array as a };
|