@onehat/data 1.20.1 → 1.20.3

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.20.1",
3
+ "version": "1.20.3",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -908,7 +908,7 @@ class Entity extends EventEmitter {
908
908
  if (this.isDestroyed) {
909
909
  throw Error('this.getIdProperty is no longer valid. Entity has been destroyed.');
910
910
  }
911
- const idProperty = this.getSchema().model?.idProperty || null;
911
+ const idProperty = this.getSchema()?.model?.idProperty || null;
912
912
  if (!idProperty) {
913
913
  throw new Error('No idProperty found for ' + schema.name);
914
914
  }
@@ -964,7 +964,7 @@ class Entity extends EventEmitter {
964
964
  }
965
965
  const
966
966
  schema = this.getSchema(),
967
- model = schema.model,
967
+ model = schema?.model,
968
968
  displayProperty = model && model.displayProperty ? model.displayProperty : null;
969
969
  if (!displayProperty) {
970
970
  throw new Error('No displayProperty found for ' + schema.name);
@@ -1066,10 +1066,10 @@ class Entity extends EventEmitter {
1066
1066
  }
1067
1067
 
1068
1068
  const schema = this.getSchema();
1069
- if (!schema.model.associations.hasOne.includes(repositoryName) &&
1070
- !schema.model.associations.hasMany.includes(repositoryName) &&
1071
- !schema.model.associations.belongsTo.includes(repositoryName) &&
1072
- !schema.model.associations.belongsToMany.includes(repositoryName)
1069
+ if (!schema?.model.associations.hasOne.includes(repositoryName) &&
1070
+ !schema?.model.associations.hasMany.includes(repositoryName) &&
1071
+ !schema?.model.associations.belongsTo.includes(repositoryName) &&
1072
+ !schema?.model.associations.belongsToMany.includes(repositoryName)
1073
1073
  ) {
1074
1074
  throw Error(repositoryName + ' is not associated with this schema');
1075
1075
  }
@@ -1449,7 +1449,7 @@ class Entity extends EventEmitter {
1449
1449
  throw Error('this.getParentIdProperty is no longer valid. TreeNode has been destroyed.');
1450
1450
  }
1451
1451
 
1452
- const parentIdProperty = this.getSchema().model.parentIdProperty;
1452
+ const parentIdProperty = this.getSchema()?.model.parentIdProperty;
1453
1453
  return this.getProperty(parentIdProperty);
1454
1454
  }
1455
1455
 
@@ -1509,7 +1509,7 @@ class Entity extends EventEmitter {
1509
1509
  throw Error('this.getDepthProperty is no longer valid. TreeNode has been destroyed.');
1510
1510
  }
1511
1511
 
1512
- const depthProperty = this.getSchema().model.depthProperty;
1512
+ const depthProperty = this.getSchema()?.model.depthProperty;
1513
1513
  return this.getProperty(depthProperty);
1514
1514
  }
1515
1515
 
@@ -1546,7 +1546,7 @@ class Entity extends EventEmitter {
1546
1546
  throw Error('this.getHasChildrenProperty is no longer valid. TreeNode has been destroyed.');
1547
1547
  }
1548
1548
 
1549
- const hasChildrenProperty = this.getSchema().model.hasChildrenProperty;
1549
+ const hasChildrenProperty = this.getSchema()?.model.hasChildrenProperty;
1550
1550
  return this.getProperty(hasChildrenProperty);
1551
1551
  }
1552
1552
 
@@ -1840,8 +1840,8 @@ class Entity extends EventEmitter {
1840
1840
  })
1841
1841
  this.properties = null;
1842
1842
 
1843
- this.emit('destroy', this._proxy);
1844
1843
  this.isDestroyed = true;
1844
+ this.emit('destroy', this._proxy);
1845
1845
 
1846
1846
  // listeners
1847
1847
  this.removeAllListeners();
@@ -1036,7 +1036,10 @@ class AjaxRepository extends Repository {
1036
1036
  this.assembleTreeNodes();
1037
1037
  this.emit('changeData', this.entities);
1038
1038
  } else if (this.isRemotePhantomMode && (this._operations.add || this._operations.deletePhantom)) {
1039
- // Do nothing, as we don't want to immediately reload on add for a remote phantom mode record. It won't appear, and it will cause all kinds of trouble!
1039
+ if (this._operations.add) {
1040
+ // Do nothing, as we don't want to immediately reload on add for a remote phantom mode record.
1041
+ // The entity wouldn't appear, and it would cause all kinds of trouble!
1042
+ }
1040
1043
  if (this._operations.deletePhantom) {
1041
1044
  // sweep existing deleted records and remove them
1042
1045
  _.each(this.entities, (entity) => {
@@ -340,6 +340,9 @@ class OneBuildRepository extends AjaxRepository {
340
340
 
341
341
 
342
342
  const duplicateEntity = await this.createStandaloneEntity(root, true, true);
343
+ if (entity.isRemotePhantomMode) {
344
+ entity.isRemotePhantom = true;
345
+ }
343
346
  this._insertBefore(duplicateEntity, entity);
344
347
 
345
348
  this.markLoading(false);
@@ -1716,6 +1716,10 @@ export default class Repository extends EventEmitter {
1716
1716
  break;
1717
1717
  case 'edit':
1718
1718
  entities = this.getDirty();
1719
+ if (_.isEmpty(entities) && this.isRemotePhantomMode) {
1720
+ // In remote phantom mode, we need to save phantoms even if they're not dirty
1721
+ entities = this.getPhantom();
1722
+ }
1719
1723
  if (useStaged) {
1720
1724
  entities = this.getStaged(entities);
1721
1725
  }