• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2021 Huawei Device Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16import { AsyncCallback } from '../basic';
17import { ResultSet } from '../data/rdb/resultSet';
18import { DataAbilityOperation } from './dataAbilityOperation';
19import { DataAbilityResult } from './dataAbilityResult';
20import dataAbility from '../@ohos.data.dataAbility';
21import rdb from '../@ohos.data.rdb';
22
23/**
24 * DataAbilityHelper
25 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
26 *
27 * @since 7
28 * @FAModelOnly
29 */
30export interface DataAbilityHelper {
31    /**
32     * Opens a file in a specified remote path.
33     *
34     * @since 7
35     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
36     * @param uri Indicates the path of the file to open.
37     * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
38     *             (erasing whatever data is currently in the file), "wt" for write access that truncates any existing
39     *             file, "wa" for write-only access to append to any existing data, "rw" for read and write access on
40     *             any existing data, or "rwt" for read and write access that truncates any existing file.
41     * @param callback Indicates the callback when openfile success
42     * @returns Returns the file descriptor.
43     * @FAModelOnly
44     */
45    openFile(uri: string, mode: string, callback: AsyncCallback<number>): void;
46    openFile(uri: string, mode: string): Promise<number>;
47
48    /**
49     * Registers an observer to observe data specified by the given uri.
50     *
51     * @since 7
52     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
53     * @param type dataChange.
54     * @param uri Indicates the path of the data to operate.
55     * @param callback Indicates the callback when dataChange.
56     * @returns -
57     * @FAModelOnly
58     */
59    on(type: 'dataChange', uri: string, callback: AsyncCallback<void>): void;
60
61    /**
62     * Deregisters all observers used for monitoring data specified by the given uri.
63     *
64     * @since 7
65     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
66     * @param type dataChange.
67     * @param uri Indicates the path of the data to operate.
68     * @param callback Indicates the registered callback.
69     * @returns -
70     * @FAModelOnly
71     */
72    off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void;
73
74    /**
75     * Obtains the MIME type of the date specified by the given URI.
76     *
77     * @since 7
78     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
79     * @param uri Indicates the path of the data to operate.
80     * @returns Returns the MIME type that matches the data specified by uri.
81     * @FAModelOnly
82     */
83    getType(uri: string, callback: AsyncCallback<string>): void;
84    getType(uri: string): Promise<string>;
85
86    /**
87     * Obtains the MIME types of files supported.
88     *
89     * @since 7
90     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
91     * @param uri Indicates the path of the files to obtain.
92     * @param mimeTypeFilter Indicates the MIME types of the files to obtain.
93     * @returns Returns the matched MIME types Array.
94     * @FAModelOnly
95     */
96    getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>): void;
97    getFileTypes(uri: string, mimeTypeFilter: string): Promise<Array<string>>;
98
99    /**
100     * Converts the given uri that refers to the Data ability into a normalized uri.
101     *
102     * @since 7
103     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
104     * @param uri Indicates the uri object to normalize.
105     * @returns Returns the normalized uri object if the Data ability supports URI normalization or null.
106     * @FAModelOnly
107     */
108    normalizeUri(uri: string, callback: AsyncCallback<string>): void;
109    normalizeUri(uri: string): Promise<string>;
110
111    /**
112     * Converts the given normalized uri generated by normalizeUri(uri) into a denormalized one.
113     *
114     * @since 7
115     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
116     * @param uri Indicates the uri object to normalize.
117     * @returns Returns the denormalized uri object if the denormalization is successful.
118     * @FAModelOnly
119     */
120    denormalizeUri(uri: string, callback: AsyncCallback<string>): void;
121    denormalizeUri(uri: string): Promise<string>;
122
123    /**
124     * Notifies the registered observers of a change to the data resource specified by uri.
125     *
126     * @since 7
127     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
128     * @param uri Indicates the path of the data to operate.
129     * @returns -
130     * @FAModelOnly
131     */
132    notifyChange(uri: string, callback: AsyncCallback<void>): void;
133    notifyChange(uri: string): Promise<void>;
134
135    /**
136     * Inserts a single data record into the database.
137     *
138     * @since 7
139     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
140     * @param uri Indicates the path of the data to insert.
141     * @param valuesBucket Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
142     * @returns Returns the index of the inserted data record.
143     * @FAModelOnly
144     */
145    insert(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;
146    insert(uri: string, valuesBucket: rdb.ValuesBucket): Promise<number>;
147
148    /**
149     * Inserts multiple data records into the database.
150     *
151     * @since 7
152     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
153     * @param uri Indicates the path of the data to batchInsert.
154     * @param valuesBuckets Indicates the data records to insert.
155     * @returns Returns the number of data records inserted.
156     * @FAModelOnly
157     */
158    batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>, callback: AsyncCallback<number>): void;
159    batchInsert(uri: string, valuesBuckets: Array<rdb.ValuesBucket>): Promise<number>;
160
161    /**
162     * Deletes one or more data records from the database.
163     *
164     * @since 7
165     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
166     * @param uri Indicates the path of the data to delete.
167     * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
168     * @returns Returns the number of data records deleted.
169     * @FAModelOnly
170     */
171    delete(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;
172    delete(uri: string, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;
173    delete(uri: string, callback: AsyncCallback<number>): void;
174
175    /**
176     * Updates data records in the database.
177     *
178     * @since 7
179     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
180     * @param uri Indicates the path of data to update.
181     * @param valuesBucket Indicates the data to update.
182     * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
183     * @returns Returns the number of data records updated.
184     * @FAModelOnly
185     */
186    update(uri: string, valuesBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<number>): void;
187    update(uri: string, valuesBucket: rdb.ValuesBucket, predicates?: dataAbility.DataAbilityPredicates): Promise<number>;
188    update(uri: string, valuesBucket: rdb.ValuesBucket, callback: AsyncCallback<number>): void;
189
190    /**
191     * Queries data in the database.
192     *
193     * @since 7
194     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
195     * @param uri Indicates the path of data to query.
196     * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
197     * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
198     * @returns Returns the query result {@link ResultSet}.
199     * @FAModelOnly
200     */
201    query(uri: string, columns: Array<string>, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;
202    query(uri: string, callback: AsyncCallback<ResultSet>): void;
203    query(uri: string, columns: Array<string>, callback: AsyncCallback<ResultSet>): void;
204    query(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;
205    query(uri: string, columns?: Array<string>, predicates?: dataAbility.DataAbilityPredicates): Promise<ResultSet>;
206
207    /**
208     * Calls the extended API of the DataAbility. This method uses a promise to return the result.
209     *
210     * @since 7
211     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
212     * @param uri URI of the Data ability. Example: "dataability:///com.example.xxx.xxxx"
213     * @param method Indicates the method to call.
214     * @param arg Indicates the parameter of the String type.
215     * @param extras Indicates the parameter of the PacMap type.
216     * If a custom Sequenceable object is put in the PacMap object and will be transferred across processes,
217     * you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
218     * If the PacMap object is to be transferred to a non-OHOS process,
219     * values of primitive types are supported, but not custom Sequenceable objects.
220     * @returns Returns the query result {@link PacMap}.
221     * @FAModelOnly
222     */
223    call(uri: string, method: string, arg: string, extras: PacMap, callback: AsyncCallback<PacMap>): void;
224    call(uri: string, method: string, arg: string, extras: PacMap): Promise<PacMap>;
225
226    /**
227     * Queries data in the database.
228     *
229     * @since 7
230     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
231     * @param uri Indicates the path of data to query.
232     * @param operations Indicates the data operation list, which can contain multiple operations on the database.
233     * @returns Returns the result of each operation, in array {@link DataAbilityResult}.
234     */
235     executeBatch(uri: string, operations: Array<DataAbilityOperation>, callback: AsyncCallback<Array<DataAbilityResult>>): void;
236     executeBatch(uri: string, operations: Array<DataAbilityOperation>): Promise<Array<DataAbilityResult>>;
237}
238
239/**
240 * Defines a PacMap object for storing a series of values.
241 * @since 7
242 * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
243 * @FAModelOnly
244 */
245 export interface PacMap {
246
247    /**
248     * Indicates the parameter of the PacMap type.
249     * If a custom Sequenceable object is put in the PacMap object and will be transferred across processes,
250     * you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
251     * If the PacMap object is to be transferred to a non-OHOS process,
252     * values of primitive types are supported, but not custom Sequenceable objects.
253     * @since 7
254     * @syscap SystemCapability.Ability.AbilityRuntime.FAModel
255     * @FAModelOnly
256     */
257     [key: string]: number | string | boolean | Array<string | number | boolean> | null;
258}
259