react-native-nitro-storage 0.3.2 → 0.4.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/README.md +192 -30
- package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +22 -2
- package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +3 -1
- package/android/src/main/java/com/nitrostorage/AndroidStorageAdapter.kt +54 -5
- package/cpp/bindings/HybridStorage.cpp +167 -22
- package/cpp/bindings/HybridStorage.hpp +12 -1
- package/cpp/core/NativeStorageAdapter.hpp +3 -0
- package/ios/IOSStorageAdapterCpp.hpp +16 -0
- package/ios/IOSStorageAdapterCpp.mm +135 -11
- package/lib/commonjs/index.js +522 -275
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +614 -270
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/indexeddb-backend.js +130 -0
- package/lib/commonjs/indexeddb-backend.js.map +1 -0
- package/lib/commonjs/internal.js +25 -0
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/module/index.js +516 -277
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +608 -272
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/indexeddb-backend.js +126 -0
- package/lib/module/indexeddb-backend.js.map +1 -0
- package/lib/module/internal.js +24 -0
- package/lib/module/internal.js.map +1 -1
- package/lib/typescript/Storage.nitro.d.ts +2 -0
- package/lib/typescript/Storage.nitro.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +40 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +42 -1
- package/lib/typescript/index.web.d.ts.map +1 -1
- package/lib/typescript/indexeddb-backend.d.ts +29 -0
- package/lib/typescript/indexeddb-backend.d.ts.map +1 -0
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/internal.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroStorageOnLoad.cpp +22 -17
- package/nitrogen/generated/android/NitroStorageOnLoad.hpp +13 -4
- package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +2 -0
- package/package.json +7 -3
- package/src/Storage.nitro.ts +2 -0
- package/src/index.ts +671 -296
- package/src/index.web.ts +776 -288
- package/src/indexeddb-backend.ts +143 -0
- package/src/internal.ts +28 -0
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
import { StorageScope, AccessControl } from "./Storage.types";
|
|
1
|
+
import { StorageScope, AccessControl, BiometricLevel } from "./Storage.types";
|
|
2
2
|
export { StorageScope, AccessControl, BiometricLevel } from "./Storage.types";
|
|
3
3
|
export { migrateFromMMKV } from "./migration";
|
|
4
4
|
export type Validator<T> = (value: unknown) => value is T;
|
|
5
5
|
export type ExpirationConfig = {
|
|
6
6
|
ttlMs: number;
|
|
7
7
|
};
|
|
8
|
+
export type StorageVersion = string;
|
|
9
|
+
export type VersionedValue<T> = {
|
|
10
|
+
value: T;
|
|
11
|
+
version: StorageVersion;
|
|
12
|
+
};
|
|
13
|
+
export type StorageMetricsEvent = {
|
|
14
|
+
operation: string;
|
|
15
|
+
scope: StorageScope;
|
|
16
|
+
durationMs: number;
|
|
17
|
+
keysCount: number;
|
|
18
|
+
};
|
|
19
|
+
export type StorageMetricsObserver = (event: StorageMetricsEvent) => void;
|
|
20
|
+
export type StorageMetricSummary = {
|
|
21
|
+
count: number;
|
|
22
|
+
totalDurationMs: number;
|
|
23
|
+
avgDurationMs: number;
|
|
24
|
+
maxDurationMs: number;
|
|
25
|
+
};
|
|
26
|
+
export type WebSecureStorageBackend = {
|
|
27
|
+
getItem: (key: string) => string | null;
|
|
28
|
+
setItem: (key: string, value: string) => void;
|
|
29
|
+
removeItem: (key: string) => void;
|
|
30
|
+
clear: () => void;
|
|
31
|
+
getAllKeys: () => string[];
|
|
32
|
+
};
|
|
8
33
|
export type MigrationContext = {
|
|
9
34
|
scope: StorageScope;
|
|
10
35
|
getRaw: (key: string) => string | undefined;
|
|
@@ -31,6 +56,7 @@ export interface Storage {
|
|
|
31
56
|
clear(scope: number): void;
|
|
32
57
|
has(key: string, scope: number): boolean;
|
|
33
58
|
getAllKeys(scope: number): string[];
|
|
59
|
+
getKeysByPrefix(prefix: string, scope: number): string[];
|
|
34
60
|
size(scope: number): number;
|
|
35
61
|
setBatch(keys: string[], values: string[], scope: number): void;
|
|
36
62
|
getBatch(keys: string[], scope: number): (string | undefined)[];
|
|
@@ -41,6 +67,7 @@ export interface Storage {
|
|
|
41
67
|
setSecureWritesAsync(enabled: boolean): void;
|
|
42
68
|
setKeychainAccessGroup(group: string): void;
|
|
43
69
|
setSecureBiometric(key: string, value: string): void;
|
|
70
|
+
setSecureBiometricWithLevel(key: string, value: string, level: number): void;
|
|
44
71
|
getSecureBiometric(key: string): string | undefined;
|
|
45
72
|
deleteSecureBiometric(key: string): void;
|
|
46
73
|
hasSecureBiometric(key: string): boolean;
|
|
@@ -53,13 +80,21 @@ export declare const storage: {
|
|
|
53
80
|
clearBiometric: () => void;
|
|
54
81
|
has: (key: string, scope: StorageScope) => boolean;
|
|
55
82
|
getAllKeys: (scope: StorageScope) => string[];
|
|
83
|
+
getKeysByPrefix: (prefix: string, scope: StorageScope) => string[];
|
|
84
|
+
getByPrefix: (prefix: string, scope: StorageScope) => Record<string, string>;
|
|
56
85
|
getAll: (scope: StorageScope) => Record<string, string>;
|
|
57
86
|
size: (scope: StorageScope) => number;
|
|
58
87
|
setAccessControl: (_level: AccessControl) => void;
|
|
59
88
|
setSecureWritesAsync: (_enabled: boolean) => void;
|
|
60
89
|
flushSecureWrites: () => void;
|
|
61
90
|
setKeychainAccessGroup: (_group: string) => void;
|
|
91
|
+
setMetricsObserver: (observer?: StorageMetricsObserver) => void;
|
|
92
|
+
getMetricsSnapshot: () => Record<string, StorageMetricSummary>;
|
|
93
|
+
resetMetrics: () => void;
|
|
94
|
+
import: (data: Record<string, string>, scope: StorageScope) => void;
|
|
62
95
|
};
|
|
96
|
+
export declare function setWebSecureStorageBackend(backend?: WebSecureStorageBackend): void;
|
|
97
|
+
export declare function getWebSecureStorageBackend(): WebSecureStorageBackend | undefined;
|
|
63
98
|
export interface StorageItemConfig<T> {
|
|
64
99
|
key: string;
|
|
65
100
|
scope: StorageScope;
|
|
@@ -74,11 +109,14 @@ export interface StorageItemConfig<T> {
|
|
|
74
109
|
coalesceSecureWrites?: boolean;
|
|
75
110
|
namespace?: string;
|
|
76
111
|
biometric?: boolean;
|
|
112
|
+
biometricLevel?: BiometricLevel;
|
|
77
113
|
accessControl?: AccessControl;
|
|
78
114
|
}
|
|
79
115
|
export interface StorageItem<T> {
|
|
80
116
|
get: () => T;
|
|
117
|
+
getWithVersion: () => VersionedValue<T>;
|
|
81
118
|
set: (value: T | ((prev: T) => T)) => void;
|
|
119
|
+
setIfVersion: (version: StorageVersion, value: T | ((prev: T) => T)) => boolean;
|
|
82
120
|
delete: () => void;
|
|
83
121
|
has: () => boolean;
|
|
84
122
|
subscribe: (callback: () => void) => () => void;
|
|
@@ -89,11 +127,13 @@ export interface StorageItem<T> {
|
|
|
89
127
|
}
|
|
90
128
|
export declare function createStorageItem<T = undefined>(config: StorageItemConfig<T>): StorageItem<T>;
|
|
91
129
|
export { useStorage, useStorageSelector, useSetStorage } from "./storage-hooks";
|
|
130
|
+
export { createIndexedDBBackend } from "./indexeddb-backend";
|
|
92
131
|
type BatchReadItem<T> = Pick<StorageItem<T>, "key" | "scope" | "get" | "deserialize"> & {
|
|
93
132
|
_hasValidation?: boolean;
|
|
94
133
|
_hasExpiration?: boolean;
|
|
95
134
|
_readCacheEnabled?: boolean;
|
|
96
135
|
_isBiometric?: boolean;
|
|
136
|
+
_defaultValue?: unknown;
|
|
97
137
|
_secureAccessControl?: AccessControl;
|
|
98
138
|
};
|
|
99
139
|
type BatchRemoveItem = Pick<StorageItem<unknown>, "key" | "scope" | "delete">;
|
|
@@ -110,6 +150,7 @@ export declare function runTransaction<T>(scope: StorageScope, transaction: (con
|
|
|
110
150
|
export type SecureAuthStorageConfig<K extends string = string> = Record<K, {
|
|
111
151
|
ttlMs?: number;
|
|
112
152
|
biometric?: boolean;
|
|
153
|
+
biometricLevel?: BiometricLevel;
|
|
113
154
|
accessControl?: AccessControl;
|
|
114
155
|
}>;
|
|
115
156
|
export declare function createSecureAuthStorage<K extends string>(config: SecureAuthStorageConfig<K>, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../src/index.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../src/index.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAc9E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;AAC1D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,mBAAmB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SAAS,MAAM,EACtD,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CA6BhC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WebSecureStorageBackend } from "./index.web";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a `WebSecureStorageBackend` backed by IndexedDB.
|
|
4
|
+
*
|
|
5
|
+
* IndexedDB is async, but `WebSecureStorageBackend` requires a synchronous
|
|
6
|
+
* interface. This implementation bridges the gap with a write-through in-memory
|
|
7
|
+
* cache:
|
|
8
|
+
*
|
|
9
|
+
* - **Reads** are always served from the in-memory cache (synchronous, O(1)).
|
|
10
|
+
* - **Writes** update the cache synchronously, then persist to IndexedDB
|
|
11
|
+
* asynchronously in the background.
|
|
12
|
+
* - **Initialisation**: the returned backend pre-loads all persisted entries
|
|
13
|
+
* from IndexedDB into memory before resolving, so the first synchronous read
|
|
14
|
+
* after `await createIndexedDBBackend()` already returns the correct value.
|
|
15
|
+
*
|
|
16
|
+
* @param dbName Name of the IndexedDB database. Defaults to `"nitro-storage-secure"`.
|
|
17
|
+
* @param storeName Name of the object store inside the database. Defaults to `"keyvalue"`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { setWebSecureStorageBackend } from "react-native-nitro-storage";
|
|
22
|
+
* import { createIndexedDBBackend } from "react-native-nitro-storage/indexeddb-backend";
|
|
23
|
+
*
|
|
24
|
+
* const backend = await createIndexedDBBackend();
|
|
25
|
+
* setWebSecureStorageBackend(backend);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createIndexedDBBackend(dbName?: string, storeName?: string): Promise<WebSecureStorageBackend>;
|
|
29
|
+
//# sourceMappingURL=indexeddb-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexeddb-backend.d.ts","sourceRoot":"","sources":["../../src/indexeddb-backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAgC3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,SAAkB,EACxB,SAAS,SAAqB,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAiFlC"}
|
|
@@ -18,4 +18,5 @@ export declare function prefixKey(namespace: string | undefined, key: string): s
|
|
|
18
18
|
export declare function isNamespaced(key: string, namespace: string): boolean;
|
|
19
19
|
export declare function serializeWithPrimitiveFastPath<T>(value: T): string;
|
|
20
20
|
export declare function deserializeWithPrimitiveFastPath<T>(value: string): T;
|
|
21
|
+
export declare function toVersionToken(raw: unknown): string;
|
|
21
22
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,eAAO,MAAM,qBAAqB,wCAAwC,CAAC;AAC3E,eAAO,MAAM,6BAA6B,wCACH,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,eAAO,MAAM,qBAAqB,wCAAwC,CAAC;AAC3E,eAAO,MAAM,6BAA6B,wCACH,CAAC;AAKxC,MAAM,MAAM,cAAc,GAAG;IAC3B,sBAAsB,EAAE,IAAI,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAWxE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAQ1D;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,KAAK,EAAE,YAAY,GAClB,IAAI,CAaN;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CA4BlE;AAED,wBAAgB,gCAAgC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAkCpE;AAWD,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAgBnD"}
|
|
@@ -20,25 +20,30 @@
|
|
|
20
20
|
namespace margelo::nitro::NitroStorage {
|
|
21
21
|
|
|
22
22
|
int initialize(JavaVM* vm) {
|
|
23
|
+
return facebook::jni::initialize(vm, []() {
|
|
24
|
+
::margelo::nitro::NitroStorage::registerAllNatives();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
void registerAllNatives() {
|
|
23
31
|
using namespace margelo::nitro;
|
|
24
32
|
using namespace margelo::nitro::NitroStorage;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
});
|
|
33
|
+
|
|
34
|
+
// Register native JNI methods
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Register Nitro Hybrid Objects
|
|
38
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
39
|
+
"Storage",
|
|
40
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
41
|
+
static_assert(std::is_default_constructible_v<HybridStorage>,
|
|
42
|
+
"The HybridObject \"HybridStorage\" is not default-constructible! "
|
|
43
|
+
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
44
|
+
return std::make_shared<HybridStorage>();
|
|
45
|
+
}
|
|
46
|
+
);
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
} // namespace margelo::nitro::NitroStorage
|
|
@@ -6,20 +6,29 @@
|
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
9
10
|
#include <NitroModules/NitroDefines.hpp>
|
|
10
11
|
|
|
11
12
|
namespace margelo::nitro::NitroStorage {
|
|
12
13
|
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`)
|
|
18
|
+
* Register the native (C++) part of NitroStorage, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
16
21
|
* Example:
|
|
17
22
|
* ```cpp (cpp-adapter.cpp)
|
|
18
23
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
-
* return
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroStorage HybridObjects
|
|
26
|
+
* margelo::nitro::NitroStorage::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
20
29
|
* }
|
|
21
30
|
* ```
|
|
22
31
|
*/
|
|
23
|
-
|
|
32
|
+
void registerAllNatives();
|
|
24
33
|
|
|
25
34
|
} // namespace margelo::nitro::NitroStorage
|
|
@@ -20,6 +20,7 @@ namespace margelo::nitro::NitroStorage {
|
|
|
20
20
|
prototype.registerHybridMethod("clear", &HybridStorageSpec::clear);
|
|
21
21
|
prototype.registerHybridMethod("has", &HybridStorageSpec::has);
|
|
22
22
|
prototype.registerHybridMethod("getAllKeys", &HybridStorageSpec::getAllKeys);
|
|
23
|
+
prototype.registerHybridMethod("getKeysByPrefix", &HybridStorageSpec::getKeysByPrefix);
|
|
23
24
|
prototype.registerHybridMethod("size", &HybridStorageSpec::size);
|
|
24
25
|
prototype.registerHybridMethod("setBatch", &HybridStorageSpec::setBatch);
|
|
25
26
|
prototype.registerHybridMethod("getBatch", &HybridStorageSpec::getBatch);
|
|
@@ -30,6 +31,7 @@ namespace margelo::nitro::NitroStorage {
|
|
|
30
31
|
prototype.registerHybridMethod("setSecureWritesAsync", &HybridStorageSpec::setSecureWritesAsync);
|
|
31
32
|
prototype.registerHybridMethod("setKeychainAccessGroup", &HybridStorageSpec::setKeychainAccessGroup);
|
|
32
33
|
prototype.registerHybridMethod("setSecureBiometric", &HybridStorageSpec::setSecureBiometric);
|
|
34
|
+
prototype.registerHybridMethod("setSecureBiometricWithLevel", &HybridStorageSpec::setSecureBiometricWithLevel);
|
|
33
35
|
prototype.registerHybridMethod("getSecureBiometric", &HybridStorageSpec::getSecureBiometric);
|
|
34
36
|
prototype.registerHybridMethod("deleteSecureBiometric", &HybridStorageSpec::deleteSecureBiometric);
|
|
35
37
|
prototype.registerHybridMethod("hasSecureBiometric", &HybridStorageSpec::hasSecureBiometric);
|
|
@@ -57,6 +57,7 @@ namespace margelo::nitro::NitroStorage {
|
|
|
57
57
|
virtual void clear(double scope) = 0;
|
|
58
58
|
virtual bool has(const std::string& key, double scope) = 0;
|
|
59
59
|
virtual std::vector<std::string> getAllKeys(double scope) = 0;
|
|
60
|
+
virtual std::vector<std::string> getKeysByPrefix(const std::string& prefix, double scope) = 0;
|
|
60
61
|
virtual double size(double scope) = 0;
|
|
61
62
|
virtual void setBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values, double scope) = 0;
|
|
62
63
|
virtual std::vector<std::string> getBatch(const std::vector<std::string>& keys, double scope) = 0;
|
|
@@ -67,6 +68,7 @@ namespace margelo::nitro::NitroStorage {
|
|
|
67
68
|
virtual void setSecureWritesAsync(bool enabled) = 0;
|
|
68
69
|
virtual void setKeychainAccessGroup(const std::string& group) = 0;
|
|
69
70
|
virtual void setSecureBiometric(const std::string& key, const std::string& value) = 0;
|
|
71
|
+
virtual void setSecureBiometricWithLevel(const std::string& key, const std::string& value, double level) = 0;
|
|
70
72
|
virtual std::optional<std::string> getSecureBiometric(const std::string& key) = 0;
|
|
71
73
|
virtual void deleteSecureBiometric(const std::string& key) = 0;
|
|
72
74
|
virtual bool hasSecureBiometric(const std::string& key) = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The fastest, most complete storage solution for React Native. Synchronous Memory, Disk, and Secure storage in one unified API. Built with Nitro Modules.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"browser": "./src/index.web.ts",
|
|
17
17
|
"default": "./lib/commonjs/index.js"
|
|
18
18
|
},
|
|
19
|
+
"./indexeddb-backend": {
|
|
20
|
+
"types": "./lib/typescript/indexeddb-backend.d.ts",
|
|
21
|
+
"default": "./lib/commonjs/indexeddb-backend.js"
|
|
22
|
+
},
|
|
19
23
|
"./app.plugin": "./app.plugin.js",
|
|
20
24
|
"./app.plugin.js": "./app.plugin.js",
|
|
21
25
|
"./package.json": "./package.json"
|
|
@@ -91,11 +95,11 @@
|
|
|
91
95
|
"registry": "https://registry.npmjs.org/"
|
|
92
96
|
},
|
|
93
97
|
"devDependencies": {
|
|
94
|
-
"@expo/config-plugins": "^
|
|
98
|
+
"@expo/config-plugins": "^55.0.3",
|
|
95
99
|
"@react-native/babel-preset": "^0.83.2",
|
|
96
100
|
"@testing-library/react-hooks": "^8.0.1",
|
|
97
101
|
"@testing-library/react-native": "^13.3.3",
|
|
98
|
-
"@types/react": "~19.
|
|
102
|
+
"@types/react": "~19.2.0",
|
|
99
103
|
"typescript": "^5.9.3"
|
|
100
104
|
},
|
|
101
105
|
"peerDependencies": {
|
package/src/Storage.nitro.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface Storage extends HybridObject<{ ios: "c++"; android: "c++" }> {
|
|
|
7
7
|
clear(scope: number): void;
|
|
8
8
|
has(key: string, scope: number): boolean;
|
|
9
9
|
getAllKeys(scope: number): string[];
|
|
10
|
+
getKeysByPrefix(prefix: string, scope: number): string[];
|
|
10
11
|
size(scope: number): number;
|
|
11
12
|
setBatch(keys: string[], values: string[], scope: number): void;
|
|
12
13
|
getBatch(keys: string[], scope: number): (string | undefined)[];
|
|
@@ -20,6 +21,7 @@ export interface Storage extends HybridObject<{ ios: "c++"; android: "c++" }> {
|
|
|
20
21
|
setSecureWritesAsync(enabled: boolean): void;
|
|
21
22
|
setKeychainAccessGroup(group: string): void;
|
|
22
23
|
setSecureBiometric(key: string, value: string): void;
|
|
24
|
+
setSecureBiometricWithLevel(key: string, value: string, level: number): void;
|
|
23
25
|
getSecureBiometric(key: string): string | undefined;
|
|
24
26
|
deleteSecureBiometric(key: string): void;
|
|
25
27
|
hasSecureBiometric(key: string): boolean;
|