1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ArkData 19 */ 20 21import { AsyncCallback, Callback } from './@ohos.base'; 22import type Context from './application/BaseContext'; 23import commonType from '@ohos.data.commonType'; 24 25/** 26 * Provides interfaces to sync distributed object. 27 * 28 * @namespace distributedDataObject 29 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 30 * @since 8 31 */ 32declare namespace distributedDataObject { 33 /** 34 * The information about the database bound to the asset. 35 * 36 * @interface BindInfo 37 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 38 * @since 11 39 */ 40 interface BindInfo { 41 /** 42 * The name of store where the asset resides. 43 * 44 * @type { string } 45 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 46 * @since 11 47 */ 48 storeName: string; 49 50 /** 51 * The name of table where the asset resides. 52 * 53 * @type { string } 54 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 55 * @since 11 56 */ 57 tableName: string; 58 59 /** 60 * The Primary key of the rdb table where the asset resides. 61 * 62 * @type { commonType.ValuesBucket } 63 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 64 * @since 11 65 */ 66 primaryKey: commonType.ValuesBucket; 67 68 /** 69 * The field(column) name of the rdb table where the asset resides. 70 * 71 * @type { string } 72 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 73 * @since 11 74 */ 75 field: string; 76 77 /** 78 * Name of the asset to be bound. When the column type is Assets, this field refers to the asset name of 79 * one of the assets. 80 * 81 * @type { string } 82 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 83 * @since 11 84 */ 85 assetName: string; 86 } 87 88 /** 89 * Create distributed object. 90 * 91 * @param { object } source - Source Init data of distributed object. 92 * @returns { DistributedObject } - Return the distributed object. 93 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 94 * @since 8 95 * @deprecated since 9 96 * @useinstead ohos.distributedDataObject.create 97 */ 98 function createDistributedObject(source: object): DistributedObject; 99 100 /** 101 * Create distributed object. 102 * 103 * @param { Context } context - Indicates the application context. 104 * @param { object } source - Source Init data of distributed object. 105 * @returns { DataObject } - Return the distributed object. 106 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 107 * 2. Incorrect parameter types. 108 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 109 * @since 9 110 */ 111 function create(context: Context, source: object): DataObject; 112 113 /** 114 * Generate a random sessionId. 115 * 116 * @returns { string } - Return generated sessionId. 117 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 118 * @since 8 119 */ 120 function genSessionId(): string; 121 122 /** 123 * The response of save. 124 * Contains the parameter information of the save object. 125 * 126 * @interface SaveSuccessResponse 127 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 128 * @since 9 129 */ 130 interface SaveSuccessResponse { 131 /** 132 * sessionId of saved object 133 * 134 * @type { string } 135 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 136 * @since 9 137 */ 138 sessionId: string; 139 140 /** 141 * version of saved object, can compare with DistributedObject.__version 142 * 143 * @type { number } 144 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 145 * @since 9 146 */ 147 version: number; 148 149 /** 150 * deviceid that data saved 151 * data is "local", means save in local device 152 * otherwise, means the deviceId of others device 153 * 154 * @type { string } 155 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 156 * @since 9 157 */ 158 deviceId: string; 159 } 160 161 /** 162 * The response of revokeSave. 163 * Contains the sessionId of the changed object. 164 * 165 * @interface RevokeSaveSuccessResponse 166 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 167 * @since 9 168 */ 169 interface RevokeSaveSuccessResponse { 170 /** 171 * The sessionId of the changed object. 172 * 173 * @type { string } 174 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 175 * @since 9 176 */ 177 sessionId: string; 178 } 179 180 /** 181 * Indicates the observer of object data changed. 182 * 183 * @typedef { function } ChangeCallback 184 * @param { string } sessionId - The sessionId of the changed object. 185 * @param { Array<string> } fields - Property names of changed data. 186 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 187 * @since 20 188 */ 189 type DataObserver = (sessionId: string, fields: Array<string>) => void; 190 191 /** 192 * Indicates the observer of object status changed. 193 * 194 * @typedef { function } StatusObserver 195 * @param { string } sessionId - The sessionId of the changed object. 196 * @param { string } networkId - The networkId of the changed device. 197 * @param { string } status 'online' The object became online on the device and data can be synced to the device; 198 * 'offline' The object became offline on the device and the object can not sync any data; 199 * 'restored' The object restored success. 200 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 201 * @since 20 202 */ 203 type StatusObserver = (sessionId: string, networkId: string, status: string) => void; 204 205 /** 206 * Defines a callback used to return the asset sync progress. 207 * 208 * @typedef { function } ProcessObserver 209 * @param { string } sessionId - Session ID of the observed object. 210 * @param { number } progress - Asset sync progress. The value range is -1 to 100, where 211 * <br>100 indicates that the asset sync is complete and -1 indicates that the asset sync failed. 212 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 213 * @since 20 214 */ 215 type ProgressObserver = (sessionId: string, progress: number) => void; 216 217 /** 218 * Object create by {@link createDistributedObject}. 219 * 220 * @interface DistributedObject 221 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 222 * @since 8 223 * @deprecated since 9 224 * @useinstead ohos.distributedDataObject.DataObject 225 */ 226 interface DistributedObject { 227 /** 228 * Change object session 229 * 230 * @permission ohos.permission.DISTRIBUTED_DATASYNC 231 * @param { string } sessionId - sessionId The sessionId to be joined, if empty, leave all session. 232 * @returns { boolean } - Return a result of function. 233 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 234 * @since 8 235 * @deprecated since 9 236 * @useinstead ohos.distributedDataObject.DataObject.setSessionId 237 */ 238 setSessionId(sessionId?: string): boolean; 239 240 /** 241 * On watch of change 242 * 243 * @param { 'change' } type - Event type, fixed as 'change', indicates data change. 244 * @param { Function } callback 245 * Indicates the observer of object data changed. 246 * {string} sessionId - The sessionId of the changed object. 247 * {Array<string>} fields - Attribute names of changed data. 248 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 249 * @since 8 250 * @deprecated since 9 251 * @useinstead ohos.distributedDataObject.DataObject.on 252 */ 253 on(type: 'change', callback: (sessionId: string, fields: Array<string>) => void): void; 254 255 /** 256 * Off watch of change 257 * 258 * @param { 'change' } type - Event type, fixed as 'change', indicates data change. 259 * @param { Function } callback 260 * Indicates the observer of object data changed. 261 * {string} sessionId - The sessionId of the changed object. 262 * {Array<string>} fields - Attribute names of changed data. 263 * callback If not null, off the callback, if undefined, off all callbacks. 264 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 265 * @since 8 266 * @deprecated since 9 267 * @useinstead ohos.distributedDataObject.DataObject.off 268 */ 269 off(type: 'change', callback?: (sessionId: string, fields: Array<string>) => void): void; 270 271 /** 272 * On watch of status 273 * 274 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 275 * @param { Function } callback 276 * Indicates the observer of object status changed. 277 * {string} sessionId - The sessionId of the changed object. 278 * {string} networkId - NetworkId of the changed device. 279 * {string} status 280 * 'online' The object became online on the device and data can be synced to the device. 281 * 'offline' The object became offline on the device and the object can not sync any data. 282 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 283 * @since 8 284 * @deprecated since 9 285 * @useinstead ohos.distributedDataObject.DataObject.on 286 */ 287 on( 288 type: 'status', 289 callback: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void 290 ): void; 291 292 /** 293 * Off watch of status 294 * 295 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 296 * @param { Function } callback 297 * Indicates the observer of object status changed. 298 * {string} sessionId - The sessionId of the changed object. 299 * {string} networkId - NetworkId of the changed device. 300 * {string} status 301 * 'online' The object became online on the device and data can be synced to the device. 302 * 'offline' The object became offline on the device and the object can not sync any data. 303 * callback If not null, off the callback, if undefined, off all callbacks. 304 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 305 * @since 8 306 * @deprecated since 9 307 * @useinstead ohos.distributedDataObject.DataObject.off 308 */ 309 off( 310 type: 'status', 311 callback?: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void 312 ): void; 313 } 314 315 /** 316 * Object create by {@link create}. 317 * 318 * @interface DataObject 319 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 320 * @since 9 321 */ 322 interface DataObject { 323 /** 324 * Change object session. 325 * 326 * @permission ohos.permission.DISTRIBUTED_DATASYNC 327 * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. 328 * @param {AsyncCallback<void>} callback - The callback of setSessionId. 329 * @throws {BusinessError} 201 - Permission verification failed. 330 * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types. 331 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 332 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 333 * @since 9 334 */ 335 /** 336 * Change object session. 337 * 338 * @permission ohos.permission.DISTRIBUTED_DATASYNC 339 * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. 340 * @param {AsyncCallback<void>} callback - The callback of setSessionId. 341 * @throws {BusinessError} 201 - Permission verification failed. 342 * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Incorrect parameter types; 343 * 2. The sessionId allows only letters, digits, and underscores(_), and cannot exceed 128 in length. 344 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 345 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 346 * @since 12 347 */ 348 setSessionId(sessionId: string, callback: AsyncCallback<void>): void; 349 350 /** 351 * Leave all session. 352 * 353 * @permission ohos.permission.DISTRIBUTED_DATASYNC 354 * @param {AsyncCallback<void>} callback - The callback of setSessionId. 355 * @throws {BusinessError} 201 - Permission verification failed. 356 * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types. 357 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 358 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 359 * @since 9 360 */ 361 /** 362 * Leave all session. 363 * 364 * @param {AsyncCallback<void>} callback - The callback of setSessionId. 365 * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types. 366 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 367 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 368 * @since 20 369 */ 370 setSessionId(callback: AsyncCallback<void>): void; 371 372 /** 373 * Change object session. 374 * 375 * @permission ohos.permission.DISTRIBUTED_DATASYNC 376 * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. 377 * @returns {Promise<void>} - The promise returned by the function. 378 * @throws {BusinessError} 201 - Permission verification failed. 379 * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types. 380 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 381 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 382 * @since 9 383 */ 384 /** 385 * Change object session. 386 * 387 * @permission ohos.permission.DISTRIBUTED_DATASYNC 388 * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. 389 * @returns {Promise<void>} - The promise returned by the function. 390 * @throws {BusinessError} 201 - Permission verification failed. 391 * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Incorrect parameter types; 392 * 2. The sessionId allows only letters, digits, and underscores(_), and cannot exceed 128 in length. 393 * @throws {BusinessError} 15400001 - Failed to create the in-memory database. 394 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 395 * @since 12 396 */ 397 setSessionId(sessionId?: string): Promise<void>; 398 399 /** 400 * On watch of change. 401 * 402 * @param { 'change' } type - event type, fixed as 'change', indicates data change. 403 * @param { Function } callback 404 * indicates the observer of object data changed. 405 * {string} sessionId - the sessionId of the changed object. 406 * {Array<string>} fields - Attribute names of changed data. 407 * sessionId The sessionId of the changed object. 408 * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 409 * 2. Incorrect parameter types. 410 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 411 * @since 9 412 */ 413 on(type: 'change', callback: (sessionId: string, fields: Array<string>) => void ): void; 414 415 /** 416 * Off watch of change. 417 * 418 * @param { 'change' } type - Event type, fixed as 'change', indicates data change. 419 * @param { Function } callback 420 * indicates the observer of object data changed. 421 * {string} sessionId - The sessionId of the changed object. 422 * {Array<string>} fields - Attribute names of changed data. 423 * callback If not null, off the callback, if undefined, off all callbacks. 424 * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 425 * 2. Incorrect parameter types. 426 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 427 * @since 9 428 */ 429 off(type: 'change', callback?: (sessionId: string, fields: Array<string>) => void ): void; 430 431 /** 432 * On watch of status. 433 * 434 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 435 * @param { Function } callback 436 * indicates the observer of object status changed. 437 * {string} sessionId - The sessionId of the changed object. 438 * {string} networkId - NetworkId of the changed device. 439 * {string} status 440 * 'online' The object became online on the device and data can be synced to the device. 441 * 'offline' The object became offline on the device and the object can not sync any data. 442 * 'restored' The object restored success. 443 * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 444 * 2. Incorrect parameter types. 445 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 446 * @since 9 447 */ 448 on( 449 type: 'status', 450 callback: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void 451 ): void; 452 453 /** 454 * Off watch of status. 455 * 456 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 457 * @param { Function } callback 458 * Indicates the observer of object status changed. 459 * {string} sessionId - The sessionId of the changed object. 460 * {string} networkId - NetworkId of the changed device. 461 * {string} status 462 * 'online' The object became online on the device and data can be synced to the device. 463 * 'offline' The object became offline on the device and the object can not sync any data. 464 * callback If not null, off the callback, if undefined, off all callbacks. 465 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 466 * 2. Incorrect parameter types. 467 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 468 * @since 9 469 */ 470 off( 471 type: 'status', 472 callback?: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void 473 ): void; 474 475 /** 476 * Save object, after save object data successfully, the object data will not release when app existed, 477 * and resume data on saved device after app existed. 478 * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data, 479 * you should encrypt it 480 * The saved data will be released when 481 * 1. saved after 24h. 482 * 2. app uninstalled. 483 * 3. after resume data success, system will auto delete the saved data. 484 * 485 * @param { string } deviceId - Indicates the device that will resume the object data. 486 * @param { AsyncCallback<SaveSuccessResponse> } callback 487 * {SaveSuccessResponse}: The response of save. 488 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 489 * 2. Incorrect parameter types. 490 * @throws { BusinessError } 801 - Capability not supported. 491 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 492 * @since 9 493 */ 494 save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void; 495 496 /** 497 * Save object, after save object data successfully, the object data will not release when app existed, 498 * and resume data on saved device after app existed. 499 * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data, 500 * you should encrypt it. 501 * The saved data will be released when 502 * 1. saved after 24h. 503 * 2. app uninstalled. 504 * 3. after resume data success, system will auto delete the saved data. 505 * 506 * @param { string } deviceId - Indicates the device that will resume the object data. 507 * @returns { Promise<SaveSuccessResponse> } {SaveSuccessResponse}: The response of save. 508 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 509 * 2. Incorrect parameter types. 510 * @throws { BusinessError } 801 - Capability not supported. 511 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 512 * @since 9 513 */ 514 save(deviceId: string): Promise<SaveSuccessResponse>; 515 516 /** 517 * Revoke save object, delete saved object immediately, if object is saved in local device, 518 * it will delete saved data on all trusted device. 519 * if object is saved in other device, it will delete data in local device. 520 * 521 * @param { AsyncCallback<RevokeSaveSuccessResponse> } callback 522 * {RevokeSaveSuccessResponse}: The response of revokeSave. 523 * @throws { BusinessError } 401 - Parameter error. Incorrect parameter types. 524 * @throws { BusinessError } 801 - Capability not supported. 525 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 526 * @since 9 527 */ 528 revokeSave(callback: AsyncCallback<RevokeSaveSuccessResponse>): void; 529 530 /** 531 * Revoke save object, delete saved object immediately, if object is saved in local device, 532 * it will delete saved data on all trusted device. 533 * if object is saved in other device, it will delete data in local device. 534 * 535 * @returns { Promise<RevokeSaveSuccessResponse> } {RevokeSaveSuccessResponse}: The response of revokeSave. 536 * @throws { BusinessError } 801 - Capability not supported. 537 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 538 * @since 9 539 */ 540 revokeSave(): Promise<RevokeSaveSuccessResponse>; 541 542 /** 543 * Bind an Asset of a distributed object to an asset in rdb that points to the same asset file, which means that 544 * both assets have the same uri. 545 * @param { string } assetKey - Indicates the key of the asset type in Object. 546 * @param { BindInfo } bindInfo - Indicates the information of the asset in RelationalStore. 547 * @param { AsyncCallback<void> } callback - The callback of bindAssetStore. 548 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 549 * 2. Incorrect parameter types. 550 * @throws { BusinessError } 801 - Capability not supported. 551 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 552 * @since 11 553 */ 554 bindAssetStore(assetKey: string, bindInfo: BindInfo, callback: AsyncCallback<void>): void; 555 556 /** 557 * Bind an Asset of a distributed object to an asset in rdb that points to the same asset file, which means that 558 * both assets have the same uri. 559 * @param { string } assetKey - Indicates the key of the asset type in Object. 560 * @param { BindInfo } bindInfo - Indicates the information of the asset in RelationalStore. 561 * @returns { Promise<void> } The promise returned by the function. 562 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 563 * 2. Incorrect parameter types. 564 * @throws { BusinessError } 801 - Capability not supported. 565 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 566 * @since 11 567 */ 568 bindAssetStore(assetKey: string, bindInfo: BindInfo): Promise<void>; 569 570 /** 571 * On watch of change. 572 * 573 * @param { 'change' } type - Event type, fixed as 'change', indicates data change. 574 * @param { DataObserver } callback - The observer of object data changed. 575 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 576 * @since 20 577 */ 578 on(type: 'change', callback: DataObserver): void; 579 580 /** 581 * Off watch of change. 582 * 583 * @param { 'change' } type - Event type, fixed as 'change', indicates data change. 584 * @param { DataObserver } [callback] - The observer of object data changed, if not null, off the callback, if undefined, off all callbacks. 585 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 586 * @since 20 587 */ 588 off(type: 'change', callback?: DataObserver): void; 589 590 /** 591 * On watch of status. 592 * 593 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 594 * @param { StatusObserver } callback - The observer of object status changed. 595 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 596 * @since 20 597 */ 598 on(type: 'status', callback: StatusObserver): void; 599 600 /** 601 * Off watch of status. 602 * 603 * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object. 604 * @param { StatusObserver } [callback] - The observer of object status changed, if not null, off the callback, if undefined, off all callbacks. 605 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 606 * @since 20 607 */ 608 off(type: 'status', callback?: StatusObserver): void; 609 610 /** 611 * On watch of progress. 612 * 613 * @param { 'progressChanged' } type - Event type, fixed as 'progressChanged', indicates the progress of asset sync 614 * <br>in object. 615 * @param { ProgressObserver } callback - The observer of progress of asset sync. 616 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 617 * @since 20 618 */ 619 on(type: 'progressChanged', callback: ProgressObserver): void; 620 621 /** 622 * Off watch of process. 623 * 624 * @param { 'progressChanged' } type - Event type, fixed as 'progressChanged', indicates the progress of asset sync 625 * <br>in object. 626 * @param { ProgressObserver } [callback] - The observer of object status changed, if not null, off the callback, if 627 * <br>undefined, off all callbacks. 628 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 629 * @since 20 630 */ 631 off(type: 'progressChanged', callback?: ProgressObserver): void; 632 633 /** 634 * Mark an attribute of a distributed object as an asset type. This interface must be called before setSessionId. 635 * 636 * @param { string } assetKey - Indicates the key of the asset type in Object. 637 * @param { string } uri - Indicates the uri of asset. 638 * @returns { Promise<void> } The promise returned by the function. 639 * @throws { BusinessError } 15400002 - Parameter error. Possible causes: 640 * 1. The assetKey is invalid, such as ""; 641 * 2. The uri is invalid, such as "". 642 * @throws {BusinessError} 15400003 - The sessionId of the distributed object has been set. 643 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 644 * @since 20 645 */ 646 setAsset(assetKey: string, uri: string): Promise<void>; 647 648 /** 649 * Marks an attribute of a distributed object as an asset array type. This interface must be called before setSessionId. 650 * 651 * @param { string } assetsKey - Indicates the key of the asset type in Object. 652 * @param { Array<string> } uris - Indicates the uri array of asset. 653 * @returns { Promise<void> } The promise returned by the function. 654 * @throws { BusinessError } 15400002 - Parameter error. Possible causes: 655 * 1. The assetsKey is invalid, such as ""; 656 * 2. The uris is invalid, such as the length of uris is more than 50. 657 * @throws {BusinessError} 15400003 - The sessionId of the distributed object has been set. 658 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject 659 * @since 20 660 */ 661 setAssets(assetsKey: string, uris: Array<string>): Promise<void>; 662 } 663} 664 665export default distributedDataObject; 666