@dvsa/cvs-type-definitions 2.0.29 → 2.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvsa/cvs-type-definitions",
3
- "version": "2.0.29",
3
+ "version": "2.1.0",
4
4
  "description": "type definitions for cvs vta application",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -1,3 +1,5 @@
1
+ import { ErrorObject } from "ajv";
1
2
  import { schemas } from "./schemas";
2
3
  export declare type Schema = typeof schemas[number];
3
- export declare const isValidObject: (schemaName: Schema, objectToValidate: object, logErrors?: boolean) => boolean;
4
+ export declare function isValidObject<B extends boolean | undefined>(schemaName: Schema, objectToValidate: object): boolean;
5
+ export declare function isValidObject<B extends boolean | undefined>(schemaName: Schema, objectToValidate: object, returnErrors: B): B extends false ? boolean : ErrorObject[];
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isValidObject = void 0;
4
4
  var ajv_1 = require("ajv");
5
5
  var fs_1 = require("fs");
6
- var isValidObject = function (schemaName, objectToValidate, logErrors) {
6
+ function isValidObject(schemaName, objectToValidate, returnErrors, logErrors) {
7
+ var _a;
7
8
  if (logErrors === void 0) { logErrors = false; }
8
9
  var ajv = new ajv_1.default({ removeAdditional: true, allErrors: true });
9
10
  var schema = JSON.parse((0, fs_1.readFileSync)("".concat(__dirname, "/json-schemas/").concat(schemaName), "utf8"));
@@ -12,6 +13,10 @@ var isValidObject = function (schemaName, objectToValidate, logErrors) {
12
13
  if (logErrors && validateFunction.errors) {
13
14
  console.error(validateFunction.errors);
14
15
  }
16
+ if (returnErrors) {
17
+ return (_a = validateFunction.errors) !== null && _a !== void 0 ? _a : [];
18
+ }
15
19
  return isValid;
16
- };
20
+ }
17
21
  exports.isValidObject = isValidObject;
22
+ ;