@aeriajs/validation 0.0.161 → 0.0.162
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 +4 -2
- package/dist/validate.js +7 -7
- package/dist/validate.mjs +7 -7
- package/package.json +1 -1
package/dist/validate.d.ts
CHANGED
|
@@ -2,13 +2,15 @@ import type { JsonSchema, Property, InferSchema, Description, PropertyValidation
|
|
|
2
2
|
import { Result } from '@aeriajs/types';
|
|
3
3
|
export type ValidateOptions = {
|
|
4
4
|
tolerateExtraneous?: boolean;
|
|
5
|
+
checkObjectIds?: boolean;
|
|
5
6
|
throwOnError?: boolean;
|
|
6
7
|
coerce?: boolean;
|
|
7
8
|
parentProperty?: Property | Description;
|
|
9
|
+
descriptions?: Record<string, Description>;
|
|
8
10
|
};
|
|
9
11
|
export declare const makeValidationError: <TValidationError extends ValidationError>(error: TValidationError) => TValidationError;
|
|
10
12
|
export declare const validateProperty: <TWhat>(what: TWhat, property: Property | undefined, options?: ValidateOptions) => Result.Either<PropertyValidationError | ValidationError, unknown>;
|
|
11
|
-
export declare const validateRefs: <TWhat>(what: TWhat, property: Property | Description | undefined, options?: ValidateOptions
|
|
13
|
+
export declare const validateRefs: <TWhat>(what: TWhat, property: Property | Description | undefined, options?: ValidateOptions) => Promise<Result.Either<PropertyValidationError | ValidationError, unknown>>;
|
|
12
14
|
export declare const validateWholeness: (what: Record<string, unknown>, schema: Omit<JsonSchema, "$id">) => {
|
|
13
15
|
code: "MISSING_PROPERTIES";
|
|
14
16
|
details: {
|
|
@@ -26,7 +28,7 @@ export declare const validate: <TWhat, const TJsonSchema extends Property | Desc
|
|
|
26
28
|
readonly error: undefined;
|
|
27
29
|
readonly result: InferSchema<TJsonSchema, {}>;
|
|
28
30
|
};
|
|
29
|
-
export declare const validateWithRefs: <TWhat, const TJsonSchema extends Property | Description>(what: TWhat | undefined, schema: TJsonSchema, options?: ValidateOptions
|
|
31
|
+
export declare const validateWithRefs: <TWhat, const TJsonSchema extends Property | Description>(what: TWhat | undefined, schema: TJsonSchema, options?: ValidateOptions) => Promise<{
|
|
30
32
|
readonly _tag: "Error";
|
|
31
33
|
readonly error: PropertyValidationError | ValidationError;
|
|
32
34
|
readonly result: undefined;
|
package/dist/validate.js
CHANGED
|
@@ -211,12 +211,12 @@ const validateProperty = (what, property, options = {}) => {
|
|
|
211
211
|
return types_1.Result.result(what);
|
|
212
212
|
};
|
|
213
213
|
exports.validateProperty = validateProperty;
|
|
214
|
-
const validateRefs = async (what, property, options
|
|
214
|
+
const validateRefs = async (what, property, options = {}) => {
|
|
215
215
|
if (property) {
|
|
216
216
|
if ('$ref' in property) {
|
|
217
217
|
let description;
|
|
218
|
-
if (descriptions) {
|
|
219
|
-
description = descriptions[property.$ref];
|
|
218
|
+
if (options.descriptions) {
|
|
219
|
+
description = options.descriptions[property.$ref];
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
222
|
const collection = await (0, entrypoint_1.getCollection)(property.$ref);
|
|
@@ -238,7 +238,7 @@ const validateRefs = async (what, property, options, descriptions) => {
|
|
|
238
238
|
throw new Error;
|
|
239
239
|
}
|
|
240
240
|
for (const elem of what) {
|
|
241
|
-
const { error } = await (0, exports.validateRefs)(elem, property.items, options
|
|
241
|
+
const { error } = await (0, exports.validateRefs)(elem, property.items, options);
|
|
242
242
|
if (error) {
|
|
243
243
|
return types_1.Result.error(error);
|
|
244
244
|
}
|
|
@@ -247,7 +247,7 @@ const validateRefs = async (what, property, options, descriptions) => {
|
|
|
247
247
|
else if ('properties' in property) {
|
|
248
248
|
const details = {};
|
|
249
249
|
for (const propName in what) {
|
|
250
|
-
const { error } = await (0, exports.validateRefs)(what[propName], property.properties[propName], options
|
|
250
|
+
const { error } = await (0, exports.validateRefs)(what[propName], property.properties[propName], options);
|
|
251
251
|
if (error) {
|
|
252
252
|
details[propName] = error;
|
|
253
253
|
}
|
|
@@ -329,8 +329,8 @@ const validate = (what, schema, options = {}) => {
|
|
|
329
329
|
return types_1.Result.result(resultCopy);
|
|
330
330
|
};
|
|
331
331
|
exports.validate = validate;
|
|
332
|
-
const validateWithRefs = async (what, schema, options = {}
|
|
333
|
-
const { error: refsError } = await (0, exports.validateRefs)(what, schema, options
|
|
332
|
+
const validateWithRefs = async (what, schema, options = {}) => {
|
|
333
|
+
const { error: refsError } = await (0, exports.validateRefs)(what, schema, options);
|
|
334
334
|
if (refsError) {
|
|
335
335
|
return types_1.Result.error(refsError);
|
|
336
336
|
}
|
package/dist/validate.mjs
CHANGED
|
@@ -197,12 +197,12 @@ export const validateProperty = (what, property, options = {}) => {
|
|
|
197
197
|
}
|
|
198
198
|
return Result.result(what);
|
|
199
199
|
};
|
|
200
|
-
export const validateRefs = async (what, property, options
|
|
200
|
+
export const validateRefs = async (what, property, options = {}) => {
|
|
201
201
|
if (property) {
|
|
202
202
|
if ("$ref" in property) {
|
|
203
203
|
let description;
|
|
204
|
-
if (descriptions) {
|
|
205
|
-
description = descriptions[property.$ref];
|
|
204
|
+
if (options.descriptions) {
|
|
205
|
+
description = options.descriptions[property.$ref];
|
|
206
206
|
} else {
|
|
207
207
|
const collection = await getCollection(property.$ref);
|
|
208
208
|
if (!collection) {
|
|
@@ -222,7 +222,7 @@ export const validateRefs = async (what, property, options, descriptions) => {
|
|
|
222
222
|
throw new Error();
|
|
223
223
|
}
|
|
224
224
|
for (const elem of what) {
|
|
225
|
-
const { error } = await validateRefs(elem, property.items, options
|
|
225
|
+
const { error } = await validateRefs(elem, property.items, options);
|
|
226
226
|
if (error) {
|
|
227
227
|
return Result.error(error);
|
|
228
228
|
}
|
|
@@ -230,7 +230,7 @@ export const validateRefs = async (what, property, options, descriptions) => {
|
|
|
230
230
|
} else if ("properties" in property) {
|
|
231
231
|
const details = {};
|
|
232
232
|
for (const propName in what) {
|
|
233
|
-
const { error } = await validateRefs(what[propName], property.properties[propName], options
|
|
233
|
+
const { error } = await validateRefs(what[propName], property.properties[propName], options);
|
|
234
234
|
if (error) {
|
|
235
235
|
details[propName] = error;
|
|
236
236
|
}
|
|
@@ -307,8 +307,8 @@ export const validate = (what, schema, options = {}) => {
|
|
|
307
307
|
}
|
|
308
308
|
return Result.result(resultCopy);
|
|
309
309
|
};
|
|
310
|
-
export const validateWithRefs = async (what, schema, options = {}
|
|
311
|
-
const { error: refsError } = await validateRefs(what, schema, options
|
|
310
|
+
export const validateWithRefs = async (what, schema, options = {}) => {
|
|
311
|
+
const { error: refsError } = await validateRefs(what, schema, options);
|
|
312
312
|
if (refsError) {
|
|
313
313
|
return Result.error(refsError);
|
|
314
314
|
}
|