@onehat/data 1.8.30 → 1.8.32
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.
|
@@ -8,6 +8,12 @@ describe('MemoryRepository', function() {
|
|
|
8
8
|
model: {
|
|
9
9
|
idProperty: 'key',
|
|
10
10
|
displayProperty: 'value',
|
|
11
|
+
sorters: [
|
|
12
|
+
{
|
|
13
|
+
name: 'key',
|
|
14
|
+
direction: 'ASC',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
11
17
|
properties: [
|
|
12
18
|
{ name: 'key', type: 'int' },
|
|
13
19
|
{ name: 'value' },
|
|
@@ -19,6 +25,7 @@ describe('MemoryRepository', function() {
|
|
|
19
25
|
id: 'foo',
|
|
20
26
|
schema: this.schema,
|
|
21
27
|
isPaginated: true,
|
|
28
|
+
isSorted: true,
|
|
22
29
|
data: [
|
|
23
30
|
{ key: 1, value: 'one', },
|
|
24
31
|
{ key: 2, value: 'two', },
|
|
@@ -148,11 +155,19 @@ describe('MemoryRepository', function() {
|
|
|
148
155
|
|
|
149
156
|
// setPageSize
|
|
150
157
|
this.repository.setPageSize(2);
|
|
158
|
+
this.repository.setPage(2);
|
|
151
159
|
expect(this.repository.pageTotal).to.be.eq(2);
|
|
160
|
+
let entitiesOnPage = this.repository.getEntitiesOnPage();
|
|
161
|
+
expect(_.size(entitiesOnPage)).to.be.eq(2);
|
|
162
|
+
|
|
163
|
+
expect(entitiesOnPage[0].id).to.be.eq(3);
|
|
164
|
+
expect(entitiesOnPage[1].id).to.be.eq(4);
|
|
152
165
|
|
|
153
166
|
// setPage
|
|
154
167
|
this.repository.setPage(3);
|
|
155
168
|
expect(this.repository.pageTotal).to.be.eq(1);
|
|
169
|
+
entitiesOnPage = this.repository.getEntitiesOnPage();
|
|
170
|
+
expect(_.size(entitiesOnPage)).to.be.eq(1);
|
|
156
171
|
|
|
157
172
|
// prevPage
|
|
158
173
|
this.repository.prevPage();
|
|
@@ -206,7 +221,7 @@ describe('MemoryRepository', function() {
|
|
|
206
221
|
const result = this.repository.getFirstBy((entity) => {
|
|
207
222
|
return entity.id > 2;
|
|
208
223
|
});
|
|
209
|
-
expect(result.id).to.be.eq(
|
|
224
|
+
expect(result.id).to.be.eq(3);
|
|
210
225
|
});
|
|
211
226
|
|
|
212
227
|
it('Repository.* retrieve methods, after delete/add', async function() {
|
|
@@ -465,9 +480,13 @@ describe('MemoryRepository', function() {
|
|
|
465
480
|
|
|
466
481
|
});
|
|
467
482
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
483
|
+
describe('toString', function() {
|
|
484
|
+
|
|
485
|
+
it('toString', function() {
|
|
486
|
+
const str = this.repository.toString();
|
|
487
|
+
expect(str).to.be.eq('MemoryRepository {bar} - foo');
|
|
488
|
+
});
|
|
489
|
+
|
|
471
490
|
});
|
|
472
491
|
|
|
473
492
|
});
|
|
@@ -25,9 +25,9 @@ describe('Schema', function() {
|
|
|
25
25
|
expect(_.isEqual(clone._originalConfig, this.schema._originalConfig)).to.be.true;
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
it('
|
|
29
|
-
const
|
|
30
|
-
expect(_.isEqual(
|
|
28
|
+
it('getPropertyDefinition', function() {
|
|
29
|
+
const propertyDefinition = this.schema.getPropertyDefinition('groups_users__id');
|
|
30
|
+
expect(_.isEqual(propertyDefinition.name, 'groups_users__id')).to.be.true;
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
});
|
package/package.json
CHANGED
package/src/Repository/Memory.js
CHANGED
|
@@ -429,6 +429,27 @@ class MemoryRepository extends Repository {
|
|
|
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
|
+
|
|
432
453
|
/**
|
|
433
454
|
* Get an array of all Entities
|
|
434
455
|
* @return {Entity[]} Entities that passed through filter
|
|
@@ -564,9 +585,6 @@ class MemoryRepository extends Repository {
|
|
|
564
585
|
|
|
565
586
|
destroy() {
|
|
566
587
|
// objects associated with this RepositoryType
|
|
567
|
-
_.each(this._keyedEntities, (entity) => {
|
|
568
|
-
entity.destroy();
|
|
569
|
-
})
|
|
570
588
|
this._keyedEntities = null;
|
|
571
589
|
this._unsortedEntities = null;
|
|
572
590
|
this._filteredEntities = null;
|
package/src/Schema/Schema.js
CHANGED
|
@@ -59,7 +59,7 @@ export default class Schema extends EventEmitter {
|
|
|
59
59
|
displayProperty: null,
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* @member {array}
|
|
62
|
+
* @member {array} properties - Array of Property definition objects
|
|
63
63
|
*/
|
|
64
64
|
properties: [],
|
|
65
65
|
|
|
@@ -183,20 +183,20 @@ export default class Schema extends EventEmitter {
|
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* Gets a single Property definition by name,
|
|
186
|
-
* @param {string} propertyName - Name of the
|
|
187
|
-
* @return {object}
|
|
186
|
+
* @param {string} propertyName - Name of the property definition to retrieve
|
|
187
|
+
* @return {object} propertyDefinition - The property definition
|
|
188
188
|
*/
|
|
189
|
-
|
|
189
|
+
getPropertyDefinition = (propertyName) => {
|
|
190
190
|
if (this.isDestroyed) {
|
|
191
|
-
throw Error('this.
|
|
191
|
+
throw Error('this.getPropertyDefinition is no longer valid. Schema has been destroyed.');
|
|
192
192
|
}
|
|
193
|
-
const
|
|
193
|
+
const propertyDefinition = _.find(this.model.properties, (propertyDefinition) => {
|
|
194
194
|
return propertyDefinition.name === propertyName;
|
|
195
195
|
});
|
|
196
|
-
if (!
|
|
197
|
-
throw new Error('Property ' + propertyName + ' not found.
|
|
196
|
+
if (!propertyDefinition) {
|
|
197
|
+
throw new Error('Property definition ' + propertyName + ' not found.');
|
|
198
198
|
}
|
|
199
|
-
return
|
|
199
|
+
return propertyDefinition;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|