@onehat/data 1.21.9 → 1.21.10

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.
@@ -811,6 +811,35 @@ describe('Repository Base', function() {
811
811
  expect(result).to.be.true;
812
812
  });
813
813
 
814
+ it('getIsBound', function() {
815
+
816
+ // try with bound schema
817
+ expect(this.repository.getIsBound()).to.be.true;
818
+
819
+ // try with unbound schema
820
+ const repository = new this.Repository({
821
+ id: 'foo',
822
+ schema: this.schema,
823
+ });
824
+ repository.initialize();
825
+ expect(repository.getIsBound()).to.be.false;
826
+
827
+ });
828
+
829
+ it('isBound', function() {
830
+
831
+ // try with bound schema
832
+ expect(this.repository.isBound).to.be.true;
833
+
834
+ // try with unbound schema
835
+ const repository = new this.Repository({
836
+ id: 'foo',
837
+ schema: this.schema,
838
+ });
839
+ repository.initialize();
840
+ expect(repository.isBound).to.be.false;
841
+
842
+ });
814
843
  });
815
844
 
816
845
  describe('updating', function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.21.9",
3
+ "version": "1.21.10",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -517,6 +517,10 @@ class LocalFromRemoteRepository extends EventEmitter {
517
517
  * @private
518
518
  */
519
519
  async _setLastSync() {
520
+ if (!this.local.entities.length) {
521
+ return; // don't set sync date if nothing was synced
522
+ }
523
+
520
524
  const now = moment();
521
525
  this.lastSync = now;
522
526
  if (this.local.setLastSync) {
@@ -1479,6 +1479,18 @@ export default class Repository extends EventEmitter {
1479
1479
  }
1480
1480
  /* */
1481
1481
 
1482
+ /**
1483
+ * Determines whether this repository is bound to the schema
1484
+ * @return {boolean}
1485
+ */
1486
+ getIsBound() {
1487
+ if (this.isDestroyed) {
1488
+ this.throwError('this.getIsBound is no longer valid. Repository has been destroyed.');
1489
+ return;
1490
+ }
1491
+ return this.schema.getBoundRepository() === this;
1492
+ }
1493
+
1482
1494
  /**
1483
1495
  * Get all dirty (having unsaved changes) Entities
1484
1496
  * @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
@@ -1637,6 +1649,19 @@ export default class Repository extends EventEmitter {
1637
1649
  return !_.isNil(this.getById(idOrEntity));
1638
1650
  }
1639
1651
 
1652
+ /**
1653
+ * Getter of isBound for this Repository.
1654
+ * Returns true if this repository is bound to the schema
1655
+ * @return {boolean} isBound
1656
+ */
1657
+ get isBound() {
1658
+ if (this.isDestroyed) {
1659
+ this.throwError('this.isBound is no longer valid. Repository has been destroyed.');
1660
+ return;
1661
+ }
1662
+ return this.getIsBound();
1663
+ }
1664
+
1640
1665
  /**
1641
1666
  * Getter of isDirty for this Repository.
1642
1667
  * Returns true if any Entities within it are dirty