velocious 1.0.85 → 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.
Files changed (95) hide show
  1. package/bin/velocious.js +10 -1
  2. package/eslint.config.js +33 -0
  3. package/package.json +7 -2
  4. package/peak_flow.yml +6 -0
  5. package/spec/cli/commands/db/create-spec.js +4 -0
  6. package/spec/cli/commands/db/migrate-spec.js +4 -2
  7. package/spec/cli/commands/db/rollback-spec.js +179 -0
  8. package/spec/cli/commands/destroy/migration-spec.js +4 -0
  9. package/spec/cli/commands/generate/migration-spec.js +4 -0
  10. package/spec/cli/commands/init-spec.js +4 -0
  11. package/spec/dummy/index.js +7 -4
  12. package/spec/dummy/src/config/configuration.example.js +2 -0
  13. package/spec/dummy/src/config/configuration.peakflow.mariadb.js +2 -0
  14. package/spec/dummy/src/config/configuration.peakflow.mssql.js +2 -0
  15. package/spec/dummy/src/config/configuration.peakflow.pgsql.js +2 -0
  16. package/spec/dummy/src/config/configuration.peakflow.sqlite.js +2 -0
  17. package/spec/dummy/src/database/migrations/20250921121002-create-project-details.js +3 -1
  18. package/src/application.js +12 -0
  19. package/src/cli/base-command.js +9 -5
  20. package/src/cli/browser-cli.js +37 -0
  21. package/src/cli/commands/db/create.js +5 -5
  22. package/src/cli/commands/db/drop.js +4 -5
  23. package/src/cli/commands/db/migrate.js +6 -10
  24. package/src/cli/commands/db/reset.js +8 -12
  25. package/src/cli/commands/db/rollback.js +15 -0
  26. package/src/cli/commands/destroy/migration.js +2 -2
  27. package/src/cli/commands/generate/migration.js +3 -6
  28. package/src/cli/commands/generate/model.js +3 -6
  29. package/src/cli/commands/init.js +5 -8
  30. package/src/cli/commands/server.js +3 -3
  31. package/src/cli/commands/test.js +1 -1
  32. package/src/cli/index.js +15 -63
  33. package/src/cli/use-browser-cli.js +25 -0
  34. package/src/configuration-resolver.js +1 -1
  35. package/src/configuration.js +118 -9
  36. package/src/controller.js +29 -0
  37. package/src/database/drivers/base-column.js +14 -0
  38. package/src/database/drivers/base-columns-index.js +3 -0
  39. package/src/database/drivers/base-foreign-key.js +3 -0
  40. package/src/database/drivers/base-table.js +3 -0
  41. package/src/database/drivers/base.js +55 -1
  42. package/src/database/drivers/mssql/index.js +64 -1
  43. package/src/database/drivers/mysql/columns-index.js +0 -1
  44. package/src/database/drivers/sqlite/base.js +39 -0
  45. package/src/database/drivers/sqlite/connection-remote.js +1 -1
  46. package/src/database/drivers/sqlite/sql/alter-table.js +1 -1
  47. package/src/database/drivers/sqlite/sql/delete.js +15 -10
  48. package/src/database/migration/index.js +122 -1
  49. package/src/database/migrator/files-finder.js +13 -1
  50. package/src/database/migrator.js +125 -24
  51. package/src/database/pool/single-multi-use.js +1 -1
  52. package/src/database/query/alter-table-base.js +11 -0
  53. package/src/database/query/base.js +7 -0
  54. package/src/database/query/create-database-base.js +3 -0
  55. package/src/database/query/create-index-base.js +3 -1
  56. package/src/database/query/create-table-base.js +3 -0
  57. package/src/database/query/drop-table-base.js +4 -1
  58. package/src/database/query/from-base.js +7 -0
  59. package/src/database/query/index.js +96 -6
  60. package/src/database/query/insert-base.js +6 -0
  61. package/src/database/query/join-base.js +3 -0
  62. package/src/database/query/order-base.js +3 -0
  63. package/src/database/query/select-base.js +3 -0
  64. package/src/database/query/update-base.js +3 -0
  65. package/src/database/query/where-base.js +3 -0
  66. package/src/database/record/index.js +274 -21
  67. package/src/database/record/instance-relationships/base.js +66 -1
  68. package/src/database/record/relationships/base.js +41 -1
  69. package/src/database/record/validators/base.js +10 -0
  70. package/src/database/record/validators/presence.js +1 -1
  71. package/src/database/table-data/table-column.js +37 -3
  72. package/src/database/table-data/table-index.js +1 -1
  73. package/src/database/use-database.js +2 -2
  74. package/src/environment-handlers/base.js +53 -0
  75. package/src/environment-handlers/browser.js +171 -0
  76. package/src/environment-handlers/node.js +162 -0
  77. package/src/http-server/client/request-buffer/index.js +9 -9
  78. package/src/http-server/index.js +6 -0
  79. package/src/http-server/worker-handler/index.js +20 -19
  80. package/src/initializer.js +17 -1
  81. package/src/logger.js +3 -0
  82. package/src/routes/app-routes.js +6 -2
  83. package/src/routes/base-route.js +1 -1
  84. package/src/routes/get-route.js +1 -1
  85. package/src/routes/namespace-route.js +1 -1
  86. package/src/routes/post-route.js +1 -1
  87. package/src/routes/resolver.js +1 -1
  88. package/src/routes/resource-route.js +1 -1
  89. package/src/templates/configuration.js +4 -0
  90. package/src/testing/request-client.js +26 -3
  91. package/src/testing/test-files-finder.js +2 -2
  92. package/src/testing/test-runner.js +74 -28
  93. package/src/testing/test.js +62 -0
  94. package/src/utils/file-exists.js +7 -5
  95. package/src/utils/rest-args-error.js +5 -3
@@ -1,26 +1,22 @@
1
1
  import BaseCommand from "../../base-command.js"
2
- import FilesFinder from "../../../database/migrator/files-finder.js"
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.configuration.getEnvironment()
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 projectPath = this.configuration.getDirectory()
14
- const migrationsPath = `${projectPath}/src/database/migrations`
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.migrator = new Migrator({configuration: this.configuration})
19
-
20
- await this.configuration.ensureConnections(async () => {
21
- await this.migrator.reset()
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 "node:fs/promises"
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.configuration.getDirectory()}/src/database/migrations`
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 "node:fs/promises"
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 __filename = fileURLToPath(import.meta.url)
17
- const __dirname = dirname(__filename)
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 "node:fs/promises"
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 __filename = fileURLToPath(`${import.meta.url}/../../..`)
15
- const __dirname = dirname(__filename)
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`
@@ -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 {fileURLToPath} from "url"
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 __filename = fileURLToPath(`${import.meta.url}/../../..`)
10
- const velocipusPath = dirname(__filename)
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: `${velocipusPath}/src/templates/configuration.js`,
12
+ source: `${velociousPath}/src/templates/configuration.js`,
16
13
  target: `${projectConfigPath}/configuration.js`
17
14
  },
18
15
  {
19
- source: `${velocipusPath}/src/templates/routes.js`,
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.configuration.getDatabasePool()
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,14 +13,14 @@ 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.configuration,
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.configuration.getEnvironment()
23
+ const environment = this.getConfiguration().getEnvironment()
24
24
 
25
25
  await application.initialize()
26
26
  await application.startHttpServer()
@@ -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.configuration, testFiles})
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,67 +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
14
  const commandParts = this.args.processArgs[0].split(":")
15
- const filePaths = []
16
- const basePath = await this.getBasePath()
17
- const commandsPath = `${basePath}/src/cli/commands`
18
- let filePath = commandsPath
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
- filePath += `/${commandPart}`
26
- }
27
-
28
- filePaths.push(`${filePath}/index.js`)
29
- filePath += ".js"
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) {
42
- const possibleCommands = []
43
- const commandFiles = fs.glob(`${commandsPath}/**/*.js`)
44
-
45
- for await (const aFilePath of commandFiles) {
46
- const aFilePathParts = aFilePath.split("/")
47
- const lastPart = aFilePathParts[aFilePathParts.length - 1]
48
-
49
- if (lastPart == "index.js") {
50
- possibleCommands.push(aFilePathParts[aFilePathParts.length - 2])
51
- } else {
52
- possibleCommands.push(lastPart.replace(".js", ""))
53
- }
54
- }
55
-
56
- throw new Error(`Unknown command: ${this.args.processArgs[0]} which should have been one of: ${possibleCommands.sort().join(", ")}`)
22
+ parsedCommandParts.push(commandPart)
57
23
  }
58
24
 
59
- const commandClassImport = await import(fileFound)
60
- const CommandClass = commandClassImport.default
61
-
62
- await this.loadConfiguration()
63
-
64
- 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})
65
27
 
66
28
  if (commandInstance.initialize) {
67
29
  await commandInstance.initialize()
@@ -70,18 +32,8 @@ export default class VelociousCli {
70
32
  return await commandInstance.execute()
71
33
  }
72
34
 
73
- async getBasePath() {
74
- const __filename = fileURLToPath(import.meta.url)
75
- const basePath = await fs.realpath(`${dirname(__filename)}/../..`)
76
-
77
- return basePath
78
- }
79
-
80
- async loadConfiguration() {
81
- this.configuration = await configurationResolver({directory: this.args.directory})
82
- this.configuration.setCurrent()
83
- this.args.configuration = this.configuration
84
- }
85
-
86
- getConfiguration() { return this.args.configuration }
35
+ /**
36
+ * @returns {import("../configuration.js").default} configuration
37
+ */
38
+ getConfiguration() { return this.configuration }
87
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
  }
@@ -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
- constructor({cors, database, debug, directory, environment, initializeModels, initializers, locale, localeFallbacks, locales, testing, ...restArgs}) {
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
- setRoutes(newRoutes) {
157
- this.routes = newRoutes
158
- }
159
-
160
- setTranslator(callback) {
161
- this._translator = callback
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(),
@@ -14,6 +14,9 @@ export default class VelociousDatabaseDriversBaseColumnsIndex {
14
14
  return digg(this, "data", "index_name")
15
15
  }
16
16
 
17
+ /**
18
+ * @returns {import("../query-parser/options.js").default}
19
+ */
17
20
  getOptions() {
18
21
  return this.getDriver().options()
19
22
  }