@onehat/data 1.20.8 → 1.21.0
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/cypress/downloads/downloads.html +0 -0
- package/cypress/e2e/Entity.cy.js +2 -2
- package/cypress/e2e/Property/Base64.cy.js +37 -3
- package/cypress/e2e/Property/Boolean.cy.js +30 -0
- package/cypress/e2e/Property/Currency.cy.js +41 -0
- package/cypress/e2e/Property/Date.cy.js +33 -0
- package/cypress/e2e/Property/DateTime.cy.js +33 -0
- package/cypress/e2e/Property/Float.cy.js +31 -0
- package/cypress/e2e/Property/Integer.cy.js +31 -0
- package/cypress/e2e/Property/Json.cy.js +29 -0
- package/cypress/e2e/Property/PercentInt.cy.js +32 -0
- package/cypress/e2e/Property/Property.cy.js +29 -0
- package/cypress/e2e/Property/Time.cy.js +33 -0
- package/cypress/e2e/Repository/Repository.cy.js +25 -18
- package/cypress/e2e/Schema.cy.js +2 -2
- package/package.json +1 -1
- package/src/Integration/Browser/Repository/Cookie.js +4 -4
- package/src/Integration/Browser/Repository/IndexedDB.js +4 -4
- package/src/Integration/Browser/Repository/LocalStorage.js +4 -4
- package/src/Integration/Browser/Repository/SecureLocalStorage.js +2 -2
- package/src/Integration/Browser/Repository/SecureSessionStorage.js +2 -2
- package/src/Integration/Browser/Repository/SessionStorage.js +4 -4
- package/src/Integration/ReactNative/Repository/AsyncStorage.js +8 -8
- package/src/Integration/ReactNative/Repository/SecureStore.js +4 -4
- package/src/Property/Base64.js +21 -11
- package/src/Property/Boolean.js +20 -12
- package/src/Property/Currency.js +30 -21
- package/src/Property/Date.js +23 -14
- package/src/Property/DateTime.js +18 -9
- package/src/Property/File.js +0 -4
- package/src/Property/Float.js +19 -10
- package/src/Property/Integer.js +19 -10
- package/src/Property/Json.js +22 -13
- package/src/Property/Percent.js +2 -2
- package/src/Property/PercentInt.js +16 -7
- package/src/Property/Property.js +150 -140
- package/src/Property/String.js +2 -7
- package/src/Property/Time.js +17 -8
- package/src/Property/Uuid.js +3 -8
- package/src/Property/index.js +2 -0
- package/src/Repository/Ajax.js +35 -30
- package/src/Repository/LocalFromRemote/Command.js +5 -5
- package/src/Repository/LocalFromRemote/CommandRepository.js +1 -1
- package/src/Repository/LocalFromRemote/LocalFromRemote.js +18 -17
- package/src/Repository/Memory.js +22 -21
- package/src/Repository/Null.js +5 -5
- package/src/Repository/Offline.js +17 -16
- package/src/Repository/OneBuild.js +37 -31
- package/src/Repository/OneBuild2.js +19 -13
- package/src/Repository/Repository.js +106 -103
- package/src/Schema/Schema.js +9 -6
|
@@ -33,8 +33,7 @@ export default class Repository extends EventEmitter {
|
|
|
33
33
|
const { schema } = config;
|
|
34
34
|
|
|
35
35
|
if (!schema || !schema.model) {
|
|
36
|
-
|
|
37
|
-
return;
|
|
36
|
+
throw Error('Schema cannot be empty'); // don't use throwError() because Repository is not yet successfully constructed
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
const defaults = {
|
|
@@ -303,6 +302,9 @@ export default class Repository extends EventEmitter {
|
|
|
303
302
|
'reloadEntity',
|
|
304
303
|
'save',
|
|
305
304
|
]);
|
|
305
|
+
|
|
306
|
+
// create error listener to block Node from throwing the Error. https://nodejs.org/dist/v11.13.0/docs/api/events.html#events_emitter_emit_eventname_args:~:text=Error%20events-,%23,-When%20an%20error
|
|
307
|
+
this.on('error', () => {});
|
|
306
308
|
}
|
|
307
309
|
|
|
308
310
|
/**
|
|
@@ -362,15 +364,16 @@ export default class Repository extends EventEmitter {
|
|
|
362
364
|
* Creates the methods for this Repository, based on Schema.
|
|
363
365
|
* @private
|
|
364
366
|
*/
|
|
365
|
-
_createMethods
|
|
367
|
+
_createMethods() {
|
|
366
368
|
if (this.isDestroyed) {
|
|
367
369
|
this.throwError('this._createMethods is no longer valid. Repository has been destroyed.');
|
|
368
370
|
return;
|
|
369
371
|
}
|
|
370
372
|
const methodDefinitions = this.schema.repository.methods || this.originalConfig.methods; // The latter is mainly for lfr repositories
|
|
371
373
|
if (!_.isEmpty(methodDefinitions)) {
|
|
374
|
+
const oThis = this;
|
|
372
375
|
_.each(methodDefinitions, (method, name) => {
|
|
373
|
-
|
|
376
|
+
oThis[name] = method; // NOTE: Methods must be defined in schema as "function() {}", not as "() => {}" so scope of "this" will be correct
|
|
374
377
|
});
|
|
375
378
|
}
|
|
376
379
|
}
|
|
@@ -379,15 +382,16 @@ export default class Repository extends EventEmitter {
|
|
|
379
382
|
* Creates the static properties for this Repository, based on Schema.
|
|
380
383
|
* @private
|
|
381
384
|
*/
|
|
382
|
-
|
|
385
|
+
_createStatics() {
|
|
383
386
|
if (this.isDestroyed) {
|
|
384
387
|
this.throwError('this._createStatics is no longer valid. Repository has been destroyed.');
|
|
385
388
|
return;
|
|
386
389
|
}
|
|
387
390
|
const staticsDefinitions = this.schema.repository.statics || this.originalConfig.statics; // The latter is mainly for lfr repositories
|
|
388
391
|
if (!_.isEmpty(staticsDefinitions)) {
|
|
392
|
+
const oThis = this;
|
|
389
393
|
_.each(staticsDefinitions, (value, key) => {
|
|
390
|
-
|
|
394
|
+
oThis[key] = value;
|
|
391
395
|
});
|
|
392
396
|
}
|
|
393
397
|
}
|
|
@@ -403,7 +407,7 @@ export default class Repository extends EventEmitter {
|
|
|
403
407
|
* Tells storage medium to load data
|
|
404
408
|
* @abstract
|
|
405
409
|
*/
|
|
406
|
-
|
|
410
|
+
async load() {
|
|
407
411
|
this.throwError('load must be implemented by Repository subclass');
|
|
408
412
|
return;
|
|
409
413
|
}
|
|
@@ -411,14 +415,14 @@ export default class Repository extends EventEmitter {
|
|
|
411
415
|
/**
|
|
412
416
|
* Marks this repository as loading
|
|
413
417
|
*/
|
|
414
|
-
markLoading
|
|
418
|
+
markLoading(bool = true) {
|
|
415
419
|
this.isLoading = bool;
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
/**
|
|
419
423
|
* Async function that resolves when !isLoading
|
|
420
424
|
*/
|
|
421
|
-
|
|
425
|
+
async waitUntilDoneLoading(timeout = 10000) {
|
|
422
426
|
if (this.isDestroyed) {
|
|
423
427
|
this.throwError('this.waitUntilDoneLoading is no longer valid. Repository has been destroyed.');
|
|
424
428
|
return;
|
|
@@ -430,7 +434,7 @@ export default class Repository extends EventEmitter {
|
|
|
430
434
|
/**
|
|
431
435
|
* Marks this repository as loaded
|
|
432
436
|
*/
|
|
433
|
-
markLoaded
|
|
437
|
+
markLoaded() {
|
|
434
438
|
this.markLoading(false);
|
|
435
439
|
this.isLoaded = true;
|
|
436
440
|
this.lastLoaded = moment(new Date()).format('YYYY-MM-DD HH:mm:ss.SSSS');
|
|
@@ -449,7 +453,7 @@ export default class Repository extends EventEmitter {
|
|
|
449
453
|
* Tells storage medium to reload just this one entity
|
|
450
454
|
* @abstract
|
|
451
455
|
*/
|
|
452
|
-
|
|
456
|
+
async reloadEntity(entity) {
|
|
453
457
|
this.throwError('reloadEntity must be implemented by Repository subclass');
|
|
454
458
|
return;
|
|
455
459
|
}
|
|
@@ -458,7 +462,7 @@ export default class Repository extends EventEmitter {
|
|
|
458
462
|
* Sets the isAutoSave setting of this Repository
|
|
459
463
|
* @param {boolean} isAutoSave
|
|
460
464
|
*/
|
|
461
|
-
setAutoSave
|
|
465
|
+
setAutoSave(isAutoSave) {
|
|
462
466
|
if (this.isDestroyed) {
|
|
463
467
|
this.throwError('this.setAutoSave is no longer valid. Repository has been destroyed.');
|
|
464
468
|
return;
|
|
@@ -470,7 +474,7 @@ export default class Repository extends EventEmitter {
|
|
|
470
474
|
* Sets the isAutoLoad setting of this Repository
|
|
471
475
|
* @param {boolean} isAutoLoad
|
|
472
476
|
*/
|
|
473
|
-
setAutoLoad
|
|
477
|
+
setAutoLoad(isAutoLoad) {
|
|
474
478
|
if (this.isDestroyed) {
|
|
475
479
|
this.throwError('this.setAutoLoad is no longer valid. Repository has been destroyed.');
|
|
476
480
|
return;
|
|
@@ -499,7 +503,7 @@ export default class Repository extends EventEmitter {
|
|
|
499
503
|
/**
|
|
500
504
|
* Clear all sorting from this Repository.
|
|
501
505
|
*/
|
|
502
|
-
clearSort
|
|
506
|
+
clearSort() {
|
|
503
507
|
if (this.isDestroyed) {
|
|
504
508
|
this.throwError('this.clearSort is no longer valid. Repository has been destroyed.');
|
|
505
509
|
return;
|
|
@@ -537,7 +541,7 @@ export default class Repository extends EventEmitter {
|
|
|
537
541
|
*
|
|
538
542
|
* @return this
|
|
539
543
|
*/
|
|
540
|
-
sort
|
|
544
|
+
sort(arg1 = null, arg2 = 'ASC', arg3 = null) {
|
|
541
545
|
if (this.isDestroyed) {
|
|
542
546
|
this.throwError('this.sort is no longer valid. Repository has been destroyed.');
|
|
543
547
|
return;
|
|
@@ -569,7 +573,7 @@ export default class Repository extends EventEmitter {
|
|
|
569
573
|
* Gets default sorters. Either what was specified on schema, or sorty by displayProperty ASC.
|
|
570
574
|
* @return {array} sorters
|
|
571
575
|
*/
|
|
572
|
-
getDefaultSorters
|
|
576
|
+
getDefaultSorters() {
|
|
573
577
|
if (this.isDestroyed) {
|
|
574
578
|
this.throwError('this.getDefaultSorters is no longer valid. Repository has been destroyed.');
|
|
575
579
|
return;
|
|
@@ -597,7 +601,7 @@ export default class Repository extends EventEmitter {
|
|
|
597
601
|
* Sets the sorters directly
|
|
598
602
|
* @fires changeSorters
|
|
599
603
|
*/
|
|
600
|
-
setSorters
|
|
604
|
+
setSorters(sorters) {
|
|
601
605
|
if (this.isDestroyed) {
|
|
602
606
|
this.throwError('this.setSorters is no longer valid. Repository has been destroyed.');
|
|
603
607
|
return;
|
|
@@ -612,20 +616,21 @@ export default class Repository extends EventEmitter {
|
|
|
612
616
|
isChanged = true;
|
|
613
617
|
|
|
614
618
|
// Check to make sure specified properties are sortable
|
|
619
|
+
const oThis = this;
|
|
615
620
|
_.each(sorters, (sorter) => {
|
|
616
621
|
if (_.isFunction(sorter)) {
|
|
617
622
|
return; // skip
|
|
618
623
|
}
|
|
619
|
-
const propertyDefinition = _.find(
|
|
624
|
+
const propertyDefinition = _.find(oThis.schema.model.properties, (property) => property.name === sorter.name);
|
|
620
625
|
if (!propertyDefinition) {
|
|
621
|
-
|
|
626
|
+
oThis.throwError('Sorting property does not exist.');
|
|
622
627
|
return;
|
|
623
628
|
}
|
|
624
629
|
const propertyType = propertyDefinition.type;
|
|
625
630
|
if (propertyType && PropertyTypes[propertyType]) {
|
|
626
631
|
const propertyInstance = new PropertyTypes[propertyType]();
|
|
627
632
|
if (!propertyInstance.isSortable) {
|
|
628
|
-
|
|
633
|
+
oThis.throwError('Sorting property type is not sortable.');
|
|
629
634
|
return;
|
|
630
635
|
}
|
|
631
636
|
}
|
|
@@ -654,7 +659,7 @@ export default class Repository extends EventEmitter {
|
|
|
654
659
|
return this.filters.length > 0;
|
|
655
660
|
}
|
|
656
661
|
|
|
657
|
-
hasFilter
|
|
662
|
+
hasFilter(name) {
|
|
658
663
|
if (!this.hasFilters) {
|
|
659
664
|
return false;
|
|
660
665
|
}
|
|
@@ -662,7 +667,7 @@ export default class Repository extends EventEmitter {
|
|
|
662
667
|
return !!found;
|
|
663
668
|
}
|
|
664
669
|
|
|
665
|
-
hasFilterValue
|
|
670
|
+
hasFilterValue(name, value) {
|
|
666
671
|
if (!this.hasFilters) {
|
|
667
672
|
return false;
|
|
668
673
|
}
|
|
@@ -705,7 +710,7 @@ export default class Repository extends EventEmitter {
|
|
|
705
710
|
*
|
|
706
711
|
* @return this
|
|
707
712
|
*/
|
|
708
|
-
filter
|
|
713
|
+
filter(arg1 = null, arg2 = null, clearFirst = true) {
|
|
709
714
|
if (this.isDestroyed) {
|
|
710
715
|
this.throwError('this.filter is no longer valid. Repository has been destroyed.');
|
|
711
716
|
return;
|
|
@@ -773,7 +778,7 @@ export default class Repository extends EventEmitter {
|
|
|
773
778
|
*
|
|
774
779
|
* @return this
|
|
775
780
|
*/
|
|
776
|
-
setFilters
|
|
781
|
+
setFilters(filters, clearFirst = true) {
|
|
777
782
|
const parsed = _.map(filters, (value, name) => {
|
|
778
783
|
return {
|
|
779
784
|
name,
|
|
@@ -793,7 +798,7 @@ export default class Repository extends EventEmitter {
|
|
|
793
798
|
* - repository.clearFilters('first_name'); // Clear a single filter
|
|
794
799
|
* - repository.clearFilters(['first_name', 'last_name']); // Clear multiple filters
|
|
795
800
|
*/
|
|
796
|
-
clearFilters
|
|
801
|
+
clearFilters(filtersToClear) {
|
|
797
802
|
let filters = [];
|
|
798
803
|
if (filtersToClear) {
|
|
799
804
|
if (_.isString(filtersToClear)) {
|
|
@@ -811,7 +816,7 @@ export default class Repository extends EventEmitter {
|
|
|
811
816
|
* @private
|
|
812
817
|
* @fires changeFilters
|
|
813
818
|
*/
|
|
814
|
-
_setFilters
|
|
819
|
+
_setFilters(filters) {
|
|
815
820
|
if (this.isDestroyed) {
|
|
816
821
|
this.throwError('this._setFilters is no longer valid. Repository has been destroyed.');
|
|
817
822
|
return;
|
|
@@ -845,7 +850,7 @@ export default class Repository extends EventEmitter {
|
|
|
845
850
|
* Resets the pagination to page one
|
|
846
851
|
* @fires changePageSize
|
|
847
852
|
*/
|
|
848
|
-
resetPagination
|
|
853
|
+
resetPagination() {
|
|
849
854
|
if (this.isDestroyed) {
|
|
850
855
|
this.throwError('this.resetPagination is no longer valid. Repository has been destroyed.');
|
|
851
856
|
return;
|
|
@@ -856,7 +861,7 @@ export default class Repository extends EventEmitter {
|
|
|
856
861
|
/**
|
|
857
862
|
* Sets isPaginated
|
|
858
863
|
*/
|
|
859
|
-
setIsPaginated
|
|
864
|
+
setIsPaginated(bool) {
|
|
860
865
|
if (this.isDestroyed) {
|
|
861
866
|
this.throwError('this.setIsPaginated is no longer valid. Repository has been destroyed.');
|
|
862
867
|
return;
|
|
@@ -874,7 +879,7 @@ export default class Repository extends EventEmitter {
|
|
|
874
879
|
* @fires changePage
|
|
875
880
|
* @fires changePageSize
|
|
876
881
|
*/
|
|
877
|
-
setPageSize
|
|
882
|
+
setPageSize(pageSize) {
|
|
878
883
|
if (this.isDestroyed) {
|
|
879
884
|
this.throwError('this.setPageSize is no longer valid. Repository has been destroyed.');
|
|
880
885
|
return;
|
|
@@ -905,7 +910,7 @@ export default class Repository extends EventEmitter {
|
|
|
905
910
|
* @return {boolean} success
|
|
906
911
|
* @fires changePage
|
|
907
912
|
*/
|
|
908
|
-
setPage
|
|
913
|
+
setPage(page) {
|
|
909
914
|
if (this.isDestroyed) {
|
|
910
915
|
this.throwError('this.setPage is no longer valid. Repository has been destroyed.');
|
|
911
916
|
return;
|
|
@@ -935,7 +940,7 @@ export default class Repository extends EventEmitter {
|
|
|
935
940
|
* Advances to the previous page of entities
|
|
936
941
|
* @return {boolean} success
|
|
937
942
|
*/
|
|
938
|
-
prevPage
|
|
943
|
+
prevPage() {
|
|
939
944
|
return this.setPage(this.page -1);
|
|
940
945
|
}
|
|
941
946
|
|
|
@@ -943,7 +948,7 @@ export default class Repository extends EventEmitter {
|
|
|
943
948
|
* Advances to the next page of entities
|
|
944
949
|
* @return {boolean} success
|
|
945
950
|
*/
|
|
946
|
-
nextPage
|
|
951
|
+
nextPage() {
|
|
947
952
|
return this.setPage(this.page +1);
|
|
948
953
|
}
|
|
949
954
|
|
|
@@ -953,7 +958,7 @@ export default class Repository extends EventEmitter {
|
|
|
953
958
|
* This function takes care of calculating and setting the rest.
|
|
954
959
|
* @private
|
|
955
960
|
*/
|
|
956
|
-
_setPaginationVars
|
|
961
|
+
_setPaginationVars() {
|
|
957
962
|
if (this.isDestroyed) {
|
|
958
963
|
this.throwError('this._setPaginationVars is no longer valid. Repository has been destroyed.');
|
|
959
964
|
return;
|
|
@@ -988,7 +993,7 @@ export default class Repository extends EventEmitter {
|
|
|
988
993
|
* @private
|
|
989
994
|
* @static
|
|
990
995
|
*/
|
|
991
|
-
static _calculatePaginationVars
|
|
996
|
+
static _calculatePaginationVars(total, page, pageSize) {
|
|
992
997
|
|
|
993
998
|
// Special case: empty pages
|
|
994
999
|
if (total < 1) {
|
|
@@ -1049,7 +1054,7 @@ export default class Repository extends EventEmitter {
|
|
|
1049
1054
|
* @return {object} entity - new Entity object
|
|
1050
1055
|
* @fires add
|
|
1051
1056
|
*/
|
|
1052
|
-
|
|
1057
|
+
async add(data, isPersisted = false, isDelayedSave = false) {
|
|
1053
1058
|
if (this.isDestroyed) {
|
|
1054
1059
|
this.throwError('this.add is no longer valid. Repository has been destroyed.');
|
|
1055
1060
|
return;
|
|
@@ -1113,7 +1118,7 @@ export default class Repository extends EventEmitter {
|
|
|
1113
1118
|
* @param {boolean} isDelayedSave - Should the repository skip autosave when immediately adding the record?
|
|
1114
1119
|
* @return {object} entity - new Entity object
|
|
1115
1120
|
*/
|
|
1116
|
-
createStandaloneEntity
|
|
1121
|
+
createStandaloneEntity(data, isPersisted = false, isDelayedSave = false) {
|
|
1117
1122
|
if (this.isDestroyed) {
|
|
1118
1123
|
this.throwError('this.createStandaloneEntity is no longer valid. Repository has been destroyed.');
|
|
1119
1124
|
return;
|
|
@@ -1134,7 +1139,7 @@ export default class Repository extends EventEmitter {
|
|
|
1134
1139
|
* @param {boolean} isPersisted - Whether the new entities should be marked as already being persisted in storage medium.
|
|
1135
1140
|
* @return {array} entities - new Entity objects
|
|
1136
1141
|
*/
|
|
1137
|
-
|
|
1142
|
+
async addMultiple(allData, isPersisted = false) {
|
|
1138
1143
|
|
|
1139
1144
|
if (!this.canAdd) {
|
|
1140
1145
|
this.throwError('Adding has been disabled on this repository.');
|
|
@@ -1166,7 +1171,7 @@ export default class Repository extends EventEmitter {
|
|
|
1166
1171
|
* @return {object} entity - new Entity object
|
|
1167
1172
|
* @private
|
|
1168
1173
|
*/
|
|
1169
|
-
static _createEntity
|
|
1174
|
+
static _createEntity(schema, rawData, repository = null, isPersisted = false, isDelayedSave = false, isRemotePhantomMode = false) {
|
|
1170
1175
|
const entity = new Entity(schema, rawData, repository, isDelayedSave, isRemotePhantomMode);
|
|
1171
1176
|
entity.initialize();
|
|
1172
1177
|
entity.isPersisted = isPersisted;
|
|
@@ -1179,7 +1184,7 @@ export default class Repository extends EventEmitter {
|
|
|
1179
1184
|
* @param {object} entity - Entity
|
|
1180
1185
|
* @private
|
|
1181
1186
|
*/
|
|
1182
|
-
_relayEntityEvents
|
|
1187
|
+
_relayEntityEvents(entity) {
|
|
1183
1188
|
if (this.isDestroyed) {
|
|
1184
1189
|
this.throwError('this._relayEntityEvents is no longer valid. Repository has been destroyed.');
|
|
1185
1190
|
return;
|
|
@@ -1196,7 +1201,7 @@ export default class Repository extends EventEmitter {
|
|
|
1196
1201
|
* Destroys the current entities -
|
|
1197
1202
|
* mostly so they can be replaced with other entities.
|
|
1198
1203
|
*/
|
|
1199
|
-
_destroyEntities
|
|
1204
|
+
_destroyEntities() {
|
|
1200
1205
|
_.each(this.entities, (entity) => {
|
|
1201
1206
|
entity.destroy();
|
|
1202
1207
|
});
|
|
@@ -1206,7 +1211,7 @@ export default class Repository extends EventEmitter {
|
|
|
1206
1211
|
/**
|
|
1207
1212
|
* Inserts the newEntity directly before entity on the current page.
|
|
1208
1213
|
*/
|
|
1209
|
-
_insertBefore
|
|
1214
|
+
_insertBefore(newEntity, entity = null) {
|
|
1210
1215
|
|
|
1211
1216
|
const
|
|
1212
1217
|
currentEntities = this.getEntities(),
|
|
@@ -1236,7 +1241,7 @@ export default class Repository extends EventEmitter {
|
|
|
1236
1241
|
* usually, the current "page".
|
|
1237
1242
|
* Does not actually affect anything on the server.
|
|
1238
1243
|
*/
|
|
1239
|
-
|
|
1244
|
+
async clear() {
|
|
1240
1245
|
this._destroyEntities();
|
|
1241
1246
|
}
|
|
1242
1247
|
|
|
@@ -1251,7 +1256,7 @@ export default class Repository extends EventEmitter {
|
|
|
1251
1256
|
* Gets an array of "submit" values objects for the entities
|
|
1252
1257
|
* @return {array} map -
|
|
1253
1258
|
*/
|
|
1254
|
-
getSubmitValues
|
|
1259
|
+
getSubmitValues() {
|
|
1255
1260
|
return _.map(this.entities, (entity) => {
|
|
1256
1261
|
return entity.getSubmitValues();
|
|
1257
1262
|
});
|
|
@@ -1261,7 +1266,7 @@ export default class Repository extends EventEmitter {
|
|
|
1261
1266
|
* Gets an array of "display" values objects for the entities
|
|
1262
1267
|
* @return {array} map -
|
|
1263
1268
|
*/
|
|
1264
|
-
getDisplayValues
|
|
1269
|
+
getDisplayValues() {
|
|
1265
1270
|
return _.map(this.entities, (entity) => {
|
|
1266
1271
|
return entity.getDisplayValues();
|
|
1267
1272
|
});
|
|
@@ -1271,7 +1276,7 @@ export default class Repository extends EventEmitter {
|
|
|
1271
1276
|
* Gets an array of "raw" values objects for the entities
|
|
1272
1277
|
* @return {array} map -
|
|
1273
1278
|
*/
|
|
1274
|
-
getRawValues
|
|
1279
|
+
getRawValues() {
|
|
1275
1280
|
return _.map(this.entities, (entity) => {
|
|
1276
1281
|
return entity.getRawValues();
|
|
1277
1282
|
});
|
|
@@ -1281,7 +1286,7 @@ export default class Repository extends EventEmitter {
|
|
|
1281
1286
|
* Gets an array of "originalData" values objects for the entities
|
|
1282
1287
|
* @return {array} map -
|
|
1283
1288
|
*/
|
|
1284
|
-
getOriginalData
|
|
1289
|
+
getOriginalData() {
|
|
1285
1290
|
return _.map(this.entities, (entity) => {
|
|
1286
1291
|
return entity.getOriginalData();
|
|
1287
1292
|
});
|
|
@@ -1291,7 +1296,7 @@ export default class Repository extends EventEmitter {
|
|
|
1291
1296
|
* Gets a single random entity
|
|
1292
1297
|
* @return {array} map -
|
|
1293
1298
|
*/
|
|
1294
|
-
getRandomEntity
|
|
1299
|
+
getRandomEntity() {
|
|
1295
1300
|
const len = this.entities.length;
|
|
1296
1301
|
if (!len) {
|
|
1297
1302
|
return null;
|
|
@@ -1304,7 +1309,7 @@ export default class Repository extends EventEmitter {
|
|
|
1304
1309
|
* Gets an array of "parsed" values objects for the entities
|
|
1305
1310
|
* @return {array} map -
|
|
1306
1311
|
*/
|
|
1307
|
-
getParsedValues
|
|
1312
|
+
getParsedValues() {
|
|
1308
1313
|
return _.map(this.entities, (entity) => {
|
|
1309
1314
|
return entity.getParsedValues();
|
|
1310
1315
|
});
|
|
@@ -1315,7 +1320,7 @@ export default class Repository extends EventEmitter {
|
|
|
1315
1320
|
* @param {integer} ix - Index
|
|
1316
1321
|
* @return {object} entity - Entity
|
|
1317
1322
|
*/
|
|
1318
|
-
getByIx
|
|
1323
|
+
getByIx(ix) {
|
|
1319
1324
|
if (this.isDestroyed) {
|
|
1320
1325
|
this.throwError('this.getByIx is no longer valid. Repository has been destroyed.');
|
|
1321
1326
|
return;
|
|
@@ -1330,7 +1335,7 @@ export default class Repository extends EventEmitter {
|
|
|
1330
1335
|
* @param {integer} endIx - Index (inclusive)
|
|
1331
1336
|
* @return {array} entities - Array of Entities
|
|
1332
1337
|
*/
|
|
1333
|
-
getByRange
|
|
1338
|
+
getByRange(startIx, endIx) {
|
|
1334
1339
|
if (this.isDestroyed) {
|
|
1335
1340
|
this.throwError('this.getByRange is no longer valid. Repository has been destroyed.');
|
|
1336
1341
|
return;
|
|
@@ -1343,7 +1348,7 @@ export default class Repository extends EventEmitter {
|
|
|
1343
1348
|
* @param {integer} id - id of record to retrieve
|
|
1344
1349
|
* @return {Entity} The Entity with matching id, or undefined
|
|
1345
1350
|
*/
|
|
1346
|
-
getById
|
|
1351
|
+
getById(id) {
|
|
1347
1352
|
if (this.isDestroyed) {
|
|
1348
1353
|
this.throwError('this.getById is no longer valid. Repository has been destroyed.');
|
|
1349
1354
|
return;
|
|
@@ -1356,7 +1361,7 @@ export default class Repository extends EventEmitter {
|
|
|
1356
1361
|
* @param {integer} id - id of record to retrieve
|
|
1357
1362
|
* @return {integer} The numerical index, or undefined
|
|
1358
1363
|
*/
|
|
1359
|
-
getIxById
|
|
1364
|
+
getIxById(id) {
|
|
1360
1365
|
if (this.isDestroyed) {
|
|
1361
1366
|
this.throwError('this.getIxById is no longer valid. Repository has been destroyed.');
|
|
1362
1367
|
return;
|
|
@@ -1374,7 +1379,7 @@ export default class Repository extends EventEmitter {
|
|
|
1374
1379
|
* @param {function} filter - Filter function to apply to all entities
|
|
1375
1380
|
* @return {Entity[]} Entities that passed through filter, or []
|
|
1376
1381
|
*/
|
|
1377
|
-
getBy
|
|
1382
|
+
getBy(filter) {
|
|
1378
1383
|
if (this.isDestroyed) {
|
|
1379
1384
|
this.throwError('this.getBy is no longer valid. Repository has been destroyed.');
|
|
1380
1385
|
return;
|
|
@@ -1391,7 +1396,7 @@ export default class Repository extends EventEmitter {
|
|
|
1391
1396
|
* @param {function} filter - Filter function to search by
|
|
1392
1397
|
* @return {Entity} First Entity found, or undefined
|
|
1393
1398
|
*/
|
|
1394
|
-
getFirstBy
|
|
1399
|
+
getFirstBy(filter) {
|
|
1395
1400
|
if (this.isDestroyed) {
|
|
1396
1401
|
this.throwError('this.getFirstBy is no longer valid. Repository has been destroyed.');
|
|
1397
1402
|
return;
|
|
@@ -1404,7 +1409,7 @@ export default class Repository extends EventEmitter {
|
|
|
1404
1409
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|
|
1405
1410
|
* @return {Entity[]} Array of phantom Entities, or []
|
|
1406
1411
|
*/
|
|
1407
|
-
getPhantom
|
|
1412
|
+
getPhantom(entities = null) {
|
|
1408
1413
|
if (this.isDestroyed) {
|
|
1409
1414
|
this.throwError('this.getPhantom is no longer valid. Repository has been destroyed.');
|
|
1410
1415
|
return;
|
|
@@ -1420,7 +1425,7 @@ export default class Repository extends EventEmitter {
|
|
|
1420
1425
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|
|
1421
1426
|
* @return {Entity[]} Array of dirty Entities, or []
|
|
1422
1427
|
*/
|
|
1423
|
-
getNonPersisted
|
|
1428
|
+
getNonPersisted(entities = null) {
|
|
1424
1429
|
if (this.isDestroyed) {
|
|
1425
1430
|
this.throwError('this.getNonPersisted is no longer valid. Repository has been destroyed.');
|
|
1426
1431
|
return;
|
|
@@ -1436,7 +1441,7 @@ export default class Repository extends EventEmitter {
|
|
|
1436
1441
|
* Can be overridden by subclasses.
|
|
1437
1442
|
* @return {array} Entities that passed through filter
|
|
1438
1443
|
*/
|
|
1439
|
-
getEntities
|
|
1444
|
+
getEntities() {
|
|
1440
1445
|
if (this.isDestroyed) {
|
|
1441
1446
|
this.throwError('this.getEntities is no longer valid. Repository has been destroyed.');
|
|
1442
1447
|
return;
|
|
@@ -1451,7 +1456,7 @@ export default class Repository extends EventEmitter {
|
|
|
1451
1456
|
* Subclasses may change this behavior.
|
|
1452
1457
|
* @return {array} Entities
|
|
1453
1458
|
*/
|
|
1454
|
-
getEntitiesOnPage
|
|
1459
|
+
getEntitiesOnPage() {
|
|
1455
1460
|
if (this.isDestroyed) {
|
|
1456
1461
|
this.throwError('this.getPagedEntities is no longer valid. Repository has been destroyed.');
|
|
1457
1462
|
return;
|
|
@@ -1473,7 +1478,7 @@ export default class Repository extends EventEmitter {
|
|
|
1473
1478
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|
|
1474
1479
|
* @return {Entity[]} Array of dirty Entities, or []
|
|
1475
1480
|
*/
|
|
1476
|
-
getDirty
|
|
1481
|
+
getDirty(entities = null) {
|
|
1477
1482
|
if (this.isDestroyed) {
|
|
1478
1483
|
this.throwError('this.getDirty is no longer valid. Repository has been destroyed.');
|
|
1479
1484
|
return;
|
|
@@ -1489,7 +1494,7 @@ export default class Repository extends EventEmitter {
|
|
|
1489
1494
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|
|
1490
1495
|
* @return {Entity[]} Array of deleted Entities, or []
|
|
1491
1496
|
*/
|
|
1492
|
-
getDeleted
|
|
1497
|
+
getDeleted(entities = null) {
|
|
1493
1498
|
if (this.isDestroyed) {
|
|
1494
1499
|
this.throwError('this.getDeleted is no longer valid. Repository has been destroyed.');
|
|
1495
1500
|
return;
|
|
@@ -1505,7 +1510,7 @@ export default class Repository extends EventEmitter {
|
|
|
1505
1510
|
* @param {array} entities - Array of entities to filter. Optional. Defaults to this.entities
|
|
1506
1511
|
* @return {Entity[]} Array of deleted Entities, or []
|
|
1507
1512
|
*/
|
|
1508
|
-
getStaged
|
|
1513
|
+
getStaged(entities = null) {
|
|
1509
1514
|
if (this.isDestroyed) {
|
|
1510
1515
|
this.throwError('this.getStaged is no longer valid. Repository has been destroyed.');
|
|
1511
1516
|
return;
|
|
@@ -1520,7 +1525,7 @@ export default class Repository extends EventEmitter {
|
|
|
1520
1525
|
* Gets the Schema object
|
|
1521
1526
|
* @return {Schema} schema
|
|
1522
1527
|
*/
|
|
1523
|
-
getSchema
|
|
1528
|
+
getSchema() {
|
|
1524
1529
|
if (this.isDestroyed) {
|
|
1525
1530
|
this.throwError('this.getSchema is no longer valid. Repository has been destroyed.');
|
|
1526
1531
|
return;
|
|
@@ -1532,7 +1537,7 @@ export default class Repository extends EventEmitter {
|
|
|
1532
1537
|
* Gets the sort field, if only one sorter is applied.
|
|
1533
1538
|
* @return {Schema} schema
|
|
1534
1539
|
*/
|
|
1535
|
-
getSortField
|
|
1540
|
+
getSortField() {
|
|
1536
1541
|
if (this.isDestroyed) {
|
|
1537
1542
|
this.throwError('this.getSortField is no longer valid. Repository has been destroyed.');
|
|
1538
1543
|
return;
|
|
@@ -1547,7 +1552,7 @@ export default class Repository extends EventEmitter {
|
|
|
1547
1552
|
* Gets the sort direction, if only one sorter is applied.
|
|
1548
1553
|
* @return {Schema} schema
|
|
1549
1554
|
*/
|
|
1550
|
-
getSortDirection
|
|
1555
|
+
getSortDirection() {
|
|
1551
1556
|
if (this.isDestroyed) {
|
|
1552
1557
|
this.throwError('this.getSortDirection is no longer valid. Repository has been destroyed.');
|
|
1553
1558
|
return;
|
|
@@ -1562,7 +1567,7 @@ export default class Repository extends EventEmitter {
|
|
|
1562
1567
|
* Gets the sort function, if only one sorter is applied.
|
|
1563
1568
|
* @return {Schema} schema
|
|
1564
1569
|
*/
|
|
1565
|
-
getSortFn
|
|
1570
|
+
getSortFn() {
|
|
1566
1571
|
if (this.isDestroyed) {
|
|
1567
1572
|
this.throwError('this.getSortDirection is no longer valid. Repository has been destroyed.');
|
|
1568
1573
|
return;
|
|
@@ -1578,7 +1583,7 @@ export default class Repository extends EventEmitter {
|
|
|
1578
1583
|
* @param {string} repositoryName - Name of the Repository to retrieve
|
|
1579
1584
|
* @return {boolean} hasProperty
|
|
1580
1585
|
*/
|
|
1581
|
-
getAssociatedRepository
|
|
1586
|
+
getAssociatedRepository(repositoryName) {
|
|
1582
1587
|
if (this.isDestroyed) {
|
|
1583
1588
|
this.throwError('this.getAssociatedRepository is no longer valid. Repository has been destroyed.');
|
|
1584
1589
|
return;
|
|
@@ -1644,14 +1649,14 @@ export default class Repository extends EventEmitter {
|
|
|
1644
1649
|
* Alias for isInRepository
|
|
1645
1650
|
* NOTE: It only searches in memory. Doesn't query server
|
|
1646
1651
|
*/
|
|
1647
|
-
hasId
|
|
1652
|
+
hasId(id) {
|
|
1648
1653
|
return this.isInRepository(id);
|
|
1649
1654
|
}
|
|
1650
1655
|
|
|
1651
1656
|
/**
|
|
1652
1657
|
* Convenience function
|
|
1653
1658
|
*/
|
|
1654
|
-
saveStaged
|
|
1659
|
+
saveStaged() {
|
|
1655
1660
|
return this.save(null, true);
|
|
1656
1661
|
}
|
|
1657
1662
|
|
|
@@ -1665,7 +1670,7 @@ export default class Repository extends EventEmitter {
|
|
|
1665
1670
|
* @param {object} entity - Optional single entity to save (instead of doing a batch operation on everything)
|
|
1666
1671
|
* @param {boolean} useStaged - Save only the staged items, not all
|
|
1667
1672
|
*/
|
|
1668
|
-
|
|
1673
|
+
async save(entity = null, useStaged = false) {
|
|
1669
1674
|
if (this.isDestroyed) {
|
|
1670
1675
|
this.throwError('this.save is no longer valid. Repository has been destroyed.');
|
|
1671
1676
|
return;
|
|
@@ -1900,7 +1905,7 @@ export default class Repository extends EventEmitter {
|
|
|
1900
1905
|
* @return {Promise}
|
|
1901
1906
|
* @private
|
|
1902
1907
|
*/
|
|
1903
|
-
_finalizeSave
|
|
1908
|
+
_finalizeSave(results) {
|
|
1904
1909
|
this.isSaving = false;
|
|
1905
1910
|
this.emit('save');
|
|
1906
1911
|
return results;
|
|
@@ -1913,7 +1918,7 @@ export default class Repository extends EventEmitter {
|
|
|
1913
1918
|
* @param {bool} moveSubtreeUp - whether or not to move the subtree up (if this is a tree)
|
|
1914
1919
|
* @fires delete
|
|
1915
1920
|
*/
|
|
1916
|
-
|
|
1921
|
+
async delete(entities, moveSubtreeUp = false) {
|
|
1917
1922
|
if (this.isDestroyed) {
|
|
1918
1923
|
this.throwError('this.delete is no longer valid. Repository has been destroyed.');
|
|
1919
1924
|
return;
|
|
@@ -1931,13 +1936,14 @@ export default class Repository extends EventEmitter {
|
|
|
1931
1936
|
if (!entities.length) {
|
|
1932
1937
|
return false;
|
|
1933
1938
|
}
|
|
1939
|
+
const oThis = this;
|
|
1934
1940
|
_.each(entities, (entity) => {
|
|
1935
1941
|
if (!entity) {
|
|
1936
1942
|
return;
|
|
1937
1943
|
}
|
|
1938
1944
|
if (entity.isPhantom && !entity.isRemotePhantomMode) {
|
|
1939
1945
|
// Just auto-remove it. Don't bother saving to storage medium.
|
|
1940
|
-
|
|
1946
|
+
oThis.removeEntity(entity);
|
|
1941
1947
|
} else {
|
|
1942
1948
|
entity.markDeleted(); // Entity is still there, it's just marked for deletion
|
|
1943
1949
|
}
|
|
@@ -1971,7 +1977,7 @@ export default class Repository extends EventEmitter {
|
|
|
1971
1977
|
* @param {integer} ix - Index
|
|
1972
1978
|
* @return {object} entity - Entity
|
|
1973
1979
|
*/
|
|
1974
|
-
|
|
1980
|
+
async deleteByIx(ix) {
|
|
1975
1981
|
await this.delete(this.getByIx(ix));
|
|
1976
1982
|
}
|
|
1977
1983
|
|
|
@@ -1982,7 +1988,7 @@ export default class Repository extends EventEmitter {
|
|
|
1982
1988
|
* @param {integer} endIx - Index (inclusive)
|
|
1983
1989
|
* @return {array} entities - Array of Entities
|
|
1984
1990
|
*/
|
|
1985
|
-
|
|
1991
|
+
async deleteByRange(startIx, endIx) {
|
|
1986
1992
|
await this.delete(this.getByRange(startIx, endIx));
|
|
1987
1993
|
}
|
|
1988
1994
|
|
|
@@ -1991,7 +1997,7 @@ export default class Repository extends EventEmitter {
|
|
|
1991
1997
|
* @param {function} fn - Filter function to apply to all entities
|
|
1992
1998
|
* @return {Entity[]} Entities that passed through filter
|
|
1993
1999
|
*/
|
|
1994
|
-
|
|
2000
|
+
async deleteBy(filter) {
|
|
1995
2001
|
await this.delete(this.getBy(filter));
|
|
1996
2002
|
}
|
|
1997
2003
|
|
|
@@ -2000,7 +2006,7 @@ export default class Repository extends EventEmitter {
|
|
|
2000
2006
|
* @param {integer} id - id of record to retrieve
|
|
2001
2007
|
* @return {Entity} The Entity with matching id
|
|
2002
2008
|
*/
|
|
2003
|
-
|
|
2009
|
+
async deleteById(id) {
|
|
2004
2010
|
await this.delete(this.getById(id));
|
|
2005
2011
|
}
|
|
2006
2012
|
|
|
@@ -2010,7 +2016,7 @@ export default class Repository extends EventEmitter {
|
|
|
2010
2016
|
*
|
|
2011
2017
|
* @return {Entity[]} Array of dirty Entities
|
|
2012
2018
|
*/
|
|
2013
|
-
|
|
2019
|
+
async deleteDirty() {
|
|
2014
2020
|
await this.delete(this.getDirty());
|
|
2015
2021
|
}
|
|
2016
2022
|
|
|
@@ -2020,7 +2026,7 @@ export default class Repository extends EventEmitter {
|
|
|
2020
2026
|
*
|
|
2021
2027
|
* @return {Entity[]} Array of phantom Entities
|
|
2022
2028
|
*/
|
|
2023
|
-
|
|
2029
|
+
async deletePhantom() {
|
|
2024
2030
|
await this.delete(this.getPhantom());
|
|
2025
2031
|
}
|
|
2026
2032
|
|
|
@@ -2029,7 +2035,7 @@ export default class Repository extends EventEmitter {
|
|
|
2029
2035
|
* @param {integer} ix - Index
|
|
2030
2036
|
* @return {object} entity - Entity
|
|
2031
2037
|
*/
|
|
2032
|
-
|
|
2038
|
+
async undeleteByIx(ix) {
|
|
2033
2039
|
await this.undelete(this.getByIx(ix));
|
|
2034
2040
|
}
|
|
2035
2041
|
|
|
@@ -2040,7 +2046,7 @@ export default class Repository extends EventEmitter {
|
|
|
2040
2046
|
* @param {integer} endIx - Index (inclusive)
|
|
2041
2047
|
* @return {array} entities - Array of Entities
|
|
2042
2048
|
*/
|
|
2043
|
-
|
|
2049
|
+
async undeleteByRange(startIx, endIx) {
|
|
2044
2050
|
await this.undelete(this.getByRange(startIx, endIx));
|
|
2045
2051
|
}
|
|
2046
2052
|
|
|
@@ -2049,7 +2055,7 @@ export default class Repository extends EventEmitter {
|
|
|
2049
2055
|
* @param {function} fn - Filter function to apply to all entities
|
|
2050
2056
|
* @return {Entity[]} Entities that passed through filter
|
|
2051
2057
|
*/
|
|
2052
|
-
|
|
2058
|
+
async undeleteBy(filter) {
|
|
2053
2059
|
await this.undelete(this.getBy(filter));
|
|
2054
2060
|
}
|
|
2055
2061
|
|
|
@@ -2058,7 +2064,7 @@ export default class Repository extends EventEmitter {
|
|
|
2058
2064
|
* @param {integer} id - id of record to retrieve
|
|
2059
2065
|
* @return {Entity} The Entity with matching id
|
|
2060
2066
|
*/
|
|
2061
|
-
|
|
2067
|
+
async undeleteById(id) {
|
|
2062
2068
|
await this.undelete(this.getById(id));
|
|
2063
2069
|
}
|
|
2064
2070
|
|
|
@@ -2066,7 +2072,7 @@ export default class Repository extends EventEmitter {
|
|
|
2066
2072
|
* Undelete all deleted Entities
|
|
2067
2073
|
* @return {Entity[]} Entities that passed through filter
|
|
2068
2074
|
*/
|
|
2069
|
-
|
|
2075
|
+
async undeleteDeleted() {
|
|
2070
2076
|
await this.undelete(this.getDeleted());
|
|
2071
2077
|
}
|
|
2072
2078
|
|
|
@@ -2081,10 +2087,10 @@ export default class Repository extends EventEmitter {
|
|
|
2081
2087
|
/**
|
|
2082
2088
|
* Gets the root TreeNodes
|
|
2083
2089
|
*/
|
|
2084
|
-
getRootNodes
|
|
2090
|
+
getRootNodes() {
|
|
2085
2091
|
this.ensureTree();
|
|
2086
2092
|
if (this.isDestroyed) {
|
|
2087
|
-
this.throwError('this.
|
|
2093
|
+
this.throwError('this.loadRootNodes is no longer valid. Repository has been destroyed.');
|
|
2088
2094
|
return;
|
|
2089
2095
|
}
|
|
2090
2096
|
|
|
@@ -2100,7 +2106,7 @@ export default class Repository extends EventEmitter {
|
|
|
2100
2106
|
/**
|
|
2101
2107
|
* Populates the TreeNodes with .parent and .children references
|
|
2102
2108
|
*/
|
|
2103
|
-
assembleTreeNodes
|
|
2109
|
+
assembleTreeNodes() {
|
|
2104
2110
|
this.ensureTree();
|
|
2105
2111
|
if (this.isDestroyed) {
|
|
2106
2112
|
this.throwError('this.assembleTreeNodes is no longer valid. Repository has been destroyed.');
|
|
@@ -2116,8 +2122,9 @@ export default class Repository extends EventEmitter {
|
|
|
2116
2122
|
});
|
|
2117
2123
|
|
|
2118
2124
|
// Rebuild all parent/child relationships
|
|
2125
|
+
const oThis = this;
|
|
2119
2126
|
_.each(treeNodes, (treeNode) => {
|
|
2120
|
-
const parent =
|
|
2127
|
+
const parent = oThis.getById(treeNode.parentId);
|
|
2121
2128
|
if (parent) {
|
|
2122
2129
|
treeNode.parent = parent;
|
|
2123
2130
|
parent.children.push(treeNode);
|
|
@@ -2129,14 +2136,15 @@ export default class Repository extends EventEmitter {
|
|
|
2129
2136
|
* Removes the treeNode and all of its children from repository
|
|
2130
2137
|
* without deleting anything on the server
|
|
2131
2138
|
*/
|
|
2132
|
-
removeTreeNode
|
|
2139
|
+
removeTreeNode(treeNode) {
|
|
2133
2140
|
if (!_.isEmpty(treeNode.children)) {
|
|
2134
2141
|
const children = treeNode.children;
|
|
2135
2142
|
treeNode.parent = null;
|
|
2136
2143
|
treeNode.children = [];
|
|
2137
|
-
|
|
2144
|
+
|
|
2145
|
+
const oThis = this;
|
|
2138
2146
|
_.each(children, (child) => {
|
|
2139
|
-
|
|
2147
|
+
oThis.removeTreeNode(child);
|
|
2140
2148
|
});
|
|
2141
2149
|
}
|
|
2142
2150
|
|
|
@@ -2147,7 +2155,7 @@ export default class Repository extends EventEmitter {
|
|
|
2147
2155
|
* Helper to make sure this Repository is a tree
|
|
2148
2156
|
* @private
|
|
2149
2157
|
*/
|
|
2150
|
-
|
|
2158
|
+
async ensureTree() {
|
|
2151
2159
|
if (!this.isTree) {
|
|
2152
2160
|
this.throwError('This Repository is not a tree!');
|
|
2153
2161
|
return false;
|
|
@@ -2170,16 +2178,16 @@ export default class Repository extends EventEmitter {
|
|
|
2170
2178
|
* @param {object} options - config options to set.
|
|
2171
2179
|
* Note: this will overwrite any existing properties on 'this', so *use with caution!*
|
|
2172
2180
|
*/
|
|
2173
|
-
setOptions
|
|
2181
|
+
setOptions(options) {
|
|
2174
2182
|
_.merge(this, options);
|
|
2175
2183
|
}
|
|
2176
2184
|
|
|
2177
|
-
rehash
|
|
2185
|
+
rehash() {
|
|
2178
2186
|
const hashes = _.map(this.entities, (entity) => entity.hash);
|
|
2179
2187
|
this.hash = hash(hashes);
|
|
2180
2188
|
}
|
|
2181
2189
|
|
|
2182
|
-
unmapData
|
|
2190
|
+
unmapData(mappedData) {
|
|
2183
2191
|
const propertiesDef = this.schema?.model?.properties;
|
|
2184
2192
|
if (!propertiesDef) {
|
|
2185
2193
|
throw Error('No properties defined!');
|
|
@@ -2237,7 +2245,7 @@ export default class Repository extends EventEmitter {
|
|
|
2237
2245
|
* Set error handler for this repository
|
|
2238
2246
|
* @param {function} handler - the error handler
|
|
2239
2247
|
*/
|
|
2240
|
-
setErrorHandler
|
|
2248
|
+
setErrorHandler(handler) {
|
|
2241
2249
|
this.errorHandler = handler;
|
|
2242
2250
|
}
|
|
2243
2251
|
|
|
@@ -2252,11 +2260,6 @@ export default class Repository extends EventEmitter {
|
|
|
2252
2260
|
this.errorHandler(obj, data);
|
|
2253
2261
|
} else {
|
|
2254
2262
|
this.emit('error', obj, data);
|
|
2255
|
-
let message = obj;
|
|
2256
|
-
if (data) {
|
|
2257
|
-
message = JSON.stringify({ obj, data });
|
|
2258
|
-
}
|
|
2259
|
-
throw Error(message);
|
|
2260
2263
|
}
|
|
2261
2264
|
}
|
|
2262
2265
|
|
|
@@ -2288,7 +2291,7 @@ export default class Repository extends EventEmitter {
|
|
|
2288
2291
|
* Gets the className of this Repository type.
|
|
2289
2292
|
* @return {string} className
|
|
2290
2293
|
*/
|
|
2291
|
-
getClassName
|
|
2294
|
+
getClassName() {
|
|
2292
2295
|
if (this.isDestroyed) {
|
|
2293
2296
|
this.throwError('this.getClassName is no longer valid. Repository has been destroyed.');
|
|
2294
2297
|
return;
|
|
@@ -2304,7 +2307,7 @@ export default class Repository extends EventEmitter {
|
|
|
2304
2307
|
* Gets the type of this Repository.
|
|
2305
2308
|
* @return {string} className
|
|
2306
2309
|
*/
|
|
2307
|
-
getType
|
|
2310
|
+
getType() {
|
|
2308
2311
|
if (this.isDestroyed) {
|
|
2309
2312
|
this.throwError('this.getClassName is no longer valid. Repository has been destroyed.');
|
|
2310
2313
|
return;
|
|
@@ -2316,7 +2319,7 @@ export default class Repository extends EventEmitter {
|
|
|
2316
2319
|
return this.getType();
|
|
2317
2320
|
}
|
|
2318
2321
|
|
|
2319
|
-
toString
|
|
2322
|
+
toString() {
|
|
2320
2323
|
if (this.isDestroyed) {
|
|
2321
2324
|
this.throwError('this.toString is no longer valid. Repository has been destroyed.');
|
|
2322
2325
|
return;
|