@webda/core 1.6.0-beta.3 → 2.0.0-beta.2

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.
Files changed (253) hide show
  1. package/lib/application.d.ts +355 -195
  2. package/lib/application.js +188 -682
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +109 -289
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +150 -215
  7. package/lib/core.js +188 -71
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +103 -42
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +4 -0
  12. package/lib/index.js +9 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +3 -1
  15. package/lib/models/aclmodel.js +6 -3
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +10 -5
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +86 -24
  20. package/lib/models/coremodel.js +85 -36
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +21 -2
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/ident.d.ts +7 -5
  25. package/lib/models/ident.js +2 -1
  26. package/lib/models/ident.js.map +1 -1
  27. package/lib/models/ident.spec.js +1 -1
  28. package/lib/models/ident.spec.js.map +1 -1
  29. package/lib/models/ownermodel.d.ts +18 -4
  30. package/lib/models/ownermodel.js +24 -4
  31. package/lib/models/ownermodel.js.map +1 -1
  32. package/lib/models/ownermodel.spec.js +18 -1
  33. package/lib/models/ownermodel.spec.js.map +1 -1
  34. package/lib/models/rolemodel.js.map +1 -1
  35. package/lib/models/rolemodel.spec.js +5 -2
  36. package/lib/models/rolemodel.spec.js.map +1 -1
  37. package/lib/models/user.d.ts +7 -6
  38. package/lib/models/user.js +2 -1
  39. package/lib/models/user.js.map +1 -1
  40. package/lib/models/user.spec.js +1 -1
  41. package/lib/models/user.spec.js.map +1 -1
  42. package/lib/queues/filequeue.d.ts +2 -7
  43. package/lib/queues/filequeue.js +4 -13
  44. package/lib/queues/filequeue.js.map +1 -1
  45. package/lib/queues/filequeue.spec.js +2 -3
  46. package/lib/queues/filequeue.spec.js.map +1 -1
  47. package/lib/queues/memoryqueue.d.ts +2 -7
  48. package/lib/queues/memoryqueue.js +1 -11
  49. package/lib/queues/memoryqueue.js.map +1 -1
  50. package/lib/queues/memoryqueue.spec.js +1 -1
  51. package/lib/queues/memoryqueue.spec.js.map +1 -1
  52. package/lib/queues/queue.spec.d.ts +1 -1
  53. package/lib/queues/queue.spec.js +12 -10
  54. package/lib/queues/queue.spec.js.map +1 -1
  55. package/lib/queues/queueservice.d.ts +1 -1
  56. package/lib/queues/queueservice.js +1 -1
  57. package/lib/queues/queueservice.js.map +1 -1
  58. package/lib/router.d.ts +52 -2
  59. package/lib/router.js +80 -51
  60. package/lib/router.js.map +1 -1
  61. package/lib/router.spec.js +23 -6
  62. package/lib/router.spec.js.map +1 -1
  63. package/lib/services/asyncevents.d.ts +1 -0
  64. package/lib/services/asyncevents.js +4 -3
  65. package/lib/services/asyncevents.js.map +1 -1
  66. package/lib/services/asyncevents.spec.js +2 -2
  67. package/lib/services/asyncevents.spec.js.map +1 -1
  68. package/lib/services/authentication.d.ts +39 -11
  69. package/lib/services/authentication.js +60 -55
  70. package/lib/services/authentication.js.map +1 -1
  71. package/lib/services/authentication.spec.js +2 -1
  72. package/lib/services/authentication.spec.js.map +1 -1
  73. package/lib/services/binary.d.ts +127 -65
  74. package/lib/services/binary.js +255 -98
  75. package/lib/services/binary.js.map +1 -1
  76. package/lib/services/binary.spec.d.ts +2 -1
  77. package/lib/services/binary.spec.js +101 -30
  78. package/lib/services/binary.spec.js.map +1 -1
  79. package/lib/services/cloudbinary.d.ts +67 -0
  80. package/lib/services/cloudbinary.js +178 -0
  81. package/lib/services/cloudbinary.js.map +1 -0
  82. package/lib/services/cloudbinary.spec.d.ts +13 -0
  83. package/lib/services/cloudbinary.spec.js +212 -0
  84. package/lib/services/cloudbinary.spec.js.map +1 -0
  85. package/lib/services/configuration.d.ts +7 -2
  86. package/lib/services/configuration.js +6 -5
  87. package/lib/services/configuration.js.map +1 -1
  88. package/lib/services/configuration.spec.js +3 -2
  89. package/lib/services/configuration.spec.js.map +1 -1
  90. package/lib/services/cron.d.ts +5 -6
  91. package/lib/services/cron.js +5 -12
  92. package/lib/services/cron.js.map +1 -1
  93. package/lib/services/cron.spec.js +3 -4
  94. package/lib/services/cron.spec.js.map +1 -1
  95. package/lib/services/debugmailer.d.ts +3 -5
  96. package/lib/services/debugmailer.js +3 -11
  97. package/lib/services/debugmailer.js.map +1 -1
  98. package/lib/services/debugmailer.spec.js +1 -1
  99. package/lib/services/debugmailer.spec.js.map +1 -1
  100. package/lib/services/echo.d.ts +3 -7
  101. package/lib/services/echo.js +1 -11
  102. package/lib/services/echo.js.map +1 -1
  103. package/lib/services/echo.spec.js +4 -3
  104. package/lib/services/echo.spec.js.map +1 -1
  105. package/lib/services/filebinary.d.ts +45 -16
  106. package/lib/services/filebinary.js +147 -50
  107. package/lib/services/filebinary.js.map +1 -1
  108. package/lib/services/filebinary.spec.d.ts +4 -2
  109. package/lib/services/filebinary.spec.js +50 -12
  110. package/lib/services/filebinary.spec.js.map +1 -1
  111. package/lib/services/fileconfiguration.d.ts +1 -5
  112. package/lib/services/fileconfiguration.js +3 -12
  113. package/lib/services/fileconfiguration.js.map +1 -1
  114. package/lib/services/fileconfiguration.spec.js +2 -2
  115. package/lib/services/fileconfiguration.spec.js.map +1 -1
  116. package/lib/services/invitationservice.d.ts +28 -4
  117. package/lib/services/invitationservice.js +9 -6
  118. package/lib/services/invitationservice.js.map +1 -1
  119. package/lib/services/invitationservice.spec.js +4 -3
  120. package/lib/services/invitationservice.spec.js.map +1 -1
  121. package/lib/services/kubernetesconfiguration.d.ts +3 -5
  122. package/lib/services/kubernetesconfiguration.js +7 -14
  123. package/lib/services/kubernetesconfiguration.js.map +1 -1
  124. package/lib/services/kubernetesconfiguration.spec.js +5 -5
  125. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  126. package/lib/services/mailer.d.ts +1 -5
  127. package/lib/services/mailer.js +1 -10
  128. package/lib/services/mailer.js.map +1 -1
  129. package/lib/services/mailer.spec.js +3 -3
  130. package/lib/services/mailer.spec.js.map +1 -1
  131. package/lib/services/notificationservice.d.ts +2 -0
  132. package/lib/services/notificationservice.js +2 -0
  133. package/lib/services/notificationservice.js.map +1 -1
  134. package/lib/services/notificationservice.spec.js +2 -2
  135. package/lib/services/notificationservice.spec.js.map +1 -1
  136. package/lib/services/oauth.d.ts +8 -6
  137. package/lib/services/oauth.js +30 -14
  138. package/lib/services/oauth.js.map +1 -1
  139. package/lib/services/oauth.spec.js +11 -10
  140. package/lib/services/oauth.spec.js.map +1 -1
  141. package/lib/services/resource.d.ts +18 -5
  142. package/lib/services/resource.js +42 -23
  143. package/lib/services/resource.js.map +1 -1
  144. package/lib/services/resource.spec.js +4 -4
  145. package/lib/services/resource.spec.js.map +1 -1
  146. package/lib/services/service.d.ts +25 -25
  147. package/lib/services/service.js +21 -25
  148. package/lib/services/service.js.map +1 -1
  149. package/lib/services/service.spec.js +2 -2
  150. package/lib/services/service.spec.js.map +1 -1
  151. package/lib/services/version.d.ts +2 -5
  152. package/lib/services/version.js +1 -10
  153. package/lib/services/version.js.map +1 -1
  154. package/lib/services/version.spec.js +1 -1
  155. package/lib/services/version.spec.js.map +1 -1
  156. package/lib/stores/aggregator.d.ts +3 -5
  157. package/lib/stores/aggregator.js +3 -10
  158. package/lib/stores/aggregator.js.map +1 -1
  159. package/lib/stores/file.d.ts +15 -8
  160. package/lib/stores/file.js +21 -18
  161. package/lib/stores/file.js.map +1 -1
  162. package/lib/stores/file.spec.d.ts +3 -1
  163. package/lib/stores/file.spec.js +32 -8
  164. package/lib/stores/file.spec.js.map +1 -1
  165. package/lib/stores/mapper.d.ts +1 -5
  166. package/lib/stores/mapper.js +5 -13
  167. package/lib/stores/mapper.js.map +1 -1
  168. package/lib/stores/mapper.spec.js +2 -2
  169. package/lib/stores/mapper.spec.js.map +1 -1
  170. package/lib/stores/memory.d.ts +5 -9
  171. package/lib/stores/memory.js +5 -17
  172. package/lib/stores/memory.js.map +1 -1
  173. package/lib/stores/memory.spec.d.ts +2 -1
  174. package/lib/stores/memory.spec.js +36 -4
  175. package/lib/stores/memory.spec.js.map +1 -1
  176. package/lib/stores/store.d.ts +142 -29
  177. package/lib/stores/store.js +451 -82
  178. package/lib/stores/store.js.map +1 -1
  179. package/lib/stores/store.spec.d.ts +31 -4
  180. package/lib/stores/store.spec.js +206 -35
  181. package/lib/stores/store.spec.js.map +1 -1
  182. package/lib/stores/webdaql/WebdaQLLexer.d.ts +53 -0
  183. package/lib/stores/webdaql/WebdaQLLexer.js +290 -0
  184. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -0
  185. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +53 -0
  186. package/lib/stores/webdaql/WebdaQLParserLexer.js +290 -0
  187. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -0
  188. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +284 -0
  189. package/lib/stores/webdaql/WebdaQLParserListener.js +4 -0
  190. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -0
  191. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +301 -0
  192. package/lib/stores/webdaql/WebdaQLParserParser.js +1781 -0
  193. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -0
  194. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +174 -0
  195. package/lib/stores/webdaql/WebdaQLParserVisitor.js +4 -0
  196. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -0
  197. package/lib/stores/webdaql/query.d.ts +300 -0
  198. package/lib/stores/webdaql/query.js +471 -0
  199. package/lib/stores/webdaql/query.js.map +1 -0
  200. package/lib/stores/webdaql/query.spec.d.ts +1 -0
  201. package/lib/stores/webdaql/query.spec.js +136 -0
  202. package/lib/stores/webdaql/query.spec.js.map +1 -0
  203. package/lib/test.d.ts +54 -9
  204. package/lib/test.js +139 -25
  205. package/lib/test.js.map +1 -1
  206. package/lib/unpackedapplication.d.ts +66 -0
  207. package/lib/unpackedapplication.js +219 -0
  208. package/lib/unpackedapplication.js.map +1 -0
  209. package/lib/utils/abstractdeployer.spec.js +1 -1
  210. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  211. package/lib/utils/context.d.ts +17 -58
  212. package/lib/utils/context.js +33 -124
  213. package/lib/utils/context.js.map +1 -1
  214. package/lib/utils/context.spec.js +52 -28
  215. package/lib/utils/context.spec.js.map +1 -1
  216. package/lib/utils/cookie.d.ts +6 -3
  217. package/lib/utils/cookie.js +9 -5
  218. package/lib/utils/cookie.js.map +1 -1
  219. package/lib/utils/cookie.spec.js +5 -5
  220. package/lib/utils/cookie.spec.js.map +1 -1
  221. package/lib/utils/httpcontext.d.ts +182 -0
  222. package/lib/utils/httpcontext.js +325 -0
  223. package/lib/utils/httpcontext.js.map +1 -0
  224. package/lib/utils/httpcontext.spec.d.ts +5 -0
  225. package/lib/utils/httpcontext.spec.js +90 -0
  226. package/lib/utils/httpcontext.spec.js.map +1 -0
  227. package/lib/utils/logger.d.ts +18 -5
  228. package/lib/utils/logger.js +17 -4
  229. package/lib/utils/logger.js.map +1 -1
  230. package/lib/utils/logger.spec.js.map +1 -1
  231. package/lib/utils/serializers.js +5 -1
  232. package/lib/utils/serializers.js.map +1 -1
  233. package/lib/utils/serializers.spec.js +3 -3
  234. package/lib/utils/serializers.spec.js.map +1 -1
  235. package/lib/utils/waiter.d.ts +1 -1
  236. package/lib/utils/waiter.js.map +1 -1
  237. package/lib/utils/waiter.spec.js +2 -2
  238. package/lib/utils/waiter.spec.js.map +1 -1
  239. package/package.json +25 -18
  240. package/test/config-file-no-reload.json +2 -1
  241. package/test/config-file-reload.json +2 -1
  242. package/test/config-kube-reload.json +2 -1
  243. package/test/config-reload.json +1 -1
  244. package/test/config.json +8 -11
  245. package/test/config.old.json +1 -1
  246. package/test/moddas/annotatedservice.js +1 -3
  247. package/test/moddas/debugmailer.js +2 -7
  248. package/test/moddas/fakeservice.js +1 -1
  249. package/test/moddas/voidstore.js +2 -4
  250. package/test/models/ident.js +1 -1
  251. package/test/models/task.js +1 -6
  252. package/webda.module.json +1124 -0
  253. package/test/config.old-default.json +0 -151
@@ -1,62 +1,28 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
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.DefaultSchemaResolver = void 0;
10
- const child_process_1 = require("child_process");
12
+ exports.Application = exports.SectionEnum = void 0;
13
+ const workout_1 = require("@webda/workout");
11
14
  const fs = require("fs");
12
- const glob = require("glob");
13
- const merge = require("merge");
14
15
  const path = require("path");
16
+ const path_1 = require("path");
15
17
  const index_1 = require("./index");
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
18
  const serializers_1 = require("./utils/serializers");
22
- const echo_1 = require("./services/echo");
23
- const cron_1 = require("./services/cron");
24
- const invitationservice_1 = require("./services/invitationservice");
25
- const notificationservice_1 = require("./services/notificationservice");
26
- /**
27
- * Implement the default way of retrieving schema
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;
19
+ var SectionEnum;
20
+ (function (SectionEnum) {
21
+ SectionEnum["Moddas"] = "moddas";
22
+ SectionEnum["Deployers"] = "deployers";
23
+ SectionEnum["Models"] = "models";
24
+ SectionEnum["Beans"] = "beans";
25
+ })(SectionEnum = exports.SectionEnum || (exports.SectionEnum = {}));
60
26
  /**
61
27
  * Map a Webda Application
62
28
  *
@@ -76,21 +42,12 @@ class Application {
76
42
  * @param {string} fileOrFolder to load Webda Application from
77
43
  * @param {Logger} logger
78
44
  */
79
- constructor(file, logger = undefined, allowModule = false) {
80
- /**
81
- * Contains all definitions from imported modules and current code
82
- */
83
- this.cachedModules = {
84
- services: {},
85
- models: {},
86
- deployers: {},
87
- sources: []
88
- };
45
+ constructor(file, logger = undefined) {
89
46
  /**
90
47
  * Contains definitions of current application
91
48
  */
92
49
  this.appModule = {
93
- services: {},
50
+ moddas: {},
94
51
  models: {},
95
52
  deployers: {}
96
53
  };
@@ -103,58 +60,13 @@ class Application {
103
60
  */
104
61
  this.deployers = {};
105
62
  /**
106
- * Services type registry
63
+ * Moddas registry
107
64
  */
108
- this.services = {
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
- };
65
+ this.moddas = {};
133
66
  /**
134
67
  * Models type registry
135
68
  */
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 = {};
69
+ this.models = {};
158
70
  /**
159
71
  * Detect if running as workspace
160
72
  */
@@ -162,90 +74,70 @@ class Application {
162
74
  this.logger = logger || new workout_1.WorkerOutput();
163
75
  this.initTime = Date.now();
164
76
  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}`);
77
+ 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
78
  }
167
79
  if (fs.lstatSync(file).isDirectory()) {
168
- file = path.join(file, "webda.config.json");
80
+ file = path.join(file, "webda.config.jsonc");
81
+ if (!fs.existsSync(file)) {
82
+ file = file.substring(0, file.length - 1);
83
+ }
169
84
  }
85
+ this.configurationFile = file;
86
+ this.appPath = path.dirname(file);
87
+ }
88
+ /**
89
+ * Import all required modules
90
+ */
91
+ load() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ this.loadConfiguration(this.configurationFile);
94
+ yield this.loadModule(this.baseConfiguration.cachedModules);
95
+ return this;
96
+ });
97
+ }
98
+ /**
99
+ * Allow subclass to implement migration
100
+ *
101
+ * @param file
102
+ * @returns
103
+ */
104
+ loadConfiguration(file) {
170
105
  // Check if file is a file or folder
171
- if (!fs.existsSync(file) && !allowModule) {
172
- throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.json file: ${file}`);
106
+ if (!fs.existsSync(file)) {
107
+ throw new index_1.WebdaError("NO_WEBDA_FOLDER", `Not a webda application folder or webda.config.jsonc or webda.config.json file: ${file}`);
173
108
  }
174
- this.appPath = path.dirname(file);
175
109
  try {
176
- this.baseConfiguration = JSON.parse(fs.readFileSync(file).toString());
177
- }
178
- catch (err) {
179
- this.log("WARN", err);
180
- if (allowModule) {
181
- this.baseConfiguration = { version: 2, module: {} };
110
+ this.baseConfiguration = serializers_1.FileUtils.load(file);
111
+ if (this.baseConfiguration.version !== 3) {
112
+ this.log("ERROR", "Your configuration file should use version 3, see https://docs.webda.io/");
182
113
  }
183
- else {
184
- throw new index_1.WebdaError("INVALID_WEBDA_CONFIG", `Cannot parse JSON of: ${file}`);
185
- }
186
- }
187
- // Load default schema resolver
188
- this.schemaResolver = new DefaultSchemaResolver(this);
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
114
  }
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
- }
115
+ catch (err) {
116
+ throw new index_1.WebdaError("INVALID_WEBDA_CONFIG", `Cannot parse JSON of: ${file}`);
209
117
  }
210
- this.loadPackageInfos();
211
- this.namespace = this.packageDescription.webda
212
- ? this.packageDescription.webda.namespace
213
- : this.packageDescription.name | this.packageDescription.name;
214
118
  }
215
119
  /**
216
120
  *
217
121
  * @param proto Prototype to send
218
122
  */
219
123
  getFullNameFromPrototype(proto) {
220
- for (let i in this.services) {
221
- if (this.services[i].prototype === proto) {
222
- return i;
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;
124
+ for (let section in SectionEnum) {
125
+ for (let i in this[SectionEnum[section]]) {
126
+ if (this[SectionEnum[section]][i] && this[SectionEnum[section]][i].prototype === proto) {
127
+ return i;
128
+ }
233
129
  }
234
130
  }
235
131
  }
236
132
  /**
237
- * Set the current schema resolver
133
+ * Get a schema from a type
238
134
  *
239
- * @param resolver
240
- */
241
- setSchemaResolver(resolver) {
242
- this.schemaResolver = resolver;
243
- }
244
- /**
245
- * Get schema resolver
135
+ * Schema should be precomputed in the default app
136
+ * @param type
137
+ * @returns
246
138
  */
247
- getSchemaResolver() {
248
- return this.schemaResolver;
139
+ getSchema(type) {
140
+ return this.baseConfiguration.cachedModules.schemas[type];
249
141
  }
250
142
  /**
251
143
  * Check if application has cached modules
@@ -255,46 +147,7 @@ class Application {
255
147
  * take the schema from the cached modules also
256
148
  */
257
149
  isCached() {
258
- return this.baseConfiguration.cachedModules !== undefined;
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) !== "/");
150
+ return true;
298
151
  }
299
152
  /**
300
153
  * Retrieve specific webda conf from package.json
@@ -302,82 +155,17 @@ class Application {
302
155
  * In case of workspaces the object is combined
303
156
  */
304
157
  getPackageWebda() {
305
- return this.packageWebda;
158
+ var _a;
159
+ return (((_a = this.baseConfiguration.cachedModules.project) === null || _a === void 0 ? void 0 : _a.webda) || {
160
+ namespace: "Webda"
161
+ });
306
162
  }
307
163
  /**
308
164
  * Retrieve content of package.json
309
165
  */
310
166
  getPackageDescription() {
311
- return this.packageDescription;
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;
167
+ var _a, _b;
168
+ return ((_b = (_a = this.baseConfiguration.cachedModules) === null || _a === void 0 ? void 0 : _a.project) === null || _b === void 0 ? void 0 : _b.package) || {};
381
169
  }
382
170
  /**
383
171
  * Log information
@@ -403,7 +191,7 @@ class Application {
403
191
  */
404
192
  getAppPath(subpath = undefined) {
405
193
  if (subpath && subpath !== "") {
406
- if (subpath.startsWith("/")) {
194
+ if (path.isAbsolute(subpath)) {
407
195
  return subpath;
408
196
  }
409
197
  return path.join(this.appPath, subpath);
@@ -418,30 +206,45 @@ class Application {
418
206
  */
419
207
  addService(name, service) {
420
208
  this.log("TRACE", "Registering service", name);
421
- this.services[name.toLowerCase()] = service;
209
+ this.moddas[name.toLowerCase()] = service;
210
+ return this;
422
211
  }
423
212
  /**
424
- * Get a service based on name
425
213
  *
214
+ * @param section
426
215
  * @param name
216
+ * @returns
427
217
  */
428
- getService(name) {
429
- let serviceName = this.completeNamespace(name).toLowerCase();
430
- this.log("TRACE", "Search for service", serviceName);
431
- if (!this.services[serviceName]) {
432
- serviceName = `Webda/${name}`.toLowerCase();
433
- // Try Webda namespace
434
- if (!this.services[serviceName]) {
435
- throw Error("Undefined service " + name);
436
- }
218
+ getWebdaObject(section, name) {
219
+ let objectName = this.completeNamespace(name);
220
+ this.log("TRACE", `Search for ${section} ${objectName}`);
221
+ if (!this[section][objectName] && name.indexOf("/") === -1) {
222
+ objectName = `webda/${name}`.toLowerCase();
437
223
  }
438
- return this.services[serviceName];
224
+ if (!this[section][objectName]) {
225
+ throw Error(`Undefined ${section.substring(0, section.length - 1)} ${name} or ${objectName} (${Object.keys(this[section]).join(", ")})`);
226
+ }
227
+ return this[section][objectName];
228
+ }
229
+ /**
230
+ * Get a service based on name
231
+ *
232
+ * @param name
233
+ */
234
+ getModda(name) {
235
+ return this.getWebdaObject("moddas", name);
439
236
  }
440
237
  /**
441
238
  * Return all services of the application
442
239
  */
443
- getServices() {
444
- return this.services;
240
+ getModdas() {
241
+ return this.moddas;
242
+ }
243
+ /**
244
+ * Return all beans of the application
245
+ */
246
+ getBeans() {
247
+ return this.baseConfiguration.cachedModules.beans;
445
248
  }
446
249
  /**
447
250
  * Retrieve the model implementation
@@ -449,14 +252,7 @@ class Application {
449
252
  * @param name model to retrieve
450
253
  */
451
254
  getModel(name) {
452
- name = name.toLowerCase();
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()];
255
+ return this.getWebdaObject("models", name);
460
256
  }
461
257
  /**
462
258
  * Get all models definitions
@@ -479,6 +275,7 @@ class Application {
479
275
  addModel(name, model) {
480
276
  this.log("TRACE", "Registering model", name);
481
277
  this.models[name.toLowerCase()] = model;
278
+ return this;
482
279
  }
483
280
  /**
484
281
  * Add a new deployer
@@ -489,16 +286,7 @@ class Application {
489
286
  addDeployer(name, model) {
490
287
  this.log("TRACE", "Registering deployer", name);
491
288
  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"));
289
+ return this;
502
290
  }
503
291
  /**
504
292
  * Return webda current version
@@ -509,76 +297,15 @@ class Application {
509
297
  getWebdaVersion() {
510
298
  return JSON.parse(fs.readFileSync(__dirname + "/../package.json").toString()).version;
511
299
  }
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
300
  /**
532
301
  * Retrieve Git Repository information
533
302
  *
534
303
  * {@link GitInformation} for more details on how the information is gathered
535
304
  * @return the git information
536
305
  */
537
- getGitInformation() {
538
- let options = {
539
- cwd: this.getAppPath()
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
- }
306
+ getGitInformation(_packageName, _version) {
307
+ var _a;
308
+ return (_a = this.baseConfiguration.cachedModules.project) === null || _a === void 0 ? void 0 : _a.git;
582
309
  }
583
310
  /**
584
311
  * Allow variable inside of string
@@ -591,7 +318,21 @@ class Application {
591
318
  if (templateString.indexOf("${") < 0) {
592
319
  return templateString;
593
320
  }
594
- return new Function("return `" + templateString.replace(/\$\{/g, "${this.") + "`;").call(Object.assign({ package: this.getPackageDescription(), git: this.getGitInformation(), deployment: this.getCurrentDeployment(), now: this.initTime }, replacements));
321
+ let scan = templateString;
322
+ let index;
323
+ let i = 0;
324
+ while ((index = scan.indexOf("${")) >= 0) {
325
+ let next = scan.indexOf("}", index);
326
+ let variable = scan.substring(index + 2, next);
327
+ scan = scan.substring(next);
328
+ if (variable.match(/[|&;<>\\\{]/)) {
329
+ throw new Error(`Variable cannot use every javascript features found ${variable}`);
330
+ }
331
+ if (i++ > 10) {
332
+ throw new Error("Too many variables");
333
+ }
334
+ }
335
+ return new Function("return `" + templateString.replace(/\$\{([^\}\{]+)}/g, "${this.$1}") + "`;").call(Object.assign(Object.assign(Object.assign({}, this.baseConfiguration.cachedModules.project), { now: this.initTime }), replacements));
595
336
  }
596
337
  /**
597
338
  * Allow variable inside object strings
@@ -642,75 +383,26 @@ class Application {
642
383
  }));
643
384
  }
644
385
  /**
645
- * Return the application Configuration for a deployment
646
- *
647
- * Given this inputs:
648
- *
649
- * webda.config.json
650
- * ```json
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}
386
+ * Get current deployment name
387
+ */
388
+ getCurrentDeployment() {
389
+ return this.baseConfiguration.cachedModules.project.deployment.name;
390
+ }
391
+ /**
392
+ * Return all application modules merged as one
702
393
  *
703
- * @param deploymentName to use for the Configuration
394
+ * Used when deployed
395
+ * @returns
704
396
  */
705
- getConfiguration(deploymentName = undefined) {
706
- if (!deploymentName) {
707
- return this.baseConfiguration;
708
- }
709
- let config = JSON.parse(JSON.stringify(this.baseConfiguration));
710
- let deploymentModel = this.getDeployment(deploymentName);
711
- config.parameters = this.replaceVariables(merge.recursive(config.parameters, deploymentModel.parameters));
712
- config.services = this.replaceVariables(merge.recursive(config.services, deploymentModel.services));
713
- return config;
397
+ getModules() {
398
+ return this.baseConfiguration.cachedModules;
399
+ }
400
+ /**
401
+ * Get application configuration
402
+ * @returns
403
+ */
404
+ getConfiguration(_deployment = undefined) {
405
+ return this.baseConfiguration;
714
406
  }
715
407
  /**
716
408
  * Return current Configuration of the Application
@@ -722,132 +414,7 @@ class Application {
722
414
  * ```
723
415
  */
724
416
  getCurrentConfiguration() {
725
- return this.getConfiguration(this.currentDeployment);
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
- }
417
+ return this.getConfiguration();
851
418
  }
852
419
  /**
853
420
  * Import a file
@@ -856,32 +423,35 @@ class Application {
856
423
  *
857
424
  * @param info
858
425
  */
859
- resolveRequire(info) {
860
- if (info.startsWith(".")) {
861
- info = this.appPath + "/" + info;
862
- }
863
- try {
864
- let serviceConstructor = require(info);
865
- if (serviceConstructor.default) {
866
- return serviceConstructor.default;
426
+ importFile(info) {
427
+ return __awaiter(this, void 0, void 0, function* () {
428
+ if (info.startsWith(".")) {
429
+ info = (0, path_1.join)(this.appPath, ...info.split("/"));
867
430
  }
868
- else {
869
- return serviceConstructor;
431
+ try {
432
+ this.log("TRACE", "Load file", info);
433
+ const [importFilename, importName = "default"] = info.split(":");
434
+ const importObject = (yield Promise.resolve().then(() => require(importFilename)))[importName];
435
+ if (!importObject) {
436
+ this.log("WARN", `Module ${importFilename} does not have export named ${importName}`);
437
+ }
438
+ return importObject;
870
439
  }
871
- }
872
- catch (err) {
873
- this.log("WARN", "Cannot resolve require", info, err.message);
874
- return null;
875
- }
440
+ catch (err) {
441
+ this.log("WARN", "Cannot resolve require", info, err.message);
442
+ }
443
+ });
876
444
  }
877
445
  /**
878
446
  * Load local module
879
447
  */
880
448
  loadLocalModule() {
881
- let moduleFile = path.join(process.cwd(), "webda.module.json");
882
- if (fs.existsSync(moduleFile)) {
883
- this.loadModule(JSON.parse(fs.readFileSync(moduleFile).toString()), process.cwd());
884
- }
449
+ return __awaiter(this, void 0, void 0, function* () {
450
+ let moduleFile = path.join(process.cwd(), "webda.module.json");
451
+ if (fs.existsSync(moduleFile)) {
452
+ yield this.loadModule(serializers_1.FileUtils.load(moduleFile), process.cwd());
453
+ }
454
+ });
885
455
  }
886
456
  /**
887
457
  * Load the module,
@@ -889,40 +459,26 @@ class Application {
889
459
  * @protected
890
460
  * @ignore Useless for documentation
891
461
  */
892
- loadModule(info, parent = this.appPath) {
893
- info.services = info.services || {};
894
- info.models = info.models || {};
895
- info.deployers = info.deployers || {};
896
- // Load services definition
897
- for (let key in info.services) {
898
- let service = this.resolveRequire(path.join(parent, info.services[key]));
899
- if (!service) {
900
- continue;
901
- }
902
- this.addService(key, service);
903
- this.cachedModules.services[key] =
904
- "./" + path.relative(this.appPath, path.resolve(path.join(parent, info.services[key])));
905
- }
906
- // Load models definition
907
- for (let key in info.models) {
908
- let service = this.resolveRequire(path.join(parent, info.models[key]));
909
- if (!service) {
910
- continue;
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
- }
462
+ loadModule(module, parent = this.appPath) {
463
+ return __awaiter(this, void 0, void 0, function* () {
464
+ const info = Object.assign({ beans: {} }, module);
465
+ const sectionLoader = (section) => __awaiter(this, void 0, void 0, function* () {
466
+ var _a;
467
+ var _b, _c;
468
+ for (let key in info[section]) {
469
+ (_a = (_b = this[section])[_c = key.toLowerCase()]) !== null && _a !== void 0 ? _a : (_b[_c] = yield this.importFile(path.join(parent, info[section][key])));
470
+ }
471
+ });
472
+ yield Promise.all([
473
+ sectionLoader("moddas"),
474
+ sectionLoader("deployers"),
475
+ sectionLoader("models"),
476
+ ...Object.keys(info.beans).map(f => {
477
+ this.baseConfiguration.cachedModules.beans[f] = info.beans[f];
478
+ return Promise.resolve().then(() => require(path.join(parent, info.beans[f]))).catch(this.log.bind(this, "WARN"));
479
+ })
480
+ ]);
481
+ });
926
482
  }
927
483
  /**
928
484
  * Return the full name including namespace
@@ -934,11 +490,12 @@ class Application {
934
490
  * @param name
935
491
  */
936
492
  completeNamespace(name = "") {
493
+ var _a, _b;
937
494
  // Do not add a namespace if already present
938
495
  if (name.indexOf("/") >= 0) {
939
- return name;
496
+ return name.toLowerCase();
940
497
  }
941
- return `${this.namespace}/${name}`;
498
+ 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
499
  }
943
500
  /**
944
501
  * Check if object extends a class
@@ -950,7 +507,6 @@ class Application {
950
507
  if (!obj) {
951
508
  return false;
952
509
  }
953
- let i = 1;
954
510
  while (obj && Object.getPrototypeOf(obj)) {
955
511
  let proto = Object.getPrototypeOf(obj);
956
512
  if (proto.name == className.name || proto == className.name) {
@@ -960,56 +516,6 @@ class Application {
960
516
  }
961
517
  return false;
962
518
  }
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
519
  }
1011
- __decorate([
1012
- (0, index_1.Cache)()
1013
- ], Application.prototype, "getGitInformation", null);
1014
520
  exports.Application = Application;
1015
521
  //# sourceMappingURL=application.js.map