velocious 1.0.0 → 1.0.2

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 (120) hide show
  1. package/README.md +26 -0
  2. package/bin/velocious.mjs +8 -0
  3. package/index.mjs +17 -0
  4. package/package.json +13 -6
  5. package/peak_flow.yml +9 -5
  6. package/spec/cli/generate/migration-spec.mjs +9 -0
  7. package/spec/database/connection/drivers/mysql/{query-parser-spec.cjs → query-parser-spec.mjs} +12 -8
  8. package/spec/database/drivers/mysql/connection-spec.mjs +21 -0
  9. package/spec/database/record/create-spec.mjs +14 -0
  10. package/spec/database/record/destroy-spec.mjs +17 -0
  11. package/spec/database/record/find-spec.mjs +29 -0
  12. package/spec/database/record/update-spec.mjs +15 -0
  13. package/spec/dummy/index.mjs +69 -0
  14. package/spec/dummy/src/config/database.example.mjs +15 -0
  15. package/spec/dummy/src/config/database.peakflow.mjs +15 -0
  16. package/spec/dummy/src/{routes.cjs → config/routes.mjs} +3 -2
  17. package/spec/dummy/src/database/migrations/001-create-tasks.mjs +12 -0
  18. package/spec/dummy/src/models/task.mjs +4 -0
  19. package/spec/dummy/src/routes/tasks/controller.mjs +26 -0
  20. package/spec/http-server/{client-spec.cjs → client-spec.mjs} +12 -5
  21. package/spec/http-server/{get-spec.cjs → get-spec.mjs} +2 -2
  22. package/spec/http-server/post-spec.mjs +72 -0
  23. package/spec/support/jasmine.json +4 -3
  24. package/src/application.mjs +56 -0
  25. package/src/cli/commands/db/create.mjs +14 -0
  26. package/src/cli/commands/generate/migration.mjs +12 -0
  27. package/src/cli/index.mjs +39 -0
  28. package/src/configuration.mjs +27 -0
  29. package/src/{controller.cjs → controller.mjs} +21 -4
  30. package/src/database/drivers/base.mjs +9 -0
  31. package/src/database/drivers/index.mjs +5 -0
  32. package/src/database/drivers/mysql/connect-connection.mjs +12 -0
  33. package/src/database/drivers/mysql/index.mjs +77 -0
  34. package/src/database/drivers/mysql/options.mjs +17 -0
  35. package/src/database/drivers/mysql/query-parser.mjs +25 -0
  36. package/src/database/drivers/mysql/query.mjs +26 -0
  37. package/src/database/drivers/mysql/sql/delete.mjs +19 -0
  38. package/src/database/drivers/mysql/sql/insert.mjs +29 -0
  39. package/src/database/drivers/mysql/sql/update.mjs +31 -0
  40. package/src/database/handler.mjs +11 -0
  41. package/src/database/index.mjs +15 -0
  42. package/src/database/migration/index.mjs +5 -0
  43. package/src/database/migrator/index.mjs +15 -0
  44. package/src/database/pool/index.mjs +43 -0
  45. package/src/database/query/delete-base.mjs +15 -0
  46. package/src/database/query/from-base.mjs +9 -0
  47. package/src/database/query/from-plain.mjs +12 -0
  48. package/src/database/query/{from-table.cjs → from-table.mjs} +2 -2
  49. package/src/database/query/index.mjs +144 -0
  50. package/src/database/query/insert-base.mjs +15 -0
  51. package/src/database/query/join-base.mjs +9 -0
  52. package/src/database/query/join-plain.mjs +12 -0
  53. package/src/database/query/order-base.mjs +9 -0
  54. package/src/database/query/order-plain.mjs +21 -0
  55. package/src/database/query/select-base.mjs +9 -0
  56. package/src/database/query/select-plain.mjs +12 -0
  57. package/src/database/query/{select-table-and-column.cjs → select-table-and-column.mjs} +4 -4
  58. package/src/database/query/update-base.mjs +16 -0
  59. package/src/database/query-parser/{from-parser.cjs → from-parser.mjs} +3 -6
  60. package/src/database/query-parser/{joins-parser.cjs → joins-parser.mjs} +3 -6
  61. package/src/database/query-parser/{options.cjs → options.mjs} +13 -2
  62. package/src/database/query-parser/{select-parser.cjs → select-parser.mjs} +7 -6
  63. package/src/database/record/index.mjs +187 -0
  64. package/src/database/record/record-not-found-error.mjs +1 -0
  65. package/src/{error-logger.js → error-logger.mjs} +1 -1
  66. package/src/http-server/client/{index.cjs → index.mjs} +10 -11
  67. package/src/http-server/client/params-to-object.mjs +68 -0
  68. package/src/http-server/client/request-buffer/form-data-part.mjs +42 -0
  69. package/src/http-server/client/request-buffer/header.mjs +7 -0
  70. package/src/http-server/client/request-buffer/index.mjs +229 -0
  71. package/src/http-server/client/request-parser.mjs +47 -0
  72. package/src/http-server/client/{request-runner.cjs → request-runner.mjs} +5 -5
  73. package/src/http-server/client/request.mjs +15 -0
  74. package/src/http-server/client/{response.cjs → response.mjs} +1 -1
  75. package/src/http-server/index.mjs +137 -0
  76. package/src/http-server/server-client.mjs +47 -0
  77. package/src/http-server/worker-handler/index.mjs +79 -0
  78. package/src/http-server/worker-handler/worker-script.mjs +4 -0
  79. package/src/http-server/worker-handler/{worker-thread.cjs → worker-thread.mjs} +18 -11
  80. package/src/{logger.cjs → logger.mjs} +2 -2
  81. package/src/routes/base-route.mjs +34 -0
  82. package/src/routes/{get-route.cjs → get-route.mjs} +5 -3
  83. package/src/routes/index.mjs +9 -0
  84. package/src/routes/{resolver.cjs → resolver.mjs} +15 -9
  85. package/src/routes/{resource-route.cjs → resource-route.mjs} +9 -5
  86. package/src/routes/root-route.mjs +6 -0
  87. package/bin/velocious +0 -14
  88. package/index.cjs +0 -11
  89. package/spec/dummy/config/databases.example.json +0 -10
  90. package/spec/dummy/config/databases.json +0 -0
  91. package/spec/dummy/config/databases.peakflow.json +0 -11
  92. package/spec/dummy/index.cjs +0 -40
  93. package/spec/dummy/src/models/task.cjs +0 -4
  94. package/spec/dummy/src/routes/tasks/controller.cjs +0 -18
  95. package/src/application.cjs +0 -36
  96. package/src/configuration.cjs +0 -14
  97. package/src/database/connection/drivers/mysql/index.cjs +0 -5
  98. package/src/database/connection/drivers/mysql/options.cjs +0 -7
  99. package/src/database/connection/drivers/mysql/query-parser.cjs +0 -26
  100. package/src/database/connection/index.cjs +0 -2
  101. package/src/database/handler.cjs +0 -5
  102. package/src/database/index.cjs +0 -9
  103. package/src/database/pool/index.cjs +0 -2
  104. package/src/database/query/from-base.cjs +0 -15
  105. package/src/database/query/from-plain.cjs +0 -12
  106. package/src/database/query/index.cjs +0 -59
  107. package/src/database/query/join-base.cjs +0 -15
  108. package/src/database/query/join-plain.cjs +0 -12
  109. package/src/database/query/select-base.cjs +0 -15
  110. package/src/database/query/select-plain.cjs +0 -12
  111. package/src/database/record/index.cjs +0 -5
  112. package/src/http-server/client/request-parser.cjs +0 -92
  113. package/src/http-server/client/request.cjs +0 -25
  114. package/src/http-server/index.cjs +0 -78
  115. package/src/http-server/worker-handler/index.cjs +0 -78
  116. package/src/http-server/worker-handler/socket-handler.cjs +0 -35
  117. package/src/http-server/worker-handler/worker-script.cjs +0 -4
  118. package/src/routes/base-route.cjs +0 -25
  119. package/src/routes/index.cjs +0 -9
  120. package/src/routes/root-route.cjs +0 -4
@@ -1,78 +0,0 @@
1
- const logger = require("../logger.cjs")
2
- const Net = require("net")
3
- const WorkerHandler = require("./worker-handler/index.cjs")
4
-
5
- module.exports = class VelociousHttpServer {
6
- constructor({configuration, host, maxWorkers, port}) {
7
- this.configuration = configuration
8
- this.host = host
9
- this.port = port
10
- this.clientCount = 0
11
- this.maxWorkers = maxWorkers || 16
12
- this.workerCount = 0
13
- this.workerHandlers = []
14
- }
15
-
16
- async start() {
17
- // We need at least one worker to handle requests
18
- if (this.workerHandlers.length == 0) {
19
- await this.spawnWorker()
20
- }
21
-
22
- this.netServer = new Net.Server()
23
- this.netServer.on("connection", (socket) => this.onConnection(socket))
24
- this.netServer.listen(this.port, () => {
25
- logger(this, `Velocious listening on ${this.host}:${this.port}`)
26
- })
27
- }
28
-
29
- stop() {
30
- return new Promise((resolve) => {
31
- this.netServer?.close(() => resolve())
32
- })
33
- }
34
-
35
- onConnection(socket) {
36
- const clientCount = this.clientCount
37
-
38
- logger(this, `New client ${clientCount}`)
39
-
40
- this.clientCount++
41
-
42
- const workerHandler = this.workerHandlerToUse()
43
-
44
- logger(this, `Gave client ${clientCount} to worker ${workerHandler.workerCount}`)
45
-
46
- workerHandler.addSocketConnection({
47
- socket,
48
- clientCount: this.clientCount
49
- })
50
- }
51
-
52
- async spawnWorker() {
53
- const workerCount = this.workerCount
54
-
55
- this.workerCount++
56
-
57
- const workerHandler = new WorkerHandler({
58
- configuration: this.configuration,
59
- workerCount
60
- })
61
-
62
- await workerHandler.start()
63
- this.workerHandlers.push(workerHandler)
64
- }
65
-
66
- workerHandlerToUse() {
67
- logger(this, `Worker handlers length: ${this.workerHandlers.length}`)
68
-
69
- const randomWorkerNumber = parseInt(Math.random() * this.workerHandlers.length)
70
- const workerHandler = this.workerHandlers[randomWorkerNumber]
71
-
72
- if (!workerHandler) {
73
- throw new Error(`No workerHandler by that number: ${randomWorkerNumber}`)
74
- }
75
-
76
- return workerHandler
77
- }
78
- }
@@ -1,78 +0,0 @@
1
- const {digs} = require("diggerize")
2
- const logger = require("../../logger.cjs")
3
- const SocketHandler = require("./socket-handler.cjs")
4
- const {Worker} = require("worker_threads")
5
-
6
- module.exports = class VelociousHttpServerWorker {
7
- constructor({configuration, workerCount}) {
8
- this.configuration = configuration
9
- this.socketHandlers = {}
10
- this.workerCount = workerCount
11
- }
12
-
13
- async start() {
14
- return new Promise((resolve) => {
15
- const {debug, directory} = digs(this.configuration, "debug", "directory")
16
-
17
- this.onStartCallback = resolve
18
- this.worker = new Worker("./src/http-server/worker-handler/worker-script.cjs", {
19
- workerData: {
20
- debug,
21
- directory,
22
- workerCount: this.workerCount
23
- }
24
- })
25
- this.worker.on("error", (error) => this.onWorkerError(error))
26
- this.worker.on("exit", (code) => this.onWorkerExit(code))
27
- this.worker.on("message", (message) => this.onWorkerMessage(message))
28
- })
29
- }
30
-
31
- addSocketConnection({socket, clientCount}) {
32
- socket.on("end", () => {
33
- logger(this, `Removing ${clientCount} from socketHandlers`)
34
- delete this.socketHandlers[clientCount]
35
- })
36
-
37
- const socketHandler = new SocketHandler({
38
- configuration: this.configuration,
39
- socket,
40
- clientCount,
41
- worker: this.worker
42
- })
43
-
44
- this.socketHandlers[clientCount] = socketHandler
45
- this.worker.postMessage({command: "newClient", clientCount})
46
- }
47
-
48
- onWorkerError(error) {
49
- throw new Error(`Worker error: ${error}`)
50
- }
51
-
52
- onWorkerExit(code) {
53
- if (code !== 0) {
54
- throw new Error(`Client worker stopped with exit code ${code}`)
55
- }
56
- }
57
-
58
- onWorkerMessage(data) {
59
- logger(this, `Worker message`, data)
60
-
61
- const {command} = digs(data, "command")
62
-
63
- if (command == "started") {
64
- this.onStartCallback()
65
- this.onStartCallback = null
66
- } else if (command == "clientOutput") {
67
- logger(this, "CLIENT OUTPUT", data)
68
-
69
- const {clientCount, output} = digs(data, "clientCount", "output")
70
-
71
- logger(this, "CLIENT OUTPUT", data)
72
-
73
- this.socketHandlers[clientCount].send(output)
74
- } else {
75
- throw new Error(`Unknown command: ${command}`)
76
- }
77
- }
78
- }
@@ -1,35 +0,0 @@
1
- const logger = require("../../logger.cjs")
2
-
3
- module.exports = class VelociousHttpServerWorkerHandlerSocketHandler {
4
- constructor({configuration, socket, clientCount, worker}) {
5
- if (!configuration) throw new Error("No configuration given")
6
-
7
- this.configuration = configuration
8
- this.socket = socket
9
- this.clientCount = clientCount
10
- this.worker = worker
11
-
12
- socket.on("data", (chunk) => this.onSocketData(chunk))
13
- socket.on("end", () => this.onSocketEnd())
14
- }
15
-
16
- onSocketData(chunk) {
17
- logger(this, `Socket ${this.clientCount}: ${chunk}`)
18
-
19
- this.worker.postMessage({
20
- command: "clientWrite",
21
- chunk,
22
- clientCount: this.clientCount
23
- })
24
- }
25
-
26
- onSocketEnd() {
27
- logger(this, `Socket ${this.clientCount} end`)
28
- }
29
-
30
- send(data) {
31
- logger(this, "Send", data)
32
-
33
- this.socket.write(data)
34
- }
35
- }
@@ -1,4 +0,0 @@
1
- const { workerData, parentPort } = require("worker_threads")
2
- const WorkerThread = require("./worker-thread.cjs")
3
-
4
- new WorkerThread({parentPort, workerData})
@@ -1,25 +0,0 @@
1
- module.exports = class VelociousBaseRoute {
2
- routes = []
3
-
4
- get(name, args) {
5
- const GetRoute = require("./get-route.cjs")
6
- const route = new GetRoute({name, args})
7
-
8
- this.routes.push(route)
9
- }
10
-
11
- matchWithPath(_path) {
12
- throw new Error(`No 'matchWithPath' implemented on ${this.constructor.name}`)
13
- }
14
-
15
- resources(name, callback) {
16
- const ResourceRoute = require("./resource-route.cjs")
17
- const route = new ResourceRoute({name})
18
-
19
- this.routes.push(route)
20
-
21
- if (callback) {
22
- callback(route)
23
- }
24
- }
25
- }
@@ -1,9 +0,0 @@
1
- const RootRoute = require("./root-route.cjs")
2
-
3
- module.exports = class VelociousRoutes {
4
- rootRoute = new RootRoute()
5
-
6
- draw(callback) {
7
- callback(this.rootRoute)
8
- }
9
- }
@@ -1,4 +0,0 @@
1
- const BaseRoute = require("./base-route.cjs")
2
-
3
- module.exports = class VelociousRootRoute extends BaseRoute {
4
- }