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.
- package/README.md +141 -30
- package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +22 -2
- package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +3 -0
- 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 +466 -275
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +564 -270
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/internal.js +25 -0
- package/lib/commonjs/internal.js.map +1 -1
- package/lib/module/index.js +466 -277
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +564 -272
- package/lib/module/index.web.js.map +1 -1
- 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 +38 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +40 -1
- package/lib/typescript/index.web.d.ts.map +1 -1
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/internal.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +2 -0
- package/package.json +1 -1
- package/src/Storage.nitro.ts +2 -0
- package/src/index.ts +616 -296
- package/src/index.web.ts +728 -288
- 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
|
+
}
|