@prover-coder-ai/openapi-effect 1.0.19 → 1.0.21
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/README.md +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +16 -11
- package/src/shell/api-client/create-client-middleware.ts +179 -0
- package/src/shell/api-client/create-client-response.ts +115 -0
- package/src/shell/api-client/create-client-runtime-helpers.ts +142 -0
- package/src/shell/api-client/create-client-runtime-types.ts +97 -0
- package/src/shell/api-client/create-client-runtime.ts +316 -0
- package/src/shell/api-client/create-client-types.ts +278 -286
- package/src/shell/api-client/create-client.ts +89 -496
- package/src/shell/api-client/index.ts +28 -1
- package/src/shell/api-client/openapi-compat-path.ts +82 -0
- package/src/shell/api-client/openapi-compat-request.ts +153 -0
- package/src/shell/api-client/openapi-compat-serializers.ts +277 -0
- package/src/shell/api-client/openapi-compat-utils.ts +10 -0
- package/src/shell/api-client/openapi-compat-value-guards.ts +9 -0
|
@@ -1,310 +1,302 @@
|
|
|
1
|
-
// CHANGE: Extract public createClient types into dedicated module
|
|
2
|
-
// WHY: Keep create-client.ts under lint max-lines without weakening type-level invariants
|
|
3
|
-
// QUOTE(ТЗ): "Только прогони по всему проекту линтеры"
|
|
4
|
-
// REF: user-msg-2
|
|
5
|
-
// SOURCE: n/a
|
|
6
|
-
// PURITY: CORE
|
|
7
|
-
// EFFECT: none
|
|
8
|
-
// INVARIANT: All type-level correlations remain unchanged
|
|
9
|
-
// COMPLEXITY: O(1) compile-time / O(0) runtime
|
|
10
|
-
|
|
11
|
-
import type * as HttpClient from "@effect/platform/HttpClient"
|
|
12
1
|
import type { Effect } from "effect"
|
|
13
|
-
import type { ClientOptions as OpenapiFetchClientOptions } from "openapi-fetch"
|
|
14
|
-
import type { HttpMethod } from "openapi-typescript-helpers"
|
|
15
|
-
|
|
16
2
|
import type {
|
|
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
|
-
|
|
3
|
+
ErrorResponse,
|
|
4
|
+
FilterKeys,
|
|
5
|
+
HttpMethod,
|
|
6
|
+
IsOperationRequestBodyOptional,
|
|
7
|
+
MediaType,
|
|
8
|
+
OperationRequestBodyContent,
|
|
9
|
+
PathsWithMethod,
|
|
10
|
+
Readable,
|
|
11
|
+
RequiredKeysOf,
|
|
12
|
+
ResponseObjectMap,
|
|
13
|
+
SuccessResponse,
|
|
14
|
+
Writable
|
|
15
|
+
} from "openapi-typescript-helpers"
|
|
16
|
+
|
|
17
|
+
export interface ClientOptions extends Omit<RequestInit, "headers"> {
|
|
18
|
+
baseUrl?: string
|
|
19
|
+
fetch?: (input: Request) => ReturnType<typeof globalThis.fetch>
|
|
20
|
+
Request?: typeof Request
|
|
21
|
+
querySerializer?: QuerySerializer<unknown> | QuerySerializerOptions
|
|
22
|
+
bodySerializer?: BodySerializer<unknown>
|
|
23
|
+
pathSerializer?: PathSerializer
|
|
24
|
+
headers?: HeadersOptions
|
|
25
|
+
requestInitExt?: Record<string, unknown>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type HeadersOptions =
|
|
29
|
+
| Required<RequestInit>["headers"]
|
|
30
|
+
| Record<
|
|
31
|
+
string,
|
|
32
|
+
string | number | boolean | Array<string | number | boolean> | null | undefined
|
|
33
|
+
>
|
|
34
|
+
|
|
35
|
+
export type QuerySerializer<T> = (
|
|
36
|
+
query: T extends { parameters: infer Parameters } ? Parameters extends { query?: infer Query } ? NonNullable<Query>
|
|
37
|
+
: Record<string, unknown>
|
|
38
|
+
: Record<string, unknown>
|
|
39
|
+
) => string
|
|
40
|
+
|
|
41
|
+
export type QuerySerializerOptions = {
|
|
42
|
+
array?: {
|
|
43
|
+
style: "form" | "spaceDelimited" | "pipeDelimited"
|
|
44
|
+
explode: boolean
|
|
45
|
+
}
|
|
46
|
+
object?: {
|
|
47
|
+
style: "form" | "deepObject"
|
|
48
|
+
explode: boolean
|
|
49
|
+
}
|
|
50
|
+
allowReserved?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type BodySerializer<T> = (
|
|
54
|
+
body: Writable<OperationRequestBodyContent<T>> | BodyInit | object,
|
|
55
|
+
headers?: Headers | HeadersOptions
|
|
56
|
+
) => BodyInit
|
|
57
|
+
|
|
58
|
+
export type PathSerializer = (
|
|
59
|
+
pathname: string,
|
|
60
|
+
pathParams: Record<string, unknown>
|
|
61
|
+
) => string
|
|
62
|
+
|
|
63
|
+
type BodyType<T = unknown> = {
|
|
64
|
+
json: T
|
|
65
|
+
text: Awaited<ReturnType<Response["text"]>>
|
|
66
|
+
blob: Awaited<ReturnType<Response["blob"]>>
|
|
67
|
+
arrayBuffer: Awaited<ReturnType<Response["arrayBuffer"]>>
|
|
68
|
+
stream: Response["body"]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ParseAs = keyof BodyType
|
|
72
|
+
|
|
73
|
+
export type ParseAsResponse<T, Options> = Options extends { parseAs: ParseAs } ? BodyType<T>[Options["parseAs"]]
|
|
74
|
+
: T
|
|
75
|
+
|
|
76
|
+
export interface DefaultParamsOption {
|
|
77
|
+
params?: {
|
|
78
|
+
query?: Record<string, unknown>
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type ParamsOption<T> = T extends { parameters: infer Parameters }
|
|
83
|
+
? RequiredKeysOf<Parameters> extends never ? { params?: Parameters }
|
|
84
|
+
: { params: Parameters }
|
|
85
|
+
: DefaultParamsOption
|
|
86
|
+
|
|
87
|
+
export type RequestBodyOption<T> = Writable<OperationRequestBodyContent<T>> extends never ? { body?: never }
|
|
88
|
+
: IsOperationRequestBodyOptional<T> extends true ? { body?: Writable<OperationRequestBodyContent<T>> }
|
|
89
|
+
: { body: Writable<OperationRequestBodyContent<T>> }
|
|
90
|
+
|
|
91
|
+
export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body" | "headers">
|
|
92
|
+
|
|
93
|
+
export type FetchResponse<
|
|
94
|
+
T extends Record<string | number, unknown>,
|
|
95
|
+
Options,
|
|
96
|
+
Media extends MediaType
|
|
97
|
+
> =
|
|
98
|
+
| {
|
|
99
|
+
data: ParseAsResponse<Readable<SuccessResponse<ResponseObjectMap<T>, Media>>, Options>
|
|
100
|
+
error?: never
|
|
101
|
+
response: Response
|
|
102
|
+
}
|
|
103
|
+
| {
|
|
104
|
+
data?: never
|
|
105
|
+
error: Readable<ErrorResponse<ResponseObjectMap<T>, Media>>
|
|
106
|
+
response: Response
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type RequestOptions<T> =
|
|
110
|
+
& ParamsOption<T>
|
|
111
|
+
& RequestBodyOption<T>
|
|
112
|
+
& {
|
|
113
|
+
baseUrl?: string
|
|
114
|
+
querySerializer?: QuerySerializer<T> | QuerySerializerOptions
|
|
115
|
+
bodySerializer?: BodySerializer<T>
|
|
116
|
+
pathSerializer?: PathSerializer
|
|
117
|
+
parseAs?: ParseAs
|
|
118
|
+
fetch?: ClientOptions["fetch"]
|
|
119
|
+
headers?: HeadersOptions
|
|
120
|
+
middleware?: Array<Middleware>
|
|
50
121
|
}
|
|
122
|
+
|
|
123
|
+
export type MergedOptions<T = unknown> = {
|
|
124
|
+
baseUrl: string
|
|
125
|
+
parseAs: ParseAs
|
|
126
|
+
querySerializer: QuerySerializer<T>
|
|
127
|
+
bodySerializer: BodySerializer<T>
|
|
128
|
+
pathSerializer: PathSerializer
|
|
129
|
+
fetch: typeof globalThis.fetch
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface MiddlewareRequestParams {
|
|
133
|
+
query?: Record<string, unknown>
|
|
134
|
+
header?: Record<string, unknown>
|
|
135
|
+
path?: Record<string, unknown>
|
|
136
|
+
cookie?: Record<string, unknown>
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface MiddlewareCallbackParams {
|
|
140
|
+
request: Request
|
|
141
|
+
readonly schemaPath: string
|
|
142
|
+
readonly params: MiddlewareRequestParams
|
|
143
|
+
readonly id: string
|
|
144
|
+
readonly options: MergedOptions
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type Thenable<T> = {
|
|
148
|
+
then: (
|
|
149
|
+
onFulfilled: (value: T) => unknown,
|
|
150
|
+
onRejected?: (reason: unknown) => unknown
|
|
151
|
+
) => unknown
|
|
51
152
|
}
|
|
52
153
|
|
|
53
|
-
export type
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
&
|
|
154
|
+
export type AsyncValue<T> = T | Thenable<T>
|
|
155
|
+
|
|
156
|
+
export type MiddlewareOnRequest = (
|
|
157
|
+
options: MiddlewareCallbackParams
|
|
158
|
+
) => AsyncValue<Request | Response | undefined>
|
|
159
|
+
|
|
160
|
+
export type MiddlewareOnResponse = (
|
|
161
|
+
options: MiddlewareCallbackParams & { response: Response }
|
|
162
|
+
) => AsyncValue<Response | undefined>
|
|
163
|
+
|
|
164
|
+
export type MiddlewareOnError = (
|
|
165
|
+
options: MiddlewareCallbackParams & { error: unknown }
|
|
166
|
+
) => AsyncValue<Response | Error | undefined>
|
|
167
|
+
|
|
168
|
+
export type Middleware =
|
|
169
|
+
| {
|
|
170
|
+
onRequest: MiddlewareOnRequest
|
|
171
|
+
onResponse?: MiddlewareOnResponse
|
|
172
|
+
onError?: MiddlewareOnError
|
|
173
|
+
}
|
|
174
|
+
| {
|
|
175
|
+
onRequest?: MiddlewareOnRequest
|
|
176
|
+
onResponse: MiddlewareOnResponse
|
|
177
|
+
onError?: MiddlewareOnError
|
|
178
|
+
}
|
|
179
|
+
| {
|
|
180
|
+
onRequest?: MiddlewareOnRequest
|
|
181
|
+
onResponse?: MiddlewareOnResponse
|
|
182
|
+
onError: MiddlewareOnError
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export type MaybeOptionalInit<Params, Location extends keyof Params> = RequiredKeysOf<
|
|
186
|
+
FetchOptions<FilterKeys<Params, Location>>
|
|
187
|
+
> extends never ? FetchOptions<FilterKeys<Params, Location>> | undefined
|
|
188
|
+
: FetchOptions<FilterKeys<Params, Location>>
|
|
189
|
+
|
|
190
|
+
type InitParam<Init> = RequiredKeysOf<Init> extends never ? [(Init & { [key: string]: unknown })?]
|
|
191
|
+
: [Init & { [key: string]: unknown }]
|
|
61
192
|
|
|
62
|
-
type
|
|
193
|
+
type OperationFor<
|
|
63
194
|
Paths extends object,
|
|
64
195
|
Path extends keyof Paths,
|
|
65
196
|
Method extends HttpMethod
|
|
66
|
-
> =
|
|
197
|
+
> = Paths[Path] extends Record<Method, infer Operation> ? Operation & Record<string | number, unknown>
|
|
198
|
+
: never
|
|
67
199
|
|
|
68
|
-
type
|
|
200
|
+
type MethodResult<
|
|
69
201
|
Paths extends object,
|
|
70
|
-
Path extends
|
|
71
|
-
Method extends HttpMethod
|
|
202
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
203
|
+
Method extends HttpMethod,
|
|
204
|
+
Init,
|
|
205
|
+
Media extends MediaType
|
|
72
206
|
> = Effect.Effect<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
HttpClient.HttpClient
|
|
207
|
+
FetchResponse<OperationFor<Paths, Path & keyof Paths, Method>, Init, Media>,
|
|
208
|
+
Error
|
|
76
209
|
>
|
|
77
210
|
|
|
78
|
-
type
|
|
211
|
+
export type ClientMethod<
|
|
79
212
|
Paths extends object,
|
|
80
|
-
|
|
81
|
-
|
|
213
|
+
Method extends HttpMethod,
|
|
214
|
+
Media extends MediaType
|
|
215
|
+
> = <
|
|
216
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
217
|
+
Init extends MaybeOptionalInit<Paths[Path], Extract<Method, keyof Paths[Path]>>
|
|
218
|
+
>(
|
|
219
|
+
url: Path,
|
|
220
|
+
...init: InitParam<Init>
|
|
221
|
+
) => MethodResult<Paths, Path, Method, Init, Media>
|
|
222
|
+
|
|
223
|
+
export type ClientRequestMethod<
|
|
224
|
+
Paths extends object,
|
|
225
|
+
Media extends MediaType
|
|
226
|
+
> = <
|
|
227
|
+
Method extends HttpMethod,
|
|
228
|
+
Path extends PathsWithMethod<Paths, Method>,
|
|
229
|
+
Init extends MaybeOptionalInit<Paths[Path], Extract<Method, keyof Paths[Path]>>
|
|
230
|
+
>(
|
|
231
|
+
method: Method,
|
|
232
|
+
url: Path,
|
|
233
|
+
...init: InitParam<Init>
|
|
234
|
+
) => MethodResult<Paths, Path, Method, Init, Media>
|
|
235
|
+
|
|
236
|
+
type PathMethodResult<
|
|
237
|
+
PathInfo extends Record<string | number, unknown>,
|
|
238
|
+
Method extends keyof PathInfo,
|
|
239
|
+
Init,
|
|
240
|
+
Media extends MediaType
|
|
82
241
|
> = Effect.Effect<
|
|
83
|
-
|
|
|
84
|
-
|
|
85
|
-
Exclude<
|
|
86
|
-
ApiFailure<ResponsesForOperation<Paths, Path, Method>>,
|
|
87
|
-
HttpError<ResponsesForOperation<Paths, Path, Method>>
|
|
88
|
-
>,
|
|
89
|
-
HttpClient.HttpClient
|
|
242
|
+
FetchResponse<PathInfo[Method] & Record<string | number, unknown>, Init, Media>,
|
|
243
|
+
Error
|
|
90
244
|
>
|
|
91
245
|
|
|
92
|
-
type
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
246
|
+
export type ClientForPath<PathInfo extends Record<string | number, unknown>, Media extends MediaType> = {
|
|
247
|
+
[Method in keyof PathInfo as Uppercase<string & Method>]: <
|
|
248
|
+
Init extends MaybeOptionalInit<PathInfo, Method>
|
|
249
|
+
>(
|
|
250
|
+
...init: InitParam<Init>
|
|
251
|
+
) => PathMethodResult<PathInfo, Method, Init, Media>
|
|
252
|
+
}
|
|
97
253
|
|
|
98
|
-
|
|
99
|
-
Paths
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
* 3. Dispatcher type is derived from operation's responses
|
|
111
|
-
* 4. Request options (params/query/body) are derived from operation
|
|
112
|
-
*
|
|
113
|
-
* **Effect Channel Design:**
|
|
114
|
-
* - Success channel: `ApiSuccess<Responses>` - 2xx responses only
|
|
115
|
-
* - Error channel: `ApiFailure<Responses>` - HTTP errors (4xx, 5xx) + boundary errors
|
|
116
|
-
*
|
|
117
|
-
* @typeParam Paths - OpenAPI paths type from openapi-typescript
|
|
118
|
-
*
|
|
119
|
-
* @pure false - operations perform HTTP requests
|
|
120
|
-
* @invariant ∀ call: path ∈ PathsForMethod<Paths, method> ∧ options derived from operation
|
|
121
|
-
*/
|
|
122
|
-
export type StrictApiClient<Paths extends object> = {
|
|
123
|
-
/**
|
|
124
|
-
* Execute GET request
|
|
125
|
-
*
|
|
126
|
-
* @typeParam Path - Path that supports GET method (enforced at type level)
|
|
127
|
-
* @param path - API path with GET method
|
|
128
|
-
* @param dispatcher - Response dispatcher (must match operation responses)
|
|
129
|
-
* @param options - Request options (typed from operation)
|
|
130
|
-
* @returns Effect with 2xx in success channel, errors in error channel
|
|
131
|
-
*/
|
|
132
|
-
readonly GET: <Path extends PathsForMethod<Paths, "get">>(
|
|
133
|
-
path: Path,
|
|
134
|
-
dispatcher: DispatcherFor<Paths, Path, "get">,
|
|
135
|
-
options?: RequestOptionsForOperation<Paths, Path, "get">
|
|
136
|
-
) => RequestEffect<Paths, Path, "get">
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Execute POST request
|
|
140
|
-
*/
|
|
141
|
-
readonly POST: <Path extends PathsForMethod<Paths, "post">>(
|
|
142
|
-
path: Path,
|
|
143
|
-
dispatcher: DispatcherFor<Paths, Path, "post">,
|
|
144
|
-
options?: RequestOptionsForOperation<Paths, Path, "post">
|
|
145
|
-
) => RequestEffect<Paths, Path, "post">
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Execute PUT request
|
|
149
|
-
*/
|
|
150
|
-
readonly PUT: <Path extends PathsForMethod<Paths, "put">>(
|
|
151
|
-
path: Path,
|
|
152
|
-
dispatcher: DispatcherFor<Paths, Path, "put">,
|
|
153
|
-
options?: RequestOptionsForOperation<Paths, Path, "put">
|
|
154
|
-
) => RequestEffect<Paths, Path, "put">
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Execute DELETE request
|
|
158
|
-
*/
|
|
159
|
-
readonly DELETE: <Path extends PathsForMethod<Paths, "delete">>(
|
|
160
|
-
path: Path,
|
|
161
|
-
dispatcher: DispatcherFor<Paths, Path, "delete">,
|
|
162
|
-
options?: RequestOptionsForOperation<Paths, Path, "delete">
|
|
163
|
-
) => RequestEffect<Paths, Path, "delete">
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Execute PATCH request
|
|
167
|
-
*/
|
|
168
|
-
readonly PATCH: <Path extends PathsForMethod<Paths, "patch">>(
|
|
169
|
-
path: Path,
|
|
170
|
-
dispatcher: DispatcherFor<Paths, Path, "patch">,
|
|
171
|
-
options?: RequestOptionsForOperation<Paths, Path, "patch">
|
|
172
|
-
) => RequestEffect<Paths, Path, "patch">
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Execute HEAD request
|
|
176
|
-
*/
|
|
177
|
-
readonly HEAD: <Path extends PathsForMethod<Paths, "head">>(
|
|
178
|
-
path: Path,
|
|
179
|
-
dispatcher: DispatcherFor<Paths, Path, "head">,
|
|
180
|
-
options?: RequestOptionsForOperation<Paths, Path, "head">
|
|
181
|
-
) => RequestEffect<Paths, Path, "head">
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Execute OPTIONS request
|
|
185
|
-
*/
|
|
186
|
-
readonly OPTIONS: <Path extends PathsForMethod<Paths, "options">>(
|
|
187
|
-
path: Path,
|
|
188
|
-
dispatcher: DispatcherFor<Paths, Path, "options">,
|
|
189
|
-
options?: RequestOptionsForOperation<Paths, Path, "options">
|
|
190
|
-
) => RequestEffect<Paths, Path, "options">
|
|
254
|
+
export interface Client<Paths extends object, Media extends MediaType = MediaType> {
|
|
255
|
+
request: ClientRequestMethod<Paths, Media>
|
|
256
|
+
GET: ClientMethod<Paths, "get", Media>
|
|
257
|
+
PUT: ClientMethod<Paths, "put", Media>
|
|
258
|
+
POST: ClientMethod<Paths, "post", Media>
|
|
259
|
+
DELETE: ClientMethod<Paths, "delete", Media>
|
|
260
|
+
OPTIONS: ClientMethod<Paths, "options", Media>
|
|
261
|
+
HEAD: ClientMethod<Paths, "head", Media>
|
|
262
|
+
PATCH: ClientMethod<Paths, "patch", Media>
|
|
263
|
+
TRACE: ClientMethod<Paths, "trace", Media>
|
|
264
|
+
use(...middleware: Array<Middleware>): void
|
|
265
|
+
eject(...middleware: Array<Middleware>): void
|
|
191
266
|
}
|
|
192
267
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
) => RequestEffect<Paths, Path, "get">
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Execute POST request (dispatcher is inferred)
|
|
221
|
-
*/
|
|
222
|
-
readonly POST: <Path extends PathsForMethod<Paths, "post">>(
|
|
223
|
-
path: Path,
|
|
224
|
-
options?: RequestOptionsForOperation<Paths, Path, "post">
|
|
225
|
-
) => RequestEffect<Paths, Path, "post">
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Execute PUT request (dispatcher is inferred)
|
|
229
|
-
*/
|
|
230
|
-
readonly PUT: <Path extends PathsForMethod<Paths, "put">>(
|
|
231
|
-
path: Path,
|
|
232
|
-
options?: RequestOptionsForOperation<Paths, Path, "put">
|
|
233
|
-
) => RequestEffect<Paths, Path, "put">
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Execute DELETE request (dispatcher is inferred)
|
|
237
|
-
*/
|
|
238
|
-
readonly DELETE: <Path extends PathsForMethod<Paths, "delete">>(
|
|
239
|
-
path: Path,
|
|
240
|
-
options?: RequestOptionsForOperation<Paths, Path, "delete">
|
|
241
|
-
) => RequestEffect<Paths, Path, "delete">
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Execute PATCH request (dispatcher is inferred)
|
|
245
|
-
*/
|
|
246
|
-
readonly PATCH: <Path extends PathsForMethod<Paths, "patch">>(
|
|
247
|
-
path: Path,
|
|
248
|
-
options?: RequestOptionsForOperation<Paths, Path, "patch">
|
|
249
|
-
) => RequestEffect<Paths, Path, "patch">
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Execute HEAD request (dispatcher is inferred)
|
|
253
|
-
*/
|
|
254
|
-
readonly HEAD: <Path extends PathsForMethod<Paths, "head">>(
|
|
255
|
-
path: Path,
|
|
256
|
-
options?: RequestOptionsForOperation<Paths, Path, "head">
|
|
257
|
-
) => RequestEffect<Paths, Path, "head">
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Execute OPTIONS request (dispatcher is inferred)
|
|
261
|
-
*/
|
|
262
|
-
readonly OPTIONS: <Path extends PathsForMethod<Paths, "options">>(
|
|
263
|
-
path: Path,
|
|
264
|
-
options?: RequestOptionsForOperation<Paths, Path, "options">
|
|
265
|
-
) => RequestEffect<Paths, Path, "options">
|
|
268
|
+
export type ClientPathsWithMethod<
|
|
269
|
+
CreatedClient extends Client<Record<string, Record<HttpMethod, unknown>>>,
|
|
270
|
+
Method extends HttpMethod
|
|
271
|
+
> = CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method>
|
|
272
|
+
: never
|
|
273
|
+
|
|
274
|
+
export type MethodResponse<
|
|
275
|
+
CreatedClient extends Client<Record<string, Record<HttpMethod, unknown>>>,
|
|
276
|
+
Method extends HttpMethod,
|
|
277
|
+
Path extends ClientPathsWithMethod<CreatedClient, Method>,
|
|
278
|
+
Options = object
|
|
279
|
+
> = CreatedClient extends Client<
|
|
280
|
+
infer Paths extends Record<string, Record<HttpMethod, unknown>>,
|
|
281
|
+
infer Media extends MediaType
|
|
282
|
+
> ? NonNullable<
|
|
283
|
+
FetchResponse<Paths[Path][Method] & Record<string | number, unknown>, Options, Media>["data"]
|
|
284
|
+
>
|
|
285
|
+
: never
|
|
286
|
+
|
|
287
|
+
export type PathBasedClient<
|
|
288
|
+
Paths extends Record<string | number, unknown>,
|
|
289
|
+
Media extends MediaType = MediaType
|
|
290
|
+
> = {
|
|
291
|
+
[Path in keyof Paths]: ClientForPath<Paths[Path] & Record<string | number, unknown>, Media>
|
|
266
292
|
}
|
|
267
293
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
* Boundary/protocol errors remain in the error channel.
|
|
273
|
-
* This removes the need for `Effect.either` when handling normal HTTP statuses.
|
|
274
|
-
*/
|
|
275
|
-
export type ClientEffect<Paths extends object> = {
|
|
276
|
-
readonly GET: <Path extends PathsForMethod<Paths, "get">>(
|
|
277
|
-
path: Path,
|
|
278
|
-
options?: RequestOptionsForOperation<Paths, Path, "get">
|
|
279
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "get">
|
|
280
|
-
|
|
281
|
-
readonly POST: <Path extends PathsForMethod<Paths, "post">>(
|
|
282
|
-
path: Path,
|
|
283
|
-
options?: RequestOptionsForOperation<Paths, Path, "post">
|
|
284
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "post">
|
|
285
|
-
|
|
286
|
-
readonly PUT: <Path extends PathsForMethod<Paths, "put">>(
|
|
287
|
-
path: Path,
|
|
288
|
-
options?: RequestOptionsForOperation<Paths, Path, "put">
|
|
289
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "put">
|
|
290
|
-
|
|
291
|
-
readonly DELETE: <Path extends PathsForMethod<Paths, "delete">>(
|
|
292
|
-
path: Path,
|
|
293
|
-
options?: RequestOptionsForOperation<Paths, Path, "delete">
|
|
294
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "delete">
|
|
295
|
-
|
|
296
|
-
readonly PATCH: <Path extends PathsForMethod<Paths, "patch">>(
|
|
297
|
-
path: Path,
|
|
298
|
-
options?: RequestOptionsForOperation<Paths, Path, "patch">
|
|
299
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "patch">
|
|
300
|
-
|
|
301
|
-
readonly HEAD: <Path extends PathsForMethod<Paths, "head">>(
|
|
302
|
-
path: Path,
|
|
303
|
-
options?: RequestOptionsForOperation<Paths, Path, "head">
|
|
304
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "head">
|
|
305
|
-
|
|
306
|
-
readonly OPTIONS: <Path extends PathsForMethod<Paths, "options">>(
|
|
307
|
-
path: Path,
|
|
308
|
-
options?: RequestOptionsForOperation<Paths, Path, "options">
|
|
309
|
-
) => RequestEffectWithHttpErrorsInSuccess<Paths, Path, "options">
|
|
294
|
+
export type DispatchersFor<Paths extends object> = {
|
|
295
|
+
[Path in keyof Paths]?: {
|
|
296
|
+
[Method in HttpMethod]?: object
|
|
297
|
+
}
|
|
310
298
|
}
|
|
299
|
+
|
|
300
|
+
export type StrictApiClient<Paths extends object> = Client<Paths>
|
|
301
|
+
export type StrictApiClientWithDispatchers<Paths extends object> = Client<Paths>
|
|
302
|
+
export type ClientEffect<Paths extends object> = Client<Paths>
|