@deepkit/http 1.0.1-alpha.16 → 1.0.1-alpha.160

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 (124) hide show
  1. package/CHANGELOG.md +236 -0
  2. package/dist/cjs/index.d.ts +14 -10
  3. package/dist/cjs/index.js +19 -11
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/src/controllers.d.ts +10 -3
  6. package/dist/cjs/src/controllers.js +7 -3
  7. package/dist/cjs/src/controllers.js.map +1 -1
  8. package/dist/cjs/src/decorator.d.ts +144 -70
  9. package/dist/cjs/src/decorator.js +277 -102
  10. package/dist/cjs/src/decorator.js.map +1 -1
  11. package/dist/cjs/src/filter.d.ts +49 -0
  12. package/dist/cjs/src/filter.js +215 -0
  13. package/dist/cjs/src/filter.js.map +1 -0
  14. package/dist/cjs/src/http-app.d.ts +8 -0
  15. package/dist/cjs/src/http-app.js +16 -0
  16. package/dist/cjs/src/http-app.js.map +1 -0
  17. package/dist/cjs/src/http.d.ts +131 -32
  18. package/dist/cjs/src/http.js +523 -122
  19. package/dist/cjs/src/http.js.map +1 -1
  20. package/dist/cjs/src/kernel.d.ts +50 -9
  21. package/dist/cjs/src/kernel.js +109 -98
  22. package/dist/cjs/src/kernel.js.map +1 -1
  23. package/dist/cjs/src/logger.d.ts +3 -3
  24. package/dist/cjs/src/logger.js +9 -12
  25. package/dist/cjs/src/logger.js.map +1 -1
  26. package/dist/cjs/src/middleware.d.ts +61 -0
  27. package/dist/cjs/src/middleware.js +95 -0
  28. package/dist/cjs/src/middleware.js.map +1 -0
  29. package/dist/cjs/src/model.d.ts +270 -4
  30. package/dist/cjs/src/model.js +401 -3
  31. package/dist/cjs/src/model.js.map +1 -1
  32. package/dist/cjs/src/module.config.d.ts +149 -4
  33. package/dist/cjs/src/module.config.js +11 -6
  34. package/dist/cjs/src/module.config.js.map +1 -1
  35. package/dist/cjs/src/module.d.ts +14 -32
  36. package/dist/cjs/src/module.js +122 -7
  37. package/dist/cjs/src/module.js.map +1 -1
  38. package/dist/cjs/src/request-parser.d.ts +37 -0
  39. package/dist/cjs/src/request-parser.js +382 -0
  40. package/dist/cjs/src/request-parser.js.map +1 -0
  41. package/dist/cjs/src/router.d.ts +174 -75
  42. package/dist/cjs/src/router.js +469 -288
  43. package/dist/cjs/src/router.js.map +1 -1
  44. package/dist/cjs/src/static-serving.d.ts +32 -4
  45. package/dist/cjs/src/static-serving.js +115 -71
  46. package/dist/cjs/src/static-serving.js.map +1 -1
  47. package/dist/cjs/src/utils.js +2 -2
  48. package/dist/cjs/src/utils.js.map +1 -1
  49. package/dist/cjs/tsconfig.tsbuildinfo +1 -2916
  50. package/dist/esm/index.d.ts +14 -10
  51. package/dist/esm/index.js +14 -10
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/src/controllers.d.ts +10 -3
  54. package/dist/esm/src/controllers.js +7 -3
  55. package/dist/esm/src/controllers.js.map +1 -1
  56. package/dist/esm/src/decorator.d.ts +144 -70
  57. package/dist/esm/src/decorator.js +272 -99
  58. package/dist/esm/src/decorator.js.map +1 -1
  59. package/dist/esm/src/filter.d.ts +49 -0
  60. package/dist/esm/src/filter.js +209 -0
  61. package/dist/esm/src/filter.js.map +1 -0
  62. package/dist/esm/src/http-app.d.ts +8 -0
  63. package/dist/esm/src/http-app.js +12 -0
  64. package/dist/esm/src/http-app.js.map +1 -0
  65. package/dist/esm/src/http.d.ts +131 -32
  66. package/dist/esm/src/http.js +504 -121
  67. package/dist/esm/src/http.js.map +1 -1
  68. package/dist/esm/src/kernel.d.ts +50 -9
  69. package/dist/esm/src/kernel.js +110 -100
  70. package/dist/esm/src/kernel.js.map +1 -1
  71. package/dist/esm/src/logger.d.ts +3 -3
  72. package/dist/esm/src/logger.js +7 -11
  73. package/dist/esm/src/logger.js.map +1 -1
  74. package/dist/esm/src/middleware.d.ts +61 -0
  75. package/dist/esm/src/middleware.js +90 -0
  76. package/dist/esm/src/middleware.js.map +1 -0
  77. package/dist/esm/src/model.d.ts +270 -4
  78. package/dist/esm/src/model.js +357 -1
  79. package/dist/esm/src/model.js.map +1 -1
  80. package/dist/esm/src/module.config.d.ts +149 -4
  81. package/dist/esm/src/module.config.js +9 -5
  82. package/dist/esm/src/module.config.js.map +1 -1
  83. package/dist/esm/src/module.d.ts +14 -32
  84. package/dist/esm/src/module.js +121 -7
  85. package/dist/esm/src/module.js.map +1 -1
  86. package/dist/esm/src/request-parser.d.ts +37 -0
  87. package/dist/esm/src/request-parser.js +372 -0
  88. package/dist/esm/src/request-parser.js.map +1 -0
  89. package/dist/esm/src/router.d.ts +174 -75
  90. package/dist/esm/src/router.js +463 -285
  91. package/dist/esm/src/router.js.map +1 -1
  92. package/dist/esm/src/static-serving.d.ts +32 -4
  93. package/dist/esm/src/static-serving.js +107 -65
  94. package/dist/esm/src/static-serving.js.map +1 -1
  95. package/dist/esm/src/utils.js +1 -0
  96. package/dist/esm/src/utils.js.map +1 -1
  97. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -2916
  98. package/index.ts +14 -10
  99. package/package.json +30 -19
  100. package/src/controllers.ts +4 -3
  101. package/src/decorator.ts +242 -104
  102. package/src/filter.ts +224 -0
  103. package/src/http-app.ts +11 -0
  104. package/src/http.ts +501 -100
  105. package/src/kernel.ts +128 -80
  106. package/src/logger.ts +4 -6
  107. package/src/middleware.ts +116 -0
  108. package/src/model.ts +516 -5
  109. package/src/module.config.ts +168 -5
  110. package/src/module.ts +120 -7
  111. package/src/request-parser.ts +430 -0
  112. package/src/router.ts +546 -317
  113. package/src/static-serving.ts +120 -50
  114. package/src/utils.ts +0 -2
  115. package/tsconfig.esm.json +7 -7
  116. package/tsconfig.json +18 -11
  117. package/tsconfig.spec.json +8 -0
  118. package/dist/cjs/tests/router.spec.d.ts +0 -1
  119. package/dist/cjs/tests/router.spec.js +0 -481
  120. package/dist/cjs/tests/router.spec.js.map +0 -1
  121. package/dist/esm/tests/router.spec.d.ts +0 -1
  122. package/dist/esm/tests/router.spec.js +0 -479
  123. package/dist/esm/tests/router.spec.js.map +0 -1
  124. package/tests/router.spec.ts +0 -347
@@ -1,4 +1,54 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MemoryHttpResponse = exports.HttpRequest = exports.RequestBuilder = exports.__ΩHttpRegExp = exports.__ΩHttpQueries = exports.__ΩHttpQuery = exports.__ΩHttpHeader = exports.__ΩHttpPath = exports.__ΩHttpRequestParser = exports.__ΩHttpRequestParserOptions = exports.__ΩHttpBodyValidation = exports.__ΩHttpBody = exports.ValidatedBody = exports.BodyValidationError = exports.__ΩHttpRequestPositionedParameters = exports.__ΩHttpRequestResolvedParameters = exports.__ΩHttpRequestQuery = exports.HttpResponse = void 0;
37
+ exports.readBody = readBody;
38
+ exports.createRequestWithCachedBody = createRequestWithCachedBody;
39
+ exports.getRegExp = getRegExp;
40
+ exports.incomingMessageToHttpRequest = incomingMessageToHttpRequest;
41
+ exports.serverResponseToHttpResponse = serverResponseToHttpResponse;
42
+ const __ΩError = ['name', 'message', 'stack', 'Error', 'P&4!&4"&4#8Mw$y'];
43
+ const __ΩPartial = ['T', 'Partial', 'l+e#!e"!fRb!Pde"!gN#"w"y'];
44
+ const __ΩReadonlyArray = ['T', 'length', 'toString', 'toLocaleString', () => __ΩConcatArray, 'items', 'concat', () => __ΩConcatArray, 'separator', 'join', 'start', 'end', 'slice', 'searchElement', 'fromIndex', 'indexOf', 'lastIndexOf', 'value', 'index', 'array', '', 'predicate', 'thisArg', 'every', 'some', 'callbackfn', 'forEach', 'map', 'filter', 'previousValue', 'currentValue', 'currentIndex', 'reduce', 'initialValue', 'reduceRight', 'ReadonlyArray', 'b!P\'4"9P&1#P&1$Pe#!o%"@2&e#!F1\'PPe$!e$!o("J@2&e#!F1\'P&2)8&1*P\'2+8\'2,8e#!F1-Pe#!2.\'2/8\'10Pe#!2.\'2/8\'11PPe$!22\'23e$!F924!/526"278!18PPe$!22\'23e$!F924#/526"278)18PPe$!22\'23e$!F924#/526"278)19PPe$!22\'23e$!F924$/52:"278$1;PPe$!22\'23e$!F924"/52:"278"F1<PPe$!22\'23e$!F924!/526"278"F1=PPe$!22\'23e$!F924#/526"278e#!F1=PPe$!2>e$!2?\'2@e$!F924e$!/52:e#!1APPe$!2>e$!2?\'2@e$!F924e$!/52:e#!2Be#!1APP"2>e$!2?\'2@e$!F924"/52:"2B"1APPe$!2>e$!2?\'2@e$!F924e$!/52:e#!1CPPe$!2>e$!2?\'2@e$!F924e$!/52:e#!2Be#!1CPP"2>e$!2?\'2@e$!F924"/52:"2B"1C\'e"!LMwDy'];
45
+ const __ΩConcatArray = ['T', 'length', 'separator', 'join', 'start', 'end', 'slice', 'ConcatArray', 'b!P\'4"9\'e"!LP&2#8&1$P\'2%8\'2&8e#!F1\'Mw(y'];
46
+ /*@ts-ignore*/
47
+ const { __ΩTypeAnnotation } = require('@deepkit/core');
48
+ function __assignType(fn, args) {
49
+ fn.__type = args;
50
+ return fn;
51
+ }
2
52
  /*
3
53
  * Deepkit Framework
4
54
  * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
@@ -8,9 +58,12 @@
8
58
  *
9
59
  * You should have received a copy of the MIT License along with this program.
10
60
  */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.HttpRequest = exports.HttpResponse = void 0;
13
61
  const http_1 = require("http");
62
+ const router_js_1 = require("./router.js");
63
+ const querystring = __importStar(require("querystring"));
64
+ const stream_1 = require("stream");
65
+ const type_1 = require("@deepkit/type");
66
+ const core_1 = require("@deepkit/core");
14
67
  class HttpResponse extends http_1.ServerResponse {
15
68
  status(code) {
16
69
  this.writeHead(code);
@@ -18,6 +71,217 @@ class HttpResponse extends http_1.ServerResponse {
18
71
  }
19
72
  }
20
73
  exports.HttpResponse = HttpResponse;
74
+ HttpResponse.__type = [() => http_1.ServerResponse, 'code', 'status', 'HttpResponse', 'P7!P\'2""0#5w$'];
75
+ /**
76
+ * Reads the body of the request and returns it as a Buffer.
77
+ * The result will be cached in the request object as `request.body`.
78
+ *
79
+ * Deepkit's router will automatically use `request.body` if available.
80
+ */
81
+ function readBody(request) {
82
+ return (0, core_1.asyncOperation)(__assignType((resolve, reject) => {
83
+ const chunks = [];
84
+ request.on('data', __assignType((chunk) => {
85
+ chunks.push(chunk);
86
+ }, ['chunk', '', 'P!2!"/"']));
87
+ request.on('end', () => {
88
+ const body = Buffer.concat(chunks);
89
+ //the router uses this now instead of trying to read the body again
90
+ request.body = body;
91
+ resolve(body);
92
+ });
93
+ request.on('error', __assignType((error) => {
94
+ reject(error);
95
+ }, [() => __ΩError, 'error', '', 'Pn!2""/#']));
96
+ }, ['resolve', 'reject', '', 'P"2!"2""/#']));
97
+ }
98
+ readBody.__type = ['request', 'readBody', 'P!2!!`/"'];
99
+ function createRequestWithCachedBody(request, body) {
100
+ var _a;
101
+ const headers = request.headers;
102
+ const method = request.method;
103
+ const url = request.url;
104
+ const writable = new stream_1.Writable({
105
+ write: __assignType(function write(chunk, encoding, callback) {
106
+ callback();
107
+ }, ['chunk', 'encoding', 'callback', 'write', 'P"2!"2""2#"/$']),
108
+ writev: __assignType(function writev(chunks, callback) {
109
+ callback();
110
+ }, ['chunks', 'callback', 'writev', 'P"2!"2""/#'])
111
+ });
112
+ return new (_a = class extends HttpRequest {
113
+ constructor() {
114
+ super(...arguments);
115
+ this.url = url;
116
+ this.method = method;
117
+ this.position = 0;
118
+ this.headers = headers;
119
+ }
120
+ _read(size) {
121
+ if (this.complete) {
122
+ this.push(null);
123
+ }
124
+ else {
125
+ //in Node 18 this seems to be necessary to not trigger the abort event
126
+ this.complete = true;
127
+ this.push(body);
128
+ }
129
+ }
130
+ },
131
+ _a.__type = [() => HttpRequest, 'url', function () { return url; }, 'method', function () { return method; }, 'position', function () { return 0; }, 'headers', function () { return headers; }, 'size', '_read', 'P7!!3">#!3$>%\'3&>\'!3(>)P\'2*"0+5'],
132
+ _a)(writable);
133
+ }
134
+ createRequestWithCachedBody.__type = [() => __ΩPartial, 'request', 'body', () => HttpRequest, 'createRequestWithCachedBody', 'P!o!"2"!2#P7$/%'];
135
+ const __ΩHttpRequestQuery = ['HttpRequestQuery', 'P&&LMw!y'];
136
+ exports.__ΩHttpRequestQuery = __ΩHttpRequestQuery;
137
+ const __ΩHttpRequestResolvedParameters = ['HttpRequestResolvedParameters', 'P&"LMw!y'];
138
+ exports.__ΩHttpRequestResolvedParameters = __ΩHttpRequestResolvedParameters;
139
+ const __ΩHttpRequestPositionedParameters = ['arguments', () => __ΩHttpRequestResolvedParameters, 'parameters', 'HttpRequestPositionedParameters', 'P"F4!n"4#Mw$y'];
140
+ exports.__ΩHttpRequestPositionedParameters = __ΩHttpRequestPositionedParameters;
141
+ class BodyValidationError {
142
+ constructor(errors = []) {
143
+ this.errors = errors;
144
+ }
145
+ hasErrors(prefix) {
146
+ return this.getErrors(prefix).length > 0;
147
+ }
148
+ getErrors(prefix) {
149
+ if (prefix)
150
+ return this.errors.filter(__assignType(v => v.path.startsWith(prefix), ['v', '', 'P"2!"/"']));
151
+ return this.errors;
152
+ }
153
+ getErrorsForPath(path) {
154
+ return this.errors.filter(__assignType(v => v.path === path, ['v', '', 'P"2!"/"']));
155
+ }
156
+ getErrorMessageForPath(path) {
157
+ return this.getErrorsForPath(path).map(__assignType(v => v.toString(), ['v', '', 'P"2!"/"'])).join(', ');
158
+ }
159
+ }
160
+ exports.BodyValidationError = BodyValidationError;
161
+ BodyValidationError.__type = [() => type_1.ValidationErrorItem, 'errors', () => [], 'constructor', 'prefix', 'hasErrors', () => type_1.ValidationErrorItem, 'getErrors', 'path', () => type_1.ValidationErrorItem, 'getErrorsForPath', 'getErrorMessageForPath', 'BodyValidationError', 'PP7!F2":9>#"0$P&2%8)0&P&2%8P7\'F0(P&2)P7*F0+P&2)&0,5w-'];
162
+ class ValidatedBody {
163
+ constructor(error, value) {
164
+ this.error = error;
165
+ this.value = value;
166
+ }
167
+ valid() {
168
+ return this.value !== undefined;
169
+ }
170
+ }
171
+ exports.ValidatedBody = ValidatedBody;
172
+ ValidatedBody.__type = ['T', () => BodyValidationError, 'error', 'value', 'constructor', 'valid', 'ValidatedBody', 'b!PP7"2#:e"!2$8:"0%P!0&5w\''];
173
+ const __ΩHttpBody = ['T', () => __ΩTypeAnnotation, "httpBody", 'HttpBody', 'b!Pe"!.#o""Kw$y'];
174
+ exports.__ΩHttpBody = __ΩHttpBody;
175
+ const __ΩHttpBodyValidation = ['T', () => ValidatedBody, () => __ΩTypeAnnotation, "httpBodyValidation", 'HttpBodyValidation', 'b!PPe#!7".$o#"Kw%y'];
176
+ exports.__ΩHttpBodyValidation = __ΩHttpBodyValidation;
177
+ const __ΩHttpRequestParserOptions = ['withPath', 'withBody', 'withQuery', 'withHeader', 'HttpRequestParserOptions', 'P)4!8)4"8)4#8)4$8Mw%y'];
178
+ exports.__ΩHttpRequestParserOptions = __ΩHttpRequestParserOptions;
179
+ const __ΩHttpRequestParser = ['T', () => __ΩHttpRequestParserOptions, 'options', '', () => __ΩTypeAnnotation, "httpRequestParser", 'HttpRequestParser', 'b!PPn"2#8e#!`/$.&e"!o%#Kw\'y'];
180
+ exports.__ΩHttpRequestParser = __ΩHttpRequestParser;
181
+ const __ΩHttpPath = ['T', 'Options', () => __ΩTypeAnnotation, "httpPath", 'HttpPath', 'b!PMc"Pe"!.$e""o##Kw%y'];
182
+ exports.__ΩHttpPath = __ΩHttpPath;
183
+ const __ΩHttpHeader = ['T', 'Options', () => __ΩTypeAnnotation, "httpHeader", 'HttpHeader', 'b!PMc"Pe"!.$e""o##Kw%y'];
184
+ exports.__ΩHttpHeader = __ΩHttpHeader;
185
+ const __ΩHttpQuery = ['T', 'Options', () => __ΩTypeAnnotation, "httpQuery", 'HttpQuery', 'b!PMc"Pe"!.$e""o##Kw%y'];
186
+ exports.__ΩHttpQuery = __ΩHttpQuery;
187
+ const __ΩHttpQueries = ['T', 'Options', () => __ΩTypeAnnotation, "httpQueries", 'HttpQueries', 'b!PMc"Pe"!.$e""o##Kw%y'];
188
+ exports.__ΩHttpQueries = __ΩHttpQueries;
189
+ const __ΩHttpRegExp = ['T', 'Pattern', () => __ΩTypeAnnotation, "httpRegExp", 'HttpRegExp', 'b!b"Pe"!.$e""o##Kw%y'];
190
+ exports.__ΩHttpRegExp = __ΩHttpRegExp;
191
+ function getRegExp(type) {
192
+ const options = type_1.typeAnnotation.getType(type, 'httpRegExp');
193
+ if (!options)
194
+ return;
195
+ if (options.kind === type_1.ReflectionKind.literal && 'string' === typeof options.literal)
196
+ return options.literal;
197
+ if (options.kind === type_1.ReflectionKind.literal && options.literal instanceof RegExp)
198
+ return options.literal;
199
+ return;
200
+ }
201
+ getRegExp.__type = ['Type', 'type', 'getRegExp', 'P"w!2"P&A-J/#'];
202
+ class RequestBuilder {
203
+ constructor(path, method = 'GET') {
204
+ this.path = path;
205
+ this.method = method;
206
+ this.contentBuffer = Buffer.alloc(0);
207
+ this._headers = {};
208
+ }
209
+ getUrl() {
210
+ if (this.queryPath) {
211
+ return this.path + '?' + this.queryPath;
212
+ }
213
+ return this.path;
214
+ }
215
+ build() {
216
+ return createRequestWithCachedBody({
217
+ method: this.method,
218
+ url: this.getUrl(),
219
+ headers: this._headers,
220
+ }, this.contentBuffer);
221
+ }
222
+ headers(headers) {
223
+ this._headers = headers;
224
+ return this;
225
+ }
226
+ header(name, value) {
227
+ this._headers[name] = String(value);
228
+ return this;
229
+ }
230
+ json(body) {
231
+ this.contentBuffer = Buffer.from(JSON.stringify(body), 'utf8');
232
+ this._headers['content-type'] = 'application/json; charset=utf-8';
233
+ this._headers['content-length'] = String(this.contentBuffer.byteLength);
234
+ return this;
235
+ }
236
+ multiPart(items) {
237
+ const boundary = '--------------------------' + Math.random().toString(36).substr(2, 10);
238
+ this._headers['content-type'] = 'multipart/form-data; boundary=' + boundary;
239
+ const parts = items.map(__assignType(item => {
240
+ if (item.file) {
241
+ const header = Buffer.from(`--${boundary}\r
242
+ Content-Disposition: form-data; name="${item.name}"; filename="${item.fileName || 'file'}"\r
243
+ Content-Type: application/octet-stream\r
244
+ \r\n`, 'utf8');
245
+ return Buffer.concat([header, item.file, Buffer.from('\r\n', 'utf8')]);
246
+ }
247
+ else if (item.json) {
248
+ const header = Buffer.from(`--${boundary}\r
249
+ Content-Disposition: form-data; name="${item.name}"\r
250
+ Content-Type: application/json\r
251
+ \r\n`, 'utf8');
252
+ return Buffer.concat([header, Buffer.from(JSON.stringify(item.json) + '\r\n', 'utf8')]);
253
+ }
254
+ else {
255
+ throw new Error('Invalid multiPart item');
256
+ }
257
+ }, ['item', '', 'P"2!"/"']));
258
+ parts.push(Buffer.from(`--${boundary}--`, 'utf8'));
259
+ this.contentBuffer = Buffer.concat(parts);
260
+ this._headers['content-length'] = String(this.contentBuffer.byteLength);
261
+ return this;
262
+ }
263
+ body(body) {
264
+ if ('string' === typeof body) {
265
+ this.contentBuffer = Buffer.from(body, 'utf8');
266
+ }
267
+ else {
268
+ this.contentBuffer = body;
269
+ }
270
+ this._headers['content-length'] = String(this.contentBuffer.byteLength);
271
+ return this;
272
+ }
273
+ query(query) {
274
+ if ('string' === typeof query) {
275
+ this.queryPath = query;
276
+ }
277
+ else {
278
+ this.queryPath = querystring.stringify(query);
279
+ }
280
+ return this;
281
+ }
282
+ }
283
+ exports.RequestBuilder = RequestBuilder;
284
+ RequestBuilder.__type = ['contentBuffer', function () { return Buffer.alloc(0); }, '_headers', function () { return {}; }, 'queryPath', 'path', 'method', () => "GET", 'constructor', 'getUrl', () => HttpRequest, 'build', 'headers', 'name', 'value', 'header', 'body', 'json', 'file', 'fileName', 'items', 'multiPart', 'query', 'RequestBuilder', '!3!<>"P&&LM3#<>$&3%8<P&2&<&2\'<>("0)P"0*PP7+0,PP&&LM2-!0-P&2.P&\'J2/!00P%21!02PP&4.W438&448"428MF25!06PP&!J21!01PP"&J27!075w8'];
21
285
  class HttpRequest extends http_1.IncomingMessage {
22
286
  constructor() {
23
287
  super(...arguments);
@@ -25,6 +289,40 @@ class HttpRequest extends http_1.IncomingMessage {
25
289
  * A store that can be used to transport data from guards/listeners to ParameterResolvers/controllers.
26
290
  */
27
291
  this.store = {};
292
+ this.uploadedFiles = {};
293
+ this.throwErrorOnNotFound = false;
294
+ }
295
+ async readBody() {
296
+ if (this.body)
297
+ return this.body;
298
+ return await readBody(this);
299
+ }
300
+ async readBodyText() {
301
+ return (await this.readBody()).toString('utf8');
302
+ }
303
+ static GET(path) {
304
+ return new RequestBuilder(path);
305
+ }
306
+ static POST(path) {
307
+ return new RequestBuilder(path, 'POST');
308
+ }
309
+ static OPTIONS(path) {
310
+ return new RequestBuilder(path, 'OPTIONS');
311
+ }
312
+ static TRACE(path) {
313
+ return new RequestBuilder(path, 'TRACE');
314
+ }
315
+ static HEAD(path) {
316
+ return new RequestBuilder(path, 'HEAD');
317
+ }
318
+ static PATCH(path) {
319
+ return new RequestBuilder(path, 'PATCH');
320
+ }
321
+ static PUT(path) {
322
+ return new RequestBuilder(path, 'PUT');
323
+ }
324
+ static DELETE(path) {
325
+ return new RequestBuilder(path, 'DELETE');
28
326
  }
29
327
  getUrl() {
30
328
  return this.url || '/';
@@ -33,8 +331,108 @@ class HttpRequest extends http_1.IncomingMessage {
33
331
  return this.method || 'GET';
34
332
  }
35
333
  getRemoteAddress() {
36
- return this.connection.remoteAddress || '';
334
+ return this.socket.remoteAddress || '';
37
335
  }
38
336
  }
39
337
  exports.HttpRequest = HttpRequest;
338
+ HttpRequest.__type = [() => http_1.IncomingMessage, 'store', function () { return {}; }, () => router_js_1.UploadedFile, 'uploadedFiles', function () { return {}; }, 'throwErrorOnNotFound', function () { return false; }, 'body', 'readBody', 'readBodyText', 'path', () => RequestBuilder, 'GET', () => RequestBuilder, 'POST', () => RequestBuilder, 'OPTIONS', () => RequestBuilder, 'TRACE', () => RequestBuilder, 'HEAD', () => RequestBuilder, 'PATCH', () => RequestBuilder, 'PUT', () => RequestBuilder, 'DELETE', 'getUrl', 'getMethod', 'getRemoteAddress', 'HttpRequest', 'P7!P&"LM3">#P&P7$LM3%>&)3\'>(!3)8P!`0*P&`0+P&2,P7-0.sP&2,P7/00sP&2,P7102sP&2,P7304sP&2,P7506sP&2,P7708sP&2,P790:sP&2,P7;0<sP&0=P&0>P&0?5w@'];
339
+ function incomingMessageToHttpRequest(request) {
340
+ if (request instanceof HttpRequest)
341
+ return request;
342
+ Object.setPrototypeOf(request, HttpRequest.prototype);
343
+ HttpRequest.constructor.call(request);
344
+ return request;
345
+ }
346
+ incomingMessageToHttpRequest.__type = ['request', () => HttpRequest, 'incomingMessageToHttpRequest', 'P!2!P7"/#'];
347
+ function serverResponseToHttpResponse(response) {
348
+ if (response instanceof HttpResponse)
349
+ return response;
350
+ Object.setPrototypeOf(response, HttpResponse.prototype);
351
+ MemoryHttpResponse.constructor.call(response);
352
+ return response;
353
+ }
354
+ serverResponseToHttpResponse.__type = ['response', () => HttpResponse, 'serverResponseToHttpResponse', 'P!2!P7"/#'];
355
+ class MemoryHttpResponse extends HttpResponse {
356
+ constructor() {
357
+ super(...arguments);
358
+ this.body = Buffer.alloc(0);
359
+ this.headers = Object.create(null);
360
+ }
361
+ setHeader(name, value) {
362
+ this.headers[name] = value;
363
+ super.setHeader(name, value);
364
+ return this;
365
+ }
366
+ removeHeader(name) {
367
+ delete this.headers[name];
368
+ super.removeHeader(name);
369
+ }
370
+ getHeader(name) {
371
+ return this.headers[name];
372
+ }
373
+ getHeaders() {
374
+ return this.headers;
375
+ }
376
+ writeHead(statusCode, headersOrReasonPhrase, headers) {
377
+ headers = typeof headersOrReasonPhrase === 'string' ? headers : headersOrReasonPhrase;
378
+ if (headers && !(0, core_1.isArray)(headers))
379
+ this.headers = headers;
380
+ if (typeof headersOrReasonPhrase === 'string')
381
+ return super.writeHead(statusCode, headersOrReasonPhrase, headers);
382
+ return super.writeHead(statusCode, headers);
383
+ }
384
+ get json() {
385
+ const json = this.bodyString;
386
+ try {
387
+ return JSON.parse(json);
388
+ }
389
+ catch (error) {
390
+ throw new Error(`Could not parse JSON: ${error.message}, body: ${json}`);
391
+ }
392
+ }
393
+ get text() {
394
+ return this.bodyString;
395
+ }
396
+ get bodyString() {
397
+ return this.body.toString('utf8');
398
+ }
399
+ write(chunk, encoding, callback) {
400
+ if (typeof encoding === 'function') {
401
+ callback = encoding;
402
+ encoding = null;
403
+ }
404
+ if (chunk) {
405
+ if ('string' === typeof chunk) {
406
+ chunk = Buffer.from(chunk, encoding || 'utf8');
407
+ }
408
+ this.body = Buffer.concat([this.body, chunk]);
409
+ }
410
+ if (callback)
411
+ callback();
412
+ return true;
413
+ }
414
+ end(chunk, encoding, callback) {
415
+ if (typeof chunk === 'function') {
416
+ callback = chunk;
417
+ chunk = null;
418
+ encoding = null;
419
+ }
420
+ else if (typeof encoding === 'function') {
421
+ callback = encoding;
422
+ encoding = null;
423
+ }
424
+ if (chunk) {
425
+ if ('string' === typeof chunk) {
426
+ chunk = Buffer.from(chunk, encoding || 'utf8');
427
+ }
428
+ this.body = Buffer.concat([this.body, chunk]);
429
+ }
430
+ this.emit('finish');
431
+ super.end(chunk, encoding, callback);
432
+ this.emit('close');
433
+ return this;
434
+ }
435
+ }
436
+ exports.MemoryHttpResponse = MemoryHttpResponse;
437
+ MemoryHttpResponse.__type = [() => HttpResponse, 'body', function () { return Buffer.alloc(0); }, 'headers', function () { return Object.create(null); }, 'name', () => __ΩReadonlyArray, 'value', 'setHeader', 'removeHeader', 'getHeader', 'getHeaders', 'statusCode', 'headersOrReasonPhrase', 'writeHead', 'chunk', 'encoding', 'callback', 'write', 'end', 'MemoryHttpResponse', 'P7!!3">#P&P\'&&F-JLM3$>%P&2&P\'&&o\'"J2(!0)P&2&"0*P&2&"0+P!0,P\'2-P&!!FJ2.8P!!FJ2$8!0/!!!P"20"21"228"03P"20"218"228"045w5'];
40
438
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/model.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,+BAAuD;AAEvD,MAAa,YAAa,SAAQ,qBAAc;IAC5C,MAAM,CAAC,IAAY;QACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,EAAE,CAAC;IACf,CAAC;CACJ;AALD,oCAKC;AAKD,MAAa,WAAY,SAAQ,sBAAe;IAAhD;;QACI;;WAEG;QACI,UAAK,GAA0B,EAAE,CAAC;IAa7C,CAAC;IAXG,MAAM;QACF,OAAO,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC;IAC3B,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;IAChC,CAAC;IAED,gBAAg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deepkit/app';
2
- export declare const config: AppModuleConfig<{
3
- debug: import("@deepkit/type").FieldDecoratorResult<boolean>;
4
- }>;
1
+ export interface HttpParserOptions {
2
+ /**
3
+ * sets encoding for incoming form fields
4
+ *
5
+ * @default 'utf-8'
6
+ */
7
+ encoding?: string | undefined;
8
+ /**
9
+ * the directory for placing file uploads in. You can move them later by using fs.rename()
10
+ *
11
+ * @default os.tmpdir()
12
+ */
13
+ uploadDir?: string | undefined;
14
+ /**
15
+ * to include the extensions of the original files or not
16
+ *
17
+ * @default false
18
+ */
19
+ keepExtensions?: boolean | undefined;
20
+ /**
21
+ * allow upload empty files
22
+ *
23
+ * @default true
24
+ */
25
+ allowEmptyFiles?: boolean | undefined;
26
+ /**
27
+ * the minium size of uploaded file
28
+ *
29
+ * @default 1
30
+ */
31
+ minFileSize?: number | undefined;
32
+ /**
33
+ * limit the amount of uploaded files, set Infinity for unlimited
34
+ *
35
+ * @default Infinity
36
+ */
37
+ maxFiles?: number | undefined;
38
+ /**
39
+ * limit the size of uploaded file
40
+ *
41
+ * @default 200 * 1024 * 1024
42
+ */
43
+ maxFileSize?: number | undefined;
44
+ /**
45
+ * limit the size of the batch of uploaded files
46
+ *
47
+ * @default options.maxFileSize
48
+ */
49
+ maxTotalFileSize?: number | undefined;
50
+ /**
51
+ * limit the number of fields, set 0 for unlimited
52
+ *
53
+ * @default 1000
54
+ */
55
+ maxFields?: number | undefined;
56
+ /**
57
+ * limit the amount of memory all fields together (except files) can allocate in bytes
58
+ *
59
+ * @default 20 * 1024 * 1024
60
+ */
61
+ maxFieldsSize?: number | undefined;
62
+ /**
63
+ * include checksums calculated for incoming files, set this to some hash algorithm, see
64
+ * crypto.createHash for available algorithms
65
+ *
66
+ * @default false
67
+ */
68
+ hashAlgorithm?: string | false | undefined;
69
+ /**
70
+ * when you call the .parse method, the files argument (of the callback) will contain arrays of
71
+ * files for inputs which submit multiple files using the HTML5 multiple attribute. Also, the
72
+ * fields argument will contain arrays of values for fields that have names ending with '[]'
73
+ *
74
+ * @default false
75
+ */
76
+ multiples?: boolean | undefined;
77
+ enabledPlugins?: string[] | undefined;
78
+ }
79
+ export declare class HttpConfig {
80
+ debug: boolean;
81
+ parser: HttpParserOptions;
82
+ /**
83
+ * Limits maximum incoming headers count. If set to 0, no limit will be applied.
84
+ */
85
+ maxHeadersCount?: number;
86
+ /**
87
+ * The maximum number of requests socket can handle
88
+ * before closing keep alive connection.
89
+ *
90
+ * A value of `0` will disable the limit.
91
+ *
92
+ * When the limit is reached it will set the `Connection` header value to `close`,
93
+ * but will not actually close the connection, subsequent requests sent
94
+ * after the limit is reached will get `503 Service Unavailable` as a response.
95
+ */
96
+ maxRequestsPerSocket?: number;
97
+ /**
98
+ * The number of milliseconds of inactivity before a socket is presumed
99
+ * to have timed out.
100
+ *
101
+ * A value of `0` will disable the timeout behavior on incoming connections.
102
+ *
103
+ * The socket timeout logic is set up on connection, so changing this
104
+ * value only affects new connections to the server, not any existing connections.
105
+ */
106
+ timeout?: number;
107
+ /**
108
+ * Limit the amount of time the parser will wait to receive the complete HTTP
109
+ * headers.
110
+ *
111
+ * If the timeout expires, the server responds with status 408 without
112
+ * forwarding the request to the request listener and then closes the connection.
113
+ *
114
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
115
+ * potential Denial-of-Service attacks in case the server is deployed without a
116
+ * reverse proxy in front.
117
+ */
118
+ headersTimeout?: number;
119
+ /**
120
+ * The number of milliseconds of inactivity a server needs to wait for additional
121
+ * incoming data, after it has finished writing the last response, before a socket
122
+ * will be destroyed. If the server receives new data before the keep-alive
123
+ * timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`.
124
+ *
125
+ * A value of `0` will disable the keep-alive timeout behavior on incoming
126
+ * connections.
127
+ * A value of `0` makes the http server behave similarly to Node.js versions prior
128
+ * to 8.0.0, which did not have a keep-alive timeout.
129
+ *
130
+ * The socket timeout logic is set up on connection, so changing this value only
131
+ * affects new connections to the server, not any existing connections.
132
+ */
133
+ keepAliveTimeout?: number;
134
+ /**
135
+ * Sets the timeout value in milliseconds for receiving the entire request from
136
+ * the client.
137
+ *
138
+ * If the timeout expires, the server responds with status 408 without
139
+ * forwarding the request to the request listener and then closes the connection.
140
+ *
141
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
142
+ * potential Denial-of-Service attacks in case the server is deployed without a
143
+ * reverse proxy in front.
144
+ *
145
+ * Default is 5 minutes.
146
+ */
147
+ requestTimeout?: number;
148
+ }
149
+ export declare type __ΩHttpParserOptions = any[];
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.config = void 0;
4
- const type_1 = require("@deepkit/type");
5
- const app_1 = require("@deepkit/app");
6
- exports.config = new app_1.AppModuleConfig({
7
- debug: type_1.t.boolean.default(false)
8
- });
3
+ exports.HttpConfig = exports.__ΩHttpParserOptions = void 0;
4
+ const __ΩHttpParserOptions = ['encoding', 'uploadDir', 'keepExtensions', 'allowEmptyFiles', 'minFileSize', 'maxFiles', 'maxFileSize', 'maxTotalFileSize', 'maxFields', 'maxFieldsSize', false, 'hashAlgorithm', 'multiples', 'enabledPlugins', 'HttpParserOptions', 'PP&-J4!8P&-J4"8P)-J4#8P)-J4$8P\'-J4%8P\'-J4&8P\'-J4\'8P\'-J4(8P\'-J4)8P\'-J4*8P&.+-J4,8P)-J4-8P&F-J4.8Mw/y'];
5
+ exports.__ΩHttpParserOptions = __ΩHttpParserOptions;
6
+ class HttpConfig {
7
+ constructor() {
8
+ this.debug = false;
9
+ this.parser = {};
10
+ }
11
+ }
12
+ exports.HttpConfig = HttpConfig;
13
+ HttpConfig.__type = ['debug', function () { return false; }, () => __ΩHttpParserOptions, 'parser', function () { return {}; }, 'maxHeadersCount', 'maxRequestsPerSocket', 'timeout', 'headersTimeout', 'keepAliveTimeout', 'requestTimeout', 'HttpConfig', ')3!>"n#3$>%\'3&8\'3\'8\'3(8\'3)8\'3*8\'3+85w,'];
9
14
  //# sourceMappingURL=module.config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"module.config.js","sourceRoot":"","sources":["../../../src/module.config.ts"],"names":[],"mappings":";;;AAAA,wCAAkC;AAClC,sCAA+C;AAElC,QAAA,MAAM,GAAG,IAAI,qBAAe,CAAC;IACtC,KAAK,EAAE,QAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;CAClC,CAAC,CAAC"}
1
+ {"version":3,"file":"module.config.js","sourceRoot":"","sources":["../../../src/module.config.ts"],"names":[],"mappings":";;;;;AA2FA,MAAa,UAAU;IAAvB;QAEI,UAAK,GAAY,KAAK,CAAC;QAEvB,WAAM,GAAsB,EAAE,CAAC;KAyElC;;AA7ED,gCA6EC;mDA3EoB,KAAK,gEAEM,EAAE"}