eve-esi-types 3.1.6 → 3.2.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/CHANGELOG.md +182 -0
- package/jsconfig.json +28 -0
- package/lib/rq-util.mjs +1 -1
- package/lib/tagged-request-api.mjs +5 -6
- package/package.json +14 -8
- package/v2/esi-tagged-types.d.ts +9 -5
- package/v2/{get_alliances_alliance_id_ok.d.ts → globals/alliance.d.ts} +44 -0
- package/v2/globals/assets.d.ts +443 -0
- package/v2/globals/calendar.d.ts +130 -0
- package/v2/globals/character.d.ts +1084 -0
- package/v2/{get_characters_character_id_clones_ok.d.ts → globals/clones.d.ts} +15 -0
- package/v2/globals/contacts.d.ts +212 -0
- package/v2/globals/contracts.d.ts +546 -0
- package/v2/globals/corporation.d.ts +2329 -0
- package/v2/globals/dogma.d.ts +262 -0
- package/v2/globals/factionwarfare.d.ts +668 -0
- package/v2/{get_characters_character_id_fittings_ok.d.ts → globals/fittings.d.ts} +23 -0
- package/v2/globals/fleets.d.ts +201 -0
- package/v2/{get_incursions_ok.d.ts → globals/incursions.d.ts} +5 -0
- package/v2/globals/industry.d.ts +445 -0
- package/v2/globals/insurance.d.ts +47 -0
- package/v2/{get_killmails_killmail_id_killmail_hash_ok.d.ts → globals/killmails.d.ts} +55 -0
- package/v2/globals/location.d.ts +74 -0
- package/v2/{get_loyalty_stores_corporation_id_offers_ok.d.ts → globals/loyalty.d.ts} +30 -0
- package/v2/globals/mail.d.ts +237 -0
- package/v2/globals/market.d.ts +615 -0
- package/v2/globals/planetaryinteraction.d.ts +344 -0
- package/v2/globals/routes.d.ts +14 -0
- package/v2/{get_characters_character_id_search_ok.d.ts → globals/search.d.ts} +5 -0
- package/v2/globals/skills.d.ts +144 -0
- package/v2/globals/sovereignty.d.ts +168 -0
- package/v2/{get_status_ok.d.ts → globals/status.d.ts} +5 -0
- package/v2/globals/universe.d.ts +1297 -0
- package/v2/globals/wallet.d.ts +601 -0
- package/v2/{get_wars_war_id_ok.d.ts → globals/wars.d.ts} +40 -0
- package/v2/index.d.ts +38 -163
- package/v2/response-map.d.ts +22 -45
- package/v2/types-index.d.ts +31 -182
- package/v2/types-util.d.ts +335 -0
- package/v2/util.d.ts +4 -2
- package/web/index.html +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
- package/tsconfig.json +0 -28
- package/v2/get_alliances_alliance_id_contacts_labels_ok.d.ts +0 -24
- package/v2/get_alliances_alliance_id_contacts_ok.d.ts +0 -35
- package/v2/get_alliances_alliance_id_corporations_ok.d.ts +0 -9
- package/v2/get_alliances_alliance_id_icons_ok.d.ts +0 -18
- package/v2/get_alliances_ok.d.ts +0 -9
- package/v2/get_characters_character_id_agents_research_ok.d.ts +0 -33
- package/v2/get_characters_character_id_assets_ok.d.ts +0 -134
- package/v2/get_characters_character_id_attributes_ok.d.ts +0 -42
- package/v2/get_characters_character_id_blueprints_ok.d.ts +0 -122
- package/v2/get_characters_character_id_calendar_event_id_attendees_ok.d.ts +0 -30
- package/v2/get_characters_character_id_calendar_event_id_ok.d.ts +0 -56
- package/v2/get_characters_character_id_calendar_ok.d.ts +0 -37
- package/v2/get_characters_character_id_contacts_labels_ok.d.ts +0 -24
- package/v2/get_characters_character_id_contacts_ok.d.ts +0 -43
- package/v2/get_characters_character_id_contracts_contract_id_bids_ok.d.ts +0 -32
- package/v2/get_characters_character_id_contracts_contract_id_items_ok.d.ts +0 -38
- package/v2/get_characters_character_id_contracts_ok.d.ts +0 -117
- package/v2/get_characters_character_id_corporationhistory_ok.d.ts +0 -32
- package/v2/get_characters_character_id_fatigue_ok.d.ts +0 -22
- package/v2/get_characters_character_id_fleet_ok.d.ts +0 -31
- package/v2/get_characters_character_id_fw_stats_ok.d.ts +0 -64
- package/v2/get_characters_character_id_implants_ok.d.ts +0 -9
- package/v2/get_characters_character_id_industry_jobs_ok.d.ts +0 -105
- package/v2/get_characters_character_id_killmails_recent_ok.d.ts +0 -24
- package/v2/get_characters_character_id_location_ok.d.ts +0 -22
- package/v2/get_characters_character_id_loyalty_points_ok.d.ts +0 -24
- package/v2/get_characters_character_id_mail_labels_ok.d.ts +0 -62
- package/v2/get_characters_character_id_mail_lists_ok.d.ts +0 -24
- package/v2/get_characters_character_id_mail_mail_id_ok.d.ts +0 -59
- package/v2/get_characters_character_id_mail_ok.d.ts +0 -65
- package/v2/get_characters_character_id_medals_ok.d.ts +0 -135
- package/v2/get_characters_character_id_mining_ok.d.ts +0 -29
- package/v2/get_characters_character_id_notifications_contacts_ok.d.ts +0 -36
- package/v2/get_characters_character_id_notifications_ok.d.ts +0 -291
- package/v2/get_characters_character_id_ok.d.ts +0 -55
- package/v2/get_characters_character_id_online_ok.d.ts +0 -26
- package/v2/get_characters_character_id_opportunities_ok.d.ts +0 -24
- package/v2/get_characters_character_id_orders_history_ok.d.ts +0 -87
- package/v2/get_characters_character_id_orders_ok.d.ts +0 -82
- package/v2/get_characters_character_id_planets_ok.d.ts +0 -124
- package/v2/get_characters_character_id_planets_planet_id_ok.d.ts +0 -283
- package/v2/get_characters_character_id_portrait_ok.d.ts +0 -26
- package/v2/get_characters_character_id_roles_ok.d.ts +0 -270
- package/v2/get_characters_character_id_ship_ok.d.ts +0 -19
- package/v2/get_characters_character_id_skillqueue_ok.d.ts +0 -48
- package/v2/get_characters_character_id_skills_ok.d.ts +0 -47
- package/v2/get_characters_character_id_standings_ok.d.ts +0 -29
- package/v2/get_characters_character_id_titles_ok.d.ts +0 -184
- package/v2/get_characters_character_id_wallet_journal_ok.d.ts +0 -228
- package/v2/get_characters_character_id_wallet_ok.d.ts +0 -7
- package/v2/get_characters_character_id_wallet_transactions_ok.d.ts +0 -53
- package/v2/get_contracts_public_bids_contract_id_ok.d.ts +0 -28
- package/v2/get_contracts_public_items_contract_id_ok.d.ts +0 -49
- package/v2/get_contracts_public_region_id_ok.d.ts +0 -81
- package/v2/get_corporation_corporation_id_mining_extractions_ok.d.ts +0 -39
- package/v2/get_corporation_corporation_id_mining_observers_observer_id_ok.d.ts +0 -36
- package/v2/get_corporation_corporation_id_mining_observers_ok.d.ts +0 -30
- package/v2/get_corporations_corporation_id_alliancehistory_ok.d.ts +0 -32
- package/v2/get_corporations_corporation_id_assets_ok.d.ts +0 -170
- package/v2/get_corporations_corporation_id_blueprints_ok.d.ts +0 -163
- package/v2/get_corporations_corporation_id_contacts_labels_ok.d.ts +0 -24
- package/v2/get_corporations_corporation_id_contacts_ok.d.ts +0 -39
- package/v2/get_corporations_corporation_id_containers_logs_ok.d.ts +0 -188
- package/v2/get_corporations_corporation_id_contracts_contract_id_bids_ok.d.ts +0 -33
- package/v2/get_corporations_corporation_id_contracts_contract_id_items_ok.d.ts +0 -38
- package/v2/get_corporations_corporation_id_contracts_ok.d.ts +0 -117
- package/v2/get_corporations_corporation_id_customs_offices_ok.d.ts +0 -78
- package/v2/get_corporations_corporation_id_divisions_ok.d.ts +0 -128
- package/v2/get_corporations_corporation_id_facilities_ok.d.ts +0 -25
- package/v2/get_corporations_corporation_id_fw_stats_ok.d.ts +0 -60
- package/v2/get_corporations_corporation_id_icons_ok.d.ts +0 -22
- package/v2/get_corporations_corporation_id_industry_jobs_ok.d.ts +0 -105
- package/v2/get_corporations_corporation_id_killmails_recent_ok.d.ts +0 -24
- package/v2/get_corporations_corporation_id_medals_issued_ok.d.ts +0 -41
- package/v2/get_corporations_corporation_id_medals_ok.d.ts +0 -36
- package/v2/get_corporations_corporation_id_members_limit_ok.d.ts +0 -7
- package/v2/get_corporations_corporation_id_members_ok.d.ts +0 -9
- package/v2/get_corporations_corporation_id_members_titles_ok.d.ts +0 -194
- package/v2/get_corporations_corporation_id_membertracking_ok.d.ts +0 -41
- package/v2/get_corporations_corporation_id_ok.d.ts +0 -66
- package/v2/get_corporations_corporation_id_orders_history_ok.d.ts +0 -91
- package/v2/get_corporations_corporation_id_orders_ok.d.ts +0 -86
- package/v2/get_corporations_corporation_id_roles_history_ok.d.ts +0 -171
- package/v2/get_corporations_corporation_id_roles_ok.d.ts +0 -543
- package/v2/get_corporations_corporation_id_shareholders_ok.d.ts +0 -29
- package/v2/get_corporations_corporation_id_standings_ok.d.ts +0 -29
- package/v2/get_corporations_corporation_id_starbases_ok.d.ts +0 -51
- package/v2/get_corporations_corporation_id_starbases_starbase_id_ok.d.ts +0 -110
- package/v2/get_corporations_corporation_id_structures_ok.d.ts +0 -176
- package/v2/get_corporations_corporation_id_titles_ok.d.ts +0 -548
- package/v2/get_corporations_corporation_id_wallets_division_journal_ok.d.ts +0 -229
- package/v2/get_corporations_corporation_id_wallets_division_transactions_ok.d.ts +0 -50
- package/v2/get_corporations_corporation_id_wallets_ok.d.ts +0 -62
- package/v2/get_corporations_npccorps_ok.d.ts +0 -9
- package/v2/get_dogma_attributes_attribute_id_ok.d.ts +0 -50
- package/v2/get_dogma_attributes_ok.d.ts +0 -9
- package/v2/get_dogma_dynamic_items_type_id_item_id_ok.d.ts +0 -58
- package/v2/get_dogma_effects_effect_id_ok.d.ts +0 -127
- package/v2/get_dogma_effects_ok.d.ts +0 -9
- package/v2/get_fleets_fleet_id_members_ok.d.ts +0 -54
- package/v2/get_fleets_fleet_id_ok.d.ts +0 -26
- package/v2/get_fleets_fleet_id_wings_ok.d.ts +0 -45
- package/v2/get_fw_leaderboards_characters_ok.d.ts +0 -110
- package/v2/get_fw_leaderboards_corporations_ok.d.ts +0 -109
- package/v2/get_fw_leaderboards_ok.d.ts +0 -182
- package/v2/get_fw_stats_ok.d.ts +0 -66
- package/v2/get_fw_systems_ok.d.ts +0 -41
- package/v2/get_fw_wars_ok.d.ts +0 -24
- package/v2/get_industry_facilities_ok.d.ts +0 -37
- package/v2/get_industry_systems_ok.d.ts +0 -119
- package/v2/get_insurance_prices_ok.d.ts +0 -62
- package/v2/get_markets_groups_market_group_id_ok.d.ts +0 -27
- package/v2/get_markets_groups_ok.d.ts +0 -9
- package/v2/get_markets_prices_ok.d.ts +0 -25
- package/v2/get_markets_region_id_history_ok.d.ts +0 -40
- package/v2/get_markets_region_id_orders_ok.d.ts +0 -74
- package/v2/get_markets_region_id_types_ok.d.ts +0 -9
- package/v2/get_markets_structures_structure_id_ok.d.ts +0 -70
- package/v2/get_opportunities_groups_group_id_ok.d.ts +0 -38
- package/v2/get_opportunities_groups_ok.d.ts +0 -9
- package/v2/get_opportunities_tasks_ok.d.ts +0 -9
- package/v2/get_opportunities_tasks_task_id_ok.d.ts +0 -26
- package/v2/get_route_origin_destination_ok.d.ts +0 -9
- package/v2/get_sovereignty_campaigns_ok.d.ts +0 -83
- package/v2/get_sovereignty_map_ok.d.ts +0 -32
- package/v2/get_sovereignty_structures_ok.d.ts +0 -46
- package/v2/get_universe_ancestries_ok.d.ts +0 -40
- package/v2/get_universe_asteroid_belts_asteroid_belt_id_ok.d.ts +0 -37
- package/v2/get_universe_bloodlines_ok.d.ts +0 -57
- package/v2/get_universe_categories_category_id_ok.d.ts +0 -28
- package/v2/get_universe_categories_ok.d.ts +0 -9
- package/v2/get_universe_constellations_constellation_id_ok.d.ts +0 -47
- package/v2/get_universe_constellations_ok.d.ts +0 -9
- package/v2/get_universe_factions_ok.d.ts +0 -56
- package/v2/get_universe_graphics_graphic_id_ok.d.ts +0 -42
- package/v2/get_universe_graphics_ok.d.ts +0 -9
- package/v2/get_universe_groups_group_id_ok.d.ts +0 -27
- package/v2/get_universe_groups_ok.d.ts +0 -9
- package/v2/get_universe_moons_moon_id_ok.d.ts +0 -41
- package/v2/get_universe_planets_planet_id_ok.d.ts +0 -42
- package/v2/get_universe_races_ok.d.ts +0 -52
- package/v2/get_universe_regions_ok.d.ts +0 -9
- package/v2/get_universe_regions_region_id_ok.d.ts +0 -28
- package/v2/get_universe_schematics_schematic_id_ok.d.ts +0 -18
- package/v2/get_universe_stargates_stargate_id_ok.d.ts +0 -57
- package/v2/get_universe_stars_star_id_ok.d.ts +0 -129
- package/v2/get_universe_stations_station_id_ok.d.ts +0 -104
- package/v2/get_universe_structures_ok.d.ts +0 -9
- package/v2/get_universe_structures_structure_id_ok.d.ts +0 -43
- package/v2/get_universe_system_jumps_ok.d.ts +0 -24
- package/v2/get_universe_system_kills_ok.d.ts +0 -32
- package/v2/get_universe_systems_ok.d.ts +0 -9
- package/v2/get_universe_systems_system_id_ok.d.ts +0 -94
- package/v2/get_universe_types_ok.d.ts +0 -9
- package/v2/get_universe_types_type_id_ok.d.ts +0 -105
- package/v2/get_wars_ok.d.ts +0 -9
- package/v2/get_wars_war_id_killmails_ok.d.ts +0 -24
- package/v2/post_characters_affiliation_ok.d.ts +0 -32
- package/v2/post_characters_character_id_assets_locations_ok.d.ts +0 -39
- package/v2/post_characters_character_id_assets_names_ok.d.ts +0 -24
- package/v2/post_characters_character_id_contacts_created.d.ts +0 -9
- package/v2/post_characters_character_id_cspa_created.d.ts +0 -7
- package/v2/post_characters_character_id_fittings_created.d.ts +0 -14
- package/v2/post_characters_character_id_mail_created.d.ts +0 -7
- package/v2/post_characters_character_id_mail_labels_created.d.ts +0 -7
- package/v2/post_corporations_corporation_id_assets_locations_ok.d.ts +0 -39
- package/v2/post_corporations_corporation_id_assets_names_ok.d.ts +0 -24
- package/v2/post_fleets_fleet_id_wings_created.d.ts +0 -14
- package/v2/post_fleets_fleet_id_wings_wing_id_squads_created.d.ts +0 -14
- package/v2/post_universe_ids_ok.d.ts +0 -86
- package/v2/post_universe_names_ok.d.ts +0 -38
- /package/v2/{extra-types.d.ts → globals/extra-types.d.ts} +0 -0
|
@@ -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.
|
|
@@ -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.
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"skipDefaultLibCheck": true,
|
|
5
|
-
"skipLibCheck": true,
|
|
6
|
-
"declaration": true,
|
|
7
|
-
// "declarationDir": "./dts",
|
|
8
|
-
"outDir": ".",
|
|
9
|
-
"target": "esnext",
|
|
10
|
-
"module": "esnext",
|
|
11
|
-
"diagnostics": true,
|
|
12
|
-
"newLine": "LF",
|
|
13
|
-
"strict": true,
|
|
14
|
-
"moduleResolution": "node",
|
|
15
|
-
"rootDirs": [
|
|
16
|
-
"./scripts"
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"include": [
|
|
20
|
-
"./scripts/**/*.mts",
|
|
21
|
-
"./scripts/**/*.d.ts",
|
|
22
|
-
"./v2/*.d.ts"
|
|
23
|
-
],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"./scripts/auth-*",
|
|
26
|
-
"./scripts/esi-*",
|
|
27
|
-
]
|
|
28
|
-
}
|