qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),SyncGatewaySubDevicePlugin=function(){function e(){}return e.install=function(e){var t=new SyncGatewaySubDeviceImplements(this);e.plugins.syncGatewaySubDevicePlugin={sync:t.syncGatewaySubDevice,syncByList:t.syncGatewaySubDeviceByList}},e}();exports.default=SyncGatewaySubDevicePlugin;var SyncGatewaySubDeviceImplements=function(){function e(e){this.sdk=e}return e.prototype.syncGatewaySubDeviceByList=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,a,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return t={},i={},e.forEach((function(e){var s=e.ProductId,a=e.DeviceId,r=e.DeviceName,n=e.DeviceType,c=e.GatewayDeviceId;a||(a=s+"/"+r),2===n&&c&&(i[c]||(i[c]=[]),i[c].push(e)),1===n&&(t[a]=e)})),[4,Promise.all(Object.keys(t).map((function(e){return tslib_1.__awaiter(r,void 0,void 0,(function(){var s;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:return[4,this.syncGatewaySubDevice(t[e],{subDeviceAlreadyInFamilyList:i[e]})];case 1:return s=a.sent(),[2,tslib_1.__assign(tslib_1.__assign({},s),{gatewayDeviceInfo:t[e]})]}}))}))})))];case 1:return s=n.sent(),a=!1,s.forEach((function(t){var i=t.gatewayDeviceInfo,s=t.diffResult;s.add.forEach((function(t){a=!0,t.success?e.push(tslib_1.__assign(tslib_1.__assign({},t.deviceInfo),{isShareDevice:i.isShareDevice})):utils_1.logger.debug("该子设备添加失败",t)})),s.remove.forEach((function(t){a=!0;var i=e.findIndex((function(e){return e.DeviceId===t.deviceInfo.DeviceId}));e.splice(i,1),utils_1.logger.debug("删除子设备",t.deviceInfo,i,e)}))})),a&&this.sdk.reporter.info("sync-gateway-subdevice-result",{data:s}),[2,{deviceList:e,syncResults:s}]}}))}))},e.prototype.syncGatewaySubDevice=function(e,t){var i=(void 0===t?{}:t).subDeviceAlreadyInFamilyList;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,a,r,n,c,u,o,v,l,d,f=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return a={subDeviceList:[],diffResult:s={add:[],remove:[]}},"string"!=typeof e?[3,2]:[4,this.sdk.requestApi("AppGetDevice",{DeviceId:e})];case 1:e=_.sent(),_.label=2;case 2:return r=e.ProductId,n=e.DeviceName,c=e.FamilyId,1!==e.DeviceType||"~virtualDev"===e.DeviceName?(utils_1.logger.debug("无需同步子设备",e),[2,a]):(u=[],t||u.push(utils_1.fetchAllList((function(e){var t=e.offset,i=e.limit;return f._getGatewayBindDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:i})})).then((function(e){return t=e}))),i||u.push(utils_1.fetchAllList((function(e){var t=e.offset,s=e.limit;return f._getFamilySubDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:s}).then((function(e){return i=e}))}))),[4,Promise.all(u)]);case 3:return _.sent(),o={},v={},t.forEach((function(e){return o[e.DeviceId]=e})),i.forEach((function(e){return v[e.DeviceId]=e})),t.forEach((function(e){v[e.DeviceId]?a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e),v[e.DeviceId])):s.add.push({success:!1,deviceInfo:e})})),i.forEach((function(e){o[e.DeviceId]||s.remove.push({success:!1,deviceInfo:e})})),utils_1.logger.debug("syncGatewaySubDeviceList",{result:a,diffResult:s,subDeviceList:t,subDeviceAlreadyInFamilyList:i}),l=s.add.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.sdk.requestApi("AppBindSubDeviceInFamily",{ProductId:e.deviceInfo.ProductId,DeviceName:e.deviceInfo.DeviceName,GatewayProductId:r,GatewayDeviceName:n})];case 1:return t=s.sent().Data.AppDeviceInfo,a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e.deviceInfo),t)),e.success=!0,[3,3];case 2:return i=s.sent(),utils_1.logger.error("Sync subdevice to family fail",i),e.success=!1,e.error=i,[3,3];case 3:return[2]}}))}))})),d=s.remove.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),c?[4,this.sdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:c,DeviceId:e.deviceInfo.DeviceId})]:[3,2];case 1:i.sent(),i.label=2;case 2:return e.success=!0,[3,4];case 3:return t=i.sent(),utils_1.logger.warn("Remove extra device from family fail",t),e.success=!1,e.error=t,[3,4];case 4:return[2]}}))}))})),[4,Promise.all(tslib_1.__spread(l,d))];case 4:return _.sent(),[2,a]}}))}))},e.prototype._getGatewayBindDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.ProductId,a=void 0===s?"":s,r=e.Limit,n=e.Offset;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,c;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:return[4,this.sdk.requestApi("AppGetGatewayBindDeviceList",{GatewayProductId:t,GatewayDeviceName:i,ProductId:a,Limit:r,Offset:n})];case 1:return e=u.sent(),s=e.DeviceList,c=e.Total,[2,{list:s,total:c}]}}))}))},e.prototype._getFamilySubDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.Offset,a=void 0===s?0:s,r=e.Limit,n=void 0===r?100:r;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,r;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,this.sdk.requestApi("AppGetFamilySubDeviceList",{GatewayProductId:t,GatewayDeviceName:i,Offset:a,Limit:n})];case 1:return e=c.sent(),s=e.DeviceList,r=e.Total,[2,{list:s,total:r}]}}))}))},e}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),utils_1=require("qcloud-iotexplorer-appdev-sdk/lib/utils"),SyncGatewaySubDevicePlugin=function(){function e(){}return e.install=function(e){var t=new SyncGatewaySubDeviceImplements(this);e.plugins.syncGatewaySubDevicePlugin={sync:t.syncGatewaySubDevice.bind(t),syncByList:t.syncGatewaySubDeviceByList.bind(t)}},e}();exports.default=SyncGatewaySubDevicePlugin;var SyncGatewaySubDeviceImplements=function(){function e(e){this.sdk=e}return e.prototype.syncGatewaySubDeviceByList=function(e){return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,i,s,a,r=this;return tslib_1.__generator(this,(function(n){switch(n.label){case 0:return t={},i={},e.forEach((function(e){var s=e.ProductId,a=e.DeviceId,r=e.DeviceName,n=e.DeviceType,c=e.GatewayDeviceId;a||(a=s+"/"+r),2===n&&c&&(i[c]||(i[c]=[]),i[c].push(e)),1===n&&(t[a]=e)})),[4,Promise.all(Object.keys(t).map((function(e){return tslib_1.__awaiter(r,void 0,void 0,(function(){var s;return tslib_1.__generator(this,(function(a){switch(a.label){case 0:return[4,this.syncGatewaySubDevice(t[e],{subDeviceAlreadyInFamilyList:i[e]})];case 1:return s=a.sent(),[2,tslib_1.__assign(tslib_1.__assign({},s),{gatewayDeviceInfo:t[e]})]}}))}))})))];case 1:return s=n.sent(),a=!1,s.forEach((function(t){var i=t.gatewayDeviceInfo,s=t.diffResult;s.add.forEach((function(t){a=!0,t.success?e.push(tslib_1.__assign(tslib_1.__assign({},t.deviceInfo),{isShareDevice:i.isShareDevice})):utils_1.logger.debug("该子设备添加失败",t)})),s.remove.forEach((function(t){a=!0;var i=e.findIndex((function(e){return e.DeviceId===t.deviceInfo.DeviceId}));e.splice(i,1),utils_1.logger.debug("删除子设备",t.deviceInfo,i,e)}))})),a&&this.sdk.reporter.info("sync-gateway-subdevice-result",{data:s}),[2,{deviceList:e,syncResults:s}]}}))}))},e.prototype.syncGatewaySubDevice=function(e,t){var i=(void 0===t?{}:t).subDeviceAlreadyInFamilyList;return tslib_1.__awaiter(this,void 0,void 0,(function(){var t,s,a,r,n,c,u,o,v,l,d,f=this;return tslib_1.__generator(this,(function(_){switch(_.label){case 0:return a={subDeviceList:[],diffResult:s={add:[],remove:[]}},"string"!=typeof e?[3,2]:[4,this.sdk.requestApi("AppGetDevice",{DeviceId:e})];case 1:e=_.sent(),_.label=2;case 2:return r=e.ProductId,n=e.DeviceName,c=e.FamilyId,1!==e.DeviceType||"~virtualDev"===e.DeviceName?(utils_1.logger.debug("无需同步子设备",e),[2,a]):(u=[],t||u.push(utils_1.fetchAllList((function(e){var t=e.offset,i=e.limit;return f._getGatewayBindDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:i})})).then((function(e){return t=e}))),i||u.push(utils_1.fetchAllList((function(e){var t=e.offset,s=e.limit;return f._getFamilySubDeviceList({GatewayProductId:r,GatewayDeviceName:n,Offset:t,Limit:s}).then((function(e){return i=e}))}))),[4,Promise.all(u)]);case 3:return _.sent(),o={},v={},t.forEach((function(e){return o[e.DeviceId]=e})),i.forEach((function(e){return v[e.DeviceId]=e})),t.forEach((function(e){v[e.DeviceId]?a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e),v[e.DeviceId])):s.add.push({success:!1,deviceInfo:e})})),i.forEach((function(e){o[e.DeviceId]||s.remove.push({success:!1,deviceInfo:e})})),utils_1.logger.debug("syncGatewaySubDeviceList",{result:a,diffResult:s,subDeviceList:t,subDeviceAlreadyInFamilyList:i}),l=s.add.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t,i;return tslib_1.__generator(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this.sdk.requestApi("AppBindSubDeviceInFamily",{ProductId:e.deviceInfo.ProductId,DeviceName:e.deviceInfo.DeviceName,GatewayProductId:r,GatewayDeviceName:n})];case 1:return t=s.sent().Data.AppDeviceInfo,a.subDeviceList.push(tslib_1.__assign(tslib_1.__assign({},e.deviceInfo),t)),e.success=!0,[3,3];case 2:return i=s.sent(),utils_1.logger.error("Sync subdevice to family fail",i),e.success=!1,e.error=i,[3,3];case 3:return[2]}}))}))})),d=s.remove.map((function(e){return tslib_1.__awaiter(f,void 0,void 0,(function(){var t;return tslib_1.__generator(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),c?[4,this.sdk.requestApi("AppDeleteDeviceInFamily",{FamilyId:c,DeviceId:e.deviceInfo.DeviceId})]:[3,2];case 1:i.sent(),i.label=2;case 2:return e.success=!0,[3,4];case 3:return t=i.sent(),utils_1.logger.warn("Remove extra device from family fail",t),e.success=!1,e.error=t,[3,4];case 4:return[2]}}))}))})),[4,Promise.all(tslib_1.__spread(l,d))];case 4:return _.sent(),[2,a]}}))}))},e.prototype._getGatewayBindDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.ProductId,a=void 0===s?"":s,r=e.Limit,n=e.Offset;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,c;return tslib_1.__generator(this,(function(u){switch(u.label){case 0:return[4,this.sdk.requestApi("AppGetGatewayBindDeviceList",{GatewayProductId:t,GatewayDeviceName:i,ProductId:a,Limit:r,Offset:n})];case 1:return e=u.sent(),s=e.DeviceList,c=e.Total,[2,{list:s,total:c}]}}))}))},e.prototype._getFamilySubDeviceList=function(e){var t=e.GatewayProductId,i=e.GatewayDeviceName,s=e.Offset,a=void 0===s?0:s,r=e.Limit,n=void 0===r?100:r;return tslib_1.__awaiter(this,void 0,void 0,(function(){var e,s,r;return tslib_1.__generator(this,(function(c){switch(c.label){case 0:return[4,this.sdk.requestApi("AppGetFamilySubDeviceList",{GatewayProductId:t,GatewayDeviceName:i,Offset:a,Limit:n})];case 1:return e=c.sent(),s=e.DeviceList,r=e.Total,[2,{list:s,total:r}]}}))}))},e}(); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "qcloud-iotexplorer-appdev-plugin-sync-gateway-subdevice", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -19,3 +19,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "dda08a8e50ac6c242b2d3f720059e669c234d854" | ||
"gitHead": "cf347ee5c5f666392dd5bee533dbbe19a092cafe" | ||
} |
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
11569