@onehat/data 1.6.0 → 1.6.1
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.
|
@@ -581,6 +581,23 @@ describe('Repository Base', function() {
|
|
|
581
581
|
expect(result.value).to.be.eq('three');
|
|
582
582
|
});
|
|
583
583
|
|
|
584
|
+
it('getById', function() {
|
|
585
|
+
const result = this.repository.getById(3);
|
|
586
|
+
expect(result.value).to.be.eq('three');
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it('getBy', function() {
|
|
590
|
+
const result = this.repository.getBy(entity => entity.id === 2 || entity.id === 3);
|
|
591
|
+
expect(result.length).to.be.eq(2);
|
|
592
|
+
expect(result[0].value).to.be.eq('two');
|
|
593
|
+
expect(result[1].value).to.be.eq('three');
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it('getFirstBy', function() {
|
|
597
|
+
const result = this.repository.getFirstBy(entity => entity.id === 3);
|
|
598
|
+
expect(result.value).to.be.eq('three');
|
|
599
|
+
});
|
|
600
|
+
|
|
584
601
|
it('getByRange', function() {
|
|
585
602
|
const result = this.repository.getByRange(1, 4);
|
|
586
603
|
expect(_.size(result)).to.be.eq(4);
|
package/package.json
CHANGED
|
@@ -1064,20 +1064,19 @@ export default class Repository extends EventEmitter {
|
|
|
1064
1064
|
/**
|
|
1065
1065
|
* Get a single Entity by its id
|
|
1066
1066
|
* @param {integer} id - id of record to retrieve
|
|
1067
|
-
* @return {Entity} The Entity with matching id
|
|
1067
|
+
* @return {Entity} The Entity with matching id, or undefined
|
|
1068
1068
|
*/
|
|
1069
1069
|
getById = (id) => {
|
|
1070
1070
|
if (this.isDestroyed) {
|
|
1071
1071
|
throw Error('this.getById is no longer valid. Repository has been destroyed.');
|
|
1072
1072
|
}
|
|
1073
|
-
|
|
1074
|
-
return result.length > 0 ? result[0] : null;
|
|
1073
|
+
return this.getFirstBy(entity => entity.id === id);
|
|
1075
1074
|
}
|
|
1076
1075
|
|
|
1077
1076
|
/**
|
|
1078
1077
|
* Get an array of Entities by supplied filter function
|
|
1079
1078
|
* @param {function} filter - Filter function to apply to all entities
|
|
1080
|
-
* @return {Entity[]} Entities that passed through filter
|
|
1079
|
+
* @return {Entity[]} Entities that passed through filter, or []
|
|
1081
1080
|
*/
|
|
1082
1081
|
getBy = (filter) => {
|
|
1083
1082
|
if (this.isDestroyed) {
|
|
@@ -1093,7 +1092,7 @@ export default class Repository extends EventEmitter {
|
|
|
1093
1092
|
* filters into account. Defaults to false.
|
|
1094
1093
|
*
|
|
1095
1094
|
* @param {function} filter - Filter function to search by
|
|
1096
|
-
* @return {Entity} First Entity found
|
|
1095
|
+
* @return {Entity} First Entity found, or undefined
|
|
1097
1096
|
*/
|
|
1098
1097
|
getFirstBy = (filter) => {
|
|
1099
1098
|
if (this.isDestroyed) {
|
|
@@ -1104,7 +1103,7 @@ export default class Repository extends EventEmitter {
|
|
|
1104
1103
|
|
|
1105
1104
|
/**
|
|
1106
1105
|
* Get all phantom (unsaved) Entities
|
|
1107
|
-
* @return {Entity[]} Array of phantom Entities
|
|
1106
|
+
* @return {Entity[]} Array of phantom Entities, or []
|
|
1108
1107
|
*/
|
|
1109
1108
|
getPhantom = () => {
|
|
1110
1109
|
if (this.isDestroyed) {
|
|
@@ -1115,7 +1114,7 @@ export default class Repository extends EventEmitter {
|
|
|
1115
1114
|
|
|
1116
1115
|
/**
|
|
1117
1116
|
* Get all Entities not yet persisted to a storage medium
|
|
1118
|
-
* @return {Entity[]} Array of dirty Entities
|
|
1117
|
+
* @return {Entity[]} Array of dirty Entities, or []
|
|
1119
1118
|
*/
|
|
1120
1119
|
getNonPersisted = () => {
|
|
1121
1120
|
if (this.isDestroyed) {
|
|
@@ -1128,7 +1127,7 @@ export default class Repository extends EventEmitter {
|
|
|
1128
1127
|
|
|
1129
1128
|
/**
|
|
1130
1129
|
* Get all dirty (having unsaved changes) Entities
|
|
1131
|
-
* @return {Entity[]} Array of dirty Entities
|
|
1130
|
+
* @return {Entity[]} Array of dirty Entities, or []
|
|
1132
1131
|
*/
|
|
1133
1132
|
getDirty = () => {
|
|
1134
1133
|
if (this.isDestroyed) {
|
|
@@ -1141,7 +1140,7 @@ export default class Repository extends EventEmitter {
|
|
|
1141
1140
|
|
|
1142
1141
|
/**
|
|
1143
1142
|
* Get all deleted Entities
|
|
1144
|
-
* @return {Entity[]} Array of deleted Entities
|
|
1143
|
+
* @return {Entity[]} Array of deleted Entities, or []
|
|
1145
1144
|
*/
|
|
1146
1145
|
getDeleted = () => {
|
|
1147
1146
|
if (this.isDestroyed) {
|