161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit ArkData
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport { AsyncCallback, Callback } from './@ohos.base';
2261847f8eSopenharmony_ciimport type Context from './application/BaseContext';
2361847f8eSopenharmony_ciimport commonType from '@ohos.data.commonType';
2461847f8eSopenharmony_ci
2561847f8eSopenharmony_ci/**
2661847f8eSopenharmony_ci * Provides interfaces to sync distributed object.
2761847f8eSopenharmony_ci *
2861847f8eSopenharmony_ci * @namespace distributedDataObject
2961847f8eSopenharmony_ci * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
3061847f8eSopenharmony_ci * @since 8
3161847f8eSopenharmony_ci */
3261847f8eSopenharmony_cideclare namespace distributedDataObject {
3361847f8eSopenharmony_ci  /**
3461847f8eSopenharmony_ci   * The information about the database bound to the asset.
3561847f8eSopenharmony_ci   *
3661847f8eSopenharmony_ci   * @interface BindInfo
3761847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
3861847f8eSopenharmony_ci   * @since 11
3961847f8eSopenharmony_ci   */
4061847f8eSopenharmony_ci  interface BindInfo {
4161847f8eSopenharmony_ci    /**
4261847f8eSopenharmony_ci     * The name of store where the asset resides.
4361847f8eSopenharmony_ci     *
4461847f8eSopenharmony_ci     * @type { string }
4561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
4661847f8eSopenharmony_ci     * @since 11
4761847f8eSopenharmony_ci     */
4861847f8eSopenharmony_ci    storeName: string;
4961847f8eSopenharmony_ci
5061847f8eSopenharmony_ci    /**
5161847f8eSopenharmony_ci     * The name of table where the asset resides.
5261847f8eSopenharmony_ci     *
5361847f8eSopenharmony_ci     * @type { string }
5461847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
5561847f8eSopenharmony_ci     * @since 11
5661847f8eSopenharmony_ci     */
5761847f8eSopenharmony_ci    tableName: string;
5861847f8eSopenharmony_ci
5961847f8eSopenharmony_ci    /**
6061847f8eSopenharmony_ci     * The Primary key of the rdb table where the asset resides.
6161847f8eSopenharmony_ci     *
6261847f8eSopenharmony_ci     * @type { commonType.ValuesBucket }
6361847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
6461847f8eSopenharmony_ci     * @since 11
6561847f8eSopenharmony_ci     */
6661847f8eSopenharmony_ci    primaryKey: commonType.ValuesBucket;
6761847f8eSopenharmony_ci
6861847f8eSopenharmony_ci    /**
6961847f8eSopenharmony_ci     * The field(column) name of the rdb table where the asset resides.
7061847f8eSopenharmony_ci     *
7161847f8eSopenharmony_ci     * @type { string }
7261847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
7361847f8eSopenharmony_ci     * @since 11
7461847f8eSopenharmony_ci     */
7561847f8eSopenharmony_ci    field: string;
7661847f8eSopenharmony_ci
7761847f8eSopenharmony_ci    /**
7861847f8eSopenharmony_ci     * Name of the asset to be bound. When the column type is Assets, this field refers to the asset name of
7961847f8eSopenharmony_ci     * one of the assets.
8061847f8eSopenharmony_ci     *
8161847f8eSopenharmony_ci     * @type { string }
8261847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
8361847f8eSopenharmony_ci     * @since 11
8461847f8eSopenharmony_ci     */
8561847f8eSopenharmony_ci    assetName: string;
8661847f8eSopenharmony_ci  }
8761847f8eSopenharmony_ci
8861847f8eSopenharmony_ci  /**
8961847f8eSopenharmony_ci   * Create distributed object.
9061847f8eSopenharmony_ci   *
9161847f8eSopenharmony_ci   * @param { object } source - Source Init data of distributed object.
9261847f8eSopenharmony_ci   * @returns { DistributedObject } - Return the distributed object.
9361847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
9461847f8eSopenharmony_ci   * @since 8
9561847f8eSopenharmony_ci   * @deprecated since 9
9661847f8eSopenharmony_ci   * @useinstead ohos.distributedDataObject.create
9761847f8eSopenharmony_ci   */
9861847f8eSopenharmony_ci  function createDistributedObject(source: object): DistributedObject;
9961847f8eSopenharmony_ci
10061847f8eSopenharmony_ci  /**
10161847f8eSopenharmony_ci   * Create distributed object.
10261847f8eSopenharmony_ci   *
10361847f8eSopenharmony_ci   * @param { Context } context - Indicates the application context.
10461847f8eSopenharmony_ci   * @param { object } source - Source Init data of distributed object.
10561847f8eSopenharmony_ci   * @returns { DataObject } - Return the distributed object.
10661847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
10761847f8eSopenharmony_ci   *                                                                   2. Incorrect parameter types.
10861847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
10961847f8eSopenharmony_ci   * @since 9
11061847f8eSopenharmony_ci   */
11161847f8eSopenharmony_ci  function create(context: Context, source: object): DataObject;
11261847f8eSopenharmony_ci
11361847f8eSopenharmony_ci  /**
11461847f8eSopenharmony_ci   * Generate a random sessionId.
11561847f8eSopenharmony_ci   *
11661847f8eSopenharmony_ci   * @returns { string } - Return generated sessionId.
11761847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
11861847f8eSopenharmony_ci   * @since 8
11961847f8eSopenharmony_ci   */
12061847f8eSopenharmony_ci  function genSessionId(): string;
12161847f8eSopenharmony_ci
12261847f8eSopenharmony_ci  /**
12361847f8eSopenharmony_ci   * The response of save.
12461847f8eSopenharmony_ci   * Contains the parameter information of the save object.
12561847f8eSopenharmony_ci   *
12661847f8eSopenharmony_ci   * @interface SaveSuccessResponse
12761847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
12861847f8eSopenharmony_ci   * @since 9
12961847f8eSopenharmony_ci   */
13061847f8eSopenharmony_ci  interface SaveSuccessResponse {
13161847f8eSopenharmony_ci    /**
13261847f8eSopenharmony_ci     * sessionId of saved object
13361847f8eSopenharmony_ci     *
13461847f8eSopenharmony_ci     * @type { string }
13561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
13661847f8eSopenharmony_ci     * @since 9
13761847f8eSopenharmony_ci     */
13861847f8eSopenharmony_ci    sessionId: string;
13961847f8eSopenharmony_ci
14061847f8eSopenharmony_ci    /**
14161847f8eSopenharmony_ci     * version of saved object, can compare with DistributedObject.__version
14261847f8eSopenharmony_ci     *
14361847f8eSopenharmony_ci     * @type { number }
14461847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
14561847f8eSopenharmony_ci     * @since 9
14661847f8eSopenharmony_ci     */
14761847f8eSopenharmony_ci    version: number;
14861847f8eSopenharmony_ci
14961847f8eSopenharmony_ci    /**
15061847f8eSopenharmony_ci     * deviceid that data saved
15161847f8eSopenharmony_ci     * data is "local", means save in local device
15261847f8eSopenharmony_ci     * otherwise, means the deviceId of others device
15361847f8eSopenharmony_ci     *
15461847f8eSopenharmony_ci     * @type { string }
15561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
15661847f8eSopenharmony_ci     * @since 9
15761847f8eSopenharmony_ci     */
15861847f8eSopenharmony_ci    deviceId: string;
15961847f8eSopenharmony_ci  }
16061847f8eSopenharmony_ci
16161847f8eSopenharmony_ci  /**
16261847f8eSopenharmony_ci   * The response of revokeSave.
16361847f8eSopenharmony_ci   * Contains the sessionId of the changed object.
16461847f8eSopenharmony_ci   *
16561847f8eSopenharmony_ci   * @interface RevokeSaveSuccessResponse
16661847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
16761847f8eSopenharmony_ci   * @since 9
16861847f8eSopenharmony_ci   */
16961847f8eSopenharmony_ci  interface RevokeSaveSuccessResponse {
17061847f8eSopenharmony_ci    /**
17161847f8eSopenharmony_ci     * The sessionId of the changed object.
17261847f8eSopenharmony_ci     *
17361847f8eSopenharmony_ci     * @type { string }
17461847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
17561847f8eSopenharmony_ci     * @since 9
17661847f8eSopenharmony_ci     */
17761847f8eSopenharmony_ci    sessionId: string;
17861847f8eSopenharmony_ci  }
17961847f8eSopenharmony_ci
18061847f8eSopenharmony_ci  /**
18161847f8eSopenharmony_ci   * Object create by {@link createDistributedObject}.
18261847f8eSopenharmony_ci   *
18361847f8eSopenharmony_ci   * @interface DistributedObject
18461847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
18561847f8eSopenharmony_ci   * @since 8
18661847f8eSopenharmony_ci   * @deprecated since 9
18761847f8eSopenharmony_ci   * @useinstead ohos.distributedDataObject.DataObject
18861847f8eSopenharmony_ci   */
18961847f8eSopenharmony_ci  interface DistributedObject {
19061847f8eSopenharmony_ci    /**
19161847f8eSopenharmony_ci     * Change object session
19261847f8eSopenharmony_ci     *
19361847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
19461847f8eSopenharmony_ci     * @param { string } sessionId - sessionId The sessionId to be joined, if empty, leave all session.
19561847f8eSopenharmony_ci     * @returns { boolean } - Return a result of function.
19661847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
19761847f8eSopenharmony_ci     * @since 8
19861847f8eSopenharmony_ci     * @deprecated since 9
19961847f8eSopenharmony_ci     * @useinstead ohos.distributedDataObject.DataObject.setSessionId
20061847f8eSopenharmony_ci     */
20161847f8eSopenharmony_ci    setSessionId(sessionId?: string): boolean;
20261847f8eSopenharmony_ci
20361847f8eSopenharmony_ci    /**
20461847f8eSopenharmony_ci     * On watch of change
20561847f8eSopenharmony_ci     *
20661847f8eSopenharmony_ci     * @param { 'change' } type - Event type, fixed as 'change', indicates data change.
20761847f8eSopenharmony_ci     * @param { Function } callback
20861847f8eSopenharmony_ci     *          Indicates the observer of object data changed.
20961847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
21061847f8eSopenharmony_ci     *          {Array<string>} fields - Attribute names of changed data.
21161847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
21261847f8eSopenharmony_ci     * @since 8
21361847f8eSopenharmony_ci     * @deprecated since 9
21461847f8eSopenharmony_ci     * @useinstead ohos.distributedDataObject.DataObject.on
21561847f8eSopenharmony_ci     */
21661847f8eSopenharmony_ci    on(type: 'change', callback: (sessionId: string, fields: Array<string>) => void): void;
21761847f8eSopenharmony_ci
21861847f8eSopenharmony_ci    /**
21961847f8eSopenharmony_ci     * Off watch of change
22061847f8eSopenharmony_ci     *
22161847f8eSopenharmony_ci     * @param { 'change' } type - Event type, fixed as 'change', indicates data change.
22261847f8eSopenharmony_ci     * @param { Function } callback
22361847f8eSopenharmony_ci     *          Indicates the observer of object data changed.
22461847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
22561847f8eSopenharmony_ci     *          {Array<string>} fields - Attribute names of changed data.
22661847f8eSopenharmony_ci     *          callback If not null, off the callback, if undefined, off all callbacks.
22761847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
22861847f8eSopenharmony_ci     * @since 8
22961847f8eSopenharmony_ci     * @deprecated since 9
23061847f8eSopenharmony_ci     * @useinstead ohos.distributedDataObject.DataObject.off
23161847f8eSopenharmony_ci     */
23261847f8eSopenharmony_ci    off(type: 'change', callback?: (sessionId: string, fields: Array<string>) => void): void;
23361847f8eSopenharmony_ci
23461847f8eSopenharmony_ci    /**
23561847f8eSopenharmony_ci     * On watch of status
23661847f8eSopenharmony_ci     *
23761847f8eSopenharmony_ci     * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object.
23861847f8eSopenharmony_ci     * @param { Function } callback
23961847f8eSopenharmony_ci     *          Indicates the observer of object status changed.
24061847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
24161847f8eSopenharmony_ci     *          {string} networkId - NetworkId of the changed device.
24261847f8eSopenharmony_ci     *          {string} status
24361847f8eSopenharmony_ci     *                   'online' The object became online on the device and data can be synced to the device.
24461847f8eSopenharmony_ci     *                   'offline' The object became offline on the device and the object can not sync any data.
24561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
24661847f8eSopenharmony_ci     * @since 8
24761847f8eSopenharmony_ci     * @deprecated since 9
24861847f8eSopenharmony_ci     * @useinstead ohos.distributedDataObject.DataObject.on
24961847f8eSopenharmony_ci     */
25061847f8eSopenharmony_ci    on(
25161847f8eSopenharmony_ci      type: 'status',
25261847f8eSopenharmony_ci      callback: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void
25361847f8eSopenharmony_ci    ): void;
25461847f8eSopenharmony_ci
25561847f8eSopenharmony_ci    /**
25661847f8eSopenharmony_ci     * Off watch of status
25761847f8eSopenharmony_ci     *
25861847f8eSopenharmony_ci     * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object.
25961847f8eSopenharmony_ci     * @param { Function } callback
26061847f8eSopenharmony_ci     *          Indicates the observer of object status changed.
26161847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
26261847f8eSopenharmony_ci     *          {string} networkId - NetworkId of the changed device.
26361847f8eSopenharmony_ci     *          {string} status
26461847f8eSopenharmony_ci     *                   'online' The object became online on the device and data can be synced to the device.
26561847f8eSopenharmony_ci     *                   'offline' The object became offline on the device and the object can not sync any data.
26661847f8eSopenharmony_ci     *          callback If not null, off the callback, if undefined, off all callbacks.
26761847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
26861847f8eSopenharmony_ci     * @since 8
26961847f8eSopenharmony_ci     * @deprecated since 9
27061847f8eSopenharmony_ci     * @useinstead ohos.distributedDataObject.DataObject.off
27161847f8eSopenharmony_ci     */
27261847f8eSopenharmony_ci    off(
27361847f8eSopenharmony_ci      type: 'status',
27461847f8eSopenharmony_ci      callback?: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void
27561847f8eSopenharmony_ci    ): void;
27661847f8eSopenharmony_ci  }
27761847f8eSopenharmony_ci
27861847f8eSopenharmony_ci  /**
27961847f8eSopenharmony_ci   * Object create by {@link create}.
28061847f8eSopenharmony_ci   *
28161847f8eSopenharmony_ci   * @interface DataObject
28261847f8eSopenharmony_ci   * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
28361847f8eSopenharmony_ci   * @since 9
28461847f8eSopenharmony_ci   */
28561847f8eSopenharmony_ci  interface DataObject {
28661847f8eSopenharmony_ci    /**
28761847f8eSopenharmony_ci     * Change object session.
28861847f8eSopenharmony_ci     *
28961847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
29061847f8eSopenharmony_ci     * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session.
29161847f8eSopenharmony_ci     * @param {AsyncCallback<void>} callback - The callback of setSessionId.
29261847f8eSopenharmony_ci     * @throws {BusinessError} 201 - Permission verification failed.
29361847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types.
29461847f8eSopenharmony_ci     * @throws {BusinessError} 15400001 - Create table failed.
29561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
29661847f8eSopenharmony_ci     * @since 9
29761847f8eSopenharmony_ci     */
29861847f8eSopenharmony_ci    /**
29961847f8eSopenharmony_ci     * Change object session.
30061847f8eSopenharmony_ci     *
30161847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
30261847f8eSopenharmony_ci     * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session.
30361847f8eSopenharmony_ci     * @param {AsyncCallback<void>} callback - The callback of setSessionId.
30461847f8eSopenharmony_ci     * @throws {BusinessError} 201 - Permission verification failed.
30561847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
30661847f8eSopenharmony_ci     *     2. The sessionId allows only letters, digits, and underscores(_), and cannot exceed 128 in length.
30761847f8eSopenharmony_ci     * @throws {BusinessError} 15400001 - Create table failed.
30861847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
30961847f8eSopenharmony_ci     * @since 12
31061847f8eSopenharmony_ci     */
31161847f8eSopenharmony_ci    setSessionId(sessionId: string, callback: AsyncCallback<void>): void;
31261847f8eSopenharmony_ci
31361847f8eSopenharmony_ci    /**
31461847f8eSopenharmony_ci     * Leave all session.
31561847f8eSopenharmony_ci     *
31661847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
31761847f8eSopenharmony_ci     * @param {AsyncCallback<void>} callback - The callback of setSessionId.
31861847f8eSopenharmony_ci     * @throws {BusinessError} 201 - Permission verification failed.
31961847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types.
32061847f8eSopenharmony_ci     * @throws {BusinessError} 15400001 - Create table failed.
32161847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
32261847f8eSopenharmony_ci     * @since 9
32361847f8eSopenharmony_ci     */
32461847f8eSopenharmony_ci    setSessionId(callback: AsyncCallback<void>): void;
32561847f8eSopenharmony_ci
32661847f8eSopenharmony_ci    /**
32761847f8eSopenharmony_ci     * Change object session.
32861847f8eSopenharmony_ci     *
32961847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
33061847f8eSopenharmony_ci     * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session.
33161847f8eSopenharmony_ci     * @returns {Promise<void>} - The promise returned by the function.
33261847f8eSopenharmony_ci     * @throws {BusinessError} 201 - Permission verification failed.
33361847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Incorrect parameter types.
33461847f8eSopenharmony_ci     * @throws {BusinessError} 15400001 - Create table failed.
33561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
33661847f8eSopenharmony_ci     * @since 9
33761847f8eSopenharmony_ci     */
33861847f8eSopenharmony_ci    /**
33961847f8eSopenharmony_ci     * Change object session.
34061847f8eSopenharmony_ci     *
34161847f8eSopenharmony_ci     * @permission ohos.permission.DISTRIBUTED_DATASYNC
34261847f8eSopenharmony_ci     * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session.
34361847f8eSopenharmony_ci     * @returns {Promise<void>} - The promise returned by the function.
34461847f8eSopenharmony_ci     * @throws {BusinessError} 201 - Permission verification failed.
34561847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
34661847f8eSopenharmony_ci     *     2. The sessionId allows only letters, digits, and underscores(_), and cannot exceed 128 in length.
34761847f8eSopenharmony_ci     * @throws {BusinessError} 15400001 - Create table failed.
34861847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
34961847f8eSopenharmony_ci     * @since 12
35061847f8eSopenharmony_ci     */
35161847f8eSopenharmony_ci    setSessionId(sessionId?: string): Promise<void>;
35261847f8eSopenharmony_ci
35361847f8eSopenharmony_ci    /**
35461847f8eSopenharmony_ci     * On watch of change.
35561847f8eSopenharmony_ci     *
35661847f8eSopenharmony_ci     * @param { 'change' } type - event type, fixed as 'change', indicates data change.
35761847f8eSopenharmony_ci     * @param { Function } callback
35861847f8eSopenharmony_ci     *          indicates the observer of object data changed.
35961847f8eSopenharmony_ci     *          {string} sessionId - the sessionId of the changed object.
36061847f8eSopenharmony_ci     *          {Array<string>} fields - Attribute names of changed data.
36161847f8eSopenharmony_ci     *          sessionId The sessionId of the changed object.
36261847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
36361847f8eSopenharmony_ci     *                                                                 2. Incorrect parameter types.
36461847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
36561847f8eSopenharmony_ci     * @since 9
36661847f8eSopenharmony_ci     */
36761847f8eSopenharmony_ci    on(type: 'change', callback: (sessionId: string, fields: Array<string>) => void ): void;
36861847f8eSopenharmony_ci
36961847f8eSopenharmony_ci    /**
37061847f8eSopenharmony_ci     * Off watch of change.
37161847f8eSopenharmony_ci     *
37261847f8eSopenharmony_ci     * @param { 'change' } type - Event type, fixed as 'change', indicates data change.
37361847f8eSopenharmony_ci     * @param { Function } callback
37461847f8eSopenharmony_ci     *          indicates the observer of object data changed.
37561847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
37661847f8eSopenharmony_ci     *          {Array<string>} fields - Attribute names of changed data.
37761847f8eSopenharmony_ci     *          callback If not null, off the callback, if undefined, off all callbacks.
37861847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
37961847f8eSopenharmony_ci     *                                                                 2. Incorrect parameter types.
38061847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
38161847f8eSopenharmony_ci     * @since 9
38261847f8eSopenharmony_ci     */
38361847f8eSopenharmony_ci    off(type: 'change', callback?: (sessionId: string, fields: Array<string>) => void ): void;
38461847f8eSopenharmony_ci
38561847f8eSopenharmony_ci    /**
38661847f8eSopenharmony_ci     * On watch of status.
38761847f8eSopenharmony_ci     *
38861847f8eSopenharmony_ci     * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object.
38961847f8eSopenharmony_ci     * @param { Function } callback
39061847f8eSopenharmony_ci     *          indicates the observer of object status changed.
39161847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
39261847f8eSopenharmony_ci     *          {string} networkId - NetworkId of the changed device.
39361847f8eSopenharmony_ci     *          {string} status
39461847f8eSopenharmony_ci     *                   'online' The object became online on the device and data can be synced to the device.
39561847f8eSopenharmony_ci     *                   'offline' The object became offline on the device and the object can not sync any data.
39661847f8eSopenharmony_ci     *                   'restored' The object restored success.
39761847f8eSopenharmony_ci     * @throws {BusinessError} 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
39861847f8eSopenharmony_ci     *                                                                 2. Incorrect parameter types.
39961847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
40061847f8eSopenharmony_ci     * @since 9
40161847f8eSopenharmony_ci     */
40261847f8eSopenharmony_ci    on(
40361847f8eSopenharmony_ci      type: 'status',
40461847f8eSopenharmony_ci      callback: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void
40561847f8eSopenharmony_ci    ): void;
40661847f8eSopenharmony_ci
40761847f8eSopenharmony_ci    /**
40861847f8eSopenharmony_ci     * Off watch of status.
40961847f8eSopenharmony_ci     *
41061847f8eSopenharmony_ci     * @param { 'status' } type - Event type, fixed as 'status', indicates the online and offline of the object.
41161847f8eSopenharmony_ci     * @param { Function } callback
41261847f8eSopenharmony_ci     *          Indicates the observer of object status changed.
41361847f8eSopenharmony_ci     *          {string} sessionId - The sessionId of the changed object.
41461847f8eSopenharmony_ci     *          {string} networkId - NetworkId of the changed device.
41561847f8eSopenharmony_ci     *          {string} status
41661847f8eSopenharmony_ci     *                   'online' The object became online on the device and data can be synced to the device.
41761847f8eSopenharmony_ci     *                   'offline' The object became offline on the device and the object can not sync any data.
41861847f8eSopenharmony_ci     *          callback If not null, off the callback, if undefined, off all callbacks.
41961847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
42061847f8eSopenharmony_ci     *                                                                   2. Incorrect parameter types.
42161847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
42261847f8eSopenharmony_ci     * @since 9
42361847f8eSopenharmony_ci     */
42461847f8eSopenharmony_ci    off(
42561847f8eSopenharmony_ci      type: 'status',
42661847f8eSopenharmony_ci      callback?: (sessionId: string, networkId: string, status: 'online' | 'offline' ) => void
42761847f8eSopenharmony_ci    ): void;
42861847f8eSopenharmony_ci
42961847f8eSopenharmony_ci    /**
43061847f8eSopenharmony_ci     * Save object, after save object data successfully, the object data will not release when app existed,
43161847f8eSopenharmony_ci     * and resume data on saved device after app existed.
43261847f8eSopenharmony_ci     * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data,
43361847f8eSopenharmony_ci     * you should encrypt it
43461847f8eSopenharmony_ci     * The saved data will be released when
43561847f8eSopenharmony_ci     * 1. saved after 24h.
43661847f8eSopenharmony_ci     * 2. app uninstalled.
43761847f8eSopenharmony_ci     * 3. after resume data success, system will auto delete the saved data.
43861847f8eSopenharmony_ci     *
43961847f8eSopenharmony_ci     * @param { string } deviceId - Indicates the device that will resume the object data.
44061847f8eSopenharmony_ci     * @param { AsyncCallback<SaveSuccessResponse> } callback
44161847f8eSopenharmony_ci     *        {SaveSuccessResponse}: The response of save.
44261847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
44361847f8eSopenharmony_ci     *                                                                   2. Incorrect parameter types.
44461847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
44561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
44661847f8eSopenharmony_ci     * @since 9
44761847f8eSopenharmony_ci     */
44861847f8eSopenharmony_ci    save(deviceId: string, callback: AsyncCallback<SaveSuccessResponse>): void;
44961847f8eSopenharmony_ci
45061847f8eSopenharmony_ci    /**
45161847f8eSopenharmony_ci     * Save object, after save object data successfully, the object data will not release when app existed,
45261847f8eSopenharmony_ci     * and resume data on saved device after app existed.
45361847f8eSopenharmony_ci     * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data,
45461847f8eSopenharmony_ci     * you should encrypt it.
45561847f8eSopenharmony_ci     * The saved data will be released when
45661847f8eSopenharmony_ci     * 1. saved after 24h.
45761847f8eSopenharmony_ci     * 2. app uninstalled.
45861847f8eSopenharmony_ci     * 3. after resume data success, system will auto delete the saved data.
45961847f8eSopenharmony_ci     *
46061847f8eSopenharmony_ci     * @param { string } deviceId - Indicates the device that will resume the object data.
46161847f8eSopenharmony_ci     * @returns { Promise<SaveSuccessResponse> } {SaveSuccessResponse}: The response of save.
46261847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
46361847f8eSopenharmony_ci     *                                                                   2. Incorrect parameter types.
46461847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
46561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
46661847f8eSopenharmony_ci     * @since 9
46761847f8eSopenharmony_ci     */
46861847f8eSopenharmony_ci    save(deviceId: string): Promise<SaveSuccessResponse>;
46961847f8eSopenharmony_ci
47061847f8eSopenharmony_ci    /**
47161847f8eSopenharmony_ci     * Revoke save object, delete saved object immediately, if object is saved in local device,
47261847f8eSopenharmony_ci     * it will delete saved data on all trusted device.
47361847f8eSopenharmony_ci     * if object is saved in other device, it will delete data in local device.
47461847f8eSopenharmony_ci     *
47561847f8eSopenharmony_ci     * @param { AsyncCallback<RevokeSaveSuccessResponse> } callback
47661847f8eSopenharmony_ci     *        {RevokeSaveSuccessResponse}: The response of revokeSave.
47761847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Incorrect parameter types.
47861847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
47961847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
48061847f8eSopenharmony_ci     * @since 9
48161847f8eSopenharmony_ci     */
48261847f8eSopenharmony_ci    revokeSave(callback: AsyncCallback<RevokeSaveSuccessResponse>): void;
48361847f8eSopenharmony_ci
48461847f8eSopenharmony_ci    /**
48561847f8eSopenharmony_ci     * Revoke save object, delete saved object immediately, if object is saved in local device,
48661847f8eSopenharmony_ci     * it will delete saved data on all trusted device.
48761847f8eSopenharmony_ci     * if object is saved in other device, it will delete data in local device.
48861847f8eSopenharmony_ci     *
48961847f8eSopenharmony_ci     * @returns { Promise<RevokeSaveSuccessResponse> } {RevokeSaveSuccessResponse}: The response of revokeSave.
49061847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
49161847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
49261847f8eSopenharmony_ci     * @since 9
49361847f8eSopenharmony_ci     */
49461847f8eSopenharmony_ci    revokeSave(): Promise<RevokeSaveSuccessResponse>;
49561847f8eSopenharmony_ci
49661847f8eSopenharmony_ci    /**
49761847f8eSopenharmony_ci     * Bind an Asset of a distributed object to an asset in rdb that points to the same asset file, which means that
49861847f8eSopenharmony_ci     * both assets have the same uri.
49961847f8eSopenharmony_ci     * @param { string } assetKey - Indicates the key of the asset type in Object.
50061847f8eSopenharmony_ci     * @param { BindInfo } bindInfo - Indicates the information of the asset in RelationalStore.
50161847f8eSopenharmony_ci     * @param { AsyncCallback<void> } callback - The callback of bindAssetStore.
50261847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
50361847f8eSopenharmony_ci     *                                                                   2. Incorrect parameter types.
50461847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
50561847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
50661847f8eSopenharmony_ci     * @since 11
50761847f8eSopenharmony_ci     */
50861847f8eSopenharmony_ci    bindAssetStore(assetKey: string, bindInfo: BindInfo, callback: AsyncCallback<void>): void;
50961847f8eSopenharmony_ci
51061847f8eSopenharmony_ci    /**
51161847f8eSopenharmony_ci     * Bind an Asset of a distributed object to an asset in rdb that points to the same asset file, which means that
51261847f8eSopenharmony_ci     * both assets have the same uri.
51361847f8eSopenharmony_ci     * @param { string } assetKey - Indicates the key of the asset type in Object.
51461847f8eSopenharmony_ci     * @param { BindInfo } bindInfo - Indicates the information of the asset in RelationalStore.
51561847f8eSopenharmony_ci     * @returns { Promise<void> } The promise returned by the function.
51661847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
51761847f8eSopenharmony_ci     *                                                                   2. Incorrect parameter types.
51861847f8eSopenharmony_ci     * @throws { BusinessError } 801 - Capability not supported.
51961847f8eSopenharmony_ci     * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject
52061847f8eSopenharmony_ci     * @since 11
52161847f8eSopenharmony_ci     */
52261847f8eSopenharmony_ci    bindAssetStore(assetKey: string, bindInfo: BindInfo): Promise<void>;
52361847f8eSopenharmony_ci  }
52461847f8eSopenharmony_ci}
52561847f8eSopenharmony_ci
52661847f8eSopenharmony_ciexport default distributedDataObject;
527