velocious 1.0.61 → 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.61",
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()
@@ -22,6 +22,9 @@ export default class VelociousCliCommandsTest extends BaseCommand {
22
22
  if (testRunner.isFailed()) {
23
23
  console.error(`\nTest run failed with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
24
24
  process.exit(1)
25
+ } else if (testRunner.areAnyTestsFocussed()) {
26
+ console.error(`\nFocussed run with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
27
+ process.exit(1)
25
28
  } else {
26
29
  console.log(`\nTest run succeeded with ${testRunner.getSuccessfulTests()} successful tests`)
27
30
  process.exit(0)
@@ -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
 
@@ -27,6 +27,11 @@ export default class VelociousDatabaseMigration {
27
27
  }
28
28
 
29
29
  getDriver() { return this._db }
30
+ connection() { return this.getDriver() }
31
+
32
+ async execute(sql) {
33
+ await this.connection().query(sql)
34
+ }
30
35
 
31
36
  async addColumn(tableName, columnName, columnType, args) {
32
37
  if (!columnType) throw new Error("No column type given")
@@ -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
+ }
@@ -2,10 +2,10 @@ import Migration from "velocious/src/database/migration/index.js"
2
2
 
3
3
  export default class __MIGRATION_NAME__ extends Migration {
4
4
  async up() {
5
- await this.connection().execute("...")
5
+ await this.execute("...")
6
6
  }
7
7
 
8
8
  async down() {
9
- await this.connection().execute("...")
9
+ await this.execute("...")
10
10
  }
11
11
  }
@@ -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()
@@ -62,6 +63,7 @@ export default class TestRunner {
62
63
  }
63
64
 
64
65
  async prepare() {
66
+ this.anyTestsFocussed = false
65
67
  this._failedTests = 0
66
68
  this._successfulTests = 0
67
69
  this._testsCount = 0
@@ -76,6 +78,14 @@ export default class TestRunner {
76
78
  }
77
79
  }
78
80
 
81
+ areAnyTestsFocussed() {
82
+ if (this.anyTestsFocussed === undefined) {
83
+ throw new Error("Hasn't been detected yet")
84
+ }
85
+
86
+ return this.anyTestsFocussed
87
+ }
88
+
79
89
  async run() {
80
90
  await this.configuration.ensureConnections(async () => {
81
91
  await this.runTests({