envio 2.8.1 → 2.9.0

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,182 @@
1
+ /*
2
+ Vendored from: https://github.com/DZakh/rescript-rest
3
+ Version: 1.0.1
4
+
5
+ IF EDITING THIS FILE, PLEASE LIST THE CHANGES BELOW
6
+
7
+ here
8
+
9
+ */
10
+
11
+ @@uncurried
12
+
13
+ module ApiFetcher: {
14
+ type args = {body: option<unknown>, headers: option<dict<unknown>>, method: string, path: string}
15
+ type response = {data: unknown, status: int, headers: dict<unknown>}
16
+ type t = args => promise<response>
17
+
18
+ // Inspired by https://github.com/ts-rest/ts-rest/blob/7792ef7bdc352e84a4f5766c53f984a9d630c60e/libs/ts-rest/core/src/lib/client.ts#L102
19
+ /**
20
+ * Default fetch api implementation:
21
+ *
22
+ * Can be used as a reference for implementing your own fetcher,
23
+ * or used in the "api" field of ClientArgs to allow you to hook
24
+ * into the request to run custom logic
25
+ */
26
+ let default: t
27
+ }
28
+
29
+ module Response: {
30
+ type numiricStatus = [
31
+ | #100
32
+ | #101
33
+ | #102
34
+ | #200
35
+ | #201
36
+ | #202
37
+ | #203
38
+ | #204
39
+ | #205
40
+ | #206
41
+ | #207
42
+ | #300
43
+ | #301
44
+ | #302
45
+ | #303
46
+ | #304
47
+ | #305
48
+ | #307
49
+ | #308
50
+ | #400
51
+ | #401
52
+ | #402
53
+ | #403
54
+ | #404
55
+ | #405
56
+ | #406
57
+ | #407
58
+ | #408
59
+ | #409
60
+ | #410
61
+ | #411
62
+ | #412
63
+ | #413
64
+ | #414
65
+ | #415
66
+ | #416
67
+ | #417
68
+ | #418
69
+ | #419
70
+ | #420
71
+ | #421
72
+ | #422
73
+ | #423
74
+ | #424
75
+ | #428
76
+ | #429
77
+ | #431
78
+ | #451
79
+ | #500
80
+ | #501
81
+ | #502
82
+ | #503
83
+ | #504
84
+ | #505
85
+ | #507
86
+ | #511
87
+ ]
88
+ type status = [
89
+ | #"1XX"
90
+ | #"2XX"
91
+ | #"3XX"
92
+ | #"4XX"
93
+ | #"5XX"
94
+ | numiricStatus
95
+ ]
96
+
97
+ type t<'response> = {
98
+ // When it's empty, treat response as a default
99
+ status: option<int>,
100
+ description: option<string>,
101
+ dataSchema: S.t<unknown>,
102
+ emptyData: bool,
103
+ schema: S.t<'response>,
104
+ }
105
+
106
+ type s = {
107
+ status: int => unit,
108
+ description: string => unit,
109
+ data: 'value. S.t<'value> => 'value,
110
+ field: 'value. (string, S.t<'value>) => 'value,
111
+ header: 'value. (string, S.t<'value>) => 'value,
112
+ }
113
+ }
114
+
115
+ type auth = Bearer | Basic
116
+
117
+ type s = {
118
+ field: 'value. (string, S.t<'value>) => 'value,
119
+ body: 'value. S.t<'value> => 'value,
120
+ rawBody: 'value. S.t<'value> => 'value,
121
+ header: 'value. (string, S.t<'value>) => 'value,
122
+ query: 'value. (string, S.t<'value>) => 'value,
123
+ param: 'value. (string, S.t<'value>) => 'value,
124
+ auth: auth => string,
125
+ }
126
+
127
+ type method =
128
+ | @as("GET") Get
129
+ | @as("POST") Post
130
+ | @as("PUT") Put
131
+ | @as("PATCH") Patch
132
+ | @as("DELETE") Delete
133
+ | @as("HEAD") Head
134
+ | @as("OPTIONS") Options
135
+ | @as("TRACE") Trace
136
+
137
+ type definition<'variables, 'response> = {
138
+ method: method,
139
+ path: string,
140
+ variables: s => 'variables,
141
+ responses: array<Response.s => 'response>,
142
+ summary?: string,
143
+ description?: string,
144
+ deprecated?: bool,
145
+ }
146
+
147
+ type route<'variables, 'response>
148
+
149
+ type pathParam = {name: string}
150
+ @unboxed
151
+ type pathItem = Static(string) | Param(pathParam)
152
+
153
+ type routeParams<'variables, 'response> = {
154
+ definition: definition<'variables, 'response>,
155
+ pathItems: array<pathItem>,
156
+ variablesSchema: S.t<'variables>,
157
+ responses: array<Response.t<'response>>,
158
+ responsesMap: dict<Response.t<'response>>,
159
+ isRawBody: bool,
160
+ }
161
+
162
+ let params: route<'variables, 'response> => routeParams<'variables, 'response>
163
+
164
+ external route: (unit => definition<'variables, 'response>) => route<'variables, 'response> =
165
+ "%identity"
166
+
167
+ type client = {
168
+ call: 'variables 'response. (route<'variables, 'response>, 'variables) => promise<'response>,
169
+ baseUrl: string,
170
+ fetcher: ApiFetcher.t,
171
+ jsonQuery: bool,
172
+ }
173
+
174
+ let client: (~baseUrl: string, ~fetcher: ApiFetcher.t=?, ~jsonQuery: bool=?) => client
175
+
176
+ let fetch: (
177
+ route<'variables, 'response>,
178
+ string,
179
+ 'variables,
180
+ ~fetcher: ApiFetcher.t=?,
181
+ ~jsonQuery: bool=?,
182
+ ) => promise<'response>