react-native-nitro-storage 0.1.3 → 0.3.0
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/README.md +320 -391
- package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +101 -0
- package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +6 -41
- package/android/src/main/java/com/nitrostorage/AndroidStorageAdapter.kt +125 -37
- package/app.plugin.js +9 -7
- package/cpp/bindings/HybridStorage.cpp +214 -19
- package/cpp/bindings/HybridStorage.hpp +1 -0
- package/cpp/core/NativeStorageAdapter.hpp +7 -0
- package/ios/IOSStorageAdapterCpp.hpp +6 -0
- package/ios/IOSStorageAdapterCpp.mm +90 -7
- package/lib/commonjs/index.js +537 -66
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +558 -130
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/internal.js +102 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/module/index.js +528 -67
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +536 -122
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/internal.js +92 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/typescript/index.d.ts +42 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +45 -12
- package/lib/typescript/index.web.d.ts.map +1 -1
- package/lib/typescript/internal.d.ts +19 -0
- package/lib/typescript/internal.d.ts.map +1 -0
- package/lib/typescript/migration.d.ts +2 -3
- package/lib/typescript/migration.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroStorage+autolinking.cmake +1 -1
- package/nitrogen/generated/android/NitroStorage+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroStorageOnLoad.cpp +1 -1
- package/nitrogen/generated/android/NitroStorageOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitrostorage/NitroStorageOnLoad.kt +1 -1
- package/nitrogen/generated/ios/NitroStorage+autolinking.rb +1 -1
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/NitroStorageAutolinking.mm +1 -1
- package/nitrogen/generated/ios/NitroStorageAutolinking.swift +5 -1
- package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +1 -1
- package/package.json +19 -8
- package/src/index.ts +734 -74
- package/src/index.web.ts +732 -128
- package/src/internal.ts +134 -0
- package/src/migration.ts +2 -2
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
namespace margelo::nitro::NitroStorage {
|
|
12
12
|
|
|
13
|
+
namespace {
|
|
14
|
+
constexpr auto kBatchMissingSentinel = "__nitro_storage_batch_missing__::v1";
|
|
15
|
+
} // namespace
|
|
16
|
+
|
|
13
17
|
HybridStorage::HybridStorage()
|
|
14
18
|
: HybridObject(TAG), HybridStorageSpec() {
|
|
15
19
|
#if __APPLE__
|
|
@@ -24,12 +28,21 @@ HybridStorage::HybridStorage(std::shared_ptr<::NitroStorage::NativeStorageAdapte
|
|
|
24
28
|
: HybridObject(TAG), HybridStorageSpec(), nativeAdapter_(std::move(adapter)) {}
|
|
25
29
|
|
|
26
30
|
HybridStorage::Scope HybridStorage::toScope(double scopeValue) {
|
|
27
|
-
|
|
31
|
+
if (scopeValue < 0.0 || scopeValue > 2.0) {
|
|
32
|
+
throw std::runtime_error("NitroStorage: Invalid scope value");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
int intValue = static_cast<int>(scopeValue);
|
|
36
|
+
if (scopeValue != static_cast<double>(intValue)) {
|
|
37
|
+
throw std::runtime_error("NitroStorage: Invalid scope value");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return static_cast<Scope>(intValue);
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
void HybridStorage::set(const std::string& key, const std::string& value, double scope) {
|
|
31
44
|
Scope s = toScope(scope);
|
|
32
|
-
|
|
45
|
+
|
|
33
46
|
switch (s) {
|
|
34
47
|
case Scope::Memory: {
|
|
35
48
|
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
@@ -37,10 +50,24 @@ void HybridStorage::set(const std::string& key, const std::string& value, double
|
|
|
37
50
|
break;
|
|
38
51
|
}
|
|
39
52
|
case Scope::Disk:
|
|
40
|
-
|
|
53
|
+
ensureAdapter();
|
|
54
|
+
try {
|
|
55
|
+
nativeAdapter_->setDisk(key, value);
|
|
56
|
+
} catch (const std::exception& e) {
|
|
57
|
+
throw std::runtime_error(std::string("NitroStorage: Disk set failed: ") + e.what());
|
|
58
|
+
} catch (...) {
|
|
59
|
+
throw std::runtime_error("NitroStorage: Disk set failed");
|
|
60
|
+
}
|
|
41
61
|
break;
|
|
42
62
|
case Scope::Secure:
|
|
43
|
-
|
|
63
|
+
ensureAdapter();
|
|
64
|
+
try {
|
|
65
|
+
nativeAdapter_->setSecure(key, value);
|
|
66
|
+
} catch (const std::exception& e) {
|
|
67
|
+
throw std::runtime_error(std::string("NitroStorage: Secure set failed: ") + e.what());
|
|
68
|
+
} catch (...) {
|
|
69
|
+
throw std::runtime_error("NitroStorage: Secure set failed");
|
|
70
|
+
}
|
|
44
71
|
break;
|
|
45
72
|
}
|
|
46
73
|
|
|
@@ -60,9 +87,23 @@ std::optional<std::string> HybridStorage::get(const std::string& key, double sco
|
|
|
60
87
|
return std::nullopt;
|
|
61
88
|
}
|
|
62
89
|
case Scope::Disk:
|
|
63
|
-
|
|
90
|
+
ensureAdapter();
|
|
91
|
+
try {
|
|
92
|
+
return nativeAdapter_->getDisk(key);
|
|
93
|
+
} catch (const std::exception& e) {
|
|
94
|
+
throw std::runtime_error(std::string("NitroStorage: Disk get failed: ") + e.what());
|
|
95
|
+
} catch (...) {
|
|
96
|
+
throw std::runtime_error("NitroStorage: Disk get failed");
|
|
97
|
+
}
|
|
64
98
|
case Scope::Secure:
|
|
65
|
-
|
|
99
|
+
ensureAdapter();
|
|
100
|
+
try {
|
|
101
|
+
return nativeAdapter_->getSecure(key);
|
|
102
|
+
} catch (const std::exception& e) {
|
|
103
|
+
throw std::runtime_error(std::string("NitroStorage: Secure get failed: ") + e.what());
|
|
104
|
+
} catch (...) {
|
|
105
|
+
throw std::runtime_error("NitroStorage: Secure get failed");
|
|
106
|
+
}
|
|
66
107
|
}
|
|
67
108
|
|
|
68
109
|
return std::nullopt;
|
|
@@ -78,10 +119,24 @@ void HybridStorage::remove(const std::string& key, double scope) {
|
|
|
78
119
|
break;
|
|
79
120
|
}
|
|
80
121
|
case Scope::Disk:
|
|
81
|
-
|
|
122
|
+
ensureAdapter();
|
|
123
|
+
try {
|
|
124
|
+
nativeAdapter_->deleteDisk(key);
|
|
125
|
+
} catch (const std::exception& e) {
|
|
126
|
+
throw std::runtime_error(std::string("NitroStorage: Disk delete failed: ") + e.what());
|
|
127
|
+
} catch (...) {
|
|
128
|
+
throw std::runtime_error("NitroStorage: Disk delete failed");
|
|
129
|
+
}
|
|
82
130
|
break;
|
|
83
131
|
case Scope::Secure:
|
|
84
|
-
|
|
132
|
+
ensureAdapter();
|
|
133
|
+
try {
|
|
134
|
+
nativeAdapter_->deleteSecure(key);
|
|
135
|
+
} catch (const std::exception& e) {
|
|
136
|
+
throw std::runtime_error(std::string("NitroStorage: Secure delete failed: ") + e.what());
|
|
137
|
+
} catch (...) {
|
|
138
|
+
throw std::runtime_error("NitroStorage: Secure delete failed");
|
|
139
|
+
}
|
|
85
140
|
break;
|
|
86
141
|
}
|
|
87
142
|
|
|
@@ -123,10 +178,24 @@ void HybridStorage::clear(double scope) {
|
|
|
123
178
|
break;
|
|
124
179
|
}
|
|
125
180
|
case Scope::Disk:
|
|
126
|
-
|
|
181
|
+
ensureAdapter();
|
|
182
|
+
try {
|
|
183
|
+
nativeAdapter_->clearDisk();
|
|
184
|
+
} catch (const std::exception& e) {
|
|
185
|
+
throw std::runtime_error(std::string("NitroStorage: Disk clear failed: ") + e.what());
|
|
186
|
+
} catch (...) {
|
|
187
|
+
throw std::runtime_error("NitroStorage: Disk clear failed");
|
|
188
|
+
}
|
|
127
189
|
break;
|
|
128
190
|
case Scope::Secure:
|
|
129
|
-
|
|
191
|
+
ensureAdapter();
|
|
192
|
+
try {
|
|
193
|
+
nativeAdapter_->clearSecure();
|
|
194
|
+
} catch (const std::exception& e) {
|
|
195
|
+
throw std::runtime_error(std::string("NitroStorage: Secure clear failed: ") + e.what());
|
|
196
|
+
} catch (...) {
|
|
197
|
+
throw std::runtime_error("NitroStorage: Secure clear failed");
|
|
198
|
+
}
|
|
130
199
|
break;
|
|
131
200
|
}
|
|
132
201
|
|
|
@@ -137,9 +206,41 @@ void HybridStorage::setBatch(const std::vector<std::string>& keys, const std::ve
|
|
|
137
206
|
if (keys.size() != values.size()) {
|
|
138
207
|
throw std::runtime_error("NitroStorage: Keys and values size mismatch in setBatch");
|
|
139
208
|
}
|
|
140
|
-
|
|
209
|
+
|
|
210
|
+
Scope s = toScope(scope);
|
|
211
|
+
|
|
212
|
+
switch (s) {
|
|
213
|
+
case Scope::Memory: {
|
|
214
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
215
|
+
for (size_t i = 0; i < keys.size(); ++i) {
|
|
216
|
+
memoryStore_[keys[i]] = values[i];
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case Scope::Disk:
|
|
221
|
+
ensureAdapter();
|
|
222
|
+
try {
|
|
223
|
+
nativeAdapter_->setDiskBatch(keys, values);
|
|
224
|
+
} catch (const std::exception& e) {
|
|
225
|
+
throw std::runtime_error(std::string("NitroStorage: Disk setBatch failed: ") + e.what());
|
|
226
|
+
} catch (...) {
|
|
227
|
+
throw std::runtime_error("NitroStorage: Disk setBatch failed");
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
case Scope::Secure:
|
|
231
|
+
ensureAdapter();
|
|
232
|
+
try {
|
|
233
|
+
nativeAdapter_->setSecureBatch(keys, values);
|
|
234
|
+
} catch (const std::exception& e) {
|
|
235
|
+
throw std::runtime_error(std::string("NitroStorage: Secure setBatch failed: ") + e.what());
|
|
236
|
+
} catch (...) {
|
|
237
|
+
throw std::runtime_error("NitroStorage: Secure setBatch failed");
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
|
|
141
242
|
for (size_t i = 0; i < keys.size(); ++i) {
|
|
142
|
-
|
|
243
|
+
notifyListeners(static_cast<int>(s), keys[i], values[i]);
|
|
143
244
|
}
|
|
144
245
|
}
|
|
145
246
|
|
|
@@ -147,19 +248,103 @@ void HybridStorage::setBatch(const std::vector<std::string>& keys, const std::ve
|
|
|
147
248
|
std::vector<std::string> HybridStorage::getBatch(const std::vector<std::string>& keys, double scope) {
|
|
148
249
|
std::vector<std::string> results;
|
|
149
250
|
results.reserve(keys.size());
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
251
|
+
|
|
252
|
+
Scope s = toScope(scope);
|
|
253
|
+
|
|
254
|
+
switch (s) {
|
|
255
|
+
case Scope::Memory: {
|
|
256
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
257
|
+
for (const auto& key : keys) {
|
|
258
|
+
auto it = memoryStore_.find(key);
|
|
259
|
+
if (it != memoryStore_.end()) {
|
|
260
|
+
results.push_back(it->second);
|
|
261
|
+
} else {
|
|
262
|
+
results.push_back(kBatchMissingSentinel);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return results;
|
|
266
|
+
}
|
|
267
|
+
case Scope::Disk: {
|
|
268
|
+
ensureAdapter();
|
|
269
|
+
std::vector<std::optional<std::string>> values;
|
|
270
|
+
try {
|
|
271
|
+
values = nativeAdapter_->getDiskBatch(keys);
|
|
272
|
+
} catch (const std::exception& e) {
|
|
273
|
+
throw std::runtime_error(std::string("NitroStorage: Disk getBatch failed: ") + e.what());
|
|
274
|
+
} catch (...) {
|
|
275
|
+
throw std::runtime_error("NitroStorage: Disk getBatch failed");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
for (const auto& value : values) {
|
|
279
|
+
if (value.has_value()) {
|
|
280
|
+
results.push_back(*value);
|
|
281
|
+
} else {
|
|
282
|
+
results.push_back(kBatchMissingSentinel);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return results;
|
|
286
|
+
}
|
|
287
|
+
case Scope::Secure: {
|
|
288
|
+
ensureAdapter();
|
|
289
|
+
std::vector<std::optional<std::string>> values;
|
|
290
|
+
try {
|
|
291
|
+
values = nativeAdapter_->getSecureBatch(keys);
|
|
292
|
+
} catch (const std::exception& e) {
|
|
293
|
+
throw std::runtime_error(std::string("NitroStorage: Secure getBatch failed: ") + e.what());
|
|
294
|
+
} catch (...) {
|
|
295
|
+
throw std::runtime_error("NitroStorage: Secure getBatch failed");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
for (const auto& value : values) {
|
|
299
|
+
if (value.has_value()) {
|
|
300
|
+
results.push_back(*value);
|
|
301
|
+
} else {
|
|
302
|
+
results.push_back(kBatchMissingSentinel);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return results;
|
|
306
|
+
}
|
|
154
307
|
}
|
|
155
|
-
|
|
308
|
+
|
|
156
309
|
return results;
|
|
157
310
|
}
|
|
158
311
|
|
|
159
312
|
|
|
160
313
|
void HybridStorage::removeBatch(const std::vector<std::string>& keys, double scope) {
|
|
314
|
+
Scope s = toScope(scope);
|
|
315
|
+
|
|
316
|
+
switch (s) {
|
|
317
|
+
case Scope::Memory: {
|
|
318
|
+
std::lock_guard<std::mutex> lock(memoryMutex_);
|
|
319
|
+
for (const auto& key : keys) {
|
|
320
|
+
memoryStore_.erase(key);
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case Scope::Disk:
|
|
325
|
+
ensureAdapter();
|
|
326
|
+
try {
|
|
327
|
+
nativeAdapter_->deleteDiskBatch(keys);
|
|
328
|
+
} catch (const std::exception& e) {
|
|
329
|
+
throw std::runtime_error(std::string("NitroStorage: Disk removeBatch failed: ") + e.what());
|
|
330
|
+
} catch (...) {
|
|
331
|
+
throw std::runtime_error("NitroStorage: Disk removeBatch failed");
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
case Scope::Secure:
|
|
335
|
+
ensureAdapter();
|
|
336
|
+
try {
|
|
337
|
+
nativeAdapter_->deleteSecureBatch(keys);
|
|
338
|
+
} catch (const std::exception& e) {
|
|
339
|
+
throw std::runtime_error(std::string("NitroStorage: Secure removeBatch failed: ") + e.what());
|
|
340
|
+
} catch (...) {
|
|
341
|
+
throw std::runtime_error("NitroStorage: Secure removeBatch failed");
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
|
|
161
346
|
for (const auto& key : keys) {
|
|
162
|
-
|
|
347
|
+
notifyListeners(static_cast<int>(s), key, std::nullopt);
|
|
163
348
|
}
|
|
164
349
|
}
|
|
165
350
|
|
|
@@ -179,7 +364,17 @@ void HybridStorage::notifyListeners(
|
|
|
179
364
|
}
|
|
180
365
|
|
|
181
366
|
for (const auto& listener : listenersCopy) {
|
|
182
|
-
|
|
367
|
+
try {
|
|
368
|
+
listener.callback(key, value);
|
|
369
|
+
} catch (...) {
|
|
370
|
+
// Ignore listener failures to avoid crashing the caller.
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
void HybridStorage::ensureAdapter() const {
|
|
376
|
+
if (!nativeAdapter_) {
|
|
377
|
+
throw std::runtime_error("NitroStorage: Native adapter not initialized");
|
|
183
378
|
}
|
|
184
379
|
}
|
|
185
380
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
#include <optional>
|
|
5
|
+
#include <vector>
|
|
5
6
|
|
|
6
7
|
namespace NitroStorage {
|
|
7
8
|
|
|
@@ -12,10 +13,16 @@ public:
|
|
|
12
13
|
virtual void setDisk(const std::string& key, const std::string& value) = 0;
|
|
13
14
|
virtual std::optional<std::string> getDisk(const std::string& key) = 0;
|
|
14
15
|
virtual void deleteDisk(const std::string& key) = 0;
|
|
16
|
+
virtual void setDiskBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values) = 0;
|
|
17
|
+
virtual std::vector<std::optional<std::string>> getDiskBatch(const std::vector<std::string>& keys) = 0;
|
|
18
|
+
virtual void deleteDiskBatch(const std::vector<std::string>& keys) = 0;
|
|
15
19
|
|
|
16
20
|
virtual void setSecure(const std::string& key, const std::string& value) = 0;
|
|
17
21
|
virtual std::optional<std::string> getSecure(const std::string& key) = 0;
|
|
18
22
|
virtual void deleteSecure(const std::string& key) = 0;
|
|
23
|
+
virtual void setSecureBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values) = 0;
|
|
24
|
+
virtual std::vector<std::optional<std::string>> getSecureBatch(const std::vector<std::string>& keys) = 0;
|
|
25
|
+
virtual void deleteSecureBatch(const std::vector<std::string>& keys) = 0;
|
|
19
26
|
|
|
20
27
|
virtual void clearDisk() = 0;
|
|
21
28
|
virtual void clearSecure() = 0;
|
|
@@ -12,10 +12,16 @@ public:
|
|
|
12
12
|
void setDisk(const std::string& key, const std::string& value) override;
|
|
13
13
|
std::optional<std::string> getDisk(const std::string& key) override;
|
|
14
14
|
void deleteDisk(const std::string& key) override;
|
|
15
|
+
void setDiskBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values) override;
|
|
16
|
+
std::vector<std::optional<std::string>> getDiskBatch(const std::vector<std::string>& keys) override;
|
|
17
|
+
void deleteDiskBatch(const std::vector<std::string>& keys) override;
|
|
15
18
|
|
|
16
19
|
void setSecure(const std::string& key, const std::string& value) override;
|
|
17
20
|
std::optional<std::string> getSecure(const std::string& key) override;
|
|
18
21
|
void deleteSecure(const std::string& key) override;
|
|
22
|
+
void setSecureBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values) override;
|
|
23
|
+
std::vector<std::optional<std::string>> getSecureBatch(const std::vector<std::string>& keys) override;
|
|
24
|
+
void deleteSecureBatch(const std::vector<std::string>& keys) override;
|
|
19
25
|
|
|
20
26
|
void clearDisk() override;
|
|
21
27
|
void clearSecure() override;
|
|
@@ -5,23 +5,77 @@
|
|
|
5
5
|
namespace NitroStorage {
|
|
6
6
|
|
|
7
7
|
static NSString* const kKeychainService = @"com.nitrostorage.keychain";
|
|
8
|
+
static NSString* const kDiskSuiteName = @"com.nitrostorage.disk";
|
|
9
|
+
|
|
10
|
+
static NSUserDefaults* NitroDiskDefaults() {
|
|
11
|
+
static NSUserDefaults* defaults = [[NSUserDefaults alloc] initWithSuiteName:kDiskSuiteName];
|
|
12
|
+
return defaults ?: [NSUserDefaults standardUserDefaults];
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
IOSStorageAdapterCpp::IOSStorageAdapterCpp() {}
|
|
10
16
|
IOSStorageAdapterCpp::~IOSStorageAdapterCpp() {}
|
|
11
17
|
|
|
12
18
|
void IOSStorageAdapterCpp::setDisk(const std::string& key, const std::string& value) {
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
NSString* nsKey = [NSString stringWithUTF8String:key.c_str()];
|
|
20
|
+
NSString* nsValue = [NSString stringWithUTF8String:value.c_str()];
|
|
21
|
+
NSUserDefaults* defaults = NitroDiskDefaults();
|
|
22
|
+
[defaults setObject:nsValue forKey:nsKey];
|
|
23
|
+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:nsKey];
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
std::optional<std::string> IOSStorageAdapterCpp::getDisk(const std::string& key) {
|
|
18
|
-
NSString*
|
|
27
|
+
NSString* nsKey = [NSString stringWithUTF8String:key.c_str()];
|
|
28
|
+
NSUserDefaults* defaults = NitroDiskDefaults();
|
|
29
|
+
NSString* result = [defaults stringForKey:nsKey];
|
|
30
|
+
|
|
31
|
+
if (!result) {
|
|
32
|
+
NSUserDefaults* legacyDefaults = [NSUserDefaults standardUserDefaults];
|
|
33
|
+
NSString* legacyValue = [legacyDefaults stringForKey:nsKey];
|
|
34
|
+
if (legacyValue) {
|
|
35
|
+
[defaults setObject:legacyValue forKey:nsKey];
|
|
36
|
+
[legacyDefaults removeObjectForKey:nsKey];
|
|
37
|
+
result = legacyValue;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
19
41
|
if (!result) return std::nullopt;
|
|
20
42
|
return std::string([result UTF8String]);
|
|
21
43
|
}
|
|
22
44
|
|
|
23
45
|
void IOSStorageAdapterCpp::deleteDisk(const std::string& key) {
|
|
24
|
-
|
|
46
|
+
NSString* nsKey = [NSString stringWithUTF8String:key.c_str()];
|
|
47
|
+
[NitroDiskDefaults() removeObjectForKey:nsKey];
|
|
48
|
+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:nsKey];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void IOSStorageAdapterCpp::setDiskBatch(
|
|
52
|
+
const std::vector<std::string>& keys,
|
|
53
|
+
const std::vector<std::string>& values
|
|
54
|
+
) {
|
|
55
|
+
NSUserDefaults* defaults = NitroDiskDefaults();
|
|
56
|
+
for (size_t i = 0; i < keys.size() && i < values.size(); ++i) {
|
|
57
|
+
NSString* nsKey = [NSString stringWithUTF8String:keys[i].c_str()];
|
|
58
|
+
NSString* nsValue = [NSString stringWithUTF8String:values[i].c_str()];
|
|
59
|
+
[defaults setObject:nsValue forKey:nsKey];
|
|
60
|
+
[[NSUserDefaults standardUserDefaults] removeObjectForKey:nsKey];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
std::vector<std::optional<std::string>> IOSStorageAdapterCpp::getDiskBatch(
|
|
65
|
+
const std::vector<std::string>& keys
|
|
66
|
+
) {
|
|
67
|
+
std::vector<std::optional<std::string>> results;
|
|
68
|
+
results.reserve(keys.size());
|
|
69
|
+
for (const auto& key : keys) {
|
|
70
|
+
results.push_back(getDisk(key));
|
|
71
|
+
}
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void IOSStorageAdapterCpp::deleteDiskBatch(const std::vector<std::string>& keys) {
|
|
76
|
+
for (const auto& key : keys) {
|
|
77
|
+
deleteDisk(key);
|
|
78
|
+
}
|
|
25
79
|
}
|
|
26
80
|
|
|
27
81
|
void IOSStorageAdapterCpp::setSecure(const std::string& key, const std::string& value) {
|
|
@@ -39,7 +93,7 @@ void IOSStorageAdapterCpp::setSecure(const std::string& key, const std::string&
|
|
|
39
93
|
};
|
|
40
94
|
|
|
41
95
|
OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)updateAttributes);
|
|
42
|
-
|
|
96
|
+
|
|
43
97
|
if (status == errSecItemNotFound) {
|
|
44
98
|
NSMutableDictionary* addQuery = [query mutableCopy];
|
|
45
99
|
addQuery[(__bridge id)kSecValueData] = data;
|
|
@@ -75,9 +129,38 @@ void IOSStorageAdapterCpp::deleteSecure(const std::string& key) {
|
|
|
75
129
|
SecItemDelete((__bridge CFDictionaryRef)query);
|
|
76
130
|
}
|
|
77
131
|
|
|
132
|
+
void IOSStorageAdapterCpp::setSecureBatch(
|
|
133
|
+
const std::vector<std::string>& keys,
|
|
134
|
+
const std::vector<std::string>& values
|
|
135
|
+
) {
|
|
136
|
+
for (size_t i = 0; i < keys.size() && i < values.size(); ++i) {
|
|
137
|
+
setSecure(keys[i], values[i]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
std::vector<std::optional<std::string>> IOSStorageAdapterCpp::getSecureBatch(
|
|
142
|
+
const std::vector<std::string>& keys
|
|
143
|
+
) {
|
|
144
|
+
std::vector<std::optional<std::string>> results;
|
|
145
|
+
results.reserve(keys.size());
|
|
146
|
+
for (const auto& key : keys) {
|
|
147
|
+
results.push_back(getSecure(key));
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
void IOSStorageAdapterCpp::deleteSecureBatch(const std::vector<std::string>& keys) {
|
|
153
|
+
for (const auto& key : keys) {
|
|
154
|
+
deleteSecure(key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
78
158
|
void IOSStorageAdapterCpp::clearDisk() {
|
|
79
|
-
|
|
80
|
-
[
|
|
159
|
+
NSUserDefaults* defaults = NitroDiskDefaults();
|
|
160
|
+
NSDictionary<NSString*, id>* entries = [defaults dictionaryRepresentation];
|
|
161
|
+
for (NSString* key in entries) {
|
|
162
|
+
[defaults removeObjectForKey:key];
|
|
163
|
+
}
|
|
81
164
|
}
|
|
82
165
|
|
|
83
166
|
void IOSStorageAdapterCpp::clearSecure() {
|