@@ -714,7 +714,7 @@ export class Upload {
714714 */
715715 async _upgradeAdapterObjectsHelper (
716716 name : string ,
717- ioPack : Record < string , any > ,
717+ ioPack : ioBroker . AdapterObject ,
718718 hostname : string ,
719719 logger : Logger | typeof console
720720 ) : Promise < string > {
@@ -730,6 +730,8 @@ export class Upload {
730730 const _obj = await this . objects . getObjectAsync ( row . id ) ;
731731 const newObject = deepClone ( _obj ) as ioBroker . InstanceObject ;
732732
733+ // TODO: refactor the following assignments into a method, where we can define which attributes need a real override and their defaults
734+
733735 // all common settings should be taken from new one
734736 newObject . common = this . extendCommon (
735737 newObject . common ,
@@ -743,15 +745,19 @@ export class Upload {
743745 newObject . encryptedNative = ioPack . encryptedNative || [ ] ;
744746 newObject . notifications = ioPack . notifications || [ ] ;
745747 // update instanceObjects and objects
746- // @ts -expect-error TODO needs to be added to types
747748 newObject . instanceObjects = ioPack . instanceObjects || [ ] ;
748- // @ts -expect-error TODO needs to be added to types
749749 newObject . objects = ioPack . objects || [ ] ;
750750
751751 newObject . common . version = ioPack . common . version ;
752752 newObject . common . installedVersion = ioPack . common . version ;
753753 newObject . common . installedFrom = ioPack . common . installedFrom ;
754754
755+ if ( ioPack . common . visWidgets ) {
756+ newObject . common . visWidgets = ioPack . common . visWidgets ;
757+ } else {
758+ delete newObject . common . visWidgets ;
759+ }
760+
755761 if ( ! ioPack . common . compact && newObject . common . compact ) {
756762 newObject . common . compact = ioPack . common . compact ;
757763 }
@@ -770,17 +776,17 @@ export class Upload {
770776 }
771777
772778 // updates only "_design/system" and co "_design/*"
773- if ( ioPack . objects && typeof ioPack . objects === 'object' ) {
774- for ( const _id of Object . keys ( ioPack . objects ) ) {
775- if ( name === 'js-controller' && ! _id . startsWith ( '_design/' ) ) {
779+ if ( Array . isArray ( ioPack . objects ) ) {
780+ for ( const obj of ioPack . objects ) {
781+ if ( name === 'js-controller' && ! obj . _id . startsWith ( '_design/' ) ) {
776782 continue ;
777783 }
778784
779- ioPack . objects [ _id ] . from = `system.host.${ hostname } .cli` ;
780- ioPack . objects [ _id ] . ts = Date . now ( ) ;
785+ obj . from = `system.host.${ hostname } .cli` ;
786+ obj . ts = Date . now ( ) ;
781787
782788 try {
783- await this . objects . setObjectAsync ( ioPack . objects [ _id ] . _id , ioPack . objects [ _id ] ) ;
789+ await this . objects . setObjectAsync ( obj . _id , obj ) ;
784790 } catch ( err ) {
785791 logger . error ( `Cannot update object: ${ err } ` ) ;
786792 }
@@ -795,15 +801,15 @@ export class Upload {
795801 */
796802 async upgradeAdapterObjects (
797803 name : string ,
798- ioPack ?: Record < string , any > ,
804+ ioPack ?: ioBroker . AdapterObject ,
799805 _logger ?: Logger | typeof console
800806 ) : Promise < string > {
801807 const logger = _logger || console ;
802808
803809 const adapterDir = tools . getAdapterDir ( name ) ;
804810 let ioPackFile ;
805811 try {
806- ioPackFile = fs . readJSONSync ( adapterDir + ' /io-package.json' ) ;
812+ ioPackFile = fs . readJSONSync ( ` ${ adapterDir } /io-package.json` ) ;
807813 } catch {
808814 if ( adapterDir ) {
809815 logger . error ( `Cannot find io-package.json in ${ adapterDir } ` ) ;
@@ -815,8 +821,8 @@ export class Upload {
815821 ioPack = ioPack || ioPackFile ;
816822
817823 if ( ioPack ) {
818- // Always update installed From from File on disk if exists and set
819- if ( ioPackFile && ioPackFile . common && ioPackFile . common . installedFrom ) {
824+ // Always update installedFrom from File on disk if exists and set
825+ if ( ioPackFile ? .common ? .installedFrom ) {
820826 ioPack . common = ioPack . common || { } ;
821827 ioPack . common . installedFrom = ioPackFile . common . installedFrom ;
822828 }
@@ -830,7 +836,9 @@ export class Upload {
830836 const obj : Omit < ioBroker . AdapterObject , '_id' > = _obj || {
831837 common : ioPack . common ,
832838 native : ioPack . native ,
833- type : 'adapter'
839+ type : 'adapter' ,
840+ instanceObjects : [ ] ,
841+ objects : [ ]
834842 } ;
835843
836844 obj . common = ioPack . common || { } ;
@@ -840,19 +848,15 @@ export class Upload {
840848 obj . encryptedNative = ioPack . encryptedNative || [ ] ;
841849 obj . notifications = ioPack . notifications || [ ] ;
842850 // update instanceObjects and objects
843- // @ts -expect-error TODO needs to be added to types
844851 obj . instanceObjects = ioPack . instanceObjects || [ ] ;
845- // @ts -expect-error TODO needs to be added to types
846852 obj . objects = ioPack . objects || [ ] ;
847853
848854 obj . type = 'adapter' ;
849855
850- obj . common ! . installedVersion = ioPack . common . version ;
856+ obj . common . installedVersion = ioPack . common . version ;
851857
852- // @ts -expect-error TODO needs to be added to types
853- if ( obj . common ! . news ) {
854- // @ts -expect-error TODO needs to be added to types
855- delete obj . common ! . news ; // remove this information as it could be big, but it will be taken from repo
858+ if ( obj . common . news ) {
859+ delete obj . common . news ; // remove this information as it could be big, but it will be taken from repo
856860 }
857861
858862 const hostname = tools . getHostName ( ) ;
0 commit comments