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