eve-esi-types 3.1.6 → 3.1.7

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.
@@ -1,57 +0,0 @@
1
- # Explanation of the `RequireThese` Type
2
-
3
- The `RequireThese` type is a utility type that takes an existing type `T` and a subset of its keys `K`, and marks those keys as **required**. The rest of the properties in `T` remain unchanged. This is especially useful when you want to enforce that certain properties are provided while leaving other properties optional or in their original state.
4
-
5
- ## Type Definition
6
-
7
- ```typescript
8
- type RequireThese<T, K extends keyof T> = {
9
- [P in keyof T as P extends K ? P : never]-?: T[P];
10
- } & {
11
- [P in keyof T as P extends K ? never : P]: T[P];
12
- };
13
- ```
14
-
15
- ## How It Works
16
-
17
- 1. **Selecting Required Keys**
18
- The first mapped type:
19
- ```typescript
20
- {
21
- [P in keyof T as P extends K ? P : never]-?: T[P];
22
- }
23
- ```
24
- - Iterates over each property key `P` in `T`.
25
- - Uses a conditional type `P extends K ? P : never` to filter in only the keys that are specified in `K`.
26
- - The `-?` operator removes the optional modifier, ensuring that these properties are marked as required.
27
-
28
- 2. **Preserving Other Keys**
29
- The second mapped type:
30
- ```typescript
31
- {
32
- [P in keyof T as P extends K ? never : P]: T[P];
33
- }
34
- ```
35
- - Iterates over each property key `P` in `T`.
36
- - Uses a conditional type to exclude the keys in `K` (by returning `never` for them), effectively preserving only the properties not in `K` in their original form.
37
-
38
- 3. **Combining the Results**
39
- The intersection (`&`) of the two mapped types results in a new type that:
40
- - Contains all keys in `K` as required.
41
- - Contains all keys not in `K` with their original modifiers (optional or required).
42
-
43
- ## Practical Example
44
-
45
- ```typescript
46
- type Original = { a?: number; b?: string; c: boolean };
47
- type RequiredA = RequireThese<Original, 'a'>;
48
- // Evaluates to: { a: number; b?: string; c: boolean }
49
- ```
50
-
51
- In this example:
52
- - The property `a` is transformed from an optional property to a required property.
53
- - The properties `b` and `c` retain their original statuses, with `b` remaining optional and `c` remaining required.
54
-
55
- ---
56
-
57
- `RequireThese` provides a concise way to enforce the presence of selected properties within a type, making it an effective tool for enhancing type safety in TypeScript.
@@ -1,67 +0,0 @@
1
- # Explanation of the `TESIEnhancedRequestFunctionSignature` Type
2
-
3
- `TESIEnhancedRequestFunctionSignature` is a highly generic function signature type for performing enhanced ESI requests.
4
- It extends a base request function signature by injecting a prepended parameter at the beginning of the function call,
5
- thereby providing extra context or enabling pre-processing prior to executing the request.
6
-
7
- This signature adapts to the specifics of the chosen HTTP method, endpoint configuration, inferred path parameters,
8
- and additional request options—making it ideal for advanced API interactions where both flexibility and strict type-safety are required.
9
-
10
- ## Generic Parameters
11
-
12
- - **`PrependParam`**: The type of the additional parameter that is injected at the beginning of the function call.
13
- - **`ActualOpt`**: An object representing the default options (typically extending `ESIRequestOptions`) used for the request.
14
-
15
- ## Function Generic Parameters
16
-
17
- - **`Mtd`**: The ESI request method type (e.g., GET, POST, DELETE) as defined in `TESIEntryMethod`.
18
- - **`REP`**: The endpoint type, which can be either a version with replaced path parameters (via `ReplacePathParams`) or the raw endpoint type from `ESIEndpointOf<Mtd>`.
19
- - **`EPX`**: The resolved endpoint type, derived from `REP` and `Mtd`.
20
- - **`PPM`**: The type representing the inferred path parameters extracted from `REP` and `EPX`.
21
- - **`Opt`**: The type for additional request options, as deduced from the HTTP method (`Mtd`), endpoint (`EPX`), the default options (`ActualOpt`), and the inferred path parameters (`PPM`).
22
- - **`Ret`**: The type of the response result from the ESI request, as inferred from the method and the endpoint.
23
- - **`HasOpt`**: An internal flag, computed via `HasRequireParams<Mtd, EPX, PPM>`, used to determine whether the request options (`Opt`) are required (evaluating to `1`) or optional (evaluating to `0`).
24
-
25
- ## Parameters
26
-
27
- - **`prependParam: PrependParam`**
28
- A prepended parameter that supplies additional context or configuration necessary for the request.
29
-
30
- - **`method: Mtd`**
31
- The HTTP method for the request.
32
-
33
- - **`endpoint: REP`**
34
- The API endpoint, which may include path parameter replacements (as provided by `ReplacePathParams`).
35
-
36
- - **`...options: HasOpt extends 1 ? [Opt] : [Opt?]`**
37
- A rest parameter representing additional options for the request. This is required if `HasOpt` is `1` (indicating that some options are mandatory), otherwise it is optional.
38
-
39
- ## Return Value
40
-
41
- - Returns a `Promise<Ret>` that resolves with the response from the ESI endpoint, where `Ret` reflects the inferred result type.
42
-
43
- ## Type Definition
44
-
45
- ```typescript
46
- type TESIEnhancedRequestFunctionSignature<
47
- PrependParam extends unknown, ActualOpt extends Record<string, unknown>
48
- > = <
49
- Mtd extends TESIEntryMethod,
50
- REP extends ReplacePathParams<ESIEndpointOf<Mtd>> | ESIEndpointOf<Mtd>,
51
- EPX extends ResolvedEndpoint<REP, Mtd>,
52
- PPM extends InferPathParams<REP, EPX>,
53
- Opt extends IdentifyParameters<Mtd, EPX, ActualOpt, PPM>,
54
- Ret extends InferESIResponseResult<Mtd, EPX>,
55
- HasOpt = HasRequireParams<Mtd, EPX, PPM>
56
- >(
57
- prependParam: PrependParam,
58
- method: Mtd,
59
- endpoint: REP,
60
- ...options: HasOpt extends 1 ? [Opt] : [Opt?]
61
- ) => Promise<Ret>;
62
- ```
63
-
64
- ---
65
-
66
- `TESIEnhancedRequestFunctionSignature` combines dynamic type inference with advanced parameter and return type handling to support complex API interactions in a type-safe manner.
67
- It ensures that extra configuration is accounted for at the start of the function call, aligning the signature with the specific needs of the API endpoint and HTTP method being used.
@@ -1,319 +0,0 @@
1
- <!--!
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
- Copyright (C) 2025 jeffy-g <hirotom1107@gmail.com>
4
- Released under the MIT license
5
- https://opensource.org/licenses/mit-license.php
6
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
- -->
8
-
9
- # ESI Types Utility 3.1 Summary
10
-
11
- This document provides detailed explanations of each type defined in the `eve-esi-types/v2/index.d.ts` file.
12
-
13
- > ## TESIRequestFunctionSignature2
14
-
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.
16
-
17
- #### Type Parameters
18
-
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.
27
-
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.
70
-
71
-
72
-
73
- ## ReplacePathParams
74
-
75
- `ReplacePathParams` is a type that replaces path parameters in a string with numbers.
76
-
77
- ```typescript
78
- type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
79
- ? `${Start}${number}${ReplacePathParams<End>}` : T;
80
- ```
81
-
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.
94
-
95
- ```typescript
96
- type InferPathParams<
97
- RealEP extends unknown, EPx extends unknown
98
- > = RealEP extends EPx ? _IfNeedPathParams<EPx> : TPathParamsNever;
99
- ```
100
-
101
- ## InferEndpointOrigin
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.
104
-
105
- ```typescript
106
- type InferEndpointOrigin<
107
- RealEP extends unknown, M extends TESIEntryMethod,
108
- Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>
109
- > = {
110
- [EP in Endpoints]: RealEP extends ReplacePathParams<EP>
111
- ? EP : never;
112
- }[Endpoints];
113
- ```
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
-
189
- ## IfParameterizedPath
190
-
191
- `IfParameterizedPath` is a type that determines the required number of replacements if `EP` (endpoint) is a parameterized path.
192
-
193
- ```typescript
194
- type IfParameterizedPath<EP extends unknown, Opt = never> = EP extends `${string}/{${string}}${string}`
195
- ? PickPathParameters<EP> extends never
196
- ? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
197
- ? number : [number, number]
198
- : Opt;
199
- ```
200
-
201
- ## IdentifyParameters
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.
204
-
205
- ```typescript
206
- type IdentifyParameters<
207
- M extends TESIEntryMethod,
208
- EPx extends ESIEndpointOf<M> | string,
209
- Opt extends Record<string, unknown>,
210
- Entry = _ESIResponseType<M, EPx>,
211
- Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
212
- > = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
213
- ```
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
-
226
- ## InferESIResponseResult
227
-
228
- `InferESIResponseResult` is a type that infers the result type of an ESI response based on the method and endpoint.
229
-
230
- ```typescript
231
- type InferESIResponseResult<
232
- M extends TESIEntryMethod,
233
- EPx extends ESIEndpointOf<M> | string
234
- > = _ESIResponseType<M, EPx> extends { result: infer U } ? U : never;
235
- ```
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
-
246
- ## NoContentResponse
247
-
248
- `NoContentResponse` is a type that represents a response with no content (HTTP status 204).
249
-
250
- ```typescript
251
- type NoContentResponse = { /* status: 204 */ };
252
- ```
253
-
254
- ## TESIEntryMethod
255
-
256
- `TESIEntryMethod` is a type that represents the HTTP methods supported by ESI.
257
-
258
- ```typescript
259
- type TESIEntryMethod = keyof TESIResponseOKMap;
260
- ```
261
-
262
- <details>
263
- > Example
264
-
265
- ```typescript
266
- "get" | "post" | "put" | "delete"
267
- ```
268
- </details>
269
-
270
- ## ESIEndpointOf
271
-
272
- `ESIEndpointOf` is a type that represents the endpoints for the specified HTTP method.
273
-
274
- ```typescript
275
- type ESIEndpointOf<M extends TESIEntryMethod> = keyof TESIResponseOKMap[M];
276
- ```
277
-
278
- <details>
279
- > Example
280
-
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>
288
-
289
- ## TESIResponseGetEntry
290
-
291
- `TESIResponseGetEntry` is a type that represents the entry details for the "get" method.
292
-
293
- ```typescript
294
- type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
295
- ```
296
-
297
- ## TESIResponsePutEntry
298
-
299
- `TESIResponsePutEntry` is a type that represents the entry details for the "put" method.
300
-
301
- ```typescript
302
- type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
303
- ```
304
-
305
- ## TESIResponsePostEntry
306
-
307
- `TESIResponsePostEntry` is a type that represents the entry details for the "post" method.
308
-
309
- ```typescript
310
- type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][K];
311
- ```
312
-
313
- ## TESIResponseDeleteEntry
314
-
315
- `TESIResponseDeleteEntry` is a type that represents the entry details for the "delete" method.
316
-
317
- ```typescript
318
- type TESIResponseDeleteEntry<K extends TEndPointDelete> = TESIResponseOKMap["delete"][K];
319
- ```
@@ -1,50 +0,0 @@
1
- # Explanation of the `HasRequireParams` Type
2
-
3
- `HasRequireParams` is a conditional TypeScript utility type designed to determine whether an API entry has any required parameters, including additional options. It does so by leveraging the `PickRequireParams` type to extract the keys from an entry type that are considered required once common metadata keys (`"result"`, `"tag"`, and `"cachedSeconds"`) have been excluded. If there remain any keys after this exclusion, it means the entry has required parameters, and the type evaluates to `1`; otherwise, it evaluates to `0`.
4
-
5
- ## Type Definition
6
-
7
- ```typescript
8
- type HasRequireParams<
9
- M extends TESIEntryMethod,
10
- EPx extends ESIEndpointOf<M> | string,
11
- AdditionalParams,
12
- > = PickRequireParams<M, EPx, AdditionalParams> extends never ? 0 : 1;
13
- ```
14
-
15
- ## Template Parameters
16
-
17
- - **`M extends TESIEntryMethod`**
18
- Represents the HTTP method (like `"get"`, `"post"`, `"delete"`, etc.) for the request. This helps identify the correct set of endpoints and types associated with that method.
19
-
20
- - **`EPx extends ESIEndpointOf<M> | string`**
21
- Denotes the endpoint path. It can be a specific parameterized endpoint from a predefined set (based on the HTTP method) or a generic string.
22
-
23
- - **`AdditionalParams`**
24
- Contains any extra parameters that should be considered during the evaluation. These are merged with the entry type to form a complete set of properties before excluding the metadata keys.
25
-
26
- ## How It Works
27
-
28
- 1. **Extracting Required Parameters**
29
- The type starts by merging the entry type with `AdditionalParams` and then uses `PickRequireParams` to exclude common metadata keys (`"result"`, `"tag"`, and `"cachedSeconds"`). This extraction isolates the parameters that are truly required for the API call.
30
-
31
- 2. **Conditional Evaluation**
32
- - If the resulting type from `PickRequireParams` is `never` (meaning there are no keys left), then `HasRequireParams` evaluates to `0`.
33
- - Otherwise, if there exists at least one required parameter, it evaluates to `1`.
34
-
35
- ## Practical Example
36
-
37
- ```typescript
38
- type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
39
- type HasRequired = HasRequireParams<"get", "/example/endpoint", { auth: string }>;
40
- // Evaluates to: 1
41
- ```
42
-
43
- In this example:
44
- - The `ExampleEntry` type includes metadata keys as well as an essential key `auth`.
45
- - After merging with `AdditionalParams` (which also includes `{ auth: string }`) and excluding the metadata keys, `auth` remains.
46
- - Since there is a required parameter (`auth`), `HasRequireParams` evaluates to `1`.
47
-
48
- ---
49
-
50
- `HasRequireParams` provides a straightforward mechanism to check if any required parameters exist for a given API entry, assisting in enhancing type safety and clarity in API definitions.
@@ -1,57 +0,0 @@
1
- # Explanation of the `InferEndpointOrigin` Type
2
-
3
- `InferEndpointOrigin` is a utility TypeScript type that deduces the original parameterized endpoint from a real endpoint string and a specified HTTP method. It does so by mapping over all possible parameterized endpoints associated with the given HTTP method, and selecting the one whose transformed version (via `ReplacePathParams`) matches the real endpoint. This technique enables you to recover the canonical endpoint structure from a concrete URL.
4
-
5
- ## Type Definition
6
-
7
- ```typescript
8
- type InferEndpointOrigin<
9
- RealEP extends unknown, M extends TESIEntryMethod,
10
- Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>
11
- > = {
12
- [EP in Endpoints]: RealEP extends ReplacePathParams<EP>
13
- ? EP : never;
14
- }[Endpoints];
15
- ```
16
-
17
- ## Template Parameters
18
-
19
- - **`RealEP extends unknown`**
20
- The real endpoint path, e.g., `"/characters/123/fittings/456/"`, representing the concrete URL accessed in a request.
21
-
22
- - **`M extends TESIEntryMethod`**
23
- The HTTP method (such as `"get"`, `"post"`, `"delete"`, etc.) used to determine which endpoints are applicable.
24
-
25
- - **`Endpoints extends ESIEndpointOf<M> = ESIEndpointOf<M>`**
26
- The union of all possible parameterized endpoints for the given HTTP method. These endpoints generally include dynamic segments in their definition, like `"/characters/{character_id}/fittings/{fitting_id}/"`.
27
-
28
- ## How It Works
29
-
30
- 1. **Mapping Over Endpoints**
31
- The type creates a mapped type where it iterates over each possible endpoint (`EP`) in the `Endpoints` union:
32
- ```typescript
33
- RealEP extends ReplacePathParams<EP> ? EP : never;
34
- ```
35
- - **Condition:** It checks if the real endpoint `RealEP` is assignable to the version of `EP` produced by `ReplacePathParams` (i.e., with its dynamic segments replaced by `${number}`).
36
- - **Outcome:**
37
- - If the condition holds true, it retains `EP`—indicating that this is the matching original endpoint.
38
- - Otherwise, it assigns `never` for that endpoint.
39
-
40
- 2. **Indexing the Mapped Type**
41
- After processing all endpoints, the type uses an index lookup `[Endpoints]` to extract the union of all endpoints that passed the conditional check (i.e., where the condition did not yield `never`). In typical usage, this results in a single matching endpoint.
42
-
43
- ## Practical Example
44
-
45
- ```ts
46
- type Original = InferEndpointOrigin<"/characters/123/fittings/456/", "delete">;
47
- // Evaluates to: "/characters/{character_id}/fittings/{fitting_id}/"
48
- ```
49
-
50
- In this example:
51
- - The real endpoint `"/characters/123/fittings/456/"` is compared against each parameterized endpoint available for the `"delete"` method.
52
- - When the condition `RealEP extends ReplacePathParams<EP>` is satisfied, it indicates that the endpoint structure matches. Accordingly, the original parameterized endpoint (`EP`) is selected.
53
- - The final resulting type is the parameterized endpoint, `"/characters/{character_id}/fittings/{fitting_id}/"`.
54
-
55
- ---
56
-
57
- `InferEndpointOrigin` thus serves as a robust mechanism to align concrete URLs with their original endpoint definitions, ensuring accurate type-checking for API route definitions.
@@ -1,41 +0,0 @@
1
- # Explanation of the `InferPathParams` Type
2
-
3
- `InferPathParams` is a conditional utility TypeScript type that infers path parameters by comparing the real endpoint path (`RealEP`) with the resolved endpoint path (`EPx`). It determines the appropriate type for the path parameters based on whether the real endpoint extends the resolved endpoint.
4
-
5
- ## Type Definition
6
-
7
- ```typescript
8
- type InferPathParams<
9
- RealEP extends unknown, EPx extends unknown
10
- > = RealEP extends EPx ? _IfNeedPathParams<EPx> : TPathParamsNever;
11
- ```
12
-
13
- ## Template Parameters
14
-
15
- - **`RealEP extends unknown`**
16
- Represents the real endpoint path, which is the original route definition provided in your API.
17
-
18
- - **`EPx extends unknown`**
19
- Represents the resolved endpoint path, which may be a transformed or standardized version of the real endpoint.
20
-
21
- ## How It Works
22
-
23
- 1. **Conditional Check**
24
- The type first evaluates whether `RealEP` extends `EPx`:
25
- - If **true**, it indicates that the real endpoint is compatible with the resolved endpoint.
26
-
27
- 2. **Path Parameter Inference**
28
- - When the condition is met, the type returns `_IfNeedPathParams<EPx>`, a helper type that likely infers and extracts the necessary path parameters embedded within `EPx`.
29
- - Otherwise, it returns `TPathParamsNever`, a type signaling that no valid path parameters could be inferred or that they are not needed.
30
-
31
- ## Practical Example
32
-
33
- Consider a scenario where you have:
34
- - A real endpoint like `"/characters/{character_id}"`.
35
- - A resolved endpoint that might incorporate specific formatting or type annotations.
36
-
37
- Using `InferPathParams`, if the real endpoint correctly extends the resolved endpoint, `_IfNeedPathParams` will process `EPx` to extract dynamic segments (such as converting `{character_id}` to an interpolated type). If not, it falls back to `TPathParamsNever`.
38
-
39
- ---
40
-
41
- This type is instrumental in achieving type safety in API route definitions. By conditionally inferring path parameters, it ensures that only valid and necessary parameters are extracted, promoting robust type-checking and eliminating unnecessary types.
@@ -1,56 +0,0 @@
1
- # Explanation of the `PickRequireParams` Type
2
-
3
- `PickRequireParams` is an advanced TypeScript utility type designed to extract the required keys from an entry type after merging it with additional parameters. It achieves this by excluding specific keys—namely, `"result"`, `"tag"`, and `"cachedSeconds"`—which are considered metadata or non-essential for defining required parameters. This type proves extremely useful when determining which parameters are needed for a particular API operation.
4
-
5
- ## Type Definition
6
-
7
- ```typescript
8
- type PickRequireParams<
9
- M extends TESIEntryMethod,
10
- EPx extends ESIEndpointOf<M> | string,
11
- AdditionalParams,
12
- Entry = _ESIResponseType<M, EPx>
13
- > = Exclude<keyof (Entry & AdditionalParams), "result" | "tag" | "cachedSeconds">;
14
- ```
15
-
16
- ## Template Parameters
17
-
18
- - **`M extends TESIEntryMethod`**
19
- Denotes the HTTP method (such as `"get"`, `"post"`, etc.) used for the request. This helps narrow down the endpoint and response types applicable for the method.
20
-
21
- - **`EPx extends ESIEndpointOf<M> | string`**
22
- Represents the endpoint path. It can either be a specific parameterized endpoint from a predefined collection (for the given HTTP method) or a generic string.
23
-
24
- - **`AdditionalParams`**
25
- Contains any extra parameters that need to be considered. These are merged with the entry type to facilitate a comprehensive parameter extraction.
26
-
27
- - **`Entry = _ESIResponseType<M, EPx>`**
28
- By default, this infers the response type corresponding to the HTTP method and endpoint provided. The resulting type is combined with `AdditionalParams` to determine the full set of keys available before excluding the non-required ones.
29
-
30
- ## How It Works
31
-
32
- 1. **Merging Types**
33
- The type starts by merging `Entry` with `AdditionalParams` using an intersection (`Entry & AdditionalParams`). This combined type gathers all properties from both sources.
34
-
35
- 2. **Extracting Keys**
36
- Using `keyof` on the merged type yields a union of all property keys present in either `Entry` or `AdditionalParams`.
37
-
38
- 3. **Excluding Unwanted Keys**
39
- The `Exclude` utility then removes the keys `"result"`, `"tag"`, and `"cachedSeconds"` from the union. These keys are typically reserved for metadata or caching information and are not required as input parameters.
40
-
41
- ## Practical Example
42
-
43
- ```typescript
44
- type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
45
- type RequiredParams = PickRequireParams<"get", "/example/endpoint", { auth: string }, ExampleEntry>;
46
- // Result: "auth"
47
- ```
48
-
49
- In this example:
50
- - The `ExampleEntry` type contains metadata keys (`result`, `tag`, `cachedSeconds`) and an essential key `auth`.
51
- - After merging with `AdditionalParams` (which provides `{ auth: string }`), the `PickRequireParams` type excludes the metadata keys.
52
- - The final resulting type, `RequiredParams`, is `"auth"`, representing the required parameter.
53
-
54
- ---
55
-
56
- `PickRequireParams` provides a powerful approach to isolating the essential parameters needed for API operations, ensuring that extraneous metadata does not interfere with type-safety and clarity in your API definitions.