@my-devkit/firebase 1.0.194 → 1.0.196
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/.eslintrc.js +3 -3
- package/dist/app-factory.js +9 -9
- package/dist/app-factory.js.map +1 -1
- package/dist/bus.js +1 -4
- package/dist/bus.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/context.js +1 -1
- package/dist/decorators/controller/body.js.map +1 -1
- package/dist/decorators/controller/body.spec.js.map +1 -1
- package/dist/decorators/controller/controller.js +1 -1
- package/dist/decorators/controller/controller.js.map +1 -1
- package/dist/decorators/controller/get.js +1 -1
- package/dist/decorators/controller/param.js.map +1 -1
- package/dist/decorators/controller/param.spec.js.map +1 -1
- package/dist/decorators/controller/post.js +1 -1
- package/dist/decorators/controller/query.js.map +1 -1
- package/dist/decorators/controller/query.spec.js.map +1 -1
- package/dist/decorators/handler/command-handler.js.map +1 -1
- package/dist/decorators/handler/command-handler.spec.js.map +1 -1
- package/dist/decorators/handler/event-handler.js.map +1 -1
- package/dist/decorators/handler/event-handler.spec.js.map +1 -1
- package/dist/decorators/injectable.js +1 -1
- package/dist/decorators/injectable.js.map +1 -1
- package/dist/decorators/module.js +1 -1
- package/dist/decorators/module.js.map +1 -1
- package/dist/decorators/transactional-client.js +1 -1
- package/dist/decorators/transactional-client.js.map +1 -1
- package/dist/firestore-client.js +10 -10
- package/dist/firestore-client.js.map +1 -1
- package/dist/handler-helper.js.map +1 -1
- package/dist/injector.js +1 -1
- package/dist/injector.js.map +1 -1
- package/dist/reflect.js +7 -7
- package/dist/reflect.js.map +1 -1
- package/dist/sanity-check/module.js +1 -1
- package/dist/server/middlewares/authentication-middleware.js +1 -3
- package/dist/server/middlewares/authentication-middleware.js.map +1 -1
- package/dist/server/middlewares/create-context-middleware.js.map +1 -1
- package/dist/server/middlewares/error-middleware.js.map +1 -1
- package/dist/server/middlewares/headers-middleware.js.map +1 -1
- package/dist/server/server.js.map +1 -1
- package/package.json +4 -4
- package/src/app-factory.ts +31 -69
- package/src/bus.ts +5 -22
- package/src/constants.ts +1 -1
- package/src/context.ts +1 -1
- package/src/decorators/controller/body.spec.ts +3 -9
- package/src/decorators/controller/body.ts +3 -9
- package/src/decorators/controller/controller.ts +1 -1
- package/src/decorators/controller/get.ts +1 -1
- package/src/decorators/controller/param.spec.ts +5 -14
- package/src/decorators/controller/param.ts +2 -7
- package/src/decorators/controller/post.ts +1 -1
- package/src/decorators/controller/query.spec.ts +4 -10
- package/src/decorators/controller/query.ts +2 -7
- package/src/decorators/handler/command-handler.spec.ts +2 -6
- package/src/decorators/handler/command-handler.ts +3 -9
- package/src/decorators/handler/event-handler.spec.ts +2 -6
- package/src/decorators/handler/event-handler.ts +3 -9
- package/src/decorators/injectable.ts +1 -1
- package/src/decorators/module.ts +1 -1
- package/src/decorators/transactional-client.ts +1 -1
- package/src/execution-mode-enum.ts +1 -1
- package/src/firestore-client.ts +32 -79
- package/src/handler-helper.ts +5 -18
- package/src/injector.ts +1 -1
- package/src/interfaces/from-array.ts +1 -2
- package/src/reflect.ts +11 -20
- package/src/request-method.enum.ts +1 -1
- package/src/sanity-check/module.ts +1 -1
- package/src/server/middlewares/authentication-middleware.ts +4 -14
- package/src/server/middlewares/create-context-middleware.ts +1 -5
- package/src/server/middlewares/error-middleware.ts +1 -5
- package/src/server/middlewares/headers-middleware.ts +1 -5
- package/src/server/server.ts +10 -32
package/dist/reflect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.js","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reflect.js","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":";;AA+JA,0BAEC;AAjKD,4BAA0B;AAE1B,0CAAuD;AAOvD,MAAM,aAAa;IAMf,YACY,MAAS,EACT,UAA2B;QAD3B,WAAM,GAAN,MAAM,CAAG;QACT,eAAU,GAAV,UAAU,CAAiB;QA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
|
@@ -14,7 +14,7 @@ let SanityCheckModule = class SanityCheckModule {
|
|
|
14
14
|
exports.SanityCheckModule = SanityCheckModule;
|
|
15
15
|
exports.SanityCheckModule = SanityCheckModule = __decorate([
|
|
16
16
|
(0, decorators_1.Module)({
|
|
17
|
-
controllers: [controller_1.SanityCheckController]
|
|
17
|
+
controllers: [controller_1.SanityCheckController],
|
|
18
18
|
})
|
|
19
19
|
], SanityCheckModule);
|
|
20
20
|
//# sourceMappingURL=module.js.map
|
|
@@ -14,9 +14,7 @@ const core_1 = require("@my-devkit/core");
|
|
|
14
14
|
const context_1 = require("../../context");
|
|
15
15
|
function AuthenticationMiddleware(auth, publicPaths) {
|
|
16
16
|
return (request, _response, next) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const authorizationHeader = request.headers.authorization
|
|
18
|
-
? request.headers.authorization.toString()
|
|
19
|
-
: null;
|
|
17
|
+
const authorizationHeader = request.headers.authorization ? request.headers.authorization.toString() : null;
|
|
20
18
|
core_1.Logger.info(`${request.method} ${request.path}: Authentication check`);
|
|
21
19
|
if (publicPaths.includes(request.path)) {
|
|
22
20
|
core_1.Logger.info(`${request.path} is a public path, no authorization check`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/authentication-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,
|
|
1
|
+
{"version":3,"file":"authentication-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/authentication-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,4DAuCC;AA7CD,0CAA4D;AAG5D,2CAAwC;AAGxC,SAAgB,wBAAwB,CAAC,IAAU,EAAE,WAAqB;IACtE,OAAO,CAAO,OAAuB,EAAE,SAA0B,EAAE,IAAyB,EAAiB,EAAE;QAC3G,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC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,CAAC,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,IAAI,CAAC;gBACD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAChF,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;oBAC9B,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBACxC,CAAC;gBACD,iBAAO,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAC1C,IAAI,EAAE,CAAC;YACX,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,MAAM,IAAI,wBAAiB,CAAC,+BAA+B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACvG,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,wBAAiB,CAAC,gCAAgC,CAAC,CAAC;QAClE,CAAC;IACL,CAAC,CAAA,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-context-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/create-context-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,
|
|
1
|
+
{"version":3,"file":"create-context-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/create-context-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,0DASC;AAfD,0CAA+C;AAG/C,2CAAwC;AAGxC,SAAgB,uBAAuB,CAAC,GAAQ;IAC5C,OAAO,CAAO,OAAuB,EAAE,SAA0B,EAAE,IAAyB,EAAiB,EAAE;QAC3G,iBAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,iBAAO,CAAC,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,IAAA,WAAI,GAAE,CAAC;QAErE,aAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,mBAAmB,CAAC,CAAC;QAElE,IAAI,EAAE,CAAC;IACX,CAAC,CAAA,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/error-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAKA,
|
|
1
|
+
{"version":3,"file":"error-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/error-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAKA,0CA2BC;AAhCD,0CAAyC;AAEzC,2CAAwC;AACxC,sCAAmC;AAEnC,SAAgB,eAAe;IAC3B,OAAO,CAAO,KAAU,EAAE,QAAwB,EAAE,QAAyB,EAAiB,EAAE;QAC5F,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;YAC5B,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;QAED,IAAI,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,qBAAqB,CAAC;QACtD,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACrC,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,YAAY,CAAC;QAC7C,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;YAC1C,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,WAAW,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACtC,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,WAAW,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACzC,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,SAAS,CAAC;QAC1C,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACzC,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,eAAe,CAAC;QAChD,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YACxC,MAAM,GAAG,eAAM,CAAC,WAAW,CAAC,SAAS,CAAC;QAC1C,CAAC;QAED,aAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAEhD,iBAAO,CAAC,OAAO,EAAE,CAAC;QAElB,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAA,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/headers-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,
|
|
1
|
+
{"version":3,"file":"headers-middleware.js","sourceRoot":"","sources":["../../../src/server/middlewares/headers-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,8CAYC;AAfD,2CAAwC;AAGxC,SAAgB,iBAAiB;IAC7B,OAAO,CAAO,QAAwB,EAAE,QAAyB,EAAE,IAAyB,EAAiB,EAAE;QAC3G,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,yBAAyB;QAChE,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,qCAAqC,CAAC,CAAC,CAAC,YAAY;QACxF,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,YAAY;QACtD,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,WAAW;QAC/C,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC,CAAC,wBAAwB;QAChF,QAAQ,CAAC,SAAS,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;QAC/D,QAAQ,CAAC,SAAS,CAAC,kBAAkB,EAAE,iBAAO,CAAC,aAAa,CAAC,CAAC;QAE9D,IAAI,EAAE,CAAC;IACX,CAAC,CAAA,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAE9B,yDAAgD;AAGhD,gEAAuD;AACvD,2DAA6C;AAE7C,SAAS,WAAW,CAAC,OAA8B;IAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,sDAA8B;AAE9B,yDAAgD;AAGhD,gEAAuD;AACvD,2DAA6C;AAE7C,SAAS,WAAW,CAAC,OAA8B;IAC/C,OAAO,CAAO,OAAuB,EAAE,QAAyB,EAAE,IAAyB,EAAiB,EAAE;QAC1G,IAAI,CAAC;YACD,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACL,CAAC,CAAA,CAAC;AACN,CAAC;AAED,MAAa,MAAM;IAIf,YAAY,OAAuB;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAA,iBAAO,GAAE,CAAC;QACtB,IAAI,CAAC,sBAAsB,CAA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C5C,WAAiB,MAAM;IAQnB,MAAa,MAAM;QAEf;YACI,IAAI,CAAC,MAAM,GAAG,iBAAO,CAAC,MAAM,EAAE,CAAC;QACnC,CAAC;QAEM,aAAa,CAAC,MAAqB,EAAE,IAAY,EAAE,OAAuB;YAC7E,QAAQ,MAAM,EAAE,CAAC;gBACb,KAAK,mCAAa,CAAC,GAAG;oBAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC5C,MAAM;gBACV,KAAK,mCAAa,CAAC,IAAI;oBACnB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC7C,MAAM;gBACV;oBACI,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,wBAAwB,CAAC,CAAC;YACxF,CAAC;QACL,CAAC;QAEM,gBAAgB,CAAC,IAAY,EAAE,MAAc;YAChD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;KACJ;IAtBY,aAAM,SAsBlB,CAAA;AAOL,CAAC,EArCgB,MAAM,sBAAN,MAAM,QAqCtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@my-devkit/firebase",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.196",
|
|
4
4
|
"description": "My Devkit: firebase tools for CQRS implementation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"reflect-metadata": "0.2.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@my-devkit/core": "1.0.
|
|
26
|
+
"@my-devkit/core": "1.0.124",
|
|
27
27
|
"firebase-admin": "13.5.0",
|
|
28
28
|
"firebase-functions": "6.6.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@my-devkit/cli": "2.1.
|
|
32
|
-
"@my-devkit/core": "1.0.
|
|
31
|
+
"@my-devkit/cli": "2.1.9",
|
|
32
|
+
"@my-devkit/core": "1.0.124",
|
|
33
33
|
"@types/cors": "2.8.19",
|
|
34
34
|
"@types/express": "4.17.21",
|
|
35
35
|
"@types/mocha": "10.0.10",
|
package/src/app-factory.ts
CHANGED
|
@@ -28,9 +28,7 @@ export class AppFactory {
|
|
|
28
28
|
|
|
29
29
|
public static isActive(name: string): boolean {
|
|
30
30
|
const functionName = process.env.FUNCTION_NAME || process.env.K_SERVICE;
|
|
31
|
-
return (
|
|
32
|
-
this.isEmulator || !functionName || functionName.toLowerCase() === name.toLowerCase()
|
|
33
|
-
);
|
|
31
|
+
return this.isEmulator || !functionName || functionName.toLowerCase() === name.toLowerCase();
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
public static initializeApp(options: AppFactory.Options): void {
|
|
@@ -64,7 +62,7 @@ export class AppFactory {
|
|
|
64
62
|
bus,
|
|
65
63
|
firebaseAuth: this.auth,
|
|
66
64
|
firestore: this.firestore,
|
|
67
|
-
publicPaths: this.publicPaths
|
|
65
|
+
publicPaths: this.publicPaths,
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
this.registerControllers(server, module);
|
|
@@ -77,9 +75,9 @@ export class AppFactory {
|
|
|
77
75
|
{
|
|
78
76
|
memory: this.options.memory,
|
|
79
77
|
timeoutSeconds: this.options.timeoutSeconds,
|
|
80
|
-
region: this.options.region
|
|
78
|
+
region: this.options.region,
|
|
81
79
|
},
|
|
82
|
-
server.app
|
|
80
|
+
server.app,
|
|
83
81
|
);
|
|
84
82
|
}
|
|
85
83
|
|
|
@@ -92,9 +90,9 @@ export class AppFactory {
|
|
|
92
90
|
{
|
|
93
91
|
secrets: [this.apiKey],
|
|
94
92
|
region: this.options.region,
|
|
95
|
-
cors: this.options.cors
|
|
93
|
+
cors: this.options.cors,
|
|
96
94
|
},
|
|
97
|
-
flow
|
|
95
|
+
flow,
|
|
98
96
|
);
|
|
99
97
|
}
|
|
100
98
|
|
|
@@ -103,7 +101,7 @@ export class AppFactory {
|
|
|
103
101
|
module: Type,
|
|
104
102
|
schedule: string,
|
|
105
103
|
timeZone: string,
|
|
106
|
-
commandType: new () => C
|
|
104
|
+
commandType: new () => C,
|
|
107
105
|
) {
|
|
108
106
|
if (!this.isActive(name)) return null;
|
|
109
107
|
|
|
@@ -121,17 +119,13 @@ export class AppFactory {
|
|
|
121
119
|
timeZone,
|
|
122
120
|
memory: this.options.memory,
|
|
123
121
|
timeoutSeconds: this.options.timeoutSeconds,
|
|
124
|
-
region: this.options.region
|
|
122
|
+
region: this.options.region,
|
|
125
123
|
},
|
|
126
|
-
this.getFunctionCommandHandler(bus, commandType)
|
|
124
|
+
this.getFunctionCommandHandler(bus, commandType),
|
|
127
125
|
);
|
|
128
126
|
}
|
|
129
127
|
|
|
130
|
-
public static createEventListener(
|
|
131
|
-
name: string,
|
|
132
|
-
module: Type,
|
|
133
|
-
mode: ExecutionMode = ExecutionMode.Asynchronous
|
|
134
|
-
) {
|
|
128
|
+
public static createEventListener(name: string, module: Type, mode: ExecutionMode = ExecutionMode.Asynchronous) {
|
|
135
129
|
if (!this.isActive(name)) return null;
|
|
136
130
|
|
|
137
131
|
Logger.info(`Cold start Event Listener ${mode}`);
|
|
@@ -147,9 +141,9 @@ export class AppFactory {
|
|
|
147
141
|
document: 'events/{eventId}',
|
|
148
142
|
memory: this.options.memory,
|
|
149
143
|
timeoutSeconds: this.options.timeoutSeconds,
|
|
150
|
-
region: this.options.region
|
|
144
|
+
region: this.options.region,
|
|
151
145
|
},
|
|
152
|
-
this.getFunctionEventHandler(bus, ExecutionMode.Asynchronous)
|
|
146
|
+
this.getFunctionEventHandler(bus, ExecutionMode.Asynchronous),
|
|
153
147
|
);
|
|
154
148
|
}
|
|
155
149
|
|
|
@@ -181,18 +175,16 @@ export class AppFactory {
|
|
|
181
175
|
route.requestMethod,
|
|
182
176
|
`/${route.path}`,
|
|
183
177
|
async (request: Server.Request, response: Server.Response): Promise<void> => {
|
|
184
|
-
Logger.info(
|
|
185
|
-
`${route.requestMethod}/${route.path}: executing handler method ${controller.name}.${route.methodName}`
|
|
186
|
-
);
|
|
178
|
+
Logger.info(`${route.requestMethod}/${route.path}: executing handler method ${controller.name}.${route.methodName}`);
|
|
187
179
|
const controllerInstance = Context.resolve(controller);
|
|
188
|
-
const args = route.argumentInjectors.map(injector => injector(request));
|
|
180
|
+
const args = route.argumentInjectors.map((injector) => injector(request));
|
|
189
181
|
const result = await controllerInstance[route.methodName](...args);
|
|
190
182
|
|
|
191
183
|
await Context.commit();
|
|
192
184
|
|
|
193
185
|
Context.destroy();
|
|
194
186
|
response.status(Server.statusCodes.OK).send({ result });
|
|
195
|
-
}
|
|
187
|
+
},
|
|
196
188
|
);
|
|
197
189
|
}
|
|
198
190
|
|
|
@@ -205,19 +197,12 @@ export class AppFactory {
|
|
|
205
197
|
const handlerConfiguration = reflect(handler).getHandlerConfiguration();
|
|
206
198
|
|
|
207
199
|
const instance = new handler();
|
|
208
|
-
for (const commandHandler of Array.from(
|
|
209
|
-
|
|
210
|
-
)) {
|
|
211
|
-
bus.onCommand(commandHandler.command, command => {
|
|
200
|
+
for (const commandHandler of Array.from(handlerConfiguration.commandHandlers.values())) {
|
|
201
|
+
bus.onCommand(commandHandler.command, (command) => {
|
|
212
202
|
const startDate = new Date();
|
|
213
|
-
Logger.info(
|
|
214
|
-
`${handler.name}.${commandHandler.methodName} handle ${command._type}`
|
|
215
|
-
);
|
|
203
|
+
Logger.info(`${handler.name}.${commandHandler.methodName} handle ${command._type}`);
|
|
216
204
|
const result = instance[commandHandler.methodName](command);
|
|
217
|
-
Logger.infoWithElapesedTime(
|
|
218
|
-
`${command._type} handled by ${handler.name}.${commandHandler.methodName}`,
|
|
219
|
-
startDate
|
|
220
|
-
);
|
|
205
|
+
Logger.infoWithElapesedTime(`${command._type} handled by ${handler.name}.${commandHandler.methodName}`, startDate);
|
|
221
206
|
return result;
|
|
222
207
|
});
|
|
223
208
|
}
|
|
@@ -225,18 +210,13 @@ export class AppFactory {
|
|
|
225
210
|
for (const eventHandler of Array.from(handlerConfiguration.eventHandlers.values())) {
|
|
226
211
|
bus.onEvent(
|
|
227
212
|
eventHandler.event,
|
|
228
|
-
async event => {
|
|
213
|
+
async (event) => {
|
|
229
214
|
const startDate = new Date();
|
|
230
|
-
Logger.info(
|
|
231
|
-
`${handler.name}.${eventHandler.methodName} handle ${event._type}`
|
|
232
|
-
);
|
|
215
|
+
Logger.info(`${handler.name}.${eventHandler.methodName} handle ${event._type}`);
|
|
233
216
|
await instance[eventHandler.methodName](event);
|
|
234
|
-
Logger.infoWithElapesedTime(
|
|
235
|
-
`${event._type} handled by ${handler.name}.${eventHandler.methodName}`,
|
|
236
|
-
startDate
|
|
237
|
-
);
|
|
217
|
+
Logger.infoWithElapesedTime(`${event._type} handled by ${handler.name}.${eventHandler.methodName}`, startDate);
|
|
238
218
|
},
|
|
239
|
-
eventHandler.executionMode
|
|
219
|
+
eventHandler.executionMode,
|
|
240
220
|
);
|
|
241
221
|
}
|
|
242
222
|
}
|
|
@@ -260,7 +240,7 @@ export class AppFactory {
|
|
|
260
240
|
eventId: Context.eventId,
|
|
261
241
|
userId: Context.user?.uid,
|
|
262
242
|
userEmail: Context.user?.email,
|
|
263
|
-
...data
|
|
243
|
+
...data,
|
|
264
244
|
};
|
|
265
245
|
};
|
|
266
246
|
|
|
@@ -276,14 +256,11 @@ export class AppFactory {
|
|
|
276
256
|
},
|
|
277
257
|
error: (message: string, data: Logger.LogMetaData): void => {
|
|
278
258
|
logger.error(message, completeMetaData(data));
|
|
279
|
-
}
|
|
259
|
+
},
|
|
280
260
|
});
|
|
281
261
|
}
|
|
282
262
|
|
|
283
|
-
public static getFunctionCommandHandler<C extends Command>(
|
|
284
|
-
bus: Bus,
|
|
285
|
-
commandType: new () => C
|
|
286
|
-
): () => any {
|
|
263
|
+
public static getFunctionCommandHandler<C extends Command>(bus: Bus, commandType: new () => C): () => any {
|
|
287
264
|
return async (): Promise<void> => {
|
|
288
265
|
const startDate = new Date();
|
|
289
266
|
|
|
@@ -299,25 +276,16 @@ export class AppFactory {
|
|
|
299
276
|
|
|
300
277
|
await Context.commit();
|
|
301
278
|
|
|
302
|
-
Logger.infoWithElapesedTime(
|
|
303
|
-
`${'-'.repeat(5)} ${command._type} handled successfully ${'-'.repeat(5)}`,
|
|
304
|
-
startDate
|
|
305
|
-
);
|
|
279
|
+
Logger.infoWithElapesedTime(`${'-'.repeat(5)} ${command._type} handled successfully ${'-'.repeat(5)}`, startDate);
|
|
306
280
|
} catch (error) {
|
|
307
|
-
Logger.error(
|
|
308
|
-
`${'-'.repeat(5)} ${command._type} couldn't be handled correctly ${'-'.repeat(5)}`,
|
|
309
|
-
{ error }
|
|
310
|
-
);
|
|
281
|
+
Logger.error(`${'-'.repeat(5)} ${command._type} couldn't be handled correctly ${'-'.repeat(5)}`, { error });
|
|
311
282
|
} finally {
|
|
312
283
|
Context.destroy();
|
|
313
284
|
}
|
|
314
285
|
};
|
|
315
286
|
}
|
|
316
287
|
|
|
317
|
-
public static getFunctionEventHandler(
|
|
318
|
-
bus: Bus,
|
|
319
|
-
mode: ExecutionMode
|
|
320
|
-
): (snapshot: FirestoreEvent<QueryDocumentSnapshot>) => any {
|
|
288
|
+
public static getFunctionEventHandler(bus: Bus, mode: ExecutionMode): (snapshot: FirestoreEvent<QueryDocumentSnapshot>) => any {
|
|
321
289
|
return async (snapshot: FirestoreEvent<QueryDocumentSnapshot>): Promise<void> => {
|
|
322
290
|
const startDate = new Date();
|
|
323
291
|
const unserializedEvent = snapshot.data.data();
|
|
@@ -340,15 +308,9 @@ export class AppFactory {
|
|
|
340
308
|
|
|
341
309
|
await Context.commit();
|
|
342
310
|
|
|
343
|
-
Logger.infoWithElapesedTime(
|
|
344
|
-
`${'-'.repeat(5)} ${event._type} handled successfully ${'-'.repeat(5)}`,
|
|
345
|
-
startDate
|
|
346
|
-
);
|
|
311
|
+
Logger.infoWithElapesedTime(`${'-'.repeat(5)} ${event._type} handled successfully ${'-'.repeat(5)}`, startDate);
|
|
347
312
|
} catch (error) {
|
|
348
|
-
Logger.error(
|
|
349
|
-
`${'-'.repeat(5)} ${event._type} couldn't be handled correctly ${'-'.repeat(5)}`,
|
|
350
|
-
{ error }
|
|
351
|
-
);
|
|
313
|
+
Logger.error(`${'-'.repeat(5)} ${event._type} couldn't be handled correctly ${'-'.repeat(5)}`, { error });
|
|
352
314
|
} finally {
|
|
353
315
|
Context.destroy();
|
|
354
316
|
}
|
package/src/bus.ts
CHANGED
|
@@ -23,35 +23,22 @@ export class Bus {
|
|
|
23
23
|
return handler(command);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public async publish<E extends Event>(
|
|
27
|
-
event: E,
|
|
28
|
-
mode: ExecutionMode = ExecutionMode.Synchronous
|
|
29
|
-
): Promise<void> {
|
|
26
|
+
public async publish<E extends Event>(event: E, mode: ExecutionMode = ExecutionMode.Synchronous): Promise<void> {
|
|
30
27
|
Logger.info(`Bus.publish ${event._type} `, { event: serialize(event) });
|
|
31
28
|
|
|
32
|
-
const handlers = [
|
|
33
|
-
...this.getEventHandlers(event._type, mode),
|
|
34
|
-
...this.getEventHandlers('**', mode)
|
|
35
|
-
];
|
|
29
|
+
const handlers = [...this.getEventHandlers(event._type, mode), ...this.getEventHandlers('**', mode)];
|
|
36
30
|
for (const handler of handlers) {
|
|
37
31
|
Logger.info(`Run event handler ${handler.name}`);
|
|
38
32
|
await handler(event);
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
public onCommand<C extends Command, R>(
|
|
43
|
-
commandType: new () => C,
|
|
44
|
-
handler: Bus.Handler<C, R>
|
|
45
|
-
): void {
|
|
36
|
+
public onCommand<C extends Command, R>(commandType: new () => C, handler: Bus.Handler<C, R>): void {
|
|
46
37
|
const commandName = commandType.constructor.name;
|
|
47
38
|
this.commandHandlers.set(commandName, handler);
|
|
48
39
|
}
|
|
49
40
|
|
|
50
|
-
public onEvent<E extends Event>(
|
|
51
|
-
eventType: new () => E,
|
|
52
|
-
handler: Bus.Handler<E, void>,
|
|
53
|
-
mode: ExecutionMode
|
|
54
|
-
): void {
|
|
41
|
+
public onEvent<E extends Event>(eventType: new () => E, handler: Bus.Handler<E, void>, mode: ExecutionMode): void {
|
|
55
42
|
this.registerEventHandler(eventType.constructor.name, mode, handler);
|
|
56
43
|
}
|
|
57
44
|
|
|
@@ -63,11 +50,7 @@ export class Bus {
|
|
|
63
50
|
return `${eventType}_${mode.toString()}`;
|
|
64
51
|
}
|
|
65
52
|
|
|
66
|
-
private registerEventHandler<E extends Event>(
|
|
67
|
-
type: string,
|
|
68
|
-
mode: ExecutionMode,
|
|
69
|
-
handler: Bus.Handler<E, void>
|
|
70
|
-
): void {
|
|
53
|
+
private registerEventHandler<E extends Event>(type: string, mode: ExecutionMode, handler: Bus.Handler<E, void>): void {
|
|
71
54
|
const key = this.getDictionaryKey(type, mode);
|
|
72
55
|
|
|
73
56
|
if (!this.eventHandlers.has(key)) {
|
package/src/constants.ts
CHANGED
package/src/context.ts
CHANGED
|
@@ -32,13 +32,10 @@ describe('Given a Body decorator', () => {
|
|
|
32
32
|
|
|
33
33
|
const request1 = <any>{ body: '2021-02-08T11:14:23.318Z' };
|
|
34
34
|
|
|
35
|
-
expect(config.routes[0].argumentInjectors.length).equal(
|
|
36
|
-
1,
|
|
37
|
-
'Wrong argumentInjectors length'
|
|
38
|
-
);
|
|
35
|
+
expect(config.routes[0].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length');
|
|
39
36
|
expect(config.routes[0].argumentInjectors[0](request1)).to.be.a('Date');
|
|
40
37
|
expect(config.routes[0].argumentInjectors[0](request1).toISOString()).equals(
|
|
41
|
-
new Date('2021-02-08T11:14:23.318Z').toISOString()
|
|
38
|
+
new Date('2021-02-08T11:14:23.318Z').toISOString(),
|
|
42
39
|
);
|
|
43
40
|
|
|
44
41
|
const request2 = <any>{ body: { testString: 'test' } };
|
|
@@ -47,10 +44,7 @@ describe('Given a Body decorator', () => {
|
|
|
47
44
|
expectedBody2.testString = 'test';
|
|
48
45
|
expectedBody2.testDate = null;
|
|
49
46
|
|
|
50
|
-
expect(config.routes[1].argumentInjectors.length).equal(
|
|
51
|
-
1,
|
|
52
|
-
'Wrong argumentInjectors length'
|
|
53
|
-
);
|
|
47
|
+
expect(config.routes[1].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length');
|
|
54
48
|
expect(config.routes[1].argumentInjectors[0](request2)).to.be.instanceOf(Command);
|
|
55
49
|
expect(config.routes[1].argumentInjectors[0](request2)).deep.equal(expectedBody2);
|
|
56
50
|
});
|
|
@@ -7,17 +7,11 @@ export function Body(): ParameterDecorator {
|
|
|
7
7
|
return (target, propertyKey, parameterIndex) => {
|
|
8
8
|
const methodArguments = reflect(target, propertyKey).getParameters();
|
|
9
9
|
if (!methodArguments.hasOwnProperty(parameterIndex)) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Body: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`
|
|
12
|
-
);
|
|
10
|
+
throw new Error(`Body: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
const injector: RequestArgumentInjector = (req: Server.Request) =>
|
|
16
|
-
deserialize(req.body, methodArguments[parameterIndex]);
|
|
13
|
+
const injector: RequestArgumentInjector = (req: Server.Request) => deserialize(req.body, methodArguments[parameterIndex]);
|
|
17
14
|
|
|
18
|
-
reflect(target, propertyKey).registerControllerRouteArgumentInjector(
|
|
19
|
-
injector,
|
|
20
|
-
parameterIndex
|
|
21
|
-
);
|
|
15
|
+
reflect(target, propertyKey).registerControllerRouteArgumentInjector(injector, parameterIndex);
|
|
22
16
|
};
|
|
23
17
|
}
|
|
@@ -2,7 +2,7 @@ import { reflect } from '../../reflect';
|
|
|
2
2
|
import { Injectable } from './../injectable';
|
|
3
3
|
|
|
4
4
|
export function Controller(basePath: string): ClassDecorator {
|
|
5
|
-
return target => {
|
|
5
|
+
return (target) => {
|
|
6
6
|
reflect(target).registerController(basePath);
|
|
7
7
|
// Register controller as injectable ressource
|
|
8
8
|
Injectable()(target);
|
|
@@ -8,7 +8,7 @@ import { Param } from './param';
|
|
|
8
8
|
describe('Given a Param decorator', () => {
|
|
9
9
|
enum Gender {
|
|
10
10
|
Male = 0,
|
|
11
|
-
Female = 'Female'
|
|
11
|
+
Female = 'Female',
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
@Controller('test')
|
|
@@ -19,10 +19,7 @@ describe('Given a Param decorator', () => {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
@Get(':gender/:minDate')
|
|
22
|
-
public getByGenderOlderThan(
|
|
23
|
-
@Param('minDate') minDate: Date,
|
|
24
|
-
@Param('gender') gender: Gender
|
|
25
|
-
): string {
|
|
22
|
+
public getByGenderOlderThan(@Param('minDate') minDate: Date, @Param('gender') gender: Gender): string {
|
|
26
23
|
return `getByGenderOlderThan: ${gender} ${minDate.toISOString()}`;
|
|
27
24
|
}
|
|
28
25
|
}
|
|
@@ -33,23 +30,17 @@ describe('Given a Param decorator', () => {
|
|
|
33
30
|
expect(config.routes.length).equal(2, 'Wrong route count detected');
|
|
34
31
|
|
|
35
32
|
const request1 = <any>{ params: { id: 'guid 1' } };
|
|
36
|
-
expect(config.routes[0].argumentInjectors.length).equal(
|
|
37
|
-
1,
|
|
38
|
-
'Wrong argumentInjectors length for getById'
|
|
39
|
-
);
|
|
33
|
+
expect(config.routes[0].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length for getById');
|
|
40
34
|
expect(config.routes[0].argumentInjectors[0](request1)).to.be.a('string');
|
|
41
35
|
expect(config.routes[0].argumentInjectors[0](request1)).equals('guid 1');
|
|
42
36
|
|
|
43
37
|
const request2 = <any>{ params: { gender: 0, minDate: '2021-02-15T14:23:00.318Z' } };
|
|
44
38
|
|
|
45
|
-
expect(config.routes[1].argumentInjectors.length).equal(
|
|
46
|
-
2,
|
|
47
|
-
'Wrong argumentInjectors length for getByGenderOlderThan'
|
|
48
|
-
);
|
|
39
|
+
expect(config.routes[1].argumentInjectors.length).equal(2, 'Wrong argumentInjectors length for getByGenderOlderThan');
|
|
49
40
|
|
|
50
41
|
expect(config.routes[1].argumentInjectors[0](request2)).to.be.a('Date');
|
|
51
42
|
expect(config.routes[1].argumentInjectors[0](request2).toISOString()).equals(
|
|
52
|
-
new Date('2021-02-15T14:23:00.318Z').toISOString()
|
|
43
|
+
new Date('2021-02-15T14:23:00.318Z').toISOString(),
|
|
53
44
|
);
|
|
54
45
|
|
|
55
46
|
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Male);
|
|
@@ -7,9 +7,7 @@ export function Param(key: string): ParameterDecorator {
|
|
|
7
7
|
return (target, propertyKey, parameterIndex) => {
|
|
8
8
|
const methodArguments = reflect(target, propertyKey).getParameters();
|
|
9
9
|
if (!methodArguments.hasOwnProperty(parameterIndex)) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Param: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`
|
|
12
|
-
);
|
|
10
|
+
throw new Error(`Param: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
const injector: RequestArgumentInjector = (req: Server.Request) => {
|
|
@@ -18,9 +16,6 @@ export function Param(key: string): ParameterDecorator {
|
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
reflect(target, propertyKey).registerControllerRouteArgumentInjector(
|
|
22
|
-
injector,
|
|
23
|
-
parameterIndex
|
|
24
|
-
);
|
|
19
|
+
reflect(target, propertyKey).registerControllerRouteArgumentInjector(injector, parameterIndex);
|
|
25
20
|
};
|
|
26
21
|
}
|
|
@@ -8,7 +8,7 @@ import { Query } from './query';
|
|
|
8
8
|
describe('Given a Query decorator', () => {
|
|
9
9
|
enum Gender {
|
|
10
10
|
Male = 0,
|
|
11
|
-
Female = 'Female'
|
|
11
|
+
Female = 'Female',
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
@Controller('test')
|
|
@@ -30,23 +30,17 @@ describe('Given a Query decorator', () => {
|
|
|
30
30
|
expect(config.routes.length).equal(2, 'Wrong route count detected');
|
|
31
31
|
|
|
32
32
|
const request1 = <any>{ query: { id: 'guid 1' } };
|
|
33
|
-
expect(config.routes[0].argumentInjectors.length).equal(
|
|
34
|
-
1,
|
|
35
|
-
'Wrong argumentInjectors length for getById'
|
|
36
|
-
);
|
|
33
|
+
expect(config.routes[0].argumentInjectors.length).equal(1, 'Wrong argumentInjectors length for getById');
|
|
37
34
|
expect(config.routes[0].argumentInjectors[0](request1)).to.be.a('string');
|
|
38
35
|
expect(config.routes[0].argumentInjectors[0](request1)).equals('guid 1');
|
|
39
36
|
|
|
40
37
|
const request2 = <any>{ query: { gender: 0, minDate: '2021-02-15T14:23:00.318Z' } };
|
|
41
38
|
|
|
42
|
-
expect(config.routes[1].argumentInjectors.length).equal(
|
|
43
|
-
2,
|
|
44
|
-
'Wrong argumentInjectors length for getByGenderOlderThan'
|
|
45
|
-
);
|
|
39
|
+
expect(config.routes[1].argumentInjectors.length).equal(2, 'Wrong argumentInjectors length for getByGenderOlderThan');
|
|
46
40
|
|
|
47
41
|
expect(config.routes[1].argumentInjectors[0](request2)).to.be.a('Date');
|
|
48
42
|
expect(config.routes[1].argumentInjectors[0](request2).toISOString()).equals(
|
|
49
|
-
new Date('2021-02-15T14:23:00.318Z').toISOString()
|
|
43
|
+
new Date('2021-02-15T14:23:00.318Z').toISOString(),
|
|
50
44
|
);
|
|
51
45
|
|
|
52
46
|
expect(config.routes[1].argumentInjectors[1](request2)).equals(Gender.Male);
|
|
@@ -7,9 +7,7 @@ export function Query(key: string): ParameterDecorator {
|
|
|
7
7
|
return (target, propertyKey, parameterIndex) => {
|
|
8
8
|
const methodArguments = reflect(target, propertyKey).getParameters();
|
|
9
9
|
if (!methodArguments.hasOwnProperty(parameterIndex)) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Query: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`
|
|
12
|
-
);
|
|
10
|
+
throw new Error(`Query: can't find argument ${parameterIndex} on ${target.constructor.name}.${propertyKey.toString()}`);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
const injector: RequestArgumentInjector = (req: Server.Request) => {
|
|
@@ -18,9 +16,6 @@ export function Query(key: string): ParameterDecorator {
|
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
reflect(target, propertyKey).registerControllerRouteArgumentInjector(
|
|
22
|
-
injector,
|
|
23
|
-
parameterIndex
|
|
24
|
-
);
|
|
19
|
+
reflect(target, propertyKey).registerControllerRouteArgumentInjector(injector, parameterIndex);
|
|
25
20
|
};
|
|
26
21
|
}
|