@moostjs/event-http 0.3.10 → 0.3.12

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.d.ts CHANGED
@@ -1,329 +1,279 @@
1
- /// <reference types="node" />
2
-
3
- import { HttpError } from '@wooksjs/event-http';
4
- import { IncomingMessage } from 'http';
5
- import { Moost } from 'moost';
6
- import { ServerResponse } from 'http';
7
- import { TConsoleBase } from '@prostojs/logger';
8
- import { TCookieAttributes as TCookieAttributes_2 } from '@wooksjs/event-http';
9
- import { TCookieAttributesInput } from '@wooksjs/event-http';
10
- import { THook } from '@wooksjs/event-core';
11
- import { TInterceptorFn } from 'moost';
12
- import { TMoostAdapter } from 'moost';
13
- import { TMoostAdapterOptions } from 'moost';
14
- import { TProstoRouterPathBuilder } from '@prostojs/router';
15
- import { TProvideRegistry } from '@prostojs/infact';
16
- import { TWooksHttpOptions } from '@wooksjs/event-http';
17
- import { useHttpContext } from '@wooksjs/event-http';
18
- import { useSetCookies } from '@wooksjs/event-http';
19
- import { WooksHttp } from '@wooksjs/event-http';
20
-
21
- export declare const All: (path?: string) => MethodDecorator;
22
-
23
- /**
24
- * Parse Authorisation Header
25
- * @decorator
26
- * @param name - define what to take from the Auth header
27
- * @paramType string
28
- */
29
- export declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator & PropertyDecorator;
30
-
31
- /**
32
- * Get Parsed Request Body
33
- * @decorator
34
- * @paramType object | string | unknown
35
- */
36
- declare function Body_2(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
37
- export { Body_2 as Body }
38
-
39
- /**
40
- * Get Request Cookie Value
41
- * @decorator
42
- * @param name - cookie name
43
- * @paramType string
44
- */
45
- export declare function Cookie(name: string): ParameterDecorator & PropertyDecorator;
46
-
47
- /**
48
- * Hook to the Response Cookie Attributes
49
- * @decorator
50
- * @param name - cookie name
51
- * @paramType TCookieAttributes
52
- */
53
- export declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator;
54
-
55
- /**
56
- * Hook to the Response Cookie
57
- * @decorator
58
- * @param name - cookie name
59
- * @paramType TCookieHook
60
- */
61
- export declare const CookieHook: (name: string) => ParameterDecorator & PropertyDecorator;
62
-
63
- export declare const Delete: (path?: string) => MethodDecorator;
64
-
65
- export declare const Get: (path?: string) => MethodDecorator;
66
-
67
- /**
68
- * Get Request Header Value
69
- * @decorator
70
- * @param name - header name
71
- * @paramType string
72
- */
73
- export declare function Header(name: string): ParameterDecorator & PropertyDecorator;
74
-
75
- /**
76
- * Hook to the Response Header
77
- * @decorator
78
- * @param name - header name
79
- * @paramType THeaderHook
80
- */
81
- export declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator;
82
-
83
- export { HttpError }
84
-
85
- export declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
86
-
87
- /**
88
- * Get Request IP Address
89
- * @decorator
90
- * @paramType string
91
- */
92
- export declare function Ip(opts?: {
93
- trustProxy: boolean;
94
- }): ParameterDecorator & PropertyDecorator;
95
-
96
- /**
97
- * Get Request IP Address list
98
- * @decorator
99
- * @paramType string[]
100
- */
101
- export declare function IpList(): ParameterDecorator & PropertyDecorator;
102
-
103
- /**
104
- * Get Requested HTTP Method
105
- * @decorator
106
- * @paramType string
107
- */
108
- export declare function Method(): ParameterDecorator & PropertyDecorator;
109
-
110
- /**
111
- * ## Moost HTTP Adapter
112
- *
113
- * Moost Adapter for HTTP events
114
- *
115
- * ```ts
116
- * │ // HTTP server example
117
- * │ import { MoostHttp, Get } from '@moostjs/event-http'
118
- * │ import { Moost, Param } from 'moost'
119
- *
120
- * │ class MyServer extends Moost {
121
- * @Get('test/:name')
122
- * │ test(@Param('name') name: string) {
123
- * │ return { message: `Hello ${name}!` }
124
- * │ }
125
- * │ }
126
- *
127
- * │ const app = new MyServer()
128
- * │ const http = new MoostHttp()
129
- * │ app.adapter(http).listen(3000, () => {
130
- * │ app.getLogger('MyApp').log('Up on port 3000')
131
- * │ })
132
- * │ app.init()
133
- * ```
134
- */
135
- export declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
136
- protected httpApp: WooksHttp;
137
- constructor(httpApp?: WooksHttp | TWooksHttpOptions);
138
- getHttpApp(): WooksHttp;
139
- getServerCb(): (req: IncomingMessage, res: ServerResponse<IncomingMessage>) => Promise<void>;
140
- listen(...args: Parameters<WooksHttp['listen']>): Promise<unknown>;
141
- readonly pathBuilders: {
142
- [id: string]: {
143
- GET?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
144
- PUT?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
145
- PATCH?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
146
- POST?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
147
- DELETE?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
148
- };
149
- };
150
- onNotFound(): Promise<{}>;
151
- protected moost?: Moost;
152
- onInit(moost: Moost): void;
153
- getProvideRegistry(): TProvideRegistry;
154
- getLogger(): TConsoleBase;
155
- bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void;
156
- }
157
-
158
- export declare const Patch: (path?: string) => MethodDecorator;
159
-
160
- export declare const Post: (path?: string) => MethodDecorator;
161
-
162
- export declare const Put: (path?: string) => MethodDecorator;
163
-
164
- /**
165
- * Get Query Item value or the whole parsed Query as an object
166
- * @decorator
167
- * @param name - query item name (optional)
168
- * @paramType string | object
169
- */
170
- export declare function Query(name?: string): ParameterDecorator;
171
-
172
- /**
173
- * Get Raw Request Body Buffer
174
- * @decorator
175
- * @paramType Promise<Buffer>
176
- */
177
- export declare function RawBody(): ParameterDecorator & PropertyDecorator;
178
-
179
- /**
180
- * Get Raw Request Instance
181
- * @decorator
182
- * @paramType IncomingMessage
183
- */
184
- export declare function Req(): ParameterDecorator & PropertyDecorator;
185
-
186
- /**
187
- * Get Request Unique Identificator (UUID)
188
- * @decorator
189
- * @paramType string
190
- */
191
- export declare function ReqId(): ParameterDecorator & PropertyDecorator;
192
-
193
- /**
194
- * Get Raw Response Instance
195
- * @decorator
196
- * @param opts (optional) { passthrough: boolean }
197
- * @paramType ServerResponse
198
- */
199
- export declare function Res(opts?: {
200
- passthrough: boolean;
201
- }): ParameterDecorator & PropertyDecorator;
202
-
203
- /**
204
- * Set Cookie for Request Handler
205
- * ```ts
206
- * import { Get, SetCookie } from '@moostjs/event-http';
207
- * import { Controller } from 'moost';
208
- *
209
- * @Controller()
210
- * export class ExampleController {
211
- * @Get('test')
212
- * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
213
- * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
214
- * testHandler() {
215
- * return '...'
216
- * }
217
- * }
218
- * ```
219
- *
220
- * @param name name of cookie
221
- * @param value value for cookie
222
- * @param attrs cookie attributes
223
- */
224
- export declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
225
-
226
- declare const setCookieInterceptor: (...args: Parameters<ReturnType<typeof useSetCookies>['setCookie']>) => TInterceptorFn;
227
-
228
- /**
229
- * Set Header for Request Handler
230
- *
231
- * ```ts
232
- * import { Get, SetHeader } from '@moostjs/event-http';
233
- * import { Controller } from 'moost';
234
- *
235
- * @Controller()
236
- * export class ExampleController {
237
- * @Get('test')
238
- * // setting header for request handler
239
- * @SetHeader('x-server', 'my-server')
240
- * testHandler() {
241
- * return '...'
242
- * }
243
- * }
244
- * ```
245
- *
246
- * ```ts
247
- * import { Get, SetHeader } from '@moostjs/event-http';
248
- * import { Controller } from 'moost';
249
- *
250
- * @Controller()
251
- * export class ExampleController {
252
- * @Get('test')
253
- * // setting header only if status = 400
254
- * @SetHeader('content-type', 'text/plain', { status: 400 })
255
- * testHandler() {
256
- * return '...'
257
- * }
258
- * }
259
- * ```
260
- *
261
- * @param name name of header
262
- * @param value value for header
263
- * @param options options { status?: number, force?: boolean }
264
- */
265
- export declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator;
266
-
267
- declare const setHeaderInterceptor: (name: string, value: string, opts?: {
268
- force?: boolean;
269
- status?: number;
270
- when?: 'always' | 'error' | 'ok';
271
- }) => TInterceptorFn;
272
-
273
- /**
274
- * Set Response Status for Request Handler
275
- *
276
- * ```ts
277
- * import { Get, SetStatus } from '@moostjs/event-http';
278
- * import { Controller } from 'moost';
279
- *
280
- * @Controller()
281
- * export class ExampleController {
282
- * @Get('test')
283
- * @SetStatus(201)
284
- * testHandler() {
285
- * return '...'
286
- * }
287
- * }
288
- * ```
289
- * @param code number
290
- * @param opts optional { force?: boolean }
291
- */
292
- export declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator;
293
-
294
- declare const setStatusInterceptor: (code: number, opts?: {
295
- force?: boolean;
296
- }) => TInterceptorFn;
297
-
298
- /**
299
- * Hook to the Response Status
300
- * @decorator
301
- * @paramType TStatusHook
302
- */
303
- export declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
304
-
305
- export declare type TCookieAttributes = Partial<TCookieAttributes_2>;
306
-
307
- export { TCookieAttributesInput }
308
-
309
- export declare type TCookieHook = THook & Partial<THook<TCookieAttributes, 'attrs'>>;
310
-
311
- export declare type THeaderHook = THook;
312
-
313
- export declare interface THttpHandlerMeta {
314
- method: string;
315
- path: string;
316
- }
317
-
318
- export declare type TStatusHook = THook<number>;
319
-
320
- /**
321
- * Get Requested URL
322
- * @decorator
323
- * @paramType string
324
- */
325
- export declare function Url(): ParameterDecorator & PropertyDecorator;
326
-
327
- export { useHttpContext }
328
-
329
- export { }
1
+ import * as _prostojs_logger from '@prostojs/logger';
2
+ import * as moost from 'moost';
3
+ import { TMoostAdapter, Moost, TMoostAdapterOptions, TInterceptorFn } from 'moost';
4
+ import * as http from 'http';
5
+ import { WooksHttp, TWooksHttpOptions, TCookieAttributes as TCookieAttributes$1, useSetCookies } from '@wooksjs/event-http';
6
+ export { HttpError, TCookieAttributesInput, useHttpContext } from '@wooksjs/event-http';
7
+ import { TProstoRouterPathBuilder } from '@prostojs/router';
8
+ import { THook } from '@wooksjs/event-core';
9
+
10
+ interface THttpHandlerMeta {
11
+ method: string;
12
+ path: string;
13
+ }
14
+ /**
15
+ * ## Moost HTTP Adapter
16
+ *
17
+ * Moost Adapter for HTTP events
18
+ *
19
+ * ```ts
20
+ * │ // HTTP server example
21
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
22
+ * │ import { Moost, Param } from 'moost'
23
+ * │
24
+ * │ class MyServer extends Moost {
25
+ * @Get('test/:name')
26
+ * │ test(@Param('name') name: string) {
27
+ * │ return { message: `Hello ${name}!` }
28
+ * │ }
29
+ * │ }
30
+ * │
31
+ * │ const app = new MyServer()
32
+ * │ const http = new MoostHttp()
33
+ * │ app.adapter(http).listen(3000, () => {
34
+ * │ app.getLogger('MyApp').log('Up on port 3000')
35
+ * │ })
36
+ * │ app.init()
37
+ * ```
38
+ */
39
+ declare class MoostHttp implements TMoostAdapter<THttpHandlerMeta> {
40
+ protected httpApp: WooksHttp;
41
+ constructor(httpApp?: WooksHttp | TWooksHttpOptions);
42
+ getHttpApp(): WooksHttp;
43
+ getServerCb(): (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => Promise<void>;
44
+ listen(...args: Parameters<WooksHttp['listen']>): Promise<unknown>;
45
+ readonly pathBuilders: {
46
+ [id: string]: {
47
+ GET?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
48
+ PUT?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
49
+ PATCH?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
50
+ POST?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
51
+ DELETE?: TProstoRouterPathBuilder<Record<string, string | string[]>>;
52
+ };
53
+ };
54
+ onNotFound(): Promise<{}>;
55
+ protected moost?: Moost;
56
+ onInit(moost: Moost): void;
57
+ getProvideRegistry(): moost.TProvideRegistry;
58
+ getLogger(): _prostojs_logger.TConsoleBase;
59
+ bindHandler<T extends object = object>(opts: TMoostAdapterOptions<THttpHandlerMeta, T>): void;
60
+ }
61
+
62
+ declare function HttpMethod(method: '*' | 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS', path?: string): MethodDecorator;
63
+ declare const All: (path?: string) => MethodDecorator;
64
+ declare const Get: (path?: string) => MethodDecorator;
65
+ declare const Post: (path?: string) => MethodDecorator;
66
+ declare const Put: (path?: string) => MethodDecorator;
67
+ declare const Delete: (path?: string) => MethodDecorator;
68
+ declare const Patch: (path?: string) => MethodDecorator;
69
+
70
+ /**
71
+ * Hook to the Response Status
72
+ * @decorator
73
+ * @paramType TStatusHook
74
+ */
75
+ declare const StatusHook: () => ParameterDecorator & PropertyDecorator;
76
+ /**
77
+ * Hook to the Response Header
78
+ * @decorator
79
+ * @param name - header name
80
+ * @paramType THeaderHook
81
+ */
82
+ declare const HeaderHook: (name: string) => ParameterDecorator & PropertyDecorator;
83
+ /**
84
+ * Hook to the Response Cookie
85
+ * @decorator
86
+ * @param name - cookie name
87
+ * @paramType TCookieHook
88
+ */
89
+ declare const CookieHook: (name: string) => ParameterDecorator & PropertyDecorator;
90
+ /**
91
+ * Hook to the Response Cookie Attributes
92
+ * @decorator
93
+ * @param name - cookie name
94
+ * @paramType TCookieAttributes
95
+ */
96
+ declare const CookieAttrsHook: (name: string) => ParameterDecorator & PropertyDecorator;
97
+ /**
98
+ * Parse Authorisation Header
99
+ * @decorator
100
+ * @param name - define what to take from the Auth header
101
+ * @paramType string
102
+ */
103
+ declare function Authorization(name: 'username' | 'password' | 'bearer' | 'raw' | 'type'): ParameterDecorator & PropertyDecorator;
104
+ /**
105
+ * Get Request Header Value
106
+ * @decorator
107
+ * @param name - header name
108
+ * @paramType string
109
+ */
110
+ declare function Header(name: string): ParameterDecorator & PropertyDecorator;
111
+ /**
112
+ * Get Request Cookie Value
113
+ * @decorator
114
+ * @param name - cookie name
115
+ * @paramType string
116
+ */
117
+ declare function Cookie(name: string): ParameterDecorator & PropertyDecorator;
118
+ /**
119
+ * Get Query Item value or the whole parsed Query as an object
120
+ * @decorator
121
+ * @param name - query item name (optional)
122
+ * @paramType string | object
123
+ */
124
+ declare function Query(name?: string): ParameterDecorator;
125
+ /**
126
+ * Get Requested URL
127
+ * @decorator
128
+ * @paramType string
129
+ */
130
+ declare function Url(): ParameterDecorator & PropertyDecorator;
131
+ /**
132
+ * Get Requested HTTP Method
133
+ * @decorator
134
+ * @paramType string
135
+ */
136
+ declare function Method(): ParameterDecorator & PropertyDecorator;
137
+ /**
138
+ * Get Raw Request Instance
139
+ * @decorator
140
+ * @paramType IncomingMessage
141
+ */
142
+ declare function Req(): ParameterDecorator & PropertyDecorator;
143
+ /**
144
+ * Get Raw Response Instance
145
+ * @decorator
146
+ * @param opts (optional) { passthrough: boolean }
147
+ * @paramType ServerResponse
148
+ */
149
+ declare function Res(opts?: {
150
+ passthrough: boolean;
151
+ }): ParameterDecorator & PropertyDecorator;
152
+ /**
153
+ * Get Request Unique Identificator (UUID)
154
+ * @decorator
155
+ * @paramType string
156
+ */
157
+ declare function ReqId(): ParameterDecorator & PropertyDecorator;
158
+ /**
159
+ * Get Request IP Address
160
+ * @decorator
161
+ * @paramType string
162
+ */
163
+ declare function Ip(opts?: {
164
+ trustProxy: boolean;
165
+ }): ParameterDecorator & PropertyDecorator;
166
+ /**
167
+ * Get Request IP Address list
168
+ * @decorator
169
+ * @paramType string[]
170
+ */
171
+ declare function IpList(): ParameterDecorator & PropertyDecorator;
172
+ /**
173
+ * Get Parsed Request Body
174
+ * @decorator
175
+ * @paramType object | string | unknown
176
+ */
177
+ declare function Body(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
178
+ /**
179
+ * Get Raw Request Body Buffer
180
+ * @decorator
181
+ * @paramType Promise<Buffer>
182
+ */
183
+ declare function RawBody(): ParameterDecorator & PropertyDecorator;
184
+ type TStatusHook = THook<number>;
185
+ type THeaderHook = THook;
186
+ type TCookieAttributes = Partial<TCookieAttributes$1>;
187
+ type TCookieHook = THook & Partial<THook<TCookieAttributes, 'attrs'>>;
188
+
189
+ declare const setHeaderInterceptor: (name: string, value: string, opts?: {
190
+ force?: boolean;
191
+ status?: number;
192
+ when?: 'always' | 'error' | 'ok';
193
+ }) => TInterceptorFn;
194
+ /**
195
+ * Set Header for Request Handler
196
+ *
197
+ * ```ts
198
+ * import { Get, SetHeader } from '@moostjs/event-http';
199
+ * import { Controller } from 'moost';
200
+ *
201
+ * @Controller()
202
+ * export class ExampleController {
203
+ * @Get('test')
204
+ * // setting header for request handler
205
+ * @SetHeader('x-server', 'my-server')
206
+ * testHandler() {
207
+ * return '...'
208
+ * }
209
+ * }
210
+ * ```
211
+ *
212
+ * ```ts
213
+ * import { Get, SetHeader } from '@moostjs/event-http';
214
+ * import { Controller } from 'moost';
215
+ *
216
+ * @Controller()
217
+ * export class ExampleController {
218
+ * @Get('test')
219
+ * // setting header only if status = 400
220
+ * @SetHeader('content-type', 'text/plain', { status: 400 })
221
+ * testHandler() {
222
+ * return '...'
223
+ * }
224
+ * }
225
+ * ```
226
+ *
227
+ * @param name name of header
228
+ * @param value value for header
229
+ * @param options options { status?: number, force?: boolean }
230
+ */
231
+ declare function SetHeader(...args: Parameters<typeof setHeaderInterceptor>): ClassDecorator & MethodDecorator;
232
+ declare const setCookieInterceptor: (...args: Parameters<ReturnType<typeof useSetCookies>['setCookie']>) => TInterceptorFn;
233
+ /**
234
+ * Set Cookie for Request Handler
235
+ * ```ts
236
+ * import { Get, SetCookie } from '@moostjs/event-http';
237
+ * import { Controller } from 'moost';
238
+ *
239
+ * @Controller()
240
+ * export class ExampleController {
241
+ * @Get('test')
242
+ * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
243
+ * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
244
+ * testHandler() {
245
+ * return '...'
246
+ * }
247
+ * }
248
+ * ```
249
+ *
250
+ * @param name name of cookie
251
+ * @param value value for cookie
252
+ * @param attrs cookie attributes
253
+ */
254
+ declare function SetCookie(...args: Parameters<typeof setCookieInterceptor>): ClassDecorator & MethodDecorator;
255
+ declare const setStatusInterceptor: (code: number, opts?: {
256
+ force?: boolean;
257
+ }) => TInterceptorFn;
258
+ /**
259
+ * Set Response Status for Request Handler
260
+ *
261
+ * ```ts
262
+ * import { Get, SetStatus } from '@moostjs/event-http';
263
+ * import { Controller } from 'moost';
264
+ *
265
+ * @Controller()
266
+ * export class ExampleController {
267
+ * @Get('test')
268
+ * @SetStatus(201)
269
+ * testHandler() {
270
+ * return '...'
271
+ * }
272
+ * }
273
+ * ```
274
+ * @param code number
275
+ * @param opts optional { force?: boolean }
276
+ */
277
+ declare function SetStatus(...args: Parameters<typeof setStatusInterceptor>): ClassDecorator & MethodDecorator;
278
+
279
+ 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, type TCookieAttributes, type TCookieHook, type THeaderHook, type THttpHandlerMeta, type TStatusHook, Url };