@onehat/data 1.21.16 → 1.21.18

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.
@@ -2,6 +2,7 @@ import { OneHatData } from '../../../src/OneHatData.js';
2
2
  import UsersDefinition from '../../fixtures/Definitions/Users.js';
3
3
  import GroupsDefinition from '../../fixtures/Definitions/Groups.js';
4
4
  import UserData from '../../fixtures/Data/User.js';
5
+ import _ from 'lodash';
5
6
 
6
7
  const baseURL = Cypress.env('baseURL'),
7
8
  creds = {
@@ -63,6 +64,22 @@ describe('OneBuildRepository', function() {
63
64
  expect(p.conditions.key2).to.be.eq('2');
64
65
  });
65
66
 
67
+ it('merge from lodash', function() {
68
+ const
69
+ a = {
70
+ test: true,
71
+ },
72
+ b = {
73
+ foo: true,
74
+ };
75
+ let c;
76
+ const bar = _.merge({}, a, b, c);
77
+
78
+ expect(_.isEqual(a, { test: true })).to.be.true;
79
+ expect(_.isEqual(b, { foo: true })).to.be.true;
80
+ expect(_.isEqual(bar, { test: true, foo: true })).to.be.true;
81
+ });
82
+
66
83
  it.skip('401', function() {
67
84
  cy.wrap((async () => {
68
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.21.16",
3
+ "version": "1.21.18",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -459,7 +459,7 @@ class LocalFromRemoteRepository extends EventEmitter {
459
459
  }
460
460
 
461
461
  // local <-- remote
462
- await localItem.loadOriginalData(remoteItem.getOriginalData());
462
+ localItem.response = remoteItem.response;
463
463
  this.remote.clear();
464
464
 
465
465
  // Handle the server's response
@@ -449,10 +449,11 @@ class MemoryRepository extends Repository {
449
449
  return;
450
450
  }
451
451
 
452
- delete this._keyedEntities[entity.id];
452
+ if (!entity.isDestroyed) {
453
+ delete this._keyedEntities[entity.id];
454
+ entity.destroy();
455
+ }
453
456
  this.entities = _.filter(this.entities, (x) => x.id !== entity.id);
454
-
455
- entity.destroy();
456
457
  return entity;
457
458
  }
458
459
 
@@ -600,8 +601,9 @@ class MemoryRepository extends Repository {
600
601
 
601
602
  this._setPaginationVars();
602
603
 
603
- const nextEntities = this._paginate(entities),
604
- nextValues = _.map(nextEntities, (entity) => entity.getSubmitValues());
604
+ const
605
+ nextEntities = this._paginate(entities),
606
+ nextValues = _.map(nextEntities, (entity) => entity.isDestroyed ? null : entity.getSubmitValues());
605
607
  if (!_.isEqual(this._previousValues, nextValues)) {
606
608
  this.entities = nextEntities;
607
609
  this._previousValues = nextValues;
@@ -214,6 +214,10 @@ class OfflineRepository extends MemoryRepository {
214
214
  }
215
215
 
216
216
  // Get a clone, in case we need to revert back to it later
217
+ if (entity.isDestroyed) {
218
+ return await this._storageDeleteValue(entity.id);
219
+ }
220
+
217
221
  const clone = entity.clone();
218
222
 
219
223
  // Attempt to edit
@@ -242,7 +246,7 @@ class OfflineRepository extends MemoryRepository {
242
246
  }
243
247
 
244
248
  // Get a clone, in case we need to revert back to it later
245
- const clone = entity.clone();
249
+ const clone = entity.isDestroyed ? null : entity.clone();
246
250
 
247
251
  // Attempt to delete
248
252
  super._doDelete(entity);
@@ -253,8 +257,12 @@ class OfflineRepository extends MemoryRepository {
253
257
  storageResult = await this._storageDeleteValue(entity.id);
254
258
  await this._deleteFromIndex(entity.id);
255
259
  } catch (e) {
256
- // Revert to clone
257
- this._keyedEntities[clone.id] = clone;
260
+ // try to revert to clone
261
+ if (clone) {
262
+ this._keyedEntities[clone.id] = clone;
263
+ } else {
264
+ delete this._keyedEntities[entity.id];
265
+ }
258
266
  }
259
267
 
260
268
  return storageResult;
@@ -96,7 +96,7 @@ class OneBuildRepository extends AjaxRepository {
96
96
  * Fires off axios request to server
97
97
  * @private
98
98
  */
99
- _send(method, url, data) {
99
+ _send(method, url, data, headers) {
100
100
 
101
101
  if (!url) {
102
102
  this.throwError('No url submitted');
@@ -108,17 +108,17 @@ class OneBuildRepository extends AjaxRepository {
108
108
  return;
109
109
  }
110
110
 
111
- const headers = _.merge({
111
+ const mergedHeaders = _.merge({
112
112
  // 'Content-Type': 'application/json', // Stops axios from using 'application/x-www-form-urlencoded'
113
113
  Accept: 'application/json',
114
- }, this.headers);
114
+ }, this.headers, headers);
115
115
 
116
116
  const options = {
117
117
  url,
118
118
  method,
119
119
  baseURL: this.api.baseURL,
120
120
  transformResponse: null,
121
- headers,
121
+ headers: mergedHeaders,
122
122
  params: method === 'GET' ? data : null,
123
123
  data: method !== 'GET' ? qs.stringify(data) : null,
124
124
  timeout: this.timeout,
@@ -1523,7 +1523,7 @@ export default class Repository extends EventEmitter {
1523
1523
  if (!entities) {
1524
1524
  entities = this.entities;
1525
1525
  }
1526
- return _.filter(entities, entity => entity.isDirty && !entity.isSaving);
1526
+ return _.filter(entities, entity => !entity.isSaving && (entity.isDestroyed || entity.isDirty));
1527
1527
  }
1528
1528
 
1529
1529
  /**
@@ -1539,7 +1539,7 @@ export default class Repository extends EventEmitter {
1539
1539
  if (!entities) {
1540
1540
  entities = this.entities;
1541
1541
  }
1542
- return _.filter(entities, entity => entity.isDeleted);
1542
+ return _.filter(entities, entity => entity.isDestroyed || entity.isDeleted);
1543
1543
  }
1544
1544
 
1545
1545
  /**