eve-esi-types 3.0.3 → 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 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 -> [`v2.mjs`](./v2.mjs)
11
+ > Sample code is provided -> [`request-v3.mjs`](./request-v3.mjs)
12
12
 
13
13
  ```shell
14
- $ node v2.mjs
14
+ $ node request-v3.mjs
15
15
  ```
16
16
 
17
17
  ## API
@@ -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
- ## TESICachedSeconds
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
- ```typescript
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
- ## TPathParamsNever
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
- ```typescript
31
- type TPathParamsNever = { pathParams?: never };
32
- ```
17
+ #### Type Parameters
33
18
 
34
- ## TESIRequestFunctionSignature2
35
- `TESIRequestFunctionSignature2` is a type that defines the signature of an ESI request function.
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
- ```typescript
38
- type TESIRequestFunctionSignature2<ActualOpt> = <
39
- M extends TESIEntryMethod,
40
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
41
- EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
42
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
43
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
44
- R extends InferESIResponseResult<M, EP>
45
- >(method: M, endpoint: RealEP, options?: Opt) => Promise<R>;
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 string> = T extends `${infer Start}{${infer Param}}${infer End}`
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
- ## IfNeedPathParams
70
- `IfNeedPathParams` is a type that determines if the endpoint requires path parameters.
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 IfNeedPathParams<EP> = IfParameterizedPath<EP> extends never ? TPathParamsNever :
74
- EP extends ReplacePathParams<EP> ? TPathParamsNever : { pathParams: IfParameterizedPath<EP> };
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
- `InferEndpointOrigin` is a type that infers the original endpoint path from a real endpoint path.
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<RealEP extends unknown, Endpoints> = {
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
- `IfParameterizedPath` is a type that determines the required number of replacements if the endpoint is a parameterized path.
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
- `IdentifyParameters` is a type that identifies the required parameters for a given entry type.
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
- Entry, Opt,
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
- EP extends keyof TESIResponseOKMap[M]
115
- > = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
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
- ## TEndPointGet
133
- `TEndPointGet` is a type that represents the endpoints for the "get" method.
262
+ <details>
263
+ > Example
134
264
 
135
- ```typescript
136
- type TEndPointGet = keyof TESIResponseOKMap["get"];
137
- ```
265
+ ```typescript
266
+ "get" | "post" | "put" | "delete"
267
+ ```
268
+ </details>
138
269
 
139
- ## TEndPointPost
140
- `TEndPointPost` is a type that represents the endpoints for the "post" method.
270
+ ## ESIEndpointOf
141
271
 
142
- ```typescript
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 TEndPointPut = keyof TESIResponseOKMap["put"];
275
+ type ESIEndpointOf<M extends TESIEntryMethod> = keyof TESIResponseOKMap[M];
151
276
  ```
152
277
 
153
- ## TEndPointDelete
154
- `TEndPointDelete` is a type that represents the endpoints for the "delete" method.
278
+ <details>
279
+ > Example
155
280
 
156
- ```typescript
157
- type TEndPointDelete = keyof TESIResponseOKMap["delete"];
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
@@ -69,8 +69,8 @@ export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endp
69
69
  // implements rest methods of `request` (IESIRequestFunction2)
70
70
  //
71
71
  /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
72
- request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method>} */ (function (endpoint, opt) {
73
- // @ts-expect-error TODO: 2025/3/12
74
- return this(method, endpoint, opt);
72
+ request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
73
+ // @ts-expect-error TODO: ts(2345)
74
+ return request2(method, endpoint, opt);
75
75
  });
76
76
  });
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 { TESIResponseOKMap, TESIRequestFunctionMethods2, TPathParamsNever } from "../v2";
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
- fireWithoutAuth<M extends TESIEntryMethod, RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M], EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP : InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>, PathParams extends RealEP extends EP ? IfNeedPathParams<EP> : TPathParamsNever, Opt extends IdentifyParameters<TESIResponseOKMap[M][Extract<EP, keyof TESIResponseOKMap[M]>], ESIRequestOptions & PathParams>, R extends InferESIResponseResult<M, Extract<EP, keyof TESIResponseOKMap[M]>>, HasOpt = HasRequireParams<TESIResponseOKMap[M][Extract<EP, keyof TESIResponseOKMap[M]>]> extends never ? 0 : 1>(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>, method: M, endpoint: RealEP, ...opt: HasOpt extends 1 ? [Opt] : [Opt?]): Promise<R>;
186
- }["fireWithoutAuth"];
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,18 +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
  */
346
+ // @ts-expect -error
328
347
  const fireWithoutAuth = (fn, method, endpoint, ...opt) => {
348
+ const arg = opt.length ? opt[0] : void 0;
329
349
  if (typeof fn === "function") {
330
350
  // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
331
- return fn(method, endpoint, opt);
351
+ return fn(method, endpoint, arg);
332
352
  }
333
353
  // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
334
- return fn[method](endpoint, opt);
354
+ return fn[method](endpoint, arg);
335
355
  };
336
356
  /**
337
357
  * Need typescript v5.5 later
@@ -357,7 +377,9 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
357
377
  // Here, I borrow data from "CCP Zoetrope".
358
378
  clog();
359
379
  casefireWithoutAuth: {
360
- await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/`).then(log);
380
+ await fireWithoutAuth(fn, "get", `/characters/{character_id}/`, {
381
+ pathParams: ID_CCP_Zoetrope
382
+ }).then(log);
361
383
  clog('(portrait)');
362
384
  await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/portrait/`).then(log);
363
385
  clog('(affiliation)');
@@ -367,10 +389,16 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
367
389
  await fireWithoutAuth(fn, "get", `/corporations/${affiliation[0].corporation_id}/`).then(log);
368
390
  rlog("get:/incursions/".green);
369
391
  await fireWithoutAuth(fn, "get", "/incursions/").then(log);
370
- fireWithoutAuth(fn, "delete", `/characters/${1234}/fittings/${56789}/`, {
371
- // pathParams: [1234, 56789],
372
- auth: true
373
- }).catch(console.log);
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
+ }
374
402
  }
375
403
  // - - - - - - - - - - - -
376
404
  // Miscellaneous
@@ -405,6 +433,7 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
405
433
  auth: true,
406
434
  token: "token.token.token"
407
435
  });
436
+ log(`get:/characters/${ID_CCP_Zoetrope}/ship/, returns=${willFailed}`);
408
437
  // in this case, "categories" and "search" is required
409
438
  await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
410
439
  pathParams: ID_CCP_Zoetrope,
@@ -414,16 +443,15 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
414
443
  },
415
444
  auth: true
416
445
  });
417
- // TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
418
- // Or rather, I don't know how to do it.
419
- await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
420
- auth: true,
421
- pathParams: 1234,
422
- query: {
423
- categories: ["alliance"], search: "test!!"
424
- }
425
- });
426
- log(willFailed);
446
+ // // TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
447
+ // // Or rather, I don't know how to do it.
448
+ // await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
449
+ // auth: true,
450
+ // pathParams: 1234,
451
+ // query: {
452
+ // categories: ["alliance"], search: "test!!"
453
+ // }
454
+ // });
427
455
  }
428
456
  catch (e) {
429
457
  console.error("Failed to request -", e);
@@ -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
- /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
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/minimal-rq.mjs CHANGED
@@ -27,9 +27,9 @@ const log = util.getUniversalLogger("[request-mini]: ");
27
27
  // Delegates implementation to `request` (TESIRequestFunctionMethods2)
28
28
  //
29
29
  const esiMethods = /** @type {TESIRequestFunctionMethods2} */ ({});
30
- /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
31
- esiMethods[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method>} */ (function (endpoint, opt) {
32
- // @ts-expect-error
30
+ /** @satisfies {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
31
+ esiMethods[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
32
+ // @ts-expect-error ts(2345)
33
33
  return request2(method, endpoint, opt);
34
34
  });
35
35
  });
@@ -39,18 +39,20 @@ const esiMethods = /** @type {TESIRequestFunctionMethods2} */ ({});
39
39
  */
40
40
  async function getEVEStatus2(fn) {
41
41
  await util.getSDEVersion().then(sdeVersion => log(`sdeVersion: ${sdeVersion}`.blue));
42
+ const { clog, rlog } = util.getLogger();
43
+ rlog("- - - - - - - > run as IESIRequestFunction2<ESIRequestOptions>".red, fn);
42
44
  await util.fireRequestsDoesNotRequireAuth(fn);
43
45
  CaseIESIRequestFunctionMethods: {
46
+ rlog("- - - - - - - > run as TESIRequestFunctionMethods2<ESIRequestOptions>".red, esiMethods);
44
47
  await util.fireRequestsDoesNotRequireAuth(esiMethods);
45
48
  }
46
- const { clog, rlog } = util.getLogger();
47
49
  CaseIESIRequestFunction2: {
48
50
  const ID_CCP_Zoetrope = 2112625428;
49
51
  // - - - - - - - - - - - -
50
52
  // Character
51
53
  // - - - - - - - - - - - -
52
54
  // Here, I borrow data from "CCP Zoetrope".
53
- rlog("- - - - - - - > run as IESIRequestFunction2<ESIRequestOptions>".red);
55
+ rlog("- - - - - - - > run as IESIRequestFunction2::TESIRequestFunctionMethods2<ESIRequestOptions>".red, fn);
54
56
  clog();
55
57
  await fn.get("/characters/{character_id}/", { pathParams: ID_CCP_Zoetrope }).then(log);
56
58
  clog('(portrait)');
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "eve-esi-types",
3
- "version": "3.0.3",
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 v2.mjs -debug",
7
+ "test": "node request-v3.mjs -debug",
8
8
  "test:mini": "node minimal-rq.mjs -debug"
9
9
  },
10
10
  "repository": {
@@ -92,7 +92,7 @@ async function getEVEStatus(fn) {
92
92
  return fn("get", "/status/");
93
93
  }
94
94
  // type following and run
95
- // node v2.mjs
95
+ // node request-v3.mjs
96
96
  // or yarn test
97
97
  if (!is("x")) {
98
98
  getEVEStatus(fire).then(eveStatus => log(eveStatus));
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/{character_id}/fittings/{fitting_id}/", {
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/", {
@@ -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.3 of the EVE Online ESI response types.
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, TPathParamsNever } from "./index.d.ts";
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 EInferSomethingBy = {
34
- readonly METHOD: 0;
35
- readonly TAGs: 1;
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 EInferSomethingBy["TAGs"]
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, EInferSomethingBy["TAGs"]>
52
+ export declare type ESITags = InferSomethingBy<never, InferSomethingByTags>
54
53
 
55
54
  // - - - - - - - - - - - - - - - - - - - - - - - - - -
56
55
  // Utility Type `InferMethod`
@@ -82,17 +81,21 @@ export declare type InferMethod<Tag> = InferSomethingBy<Tag>
82
81
  *
83
82
  * @param endpoint - The endpoint path.
84
83
  * @param pathParams - The path parameters.
85
- * @param options - The request options.
84
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
86
85
  * @returns A promise that resolves to the response.
87
- * @date 2025/2/28
86
+ *
87
+ * @remarks
88
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
89
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
88
90
  */
91
+ // TODO: 2025/3/16 1:20:50 Generics bug maybe OK?
89
92
  export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Tag extends ESITags, ActualOpt = {}> = <
90
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
91
- EP extends InferEndpointOrigin<RealEP, SelectEndpointByTag<Tag, M>> extends never ? RealEP: InferEndpointOrigin<RealEP, SelectEndpointByTag<Tag, M>>,
92
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
93
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
94
- R extends InferESIResponseResult<M, EP>,
95
- HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
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>,
96
99
  // RealEPX = ReplacePathParamsX<RealEPX>,
97
100
  // EPX = ReplacePathParams<EP>,
98
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.3 of the EVE Online ESI response types.
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 keyof TESIResponseOKMap[M]]: TESIResponseOKMap[M][EP]["cachedSeconds"] extends number
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
- }[keyof TESIResponseOKMap[M]];
92
+ }[ESIEndpointOf<M>];
94
93
  }[Method];
95
- // const cacheSecGet: TESICachedSeconds<"get">;
96
- // const cache5sec: TESICachedSeconds<"put">;
97
- // const cache3600sEndpoint: TESICachedSeconds<"post", 1>;
98
- export declare type TPathParamsNever = { pathParams?: never };
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
- * mark a specific property as `required`
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> = T & Required<Pick<T, K>>;
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
@@ -125,21 +204,22 @@ declare global {
125
204
  *
126
205
  * @param method - The HTTP method to use for the request (e.g., "get", "post").
127
206
  * @param endpoint - The real path of the ESI endpoint to send the request to.
128
- * @param options - An optional object containing additional options for the request.
207
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
129
208
  *
130
209
  * @returns A Promise object containing the response data, with the type inferred based on the method and endpoint.
210
+ *
211
+ * @remarks
212
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
213
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
131
214
  */
132
215
  type TESIRequestFunctionSignature2<ActualOpt> = <
133
216
  M extends TESIEntryMethod,
134
- // "/characters/123/fittings/456/"
135
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
136
- // "/characters/{character_id}/fittings/{fitting_id}/"
137
- EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
138
- // If RealEP points to an endpoint origin (not a replaced endpoint), the path parameter is required
139
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
140
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
141
- R extends InferESIResponseResult<M, EP>,
142
- 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>,
143
223
  >(method: M, endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
144
224
 
145
225
  /**
@@ -157,88 +237,149 @@ declare global {
157
237
  * @template R - The response type.
158
238
  *
159
239
  * @param endpoint - The real path of the ESI endpoint to send the request to.
160
- * @param options - An optional object containing additional options for the request.
240
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
161
241
  *
162
242
  * @returns A Promise object containing the response data, with the type inferred based on the method and endpoint.
243
+ *
244
+ * @remarks
245
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
246
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
163
247
  */
164
248
  type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
165
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
166
- EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
167
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
168
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
169
- R extends InferESIResponseResult<M, EP>,
170
- HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
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>,
171
255
  >(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
172
256
 
173
257
  /**
174
258
  * Replaces path parameters in a string with numbers.
175
259
  *
176
260
  * @template T - The string representing the endpoint path.
261
+ * @type {string}
177
262
  * @example
178
263
  * ```ts
179
264
  * type Example = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
180
265
  * // Result: `/characters/${number}/fittings/${number}/`
181
266
  * ```
182
267
  */
183
- type ReplacePathParams<T extends string> = T extends `${infer Start}{${infer Param}}${infer End}`
268
+ type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
184
269
  ? `${Start}${number}${ReplacePathParams<End>}` : T;
185
-
186
- // // type Example = ReplacePathParamsX<"/characters/1234/fittings/{fitting_id}/">;
270
+ // type XEPP = ESIEndpointOf<"delete">
271
+ // // incomplete
272
+ // type Example2 = ReplacePathParams<"/characters/1234/fittings/{fitting_id}/">;
187
273
  // // Result: `characters/${number}/fittings/${number}/`
188
- // type ReplacePathParamsX<T extends string> =
189
- // T extends `/${infer Start}/${infer Param}/${infer End}` ? `${Start}/${number}/${ReplacePathParams<End>}`
190
- // : T;
274
+ // type Example3 = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
275
+
191
276
  /**
192
- * Determines if the endpoint requires path parameters.
277
+ * Infers the path parameters based on the real endpoint and the resolved endpoint.
193
278
  *
194
- * @template EP - The string representing the endpoint path.
195
- * @returns {TPathParamsNever | { pathParams: IfParameterizedPath<EP> }}
196
- * Returns an object with `pathParams` if the endpoint requires parameters, otherwise returns `TPathParamsNever`.
197
- * @example
198
- * ```ts
199
- * type Example = IfNeedPathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
200
- * // Result: { pathParams: [number, number] }
201
- * ```
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
202
285
  */
203
- type IfNeedPathParams<EP> = IfParameterizedPath<EP> extends never ? TPathParamsNever :
204
- EP extends ReplacePathParams<EP> ? TPathParamsNever : { pathParams: IfParameterizedPath<EP> };
286
+ type InferPathParams<
287
+ RealEP extends unknown, EPx extends unknown
288
+ > = RealEP extends EPx ? _IfNeedPathParams<EPx> : TPathParamsNever;
289
+
205
290
  /**
206
- * Infers the original endpoint path from a real endpoint path.
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.
207
295
  *
208
296
  * @template RealEP - The real endpoint path.
209
- * @returns {string} The original endpoint path with parameters.
297
+ * @template M - The HTTP method to use for the request.
298
+ * @template Endpoints - The possible endpoints for the given method.
299
+ *
210
300
  * @example
211
301
  * ```ts
212
- * type EPOrigin = InferEndpointOrigin<"/characters/123/fittings/456/", TEndPointDelete>;
302
+ * type Original = InferEndpointOrigin<"/characters/123/fittings/456/", "delete">;
213
303
  * // Result: "/characters/{character_id}/fittings/{fitting_id}/"
214
304
  * ```
305
+ * @see {@link ESIEndpointOf}
306
+ * @see {@link ReplacePathParams}
215
307
  */
216
- type InferEndpointOrigin<RealEP extends unknown, Endpoints> = {
308
+ type InferEndpointOrigin<
309
+ RealEP extends unknown, M extends TESIEntryMethod,
310
+ Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>
311
+ > = {
217
312
  [EP in Endpoints]: RealEP extends ReplacePathParams<EP>
218
313
  ? EP : never;
219
314
  }[Endpoints];
220
- // type InferEndpointOrigin<RealEP extends string> = {
221
- // [Method in TESIEntryMethod]: {
222
- // [EP in keyof TESIResponseOKMap[Method]]: RealEP extends ReplacePathParams<EP>
223
- // ? EP : never;
224
- // }[keyof TESIResponseOKMap[Method]]
225
- // }[TESIEntryMethod];
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>;
226
333
 
227
334
  /**
228
- * Determines if the given entry has required parameters.
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.
229
362
  *
230
363
  * This type checks if an entry has any required parameters by excluding the keys "result", "tag", and "cachedSeconds".
231
364
  * If any keys remain after this exclusion, it means the entry has required parameters.
232
365
  *
233
- * @template Entry - The entry type to check for required parameters.
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.
234
369
  *
235
370
  * @example
236
371
  * ```ts
237
372
  * type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
238
- * type HasRequired = HasRequireParams<ExampleEntry>; // "auth"
373
+ * type HasRequired = HasRequireParams<"get", "/example/endpoint", { auth: string }>; // 1
239
374
  * ```
375
+ * @see {@link ESIEndpointOf}
376
+ * @see {@link PickRequireParams}
240
377
  */
241
- type HasRequireParams<Entry> = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">;
378
+ type HasRequireParams<
379
+ M extends TESIEntryMethod,
380
+ EPx extends ESIEndpointOf<M> | string,
381
+ AdditionalParams,
382
+ > = PickRequireParams<M, EPx, AdditionalParams> extends never ? 0 : 1;
242
383
 
243
384
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
244
385
  // Version 2 types
@@ -251,41 +392,76 @@ declare global {
251
392
  * @returns {number | [number, number] | Opt}
252
393
  * Returns `number` if there is one parameter, `[number, number]` if there are two parameters, otherwise `Opt`.
253
394
  */
254
- type IfParameterizedPath<EP, Opt = never> = EP extends `${string}/{${string}}${string}`
395
+ type IfParameterizedPath<EP extends unknown, Opt = never> = EP extends `${string}/{${string}}${string}`
255
396
  ? PickPathParameters<EP> extends never
256
397
  ? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
257
398
  ? number : [number, number]
258
399
  : Opt;
259
400
 
260
401
  /**
261
- * 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.
262
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.
263
410
  * @template Entry - The entry type to identify parameters for.
264
- * @template Opt - The type of the parameters.
265
- * @type {Opt & Pick<Entry, Exclude<keyof Entry, "result">>}
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}
266
423
  */
267
424
  //* ctt
268
425
  type IdentifyParameters<
269
- Entry, Opt,
426
+ M extends TESIEntryMethod,
427
+ EPx extends ESIEndpointOf<M> | string,
428
+ Opt extends Record<string, unknown>,
429
+ Entry = _ESIResponseType<M, EPx>,
270
430
  Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
431
+ // @ts-expect-error
271
432
  > = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
272
433
  /*/
273
434
  type IdentifyParameters<
274
435
  Entry, Opt,
275
- Keys = Exclude<keyof Entry, "result">
276
- > = Opt & (Keys extends keyof Entry ? Pick<Entry, Keys> : {});
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> : {});
277
443
  //*/
278
444
 
279
445
  /**
280
- * Infer the result type of an ESI response based on the method and endpoint.
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.
281
450
  *
282
- * @template M - The HTTP method (e.g., "get", "post").
283
- * @template EP - The endpoint path.
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}
284
458
  */
285
459
  type InferESIResponseResult<
286
460
  M extends TESIEntryMethod,
287
- EP extends keyof TESIResponseOKMap[M]
288
- > = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
461
+ EPx extends ESIEndpointOf<M> | string
462
+ > = _ESIResponseType<M, EPx> extends { result: infer U } ? U : never;
463
+ /*
464
+ */
289
465
 
290
466
  /**
291
467
  * Represents a response with no content (HTTP status 204).
@@ -301,22 +477,26 @@ declare global {
301
477
  */
302
478
  type TESIEntryMethod = keyof TESIResponseOKMap;
303
479
 
480
+ /**
481
+ * @date 2025/3/16 21:45:50
482
+ */
483
+ type ESIEndpointOf<M extends TESIEntryMethod> = keyof TESIResponseOKMap[M];
304
484
  /**
305
485
  * Represents the endpoints for the "get" method.
306
486
  */
307
- type TEndPointGet = keyof TESIResponseOKMap["get"];
487
+ type TEndPointGet = ESIEndpointOf<"get">;
308
488
  /**
309
489
  * Represents the endpoints for the "post" method.
310
490
  */
311
- type TEndPointPost = keyof TESIResponseOKMap["post"];
491
+ type TEndPointPost = ESIEndpointOf<"post">;
312
492
  /**
313
493
  * Represents the endpoints for the "put" method.
314
494
  */
315
- type TEndPointPut = keyof TESIResponseOKMap["put"];
495
+ type TEndPointPut = ESIEndpointOf<"put">;
316
496
  /**
317
497
  * Represents the endpoints for the "delete" method.
318
498
  */
319
- type TEndPointDelete = keyof TESIResponseOKMap["delete"];
499
+ type TEndPointDelete = ESIEndpointOf<"delete">;
320
500
 
321
501
  /**
322
502
  * Represents the entry details for the "get" method.
@@ -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.3 of the EVE Online ESI response types.
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
 
@@ -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.3 of the EVE Online ESI response types.
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