@iota-pico/core
Version:
IOTA Pico Framework Core
16 lines (14 loc) • 16.3 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("@iota-pico/core",[],e):"object"==typeof exports?exports["@iota-pico/core"]=e():t.IotaPicoCore=e()}("undefined"!=typeof self?self: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=10)}([function(t,e){Object.defineProperty(e,"__esModule",{value:!0});class r{static isString(t){return null!==t&&void 0!==t&&"[object String]"===Object.prototype.toString.call(t)}static isEmpty(t){return!r.isString(t)||0===t.length}static isASCII(t){return null!==t&&void 0!==t&&/^[\x00-\x7F]*$/.test(t)}static encodeNonASCII(t){return r.isString(t)?t.replace(/[\u0080-\uFFFF]/g,t=>`\\u${`0000${t.charCodeAt(0).toString(16)}`.substr(-4)}`):void 0}static decodeNonASCII(t){return r.isString(t)?t.replace(/\\u([\d\w]{4})/gi,(t,e)=>String.fromCharCode(parseInt(e,16))):void 0}}e.StringHelper=r},function(t,e){Object.defineProperty(e,"__esModule",{value:!0});class r{static isEmpty(t){return null===t||void 0===t}static isObject(t){return null!==t&&void 0!==t&&"object"==typeof t&&!Array.isArray(t)}static isType(t,e){const n=r.getClassName(t);return void 0!==n&&n===r.getClassName(e)}static getClassName(t){if(null!==t&&void 0!==t){const e=("function"==typeof t?t.toString():t.constructor.toString()).match(/\w+/g);return e&&e.length>1?e[1]:void 0}}}e.ObjectHelper=r},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(4),o=r(0);e.CoreError=class extends Error{constructor(t,e,r){super(t),this.additional=e||{},this.innerError=r,this.domain="Core"}static isError(t){return void 0!==t&&null!==t&&"object"==typeof t&&"message"in t&&"additional"in t}format(){let t="";o.StringHelper.isEmpty(this.domain)||(t+=`${this.domain}: `),o.StringHelper.isEmpty(this.message)||(t+=`${this.message}`);const e=Object.keys(this.additional);return e.length>0&&(t.length>0&&(t+="\n"),e.forEach(e=>{t+=`\t${e}: ${n.JsonHelper.stringify(this.additional[e])}\n`})),t}}},function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.FactoryBase=class{constructor(){this._types={}}register(t,e){this.getInstance()._types[t]=e}unregister(t){delete this.getInstance()._types[t]}exists(t){return void 0!==this.getInstance()._types[t]}types(){return Object.keys(this.getInstance()._types)}create(t,...e){const r=this.getInstance();return r._types[t]?r._types[t](...e):void 0}}},function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.JsonHelper=class{static stringify(t,e,r){const n=[];return JSON.stringify(t,(r,o)=>{if("object"==typeof o&&null!==t&&void 0!==o){if(-1!==n.indexOf(o))return;n.push(o)}return e?e(r,o):o},r)}}},function(t,e,r){"use strict";r.r(e),r.d(e,"__extends",function(){return o}),r.d(e,"__assign",function(){return i}),r.d(e,"__rest",function(){return s}),r.d(e,"__decorate",function(){return c}),r.d(e,"__param",function(){return a}),r.d(e,"__metadata",function(){return u}),r.d(e,"__awaiter",function(){return l}),r.d(e,"__generator",function(){return f}),r.d(e,"__exportStar",function(){return p}),r.d(e,"__values",function(){return d}),r.d(e,"__read",function(){return _}),r.d(e,"__spread",function(){return y}),r.d(e,"__await",function(){return g}),r.d(e,"__asyncGenerator",function(){return h}),r.d(e,"__asyncDelegator",function(){return b}),r.d(e,"__asyncValues",function(){return m}),r.d(e,"__makeTemplateObject",function(){return v}),r.d(e,"__importStar",function(){return O}),r.d(e,"__importDefault",function(){return j});
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function o(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var i=function(){return(i=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&(r[n[o]]=t[n[o]])}return r}function c(t,e,r,n){var o,i=arguments.length,s=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s}function a(t,e){return function(r,n){e(r,n,t)}}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function l(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{a(n.next(t))}catch(t){i(t)}}function c(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,c)}a((n=n.apply(t,e||[])).next())})}function f(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function p(t,e){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}function d(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function _(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function y(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(_(arguments[e]));return t}function g(t){return this instanceof g?(this.v=t,this):new g(t)}function h(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(t,e||[]),i=[];return n={},s("next"),s("throw"),s("return"),n[Symbol.asyncIterator]=function(){return this},n;function s(t){o[t]&&(n[t]=function(e){return new Promise(function(r,n){i.push([t,e,r,n])>1||c(t,e)})})}function c(t,e){try{!function(t){t.value instanceof g?Promise.resolve(t.value.v).then(a,u):l(i[0][2],t)}(o[t](e))}catch(t){l(i[0][3],t)}}function a(t){c("next",t)}function u(t){c("throw",t)}function l(t,e){t(e),i.shift(),i.length&&c(i[0][0],i[0][1])}}function b(t){var e,r;return e={},n("next"),n("throw",function(t){throw t}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(n,o){e[n]=t[n]?function(e){return(r=!r)?{value:g(t[n](e)),done:"return"===n}:o?o(e):e}:o}}function m(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=d(t),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise(function(n,o){!function(t,e,r,n){Promise.resolve(n).then(function(e){t({value:e,done:r})},e)}(n,o,(e=t[r](e)).done,e.value)})}}}function v(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function O(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function j(t){return t&&t.__esModule?t:{default:t}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(2);e.NetworkError=class extends n.CoreError{constructor(t,e,r){super(t,e,r),this.domain="Network"}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(1);class o{static isArray(t){return null!==t&&void 0!==t&&Array.isArray(t)}static isEmpty(t){return!o.isArray(t)||0===t.length}static isTyped(t,e){return!o.isEmpty(t)&&!t.includes(void 0)&&!t.includes(null)&&t.every(t=>n.ObjectHelper.isType(t,e))}}e.ArrayHelper=o},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(2),o=r(4),i=r(1),s=r(0);e.ErrorHelper=class{static format(t,e){if(null===t||void 0===t)return"unknown error";if(n.CoreError.isError(t)){let r=t.format();if(e&&t.stack){r+="\nStack Trace";const e=t.stack.split("\n");e.shift(),r+=`\n${e.join("\n")}`}return i.ObjectHelper.isEmpty(t.innerError)||(e&&!i.ObjectHelper.isEmpty(t.innerError.stack)?(r+="\n\n-----------------------------------------------",r+="\nInner Stack Trace\n",r+=t.innerError.stack):r+=`\nInner Error: ${t.innerError.message}\n`),r}if(t instanceof Error){let r="";return e&&!i.ObjectHelper.isEmpty(t.stack)?r+=t.stack:r+=t.message,r}return s.StringHelper.isString(t)?t:o.JsonHelper.stringify(t,void 0,"\t")}}},function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.NumberHelper=class{static isInteger(t){return Number.isInteger(t)&&!Number.isNaN(t)&&Number.isFinite(t)}static isNumber(t){return void 0!==t&&null!==t&&"number"==typeof t&&!Number.isNaN(t)&&Number.isFinite(t)}static isFloatString(t){return/^-?\d*\.?\d+$/.test(t)}static isIntegerString(t){return/^-?\d+$/.test(t)}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(5);n.__exportStar(r(2),e),n.__exportStar(r(6),e),n.__exportStar(r(11),e),n.__exportStar(r(3),e),n.__exportStar(r(12),e),n.__exportStar(r(13),e),n.__exportStar(r(14),e),n.__exportStar(r(7),e),n.__exportStar(r(8),e),n.__exportStar(r(4),e),n.__exportStar(r(9),e),n.__exportStar(r(0),e),n.__exportStar(r(1),e),n.__exportStar(r(15),e),n.__exportStar(r(16),e),n.__exportStar(r(17),e),n.__exportStar(r(18),e),n.__exportStar(r(19),e)},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(2);e.PlatformError=class extends n.CoreError{constructor(t,e,r){super(t,e,r),this.domain="Platform"}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(3);class o extends n.FactoryBase{constructor(){super()}static instance(){return o._instance||(o._instance=new o),o._instance}getInstance(){return o.instance()}}e.NetworkClientFactory=o},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(3);class o extends n.FactoryBase{constructor(){super()}static instance(){return o._instance||(o._instance=new o),o._instance}getInstance(){return o.instance()}}e.PlatformCryptoFactory=o},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(3);class o extends n.FactoryBase{constructor(){super()}static instance(){return o._instance||(o._instance=new o),o._instance}getInstance(){return o.instance()}}e.RngServiceFactory=o},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(7),o=r(8),i=r(1),s=r(0);e.ConsoleLogger=class{constructor(t){this._loggingObject=t||console}banner(t,...e){this._loggingObject.log("=".repeat(80)),this._loggingObject.log(t),this.logArgs(this._loggingObject.log,e),this._loggingObject.log("=".repeat(80))}log(t,...e){this._loggingObject.log(t),this.logArgs(this._loggingObject.log,e)}info(t,...e){this._loggingObject.info(t),this.logArgs(this._loggingObject.info,e)}warning(t,...e){this._loggingObject.warn(t),this.logArgs(this._loggingObject.warn,e)}error(t,e,...r){this._loggingObject.error(t),i.ObjectHelper.isEmpty(e)||o.ErrorHelper.format(e,!0).split("\n").forEach(t=>{this._loggingObject.error(`\t${t}`)}),this.logArgs(this._loggingObject.error,r)}logArgs(t,e){if(!n.ArrayHelper.isEmpty(e)){const r="\t";let n="";e.forEach((t,o)=>{n+=this.createItem(r,"",t),o<e.length-1&&(n+=`${r}${"-".repeat(70)}\n`)}),t(n)}}createItem(t,e,r,o="\n"){let c="";if(n.ArrayHelper.isArray(r)){const n=`${t}\t`;s.StringHelper.isEmpty(e)?c+=`${t}[\n`:c+=`${t}${e}: [\n`,r.forEach((t,e)=>{c+=this.createItem(n,"",t,`${e<r.length-1?",":""}\n`)}),c+=`${t}]\n`}else if(i.ObjectHelper.isObject(r)){const n=r.toString();if("[object Object]"===n){const n=`${t}\t`;s.StringHelper.isEmpty(e)?c+=`${t}{\n`:c+=`${t}${e}: {\n`;const o=Object.keys(r);o.forEach((t,e)=>{c+=this.createItem(n,t,r[t],`${e<o.length-1?",":""}\n`)}),c+=`${t}}\n`}else c+=this.createItem(t,e,n.replace(/\n/g,`\n${t}`),o)}else s.StringHelper.isEmpty(e)?c+=`${t}${i.ObjectHelper.isEmpty(r)?r:r.toString()}${o}`:c+=`${t}${e}: ${i.ObjectHelper.isEmpty(r)?r:r.toString()}${o}`;return c}}},function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.NullLogger=class{banner(t,...e){}log(t,...e){}info(t,...e){}warning(t,...e){}error(t,e,...r){}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(6),o=r(9),i=r(1),s=r(0);e.NetworkEndPoint=class{constructor(t,e,r,c){if(!s.StringHelper.isString(t)||!/http|https/.test(t))throw new n.NetworkError("The protocol must be defined as http or https");if(!s.StringHelper.isString(e))throw new n.NetworkError("The host must be defined");if(!o.NumberHelper.isInteger(r)||r<=0)throw new n.NetworkError("The port must be a number greater than zero");if(!i.ObjectHelper.isEmpty(c)&&!s.StringHelper.isString(c))throw new n.NetworkError("The rootPath must be a valid string");this._protocol=t,this._host=e.replace(/^\/*/,"").replace(/\/*$/,""),this._port=r,this._rootPath=(c||"").replace(/^\/*/,"").replace(/\/*$/,"")}getProtocol(){return this._protocol}getHost(){return this._host}getRootPath(){return this._rootPath}getPort(){return this._port}getUri(){let t=`${this._protocol}://${this._host}:${this._port}`;return this._rootPath.length>0&&(t+=`/${this._rootPath}`),t}}},function(t,e,r){Object.defineProperty(e,"__esModule",{value:!0});const n=r(5);e.BackgroundTaskService=class{create(t,e){return n.__awaiter(this,void 0,void 0,function*(){return new Promise((r,n)=>{setTimeout(()=>{try{r(t())}catch(t){n(t)}},e)})})}}},function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.TimeService=class{msSinceEpoch(){return Date.now()}}}])});