@onehat/data 1.21.10 → 1.21.12

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.
@@ -325,14 +325,24 @@ describe('Repository Base', function() {
325
325
  expect(filter.value).to.be.eq('1');
326
326
  });
327
327
 
328
- it('filter - object', function() {
328
+ it.only('filter - object', function() {
329
+ // two possible ways to call filter with an object
330
+ // 1. filter({ name: 'key', value: '1' });
329
331
  this.repository.filter({
330
332
  name: 'key',
331
333
  value: '1',
332
334
  });
333
- const filter = this.repository.filters[0];
334
- expect(filter.name).to.be.eq('key');
335
- expect(filter.value).to.be.eq('1');
335
+ const filter1 = this.repository.filters[0];
336
+ expect(filter1.name).to.be.eq('key');
337
+ expect(filter1.value).to.be.eq('1');
338
+
339
+ // 2. filter({ key: '1' });
340
+ this.repository.filter({
341
+ key: '1',
342
+ });
343
+ const filter2 = this.repository.filters[0];
344
+ expect(filter2.name).to.be.eq('key');
345
+ expect(filter2.value).to.be.eq('1');
336
346
  });
337
347
 
338
348
  it('filter - array', function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.21.10",
3
+ "version": "1.21.12",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -512,6 +512,10 @@ 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
@@ -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:
@@ -729,7 +729,19 @@ export default class Repository extends EventEmitter {
729
729
  }];
730
730
  } else if (_.isArray(arg1)) {
731
731
  newFilters = arg1;
732
- } else if (_.isObject(arg1)) { // includes functions
732
+ } else if (_.isPlainObject(arg1)) {
733
+ if (arg1.name) {
734
+ // like { name: 'first_name', value: 'Steve' }
735
+ newFilters = [arg1];
736
+ } else {
737
+ // like { first_name: 'Steve' }
738
+ const name = Object.keys(arg1)[0];
739
+ newFilters = [{
740
+ name,
741
+ value: arg1[name],
742
+ }];
743
+ }
744
+ } else if (_.isFunction(arg1)) {
733
745
  newFilters = [arg1];
734
746
  }
735
747