@onehat/data 1.19.26 → 1.19.28

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.19.26",
3
+ "version": "1.19.28",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -602,9 +602,6 @@ class Entity extends EventEmitter {
602
602
  * @return {object} values
603
603
  */
604
604
  get submitValues() {
605
- if (this.isDestroyed) {
606
- throw Error('this.submitValues is no longer valid. Entity has been destroyed.');
607
- }
608
605
  return this.getSubmitValues();
609
606
  }
610
607
 
@@ -632,9 +629,6 @@ class Entity extends EventEmitter {
632
629
  * @return {object} values
633
630
  */
634
631
  get submitValuesMapped() {
635
- if (this.isDestroyed) {
636
- throw Error('this.submitValuesMapped is no longer valid. Entity has been destroyed.');
637
- }
638
632
  return this.getSubmitValuesMapped();
639
633
  }
640
634
 
@@ -645,7 +639,7 @@ class Entity extends EventEmitter {
645
639
  */
646
640
  getDisplayValues = () => {
647
641
  if (this.isDestroyed) {
648
- throw Error('this.getSubmitValues is no longer valid. Entity has been destroyed.');
642
+ throw Error('this.getDisplayValues is no longer valid. Entity has been destroyed.');
649
643
  }
650
644
  let propertyValues = {};
651
645
  _.forOwn(this.properties, (property) => {
@@ -659,9 +653,6 @@ class Entity extends EventEmitter {
659
653
  * @return {object} values
660
654
  */
661
655
  get displayValues() {
662
- if (this.isDestroyed) {
663
- throw Error('this.displayValues is no longer valid. Entity has been destroyed.');
664
- }
665
656
  return this.getDisplayValues();
666
657
  }
667
658
 
@@ -686,9 +677,6 @@ class Entity extends EventEmitter {
686
677
  * @return {object} values
687
678
  */
688
679
  get rawValues() {
689
- if (this.isDestroyed) {
690
- throw Error('this.rawValues is no longer valid. Entity has been destroyed.');
691
- }
692
680
  return this.getRawValues();
693
681
  }
694
682
 
@@ -713,9 +701,6 @@ class Entity extends EventEmitter {
713
701
  * @return {object} values
714
702
  */
715
703
  get parsedRawValues() {
716
- if (this.isDestroyed) {
717
- throw Error('this.parsedRawValues is no longer valid. Entity has been destroyed.');
718
- }
719
704
  return this.getParsedRawValues();
720
705
  }
721
706
 
@@ -726,7 +711,7 @@ class Entity extends EventEmitter {
726
711
  */
727
712
  getParsedValues = () => {
728
713
  if (this.isDestroyed) {
729
- throw Error('this.getSubmitValues is no longer valid. Entity has been destroyed.');
714
+ throw Error('this.getParsedValues is no longer valid. Entity has been destroyed.');
730
715
  }
731
716
  let propertyValues = {};
732
717
  _.forOwn(this.properties, (property) => {
@@ -740,9 +725,6 @@ class Entity extends EventEmitter {
740
725
  * @return {object} values
741
726
  */
742
727
  get parsedValues() {
743
- if (this.isDestroyed) {
744
- throw Error('this.parsedValues is no longer valid. Entity has been destroyed.');
745
- }
746
728
  return this.getParsedValues();
747
729
  }
748
730
 
@@ -33,6 +33,7 @@ export default function useOneHatData(schemaName, uniqueRepository = false) {
33
33
 
34
34
  if (uniqueRepository) {
35
35
  repository = await oneHatData.createRepository(schemaName);
36
+ repository.isUnique = true;
36
37
  } else if (_.isObject(schemaName)) {
37
38
  if (schemaName.id) {
38
39
  repository = oneHatData.getRepositoryById(schemaName.id);
package/src/OneHatData.js CHANGED
@@ -487,6 +487,7 @@ export class OneHatData extends EventEmitter {
487
487
  const id = uuid();
488
488
  clone.name = clone.name + '-' + id;
489
489
  clone.id = id;
490
+ clone.isUnique = true;
490
491
  return clone;
491
492
  }
492
493
  return schema.getBoundRepository();
@@ -517,6 +518,7 @@ export class OneHatData extends EventEmitter {
517
518
 
518
519
  const repository = await this.createRepository(schemaName);
519
520
  this.uniqueRepositoriesMap[mapName] = repository.id;
521
+ repository.isUnique = true;
520
522
  return repository;
521
523
  }
522
524
 
@@ -331,6 +331,11 @@ class MemoryRepository extends Repository {
331
331
  passedAll = false;
332
332
  return false; // break the forEach loop
333
333
  }
334
+ } else if (!_.isNil(filter.fn)) {
335
+ if (!filter.fn(entity)) {
336
+ passedAll = false;
337
+ return false; // break the forEach loop
338
+ }
334
339
  } else {
335
340
  const { name, value } = filter,
336
341
  property = entity.getProperty(name);
@@ -175,7 +175,7 @@ class OfflineRepository extends MemoryRepository {
175
175
  let storageResult;
176
176
  try {
177
177
  storageResult = await this._storageSetValue(entity.id, entity.getOriginalData());
178
- this._addToIndex(entity.id);
178
+ await this._addToIndex(entity.id);
179
179
  } catch (e) {
180
180
  // Revert to clone
181
181
  delete this._keyedEntities[entity.id];
@@ -236,7 +236,7 @@ class OfflineRepository extends MemoryRepository {
236
236
  let storageResult;
237
237
  try {
238
238
  storageResult = await this._storageDeleteValue(entity.id);
239
- this._deleteFromIndex(entity.id);
239
+ await this._deleteFromIndex(entity.id);
240
240
  } catch (e) {
241
241
  // Revert to clone
242
242
  this._keyedEntities[clone.id] = clone;
@@ -47,6 +47,11 @@ export default class Repository extends EventEmitter {
47
47
  */
48
48
  name: schema.name,
49
49
 
50
+ /**
51
+ * @member {boolean} isUnique - Whether this repository is classified as 'unique'
52
+ */
53
+ isUnique: false,
54
+
50
55
  /**
51
56
  * @member {boolean} isAutoLoad - Whether to immediately load this repository's data on instantiation
52
57
  */
@@ -611,10 +616,6 @@ export default class Repository extends EventEmitter {
611
616
  * @member {boolean} hasFilters - Whether or not any filters are applied
612
617
  */
613
618
  get hasFilters() {
614
- if (this.isDestroyed) {
615
- this.throwError('this.hasFilters is no longer valid. Repository has been destroyed.');
616
- return;
617
- }
618
619
  return this.filters.length > 0;
619
620
  }
620
621
 
@@ -622,9 +623,7 @@ export default class Repository extends EventEmitter {
622
623
  if (!this.hasFilters) {
623
624
  return false;
624
625
  }
625
- const found = _.find(this.filters, (filter) => {
626
- return filter.name === name;
627
- });
626
+ const found = _.find(this.filters, (filter) => filter.name === name);
628
627
  return !!found;
629
628
  }
630
629
 
@@ -697,14 +696,14 @@ export default class Repository extends EventEmitter {
697
696
  // Set up new filters
698
697
  let filters = clearFirst ?
699
698
  [] : // Clear existing filters
700
- _.map(this.filters, filter => filter); // Add to or modify existing filters. Work with a copy, so we can detect changes in _setFilters
699
+ _.clone(this.filters); // so we can detect changes in _setFilters
701
700
 
702
701
  _.each(newFilters, (newFilter) => {
703
702
 
704
703
  let deleteExisting = false,
705
704
  addNew = true;
706
705
 
707
- if (!_.isFunction(newFilter)) {
706
+ if (!_.isFunction(newFilter) && _.isNil(newFilter.fn)) {
708
707
  if (_.isNil(newFilter.value)) {
709
708
  deleteExisting = true;
710
709
  addNew = false;