@aeriajs/validation 0.0.146 → 0.0.148
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 +3 -3
- package/dist/validate.js +11 -11
- package/dist/validate.mjs +11 -11
- package/package.json +4 -4
package/dist/validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchema, Property, InferSchema, Description, PropertyValidationError, ValidationError } from '@aeriajs/types';
|
|
2
|
-
import { Result
|
|
2
|
+
import { Result } from '@aeriajs/types';
|
|
3
3
|
export type ValidateOptions = {
|
|
4
4
|
tolerateExtraneous?: boolean;
|
|
5
5
|
throwOnError?: boolean;
|
|
@@ -10,8 +10,8 @@ export declare const makeValidationError: <TValidationError extends ValidationEr
|
|
|
10
10
|
export declare const validateProperty: <TWhat>(what: TWhat, property: Property | undefined, options?: ValidateOptions) => Result.Either<PropertyValidationError | ValidationError, unknown>;
|
|
11
11
|
export declare const validateRefs: <TWhat>(what: TWhat, property: Property | Description | undefined, options?: ValidateOptions, descriptions?: Record<string, Description>) => Promise<Result.Either<PropertyValidationError | ValidationError, unknown>>;
|
|
12
12
|
export declare const validateWholeness: (what: Record<string, unknown>, schema: Omit<JsonSchema, "$id">) => {
|
|
13
|
-
code:
|
|
14
|
-
|
|
13
|
+
code: "MISSING_PROPERTIES";
|
|
14
|
+
details: {
|
|
15
15
|
[k: string]: {
|
|
16
16
|
type: "missing";
|
|
17
17
|
};
|
package/dist/validate.js
CHANGED
|
@@ -178,7 +178,7 @@ const validateProperty = (what, property, options = {}) => {
|
|
|
178
178
|
for (const elem of what) {
|
|
179
179
|
const { error } = (0, exports.validateProperty)(elem, property.items, options);
|
|
180
180
|
if (error) {
|
|
181
|
-
if ('
|
|
181
|
+
if ('code' in error) {
|
|
182
182
|
continue;
|
|
183
183
|
}
|
|
184
184
|
error.index = i;
|
|
@@ -242,17 +242,17 @@ const validateRefs = async (what, property, options, descriptions) => {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
else if ('properties' in property) {
|
|
245
|
-
const
|
|
245
|
+
const details = {};
|
|
246
246
|
for (const propName in what) {
|
|
247
247
|
const { error } = await (0, exports.validateRefs)(what[propName], property.properties[propName], options, descriptions);
|
|
248
248
|
if (error) {
|
|
249
|
-
|
|
249
|
+
details[propName] = error;
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
-
if (Object.keys(
|
|
252
|
+
if (Object.keys(details).length > 0) {
|
|
253
253
|
return types_1.Result.error((0, exports.makeValidationError)({
|
|
254
254
|
code: types_1.ValidationErrorCode.InvalidProperties,
|
|
255
|
-
|
|
255
|
+
details,
|
|
256
256
|
}));
|
|
257
257
|
}
|
|
258
258
|
}
|
|
@@ -268,7 +268,7 @@ const validateWholeness = (what, schema) => {
|
|
|
268
268
|
if (missingProps.length > 0) {
|
|
269
269
|
return (0, exports.makeValidationError)({
|
|
270
270
|
code: types_1.ValidationErrorCode.MissingProperties,
|
|
271
|
-
|
|
271
|
+
details: Object.fromEntries(missingProps.map((error) => [
|
|
272
272
|
error,
|
|
273
273
|
{
|
|
274
274
|
type: 'missing',
|
|
@@ -282,7 +282,7 @@ const validate = (what, schema, options = {}) => {
|
|
|
282
282
|
if (what === undefined) {
|
|
283
283
|
return types_1.Result.error((0, exports.makeValidationError)({
|
|
284
284
|
code: types_1.ValidationErrorCode.EmptyTarget,
|
|
285
|
-
|
|
285
|
+
details: {},
|
|
286
286
|
}));
|
|
287
287
|
}
|
|
288
288
|
if (!('properties' in schema)) {
|
|
@@ -299,7 +299,7 @@ const validate = (what, schema, options = {}) => {
|
|
|
299
299
|
}
|
|
300
300
|
return types_1.Result.error(wholenessError);
|
|
301
301
|
}
|
|
302
|
-
const
|
|
302
|
+
const details = {};
|
|
303
303
|
const resultCopy = {};
|
|
304
304
|
for (const propName in what) {
|
|
305
305
|
const { error, result: parsed } = (0, exports.validateProperty)(what[propName], schema.properties[propName], {
|
|
@@ -310,17 +310,17 @@ const validate = (what, schema, options = {}) => {
|
|
|
310
310
|
if (options.throwOnError) {
|
|
311
311
|
throw new TypeError(types_1.ValidationErrorCode.InvalidProperties);
|
|
312
312
|
}
|
|
313
|
-
|
|
313
|
+
details[propName] = error;
|
|
314
314
|
continue;
|
|
315
315
|
}
|
|
316
316
|
if (parsed !== undefined) {
|
|
317
317
|
resultCopy[propName] = parsed;
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
if (Object.keys(
|
|
320
|
+
if (Object.keys(details).length > 0) {
|
|
321
321
|
return types_1.Result.error((0, exports.makeValidationError)({
|
|
322
322
|
code: types_1.ValidationErrorCode.InvalidProperties,
|
|
323
|
-
|
|
323
|
+
details,
|
|
324
324
|
}));
|
|
325
325
|
}
|
|
326
326
|
return types_1.Result.result(resultCopy);
|
package/dist/validate.mjs
CHANGED
|
@@ -167,7 +167,7 @@ export const validateProperty = (what, property, options = {}) => {
|
|
|
167
167
|
for (const elem of what) {
|
|
168
168
|
const { error } = validateProperty(elem, property.items, options);
|
|
169
169
|
if (error) {
|
|
170
|
-
if ("
|
|
170
|
+
if ("code" in error) {
|
|
171
171
|
continue;
|
|
172
172
|
}
|
|
173
173
|
error.index = i;
|
|
@@ -225,17 +225,17 @@ export const validateRefs = async (what, property, options, descriptions) => {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
} else if ("properties" in property) {
|
|
228
|
-
const
|
|
228
|
+
const details = {};
|
|
229
229
|
for (const propName in what) {
|
|
230
230
|
const { error } = await validateRefs(what[propName], property.properties[propName], options, descriptions);
|
|
231
231
|
if (error) {
|
|
232
|
-
|
|
232
|
+
details[propName] = error;
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
if (Object.keys(
|
|
235
|
+
if (Object.keys(details).length > 0) {
|
|
236
236
|
return Result.error(makeValidationError({
|
|
237
237
|
code: ValidationErrorCode.InvalidProperties,
|
|
238
|
-
|
|
238
|
+
details
|
|
239
239
|
}));
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -248,7 +248,7 @@ export const validateWholeness = (what, schema) => {
|
|
|
248
248
|
if (missingProps.length > 0) {
|
|
249
249
|
return makeValidationError({
|
|
250
250
|
code: ValidationErrorCode.MissingProperties,
|
|
251
|
-
|
|
251
|
+
details: Object.fromEntries(missingProps.map((error) => [
|
|
252
252
|
error,
|
|
253
253
|
{
|
|
254
254
|
type: "missing"
|
|
@@ -261,7 +261,7 @@ export const validate = (what, schema, options = {}) => {
|
|
|
261
261
|
if (what === void 0) {
|
|
262
262
|
return Result.error(makeValidationError({
|
|
263
263
|
code: ValidationErrorCode.EmptyTarget,
|
|
264
|
-
|
|
264
|
+
details: {}
|
|
265
265
|
}));
|
|
266
266
|
}
|
|
267
267
|
if (!("properties" in schema)) {
|
|
@@ -278,7 +278,7 @@ export const validate = (what, schema, options = {}) => {
|
|
|
278
278
|
}
|
|
279
279
|
return Result.error(wholenessError);
|
|
280
280
|
}
|
|
281
|
-
const
|
|
281
|
+
const details = {};
|
|
282
282
|
const resultCopy = {};
|
|
283
283
|
for (const propName in what) {
|
|
284
284
|
const { error, result: parsed } = validateProperty(what[propName], schema.properties[propName], {
|
|
@@ -289,17 +289,17 @@ export const validate = (what, schema, options = {}) => {
|
|
|
289
289
|
if (options.throwOnError) {
|
|
290
290
|
throw new TypeError(ValidationErrorCode.InvalidProperties);
|
|
291
291
|
}
|
|
292
|
-
|
|
292
|
+
details[propName] = error;
|
|
293
293
|
continue;
|
|
294
294
|
}
|
|
295
295
|
if (parsed !== void 0) {
|
|
296
296
|
resultCopy[propName] = parsed;
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
-
if (Object.keys(
|
|
299
|
+
if (Object.keys(details).length > 0) {
|
|
300
300
|
return Result.error(makeValidationError({
|
|
301
301
|
code: ValidationErrorCode.InvalidProperties,
|
|
302
|
-
|
|
302
|
+
details
|
|
303
303
|
}));
|
|
304
304
|
}
|
|
305
305
|
return Result.result(resultCopy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/validation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.148",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@aeriajs/types": "link:../types"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@aeriajs/common": "^0.0.
|
|
31
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
32
|
-
"@aeriajs/types": "^0.0.
|
|
30
|
+
"@aeriajs/common": "^0.0.132",
|
|
31
|
+
"@aeriajs/entrypoint": "^0.0.136",
|
|
32
|
+
"@aeriajs/types": "^0.0.114",
|
|
33
33
|
"mongodb": "^6.5.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|