@iotize/tap
Version:
IoTize Device client for Javascript
17 lines (15 loc) • 15 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@iotize/tap/client/impl"),require("@iotize/common/error"),require("@iotize/common/utility"),require("@iotize/tap/service/core"),require("@iotize/tap/client/api"),require("@iotize/tap/service/impl/target"),require("@iotize/tap/service/impl/variable"),require("@iotize/tap/service/impl/interface"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@iotize/tap/extra/dbiot",["exports","@iotize/tap/client/impl","@iotize/common/error","@iotize/common/utility","@iotize/tap/service/core","@iotize/tap/client/api","@iotize/tap/service/impl/target","@iotize/tap/service/impl/variable","@iotize/tap/service/impl/interface","rxjs","rxjs/operators"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).iotize=e.iotize||{},e.iotize.tap=e.iotize.tap||{},e.iotize.tap.extra=e.iotize.tap.extra||{},e.iotize.tap.extra.dbiot={}),e.iotize.tap.client.impl,e.error,e.utility,e.iotize.tap.service.core,e.iotize.tap.client.api,e.iotize.tap.service.impl.target,e.iotize.tap.service.impl.variable,e.iotize.tap.service.impl.interface,e.rxjs,e.rxjs.operators)}(this,(function(e,t,r,n,o,i,a,c,u,d,l){"use strict";var s;!function(e){e[e.DEVICE_CONTROL_1=17]="DEVICE_CONTROL_1"}(s||(s={}));
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var p=function(e,t){return p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},p(e,t)};function v(e,t){var r,n,o,i,a={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(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],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])}}}Object.create;function f(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}Object.create;var h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}(t,e),t.maxDataLengthReach=function(e,r){return new t("Cannot write "+e+" bytes. Maximum field length is "+r+" bytes.",t.Code.MaxDataLengthReach)},t.unknownFieldName=function(e){return new t('Cannot find definition for field name "'+e+'"',t.Code.UnknownFieldName)},t.unknownFieldCode=function(e){return new t('Cannot find definition for code "'+e+'"',t.Code.UnknownFieldCode)},t.unexpectedCharacter=function(e){return new t(e,t.Code.UnexpectedCharacter)},t.invalidEnumKey=function(e,r){return new t('Invalid enum key "'+e+'". Authorized keys are '+n.listEnumValues(r).map((function(e){return e+": "+r[e]})).join(", "),t.Code.InvalidEnumKey)},t}(r.CodeError);function y(e,t){var r=Math.ceil(Math.log2(Math.abs(e)+1))+(t?1:0);return Math.ceil(r/8)}!function(e){!function(e){e.UnknownFieldCode="TlvJsonCompressorErrorUnknownFieldCode",e.UnknownFieldName="TlvJsonCompressorErrorUnknownFieldName",e.UnexpectedCharacter="TlvJsonCompressorErrorUnexpectedCharacter",e.MaxDataLengthReach="TlvJsonCompressorErrorMaxDataLengthReach",e.InvalidEnumKey="TlvJsonCompressorErrorInvalidEnumKey"}(e.Code||(e.Code={}))}(h||(h={}));var w=function(){function e(e){this.signed=e}return e.prototype.encode=function(e,r){var n;if(void 0===r&&(r=new t.TapStreamWriter),0===e)n=1;else if((n=y(e,this.signed))<=0)throw new Error("Invalid byte length "+n);return 3===n&&(n=4),z(r,n),this.signed?r.writeS(e,n):r.writeU(e,n),r.toBytes},e.prototype.decode=function(e){var r=t.TapStreamReader.create(e),n=R(r);return 0===n?0:this.signed?r.readS(n):r.readU(n)},e}(),b=function(){function e(){}return e.prototype.encode=function(e,r){if(void 0===r&&(r=new t.TapStreamWriter),0===e)return z(r,0),r.toBytes;if(Number.isInteger(e)){var n=y(e,!0);if(n<3)return z(r,n),r.writeS(e,n),r.toBytes}var o=Math.fround(e)===e?4:8;return z(r,o),r.writeF(e,o),r.toBytes},e.prototype.decode=function(e){var r=t.TapStreamReader.create(e),n=R(r);return 0===n?0:4===n||8==n?r.readFloat(n):n<3?r.readS(n):(console.warn('failed to decode float64 number with length "'+n+'"'),0)},e}(),g=function(){function e(){}return e.prototype.encode=function(e,r){return void 0===r&&(r=new t.TapStreamWriter),e?z(r,0):(z(r,1),r.writeU1(0)),r.toBytes},e.prototype.decode=function(e){var r=t.TapStreamReader.create(e),n=R(r);return 0===n||0!==r.readU(n)},e}(),C=function(){function e(e){this.converter=e}return e.prototype.encode=function(e,r){void 0===r&&(r=new t.TapStreamWriter);var n=this.converter.encode(e);return z(r,n.length),r.writeBytes(n),r.toBytes},e.prototype.decode=function(e){var r=t.TapStreamReader.create(e),n=R(r);return this.converter.decode(r.readBytes(n))},e}(),T=new C(o.converters.utf8),x=new g,E=new C(o.converters.float),S=new w(!1),B=(new w(!0),new b);function O(e,t){return Object.entries(t).find((function(t){var r=m(t,2);r[0];return r[1].code===String.fromCharCode(e)}))}function z(e,t){if(t>127){if(t>32767)throw h.maxDataLengthReach(t,32767);e.writeBits(1,1),e.writeBits(t,15)}else e.writeBits(0,1),e.writeBits(t,7)}function R(e){var t=e.readBits(1);return e.readBits(t?15:7)}var _,N=function(){function e(e){this.mapping=e,this.strictMode=!1}return e.prototype.encode=function(e,r){var n=this;void 0===r&&(r=new t.TapStreamWriter);var o=Object.entries(e),i=new t.TapStreamWriter;o.forEach((function(e){var t=m(e,2),r=t[0],o=t[1],a=n.mapping[r];if(!a)throw h.unknownFieldName(r);i.writeU1(a.code.charCodeAt(0));var c=a.converter.encode(o);z(i,c.length),i.writeBytes(c)}));var a=i.toBytes;return z(r,a.length),r.writeBytes(a),r.toBytes},e.prototype.decode=function(e){for(var r=t.TapStreamReader.create(e),n={},o=R(r),i=r.pos;r.pos-i<o;){var a=r.readU1(),c=O(a,this.mapping),u=R(r);if(c){var d=m(c,2),l=d[0],s=d[1];n[l]=s.converter.decode(r)}else{if(this.strictMode)throw h.unknownFieldCode(a);r.forward(u)}}return n},e}(),U=function(){function e(e){this.options=e}return e.prototype.encode=function(e,r){var n=this;void 0===r&&(r=new t.TapStreamWriter);var o=new t.TapStreamWriter;e.forEach((function(e){n.options.itemConverter.encode(e,o)}));var i=o.toBytes;return z(r,i.length),r.writeBytes(i),r.toBytes},e.prototype.decode=function(e){for(var r=t.TapStreamReader.create(e),n=R(r),o=r.subStream(n),i=[];!o.isEof();){var a=this.options.itemConverter.decode(o);i.push(a)}return i},e}(),L=function(){function e(e){this.options=e}return e.prototype.encode=function(e,r){void 0===r&&(r=new t.TapStreamWriter);var n=new t.TapStreamWriter;S.encode(e.length,n),this.options.fields.forEach((function(t){var r=t.fieldName,o=t.converter;e.forEach((function(e,t){r in e?o.encode(e[r],n):z(n,0)}))}));var o=n.toBytes;return z(r,o.length),r.writeBytes(o),r.toBytes},e.prototype.decode=function(e){var r=t.TapStreamReader.create(e),n=(R(r),S.decode(r)),o=new Array(n).fill(void 0).map((function(){return{}}));return this.options.fields.forEach((function(e){var t=e.fieldName,n=e.converter;o.forEach((function(e,o){var i=n.decode(r);e[t]=i}))})),o},e}(),M={encode:function(e,r){var n,o;void 0===r&&(r=new t.TapStreamWriter);var i=new t.TapStreamWriter;z(i,e.length);try{for(var a=f(e),c=a.next();!c.done;c=a.next()){var u=c.value;i.writeBitsInt(u,4)}}catch(e){n={error:e}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(n)throw n.error}}var d=i.toBytes;return z(r,d.length),r.writeBytes(d),r.toBytes},decode:function(e){for(var r=R(e=t.TapStreamReader.create(e)),n=e.subStream(r),o=R(n),i=[],a=0;a<o;a++)i.push(n.readBitsInt(4));return i}};!function(e){e[e.DEFAULT=0]="DEFAULT",e[e.SMALL=1]="SMALL",e[e.LARGE=2]="LARGE"}(_||(_={}));var F=new N({encoding:{code:"E",converter:new N({scaling:{code:"x",converter:E},bitLength:{code:"b",converter:S},offset:{code:"o",converter:E}})},tap:{code:"T",converter:new N({address:{code:"a",converter:S},valueAcquisitionPeriod:{code:"s",converter:S}})},dashboard:{code:"D",converter:new N({offset:{code:"O",converter:B},scaling:{code:"X",converter:B},readable:{code:"R",converter:x},writable:{code:"W",converter:x},format:{code:"F",converter:T},name:{code:"N",converter:T},unit:{code:"U",converter:T},byteOrder:{code:"B",converter:M},component:{code:"C",converter:new N({"tap-variable-number":{code:"t",converter:new N({})},"tap-variable-range":{code:"r",converter:new N({min:{code:"m",converter:B},max:{code:"M",converter:B},step:{code:"s",converter:B},writeValueForEveryChange:{code:"w",converter:x}})},"tap-variable-linear-gauge":{code:"G",converter:new N({min:{code:"m",converter:B},max:{code:"M",converter:B}})},"tap-variable-gauge":{code:"g",converter:new N({min:{code:"m",converter:B},max:{code:"M",converter:B}})},"tap-variable-line-chart":{code:"l",converter:new N({})},"tap-variable-bar-chart":{code:"B",converter:new N({})},"tap-variable-table":{code:"T",converter:new N({})},"tap-variable-bits-editor":{code:"b",converter:new N({bitsTemplate:{code:"T",converter:new L({fields:[{fieldName:"index",converter:S},{fieldName:"label",converter:T}]})}})},"tap-variable-buttons":{code:"U",converter:new N({buttons:{code:"b",converter:new L({fields:[{fieldName:"value",converter:B},{fieldName:"label",converter:T}]})}})},"tap-variable-push-button":{code:"P",converter:new N({mouseDownValue:{code:"d",converter:B},mouseUpValue:{code:"U",converter:B},value:{code:"u",converter:B},buttonText:{code:"l",converter:T},icon:{code:"i",converter:T}})},"tap-variable-select":{code:"S",converter:new N({options:{code:"o",converter:new L({fields:[{fieldName:"value",converter:B},{fieldName:"text",converter:T}]})}})}})}})},cloud:{code:"C",converter:new N({name:{code:"N",converter:T},optional:{code:"p",converter:S},uploadPeriod:{code:"t",converter:S},valueDelta:{code:"d",converter:E},alarmMinValue:{code:"l",converter:E},alarmMaxValue:{code:"h",converter:E}})}}),I=function(){function e(){}return e.prototype.encode=function(e){if(!e)return new Uint8Array;var r=new t.TapStreamWriter;return r.writeU1(s.DEVICE_CONTROL_1),F.encode(e,r),r.toBytes},e.prototype.decode=function(e){var r,n=t.TapStreamReader.create(e);if(0!==n.byteLeft&&(n.isEof()||r===s.DEVICE_CONTROL_1||(r=n.readU1()),r===s.DEVICE_CONTROL_1))try{return F.decode(n)}catch(e){console.warn("Failed to restore variable configuration",e)}},e}(),D=new I,j=function(){function e(e){this.mapping=e}return e.prototype.encode=function(r,n){if(void 0===n&&(n=new t.TapStreamWriter),!(r in this.mapping))throw h.invalidEnumKey(r,this.mapping);return e._valueConverter.encode(r,n)},e.prototype.decode=function(t){var r=e._valueConverter.decode(t);if(!(r in this.mapping))throw h.invalidEnumKey(r,this.mapping);return r},e}();j._valueConverter=new w(!1);var k=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function c(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}u((n=n.apply(e,t||[])).next())}))};function V(e,t){return k(this,void 0,void 0,(function(){var r,n,o,a,c,u,d,l;return v(this,(function(s){switch(s.label){case 0:return[4,e.service.interface.executeMultipleCalls([e.service.variable.getNumberOfElementsCall(t),e.service.variable.getTypeCall(t),e.service.variable.getBundleIdCall(t)])];case 1:return r=m.apply(void 0,[s.sent(),3]),n=r[0],o=r[1],a=r[2],n.isSuccessful()||n.codeRet()!==i.ResultCode.NOT_FOUND?(c=n.body(),u=void 0,c>0?[4,e.service.variable.getRawMeta(t)]:[3,3]):[2,void 0];case 2:if(d=s.sent(),(l=d.body()).length>0)try{u=D.decode(l)}catch(e){return console.warn('Cannot parse dbiot info for variable "'+t+'"',e),[2]}s.label=3;case 3:return[2,{id:t,bundleId:a.body(),length:c,type:o.body(),dbiot:u}]}}))}))}e.DBIOTVarConfigConverter=I,e.DBIOT_VARIABLE_CONFIG_CONVERTER=D,e.TLVMappedEnumConverter=j,e.TLVMappedJsonArrayCompressor=U,e.createReadDBIOTConfigurationFromTapObservable=function(e,t){var r=this;return new d.Observable((function(n){var o=!1,i={type:"start",data:{total:t}};return n.next(i),k(r,void 0,void 0,(function(){var r,i,a,c,u,d,l,s;return v(this,(function(p){switch(p.label){case 0:return p.trys.push([0,6,,7]),[4,e.service.target.getProtocol()];case 1:r=p.sent().body(),i=[],a={type:"progress",data:{current:0,total:t}},n.next(a),c=0,p.label=2;case 2:return c<t&&!o?[4,V(e,c)]:[3,5];case 3:(u=p.sent())&&i.push(u),d={type:"progress",data:{current:c+1,total:t,variable:u}},n.next(d),p.label=4;case 4:return c++,[3,2];case 5:return o||(l={type:"complete",data:{bundles:[],variables:i,targetProtocol:r}},n.next(l)),n.complete(),[3,7];case 6:return s=p.sent(),n.error(s),[3,7];case 7:return[2]}}))})),function(){o=!0}})).pipe(l.share())},e["ɵa"]=w,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=iotize-tap-extra-dbiot.umd.min.js.map