@tsed/ajv 7.0.0-alpha.1 → 7.0.0-beta.3

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.
Files changed (61) hide show
  1. package/lib/cjs/decorators/formats.js +22 -0
  2. package/lib/cjs/decorators/formats.js.map +1 -0
  3. package/lib/cjs/decorators/keyword.js +21 -0
  4. package/lib/cjs/decorators/keyword.js.map +1 -0
  5. package/lib/cjs/errors/AjvValidationError.js +13 -0
  6. package/lib/cjs/errors/AjvValidationError.js.map +1 -0
  7. package/lib/cjs/index.js +11 -0
  8. package/lib/cjs/index.js.map +1 -0
  9. package/lib/cjs/interfaces/FormatsMethods.js +3 -0
  10. package/lib/cjs/interfaces/FormatsMethods.js.map +1 -0
  11. package/lib/cjs/interfaces/IAjvSettings.js +3 -0
  12. package/lib/cjs/interfaces/IAjvSettings.js.map +1 -0
  13. package/lib/cjs/interfaces/KeywordMethods.js +3 -0
  14. package/lib/cjs/interfaces/KeywordMethods.js.map +1 -0
  15. package/lib/cjs/services/Ajv.js +68 -0
  16. package/lib/cjs/services/Ajv.js.map +1 -0
  17. package/lib/cjs/services/AjvService.js +91 -0
  18. package/lib/cjs/services/AjvService.js.map +1 -0
  19. package/lib/cjs/utils/defaultErrorFormatter.js +24 -0
  20. package/lib/cjs/utils/defaultErrorFormatter.js.map +1 -0
  21. package/lib/cjs/utils/getPath.js +9 -0
  22. package/lib/cjs/utils/getPath.js.map +1 -0
  23. package/lib/esm/decorators/formats.js +18 -0
  24. package/lib/esm/decorators/formats.js.map +1 -0
  25. package/lib/esm/decorators/keyword.js +17 -0
  26. package/lib/esm/decorators/keyword.js.map +1 -0
  27. package/lib/esm/errors/AjvValidationError.js +9 -0
  28. package/lib/esm/errors/AjvValidationError.js.map +1 -0
  29. package/lib/esm/index.js +8 -0
  30. package/lib/esm/index.js.map +1 -0
  31. package/lib/esm/interfaces/FormatsMethods.js +2 -0
  32. package/lib/esm/interfaces/FormatsMethods.js.map +1 -0
  33. package/lib/esm/interfaces/IAjvSettings.js +2 -0
  34. package/lib/esm/interfaces/IAjvSettings.js.map +1 -0
  35. package/lib/esm/interfaces/KeywordMethods.js +2 -0
  36. package/lib/esm/interfaces/KeywordMethods.js.map +1 -0
  37. package/lib/esm/services/Ajv.js +65 -0
  38. package/lib/esm/services/Ajv.js.map +1 -0
  39. package/lib/esm/services/AjvService.js +88 -0
  40. package/lib/esm/services/AjvService.js.map +1 -0
  41. package/lib/esm/utils/defaultErrorFormatter.js +20 -0
  42. package/lib/esm/utils/defaultErrorFormatter.js.map +1 -0
  43. package/lib/esm/utils/getPath.js +5 -0
  44. package/lib/esm/utils/getPath.js.map +1 -0
  45. package/lib/{decorators → types/decorators}/formats.d.ts +0 -0
  46. package/lib/{decorators → types/decorators}/keyword.d.ts +0 -0
  47. package/lib/{errors → types/errors}/AjvValidationError.d.ts +0 -0
  48. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  49. package/lib/{interfaces → types/interfaces}/FormatsMethods.d.ts +0 -0
  50. package/lib/{interfaces → types/interfaces}/IAjvSettings.d.ts +0 -0
  51. package/lib/{interfaces → types/interfaces}/KeywordMethods.d.ts +0 -0
  52. package/lib/{services → types/services}/Ajv.d.ts +0 -0
  53. package/lib/{services → types/services}/AjvService.d.ts +0 -0
  54. package/lib/{utils → types/utils}/defaultErrorFormatter.d.ts +0 -0
  55. package/lib/{utils → types/utils}/getPath.d.ts +0 -0
  56. package/package.json +21 -14
  57. package/tsconfig.compile.esm.json +23 -0
  58. package/lib/index.js +0 -302
  59. package/lib/index.js.map +0 -1
  60. package/lib/index.modern.js +0 -295
  61. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,88 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { deepClone, getValue, nameOf, prototypeOf, setValue } from "@tsed/core";
3
+ import { Constant, Inject, Injectable } from "@tsed/di";
4
+ import { getJsonSchema, JsonEntityStore, JsonSchema } from "@tsed/schema";
5
+ import Ajv from "ajv";
6
+ import { AjvValidationError } from "../errors/AjvValidationError";
7
+ import { defaultErrorFormatter } from "../utils/defaultErrorFormatter";
8
+ import "./Ajv";
9
+ import { getPath } from "../utils/getPath";
10
+ let AjvService = class AjvService {
11
+ async validate(value, options) {
12
+ let { schema, type, collectionType, ...additionalOptions } = this.mapOptions(options);
13
+ schema = schema || getJsonSchema(type, { ...additionalOptions, customKeys: true });
14
+ if (schema) {
15
+ const localValue = deepClone(value);
16
+ const valid = await this.ajv.validate(schema, localValue);
17
+ if (!valid && this.ajv.errors) {
18
+ throw this.mapErrors(this.ajv.errors || [], {
19
+ type,
20
+ collectionType,
21
+ async: true,
22
+ value: localValue
23
+ });
24
+ }
25
+ }
26
+ return value;
27
+ }
28
+ mapOptions(options) {
29
+ if (options instanceof JsonSchema) {
30
+ return {
31
+ schema: options.toJSON({ customKeys: true })
32
+ };
33
+ }
34
+ return options;
35
+ }
36
+ mapErrors(errors, options) {
37
+ const { type, collectionType, value } = options;
38
+ const message = errors
39
+ .map((error) => {
40
+ if (collectionType) {
41
+ error.collectionName = nameOf(collectionType);
42
+ }
43
+ const dataPath = getPath(error);
44
+ if (!error.data) {
45
+ if (dataPath) {
46
+ error.data = getValue(value, dataPath.replace(/^\./, ""));
47
+ }
48
+ else if (error.schemaPath !== "#/required") {
49
+ error.data = value;
50
+ }
51
+ }
52
+ if (dataPath && dataPath.match(/pwd|password|mdp|secret/)) {
53
+ error.data = "[REDACTED]";
54
+ }
55
+ if (type) {
56
+ error.modelName = nameOf(type);
57
+ error.message = this.mapClassError(error, type);
58
+ }
59
+ return this.errorFormatter.call(this, error, {});
60
+ })
61
+ .join("\n");
62
+ return new AjvValidationError(message, errors);
63
+ }
64
+ mapClassError(error, targetType) {
65
+ const propertyKey = getValue(error, "params.missingProperty");
66
+ if (propertyKey) {
67
+ const store = JsonEntityStore.from(prototypeOf(targetType), propertyKey);
68
+ if (store) {
69
+ setValue(error, "params.missingProperty", store.name || propertyKey);
70
+ return error.message.replace(`'${propertyKey}'`, `'${store.name || propertyKey}'`);
71
+ }
72
+ }
73
+ return error.message;
74
+ }
75
+ };
76
+ __decorate([
77
+ Constant("ajv.errorFormatter", defaultErrorFormatter),
78
+ __metadata("design:type", Function)
79
+ ], AjvService.prototype, "errorFormatter", void 0);
80
+ __decorate([
81
+ Inject(),
82
+ __metadata("design:type", Ajv)
83
+ ], AjvService.prototype, "ajv", void 0);
84
+ AjvService = __decorate([
85
+ Injectable()
86
+ ], AjvService);
87
+ export { AjvService };
88
+ //# sourceMappingURL=AjvService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AjvService.js","sourceRoot":"","sources":["../../../src/services/AjvService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAO,MAAM,YAAY,CAAC;AACpF,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AACtD,OAAO,EAAC,aAAa,EAAE,eAAe,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAC1F,OAAO,GAAkB,MAAM,KAAK,CAAC;AACrC,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,OAAO,CAAC;AACf,OAAO,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AASzC,IAAa,UAAU,GAAvB,MAAa,UAAU;IAOrB,KAAK,CAAC,QAAQ,CAAC,KAAU,EAAE,OAAwC;QACjE,IAAI,EAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,iBAAiB,EAAC,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEpF,MAAM,GAAG,MAAM,IAAI,aAAa,CAAC,IAAI,EAAE,EAAC,GAAG,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAC;QAEjF,IAA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B,UAAU,EAAE;GACA,UAAU,CAwFtB;SAxFY,UAAU","sourcesContent":["import {deepClone, getValue, nameOf, prototypeOf, setValue, Type} from \"@tsed/core\";\nimport {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {getJsonSchema, JsonEntityStore, JsonSchema, JsonSchemaObject} from \"@tsed/schema\";\nimport Ajv, {ErrorObject} from \"ajv\";\nimport {AjvValidationError} from \"../errors/AjvValidationError\";\nimport {AjvErrorObject, ErrorFormatter} from \"../interfaces/IAjvSettings\";\nimport {defaultErrorFormatter} from \"../utils/defaultErrorFormatter\";\nimport \"./Ajv\";\nimport {getPath} from \"../utils/getPath\";\n\nexport interface AjvValidateOptions extends Record<string, any> {\n schema?: JsonSchema | Partial<JsonSchemaObject>;\n type?: Type<any> | any;\n collectionType?: Type<any> | any;\n}\n\n@Injectable()\nexport class AjvService {\n @Constant(\"ajv.errorFormatter\", defaultErrorFormatter)\n protected errorFormatter: ErrorFormatter;\n\n @Inject()\n protected ajv: Ajv;\n\n async validate(value: any, options: AjvValidateOptions | JsonSchema): Promise<any> {\n let {schema, type, collectionType, ...additionalOptions} = this.mapOptions(options);\n\n schema = schema || getJsonSchema(type, {...additionalOptions, customKeys: true});\n\n if (schema) {\n const localValue = deepClone(value);\n const valid = await this.ajv.validate(schema as any, localValue);\n if (!valid && this.ajv.errors) {\n throw this.mapErrors(this.ajv.errors || [], {\n type,\n collectionType,\n async: true,\n value: localValue\n });\n }\n }\n\n return value;\n }\n\n protected mapOptions(options: AjvValidateOptions | JsonSchema): AjvValidateOptions {\n if (options instanceof JsonSchema) {\n return {\n schema: options.toJSON({customKeys: true})\n };\n }\n\n return options;\n }\n\n protected mapErrors(errors: ErrorObject[], options: any) {\n const {type, collectionType, value} = options;\n\n const message = errors\n .map((error: AjvErrorObject) => {\n if (collectionType) {\n error.collectionName = nameOf(collectionType);\n }\n\n const dataPath = getPath(error);\n\n if (!error.data) {\n if (dataPath) {\n error.data = getValue(value, dataPath.replace(/^\\./, \"\"));\n } else if (error.schemaPath !== \"#/required\") {\n error.data = value;\n }\n }\n\n if (dataPath && dataPath.match(/pwd|password|mdp|secret/)) {\n error.data = \"[REDACTED]\";\n }\n\n if (type) {\n error.modelName = nameOf(type);\n error.message = this.mapClassError(error, type);\n }\n\n return this.errorFormatter.call(this, error, {});\n })\n .join(\"\\n\");\n\n return new AjvValidationError(message, errors);\n }\n\n protected mapClassError(error: AjvErrorObject, targetType: Type<any>) {\n const propertyKey = getValue(error, \"params.missingProperty\");\n\n if (propertyKey) {\n const store = JsonEntityStore.from<JsonEntityStore>(prototypeOf(targetType), propertyKey);\n\n if (store) {\n setValue(error, \"params.missingProperty\", store.name || propertyKey);\n\n return error.message!.replace(`'${propertyKey}'`, `'${store.name || propertyKey}'`);\n }\n }\n\n return error.message;\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { getPath } from "./getPath";
2
+ export function defaultErrorFormatter(error) {
3
+ const value = JSON.stringify(error.data === undefined ? "undefined" : error.data);
4
+ const join = (list) => list.filter(Boolean).join("").trim();
5
+ error.dataPath = getPath(error);
6
+ const [, indexPath, ...paths] = error.dataPath.split(".");
7
+ const deepPaths = paths.length ? "." + paths.join(".") : "";
8
+ if (error.collectionName) {
9
+ switch (error.collectionName) {
10
+ case "Array":
11
+ return join([`${error.modelName || ""}[${indexPath}]${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
12
+ case "Map":
13
+ return join([`Map<${indexPath}, ${error.modelName || ""}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
14
+ case "Set":
15
+ return join([`Set<${indexPath}, ${error.modelName || ""}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
16
+ }
17
+ }
18
+ return join([!error.modelName && "Value", `${error.modelName || ""}`, error.dataPath, ` ${error.message}. Given value: ${value}`]);
19
+ }
20
+ //# sourceMappingURL=defaultErrorFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultErrorFormatter.js","sourceRoot":"","sources":["../../../src/utils/default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AAK,KAAK,CAAC,SAAS,IAAI,EAAE,IAAI,SAAS,EAAE,EAAE,IAAI,KAAK,CAAC,OAAO,kBAAkB,KAAK,EAAE,CAAC,CAAC,CAAC;SACxH;KACF;IAED,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,OAAO,EAAE,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,KAAK,CAAC,OAAO,kBAAkB,KAAK,EAAE,CAAC,CAAC,CAAC;AACrI,CAAC","sourcesContent":["import {AjvErrorObject} from \"../interfaces/IAjvSettings\";\nimport {getPath} from \"./getPath\";\n\nexport function defaultErrorFormatter(error: AjvErrorObject & {dataPath: string}) {\n const value = JSON.stringify(error.data === undefined ? \"undefined\" : error.data);\n const join = (list: any[]): string => list.filter(Boolean).join(\"\").trim();\n\n error.dataPath = getPath(error);\n\n const [, indexPath, ...paths] = error.dataPath.split(\".\");\n const deepPaths = paths.length ? \".\" + paths.join(\".\") : \"\";\n\n if (error.collectionName) {\n switch (error.collectionName) {\n case \"Array\":\n return join([`${error.modelName || \"\"}[${indexPath}]${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Map\":\n return join([`Map<${indexPath}, ${error.modelName || \"\"}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Set\":\n return join([`Set<${indexPath}, ${error.modelName || \"\"}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n }\n }\n\n return join([!error.modelName && \"Value\", `${error.modelName || \"\"}`, error.dataPath, ` ${error.message}. Given value: ${value}`]);\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { getValue } from "@tsed/core";
2
+ export function getPath(error) {
3
+ return getValue(error, "dataPath", getValue(error, "instancePath", "")).replace(/\//gi, ".");
4
+ }
5
+ //# sourceMappingURL=getPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPath.js","sourceRoot":"","sources":["../../../src/utils/getPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,MAAM,UAAU,OAAO,CAAC,KAAU;IAChC,OAAO,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import {getValue} from \"@tsed/core\";\n\nexport function getPath(error: any) {\n return getValue(error, \"dataPath\", getValue(error, \"instancePath\", \"\")).replace(/\\//gi, \".\");\n}\n"]}
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,37 +1,44 @@
1
1
  {
2
2
  "name": "@tsed/ajv",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.3",
4
4
  "description": "AJV package for Ts.ED framework",
5
5
  "source": "./src/index.ts",
6
- "main": "./lib/index.js",
7
- "typings": "./lib/index.d.ts",
8
- "private": false,
6
+ "main": "./lib/cjs/index.js",
7
+ "typings": "./lib/types/index.d.ts",
8
+ "exports": {
9
+ "types": "./lib/types/index.d.ts",
10
+ "import": "./lib/esm/index.js",
11
+ "require": "./lib/cjs/index.js",
12
+ "default": "./lib/esm/index.js"
13
+ },
9
14
  "scripts": {
10
- "build": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json"
15
+ "build": "yarn run build:esm && yarn run build:cjs",
16
+ "build:cjs": "tsc --build tsconfig.compile.json",
17
+ "build:esm": "tsc --build tsconfig.compile.esm.json"
11
18
  },
12
19
  "dependencies": {
13
20
  "ajv-formats": "1.5.1",
14
21
  "tslib": "2.2.0"
15
22
  },
16
23
  "devDependencies": {
17
- "@tsed/core": "7.0.0-alpha.1",
18
- "@tsed/di": "7.0.0-alpha.1",
19
- "@tsed/exceptions": "7.0.0-alpha.1",
20
- "@tsed/schema": "7.0.0-alpha.1",
24
+ "@tsed/core": "7.0.0-beta.3",
25
+ "@tsed/di": "7.0.0-beta.3",
26
+ "@tsed/exceptions": "7.0.0-beta.3",
27
+ "@tsed/schema": "7.0.0-beta.3",
21
28
  "ajv": "8.6.0"
22
29
  },
23
30
  "peerDependencies": {
24
- "@tsed/core": "^7.0.0-alpha.1",
25
- "@tsed/di": "^7.0.0-alpha.1",
26
- "@tsed/exceptions": "^7.0.0-alpha.1",
27
- "@tsed/schema": "^7.0.0-alpha.1",
31
+ "@tsed/core": "^7.0.0-beta.3",
32
+ "@tsed/di": "^7.0.0-beta.3",
33
+ "@tsed/exceptions": "^7.0.0-beta.3",
34
+ "@tsed/schema": "^7.0.0-beta.3",
28
35
  "ajv": "7||8"
29
36
  },
30
37
  "repository": "https://github.com/tsedio/tsed",
31
38
  "bugs": {
32
39
  "url": "https://github.com/tsedio/tsed/issues"
33
40
  },
34
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/specs/ajv",
41
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/specs/ajv",
35
42
  "author": "Romain Lenzotti",
36
43
  "license": "MIT"
37
44
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": [
12
+ "node_modules",
13
+ "test",
14
+ "lib",
15
+ "benchmark",
16
+ "coverage",
17
+ "spec",
18
+ "**/*.benchmark.ts",
19
+ "**/*.spec.ts",
20
+ "keys",
21
+ "jest.config.js"
22
+ ]
23
+ }
package/lib/index.js DELETED
@@ -1,302 +0,0 @@
1
- var exceptions = require('@tsed/exceptions');
2
- var tslib = require('tslib');
3
- var core = require('@tsed/core');
4
- var di = require('@tsed/di');
5
- var schema = require('@tsed/schema');
6
- var Ajv = require('ajv');
7
- var AjvFormats = require('ajv-formats');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
12
- var AjvFormats__default = /*#__PURE__*/_interopDefaultLegacy(AjvFormats);
13
-
14
- class AjvValidationError extends exceptions.BadRequest {
15
- constructor(message, errors = []) {
16
- super(message);
17
- this.name = "AJV_VALIDATION_ERROR";
18
- this.errors = errors;
19
- }
20
-
21
- }
22
-
23
- function _extends() {
24
- _extends = Object.assign || function (target) {
25
- for (var i = 1; i < arguments.length; i++) {
26
- var source = arguments[i];
27
-
28
- for (var key in source) {
29
- if (Object.prototype.hasOwnProperty.call(source, key)) {
30
- target[key] = source[key];
31
- }
32
- }
33
- }
34
-
35
- return target;
36
- };
37
-
38
- return _extends.apply(this, arguments);
39
- }
40
-
41
- function _objectWithoutPropertiesLoose(source, excluded) {
42
- if (source == null) return {};
43
- var target = {};
44
- var sourceKeys = Object.keys(source);
45
- var key, i;
46
-
47
- for (i = 0; i < sourceKeys.length; i++) {
48
- key = sourceKeys[i];
49
- if (excluded.indexOf(key) >= 0) continue;
50
- target[key] = source[key];
51
- }
52
-
53
- return target;
54
- }
55
-
56
- function getPath(error) {
57
- return core.getValue(error, "dataPath", core.getValue(error, "instancePath", "")).replace(/\//gi, ".");
58
- }
59
-
60
- function defaultErrorFormatter(error) {
61
- const value = JSON.stringify(error.data === undefined ? "undefined" : error.data);
62
-
63
- const join = list => list.filter(Boolean).join("").trim();
64
-
65
- error.dataPath = getPath(error);
66
- const [, indexPath, ...paths] = error.dataPath.split(".");
67
- const deepPaths = paths.length ? "." + paths.join(".") : "";
68
-
69
- if (error.collectionName) {
70
- switch (error.collectionName) {
71
- case "Array":
72
- return join([`${error.modelName || ""}[${indexPath}]${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
73
-
74
- case "Map":
75
- return join([`Map<${indexPath}, ${error.modelName || ""}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
76
-
77
- case "Set":
78
- return join([`Set<${indexPath}, ${error.modelName || ""}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);
79
- }
80
- }
81
-
82
- return join([!error.modelName && "Value", `${error.modelName || ""}`, error.dataPath, ` ${error.message}. Given value: ${value}`]);
83
- }
84
-
85
- const _excluded$1 = ["errorFormatter", "keywords"];
86
-
87
- function getHandler(key, service) {
88
- if (service[key]) {
89
- return service[key].bind(service);
90
- }
91
- }
92
-
93
- function getKeywordProviders(injector) {
94
- return injector.getProviders("ajv:keyword");
95
- }
96
-
97
- function bindKeywords(injector) {
98
- return getKeywordProviders(injector).map(provider => {
99
- const options = provider.store.get("ajv:keyword", {});
100
- const service = injector.invoke(provider.token);
101
- return core.cleanObject(_extends({}, options, {
102
- validate: getHandler("validate", service),
103
- compile: getHandler("compile", service),
104
- code: getHandler("code", service),
105
- macro: getHandler("macro", service)
106
- }));
107
- });
108
- }
109
-
110
- function getFormatsProviders(injector) {
111
- return injector.getProviders("ajv:formats");
112
- }
113
-
114
- function getFormats(injector) {
115
- return getFormatsProviders(injector).map(provider => {
116
- var _service$compare;
117
-
118
- const {
119
- name,
120
- options
121
- } = provider.store.get("ajv:formats", {});
122
- const service = injector.invoke(provider.token);
123
- return {
124
- name,
125
- options: _extends({}, options, {
126
- validate: service.validate.bind(service),
127
- compare: (_service$compare = service.compare) == null ? void 0 : _service$compare.bind(service)
128
- })
129
- };
130
- });
131
- }
132
-
133
- di.registerProvider({
134
- provide: Ajv__default['default'],
135
- deps: [di.Configuration, di.InjectorService],
136
- scope: di.ProviderScope.SINGLETON,
137
-
138
- useFactory(configuration, injector) {
139
- const _ref = configuration.get("ajv") || {},
140
- {
141
- keywords = []
142
- } = _ref,
143
- props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
144
-
145
- const options = _extends({
146
- verbose: false,
147
- coerceTypes: true,
148
- strict: false,
149
- keywords: [...keywords, ...bindKeywords(injector)]
150
- }, props);
151
-
152
- const ajv = new Ajv__default['default'](options);
153
- AjvFormats__default['default'](ajv);
154
- getFormats(injector).forEach(({
155
- name,
156
- options
157
- }) => {
158
- ajv.addFormat(name, options);
159
- });
160
- return ajv;
161
- }
162
-
163
- });
164
-
165
- const _excluded = ["schema", "type", "collectionType"];
166
- exports.AjvService = class AjvService {
167
- async validate(value, options) {
168
- let _this$mapOptions = this.mapOptions(options),
169
- {
170
- schema: schema$1,
171
- type,
172
- collectionType
173
- } = _this$mapOptions,
174
- additionalOptions = _objectWithoutPropertiesLoose(_this$mapOptions, _excluded);
175
-
176
- schema$1 = schema$1 || schema.getJsonSchema(type, _extends({}, additionalOptions, {
177
- customKeys: true
178
- }));
179
-
180
- if (schema$1) {
181
- const localValue = core.deepClone(value);
182
- const valid = await this.ajv.validate(schema$1, localValue);
183
-
184
- if (!valid) {
185
- throw this.mapErrors(this.ajv.errors || [], {
186
- type,
187
- collectionType,
188
- async: true,
189
- value: localValue
190
- });
191
- }
192
- }
193
-
194
- return value;
195
- }
196
-
197
- mapOptions(options) {
198
- if (options instanceof schema.JsonSchema) {
199
- return {
200
- schema: options.toJSON({
201
- customKeys: true
202
- })
203
- };
204
- }
205
-
206
- return options;
207
- }
208
-
209
- mapErrors(errors, options) {
210
- const {
211
- type,
212
- collectionType,
213
- value
214
- } = options;
215
- const message = errors.map(error => {
216
- if (collectionType) {
217
- error.collectionName = core.nameOf(collectionType);
218
- }
219
-
220
- const dataPath = getPath(error);
221
-
222
- if (!error.data) {
223
- if (dataPath) {
224
- error.data = core.getValue(value, dataPath.replace(/^\./, ""));
225
- } else if (error.schemaPath !== "#/required") {
226
- error.data = value;
227
- }
228
- }
229
-
230
- if (dataPath && dataPath.match(/pwd|password|mdp|secret/)) {
231
- error.data = "[REDACTED]";
232
- }
233
-
234
- if (type) {
235
- error.modelName = core.nameOf(type);
236
- error.message = this.mapClassError(error, type);
237
- }
238
-
239
- return this.errorFormatter.call(this, error, {});
240
- }).join("\n");
241
- return new AjvValidationError(message, errors);
242
- }
243
-
244
- mapClassError(error, targetType) {
245
- const propertyKey = core.getValue(error, "params.missingProperty");
246
-
247
- if (propertyKey) {
248
- const store = schema.JsonEntityStore.from(core.prototypeOf(targetType), propertyKey);
249
-
250
- if (store) {
251
- core.setValue(error, "params.missingProperty", store.name || propertyKey);
252
- return error.message.replace(`'${propertyKey}'`, `'${store.name || propertyKey}'`);
253
- }
254
- }
255
-
256
- return error.message;
257
- }
258
-
259
- };
260
-
261
- tslib.__decorate([di.Constant("ajv.errorFormatter", defaultErrorFormatter), tslib.__metadata("design:type", Function)], exports.AjvService.prototype, "errorFormatter", void 0);
262
-
263
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", Ajv__default['default'])], exports.AjvService.prototype, "ajv", void 0);
264
-
265
- exports.AjvService = tslib.__decorate([di.Injectable()], exports.AjvService);
266
-
267
- /**
268
- * Create new keyword custom validator
269
- * @param options
270
- * @decorator
271
- * @ajv
272
- */
273
-
274
- function Keyword(options) {
275
- return core.useDecorators(di.Injectable({
276
- type: "ajv:keyword"
277
- }), core.StoreSet("ajv:keyword", _extends({}, options, {
278
- metaSchema: options.metaSchema && options.metaSchema.toJSON ? options.metaSchema.toJSON() : options.metaSchema
279
- })));
280
- }
281
-
282
- /**
283
- * Create a new custom formats validator
284
- * @param name
285
- * @param options
286
- * @decorator
287
- * @ajv
288
- */
289
-
290
- function Formats(name, options = {}) {
291
- return core.useDecorators(di.Injectable({
292
- type: "ajv:formats"
293
- }), core.StoreSet("ajv:formats", {
294
- name,
295
- options
296
- }));
297
- }
298
-
299
- exports.AjvValidationError = AjvValidationError;
300
- exports.Formats = Formats;
301
- exports.Keyword = Keyword;
302
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/errors/AjvValidationError.ts","../src/utils/getPath.ts","../src/utils/defaultErrorFormatter.ts","../src/services/Ajv.ts","../src/services/AjvService.ts","../src/decorators/keyword.ts","../src/decorators/formats.ts"],"sourcesContent":["import {BadRequest} from \"@tsed/exceptions\";\n\nexport class AjvValidationError extends BadRequest {\n public name: string = \"AJV_VALIDATION_ERROR\";\n public errors: any[];\n\n constructor(message: string, errors: any[] = []) {\n super(message);\n this.errors = errors;\n }\n}\n","import {getValue} from \"@tsed/core\";\n\nexport function getPath(error: any) {\n return getValue(error, \"dataPath\", getValue(error, \"instancePath\", \"\")).replace(/\\//gi, \".\");\n}\n","import {AjvErrorObject} from \"../interfaces/IAjvSettings\";\nimport {getPath} from \"./getPath\";\n\nexport function defaultErrorFormatter(error: AjvErrorObject & {dataPath: string}) {\n const value = JSON.stringify(error.data === undefined ? \"undefined\" : error.data);\n const join = (list: any[]): string => list.filter(Boolean).join(\"\").trim();\n\n error.dataPath = getPath(error);\n\n const [, indexPath, ...paths] = error.dataPath.split(\".\");\n const deepPaths = paths.length ? \".\" + paths.join(\".\") : \"\";\n\n if (error.collectionName) {\n switch (error.collectionName) {\n case \"Array\":\n return join([`${error.modelName || \"\"}[${indexPath}]${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Map\":\n return join([`Map<${indexPath}, ${error.modelName || \"\"}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Set\":\n return join([`Set<${indexPath}, ${error.modelName || \"\"}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n }\n }\n\n return join([!error.modelName && \"Value\", `${error.modelName || \"\"}`, error.dataPath, ` ${error.message}. Given value: ${value}`]);\n}\n","import {cleanObject} from \"@tsed/core\";\nimport {Configuration, InjectorService, ProviderScope, registerProvider} from \"@tsed/di\";\nimport Ajv, {Format, KeywordDefinition, Vocabulary} from \"ajv\";\nimport AjvFormats from \"ajv-formats\";\nimport {FormatsMethods} from \"../interfaces/FormatsMethods\";\nimport {IAjvSettings} from \"../interfaces/IAjvSettings\";\n\nfunction getHandler(key: string, service: any) {\n if (service[key]) {\n return service[key].bind(service);\n }\n}\n\nfunction getKeywordProviders(injector: InjectorService) {\n return injector.getProviders(\"ajv:keyword\");\n}\n\nfunction bindKeywords(injector: InjectorService): Vocabulary {\n return getKeywordProviders(injector).map((provider) => {\n const options = provider.store.get<Omit<KeywordDefinition, \"compile\">>(\"ajv:keyword\", {})!;\n const service = injector.invoke(provider.token);\n\n return <KeywordDefinition>cleanObject({\n ...options,\n validate: getHandler(\"validate\", service),\n compile: getHandler(\"compile\", service),\n code: getHandler(\"code\", service),\n macro: getHandler(\"macro\", service)\n });\n });\n}\n\nfunction getFormatsProviders(injector: InjectorService) {\n return injector.getProviders(\"ajv:formats\");\n}\n\nfunction getFormats(injector: InjectorService): {name: string; options: Format}[] {\n return getFormatsProviders(injector).map((provider) => {\n const {name, options} = provider.store.get<any>(\"ajv:formats\", {})!;\n const service = injector.invoke<FormatsMethods<any>>(provider.token);\n\n return {\n name,\n options: {\n ...options,\n validate: service.validate.bind(service),\n compare: service.compare?.bind(service)\n }\n };\n });\n}\n\nregisterProvider({\n provide: Ajv,\n deps: [Configuration, InjectorService],\n scope: ProviderScope.SINGLETON,\n useFactory(configuration: Configuration, injector: InjectorService) {\n const {errorFormatter, keywords = [], ...props} = configuration.get<IAjvSettings>(\"ajv\") || {};\n const options = {\n verbose: false,\n coerceTypes: true,\n strict: false,\n keywords: [...keywords, ...bindKeywords(injector)],\n ...props\n };\n\n const ajv = new Ajv(options);\n\n AjvFormats(ajv as any);\n\n getFormats(injector).forEach(({name, options}) => {\n ajv.addFormat(name, options);\n });\n\n return ajv;\n }\n});\n","import {deepClone, getValue, nameOf, prototypeOf, setValue, Type} from \"@tsed/core\";\nimport {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {getJsonSchema, JsonEntityStore, JsonSchema, JsonSchemaObject} from \"@tsed/schema\";\nimport Ajv, {ErrorObject} from \"ajv\";\nimport {AjvValidationError} from \"../errors/AjvValidationError\";\nimport {AjvErrorObject, ErrorFormatter} from \"../interfaces/IAjvSettings\";\nimport {defaultErrorFormatter} from \"../utils/defaultErrorFormatter\";\nimport \"./Ajv\";\nimport {getPath} from \"../utils/getPath\";\n\nexport interface AjvValidateOptions extends Record<string, any> {\n schema?: JsonSchema | Partial<JsonSchemaObject>;\n type?: Type<any> | any;\n collectionType?: Type<any> | any;\n}\n\n@Injectable()\nexport class AjvService {\n @Constant(\"ajv.errorFormatter\", defaultErrorFormatter)\n protected errorFormatter: ErrorFormatter;\n\n @Inject()\n protected ajv: Ajv;\n\n async validate(value: any, options: AjvValidateOptions | JsonSchema): Promise<any> {\n let {schema, type, collectionType, ...additionalOptions} = this.mapOptions(options);\n\n schema = schema || getJsonSchema(type, {...additionalOptions, customKeys: true});\n\n if (schema) {\n const localValue = deepClone(value);\n const valid = await this.ajv.validate(schema as any, localValue);\n if (!valid) {\n throw this.mapErrors(this.ajv.errors || [], {\n type,\n collectionType,\n async: true,\n value: localValue\n });\n }\n }\n\n return value;\n }\n\n protected mapOptions(options: AjvValidateOptions | JsonSchema): AjvValidateOptions {\n if (options instanceof JsonSchema) {\n return {\n schema: options.toJSON({customKeys: true})\n };\n }\n\n return options;\n }\n\n protected mapErrors(errors: ErrorObject[], options: any) {\n const {type, collectionType, value} = options;\n\n const message = errors\n .map((error: AjvErrorObject) => {\n if (collectionType) {\n error.collectionName = nameOf(collectionType);\n }\n\n const dataPath = getPath(error);\n\n if (!error.data) {\n if (dataPath) {\n error.data = getValue(value, dataPath.replace(/^\\./, \"\"));\n } else if (error.schemaPath !== \"#/required\") {\n error.data = value;\n }\n }\n\n if (dataPath && dataPath.match(/pwd|password|mdp|secret/)) {\n error.data = \"[REDACTED]\";\n }\n\n if (type) {\n error.modelName = nameOf(type);\n error.message = this.mapClassError(error, type);\n }\n\n return this.errorFormatter.call(this, error, {});\n })\n .join(\"\\n\");\n\n return new AjvValidationError(message, errors);\n }\n\n protected mapClassError(error: AjvErrorObject, targetType: Type<any>) {\n const propertyKey = getValue(error, \"params.missingProperty\");\n\n if (propertyKey) {\n const store = JsonEntityStore.from<JsonEntityStore>(prototypeOf(targetType), propertyKey);\n\n if (store) {\n setValue(error, \"params.missingProperty\", store.name || propertyKey);\n\n return error.message!.replace(`'${propertyKey}'`, `'${store.name || propertyKey}'`);\n }\n }\n\n return error.message;\n }\n}\n","import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {JsonSchema} from \"@tsed/schema\";\nimport {AnySchemaObject, KeywordDefinition} from \"ajv\";\n\nexport type KeywordOptions = Partial<Omit<KeywordDefinition, \"metaSchema\">> & {\n metaSchema?: AnySchemaObject | JsonSchema;\n};\n\n/**\n * Create new keyword custom validator\n * @param options\n * @decorator\n * @ajv\n */\nexport function Keyword(options: KeywordOptions): ClassDecorator {\n return useDecorators(\n Injectable({\n type: \"ajv:keyword\"\n }),\n StoreSet(\"ajv:keyword\", {\n ...options,\n metaSchema: options.metaSchema && options.metaSchema.toJSON ? options.metaSchema.toJSON() : options.metaSchema\n })\n );\n}\n","import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {AsyncFormatDefinition, FormatDefinition} from \"ajv\";\n\nexport type FormatsOptions = Omit<FormatDefinition<any>, \"validate\" | \"compare\"> | Omit<AsyncFormatDefinition<any>, \"validate\" | \"compare\">;\n\n/**\n * Create a new custom formats validator\n * @param name\n * @param options\n * @decorator\n * @ajv\n */\nexport function Formats(name: string, options: FormatsOptions = {}): ClassDecorator {\n return useDecorators(\n Injectable({\n type: \"ajv:formats\"\n }),\n StoreSet(\"ajv:formats\", {\n name,\n options\n })\n );\n}\n"],"names":["AjvValidationError","BadRequest","constructor","message","errors","getPath","error","getValue","replace","defaultErrorFormatter","value","JSON","stringify","data","undefined","join","list","filter","Boolean","trim","dataPath","indexPath","paths","split","deepPaths","length","collectionName","modelName","getHandler","key","service","bind","getKeywordProviders","injector","getProviders","bindKeywords","map","provider","options","store","get","invoke","token","cleanObject","validate","compile","code","macro","getFormatsProviders","getFormats","name","compare","registerProvider","provide","Ajv","deps","Configuration","InjectorService","scope","ProviderScope","SINGLETON","useFactory","configuration","keywords","props","verbose","coerceTypes","strict","ajv","AjvFormats","forEach","addFormat","AjvService","mapOptions","schema","type","collectionType","additionalOptions","getJsonSchema","customKeys","localValue","deepClone","valid","mapErrors","async","JsonSchema","toJSON","nameOf","schemaPath","match","mapClassError","errorFormatter","call","targetType","propertyKey","JsonEntityStore","from","prototypeOf","setValue","__decorate","Constant","Inject","Injectable","Keyword","useDecorators","StoreSet","metaSchema","Formats"],"mappings":";;;;;;;;;;;;;MAEaA,2BAA2BC;AAItCC,EAAAA,YAAYC,SAAiBC,SAAgB;AAC3C,UAAMD,OAAN;AAJK,aAAA,GAAe,sBAAf;AAKL,SAAKC,MAAL,GAAcA,MAAd;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SCPaC,QAAQC;AACtB,SAAOC,aAAQ,CAACD,KAAD,EAAQ,UAAR,EAAoBC,aAAQ,CAACD,KAAD,EAAQ,cAAR,EAAwB,EAAxB,CAA5B,CAAR,CAAiEE,OAAjE,CAAyE,MAAzE,EAAiF,GAAjF,CAAP;AACD;;SCDeC,sBAAsBH;AACpC,QAAMI,KAAK,GAAGC,IAAI,CAACC,SAAL,CAAeN,KAAK,CAACO,IAAN,KAAeC,SAAf,GAA2B,WAA3B,GAAyCR,KAAK,CAACO,IAA9D,CAAd;;AACA,QAAME,IAAI,GAAIC,IAAD,IAAyBA,IAAI,CAACC,MAAL,CAAYC,OAAZ,EAAqBH,IAArB,CAA0B,EAA1B,EAA8BI,IAA9B,EAAtC;;AAEAb,EAAAA,KAAK,CAACc,QAAN,GAAiBf,OAAO,CAACC,KAAD,CAAxB;AAEA,QAAM,GAAGe,SAAH,EAAc,GAAGC,KAAjB,IAA0BhB,KAAK,CAACc,QAAN,CAAeG,KAAf,CAAqB,GAArB,CAAhC;AACA,QAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,GAAe,MAAMH,KAAK,CAACP,IAAN,CAAW,GAAX,CAArB,GAAuC,EAAzD;;AAEA,MAAIT,KAAK,CAACoB,cAAV,EAA0B;AACxB,YAAQpB,KAAK,CAAC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