Comparing version 1.9.1 to 1.9.2
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.morphism=e():t.morphism=e()}(this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e){},function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t){return s(t)&&t.hasOwnProperty("fn")&&t.hasOwnProperty("path")}function i(t){return p(t)}function c(t){return Array.isArray(t)&&t.every(i)}r.r(e);const u=(t,e)=>t.reduce((t,r)=>(d(t,r,l(e,r)),t),{});function a(t){return void 0===t}function s(t){const e=typeof t;return null!=t&&("object"===e||"function"===e)}function p(t){return"string"==typeof t||t instanceof String}function f(t){return"function"==typeof t}function l(t,e){const r=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");for(let e=0,n=r.length;e<n;++e){const n=r[e];if(!(s(t)&&n in t))return;t=t[n]}return t}function h(t,e){return t.reduce((t,r,o)=>(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.forEach(function(e){n(t,e,r[e])})}return t})({},t,{[r]:e[o]}),{})}function y(t,e){return"number"==typeof e&&Array.isArray(t)||function(t,e){return null!=t&&Object.prototype.hasOwnProperty.call(t,e)}(t,e)}function d(t,e,r,n){if("number"==typeof e&&(e=[e]),!e||0===e.length)return t;if("string"==typeof e)return d(t,e.split(".").map(g),r,n);const o=e[0],i=function(t,e){if(y(t,e))return t[e]}(t,o);return 1===e.length?(void 0!==i&&n||(t[o]=r),i):(void 0===i&&("number"==typeof e[1]?t[o]=[]:t[o]={}),d(t[o],e.slice(1),r,n))}function g(t){const e=parseInt(t);return e.toString()===t?e:t}var m=r(0);function b(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){P(t,e,r[e])})}return t}function P(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}let v;function j(t){const e=new w;return function t(e,r,n,i){u=r,(p(u)||f(u)||o(u)||c(u))&&n?(e.add({propertyName:n,action:r},i),i=i?`${i}.${n}`:n):(n&&(e.add({propertyName:n,action:null},i),i=i?`${i}.${n}`:n),Array.isArray(r)?r.forEach((r,n)=>{t(e,r,n.toString(),i)}):s(r)&&Object.keys(r).forEach(n=>{t(e,r[n],n,i)}));var u}(e,t),e}!function(t){t.Root="Root",t.Property="Property",t.ActionFunction="ActionFunction",t.ActionAggregator="ActionAggregator",t.ActionString="ActionString",t.ActionSelector="ActionSelector"}(v||(v={}));class w{constructor(){this.root=void 0,this.root={data:{targetPropertyPath:"",propertyName:"MorphismTreeRoot",action:null,kind:v.Root},parent:null,children:[]}}*traverseBFS(){const t=[];for(t.push(this.root);t.length>0;){let e=t.shift();if(!e)return;for(let r=0,n=e.children.length;r<n;r++)t.push(e.children[r]);e.data.kind!==v.Root&&(yield e)}}add(t,e){const r=this.getActionKind(t.action);if(!r)throw new Error(`The action specified for ${t.propertyName} is not supported.`);const n={data:b({},t,{kind:r,targetPropertyPath:""}),parent:null,children:[]};if(n.data.preparedAction=this.getPreparedAction(n.data),e)for(const t of this.traverseBFS())t.data.targetPropertyPath===e&&(n.parent=t,n.data.targetPropertyPath=`${t.data.targetPropertyPath}.${n.data.propertyName}`,t.children.push(n));else n.parent=this.root,n.data.targetPropertyPath=n.data.propertyName,this.root.children.push(n)}getActionKind(t){return i(t)?v.ActionString:f(t)?v.ActionFunction:o(t)?v.ActionSelector:c(t)?v.ActionAggregator:null===t?v.Property:void 0}getPreparedAction(t){const e=t.propertyName,r=t.action,n=t.kind;if(i(r))return t=>{return l(t.object,r)};if(f(r))return t=>{let e=t.object,n=t.items,o=t.objectToCompute;return r.call(void 0,e,n,o)};if(c(r))return t=>{let e=t.object;return u(r,e)};if(o(r))return t=>{let n,o=t.object,i=t.items,c=t.objectToCompute;try{let t;Array.isArray(r.path)?t=u(r.path,o):p(r.path)&&(t=l(o,r.path)),n=r.fn.call(void 0,t,o,i,c)}catch(t){throw t.message=`Unable to set target property [${e}].\n \n An error occured when applying [${r.fn.name}] on property [${r.path}]\n \n Internal error: ${t.message}`,t}return n};if(n===v.Property)return null;throw new Error(`The action specified for ${e} is not supported.`)}}function A(t){return(e,r,n)=>{const o=n.value;return"function"==typeof o&&(n.value=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];const i=o.apply(this,r);return function(t){if(Promise&&Promise.resolve)return Promise.resolve(t)==t;throw"Promise not supported in your environment"}(i)?Promise.resolve(i).then(e=>t(e)):t(i)}),n}}function O(t,e,r,n){const o=[];for(const i of e.traverseBFS()){const e=i.data,c=e.preparedAction,u=e.targetPropertyPath;c&&o.push({targetPropertyPath:u,preparedAction:c({object:t,objectToCompute:n,items:r})})}return o.reduce((t,e)=>{const r=((t,e)=>a(e)?a(t)?void 0:t:e)(l(t,e.targetPropertyPath),e.preparedAction);return d(t,e.targetPropertyPath,r),t},n)}function S(t,e){const r=j(t);return function(t){if(!t)return t;if(Array.isArray(t))return t.map(n=>{if(e){const o=new e;return O(n,r,t,o)}return O(n,r,t,{})});{const n=t;if(e){const t=new e;return O(n,r,[n],t)}return O(n,r,[n],{})}}}function M(t,e){let r=Object.keys(new t),n=h(r,r);return Object.assign(n,e)}function $(t,e,r){if(void 0===e&&void 0===r)return S(t);if(t&&e&&r){return S(M(r,t),r)(e)}if(t&&e)return S(t)(e);if(r&&e){return S(M(r,t),r)(e)}if(r){let e=M(r,t);return t=>S(e,r)(t)}}function _(t,e){return A(S(t,e))}function x(t){return A(S(t))}function E(t,e){return A(S(t,e))}r.d(e,"morphism",function(){return $}),r.d(e,"morph",function(){return _}),r.d(e,"toJSObject",function(){return x}),r.d(e,"toClassObject",function(){return E}),r.d(e,"Schema",function(){return m.Schema}),r.d(e,"StrictSchema",function(){return m.StrictSchema});const T=new class{constructor(t){this._registry=null,this._registry=t||{cache:new Map}}register(t,e){if(!t&&!e)throw new Error("type paramater is required when you register a mapping");if(this.exists(t))throw new Error(`A mapper for ${t.name} has already been registered`);let r;return r=$(e||{},null,t),this._registry.cache.set(t,r),r}map(t,e){if(!this.exists(t)){const r=this.register(t);if(void 0===e)return r}return this.getMapper(t)(e)}getMapper(t){return this._registry.cache.get(t)}setMapper(t,e){if(e){if(this.exists(t)){let r=$(e,null,t);return this._registry.cache.set(t,r),r}throw new Error(`The type ${t.name} is not registered. Register it using \`Mophism.register(${t.name}, schema)\``)}throw new Error(`The schema must be an Object. Found ${e}`)}deleteMapper(t){return this._registry.cache.delete(t)}exists(t){return this._registry.cache.has(t)}get mappers(){return this._registry.cache}},k=$;k.register=((t,e)=>T.register(t,e)),k.map=((t,e)=>T.map(t,e)),k.getMapper=(t=>T.getMapper(t)),k.setMapper=((t,e)=>T.setMapper(t,e)),k.deleteMapper=(t=>T.deleteMapper(t)),k.mappers=T.mappers;const F=k;e.default=F}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.morphism=e():t.morphism=e()}(this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e){},function(t,e,r){"use strict";function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t){return s(t)&&t.hasOwnProperty("fn")&&t.hasOwnProperty("path")}function i(t){return p(t)}function c(t){return Array.isArray(t)&&t.every(i)}r.r(e);const u=(t,e)=>t.reduce((t,r)=>(d(t,r,l(e,r)),t),{});function a(t){return void 0===t}function s(t){const e=typeof t;return null!=t&&("object"===e||"function"===e)}function p(t){return"string"==typeof t||t instanceof String}function f(t){return"function"==typeof t}function l(t,e){const r=(e=(e=e.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");for(let e=0,n=r.length;e<n;++e){const n=r[e];if(!(s(t)&&n in t))return;t=t[n]}return t}function h(t,e){return t.reduce((t,r,o)=>(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.forEach(function(e){n(t,e,r[e])})}return t})({},t,{[r]:e[o]}),{})}function y(t,e){return"number"==typeof e&&Array.isArray(t)||function(t,e){return null!=t&&Object.prototype.hasOwnProperty.call(t,e)}(t,e)}function d(t,e,r,n){if("number"==typeof e&&(e=[e]),!e||0===e.length)return t;if("string"==typeof e)return d(t,e.split(".").map(g),r,n);const o=e[0],i=function(t,e){if(y(t,e))return t[e]}(t,o);return 1===e.length?(void 0!==i&&n||(t[o]=r),i):(void 0===i&&("number"==typeof e[1]?t[o]=[]:t[o]={}),d(t[o],e.slice(1),r,n))}function g(t){const e=parseInt(t);return e.toString()===t?e:t}var m=r(0);function b(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){P(t,e,r[e])})}return t}function P(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}let w;function v(t){const e=new j;return function t(e,r,n,i){u=r,(p(u)||f(u)||o(u)||c(u))&&n?(e.add({propertyName:n,action:r},i),i=i?`${i}.${n}`:n):(n&&(e.add({propertyName:n,action:null},i),i=i?`${i}.${n}`:n),Array.isArray(r)?r.forEach((r,n)=>{t(e,r,n.toString(),i)}):s(r)&&Object.keys(r).forEach(n=>{t(e,r[n],n,i)}));var u}(e,t),e}!function(t){t.Root="Root",t.Property="Property",t.ActionFunction="ActionFunction",t.ActionAggregator="ActionAggregator",t.ActionString="ActionString",t.ActionSelector="ActionSelector"}(w||(w={}));class j{constructor(){this.root=void 0,this.root={data:{targetPropertyPath:"",propertyName:"MorphismTreeRoot",action:null,kind:w.Root},parent:null,children:[]}}*traverseBFS(){const t=[];for(t.push(this.root);t.length>0;){let e=t.shift();if(!e)return;for(let r=0,n=e.children.length;r<n;r++)t.push(e.children[r]);e.data.kind!==w.Root&&(yield e)}}add(t,e){const r=this.getActionKind(t.action);if(!r)throw new Error(`The action specified for ${t.propertyName} is not supported.`);const n={data:b({},t,{kind:r,targetPropertyPath:""}),parent:null,children:[]};if(n.data.preparedAction=this.getPreparedAction(n.data),e)for(const t of this.traverseBFS())t.data.targetPropertyPath===e&&(n.parent=t,n.data.targetPropertyPath=`${t.data.targetPropertyPath}.${n.data.propertyName}`,t.children.push(n));else n.parent=this.root,n.data.targetPropertyPath=n.data.propertyName,this.root.children.push(n)}getActionKind(t){return i(t)?w.ActionString:f(t)?w.ActionFunction:o(t)?w.ActionSelector:c(t)?w.ActionAggregator:null===t?w.Property:void 0}getPreparedAction(t){const e=t.propertyName,r=t.action,n=t.kind;if(i(r))return t=>{return l(t.object,r)};if(f(r))return t=>{let e=t.object,n=t.items,o=t.objectToCompute;return r.call(void 0,e,n,o)};if(c(r))return t=>{let e=t.object;return u(r,e)};if(o(r))return t=>{let n,o=t.object,i=t.items,c=t.objectToCompute;try{let t;Array.isArray(r.path)?t=u(r.path,o):p(r.path)&&(t=l(o,r.path)),n=r.fn.call(void 0,t,o,i,c)}catch(t){throw t.message=`Unable to set target property [${e}].\n \n An error occured when applying [${r.fn.name}] on property [${r.path}]\n \n Internal error: ${t.message}`,t}return n};if(n===w.Property)return null;throw new Error(`The action specified for ${e} is not supported.`)}}function A(t){return(e,r,n)=>{const o=n.value;return"function"==typeof o&&(n.value=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];const i=o.apply(this,r);return function(t){if(Promise&&Promise.resolve)return Promise.resolve(t)==t;throw"Promise not supported in your environment"}(i)?Promise.resolve(i).then(e=>t(e)):t(i)}),n}}function O(t,e,r,n){const o=[];for(const i of e.traverseBFS()){const e=i.data,c=e.preparedAction,u=e.targetPropertyPath;c&&o.push({targetPropertyPath:u,preparedAction:c({object:t,objectToCompute:n,items:r})})}return o.reduce((t,e)=>{const r=((t,e)=>a(e)?a(t)?void 0:t:e)(l(t,e.targetPropertyPath),e.preparedAction);return d(t,e.targetPropertyPath,r),t},n)}function S(t,e){const r=v(t);return function(t){if(!t)return t;if(Array.isArray(t))return t.map(n=>{if(e){const o=new e;return O(n,r,t,o)}return O(n,r,t,{})});{const n=t;if(e){const t=new e;return O(n,r,[n],t)}return O(n,r,[n],{})}}}function $(t,e,r){switch(arguments.length){case 1:return S(t);case 2:return S(t)(e);case 3:if(r){const n=function(t,e){let r=Object.keys(new t),n=h(r,r);return Object.assign(n,e)}(r,t);return null!==e?S(n,r)(e):S(n,r)}throw new Error(`When using morphism(schema, items, type), type should be defined but value received is ${r}`)}}function M(t,e){return A(S(t,e))}function _(t){return A(S(t))}function x(t,e){return A(S(t,e))}r.d(e,"morphism",function(){return $}),r.d(e,"morph",function(){return M}),r.d(e,"toJSObject",function(){return _}),r.d(e,"toClassObject",function(){return x}),r.d(e,"Schema",function(){return m.Schema}),r.d(e,"StrictSchema",function(){return m.StrictSchema});const E=new class{constructor(t){this._registry=null,this._registry=t||{cache:new Map}}register(t,e){if(!t&&!e)throw new Error("type paramater is required when you register a mapping");if(this.exists(t))throw new Error(`A mapper for ${t.name} has already been registered`);let r;return r=$(e||{},null,t),this._registry.cache.set(t,r),r}map(t,e){if(!this.exists(t)){const r=this.register(t);if(void 0===e)return r}return this.getMapper(t)(e)}getMapper(t){return this._registry.cache.get(t)}setMapper(t,e){if(e){if(this.exists(t)){let r=$(e,null,t);return this._registry.cache.set(t,r),r}throw new Error(`The type ${t.name} is not registered. Register it using \`Mophism.register(${t.name}, schema)\``)}throw new Error(`The schema must be an Object. Found ${e}`)}deleteMapper(t){return this._registry.cache.delete(t)}exists(t){return this._registry.cache.has(t)}get mappers(){return this._registry.cache}},T=$;T.register=((t,e)=>E.register(t,e)),T.map=((t,e)=>E.map(t,e)),T.getMapper=(t=>E.getMapper(t)),T.setMapper=((t,e)=>E.setMapper(t,e)),T.deleteMapper=(t=>E.deleteMapper(t)),T.mappers=E.mappers;const k=T;e.default=k}])}); | ||
//# sourceMappingURL=morphism.map |
{ | ||
"name": "morphism", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"description": "Do not repeat anymore your objects transformations.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/nobrainr/morphism", |
Sorry, the diff of this file is not supported yet
438
81473