eve-esi-types 3.0.4 → 3.1.2

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.
@@ -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.4 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.1.1 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`
@@ -62,26 +61,51 @@ export declare type ESITags = InferSomethingBy<never, EInferSomethingBy["TAGs"]>
62
61
  * @date 2025/2/28
63
62
  */
64
63
  export declare type InferMethod<Tag> = InferSomethingBy<Tag>
65
- // type XAssets = InferMethod<"Assets">;
66
- // type XContacts = InferMethod<"Contacts">;
67
- // type XPlanetary = InferMethod<"Planetary Interaction">;
64
+ /* ctt
65
+ type XAssets = InferMethod<"Assets">;
66
+ type XContacts = InferMethod<"Contacts">;
67
+ type XPlanetary = InferMethod<"Planetary Interaction">;
68
+ /*/
69
+ //*/
68
70
 
69
71
  // - - - - - - - - - - - - - - - - - - - - - - - - - -
70
72
  // Utility Type `TaggedEndpointRequestFunction2`
71
73
  // - - - - - - - - - - - - - - - - - - - - - - - - - -
74
+ /**
75
+ * Infers the endpoint origin based on the provided endpoints.
76
+ *
77
+ * + Customed InferEndpointOrigin
78
+ *
79
+ * @template RealEP - The real endpoint type.
80
+ * @template Endpoints - The possible endpoints.
81
+ *
82
+ * @typeParam RealEP - The type of the real endpoint.
83
+ * @typeParam Endpoints - The type of the possible endpoints.
84
+ *
85
+ * @returns The inferred endpoint origin.
86
+ */
87
+ type _InferEndpointOrigin<
88
+ RealEP extends unknown, Endpoints extends string | number | symbol
89
+ > = {
90
+ [EP in Endpoints]: RealEP extends ReplacePathParams<EP>
91
+ ? EP : never;
92
+ }[Endpoints];
93
+
72
94
  /**
73
95
  * Creates a function type for making requests to tagged endpoints.
74
96
  *
75
97
  * @template M - The HTTP method.
76
98
  * @template Tag - The tag associated with the endpoint.
77
99
  * @template ActualOpt - The actual options for the request.
78
- * @template EP - The endpoint path.
79
- * @template P2 - The path parameters.
100
+ * @template EndPoints - The possible endpoints.
101
+ * @template REP - The real endpoint path.
102
+ * @template EPX - The inferred endpoint origin.
103
+ * @template PPM - The path parameters.
80
104
  * @template Opt - The request options.
81
- * @template R - The response type.
105
+ * @template Ret - The response type.
106
+ * @template HasOpt - Indicates if the endpoint has required parameters.
82
107
  *
83
108
  * @param endpoint - The endpoint path.
84
- * @param pathParams - The path parameters.
85
109
  * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
86
110
  * @returns A promise that resolves to the response.
87
111
  *
@@ -89,16 +113,18 @@ export declare type InferMethod<Tag> = InferSomethingBy<Tag>
89
113
  * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
90
114
  * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
91
115
  */
92
- export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Tag extends ESITags, ActualOpt = {}> = <
93
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
94
- EP extends InferEndpointOrigin<RealEP, SelectEndpointByTag<Tag, M>> extends never ? RealEP: InferEndpointOrigin<RealEP, SelectEndpointByTag<Tag, M>>,
95
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
96
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
97
- R extends InferESIResponseResult<M, EP>,
98
- HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
99
- // RealEPX = ReplacePathParamsX<RealEPX>,
100
- // EPX = ReplacePathParams<EP>,
101
- >(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
116
+ export declare type TaggedEndpointRequestFunction2<
117
+ M extends TESIEntryMethod, Tag extends ESITags,
118
+ ActualOpt extends Record<string, unknown> = {},
119
+ EndPoints extends SelectEndpointByTag<Tag, M> = SelectEndpointByTag<Tag, M>,
120
+ > = <
121
+ REP extends ReplacePathParams<EndPoints> | EndPoints,
122
+ EPX extends _InferEndpointOrigin<REP, EndPoints> extends never ? REP: _InferEndpointOrigin<REP, EndPoints>,
123
+ PPM extends InferPathParams<REP, EPX>,
124
+ Opt extends IdentifyParameters<M, EPX, ActualOpt & PPM>,
125
+ Ret extends InferESIResponseResult<M, EPX>,
126
+ HasOpt = HasRequireParams<M, EPX, PPM>,
127
+ >(endpoint: REP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<Ret>;
102
128
 
103
129
 
104
130
  // - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -108,9 +134,10 @@ export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Ta
108
134
  * Maps tags to their corresponding endpoint request functions.
109
135
  *
110
136
  * @template Tag - The tag to map.
137
+ * @template ActualOpt - The actual options for the request.
111
138
  * @date 2025/2/28
112
139
  */
113
- export declare type ESITaggedEndpointRequest2<Tag extends ESITags, ActualOpt = {}> = {
140
+ export declare type ESITaggedEndpointRequest2<Tag extends ESITags, ActualOpt extends Record<string, unknown> = {}> = {
114
141
  [tag in Tag]: {
115
142
  [method in InferMethod<Tag>]: TaggedEndpointRequestFunction2<method, tag, ActualOpt>;
116
143
  };
@@ -135,14 +162,19 @@ export declare type SelectEndpointByTag<
135
162
  ? EP : never
136
163
  : never;
137
164
  }[keyof TESIResponseOKMap[M]];
138
- // type XAssetsEndpointGet = SelectEndpointByTag<"Assets", "get">;
139
- // type XAssetsEndpointPost = SelectEndpointByTag<"Assets", "post">;
165
+ /* ctt
166
+ type XAssetsEndpointGet = SelectEndpointByTag<"Assets", "get">;
167
+ type XAssetsEndpointPost = SelectEndpointByTag<"Assets", "post">;
168
+ /*/
169
+ //*/
140
170
 
141
171
  /**
142
172
  * Maps lower camel case tags to their corresponding endpoint request functions.
173
+ *
174
+ * @template ActualOpt - The actual options for the request.
143
175
  * @date 2025/3/12
144
176
  */
145
- export declare type TaggedESIRequestMap2<ActualOpt = {}> = {
177
+ export declare type TaggedESIRequestMap2<ActualOpt extends Record<string, unknown> = {}> = {
146
178
  [tag in ESITags as LCamelCase<tag>]: ESITaggedEndpointRequest2<tag, ActualOpt>;
147
179
  };
148
180
 
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.4 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.1.1 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
@@ -116,12 +195,12 @@ declare global {
116
195
  * This function sends a request to a specified endpoint and returns a response.
117
196
  *
118
197
  * @template ActualOpt - The actual type of the option.
119
- * @template M - The HTTP method to use for the request
120
- * @template RealEP - The real path of the ESI endpoint to send the request to
121
- * @template EP - The parameterized path of the ESI endpoint to send the request to
122
- * @template PathParams - Parameters to include in the request if the endpoint is parameterized
198
+ * @template Mtd - The HTTP method to use for the request
199
+ * @template REP - The real path of the ESI endpoint to send the request to
200
+ * @template EPX - The parameterized path of the ESI endpoint to send the request to
201
+ * @template PPM - Parameters to include in the request if the endpoint is parameterized
123
202
  * @template Opt - Options to include in the request. If there is a required parameter, its type will be merged with `ActualOpt`
124
- * @template R - The response type
203
+ * @template Ret - The response type
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.
@@ -134,31 +213,28 @@ declare global {
134
213
  * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
135
214
  */
136
215
  type TESIRequestFunctionSignature2<ActualOpt> = <
137
- M extends TESIEntryMethod,
138
- // "/characters/123/fittings/456/"
139
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
140
- // "/characters/{character_id}/fittings/{fitting_id}/"
141
- EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
142
- // If RealEP points to an endpoint origin (not a replaced endpoint), the path parameter is required
143
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
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
147
- >(method: M, endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
216
+ Mtd extends TESIEntryMethod,
217
+ REP extends ReplacePathParams<ESIEndpointOf<Mtd>> | ESIEndpointOf<Mtd>,
218
+ EPX extends ResolvedEndpoint<REP, Mtd>,
219
+ PPM extends InferPathParams<REP, EPX>,
220
+ Opt extends IdentifyParameters<Mtd, EPX, ActualOpt & PPM>,
221
+ Ret extends InferESIResponseResult<Mtd, EPX>,
222
+ HasOpt = HasRequireParams<Mtd, EPX, PPM>,
223
+ >(method: Mtd, endpoint: REP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<Ret>;
148
224
 
149
225
  /**
150
226
  * Represents a function that can make ESI requests for a specific HTTP method.
151
227
  *
152
228
  * This type is used to define functions that send requests to specific ESI endpoints using a given HTTP method.
153
229
  *
154
- * @template M - The HTTP method to use for the request.
230
+ * @template Mtd - The HTTP method to use for the request.
155
231
  * @template ActualOpt - The actual type of the options.
156
232
  *
157
- * @template RealEP - The real path of the ESI endpoint to send the request to.
158
- * @template EP - The parameterized path of the ESI endpoint to send the request to.
159
- * @template PathParams - Parameters to include in the request if the endpoint is parameterized.
233
+ * @template REP - The real path of the ESI endpoint to send the request to.
234
+ * @template EPX - The parameterized path of the ESI endpoint to send the request to.
235
+ * @template PPM - Parameters to include in the request if the endpoint is parameterized.
160
236
  * @template Opt - Options to include in the request. If there is a required parameter, its type will be merged with `ActualOpt`.
161
- * @template R - The response type.
237
+ * @template Ret - The response type.
162
238
  *
163
239
  * @param endpoint - The real path of the ESI endpoint to send the request to.
164
240
  * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
@@ -169,84 +245,141 @@ declare global {
169
245
  * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
170
246
  * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
171
247
  */
172
- type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
173
- RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
174
- EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
175
- PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
176
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
177
- R extends InferESIResponseResult<M, EP>,
178
- HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
179
- >(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
248
+ type TESIRequestFunctionEachMethod2<Mtd extends TESIEntryMethod, ActualOpt = {}> = <
249
+ REP extends ReplacePathParams<ESIEndpointOf<Mtd>> | ESIEndpointOf<Mtd>,
250
+ EPX extends ResolvedEndpoint<REP, Mtd>,
251
+ PPM extends InferPathParams<REP, EPX>,
252
+ Opt extends IdentifyParameters<Mtd, EPX, ActualOpt & PPM>,
253
+ Ret extends InferESIResponseResult<Mtd, EPX>,
254
+ HasOpt = HasRequireParams<Mtd, EPX, PPM>,
255
+ >(endpoint: REP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<Ret>;
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 string> = T extends `${infer Start}{${infer Param}}${infer End}`
268
+ type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
192
269
  ? `${Start}${number}${ReplacePathParams<End>}` : T;
193
-
194
- // // type Example = ReplacePathParamsX<"/characters/1234/fittings/{fitting_id}/">;
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 ReplacePathParamsX<T extends string> =
197
- // T extends `/${infer Start}/${infer Param}/${infer End}` ? `${Start}/${number}/${ReplacePathParams<End>}`
198
- // : T;
274
+ // type Example3 = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
275
+
199
276
  /**
200
- * Determines if the endpoint requires path parameters.
277
+ * Infers the path parameters based on the real endpoint and the resolved endpoint.
201
278
  *
202
- * @template EP - The string representing the endpoint path.
203
- * @returns {TPathParamsNever | { pathParams: IfParameterizedPath<EP> }}
204
- * Returns an object with `pathParams` if the endpoint requires parameters, otherwise returns `TPathParamsNever`.
205
- * @example
206
- * ```ts
207
- * type Example = IfNeedPathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
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 IfNeedPathParams<EP> = IfParameterizedPath<EP> extends never ? TPathParamsNever :
212
- 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
+
213
290
  /**
214
- * 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.
215
295
  *
216
296
  * @template RealEP - The real endpoint path.
217
- * @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
+ *
218
300
  * @example
219
301
  * ```ts
220
- * type EPOrigin = InferEndpointOrigin<"/characters/123/fittings/456/", TEndPointDelete>;
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<RealEP extends unknown, Endpoints> = {
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
- // type InferEndpointOrigin<RealEP extends string> = {
229
- // [Method in TESIEntryMethod]: {
230
- // [EP in keyof TESIResponseOKMap[Method]]: RealEP extends ReplacePathParams<EP>
231
- // ? EP : never;
232
- // }[keyof TESIResponseOKMap[Method]]
233
- // }[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>;
234
333
 
235
334
  /**
236
- * 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.
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 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.
242
369
  *
243
370
  * @example
244
371
  * ```ts
245
372
  * type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
246
- * type HasRequired = HasRequireParams<ExampleEntry>; // "auth"
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<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;
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 Opt - The type of the parameters.
273
- * @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}
274
423
  */
275
424
  //* ctt
276
425
  type IdentifyParameters<
277
- Entry, Opt,
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
- > = 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> : {});
285
443
  //*/
286
444
 
287
445
  /**
288
- * 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.
289
450
  *
290
- * @template M - The HTTP method (e.g., "get", "post").
291
- * @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}
292
458
  */
293
459
  type InferESIResponseResult<
294
460
  M extends TESIEntryMethod,
295
- EP extends keyof TESIResponseOKMap[M]
296
- > = 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
+ */
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 = keyof TESIResponseOKMap["get"];
487
+ type TEndPointGet = ESIEndpointOf<"get">;
316
488
  /**
317
489
  * Represents the endpoints for the "post" method.
318
490
  */
319
- type TEndPointPost = keyof TESIResponseOKMap["post"];
491
+ type TEndPointPost = ESIEndpointOf<"post">;
320
492
  /**
321
493
  * Represents the endpoints for the "put" method.
322
494
  */
323
- type TEndPointPut = keyof TESIResponseOKMap["put"];
495
+ type TEndPointPut = ESIEndpointOf<"put">;
324
496
  /**
325
497
  * Represents the endpoints for the "delete" method.
326
498
  */
327
- type TEndPointDelete = keyof TESIResponseOKMap["delete"];
499
+ type TEndPointDelete = ESIEndpointOf<"delete">;
328
500
 
329
501
  /**
330
502
  * Represents the entry details for the "get" method.