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