Socket
Socket
Sign inDemoInstall

@tsed/json-mapper

Package Overview
Dependencies
Maintainers
0
Versions
789
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsed/json-mapper - npm Package Compare versions

Comparing version 7.82.2 to 7.82.3

2

lib/browser/json-mapper.umd.min.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@tsed/core"),require("@tsed/schema")):"function"==typeof define&&define.amd?define(["@tsed/core","@tsed/schema"],t):"object"==typeof exports?exports["@tsed/json-mapper"]=t(require("@tsed/core"),require("@tsed/schema")):e["@tsed/json-mapper"]=t(e["@tsed/core"],e["@tsed/schema"])}(self,((__WEBPACK_EXTERNAL_MODULE__803__,__WEBPACK_EXTERNAL_MODULE__953__)=>(()=>{"use strict";var __webpack_modules__={405:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{S:()=>JsonMapperCompiler});var _tsed_core__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(803),_tsed_core__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_tsed_core__WEBPACK_IMPORTED_MODULE_0__);class JsonMapperCompiler{cache=new Map;mappers={};schemes={};constructors={};globals={isCollection:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isCollection,isClass:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isClass,isObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isObject,classOf:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.classOf,nameOf:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf,hasJsonMethod:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.hasJsonMethod,isMongooseObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isMongooseObject,isNil:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isNil,isDate:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isDate,objectKeys:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.objectKeys,isMomentObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isMomentObject};constructor(){this.addGlobal("alterIgnore",this.alterIgnore.bind(this)),this.addGlobal("alterValue",this.alterValue.bind(this)),this.addGlobal("execMapper",this.execMapper.bind(this)),this.addGlobal("compileAndMap",this.map.bind(this))}addTypeMapper(e,t){const r=(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e);return this.cache.set(e,(new Map).set("typeMapper",{id:r,fn:t})),this.mappers[r]=t,this}removeTypeMapper(e){const t=this.cache.get(e);if(t){const{id:r}=t.get("typeMapper");delete this.mappers[r],this.cache.delete(e)}}addGlobal(e,t){return this.globals[e]=t,this}eval(mapper,{id,groupsId,model}){this.addGlobal("cache",this.cache);const{globals,schemes}=this,injectGlobals=Object.keys(globals).map((e=>`const ${e} = globals.${e};`)).join("\n");eval(`${injectGlobals};\n\n cache.get(model).set(groupsId, { id: '${id}', fn: ${mapper} })`);const store=this.cache.get(model).get(groupsId);return this.mappers[id]=store.fn,store}createContext(e){const{cache:t}=this;return{...e,cache:t}}compile(e,t,r={}){const s=(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isString)(e)?e:this.getType(e),i=this.getGroupsId(t);let n=this.cache.get(s)||this.cache.get((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(s));if(n||(n=new Map,this.cache.set(s,n)),n.has("typeMapper"))return n.get("typeMapper");if(!n.has(i)){const o=this.getId(s,i);n.set(i,{id:o});const a=r.mapper?r.mapper(o,t):this.createMapper(s,o,t);try{return this.eval(a,{id:o,model:s,groupsId:i})}catch(t){throw new Error(`Fail to compile mapper for ${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e)}. See the error above: ${t.message}.\n${a}`)}}return n.get(i)}execMapper(e,t,r){return(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isObjectID)(t)?t.toString():this.mappers[e||(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.classOf)(t))](t,r)}getType(e){if(!e)return Object;if((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isClass)(e)&&!(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isCollection)(e)){const t=[Array,Map,Set].find((t=>(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.ancestorsOf)(e).includes(t)));if(t)return t}return e}alterIgnore(e,t){let r=this.schemes[e]?.$hooks?.alter("ignore",!1,[t]);if(r)return r}alterGroups(e,t){return!1!==t&&e.$hooks.alter("groups",!1,[t])}getGroupsId(e){return!1===e?"default":0===e.length?"-":e.join(",")}getId(e,t){return`${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isString)(e)?e:(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e)}:${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.getRandomId)()}:${t}`}getSchemaId(e,t){return`${e}:${t}`}}},803:e=>{e.exports=__WEBPACK_EXTERNAL_MODULE__803__},953:e=>{e.exports=__WEBPACK_EXTERNAL_MODULE__953__}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};return(()=>{function e(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AfterDeserialize:()=>u,BeforeDeserialize:()=>d,CastError:()=>p,DateMapper:()=>o,JsonDeserializer:()=>P,JsonMapper:()=>n,JsonMapperCompiler:()=>O.S,JsonMapperSettings:()=>y,JsonSerializer:()=>A,OnDeserialize:()=>h,OnSerialize:()=>m,PrimitiveMapper:()=>c,SymbolMapper:()=>_,Writer:()=>g,alterAfterDeserialize:()=>f,alterBeforeDeserialize:()=>b,alterOnDeserialize:()=>M,alterOnSerialize:()=>S,deserialize:()=>I,getJsonMapperTypes:()=>i,getObjectProperties:()=>w,registerJsonTypeMapper:()=>s,serialize:()=>C}),Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var t=__webpack_require__(803);const r=new Map;function s(e,t){r.set(e,new t)}function i(){return r}function n(...e){return t=>{e.forEach((e=>{s(e,t)}))}}let o=class{deserialize(e){return(0,t.isBoolean)(e)||null==e?e:new Date(e)}serialize(e){return e?new Date(e).toISOString():e}};function a(e){return[null,"null"].includes(e)}o=e([n(Date)],o);class p extends Error{name="CAST_ERROR";constructor(e){super(`Cast error. ${e}`)}}let c=class{deserialize(e,r){return this[(0,t.nameOf)(r.type)]?this[(0,t.nameOf)(r.type)](e,r):void 0}serialize(e,r){return this[(0,t.nameOf)(r?.type)]&&"object"!=typeof e?this[(0,t.nameOf)(r.type)](e,r):e}String(e){return null===e?null:""+e}Boolean(e){return!!["true","1",!0].includes(e)||!["false","0",!1].includes(e)&&(a(e)?null:void 0!==e?!!e:void 0)}Number(e){if(a(e))return null;if(void 0===e)return e;const t=+e;if(isNaN(t))throw new p("Expression value is not a number.");return t}BigInt(e){return a(e)?null:BigInt(e)}};c=e([n(String,Number,Boolean,BigInt)],c);let _=class{deserialize(e){return Symbol.for(e)}serialize(e){return e.toString().replace("Symbol(","").replace(")","")}};_=e([n(Symbol)],_);var l=__webpack_require__(953);function u(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("afterDeserialize",e)}))}function d(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("beforeDeserialize",e)}))}function h(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("onDeserialize",e)}))}function m(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("onSerialize",e)}))}function f(e,t,r){return t?.$hooks?.alter("afterDeserialize",e,[r])}function b(e,t,r){return t?.$hooks?.alter("beforeDeserialize",e,[r])}function M(e,t,r){return e.$hooks.alter("onDeserialize",t,[r])}var O=__webpack_require__(405);const y={disableUnsecureConstructor:!0,additionalProperties:!1,strictGroups:!1};class g{static object={assign:(...e)=>`{ ${e.filter(Boolean).join(", ")} }`};_root;body=[];_indent;constructor(e){this._root=e}static indent(e){return e.map((e=>`\t${e}`))}static mapper(e,t,r){return`execMapper('${e}', ${t}, ${r})`}static mapperFrom(e,t){return`execMapper(nameOf(classOf(${e})), ${e}, ${t})`}static options(...e){return(e=e.filter(Boolean)).length?g.object.assign("...options",...e):"options"}add(...e){return(e=e.filter((e=>void 0!==e))).length&&this.body.push(...e),this}arrow(...e){this.add(`(${e}) => {`);const t=this.new();return this.add("}"),t}build(){const e=this.body.flatMap((e=>e instanceof g?e.build():e));return this._indent?e.map((e=>"\t"+e)):e}callMapper(e,t,...r){return this.set(t,g.mapper(e,t,g.options(...r)))}returnCallMapper(e,t,...r){return this.return(g.mapper(e,t,g.options(...r)))}const(e,t){return this.add(`const ${e} = ${t};`),this}each(e,t=[]){const r=this.add(e+".forEach(("+t.join(", ")+") => {").new();return this.add("});"),r}if(e){const t=new E(e,this);return this.add(t),t}switch(e){const t=new $(e);return this.add(t),t}indent(e){return this._indent=e,this}new(e=!0){const t=new g(this.root());return t.indent(e),this.add(t),t}return(e){return this.add(`return ${e};`),this.root()}root(){return this._root||this}set(e,t){return this.add(`${e} = ${t};`),this}toString(){return this.build().join("\n")}}class E extends g{condition;elseWriter;constructor(e,t){super(),this.condition=e,this._root=t}else(){const e=new g(this._root);return this.elseWriter=e,e}build(){return[`if (${this.condition}) {`,...g.indent(super.build()),"}",this.elseWriter?["else {",...g.indent(this.elseWriter.build()),"}"]:[]].flat()}}class $ extends g{input;#e=new Map;constructor(e){super(),this.input=e}case(e){const t=new g;return this.#e.set(e,t),t}build(){return[`switch (${this.input}) {`,...g.indent(Array.from(this.#e.entries()).flatMap((([e,t])=>["default"===e?`${e}:`:`case ${e}:`,...g.indent(t.build())]))),"}"].flat()}}function D(e){return`__${e}`}class P extends O.S{constructors={};constructor(){super(),this.addGlobal("newInstanceOf",this.newInstanceOf.bind(this)),this.addGlobal("alterBeforeDeserialize",this.alterBeforeDeserialize.bind(this)),this.addGlobal("alterAfterDeserialize",this.alterAfterDeserialize.bind(this)),this.addTypeMapper(Object,this.mapObject.bind(this)),this.addTypeMapper(Array,this.mapArray.bind(this)),this.addTypeMapper(Map,this.mapMap.bind(this)),this.addTypeMapper(Set,this.mapSet.bind(this)),this.addTypeMapper("ObjectId",(e=>String(e)))}map(e,r={}){if(!function(e,r){return!(r.collectionType&&(0,t.isNil)(e)||void 0===e||(0,t.isEmpty)(r.type)||r.type===Object&&!r.collectionType)}(e,r=this.mapOptions(r)))return e;!r.collectionType&&(0,t.isArray)(e)&&(r.collectionType=Array);const s=r.type||(0,t.classOf)(e),i=this.compile(s,r.groups);return r.collectionType?this.compile(r.collectionType,r.groups).fn(e,{...r,id:i.id}):i.fn(e,this.createContext(r))}compile(e,r){if([WeakMap,WeakSet].includes(e))throw new Error(`${(0,t.nameOf)(e)} is not supported by JsonMapper.`);return super.compile(e,r)}eval(e,{id:t,groupsId:r,model:s}){return this.constructors[t]=s,super.eval(e,{id:t,groupsId:r,model:s})}newInstanceOf(e,t,r){try{return new this.constructors[e](r.disableUnsecureConstructor?{}:t)}catch(e){return t}}createMapper(e,r,s){const i=l.JsonEntityStore.from(e),n=new Set,o=[...(0,l.getPropertiesStores)(i).values()],a=(new g).arrow("input","options");return a.if("isNil(input)").return("input"),i.schema.hasDiscriminator&&a.add(this.mapDiscriminator(i,s)),i.schema.$hooks?.has("beforeDeserialize")&&(this.schemes[r]=i.schema,a.set("input",`alterBeforeDeserialize('${r}', input, options)`)),a.const("generics","options.generics[0]"),i.schema.genericLabels?.length?a.set("options","{...options, self: input, generics: [...options.generics].slice(1)}"):a.set("options","{...options, self: input}"),a.const("obj",`newInstanceOf('${r}', input, options)`),a.add(...o.flatMap((e=>{const i=e.propertyName;if(n.add(String(e.parent.schema.getAliasOf(i)||i)),!(e.schema?.$ignore&&(0,t.isBoolean)(e.schema?.$ignore)||e.isGetterOnly()||e.schema?.$hooks?.has("groups")&&this.alterGroups(e.schema,s)))return this.mapProperty(e,r,s)}))),a.add(this.mapAdditionalProperties(i,n,s)),i.schema.$hooks?.has("afterDeserialize")?(this.schemes[r]=i.schema,a.return(`alterAfterDeserialize('${r}', obj, options)`).root().toString()):a.return("obj").root().toString()}alterValue(e,t,r){return M(this.schemes[e],t,r)}mapDiscriminator(e,t){const r=new g,s=e.schema.discriminator(),i=r.switch(`input['${s.propertyName}']`);return s.values.forEach(((e,r)=>{const s=this.compile(e,t);i.case(`'${r}'`).returnCallMapper(s.id,"input")})),r}mapProperty(e,t,r){const s=String(e.propertyKey),i=String(e.parent.schema.getAliasOf(s)||s),n=this.getSchemaId(t,s),o=e.itemSchema.get("format"),a=o&&`options: {format: '${o}'}`;let p=(new g).add(`// Map ${s} ${t} ${r||""}`);const c=s!==i?`options.useAlias ? '${i}' : '${s}'`:`'${s}'`;e.schema?.$hooks?.has("ignore")&&(this.schemes[n]=e.schema,p=p.if(`!alterIgnore('${n}', {...options, self: input})`));const _=e.schema?.$hooks?.has("onDeserialize");let l=`input[${c}]`;_&&(this.schemes[n]=e.schema,l=`alterValue('${n}', input[${c}], ${g.options(a)})`);const u=p.set(`let ${D(s)}`,l).if(`${D(s)} !== undefined`);return this.getPropertyFiller(e,t,r,a)(_?u.if(`${D(s)} === input.${s}`):u),u.set(`obj.${s}`,D(s)),r&&r.includes("partial")&&u.else().add(`delete obj.${s}`),p.root()}getPropertyFiller(e,r,s,i){const n=String(e.propertyKey),o=this.getSchemaId(r,n),a=e.itemSchema.nestedGenerics;if(e.itemSchema.isGeneric&&!a?.length){const t=function(e){return e.parent.schema.genericLabels.indexOf(e.itemSchema.genericType)}(e),r=g.options(i,`type: generics[${t}]`);return e=>e.set(D(n),`compileAndMap(${D(n)}, ${r})`)}const p=e.itemSchema.hasDiscriminator?e.itemSchema.discriminator().base:e.getBestType(),c=this.compile(p,s);return e.isCollection?r=>r.callMapper((0,t.nameOf)(e.collectionType),D(n),`id: '${c.id}'`,i):a?.length?(this.schemes[o]=e.schema,e=>e.callMapper(c.id,D(n),i,`generics: schemes['${o}'].nestedGenerics`)):e=>e.callMapper(c.id,D(n),i)}mapOptions({groups:e,useAlias:r=!0,types:s,...n}){if(n.store instanceof l.JsonParameterStore)return this.mapOptions(function(e,t){return{...t,store:void 0,type:e.getBestType(),collectionType:e.collectionType,groups:e.parameter.groups,generics:e.nestedGenerics}}(n.store,n));(s=s||i()).forEach(((e,r)=>{if(![Array,Set,Map].includes(r)){const s=(0,t.nameOf)(r);(0,t.nameOf)(r)in e?this.addTypeMapper(r,e[s].bind(e)):this.addTypeMapper(r,((t,s)=>e.deserialize(t,{...s,type:r})))}}));const o=n.strictGroups??y.strictGroups;return{...n,additionalProperties:n.additionalProperties??y.additionalProperties,disableUnsecureConstructor:n.disableUnsecureConstructor??y.disableUnsecureConstructor,groups:void 0===e?!!o&&[]:e||!1,useAlias:r,customMappers:{},generics:n.generics||[]}}mapAdditionalProperties(e,r,s){const i=e.schema.get("additionalProperties"),n=[...r.values()].map((e=>`'${e}'`)).join(", "),o=new g;o.add("// add additional properties");let a=o.each("objectKeys(input)",["key"]);if(n.length&&(a=a.if(`![${n}].includes(key)`)),(0,t.isClass)(i)){const e=this.compile(i.getComputedType(),s);return a.set("obj[key]",g.mapper(e.id,"input[key]","options")),o}return i?(a.set("obj[key]","input[key]"),o):(a.if("options.additionalProperties && obj[key] === undefined").set("obj[key]","input[key]"),o)}mapObject(e,t){return e}mapSet(e,r){if((0,t.isNil)(e))return e;const s=new Set;return(0,t.objectKeys)(e).forEach((t=>{s.add(this.mapItem(e[t],r))})),s}mapArray(e,r){return(0,t.isNil)(e)?e:[].concat(e).map((e=>this.mapItem(e,r)))}mapMap(e,r){if((0,t.isNil)(e))return e;const s=new Map;return(0,t.objectKeys)(e).forEach((t=>{s.set(t,this.mapItem(e[t],r))})),s}mapItem(e,{id:t,...r}){return this.execMapper(t,e,r)}alterBeforeDeserialize(e,t,r){return b(t,this.schemes[e],r)}alterAfterDeserialize(e,t,r){return f(t,this.schemes[e],r)}}function S(e,t,r){return e.$hooks.alter("onSerialize",t,[r])}function w(e){return Object.entries(e).filter((([,e])=>!(0,t.isFunction)(e)))}function j(e){return`__${e}`}class A extends O.S{constructor(){super(),this.addTypeMapper(Object,this.mapObject.bind(this)),this.addTypeMapper(Array,this.mapArray.bind(this)),this.addTypeMapper(Map,this.mapMap.bind(this)),this.addTypeMapper(Set,this.mapSet.bind(this)),this.addGlobal("mapJSON",this.mapJSON.bind(this)),this.addTypeMapper("ObjectId",(e=>String(e)))}map(e,r={}){if((0,t.isNil)(e))return e;const s=function(e,r){const s=(0,t.classOf)(r);return!s||(0,t.isClassObject)(s)||(0,t.isCollection)(r)?e||Object:s}((r=this.mapOptions(r)).type,e);return this.compile(s,r.groups).fn(e,this.createContext(r))}alterValue(e,t,r){return S(this.schemes[e],t,r)}createMapper(e,r,s){const i=l.JsonEntityStore.from(e),n=new Set,o=[...(0,l.getPropertiesStores)(i).values()],a=(new g).arrow("input","options");return a.if("isNil(input)").return("input"),a.const("obj","{}"),a.set("options","{...options, self: input}"),a.add(this.mapPrecondition(r)),o.length?(a.add(...o.flatMap((e=>{if(n.add(e.propertyKey),!(e.schema?.$ignore&&(0,t.isBoolean)(e.schema?.$ignore)||e.schema?.$hooks?.has("groups")&&this.alterGroups(e.schema,s)))return this.mapProperty(e,r,s)}))),a.add(this.mapDiscriminatorKeyValue(i)),a.add(this.mapAdditionalProperties(i,n)),a.return("obj").root().toString()):a.return("isObject(input) ? {...input} : input").root().toString()}mapOptions({groups:e,useAlias:t=!0,types:r,...s}){(r=r||i()).forEach(((e,t)=>{[Array,Set,Map].includes(t)||this.addTypeMapper(t,((r,s)=>e.serialize(r,{...s,type:t})))}));const n=s.strictGroups??y.strictGroups;return{...s,groups:void 0===e?!!n&&[]:e||!1,useAlias:t,customMappers:{}}}mapProperty(e,t,r){const s=String(e.propertyKey),i=String(e.parent.schema.getAliasOf(s)||s),n=this.getSchemaId(t,s),o=e.itemSchema.get("format"),a=o&&`options: {format: '${o}'}`;let p=(new g).add(`// Map ${s} ${t} ${r||""}`);e.schema?.$hooks?.has("ignore")&&(this.schemes[n]=e.schema,p=p.if(`!alterIgnore('${n}', {...options, self: input})`));const c=e.schema?.$hooks?.has("onSerialize");let _=`input.${s}`;c&&(this.schemes[n]=e.schema,_=`alterValue('${n}', input.${s}, ${g.options(a)})`),p=p.set(`let ${j(s)}`,_).if(`${j(s)} !== undefined`);return this.getPropertyFiller(e,s,r,a)(c?p.if(`${j(s)} === input.${s}`):p),i!==s?p.set(`obj[options.useAlias ? '${i}' : '${s}']`,j(s)):p.set(`obj.${s}`,j(s)),p.root()}getPropertyFiller(e,r,s,i){const n=e.itemSchema.isGeneric,o=e.itemSchema.hasDiscriminator;if(e.isCollection){const a=e.getBestType();let p;if(o){const t=e.parent.targetName;p=this.compile(`Discriminator:${t}:${r}`,s,{mapper:()=>this.createDiscriminatorMapper(e,s)})}else p=n?{id:""}:this.compile(a,s);return s=>s.callMapper((0,t.nameOf)(e.collectionType),j(r),`id: '${p.id}'`,i)}if(n)return e=>e.set(j(r),`compileAndMap(${j(r)}, options)`);let a;if(o){const t=e.parent.targetName;a=this.compile(`Discriminator:${t}:${r}`,s,{mapper:()=>this.createDiscriminatorMapper(e,s)})}else a=this.compile(e.getBestType(),s);return e=>e.callMapper(a.id,j(r),i)}createDiscriminatorMapper(e,r){const s=e.itemSchema.discriminator(),i=(new g).arrow("input","options"),n=i.switch("nameOf(classOf(input))");return s.values.forEach(((e,s)=>{const i=this.compile(e,r);n.case(`'${(0,t.nameOf)(e)}'`).returnCallMapper(i.id,"input")})),i.root().toString()}mapPrecondition(e){const t=new g;return t.if("input && isCollection(input)").return(g.mapperFrom("input",`{...options, id: '${e}'}`)),t.if("hasJsonMethod(input)").return(`mapJSON(input, {...options, id: '${e}'})`),t}mapDiscriminatorKeyValue(e){if(e.discriminatorAncestor){const t=e.discriminatorAncestor.schema.discriminator(),r=t.getDefaultValue(e.target);if(r){const e=new g;return e.if(`!obj.${t.propertyName}`).set(`obj.${t.propertyName}`,`'${r}'`),e}}}mapAdditionalProperties(e,t){if(e.schema.get("additionalProperties")){const e=[...t.values()].map((e=>`'${e}'`)).join(", "),r=new g;return r.add("// add additional properties"),r.each("objectKeys(input)",["key"]).if(`![${e}].includes(key)`).set("obj[key]","input[key]"),r}}mapObject(e,{type:r,...s}){return e&&(0,t.isPrimitive)(e)||!e?e:e&&(0,t.isCollection)(e)?this.execMapper((e=>(0,t.isArray)(e)?"Array":e instanceof Set?"Set":e instanceof Map?"Map":void 0)(e),e,s):(0,t.hasJsonMethod)(e)?this.mapJSON(e,s):w(e).filter((([,e])=>void 0!==e)).reduce(((e,[r,i])=>{if((0,t.isNil)(i))return{...e,[r]:i};const n=this.compile((0,t.classOf)(i),s.groups);return{...e,[r]:n.fn(i,s)}}),{})}mapSet(e,r){return(0,t.isNil)(e)?e:[...e.values()].map((e=>this.mapItem(e,r)))}mapArray(e,r){return(0,t.isNil)(e)?e:[].concat(e).map((e=>this.mapItem(e,r)))}mapMap(e,r){return(0,t.isNil)(e)?e:[...e.entries()].reduce(((e,[t,s])=>({...e,[t]:this.mapItem(s,r)})),{})}mapItem(e,{id:r,...s}){return!r&&e?this.compile((0,t.classOf)(e),s.groups).fn(e,s):r?this.execMapper(r,e,s):e}mapJSON(e,{id:r,...s}){return(0,t.isMongooseObject)(e)?e.toJSON({...s,id:r}):(r=r||(0,t.nameOf)((0,t.classOf)(e)),this.mappers[r]&&((0,t.isDate)(e)||(0,t.isMomentObject)(e))?this.execMapper(r,e,s):(e=e.toJSON(),(0,t.isObject)(e)?this.execMapper(r,e,s):e))}}const T=new P;function I(e,t){return T.map(e,t)}const k=new A;function C(e,t){return k.map(e,t)}})(),__webpack_exports__})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@tsed/core"),require("@tsed/schema")):"function"==typeof define&&define.amd?define(["@tsed/core","@tsed/schema"],t):"object"==typeof exports?exports["@tsed/json-mapper"]=t(require("@tsed/core"),require("@tsed/schema")):e["@tsed/json-mapper"]=t(e["@tsed/core"],e["@tsed/schema"])}(self,((__WEBPACK_EXTERNAL_MODULE__803__,__WEBPACK_EXTERNAL_MODULE__953__)=>(()=>{"use strict";var __webpack_modules__={405:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{S:()=>JsonMapperCompiler});var _tsed_core__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(803),_tsed_core__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(_tsed_core__WEBPACK_IMPORTED_MODULE_0__);class JsonMapperCompiler{constructor(){this.cache=new Map,this.mappers={},this.schemes={},this.constructors={},this.globals={isCollection:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isCollection,isClass:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isClass,isObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isObject,classOf:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.classOf,nameOf:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf,hasJsonMethod:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.hasJsonMethod,isMongooseObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isMongooseObject,isNil:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isNil,isDate:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isDate,objectKeys:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.objectKeys,isMomentObject:_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isMomentObject},this.addGlobal("alterIgnore",this.alterIgnore.bind(this)),this.addGlobal("alterValue",this.alterValue.bind(this)),this.addGlobal("execMapper",this.execMapper.bind(this)),this.addGlobal("compileAndMap",this.map.bind(this))}addTypeMapper(e,t){const r=(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e);return this.cache.set(e,(new Map).set("typeMapper",{id:r,fn:t})),this.mappers[r]=t,this}removeTypeMapper(e){const t=this.cache.get(e);if(t){const{id:r}=t.get("typeMapper");delete this.mappers[r],this.cache.delete(e)}}addGlobal(e,t){return this.globals[e]=t,this}eval(mapper,{id,groupsId,model}){this.addGlobal("cache",this.cache);const{globals,schemes}=this,injectGlobals=Object.keys(globals).map((e=>`const ${e} = globals.${e};`)).join("\n");eval(`${injectGlobals};\n\n cache.get(model).set(groupsId, { id: '${id}', fn: ${mapper} })`);const store=this.cache.get(model).get(groupsId);return this.mappers[id]=store.fn,store}createContext(e){const{cache:t}=this;return{...e,cache:t}}compile(e,t,r={}){const s=(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isString)(e)?e:this.getType(e),i=this.getGroupsId(t);let n=this.cache.get(s)||this.cache.get((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(s));if(n||(n=new Map,this.cache.set(s,n)),n.has("typeMapper"))return n.get("typeMapper");if(!n.has(i)){const o=this.getId(s,i);n.set(i,{id:o});const a=r.mapper?r.mapper(o,t):this.createMapper(s,o,t);try{return this.eval(a,{id:o,model:s,groupsId:i})}catch(t){throw new Error(`Fail to compile mapper for ${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e)}. See the error above: ${t.message}.\n${a}`)}}return n.get(i)}execMapper(e,t,r){return(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isObjectID)(t)?t.toString():this.mappers[e||(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.classOf)(t))](t,r)}getType(e){if(!e)return Object;if((0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isClass)(e)&&!(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isCollection)(e)){const t=[Array,Map,Set].find((t=>(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.ancestorsOf)(e).includes(t)));if(t)return t}return e}alterIgnore(e,t){let r=this.schemes[e]?.$hooks?.alter("ignore",!1,[t]);if(r)return r}alterGroups(e,t){return!1!==t&&e.$hooks.alter("groups",!1,[t])}getGroupsId(e){return!1===e?"default":0===e.length?"-":e.join(",")}getId(e,t){return`${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.isString)(e)?e:(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.nameOf)(e)}:${(0,_tsed_core__WEBPACK_IMPORTED_MODULE_0__.getRandomId)()}:${t}`}getSchemaId(e,t){return`${e}:${t}`}}},803:e=>{e.exports=__WEBPACK_EXTERNAL_MODULE__803__},953:e=>{e.exports=__WEBPACK_EXTERNAL_MODULE__953__}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return __webpack_require__.d(t,{a:t}),t},__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};return(()=>{function e(e,t,r,s){var i,n=arguments.length,o=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(n<3?i(o):n>3?i(t,r,o):i(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{AfterDeserialize:()=>u,BeforeDeserialize:()=>d,CastError:()=>p,DateMapper:()=>o,JsonDeserializer:()=>P,JsonMapper:()=>n,JsonMapperCompiler:()=>O.S,JsonMapperSettings:()=>y,JsonSerializer:()=>A,OnDeserialize:()=>h,OnSerialize:()=>m,PrimitiveMapper:()=>c,SymbolMapper:()=>_,Writer:()=>g,alterAfterDeserialize:()=>f,alterBeforeDeserialize:()=>b,alterOnDeserialize:()=>M,alterOnSerialize:()=>S,deserialize:()=>I,getJsonMapperTypes:()=>i,getObjectProperties:()=>w,registerJsonTypeMapper:()=>s,serialize:()=>C}),Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var t=__webpack_require__(803);const r=new Map;function s(e,t){r.set(e,new t)}function i(){return r}function n(...e){return t=>{e.forEach((e=>{s(e,t)}))}}let o=class{deserialize(e){return(0,t.isBoolean)(e)||null==e?e:new Date(e)}serialize(e){return e?new Date(e).toISOString():e}};function a(e){return[null,"null"].includes(e)}o=e([n(Date)],o);class p extends Error{constructor(e){super(`Cast error. ${e}`),this.name="CAST_ERROR"}}let c=class{deserialize(e,r){return this[(0,t.nameOf)(r.type)]?this[(0,t.nameOf)(r.type)](e,r):void 0}serialize(e,r){return this[(0,t.nameOf)(r?.type)]&&"object"!=typeof e?this[(0,t.nameOf)(r.type)](e,r):e}String(e){return null===e?null:""+e}Boolean(e){return!!["true","1",!0].includes(e)||!["false","0",!1].includes(e)&&(a(e)?null:void 0!==e?!!e:void 0)}Number(e){if(a(e))return null;if(void 0===e)return e;const t=+e;if(isNaN(t))throw new p("Expression value is not a number.");return t}BigInt(e){return a(e)?null:BigInt(e)}};c=e([n(String,Number,Boolean,BigInt)],c);let _=class{deserialize(e){return Symbol.for(e)}serialize(e){return e.toString().replace("Symbol(","").replace(")","")}};_=e([n(Symbol)],_);var l=__webpack_require__(953);function u(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("afterDeserialize",e)}))}function d(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("beforeDeserialize",e)}))}function h(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("onDeserialize",e)}))}function m(e){return(0,l.JsonEntityFn)((t=>{t.schema.$hooks.on("onSerialize",e)}))}function f(e,t,r){return t?.$hooks?.alter("afterDeserialize",e,[r])}function b(e,t,r){return t?.$hooks?.alter("beforeDeserialize",e,[r])}function M(e,t,r){return e.$hooks.alter("onDeserialize",t,[r])}var O=__webpack_require__(405);const y={disableUnsecureConstructor:!0,additionalProperties:!1,strictGroups:!1};class g{static{this.object={assign:(...e)=>`{ ${e.filter(Boolean).join(", ")} }`}}constructor(e){this.body=[],this._root=e}static indent(e){return e.map((e=>`\t${e}`))}static mapper(e,t,r){return`execMapper('${e}', ${t}, ${r})`}static mapperFrom(e,t){return`execMapper(nameOf(classOf(${e})), ${e}, ${t})`}static options(...e){return(e=e.filter(Boolean)).length?g.object.assign("...options",...e):"options"}add(...e){return(e=e.filter((e=>void 0!==e))).length&&this.body.push(...e),this}arrow(...e){this.add(`(${e}) => {`);const t=this.new();return this.add("}"),t}build(){const e=this.body.flatMap((e=>e instanceof g?e.build():e));return this._indent?e.map((e=>"\t"+e)):e}callMapper(e,t,...r){return this.set(t,g.mapper(e,t,g.options(...r)))}returnCallMapper(e,t,...r){return this.return(g.mapper(e,t,g.options(...r)))}const(e,t){return this.add(`const ${e} = ${t};`),this}each(e,t=[]){const r=this.add(e+".forEach(("+t.join(", ")+") => {").new();return this.add("});"),r}if(e){const t=new E(e,this);return this.add(t),t}switch(e){const t=new $(e);return this.add(t),t}indent(e){return this._indent=e,this}new(e=!0){const t=new g(this.root());return t.indent(e),this.add(t),t}return(e){return this.add(`return ${e};`),this.root()}root(){return this._root||this}set(e,t){return this.add(`${e} = ${t};`),this}toString(){return this.build().join("\n")}}class E extends g{constructor(e,t){super(),this.condition=e,this._root=t}else(){const e=new g(this._root);return this.elseWriter=e,e}build(){return[`if (${this.condition}) {`,...g.indent(super.build()),"}",this.elseWriter?["else {",...g.indent(this.elseWriter.build()),"}"]:[]].flat()}}class $ extends g{#e;constructor(e){super(),this.input=e,this.#e=new Map}case(e){const t=new g;return this.#e.set(e,t),t}build(){return[`switch (${this.input}) {`,...g.indent(Array.from(this.#e.entries()).flatMap((([e,t])=>["default"===e?`${e}:`:`case ${e}:`,...g.indent(t.build())]))),"}"].flat()}}function D(e){return`__${e}`}class P extends O.S{constructor(){super(),this.constructors={},this.addGlobal("newInstanceOf",this.newInstanceOf.bind(this)),this.addGlobal("alterBeforeDeserialize",this.alterBeforeDeserialize.bind(this)),this.addGlobal("alterAfterDeserialize",this.alterAfterDeserialize.bind(this)),this.addTypeMapper(Object,this.mapObject.bind(this)),this.addTypeMapper(Array,this.mapArray.bind(this)),this.addTypeMapper(Map,this.mapMap.bind(this)),this.addTypeMapper(Set,this.mapSet.bind(this)),this.addTypeMapper("ObjectId",(e=>String(e)))}map(e,r={}){if(!function(e,r){return!(r.collectionType&&(0,t.isNil)(e)||void 0===e||(0,t.isEmpty)(r.type)||r.type===Object&&!r.collectionType)}(e,r=this.mapOptions(r)))return e;!r.collectionType&&(0,t.isArray)(e)&&(r.collectionType=Array);const s=r.type||(0,t.classOf)(e),i=this.compile(s,r.groups);return r.collectionType?this.compile(r.collectionType,r.groups).fn(e,{...r,id:i.id}):i.fn(e,this.createContext(r))}compile(e,r){if([WeakMap,WeakSet].includes(e))throw new Error(`${(0,t.nameOf)(e)} is not supported by JsonMapper.`);return super.compile(e,r)}eval(e,{id:t,groupsId:r,model:s}){return this.constructors[t]=s,super.eval(e,{id:t,groupsId:r,model:s})}newInstanceOf(e,t,r){try{return new this.constructors[e](r.disableUnsecureConstructor?{}:t)}catch(e){return t}}createMapper(e,r,s){const i=l.JsonEntityStore.from(e),n=new Set,o=[...(0,l.getPropertiesStores)(i).values()],a=(new g).arrow("input","options");return a.if("isNil(input)").return("input"),i.schema.hasDiscriminator&&a.add(this.mapDiscriminator(i,s)),i.schema.$hooks?.has("beforeDeserialize")&&(this.schemes[r]=i.schema,a.set("input",`alterBeforeDeserialize('${r}', input, options)`)),a.const("generics","options.generics[0]"),i.schema.genericLabels?.length?a.set("options","{...options, self: input, generics: [...options.generics].slice(1)}"):a.set("options","{...options, self: input}"),a.const("obj",`newInstanceOf('${r}', input, options)`),a.add(...o.flatMap((e=>{const i=e.propertyName;if(n.add(String(e.parent.schema.getAliasOf(i)||i)),!(e.schema?.$ignore&&(0,t.isBoolean)(e.schema?.$ignore)||e.isGetterOnly()||e.schema?.$hooks?.has("groups")&&this.alterGroups(e.schema,s)))return this.mapProperty(e,r,s)}))),a.add(this.mapAdditionalProperties(i,n,s)),i.schema.$hooks?.has("afterDeserialize")?(this.schemes[r]=i.schema,a.return(`alterAfterDeserialize('${r}', obj, options)`).root().toString()):a.return("obj").root().toString()}alterValue(e,t,r){return M(this.schemes[e],t,r)}mapDiscriminator(e,t){const r=new g,s=e.schema.discriminator(),i=r.switch(`input['${s.propertyName}']`);return s.values.forEach(((e,r)=>{const s=this.compile(e,t);i.case(`'${r}'`).returnCallMapper(s.id,"input")})),r}mapProperty(e,t,r){const s=String(e.propertyKey),i=String(e.parent.schema.getAliasOf(s)||s),n=this.getSchemaId(t,s),o=e.itemSchema.get("format"),a=o&&`options: {format: '${o}'}`;let p=(new g).add(`// Map ${s} ${t} ${r||""}`);const c=s!==i?`options.useAlias ? '${i}' : '${s}'`:`'${s}'`;e.schema?.$hooks?.has("ignore")&&(this.schemes[n]=e.schema,p=p.if(`!alterIgnore('${n}', {...options, self: input})`));const _=e.schema?.$hooks?.has("onDeserialize");let l=`input[${c}]`;_&&(this.schemes[n]=e.schema,l=`alterValue('${n}', input[${c}], ${g.options(a)})`);const u=p.set(`let ${D(s)}`,l).if(`${D(s)} !== undefined`);return this.getPropertyFiller(e,t,r,a)(_?u.if(`${D(s)} === input.${s}`):u),u.set(`obj.${s}`,D(s)),r&&r.includes("partial")&&u.else().add(`delete obj.${s}`),p.root()}getPropertyFiller(e,r,s,i){const n=String(e.propertyKey),o=this.getSchemaId(r,n),a=e.itemSchema.nestedGenerics;if(e.itemSchema.isGeneric&&!a?.length){const t=function(e){return e.parent.schema.genericLabels.indexOf(e.itemSchema.genericType)}(e),r=g.options(i,`type: generics[${t}]`);return e=>e.set(D(n),`compileAndMap(${D(n)}, ${r})`)}const p=e.itemSchema.hasDiscriminator?e.itemSchema.discriminator().base:e.getBestType(),c=this.compile(p,s);return e.isCollection?r=>r.callMapper((0,t.nameOf)(e.collectionType),D(n),`id: '${c.id}'`,i):a?.length?(this.schemes[o]=e.schema,e=>e.callMapper(c.id,D(n),i,`generics: schemes['${o}'].nestedGenerics`)):e=>e.callMapper(c.id,D(n),i)}mapOptions({groups:e,useAlias:r=!0,types:s,...n}){if(n.store instanceof l.JsonParameterStore)return this.mapOptions(function(e,t){return{...t,store:void 0,type:e.getBestType(),collectionType:e.collectionType,groups:e.parameter.groups,generics:e.nestedGenerics}}(n.store,n));(s=s||i()).forEach(((e,r)=>{if(![Array,Set,Map].includes(r)){const s=(0,t.nameOf)(r);(0,t.nameOf)(r)in e?this.addTypeMapper(r,e[s].bind(e)):this.addTypeMapper(r,((t,s)=>e.deserialize(t,{...s,type:r})))}}));const o=n.strictGroups??y.strictGroups;return{...n,additionalProperties:n.additionalProperties??y.additionalProperties,disableUnsecureConstructor:n.disableUnsecureConstructor??y.disableUnsecureConstructor,groups:void 0===e?!!o&&[]:e||!1,useAlias:r,customMappers:{},generics:n.generics||[]}}mapAdditionalProperties(e,r,s){const i=e.schema.get("additionalProperties"),n=[...r.values()].map((e=>`'${e}'`)).join(", "),o=new g;o.add("// add additional properties");let a=o.each("objectKeys(input)",["key"]);if(n.length&&(a=a.if(`![${n}].includes(key)`)),(0,t.isClass)(i)){const e=this.compile(i.getComputedType(),s);return a.set("obj[key]",g.mapper(e.id,"input[key]","options")),o}return i?(a.set("obj[key]","input[key]"),o):(a.if("options.additionalProperties && obj[key] === undefined").set("obj[key]","input[key]"),o)}mapObject(e,t){return e}mapSet(e,r){if((0,t.isNil)(e))return e;const s=new Set;return(0,t.objectKeys)(e).forEach((t=>{s.add(this.mapItem(e[t],r))})),s}mapArray(e,r){return(0,t.isNil)(e)?e:[].concat(e).map((e=>this.mapItem(e,r)))}mapMap(e,r){if((0,t.isNil)(e))return e;const s=new Map;return(0,t.objectKeys)(e).forEach((t=>{s.set(t,this.mapItem(e[t],r))})),s}mapItem(e,{id:t,...r}){return this.execMapper(t,e,r)}alterBeforeDeserialize(e,t,r){return b(t,this.schemes[e],r)}alterAfterDeserialize(e,t,r){return f(t,this.schemes[e],r)}}function S(e,t,r){return e.$hooks.alter("onSerialize",t,[r])}function w(e){return Object.entries(e).filter((([,e])=>!(0,t.isFunction)(e)))}function j(e){return`__${e}`}class A extends O.S{constructor(){super(),this.addTypeMapper(Object,this.mapObject.bind(this)),this.addTypeMapper(Array,this.mapArray.bind(this)),this.addTypeMapper(Map,this.mapMap.bind(this)),this.addTypeMapper(Set,this.mapSet.bind(this)),this.addGlobal("mapJSON",this.mapJSON.bind(this)),this.addTypeMapper("ObjectId",(e=>String(e)))}map(e,r={}){if((0,t.isNil)(e))return e;const s=function(e,r){const s=(0,t.classOf)(r);return!s||(0,t.isClassObject)(s)||(0,t.isCollection)(r)?e||Object:s}((r=this.mapOptions(r)).type,e);return this.compile(s,r.groups).fn(e,this.createContext(r))}alterValue(e,t,r){return S(this.schemes[e],t,r)}createMapper(e,r,s){const i=l.JsonEntityStore.from(e),n=new Set,o=[...(0,l.getPropertiesStores)(i).values()],a=(new g).arrow("input","options");return a.if("isNil(input)").return("input"),a.const("obj","{}"),a.set("options","{...options, self: input}"),a.add(this.mapPrecondition(r)),o.length?(a.add(...o.flatMap((e=>{if(n.add(e.propertyKey),!(e.schema?.$ignore&&(0,t.isBoolean)(e.schema?.$ignore)||e.schema?.$hooks?.has("groups")&&this.alterGroups(e.schema,s)))return this.mapProperty(e,r,s)}))),a.add(this.mapDiscriminatorKeyValue(i)),a.add(this.mapAdditionalProperties(i,n)),a.return("obj").root().toString()):a.return("isObject(input) ? {...input} : input").root().toString()}mapOptions({groups:e,useAlias:t=!0,types:r,...s}){(r=r||i()).forEach(((e,t)=>{[Array,Set,Map].includes(t)||this.addTypeMapper(t,((r,s)=>e.serialize(r,{...s,type:t})))}));const n=s.strictGroups??y.strictGroups;return{...s,groups:void 0===e?!!n&&[]:e||!1,useAlias:t,customMappers:{}}}mapProperty(e,t,r){const s=String(e.propertyKey),i=String(e.parent.schema.getAliasOf(s)||s),n=this.getSchemaId(t,s),o=e.itemSchema.get("format"),a=o&&`options: {format: '${o}'}`;let p=(new g).add(`// Map ${s} ${t} ${r||""}`);e.schema?.$hooks?.has("ignore")&&(this.schemes[n]=e.schema,p=p.if(`!alterIgnore('${n}', {...options, self: input})`));const c=e.schema?.$hooks?.has("onSerialize");let _=`input.${s}`;c&&(this.schemes[n]=e.schema,_=`alterValue('${n}', input.${s}, ${g.options(a)})`),p=p.set(`let ${j(s)}`,_).if(`${j(s)} !== undefined`);return this.getPropertyFiller(e,s,r,a)(c?p.if(`${j(s)} === input.${s}`):p),i!==s?p.set(`obj[options.useAlias ? '${i}' : '${s}']`,j(s)):p.set(`obj.${s}`,j(s)),p.root()}getPropertyFiller(e,r,s,i){const n=e.itemSchema.isGeneric,o=e.itemSchema.hasDiscriminator;if(e.isCollection){const a=e.getBestType();let p;if(o){const t=e.parent.targetName;p=this.compile(`Discriminator:${t}:${r}`,s,{mapper:()=>this.createDiscriminatorMapper(e,s)})}else p=n?{id:""}:this.compile(a,s);return s=>s.callMapper((0,t.nameOf)(e.collectionType),j(r),`id: '${p.id}'`,i)}if(n)return e=>e.set(j(r),`compileAndMap(${j(r)}, options)`);let a;if(o){const t=e.parent.targetName;a=this.compile(`Discriminator:${t}:${r}`,s,{mapper:()=>this.createDiscriminatorMapper(e,s)})}else a=this.compile(e.getBestType(),s);return e=>e.callMapper(a.id,j(r),i)}createDiscriminatorMapper(e,r){const s=e.itemSchema.discriminator(),i=(new g).arrow("input","options"),n=i.switch("nameOf(classOf(input))");return s.values.forEach(((e,s)=>{const i=this.compile(e,r);n.case(`'${(0,t.nameOf)(e)}'`).returnCallMapper(i.id,"input")})),i.root().toString()}mapPrecondition(e){const t=new g;return t.if("input && isCollection(input)").return(g.mapperFrom("input",`{...options, id: '${e}'}`)),t.if("hasJsonMethod(input)").return(`mapJSON(input, {...options, id: '${e}'})`),t}mapDiscriminatorKeyValue(e){if(e.discriminatorAncestor){const t=e.discriminatorAncestor.schema.discriminator(),r=t.getDefaultValue(e.target);if(r){const e=new g;return e.if(`!obj.${t.propertyName}`).set(`obj.${t.propertyName}`,`'${r}'`),e}}}mapAdditionalProperties(e,t){if(e.schema.get("additionalProperties")){const e=[...t.values()].map((e=>`'${e}'`)).join(", "),r=new g;return r.add("// add additional properties"),r.each("objectKeys(input)",["key"]).if(`![${e}].includes(key)`).set("obj[key]","input[key]"),r}}mapObject(e,{type:r,...s}){return e&&(0,t.isPrimitive)(e)||!e?e:e&&(0,t.isCollection)(e)?this.execMapper((e=>(0,t.isArray)(e)?"Array":e instanceof Set?"Set":e instanceof Map?"Map":void 0)(e),e,s):(0,t.hasJsonMethod)(e)?this.mapJSON(e,s):w(e).filter((([,e])=>void 0!==e)).reduce(((e,[r,i])=>{if((0,t.isNil)(i))return{...e,[r]:i};const n=this.compile((0,t.classOf)(i),s.groups);return{...e,[r]:n.fn(i,s)}}),{})}mapSet(e,r){return(0,t.isNil)(e)?e:[...e.values()].map((e=>this.mapItem(e,r)))}mapArray(e,r){return(0,t.isNil)(e)?e:[].concat(e).map((e=>this.mapItem(e,r)))}mapMap(e,r){return(0,t.isNil)(e)?e:[...e.entries()].reduce(((e,[t,s])=>({...e,[t]:this.mapItem(s,r)})),{})}mapItem(e,{id:r,...s}){return!r&&e?this.compile((0,t.classOf)(e),s.groups).fn(e,s):r?this.execMapper(r,e,s):e}mapJSON(e,{id:r,...s}){return(0,t.isMongooseObject)(e)?e.toJSON({...s,id:r}):(r=r||(0,t.nameOf)((0,t.classOf)(e)),this.mappers[r]&&((0,t.isDate)(e)||(0,t.isMomentObject)(e))?this.execMapper(r,e,s):(e=e.toJSON(),(0,t.isObject)(e)?this.execMapper(r,e,s):e))}}const T=new P;function I(e,t){return T.map(e,t)}const k=new A;function C(e,t){return k.map(e,t)}})(),__webpack_exports__})()));
//# sourceMappingURL=json-mapper.umd.min.js.map

@@ -11,5 +11,5 @@ "use strict";

class CastError extends Error {
name = "CAST_ERROR";
constructor(message) {
super(`Cast error. ${message}`);
this.name = "CAST_ERROR";
}

@@ -16,0 +16,0 @@ }

@@ -37,9 +37,9 @@ "use strict";

class JsonDeserializer extends JsonMapperCompiler_js_1.JsonMapperCompiler {
/**
* Cached classes by his id
* @protected
*/
constructors = {};
constructor() {
super();
/**
* Cached classes by his id
* @protected
*/
this.constructors = {};
this.addGlobal("newInstanceOf", this.newInstanceOf.bind(this));

@@ -46,0 +46,0 @@ this.addGlobal("alterBeforeDeserialize", this.alterBeforeDeserialize.bind(this));

@@ -6,40 +6,40 @@ "use strict";

class JsonMapperCompiler {
/**
* Cached mappers metadata
* @protected
*/
cache = new Map();
/**
* Cached executable mappers by his id
* @protected
*/
mappers = {};
/**
* Cached schemas
* @protected
*/
schemes = {};
/**
* Cached classes by his id
* @protected
*/
constructors = {};
/**
* Global variables available in the mapper
* @protected
*/
globals = {
isCollection: core_1.isCollection,
isClass: core_1.isClass,
isObject: core_1.isObject,
classOf: core_1.classOf,
nameOf: core_1.nameOf,
hasJsonMethod: core_1.hasJsonMethod,
isMongooseObject: core_1.isMongooseObject,
isNil: core_1.isNil,
isDate: core_1.isDate,
objectKeys: core_1.objectKeys,
isMomentObject: core_1.isMomentObject
};
constructor() {
/**
* Cached mappers metadata
* @protected
*/
this.cache = new Map();
/**
* Cached executable mappers by his id
* @protected
*/
this.mappers = {};
/**
* Cached schemas
* @protected
*/
this.schemes = {};
/**
* Cached classes by his id
* @protected
*/
this.constructors = {};
/**
* Global variables available in the mapper
* @protected
*/
this.globals = {
isCollection: core_1.isCollection,
isClass: core_1.isClass,
isObject: core_1.isObject,
classOf: core_1.classOf,
nameOf: core_1.nameOf,
hasJsonMethod: core_1.hasJsonMethod,
isMongooseObject: core_1.isMongooseObject,
isNil: core_1.isNil,
isDate: core_1.isDate,
objectKeys: core_1.objectKeys,
isMomentObject: core_1.isMomentObject
};
this.addGlobal("alterIgnore", this.alterIgnore.bind(this));

@@ -46,0 +46,0 @@ this.addGlobal("alterValue", this.alterValue.bind(this));

@@ -5,11 +5,9 @@ "use strict";

class Writer {
static object = {
static { this.object = {
assign(...args) {
return `{ ${args.filter(Boolean).join(", ")} }`;
}
};
_root;
body = [];
_indent;
}; }
constructor(root) {
this.body = [];
this._root = root;

@@ -99,4 +97,2 @@ }

class IfWriter extends Writer {
condition;
elseWriter;
constructor(condition, root) {

@@ -122,7 +118,7 @@ super();

class SwitchWriter extends Writer {
input;
#map = new Map();
#map;
constructor(input) {
super();
this.input = input;
this.#map = new Map();
}

@@ -129,0 +125,0 @@ case(condition) {

@@ -8,5 +8,5 @@ import { __decorate } from "tslib";

export class CastError extends Error {
name = "CAST_ERROR";
constructor(message) {
super(`Cast error. ${message}`);
this.name = "CAST_ERROR";
}

@@ -13,0 +13,0 @@ }

@@ -34,9 +34,9 @@ import { classOf, isArray, isBoolean, isClass, isEmpty, isNil, nameOf, objectKeys } from "@tsed/core";

export class JsonDeserializer extends JsonMapperCompiler {
/**
* Cached classes by his id
* @protected
*/
constructors = {};
constructor() {
super();
/**
* Cached classes by his id
* @protected
*/
this.constructors = {};
this.addGlobal("newInstanceOf", this.newInstanceOf.bind(this));

@@ -43,0 +43,0 @@ this.addGlobal("alterBeforeDeserialize", this.alterBeforeDeserialize.bind(this));

import { ancestorsOf, classOf, getRandomId, hasJsonMethod, isClass, isCollection, isDate, isMomentObject, isMongooseObject, isNil, isObject, isObjectID, isString, nameOf, objectKeys } from "@tsed/core";
export class JsonMapperCompiler {
/**
* Cached mappers metadata
* @protected
*/
cache = new Map();
/**
* Cached executable mappers by his id
* @protected
*/
mappers = {};
/**
* Cached schemas
* @protected
*/
schemes = {};
/**
* Cached classes by his id
* @protected
*/
constructors = {};
/**
* Global variables available in the mapper
* @protected
*/
globals = {
isCollection,
isClass,
isObject,
classOf,
nameOf,
hasJsonMethod,
isMongooseObject,
isNil,
isDate,
objectKeys,
isMomentObject
};
constructor() {
/**
* Cached mappers metadata
* @protected
*/
this.cache = new Map();
/**
* Cached executable mappers by his id
* @protected
*/
this.mappers = {};
/**
* Cached schemas
* @protected
*/
this.schemes = {};
/**
* Cached classes by his id
* @protected
*/
this.constructors = {};
/**
* Global variables available in the mapper
* @protected
*/
this.globals = {
isCollection,
isClass,
isObject,
classOf,
nameOf,
hasJsonMethod,
isMongooseObject,
isNil,
isDate,
objectKeys,
isMomentObject
};
this.addGlobal("alterIgnore", this.alterIgnore.bind(this));

@@ -42,0 +42,0 @@ this.addGlobal("alterValue", this.alterValue.bind(this));

export class Writer {
static object = {
static { this.object = {
assign(...args) {
return `{ ${args.filter(Boolean).join(", ")} }`;
}
};
_root;
body = [];
_indent;
}; }
constructor(root) {
this.body = [];
this._root = root;

@@ -94,4 +92,2 @@ }

class IfWriter extends Writer {
condition;
elseWriter;
constructor(condition, root) {

@@ -117,7 +113,7 @@ super();

class SwitchWriter extends Writer {
input;
#map = new Map();
#map;
constructor(input) {
super();
this.input = input;
this.#map = new Map();
}

@@ -124,0 +120,0 @@ case(condition) {

@@ -5,3 +5,3 @@ {

"type": "commonjs",
"version": "7.82.2",
"version": "7.82.3",
"source": "./src/index.ts",

@@ -46,6 +46,6 @@ "main": "./lib/cjs/index.js",

"devDependencies": {
"@tsed/barrels": "7.82.2",
"@tsed/core": "7.82.2",
"@tsed/schema": "7.82.2",
"@tsed/typescript": "7.82.2",
"@tsed/barrels": "7.82.3",
"@tsed/core": "7.82.3",
"@tsed/schema": "7.82.3",
"@tsed/typescript": "7.82.3",
"eslint": "^8.57.0",

@@ -56,4 +56,4 @@ "typescript": "4.9.5",

"peerDependencies": {
"@tsed/core": "7.82.2",
"@tsed/schema": "7.82.2"
"@tsed/core": "7.82.3",
"@tsed/schema": "7.82.3"
},

@@ -60,0 +60,0 @@ "peerDependenciesMeta": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc