eve-esi-types 3.0.4 → 3.1.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.
- package/README.md +2 -2
- package/esi-types-util3.md +208 -75
- package/lib/rq-util.d.mts +5 -4
- package/lib/rq-util.mjs +36 -9
- package/lib/tagged-request-api.mjs +1 -1
- package/package.json +2 -2
- package/{v2.mjs → request-v3.mjs} +1 -1
- package/tagged-rq.mjs +2 -2
- package/v2/esi-tagged-types.d.ts +15 -15
- package/v2/index.d.ts +244 -72
- package/v2/response-map.d.ts +1 -1
- package/v2/types-index.d.ts +1 -1
- /package/{v2.d.mts → request-v3.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -8,10 +8,10 @@ Extracted main types of ESI. Used for ESI request response types.
|
|
|
8
8
|
+ If you need to use version 1, please refer to the following link:
|
|
9
9
|
[eve-esi-types v1](https://github.com/jeffy-g/eve-esi-types/tree/version-1.x)
|
|
10
10
|
|
|
11
|
-
> Sample code is provided -> [`
|
|
11
|
+
> Sample code is provided -> [`request-v3.mjs`](./request-v3.mjs)
|
|
12
12
|
|
|
13
13
|
```shell
|
|
14
|
-
$ node
|
|
14
|
+
$ node request-v3.mjs
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## API
|
package/esi-types-util3.md
CHANGED
|
@@ -6,89 +6,192 @@
|
|
|
6
6
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
|
-
# ESI Types Utility Summary
|
|
9
|
+
# ESI Types Utility 3.1 Summary
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
`TESICachedSeconds` is a type to get the cached seconds for a specific HTTP method.
|
|
11
|
+
This document provides detailed explanations of each type defined in the `index.d.ts` file.
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
type TESICachedSeconds<
|
|
16
|
-
Method extends TESIEntryMethod, AsEndpoint = void
|
|
17
|
-
> = {
|
|
18
|
-
[M in TESIEntryMethod]: {
|
|
19
|
-
[EP in keyof TESIResponseOKMap[M]]: TESIResponseOKMap[M][EP]["cachedSeconds"] extends number
|
|
20
|
-
? AsEndpoint extends void
|
|
21
|
-
? TESIResponseOKMap[M][EP]["cachedSeconds"]: EP
|
|
22
|
-
: never
|
|
23
|
-
}[keyof TESIResponseOKMap[M]];
|
|
24
|
-
}[Method];
|
|
25
|
-
```
|
|
13
|
+
> ## TESIRequestFunctionSignature2
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
`TPathParamsNever` is a type used when path parameters are not required.
|
|
15
|
+
`TESIRequestFunctionSignature2` is a type that defines the signature of an ESI request function where the endpoint can be a real endpoint or a parameterized endpoint. This function sends a request to a specified endpoint and returns a response.
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
type TPathParamsNever = { pathParams?: never };
|
|
32
|
-
```
|
|
17
|
+
#### Type Parameters
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
`
|
|
19
|
+
- `ActualOpt`: The actual type of the options.
|
|
20
|
+
- `M`: The HTTP method to use for the request.
|
|
21
|
+
- `RealEP`: The real path of the ESI endpoint to send the request to.
|
|
22
|
+
- `EPx`: The parameterized path of the ESI endpoint to send the request to.
|
|
23
|
+
- `PathParams`: Parameters to include in the request if the endpoint is parameterized.
|
|
24
|
+
- `Opt`: Options to include in the request. If there is a required parameter, its type will be merged with `ActualOpt`.
|
|
25
|
+
- `R`: The response type.
|
|
26
|
+
- `HasOpt`: Determines if the options parameter is required.
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
#### Parameters
|
|
29
|
+
|
|
30
|
+
- `method`: The HTTP method to use for the request (e.g., "get", "post").
|
|
31
|
+
- `endpoint`: The real path of the ESI endpoint to send the request to.
|
|
32
|
+
- `options`: An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
|
|
33
|
+
|
|
34
|
+
#### Returns
|
|
35
|
+
|
|
36
|
+
A `Promise` object containing the response data, with the type inferred based on the method and endpoint.
|
|
37
|
+
|
|
38
|
+
#### Remarks
|
|
39
|
+
|
|
40
|
+
The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters, the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
> ## TESIRequestFunctionEachMethod2
|
|
44
|
+
|
|
45
|
+
`TESIRequestFunctionEachMethod2` is a type that defines the signature of an ESI request function for a specific HTTP method. This function sends a request to a specified endpoint and returns a response.
|
|
46
|
+
|
|
47
|
+
#### Type Parameters
|
|
48
|
+
|
|
49
|
+
- `M`: The HTTP method to use for the request.
|
|
50
|
+
- `ActualOpt`: The actual type of the options.
|
|
51
|
+
- `RealEP`: The real path of the ESI endpoint to send the request to.
|
|
52
|
+
- `EPx`: The parameterized path of the ESI endpoint to send the request to.
|
|
53
|
+
- `PathParams`: Parameters to include in the request if the endpoint is parameterized.
|
|
54
|
+
- `Opt`: Options to include in the request. If there is a required parameter, its type will be merged with `ActualOpt`.
|
|
55
|
+
- `R`: The response type.
|
|
56
|
+
- `HasOpt`: Determines if the options parameter is required.
|
|
57
|
+
|
|
58
|
+
#### Parameters
|
|
59
|
+
|
|
60
|
+
- `endpoint`: The real path of the ESI endpoint to send the request to.
|
|
61
|
+
- `options`: An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
|
|
62
|
+
|
|
63
|
+
#### Returns
|
|
64
|
+
|
|
65
|
+
A `Promise` object containing the response data, with the type inferred based on the method and endpoint.
|
|
66
|
+
|
|
67
|
+
#### Remarks
|
|
68
|
+
|
|
69
|
+
The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters, the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
|
|
47
70
|
|
|
48
|
-
## TESIRequestFunctionEachMethod2
|
|
49
|
-
`TESIRequestFunctionEachMethod2` is a type that defines functions to make ESI requests for a specific HTTP method.
|
|
50
71
|
|
|
51
|
-
```typescript
|
|
52
|
-
type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
|
|
53
|
-
RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
|
|
54
|
-
EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
|
|
55
|
-
PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
|
|
56
|
-
Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
|
|
57
|
-
R extends InferESIResponseResult<M, EP>
|
|
58
|
-
>(endpoint: RealEP, options?: Opt) => Promise<R>;
|
|
59
|
-
```
|
|
60
72
|
|
|
61
73
|
## ReplacePathParams
|
|
74
|
+
|
|
62
75
|
`ReplacePathParams` is a type that replaces path parameters in a string with numbers.
|
|
63
76
|
|
|
64
77
|
```typescript
|
|
65
|
-
type ReplacePathParams<T extends
|
|
78
|
+
type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
|
|
66
79
|
? `${Start}${number}${ReplacePathParams<End>}` : T;
|
|
67
80
|
```
|
|
68
81
|
|
|
69
|
-
|
|
70
|
-
|
|
82
|
+
<details>
|
|
83
|
+
> Example
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
type Example = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
87
|
+
// Result: `/characters/${number}/fittings/${number}/`
|
|
88
|
+
```
|
|
89
|
+
</details>
|
|
90
|
+
|
|
91
|
+
## InferPathParams
|
|
92
|
+
|
|
93
|
+
`InferPathParams` is a type that infers the path parameters based on the real endpoint and the resolved endpoint.
|
|
71
94
|
|
|
72
95
|
```typescript
|
|
73
|
-
type
|
|
74
|
-
|
|
96
|
+
type InferPathParams<
|
|
97
|
+
RealEP extends unknown, EPx extends unknown
|
|
98
|
+
> = RealEP extends EPx ? _IfNeedPathParams<EPx> : TPathParamsNever;
|
|
75
99
|
```
|
|
76
100
|
|
|
77
101
|
## InferEndpointOrigin
|
|
78
|
-
|
|
102
|
+
|
|
103
|
+
`InferEndpointOrigin` is a type that infers the original endpoint based on the real endpoint and the HTTP method. This type maps the real endpoint to its corresponding parameterized endpoint by checking if the real endpoint matches the pattern of any parameterized endpoint.
|
|
79
104
|
|
|
80
105
|
```typescript
|
|
81
|
-
type InferEndpointOrigin<
|
|
106
|
+
type InferEndpointOrigin<
|
|
107
|
+
RealEP extends unknown, M extends TESIEntryMethod,
|
|
108
|
+
Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>
|
|
109
|
+
> = {
|
|
82
110
|
[EP in Endpoints]: RealEP extends ReplacePathParams<EP>
|
|
83
111
|
? EP : never;
|
|
84
112
|
}[Endpoints];
|
|
85
113
|
```
|
|
86
114
|
|
|
115
|
+
<details>
|
|
116
|
+
> Example
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
type Original = InferEndpointOrigin<"/characters/123/fittings/456/", "delete">;
|
|
120
|
+
// Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
121
|
+
```
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## ResolvedEndpoint
|
|
126
|
+
|
|
127
|
+
`ResolvedEndpoint` is a type that determines the resolved endpoint based on the real endpoint and the method.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
type ResolvedEndpoint<
|
|
131
|
+
RealEP extends unknown, M extends TESIEntryMethod,
|
|
132
|
+
> = InferEndpointOrigin<RealEP, M> extends never ? RealEP: InferEndpointOrigin<RealEP, M>;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
<details>
|
|
136
|
+
> Example
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
type Resolved = ResolvedEndpoint<"/characters/123/fittings/456/", "delete">;
|
|
140
|
+
// Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
141
|
+
```
|
|
142
|
+
</details>
|
|
143
|
+
|
|
144
|
+
## PickRequireParams
|
|
145
|
+
|
|
146
|
+
`PickRequireParams` is a type that picks the required parameters from an entry type, including additional parameters. This type excludes the keys "result", "tag", and "cachedSeconds" from the entry type and the additional parameters, and returns the remaining keys as the required parameters.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
type PickRequireParams<
|
|
150
|
+
M extends TESIEntryMethod,
|
|
151
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
152
|
+
AdditionalParams,
|
|
153
|
+
Entry = _ESIResponseType<M, EPx>
|
|
154
|
+
> = Exclude<keyof (Entry & AdditionalParams), "result" | "tag" | "cachedSeconds">;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
<details>
|
|
158
|
+
> Example
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
162
|
+
type RequiredParams = PickRequireParams<"get", "/example/endpoint", { auth: string }>;
|
|
163
|
+
// Result: "auth"
|
|
164
|
+
```
|
|
165
|
+
</details>
|
|
166
|
+
|
|
167
|
+
## HasRequireParams
|
|
168
|
+
|
|
169
|
+
`HasRequireParams` is a type that determines if the given entry has required parameters, including additional options. This type checks if an entry has any required parameters by excluding the keys "result", "tag", and "cachedSeconds". If any keys remain after this exclusion, it means the entry has required parameters.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
type HasRequireParams<
|
|
173
|
+
M extends TESIEntryMethod,
|
|
174
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
175
|
+
AdditionalParams,
|
|
176
|
+
> = PickRequireParams<M, EPx, AdditionalParams> extends never ? 0 : 1;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
<details>
|
|
180
|
+
> Example
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
184
|
+
type HasRequired = HasRequireParams<"get", "/example/endpoint", { auth: string }>;
|
|
185
|
+
// Result: 1
|
|
186
|
+
```
|
|
187
|
+
</details>
|
|
188
|
+
|
|
87
189
|
## IfParameterizedPath
|
|
88
|
-
|
|
190
|
+
|
|
191
|
+
`IfParameterizedPath` is a type that determines the required number of replacements if `EP` (endpoint) is a parameterized path.
|
|
89
192
|
|
|
90
193
|
```typescript
|
|
91
|
-
type IfParameterizedPath<EP, Opt = never> = EP extends `${string}/{${string}}${string}`
|
|
194
|
+
type IfParameterizedPath<EP extends unknown, Opt = never> = EP extends `${string}/{${string}}${string}`
|
|
92
195
|
? PickPathParameters<EP> extends never
|
|
93
196
|
? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
|
|
94
197
|
? number : [number, number]
|
|
@@ -96,26 +199,52 @@ type IfParameterizedPath<EP, Opt = never> = EP extends `${string}/{${string}}${s
|
|
|
96
199
|
```
|
|
97
200
|
|
|
98
201
|
## IdentifyParameters
|
|
99
|
-
|
|
202
|
+
|
|
203
|
+
`IdentifyParameters` is a type that identifies the required parameters for a given entry type, including additional options. This type combines the required parameters from the entry type and the additional options, ensuring that all required parameters are marked as required.
|
|
100
204
|
|
|
101
205
|
```typescript
|
|
102
206
|
type IdentifyParameters<
|
|
103
|
-
|
|
207
|
+
M extends TESIEntryMethod,
|
|
208
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
209
|
+
Opt extends Record<string, unknown>,
|
|
210
|
+
Entry = _ESIResponseType<M, EPx>,
|
|
104
211
|
Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
|
|
105
212
|
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
106
213
|
```
|
|
107
214
|
|
|
215
|
+
<details>
|
|
216
|
+
> Example
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
220
|
+
type ExampleOpt = { auth: string };
|
|
221
|
+
type IdentifiedParams = IdentifyParameters<"get", "/example/endpoint", ExampleOpt, ExampleEntry>;
|
|
222
|
+
// Result: { auth: string } & { auth: string }
|
|
223
|
+
```
|
|
224
|
+
</details>
|
|
225
|
+
|
|
108
226
|
## InferESIResponseResult
|
|
227
|
+
|
|
109
228
|
`InferESIResponseResult` is a type that infers the result type of an ESI response based on the method and endpoint.
|
|
110
229
|
|
|
111
230
|
```typescript
|
|
112
231
|
type InferESIResponseResult<
|
|
113
232
|
M extends TESIEntryMethod,
|
|
114
|
-
|
|
115
|
-
> =
|
|
233
|
+
EPx extends ESIEndpointOf<M> | string
|
|
234
|
+
> = _ESIResponseType<M, EPx> extends { result: infer U } ? U : never;
|
|
116
235
|
```
|
|
117
236
|
|
|
237
|
+
<details>
|
|
238
|
+
> Example
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
type Result = InferESIResponseResult<"get", "/characters/{character_id}/">;
|
|
242
|
+
// Result: The inferred type of the response for the given method and endpoint.
|
|
243
|
+
```
|
|
244
|
+
</details>
|
|
245
|
+
|
|
118
246
|
## NoContentResponse
|
|
247
|
+
|
|
119
248
|
`NoContentResponse` is a type that represents a response with no content (HTTP status 204).
|
|
120
249
|
|
|
121
250
|
```typescript
|
|
@@ -123,41 +252,42 @@ type NoContentResponse = { /* status: 204 */ };
|
|
|
123
252
|
```
|
|
124
253
|
|
|
125
254
|
## TESIEntryMethod
|
|
255
|
+
|
|
126
256
|
`TESIEntryMethod` is a type that represents the HTTP methods supported by ESI.
|
|
127
257
|
|
|
128
258
|
```typescript
|
|
129
259
|
type TESIEntryMethod = keyof TESIResponseOKMap;
|
|
130
260
|
```
|
|
131
261
|
|
|
132
|
-
|
|
133
|
-
|
|
262
|
+
<details>
|
|
263
|
+
> Example
|
|
134
264
|
|
|
135
|
-
```typescript
|
|
136
|
-
|
|
137
|
-
```
|
|
265
|
+
```typescript
|
|
266
|
+
"get" | "post" | "put" | "delete"
|
|
267
|
+
```
|
|
268
|
+
</details>
|
|
138
269
|
|
|
139
|
-
##
|
|
140
|
-
`TEndPointPost` is a type that represents the endpoints for the "post" method.
|
|
270
|
+
## ESIEndpointOf
|
|
141
271
|
|
|
142
|
-
|
|
143
|
-
type TEndPointPost = keyof TESIResponseOKMap["post"];
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## TEndPointPut
|
|
147
|
-
`TEndPointPut` is a type that represents the endpoints for the "put" method.
|
|
272
|
+
`ESIEndpointOf` is a type that represents the endpoints for the specified HTTP method.
|
|
148
273
|
|
|
149
274
|
```typescript
|
|
150
|
-
type
|
|
275
|
+
type ESIEndpointOf<M extends TESIEntryMethod> = keyof TESIResponseOKMap[M];
|
|
151
276
|
```
|
|
152
277
|
|
|
153
|
-
|
|
154
|
-
|
|
278
|
+
<details>
|
|
279
|
+
> Example
|
|
155
280
|
|
|
156
|
-
```typescript
|
|
157
|
-
type
|
|
158
|
-
|
|
281
|
+
```typescript
|
|
282
|
+
type TEndPointGet = ESIEndpointOf<"get">;
|
|
283
|
+
type TEndPointPost = ESIEndpointOf<"post">;
|
|
284
|
+
type TEndPointPut = ESIEndpointOf<"put">;
|
|
285
|
+
type TEndPointDelete = ESIEndpointOf<"delete">;
|
|
286
|
+
```
|
|
287
|
+
</details>
|
|
159
288
|
|
|
160
289
|
## TESIResponseGetEntry
|
|
290
|
+
|
|
161
291
|
`TESIResponseGetEntry` is a type that represents the entry details for the "get" method.
|
|
162
292
|
|
|
163
293
|
```typescript
|
|
@@ -165,6 +295,7 @@ type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
|
|
|
165
295
|
```
|
|
166
296
|
|
|
167
297
|
## TESIResponsePutEntry
|
|
298
|
+
|
|
168
299
|
`TESIResponsePutEntry` is a type that represents the entry details for the "put" method.
|
|
169
300
|
|
|
170
301
|
```typescript
|
|
@@ -172,6 +303,7 @@ type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
|
|
|
172
303
|
```
|
|
173
304
|
|
|
174
305
|
## TESIResponsePostEntry
|
|
306
|
+
|
|
175
307
|
`TESIResponsePostEntry` is a type that represents the entry details for the "post" method.
|
|
176
308
|
|
|
177
309
|
```typescript
|
|
@@ -179,6 +311,7 @@ type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][
|
|
|
179
311
|
```
|
|
180
312
|
|
|
181
313
|
## TESIResponseDeleteEntry
|
|
314
|
+
|
|
182
315
|
`TESIResponseDeleteEntry` is a type that represents the entry details for the "delete" method.
|
|
183
316
|
|
|
184
317
|
```typescript
|
package/lib/rq-util.d.mts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// https://opensource.org/licenses/mit-license.php
|
|
17
17
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
18
18
|
*/
|
|
19
|
-
import type {
|
|
19
|
+
import type { TESIRequestFunctionMethods2 } from "../v2";
|
|
20
20
|
import type { TESIErrorStats } from "./esi-error-types";
|
|
21
21
|
export { isNode } from "./constants.mjs";
|
|
22
22
|
/**
|
|
@@ -181,9 +181,10 @@ export declare function getLogger(): {
|
|
|
181
181
|
clog: (...args: any[]) => void;
|
|
182
182
|
rlog: (...args: any[]) => void;
|
|
183
183
|
};
|
|
184
|
-
export type TFireWithoutAuth =
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
export type TFireWithoutAuth = <M extends TESIEntryMethod, RealEP extends ReplacePathParams<ESIEndpointOf<M>> | ESIEndpointOf<M>, EPx extends ResolvedEndpoint<RealEP, M>, PathParams extends InferPathParams<RealEP, EPx>, Opt extends IdentifyParameters<M, EPx, ESIRequestOptions & PathParams>, R extends InferESIResponseResult<M, EPx>, HasOpt = HasRequireParams<M, EPx, PathParams>, XX = PickRequireParams<M, EPx, PathParams>>(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>, method: M, endpoint: RealEP, ...opt: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
|
|
185
|
+
export interface IFireWithoutAuth {
|
|
186
|
+
<M extends TESIEntryMethod, RealEP extends ReplacePathParams<ESIEndpointOf<M>> | ESIEndpointOf<M>, EPx extends ResolvedEndpoint<RealEP, M>, PathParams extends InferPathParams<RealEP, EPx>, Opt extends IdentifyParameters<M, EPx, ESIRequestOptions & PathParams>, R extends InferESIResponseResult<M, EPx>, HasOpt = HasRequireParams<M, EPx, PathParams>, XX = PickRequireParams<M, EPx, PathParams>>(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>, method: M, endpoint: RealEP, ...opt: HasOpt extends 1 ? [Opt] : [Opt?]): Promise<R>;
|
|
187
|
+
}
|
|
187
188
|
/**
|
|
188
189
|
* Need typescript v5.5 later
|
|
189
190
|
* @import * as ESI from "../v2";
|
package/lib/rq-util.mjs
CHANGED
|
@@ -320,19 +320,38 @@ export function getLogger() {
|
|
|
320
320
|
const rlog = consoleUtil.getLogger("- - -> Run ESI request".cyan);
|
|
321
321
|
return { clog, rlog };
|
|
322
322
|
}
|
|
323
|
+
/* ctt
|
|
324
|
+
// Result: `/characters/${number}/fittings/${number}/`
|
|
325
|
+
type Example = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
326
|
+
|
|
327
|
+
// Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
328
|
+
type ResovedEP = ResolvedEndpoint<"/characters/123/fittings/456/", "delete">;
|
|
329
|
+
// Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
330
|
+
type ResovedEP2 = ResolvedEndpoint<"/characters/{character_id}/fittings/{fitting_id}/", "delete">;
|
|
331
|
+
type IncompleteEP = ResolvedEndpoint<"/characters/1234/fittings/{fitting_id}/", "delete">;
|
|
332
|
+
|
|
333
|
+
// Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
334
|
+
type EPOriginOK = InferEndpointOrigin<"/characters/123/fittings/456/", "delete">;
|
|
335
|
+
// result: never
|
|
336
|
+
type EPOriginNever = InferEndpointOrigin<"/characters/123/fittings/{fitting_id}/", "delete">;
|
|
337
|
+
// result: never
|
|
338
|
+
type EPOriginNever2 = InferEndpointOrigin<"/characters/{character_id}/fittings/456/", "delete">;
|
|
339
|
+
/*/
|
|
340
|
+
//*/
|
|
323
341
|
/**
|
|
324
342
|
* #### Fire a request that does not require authentication.
|
|
325
343
|
*
|
|
326
344
|
* @type {import("./rq-util.d.mts").TFireWithoutAuth}
|
|
327
345
|
*/
|
|
328
|
-
// @ts-expect-error
|
|
329
|
-
const fireWithoutAuth = (fn, method, endpoint, opt) => {
|
|
346
|
+
// @ts-expect -error
|
|
347
|
+
const fireWithoutAuth = (fn, method, endpoint, ...opt) => {
|
|
348
|
+
const arg = opt.length ? opt[0] : void 0;
|
|
330
349
|
if (typeof fn === "function") {
|
|
331
350
|
// @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
|
|
332
|
-
return fn(method, endpoint,
|
|
351
|
+
return fn(method, endpoint, arg);
|
|
333
352
|
}
|
|
334
353
|
// @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
|
|
335
|
-
return fn[method](endpoint,
|
|
354
|
+
return fn[method](endpoint, arg);
|
|
336
355
|
};
|
|
337
356
|
/**
|
|
338
357
|
* Need typescript v5.5 later
|
|
@@ -358,7 +377,9 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
|
|
|
358
377
|
// Here, I borrow data from "CCP Zoetrope".
|
|
359
378
|
clog();
|
|
360
379
|
casefireWithoutAuth: {
|
|
361
|
-
await fireWithoutAuth(fn, "get", `/characters
|
|
380
|
+
await fireWithoutAuth(fn, "get", `/characters/{character_id}/`, {
|
|
381
|
+
pathParams: ID_CCP_Zoetrope
|
|
382
|
+
}).then(log);
|
|
362
383
|
clog('(portrait)');
|
|
363
384
|
await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/portrait/`).then(log);
|
|
364
385
|
clog('(affiliation)');
|
|
@@ -368,10 +389,16 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
|
|
|
368
389
|
await fireWithoutAuth(fn, "get", `/corporations/${affiliation[0].corporation_id}/`).then(log);
|
|
369
390
|
rlog("get:/incursions/".green);
|
|
370
391
|
await fireWithoutAuth(fn, "get", "/incursions/").then(log);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
392
|
+
if (is("withError")) {
|
|
393
|
+
await fireWithoutAuth(fn, "get", "/characters/{character_id}/assets/", {
|
|
394
|
+
auth: true,
|
|
395
|
+
pathParams: 12354
|
|
396
|
+
});
|
|
397
|
+
await fireWithoutAuth(fn, "delete", `/characters/${1234}/fittings/${56789}/`, {
|
|
398
|
+
pathParams: [1234, 56789], // ⚠️ TODO: A semantics error should be deliberately caused here
|
|
399
|
+
auth: true
|
|
400
|
+
}).catch(console.log);
|
|
401
|
+
}
|
|
375
402
|
}
|
|
376
403
|
// - - - - - - - - - - - -
|
|
377
404
|
// Miscellaneous
|
|
@@ -53,7 +53,7 @@ export function decoreateESIRequestBody(requestBody) {
|
|
|
53
53
|
// DEVNOTE: 2025/03/08 - In reality, you only need one function instance for each of "get", "post", "put", and "delete",
|
|
54
54
|
// so you can just refer to the cached functions as a map.
|
|
55
55
|
const methodMap = /** @type {TESIRequestFunctionMethods2<Opt>} */ ({});
|
|
56
|
-
/** @
|
|
56
|
+
/** @satisfies {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
|
|
57
57
|
methodMap[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, Opt>} */ (
|
|
58
58
|
// @ts-expect-error Type peeling due to differences in inference process
|
|
59
59
|
(e, opt) => requestBody(method, e, opt));
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-esi-types",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Extracted the main type of ESI. use for ESI request response types (version 2 only)",
|
|
5
5
|
"main": "v2/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node
|
|
7
|
+
"test": "node request-v3.mjs -debug",
|
|
8
8
|
"test:mini": "node minimal-rq.mjs -debug"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
package/tagged-rq.mjs
CHANGED
|
@@ -43,8 +43,8 @@ if (util.is("withError")) {
|
|
|
43
43
|
},
|
|
44
44
|
// token: "s.s.s"
|
|
45
45
|
})).then(console.log).catch(console.log);
|
|
46
|
-
esi.fittings.delete("/characters/
|
|
47
|
-
pathParams: [1234, 56789],
|
|
46
|
+
esi.fittings.delete("/characters/1234/fittings/56789/", {
|
|
47
|
+
pathParams: [1234, 56789], // ⚠️ TODO: A semantics error should be deliberately caused here
|
|
48
48
|
auth: true
|
|
49
49
|
});
|
|
50
50
|
esi.character.post("/characters/affiliation/", {
|
package/v2/esi-tagged-types.d.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* THIS DTS IS AUTO GENERATED, DO NOT EDIT
|
|
10
10
|
*
|
|
11
11
|
* @file eve-esi-types/v2/esi-tagged-types.d.ts
|
|
12
|
-
* @summary This file is auto-generated and defines version 3.0
|
|
12
|
+
* @summary This file is auto-generated and defines version 3.1.0 of the EVE Online ESI response types.
|
|
13
13
|
*/
|
|
14
|
-
import { TESIResponseOKMap
|
|
14
|
+
import { TESIResponseOKMap } from "./index.d.ts";
|
|
15
15
|
export * from "./index.d.ts";
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -30,13 +30,12 @@ export declare type LCamelCase<S extends string> = S extends `${infer P1} ${infe
|
|
|
30
30
|
? `${Lowercase<P1>}${Capitalize<P2>}` : Lowercase<S>;
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
declare type
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare type InferSomethingBy<Tag, AsType extends EInferSomethingBy = EInferSomethingBy["METHOD"]> = {
|
|
33
|
+
declare type InferSomethingByBrand<N = number> = N & { __enum: "InferSomethingBy" };
|
|
34
|
+
declare type InferSomethingByMethod = InferSomethingByBrand<0>;
|
|
35
|
+
declare type InferSomethingByTags = InferSomethingByBrand<1>;
|
|
36
|
+
declare type InferSomethingBy<Tag, AsType extends InferSomethingByBrand = InferSomethingByMethod> = {
|
|
38
37
|
[M in TESIEntryMethod]: TESIResponseOKMap[M] extends Record<`/${string}/`, { tag: infer ActualTag }>
|
|
39
|
-
? AsType extends
|
|
38
|
+
? AsType extends InferSomethingByTags
|
|
40
39
|
? ActualTag : ActualTag extends Tag
|
|
41
40
|
? M
|
|
42
41
|
: never
|
|
@@ -50,7 +49,7 @@ declare type InferSomethingBy<Tag, AsType extends EInferSomethingBy = EInferSome
|
|
|
50
49
|
* @template M - The HTTP method.
|
|
51
50
|
* @date 2025/2/28
|
|
52
51
|
*/
|
|
53
|
-
export declare type ESITags = InferSomethingBy<never,
|
|
52
|
+
export declare type ESITags = InferSomethingBy<never, InferSomethingByTags>
|
|
54
53
|
|
|
55
54
|
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
56
55
|
// Utility Type `InferMethod`
|
|
@@ -89,13 +88,14 @@ export declare type InferMethod<Tag> = InferSomethingBy<Tag>
|
|
|
89
88
|
* The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
|
|
90
89
|
* the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
|
|
91
90
|
*/
|
|
91
|
+
// TODO: 2025/3/16 1:20:50 Generics bug maybe OK?
|
|
92
92
|
export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Tag extends ESITags, ActualOpt = {}> = <
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
RealEP extends ReplacePathParams<ESIEndpointOf<M>> | ESIEndpointOf<M>,
|
|
94
|
+
EPx extends ResolvedEndpoint<RealEP, M>,
|
|
95
|
+
PathParams extends InferPathParams<RealEP, EPx>,
|
|
96
|
+
Opt extends IdentifyParameters<M, EPx, ActualOpt & PathParams>,
|
|
97
|
+
R extends InferESIResponseResult<M, EPx>,
|
|
98
|
+
HasOpt = HasRequireParams<M, EPx, PathParams>,
|
|
99
99
|
// RealEPX = ReplacePathParamsX<RealEPX>,
|
|
100
100
|
// EPX = ReplacePathParams<EP>,
|
|
101
101
|
>(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
|
package/v2/index.d.ts
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
* THIS DTS IS AUTO GENERATED, DO NOT EDIT
|
|
10
10
|
*
|
|
11
11
|
* @file eve-esi-types/v2/index.d.ts
|
|
12
|
-
* @summary This file is auto-generated and defines version 3.0
|
|
12
|
+
* @summary This file is auto-generated and defines version 3.1.0 of the EVE Online ESI response types.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
import type { TESIResponseOKMap } from "./response-map.d.ts";
|
|
16
15
|
export type { TESIResponseOKMap } from "./response-map.d.ts";
|
|
17
16
|
|
|
@@ -86,23 +85,103 @@ export declare type TESICachedSeconds<
|
|
|
86
85
|
Method extends TESIEntryMethod, AsEndpoint = void
|
|
87
86
|
> = {
|
|
88
87
|
[M in TESIEntryMethod]: {
|
|
89
|
-
[EP in
|
|
88
|
+
[EP in ESIEndpointOf<M>]: TESIResponseOKMap[M][EP] extends { cachedSeconds: number }
|
|
90
89
|
? AsEndpoint extends void
|
|
91
90
|
? TESIResponseOKMap[M][EP]["cachedSeconds"]: EP
|
|
92
91
|
: never
|
|
93
|
-
}[
|
|
92
|
+
}[ESIEndpointOf<M>];
|
|
94
93
|
}[Method];
|
|
95
|
-
// const cacheSecGet: TESICachedSeconds<"get">;
|
|
96
|
-
// const cache5sec: TESICachedSeconds<"put">;
|
|
97
|
-
// const cache3600sEndpoint: TESICachedSeconds<"post", 1>;
|
|
98
|
-
|
|
94
|
+
// declare const cacheSecGet: TESICachedSeconds<"get">;
|
|
95
|
+
// declare const cache5sec: TESICachedSeconds<"put">;
|
|
96
|
+
// declare const cache3600sEndpoint: TESICachedSeconds<"post", 1>;
|
|
97
|
+
// TODO: 2025/3/17 How do I get rid of `pathParams` completely?
|
|
98
|
+
export declare type TPathParamsNever = { /* pathParams?: never */ };
|
|
99
|
+
|
|
100
|
+
// local types
|
|
101
|
+
/**
|
|
102
|
+
* Infers the response type of an ESI request based on the HTTP method and endpoint.
|
|
103
|
+
*
|
|
104
|
+
* This type extracts the response type from the `TESIResponseOKMap` based on the provided
|
|
105
|
+
* HTTP method and endpoint.
|
|
106
|
+
*
|
|
107
|
+
* @template M - The HTTP method to use for the request.
|
|
108
|
+
* @template EPx - The endpoint path.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* type ResponseType = _ESIResponseType<"get", "/characters/{character_id}/">;
|
|
113
|
+
* // Result: The inferred response type for the given method and endpoint.
|
|
114
|
+
* ```
|
|
115
|
+
* @internal
|
|
116
|
+
* @see {@link ESIEndpointOf}
|
|
117
|
+
*/
|
|
118
|
+
export type _ESIResponseType<
|
|
119
|
+
M extends TESIEntryMethod,
|
|
120
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
121
|
+
> = TESIResponseOKMap[M][Extract<EPx, ESIEndpointOf<M>>];
|
|
122
|
+
// type XOK = _ESIResponseType<"get", "/status/"> extends global._ESIResponseType<"get", "/status/"> ? 1 : 0;
|
|
123
|
+
/**
|
|
124
|
+
* Determines if the endpoint requires path parameters.
|
|
125
|
+
*
|
|
126
|
+
* @template EP - The string representing the endpoint path.
|
|
127
|
+
* @returns {TPathParamsNever | { pathParams: IfParameterizedPath<EP> }}
|
|
128
|
+
* Returns an object with `pathParams` if the endpoint requires parameters, otherwise returns `TPathParamsNever`.
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* type Example = IfNeedPathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
132
|
+
* // Result: { pathParams: [number, number] }
|
|
133
|
+
* ```
|
|
134
|
+
* @internal
|
|
135
|
+
* @see {@link IfParameterizedPath}
|
|
136
|
+
* @see {@link ReplacePathParams}
|
|
137
|
+
*/
|
|
138
|
+
export type _IfNeedPathParams<EP extends unknown> = IfParameterizedPath<EP> extends never ? TPathParamsNever :
|
|
139
|
+
EP extends ReplacePathParams<EP> ? TPathParamsNever : { pathParams: IfParameterizedPath<EP> };
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Infer the result type of an ESI response based on the method and endpoint.
|
|
143
|
+
*
|
|
144
|
+
* @template M - The HTTP method (e.g., "get", "post").
|
|
145
|
+
* @template EP - The endpoint path.
|
|
146
|
+
* @deprecated 2025/3/17 12:12:33
|
|
147
|
+
*/
|
|
148
|
+
export type __InferESIResponseResult<
|
|
149
|
+
M extends TESIEntryMethod,
|
|
150
|
+
EP extends ESIEndpointOf<M>
|
|
151
|
+
> = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
|
|
152
|
+
/**
|
|
153
|
+
* Identifies the required parameters for a given entry type.
|
|
154
|
+
*
|
|
155
|
+
* @template Entry - The entry type to identify parameters for.
|
|
156
|
+
* @template Opt - The type of the parameters.
|
|
157
|
+
* @type {Opt & Pick<Entry, Exclude<keyof Entry, "result">>}
|
|
158
|
+
* @deprecated 2025/3/17 12:12:33
|
|
159
|
+
*/
|
|
160
|
+
export type __IdentifyParameters<
|
|
161
|
+
Entry, Opt,
|
|
162
|
+
Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
|
|
163
|
+
// @ts-expect-error
|
|
164
|
+
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
165
|
+
|
|
99
166
|
|
|
100
167
|
declare global {
|
|
101
168
|
|
|
102
169
|
/**
|
|
103
|
-
*
|
|
170
|
+
* Marks specific properties of a type as required.
|
|
171
|
+
*
|
|
172
|
+
* @template T - The original type.
|
|
173
|
+
* @template K - The keys of the properties to mark as required.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* type Original = { a?: number; b?: string; c: boolean };
|
|
178
|
+
* type RequiredA = RequireThese<Original, 'a'>;
|
|
179
|
+
* // Result: { a: number; b?: string; c: boolean }
|
|
180
|
+
* ```
|
|
104
181
|
*/
|
|
105
|
-
type RequireThese<T, K extends keyof T> =
|
|
182
|
+
type RequireThese<T, K extends keyof T> = {
|
|
183
|
+
[P in keyof T]: P extends K ? Required<Pick<T, P>>[P] : T[P];
|
|
184
|
+
};
|
|
106
185
|
|
|
107
186
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
108
187
|
// Version 3 types
|
|
@@ -135,15 +214,12 @@ declare global {
|
|
|
135
214
|
*/
|
|
136
215
|
type TESIRequestFunctionSignature2<ActualOpt> = <
|
|
137
216
|
M extends TESIEntryMethod,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
|
|
145
|
-
R extends InferESIResponseResult<M, EP>,
|
|
146
|
-
HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
|
|
217
|
+
RealEP extends ReplacePathParams<ESIEndpointOf<M>> | ESIEndpointOf<M>,
|
|
218
|
+
EPx extends ResolvedEndpoint<RealEP, M>,
|
|
219
|
+
PathParams extends InferPathParams<RealEP, EPx>,
|
|
220
|
+
Opt extends IdentifyParameters<M, EPx, ActualOpt & PathParams>,
|
|
221
|
+
R extends InferESIResponseResult<M, EPx>,
|
|
222
|
+
HasOpt = HasRequireParams<M, EPx, PathParams>,
|
|
147
223
|
>(method: M, endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
|
|
148
224
|
|
|
149
225
|
/**
|
|
@@ -170,83 +246,140 @@ declare global {
|
|
|
170
246
|
* the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
|
|
171
247
|
*/
|
|
172
248
|
type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
|
|
173
|
-
RealEP extends ReplacePathParams<
|
|
174
|
-
|
|
175
|
-
PathParams extends RealEP
|
|
176
|
-
Opt extends IdentifyParameters<
|
|
177
|
-
R extends InferESIResponseResult<M,
|
|
178
|
-
HasOpt = HasRequireParams<
|
|
249
|
+
RealEP extends ReplacePathParams<ESIEndpointOf<M>> | ESIEndpointOf<M>,
|
|
250
|
+
EPx extends ResolvedEndpoint<RealEP, M>,
|
|
251
|
+
PathParams extends InferPathParams<RealEP, EPx>,
|
|
252
|
+
Opt extends IdentifyParameters<M, EPx, ActualOpt & PathParams>,
|
|
253
|
+
R extends InferESIResponseResult<M, EPx>,
|
|
254
|
+
HasOpt = HasRequireParams<M, EPx, PathParams>,
|
|
179
255
|
>(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
|
|
180
256
|
|
|
181
257
|
/**
|
|
182
258
|
* Replaces path parameters in a string with numbers.
|
|
183
259
|
*
|
|
184
260
|
* @template T - The string representing the endpoint path.
|
|
261
|
+
* @type {string}
|
|
185
262
|
* @example
|
|
186
263
|
* ```ts
|
|
187
264
|
* type Example = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
188
265
|
* // Result: `/characters/${number}/fittings/${number}/`
|
|
189
266
|
* ```
|
|
190
267
|
*/
|
|
191
|
-
type ReplacePathParams<T extends
|
|
268
|
+
type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
|
|
192
269
|
? `${Start}${number}${ReplacePathParams<End>}` : T;
|
|
193
|
-
|
|
194
|
-
// //
|
|
270
|
+
// type XEPP = ESIEndpointOf<"delete">
|
|
271
|
+
// // incomplete
|
|
272
|
+
// type Example2 = ReplacePathParams<"/characters/1234/fittings/{fitting_id}/">;
|
|
195
273
|
// // Result: `characters/${number}/fittings/${number}/`
|
|
196
|
-
// type
|
|
197
|
-
|
|
198
|
-
// : T;
|
|
274
|
+
// type Example3 = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
275
|
+
|
|
199
276
|
/**
|
|
200
|
-
*
|
|
277
|
+
* Infers the path parameters based on the real endpoint and the resolved endpoint.
|
|
201
278
|
*
|
|
202
|
-
* @template
|
|
203
|
-
* @
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* // Result: { pathParams: [number, number] }
|
|
209
|
-
* ```
|
|
279
|
+
* @template RealEP - The real endpoint path.
|
|
280
|
+
* @template EPx - The resolved endpoint path.
|
|
281
|
+
* @returns {TPathParamsNever | _IfNeedPathParams<EPx>}
|
|
282
|
+
* @see {@link _IfNeedPathParams}
|
|
283
|
+
* @see {@link TPathParamsNever}
|
|
284
|
+
* @date 2025/3/17 4:32:47
|
|
210
285
|
*/
|
|
211
|
-
type
|
|
212
|
-
|
|
286
|
+
type InferPathParams<
|
|
287
|
+
RealEP extends unknown, EPx extends unknown
|
|
288
|
+
> = RealEP extends EPx ? _IfNeedPathParams<EPx> : TPathParamsNever;
|
|
289
|
+
|
|
213
290
|
/**
|
|
214
|
-
* Infers the original endpoint
|
|
291
|
+
* Infers the original endpoint based on the real endpoint and the HTTP method.
|
|
292
|
+
*
|
|
293
|
+
* This type maps the real endpoint to its corresponding parameterized endpoint
|
|
294
|
+
* by checking if the real endpoint matches the pattern of any parameterized endpoint.
|
|
215
295
|
*
|
|
216
296
|
* @template RealEP - The real endpoint path.
|
|
217
|
-
* @
|
|
297
|
+
* @template M - The HTTP method to use for the request.
|
|
298
|
+
* @template Endpoints - The possible endpoints for the given method.
|
|
299
|
+
*
|
|
218
300
|
* @example
|
|
219
301
|
* ```ts
|
|
220
|
-
* type
|
|
302
|
+
* type Original = InferEndpointOrigin<"/characters/123/fittings/456/", "delete">;
|
|
221
303
|
* // Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
222
304
|
* ```
|
|
305
|
+
* @see {@link ESIEndpointOf}
|
|
306
|
+
* @see {@link ReplacePathParams}
|
|
223
307
|
*/
|
|
224
|
-
type InferEndpointOrigin<
|
|
308
|
+
type InferEndpointOrigin<
|
|
309
|
+
RealEP extends unknown, M extends TESIEntryMethod,
|
|
310
|
+
Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>
|
|
311
|
+
> = {
|
|
225
312
|
[EP in Endpoints]: RealEP extends ReplacePathParams<EP>
|
|
226
313
|
? EP : never;
|
|
227
314
|
}[Endpoints];
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Determines the resolved endpoint based on the real endpoint and the method.
|
|
317
|
+
*
|
|
318
|
+
* @template RealEP - The real endpoint path.
|
|
319
|
+
* @template M - The HTTP method to use for the request.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* type Resolved = ResolvedEndpoint<"/characters/123/fittings/456/", "delete">;
|
|
324
|
+
* // Result: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
325
|
+
* ```
|
|
326
|
+
* DONE: 2025/3/17 4:12:09 Ok, works
|
|
327
|
+
*
|
|
328
|
+
* @see {@link InferEndpointOrigin}
|
|
329
|
+
*/
|
|
330
|
+
type ResolvedEndpoint<
|
|
331
|
+
RealEP extends unknown, M extends TESIEntryMethod,
|
|
332
|
+
> = InferEndpointOrigin<RealEP, M> extends never ? RealEP: InferEndpointOrigin<RealEP, M>;
|
|
234
333
|
|
|
235
334
|
/**
|
|
236
|
-
*
|
|
335
|
+
* Picks the required parameters from an entry type, including additional parameters.
|
|
336
|
+
*
|
|
337
|
+
* This type excludes the keys "result", "tag", and "cachedSeconds" from the entry type and the additional parameters,
|
|
338
|
+
* and returns the remaining keys as the required parameters.
|
|
339
|
+
*
|
|
340
|
+
* @template M - The HTTP method to use for the request.
|
|
341
|
+
* @template EPx - The endpoint path.
|
|
342
|
+
* @template AdditionalParams - Additional parameters to include in the check.
|
|
343
|
+
* @template Entry - The entry type to pick parameters from.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
348
|
+
* type RequiredParams = PickRequireParams<"get", "/example/endpoint", { auth: string }, ExampleEntry>;
|
|
349
|
+
* // Result: "auth"
|
|
350
|
+
* ```
|
|
351
|
+
* @see {@link ESIEndpointOf}
|
|
352
|
+
* @see {@link _ESIResponseType}
|
|
353
|
+
*/
|
|
354
|
+
type PickRequireParams<
|
|
355
|
+
M extends TESIEntryMethod,
|
|
356
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
357
|
+
AdditionalParams,
|
|
358
|
+
Entry = _ESIResponseType<M, EPx>
|
|
359
|
+
> = Exclude<keyof (Entry & AdditionalParams), "result" | "tag" | "cachedSeconds">;
|
|
360
|
+
/**
|
|
361
|
+
* Determines if the given entry has required parameters, including additional options.
|
|
237
362
|
*
|
|
238
363
|
* This type checks if an entry has any required parameters by excluding the keys "result", "tag", and "cachedSeconds".
|
|
239
364
|
* If any keys remain after this exclusion, it means the entry has required parameters.
|
|
240
365
|
*
|
|
241
|
-
* @template
|
|
366
|
+
* @template M - The HTTP method to use for the request.
|
|
367
|
+
* @template EPx - The endpoint path.
|
|
368
|
+
* @template AdditionalParams - Additional parameters to include in the check.
|
|
242
369
|
*
|
|
243
370
|
* @example
|
|
244
371
|
* ```ts
|
|
245
372
|
* type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
246
|
-
* type HasRequired = HasRequireParams<
|
|
373
|
+
* type HasRequired = HasRequireParams<"get", "/example/endpoint", { auth: string }>; // 1
|
|
247
374
|
* ```
|
|
375
|
+
* @see {@link ESIEndpointOf}
|
|
376
|
+
* @see {@link PickRequireParams}
|
|
248
377
|
*/
|
|
249
|
-
type HasRequireParams<
|
|
378
|
+
type HasRequireParams<
|
|
379
|
+
M extends TESIEntryMethod,
|
|
380
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
381
|
+
AdditionalParams,
|
|
382
|
+
> = PickRequireParams<M, EPx, AdditionalParams> extends never ? 0 : 1;
|
|
250
383
|
|
|
251
384
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
252
385
|
// Version 2 types
|
|
@@ -259,41 +392,76 @@ declare global {
|
|
|
259
392
|
* @returns {number | [number, number] | Opt}
|
|
260
393
|
* Returns `number` if there is one parameter, `[number, number]` if there are two parameters, otherwise `Opt`.
|
|
261
394
|
*/
|
|
262
|
-
type IfParameterizedPath<EP, Opt = never> = EP extends `${string}/{${string}}${string}`
|
|
395
|
+
type IfParameterizedPath<EP extends unknown, Opt = never> = EP extends `${string}/{${string}}${string}`
|
|
263
396
|
? PickPathParameters<EP> extends never
|
|
264
397
|
? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
|
|
265
398
|
? number : [number, number]
|
|
266
399
|
: Opt;
|
|
267
400
|
|
|
268
401
|
/**
|
|
269
|
-
* Identifies the required parameters for a given entry type.
|
|
402
|
+
* Identifies the required parameters for a given entry type, including additional options.
|
|
403
|
+
*
|
|
404
|
+
* This type combines the required parameters from the entry type and the additional options,
|
|
405
|
+
* ensuring that all required parameters are marked as required.
|
|
270
406
|
*
|
|
407
|
+
* @template M - The HTTP method to use for the request.
|
|
408
|
+
* @template EPx - The endpoint path.
|
|
409
|
+
* @template Opt - The type of the additional options.
|
|
271
410
|
* @template Entry - The entry type to identify parameters for.
|
|
272
|
-
* @template
|
|
273
|
-
*
|
|
411
|
+
* @template Keys - The keys of the entry type that are required parameters.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
416
|
+
* type ExampleOpt = { auth: string };
|
|
417
|
+
* type IdentifiedParams = IdentifyParameters<"get", "/example/endpoint", ExampleOpt, ExampleEntry>;
|
|
418
|
+
* // Result: { auth: string } & { auth: string }
|
|
419
|
+
* ```
|
|
420
|
+
* @see {@link RequireThese}
|
|
421
|
+
* @see {@link ESIEndpointOf}
|
|
422
|
+
* @see {@link _ESIResponseType}
|
|
274
423
|
*/
|
|
275
424
|
//* ctt
|
|
276
425
|
type IdentifyParameters<
|
|
277
|
-
|
|
426
|
+
M extends TESIEntryMethod,
|
|
427
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
428
|
+
Opt extends Record<string, unknown>,
|
|
429
|
+
Entry = _ESIResponseType<M, EPx>,
|
|
278
430
|
Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
|
|
431
|
+
// @ts-expect-error
|
|
279
432
|
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
280
433
|
/*/
|
|
281
434
|
type IdentifyParameters<
|
|
282
435
|
Entry, Opt,
|
|
283
|
-
Keys = Exclude<keyof Entry, "result">
|
|
284
|
-
|
|
436
|
+
Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
|
|
437
|
+
// @ts-expect-error
|
|
438
|
+
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
439
|
+
// type IdentifyParameters<
|
|
440
|
+
// Entry, Opt,
|
|
441
|
+
// Keys = Exclude<keyof Entry, "result">
|
|
442
|
+
// > = Opt & (Keys extends keyof Entry ? Pick<Entry, Keys> : {});
|
|
285
443
|
//*/
|
|
286
444
|
|
|
287
445
|
/**
|
|
288
|
-
*
|
|
446
|
+
* Infers the result type of an ESI response based on the method and endpoint.
|
|
447
|
+
*
|
|
448
|
+
* @template M - The HTTP method to use for the request.
|
|
449
|
+
* @template EPx - The endpoint path.
|
|
289
450
|
*
|
|
290
|
-
* @
|
|
291
|
-
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```ts
|
|
453
|
+
* type Result = InferESIResponseResult<"get", "/characters/{character_id}/">;
|
|
454
|
+
* // Result: The inferred type of the response for the given method and endpoint.
|
|
455
|
+
* ```
|
|
456
|
+
* @see {@link ESIEndpointOf}
|
|
457
|
+
* @see {@link _ESIResponseType}
|
|
292
458
|
*/
|
|
293
459
|
type InferESIResponseResult<
|
|
294
460
|
M extends TESIEntryMethod,
|
|
295
|
-
|
|
296
|
-
> =
|
|
461
|
+
EPx extends ESIEndpointOf<M> | string
|
|
462
|
+
> = _ESIResponseType<M, EPx> extends { result: infer U } ? U : never;
|
|
463
|
+
/*
|
|
464
|
+
*/
|
|
297
465
|
|
|
298
466
|
/**
|
|
299
467
|
* Represents a response with no content (HTTP status 204).
|
|
@@ -309,22 +477,26 @@ declare global {
|
|
|
309
477
|
*/
|
|
310
478
|
type TESIEntryMethod = keyof TESIResponseOKMap;
|
|
311
479
|
|
|
480
|
+
/**
|
|
481
|
+
* @date 2025/3/16 21:45:50
|
|
482
|
+
*/
|
|
483
|
+
type ESIEndpointOf<M extends TESIEntryMethod> = keyof TESIResponseOKMap[M];
|
|
312
484
|
/**
|
|
313
485
|
* Represents the endpoints for the "get" method.
|
|
314
486
|
*/
|
|
315
|
-
type TEndPointGet =
|
|
487
|
+
type TEndPointGet = ESIEndpointOf<"get">;
|
|
316
488
|
/**
|
|
317
489
|
* Represents the endpoints for the "post" method.
|
|
318
490
|
*/
|
|
319
|
-
type TEndPointPost =
|
|
491
|
+
type TEndPointPost = ESIEndpointOf<"post">;
|
|
320
492
|
/**
|
|
321
493
|
* Represents the endpoints for the "put" method.
|
|
322
494
|
*/
|
|
323
|
-
type TEndPointPut =
|
|
495
|
+
type TEndPointPut = ESIEndpointOf<"put">;
|
|
324
496
|
/**
|
|
325
497
|
* Represents the endpoints for the "delete" method.
|
|
326
498
|
*/
|
|
327
|
-
type TEndPointDelete =
|
|
499
|
+
type TEndPointDelete = ESIEndpointOf<"delete">;
|
|
328
500
|
|
|
329
501
|
/**
|
|
330
502
|
* Represents the entry details for the "get" method.
|
package/v2/response-map.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* THIS DTS IS AUTO GENERATED, DO NOT EDIT
|
|
10
10
|
*
|
|
11
11
|
* @file eve-esi-types/v2/response-map.d.ts
|
|
12
|
-
* @summary This file is auto-generated and defines version 3.0
|
|
12
|
+
* @summary This file is auto-generated and defines version 3.1.0 of the EVE Online ESI response types.
|
|
13
13
|
*/
|
|
14
14
|
import "./types-index.d.ts";
|
|
15
15
|
|
package/v2/types-index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* THIS DTS IS AUTO GENERATED, DO NOT EDIT
|
|
10
10
|
*
|
|
11
11
|
* @file eve-esi-types/v2/types-index.d.ts
|
|
12
|
-
* @summary This file is auto-generated and defines version 3.0
|
|
12
|
+
* @summary This file is auto-generated and defines version 3.1.0 of the EVE Online ESI response types.
|
|
13
13
|
*/
|
|
14
14
|
import "./get_wars_ok.d.ts";
|
|
15
15
|
import "./get_status_ok.d.ts";
|
|
File without changes
|