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
@@ -0,0 +1,9 @@
1
+ import RootRoute from "./root-route.mjs"
2
+
3
+ export default class VelociousRoutes {
4
+ rootRoute = new RootRoute()
5
+
6
+ draw(callback) {
7
+ callback(this.rootRoute)
8
+ }
9
+ }
@@ -1,18 +1,18 @@
1
- const {digg, digs} = require("diggerize")
1
+ import {digg, digs} from "diggerize"
2
2
 
3
- module.exports = class VelociousRoutesResolver {
4
- constructor({configuration, request, response, routes}) {
3
+ export default class VelociousRoutesResolver {
4
+ constructor({configuration, request, response}) {
5
5
  if (!configuration) throw new Error("No configuration given")
6
6
  if (!request) throw new Error("No request given")
7
7
  if (!response) throw new Error("No response given")
8
8
 
9
9
  this.configuration = configuration
10
- this.params = {}
10
+ this.params = request.params()
11
11
  this.request = request
12
12
  this.response = response
13
13
  }
14
14
 
15
- resolve() {
15
+ async resolve() {
16
16
  let currentRoute = digg(this, "configuration", "routes", "rootRoute")
17
17
  let currentPath = this.request.path()
18
18
 
@@ -21,8 +21,9 @@ module.exports = class VelociousRoutesResolver {
21
21
  if (!matchResult) throw new Error(`Couldn't match a route with the given path: ${currentPath}`)
22
22
 
23
23
  if (this.params.action && this.params.controller) {
24
- const controllerPath = `${digg(this, "configuration", "directory")}/src/routes/${digg(this, "params", "controller")}/controller.cjs`
25
- const controllerClass = require(controllerPath)
24
+ const controllerPath = `${digg(this, "configuration", "directory")}/src/routes/${digg(this, "params", "controller")}/controller.mjs`
25
+ const controllerClassImport = await import(controllerPath)
26
+ const controllerClass = controllerClassImport.default
26
27
  const controllerInstance = new controllerClass({
27
28
  configuration: this.configuration,
28
29
  params: this.params,
@@ -30,7 +31,11 @@ module.exports = class VelociousRoutesResolver {
30
31
  response: this.response
31
32
  })
32
33
 
33
- controllerInstance[this.params.action]()
34
+ if (!(this.params.action in controllerInstance)) {
35
+ throw new Error(`Missing action on controller: ${this.params.controller}#${this.params.action}`)
36
+ }
37
+
38
+ await controllerInstance[this.params.action]()
34
39
 
35
40
  return
36
41
  }
@@ -44,7 +49,8 @@ module.exports = class VelociousRoutesResolver {
44
49
  for (const subRoute of route.routes) {
45
50
  const matchResult = subRoute.matchWithPath({
46
51
  params: this.params,
47
- path: pathWithoutSlash
52
+ path: pathWithoutSlash,
53
+ request: this.request
48
54
  })
49
55
 
50
56
  if (!matchResult) continue
@@ -1,14 +1,16 @@
1
- const BaseRoute = require("./base-route.cjs")
2
- const escapeStringRegexp = require("escape-string-regexp")
1
+ import BaseRoute, {initBaseRoute} from "./base-route.mjs"
2
+ import escapeStringRegexp from "escape-string-regexp"
3
3
 
4
- module.exports = class VelociousRouteResourceRoute extends BaseRoute {
4
+ initBaseRoute()
5
+
6
+ export default class VelociousRouteResourceRoute extends BaseRoute {
5
7
  constructor({name}) {
6
8
  super()
7
9
  this.name = name
8
10
  this.regExp = new RegExp(`^(${escapeStringRegexp(name)})(.*)$`)
9
11
  }
10
12
 
11
- matchWithPath({params, path}) {
13
+ matchWithPath({params, path, request}) {
12
14
  const match = path.match(this.regExp)
13
15
 
14
16
  if (match) {
@@ -24,7 +26,9 @@ module.exports = class VelociousRouteResourceRoute extends BaseRoute {
24
26
  }
25
27
 
26
28
  if (!subRoutesMatchesRestPath) {
27
- if (restPath.match(/\/(.+)/)) {
29
+ if (request.httpMethod() == "POST") {
30
+ action = "create"
31
+ } else if (restPath.match(/\/(.+)/)) {
28
32
  // TODO: This should change the action to "show" and set the "resource_name_id" in params.
29
33
  action = "show"
30
34
  }
@@ -0,0 +1,6 @@
1
+ import BaseRoute, {initBaseRoute} from "./base-route.mjs"
2
+
3
+ initBaseRoute()
4
+
5
+ export default class VelociousRootRoute extends BaseRoute {
6
+ }
package/bin/velocious DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/node
2
-
3
- console.log("Hello", process.argv)
4
-
5
- const args = process.argv.slice(2)
6
-
7
- console.log(args)
8
-
9
- if (args[0] == "g" && args[1] == "migration") {
10
- const migrationName = args[2]
11
- const date = new Date()
12
-
13
- console.log({ migrationName, date })
14
- }
package/index.cjs DELETED
@@ -1,11 +0,0 @@
1
- const Application = require("./src/application.cjs")
2
- const Controller = require("./src/controller.cjs")
3
- const Database = require("./src/database/index.cjs")
4
- const HttpServer = require("./src/http-server/index.cjs")
5
-
6
- module.exports = {
7
- Application,
8
- Controller,
9
- Database,
10
- HttpServer
11
- }
@@ -1,10 +0,0 @@
1
- {
2
- "default": {
3
- "master": {
4
- "type": "mysql",
5
- "host": "mysql",
6
- "username": "username",
7
- "password": "password"
8
- }
9
- }
10
- }
File without changes
@@ -1,11 +0,0 @@
1
- {
2
- "default": {
3
- "master": {
4
- "type": "mysql",
5
- "host": "mysql",
6
- "username": "peakflow",
7
- "password": "password",
8
- "database": "velocious_test"
9
- }
10
- }
11
- }
@@ -1,40 +0,0 @@
1
- const {Application} = require("../../index.cjs")
2
-
3
- module.exports = class Dummy {
4
- static async run(callback) {
5
- const dummy = new Dummy()
6
-
7
- await dummy.run(callback)
8
- }
9
-
10
- async run(callback) {
11
- await this.start()
12
-
13
- try {
14
- await callback()
15
- } finally {
16
- this.stop()
17
- }
18
- }
19
-
20
- async start() {
21
- this.application = new Application({
22
- databases: {
23
- default: {
24
- host: "mysql",
25
- username: "user",
26
- password: ""
27
- }
28
- },
29
- debug: false,
30
- directory: __dirname,
31
- httpServer: {port: 3006}
32
- })
33
-
34
- await this.application.start()
35
- }
36
-
37
- stop() {
38
- this.application.stop()
39
- }
40
- }
@@ -1,4 +0,0 @@
1
- const Record = require("../../../../src/database/record/index.cjs")
2
-
3
- module.exports = class Task extends Record {
4
- }
@@ -1,18 +0,0 @@
1
- const Controller = require("../../../../../src/controller.cjs")
2
- const {digg} = require("diggerize")
3
- const Task = require("../../models/task.cjs")
4
-
5
- module.exports = class TasksController extends Controller {
6
- index() {
7
- this.viewParams.numbers = [1, 2, 3, 4, 5]
8
- this.render()
9
- }
10
-
11
- async show() {
12
- const taskId = digg(params, "id")
13
- const task = await Task.find(taskId)
14
-
15
- this.viewParams.task = task
16
- this.render()
17
- }
18
- }
@@ -1,36 +0,0 @@
1
- const {digs} = require("diggerize")
2
- const Configuration = require("./configuration.cjs")
3
- const logger = require("./logger.cjs")
4
- const HttpServer = require("./http-server/index.cjs")
5
-
6
- module.exports = class VelociousApplication {
7
- constructor({debug, directory, httpServer}) {
8
- this.configuration = new Configuration({debug, directory})
9
- this.httpServerConfiguration = httpServer ?? {}
10
- }
11
-
12
- async run(callback) {
13
- await this.start()
14
-
15
- try {
16
- await callback()
17
- } finally {
18
- this.stop()
19
- }
20
- }
21
-
22
- async start() {
23
- const {configuration, httpServerConfiguration} = digs(this, "configuration", "httpServerConfiguration")
24
- const port = httpServerConfiguration.port || 3006
25
-
26
- logger(this, `Starting server on port ${port}`)
27
-
28
- this.httpServer = new HttpServer({configuration, port})
29
-
30
- await this.httpServer.start()
31
- }
32
-
33
- stop() {
34
- this.httpServer.stop()
35
- }
36
- }
@@ -1,14 +0,0 @@
1
- const Routes = require("./routes/index.cjs")
2
-
3
- module.exports = class VelociousConfiguration {
4
- constructor({debug, directory}) {
5
- if (!directory) throw new Error("No directory given")
6
-
7
- // Every client need to make their own routes because they probably can't be shared across different worker threads
8
- const {routes} = require(`${directory}/src/routes.cjs`)
9
-
10
- this.debug = debug
11
- this.directory = directory
12
- this.routes = routes
13
- }
14
- }
@@ -1,5 +0,0 @@
1
- module.exports = class VelociousDatabaseConnectionDriversMysql {
2
- constructor(args) {
3
- this.args = args
4
- }
5
- }
@@ -1,7 +0,0 @@
1
- const QueryParserOptions = require("../../../query-parser/options.cjs")
2
- const queryParserOptions = new QueryParserOptions({
3
- columnQuote: "`",
4
- tableQuote: "`"
5
- })
6
-
7
- module.exports = queryParserOptions
@@ -1,26 +0,0 @@
1
- const {digs} = require("diggerize")
2
- const FromParser = require("../../../query-parser/from-parser.cjs")
3
- const JoinsParser = require("../../../query-parser/joins-parser.cjs")
4
- const queryParserOptions = require("./options.cjs")
5
- const SelectParser = require("../../../query-parser/select-parser.cjs")
6
-
7
- module.exports = class VelociousDatabaseConnectionDriversMysqlQueryParser {
8
- constructor({pretty, query}) {
9
- if (!query) throw new Error("No query given")
10
-
11
- this.pretty = pretty
12
- this.query = query
13
- }
14
-
15
- toSql() {
16
- const {pretty, query} = digs(this, "pretty", "query")
17
-
18
- let sql = ""
19
-
20
- sql += new SelectParser({pretty, query, queryParserOptions}).toSql()
21
- sql += new FromParser({pretty, query, queryParserOptions}).toSql()
22
- sql += new JoinsParser({pretty, query, queryParserOptions}).toSql()
23
-
24
- return sql
25
- }
26
- }
@@ -1,2 +0,0 @@
1
- module.exports = class VelociousDatabaseConnection {
2
- }
@@ -1,5 +0,0 @@
1
- module.exports = class VelociousDatabaseHandler {
2
- constructor() {
3
- console.log("stub")
4
- }
5
- }
@@ -1,9 +0,0 @@
1
- const Handler = require("./handler.cjs")
2
- const Query = require("./query/index.cjs")
3
- const Record = require("./record/index.cjs")
4
-
5
- module.exports = {
6
- Handler,
7
- Query,
8
- Record
9
- }
@@ -1,2 +0,0 @@
1
- module.exports = class VelociousDatabasePool {
2
- }
@@ -1,15 +0,0 @@
1
- module.exports = class VelociousDatabaseQueryFromBase {
2
- getOptions() {
3
- if (!this._options) throw new Error("Options hasn't been set")
4
-
5
- return this._options
6
- }
7
-
8
- setOptions(options) {
9
- this._options = options
10
- }
11
-
12
- toSql() {
13
- throw new Error("'toSql' wasn't implemented")
14
- }
15
- }
@@ -1,12 +0,0 @@
1
- const FromBase = require("./from-base.cjs")
2
-
3
- module.exports = class VelociousDatabaseQueryFromPlain extends FromBase {
4
- constructor({plain}) {
5
- super()
6
- this.plain = plain
7
- }
8
-
9
- toSql() {
10
- return this.plain
11
- }
12
- }
@@ -1,59 +0,0 @@
1
- const FromPlain = require("./from-plain.cjs")
2
- const JoinPlain = require("./join-plain.cjs")
3
- const SelectPlain = require("./select-plain.cjs")
4
-
5
- module.exports = class VelociousDatabaseQuery {
6
- constructor({handler}) {
7
- if (!handler) throw new Error("No handler given")
8
-
9
- this._froms = []
10
- this._joins = []
11
- this._orders = []
12
- this._selects = []
13
- }
14
-
15
- getOptions() {
16
- if (!this._options) throw new Error("Options not set")
17
- return this._options
18
- }
19
-
20
- from(from) {
21
- if (typeof from == "string") from = new FromPlain({plain: from})
22
-
23
- this._froms.push(from)
24
- return this
25
- }
26
-
27
- joins(join) {
28
- if (typeof join == "string") join = new JoinPlain({plain: join})
29
-
30
- this._joins.push(join)
31
- return this
32
- }
33
-
34
- order(order) {
35
- if (typeof order == "string") order = new OrderPlain({plain: order})
36
-
37
- this._orders.push(order)
38
- return this
39
- }
40
-
41
- select(select) {
42
- if (Array.isArray(select)) {
43
- for (const selectInArray of select) {
44
- this.select(selectInArray)
45
- }
46
-
47
- return this
48
- }
49
-
50
- if (typeof select == "string") select = new SelectPlain({plain: select})
51
-
52
- this._selects.push(select)
53
- return this
54
- }
55
-
56
- toSql() {
57
- throw new Error("stub")
58
- }
59
- }
@@ -1,15 +0,0 @@
1
- module.exports = class VelociousDatabaseQueryJoinBase {
2
- getOptions() {
3
- if (!this._options) throw new Error("Options hasn't been set")
4
-
5
- return this._options
6
- }
7
-
8
- setOptions(options) {
9
- this._options = options
10
- }
11
-
12
- toSql() {
13
- throw new Error("'toSql' wasn't implemented")
14
- }
15
- }
@@ -1,12 +0,0 @@
1
- const JoinBase = require("./join-base.cjs")
2
-
3
- module.exports = class VelociousDatabaseQueryJoinPlain extends JoinBase {
4
- constructor({plain}) {
5
- super()
6
- this.plain = plain
7
- }
8
-
9
- toSql() {
10
- return this.plain
11
- }
12
- }
@@ -1,15 +0,0 @@
1
- module.exports = class VelociousDatabaseQuerySelectBase {
2
- getOptions() {
3
- if (!this._options) throw new Error("Options hasn't been set")
4
-
5
- return this._options
6
- }
7
-
8
- setOptions(options) {
9
- this._options = options
10
- }
11
-
12
- toSql() {
13
- throw new Error("'toSql' wasn't implemented")
14
- }
15
- }
@@ -1,12 +0,0 @@
1
- const SelectBase = require("./select-base.cjs")
2
-
3
- module.exports = class VelociousDatabaseQuerySelectPlain extends SelectBase {
4
- constructor({plain}) {
5
- super()
6
- this.plain = plain
7
- }
8
-
9
- toSql() {
10
- return this.plain
11
- }
12
- }
@@ -1,5 +0,0 @@
1
- module.exports = class VelociousDatabaseRecord {
2
- static find(recordId) {
3
- throw new Error("stub")
4
- }
5
- }
@@ -1,92 +0,0 @@
1
- const {EventEmitter} = require("events")
2
- const logger = require("../../logger.cjs")
3
-
4
- module.exports = class VelociousHttpServerClientRequestParser {
5
- constructor({configuration}) {
6
- if (!configuration) throw new Error("No configuration given")
7
-
8
- this.configuration = configuration
9
- this.data = []
10
- this.events = new EventEmitter()
11
- this.headers = []
12
- this.headersByName = {}
13
- this.state = "status"
14
- }
15
-
16
- addHeader(name, value) {
17
- logger(this, "addHeader", {name, value})
18
-
19
- this.headers.push({name, value})
20
-
21
- const formattedName = name.toLowerCase().trim()
22
-
23
- this.headersByName[formattedName] = value
24
- }
25
-
26
- feed(data) {
27
- if (this.state == "status" || this.state == "headers") {
28
- for (const char of data) {
29
- this.data.push(char)
30
-
31
- if (char == 10) {
32
- const line = String.fromCharCode.apply(null, this.data)
33
-
34
- this.data = []
35
- this.parse(line)
36
- }
37
- }
38
- }
39
- }
40
-
41
- matchAndRemove(regex) {
42
- const match = this.data.match(regex)
43
-
44
- if (!match) {
45
- return null
46
- }
47
-
48
- this.data = this.data.replace(regex, "")
49
-
50
- return match
51
- }
52
-
53
- parse(line) {
54
- if (this.state == "status") {
55
- this.parseStatusLine(line)
56
- } else if (this.state == "headers") {
57
- this.parseHeader(line)
58
- } else {
59
- throw new Error(`Unknown state: ${this.state}`)
60
- }
61
- }
62
-
63
- parseHeader(line) {
64
- let match
65
-
66
- if (match = line.match(/^(.+): (.+)\r\n/)) {
67
- const name = match[1]
68
- const value = match[2]
69
-
70
- this.addHeader(name, value)
71
- } else if (line == "\r\n") {
72
- if (this.httpMethod.toUpperCase() == "GET") {
73
- this.state = "done"
74
- this.events.emit("done")
75
- } else {
76
- throw new Error(`Unknown HTTP method: ${this.httpMethod}`)
77
- }
78
- }
79
- }
80
-
81
- parseStatusLine(line) {
82
- const match = line.match(/^(GET|POST) (.+?) HTTP\/1\.1\r\n/)
83
-
84
- if (!match) {
85
- throw new Error(`Couldn't match status line from: ${line}`)
86
- }
87
-
88
- this.httpMethod = match[1]
89
- this.path = match[2]
90
- this.state = "headers"
91
- }
92
- }
@@ -1,25 +0,0 @@
1
- const {digg} = require("diggerize")
2
- const RequestParser = require("./request-parser.cjs")
3
-
4
- module.exports = class VelociousHttpServerClientRequest {
5
- constructor({configuration}) {
6
- this.configuration = configuration
7
- this.requestParser = new RequestParser({configuration})
8
- }
9
-
10
- feed(data) {
11
- this.requestParser.feed(data)
12
- }
13
-
14
- httpMethod() {
15
- return digg(this, "requestParser", "httpMethod")
16
- }
17
-
18
- host() {
19
- return digg(this, "requestParser", "headersByName", "host")
20
- }
21
-
22
- path() {
23
- return digg(this, "requestParser", "path")
24
- }
25
- }