velocious 1.0.62 → 1.0.64
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 +2 -2
- 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-resolver.js +13 -2
- 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-files-finder.js +2 -2
- package/src/testing/test-runner.js +2 -1
- package/src/utils/file-exists.js +1 -1
- /package/bin/{velocious.js → velocious.mjs} +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bin": {
|
|
3
|
-
"velocious": "bin/velocious.
|
|
3
|
+
"velocious": "bin/velocious.mjs"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.64",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
|
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
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Configuration from "./configuration.js"
|
|
2
|
+
import envSense from "env-sense/src/use-env-sense.js"
|
|
3
|
+
import fileExists from "./utils/file-exists.js"
|
|
2
4
|
|
|
3
5
|
const configurationResolver = async (args) => {
|
|
4
6
|
if (Configuration.current(false)) {
|
|
@@ -6,8 +8,17 @@ const configurationResolver = async (args) => {
|
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
const directory = args.directory || process.cwd()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
let configurationPrePath = `${directory}/src/config/configuration`
|
|
12
|
+
const configurationPathForNode = `${configurationPrePath}.node.js`
|
|
13
|
+
const configurationPathDefault = `${configurationPrePath}.js`
|
|
14
|
+
const {isServer} = envSense()
|
|
15
|
+
let configuration, configurationPath
|
|
16
|
+
|
|
17
|
+
if (isServer && await fileExists(configurationPathForNode)) {
|
|
18
|
+
configurationPath = configurationPathForNode
|
|
19
|
+
} else {
|
|
20
|
+
configurationPath = configurationPathDefault
|
|
21
|
+
}
|
|
11
22
|
|
|
12
23
|
try {
|
|
13
24
|
const configurationImport = await import(configurationPath)
|
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
|
+
}
|
|
@@ -23,7 +23,7 @@ export default class TestFilesFinder {
|
|
|
23
23
|
return this.foundFiles
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
findingPromisesLength
|
|
26
|
+
findingPromisesLength() { return Object.keys(this.findingPromises).length }
|
|
27
27
|
|
|
28
28
|
async waitForFindingPromises() {
|
|
29
29
|
while (this.findingPromisesLength() > 0) {
|
|
@@ -90,7 +90,7 @@ export default class TestFilesFinder {
|
|
|
90
90
|
return true
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
} else if (file.match(/-(spec|test)\.js
|
|
93
|
+
} else if (file.match(/-(spec|test)\.(m|)js$/)) {
|
|
94
94
|
return true
|
|
95
95
|
}
|
|
96
96
|
|
package/src/utils/file-exists.js
CHANGED
|
File without changes
|