@onflow/decode
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -5,2 +5,7 @@ ### Unreleased | ||
### 0.0.5 -- 2020-04-20 | ||
- 2020-04-20 **BREAKING** -- Only export `decode` and `decodeResponse` | ||
- 2020-04-20 -- Removed dependency for `@onflow/bytes` | ||
### 0.0.4 -- 2020-04-18 | ||
@@ -7,0 +12,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/bytes");function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var t=function(e,r,t){try{try{return Promise.resolve(Number(e))}catch(e){throw new Error("Decode Number Error : "+t.join("."))}}catch(e){return Promise.reject(e)}},o=function(e){return Promise.resolve(e)},n=function(){return Promise.resolve(null)},c=function(e,r,t){return Promise.resolve(e?m(e,r,t):null)},s=function(e){try{return Promise.resolve({address:e.address,type:e.type})}catch(e){return Promise.reject(e)}},i=function(e,r,t){try{return Promise.resolve(Promise.all(e.map(function(e){return new Promise(function(o){try{return Promise.resolve(m(e,r,[].concat(t,[e.type]))).then(o)}catch(e){return Promise.reject(e)}})})))}catch(e){return Promise.reject(e)}},u=function(e,r,t){try{return Promise.resolve(e.reduce(function(e,o){try{return Promise.resolve(e).then(function(n){return e=n,Promise.resolve(m(o.key,r,[].concat(t,[o.key]))).then(function(n){return Promise.resolve(m(o.value,r,[].concat(t,[o.key]))).then(function(r){return e[n]=r,e})})})}catch(e){return Promise.reject(e)}},Promise.resolve({})))}catch(e){return Promise.reject(e)}},d=function(e,r,t){try{return Promise.resolve(e.fields.reduce(function(e,o){try{return Promise.resolve(e).then(function(n){return e=n,Promise.resolve(m(o.value,r,[].concat(t,[o.name]))).then(function(r){return e[o.name]=r,e})})}catch(e){return Promise.reject(e)}},Promise.resolve({}))).then(function(t){var o=e.id&&l(r,e.id);return o?Promise.resolve(o(t)):t})}catch(e){return Promise.reject(e)}},a={UInt:t,Int:t,UInt8:t,Int8:t,UInt16:t,Int16:t,UInt32:t,Int32:t,UInt64:t,Int64:t,UInt128:t,Int128:t,UInt256:t,Int256:t,Word8:t,Word16:t,Word32:t,Word64:t,UFix64:t,Fix64:t,String:o,Character:o,Bool:o,Address:o,Void:n,Optional:c,Reference:s,Array:i,Dictionary:u,Event:d,Resource:d,Struct:d},l=function(e,r){var t=Object.keys(e).find(function(e){return/^\/.*\/$/.test(e)?new RegExp(e.substring(1,e.length-1)).test(r):e===r});return r&&t&&e[t]},m=function(e,r,t){try{var o=l(r,e.type);if(!o)throw new Error("Undefined Decoder Error: "+e.type+"@"+t.join("."));return Promise.resolve(o(e.value,r,t))}catch(e){return Promise.reject(e)}},v=function(e,t,o){void 0===t&&(t={}),void 0===o&&(o=[]);var n=r({},a,{},t);return Promise.resolve(m(e,n,o))};exports.decode=v,exports.decodeArray=i,exports.decodeComposite=d,exports.decodeDictionary=u,exports.decodeImplicit=o,exports.decodeNumber=t,exports.decodeOptional=c,exports.decodeReference=s,exports.decodeResponse=function(t,o){void 0===o&&(o={});try{var n=r({},a,{},o),c=e.bytesToString(e.bytes(t.encodedData)),s=JSON.parse(c);return Promise.resolve(v(s,n))}catch(e){return Promise.reject(e)}},exports.decodeVoid=n,exports.decoderLookup=l,exports.defaultDecoders=a,exports.recurseDecode=m; | ||
function r(){return(r=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var e=function(r,e,t){try{try{return Promise.resolve(Number(r))}catch(r){throw new Error("Decode Number Error : "+t.join("."))}}catch(r){return Promise.reject(r)}},t=function(r){return Promise.resolve(r)},n=function(r,e,t){try{return Promise.resolve(r.fields.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(i(n.value,e,[].concat(t,[n.name]))).then(function(e){return r[n.name]=e,r})})}catch(r){return Promise.reject(r)}},Promise.resolve({}))).then(function(t){var n=r.id&&c(e,r.id);return n?Promise.resolve(n(t)):t})}catch(r){return Promise.reject(r)}},o={UInt:e,Int:e,UInt8:e,Int8:e,UInt16:e,Int16:e,UInt32:e,Int32:e,UInt64:e,Int64:e,UInt128:e,Int128:e,UInt256:e,Int256:e,Word8:e,Word16:e,Word32:e,Word64:e,UFix64:e,Fix64:e,String:t,Character:t,Bool:t,Address:t,Void:function(){return Promise.resolve(null)},Optional:function(r,e,t){return Promise.resolve(r?i(r,e,t):null)},Reference:function(r){try{return Promise.resolve({address:r.address,type:r.type})}catch(r){return Promise.reject(r)}},Array:function(r,e,t){try{return Promise.resolve(Promise.all(r.map(function(r){return new Promise(function(n){try{return Promise.resolve(i(r,e,[].concat(t,[r.type]))).then(n)}catch(r){return Promise.reject(r)}})})))}catch(r){return Promise.reject(r)}},Dictionary:function(r,e,t){try{return Promise.resolve(r.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(i(n.key,e,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(i(n.value,e,[].concat(t,[n.key]))).then(function(e){return r[o]=e,r})})})}catch(r){return Promise.reject(r)}},Promise.resolve({})))}catch(r){return Promise.reject(r)}},Event:n,Resource:n,Struct:n},c=function(r,e){var t=Object.keys(r).find(function(r){return/^\/.*\/$/.test(r)?new RegExp(r.substring(1,r.length-1)).test(e):r===e});return e&&t&&r[t]},i=function(r,e,t){try{var n=c(e,r.type);if(!n)throw new Error("Undefined Decoder Error: "+r.type+"@"+t.join("."));return Promise.resolve(n(r.value,e,t))}catch(r){return Promise.reject(r)}},s=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]);var c=r({},o,{},t);return Promise.resolve(i(e,c,n))};exports.decode=s,exports.decodeResponse=function(e,t){void 0===t&&(t={});try{var n=r({},o,{},t),c=Buffer.from(e.encodedData).toString("utf8"),i=JSON.parse(c);return Promise.resolve(s(i,n))}catch(r){return Promise.reject(r)}}; | ||
//# sourceMappingURL=decode.js.map |
@@ -1,2 +0,2 @@ | ||
import{bytesToString as r,bytes as e}from"@onflow/bytes";function t(){return(t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var n=function(r,e,t){try{try{return Promise.resolve(Number(r))}catch(r){throw new Error("Decode Number Error : "+t.join("."))}}catch(r){return Promise.reject(r)}},o=function(r){return Promise.resolve(r)},i=function(){return Promise.resolve(null)},c=function(r,e,t){return Promise.resolve(r?f(r,e,t):null)},u=function(r){try{return Promise.resolve({address:r.address,type:r.type})}catch(r){return Promise.reject(r)}},s=function(r,e,t){try{return Promise.resolve(Promise.all(r.map(function(r){return new Promise(function(n){try{return Promise.resolve(f(r,e,[].concat(t,[r.type]))).then(n)}catch(r){return Promise.reject(r)}})})))}catch(r){return Promise.reject(r)}},a=function(r,e,t){try{return Promise.resolve(r.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(f(n.key,e,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(f(n.value,e,[].concat(t,[n.key]))).then(function(e){return r[o]=e,r})})})}catch(r){return Promise.reject(r)}},Promise.resolve({})))}catch(r){return Promise.reject(r)}},m=function(r,e,t){try{return Promise.resolve(r.fields.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(f(n.value,e,[].concat(t,[n.name]))).then(function(e){return r[n.name]=e,r})})}catch(r){return Promise.reject(r)}},Promise.resolve({}))).then(function(t){var n=r.id&&v(e,r.id);return n?Promise.resolve(n(t)):t})}catch(r){return Promise.reject(r)}},l={UInt:n,Int:n,UInt8:n,Int8:n,UInt16:n,Int16:n,UInt32:n,Int32:n,UInt64:n,Int64:n,UInt128:n,Int128:n,UInt256:n,Int256:n,Word8:n,Word16:n,Word32:n,Word64:n,UFix64:n,Fix64:n,String:o,Character:o,Bool:o,Address:o,Void:i,Optional:c,Reference:u,Array:s,Dictionary:a,Event:m,Resource:m,Struct:m},v=function(r,e){var t=Object.keys(r).find(function(r){return/^\/.*\/$/.test(r)?new RegExp(r.substring(1,r.length-1)).test(e):r===e});return e&&t&&r[t]},f=function(r,e,t){try{var n=v(e,r.type);if(!n)throw new Error("Undefined Decoder Error: "+r.type+"@"+t.join("."));return Promise.resolve(n(r.value,e,t))}catch(r){return Promise.reject(r)}},P=function(r,e,n){void 0===e&&(e={}),void 0===n&&(n=[]);var o=t({},l,{},e);return Promise.resolve(f(r,o,n))},d=function(n,o){void 0===o&&(o={});try{var i=t({},l,{},o),c=r(e(n.encodedData)),u=JSON.parse(c);return Promise.resolve(P(u,i))}catch(r){return Promise.reject(r)}};export{P as decode,s as decodeArray,m as decodeComposite,a as decodeDictionary,o as decodeImplicit,n as decodeNumber,c as decodeOptional,u as decodeReference,d as decodeResponse,i as decodeVoid,v as decoderLookup,l as defaultDecoders,f as recurseDecode}; | ||
function r(){return(r=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var e=function(r,e,t){try{try{return Promise.resolve(Number(r))}catch(r){throw new Error("Decode Number Error : "+t.join("."))}}catch(r){return Promise.reject(r)}},t=function(r){return Promise.resolve(r)},n=function(r,e,t){try{return Promise.resolve(r.fields.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(c(n.value,e,[].concat(t,[n.name]))).then(function(e){return r[n.name]=e,r})})}catch(r){return Promise.reject(r)}},Promise.resolve({}))).then(function(t){var n=r.id&&i(e,r.id);return n?Promise.resolve(n(t)):t})}catch(r){return Promise.reject(r)}},o={UInt:e,Int:e,UInt8:e,Int8:e,UInt16:e,Int16:e,UInt32:e,Int32:e,UInt64:e,Int64:e,UInt128:e,Int128:e,UInt256:e,Int256:e,Word8:e,Word16:e,Word32:e,Word64:e,UFix64:e,Fix64:e,String:t,Character:t,Bool:t,Address:t,Void:function(){return Promise.resolve(null)},Optional:function(r,e,t){return Promise.resolve(r?c(r,e,t):null)},Reference:function(r){try{return Promise.resolve({address:r.address,type:r.type})}catch(r){return Promise.reject(r)}},Array:function(r,e,t){try{return Promise.resolve(Promise.all(r.map(function(r){return new Promise(function(n){try{return Promise.resolve(c(r,e,[].concat(t,[r.type]))).then(n)}catch(r){return Promise.reject(r)}})})))}catch(r){return Promise.reject(r)}},Dictionary:function(r,e,t){try{return Promise.resolve(r.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(c(n.key,e,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(c(n.value,e,[].concat(t,[n.key]))).then(function(e){return r[o]=e,r})})})}catch(r){return Promise.reject(r)}},Promise.resolve({})))}catch(r){return Promise.reject(r)}},Event:n,Resource:n,Struct:n},i=function(r,e){var t=Object.keys(r).find(function(r){return/^\/.*\/$/.test(r)?new RegExp(r.substring(1,r.length-1)).test(e):r===e});return e&&t&&r[t]},c=function(r,e,t){try{var n=i(e,r.type);if(!n)throw new Error("Undefined Decoder Error: "+r.type+"@"+t.join("."));return Promise.resolve(n(r.value,e,t))}catch(r){return Promise.reject(r)}},u=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]);var i=r({},o,{},t);return Promise.resolve(c(e,i,n))},s=function(e,t){void 0===t&&(t={});try{var n=r({},o,{},t),i=Buffer.from(e.encodedData).toString("utf8"),c=JSON.parse(i);return Promise.resolve(u(c,n))}catch(r){return Promise.reject(r)}};export{u as decode,s as decodeResponse}; | ||
//# sourceMappingURL=decode.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{bytesToString as r,bytes as e}from"@onflow/bytes";function t(){return(t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var n=function(r,e,t){try{try{return Promise.resolve(Number(r))}catch(r){throw new Error("Decode Number Error : "+t.join("."))}}catch(r){return Promise.reject(r)}},o=function(r){return Promise.resolve(r)},i=function(){return Promise.resolve(null)},c=function(r,e,t){return Promise.resolve(r?f(r,e,t):null)},u=function(r){try{return Promise.resolve({address:r.address,type:r.type})}catch(r){return Promise.reject(r)}},s=function(r,e,t){try{return Promise.resolve(Promise.all(r.map(function(r){return new Promise(function(n){try{return Promise.resolve(f(r,e,[].concat(t,[r.type]))).then(n)}catch(r){return Promise.reject(r)}})})))}catch(r){return Promise.reject(r)}},a=function(r,e,t){try{return Promise.resolve(r.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(f(n.key,e,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(f(n.value,e,[].concat(t,[n.key]))).then(function(e){return r[o]=e,r})})})}catch(r){return Promise.reject(r)}},Promise.resolve({})))}catch(r){return Promise.reject(r)}},m=function(r,e,t){try{return Promise.resolve(r.fields.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(f(n.value,e,[].concat(t,[n.name]))).then(function(e){return r[n.name]=e,r})})}catch(r){return Promise.reject(r)}},Promise.resolve({}))).then(function(t){var n=r.id&&v(e,r.id);return n?Promise.resolve(n(t)):t})}catch(r){return Promise.reject(r)}},l={UInt:n,Int:n,UInt8:n,Int8:n,UInt16:n,Int16:n,UInt32:n,Int32:n,UInt64:n,Int64:n,UInt128:n,Int128:n,UInt256:n,Int256:n,Word8:n,Word16:n,Word32:n,Word64:n,UFix64:n,Fix64:n,String:o,Character:o,Bool:o,Address:o,Void:i,Optional:c,Reference:u,Array:s,Dictionary:a,Event:m,Resource:m,Struct:m},v=function(r,e){var t=Object.keys(r).find(function(r){return/^\/.*\/$/.test(r)?new RegExp(r.substring(1,r.length-1)).test(e):r===e});return e&&t&&r[t]},f=function(r,e,t){try{var n=v(e,r.type);if(!n)throw new Error("Undefined Decoder Error: "+r.type+"@"+t.join("."));return Promise.resolve(n(r.value,e,t))}catch(r){return Promise.reject(r)}},P=function(r,e,n){void 0===e&&(e={}),void 0===n&&(n=[]);var o=t({},l,{},e);return Promise.resolve(f(r,o,n))},d=function(n,o){void 0===o&&(o={});try{var i=t({},l,{},o),c=r(e(n.encodedData)),u=JSON.parse(c);return Promise.resolve(P(u,i))}catch(r){return Promise.reject(r)}};export{P as decode,s as decodeArray,m as decodeComposite,a as decodeDictionary,o as decodeImplicit,n as decodeNumber,c as decodeOptional,u as decodeReference,d as decodeResponse,i as decodeVoid,v as decoderLookup,l as defaultDecoders,f as recurseDecode}; | ||
function r(){return(r=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}var e=function(r,e,t){try{try{return Promise.resolve(Number(r))}catch(r){throw new Error("Decode Number Error : "+t.join("."))}}catch(r){return Promise.reject(r)}},t=function(r){return Promise.resolve(r)},n=function(r,e,t){try{return Promise.resolve(r.fields.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(c(n.value,e,[].concat(t,[n.name]))).then(function(e){return r[n.name]=e,r})})}catch(r){return Promise.reject(r)}},Promise.resolve({}))).then(function(t){var n=r.id&&i(e,r.id);return n?Promise.resolve(n(t)):t})}catch(r){return Promise.reject(r)}},o={UInt:e,Int:e,UInt8:e,Int8:e,UInt16:e,Int16:e,UInt32:e,Int32:e,UInt64:e,Int64:e,UInt128:e,Int128:e,UInt256:e,Int256:e,Word8:e,Word16:e,Word32:e,Word64:e,UFix64:e,Fix64:e,String:t,Character:t,Bool:t,Address:t,Void:function(){return Promise.resolve(null)},Optional:function(r,e,t){return Promise.resolve(r?c(r,e,t):null)},Reference:function(r){try{return Promise.resolve({address:r.address,type:r.type})}catch(r){return Promise.reject(r)}},Array:function(r,e,t){try{return Promise.resolve(Promise.all(r.map(function(r){return new Promise(function(n){try{return Promise.resolve(c(r,e,[].concat(t,[r.type]))).then(n)}catch(r){return Promise.reject(r)}})})))}catch(r){return Promise.reject(r)}},Dictionary:function(r,e,t){try{return Promise.resolve(r.reduce(function(r,n){try{return Promise.resolve(r).then(function(o){return r=o,Promise.resolve(c(n.key,e,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(c(n.value,e,[].concat(t,[n.key]))).then(function(e){return r[o]=e,r})})})}catch(r){return Promise.reject(r)}},Promise.resolve({})))}catch(r){return Promise.reject(r)}},Event:n,Resource:n,Struct:n},i=function(r,e){var t=Object.keys(r).find(function(r){return/^\/.*\/$/.test(r)?new RegExp(r.substring(1,r.length-1)).test(e):r===e});return e&&t&&r[t]},c=function(r,e,t){try{var n=i(e,r.type);if(!n)throw new Error("Undefined Decoder Error: "+r.type+"@"+t.join("."));return Promise.resolve(n(r.value,e,t))}catch(r){return Promise.reject(r)}},u=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]);var i=r({},o,{},t);return Promise.resolve(c(e,i,n))},s=function(e,t){void 0===t&&(t={});try{var n=r({},o,{},t),i=Buffer.from(e.encodedData).toString("utf8"),c=JSON.parse(i);return Promise.resolve(u(c,n))}catch(r){return Promise.reject(r)}};export{u as decode,s as decodeResponse}; | ||
//# sourceMappingURL=decode.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@onflow/bytes")):"function"==typeof define&&define.amd?define(["exports","@onflow/bytes"],r):r((e=e||self).decode={},e.bytes)}(this,function(e,r){function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var n=function(e,r,t){try{try{return Promise.resolve(Number(e))}catch(e){throw new Error("Decode Number Error : "+t.join("."))}}catch(e){return Promise.reject(e)}},o=function(e){return Promise.resolve(e)},c=function(){return Promise.resolve(null)},i=function(e,r,t){return Promise.resolve(e?m(e,r,t):null)},s=function(e){try{return Promise.resolve({address:e.address,type:e.type})}catch(e){return Promise.reject(e)}},u=function(e,r,t){try{return Promise.resolve(Promise.all(e.map(function(e){return new Promise(function(n){try{return Promise.resolve(m(e,r,[].concat(t,[e.type]))).then(n)}catch(e){return Promise.reject(e)}})})))}catch(e){return Promise.reject(e)}},d=function(e,r,t){try{return Promise.resolve(e.reduce(function(e,n){try{return Promise.resolve(e).then(function(o){return e=o,Promise.resolve(m(n.key,r,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(m(n.value,r,[].concat(t,[n.key]))).then(function(r){return e[o]=r,e})})})}catch(e){return Promise.reject(e)}},Promise.resolve({})))}catch(e){return Promise.reject(e)}},a=function(e,r,t){try{return Promise.resolve(e.fields.reduce(function(e,n){try{return Promise.resolve(e).then(function(o){return e=o,Promise.resolve(m(n.value,r,[].concat(t,[n.name]))).then(function(r){return e[n.name]=r,e})})}catch(e){return Promise.reject(e)}},Promise.resolve({}))).then(function(t){var n=e.id&&l(r,e.id);return n?Promise.resolve(n(t)):t})}catch(e){return Promise.reject(e)}},f={UInt:n,Int:n,UInt8:n,Int8:n,UInt16:n,Int16:n,UInt32:n,Int32:n,UInt64:n,Int64:n,UInt128:n,Int128:n,UInt256:n,Int256:n,Word8:n,Word16:n,Word32:n,Word64:n,UFix64:n,Fix64:n,String:o,Character:o,Bool:o,Address:o,Void:c,Optional:i,Reference:s,Array:u,Dictionary:d,Event:a,Resource:a,Struct:a},l=function(e,r){var t=Object.keys(e).find(function(e){return/^\/.*\/$/.test(e)?new RegExp(e.substring(1,e.length-1)).test(r):e===r});return r&&t&&e[t]},m=function(e,r,t){try{var n=l(r,e.type);if(!n)throw new Error("Undefined Decoder Error: "+e.type+"@"+t.join("."));return Promise.resolve(n(e.value,r,t))}catch(e){return Promise.reject(e)}},v=function(e,r,n){void 0===r&&(r={}),void 0===n&&(n=[]);var o=t({},f,{},r);return Promise.resolve(m(e,o,n))};e.decode=v,e.decodeArray=u,e.decodeComposite=a,e.decodeDictionary=d,e.decodeImplicit=o,e.decodeNumber=n,e.decodeOptional=i,e.decodeReference=s,e.decodeResponse=function(e,n){void 0===n&&(n={});try{var o=t({},f,{},n),c=r.bytesToString(r.bytes(e.encodedData)),i=JSON.parse(c);return Promise.resolve(v(i,o))}catch(e){return Promise.reject(e)}},e.decodeVoid=c,e.decoderLookup=l,e.defaultDecoders=f,e.recurseDecode=m}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).decode={})}(this,function(e){function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var t=function(e,r,t){try{try{return Promise.resolve(Number(e))}catch(e){throw new Error("Decode Number Error : "+t.join("."))}}catch(e){return Promise.reject(e)}},n=function(e){return Promise.resolve(e)},o=function(e,r,t){try{return Promise.resolve(e.fields.reduce(function(e,n){try{return Promise.resolve(e).then(function(o){return e=o,Promise.resolve(u(n.value,r,[].concat(t,[n.name]))).then(function(r){return e[n.name]=r,e})})}catch(e){return Promise.reject(e)}},Promise.resolve({}))).then(function(t){var n=e.id&&c(r,e.id);return n?Promise.resolve(n(t)):t})}catch(e){return Promise.reject(e)}},i={UInt:t,Int:t,UInt8:t,Int8:t,UInt16:t,Int16:t,UInt32:t,Int32:t,UInt64:t,Int64:t,UInt128:t,Int128:t,UInt256:t,Int256:t,Word8:t,Word16:t,Word32:t,Word64:t,UFix64:t,Fix64:t,String:n,Character:n,Bool:n,Address:n,Void:function(){return Promise.resolve(null)},Optional:function(e,r,t){return Promise.resolve(e?u(e,r,t):null)},Reference:function(e){try{return Promise.resolve({address:e.address,type:e.type})}catch(e){return Promise.reject(e)}},Array:function(e,r,t){try{return Promise.resolve(Promise.all(e.map(function(e){return new Promise(function(n){try{return Promise.resolve(u(e,r,[].concat(t,[e.type]))).then(n)}catch(e){return Promise.reject(e)}})})))}catch(e){return Promise.reject(e)}},Dictionary:function(e,r,t){try{return Promise.resolve(e.reduce(function(e,n){try{return Promise.resolve(e).then(function(o){return e=o,Promise.resolve(u(n.key,r,[].concat(t,[n.key]))).then(function(o){return Promise.resolve(u(n.value,r,[].concat(t,[n.key]))).then(function(r){return e[o]=r,e})})})}catch(e){return Promise.reject(e)}},Promise.resolve({})))}catch(e){return Promise.reject(e)}},Event:o,Resource:o,Struct:o},c=function(e,r){var t=Object.keys(e).find(function(e){return/^\/.*\/$/.test(e)?new RegExp(e.substring(1,e.length-1)).test(r):e===r});return r&&t&&e[t]},u=function(e,r,t){try{var n=c(r,e.type);if(!n)throw new Error("Undefined Decoder Error: "+e.type+"@"+t.join("."));return Promise.resolve(n(e.value,r,t))}catch(e){return Promise.reject(e)}},s=function(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]);var o=r({},i,{},t);return Promise.resolve(u(e,o,n))};e.decode=s,e.decodeResponse=function(e,t){void 0===t&&(t={});try{var n=r({},i,{},t),o=Buffer.from(e.encodedData).toString("utf8"),c=JSON.parse(o);return Promise.resolve(s(c,n))}catch(e){return Promise.reject(e)}}}); | ||
//# sourceMappingURL=decode.umd.js.map |
{ | ||
"name": "@onflow/decode", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Flow SDK Decoder", | ||
@@ -35,6 +35,3 @@ "license": "Apache-2.0", | ||
"start": "microbundle watch" | ||
}, | ||
"dependencies": { | ||
"@onflow/bytes": "0.0.1" | ||
} | ||
} |
@@ -1,4 +0,2 @@ | ||
import {bytes, bytesToString} from "@onflow/bytes" | ||
export const decodeNumber = async (num, _, stack) => { | ||
const decodeNumber = async (num, _, stack) => { | ||
try { | ||
@@ -11,16 +9,16 @@ return Number(num) | ||
export const decodeImplicit = async (i) => i | ||
const decodeImplicit = async i => i | ||
export const decodeVoid = async () => null | ||
const decodeVoid = async () => null | ||
export const decodeOptional = async (optional, decoders, stack) => | ||
const decodeOptional = async (optional, decoders, stack) => | ||
optional ? await recurseDecode(optional, decoders, stack) : null | ||
export const decodeReference = async (v) => ({address: v.address, type: v.type}) | ||
const decodeReference = async v => ({address: v.address, type: v.type}) | ||
export const decodeArray = async (array, decoders, stack) => | ||
const decodeArray = async (array, decoders, stack) => | ||
await Promise.all( | ||
array.map( | ||
(v) => | ||
new Promise(async (res) => | ||
v => | ||
new Promise(async res => | ||
res(await recurseDecode(v, decoders, [...stack, v.type])) | ||
@@ -31,3 +29,3 @@ ) | ||
export const decodeDictionary = async (dictionary, decoders, stack) => | ||
const decodeDictionary = async (dictionary, decoders, stack) => | ||
await dictionary.reduce(async (acc, v) => { | ||
@@ -41,3 +39,3 @@ acc = await acc | ||
export const decodeComposite = async (composite, decoders, stack) => { | ||
const decodeComposite = async (composite, decoders, stack) => { | ||
const decoded = await composite.fields.reduce(async (acc, v) => { | ||
@@ -52,3 +50,3 @@ acc = await acc | ||
export const defaultDecoders = { | ||
const defaultDecoders = { | ||
UInt: decodeNumber, | ||
@@ -88,7 +86,7 @@ Int: decodeNumber, | ||
export const decoderLookup = (decoders, lookup) => { | ||
const decoderLookup = (decoders, lookup) => { | ||
const found = Object.keys(decoders).find(decoder => { | ||
if (/^\/.*\/$/.test(decoder)) { | ||
const reg = new RegExp(decoder.substring(1, decoder.length - 1)) | ||
return reg.test(lookup) | ||
return reg.test(lookup) | ||
} | ||
@@ -100,3 +98,3 @@ return decoder === lookup | ||
export const recurseDecode = async (decodeInstructions, decoders, stack) => { | ||
const recurseDecode = async (decodeInstructions, decoders, stack) => { | ||
let decoder = decoderLookup(decoders, decodeInstructions.type) | ||
@@ -123,3 +121,3 @@ if (!decoder) | ||
const encoded = response.encodedData | ||
const decodeInstructions = bytesToString(bytes(encoded)) | ||
const decodeInstructions = Buffer.from(encoded).toString("utf8") | ||
const decodeInstructionsJson = JSON.parse(decodeInstructions) | ||
@@ -126,0 +124,0 @@ |
@@ -1,3 +0,27 @@ | ||
import {decode} from "./decode" | ||
import * as root from "./decode" | ||
import {decode, decodeResponse} from "./decode" | ||
it("exported interface contract", () => { | ||
expect(root).toStrictEqual( | ||
expect.objectContaining({ | ||
decode: expect.any(Function), | ||
decodeResponse: expect.any(Function), | ||
}) | ||
) | ||
}) | ||
it("decodeResponse", async () => { | ||
const response = { | ||
encodedData: Uint8Array.from( | ||
Buffer.from( | ||
"7b2274797065223a22496e74222c2276616c7565223a2237227d0a", | ||
"hex" | ||
) | ||
), | ||
} | ||
const data = await decodeResponse(response) | ||
expect(data).toBe(7) | ||
}) | ||
describe("unit tests to cover all types", () => { | ||
@@ -99,3 +123,5 @@ it("returns the correct response given a json-cdc payload 2 OPTIONAL", async () => { | ||
expect(decoded).toStrictEqual(115792089237316195423570985008687907853269984665640564039457584007913129639945) | ||
expect(decoded).toStrictEqual( | ||
115792089237316195423570985008687907853269984665640564039457584007913129639945 | ||
) | ||
}) | ||
@@ -112,3 +138,5 @@ | ||
expect(decoded).toStrictEqual(-57896044618658097711785492504343953926634992332820282019728792003956564819978) | ||
expect(decoded).toStrictEqual( | ||
-57896044618658097711785492504343953926634992332820282019728792003956564819978 | ||
) | ||
}) | ||
@@ -176,3 +204,5 @@ | ||
expect(decoded).toStrictEqual(57896044618658097711785492504343953926634992332820282019728792003956564819967) | ||
expect(decoded).toStrictEqual( | ||
57896044618658097711785492504343953926634992332820282019728792003956564819967 | ||
) | ||
}) | ||
@@ -189,3 +219,5 @@ | ||
expect(decoded).toStrictEqual(115792089237316195423570985008687907853269984665640564039457584007913129639945) | ||
expect(decoded).toStrictEqual( | ||
115792089237316195423570985008687907853269984665640564039457584007913129639945 | ||
) | ||
}) | ||
@@ -245,3 +277,5 @@ | ||
expect(decoded).toStrictEqual(115792089237316195423570985008687907853269984665640564039457584007913129639935) | ||
expect(decoded).toStrictEqual( | ||
115792089237316195423570985008687907853269984665640564039457584007913129639935 | ||
) | ||
}) | ||
@@ -317,3 +351,3 @@ | ||
expect(decoded).toStrictEqual([1,2,3]) | ||
expect(decoded).toStrictEqual([1, 2, 3]) | ||
}) | ||
@@ -704,3 +738,3 @@ | ||
const arr = Array.from({length: dictionaryLength}).reduce( | ||
(acc) => { | ||
acc => { | ||
const {payload: valPayload, decoded: val} = OPTIONS[ | ||
@@ -757,3 +791,3 @@ ~~(Math.random() * OPTIONS.length) | ||
const res = Array.from({length: fieldsLength}).reduce( | ||
(acc) => { | ||
acc => { | ||
const {payload: valPayload, decoded: val} = OPTIONS[ | ||
@@ -810,3 +844,3 @@ ~~(Math.random() * OPTIONS.length) | ||
const res = Array.from({length: fieldsLength}).reduce( | ||
(acc) => { | ||
acc => { | ||
const {payload: valPayload, decoded: val} = OPTIONS[ | ||
@@ -863,3 +897,3 @@ ~~(Math.random() * OPTIONS.length) | ||
const res = Array.from({length: fieldsLength}).reduce( | ||
(acc) => { | ||
acc => { | ||
const {payload: valPayload, decoded: val} = OPTIONS[ | ||
@@ -916,3 +950,3 @@ ~~(Math.random() * OPTIONS.length) | ||
const arr = Array.from({length: fieldsLength}).reduce( | ||
(acc) => { | ||
acc => { | ||
const {payload, decoded} = OPTIONS[~~(Math.random() * OPTIONS.length)]() | ||
@@ -939,3 +973,3 @@ acc.values.push(payload) | ||
const times = (fn) => { | ||
const times = fn => { | ||
const OPTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
@@ -962,4 +996,4 @@ return Array.from({length: OPTS[~~(Math.random() * OPTS.length)]}, () => fn) | ||
] | ||
.filter((d) => d != null) | ||
.map((d) => { | ||
.filter(d => d != null) | ||
.map(d => { | ||
return typeof d === "function" ? d() : d | ||
@@ -969,3 +1003,5 @@ }) | ||
it(label, async () => | ||
expect(await decode(payload, custom || undefined)).toStrictEqual(decoded) | ||
expect(await decode(payload, custom || undefined)).toStrictEqual( | ||
decoded | ||
) | ||
) | ||
@@ -985,3 +1021,3 @@ }) | ||
const fooDecoder = async (resource) => ({ | ||
const fooDecoder = async resource => ({ | ||
hello: "world", | ||
@@ -1004,8 +1040,8 @@ }) | ||
{name: "firstName", value: {type: "String", value: "Jeff"}}, | ||
{name: "lastName", value: {type: "String", value: "Doyle"}} | ||
] | ||
} | ||
{name: "lastName", value: {type: "String", value: "Doyle"}}, | ||
], | ||
}, | ||
} | ||
const Jeff = function (resource) { | ||
const Jeff = function(resource) { | ||
if (!(this instanceof Jeff)) return new Jeff(resource) | ||
@@ -1017,7 +1053,7 @@ this.firstName = resource.firstName | ||
const jeffDecoder = async (resource) => { | ||
const jeffDecoder = async resource => { | ||
return Jeff(resource) | ||
} | ||
const decoded = await decode(resource, { "test.Jeff": jeffDecoder }, []) | ||
const decoded = await decode(resource, {"test.Jeff": jeffDecoder}, []) | ||
@@ -1034,25 +1070,31 @@ expect(decoded.printName()).toStrictEqual("Jeff Doyle") | ||
{name: "kittyName", value: {type: "String", value: "Sir Meowsers"}}, | ||
{name: "kittyHat", value: { | ||
type: "Resource", | ||
{ | ||
name: "kittyHat", | ||
value: { | ||
id: "test.CryptoKittyHat", | ||
fields: [ | ||
{name: "kittyHatName", value: {type: "String", value: "Yankee With No Brim"}} | ||
] | ||
} | ||
}} | ||
] | ||
} | ||
type: "Resource", | ||
value: { | ||
id: "test.CryptoKittyHat", | ||
fields: [ | ||
{ | ||
name: "kittyHatName", | ||
value: {type: "String", value: "Yankee With No Brim"}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
const kittyHatDecoder = async (kittyHat) => ({ | ||
name: kittyHat.kittyHatName | ||
const kittyHatDecoder = async kittyHat => ({ | ||
name: kittyHat.kittyHatName, | ||
}) | ||
const kittyDecoder = async (kitty) => ({ | ||
const kittyDecoder = async kitty => ({ | ||
name: kitty.kittyName, | ||
hat: kitty.kittyHat | ||
hat: kitty.kittyHat, | ||
}) | ||
const decoded = await decode(resource, { | ||
const decoded = await decode(resource, { | ||
"/test.CryptoKitty$/": kittyDecoder, | ||
@@ -1065,4 +1107,4 @@ "/test.CryptoKittyHat$/": kittyHatDecoder, | ||
hat: { | ||
name: "Yankee With No Brim" | ||
} | ||
name: "Yankee With No Brim", | ||
}, | ||
}) | ||
@@ -1078,25 +1120,31 @@ }) | ||
{name: "kittyName", value: {type: "String", value: "Sir Meowsers"}}, | ||
{name: "kittyHat", value: { | ||
type: "Resource", | ||
{ | ||
name: "kittyHat", | ||
value: { | ||
id: "test.CryptoKittyHat", | ||
fields: [ | ||
{name: "kittyHatName", value: {type: "String", value: "Yankee With No Brim"}} | ||
] | ||
} | ||
}} | ||
] | ||
} | ||
type: "Resource", | ||
value: { | ||
id: "test.CryptoKittyHat", | ||
fields: [ | ||
{ | ||
name: "kittyHatName", | ||
value: {type: "String", value: "Yankee With No Brim"}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
const kittyHatDecoder = async (kittyHat) => ({ | ||
name: kittyHat.kittyHatName | ||
const kittyHatDecoder = async kittyHat => ({ | ||
name: kittyHat.kittyHatName, | ||
}) | ||
const kittyDecoder = async (kitty) => ({ | ||
const kittyDecoder = async kitty => ({ | ||
name: kitty.kittyName, | ||
hat: kitty.kittyHat | ||
hat: kitty.kittyHat, | ||
}) | ||
const decoded = await decode(resource, { | ||
const decoded = await decode(resource, { | ||
"/.CryptoKittyHat$/": kittyHatDecoder, | ||
@@ -1109,6 +1157,6 @@ "/.CryptoKitty$/": kittyDecoder, | ||
hat: { | ||
name: "Yankee With No Brim" | ||
} | ||
name: "Yankee With No Brim", | ||
}, | ||
}) | ||
}) | ||
}) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
1123
1
72260
- Removed@onflow/bytes@0.0.1
- Removed@onflow/bytes@0.0.1(transitive)