@onehat/data 1.16.8 → 1.16.10

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.16.8",
3
+ "version": "1.16.10",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  /** @module Repository */
2
2
 
3
- import OfflineRepository from './Offline';
3
+ import OfflineRepository from '@onehat/data/src/Repository/Offline.js';
4
4
  import IDBStorage from 'idbstorage';
5
5
  import _ from 'lodash';
6
6
 
@@ -1,6 +1,6 @@
1
1
  /** @module Repository */
2
2
 
3
- import OfflineRepository from './Offline';
3
+ import OfflineRepository from '@onehat/data/src/Repository/Offline.js';
4
4
  import store from 'store2'; // see: https://github.com/nbubna/store#readme
5
5
  import _ from 'lodash';
6
6
 
@@ -25,26 +25,73 @@ class LocalStorageRepository extends OfflineRepository {
25
25
  }
26
26
 
27
27
  _storageGetValue = (name) => {
28
- const result = this._store(name);
29
- let value;
30
28
  try {
31
- value = JSON.parse(result);
32
- } catch (e) {
33
- // Invalid JSON, just return raw result
34
- value = result;
29
+
30
+ if (this.debugMode) {
31
+ console.log(this.name, 'LocalStorage.get', name);
32
+ }
33
+
34
+ const result = this._store(name);
35
+
36
+ if (this.debugMode) {
37
+ console.log(this.name, 'LocalStorage.get results', name, result);
38
+ }
39
+
40
+ let value = null;
41
+ if (!_.isNil(result)) {
42
+ try {
43
+ value = JSON.parse(result);
44
+ } catch (e) {
45
+ // Invalid JSON, just return raw result
46
+ value = result;
47
+ }
48
+ }
49
+ return value;
50
+ } catch (error) {
51
+ if (this.debugMode) {
52
+ const msg = error && error.message;
53
+ debugger;
54
+ }
35
55
  }
36
- return value;
37
56
  }
38
57
 
39
58
  _storageSetValue = (name, value) => {
40
- if (!_.isString(value)) {
41
- value = JSON.stringify(value);
59
+ try {
60
+ if (this.debugMode) {
61
+ console.log(this.name, 'LocalStorage.set', name, value);
62
+ }
63
+ if (!_.isString(value)) {
64
+ value = JSON.stringify(value);
65
+ }
66
+
67
+ return this._store(name, value);
68
+
69
+ } catch (error) {
70
+ if (this.debugMode) {
71
+ const msg = error && error.message;
72
+ debugger;
73
+ }
42
74
  }
43
- return this._store(name, value);
44
75
  }
45
76
 
46
77
  _storageDeleteValue = (name) => {
47
- return this._store.remove(name);
78
+ try {
79
+ if (_.isNil(name) || (_.isString(name) && name === '')) {
80
+ return;
81
+ }
82
+
83
+ if (this.debugMode) {
84
+ console.log(this.name, 'LocalStorage.delete', name);
85
+ }
86
+
87
+ return this._store.remove(name);
88
+
89
+ } catch (error) {
90
+ if (this.debugMode) {
91
+ const msg = error && error.message;
92
+ debugger;
93
+ }
94
+ }
48
95
  }
49
96
 
50
97
  _clearAll = () => {
@@ -1,6 +1,6 @@
1
1
  /** @module Repository */
2
2
 
3
- import OfflineRepository from './Offline';
3
+ import OfflineRepository from '@onehat/data/src/Repository/Offline.js';
4
4
  import store from 'store2'; // see: https://github.com/nbubna/store#readme
5
5
  import _ from 'lodash';
6
6
 
@@ -1,7 +1,7 @@
1
1
  import moment from 'moment';
2
2
  import momentAlt from 'relative-time-parser'; // Notice this version of moment is imported from 'relative-time-parser', and may be out of sync with our general 'moment' package
3
3
  import accounting from 'accounting-js';
4
- // import * as chrono from 'chrono-node'; // Doesn't yet work in React Native ("SyntaxError: Invalid RegExp: Quantifier has nothing to repeat, js engine: hermes") Github ticket: https://github.com/facebook/hermes/blob/main/doc/RegExp.md
4
+ import * as chrono from 'chrono-node'; // Doesn't yet work in React Native ("SyntaxError: Invalid RegExp: Quantifier has nothing to repeat, js engine: hermes") Github ticket: https://github.com/facebook/hermes/blob/main/doc/RegExp.md
5
5
  import _ from 'lodash';
6
6
 
7
7
  class Parsers {