velocious 1.0.5 → 1.0.7

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 (173) hide show
  1. package/bin/{velocious.mjs → velocious.js} +1 -1
  2. package/package.json +7 -5
  3. package/peak_flow.yml +1 -1
  4. package/spec/cli/commands/db/{create-spec.mjs → create-spec.js} +3 -3
  5. package/spec/cli/commands/db/{migrate-spec.mjs → migrate-spec.js} +4 -2
  6. package/spec/cli/commands/destroy/{migration-spec.mjs → migration-spec.js} +2 -2
  7. package/spec/cli/commands/generate/{migration-spec.mjs → migration-spec.js} +3 -3
  8. package/spec/cli/commands/{init-spec.mjs → init-spec.js} +6 -6
  9. package/spec/cli/commands/test/{test-files-finder-spec.mjs → test-files-finder-spec.js} +2 -2
  10. package/spec/database/connection/drivers/mysql/{query-parser-spec.mjs → query-parser-spec.js} +6 -6
  11. package/spec/database/drivers/mysql/{connection-spec.mjs → connection-spec.js} +2 -2
  12. package/spec/database/record/create-spec.js +23 -0
  13. package/spec/database/record/{destroy-spec.mjs → destroy-spec.js} +2 -2
  14. package/spec/database/record/{find-spec.mjs → find-spec.js} +2 -3
  15. package/spec/database/record/query-spec.js +37 -0
  16. package/spec/database/record/{update-spec.mjs → update-spec.js} +2 -2
  17. package/spec/dummy/{index.mjs → index.js} +16 -4
  18. package/spec/dummy/src/config/configuration.example.js +36 -0
  19. package/spec/dummy/src/config/configuration.peakflow.js +37 -0
  20. package/spec/dummy/src/config/{routes.mjs → routes.js} +1 -1
  21. package/spec/dummy/src/database/migrations/{20230728075328-create-projects.mjs → 20230728075328-create-projects.js} +1 -2
  22. package/spec/dummy/src/database/migrations/{20230728075329-create-tasks.mjs → 20230728075329-create-tasks.js} +1 -2
  23. package/spec/dummy/src/database/migrations/20250605133926-create-project-translations.js +16 -0
  24. package/spec/dummy/src/models/project.js +9 -0
  25. package/spec/dummy/src/models/task.js +8 -0
  26. package/spec/dummy/src/routes/tasks/{controller.mjs → controller.js} +2 -2
  27. package/spec/http-server/{client-spec.mjs → client-spec.js} +3 -3
  28. package/spec/http-server/{get-spec.mjs → get-spec.js} +1 -1
  29. package/spec/http-server/{post-spec.mjs → post-spec.js} +2 -2
  30. package/spec/support/jasmine.json +2 -2
  31. package/src/{application.mjs → application.js} +3 -3
  32. package/src/big-brother.js +37 -0
  33. package/src/cli/commands/db/{create.mjs → create.js} +9 -7
  34. package/src/cli/commands/db/{migrate.mjs → migrate.js} +4 -5
  35. package/src/cli/commands/destroy/{migration.mjs → migration.js} +2 -2
  36. package/src/cli/commands/generate/{migration.mjs → migration.js} +5 -5
  37. package/src/cli/commands/generate/{model.mjs → model.js} +5 -5
  38. package/src/cli/commands/{init.mjs → init.js} +6 -6
  39. package/src/cli/commands/{server.mjs → server.js} +1 -1
  40. package/src/cli/commands/test/{index.mjs → index.js} +3 -3
  41. package/src/cli/commands/test/{test-files-finder.mjs → test-files-finder.js} +1 -1
  42. package/src/cli/{index.mjs → index.js} +4 -4
  43. package/src/{configuration-resolver.mjs → configuration-resolver.js} +2 -2
  44. package/src/{configuration.mjs → configuration.js} +39 -3
  45. package/src/database/drivers/{base.mjs → base.js} +23 -4
  46. package/src/database/drivers/mysql/column.js +8 -0
  47. package/src/database/drivers/mysql/{index.mjs → index.js} +44 -12
  48. package/src/database/drivers/{sqlite/options.mjs → mysql/options.js} +2 -1
  49. package/src/database/drivers/mysql/query-parser.js +4 -0
  50. package/src/database/drivers/mysql/sql/{create-database.mjs → create-database.js} +1 -1
  51. package/src/database/drivers/{sqlite/sql/create-table.mjs → mysql/sql/create-table.js} +1 -1
  52. package/src/database/drivers/mysql/sql/{delete.mjs → delete.js} +1 -1
  53. package/src/database/drivers/{sqlite/sql/insert.mjs → mysql/sql/insert.js} +1 -1
  54. package/src/database/drivers/mysql/sql/{update.mjs → update.js} +1 -1
  55. package/src/database/drivers/mysql/table.js +25 -0
  56. package/src/database/drivers/sqlite/base.js +108 -0
  57. package/src/database/drivers/sqlite/column.js +10 -0
  58. package/src/database/drivers/sqlite/{index.native.mjs → index.native.js} +19 -22
  59. package/src/database/drivers/sqlite/index.web.js +55 -0
  60. package/src/database/drivers/{mysql/options.mjs → sqlite/options.js} +3 -2
  61. package/src/database/drivers/sqlite/query-parser.js +4 -0
  62. package/src/database/drivers/sqlite/query.native.js +24 -0
  63. package/src/database/drivers/sqlite/query.web.js +34 -0
  64. package/src/database/drivers/sqlite/sql/create-index.js +4 -0
  65. package/src/database/drivers/{mysql/sql/create-table.mjs → sqlite/sql/create-table.js} +1 -1
  66. package/src/database/drivers/sqlite/sql/{delete.mjs → delete.js} +1 -1
  67. package/src/database/drivers/{mysql/sql/insert.mjs → sqlite/sql/insert.js} +1 -1
  68. package/src/database/drivers/sqlite/sql/{update.mjs → update.js} +1 -1
  69. package/src/database/drivers/sqlite/table.js +24 -0
  70. package/src/database/initializer-from-require-context.js +21 -0
  71. package/src/database/{migrate-from-require-context.mjs → migrate-from-require-context.js} +2 -2
  72. package/src/database/migration/index.js +50 -0
  73. package/src/database/{migrator.mjs → migrator.js} +4 -2
  74. package/src/database/pool/{async-tracked-multi-connection.mjs → async-tracked-multi-connection.js} +1 -1
  75. package/src/database/pool/{base.mjs → base.js} +6 -1
  76. package/src/database/pool/{single-multi-use.mjs → single-multi-use.js} +1 -1
  77. package/src/database/query/{base.mjs → base.js} +2 -1
  78. package/src/database/query/{create-database-base.mjs → create-database-base.js} +1 -1
  79. package/src/database/query/create-index-base.js +50 -0
  80. package/src/database/query/create-table-base.js +92 -0
  81. package/src/database/query/{delete-base.mjs → delete-base.js} +1 -1
  82. package/src/database/query/{from-plain.mjs → from-plain.js} +1 -1
  83. package/src/database/query/{from-table.mjs → from-table.js} +1 -1
  84. package/src/database/query/index.js +206 -0
  85. package/src/database/query/{join-plain.mjs → join-plain.js} +1 -1
  86. package/src/database/query/{order-plain.mjs → order-plain.js} +1 -1
  87. package/src/database/query/preloader/belongs-to.js +52 -0
  88. package/src/database/query/preloader/has-many.js +55 -0
  89. package/src/database/query/preloader.js +41 -0
  90. package/src/database/query/{select-plain.mjs → select-plain.js} +1 -1
  91. package/src/database/query/{select-table-and-column.mjs → select-table-and-column.js} +1 -1
  92. package/src/database/query/where-base.js +9 -0
  93. package/src/database/query/where-hash.js +35 -0
  94. package/src/database/query/where-plain.js +13 -0
  95. package/src/database/query-parser/base-query-parser.js +33 -0
  96. package/src/database/query-parser/group-parser.js +40 -0
  97. package/src/database/query-parser/joins-parser.js +71 -0
  98. package/src/database/query-parser/limit-parser.js +40 -0
  99. package/src/database/query-parser/{options.mjs → options.js} +2 -1
  100. package/src/database/query-parser/order-parser.js +39 -0
  101. package/src/database/query-parser/{select-parser.mjs → select-parser.js} +5 -1
  102. package/src/database/query-parser/where-parser.js +39 -0
  103. package/src/database/record/index.js +622 -0
  104. package/src/database/record/instance-relationships/base.js +28 -0
  105. package/src/database/record/instance-relationships/belongs-to.js +20 -0
  106. package/src/database/record/instance-relationships/has-many.js +47 -0
  107. package/src/database/record/relationships/base.js +32 -0
  108. package/src/database/record/relationships/belongs-to.js +12 -0
  109. package/src/database/record/relationships/has-many.js +12 -0
  110. package/src/database/table-data/{index.mjs → index.js} +15 -25
  111. package/src/http-server/client/{index.mjs → index.js} +3 -3
  112. package/src/http-server/client/request-buffer/{index.mjs → index.js} +4 -4
  113. package/src/http-server/client/{request-parser.mjs → request-parser.js} +2 -2
  114. package/src/http-server/client/{request-runner.mjs → request-runner.js} +3 -3
  115. package/src/http-server/client/{request.mjs → request.js} +1 -1
  116. package/src/http-server/{index.mjs → index.js} +3 -3
  117. package/src/http-server/{server-client.mjs → server-client.js} +1 -1
  118. package/src/http-server/worker-handler/{index.mjs → index.js} +2 -2
  119. package/src/http-server/worker-handler/{worker-script.mjs → worker-script.js} +1 -1
  120. package/src/http-server/worker-handler/{worker-thread.mjs → worker-thread.js} +12 -9
  121. package/src/routes/{app-routes.mjs → app-routes.js} +1 -1
  122. package/src/routes/{base-route.mjs → base-route.js} +2 -2
  123. package/src/routes/{get-route.mjs → get-route.js} +1 -1
  124. package/src/routes/{index.mjs → index.js} +1 -1
  125. package/src/routes/{resolver.mjs → resolver.js} +1 -1
  126. package/src/routes/{resource-route.mjs → resource-route.js} +1 -1
  127. package/src/routes/{root-route.mjs → root-route.js} +1 -1
  128. package/src/templates/{configuration.mjs → configuration.js} +3 -3
  129. package/src/templates/{generate-migration.mjs → generate-migration.js} +1 -1
  130. package/src/templates/generate-model.js +6 -0
  131. package/src/templates/{routes.mjs → routes.js} +1 -1
  132. package/src/utils/rest-args-error.js +9 -0
  133. package/spec/database/record/create-spec.mjs +0 -14
  134. package/spec/dummy/src/config/configuration.example.mjs +0 -21
  135. package/spec/dummy/src/config/configuration.peakflow.mjs +0 -22
  136. package/spec/dummy/src/models/task.mjs +0 -4
  137. package/src/database/drivers/mysql/query-parser.mjs +0 -25
  138. package/src/database/drivers/sqlite/base.mjs +0 -36
  139. package/src/database/drivers/sqlite/index.web.mjs +0 -45
  140. package/src/database/drivers/sqlite/query-parser.mjs +0 -25
  141. package/src/database/drivers/sqlite/query.native.mjs +0 -9
  142. package/src/database/drivers/sqlite/query.web.mjs +0 -9
  143. package/src/database/drivers/sqlite/table.mjs +0 -9
  144. package/src/database/migration/index.mjs +0 -18
  145. package/src/database/query/create-table-base.mjs +0 -69
  146. package/src/database/query/index.mjs +0 -144
  147. package/src/database/query-parser/joins-parser.mjs +0 -30
  148. package/src/database/record/index.mjs +0 -187
  149. package/src/templates/generate-model.mjs +0 -4
  150. /package/{index.mjs → index.js} +0 -0
  151. /package/spec/dummy/{dummy-directory.mjs → dummy-directory.js} +0 -0
  152. /package/src/cli/{base-command.mjs → base-command.js} +0 -0
  153. /package/src/cli/commands/test/{test-runner.mjs → test-runner.js} +0 -0
  154. /package/src/{controller.mjs → controller.js} +0 -0
  155. /package/src/database/drivers/mysql/{connect-connection.mjs → connect-connection.js} +0 -0
  156. /package/src/database/drivers/mysql/{query.mjs → query.js} +0 -0
  157. /package/src/database/{handler.mjs → handler.js} +0 -0
  158. /package/src/database/query/{from-base.mjs → from-base.js} +0 -0
  159. /package/src/database/query/{insert-base.mjs → insert-base.js} +0 -0
  160. /package/src/database/query/{join-base.mjs → join-base.js} +0 -0
  161. /package/src/database/query/{order-base.mjs → order-base.js} +0 -0
  162. /package/src/database/query/{select-base.mjs → select-base.js} +0 -0
  163. /package/src/database/query/{update-base.mjs → update-base.js} +0 -0
  164. /package/src/database/query-parser/{from-parser.mjs → from-parser.js} +0 -0
  165. /package/src/database/record/{record-not-found-error.mjs → record-not-found-error.js} +0 -0
  166. /package/src/{error-logger.mjs → error-logger.js} +0 -0
  167. /package/src/http-server/client/{params-to-object.mjs → params-to-object.js} +0 -0
  168. /package/src/http-server/client/request-buffer/{form-data-part.mjs → form-data-part.js} +0 -0
  169. /package/src/http-server/client/request-buffer/{header.mjs → header.js} +0 -0
  170. /package/src/http-server/client/{response.mjs → response.js} +0 -0
  171. /package/src/{logger.mjs → logger.js} +0 -0
  172. /package/src/spec/{index.mjs → index.js} +0 -0
  173. /package/src/utils/{file-exists.mjs → file-exists.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import Cli from "../src/cli/index.mjs"
3
+ import Cli from "../src/cli/index.js"
4
4
 
5
5
  const processArgs = process.argv.slice(2)
6
6
  const cli = new Cli({processArgs})
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "bin": {
3
- "velocious": "bin/velocious.mjs"
3
+ "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.5",
7
- "main": "index.mjs",
6
+ "version": "1.0.7",
7
+ "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
10
10
  "velocious": "asd"
@@ -14,7 +14,7 @@
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/kaspernj/velocious.git"
16
16
  },
17
- "author": "k@spernj.org",
17
+ "author": "kasper@diestoeckels.de",
18
18
  "license": "ISC",
19
19
  "bugs": {
20
20
  "url": "https://github.com/kaspernj/velocious/issues"
@@ -24,9 +24,11 @@
24
24
  "devDependencies": {
25
25
  "jasmine": "^5.0.2",
26
26
  "mysql": "^2.18.1",
27
- "node-fetch": "^3.3.1"
27
+ "node-fetch": "^3.3.1",
28
+ "require-context": "^1.1.0"
28
29
  },
29
30
  "dependencies": {
31
+ "better-localstorage": "^1.0.7",
30
32
  "diggerize": "^1.0.5",
31
33
  "ejs": "^3.1.6",
32
34
  "escape-string-regexp": "^1.0.5",
package/peak_flow.yml CHANGED
@@ -5,7 +5,7 @@ before_install:
5
5
  - sudo apt-get update
6
6
  - sudo apt-get install -y nodejs
7
7
  before_script:
8
- - cp spec/dummy/src/config/configuration.peakflow.mjs spec/dummy/src/config/configuration.mjs
8
+ - cp spec/dummy/src/config/configuration.peakflow.js spec/dummy/src/config/configuration.js
9
9
  - npm install
10
10
  - wait-for-it mariadb:3306
11
11
  services:
@@ -1,5 +1,5 @@
1
- import Cli from "../../../../src/cli/index.mjs"
2
- import dummyDirectory from "../../../dummy/dummy-directory.mjs"
1
+ import Cli from "../../../../src/cli/index.js"
2
+ import dummyDirectory from "../../../dummy/dummy-directory.js"
3
3
 
4
4
  describe("Cli - Commands - db:create", () => {
5
5
  it("generates SQL to create a new database", async () => {
@@ -17,7 +17,7 @@ describe("Cli - Commands - db:create", () => {
17
17
  sql: 'CREATE DATABASE IF NOT EXISTS `velocious_test`'
18
18
  },
19
19
  {
20
- createSchemaMigrationsTableSql: 'CREATE TABLE IF NOT EXISTS schema_migrations (`version` varchar(255) PRIMARY KEY)'
20
+ createSchemaMigrationsTableSql: 'CREATE TABLE IF NOT EXISTS schema_migrations (`version` varchar(255) PRIMARY KEY NOT NULL)'
21
21
  }
22
22
  ]
23
23
  )
@@ -1,5 +1,5 @@
1
- import Cli from "../../../../src/cli/index.mjs"
2
- import dummyDirectory from "../../../dummy/dummy-directory.mjs"
1
+ import Cli from "../../../../src/cli/index.js"
2
+ import dummyDirectory from "../../../dummy/dummy-directory.js"
3
3
 
4
4
  describe("Cli - Commands - db:migrate", () => {
5
5
  it("runs migrations", async () => {
@@ -17,6 +17,7 @@ describe("Cli - Commands - db:migrate", () => {
17
17
  await db.withConnection(async () => {
18
18
  await db.query("DROP TABLE IF EXISTS tasks")
19
19
  await db.query("DROP TABLE IF EXISTS projects")
20
+ await db.query("DROP TABLE IF EXISTS project_translations")
20
21
  })
21
22
 
22
23
  await cli.execute()
@@ -29,6 +30,7 @@ describe("Cli - Commands - db:migrate", () => {
29
30
 
30
31
  expect(tablesResult).toEqual(
31
32
  [
33
+ {Tables_in_velocious_test: "project_translations"},
32
34
  {Tables_in_velocious_test: "projects"},
33
35
  {Tables_in_velocious_test: "tasks"}
34
36
  ]
@@ -1,5 +1,5 @@
1
- import Cli from "../../../../src/cli/index.mjs"
2
- import dummyDirectory from "../../../dummy/dummy-directory.mjs"
1
+ import Cli from "../../../../src/cli/index.js"
2
+ import dummyDirectory from "../../../dummy/dummy-directory.js"
3
3
 
4
4
  describe("Cli - destroy - migration", () => {
5
5
  it("destroys an existing migration", async () => {
@@ -1,5 +1,5 @@
1
- import Cli from "../../../../src/cli/index.mjs"
2
- import dummyDirectory from "../../../dummy/dummy-directory.mjs"
1
+ import Cli from "../../../../src/cli/index.js"
2
+ import dummyDirectory from "../../../dummy/dummy-directory.js"
3
3
 
4
4
  describe("Cli - generate - migration", () => {
5
5
  it("generates a new migration", async () => {
@@ -13,6 +13,6 @@ describe("Cli - generate - migration", () => {
13
13
  expect(result.migrationName).toEqual("create-tasks")
14
14
  expect(result.migrationNameCamelized).toEqual("CreateTasks")
15
15
  expect(result.migrationNumber).toMatch(/^\d+$/)
16
- expect(result.migrationPath).toMatch(/-create-tasks\.mjs$/)
16
+ expect(result.migrationPath).toMatch(/-create-tasks\.js$/)
17
17
  })
18
18
  })
@@ -1,5 +1,5 @@
1
- import Cli from "../../../src/cli/index.mjs"
2
- import dummyDirectory from "../../dummy/dummy-directory.mjs"
1
+ import Cli from "../../../src/cli/index.js"
2
+ import dummyDirectory from "../../dummy/dummy-directory.js"
3
3
 
4
4
  describe("Cli - Commands - init", () => {
5
5
  it("inits files and dirs", async () => {
@@ -11,9 +11,9 @@ describe("Cli - Commands - init", () => {
11
11
  const result = await cli.execute()
12
12
 
13
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")
14
+ expect(result.fileMappings[0].source).toContain("/src/templates/configuration.js")
15
+ expect(result.fileMappings[0].target).toContain("/spec/dummy/src/config/configuration.js")
16
+ expect(result.fileMappings[1].source).toContain("/src/templates/routes.js")
17
+ expect(result.fileMappings[1].target).toContain("/spec/dummy/src/config/routes.js")
18
18
  })
19
19
  })
@@ -1,11 +1,11 @@
1
- import TestFilesFinder from "../../../../src/cli/commands/test/test-files-finder.mjs"
1
+ import TestFilesFinder from "../../../../src/cli/commands/test/test-files-finder.js"
2
2
 
3
3
  describe("Cli - Commands - test - TestFilesFinder", () => {
4
4
  it("finds the correct test files", async () => {
5
5
  const testFilesFinder = new TestFilesFinder({directory: process.cwd(), processArgs: ["test"]})
6
6
  const testFiles = await testFilesFinder.findTestFiles()
7
7
 
8
- const sampleTestFilePath = `${process.cwd()}/spec/cli/commands/destroy/migration-spec.mjs`
8
+ const sampleTestFilePath = `${process.cwd()}/spec/cli/commands/destroy/migration-spec.js`
9
9
 
10
10
  expect(testFiles.includes(sampleTestFilePath)).toBe(true)
11
11
  })
@@ -1,11 +1,11 @@
1
- import DatabaseHandler from "../../../../../src/database/handler.mjs"
2
- import DatabaseQuery from "../../../../../src/database/query/index.mjs"
3
- import MysqlQueryParser from "../../../../../src/database/drivers/mysql/query-parser.mjs"
1
+ import DatabaseHandler from "../../../../../src/database/handler.js"
2
+ import DatabaseQuery from "../../../../../src/database/query/index.js"
3
+ import MysqlQueryParser from "../../../../../src/database/drivers/mysql/query-parser.js"
4
4
 
5
- import FromTable from "../../../../../src/database/query/from-table.mjs"
6
- import SelectTableAndColumn from "../../../../../src/database/query/select-table-and-column.mjs"
5
+ import FromTable from "../../../../../src/database/query/from-table.js"
6
+ import SelectTableAndColumn from "../../../../../src/database/query/select-table-and-column.js"
7
7
 
8
- import MysqlDriverClass from "../../../../../src/database/drivers/mysql/index.mjs"
8
+ import MysqlDriverClass from "../../../../../src/database/drivers/mysql/index.js"
9
9
 
10
10
  const mysqlDriver = new MysqlDriverClass()
11
11
 
@@ -1,5 +1,5 @@
1
- import DatabaseDriversMysql from "../../../../src/database/drivers/mysql/index.mjs"
2
- import configuration from "../../../dummy/src/config/configuration.mjs"
1
+ import DatabaseDriversMysql from "../../../../src/database/drivers/mysql/index.js"
2
+ import configuration from "../../../dummy/src/config/configuration.js"
3
3
  import {digg} from "diggerize"
4
4
 
5
5
  const mysqlConfig = digg(configuration, "database", "default", "master")
@@ -0,0 +1,23 @@
1
+ import Dummy from "../../dummy/index.js"
2
+ import Task from "../../dummy/src/models/task.js"
3
+
4
+ describe("Record - create", () => {
5
+ it("creates a new simple record", async () => {
6
+ await Dummy.run(async () => {
7
+ const task = new Task({name: "Test task"})
8
+ const project = task.buildProject({nameEn: "Test project", nameDe: "Test projekt"})
9
+
10
+ await task.save()
11
+
12
+ expect(task.id()).not.toBeUndefined()
13
+ expect(task.name()).toEqual("Test task")
14
+ expect(task.project().id()).toEqual(project.id())
15
+ expect(task.project()).toEqual(project)
16
+
17
+ expect(project.id()).not.toBeUndefined()
18
+ expect(project.name()).toEqual("Test project")
19
+ expect(project.nameDe()).toEqual("Test projekt")
20
+ expect(project.nameEn()).toEqual("Test project")
21
+ })
22
+ })
23
+ })
@@ -1,5 +1,5 @@
1
- import Dummy from "../../dummy/index.mjs"
2
- import Task from "../../dummy/src/models/task.mjs"
1
+ import Dummy from "../../dummy/index.js"
2
+ import Task from "../../dummy/src/models/task.js"
3
3
 
4
4
  describe("Record - destroy", () => {
5
5
  it("destroys a record", async () => {
@@ -1,6 +1,5 @@
1
- import Dummy from "../../dummy/index.mjs"
2
- import RecordNotFoundError from "../../../src/database/record/record-not-found-error.mjs"
3
- import Task from "../../dummy/src/models/task.mjs"
1
+ import Dummy from "../../dummy/index.js"
2
+ import Task from "../../dummy/src/models/task.js"
4
3
 
5
4
  describe("Record - find", () => {
6
5
  it("finds an existing record", async () => {
@@ -0,0 +1,37 @@
1
+ import Dummy from "../../dummy/index.js"
2
+ import Task from "../../dummy/src/models/task.js"
3
+
4
+ describe("Record - query", () => {
5
+ it("queries for records", async () => {
6
+ await Dummy.run(async () => {
7
+ const task = new Task({name: "Test task"})
8
+ const project = task.buildProject({nameEn: "Test project", nameDe: "Test projekt"})
9
+
10
+ await task.save()
11
+
12
+ expect(task.id()).not.toBeUndefined()
13
+ expect(task.name()).toEqual("Test task")
14
+ expect(task.project().id()).toEqual(project.id())
15
+ expect(task.project()).toEqual(project)
16
+
17
+ expect(project.id()).not.toBeUndefined()
18
+ expect(project.name()).toEqual("Test project")
19
+ expect(project.nameDe()).toEqual("Test projekt")
20
+ expect(project.nameEn()).toEqual("Test project")
21
+
22
+ const tasks = await Task.preload({project: {translations: true}}).toArray()
23
+ const newTask = tasks[0]
24
+ const newProject = newTask.project()
25
+
26
+ expect(newTask.id()).not.toBeUndefined()
27
+ expect(newTask.name()).toEqual("Test task")
28
+ expect(task.project().id()).toEqual(newProject.id())
29
+ expect(newTask.project()).toEqual(newProject)
30
+
31
+ expect(newProject.id()).not.toBeUndefined()
32
+ expect(newProject.name()).toEqual("Test project")
33
+ expect(newProject.nameDe()).toEqual("Test projekt")
34
+ expect(newProject.nameEn()).toEqual("Test project")
35
+ })
36
+ })
37
+ })
@@ -1,5 +1,5 @@
1
- import Dummy from "../../dummy/index.mjs"
2
- import Task from "../../dummy/src/models/task.mjs"
1
+ import Dummy from "../../dummy/index.js"
2
+ import Task from "../../dummy/src/models/task.js"
3
3
 
4
4
  describe("Record - update", () => {
5
5
  it("updates a record", async () => {
@@ -1,5 +1,5 @@
1
- import Application from "../../src/application.mjs"
2
- import dummyConfiguration from "./src/config/configuration.mjs"
1
+ import Application from "../../src/application.js"
2
+ import dummyConfiguration from "./src/config/configuration.js"
3
3
 
4
4
  export default class Dummy {
5
5
  static current() {
@@ -11,11 +11,23 @@ export default class Dummy {
11
11
  }
12
12
 
13
13
  static async prepare() {
14
+ dummyConfiguration.setCurrent()
15
+
14
16
  const db = dummyConfiguration.getDatabasePool()
15
17
 
16
18
  await db.withConnection(async () => {
17
19
  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))")
20
+ await db.query("DROP TABLE IF EXISTS projects")
21
+ await db.query("DROP TABLE IF EXISTS project_translations")
22
+
23
+ await db.query("CREATE TABLE tasks (id MEDIUMINT NOT NULL AUTO_INCREMENT, project_id MEDIUMINT, name VARCHAR(255), description TEXT, PRIMARY KEY (id))")
24
+ await db.query("CREATE TABLE projects (id MEDIUMINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id))")
25
+ await db.query("CREATE TABLE project_translations (id MEDIUMINT NOT NULL AUTO_INCREMENT, project_id MEDIUMINT, locale VARCHAR(255), name VARCHAR(255), PRIMARY KEY (id))")
26
+ await db.query("CREATE UNIQUE INDEX unique_project_translation ON project_translations (project_id, locale)")
27
+
28
+ if (!dummyConfiguration.isInitialized()) {
29
+ await dummyConfiguration.initialize()
30
+ }
19
31
  })
20
32
  }
21
33
 
@@ -25,10 +37,10 @@ export default class Dummy {
25
37
 
26
38
  async run(callback) {
27
39
  await dummyConfiguration.getDatabasePool().withConnection(async () => {
40
+ await Dummy.prepare()
28
41
  await this.start()
29
42
 
30
43
  try {
31
- await Dummy.prepare()
32
44
  await callback()
33
45
  } finally {
34
46
  await this.stop()
@@ -0,0 +1,36 @@
1
+ import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.js"
2
+ import Configuration from "../../../../src/configuration.js"
3
+ import dummyDirectory from "../../dummy-directory.js"
4
+ import fs from "fs/promises"
5
+ import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
6
+ import MysqlDriver from "../../../../src/database/drivers/mysql/index.js"
7
+ import path from "path"
8
+ import requireContext from "require-context"
9
+
10
+ export default new Configuration({
11
+ database: {
12
+ default: {
13
+ master: {
14
+ driver: MysqlDriver,
15
+ poolType: AsyncTrackedMultiConnection,
16
+ type: "mysql",
17
+ host: "mariadb",
18
+ username: "username",
19
+ password: "password",
20
+ database: "velocious_test"
21
+ }
22
+ }
23
+ },
24
+ directory: dummyDirectory(),
25
+ initializeModels: async ({configuration}) => {
26
+ const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
27
+ const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
28
+ const initializerFromRequireContext = new InitializerFromRequireContext({requireContext: requireContextModels})
29
+
30
+ await configuration.getDatabasePool().withConnection(async () => {
31
+ await initializerFromRequireContext.initialize({configuration})
32
+ })
33
+ },
34
+ locale: () => "en",
35
+ locales: ["de", "en"]
36
+ })
@@ -0,0 +1,37 @@
1
+ import AsyncTrackedMultiConnection from "../../../../src/database/pool/async-tracked-multi-connection.js"
2
+ import Configuration from "../../../../src/configuration.js"
3
+ import dummyDirectory from "../../dummy-directory.js"
4
+ import fs from "fs/promises"
5
+ import InitializerFromRequireContext from "../../../../src/database/initializer-from-require-context.js"
6
+ import MysqlDriver from "../../../../src/database/drivers/mysql/index.js"
7
+ import path from "path"
8
+ import requireContext from "require-context"
9
+
10
+ export default new Configuration({
11
+ database: {
12
+ default: {
13
+ master: {
14
+ driver: MysqlDriver,
15
+ poolType: AsyncTrackedMultiConnection,
16
+ type: "mysql",
17
+ host: "mariadb",
18
+ username: "peakflow",
19
+ password: "password",
20
+ database: "velocious_test",
21
+ useDatabase: "velocious_test"
22
+ }
23
+ }
24
+ },
25
+ directory: dummyDirectory(),
26
+ initializeModels: async ({configuration}) => {
27
+ const modelsPath = await fs.realpath(`${path.dirname(import.meta.dirname)}/../src/models`)
28
+ const requireContextModels = requireContext(modelsPath, true, /^(.+)\.js$/)
29
+ const initializerFromRequireContext = new InitializerFromRequireContext({requireContext: requireContextModels})
30
+
31
+ await configuration.getDatabasePool().withConnection(async () => {
32
+ await initializerFromRequireContext.initialize({configuration})
33
+ })
34
+ },
35
+ locale: () => "en",
36
+ locales: ["de", "en"]
37
+ })
@@ -1,4 +1,4 @@
1
- import Routes from "../../../../src/routes/index.mjs"
1
+ import Routes from "../../../../src/routes/index.js"
2
2
 
3
3
  const routes = new Routes()
4
4
 
@@ -1,9 +1,8 @@
1
- import Migration from "../../../../../src/database/migration/index.mjs"
1
+ import Migration from "../../../../../src/database/migration/index.js"
2
2
 
3
3
  export default class CreateProjects extends Migration {
4
4
  async change() {
5
5
  await this.createTable("projects", (table) => {
6
- table.bigint("id", {autoIncrement: true, primaryKey: true})
7
6
  table.string("name", {maxLength: 100, null: false})
8
7
  table.timestamps()
9
8
  })
@@ -1,9 +1,8 @@
1
- import Migration from "../../../../../src/database/migration/index.mjs"
1
+ import Migration from "../../../../../src/database/migration/index.js"
2
2
 
3
3
  export default class CreateTasks extends Migration {
4
4
  async change() {
5
5
  await this.createTable("tasks", (table) => {
6
- table.bigint("id", {autoIncrement: true, primaryKey: true})
7
6
  table.references("project")
8
7
  table.string("name")
9
8
  table.text("description")
@@ -0,0 +1,16 @@
1
+ import Migration from "../../../../../src/database/migration/index.js"
2
+
3
+ export default class CreateProjectTranslations extends Migration {
4
+ async up() {
5
+ await this.createTable("project_translations", (t) => {
6
+ t.references("project", {null: false})
7
+ t.string("locale", {null: false})
8
+ t.string("name")
9
+ t.timestamps()
10
+ })
11
+ }
12
+
13
+ async down() {
14
+ await this.dropTable("project_translations")
15
+ }
16
+ }
@@ -0,0 +1,9 @@
1
+ import DatabaseRecord from "../../../../src/database/record/index.js"
2
+
3
+ class Project extends DatabaseRecord {
4
+ }
5
+
6
+ Project.hasMany("tasks")
7
+ Project.translates("name")
8
+
9
+ export default Project
@@ -0,0 +1,8 @@
1
+ import DatabaseRecord from "../../../../src/database/record/index.js"
2
+
3
+ class Task extends DatabaseRecord {
4
+ }
5
+
6
+ Task.belongsTo("project")
7
+
8
+ export default Task
@@ -1,6 +1,6 @@
1
- import Controller from "../../../../../src/controller.mjs"
1
+ import Controller from "../../../../../src/controller.js"
2
2
  import {digg} from "diggerize"
3
- import Task from "../../models/task.mjs"
3
+ import Task from "../../models/task.js"
4
4
 
5
5
  export default class TasksController extends Controller {
6
6
  index() {
@@ -1,7 +1,7 @@
1
- import AppRoutes from "../../src/routes/app-routes.mjs"
2
- import Client from "../../src/http-server/client/index.mjs"
1
+ import AppRoutes from "../../src/routes/app-routes.js"
2
+ import Client from "../../src/http-server/client/index.js"
3
3
  import {digg} from "diggerize"
4
- import dummyConfiguration from "../dummy/src/config/configuration.mjs"
4
+ import dummyConfiguration from "../dummy/src/config/configuration.js"
5
5
 
6
6
  describe("http server - client", () => {
7
7
  it("spawns a request for each that it is fed", async () => {
@@ -1,5 +1,5 @@
1
1
  import fetch from "node-fetch"
2
- import Dummy from "../dummy/index.mjs"
2
+ import Dummy from "../dummy/index.js"
3
3
 
4
4
  describe("HttpServer", () => {
5
5
  it("handles get requests", async () => {
@@ -1,7 +1,7 @@
1
1
  import fetch from "node-fetch"
2
- import Dummy from "../dummy/index.mjs"
2
+ import Dummy from "../dummy/index.js"
3
3
  import querystring from "querystring"
4
- import Task from "../dummy/src/models/task.mjs"
4
+ import Task from "../dummy/src/models/task.js"
5
5
 
6
6
  describe("HttpServer", () => {
7
7
  it("handles post requests", async () => {
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "spec_dir": "spec",
3
3
  "spec_files": [
4
- "**/*-spec.mjs"
4
+ "**/*-spec.js"
5
5
  ],
6
6
  "helpers": [
7
- "helpers/**/*.mjs"
7
+ "helpers/**/*.js"
8
8
  ],
9
9
  "stopSpecOnExpectationFailure": false,
10
10
  "random": false,
@@ -1,7 +1,7 @@
1
- import AppRoutes from "../src/routes/app-routes.mjs"
1
+ import AppRoutes from "../src/routes/app-routes.js"
2
2
  import {digs} from "diggerize"
3
- import logger from "./logger.mjs"
4
- import HttpServer from "./http-server/index.mjs"
3
+ import logger from "./logger.js"
4
+ import HttpServer from "./http-server/index.js"
5
5
 
6
6
  export default class VelociousApplication {
7
7
  constructor({configuration, httpServer}) {
@@ -0,0 +1,37 @@
1
+ export default class VelociousBigBrother {
2
+ constructor() {
3
+ this.enabledLoggers = {
4
+ databaseQuery: false
5
+ }
6
+ }
7
+
8
+ checkExists(name) {
9
+ if (!(name in this.enabledLoggers)) throw new Error(`Invalid logger name: ${name}`)
10
+ }
11
+
12
+ isEnabled(name) {
13
+ this.checkExists(name)
14
+
15
+ return this.enabledLoggers[name]
16
+ }
17
+
18
+ async run({after, before, name}, callback) {
19
+ this.checkExists(name)
20
+
21
+ if (!this.enabledLoggers[name]) {
22
+ return await callback()
23
+ }
24
+
25
+ if (before) {
26
+ before()
27
+ }
28
+
29
+ const startTime = new Date()
30
+ const result = await callback()
31
+ const endTime = new Date()
32
+
33
+ if (after) {
34
+ after({result})
35
+ }
36
+ }
37
+ }
@@ -1,6 +1,6 @@
1
- import BaseCommand from "../../base-command.mjs"
1
+ import BaseCommand from "../../base-command.js"
2
2
  import {digg} from "diggerize"
3
- import TableData from "../../../database/table-data/index.mjs"
3
+ import TableData from "../../../database/table-data/index.js"
4
4
 
5
5
  export default class DbCreate extends BaseCommand{
6
6
  async execute() {
@@ -39,12 +39,14 @@ export default class DbCreate extends BaseCommand{
39
39
 
40
40
  schemaMigrationsTable.string("version", {null: false, primaryKey: true})
41
41
 
42
- const createSchemaMigrationsTableSql = this.databaseConnection.createTableSql(schemaMigrationsTable)
42
+ const createSchemaMigrationsTableSqls = this.databaseConnection.createTableSql(schemaMigrationsTable)
43
43
 
44
- if (this.args.testing) {
45
- this.result.push({createSchemaMigrationsTableSql})
46
- } else {
47
- await this.databaseConnection.query(createSchemaMigrationsTableSql)
44
+ for (const createSchemaMigrationsTableSql of createSchemaMigrationsTableSqls) {
45
+ if (this.args.testing) {
46
+ this.result.push({createSchemaMigrationsTableSql})
47
+ } else {
48
+ await this.databaseConnection.query(createSchemaMigrationsTableSql)
49
+ }
48
50
  }
49
51
  }
50
52
  }
@@ -1,7 +1,6 @@
1
- import BaseCommand from "../../base-command.mjs"
2
- import {digg} from "diggerize"
1
+ import BaseCommand from "../../base-command.js"
3
2
  import fs from "node:fs/promises"
4
- import inflection from "inflection"
3
+ import * as inflection from "inflection"
5
4
 
6
5
  export default class DbMigrate extends BaseCommand {
7
6
  async execute() {
@@ -11,7 +10,7 @@ export default class DbMigrate extends BaseCommand {
11
10
 
12
11
  files = files
13
12
  .map((file) => {
14
- const match = file.match(/^(\d{14})-(.+)\.mjs$/)
13
+ const match = file.match(/^(\d{14})-(.+)\.js$/)
15
14
 
16
15
  if (!match) return null
17
16
 
@@ -39,7 +38,7 @@ export default class DbMigrate extends BaseCommand {
39
38
 
40
39
  files = migrationFiles
41
40
  .map((file) => {
42
- const match = file.match(/^(\d{14})-(.+)\.mjs$/)
41
+ const match = file.match(/^(\d{14})-(.+)\.js$/)
43
42
 
44
43
  if (!match) return null
45
44