velocious 1.0.97 → 1.0.98
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/eslint.config.js +1 -0
- package/package.json +2 -1
- package/spec/database/connection/drivers/mysql/query-parser-spec.js +4 -4
- package/spec/http-server/post-spec.js +2 -0
- package/src/application.js +27 -9
- package/src/configuration-resolver.js +29 -10
- package/src/configuration-types.js +44 -0
- package/src/configuration.js +63 -33
- package/src/database/drivers/base-column.js +6 -1
- package/src/database/drivers/base-columns-index.js +11 -1
- package/src/database/drivers/base-foreign-key.js +45 -0
- package/src/database/drivers/base-table.js +24 -2
- package/src/database/drivers/base.js +211 -39
- package/src/database/drivers/mssql/index.js +1 -3
- package/src/database/drivers/sqlite/sql/alter-table.js +4 -2
- package/src/database/handler.js +5 -0
- package/src/database/migration/index.js +77 -19
- package/src/database/migrator/files-finder.js +21 -22
- package/src/database/migrator/types.js +29 -0
- package/src/database/migrator.js +98 -59
- package/src/database/pool/async-tracked-multi-connection.js +42 -7
- package/src/database/pool/base-methods-forward.js +37 -0
- package/src/database/pool/base.js +79 -46
- package/src/database/pool/single-multi-use.js +18 -3
- package/src/database/query/alter-table-base.js +4 -4
- package/src/database/query/base.js +9 -2
- package/src/database/query/create-database-base.js +8 -0
- package/src/database/query/create-index-base.js +20 -5
- package/src/database/query/create-table-base.js +28 -9
- package/src/database/query/from-base.js +17 -0
- package/src/database/query/from-plain.js +8 -3
- package/src/database/query/from-table.js +8 -3
- package/src/database/query/index.js +43 -32
- package/src/database/query/join-base.js +28 -1
- package/src/database/query/join-object.js +67 -0
- package/src/database/query/join-plain.js +6 -1
- package/src/database/query/order-base.js +18 -0
- package/src/database/query/order-plain.js +8 -2
- package/src/database/query/select-base.js +15 -0
- package/src/database/query/select-plain.js +6 -1
- package/src/database/query/select-table-and-column.js +8 -2
- package/src/database/query/where-base.js +23 -1
- package/src/database/query/where-hash.js +15 -0
- package/src/database/query/where-plain.js +6 -0
- package/src/database/query-parser/base-query-parser.js +8 -2
- package/src/database/query-parser/from-parser.js +2 -0
- package/src/database/query-parser/joins-parser.js +10 -45
- package/src/database/query-parser/select-parser.js +2 -0
- package/src/database/record/index.js +1 -1
- package/src/database/table-data/index.js +39 -121
- package/src/database/table-data/table-column.js +54 -25
- package/src/database/table-data/table-foreign-key.js +5 -3
- package/src/database/table-data/table-index.js +12 -6
- package/src/database/table-data/table-reference.js +2 -0
- package/src/database/use-database.js +4 -2
- package/src/environment-handlers/base.js +41 -8
- package/src/environment-handlers/node/cli/commands/destroy/migration.js +3 -0
- package/src/environment-handlers/node/cli/commands/generate/migration.js +3 -0
- package/src/environment-handlers/node/cli/commands/generate/model.js +3 -0
- package/src/environment-handlers/node/cli/commands/init.js +3 -0
- package/src/environment-handlers/node.js +59 -28
- package/src/http-client/header.js +6 -0
- package/src/http-client/request.js +31 -5
- package/src/http-client/response.js +31 -7
- package/src/http-server/client/index.js +24 -4
- package/src/http-server/client/request-buffer/form-data-part.js +11 -0
- package/src/http-server/client/request-buffer/header.js +6 -0
- package/src/http-server/client/request-buffer/index.js +91 -13
- package/src/http-server/client/request-parser.js +26 -0
- package/src/http-server/client/request-runner.js +15 -3
- package/src/http-server/client/request.js +17 -0
- package/src/http-server/client/response.js +41 -1
- package/src/http-server/index.js +32 -4
- package/src/http-server/server-client.js +33 -2
- package/src/http-server/worker-handler/index.js +42 -9
- package/src/http-server/worker-handler/worker-script.js +2 -0
- package/src/http-server/worker-handler/worker-thread.js +34 -6
- package/src/logger.js +21 -15
- package/src/routes/app-routes.js +1 -1
- package/src/testing/test-files-finder.js +8 -4
- package/src/testing/test-runner.js +76 -24
- package/src/utils/backtrace-cleaner.js +6 -4
- package/src/utils/ensure-error.js +13 -0
- package/src/utils/file-exists.js +3 -1
- package/src/utils/rest-args-error.js +2 -0
package/eslint.config.js
CHANGED
|
@@ -20,6 +20,7 @@ export default defineConfig([
|
|
|
20
20
|
"jsdoc/require-jsdoc": "off",
|
|
21
21
|
"jsdoc/require-param": "off",
|
|
22
22
|
"jsdoc/require-param-description": "off",
|
|
23
|
+
"jsdoc/require-property-description": "off",
|
|
23
24
|
"jsdoc/require-returns": "off",
|
|
24
25
|
"jsdoc/require-returns-description": "off"
|
|
25
26
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"velocious": "bin/velocious.js"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.98",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"lint": "eslint",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"escape-string-regexp": "^1.0.5",
|
|
35
35
|
"incorporator": "^1.0.2",
|
|
36
36
|
"inflection": "^3.0.0",
|
|
37
|
+
"is-plain-object": "^5.0.0",
|
|
37
38
|
"pure-uuid": "^1.8.1",
|
|
38
39
|
"set-state-compare": "^1.0.58",
|
|
39
40
|
"sql-escape-string": "^1.1.0",
|
|
@@ -22,14 +22,14 @@ describe("database - connection - drivers - mysql - query parser", () => {
|
|
|
22
22
|
expect(sql).toEqual("SELECT tasks.id, tasks.name FROM tasks LEFT JOIN projects ON projects.id = tasks.project_id")
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it("generates sql with selects, joins and orders", () => {
|
|
25
|
+
it("generates sql with selects, joins and orders with SelectTableAndColumn", () => {
|
|
26
26
|
const handler = new DatabaseHandler()
|
|
27
27
|
const query = new DatabaseQuery({driver: mysqlDriver, handler})
|
|
28
28
|
.select([
|
|
29
|
-
new SelectTableAndColumn(
|
|
30
|
-
new SelectTableAndColumn(
|
|
29
|
+
new SelectTableAndColumn("tasks", "id"),
|
|
30
|
+
new SelectTableAndColumn("tasks", "name")
|
|
31
31
|
])
|
|
32
|
-
.from(new FromTable(
|
|
32
|
+
.from(new FromTable("tasks"))
|
|
33
33
|
.joins("LEFT JOIN projects ON projects.id = tasks.project_id")
|
|
34
34
|
|
|
35
35
|
const sql = new MysqlQueryParser({query}).toSql()
|
|
@@ -67,6 +67,7 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
67
67
|
for (let i = 0; i <= 5; i++) {
|
|
68
68
|
const body = new FormData()
|
|
69
69
|
|
|
70
|
+
body.append("project[creating_user_reference]", 150123)
|
|
70
71
|
body.append("project[name]", "Test create project")
|
|
71
72
|
|
|
72
73
|
const response = await fetch(
|
|
@@ -84,6 +85,7 @@ describe("HttpServer - post", {databaseCleaning: {transaction: false, truncate:
|
|
|
84
85
|
|
|
85
86
|
const createdProject = await Project.preload({translations: true}).last()
|
|
86
87
|
|
|
88
|
+
expect(createdProject.creatingUserReference()).toEqual("150123")
|
|
87
89
|
expect(createdProject.name()).toEqual("Test create project")
|
|
88
90
|
}
|
|
89
91
|
})
|
package/src/application.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import AppRoutes from "./routes/app-routes.js"
|
|
3
4
|
import {Logger} from "./logger.js"
|
|
4
5
|
import HttpServer from "./http-server/index.js"
|
|
6
|
+
import restArgsError from "./utils/rest-args-error.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {object} HttpServerConfiguration
|
|
10
|
+
* @property {number} [port]
|
|
11
|
+
*/
|
|
5
12
|
|
|
6
13
|
export default class VelociousApplication {
|
|
7
14
|
/**
|
|
8
15
|
* @param {object} args
|
|
9
|
-
* @param {import("./http-server/index.js").default} args.httpServer
|
|
10
16
|
* @param {import("./configuration.js").default} args.configuration
|
|
17
|
+
* @param {HttpServerConfiguration} [args.httpServer]
|
|
11
18
|
* @param {string} args.type
|
|
12
19
|
*/
|
|
13
|
-
constructor({configuration, httpServer, type}) {
|
|
20
|
+
constructor({configuration, httpServer, type, ...restArgs}) {
|
|
21
|
+
restArgsError(restArgs)
|
|
22
|
+
|
|
23
|
+
if (!configuration) throw new Error("configuration is required")
|
|
24
|
+
|
|
14
25
|
this.configuration = configuration
|
|
15
|
-
|
|
26
|
+
|
|
27
|
+
/** @type {HttpServerConfiguration} */
|
|
28
|
+
this.httpServerConfiguration = httpServer ?? {port: undefined}
|
|
29
|
+
|
|
16
30
|
this.logger = new Logger(this)
|
|
17
31
|
this._type = type
|
|
18
32
|
}
|
|
@@ -41,7 +55,11 @@ export default class VelociousApplication {
|
|
|
41
55
|
* @returns {boolean}
|
|
42
56
|
*/
|
|
43
57
|
isActive() {
|
|
44
|
-
|
|
58
|
+
if (this.httpServer) {
|
|
59
|
+
return this.httpServer?.isActive()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
/**
|
|
@@ -49,7 +67,7 @@ export default class VelociousApplication {
|
|
|
49
67
|
* @returns {Promise<void>}
|
|
50
68
|
*/
|
|
51
69
|
async run(callback) {
|
|
52
|
-
await this.
|
|
70
|
+
await this.startHttpServer()
|
|
53
71
|
|
|
54
72
|
try {
|
|
55
73
|
await callback()
|
|
@@ -62,7 +80,7 @@ export default class VelociousApplication {
|
|
|
62
80
|
* @returns {Promise<void>}
|
|
63
81
|
*/
|
|
64
82
|
async startHttpServer() {
|
|
65
|
-
const {configuration, httpServerConfiguration} =
|
|
83
|
+
const {configuration, httpServerConfiguration} = this
|
|
66
84
|
const port = httpServerConfiguration.port || 3006
|
|
67
85
|
|
|
68
86
|
await this.logger.debug(`Starting server on port ${port}`)
|
|
@@ -78,7 +96,7 @@ export default class VelociousApplication {
|
|
|
78
96
|
*/
|
|
79
97
|
async stop() {
|
|
80
98
|
await this.logger.debug("Stopping server")
|
|
81
|
-
await this.httpServer
|
|
99
|
+
await this.httpServer?.stop()
|
|
82
100
|
}
|
|
83
101
|
|
|
84
102
|
/**
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import Configuration, {CurrentConfigurationNotSetError} from "./configuration.js"
|
|
2
4
|
import envSense from "env-sense/src/use-env-sense.js"
|
|
3
5
|
import fileExists from "./utils/file-exists.js"
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string} args.directory
|
|
8
|
+
* @param {import("./configuration-types.js").ConfigurationArgsType} [args]
|
|
8
9
|
* @returns {Promise<Configuration>}
|
|
9
10
|
*/
|
|
10
|
-
export default async function configurationResolver(args
|
|
11
|
-
|
|
11
|
+
export default async function configurationResolver(args) {
|
|
12
|
+
let configuration
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
configuration = Configuration.current()
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof CurrentConfigurationNotSetError) {
|
|
18
|
+
// Ignore
|
|
19
|
+
} else {
|
|
20
|
+
throw error
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (configuration) {
|
|
12
25
|
return Configuration.current()
|
|
13
26
|
}
|
|
14
27
|
|
|
15
|
-
const directory = args
|
|
28
|
+
const directory = args?.directory || process.cwd()
|
|
16
29
|
let configurationPrePath = `${directory}/src/config/configuration`
|
|
17
30
|
const configurationPathForNode = `${configurationPrePath}.node.js`
|
|
18
31
|
const configurationPathDefault = `${configurationPrePath}.js`
|
|
19
32
|
const {isServer} = envSense()
|
|
20
|
-
let
|
|
33
|
+
let configurationPath
|
|
21
34
|
|
|
22
35
|
if (isServer && await fileExists(configurationPathForNode)) {
|
|
23
36
|
configurationPath = configurationPathForNode
|
|
@@ -30,9 +43,15 @@ export default async function configurationResolver(args = {}) {
|
|
|
30
43
|
|
|
31
44
|
configuration = configurationImport.default
|
|
32
45
|
} catch (error) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
// This might happen during an "init" CLI command where we copy a sample configuration file.
|
|
48
|
+
if (!error.message.match(/^Cannot find module '(.+)\/configuration\.js'/)) {
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!args) {
|
|
54
|
+
throw new Error("Can't spawn a new configuration because no configuration-arguments was given")
|
|
36
55
|
}
|
|
37
56
|
|
|
38
57
|
configuration = new Configuration(args)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {function({request: import("./http-server/client/request.js").default, response: import("./http-server/client/response.js").default}): Promise<void>} CorsType
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {(id: string) => {default: typeof import("./initializer.js").default}} InitializersRequireContextType
|
|
11
|
+
* @typedef {InitializersRequireContextType & {
|
|
12
|
+
* keys: () => string[],
|
|
13
|
+
* id: string
|
|
14
|
+
* }} WebpackRequireContext
|
|
15
|
+
* @typedef {{requireContext: WebpackRequireContext}} InitializersExportType
|
|
16
|
+
* @typedef {function({configuration: import("./configuration.js").default}) : Promise<InitializersExportType>} InitializersType
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {object} DatabaseConfigurationType
|
|
21
|
+
* @property {string} [host]
|
|
22
|
+
* @property {boolean} [migrations]
|
|
23
|
+
* @property {string} [password]
|
|
24
|
+
* @property {string} [username]
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} ConfigurationArgsType
|
|
29
|
+
* @property {object} args
|
|
30
|
+
* @property {CorsType} [cors]
|
|
31
|
+
* @property {{[key: string]: DatabaseConfigurationType}} database
|
|
32
|
+
* @property {boolean} debug
|
|
33
|
+
* @property {string} directory
|
|
34
|
+
* @property {string} environment
|
|
35
|
+
* @property {import("./environment-handlers/base.js").default} environmentHandler
|
|
36
|
+
* @property {function({configuration: import("./configuration.js").default, type: string}) : void} initializeModels
|
|
37
|
+
* @property {InitializersType} initializers
|
|
38
|
+
* @property {string | function() : string} locale
|
|
39
|
+
* @property {string[]} locales
|
|
40
|
+
* @property {object} localeFallbacks
|
|
41
|
+
* @property {string} testing
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
export const nothing = {}
|
package/src/configuration.js
CHANGED
|
@@ -1,59 +1,70 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {digg} from "diggerize"
|
|
2
4
|
import restArgsError from "./utils/rest-args-error.js"
|
|
3
5
|
import {withTrackedStack} from "./utils/with-tracked-stack.js"
|
|
4
6
|
|
|
7
|
+
/** @type {{currentConfiguration: VelociousConfiguration | null}} */
|
|
8
|
+
const shared = {
|
|
9
|
+
currentConfiguration: null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class CurrentConfigurationNotSetError extends Error {}
|
|
13
|
+
|
|
14
|
+
export {CurrentConfigurationNotSetError}
|
|
15
|
+
|
|
5
16
|
export default class VelociousConfiguration {
|
|
6
17
|
/**
|
|
7
18
|
* @returns {VelociousConfiguration}
|
|
8
19
|
*/
|
|
9
|
-
static current(
|
|
10
|
-
if (!
|
|
20
|
+
static current() {
|
|
21
|
+
if (!shared.currentConfiguration) throw new CurrentConfigurationNotSetError("A current configuration hasn't been set")
|
|
11
22
|
|
|
12
|
-
return
|
|
23
|
+
return shared.currentConfiguration
|
|
13
24
|
}
|
|
14
25
|
|
|
15
26
|
/**
|
|
16
|
-
* @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @param {object} args.database
|
|
20
|
-
* @param {boolean} args.debug
|
|
21
|
-
* @param {string} args.directory
|
|
22
|
-
* @param {string} args.environment
|
|
23
|
-
* @param {T} args.environmentHandler
|
|
24
|
-
* @param {function() : void} args.initializeModels
|
|
25
|
-
* @param {function() : void} args.initializers
|
|
26
|
-
* @param {string} args.locale
|
|
27
|
-
* @param {object} args.localeFallbacks
|
|
28
|
-
* @param {string} args.testing
|
|
29
|
-
*/
|
|
30
|
-
constructor({cors, database, debug, directory, environment, environmentHandler, initializeModels, initializers, locale, localeFallbacks, locales, testing, ...restArgs}) {
|
|
27
|
+
* @param {import("./configuration-types.js").ConfigurationArgsType} args
|
|
28
|
+
*/
|
|
29
|
+
constructor({cors, database, debug = false, directory, environment, environmentHandler, initializeModels, initializers, locale, localeFallbacks, locales, testing, ...restArgs}) {
|
|
31
30
|
restArgsError(restArgs)
|
|
32
31
|
|
|
33
32
|
this.cors = cors
|
|
34
33
|
this.database = database
|
|
35
|
-
this.databasePools = {}
|
|
36
34
|
this.debug = debug
|
|
37
35
|
this._environment = environment || process.env.VELOCIOUS_ENV || process.env.NODE_ENV || "development"
|
|
38
36
|
this._environmentHandler = environmentHandler
|
|
39
37
|
this._directory = directory
|
|
40
38
|
this._initializeModels = initializeModels
|
|
41
|
-
this._initializers = initializers
|
|
42
39
|
this._isInitialized = false
|
|
43
40
|
this.locale = locale
|
|
44
41
|
this.localeFallbacks = localeFallbacks
|
|
45
42
|
this.locales = locales
|
|
46
|
-
this.
|
|
43
|
+
this._initializers = initializers
|
|
47
44
|
this._testing = testing
|
|
48
45
|
|
|
46
|
+
/** @type {{[key: string]: import("./database/pool/base.js").default}} */
|
|
47
|
+
this.databasePools = {}
|
|
48
|
+
|
|
49
|
+
/** @type {{[key: string]: typeof import("./database/record/index.js").default}} */
|
|
50
|
+
this.modelClasses = {}
|
|
51
|
+
|
|
49
52
|
this.getEnvironmentHandler().setConfiguration(this)
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @returns {import("./configuration-types.js").CorsType | undefined}
|
|
57
|
+
*/
|
|
58
|
+
getCors() {
|
|
59
|
+
return this.cors
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
/**
|
|
53
63
|
* @returns {Record<string, any>}
|
|
54
64
|
*/
|
|
55
65
|
getDatabaseConfiguration() {
|
|
56
66
|
if (!this.database) throw new Error("No database configuration")
|
|
67
|
+
|
|
57
68
|
if (!this.database[this.getEnvironment()]) {
|
|
58
69
|
throw new Error(`No database configuration for environment: ${this.getEnvironment()} - ${Object.keys(this.database).join(", ")}`)
|
|
59
70
|
}
|
|
@@ -68,6 +79,10 @@ export default class VelociousConfiguration {
|
|
|
68
79
|
return Object.keys(this.getDatabaseConfiguration())
|
|
69
80
|
}
|
|
70
81
|
|
|
82
|
+
/**
|
|
83
|
+
* @param {string} identifier
|
|
84
|
+
* @returns {import("./database/pool/base.js").default}
|
|
85
|
+
*/
|
|
71
86
|
getDatabasePool(identifier = "default") {
|
|
72
87
|
if (!this.isDatabasePoolInitialized(identifier)) {
|
|
73
88
|
this.initializeDatabasePool(identifier)
|
|
@@ -76,12 +91,20 @@ export default class VelociousConfiguration {
|
|
|
76
91
|
return digg(this, "databasePools", identifier)
|
|
77
92
|
}
|
|
78
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @param {string} identifier
|
|
96
|
+
* @returns {import("./configuration-types.js").DatabaseConfigurationType})
|
|
97
|
+
*/
|
|
79
98
|
getDatabaseIdentifier(identifier) {
|
|
80
99
|
if (!this.getDatabaseConfiguration()[identifier]) throw new Error(`No such database identifier configured: ${identifier}`)
|
|
81
100
|
|
|
82
101
|
return this.getDatabaseConfiguration()[identifier]
|
|
83
102
|
}
|
|
84
103
|
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} identifier
|
|
106
|
+
* @returns {typeof import("./database/pool/base.js").default}
|
|
107
|
+
*/
|
|
85
108
|
getDatabasePoolType(identifier = "default") {
|
|
86
109
|
const poolTypeClass = digg(this.getDatabaseIdentifier(identifier), "poolType")
|
|
87
110
|
|
|
@@ -126,8 +149,7 @@ export default class VelociousConfiguration {
|
|
|
126
149
|
setEnvironment(newEnvironment) { this._environment = newEnvironment }
|
|
127
150
|
|
|
128
151
|
/**
|
|
129
|
-
* @
|
|
130
|
-
* @returns {T}
|
|
152
|
+
* @returns {import("./environment-handlers/base.js").default}
|
|
131
153
|
*/
|
|
132
154
|
getEnvironmentHandler() {
|
|
133
155
|
if (!this._environmentHandler) throw new Error("No environment handler set")
|
|
@@ -166,8 +188,7 @@ export default class VelociousConfiguration {
|
|
|
166
188
|
|
|
167
189
|
/**
|
|
168
190
|
* @param {string} name
|
|
169
|
-
* @
|
|
170
|
-
* @returns {T}
|
|
191
|
+
* @returns {typeof import("./database/record/index.js").default}
|
|
171
192
|
*/
|
|
172
193
|
getModelClass(name) {
|
|
173
194
|
const modelClass = this.modelClasses[name]
|
|
@@ -212,7 +233,7 @@ export default class VelociousConfiguration {
|
|
|
212
233
|
/**
|
|
213
234
|
* @param {object} args
|
|
214
235
|
* @param {string} args.type
|
|
215
|
-
* @returns {void}
|
|
236
|
+
* @returns {Promise<void>}
|
|
216
237
|
*/
|
|
217
238
|
async initializeModels(args = {type: "server"}) {
|
|
218
239
|
if (!this._modelsInitialized) {
|
|
@@ -224,7 +245,12 @@ export default class VelociousConfiguration {
|
|
|
224
245
|
}
|
|
225
246
|
}
|
|
226
247
|
|
|
227
|
-
|
|
248
|
+
/**
|
|
249
|
+
* @param {object} args
|
|
250
|
+
* @param {string} args.type
|
|
251
|
+
* @returns {Promise<void>}
|
|
252
|
+
*/
|
|
253
|
+
async initialize({type} = {type: "undefined"}) {
|
|
228
254
|
if (!this.isInitialized()) {
|
|
229
255
|
this._isInitialized = true
|
|
230
256
|
|
|
@@ -249,7 +275,8 @@ export default class VelociousConfiguration {
|
|
|
249
275
|
}
|
|
250
276
|
|
|
251
277
|
/**
|
|
252
|
-
* @param {
|
|
278
|
+
* @param {typeof import("./database/record/index.js").default} modelClass
|
|
279
|
+
* @returns {void}
|
|
253
280
|
*/
|
|
254
281
|
registerModelClass(modelClass) {
|
|
255
282
|
this.modelClasses[modelClass.name] = modelClass
|
|
@@ -259,10 +286,11 @@ export default class VelociousConfiguration {
|
|
|
259
286
|
* @returns {void}
|
|
260
287
|
*/
|
|
261
288
|
setCurrent() {
|
|
262
|
-
|
|
289
|
+
shared.currentConfiguration = this
|
|
263
290
|
}
|
|
264
291
|
|
|
265
292
|
/**
|
|
293
|
+
* @param {import("./routes/index.js").default} newRoutes
|
|
266
294
|
* @returns {void}
|
|
267
295
|
*/
|
|
268
296
|
setRoutes(newRoutes) { this.routes = newRoutes }
|
|
@@ -275,7 +303,7 @@ export default class VelociousConfiguration {
|
|
|
275
303
|
|
|
276
304
|
/**
|
|
277
305
|
* @param {string} msgID
|
|
278
|
-
* @param {
|
|
306
|
+
* @param {undefined | {defaultValue: string}} args
|
|
279
307
|
* @returns {string}
|
|
280
308
|
*/
|
|
281
309
|
_defaultTranslator(msgID, args) {
|
|
@@ -296,7 +324,9 @@ export default class VelociousConfiguration {
|
|
|
296
324
|
* @returns {Promise<void>}
|
|
297
325
|
*/
|
|
298
326
|
async withConnections(callback) {
|
|
327
|
+
/** @type {{[key: string]: import("./database/drivers/base.js").default}} */
|
|
299
328
|
const dbs = {}
|
|
329
|
+
|
|
300
330
|
const stack = Error().stack
|
|
301
331
|
const actualCallback = async () => {
|
|
302
332
|
await withTrackedStack(stack, async () => {
|
|
@@ -324,17 +354,17 @@ export default class VelociousConfiguration {
|
|
|
324
354
|
}
|
|
325
355
|
|
|
326
356
|
/**
|
|
327
|
-
* @
|
|
328
|
-
* @returns {Record<string, T>} A map of database connections with identifier as key
|
|
357
|
+
* @returns {Record<string, import("./database/drivers/base.js").default>} A map of database connections with identifier as key
|
|
329
358
|
*/
|
|
330
359
|
getCurrentConnections() {
|
|
360
|
+
/** @type {{[key: string]: import("./database/drivers/base.js").default}} */
|
|
331
361
|
const dbs = {}
|
|
332
362
|
|
|
333
363
|
for (const identifier of this.getDatabaseIdentifiers()) {
|
|
334
364
|
try {
|
|
335
365
|
dbs[identifier] = this.getDatabasePool(identifier).getCurrentConnection()
|
|
336
366
|
} catch (error) {
|
|
337
|
-
if (error.message == "ID hasn't been set for this async context" || error.message == "A connection hasn't been made yet") {
|
|
367
|
+
if (error instanceof Error && (error.message == "ID hasn't been set for this async context" || error.message == "A connection hasn't been made yet")) {
|
|
338
368
|
// Ignore
|
|
339
369
|
} else {
|
|
340
370
|
throw error
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import TableColumn from "../table-data/table-column.js"
|
|
2
4
|
import TableData from "../table-data/index.js"
|
|
3
5
|
|
|
4
6
|
export default class VelociousDatabaseDriversBaseColumn {
|
|
7
|
+
/** @type {import("./base-table.js").default | undefined} */
|
|
8
|
+
table = undefined
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* @interface
|
|
7
12
|
* @returns {boolean}
|
|
@@ -19,7 +24,7 @@ export default class VelociousDatabaseDriversBaseColumn {
|
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* @param {string} indexName
|
|
22
|
-
* @returns {Promise<import(
|
|
27
|
+
* @returns {Promise<import("./base-columns-index.js").default | undefined>}
|
|
23
28
|
*/
|
|
24
29
|
async getIndexByName(indexName) {
|
|
25
30
|
const indexes = await this.getIndexes()
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {digg} from "diggerize"
|
|
2
4
|
|
|
3
5
|
export default class VelociousDatabaseDriversBaseColumnsIndex {
|
|
4
6
|
/**
|
|
@@ -40,6 +42,14 @@ export default class VelociousDatabaseDriversBaseColumnsIndex {
|
|
|
40
42
|
return this.table
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @interface
|
|
47
|
+
* @returns {import("../table-data/table-index.js").default}
|
|
48
|
+
*/
|
|
49
|
+
getTableDataIndex() {
|
|
50
|
+
throw new Error("'getTableDataIndex' not implemented")
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
/**
|
|
44
54
|
* @returns {boolean}
|
|
45
55
|
*/
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import TableForeignKey from "../table-data/table-foreign-key.js"
|
|
2
4
|
|
|
3
5
|
export default class VelociousDatabaseDriversBaseForeignKey {
|
|
6
|
+
/** @type {import("./base-table.js").default | undefined} */
|
|
7
|
+
table = undefined
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* @param {object} data
|
|
6
11
|
*/
|
|
@@ -8,6 +13,14 @@ export default class VelociousDatabaseDriversBaseForeignKey {
|
|
|
8
13
|
this.data = data
|
|
9
14
|
}
|
|
10
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @interface
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
getColumnName() {
|
|
21
|
+
throw new Error(`'getColumnName' not implemented`)
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
/**
|
|
12
25
|
* @returns {import("./base.js").default}
|
|
13
26
|
*/
|
|
@@ -15,6 +28,14 @@ export default class VelociousDatabaseDriversBaseForeignKey {
|
|
|
15
28
|
return this.getTable().getDriver()
|
|
16
29
|
}
|
|
17
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @interface
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
getName() {
|
|
36
|
+
throw new Error(`'getName' not implemented`)
|
|
37
|
+
}
|
|
38
|
+
|
|
18
39
|
/**
|
|
19
40
|
* @returns {import("../query-parser/options.js").default}
|
|
20
41
|
*/
|
|
@@ -22,6 +43,22 @@ export default class VelociousDatabaseDriversBaseForeignKey {
|
|
|
22
43
|
return this.getDriver().options()
|
|
23
44
|
}
|
|
24
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @interface
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
getReferencedColumnName() {
|
|
51
|
+
throw new Error(`'getReferencedColumnName' not implemented`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @interface
|
|
56
|
+
* @returns {string}
|
|
57
|
+
*/
|
|
58
|
+
getReferencedTableName() {
|
|
59
|
+
throw new Error(`'getReferencedTableName' not implemented`)
|
|
60
|
+
}
|
|
61
|
+
|
|
25
62
|
/**
|
|
26
63
|
* @returns {import("./base-table.js").default}
|
|
27
64
|
*/
|
|
@@ -31,6 +68,14 @@ export default class VelociousDatabaseDriversBaseForeignKey {
|
|
|
31
68
|
return this.table
|
|
32
69
|
}
|
|
33
70
|
|
|
71
|
+
/**
|
|
72
|
+
* @interface
|
|
73
|
+
* @returns {string}
|
|
74
|
+
*/
|
|
75
|
+
getTableName() {
|
|
76
|
+
throw new Error("'getTableName' not implemented")
|
|
77
|
+
}
|
|
78
|
+
|
|
34
79
|
/**
|
|
35
80
|
* @returns {TableForeignKey}
|
|
36
81
|
*/
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import {digg} from "diggerize"
|
|
2
4
|
import TableData from "../table-data/index.js"
|
|
3
5
|
|
|
4
6
|
export default class VelociousDatabaseDriversBaseTable {
|
|
7
|
+
/** @type {import("./base.js").default | undefined} */
|
|
8
|
+
driver = undefined
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* @param {string} columnName
|
|
7
|
-
* @returns {import("./base-column.js").default}
|
|
12
|
+
* @returns {Promise<import("./base-column.js").default | undefined>}
|
|
8
13
|
*/
|
|
9
14
|
async getColumnByName(columnName) {
|
|
10
15
|
const columnes = await this.getColumns()
|
|
@@ -30,6 +35,22 @@ export default class VelociousDatabaseDriversBaseTable {
|
|
|
30
35
|
return this.driver
|
|
31
36
|
}
|
|
32
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @interface
|
|
40
|
+
* @returns {Promise<import("./base-foreign-key.js").default[]>}
|
|
41
|
+
*/
|
|
42
|
+
getForeignKeys() {
|
|
43
|
+
throw new Error("'getForeignKeys' not implemented")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @interface
|
|
48
|
+
* @returns {Promise<import("./base-columns-index.js").default[]>}
|
|
49
|
+
*/
|
|
50
|
+
getIndexes() {
|
|
51
|
+
throw new Error("'getForeignKeys' not implemented")
|
|
52
|
+
}
|
|
53
|
+
|
|
33
54
|
/**
|
|
34
55
|
* @interface
|
|
35
56
|
* @returns {string}
|
|
@@ -86,6 +107,7 @@ export default class VelociousDatabaseDriversBaseTable {
|
|
|
86
107
|
}
|
|
87
108
|
|
|
88
109
|
/**
|
|
110
|
+
* @param {{cascade: boolean}} [args]
|
|
89
111
|
* @returns {Promise<Array<Record<string, any>>>}
|
|
90
112
|
*/
|
|
91
113
|
async truncate(args) {
|
|
@@ -102,6 +124,6 @@ export default class VelociousDatabaseDriversBaseTable {
|
|
|
102
124
|
}
|
|
103
125
|
}
|
|
104
126
|
|
|
105
|
-
await this.getDriver().query(sql)
|
|
127
|
+
return await this.getDriver().query(sql)
|
|
106
128
|
}
|
|
107
129
|
}
|