From 4dcafe07f4e54355e6816d1c73503a4bc6263994 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Sat, 15 Jul 2023 14:03:22 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../reference/apis/js-apis-data-dataShare.md | 73 +++++++------------ .../changelogs-datashare.md | 39 ++++++++++ 2 files changed, 66 insertions(+), 46 deletions(-) create mode 100644 en/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md diff --git a/en/application-dev/reference/apis/js-apis-data-dataShare.md b/en/application-dev/reference/apis/js-apis-data-dataShare.md index 991aa68327..fcb1e22348 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/en/application-dev/reference/apis/js-apis-data-dataShare.md @@ -4,11 +4,11 @@ The **DataShare** module allows an application to manage its own data and share > **NOTE** > -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > -> The APIs provided by this module are system APIs. -> -> The APIs of this module can be used only in the stage model. +> +>- The APIs provided by this module are system APIs and can be used only in the stage model. +> ## Modules to Import @@ -34,7 +34,7 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | +| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of the application. | | uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect. | | callback | AsyncCallback<[DataShareHelper](#datasharehelper)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the **DataShareHelper** instance created. Otherwise, **err** is an error object.| @@ -82,8 +82,8 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | -| uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect. | +| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of the application. | +| uri | string | Yes | URI of the server application to connect. | | options | [DataShareHelperOptions](#datasharehelperoptions10)| Yes | Configuration specifying whether [DataShareHelper](#datasharehelper) is in proxy mode.| | callback | AsyncCallback<[DataShareHelper](#datasharehelper)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the **DataShareHelper** instance created. Otherwise, **err** is an error object.| @@ -133,8 +133,8 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------- | ---- | ------------------------------ | | context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | -| uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect.| -| options | [DataShareHelperOptions](#datasharehelperoptions10) | No| Optional configuration of the **DataShareHelper** instance. This parameter is supported from API version 10. If it is not set, [DataShareHelper](#datasharehelper) is not in proxy mode.| +| uri | string | Yes | URI of the server application to connect. | +| options | [DataShareHelperOptions](#datasharehelperoptions10) | No| Configuration of the **DataShareHelper** instance. This parameter is supported from API version 10. If it is not set, [DataShareHelper](#datasharehelper) is not in proxy mode. | **Return value** @@ -177,7 +177,7 @@ Defines whether [DataShareHelper](#datasharehelper) is in proxy mode. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| isProxy | boolean | No| Whether the [DataShareHelper](#datasharehelper) is in proxy mode. The default value is **false**.
If the value is **true**, the [DataShareHelper](#datasharehelper) to be created is in proxy mode, and all operations will not open the data provider application unless the database does not exist. If the database does not exist, [createDataShareHelper] (#datasharecreatedatasharehelper10) will start the data provider to create a database.| +| isProxy | boolean | No| Whether the [DataShareHelper](#datasharehelper) is in proxy mode.
The default value is **false**.
If the value is **true**, the [DataShareHelper](#datasharehelper) to be created is in proxy mode, and all operations will not open the data provider application unless the database does not exist. If the database does not exist, [createDataShareHelper](#datasharecreatedatasharehelper10) will start the data provider to create a database. | ## TemplateId10+ @@ -192,14 +192,14 @@ Defines the **TemplateId** struct. **TemplateId** is generated by [**addTemplate ## PublishedItem10+ -Defines the type of the data to publish. +Defines the data to publish. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data to publish.| -| data | string \| [Ashmem](js-apis-rpc.md#ashmem8) | Yes| Data to publish. If the data volume is large, use **Ashmem**.| +| data | string \| ArrayBuffer | Yes| Data to publish. If the data to publish exceeds 20 KB, you are advised to use **data** of the ArrayBuffer type. | | subscriberId | string | Yes| Subscriber ID.| ## RdbDataChangeNode10+ @@ -245,7 +245,7 @@ Defines the result of the operation for subscribing to or unsubscribing from the | Name| Type| Mandatory| Description| | -------- | -------- | ----- | -------- | | key | string | Yes| Key of the operation result.| -| result | number | Yes| Operation result. | +| result | number | Yes| Operation result. If the operation is successful, **0** is returned; otherwise, an error code is returned. | ## DataShareHelper Provides a **DataShareHelper** instance to access or manage data on the server. Before calling an API provided by **DataShareHelper**, you must create a **DataShareHelper** instance using [createDataShareHelper](#datasharecreatedatasharehelper). @@ -393,7 +393,7 @@ Subscribes to the changes of the data corresponding to the specified URI and tem | Name | Type | Mandatory| Description | | -------- | ----------------------------------| ---- | ------------------------------------------------------------ | -| type | string | Yes | Type of the event to subscribe to. The value is **rdbDataChange**, which indicates the RDB data change event. | +| type | string | Yes | Type of the event to subscribe to. The value is **rdbDataChange**, which indicates the RDB data change event. If **type** is any other value, there is no response to this API. | | uris | Array<string> | Yes | URIs of the data to operate. | | templateId | [TemplateId](#templateid10) | Yes | ID of the template that triggers the callback. | | callback | AsyncCallback<[RdbDataChangeNode](#rdbdatachangenode10)> | Yes | Callback invoked to return the result when the specified data changes. The **err** is **undefined**, and **node** is the new data. Otherwise, this callback is not triggered or **err** is an error object. | @@ -478,18 +478,15 @@ Subscribes to the changes of the published data. **Example** ```ts -import rpc from '@ohos.rpc'; - function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { console.info("onPublishCallback node bundleName " + JSON.stringify(node.bundleName)); console.info("onPublishCallback node data size" + node.data.length); for (let i = 0; i < node.data.length; i++) { console.info("onPublishCallback node " + typeof node.data[i].data); if (typeof node.data[i].data != 'string') { - let ash:rpc.Ashmem = node.data[i].data; - ash.mapReadonlyAshmem(); - console.info("onPublishCallback " + JSON.stringify(ash.readAshmem(ash.getAshmemSize()/4, 0))); - ash.closeAshmem(); + let array:ArrayBuffer = node.data[i].data; + let data:Uint8Array = new Uint8Array(array); + console.info("onPublishCallback " + i + " " + JSON.stringify(data)); } console.info("onPublishCallback data " + i + " " + JSON.stringify(node.data[i])); } @@ -561,29 +558,13 @@ For details about the error codes, see [DataShare Error Codes](../errorcodes/err **Example** ```ts -import rpc from '@ohos.rpc'; - -let ashmem = null; -let subscriberId = '11'; +let arrayBuffer = new ArrayBuffer(1); let version = 1; -let data : Array = [ - {key:"city", subscriberId:"11", data:"xian"}, - {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, - {key:"empty", subscriberId:"11", data:"nobody sub"}]; -let nums:number[] = [1,2,3]; +let data : Array = [{key:"key2", subscriberId:"11", data:arrayBuffer}]; function publishCallback(err, result: Array) { console.info("publishCallback " + JSON.stringify(result)); - ashmem.closeAshmem(); } try { - ashmem = rpc.Ashmem.create("ashmem", (nums.length) * 4); - ashmem.mapReadWriteAshmem(); - ashmem.writeAshmem(nums, nums.length, 0); - data.push({ - "key" : "key2", - "data" : ashmem, - "subscriberId" : "11", - }); console.info("data length is:", data.length); dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); } catch (e) { @@ -1066,7 +1047,7 @@ try { batchInsert(uri: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void -Batch inserts data into the database. This API uses an asynchronous callback to return the result. +Batch inserts data into the database. This API uses an asynchronous callback to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1102,7 +1083,7 @@ try { batchInsert(uri: string, values: Array<ValuesBucket>): Promise<number> -Batch inserts data into the database. This API uses a promise to return the result. +Batch inserts data into the database. This API uses a promise to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1141,7 +1122,7 @@ try { normalizeUri(uri: string, callback: AsyncCallback<string>): void -Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the local device, but the normalized URI can be used across devices. This API uses an asynchronous callback to return the result. +Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the local device, but the normalized URI can be used across devices. This API uses an asynchronous callback to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1169,7 +1150,7 @@ dataShareHelper.normalizeUri(uri, (err, data) => { normalizeUri(uri: string): Promise<string> -Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the local device, but the normalized URI can be used across devices. This API uses a promise to return the result. +Normalizes a **DataShare** URI. The **DataShare** URI can be used only by the local device, but the normalized URI can be used across devices. This API uses a promise to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1200,7 +1181,7 @@ dataShareHelper.normalizeUri(uri).then((data) => { denormalizeUri(uri: string, callback: AsyncCallback<string>): void -Denormalizes a URI. This API uses an asynchronous callback to return the result. +Denormalizes a URI. This API uses an asynchronous callback to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1228,7 +1209,7 @@ dataShareHelper.denormalizeUri(uri, (err, data) => { denormalizeUri(uri: string): Promise<string> -Denormalizes a URI. This API uses a promise to return the result. +Denormalizes a URI. This API uses a promise to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1259,7 +1240,7 @@ dataShareHelper.denormalizeUri(uri).then((data) => { notifyChange(uri: string, callback: AsyncCallback<void>): void -Notifies the registered observer of data changes. This API uses an asynchronous callback to return the result. +Notifies the registered observer of data changes. This API uses an asynchronous callback to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer @@ -1283,7 +1264,7 @@ dataShareHelper.notifyChange(uri, () => { notifyChange(uri: string): Promise<void> -Notifies the registered observer of data changes. This API uses a promise to return the result. +Notifies the registered observer of data changes. This API uses a promise to return the result. Silent access is not supported currently. **System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer diff --git a/en/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md b/en/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md new file mode 100644 index 0000000000..7bb349388e --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md @@ -0,0 +1,39 @@ +# Distributed Data Management Subsystem Changelog + +## cl.datashare.1 Change of the data Type in PublishedItem from Ashmem to ArrayBuffer + +**Change Impact** + +Changed the type of **data** in **PublishedItem** from Ashmem to ArrayBuffer. + +## PublishedItem10+ + +Defines the data to publish. + +**System capability**: SystemCapability.DistributedDataManager.DataShare.Consumer + +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| key | string | Yes| Key of the data to publish.| +| data | string \| ArrayBuffer | Yes| Data to publish. If a large volume of data is to be published, use **data** of the ArrayBuffer type. | +| subscriberId | string | Yes| Subscriber ID.| + +**Adaptation Guide** +The sample code is as follows: + +**Example** + +```ts +let arrayBuffer = new ArrayBuffer(1); +let version = 1; +let data : Array = [{key:"key2", subscriberId:"11", data:arrayBuffer}]; +function publishCallback(err, result: Array) { + console.info("publishCallback " + JSON.stringify(result)); +} +try { + console.info("data length is:", data.length); + dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); +} catch (e) { + console.error("publish error " + JSON.stringify(e)); +} +``` -- GitLab