velocious 1.0.84 → 1.0.86
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/bin/velocious.js +10 -1
- package/eslint.config.js +33 -0
- package/package.json +7 -2
- package/peak_flow.yml +6 -0
- package/spec/cli/commands/db/create-spec.js +4 -0
- package/spec/cli/commands/db/migrate-spec.js +4 -2
- package/spec/cli/commands/db/rollback-spec.js +179 -0
- package/spec/cli/commands/destroy/migration-spec.js +4 -0
- package/spec/cli/commands/generate/migration-spec.js +4 -0
- package/spec/cli/commands/init-spec.js +4 -0
- package/spec/dummy/index.js +7 -4
- package/spec/dummy/src/config/configuration.example.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.mariadb.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.mssql.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.pgsql.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.sqlite.js +2 -0
- package/spec/dummy/src/database/migrations/20250921121002-create-project-details.js +3 -1
- package/src/application.js +12 -0
- package/src/cli/base-command.js +9 -5
- package/src/cli/browser-cli.js +37 -0
- package/src/cli/commands/db/create.js +5 -5
- package/src/cli/commands/db/drop.js +4 -5
- package/src/cli/commands/db/migrate.js +6 -10
- package/src/cli/commands/db/reset.js +8 -12
- package/src/cli/commands/db/rollback.js +15 -0
- package/src/cli/commands/destroy/migration.js +2 -2
- package/src/cli/commands/generate/migration.js +3 -6
- package/src/cli/commands/generate/model.js +3 -6
- package/src/cli/commands/init.js +5 -8
- package/src/cli/commands/server.js +4 -3
- package/src/cli/commands/test.js +1 -1
- package/src/cli/index.js +15 -40
- package/src/cli/use-browser-cli.js +25 -0
- package/src/configuration-resolver.js +1 -1
- package/src/configuration.js +118 -9
- package/src/controller.js +29 -0
- package/src/database/drivers/base-column.js +14 -0
- package/src/database/drivers/base-columns-index.js +3 -0
- package/src/database/drivers/base-foreign-key.js +3 -0
- package/src/database/drivers/base-table.js +3 -0
- package/src/database/drivers/base.js +55 -1
- package/src/database/drivers/mssql/index.js +64 -1
- package/src/database/drivers/mysql/columns-index.js +0 -1
- package/src/database/drivers/sqlite/base.js +39 -0
- package/src/database/drivers/sqlite/connection-remote.js +1 -1
- package/src/database/drivers/sqlite/sql/alter-table.js +1 -1
- package/src/database/drivers/sqlite/sql/delete.js +15 -10
- package/src/database/migration/index.js +122 -1
- package/src/database/migrator/files-finder.js +13 -1
- package/src/database/migrator.js +125 -24
- package/src/database/pool/single-multi-use.js +1 -1
- package/src/database/query/alter-table-base.js +11 -0
- package/src/database/query/base.js +7 -0
- package/src/database/query/create-database-base.js +3 -0
- package/src/database/query/create-index-base.js +3 -1
- package/src/database/query/create-table-base.js +3 -0
- package/src/database/query/drop-table-base.js +4 -1
- package/src/database/query/from-base.js +7 -0
- package/src/database/query/index.js +105 -1
- package/src/database/query/insert-base.js +6 -0
- package/src/database/query/join-base.js +3 -0
- package/src/database/query/order-base.js +3 -0
- package/src/database/query/select-base.js +3 -0
- package/src/database/query/update-base.js +3 -0
- package/src/database/query/where-base.js +3 -0
- package/src/database/record/index.js +321 -14
- package/src/database/record/instance-relationships/base.js +66 -1
- package/src/database/record/relationships/base.js +41 -1
- package/src/database/record/validators/base.js +10 -0
- package/src/database/record/validators/presence.js +1 -1
- package/src/database/table-data/table-column.js +37 -3
- package/src/database/table-data/table-index.js +1 -1
- package/src/database/use-database.js +2 -2
- package/src/environment-handlers/base.js +53 -0
- package/src/environment-handlers/browser.js +171 -0
- package/src/environment-handlers/node.js +162 -0
- package/src/http-server/client/request-buffer/index.js +9 -9
- package/src/http-server/index.js +6 -0
- package/src/http-server/worker-handler/index.js +20 -19
- package/src/initializer.js +17 -1
- package/src/logger.js +3 -0
- package/src/routes/app-routes.js +6 -2
- package/src/routes/base-route.js +1 -1
- package/src/routes/get-route.js +1 -1
- package/src/routes/namespace-route.js +1 -1
- package/src/routes/post-route.js +1 -1
- package/src/routes/resolver.js +1 -1
- package/src/routes/resource-route.js +1 -1
- package/src/templates/configuration.js +4 -0
- package/src/testing/request-client.js +26 -3
- package/src/testing/test-files-finder.js +2 -2
- package/src/testing/test-runner.js +74 -28
- package/src/testing/test.js +62 -0
- package/src/utils/file-exists.js +7 -5
- package/src/utils/rest-args-error.js +5 -3
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
3
|
import Migrator from "../../../database/migrator.js"
|
|
4
4
|
|
|
5
5
|
export default class DbReset extends BaseCommand {
|
|
6
6
|
async execute() {
|
|
7
|
-
const environment = this.
|
|
7
|
+
const environment = this.getConfiguration().getEnvironment()
|
|
8
8
|
|
|
9
9
|
if (environment != "development" && environment != "test") {
|
|
10
10
|
throw new Error(`This command should only be executed on development and test environments and not: ${environment}`)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const filesFinder = new FilesFinder({path: migrationsPath})
|
|
16
|
-
const files = await filesFinder.findFiles()
|
|
13
|
+
const migrations = await this.getEnvironmentHandler().findMigrations()
|
|
14
|
+
const migrator = new Migrator({configuration: this.getConfiguration()})
|
|
17
15
|
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
await
|
|
22
|
-
await this.migrator.prepare()
|
|
23
|
-
await this.migrator.migrateFiles(files, async (importPath) => await import(importPath))
|
|
16
|
+
await this.getConfiguration().ensureConnections(async () => {
|
|
17
|
+
await migrator.reset()
|
|
18
|
+
await migrator.prepare()
|
|
19
|
+
await migrator.migrateFiles(migrations, digg(this.getEnvironmentHandler(), "requireMigration"))
|
|
24
20
|
})
|
|
25
21
|
}
|
|
26
22
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import BaseCommand from "../../base-command.js"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import Migrator from "../../../database/migrator.js"
|
|
4
|
+
|
|
5
|
+
export default class DbRollback extends BaseCommand {
|
|
6
|
+
async execute() {
|
|
7
|
+
const migrations = await this.getEnvironmentHandler().findMigrations()
|
|
8
|
+
const migrator = new Migrator({configuration: this.getConfiguration()})
|
|
9
|
+
|
|
10
|
+
await this.getConfiguration().ensureConnections(async () => {
|
|
11
|
+
await migrator.prepare()
|
|
12
|
+
await migrator.rollback(migrations, digg(this.getEnvironmentHandler(), "requireMigration"))
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import fs from "
|
|
2
|
+
import fs from "fs/promises"
|
|
3
3
|
|
|
4
4
|
export default class DbDestroyMigration extends BaseCommand {
|
|
5
5
|
async execute() {
|
|
6
6
|
const migrationName = this.processArgs[1]
|
|
7
|
-
const migrationDir = `${this.
|
|
7
|
+
const migrationDir = `${this.getConfiguration().getDirectory()}/src/database/migrations`
|
|
8
8
|
const migrationFiles = await fs.readdir(migrationDir)
|
|
9
9
|
const destroyed = []
|
|
10
10
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import {dirname} from "path"
|
|
3
|
-
import {fileURLToPath} from "url"
|
|
4
2
|
import fileExists from "../../../utils/file-exists.js"
|
|
5
|
-
import fs from "
|
|
3
|
+
import fs from "fs/promises"
|
|
6
4
|
import * as inflection from "inflection"
|
|
7
5
|
import strftime from "strftime"
|
|
8
6
|
|
|
@@ -13,9 +11,8 @@ export default class DbGenerateMigration extends BaseCommand {
|
|
|
13
11
|
const date = new Date()
|
|
14
12
|
const migrationNumber = strftime("%Y%m%d%H%M%S")
|
|
15
13
|
const migrationFileName = `${migrationNumber}-${migrationName}.js`
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const templateFilePath = `${__dirname}/../../../templates/generate-migration.js`
|
|
14
|
+
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
15
|
+
const templateFilePath = `${velociousPath}/src/templates/generate-migration.js`
|
|
19
16
|
const migrationContentBuffer = await fs.readFile(templateFilePath)
|
|
20
17
|
const migrationContent = migrationContentBuffer.toString().replaceAll("__MIGRATION_NAME__", migrationNameCamelized)
|
|
21
18
|
const migrationDir = `${process.cwd()}/src/database/migrations`
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import {dirname} from "path"
|
|
3
|
-
import {fileURLToPath} from "url"
|
|
4
2
|
import fileExists from "../../../utils/file-exists.js"
|
|
5
|
-
import fs from "
|
|
3
|
+
import fs from "fs/promises"
|
|
6
4
|
import * as inflection from "inflection"
|
|
7
5
|
|
|
8
6
|
export default class DbGenerateModel extends BaseCommand {
|
|
@@ -11,9 +9,8 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
11
9
|
const modelNameCamelized = inflection.camelize(modelName.replaceAll("-", "_"))
|
|
12
10
|
const date = new Date()
|
|
13
11
|
const modelFileName = `${inflection.dasherize(inflection.underscore(modelName))}.js`
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const templateFilePath = `${__dirname}/templates/generate-model.js`
|
|
12
|
+
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
13
|
+
const templateFilePath = `${velociousPath}/src/templates/generate-model.js`
|
|
17
14
|
const modelContentBuffer = await fs.readFile(templateFilePath)
|
|
18
15
|
const modelContent = modelContentBuffer.toString().replaceAll("__MODEL_NAME__", modelNameCamelized)
|
|
19
16
|
const modelsDir = `${process.cwd()}/src/models`
|
package/src/cli/commands/init.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import BaseCommand from "../base-command.js"
|
|
2
|
-
import {dirname} from "path"
|
|
3
2
|
import fileExists from "../../utils/file-exists.js"
|
|
4
|
-
import
|
|
5
|
-
import fs from "node:fs/promises"
|
|
3
|
+
import fs from "fs/promises"
|
|
6
4
|
|
|
7
5
|
export default class VelociousCliCommandsInit extends BaseCommand {
|
|
8
6
|
async execute() {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const projectPath = this.configuration?.getDirectory() || process.cwd()
|
|
7
|
+
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
8
|
+
const projectPath = this.getConfiguration()?.getDirectory() || process.cwd()
|
|
12
9
|
const projectConfigPath = `${projectPath}/src/config`
|
|
13
10
|
const fileMappings = [
|
|
14
11
|
{
|
|
15
|
-
source: `${
|
|
12
|
+
source: `${velociousPath}/src/templates/configuration.js`,
|
|
16
13
|
target: `${projectConfigPath}/configuration.js`
|
|
17
14
|
},
|
|
18
15
|
{
|
|
19
|
-
source: `${
|
|
16
|
+
source: `${velociousPath}/src/templates/routes.js`,
|
|
20
17
|
target: `${projectConfigPath}/routes.js`
|
|
21
18
|
}
|
|
22
19
|
]
|
|
@@ -3,7 +3,7 @@ import BaseCommand from "../base-command.js"
|
|
|
3
3
|
|
|
4
4
|
export default class VelociousCliCommandsServer extends BaseCommand{
|
|
5
5
|
async execute() {
|
|
6
|
-
this.databasePool = this.
|
|
6
|
+
this.databasePool = this.getConfiguration().getDatabasePool()
|
|
7
7
|
this.newConfiguration = Object.assign({}, this.databasePool.getConfiguration())
|
|
8
8
|
this.databaseConnection = await this.databasePool.spawnConnectionWithConfiguration(this.newConfiguration)
|
|
9
9
|
|
|
@@ -13,17 +13,18 @@ export default class VelociousCliCommandsServer extends BaseCommand{
|
|
|
13
13
|
const host = parsedProcessArgs.h || parsedProcessArgs.host || "127.0.0.1"
|
|
14
14
|
const port = parsedProcessArgs.p || parsedProcessArgs.port || 3006
|
|
15
15
|
const application = new Application({
|
|
16
|
-
configuration: this.
|
|
16
|
+
configuration: this.getConfiguration(),
|
|
17
17
|
httpServer: {
|
|
18
18
|
host,
|
|
19
19
|
port
|
|
20
20
|
},
|
|
21
21
|
type: "server"
|
|
22
22
|
})
|
|
23
|
+
const environment = this.getConfiguration().getEnvironment()
|
|
23
24
|
|
|
24
25
|
await application.initialize()
|
|
25
26
|
await application.startHttpServer()
|
|
26
|
-
console.log(`Started Velocious HTTP server on ${host}:${port}`)
|
|
27
|
+
console.log(`Started Velocious HTTP server on ${host}:${port} in ${environment} environment`)
|
|
27
28
|
await application.wait()
|
|
28
29
|
}
|
|
29
30
|
}
|
package/src/cli/commands/test.js
CHANGED
|
@@ -9,7 +9,7 @@ export default class VelociousCliCommandsTest extends BaseCommand {
|
|
|
9
9
|
const directory = process.env.VELOCIOUS_TEST_DIR || this.directory()
|
|
10
10
|
const testFilesFinder = new TestFilesFinder({directory, processArgs: this.processArgs})
|
|
11
11
|
const testFiles = await testFilesFinder.findTestFiles()
|
|
12
|
-
const testRunner = new TestRunner({configuration: this.
|
|
12
|
+
const testRunner = new TestRunner({configuration: this.getConfiguration(), testFiles})
|
|
13
13
|
|
|
14
14
|
await testRunner.prepare()
|
|
15
15
|
|
package/src/cli/index.js
CHANGED
|
@@ -1,51 +1,29 @@
|
|
|
1
|
-
import {dirname} from "path"
|
|
2
|
-
import {fileURLToPath} from "url"
|
|
3
|
-
import fs from "fs/promises"
|
|
4
|
-
|
|
5
|
-
import configurationResolver from "../configuration-resolver.js"
|
|
6
|
-
import fileExists from "../utils/file-exists.js"
|
|
7
|
-
|
|
8
1
|
export default class VelociousCli {
|
|
9
2
|
constructor(args = {}) {
|
|
3
|
+
if (!args.configuration) throw new Error("configuration argument is required")
|
|
4
|
+
|
|
10
5
|
this.args = args
|
|
6
|
+
this.configuration = args.configuration
|
|
7
|
+
|
|
8
|
+
this.environmentHandler = args.configuration.getEnvironmentHandler()
|
|
9
|
+
this.environmentHandler.setArgs(args)
|
|
10
|
+
this.environmentHandler.setConfiguration(args.configuration)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async execute() {
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
15
|
-
const basePath = await fs.realpath(`${dirname(__filename)}/../..`)
|
|
16
14
|
const commandParts = this.args.processArgs[0].split(":")
|
|
17
|
-
const
|
|
18
|
-
let filePath = `${basePath}/src/cli/commands`
|
|
15
|
+
const parsedCommandParts = []
|
|
19
16
|
|
|
20
17
|
for (let commandPart of commandParts) {
|
|
21
18
|
if (commandPart == "d") commandPart = "destroy"
|
|
22
19
|
if (commandPart == "g") commandPart = "generate"
|
|
23
20
|
if (commandPart == "s") commandPart = "server"
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
parsedCommandParts.push(commandPart)
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
filePaths.push(filePath)
|
|
31
|
-
|
|
32
|
-
let fileFound
|
|
33
|
-
|
|
34
|
-
for (const aFilePath of filePaths) {
|
|
35
|
-
if (await fileExists(aFilePath)) {
|
|
36
|
-
fileFound = aFilePath
|
|
37
|
-
break
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!fileFound) throw new Error(`Unknown command: ${this.args.processArgs[0]} which should have been one of ${filePaths.join(", ")}`)
|
|
42
|
-
|
|
43
|
-
const commandClassImport = await import(fileFound)
|
|
44
|
-
const CommandClass = commandClassImport.default
|
|
45
|
-
|
|
46
|
-
await this.loadConfiguration()
|
|
47
|
-
|
|
48
|
-
const commandInstance = new CommandClass(this.args)
|
|
25
|
+
const CommandClass = await this.environmentHandler.requireCommand({commandParts: parsedCommandParts})
|
|
26
|
+
const commandInstance = new CommandClass({args: this.args, environmentHandler: this.environmentHandler})
|
|
49
27
|
|
|
50
28
|
if (commandInstance.initialize) {
|
|
51
29
|
await commandInstance.initialize()
|
|
@@ -54,11 +32,8 @@ export default class VelociousCli {
|
|
|
54
32
|
return await commandInstance.execute()
|
|
55
33
|
}
|
|
56
34
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getConfiguration() { return this.args.configuration }
|
|
35
|
+
/**
|
|
36
|
+
* @returns {import("../configuration.js").default} configuration
|
|
37
|
+
*/
|
|
38
|
+
getConfiguration() { return this.configuration }
|
|
64
39
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import BrowserCli from "./browser-cli.js"
|
|
3
|
+
import restArgsError from "../utils/rest-args-error.js"
|
|
4
|
+
|
|
5
|
+
const shared = {}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} args
|
|
9
|
+
* @param {import("../configuration.js").default} args.configuration
|
|
10
|
+
* @returns {Promise<BrowserCli>} browserCli
|
|
11
|
+
*/
|
|
12
|
+
export default function velociousUseBrowserCli({configuration, ...restArgs}) {
|
|
13
|
+
const browserCli = React.useMemo(async () => {
|
|
14
|
+
if (!shared.browserCli) {
|
|
15
|
+
shared.browserCli = new BrowserCli({configuration})
|
|
16
|
+
shared.browserCli.enable()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return shared.browserCli
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
restArgsError(restArgs)
|
|
23
|
+
|
|
24
|
+
return browserCli
|
|
25
|
+
}
|
|
@@ -2,7 +2,7 @@ import Configuration from "./configuration.js"
|
|
|
2
2
|
import envSense from "env-sense/src/use-env-sense.js"
|
|
3
3
|
import fileExists from "./utils/file-exists.js"
|
|
4
4
|
|
|
5
|
-
const configurationResolver = async (args) => {
|
|
5
|
+
const configurationResolver = async (args = {}) => {
|
|
6
6
|
if (Configuration.current(false)) {
|
|
7
7
|
return Configuration.current()
|
|
8
8
|
}
|
package/src/configuration.js
CHANGED
|
@@ -3,13 +3,31 @@ import restArgsError from "./utils/rest-args-error.js"
|
|
|
3
3
|
import {withTrackedStack} from "./utils/with-tracked-stack.js"
|
|
4
4
|
|
|
5
5
|
export default class VelociousConfiguration {
|
|
6
|
+
/**
|
|
7
|
+
* @returns {VelociousConfiguration}
|
|
8
|
+
*/
|
|
6
9
|
static current(throwError = true) {
|
|
7
10
|
if (!this.velociousConfiguration && throwError) throw new Error("A Velocious configuration hasn't been set")
|
|
8
11
|
|
|
9
12
|
return this.velociousConfiguration
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @template T extends import("./environment-handlers/base.js").default
|
|
17
|
+
* @param {object} args
|
|
18
|
+
* @param {function() : void} args.cors
|
|
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}) {
|
|
13
31
|
restArgsError(restArgs)
|
|
14
32
|
|
|
15
33
|
this.cors = cors
|
|
@@ -17,6 +35,7 @@ export default class VelociousConfiguration {
|
|
|
17
35
|
this.databasePools = {}
|
|
18
36
|
this.debug = debug
|
|
19
37
|
this._environment = environment || process.env.VELOCIOUS_ENV || process.env.NODE_ENV || "development"
|
|
38
|
+
this._environmentHandler = environmentHandler
|
|
20
39
|
this._directory = directory
|
|
21
40
|
this._initializeModels = initializeModels
|
|
22
41
|
this._initializers = initializers
|
|
@@ -26,14 +45,22 @@ export default class VelociousConfiguration {
|
|
|
26
45
|
this.locales = locales
|
|
27
46
|
this.modelClasses = {}
|
|
28
47
|
this._testing = testing
|
|
48
|
+
|
|
49
|
+
this.getEnvironmentHandler().setConfiguration(this)
|
|
29
50
|
}
|
|
30
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @returns {object}
|
|
54
|
+
*/
|
|
31
55
|
getDatabaseConfiguration() {
|
|
32
56
|
if (!this.database) throw new Error("No database configuration")
|
|
33
57
|
|
|
34
58
|
return digg(this, "database", this.getEnvironment())
|
|
35
59
|
}
|
|
36
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @returns {Array<string>}
|
|
63
|
+
*/
|
|
37
64
|
getDatabaseIdentifiers() {
|
|
38
65
|
return Object.keys(this.getDatabaseConfiguration())
|
|
39
66
|
}
|
|
@@ -62,6 +89,9 @@ export default class VelociousConfiguration {
|
|
|
62
89
|
return poolTypeClass
|
|
63
90
|
}
|
|
64
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @returns {string} The database type.
|
|
94
|
+
*/
|
|
65
95
|
getDatabaseType(identifier = "default") {
|
|
66
96
|
const databaseType = digg(this.getDatabaseIdentifier(identifier), "type")
|
|
67
97
|
|
|
@@ -70,6 +100,9 @@ export default class VelociousConfiguration {
|
|
|
70
100
|
return databaseType
|
|
71
101
|
}
|
|
72
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @returns {string}
|
|
105
|
+
*/
|
|
73
106
|
getDirectory() {
|
|
74
107
|
if (!this._directory) {
|
|
75
108
|
this._directory = process.cwd()
|
|
@@ -78,12 +111,41 @@ export default class VelociousConfiguration {
|
|
|
78
111
|
return this._directory
|
|
79
112
|
}
|
|
80
113
|
|
|
114
|
+
/**
|
|
115
|
+
* @returns {string}
|
|
116
|
+
*/
|
|
81
117
|
getEnvironment() { return digg(this, "_environment") }
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} newEnvironment
|
|
121
|
+
* @returns {void}
|
|
122
|
+
*/
|
|
82
123
|
setEnvironment(newEnvironment) { this._environment = newEnvironment }
|
|
83
124
|
|
|
125
|
+
/**
|
|
126
|
+
* @template T extends import("./environment-handlers/base.js").default
|
|
127
|
+
* @returns {T}
|
|
128
|
+
*/
|
|
129
|
+
getEnvironmentHandler() {
|
|
130
|
+
if (!this._environmentHandler) throw new Error("No environment handler set")
|
|
131
|
+
|
|
132
|
+
return this._environmentHandler
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @returns {object}
|
|
137
|
+
*/
|
|
84
138
|
getLocaleFallbacks() { return this.localeFallbacks }
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {object} newLocaleFallbacks
|
|
142
|
+
* @returns {void}
|
|
143
|
+
*/
|
|
85
144
|
setLocaleFallbacks(newLocaleFallbacks) { this.localeFallbacks = newLocaleFallbacks }
|
|
86
145
|
|
|
146
|
+
/**
|
|
147
|
+
* @returns {string}
|
|
148
|
+
*/
|
|
87
149
|
getLocale() {
|
|
88
150
|
if (typeof this.locale == "function") {
|
|
89
151
|
return this.locale()
|
|
@@ -94,8 +156,16 @@ export default class VelociousConfiguration {
|
|
|
94
156
|
}
|
|
95
157
|
}
|
|
96
158
|
|
|
159
|
+
/**
|
|
160
|
+
* @returns {Array<string>}
|
|
161
|
+
*/
|
|
97
162
|
getLocales() { return digg(this, "locales") }
|
|
98
163
|
|
|
164
|
+
/**
|
|
165
|
+
* @param {string} name
|
|
166
|
+
* @template T extends import("./database/record/index.js").default
|
|
167
|
+
* @returns {T}
|
|
168
|
+
*/
|
|
99
169
|
getModelClass(name) {
|
|
100
170
|
const modelClass = this.modelClasses[name]
|
|
101
171
|
|
|
@@ -104,8 +174,14 @@ export default class VelociousConfiguration {
|
|
|
104
174
|
return modelClass
|
|
105
175
|
}
|
|
106
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @returns {string} The path to a config file that should be used for testing.
|
|
179
|
+
*/
|
|
107
180
|
getTesting() { return this._testing }
|
|
108
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @returns {void}
|
|
184
|
+
*/
|
|
109
185
|
initializeDatabasePool(identifier = "default") {
|
|
110
186
|
if (!this.database) throw new Error("No 'database' was given")
|
|
111
187
|
if (this.databasePools[identifier]) throw new Error("DatabasePool has already been initialized")
|
|
@@ -117,6 +193,10 @@ export default class VelociousConfiguration {
|
|
|
117
193
|
}
|
|
118
194
|
|
|
119
195
|
isDatabasePoolInitialized(identifier = "default") { return Boolean(this.databasePools[identifier]) }
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @returns {boolean}
|
|
199
|
+
*/
|
|
120
200
|
isInitialized() { return this._isInitialized }
|
|
121
201
|
|
|
122
202
|
async initialize({type} = {}) {
|
|
@@ -145,32 +225,53 @@ export default class VelociousConfiguration {
|
|
|
145
225
|
}
|
|
146
226
|
}
|
|
147
227
|
|
|
228
|
+
/**
|
|
229
|
+
* @param {Function} modelClass
|
|
230
|
+
*/
|
|
148
231
|
registerModelClass(modelClass) {
|
|
149
232
|
this.modelClasses[modelClass.name] = modelClass
|
|
150
233
|
}
|
|
151
234
|
|
|
235
|
+
/**
|
|
236
|
+
* @returns {void}
|
|
237
|
+
*/
|
|
152
238
|
setCurrent() {
|
|
153
239
|
this.constructor.velociousConfiguration = this
|
|
154
240
|
}
|
|
155
241
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
242
|
+
/**
|
|
243
|
+
* @returns {void}
|
|
244
|
+
*/
|
|
245
|
+
setRoutes(newRoutes) { this.routes = newRoutes }
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @param {Function} callback
|
|
249
|
+
* @returns {void}
|
|
250
|
+
*/
|
|
251
|
+
setTranslator(callback) { this._translator = callback }
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @param {string} msgID
|
|
255
|
+
* @param {object} args
|
|
256
|
+
* @returns {string}
|
|
257
|
+
*/
|
|
164
258
|
_defaultTranslator(msgID, args) {
|
|
165
259
|
if (args?.defaultValue) return args.defaultValue
|
|
166
260
|
|
|
167
261
|
return msgID
|
|
168
262
|
}
|
|
169
263
|
|
|
264
|
+
/**
|
|
265
|
+
* @returns {Function}
|
|
266
|
+
*/
|
|
170
267
|
getTranslator() {
|
|
171
268
|
return this._translator || this._defaultTranslator
|
|
172
269
|
}
|
|
173
270
|
|
|
271
|
+
/**
|
|
272
|
+
* @param {Function} callback
|
|
273
|
+
* @returns {Promise<void>}
|
|
274
|
+
*/
|
|
174
275
|
async withConnections(callback) {
|
|
175
276
|
const dbs = {}
|
|
176
277
|
const stack = Error().stack
|
|
@@ -199,6 +300,10 @@ export default class VelociousConfiguration {
|
|
|
199
300
|
await runRequest()
|
|
200
301
|
}
|
|
201
302
|
|
|
303
|
+
/**
|
|
304
|
+
* @template T extends import("./database/drivers/base.js").default
|
|
305
|
+
* @returns {Record<string, T>} A map of database connections with identifier as key
|
|
306
|
+
*/
|
|
202
307
|
getCurrentConnections() {
|
|
203
308
|
const dbs = {}
|
|
204
309
|
|
|
@@ -217,6 +322,10 @@ export default class VelociousConfiguration {
|
|
|
217
322
|
return dbs
|
|
218
323
|
}
|
|
219
324
|
|
|
325
|
+
/**
|
|
326
|
+
* @param {Function} callback
|
|
327
|
+
* @returns {Promise<void>}
|
|
328
|
+
*/
|
|
220
329
|
async ensureConnections(callback) {
|
|
221
330
|
let dbs = this.getCurrentConnections()
|
|
222
331
|
|
package/src/controller.js
CHANGED
|
@@ -6,6 +6,10 @@ import {Logger} from "./logger.js"
|
|
|
6
6
|
import restArgsError from "./utils/rest-args-error.js"
|
|
7
7
|
|
|
8
8
|
export default class VelociousController {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} methodName
|
|
11
|
+
* @returns {void}
|
|
12
|
+
*/
|
|
9
13
|
static beforeAction(methodName) {
|
|
10
14
|
if (!this._beforeActions) this._beforeActions = []
|
|
11
15
|
|
|
@@ -32,9 +36,24 @@ export default class VelociousController {
|
|
|
32
36
|
this._viewPath = viewPath
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
35
42
|
getAction() { return this._action }
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @returns {import("./configuration.js").default}
|
|
46
|
+
*/
|
|
36
47
|
getConfiguration() { return this._configuration }
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @returns {object}
|
|
51
|
+
*/
|
|
37
52
|
getParams() { return this._params }
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @returns {import("./http-server/client/request.js").default}
|
|
56
|
+
*/
|
|
38
57
|
getRequest() { return this._request }
|
|
39
58
|
|
|
40
59
|
async _runBeforeCallbacks() {
|
|
@@ -67,6 +86,9 @@ export default class VelociousController {
|
|
|
67
86
|
await this.logger.debug("After runBeforeCallbacks")
|
|
68
87
|
}
|
|
69
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @returns {object}
|
|
91
|
+
*/
|
|
70
92
|
params() { return this._params }
|
|
71
93
|
|
|
72
94
|
render({json, status, ...restArgs} = {}) {
|
|
@@ -113,6 +135,13 @@ export default class VelociousController {
|
|
|
113
135
|
throw new Error("renderText stub")
|
|
114
136
|
}
|
|
115
137
|
|
|
138
|
+
/**
|
|
139
|
+
* @returns {import("./http-server/client/request.js").default}
|
|
140
|
+
*/
|
|
116
141
|
request() { return this._request }
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @returns {import("./http-server/client/response.js").default}
|
|
145
|
+
*/
|
|
117
146
|
response() { return this._response }
|
|
118
147
|
}
|
|
@@ -2,6 +2,10 @@ import TableColumn from "../table-data/table-column.js"
|
|
|
2
2
|
import TableData from "../table-data/index.js"
|
|
3
3
|
|
|
4
4
|
export default class VelociousDatabaseDriversBaseColumn {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} indexName
|
|
7
|
+
* @returns {Promise<import('../table-data/table-index.js').default>}
|
|
8
|
+
*/
|
|
5
9
|
async getIndexByName(indexName) {
|
|
6
10
|
const indexes = await this.getIndexes()
|
|
7
11
|
const index = indexes.find((index) => index.getName() == indexName)
|
|
@@ -9,6 +13,10 @@ export default class VelociousDatabaseDriversBaseColumn {
|
|
|
9
13
|
return index
|
|
10
14
|
}
|
|
11
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @param {boolean} nullable Whether the column should be nullable or not.
|
|
18
|
+
* @returns {Promise<void>}
|
|
19
|
+
*/
|
|
12
20
|
async changeNullable(nullable) {
|
|
13
21
|
const tableData = new TableData(this.getTable().getName())
|
|
14
22
|
const column = this.getTableDataColumn()
|
|
@@ -28,6 +36,9 @@ export default class VelociousDatabaseDriversBaseColumn {
|
|
|
28
36
|
return this.getTable().getDriver()
|
|
29
37
|
}
|
|
30
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @returns {import("../query-parser/options.js").default}
|
|
41
|
+
*/
|
|
31
42
|
getOptions() {
|
|
32
43
|
return this.getDriver().options()
|
|
33
44
|
}
|
|
@@ -38,6 +49,9 @@ export default class VelociousDatabaseDriversBaseColumn {
|
|
|
38
49
|
return this.table
|
|
39
50
|
}
|
|
40
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @returns {TableColumn} The table column data for this column. This is used for altering tables and such.
|
|
54
|
+
*/
|
|
41
55
|
getTableDataColumn() {
|
|
42
56
|
return new TableColumn(this.getName(), {
|
|
43
57
|
autoIncrement: this.getAutoIncrement(),
|