@onehat/data 1.20.0 → 1.20.2

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.0",
3
+ "version": "1.20.2",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -265,7 +265,9 @@ class Entity extends EventEmitter {
265
265
  */
266
266
  emit(name) { // NOTE: Purposefully do not use an arrow-function, so we have access to arguments
267
267
 
268
- this.rehash();
268
+ if (!this.isDestroyed) {
269
+ this.rehash();
270
+ }
269
271
 
270
272
  return super.emit(...arguments);
271
273
  }
@@ -906,7 +908,7 @@ class Entity extends EventEmitter {
906
908
  if (this.isDestroyed) {
907
909
  throw Error('this.getIdProperty is no longer valid. Entity has been destroyed.');
908
910
  }
909
- const idProperty = this.getSchema().model?.idProperty || null;
911
+ const idProperty = this.getSchema()?.model?.idProperty || null;
910
912
  if (!idProperty) {
911
913
  throw new Error('No idProperty found for ' + schema.name);
912
914
  }
@@ -962,7 +964,7 @@ class Entity extends EventEmitter {
962
964
  }
963
965
  const
964
966
  schema = this.getSchema(),
965
- model = schema.model,
967
+ model = schema?.model,
966
968
  displayProperty = model && model.displayProperty ? model.displayProperty : null;
967
969
  if (!displayProperty) {
968
970
  throw new Error('No displayProperty found for ' + schema.name);
@@ -1064,10 +1066,10 @@ class Entity extends EventEmitter {
1064
1066
  }
1065
1067
 
1066
1068
  const schema = this.getSchema();
1067
- if (!schema.model.associations.hasOne.includes(repositoryName) &&
1068
- !schema.model.associations.hasMany.includes(repositoryName) &&
1069
- !schema.model.associations.belongsTo.includes(repositoryName) &&
1070
- !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)
1071
1073
  ) {
1072
1074
  throw Error(repositoryName + ' is not associated with this schema');
1073
1075
  }
@@ -1447,7 +1449,7 @@ class Entity extends EventEmitter {
1447
1449
  throw Error('this.getParentIdProperty is no longer valid. TreeNode has been destroyed.');
1448
1450
  }
1449
1451
 
1450
- const parentIdProperty = this.getSchema().model.parentIdProperty;
1452
+ const parentIdProperty = this.getSchema()?.model.parentIdProperty;
1451
1453
  return this.getProperty(parentIdProperty);
1452
1454
  }
1453
1455
 
@@ -1507,7 +1509,7 @@ class Entity extends EventEmitter {
1507
1509
  throw Error('this.getDepthProperty is no longer valid. TreeNode has been destroyed.');
1508
1510
  }
1509
1511
 
1510
- const depthProperty = this.getSchema().model.depthProperty;
1512
+ const depthProperty = this.getSchema()?.model.depthProperty;
1511
1513
  return this.getProperty(depthProperty);
1512
1514
  }
1513
1515
 
@@ -1544,7 +1546,7 @@ class Entity extends EventEmitter {
1544
1546
  throw Error('this.getHasChildrenProperty is no longer valid. TreeNode has been destroyed.');
1545
1547
  }
1546
1548
 
1547
- const hasChildrenProperty = this.getSchema().model.hasChildrenProperty;
1549
+ const hasChildrenProperty = this.getSchema()?.model.hasChildrenProperty;
1548
1550
  return this.getProperty(hasChildrenProperty);
1549
1551
  }
1550
1552
 
@@ -1838,8 +1840,8 @@ class Entity extends EventEmitter {
1838
1840
  })
1839
1841
  this.properties = null;
1840
1842
 
1841
- this.emit('destroy', this._proxy);
1842
1843
  this.isDestroyed = true;
1844
+ this.emit('destroy', this._proxy);
1843
1845
 
1844
1846
  // listeners
1845
1847
  this.removeAllListeners();