velocious 1.0.62 → 1.0.63
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/package.json +1 -1
- package/run-tests.sh +1 -1
- package/spec/dummy/index.js +2 -1
- package/src/application.js +5 -2
- package/src/cli/commands/server.js +2 -1
- package/src/configuration.js +21 -4
- package/src/http-server/worker-handler/worker-thread.js +2 -2
- package/src/initializer.js +13 -0
- package/src/testing/test-runner.js +2 -1
package/package.json
CHANGED
package/run-tests.sh
CHANGED
package/spec/dummy/index.js
CHANGED
package/src/application.js
CHANGED
|
@@ -4,16 +4,19 @@ import {Logger} from "./logger.js"
|
|
|
4
4
|
import HttpServer from "./http-server/index.js"
|
|
5
5
|
|
|
6
6
|
export default class VelociousApplication {
|
|
7
|
-
constructor({configuration, httpServer}) {
|
|
7
|
+
constructor({configuration, httpServer, type}) {
|
|
8
8
|
this.configuration = configuration
|
|
9
9
|
this.httpServerConfiguration = httpServer ?? {}
|
|
10
10
|
this.logger = new Logger(this)
|
|
11
|
+
this._type = type
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
getType() { return this._type }
|
|
15
|
+
|
|
13
16
|
async initialize() {
|
|
14
17
|
const routes = await AppRoutes.getRoutes(this.configuration)
|
|
15
18
|
|
|
16
|
-
await this.configuration.initialize()
|
|
19
|
+
await this.configuration.initialize({type: this.getType()})
|
|
17
20
|
|
|
18
21
|
this.configuration.setRoutes(routes)
|
|
19
22
|
|
package/src/configuration.js
CHANGED
|
@@ -9,7 +9,7 @@ export default class VelociousConfiguration {
|
|
|
9
9
|
return this.velociousConfiguration
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
constructor({cors, database, debug, directory, environment, initializeModels, locale, localeFallbacks, locales, testing, ...restArgs}) {
|
|
12
|
+
constructor({cors, database, debug, directory, environment, initializeModels, initializers, locale, localeFallbacks, locales, testing, ...restArgs}) {
|
|
13
13
|
restArgsError(restArgs)
|
|
14
14
|
|
|
15
15
|
this.cors = cors
|
|
@@ -19,6 +19,7 @@ export default class VelociousConfiguration {
|
|
|
19
19
|
this._environment = environment || process.env.VELOCIOUS_ENV || process.env.NODE_ENV || "development"
|
|
20
20
|
this._directory = directory
|
|
21
21
|
this._initializeModels = initializeModels
|
|
22
|
+
this._initializers = initializers
|
|
22
23
|
this._isInitialized = false
|
|
23
24
|
this.locale = locale
|
|
24
25
|
this.localeFallbacks = localeFallbacks
|
|
@@ -118,13 +119,29 @@ export default class VelociousConfiguration {
|
|
|
118
119
|
isDatabasePoolInitialized(identifier = "default") { return Boolean(this.databasePools[identifier]) }
|
|
119
120
|
isInitialized() { return this._isInitialized }
|
|
120
121
|
|
|
121
|
-
async initialize() {
|
|
122
|
+
async initialize({type} = {}) {
|
|
122
123
|
if (!this.isInitialized()) {
|
|
124
|
+
this._isInitialized = true
|
|
125
|
+
|
|
123
126
|
if (this._initializeModels) {
|
|
124
|
-
await this._initializeModels({configuration: this})
|
|
127
|
+
await this._initializeModels({configuration: this, type})
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
this.
|
|
130
|
+
if (this._initializers) {
|
|
131
|
+
const initializers = await this._initializers({configuration: this})
|
|
132
|
+
const {requireContext, ...restArgs} = initializers
|
|
133
|
+
|
|
134
|
+
restArgsError(restArgs)
|
|
135
|
+
|
|
136
|
+
if (requireContext) {
|
|
137
|
+
for (const initializerKey of requireContext.keys()) {
|
|
138
|
+
const InitializerClass = requireContext(initializerKey).default
|
|
139
|
+
const initializerInstance = new InitializerClass({configuration: this, type})
|
|
140
|
+
|
|
141
|
+
await initializerInstance.run()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
147
|
|
|
@@ -33,10 +33,10 @@ export default class VelociousHttpServerWorkerHandlerWorkerThread {
|
|
|
33
33
|
this.configuration.setEnvironment(environment)
|
|
34
34
|
this.configuration.setCurrent()
|
|
35
35
|
|
|
36
|
-
this.application = new Application({configuration: this.configuration, debug, directory})
|
|
36
|
+
this.application = new Application({configuration: this.configuration, debug, directory, type: "worker-handler"})
|
|
37
37
|
|
|
38
38
|
if (this.configuration.isInitialized()) {
|
|
39
|
-
await this.configuration.initialize()
|
|
39
|
+
await this.configuration.initialize({type: "worker-handler"})
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default class VelociousInitializer {
|
|
2
|
+
constructor({configuration, type}) {
|
|
3
|
+
this._configuration = configuration
|
|
4
|
+
this._type = type
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
getConfiguration() { return this._configuration }
|
|
8
|
+
getType() { return this._type }
|
|
9
|
+
|
|
10
|
+
run() {
|
|
11
|
+
throw new Error(`'run' hasn't been implemented on ${this.constructor.name})`)
|
|
12
|
+
}
|
|
13
|
+
}
|