From 749fd556c09479ab75997dd137f5554709afff56 Mon Sep 17 00:00:00 2001 From: lxt Date: Thu, 28 Aug 2025 09:41:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:0728=20datashare=20ArkTS1.2=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=8A=A5=E9=94=99=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lxt --- ...application.DataShareExtensionAbility.d.ts | 218 ++++++++++++++++-- 1 file changed, 199 insertions(+), 19 deletions(-) diff --git a/api/@ohos.application.DataShareExtensionAbility.d.ts b/api/@ohos.application.DataShareExtensionAbility.d.ts index 177444235a..fe778a801c 100644 --- a/api/@ohos.application.DataShareExtensionAbility.d.ts +++ b/api/@ohos.application.DataShareExtensionAbility.d.ts @@ -26,16 +26,126 @@ import { ValuesBucket } from './@ohos.data.ValuesBucket'; import dataShare from './@ohos.data.dataShare'; /** - * Struct for a batch update operation. - * - * @typedef { dataShare.UpdateOperation } - * @syscap SystemCapability.DistributedDataManager.DataShare.Provider - * @systemapi - * @stagemodelonly - * @since 12 - */ + * Struct for a batch update operation. + * + * @typedef { dataShare.UpdateOperation } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @stagemodelonly + * @since 12 + */ type UpdateOperation = dataShare.UpdateOperation; +/** + * Called back when a datashare extension ability is started for initialization. + * + * @typedef { function } + * @param { Want } want - Indicates connection information about the datashare extension ability. + * @param { AsyncCallback } callback - callback function, no return value. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type OnCreateFn = (want: Want, callback: AsyncCallback) => void; + +/** + * Inserts a data record into the database. This method should be implemented by a data share. + * + * @typedef { function } + * @param { string } uri - Indicates the position where the data is to insert. + * @param { ValuesBucket } valueBucket - Indicates the data to insert. + * @param { AsyncCallback } callback - Returns the index of the newly inserted data record. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type InsertFn = (uri: string, valueBucket: ValuesBucket, callback: AsyncCallback) => void; + +/** + * Updates one or more data records in the database. This method should be implemented by a data share. + * + * @typedef { function } + * @param { string } uri - Indicates the database table storing the data to update. + * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is + * null, all data records will be updated by default. + * @param { ValuesBucket } valueBucket - Indicates the data to update. This parameter can be null. + * @param { AsyncCallback } callback - Returns the number of data records updated. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type UpdateFn = ( + uri: string, + predicates: dataSharePredicates.DataSharePredicates, + valueBucket: ValuesBucket, + callback: AsyncCallback +) => void; + +/** + * Deletes one or more data records. This method should be implemented by a data share. + * + * @typedef { function } + * @param { string } uri - Indicates the database table storing the data to delete. + * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is + * null, all data records will be deleted by default. + * @param { AsyncCallback } callback - Returns the number of data records deleted. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type DeleteFn = ( + uri: string, + predicates: dataSharePredicates.DataSharePredicates, + callback: AsyncCallback +) => void; + +/** + * Queries one or more data records in the database. This method should be implemented by a data share. + * Only RDB and distributed KVDB resultsets are supported. The current version does not support custom resultsets. + * + * @typedef { function } + * @param { string } uri - Indicates the database table storing the data to query. + * @param { dataSharePredicates.DataSharePredicates } predicates - Indicates filter criteria. If this parameter is + * null, all data records will be queried by default. + * @param { Array } columns - Indicates the columns to be queried, in array, for example, {"name","age"}. + * You should define the processing logic when this parameter is null. + * @param { AsyncCallback } callback - Returns the queried data, only support result set of rdb or kvstore. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type QueryFn = ( + uri: string, + predicates: dataSharePredicates.DataSharePredicates, + columns: Array, + callback: AsyncCallback +) => void; + +/** + * Inserts multiple data records into the database. This method should be implemented by a data share. + * + * @typedef { function } + * @param { string } uri - Indicates the position where the data is to insert. + * @param { Array } valueBuckets - Indicates the data to insert. + * @param { AsyncCallback } callback - Returns the number of data records inserted. + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ +type BatchInsertFn = (uri: string, valueBuckets: Array, callback: AsyncCallback) => void; + /** * This module provides data sharing and expansion capabilities. * @@ -45,7 +155,7 @@ type UpdateOperation = dataShare.UpdateOperation; * @since arkts {'1.1':'9', '1.2':'20'} * @arkts 1.1&1.2 */ -export default class DataShareExtensionAbility { +declare class DataShareExtensionAbility { /** * Indicates datashare extension ability context. * @@ -66,11 +176,22 @@ export default class DataShareExtensionAbility { * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @systemapi * @StageModelOnly - * @since arkts {'1.1':'9', '1.2':'20'} - * @arkts 1.1&1.2 + * @since 9 */ onCreate?(want: Want, callback: AsyncCallback): void; + /** + * Called back when a datashare extension ability is started for initialization. + * + * @type { ?OnCreateFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + onCreate?: OnCreateFn; + /** * Inserts a data record into the database. This method should be implemented by a data share. * @@ -84,6 +205,18 @@ export default class DataShareExtensionAbility { */ insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback): void; + /** + * Inserts a data record into the database. This method should be implemented by a data share. + * + * @type { ?InsertFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + insert?: InsertFn; + /** * Updates one or more data records in the database. This method should be implemented by a data share. * @@ -95,8 +228,7 @@ export default class DataShareExtensionAbility { * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @systemapi * @StageModelOnly - * @since arkts {'1.1':'9', '1.2':'20'} - * @arkts 1.1&1.2 + * @since 9 */ update?( uri: string, @@ -105,6 +237,18 @@ export default class DataShareExtensionAbility { callback: AsyncCallback ): void; + /** + * Updates one or more data records in the database. This method should be implemented by a data share. + * + * @type { ?UpdateFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + update?: UpdateFn; + /** * Updates data records in the database. * @@ -130,11 +274,22 @@ export default class DataShareExtensionAbility { * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @systemapi * @StageModelOnly - * @since arkts {'1.1':'9', '1.2':'20'} - * @arkts 1.1&1.2 + * @since 9 */ delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback): void; + /** + * Deletes one or more data records. This method should be implemented by a data share. + * + * @type { ?DeleteFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + delete?: DeleteFn; + /** * Queries one or more data records in the database. This method should be implemented by a data share. * Only RDB and distributed KVDB resultsets are supported. The current version does not support custom resultsets. @@ -148,8 +303,7 @@ export default class DataShareExtensionAbility { * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @systemapi * @StageModelOnly - * @since arkts {'1.1':'9', '1.2':'20'} - * @arkts 1.1&1.2 + * @since 9 */ query?( uri: string, @@ -158,6 +312,19 @@ export default class DataShareExtensionAbility { callback: AsyncCallback ): void; + /** + * Queries one or more data records in the database. This method should be implemented by a data share. + * Only RDB and distributed KVDB resultsets are supported. The current version does not support custom resultsets. + * + * @type { ?QueryFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + query?: QueryFn; + /** * Inserts multiple data records into the database. This method should be implemented by a data share. * @@ -167,11 +334,22 @@ export default class DataShareExtensionAbility { * @syscap SystemCapability.DistributedDataManager.DataShare.Provider * @systemapi * @StageModelOnly - * @since arkts {'1.1':'9', '1.2':'20'} - * @arkts 1.1&1.2 + * @since 9 */ batchInsert?(uri: string, valueBuckets: Array, callback: AsyncCallback): void; + /** + * Inserts multiple data records into the database. This method should be implemented by a data share. + * + * @type { ?BatchInsertFn } + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi + * @StageModelOnly + * @since 20 + * @arkts 1.2 + */ + batchInsert?: BatchInsertFn; + /** * Converts the given {@code uri} that refer to the data share into a normalized URI. A normalized URI can be * used across devices, persisted, backed up, and restored. It can refer to the same item in the data share @@ -202,3 +380,5 @@ export default class DataShareExtensionAbility { */ denormalizeUri?(uri: string, callback: AsyncCallback): void; } + +export default DataShareExtensionAbility; -- Gitee