@moostjs/event-http 0.5.21 → 0.5.23
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/LICENSE +21 -0
- package/dist/index.cjs +293 -286
- package/dist/index.d.ts +3 -198
- package/dist/index.mjs +229 -249
- package/package.json +17 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { THook } from '@wooksjs/event-core';
|
|
2
3
|
import { TCookieAttributes as TCookieAttributes$1, useSetCookies, WooksHttp, TWooksHttpOptions } from '@wooksjs/event-http';
|
|
3
4
|
export { HttpError, TCacheControl, TCookieAttributesInput, TSetCookieData, useHttpContext } from '@wooksjs/event-http';
|
|
4
|
-
import { TInterceptorFn, TMoostAdapter, Moost, TMoostAdapterOptions } from 'moost';
|
|
5
|
-
import * as _prostojs_logger from '@prostojs/logger';
|
|
5
|
+
import { TInterceptorFn, TMoostAdapter, Moost, TConsoleBase, TMoostAdapterOptions } from 'moost';
|
|
6
6
|
import * as _prostojs_infact from '@prostojs/infact';
|
|
7
7
|
import * as http from 'http';
|
|
8
8
|
import { TProstoRouterPathBuilder } from '@prostojs/router';
|
|
@@ -16,119 +16,26 @@ declare const Put: (path?: string) => MethodDecorator;
|
|
|
16
16
|
declare const Delete: (path?: string) => MethodDecorator;
|
|
17
17
|
declare const Patch: (path?: string) => MethodDecorator;
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Hook to the Response Status
|
|
21
|
-
* @decorator
|
|
22
|
-
* @paramType TStatusHook
|
|
23
|
-
*/
|
|
24
19
|
declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
|
|
25
|
-
/**
|
|
26
|
-
* Hook to the Response Header
|
|
27
|
-
* @decorator
|
|
28
|
-
* @param name - header name
|
|
29
|
-
* @paramType THeaderHook
|
|
30
|
-
*/
|
|
31
20
|
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
|
-
*/
|
|
38
21
|
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
|
-
*/
|
|
45
22
|
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
|
-
*/
|
|
52
23
|
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
|
-
*/
|
|
59
24
|
declare function Header(name: string): ParameterDecorator & PropertyDecorator;
|
|
60
|
-
/**
|
|
61
|
-
* Get Request Cookie Value
|
|
62
|
-
* @decorator
|
|
63
|
-
* @param name - cookie name
|
|
64
|
-
* @paramType string
|
|
65
|
-
*/
|
|
66
25
|
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
|
-
*/
|
|
73
26
|
declare function Query(name?: string): ParameterDecorator;
|
|
74
|
-
/**
|
|
75
|
-
* Get Requested URL
|
|
76
|
-
* @decorator
|
|
77
|
-
* @paramType string
|
|
78
|
-
*/
|
|
79
27
|
declare function Url(): ParameterDecorator & PropertyDecorator;
|
|
80
|
-
/**
|
|
81
|
-
* Get Requested HTTP Method
|
|
82
|
-
* @decorator
|
|
83
|
-
* @paramType string
|
|
84
|
-
*/
|
|
85
28
|
declare function Method(): ParameterDecorator & PropertyDecorator;
|
|
86
|
-
/**
|
|
87
|
-
* Get Raw Request Instance
|
|
88
|
-
* @decorator
|
|
89
|
-
* @paramType IncomingMessage
|
|
90
|
-
*/
|
|
91
29
|
declare function Req(): ParameterDecorator & PropertyDecorator;
|
|
92
|
-
/**
|
|
93
|
-
* Get Raw Response Instance
|
|
94
|
-
* @decorator
|
|
95
|
-
* @param opts (optional) { passthrough: boolean }
|
|
96
|
-
* @paramType ServerResponse
|
|
97
|
-
*/
|
|
98
30
|
declare function Res(opts?: {
|
|
99
31
|
passthrough: boolean;
|
|
100
32
|
}): ParameterDecorator & PropertyDecorator;
|
|
101
|
-
/**
|
|
102
|
-
* Get Request Unique Identificator (UUID)
|
|
103
|
-
* @decorator
|
|
104
|
-
* @paramType string
|
|
105
|
-
*/
|
|
106
33
|
declare function ReqId(): ParameterDecorator & PropertyDecorator;
|
|
107
|
-
/**
|
|
108
|
-
* Get Request IP Address
|
|
109
|
-
* @decorator
|
|
110
|
-
* @paramType string
|
|
111
|
-
*/
|
|
112
34
|
declare function Ip(opts?: {
|
|
113
35
|
trustProxy: boolean;
|
|
114
36
|
}): ParameterDecorator & PropertyDecorator;
|
|
115
|
-
/**
|
|
116
|
-
* Get Request IP Address list
|
|
117
|
-
* @decorator
|
|
118
|
-
* @paramType string[]
|
|
119
|
-
*/
|
|
120
37
|
declare function IpList(): ParameterDecorator & PropertyDecorator;
|
|
121
|
-
/**
|
|
122
|
-
* Get Parsed Request Body
|
|
123
|
-
* @decorator
|
|
124
|
-
* @paramType object | string | unknown
|
|
125
|
-
*/
|
|
126
38
|
declare function Body(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
127
|
-
/**
|
|
128
|
-
* Get Raw Request Body Buffer
|
|
129
|
-
* @decorator
|
|
130
|
-
* @paramType Promise<Buffer>
|
|
131
|
-
*/
|
|
132
39
|
declare function RawBody(): ParameterDecorator & PropertyDecorator;
|
|
133
40
|
type TStatusHook = THook<number>;
|
|
134
41
|
type THeaderHook = THook;
|
|
@@ -140,120 +47,18 @@ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
|
|
|
140
47
|
status?: number;
|
|
141
48
|
when?: 'always' | 'error' | 'ok';
|
|
142
49
|
}) => 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
|
-
*/
|
|
180
50
|
declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator;
|
|
181
51
|
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
|
-
*/
|
|
203
52
|
declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
|
|
204
53
|
declare const setStatusInterceptor: (code: number, opts?: {
|
|
205
54
|
force?: boolean;
|
|
206
55
|
}) => 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
|
-
*/
|
|
226
56
|
declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator;
|
|
227
57
|
|
|
228
58
|
interface THttpHandlerMeta {
|
|
229
59
|
method: string;
|
|
230
60
|
path: string;
|
|
231
61
|
}
|
|
232
|
-
/**
|
|
233
|
-
* ## Moost HTTP Adapter
|
|
234
|
-
*
|
|
235
|
-
* Moost Adapter for HTTP events
|
|
236
|
-
*
|
|
237
|
-
* ```ts
|
|
238
|
-
* │ // HTTP server example
|
|
239
|
-
* │ import { MoostHttp, Get } from '@moostjs/event-http'
|
|
240
|
-
* │ import { Moost, Param } from 'moost'
|
|
241
|
-
* │
|
|
242
|
-
* │ class MyServer extends Moost {
|
|
243
|
-
* │ @Get('test/:name')
|
|
244
|
-
* │ test(@Param('name') name: string) {
|
|
245
|
-
* │ return { message: `Hello ${name}!` }
|
|
246
|
-
* │ }
|
|
247
|
-
* │ }
|
|
248
|
-
* │
|
|
249
|
-
* │ const app = new MyServer()
|
|
250
|
-
* │ const http = new MoostHttp()
|
|
251
|
-
* │ app.adapter(http).listen(3000, () => {
|
|
252
|
-
* │ app.getLogger('MyApp').log('Up on port 3000')
|
|
253
|
-
* │ })
|
|
254
|
-
* │ app.init()
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
62
|
declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
258
63
|
readonly name = "http";
|
|
259
64
|
protected httpApp: WooksHttp;
|
|
@@ -280,7 +85,7 @@ declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
|
|
|
280
85
|
protected moost?: Moost;
|
|
281
86
|
onInit(moost: Moost): void;
|
|
282
87
|
getProvideRegistry(): _prostojs_infact.TProvideRegistry;
|
|
283
|
-
getLogger():
|
|
88
|
+
getLogger(): TConsoleBase;
|
|
284
89
|
bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void;
|
|
285
90
|
}
|
|
286
91
|
|