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