@react-native-gpui/async-storage 0.0.0-stage → 3.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +35 -2
- package/desktop/Cargo.toml +13 -0
- package/desktop/build.rs +3 -0
- package/desktop/src/lib.rs +264 -0
- package/desktop/src/paths.rs +41 -0
- package/package.json +34 -4
- package/react-native.config.js +9 -0
- package/src/NativeAsyncStorage.ts +33 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@react-native-gpui/async-storage` are listed here. Each version's section becomes the notes of its GitHub release.
|
|
4
|
+
|
|
5
|
+
## 3.1.0-alpha.1 - 2026-11-27
|
|
6
|
+
|
|
7
|
+
- First release, for `@react-native-async-storage/async-storage` 3.1.x: the default storage, named storages created with `createAsyncStorage`, and the legacy API, kept in redb databases.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Streetwriters
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @react-native-gpui/async-storage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Adapter for [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage) (MIT): persistent key-value storage on the desktop renderer.
|
|
4
|
+
|
|
5
|
+
Part of [react-native-gpui](https://github.com/streetwriters/react-native-gpui), React Native for macOS, Windows and Linux.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @react-native-async-storage/async-storage@3.1.x @react-native-gpui/async-storage
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The module is autolinked on desktop. The library's JavaScript runs unchanged:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import AsyncStorage, {
|
|
17
|
+
createAsyncStorage,
|
|
18
|
+
} from '@react-native-async-storage/async-storage';
|
|
19
|
+
|
|
20
|
+
await AsyncStorage.setItem('key', 'value');
|
|
21
|
+
const custom = createAsyncStorage('custom');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Storage location
|
|
25
|
+
|
|
26
|
+
Each named storage is one [redb](https://github.com/cberner/redb) database file, `async-storage/x-<hex>.redb`, in the application data directory (`RN_GPUI_APP_DATA_DIR` when set, otherwise the platform's data folder). The storage behind the legacy API, `getLegacyStorage()`, is `async-storage/legacy.redb`. The file name is the storage name in lowercase hex, so names that differ only in case, such as `Custom` and `custom`, stay separate on case-insensitive file systems.
|
|
27
|
+
|
|
28
|
+
A database file is locked while the app has it open. If a second instance of the same app runs at the same time, its calls on that storage reject with an error; the data is not affected.
|
|
29
|
+
|
|
30
|
+
## Platforms
|
|
31
|
+
|
|
32
|
+
macOS is tested. Windows and Linux are not tested yet.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT. See [LICENSE](LICENSE). The upstream library, [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage), is MIT licensed.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "rn-gpui-async-storage"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
rn-gpui-module = { version = "0.1" }
|
|
8
|
+
redb = "2"
|
|
9
|
+
serde_json = { version = "1", features = ["preserve_order"] }
|
|
10
|
+
dirs = "5"
|
|
11
|
+
|
|
12
|
+
[build-dependencies]
|
|
13
|
+
rn-gpui-module-build = { version = "0.1" }
|
package/desktop/build.rs
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
rn_gpui_module::include_specs!();
|
|
2
|
+
|
|
3
|
+
mod paths;
|
|
4
|
+
|
|
5
|
+
use std::collections::HashMap;
|
|
6
|
+
use std::path::PathBuf;
|
|
7
|
+
use std::sync::{Arc, Mutex};
|
|
8
|
+
|
|
9
|
+
use redb::{Database, ReadableTable, TableDefinition, TableError};
|
|
10
|
+
use rn_gpui_module::ModuleError;
|
|
11
|
+
use serde_json::{Map, Value as Json};
|
|
12
|
+
|
|
13
|
+
const KV: TableDefinition<&str, &str> = TableDefinition::new("kv");
|
|
14
|
+
const LEGACY_FILE: &str = "legacy";
|
|
15
|
+
|
|
16
|
+
pub struct AsyncStorage {
|
|
17
|
+
directory: PathBuf,
|
|
18
|
+
databases: Mutex<HashMap<String, Arc<Database>>>,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fn storage_error(error: impl std::fmt::Display) -> ModuleError {
|
|
22
|
+
ModuleError::new(error.to_string())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fn hex(name: &str) -> String {
|
|
26
|
+
name.bytes().map(|byte| format!("{byte:02x}")).collect()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// The database file stem for a storage name: its lowercase hex encoding, so
|
|
30
|
+
/// names that differ only in case get their own file on case-insensitive file
|
|
31
|
+
/// systems, and no name maps to the legacy storage's stem.
|
|
32
|
+
fn file_stem(name: &str) -> String {
|
|
33
|
+
format!("x-{}", hex(name))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn merge(target: &mut Map<String, Json>, source: Map<String, Json>) {
|
|
37
|
+
for (key, incoming) in source {
|
|
38
|
+
match (target.get_mut(&key), incoming) {
|
|
39
|
+
(Some(Json::Object(existing)), Json::Object(incoming)) => merge(existing, incoming),
|
|
40
|
+
(_, incoming) => {
|
|
41
|
+
target.insert(key, incoming);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn merged(old: &str, new: &str) -> String {
|
|
48
|
+
match (
|
|
49
|
+
serde_json::from_str::<Json>(old),
|
|
50
|
+
serde_json::from_str::<Json>(new),
|
|
51
|
+
) {
|
|
52
|
+
(Ok(Json::Object(mut old)), Ok(Json::Object(new))) => {
|
|
53
|
+
merge(&mut old, new);
|
|
54
|
+
Json::Object(old).to_string()
|
|
55
|
+
}
|
|
56
|
+
_ => new.to_string(),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
impl AsyncStorage {
|
|
61
|
+
fn database(&self, stem: &str) -> Result<Arc<Database>, ModuleError> {
|
|
62
|
+
let mut databases = self.databases.lock().map_err(storage_error)?;
|
|
63
|
+
if let Some(database) = databases.get(stem) {
|
|
64
|
+
return Ok(database.clone());
|
|
65
|
+
}
|
|
66
|
+
std::fs::create_dir_all(&self.directory).map_err(storage_error)?;
|
|
67
|
+
let path = self.directory.join(format!("{stem}.redb"));
|
|
68
|
+
let database = Arc::new(Database::create(&path).map_err(|error| {
|
|
69
|
+
ModuleError::new(format!("Could not open {}: {error}", path.display()))
|
|
70
|
+
})?);
|
|
71
|
+
databases.insert(stem.to_string(), database.clone());
|
|
72
|
+
Ok(database)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn named(&self, name: &str) -> Result<Arc<Database>, ModuleError> {
|
|
76
|
+
self.database(&file_stem(name))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fn legacy(&self) -> Result<Arc<Database>, ModuleError> {
|
|
80
|
+
self.database(LEGACY_FILE)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn read(database: &Database, keys: &[String]) -> Result<Vec<(String, Option<String>)>, ModuleError> {
|
|
85
|
+
let transaction = database.begin_read().map_err(storage_error)?;
|
|
86
|
+
let table = match transaction.open_table(KV) {
|
|
87
|
+
Ok(table) => Some(table),
|
|
88
|
+
Err(TableError::TableDoesNotExist(_)) => None,
|
|
89
|
+
Err(error) => return Err(storage_error(error)),
|
|
90
|
+
};
|
|
91
|
+
keys.iter()
|
|
92
|
+
.map(|key| {
|
|
93
|
+
let value = match &table {
|
|
94
|
+
Some(table) => table
|
|
95
|
+
.get(key.as_str())
|
|
96
|
+
.map_err(storage_error)?
|
|
97
|
+
.map(|value| value.value().to_string()),
|
|
98
|
+
None => None,
|
|
99
|
+
};
|
|
100
|
+
Ok((key.clone(), value))
|
|
101
|
+
})
|
|
102
|
+
.collect()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn write(
|
|
106
|
+
database: &Database,
|
|
107
|
+
entries: &[(String, Option<String>)],
|
|
108
|
+
merge_json: bool,
|
|
109
|
+
) -> Result<(), ModuleError> {
|
|
110
|
+
let transaction = database.begin_write().map_err(storage_error)?;
|
|
111
|
+
{
|
|
112
|
+
let mut table = transaction.open_table(KV).map_err(storage_error)?;
|
|
113
|
+
for (key, value) in entries {
|
|
114
|
+
match value {
|
|
115
|
+
Some(value) => {
|
|
116
|
+
let next = if merge_json {
|
|
117
|
+
let current = table
|
|
118
|
+
.get(key.as_str())
|
|
119
|
+
.map_err(storage_error)?
|
|
120
|
+
.map(|current| current.value().to_string());
|
|
121
|
+
match current {
|
|
122
|
+
Some(current) => merged(¤t, value),
|
|
123
|
+
None => value.clone(),
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
value.clone()
|
|
127
|
+
};
|
|
128
|
+
table
|
|
129
|
+
.insert(key.as_str(), next.as_str())
|
|
130
|
+
.map_err(storage_error)?;
|
|
131
|
+
}
|
|
132
|
+
None => {
|
|
133
|
+
table.remove(key.as_str()).map_err(storage_error)?;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
transaction.commit().map_err(storage_error)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fn remove(database: &Database, keys: &[String]) -> Result<(), ModuleError> {
|
|
142
|
+
let entries: Vec<_> = keys.iter().map(|key| (key.clone(), None)).collect();
|
|
143
|
+
write(database, &entries, false)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn keys(database: &Database) -> Result<Vec<String>, ModuleError> {
|
|
147
|
+
let transaction = database.begin_read().map_err(storage_error)?;
|
|
148
|
+
let table = match transaction.open_table(KV) {
|
|
149
|
+
Ok(table) => table,
|
|
150
|
+
Err(TableError::TableDoesNotExist(_)) => return Ok(Vec::new()),
|
|
151
|
+
Err(error) => return Err(storage_error(error)),
|
|
152
|
+
};
|
|
153
|
+
table
|
|
154
|
+
.iter()
|
|
155
|
+
.map_err(storage_error)?
|
|
156
|
+
.map(|entry| {
|
|
157
|
+
entry
|
|
158
|
+
.map(|(key, _)| key.value().to_string())
|
|
159
|
+
.map_err(storage_error)
|
|
160
|
+
})
|
|
161
|
+
.collect()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
fn clear(database: &Database) -> Result<(), ModuleError> {
|
|
165
|
+
let transaction = database.begin_write().map_err(storage_error)?;
|
|
166
|
+
transaction.delete_table(KV).map_err(storage_error)?;
|
|
167
|
+
transaction.commit().map_err(storage_error)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fn pairs(kv_pairs: Vec<Vec<String>>) -> Result<Vec<(String, Option<String>)>, ModuleError> {
|
|
171
|
+
kv_pairs
|
|
172
|
+
.into_iter()
|
|
173
|
+
.map(|pair| match <[String; 2]>::try_from(pair) {
|
|
174
|
+
Ok([key, value]) => Ok((key, Some(value))),
|
|
175
|
+
Err(_) => Err(ModuleError::new("Each entry must be a [key, value] pair")),
|
|
176
|
+
})
|
|
177
|
+
.collect()
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
impl NativeAsyncStorageSpec for AsyncStorage {
|
|
181
|
+
fn new(_events: NativeAsyncStorageEvents) -> Self {
|
|
182
|
+
Self {
|
|
183
|
+
directory: paths::storage_directory(),
|
|
184
|
+
databases: Mutex::new(HashMap::new()),
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async fn get_values(
|
|
189
|
+
&self,
|
|
190
|
+
db_name: String,
|
|
191
|
+
keys: Vec<String>,
|
|
192
|
+
) -> Result<Vec<GetValuesResult>, ModuleError> {
|
|
193
|
+
let values = read(self.named(&db_name)?.as_ref(), &keys)?;
|
|
194
|
+
Ok(values
|
|
195
|
+
.into_iter()
|
|
196
|
+
.map(|(key, value)| GetValuesResult { key, value })
|
|
197
|
+
.collect())
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async fn set_values(
|
|
201
|
+
&self,
|
|
202
|
+
db_name: String,
|
|
203
|
+
values: Vec<SetValuesValues>,
|
|
204
|
+
) -> Result<Vec<SetValuesResult>, ModuleError> {
|
|
205
|
+
let entries: Vec<_> = values
|
|
206
|
+
.iter()
|
|
207
|
+
.map(|entry| (entry.key.clone(), entry.value.clone()))
|
|
208
|
+
.collect();
|
|
209
|
+
write(self.named(&db_name)?.as_ref(), &entries, false)?;
|
|
210
|
+
Ok(values
|
|
211
|
+
.into_iter()
|
|
212
|
+
.map(|entry| SetValuesResult {
|
|
213
|
+
key: entry.key,
|
|
214
|
+
value: entry.value,
|
|
215
|
+
})
|
|
216
|
+
.collect())
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async fn remove_values(&self, db_name: String, keys: Vec<String>) -> Result<(), ModuleError> {
|
|
220
|
+
remove(self.named(&db_name)?.as_ref(), &keys)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async fn get_keys(&self, db_name: String) -> Result<Vec<String>, ModuleError> {
|
|
224
|
+
keys(self.named(&db_name)?.as_ref())
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async fn clear_storage(&self, db_name: String) -> Result<(), ModuleError> {
|
|
228
|
+
clear(self.named(&db_name)?.as_ref())
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async fn legacy_multi_get(
|
|
232
|
+
&self,
|
|
233
|
+
keys: Vec<String>,
|
|
234
|
+
) -> Result<Vec<Vec<Option<String>>>, ModuleError> {
|
|
235
|
+
Ok(read(self.legacy()?.as_ref(), &keys)?
|
|
236
|
+
.into_iter()
|
|
237
|
+
.map(|(key, value)| vec![Some(key), value])
|
|
238
|
+
.collect())
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async fn legacy_multi_set(&self, kv_pairs: Vec<Vec<String>>) -> Result<(), ModuleError> {
|
|
242
|
+
write(self.legacy()?.as_ref(), &pairs(kv_pairs)?, false)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async fn legacy_multi_remove(&self, keys: Vec<String>) -> Result<(), ModuleError> {
|
|
246
|
+
remove(self.legacy()?.as_ref(), &keys)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async fn legacy_multi_merge(&self, kv_pairs: Vec<Vec<String>>) -> Result<(), ModuleError> {
|
|
250
|
+
write(self.legacy()?.as_ref(), &pairs(kv_pairs)?, true)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async fn legacy_get_all_keys(&self) -> Result<Vec<String>, ModuleError> {
|
|
254
|
+
keys(self.legacy()?.as_ref())
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async fn legacy_clear(&self) -> Result<(), ModuleError> {
|
|
258
|
+
clear(self.legacy()?.as_ref())
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
pub fn rn_gpui_register() {
|
|
263
|
+
rn_gpui_module::register(native_async_storage_module::<AsyncStorage>());
|
|
264
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
use std::path::PathBuf;
|
|
2
|
+
|
|
3
|
+
fn sanitize(id: &str) -> String {
|
|
4
|
+
id.trim()
|
|
5
|
+
.chars()
|
|
6
|
+
.map(|c| match c {
|
|
7
|
+
'/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' | '\0' => '-',
|
|
8
|
+
other => other,
|
|
9
|
+
})
|
|
10
|
+
.collect::<String>()
|
|
11
|
+
.trim_matches(|c| c == '.' || c == '-')
|
|
12
|
+
.to_string()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fn app_id() -> String {
|
|
16
|
+
let from_environment = std::env::var("RN_GPUI_APP_ID").ok();
|
|
17
|
+
let from_executable = std::env::current_exe().ok().and_then(|exe| {
|
|
18
|
+
exe.file_stem()
|
|
19
|
+
.map(|stem| stem.to_string_lossy().into_owned())
|
|
20
|
+
});
|
|
21
|
+
[from_environment, from_executable]
|
|
22
|
+
.into_iter()
|
|
23
|
+
.flatten()
|
|
24
|
+
.map(|id| sanitize(&id))
|
|
25
|
+
.find(|id| !id.is_empty())
|
|
26
|
+
.unwrap_or_else(|| "rn-gpui-app".to_string())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// `<app data folder>/async-storage`, where the app data folder follows the
|
|
30
|
+
/// convention of the other desktop modules.
|
|
31
|
+
pub fn storage_directory() -> PathBuf {
|
|
32
|
+
let id = app_id();
|
|
33
|
+
let root = std::env::var_os("RN_GPUI_APP_DATA_DIR").filter(|root| !root.is_empty());
|
|
34
|
+
let app_data = match root {
|
|
35
|
+
Some(root) => PathBuf::from(root).join(id),
|
|
36
|
+
None => dirs::data_dir()
|
|
37
|
+
.unwrap_or_else(std::env::temp_dir)
|
|
38
|
+
.join(id),
|
|
39
|
+
};
|
|
40
|
+
app_data.join("async-storage")
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-gpui/async-storage",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.1.0-alpha.1",
|
|
4
|
+
"description": "Adapter for @react-native-async-storage/async-storage (MIT): persistent key-value storage on the desktop renderer",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"desktop",
|
|
9
|
+
"react-native.config.js",
|
|
10
|
+
"README.md",
|
|
11
|
+
"CHANGELOG.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"codegenConfig": {
|
|
15
|
+
"name": "RNAsyncStorageSpec",
|
|
16
|
+
"type": "modules",
|
|
17
|
+
"jsSrcsDir": "src"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react-native": "0.87.x",
|
|
21
|
+
"@react-native-async-storage/async-storage": "3.1.x"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
|
|
26
|
+
"directory": "modules/async-storage"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/async-storage#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"tag": "latest"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
getValues: (
|
|
6
|
+
dbName: string,
|
|
7
|
+
keys: string[],
|
|
8
|
+
) => Promise<{ key: string; value: string | null }[]>;
|
|
9
|
+
|
|
10
|
+
setValues: (
|
|
11
|
+
dbName: string,
|
|
12
|
+
values: { key: string; value: string | null }[],
|
|
13
|
+
) => Promise<{ key: string; value: string | null }[]>;
|
|
14
|
+
|
|
15
|
+
removeValues: (dbName: string, keys: string[]) => Promise<void>;
|
|
16
|
+
|
|
17
|
+
getKeys: (dbName: string) => Promise<string[]>;
|
|
18
|
+
|
|
19
|
+
clearStorage: (dbName: string) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* As part of migration to new storage, old implementation is available.
|
|
23
|
+
* But the callback approach is replaced with promises.
|
|
24
|
+
*/
|
|
25
|
+
legacy_multiGet: (keys: string[]) => Promise<Array<Array<string | null>>>;
|
|
26
|
+
legacy_multiSet: (kvPairs: Array<Array<string>>) => Promise<void>;
|
|
27
|
+
legacy_multiRemove: (keys: readonly string[]) => Promise<void>;
|
|
28
|
+
legacy_multiMerge: (kvPairs: Array<Array<string>>) => Promise<void>;
|
|
29
|
+
legacy_getAllKeys: () => Promise<string[]>;
|
|
30
|
+
legacy_clear: () => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default TurboModuleRegistry.get<Spec>('RNAsyncStorage');
|