react-native-nitro-storage 0.5.5 → 0.5.7
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 +267 -320
- package/ios/IOSStorageAdapterCpp.mm +126 -80
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/storage-hooks.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/storage-hooks.js.map +1 -1
- package/lib/typescript/index.d.ts +11 -6
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +7 -2
- package/lib/typescript/index.web.d.ts.map +1 -1
- package/lib/typescript/storage-hooks.d.ts +5 -4
- package/lib/typescript/storage-hooks.d.ts.map +1 -1
- package/package.json +9 -5
- package/react-native-nitro-storage.podspec +4 -0
- package/src/index.ts +16 -10
- package/src/index.web.ts +12 -6
- package/src/storage-hooks.ts +6 -6
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type HookStorageItem<T> = {
|
|
2
2
|
get: () => T;
|
|
3
|
-
set:
|
|
3
|
+
set: StorageSetter<T>;
|
|
4
4
|
subscribe: (callback: () => void) => () => void;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
6
|
+
export type StorageSetter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
|
+
export declare function useStorage<T>(item: HookStorageItem<T>): [T, StorageSetter<T>];
|
|
8
|
+
export declare function useStorageSelector<T, TSelected>(item: HookStorageItem<T>, selector: (value: T) => TSelected, isEqual?: (prev: TSelected, next: TSelected) => boolean): [TSelected, StorageSetter<T>];
|
|
9
|
+
export declare function useSetStorage<T>(item: HookStorageItem<T>): StorageSetter<T>;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=storage-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-hooks.d.ts","sourceRoot":"","sources":["../../src/storage-hooks.ts"],"names":[],"mappings":"AAEA,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"storage-hooks.d.ts","sourceRoot":"","sources":["../../src/storage-hooks.ts"],"names":[],"mappings":"AAEA,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;AAErE,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAG7E;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,SAAS,EAC7C,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,EACxB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,SAAS,EACjC,OAAO,GAAE,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,KAAK,OAAmB,GACjE,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAwB/B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAE3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-storage",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Synchronous React Native storage powered by Nitro Modules and JSI: typed Memory, Disk, Keychain/Android Keystore secure storage, biometric auth, MMKV migration, Expo, Zustand/Jotai persistence, and web IndexedDB support.",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"build": "bob build",
|
|
51
51
|
"clean": "rimraf lib nitrogen/generated",
|
|
52
52
|
"codegen": "nitrogen --logLevel=\"debug\"",
|
|
53
|
-
"lint": "bunx eslint src --max-warnings=0
|
|
53
|
+
"lint": "bunx eslint src --max-warnings=0",
|
|
54
|
+
"lint:fix": "bunx eslint src --max-warnings=0 --fix",
|
|
54
55
|
"lint:check": "bunx eslint src --max-warnings=0",
|
|
55
56
|
"format": "bunx prettier --write \"src/**/*.{ts,tsx}\" \"../../README.md\" \"../../CHANGELOG.md\" \"../../SECURITY.md\" \"../../docs/**/*.md\"",
|
|
56
57
|
"format:check": "bunx prettier --check \"src/**/*.{ts,tsx}\" \"../../README.md\" \"../../CHANGELOG.md\" \"../../SECURITY.md\" \"../../docs/**/*.md\"",
|
|
@@ -60,7 +61,10 @@
|
|
|
60
61
|
"test:coverage": "jest --coverage",
|
|
61
62
|
"benchmark": "node scripts/benchmark-check.js",
|
|
62
63
|
"test:cpp": "node scripts/test-cpp.js",
|
|
64
|
+
"test:cpp:asan": "node scripts/test-cpp.js --sanitize=address",
|
|
63
65
|
"test:cpp:coverage": "node scripts/test-cpp.js --coverage",
|
|
66
|
+
"test:cpp:tsan": "node scripts/test-cpp.js --sanitize=thread",
|
|
67
|
+
"test:cpp:ubsan": "node scripts/test-cpp.js --sanitize=undefined",
|
|
64
68
|
"check:pack": "node scripts/check-pack-contents.js",
|
|
65
69
|
"prepublishOnly": "bun run clean && bun run codegen && bun run build && bun run test:types && bun run benchmark",
|
|
66
70
|
"prepack": "node scripts/sync-package-docs.js prepare",
|
|
@@ -111,8 +115,8 @@
|
|
|
111
115
|
"registry": "https://registry.npmjs.org/"
|
|
112
116
|
},
|
|
113
117
|
"devDependencies": {
|
|
114
|
-
"@expo/config-plugins": "^
|
|
115
|
-
"@react-native/babel-preset": "^0.
|
|
118
|
+
"@expo/config-plugins": "^56.0.8",
|
|
119
|
+
"@react-native/babel-preset": "^0.85.3",
|
|
116
120
|
"@testing-library/react-hooks": "^8.0.1",
|
|
117
121
|
"@testing-library/react-native": "^13.3.3",
|
|
118
122
|
"@types/react": "~19.2.0"
|
|
@@ -120,7 +124,7 @@
|
|
|
120
124
|
"peerDependencies": {
|
|
121
125
|
"react": ">=18.2.0",
|
|
122
126
|
"react-native": ">=0.75.0",
|
|
123
|
-
"react-native-nitro-modules": ">=0.35.
|
|
127
|
+
"react-native-nitro-modules": ">=0.35.7"
|
|
124
128
|
},
|
|
125
129
|
"react-native-builder-bob": {
|
|
126
130
|
"source": "src",
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
type StorageEventListener,
|
|
36
36
|
type StorageKeyChangeEvent,
|
|
37
37
|
} from "./storage-events";
|
|
38
|
+
import type { StorageSetter } from "./storage-hooks";
|
|
38
39
|
|
|
39
40
|
export { StorageScope, AccessControl, BiometricLevel } from "./Storage.types";
|
|
40
41
|
export type { Storage } from "./Storage.nitro";
|
|
@@ -54,6 +55,7 @@ export type {
|
|
|
54
55
|
StorageEventListener,
|
|
55
56
|
StorageKeyChangeEvent,
|
|
56
57
|
} from "./storage-events";
|
|
58
|
+
export type { StorageSetter } from "./storage-hooks";
|
|
57
59
|
export type {
|
|
58
60
|
WebDiskStorageBackend,
|
|
59
61
|
WebSecureStorageBackend,
|
|
@@ -1387,7 +1389,7 @@ export async function flushWebStorageBackends(): Promise<void> {
|
|
|
1387
1389
|
// Native platforms do not use web storage backends.
|
|
1388
1390
|
}
|
|
1389
1391
|
|
|
1390
|
-
export
|
|
1392
|
+
export type StorageItemConfig<T> = {
|
|
1391
1393
|
key: string;
|
|
1392
1394
|
scope: StorageScope;
|
|
1393
1395
|
defaultValue?: T;
|
|
@@ -1404,12 +1406,12 @@ export interface StorageItemConfig<T> {
|
|
|
1404
1406
|
biometric?: boolean;
|
|
1405
1407
|
biometricLevel?: BiometricLevel;
|
|
1406
1408
|
accessControl?: AccessControl;
|
|
1407
|
-
}
|
|
1409
|
+
};
|
|
1408
1410
|
|
|
1409
|
-
export
|
|
1411
|
+
export type StorageItem<T> = {
|
|
1410
1412
|
get: () => T;
|
|
1411
1413
|
getWithVersion: () => VersionedValue<T>;
|
|
1412
|
-
set:
|
|
1414
|
+
set: StorageSetter<T>;
|
|
1413
1415
|
setIfVersion: (
|
|
1414
1416
|
version: StorageVersion,
|
|
1415
1417
|
value: T | ((prev: T) => T),
|
|
@@ -1426,7 +1428,7 @@ export interface StorageItem<T> {
|
|
|
1426
1428
|
deserialize: (value: string) => T;
|
|
1427
1429
|
scope: StorageScope;
|
|
1428
1430
|
key: string;
|
|
1429
|
-
}
|
|
1431
|
+
};
|
|
1430
1432
|
|
|
1431
1433
|
type StorageItemInternal<T> = StorageItem<T> & {
|
|
1432
1434
|
_triggerListeners: () => void;
|
|
@@ -2050,16 +2052,20 @@ type BatchReadItem<T> = Pick<
|
|
|
2050
2052
|
_secureAccessControl?: AccessControl;
|
|
2051
2053
|
};
|
|
2052
2054
|
type BatchRemoveItem = Pick<StorageItem<unknown>, "key" | "scope" | "delete">;
|
|
2055
|
+
type BatchValues<TItems extends readonly BatchReadItem<unknown>[]> = {
|
|
2056
|
+
[Index in keyof TItems]: TItems[Index] extends BatchReadItem<infer Value>
|
|
2057
|
+
? Value
|
|
2058
|
+
: never;
|
|
2059
|
+
};
|
|
2053
2060
|
|
|
2054
2061
|
export type StorageBatchSetItem<T> = {
|
|
2055
2062
|
item: StorageItem<T>;
|
|
2056
2063
|
value: T;
|
|
2057
2064
|
};
|
|
2058
2065
|
|
|
2059
|
-
export function getBatch
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
): unknown[] {
|
|
2066
|
+
export function getBatch<
|
|
2067
|
+
const TItems extends readonly BatchReadItem<unknown>[],
|
|
2068
|
+
>(items: TItems, scope: StorageScope): BatchValues<TItems> {
|
|
2063
2069
|
return measureOperation(
|
|
2064
2070
|
"batch:get",
|
|
2065
2071
|
scope,
|
|
@@ -2138,7 +2144,7 @@ export function getBatch(
|
|
|
2138
2144
|
});
|
|
2139
2145
|
},
|
|
2140
2146
|
items.length,
|
|
2141
|
-
)
|
|
2147
|
+
) as BatchValues<TItems>;
|
|
2142
2148
|
}
|
|
2143
2149
|
|
|
2144
2150
|
export function setBatch<T>(
|
package/src/index.web.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
type StorageEventListener,
|
|
36
36
|
type StorageKeyChangeEvent,
|
|
37
37
|
} from "./storage-events";
|
|
38
|
+
import type { StorageSetter } from "./storage-hooks";
|
|
38
39
|
|
|
39
40
|
export { StorageScope, AccessControl, BiometricLevel } from "./Storage.types";
|
|
40
41
|
export { migrateFromMMKV } from "./migration";
|
|
@@ -53,6 +54,7 @@ export type {
|
|
|
53
54
|
StorageEventListener,
|
|
54
55
|
StorageKeyChangeEvent,
|
|
55
56
|
} from "./storage-events";
|
|
57
|
+
export type { StorageSetter } from "./storage-hooks";
|
|
56
58
|
export type {
|
|
57
59
|
WebDiskStorageBackend,
|
|
58
60
|
WebSecureStorageBackend,
|
|
@@ -1924,7 +1926,7 @@ export interface StorageItemConfig<T> {
|
|
|
1924
1926
|
export interface StorageItem<T> {
|
|
1925
1927
|
get: () => T;
|
|
1926
1928
|
getWithVersion: () => VersionedValue<T>;
|
|
1927
|
-
set:
|
|
1929
|
+
set: StorageSetter<T>;
|
|
1928
1930
|
setIfVersion: (
|
|
1929
1931
|
version: StorageVersion,
|
|
1930
1932
|
value: T | ((prev: T) => T),
|
|
@@ -2541,16 +2543,20 @@ type BatchReadItem<T> = Pick<
|
|
|
2541
2543
|
_secureAccessControl?: AccessControl;
|
|
2542
2544
|
};
|
|
2543
2545
|
type BatchRemoveItem = Pick<StorageItem<unknown>, "key" | "scope" | "delete">;
|
|
2546
|
+
type BatchValues<TItems extends readonly BatchReadItem<unknown>[]> = {
|
|
2547
|
+
[Index in keyof TItems]: TItems[Index] extends BatchReadItem<infer Value>
|
|
2548
|
+
? Value
|
|
2549
|
+
: never;
|
|
2550
|
+
};
|
|
2544
2551
|
|
|
2545
2552
|
export type StorageBatchSetItem<T> = {
|
|
2546
2553
|
item: StorageItem<T>;
|
|
2547
2554
|
value: T;
|
|
2548
2555
|
};
|
|
2549
2556
|
|
|
2550
|
-
export function getBatch
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
): unknown[] {
|
|
2557
|
+
export function getBatch<
|
|
2558
|
+
const TItems extends readonly BatchReadItem<unknown>[],
|
|
2559
|
+
>(items: TItems, scope: StorageScope): BatchValues<TItems> {
|
|
2554
2560
|
return measureOperation(
|
|
2555
2561
|
"batch:get",
|
|
2556
2562
|
scope,
|
|
@@ -2626,7 +2632,7 @@ export function getBatch(
|
|
|
2626
2632
|
});
|
|
2627
2633
|
},
|
|
2628
2634
|
items.length,
|
|
2629
|
-
)
|
|
2635
|
+
) as BatchValues<TItems>;
|
|
2630
2636
|
}
|
|
2631
2637
|
|
|
2632
2638
|
export function setBatch<T>(
|
package/src/storage-hooks.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { useRef, useSyncExternalStore } from "react";
|
|
|
2
2
|
|
|
3
3
|
type HookStorageItem<T> = {
|
|
4
4
|
get: () => T;
|
|
5
|
-
set:
|
|
5
|
+
set: StorageSetter<T>;
|
|
6
6
|
subscribe: (callback: () => void) => () => void;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export type StorageSetter<T> = (value: T | ((prev: T) => T)) => void;
|
|
10
|
+
|
|
11
|
+
export function useStorage<T>(item: HookStorageItem<T>): [T, StorageSetter<T>] {
|
|
12
12
|
const value = useSyncExternalStore(item.subscribe, item.get, item.get);
|
|
13
13
|
return [value, item.set];
|
|
14
14
|
}
|
|
@@ -17,7 +17,7 @@ export function useStorageSelector<T, TSelected>(
|
|
|
17
17
|
item: HookStorageItem<T>,
|
|
18
18
|
selector: (value: T) => TSelected,
|
|
19
19
|
isEqual: (prev: TSelected, next: TSelected) => boolean = Object.is,
|
|
20
|
-
): [TSelected,
|
|
20
|
+
): [TSelected, StorageSetter<T>] {
|
|
21
21
|
const selectedRef = useRef<
|
|
22
22
|
{ hasValue: false } | { hasValue: true; value: TSelected }
|
|
23
23
|
>({
|
|
@@ -43,6 +43,6 @@ export function useStorageSelector<T, TSelected>(
|
|
|
43
43
|
return [selectedValue, item.set];
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export function useSetStorage<T>(item: HookStorageItem<T>) {
|
|
46
|
+
export function useSetStorage<T>(item: HookStorageItem<T>): StorageSetter<T> {
|
|
47
47
|
return item.set;
|
|
48
48
|
}
|