velocious 1.0.85 → 1.0.87

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 +272 -19
  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
package/bin/velocious.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import Cli from "../src/cli/index.js"
4
+ import configurationResolver from "../src/configuration-resolver.js"
4
5
 
5
6
  const processArgs = process.argv.slice(2)
6
7
  const parsedProcessArgs = {}
@@ -19,7 +20,15 @@ for (let i = 0; i < processArgs.length; i++) {
19
20
  }
20
21
  }
21
22
 
22
- const cli = new Cli({parsedProcessArgs, processArgs})
23
+ const configuration = await configurationResolver()
24
+
25
+ configuration.setCurrent()
26
+
27
+ const cli = new Cli({
28
+ configuration,
29
+ parsedProcessArgs,
30
+ processArgs
31
+ })
23
32
 
24
33
  await cli.execute()
25
34
  process.exit(0)
@@ -0,0 +1,33 @@
1
+ import js from "@eslint/js"
2
+ import {jsdoc} from 'eslint-plugin-jsdoc'
3
+ import globals from "globals"
4
+ import { defineConfig } from "eslint/config"
5
+
6
+ export default defineConfig([
7
+ {
8
+ files: ["**/*.{js,mjs,cjs}"],
9
+ plugins: {js},
10
+ extends: ["js/recommended"],
11
+ languageOptions: {
12
+ globals: {...globals.browser, ...globals.node}
13
+ }
14
+ },
15
+ jsdoc({
16
+ config: "flat/recommended",
17
+ rules: {
18
+ "jsdoc/reject-any-type": "off",
19
+ "jsdoc/reject-function-type": "off",
20
+ "jsdoc/require-jsdoc": "off",
21
+ "jsdoc/require-param": "off",
22
+ "jsdoc/require-param-description": "off",
23
+ "jsdoc/require-returns": "off",
24
+ "jsdoc/require-returns-description": "off"
25
+ }
26
+ }),
27
+ {
28
+ files: ["spec/**/*.js"],
29
+ rules: {
30
+ "no-undef": "off"
31
+ }
32
+ }
33
+ ])
package/package.json CHANGED
@@ -3,9 +3,10 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.85",
6
+ "version": "1.0.87",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
+ "lint": "eslint",
9
10
  "test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
10
11
  "velocious": "asd"
11
12
  },
@@ -40,6 +41,10 @@
40
41
  "strftime": "^0.10.2"
41
42
  },
42
43
  "devDependencies": {
44
+ "@eslint/js": "^9.39.1",
45
+ "eslint": "^9.39.1",
46
+ "eslint-plugin-jsdoc": "^61.4.1",
47
+ "globals": "^16.5.0",
43
48
  "mssql": "^12.0.0",
44
49
  "mysql": "^2.18.1",
45
50
  "node-fetch": "^3.3.1",
@@ -47,7 +52,7 @@
47
52
  "require-context": "^1.1.0",
48
53
  "sqlite": "^5.1.1",
49
54
  "sqlite3": "^5.1.7",
50
- "tedious": "^18.6.1",
55
+ "tedious": "^19.1.3",
51
56
  "uniqunize": "^1.0.1"
52
57
  }
53
58
  }
package/peak_flow.yml CHANGED
@@ -80,3 +80,9 @@ builds:
80
80
  - cd spec/dummy && npx velocious db:create
81
81
  - cd spec/dummy && npx velocious db:migrate
82
82
  - cd spec/dummy && npx velocious test
83
+ build_5:
84
+ name: ESLint
85
+ script:
86
+ - cp spec/dummy/src/config/configuration.peakflow.sqlite.js spec/dummy/src/config/configuration.js
87
+ - sleep 5
88
+ - npm run lint
@@ -1,10 +1,14 @@
1
1
  import Cli from "../../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../../dummy/src/config/configuration.js"
2
3
  import dummyDirectory from "../../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../../src/environment-handlers/node.js"
3
5
 
4
6
  describe("Cli - Commands - db:create", () => {
5
7
  it("generates SQL to create a new database", async () => {
6
8
  const cli = new Cli({
9
+ configuration: dummyConfiguration,
7
10
  directory: dummyDirectory(),
11
+ environmentHandler: new EnvironmentHandlerNode(),
8
12
  processArgs: ["db:create"],
9
13
  testing: true
10
14
  })
@@ -1,18 +1,20 @@
1
1
  import Cli from "../../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../../dummy/src/config/configuration.js"
2
3
  import dummyDirectory from "../../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../../src/environment-handlers/node.js"
3
5
  import uniqunize from "uniqunize"
4
6
 
5
7
  describe("Cli - Commands - db:migrate", () => {
6
8
  it("runs migrations", {databaseCleaning: {transaction: false}}, async () => {
7
9
  const directory = dummyDirectory()
8
10
  const cli = new Cli({
11
+ configuration: dummyConfiguration,
9
12
  directory,
13
+ environmentHandler: new EnvironmentHandlerNode(),
10
14
  processArgs: ["db:migrate"],
11
15
  testing: true
12
16
  })
13
17
 
14
- await cli.loadConfiguration()
15
-
16
18
  let defaultDatabaseType, defaultSchemaMigrations = [], projectForeignKey = [], tablesResult = []
17
19
 
18
20
  await cli.configuration.ensureConnections(async (dbs) => {
@@ -0,0 +1,179 @@
1
+ import Cli from "../../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../../dummy/src/config/configuration.js"
3
+ import dummyDirectory from "../../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../../src/environment-handlers/node.js"
5
+ import uniqunize from "uniqunize"
6
+
7
+ describe("Cli - Commands - db:rollback", () => {
8
+ const runMigrations = async () => {
9
+ const cliMigrate = new Cli({
10
+ configuration: dummyConfiguration,
11
+ directory: dummyDirectory(),
12
+ environmentHandler: new EnvironmentHandlerNode(),
13
+ processArgs: ["db:migrate"],
14
+ testing: true
15
+ })
16
+
17
+ await cliMigrate.execute()
18
+ }
19
+
20
+ const getTestData = async () => {
21
+ const cliRollback = new Cli({
22
+ configuration: dummyConfiguration,
23
+ directory: dummyDirectory(),
24
+ environmentHandler: new EnvironmentHandlerNode(),
25
+ processArgs: ["db:rollback"],
26
+ testing: true
27
+ })
28
+
29
+ let defaultDatabaseType, defaultSchemaMigrations = [], tablesResult = []
30
+
31
+ await cliRollback.configuration.ensureConnections(async (dbs) => {
32
+ defaultDatabaseType = dbs.default.getType()
33
+
34
+ for (const dbIdentifier in dbs) {
35
+ const db = dbs[dbIdentifier]
36
+ const tables = await db.getTables()
37
+
38
+ for (const table of tables) {
39
+ tablesResult.push(table.getName())
40
+ }
41
+
42
+ const schemaMigrationsResult = await db.select("schema_migrations")
43
+
44
+ for (const schemaMigrationResult of schemaMigrationsResult) {
45
+ defaultSchemaMigrations.push(schemaMigrationResult.version)
46
+ }
47
+ }
48
+ })
49
+
50
+ return {defaultDatabaseType, defaultSchemaMigrations, tablesResult}
51
+ }
52
+
53
+ it("runs migrations", {databaseCleaning: {transaction: false}}, async () => {
54
+ const directory = dummyDirectory()
55
+
56
+ await runMigrations()
57
+
58
+ const cliRollback = new Cli({
59
+ configuration: dummyConfiguration,
60
+ directory,
61
+ environmentHandler: new EnvironmentHandlerNode(),
62
+ processArgs: ["db:rollback"],
63
+ testing: true
64
+ })
65
+
66
+ await cliRollback.configuration.ensureConnections(async () => {
67
+ await runMigrations()
68
+ await cliRollback.execute()
69
+ })
70
+
71
+ const {defaultDatabaseType, defaultSchemaMigrations, tablesResult} = await getTestData()
72
+
73
+ if (defaultDatabaseType == "mssql") {
74
+ expect(uniqunize(tablesResult.sort())).toEqual(
75
+ [
76
+ "accounts",
77
+ "authentication_tokens",
78
+ "project_translations",
79
+ "projects",
80
+ "schema_migrations",
81
+ "tasks",
82
+ "users"
83
+ ]
84
+ )
85
+
86
+ expect(uniqunize(defaultSchemaMigrations.sort())).toEqual([
87
+ "20230728075328",
88
+ "20230728075329",
89
+ "20250605133926",
90
+ "20250903112845",
91
+ "20250912183605",
92
+ "20250912183606",
93
+ "20250915085450",
94
+ "20250916111330"
95
+ ])
96
+ } else {
97
+ expect(tablesResult.sort()).toEqual(
98
+ [
99
+ "accounts",
100
+ "authentication_tokens",
101
+ "project_translations",
102
+ "projects",
103
+ "schema_migrations",
104
+ "schema_migrations",
105
+ "tasks",
106
+ "users"
107
+ ]
108
+ )
109
+
110
+ expect(defaultSchemaMigrations.sort()).toEqual([
111
+ "20230728075328",
112
+ "20230728075329",
113
+ "20250605133926",
114
+ "20250903112845",
115
+ "20250912183605",
116
+ "20250912183606",
117
+ "20250915085450",
118
+ "20250916111330"
119
+ ])
120
+ }
121
+
122
+ await runMigrations()
123
+
124
+ const {defaultSchemaMigrations: newDefaultSchemaMigrations, tablesResult: newTablesResult} = await getTestData()
125
+
126
+ if (defaultDatabaseType == "mssql") {
127
+ expect(uniqunize(newTablesResult.sort())).toEqual(
128
+ [
129
+ "accounts",
130
+ "authentication_tokens",
131
+ "project_details",
132
+ "project_translations",
133
+ "projects",
134
+ "schema_migrations",
135
+ "tasks",
136
+ "users"
137
+ ]
138
+ )
139
+
140
+ expect(uniqunize(newDefaultSchemaMigrations.sort())).toEqual([
141
+ "20230728075328",
142
+ "20230728075329",
143
+ "20250605133926",
144
+ "20250903112845",
145
+ "20250912183605",
146
+ "20250912183606",
147
+ "20250915085450",
148
+ "20250916111330",
149
+ "20250921121002"
150
+ ])
151
+ } else {
152
+ expect(newTablesResult.sort()).toEqual(
153
+ [
154
+ "accounts",
155
+ "authentication_tokens",
156
+ "project_details",
157
+ "project_translations",
158
+ "projects",
159
+ "schema_migrations",
160
+ "schema_migrations",
161
+ "tasks",
162
+ "users"
163
+ ]
164
+ )
165
+
166
+ expect(newDefaultSchemaMigrations.sort()).toEqual([
167
+ "20230728075328",
168
+ "20230728075329",
169
+ "20250605133926",
170
+ "20250903112845",
171
+ "20250912183605",
172
+ "20250912183606",
173
+ "20250915085450",
174
+ "20250916111330",
175
+ "20250921121002"
176
+ ])
177
+ }
178
+ })
179
+ })
@@ -1,10 +1,14 @@
1
1
  import Cli from "../../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../../dummy/src/config/configuration.js"
2
3
  import dummyDirectory from "../../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../../src/environment-handlers/node.js"
3
5
 
4
6
  describe("Cli - destroy - migration", () => {
5
7
  it("destroys an existing migration", async () => {
6
8
  const cli = new Cli({
9
+ configuration: dummyConfiguration,
7
10
  directory: dummyDirectory(),
11
+ environmentHandler: new EnvironmentHandlerNode(),
8
12
  processArgs: ["d:migration", "create-tasks"],
9
13
  testing: true
10
14
  })
@@ -1,10 +1,14 @@
1
1
  import Cli from "../../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../../dummy/src/config/configuration.js"
2
3
  import dummyDirectory from "../../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../../src/environment-handlers/node.js"
3
5
 
4
6
  describe("Cli - generate - migration", () => {
5
7
  it("generates a new migration", async () => {
6
8
  const cli = new Cli({
9
+ configuration: dummyConfiguration,
7
10
  directory: dummyDirectory(),
11
+ environmentHandler: new EnvironmentHandlerNode(),
8
12
  processArgs: ["g:migration", "create-tasks"],
9
13
  testing: true
10
14
  })
@@ -1,10 +1,14 @@
1
1
  import Cli from "../../../src/cli/index.js"
2
+ import dummyConfiguration from "../../dummy/src/config/configuration.js"
2
3
  import dummyDirectory from "../../dummy/dummy-directory.js"
4
+ import EnvironmentHandlerNode from "../../../src/environment-handlers/node.js"
3
5
 
4
6
  describe("Cli - Commands - init", () => {
5
7
  it("inits files and dirs", async () => {
6
8
  const cli = new Cli({
9
+ configuration: dummyConfiguration,
7
10
  directory: dummyDirectory(),
11
+ environmentHandler: new EnvironmentHandlerNode(),
8
12
  processArgs: ["init"],
9
13
  testing: true
10
14
  })
@@ -1,6 +1,7 @@
1
1
  import Application from "../../src/application.js"
2
+ import {digg} from "diggerize"
2
3
  import dummyConfiguration from "./src/config/configuration.js"
3
- import FilesFinder from "../../src/database/migrator/files-finder.js"
4
+ import EnvironmentHandlerNode from "../../src/environment-handlers/node.js"
4
5
  import Migrator from "../../src/database/migrator.js"
5
6
 
6
7
  export default class Dummy {
@@ -25,12 +26,14 @@ export default class Dummy {
25
26
  }
26
27
 
27
28
  static async runMigrations() {
28
- const migrationsPath = `${import.meta.dirname}/src/database/migrations`
29
- const files = await new FilesFinder({path: migrationsPath}).findFiles()
29
+ const environmentHandlerNode = new EnvironmentHandlerNode()
30
+
31
+ environmentHandlerNode.setConfiguration(dummyConfiguration)
32
+
30
33
  const migrator = new Migrator({configuration: dummyConfiguration})
31
34
 
32
35
  await migrator.prepare()
33
- await migrator.migrateFiles(files, async (path) => await import(path))
36
+ await migrator.migrateFiles(await environmentHandlerNode.findMigrations(), digg(environmentHandlerNode, "requireMigration"))
34
37
  }
35
38
 
36
39
  static async run(callback) {
@@ -5,6 +5,7 @@ import dummyDirectory from "../../dummy-directory.js"
5
5
  import fs from "fs/promises"
6
6
  import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
7
7
  import MysqlDriver from "../../../../src/database/drivers/mysql/index.js"
8
+ import NodeEnvironmentHandler from "../../../../src/environment-handlers/node.js"
8
9
  import path from "path"
9
10
  import requireContext from "require-context"
10
11
 
@@ -48,6 +49,7 @@ export default new Configuration({
48
49
  }
49
50
  },
50
51
  directory: dummyDirectory(),
52
+ environmentHandler: new NodeEnvironmentHandler(),
51
53
  initializeModels: async ({configuration}) => {
52
54
  const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
53
55
  const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
@@ -6,6 +6,7 @@ import fs from "fs/promises"
6
6
  import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
7
7
  import MssqlDriver from "../../../../src/database/drivers/mssql/index.js"
8
8
  import MysqlDriver from "../../../../src/database/drivers/mysql/index.js"
9
+ import NodeEnvironmentHandler from "../../../../src/environment-handlers/node.js"
9
10
  import path from "path"
10
11
  import requireContext from "require-context"
11
12
 
@@ -44,6 +45,7 @@ export default new Configuration({
44
45
  }
45
46
  },
46
47
  directory: dummyDirectory(),
48
+ environmentHandler: new NodeEnvironmentHandler(),
47
49
  initializeModels: async ({configuration}) => {
48
50
  const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
49
51
  const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
@@ -5,6 +5,7 @@ import dummyDirectory from "../../dummy-directory.js"
5
5
  import fs from "fs/promises"
6
6
  import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
7
7
  import MssqlDriver from "../../../../src/database/drivers/mssql/index.js"
8
+ import NodeEnvironmentHandler from "../../../../src/environment-handlers/node.js"
8
9
  import path from "path"
9
10
  import requireContext from "require-context"
10
11
 
@@ -50,6 +51,7 @@ export default new Configuration({
50
51
  }
51
52
  },
52
53
  directory: dummyDirectory(),
54
+ environmentHandler: new NodeEnvironmentHandler(),
53
55
  initializeModels: async ({configuration}) => {
54
56
  const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
55
57
  const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
@@ -5,6 +5,7 @@ import dummyDirectory from "../../dummy-directory.js"
5
5
  import fs from "fs/promises"
6
6
  import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
7
7
  import MssqlDriver from "../../../../src/database/drivers/mssql/index.js"
8
+ import NodeEnvironmentHandler from "../../../../src/environment-handlers/node.js"
8
9
  import path from "path"
9
10
  import PgsqlDriver from "../../../../src/database/drivers/pgsql/index.js"
10
11
  import requireContext from "require-context"
@@ -44,6 +45,7 @@ export default new Configuration({
44
45
  }
45
46
  },
46
47
  directory: dummyDirectory(),
48
+ environmentHandler: new NodeEnvironmentHandler(),
47
49
  initializeModels: async ({configuration}) => {
48
50
  const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
49
51
  const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
@@ -5,6 +5,7 @@ import dummyDirectory from "../../dummy-directory.js"
5
5
  import fs from "fs/promises"
6
6
  import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
7
7
  import MssqlDriver from "../../../../src/database/drivers/mssql/index.js"
8
+ import NodeEnvironmentHandler from "../../../../src/environment-handlers/node.js"
8
9
  import SqliteDriver from "../../../../src/database/drivers/sqlite/index.js"
9
10
  import path from "path"
10
11
  import requireContext from "require-context"
@@ -41,6 +42,7 @@ export default new Configuration({
41
42
  }
42
43
  },
43
44
  directory: dummyDirectory(),
45
+ environmentHandler: new NodeEnvironmentHandler(),
44
46
  initializeModels: async ({configuration}) => {
45
47
  const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
46
48
  const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
@@ -10,6 +10,8 @@ export default class CreateProjectDetails extends Migration {
10
10
  }
11
11
 
12
12
  async down() {
13
- await this.dropTable("project_details")
13
+ if (await this.tableExists("project_details")) {
14
+ await this.dropTable("project_details")
15
+ }
14
16
  }
15
17
  }
@@ -4,6 +4,12 @@ import {Logger} from "./logger.js"
4
4
  import HttpServer from "./http-server/index.js"
5
5
 
6
6
  export default class VelociousApplication {
7
+ /**
8
+ * @param {object} args
9
+ * @param {import("./http-server/index.js").default} args.httpServer
10
+ * @param {import("./configuration.js").default} args.configuration
11
+ * @param {string} args.type
12
+ */
7
13
  constructor({configuration, httpServer, type}) {
8
14
  this.configuration = configuration
9
15
  this.httpServerConfiguration = httpServer ?? {}
@@ -11,6 +17,9 @@ export default class VelociousApplication {
11
17
  this._type = type
12
18
  }
13
19
 
20
+ /**
21
+ * @returns {string}
22
+ */
14
23
  getType() { return this._type }
15
24
 
16
25
  async initialize() {
@@ -25,6 +34,9 @@ export default class VelociousApplication {
25
34
  }
26
35
  }
27
36
 
37
+ /**
38
+ * @returns {boolean}
39
+ */
28
40
  isActive() {
29
41
  return this.httpServer?.isActive()
30
42
  }
@@ -1,12 +1,16 @@
1
- import {digg} from "diggerize"
1
+ import restArgsError from "../utils/rest-args-error.js"
2
2
 
3
3
  export default class VelociousCliBaseCommand {
4
- constructor(args) {
4
+ constructor({args = {}, environmentHandler, ...restArgs}) {
5
+ restArgsError(restArgs)
6
+
5
7
  this.args = args
6
- this.configuration = this.args.configuration
8
+ this._configuration = args.configuration
9
+ this._environmentHandler = environmentHandler
7
10
  this.processArgs = args.processArgs
8
11
  }
9
12
 
10
- directory() { return digg(this, "configuration").getDirectory() }
11
- getConfiguration() { return this.configuration }
13
+ directory() { return this.getConfiguration().getDirectory() }
14
+ getConfiguration() { return this._configuration }
15
+ getEnvironmentHandler() { return this._environmentHandler }
12
16
  }
@@ -0,0 +1,37 @@
1
+ import Cli from "./index.js"
2
+ import restArgsError from "../utils/rest-args-error.js"
3
+
4
+ export default class VelociousBrowserCli {
5
+ /**
6
+ * @param {object} args
7
+ * @param {import("../configuration.js").default} args.configuration
8
+ */
9
+ constructor({configuration, ...restArgs}) {
10
+ restArgsError(restArgs)
11
+
12
+ this.configuration = configuration
13
+ }
14
+
15
+ /**
16
+ * @description Enable the CLI in the global scope. This is useful for debugging and testing.
17
+ * @returns {void}
18
+ */
19
+ enable() {
20
+ globalThis.velociousCLI = this
21
+ }
22
+
23
+ /**
24
+ * @description Run a command. This is useful for debugging and testing. This is a wrapper around the Cli class.
25
+ * @param {string} command
26
+ * @returns {Promise<void>}
27
+ */
28
+ async run(command) {
29
+ const processArgs = command.split(/\s+/)
30
+ const cli = new Cli({
31
+ configuration: this.configuration,
32
+ processArgs
33
+ })
34
+
35
+ await cli.execute()
36
+ }
37
+ }
@@ -5,9 +5,9 @@ import TableData from "../../../database/table-data/index.js"
5
5
 
6
6
  export default class DbCreate extends BaseCommand{
7
7
  async execute() {
8
- for (const databaseIdentifier of this.configuration.getDatabaseIdentifiers()) {
9
- const databaseType = this.configuration.getDatabaseType(databaseIdentifier)
10
- const databasePool = this.configuration.getDatabasePool(databaseIdentifier)
8
+ for (const databaseIdentifier of this.getConfiguration().getDatabaseIdentifiers()) {
9
+ const databaseType = this.getConfiguration().getDatabaseType(databaseIdentifier)
10
+ const databasePool = this.getConfiguration().getDatabasePool(databaseIdentifier)
11
11
  const newConfiguration = incorporate({}, databasePool.getConfiguration())
12
12
  const DriverClass = digg(newConfiguration, "driver")
13
13
 
@@ -21,7 +21,7 @@ export default class DbCreate extends BaseCommand{
21
21
  delete newConfiguration.sqlConfig.database
22
22
  }
23
23
 
24
- this.databaseConnection = new DriverClass(newConfiguration, this.configuration)
24
+ this.databaseConnection = new DriverClass(newConfiguration, this.getConfiguration())
25
25
 
26
26
  await this.databaseConnection.connect()
27
27
 
@@ -42,7 +42,7 @@ export default class DbCreate extends BaseCommand{
42
42
  }
43
43
 
44
44
  async createDatabase(databaseIdentifier) {
45
- const databaseName = digg(this.configuration.getDatabaseConfiguration(), databaseIdentifier, "database")
45
+ const databaseName = digg(this.getConfiguration().getDatabaseConfiguration(), databaseIdentifier, "database")
46
46
  const sqls = this.databaseConnection.createDatabaseSql(databaseName, {ifNotExists: true})
47
47
 
48
48
  for (const sql of sqls) {
@@ -1,19 +1,18 @@
1
1
  import BaseCommand from "../../base-command.js"
2
- import FilesFinder from "../../../database/migrator/files-finder.js"
3
2
  import Migrator from "../../../database/migrator.js"
4
3
 
5
4
  export default class DbDrop extends BaseCommand {
6
5
  async execute() {
7
- const environment = this.configuration.getEnvironment()
6
+ const environment = this.getConfiguration().getEnvironment()
8
7
 
9
8
  if (environment != "development" && environment != "test") {
10
9
  throw new Error(`This command should only be executed on development and test environments and not: ${environment}`)
11
10
  }
12
11
 
13
- this.migrator = new Migrator({configuration: this.configuration})
12
+ const migrator = new Migrator({configuration: this.getConfiguration()})
14
13
 
15
- await this.configuration.ensureConnections(async () => {
16
- await this.migrator.dropDatabase()
14
+ await this.getConfiguration().ensureConnections(async () => {
15
+ await migrator.dropDatabase()
17
16
  })
18
17
  }
19
18
  }
@@ -1,19 +1,15 @@
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 DbMigrate extends BaseCommand {
6
6
  async execute() {
7
- const projectPath = this.configuration.getDirectory()
8
- const migrationsPath = `${projectPath}/src/database/migrations`
9
- const filesFinder = new FilesFinder({path: migrationsPath})
10
- const files = await filesFinder.findFiles()
7
+ const migrations = await this.getEnvironmentHandler().findMigrations()
8
+ const migrator = new Migrator({configuration: this.getConfiguration()})
11
9
 
12
- this.migrator = new Migrator({configuration: this.configuration})
13
-
14
- await this.configuration.ensureConnections(async () => {
15
- await this.migrator.prepare()
16
- await this.migrator.migrateFiles(files, async (importPath) => await import(importPath))
10
+ await this.getConfiguration().ensureConnections(async () => {
11
+ await migrator.prepare()
12
+ await migrator.migrateFiles(migrations, digg(this.getEnvironmentHandler(), "requireMigration"))
17
13
  })
18
14
  }
19
15
  }