@onehat/data 1.21.9 → 1.21.11

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.11",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -512,11 +512,19 @@ class LocalFromRemoteRepository extends EventEmitter {
512
512
  return this.lastSync;
513
513
  }
514
514
 
515
+ getLastModifiedDate() {
516
+ return this.remote.getLastModifiedDate();
517
+ }
518
+
515
519
  /**
516
520
  * Sets lastSync to now and saves to local storage medium, if possible.
517
521
  * @private
518
522
  */
519
523
  async _setLastSync() {
524
+ if (!this.local.entities.length) {
525
+ return; // don't set sync date if nothing was synced
526
+ }
527
+
520
528
  const now = moment();
521
529
  this.lastSync = now;
522
530
  if (this.local.setLastSync) {
@@ -44,6 +44,7 @@ class OneBuildRepository extends AjaxRepository {
44
44
  batchAdd: model + '/batchAdd',
45
45
  batchEdit: model + '/batchEdit',
46
46
  batchDelete: model + '/batchDelete',
47
+ getLastModifiedDate: model + '/getLastModifiedDate',
47
48
  },
48
49
 
49
50
  methods: {
@@ -442,6 +443,53 @@ class OneBuildRepository extends AjaxRepository {
442
443
 
443
444
  }
444
445
 
446
+ async getLastModifiedDate() {
447
+ if (this.isDestroyed) {
448
+ this.throwError('this.getLastModifiedDate is no longer valid. Repository has been destroyed.');
449
+ return;
450
+ }
451
+ if (!this.api.getLastModifiedDate) {
452
+ this.throwError('No "getLastModifiedDate" api endpoint defined.');
453
+ return;
454
+ }
455
+
456
+ this.markLoading();
457
+
458
+ if (this.debugMode) {
459
+ console.log('getLastModifiedDate');
460
+ }
461
+
462
+ return this._send(this.methods.get, this.api.getLastModifiedDate, this._baseParams)
463
+ .then(result => {
464
+ if (this.debugMode) {
465
+ console.log('Response for getLastModifiedDate for ' + this.name, result);
466
+ }
467
+
468
+ if (this.isDestroyed) {
469
+ // If this repository gets destroyed before it has a chance
470
+ // to process the Ajax request, just ignore the response.
471
+ return;
472
+ }
473
+
474
+ const {
475
+ root,
476
+ success,
477
+ total,
478
+ message
479
+ } = this._processServerResponse(result);
480
+
481
+ if (!success) {
482
+ this.throwError(message);
483
+ return;
484
+ }
485
+ return root;
486
+ })
487
+ .finally(() => {
488
+ this.markLoading(false);
489
+ });
490
+
491
+ }
492
+
445
493
  /**
446
494
  * Login to OneBuild API
447
495
  * @param {object} creds - object with two properties:
@@ -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