@webda/core 2.0.0-beta.1 → 2.0.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/lib/application.d.ts +9 -21
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +86 -46
- package/lib/core.js +254 -316
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +326 -391
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -45
- package/lib/index.js +54 -67
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +127 -151
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +84 -11
- package/lib/models/coremodel.js +104 -103
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +91 -91
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +5 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +12 -2
- package/lib/models/ownermodel.js +54 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +129 -152
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +2 -2
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -61
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +5 -5
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +4 -4
- package/lib/queues/queueservice.js +52 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +7 -3
- package/lib/router.js +49 -48
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +28 -19
- package/lib/services/authentication.js +539 -571
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +8 -6
- package/lib/services/binary.js +212 -244
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +46 -71
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +6 -3
- package/lib/services/configuration.js +78 -103
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +258 -0
- package/lib/services/cryptoservice.js +312 -0
- package/lib/services/cryptoservice.js.map +1 -0
- package/lib/services/cryptoservice.spec.d.ts +1 -0
- package/lib/services/cryptoservice.spec.js +137 -0
- package/lib/services/cryptoservice.spec.js.map +1 -0
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +15 -5
- package/lib/services/filebinary.js +171 -200
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -117
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +2 -2
- package/lib/services/fileconfiguration.js +25 -43
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +9 -9
- package/lib/services/invitationservice.js +275 -313
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +442 -448
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +2 -2
- package/lib/services/kubernetesconfiguration.js +41 -59
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +4 -4
- package/lib/services/notificationservice.js +23 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +32 -6
- package/lib/services/oauth.js +73 -78
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +128 -147
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +74 -0
- package/lib/services/proxy.js +126 -0
- package/lib/services/proxy.js.map +1 -0
- package/lib/services/proxy.spec.d.ts +1 -0
- package/lib/services/proxy.spec.js +59 -0
- package/lib/services/proxy.spec.js.map +1 -0
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +33 -7
- package/lib/services/service.js +74 -42
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -3
- package/lib/stores/aggregator.js +37 -57
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +261 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.js +112 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +131 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +67 -6
- package/lib/stores/memory.js +155 -117
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +3 -2
- package/lib/stores/memory.spec.js +127 -105
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +35 -15
- package/lib/stores/store.js +839 -821
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +6 -4
- package/lib/stores/store.spec.js +627 -647
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +74 -94
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +25 -31
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +61 -29
- package/lib/utils/context.js +133 -127
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +147 -153
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +66 -45
- package/lib/utils/cookie.js +69 -158
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +220 -238
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +37 -9
- package/lib/utils/httpcontext.js +86 -57
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -48
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +120 -0
- package/lib/utils/session.js +155 -0
- package/lib/utils/session.js.map +1 -0
- package/lib/utils/session.spec.d.ts +1 -0
- package/lib/utils/session.spec.js +66 -0
- package/lib/utils/session.spec.js.map +1 -0
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +22 -14
- package/test/config-invitation.json +1 -3
- package/test/config.json +3 -3
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +956 -188
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.spec.js","sourceRoot":"","sources":["../../src/services/proxy.spec.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,SAAS;IAG/B,KAAK,CAAC,MAAM;QACV,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED,SAAS;QACP,IAAI,CAAC,MAAM,GAAG,IAAI;aACf,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACzB,mBAAmB;YACnB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC,CAAC;aACD,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IACvB,CAAC;IAGD,KAAK,CAAC,KAAK;QACT,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,EAA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AyF;QAEzF,MAAM;QACN,YAAY,CAAC,aAAa,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC;QAC7C,YAAY,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF,CAAA;AA5BC;IADC,IAAI;sCA4BJ;AAjDG,SAAS;IADd,KAAK;GACA,SAAS,CAkDd"}
|
package/lib/services/resource.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const mime = require("mime-types");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const service_1 = require("./service");
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as mime from "mime-types";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
8
5
|
/**
|
|
9
6
|
* ResourceService parameters
|
|
10
7
|
*/
|
|
11
|
-
class ResourceServiceParameters extends
|
|
8
|
+
export class ResourceServiceParameters extends ServiceParameters {
|
|
12
9
|
constructor(params) {
|
|
13
|
-
var _a, _b, _c, _d, _e;
|
|
14
10
|
super(params);
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
this.url ?? (this.url = "resources");
|
|
12
|
+
this.rootRedirect ?? (this.rootRedirect = false);
|
|
17
13
|
if (!this.url.startsWith("/")) {
|
|
18
14
|
this.url = "/" + this.url;
|
|
19
15
|
}
|
|
20
16
|
if (!this.url.endsWith("/")) {
|
|
21
17
|
this.url += "/";
|
|
22
18
|
}
|
|
23
|
-
|
|
19
|
+
this.folder ?? (this.folder = "." + this.url);
|
|
24
20
|
if (!this.folder.endsWith("/")) {
|
|
25
21
|
this.folder += "/";
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
this.index ?? (this.index = "index.html");
|
|
24
|
+
this.indexFallback ?? (this.indexFallback = true);
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
exports.ResourceServiceParameters = ResourceServiceParameters;
|
|
32
27
|
/**
|
|
33
28
|
* This service expose a folder as web
|
|
34
29
|
*
|
|
@@ -37,7 +32,7 @@ exports.ResourceServiceParameters = ResourceServiceParameters;
|
|
|
37
32
|
* @category CoreServices
|
|
38
33
|
* @WebdaModda
|
|
39
34
|
*/
|
|
40
|
-
class ResourceService extends
|
|
35
|
+
export default class ResourceService extends Service {
|
|
41
36
|
/**
|
|
42
37
|
* Load the parameters for a service
|
|
43
38
|
*/
|
|
@@ -148,6 +143,5 @@ class ResourceService extends service_1.Service {
|
|
|
148
143
|
ctx.end();
|
|
149
144
|
}
|
|
150
145
|
}
|
|
151
|
-
|
|
152
|
-
exports.ResourceService = ResourceService;
|
|
146
|
+
export { ResourceService };
|
|
153
147
|
//# sourceMappingURL=resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/services/resource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/services/resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IAiC9D,YAAY,MAAW;QACrB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,GAAG,KAAR,IAAI,CAAC,GAAG,GAAK,WAAW,EAAC;QACzB,IAAI,CAAC,YAAY,KAAjB,IAAI,CAAC,YAAY,GAAK,KAAK,EAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;SAC3B;QACD,IAAI,CAAC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I,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACtF;QAED,yBAAyB;QACzB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAClD,MAAM,GAAG,CAAC;SACX;QAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACxB,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YACxD,oBAAoB;YACpB,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE;gBAC3D,MAAM,GAAG,CAAC;aACX;SACF;QACD,IAAI,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC;QAC/D,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAChC,QAAQ,IAAI,iBAAiB,CAAC;SAC/B;QACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;YACjB,cAAc,EAAE,QAAQ;SACzB,CAAC,CAAC;QACH,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QACjC,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC;CACF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,144 +1,112 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const assert = require("assert");
|
|
20
|
-
const fs = require("fs");
|
|
21
|
-
const test_1 = require("../test");
|
|
22
|
-
const resource_1 = require("./resource");
|
|
23
|
-
let ResourceTest = class ResourceTest extends test_1.WebdaTest {
|
|
24
|
-
before(init = true) {
|
|
25
|
-
const _super = Object.create(null, {
|
|
26
|
-
before: { get: () => super.before }
|
|
27
|
-
});
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
yield _super.before.call(this, init);
|
|
30
|
-
this.resource = this.getService("ResourceService");
|
|
31
|
-
this.resourceModel = this.getService("ModelsResource");
|
|
32
|
-
this.ctx = yield this.newContext();
|
|
33
|
-
});
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import { WebdaTest } from "../test.js";
|
|
11
|
+
import { ResourceServiceParameters } from "./resource.js";
|
|
12
|
+
let ResourceTest = class ResourceTest extends WebdaTest {
|
|
13
|
+
async before(init = true) {
|
|
14
|
+
await super.before(init);
|
|
15
|
+
this.resource = this.getService("ResourceService");
|
|
16
|
+
this.resourceModel = this.getService("ModelsResource");
|
|
17
|
+
this.ctx = await this.newContext();
|
|
34
18
|
}
|
|
35
|
-
parentFolder() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
yield assert.rejects(() => executor.execute(this.ctx), err => err == 401);
|
|
40
|
-
});
|
|
19
|
+
async parentFolder() {
|
|
20
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/../config.json");
|
|
21
|
+
assert.notStrictEqual(executor, undefined);
|
|
22
|
+
await assert.rejects(() => executor.execute(this.ctx), err => err == 401);
|
|
41
23
|
}
|
|
42
24
|
params() {
|
|
43
|
-
let params = new
|
|
25
|
+
let params = new ResourceServiceParameters({
|
|
44
26
|
url: "/test/",
|
|
45
27
|
rootRedirect: true
|
|
46
28
|
});
|
|
47
29
|
assert.strictEqual(params.url, "/test/");
|
|
48
30
|
assert.strictEqual(params.folder, "./test/");
|
|
49
31
|
}
|
|
50
|
-
redirect() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
assert.strictEqual(this.ctx.getResponseHeaders().Location, "http://test.webda.io/resources/");
|
|
59
|
-
});
|
|
32
|
+
async redirect() {
|
|
33
|
+
this.resource.getParameters().rootRedirect = true;
|
|
34
|
+
this.webda.getRouter().removeRoute("/");
|
|
35
|
+
assert.ok(this.webda.getRouter().getRouteFromUrl(this.ctx, "GET", "/") === undefined);
|
|
36
|
+
this.resource.initRoutes();
|
|
37
|
+
assert.ok(this.webda.getRouter().getRouteFromUrl(this.ctx, "GET", "/") !== undefined);
|
|
38
|
+
this.resource._redirect(this.ctx);
|
|
39
|
+
assert.strictEqual(this.ctx.getResponseHeaders().Location, "http://test.webda.io/resources/");
|
|
60
40
|
}
|
|
61
|
-
index() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
yield assert.rejects(() => executor.execute(this.ctx), err => err == 404);
|
|
66
|
-
});
|
|
41
|
+
async index() {
|
|
42
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/");
|
|
43
|
+
// index.html does not exist in our case
|
|
44
|
+
await assert.rejects(() => executor.execute(this.ctx), err => err == 404);
|
|
67
45
|
}
|
|
68
|
-
unknownFile() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
yield assert.rejects(() => executor.execute(this.ctx), /404/);
|
|
74
|
-
});
|
|
46
|
+
async unknownFile() {
|
|
47
|
+
this.getService("ResourceService").getParameters().indexFallback = true;
|
|
48
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/config.unknown.json");
|
|
49
|
+
assert.notStrictEqual(executor, undefined);
|
|
50
|
+
await assert.rejects(() => executor.execute(this.ctx), /404/);
|
|
75
51
|
}
|
|
76
|
-
jsonFile() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/json");
|
|
83
|
-
});
|
|
52
|
+
async jsonFile() {
|
|
53
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/config.json");
|
|
54
|
+
assert.notStrictEqual(executor, undefined);
|
|
55
|
+
await executor.execute(this.ctx);
|
|
56
|
+
assert.strictEqual(this.ctx.getResponseBody().toString(), fs.readFileSync("./test/config.json").toString());
|
|
57
|
+
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/json");
|
|
84
58
|
}
|
|
85
|
-
jsFile() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/javascript");
|
|
92
|
-
});
|
|
59
|
+
async jsFile() {
|
|
60
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/moddas/voidstore.js");
|
|
61
|
+
assert.notStrictEqual(executor, undefined);
|
|
62
|
+
await executor.execute(this.ctx);
|
|
63
|
+
assert.strictEqual(this.ctx.getResponseBody().toString(), fs.readFileSync("./test/moddas/voidstore.js").toString());
|
|
64
|
+
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/javascript");
|
|
93
65
|
}
|
|
94
|
-
textFile() {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "text/plain; charset=UTF-8");
|
|
101
|
-
});
|
|
66
|
+
async textFile() {
|
|
67
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/resources/data/test.txt");
|
|
68
|
+
assert.notStrictEqual(executor, undefined);
|
|
69
|
+
await executor.execute(this.ctx);
|
|
70
|
+
assert.strictEqual(this.ctx.getResponseBody().toString(), fs.readFileSync("./test/data/test.txt").toString());
|
|
71
|
+
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "text/plain; charset=UTF-8");
|
|
102
72
|
}
|
|
103
73
|
// Check Store HTTP mapping
|
|
104
|
-
testStoreHttpMapping() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/octet-stream");
|
|
111
|
-
});
|
|
74
|
+
async testStoreHttpMapping() {
|
|
75
|
+
let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/templates/PASSPORT_EMAIL_RECOVERY/html.mustache");
|
|
76
|
+
assert.notStrictEqual(executor, undefined);
|
|
77
|
+
await executor.execute(this.ctx);
|
|
78
|
+
assert.strictEqual(this.ctx.getResponseBody().toString(), fs.readFileSync("./templates/PASSPORT_EMAIL_RECOVERY/html.mustache").toString());
|
|
79
|
+
assert.strictEqual(this.ctx.getResponseHeaders()["Content-Type"], "application/octet-stream");
|
|
112
80
|
}
|
|
113
81
|
};
|
|
114
82
|
__decorate([
|
|
115
|
-
|
|
83
|
+
test
|
|
116
84
|
], ResourceTest.prototype, "parentFolder", null);
|
|
117
85
|
__decorate([
|
|
118
|
-
|
|
86
|
+
test
|
|
119
87
|
], ResourceTest.prototype, "params", null);
|
|
120
88
|
__decorate([
|
|
121
|
-
|
|
89
|
+
test
|
|
122
90
|
], ResourceTest.prototype, "redirect", null);
|
|
123
91
|
__decorate([
|
|
124
|
-
|
|
92
|
+
test
|
|
125
93
|
], ResourceTest.prototype, "index", null);
|
|
126
94
|
__decorate([
|
|
127
|
-
|
|
95
|
+
test
|
|
128
96
|
], ResourceTest.prototype, "unknownFile", null);
|
|
129
97
|
__decorate([
|
|
130
|
-
|
|
98
|
+
test
|
|
131
99
|
], ResourceTest.prototype, "jsonFile", null);
|
|
132
100
|
__decorate([
|
|
133
|
-
|
|
101
|
+
test
|
|
134
102
|
], ResourceTest.prototype, "jsFile", null);
|
|
135
103
|
__decorate([
|
|
136
|
-
|
|
104
|
+
test
|
|
137
105
|
], ResourceTest.prototype, "textFile", null);
|
|
138
106
|
__decorate([
|
|
139
|
-
|
|
107
|
+
test
|
|
140
108
|
], ResourceTest.prototype, "testStoreHttpMapping", null);
|
|
141
109
|
ResourceTest = __decorate([
|
|
142
|
-
|
|
110
|
+
suite
|
|
143
111
|
], ResourceTest);
|
|
144
112
|
//# sourceMappingURL=resource.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.spec.js","sourceRoot":"","sources":["../../src/services/resource.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resource.spec.js","sourceRoot":"","sources":["../../src/services/resource.spec.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGxE,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,SAAS;IAIlC,KAAK,CAAC,MAAM,CAAC,OAAgB,IAAI;QAC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J;AAtGG,YAAY;IADjB,KAAK;GACA,YAAY,CAuGjB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { WorkerLogLevel } from "@webda/workout";
|
|
3
3
|
import * as events from "events";
|
|
4
|
-
import { Core, Logger } from "../index";
|
|
5
|
-
import { OpenAPIWebdaDefinition } from "../router";
|
|
6
|
-
import { HttpMethodType } from "../utils/httpcontext";
|
|
4
|
+
import { Core, Logger } from "../index.js";
|
|
5
|
+
import { OpenAPIWebdaDefinition } from "../router.js";
|
|
6
|
+
import { HttpMethodType } from "../utils/httpcontext.js";
|
|
7
7
|
/**
|
|
8
8
|
* Inject a Bean inside this attribute
|
|
9
9
|
*
|
|
@@ -18,6 +18,7 @@ import { HttpMethodType } from "../utils/httpcontext";
|
|
|
18
18
|
* Might consider to split into two annotations
|
|
19
19
|
*/
|
|
20
20
|
export declare function Inject(parameterOrName: string, defaultValue?: string | boolean, optional?: boolean): (target: any, propertyName: string) => void;
|
|
21
|
+
export declare function Route(route: string, methods?: string | string[], allowPath?: boolean, openapi?: OpenAPIWebdaDefinition): (target: any, executor: string) => void;
|
|
21
22
|
/**
|
|
22
23
|
* Interface to specify the Service parameters
|
|
23
24
|
*/
|
|
@@ -26,6 +27,15 @@ export declare class ServiceParameters {
|
|
|
26
27
|
* Type of the service
|
|
27
28
|
*/
|
|
28
29
|
type: string;
|
|
30
|
+
/**
|
|
31
|
+
* URL on which to serve the content
|
|
32
|
+
*/
|
|
33
|
+
url?: string;
|
|
34
|
+
/**
|
|
35
|
+
* OpenAPI override
|
|
36
|
+
* @SchemaIgnore
|
|
37
|
+
*/
|
|
38
|
+
openapi?: OpenAPIWebdaDefinition;
|
|
29
39
|
/**
|
|
30
40
|
* Copy all parameters into the object by default
|
|
31
41
|
*
|
|
@@ -33,6 +43,9 @@ export declare class ServiceParameters {
|
|
|
33
43
|
*/
|
|
34
44
|
constructor(params: any);
|
|
35
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a new type with only optional
|
|
48
|
+
*/
|
|
36
49
|
export declare type DeepPartial<T> = {
|
|
37
50
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
38
51
|
};
|
|
@@ -107,7 +120,15 @@ declare abstract class Service<T extends ServiceParameters = ServiceParameters,
|
|
|
107
120
|
* Resolve parameters
|
|
108
121
|
* Call initRoutes and initBeanRoutes
|
|
109
122
|
*/
|
|
110
|
-
resolve():
|
|
123
|
+
resolve(): this;
|
|
124
|
+
/**
|
|
125
|
+
* Return the full path url based on parameters
|
|
126
|
+
*
|
|
127
|
+
* @param url relative url to service
|
|
128
|
+
* @param _methods in case we need filtering (like Store)
|
|
129
|
+
* @returns absolute url or undefined if need to skip the Route
|
|
130
|
+
*/
|
|
131
|
+
getUrl(url: string, _methods: HttpMethodType[]): string;
|
|
111
132
|
/**
|
|
112
133
|
* Add a route dynamicaly
|
|
113
134
|
*
|
|
@@ -115,7 +136,12 @@ declare abstract class Service<T extends ServiceParameters = ServiceParameters,
|
|
|
115
136
|
* @param {Array[]} methods
|
|
116
137
|
* @param {Function} executer Method to execute for this route
|
|
117
138
|
*/
|
|
118
|
-
protected addRoute(url: string, methods: HttpMethodType[], executer: Function, openapi?: OpenAPIWebdaDefinition, allowPath?: boolean): void;
|
|
139
|
+
protected addRoute(url: string, methods: HttpMethodType[], executer: Function, openapi?: OpenAPIWebdaDefinition, allowPath?: boolean, override?: boolean): void;
|
|
140
|
+
/**
|
|
141
|
+
* Return variables for replacement in openapi
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
getOpenApiReplacements(): any;
|
|
119
145
|
/**
|
|
120
146
|
* Init the routes
|
|
121
147
|
*/
|
|
@@ -134,12 +160,12 @@ declare abstract class Service<T extends ServiceParameters = ServiceParameters,
|
|
|
134
160
|
* @param config for the host so you can add your own route here
|
|
135
161
|
* @abstract
|
|
136
162
|
*/
|
|
137
|
-
init(): Promise<
|
|
163
|
+
init(): Promise<this>;
|
|
138
164
|
/**
|
|
139
165
|
*
|
|
140
166
|
* @param config new parameters for the service
|
|
141
167
|
*/
|
|
142
|
-
reinit(config: DeepPartial<T>): Promise<
|
|
168
|
+
reinit(config: DeepPartial<T>): Promise<this>;
|
|
143
169
|
/**
|
|
144
170
|
* Display a message if the listener takes too long
|
|
145
171
|
* @param start
|
package/lib/services/service.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Service = exports.ServiceParameters = exports.Inject = void 0;
|
|
13
|
-
const events = require("events");
|
|
1
|
+
import { deepmerge } from "deepmerge-ts";
|
|
2
|
+
import * as events from "events";
|
|
14
3
|
/**
|
|
15
4
|
* Represent a Inject annotation
|
|
16
5
|
*
|
|
@@ -80,7 +69,7 @@ class Injector {
|
|
|
80
69
|
*
|
|
81
70
|
* Might consider to split into two annotations
|
|
82
71
|
*/
|
|
83
|
-
function Inject(parameterOrName, defaultValue, optional) {
|
|
72
|
+
export function Inject(parameterOrName, defaultValue, optional) {
|
|
84
73
|
return function (target, propertyName) {
|
|
85
74
|
target.Injectors = target.Injectors || [];
|
|
86
75
|
if (typeof defaultValue === "boolean") {
|
|
@@ -91,11 +80,24 @@ function Inject(parameterOrName, defaultValue, optional) {
|
|
|
91
80
|
}
|
|
92
81
|
};
|
|
93
82
|
}
|
|
94
|
-
|
|
83
|
+
// @Route to declare route on Bean
|
|
84
|
+
export function Route(route, methods = ["GET"], allowPath = false, openapi = {}) {
|
|
85
|
+
return function (target, executor) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
(_a = target.constructor).routes ?? (_a.routes = {});
|
|
88
|
+
(_b = target.constructor.routes)[route] ?? (_b[route] = []);
|
|
89
|
+
target.constructor.routes[route].push({
|
|
90
|
+
methods: Array.isArray(methods) ? methods : [methods],
|
|
91
|
+
executor,
|
|
92
|
+
allowPath,
|
|
93
|
+
openapi
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|
|
95
97
|
/**
|
|
96
98
|
* Interface to specify the Service parameters
|
|
97
99
|
*/
|
|
98
|
-
class ServiceParameters {
|
|
100
|
+
export class ServiceParameters {
|
|
99
101
|
/**
|
|
100
102
|
* Copy all parameters into the object by default
|
|
101
103
|
*
|
|
@@ -105,7 +107,6 @@ class ServiceParameters {
|
|
|
105
107
|
Object.assign(this, params);
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
exports.ServiceParameters = ServiceParameters;
|
|
109
110
|
/**
|
|
110
111
|
* Use this object for representing a service in the application
|
|
111
112
|
* A Service is a singleton in the application, that is init after all others services are created
|
|
@@ -173,7 +174,27 @@ class Service extends events.EventEmitter {
|
|
|
173
174
|
// We wait for all services to be created before calling computeParameters
|
|
174
175
|
this.computeParameters();
|
|
175
176
|
this.initRoutes();
|
|
176
|
-
this
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Return the full path url based on parameters
|
|
181
|
+
*
|
|
182
|
+
* @param url relative url to service
|
|
183
|
+
* @param _methods in case we need filtering (like Store)
|
|
184
|
+
* @returns absolute url or undefined if need to skip the Route
|
|
185
|
+
*/
|
|
186
|
+
getUrl(url, _methods) {
|
|
187
|
+
// If url is absolute
|
|
188
|
+
if (url.startsWith("/")) {
|
|
189
|
+
return url;
|
|
190
|
+
}
|
|
191
|
+
if (!this.parameters.url) {
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
if (url.startsWith(".")) {
|
|
195
|
+
return this.parameters.url + url.substring(1);
|
|
196
|
+
}
|
|
197
|
+
return url;
|
|
177
198
|
}
|
|
178
199
|
/**
|
|
179
200
|
* Add a route dynamicaly
|
|
@@ -182,26 +203,39 @@ class Service extends events.EventEmitter {
|
|
|
182
203
|
* @param {Array[]} methods
|
|
183
204
|
* @param {Function} executer Method to execute for this route
|
|
184
205
|
*/
|
|
185
|
-
addRoute(url, methods, executer, openapi = {}, allowPath = false) {
|
|
186
|
-
let
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
info.openapi = openapi;
|
|
192
|
-
this._webda.addRoute(url, {
|
|
206
|
+
addRoute(url, methods, executer, openapi = {}, allowPath = false, override = false) {
|
|
207
|
+
let finalUrl = this.getUrl(url, methods);
|
|
208
|
+
if (!finalUrl) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this._webda.addRoute(finalUrl, {
|
|
193
212
|
_method: executer,
|
|
194
213
|
executor: this._name,
|
|
195
214
|
allowPath,
|
|
196
|
-
openapi,
|
|
197
|
-
methods
|
|
215
|
+
openapi: deepmerge(openapi, this.parameters.openapi || {}),
|
|
216
|
+
methods,
|
|
217
|
+
override
|
|
198
218
|
});
|
|
199
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Return variables for replacement in openapi
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
224
|
+
getOpenApiReplacements() {
|
|
225
|
+
return {};
|
|
226
|
+
}
|
|
200
227
|
/**
|
|
201
228
|
* Init the routes
|
|
202
229
|
*/
|
|
203
230
|
initRoutes() {
|
|
204
|
-
//
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
let routes = this.constructor.routes || {};
|
|
233
|
+
for (let j in routes) {
|
|
234
|
+
this.log("TRACE", "Adding route", j, "for bean", this.getName());
|
|
235
|
+
routes[j].forEach(route => {
|
|
236
|
+
this.addRoute(j, route.methods, this[route.executor], route.openapi, route.allowPath || false);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
205
239
|
}
|
|
206
240
|
/**
|
|
207
241
|
* Convert an object to JSON using the Webda json filter
|
|
@@ -219,21 +253,18 @@ class Service extends events.EventEmitter {
|
|
|
219
253
|
* @param config for the host so you can add your own route here
|
|
220
254
|
* @abstract
|
|
221
255
|
*/
|
|
222
|
-
init() {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
256
|
+
async init() {
|
|
257
|
+
// Can be overriden by subclasses if needed
|
|
258
|
+
return this;
|
|
226
259
|
}
|
|
227
260
|
/**
|
|
228
261
|
*
|
|
229
262
|
* @param config new parameters for the service
|
|
230
263
|
*/
|
|
231
|
-
reinit(config) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return this.init();
|
|
236
|
-
});
|
|
264
|
+
async reinit(config) {
|
|
265
|
+
this.parameters = this.loadParameters(config);
|
|
266
|
+
this.computeParameters();
|
|
267
|
+
return this.init();
|
|
237
268
|
}
|
|
238
269
|
/**
|
|
239
270
|
* Display a message if the listener takes too long
|
|
@@ -249,7 +280,7 @@ class Service extends events.EventEmitter {
|
|
|
249
280
|
* Emit the event with data and wait for Promise to finish if listener returned a Promise
|
|
250
281
|
*/
|
|
251
282
|
emitSync(event, data) {
|
|
252
|
-
|
|
283
|
+
let promises = [];
|
|
253
284
|
for (let listener of this.listeners(event)) {
|
|
254
285
|
let start = Date.now();
|
|
255
286
|
let result = listener(data);
|
|
@@ -337,8 +368,9 @@ class Service extends events.EventEmitter {
|
|
|
337
368
|
* @param args
|
|
338
369
|
*/
|
|
339
370
|
log(level, ...args) {
|
|
340
|
-
|
|
371
|
+
// Add the service name to avoid confusion
|
|
372
|
+
this.logger.log(level, `[${this._name}]`, ...args);
|
|
341
373
|
}
|
|
342
374
|
}
|
|
343
|
-
|
|
375
|
+
export { Service };
|
|
344
376
|
//# sourceMappingURL=service.js.map
|