react-native-nitro-storage 0.1.1 → 0.1.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.
- package/README.md +43 -22
- package/android/src/main/cpp/AndroidStorageAdapterCpp.cpp +10 -0
- package/android/src/main/cpp/AndroidStorageAdapterCpp.hpp +13 -0
- package/android/src/main/java/com/nitrostorage/AndroidStorageAdapter.kt +10 -0
- package/cpp/bindings/HybridStorage.cpp +50 -0
- package/cpp/bindings/HybridStorage.hpp +4 -0
- package/cpp/core/NativeStorageAdapter.hpp +3 -0
- package/ios/IOSStorageAdapterCpp.hpp +3 -0
- package/ios/IOSStorageAdapterCpp.mm +13 -0
- package/lib/commonjs/Storage.nitro.js +0 -7
- package/lib/commonjs/Storage.nitro.js.map +1 -1
- package/lib/commonjs/Storage.types.js +13 -0
- package/lib/commonjs/Storage.types.js.map +1 -0
- package/lib/commonjs/index.js +69 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +268 -0
- package/lib/commonjs/index.web.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/Storage.nitro.js +1 -6
- package/lib/module/Storage.nitro.js.map +1 -1
- package/lib/module/Storage.types.js +9 -0
- package/lib/module/Storage.types.js.map +1 -0
- package/lib/module/index.js +66 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +257 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/typescript/Storage.nitro.d.ts +5 -6
- package/lib/typescript/Storage.nitro.d.ts.map +1 -1
- package/lib/typescript/Storage.types.d.ts +6 -0
- package/lib/typescript/Storage.types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +12 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +50 -0
- package/lib/typescript/index.web.d.ts.map +1 -0
- package/nitrogen/generated/android/NitroStorage+autolinking.cmake +1 -1
- package/nitrogen/generated/android/NitroStorage+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroStorageOnLoad.cpp +1 -1
- package/nitrogen/generated/android/NitroStorageOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitrostorage/NitroStorageOnLoad.kt +1 -1
- package/nitrogen/generated/ios/NitroStorage+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/NitroStorage-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/NitroStorageAutolinking.mm +1 -1
- package/nitrogen/generated/ios/NitroStorageAutolinking.swift +1 -1
- package/nitrogen/generated/shared/c++/HybridStorageSpec.cpp +5 -1
- package/nitrogen/generated/shared/c++/HybridStorageSpec.hpp +6 -1
- package/package.json +6 -25
- package/src/Storage.nitro.ts +6 -7
- package/src/Storage.types.ts +5 -0
- package/src/index.ts +88 -14
- package/src/index.web.ts +341 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
export let StorageScope = /*#__PURE__*/function (StorageScope) {
|
|
5
|
+
StorageScope[StorageScope["Memory"] = 0] = "Memory";
|
|
6
|
+
StorageScope[StorageScope["Disk"] = 1] = "Disk";
|
|
7
|
+
StorageScope[StorageScope["Secure"] = 2] = "Secure";
|
|
8
|
+
return StorageScope;
|
|
9
|
+
}({});
|
|
10
|
+
const diskListeners = new Map();
|
|
11
|
+
const secureListeners = new Map();
|
|
12
|
+
function notifyDiskListeners(key) {
|
|
13
|
+
diskListeners.get(key)?.forEach(cb => cb());
|
|
14
|
+
}
|
|
15
|
+
function notifySecureListeners(key) {
|
|
16
|
+
secureListeners.get(key)?.forEach(cb => cb());
|
|
17
|
+
}
|
|
18
|
+
const WebStorage = {
|
|
19
|
+
name: "Storage",
|
|
20
|
+
equals: other => other === WebStorage,
|
|
21
|
+
dispose: () => {},
|
|
22
|
+
set: (key, value, scope) => {
|
|
23
|
+
if (scope === StorageScope.Disk) {
|
|
24
|
+
localStorage?.setItem(key, value);
|
|
25
|
+
notifyDiskListeners(key);
|
|
26
|
+
} else if (scope === StorageScope.Secure) {
|
|
27
|
+
sessionStorage?.setItem(key, value);
|
|
28
|
+
notifySecureListeners(key);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
get: (key, scope) => {
|
|
32
|
+
if (scope === StorageScope.Disk) {
|
|
33
|
+
return localStorage?.getItem(key) ?? undefined;
|
|
34
|
+
} else if (scope === StorageScope.Secure) {
|
|
35
|
+
return sessionStorage?.getItem(key) ?? undefined;
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
},
|
|
39
|
+
remove: (key, scope) => {
|
|
40
|
+
if (scope === StorageScope.Disk) {
|
|
41
|
+
localStorage?.removeItem(key);
|
|
42
|
+
notifyDiskListeners(key);
|
|
43
|
+
} else if (scope === StorageScope.Secure) {
|
|
44
|
+
sessionStorage?.removeItem(key);
|
|
45
|
+
notifySecureListeners(key);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
clear: scope => {
|
|
49
|
+
if (scope === StorageScope.Disk) {
|
|
50
|
+
localStorage?.clear();
|
|
51
|
+
diskListeners.forEach(listeners => {
|
|
52
|
+
listeners.forEach(cb => cb());
|
|
53
|
+
});
|
|
54
|
+
} else if (scope === StorageScope.Secure) {
|
|
55
|
+
sessionStorage?.clear();
|
|
56
|
+
secureListeners.forEach(listeners => {
|
|
57
|
+
listeners.forEach(cb => cb());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
setBatch: (keys, values, scope) => {
|
|
62
|
+
keys.forEach((key, i) => WebStorage.set(key, values[i], scope));
|
|
63
|
+
},
|
|
64
|
+
getBatch: (keys, scope) => {
|
|
65
|
+
return keys.map(key => WebStorage.get(key, scope));
|
|
66
|
+
},
|
|
67
|
+
removeBatch: (keys, scope) => {
|
|
68
|
+
keys.forEach(key => WebStorage.remove(key, scope));
|
|
69
|
+
},
|
|
70
|
+
addOnChange: (_scope, _callback) => {
|
|
71
|
+
return () => {};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const memoryStore = new Map();
|
|
75
|
+
const memoryListeners = new Set();
|
|
76
|
+
function notifyMemoryListeners(key, value) {
|
|
77
|
+
memoryListeners.forEach(listener => listener(key, value));
|
|
78
|
+
}
|
|
79
|
+
export const storage = {
|
|
80
|
+
clear: scope => {
|
|
81
|
+
if (scope === StorageScope.Memory) {
|
|
82
|
+
memoryStore.clear();
|
|
83
|
+
notifyMemoryListeners("", undefined);
|
|
84
|
+
} else {
|
|
85
|
+
WebStorage.clear(scope);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
clearAll: () => {
|
|
89
|
+
storage.clear(StorageScope.Memory);
|
|
90
|
+
storage.clear(StorageScope.Disk);
|
|
91
|
+
storage.clear(StorageScope.Secure);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
function defaultSerialize(value) {
|
|
95
|
+
return JSON.stringify(value);
|
|
96
|
+
}
|
|
97
|
+
function defaultDeserialize(value) {
|
|
98
|
+
return JSON.parse(value);
|
|
99
|
+
}
|
|
100
|
+
export function createStorageItem(config) {
|
|
101
|
+
const serialize = config.serialize ?? defaultSerialize;
|
|
102
|
+
const deserialize = config.deserialize ?? defaultDeserialize;
|
|
103
|
+
const isMemory = config.scope === StorageScope.Memory;
|
|
104
|
+
const listeners = new Set();
|
|
105
|
+
let unsubscribe = null;
|
|
106
|
+
let lastRaw;
|
|
107
|
+
let lastValue;
|
|
108
|
+
const ensureSubscription = () => {
|
|
109
|
+
if (!unsubscribe) {
|
|
110
|
+
if (isMemory) {
|
|
111
|
+
const listener = key => {
|
|
112
|
+
if (key === config.key) {
|
|
113
|
+
lastRaw = undefined;
|
|
114
|
+
lastValue = undefined;
|
|
115
|
+
listeners.forEach(l => l());
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
memoryListeners.add(listener);
|
|
119
|
+
unsubscribe = () => memoryListeners.delete(listener);
|
|
120
|
+
} else if (config.scope === StorageScope.Disk) {
|
|
121
|
+
const listener = () => {
|
|
122
|
+
lastRaw = undefined;
|
|
123
|
+
lastValue = undefined;
|
|
124
|
+
listeners.forEach(l => l());
|
|
125
|
+
};
|
|
126
|
+
if (!diskListeners.has(config.key)) {
|
|
127
|
+
diskListeners.set(config.key, new Set());
|
|
128
|
+
}
|
|
129
|
+
diskListeners.get(config.key).add(listener);
|
|
130
|
+
unsubscribe = () => diskListeners.get(config.key)?.delete(listener);
|
|
131
|
+
} else if (config.scope === StorageScope.Secure) {
|
|
132
|
+
const listener = () => {
|
|
133
|
+
lastRaw = undefined;
|
|
134
|
+
lastValue = undefined;
|
|
135
|
+
listeners.forEach(l => l());
|
|
136
|
+
};
|
|
137
|
+
if (!secureListeners.has(config.key)) {
|
|
138
|
+
secureListeners.set(config.key, new Set());
|
|
139
|
+
}
|
|
140
|
+
secureListeners.get(config.key).add(listener);
|
|
141
|
+
unsubscribe = () => secureListeners.get(config.key)?.delete(listener);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const get = () => {
|
|
146
|
+
let raw;
|
|
147
|
+
if (isMemory) {
|
|
148
|
+
raw = memoryStore.get(config.key);
|
|
149
|
+
} else {
|
|
150
|
+
raw = WebStorage.get(config.key, config.scope);
|
|
151
|
+
}
|
|
152
|
+
if (raw === lastRaw && lastValue !== undefined) {
|
|
153
|
+
return lastValue;
|
|
154
|
+
}
|
|
155
|
+
lastRaw = raw;
|
|
156
|
+
if (raw === undefined) {
|
|
157
|
+
lastValue = config.defaultValue;
|
|
158
|
+
} else {
|
|
159
|
+
lastValue = isMemory ? raw : deserialize(raw);
|
|
160
|
+
}
|
|
161
|
+
return lastValue;
|
|
162
|
+
};
|
|
163
|
+
const set = valueOrFn => {
|
|
164
|
+
const currentValue = get();
|
|
165
|
+
const newValue = typeof valueOrFn === "function" ? valueOrFn(currentValue) : valueOrFn;
|
|
166
|
+
lastRaw = undefined;
|
|
167
|
+
if (isMemory) {
|
|
168
|
+
memoryStore.set(config.key, newValue);
|
|
169
|
+
notifyMemoryListeners(config.key, newValue);
|
|
170
|
+
} else {
|
|
171
|
+
WebStorage.set(config.key, serialize(newValue), config.scope);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const deleteItem = () => {
|
|
175
|
+
lastRaw = undefined;
|
|
176
|
+
if (isMemory) {
|
|
177
|
+
memoryStore.delete(config.key);
|
|
178
|
+
notifyMemoryListeners(config.key, undefined);
|
|
179
|
+
} else {
|
|
180
|
+
WebStorage.remove(config.key, config.scope);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const subscribe = callback => {
|
|
184
|
+
ensureSubscription();
|
|
185
|
+
listeners.add(callback);
|
|
186
|
+
return () => {
|
|
187
|
+
listeners.delete(callback);
|
|
188
|
+
if (listeners.size === 0 && unsubscribe) {
|
|
189
|
+
unsubscribe();
|
|
190
|
+
unsubscribe = null;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
get,
|
|
196
|
+
set,
|
|
197
|
+
delete: deleteItem,
|
|
198
|
+
subscribe,
|
|
199
|
+
serialize,
|
|
200
|
+
deserialize,
|
|
201
|
+
_triggerListeners: () => {
|
|
202
|
+
lastRaw = undefined;
|
|
203
|
+
lastValue = undefined;
|
|
204
|
+
listeners.forEach(l => l());
|
|
205
|
+
},
|
|
206
|
+
scope: config.scope,
|
|
207
|
+
key: config.key
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export function useStorage(item) {
|
|
211
|
+
const value = useSyncExternalStore(item.subscribe, item.get, item.get);
|
|
212
|
+
return [value, item.set];
|
|
213
|
+
}
|
|
214
|
+
export function useSetStorage(item) {
|
|
215
|
+
return item.set;
|
|
216
|
+
}
|
|
217
|
+
export function getBatch(items, scope) {
|
|
218
|
+
if (scope === StorageScope.Memory) {
|
|
219
|
+
return items.map(item => item.get());
|
|
220
|
+
}
|
|
221
|
+
const keys = items.map(item => item.key);
|
|
222
|
+
const rawValues = WebStorage.getBatch(keys, scope);
|
|
223
|
+
return items.map((item, idx) => {
|
|
224
|
+
const raw = rawValues[idx];
|
|
225
|
+
if (raw === undefined) {
|
|
226
|
+
return item.get();
|
|
227
|
+
}
|
|
228
|
+
return item.deserialize(raw);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
export function setBatch(items, scope) {
|
|
232
|
+
if (scope === StorageScope.Memory) {
|
|
233
|
+
items.forEach(({
|
|
234
|
+
item,
|
|
235
|
+
value
|
|
236
|
+
}) => item.set(value));
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const keys = items.map(i => i.item.key);
|
|
240
|
+
const values = items.map(i => i.item.serialize(i.value));
|
|
241
|
+
WebStorage.setBatch(keys, values, scope);
|
|
242
|
+
items.forEach(({
|
|
243
|
+
item
|
|
244
|
+
}) => {
|
|
245
|
+
item._triggerListeners();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
export function removeBatch(items, scope) {
|
|
249
|
+
if (scope === StorageScope.Memory) {
|
|
250
|
+
items.forEach(item => item.delete());
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const keys = items.map(item => item.key);
|
|
254
|
+
WebStorage.removeBatch(keys, scope);
|
|
255
|
+
items.forEach(item => item.delete());
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=index.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSyncExternalStore","StorageScope","diskListeners","Map","secureListeners","notifyDiskListeners","key","get","forEach","cb","notifySecureListeners","WebStorage","name","equals","other","dispose","set","value","scope","Disk","localStorage","setItem","Secure","sessionStorage","getItem","undefined","remove","removeItem","clear","listeners","setBatch","keys","values","i","getBatch","map","removeBatch","addOnChange","_scope","_callback","memoryStore","memoryListeners","Set","notifyMemoryListeners","listener","storage","Memory","clearAll","defaultSerialize","JSON","stringify","defaultDeserialize","parse","createStorageItem","config","serialize","deserialize","isMemory","unsubscribe","lastRaw","lastValue","ensureSubscription","l","add","delete","has","raw","defaultValue","valueOrFn","currentValue","newValue","deleteItem","subscribe","callback","size","_triggerListeners","useStorage","item","useSetStorage","items","rawValues","idx"],"sourceRoot":"../../src","sources":["index.web.ts"],"mappings":";;AAAA,SAASA,oBAAoB,QAAQ,OAAO;AAE5C,WAAYC,YAAY,0BAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA;AAuBxB,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAA0B,CAAC;AACxD,MAAMC,eAAe,GAAG,IAAID,GAAG,CAA0B,CAAC;AAE1D,SAASE,mBAAmBA,CAACC,GAAW,EAAE;EACxCJ,aAAa,CAACK,GAAG,CAACD,GAAG,CAAC,EAAEE,OAAO,CAAEC,EAAE,IAAKA,EAAE,CAAC,CAAC,CAAC;AAC/C;AAEA,SAASC,qBAAqBA,CAACJ,GAAW,EAAE;EAC1CF,eAAe,CAACG,GAAG,CAACD,GAAG,CAAC,EAAEE,OAAO,CAAEC,EAAE,IAAKA,EAAE,CAAC,CAAC,CAAC;AACjD;AAEA,MAAME,UAAmB,GAAG;EAC1BC,IAAI,EAAE,SAAS;EACfC,MAAM,EAAGC,KAAK,IAAKA,KAAK,KAAKH,UAAU;EACvCI,OAAO,EAAEA,CAAA,KAAM,CAAC,CAAC;EACjBC,GAAG,EAAEA,CAACV,GAAW,EAAEW,KAAa,EAAEC,KAAa,KAAK;IAClD,IAAIA,KAAK,KAAKjB,YAAY,CAACkB,IAAI,EAAE;MAC/BC,YAAY,EAAEC,OAAO,CAACf,GAAG,EAAEW,KAAK,CAAC;MACjCZ,mBAAmB,CAACC,GAAG,CAAC;IAC1B,CAAC,MAAM,IAAIY,KA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GAAG,CAACC,KAAK,CAAC,CAAC;IACnD;EACF;EAEA,MAAMc,IAAI,GAAGgD,KAAK,CAAC5C,GAAG,CAAEF,CAAC,IAAKA,CAAC,CAAC4C,IAAI,CAACvE,GAAG,CAAC;EACzC,MAAM0B,MAAM,GAAG+C,KAAK,CAAC5C,GAAG,CAAEF,CAAC,IAAKA,CAAC,CAAC4C,IAAI,CAACtB,SAAS,CAACtB,CAAC,CAAChB,KAAK,CAAC,CAAC;EAC1DN,UAAU,CAACmB,QAAQ,CAACC,IAAI,EAAEC,MAAM,EAAEd,KAAK,CAAC;EAExC6D,KAAK,CAACvE,OAAO,CAAC,CAAC;IAAEqE;EAAK,CAAC,KAAK;IAC1BA,IAAI,CAACF,iBAAiB,CAAC,CAAC;EAC1B,CAAC,CAAC;AACJ;AAEA,OAAO,SAASvC,WAAWA,CACzB2C,KAAyB,EACzB7D,KAAmB,EACb;EACN,IAAIA,KAAK,KAAKjB,YAAY,CAAC6C,MAAM,EAAE;IACjCiC,KAAK,CAACvE,OAAO,CAAEqE,IAAI,IAAKA,IAAI,CAACb,MAAM,CAAC,CAAC,CAAC;IACtC;EACF;EAEA,MAAMjC,IAAI,GAAGgD,KAAK,CAAC5C,GAAG,CAAE0C,IAAI,IAAKA,IAAI,CAACvE,GAAG,CAAC;EAC1CK,UAAU,CAACyB,WAAW,CAACL,IAAI,EAAEb,KAAK,CAAC;EACnC6D,KAAK,CAACvE,OAAO,CAAEqE,IAAI,IAAKA,IAAI,CAACb,MAAM,CAAC,CAAC,CAAC;AACxC","ignoreList":[]}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare enum StorageScope {
|
|
3
|
-
Memory = 0,
|
|
4
|
-
Disk = 1,
|
|
5
|
-
Secure = 2
|
|
6
|
-
}
|
|
1
|
+
import { type HybridObject } from "react-native-nitro-modules";
|
|
7
2
|
export interface Storage extends HybridObject<{
|
|
8
3
|
ios: "c++";
|
|
9
4
|
android: "c++";
|
|
@@ -11,6 +6,10 @@ export interface Storage extends HybridObject<{
|
|
|
11
6
|
set(key: string, value: string, scope: number): void;
|
|
12
7
|
get(key: string, scope: number): string | undefined;
|
|
13
8
|
remove(key: string, scope: number): void;
|
|
9
|
+
clear(scope: number): void;
|
|
10
|
+
setBatch(keys: string[], values: string[], scope: number): void;
|
|
11
|
+
getBatch(keys: string[], scope: number): (string | undefined)[];
|
|
12
|
+
removeBatch(keys: string[], scope: number): void;
|
|
14
13
|
addOnChange(scope: number, callback: (key: string, value: string | undefined) => void): () => void;
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=Storage.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Storage.nitro.d.ts","sourceRoot":"","sources":["../../src/Storage.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Storage.nitro.d.ts","sourceRoot":"","sources":["../../src/Storage.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,WAAW,OAAQ,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IAC3E,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAChE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,WAAW,CACT,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,GACzD,MAAM,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.types.d.ts","sourceRoot":"","sources":["../../src/Storage.types.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,MAAM,IAAI;IACV,IAAI,IAAI;IACR,MAAM,IAAI;CACX"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { StorageScope } from "./Storage.
|
|
1
|
+
import { StorageScope } from "./Storage.types";
|
|
2
|
+
export { StorageScope } from "./Storage.types";
|
|
3
3
|
export type { Storage } from "./Storage.nitro";
|
|
4
4
|
export declare const storage: {
|
|
5
|
-
clear: (scope: StorageScope
|
|
5
|
+
clear: (scope: StorageScope) => void;
|
|
6
6
|
clearAll: () => void;
|
|
7
7
|
};
|
|
8
8
|
export interface StorageItemConfig<T> {
|
|
@@ -17,10 +17,19 @@ export interface StorageItem<T> {
|
|
|
17
17
|
set: (value: T | ((prev: T) => T)) => void;
|
|
18
18
|
delete: () => void;
|
|
19
19
|
subscribe: (callback: () => void) => () => void;
|
|
20
|
+
serialize: (value: T) => string;
|
|
21
|
+
deserialize: (value: string) => T;
|
|
22
|
+
_triggerListeners: () => void;
|
|
20
23
|
scope: StorageScope;
|
|
21
24
|
key: string;
|
|
22
25
|
}
|
|
23
26
|
export declare function createStorageItem<T = undefined>(config: StorageItemConfig<T>): StorageItem<T>;
|
|
24
27
|
export declare function useStorage<T>(item: StorageItem<T>): [T, (value: T | ((prev: T) => T)) => void];
|
|
25
28
|
export declare function useSetStorage<T>(item: StorageItem<T>): (value: T | ((prev: T) => T)) => void;
|
|
29
|
+
export declare function getBatch(items: StorageItem<any>[], scope: StorageScope): any[];
|
|
30
|
+
export declare function setBatch(items: {
|
|
31
|
+
item: StorageItem<any>;
|
|
32
|
+
value: any;
|
|
33
|
+
}[], scope: StorageScope): void;
|
|
34
|
+
export declare function removeBatch(items: StorageItem<any>[], scope: StorageScope): void;
|
|
26
35
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAkB/C,eAAO,MAAM,OAAO;mBACH,YAAY;;CAa5B,CAAC;AAEF,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3C,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,S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secure = 2
|
|
5
|
+
}
|
|
6
|
+
export interface Storage {
|
|
7
|
+
name: string;
|
|
8
|
+
equals: (other: any) => boolean;
|
|
9
|
+
dispose: () => void;
|
|
10
|
+
set(key: string, value: string, scope: number): void;
|
|
11
|
+
get(key: string, scope: number): string | undefined;
|
|
12
|
+
remove(key: string, scope: number): void;
|
|
13
|
+
clear(scope: number): void;
|
|
14
|
+
setBatch(keys: string[], values: string[], scope: number): void;
|
|
15
|
+
getBatch(keys: string[], scope: number): (string | undefined)[];
|
|
16
|
+
removeBatch(keys: string[], scope: number): void;
|
|
17
|
+
addOnChange(scope: number, callback: (key: string, value: string | undefined) => void): () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare const storage: {
|
|
20
|
+
clear: (scope: StorageScope) => void;
|
|
21
|
+
clearAll: () => void;
|
|
22
|
+
};
|
|
23
|
+
export interface StorageItemConfig<T> {
|
|
24
|
+
key: string;
|
|
25
|
+
scope: StorageScope;
|
|
26
|
+
defaultValue?: T;
|
|
27
|
+
serialize?: (value: T) => string;
|
|
28
|
+
deserialize?: (value: string) => T;
|
|
29
|
+
}
|
|
30
|
+
export interface StorageItem<T> {
|
|
31
|
+
get: () => T;
|
|
32
|
+
set: (value: T | ((prev: T) => T)) => void;
|
|
33
|
+
delete: () => void;
|
|
34
|
+
subscribe: (callback: () => void) => () => void;
|
|
35
|
+
serialize: (value: T) => string;
|
|
36
|
+
deserialize: (value: string) => T;
|
|
37
|
+
_triggerListeners: () => void;
|
|
38
|
+
scope: StorageScope;
|
|
39
|
+
key: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function createStorageItem<T = undefined>(config: StorageItemConfig<T>): StorageItem<T>;
|
|
42
|
+
export declare function useStorage<T>(item: StorageItem<T>): [T, (value: T | ((prev: T) => T)) => void];
|
|
43
|
+
export declare function useSetStorage<T>(item: StorageItem<T>): (value: T | ((prev: T) => T)) => void;
|
|
44
|
+
export declare function getBatch(items: StorageItem<any>[], scope: StorageScope): any[];
|
|
45
|
+
export declare function setBatch(items: {
|
|
46
|
+
item: StorageItem<any>;
|
|
47
|
+
value: any;
|
|
48
|
+
}[], scope: StorageScope): void;
|
|
49
|
+
export declare function removeBatch(items: StorageItem<any>[], scope: StorageScope): void;
|
|
50
|
+
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../src/index.web.ts"],"names":[],"mappings":"AAEA,oBAAY,YAAY;IACtB,MAAM,IAAI;IACV,IAAI,IAAI;IACR,MAAM,IAAI;CACX;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;IAChC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAChE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,WAAW,CACT,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAA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K,IAAI,CAAC,CAG5C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,oCA3Jb,IAAI,CA6J3C;AAED,wBAAgB,QAAQ,CACtB,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,EACzB,KAAK,EAAE,YAAY,GAClB,GAAG,EAAE,CAeP;AAED,wBAAgB,QAAQ,CACtB,KAAK,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE,EAAE,EAC/C,KAAK,EAAE,YAAY,GAClB,IAAI,CAaN;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,EACzB,KAAK,EAAE,YAAY,GAClB,IAAI,CASN"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# NitroStorage+autolinking.cmake
|
|
3
3
|
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
# https://github.com/mrousavy/nitro
|
|
5
|
-
# Copyright ©
|
|
5
|
+
# Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
#
|
|
7
7
|
|
|
8
8
|
# This is a CMake file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorage+autolinking.gradle
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorageOnLoad.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#ifndef BUILDING_NITROSTORAGE_WITH_GENERATED_CMAKE_PROJECT
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitrostorage/NitroStorageOnLoad.kt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorageOnLoad.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
package com.margelo.nitro.com.nitrostorage
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# NitroStorage+autolinking.rb
|
|
3
3
|
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
# https://github.com/mrousavy/nitro
|
|
5
|
-
# Copyright ©
|
|
5
|
+
# Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
#
|
|
7
7
|
|
|
8
8
|
# This is a Ruby script that adds all files generated by Nitrogen
|
|
@@ -52,7 +52,7 @@ def add_nitrogen_files(spec)
|
|
|
52
52
|
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
53
|
# Use C++ 20
|
|
54
54
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
-
# Enables C++ <-> Swift interop (by default it's only
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only ObjC)
|
|
56
56
|
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
57
|
# Enables stricter modular headers
|
|
58
58
|
"DEFINES_MODULE" => "YES",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorage-Swift-Cxx-Bridge.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "NitroStorage-Swift-Cxx-Bridge.hpp"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorageAutolinking.mm
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#import <Foundation/Foundation.h>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// NitroStorageAutolinking.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
public final class NitroStorageAutolinking {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridStorageSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include "HybridStorageSpec.hpp"
|
|
@@ -17,6 +17,10 @@ namespace margelo::nitro::NitroStorage {
|
|
|
17
17
|
prototype.registerHybridMethod("set", &HybridStorageSpec::set);
|
|
18
18
|
prototype.registerHybridMethod("get", &HybridStorageSpec::get);
|
|
19
19
|
prototype.registerHybridMethod("remove", &HybridStorageSpec::remove);
|
|
20
|
+
prototype.registerHybridMethod("clear", &HybridStorageSpec::clear);
|
|
21
|
+
prototype.registerHybridMethod("setBatch", &HybridStorageSpec::setBatch);
|
|
22
|
+
prototype.registerHybridMethod("getBatch", &HybridStorageSpec::getBatch);
|
|
23
|
+
prototype.registerHybridMethod("removeBatch", &HybridStorageSpec::removeBatch);
|
|
20
24
|
prototype.registerHybridMethod("addOnChange", &HybridStorageSpec::addOnChange);
|
|
21
25
|
});
|
|
22
26
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// HybridStorageSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright ©
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include <string>
|
|
19
19
|
#include <optional>
|
|
20
|
+
#include <vector>
|
|
20
21
|
#include <functional>
|
|
21
22
|
|
|
22
23
|
namespace margelo::nitro::NitroStorage {
|
|
@@ -53,6 +54,10 @@ namespace margelo::nitro::NitroStorage {
|
|
|
53
54
|
virtual void set(const std::string& key, const std::string& value, double scope) = 0;
|
|
54
55
|
virtual std::optional<std::string> get(const std::string& key, double scope) = 0;
|
|
55
56
|
virtual void remove(const std::string& key, double scope) = 0;
|
|
57
|
+
virtual void clear(double scope) = 0;
|
|
58
|
+
virtual void setBatch(const std::vector<std::string>& keys, const std::vector<std::string>& values, double scope) = 0;
|
|
59
|
+
virtual std::vector<std::string> getBatch(const std::vector<std::string>& keys, double scope) = 0;
|
|
60
|
+
virtual void removeBatch(const std::vector<std::string>& keys, double scope) = 0;
|
|
56
61
|
virtual std::function<void()> addOnChange(double scope, const std::function<void(const std::string& /* key */, const std::optional<std::string>& /* value */)>& callback) = 0;
|
|
57
62
|
|
|
58
63
|
protected:
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-storage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.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",
|
|
7
7
|
"types": "lib/typescript/index.d.ts",
|
|
8
8
|
"react-native": "src/index.ts",
|
|
9
|
+
"browser": "src/index.web.ts",
|
|
9
10
|
"source": "src/index.ts",
|
|
10
11
|
"app": "app.plugin.js",
|
|
11
12
|
"files": [
|
|
@@ -78,40 +79,20 @@
|
|
|
78
79
|
"@react-native/babel-preset": "^0.83.0",
|
|
79
80
|
"@testing-library/react-hooks": "^8.0.1",
|
|
80
81
|
"@testing-library/react-native": "^13.3.3",
|
|
81
|
-
"@types/
|
|
82
|
-
"@types/node": "^20.0.0",
|
|
83
|
-
"@types/react": "^18.0.0",
|
|
84
|
-
"jest": "^29.7.0",
|
|
85
|
-
"nitrogen": "^0.31.10",
|
|
86
|
-
"react": "19.1.0",
|
|
87
|
-
"react-native": "0.81.5",
|
|
88
|
-
"react-native-builder-bob": "^0.31.0",
|
|
89
|
-
"react-native-nitro-modules": "^0.31.10",
|
|
90
|
-
"rimraf": "^6.0.1",
|
|
91
|
-
"ts-jest": "^29.2.5",
|
|
82
|
+
"@types/react": "^19.1.10",
|
|
92
83
|
"typescript": "^5.6.3"
|
|
93
84
|
},
|
|
94
85
|
"peerDependencies": {
|
|
95
86
|
"react": "*",
|
|
96
87
|
"react-native": ">=0.75.0",
|
|
97
|
-
"react-native-nitro-modules": ">=0.
|
|
88
|
+
"react-native-nitro-modules": ">=0.32.0"
|
|
98
89
|
},
|
|
99
90
|
"react-native-builder-bob": {
|
|
100
91
|
"source": "src",
|
|
101
92
|
"output": "lib",
|
|
102
93
|
"targets": [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
"esm": true
|
|
107
|
-
}
|
|
108
|
-
],
|
|
109
|
-
[
|
|
110
|
-
"module",
|
|
111
|
-
{
|
|
112
|
-
"esm": true
|
|
113
|
-
}
|
|
114
|
-
],
|
|
94
|
+
"commonjs",
|
|
95
|
+
"module",
|
|
115
96
|
"typescript"
|
|
116
97
|
]
|
|
117
98
|
}
|