react-native-nitro-storage 0.3.2 → 0.4.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.
Files changed (36) hide show
  1. package/README.md +141 -30
  2. package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +22 -2
  3. package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +3 -0
  4. package/android/src/main/java/com/nitrostorage/AndroidStorageAdapter.kt +54 -5
  5. package/cpp/bindings/HybridStorage.cpp +167 -22
  6. package/cpp/bindings/HybridStorage.hpp +12 -1
  7. package/cpp/core/NativeStorageAdapter.hpp +3 -0
  8. package/ios/IOSStorageAdapterCpp.hpp +16 -0
  9. package/ios/IOSStorageAdapterCpp.mm +135 -11
  10. package/lib/commonjs/index.js +466 -275
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/index.web.js +564 -270
  13. package/lib/commonjs/index.web.js.map +1 -1
  14. package/lib/commonjs/internal.js +25 -0
  15. package/lib/commonjs/internal.js.map +1 -1
  16. package/lib/module/index.js +466 -277
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/module/index.web.js +564 -272
  19. package/lib/module/index.web.js.map +1 -1
  20. package/lib/module/internal.js +24 -0
  21. package/lib/module/internal.js.map +1 -1
  22. package/lib/typescript/Storage.nitro.d.ts +2 -0
  23. package/lib/typescript/Storage.nitro.d.ts.map +1 -1
  24. package/lib/typescript/index.d.ts +38 -1
  25. package/lib/typescript/index.d.ts.map +1 -1
  26. package/lib/typescript/index.web.d.ts +40 -1
  27. package/lib/typescript/index.web.d.ts.map +1 -1
  28. package/lib/typescript/internal.d.ts +1 -0
  29. package/lib/typescript/internal.d.ts.map +1 -1
  30. package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +2 -0
  31. package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +2 -0
  32. package/package.json +1 -1
  33. package/src/Storage.nitro.ts +2 -0
  34. package/src/index.ts +616 -296
  35. package/src/index.web.ts +728 -288
  36. package/src/internal.ts +28 -0
package/src/internal.ts CHANGED
@@ -5,6 +5,7 @@ export const NATIVE_BATCH_MISSING_SENTINEL =
5
5
  "__nitro_storage_batch_missing__::v1";
6
6
  const PRIMITIVE_FAST_PATH_PREFIX = "__nitro_storage_primitive__:";
7
7
  const NAMESPACE_SEPARATOR = ":";
8
+ const VERSION_TOKEN_PREFIX = "__nitro_storage_version__:";
8
9
 
9
10
  export type StoredEnvelope = {
10
11
  __nitroStorageEnvelope: true;
@@ -142,3 +143,30 @@ export function deserializeWithPrimitiveFastPath<T>(value: string): T {
142
143
  return value as T;
143
144
  }
144
145
  }
146
+
147
+ function fnv1aHash(value: string): string {
148
+ let hash = 0x811c9dc5;
149
+ for (let index = 0; index < value.length; index += 1) {
150
+ hash ^= value.charCodeAt(index);
151
+ hash = Math.imul(hash, 0x01000193);
152
+ }
153
+ return (hash >>> 0).toString(16).padStart(8, "0");
154
+ }
155
+
156
+ export function toVersionToken(raw: unknown): string {
157
+ if (raw === undefined) {
158
+ return `${VERSION_TOKEN_PREFIX}missing`;
159
+ }
160
+
161
+ if (typeof raw === "string") {
162
+ return `${VERSION_TOKEN_PREFIX}${raw.length}:${fnv1aHash(raw)}`;
163
+ }
164
+
165
+ let normalized: string;
166
+ try {
167
+ normalized = JSON.stringify(raw) ?? String(raw);
168
+ } catch {
169
+ normalized = String(raw);
170
+ }
171
+ return `${VERSION_TOKEN_PREFIX}${normalized.length}:${fnv1aHash(normalized)}`;
172
+ }