• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16/**
17 * @file
18 * @kit ArkData
19 */
20
21import Context from './application/BaseContext';
22
23/**
24 * Provides methods for graphStore create and delete.
25 *
26 * @namespace graphStore
27 * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
28 * @systemapi
29 * @since 18
30 */
31declare namespace graphStore {
32  /**
33   * Indicates possible value types
34   *
35   * @typedef { null | number | string } ValueType
36   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
37   * @systemapi
38   * @since 18
39   */
40  type ValueType = null | number | string;
41
42  /**
43   * Describes the security level.
44   *
45   * @enum { number }
46   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
47   * @systemapi
48   * @since 18
49   */
50  enum SecurityLevel {
51    /**
52     * S1: means the db is low level security
53     * There are some low impact, when the data is leaked.
54     *
55     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
56     * @systemapi
57     * @since 18
58     */
59    S1 = 1,
60    /**
61     * S2: means the db is middle level security
62     * There are some major impact, when the data is leaked.
63     *
64     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
65     * @systemapi
66     * @since 18
67     */
68    S2 = 2,
69    /**
70     * S3: means the db is high level security
71     * There are some severity impact, when the data is leaked.
72     *
73     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
74     * @systemapi
75     * @since 18
76     */
77    S3 = 3,
78    /**
79     * S4: means the db is critical level security
80     * There are some critical impact, when the data is leaked.
81     *
82     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
83     * @systemapi
84     * @since 18
85     */
86    S4 = 4
87  }
88
89  /**
90   * Manages graph database configurations.
91   *
92   * @interface storeConfig
93   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
94   * @systemapi
95   * @since 18
96   */
97  interface StoreConfig {
98    /**
99     * The database name.
100     *
101     * @type { string }
102     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
103     * @systemapi
104     * @since 18
105     */
106    name: string;
107    /**
108     * Specifies the security level of the database.
109     *
110     * @type { SecurityLevel }
111     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
112     * @systemapi
113     * @since 18
114     */
115    securityLevel: SecurityLevel;
116    /**
117     * Specifies whether the database is encrypted.
118     *
119     * @type { ?boolean }
120     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
121     * @systemapi
122     * @since 18
123     */
124    encrypt?: boolean;
125  }
126
127  /**
128   * Defines Vertex Type.
129   *
130   * @interface Vertex
131   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
132   * @systemapi
133   * @since 18
134   */
135  interface Vertex {
136    /**
137     * The Vertex element identifier.
138     *
139     * @type { string }
140     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
141     * @systemapi
142     * @since 18
143     */
144    vid: string;
145    /**
146     * Labels of the vertex.
147     *
148     * @type { Array<string> }
149     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
150     * @systemapi
151     * @since 18
152     */
153    labels: Array<string>;
154    /**
155     * Properties of the vertex.
156     *
157     * @type { Record<string, ValueType> }
158     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
159     * @systemapi
160     * @since 18
161     */
162    properties: Record<string, ValueType>;
163  }
164
165  /**
166   * Defines Edge Type.
167   *
168   * @interface Edge
169   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
170   * @systemapi
171   * @since 18
172   */
173  interface Edge {
174    /**
175     * The Edge element identifier.
176     *
177     * @type { string }
178     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
179     * @systemapi
180     * @since 18
181     */
182    eid: string;
183    /**
184     * Type of the edge.
185     *
186     * @type { string }
187     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
188     * @systemapi
189     * @since 18
190     */
191    type: string;
192    /**
193     * The Start Vertex element identifier.
194     *
195     * @type { string }
196     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
197     * @systemapi
198     * @since 18
199     */
200    startVid: string;
201    /**
202     * The End Vertex element identifier.
203     *
204     * @type { string }
205     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
206     * @systemapi
207     * @since 18
208     */
209    endVid: string;
210    /**
211     * Properties of the edge.
212     *
213     * @type { Record<string, ValueType> }
214     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
215     * @systemapi
216     * @since 18
217     */
218    properties: Record<string, ValueType>;
219  }
220
221  /**
222   * Defines PathSegment Type.
223   *
224   * @interface PathSegment
225   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
226   * @systemapi
227   * @since 18
228   */
229  interface PathSegment {
230    /**
231     * Start vertex.
232     *
233     * @type { Vertex }
234     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
235     * @systemapi
236     * @since 18
237     */
238    start: Vertex;
239    /**
240     * End vertex.
241     *
242     * @type { Vertex }
243     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
244     * @systemapi
245     * @since 18
246     */
247    end: Vertex;
248    /**
249     * The edge between start vertex and end vertex.
250     *
251     * @type { Edge }
252     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
253     * @systemapi
254     * @since 18
255     */
256    edge: Edge;
257  }
258
259  /**
260   * Defines Path Type.
261   *
262   * @interface Path
263   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
264   * @systemapi
265   * @since 18
266   */
267  interface Path {
268    /**
269     * Start vertex.
270     *
271     * @type { Vertex }
272     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
273     * @systemapi
274     * @since 18
275     */
276    start: Vertex;
277    /**
278     * End vertex.
279     *
280     * @type { Vertex }
281     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
282     * @systemapi
283     * @since 18
284     */
285    end: Vertex;
286    /**
287     * Length of segments.
288     *
289     * @type { number }
290     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
291     * @systemapi
292     * @since 18
293     */
294    length: number;
295    /**
296     * Segments in the path.
297     *
298     * @type { Array<PathSegment> }
299     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
300     * @systemapi
301     * @since 18
302     */
303    segments: Array<PathSegment>;
304  }
305
306  /**
307   * The GQL statement execution result.
308   *
309   * @interface Result
310   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
311   * @systemapi
312   * @since 18
313   */
314  interface Result {
315    /**
316     * The data records of querying the database.
317     *
318     * @type { ?Array<Record<string, Object>> }
319     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
320     * @systemapi
321     * @since 18
322     */
323    records?: Array<Record<string, Object>>;
324  }
325
326  /**
327   * Provides transactional methods for managing the graph database.
328   *
329   * @interface Transaction
330   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
331   * @systemapi
332   * @since 18
333   */
334  interface Transaction {
335    /**
336     * Execute a query procedure.
337     *
338     * @param { string } gql - Indicates the GQL statement to execute.
339     * @returns { Promise<Result> } The {@link Result} object if the operation is successful.
340     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
341     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
342     * <br>2. Incorrect parameter types.
343     * @throws { BusinessError } 31300000 - Inner error.
344     * @throws { BusinessError } 31300001 - Database corrupted.
345     * @throws { BusinessError } 31300002 - Already closed.
346     * @throws { BusinessError } 31300003 - The database is busy.
347     * @throws { BusinessError } 31300004 - The database is out of memory.
348     * @throws { BusinessError } 31300005 - The database is full.
349     * @throws { BusinessError } 31300006 - A duplicate graph name, vertex or edge type, or vertex or edge property name exists.
350     * @throws { BusinessError } 31300007 - The graph name, vertex or edge type, or vertex or edge property is not defined.
351     * @throws { BusinessError } 31300008 - The graph name, vertex or edge type, or vertex or edge property name does not conform to constraints.
352     * @throws { BusinessError } 31300009 - The GQL statement syntax error.
353     * @throws { BusinessError } 31300010 - The GQL statement semantic error.
354     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
355     * @systemapi
356     * @since 18
357     */
358    read(gql: string): Promise<Result>;
359
360    /**
361     * Execute a data-modifying procedure.
362     *
363     * @param { string } gql - Indicates the GQL statement to execute.
364     * @returns { Promise<Result> } The {@link Result} object if the operation is successful.
365     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
366     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
367     * <br>2. Incorrect parameter types.
368     * @throws { BusinessError } 31300000 - Inner error.
369     * @throws { BusinessError } 31300001 - Database corrupted.
370     * @throws { BusinessError } 31300002 - Already closed.
371     * @throws { BusinessError } 31300003 - The database is busy.
372     * @throws { BusinessError } 31300004 - The database is out of memory.
373     * @throws { BusinessError } 31300005 - The database is full.
374     * @throws { BusinessError } 31300006 - A duplicate graph name, vertex or edge type, or vertex or edge property name exists.
375     * @throws { BusinessError } 31300007 - The graph name, vertex or edge type, or vertex or edge property is not defined.
376     * @throws { BusinessError } 31300008 - The graph name, vertex or edge type, or vertex or edge property name does not conform to constraints.
377     * @throws { BusinessError } 31300009 - The GQL statement syntax error.
378     * @throws { BusinessError } 31300010 - The GQL statement semantic error.
379     * @throws { BusinessError } 31300012 - The number of graph names, vertex or edge types, or vertex or edge properties exceeds the limit.
380     * @throws { BusinessError } 31300013 - A conflicting constraint already exists.
381     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
382     * @systemapi
383     * @since 18
384     */
385    write(gql: string): Promise<Result>;
386
387    /**
388     * Commit the transaction.
389     *
390     * @returns { Promise<void> } The Promise used to return the result.
391     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
392     * @throws { BusinessError } 31300000 - Inner error.
393     * @throws { BusinessError } 31300001 - Database corrupted.
394     * @throws { BusinessError } 31300002 - Already closed.
395     * @throws { BusinessError } 31300003 - The database is busy.
396     * @throws { BusinessError } 31300004 - The database is out of memory.
397     * @throws { BusinessError } 31300005 - The database is full.
398     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
399     * @systemapi
400     * @since 18
401     */
402    commit(): Promise<void>;
403
404    /**
405     * Rollback the transaction.
406     *
407     * @returns { Promise<void> } The Promise used to return the result.
408     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
409     * @throws { BusinessError } 31300000 - Inner error.
410     * @throws { BusinessError } 31300001 - Database corrupted.
411     * @throws { BusinessError } 31300002 - Already closed.
412     * @throws { BusinessError } 31300003 - The database is busy.
413     * @throws { BusinessError } 31300004 - The database is out of memory.
414     * @throws { BusinessError } 31300005 - The database is full.
415     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
416     * @systemapi
417     * @since 18
418     */
419    rollback(): Promise<void>;
420  }
421
422  /**
423   * Provides methods for managing the graph database.
424   *
425   * @interface GraphStore
426   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
427   * @systemapi
428   * @since 18
429   */
430  interface GraphStore {
431    /**
432     * Execute a query procedure.
433     *
434     * @param { string } gql - Indicates the GQL statement to execute.
435     * @returns { Promise<Result> } The {@link Result} object if the operation is successful.
436     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
437     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
438     * <br>2. Incorrect parameter types.
439     * @throws { BusinessError } 31300000 - Inner error.
440     * @throws { BusinessError } 31300001 - Database corrupted.
441     * @throws { BusinessError } 31300002 - Already closed.
442     * @throws { BusinessError } 31300003 - The database is busy.
443     * @throws { BusinessError } 31300004 - The database is out of memory.
444     * @throws { BusinessError } 31300005 - The database is full.
445     * @throws { BusinessError } 31300006 - A duplicate graph name, vertex or edge type, or vertex or edge property name exists.
446     * @throws { BusinessError } 31300007 - The graph name, vertex or edge type, or vertex or edge property is not defined.
447     * @throws { BusinessError } 31300008 - The graph name, vertex or edge type, or vertex or edge property name does not conform to constraints.
448     * @throws { BusinessError } 31300009 - The GQL statement syntax error.
449     * @throws { BusinessError } 31300010 - The GQL statement semantic error.
450     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
451     * @systemapi
452     * @since 18
453     */
454    read(gql: string): Promise<Result>;
455
456    /**
457     * Execute a data-modifying or catalog-modifying procedure.
458     *
459     * @param { string } gql - Indicates the GQL statement to execute.
460     * @returns { Promise<Result> } The {@link Result} object if the operation is successful.
461     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
462     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
463     * <br>2. Incorrect parameter types.
464     * @throws { BusinessError } 31300000 - Inner error.
465     * @throws { BusinessError } 31300001 - Database corrupted.
466     * @throws { BusinessError } 31300002 - Already closed.
467     * @throws { BusinessError } 31300003 - The database is busy.
468     * @throws { BusinessError } 31300004 - The database is out of memory.
469     * @throws { BusinessError } 31300005 - The database is full.
470     * @throws { BusinessError } 31300006 - A duplicate graph name, vertex or edge type, or vertex or edge property name exists.
471     * @throws { BusinessError } 31300007 - The graph name, vertex or edge type, or vertex or edge property is not defined.
472     * @throws { BusinessError } 31300008 - The graph name, vertex or edge type, or vertex or edge property name does not conform to constraints.
473     * @throws { BusinessError } 31300009 - The GQL statement syntax error.
474     * @throws { BusinessError } 31300010 - The GQL statement semantic error.
475     * @throws { BusinessError } 31300012 - The number of graph names, vertex or edge types, or vertex or edge properties exceeds the limit.
476     * @throws { BusinessError } 31300013 - A conflicting constraint already exists.
477     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
478     * @systemapi
479     * @since 18
480     */
481    write(gql: string): Promise<Result>;
482
483    /**
484     * Create a transaction instance.
485     *
486     * @returns { Promise<Transaction> } The {@link Transaction} object if the operation is successful.
487     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
488     * @throws { BusinessError } 31300000 - Inner error.
489     * @throws { BusinessError } 31300001 - Database corrupted.
490     * @throws { BusinessError } 31300002 - Already closed.
491     * @throws { BusinessError } 31300003 - The database is busy.
492     * @throws { BusinessError } 31300004 - The database is out of memory.
493     * @throws { BusinessError } 31300005 - The database is full.
494     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
495     * @systemapi
496     * @since 18
497     */
498    createTransaction(): Promise<Transaction>;
499
500    /**
501     * Close the GraphStore and opened transactions will be rollback.
502     * @returns { Promise<void> } The Promise returned by the function.
503     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
504     * @throws { BusinessError } 31300000 - Inner error.
505     * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
506     * @systemapi
507     * @since 18
508     */
509    close(): Promise<void>;
510  }
511
512  /**
513   * Obtains a graph store.
514   * You can set parameters of the graph store as required. In general, this method is recommended
515   * to obtain a graph store.
516   *
517   * @param { Context } context - Indicates the context of an application or ability.
518   * @param { StoreConfig } config - Indicates the {@link StoreConfig} configuration of the database related to this graph store.
519   * @returns { Promise<GraphStore> } The graph store {@link GraphStore}.
520   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
521   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
522   * <br>2. Incorrect parameter types.
523   * @throws { BusinessError } 31300000 - Inner error.
524   * @throws { BusinessError } 31300001 - Database corrupted.
525   * @throws { BusinessError } 31300014 - Invalid database path.
526   * @throws { BusinessError } 31300015 - Config changed.
527   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
528   * @systemapi
529   * @since 18
530   */
531  function getStore(context: Context, config: StoreConfig): Promise<GraphStore>;
532
533  /**
534   * Deletes the database with a specified store config.
535   *
536   * @param { Context } context - Indicates the context of an application or ability.
537   * @param { StoreConfig } config - Indicates the {@link StoreConfig} configuration of the database related to this graph store.
538   * @returns { Promise<void> } The Promise returned by the function.
539   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
540   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
541   * <br>2. Incorrect parameter types.
542   * @throws { BusinessError } 31300000 - Inner error.
543   * @throws { BusinessError } 31300014 - Invalid database path.
544   * @syscap SystemCapability.DistributedDataManager.DataIntelligence.Core
545   * @systemapi
546   * @since 18
547   */
548  function deleteStore(context: Context, config: StoreConfig): Promise<void>;
549}
550
551export default graphStore;
552