react-native-mosquito-transport 0.0.33 → 0.0.34
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-mosquito-transport",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "React native javascript sdk for mosquito-transport (https://github.com/brainbehindx/mosquito-transport)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react-native": "*",
|
|
43
|
-
"react-native-
|
|
44
|
-
"react-native-
|
|
45
|
-
"react-native-
|
|
43
|
+
"react-native-file-access": "*",
|
|
44
|
+
"react-native-get-random-values": "*",
|
|
45
|
+
"react-native-sha256": "*"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Scoped } from "./variables";
|
|
2
2
|
import { Platform } from "react-native";
|
|
3
|
-
import {
|
|
3
|
+
import { Dirs, FileSystem } from "react-native-file-access";
|
|
4
4
|
|
|
5
|
-
const PARENT_FOLDER = `${Platform.OS === 'android' ?
|
|
5
|
+
const PARENT_FOLDER = `${Platform.OS === 'android' ? Dirs.DocumentDir.split('/').slice(0, -1).join('/') : Dirs.MainBundleDir}/mosquito_base`;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* this method linearize read/write for individual access_id on the file system ensuring consistency across concurrent operations
|
|
@@ -46,22 +46,22 @@ export const getSystem = (builder) => {
|
|
|
46
46
|
return {
|
|
47
47
|
set: async (table, primary_key, value) => {
|
|
48
48
|
const path = conjoin(table, primary_key);
|
|
49
|
-
await mkdir(path).catch(() => null);
|
|
49
|
+
await FileSystem.mkdir(path).catch(() => null);
|
|
50
50
|
await Promise.all(Object.entries(value).map(([k, v]) =>
|
|
51
|
-
writeFile(joinPath(path, k), JSON.stringify(v), 'utf8')
|
|
51
|
+
FileSystem.writeFile(joinPath(path, k), JSON.stringify(v), 'utf8')
|
|
52
52
|
));
|
|
53
53
|
},
|
|
54
|
-
delete: (table, primary_key) => unlink(conjoin(table, primary_key)),
|
|
54
|
+
delete: (table, primary_key) => FileSystem.unlink(conjoin(table, primary_key)),
|
|
55
55
|
find: async (table, primary_key, extractions) => {
|
|
56
56
|
const path = conjoin(table, primary_key);
|
|
57
57
|
|
|
58
58
|
const value_map = await Promise.all(extractions.map(async node =>
|
|
59
|
-
[node, JSON.parse(await readFile(joinPath(path, node)), 'utf8')]
|
|
59
|
+
[node, JSON.parse(await FileSystem.readFile(joinPath(path, node)), 'utf8')]
|
|
60
60
|
));
|
|
61
61
|
return Object.fromEntries(value_map);
|
|
62
62
|
},
|
|
63
63
|
list: async (table, extractions) => {
|
|
64
|
-
const names = await
|
|
64
|
+
const names = await FileSystem.ls(conjoin(table));
|
|
65
65
|
const list_data = await Promise.all(names.map(async primary_key => {
|
|
66
66
|
const obj = await system.find(table, primary_key, extractions)
|
|
67
67
|
.catch(() => null);
|
|
@@ -74,7 +74,7 @@ export const getSystem = (builder) => {
|
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
function purifyFilepath(filename) {
|
|
77
|
+
export function purifyFilepath(filename) {
|
|
78
78
|
if (!filename || typeof filename !== 'string')
|
|
79
79
|
throw `invalid filename:${filename}`;
|
|
80
80
|
|
|
@@ -4,6 +4,7 @@ import naclPkg from 'tweetnacl';
|
|
|
4
4
|
import getLodash from "lodash/get";
|
|
5
5
|
import { deserialize, serialize } from "entity-serializer";
|
|
6
6
|
import { sha256 } from 'react-native-sha256';
|
|
7
|
+
import { purifyFilepath } from "./fs_manager";
|
|
7
8
|
|
|
8
9
|
const { box, randomBytes } = naclPkg;
|
|
9
10
|
|
|
@@ -67,8 +68,7 @@ export function sortArrayByObjectKey(arr = [], key) {
|
|
|
67
68
|
|
|
68
69
|
export async function niceHash(str = '') {
|
|
69
70
|
const hash = Buffer.from(await sha256(str), 'hex').toString('base64');
|
|
70
|
-
|
|
71
|
-
return hash;
|
|
71
|
+
return purifyFilepath(hash);
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
export const sameInstance = (var1, var2) => {
|
|
@@ -69,10 +69,12 @@ export const getCountQuery = async (builder, access_id) => {
|
|
|
69
69
|
return data && data.value;
|
|
70
70
|
} else {
|
|
71
71
|
return useFS(builder, access_id, 'dbQueryCount')(async fs => {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const data = await fs.find(DB_COUNT_QUERY(path), access_id, ['value']).catch(() => null);
|
|
73
|
+
if (data) {
|
|
74
|
+
await fs.set(DB_COUNT_QUERY(path), access_id, { touched: Date.now() });
|
|
75
|
+
return data.value;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -25,7 +25,7 @@ export const insertFetchResources = async (projectUrl, access_id, value) => {
|
|
|
25
25
|
updateCacheStore(['FetchedStore', 'DatabaseStats']);
|
|
26
26
|
} else {
|
|
27
27
|
await useFS(FETCH_RESOURCES(projectUrl), access_id, 'httpFetch')(async fs => {
|
|
28
|
-
const b4Data = await fs.find('main', access_id, ['size']);
|
|
28
|
+
const b4Data = await fs.find('main', access_id, ['size']).catch(() => null);
|
|
29
29
|
|
|
30
30
|
await fs.set('main', access_id, { value, size: dataSize, touched: Date.now() });
|
|
31
31
|
incrementFetcherSize(projectUrl, dataSize - (b4Data?.size || 0));
|
|
@@ -106,7 +106,7 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
106
106
|
|
|
107
107
|
await awaitStore();
|
|
108
108
|
const resolveCache = (reqData) => {
|
|
109
|
-
finalize(buildFetchData(reqData
|
|
109
|
+
finalize(buildFetchData(reqData, { fromCache: true }));
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
try {
|