webhoster 0.3.4 → 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 (125) hide show
  1. package/package.json +12 -1
  2. package/types/data/CookieObject.d.ts +34 -0
  3. package/types/data/CookieObject.d.ts.map +1 -0
  4. package/types/data/custom-types.d.ts +111 -0
  5. package/types/data/custom-types.d.ts.map +1 -0
  6. package/types/errata/socketio.d.ts +11 -0
  7. package/types/errata/socketio.d.ts.map +1 -0
  8. package/types/examples/starter.d.ts +2 -0
  9. package/types/examples/starter.d.ts.map +1 -0
  10. package/types/helpers/HeadersParser.d.ts +27 -0
  11. package/types/helpers/HeadersParser.d.ts.map +1 -0
  12. package/types/helpers/HttpListener.d.ts +84 -0
  13. package/types/helpers/HttpListener.d.ts.map +1 -0
  14. package/types/helpers/RequestHeaders.d.ts +25 -0
  15. package/types/helpers/RequestHeaders.d.ts.map +1 -0
  16. package/types/helpers/RequestReader.d.ts +52 -0
  17. package/types/helpers/RequestReader.d.ts.map +1 -0
  18. package/types/helpers/ResponseHeaders.d.ts +126 -0
  19. package/types/helpers/ResponseHeaders.d.ts.map +1 -0
  20. package/types/helpers/index.d.ts +6 -0
  21. package/types/helpers/index.d.ts.map +1 -0
  22. package/types/lib/HttpHandler.d.ts +79 -0
  23. package/types/lib/HttpHandler.d.ts.map +1 -0
  24. package/types/lib/HttpRequest.d.ts +175 -0
  25. package/types/lib/HttpRequest.d.ts.map +1 -0
  26. package/types/lib/HttpResponse.d.ts +117 -0
  27. package/types/lib/HttpResponse.d.ts.map +1 -0
  28. package/types/lib/HttpTransaction.d.ts +114 -0
  29. package/types/lib/HttpTransaction.d.ts.map +1 -0
  30. package/types/middleware/AutoHeadersMiddleware.d.ts +27 -0
  31. package/types/middleware/AutoHeadersMiddleware.d.ts.map +1 -0
  32. package/types/middleware/CORSMiddleware.d.ts +65 -0
  33. package/types/middleware/CORSMiddleware.d.ts.map +1 -0
  34. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts +27 -0
  35. package/types/middleware/CaseInsensitiveHeadersMiddleware.d.ts.map +1 -0
  36. package/types/middleware/ContentDecoderMiddleware.d.ts +17 -0
  37. package/types/middleware/ContentDecoderMiddleware.d.ts.map +1 -0
  38. package/types/middleware/ContentEncoderMiddleware.d.ts +48 -0
  39. package/types/middleware/ContentEncoderMiddleware.d.ts.map +1 -0
  40. package/types/middleware/ContentLengthMiddleware.d.ts +38 -0
  41. package/types/middleware/ContentLengthMiddleware.d.ts.map +1 -0
  42. package/types/middleware/HashMiddleware.d.ts +28 -0
  43. package/types/middleware/HashMiddleware.d.ts.map +1 -0
  44. package/types/middleware/HeadMethodMiddleware.d.ts +12 -0
  45. package/types/middleware/HeadMethodMiddleware.d.ts.map +1 -0
  46. package/types/middleware/MethodMiddleware.d.ts +40 -0
  47. package/types/middleware/MethodMiddleware.d.ts.map +1 -0
  48. package/types/middleware/PathMiddleware.d.ts +81 -0
  49. package/types/middleware/PathMiddleware.d.ts.map +1 -0
  50. package/types/middleware/ReadFormData.d.ts +7 -0
  51. package/types/middleware/ReadFormData.d.ts.map +1 -0
  52. package/types/middleware/SendJsonMiddleware.d.ts +51 -0
  53. package/types/middleware/SendJsonMiddleware.d.ts.map +1 -0
  54. package/types/middleware/SendStringMiddleware.d.ts +35 -0
  55. package/types/middleware/SendStringMiddleware.d.ts.map +1 -0
  56. package/types/templates/starter.d.ts +15 -0
  57. package/types/templates/starter.d.ts.map +1 -0
  58. package/types/utils/AsyncObject.d.ts +38 -0
  59. package/types/utils/AsyncObject.d.ts.map +1 -0
  60. package/types/utils/CaseInsensitiveObject.d.ts +9 -0
  61. package/types/utils/CaseInsensitiveObject.d.ts.map +1 -0
  62. package/types/utils/function.d.ts +2 -0
  63. package/types/utils/function.d.ts.map +1 -0
  64. package/types/utils/headers.d.ts +7 -0
  65. package/types/utils/headers.d.ts.map +1 -0
  66. package/types/utils/qualityValues.d.ts +12 -0
  67. package/types/utils/qualityValues.d.ts.map +1 -0
  68. package/types/utils/stream.d.ts +6 -0
  69. package/types/utils/stream.d.ts.map +1 -0
  70. package/.eslintrc.json +0 -96
  71. package/.github/FUNDING.yml +0 -4
  72. package/.github/copilot-instructions.md +0 -100
  73. package/.github/workflows/publish.yml +0 -29
  74. package/.github/workflows/test-matrix.yml +0 -37
  75. package/.test/benchmark.js +0 -28
  76. package/.test/constants.js +0 -4
  77. package/.test/cookietester.js +0 -19
  78. package/.test/http2server.js +0 -35
  79. package/.test/httpserver.js +0 -32
  80. package/.test/index.js +0 -498
  81. package/.test/multipromise.js +0 -32
  82. package/.test/tls.js +0 -75
  83. package/.test/urlencoded.js +0 -54
  84. package/.vscode/launch.json +0 -35
  85. package/.vscode/settings.json +0 -5
  86. package/CHANGELOG.md +0 -10
  87. package/CODE_OF_CONDUCT.md +0 -76
  88. package/examples/starter.js +0 -11
  89. package/jsconfig.json +0 -12
  90. package/polyfill/FormData.js +0 -164
  91. package/rollup.config.js +0 -8
  92. package/scripts/check-teapot.mjs +0 -40
  93. package/scripts/test-all-sync.sh +0 -6
  94. package/scripts/test-all.sh +0 -7
  95. package/test/fixtures/stream.js +0 -68
  96. package/test/helpers/HttpListener/construct.js +0 -18
  97. package/test/helpers/HttpListener/customOptions.js +0 -22
  98. package/test/helpers/HttpListener/doubleCreate.js +0 -40
  99. package/test/helpers/HttpListener/events.js +0 -77
  100. package/test/helpers/HttpListener/http.js +0 -31
  101. package/test/helpers/HttpListener/http2.js +0 -41
  102. package/test/helpers/HttpListener/https.js +0 -38
  103. package/test/helpers/HttpListener/startAll.js +0 -31
  104. package/test/helpers/HttpListener/stopNotStarted.js +0 -23
  105. package/test/lib/HttpHandler/class.js +0 -8
  106. package/test/lib/HttpHandler/handleRequest.js +0 -11
  107. package/test/lib/HttpHandler/middleware.js +0 -941
  108. package/test/lib/HttpHandler/parse.js +0 -41
  109. package/test/lib/HttpRequest/class.js +0 -8
  110. package/test/lib/HttpRequest/downstream.js +0 -171
  111. package/test/lib/HttpRequest/properties.js +0 -101
  112. package/test/lib/HttpRequest/read.js +0 -518
  113. package/test/lib/HttpResponse/async-iterable-middleware.js +0 -37
  114. package/test/lib/HttpResponse/async-iterable.js +0 -31
  115. package/test/lib/HttpResponse/class.js +0 -8
  116. package/test/lib/HttpResponse/properties.js +0 -59
  117. package/test/lib/HttpResponse/send.js +0 -275
  118. package/test/lib/HttpTransaction/class.js +0 -8
  119. package/test/lib/HttpTransaction/ping.js +0 -50
  120. package/test/lib/HttpTransaction/push.js +0 -89
  121. package/test/middleware/SendJsonMiddleware.js +0 -222
  122. package/test/sanity.js +0 -10
  123. package/test/templates/error-teapot.js +0 -47
  124. package/test/templates/starter.js +0 -93
  125. package/tsconfig.json +0 -29
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentLengthMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/ContentLengthMiddleware.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;IACE,wDAAwD;IACxD,sBADY,8BAA8B,EAKzC;IAHC,oBAA2C;IAC3C,wBAAqD;;IAIvD;;;OAGG;IACH,6BAHW,YAAY,GACX,IAAI,CAwDf;;CA+BF;2BAjHa,OAAO,wBAAwB,EAAE,OAAO;iCACxC,OAAO,yBAAyB,EAAE,kBAAkB;gCACpD,OAAO,yBAAyB,EAAE,iBAAiB;;;;;;;kBAMvD,MAAM;;;;qBAIN,OAAO"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @typedef {Object} HashMiddlewareOptions
3
+ * @prop {'md5'|'sha1'|'sha256'|'sha512'} [algorithm=DEFAULT_ALGORITHM]
4
+ * @prop {BinaryToTextEncoding} [digest=DEFAULT_DIGEST]
5
+ */
6
+ export default class HashMiddleware {
7
+ /** @param {HashMiddlewareOptions} options */
8
+ constructor(options?: HashMiddlewareOptions);
9
+ algorithm: "sha1" | "md5" | "sha256" | "sha512";
10
+ digest: import("crypto").BinaryToTextEncoding;
11
+ finalizeResponse(response: import("../data/custom-types.js").HttpResponse): void | null | boolean | Promise<void | null | boolean>;
12
+ /**
13
+ * @param {HttpResponse} response
14
+ * @return {void}
15
+ */
16
+ addTransformStream(response: HttpResponse): void;
17
+ execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
18
+ }
19
+ export type BinaryToTextEncoding = import("node:crypto").BinaryToTextEncoding;
20
+ export type HttpRequest = import("../lib/HttpRequest.js").default;
21
+ export type HttpResponse = import("../lib/HttpResponse.js").default;
22
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
23
+ export type ResponseFinalizer = import("../data/custom-types.js").ResponseFinalizer;
24
+ export type HashMiddlewareOptions = {
25
+ algorithm?: "md5" | "sha1" | "sha256" | "sha512";
26
+ digest?: BinaryToTextEncoding;
27
+ };
28
+ //# sourceMappingURL=HashMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/HashMiddleware.js"],"names":[],"mappings":"AAaA;;;;GAIG;AAEH;IACE,6CAA6C;IAC7C,sBADY,qBAAqB,EAKhC;IAHC,gDAAuD;IACvD,8CAA8C;;IAIhD;;;OAGG;IACH,6BAHW,YAAY,GACX,IAAI,CAiDf;;CA8BF;mCAzGa,OAAO,aAAa,EAAE,oBAAoB;0BAC1C,OAAO,uBAAuB,EAAE,OAAO;2BACvC,OAAO,wBAAwB,EAAE,OAAO;iCACxC,OAAO,yBAAyB,EAAE,kBAAkB;gCACpD,OAAO,yBAAyB,EAAE,iBAAiB;;gBAQvD,KAAK,GAAC,MAAM,GAAC,QAAQ,GAAC,QAAQ;aAC9B,oBAAoB"}
@@ -0,0 +1,12 @@
1
+ export default class HeadMethodMiddleware {
2
+ /** @type {ConstructorParameters<typeof Transform>[0]} */
3
+ static DEFAULT_TRANSFORM_OPTIONS: ConstructorParameters<typeof Transform>[0];
4
+ static FinalizeResponse(response: import("../data/custom-types.js").HttpResponse): void | null | boolean | Promise<void | null | boolean>;
5
+ static Execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
6
+ execute: any;
7
+ }
8
+ export type HttpTransaction = import("../data/custom-types.js").HttpTransaction;
9
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
10
+ export type ResponseFinalizer = import("../data/custom-types.js").ResponseFinalizer;
11
+ import { Transform } from 'node:stream';
12
+ //# sourceMappingURL=HeadMethodMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HeadMethodMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/HeadMethodMiddleware.js"],"names":[],"mappings":"AAMA;IAKE,yDAAyD;IACzD,kCADW,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAInD;;;IAPA,aAAsD;CAuBzD;8BA/Ba,OAAO,yBAAyB,EAAE,eAAe;iCACjD,OAAO,yBAAyB,EAAE,kBAAkB;gCACpD,OAAO,yBAAyB,EAAE,iBAAiB;0BAEvC,aAAa"}
@@ -0,0 +1,40 @@
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
+ /** @typedef {RegExp|RequestMethod} MethodEntry */
5
+ /**
6
+ * @typedef {Object} MethodMiddlewareOptions
7
+ * @prop {MethodEntry|MethodEntry[]} method
8
+ */
9
+ export default class MethodMiddleware {
10
+ /** @type {Map<MethodEntry, MethodMiddleware>} */
11
+ static cache: Map<MethodEntry, MethodMiddleware>;
12
+ /**
13
+ * @param {RequestMethod} method
14
+ * @param {RegExp | string} input
15
+ * @return {boolean}
16
+ */
17
+ static test(method: RequestMethod, input: RegExp | string): boolean;
18
+ static CONNECT(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
19
+ static DELETE(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
20
+ static HEADORGET(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
21
+ static GET(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
22
+ static OPTIONS(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
23
+ static HEAD(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
24
+ static PATCH(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
25
+ static POST(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
26
+ static PUT(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
27
+ static TRACE(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
28
+ /** @param {MethodMiddlewareOptions|MethodEntry|MethodEntry[]} options */
29
+ constructor(options: MethodMiddlewareOptions | MethodEntry | MethodEntry[]);
30
+ method: MethodEntry[];
31
+ execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
32
+ }
33
+ export type HttpTransaction = import("../data/custom-types.js").HttpTransaction;
34
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
35
+ export type RequestMethod = import("../data/custom-types.js").RequestMethod;
36
+ export type MethodEntry = RegExp | RequestMethod;
37
+ export type MethodMiddlewareOptions = {
38
+ method: MethodEntry | MethodEntry[];
39
+ };
40
+ //# sourceMappingURL=MethodMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MethodMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/MethodMiddleware.js"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,yFAAyF;AACzF,+EAA+E;AAE/E,kDAAkD;AAElD;;;GAGG;AAEH;IAYE,iDAAiD;IACjD,cADW,GAAG,CAAC,WAAW,EAAE,gBAAgB,CAAC,CACpB;IAEzB;;;;OAIG;IACH,oBAJW,aAAa,SACb,MAAM,GAAG,MAAM,GACd,OAAO,CAOlB;;;;;;;;;;;IAxBD,yEAAyE;IACzE,qBADY,uBAAuB,GAAC,WAAW,GAAC,WAAW,EAAE,EAS5D;IANG,sBAAqB;;CA8D1B;8BA7Ea,OAAO,yBAAyB,EAAE,eAAe;iCACjD,OAAO,yBAAyB,EAAE,kBAAkB;4BACpD,OAAO,yBAAyB,EAAE,aAAa;0BAE/C,MAAM,GAAC,aAAa;;YAIxB,WAAW,GAAC,WAAW,EAAE"}
@@ -0,0 +1,81 @@
1
+ /** @typedef {import('../data/custom-types.js').HttpTransaction} HttpTransaction */
2
+ /** @typedef {import('../data/custom-types.js').IMiddleware} IMiddleware */
3
+ /** @typedef {import('../data/custom-types.js').MiddlewareFunction} MiddlewareFunction */
4
+ /** @typedef {import('../data/custom-types.js').RequestMethod} RequestMethod */
5
+ /** @typedef {RegExp|string} PathEntry */
6
+ /**
7
+ * @typedef {Object} PathHistoryEntry hello?
8
+ * @prop {string} base
9
+ * @prop {number[]} treeIndex
10
+ */
11
+ /**
12
+ * @typedef {Object} PathState
13
+ * @prop {PathHistoryEntry[]} history
14
+ * @prop {string} currentPath
15
+ */
16
+ /**
17
+ * @typedef {Object} PathMiddlewareOptions
18
+ * @prop {PathEntry|PathEntry[]} [path]
19
+ * @prop {boolean} [absolute=false]
20
+ * Path is not relative to previous PathMiddleware. Defaults to `false`.
21
+ * @prop {boolean} [subPath=false]
22
+ * Path values are subpaths. Default to `false`;
23
+ */
24
+ export default class PathMiddleware {
25
+ /**
26
+ * @param {PathEntry|PathEntry[]} entry
27
+ */
28
+ static SUBPATH(entry: PathEntry | PathEntry[]): PathMiddleware;
29
+ /**
30
+ * @param {string} path
31
+ * @param {RegExp | string} input
32
+ * @return {?string}
33
+ */
34
+ static test(path: string, input: RegExp | string): string | null;
35
+ /**
36
+ * @param {HttpTransaction} transaction
37
+ * @param {string} base new base subpath
38
+ * @param {string} currentPath
39
+ * @return {void}
40
+ */
41
+ static WritePathState(transaction: HttpTransaction, base: string, currentPath: string): void;
42
+ /**
43
+ * @param {HttpTransaction} transaction
44
+ * @return {string} joined base path
45
+ */
46
+ static ReadPathState(transaction: HttpTransaction): string;
47
+ /** @param {PathMiddlewareOptions|PathEntry|PathEntry[]} options */
48
+ constructor(options: PathMiddlewareOptions | PathEntry | PathEntry[]);
49
+ path: PathEntry[];
50
+ absolute: boolean;
51
+ subPath: boolean;
52
+ execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
53
+ }
54
+ export type HttpTransaction = import("../data/custom-types.js").HttpTransaction;
55
+ export type IMiddleware = import("../data/custom-types.js").IMiddleware;
56
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
57
+ export type RequestMethod = import("../data/custom-types.js").RequestMethod;
58
+ export type PathEntry = RegExp | string;
59
+ /**
60
+ * hello?
61
+ */
62
+ export type PathHistoryEntry = {
63
+ base: string;
64
+ treeIndex: number[];
65
+ };
66
+ export type PathState = {
67
+ history: PathHistoryEntry[];
68
+ currentPath: string;
69
+ };
70
+ export type PathMiddlewareOptions = {
71
+ path?: PathEntry | PathEntry[];
72
+ /**
73
+ * Path is not relative to previous PathMiddleware. Defaults to `false`.
74
+ */
75
+ absolute?: boolean;
76
+ /**
77
+ * Path values are subpaths. Default to `false`;
78
+ */
79
+ subPath?: boolean;
80
+ };
81
+ //# sourceMappingURL=PathMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/PathMiddleware.js"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,2EAA2E;AAC3E,yFAAyF;AACzF,+EAA+E;AAE/E,yCAAyC;AAEzC;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;;GAOG;AAEH;IACE;;OAEG;IACH,sBAFW,SAAS,GAAC,SAAS,EAAE,kBAQ/B;IAED;;;;OAIG;IACH,kBAJW,MAAM,SACN,MAAM,GAAG,MAAM,GACb,MAAM,OAAA,CAYlB;IAED;;;;;OAKG;IACH,mCALW,eAAe,QACf,MAAM,eACN,MAAM,GACL,IAAI,CAWf;IAED;;;OAGG;IACH,kCAHW,eAAe,GACd,MAAM,CA4BjB;IAED,mEAAmE;IACnE,qBADY,qBAAqB,GAAC,SAAS,GAAC,SAAS,EAAE,EAetD;IAZG,kBAAmB;IACnB,kBAAqB;IACrB,iBAAoB;;CA4BzB;8BA3Ia,OAAO,yBAAyB,EAAE,eAAe;0BACjD,OAAO,yBAAyB,EAAE,WAAW;iCAC7C,OAAO,yBAAyB,EAAE,kBAAkB;4BACpD,OAAO,yBAAyB,EAAE,aAAa;wBAE/C,MAAM,GAAC,MAAM;;;;;UAIjB,MAAM;eACN,MAAM,EAAE;;;aAKR,gBAAgB,EAAE;iBAClB,MAAM;;;WAKN,SAAS,GAAC,SAAS,EAAE;;;;eACrB,OAAO;;;;cAEP,OAAO"}
@@ -0,0 +1,7 @@
1
+ export default class ReadFormData {
2
+ static Execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
3
+ execute: any;
4
+ }
5
+ export type HttpRequest = import("../lib/HttpRequest.js").default;
6
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
7
+ //# sourceMappingURL=ReadFormData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadFormData.d.ts","sourceRoot":"","sources":["../../middleware/ReadFormData.js"],"names":[],"mappings":"AAwFA;;IAEI,aAA8C;CAQjD;0BAlGa,OAAO,uBAAuB,EAAE,OAAO;iCACvC,OAAO,yBAAyB,EAAE,kBAAkB"}
@@ -0,0 +1,51 @@
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
+ /**
6
+ * @typedef {Object} SendJsonMiddlewareOptions
7
+ * @prop {string} [defaultCharset='utf-8']
8
+ * @prop {boolean} [setCharset=true]
9
+ * Automatically applies charset in `Content-Type`
10
+ * @prop {boolean} [setMediaType=true]
11
+ * Automatically applies `application/json` mediatype in `Content-Type`
12
+ */
13
+ export default class SendJsonMiddleware {
14
+ /** @type {SendJsonMiddleware} */
15
+ static "__#5@#defaultInstance": SendJsonMiddleware;
16
+ /**
17
+ * @param {string} charset
18
+ * @return {BufferEncoding}
19
+ */
20
+ static charsetAsBufferEncoding(charset: string): BufferEncoding;
21
+ static Execute(transaction: {
22
+ response: import("../lib/HttpResponse.js").default;
23
+ }): import("../data/custom-types.js").MiddlewareFunctionResult;
24
+ /** @param {SendJsonMiddlewareOptions} [options] */
25
+ constructor(options?: SendJsonMiddlewareOptions);
26
+ options: {
27
+ defaultCharset: string;
28
+ setCharset: boolean;
29
+ setMediaType: boolean;
30
+ };
31
+ finalizeResponse(response: import("../data/custom-types.js").HttpResponse): void | null | boolean | Promise<void | null | boolean>;
32
+ execute(transaction: {
33
+ response: import("../lib/HttpResponse.js").default;
34
+ }): import("../data/custom-types.js").MiddlewareFunctionResult;
35
+ }
36
+ export type IMiddleware = import("../data/custom-types.js").IMiddleware;
37
+ export type MiddlewareResponseFunction = import("../data/custom-types.js").MiddlewareResponseFunction;
38
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
39
+ export type ResponseFinalizer = import("../data/custom-types.js").ResponseFinalizer;
40
+ export type SendJsonMiddlewareOptions = {
41
+ defaultCharset?: string;
42
+ /**
43
+ * Automatically applies charset in `Content-Type`
44
+ */
45
+ setCharset?: boolean;
46
+ /**
47
+ * Automatically applies `application/json` mediatype in `Content-Type`
48
+ */
49
+ setMediaType?: boolean;
50
+ };
51
+ //# sourceMappingURL=SendJsonMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SendJsonMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/SendJsonMiddleware.js"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yGAAyG;AACzG,yFAAyF;AACzF,uFAAuF;AAEvF;;;;;;;GAOG;AAIH;IACE,iCAAiC;IACjC,gCADW,kBAAkB,CACL;IAExB;;;OAGG;IACH,wCAHW,MAAM,GACL,cAAc,CAsBzB;;;;IAcD,mDAAmD;IACnD,sBADY,yBAAyB,EASpC;IAPC;;;;MAIC;;;;;CAkEJ;0BAlIa,OAAO,yBAAyB,EAAE,WAAW;yCAC7C,OAAO,yBAAyB,EAAE,0BAA0B;iCAC5D,OAAO,yBAAyB,EAAE,kBAAkB;gCACpD,OAAO,yBAAyB,EAAE,iBAAiB;;qBAIvD,MAAM;;;;iBACN,OAAO;;;;mBAEP,OAAO"}
@@ -0,0 +1,35 @@
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
+ /**
5
+ * @typedef {Object} SendStringMiddlewareOptions
6
+ * @prop {string} [defaultCharset='utf-8']
7
+ * @prop {boolean} [setCharset=true]
8
+ * Automatically applies charset in `Content-Type`
9
+ */
10
+ export default class SendStringMiddleware {
11
+ /**
12
+ * @param {string} charset
13
+ * @return {BufferEncoding}
14
+ */
15
+ static charsetAsBufferEncoding(charset: string): BufferEncoding;
16
+ /** @param {SendStringMiddlewareOptions} [options] */
17
+ constructor(options?: SendStringMiddlewareOptions);
18
+ options: {
19
+ defaultCharset: string;
20
+ setCharset: boolean;
21
+ };
22
+ finalizeResponse(response: import("../data/custom-types.js").HttpResponse): void | null | boolean | Promise<void | null | boolean>;
23
+ execute(transaction: import("../lib/HttpTransaction.js").default<any>): import("../data/custom-types.js").MiddlewareFunctionResult;
24
+ }
25
+ export type IMiddleware = import("../data/custom-types.js").IMiddleware;
26
+ export type MiddlewareFunction = import("../data/custom-types.js").MiddlewareFunction;
27
+ export type ResponseFinalizer = import("../data/custom-types.js").ResponseFinalizer;
28
+ export type SendStringMiddlewareOptions = {
29
+ defaultCharset?: string;
30
+ /**
31
+ * Automatically applies charset in `Content-Type`
32
+ */
33
+ setCharset?: boolean;
34
+ };
35
+ //# sourceMappingURL=SendStringMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SendStringMiddleware.d.ts","sourceRoot":"","sources":["../../middleware/SendStringMiddleware.js"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yFAAyF;AACzF,uFAAuF;AAEvF;;;;;GAKG;AAEH;IAWE;;;OAGG;IACH,wCAHW,MAAM,GACL,cAAc,CAsBzB;IAlCD,qDAAqD;IACrD,sBADY,2BAA2B,EAQtC;IANC;;;MAGC;;;CAqEJ;0BAtFa,OAAO,yBAAyB,EAAE,WAAW;iCAC7C,OAAO,yBAAyB,EAAE,kBAAkB;gCACpD,OAAO,yBAAyB,EAAE,iBAAiB;;qBAIvD,MAAM;;;;iBACN,OAAO"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param {Object} options
3
+ * @param {string} [options.host='0.0.0.0']
4
+ * @param {number} [options.port=8080]
5
+ * @param {import('../data/custom-types.js').Middleware[]} [options.middleware]
6
+ * @param {import('../data/custom-types.js').MiddlewareErrorHandler[]} [options.errorHandlers]
7
+ * @return {Promise<import('../helpers/HttpListener.js').default>}
8
+ */
9
+ export function start(options: {
10
+ host?: string;
11
+ port?: number;
12
+ middleware?: import("../data/custom-types.js").Middleware[];
13
+ errorHandlers?: import("../data/custom-types.js").MiddlewareErrorHandler[];
14
+ }): Promise<import("../helpers/HttpListener.js").default>;
15
+ //# sourceMappingURL=starter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"starter.d.ts","sourceRoot":"","sources":["../../templates/starter.js"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,+BANG;IAAyB,IAAI,GAArB,MAAM;IACW,IAAI,GAArB,MAAM;IACmD,UAAU,GAAnE,OAAO,yBAAyB,EAAE,UAAU,EAAE;IACuB,aAAa,GAAlF,OAAO,yBAAyB,EAAE,sBAAsB,EAAE;CAClE,GAAS,OAAO,CAAC,OAAO,4BAA4B,EAAE,OAAO,CAAC,CAqChE"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @template {any} T
3
+ * @class AsyncObject<T>
4
+ */
5
+ export default class AsyncObject<T extends unknown> {
6
+ /** @param {T} [value] */
7
+ constructor(value?: T);
8
+ value: T;
9
+ ready: boolean;
10
+ busy: boolean;
11
+ /** @type {{resolve:function(T):void, reject:function(Error?):void}[]} */
12
+ pendingPromises: {
13
+ resolve: (arg0: T) => void;
14
+ reject: (arg0: Error | null) => void;
15
+ }[];
16
+ hasValue(): boolean;
17
+ isBusy(): boolean;
18
+ /** @return {Promise<T>} */
19
+ get(): Promise<T>;
20
+ /**
21
+ * @param {T} [value]
22
+ * @return {T}
23
+ */
24
+ set(value?: T): T;
25
+ /**
26
+ * @param {Error} [error] Error passed to pending promises
27
+ * @return {void}
28
+ */
29
+ reset(error?: Error): void;
30
+ /**
31
+ * Clear value and mark busy
32
+ * @return {void}
33
+ */
34
+ prepare(): void;
35
+ /** @return {void} */
36
+ setBusy(): void;
37
+ }
38
+ //# sourceMappingURL=AsyncObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncObject.d.ts","sourceRoot":"","sources":["../../utils/AsyncObject.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,iCAHmB,CAAC;IAIlB,yBAAyB;IACzB,oBADY,CAAC,EAOZ;IALC,SAAkB;IAClB,eAAkB;IAClB,cAAiB;IACjB,yEAAyE;IACzE,iBADW;QAAC,OAAO,EAAC,CAAS,IAAC,EAAD,CAAC,KAAE,IAAI,CAAC;QAAC,MAAM,EAAC,CAAS,IAAM,EAAN,KAAK,OAAC,KAAE,IAAI,CAAA;KAAC,EAAE,CAC5C;IAG3B,oBAEC;IAED,kBAEC;IAED,2BAA2B;IAC3B,OADa,OAAO,CAAC,CAAC,CAAC,CAQtB;IAED;;;OAGG;IACH,YAHW,CAAC,GACA,CAAC,CAUZ;IAED;;;OAGG;IACH,cAHW,KAAK,GACJ,IAAI,CASf;IAED;;;OAGG;IACH,WAFY,IAAI,CAMf;IAED,qBAAqB;IACrB,WADa,IAAI,CAGhB;CACF"}
@@ -0,0 +1,9 @@
1
+ declare class CaseInsensitiveObject {
2
+ /** @param {Object} [object] */
3
+ constructor(object?: Object);
4
+ }
5
+ declare namespace CaseInsensitiveObject {
6
+ let defaultProxyHandler: ProxyHandler<Object>;
7
+ }
8
+ export default CaseInsensitiveObject;
9
+ //# sourceMappingURL=CaseInsensitiveObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CaseInsensitiveObject.d.ts","sourceRoot":"","sources":["../../utils/CaseInsensitiveObject.js"],"names":[],"mappings":"AAAA;IACE,+BAA+B;IAC/B,qBADY,MAAM,EAajB;CACF;;6BAEU,YAAY,CAAC,MAAM,CAAC"}
@@ -0,0 +1,2 @@
1
+ export function noop(): void;
2
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../utils/function.js"],"names":[],"mappings":"AAAO,6BAAqB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {?string} contentType
4
+ * @return {import('../data/custom-types.js').MediaType}
5
+ */
6
+ export function parseContentType(contentType: string | null): import("../data/custom-types.js").MediaType;
7
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../utils/headers.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8CAHY,MAAM,OAAA,GACN,OAAO,yBAAyB,EAAE,SAAS,CAsCtD"}
@@ -0,0 +1,12 @@
1
+ /** @typedef {{q:number?} & {[key:string]:string}} ParsedQualityValues */
2
+ /**
3
+ * @param {string} input
4
+ * @return {Map<string, ParsedQualityValues>}
5
+ */
6
+ export function parseQualityValues(input: string): Map<string, ParsedQualityValues>;
7
+ export type ParsedQualityValues = {
8
+ q: number | null;
9
+ } & {
10
+ [key: string]: string;
11
+ };
12
+ //# sourceMappingURL=qualityValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualityValues.d.ts","sourceRoot":"","sources":["../../utils/qualityValues.js"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE;;;GAGG;AACH,0CAHW,MAAM,GACL,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CA2B3C;kCA/Ba;IAAC,CAAC,EAAC,MAAM,OAAC,CAAA;CAAC,GAAG;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,MAAM,CAAA;CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {import('node:stream').Writable|import('node:http').ServerResponse} writableLike
3
+ * @return {boolean}
4
+ */
5
+ export function isWritable(writableLike: import("node:stream").Writable | import("node:http").ServerResponse): boolean;
6
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../utils/stream.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,yCAHW,OAAO,aAAa,EAAE,QAAQ,GAAC,OAAO,WAAW,EAAE,cAAc,GAChE,OAAO,CAIlB"}
package/.eslintrc.json DELETED
@@ -1,96 +0,0 @@
1
- {
2
- "env": {
3
- "es2021": true
4
- },
5
- "extends": [
6
- "airbnb-base",
7
- "plugin:@typescript-eslint/recommended",
8
- "plugin:jsdoc/recommended-typescript-flavor-error",
9
- "plugin:n/recommended",
10
- "plugin:unicorn/recommended",
11
- "plugin:import/recommended"
12
- ],
13
- "overrides": [
14
- {
15
- "files": [
16
- "*.cjs"
17
- ],
18
- "rules": {
19
- "@typescript-eslint/no-var-requires": 0,
20
- "import/no-nodejs-modules": 0
21
- }
22
- }
23
- ],
24
- "parser": "@typescript-eslint/parser",
25
- "parserOptions": {
26
- "ecmaFeatures": {
27
- "impliedStrict": true
28
- },
29
- "ecmaVersion": 2019,
30
- "project": "./jsconfig.json",
31
- "sourceType": "module"
32
- },
33
- "plugins": [
34
- "@typescript-eslint",
35
- "canonical",
36
- "jsdoc",
37
- "n",
38
- "unicorn",
39
- "import"
40
- ],
41
- "root": true,
42
- "rules": {
43
- "import/extensions": [
44
- "error",
45
- "always",
46
- {
47
- "js": "always",
48
- "mjs": "never"
49
- }
50
- ],
51
- "import/no-extraneous-dependencies": "off",
52
- "import/prefer-default-export": "off",
53
- "jsdoc/no-defaults": "off",
54
- "jsdoc/require-param-description": "off",
55
- "jsdoc/require-property-description": "off",
56
- "jsdoc/require-returns": "off",
57
- "jsdoc/require-returns-description": "off",
58
- "no-continue": "off",
59
- "no-restricted-syntax": "off",
60
- "no-return-await": "off",
61
- "unicorn/explicit-length-check": "off",
62
- "unicorn/filename-case": "off",
63
- "unicorn/no-null": "off",
64
- "unicorn/no-useless-switch-case": "off",
65
- "unicorn/no-useless-undefined": "off",
66
- "unicorn/prefer-ternary": [
67
- "error",
68
- "only-single-line"
69
- ],
70
- "unicorn/prevent-abbreviations": [
71
- "error",
72
- {
73
- "checkFilenames": false
74
- }
75
- ],
76
- "unicorn/switch-case-braces": "off",
77
- "unicorn/text-encoding-identifier-case": "off"
78
- },
79
- "settings": {
80
- "jsdoc": {
81
- "preferredTypes": {
82
- "array": "Array",
83
- "object": "Object",
84
- "object.": "Object<>",
85
- "object<>": "Object<>",
86
- "symbol": "Symbol"
87
- },
88
- "tagNamePreference": {
89
- "augment": "extends",
90
- "constant": "const",
91
- "property": "prop",
92
- "returns": "return"
93
- }
94
- }
95
- }
96
- }
@@ -1,4 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [clshortfuse]
4
- custom: ["https://www.paypal.me/clshortfuse"]
@@ -1,100 +0,0 @@
1
- <!-- Auto-generated: guidance for AI coding assistants working on this repo -->
2
- # Copilot / AI assistant instructions for webhoster
3
-
4
- This file gives focused, actionable guidance to quickly become productive in this repository.
5
-
6
- Overview
7
- - **Purpose**: `webhoster` is a stream-first, middleware-driven HTTP/HTTP2 framework for Node.js. Core classes live in `lib/` (notably `lib/HttpHandler.js`, `lib/HttpRequest.js`, `lib/HttpResponse.js`). Middleware implementations live in `middleware/` and are composed into the `HttpHandler` middleware tree.
8
- - **Module type**: The project is ESM (`"type": "module"` in `package.json`) and targets Node >v16.13.
9
-
10
- Key patterns and conventions
11
- - **Middleware tree**: Middleware can be a function, a filter, an Iterable (e.g. `Set`), or a `Map`. Branching is represented by nested arrays/iterables. See examples in `README.md` and `middleware/` files.
12
- - **Return values**: Middleware return values drive control flow. Use the `HttpHandler` constants or their aliases:
13
- - `HttpHandler.CONTINUE` (or `true`, `undefined`, `null`) — continue the branch
14
- - `HttpHandler.BREAK` (or `false`) — break this branch, move to next
15
- - `HttpHandler.END` (or `0`) — terminate the middleware tree
16
- - `number` — treated as an HTTP status code and ends
17
- - **I/O model**: Requests expose `.read()`, `.stream`, and `.body` helpers. Responses expose `.stream`, `.end()`, `.send()`, `.pipeFrom()` and may call `.pushPath()` for HTTP/2 pushes. See `lib/HttpRequest.js` and `lib/HttpResponse.js`.
18
- - **Locals**: Per-request state belongs on `request.locals` (or `locals`) and is passed through middleware.
19
-
20
- Developer workflows
21
- - **Run tests**: `npm test` (uses `c8` + `ava` for coverage). Unit tests live under `test/` (pattern: `test/**/*.js`, excluding `test/fixtures/**`).
22
- - **Run full/test-all scripts**: `npm run testall` (async) or `npm run testallsync` (sync). These call the scripts in `scripts/`.
23
- - **Debug tests**: `npm run debug-test` which runs `ava --serial`.
24
- - **Coverage**: Coverage created by `c8`; `posttestall`/`posttestallsync` call `c8 report`.
25
-
26
- Code style & types
27
- - Project uses `eslint` (Airbnb base + plugins) in devDependencies — follow existing style. There are TypeScript type hints (`types/typings.d.ts`) but the codebase is JavaScript ESM.
28
-
29
- Where to change behavior
30
- - Add or alter middleware in `middleware/`. Prefer small, single-responsibility modules: decoding, encoding, header transforms, routing filters (see `PathMiddleware.js`, `MethodMiddleware.js`).
31
- - Core runtime behavior is in `lib/HttpHandler.js`. Changes here affect branching, error handling, and how middleware results are interpreted.
32
-
33
- Testing & examples
34
- - Example middleware composition is in `README.md` and `test/index.js` — use those as canonical examples when adding new middleware or behavior.
35
- - Write tests under `test/` and avoid touching `test/fixtures/` unless updating fixture data. Use `ava` and follow existing test styles.
36
- \
37
- Example: minimal middleware
38
-
39
- ```js
40
- // middleware/ExampleMiddleware.js
41
- export default class ExampleMiddleware {
42
- execute(transaction) {
43
- transaction.locals = transaction.locals || {};
44
- transaction.locals.example = (transaction.locals.example || 0) + 1;
45
- return true; // continue processing
46
- }
47
- }
48
- ```
49
-
50
- Test example (AVA):
51
-
52
- ```js
53
- import test from 'ava';
54
- import ExampleMiddleware from '../middleware/ExampleMiddleware.js';
55
-
56
- test('ExampleMiddleware increments locals', (t) => {
57
- const m = new ExampleMiddleware();
58
- const transaction = { locals: {}, state: { treeIndex: [] }, request: {}, response: {} };
59
- m.execute(transaction);
60
- t.is(transaction.locals.example, 1);
61
- });
62
- ```
63
-
64
- I added `middleware/ExampleMiddleware.js` and `test/example-middleware.js` to the repo as a runnable template. Run `npm test` to verify the example.
65
-
66
- Integration points & runtime
67
- - Typical integration: a server registers handlers:
68
- - `http1Server.addListener('request', HttpHandler.defaultInstance.handleHttp1Request)`
69
- - `http2Server.addListener('stream', HttpHandler.defaultInstance.handleHttp2Stream)`
70
- - Middleware may push HTTP/2 resources using `response.pushPath()` — guard with `if (response.canPushPath)`.
71
-
72
- Practical tips for PRs and edits
73
- - Keep changes small and focused. Prefer adding middleware modules over modifying `HttpHandler` unless implementing a framework-level feature.
74
- - Preserve ESM syntax and `export`/`import` styles. Respect the project's `node` engine minimum.
75
- - Add or update `test/*.js` for any behavioral change; run `npm test` locally to confirm.
76
-
77
- Files to inspect when in doubt
78
- - `lib/HttpHandler.js`, `lib/HttpRequest.js`, `lib/HttpResponse.js`
79
- - `middleware/*` for existing middleware primitives
80
- - `test/index.js` and `test/**` for test patterns and usage examples
81
- - `scripts/test-all.sh` and `scripts/test-all-sync.sh` for CI/test orchestration
82
-
83
- CI / Workflows
84
- - `/.github/workflows/test-matrix.yml`: the recommended workflow. Runs `npm ci` + `npm run test` across a Node matrix (`16.13`, `16`, `18`, `20`, `22`) using `actions/setup-node`. Prefer editing this file when you want to change supported Node versions or add reporting steps (Codecov/Upload). Each matrix job uses the display name `Test on Node <version>`.
85
- - `/.github/workflows/test-with-nvm.yml`: optional workflow that installs `nvm` on the runner and executes `scripts/test-all.sh` to mirror local developer behavior. Keep this for parity/debugging only; the matrix job is preferred for CI.
86
-
87
- README badges
88
- - `README.md` contains per-node badges that point to the `test-matrix.yml` workflow and the job names. If you rename the workflow or change the job display name, update the badges in `README.md` accordingly. Badges point to the `master` branch by default.
89
-
90
- Local & debugging notes
91
- - Run tests locally (fast):
92
- - `npm ci`
93
- - `npm test` (runs `c8 ava`)
94
- - Run the full multi-version script locally (requires `nvm`):
95
- - `chmod +x scripts/test-all.sh`
96
- - `./scripts/test-all.sh`
97
- - The `scripts/test-all.sh` script runs `nvm install`/`nvm use` for multiple Node versions and then executes `npx c8 --clean false -r none ava` for each version in parallel. A recent fix corrected a typo so the Node 22 step now correctly runs `nvm use 22`.
98
-
99
- If you need more
100
- - If anything here is unclear or you'd like more examples (specific middleware templates, test scaffolds, or a debugging recipe), ask and I'll add them.