Socket
Socket
Sign inDemoInstall

qcloud-iotexplorer-common-libs

Package Overview
Dependencies
12
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.12.16 to 0.12.18

2

lib/libs/flow-logger.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FlowLogger=void 0;var tslib_1=require("tslib"),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),qcloud_iotexplorer_logger_1=tslib_1.__importDefault(require("qcloud-iotexplorer-logger")),SELF_EVENT_FLAG="@",concatMessage=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return Array.isArray(e)?e.concat(t):tslib_1.__spread([e],t)},parseData=function(e){return e instanceof Error?parseJsError(e):e},parseJsError=function(e){return{type:"js-error",code:e.name,msg:e.message}},parseError=function(e,t){var r;if(void 0===t&&(t={}),void 0===e)return e;if(e instanceof Error)return tslib_1.__assign(tslib_1.__assign({},parseJsError(e)),{stack:e.stack});var o=e;if(o&&"object"==typeof o&&(void 0!==o.errCode||void 0!==o.errMsg||void 0!==o.errno)){var s=o.errCode,i=o.errMsg,n=o.errno,a=tslib_1.__rest(o,["errCode","errMsg","errno"]);return tslib_1.__assign({type:"wx-api-fail",code:null!=n?n:s,msg:i,errCode:s,errno:n},a)}if(o&&"object"==typeof o&&(void 0!==o.code||void 0!==o.msg)){var c=o.code,g=o.msg,u=o.cause;a=tslib_1.__rest(o,["code","msg","cause"]);return tslib_1.__assign({type:"business-error",code:c,msg:null!==(r=null!=g?g:t[String(c)])&&void 0!==r?r:"-",cause:u instanceof Error?{type:"js-error",code:u.name,msg:u.message}:u,stack:u instanceof Error?u.stack:void 0},a)}return"string"==typeof e?{type:"plain-error",code:null,msg:e}:{type:"unknown-error",code:null,msg:"see `.cause` for more info",cause:e}},convertMessageToString=function(e){if(void 0!==e)return"string"==typeof e?e:Array.isArray(e)?e.filter((function(e){return null!=e})).join(", "):String(e)},FlowLogger=function(){function e(e,t){this.startTime=0,this.context={},this.errorMsgMap={},this.tag=e,this.parent=null!=t?t:void 0}return Object.defineProperty(e.prototype,"event",{get:function(){return this.parent?this.parent.event+"."+this.tag:this.tag},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"insightLogger",{get:function(){var e=this;return this.protectedInsightLogger||(this.protectedInsightLogger=(this.parent?this.parent.insightLogger:qcloud_iotexplorer_logger_1.default).derive((function(){var t;return{context:tslib_1.__assign(tslib_1.__assign({},e.context),null===(t=e.externalContextGetter)||void 0===t?void 0:t.call(e)),metric:{spanId:e.spanId}}}))),this.protectedInsightLogger},enumerable:!1,configurable:!0}),e.prototype.start=function(e,t){this.startTime=Date.now(),this.insightLogger.info(this.event,{message:e?convertMessageToString(e):this.defaultMessage+"开始",data:parseData(t),metric:{type:"start"}})},e.prototype.flow=function(t,r,o){void 0===o&&(o=!1);var s=new e(t,this);return s.defaultMessage=r,s.context.flowId=shortid_for_miniprogram_1.default(),o&&s.start(null,"object"==typeof o?o:void 0),s},e.prototype.step=function(t,r,o){void 0===o&&(o=!1);var s=new e(t,this);return s.defaultMessage=r,s.spanId=shortid_for_miniprogram_1.default(),o&&s.start(null,"object"==typeof o?o:void 0),s},e.prototype.info=function(e,t,r){this.insightLogger.info(e!==SELF_EVENT_FLAG?this.event+"."+e:this.event,{message:convertMessageToString(t),data:parseData(r)})},e.prototype.warn=function(e,t,r){this.insightLogger.warn(e!==SELF_EVENT_FLAG?this.event+"."+e:this.event,{message:convertMessageToString(t),data:parseData(r)})},e.prototype.error=function(e,t,r,o){var s;if(r instanceof Error)this.insightLogger.error(e!==SELF_EVENT_FLAG?this.event+"."+e:this.event,{message:convertMessageToString(t),data:parseData(o),error:parseJsError(r),stack:r.stack});else{var i=r,n=void 0;r&&"object"==typeof r&&"stack"in r&&(n=(s=r).stack,i=tslib_1.__rest(s,["stack"])),this.insightLogger.error(e!==SELF_EVENT_FLAG?this.event+"."+e:this.event,{message:convertMessageToString(t),data:parseData(o),error:i,stack:n})}},e.prototype.debug=function(e,t,r){this.insightLogger.debug(e!==SELF_EVENT_FLAG?this.event+"."+e:this.event,{message:convertMessageToString(t),data:parseData(r)})},e.prototype.success=function(e,t){this.endMetric("success","info",null!=e?e:this.defaultMessage+"成功",t)},e.prototype.fail=function(e,t,r){var o=void 0===t?void 0:parseError(t,this.errorMsgMap);this.endMetric("fail","error",concatMessage(null!=e?e:this.defaultMessage+"失败","["+o.type+"] ["+o.code+"] "+o.msg),r,o)},e.prototype.wrapWithoutRetValue=function(e){return this.wrap(e,2)},e.prototype.wrap=function(e,t,r){var o=this;return void 0===t&&(t=1),void 0===r&&(r=1),e.then((function(e){try{switch(t){case 1:var r=e;void 0!==r&&(r&&"object"==typeof r||(r={data:r})),o.success(null,r);break;case 2:o.success();break;case 3:break;default:return t(e,o)}}catch(e){console.error("[LLSyncFlowLogger.wrap] resolve handler error",e)}return e})).catch((function(e){try{switch(r){case 1:o.fail(null,e);break;case 2:o.fail(null,{});break;case 3:break;default:return r(e,o)}}catch(e){console.error("[LLSyncFlowLogger.wrap] reject handler error",e)}return Promise.reject(e)}))},e.prototype.setErrorMsgMap=function(e){this.errorMsgMap=e},e.prototype.endMetric=function(e,t,r,o,s){var i,n=Date.now(),a=s,c=void 0;s&&"object"==typeof s&&"stack"in s&&(c=(i=s).stack,a=tslib_1.__rest(i,["stack"])),this.insightLogger[t](this.event,{message:convertMessageToString(r),data:parseData(o),error:a,stack:c,metric:{type:e,timeCost:this.startTime?n-this.startTime:void 0}})},e}();exports.FlowLogger=FlowLogger;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FlowLogger=void 0;var tslib_1=require("tslib"),shortid_for_miniprogram_1=tslib_1.__importDefault(require("shortid-for-miniprogram")),qcloud_iotexplorer_logger_1=tslib_1.__importDefault(require("qcloud-iotexplorer-logger")),SELF_EVENT_FLAG="@",concatMessage=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return Array.isArray(t)?t.concat(r):tslib_1.__spread([t],r)},parseData=function(t){return t instanceof Error?parseJsError(t):t},parseJsError=function(t){return{isJsError:!0,code:t.name,msg:t.message}},parseError=function(t,r){var e;if(void 0===r&&(r={}),void 0===t)return t;if(t instanceof Error)return tslib_1.__assign(tslib_1.__assign({},parseJsError(t)),{stack:t.stack,toString:function(){return"[JsError] "+String(t)}});var s=t;return s&&"object"==typeof s?tslib_1.__assign(tslib_1.__assign({},s),{msg:null!==(e=s.msg)&&void 0!==e?e:r[String(s.msg)],cause:s.cause instanceof Error?parseJsError(s.cause):s.cause,stack:s.cause instanceof Error?s.cause.stack:void 0,toString:function(){var t,r,e,o="["+(null!==(r=null!==(t=this.code)&&void 0!==t?t:this.errno)&&void 0!==r?r:this.errCode)+"] "+(null!==(e=this.errMsg)&&void 0!==e?e:this.msg);return s.cause instanceof Error?o+" caused by "+String(s.cause):o}}):"string"==typeof t?{code:t,msg:t,toString:function(){return t}}:{code:"UnknownError",msg:"see `.cause` for more info",cause:t,toString:function(){return"[UnknownError]"}}},convertMessageToString=function(t){if(void 0!==t)return"string"==typeof t?t:Array.isArray(t)?t.filter((function(t){return null!=t})).join(", "):String(t)},FlowLogger=function(){function t(t,r){this.startTime=0,this.context={},this.errorMsgMap={},this.tag=t,this.parent=null!=r?r:void 0}return Object.defineProperty(t.prototype,"event",{get:function(){return this.parent?this.parent.event+"."+this.tag:this.tag},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"insightLogger",{get:function(){var t=this;return this.protectedInsightLogger||(this.protectedInsightLogger=(this.parent?this.parent.insightLogger:qcloud_iotexplorer_logger_1.default).derive((function(){var r;return{context:tslib_1.__assign(tslib_1.__assign({},t.context),null===(r=t.externalContextGetter)||void 0===r?void 0:r.call(t)),metric:{spanId:t.spanId}}}))),this.protectedInsightLogger},enumerable:!1,configurable:!0}),t.prototype.start=function(t,r){this.startTime=Date.now(),this.insightLogger.info(this.event,{message:t?convertMessageToString(t):this.defaultMessage+"开始",data:parseData(r),metric:{type:"start"}})},t.prototype.flow=function(r,e,s){void 0===s&&(s=!1);var o=new t(r,this);return o.defaultMessage=e,o.context.flowId=shortid_for_miniprogram_1.default(),o.errorMsgMap=this.errorMsgMap,s&&o.start(null,"object"==typeof s?s:void 0),o},t.prototype.step=function(r,e,s){void 0===s&&(s=!1);var o=new t(r,this);return o.defaultMessage=e,o.spanId=shortid_for_miniprogram_1.default(),o.errorMsgMap=this.errorMsgMap,s&&o.start(null,"object"==typeof s?s:void 0),o},t.prototype.info=function(t,r,e){this.insightLogger.info(t!==SELF_EVENT_FLAG?this.event+"."+t:this.event,{message:convertMessageToString(r),data:parseData(e)})},t.prototype.warn=function(t,r,e){this.insightLogger.warn(t!==SELF_EVENT_FLAG?this.event+"."+t:this.event,{message:convertMessageToString(r),data:parseData(e)})},t.prototype.error=function(t,r,e,s){var o;if(e instanceof Error)this.insightLogger.error(t!==SELF_EVENT_FLAG?this.event+"."+t:this.event,{message:convertMessageToString(r),data:parseData(s),error:parseJsError(e),stack:e.stack});else{var i=e,n=void 0;e&&"object"==typeof e&&"stack"in e&&(n=(o=e).stack,i=tslib_1.__rest(o,["stack"])),this.insightLogger.error(t!==SELF_EVENT_FLAG?this.event+"."+t:this.event,{message:convertMessageToString(r),data:parseData(s),error:i,stack:n})}},t.prototype.debug=function(t,r,e){this.insightLogger.debug(t!==SELF_EVENT_FLAG?this.event+"."+t:this.event,{message:convertMessageToString(r),data:parseData(e)})},t.prototype.success=function(t,r){this.endMetric("success","info",null!=t?t:this.defaultMessage+"成功",r)},t.prototype.fail=function(t,r,e){var s=void 0===r?void 0:parseError(r,this.errorMsgMap);this.endMetric("fail","error",concatMessage(null!=t?t:this.defaultMessage+"失败",s?String(s):null),e,s)},t.prototype.wrapWithoutRetValue=function(t){return this.wrap(t,2)},t.prototype.wrap=function(t,r,e){var s=this;return void 0===r&&(r=1),void 0===e&&(e=1),t.then((function(t){try{switch(r){case 1:var e=t;void 0!==e&&(e&&"object"==typeof e||(e={data:e})),s.success(null,e);break;case 2:s.success();break;case 3:break;default:return r(t,s)}}catch(t){console.error("[LLSyncFlowLogger.wrap] resolve handler error",t)}return t})).catch((function(t){try{switch(e){case 1:s.fail(null,t);break;case 2:s.fail(null,{});break;case 3:break;default:return e(t,s)}}catch(t){console.error("[LLSyncFlowLogger.wrap] reject handler error",t)}return Promise.reject(t)}))},t.prototype.setErrorMsgMap=function(t){this.errorMsgMap=t},t.prototype.endMetric=function(t,r,e,s,o){var i,n=Date.now(),a=o,c=void 0;o&&"object"==typeof o&&"stack"in o&&(c=(i=o).stack,a=tslib_1.__rest(i,["stack"])),this.insightLogger[r](this.event,{message:convertMessageToString(e),data:parseData(s),error:a,stack:c,metric:{type:t,timeCost:this.startTime?n-this.startTime:void 0}})},t}();exports.FlowLogger=FlowLogger;
//# sourceMappingURL=flow-logger.js.map
{
"name": "qcloud-iotexplorer-common-libs",
"version": "0.12.16",
"version": "0.12.18",
"description": "腾讯云IOT前端通用工具库",

@@ -26,3 +26,3 @@ "main": "lib/index.js",

},
"gitHead": "572dae28019e882a5527edc60cd2acb8cc61ac1f"
"gitHead": "0a942a41d7af740506ec232e56904d3e91481641"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc