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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.62",
6
+ "version": "1.0.63",
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
@@ -1,4 +1,4 @@
1
1
  #!/bin/bash
2
2
 
3
- VELOCIOUS_TEST_DIR=/home/dev/Development/velocious cd spec/dummy && npx velocious test
3
+ VELOCIOUS_TEST_DIR=/home/dev/Development/velocious/spec cd spec/dummy && npx velocious test
4
4
 
@@ -60,7 +60,8 @@ export default class Dummy {
60
60
  httpServer: {
61
61
  maxWorkers: 1,
62
62
  port: 3006
63
- }
63
+ },
64
+ type: "dummy"
64
65
  })
65
66
 
66
67
  await this.application.initialize()
@@ -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
 
@@ -17,7 +17,8 @@ export default class VelociousCliCommandsServer extends BaseCommand{
17
17
  httpServer: {
18
18
  host,
19
19
  port
20
- }
20
+ },
21
+ type: "server"
21
22
  })
22
23
 
23
24
  await application.initialize()
@@ -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._isInitialized = true
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
+ }
@@ -21,7 +21,8 @@ export default class TestRunner {
21
21
  password: ""
22
22
  }
23
23
  },
24
- httpServer: {port: 31006}
24
+ httpServer: {port: 31006},
25
+ type: "test-runner"
25
26
  })
26
27
 
27
28
  await this._application.initialize()