diff --git a/api/@ohos.data.distributedDataObject.d.ts b/api/@ohos.data.distributedDataObject.d.ts index ac9d6683f1bfa88b7ca9f9a398a471afa948cb91..c42521376c48a3284cc1256d199a18cd15387bfc 100644 --- a/api/@ohos.data.distributedDataObject.d.ts +++ b/api/@ohos.data.distributedDataObject.d.ts @@ -14,44 +14,68 @@ */ import {AsyncCallback, Callback} from './basic'; +import Context from './application/Context'; /** - * Provides interfaces to sync distributed object + * Provides interfaces to sync distributed object. * - * @name distributedDataObject - * @since 8 * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 8 */ declare namespace distributedDataObject { + /** - * Create distributed object + * Create distributed object. * - * @param source Init data of distributed object - * @return Returns the distributed object + * @param {object} source - source Init data of distributed object. + * @returns {DistributedObject} - return the distributed object. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.create */ function createDistributedObject(source: object): DistributedObject; /** - * Generate a random sessionId + * Create distributed object. * - * @return Returns the random sessionId + * @param {Context} context - Indicates the application context. + * @param {object} source - source Init data of distributed object. + * @returns {DistributedObjectV9} - return the distributed object. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + function create(context: Context, source: object): DistributedObjectV9; + + /** + * Generate a random sessionId. + * + * @returns {string} - return generated sessionId. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 */ function genSessionId(): string; /** + * The response of save. + * Contains the parameter information of the save object. + * + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 9 */ interface SaveSuccessResponse { + /** * sessionId of saved object + * * @since 9 */ sessionId: string; /** * version of saved object, can compare with DistributedObject.__version + * * @since 9 */ version: number; @@ -60,16 +84,24 @@ declare namespace distributedDataObject { * deviceid that data saved * data is "local", means save in local device * otherwise, means the networkId of device + * * @since 9 */ deviceId: string; } /** + * The response of revokeSave. + * Contains the sessionId of the changed object. + * + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 9 */ interface RevokeSaveSuccessResponse { + /** + * The sessionId of the changed object. + * * @since 9 */ sessionId: string; @@ -80,76 +112,262 @@ declare namespace distributedDataObject { * * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9 */ interface DistributedObject { - /* + + /** * Change object session * - * @param sessionId The sessionId to be joined, if empty, leave all session - * @return Operation result, true is success, false is failed * @permission ohos.permission.DISTRIBUTED_DATASYNC + * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. + * @returns {boolean} - return a result of function. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9.setSessionId */ setSessionId(sessionId?: string): boolean; /** * On watch of change - * - * @param callback The callback of change + * + * @param {string} type - event type, fixed as' change ', indicates data change. + * @param {Callback<{sessionId: string, fields: Array}>} callback + * indicates the observer of object data changed. + * {string} sessionId - the sessionId of the changed object. + * {Array} fields - changed data. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9.on */ on(type: 'change', callback: Callback<{ sessionId: string, fields: Array }>): void; /** * Off watch of change - * - * @param callback If not null, off the callback, if undefined, off all callbacks + * + * @param {string} type - event type, fixed as' change ', indicates data change. + * @param {Callback<{sessionId: string, fields: Array}>} callback + * indicates the observer of object data changed. + * {string} sessionId - the sessionId of the changed object. + * {Array} fields - changed data. + * callback If not null, off the callback, if undefined, off all callbacks. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9.off */ off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array }>): void; /** * On watch of status - * - * @param callback Indicates the observer of object status changed. - * sessionId: The sessionId of the changed object - * networkId: NetworkId of the changed device - * status: 'online' The object became online on the device and data can be synced to the device - * 'offline' The object became offline on the device and the object can not sync any data + * + * @param {string} type - event type, fixed as' status', indicates the online and offline of the object. + * @param {Callback<{sessionId: string, networkId: string, status: 'online' | 'offline'}>} callback + * indicates the observer of object status changed. + * {string} sessionId - the sessionId of the changed object. + * {string} networkId - networkId of the changed device. + * {string} status + * 'online' The object became online on the device and data can be synced to the device. + * 'offline' The object became offline on the device and the object can not sync any data. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9.on */ - on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void; + on(type: 'status', + callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void; /** * Off watch of status - * - * @param callback If not null, off the callback, if undefined, off all callbacks + * + * @param {string} type - event type, fixed as' status', indicates the online and offline of the object. + * @param {Callback<{sessionId: string, networkId: string, status: 'online' | 'offline'}>} callback + * Indicates the observer of object status changed. + * {string} sessionId - the sessionId of the changed object. + * {string} networkId - networkId of the changed device. + * {string} status + * 'online' The object became online on the device and data can be synced to the device. + * 'offline' The object became offline on the device and the object can not sync any data. + * callback If not null, off the callback, if undefined, off all callbacks. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 8 + * @deprecated since 9 + * @useinstead ohos.distributedDataObject.DistributedObjectV9.off + */ + off(type: 'status', + callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void; + } + + /** + * Object create by {@link create}. + * + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + interface DistributedObjectV9 { + + /* + * Change object session. + * + * @permission ohos.permission.DISTRIBUTED_DATASYNC. + * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. + * @param {AsyncCallback} callback - the callback of setSessionId. + * @throws {BusinessError} 201 - the permissions check failed. + * @throws {BusinessError} 401 - the parameter check failed. + * @throws {BusinessError} 15400001 - create table failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + setSessionId(sessionId: string, callback: AsyncCallback): void; + setSessionId(callback: AsyncCallback): void; + + /* + * Change object session. + * + * @permission ohos.permission.DISTRIBUTED_DATASYNC. + * @param {string} sessionId - sessionId The sessionId to be joined, if empty, leave all session. + * @returns {Promise} - the promise returned by the function. + * @throws {BusinessError} 201 - the permissions check failed. + * @throws {BusinessError} 401 - the parameter check failed. + * @throws {BusinessError} 15400001 - create table failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 */ - off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void; + setSessionId(sessionId?: string): Promise; + + /** + * On watch of change. + * + * @param {string} type - event type, fixed as' change ', indicates data change. + * @param {Callback<{sessionId: string, fields: Array}>} callback + * indicates the observer of object data changed. + * {string} sessionId - the sessionId of the changed object. + * {Array} fields - changed data. + * sessionId the sessionId of the changed object. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + on(type: 'change', callback: Callback<{ sessionId: string, fields: Array }>): void; /** - * Save object, after save object data successfully, the object data will not release when app existed, and resume data on saved device after app existed - * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data, you should encrypt it + * Off watch of change. + * + * @param {string} type - event type, fixed as' change ', indicates data change. + * @param {Callback<{sessionId: string, fields: Array}>} callback + * indicates the observer of object data changed. + * {string} sessionId - the sessionId of the changed object. + * {Array} fields - changed data. + * callback If not null, off the callback, if undefined, off all callbacks. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array }>): void; + + /** + * On watch of status. + * + * @param {string} type - event type, fixed as' status', indicates the online and offline of the object. + * @param {Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>} callback + * indicates the observer of object status changed. + * {string} sessionId - the sessionId of the changed object. + * {string} networkId - networkId of the changed device. + * {string} status + * 'online' The object became online on the device and data can be synced to the device. + * 'offline' The object became offline on the device and the object can not sync any data. + * 'restored' The object restored success. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + on(type: 'status', + callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void; + + /** + * Off watch of status. * - * the saved data will be released when - * 1. saved after 24h - * 2. app uninstalled - * 3. after resume data success, system will auto delete the saved data + * @param {string} type - event type, fixed as' status', indicates the online and offline of the object. + * @param {Callback<{sessionId: string, networkId: string, status: 'online' | 'offline'}>} callback + * Indicates the observer of object status changed. + * {string} sessionId - the sessionId of the changed object. + * {string} networkId - networkId of the changed device. + * {string} status + * 'online' The object became online on the device and data can be synced to the device. + * 'offline' The object became offline on the device and the object can not sync any data. + * callback If not null, off the callback, if undefined, off all callbacks. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ + off(type: 'status', + callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void; + + /** + * Save object, after save object data successfully, the object data will not release when app existed, + * and resume data on saved device after app existed. + * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data, + * you should encrypt it * - * @param deviceId Indicates the device that will resume the object data + * The saved data will be released when + * 1. saved after 24h. + * 2. app uninstalled. + * 3. after resume data success, system will auto delete the saved data. + * + * @param {string} deviceId - Indicates the device that will resume the object data. + * @param {AsyncCallback} callback + * {SaveSuccessResponse}: the response of save. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 9 */ save(deviceId: string, callback: AsyncCallback): void; + + /** + * Save object, after save object data successfully, the object data will not release when app existed, + * and resume data on saved device after app existed. + * the saved data secure level is S0, it is not safe, can only save public data, if there is privacy data, + * you should encrypt it. + * + * The saved data will be released when + * 1. saved after 24h. + * 2. app uninstalled. + * 3. after resume data success, system will auto delete the saved data. + * + * @param {string} deviceId - Indicates the device that will resume the object data. + * @returns {Promise} {SaveSuccessResponse}: the response of save. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ save(deviceId: string): Promise; /** - * Revoke save object, delete saved object immediately, if object is saved in local device, it will delete saved data on all trusted device + * Revoke save object, delete saved object immediately, if object is saved in local device, + * it will delete saved data on all trusted device. * if object is saved in other device, it will delete data in local device. - * + * + * @param {AsyncCallback} callback + * {RevokeSaveSuccessResponse}: the response of revokeSave. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject * @since 9 */ revokeSave(callback: AsyncCallback): void; + + /** + * Revoke save object, delete saved object immediately, if object is saved in local device, + * it will delete saved data on all trusted device. + * if object is saved in other device, it will delete data in local device. + * + * @returns {Promise} {RevokeSaveSuccessResponse}: the response of revokeSave. + * @throws {BusinessError} 401 - the parameter check failed. + * @syscap SystemCapability.DistributedDataManager.DataObject.DistributedObject + * @since 9 + */ revokeSave(): Promise; } }