@onehat/data 1.21.16 → 1.21.17

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.21.16",
3
+ "version": "1.21.17",
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;
@@ -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
  /**