@moostjs/event-http 0.5.29 → 0.5.31

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.
package/dist/index.cjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  //#region rolldown:runtime
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -47,7 +46,11 @@ const Patch = (path) => HttpMethod("PATCH", path);
47
46
 
48
47
  //#endregion
49
48
  //#region packages/event-http/src/decorators/resolve.decorator.ts
50
- const StatusHook = () => (0, moost.Resolve)((metas, level) => {
49
+ /**
50
+ * Hook to the Response Status
51
+ * @decorator
52
+ * @paramType TStatusHook
53
+ */ const StatusHook = () => (0, moost.Resolve)((metas, level) => {
51
54
  const hook = (0, __wooksjs_event_http.useStatus)();
52
55
  if (level === "PARAM") return hook;
53
56
  if (level === "PROP" && metas.instance && metas.key) {
@@ -59,7 +62,12 @@ const StatusHook = () => (0, moost.Resolve)((metas, level) => {
59
62
  return typeof initialValue === "number" ? initialValue : 200;
60
63
  }
61
64
  }, "statusCode");
62
- const HeaderHook = (name) => (0, moost.Resolve)((metas, level) => {
65
+ /**
66
+ * Hook to the Response Header
67
+ * @decorator
68
+ * @param name - header name
69
+ * @paramType THeaderHook
70
+ */ const HeaderHook = (name) => (0, moost.Resolve)((metas, level) => {
63
71
  const hook = (0, __wooksjs_event_http.useSetHeader)(name);
64
72
  if (level === "PARAM") return hook;
65
73
  if (level === "PROP" && metas.instance && metas.key) {
@@ -71,7 +79,12 @@ const HeaderHook = (name) => (0, moost.Resolve)((metas, level) => {
71
79
  return typeof initialValue === "string" ? initialValue : "";
72
80
  }
73
81
  }, name);
74
- const CookieHook = (name) => (0, moost.Resolve)((metas, level) => {
82
+ /**
83
+ * Hook to the Response Cookie
84
+ * @decorator
85
+ * @param name - cookie name
86
+ * @paramType TCookieHook
87
+ */ const CookieHook = (name) => (0, moost.Resolve)((metas, level) => {
75
88
  const hook = (0, __wooksjs_event_http.useSetCookie)(name);
76
89
  if (level === "PARAM") return hook;
77
90
  if (level === "PROP" && metas.instance && metas.key) {
@@ -83,7 +96,12 @@ const CookieHook = (name) => (0, moost.Resolve)((metas, level) => {
83
96
  return typeof initialValue === "string" ? initialValue : "";
84
97
  }
85
98
  }, name);
86
- const CookieAttrsHook = (name) => (0, moost.Resolve)((metas, level) => {
99
+ /**
100
+ * Hook to the Response Cookie Attributes
101
+ * @decorator
102
+ * @param name - cookie name
103
+ * @paramType TCookieAttributes
104
+ */ const CookieAttrsHook = (name) => (0, moost.Resolve)((metas, level) => {
87
105
  const hook = (0, __wooksjs_event_http.useSetCookie)(name);
88
106
  if (level === "PARAM") return (0, __wooksjs_event_core.attachHook)({}, {
89
107
  get: () => hook.attrs,
@@ -98,28 +116,49 @@ const CookieAttrsHook = (name) => (0, moost.Resolve)((metas, level) => {
98
116
  return typeof initialValue === "object" ? initialValue : {};
99
117
  }
100
118
  }, name);
101
- function Authorization(name) {
119
+ /**
120
+ * Parse Authorisation Header
121
+ * @decorator
122
+ * @param name - define what to take from the Auth header
123
+ * @paramType string
124
+ */ function Authorization(name) {
102
125
  return (0, moost.Resolve)(() => {
103
126
  const auth = (0, __wooksjs_event_http.useAuthorization)();
104
127
  switch (name) {
105
- case "username": return auth.isBasic() ? auth.basicCredentials()?.username : undefined;
106
- case "password": return auth.isBasic() ? auth.basicCredentials()?.password : undefined;
107
- case "bearer": return auth.isBearer() ? auth.authorization : undefined;
128
+ case "username": return auth.isBasic() ? auth.basicCredentials()?.username : void 0;
129
+ case "password": return auth.isBasic() ? auth.basicCredentials()?.password : void 0;
130
+ case "bearer": return auth.isBearer() ? auth.authorization : void 0;
108
131
  case "raw": return auth.authRawCredentials();
109
132
  case "type": return auth.authType();
133
+ default: return void 0;
110
134
  }
111
135
  }, "authorization");
112
136
  }
113
- function Header(name) {
137
+ /**
138
+ * Get Request Header Value
139
+ * @decorator
140
+ * @param name - header name
141
+ * @paramType string
142
+ */ function Header(name) {
114
143
  return (0, moost.Resolve)(() => {
115
144
  const headers = (0, __wooksjs_event_http.useHeaders)();
116
145
  return headers[name];
117
146
  }, `header: ${name}`);
118
147
  }
119
- function Cookie(name) {
148
+ /**
149
+ * Get Request Cookie Value
150
+ * @decorator
151
+ * @param name - cookie name
152
+ * @paramType string
153
+ */ function Cookie(name) {
120
154
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useCookies)().getCookie(name), `cookie: ${name}`);
121
155
  }
122
- function Query(name) {
156
+ /**
157
+ * Get Query Item value or the whole parsed Query as an object
158
+ * @decorator
159
+ * @param name - query item name (optional)
160
+ * @paramType string | object
161
+ */ function Query(name) {
123
162
  const isItem = !!name;
124
163
  const _name = isItem ? name : "Query";
125
164
  return (0, moost.getMoostMate)().apply((0, moost.getMoostMate)().decorate("paramSource", isItem ? "QUERY_ITEM" : "QUERY"), (0, moost.getMoostMate)().decorate("paramName", _name), (0, moost.Resolve)(() => {
@@ -127,37 +166,74 @@ function Query(name) {
127
166
  if (isItem) {
128
167
  const p = urlSearchParams();
129
168
  const value = p.get(name);
130
- return value === null ? undefined : value;
169
+ return value === null ? void 0 : value;
131
170
  }
132
171
  const json = jsonSearchParams();
133
- return Object.keys(json).length > 0 ? json : undefined;
172
+ return Object.keys(json).length > 0 ? json : void 0;
134
173
  }, _name));
135
174
  }
136
- function Url() {
175
+ /**
176
+ * Get Requested URL
177
+ * @decorator
178
+ * @paramType string
179
+ */ function Url() {
137
180
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().url || "", "url");
138
181
  }
139
- function Method() {
182
+ /**
183
+ * Get Requested HTTP Method
184
+ * @decorator
185
+ * @paramType string
186
+ */ function Method() {
140
187
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().method, "http_method");
141
188
  }
142
- function Req() {
189
+ /**
190
+ * Get Raw Request Instance
191
+ * @decorator
192
+ * @paramType IncomingMessage
193
+ */ function Req() {
143
194
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().rawRequest, "request");
144
195
  }
145
- function Res(opts) {
196
+ /**
197
+ * Get Raw Response Instance
198
+ * @decorator
199
+ * @param opts (optional) { passthrough: boolean }
200
+ * @paramType ServerResponse
201
+ */ function Res(opts) {
146
202
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useResponse)().rawResponse(opts), "response");
147
203
  }
148
- function ReqId() {
204
+ /**
205
+ * Get Request Unique Identificator (UUID)
206
+ * @decorator
207
+ * @paramType string
208
+ */ function ReqId() {
149
209
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().reqId(), "reqId");
150
210
  }
151
- function Ip(opts) {
211
+ /**
212
+ * Get Request IP Address
213
+ * @decorator
214
+ * @paramType string
215
+ */ function Ip(opts) {
152
216
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().getIp(opts), "ip");
153
217
  }
154
- function IpList() {
218
+ /**
219
+ * Get Request IP Address list
220
+ * @decorator
221
+ * @paramType string[]
222
+ */ function IpList() {
155
223
  return (0, moost.Resolve)(() => (0, __wooksjs_event_http.useRequest)().getIpList(), "ipList");
156
224
  }
157
- function Body() {
225
+ /**
226
+ * Get Parsed Request Body
227
+ * @decorator
228
+ * @paramType object | string | unknown
229
+ */ function Body() {
158
230
  return (0, moost.getMoostMate)().apply((0, moost.getMoostMate)().decorate("paramSource", "BODY"), (0, moost.Resolve)(() => (0, __wooksjs_http_body.useBody)().parseBody(), "body"));
159
231
  }
160
- function RawBody() {
232
+ /**
233
+ * Get Raw Request Body Buffer
234
+ * @decorator
235
+ * @paramType Promise<Buffer>
236
+ */ function RawBody() {
161
237
  return (0, moost.Resolve)(() => (0, __wooksjs_http_body.useBody)().rawBody(), "body");
162
238
  }
163
239
 
@@ -176,7 +252,43 @@ const setHeaderInterceptor = (name, value, opts) => {
176
252
  fn.priority = moost.TInterceptorPriority.AFTER_ALL;
177
253
  return fn;
178
254
  };
179
- function SetHeader(...args) {
255
+ /**
256
+ * Set Header for Request Handler
257
+ *
258
+ * ```ts
259
+ * import { Get, SetHeader } from '@moostjs/event-http';
260
+ * import { Controller } from 'moost';
261
+ *
262
+ * @Controller()
263
+ * export class ExampleController {
264
+ * @Get('test')
265
+ * // setting header for request handler
266
+ * @SetHeader('x-server', 'my-server')
267
+ * testHandler() {
268
+ * return '...'
269
+ * }
270
+ * }
271
+ * ```
272
+ *
273
+ * ```ts
274
+ * import { Get, SetHeader } from '@moostjs/event-http';
275
+ * import { Controller } from 'moost';
276
+ *
277
+ * @Controller()
278
+ * export class ExampleController {
279
+ * @Get('test')
280
+ * // setting header only if status = 400
281
+ * @SetHeader('content-type', 'text/plain', { status: 400 })
282
+ * testHandler() {
283
+ * return '...'
284
+ * }
285
+ * }
286
+ * ```
287
+ *
288
+ * @param name name of header
289
+ * @param value value for header
290
+ * @param options options { status?: number, force?: boolean }
291
+ */ function SetHeader(...args) {
180
292
  return (0, moost.Intercept)(setHeaderInterceptor(...args));
181
293
  }
182
294
  const setCookieInterceptor = (name, value, attrs) => {
@@ -189,7 +301,27 @@ const setCookieInterceptor = (name, value, attrs) => {
189
301
  fn.priority = moost.TInterceptorPriority.AFTER_ALL;
190
302
  return fn;
191
303
  };
192
- function SetCookie(...args) {
304
+ /**
305
+ * Set Cookie for Request Handler
306
+ * ```ts
307
+ * import { Get, SetCookie } from '@moostjs/event-http';
308
+ * import { Controller } from 'moost';
309
+ *
310
+ * @Controller()
311
+ * export class ExampleController {
312
+ * @Get('test')
313
+ * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
314
+ * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
315
+ * testHandler() {
316
+ * return '...'
317
+ * }
318
+ * }
319
+ * ```
320
+ *
321
+ * @param name name of cookie
322
+ * @param value value for cookie
323
+ * @param attrs cookie attributes
324
+ */ function SetCookie(...args) {
193
325
  return (0, moost.Intercept)(setCookieInterceptor(...args));
194
326
  }
195
327
  const setStatusInterceptor = (code, opts) => (0, moost.defineInterceptorFn)((before, after) => {
@@ -198,24 +330,69 @@ const setStatusInterceptor = (code, opts) => (0, moost.defineInterceptorFn)((bef
198
330
  if (!status.isDefined || opts?.force) status.value = code;
199
331
  });
200
332
  });
201
- function SetStatus(...args) {
333
+ /**
334
+ * Set Response Status for Request Handler
335
+ *
336
+ * ```ts
337
+ * import { Get, SetStatus } from '@moostjs/event-http';
338
+ * import { Controller } from 'moost';
339
+ *
340
+ * @Controller()
341
+ * export class ExampleController {
342
+ * @Get('test')
343
+ * @SetStatus(201)
344
+ * testHandler() {
345
+ * return '...'
346
+ * }
347
+ * }
348
+ * ```
349
+ * @param code number
350
+ * @param opts optional { force?: boolean }
351
+ */ function SetStatus(...args) {
202
352
  return (0, moost.Intercept)(setStatusInterceptor(...args));
203
353
  }
204
354
 
205
355
  //#endregion
206
356
  //#region packages/event-http/src/decorators/limits.decorator.ts
207
- const globalBodySizeLimit = (n) => (0, moost.defineInterceptorFn)(() => {
357
+ /**
358
+ * Creates an interceptor that sets the maximum allowed inflated body size in bytes.
359
+ *
360
+ * @param n - Maximum body size in bytes after decompression.
361
+ * @returns Interceptor function to enforce the limit.
362
+ */ const globalBodySizeLimit = (n) => (0, moost.defineInterceptorFn)(() => {
208
363
  (0, __wooksjs_event_http.useRequest)().setMaxInflated(n);
209
364
  }, moost.TInterceptorPriority.BEFORE_ALL);
210
- const globalCompressedBodySizeLimit = (n) => (0, moost.defineInterceptorFn)(() => {
365
+ /**
366
+ * Creates an interceptor that sets the maximum allowed compressed body size in bytes.
367
+ *
368
+ * @param n - Maximum body size in bytes before decompression.
369
+ * @returns Interceptor function to enforce the limit.
370
+ */ const globalCompressedBodySizeLimit = (n) => (0, moost.defineInterceptorFn)(() => {
211
371
  (0, __wooksjs_event_http.useRequest)().setMaxCompressed(n);
212
372
  }, moost.TInterceptorPriority.BEFORE_ALL);
213
- const globalBodyReadTimeoutMs = (n) => (0, moost.defineInterceptorFn)(() => {
373
+ /**
374
+ * Creates an interceptor that sets the timeout for reading the request body.
375
+ *
376
+ * @param n - Timeout in milliseconds.
377
+ * @returns Interceptor function to enforce the timeout.
378
+ */ const globalBodyReadTimeoutMs = (n) => (0, moost.defineInterceptorFn)(() => {
214
379
  (0, __wooksjs_event_http.useRequest)().setReadTimeoutMs(n);
215
380
  }, moost.TInterceptorPriority.BEFORE_ALL);
216
- const BodySizeLimit = (n) => (0, moost.Intercept)(globalBodySizeLimit(n));
217
- const CompressedBodySizeLimit = (n) => (0, moost.Intercept)(globalCompressedBodySizeLimit(n));
218
- const BodyReadTimeoutMs = (n) => (0, moost.Intercept)(globalBodyReadTimeoutMs(n));
381
+ /**
382
+ * Decorator to limit the maximum inflated body size for the request. Default: 10 MB
383
+ *
384
+ * @param n - Maximum body size in bytes after decompression.
385
+ */ const BodySizeLimit = (n) => (0, moost.Intercept)(globalBodySizeLimit(n));
386
+ /**
387
+ * Decorator to limit the maximum compressed body size for the request. Default: 1 MB
388
+ *
389
+ * @param n - Maximum body size in bytes before decompression.
390
+ */ const CompressedBodySizeLimit = (n) => (0, moost.Intercept)(globalCompressedBodySizeLimit(n));
391
+ /**
392
+ * Decorator to set a timeout (in milliseconds) for reading the request body. Default: 10 s
393
+ *
394
+ * @param n - Timeout duration in milliseconds.
395
+ */ const BodyReadTimeoutMs = (n) => (0, moost.Intercept)(globalBodyReadTimeoutMs(n));
219
396
 
220
397
  //#endregion
221
398
  //#region packages/event-http/src/event-http.ts
@@ -231,7 +408,31 @@ function _define_property(obj, key, value) {
231
408
  }
232
409
  const LOGGER_TITLE = "moost-http";
233
410
  const CONTEXT_TYPE = "HTTP";
234
- var MoostHttp = class {
411
+ /**
412
+ * ## Moost HTTP Adapter
413
+ *
414
+ * Moost Adapter for HTTP events
415
+ *
416
+ * ```ts
417
+ * │ // HTTP server example
418
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
419
+ * │ import { Moost, Param } from 'moost'
420
+ * │
421
+ * │ class MyServer extends Moost {
422
+ * │ @Get('test/:name')
423
+ * │ test(@Param('name') name: string) {
424
+ * │ return { message: `Hello ${name}!` }
425
+ * │ }
426
+ * │ }
427
+ * │
428
+ * │ const app = new MyServer()
429
+ * │ const http = new MoostHttp()
430
+ * │ app.adapter(http).listen(3000, () => {
431
+ * │ app.getLogger('MyApp').log('Up on port 3000')
432
+ * │ })
433
+ * │ app.init()
434
+ * ```
435
+ */ var MoostHttp = class {
235
436
  getHttpApp() {
236
437
  return this.httpApp;
237
438
  }
@@ -296,7 +497,7 @@ var MoostHttp = class {
296
497
  methods.DELETE = pathBuilder;
297
498
  } else methods[handler.method] = pathBuilder;
298
499
  }
299
- opts.logHandler(`${"\x1B[36m"}(${handler.method})${"\x1B[32m"}${targetPath}`);
500
+ opts.logHandler(`(${handler.method})${targetPath}`);
300
501
  const args = routerBinding.getArgs();
301
502
  const params = {};
302
503
  args.forEach((a) => params[a] = `{${a}}`);
@@ -318,46 +519,46 @@ var MoostHttp = class {
318
519
  };
319
520
 
320
521
  //#endregion
321
- exports.All = All
322
- exports.Authorization = Authorization
323
- exports.Body = Body
324
- exports.BodyReadTimeoutMs = BodyReadTimeoutMs
325
- exports.BodySizeLimit = BodySizeLimit
326
- exports.CompressedBodySizeLimit = CompressedBodySizeLimit
327
- exports.Cookie = Cookie
328
- exports.CookieAttrsHook = CookieAttrsHook
329
- exports.CookieHook = CookieHook
330
- exports.Delete = Delete
331
- exports.Get = Get
332
- exports.Header = Header
333
- exports.HeaderHook = HeaderHook
522
+ exports.All = All;
523
+ exports.Authorization = Authorization;
524
+ exports.Body = Body;
525
+ exports.BodyReadTimeoutMs = BodyReadTimeoutMs;
526
+ exports.BodySizeLimit = BodySizeLimit;
527
+ exports.CompressedBodySizeLimit = CompressedBodySizeLimit;
528
+ exports.Cookie = Cookie;
529
+ exports.CookieAttrsHook = CookieAttrsHook;
530
+ exports.CookieHook = CookieHook;
531
+ exports.Delete = Delete;
532
+ exports.Get = Get;
533
+ exports.Header = Header;
534
+ exports.HeaderHook = HeaderHook;
334
535
  Object.defineProperty(exports, 'HttpError', {
335
536
  enumerable: true,
336
537
  get: function () {
337
538
  return __wooksjs_event_http.HttpError;
338
539
  }
339
540
  });
340
- exports.HttpMethod = HttpMethod
341
- exports.Ip = Ip
342
- exports.IpList = IpList
343
- exports.Method = Method
344
- exports.MoostHttp = MoostHttp
345
- exports.Patch = Patch
346
- exports.Post = Post
347
- exports.Put = Put
348
- exports.Query = Query
349
- exports.RawBody = RawBody
350
- exports.Req = Req
351
- exports.ReqId = ReqId
352
- exports.Res = Res
353
- exports.SetCookie = SetCookie
354
- exports.SetHeader = SetHeader
355
- exports.SetStatus = SetStatus
356
- exports.StatusHook = StatusHook
357
- exports.Url = Url
358
- exports.globalBodyReadTimeoutMs = globalBodyReadTimeoutMs
359
- exports.globalBodySizeLimit = globalBodySizeLimit
360
- exports.globalCompressedBodySizeLimit = globalCompressedBodySizeLimit
541
+ exports.HttpMethod = HttpMethod;
542
+ exports.Ip = Ip;
543
+ exports.IpList = IpList;
544
+ exports.Method = Method;
545
+ exports.MoostHttp = MoostHttp;
546
+ exports.Patch = Patch;
547
+ exports.Post = Post;
548
+ exports.Put = Put;
549
+ exports.Query = Query;
550
+ exports.RawBody = RawBody;
551
+ exports.Req = Req;
552
+ exports.ReqId = ReqId;
553
+ exports.Res = Res;
554
+ exports.SetCookie = SetCookie;
555
+ exports.SetHeader = SetHeader;
556
+ exports.SetStatus = SetStatus;
557
+ exports.StatusHook = StatusHook;
558
+ exports.Url = Url;
559
+ exports.globalBodyReadTimeoutMs = globalBodyReadTimeoutMs;
560
+ exports.globalBodySizeLimit = globalBodySizeLimit;
561
+ exports.globalCompressedBodySizeLimit = globalCompressedBodySizeLimit;
361
562
  Object.defineProperty(exports, 'useHttpContext', {
362
563
  enumerable: true,
363
564
  get: function () {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { THook } from '@wooksjs/event-core';
3
2
  import { TCookieAttributes as TCookieAttributes$1, useSetCookies, WooksHttp, TWooksHttpOptions } from '@wooksjs/event-http';
4
3
  export { HttpError, TCacheControl, TCookieAttributesInput, TSetCookieData, useHttpContext } from '@wooksjs/event-http';
@@ -17,26 +16,119 @@ declare const Put: (path?: string) => MethodDecorator;
17
16
  declare const Delete: (path?: string) => MethodDecorator;
18
17
  declare const Patch: (path?: string) => MethodDecorator;
19
18
 
19
+ /**
20
+ * Hook to the Response Status
21
+ * @decorator
22
+ * @paramType TStatusHook
23
+ */
20
24
  declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
25
+ /**
26
+ * Hook to the Response Header
27
+ * @decorator
28
+ * @param name - header name
29
+ * @paramType THeaderHook
30
+ */
21
31
  declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator;
32
+ /**
33
+ * Hook to the Response Cookie
34
+ * @decorator
35
+ * @param name - cookie name
36
+ * @paramType TCookieHook
37
+ */
22
38
  declare const CookieHook: (name: string) => ParameterDecorator & PropertyDecorator;
39
+ /**
40
+ * Hook to the Response Cookie Attributes
41
+ * @decorator
42
+ * @param name - cookie name
43
+ * @paramType TCookieAttributes
44
+ */
23
45
  declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator;
46
+ /**
47
+ * Parse Authorisation Header
48
+ * @decorator
49
+ * @param name - define what to take from the Auth header
50
+ * @paramType string
51
+ */
24
52
  declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator & PropertyDecorator;
53
+ /**
54
+ * Get Request Header Value
55
+ * @decorator
56
+ * @param name - header name
57
+ * @paramType string
58
+ */
25
59
  declare function Header(name: string): ParameterDecorator & PropertyDecorator;
60
+ /**
61
+ * Get Request Cookie Value
62
+ * @decorator
63
+ * @param name - cookie name
64
+ * @paramType string
65
+ */
26
66
  declare function Cookie(name: string): ParameterDecorator & PropertyDecorator;
67
+ /**
68
+ * Get Query Item value or the whole parsed Query as an object
69
+ * @decorator
70
+ * @param name - query item name (optional)
71
+ * @paramType string | object
72
+ */
27
73
  declare function Query(name?: string): ParameterDecorator;
74
+ /**
75
+ * Get Requested URL
76
+ * @decorator
77
+ * @paramType string
78
+ */
28
79
  declare function Url(): ParameterDecorator & PropertyDecorator;
80
+ /**
81
+ * Get Requested HTTP Method
82
+ * @decorator
83
+ * @paramType string
84
+ */
29
85
  declare function Method(): ParameterDecorator & PropertyDecorator;
86
+ /**
87
+ * Get Raw Request Instance
88
+ * @decorator
89
+ * @paramType IncomingMessage
90
+ */
30
91
  declare function Req(): ParameterDecorator & PropertyDecorator;
92
+ /**
93
+ * Get Raw Response Instance
94
+ * @decorator
95
+ * @param opts (optional) { passthrough: boolean }
96
+ * @paramType ServerResponse
97
+ */
31
98
  declare function Res(opts?: {
32
99
  passthrough: boolean;
33
100
  }): ParameterDecorator & PropertyDecorator;
101
+ /**
102
+ * Get Request Unique Identificator (UUID)
103
+ * @decorator
104
+ * @paramType string
105
+ */
34
106
  declare function ReqId(): ParameterDecorator & PropertyDecorator;
107
+ /**
108
+ * Get Request IP Address
109
+ * @decorator
110
+ * @paramType string
111
+ */
35
112
  declare function Ip(opts?: {
36
113
  trustProxy: boolean;
37
114
  }): ParameterDecorator & PropertyDecorator;
115
+ /**
116
+ * Get Request IP Address list
117
+ * @decorator
118
+ * @paramType string[]
119
+ */
38
120
  declare function IpList(): ParameterDecorator & PropertyDecorator;
121
+ /**
122
+ * Get Parsed Request Body
123
+ * @decorator
124
+ * @paramType object | string | unknown
125
+ */
39
126
  declare function Body(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
127
+ /**
128
+ * Get Raw Request Body Buffer
129
+ * @decorator
130
+ * @paramType Promise<Buffer>
131
+ */
40
132
  declare function RawBody(): ParameterDecorator & PropertyDecorator;
41
133
  type TStatusHook = THook<number>;
42
134
  type THeaderHook = THook;
@@ -48,31 +140,166 @@ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
48
140
  status?: number;
49
141
  when?: 'always' | 'error' | 'ok';
50
142
  }) => TInterceptorFn;
143
+ /**
144
+ * Set Header for Request Handler
145
+ *
146
+ * ```ts
147
+ * import { Get, SetHeader } from '@moostjs/event-http';
148
+ * import { Controller } from 'moost';
149
+ *
150
+ * @Controller()
151
+ * export class ExampleController {
152
+ * @Get('test')
153
+ * // setting header for request handler
154
+ * @SetHeader('x-server', 'my-server')
155
+ * testHandler() {
156
+ * return '...'
157
+ * }
158
+ * }
159
+ * ```
160
+ *
161
+ * ```ts
162
+ * import { Get, SetHeader } from '@moostjs/event-http';
163
+ * import { Controller } from 'moost';
164
+ *
165
+ * @Controller()
166
+ * export class ExampleController {
167
+ * @Get('test')
168
+ * // setting header only if status = 400
169
+ * @SetHeader('content-type', 'text/plain', { status: 400 })
170
+ * testHandler() {
171
+ * return '...'
172
+ * }
173
+ * }
174
+ * ```
175
+ *
176
+ * @param name name of header
177
+ * @param value value for header
178
+ * @param options options { status?: number, force?: boolean }
179
+ */
51
180
  declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator;
52
181
  declare const setCookieInterceptor: (...args: Parameters<ReturnType<typeof useSetCookies>['setCookie']>) => TInterceptorFn;
182
+ /**
183
+ * Set Cookie for Request Handler
184
+ * ```ts
185
+ * import { Get, SetCookie } from '@moostjs/event-http';
186
+ * import { Controller } from 'moost';
187
+ *
188
+ * @Controller()
189
+ * export class ExampleController {
190
+ * @Get('test')
191
+ * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
192
+ * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
193
+ * testHandler() {
194
+ * return '...'
195
+ * }
196
+ * }
197
+ * ```
198
+ *
199
+ * @param name name of cookie
200
+ * @param value value for cookie
201
+ * @param attrs cookie attributes
202
+ */
53
203
  declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
54
204
  declare const setStatusInterceptor: (code: number, opts?: {
55
205
  force?: boolean;
56
206
  }) => TInterceptorFn;
207
+ /**
208
+ * Set Response Status for Request Handler
209
+ *
210
+ * ```ts
211
+ * import { Get, SetStatus } from '@moostjs/event-http';
212
+ * import { Controller } from 'moost';
213
+ *
214
+ * @Controller()
215
+ * export class ExampleController {
216
+ * @Get('test')
217
+ * @SetStatus(201)
218
+ * testHandler() {
219
+ * return '...'
220
+ * }
221
+ * }
222
+ * ```
223
+ * @param code number
224
+ * @param opts optional { force?: boolean }
225
+ */
57
226
  declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator;
58
227
 
228
+ /**
229
+ * Creates an interceptor that sets the maximum allowed inflated body size in bytes.
230
+ *
231
+ * @param n - Maximum body size in bytes after decompression.
232
+ * @returns Interceptor function to enforce the limit.
233
+ */
59
234
  declare const globalBodySizeLimit: (n: number) => moost.TInterceptorFn;
235
+ /**
236
+ * Creates an interceptor that sets the maximum allowed compressed body size in bytes.
237
+ *
238
+ * @param n - Maximum body size in bytes before decompression.
239
+ * @returns Interceptor function to enforce the limit.
240
+ */
60
241
  declare const globalCompressedBodySizeLimit: (n: number) => moost.TInterceptorFn;
242
+ /**
243
+ * Creates an interceptor that sets the timeout for reading the request body.
244
+ *
245
+ * @param n - Timeout in milliseconds.
246
+ * @returns Interceptor function to enforce the timeout.
247
+ */
61
248
  declare const globalBodyReadTimeoutMs: (n: number) => moost.TInterceptorFn;
249
+ /**
250
+ * Decorator to limit the maximum inflated body size for the request. Default: 10 MB
251
+ *
252
+ * @param n - Maximum body size in bytes after decompression.
253
+ */
62
254
  declare const BodySizeLimit: (n: number) => ClassDecorator & MethodDecorator;
255
+ /**
256
+ * Decorator to limit the maximum compressed body size for the request. Default: 1 MB
257
+ *
258
+ * @param n - Maximum body size in bytes before decompression.
259
+ */
63
260
  declare const CompressedBodySizeLimit: (n: number) => ClassDecorator & MethodDecorator;
261
+ /**
262
+ * Decorator to set a timeout (in milliseconds) for reading the request body. Default: 10 s
263
+ *
264
+ * @param n - Timeout duration in milliseconds.
265
+ */
64
266
  declare const BodyReadTimeoutMs: (n: number) => ClassDecorator & MethodDecorator;
65
267
 
66
268
  interface THttpHandlerMeta {
67
269
  method: string;
68
270
  path: string;
69
271
  }
272
+ /**
273
+ * ## Moost HTTP Adapter
274
+ *
275
+ * Moost Adapter for HTTP events
276
+ *
277
+ * ```ts
278
+ * │ // HTTP server example
279
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
280
+ * │ import { Moost, Param } from 'moost'
281
+ * │
282
+ * │ class MyServer extends Moost {
283
+ * │ @Get('test/:name')
284
+ * │ test(@Param('name') name: string) {
285
+ * │ return { message: `Hello ${name}!` }
286
+ * │ }
287
+ * │ }
288
+ * │
289
+ * │ const app = new MyServer()
290
+ * │ const http = new MoostHttp()
291
+ * │ app.adapter(http).listen(3000, () => {
292
+ * │ app.getLogger('MyApp').log('Up on port 3000')
293
+ * │ })
294
+ * │ app.init()
295
+ * ```
296
+ */
70
297
  declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
71
298
  readonly name = "http";
72
299
  protected httpApp: WooksHttp;
73
300
  constructor(httpApp?: WooksHttp | TWooksHttpOptions);
74
301
  getHttpApp(): WooksHttp;
75
- getServerCb(): (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
302
+ getServerCb(): (req: http.IncomingMessage, res: http.ServerResponse) => void;
76
303
  listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): Promise<void>;
77
304
  listen(port?: number, hostname?: string, listeningListener?: () => void): Promise<void>;
78
305
  listen(port?: number, backlog?: number, listeningListener?: () => void): Promise<void>;
@@ -97,4 +324,5 @@ declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
97
324
  bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void;
98
325
  }
99
326
 
100
- export { All, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, CompressedBodySizeLimit, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusHook, type TCookieAttributes, type TCookieHook, type THeaderHook, type THttpHandlerMeta, type TStatusHook, Url, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit };
327
+ export { All, Authorization, Body, BodyReadTimeoutMs, BodySizeLimit, CompressedBodySizeLimit, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusHook, Url, globalBodyReadTimeoutMs, globalBodySizeLimit, globalCompressedBodySizeLimit };
328
+ export type { TCookieAttributes, TCookieHook, THeaderHook, THttpHandlerMeta, TStatusHook };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Intercept, Resolve, TInterceptorPriority, defineInterceptorFn, defineMoostEventHandler, getMoostMate } from "moost";
2
2
  import { attachHook } from "@wooksjs/event-core";
3
- import { HttpError, WooksHttp, createHttpApp, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useSearchParams, useSetCookie, useSetCookies, useSetHeader, useStatus } from "@wooksjs/event-http";
3
+ import { HttpError, HttpError as HttpError$1, WooksHttp, createHttpApp, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useSearchParams, useSetCookie, useSetCookies, useSetHeader, useStatus } from "@wooksjs/event-http";
4
4
  import { useBody } from "@wooksjs/http-body";
5
5
  import { createProvideRegistry } from "@prostojs/infact";
6
6
  import { Server } from "http";
@@ -23,7 +23,11 @@ const Patch = (path) => HttpMethod("PATCH", path);
23
23
 
24
24
  //#endregion
25
25
  //#region packages/event-http/src/decorators/resolve.decorator.ts
26
- const StatusHook = () => Resolve((metas, level) => {
26
+ /**
27
+ * Hook to the Response Status
28
+ * @decorator
29
+ * @paramType TStatusHook
30
+ */ const StatusHook = () => Resolve((metas, level) => {
27
31
  const hook = useStatus();
28
32
  if (level === "PARAM") return hook;
29
33
  if (level === "PROP" && metas.instance && metas.key) {
@@ -35,7 +39,12 @@ const StatusHook = () => Resolve((metas, level) => {
35
39
  return typeof initialValue === "number" ? initialValue : 200;
36
40
  }
37
41
  }, "statusCode");
38
- const HeaderHook = (name) => Resolve((metas, level) => {
42
+ /**
43
+ * Hook to the Response Header
44
+ * @decorator
45
+ * @param name - header name
46
+ * @paramType THeaderHook
47
+ */ const HeaderHook = (name) => Resolve((metas, level) => {
39
48
  const hook = useSetHeader(name);
40
49
  if (level === "PARAM") return hook;
41
50
  if (level === "PROP" && metas.instance && metas.key) {
@@ -47,7 +56,12 @@ const HeaderHook = (name) => Resolve((metas, level) => {
47
56
  return typeof initialValue === "string" ? initialValue : "";
48
57
  }
49
58
  }, name);
50
- const CookieHook = (name) => Resolve((metas, level) => {
59
+ /**
60
+ * Hook to the Response Cookie
61
+ * @decorator
62
+ * @param name - cookie name
63
+ * @paramType TCookieHook
64
+ */ const CookieHook = (name) => Resolve((metas, level) => {
51
65
  const hook = useSetCookie(name);
52
66
  if (level === "PARAM") return hook;
53
67
  if (level === "PROP" && metas.instance && metas.key) {
@@ -59,7 +73,12 @@ const CookieHook = (name) => Resolve((metas, level) => {
59
73
  return typeof initialValue === "string" ? initialValue : "";
60
74
  }
61
75
  }, name);
62
- const CookieAttrsHook = (name) => Resolve((metas, level) => {
76
+ /**
77
+ * Hook to the Response Cookie Attributes
78
+ * @decorator
79
+ * @param name - cookie name
80
+ * @paramType TCookieAttributes
81
+ */ const CookieAttrsHook = (name) => Resolve((metas, level) => {
63
82
  const hook = useSetCookie(name);
64
83
  if (level === "PARAM") return attachHook({}, {
65
84
  get: () => hook.attrs,
@@ -74,28 +93,49 @@ const CookieAttrsHook = (name) => Resolve((metas, level) => {
74
93
  return typeof initialValue === "object" ? initialValue : {};
75
94
  }
76
95
  }, name);
77
- function Authorization(name) {
96
+ /**
97
+ * Parse Authorisation Header
98
+ * @decorator
99
+ * @param name - define what to take from the Auth header
100
+ * @paramType string
101
+ */ function Authorization(name) {
78
102
  return Resolve(() => {
79
103
  const auth = useAuthorization();
80
104
  switch (name) {
81
- case "username": return auth.isBasic() ? auth.basicCredentials()?.username : undefined;
82
- case "password": return auth.isBasic() ? auth.basicCredentials()?.password : undefined;
83
- case "bearer": return auth.isBearer() ? auth.authorization : undefined;
105
+ case "username": return auth.isBasic() ? auth.basicCredentials()?.username : void 0;
106
+ case "password": return auth.isBasic() ? auth.basicCredentials()?.password : void 0;
107
+ case "bearer": return auth.isBearer() ? auth.authorization : void 0;
84
108
  case "raw": return auth.authRawCredentials();
85
109
  case "type": return auth.authType();
110
+ default: return void 0;
86
111
  }
87
112
  }, "authorization");
88
113
  }
89
- function Header(name) {
114
+ /**
115
+ * Get Request Header Value
116
+ * @decorator
117
+ * @param name - header name
118
+ * @paramType string
119
+ */ function Header(name) {
90
120
  return Resolve(() => {
91
121
  const headers = useHeaders();
92
122
  return headers[name];
93
123
  }, `header: ${name}`);
94
124
  }
95
- function Cookie(name) {
125
+ /**
126
+ * Get Request Cookie Value
127
+ * @decorator
128
+ * @param name - cookie name
129
+ * @paramType string
130
+ */ function Cookie(name) {
96
131
  return Resolve(() => useCookies().getCookie(name), `cookie: ${name}`);
97
132
  }
98
- function Query(name) {
133
+ /**
134
+ * Get Query Item value or the whole parsed Query as an object
135
+ * @decorator
136
+ * @param name - query item name (optional)
137
+ * @paramType string | object
138
+ */ function Query(name) {
99
139
  const isItem = !!name;
100
140
  const _name = isItem ? name : "Query";
101
141
  return getMoostMate().apply(getMoostMate().decorate("paramSource", isItem ? "QUERY_ITEM" : "QUERY"), getMoostMate().decorate("paramName", _name), Resolve(() => {
@@ -103,37 +143,74 @@ function Query(name) {
103
143
  if (isItem) {
104
144
  const p = urlSearchParams();
105
145
  const value = p.get(name);
106
- return value === null ? undefined : value;
146
+ return value === null ? void 0 : value;
107
147
  }
108
148
  const json = jsonSearchParams();
109
- return Object.keys(json).length > 0 ? json : undefined;
149
+ return Object.keys(json).length > 0 ? json : void 0;
110
150
  }, _name));
111
151
  }
112
- function Url() {
152
+ /**
153
+ * Get Requested URL
154
+ * @decorator
155
+ * @paramType string
156
+ */ function Url() {
113
157
  return Resolve(() => useRequest().url || "", "url");
114
158
  }
115
- function Method() {
159
+ /**
160
+ * Get Requested HTTP Method
161
+ * @decorator
162
+ * @paramType string
163
+ */ function Method() {
116
164
  return Resolve(() => useRequest().method, "http_method");
117
165
  }
118
- function Req() {
166
+ /**
167
+ * Get Raw Request Instance
168
+ * @decorator
169
+ * @paramType IncomingMessage
170
+ */ function Req() {
119
171
  return Resolve(() => useRequest().rawRequest, "request");
120
172
  }
121
- function Res(opts) {
173
+ /**
174
+ * Get Raw Response Instance
175
+ * @decorator
176
+ * @param opts (optional) { passthrough: boolean }
177
+ * @paramType ServerResponse
178
+ */ function Res(opts) {
122
179
  return Resolve(() => useResponse().rawResponse(opts), "response");
123
180
  }
124
- function ReqId() {
181
+ /**
182
+ * Get Request Unique Identificator (UUID)
183
+ * @decorator
184
+ * @paramType string
185
+ */ function ReqId() {
125
186
  return Resolve(() => useRequest().reqId(), "reqId");
126
187
  }
127
- function Ip(opts) {
188
+ /**
189
+ * Get Request IP Address
190
+ * @decorator
191
+ * @paramType string
192
+ */ function Ip(opts) {
128
193
  return Resolve(() => useRequest().getIp(opts), "ip");
129
194
  }
130
- function IpList() {
195
+ /**
196
+ * Get Request IP Address list
197
+ * @decorator
198
+ * @paramType string[]
199
+ */ function IpList() {
131
200
  return Resolve(() => useRequest().getIpList(), "ipList");
132
201
  }
133
- function Body() {
202
+ /**
203
+ * Get Parsed Request Body
204
+ * @decorator
205
+ * @paramType object | string | unknown
206
+ */ function Body() {
134
207
  return getMoostMate().apply(getMoostMate().decorate("paramSource", "BODY"), Resolve(() => useBody().parseBody(), "body"));
135
208
  }
136
- function RawBody() {
209
+ /**
210
+ * Get Raw Request Body Buffer
211
+ * @decorator
212
+ * @paramType Promise<Buffer>
213
+ */ function RawBody() {
137
214
  return Resolve(() => useBody().rawBody(), "body");
138
215
  }
139
216
 
@@ -152,7 +229,43 @@ const setHeaderInterceptor = (name, value, opts) => {
152
229
  fn.priority = TInterceptorPriority.AFTER_ALL;
153
230
  return fn;
154
231
  };
155
- function SetHeader(...args) {
232
+ /**
233
+ * Set Header for Request Handler
234
+ *
235
+ * ```ts
236
+ * import { Get, SetHeader } from '@moostjs/event-http';
237
+ * import { Controller } from 'moost';
238
+ *
239
+ * @Controller()
240
+ * export class ExampleController {
241
+ * @Get('test')
242
+ * // setting header for request handler
243
+ * @SetHeader('x-server', 'my-server')
244
+ * testHandler() {
245
+ * return '...'
246
+ * }
247
+ * }
248
+ * ```
249
+ *
250
+ * ```ts
251
+ * import { Get, SetHeader } from '@moostjs/event-http';
252
+ * import { Controller } from 'moost';
253
+ *
254
+ * @Controller()
255
+ * export class ExampleController {
256
+ * @Get('test')
257
+ * // setting header only if status = 400
258
+ * @SetHeader('content-type', 'text/plain', { status: 400 })
259
+ * testHandler() {
260
+ * return '...'
261
+ * }
262
+ * }
263
+ * ```
264
+ *
265
+ * @param name name of header
266
+ * @param value value for header
267
+ * @param options options { status?: number, force?: boolean }
268
+ */ function SetHeader(...args) {
156
269
  return Intercept(setHeaderInterceptor(...args));
157
270
  }
158
271
  const setCookieInterceptor = (name, value, attrs) => {
@@ -165,7 +278,27 @@ const setCookieInterceptor = (name, value, attrs) => {
165
278
  fn.priority = TInterceptorPriority.AFTER_ALL;
166
279
  return fn;
167
280
  };
168
- function SetCookie(...args) {
281
+ /**
282
+ * Set Cookie for Request Handler
283
+ * ```ts
284
+ * import { Get, SetCookie } from '@moostjs/event-http';
285
+ * import { Controller } from 'moost';
286
+ *
287
+ * @Controller()
288
+ * export class ExampleController {
289
+ * @Get('test')
290
+ * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
291
+ * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
292
+ * testHandler() {
293
+ * return '...'
294
+ * }
295
+ * }
296
+ * ```
297
+ *
298
+ * @param name name of cookie
299
+ * @param value value for cookie
300
+ * @param attrs cookie attributes
301
+ */ function SetCookie(...args) {
169
302
  return Intercept(setCookieInterceptor(...args));
170
303
  }
171
304
  const setStatusInterceptor = (code, opts) => defineInterceptorFn((before, after) => {
@@ -174,24 +307,69 @@ const setStatusInterceptor = (code, opts) => defineInterceptorFn((before, after)
174
307
  if (!status.isDefined || opts?.force) status.value = code;
175
308
  });
176
309
  });
177
- function SetStatus(...args) {
310
+ /**
311
+ * Set Response Status for Request Handler
312
+ *
313
+ * ```ts
314
+ * import { Get, SetStatus } from '@moostjs/event-http';
315
+ * import { Controller } from 'moost';
316
+ *
317
+ * @Controller()
318
+ * export class ExampleController {
319
+ * @Get('test')
320
+ * @SetStatus(201)
321
+ * testHandler() {
322
+ * return '...'
323
+ * }
324
+ * }
325
+ * ```
326
+ * @param code number
327
+ * @param opts optional { force?: boolean }
328
+ */ function SetStatus(...args) {
178
329
  return Intercept(setStatusInterceptor(...args));
179
330
  }
180
331
 
181
332
  //#endregion
182
333
  //#region packages/event-http/src/decorators/limits.decorator.ts
183
- const globalBodySizeLimit = (n) => defineInterceptorFn(() => {
334
+ /**
335
+ * Creates an interceptor that sets the maximum allowed inflated body size in bytes.
336
+ *
337
+ * @param n - Maximum body size in bytes after decompression.
338
+ * @returns Interceptor function to enforce the limit.
339
+ */ const globalBodySizeLimit = (n) => defineInterceptorFn(() => {
184
340
  useRequest().setMaxInflated(n);
185
341
  }, TInterceptorPriority.BEFORE_ALL);
186
- const globalCompressedBodySizeLimit = (n) => defineInterceptorFn(() => {
342
+ /**
343
+ * Creates an interceptor that sets the maximum allowed compressed body size in bytes.
344
+ *
345
+ * @param n - Maximum body size in bytes before decompression.
346
+ * @returns Interceptor function to enforce the limit.
347
+ */ const globalCompressedBodySizeLimit = (n) => defineInterceptorFn(() => {
187
348
  useRequest().setMaxCompressed(n);
188
349
  }, TInterceptorPriority.BEFORE_ALL);
189
- const globalBodyReadTimeoutMs = (n) => defineInterceptorFn(() => {
350
+ /**
351
+ * Creates an interceptor that sets the timeout for reading the request body.
352
+ *
353
+ * @param n - Timeout in milliseconds.
354
+ * @returns Interceptor function to enforce the timeout.
355
+ */ const globalBodyReadTimeoutMs = (n) => defineInterceptorFn(() => {
190
356
  useRequest().setReadTimeoutMs(n);
191
357
  }, TInterceptorPriority.BEFORE_ALL);
192
- const BodySizeLimit = (n) => Intercept(globalBodySizeLimit(n));
193
- const CompressedBodySizeLimit = (n) => Intercept(globalCompressedBodySizeLimit(n));
194
- const BodyReadTimeoutMs = (n) => Intercept(globalBodyReadTimeoutMs(n));
358
+ /**
359
+ * Decorator to limit the maximum inflated body size for the request. Default: 10 MB
360
+ *
361
+ * @param n - Maximum body size in bytes after decompression.
362
+ */ const BodySizeLimit = (n) => Intercept(globalBodySizeLimit(n));
363
+ /**
364
+ * Decorator to limit the maximum compressed body size for the request. Default: 1 MB
365
+ *
366
+ * @param n - Maximum body size in bytes before decompression.
367
+ */ const CompressedBodySizeLimit = (n) => Intercept(globalCompressedBodySizeLimit(n));
368
+ /**
369
+ * Decorator to set a timeout (in milliseconds) for reading the request body. Default: 10 s
370
+ *
371
+ * @param n - Timeout duration in milliseconds.
372
+ */ const BodyReadTimeoutMs = (n) => Intercept(globalBodyReadTimeoutMs(n));
195
373
 
196
374
  //#endregion
197
375
  //#region packages/event-http/src/event-http.ts
@@ -207,7 +385,31 @@ function _define_property(obj, key, value) {
207
385
  }
208
386
  const LOGGER_TITLE = "moost-http";
209
387
  const CONTEXT_TYPE = "HTTP";
210
- var MoostHttp = class {
388
+ /**
389
+ * ## Moost HTTP Adapter
390
+ *
391
+ * Moost Adapter for HTTP events
392
+ *
393
+ * ```ts
394
+ * │ // HTTP server example
395
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
396
+ * │ import { Moost, Param } from 'moost'
397
+ * │
398
+ * │ class MyServer extends Moost {
399
+ * │ @Get('test/:name')
400
+ * │ test(@Param('name') name: string) {
401
+ * │ return { message: `Hello ${name}!` }
402
+ * │ }
403
+ * │ }
404
+ * │
405
+ * │ const app = new MyServer()
406
+ * │ const http = new MoostHttp()
407
+ * │ app.adapter(http).listen(3000, () => {
408
+ * │ app.getLogger('MyApp').log('Up on port 3000')
409
+ * │ })
410
+ * │ app.init()
411
+ * ```
412
+ */ var MoostHttp = class {
211
413
  getHttpApp() {
212
414
  return this.httpApp;
213
415
  }
@@ -222,7 +424,7 @@ var MoostHttp = class {
222
424
  loggerTitle: LOGGER_TITLE,
223
425
  getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
224
426
  getControllerInstance: () => this.moost,
225
- callControllerMethod: () => new HttpError(404, "Resource Not Found"),
427
+ callControllerMethod: () => new HttpError$1(404, "Resource Not Found"),
226
428
  targetPath: "",
227
429
  handlerType: "__SYSTEM__"
228
430
  })();
@@ -272,7 +474,7 @@ var MoostHttp = class {
272
474
  methods.DELETE = pathBuilder;
273
475
  } else methods[handler.method] = pathBuilder;
274
476
  }
275
- opts.logHandler(`${"\x1B[36m"}(${handler.method})${"\x1B[32m"}${targetPath}`);
477
+ opts.logHandler(`(${handler.method})${targetPath}`);
276
478
  const args = routerBinding.getArgs();
277
479
  const params = {};
278
480
  args.forEach((a) => params[a] = `{${a}}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moostjs/event-http",
3
- "version": "0.5.29",
3
+ "version": "0.5.31",
4
4
  "description": "@moostjs/event-http",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -37,16 +37,18 @@
37
37
  "url": "https://github.com/moostjs/moostjs/issues"
38
38
  },
39
39
  "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-http#readme",
40
- "dependencies": {
40
+ "peerDependencies": {
41
+ "@wooksjs/event-core": "^0.6.1",
41
42
  "@prostojs/infact": "^0.3.3",
42
43
  "@prostojs/router": "^0.2.1",
43
- "@wooksjs/event-core": "^0.6.0",
44
- "@wooksjs/event-http": "^0.6.0",
45
- "@wooksjs/http-body": "^0.6.0",
46
- "moost": "^0.5.29"
44
+ "moost": "^0.5.31"
45
+ },
46
+ "dependencies": {
47
+ "@wooksjs/event-http": "^0.6.1",
48
+ "@wooksjs/http-body": "^0.6.1"
47
49
  },
48
50
  "devDependencies": {
49
- "vitest": "^3.0.5"
51
+ "vitest": "3.2.4"
50
52
  },
51
53
  "scripts": {
52
54
  "pub": "pnpm publish --access public",