@reclaimprotocol/client 0.1.0-dev.1

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.
@@ -0,0 +1,80 @@
1
+ import type { components, operations } from './openapi.gen.ts'
2
+
3
+ export type IOperationId = keyof operations
4
+
5
+ type RequestBodyContent<T> = T extends {
6
+ content: { 'application/json': infer R }
7
+ }
8
+ ? R
9
+ : T extends { content: { 'application/x-www-form-urlencoded': infer R } }
10
+ ? R
11
+ : undefined
12
+
13
+ export type IJsonRequestBody<T extends IOperationId> = operations[T] extends {
14
+ requestBody?: infer B
15
+ }
16
+ ? RequestBodyContent<B>
17
+ : undefined
18
+
19
+ type AnySuccess<R> = R extends {
20
+ 200: { content: { 'application/json': infer J } }
21
+ }
22
+ ? J
23
+ : R extends { 201: { content: { 'application/json': infer J } } }
24
+ ? J
25
+ : R extends { 204: unknown }
26
+ ? void
27
+ : unknown
28
+
29
+ export type IJsonResponseBody<T extends IOperationId> = operations[T] extends {
30
+ responses: infer R
31
+ }
32
+ ? AnySuccess<R>
33
+ : void
34
+
35
+ export type IQuery<T extends IOperationId> = operations[T] extends {
36
+ parameters: { query?: infer R }
37
+ }
38
+ ? Exclude<R, undefined>
39
+ : undefined
40
+
41
+ export type IParams<T extends IOperationId> = operations[T] extends {
42
+ parameters: { path?: infer R }
43
+ }
44
+ ? Exclude<R, undefined>
45
+ : undefined
46
+
47
+ export type IHeaders<T extends IOperationId> = operations[T] extends {
48
+ parameters: { header?: infer R }
49
+ }
50
+ ? Exclude<R, undefined>
51
+ : undefined
52
+
53
+ // Shape passed to `ReclaimClient.call(operationId, args)`. Each member
54
+ // is keyed off the openapi spec — pass `params` for path params,
55
+ // `query` for query params, `body` for the JSON body, and `headers` for
56
+ // header params (e.g. `If-Match`). `headers` is optional since most
57
+ // operations declare none.
58
+ export type IOperationArgs<T extends IOperationId> = {
59
+ params?: IParams<T> | undefined
60
+ query?: IQuery<T> | undefined
61
+ body?: IJsonRequestBody<T> | undefined
62
+ headers?: IHeaders<T> | undefined
63
+ } & (
64
+ [IParams<T>] extends [undefined] ? unknown : { params: IParams<T> }
65
+ ) & (
66
+ [IQuery<T>] extends [undefined] ? unknown : { query: IQuery<T> }
67
+ ) & (
68
+ [IJsonRequestBody<T>] extends [undefined]
69
+ ? unknown
70
+ : { body: IJsonRequestBody<T> }
71
+ ) & (
72
+ [IHeaders<T>] extends [undefined] ? unknown : { headers: IHeaders<T> }
73
+ )
74
+
75
+ export type IOperationResponse<T extends IOperationId> = IJsonResponseBody<T>
76
+
77
+ // RFC 9457 — Problem Details for HTTP APIs.
78
+ export type ProblemDetails = components['schemas']['Problem'] & {
79
+ [key: string]: unknown
80
+ }