@futdevpro/nts-dynamo 1.9.39 → 1.9.41
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/build/_collections/archive.util.d.ts +3 -0
- package/build/_collections/archive.util.d.ts.map +1 -0
- package/build/_collections/archive.util.js +9 -0
- package/build/_collections/archive.util.js.map +1 -0
- package/build/_collections/global-settings.const.d.ts.map +1 -1
- package/build/_collections/global-settings.const.js +1 -0
- package/build/_collections/global-settings.const.js.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.d.ts +13 -8
- package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +60 -10
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/interfaces/global-settings.interface.d.ts +4 -0
- package/build/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.d.ts.map +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.js +1 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.js.map +1 -1
- package/build/_modules/socket/_models/socket-presence.control-model.js +1 -1
- package/build/_modules/socket/_models/socket-presence.control-model.js.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.d.ts +3 -3
- package/build/_modules/socket/_services/app-extended.server.d.ts.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.js +33 -21
- package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.js +3 -3
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_services/base/archive-data.service.d.ts +24 -0
- package/build/_services/base/archive-data.service.d.ts.map +1 -0
- package/build/_services/base/archive-data.service.js +135 -0
- package/build/_services/base/archive-data.service.js.map +1 -0
- package/build/_services/base/data.service.d.ts +3 -2
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +28 -30
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts +6 -5
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +31 -14
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/base/singleton.service-base.d.ts +1 -1
- package/build/_services/base/singleton.service-base.d.ts.map +1 -1
- package/build/_services/base/singleton.service-base.js +1 -0
- package/build/_services/base/singleton.service-base.js.map +1 -1
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +46 -23
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/route/routing-module.service.d.ts +1 -1
- package/build/_services/route/routing-module.service.d.ts.map +1 -1
- package/build/_services/route/routing-module.service.js +19 -2
- package/build/_services/route/routing-module.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +2 -2
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +18 -10
- package/build/_services/server/app.server.js.map +1 -1
- package/build/index.d.ts +7 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +12 -6
- package/build/index.js.map +1 -1
- package/package.json +3 -3
- package/src/_collections/archive.util.ts +9 -0
- package/src/_collections/global-settings.const.ts +1 -0
- package/src/_models/control-models/endpoint-params.control-model.ts +98 -21
- package/src/_models/interfaces/global-settings.interface.ts +5 -0
- package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +2 -1
- package/src/_modules/socket/_models/socket-presence.control-model.ts +1 -1
- package/src/_modules/socket/_services/app-extended.server.ts +10 -8
- package/src/_modules/socket/_services/socket-server.service.ts +3 -3
- package/src/_services/base/archive-data.service.ts +207 -0
- package/src/_services/base/data.service.ts +50 -45
- package/src/_services/base/db.service.ts +41 -14
- package/src/_services/base/singleton.service-base.ts +2 -1
- package/src/_services/core/global.service.ts +66 -34
- package/src/_services/route/routing-module.service.ts +23 -4
- package/src/_services/server/app.server.ts +42 -29
- package/src/index.ts +16 -6
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
DyFM_Metadata, DyFM_DataModel_Params, DyFM_DataProperty_Params, DyFM_Error,
|
|
4
4
|
DyFM_Log, DyFM_AnyError, DyFM_Error_Settings, DyFM_ErrorLevel
|
|
5
5
|
} from '@futdevpro/fsm-dynamo';
|
|
6
|
+
|
|
6
7
|
import { DyNTS_DBFilter } from '../../_models/types/db-filter.type';
|
|
7
8
|
import { DyNTS_DBUpdate } from '../../_models/types/db-update.type';
|
|
8
|
-
|
|
9
|
-
import { DyNTS_DBService } from './db.service';
|
|
10
|
-
import { DyNTS_GlobalService } from '../core/global.service';
|
|
11
9
|
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
10
|
+
import { DyNTS_GlobalService } from '../core/global.service';
|
|
11
|
+
import { DyNTS_DBService } from './db.service';
|
|
12
12
|
|
|
13
13
|
// TODO: 2 type of archiving service system: within list, or separate db elements
|
|
14
14
|
|
|
@@ -79,12 +79,13 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
79
79
|
} catch (error) {
|
|
80
80
|
throw new DyFM_Error({
|
|
81
81
|
...this._getDefaultErrorSettings('constructor', error),
|
|
82
|
-
message: `The dataService construction failed for "${dataParams?.dataName}". ` +
|
|
83
|
-
`at "${this.serviceName}" (${this.constructor.name})` +
|
|
84
|
-
`\nMaybe you forgot to add the dbService to the GlobalService?\n\n`,
|
|
85
|
-
level: DyFM_ErrorLevel.critical,
|
|
86
82
|
|
|
87
83
|
errorCode: 'NTS-DS0-C00',
|
|
84
|
+
message:
|
|
85
|
+
`The dataService construction failed for "${dataParams?.dataName}". ` +
|
|
86
|
+
`at "${this.serviceName}" (${this.constructor.name})` +
|
|
87
|
+
`\nMaybe you forgot to add the dbService to the GlobalService?`,
|
|
88
|
+
level: DyFM_ErrorLevel.critical,
|
|
88
89
|
});
|
|
89
90
|
/* DyFM_Log.error(
|
|
90
91
|
`\nDyNTS_DataService ERROR: ` +
|
|
@@ -371,7 +372,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
371
372
|
|
|
372
373
|
errorCode: 'NTS-DS0-GLD2',
|
|
373
374
|
additionalContent: {
|
|
374
|
-
data: this.data
|
|
375
|
+
data: this.data,
|
|
375
376
|
},
|
|
376
377
|
});
|
|
377
378
|
}
|
|
@@ -579,24 +580,32 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
579
580
|
* //
|
|
580
581
|
*/
|
|
581
582
|
async updateData(
|
|
582
|
-
set: { filterBy?: DyNTS_DBFilter<T>, update: DyNTS_DBUpdate<T> }
|
|
583
|
+
set: { filterBy?: DyNTS_DBFilter<T>, update: DyNTS_DBUpdate<T> },
|
|
584
|
+
dontUpdateModified?: boolean
|
|
583
585
|
): Promise<void> {
|
|
584
586
|
try {
|
|
585
587
|
if (set.filterBy) {
|
|
586
|
-
await this.dataDBService.updateOne(
|
|
588
|
+
await this.dataDBService.updateOne(
|
|
589
|
+
set.filterBy,
|
|
590
|
+
set.update,
|
|
591
|
+
this.issuer,
|
|
592
|
+
dontUpdateModified
|
|
593
|
+
);
|
|
587
594
|
|
|
588
595
|
} else if (this.data._id) {
|
|
589
596
|
await this.dataDBService.updateOne(
|
|
590
597
|
{ _id: this.data._id } as DyNTS_DBFilter<T>,
|
|
591
598
|
set.update,
|
|
592
|
-
this.issuer
|
|
599
|
+
this.issuer,
|
|
600
|
+
dontUpdateModified
|
|
593
601
|
);
|
|
594
602
|
|
|
595
603
|
} else if (this.depKey && this.data[this.depKey]) {
|
|
596
604
|
await this.dataDBService.updateOne(
|
|
597
605
|
{ [this.depKey]: this.data[this.depKey] } as DyNTS_DBFilter<T>,
|
|
598
606
|
set.update,
|
|
599
|
-
this.issuer
|
|
607
|
+
this.issuer,
|
|
608
|
+
dontUpdateModified
|
|
600
609
|
);
|
|
601
610
|
|
|
602
611
|
} else {
|
|
@@ -629,6 +638,25 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
629
638
|
}
|
|
630
639
|
}
|
|
631
640
|
|
|
641
|
+
protected ensureData(data?: T): T {
|
|
642
|
+
if (!data && this.data) {
|
|
643
|
+
data = this.data;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (!data) {
|
|
647
|
+
throw new DyFM_Error({
|
|
648
|
+
...this._getDefaultErrorSettings(
|
|
649
|
+
'saveData',
|
|
650
|
+
new Error(`no data to save! (${this.dataParams.dataName})`)
|
|
651
|
+
),
|
|
652
|
+
|
|
653
|
+
errorCode: 'NTS-DS0-ED0',
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
return data;
|
|
658
|
+
}
|
|
659
|
+
|
|
632
660
|
/**
|
|
633
661
|
* modifies data if the data have ID and already exists in the DB,
|
|
634
662
|
* creates new if the ID is not present or cant find in DB,
|
|
@@ -640,22 +668,9 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
640
668
|
* (when you simultaneously trying to change the same data's
|
|
641
669
|
* different values from different flows)
|
|
642
670
|
*/
|
|
643
|
-
async saveData(data?: T, dontSetToService?: boolean): Promise<T> {
|
|
671
|
+
async saveData(data?: T, dontSetToService?: boolean, dontUpdateModified?: boolean): Promise<T> {
|
|
644
672
|
try {
|
|
645
|
-
|
|
646
|
-
data = this.data;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (!data) {
|
|
650
|
-
throw new DyFM_Error({
|
|
651
|
-
...this._getDefaultErrorSettings(
|
|
652
|
-
'saveData',
|
|
653
|
-
new Error(`no data to save! (${this.dataParams.dataName})`)
|
|
654
|
-
),
|
|
655
|
-
|
|
656
|
-
errorCode: 'NTS-DS0-SD4',
|
|
657
|
-
});
|
|
658
|
-
}
|
|
673
|
+
data = this.ensureData(data);
|
|
659
674
|
|
|
660
675
|
await this.validateForSave(data);
|
|
661
676
|
|
|
@@ -694,7 +709,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
694
709
|
}
|
|
695
710
|
|
|
696
711
|
// if data exists do modify
|
|
697
|
-
data = await this.dataDBService.modifyData(data, this.issuer);
|
|
712
|
+
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
698
713
|
|
|
699
714
|
if (!dontSetToService) {
|
|
700
715
|
this.data = data;
|
|
@@ -726,7 +741,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
726
741
|
|
|
727
742
|
if (dataExists) {
|
|
728
743
|
// if data exists do modify
|
|
729
|
-
data = await this.dataDBService.modifyData(data, this.issuer);
|
|
744
|
+
data = await this.dataDBService.modifyData(data, this.issuer, dontUpdateModified);
|
|
730
745
|
|
|
731
746
|
if (!dontSetToService) {
|
|
732
747
|
this.data = data;
|
|
@@ -800,8 +815,12 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
800
815
|
errorCode: 'NTS-DS0-DD1',
|
|
801
816
|
});
|
|
802
817
|
}
|
|
803
|
-
|
|
818
|
+
|
|
804
819
|
await this.dataDBService.deleteDataById(id);
|
|
820
|
+
|
|
821
|
+
if (this.data._id === id) {
|
|
822
|
+
delete this.data._id;
|
|
823
|
+
}
|
|
805
824
|
} catch (error) {
|
|
806
825
|
if (error?.errorCode == 'NTS-DS0-DD1') {
|
|
807
826
|
throw error;
|
|
@@ -820,21 +839,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
820
839
|
*/
|
|
821
840
|
async validateForSave(data?: T): Promise<void> {
|
|
822
841
|
try {
|
|
823
|
-
|
|
824
|
-
data = this.data;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
if (!data) {
|
|
828
|
-
throw new DyFM_Error({
|
|
829
|
-
...this._getDefaultErrorSettings(
|
|
830
|
-
'validateForSave',
|
|
831
|
-
new Error(`validateForSave failed, no data provided! (${this.dataParams.dataName})`)
|
|
832
|
-
),
|
|
833
|
-
|
|
834
|
-
status: 522,
|
|
835
|
-
errorCode: 'NTS-DS0-VD4',
|
|
836
|
-
});
|
|
837
|
-
}
|
|
842
|
+
data = this.ensureData(data);
|
|
838
843
|
|
|
839
844
|
for (const element of this.dataParams.properties) {
|
|
840
845
|
// basic required validations
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '@futdevpro/fsm-dynamo';
|
|
9
9
|
import { DyNTS_DBFilter } from '../../_models/types/db-filter.type';
|
|
10
10
|
import { DyNTS_DBUpdate } from '../../_models/types/db-update.type';
|
|
11
|
+
import { DyNTS_archiveSuffix } from '../../_collections/archive.util';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* DB Service for MongoDB
|
|
@@ -125,9 +126,11 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
125
126
|
* @param data data
|
|
126
127
|
* @returns data
|
|
127
128
|
*/
|
|
128
|
-
async modifyData(data: T, issuer: string): Promise<T> {
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
async modifyData(data: T, issuer: string, dontUpdateModified?: boolean): Promise<T> {
|
|
130
|
+
if (!dontUpdateModified) {
|
|
131
|
+
data.__lastModified = new Date();
|
|
132
|
+
data.__lastModifiedBy = issuer;
|
|
133
|
+
}
|
|
131
134
|
|
|
132
135
|
/**
|
|
133
136
|
* EZ A SZAR TELJESEN SZAR, nem friss, nem a db-be mentett adatokat ad vissza,
|
|
@@ -718,9 +721,16 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
718
721
|
* @param update update
|
|
719
722
|
* @returns data
|
|
720
723
|
*/
|
|
721
|
-
async findByIdAndUpdate(
|
|
722
|
-
|
|
723
|
-
update
|
|
724
|
+
async findByIdAndUpdate(
|
|
725
|
+
id: string,
|
|
726
|
+
update: DyNTS_DBUpdate<T>,
|
|
727
|
+
issuer: string,
|
|
728
|
+
dontUpdateModified?: boolean
|
|
729
|
+
): Promise<T> {
|
|
730
|
+
if (!dontUpdateModified) {
|
|
731
|
+
update.__lastModified = new Date();
|
|
732
|
+
update.__lastModifiedBy = issuer;
|
|
733
|
+
}
|
|
724
734
|
|
|
725
735
|
let newData: T = await this.dataModel
|
|
726
736
|
.findByIdAndUpdate(id, update)
|
|
@@ -796,10 +806,13 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
796
806
|
async updateOne(
|
|
797
807
|
filterBy: DyNTS_DBFilter<T>,
|
|
798
808
|
update: DyNTS_DBUpdate<T>,
|
|
799
|
-
issuer: string
|
|
809
|
+
issuer: string,
|
|
810
|
+
dontUpdateModified?: boolean
|
|
800
811
|
): Promise<void> {
|
|
801
|
-
|
|
802
|
-
|
|
812
|
+
if (!dontUpdateModified) {
|
|
813
|
+
update.__lastModified = new Date();
|
|
814
|
+
update.__lastModifiedBy = issuer;
|
|
815
|
+
}
|
|
803
816
|
|
|
804
817
|
await this.dataModel
|
|
805
818
|
.updateOne(filterBy, update)
|
|
@@ -869,10 +882,13 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
869
882
|
async updateMany(
|
|
870
883
|
filterBy: DyNTS_DBFilter<T>,
|
|
871
884
|
update: DyNTS_DBUpdate<T>,
|
|
872
|
-
issuer: string
|
|
885
|
+
issuer: string,
|
|
886
|
+
dontUpdateModified?: boolean
|
|
873
887
|
): Promise<void> {
|
|
874
|
-
|
|
875
|
-
|
|
888
|
+
if (!dontUpdateModified) {
|
|
889
|
+
update.__lastModified = new Date();
|
|
890
|
+
update.__lastModifiedBy = issuer;
|
|
891
|
+
}
|
|
876
892
|
|
|
877
893
|
await this.dataModel
|
|
878
894
|
.updateMany(filterBy, update)
|
|
@@ -939,7 +955,11 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
939
955
|
private getSchema(): mongoose.Schema {
|
|
940
956
|
let schema: any = this.buildMongooseSchemaByModelParams();
|
|
941
957
|
|
|
942
|
-
schema = this.
|
|
958
|
+
schema = this.addMetadataToSchema(schema);
|
|
959
|
+
|
|
960
|
+
if (this.dataParams.dataName.includes(DyNTS_archiveSuffix)) {
|
|
961
|
+
schema = this.addArchiveMetadataToSchema(schema);
|
|
962
|
+
}
|
|
943
963
|
|
|
944
964
|
// tslint:disable-next-line: no-string-literal
|
|
945
965
|
if (schema['_id']) {
|
|
@@ -1039,7 +1059,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
1039
1059
|
* @param schema schema to update
|
|
1040
1060
|
* @returns updated schema
|
|
1041
1061
|
*/
|
|
1042
|
-
private
|
|
1062
|
+
private addMetadataToSchema(schema: any): any {
|
|
1043
1063
|
schema.__created = { type: Date };
|
|
1044
1064
|
schema.__createdBy = { type: String };
|
|
1045
1065
|
schema.__lastModified = { type: Date };
|
|
@@ -1048,6 +1068,13 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
1048
1068
|
return schema;
|
|
1049
1069
|
}
|
|
1050
1070
|
|
|
1071
|
+
private addArchiveMetadataToSchema(schema: any): any {
|
|
1072
|
+
schema._originalId = { type: String, required: true, index: true, unique: true };
|
|
1073
|
+
schema._archived = { type: Date, required: true };
|
|
1074
|
+
|
|
1075
|
+
return schema;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1051
1078
|
/**
|
|
1052
1079
|
* sets depDataKey
|
|
1053
1080
|
*/
|
|
@@ -10,7 +10,8 @@ export class DyNTS_SingletonServiceBase {
|
|
|
10
10
|
/// --- --- --- SINGLETON --- --- --- \\\
|
|
11
11
|
protected static instance;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
14
|
+
protected static getSingletonInstance() {
|
|
14
15
|
if (!this.instance) {
|
|
15
16
|
this.instance = new this();
|
|
16
17
|
}
|
|
@@ -23,6 +23,8 @@ import { DyNTS_Service_Collection } from './service-collection.service';
|
|
|
23
23
|
/* import { DyNTS_EmailServiceCollection } from './email-service-collection.service'; */
|
|
24
24
|
import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
25
25
|
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
26
|
+
/* import { DyNTS_archiveFlag } from '../../_collections/archive-flag.const'; */
|
|
27
|
+
import { DyNTS_getArchivedDBName } from '../../_collections/archive.util';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* This is the main Global/Core Service Collection used by DynamoBE,
|
|
@@ -84,6 +86,34 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
84
86
|
private static async setDBServices(dbModels?: DyFM_DataModel_Params[]): Promise<void> {
|
|
85
87
|
try {
|
|
86
88
|
this.instance.dbServiceCollection = {};
|
|
89
|
+
|
|
90
|
+
dbModels?.forEach((dbModel: DyFM_DataModel_Params): void => {
|
|
91
|
+
if (!dbModel) {
|
|
92
|
+
throw new DyFM_Error({
|
|
93
|
+
...this.getDefaultErrorSettings(
|
|
94
|
+
'setDBServices',
|
|
95
|
+
new Error(`given dbModel is empty!`),
|
|
96
|
+
'DyNTS_GlobalService'
|
|
97
|
+
),
|
|
98
|
+
|
|
99
|
+
errorCode: 'NTS-GS0-SDBS2',
|
|
100
|
+
additionalContent: {
|
|
101
|
+
dbModels: dbModels,
|
|
102
|
+
dbModelNames: dbModels.map((dbModel: DyFM_DataModel_Params) => dbModel.dataName),
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (dbModel.addArchive) {
|
|
108
|
+
const archiveModel: DyFM_DataModel_Params = new DyFM_DataModel_Params({
|
|
109
|
+
...dbModel,
|
|
110
|
+
dataName: DyNTS_getArchivedDBName(dbModel.dataName),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
dbModels.push(archiveModel);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
87
117
|
dbModels?.forEach((dbModel: DyFM_DataModel_Params): void => {
|
|
88
118
|
if (!dbModel.constructed) {
|
|
89
119
|
throw new DyFM_Error({
|
|
@@ -164,35 +194,39 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
164
194
|
|
|
165
195
|
private static async setErrorHandler(errorHandler?: DyNTS_GlobalErrorHandlerFn): Promise<void> {
|
|
166
196
|
try {
|
|
167
|
-
DyNTS_GlobalService.globalErrorHandler =
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
197
|
+
DyNTS_GlobalService.globalErrorHandler = (async (error: any): Promise<void> => {
|
|
198
|
+
try {
|
|
199
|
+
if (errorHandler) {
|
|
200
|
+
await errorHandler(error);
|
|
201
|
+
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
DyFM_Log.warn(
|
|
206
|
+
`globalErrorHandler not set! (set in app.getGlobalServiceCollection)`,
|
|
207
|
+
'\nwill use default-logging',
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
DyNTS_global_settings.log_settings.highDetailedLogs ||
|
|
212
|
+
!(error instanceof DyFM_Error)
|
|
213
|
+
) {
|
|
214
|
+
DyFM_Log.H_error(
|
|
215
|
+
`Error caught by globalErrorHandler.`,
|
|
216
|
+
`\n ERROR:`, error?.replaceAll?.('at', ' at') ?? error
|
|
174
217
|
);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
!(error instanceof DyFM_Error)
|
|
179
|
-
) {
|
|
180
|
-
DyFM_Log.H_error(
|
|
181
|
-
`Error caught by globalErrorHandler.`,
|
|
182
|
-
`\n ERROR:`, error?.replaceAll?.('at', ' at') ?? error
|
|
183
|
-
);
|
|
184
|
-
} else /* if (!error.___logged) */ {
|
|
185
|
-
error.logSimple(
|
|
186
|
-
`Error caught by globalErrorHandler.`
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
} catch (error) {
|
|
190
|
-
DyFM_Log.error(
|
|
191
|
-
`NTS GLOBAL MULTILEVEL ERROR: \nFailed to handle error on globalErrorHandler.`,
|
|
192
|
-
error
|
|
218
|
+
} else /* if (!error.___logged) */ {
|
|
219
|
+
error.logSimple(
|
|
220
|
+
`Error caught by globalErrorHandler.`
|
|
193
221
|
);
|
|
194
222
|
}
|
|
195
|
-
})
|
|
223
|
+
} catch (error) {
|
|
224
|
+
DyFM_Log.error(
|
|
225
|
+
`NTS GLOBAL MULTILEVEL ERROR: \nFailed to handle error on globalErrorHandler.`,
|
|
226
|
+
error
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
196
230
|
} catch (error) {
|
|
197
231
|
throw new DyFM_Error({
|
|
198
232
|
...this.getDefaultErrorSettings('setErrorHandler', error, 'DyNTS_GlobalService'),
|
|
@@ -261,15 +295,11 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
261
295
|
if (collection[key]) {
|
|
262
296
|
return collection[key] as DyNTS_DBService<T>;
|
|
263
297
|
} else {
|
|
264
|
-
let keys: string = `${Object.keys(collection)}`;
|
|
265
|
-
|
|
266
|
-
keys = keys.replace(/,/g, '\n ');
|
|
267
|
-
|
|
268
298
|
throw new Error(
|
|
269
299
|
`\n DyNTS_GlobalService.getDBService failed, ERROR: ` +
|
|
270
|
-
`\n no dbService on collection with this key: ${key}!` +
|
|
300
|
+
`\n no dbService on collection with this key: "${key}"!` +
|
|
271
301
|
`\n The available dbServices on collection:` +
|
|
272
|
-
`\n ${keys}\n`
|
|
302
|
+
`\n ${Object.keys(collection).join(', ')}\n`
|
|
273
303
|
);
|
|
274
304
|
}
|
|
275
305
|
}
|
|
@@ -279,12 +309,14 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
279
309
|
* @returns
|
|
280
310
|
*/
|
|
281
311
|
static getEmailServiceCollection(): DyNTS_Service_Collection<DyNTS_EmailService> {
|
|
282
|
-
if (!this.instance
|
|
312
|
+
if (!this.instance.emailServiceCollection) {
|
|
283
313
|
throw new Error(
|
|
284
314
|
`\n Unique Email Service Collection missing!` +
|
|
285
315
|
`\n Please create a Unique Email Service Collection extending ` +
|
|
286
316
|
`DynamoBEEmailServiceCollection, ` +
|
|
287
|
-
`\n and Setup with DyNTS_GlobalServiceC.setServices(...)\n`
|
|
317
|
+
`\n and Setup with DyNTS_GlobalServiceC.setServices(...)\n` +
|
|
318
|
+
`\n available emailServiceCollection: ` +
|
|
319
|
+
`${Object().keys(this.instance.emailServiceCollection).join(', ')}\n`
|
|
288
320
|
);
|
|
289
321
|
}
|
|
290
322
|
|
|
@@ -65,7 +65,7 @@ export class DyNTS_RoutingModule {
|
|
|
65
65
|
security: DyNTS_RouteSecurity;
|
|
66
66
|
route: string;
|
|
67
67
|
|
|
68
|
-
private controllers: DyNTS_Controller[];
|
|
68
|
+
private readonly controllers: DyNTS_Controller[];
|
|
69
69
|
endpoints: DyNTS_Endpoint_Params[] = [];
|
|
70
70
|
|
|
71
71
|
openRouter: Router = Router();
|
|
@@ -93,13 +93,29 @@ export class DyNTS_RoutingModule {
|
|
|
93
93
|
`routing module setup done: ${this.route} security: ${this.security}\n`
|
|
94
94
|
);
|
|
95
95
|
} catch (error) {
|
|
96
|
+
/* if (
|
|
97
|
+
DyNTS_global_settings.log_settings.highDetailedLogs ||
|
|
98
|
+
!(error instanceof DyFM_Error)
|
|
99
|
+
) {
|
|
100
|
+
DyFM_Log.H_error(
|
|
101
|
+
`Routing module setup failed (${this.route}).`,
|
|
102
|
+
`\n ERROR:`, error
|
|
103
|
+
);
|
|
104
|
+
} else {
|
|
105
|
+
error.logSimple(
|
|
106
|
+
`Routing module setup failed (${this.route}).` +
|
|
107
|
+
'\nmessages:\n' + error._messages.join(' \n')
|
|
108
|
+
);
|
|
109
|
+
} */
|
|
110
|
+
|
|
96
111
|
/* DyFM_Log.error(`\nRouting module setup failed (${this.route})`, error); */
|
|
97
112
|
throw new DyFM_Error({
|
|
98
113
|
...this.getDefaultErrorSettings(
|
|
99
|
-
'constructor',
|
|
100
|
-
|
|
114
|
+
'DyNTS_RoutingModule.constructor',
|
|
115
|
+
error
|
|
101
116
|
),
|
|
102
117
|
|
|
118
|
+
message: `Routing module setup failed (${this.route}).`,
|
|
103
119
|
errorCode: 'NTS-RMS-000',
|
|
104
120
|
additionalContent: set,
|
|
105
121
|
});
|
|
@@ -117,9 +133,12 @@ export class DyNTS_RoutingModule {
|
|
|
117
133
|
throw new DyFM_Error({
|
|
118
134
|
...this.getDefaultErrorSettings(
|
|
119
135
|
'setupRoutes',
|
|
120
|
-
|
|
136
|
+
error
|
|
121
137
|
),
|
|
122
138
|
|
|
139
|
+
message:
|
|
140
|
+
`DyNTS_Controller setup failed. (${controller?.constructor?.name}) ` +
|
|
141
|
+
`Please check the setupEndpoints() method.`,
|
|
123
142
|
errorCode: 'NTS-RMS-SR1',
|
|
124
143
|
level: DyFM_ErrorLevel.critical,
|
|
125
144
|
});
|
|
@@ -268,37 +268,50 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
268
268
|
}
|
|
269
269
|
debugLog: boolean = DyNTS_global_settings.log_settings.server_debug;
|
|
270
270
|
|
|
271
|
-
constructor(extended?: boolean){
|
|
271
|
+
constructor(/* extended?: boolean */){
|
|
272
272
|
super();
|
|
273
273
|
|
|
274
|
-
process.on(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
DyNTS_GlobalService.globalErrorHandler?.(
|
|
284
|
-
new DyFM_Error({
|
|
285
|
-
errorCode: 'NTS-AS0-BASE-UR',
|
|
286
|
-
message: 'Unhandled Rejection!',
|
|
287
|
-
error: new Error(p_passWhatIsThis),
|
|
288
|
-
additionalContent: {
|
|
289
|
-
reason: reason,
|
|
290
|
-
p_noIdeaWhatIsThisFromProcessRejection: p_passWhatIsThis,
|
|
291
|
-
},
|
|
292
|
-
level: DyFM_ErrorLevel.critical,
|
|
293
|
-
})
|
|
274
|
+
process.on(
|
|
275
|
+
'unhandledRejection',
|
|
276
|
+
(reason_theError: object, p_passWhatIsThis_maybeThePromise: any): void => {
|
|
277
|
+
DyFM_Log.H_error(
|
|
278
|
+
'Unhandled Rejection:', (p_passWhatIsThis_maybeThePromise as Promise<any>)?.toString(),
|
|
279
|
+
'\n Rejection reason:', (reason_theError as Error)?.stack?.split('at')?.[0],
|
|
280
|
+
/* '\n ErrorCode:', (reason as any)?.code, */
|
|
281
|
+
'\n\n Stack:',
|
|
282
|
+
(reason_theError as Error)?.stack?.replaceAll?.('\n at', '\n at'),
|
|
294
283
|
);
|
|
295
284
|
|
|
296
|
-
|
|
297
|
-
|
|
285
|
+
try {
|
|
286
|
+
DyNTS_GlobalService.globalErrorHandler?.(
|
|
287
|
+
new DyFM_Error({
|
|
288
|
+
errorCode: 'NTS-AS0-BASE-UR',
|
|
289
|
+
message:
|
|
290
|
+
`Unhandled Rejection!: "${(reason_theError as Error)?.stack?.split('at')?.[0]}"`,
|
|
291
|
+
userMessage: this.defaultErrorUserMsg,
|
|
292
|
+
addECToUserMsg: true,
|
|
293
|
+
error: reason_theError as Error,
|
|
294
|
+
additionalContent: {
|
|
295
|
+
reason: reason_theError,
|
|
296
|
+
rejectedPromise: p_passWhatIsThis_maybeThePromise,
|
|
297
|
+
},
|
|
298
|
+
level: DyFM_ErrorLevel.critical,
|
|
299
|
+
})
|
|
300
|
+
);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
DyFM_Log.error('globalErrorHandler (MULTILEVEL) ERROR:', error);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
this.asyncConstruct(/* extended */).catch((error: any): void => {
|
|
308
|
+
if (error instanceof DyFM_Error) {
|
|
309
|
+
DyFM_Log.H_warn(
|
|
310
|
+
'(constructor asyncConstruct.catch) additional error content:\n',
|
|
311
|
+
error?.additionalContent
|
|
312
|
+
);
|
|
298
313
|
}
|
|
299
|
-
});
|
|
300
314
|
|
|
301
|
-
this.asyncConstruct(extended).catch((error: any): void => {
|
|
302
315
|
if (
|
|
303
316
|
DyNTS_global_settings.log_settings.highDetailedLogs ||
|
|
304
317
|
!(error instanceof DyFM_Error)
|
|
@@ -309,15 +322,15 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
309
322
|
);
|
|
310
323
|
} else {
|
|
311
324
|
error.logSimple(
|
|
312
|
-
`Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`
|
|
325
|
+
`Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)` +
|
|
326
|
+
'\n all error messages (from this stack):\n\n"' +
|
|
327
|
+
error._messages.join('"\n\n"') + '"\n\n'
|
|
313
328
|
);
|
|
314
329
|
}
|
|
315
|
-
|
|
316
|
-
DyFM_Log.H_warn('T1000\n', error?.additionalContent);
|
|
317
330
|
});
|
|
318
331
|
}
|
|
319
332
|
|
|
320
|
-
|
|
333
|
+
protected async asyncConstruct(extended?: boolean): Promise<void> {
|
|
321
334
|
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. asyncConstruct');
|
|
322
335
|
|
|
323
336
|
try {
|
package/src/index.ts
CHANGED
|
@@ -33,19 +33,29 @@ export * from './_models/types/db-update.type';
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
// SERVICES
|
|
36
|
+
// services/CORE
|
|
36
37
|
export * from './_services/core/api.service';
|
|
37
|
-
export * from './_services/server/app.server';
|
|
38
38
|
export * from './_services/core/auth.service';
|
|
39
|
-
export * from './_services/route/controller.service';
|
|
40
|
-
export * from './_services/base/data.service';
|
|
41
|
-
export * from './_services/base/db.service';
|
|
42
39
|
export * from './_services/core/email.service';
|
|
43
40
|
export * from './_services/core/global.service';
|
|
41
|
+
export * from './_services/core/service-collection.service';
|
|
42
|
+
|
|
43
|
+
// services/BASE
|
|
44
|
+
export * from './_services/base/archive-data.service';
|
|
45
|
+
export * from './_services/base/data.service';
|
|
46
|
+
export * from './_services/base/db.service';
|
|
47
|
+
export * from './_services/base/singleton.service';
|
|
48
|
+
|
|
49
|
+
// services/SERVER
|
|
50
|
+
export * from './_services/server/app.server';
|
|
51
|
+
|
|
52
|
+
// services/ROUTE
|
|
53
|
+
export * from './_services/route/controller.service';
|
|
44
54
|
export * from './_services/route/controller.service';
|
|
45
55
|
export * from './_services/route/routing-module.service';
|
|
46
|
-
|
|
56
|
+
|
|
57
|
+
// services/SHARED
|
|
47
58
|
export * from './_services/shared.static-service';
|
|
48
|
-
export * from './_services/base/singleton.service';
|
|
49
59
|
|
|
50
60
|
|
|
51
61
|
|