@webda/core 2.0.0-beta.3 → 2.1.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 +5 -5
- 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 +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- 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 +128 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -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 +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- 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 +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- 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 +23 -13
- package/lib/services/authentication.js +540 -566
- 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 -245
- 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 +45 -70
- 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 +1 -1
- package/lib/services/configuration.js +78 -105
- 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 +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- 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 +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- 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 +8 -8
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- 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 +3 -3
- package/lib/services/notificationservice.js +21 -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 +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- 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 +26 -3
- package/lib/services/service.js +68 -40
- 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 +2 -2
- package/lib/stores/aggregator.js +37 -58
- 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 +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- 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 +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- 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 +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- 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 +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- 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 +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- 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 +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- 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 +895 -190
package/lib/core.js
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const coremodel_1 = require("./models/coremodel");
|
|
24
|
-
const router_1 = require("./router");
|
|
1
|
+
import Ajv from "ajv";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
import { deepmerge } from "deepmerge-ts";
|
|
4
|
+
import * as events from "events";
|
|
5
|
+
import jsonpath from "jsonpath";
|
|
6
|
+
import pkg from "node-machine-id";
|
|
7
|
+
import { v4 as uuidv4 } from "uuid";
|
|
8
|
+
import { Context, Logger, Store } from "./index.js";
|
|
9
|
+
import { CoreModel } from "./models/coremodel.js";
|
|
10
|
+
import { Router } from "./router.js";
|
|
11
|
+
const { machineIdSync } = pkg;
|
|
12
|
+
/**
|
|
13
|
+
* Copy from https://github.com/ajv-validator/ajv/blob/master/lib/runtime/validation_error.ts
|
|
14
|
+
* It is not exported by ajv
|
|
15
|
+
*/
|
|
16
|
+
export class ValidationError extends Error {
|
|
17
|
+
constructor(errors) {
|
|
18
|
+
super("validation failed");
|
|
19
|
+
this.errors = errors;
|
|
20
|
+
this.ajv = this.validation = true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
25
23
|
/**
|
|
26
24
|
*
|
|
27
25
|
*/
|
|
28
|
-
class RegistryEntry extends
|
|
26
|
+
export class RegistryEntry extends CoreModel {
|
|
29
27
|
}
|
|
30
|
-
exports.RegistryEntry = RegistryEntry;
|
|
31
28
|
/**
|
|
32
29
|
* Error with a code
|
|
33
30
|
*/
|
|
34
|
-
class WebdaError extends Error {
|
|
31
|
+
export class WebdaError extends Error {
|
|
35
32
|
/**
|
|
36
33
|
*
|
|
37
34
|
* @param code
|
|
@@ -48,13 +45,12 @@ class WebdaError extends Error {
|
|
|
48
45
|
return this.code;
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.WebdaError = WebdaError;
|
|
52
48
|
/**
|
|
53
49
|
* Filter request based on their origin
|
|
54
50
|
*
|
|
55
51
|
* @category CoreFeatures
|
|
56
52
|
*/
|
|
57
|
-
class OriginFilter {
|
|
53
|
+
export class OriginFilter {
|
|
58
54
|
constructor(origins) {
|
|
59
55
|
this.regexs = origins.map(origin => {
|
|
60
56
|
if (!origin.endsWith("$")) {
|
|
@@ -71,26 +67,23 @@ class OriginFilter {
|
|
|
71
67
|
* @param context
|
|
72
68
|
* @returns
|
|
73
69
|
*/
|
|
74
|
-
checkRequest(context) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
if (httpContext.origin.match(regexp)) {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
70
|
+
async checkRequest(context) {
|
|
71
|
+
let httpContext = context.getHttpContext();
|
|
72
|
+
for (let regexp of this.regexs) {
|
|
73
|
+
if (httpContext.hostname.match(regexp)) {
|
|
74
|
+
return true;
|
|
84
75
|
}
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
if (httpContext.origin.match(regexp)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
|
-
exports.OriginFilter = OriginFilter;
|
|
90
83
|
/**
|
|
91
84
|
* Authorize requests based on the website
|
|
92
85
|
*/
|
|
93
|
-
class WebsiteOriginFilter {
|
|
86
|
+
export class WebsiteOriginFilter {
|
|
94
87
|
constructor(website) {
|
|
95
88
|
this.websites = [];
|
|
96
89
|
if (!Array.isArray(website)) {
|
|
@@ -105,58 +98,35 @@ class WebsiteOriginFilter {
|
|
|
105
98
|
this.websites = [...website];
|
|
106
99
|
}
|
|
107
100
|
}
|
|
108
|
-
checkRequest(context) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return false;
|
|
117
|
-
});
|
|
101
|
+
async checkRequest(context) {
|
|
102
|
+
let httpContext = context.getHttpContext();
|
|
103
|
+
if (this.websites.indexOf(httpContext.origin) >= 0 ||
|
|
104
|
+
this.websites.indexOf(httpContext.host) >= 0 ||
|
|
105
|
+
this.websites.indexOf("*") >= 0) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
118
109
|
}
|
|
119
110
|
}
|
|
120
|
-
exports.WebsiteOriginFilter = WebsiteOriginFilter;
|
|
121
111
|
const beans = {};
|
|
122
112
|
// @Bean to declare as a Singleton service
|
|
123
|
-
function Bean(constructor) {
|
|
113
|
+
export function Bean(constructor) {
|
|
124
114
|
let name = constructor.name.toLowerCase();
|
|
125
115
|
beans[name] = beans[name] || { constructor };
|
|
126
|
-
beans[name] =
|
|
127
|
-
}
|
|
128
|
-
exports.Bean = Bean;
|
|
129
|
-
// @Route to declare route on Bean
|
|
130
|
-
function Route(route, methods = ["GET"], allowPath = false, openapi = {}) {
|
|
131
|
-
return function (target, executor) {
|
|
132
|
-
let targetName = target.constructor.name.toLowerCase();
|
|
133
|
-
beans[targetName] = beans[targetName] || {
|
|
134
|
-
constructor: target.constructor
|
|
135
|
-
};
|
|
136
|
-
beans[targetName].routes = beans[targetName].routes || {};
|
|
137
|
-
beans[targetName].routes[route] = beans[targetName].routes[route] || [];
|
|
138
|
-
beans[targetName].routes[route].push({
|
|
139
|
-
methods: Array.isArray(methods) ? methods : [methods],
|
|
140
|
-
executor,
|
|
141
|
-
allowPath,
|
|
142
|
-
openapi
|
|
143
|
-
});
|
|
144
|
-
};
|
|
116
|
+
beans[name] = { ...beans[name], bean: true };
|
|
145
117
|
}
|
|
146
|
-
exports.Route = Route;
|
|
147
118
|
/**
|
|
148
119
|
* This is the main class of the framework, it handles the routing, the services initialization and resolution
|
|
149
120
|
*
|
|
150
121
|
* @class Core
|
|
151
122
|
* @category CoreFeatures
|
|
152
123
|
*/
|
|
153
|
-
class Core extends events.EventEmitter {
|
|
124
|
+
export class Core extends events.EventEmitter {
|
|
154
125
|
/**
|
|
155
126
|
* @params {Object} config - The configuration Object, if undefined will load the configuration file
|
|
156
127
|
*/
|
|
157
128
|
constructor(application) {
|
|
158
129
|
var _a, _b, _c;
|
|
159
|
-
var _d, _e, _f;
|
|
160
130
|
/** @ignore */
|
|
161
131
|
super();
|
|
162
132
|
/**
|
|
@@ -167,7 +137,7 @@ class Core extends events.EventEmitter {
|
|
|
167
137
|
/**
|
|
168
138
|
* Router that will route http request in
|
|
169
139
|
*/
|
|
170
|
-
this.router = new
|
|
140
|
+
this.router = new Router(this);
|
|
171
141
|
/**
|
|
172
142
|
* If Core is already initiated
|
|
173
143
|
*/
|
|
@@ -191,21 +161,21 @@ class Core extends events.EventEmitter {
|
|
|
191
161
|
*/
|
|
192
162
|
this._requestCORSFilters = [];
|
|
193
163
|
this.workerOutput = application.getWorkerOutput();
|
|
194
|
-
this.logger = new
|
|
164
|
+
this.logger = new Logger(this.workerOutput, "@webda/core/lib/core.js");
|
|
195
165
|
this.application = application;
|
|
196
166
|
this._initTime = new Date().getTime();
|
|
197
167
|
// Schema validations
|
|
198
|
-
this._ajv = new
|
|
199
|
-
(
|
|
168
|
+
this._ajv = new Ajv();
|
|
169
|
+
addFormats(this._ajv);
|
|
200
170
|
this._ajvSchemas = {};
|
|
201
171
|
// Load the configuration and migrate
|
|
202
172
|
this.configuration = this.application.getCurrentConfiguration();
|
|
203
173
|
// Set the global context
|
|
204
|
-
|
|
174
|
+
Context.setGlobalContext(new (this.getModel(this.parameter("contextModel") || "Webda/Context"))(this));
|
|
205
175
|
// Init default values for configuration
|
|
206
|
-
(_a =
|
|
207
|
-
(_b =
|
|
208
|
-
(_c =
|
|
176
|
+
(_a = this.configuration).parameters ?? (_a.parameters = {});
|
|
177
|
+
(_b = this.configuration.parameters).apiUrl ?? (_b.apiUrl = "http://localhost:18080");
|
|
178
|
+
(_c = this.configuration).services ?? (_c.services = {});
|
|
209
179
|
// Add CSRF origins filtering
|
|
210
180
|
if (this.configuration.parameters.csrfOrigins) {
|
|
211
181
|
this.registerCORSFilter(new OriginFilter(this.configuration.parameters.csrfOrigins));
|
|
@@ -221,8 +191,7 @@ class Core extends events.EventEmitter {
|
|
|
221
191
|
* It is a random generated string
|
|
222
192
|
*/
|
|
223
193
|
getInstanceId() {
|
|
224
|
-
|
|
225
|
-
(_a = this.instanceId) !== null && _a !== void 0 ? _a : (this.instanceId = this.getUuid());
|
|
194
|
+
this.instanceId ?? (this.instanceId = this.getUuid());
|
|
226
195
|
return this.instanceId;
|
|
227
196
|
}
|
|
228
197
|
/**
|
|
@@ -246,21 +215,6 @@ class Core extends events.EventEmitter {
|
|
|
246
215
|
getAppPath(subpath = "") {
|
|
247
216
|
return this.application.getAppPath(subpath);
|
|
248
217
|
}
|
|
249
|
-
/**
|
|
250
|
-
* Reinit the @Route
|
|
251
|
-
*/
|
|
252
|
-
reinitResolvedRoutes() {
|
|
253
|
-
for (let i in beans) {
|
|
254
|
-
if (beans[i].routes) {
|
|
255
|
-
for (let j in beans[i].routes) {
|
|
256
|
-
beans[i].routes[j].forEach(r => {
|
|
257
|
-
r.resolved = false;
|
|
258
|
-
this.router.removeRoute(j, r.info);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
218
|
/**
|
|
265
219
|
* Retrieve all detected modules definition
|
|
266
220
|
*/
|
|
@@ -283,109 +237,82 @@ class Core extends events.EventEmitter {
|
|
|
283
237
|
* Init one service
|
|
284
238
|
* @param service
|
|
285
239
|
*/
|
|
286
|
-
initService(service) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
this.log("ERROR", "Init service " + service + " failed: " + err.message);
|
|
299
|
-
this.log("TRACE", err.stack);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
240
|
+
async initService(service) {
|
|
241
|
+
try {
|
|
242
|
+
this.log("TRACE", "Initializing service", service);
|
|
243
|
+
this.services[service]._initTime = Date.now();
|
|
244
|
+
await this.services[service].init();
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
this.services[service]._initException = err;
|
|
248
|
+
this.failedServices[service] = { _initException: err };
|
|
249
|
+
this.log("ERROR", "Init service " + service + " failed: " + err.message);
|
|
250
|
+
this.log("TRACE", err.stack);
|
|
251
|
+
}
|
|
302
252
|
}
|
|
303
253
|
/**
|
|
304
254
|
* Get an object from the application based on its full uuid
|
|
305
255
|
* @param fullUuid
|
|
306
256
|
* @param partials
|
|
307
257
|
*/
|
|
308
|
-
getModelObject(fullUuid, partials) {
|
|
309
|
-
return
|
|
310
|
-
return coremodel_1.CoreModel.fromFullUuid(this, fullUuid, partials);
|
|
311
|
-
});
|
|
258
|
+
async getModelObject(fullUuid, partials) {
|
|
259
|
+
return CoreModel.fromFullUuid(this, fullUuid, partials);
|
|
312
260
|
}
|
|
313
261
|
/**
|
|
314
262
|
* Init Webda
|
|
315
263
|
*
|
|
316
264
|
* It will resolve Services init method and autolink
|
|
317
265
|
*/
|
|
318
|
-
init() {
|
|
319
|
-
var _a, _b
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.configuration.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
266
|
+
async init() {
|
|
267
|
+
var _a, _b;
|
|
268
|
+
if (this._init) {
|
|
269
|
+
return this._init;
|
|
270
|
+
}
|
|
271
|
+
if (this.configuration.parameters.configurationService) {
|
|
272
|
+
try {
|
|
273
|
+
this.log("INFO", "Create and init ConfigurationService", this.configuration.parameters.configurationService);
|
|
274
|
+
// Create the configuration service
|
|
275
|
+
this.createService(this.configuration.services, this.configuration.parameters.configurationService);
|
|
276
|
+
let cfg = await this.getService(this.configuration.parameters.configurationService).initConfiguration();
|
|
277
|
+
if (cfg.webda) {
|
|
278
|
+
(_a = cfg.webda).parameters ?? (_a.parameters = {});
|
|
279
|
+
(_b = cfg.webda).services ?? (_b.services = {});
|
|
280
|
+
this.configuration.parameters = { ...this.configuration.parameters, ...cfg.webda.parameters };
|
|
281
|
+
for (let i in this.configuration.services) {
|
|
282
|
+
this.configuration.services[i] = {
|
|
283
|
+
...deepmerge(this.configuration.services[i], cfg.webda.services[i] || {}),
|
|
284
|
+
type: this.configuration.services[i].type
|
|
285
|
+
};
|
|
338
286
|
}
|
|
339
|
-
yield this.getService(this.configuration.parameters.configurationService).init();
|
|
340
|
-
}
|
|
341
|
-
catch (err) {
|
|
342
|
-
this.log("ERROR", "Cannot use ConfigurationService", this.configuration.parameters.configurationService, err);
|
|
343
|
-
this.services = {};
|
|
344
287
|
}
|
|
288
|
+
await this.getService(this.configuration.parameters.configurationService).init();
|
|
345
289
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
this.
|
|
356
|
-
|
|
357
|
-
// Init
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
(_e = (_k = this.configuration.services)["SessionManager"]) !== null && _e !== void 0 ? _e : (_k["SessionManager"] = {
|
|
366
|
-
type: "webda/cookiesessionmanager"
|
|
367
|
-
});
|
|
368
|
-
// Init the other services
|
|
369
|
-
this.initStatics();
|
|
370
|
-
this.reinitResolvedRoutes();
|
|
371
|
-
this.log("TRACE", "Create Webda init promise");
|
|
372
|
-
this._init = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
373
|
-
// Init services
|
|
374
|
-
let service;
|
|
375
|
-
let inits = [];
|
|
376
|
-
for (service in this.services) {
|
|
377
|
-
if (this.services[service].init !== undefined &&
|
|
378
|
-
!this.services[service]._createException &&
|
|
379
|
-
!this.services[service]._initTime) {
|
|
380
|
-
inits.push(this.initService(service));
|
|
381
|
-
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
this.log("ERROR", "Cannot use ConfigurationService", this.configuration.parameters.configurationService, err);
|
|
292
|
+
this.services = {};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// Init the other services
|
|
296
|
+
this.initStatics();
|
|
297
|
+
this.log("TRACE", "Create Webda init promise");
|
|
298
|
+
this._init = new Promise(async (resolve) => {
|
|
299
|
+
await this.initService("registry");
|
|
300
|
+
await this.initService("cryptoservice");
|
|
301
|
+
// Init services
|
|
302
|
+
let service;
|
|
303
|
+
let inits = [];
|
|
304
|
+
for (service in this.services) {
|
|
305
|
+
if (this.services[service].init !== undefined &&
|
|
306
|
+
!this.services[service]._createException &&
|
|
307
|
+
!this.services[service]._initTime) {
|
|
308
|
+
inits.push(this.initService(service));
|
|
382
309
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return this._init;
|
|
310
|
+
}
|
|
311
|
+
await Promise.all(inits);
|
|
312
|
+
await this.emitSync("Webda.Init.Services", this.services);
|
|
313
|
+
resolve();
|
|
388
314
|
});
|
|
315
|
+
return this._init;
|
|
389
316
|
}
|
|
390
317
|
/**
|
|
391
318
|
* Register a request filtering
|
|
@@ -405,46 +332,36 @@ class Core extends events.EventEmitter {
|
|
|
405
332
|
registerCORSFilter(filter) {
|
|
406
333
|
this._requestCORSFilters.push(filter);
|
|
407
334
|
}
|
|
408
|
-
/**
|
|
409
|
-
*
|
|
410
|
-
* @param {Object} executor The executor to expose as executor
|
|
411
|
-
* @param {String} code to execute
|
|
412
|
-
*/
|
|
413
|
-
sandbox(code, context) {
|
|
414
|
-
context !== null && context !== void 0 ? context : (context = {
|
|
415
|
-
require: () => {
|
|
416
|
-
throw Error("not allowed");
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
context.module = {
|
|
420
|
-
exports: {}
|
|
421
|
-
};
|
|
422
|
-
vm.runInNewContext(code, context);
|
|
423
|
-
return context.module.exports();
|
|
424
|
-
}
|
|
425
335
|
/**
|
|
426
336
|
* Validate the object with schema
|
|
427
337
|
*
|
|
428
338
|
* @param schema path to use
|
|
429
339
|
* @param object to validate
|
|
430
340
|
*/
|
|
431
|
-
validateSchema(webdaObject, object) {
|
|
341
|
+
validateSchema(webdaObject, object, ignoreRequired) {
|
|
432
342
|
let name = typeof webdaObject === "string"
|
|
433
343
|
? webdaObject
|
|
434
344
|
: this.application.getFullNameFromPrototype(Object.getPrototypeOf(webdaObject));
|
|
435
|
-
|
|
345
|
+
let cacheName = name;
|
|
346
|
+
if (ignoreRequired) {
|
|
347
|
+
cacheName += "_noRequired";
|
|
348
|
+
}
|
|
349
|
+
if (!this._ajvSchemas[cacheName]) {
|
|
436
350
|
let schema = this.application.getSchema(name);
|
|
437
351
|
if (!schema) {
|
|
438
352
|
return null;
|
|
439
353
|
}
|
|
354
|
+
if (ignoreRequired) {
|
|
355
|
+
schema.required = [];
|
|
356
|
+
}
|
|
440
357
|
this.log("TRACE", "Add schema for", name);
|
|
441
|
-
this._ajv.addSchema(schema,
|
|
442
|
-
this._ajvSchemas[
|
|
358
|
+
this._ajv.addSchema(schema, cacheName);
|
|
359
|
+
this._ajvSchemas[cacheName] = true;
|
|
443
360
|
}
|
|
444
|
-
if (this._ajv.validate(
|
|
361
|
+
if (this._ajv.validate(cacheName, object)) {
|
|
445
362
|
return true;
|
|
446
363
|
}
|
|
447
|
-
throw new
|
|
364
|
+
throw new ValidationError(this._ajv.errors);
|
|
448
365
|
}
|
|
449
366
|
/**
|
|
450
367
|
* Return webda current version
|
|
@@ -481,7 +398,7 @@ class Core extends events.EventEmitter {
|
|
|
481
398
|
}
|
|
482
399
|
}
|
|
483
400
|
}
|
|
484
|
-
return new
|
|
401
|
+
return new Logger(this.workerOutput, className);
|
|
485
402
|
}
|
|
486
403
|
/**
|
|
487
404
|
* Add a route dynamicaly
|
|
@@ -545,7 +462,7 @@ class Core extends events.EventEmitter {
|
|
|
545
462
|
* @returns {{}}
|
|
546
463
|
*/
|
|
547
464
|
getStores() {
|
|
548
|
-
return this.getServicesOfType(
|
|
465
|
+
return this.getServicesOfType(Store);
|
|
549
466
|
}
|
|
550
467
|
/**
|
|
551
468
|
* Return a map of defined models
|
|
@@ -568,11 +485,11 @@ class Core extends events.EventEmitter {
|
|
|
568
485
|
updateContextWithRoute(ctx) {
|
|
569
486
|
let http = ctx.getHttpContext();
|
|
570
487
|
// Check mapping
|
|
571
|
-
|
|
488
|
+
let route = this.router.getRouteFromUrl(ctx, http.getMethod(), http.getRelativeUri());
|
|
572
489
|
if (route === undefined) {
|
|
573
490
|
return false;
|
|
574
491
|
}
|
|
575
|
-
ctx.setRoute(
|
|
492
|
+
ctx.setRoute({ ...this.configuration, ...route });
|
|
576
493
|
ctx.setExecutor(this.getService(route.executor));
|
|
577
494
|
return true;
|
|
578
495
|
}
|
|
@@ -608,41 +525,37 @@ class Core extends events.EventEmitter {
|
|
|
608
525
|
* Reinit one service
|
|
609
526
|
* @param service
|
|
610
527
|
*/
|
|
611
|
-
reinitService(service) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
}
|
|
622
|
-
});
|
|
528
|
+
async reinitService(service) {
|
|
529
|
+
try {
|
|
530
|
+
this.log("TRACE", "Re-Initializing service", service);
|
|
531
|
+
let serviceBean = this.services[service];
|
|
532
|
+
await serviceBean.reinit(this.getServiceParams(serviceBean.getName()));
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
this.log("ERROR", "Re-Init service " + service + " failed", err);
|
|
536
|
+
this.log("TRACE", err.stack);
|
|
537
|
+
}
|
|
623
538
|
}
|
|
624
539
|
/**
|
|
625
540
|
* Reinit all services with updated parameters
|
|
626
541
|
* @param updates
|
|
627
542
|
* @returns
|
|
628
543
|
*/
|
|
629
|
-
reinit(updates) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
yield Promise.all(inits);
|
|
645
|
-
});
|
|
544
|
+
async reinit(updates) {
|
|
545
|
+
let configuration = JSON.parse(JSON.stringify(this.configuration.services));
|
|
546
|
+
for (let service in updates) {
|
|
547
|
+
jsonpath.value(configuration, service, updates[service]);
|
|
548
|
+
}
|
|
549
|
+
if (JSON.stringify(Object.keys(configuration)) !== JSON.stringify(Object.keys(this.configuration.services))) {
|
|
550
|
+
this.log("ERROR", "Configuration update cannot modify services");
|
|
551
|
+
throw new WebdaError("REINIT_SERVICE_INJECTION", "Configuration is not designed to add dynamically services");
|
|
552
|
+
}
|
|
553
|
+
this.configuration.services = configuration;
|
|
554
|
+
let inits = [];
|
|
555
|
+
for (let service in this.services) {
|
|
556
|
+
inits.push(this.reinitService(service));
|
|
557
|
+
}
|
|
558
|
+
await Promise.all(inits);
|
|
646
559
|
}
|
|
647
560
|
/**
|
|
648
561
|
* Get a full resolved service parameter
|
|
@@ -652,21 +565,20 @@ class Core extends events.EventEmitter {
|
|
|
652
565
|
* @returns
|
|
653
566
|
*/
|
|
654
567
|
getServiceParams(service, configuration = { parameters: {}, services: {} }) {
|
|
655
|
-
var _a
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
(
|
|
659
|
-
|
|
660
|
-
const params = (0, deepmerge_ts_1.deepmerge)(this.configuration.parameters || {}, configuration.parameters || {}, this.configuration.services[service] || {}, configuration.services[service] || {});
|
|
568
|
+
var _a;
|
|
569
|
+
configuration.parameters ?? (configuration.parameters = {});
|
|
570
|
+
configuration.services ?? (configuration.services = {});
|
|
571
|
+
(_a = configuration.services)[service] ?? (_a[service] = {});
|
|
572
|
+
const params = deepmerge(this.configuration.parameters || {}, configuration.parameters || {}, this.configuration.services[service] || {}, configuration.services[service] || {});
|
|
661
573
|
delete params.require;
|
|
662
574
|
return params;
|
|
663
575
|
}
|
|
664
576
|
createService(services, service) {
|
|
665
|
-
|
|
577
|
+
let type = services[service].type;
|
|
666
578
|
if (type === undefined) {
|
|
667
579
|
type = service;
|
|
668
580
|
}
|
|
669
|
-
|
|
581
|
+
let serviceConstructor = undefined;
|
|
670
582
|
try {
|
|
671
583
|
serviceConstructor = this.application.getModda(type);
|
|
672
584
|
}
|
|
@@ -693,9 +605,6 @@ class Core extends events.EventEmitter {
|
|
|
693
605
|
const services = this.configuration.services;
|
|
694
606
|
this.log("DEBUG", beans);
|
|
695
607
|
for (let i in beans) {
|
|
696
|
-
if (!beans[i].bean) {
|
|
697
|
-
this.log("DEBUG", "Implicit @Bean due to a @Route", beans[i].constructor.name);
|
|
698
|
-
}
|
|
699
608
|
let name = beans[i].constructor.name;
|
|
700
609
|
if (!services[name]) {
|
|
701
610
|
services[name] = {};
|
|
@@ -732,7 +641,7 @@ class Core extends events.EventEmitter {
|
|
|
732
641
|
* @returns
|
|
733
642
|
*/
|
|
734
643
|
getRegistry() {
|
|
735
|
-
return this.
|
|
644
|
+
return this.registry;
|
|
736
645
|
}
|
|
737
646
|
/**
|
|
738
647
|
* Return the crypto service
|
|
@@ -777,39 +686,42 @@ class Core extends events.EventEmitter {
|
|
|
777
686
|
* Init services and Beans along with Routes
|
|
778
687
|
*/
|
|
779
688
|
initStatics() {
|
|
689
|
+
var _a, _b, _c;
|
|
690
|
+
// Init the registry
|
|
691
|
+
const autoRegistry = this.configuration.services["Registry"] === undefined;
|
|
692
|
+
(_a = this.configuration.services)["Registry"] ?? (_a["Registry"] = {
|
|
693
|
+
type: "webda/memorystore",
|
|
694
|
+
persistence: {
|
|
695
|
+
path: ".registry",
|
|
696
|
+
key: machineIdSync()
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
this.createService(this.configuration.services, "Registry");
|
|
700
|
+
this.registry = this.getService("Registry").resolve();
|
|
701
|
+
// Init the key service
|
|
702
|
+
(_b = this.configuration.services)["CryptoService"] ?? (_b["CryptoService"] = {
|
|
703
|
+
type: "webda/cryptoservice",
|
|
704
|
+
autoRotate: autoRegistry ? 30 : undefined,
|
|
705
|
+
autoCreate: true
|
|
706
|
+
});
|
|
707
|
+
this.createService(this.configuration.services, "CryptoService");
|
|
708
|
+
this.cryptoService = this.getService("CryptoService").resolve();
|
|
709
|
+
// Session Manager
|
|
710
|
+
(_c = this.configuration.services)["SessionManager"] ?? (_c["SessionManager"] = {
|
|
711
|
+
type: "webda/cookiesessionmanager"
|
|
712
|
+
});
|
|
780
713
|
if (this.configuration.services !== undefined) {
|
|
714
|
+
let excludes = ["registry", "cryptoservice"];
|
|
715
|
+
if (this.configuration.parameters.configurationService) {
|
|
716
|
+
excludes.push(this.configuration.parameters.configurationService.toLowerCase());
|
|
717
|
+
}
|
|
781
718
|
// Do not recreate the configuration services
|
|
782
|
-
this.createServices(
|
|
719
|
+
this.createServices(excludes);
|
|
783
720
|
}
|
|
784
721
|
this.router.remapRoutes();
|
|
785
722
|
this._initiated = true;
|
|
786
723
|
this.emit("Webda.Init", this.configuration);
|
|
787
724
|
}
|
|
788
|
-
/**
|
|
789
|
-
* Init Routes declare by @Route annotation
|
|
790
|
-
*/
|
|
791
|
-
initBeanRoutes(serviceBean) {
|
|
792
|
-
let service = serviceBean.getName().toLowerCase();
|
|
793
|
-
if (beans[service] !== undefined && beans[service].routes) {
|
|
794
|
-
for (let j in beans[service].routes) {
|
|
795
|
-
this.log("TRACE", "Adding route", j, "for bean", service);
|
|
796
|
-
beans[service].routes[j].forEach(route => {
|
|
797
|
-
if (route.resolved) {
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
route.info = {
|
|
801
|
-
methods: route.methods,
|
|
802
|
-
_method: this.services[service][route.executor],
|
|
803
|
-
allowPath: route.allowPath || false,
|
|
804
|
-
openapi: route.openapi,
|
|
805
|
-
executor: beans[service].constructor.name // Name of the service
|
|
806
|
-
};
|
|
807
|
-
this.addRoute(j, route.info);
|
|
808
|
-
route.resolved = true;
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
725
|
/**
|
|
814
726
|
* Create a new context for a request
|
|
815
727
|
*
|
|
@@ -818,15 +730,13 @@ class Core extends events.EventEmitter {
|
|
|
818
730
|
* @param stream - The request output stream if any
|
|
819
731
|
* @return A new context object to pass along
|
|
820
732
|
*/
|
|
821
|
-
newContext(httpContext, stream = undefined, noInit = false) {
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
return res;
|
|
829
|
-
});
|
|
733
|
+
async newContext(httpContext, stream = undefined, noInit = false) {
|
|
734
|
+
let res = (new (this.getModel(this.parameter("contextModel") || "Webda/Context"))(this, httpContext, stream));
|
|
735
|
+
if (!noInit) {
|
|
736
|
+
await res.init();
|
|
737
|
+
}
|
|
738
|
+
await this.emitSync("Webda.NewContext", res);
|
|
739
|
+
return res;
|
|
830
740
|
}
|
|
831
741
|
/**
|
|
832
742
|
* Convert an object to JSON using the Webda json filter
|
|
@@ -846,10 +756,10 @@ class Core extends events.EventEmitter {
|
|
|
846
756
|
*/
|
|
847
757
|
getUuid(format = "uuid") {
|
|
848
758
|
if (format === "uuid") {
|
|
849
|
-
return (
|
|
759
|
+
return uuidv4().toString();
|
|
850
760
|
}
|
|
851
761
|
let buffer = Buffer.alloc(16);
|
|
852
|
-
(
|
|
762
|
+
uuidv4(undefined, buffer);
|
|
853
763
|
if (format === "base64") {
|
|
854
764
|
// Remove useless = we won't transfer back to original value or could just add ==
|
|
855
765
|
// https://datatracker.ietf.org/doc/html/rfc4648#page-7
|
|
@@ -867,9 +777,9 @@ class Core extends events.EventEmitter {
|
|
|
867
777
|
* Emit the event with data and wait for Promise to finish if listener returned a Promise
|
|
868
778
|
*/
|
|
869
779
|
emitSync(eventType, event, ...data) {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
780
|
+
let result;
|
|
781
|
+
let promises = [];
|
|
782
|
+
let listeners = this.listeners(eventType);
|
|
873
783
|
for (let listener of listeners) {
|
|
874
784
|
result = listener(event, ...data);
|
|
875
785
|
if (result instanceof Promise) {
|
|
@@ -908,28 +818,23 @@ class Core extends events.EventEmitter {
|
|
|
908
818
|
*
|
|
909
819
|
* @param context Context of the request
|
|
910
820
|
*/
|
|
911
|
-
checkRequest(ctx) {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
return (yield Promise.all(this._requestFilters.map(filter => filter.checkRequest(ctx)))).some(v => v);
|
|
918
|
-
});
|
|
821
|
+
async checkRequest(ctx) {
|
|
822
|
+
// Do not need to filter on OPTIONS as CORS is for that
|
|
823
|
+
if (ctx.getHttpContext().getMethod() === "OPTIONS") {
|
|
824
|
+
return true;
|
|
825
|
+
}
|
|
826
|
+
return (await Promise.all(this._requestFilters.map(filter => filter.checkRequest(ctx)))).some(v => v);
|
|
919
827
|
}
|
|
920
828
|
/**
|
|
921
829
|
* Verify if an origin is allowed to do request on the API
|
|
922
830
|
*
|
|
923
831
|
* @param context Context of the request
|
|
924
832
|
*/
|
|
925
|
-
checkCORSRequest(ctx) {
|
|
926
|
-
return
|
|
927
|
-
return (yield Promise.all(this._requestCORSFilters.map(filter => filter.checkRequest(ctx)))).some(v => v);
|
|
928
|
-
});
|
|
833
|
+
async checkCORSRequest(ctx) {
|
|
834
|
+
return (await Promise.all(this._requestCORSFilters.map(filter => filter.checkRequest(ctx)))).some(v => v);
|
|
929
835
|
}
|
|
930
836
|
exportOpenAPI(skipHidden = true) {
|
|
931
837
|
var _a;
|
|
932
|
-
var _b;
|
|
933
838
|
let packageInfo = this.application.getPackageDescription();
|
|
934
839
|
let contact;
|
|
935
840
|
if (typeof packageInfo.author === "string") {
|
|
@@ -949,7 +854,7 @@ class Core extends events.EventEmitter {
|
|
|
949
854
|
else if (packageInfo.license) {
|
|
950
855
|
license = packageInfo.license;
|
|
951
856
|
}
|
|
952
|
-
let openapi =
|
|
857
|
+
let openapi = deepmerge({
|
|
953
858
|
openapi: "3.0.3",
|
|
954
859
|
info: {
|
|
955
860
|
description: packageInfo.description,
|
|
@@ -959,11 +864,11 @@ class Core extends events.EventEmitter {
|
|
|
959
864
|
contact,
|
|
960
865
|
license
|
|
961
866
|
},
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
867
|
+
components: {
|
|
868
|
+
schemas: {
|
|
869
|
+
Object: {
|
|
870
|
+
type: "object"
|
|
871
|
+
}
|
|
967
872
|
}
|
|
968
873
|
},
|
|
969
874
|
paths: {},
|
|
@@ -976,21 +881,30 @@ class Core extends events.EventEmitter {
|
|
|
976
881
|
type: "object"
|
|
977
882
|
};
|
|
978
883
|
let modelDescription = this.getModel(i);
|
|
884
|
+
let modelName = model.name || i.split("/").pop();
|
|
979
885
|
// Only export CoreModel info
|
|
980
|
-
if (!this.application.extends(modelDescription,
|
|
886
|
+
if (!this.application.extends(modelDescription, CoreModel)) {
|
|
981
887
|
continue;
|
|
982
888
|
}
|
|
983
889
|
let schema = this.application.getSchema(i);
|
|
984
890
|
if (schema) {
|
|
985
891
|
for (let j in schema.definitions) {
|
|
986
892
|
// @ts-ignore
|
|
987
|
-
(_a =
|
|
893
|
+
(_a = openapi.components.schemas)[j] ?? (_a[j] = schema.definitions[j]);
|
|
988
894
|
}
|
|
989
895
|
delete schema.definitions;
|
|
990
896
|
desc = schema;
|
|
991
897
|
}
|
|
992
|
-
//
|
|
993
|
-
|
|
898
|
+
// Remove empty required as openapi does not like that
|
|
899
|
+
// Our compiler is not generating this anymore but it is additional protection
|
|
900
|
+
/* c8 ignore next 3 */
|
|
901
|
+
if (desc.required && desc.required.length === 0) {
|
|
902
|
+
delete desc.required;
|
|
903
|
+
}
|
|
904
|
+
// Remove $schema
|
|
905
|
+
delete desc.$schema;
|
|
906
|
+
// Rename all #/definitions/ by #/components/schemas/
|
|
907
|
+
openapi.components.schemas[modelName] = JSON.parse(JSON.stringify(desc).replace(/#\/definitions\//g, "#/components/schemas/"));
|
|
994
908
|
}
|
|
995
909
|
this.router.completeOpenAPI(openapi, skipHidden);
|
|
996
910
|
openapi.tags.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
@@ -1002,5 +916,4 @@ class Core extends events.EventEmitter {
|
|
|
1002
916
|
return openapi;
|
|
1003
917
|
}
|
|
1004
918
|
}
|
|
1005
|
-
exports.Core = Core;
|
|
1006
919
|
//# sourceMappingURL=core.js.map
|