@tsed/ajv 7.0.0-beta.3 → 7.0.0-beta.6

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/lib/cjs/index.js CHANGED
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./errors/AjvValidationError"), exports);
5
- (0, tslib_1.__exportStar)(require("./services/AjvService"), exports);
6
- (0, tslib_1.__exportStar)(require("./services/Ajv"), exports);
7
- (0, tslib_1.__exportStar)(require("./decorators/keyword"), exports);
8
- (0, tslib_1.__exportStar)(require("./interfaces/KeywordMethods"), exports);
9
- (0, tslib_1.__exportStar)(require("./decorators/formats"), exports);
10
- (0, tslib_1.__exportStar)(require("./interfaces/FormatsMethods"), exports);
7
+ tslib_1.__exportStar(require("./decorators/formats"), exports);
8
+ tslib_1.__exportStar(require("./decorators/keyword"), exports);
9
+ tslib_1.__exportStar(require("./errors/AjvValidationError"), exports);
10
+ tslib_1.__exportStar(require("./interfaces/FormatsMethods"), exports);
11
+ tslib_1.__exportStar(require("./interfaces/IAjvSettings"), exports);
12
+ tslib_1.__exportStar(require("./interfaces/KeywordMethods"), exports);
13
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
14
+ tslib_1.__exportStar(require("./services/Ajv"), exports);
15
+ tslib_1.__exportStar(require("./services/AjvService"), exports);
16
+ tslib_1.__exportStar(require("./utils/defaultErrorFormatter"), exports);
17
+ tslib_1.__exportStar(require("./utils/getPath"), exports);
11
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,2EAA4C;AAC5C,qEAAsC;AACtC,8DAA+B;AAC/B,oEAAqC;AACrC,2EAA4C;AAC5C,oEAAqC;AACrC,2EAA4C","sourcesContent":["export * from \"./errors/AjvValidationError\";\nexport * from \"./services/AjvService\";\nexport * from \"./services/Ajv\";\nexport * from \"./decorators/keyword\";\nexport * from \"./interfaces/KeywordMethods\";\nexport * from \"./decorators/formats\";\nexport * from \"./interfaces/FormatsMethods\";\n\nimport {IAjvSettings} from \"./interfaces/IAjvSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n // @ts-ignore\n ajv?: IAjvSettings;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+DAAqC;AACrC,+DAAqC;AACrC,sEAA4C;AAC5C,sEAA4C;AAC5C,oEAA0C;AAC1C,sEAA4C;AAC5C,kEAAwC;AACxC,yDAA+B;AAC/B,gEAAsC;AACtC,wEAA8C;AAC9C,0DAAgC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/formats\";\nexport * from \"./decorators/keyword\";\nexport * from \"./errors/AjvValidationError\";\nexport * from \"./interfaces/FormatsMethods\";\nexport * from \"./interfaces/IAjvSettings\";\nexport * from \"./interfaces/KeywordMethods\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/Ajv\";\nexport * from \"./services/AjvService\";\nexport * from \"./utils/defaultErrorFormatter\";\nexport * from \"./utils/getPath\";\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {IAjvSettings} from \"./IAjvSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n // @ts-ignore\n ajv?: IAjvSettings;\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const core_1 = require("@tsed/core");
5
5
  const di_1 = require("@tsed/di");
6
- const ajv_1 = (0, tslib_1.__importDefault)(require("ajv"));
7
- const ajv_formats_1 = (0, tslib_1.__importDefault)(require("ajv-formats"));
6
+ const ajv_1 = tslib_1.__importDefault(require("ajv"));
7
+ const ajv_formats_1 = tslib_1.__importDefault(require("ajv-formats"));
8
8
  function getHandler(key, service) {
9
9
  if (service[key]) {
10
10
  return service[key].bind(service);
@@ -18,6 +18,7 @@ function bindKeywords(injector) {
18
18
  const options = provider.store.get("ajv:keyword", {});
19
19
  const service = injector.invoke(provider.token);
20
20
  return (0, core_1.cleanObject)({
21
+ coerceTypes: "array",
21
22
  ...options,
22
23
  validate: getHandler("validate", service),
23
24
  compile: getHandler("compile", service),
@@ -1 +1 @@
1
- {"version":3,"file":"Ajv.js","sourceRoot":"","sources":["../../../src/services/Ajv.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,iCAAyF;AACzF,2DAA+D;AAC/D,2EAAqC;AAIrC,SAAS,UAAU,CAAC,GAAW,EAAE,OAAY;IAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE;QAChB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACnC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAyB;IACpD,OAAO,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,YAAY,CAAC,QAAyB;IAC7C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAqC,aAAa,EAAE,EAAE,CAAE,CAAC;QAC3F,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK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GAAG,KAAK,EAAC,GAAG,aAAa,CAAC,GAAG,CAAe,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/F,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YAClD,GAAG,KAAK;SACT,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAA,qBAAU,EAAC,GAAU,CAAC,CAAC;QAEvB,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,EAAE,EAAE;YAC/C,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC","sourcesContent":["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"]}
1
+ {"version":3,"file":"Ajv.js","sourceRoot":"","sources":["../../../src/services/Ajv.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,iCAAyF;AACzF,sDAA+D;AAC/D,sEAAqC;AAIrC,SAAS,UAAU,CAAC,GAAW,EAAE,OAAY;IAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE;QAChB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACnC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAyB;IACpD,OAAO,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,YAAY,CAAC,QAAyB;IAC7C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAqC,aAAa,E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,kBAAa,CAAC,SAAS;IAC9B,UAAU,CAAC,aAA4B,EAAE,QAAyB;QAChE,MAAM,EAAC,cAAc,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,KAAK,EAAC,GAAG,aAAa,CAAC,GAAG,CAAe,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/F,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YAClD,GAAG,KAAK;SACT,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAA,qBAAU,EAAC,GAAU,CAAC,CAAC;QAEvB,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,EAAE,EAAE;YAC/C,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC","sourcesContent":["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 coerceTypes: \"array\",\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"]}
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const core_1 = require("@tsed/core");
6
6
  const di_1 = require("@tsed/di");
7
7
  const schema_1 = require("@tsed/schema");
8
- const ajv_1 = (0, tslib_1.__importDefault)(require("ajv"));
8
+ const ajv_1 = tslib_1.__importDefault(require("ajv"));
9
9
  const AjvValidationError_1 = require("../errors/AjvValidationError");
10
10
  const defaultErrorFormatter_1 = require("../utils/defaultErrorFormatter");
11
11
  require("./Ajv");
@@ -76,15 +76,15 @@ let AjvService = class AjvService {
76
76
  return error.message;
77
77
  }
78
78
  };
79
- (0, tslib_1.__decorate)([
79
+ tslib_1.__decorate([
80
80
  (0, di_1.Constant)("ajv.errorFormatter", defaultErrorFormatter_1.defaultErrorFormatter),
81
- (0, tslib_1.__metadata)("design:type", Function)
81
+ tslib_1.__metadata("design:type", Function)
82
82
  ], AjvService.prototype, "errorFormatter", void 0);
83
- (0, tslib_1.__decorate)([
83
+ tslib_1.__decorate([
84
84
  (0, di_1.Inject)(),
85
- (0, tslib_1.__metadata)("design:type", ajv_1.default)
85
+ tslib_1.__metadata("design:type", ajv_1.default)
86
86
  ], AjvService.prototype, "ajv", void 0);
87
- AjvService = (0, tslib_1.__decorate)([
87
+ AjvService = tslib_1.__decorate([
88
88
  (0, di_1.Injectable)()
89
89
  ], AjvService);
90
90
  exports.AjvService = AjvService;
@@ -1 +1 @@
1
- {"version":3,"file":"AjvService.js","sourceRoot":"","sources":["../../../src/services/AjvService.ts"],"names":[],"mappings":";;;;AAAA,qCAAoF;AACpF,iCAAsD;AACtD,yCAA0F;AAC1F,2DAAqC;AACrC,qEAAgE;AAEhE,0EAAqE;AACrE,iBAAe;AACf,8CAAyC;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,IAAA,sBAAa,EAAC,IAAI,EAAE,EAAC,GAAG,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAC;QAEjF,IAAI,MAAM,EAAE;YACV,MAAM,UAAU,GAAG,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAa,EAAE,UAAU,CAAC,CAAC;YACjE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;gBAC7B,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CA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;gBAC/B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;aACjD;YAED,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO,IAAI,uCAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;IAES,aAAa,CAAC,KAAqB,EAAE,UAAqB;QAClE,MAAM,WAAW,GAAG,IAAA,eAAQ,EAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;QAE9D,IAAI,WAAW,EAAE;YACf,MAAM,KAAK,GAAG,wBAAe,CAAC,IAAI,CAAkB,IAAA,kBAAW,EAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC;YAE1F,IAAI,KAAK,EAAE;gBACT,IAAA,eAAQ,EAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC;gBAErE,OAAO,KAAK,CAAC,OAAQ,CAAC,OAAO,CAAC,IAAI,WAAW,GAAG,EAAE,IAAI,KAAK,CAAC,IAAI,IAAI,WAAW,GAAG,CAAC,CAAC;aACrF;SACF;QAED,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;CACF,CAAA;AAtFC;IADC,IAAA,aAAQ,EAAC,oBAAoB,EAAE,6CAAqB,CAAC;;kDACb;AAGzC;IADC,IAAA,WAAM,GAAE;2CACM,aAAG;uCAAC;AALR,UAAU;IADtB,IAAA,eAAU,GAAE;GACA,UAAU,CAwFtB;AAxFY,gCAAU","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"]}
1
+ {"version":3,"file":"AjvService.js","sourceRoot":"","sources":["../../../src/services/AjvService.ts"],"names":[],"mappings":";;;;AAAA,qCAAoF;AACpF,iCAAsD;AACtD,yCAA0F;AAC1F,sDAAqC;AACrC,qEAAgE;AAEhE,0EAAqE;AACrE,iBAAe;AACf,8CAAyC;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,IAAA,sBAAa,EAAC,IAAI,EAAE,EAAC,GAAG,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC,CAAC;QAEjF,IAAI,MAAM,EAAE;YACV,MAAM,UAAU,GAAG,IAAA,gBAAS,EAAC,KAAK,CAAC,CAAC;YACpC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAa,EAAE,UAAU,CAAC,CAAC;YACjE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;gBAC7B,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE;oBAC1C,IAAI;oBACJ,cAAc;oBACd,KAAK,EAAE,IAAI;oBACX,KAAK,EAAE,UAAU;iBAClB,CAAC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,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO,IAAI,uCAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;IAES,aAAa,CAAC,KAAqB,EAAE,UAAqB;QAClE,MAAM,WAAW,GAAG,IAAA,eAAQ,EAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;QAE9D,IAAI,WAAW,EAAE;YACf,MAAM,KAAK,GAAG,wBAAe,CAAC,IAAI,CAAkB,IAAA,kBAAW,EAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC;YAE1F,IAAI,KAAK,EAAE;gBACT,IAAA,eAAQ,EAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC;gBAErE,OAAO,KAAK,CAAC,OAAQ,CAAC,OAAO,CAAC,IAAI,WAAW,GAAG,EAAE,IAAI,KAAK,CAAC,IAAI,IAAI,WAAW,GAAG,CAAC,CAAC;aACrF;SACF;QAED,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;CACF,CAAA;AAtFC;IADC,IAAA,aAAQ,EAAC,oBAAoB,EAAE,6CAAqB,CAAC;;kDACb;AAGzC;IADC,IAAA,WAAM,GAAE;sCACM,aAAG;uCAAC;AALR,UAAU;IADtB,IAAA,eAAU,GAAE;GACA,UAAU,CAwFtB;AAxFY,gCAAU","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"]}
package/lib/esm/index.js CHANGED
@@ -1,8 +1,15 @@
1
- export * from "./errors/AjvValidationError";
2
- export * from "./services/AjvService";
3
- export * from "./services/Ajv";
4
- export * from "./decorators/keyword";
5
- export * from "./interfaces/KeywordMethods";
6
- export * from "./decorators/formats";
7
- export * from "./interfaces/FormatsMethods";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./decorators/formats.js";
5
+ export * from "./decorators/keyword.js";
6
+ export * from "./errors/AjvValidationError.js";
7
+ export * from "./interfaces/FormatsMethods.js";
8
+ export * from "./interfaces/IAjvSettings.js";
9
+ export * from "./interfaces/KeywordMethods.js";
10
+ export * from "./interfaces/interfaces.js";
11
+ export * from "./services/Ajv.js";
12
+ export * from "./services/AjvService.js";
13
+ export * from "./utils/defaultErrorFormatter.js";
14
+ export * from "./utils/getPath.js";
8
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC","sourcesContent":["export * from \"./errors/AjvValidationError\";\nexport * from \"./services/AjvService\";\nexport * from \"./services/Ajv\";\nexport * from \"./decorators/keyword\";\nexport * from \"./interfaces/KeywordMethods\";\nexport * from \"./decorators/formats\";\nexport * from \"./interfaces/FormatsMethods\";\n\nimport {IAjvSettings} from \"./interfaces/IAjvSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n // @ts-ignore\n ajv?: IAjvSettings;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iBAAiB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./decorators/formats\";\nexport * from \"./decorators/keyword\";\nexport * from \"./errors/AjvValidationError\";\nexport * from \"./interfaces/FormatsMethods\";\nexport * from \"./interfaces/IAjvSettings\";\nexport * from \"./interfaces/KeywordMethods\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/Ajv\";\nexport * from \"./services/AjvService\";\nexport * from \"./utils/defaultErrorFormatter\";\nexport * from \"./utils/getPath\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {IAjvSettings} from \"./IAjvSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n // @ts-ignore\n ajv?: IAjvSettings;\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -15,6 +15,7 @@ function bindKeywords(injector) {
15
15
  const options = provider.store.get("ajv:keyword", {});
16
16
  const service = injector.invoke(provider.token);
17
17
  return cleanObject({
18
+ coerceTypes: "array",
18
19
  ...options,
19
20
  validate: getHandler("validate", service),
20
21
  compile: getHandler("compile", service),
@@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,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,EAAE,EAAE;YAC/C,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC","sourcesContent":["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"]}
1
+ {"version":3,"file":"Ajv.js","sourceRoot":"","sources":["../../../src/services/Ajv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACzF,OAAO,GAA4C,MAAM,KAAK,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;AAIrC,SAAS,UAAU,CAAC,GAAW,EAAE,OAAY;IAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE;QAChB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACnC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAyB;IACpD,OAAO,QAAQ,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,YAAY,CAAC,QAAyB;IAC7C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAqC,aAAa,EAAE,EAAE,CAAE,CAAC;QAC3F,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEhD,OAA0B,WAAW,CAAC;YACpC,WAAW,EAAE,OAAO;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC;YACzC,OAAO,EAAE,UAAU,CAAC,SAAS,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E,KAAK;YACb,QAAQ,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YAClD,GAAG,KAAK;SACT,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAE7B,UAAU,CAAC,GAAU,CAAC,CAAC;QAEvB,UAAU,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,EAAE,EAAE;YAC/C,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC,CAAC","sourcesContent":["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 coerceTypes: \"array\",\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"]}
@@ -3,10 +3,10 @@ import { deepClone, getValue, nameOf, prototypeOf, setValue } from "@tsed/core";
3
3
  import { Constant, Inject, Injectable } from "@tsed/di";
4
4
  import { getJsonSchema, JsonEntityStore, JsonSchema } from "@tsed/schema";
5
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";
6
+ import { AjvValidationError } from "../errors/AjvValidationError.js";
7
+ import { defaultErrorFormatter } from "../utils/defaultErrorFormatter.js";
8
+ import "./Ajv.js";
9
+ import { getPath } from "../utils/getPath.js";
10
10
  let AjvService = class AjvService {
11
11
  async validate(value, options) {
12
12
  let { schema, type, collectionType, ...additionalOptions } = this.mapOptions(options);
@@ -1,4 +1,4 @@
1
- import { getPath } from "./getPath";
1
+ import { getPath } from "./getPath.js";
2
2
  export function defaultErrorFormatter(error) {
3
3
  const value = JSON.stringify(error.data === undefined ? "undefined" : error.data);
4
4
  const join = (list) => list.filter(Boolean).join("").trim();
@@ -1,15 +1,14 @@
1
- export * from "./errors/AjvValidationError";
2
- export * from "./services/AjvService";
3
- export * from "./services/Ajv";
4
- export * from "./decorators/keyword";
5
- export * from "./interfaces/KeywordMethods";
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
6
4
  export * from "./decorators/formats";
5
+ export * from "./decorators/keyword";
6
+ export * from "./errors/AjvValidationError";
7
7
  export * from "./interfaces/FormatsMethods";
8
- import { IAjvSettings } from "./interfaces/IAjvSettings";
9
- declare global {
10
- namespace TsED {
11
- interface Configuration {
12
- ajv?: IAjvSettings;
13
- }
14
- }
15
- }
8
+ export * from "./interfaces/IAjvSettings";
9
+ export * from "./interfaces/KeywordMethods";
10
+ export * from "./interfaces/interfaces";
11
+ export * from "./services/Ajv";
12
+ export * from "./services/AjvService";
13
+ export * from "./utils/defaultErrorFormatter";
14
+ export * from "./utils/getPath";
@@ -0,0 +1,8 @@
1
+ import { IAjvSettings } from "./IAjvSettings";
2
+ declare global {
3
+ namespace TsED {
4
+ interface Configuration {
5
+ ajv?: IAjvSettings;
6
+ }
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@tsed/ajv",
3
- "version": "7.0.0-beta.3",
3
+ "version": "7.0.0-beta.6",
4
4
  "description": "AJV package for Ts.ED framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/cjs/index.js",
7
+ "module": "./lib/esm/index.js",
7
8
  "typings": "./lib/types/index.d.ts",
8
9
  "exports": {
9
10
  "types": "./lib/types/index.d.ts",
@@ -12,33 +13,48 @@
12
13
  "default": "./lib/esm/index.js"
13
14
  },
14
15
  "scripts": {
15
- "build": "yarn run build:esm && yarn run build:cjs",
16
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
16
17
  "build:cjs": "tsc --build tsconfig.compile.json",
17
- "build:esm": "tsc --build tsconfig.compile.esm.json"
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
19
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\""
18
20
  },
19
21
  "dependencies": {
20
- "ajv-formats": "1.5.1",
21
- "tslib": "2.2.0"
22
+ "ajv-formats": "2.1.1",
23
+ "tslib": "2.3.1"
22
24
  },
23
25
  "devDependencies": {
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",
28
- "ajv": "8.6.0"
26
+ "@tsed/core": "7.0.0-beta.6",
27
+ "@tsed/di": "7.0.0-beta.6",
28
+ "@tsed/exceptions": "7.0.0-beta.6",
29
+ "@tsed/schema": "7.0.0-beta.6",
30
+ "ajv": "8.11.0"
29
31
  },
30
32
  "peerDependencies": {
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",
35
- "ajv": "7||8"
33
+ "@tsed/core": "^7.0.0-beta.6",
34
+ "@tsed/di": "^7.0.0-beta.6",
35
+ "@tsed/exceptions": "^7.0.0-beta.6",
36
+ "@tsed/schema": "^7.0.0-beta.6",
37
+ "ajv": ">=8.9.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@tsed/core": {
41
+ "optional": false
42
+ },
43
+ "@tsed/di": {
44
+ "optional": false
45
+ },
46
+ "@tsed/exceptions": {
47
+ "optional": false
48
+ },
49
+ "@tsed/schema": {
50
+ "optional": false
51
+ }
36
52
  },
37
53
  "repository": "https://github.com/tsedio/tsed",
38
54
  "bugs": {
39
55
  "url": "https://github.com/tsedio/tsed/issues"
40
56
  },
41
- "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/specs/ajv",
57
+ "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/ajv",
42
58
  "author": "Romain Lenzotti",
43
59
  "license": "MIT"
44
60
  }
package/readme.md CHANGED
@@ -32,12 +32,8 @@ Then import `@tsed/ajv` in your Server:
32
32
  import {Configuration} from "@tsed/common";
33
33
  import "@tsed/ajv"; // import ajv ts.ed module
34
34
 
35
- @Configuration({
36
- rootDir: __dirname
37
- })
38
- export class Server {
39
-
40
- }
35
+ @Configuration({})
36
+ export class Server {}
41
37
  ```
42
38
 
43
39
  ### Decorators
@@ -53,39 +49,37 @@ be validated by Ajv.
53
49
  import {Required, MaxLength, MinLength, Minimum, Maximum, Format, Enum, Pattern, Email} from "@tsed/common";
54
50
 
55
51
  export class CalendarModel {
56
-
57
- @MaxLength(20)
58
- @MinLength(3)
59
- @Required()
60
- title: string;
61
-
62
- @Minimum(0)
63
- @Maximum(10)
64
- rating: number;
65
-
66
- @Email()
67
- email: string;
68
-
69
- @Format("date") // or date-time, etc...
70
- createDate: Date;
71
-
72
- @Pattern(/hello/)
73
- customInput: string;
74
-
75
- @Enum("value1", "value2")
76
- customInput: "value1" | "value2";
52
+ @MaxLength(20)
53
+ @MinLength(3)
54
+ @Required()
55
+ title: string;
56
+
57
+ @Minimum(0)
58
+ @Maximum(10)
59
+ rating: number;
60
+
61
+ @Email()
62
+ email: string;
63
+
64
+ @Format("date") // or date-time, etc...
65
+ createDate: Date;
66
+
67
+ @Pattern(/hello/)
68
+ customInput: string;
69
+
70
+ @Enum("value1", "value2")
71
+ customInput: "value1" | "value2";
77
72
  }
78
73
  ```
79
74
 
80
75
  > All validation decorators are compatible with the Swagger documentation.
81
76
 
82
-
83
77
  ## Error configuration
84
78
 
85
79
  The AJV module allows a few settings to be added through the ServerSettings (all are optional):
86
80
 
87
- * *options*, are AJV specific options passed directly to the AJV constructor,
88
- * *errorFormatter*, can be used to alter the output produced by the @tsed/ajv package.
81
+ - _options_, are AJV specific options passed directly to the AJV constructor,
82
+ - _errorFormatter_, can be used to alter the output produced by the @tsed/ajv package.
89
83
 
90
84
  The error message could be changed like:
91
85
 
@@ -94,24 +88,20 @@ import {Configuration} from "@tsed/common";
94
88
  import "@tsed/ajv"; // import ajv ts.ed module
95
89
 
96
90
  @Configuration({
97
- rootDir: __dirname,
98
- ajv: {
99
- errorFormatter: (error) => `At ${error.modelName}${error.dataPath}, value '${error.data}' ${error.message}`,
100
- options: {verbose: true}
101
- },
91
+ ajv: {
92
+ errorFormatter: (error) => `At ${error.modelName}${error.dataPath}, value '${error.data}' ${error.message}`,
93
+ options: {verbose: true}
94
+ }
102
95
  })
103
- export class Server {
104
-
105
- }
96
+ export class Server {}
106
97
  ```
107
98
 
108
-
109
99
  ## Contributors
100
+
110
101
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
111
102
 
112
103
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
113
104
 
114
-
115
105
  ## Backers
116
106
 
117
107
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
@@ -8,16 +8,5 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
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
- ]
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
23
12
  }