@onehat/data 1.8.18 → 1.8.19

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": "@onehat/data",
3
- "version": "1.8.18",
3
+ "version": "1.8.19",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -37,9 +37,9 @@
37
37
  "dependencies": {
38
38
  "@onehat/events": "^1.6.5",
39
39
  "accounting-js": "^1.1.1",
40
- "axios": "^0.27.2",
41
- "chrono-node": "^2.3.9",
42
- "fast-xml-parser": "^4.0.9",
40
+ "axios": "^1.1.3",
41
+ "chrono-node": "^2.4.1",
42
+ "fast-xml-parser": "^4.0.11",
43
43
  "he": "^1.2.0",
44
44
  "js-base64": "^3.7.2",
45
45
  "lodash": "^4.17.21",
@@ -47,7 +47,7 @@
47
47
  "numeral": "^2.0.6",
48
48
  "qs": "^6.11.0",
49
49
  "relative-time-parser": "^1.0.15",
50
- "uuid": "^8.3.2"
50
+ "uuid": "^9.0.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@babel/core": "^7.16.7",
@@ -42,12 +42,10 @@ class AsyncStorageRepository extends OfflineRepository {
42
42
  value = result; // Invalid JSON, just return raw result
43
43
  }
44
44
  }
45
-
46
45
  return value;
47
46
  } catch (error) {
48
47
  if (this.debugMode) {
49
48
  const msg = error && error.message;
50
- console.log('_storageGetValue error', msg);
51
49
  debugger;
52
50
  }
53
51
  }
@@ -67,7 +65,7 @@ class AsyncStorageRepository extends OfflineRepository {
67
65
  const results = await AsyncStorage.multiGet(this._namespace(keys));
68
66
 
69
67
  if (this.debugMode) {
70
- console.log(this.name, 'AsyncStorage.multiGet results', results);
68
+ console.log(this.name, 'AsyncStorage.multiGet results', name, results);
71
69
  }
72
70
 
73
71
  let values = [];
@@ -84,7 +82,6 @@ class AsyncStorageRepository extends OfflineRepository {
84
82
  // Delete the index to this record
85
83
  const re = new RegExp('^' + this.name + '\-' + '(.*)'),
86
84
  matches = key.match(re);
87
- debugger;
88
85
  const id = parseInt(matches, 10);
89
86
  this._deleteFromIndex(id);
90
87
  } else {
@@ -101,7 +98,6 @@ debugger;
101
98
  } catch (error) {
102
99
  if (this.debugMode) {
103
100
  const msg = error && error.message;
104
- console.log('_storageGetMultiple error', msg);
105
101
  debugger;
106
102
  }
107
103
  }
@@ -121,7 +117,6 @@ debugger;
121
117
  } catch (error) {
122
118
  if (this.debugMode) {
123
119
  const msg = error && error.message;
124
- console.log('_storageSetValue error', msg);
125
120
  debugger;
126
121
  }
127
122
  }
@@ -154,7 +149,6 @@ debugger;
154
149
  } catch (error) {
155
150
  if (this.debugMode) {
156
151
  const msg = error && error.message;
157
- console.log('_storageSetMultiple error', msg);
158
152
  debugger;
159
153
  }
160
154
  }
@@ -175,7 +169,6 @@ debugger;
175
169
  } catch (error) {
176
170
  if (this.debugMode) {
177
171
  const msg = error && error.message;
178
- console.log('_storageDeleteValue error', msg);
179
172
  debugger;
180
173
  }
181
174
  }
@@ -196,19 +189,16 @@ debugger;
196
189
  } catch (error) {
197
190
  if (this.debugMode) {
198
191
  const msg = error && error.message;
199
- console.log('_storageDeleteMultiple error', msg);
200
192
  debugger;
201
193
  }
202
194
  }
203
195
  }
204
196
 
205
- _clearAll = async () => {
206
- await AsyncStorage.clear();
207
- this._keyedEntities = {};
208
- this.reload();
197
+ clearAll = async () => {
198
+ await this.load([]);
209
199
  }
210
200
 
211
- _getAllKeys = async () => {
201
+ getAllKeys = async () => {
212
202
  return await AsyncStorage.getAllKeys();
213
203
  }
214
204
 
@@ -3,97 +3,101 @@
3
3
  * and is subject to the terms and conditions defined in
4
4
  * file 'LICENSE.txt', which is part of this source code package.
5
5
  */
6
- import OfflineRepository from '@onehat/data/src/Repository/Offline.js';
7
- import * as SecureStore from 'expo-secure-store'; // see: https://docs.expo.io/versions/latest/sdk/securestore/
8
- import _ from 'lodash';
9
-
10
- /**
11
- * Repository representing Expo's SecureStore
12
- * Uses expo-secure-store package
13
- */
14
- class SecureStoreRepository extends OfflineRepository {
15
-
16
- constructor(config = {}) {
17
- super(...arguments);
18
- _.merge(this, config);
19
- }
20
-
21
- _storageGetValue = async (name) => {
22
- try {
23
-
24
- if (this.debugMode) {
25
- console.log(this.name, 'SecureStore.get', name);
26
- }
27
-
28
- const result = await SecureStore.getItemAsync(this._namespace(name));
29
-
30
- if (this.debugMode) {
31
- console.log(this.name, 'SecureStore.get results', name, result);
32
- }
33
-
34
- let value;
35
- if (!_.isNil(result)) {
36
- try {
37
- value = JSON.parse(result);
38
- } catch (e) {
39
- value = result; // Invalid JSON, just return raw result
40
- }
41
- }
42
- return value;
43
- } catch (error) {
44
- if (this.debugMode) {
45
- const msg = error && error.message;
46
- debugger;
47
- }
48
- }
49
- }
50
-
51
- _storageSetValue = async (name, value) => {
52
- try {
53
- if (!_.isString(value)) {
54
- value = JSON.stringify(value);
55
- }
56
- if (this.debugMode) {
57
- console.log(this.name, 'SecureStore.set', name, value);
58
- }
59
-
60
- const result = await SecureStore.setItemAsync(this._namespace(name), value);
61
-
62
- // if (this.debugMode) {
63
- // console.log(this.name, 'SecureStore.set results', name, result);
64
- // }
65
- return result;
66
- } catch (error) {
67
- if (this.debugMode) {
68
- const msg = error && error.message;
69
- debugger;
70
- }
71
- }
72
- }
73
-
74
- _storageDeleteValue = async (name) => {
75
- try {
76
- if (this.debugMode) {
77
- console.log(this.name, 'SecureStore.delete', name);
78
- }
79
-
80
- const result = await SecureStore.deleteItemAsync(this._namespace(name));
81
-
82
- // if (this.debugMode) {
83
- // console.log(this.name, 'SecureStore.delete results', name, result);
84
- // }
85
- return result;
86
- } catch (error) {
87
- if (this.debugMode) {
88
- const msg = error && error.message;
89
- debugger;
90
- }
91
- }
92
- }
93
-
94
- };
95
-
96
- SecureStoreRepository.className = 'SecureStore';
97
- SecureStoreRepository.type = 'secure';
98
-
99
- export default SecureStoreRepository;
6
+ import OfflineRepository from '@onehat/data/src/Repository/Offline.js';
7
+ import * as SecureStore from 'expo-secure-store'; // see: https://docs.expo.io/versions/latest/sdk/securestore/
8
+ import _ from 'lodash';
9
+
10
+ /**
11
+ * Repository representing Expo's SecureStore
12
+ * Uses expo-secure-store package
13
+ */
14
+ class SecureStoreRepository extends OfflineRepository {
15
+
16
+ constructor(config = {}) {
17
+ super(...arguments);
18
+ _.merge(this, config);
19
+ }
20
+
21
+ _storageGetValue = async (name) => {
22
+ try {
23
+
24
+ if (this.debugMode) {
25
+ console.log(this.name, 'SecureStore.get', name);
26
+ }
27
+
28
+ const result = await SecureStore.getItemAsync(this._namespace(name));
29
+
30
+ if (this.debugMode) {
31
+ console.log(this.name, 'SecureStore.get results', name, result);
32
+ }
33
+
34
+ let value;
35
+ if (!_.isNil(result)) {
36
+ try {
37
+ value = JSON.parse(result);
38
+ } catch (e) {
39
+ value = result; // Invalid JSON, just return raw result
40
+ }
41
+ }
42
+ return value;
43
+ } catch (error) {
44
+ // if (this.debugMode) {
45
+ // const msg = error && error.message;
46
+ // debugger;
47
+ // }
48
+ }
49
+ }
50
+
51
+ _storageSetValue = async (name, value) => {
52
+ try {
53
+ if (!_.isString(value)) {
54
+ value = JSON.stringify(value);
55
+ }
56
+ if (this.debugMode) {
57
+ console.log(this.name, 'SecureStore.set', name, value);
58
+ }
59
+
60
+ const result = await SecureStore.setItemAsync(this._namespace(name), value);
61
+
62
+ // if (this.debugMode) {
63
+ // console.log(this.name, 'SecureStore.set results', name, result);
64
+ // }
65
+ return result;
66
+ } catch (error) {
67
+ // if (this.debugMode) {
68
+ // const msg = error && error.message;
69
+ // debugger;
70
+ // }
71
+ }
72
+ }
73
+
74
+ _storageDeleteValue = async (name) => {
75
+ try {
76
+ if (this.debugMode) {
77
+ console.log(this.name, 'SecureStore.delete', name);
78
+ }
79
+
80
+ const result = await SecureStore.deleteItemAsync(this._namespace(name));
81
+
82
+ // if (this.debugMode) {
83
+ // console.log(this.name, 'SecureStore.delete results', name, result);
84
+ // }
85
+ return result;
86
+ } catch (error) {
87
+ // if (this.debugMode) {
88
+ // const msg = error && error.message;
89
+ // debugger;
90
+ // }
91
+ }
92
+ }
93
+
94
+ clearAll = async () => {
95
+ await this.load([]);
96
+ }
97
+
98
+ };
99
+
100
+ SecureStoreRepository.className = 'SecureStore';
101
+ SecureStoreRepository.type = 'secure';
102
+
103
+ export default SecureStoreRepository;
package/src/OneHatData.js CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  } from './Schema';
14
14
  import _ from 'lodash';
15
15
 
16
+ export let concurrentAsyncRequests = 0; // global counter
17
+
16
18
  /**
17
19
  * OneHatData represents a collection of Repositories.
18
20
  * It is the top-level object for this module.
@@ -56,6 +58,12 @@ export class OneHatData extends EventEmitter {
56
58
  * @private
57
59
  */
58
60
  this.uniqueRepositoriesMap = {};
61
+
62
+ /**
63
+ * @member {Object} maxConcurrentAsyncRequests - Object map of all unique Repositories, with signature of { mapName: id }
64
+ * @public
65
+ */
66
+ this.maxConcurrentAsyncRequests = 500; // Total number of async requests allowed, before we start making them synchronous
59
67
 
60
68
  /**
61
69
  * @member {boolean} isDestroyed - Whether this object has been destroyed
@@ -83,7 +91,7 @@ export class OneHatData extends EventEmitter {
83
91
  if (this.isDestroyed) {
84
92
  throw new Error('this.setRepositoryGlobals is no longer valid. OneHatData has been destroyed.');
85
93
  }
86
- _.assign(this._repositoryGlobals, globals);
94
+ _.merge(this._repositoryGlobals, globals);
87
95
  return this;
88
96
  }
89
97