@aeriajs/validation 0.0.137 → 0.0.139

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.
@@ -5,7 +5,7 @@ export type ValidateOptions = {
5
5
  tolerateExtraneous?: boolean;
6
6
  throwOnError?: boolean;
7
7
  coerce?: boolean;
8
- parentProperty?: Omit<Description, '$id'> | Property;
8
+ parentProperty?: Property | Description;
9
9
  };
10
10
  export declare const makeValidationError: <TValidationError extends ValidationError>(error: TValidationError) => TValidationError;
11
11
  export declare const validateProperty: <TWhat>(what: TWhat, property: Property | undefined, options?: ValidateOptions) => Result.Either<PropertyValidationError | ValidationError, unknown>;
@@ -18,7 +18,7 @@ export declare const validateWholeness: (what: Record<string, unknown>, schema:
18
18
  };
19
19
  };
20
20
  } | undefined;
21
- export declare const validate: <TWhat, const TJsonSchema extends Omit<Description, "$id"> | Property>(what: TWhat | undefined, schema: TJsonSchema, options?: ValidateOptions) => {
21
+ export declare const validate: <TWhat, const TJsonSchema extends Property | Description>(what: TWhat | undefined, schema: TJsonSchema, options?: ValidateOptions) => {
22
22
  readonly _tag: "Error";
23
23
  readonly error: PropertyValidationError | ValidationError;
24
24
  readonly result: undefined;
@@ -27,7 +27,16 @@ export declare const validate: <TWhat, const TJsonSchema extends Omit<Descriptio
27
27
  readonly error: undefined;
28
28
  readonly result: InferSchema<TJsonSchema, {}>;
29
29
  };
30
- export declare const validator: <const TJsonSchema extends Omit<Description, "$id"> | Property>(schema: TJsonSchema, options?: ValidateOptions) => readonly [InferSchema<TJsonSchema>, <TWhat>(what: TWhat) => {
30
+ export declare const validateWithRefs: <TWhat, const TJsonSchema extends Property | Description>(what: TWhat | undefined, schema: TJsonSchema, options?: ValidateOptions, descriptions?: Record<string, Description>) => Promise<{
31
+ readonly _tag: "Error";
32
+ readonly error: PropertyValidationError | ValidationError;
33
+ readonly result: undefined;
34
+ } | {
35
+ readonly _tag: "Result";
36
+ readonly error: undefined;
37
+ readonly result: InferSchema<TJsonSchema, {}>;
38
+ }>;
39
+ export declare const validator: <const TJsonSchema extends Property | Description>(schema: TJsonSchema, options?: ValidateOptions) => readonly [InferSchema<TJsonSchema>, <TWhat>(what: TWhat) => {
31
40
  readonly _tag: "Error";
32
41
  readonly error: PropertyValidationError | ValidationError;
33
42
  readonly result: undefined;
package/dist/validate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validator = exports.validate = exports.validateWholeness = exports.validateRefs = exports.validateProperty = exports.makeValidationError = void 0;
3
+ exports.validator = exports.validateWithRefs = exports.validate = exports.validateWholeness = exports.validateRefs = exports.validateProperty = exports.makeValidationError = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
5
  const common_1 = require("@aeriajs/common");
6
6
  const types_2 = require("@aeriajs/types");
@@ -209,7 +209,7 @@ const validateRefs = async (what, property, options, descriptions) => {
209
209
  got: typeof what,
210
210
  }));
211
211
  }
212
- return (0, exports.validate)(what, description);
212
+ return (0, exports.validate)(what, description, options);
213
213
  }
214
214
  else if ('items' in property) {
215
215
  if (!Array.isArray(what)) {
@@ -307,6 +307,14 @@ const validate = (what, schema, options = {}) => {
307
307
  return types_1.Result.result(resultCopy);
308
308
  };
309
309
  exports.validate = validate;
310
+ const validateWithRefs = async (what, schema, options = {}, descriptions) => {
311
+ const { error: refsError } = await (0, exports.validateRefs)(what, schema, options, descriptions);
312
+ if (refsError) {
313
+ return types_1.Result.error(refsError);
314
+ }
315
+ return (0, exports.validate)(what, schema, options);
316
+ };
317
+ exports.validateWithRefs = validateWithRefs;
310
318
  const validator = (schema, options = {}) => {
311
319
  return [
312
320
  {},
package/dist/validate.mjs CHANGED
@@ -196,7 +196,7 @@ export const validateRefs = async (what, property, options, descriptions) => {
196
196
  got: typeof what
197
197
  }));
198
198
  }
199
- return validate(what, description);
199
+ return validate(what, description, options);
200
200
  } else if ("items" in property) {
201
201
  if (!Array.isArray(what)) {
202
202
  throw new Error();
@@ -287,6 +287,13 @@ export const validate = (what, schema, options = {}) => {
287
287
  }
288
288
  return Result.result(resultCopy);
289
289
  };
290
+ export const validateWithRefs = async (what, schema, options = {}, descriptions) => {
291
+ const { error: refsError } = await validateRefs(what, schema, options, descriptions);
292
+ if (refsError) {
293
+ return Result.error(refsError);
294
+ }
295
+ return validate(what, schema, options);
296
+ };
290
297
  export const validator = (schema, options = {}) => {
291
298
  return [
292
299
  {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/validation",
3
- "version": "0.0.137",
3
+ "version": "0.0.139",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",