webhoster 0.3.3 → 0.3.5

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 (157) hide show
  1. package/README.md +4 -4
  2. package/data/CookieObject.js +1 -1
  3. package/{types/index.js → data/custom-types.js} +1 -1
  4. package/{types/typings.d.ts → data/middleware.d.ts} +1 -1
  5. package/helpers/RequestReader.js +1 -1
  6. package/helpers/ResponseHeaders.js +9 -10
  7. package/lib/HttpHandler.js +4 -4
  8. package/lib/HttpRequest.js +2 -2
  9. package/lib/HttpResponse.js +2 -2
  10. package/lib/HttpTransaction.js +2 -2
  11. package/middleware/AutoHeadersMiddleware.js +2 -2
  12. package/middleware/CORSMiddleware.js +3 -3
  13. package/middleware/CaseInsensitiveHeadersMiddleware.js +2 -2
  14. package/middleware/ContentDecoderMiddleware.js +1 -1
  15. package/middleware/ContentEncoderMiddleware.js +2 -2
  16. package/middleware/ContentLengthMiddleware.js +2 -2
  17. package/middleware/HashMiddleware.js +2 -2
  18. package/middleware/HeadMethodMiddleware.js +3 -3
  19. package/middleware/MethodMiddleware.js +3 -3
  20. package/middleware/PathMiddleware.js +4 -4
  21. package/middleware/ReadFormData.js +1 -1
  22. package/middleware/SendJsonMiddleware.js +4 -4
  23. package/middleware/SendStringMiddleware.js +3 -3
  24. package/package.json +21 -4
  25. package/templates/starter.js +2 -2
  26. package/types/data/CookieObject.d.ts +34 -0
  27. package/types/data/CookieObject.d.ts.map +1 -0
  28. package/types/data/custom-types.d.ts +111 -0
  29. package/types/data/custom-types.d.ts.map +1 -0
  30. package/types/errata/socketio.d.ts +11 -0
  31. package/types/errata/socketio.d.ts.map +1 -0
  32. package/types/examples/starter.d.ts +2 -0
  33. package/types/examples/starter.d.ts.map +1 -0
  34. package/types/helpers/HeadersParser.d.ts +27 -0
  35. package/types/helpers/HeadersParser.d.ts.map +1 -0
  36. package/types/helpers/HttpListener.d.ts +84 -0
  37. package/types/helpers/HttpListener.d.ts.map +1 -0
  38. package/types/helpers/RequestHeaders.d.ts +25 -0
  39. package/types/helpers/RequestHeaders.d.ts.map +1 -0
  40. package/types/helpers/RequestReader.d.ts +52 -0
  41. package/types/helpers/RequestReader.d.ts.map +1 -0
  42. package/types/helpers/ResponseHeaders.d.ts +126 -0
  43. package/types/helpers/ResponseHeaders.d.ts.map +1 -0
  44. package/types/helpers/index.d.ts +6 -0
  45. package/types/helpers/index.d.ts.map +1 -0
  46. package/types/lib/HttpHandler.d.ts +79 -0
  47. package/types/lib/HttpHandler.d.ts.map +1 -0
  48. package/types/lib/HttpRequest.d.ts +175 -0
  49. package/types/lib/HttpRequest.d.ts.map +1 -0
  50. package/types/lib/HttpResponse.d.ts +117 -0
  51. package/types/lib/HttpResponse.d.ts.map +1 -0
  52. package/types/lib/HttpTransaction.d.ts +114 -0
  53. package/types/lib/HttpTransaction.d.ts.map +1 -0
  54. package/types/middleware/AutoHeadersMiddleware.d.ts +27 -0
  55. package/types/middleware/AutoHeadersMiddleware.d.ts.map +1 -0
  56. package/types/middleware/CORSMiddleware.d.ts +65 -0
  57. package/types/middleware/CORSMiddleware.d.ts.map +1 -0
  58. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts +27 -0
  59. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts.map +1 -0
  60. package/types/middleware/ContentDecoderMiddleware.d.ts +17 -0
  61. package/types/middleware/ContentDecoderMiddleware.d.ts.map +1 -0
  62. package/types/middleware/ContentEncoderMiddleware.d.ts +48 -0
  63. package/types/middleware/ContentEncoderMiddleware.d.ts.map +1 -0
  64. package/types/middleware/ContentLengthMiddleware.d.ts +38 -0
  65. package/types/middleware/ContentLengthMiddleware.d.ts.map +1 -0
  66. package/types/middleware/HashMiddleware.d.ts +28 -0
  67. package/types/middleware/HashMiddleware.d.ts.map +1 -0
  68. package/types/middleware/HeadMethodMiddleware.d.ts +12 -0
  69. package/types/middleware/HeadMethodMiddleware.d.ts.map +1 -0
  70. package/types/middleware/MethodMiddleware.d.ts +40 -0
  71. package/types/middleware/MethodMiddleware.d.ts.map +1 -0
  72. package/types/middleware/PathMiddleware.d.ts +81 -0
  73. package/types/middleware/PathMiddleware.d.ts.map +1 -0
  74. package/types/middleware/ReadFormData.d.ts +7 -0
  75. package/types/middleware/ReadFormData.d.ts.map +1 -0
  76. package/types/middleware/SendJsonMiddleware.d.ts +51 -0
  77. package/types/middleware/SendJsonMiddleware.d.ts.map +1 -0
  78. package/types/middleware/SendStringMiddleware.d.ts +35 -0
  79. package/types/middleware/SendStringMiddleware.d.ts.map +1 -0
  80. package/types/templates/starter.d.ts +15 -0
  81. package/types/templates/starter.d.ts.map +1 -0
  82. package/types/utils/AsyncObject.d.ts +38 -0
  83. package/types/utils/AsyncObject.d.ts.map +1 -0
  84. package/types/utils/CaseInsensitiveObject.d.ts +9 -0
  85. package/types/utils/CaseInsensitiveObject.d.ts.map +1 -0
  86. package/types/utils/function.d.ts +2 -0
  87. package/types/utils/function.d.ts.map +1 -0
  88. package/types/utils/headers.d.ts +7 -0
  89. package/types/utils/headers.d.ts.map +1 -0
  90. package/types/utils/qualityValues.d.ts +12 -0
  91. package/types/utils/qualityValues.d.ts.map +1 -0
  92. package/types/utils/stream.d.ts +6 -0
  93. package/types/utils/stream.d.ts.map +1 -0
  94. package/utils/headers.js +1 -1
  95. package/.eslintrc.json +0 -96
  96. package/.github/FUNDING.yml +0 -4
  97. package/.github/copilot-instructions.md +0 -100
  98. package/.github/workflows/publish.yml +0 -29
  99. package/.github/workflows/test-matrix.yml +0 -37
  100. package/.test/benchmark.js +0 -28
  101. package/.test/constants.js +0 -4
  102. package/.test/cookietester.js +0 -19
  103. package/.test/http2server.js +0 -35
  104. package/.test/httpserver.js +0 -32
  105. package/.test/index.js +0 -498
  106. package/.test/multipromise.js +0 -32
  107. package/.test/tls.js +0 -75
  108. package/.test/urlencoded.js +0 -54
  109. package/.vscode/launch.json +0 -35
  110. package/.vscode/settings.json +0 -5
  111. package/CHANGELOG.md +0 -10
  112. package/CODE_OF_CONDUCT.md +0 -76
  113. package/errata/index.js +0 -1
  114. package/examples/starter.js +0 -11
  115. package/index.js +0 -4
  116. package/jsconfig.json +0 -12
  117. package/lib/index.js +0 -3
  118. package/middleware/ContentReaderMiddleware.js +0 -249
  119. package/middleware/ContentWriterMiddleware.js +0 -161
  120. package/middleware/SendHeadersMiddleware.js +0 -47
  121. package/middleware/index.js +0 -11
  122. package/polyfill/FormData.js +0 -164
  123. package/rollup.config.js +0 -8
  124. package/scripts/check-teapot.mjs +0 -40
  125. package/scripts/test-all-sync.sh +0 -6
  126. package/scripts/test-all.sh +0 -7
  127. package/test/fixtures/stream.js +0 -68
  128. package/test/helpers/HttpListener/construct.js +0 -18
  129. package/test/helpers/HttpListener/customOptions.js +0 -22
  130. package/test/helpers/HttpListener/doubleCreate.js +0 -40
  131. package/test/helpers/HttpListener/events.js +0 -77
  132. package/test/helpers/HttpListener/http.js +0 -31
  133. package/test/helpers/HttpListener/http2.js +0 -41
  134. package/test/helpers/HttpListener/https.js +0 -38
  135. package/test/helpers/HttpListener/startAll.js +0 -31
  136. package/test/helpers/HttpListener/stopNotStarted.js +0 -23
  137. package/test/lib/HttpHandler/class.js +0 -8
  138. package/test/lib/HttpHandler/handleRequest.js +0 -11
  139. package/test/lib/HttpHandler/middleware.js +0 -941
  140. package/test/lib/HttpHandler/parse.js +0 -41
  141. package/test/lib/HttpRequest/class.js +0 -8
  142. package/test/lib/HttpRequest/downstream.js +0 -171
  143. package/test/lib/HttpRequest/properties.js +0 -101
  144. package/test/lib/HttpRequest/read.js +0 -518
  145. package/test/lib/HttpResponse/async-iterable-middleware.js +0 -37
  146. package/test/lib/HttpResponse/async-iterable.js +0 -31
  147. package/test/lib/HttpResponse/class.js +0 -8
  148. package/test/lib/HttpResponse/properties.js +0 -59
  149. package/test/lib/HttpResponse/send.js +0 -275
  150. package/test/lib/HttpTransaction/class.js +0 -8
  151. package/test/lib/HttpTransaction/ping.js +0 -50
  152. package/test/lib/HttpTransaction/push.js +0 -89
  153. package/test/middleware/SendJsonMiddleware.js +0 -222
  154. package/test/sanity.js +0 -10
  155. package/test/templates/error-teapot.js +0 -47
  156. package/test/templates/starter.js +0 -93
  157. package/tsconfig.json +0 -30
package/README.md CHANGED
@@ -39,7 +39,7 @@ For now, take a look at [/test/index.js](/test/index.js)
39
39
  * `.defaultInstance` - (`HttpHandler`) - Returns a instance of `HttpHandler` that can be accessed staticly.
40
40
  * `.middleware` - (`Middleware[]`) - An array of middleware operations to iterate through when handling a request. It is recommended to create isolated branches (eg: `/images/`; `/api/`; `/views/`; etc.).
41
41
  * `.errorHandlers` - (`MiddlewareErrorHandler[]`) - An array of `MiddlewareErrorHandler` that will handle errors and respond appropriately (eg: `res.status = 500`)
42
- * `.handleRequest` - (`function(MiddlewareFunctionParams):Promise<HttpResponse>`) - handles logic for calling middleware and error handlers. Unlikely to be used directly.
42
+ * `.handleRequest` - (`function(HttpTransaction):Promise<HttpResponse>`) - handles logic for calling middleware and error handlers. Unlikely to be used directly.
43
43
  * `.handleHttp1Request` - (`function(IncomingMessage, ServerResponse):Promise<HttpResponse>`) - constructs a new `HttpRequest` and `HttpResponse` based on the HTTP1 parameters and passes it to `handleRequest`
44
44
  * `.handleHttp2Stream` - (`function(ServerHttp2Stream, IncomingHttpHeaders, HttpResponseOptions):Promise<HttpResponse>`) - constructs a new `HttpRequest` and `HttpResponse` based on the HTTP2 parameters and passes it to `handleRequest`
45
45
 
@@ -141,7 +141,7 @@ async function onGetIndexPage(transaction) {
141
141
 
142
142
  Middleware logic flows in a tree structure, allowing for `continue`, `break`, or `end`.
143
143
 
144
- A `MiddlewareFunction` is a function that accepts a `MiddlewareFunctionParams` object structured as `{ res: HttpRequest, res: HttpResponse }`. The function can return a instruction with the step in the tree-based logic, status code, or content body to be handled. It maybe return any of these instructions with any of the values as a literal, a `Promise`, or `PromiseLike`:
144
+ A `MiddlewareFunction` is a function that accepts a `HttpTransaction` object structured as `{ res: HttpRequest, res: HttpResponse }`. The function can return a instruction with the step in the tree-based logic, status code, or content body to be handled. It maybe return any of these instructions with any of the values as a literal, a `Promise`, or `PromiseLike`:
145
145
 
146
146
  * `HttpHandler.CONTINUE`: Continues on the current branch to the next middleware, or moves to the next branch if there are no siblings left. `alias: true|void|null|undefined`
147
147
  * `HttpHandler.BREAK`: Breaks from the current middleware branch, and continues to the next branch. `alias: false`
@@ -151,7 +151,7 @@ A `MiddlewareFunction` is a function that accepts a `MiddlewareFunctionParams` o
151
151
  * `Array`: Explicitly passed to `HttpResponse.end()`. This is to support sending an `Array` object instead having it becoming an inline middleware branch.
152
152
  * `any`: Any other value returned would automatically be passed to `HttpResponse.end()` which, in turn, uses it's own content handlers (eg: `JSON`; `Readable`), and finally terminates the middleware tree.
153
153
 
154
- A `MiddlewareFilter` is a function that accepts a `MiddlewareFunctionParams` and returns a `boolean` or `Promise<boolean>` signaling whether to continue in the branch. `true` translates to `HttpHandler.CONTINUE`. `false` translates to `HttpHandler.BREAK`. There is no support for `HttpHandler.END` logic in a MiddlewareFilter by design.
154
+ A `MiddlewareFilter` is a function that accepts a `HttpTransaction` and returns a `boolean` or `Promise<boolean>` signaling whether to continue in the branch. `true` translates to `HttpHandler.CONTINUE`. `false` translates to `HttpHandler.BREAK`. There is no support for `HttpHandler.END` logic in a MiddlewareFilter by design.
155
155
 
156
156
  A `MiddlewareErrorHandler` is an `Object` with a `onError` property. `onError` is like a MiddlewareFunction, but includes an `err` item in its parameter object. When the handler is in an error state, it will bubble upwards while searching for the next `MiddlewareErrorHandler`.
157
157
 
@@ -163,7 +163,7 @@ To support branching, `Middleware` can also be a `Iterable<Middleware>` (eg: `Se
163
163
 
164
164
  ### Response Middleware
165
165
  * [AuthHeaders](./middleware/AutoHeadersMiddleware.js) - Automatically sends response headers before writing or ending a response stream
166
- * [ContentLength](./middleware/contentLengthMiddleware.js) - Sets `Content-Length` based on response stream content writes
166
+ * [ContentLength](./middleware/ContentLengthMiddleware.js) - Sets `Content-Length` based on response stream content writes
167
167
  * [Hash](./middleware/HashMiddleware.js) - Sets `ETag`, `Digest`, and `Content-MD5` response headers automatically
168
168
  * [ContentEncoder](./middleware/ContentEncoderMiddleware.js) - Applies `Content-Encoding` to response based on `Accept-Encoding` request header
169
169
  * [SendJson](./middleware/SendJsonMiddleware.js) - Adds response content processor that encodes objects and arrays to JSON string. Sets `application/json;charset=utf-8`, if content-type not set.
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../types').CookieDetails} CookieDetails */
1
+ /** @typedef {import('./custom-types.js').CookieDetails} CookieDetails */
2
2
 
3
3
  /** @private */
4
4
  export default class CookieObject {
@@ -16,7 +16,7 @@
16
16
 
17
17
  /** @typedef {import('node:stream').Duplex} Duplex */
18
18
 
19
- /** @typedef {import('./typings.js').Middleware} Middleware */
19
+ /** @typedef {import('./middleware.js').Middleware} Middleware */
20
20
 
21
21
  /** @typedef {true|false|0} MiddlewareFlowInstruction */
22
22
 
@@ -3,7 +3,7 @@ import {
3
3
  MiddlewareContent,
4
4
  MiddlewareFunction,
5
5
  MiddlewareFunctionResultType,
6
- } from './index.js';
6
+ } from './custom-types.js';
7
7
 
8
8
  export type Middleware =
9
9
  | IMiddleware
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../types').HttpRequest} HttpRequest */
1
+ /** @typedef {import('../data/custom-types.js').HttpRequest} HttpRequest */
2
2
 
3
3
  import { TextDecoder } from 'node:util';
4
4
  import AsyncObject from '../utils/AsyncObject.js';
@@ -3,7 +3,7 @@ import CookieObject from '../data/CookieObject.js';
3
3
  import HeadersHandler from './HeadersParser.js';
4
4
 
5
5
  /** @typedef {import('../lib/HttpResponse.js').default} HttpResponse */
6
- /** @typedef {import('../types').CookieDetails} CookieDetails */
6
+ /** @typedef {import('../data/custom-types.js').CookieDetails} CookieDetails */
7
7
 
8
8
  /** @type {(keyof CookieDetails)[]} */
9
9
  const COOKIE_DETAIL_KEYS = [
@@ -22,18 +22,17 @@ const COOKIE_DETAIL_KEYS = [
22
22
  const instanceCache = new WeakMap();
23
23
 
24
24
  export default class ResponseHeaders extends HeadersHandler {
25
- /** @param {HttpResponse} res */
26
- // @ts-ignore Cached constructor
27
- constructor(res) {
28
- const instance = instanceCache.get(res);
25
+ /** @param {HttpResponse} response */
26
+ constructor(response) {
27
+ const instance = instanceCache.get(response);
29
28
  if (instance) return instance;
30
- super(res.headers);
31
- instanceCache.set(res, this);
29
+ super(response.headers);
30
+ instanceCache.set(response, this);
32
31
  }
33
32
 
34
- /** @param {HttpResponse} res */
35
- static cookies(res) {
36
- const instance = new ResponseHeaders(res);
33
+ /** @param {HttpResponse} response */
34
+ static cookies(response) {
35
+ const instance = new ResponseHeaders(response);
37
36
  return instance.cookies;
38
37
  }
39
38
 
@@ -7,10 +7,10 @@ import HttpRequest from './HttpRequest.js';
7
7
  import HttpResponse from './HttpResponse.js';
8
8
  import HttpTransaction from './HttpTransaction.js';
9
9
 
10
- /** @typedef {import('../types').Middleware} Middleware */
11
- /** @typedef {import('../types').MiddlewareErrorHandler} MiddlewareErrorHandler */
12
- /** @typedef {import('../types').MiddlewareFlowInstruction} MiddlewareFlowInstruction */
13
- /** @typedef {import('../types').RequestMethod} RequestMethod */
10
+ /** @typedef {import('../data/custom-types.js').Middleware} Middleware */
11
+ /** @typedef {import('../data/custom-types.js').MiddlewareErrorHandler} MiddlewareErrorHandler */
12
+ /** @typedef {import('../data/custom-types.js').MiddlewareFlowInstruction} MiddlewareFlowInstruction */
13
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
14
14
 
15
15
  /** @type {HttpHandler} */
16
16
  let defaultInstance = null;
@@ -1,9 +1,9 @@
1
1
  import { Readable } from 'node:stream';
2
2
  import { URLSearchParams } from 'node:url';
3
3
 
4
- /** @typedef {import('../types').RequestMethod} RequestMethod */
4
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
5
5
  /** @typedef {import('http').IncomingHttpHeaders} IncomingHttpHeaders */
6
- /** @typedef {import('../types/index.js').MediaType} MediaType */
6
+ /** @typedef {import('../data/custom-types.js').MediaType} MediaType */
7
7
 
8
8
  /** @typedef {Partial<MediaType> & {parse:(this:HttpRequest)=>any|PromiseLike<any>, test?:(this:HttpRequest, mediaType: MediaType)=>boolean}} ContentReaderRegistration */
9
9
 
@@ -11,9 +11,9 @@ import { isWritable } from '../utils/stream.js';
11
11
 
12
12
  /** @typedef {import('http').OutgoingHttpHeaders} OutgoingHttpHeaders */
13
13
  /** @typedef {import('stream').Stream} Stream */
14
- /** @typedef {import('../types/index.js').Middleware} Middleware */
14
+ /** @typedef {import('../data/custom-types.js').Middleware} Middleware */
15
15
  /** @typedef {import('./HttpRequest.js').default} HttpRequest */
16
- /** @typedef {import('../types/index.js').ResponseFinalizer} ResponseFinalizer */
16
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
17
17
 
18
18
  /**
19
19
  * @typedef {Object} HttpResponseOptions
@@ -2,8 +2,8 @@
2
2
  /** @typedef {import('./HttpResponse.js').default} HttpResponse */
3
3
  /** @typedef {import('stream').Stream} Stream */
4
4
 
5
- /** @typedef {import('../types/index.js').MediaType} MediaType */
6
- /** @typedef {import('../types/index.js').Middleware} Middleware */
5
+ /** @typedef {import('../data/custom-types.js').MediaType} MediaType */
6
+ /** @typedef {import('../data/custom-types.js').Middleware} Middleware */
7
7
  /** @typedef {import('stream').Writable} Writable */
8
8
 
9
9
  /** @typedef {Partial<MediaType> & {parse:(this:HttpRequest)=>any|PromiseLike<any>, test?:(this:HttpRequest, mediaType: MediaType)=>boolean}} ContentReaderRegistration */
@@ -1,6 +1,6 @@
1
1
  /** @typedef {import('../lib/HttpResponse.js').default} HttpResponse */
2
- /** @typedef {import('../types').ResponseFinalizer} ResponseFinalizer */
3
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
2
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
3
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
4
4
 
5
5
  import { Transform } from 'node:stream';
6
6
 
@@ -1,6 +1,6 @@
1
- /** @typedef {import('../types').IMiddleware} IMiddleware */
2
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
3
- /** @typedef {import('../types').RequestMethod} RequestMethod */
1
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
4
4
 
5
5
  /**
6
6
  * @typedef CORSMiddlewareOptions
@@ -1,7 +1,7 @@
1
1
  import CaseInsensitiveObject from '../utils/CaseInsensitiveObject.js';
2
2
 
3
- /** @typedef {import('../types').IMiddleware} IMiddleware */
4
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
4
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
5
5
 
6
6
  /**
7
7
  * @typedef {Object} CaseInsensitiveHeadersMiddlewareOptions
@@ -4,7 +4,7 @@ import {
4
4
  BrotliDecompress, Gunzip, Inflate,
5
5
  } from 'node:zlib';
6
6
 
7
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
7
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
8
8
 
9
9
  /**
10
10
  * @typedef ContentDecoderMiddlewareOptions
@@ -15,8 +15,8 @@ const { BROTLI_OPERATION_FLUSH, Z_SYNC_FLUSH } = ZlibContants;
15
15
  /** @typedef {import('http').IncomingHttpHeaders} IncomingHttpHeaders */
16
16
  /** @typedef {import('../lib/HttpRequest.js').default} HttpRequest */
17
17
  /** @typedef {import('../lib/HttpResponse.js').default} HttpResponse */
18
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
19
- /** @typedef {import('../types').ResponseFinalizer} ResponseFinalizer */
18
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
19
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
20
20
 
21
21
  /** @typedef {'br'|'gzip'|'deflate'|'identity'|'*'} COMPATIBLE_ENCODING */
22
22
 
@@ -1,6 +1,6 @@
1
1
  /** @typedef {import('../lib/HttpResponse.js').default} HttpResponse */
2
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
3
- /** @typedef {import('../types').ResponseFinalizer} ResponseFinalizer */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
4
4
 
5
5
  import { Transform } from 'node:stream';
6
6
 
@@ -4,8 +4,8 @@ import { Transform } from 'node:stream';
4
4
  /** @typedef {import('node:crypto').BinaryToTextEncoding} BinaryToTextEncoding */
5
5
  /** @typedef {import('../lib/HttpRequest.js').default} HttpRequest */
6
6
  /** @typedef {import('../lib/HttpResponse.js').default} HttpResponse */
7
- /** @typedef {import('../types/index.js').MiddlewareFunction} MiddlewareFunction */
8
- /** @typedef {import('../types/index.js').ResponseFinalizer} ResponseFinalizer */
7
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
8
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
9
9
 
10
10
  const DEFAULT_ALGORITHM = 'sha1';
11
11
  /** @type {BinaryToTextEncoding} */
@@ -1,6 +1,6 @@
1
- /** @typedef {import('../types/index.js').HttpTransaction} HttpTransaction */
2
- /** @typedef {import('../types/index.js').MiddlewareFunction} MiddlewareFunction */
3
- /** @typedef {import('../types/index.js').ResponseFinalizer} ResponseFinalizer */
1
+ /** @typedef {import('../data/custom-types.js').HttpTransaction} HttpTransaction */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
4
4
 
5
5
  import { Transform } from 'node:stream';
6
6
 
@@ -1,6 +1,6 @@
1
- /** @typedef {import('../types').HttpTransaction} HttpTransaction */
2
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
3
- /** @typedef {import('../types').RequestMethod} RequestMethod */
1
+ /** @typedef {import('../data/custom-types.js').HttpTransaction} HttpTransaction */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
4
4
 
5
5
  /** @typedef {RegExp|RequestMethod} MethodEntry */
6
6
 
@@ -1,9 +1,9 @@
1
1
  import { posix } from 'node:path';
2
2
 
3
- /** @typedef {import('../types').HttpTransaction} HttpTransaction */
4
- /** @typedef {import('../types').IMiddleware} IMiddleware */
5
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
6
- /** @typedef {import('../types').RequestMethod} RequestMethod */
3
+ /** @typedef {import('../data/custom-types.js').HttpTransaction} HttpTransaction */
4
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
5
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
6
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
7
7
 
8
8
  /** @typedef {RegExp|string} PathEntry */
9
9
 
@@ -1,5 +1,5 @@
1
1
  /** @typedef {import('../lib/HttpRequest.js').default} HttpRequest */
2
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
3
 
4
4
  /**
5
5
  * The application/x-www-form-urlencoded format is in many ways an aberrant monstrosity,
@@ -1,7 +1,7 @@
1
- /** @typedef {import('../types').IMiddleware} IMiddleware */
2
- /** @typedef {import('../types').MiddlewareResponseFunction} MiddlewareResponseFunction */
3
- /** @typedef {import('../types').MiddlewareFunction} MiddlewareFunction */
4
- /** @typedef {import('../types/index.js').ResponseFinalizer} ResponseFinalizer */
1
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareResponseFunction} MiddlewareResponseFunction */
3
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
4
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
5
5
 
6
6
  /**
7
7
  * @typedef {Object} SendJsonMiddlewareOptions
@@ -1,6 +1,6 @@
1
- /** @typedef {import('../types/index.js').IMiddleware} IMiddleware */
2
- /** @typedef {import('../types/index.js').MiddlewareFunction} MiddlewareFunction */
3
- /** @typedef {import('../types/index.js').ResponseFinalizer} ResponseFinalizer */
1
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
2
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
3
+ /** @typedef {import('../data/custom-types.js').ResponseFinalizer} ResponseFinalizer */
4
4
 
5
5
  /**
6
6
  * @typedef {Object} SendStringMiddlewareOptions
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "./examples/*": "./examples/*",
30
30
  "./helpers/*": "./helpers/*",
31
31
  "./lib/*": "./lib/*",
32
- "./middlewares/*": "./middlewares/*",
32
+ "./middleware/*": "./middleware/*",
33
33
  "./polyfills/*": "./polyfills/*",
34
34
  "./templates/*": "./templates/*",
35
35
  "./types/*": "./types/*",
@@ -46,12 +46,23 @@
46
46
  "cors",
47
47
  "gzip"
48
48
  ],
49
+ "files": [
50
+ "data",
51
+ "errata",
52
+ "helpers",
53
+ "lib",
54
+ "middleware",
55
+ "polyfills",
56
+ "templates",
57
+ "types",
58
+ "utils"
59
+ ],
49
60
  "license": "MIT",
50
61
  "name": "webhoster",
51
62
  "scripts": {
52
63
  "debug-test": "ava --serial",
53
64
  "test": "c8 ava",
54
- "prepublishOnly": "rm -Rf typings && tsc --emitDeclarationOnly",
65
+ "prepublishOnly": "rm -Rf types && tsc --emitDeclarationOnly",
55
66
  "pretestallsync": "rimraf coverage",
56
67
  "testallsync": "scripts/test-all-sync.sh",
57
68
  "posttestallsync": "c8 report",
@@ -60,6 +71,12 @@
60
71
  "posttestall": "c8 report"
61
72
  },
62
73
  "type": "module",
63
- "types": "typings/index.d.ts",
64
- "version": "0.3.3"
74
+ "typesVersions": {
75
+ "*": {
76
+ "*": [
77
+ "types/*"
78
+ ]
79
+ }
80
+ },
81
+ "version": "0.3.5"
65
82
  }
@@ -13,8 +13,8 @@ import HeadMethodMiddleware from '../middleware/HeadMethodMiddleware.js';
13
13
  * @param {Object} options
14
14
  * @param {string} [options.host='0.0.0.0']
15
15
  * @param {number} [options.port=8080]
16
- * @param {import('../types').Middleware[]} [options.middleware]
17
- * @param {import('../types').MiddlewareErrorHandler[]} [options.errorHandlers]
16
+ * @param {import('../data/custom-types.js').Middleware[]} [options.middleware]
17
+ * @param {import('../data/custom-types.js').MiddlewareErrorHandler[]} [options.errorHandlers]
18
18
  * @return {Promise<import('../helpers/HttpListener.js').default>}
19
19
  */
20
20
  export async function start(options) {
@@ -0,0 +1,34 @@
1
+ /** @typedef {import('./custom-types.js').CookieDetails} CookieDetails */
2
+ /** @private */
3
+ export default class CookieObject {
4
+ /**
5
+ * @param {string} cookieString
6
+ * @return {CookieObject}
7
+ */
8
+ static parse(cookieString: string): CookieObject;
9
+ /** @param {CookieDetails|string} options */
10
+ constructor(options: CookieDetails | string);
11
+ name: string;
12
+ value: string;
13
+ expires: Date;
14
+ maxAge: number;
15
+ domain: string;
16
+ path: string;
17
+ secure: boolean;
18
+ httpOnly: boolean;
19
+ sameSite: "Strict" | "Lax" | "None";
20
+ toString(): string;
21
+ toJSON(): {
22
+ name: string;
23
+ value: string;
24
+ expires: Date;
25
+ maxAge: number;
26
+ domain: string;
27
+ path: string;
28
+ secure: true;
29
+ httpOnly: true;
30
+ sameSite: "Strict" | "Lax" | "None";
31
+ };
32
+ }
33
+ export type CookieDetails = import("./custom-types.js").CookieDetails;
34
+ //# sourceMappingURL=CookieObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieObject.d.ts","sourceRoot":"","sources":["../../data/CookieObject.js"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,eAAe;AACf;IAiBE;;;OAGG;IACH,2BAHW,MAAM,GACL,YAAY,CAuDvB;IAzED,4CAA4C;IAC5C,qBADY,aAAa,GAAC,MAAM,EAc/B;IATC,aAAwB;IACxB,cAA0B;IAC1B,cAA8B;IAC9B,eAA4B;IAC5B,eAA4B;IAC5B,aAAwB;IACxB,gBAA4B;IAC5B,kBAAgC;IAChC,oCAAgC;IA8DlC,mBAUC;IAED;;;;;;;;;;MAYC;CACF;4BAxGa,OAAO,mBAAmB,EAAE,aAAa"}
@@ -0,0 +1,111 @@
1
+ declare const _default: {};
2
+ export default _default;
3
+ /**
4
+ * <T>
5
+ */
6
+ export type HttpTransaction<T extends unknown = any> = import("../lib/HttpTransaction.js").default<T>;
7
+ export type HttpRequest = import("../lib/HttpRequest.js").default;
8
+ export type HttpResponse = import("../lib/HttpResponse.js").default;
9
+ export type MediaType = {
10
+ type: string;
11
+ tree: string;
12
+ subtype: string;
13
+ suffix: string;
14
+ parameters: Record<string, string>;
15
+ };
16
+ export type Duplex = import("node:stream").Duplex;
17
+ export type Middleware = import("./middleware.js").Middleware;
18
+ export type MiddlewareFlowInstruction = true | false | 0;
19
+ export type RequestMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
20
+ export type MiddlewareFunctionResultType = 0 | true | false | null | undefined | void;
21
+ export type MiddlewareFunctionResult = Promise<Middleware> | Middleware;
22
+ export type MiddlewareContent = Record<string, any> | number | import("stream").Readable | Buffer | string;
23
+ export type MiddlewareFunction<T extends unknown = any> = (transaction: HttpTransaction<T>) => MiddlewareFunctionResult;
24
+ export type MiddlewareResponseFunction<T extends unknown = any> = (transaction: {
25
+ response: HttpTransaction<T>["response"];
26
+ }) => MiddlewareFunctionResult;
27
+ export type StaticMiddlewareFunction = (transaction: HttpTransaction) => MiddlewareFunctionResult;
28
+ export type ResponseFinalizer = (response: HttpResponse) => void | null | boolean | Promise<void | null | boolean>;
29
+ export type MiddlewareExecutor = {
30
+ execute: MiddlewareFunction;
31
+ };
32
+ export type MiddlewareStaticExecutor = {
33
+ Execute: StaticMiddlewareFunction;
34
+ };
35
+ export type MiddlewareStaticErrorHandler = {
36
+ OnError: StaticMiddlewareFunction;
37
+ };
38
+ export type MiddlewareErrorHandler = {
39
+ onError: MiddlewareFunction;
40
+ };
41
+ export type IMiddleware = MiddlewareExecutor | MiddlewareStaticExecutor | MiddlewareErrorHandler | MiddlewareStaticErrorHandler | MiddlewareStaticExecutor;
42
+ export type CookieDetails = {
43
+ /**
44
+ * A cookie name can be any US-ASCII characters, except control characters, spaces, or tabs.
45
+ * It also must not contain a separator character like the following:( ) < > &#64; , ; : \ " / [ ] ? = { }.
46
+ * - __Secure- prefix: Cookies names starting with __Secure- (dash is part of the prefix) must be set with the secure flag from a secure page (HTTPS).
47
+ * - __Host- prefix: Cookies with names starting with __Host- must be set with the secure flag, must be from a secure page (HTTPS), must not have a domain specified (and therefore aren't sent to subdomains) and the path must be /.
48
+ */
49
+ name?: string;
50
+ /**
51
+ * A cookie value can optionally be wrapped in double quotes and include any US-ASCII characters excluding
52
+ * control characters, Whitespace, double quotes, comma, semicolon, and backslash.
53
+ *
54
+ * Encoding: Many implementations perform URL encoding on cookie values,
55
+ * however it is not required per the RFC specification.
56
+ * It does help satisfying the requirements about which characters are allowed for cookie value though.
57
+ */
58
+ value?: string;
59
+ /**
60
+ * The maximum lifetime of the cookie as an HTTP-date timestamp.
61
+ *
62
+ * If unspecified, the cookie becomes a session cookie.
63
+ * A session finishes when the client shuts down, and session cookies will be removed.
64
+ */
65
+ expires?: Date;
66
+ /**
67
+ * Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately.
68
+ * If both Expires and Max-Age are set, Max-Age has precedence.
69
+ */
70
+ maxAge?: number;
71
+ /**
72
+ * Host to which the cookie will be sent.
73
+ * - If omitted, defaults to the host of the current document URL, not including subdomains.
74
+ * - Contrary to earlier specifications, leading dots in domain names (.example.com) are ignored.
75
+ * - Multiple host/domain values are not allowed, but if a domain is specified, then subdomains are always included.
76
+ */
77
+ domain?: string;
78
+ /**
79
+ * A path that must exist in the requested URL, or the browser won't send the Cookie header.
80
+ *
81
+ * The forward slash (/) character is interpreted as a directory separator, and subdirectories will be matched as well:
82
+ * for Path=/docs, /docs, /docs/Web/, and /docs/Web/HTTP will all match.
83
+ */
84
+ path?: string;
85
+ /**
86
+ * A secure cookie is only sent to the server when a request is made with the https: scheme.
87
+ * (However, confidential information should never be stored in HTTP Cookies,
88
+ * as the entire mechanism is inherently insecure and doesn't encrypt any information.)
89
+ */
90
+ secure?: boolean;
91
+ /**
92
+ * Forbids JavaScript from accessing the cookie.
93
+ *
94
+ * For example, through the Document.cookie property, the XMLHttpRequest API, or the Request API.
95
+ * This mitigates attacks against cross-site scripting (XSS).
96
+ */
97
+ httpOnly?: boolean;
98
+ /**
99
+ * Asserts that a cookie must not be sent with cross-origin requests,
100
+ * providing some protection against cross-site request forgery attacks (CSRF).
101
+ * - Strict: The browser sends the cookie only for same-site requests
102
+ * (that is, requests originating from the same site that set the cookie).
103
+ * If the request originated from a different URL than the current one,
104
+ * no cookies with the SameSite=Strict attribute are sent.
105
+ * - Lax: The cookie is withheld on cross-site subrequests, such as calls to load images or frames,
106
+ * but is sent when a user navigates to the URL from an external site, such as by following a link.
107
+ * - None: The browser sends the cookie with both cross-site and same-site requests.
108
+ */
109
+ sameSite?: "Strict" | "Lax" | "None";
110
+ };
111
+ //# sourceMappingURL=custom-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-types.d.ts","sourceRoot":"","sources":["../../data/custom-types.js"],"names":[],"mappings":";;;;;4BACoB,CAAC,0BACR,OAAO,2BAA2B,EAAE,OAAO,CAAC,CAAC,CAAC;0BAE7C,OAAO,uBAAuB,EAAE,OAAO;2BACvC,OAAO,wBAAwB,EAAE,OAAO;;UAI5C,MAAM;UACN,MAAM;aACN,MAAM;YACN,MAAM;gBACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;qBAGlB,OAAO,aAAa,EAAE,MAAM;yBAE5B,OAAO,iBAAiB,EAAE,UAAU;wCAEpC,IAAI,GAAC,KAAK,GAAC,CAAC;4BAEZ,KAAK,GAAC,MAAM,GAAC,MAAM,GAAC,KAAK,GAAC,QAAQ,GAAC,SAAS,GAAC,SAAS,GAAC,OAAO,GAAC,OAAO;2CAEtE,CAAC,GAAC,IAAI,GAAC,KAAK,GAAC,IAAI,GAAC,SAAS,GAAC,IAAI;uCAEhC,OAAO,CAAC,UAAU,CAAC,GAAC,UAAU;gCAE9B,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,GAAC,MAAM,GAAC,OAAO,QAAQ,EAAE,QAAQ,GAAC,MAAM,GAAC,MAAM;+BAG3D,CAAC,wCAET,eAAe,CAAC,CAAC,CAAC,KAClB,wBAAwB;uCAIhB,CAAC,wCAEV;IAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;CAAE,KAC3C,wBAAwB;qDAMxB,eAAe,KACf,wBAAwB;2CAKxB,YAAY,KACZ,IAAI,GAAC,IAAI,GAAC,OAAO,GAAC,OAAO,CAAC,IAAI,GAAC,IAAI,GAAC,OAAO,CAAC;;aAK9C,kBAAkB;;;aAKlB,wBAAwB;;;aAKxB,wBAAwB;;;aAKxB,kBAAkB;;0BAIf,kBAAkB,GAAC,wBAAwB,GAAC,sBAAsB,GAAC,4BAA4B,GAAC,wBAAwB;;;;;;;;WAK3H,MAAM;;;;;;;;;YAKN,MAAM;;;;;;;cAON,IAAI;;;;;aAKJ,MAAM;;;;;;;aAGN,MAAM;;;;;;;WAKN,MAAM;;;;;;aAKN,OAAO;;;;;;;eAIP,OAAO;;;;;;;;;;;;eAKP,QAAQ,GAAC,KAAK,GAAC,MAAM"}
@@ -0,0 +1,11 @@
1
+ /** @typedef {import('../lib/HttpHandler').default} HttpHandler */
2
+ /** @typedef {import('http2').Http2SecureServer} Http2SecureServer */
3
+ /**
4
+ * @param {HttpHandler} httpHandler
5
+ * @param {RegExp} [socketioPath] /^\/socket.io\//i
6
+ * @return {void}
7
+ */
8
+ export function addHttp2Support(httpHandler: HttpHandler, socketioPath?: RegExp): void;
9
+ export type HttpHandler = import("../lib/HttpHandler").default;
10
+ export type Http2SecureServer = import("http2").Http2SecureServer;
11
+ //# sourceMappingURL=socketio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socketio.d.ts","sourceRoot":"","sources":["../../errata/socketio.js"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,qEAAqE;AAErE;;;;GAIG;AACH,6CAJW,WAAW,iBACX,MAAM,GACL,IAAI,CAYf;0BAlBa,OAAO,oBAAoB,EAAE,OAAO;gCACpC,OAAO,OAAO,EAAE,iBAAiB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=starter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"starter.d.ts","sourceRoot":"","sources":["../../examples/starter.js"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ export default class HeadersParser {
2
+ constructor(headers?: {});
3
+ /** @type {Object<string,any>} */
4
+ headers: {
5
+ [x: string]: any;
6
+ };
7
+ /** @return {string} */
8
+ get contentType(): string;
9
+ /**
10
+ * The `media-type` directive of `Content-Type`.
11
+ * The MIME type of the resource or the data.
12
+ * (Always lowercase)
13
+ * @return {string}
14
+ */
15
+ get mediaType(): string;
16
+ /**
17
+ * The `charset` direct of `Content-Type`.
18
+ * The character encoding standard.
19
+ * (Always lowercase)
20
+ @return {string} */
21
+ get charset(): string;
22
+ /** @return {string} */
23
+ get boundary(): string;
24
+ /** @return {?number} */
25
+ get contentLength(): number | null;
26
+ }
27
+ //# sourceMappingURL=HeadersParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HeadersParser.d.ts","sourceRoot":"","sources":["../../helpers/HeadersParser.js"],"names":[],"mappings":"AAAA;IACE,0BAGC;IAFC,iCAAiC;IACjC;;MAAsB;IAGxB,uBAAuB;IACvB,mBADa,MAAM,CAGlB;IAED;;;;;OAKG;IACH,iBAFY,MAAM,CAIjB;IAED;;;;yBAIqB;IACrB,eADW,MAAM,CAkBhB;IAED,uBAAuB;IACvB,gBADa,MAAM,CAkBlB;IAED,wBAAwB;IACxB,qBADc,MAAM,OAAA,CAGnB;CACF"}