@onehat/data 1.8.32 → 1.8.33
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.
|
@@ -39,8 +39,12 @@ describe('Entity', function() {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
afterEach(function() {
|
|
42
|
-
this.entity.
|
|
43
|
-
|
|
42
|
+
if (!this.entity.isDestroyed) {
|
|
43
|
+
this.entity.destroy();
|
|
44
|
+
}
|
|
45
|
+
if (!this.schema.isDestroyed) {
|
|
46
|
+
this.schema.destroy();
|
|
47
|
+
}
|
|
44
48
|
});
|
|
45
49
|
|
|
46
50
|
describe('constructor', function() {
|
package/package.json
CHANGED
package/src/Repository/Memory.js
CHANGED
|
@@ -417,39 +417,18 @@ class MemoryRepository extends Repository {
|
|
|
417
417
|
}
|
|
418
418
|
|
|
419
419
|
/**
|
|
420
|
-
*
|
|
421
|
-
* with sorting and filtering applied.
|
|
420
|
+
* Override Repository.getEntities, so we can get an array of
|
|
421
|
+
* all *active* Entities, with sorting and filtering applied.
|
|
422
422
|
* @return {array} Entities that passed through filter
|
|
423
423
|
*/
|
|
424
424
|
getEntities = () => {
|
|
425
425
|
if (this.isDestroyed) {
|
|
426
|
-
throw Error('this.
|
|
426
|
+
throw Error('this.getEntities is no longer valid. Repository has been destroyed.');
|
|
427
427
|
}
|
|
428
428
|
return this._getActiveEntities();
|
|
429
429
|
}
|
|
430
430
|
/* */
|
|
431
431
|
|
|
432
|
-
/**
|
|
433
|
-
* Get an array of all active Entities on current page,
|
|
434
|
-
* with sorting and filtering applied.
|
|
435
|
-
* @return {array} Entities that passed through filter
|
|
436
|
-
*/
|
|
437
|
-
getEntitiesOnPage = () => {
|
|
438
|
-
if (this.isDestroyed) {
|
|
439
|
-
throw Error('this.getPagedEntities is no longer valid. Repository has been destroyed.');
|
|
440
|
-
}
|
|
441
|
-
const entities = this.getEntities();
|
|
442
|
-
if (!this.isPaginated) {
|
|
443
|
-
return entities;
|
|
444
|
-
}
|
|
445
|
-
const
|
|
446
|
-
pageIx = this.page -1, // zero-indexed page#
|
|
447
|
-
start = pageIx * this.pageSize,
|
|
448
|
-
end = start + this.pageSize;
|
|
449
|
-
return entities.slice(start, end);
|
|
450
|
-
}
|
|
451
|
-
/* */
|
|
452
|
-
|
|
453
432
|
/**
|
|
454
433
|
* Get an array of all Entities
|
|
455
434
|
* @return {Entity[]} Entities that passed through filter
|
|
@@ -1224,6 +1224,41 @@ export default class Repository extends EventEmitter {
|
|
|
1224
1224
|
return _.filter(this.entities, entity => !entity.isPersisted);
|
|
1225
1225
|
}
|
|
1226
1226
|
|
|
1227
|
+
/**
|
|
1228
|
+
* Get an array of all Entities.
|
|
1229
|
+
* Can be overridden by subclasses.
|
|
1230
|
+
* @return {array} Entities that passed through filter
|
|
1231
|
+
*/
|
|
1232
|
+
getEntities = () => {
|
|
1233
|
+
if (this.isDestroyed) {
|
|
1234
|
+
throw Error('this.getEntities is no longer valid. Repository has been destroyed.');
|
|
1235
|
+
}
|
|
1236
|
+
return this.entities;
|
|
1237
|
+
}
|
|
1238
|
+
/* */
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* Get an array of all Entities on current page,
|
|
1242
|
+
* which for the base Repository, means all entities.
|
|
1243
|
+
* Subclasses may change this behavior.
|
|
1244
|
+
* @return {array} Entities
|
|
1245
|
+
*/
|
|
1246
|
+
getEntitiesOnPage = () => {
|
|
1247
|
+
if (this.isDestroyed) {
|
|
1248
|
+
throw Error('this.getPagedEntities is no longer valid. Repository has been destroyed.');
|
|
1249
|
+
}
|
|
1250
|
+
const entities = this.getEntities();
|
|
1251
|
+
if (!this.isPaginated) {
|
|
1252
|
+
return entities;
|
|
1253
|
+
}
|
|
1254
|
+
const
|
|
1255
|
+
pageIx = this.page -1, // zero-indexed page#
|
|
1256
|
+
start = pageIx * this.pageSize,
|
|
1257
|
+
end = start + this.pageSize;
|
|
1258
|
+
return entities.slice(start, end);
|
|
1259
|
+
}
|
|
1260
|
+
/* */
|
|
1261
|
+
|
|
1227
1262
|
/**
|
|
1228
1263
|
* Get all dirty (having unsaved changes) Entities
|
|
1229
1264
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|