react-native-nitro-storage 0.3.0 → 0.3.2

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.
Files changed (53) hide show
  1. package/README.md +594 -247
  2. package/android/CMakeLists.txt +2 -0
  3. package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +102 -11
  4. package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +16 -0
  5. package/android/src/main/java/com/nitrostorage/AndroidStorageAdapter.kt +154 -34
  6. package/android/src/main/java/com/nitrostorage/NitroStoragePackage.kt +2 -2
  7. package/cpp/bindings/HybridStorage.cpp +176 -21
  8. package/cpp/bindings/HybridStorage.hpp +29 -2
  9. package/cpp/core/NativeStorageAdapter.hpp +16 -0
  10. package/ios/IOSStorageAdapterCpp.hpp +20 -0
  11. package/ios/IOSStorageAdapterCpp.mm +239 -32
  12. package/lib/commonjs/Storage.types.js +23 -1
  13. package/lib/commonjs/Storage.types.js.map +1 -1
  14. package/lib/commonjs/index.js +292 -75
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/index.web.js +473 -86
  17. package/lib/commonjs/index.web.js.map +1 -1
  18. package/lib/commonjs/internal.js +10 -0
  19. package/lib/commonjs/internal.js.map +1 -1
  20. package/lib/commonjs/storage-hooks.js +36 -0
  21. package/lib/commonjs/storage-hooks.js.map +1 -0
  22. package/lib/module/Storage.types.js +22 -0
  23. package/lib/module/Storage.types.js.map +1 -1
  24. package/lib/module/index.js +264 -75
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/index.web.js +445 -86
  27. package/lib/module/index.web.js.map +1 -1
  28. package/lib/module/internal.js +8 -0
  29. package/lib/module/internal.js.map +1 -1
  30. package/lib/module/storage-hooks.js +30 -0
  31. package/lib/module/storage-hooks.js.map +1 -0
  32. package/lib/typescript/Storage.nitro.d.ts +12 -0
  33. package/lib/typescript/Storage.nitro.d.ts.map +1 -1
  34. package/lib/typescript/Storage.types.d.ts +20 -0
  35. package/lib/typescript/Storage.types.d.ts.map +1 -1
  36. package/lib/typescript/index.d.ts +33 -10
  37. package/lib/typescript/index.d.ts.map +1 -1
  38. package/lib/typescript/index.web.d.ts +45 -10
  39. package/lib/typescript/index.web.d.ts.map +1 -1
  40. package/lib/typescript/internal.d.ts +2 -0
  41. package/lib/typescript/internal.d.ts.map +1 -1
  42. package/lib/typescript/storage-hooks.d.ts +10 -0
  43. package/lib/typescript/storage-hooks.d.ts.map +1 -0
  44. package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +12 -0
  45. package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +12 -0
  46. package/package.json +8 -3
  47. package/src/Storage.nitro.ts +13 -2
  48. package/src/Storage.types.ts +22 -0
  49. package/src/index.ts +382 -123
  50. package/src/index.web.ts +618 -134
  51. package/src/internal.ts +14 -4
  52. package/src/migration.ts +1 -1
  53. package/src/storage-hooks.ts +48 -0
@@ -55,10 +55,22 @@ namespace margelo::nitro::NitroStorage {
55
55
  virtual std::optional<std::string> get(const std::string& key, double scope) = 0;
56
56
  virtual void remove(const std::string& key, double scope) = 0;
57
57
  virtual void clear(double scope) = 0;
58
+ virtual bool has(const std::string& key, double scope) = 0;
59
+ virtual std::vector<std::string> getAllKeys(double scope) = 0;
60
+ virtual double size(double scope) = 0;
58
61
  virtual void setBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values, double scope) = 0;
59
62
  virtual std::vector<std::string> getBatch(const std::vector<std::string>& keys, double scope) = 0;
60
63
  virtual void removeBatch(const std::vector<std::string>& keys, double scope) = 0;
64
+ virtual void removeByPrefix(const std::string& prefix, double scope) = 0;
61
65
  virtual std::function<void()> addOnChange(double scope, const std::function<void(const std::string& /* key */, const std::optional<std::string>& /* value */)>& callback) = 0;
66
+ virtual void setSecureAccessControl(double level) = 0;
67
+ virtual void setSecureWritesAsync(bool enabled) = 0;
68
+ virtual void setKeychainAccessGroup(const std::string& group) = 0;
69
+ virtual void setSecureBiometric(const std::string& key, const std::string& value) = 0;
70
+ virtual std::optional<std::string> getSecureBiometric(const std::string& key) = 0;
71
+ virtual void deleteSecureBiometric(const std::string& key) = 0;
72
+ virtual bool hasSecureBiometric(const std::string& key) = 0;
73
+ virtual void clearSecureBiometric() = 0;
62
74
 
63
75
  protected:
64
76
  // Hybrid Setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-storage",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
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",
@@ -33,7 +33,7 @@
33
33
  "!**/__tests__",
34
34
  "!**/__fixtures__",
35
35
  "!**/__mocks__",
36
- "!cpp/core/*Test.cpp",
36
+ "!cpp/**/*Test.cpp",
37
37
  "!cpp/build",
38
38
  "!android/build",
39
39
  "!android/.cxx",
@@ -43,12 +43,17 @@
43
43
  "build": "bob build",
44
44
  "clean": "rimraf lib nitrogen/generated",
45
45
  "codegen": "nitrogen --logLevel=\"debug\"",
46
+ "lint": "bunx eslint src --max-warnings=0 --fix",
47
+ "format": "bunx prettier --write \"src/**/*.{ts,tsx}\" \"../../README.md\"",
48
+ "format:check": "bunx prettier --check \"src/**/*.{ts,tsx}\" \"../../README.md\"",
46
49
  "typecheck": "tsc --noEmit",
50
+ "test:types": "tsc --noEmit -p tsconfig.types.json",
47
51
  "test": "jest",
48
52
  "test:coverage": "jest --coverage",
49
53
  "benchmark": "node scripts/benchmark-check.js",
50
54
  "test:cpp": "node scripts/test-cpp.js",
51
- "prepublishOnly": "bun run clean && bun run codegen && bun run build && bun run benchmark",
55
+ "check:pack": "node scripts/check-pack-contents.js",
56
+ "prepublishOnly": "bun run clean && bun run codegen && bun run build && bun run test:types && bun run benchmark",
52
57
  "prepack": "node -e \"const fs=require('fs'); fs.copyFileSync('../../README.md','./README.md'); try{fs.copyFileSync('../../LICENSE','./LICENSE')}catch(e){}\"",
53
58
  "postpack": "node -e \"const fs=require('fs'); ['./README.md','./LICENSE'].forEach(f=>fs.existsSync(f)&&fs.unlinkSync(f))\""
54
59
  },
@@ -1,16 +1,27 @@
1
1
  import { type HybridObject } from "react-native-nitro-modules";
2
- import { StorageScope } from "./Storage.types";
3
2
 
4
3
  export interface Storage extends HybridObject<{ ios: "c++"; android: "c++" }> {
5
4
  set(key: string, value: string, scope: number): void;
6
5
  get(key: string, scope: number): string | undefined;
7
6
  remove(key: string, scope: number): void;
8
7
  clear(scope: number): void;
8
+ has(key: string, scope: number): boolean;
9
+ getAllKeys(scope: number): string[];
10
+ size(scope: number): number;
9
11
  setBatch(keys: string[], values: string[], scope: number): void;
10
12
  getBatch(keys: string[], scope: number): (string | undefined)[];
11
13
  removeBatch(keys: string[], scope: number): void;
14
+ removeByPrefix(prefix: string, scope: number): void;
12
15
  addOnChange(
13
16
  scope: number,
14
- callback: (key: string, value: string | undefined) => void
17
+ callback: (key: string, value: string | undefined) => void,
15
18
  ): () => void;
19
+ setSecureAccessControl(level: number): void;
20
+ setSecureWritesAsync(enabled: boolean): void;
21
+ setKeychainAccessGroup(group: string): void;
22
+ setSecureBiometric(key: string, value: string): void;
23
+ getSecureBiometric(key: string): string | undefined;
24
+ deleteSecureBiometric(key: string): void;
25
+ hasSecureBiometric(key: string): boolean;
26
+ clearSecureBiometric(): void;
16
27
  }
@@ -3,3 +3,25 @@ export enum StorageScope {
3
3
  Disk = 1,
4
4
  Secure = 2,
5
5
  }
6
+
7
+ export enum AccessControl {
8
+ /** Accessible when unlocked (default). */
9
+ WhenUnlocked = 0,
10
+ /** Accessible after first unlock until restart. Good for background token refresh. */
11
+ AfterFirstUnlock = 1,
12
+ /** Accessible only when passcode is set, non-migratable. */
13
+ WhenPasscodeSetThisDeviceOnly = 2,
14
+ /** Same as WhenUnlocked but non-migratable between devices. */
15
+ WhenUnlockedThisDeviceOnly = 3,
16
+ /** Same as AfterFirstUnlock but non-migratable. */
17
+ AfterFirstUnlockThisDeviceOnly = 4,
18
+ }
19
+
20
+ export enum BiometricLevel {
21
+ /** No biometric requirement (default). */
22
+ None = 0,
23
+ /** Require biometric or passcode for each access. */
24
+ BiometryOrPasscode = 1,
25
+ /** Require biometric only (no passcode fallback). */
26
+ BiometryOnly = 2,
27
+ }