velocious 1.0.2 → 1.0.4
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/.github/dependabot.yml +1 -1
- package/README.md +19 -3
- package/bin/velocious.mjs +4 -4
- package/index.mjs +5 -3
- package/package.json +5 -3
- package/peak_flow.yml +5 -2
- package/spec/cli/commands/db/create-spec.mjs +25 -0
- package/spec/cli/commands/db/migrate-spec.mjs +37 -0
- package/spec/cli/commands/destroy/migration-spec.mjs +15 -0
- package/spec/cli/commands/generate/migration-spec.mjs +18 -0
- package/spec/cli/commands/init-spec.mjs +19 -0
- package/spec/cli/commands/test/test-files-finder-spec.mjs +12 -0
- package/spec/database/drivers/mysql/connection-spec.mjs +2 -2
- package/spec/dummy/dummy-directory.mjs +11 -0
- package/spec/dummy/index.mjs +22 -26
- package/spec/dummy/src/config/configuration.example.mjs +21 -0
- package/spec/dummy/src/config/configuration.peakflow.mjs +22 -0
- package/spec/dummy/src/database/migrations/20230728075328-create-projects.mjs +11 -0
- package/spec/dummy/src/database/migrations/20230728075329-create-tasks.mjs +13 -0
- package/spec/http-server/client-spec.mjs +7 -12
- package/src/application.mjs +10 -11
- package/src/cli/base-command.mjs +11 -0
- package/src/cli/commands/db/create.mjs +44 -8
- package/src/cli/commands/db/migrate.mjs +105 -0
- package/src/cli/commands/destroy/migration.mjs +35 -0
- package/src/cli/commands/generate/migration.mjs +31 -7
- package/src/cli/commands/generate/model.mjs +36 -0
- package/src/cli/commands/init.mjs +60 -0
- package/src/cli/commands/server.mjs +15 -0
- package/src/cli/commands/test/index.mjs +14 -0
- package/src/cli/commands/test/test-files-finder.mjs +99 -0
- package/src/cli/commands/test/test-runner.mjs +19 -0
- package/src/cli/index.mjs +37 -16
- package/src/configuration-resolver.mjs +26 -0
- package/src/configuration.mjs +51 -13
- package/src/controller.mjs +1 -1
- package/src/database/drivers/base.mjs +8 -0
- package/src/database/drivers/mysql/index.mjs +25 -0
- package/src/database/drivers/mysql/sql/create-database.mjs +4 -0
- package/src/database/drivers/mysql/sql/create-table.mjs +4 -0
- package/src/database/drivers/sqlite/index.native.mjs +92 -0
- package/src/database/drivers/sqlite/index.web.mjs +64 -0
- package/src/database/drivers/sqlite/options.mjs +17 -0
- package/src/database/drivers/sqlite/query-parser.mjs +25 -0
- package/src/database/drivers/sqlite/query.native.mjs +9 -0
- package/src/database/drivers/sqlite/query.web.mjs +9 -0
- package/src/database/drivers/sqlite/sql/create-table.mjs +4 -0
- package/src/database/drivers/sqlite/sql/delete.mjs +19 -0
- package/src/database/drivers/sqlite/sql/insert.mjs +29 -0
- package/src/database/drivers/sqlite/sql/update.mjs +31 -0
- package/src/database/handler.mjs +0 -4
- package/src/database/migrate-from-require-context.mjs +53 -0
- package/src/database/migration/index.mjs +15 -2
- package/src/database/pool/async-tracked-multi-connection.mjs +81 -0
- package/src/database/pool/base.mjs +47 -0
- package/src/database/pool/single-multi-use.mjs +40 -0
- package/src/database/query/base.mjs +11 -0
- package/src/database/query/create-database-base.mjs +22 -0
- package/src/database/query/create-table-base.mjs +69 -0
- package/src/database/query/delete-base.mjs +4 -10
- package/src/database/query/from-plain.mjs +3 -5
- package/src/database/query/from-table.mjs +2 -2
- package/src/database/record/index.mjs +2 -2
- package/src/database/table-data/index.mjs +83 -0
- package/src/http-server/worker-handler/index.mjs +2 -1
- package/src/http-server/worker-handler/worker-thread.mjs +17 -9
- package/src/routes/app-routes.mjs +10 -0
- package/src/routes/resolver.mjs +4 -2
- package/src/spec/index.mjs +5 -0
- package/src/templates/configuration.mjs +19 -0
- package/src/templates/generate-migration.mjs +11 -0
- package/src/templates/generate-model.mjs +4 -0
- package/src/templates/routes.mjs +11 -0
- package/src/utils/file-exists.mjs +13 -0
- package/spec/cli/generate/migration-spec.mjs +0 -9
- package/spec/dummy/src/config/database.example.mjs +0 -15
- package/spec/dummy/src/config/database.peakflow.mjs +0 -15
- package/spec/dummy/src/database/migrations/001-create-tasks.mjs +0 -12
- package/src/database/pool/index.mjs +0 -43
package/.github/dependabot.yml
CHANGED
package/README.md
CHANGED
|
@@ -9,17 +9,33 @@ This is still work in progress.
|
|
|
9
9
|
* Migrations ala Rails
|
|
10
10
|
* Controllers and views ala Rails
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
# Setup
|
|
13
13
|
|
|
14
|
+
Make a new NPM project.
|
|
14
15
|
```bash
|
|
15
|
-
|
|
16
|
+
mkdir project
|
|
17
|
+
cd project
|
|
18
|
+
npm install velocious
|
|
19
|
+
npx velocious init
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
# Migrations
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx velocious g:migration create_tasks
|
|
16
26
|
```
|
|
17
27
|
|
|
18
28
|
```bash
|
|
19
29
|
npx velocious db:migrate
|
|
20
30
|
```
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
# Models
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx velocious g:model Option
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Testing
|
|
23
39
|
|
|
24
40
|
```bash
|
|
25
41
|
npm test
|
package/bin/velocious.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import Cli from "../src/cli/index.mjs"
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const processArgs = process.argv.slice(2)
|
|
6
|
+
const cli = new Cli({processArgs})
|
|
7
7
|
|
|
8
|
-
cli.execute(
|
|
8
|
+
await cli.execute()
|
package/index.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import Application from "./src/application.mjs"
|
|
2
2
|
import Cli from "./src/cli/index.mjs"
|
|
3
|
+
import Configuration from "./src/configuration.mjs"
|
|
3
4
|
import Controller from "./src/controller.mjs"
|
|
4
5
|
import Database from "./src/database/index.mjs"
|
|
5
|
-
import DatabasePool from "./src/database/pool/index.mjs"
|
|
6
6
|
import HttpServer from "./src/http-server/index.mjs"
|
|
7
7
|
import Routes from "./src/routes/index.mjs"
|
|
8
|
+
import Spec from "./src/spec/index.mjs"
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
Application,
|
|
11
12
|
Cli,
|
|
13
|
+
Configuration,
|
|
12
14
|
Controller,
|
|
13
15
|
Database,
|
|
14
|
-
DatabasePool,
|
|
15
16
|
HttpServer,
|
|
16
|
-
Routes
|
|
17
|
+
Routes,
|
|
18
|
+
Spec
|
|
17
19
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"velocious": "bin/velocious.mjs"
|
|
4
4
|
},
|
|
5
5
|
"name": "velocious",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.4",
|
|
7
7
|
"main": "index.mjs",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "jasmine",
|
|
@@ -27,10 +27,12 @@
|
|
|
27
27
|
"node-fetch": "^3.3.1"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"diggerize": "^1.0.
|
|
30
|
+
"diggerize": "^1.0.5",
|
|
31
31
|
"ejs": "^3.1.6",
|
|
32
32
|
"escape-string-regexp": "^1.0.5",
|
|
33
33
|
"incorporator": "^1.0.2",
|
|
34
|
-
"inflection": "^
|
|
34
|
+
"inflection": "^3.0.0",
|
|
35
|
+
"sql.js": "^1.12.0",
|
|
36
|
+
"strftime": "^0.10.2"
|
|
35
37
|
}
|
|
36
38
|
}
|
package/peak_flow.yml
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
before_install:
|
|
2
|
-
-
|
|
2
|
+
- sudo mkdir -p /etc/apt/keyrings
|
|
3
|
+
- curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --no-tty --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
|
4
|
+
- echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
|
|
5
|
+
- sudo apt-get update
|
|
3
6
|
- sudo apt-get install -y nodejs
|
|
4
7
|
before_script:
|
|
5
|
-
- cp spec/dummy/src/config/
|
|
8
|
+
- cp spec/dummy/src/config/configuration.peakflow.mjs spec/dummy/src/config/configuration.mjs
|
|
6
9
|
- npm install
|
|
7
10
|
- wait-for-it mariadb:3306
|
|
8
11
|
services:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Cli from "../../../../src/cli/index.mjs"
|
|
2
|
+
import dummyDirectory from "../../../dummy/dummy-directory.mjs"
|
|
3
|
+
|
|
4
|
+
describe("Cli - Commands - db:create", () => {
|
|
5
|
+
it("generates SQL to create a new database", async () => {
|
|
6
|
+
const cli = new Cli({
|
|
7
|
+
directory: dummyDirectory(),
|
|
8
|
+
processArgs: ["db:create"],
|
|
9
|
+
testing: true
|
|
10
|
+
})
|
|
11
|
+
const result = await cli.execute()
|
|
12
|
+
|
|
13
|
+
expect(result).toEqual(
|
|
14
|
+
[
|
|
15
|
+
{
|
|
16
|
+
databaseName: 'velocious_test',
|
|
17
|
+
sql: 'CREATE DATABASE IF NOT EXISTS `velocious_test`'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
createSchemaMigrationsTableSql: 'CREATE TABLE IF NOT EXISTS schema_migrations (`version` varchar(255) PRIMARY KEY)'
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Cli from "../../../../src/cli/index.mjs"
|
|
2
|
+
import dummyDirectory from "../../../dummy/dummy-directory.mjs"
|
|
3
|
+
|
|
4
|
+
describe("Cli - Commands - db:migrate", () => {
|
|
5
|
+
it("runs migrations", async () => {
|
|
6
|
+
const directory = dummyDirectory()
|
|
7
|
+
const cli = new Cli({
|
|
8
|
+
directory,
|
|
9
|
+
processArgs: ["db:migrate"],
|
|
10
|
+
testing: true
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
await cli.loadConfiguration()
|
|
14
|
+
|
|
15
|
+
const db = cli.configuration.getDatabasePool()
|
|
16
|
+
|
|
17
|
+
await db.withConnection(async () => {
|
|
18
|
+
await db.query("DROP TABLE IF EXISTS tasks")
|
|
19
|
+
await db.query("DROP TABLE IF EXISTS projects")
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
await cli.execute()
|
|
23
|
+
|
|
24
|
+
let tablesResult
|
|
25
|
+
|
|
26
|
+
await db.withConnection(async () => {
|
|
27
|
+
tablesResult = await db.query("SHOW TABLES")
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
expect(tablesResult).toEqual(
|
|
31
|
+
[
|
|
32
|
+
{Tables_in_velocious_test: "projects"},
|
|
33
|
+
{Tables_in_velocious_test: "tasks"}
|
|
34
|
+
]
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Cli from "../../../../src/cli/index.mjs"
|
|
2
|
+
import dummyDirectory from "../../../dummy/dummy-directory.mjs"
|
|
3
|
+
|
|
4
|
+
describe("Cli - destroy - migration", () => {
|
|
5
|
+
it("destroys an existing migration", async () => {
|
|
6
|
+
const cli = new Cli({
|
|
7
|
+
directory: dummyDirectory(),
|
|
8
|
+
processArgs: ["d:migration", "create-tasks"],
|
|
9
|
+
testing: true
|
|
10
|
+
})
|
|
11
|
+
const result = await cli.execute()
|
|
12
|
+
|
|
13
|
+
expect(result.destroyed).toEqual(["create-tasks"])
|
|
14
|
+
})
|
|
15
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Cli from "../../../../src/cli/index.mjs"
|
|
2
|
+
import dummyDirectory from "../../../dummy/dummy-directory.mjs"
|
|
3
|
+
|
|
4
|
+
describe("Cli - generate - migration", () => {
|
|
5
|
+
it("generates a new migration", async () => {
|
|
6
|
+
const cli = new Cli({
|
|
7
|
+
directory: dummyDirectory(),
|
|
8
|
+
processArgs: ["g:migration", "create-tasks"],
|
|
9
|
+
testing: true
|
|
10
|
+
})
|
|
11
|
+
const result = await cli.execute()
|
|
12
|
+
|
|
13
|
+
expect(result.migrationName).toEqual("create-tasks")
|
|
14
|
+
expect(result.migrationNameCamelized).toEqual("CreateTasks")
|
|
15
|
+
expect(result.migrationNumber).toMatch(/^\d+$/)
|
|
16
|
+
expect(result.migrationPath).toMatch(/-create-tasks\.mjs$/)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Cli from "../../../src/cli/index.mjs"
|
|
2
|
+
import dummyDirectory from "../../dummy/dummy-directory.mjs"
|
|
3
|
+
|
|
4
|
+
describe("Cli - Commands - init", () => {
|
|
5
|
+
it("inits files and dirs", async () => {
|
|
6
|
+
const cli = new Cli({
|
|
7
|
+
directory: dummyDirectory(),
|
|
8
|
+
processArgs: ["init"],
|
|
9
|
+
testing: true
|
|
10
|
+
})
|
|
11
|
+
const result = await cli.execute()
|
|
12
|
+
|
|
13
|
+
expect(result.fileMappings.length).toEqual(2)
|
|
14
|
+
expect(result.fileMappings[0].source).toContain("/src/templates/configuration.mjs")
|
|
15
|
+
expect(result.fileMappings[0].target).toContain("/spec/dummy/src/config/configuration.mjs")
|
|
16
|
+
expect(result.fileMappings[1].source).toContain("/src/templates/routes.mjs")
|
|
17
|
+
expect(result.fileMappings[1].target).toContain("/spec/dummy/src/config/routes.mjs")
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import TestFilesFinder from "../../../../src/cli/commands/test/test-files-finder.mjs"
|
|
2
|
+
|
|
3
|
+
describe("Cli - Commands - test - TestFilesFinder", () => {
|
|
4
|
+
it("finds the correct test files", async () => {
|
|
5
|
+
const testFilesFinder = new TestFilesFinder({directory: process.cwd(), processArgs: ["test"]})
|
|
6
|
+
const testFiles = await testFilesFinder.findTestFiles()
|
|
7
|
+
|
|
8
|
+
const sampleTestFilePath = `${process.cwd()}/spec/cli/commands/destroy/migration-spec.mjs`
|
|
9
|
+
|
|
10
|
+
expect(testFiles.includes(sampleTestFilePath)).toBe(true)
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Database from "../../../../src/database/index.mjs"
|
|
2
|
-
import
|
|
2
|
+
import configuration from "../../../dummy/src/config/configuration.mjs"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
4
|
|
|
5
|
-
const mysqlConfig = digg(
|
|
5
|
+
const mysqlConfig = digg(configuration, "database", "default", "master")
|
|
6
6
|
const Mysql = Database.Drivers.Mysql
|
|
7
7
|
|
|
8
8
|
describe("Database - Drivers - Mysql - Connection", () => {
|
package/spec/dummy/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import Application from "../../src/application.mjs"
|
|
2
|
-
import
|
|
3
|
-
import {dirname} from "path"
|
|
4
|
-
import {fileURLToPath} from "url"
|
|
2
|
+
import dummyConfiguration from "./src/config/configuration.mjs"
|
|
5
3
|
|
|
6
4
|
export default class Dummy {
|
|
7
5
|
static current() {
|
|
8
|
-
if (!
|
|
9
|
-
|
|
6
|
+
if (!this.velociousDummy) {
|
|
7
|
+
this.velociousDummy = new Dummy()
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
return
|
|
10
|
+
return this.velociousDummy
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
static async prepare() {
|
|
16
|
-
const
|
|
14
|
+
const db = dummyConfiguration.getDatabasePool()
|
|
17
15
|
|
|
18
|
-
await
|
|
19
|
-
|
|
16
|
+
await db.withConnection(async () => {
|
|
17
|
+
await db.query("DROP TABLE IF EXISTS tasks")
|
|
18
|
+
await db.query("CREATE TABLE tasks (id MEDIUMINT NOT NULL AUTO_INCREMENT, name VARCHAR(255), description TEXT, PRIMARY KEY (id))")
|
|
19
|
+
})
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
static async run(callback) {
|
|
@@ -24,21 +24,25 @@ export default class Dummy {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async run(callback) {
|
|
27
|
-
await
|
|
27
|
+
await dummyConfiguration.getDatabasePool().withConnection(async () => {
|
|
28
|
+
await this.start()
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
try {
|
|
31
|
+
await Dummy.prepare()
|
|
32
|
+
await callback()
|
|
33
|
+
} finally {
|
|
34
|
+
await this.stop()
|
|
35
|
+
}
|
|
36
|
+
})
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
async start() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
if (!dummyConfiguration.isDatabasePoolInitialized()) {
|
|
41
|
+
await dummyConfiguration.initializeDatabasePool()
|
|
42
|
+
}
|
|
40
43
|
|
|
41
44
|
this.application = new Application({
|
|
45
|
+
configuration: dummyConfiguration,
|
|
42
46
|
databases: {
|
|
43
47
|
default: {
|
|
44
48
|
host: "mysql",
|
|
@@ -46,19 +50,11 @@ export default class Dummy {
|
|
|
46
50
|
password: ""
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
|
-
debug: false,
|
|
50
|
-
directory: __dirname,
|
|
51
53
|
httpServer: {port: 3006}
|
|
52
54
|
})
|
|
53
55
|
|
|
54
56
|
await this.application.initialize()
|
|
55
57
|
await this.application.startHttpServer()
|
|
56
|
-
|
|
57
|
-
const databasePool = DatabasePool.current()
|
|
58
|
-
|
|
59
|
-
if (!databasePool.isConnected()) {
|
|
60
|
-
await databasePool.connect()
|
|
61
|
-
}
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
async stop() {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.mjs"
|
|
2
|
+
import Configuration from "../../../../src/configuration.mjs"
|
|
3
|
+
import dummyDirectory from "../../dummy-directory.mjs"
|
|
4
|
+
import MysqlDriver from "../../../../src/database/drivers/mysql/index.mjs"
|
|
5
|
+
|
|
6
|
+
export default new Configuration({
|
|
7
|
+
database: {
|
|
8
|
+
default: {
|
|
9
|
+
master: {
|
|
10
|
+
driver: MysqlDriver,
|
|
11
|
+
poolType: AsyncTrackedMultiConnection,
|
|
12
|
+
type: "mysql",
|
|
13
|
+
host: "mariadb",
|
|
14
|
+
username: "username",
|
|
15
|
+
password: "password",
|
|
16
|
+
database: "velocious_test"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
directory: dummyDirectory()
|
|
21
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.mjs"
|
|
2
|
+
import Configuration from "../../../../src/configuration.mjs"
|
|
3
|
+
import dummyDirectory from "../../dummy-directory.mjs"
|
|
4
|
+
import MysqlDriver from "../../../../src/database/drivers/mysql/index.mjs"
|
|
5
|
+
|
|
6
|
+
export default new Configuration({
|
|
7
|
+
database: {
|
|
8
|
+
default: {
|
|
9
|
+
master: {
|
|
10
|
+
driver: MysqlDriver,
|
|
11
|
+
poolType: AsyncTrackedMultiConnection,
|
|
12
|
+
type: "mysql",
|
|
13
|
+
host: "mariadb",
|
|
14
|
+
username: "peakflow",
|
|
15
|
+
password: "password",
|
|
16
|
+
database: "velocious_test",
|
|
17
|
+
useDatabase: "velocious_test"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
directory: dummyDirectory()
|
|
22
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Migration from "../../../../../src/database/migration/index.mjs"
|
|
2
|
+
|
|
3
|
+
export default class CreateProjects extends Migration {
|
|
4
|
+
async change() {
|
|
5
|
+
await this.createTable("projects", (table) => {
|
|
6
|
+
table.bigint("id", {autoIncrement: true, primaryKey: true})
|
|
7
|
+
table.string("name", {maxLength: 100, null: false})
|
|
8
|
+
table.timestamps()
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Migration from "../../../../../src/database/migration/index.mjs"
|
|
2
|
+
|
|
3
|
+
export default class CreateTasks extends Migration {
|
|
4
|
+
async change() {
|
|
5
|
+
await this.createTable("tasks", (table) => {
|
|
6
|
+
table.bigint("id", {autoIncrement: true, primaryKey: true})
|
|
7
|
+
table.references("project")
|
|
8
|
+
table.string("name")
|
|
9
|
+
table.text("description")
|
|
10
|
+
table.timestamps()
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
+
import AppRoutes from "../../src/routes/app-routes.mjs"
|
|
1
2
|
import Client from "../../src/http-server/client/index.mjs"
|
|
2
|
-
import Configuration from "../../src/configuration.mjs"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
|
-
import
|
|
5
|
-
import {fileURLToPath} from "url"
|
|
6
|
-
import path from "path"
|
|
4
|
+
import dummyConfiguration from "../dummy/src/config/configuration.mjs"
|
|
7
5
|
|
|
8
6
|
describe("http server - client", () => {
|
|
9
7
|
it("spawns a request for each that it is fed", async () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const configuration = new Configuration({
|
|
14
|
-
directory: dummyDirectory
|
|
15
|
-
})
|
|
8
|
+
await dummyConfiguration.initialize()
|
|
9
|
+
|
|
10
|
+
const routes = await AppRoutes.getRoutes(dummyConfiguration)
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
dummyConfiguration.setRoutes(routes)
|
|
18
13
|
|
|
19
14
|
const client = new Client({
|
|
20
15
|
clientCount: 0,
|
|
21
|
-
configuration
|
|
16
|
+
configuration: dummyConfiguration
|
|
22
17
|
})
|
|
23
18
|
|
|
24
19
|
const strings = [
|
package/src/application.mjs
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
+
import AppRoutes from "../src/routes/app-routes.mjs"
|
|
1
2
|
import {digs} from "diggerize"
|
|
2
|
-
import Configuration from "./configuration.mjs"
|
|
3
3
|
import logger from "./logger.mjs"
|
|
4
4
|
import HttpServer from "./http-server/index.mjs"
|
|
5
5
|
|
|
6
6
|
export default class VelociousApplication {
|
|
7
|
-
constructor({
|
|
8
|
-
this.configuration =
|
|
7
|
+
constructor({configuration, httpServer}) {
|
|
8
|
+
this.configuration = configuration
|
|
9
9
|
this.httpServerConfiguration = httpServer ?? {}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async initialize() {
|
|
13
|
-
|
|
14
|
-
if (global.velociousConfiguration) throw new Error("A Velocious configuration has already been set")
|
|
15
|
-
|
|
16
|
-
global.velociousApplication = this
|
|
17
|
-
global.velociousConfiguration = this.configuration
|
|
13
|
+
const routes = await AppRoutes.getRoutes(this.configuration)
|
|
18
14
|
|
|
19
15
|
await this.configuration.initialize()
|
|
16
|
+
|
|
17
|
+
this.configuration.setRoutes(routes)
|
|
18
|
+
|
|
19
|
+
if (!this.configuration.isDatabasePoolInitialized()) {
|
|
20
|
+
await this.configuration.initializeDatabasePool()
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
isActive() {
|
|
@@ -49,8 +51,5 @@ export default class VelociousApplication {
|
|
|
49
51
|
logger(this, "Stopping server")
|
|
50
52
|
|
|
51
53
|
await this.httpServer.stop()
|
|
52
|
-
|
|
53
|
-
global.velociousApplication = undefined
|
|
54
|
-
global.velociousConfiguration = undefined
|
|
55
54
|
}
|
|
56
55
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
|
|
3
|
+
export default class VelociousCliBaseCommand {
|
|
4
|
+
constructor(args) {
|
|
5
|
+
this.args = args
|
|
6
|
+
this.configuration = this.args.configuration
|
|
7
|
+
this.processArgs = args.processArgs
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
directory = () => digg(this, "configuration").getDirectory()
|
|
11
|
+
}
|
|
@@ -1,14 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import BaseCommand from "../../base-command.mjs"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import TableData from "../../../database/table-data/index.mjs"
|
|
4
|
+
|
|
5
|
+
export default class DbCreate extends BaseCommand{
|
|
6
|
+
async execute() {
|
|
7
|
+
this.databasePool = this.configuration.getDatabasePool()
|
|
8
|
+
this.newConfiguration = Object.assign({}, this.databasePool.getConfiguration())
|
|
9
|
+
|
|
10
|
+
if (this.args.testing) this.result = []
|
|
11
|
+
|
|
12
|
+
// Use a database known to exist. Since we are creating the database, it shouldn't actually exist which would make connecting fail.
|
|
13
|
+
this.newConfiguration.database = this.newConfiguration.useDatabase || "mysql"
|
|
14
|
+
|
|
15
|
+
this.databaseConnection = await this.databasePool.spawnConnectionWithConfiguration(this.newConfiguration)
|
|
16
|
+
await this.databaseConnection.connect()
|
|
17
|
+
|
|
18
|
+
this.createDatabase()
|
|
19
|
+
await this.createSchemaMigrationsTable()
|
|
20
|
+
|
|
21
|
+
await this.databaseConnection.close()
|
|
22
|
+
|
|
23
|
+
if (this.args.testing) return this.result
|
|
4
24
|
}
|
|
5
25
|
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
26
|
+
async createDatabase() {
|
|
27
|
+
const databaseName = digg(this.databasePool.getConfiguration(), "database")
|
|
28
|
+
const sql = this.databaseConnection.createDatabaseSql(databaseName, {ifNotExists: true})
|
|
29
|
+
|
|
30
|
+
if (this.args.testing) {
|
|
31
|
+
this.result.push({databaseName, sql})
|
|
32
|
+
} else {
|
|
33
|
+
await this.databaseConnection.query(sql)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async createSchemaMigrationsTable() {
|
|
38
|
+
const schemaMigrationsTable = new TableData("schema_migrations", {ifNotExists: true})
|
|
39
|
+
|
|
40
|
+
schemaMigrationsTable.string("version", {null: false, primaryKey: true})
|
|
9
41
|
|
|
10
|
-
|
|
42
|
+
const createSchemaMigrationsTableSql = this.databaseConnection.createTableSql(schemaMigrationsTable)
|
|
11
43
|
|
|
12
|
-
|
|
44
|
+
if (this.args.testing) {
|
|
45
|
+
this.result.push({createSchemaMigrationsTableSql})
|
|
46
|
+
} else {
|
|
47
|
+
await this.databaseConnection.query(createSchemaMigrationsTableSql)
|
|
48
|
+
}
|
|
13
49
|
}
|
|
14
50
|
}
|