• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.cloudExtension (端云共享Extension)(系统接口)
2
3端云共享Extension,提供三方厂商适配共享云服务的能力。通过实现端云共享Extension提供的接口,对接端侧的数据共享到服务端,实现端云共享的发起、取消或退出,更改共享数据的操作权限、查询共享参与者、根据共享邀请码查询共享参与者、确认或更改共享邀请,并支持返回共享云服务的相关结果。
4
5其中,端云共享资源标识是指:对于应用发起共享的每一条数据记录,该条数据在进行端云同步时会生成唯一的共享资源标识(字符串类型的值),此标识则作为该条数据记录共享时的识别标识。
6
7端云共享参与者是指: 共享发起者根据好友列表选中的参与当前数据共享的所有人员。
8
9端云共享邀请码是指: 共享发起后,在共享的服务端会生成当前共享操作的邀请码,并将该邀请码附加到当前共享邀请中,通过push消息推送到被邀请者的设备端,被邀请者可以通过该邀请码进行邀请的确认。
10
11同步云是指: 端云同步的服务端,是同应用同帐号跨设备的同步。
12
13共享云是指: 端云共享的服务端,是同应用跨帐号跨设备的共享。
14
15> **说明:**
16>
17> - 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
18>
19> - 本模块接口为系统接口。
20
21## 导入模块
22
23```ts
24import cloudExtension from '@ohos.data.cloudExtension';
25```
26
27## Result<T>
28
29共享结果的返回值。
30
31**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
32
33| 名称          | 类型                          | 必填  | 说明           |
34| ----------- | --------------------------- | --- | ------------ |
35| code        | number                      | 是   | 错误码。       |
36| description | string                      | 否   | 错误码详细描述,默认为undefined。       |
37| value       | T                           | 否   | 返回结果的值,具体类型由参数T指定,默认为undefined。       |
38
39## CloudAsset
40
41云资产的信息。
42
43**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
44
45| 名称    | 类型   | 必填 | 说明                                 |
46| ------- | ------ | ---- | ------------------------------------ |
47| assetId | string | 是   | 资产ID。                             |
48| hash    | string | 是   | 资产的修改时间和大小转化成的哈希值。 |
49
50## CloudAssets
51
52表示[CloudAsset](#cloudasset)类型的数组。
53
54**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
55
56| 类型                             | 说明                                      |
57| -------------------------------- | ----------------------------------------- |
58| Array<[CloudAsset](#cloudasset)> | 表示[CloudAsset](#cloudasset)类型的数组。 |
59
60## ServiceInfo
61
62云服务信息。
63
64**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
65
66| 名称           | 类型    | 必填 | 说明                                                         |
67| -------------- | ------- | ---- | ------------------------------------------------------------ |
68| enableCloud    | boolean | 是   | 表示是否启用了云服务,为true时是启用云服务,为false时是未启用。 |
69| id             | string  | 是   | 使用哈希函数SHA256生成的云帐户ID。                           |
70| totalSpace     | number  | 是   | 服务器上帐户的总空间(KB)。                                 |
71| remainingSpace | number  | 是   | 服务器上帐户的可用空间(KB)。                               |
72| user           | number  | 是   | 设备的当前用户ID。                                           |
73
74## Flag
75
76描述数据库上执行操作的枚举。请使用枚举名而非枚举值。
77
78**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
79
80| 名称   | 值   | 说明       |
81| ------ | ---- | ---------- |
82| INSERT | 0    | 插入操作。 |
83| UPDATE | 1    | 更新操作。 |
84| DELETE | 2    | 删除操作。 |
85
86## ExtensionValue
87
88当前数据记录的扩展信息。
89
90**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
91
92| 名称       | 类型            | 必填 | 说明                                       |
93| ---------- | --------------- | ---- | ------------------------------------------ |
94| id         | string          | 是   | 执行插入操作时生成,只读数据不可手动更改。 |
95| createTime | number          | 是   | 创建行数据的时间。只读数据不可手动更改。   |
96| modifyTime | number          | 是   | 修改行数据的时间。只读数据不可手动更改。   |
97| operation  | [Flag](#flag) | 是   | 对行数据所作的操作。                         |
98
99## CloudType
100
101表示允许出现的云数据字段类型,接口参数具体类型根据其功能而定。
102
103**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
104
105| 类型                      | 说明                            |
106| ------------------------- | ------------------------------- |
107| null                      | 表示值的类型为空。              |
108| number                    | 表示值的类型为数字类型。         |
109| string                    | 表示值的类型为字符串类型。       |
110| boolean                   | 表示值的类型为布尔类型。         |
111| Uint8Array                | 表示值的类型为Uint8类型的数组。 |
112| [CloudAsset](#cloudasset) | 表示值的类型为云资产类型。      |
113| [CloudAssets](#cloudassets)            | 表示值的类型为云资产数组类型。   |
114
115## CloudInfo
116
117云信息。
118
119**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
120
121| 名称      | 类型                                                | 必填 | 说明           |
122| --------- | --------------------------------------------------- | ---- | -------------- |
123| cloudInfo | [ServiceInfo](#serviceinfo)                         | 是   | 云服务信息。   |
124| apps      | Record&lt;string, [AppBriefInfo](#appbriefinfo)&gt; | 是   | 简要应用信息。 |
125
126## CloudData
127
128云数据。
129
130**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
131
132| 名称       | 类型                                                       | 必填 | 说明                                                         |
133| ---------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
134| nextCursor | string                                                     | 是   | 查询游标。                                                   |
135| hasMore    | boolean                                                    | 是   | 服务器是否存在更多数据可供查询,true表示服务器上还有数据等待查询,false表示服务器上不存在可查询的数据。 |
136| values     | Array&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt; | 是   | 需要查询数据的数组,包括data value(数据值)和[ExtensionValue](#extensionvalue)(扩展值)。 |
137
138## AppBriefInfo
139
140简要应用信息。
141
142**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
143
144| 名称        | 类型    | 必填 | 说明                               |
145| ----------- | ------- | ---- | ---------------------------------- |
146| appId       | string  | 是   | 应用程序ID。                      |
147| bundleName  | string  | 是   | 应用包名。                         |
148| cloudSwitch | boolean | 是   | 云开关,表示应用程序是否启用云,true表示启用云,false表示不启用云。 |
149| instanceId  | number  | 是   | 应用分身ID,0表示应用本身,分身ID依次递增。 |
150
151## FieldType
152
153描述数据库表中字段类型的枚举。请使用枚举名而非枚举值。
154
155**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
156
157| 名称                                               | 值   | 说明                                   |
158| -------------------------------------------------- | ---- | -------------------------------------- |
159| NULL                                               | 0    | 类型为空。                             |
160| NUMBER                                             | 1    | 数值类型。                             |
161| REAL                                               | 2    | 双精度浮点类型。                       |
162| TEXT                                               | 3    | 文本类型。                             |
163| BOOL                                               | 4    | 布尔类型。                             |
164| BLOB                                               | 5    | 二进制大对象类型,可以存储二进制文件。 |
165| [ASSET](js-apis-data-relationalStore.md#asset10)   | 6    | 资产类型。                             |
166| [ASSETS](js-apis-data-relationalStore.md#assets10) | 7    | 资产列表类型。                         |
167
168## Field
169
170数据库中的字段结构。
171
172**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
173
174| 名称     | 类型                      | 必填 | 说明                   |
175| -------- | ------------------------- | ---- | ---------------------- |
176| alias    | string                    | 是   | 该字段在服务器表中的别名。 |
177| colName  | string                    | 是   | 列名。                 |
178| type     | [FieldType](#fieldtype) | 是   | 字段类型。             |
179| primary  | boolean                   | 是   | 表示当前列是否是主键。true表示当前列为主键,false表示当前列不为主键。 |
180| nullable | boolean                   | 是   | 当前列是否为空值,true表示当前列为空,false表示当前列不为空。      |
181
182## Table
183
184表结构信息。
185
186**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
187
188| 名称   | 类型                         | 必填 | 说明                         |
189| ------ | ---------------------------- | ---- | ---------------------------- |
190| alias  | string                       | 是   | 该表在服务器数据库中的别名。 |
191| name   | string                       | 是   | 表名。                       |
192| fields | Array&lt;[Field](#field)&gt; | 是   | 数据库表中的字段结构信息。   |
193
194## Database
195
196数据库结构信息。
197
198**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
199
200| 名称   | 类型                         | 必填 | 说明                             |
201| ------ | ---------------------------- | ---- | -------------------------------- |
202| name   | string                       | 是   | 数据库名称。                     |
203| alias  | string                       | 是   | 该数据库在服务器中的别名。       |
204| tables | Array&lt;[Table](#table)&gt; | 是   | 数据库中的表,包含数据详细信息。 |
205
206## AppSchema
207
208应用数据库模式。
209
210**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
211
212| 名称       | 类型                                 | 必填 | 说明               |
213| ---------- | ------------------------------------ | ---- | ------------------ |
214| bundleName | string                               | 是   | 应用包名。         |
215| version    | number                               | 是   | 数据库模式的版本。 |
216| databases  | Array&lt;[Database](#database)&gt; | 是   | 应用的数据库信息。 |
217
218## SubscribeId
219
220订阅ID。
221
222**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
223
224| 名称          | 类型   | 必填 | 说明                   |
225| ------------- | ------ | ---- | ---------------------- |
226| databaseAlias | string | 是   | 服务器上数据库的名称。 |
227| id            | string | 是   | 订阅ID。              |
228
229## SubscribeInfo
230
231订阅信息。
232
233**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
234
235| 名称           | 类型                                                         | 必填 | 说明                 |
236| -------------- | ------------------------------------------------------------ | ---- | -------------------- |
237| expirationTime | number                                                       | 是   | 订阅过期时间(ms)。 |
238| subscribe      | Record&lt;string, Array&lt;[SubscribeId](#subscribeid)&gt;&gt; | 是   | 订阅信息。           |
239
240## LockInfo
241
242云数据库锁信息。
243
244**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
245
246| 名称     | 类型   | 必填 | 说明                            |
247| -------- | ------ | ---- | ------------------------------- |
248| interval | number | 是   | 云数据库锁的持续时间,单位为s。 |
249| lockId   | number | 是   | 锁ID。                          |
250
251## ErrorCode
252
253表示端云共享过程的状态。请使用枚举名而非枚举值。
254
255**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
256
257| 名称                  | 值   | 说明                                                         |
258| --------------------- | ---- | ------------------------------------------------------------ |
259| SUCCESS               | 0    | 表示端云同步过程成功。                                       |
260| UNKNOWN_ERROR         | 1    | 表示端云同步过程中遇到未知错误。                             |
261| NETWORK_ERROR         | 2    | 表示端云同步过程中遇到网络错误。                             |
262| CLOUD_DISABLED        | 3    | 表示云端不可用。                                             |
263| LOCKED_BY_OTHERS      | 4    | 表示有其他设备正在进行端云同步,本设备无法进行端云同步。请确保无其他设备占用端云资源后,在使用本设备进行端云同步任务。 |
264| RECORD_LIMIT_EXCEEDED | 5    | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 |
265| NO_SPACE_FOR_ASSET    | 6    | 表示云空间剩余空间小于待同步的资产大小。                     |
266
267## cloudExtension.createCloudServiceStub
268
269createCloudServiceStub(instance: CloudService): Promise&lt;rpc.RemoteObject&gt;
270
271根据[CloudService](#cloudservice)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[CloudService](#cloudservice)的实现接口,使用Promise异步回调。
272
273**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
274
275**参数:**
276
277| 参数名    | 类型                            | 必填 | 说明                                                         |
278| --------- | ------------------------------- | ---- | -------------------------------- |
279| instance  | [CloudService](#cloudservice)   | 是    | [CloudService](#cloudservice)类的实例。   |
280
281**返回值:**
282
283| 类型                | 说明                      |
284| -------------------             | ------------------------- |
285| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[CloudService](#cloudservice)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
286
287**示例:**
288
289```ts
290import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
291import Want from '@ohos.app.ability.Want';
292import rpc from '@ohos.rpc';
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
325根据[ShareCenter](#sharecenter)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[ShareCenter](#sharecenter)的实现接口,使用Promise异步回调。
326
327**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
328
329**参数:**
330
331| 参数名    | 类型                            | 必填 | 说明                                                         |
332| --------- | ------------------------------- | ---- | -------------------------------- |
333| instance  | [ShareCenter](#sharecenter)   | 是    | [ShareCenter](#sharecenter)类的实例。                   |
334
335**返回值:**
336
337| 类型                | 说明                      |
338| -------------------             | ------------------------- |
339| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
340
341**示例:**
342
343```ts
344import rpc from '@ohos.rpc';
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
364根据[CloudDB](#clouddb)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[CloudDB](#clouddb)的实现接口,使用Promise异步回调。
365
366**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
367
368**参数:**
369
370| 参数名   | 类型                  | 必填 | 说明                            |
371| -------- | --------------------- | ---- | ------------------------------- |
372| instance | [CloudDB](#clouddb) | 是   | [CloudDB](#clouddb)类的实例。 |
373
374**返回值:**
375
376| 类型                                                         | 说明                                                         |
377| ------------------------------------------------------------ | ------------------------------------------------------------ |
378| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[CloudDB](#clouddb)的[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
379
380```ts
381import rpc from '@ohos.rpc';
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
401根据[AssetLoader](#assetloader)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[AssetLoader](#assetloader)的实现接口,使用Promise异步回调。
402
403**参数:**
404
405| 参数名   | 类型                          | 必填 | 说明                                              |
406| -------- | ----------------------------- | ---- | ------------------------------------------------- |
407| instance | [AssetLoader](#assetloader) | 是   | 表示一个[AssetLoader](#assetloader)类型的实例。 |
408
409**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
410
411**返回值:**
412
413| 类型                                                         | 说明                                                         |
414| ------------------------------------------------------------ | ------------------------------------------------------------ |
415| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[AssetLoader](#assetloader)的[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
416
417**示例:**
418
419```ts
420import rpc from '@ohos.rpc';
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
440提供云数据库的操作接口的类。
441
442### generateId
443
444generateId(count: number): Promise&lt;Result&lt;Array&lt;string&gt;&gt;&gt;
445
446为插入的云数据生成ID。生成的ID具有唯一性。
447
448**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
449
450**参数:**
451
452| 参数名 | 类型   | 必填 | 说明                 |
453| ------ | ------ | ---- | -------------------- |
454| count  | number | 是   | 表示要生成ID的数量。 |
455
456**返回值:**
457
458| 类型                                                     | 说明                                                         |
459| -------------------------------------------------------- | ------------------------------------------------------------ |
460| Promise&lt;[Result](#resultt)&lt;Array&lt;string&gt;&gt; | Promise对象,以[Result](#resultt)结构将生成的ID以数组形式返回。 |
461
462**示例:**
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
484通过该接口更新云上的数据。
485
486**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
487
488**参数:**
489
490| 参数名     | 类型                                                         | 必填 | 说明                   |
491| ---------- | ------------------------------------------------------------ | ---- | ---------------------- |
492| table      | string                                                       | 是   | 表名。 |
493| values     | Array&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt; | 是   | 表示要插入的数据。     |
494| extensions | Array&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt; | 是   | 表示当前数据的扩展信息。 |
495
496**返回值:**
497
498| 类型                                                         | 说明                                    |
499| ------------------------------------------------------------ | --------------------------------------- |
500| Promise&lt;Array&lt;[Result](#resultt)&lt;Record&lt;string,  [CloudType](#cloudtype)&gt;&gt;&gt;&gt; | Promise对象,返回更新的数据和更新结果。 |
501
502**示例:**
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    // 返回更新数据的结果
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
522将数据插入云数据库表中。
523
524**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
525
526**参数:**
527
528| 参数名     | 类型                                                       | 必填 | 说明                     |
529| ---------- | ---------------------------------------------------------- | ---- | ------------------------ |
530| table      | string                                                     | 是   | 表名。                   |
531| values     | Array&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt; | 是   | 表示要插入的数据。       |
532| extensions | Array&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt; | 是   | 表示当前数据的扩展信息。 |
533
534**返回值:**
535
536| 类型                                                         | 说明                                  |
537| ------------------------------------------------------------ | ------------------------------------- |
538| Promise&lt;Array&lt;[Result](#resultt)&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt;&gt;&gt; | Promise对象,返回插入数据和插入结果。 |
539
540**示例:**
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    // 返回插入数据的结果
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
560删除云数据库表中的指定数据。
561
562**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
563
564**参数:**
565
566| 参数名     | 类型                                                      | 必填 | 说明                     |
567| ---------- | --------------------------------------------------------- | ---- | ------------------------ |
568| table      | string                                                    | 是   | 表名。                   |
569| extensions | Array&lt;Record&lt;string,[CloudType](#cloudtype)&gt;&gt; | 是   | 表示当前数据的扩展信息。 |
570
571**返回值:**
572
573| 类型                                                         | 说明                                      |
574| ------------------------------------------------------------ | ----------------------------------------- |
575| Promise&lt;Array&lt;[Result](#resultt)&lt;Record&lt;string, [CloudType](#cloudtype)&gt;&gt;&gt;&gt; | Promise对象,返回被删除的数据和删除结果。 |
576
577**示例:**
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    // 返回插入数据的结果
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
597在云数据库表中查询数据。
598
599**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
600
601**参数:**
602
603| 参数名      | 类型          | 必填 | 说明                     |
604| ----------- | ------------- | ---- | ------------------------ |
605| table       | string        | 是   | 表名。                   |
606| fields      | Array&lt;string&gt; | 是   | 表示字段名。          |
607| queryCount  | number        | 是   | 表示要查询的数据记录数。 |
608| queryCursor | string        | 是   | 表示要查询的游标。       |
609
610**返回值:**
611
612| 类型                                                         | 说明                                    |
613| ------------------------------------------------------------ | --------------------------------------- |
614| Promise&lt;[Result](#resultt)&lt;[CloudData](#clouddata)&gt;&gt; | Promise对象,返回被查询数据和查询结果。 |
615
616**示例:**
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    // 返回插入数据的结果
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
643为云数据库加锁。
644
645**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
646
647**返回值:**
648
649| 类型                                                         | 说明                                                |
650| ------------------------------------------------------------ | --------------------------------------------------- |
651| Promise&lt;[Result](#resultt)&lt;[LockInfo](#lockinfo)&gt;&gt; | Promise对象,返回加锁的信息,包含加锁时长和锁的ID。 |
652
653**示例:**
654
655```ts
656export default class MyCloudDB implements cloudExtension.CloudDB {
657  let test_time: number = 10;
658  let test_lockId: number = 1;
659  // ...
660  async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> {
661    console.info(`DB lock`);
662    // ...
663    // 返回插入数据的结果
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
681延长数据库的加锁时效。
682
683**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
684
685**参数:**
686
687| 参数名 | 类型   | 必填 | 说明                  |
688| ------ | ------ | ---- | --------------------- |
689| lockId | number | 是   | 表示需要延时的锁ID。 |
690
691**返回值:**
692
693| 类型                                                         | 说明                                              |
694| ------------------------------------------------------------ | ------------------------------------------------- |
695| Promise&lt;[Result](#resultt)&lt;[LockInfo](#lockinfo)&gt;&gt; | Promise对象,返回锁的信息,包含加锁时长和锁的ID。 |
696
697**示例:**
698
699```ts
700export default class MyCloudDB implements cloudExtension.CloudDB {
701  let test_lockId: number = 1;
702  let test_time: number = 10;
703  // ...
704  async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> {
705    console.info(`heartbeat lock`);
706    // ...
707    // 返回插入数据的结果
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
725为云数据库解锁。
726
727**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
728
729**参数:**
730
731| 参数名 | 类型   | 必填 | 说明          |
732| ------ | ------ | ---- | ------------- |
733| lockId | number | 是   | 表示锁的ID。 |
734
735**返回值:**
736
737| 类型                                             | 说明                                                         |
738| ------------------------------------------------ | ------------------------------------------------------------ |
739| Promise&lt;[Result](#resultt)&lt;boolean&gt;&gt; | Promise对象,返回解锁结果,true表示解锁成功,false表示解锁失败。 |
740
741**示例:**
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    // 返回插入数据的结果
750    return {
751      code: cloudExtension.ErrorCode.SUCCESS,
752      description: 'unlock succeeded',
753      value: false
754    };
755  }
756  // ...
757}
758```
759
760## CloudService
761
762提供对接同步云服务的类。开发者需要继承此类并实现类的接口,系统内部通过该类的接口连接并使用同步云服务。
763
764### getServiceInfo
765
766getServiceInfo(): Promise<ServiceInfo&gt;
767
768获取服务器上的信息。使用Promise异步回调。
769
770**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
771
772**返回值:**
773
774| 类型                                         | 说明                                |
775| -------------------------------------------- | ----------------------------------- |
776| Promise&lt;[ServiceInfo](#serviceinfo)&gt; | Promise对象,返回获取的服务器信息。 |
777
778**示例:**
779
780```ts
781import rpc from '@ohos.rpc';
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
807获取简要应用信息。使用Promise异步回调。
808
809**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
810
811**返回值:**
812
813| 类型                                                         | 说明                                                         |
814| ------------------------------------------------------------ | ------------------------------------------------------------ |
815| Promise&lt;Record&lt;string, [AppBriefInfo](#appbriefinfo)&gt;&gt;&gt; | Promise对象,返回与bundleName和 [AppBriefInfo](#appbriefinfo)相对应的键值对。 |
816
817**示例:**
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
843获取应用Schema(数据库模式)信息。使用Promise异步回调。
844
845**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
846
847**参数:**
848
849| 参数名     | 类型   | 必填 | 说明       |
850| ---------- | ------ | ---- | ---------- |
851| bundleName | string | 是   | 应用包名。 |
852
853**返回值:**
854
855| 类型                                                         | 说明                                  |
856| ------------------------------------------------------------ | ------------------------------------- |
857| Promise&lt;[Result](#resultt)&lt;[AppSchema](#appschema)&gt;&gt; | Promise对象,返回数据库的schema信息。 |
858
859**示例:**
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
886发起订阅,使用Promise异步回调。
887
888**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
889
890**参数:**
891
892| 参数名         | 类型                                                       | 必填 | 说明                                                   |
893| -------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------ |
894| subInfo        | Record&lt;string, Array&lt;[Database](#database)&gt;&gt; | 是   | 需要订阅的数据,由应用包名称和数据库信息组成的键值对。 |
895| expirationTime | number                                                     | 是   | 表示订阅到期时间。                                     |
896
897**返回值:**
898
899| 类型                                                         | 说明                                                        |
900| ------------------------------------------------------------ | ----------------------------------------------------------- |
901| Promise&lt;[Result](#resultt)&lt;[SubscribeInfo](#subscribeinfo)&gt;&gt; | Promise对象,返回订阅的结果,包含订阅的过期时间和订阅信息。 |
902
903**示例:**
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
933取消订阅云中的数据变更。使用Promise异步回调。
934
935**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
936
937**参数:**
938
939| 参数名          | 类型                                   | 必填 | 说明                                                         |
940| --------------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
941| unsubscribeInfo | Record&lt;string, Array<string&gt;&gt; | 是   | 需要取消订阅的数据信息,由应用包名和数据库结构组成的键值对。 |
942
943**返回值:**
944
945| 类型                  | 说明                                    |
946| --------------------- | --------------------------------------- |
947| Promise&lt;number&gt; | Promise对象,返回取消订阅结果的错误码。 |
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
966系统内部通过该接口获取[CloudDB](#clouddb)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createCloudDBStub](#cloudextensioncreateclouddbstub)接口进行创建,使用Promise异步回调。
967
968**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
969
970**参数:**
971
972| 参数名     | 类型                    | 必填 | 说明               |
973| ---------- | ----------------------- | ---- | ------------------ |
974| bundleName | string                  | 是   | 应用包名。         |
975| database   | [Database](#database) | 是   | 需要连接的数据库。 |
976
977**返回值:**
978
979| 类型                                                         | 说明                                                         |
980| ------------------------------------------------------------ | ------------------------------------------------------------ |
981| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[CloudDB](#clouddb)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
982
983```ts
984import rpc from '@ohos.rpc';
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
1004系统内部通过该接口获取[AssetLoader](#assetloader)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createAssetLoaderStub](#cloudextensioncreateassetloaderstub)接口进行创建,使用Promise异步回调。
1005
1006连接进行资产上传和下载的对象。
1007
1008**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1009
1010**参数:**
1011
1012| 参数名     | 类型                    | 必填 | 说明               |
1013| ---------- | ----------------------- | ---- | ------------------ |
1014| bundleName | string                  | 是   | 应用包名。         |
1015| database   | [Database](#database) | 是   | 需要连接的数据库。 |
1016
1017**返回值:**
1018
1019| 类型                                                         | 说明                                                         |
1020| ------------------------------------------------------------ | ------------------------------------------------------------ |
1021| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[AssetLoader](#assetloader)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
1022
1023```ts
1024import rpc from '@ohos.rpc';
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
1044系统内部通过该接口获取[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createShareServiceStub](#cloudextensioncreateshareservicestub)接口进行创建,使用Promise异步回调。
1045
1046**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1047
1048**参数:**
1049
1050| 参数名  | 类型                    | 必填 | 说明                                            |
1051| ------- | ----------------------- | ---- | ----------------------------------------------- |
1052| userId      | number  | 是   | 表示用户ID。         |
1053| bundleName  | string  | 是   | 应用包名。   |
1054
1055**返回值:**
1056
1057| 类型                                                         | 说明                                                         |
1058| ------------------------------------------------------------ | ------------------------------------------------------------ |
1059| Promise&lt;[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)&gt; | Promise对象,返回[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 |
1060
1061**示例:**
1062
1063```ts
1064import rpc from '@ohos.rpc';
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
1082提供资产的上传下载接口的类。
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
1088通过该接口实现资产的下载。
1089
1090**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1091
1092**参数:**
1093
1094| 参数名 | 类型                                   | 必填 | 说明                       |
1095| ------ | -------------------------------------- | ---- | -------------------------- |
1096| table  | string                                 | 是   | 表名。                     |
1097| gid    | string                                 | 是   | 数据上云后生成的唯一标记。 |
1098| prefix | string                                 | 是   | 表示前缀信息。             |
1099| assets | Array&lt;[CloudAsset](#cloudasset)&gt; | 是   | 表示需要下载的资产。       |
1100
1101**返回值:**
1102
1103| 类型                                                         | 说明                                                    |
1104| ------------------------------------------------------------ | ------------------------------------------------------- |
1105| Promise&lt;Array&lt;[Result](resultt)&lt;[CloudAsset](#cloudasset)&gt;&gt;&gt; | Promise对象,返回资产下载结果,包含资产ID和资产哈希值。 |
1106
1107**示例:**
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
1124通过该接口实现资产的上传。
1125
1126**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1127
1128**参数:**
1129
1130| 参数名 | 类型                                     | 必填 | 说明                                 |
1131| ------ | ---------------------------------------- | ---- | ------------------------------------ |
1132| table  | string                                   | 是   | 表名。                               |
1133| gid    | string                                   | 是   | 表示 GID,数据上云后生成的唯一标记。 |
1134| assets | Array&lt;[CloudAsset](#cloudasset)&gt; | 是   | 表示需要上传的资产。                 |
1135
1136**返回值:**
1137
1138| 类型                                                         | 说明                                                      |
1139| ------------------------------------------------------------ | --------------------------------------------------------- |
1140| Promise&lt;Array&lt;[Result](#resultt)&lt;[CloudAsset](#cloudasset)&gt;&gt;&gt; | Promise对象,返回资产上云的结果,包含资产ID和资产哈希值。 |
1141
1142**示例:**
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
1158提供对接共享云服务的类。开发者需要继承此类并实现类的接口,系统内部通过该类的接口联接并使用共享云服务,实现端云共享的发起、取消或退出等能力。
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
1164发起端云共享邀请。共享邀请时,会指定当前发起共享的应用、共享数据的资源标识和共享参与者,使用Promise异步回调。
1165
1166**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1167
1168**参数:**
1169
1170| 参数名  | 类型                    | 必填 | 说明                                            |
1171| ------- | ----------------------- | ---- | ----------------------------------------------- |
1172| userId          | number  | 是   | 表示用户ID。  |
1173| bundleName      | string  | 是   | 应用包名。    |
1174| sharingResource | string  | 是   | 端云共享资源的标识。   |
1175| participants    | Array&lt;[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)&gt;  | 是   | 端云共享参与者。   |
1176
1177**返回值:**
1178
1179| 类型                | 说明                      |
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对象,返回发起共享的结果。 |
1182
1183**示例:**
1184
1185```ts
1186import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得共享的返回值
1196    // ...
1197    // 返回服务端发起共享的返回结果
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
1219取消端云共享。取消共享时,会指定当前取消共享的应用、取消共享数据的资源标识和取消共享的参与者,使用Promise异步回调。
1220
1221**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1222
1223**参数:**
1224
1225| 参数名  | 类型                    | 必填 | 说明                                            |
1226| ------- | ----------------------- | ---- | ----------------------------------------------- |
1227| userId          | number  | 是   | 表示用户ID。  |
1228| bundleName      | string  | 是   | 应用包名。    |
1229| sharingResource | string  | 是   | 端云共享资源标识。   |
1230| participants    | Array&lt;[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)&gt;  | 是   | 端云共享参与者。   |
1231
1232**返回值:**
1233
1234| 类型                | 说明                      |
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对象,返回取消共享的结果。 |
1237
1238**示例:**
1239
1240```ts
1241import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得取消共享的返回值
1251    // ...
1252    // 返回服务端取消共享的返回结果
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
1274退出端云共享。退出共享时,会指定当前退出共享的应用以及退出共享数据的资源标识,使用Promise异步回调。
1275
1276**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1277
1278**参数:**
1279
1280| 参数名  | 类型                    | 必填 | 说明                                            |
1281| ------- | ----------------------- | ---- | ----------------------------------------------- |
1282| userId          | number  | 是   | 表示用户ID。  |
1283| bundleName      | string  | 是   | 应用包名。    |
1284| sharingResource | string  | 是   | 端云共享资源标识。   |
1285
1286**返回值:**
1287
1288| 类型                | 说明                      |
1289| ------------------- | ------------------------- |
1290| Promise&lt;[Result](#resultt)&lt;void&gt;&gt; | Promise对象,返回退出共享的结果。 |
1291
1292**示例:**
1293
1294```ts
1295import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得退出共享的返回值
1303    // ...
1304    // 返回服务端退出共享的返回结果
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
1318更改已共享数据的操作权限。更改权限时,会指定当前更改权限的应用、更改权限数据的资源标识和更改权限的参与者,使用Promise异步回调。
1319
1320**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1321
1322**参数:**
1323
1324| 参数名  | 类型                    | 必填 | 说明                                            |
1325| ------- | ----------------------- | ---- | ----------------------------------------------- |
1326| userId          | number  | 是   | 表示用户ID。  |
1327| bundleName      | string  | 是   | 应用包名。    |
1328| sharingResource | string  | 是   | 端云共享资源标识。   |
1329| participants    | Array&lt;[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)&gt;  | 是   | 端云共享参与者。   |
1330
1331**返回值:**
1332
1333| 类型                | 说明                      |
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对象,返回更改权限的结果。 |
1336
1337**示例:**
1338
1339```ts
1340import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得更改权限的返回值
1350    // ...
1351    // 返回服务端更改权限的返回结果
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
1373查询当前端云共享的参与者。查询时,会指定当前查询参与者的应用、查询参与者数据的资源标识,使用Promise异步回调。
1374
1375**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1376
1377**参数:**
1378
1379| 参数名  | 类型                    | 必填 | 说明                                            |
1380| ------- | ----------------------- | ---- | ----------------------------------------------- |
1381| userId          | number  | 是   | 表示用户ID。  |
1382| bundleName      | string  | 是   | 应用包名。    |
1383| sharingResource | string  | 是   | 端云共享资源标识。   |
1384
1385**返回值:**
1386
1387| 类型                                                         | 说明                                    |
1388| ------------------------------------------------------------ | --------------------------------------- |
1389| Promise&lt;[Result](#resultt)&lt;Array&lt;[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)&gt;&gt;&gt; | Promise对象,返回查询共享参与者的结果。 |
1390
1391**示例:**
1392
1393```ts
1394import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得查询参与者的返回值
1404    // ...
1405    // 返回服务端查询参与者的返回结果
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
1447根据邀请码查询当前端云共享的参与者。查询时,会指定当前查询参与者的应用、共享数据的邀请码,使用Promise异步回调。
1448
1449**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1450
1451**参数:**
1452
1453| 参数名  | 类型                    | 必填 | 说明                                            |
1454| ------- | ----------------------- | ---- | ----------------------------------------------- |
1455| userId          | number  | 是   | 表示用户ID。  |
1456| bundleName      | string  | 是   | 应用包名。    |
1457| invitationCode  | string  | 是   | 端云共享邀请码。   |
1458
1459**返回值:**
1460
1461| 类型                | 说明                      |
1462| ------------------- | ------------------------- |
1463| Promise&lt;[Result](#resultt)&lt;Array&lt;[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)&gt;&gt;&gt; | Promise对象,返回根据邀请码查询共享参与者的结果。 |
1464
1465**示例:**
1466
1467```ts
1468import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得查询参与者的返回值
1478    // ...
1479    // 返回服务端查询参与者的返回结果
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
1521被邀请者确认端云共享邀请。确认时,会指定当前确认邀请的应用、共享数据的邀请码以及确认状态,使用Promise异步回调。
1522
1523**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1524
1525**参数:**
1526
1527| 参数名  | 类型                    | 必填 | 说明                                            |
1528| ------- | ----------------------- | ---- | ----------------------------------------------- |
1529| userId          | number  | 是   | 表示用户ID。  |
1530| bundleName      | string  | 是   | 应用包名。    |
1531| invitationCode  | string  | 是   | 端云共享邀请码。   |
1532| state           | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11)  | 是   | 共享邀请的确认状态。   |
1533
1534**返回值:**
1535
1536| 类型                | 说明                      |
1537| ------------------- | ------------------------- |
1538| Promise&lt;[Result](#resultt)&lt;string&gt;&gt; | Promise对象,返回确认端云共享邀请数据的共享资源标识。 |
1539
1540**示例:**
1541
1542```ts
1543import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得确认共享邀请的返回值
1551    // ...
1552    // 返回服务端确认共享邀请的返回结果
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
1567更改端云共享邀请。更改共享邀请时,会指定当前更改共享邀请的应用、共享数据的的共享资源标识以及更改的状态,使用Promise异步回调。
1568
1569**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server
1570
1571**参数:**
1572
1573| 参数名  | 类型                    | 必填 | 说明                                            |
1574| ------- | ----------------------- | ---- | ----------------------------------------------- |
1575| userId          | number  | 是   | 表示用户ID。  |
1576| bundleName      | string  | 是   | 应用包名。    |
1577| sharingResource | string  | 是   | 端云共享资源标识。   |
1578| state           | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11)  | 是   | 共享邀请的更改状态。   |
1579
1580**返回值:**
1581
1582| 类型                | 说明                      |
1583| ------------------- | ------------------------- |
1584| Promise&lt;[Result](#resultt)&lt;void&gt;&gt; | Promise对象,返回更改共享邀请的结果。 |
1585
1586**示例:**
1587
1588```ts
1589import cloudData from '@ohos.data.cloudData';
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    // 对接云共享服务端,并获得更改共享邀请的返回值
1597    // ...
1598    // 返回服务端更改共享邀请的返回结果
1599    return {
1600      code: cloudData.sharing.SharingCode.SUCCESS,
1601      description: 'change confirm succeeded'
1602    }
1603  }
1604  // ...
1605}
1606```
1607## 完整示例
1608
1609以上示例中的类均采用implements实现,示例代码不能单独编译,需要实现父类中的所有方法才能使用,提供完整示例以作参考。
1610
1611```ts
1612import cloudExtension from '@ohos.data.cloudExtension';
1613import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility';
1614import Want from '@ohos.app.ability.Want';
1615import rpc from '@ohos.rpc';
1616import cloudData from '@ohos.data.cloudData';
1617
1618type Participant = cloudData.sharing.Participant;
1619let test_lockId: number = 1;
1620let test_time: number = 10;
1621let test_space: number = 100;
1622let test_userId: number = 1;
1623
1624class MyCloudDB implements cloudExtension.CloudDB {
1625  async generateId(count: number): Promise<cloudExtension.Result<Array<string>>> {
1626    console.info(`generate id, count: ${count}`);
1627    let result = new Array<string>();
1628    // ...
1629    // 返回创建Id的结果
1630    return {
1631      code: cloudExtension.ErrorCode.SUCCESS,
1632      description: 'generateId succeeded',
1633      value: result
1634    };
1635  }
1636
1637  async update(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> {
1638    console.info(`update, table: ${table}`);
1639    let updateRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = [];
1640    // ...
1641    // 返回更新数据的结果
1642    return updateRes;
1643  }
1644
1645  async insert(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> {
1646    console.info(`insert, table: ${table}`);
1647    let insertRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = [];
1648    // ...
1649    // 返回插入数据的结果
1650    return insertRes;
1651  }
1652
1653  async delete(table: string, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> {
1654    console.info(`delete, table: ${table}`);
1655    let deleteRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = [];
1656    // ...
1657    // 返回插入数据的结果
1658    return deleteRes;
1659  }
1660
1661  async query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<cloudExtension.Result<cloudExtension.CloudData>> {
1662    console.info(`query, table: ${table}`);
1663    // ...
1664    // 返回插入数据的结果
1665    return {
1666      code: cloudExtension.ErrorCode.SUCCESS,
1667      description: 'query succeeded',
1668      value: {
1669        nextCursor: "test_nextCursor",
1670        hasMore: true,
1671        values: []
1672      }
1673    };
1674  }
1675
1676  async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> {
1677    console.info(`DB lock`);
1678    // ...
1679    // 返回插入数据的结果
1680    return {
1681      code: cloudExtension.ErrorCode.SUCCESS,
1682      description: 'lock succeeded',
1683      value: {
1684        interval: test_time,
1685        lockId: test_lockId
1686      }
1687    };
1688  }
1689
1690  async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> {
1691    console.info(`heartbeat lock`);
1692    // ...
1693    // 返回插入数据的结果
1694    return {
1695      code: cloudExtension.ErrorCode.SUCCESS,
1696      description: 'heartbeat succeeded',
1697      value: {
1698        interval: test_time,
1699        lockId: test_lockId
1700      }
1701    };
1702  }
1703
1704  async unlock(lockId: number): Promise<cloudExtension.Result<boolean>> {
1705    console.info(`unlock`);
1706    // ...
1707    // 返回插入数据的结果
1708    return {
1709      code: cloudExtension.ErrorCode.SUCCESS,
1710      description: 'unlock succeeded',
1711      value: false
1712    };
1713  }
1714}
1715
1716class MyAssetLoader implements cloudExtension.AssetLoader {
1717  async download(table: string, gid: string, prefix: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> {
1718    console.info(`download asset loader, table: ${table}, gid: ${gid}, prefix: ${prefix}`);
1719    let downloadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>();
1720    // ...
1721    return downloadRes;
1722  }
1723
1724  async upload(table: string, gid: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> {
1725    console.info(`upload asset loader, table: ${table}, gid: ${gid}`);
1726    let uploadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>();
1727    // ...
1728    return uploadRes;
1729  }
1730}
1731
1732class MyShareCenter implements cloudExtension.ShareCenter {
1733  constructor() {
1734  }
1735
1736  async share(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>):
1737    Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> {
1738    console.info(`share, bundle: ${bundleName}`);
1739    // 对接云共享服务端,并获得共享的返回值
1740    // ...
1741    // 返回服务端发起共享的返回结果
1742    let result: Array<cloudExtension.Result<Participant>> = [];
1743    participants.forEach((item => {
1744      result.push({
1745        code: cloudData.sharing.SharingCode.SUCCESS,
1746        description: 'share succeeded'
1747      })
1748    }))
1749    return {
1750      code: cloudData.sharing.SharingCode.SUCCESS,
1751      description: 'share succeeded',
1752      value: result
1753    }
1754  }
1755
1756  async unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>):
1757    Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> {
1758    console.info(`unshare, bundle: ${bundleName}`);
1759    // 对接云共享服务端,并获得取消共享的返回值
1760    // ...
1761    // 返回服务端取消共享的返回结果
1762    let result: Array<cloudExtension.Result<Participant>> = [];
1763    participants.forEach((item => {
1764      result.push({
1765        code: cloudData.sharing.SharingCode.SUCCESS,
1766        description: 'unshare succeeded'
1767      })
1768    }))
1769    return {
1770      code: cloudData.sharing.SharingCode.SUCCESS,
1771      description: 'unshare succeeded',
1772      value: result
1773    }
1774  }
1775
1776  async exit(userId: number, bundleName: string, sharingResource: string):
1777    Promise<cloudExtension.Result<void>> {
1778    console.info(`exit share, bundle: ${bundleName}`);
1779    // 对接云共享服务端,并获得退出共享的返回值
1780    // ...
1781    // 返回服务端退出共享的返回结果
1782    return {
1783      code: cloudData.sharing.SharingCode.SUCCESS,
1784      description: 'exit share succeeded'
1785    }
1786  }
1787
1788  async changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>):
1789    Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> {
1790    console.info(`change privilege, bundle: ${bundleName}`);
1791    // 对接云共享服务端,并获得更改权限的返回值
1792    // ...
1793    // 返回服务端更改权限的返回结果
1794    let result: Array<cloudExtension.Result<Participant>> = [];
1795    participants.forEach((item => {
1796      result.push({
1797        code: cloudData.sharing.SharingCode.SUCCESS,
1798        description: 'change privilege succeeded'
1799      })
1800    }))
1801    return {
1802      code: cloudData.sharing.SharingCode.SUCCESS,
1803      description: 'change privilege succeeded',
1804      value: result
1805    }
1806  }
1807
1808  async queryParticipants(userId: number, bundleName: string, sharingResource: string):
1809    Promise<cloudExtension.Result<Array<Participant>>> {
1810    console.info(`query participants, bundle: ${bundleName}`);
1811    // 对接云共享服务端,并获得查询参与者的返回值
1812    // ...
1813    // 返回服务端查询参与者的返回结果
1814    let participants = new Array<cloudData.sharing.Participant>();
1815    participants.push({
1816      identity: '000000000',
1817      role: cloudData.sharing.Role.ROLE_INVITEE,
1818      state: cloudData.sharing.State.STATE_ACCEPTED,
1819      privilege: {
1820        writable: false,
1821        readable: true,
1822        creatable: false,
1823        deletable: false,
1824        shareable: false
1825      },
1826      attachInfo: ''
1827    })
1828    participants.push({
1829      identity: '111111111',
1830      role: cloudData.sharing.Role.ROLE_INVITEE,
1831      state: cloudData.sharing.State.STATE_ACCEPTED,
1832      privilege: {
1833        writable: false,
1834        readable: true,
1835        creatable: false,
1836        deletable: false,
1837        shareable: false
1838      },
1839      attachInfo: ''
1840    })
1841    return {
1842      code: cloudData.sharing.SharingCode.SUCCESS,
1843      description: 'query participants succeeded',
1844      value: participants
1845    }
1846  }
1847
1848  async queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string):
1849    Promise<cloudExtension.Result<Array<Participant>>> {
1850    console.info(`query participants by invitation, bundle: ${bundleName}`);
1851    // 对接云共享服务端,并获得查询参与者的返回值
1852    // ...
1853    // 返回服务端查询参与者的返回结果
1854    let participants = new Array<cloudData.sharing.Participant>();
1855    participants.push({
1856      identity: '000000000',
1857      role: cloudData.sharing.Role.ROLE_INVITEE,
1858      state: cloudData.sharing.State.STATE_ACCEPTED,
1859      privilege: {
1860        writable: false,
1861        readable: true,
1862        creatable: false,
1863        deletable: false,
1864        shareable: false
1865      },
1866      attachInfo: ''
1867    })
1868    participants.push({
1869      identity: '111111111',
1870      role: cloudData.sharing.Role.ROLE_INVITEE,
1871      state: cloudData.sharing.State.STATE_ACCEPTED,
1872      privilege: {
1873        writable: false,
1874        readable: true,
1875        creatable: false,
1876        deletable: false,
1877        shareable: false
1878      },
1879      attachInfo: ''
1880    })
1881    return {
1882      code: cloudData.sharing.SharingCode.SUCCESS,
1883      description: 'query participants by invitation succeeded',
1884      value: participants
1885    }
1886  }
1887
1888  async confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State):
1889    Promise<cloudExtension.Result<string>> {
1890    console.info(`confirm invitation, bundle: ${bundleName}`);
1891    // 对接云共享服务端,并获得确认共享邀请的返回值
1892    // ...
1893    // 返回服务端确认共享邀请的返回结果
1894    return {
1895      code: cloudData.sharing.SharingCode.SUCCESS,
1896      description: 'confirm invitation succeeded',
1897      value: 'sharing_resource_test'
1898    }
1899  }
1900
1901  async changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State):
1902    Promise<cloudExtension.Result<void>> {
1903    console.info(`change confirm, bundle: ${bundleName}`);
1904    // 对接云共享服务端,并获得更改共享邀请的返回值
1905    // ...
1906    // 返回服务端更改共享邀请的返回结果
1907    return {
1908      code: cloudData.sharing.SharingCode.SUCCESS,
1909      description: 'change confirm succeeded'
1910    }
1911  }
1912}
1913
1914class MyCloudService implements cloudExtension.CloudService {
1915  constructor() {
1916  }
1917
1918  async getServiceInfo(): Promise<cloudExtension.ServiceInfo> {
1919    console.info(`get service info`);
1920    // ...
1921    return {
1922      enableCloud: true,
1923      id: "test_id",
1924      totalSpace: test_space,
1925      remainingSpace: test_space,
1926      user: test_userId,
1927    };
1928  }
1929
1930  async getAppBriefInfo(): Promise<Record<string, cloudExtension.AppBriefInfo>> {
1931    console.info(`get app brief info`);
1932    // ...
1933    return {
1934      "test_bundle":
1935      {
1936        appId: "test_appID",
1937        bundleName: "test_bundlename",
1938        cloudSwitch: true,
1939        instanceId: 0,
1940      }
1941    };
1942  }
1943
1944  async getAppSchema(bundleName: string): Promise<cloudExtension.Result<cloudExtension.AppSchema>> {
1945    console.info(`get app schema, bundleName:${bundleName}`);
1946    // ...
1947    return {
1948      code: cloudExtension.ErrorCode.SUCCESS,
1949      description: "get app schema success",
1950      value: {
1951        bundleName: "test_bundleName",
1952        version: 1,
1953        databases: []
1954      }
1955    };
1956  }
1957
1958  async subscribe(subInfo: Record<string, Array<cloudExtension.Database>>, expirationTime: number): Promise<cloudExtension.Result<cloudExtension.SubscribeInfo>> {
1959    console.info
1960    (`subscribe expirationTime: ${expirationTime}`);
1961    // ...
1962    return {
1963      code: cloudExtension.ErrorCode.SUCCESS,
1964      description: "subscribe success",
1965      value: {
1966        expirationTime: test_time,
1967        subscribe: {}
1968      }
1969    };
1970  }
1971
1972  async unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> {
1973    console.info(`unsubscribe`);
1974    // ...
1975    return cloudExtension.ErrorCode.SUCCESS;
1976  }
1977
1978  async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> {
1979    console.info(`connect DB, bundleName: ${bundleName}`);
1980    return cloudExtension.createCloudDBStub(new MyCloudDB());
1981  }
1982
1983  async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> {
1984    console.info(`connect asset loader, bundle: ${bundleName}`);
1985    return cloudExtension.createAssetLoaderStub(new MyAssetLoader());
1986  }
1987
1988  async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> {
1989    console.info(`connect share center, bundle: ${bundleName}`);
1990    // ...
1991    return cloudExtension.createShareServiceStub(new MyShareCenter());
1992  }
1993}
1994
1995export default class MyServiceExtension extends ServiceExtensionAbility {
1996  onCreate(want: Want) {
1997    console.info(`onCreate: ${want}`);
1998  }
1999
2000  onRequest(want: Want, startId: number) {
2001    console.info(`onRequest: ${want} ${startId}`);
2002  }
2003
2004  onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject> {
2005    console.info(`onConnect: ${want}`);
2006    return cloudExtension.createCloudServiceStub(new MyCloudService());
2007  }
2008
2009  onDisconnect(want: Want) {
2010    console.info(`onDisconnect: ${want}`);
2011  }
2012
2013  onDestroy() {
2014    console.info('onDestroy');
2015  }
2016}
2017```
2018<!--no_check-->
2019