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