@aeriajs/validation 0.0.89 → 0.0.90
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/dist/validate.d.ts +1 -1
- package/dist/validate.js +12 -5
- package/dist/validate.mjs +12 -5
- package/package.json +3 -3
package/dist/validate.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import type { JsonSchema, Property, InferSchema, Description, PropertyValidation
|
|
|
2
2
|
import { Result } from '@aeriajs/types';
|
|
3
3
|
import { ValidationErrorCode } from '@aeriajs/types';
|
|
4
4
|
export type ValidateOptions = {
|
|
5
|
-
extraneous?: string[] | boolean;
|
|
6
5
|
filterOutExtraneous?: boolean;
|
|
7
6
|
throwOnError?: boolean;
|
|
8
7
|
coerce?: boolean;
|
|
8
|
+
parentProperty?: Omit<Description, '$id'> | Property;
|
|
9
9
|
};
|
|
10
10
|
export declare const makeValidationError: <TValidationError extends ValidationError>(error: TValidationError) => TValidationError;
|
|
11
11
|
export declare const validateProperty: <TWhat>(propName: string, what: TWhat, property: Property | undefined, options?: ValidateOptions) => Result.Either<PropertyValidationError | ValidationError, unknown>;
|
package/dist/validate.js
CHANGED
|
@@ -41,14 +41,18 @@ const makeValidationError = (error) => {
|
|
|
41
41
|
};
|
|
42
42
|
exports.makeValidationError = makeValidationError;
|
|
43
43
|
const validateProperty = (propName, what, property, options = {}) => {
|
|
44
|
-
const {
|
|
44
|
+
const { filterOutExtraneous, coerce } = options;
|
|
45
45
|
if (what === undefined) {
|
|
46
46
|
return types_1.Result.result(what);
|
|
47
47
|
}
|
|
48
48
|
if (!property) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (options.parentProperty && 'additionalProperties' in options.parentProperty && options.parentProperty.additionalProperties) {
|
|
50
|
+
const extraneous = options.parentProperty.additionalProperties;
|
|
51
|
+
if (typeof extraneous === 'boolean' || Object.keys(extraneous).includes(propName)) {
|
|
52
|
+
if (filterOutExtraneous) {
|
|
53
|
+
return types_1.Result.result(undefined);
|
|
54
|
+
}
|
|
55
|
+
return types_1.Result.result(what);
|
|
52
56
|
}
|
|
53
57
|
return types_1.Result.result(what);
|
|
54
58
|
}
|
|
@@ -210,7 +214,10 @@ const validate = (what, schema, options = {}) => {
|
|
|
210
214
|
const errors = {};
|
|
211
215
|
const resultCopy = {};
|
|
212
216
|
for (const propName in what) {
|
|
213
|
-
const { error, result: parsed } = (0, exports.validateProperty)(propName, what[propName], schema.properties[propName],
|
|
217
|
+
const { error, result: parsed } = (0, exports.validateProperty)(propName, what[propName], schema.properties[propName], {
|
|
218
|
+
...options,
|
|
219
|
+
parentProperty: schema,
|
|
220
|
+
});
|
|
214
221
|
if (error) {
|
|
215
222
|
errors[propName] = error;
|
|
216
223
|
}
|
package/dist/validate.mjs
CHANGED
|
@@ -34,14 +34,18 @@ export const makeValidationError = (error) => {
|
|
|
34
34
|
return error;
|
|
35
35
|
};
|
|
36
36
|
export const validateProperty = (propName, what, property, options = {}) => {
|
|
37
|
-
const {
|
|
37
|
+
const { filterOutExtraneous, coerce } = options;
|
|
38
38
|
if (what === void 0) {
|
|
39
39
|
return Result.result(what);
|
|
40
40
|
}
|
|
41
41
|
if (!property) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (options.parentProperty && "additionalProperties" in options.parentProperty && options.parentProperty.additionalProperties) {
|
|
43
|
+
const extraneous = options.parentProperty.additionalProperties;
|
|
44
|
+
if (typeof extraneous === "boolean" || Object.keys(extraneous).includes(propName)) {
|
|
45
|
+
if (filterOutExtraneous) {
|
|
46
|
+
return Result.result(void 0);
|
|
47
|
+
}
|
|
48
|
+
return Result.result(what);
|
|
45
49
|
}
|
|
46
50
|
return Result.result(what);
|
|
47
51
|
}
|
|
@@ -193,7 +197,10 @@ export const validate = (what, schema, options = {}) => {
|
|
|
193
197
|
propName,
|
|
194
198
|
what[propName],
|
|
195
199
|
schema.properties[propName],
|
|
196
|
-
|
|
200
|
+
{
|
|
201
|
+
...options,
|
|
202
|
+
parentProperty: schema
|
|
203
|
+
}
|
|
197
204
|
);
|
|
198
205
|
if (error) {
|
|
199
206
|
errors[propName] = error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/validation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@aeriajs/types": "link:../types"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@aeriajs/common": "^0.0.
|
|
30
|
-
"@aeriajs/types": "^0.0.
|
|
29
|
+
"@aeriajs/common": "^0.0.87",
|
|
30
|
+
"@aeriajs/types": "^0.0.75"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"test": "env TS_NODE_COMPILER_OPTIONS=\"$(cat ../compilerOptions.json)\" mocha -r ts-node/register tests/*.spec.ts",
|