-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.d.ts
45 lines (34 loc) · 1.29 KB
/
utils.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { FastifyRequest, FastifyReply, FastifyError } from "fastify"
export enum RequestKeys {
'headers',
'method',
'protocol',
'url',
'cookies',
'query_string',
'data'
}
export enum TransactionSource {
'url',
'route'
}
export type RequestData = {
headers?: FastifyRequest['headers'] | any,
method?: FastifyRequest['method'] | any,
protocol?: FastifyRequest['protocol'] | any,
cookies?: Record<string, string>,
query_string?: FastifyRequest['query'] | any,
data?: string
} & Record<string, any>
export type UserData = {
id?: string | number,
username: string,
email?: string
} & Record<string, any>
export function tryToExtractBody (request: FastifyRequest): string
export function extractRequestData(request: FastifyRequest, keys: RequestKeys): RequestData
export function extractUserData(request: FastifyRequest): UserData
export function getTransactionName(request: FastifyRequest): string
export function extractPathForTransaction(request: FastifyRequest, getName: typeof getTransactionName): [string, TransactionSource]
export function shouldHandleError(error: FastifyError, request: FastifyRequest, reply: FastifyReply): boolean
export function errorResponse(error: FastifyError, request: FastifyRequest, reply: FastifyReply): void