@tsed/ajv 8.9.5 → 8.10.0-rc.2

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.
@@ -0,0 +1,17 @@
1
+ import { useDecorators as o, StoreSet as e } from "@tsed/core";
2
+ import { Injectable as a } from "@tsed/di";
3
+ function s(r, t = {}) {
4
+ return o(
5
+ a({
6
+ type: "ajv:formats"
7
+ }),
8
+ e("ajv:formats", {
9
+ name: r,
10
+ options: t
11
+ })
12
+ );
13
+ }
14
+ export {
15
+ s as Formats
16
+ };
17
+ //# sourceMappingURL=formats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.js","sources":["../../../src/decorators/formats.ts"],"sourcesContent":["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":["Formats","name","options","useDecorators","Injectable","StoreSet"],"mappings":";;AAaO,SAASA,EAAQC,GAAcC,IAA0B,IAAoB;AAC3E,SAAAC;AAAA,IACLC,EAAW;AAAA,MACT,MAAM;AAAA,IAAA,CACP;AAAA,IACDC,EAAS,eAAe;AAAA,MACtB,MAAAJ;AAAA,MACA,SAAAC;AAAA,IACD,CAAA;AAAA,EACH;AACF;"}
@@ -0,0 +1,17 @@
1
+ import { useDecorators as a, StoreSet as m } from "@tsed/core";
2
+ import { Injectable as r } from "@tsed/di";
3
+ function c(e) {
4
+ return a(
5
+ r({
6
+ type: "ajv:keyword"
7
+ }),
8
+ m("ajv:keyword", {
9
+ ...e,
10
+ metaSchema: e.metaSchema && e.metaSchema.toJSON ? e.metaSchema.toJSON() : e.metaSchema
11
+ })
12
+ );
13
+ }
14
+ export {
15
+ c as Keyword
16
+ };
17
+ //# sourceMappingURL=keyword.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyword.js","sources":["../../../src/decorators/keyword.ts"],"sourcesContent":["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"],"names":["Keyword","options","useDecorators","Injectable","StoreSet"],"mappings":";;AAeO,SAASA,EAAQC,GAAyC;AACxD,SAAAC;AAAA,IACLC,EAAW;AAAA,MACT,MAAM;AAAA,IAAA,CACP;AAAA,IACDC,EAAS,eAAe;AAAA,MACtB,GAAGH;AAAA,MACH,YAAYA,EAAQ,cAAcA,EAAQ,WAAW,SAASA,EAAQ,WAAW,OAAO,IAAIA,EAAQ;AAAA,IACrG,CAAA;AAAA,EACH;AACF;"}
@@ -0,0 +1,10 @@
1
+ import { BadRequest as t } from "@tsed/exceptions";
2
+ class a extends t {
3
+ constructor(r, s = []) {
4
+ super(r), this.name = "AJV_VALIDATION_ERROR", this.errors = s;
5
+ }
6
+ }
7
+ export {
8
+ a as AjvValidationError
9
+ };
10
+ //# sourceMappingURL=AjvValidationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AjvValidationError.js","sources":["../../../src/errors/AjvValidationError.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"],"names":["AjvValidationError","BadRequest","message","errors"],"mappings":";AAEO,MAAMA,UAA2BC,EAAW;AAAA,EAIjD,YAAYC,GAAiBC,IAAgB,IAAI;AAC/C,UAAMD,CAAO,GAJf,KAAO,OAAe,wBAKpB,KAAK,SAASC;AAAA,EAAA;AAElB;"}
@@ -0,0 +1,17 @@
1
+ import { Formats as e } from "./decorators/formats.js";
2
+ import { Keyword as a } from "./decorators/keyword.js";
3
+ import { AjvValidationError as p } from "./errors/AjvValidationError.js";
4
+ import "./services/Ajv.js";
5
+ import { AjvService as i } from "./services/AjvService.js";
6
+ import { defaultErrorFormatter as n } from "./utils/defaultErrorFormatter.js";
7
+ import { getInstancePath as c, getPath as g } from "./utils/getPath.js";
8
+ export {
9
+ i as AjvService,
10
+ p as AjvValidationError,
11
+ e as Formats,
12
+ a as Keyword,
13
+ n as defaultErrorFormatter,
14
+ c as getInstancePath,
15
+ g as getPath
16
+ };
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -0,0 +1,57 @@
1
+ import { cleanObject as p } from "@tsed/core";
2
+ import { injectable as f, ProviderScope as v, constant as u, inject as c, injector as i } from "@tsed/di";
3
+ import { Ajv as s } from "/home/runner/work/tsed/tsed/node_modules/ajv/dist/ajv.js";
4
+ import j from "/home/runner/work/tsed/tsed/node_modules/ajv-errors/dist/index.js";
5
+ import l from "/home/runner/work/tsed/tsed/node_modules/ajv-formats/dist/index.js";
6
+ function a(r, o) {
7
+ if (o[r])
8
+ return o[r].bind(o);
9
+ }
10
+ function y() {
11
+ return i().getProviders("ajv:keyword");
12
+ }
13
+ function g() {
14
+ return y().map((r) => {
15
+ const o = r.store.get("ajv:keyword", {}), t = c(r.token);
16
+ return p({
17
+ coerceTypes: "array",
18
+ ...o,
19
+ validate: a("validate", t),
20
+ compile: a("compile", t),
21
+ code: a("code", t),
22
+ macro: a("macro", t)
23
+ });
24
+ });
25
+ }
26
+ function b() {
27
+ return i().getProviders("ajv:formats");
28
+ }
29
+ function w() {
30
+ return b().map((r) => {
31
+ var e;
32
+ const { name: o, options: t } = r.store.get("ajv:formats", {}), n = c(r.token);
33
+ return {
34
+ name: o,
35
+ options: {
36
+ ...t,
37
+ validate: n.validate.bind(n),
38
+ compare: (e = n.compare) == null ? void 0 : e.bind(n)
39
+ }
40
+ };
41
+ });
42
+ }
43
+ f(s).scope(v.SINGLETON).factory(() => {
44
+ const { errorFormatter: r, keywords: o = [], ...t } = u("ajv") || {}, n = {
45
+ verbose: !1,
46
+ coerceTypes: !0,
47
+ strict: !1,
48
+ keywords: [...o, ...g()],
49
+ discriminator: !0,
50
+ allErrors: !0,
51
+ ...t
52
+ }, e = new s(n);
53
+ return j(e), l(e), w().forEach(({ name: m, options: d }) => {
54
+ e.addFormat(m, d);
55
+ }), e;
56
+ });
57
+ //# sourceMappingURL=Ajv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ajv.js","sources":["../../../src/services/Ajv.ts"],"sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {constant, inject, injectable, injector, InjectorService, ProviderScope} from \"@tsed/di\";\nimport {Ajv, Format, KeywordDefinition, Options, Vocabulary} from \"ajv\";\nimport AjvErrors from \"ajv-errors\";\nimport AjvFormats from \"ajv-formats\";\n\nimport {FormatsMethods} from \"../interfaces/FormatsMethods.js\";\nimport {IAjvSettings} from \"../interfaces/IAjvSettings.js\";\n\nfunction getHandler(key: string, service: any) {\n if (service[key]) {\n return service[key].bind(service);\n }\n}\n\nfunction getKeywordProviders() {\n return injector().getProviders(\"ajv:keyword\");\n}\n\nfunction bindKeywords(): Vocabulary {\n return getKeywordProviders().map((provider) => {\n const options = provider.store.get<Omit<KeywordDefinition, \"compile\">>(\"ajv:keyword\", {})!;\n const service = inject(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() {\n return injector().getProviders(\"ajv:formats\");\n}\n\nfunction getFormats(): {name: string; options: Format}[] {\n return getFormatsProviders().map((provider) => {\n const {name, options} = provider.store.get<any>(\"ajv:formats\", {})!;\n const service = inject<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\ninjectable(Ajv)\n .scope(ProviderScope.SINGLETON)\n .factory(() => {\n const {errorFormatter, keywords = [], ...props} = constant<IAjvSettings>(\"ajv\") || {};\n const options: Options = {\n verbose: false,\n coerceTypes: true,\n strict: false,\n keywords: [...keywords, ...bindKeywords()],\n discriminator: true,\n allErrors: true,\n ...props\n };\n\n // @ts-ignore\n const ajv = new Ajv(options);\n\n // add support for custom error messages\n // @ts-ignore\n AjvErrors(ajv);\n // @ts-ignore\n AjvFormats(ajv as any);\n\n getFormats().forEach(({name, options}) => {\n ajv.addFormat(name, options);\n });\n\n return ajv;\n });\n"],"names":["getHandler","key","service","getKeywordProviders","injector","bindKeywords","provider","options","inject","cleanObject","getFormatsProviders","getFormats","name","_a","injectable","Ajv","ProviderScope","errorFormatter","keywords","props","constant","ajv","AjvErrors","AjvFormats"],"mappings":";;;;;AASA,SAASA,EAAWC,GAAaC,GAAc;AACzC,MAAAA,EAAQD,CAAG;AACb,WAAOC,EAAQD,CAAG,EAAE,KAAKC,CAAO;AAEpC;AAEA,SAASC,IAAsB;AACtB,SAAAC,EAAA,EAAW,aAAa,aAAa;AAC9C;AAEA,SAASC,IAA2B;AAClC,SAAOF,EAAoB,EAAE,IAAI,CAACG,MAAa;AAC7C,UAAMC,IAAUD,EAAS,MAAM,IAAwC,eAAe,CAAA,CAAE,GAClFJ,IAAUM,EAAOF,EAAS,KAAK;AAErC,WAA0BG,EAAY;AAAA,MACpC,aAAa;AAAA,MACb,GAAGF;AAAA,MACH,UAAUP,EAAW,YAAYE,CAAO;AAAA,MACxC,SAASF,EAAW,WAAWE,CAAO;AAAA,MACtC,MAAMF,EAAW,QAAQE,CAAO;AAAA,MAChC,OAAOF,EAAW,SAASE,CAAO;AAAA,IAAA,CACnC;AAAA,EAAA,CACF;AACH;AAEA,SAASQ,IAAsB;AACtB,SAAAN,EAAA,EAAW,aAAa,aAAa;AAC9C;AAEA,SAASO,IAAgD;AACvD,SAAOD,EAAoB,EAAE,IAAI,CAACJ,MAAa;;AACvC,UAAA,EAAC,MAAAM,GAAM,SAAAL,MAAWD,EAAS,MAAM,IAAS,eAAe,EAAE,GAC3DJ,IAAUM,EAA4BF,EAAS,KAAK;AAEnD,WAAA;AAAA,MACL,MAAAM;AAAA,MACA,SAAS;AAAA,QACP,GAAGL;AAAA,QACH,UAAUL,EAAQ,SAAS,KAAKA,CAAO;AAAA,QACvC,UAASW,IAAAX,EAAQ,YAAR,gBAAAW,EAAiB,KAAKX;AAAA,MAAO;AAAA,IAE1C;AAAA,EAAA,CACD;AACH;AAEAY,EAAWC,CAAG,EACX,MAAMC,EAAc,SAAS,EAC7B,QAAQ,MAAM;AACP,QAAA,EAAC,gBAAAC,GAAgB,UAAAC,IAAW,CAAC,GAAG,GAAGC,MAASC,EAAuB,KAAK,KAAK,CAAC,GAC9Eb,IAAmB;AAAA,IACvB,SAAS;AAAA,IACT,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,UAAU,CAAC,GAAGW,GAAU,GAAGb,GAAc;AAAA,IACzC,eAAe;AAAA,IACf,WAAW;AAAA,IACX,GAAGc;AAAA,EACL,GAGME,IAAM,IAAIN,EAAIR,CAAO;AAI3B,SAAAe,EAAUD,CAAG,GAEbE,EAAWF,CAAU,GAErBV,EAAA,EAAa,QAAQ,CAAC,EAAC,MAAAC,GAAM,SAAAL,QAAa;AACpC,IAAAc,EAAA,UAAUT,GAAML,CAAO;AAAA,EAAA,CAC5B,GAEMc;AACT,CAAC;"}
@@ -0,0 +1,65 @@
1
+ import "./Ajv.js";
2
+ import { deepClone as h, nameOf as p, getValue as u, prototypeOf as y, setValue as v } from "@tsed/core";
3
+ import { injectable as j, constant as d, inject as g } from "@tsed/di";
4
+ import { getJsonSchema as C, JsonSchema as E, JsonEntityStore as V } from "@tsed/schema";
5
+ import { Ajv as O } from "/home/runner/work/tsed/tsed/node_modules/ajv/dist/ajv.js";
6
+ import { AjvValidationError as S } from "../errors/AjvValidationError.js";
7
+ import { defaultErrorFormatter as w } from "../utils/defaultErrorFormatter.js";
8
+ import { getPath as P } from "../utils/getPath.js";
9
+ class A {
10
+ constructor() {
11
+ this.name = "ajv", this.errorFormatter = d("ajv.errorFormatter", w), this.returnsCoercedValues = d("ajv.returnsCoercedValues"), this.ajv = g(O);
12
+ }
13
+ async validate(t, i) {
14
+ let {
15
+ schema: a,
16
+ type: s,
17
+ collectionType: r,
18
+ returnsCoercedValues: m = this.returnsCoercedValues,
19
+ ...e
20
+ } = this.mapOptions(i);
21
+ const o = a || C(s, { ...e, customKeys: !0 });
22
+ if (o) {
23
+ const n = this.returnsCoercedValues ? t : h(t), c = this.ajv.compile(o), f = await c(n), { errors: l } = c;
24
+ if (!f && l)
25
+ throw this.mapErrors(l, {
26
+ type: s,
27
+ collectionType: r,
28
+ async: !0,
29
+ value: n
30
+ });
31
+ if (m)
32
+ return n;
33
+ }
34
+ return t;
35
+ }
36
+ mapOptions(t) {
37
+ return t instanceof E ? {
38
+ schema: t.toJSON({ customKeys: !0 })
39
+ } : t;
40
+ }
41
+ mapErrors(t, i) {
42
+ const { type: a, collectionType: s, value: r } = i, m = t.map((e) => {
43
+ s && (e.collectionName = p(s));
44
+ const o = P(e);
45
+ return e.data || (o ? e.data = u(r, o.replace(/^\./, "")) : e.schemaPath !== "#/required" && (e.data = r)), o && o.match(/pwd|password|mdp|secret/) && (e.data = "[REDACTED]"), a && (e.modelName = p(a), e.message = this.mapClassError(e, a)), this.errorFormatter.call(this, e, {});
46
+ }).join(`
47
+ `);
48
+ return new S(m, t);
49
+ }
50
+ mapClassError(t, i) {
51
+ var s;
52
+ const a = u(t, "params.missingProperty");
53
+ if (a) {
54
+ const r = V.from(y(i), a);
55
+ if (r)
56
+ return v(t, "params.missingProperty", r.name || a), (s = t.message) == null ? void 0 : s.replace(`'${a}'`, `'${r.name || a}'`);
57
+ }
58
+ return t.message;
59
+ }
60
+ }
61
+ j(A).type("validator:service");
62
+ export {
63
+ A as AjvService
64
+ };
65
+ //# sourceMappingURL=AjvService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AjvService.js","sources":["../../../src/services/AjvService.ts"],"sourcesContent":["import \"./Ajv.js\";\n\nimport {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\";\n\nimport {AjvValidationError} from \"../errors/AjvValidationError.js\";\nimport {AjvErrorObject, ErrorFormatter} from \"../interfaces/IAjvSettings.js\";\nimport {defaultErrorFormatter} from \"../utils/defaultErrorFormatter.js\";\nimport {getPath} from \"../utils/getPath.js\";\n\nexport interface AjvValidateOptions extends Record<string, any> {\n schema?: JsonSchema | Partial<JsonSchemaObject>;\n type?: Type<any> | any;\n collectionType?: Type<any> | any;\n returnsCoercedValues?: boolean;\n}\n\nexport class AjvService {\n readonly name = \"ajv\";\n protected errorFormatter = constant<ErrorFormatter>(\"ajv.errorFormatter\", defaultErrorFormatter);\n protected returnsCoercedValues = constant<boolean>(\"ajv.returnsCoercedValues\");\n protected ajv = inject(Ajv);\n\n async validate(value: any, options: AjvValidateOptions | JsonSchema): Promise<any> {\n let {\n schema: defaultSchema,\n type,\n collectionType,\n returnsCoercedValues = this.returnsCoercedValues,\n ...additionalOptions\n } = this.mapOptions(options);\n\n const schema = defaultSchema || getJsonSchema(type, {...additionalOptions, customKeys: true});\n\n if (schema) {\n const localValue = this.returnsCoercedValues ? value : deepClone(value);\n const validate = this.ajv.compile(schema);\n\n const valid = await validate(localValue);\n const {errors} = validate;\n\n if (!valid && errors) {\n throw this.mapErrors(errors, {\n type,\n collectionType,\n async: true,\n value: localValue\n });\n }\n\n if (returnsCoercedValues) {\n return localValue;\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\ninjectable(AjvService).type(\"validator:service\");\n"],"names":["AjvService","constant","defaultErrorFormatter","inject","Ajv","value","options","defaultSchema","type","collectionType","returnsCoercedValues","additionalOptions","schema","getJsonSchema","localValue","deepClone","validate","valid","errors","JsonSchema","message","error","nameOf","dataPath","getPath","getValue","AjvValidationError","targetType","propertyKey","store","JsonEntityStore","prototypeOf","setValue","_a","injectable"],"mappings":";;;;;;;;AAmBO,MAAMA,EAAW;AAAA,EAAjB,cAAA;AACL,SAAS,OAAO,OACN,KAAA,iBAAiBC,EAAyB,sBAAsBC,CAAqB,GACrF,KAAA,uBAAuBD,EAAkB,0BAA0B,GACnE,KAAA,MAAME,EAAOC,CAAG;AAAA,EAAA;AAAA,EAE1B,MAAM,SAASC,GAAYC,GAAwD;AAC7E,QAAA;AAAA,MACF,QAAQC;AAAA,MACR,MAAAC;AAAA,MACA,gBAAAC;AAAA,MACA,sBAAAC,IAAuB,KAAK;AAAA,MAC5B,GAAGC;AAAA,IAAA,IACD,KAAK,WAAWL,CAAO;AAErB,UAAAM,IAASL,KAAiBM,EAAcL,GAAM,EAAC,GAAGG,GAAmB,YAAY,IAAK;AAE5F,QAAIC,GAAQ;AACV,YAAME,IAAa,KAAK,uBAAuBT,IAAQU,EAAUV,CAAK,GAChEW,IAAW,KAAK,IAAI,QAAQJ,CAAM,GAElCK,IAAQ,MAAMD,EAASF,CAAU,GACjC,EAAC,QAAAI,MAAUF;AAEb,UAAA,CAACC,KAASC;AACN,cAAA,KAAK,UAAUA,GAAQ;AAAA,UAC3B,MAAAV;AAAA,UACA,gBAAAC;AAAA,UACA,OAAO;AAAA,UACP,OAAOK;AAAA,QAAA,CACR;AAGH,UAAIJ;AACK,eAAAI;AAAA,IACT;AAGK,WAAAT;AAAA,EAAA;AAAA,EAGC,WAAWC,GAA8D;AACjF,WAAIA,aAAmBa,IACd;AAAA,MACL,QAAQb,EAAQ,OAAO,EAAC,YAAY,GAAK,CAAA;AAAA,IAC3C,IAGKA;AAAA,EAAA;AAAA,EAGC,UAAUY,GAAuBZ,GAAc;AACvD,UAAM,EAAC,MAAAE,GAAM,gBAAAC,GAAgB,OAAAJ,EAAS,IAAAC,GAEhCc,IAAUF,EACb,IAAI,CAACG,MAA0B;AAC9B,MAAIZ,MACIY,EAAA,iBAAiBC,EAAOb,CAAc;AAGxC,YAAAc,IAAWC,EAAQH,CAAK;AAE1B,aAACA,EAAM,SACLE,IACFF,EAAM,OAAOI,EAASpB,GAAOkB,EAAS,QAAQ,OAAO,EAAE,CAAC,IAC/CF,EAAM,eAAe,iBAC9BA,EAAM,OAAOhB,KAIbkB,KAAYA,EAAS,MAAM,yBAAyB,MACtDF,EAAM,OAAO,eAGXb,MACIa,EAAA,YAAYC,EAAOd,CAAI,GAC7Ba,EAAM,UAAU,KAAK,cAAcA,GAAOb,CAAI,IAGzC,KAAK,eAAe,KAAK,MAAMa,GAAO,CAAA,CAAE;AAAA,IAAA,CAChD,EACA,KAAK;AAAA,CAAI;AAEL,WAAA,IAAIK,EAAmBN,GAASF,CAAM;AAAA,EAAA;AAAA,EAGrC,cAAcG,GAAuBM,GAAuB;;AAC9D,UAAAC,IAAcH,EAASJ,GAAO,wBAAwB;AAE5D,QAAIO,GAAa;AACf,YAAMC,IAAQC,EAAgB,KAAsBC,EAAYJ,CAAU,GAAGC,CAAW;AAExF,UAAIC;AACF,eAAAG,EAASX,GAAO,0BAA0BQ,EAAM,QAAQD,CAAW,IAE5DK,IAAAZ,EAAM,YAAN,gBAAAY,EAAe,QAAQ,IAAIL,CAAW,KAAK,IAAIC,EAAM,QAAQD,CAAW;AAAA,IACjF;AAGF,WAAOP,EAAM;AAAA,EAAA;AAEjB;AAEAa,EAAWlC,CAAU,EAAE,KAAK,mBAAmB;"}
@@ -0,0 +1,26 @@
1
+ import { getInstancePath as c, getPath as d } from "./getPath.js";
2
+ function p(a) {
3
+ var l, $;
4
+ const e = JSON.stringify(a.data === void 0 ? "undefined" : a.data), n = (t) => t.filter(Boolean).join("").trim(), [, s, ...m] = c(a).split("."), i = m.length ? "." + m.join(".") : "";
5
+ if (a.dataPath = d(a), a.collectionName) {
6
+ const t = a.modelName || "";
7
+ switch (a.collectionName) {
8
+ case "Array":
9
+ return n([`${t}[${s}]${i}`, ` ${a.message}. Given value: ${e}`]);
10
+ case "Map":
11
+ return n([`Map<${s}, ${t}>${i}`, ` ${a.message}. Given value: ${e}`]);
12
+ case "Set":
13
+ return n([`Set<${s}, ${t}>${i}`, ` ${a.message}. Given value: ${e}`]);
14
+ }
15
+ }
16
+ return n([
17
+ !a.modelName && "Value",
18
+ `${a.modelName || ""}`,
19
+ !((l = a == null ? void 0 : a.params) != null && l.missingProperty) && a.dataPath || (($ = a == null ? void 0 : a.params) == null ? void 0 : $.missingProperty) && (a.instancePath || "").replace(/\//g, "."),
20
+ ` ${a.message}. Given value: ${e}`
21
+ ]);
22
+ }
23
+ export {
24
+ p as defaultErrorFormatter
25
+ };
26
+ //# sourceMappingURL=defaultErrorFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultErrorFormatter.js","sources":["../../../src/utils/defaultErrorFormatter.ts"],"sourcesContent":["import {AjvErrorObject} from \"../interfaces/IAjvSettings.js\";\nimport {getInstancePath, getPath} from \"./getPath.js\";\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 const [, indexPath, ...paths] = getInstancePath(error).split(\".\");\n const deepPaths = paths.length ? \".\" + paths.join(\".\") : \"\";\n\n error.dataPath = getPath(error);\n\n if (error.collectionName) {\n const modelName = error.modelName || \"\";\n\n switch (error.collectionName) {\n case \"Array\":\n return join([`${modelName}[${indexPath}]${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Map\":\n return join([`Map<${indexPath}, ${modelName}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n case \"Set\":\n return join([`Set<${indexPath}, ${modelName}>${deepPaths}`, ` ${error.message}. Given value: ${value}`]);\n }\n }\n\n return join([\n !error.modelName && \"Value\",\n `${error.modelName || \"\"}`,\n (!error?.params?.missingProperty && error.dataPath) ||\n (error?.params?.missingProperty && (error.instancePath || \"\").replace(/\\//g, \".\")),\n ` ${error.message}. Given value: ${value}`\n ]);\n}\n"],"names":["defaultErrorFormatter","error","value","join","list","indexPath","paths","getInstancePath","deepPaths","getPath","modelName","_a","_b"],"mappings":";AAGO,SAASA,EAAsBC,GAA4C;;AAC1E,QAAAC,IAAQ,KAAK,UAAUD,EAAM,SAAS,SAAY,cAAcA,EAAM,IAAI,GAC1EE,IAAO,CAACC,MAAwBA,EAAK,OAAO,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,GAEnE,CAAG,EAAAC,GAAW,GAAGC,CAAK,IAAIC,EAAgBN,CAAK,EAAE,MAAM,GAAG,GAC1DO,IAAYF,EAAM,SAAS,MAAMA,EAAM,KAAK,GAAG,IAAI;AAIzD,MAFML,EAAA,WAAWQ,EAAQR,CAAK,GAE1BA,EAAM,gBAAgB;AAClB,UAAAS,IAAYT,EAAM,aAAa;AAErC,YAAQA,EAAM,gBAAgB;AAAA,MAC5B,KAAK;AACH,eAAOE,EAAK,CAAC,GAAGO,CAAS,IAAIL,CAAS,IAAIG,CAAS,IAAI,IAAIP,EAAM,OAAO,kBAAkBC,CAAK,EAAE,CAAC;AAAA,MACpG,KAAK;AACH,eAAOC,EAAK,CAAC,OAAOE,CAAS,KAAKK,CAAS,IAAIF,CAAS,IAAI,IAAIP,EAAM,OAAO,kBAAkBC,CAAK,EAAE,CAAC;AAAA,MACzG,KAAK;AACH,eAAOC,EAAK,CAAC,OAAOE,CAAS,KAAKK,CAAS,IAAIF,CAAS,IAAI,IAAIP,EAAM,OAAO,kBAAkBC,CAAK,EAAE,CAAC;AAAA,IAAA;AAAA,EAC3G;AAGF,SAAOC,EAAK;AAAA,IACV,CAACF,EAAM,aAAa;AAAA,IACpB,GAAGA,EAAM,aAAa,EAAE;AAAA,IACvB,GAACU,IAAAV,KAAA,gBAAAA,EAAO,WAAP,QAAAU,EAAe,oBAAmBV,EAAM,cACvCW,IAAAX,KAAA,gBAAAA,EAAO,WAAP,gBAAAW,EAAe,qBAAoBX,EAAM,gBAAgB,IAAI,QAAQ,OAAO,GAAG;AAAA,IAClF,IAAIA,EAAM,OAAO,kBAAkBC,CAAK;AAAA,EAAA,CACzC;AACH;"}
@@ -0,0 +1,12 @@
1
+ import { getValue as a } from "@tsed/core";
2
+ function i(t) {
3
+ return t.params && t.params.missingProperty ? `.${t.params.missingProperty}` : n(t);
4
+ }
5
+ function n(t) {
6
+ return a(t, "dataPath", a(t, "instancePath", "")).replace(/\//gi, ".");
7
+ }
8
+ export {
9
+ n as getInstancePath,
10
+ i as getPath
11
+ };
12
+ //# sourceMappingURL=getPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPath.js","sources":["../../../src/utils/getPath.ts"],"sourcesContent":["import {getValue} from \"@tsed/core\";\n\nexport function getPath(error: any) {\n if (error.params && error.params.missingProperty) {\n return `.${error.params.missingProperty}`;\n }\n\n return getInstancePath(error);\n}\n\nexport function getInstancePath(error: any) {\n return getValue(error, \"dataPath\", getValue(error, \"instancePath\", \"\")).replace(/\\//gi, \".\");\n}\n"],"names":["getPath","error","getInstancePath","getValue"],"mappings":";AAEO,SAASA,EAAQC,GAAY;AAClC,SAAIA,EAAM,UAAUA,EAAM,OAAO,kBACxB,IAAIA,EAAM,OAAO,eAAe,KAGlCC,EAAgBD,CAAK;AAC9B;AAEO,SAASC,EAAgBD,GAAY;AACnC,SAAAE,EAASF,GAAO,YAAYE,EAASF,GAAO,gBAAgB,EAAE,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAC7F;"}
package/package.json CHANGED
@@ -2,17 +2,17 @@
2
2
  "name": "@tsed/ajv",
3
3
  "description": "AJV package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.9.5",
5
+ "version": "8.10.0-rc.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
10
- "browser": "./lib/browser/ajv.umd.min.js",
10
+ "browser": "./lib/browser/index.js",
11
11
  "exports": {
12
12
  ".": {
13
13
  "tsed-source": "./src/index.ts",
14
14
  "types": "./lib/types/index.d.ts",
15
- "browser": "./lib/browser/ajv.umd.min.js",
15
+ "browser": "./lib/browser/index.js",
16
16
  "import": "./lib/esm/index.js",
17
17
  "default": "./lib/esm/index.js"
18
18
  }
@@ -20,7 +20,7 @@
20
20
  "scripts": {
21
21
  "clean": "rm -rf lib",
22
22
  "build": "yarn clean && yarn barrels && yarn build:ts && yarn run build:browser",
23
- "build:browser": "webpack",
23
+ "build:browser": "vite build",
24
24
  "barrels": "barrels",
25
25
  "test": "vitest run",
26
26
  "build:ts": "tsc --build tsconfig.esm.json",
@@ -32,23 +32,23 @@
32
32
  "tslib": "2.7.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsed/barrels": "8.9.5",
36
- "@tsed/core": "8.9.5",
37
- "@tsed/di": "8.9.5",
38
- "@tsed/exceptions": "8.9.5",
39
- "@tsed/schema": "8.9.5",
40
- "@tsed/typescript": "8.9.5",
35
+ "@tsed/barrels": "8.10.0-rc.2",
36
+ "@tsed/core": "8.10.0-rc.2",
37
+ "@tsed/di": "8.10.0-rc.2",
38
+ "@tsed/exceptions": "8.10.0-rc.2",
39
+ "@tsed/schema": "8.10.0-rc.2",
40
+ "@tsed/typescript": "8.10.0-rc.2",
41
41
  "ajv": "^8.17.1",
42
42
  "eslint": "9.12.0",
43
43
  "typescript": "5.4.5",
44
- "vitest": "3.1.4",
45
- "webpack": "^5.75.0"
44
+ "vite": "6.2.2",
45
+ "vitest": "3.1.4"
46
46
  },
47
47
  "peerDependencies": {
48
- "@tsed/core": ">=8.9.5",
49
- "@tsed/di": ">=8.9.5",
50
- "@tsed/exceptions": ">=8.9.5",
51
- "@tsed/schema": ">=8.9.5",
48
+ "@tsed/core": ">=8.0.0",
49
+ "@tsed/di": ">=8.0.0",
50
+ "@tsed/exceptions": ">=8.0.0",
51
+ "@tsed/schema": ">=8.0.0",
52
52
  "ajv": ">=8.9.0",
53
53
  "ajv-errors": ">=3.0.0"
54
54
  },
@@ -72,5 +72,8 @@
72
72
  },
73
73
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/specs/ajv",
74
74
  "author": "Romain Lenzotti",
75
- "license": "MIT"
75
+ "license": "MIT",
76
+ "publishConfig": {
77
+ "tag": "rc"
78
+ }
76
79
  }
@@ -0,0 +1,45 @@
1
+ import {defineConfig} from "vite";
2
+ import {join} from "node:path";
3
+ import {extname, relative} from "path";
4
+ import {fileURLToPath} from "node:url";
5
+ import {globbySync} from "globby";
6
+
7
+ // https://vitejs.dev/config/
8
+ export default defineConfig({
9
+ plugins: [],
10
+ build: {
11
+ assetsInlineLimit: 0,
12
+ sourcemap: true,
13
+ outDir: "lib/browser",
14
+ lib: {
15
+ entry: join(import.meta.dirname, "src/index.ts"),
16
+ formats: ["es"]
17
+ },
18
+ rollupOptions: {
19
+ external: [/node_modules\/(.*)/, /^@tsed\//],
20
+ input: Object.fromEntries(
21
+ globbySync("src/**/*.ts", {
22
+ ignore: [
23
+ "**/*.spec.{ts,tsx}",
24
+ "**/*.stories.{ts,tsx}",
25
+ "**/__mocks__/**",
26
+ "**/__mock__/**",
27
+ "**/interfaces/**"
28
+ ]
29
+ }).map((file) => [
30
+ // The name of the entry point
31
+ // lib/nested/foo.ts becomes nested/foo
32
+ relative("src", file.slice(0, file.length - extname(file).length)),
33
+ // The absolute path to the entry file
34
+ // lib/nested/foo.ts becomes /project/lib/nested/foo.ts
35
+ fileURLToPath(new URL(file, import.meta.url))
36
+ ])
37
+ ),
38
+ output: {
39
+ assetFileNames: "assets/[name][extname]",
40
+ chunkFileNames: "chunks/[name].js",
41
+ entryFileNames: "[name].js"
42
+ }
43
+ }
44
+ }
45
+ });