@onehat/data 1.16.7 → 1.16.9

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.
@@ -38,6 +38,15 @@ describe('OneBuildRepository', function() {
38
38
  expect(r._params.test).to.be.eq(1);
39
39
  });
40
40
 
41
+ it('hasParam', function() {
42
+ const r = this.repository;
43
+ r.setParam('test', 1);
44
+
45
+ const result = r.hasParam('test');
46
+
47
+ expect(result).to.be.true;
48
+ });
49
+
41
50
  it('setParams', function() {
42
51
  const r = this.repository;
43
52
  r.setParams({
@@ -56,6 +65,15 @@ describe('OneBuildRepository', function() {
56
65
  expect(r._baseParams.test).to.be.eq(1);
57
66
  });
58
67
 
68
+ it('hasBaseParam', function() {
69
+ const r = this.repository;
70
+ r.setBaseParam('test', 1);
71
+
72
+ const result = r.hasBaseParam('test');
73
+
74
+ expect(result).to.be.true;
75
+ });
76
+
59
77
  it('setBaseParams', function() {
60
78
  const r = this.repository;
61
79
  r.setBaseParams({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.16.7",
3
+ "version": "1.16.9",
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
 
@@ -277,6 +277,22 @@ class AjaxRepository extends Repository {
277
277
  });
278
278
  }
279
279
 
280
+ /**
281
+ * Determines if base query param exists
282
+ * @param {string} name - Param name
283
+ */
284
+ hasBaseParam = (name) => {
285
+ return this._baseParams.hasOwnProperty(name);
286
+ }
287
+
288
+ /**
289
+ * Determines if query param exists
290
+ * @param {string} name - Param name
291
+ */
292
+ hasParam = (name) => {
293
+ return this._params.hasOwnProperty(name);
294
+ }
295
+
280
296
  /**
281
297
  * Sets base query param
282
298
  * @param {string} name - Param name to set.