-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrequestAdapter.ts
137 lines (133 loc) · 5.61 KB
/
requestAdapter.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
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
import type { DateOnly } from "./dateOnly";
import type { Duration } from "./duration";
import { type RequestInformation } from "./requestInformation";
import type {
Parsable,
ParsableFactory,
SerializationWriterFactory,
} from "./serialization";
import { type BackingStoreFactory } from "./store";
import type { TimeOnly } from "./timeOnly";
/** Service responsible for translating abstract Request Info into concrete native HTTP requests. */
export interface RequestAdapter {
/**
* Gets the serialization writer factory currently in use for the HTTP core service.
* @return the serialization writer factory currently in use for the HTTP core service.
*/
getSerializationWriterFactory(): SerializationWriterFactory;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
* @param requestInfo the request info to execute.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param type the class of the response model to deserialize the response into.
* @typeParam ModelType the type of the response model to deserialize the response into.
* @return a {@link Promise} with the deserialized response model.
*/
send<ModelType extends Parsable>(
requestInfo: RequestInformation,
type: ParsableFactory<ModelType>,
errorMappings: ErrorMappings | undefined,
): Promise<ModelType | undefined>;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
* @param requestInfo the request info to execute.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param type the class of the response model to deserialize the response into.
* @typeParam ModelType the type of the response model to deserialize the response into.
* @return a {@link Promise} with the deserialized response model collection.
*/
sendCollection<ModelType extends Parsable>(
requestInfo: RequestInformation,
type: ParsableFactory<ModelType>,
errorMappings: ErrorMappings | undefined,
): Promise<ModelType[] | undefined>;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
* @param requestInfo the request info to execute.
* @param responseType the class of the response model to deserialize the response into.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param type the class of the response model to deserialize the response into.
* @typeParam ResponseType the type of the response model to deserialize the response into.
* @return a {@link Promise} with the deserialized response model collection.
*/
sendCollectionOfPrimitive<
ResponseType extends Exclude<
PrimitiveTypesForDeserializationType,
ArrayBuffer
>,
>(
requestInfo: RequestInformation,
responseType: Exclude<PrimitiveTypesForDeserialization, "ArrayBuffer">,
errorMappings: ErrorMappings | undefined,
): Promise<ResponseType[] | undefined>;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
* @param requestInfo the request info to execute.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @param responseType the class of the response model to deserialize the response into.
* @typeParam ResponseType the type of the response model to deserialize the response into.
* @return a {@link Promise} with the deserialized primitive response model.
*/
sendPrimitive<ResponseType extends PrimitiveTypesForDeserializationType>(
requestInfo: RequestInformation,
responseType: PrimitiveTypesForDeserialization,
errorMappings: ErrorMappings | undefined,
): Promise<ResponseType | undefined>;
/**
* Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
* @param requestInfo the request info to execute.
* @param errorMappings the error factories mapping to use in case of a failed request.
* @return a {@link Promise} of void.
*/
sendNoResponseContent(
requestInfo: RequestInformation,
errorMappings: ErrorMappings | undefined,
): Promise<void>;
/**
* Enables the backing store proxies for the SerializationWriters and ParseNodes in use.
* @param backingStoreFactory the backing store factory to use.
*/
enableBackingStore(
backingStoreFactory?: BackingStoreFactory | undefined,
): void;
/** The base url for every request. */
baseUrl: string;
/**
* Converts the given RequestInformation into a native HTTP request used by the implementing adapter.
* @param requestInfo the request info to convert.
* @typeParam T the type of the native request.
* @return a {@link Promise} with the native request.
*/
convertToNativeRequest<T>(requestInfo: RequestInformation): Promise<T>;
}
export interface ErrorMappings {
_4XX?: ParsableFactory<Parsable>;
_5XX?: ParsableFactory<Parsable>;
XXX?: ParsableFactory<Parsable>;
[key: number]: ParsableFactory<Parsable>;
}
export type PrimitiveTypesForDeserializationType =
| string
| number
| boolean
| Date
| DateOnly
| TimeOnly
| Duration
| ArrayBuffer;
export type PrimitiveTypesForDeserialization =
| "string"
| "number"
| "boolean"
| "Date"
| "DateOnly"
| "TimeOnly"
| "Duration"
| "ArrayBuffer";
export type SendMethods = Exclude<
keyof RequestAdapter,
| "enableBackingStore"
| "getSerializationWriterFactory"
| "convertToNativeRequest"
| "baseUrl"
>;