1# @ohos.data.cloudExtension (Device-Cloud Sharing Extension) (System API) 2 3The **cloudExtension** module provides APIs for third-party vendors to implement the device-cloud sharing service. You can use these APIs to share the device data to the server and implement device-cloud data sharing, including sharing and unsharing data, exiting a share, changing the privilege (operation permissions) on the shared data, querying participants by data identifier or invitation code, and confirming or changing a sharing invitation. Before you get started, it is helpful to understand the following concepts: 4 5**sharingResource**: an identifier of the string type generated for each data record shared by an application when device-cloud sync is performed. It uniquely identifies the data record being shared. 6 7**Participant**: all participants involved in a share, including the inviter and invitees. 8 9**invitationCode**: an invitation code generated by the share server for a share operation. It is generated after a share is initiated and attached to an invitation to be pushed to the devices of target invitees. The target invitees then confirm the invitation via this code. 10 11**CloudService**: device-cloud sync server, which implements data sync across devices with the same account for the same application. 12 13**ShareCenter**: device-cloud sharing server, which implements cross-account and cross-device data sharing for the same application. 14 15> **NOTE** 16> 17> - The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. 18> 19> - The APIs provided by this module are system APIs. 20 21## Modules to Import 22 23```ts 24import { cloudExtension } from '@kit.ArkData'; 25``` 26 27## Result<T> 28 29Represents the data sharing result. 30 31**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 32 33| Name | Type | Mandatory | Description | 34| ----------- | --------------------------- | --- | ------------ | 35| code | number | Yes | Error code. | 36| description | string | No | Detailed description of the error code. The default value is **undefined**. | 37| value | T | No | Value returned. The specific type is specified by the **T** parameter. The default value is **undefined**. | 38 39## CloudAsset 40 41Represents the cloud asset information. 42 43**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 44 45| Name | Type | Mandatory| Description | 46| ------- | ------ | ---- | ------------------------------------ | 47| assetId | string | Yes | Asset ID. | 48| hash | string | Yes | Hashed value of the asset modification time and size.| 49 50## CloudAssets 51 52Represents an array of [CloudAsset](#cloudasset). 53 54**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 55 56| Type | Description | 57| -------------------------------- | ----------------------------------------- | 58| Array<[CloudAsset](#cloudasset)> | Array of [CloudAsset](#cloudasset).| 59 60## ServiceInfo 61 62Represents the cloud service information. 63 64**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 65 66| Name | Type | Mandatory| Description | 67| -------------- | ------- | ---- | ------------------------------------------------------------ | 68| enableCloud | boolean | Yes | Whether the cloud service is enabled. The value **true** means that the cloud service is enabled, and the value **false** means the opposite.| 69| id | string | Yes | Cloud account ID generated using SHA-256. | 70| totalSpace | number | Yes | Total account space on the server, in KB. | 71| remainingSpace | number | Yes | Available account space on the server, in KB. | 72| user | number | Yes | Current user ID of the device. | 73 74## Flag 75 76Enumerates the operations that can be performed on a database. Use the enum name rather than the enum value. 77 78**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 79 80| Name | Value | Description | 81| ------ | ---- | ---------- | 82| INSERT | 0 | Insert data.| 83| UPDATE | 1 | Update data.| 84| DELETE | 2 | Delete data.| 85 86## ExtensionValue 87 88Represents additional information about a data record. 89 90**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 91 92| Name | Type | Read-Only| Optional| Description | 93| ---------- | --------------- | ---- | ---- | ------------------ | 94| id | string | Yes | No | ID generated when data is inserted.| 95| createTime | number | Yes | No | Time when a row of data is created. | 96| modifyTime | number | Yes | No | Time when a row of data is modified. | 97| operation | [Flag](#flag) | Yes | No | Operation performed.| 98 99## CloudType 100 101Enumerates the types of the cloud data field. The specific type is determined by the parameter function. 102 103**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 104 105| Type | Description | 106| ------------------------- | ------------------------------- | 107| null | The value is null. | 108| number | The value is a number. | 109| string | The value is a string. | 110| boolean | The value is true or false. | 111| Uint8Array | The value is a Uint8 array.| 112| [CloudAsset](#cloudasset) | The value is of the cloud asset type. | 113| [CloudAssets](#cloudassets) | The value is an array of cloud assets. | 114 115## CloudInfo 116 117Represents the cloud information. 118 119**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 120 121| Name | Type | Mandatory| Description | 122| --------- | --------------------------------------------------- | ---- | -------------- | 123| cloudInfo | [ServiceInfo](#serviceinfo) | Yes | Cloud service information. | 124| apps | Record<string, [AppBriefInfo](#appbriefinfo)> | Yes | Brief application information.| 125 126## CloudData 127 128Represents the cloud data. 129 130**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 131 132| Name | Type | Mandatory| Description | 133| ---------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 134| nextCursor | string | Yes | Cursor for data query. | 135| hasMore | boolean | Yes | Whether there is data to be queried on the on the server. The value **true** means there is data to be queried on the server; the value **false** means the opposite.| 136| values | Array<Record<string, [CloudType](#cloudtype)>> | Yes | Array of data to be queried, which consists of the data value and [ExtensionValue](#extensionvalue).| 137 138## AppBriefInfo 139 140Represents the brief application information. 141 142**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 143 144| Name | Type | Mandatory| Description | 145| ----------- | ------- | ---- | ---------------------------------- | 146| appId | string | Yes | Application ID. | 147| bundleName | string | Yes | Bundle name of the application. | 148| cloudSwitch | boolean | Yes | Whether the cloud service is enabled for the application. The value **true** means the cloud service is enabled; the value **false** means the opposite.| 149| instanceId | number | Yes | Application twin ID. The value **0** indicates the application itself, and the twin ID increases in ascending order.| 150 151## FieldType 152 153Enumerates the types of the fields in a database table. Use the enum name rather than the enum value. 154 155**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 156 157| Name | Value | Description | 158| -------------------------------------------------- | ---- | -------------------------------------- | 159| NULL | 0 | Null. | 160| NUMBER | 1 | Number. | 161| REAL | 2 | Double-precision floating point. | 162| TEXT | 3 | Text. | 163| BOOL | 4 | Boolean. | 164| BLOB | 5 | BLOB, which can hold a binary file.| 165| [ASSET](arkts-apis-data-relationalStore-i.md#asset10) | 6 | Asset. | 166| [ASSETS](arkts-apis-data-relationalStore-t.md#assets10) | 7 | Assets. | 167 168## Field 169 170Represents a field in the database. 171 172**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 173 174| Name | Type | Mandatory| Description | 175| -------- | ------------------------- | ---- | ---------------------- | 176| alias | string | Yes | Alias of the field in the table.| 177| colName | string | Yes | Name of the column, in which the field is located. | 178| type | [FieldType](#fieldtype) | Yes | Type of the field. | 179| primary | boolean | Yes | Whether the current column is the primary key. The value **true** means the current column is the primary key; the value **false** means the opposite.| 180| nullable | boolean | Yes | Whether the current column can be null. The value **true** means the current column can be null; the value **false** means the opposite. | 181 182## Table 183 184Represents the table information. 185 186**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 187 188| Name | Type | Mandatory| Description | 189| ------ | ---------------------------- | ---- | ---------------------------- | 190| alias | string | Yes | Alias of the table in the database.| 191| name | string | Yes | Table name. | 192| fields | Array<[Field](#field)> | Yes | Field information in the table. | 193 194## Database 195 196Represents the database information. 197 198**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 199 200| Name | Type | Mandatory| Description | 201| ------ | ---------------------------- | ---- | -------------------------------- | 202| name | string | Yes | Name of the database. | 203| alias | string | Yes | Alias of the database on the server. | 204| tables | Array<[Table](#table)> | Yes | Table in the database, including the detailed data information.| 205 206## AppSchema 207 208Represents the application database schema. 209 210**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 211 212| Name | Type | Mandatory| Description | 213| ---------- | ------------------------------------ | ---- | ------------------ | 214| bundleName | string | Yes | Bundle name of the application. | 215| version | number | Yes | Version of the database schema.| 216| databases | Array<[Database](#database)> | Yes | Database information of the application.| 217 218## SubscribeId 219 220Represents the subscription ID information. 221 222**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 223 224| Name | Type | Mandatory| Description | 225| ------------- | ------ | ---- | ---------------------- | 226| databaseAlias | string | Yes | Name of the database on the server.| 227| id | string | Yes | Subscription ID. | 228 229## SubscribeInfo 230 231Represents the subscription information. 232 233**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 234 235| Name | Type | Mandatory| Description | 236| -------------- | ------------------------------------------------------------ | ---- | -------------------- | 237| expirationTime | number | Yes | Subscription expiration time, in ms.| 238| subscribe | Record<string, Array<[SubscribeId](#subscribeid)>> | Yes | Subscription information. | 239 240## LockInfo 241 242Represents the cloud database lock information. 243 244**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 245 246| Name | Type | Mandatory| Description | 247| -------- | ------ | ---- | ------------------------------- | 248| interval | number | Yes | Lock period of the cloud database, in seconds.| 249| lockId | number | Yes | Lock ID. | 250 251## ErrorCode 252 253Enumerates the device-cloud sync states. Use the enum name rather than the enum value. 254 255**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 256 257| Name | Value | Description | 258| --------------------- | ---- | ------------------------------------------------------------ | 259| SUCCESS | 0 | The device-cloud sync is successful. | 260| UNKNOWN_ERROR | 1 | An unknown error occurs during the device-cloud sync process. | 261| NETWORK_ERROR | 2 | A network error occurs during the device-cloud sync process. | 262| CLOUD_DISABLED | 3 | Cloud sync is disabled. | 263| LOCKED_BY_OTHERS | 4 | The device-cloud sync of another device is being performed. The sync of the local device can be performed only when the device-cloud resources are available.| 264| RECORD_LIMIT_EXCEEDED | 5 | The number of records or size of the data to be synced exceeds the maximum. The maximum value is configured on the cloud.| 265| NO_SPACE_FOR_ASSET | 6 | The remaining cloud space is less than the size of the data to be synced. | 266 267## cloudExtension.createCloudServiceStub 268 269createCloudServiceStub(instance: CloudService): Promise<rpc.RemoteObject> 270 271Creates a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance based on a [CloudService](#cloudservice) instance. The system uses this object to call the APIs of the [CloudService](#cloudservice) instance. This API uses a promise to return the result. 272 273**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 274 275**Parameters** 276 277| Name | Type | Mandatory| Description | 278| --------- | ------------------------------- | ---- | -------------------------------- | 279| instance | [CloudService](#cloudservice) | Yes | Instance of the [CloudService](#cloudservice) class. | 280 281**Return value** 282 283| Type | Description | 284| ------------------- | ------------------------- | 285| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [CloudService](#cloudservice).| 286 287**Example** 288 289```ts 290import { Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 291import { rpc } from '@kit.IPCKit'; 292 293export default class MyCloudService implements cloudExtension.CloudService { 294 constructor() {} 295 async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 296 // ... 297 } 298} 299 300export default class MyServiceExtension extends ServiceExtensionAbility { 301 onCreate(want: Want) { 302 console.info(`onCreate: ${want}`); 303 } 304 onRequest(want: Want, startId: number) { 305 console.info(`onRequest: ${want} ${startId}`); 306 } 307 onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject> { 308 console.info(`onConnect: ${want}`); 309 return cloudExtension.createCloudServiceStub(new MyCloudService()); 310 } 311 onDisconnect(want: Want) { 312 console.info(`onDisconnect: ${want}`); 313 } 314 onDestroy() { 315 console.info('onDestroy'); 316 } 317} 318``` 319 320## cloudExtension.createShareServiceStub 321 322createShareServiceStub(instance: ShareCenter): Promise<rpc.RemoteObject> 323 324Creates a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance based on a [ShareCenter](#sharecenter) instance. The system uses this object to call the APIs of the [ShareCenter](#sharecenter) instance. This API uses a promise to return the result. 325 326**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 327 328**Parameters** 329 330| Name | Type | Mandatory| Description | 331| --------- | ------------------------------- | ---- | -------------------------------- | 332| instance | [ShareCenter](#sharecenter) | Yes | Instance of the [ShareCenter](#sharecenter) class. | 333 334**Return value** 335 336| Type | Description | 337| ------------------- | ------------------------- | 338| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [ShareCenter](#sharecenter).| 339 340**Example** 341 342```ts 343import { rpc } from '@kit.IPCKit'; 344 345export default class MyShareCenter implements cloudExtension.ShareCenter { 346 constructor() {} 347 // ... 348} 349 350export default class MyCloudService implements cloudExtension.CloudService { 351 constructor() {} 352 async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 353 console.info(`connect share center, bundle: ${bundleName}`); 354 return cloudExtension.createShareServiceStub(new MyShareCenter()); 355 } 356} 357``` 358 359## cloudExtension.createCloudDBStub 360 361createCloudDBStub(instance: CloudDB): Promise<rpc.RemoteObject> 362 363Creates a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance based on a [CloudDB](#clouddb) instance. The system uses this object to call the APIs of the [CloudDB](#clouddb) instance. This API uses a promise to return the result. 364 365**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 366 367**Parameters** 368 369| Name | Type | Mandatory| Description | 370| -------- | --------------------- | ---- | ------------------------------- | 371| instance | [CloudDB](#clouddb) | Yes | [CloudDB](#clouddb) instance.| 372 373**Return value** 374 375| Type | Description | 376| ------------------------------------------------------------ | ------------------------------------------------------------ | 377| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [CloudDB](#clouddb).| 378 379```ts 380import { rpc } from '@kit.IPCKit'; 381 382export default class MyCloudDB implements cloudExtension.CloudDB { 383 // ... 384} 385 386export default class MyCloudService implements cloudExtension.CloudService { 387 constructor() {} 388 // ... 389 async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 390 console.info(`connect DB, bundleName: ${bundleName}`); 391 return cloudExtension.createCloudDBStub(new MyCloudDB()); 392 } 393} 394``` 395 396## cloudExtension.createAssetLoaderStub 397 398createAssetLoaderStub(instance: AssetLoader): Promise<rpc.RemoteObject> 399 400Creates a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance based on an [AssetLoader](#assetloader) instance. The system uses this object to call the APIs of the [AssetLoader](#assetloader) instance. This API uses a promise to return the result. 401 402**Parameters** 403 404| Name | Type | Mandatory| Description | 405| -------- | ----------------------------- | ---- | ------------------------------------------------- | 406| instance | [AssetLoader](#assetloader) | Yes | [AssetLoader](#assetloader) instance.| 407 408**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 409 410**Return value** 411 412| Type | Description | 413| ------------------------------------------------------------ | ------------------------------------------------------------ | 414| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [AssetLoader](#assetloader).| 415 416**Example** 417 418```ts 419import { rpc } from '@kit.IPCKit'; 420 421export default class MyAssetLoader implements cloudExtension.AssetLoader { 422 // ... 423} 424 425export default class MyCloudService implements cloudExtension.CloudService { 426 constructor() {} 427 // ... 428 async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 429 console.info(`connect asset loader, bundle: ${bundleName}`); 430 return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 431 } 432} 433``` 434 435 436 437## CloudDB 438 439Provides APIs for performing cloud database operations. 440 441### generateId 442 443generateId(count: number): Promise<Result<Array<string>>> 444 445Generates IDs for the data records inserted to the cloud database. The IDs are unique. 446 447**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 448 449**Parameters** 450 451| Name| Type | Mandatory| Description | 452| ------ | ------ | ---- | -------------------- | 453| count | number | Yes | Number of IDs to generate.| 454 455**Return value** 456 457| Type | Description | 458| -------------------------------------------------------- | ------------------------------------------------------------ | 459| Promise<[Result](#resultt)<Array<string>> | Promise used to return the generated IDs in [Result](#resultt).| 460 461**Example** 462 463```ts 464export default class MyCloudDB implements cloudExtension.CloudDB { 465 async generateId(count: number): Promise<cloudExtension.Result<Array<string>>> { 466 console.info(`generate id, count: ${count}`); 467 let result = new Array<string>(); 468 // ... 469 return { 470 code: cloudExtension.ErrorCode.SUCCESS, 471 description: 'generateId succeeded', 472 value: result 473 }; 474 } 475 // ... 476} 477``` 478 479### update 480 481update(table: string, values: Array<Record<string, CloudType>>, extensions: Array<Record<string, CloudType>> ): Promise<Array<Result<Record<string, CloudType>>>> 482 483Updates data in the cloud. 484 485**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 486 487**Parameters** 488 489| Name | Type | Mandatory| Description | 490| ---------- | ------------------------------------------------------------ | ---- | ---------------------- | 491| table | string | Yes | Table name.| 492| values | Array<Record<string, [CloudType](#cloudtype)>> | Yes | Data to insert. | 493| extensions | Array<Record<string, [CloudType](#cloudtype)>> | Yes | Extended information about the current data.| 494 495**Return value** 496 497| Type | Description | 498| ------------------------------------------------------------ | --------------------------------------- | 499| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise used to return the update result and updated data.| 500 501**Example** 502 503```ts 504export default class MyCloudDB implements cloudExtension.CloudDB { 505 // ... 506 async update(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 507 console.info(`update, table: ${table}`); 508 let updateRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 509 // ... 510 // Return the data update result. 511 return updateRes; 512 } 513 // ... 514} 515``` 516 517### insert 518 519insert(table: string, values: Array<Record<string, CloudType>>, extensions: Array<Record<string, CloudType>>): Promise<Array<Result<Record<string, CloudType>>>> 520 521Inserts data to a cloud database table. 522 523**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 524 525**Parameters** 526 527| Name | Type | Mandatory| Description | 528| ---------- | ---------------------------------------------------------- | ---- | ------------------------ | 529| table | string | Yes | Name of the target table. | 530| values | Array<Record<string, [CloudType](#cloudtype)>> | Yes | Data to insert. | 531| extensions | Array<Record<string, [CloudType](#cloudtype)>> | Yes | Extended information about the current data.| 532 533**Return value** 534 535| Type | Description | 536| ------------------------------------------------------------ | ------------------------------------- | 537| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise used to return the inserted data and operation result.| 538 539**Example** 540 541```ts 542export default class MyCloudDB implements cloudExtension.CloudDB { 543 // ... 544 async insert(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 545 console.info(`insert, table: ${table}`); 546 let insertRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 547 // ... 548 // Return the operation result. 549 return insertRes; 550 } 551 // ... 552} 553``` 554 555### delete 556 557delete(table: string, extensions: Array<Record<string, CloudType>> ): Promise<Array<Result<Record<string, CloudType>>>> 558 559Deletes data from a cloud database table. 560 561**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 562 563**Parameters** 564 565| Name | Type | Mandatory| Description | 566| ---------- | --------------------------------------------------------- | ---- | ------------------------ | 567| table | string | Yes | Name of the target table. | 568| extensions | Array<Record<string,[CloudType](#cloudtype)>> | Yes | Extended information about the current data.| 569 570**Return value** 571 572| Type | Description | 573| ------------------------------------------------------------ | ----------------------------------------- | 574| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise used to return the deleted data and operation result.| 575 576**Example** 577 578```ts 579export default class MyCloudDB implements cloudExtension.CloudDB { 580 // ... 581 async delete(table: string, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 582 console.info(`delete, table: ${table}`); 583 let deleteRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 584 // ... 585 // Return the operation result. 586 return deleteRes; 587 } 588 // ... 589} 590``` 591 592### query 593 594query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<Result<CloudData>> 595 596Queries data in a cloud database table. 597 598**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 599 600**Parameters** 601 602| Name | Type | Mandatory| Description | 603| ----------- | ------------- | ---- | ------------------------ | 604| table | string | Yes | Table name. | 605| fields | Array<string> | Yes | Name of the fields to query. | 606| queryCount | number | Yes | Number of data records to query.| 607| queryCursor | string | Yes | Cursor for the query. | 608 609**Return value** 610 611| Type | Description | 612| ------------------------------------------------------------ | --------------------------------------- | 613| Promise<[Result](#resultt)<[CloudData](#clouddata)>> | Promise used to return the data and operation result.| 614 615**Example** 616 617```ts 618export default class MyCloudDB implements cloudExtension.CloudDB { 619 // ... 620 async query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<cloudExtension.Result<cloudExtension.CloudData>> { 621 console.info(`query, table: ${table}`); 622 // ... 623 // Return the operation result. 624 return { 625 code: cloudExtension.ErrorCode.SUCCESS, 626 description: 'query succeeded', 627 value: { 628 nextCursor: "test_nextCursor", 629 hasMore: true, 630 values: [] 631 } 632 }; 633 } 634 // ... 635} 636``` 637 638### lock 639 640lock(): Promise<Result<LockInfo>> 641 642Locks this cloud database. 643 644**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 645 646**Return value** 647 648| Type | Description | 649| ------------------------------------------------------------ | --------------------------------------------------- | 650| Promise<[Result](#resultt)<[LockInfo](#lockinfo)>> | Promise used to return the lock ID and lock period.| 651 652**Example** 653 654```ts 655let test_time: number = 10; 656let test_lockId: number = 1; 657export default class MyCloudDB implements cloudExtension.CloudDB { 658 // ... 659 async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 660 console.info(`DB lock`); 661 // ... 662 // Return the operation result. 663 return { 664 code: cloudExtension.ErrorCode.SUCCESS, 665 description: 'lock succeeded', 666 value: { 667 interval: test_time, 668 lockId: test_lockId 669 } 670 }; 671 } 672 // ... 673} 674``` 675 676### heartbeat 677 678heartbeat(lockId: number): Promise<Result<LockInfo>> 679 680Extends the lock period of the database. 681 682**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 683 684**Parameters** 685 686| Name| Type | Mandatory| Description | 687| ------ | ------ | ---- | --------------------- | 688| lockId | number | Yes | Lock ID.| 689 690**Return value** 691 692| Type | Description | 693| ------------------------------------------------------------ | ------------------------------------------------- | 694| Promise<[Result](#resultt)<[LockInfo](#lockinfo)>> | Promise used to return the lock ID and lock period.| 695 696**Example** 697 698```ts 699let test_lockId: number = 1; 700let test_time: number = 10; 701export default class MyCloudDB implements cloudExtension.CloudDB { 702 // ... 703 async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 704 console.info(`heartbeat lock`); 705 // ... 706 // Return the operation result. 707 return { 708 code: cloudExtension.ErrorCode.SUCCESS, 709 description: 'heartbeat succeeded', 710 value: { 711 interval: test_time, 712 lockId: test_lockId 713 } 714 }; 715 } 716 // ... 717} 718``` 719 720### unlock 721 722unlock(lockId: number): Promise<Result<boolean>> 723 724Unlocks a cloud database. 725 726**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 727 728**Parameters** 729 730| Name| Type | Mandatory| Description | 731| ------ | ------ | ---- | ------------- | 732| lockId | number | Yes | Lock ID to release.| 733 734**Return value** 735 736| Type | Description | 737| ------------------------------------------------ | ------------------------------------------------------------ | 738| Promise<[Result](#resultt)<boolean>> | Promise used to return the result. The value **true** means the operation is successful; the value **false** means the opposite. | 739 740**Example** 741 742```ts 743export default class MyCloudDB implements cloudExtension.CloudDB { 744 // ... 745 async unlock(lockId: number): Promise<cloudExtension.Result<boolean>> { 746 console.info(`unlock`); 747 // ... 748 // Return the operation result. 749 return { 750 code: cloudExtension.ErrorCode.SUCCESS, 751 description: 'unlock succeeded', 752 value: false 753 }; 754 } 755 // ... 756} 757``` 758 759## CloudService 760 761Provides APIs for interacting with the cloud sync service. You need to inherit this class and implement APIs of this class. The system calls these APIs to connect to the cloud and use the cloud sync service. 762 763### getServiceInfo 764 765getServiceInfo(): Promise<ServiceInfo> 766 767Obtains the server information. This API uses a promise to return the result. 768 769**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 770 771**Return value** 772 773| Type | Description | 774| -------------------------------------------- | ----------------------------------- | 775| Promise<[ServiceInfo](#serviceinfo)> | Promise used to return the server information obtained.| 776 777**Example** 778 779```ts 780import { rpc } from '@kit.IPCKit'; 781 782let test_space: number = 100; 783let test_userId: number = 1; 784 785export default class MyCloudService implements cloudExtension.CloudService { 786 constructor() {} 787 // ... 788 async getServiceInfo(): Promise<cloudExtension.ServiceInfo> { 789 console.info(`get service info`); 790 // ... 791 return { 792 enableCloud: true, 793 id: "test_id", 794 totalSpace: test_space, 795 remainingSpace: test_space, 796 user: test_userId, 797 }; 798 } 799} 800``` 801 802### getAppBriefInfo 803 804getAppBriefInfo(): Promise<Record<string, AppBriefInfo>> 805 806Obtains brief application information. This API uses a promise to return the result. 807 808**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 809 810**Return value** 811 812| Type | Description | 813| ------------------------------------------------------------ | ------------------------------------------------------------ | 814| Promise<Record<string, [AppBriefInfo](#appbriefinfo)>>> | Promise used to return **bundleName** and [AppBriefInfo](#appbriefinfo), in KV pairs.| 815 816**Example** 817 818```ts 819export default class MyCloudService implements cloudExtension.CloudService { 820 constructor() {} 821 // ... 822 async getAppBriefInfo(): Promise<Record<string, cloudExtension.AppBriefInfo>> { 823 console.info(`get app brief info`); 824 // ... 825 return { 826 "test_bundle": 827 { 828 appId: "test_appID", 829 bundleName: "test_bundlename", 830 cloudSwitch: true, 831 instanceId: 0, 832 } 833 }; 834 } 835} 836``` 837 838### getAppSchema 839 840 getAppSchema(bundleName: string): Promise<Result<AppSchema>> 841 842Obtains the application database schema information. This API uses a promise to return the result. 843 844**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 845 846**Parameters** 847 848| Name | Type | Mandatory| Description | 849| ---------- | ------ | ---- | ---------- | 850| bundleName | string | Yes | Bundle name of the application.| 851 852**Return value** 853 854| Type | Description | 855| ------------------------------------------------------------ | ------------------------------------- | 856| Promise<[Result](#resultt)<[AppSchema](#appschema)>> | Promise used to return the schema information obtained.| 857 858**Example** 859 860```ts 861export default class MyCloudService implements cloudExtension.CloudService { 862 constructor() { 863 } 864 // ... 865 async getAppSchema(bundleName: string): Promise<cloudExtension.Result<cloudExtension.AppSchema>> { 866 console.info(`get app schema, bundleName:${bundleName}`); 867 // ... 868 return { 869 code: cloudExtension.ErrorCode.SUCCESS, 870 description: "get app schema success", 871 value: { 872 bundleName: "test_bundleName", 873 version: 1, 874 databases: [] 875 } 876 }; 877 } 878} 879``` 880 881### subscribe 882 883subscribe(subInfo: Record<string, Array<Database>>, expirationTime: number): Promise<Result<SubscribeInfo>> 884 885Subscribes to data. This API uses a promise to return the result. 886 887**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 888 889**Parameters** 890 891| Name | Type | Mandatory| Description | 892| -------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------ | 893| subInfo | Record<string, Array<[Database](#database)>> | Yes | Data to be subscribed to, in KV pairs of the application bundle name and database information.| 894| expirationTime | number | Yes | Subscription expiration time. | 895 896**Return value** 897 898| Type | Description | 899| ------------------------------------------------------------ | ----------------------------------------------------------- | 900| Promise<[Result](#resultt)<[SubscribeInfo](#subscribeinfo)>> | Promise used to return the result, including the subscription expiration time and subscription information.| 901 902**Example** 903 904```ts 905let test_time: number = 10; 906export default class MyCloudService implements cloudExtension.CloudService { 907 constructor() { 908 } 909 // ... 910 async subscribe(subInfo: Record<string, Array<cloudExtension.Database>>, expirationTime: number): Promise<cloudExtension.Result<cloudExtension.SubscribeInfo>> { 911 console.info 912 (`subscribe expirationTime: ${expirationTime}`); 913 // ... 914 return { 915 code: cloudExtension.ErrorCode.SUCCESS, 916 description: "subscribe success", 917 value: { 918 expirationTime: test_time, 919 subscribe: {} 920 } 921 }; 922 } 923} 924``` 925 926 927 928### unsubscribe 929 930unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> 931 932Unsubscribes from data changes in the cloud. This API uses a promise to return the result. 933 934**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 935 936**Parameters** 937 938| Name | Type | Mandatory| Description | 939| --------------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 940| unsubscribeInfo | Record<string, Array<string>> | Yes | Data to be unsubscribed from, in an array of KV pairs consisting of the application bundle name and database information.| 941 942**Return value** 943 944| Type | Description | 945| --------------------- | --------------------------------------- | 946| Promise<number> | Promise used to return the result.| 947 948```ts 949export default class MyCloudService implements cloudExtension.CloudService { 950 constructor() { 951 } 952 // ... 953 async unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> { 954 console.info(`unsubscribe`); 955 // ... 956 return cloudExtension.ErrorCode.SUCCESS; 957 } 958} 959``` 960 961### connectDB 962 963 connectDB(bundleName: string, database: Database): Promise<rpc.RemoteObject> 964 965Connects to a cloud database by obtaining a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [CloudDB](#clouddb), which is created by using [createCloudDBStub](#cloudextensioncreateclouddbstub). This API uses a promise to return the result. 966 967**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 968 969**Parameters** 970 971| Name | Type | Mandatory| Description | 972| ---------- | ----------------------- | ---- | ------------------ | 973| bundleName | string | Yes | Bundle name of the application. | 974| database | [Database](#database) | Yes | Database to connect.| 975 976**Return value** 977 978| Type | Description | 979| ------------------------------------------------------------ | ------------------------------------------------------------ | 980| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [CloudDB](#clouddb).| 981 982```ts 983import { rpc } from '@kit.IPCKit'; 984 985export default class MyCloudDB implements cloudExtension.CloudDB { 986 // ... 987} 988 989export default class MyCloudService implements cloudExtension.CloudService { 990 constructor() {} 991 // ... 992 async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 993 console.info(`connect DB, bundleName: ${bundleName}`); 994 return cloudExtension.createCloudDBStub(new MyCloudDB()); 995 } 996} 997``` 998 999### connectAssetLoader 1000 1001connectAssetLoader(bundleName: string, database: Database): Promise<rpc.RemoteObject> 1002 1003Connects to an asset loader by obtaining a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [AssetLoader](#assetloader), which is created by using [createAssetLoaderStub](#cloudextensioncreateassetloaderstub). This API uses a promise to return the result. 1004 1005You can use this API to connect to the asset loader. 1006 1007**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1008 1009**Parameters** 1010 1011| Name | Type | Mandatory| Description | 1012| ---------- | ----------------------- | ---- | ------------------ | 1013| bundleName | string | Yes | Bundle name of the application. | 1014| database | [Database](#database) | Yes | Database to connect.| 1015 1016**Return value** 1017 1018| Type | Description | 1019| ------------------------------------------------------------ | ------------------------------------------------------------ | 1020| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [AssetLoader](#assetloader).| 1021 1022```ts 1023import { rpc } from '@kit.IPCKit'; 1024 1025export default class MyAssetLoader implements cloudExtension.AssetLoader { 1026 // ... 1027} 1028 1029export default class MyCloudService implements cloudExtension.CloudService { 1030 constructor() {} 1031 async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1032 // ... 1033 console.info(`connect asset loader, bundle: ${bundleName}`); 1034 return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 1035 } 1036} 1037``` 1038 1039### connectShareCenter 1040 1041connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> 1042 1043Connects to ShareCenter by obtaining a [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [ShareCenter](#sharecenter), which is created by using [createShareServiceStub](#cloudextensioncreateshareservicestub). This API uses a promise to return the result. 1044 1045**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1046 1047**Parameters** 1048 1049| Name | Type | Mandatory| Description | 1050| ------- | ----------------------- | ---- | ----------------------------------------------- | 1051| userId | number | Yes | User ID. | 1052| bundleName | string | Yes | Bundle name of the application. | 1053 1054**Return value** 1055 1056| Type | Description | 1057| ------------------------------------------------------------ | ------------------------------------------------------------ | 1058| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise used to return the [RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject) instance of [ShareCenter](#sharecenter).| 1059 1060**Example** 1061 1062```ts 1063import { rpc } from '@kit.IPCKit'; 1064 1065export default class MyShareCenter implements cloudExtension.ShareCenter { 1066 constructor() {} 1067 // ... 1068} 1069 1070export default class MyCloudService implements cloudExtension.CloudService { 1071 constructor() {} 1072 async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 1073 console.info(`connect share center, bundle: ${bundleName}`); 1074 return cloudExtension.createShareServiceStub(new MyShareCenter()); 1075 } 1076} 1077``` 1078 1079## AssetLoader 1080 1081Provides APIs for uploading and downloading assets. 1082 1083### download 1084 1085download(table: string, gid: string, prefix: string, assets: Array<CloudAsset>): Promise<Array<Result<CloudAsset>>> 1086 1087Downloads assets. 1088 1089**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1090 1091**Parameters** 1092 1093| Name| Type | Mandatory| Description | 1094| ------ | -------------------------------------- | ---- | -------------------------- | 1095| table | string | Yes | Table name. | 1096| gid | string | Yes | Unique identifier generated for the data added to the cloud.| 1097| prefix | string | Yes | Asset prefix information. | 1098| assets | Array<[CloudAsset](#cloudasset)> | Yes | Assets to download. | 1099 1100**Return value** 1101 1102| Type | Description | 1103| ------------------------------------------------------------ | ------------------------------------------------------- | 1104| Promise<Array<[Result](#resultt)<[CloudAsset](#cloudasset)>>> | Promise used to return the asset download result, including the asset IDs and asset hash values.| 1105 1106**Example** 1107 1108```ts 1109export default class MyAssetLoader implements cloudExtension.AssetLoader { 1110 async download(table: string, gid: string, prefix: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1111 console.info(`download asset loader, table: ${table}, gid: ${gid}, prefix: ${prefix}`); 1112 let downloadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1113 // ... 1114 return downloadRes; 1115 } 1116} 1117``` 1118 1119### upload 1120 1121upload(table: string, gid: string, assets: Array<CloudAsset>): Promise<Array<Result<CloudAsset>>> 1122 1123Uploads assets. 1124 1125**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1126 1127**Parameters** 1128 1129| Name| Type | Mandatory| Description | 1130| ------ | ---------------------------------------- | ---- | ------------------------------------ | 1131| table | string | Yes | Table name. | 1132| gid | string | Yes | Unique identifier generated for the data added to the cloud.| 1133| assets | Array<[CloudAsset](#cloudasset)> | Yes | Assets to upload. | 1134 1135**Return value** 1136 1137| Type | Description | 1138| ------------------------------------------------------------ | --------------------------------------------------------- | 1139| Promise<Array<[Result](#resultt)<[CloudAsset](#cloudasset)>>> | Promise used to return the asset upload result, including the asset IDs and asset hash values.| 1140 1141**Example** 1142 1143```ts 1144export default class MyAssetLoader implements cloudExtension.AssetLoader { 1145 async upload(table: string, gid: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1146 console.info(`upload asset loader, table: ${table}, gid: ${gid}`); 1147 let uploadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1148 // ... 1149 return uploadRes; 1150 } 1151 // ... 1152} 1153``` 1154 1155## ShareCenter 1156 1157Provides APIs for interacting with the **sharedCenter** service. You need to inherit this class and implement APIs of this class. The system calls these APIs to initiate, cancel, or exit a device-cloud share. 1158 1159### share 1160 1161share(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1162 1163Shares data. This API uses a promise to return the result. The application that initiates the share, shared resource ID, participants of the share need to be specified. 1164 1165**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1166 1167**Parameters** 1168 1169| Name | Type | Mandatory| Description | 1170| ------- | ----------------------- | ---- | ----------------------------------------------- | 1171| userId | number | Yes | User ID. | 1172| bundleName | string | Yes | Bundle name of the application. | 1173| sharingResource | string | Yes | Shared resource ID. | 1174| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | Yes | Participants of the share. | 1175 1176**Return value** 1177 1178| Type | Description | 1179| ------------------- | ------------------------- | 1180| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise used to return the result.| 1181 1182**Example** 1183 1184```ts 1185import { cloudData } from '@kit.ArkData'; 1186 1187type Participant = cloudData.sharing.Participant; 1188 1189export default class MyShareCenter implements cloudExtension.ShareCenter { 1190 constructor() {} 1191 async share(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1192 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1193 console.info(`share, bundle: ${bundleName}`); 1194 // Connect to ShareCenter and obtain the return value. 1195 // ... 1196 // Return the result obtained from ShareCenter. 1197 let result: Array<cloudExtension.Result<Participant>> = []; 1198 participants.forEach((item => { 1199 result.push({ 1200 code: cloudData.sharing.SharingCode.SUCCESS, 1201 description: 'share succeeded' 1202 }) 1203 })) 1204 return { 1205 code: cloudData.sharing.SharingCode.SUCCESS, 1206 description: 'share succeeded', 1207 value: result 1208 } 1209 } 1210 // ... 1211} 1212``` 1213 1214### unshare 1215 1216unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1217 1218Unshares data. This API uses a promise to return the result. The application, shared resource ID, and participants for the data to unshare need to be specified. 1219 1220**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1221 1222**Parameters** 1223 1224| Name | Type | Mandatory| Description | 1225| ------- | ----------------------- | ---- | ----------------------------------------------- | 1226| userId | number | Yes | User ID. | 1227| bundleName | string | Yes | Bundle name of the application. | 1228| sharingResource | string | Yes | Shared resource ID. | 1229| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | Yes | Participants of the share. | 1230 1231**Return value** 1232 1233| Type | Description | 1234| ------------------- | ------------------------- | 1235| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise used to return the result.| 1236 1237**Example** 1238 1239```ts 1240import { cloudData } from '@kit.ArkData'; 1241 1242type Participant = cloudData.sharing.Participant; 1243 1244export default class MyShareCenter implements cloudExtension.ShareCenter { 1245 constructor() {} 1246 async unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1247 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1248 console.info(`unshare, bundle: ${bundleName}`); 1249 // Connect to ShareCenter and obtain the return value of the unshare operation. 1250 // ... 1251 // Return the result obtained from ShareCenter. 1252 let result: Array<cloudExtension.Result<Participant>> = []; 1253 participants.forEach((item => { 1254 result.push({ 1255 code: cloudData.sharing.SharingCode.SUCCESS, 1256 description: 'unshare succeeded' 1257 }) 1258 })) 1259 return { 1260 code: cloudData.sharing.SharingCode.SUCCESS, 1261 description: 'unshare succeeded', 1262 value: result 1263 } 1264 } 1265 // ... 1266} 1267``` 1268 1269### exit 1270 1271exit(userId: number, bundleName: string, sharingResource: string): Promise<Result<void>> 1272 1273Exits a device-cloud share. This API uses a promise to return the result. The application and shared resource ID need to be specified. 1274 1275**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1276 1277**Parameters** 1278 1279| Name | Type | Mandatory| Description | 1280| ------- | ----------------------- | ---- | ----------------------------------------------- | 1281| userId | number | Yes | User ID. | 1282| bundleName | string | Yes | Bundle name of the application. | 1283| sharingResource | string | Yes | Shared resource ID. | 1284 1285**Return value** 1286 1287| Type | Description | 1288| ------------------- | ------------------------- | 1289| Promise<[Result](#resultt)<void>> | Promise used to return the result.| 1290 1291**Example** 1292 1293```ts 1294import { cloudData } from '@kit.ArkData'; 1295 1296export default class MyShareCenter implements cloudExtension.ShareCenter { 1297 constructor() {} 1298 async exit(userId: number, bundleName: string, sharingResource: string): 1299 Promise<cloudExtension.Result<void>> { 1300 console.info(`exit share, bundle: ${bundleName}`); 1301 // Connect to ShareCenter and obtain the return value of the exit operation. 1302 // ... 1303 // Return the result obtained from ShareCenter. 1304 return { 1305 code: cloudData.sharing.SharingCode.SUCCESS, 1306 description: 'exit share succeeded' 1307 } 1308 } 1309 // ... 1310} 1311``` 1312 1313### changePrivilege 1314 1315changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1316 1317Changes the privilege (operation permissions) on the shared data. This API uses a promise to return the result. The application, shared resource ID, and the participants with new privilege need to be specified. 1318 1319**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1320 1321**Parameters** 1322 1323| Name | Type | Mandatory| Description | 1324| ------- | ----------------------- | ---- | ----------------------------------------------- | 1325| userId | number | Yes | User ID. | 1326| bundleName | string | Yes | Bundle name of the application. | 1327| sharingResource | string | Yes | Shared resource ID. | 1328| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | Yes | Participants of the share. | 1329 1330**Return value** 1331 1332| Type | Description | 1333| ------------------- | ------------------------- | 1334| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise used to return the result.| 1335 1336**Example** 1337 1338```ts 1339import { cloudData } from '@kit.ArkData'; 1340 1341type Participant = cloudData.sharing.Participant; 1342 1343export default class MyShareCenter implements cloudExtension.ShareCenter { 1344 constructor() {} 1345 async changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1346 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1347 console.info(`change privilege, bundle: ${bundleName}`); 1348 // Connect to ShareCenter and obtain the return value of the privilege change operation. 1349 // ... 1350 // Return the result obtained from ShareCenter. 1351 let result: Array<cloudExtension.Result<Participant>> = []; 1352 participants.forEach((item => { 1353 result.push({ 1354 code: cloudData.sharing.SharingCode.SUCCESS, 1355 description: 'change privilege succeeded' 1356 }) 1357 })) 1358 return { 1359 code: cloudData.sharing.SharingCode.SUCCESS, 1360 description: 'change privilege succeeded', 1361 value: result 1362 } 1363 } 1364 // ... 1365} 1366``` 1367 1368### queryParticipants 1369 1370queryParticipants(userId: number, bundleName: string, sharingResource: string): Promise<Result<Array<cloudData.sharing.Participant>>> 1371 1372Queries the participants of a share. This API uses a promise to return the result. The application and shared resource ID need to be specified. 1373 1374**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1375 1376**Parameters** 1377 1378| Name | Type | Mandatory| Description | 1379| ------- | ----------------------- | ---- | ----------------------------------------------- | 1380| userId | number | Yes | User ID. | 1381| bundleName | string | Yes | Bundle name of the application. | 1382| sharingResource | string | Yes | Shared resource ID. | 1383 1384**Return value** 1385 1386| Type | Description | 1387| ------------------------------------------------------------ | --------------------------------------- | 1388| Promise<[Result](#resultt)<Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>> | Promise used to return the participants obtained.| 1389 1390**Example** 1391 1392```ts 1393import { cloudData } from '@kit.ArkData'; 1394 1395type Participant = cloudData.sharing.Participant; 1396 1397export default class MyShareCenter implements cloudExtension.ShareCenter { 1398 constructor() {} 1399 async queryParticipants(userId: number, bundleName: string, sharingResource: string): 1400 Promise<cloudExtension.Result<Array<Participant>>> { 1401 console.info(`query participants, bundle: ${bundleName}`); 1402 // Connect to ShareCenter and obtain the return value of the query operation. 1403 // ... 1404 // Return the result obtained from ShareCenter. 1405 let participants = new Array<cloudData.sharing.Participant>(); 1406 participants.push({ 1407 identity: '000000000', 1408 role: cloudData.sharing.Role.ROLE_INVITEE, 1409 state: cloudData.sharing.State.STATE_ACCEPTED, 1410 privilege: { 1411 writable: false, 1412 readable: true, 1413 creatable: false, 1414 deletable: false, 1415 shareable: false 1416 }, 1417 attachInfo: '' 1418 }) 1419 participants.push({ 1420 identity: '111111111', 1421 role: cloudData.sharing.Role.ROLE_INVITEE, 1422 state: cloudData.sharing.State.STATE_ACCEPTED, 1423 privilege: { 1424 writable: false, 1425 readable: true, 1426 creatable: false, 1427 deletable: false, 1428 shareable: false 1429 }, 1430 attachInfo: '' 1431 }) 1432 return { 1433 code: cloudData.sharing.SharingCode.SUCCESS, 1434 description: 'query participants succeeded', 1435 value: participants 1436 } 1437 } 1438 // ... 1439} 1440``` 1441 1442### queryParticipantsByInvitation 1443 1444queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): Promise<Result<Array<cloudData.sharing.Participant>>> 1445 1446Queries the participants of a share based on the invitation code. This API uses a promise to return the result. The application and the invitation code of the shared data need to be specified. 1447 1448**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1449 1450**Parameters** 1451 1452| Name | Type | Mandatory| Description | 1453| ------- | ----------------------- | ---- | ----------------------------------------------- | 1454| userId | number | Yes | User ID. | 1455| bundleName | string | Yes | Bundle name of the application. | 1456| invitationCode | string | Yes | Invitation code for the share. | 1457 1458**Return value** 1459 1460| Type | Description | 1461| ------------------- | ------------------------- | 1462| Promise<[Result](#resultt)<Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>> | Promise used to return the participants obtained.| 1463 1464**Example** 1465 1466```ts 1467import { cloudData } from '@kit.ArkData'; 1468 1469type Participant = cloudData.sharing.Participant; 1470 1471export default class MyShareCenter implements cloudExtension.ShareCenter { 1472 constructor() {} 1473 async queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): 1474 Promise<cloudExtension.Result<Array<Participant>>> { 1475 console.info(`query participants by invitation, bundle: ${bundleName}`); 1476 // Connect to ShareCenter and obtain the return value of the query operation. 1477 // ... 1478 // Return the result obtained from ShareCenter. 1479 let participants = new Array<cloudData.sharing.Participant>(); 1480 participants.push({ 1481 identity: '000000000', 1482 role: cloudData.sharing.Role.ROLE_INVITEE, 1483 state: cloudData.sharing.State.STATE_ACCEPTED, 1484 privilege: { 1485 writable: false, 1486 readable: true, 1487 creatable: false, 1488 deletable: false, 1489 shareable: false 1490 }, 1491 attachInfo: '' 1492 }) 1493 participants.push({ 1494 identity: '111111111', 1495 role: cloudData.sharing.Role.ROLE_INVITEE, 1496 state: cloudData.sharing.State.STATE_ACCEPTED, 1497 privilege: { 1498 writable: false, 1499 readable: true, 1500 creatable: false, 1501 deletable: false, 1502 shareable: false 1503 }, 1504 attachInfo: '' 1505 }) 1506 return { 1507 code: cloudData.sharing.SharingCode.SUCCESS, 1508 description: 'query participants by invitation succeeded', 1509 value: participants 1510 } 1511 } 1512 // ... 1513} 1514``` 1515 1516### confirmInvitation 1517 1518confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): Promise<Result<string>> 1519 1520Confirms the invitation for a share. This API uses a promise to return the result. The application, invitation code for the share, and the confirmation state need to be specified. 1521 1522**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1523 1524**Parameters** 1525 1526| Name | Type | Mandatory| Description | 1527| ------- | ----------------------- | ---- | ----------------------------------------------- | 1528| userId | number | Yes | User ID. | 1529| bundleName | string | Yes | Bundle name of the application. | 1530| invitationCode | string | Yes | Invitation code for the share. | 1531| state | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11) | Yes | Confirmation state of the invitation. | 1532 1533**Return value** 1534 1535| Type | Description | 1536| ------------------- | ------------------------- | 1537| Promise<[Result](#resultt)<string>> | Promise used to return the shared resource ID.| 1538 1539**Example** 1540 1541```ts 1542import { cloudData } from '@kit.ArkData'; 1543 1544export default class MyShareCenter implements cloudExtension.ShareCenter { 1545 constructor() {} 1546 async confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): 1547 Promise<cloudExtension.Result<string>> { 1548 console.info(`confirm invitation, bundle: ${bundleName}`); 1549 // Connect to ShareCenter and obtain the return value of the invitation confirmation operation. 1550 // ... 1551 // Return the result obtained from ShareCenter. 1552 return { 1553 code: cloudData.sharing.SharingCode.SUCCESS, 1554 description: 'confirm invitation succeeded', 1555 value: 'sharing_resource_test' 1556 } 1557 } 1558 // ... 1559} 1560``` 1561 1562### changeConfirmation 1563 1564changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): Promise<Result<void>> 1565 1566Changes the confirmation state of a share invitation. This API uses a promise to return the result. The application, shared resource ID, and the new conformation state need to be specified. This API uses a promise to return the result. 1567 1568**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server 1569 1570**Parameters** 1571 1572| Name | Type | Mandatory| Description | 1573| ------- | ----------------------- | ---- | ----------------------------------------------- | 1574| userId | number | Yes | User ID. | 1575| bundleName | string | Yes | Bundle name of the application. | 1576| sharingResource | string | Yes | Shared resource ID. | 1577| state | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11) | Yes | New confirmation state. | 1578 1579**Return value** 1580 1581| Type | Description | 1582| ------------------- | ------------------------- | 1583| Promise<[Result](#resultt)<void>> | Promise used to return the result.| 1584 1585**Example** 1586 1587```ts 1588import { cloudData } from '@kit.ArkData'; 1589 1590export default class MyShareCenter implements cloudExtension.ShareCenter { 1591 constructor() {} 1592 async changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): 1593 Promise<cloudExtension.Result<void>> { 1594 console.info(`change confirm, bundle: ${bundleName}`); 1595 // Connect to ShareCenter and obtain the return value of the state change operation. 1596 // ... 1597 // Return the result obtained from ShareCenter. 1598 return { 1599 code: cloudData.sharing.SharingCode.SUCCESS, 1600 description: 'change confirm succeeded' 1601 } 1602 } 1603 // ... 1604} 1605``` 1606## Complete Sample Code 1607 1608The classes in the preceding examples are implemented using **implements**, and the sample code cannot be executed independently until all the methods in the parent classes are implemented. The following provides complete sample code for your reference. 1609 1610```ts 1611import { Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 1612import { rpc } from '@kit.IPCKit'; 1613import { cloudData, cloudExtension } from '@kit.ArkData'; 1614 1615type Participant = cloudData.sharing.Participant; 1616let test_lockId: number = 1; 1617let test_time: number = 10; 1618let test_space: number = 100; 1619let test_userId: number = 1; 1620 1621class MyCloudDB implements cloudExtension.CloudDB { 1622 async generateId(count: number): Promise<cloudExtension.Result<Array<string>>> { 1623 console.info(`generate id, count: ${count}`); 1624 let result = new Array<string>(); 1625 // ... 1626 // Return the ID generated. 1627 return { 1628 code: cloudExtension.ErrorCode.SUCCESS, 1629 description: 'generateId succeeded', 1630 value: result 1631 }; 1632 } 1633 1634 async update(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1635 console.info(`update, table: ${table}`); 1636 let updateRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1637 // ... 1638 // Return the data update result. 1639 return updateRes; 1640 } 1641 1642 async insert(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1643 console.info(`insert, table: ${table}`); 1644 let insertRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1645 // ... 1646 // Return the operation result. 1647 return insertRes; 1648 } 1649 1650 async delete(table: string, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1651 console.info(`delete, table: ${table}`); 1652 let deleteRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1653 // ... 1654 // Return the operation result. 1655 return deleteRes; 1656 } 1657 1658 async query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<cloudExtension.Result<cloudExtension.CloudData>> { 1659 console.info(`query, table: ${table}`); 1660 // ... 1661 // Return the operation result. 1662 return { 1663 code: cloudExtension.ErrorCode.SUCCESS, 1664 description: 'query succeeded', 1665 value: { 1666 nextCursor: "test_nextCursor", 1667 hasMore: true, 1668 values: [] 1669 } 1670 }; 1671 } 1672 1673 async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 1674 console.info(`DB lock`); 1675 // ... 1676 // Return the operation result. 1677 return { 1678 code: cloudExtension.ErrorCode.SUCCESS, 1679 description: 'lock succeeded', 1680 value: { 1681 interval: test_time, 1682 lockId: test_lockId 1683 } 1684 }; 1685 } 1686 1687 async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 1688 console.info(`heartbeat lock`); 1689 // ... 1690 // Return the operation result. 1691 return { 1692 code: cloudExtension.ErrorCode.SUCCESS, 1693 description: 'heartbeat succeeded', 1694 value: { 1695 interval: test_time, 1696 lockId: test_lockId 1697 } 1698 }; 1699 } 1700 1701 async unlock(lockId: number): Promise<cloudExtension.Result<boolean>> { 1702 console.info(`unlock`); 1703 // ... 1704 // Return the operation result. 1705 return { 1706 code: cloudExtension.ErrorCode.SUCCESS, 1707 description: 'unlock succeeded', 1708 value: false 1709 }; 1710 } 1711} 1712 1713class MyAssetLoader implements cloudExtension.AssetLoader { 1714 async download(table: string, gid: string, prefix: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1715 console.info(`download asset loader, table: ${table}, gid: ${gid}, prefix: ${prefix}`); 1716 let downloadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1717 // ... 1718 return downloadRes; 1719 } 1720 1721 async upload(table: string, gid: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1722 console.info(`upload asset loader, table: ${table}, gid: ${gid}`); 1723 let uploadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1724 // ... 1725 return uploadRes; 1726 } 1727} 1728 1729class MyShareCenter implements cloudExtension.ShareCenter { 1730 constructor() { 1731 } 1732 1733 async share(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1734 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1735 console.info(`share, bundle: ${bundleName}`); 1736 // Connect to ShareCenter and obtain the return value. 1737 // ... 1738 // Return the result obtained from ShareCenter. 1739 let result: Array<cloudExtension.Result<Participant>> = []; 1740 participants.forEach((item => { 1741 result.push({ 1742 code: cloudData.sharing.SharingCode.SUCCESS, 1743 description: 'share succeeded' 1744 }) 1745 })) 1746 return { 1747 code: cloudData.sharing.SharingCode.SUCCESS, 1748 description: 'share succeeded', 1749 value: result 1750 } 1751 } 1752 1753 async unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1754 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1755 console.info(`unshare, bundle: ${bundleName}`); 1756 // Connect to ShareCenter and obtain the return value of the unshare operation. 1757 // ... 1758 // Return the result obtained from ShareCenter. 1759 let result: Array<cloudExtension.Result<Participant>> = []; 1760 participants.forEach((item => { 1761 result.push({ 1762 code: cloudData.sharing.SharingCode.SUCCESS, 1763 description: 'unshare succeeded' 1764 }) 1765 })) 1766 return { 1767 code: cloudData.sharing.SharingCode.SUCCESS, 1768 description: 'unshare succeeded', 1769 value: result 1770 } 1771 } 1772 1773 async exit(userId: number, bundleName: string, sharingResource: string): 1774 Promise<cloudExtension.Result<void>> { 1775 console.info(`exit share, bundle: ${bundleName}`); 1776 // Connect to ShareCenter and obtain the return value of the exit operation. 1777 // ... 1778 // Return the result obtained from ShareCenter. 1779 return { 1780 code: cloudData.sharing.SharingCode.SUCCESS, 1781 description: 'exit share succeeded' 1782 } 1783 } 1784 1785 async changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1786 Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1787 console.info(`change privilege, bundle: ${bundleName}`); 1788 // Connect to ShareCenter and obtain the return value of the privilege change operation. 1789 // ... 1790 // Return the result obtained from ShareCenter. 1791 let result: Array<cloudExtension.Result<Participant>> = []; 1792 participants.forEach((item => { 1793 result.push({ 1794 code: cloudData.sharing.SharingCode.SUCCESS, 1795 description: 'change privilege succeeded' 1796 }) 1797 })) 1798 return { 1799 code: cloudData.sharing.SharingCode.SUCCESS, 1800 description: 'change privilege succeeded', 1801 value: result 1802 } 1803 } 1804 1805 async queryParticipants(userId: number, bundleName: string, sharingResource: string): 1806 Promise<cloudExtension.Result<Array<Participant>>> { 1807 console.info(`query participants, bundle: ${bundleName}`); 1808 // Connect to ShareCenter and obtain the return value of the query operation. 1809 // ... 1810 // Return the result obtained from ShareCenter. 1811 let participants = new Array<cloudData.sharing.Participant>(); 1812 participants.push({ 1813 identity: '000000000', 1814 role: cloudData.sharing.Role.ROLE_INVITEE, 1815 state: cloudData.sharing.State.STATE_ACCEPTED, 1816 privilege: { 1817 writable: false, 1818 readable: true, 1819 creatable: false, 1820 deletable: false, 1821 shareable: false 1822 }, 1823 attachInfo: '' 1824 }) 1825 participants.push({ 1826 identity: '111111111', 1827 role: cloudData.sharing.Role.ROLE_INVITEE, 1828 state: cloudData.sharing.State.STATE_ACCEPTED, 1829 privilege: { 1830 writable: false, 1831 readable: true, 1832 creatable: false, 1833 deletable: false, 1834 shareable: false 1835 }, 1836 attachInfo: '' 1837 }) 1838 return { 1839 code: cloudData.sharing.SharingCode.SUCCESS, 1840 description: 'query participants succeeded', 1841 value: participants 1842 } 1843 } 1844 1845 async queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): 1846 Promise<cloudExtension.Result<Array<Participant>>> { 1847 console.info(`query participants by invitation, bundle: ${bundleName}`); 1848 // Connect to ShareCenter and obtain the return value of the query operation. 1849 // ... 1850 // Return the result obtained from ShareCenter. 1851 let participants = new Array<cloudData.sharing.Participant>(); 1852 participants.push({ 1853 identity: '000000000', 1854 role: cloudData.sharing.Role.ROLE_INVITEE, 1855 state: cloudData.sharing.State.STATE_ACCEPTED, 1856 privilege: { 1857 writable: false, 1858 readable: true, 1859 creatable: false, 1860 deletable: false, 1861 shareable: false 1862 }, 1863 attachInfo: '' 1864 }) 1865 participants.push({ 1866 identity: '111111111', 1867 role: cloudData.sharing.Role.ROLE_INVITEE, 1868 state: cloudData.sharing.State.STATE_ACCEPTED, 1869 privilege: { 1870 writable: false, 1871 readable: true, 1872 creatable: false, 1873 deletable: false, 1874 shareable: false 1875 }, 1876 attachInfo: '' 1877 }) 1878 return { 1879 code: cloudData.sharing.SharingCode.SUCCESS, 1880 description: 'query participants by invitation succeeded', 1881 value: participants 1882 } 1883 } 1884 1885 async confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): 1886 Promise<cloudExtension.Result<string>> { 1887 console.info(`confirm invitation, bundle: ${bundleName}`); 1888 // Connect to ShareCenter and obtain the return value of the invitation confirmation operation. 1889 // ... 1890 // Return the result obtained from ShareCenter. 1891 return { 1892 code: cloudData.sharing.SharingCode.SUCCESS, 1893 description: 'confirm invitation succeeded', 1894 value: 'sharing_resource_test' 1895 } 1896 } 1897 1898 async changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): 1899 Promise<cloudExtension.Result<void>> { 1900 console.info(`change confirm, bundle: ${bundleName}`); 1901 // Connect to ShareCenter and obtain the return value of the state change operation. 1902 // ... 1903 // Return the result obtained from ShareCenter. 1904 return { 1905 code: cloudData.sharing.SharingCode.SUCCESS, 1906 description: 'change confirm succeeded' 1907 } 1908 } 1909} 1910 1911class MyCloudService implements cloudExtension.CloudService { 1912 constructor() { 1913 } 1914 1915 async getServiceInfo(): Promise<cloudExtension.ServiceInfo> { 1916 console.info(`get service info`); 1917 // ... 1918 return { 1919 enableCloud: true, 1920 id: "test_id", 1921 totalSpace: test_space, 1922 remainingSpace: test_space, 1923 user: test_userId, 1924 }; 1925 } 1926 1927 async getAppBriefInfo(): Promise<Record<string, cloudExtension.AppBriefInfo>> { 1928 console.info(`get app brief info`); 1929 // ... 1930 return { 1931 "test_bundle": 1932 { 1933 appId: "test_appID", 1934 bundleName: "test_bundlename", 1935 cloudSwitch: true, 1936 instanceId: 0, 1937 } 1938 }; 1939 } 1940 1941 async getAppSchema(bundleName: string): Promise<cloudExtension.Result<cloudExtension.AppSchema>> { 1942 console.info(`get app schema, bundleName:${bundleName}`); 1943 // ... 1944 return { 1945 code: cloudExtension.ErrorCode.SUCCESS, 1946 description: "get app schema success", 1947 value: { 1948 bundleName: "test_bundleName", 1949 version: 1, 1950 databases: [] 1951 } 1952 }; 1953 } 1954 1955 async subscribe(subInfo: Record<string, Array<cloudExtension.Database>>, expirationTime: number): Promise<cloudExtension.Result<cloudExtension.SubscribeInfo>> { 1956 console.info 1957 (`subscribe expirationTime: ${expirationTime}`); 1958 // ... 1959 return { 1960 code: cloudExtension.ErrorCode.SUCCESS, 1961 description: "subscribe success", 1962 value: { 1963 expirationTime: test_time, 1964 subscribe: {} 1965 } 1966 }; 1967 } 1968 1969 async unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> { 1970 console.info(`unsubscribe`); 1971 // ... 1972 return cloudExtension.ErrorCode.SUCCESS; 1973 } 1974 1975 async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1976 console.info(`connect DB, bundleName: ${bundleName}`); 1977 return cloudExtension.createCloudDBStub(new MyCloudDB()); 1978 } 1979 1980 async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1981 console.info(`connect asset loader, bundle: ${bundleName}`); 1982 return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 1983 } 1984 1985 async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 1986 console.info(`connect share center, bundle: ${bundleName}`); 1987 // ... 1988 return cloudExtension.createShareServiceStub(new MyShareCenter()); 1989 } 1990} 1991 1992export default class MyServiceExtension extends ServiceExtensionAbility { 1993 onCreate(want: Want) { 1994 console.info(`onCreate: ${want}`); 1995 } 1996 1997 onRequest(want: Want, startId: number) { 1998 console.info(`onRequest: ${want} ${startId}`); 1999 } 2000 2001 onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject> { 2002 console.info(`onConnect: ${want}`); 2003 return cloudExtension.createCloudServiceStub(new MyCloudService()); 2004 } 2005 2006 onDisconnect(want: Want) { 2007 console.info(`onDisconnect: ${want}`); 2008 } 2009 2010 onDestroy() { 2011 console.info('onDestroy'); 2012 } 2013} 2014``` 2015 2016