@moostjs/event-http 0.2.31 → 0.2.33
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 +109 -10
- package/dist/index.d.ts +104 -5
- package/dist/index.mjs +103 -12
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -416,7 +416,7 @@ const CookieHook = (name) => moost.Resolve((metas, level) => {
|
|
|
416
416
|
* Hook to the Response Cookie Attributes
|
|
417
417
|
* @decorator
|
|
418
418
|
* @param name - cookie name
|
|
419
|
-
* @paramType
|
|
419
|
+
* @paramType TCookieAttributes
|
|
420
420
|
*/
|
|
421
421
|
const CookieAttrsHook = (name) => moost.Resolve((metas, level) => {
|
|
422
422
|
const hook = eventHttp.useSetCookie(name);
|
|
@@ -526,6 +526,15 @@ function Method() {
|
|
|
526
526
|
function Req() {
|
|
527
527
|
return moost.Resolve(() => eventHttp.useRequest().rawRequest, 'request');
|
|
528
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Get Raw Response Instance
|
|
531
|
+
* @decorator
|
|
532
|
+
* @param opts (optional) { passthrough: boolean }
|
|
533
|
+
* @paramType ServerResponse
|
|
534
|
+
*/
|
|
535
|
+
function Res(opts) {
|
|
536
|
+
return moost.Resolve(() => eventHttp.useResponse().rawResponse(opts), 'response');
|
|
537
|
+
}
|
|
529
538
|
/**
|
|
530
539
|
* Get Request Unique Identificator (UUID)
|
|
531
540
|
* @decorator
|
|
@@ -550,15 +559,6 @@ function Ip(opts) {
|
|
|
550
559
|
function IpList() {
|
|
551
560
|
return moost.Resolve(() => eventHttp.useRequest().getIpList(), 'ipList');
|
|
552
561
|
}
|
|
553
|
-
/**
|
|
554
|
-
* Get Raw Response Object
|
|
555
|
-
* @decorator
|
|
556
|
-
* @param options - passthrough options
|
|
557
|
-
* @paramType string
|
|
558
|
-
*/
|
|
559
|
-
function Res(options) {
|
|
560
|
-
return moost.Resolve(() => eventHttp.useResponse().rawResponse(options), 'response');
|
|
561
|
-
}
|
|
562
562
|
/**
|
|
563
563
|
* Get Parsed Request Body
|
|
564
564
|
* @decorator
|
|
@@ -590,6 +590,43 @@ const setHeaderInterceptor = (name, value, opts) => {
|
|
|
590
590
|
fn.priority = moost.TInterceptorPriority.AFTER_ALL;
|
|
591
591
|
return fn;
|
|
592
592
|
};
|
|
593
|
+
/**
|
|
594
|
+
* Set Header for Request Handler
|
|
595
|
+
*
|
|
596
|
+
* ```ts
|
|
597
|
+
* import { Get, SetHeader } from '@moostjs/event-http';
|
|
598
|
+
* import { Controller } from 'moost';
|
|
599
|
+
*
|
|
600
|
+
* @Controller()
|
|
601
|
+
* export class ExampleController {
|
|
602
|
+
* @Get('test')
|
|
603
|
+
* // setting header for request handler
|
|
604
|
+
* @SetHeader('x-server', 'my-server')
|
|
605
|
+
* testHandler() {
|
|
606
|
+
* return '...'
|
|
607
|
+
* }
|
|
608
|
+
* }
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* ```ts
|
|
612
|
+
* import { Get, SetHeader } from '@moostjs/event-http';
|
|
613
|
+
* import { Controller } from 'moost';
|
|
614
|
+
*
|
|
615
|
+
* @Controller()
|
|
616
|
+
* export class ExampleController {
|
|
617
|
+
* @Get('test')
|
|
618
|
+
* // setting header only if status = 400
|
|
619
|
+
* @SetHeader('content-type', 'text/plain', { status: 400 })
|
|
620
|
+
* testHandler() {
|
|
621
|
+
* return '...'
|
|
622
|
+
* }
|
|
623
|
+
* }
|
|
624
|
+
* ```
|
|
625
|
+
*
|
|
626
|
+
* @param name name of header
|
|
627
|
+
* @param value value for header
|
|
628
|
+
* @param options options { status?: number, force?: boolean }
|
|
629
|
+
*/
|
|
593
630
|
function SetHeader(...args) {
|
|
594
631
|
return moost.Intercept(setHeaderInterceptor(...args));
|
|
595
632
|
}
|
|
@@ -605,8 +642,61 @@ const setCookieInterceptor = (name, value, attrs) => {
|
|
|
605
642
|
fn.priority = moost.TInterceptorPriority.AFTER_ALL;
|
|
606
643
|
return fn;
|
|
607
644
|
};
|
|
645
|
+
/**
|
|
646
|
+
* Set Cookie for Request Handler
|
|
647
|
+
* ```ts
|
|
648
|
+
* import { Get, SetCookie } from '@moostjs/event-http';
|
|
649
|
+
* import { Controller } from 'moost';
|
|
650
|
+
*
|
|
651
|
+
* @Controller()
|
|
652
|
+
* export class ExampleController {
|
|
653
|
+
* @Get('test')
|
|
654
|
+
* // setting 'my-cookie' = 'value' with maxAge of 10 minutes
|
|
655
|
+
* @SetCookie('my-cookie', 'value', { maxAge: '10m' })
|
|
656
|
+
* testHandler() {
|
|
657
|
+
* return '...'
|
|
658
|
+
* }
|
|
659
|
+
* }
|
|
660
|
+
* ```
|
|
661
|
+
*
|
|
662
|
+
* @param name name of cookie
|
|
663
|
+
* @param value value for cookie
|
|
664
|
+
* @param attrs cookie attributes
|
|
665
|
+
*/
|
|
608
666
|
function SetCookie(...args) {
|
|
609
667
|
return moost.Intercept(setCookieInterceptor(...args));
|
|
668
|
+
}
|
|
669
|
+
const setStatusInterceptor = (code, opts) => {
|
|
670
|
+
return moost.defineInterceptorFn((before, after) => {
|
|
671
|
+
const status = eventHttp.useStatus();
|
|
672
|
+
after(() => {
|
|
673
|
+
if (!status.isDefined || (opts === null || opts === void 0 ? void 0 : opts.force)) {
|
|
674
|
+
status.value = code;
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
/**
|
|
680
|
+
* Set Response Status for Request Handler
|
|
681
|
+
*
|
|
682
|
+
* ```ts
|
|
683
|
+
* import { Get, SetStatus } from '@moostjs/event-http';
|
|
684
|
+
* import { Controller } from 'moost';
|
|
685
|
+
*
|
|
686
|
+
* @Controller()
|
|
687
|
+
* export class ExampleController {
|
|
688
|
+
* @Get('test')
|
|
689
|
+
* @SetStatus(201)
|
|
690
|
+
* testHandler() {
|
|
691
|
+
* return '...'
|
|
692
|
+
* }
|
|
693
|
+
* }
|
|
694
|
+
* ```
|
|
695
|
+
* @param code number
|
|
696
|
+
* @param opts optional { force?: boolean }
|
|
697
|
+
*/
|
|
698
|
+
function SetStatus(...args) {
|
|
699
|
+
return moost.Intercept(setStatusInterceptor(...args));
|
|
610
700
|
}
|
|
611
701
|
|
|
612
702
|
function httpValidatePipe(opts) {
|
|
@@ -620,6 +710,14 @@ function httpValidatePipe(opts) {
|
|
|
620
710
|
} }, opts[0]));
|
|
621
711
|
}
|
|
622
712
|
|
|
713
|
+
Object.defineProperty(exports, 'HttpError', {
|
|
714
|
+
enumerable: true,
|
|
715
|
+
get: function () { return eventHttp.HttpError; }
|
|
716
|
+
});
|
|
717
|
+
Object.defineProperty(exports, 'useHttpContext', {
|
|
718
|
+
enumerable: true,
|
|
719
|
+
get: function () { return eventHttp.useHttpContext; }
|
|
720
|
+
});
|
|
623
721
|
exports.All = All;
|
|
624
722
|
exports.Authorization = Authorization;
|
|
625
723
|
exports.Body = Body;
|
|
@@ -645,6 +743,7 @@ exports.ReqId = ReqId;
|
|
|
645
743
|
exports.Res = Res;
|
|
646
744
|
exports.SetCookie = SetCookie;
|
|
647
745
|
exports.SetHeader = SetHeader;
|
|
746
|
+
exports.SetStatus = SetStatus;
|
|
648
747
|
exports.StatusHook = StatusHook;
|
|
649
748
|
exports.Url = Url;
|
|
650
749
|
exports.httpValidatePipe = httpValidatePipe;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
|
+
import { HttpError } from '@wooksjs/event-http';
|
|
3
4
|
import { IncomingMessage } from 'http';
|
|
4
5
|
import { Moost } from 'moost';
|
|
5
6
|
import { ServerResponse } from 'http';
|
|
6
7
|
import { TConsoleBase } from '@prostojs/logger';
|
|
8
|
+
import { TCookieAttributes as TCookieAttributes_2 } from '@wooksjs/event-http';
|
|
7
9
|
import { TCookieAttributesInput } from '@wooksjs/event-http';
|
|
10
|
+
import { THook } from '@wooksjs/event-core';
|
|
8
11
|
import { TInterceptorFn } from 'moost';
|
|
9
12
|
import { TMoostAdapter } from 'moost';
|
|
10
13
|
import { TMoostAdapterOptions } from 'moost';
|
|
@@ -12,6 +15,7 @@ import { TPipeFn } from 'moost';
|
|
|
12
15
|
import { TProstoRouterPathBuilder } from '@prostojs/router';
|
|
13
16
|
import { TProvideRegistry } from '@prostojs/infact';
|
|
14
17
|
import { TWooksHttpOptions } from '@wooksjs/event-http';
|
|
18
|
+
import { useHttpContext } from '@wooksjs/event-http';
|
|
15
19
|
import { useSetCookies } from '@wooksjs/event-http';
|
|
16
20
|
import { validatePipe } from 'moost';
|
|
17
21
|
import { WooksHttp } from '@wooksjs/event-http';
|
|
@@ -46,7 +50,7 @@ export declare function Cookie(name: string): ParameterDecorator & PropertyDecor
|
|
|
46
50
|
* Hook to the Response Cookie Attributes
|
|
47
51
|
* @decorator
|
|
48
52
|
* @param name - cookie name
|
|
49
|
-
* @paramType
|
|
53
|
+
* @paramType TCookieAttributes
|
|
50
54
|
*/
|
|
51
55
|
export declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator;
|
|
52
56
|
|
|
@@ -78,6 +82,8 @@ export declare function Header(name: string): ParameterDecorator & PropertyDecor
|
|
|
78
82
|
*/
|
|
79
83
|
export declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator;
|
|
80
84
|
|
|
85
|
+
export { HttpError }
|
|
86
|
+
|
|
81
87
|
export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
|
|
82
88
|
|
|
83
89
|
export declare function httpValidatePipe(opts: Parameters<typeof validatePipe>): TPipeFn<TEmpty>;
|
|
@@ -189,19 +195,77 @@ export declare function Req(): ParameterDecorator & PropertyDecorator;
|
|
|
189
195
|
export declare function ReqId(): ParameterDecorator & PropertyDecorator;
|
|
190
196
|
|
|
191
197
|
/**
|
|
192
|
-
* Get Raw Response
|
|
198
|
+
* Get Raw Response Instance
|
|
193
199
|
* @decorator
|
|
194
|
-
* @param
|
|
195
|
-
* @paramType
|
|
200
|
+
* @param opts (optional) { passthrough: boolean }
|
|
201
|
+
* @paramType ServerResponse
|
|
196
202
|
*/
|
|
197
|
-
export declare function Res(
|
|
203
|
+
export declare function Res(opts?: {
|
|
198
204
|
passthrough: boolean;
|
|
199
205
|
}): ParameterDecorator & PropertyDecorator;
|
|
200
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Set Cookie for Request Handler
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { Get, SetCookie } from '@moostjs/event-http';
|
|
211
|
+
* import { Controller } from 'moost';
|
|
212
|
+
*
|
|
213
|
+
* @Controller()
|
|
214
|
+
* export class ExampleController {
|
|
215
|
+
* @Get('test')
|
|
216
|
+
* // setting 'my-cookie' = 'value' with maxAge of 10 minutes
|
|
217
|
+
* @SetCookie('my-cookie', 'value', { maxAge: '10m' })
|
|
218
|
+
* testHandler() {
|
|
219
|
+
* return '...'
|
|
220
|
+
* }
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @param name name of cookie
|
|
225
|
+
* @param value value for cookie
|
|
226
|
+
* @param attrs cookie attributes
|
|
227
|
+
*/
|
|
201
228
|
export declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
|
|
202
229
|
|
|
203
230
|
declare const setCookieInterceptor: (...args: Parameters<ReturnType<typeof useSetCookies>['setCookie']>) => TInterceptorFn;
|
|
204
231
|
|
|
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
|
+
*/
|
|
205
269
|
export declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator;
|
|
206
270
|
|
|
207
271
|
declare const setHeaderInterceptor: (name: string, value: string, opts?: {
|
|
@@ -209,6 +273,31 @@ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
|
|
|
209
273
|
status?: number;
|
|
210
274
|
}) => TInterceptorFn;
|
|
211
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Set Response Status for Request Handler
|
|
278
|
+
*
|
|
279
|
+
* ```ts
|
|
280
|
+
* import { Get, SetStatus } from '@moostjs/event-http';
|
|
281
|
+
* import { Controller } from 'moost';
|
|
282
|
+
*
|
|
283
|
+
* @Controller()
|
|
284
|
+
* export class ExampleController {
|
|
285
|
+
* @Get('test')
|
|
286
|
+
* @SetStatus(201)
|
|
287
|
+
* testHandler() {
|
|
288
|
+
* return '...'
|
|
289
|
+
* }
|
|
290
|
+
* }
|
|
291
|
+
* ```
|
|
292
|
+
* @param code number
|
|
293
|
+
* @param opts optional { force?: boolean }
|
|
294
|
+
*/
|
|
295
|
+
export declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator;
|
|
296
|
+
|
|
297
|
+
declare const setStatusInterceptor: (code: number, opts?: {
|
|
298
|
+
force?: boolean;
|
|
299
|
+
}) => TInterceptorFn;
|
|
300
|
+
|
|
212
301
|
/**
|
|
213
302
|
* Hook to the Response Status
|
|
214
303
|
* @decorator
|
|
@@ -216,16 +305,24 @@ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
|
|
|
216
305
|
*/
|
|
217
306
|
export declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
|
|
218
307
|
|
|
308
|
+
export declare type TCookieAttributes = Partial<TCookieAttributes_2>;
|
|
309
|
+
|
|
219
310
|
export { TCookieAttributesInput }
|
|
220
311
|
|
|
312
|
+
export declare type TCookieHook = THook & Partial<THook<TCookieAttributes, 'attrs'>>;
|
|
313
|
+
|
|
221
314
|
declare interface TEmpty {
|
|
222
315
|
}
|
|
223
316
|
|
|
317
|
+
export declare type THeaderHook = THook;
|
|
318
|
+
|
|
224
319
|
export declare interface THttpHandlerMeta {
|
|
225
320
|
method: string;
|
|
226
321
|
path: string;
|
|
227
322
|
}
|
|
228
323
|
|
|
324
|
+
export declare type TStatusHook = THook<number>;
|
|
325
|
+
|
|
229
326
|
/**
|
|
230
327
|
* Get Requested URL
|
|
231
328
|
* @decorator
|
|
@@ -233,4 +330,6 @@ export declare interface THttpHandlerMeta {
|
|
|
233
330
|
*/
|
|
234
331
|
export declare function Url(): ParameterDecorator & PropertyDecorator;
|
|
235
332
|
|
|
333
|
+
export { useHttpContext }
|
|
334
|
+
|
|
236
335
|
export { }
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WooksHttp, createHttpApp, useRequest, HttpError, useHttpContext, useHeaders, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse, useSetCookies } from '@wooksjs/event-http';
|
|
2
|
-
|
|
2
|
+
export { HttpError, useHttpContext } from '@wooksjs/event-http';
|
|
3
|
+
import { defineMoostEventHandler, getMoostMate, Resolve, Intercept, TInterceptorPriority, defineInterceptorFn, validatePipe } from 'moost';
|
|
3
4
|
import { createProvideRegistry } from '@prostojs/infact';
|
|
4
5
|
import { Server } from 'http';
|
|
5
6
|
import { Server as Server$1 } from 'https';
|
|
@@ -414,7 +415,7 @@ const CookieHook = (name) => Resolve((metas, level) => {
|
|
|
414
415
|
* Hook to the Response Cookie Attributes
|
|
415
416
|
* @decorator
|
|
416
417
|
* @param name - cookie name
|
|
417
|
-
* @paramType
|
|
418
|
+
* @paramType TCookieAttributes
|
|
418
419
|
*/
|
|
419
420
|
const CookieAttrsHook = (name) => Resolve((metas, level) => {
|
|
420
421
|
const hook = useSetCookie(name);
|
|
@@ -524,6 +525,15 @@ function Method() {
|
|
|
524
525
|
function Req() {
|
|
525
526
|
return Resolve(() => useRequest().rawRequest, 'request');
|
|
526
527
|
}
|
|
528
|
+
/**
|
|
529
|
+
* Get Raw Response Instance
|
|
530
|
+
* @decorator
|
|
531
|
+
* @param opts (optional) { passthrough: boolean }
|
|
532
|
+
* @paramType ServerResponse
|
|
533
|
+
*/
|
|
534
|
+
function Res(opts) {
|
|
535
|
+
return Resolve(() => useResponse().rawResponse(opts), 'response');
|
|
536
|
+
}
|
|
527
537
|
/**
|
|
528
538
|
* Get Request Unique Identificator (UUID)
|
|
529
539
|
* @decorator
|
|
@@ -548,15 +558,6 @@ function Ip(opts) {
|
|
|
548
558
|
function IpList() {
|
|
549
559
|
return Resolve(() => useRequest().getIpList(), 'ipList');
|
|
550
560
|
}
|
|
551
|
-
/**
|
|
552
|
-
* Get Raw Response Object
|
|
553
|
-
* @decorator
|
|
554
|
-
* @param options - passthrough options
|
|
555
|
-
* @paramType string
|
|
556
|
-
*/
|
|
557
|
-
function Res(options) {
|
|
558
|
-
return Resolve(() => useResponse().rawResponse(options), 'response');
|
|
559
|
-
}
|
|
560
561
|
/**
|
|
561
562
|
* Get Parsed Request Body
|
|
562
563
|
* @decorator
|
|
@@ -588,6 +589,43 @@ const setHeaderInterceptor = (name, value, opts) => {
|
|
|
588
589
|
fn.priority = TInterceptorPriority.AFTER_ALL;
|
|
589
590
|
return fn;
|
|
590
591
|
};
|
|
592
|
+
/**
|
|
593
|
+
* Set Header for Request Handler
|
|
594
|
+
*
|
|
595
|
+
* ```ts
|
|
596
|
+
* import { Get, SetHeader } from '@moostjs/event-http';
|
|
597
|
+
* import { Controller } from 'moost';
|
|
598
|
+
*
|
|
599
|
+
* @Controller()
|
|
600
|
+
* export class ExampleController {
|
|
601
|
+
* @Get('test')
|
|
602
|
+
* // setting header for request handler
|
|
603
|
+
* @SetHeader('x-server', 'my-server')
|
|
604
|
+
* testHandler() {
|
|
605
|
+
* return '...'
|
|
606
|
+
* }
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* ```ts
|
|
611
|
+
* import { Get, SetHeader } from '@moostjs/event-http';
|
|
612
|
+
* import { Controller } from 'moost';
|
|
613
|
+
*
|
|
614
|
+
* @Controller()
|
|
615
|
+
* export class ExampleController {
|
|
616
|
+
* @Get('test')
|
|
617
|
+
* // setting header only if status = 400
|
|
618
|
+
* @SetHeader('content-type', 'text/plain', { status: 400 })
|
|
619
|
+
* testHandler() {
|
|
620
|
+
* return '...'
|
|
621
|
+
* }
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*
|
|
625
|
+
* @param name name of header
|
|
626
|
+
* @param value value for header
|
|
627
|
+
* @param options options { status?: number, force?: boolean }
|
|
628
|
+
*/
|
|
591
629
|
function SetHeader(...args) {
|
|
592
630
|
return Intercept(setHeaderInterceptor(...args));
|
|
593
631
|
}
|
|
@@ -603,8 +641,61 @@ const setCookieInterceptor = (name, value, attrs) => {
|
|
|
603
641
|
fn.priority = TInterceptorPriority.AFTER_ALL;
|
|
604
642
|
return fn;
|
|
605
643
|
};
|
|
644
|
+
/**
|
|
645
|
+
* Set Cookie for Request Handler
|
|
646
|
+
* ```ts
|
|
647
|
+
* import { Get, SetCookie } from '@moostjs/event-http';
|
|
648
|
+
* import { Controller } from 'moost';
|
|
649
|
+
*
|
|
650
|
+
* @Controller()
|
|
651
|
+
* export class ExampleController {
|
|
652
|
+
* @Get('test')
|
|
653
|
+
* // setting 'my-cookie' = 'value' with maxAge of 10 minutes
|
|
654
|
+
* @SetCookie('my-cookie', 'value', { maxAge: '10m' })
|
|
655
|
+
* testHandler() {
|
|
656
|
+
* return '...'
|
|
657
|
+
* }
|
|
658
|
+
* }
|
|
659
|
+
* ```
|
|
660
|
+
*
|
|
661
|
+
* @param name name of cookie
|
|
662
|
+
* @param value value for cookie
|
|
663
|
+
* @param attrs cookie attributes
|
|
664
|
+
*/
|
|
606
665
|
function SetCookie(...args) {
|
|
607
666
|
return Intercept(setCookieInterceptor(...args));
|
|
667
|
+
}
|
|
668
|
+
const setStatusInterceptor = (code, opts) => {
|
|
669
|
+
return defineInterceptorFn((before, after) => {
|
|
670
|
+
const status = useStatus();
|
|
671
|
+
after(() => {
|
|
672
|
+
if (!status.isDefined || (opts === null || opts === void 0 ? void 0 : opts.force)) {
|
|
673
|
+
status.value = code;
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* Set Response Status for Request Handler
|
|
680
|
+
*
|
|
681
|
+
* ```ts
|
|
682
|
+
* import { Get, SetStatus } from '@moostjs/event-http';
|
|
683
|
+
* import { Controller } from 'moost';
|
|
684
|
+
*
|
|
685
|
+
* @Controller()
|
|
686
|
+
* export class ExampleController {
|
|
687
|
+
* @Get('test')
|
|
688
|
+
* @SetStatus(201)
|
|
689
|
+
* testHandler() {
|
|
690
|
+
* return '...'
|
|
691
|
+
* }
|
|
692
|
+
* }
|
|
693
|
+
* ```
|
|
694
|
+
* @param code number
|
|
695
|
+
* @param opts optional { force?: boolean }
|
|
696
|
+
*/
|
|
697
|
+
function SetStatus(...args) {
|
|
698
|
+
return Intercept(setStatusInterceptor(...args));
|
|
608
699
|
}
|
|
609
700
|
|
|
610
701
|
function httpValidatePipe(opts) {
|
|
@@ -618,4 +709,4 @@ function httpValidatePipe(opts) {
|
|
|
618
709
|
} }, opts[0]));
|
|
619
710
|
}
|
|
620
711
|
|
|
621
|
-
export { All, Authorization, Body, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, StatusHook, Url, httpValidatePipe };
|
|
712
|
+
export { All, Authorization, Body, 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, httpValidatePipe };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moostjs/event-http",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
4
4
|
"description": "@moostjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-http#readme",
|
|
30
30
|
"peerDependencies": {},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"moost": "0.2.
|
|
33
|
-
"@wooksjs/event-core": "^0.3.
|
|
34
|
-
"@wooksjs/event-http": "^0.3.
|
|
32
|
+
"moost": "0.2.33",
|
|
33
|
+
"@wooksjs/event-core": "^0.3.3",
|
|
34
|
+
"@wooksjs/event-http": "^0.3.3",
|
|
35
35
|
"@prostojs/infact": "^0.1.11",
|
|
36
36
|
"@prostojs/router": "^0.1.0"
|
|
37
37
|
}
|