@onehat/data 1.8.17 → 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.17",
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
 
@@ -374,10 +374,6 @@ class AjaxRepository extends Repository {
374
374
  if (!_.isNil(params) && _.isObject(params)) {
375
375
  this.setParams(params);
376
376
  }
377
-
378
- if (this.debugMode) {
379
- console.log('loading ' + this.name, params);
380
- }
381
377
 
382
378
  const repository = this;
383
379
  const data = _.merge({}, this._baseParams, this._params);
@@ -385,7 +381,7 @@ class AjaxRepository extends Repository {
385
381
  return this._send(this.methods.get, this.api.get, data)
386
382
  .then(result => {
387
383
  if (this.debugMode) {
388
- console.log('load result ' + this.name, result);
384
+ console.log('Response for ' + this.name, result);
389
385
  }
390
386
 
391
387
  if (this.isDestroyed) {
@@ -453,7 +449,7 @@ class AjaxRepository extends Repository {
453
449
  return this._send(this.methods.get, this.api.get, params)
454
450
  .then(result => {
455
451
  if (this.debugMode) {
456
- console.log('reloadEntity result ' + entity.id, result);
452
+ console.log('reloadEntity response ' + entity.id, result);
457
453
  }
458
454
 
459
455
  const {
@@ -531,7 +527,7 @@ class AjaxRepository extends Repository {
531
527
  return this._send(method, url, data)
532
528
  .then(result => {
533
529
  if (this.debugMode) {
534
- console.log(this.api.add + ' result', result);
530
+ console.log(this.api.add + ' response', result);
535
531
  }
536
532
  const {
537
533
  root,
@@ -571,7 +567,7 @@ class AjaxRepository extends Repository {
571
567
  return this._send(method, url, data)
572
568
  .then(result => {
573
569
  if (this.debugMode) {
574
- console.log(this.api.batchAdd + ' result', result);
570
+ console.log(this.api.batchAdd + ' response', result);
575
571
  }
576
572
  const {
577
573
  root,
@@ -611,7 +607,7 @@ class AjaxRepository extends Repository {
611
607
  return this._send(method, url, data)
612
608
  .then(result => {
613
609
  if (this.debugMode) {
614
- console.log(this.api.edit + ' result', result);
610
+ console.log(this.api.edit + ' response', result);
615
611
  }
616
612
  const {
617
613
  root,
@@ -651,7 +647,7 @@ class AjaxRepository extends Repository {
651
647
  return this._send(method, url, data)
652
648
  .then(result => {
653
649
  if (this.debugMode) {
654
- console.log(this.api.batchEdit + ' result', result);
650
+ console.log(this.api.batchEdit + ' response', result);
655
651
  }
656
652
  const {
657
653
  root,
@@ -691,7 +687,7 @@ class AjaxRepository extends Repository {
691
687
  return this._send(method, url, data)
692
688
  .then(result => {
693
689
  if (this.debugMode) {
694
- console.log(this.api.delete + ' result', result);
690
+ console.log(this.api.delete + ' response', result);
695
691
  }
696
692
  const {
697
693
  root,
@@ -733,7 +729,7 @@ class AjaxRepository extends Repository {
733
729
  return this._send(method, url, data)
734
730
  .then(result => {
735
731
  if (this.debugMode) {
736
- console.log(this.api.batchDelete + ' result', result);
732
+ console.log(this.api.batchDelete + ' response', result);
737
733
  }
738
734
  const {
739
735
  root,
@@ -110,7 +110,7 @@ class OneBuildRepository extends AjaxRepository {
110
110
  };
111
111
 
112
112
  if (this.debugMode) {
113
- console.log(url, options);
113
+ console.log('Sending ' + url, options);
114
114
  }
115
115
 
116
116
  this.lastSendOptions = options;
@@ -251,7 +251,7 @@ class OneBuildRepository extends AjaxRepository {
251
251
  return this.axios(data)
252
252
  .then((result) => {
253
253
  if (this.debugMode) {
254
- console.log('login result', result);
254
+ console.log('login response', result);
255
255
  }
256
256
 
257
257
  const response = result.data;
@@ -281,7 +281,7 @@ class OneBuildRepository extends AjaxRepository {
281
281
  })
282
282
  .then((result) => {
283
283
  if (this.debugMode) {
284
- console.log('logout result', result);
284
+ console.log('logout response', result);
285
285
  }
286
286
  const response = result.data;
287
287
  if (!response.success) {
@@ -309,7 +309,7 @@ class OneBuildRepository extends AjaxRepository {
309
309
  return this.axios(data)
310
310
  .then((result) => {
311
311
  if (this.debugMode) {
312
- console.log('forgotPassword result', result);
312
+ console.log('forgotPassword response', result);
313
313
  }
314
314
 
315
315
  const response = result.data;