• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 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 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
18 */
19export interface GetStorageOptions {
20  /**
21   * Content index.
22   * For liteWearable and smartVision, the value contains a maximum of 32 characters and cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
23   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
24   * @since 3
25   */
26  key: string;
27
28  /**
29   * Default value returned when the key does not exist.
30   * If this parameter is not specified, an empty string is returned.
31   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
32   * @since 3
33   */
34  default?: string;
35
36  /**
37   * Called when the stored content is read successfully.
38   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
39   * @since 3
40   */
41  success?: (data: any) => void;
42
43  /**
44   * Called when the stored content fails to be read.
45   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
46   * @since 3
47   */
48  fail?: (data: string, code: number) => void;
49
50  /**
51   * Called when the execution is completed.
52   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
53   * @since 3
54   */
55  complete?: () => void;
56}
57
58/**
59 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
60 */
61export interface SetStorageOptions {
62  /**
63   * Index of the stored content to be modified.
64   * For liteWearable and smartVision, the value contains a maximum of 32 characters and cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
65   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
66   * @since 3
67   */
68  key: string;
69
70  /**
71   * Target storage content. If the content is an empty string, the data item with the key as the index will be deleted.
72   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
73   * @since 3
74   */
75  value: string;
76
77  /**
78   * Called when the stored content is modified successfully.
79   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
80   * @since 3
81   */
82  success?: () => void;
83
84  /**
85   * Called when the stored content fails to be modified.
86   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
87   * @since 3
88   */
89  fail?: (data: string, code: number) => void;
90
91  /**
92   * Called when the execution is completed.
93   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
94   * @since 3
95   */
96  complete?: () => void;
97}
98
99/**
100 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
101 */
102export interface ClearStorageOptions {
103  /**
104   * Called when the stored content is cleared successfully.
105   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
106   * @since 3
107   */
108  success?: () => void;
109
110  /**
111   * Called when the stored content fails to be cleared.
112   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
113   * @since 3
114   */
115  fail?: (data: string, code: number) => void;
116
117  /**
118   * Called when the execution is completed.
119   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
120   * @since 3
121   */
122  complete?: () => void;
123}
124
125/**
126 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
127 */
128export interface DeleteStorageOptions {
129  /**
130   * Content index.
131   * For liteWearable and smartVision, the value contains a maximum of 32 characters and cannot contain special characters such as \/"*+,:;<=>?[]|\x7F.
132   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
133   * @since 3
134   */
135  key: string;
136
137  /**
138   * Called when the stored content is deleted successfully.
139   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
140   * @since 3
141   */
142  success?: () => void;
143
144  /**
145   * Called when the stored content fails to be deleted.
146   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
147   * @since 3
148   */
149  fail?: (data: string, code: number) => void;
150
151  /**
152   * Called when the execution is completed.
153   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
154   * @since 3
155   */
156  complete?: () => void;
157}
158
159/**
160 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
161 */
162export default class Storage {
163  /**
164   * Reads the stored content.
165   * @param options Options.
166   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
167   */
168  static get(options: GetStorageOptions): void;
169
170  /**
171   * Modifies the stored content.
172   * @param options Options.
173   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
174   */
175  static set(options: SetStorageOptions): void;
176
177  /**
178   * Clears the stored content.
179   * @param options Options.
180   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
181   */
182  static clear(options?: ClearStorageOptions): void;
183
184  /**
185   * Deletes the stored content.
186   * @param options Options.
187   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
188   */
189  static delete(options: DeleteStorageOptions): void;
190}
191