-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtypings.ts
More file actions
149 lines (134 loc) · 3.95 KB
/
typings.ts
File metadata and controls
149 lines (134 loc) · 3.95 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { AxiosRequestConfig, AxiosResponse } from 'axios'
import { Middleware } from 'koa-compose'
import { Span } from 'opentracing'
import { CacheLayer } from '../caches/CacheLayer'
import { MetricsAccumulator } from '../metrics/MetricsAccumulator'
import { IOContext } from '../service/worker/runtime/typings'
import { SpanReferenceTypes } from '../tracing'
import { IUserLandTracer } from '../tracing/UserLandTracer'
import { Cached, CacheType } from './middlewares/cache'
export type InflightKeyGenerator = (x: RequestConfig) => string
interface RequestTracingUserConfig {
rootSpan?: Span
referenceType?: SpanReferenceTypes
requestSpanNameSuffix?: string
}
export interface RequestTracingConfig {
tracing?: RequestTracingUserConfig
}
export interface RequestConfig extends AxiosRequestConfig, RequestTracingConfig {
retries?: number
exponentialTimeoutCoefficient?: number
initialBackoffDelay?: number
exponentialBackoffCoefficient?: number
retryCount?: number
/**
* Identifies the type of request for metrification purposes. Should vary with client method.
*/
metric?: string
/**
* In verbose mode, a counter will be incremented for each request made with the same `metric` label.
*/
count?: number
/**
* In verbose mode, a label will be created with a counter for each request made with the same `metric` label.
*/
label?: string
/**
* Outputs verbose logs to console for this request.
*/
verbose?: boolean
production?: boolean
cacheable?: CacheType
memoizeable?: boolean
inflightKey?: InflightKeyGenerator
forceMaxAge?: number
responseEncoding?: BufferEncoding
nullIfNotFound?: boolean
ignoreRecorder?: boolean
localCacheOptions?: LocalCacheOptions
}
export type LocalCacheOptions = Record<string, unknown>
export interface CacheHit {
disk?: 0 | 1
memory?: 0 | 1
revalidated?: 0 | 1
router?: 0 | 1
}
export interface MiddlewaresTracingContext extends Omit<RequestTracingUserConfig, 'rootSpan'> {
tracer: IUserLandTracer
logger: IOContext['logger']
rootSpan?: Span
isSampled: boolean
}
export interface MiddlewareContext {
config: RequestConfig
tracing?: MiddlewaresTracingContext
response?: AxiosResponse
cacheHit?: CacheHit
inflightHit?: boolean
memoizedHit?: boolean
}
export type CacheStorage = CacheLayer<string, Cached>
export interface InstanceOptions {
authType?: AuthType
timeout?: number
memoryCache?: CacheLayer<string, Cached>
diskCache?: CacheLayer<string, Cached>
/**
* Enables memoization, ephemeral within each request, for all requests of this client.
* Useful for services that makes recursive requests, like graphql resolvers, which
* might fetch the same endpoint more than once.
* If that's not the case for your service, disabling it might improve the CPU and
* memory usage.
*
* Default value: true
*/
memoizable?: boolean
baseURL?: string
retries?: number
exponentialTimeoutCoefficient?: number
initialBackoffDelay?: number
exponentialBackoffCoefficient?: number
metrics?: MetricsAccumulator
/**
* Maximum number of concurrent requests
*
* @type {number}
* @memberof InstanceOptions
*/
concurrency?: number
/**
* Default headers to be sent with every request
*
* @type {Record<string, string>}
* @memberof InstanceOptions
*/
headers?: Record<string, string>
/**
* Default query string parameters to be sent with every request
*
* @type {Record<string, string>}
* @memberof InstanceOptions
*/
params?: Record<string, string>
middlewares?: Array<Middleware<MiddlewareContext>>
verbose?: boolean
name?: string
serverTimings?: Record<string, string>
httpsAgent?: AxiosRequestConfig['httpsAgent']
cacheableType?: CacheType
}
export interface IOResponse<T> {
data: T
headers: Record<string, string>
status: number
}
export enum AuthType {
basic = 'Basic',
bearer = 'Bearer',
/**
* Supported for legacy reasons - this is not spec compliant!
*/
token = 'token',
}