@webda/core 1.6.0-beta.3 → 2.0.0-beta.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 +317 -195
- package/lib/application.js +171 -679
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +97 -289
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +102 -214
- package/lib/core.js +145 -68
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +78 -15
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +8 -1
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +3 -1
- package/lib/models/aclmodel.js +3 -1
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +4 -1
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +9 -17
- package/lib/models/coremodel.js +36 -36
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +2 -1
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ownermodel.d.ts +8 -4
- package/lib/models/ownermodel.js +9 -4
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +4 -1
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +4 -3
- package/lib/models/user.js +2 -1
- package/lib/models/user.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -7
- package/lib/queues/filequeue.js +2 -11
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +0 -1
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -7
- package/lib/queues/memoryqueue.js +1 -11
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +11 -9
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.js +1 -1
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +46 -1
- package/lib/router.js +89 -51
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +18 -1
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +1 -0
- package/lib/services/asyncevents.js +4 -3
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/authentication.d.ts +12 -4
- package/lib/services/authentication.js +47 -36
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +1 -0
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +126 -64
- package/lib/services/binary.js +243 -92
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +1 -0
- package/lib/services/binary.spec.js +96 -25
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +67 -0
- package/lib/services/cloudbinary.js +178 -0
- package/lib/services/cloudbinary.js.map +1 -0
- package/lib/services/cloudbinary.spec.d.ts +13 -0
- package/lib/services/cloudbinary.spec.js +205 -0
- package/lib/services/cloudbinary.spec.js.map +1 -0
- package/lib/services/configuration.d.ts +7 -2
- package/lib/services/configuration.js +4 -3
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +1 -0
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +5 -6
- package/lib/services/cron.js +4 -11
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +0 -1
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/debugmailer.d.ts +3 -5
- package/lib/services/debugmailer.js +3 -11
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/echo.d.ts +2 -6
- package/lib/services/echo.js +1 -11
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +1 -0
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +36 -12
- package/lib/services/filebinary.js +123 -38
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +4 -2
- package/lib/services/filebinary.spec.js +48 -7
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -5
- package/lib/services/fileconfiguration.js +1 -10
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/invitationservice.d.ts +2 -0
- package/lib/services/invitationservice.js +3 -1
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +1 -0
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +3 -5
- package/lib/services/kubernetesconfiguration.js +5 -12
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +1 -1
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +1 -5
- package/lib/services/mailer.js +1 -10
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/notificationservice.d.ts +2 -0
- package/lib/services/notificationservice.js +2 -0
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/oauth.d.ts +6 -4
- package/lib/services/oauth.js +28 -11
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/resource.d.ts +1 -5
- package/lib/services/resource.js +22 -17
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +0 -1
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +19 -22
- package/lib/services/service.js +16 -22
- package/lib/services/service.js.map +1 -1
- package/lib/services/version.d.ts +2 -5
- package/lib/services/version.js +1 -10
- package/lib/services/version.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -5
- package/lib/stores/aggregator.js +3 -10
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +7 -8
- package/lib/stores/file.js +18 -18
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.js +3 -2
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +1 -5
- package/lib/stores/mapper.js +4 -13
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +1 -1
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +5 -9
- package/lib/stores/memory.js +5 -17
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +1 -0
- package/lib/stores/memory.spec.js +32 -0
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +131 -26
- package/lib/stores/store.js +387 -70
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +29 -2
- package/lib/stores/store.spec.js +204 -31
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +53 -0
- package/lib/stores/webdaql/WebdaQLLexer.js +290 -0
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -0
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +53 -0
- package/lib/stores/webdaql/WebdaQLParserLexer.js +290 -0
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -0
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +308 -0
- package/lib/stores/webdaql/WebdaQLParserListener.js +4 -0
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -0
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +301 -0
- package/lib/stores/webdaql/WebdaQLParserParser.js +1781 -0
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -0
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +198 -0
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +4 -0
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -0
- package/lib/stores/webdaql/query.d.ts +300 -0
- package/lib/stores/webdaql/query.js +471 -0
- package/lib/stores/webdaql/query.js.map +1 -0
- package/lib/stores/webdaql/query.spec.d.ts +1 -0
- package/lib/stores/webdaql/query.spec.js +136 -0
- package/lib/stores/webdaql/query.spec.js.map +1 -0
- package/lib/test.d.ts +48 -1
- package/lib/test.js +141 -14
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +66 -0
- package/lib/unpackedapplication.js +202 -0
- package/lib/unpackedapplication.js.map +1 -0
- package/lib/utils/context.d.ts +13 -12
- package/lib/utils/context.js +7 -6
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/cookie.d.ts +6 -3
- package/lib/utils/cookie.js +5 -1
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/logger.d.ts +16 -3
- package/lib/utils/logger.js +16 -3
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +5 -1
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js.map +1 -1
- package/package.json +25 -18
- package/test/config-file-no-reload.json +2 -1
- package/test/config-file-reload.json +2 -1
- package/test/config-kube-reload.json +2 -1
- package/test/config-reload.json +1 -1
- package/test/config.json +6 -10
- package/test/config.old.json +1 -1
- package/test/moddas/annotatedservice.js +1 -3
- package/test/moddas/debugmailer.js +2 -7
- package/test/moddas/fakeservice.js +1 -1
- package/test/moddas/voidstore.js +2 -4
- package/test/models/ident.js +1 -1
- package/test/models/task.js +1 -5
- package/webda.module.json +1124 -0
- package/test/config.old-default.json +0 -151
package/lib/application.js
CHANGED
|
@@ -1,62 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
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
|
+
});
|
|
7
10
|
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Application = exports.
|
|
10
|
-
const child_process_1 = require("child_process");
|
|
12
|
+
exports.Application = exports.SectionEnum = void 0;
|
|
11
13
|
const fs = require("fs");
|
|
12
|
-
const glob = require("glob");
|
|
13
|
-
const merge = require("merge");
|
|
14
14
|
const path = require("path");
|
|
15
15
|
const index_1 = require("./index");
|
|
16
16
|
const workout_1 = require("@webda/workout");
|
|
17
|
-
const abstractdeployer_1 = require("./utils/abstractdeployer");
|
|
18
|
-
const deepmerge = require("deepmerge");
|
|
19
|
-
const semver = require("semver");
|
|
20
|
-
const dateFormat = require("dateformat");
|
|
21
17
|
const serializers_1 = require("./utils/serializers");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class DefaultSchemaResolver {
|
|
30
|
-
constructor(app) {
|
|
31
|
-
this.app = app;
|
|
32
|
-
}
|
|
33
|
-
fromServiceType(type = "") {
|
|
34
|
-
if (this.app.isCached()) {
|
|
35
|
-
return this.app.getConfiguration().cachedModules.schemas[type];
|
|
36
|
-
}
|
|
37
|
-
type = type.toLowerCase();
|
|
38
|
-
let proto = this.app.getDeployers()[type];
|
|
39
|
-
if (proto) {
|
|
40
|
-
return this.fromPrototype(proto);
|
|
41
|
-
}
|
|
42
|
-
proto = this.app.getServices()[type];
|
|
43
|
-
if (proto) {
|
|
44
|
-
return this.fromPrototype(proto);
|
|
45
|
-
}
|
|
46
|
-
proto = this.app.getModels()[type];
|
|
47
|
-
if (proto) {
|
|
48
|
-
return this.fromPrototype(proto);
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
fromPrototype(type) {
|
|
53
|
-
if (type && typeof type.getSchema === "function") {
|
|
54
|
-
return type.getSchema();
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.DefaultSchemaResolver = DefaultSchemaResolver;
|
|
18
|
+
var SectionEnum;
|
|
19
|
+
(function (SectionEnum) {
|
|
20
|
+
SectionEnum["Moddas"] = "moddas";
|
|
21
|
+
SectionEnum["Deployers"] = "deployers";
|
|
22
|
+
SectionEnum["Models"] = "models";
|
|
23
|
+
SectionEnum["Beans"] = "beans";
|
|
24
|
+
})(SectionEnum = exports.SectionEnum || (exports.SectionEnum = {}));
|
|
60
25
|
/**
|
|
61
26
|
* Map a Webda Application
|
|
62
27
|
*
|
|
@@ -76,21 +41,12 @@ class Application {
|
|
|
76
41
|
* @param {string} fileOrFolder to load Webda Application from
|
|
77
42
|
* @param {Logger} logger
|
|
78
43
|
*/
|
|
79
|
-
constructor(file, logger = undefined
|
|
80
|
-
/**
|
|
81
|
-
* Contains all definitions from imported modules and current code
|
|
82
|
-
*/
|
|
83
|
-
this.cachedModules = {
|
|
84
|
-
services: {},
|
|
85
|
-
models: {},
|
|
86
|
-
deployers: {},
|
|
87
|
-
sources: []
|
|
88
|
-
};
|
|
44
|
+
constructor(file, logger = undefined) {
|
|
89
45
|
/**
|
|
90
46
|
* Contains definitions of current application
|
|
91
47
|
*/
|
|
92
48
|
this.appModule = {
|
|
93
|
-
|
|
49
|
+
moddas: {},
|
|
94
50
|
models: {},
|
|
95
51
|
deployers: {}
|
|
96
52
|
};
|
|
@@ -103,58 +59,13 @@ class Application {
|
|
|
103
59
|
*/
|
|
104
60
|
this.deployers = {};
|
|
105
61
|
/**
|
|
106
|
-
*
|
|
62
|
+
* Moddas registry
|
|
107
63
|
*/
|
|
108
|
-
this.
|
|
109
|
-
// real service - modda
|
|
110
|
-
"webda/aggregator": index_1.AggregatorService,
|
|
111
|
-
"webda/asyncevents": index_1.EventService,
|
|
112
|
-
"webda/authentication": index_1.Authentication,
|
|
113
|
-
"webda/consolelogger": index_1.ConsoleLoggerService,
|
|
114
|
-
"webda/configurationservice": index_1.ConfigurationService,
|
|
115
|
-
"webda/cronservice": cron_1.CronService,
|
|
116
|
-
"webda/debugmailer": index_1.DebugMailer,
|
|
117
|
-
"webda/echoservice": echo_1.EchoService,
|
|
118
|
-
"webda/filebinary": index_1.FileBinary,
|
|
119
|
-
"webda/fileconfigurationservice": index_1.FileConfigurationService,
|
|
120
|
-
"webda/filequeue": index_1.FileQueue,
|
|
121
|
-
"webda/filestore": index_1.FileStore,
|
|
122
|
-
"webda/invitationservice": invitationservice_1.default,
|
|
123
|
-
"webda/kubernetesconfigurationservice": index_1.KubernetesConfigurationService,
|
|
124
|
-
"webda/mailer": index_1.Mailer,
|
|
125
|
-
"webda/mapper": index_1.MapperService,
|
|
126
|
-
"webda/memorylogger": index_1.MemoryLoggerService,
|
|
127
|
-
"webda/memoryqueue": index_1.MemoryQueue,
|
|
128
|
-
"webda/memorystore": index_1.MemoryStore,
|
|
129
|
-
"webda/multinotification": notificationservice_1.default,
|
|
130
|
-
"webda/resourceservice": index_1.ResourceService,
|
|
131
|
-
"webda/versionservice": index_1.VersionService
|
|
132
|
-
};
|
|
64
|
+
this.moddas = {};
|
|
133
65
|
/**
|
|
134
66
|
* Models type registry
|
|
135
67
|
*/
|
|
136
|
-
this.models = {
|
|
137
|
-
// Models
|
|
138
|
-
"webda/aclmodel": index_1.AclModel,
|
|
139
|
-
"webda/coremodel": index_1.CoreModel,
|
|
140
|
-
"webda/ident": index_1.Ident,
|
|
141
|
-
"webda/user": index_1.User,
|
|
142
|
-
"webdacore/context": index_1.Context,
|
|
143
|
-
"webdacore/securecookie": index_1.SecureCookie,
|
|
144
|
-
"webdacore/sessioncookie": index_1.SessionCookie
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Flag if application has been compiled already
|
|
148
|
-
*/
|
|
149
|
-
this.compiled = false;
|
|
150
|
-
/**
|
|
151
|
-
* Contains package.json of application
|
|
152
|
-
*/
|
|
153
|
-
this.packageDescription = {};
|
|
154
|
-
/**
|
|
155
|
-
* Contains webda section of package.json and workspaces if exist
|
|
156
|
-
*/
|
|
157
|
-
this.packageWebda = {};
|
|
68
|
+
this.models = {};
|
|
158
69
|
/**
|
|
159
70
|
* Detect if running as workspace
|
|
160
71
|
*/
|
|
@@ -162,90 +73,70 @@ class Application {
|
|
|
162
73
|
this.logger = logger || new workout_1.WorkerOutput();
|
|
163
74
|
this.initTime = Date.now();
|
|
164
75
|
if (!fs.existsSync(file)) {
|
|
165
|
-
throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.json file: unexisting ${file}`);
|
|
76
|
+
throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.jsonc or webda.config.json file: unexisting ${file}`);
|
|
166
77
|
}
|
|
167
78
|
if (fs.lstatSync(file).isDirectory()) {
|
|
168
|
-
file = path.join(file, "webda.config.
|
|
79
|
+
file = path.join(file, "webda.config.jsonc");
|
|
80
|
+
if (!fs.existsSync(file)) {
|
|
81
|
+
file = file.substring(0, file.length - 1);
|
|
82
|
+
}
|
|
169
83
|
}
|
|
84
|
+
this.configurationFile = file;
|
|
85
|
+
this.appPath = path.dirname(file);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Import all required modules
|
|
89
|
+
*/
|
|
90
|
+
load() {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
this.loadConfiguration(this.configurationFile);
|
|
93
|
+
yield this.loadModule(this.baseConfiguration.cachedModules);
|
|
94
|
+
return this;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Allow subclass to implement migration
|
|
99
|
+
*
|
|
100
|
+
* @param file
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
loadConfiguration(file) {
|
|
170
104
|
// Check if file is a file or folder
|
|
171
|
-
if (!fs.existsSync(file)
|
|
172
|
-
throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.json file: ${file}`);
|
|
105
|
+
if (!fs.existsSync(file)) {
|
|
106
|
+
throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.jsonc or webda.config.json file: ${file}`);
|
|
173
107
|
}
|
|
174
|
-
this.appPath = path.dirname(file);
|
|
175
108
|
try {
|
|
176
|
-
this.baseConfiguration =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.log("WARN", err);
|
|
180
|
-
if (allowModule) {
|
|
181
|
-
this.baseConfiguration = { version: 2, module: {} };
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
throw new index_1.WebdaError("INVALID_WEBDA_CONFIG", `Cannot parse JSON of: ${file}`);
|
|
109
|
+
this.baseConfiguration = serializers_1.FileUtils.load(file);
|
|
110
|
+
if (this.baseConfiguration.version !== 3) {
|
|
111
|
+
this.log("ERROR", "Your configuration file should use version 3, see https://docs.webda.io/");
|
|
185
112
|
}
|
|
186
113
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// Migrate if needed
|
|
190
|
-
if (!this.baseConfiguration.version) {
|
|
191
|
-
this.baseConfiguration = this.migrateV0Config(this.baseConfiguration);
|
|
192
|
-
}
|
|
193
|
-
if (this.baseConfiguration.version == 1) {
|
|
194
|
-
this.baseConfiguration = this.migrateV1Config(this.baseConfiguration);
|
|
195
|
-
}
|
|
196
|
-
// Load if a module definition is included
|
|
197
|
-
if (this.baseConfiguration.module) {
|
|
198
|
-
this.loadModule(this.baseConfiguration.module, this.appPath);
|
|
199
|
-
}
|
|
200
|
-
// Load cached modules if there
|
|
201
|
-
if (this.baseConfiguration.cachedModules) {
|
|
202
|
-
this.loadModule(this.baseConfiguration.cachedModules, this.appPath);
|
|
203
|
-
// Import all modules sources to include any annotation
|
|
204
|
-
if (this.baseConfiguration.cachedModules.sources) {
|
|
205
|
-
this.baseConfiguration.cachedModules.sources.forEach(src => {
|
|
206
|
-
require(path.join(process.cwd(), src));
|
|
207
|
-
});
|
|
208
|
-
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
throw new index_1.WebdaError("INVALID_WEBDA_CONFIG", `Cannot parse JSON of: ${file}`);
|
|
209
116
|
}
|
|
210
|
-
this.loadPackageInfos();
|
|
211
|
-
this.namespace = this.packageDescription.webda
|
|
212
|
-
? this.packageDescription.webda.namespace
|
|
213
|
-
: this.packageDescription.name | this.packageDescription.name;
|
|
214
117
|
}
|
|
215
118
|
/**
|
|
216
119
|
*
|
|
217
120
|
* @param proto Prototype to send
|
|
218
121
|
*/
|
|
219
122
|
getFullNameFromPrototype(proto) {
|
|
220
|
-
for (let
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
for (let i in this.deployers) {
|
|
226
|
-
if (this.deployers[i].prototype === proto) {
|
|
227
|
-
return i;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
for (let i in this.models) {
|
|
231
|
-
if (this.models[i].prototype === proto) {
|
|
232
|
-
return i;
|
|
123
|
+
for (let section in SectionEnum) {
|
|
124
|
+
for (let i in this[SectionEnum[section]]) {
|
|
125
|
+
if (this[SectionEnum[section]][i] && this[SectionEnum[section]][i].prototype === proto) {
|
|
126
|
+
return i;
|
|
127
|
+
}
|
|
233
128
|
}
|
|
234
129
|
}
|
|
235
130
|
}
|
|
236
131
|
/**
|
|
237
|
-
*
|
|
132
|
+
* Get a schema from a type
|
|
238
133
|
*
|
|
239
|
-
*
|
|
134
|
+
* Schema should be precomputed in the default app
|
|
135
|
+
* @param type
|
|
136
|
+
* @returns
|
|
240
137
|
*/
|
|
241
|
-
|
|
242
|
-
this.
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Get schema resolver
|
|
246
|
-
*/
|
|
247
|
-
getSchemaResolver() {
|
|
248
|
-
return this.schemaResolver;
|
|
138
|
+
getSchema(type) {
|
|
139
|
+
return this.baseConfiguration.cachedModules.schemas[type];
|
|
249
140
|
}
|
|
250
141
|
/**
|
|
251
142
|
* Check if application has cached modules
|
|
@@ -255,46 +146,7 @@ class Application {
|
|
|
255
146
|
* take the schema from the cached modules also
|
|
256
147
|
*/
|
|
257
148
|
isCached() {
|
|
258
|
-
return
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Check package.json
|
|
262
|
-
*/
|
|
263
|
-
loadPackageInfos() {
|
|
264
|
-
let packageJson = path.join(this.appPath, "package.json");
|
|
265
|
-
if (fs.existsSync(packageJson)) {
|
|
266
|
-
this.packageDescription = JSON.parse(fs.readFileSync(packageJson).toString());
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
this.log("WARN", "Application does not have a package.json");
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
this.packageWebda = this.packageDescription.webda || {};
|
|
273
|
-
let parent = path.join(this.appPath, "..");
|
|
274
|
-
do {
|
|
275
|
-
packageJson = path.join(parent, "package.json");
|
|
276
|
-
if (fs.existsSync(packageJson)) {
|
|
277
|
-
let info = JSON.parse(fs.readFileSync(packageJson).toString());
|
|
278
|
-
if (info.workspaces) {
|
|
279
|
-
this.log("DEBUG", "Application is running within a workspace");
|
|
280
|
-
this.workspacesPath = path.resolve(parent);
|
|
281
|
-
// Replace any relative path by absolute one
|
|
282
|
-
for (let i in info.webda) {
|
|
283
|
-
if (info.webda[i].startsWith("./")) {
|
|
284
|
-
info.webda[i] = path.resolve(parent) + "/" + info.webda[i].substr(2);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
this.packageWebda = deepmerge(info.webda || {}, this.packageWebda);
|
|
288
|
-
this.packageWebda.workspaces = {
|
|
289
|
-
packages: info.workspaces,
|
|
290
|
-
parent: info,
|
|
291
|
-
path: path.resolve(parent)
|
|
292
|
-
};
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
parent = path.join(parent, "..");
|
|
297
|
-
} while (path.resolve(parent) !== "/");
|
|
149
|
+
return true;
|
|
298
150
|
}
|
|
299
151
|
/**
|
|
300
152
|
* Retrieve specific webda conf from package.json
|
|
@@ -302,82 +154,17 @@ class Application {
|
|
|
302
154
|
* In case of workspaces the object is combined
|
|
303
155
|
*/
|
|
304
156
|
getPackageWebda() {
|
|
305
|
-
|
|
157
|
+
var _a;
|
|
158
|
+
return (((_a = this.baseConfiguration.cachedModules.project) === null || _a === void 0 ? void 0 : _a.webda) || {
|
|
159
|
+
namespace: "Webda"
|
|
160
|
+
});
|
|
306
161
|
}
|
|
307
162
|
/**
|
|
308
163
|
* Retrieve content of package.json
|
|
309
164
|
*/
|
|
310
165
|
getPackageDescription() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Set the status of the compilation
|
|
315
|
-
*
|
|
316
|
-
* @param compile true will avoid trigger new compilation
|
|
317
|
-
*/
|
|
318
|
-
preventCompilation(compile) {
|
|
319
|
-
this.compiled = compile;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Migrate from v0 to v1 configuration
|
|
323
|
-
*
|
|
324
|
-
* A V0 is a webda.config.json that does not contain any version tag
|
|
325
|
-
*
|
|
326
|
-
* @param config
|
|
327
|
-
*/
|
|
328
|
-
migrateV0Config(config) {
|
|
329
|
-
this.log("WARN", "Old V0 webda.config.json format, trying to migrate");
|
|
330
|
-
let newConfig = {
|
|
331
|
-
parameters: {},
|
|
332
|
-
services: {},
|
|
333
|
-
models: {},
|
|
334
|
-
routes: {},
|
|
335
|
-
version: 1
|
|
336
|
-
};
|
|
337
|
-
let domain;
|
|
338
|
-
if (config["*"]) {
|
|
339
|
-
domain = config[config["*"]];
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
domain = config[Object.keys(config)[0]] || { global: {} };
|
|
343
|
-
}
|
|
344
|
-
if (domain.global) {
|
|
345
|
-
newConfig.parameters = domain.global.params || {};
|
|
346
|
-
newConfig.services = domain.global.services || {};
|
|
347
|
-
newConfig.models = domain.global.models || {};
|
|
348
|
-
newConfig.parameters.locales = domain.global.locales;
|
|
349
|
-
newConfig.moddas = domain.global.moddas || {};
|
|
350
|
-
}
|
|
351
|
-
for (let i in domain) {
|
|
352
|
-
if (i === "global")
|
|
353
|
-
continue;
|
|
354
|
-
newConfig.routes[i] = domain[i];
|
|
355
|
-
}
|
|
356
|
-
return newConfig;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Migrate from v1 to v2 configuration format
|
|
360
|
-
*
|
|
361
|
-
* @param config
|
|
362
|
-
*/
|
|
363
|
-
migrateV1Config(config) {
|
|
364
|
-
this.log("WARN", "Old V1 webda.config.json format, trying to migrate");
|
|
365
|
-
let newConfig = {
|
|
366
|
-
parameters: config.parameters,
|
|
367
|
-
services: config.services,
|
|
368
|
-
module: {
|
|
369
|
-
services: {},
|
|
370
|
-
models: Object.assign({}, config.models),
|
|
371
|
-
deployers: {}
|
|
372
|
-
},
|
|
373
|
-
version: 2
|
|
374
|
-
};
|
|
375
|
-
if (config.moddas) {
|
|
376
|
-
for (let i in config.moddas) {
|
|
377
|
-
newConfig.module.services[i] = config.moddas[i].require;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return newConfig;
|
|
166
|
+
var _a, _b;
|
|
167
|
+
return ((_b = (_a = this.baseConfiguration.cachedModules) === null || _a === void 0 ? void 0 : _a.project) === null || _b === void 0 ? void 0 : _b.package) || {};
|
|
381
168
|
}
|
|
382
169
|
/**
|
|
383
170
|
* Log information
|
|
@@ -418,30 +205,45 @@ class Application {
|
|
|
418
205
|
*/
|
|
419
206
|
addService(name, service) {
|
|
420
207
|
this.log("TRACE", "Registering service", name);
|
|
421
|
-
this.
|
|
208
|
+
this.moddas[name.toLowerCase()] = service;
|
|
209
|
+
return this;
|
|
422
210
|
}
|
|
423
211
|
/**
|
|
424
|
-
* Get a service based on name
|
|
425
212
|
*
|
|
213
|
+
* @param section
|
|
426
214
|
* @param name
|
|
215
|
+
* @returns
|
|
427
216
|
*/
|
|
428
|
-
|
|
429
|
-
let
|
|
430
|
-
this.log("TRACE",
|
|
431
|
-
if (!this
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
217
|
+
getWebdaObject(section, name) {
|
|
218
|
+
let objectName = this.completeNamespace(name);
|
|
219
|
+
this.log("TRACE", `Search for ${section} ${objectName}`);
|
|
220
|
+
if (!this[section][objectName] && name.indexOf("/") === -1) {
|
|
221
|
+
objectName = `webda/${name}`.toLowerCase();
|
|
222
|
+
}
|
|
223
|
+
if (!this[section][objectName]) {
|
|
224
|
+
throw Error(`Undefined ${section.substring(0, section.length - 1)} ${name} or ${objectName} (${Object.keys(this[section]).join(", ")})`);
|
|
437
225
|
}
|
|
438
|
-
return this
|
|
226
|
+
return this[section][objectName];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get a service based on name
|
|
230
|
+
*
|
|
231
|
+
* @param name
|
|
232
|
+
*/
|
|
233
|
+
getModda(name) {
|
|
234
|
+
return this.getWebdaObject("moddas", name);
|
|
439
235
|
}
|
|
440
236
|
/**
|
|
441
237
|
* Return all services of the application
|
|
442
238
|
*/
|
|
443
|
-
|
|
444
|
-
return this.
|
|
239
|
+
getModdas() {
|
|
240
|
+
return this.moddas;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Return all beans of the application
|
|
244
|
+
*/
|
|
245
|
+
getBeans() {
|
|
246
|
+
return this.baseConfiguration.cachedModules.beans;
|
|
445
247
|
}
|
|
446
248
|
/**
|
|
447
249
|
* Retrieve the model implementation
|
|
@@ -449,14 +251,7 @@ class Application {
|
|
|
449
251
|
* @param name model to retrieve
|
|
450
252
|
*/
|
|
451
253
|
getModel(name) {
|
|
452
|
-
|
|
453
|
-
if (name.indexOf("/") < 0) {
|
|
454
|
-
name = `webda/${name}`;
|
|
455
|
-
}
|
|
456
|
-
if (!this.models[name.toLowerCase()]) {
|
|
457
|
-
throw Error("Undefined model '" + name + "' known models are '" + Object.keys(this.models).join(",") + "'");
|
|
458
|
-
}
|
|
459
|
-
return this.models[name.toLowerCase()];
|
|
254
|
+
return this.getWebdaObject("models", name);
|
|
460
255
|
}
|
|
461
256
|
/**
|
|
462
257
|
* Get all models definitions
|
|
@@ -479,6 +274,7 @@ class Application {
|
|
|
479
274
|
addModel(name, model) {
|
|
480
275
|
this.log("TRACE", "Registering model", name);
|
|
481
276
|
this.models[name.toLowerCase()] = model;
|
|
277
|
+
return this;
|
|
482
278
|
}
|
|
483
279
|
/**
|
|
484
280
|
* Add a new deployer
|
|
@@ -489,16 +285,7 @@ class Application {
|
|
|
489
285
|
addDeployer(name, model) {
|
|
490
286
|
this.log("TRACE", "Registering deployer", name);
|
|
491
287
|
this.deployers[name.toLowerCase()] = model;
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* Check if a deployment exists for this application
|
|
495
|
-
* This method cannot be called for a packaged application
|
|
496
|
-
* as we do not keep deployments files when deployed
|
|
497
|
-
*
|
|
498
|
-
* @param deploymentName
|
|
499
|
-
*/
|
|
500
|
-
hasDeployment(deploymentName) {
|
|
501
|
-
return fs.existsSync(path.join(this.appPath, "deployments", deploymentName + ".json"));
|
|
288
|
+
return this;
|
|
502
289
|
}
|
|
503
290
|
/**
|
|
504
291
|
* Return webda current version
|
|
@@ -509,76 +296,15 @@ class Application {
|
|
|
509
296
|
getWebdaVersion() {
|
|
510
297
|
return JSON.parse(fs.readFileSync(__dirname + "/../package.json").toString()).version;
|
|
511
298
|
}
|
|
512
|
-
getDeployment(deploymentName = undefined) {
|
|
513
|
-
if (!deploymentName) {
|
|
514
|
-
deploymentName = this.currentDeployment;
|
|
515
|
-
}
|
|
516
|
-
let deploymentConfig = path.join(this.appPath, "deployments", deploymentName + ".json");
|
|
517
|
-
// Load deployment
|
|
518
|
-
if (!fs.existsSync(deploymentConfig)) {
|
|
519
|
-
throw new index_1.WebdaError("UNKNOWN_DEPLOYMENT", "Unknown deployment");
|
|
520
|
-
}
|
|
521
|
-
let deploymentModel;
|
|
522
|
-
try {
|
|
523
|
-
deploymentModel = JSON.parse(fs.readFileSync(deploymentConfig).toString());
|
|
524
|
-
deploymentModel.name = deploymentName;
|
|
525
|
-
}
|
|
526
|
-
catch (err) {
|
|
527
|
-
throw new index_1.WebdaError("INVALID_DEPLOYMENT", `Invalid deployment configuration ${deploymentConfig}: ${err.toString()}`);
|
|
528
|
-
}
|
|
529
|
-
return deploymentModel;
|
|
530
|
-
}
|
|
531
299
|
/**
|
|
532
300
|
* Retrieve Git Repository information
|
|
533
301
|
*
|
|
534
302
|
* {@link GitInformation} for more details on how the information is gathered
|
|
535
303
|
* @return the git information
|
|
536
304
|
*/
|
|
537
|
-
getGitInformation() {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
};
|
|
541
|
-
let info = this.getPackageDescription();
|
|
542
|
-
try {
|
|
543
|
-
let tags = (0, child_process_1.execSync)(`git tag --points-at HEAD`, options)
|
|
544
|
-
.toString()
|
|
545
|
-
.trim()
|
|
546
|
-
.split("\n")
|
|
547
|
-
.filter(t => t !== "");
|
|
548
|
-
let tag = "";
|
|
549
|
-
let version = info.version;
|
|
550
|
-
if (tags.includes(`${info.name}@${info.version}`)) {
|
|
551
|
-
tag = `${info.name}@${info.version}`;
|
|
552
|
-
}
|
|
553
|
-
else if (tags.includes(`v${info.version}`)) {
|
|
554
|
-
tag = `v${info.version}`;
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
version = semver.inc(info.version, "patch") + "+" + dateFormat(new Date(), "yyyymmddHHMMssl");
|
|
558
|
-
}
|
|
559
|
-
// Search for what would be the tag
|
|
560
|
-
// packageName@version
|
|
561
|
-
// or version if single repo
|
|
562
|
-
// if not included create a nextVersion+SNAPSHOT.${commit}.${now}
|
|
563
|
-
return {
|
|
564
|
-
commit: (0, child_process_1.execSync)(`git rev-parse HEAD`, options).toString().trim(),
|
|
565
|
-
branch: (0, child_process_1.execSync)("git symbolic-ref --short HEAD", options).toString().trim(),
|
|
566
|
-
short: (0, child_process_1.execSync)(`git rev-parse --short HEAD`, options).toString().trim(),
|
|
567
|
-
tag,
|
|
568
|
-
tags,
|
|
569
|
-
version
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
catch (err) {
|
|
573
|
-
return {
|
|
574
|
-
commit: "unknown",
|
|
575
|
-
branch: "unknown",
|
|
576
|
-
tag: "",
|
|
577
|
-
short: "00000000",
|
|
578
|
-
tags: [],
|
|
579
|
-
version: info.version
|
|
580
|
-
};
|
|
581
|
-
}
|
|
305
|
+
getGitInformation(_packageName, _version) {
|
|
306
|
+
var _a;
|
|
307
|
+
return (_a = this.baseConfiguration.cachedModules.project) === null || _a === void 0 ? void 0 : _a.git;
|
|
582
308
|
}
|
|
583
309
|
/**
|
|
584
310
|
* Allow variable inside of string
|
|
@@ -591,7 +317,7 @@ class Application {
|
|
|
591
317
|
if (templateString.indexOf("${") < 0) {
|
|
592
318
|
return templateString;
|
|
593
319
|
}
|
|
594
|
-
return new Function("return `" + templateString.replace(/\$\{/g, "${this.") + "`;").call(Object.assign(
|
|
320
|
+
return new Function("return `" + templateString.replace(/\$\{/g, "${this.") + "`;").call(Object.assign(Object.assign(Object.assign({}, this.baseConfiguration.cachedModules.project), { now: this.initTime }), replacements));
|
|
595
321
|
}
|
|
596
322
|
/**
|
|
597
323
|
* Allow variable inside object strings
|
|
@@ -642,75 +368,26 @@ class Application {
|
|
|
642
368
|
}));
|
|
643
369
|
}
|
|
644
370
|
/**
|
|
645
|
-
*
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
*
|
|
652
|
-
* "parameters": {
|
|
653
|
-
* "param3": "test"
|
|
654
|
-
* },
|
|
655
|
-
* "services": {
|
|
656
|
-
* "MyService": {
|
|
657
|
-
* "param1": {
|
|
658
|
-
* "sub": "test"
|
|
659
|
-
* },
|
|
660
|
-
* "param2": "value"
|
|
661
|
-
* }
|
|
662
|
-
* }
|
|
663
|
-
* }
|
|
664
|
-
* ```
|
|
665
|
-
*
|
|
666
|
-
* deployment.json
|
|
667
|
-
* ```json
|
|
668
|
-
* {
|
|
669
|
-
* "parameters": {
|
|
670
|
-
* "param4": "deployment"
|
|
671
|
-
* }
|
|
672
|
-
* "services": {
|
|
673
|
-
* "MyService": {
|
|
674
|
-
* "param1": {
|
|
675
|
-
* "sub2": "deploymentSub"
|
|
676
|
-
* },
|
|
677
|
-
* "param2": "${package.version}"
|
|
678
|
-
* }
|
|
679
|
-
* }
|
|
680
|
-
* }
|
|
681
|
-
* ```
|
|
682
|
-
*
|
|
683
|
-
* The result would be:
|
|
684
|
-
* ```json
|
|
685
|
-
* {
|
|
686
|
-
* "parameters": {
|
|
687
|
-
* "param3": "test",
|
|
688
|
-
* "param4": "deployment"
|
|
689
|
-
* },
|
|
690
|
-
* "services": {
|
|
691
|
-
* "MyService": {
|
|
692
|
-
* "param1": {
|
|
693
|
-
* "sub": "test",
|
|
694
|
-
* "sub2": "deploymentSub"
|
|
695
|
-
* },
|
|
696
|
-
* "param2": "1.1.0"
|
|
697
|
-
* }
|
|
698
|
-
* }
|
|
699
|
-
* }
|
|
700
|
-
* ```
|
|
701
|
-
* This map can also use parameters {@link replaceVariables}
|
|
371
|
+
* Get current deployment name
|
|
372
|
+
*/
|
|
373
|
+
getCurrentDeployment() {
|
|
374
|
+
return this.baseConfiguration.cachedModules.project.deployment.name;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Return all application modules merged as one
|
|
702
378
|
*
|
|
703
|
-
*
|
|
379
|
+
* Used when deployed
|
|
380
|
+
* @returns
|
|
704
381
|
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
return
|
|
382
|
+
getModules() {
|
|
383
|
+
return this.baseConfiguration.cachedModules;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Get application configuration
|
|
387
|
+
* @returns
|
|
388
|
+
*/
|
|
389
|
+
getConfiguration(_deployment = undefined) {
|
|
390
|
+
return this.baseConfiguration;
|
|
714
391
|
}
|
|
715
392
|
/**
|
|
716
393
|
* Return current Configuration of the Application
|
|
@@ -722,132 +399,7 @@ class Application {
|
|
|
722
399
|
* ```
|
|
723
400
|
*/
|
|
724
401
|
getCurrentConfiguration() {
|
|
725
|
-
return this.getConfiguration(
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Set the current deployment for the application
|
|
729
|
-
* Call to getCurrentConfiguration will resolve to the computed configuration for the deployment
|
|
730
|
-
* If needed, you can call the method with undefined to reset to default configuration
|
|
731
|
-
*
|
|
732
|
-
* @param deployment to set
|
|
733
|
-
*/
|
|
734
|
-
setCurrentDeployment(deployment) {
|
|
735
|
-
this.currentDeployment = deployment;
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Get current deployment name
|
|
739
|
-
*/
|
|
740
|
-
getCurrentDeployment() {
|
|
741
|
-
return this.currentDeployment;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Compile the application if it is a Typescript application
|
|
745
|
-
* Do nothing otherwise
|
|
746
|
-
*/
|
|
747
|
-
compile() {
|
|
748
|
-
if (this.compiled) {
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
// exec typescript
|
|
752
|
-
this.log("DEBUG", "Compiling application");
|
|
753
|
-
try {
|
|
754
|
-
(0, child_process_1.execSync)(`tsc -p ${this.appPath}`);
|
|
755
|
-
}
|
|
756
|
-
catch (err) {
|
|
757
|
-
(err.stdout.toString() + err.stderr.toString())
|
|
758
|
-
.split("\n")
|
|
759
|
-
.filter(l => l !== "")
|
|
760
|
-
.forEach(l => {
|
|
761
|
-
this.log("ERROR", "tsc:", l);
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
this.compiled = true;
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Load all imported modules and current module
|
|
768
|
-
* It will compile module
|
|
769
|
-
* Generate the current module file
|
|
770
|
-
* Load any imported webda.module.json
|
|
771
|
-
*/
|
|
772
|
-
loadModules() {
|
|
773
|
-
// Cached modules is defined on deploy
|
|
774
|
-
if (this.baseConfiguration.cachedModules) {
|
|
775
|
-
// We should not load any modules as we are in a deployed version
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
// Compile
|
|
779
|
-
this.compile();
|
|
780
|
-
const Finder = require("fs-finder");
|
|
781
|
-
// Modules should be cached on deploy
|
|
782
|
-
var files = [];
|
|
783
|
-
let nodeModules = path.join(this.appPath, "node_modules");
|
|
784
|
-
if (fs.existsSync(nodeModules)) {
|
|
785
|
-
files = Finder.from(nodeModules).findFiles("webda.module.json");
|
|
786
|
-
}
|
|
787
|
-
// Search workspace for webda.module.json
|
|
788
|
-
if (this.workspacesPath !== "") {
|
|
789
|
-
nodeModules = path.join(this.workspacesPath, "node_modules");
|
|
790
|
-
if (fs.existsSync(nodeModules)) {
|
|
791
|
-
files.push(...Finder.from(nodeModules).findFiles("webda.module.json"));
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
// Generate module
|
|
795
|
-
this.generateModule();
|
|
796
|
-
let currentModule = path.join(this.appPath, "webda.module.json");
|
|
797
|
-
if (fs.existsSync(currentModule)) {
|
|
798
|
-
files.push(currentModule);
|
|
799
|
-
}
|
|
800
|
-
if (files.length) {
|
|
801
|
-
this.log("DEBUG", "Found modules", files);
|
|
802
|
-
files.forEach(file => {
|
|
803
|
-
let info = require(file);
|
|
804
|
-
this.loadModule(info, path.dirname(file));
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
getModules() {
|
|
809
|
-
return this.cachedModules;
|
|
810
|
-
}
|
|
811
|
-
/**
|
|
812
|
-
* Generate the module for current application
|
|
813
|
-
*/
|
|
814
|
-
generateModule() {
|
|
815
|
-
// Compile
|
|
816
|
-
this.compile();
|
|
817
|
-
// Reinit the sources cache
|
|
818
|
-
this.cachedModules.sources = [];
|
|
819
|
-
this._loaded = [];
|
|
820
|
-
// Read all files
|
|
821
|
-
this.getPackagesLocations().forEach(p => {
|
|
822
|
-
let absPath = path.resolve(path.join(this.appPath, p));
|
|
823
|
-
if (this._loaded.indexOf(absPath) >= 0) {
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
this._loaded.push(absPath);
|
|
827
|
-
if (fs.existsSync(absPath) && fs.lstatSync(absPath).isDirectory()) {
|
|
828
|
-
absPath += "/**/*.js";
|
|
829
|
-
}
|
|
830
|
-
glob.sync(absPath).forEach(f => this.loadJavascriptFile(f));
|
|
831
|
-
});
|
|
832
|
-
let moduleFile = path.join(this.appPath, "webda.module.json");
|
|
833
|
-
let current = "";
|
|
834
|
-
if (fs.existsSync(moduleFile)) {
|
|
835
|
-
current = fs.readFileSync(moduleFile).toString();
|
|
836
|
-
}
|
|
837
|
-
let module = Object.assign(Object.assign({}, this.appModule), { schemas: {} });
|
|
838
|
-
for (let i in this.appModule.services) {
|
|
839
|
-
module.schemas[i] = this.getSchemaResolver().fromPrototype(this.services[i.toLowerCase()]);
|
|
840
|
-
}
|
|
841
|
-
for (let i in this.appModule.deployers) {
|
|
842
|
-
module.schemas[i] = this.getSchemaResolver().fromPrototype(this.deployers[i.toLowerCase()]);
|
|
843
|
-
}
|
|
844
|
-
for (let i in this.appModule.models) {
|
|
845
|
-
module.schemas[i] = this.getSchemaResolver().fromPrototype(this.models[i.toLowerCase()]);
|
|
846
|
-
}
|
|
847
|
-
if (current !== serializers_1.JSONUtils.stringify(module, undefined, 2)) {
|
|
848
|
-
// Write module
|
|
849
|
-
serializers_1.FileUtils.save(module, moduleFile);
|
|
850
|
-
}
|
|
402
|
+
return this.getConfiguration();
|
|
851
403
|
}
|
|
852
404
|
/**
|
|
853
405
|
* Import a file
|
|
@@ -856,32 +408,35 @@ class Application {
|
|
|
856
408
|
*
|
|
857
409
|
* @param info
|
|
858
410
|
*/
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
info
|
|
862
|
-
|
|
863
|
-
try {
|
|
864
|
-
let serviceConstructor = require(info);
|
|
865
|
-
if (serviceConstructor.default) {
|
|
866
|
-
return serviceConstructor.default;
|
|
411
|
+
importFile(info) {
|
|
412
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
413
|
+
if (info.startsWith(".")) {
|
|
414
|
+
info = this.appPath + "/" + info;
|
|
867
415
|
}
|
|
868
|
-
|
|
869
|
-
|
|
416
|
+
try {
|
|
417
|
+
this.log("TRACE", "Load file", info);
|
|
418
|
+
const [importFilename, importName = "default"] = info.split(":");
|
|
419
|
+
const importObject = (yield Promise.resolve().then(() => require(importFilename)))[importName];
|
|
420
|
+
if (!importObject) {
|
|
421
|
+
this.log("WARN", `Module ${importFilename} does not have export named ${importName}`);
|
|
422
|
+
}
|
|
423
|
+
return importObject;
|
|
870
424
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
}
|
|
425
|
+
catch (err) {
|
|
426
|
+
this.log("WARN", "Cannot resolve require", info, err.message);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
876
429
|
}
|
|
877
430
|
/**
|
|
878
431
|
* Load local module
|
|
879
432
|
*/
|
|
880
433
|
loadLocalModule() {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
let moduleFile = path.join(process.cwd(), "webda.module.json");
|
|
436
|
+
if (fs.existsSync(moduleFile)) {
|
|
437
|
+
yield this.loadModule(JSON.parse(fs.readFileSync(moduleFile).toString()), process.cwd());
|
|
438
|
+
}
|
|
439
|
+
});
|
|
885
440
|
}
|
|
886
441
|
/**
|
|
887
442
|
* Load the module,
|
|
@@ -889,40 +444,26 @@ class Application {
|
|
|
889
444
|
* @protected
|
|
890
445
|
* @ignore Useless for documentation
|
|
891
446
|
*/
|
|
892
|
-
loadModule(
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
"
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
this.addModel(key, service);
|
|
913
|
-
this.cachedModules.models[key] =
|
|
914
|
-
"./" + path.relative(this.appPath, path.resolve(path.join(parent, info.models[key])));
|
|
915
|
-
}
|
|
916
|
-
// Load deployers definition
|
|
917
|
-
for (let key in info.deployers) {
|
|
918
|
-
let service = this.resolveRequire(path.join(parent, info.deployers[key]));
|
|
919
|
-
if (!service) {
|
|
920
|
-
continue;
|
|
921
|
-
}
|
|
922
|
-
this.addDeployer(key, service);
|
|
923
|
-
this.cachedModules.deployers[key] =
|
|
924
|
-
"./" + path.relative(this.appPath, path.resolve(path.join(parent, info.deployers[key])));
|
|
925
|
-
}
|
|
447
|
+
loadModule(module, parent = this.appPath) {
|
|
448
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
+
const info = Object.assign({ beans: {} }, module);
|
|
450
|
+
const sectionLoader = (section) => __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
var _a;
|
|
452
|
+
var _b, _c;
|
|
453
|
+
for (let key in info[section]) {
|
|
454
|
+
(_a = (_b = this[section])[_c = key.toLowerCase()]) !== null && _a !== void 0 ? _a : (_b[_c] = yield this.importFile(path.join(parent, info[section][key])));
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
yield Promise.all([
|
|
458
|
+
sectionLoader("moddas"),
|
|
459
|
+
sectionLoader("deployers"),
|
|
460
|
+
sectionLoader("models"),
|
|
461
|
+
...Object.keys(info.beans).map(f => {
|
|
462
|
+
this.baseConfiguration.cachedModules.beans[f] = info.beans[f];
|
|
463
|
+
return Promise.resolve().then(() => require(path.join(parent, info.beans[f]))).catch(this.log.bind(this, "WARN"));
|
|
464
|
+
})
|
|
465
|
+
]);
|
|
466
|
+
});
|
|
926
467
|
}
|
|
927
468
|
/**
|
|
928
469
|
* Return the full name including namespace
|
|
@@ -934,11 +475,12 @@ class Application {
|
|
|
934
475
|
* @param name
|
|
935
476
|
*/
|
|
936
477
|
completeNamespace(name = "") {
|
|
478
|
+
var _a, _b;
|
|
937
479
|
// Do not add a namespace if already present
|
|
938
480
|
if (name.indexOf("/") >= 0) {
|
|
939
|
-
return name;
|
|
481
|
+
return name.toLowerCase();
|
|
940
482
|
}
|
|
941
|
-
return `${this.namespace}/${name}
|
|
483
|
+
return `${((_b = (_a = this.baseConfiguration.cachedModules.project) === null || _a === void 0 ? void 0 : _a.webda) === null || _b === void 0 ? void 0 : _b.namespace) || "webda"}/${name}`.toLowerCase();
|
|
942
484
|
}
|
|
943
485
|
/**
|
|
944
486
|
* Check if object extends a class
|
|
@@ -960,56 +502,6 @@ class Application {
|
|
|
960
502
|
}
|
|
961
503
|
return false;
|
|
962
504
|
}
|
|
963
|
-
/**
|
|
964
|
-
* Load a javascript file and check for Modda
|
|
965
|
-
* @param path to load
|
|
966
|
-
*/
|
|
967
|
-
loadJavascriptFile(absolutePath) {
|
|
968
|
-
let marker = path.resolve(absolutePath);
|
|
969
|
-
if (this._loaded.indexOf(marker) >= 0) {
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
this._loaded.push(marker);
|
|
973
|
-
let source = "./" + path.relative(this.appPath, absolutePath);
|
|
974
|
-
if (this.cachedModules.sources.indexOf(source) < 0) {
|
|
975
|
-
this.cachedModules.sources.push(source);
|
|
976
|
-
}
|
|
977
|
-
let mod = this.resolveRequire(absolutePath);
|
|
978
|
-
let obj = mod;
|
|
979
|
-
if (obj && obj.getModda) {
|
|
980
|
-
let modda = mod.getModda();
|
|
981
|
-
let name = mod.prototype.name;
|
|
982
|
-
let category = "services";
|
|
983
|
-
if (modda) {
|
|
984
|
-
name = modda.uuid;
|
|
985
|
-
if (modda.category) {
|
|
986
|
-
category = modda.category;
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
this.log("DEBUG", `Found new getModda implementation ${category} ${this.completeNamespace(name)}`);
|
|
990
|
-
this.appModule[category][this.completeNamespace(name)] = path.relative(this.appPath, absolutePath);
|
|
991
|
-
if (this.extends(obj, abstractdeployer_1.AbstractDeployer)) {
|
|
992
|
-
this.addDeployer(this.completeNamespace(name), obj);
|
|
993
|
-
}
|
|
994
|
-
else {
|
|
995
|
-
this.addService(this.completeNamespace(name), obj);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
else if (this.extends(obj, index_1.CoreModel) || this.extends(obj, index_1.Context)) {
|
|
999
|
-
this.log("DEBUG", "Found new CoreModel implementation", this.completeNamespace(obj.name));
|
|
1000
|
-
this.appModule["models"][this.completeNamespace(obj.name)] = path.relative(this.appPath, absolutePath);
|
|
1001
|
-
this.addModel(this.completeNamespace(obj.name), obj);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Get the application files
|
|
1006
|
-
*/
|
|
1007
|
-
getPackagesLocations() {
|
|
1008
|
-
return this.packageDescription.files || ["lib/**/*.js"];
|
|
1009
|
-
}
|
|
1010
505
|
}
|
|
1011
|
-
__decorate([
|
|
1012
|
-
(0, index_1.Cache)()
|
|
1013
|
-
], Application.prototype, "getGitInformation", null);
|
|
1014
506
|
exports.Application = Application;
|
|
1015
507
|
//# sourceMappingURL=application.js.map
|