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.
- package/package.json +1 -2
- package/v2/esi-tagged-types.d.ts +1 -1
- package/v2/index.d.ts +12 -12
- package/v2/response-map.d.ts +22 -22
- package/v2/types-index.d.ts +1 -1
- package/docs/esi-tagged-types.md +0 -120
- package/docs/v2/identify-parameters.md +0 -74
- package/docs/v2/if-parameterized-path.md +0 -70
- package/docs/v2/infer-esi-response-result.md +0 -44
- package/docs/v2/require-these.md +0 -57
- package/docs/v3/esi-enhanced-function-signature.md +0 -67
- package/docs/v3/esi-types-util3.md +0 -319
- package/docs/v3/has-require-params.md +0 -50
- package/docs/v3/infer-endpoint-origin.md +0 -57
- package/docs/v3/infer-path-params.md +0 -41
- package/docs/v3/pick-require-params.md +0 -56
- package/docs/v3/replace-path-params.md +0 -60
- package/docs/v3/resolved-endpoint.md +0 -44
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# Explanation of the `ReplacePathParams` Type
|
|
2
|
-
|
|
3
|
-
`ReplacePathParams` is a recursive TypeScript type designed to replace dynamic segments—specifically,
|
|
4
|
-
the path parameters enclosed in curly braces—in a string literal with a standardized template literal interpolation of `${number}`.
|
|
5
|
-
This is especially useful when defining API endpoints where parameters in the URL are expected to be numeric.
|
|
6
|
-
|
|
7
|
-
## Type Definition
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
type ReplacePathParams<T extends unknown> = T extends `${infer Start}{${infer Param}}${infer End}`
|
|
11
|
-
? `${Start}${number}${ReplacePathParams<End>}`
|
|
12
|
-
: T;
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### Parameters
|
|
16
|
-
|
|
17
|
-
+ T extends unknown Although T is declared with the type unknown, it is intended to be a string literal representing the endpoint path.
|
|
18
|
-
The type processes the string to find dynamic segments that need to be replaced.
|
|
19
|
-
|
|
20
|
-
### How It Works
|
|
21
|
-
|
|
22
|
-
1. Pattern Matching The type checks if the input string T matches the pattern:
|
|
23
|
-
|
|
24
|
-
`${infer Start}{${infer Param}}${infer End}`
|
|
25
|
-
|
|
26
|
-
+ `Start`: Captures the substring leading up to the first occurrence of a path parameter.
|
|
27
|
-
|
|
28
|
-
+ `{${infer Param}}`: Matches a section of the string enclosed in curly braces. The content inside the braces, which is the path parameter's name, is stored temporarily in Param.
|
|
29
|
-
|
|
30
|
-
+ `End`: Captures the remaining part of the string following the matched dynamic segment.
|
|
31
|
-
|
|
32
|
-
2. **Recursive Replacement** If the pattern is matched:
|
|
33
|
-
|
|
34
|
-
+ The matching segment `{${infer Param}}` is replaced with `${number}`.
|
|
35
|
-
|
|
36
|
-
+ The type then recursively applies itself to the remainder of the string (`End`) by calling `ReplacePathParams<End>`,
|
|
37
|
-
ensuring that all occurrences of path parameters are replaced.
|
|
38
|
-
|
|
39
|
-
3. Base Case If `T` does not contain any substring that fits the pattern (i.e., no occurrence of a dynamic segment in curly braces),
|
|
40
|
-
the type simply evaluates to `T` without modification. This serves as the termination condition for the recursion.
|
|
41
|
-
|
|
42
|
-
### Practical Example
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
type Example = ReplacePathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
46
|
-
// Evaluates to: "/characters/${number}/fittings/${number}/"
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
In this example:
|
|
50
|
-
|
|
51
|
-
1. The first dynamic segment `{character_id}` is replaced with `${number}`.
|
|
52
|
-
|
|
53
|
-
1. The type then recursively processes the remaining string, encountering and replacing {fitting_id} with `${number}`.
|
|
54
|
-
|
|
55
|
-
1. The final resulting type is `"/characters/${number}/fittings/${number}/"`.
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
The `ReplacePathParams` type is a powerful tool for transforming endpoint strings into a more standardized format.
|
|
60
|
-
This is especially beneficial when type-checking API route definitions or dynamically generating strongly-typed URL strings based on certain conditions.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Explanation of the `ResolvedEndpoint` Type
|
|
2
|
-
|
|
3
|
-
`ResolvedEndpoint` is a utility TypeScript type that determines the final, "resolved" endpoint based on a given real endpoint and the specific HTTP method. It leverages the `InferEndpointOrigin` type to deduce the original parameterized endpoint from the real endpoint. If no matching parameterized endpoint is found (i.e., the inference results in `never`), it defaults back to the real endpoint.
|
|
4
|
-
|
|
5
|
-
## Type Definition
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
type ResolvedEndpoint<
|
|
9
|
-
RealEP extends unknown, M extends TESIEntryMethod,
|
|
10
|
-
> = InferEndpointOrigin<RealEP, M> extends never ? RealEP : InferEndpointOrigin<RealEP, M>;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Template Parameters
|
|
14
|
-
|
|
15
|
-
- **`RealEP extends unknown`**
|
|
16
|
-
The real endpoint path, representing the actual URL used in a request (for example, `"/characters/123/fittings/456/"`).
|
|
17
|
-
|
|
18
|
-
- **`M extends TESIEntryMethod`**
|
|
19
|
-
The HTTP method (such as `"get"`, `"post"`, `"delete"`, etc.) used for the request. This is used to narrow down which set of parameterized endpoints should be considered.
|
|
20
|
-
|
|
21
|
-
## How It Works
|
|
22
|
-
|
|
23
|
-
1. **Endpoint Inference**
|
|
24
|
-
The type starts by invoking `InferEndpointOrigin<RealEP, M>`, which attempts to map the real endpoint to its original parameterized form (e.g., converting `"/characters/123/fittings/456/"` to `"/characters/{character_id}/fittings/{fitting_id}/"`).
|
|
25
|
-
|
|
26
|
-
2. **Conditional Resolution**
|
|
27
|
-
- If `InferEndpointOrigin<RealEP, M>` results in `never`, it means no matching parameterized endpoint could be inferred from the given real endpoint. In such cases, the type falls back and returns `RealEP` as is.
|
|
28
|
-
- If the inference is successful, the resolved parameterized endpoint is returned.
|
|
29
|
-
|
|
30
|
-
## Practical Example
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
type Resolved = ResolvedEndpoint<"/characters/123/fittings/456/", "delete">;
|
|
34
|
-
// Evaluates to: "/characters/{character_id}/fittings/{fitting_id}/"
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
In this example:
|
|
38
|
-
- The real endpoint `"/characters/123/fittings/456/"` along with the HTTP method `"delete"` is provided.
|
|
39
|
-
- `InferEndpointOrigin` successfully maps it to its original form (`"/characters/{character_id}/fittings/{fitting_id}/"`), so that becomes the resolved endpoint.
|
|
40
|
-
- If the mapping had failed (i.e., if no parameterized endpoint matched), the type would have defaulted to returning the original real endpoint.
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
`ResolvedEndpoint` thus ensures that you get a consistent and properly parameterized endpoint format, which is crucial for maintaining type safety and clarity in API route definitions.
|