Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-unpacker

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-unpacker - npm Package Compare versions

Comparing version 0.0.18 to 0.0.21

dist/ObjectUnpacker001.d.ts

2

dist/bundle.js

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

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.ObjectUnpacker=r():e.ObjectUnpacker=r()}(self,(function(){return(()=>{var e={43:function(e,r,t){var n,o;!function(i,a){"use strict";void 0===(o="function"==typeof(n=function(){var e=function(){},r="undefined",t=typeof window!==r&&typeof window.navigator!==r&&/Trident\/|MSIE /.test(window.navigator.userAgent),n=["trace","debug","info","warn","error"];function o(e,r){var t=e[r];if("function"==typeof t.bind)return t.bind(e);try{return Function.prototype.bind.call(t,e)}catch(r){return function(){return Function.prototype.apply.apply(t,[e,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function a(n){return"debug"===n&&(n="log"),typeof console!==r&&("trace"===n&&t?i:void 0!==console[n]?o(console,n):void 0!==console.log?o(console,"log"):e)}function s(r,t){for(var o=0;o<n.length;o++){var i=n[o];this[i]=o<r?e:this.methodFactory(i,r,t)}this.log=this.debug}function u(e,t,n){return function(){typeof console!==r&&(s.call(this,t,n),this[e].apply(this,arguments))}}function l(e,r,t){return a(e)||u.apply(this,arguments)}function c(e,t,o){var i,a=this,u="loglevel";function c(){var e;if(typeof window!==r&&u){try{e=window.localStorage[u]}catch(e){}if(typeof e===r)try{var t=window.document.cookie,n=t.indexOf(encodeURIComponent(u)+"=");-1!==n&&(e=/^([^;]+)/.exec(t.slice(n))[1])}catch(e){}return void 0===a.levels[e]&&(e=void 0),e}}"string"==typeof e?u+=":"+e:"symbol"==typeof e&&(u=void 0),a.name=e,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=o||l,a.getLevel=function(){return i},a.setLevel=function(t,o){if("string"==typeof t&&void 0!==a.levels[t.toUpperCase()]&&(t=a.levels[t.toUpperCase()]),!("number"==typeof t&&t>=0&&t<=a.levels.SILENT))throw"log.setLevel() called with invalid level: "+t;if(i=t,!1!==o&&function(e){var t=(n[e]||"silent").toUpperCase();if(typeof window!==r&&u){try{return void(window.localStorage[u]=t)}catch(e){}try{window.document.cookie=encodeURIComponent(u)+"="+t+";"}catch(e){}}}(t),s.call(a,t,e),typeof console===r&&t<a.levels.SILENT)return"No console available for logging"},a.setDefaultLevel=function(e){c()||a.setLevel(e,!1)},a.enableAll=function(e){a.setLevel(a.levels.TRACE,e)},a.disableAll=function(e){a.setLevel(a.levels.SILENT,e)};var f=c();null==f&&(f=null==t?"WARN":t),a.setLevel(f,!1)}var f=new c,p={};f.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var r=p[e];return r||(r=p[e]=new c(e,f.getLevel(),f.methodFactory)),r};var y=typeof window!==r?window.log:void 0;return f.noConflict=function(){return typeof window!==r&&window.log===f&&(window.log=y),f},f.getLoggers=function(){return p},f.default=f,f})?n.call(r,t,r,e):n)||(e.exports=o)}()},616:function(e,r,t){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.createObjectUnpacker=void 0;var o=n(t(43)),i=t(980),a=t(27),s=t(102);r.createObjectUnpacker=function(){return new p};var u="%",l="%",c=!0,f=i.createReferencesResolver(),p=function(){function e(){}return e.prototype.convert=function(e,r,t){try{var n=y(t),a=s.transform(r,s.prefixReferences),p=new Map;s.indexObject(u,l,c,i.INDEX_NAMESPACE,p,a["?"]),s.indexObject(u,l,c,i.COMPACT_NAMESPACE,p,a),s.indexObject(u,l,c,i.SUBS_NAMESPACE,p,e);var v=d(a,n,p);return delete v["?"],f.resolve(p,v)}catch(e){return o.default.error(e.message),{error:e.message}}},e}(),y=function(e){var r=new Map;return Object.keys(e).forEach((function(t){r.set(t,new a.TransformationInstruction(t,e[t]))})),r},d=function(e,r,t){if(null===e)return null;if(Array.isArray(e))return e.map((function(e){return d(e,r,t)}));if("object"==typeof e){var n={};return Object.keys(e).forEach((function(o){var i=r.get(o);if(i&&i.additionalKeys&&i.additionalKeys.has(o)&&(i=i.additionalKeys.get(o)),i){if(i.isRemovePair())return;var a="object"!=typeof e[o]&&i.assignKeys?[e[o]]:e[o],f=v(a,i,r,t);"string"==typeof f&&f.includes("%self")&&(f=N(a,f));var p=i.transformKey(o);if(i.replacePair)S(f)&&P(f,n);else if(i.rewriteValue)if(i.resultValue)if("object"==typeof i.resultValue)n[p]=v(a,i,r,t);else if("string"==typeof i.resultValue&&i.resultValue.startsWith("%")){var y=new Map;t.forEach((function(e,r){return y.set(r,e)})),s.indexObject(u,l,c,"",y,a),n[p]=v(a,i,r,y)}else n[p]=f;else n[p]=null;else n[p]=f}else t.has(o)?n[o]=t.get(o):n[o]=d(e[o],r,t)})),n}return e},v=function(e,r,t,n){if(null===e)return e;var o=S(e)?_(e,r,n):e,i=Array.isArray(o)&&r.assignKeys?g(r.assignKeys,o):new Map,a=new Map;if(n.forEach((function(e,r){return a.set(r,e)})),s.indexObject(u,l,c,"",a,h(i)),r.isArrayMapping()){if(Array.isArray(o)){var f=r.arrayItemsName,p=f?b(f,o):o;return r.assignKeys?g(r.assignKeys,p):d(p,t,a)}throw new Error('"arrayItems" can only be applied to arrays.')}if(!r.resultValue)return i.size>0?d(h(i),t,a):d(o,t,a);switch(typeof r.resultValue){case"object":return Array.isArray(r.resultValue)?A(r,t,a):w(r,o,t,a,i);case"string":return"%self"===r.resultValue?d(o,t,a):r.resultValue.match("^%[a-zA-Z]+(.[a-zA-Z]+)*$")?a.get(r.resultValue):d(r.resultValue,t,a);default:return r.resultValue}},h=function(e){var r={};return e.forEach((function(e,t){return r[t]=e})),r},g=function(e,r){var t=new Map;return Array.isArray(r)?e.forEach((function(e,n){n<r.length?t.set(e,r[n]):t.set(e,null)})):"object"==typeof r?e.forEach((function(e){t.set(e,r[e])})):e.forEach((function(e,n){0===n?t.set(e,r):t.set(e,null)})),t},b=function(e,r){return r.map((function(r){var t={};return t[e]=r,t}))},w=function(e,r,t,n,o){var i={},a=e.resultValue?e.resultValue:r;return Object.keys(a).forEach((function(e){var p=d(a[e],t,n);if("string"==typeof p){var y=p;if(E(r,y))"object"==typeof(h=r[y.substr(1)])?j(h,t,y)?i[e]=v(h,t.get(y.substr(1)),t,n):i[e]=d(h,t,n):i[e]=h;else if(m(y,o)){var h;(h=o.get(y.substr(1)))&&"object"==typeof h?j(h,t,y)?i[e]=v(h,t.get(y.substr(1)),t,n):i[e]=d(h,t,n):i[e]=h}else if(O(y)){var g=new Map;n.forEach((function(e,r){return g.set(r,e)})),s.indexObject(u,l,c,"",g,r),i[e]=f.resolve(g,p)}else y.includes("%self")?i[e]=N(r,y):n.has(y)?i[e]=n.get(y):i[e]=null}else M(p)?i[e]=f.resolve(n,p):i[e]=p})),i},A=function(e,r,t){return e.resultValue&&Array.isArray(e.resultValue)?e.resultValue.map((function(n){return v(n,e,r,t)})).filter((function(e){return null!==e})):[]},E=function(e,r){return"object"==typeof e&&"%"===r.charAt(0)&&e.hasOwnProperty(r.substr(1))},m=function(e,r){return"%"===e.charAt(0)&&r.has(e.substr(1))},j=function(e,r,t){return Array.isArray(e)&&r.has(t.substr(1))},O=function(e){return e.startsWith("%/")||!e.startsWith("%")&&!e.includes("%self")},M=function(e){return null!==e&&"object"==typeof e},N=function(e,r){var t=new Map;return t.set("%self",e),t.set("%self%",e),f.resolve(t,r)},S=function(e){return null!==e&&!Array.isArray(e)&&"object"==typeof e},P=function(e,r){Object.keys(e).forEach((function(t){r[t]=e[t]}))},_=function(e,r,t){var n=e,o={};for(var i in n)if(r.additionalKeys.has(i)){var a=r.additionalKeys.get(i);o[a.transformKey(i)]=d(n[i],a.additionalKeys,t)}else o[i]=n[i];return o}},980:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.FIND_REFS=r.SUBS_NAMESPACE=r.COMPACT_NAMESPACE=r.INDEX_NAMESPACE=r.createReferencesResolver=void 0,r.createReferencesResolver=function(){return new t},r.INDEX_NAMESPACE="/index",r.COMPACT_NAMESPACE="/compact",r.SUBS_NAMESPACE="/subs",r.FIND_REFS=new RegExp(/%?%[\w-./@]+%?/gm);var t=function(){function e(){}return e.prototype.resolve=function(e,r){if(null==r)throw new Error("Cannot dereference an undefined dataObject.");if("string"==typeof r)return i(e,r);var t=Array.isArray(r["?"])?r["?"]:[r["?"]];return t&&t.forEach((function(r,t){e.set("%"+t,r),e.set("%"+t+"%",r)})),Array.isArray(r)?n("",e,r):o("",e,r)},e}(),n=function(e,r,t){var a=[];return t.forEach((function(t,s){var u=e+"."+s;Array.isArray(t)?a.push(n(u,r,t)):"object"==typeof t?a.push(o(u,r,t)):"string"==typeof t?a.push(i(r,t)):a.push(t)})),a},o=function(e,r,t){if(null===t)return null;var a={};return Object.keys(t).forEach((function(s){var u=t[s];if(null!==u){var l=e+"."+s;Array.isArray(u)?a[s]=n(l,r,u):a[s]="object"==typeof u?o(l,r,u):"string"==typeof u?i(r,u):u}else a[s]=null})),a},i=function(e,t){for(var n=t,o=[],i=r.FIND_REFS.exec(n);null!==i;){var s=i[0];o.push(s),i=r.FIND_REFS.exec(n)}return o.forEach((function(r){if(!r.startsWith("%%")){var t=e.get(r);if(null!=t&&"string"==typeof n)if(n===r)n="string"==typeof t?a(t):t;else if("object"==typeof t){var o=a(r);console.error(o+" refers to an object or array and cannot be embedded in a string"),n=n.replace(r,""+o)}else n=n.replace(r,""+t);else n=n===r?null:n.replace(r,"")}})),"string"==typeof n?n.replace("%%","%"):n},a=function(e){return e.replace("/index.","").replace("/subs.","")}},27:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.TransformationInstruction=void 0;var t=["rewriteValue","assignKeys","rewriteKey","replacePair","arrayItems"],n=function(){function e(r,n){var o=this;this.key=r,this.rewriteValue=!!n.hasOwnProperty("rewriteValue"),this.replacePair=!!n.hasOwnProperty("replacePair"),this.assignKeys=n.assignKeys?n.assignKeys:null,this.resultValue=n.rewriteValue?n.rewriteValue:n.replacePair,this.rewriteKey=n.rewriteKey?n.rewriteKey:null,this.arrayItemsName=n.arrayItems?n.arrayItems:null,this.additionalKeys=new Map,Object.keys(n).filter((function(e){return!t.includes(e)})).forEach((function(r){o.additionalKeys.set(r,new e(r,n[r]))}))}return e.prototype.transformKey=function(e){return this.rewriteKey?this.rewriteKey:e},e.prototype.shouldRewriteValue=function(){return this.rewriteValue},e.prototype.isArrayMapping=function(){return null!==this.arrayItemsName},e.prototype.isRemovePair=function(){return!this.replacePair&&!this.rewriteValue&&null===this.arrayItemsName&&null===this.assignKeys&&null===this.rewriteKey&&void 0===this.resultValue&&0===this.additionalKeys.size},e}();r.TransformationInstruction=n},102:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.identity=r.prefixReferences=r.transform=r.indexObject=void 0;var n=t(980);r.indexObject=function(e,t,n,o,i,a){a&&Object.entries(a).forEach((function(a){var s=o.length>0?o+"."+a[0]:""+a[0];n&&i.set(e+s,a[1]),i.set(e+s+t,a[1]),"object"==typeof a[1]&&r.indexObject(e,t,n,s,i,a[1])}))},r.transform=function(e,t){if(!e)return t(e);if(Array.isArray(e)){var n=[];return e.forEach((function(e){"object"==typeof e?n.push(r.transform(e,t)):n.push(t(e))})),t(n)}if("object"==typeof e){var o={};return Object.entries(e).forEach((function(e){"object"==typeof e[1]?o[e[0]]=r.transform(e[1],t):o[e[0]]=t(e[1])})),t(o)}return t(e)},r.prefixReferences=function(e){return"string"!=typeof e?e:e.replace(n.FIND_REFS,(function(e){if(e.startsWith("%%"))return e;var r=e.charCodeAt(1);return r>47&&r<58?"%"+n.INDEX_NAMESPACE+"."+e.substr(1):"%"+n.SUBS_NAMESPACE+"."+e.substr(1)}))},r.identity=function(e){return e}}},r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{}};return e[n].call(o.exports,o,o.exports,t),o.exports}var n={};return(()=>{"use strict";var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.mapper=void 0;var r=t(616);e.mapper=r.createObjectUnpacker()})(),n})()}));
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.ObjectUnpacker=r():e.ObjectUnpacker=r()}(self,(function(){return(()=>{"use strict";var e={571:(e,r,t)=>{const n=t(346);e.exports=a;const i=function(){function e(e){return void 0!==e&&e}try{return"undefined"!=typeof globalThis||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch(r){return e(self)||e(window)||e(this)||{}}}().console||{},s={mapHttpRequest:v,mapHttpResponse:v,wrapRequestSerializer:h,wrapResponseSerializer:h,wrapErrorSerializer:h,req:v,res:v,err:function(e){const r={type:e.constructor.name,msg:e.message,stack:e.stack};for(const t in e)void 0===r[t]&&(r[t]=e[t]);return r}};function a(e){(e=e||{}).browser=e.browser||{};const r=e.browser.transmit;if(r&&"function"!=typeof r.send)throw Error("pino: transmit option must have a send function");const t=e.browser.write||i;e.browser.write&&(e.browser.asObject=!0);const n=e.serializers||{},s=function(e,r){return Array.isArray(e)?e.filter((function(e){return"!stdSerializers.err"!==e})):!0===e&&Object.keys(r)}(e.browser.serialize,n);let l=e.browser.serialize;Array.isArray(e.browser.serialize)&&e.browser.serialize.indexOf("!stdSerializers.err")>-1&&(l=!1),"function"==typeof t&&(t.error=t.fatal=t.warn=t.info=t.debug=t.trace=t),!1===e.enabled&&(e.level="silent");const f=e.level||"info",v=Object.create(t);v.log||(v.log=b),Object.defineProperty(v,"levelVal",{get:function(){return"silent"===this.level?1/0:this.levels.values[this.level]}}),Object.defineProperty(v,"level",{get:function(){return this._level},set:function(e){if("silent"!==e&&!this.levels.values[e])throw Error("unknown level "+e);this._level=e,o(h,v,"error","log"),o(h,v,"fatal","error"),o(h,v,"warn","error"),o(h,v,"info","log"),o(h,v,"debug","log"),o(h,v,"trace","log")}});const h={transmit:r,serialize:s,asObject:e.browser.asObject,levels:["error","fatal","warn","info","debug","trace"],timestamp:y(e)};return v.levels=a.levels,v.level=f,v.setMaxListeners=v.getMaxListeners=v.emit=v.addListener=v.on=v.prependListener=v.once=v.prependOnceListener=v.removeListener=v.removeAllListeners=v.listeners=v.listenerCount=v.eventNames=v.write=v.flush=b,v.serializers=n,v._serialize=s,v._stdErrSerialize=l,v.child=function(t,i){if(!t)throw new Error("missing bindings for child Pino");i=i||{},s&&t.serializers&&(i.serializers=t.serializers);const a=i.serializers;if(s&&a){var o=Object.assign({},n,a),l=!0===e.browser.serialize?Object.keys(o):s;delete t.serializers,u([t],l,o,this._stdErrSerialize)}function f(e){this._childLevel=1+(0|e._childLevel),this.error=c(e,t,"error"),this.fatal=c(e,t,"fatal"),this.warn=c(e,t,"warn"),this.info=c(e,t,"info"),this.debug=c(e,t,"debug"),this.trace=c(e,t,"trace"),o&&(this.serializers=o,this._serialize=l),r&&(this._logEvent=p([].concat(e._logEvent.bindings,t)))}return f.prototype=this,new f(this)},r&&(v._logEvent=p()),v}function o(e,r,t,n){const s=Object.getPrototypeOf(r);r[t]=r.levelVal>r.levels.values[t]?b:s[t]?s[t]:i[t]||i[n]||b,function(e,r,t){var n;(e.transmit||r[t]!==b)&&(r[t]=(n=r[t],function(){const s=e.timestamp(),o=new Array(arguments.length),c=Object.getPrototypeOf&&Object.getPrototypeOf(this)===i?i:this;for(var p=0;p<o.length;p++)o[p]=arguments[p];if(e.serialize&&!e.asObject&&u(o,this._serialize,this.serializers,this._stdErrSerialize),e.asObject?n.call(c,l(this,t,o,s)):n.apply(c,o),e.transmit){const n=e.transmit.level||r.level,i=a.levels.values[n],l=a.levels.values[t];if(l<i)return;f(this,{ts:s,methodLevel:t,methodValue:l,transmitLevel:n,transmitValue:a.levels.values[e.transmit.level||r.level],send:e.transmit.send,val:r.levelVal},o)}}))}(e,r,t)}function l(e,r,t,i){e._serialize&&u(t,e._serialize,e.serializers,e._stdErrSerialize);const s=t.slice();let o=s[0];const l={};i&&(l.time=i),l.level=a.levels.values[r];let c=1+(0|e._childLevel);if(c<1&&(c=1),null!==o&&"object"==typeof o){for(;c--&&"object"==typeof s[0];)Object.assign(l,s.shift());o=s.length?n(s.shift(),s):void 0}else"string"==typeof o&&(o=n(s.shift(),s));return void 0!==o&&(l.msg=o),l}function u(e,r,t,n){for(const i in e)if(n&&e[i]instanceof Error)e[i]=a.stdSerializers.err(e[i]);else if("object"==typeof e[i]&&!Array.isArray(e[i]))for(const n in e[i])r&&r.indexOf(n)>-1&&n in t&&(e[i][n]=t[n](e[i][n]))}function c(e,r,t){return function(){const n=new Array(1+arguments.length);n[0]=r;for(var i=1;i<n.length;i++)n[i]=arguments[i-1];return e[t].apply(this,n)}}function f(e,r,t){const n=r.send,i=r.ts,s=r.methodLevel,a=r.methodValue,o=r.val,l=e._logEvent.bindings;u(t,e._serialize||Object.keys(e.serializers),e.serializers,void 0===e._stdErrSerialize||e._stdErrSerialize),e._logEvent.ts=i,e._logEvent.messages=t.filter((function(e){return-1===l.indexOf(e)})),e._logEvent.level.label=s,e._logEvent.level.value=a,n(s,e._logEvent,o),e._logEvent=p(l)}function p(e){return{ts:0,messages:[],bindings:e||[],level:{label:"",value:0}}}function y(e){return"function"==typeof e.timestamp?e.timestamp:!1===e.timestamp?d:g}function v(){return{}}function h(e){return e}function b(){}function d(){return!1}function g(){return Date.now()}a.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}},a.stdSerializers=s,a.stdTimeFunctions=Object.assign({},{nullTime:d,epochTime:g,unixTime:function(){return Math.round(Date.now()/1e3)},isoTime:function(){return new Date(Date.now()).toISOString()}})},346:e=>{function r(e){try{return JSON.stringify(e)}catch(e){return'"[Circular]"'}}e.exports=function(e,t,n){var i=n&&n.stringify||r;if("object"==typeof e&&null!==e){var s=t.length+1;if(1===s)return e;var a=new Array(s);a[0]=i(e);for(var o=1;o<s;o++)a[o]=i(t[o]);return a.join(" ")}if("string"!=typeof e)return e;var l=t.length;if(0===l)return e;for(var u="",c=0,f=-1,p=e&&e.length||0,y=0;y<p;){if(37===e.charCodeAt(y)&&y+1<p){switch(f=f>-1?f:0,e.charCodeAt(y+1)){case 100:case 102:if(c>=l)break;if(null==t[c])break;f<y&&(u+=e.slice(f,y)),u+=Number(t[c]),f=y+2,y++;break;case 105:if(c>=l)break;if(null==t[c])break;f<y&&(u+=e.slice(f,y)),u+=Math.floor(Number(t[c])),f=y+2,y++;break;case 79:case 111:case 106:if(c>=l)break;if(void 0===t[c])break;f<y&&(u+=e.slice(f,y));var v=typeof t[c];if("string"===v){u+="'"+t[c]+"'",f=y+2,y++;break}if("function"===v){u+=t[c].name||"<anonymous>",f=y+2,y++;break}u+=i(t[c]),f=y+2,y++;break;case 115:if(c>=l)break;f<y&&(u+=e.slice(f,y)),u+=String(t[c]),f=y+2,y++;break;case 37:f<y&&(u+=e.slice(f,y)),u+="%",f=y+2,y++,c--}++c}++y}return-1===f?e:(f<p&&(u+=e.slice(f)),u)}},616:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createObjectUnpacker=void 0;var n=t(503);r.createObjectUnpacker=function(e){switch(e){case"0.0.18":case"0.0.19":case"0.0.20":case"0.0.21":default:return new n.ObjectUnpacker001}}},503:function(e,r,t){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(r,"__esModule",{value:!0}),r.ObjectUnpacker001=void 0;var i=n(t(571)),s=t(980),a=t(27),o=t(102),l=i.default(),u=function(){function e(){}return e.prototype.convert=function(e,r,t){try{var n=v(t),i=o.transform(r,o.prefixReferences),a=new Map;o.indexObject(c,f,p,s.INDEX_NAMESPACE,a,i["?"]),o.indexObject(c,f,p,s.COMPACT_NAMESPACE,a,i),o.indexObject(c,f,p,s.SUBS_NAMESPACE,a,e);var u=h(i,n,a);return delete u["?"],y.resolve(a,u)}catch(e){return l.error(e.message),{error:e.message}}},e}();r.ObjectUnpacker001=u;var c="%",f="%",p=!0,y=s.createReferencesResolver(),v=function(e){var r=new Map;return Object.keys(e).forEach((function(t){r.set(t,new a.TransformationInstruction(t,e[t]))})),r},h=function(e,r,t){if(null===e)return null;if(Array.isArray(e))return e.map((function(e){return h(e,r,t)}));if("object"==typeof e){var n={};return Object.keys(e).forEach((function(i){var s=r.get(i);if(s&&s.additionalKeys&&s.additionalKeys.has(i)&&(s=s.additionalKeys.get(i)),s){if(s.isRemovePair())return;var a="object"!=typeof e[i]&&s.assignKeys?[e[i]]:e[i],l=b(a,s,r,t);"string"==typeof l&&l.includes("%self")&&(l=S(a,l));var u=s.transformKey(i);if(s.replacePair)P(l)&&M(l,n);else if(s.rewriteValue)if(s.resultValue)if("object"==typeof s.resultValue)n[u]=b(a,s,r,t);else if("string"==typeof s.resultValue&&s.resultValue.startsWith("%")){var y=new Map;t.forEach((function(e,r){return y.set(r,e)})),o.indexObject(c,f,p,"",y,a),n[u]=b(a,s,r,y)}else n[u]=l;else n[u]=null;else n[u]=l}else t.has(i)?n[i]=t.get(i):n[i]=h(e[i],r,t)})),n}return e},b=function(e,r,t,n){if(null===e)return e;var i=P(e)?k(e,r,n):e,s=Array.isArray(i)&&r.assignKeys?g(r.assignKeys,i):new Map,a=new Map;if(n.forEach((function(e,r){return a.set(r,e)})),o.indexObject(c,f,p,"",a,d(s)),r.isArrayMapping()){if(Array.isArray(i)){var l=r.arrayItemsName,u=l?m(l,i):i;return r.assignKeys?g(r.assignKeys,u):h(u,t,a)}throw new Error('"arrayItems" can only be applied to arrays.')}if(!r.resultValue)return s.size>0?h(d(s),t,a):h(i,t,a);switch(typeof r.resultValue){case"object":return Array.isArray(r.resultValue)?j(r,t,a):w(r,i,t,a,s);case"string":return"%self"===r.resultValue?h(i,t,a):r.resultValue.match("^%[a-zA-Z]+(.[a-zA-Z]+)*$")?a.get(r.resultValue):h(r.resultValue,t,a);default:return r.resultValue}},d=function(e){var r={};return e.forEach((function(e,t){return r[t]=e})),r},g=function(e,r){var t=new Map;return Array.isArray(r)?e.forEach((function(e,n){n<r.length?t.set(e,r[n]):t.set(e,null)})):"object"==typeof r?e.forEach((function(e){t.set(e,r[e])})):e.forEach((function(e,n){0===n?t.set(e,r):t.set(e,null)})),t},m=function(e,r){return r.map((function(r){var t={};return t[e]=r,t}))},w=function(e,r,t,n,i){var s={},a=e.resultValue?e.resultValue:r;return Object.keys(a).forEach((function(e){var l=h(a[e],t,n);if("string"==typeof l){var u=l;if(E(r,u))"object"==typeof(v=r[u.substr(1)])?O(v,t,u)?s[e]=b(v,t.get(u.substr(1)),t,n):s[e]=h(v,t,n):s[e]=v;else if(A(u,i)){var v;(v=i.get(u.substr(1)))&&"object"==typeof v?O(v,t,u)?s[e]=b(v,t.get(u.substr(1)),t,n):s[e]=h(v,t,n):s[e]=v}else if(_(u)){var d=new Map;n.forEach((function(e,r){return d.set(r,e)})),o.indexObject(c,f,p,"",d,r),s[e]=y.resolve(d,l)}else u.includes("%self")?s[e]=S(r,u):n.has(u)?s[e]=n.get(u):s[e]=null}else z(l)?s[e]=y.resolve(n,l):s[e]=l})),s},j=function(e,r,t){return e.resultValue&&Array.isArray(e.resultValue)?e.resultValue.map((function(n){return b(n,e,r,t)})).filter((function(e){return null!==e})):[]},E=function(e,r){return"object"==typeof e&&"%"===r.charAt(0)&&e.hasOwnProperty(r.substr(1))},A=function(e,r){return"%"===e.charAt(0)&&r.has(e.substr(1))},O=function(e,r,t){return Array.isArray(e)&&r.has(t.substr(1))},_=function(e){return e.startsWith("%/")||!e.startsWith("%")&&!e.includes("%self")},z=function(e){return null!==e&&"object"==typeof e},S=function(e,r){var t=new Map;return t.set("%self",e),t.set("%self%",e),y.resolve(t,r)},P=function(e){return null!==e&&!Array.isArray(e)&&"object"==typeof e},M=function(e,r){Object.keys(e).forEach((function(t){r[t]=e[t]}))},k=function(e,r,t){var n=e,i={};for(var s in n)if(r.additionalKeys.has(s)){var a=r.additionalKeys.get(s);i[a.transformKey(s)]=h(n[s],a.additionalKeys,t)}else i[s]=n[s];return i}},980:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.FIND_REFS=r.SUBS_NAMESPACE=r.COMPACT_NAMESPACE=r.INDEX_NAMESPACE=r.createReferencesResolver=void 0,r.createReferencesResolver=function(){return new t},r.INDEX_NAMESPACE="/index",r.COMPACT_NAMESPACE="/compact",r.SUBS_NAMESPACE="/subs",r.FIND_REFS=new RegExp(/%?%[\w-./@]+%?/gm);var t=function(){function e(){}return e.prototype.resolve=function(e,r){if(null==r)throw new Error("Cannot dereference an undefined dataObject.");if("string"==typeof r)return s(e,r);var t=Array.isArray(r["?"])?r["?"]:[r["?"]];return t&&t.forEach((function(r,t){e.set("%"+t,r),e.set("%"+t+"%",r)})),Array.isArray(r)?n("",e,r):i("",e,r)},e}(),n=function(e,r,t){var a=[];return t.forEach((function(t,o){var l=e+"."+o;Array.isArray(t)?a.push(n(l,r,t)):"object"==typeof t?a.push(i(l,r,t)):"string"==typeof t?a.push(s(r,t)):a.push(t)})),a},i=function(e,r,t){if(null===t)return null;var a={};return Object.keys(t).forEach((function(o){var l=t[o];if(null!==l){var u=e+"."+o;Array.isArray(l)?a[o]=n(u,r,l):a[o]="object"==typeof l?i(u,r,l):"string"==typeof l?s(r,l):l}else a[o]=null})),a},s=function(e,t){for(var n=t,i=[],s=r.FIND_REFS.exec(n);null!==s;){var o=s[0];i.push(o),s=r.FIND_REFS.exec(n)}return i.forEach((function(r){if(!r.startsWith("%%")){var t=e.get(r);if(null!=t&&"string"==typeof n)if(n===r)n="string"==typeof t?a(t):t;else if("object"==typeof t){var i=a(r);console.error(i+" refers to an object or array and cannot be embedded in a string"),n=n.replace(r,""+i)}else n=n.replace(r,""+t);else n=n===r?null:n.replace(r,"")}})),"string"==typeof n?n.replace("%%","%"):n},a=function(e){return e.replace("/index.","").replace("/subs.","")}},27:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.TransformationInstruction=void 0;var t=["rewriteValue","assignKeys","rewriteKey","replacePair","arrayItems"],n=function(){function e(r,n){var i=this;this.key=r,this.rewriteValue=!!n.hasOwnProperty("rewriteValue"),this.replacePair=!!n.hasOwnProperty("replacePair"),this.assignKeys=n.assignKeys?n.assignKeys:null,this.resultValue=n.rewriteValue?n.rewriteValue:n.replacePair,this.rewriteKey=n.rewriteKey?n.rewriteKey:null,this.arrayItemsName=n.arrayItems?n.arrayItems:null,this.additionalKeys=new Map,"object"!=typeof n||Array.isArray(n)||Object.keys(n).filter((function(e){return!t.includes(e)})).forEach((function(r){i.additionalKeys.set(r,new e(r,n[r]))}))}return e.prototype.transformKey=function(e){return this.rewriteKey?this.rewriteKey:e},e.prototype.shouldRewriteValue=function(){return this.rewriteValue},e.prototype.isArrayMapping=function(){return null!==this.arrayItemsName},e.prototype.isRemovePair=function(){return!this.replacePair&&!this.rewriteValue&&null===this.arrayItemsName&&null===this.assignKeys&&null===this.rewriteKey&&void 0===this.resultValue&&0===this.additionalKeys.size},e}();r.TransformationInstruction=n},102:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.identity=r.prefixReferences=r.transform=r.indexObject=void 0;var n=t(980);r.indexObject=function(e,t,n,i,s,a){a&&Object.entries(a).forEach((function(a){var o=i.length>0?i+"."+a[0]:""+a[0];n&&s.set(e+o,a[1]),s.set(e+o+t,a[1]),"object"==typeof a[1]&&r.indexObject(e,t,n,o,s,a[1])}))},r.transform=function(e,t){if(!e)return t(e);if(Array.isArray(e)){var n=[];return e.forEach((function(e){"object"==typeof e?n.push(r.transform(e,t)):n.push(t(e))})),t(n)}if("object"==typeof e){var i={};return Object.entries(e).forEach((function(e){"object"==typeof e[1]?i[e[0]]=r.transform(e[1],t):i[e[0]]=t(e[1])})),t(i)}return t(e)},r.prefixReferences=function(e){return"string"!=typeof e?e:e.replace(n.FIND_REFS,(function(e){if(e.startsWith("%%"))return e;var r=e.charCodeAt(1);return r>47&&r<58?"%"+n.INDEX_NAMESPACE+"."+e.substr(1):"%"+n.SUBS_NAMESPACE+"."+e.substr(1)}))},r.identity=function(e){return e}}},r={};function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.mapper=void 0;var r=t(616);e.mapper=r.createObjectUnpacker()})(),n})()}));
export interface ObjectUnpacker {
convert(referencesObject: any, data: any, mapping: object): object;
}
export declare const createObjectUnpacker: () => ObjectUnpacker;
export declare const createObjectUnpacker: (version?: string | undefined) => ObjectUnpacker;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createObjectUnpacker = void 0;
var loglevel_1 = __importDefault(require("loglevel"));
var ReferencesResolver_1 = require("./ReferencesResolver");
var TransformationInstructions_1 = require("./TransformationInstructions");
var Util_1 = require("./Util");
var createObjectUnpacker = function () {
return new ObjectUnpackerImpl();
var ObjectUnpacker001_1 = require("./ObjectUnpacker001");
var createObjectUnpacker = function (version) {
switch (version) {
case '0.0.18':
case '0.0.19':
case '0.0.20':
case '0.0.21':
default:
return new ObjectUnpacker001_1.ObjectUnpacker001();
}
};
exports.createObjectUnpacker = createObjectUnpacker;
var prefix = '%';
var postfix = '%';
var postfixIsOptional = true;
var referencesResolver = ReferencesResolver_1.createReferencesResolver();
var ObjectUnpackerImpl = (function () {
function ObjectUnpackerImpl() {
}
ObjectUnpackerImpl.prototype.convert = function (referencesObject, rawData, rawMapping) {
try {
var mapping = toTransformationInstructions(rawMapping);
var data = Util_1.transform(rawData, Util_1.prefixReferences);
var dictionary = new Map();
Util_1.indexObject(prefix, postfix, postfixIsOptional, ReferencesResolver_1.INDEX_NAMESPACE, dictionary, data['?']);
Util_1.indexObject(prefix, postfix, postfixIsOptional, ReferencesResolver_1.COMPACT_NAMESPACE, dictionary, data);
Util_1.indexObject(prefix, postfix, postfixIsOptional, ReferencesResolver_1.SUBS_NAMESPACE, dictionary, referencesObject);
var expanded = expandAll(data, mapping, dictionary);
delete expanded['?'];
return referencesResolver.resolve(dictionary, expanded);
}
catch (e) {
loglevel_1.default.error(e.message);
return { error: e.message };
}
};
return ObjectUnpackerImpl;
}());
var toTransformationInstructions = function (rawMapping) {
var result = new Map();
Object.keys(rawMapping).forEach(function (k) {
result.set(k, new TransformationInstructions_1.TransformationInstruction(k, rawMapping[k]));
});
return result;
};
var expandAll = function (data, mapping, dictionary) {
if (data === null) {
return null;
}
if (Array.isArray(data)) {
return data.map(function (k) { return expandAll(k, mapping, dictionary); });
}
if (typeof data === 'object') {
var objectResult_1 = {};
Object.keys(data).forEach(function (k) {
var mapSpec = mapping.get(k);
if (mapSpec && mapSpec.additionalKeys && mapSpec.additionalKeys.has(k)) {
mapSpec = mapSpec.additionalKeys.get(k);
}
if (mapSpec) {
if (mapSpec.isRemovePair()) {
return;
}
var toBeExpanded = typeof data[k] !== 'object' && mapSpec.assignKeys ? [data[k]] : data[k];
var value = expandMapSpec(toBeExpanded, mapSpec, mapping, dictionary);
if (typeof value === 'string') {
if (value.includes('%self')) {
value = resolveSelfRefs(toBeExpanded, value);
}
}
var newKey = mapSpec.transformKey(k);
if (mapSpec.replacePair) {
if (isNonArrayObject(value)) {
var objValue = value;
copyKeysAndValues(objValue, objectResult_1);
}
}
else if (mapSpec.rewriteValue) {
if (mapSpec.resultValue) {
if (typeof mapSpec.resultValue === 'object') {
objectResult_1[newKey] = expandMapSpec(toBeExpanded, mapSpec, mapping, dictionary);
}
else {
if (typeof mapSpec.resultValue === 'string' && mapSpec.resultValue.startsWith('%')) {
var augmentedDictionary_1 = new Map();
dictionary.forEach(function (v, key) { return augmentedDictionary_1.set(key, v); });
Util_1.indexObject(prefix, postfix, postfixIsOptional, '', augmentedDictionary_1, toBeExpanded);
objectResult_1[newKey] = expandMapSpec(toBeExpanded, mapSpec, mapping, augmentedDictionary_1);
}
else {
objectResult_1[newKey] = value;
}
}
}
else {
objectResult_1[newKey] = null;
}
}
else {
objectResult_1[newKey] = value;
}
}
else {
if (dictionary.has(k)) {
objectResult_1[k] = dictionary.get(k);
}
else {
objectResult_1[k] = expandAll(data[k], mapping, dictionary);
}
}
});
return objectResult_1;
}
return data;
};
var expandMapSpec = function (value, mapSpec, mapping, dictionary) {
if (value === null) {
return value;
}
var data = isNonArrayObject(value) ? processAdditionalKeys(value, mapSpec, dictionary) : value;
var params = Array.isArray(data) && mapSpec.assignKeys ? assignParamValues(mapSpec.assignKeys, data) : new Map();
var augmentedDictionary = new Map();
dictionary.forEach(function (v, k) { return augmentedDictionary.set(k, v); });
Util_1.indexObject(prefix, postfix, postfixIsOptional, '', augmentedDictionary, mapToObject(params));
if (mapSpec.isArrayMapping()) {
if (Array.isArray(data)) {
var typeName = mapSpec.arrayItemsName;
var adjustedData = typeName ? arrayToNamedObjects(typeName, data) : data;
if (mapSpec.assignKeys) {
return assignParamValues(mapSpec.assignKeys, adjustedData);
}
return expandAll(adjustedData, mapping, augmentedDictionary);
}
throw new Error('"arrayItems" can only be applied to arrays.');
}
if (mapSpec.resultValue) {
switch (typeof mapSpec.resultValue) {
case 'object': {
if (Array.isArray(mapSpec.resultValue)) {
return produceArrayResult(mapSpec, mapping, augmentedDictionary);
}
else {
return produceObjectResult(mapSpec, data, mapping, augmentedDictionary, params);
}
}
case 'string': {
if (mapSpec.resultValue === '%self') {
return expandAll(data, mapping, augmentedDictionary);
}
else if (mapSpec.resultValue.match('^%[a-zA-Z]+(.[a-zA-Z]+)*$')) {
return augmentedDictionary.get(mapSpec.resultValue);
}
else {
return expandAll(mapSpec.resultValue, mapping, augmentedDictionary);
}
}
default:
return mapSpec.resultValue;
}
}
else if (params.size > 0) {
return expandAll(mapToObject(params), mapping, augmentedDictionary);
}
else {
return expandAll(data, mapping, augmentedDictionary);
}
};
var mapToObject = function (m) {
var result = {};
m.forEach(function (v, k) { return (result[k] = v); });
return result;
};
var assignParamValues = function (paramNames, valuesObject) {
var result = new Map();
if (Array.isArray(valuesObject)) {
paramNames.forEach(function (p, i) {
if (i < valuesObject.length) {
result.set(p, valuesObject[i]);
}
else {
result.set(p, null);
}
});
}
else if (typeof valuesObject === 'object') {
paramNames.forEach(function (p) {
result.set(p, valuesObject[p]);
});
}
else {
paramNames.forEach(function (p, i) {
if (i === 0) {
result.set(p, valuesObject);
}
else {
result.set(p, null);
}
});
}
return result;
};
var arrayToNamedObjects = function (key, data) {
return data.map(function (v) {
var result = {};
result[key] = v;
return result;
});
};
var produceObjectResult = function (mapSpec, data, mapping, augmentedDictionary, params) {
var result = {};
var resultValue = mapSpec.resultValue ? mapSpec.resultValue : data;
Object.keys(resultValue).forEach(function (returnKey) {
var newValue = expandAll(resultValue[returnKey], mapping, augmentedDictionary);
if (typeof newValue === 'string') {
var newValueStr = newValue;
if (isObjectWithProperty(data, newValueStr)) {
var refTarget = data[newValueStr.substr(1)];
if (typeof refTarget === 'object') {
if (targetIsArrayAndMappingExists(refTarget, mapping, newValueStr)) {
result[returnKey] = expandMapSpec(refTarget, mapping.get(newValueStr.substr(1)), mapping, augmentedDictionary);
}
else {
result[returnKey] = expandAll(refTarget, mapping, augmentedDictionary);
}
}
else {
result[returnKey] = refTarget;
}
}
else if (refersToAParameter(newValueStr, params)) {
var refTarget = params.get(newValueStr.substr(1));
if (refTarget && typeof refTarget === 'object') {
if (targetIsArrayAndMappingExists(refTarget, mapping, newValueStr)) {
result[returnKey] = expandMapSpec(refTarget, mapping.get(newValueStr.substr(1)), mapping, augmentedDictionary);
}
else {
result[returnKey] = expandAll(refTarget, mapping, augmentedDictionary);
}
}
else {
result[returnKey] = refTarget;
}
}
else {
if (isAbsoluteReferenceOrNonReference(newValueStr)) {
var extendedDictionary_1 = new Map();
augmentedDictionary.forEach(function (v, k) { return extendedDictionary_1.set(k, v); });
Util_1.indexObject(prefix, postfix, postfixIsOptional, '', extendedDictionary_1, data);
result[returnKey] = referencesResolver.resolve(extendedDictionary_1, newValue);
}
else if (newValueStr.includes('%self')) {
result[returnKey] = resolveSelfRefs(data, newValueStr);
}
else if (augmentedDictionary.has(newValueStr)) {
result[returnKey] = augmentedDictionary.get(newValueStr);
}
else {
result[returnKey] = null;
}
}
}
else {
if (isNonNullObject(newValue)) {
result[returnKey] = referencesResolver.resolve(augmentedDictionary, newValue);
}
else {
result[returnKey] = newValue;
}
}
});
return result;
};
var produceArrayResult = function (mapSpec, mapping, augmentedDictionary) {
if (mapSpec.resultValue && Array.isArray(mapSpec.resultValue)) {
return mapSpec.resultValue.map(function (arrayVal) { return expandMapSpec(arrayVal, mapSpec, mapping, augmentedDictionary); }).filter(function (v) { return v !== null; });
}
return [];
};
var isObjectWithProperty = function (data, ref) {
return typeof data === 'object' && ref.charAt(0) === '%' && data.hasOwnProperty(ref.substr(1));
};
var refersToAParameter = function (ref, params) {
return ref.charAt(0) === '%' && params.has(ref.substr(1));
};
var targetIsArrayAndMappingExists = function (refTarget, mapping, newValueStr) {
return Array.isArray(refTarget) && mapping.has(newValueStr.substr(1));
};
var isAbsoluteReferenceOrNonReference = function (newValueStr) {
return newValueStr.startsWith('%/') || (!newValueStr.startsWith('%') && !newValueStr.includes('%self'));
};
var isNonNullObject = function (newValue) {
return newValue !== null && typeof newValue === 'object';
};
var resolveSelfRefs = function (toBeExpanded, value) {
var self = new Map();
self.set('%self', toBeExpanded);
self.set('%self%', toBeExpanded);
value = referencesResolver.resolve(self, value);
return value;
};
var isNonArrayObject = function (value) {
return value !== null && !Array.isArray(value) && typeof value === 'object';
};
var copyKeysAndValues = function (from, to) {
Object.keys(from).forEach(function (k) {
to[k] = from[k];
});
};
var processAdditionalKeys = function (value, mapSpec, dictionary) {
var valueObj = value;
var newValueObj = {};
for (var k in valueObj) {
if (mapSpec.additionalKeys.has(k)) {
var spec = mapSpec.additionalKeys.get(k);
var newObjKey = spec.transformKey(k);
newValueObj[newObjKey] = expandAll(valueObj[k], spec.additionalKeys, dictionary);
}
else {
newValueObj[k] = valueObj[k];
}
}
return newValueObj;
};
//# sourceMappingURL=ObjectUnpacker.js.map

@@ -16,7 +16,9 @@ "use strict";

this.additionalKeys = new Map();
Object.keys(transform)
.filter(function (ky) { return !mapSpecKeys.includes(ky); })
.forEach(function (ky) {
_this.additionalKeys.set(ky, new TransformationInstruction(ky, transform[ky]));
});
if (typeof transform === 'object' && !Array.isArray(transform)) {
Object.keys(transform)
.filter(function (ky) { return !mapSpecKeys.includes(ky); })
.forEach(function (ky) {
_this.additionalKeys.set(ky, new TransformationInstruction(ky, transform[ky]));
});
}
}

@@ -23,0 +25,0 @@ TransformationInstruction.prototype.transformKey = function (key) {

{
"name": "object-unpacker",
"version": "0.0.18",
"version": "0.0.21",
"description": "A JSON to JSON mapper in TypeScript",

@@ -8,4 +8,3 @@ "main": "dist/index.js",

"dependencies": {
"loglevel": "^1.7.0",
"loglevel-plugin-prefix": "^0.8.4"
"pino": "^7.6.5"
},

@@ -54,2 +53,2 @@ "devDependencies": {

]
}
}

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