eve-esi-types 3.2.4 → 3.2.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/CHANGELOG.md +39 -0
- package/README.md +87 -63
- package/{v2 → dist/v2}/esi-tagged-types.d.ts +77 -44
- package/{v2 → dist/v2}/experimental-esi-types.d.ts +139 -29
- package/dist/v2/index.d.ts +621 -0
- package/{v2 → dist/v2}/response-map.d.ts +1 -1
- package/{v2 → dist/v2}/types-index.d.ts +1 -1
- package/dist/v2/types-util.d.ts +281 -0
- package/dist/v2/util.d.ts +149 -0
- package/lib/console-util.mjs +1 -1
- package/lib/request-api.d.mts +4 -4
- package/lib/request-api.mjs +15 -16
- package/lib/rq-util.d.mts +76 -15
- package/lib/rq-util.mjs +122 -48
- package/lib/tagged-request-api.d.mts +2 -2
- package/lib/tagged-request-api.mjs +2 -2
- package/minimal-rq.mjs +5 -5
- package/package.json +5 -5
- package/request-v3.d.mts +1 -8
- package/request-v3.mjs +16 -19
- package/tagged-rq.mjs +17 -6
- package/{jsconfig.json → tsconfig.json} +5 -5
- package/v2/index.d.ts +0 -515
- package/v2/types-util.d.ts +0 -171
- package/v2/util.d.ts +0 -72
- /package/{v2 → dist/v2}/globals/alliance.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/assets.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/calendar.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/character.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/clones.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/contacts.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/contracts.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/corporation.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/dogma.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/extra-types.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/factionwarfare.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/fittings.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/fleets.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/incursions.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/industry.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/insurance.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/killmails.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/location.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/loyalty.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/mail.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/market.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/planetaryinteraction.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/routes.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/search.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/skills.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/sovereignty.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/status.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/universe.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/wallet.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/wars.d.ts +0 -0
|
@@ -0,0 +1,281 @@
|
|
|
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
|
+
* THIS DTS IS AUTO GENERATED, DO NOT EDIT
|
|
10
|
+
*
|
|
11
|
+
* @file eve-esi-types/v2/types-util.d.ts
|
|
12
|
+
* @summary This file is auto-generated and defines version 3.2.7 of the EVE Online ESI response types.
|
|
13
|
+
*/
|
|
14
|
+
import type { TESIResponseOKMap } from "./response-map.d.ts";
|
|
15
|
+
import type { RestrictKeys, CombineIntersection } from "./index.d.ts";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Defines the keys used in ESI entries for request parameters.
|
|
20
|
+
* These keys represent the main categories of parameters that can be included in an ESI request.
|
|
21
|
+
*/
|
|
22
|
+
export type ESIEntryParamKeys = "auth" | "query" | "body" | "pathParams";
|
|
23
|
+
/**
|
|
24
|
+
* Defines the keys that are not directly involved in ESI request parameters.
|
|
25
|
+
* These keys represent metadata or additional information that is not part of the main request parameters.
|
|
26
|
+
*/
|
|
27
|
+
export type ESIEntryExtraKeys = "result" | "tag" | "cachedSeconds";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the parameters required for making an ESI request to a specific endpoint.
|
|
31
|
+
*
|
|
32
|
+
* This type combines the user-supplied options, path parameters, and the expected response type
|
|
33
|
+
* to produce a structured result that includes:
|
|
34
|
+
* - The actual response payload type (`result`).
|
|
35
|
+
* - The final options object (`finalOptions`) that should be passed to the request.
|
|
36
|
+
* - A flag (`optionIsRequire`) indicating whether the options object is mandatory.
|
|
37
|
+
*
|
|
38
|
+
* @template Mtd - The HTTP method (e.g., "get", "post") of the request.
|
|
39
|
+
* @template REP - The endpoint path, which can be parameterized or already resolved with numbers.
|
|
40
|
+
* @template EPO - The resolved endpoint type tied to `REP`.
|
|
41
|
+
* @template Opt - A record type representing user-supplied request options.
|
|
42
|
+
* @template PathParams - A record type representing path parameters for the endpoint.
|
|
43
|
+
* @template EntryWithParams - The merged type of the response payload and path parameters.
|
|
44
|
+
* @template RequireKeys - The keys from `EntryWithParams` that represent actual request parameters.
|
|
45
|
+
*
|
|
46
|
+
* @returns An object containing:
|
|
47
|
+
* - `result`: The actual response payload type.
|
|
48
|
+
* - `finalOptions`: The exact options object to pass in (e.g., pathParams, query, body, auth).
|
|
49
|
+
* - `optionIsRequire`: A flag (`1` or `0`) indicating whether the options object is required.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // Example endpoint: /characters/{character_id}/attributes/
|
|
54
|
+
* type ExampleOpt = { auth: true; token: "eyJhbGciOiJSUzI1NiIsI..." };
|
|
55
|
+
* type ResolvedParams = ResolveEndpointParameters<
|
|
56
|
+
* "get", `/characters/${123345}/attributes/`, "/characters/{character_id}/attributes/",
|
|
57
|
+
* ExampleOpt
|
|
58
|
+
* >;
|
|
59
|
+
* // Result:
|
|
60
|
+
* // { auth: true, token: "eyJhbGciOiJSUzI1NiIsI..." }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @see {@link CombineIntersection}
|
|
64
|
+
* @see {@link RestrictKeys}
|
|
65
|
+
* @see {@link _ESIResponseType}
|
|
66
|
+
*/
|
|
67
|
+
export type ResolveEndpointParameters<
|
|
68
|
+
Mtd extends TESIEntryMethod,
|
|
69
|
+
// REP is either a parameterized path or already number-filled:
|
|
70
|
+
REP extends ReplacePathParams<ESIEndpointOf<Mtd>> | ESIEndpointOf<Mtd>,
|
|
71
|
+
// <— tie it directly to REP via ResolvedEndpoint:
|
|
72
|
+
EPO extends ResolvedEndpoint<Mtd, REP>,
|
|
73
|
+
// user-supplied options:
|
|
74
|
+
Opt extends Record<string, unknown>,
|
|
75
|
+
|
|
76
|
+
// now that EPO is fixed, these defaults all line up:
|
|
77
|
+
PathParams extends InferPathParams<REP, EPO> = InferPathParams<REP, EPO>,
|
|
78
|
+
EntryWithParams = _ESIResponseType<Mtd, EPO> & PathParams,
|
|
79
|
+
RequireKeys extends keyof EntryWithParams = Exclude<keyof EntryWithParams, ESIEntryExtraKeys>,
|
|
80
|
+
FinalOpt = CombineIntersection<
|
|
81
|
+
RestrictKeys<Opt, RequireKeys> & Pick<EntryWithParams, RequireKeys>
|
|
82
|
+
>
|
|
83
|
+
> = {
|
|
84
|
+
// the actual `"result"` payload type
|
|
85
|
+
result: EntryWithParams extends { result: infer R } ? R : never;
|
|
86
|
+
// the exact options object you should pass in (pathParams/query/body/auth)
|
|
87
|
+
finalOptions: FinalOpt;
|
|
88
|
+
// 1 if you _must_ pass an options object, else 0
|
|
89
|
+
optionIsRequire: HasRequireParams<Mtd, EPO, PathParams>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Represents a function that can make ESI requests with various HTTP methods.
|
|
95
|
+
*
|
|
96
|
+
* @template ActualOpt The actual type of the options.
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* // @ ts-expect-error
|
|
100
|
+
* export const request: IESIRequestFunction2<ESIRequestOptions> = (method, endpoint, opt) => {
|
|
101
|
+
* // Implementation for "get" | "post" | "put" | "delete" request
|
|
102
|
+
* };
|
|
103
|
+
* // You can easily implement "get" | "post" | "put" | "delete" requests
|
|
104
|
+
* // with code like the following:
|
|
105
|
+
* (["get", "post", "put", "delete"] as (keyof typeof request)[]).forEach((method) => {
|
|
106
|
+
* request[method] = function (this: typeof request, endpoint, opt) {
|
|
107
|
+
* return this(method, endpoint, opt);
|
|
108
|
+
* } as TESIRequestFunctionEachMethod2<typeof method>;
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export interface IESIRequestFunction2<ActualOpt extends Record<string, unknown>>
|
|
113
|
+
extends TESIRequestFunctionSignature2<ActualOpt>, TESIRequestFunctionMethods2<ActualOpt> {
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Represents the methods available for making ESI requests.
|
|
118
|
+
*
|
|
119
|
+
* + This interface is used when you already have implementation code such as
|
|
120
|
+
* TESIRequestFunctionSignature2 and you want to implement additional shorthand methods.
|
|
121
|
+
*
|
|
122
|
+
* @template ActualOpt The actual type of the options.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* export const request: TESIRequestFunctionSignature2<ESIRequestOptions> = (method, endpoint, opt) => {
|
|
127
|
+
* // Implementation for "get" | "post" | "put" | "delete" request
|
|
128
|
+
* };
|
|
129
|
+
* // You can easily implement "get" | "post" | "put" | "delete" requests
|
|
130
|
+
* // with code like the following:
|
|
131
|
+
* const esiMethods = {} as TESIRequestFunctionMethods2<ESIRequestOptions>;
|
|
132
|
+
* (["get", "post", "put", "delete"] as (keyof TESIRequestFunctionMethods2)[]).forEach((method) => {
|
|
133
|
+
* esiMethods[method] = function (endpoint, opt) {
|
|
134
|
+
* return request(method, endpoint, opt);
|
|
135
|
+
* } as TESIRequestFunctionEachMethod2<typeof method>;
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export type TESIRequestFunctionMethods2<ActualOpt extends Record<string, unknown>> = {
|
|
140
|
+
[method in TESIEntryMethod]: TESIRequestFunctionEachMethod2<method, ActualOpt>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* List of "x-cached-seconds"
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* // const cacheSecGet: 3600 | 300 | 604800 | 120 | 5 | 600 | 86400 | 60 | 30 | 1200 | 1800 | 30758400
|
|
148
|
+
* const cacheSecGet: TESICachedSeconds<"get">;
|
|
149
|
+
* // const cache5sec: 5
|
|
150
|
+
* const cache5s: TESICachedSeconds<"put">;
|
|
151
|
+
* // const cache3600s: 3600
|
|
152
|
+
* const cache3600s: TESICachedSeconds<"post">;
|
|
153
|
+
* // "/characters/affiliation/"
|
|
154
|
+
* const cache3600sEndpoint: TESICachedSeconds<"post", 1>;
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare type TESICachedSeconds<
|
|
158
|
+
Method extends TESIEntryMethod, AsEndpoint = 0
|
|
159
|
+
> = {
|
|
160
|
+
[M in TESIEntryMethod]: {
|
|
161
|
+
[EP in ESIEndpointOf<M>]: TESIResponseOKMap[M][EP] extends { cachedSeconds: number }
|
|
162
|
+
? AsEndpoint extends 0
|
|
163
|
+
? TESIResponseOKMap[M][EP]["cachedSeconds"]: EP
|
|
164
|
+
: never
|
|
165
|
+
}[ESIEndpointOf<M>];
|
|
166
|
+
}[Method];
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Indicates that no path parameters are allowed.
|
|
170
|
+
*
|
|
171
|
+
* This type serves as a compile-time signal for endpoints that do not support dynamic URL segments.
|
|
172
|
+
* By using this type, it is clear that no path parameters should be provided.
|
|
173
|
+
*/
|
|
174
|
+
export declare type TPathParamsNever = { /* pathParams?: never */ };
|
|
175
|
+
|
|
176
|
+
// local types
|
|
177
|
+
/**
|
|
178
|
+
* Infers the response type of an ESI request based on the HTTP method and endpoint.
|
|
179
|
+
*
|
|
180
|
+
* This type extracts the response type from the `TESIResponseOKMap` based on the provided
|
|
181
|
+
* HTTP method and endpoint.
|
|
182
|
+
*
|
|
183
|
+
* @template M The HTTP method to use for the request.
|
|
184
|
+
* @template EPx The endpoint path.
|
|
185
|
+
* include `string` in the `EPx` constraints to avoid breaking typescript inference.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* type ResponseType = _ESIResponseType<"get", "/characters/{character_id}/">;
|
|
190
|
+
* // Result: The inferred response type for the given method and endpoint.
|
|
191
|
+
* ```
|
|
192
|
+
* @internal
|
|
193
|
+
* @see {@link ESIEndpointOf}
|
|
194
|
+
*/
|
|
195
|
+
export type _ESIResponseType<
|
|
196
|
+
M extends TESIEntryMethod,
|
|
197
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
198
|
+
> = TESIResponseOKMap[M][Extract<EPx, ESIEndpointOf<M>>];
|
|
199
|
+
// type XOK = _ESIResponseType<"get", "/status/"> extends global._ESIResponseType<"get", "/status/"> ? 1 : 0;
|
|
200
|
+
/**
|
|
201
|
+
* Determines if the endpoint requires path parameters.
|
|
202
|
+
*
|
|
203
|
+
* @template EP The string representing the endpoint path.
|
|
204
|
+
* @returns {TPathParamsNever | { pathParams: IfParameterizedPath<EP> }}
|
|
205
|
+
* Returns an object with `pathParams` if the endpoint requires parameters, otherwise returns `TPathParamsNever`.
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* type Example = IfNeedPathParams<"/characters/{character_id}/fittings/{fitting_id}/">;
|
|
209
|
+
* // Result: { pathParams: [number, number] }
|
|
210
|
+
* ```
|
|
211
|
+
* @internal
|
|
212
|
+
* @see {@link IfParameterizedPath}
|
|
213
|
+
* @see {@link ReplacePathParams}
|
|
214
|
+
*/
|
|
215
|
+
//* ctt
|
|
216
|
+
export type _IfNeedPathParams<
|
|
217
|
+
EP extends PropertyKey,
|
|
218
|
+
Parameterized extends IfParameterizedPath<EP> = IfParameterizedPath<EP>
|
|
219
|
+
> = Parameterized extends 0
|
|
220
|
+
? TPathParamsNever :
|
|
221
|
+
EP extends ReplacePathParams<EP>
|
|
222
|
+
? TPathParamsNever : { pathParams: Parameterized };
|
|
223
|
+
/*/
|
|
224
|
+
export type _IfNeedPathParams<
|
|
225
|
+
EP extends PropertyKey,
|
|
226
|
+
Parameterized extends IfParameterizedPath<EP> = IfParameterizedPath<EP>
|
|
227
|
+
> = Parameterized extends 0
|
|
228
|
+
? TPathParamsNever : { pathParams: Parameterized };
|
|
229
|
+
//*/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Picks the required parameters from an entry type, including additional parameters.
|
|
233
|
+
*
|
|
234
|
+
* This type excludes the keys "result", "tag", and "cachedSeconds" from the entry type and the additional parameters,
|
|
235
|
+
* and returns the remaining keys as the required parameters.
|
|
236
|
+
*
|
|
237
|
+
* @template M The HTTP method to use for the request.
|
|
238
|
+
* @template EPx The endpoint path.
|
|
239
|
+
* @template AdditionalParams Additional parameters to include in the check.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
|
|
244
|
+
* type RequiredParams = PickRequireParams<"get", "/example/endpoint", { auth: string }, ExampleEntry>;
|
|
245
|
+
* // Result: "auth"
|
|
246
|
+
* ```
|
|
247
|
+
* @see {@link ESIEndpointOf}
|
|
248
|
+
* @see {@link _ESIResponseType}
|
|
249
|
+
* @deprecated 2025/4/28
|
|
250
|
+
* @see Documentation of [`PickRequireParams`](https://github.com/jeffy-g/eve-esi-types/blob/master/docs/v3/pick-require-params.md)
|
|
251
|
+
*/
|
|
252
|
+
export type __PickRequireParams<
|
|
253
|
+
M extends TESIEntryMethod,
|
|
254
|
+
EPx extends ESIEndpointOf<M> | string,
|
|
255
|
+
AdditionalParams,
|
|
256
|
+
> = Exclude<keyof (_ESIResponseType<M, EPx> & AdditionalParams), ESIEntryExtraKeys>;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Infer the result type of an ESI response based on the method and endpoint.
|
|
260
|
+
*
|
|
261
|
+
* @template M The HTTP method (e.g., "get", "post").
|
|
262
|
+
* @template EP The endpoint path.
|
|
263
|
+
* @deprecated 2025/3/17
|
|
264
|
+
*/
|
|
265
|
+
export type __InferESIResponseResult<
|
|
266
|
+
M extends TESIEntryMethod,
|
|
267
|
+
EP extends ESIEndpointOf<M>
|
|
268
|
+
> = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
|
|
269
|
+
/**
|
|
270
|
+
* Identifies the required parameters for a given entry type.
|
|
271
|
+
*
|
|
272
|
+
* @template Entry The entry type to identify parameters for.
|
|
273
|
+
* @template Opt The type of the parameters.
|
|
274
|
+
* @type {Opt & Pick<Entry, Exclude<keyof Entry, "result">>}
|
|
275
|
+
* @deprecated 2025/3/17
|
|
276
|
+
*/
|
|
277
|
+
export type __IdentifyParameters<
|
|
278
|
+
Entry, Opt,
|
|
279
|
+
Keys = Exclude<keyof Entry, ESIEntryExtraKeys>
|
|
280
|
+
// @ts-expect-error
|
|
281
|
+
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
* @file eve-esi-types/v2/util.d.ts
|
|
10
|
+
* @since 2.3.1
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* If `Path` is parameterized, return the parameter name, such as `killmail_id`.
|
|
15
|
+
*
|
|
16
|
+
* @template Path The string representing the endpoint path.
|
|
17
|
+
* @returns {string | never} The parameter name if the path is parameterized, otherwise `never`.
|
|
18
|
+
*/
|
|
19
|
+
//* ctt
|
|
20
|
+
export type PickPathParameters<Path extends PropertyKey> =
|
|
21
|
+
Path extends `${string}/{${infer Param}}/${infer Rest}`
|
|
22
|
+
? Param | PickPathParameters<`/${Rest}`>
|
|
23
|
+
: never;
|
|
24
|
+
/*/
|
|
25
|
+
export type PickPathParameters<Path extends string> =
|
|
26
|
+
Path extends `${string}/{${infer Param}}/${string}/{${infer Param2}}/${string}`
|
|
27
|
+
? Param | Param2 : Path extends `${string}/{${infer Param}}/${string}`
|
|
28
|
+
? Param
|
|
29
|
+
: never;
|
|
30
|
+
//*/
|
|
31
|
+
export type PathParamsToMap<EP extends PropertyKey> =
|
|
32
|
+
EP extends `${infer _Start}{${infer Param}}${infer Rest}`
|
|
33
|
+
? { [K in Param | keyof PathParamsToMap<Rest>]: string }
|
|
34
|
+
: {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Convert a union type to an intersection type.
|
|
38
|
+
*
|
|
39
|
+
* @template U The union type to convert.
|
|
40
|
+
* @returns {I} The intersection type.
|
|
41
|
+
*/
|
|
42
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
43
|
+
/**
|
|
44
|
+
* Convert a union type to a tuple.
|
|
45
|
+
*
|
|
46
|
+
* @template T The union type to convert.
|
|
47
|
+
* @returns {Array} The tuple representation of the union type.
|
|
48
|
+
*/
|
|
49
|
+
export type UnionToTuple<T> = UnionToIntersection<
|
|
50
|
+
T extends any ? () => T : never
|
|
51
|
+
> extends () => infer R ? [...UnionToTuple<Exclude<T, R>>, R] : [];
|
|
52
|
+
|
|
53
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
54
|
+
// Implemented: 2025/4/28
|
|
55
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
56
|
+
/**
|
|
57
|
+
* Extracts parameter keys from a parameterized path string as a tuple.
|
|
58
|
+
*
|
|
59
|
+
* This utility type takes a parameterized path string (e.g., `"/foo/{a}/bar/{b}/baz/"`)
|
|
60
|
+
* and extracts the parameter keys (e.g., `["a", "b"]`) as a tuple.
|
|
61
|
+
*
|
|
62
|
+
* @template Path - The parameterized path string.
|
|
63
|
+
* @returns {string[]} A tuple of parameter keys extracted from the path.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* type Params = ExtractPathParamKeys<"/foo/{a}/bar/{b}/baz/">;
|
|
68
|
+
* // Result: ["a", "b"]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export type ExtractPathParamKeys<
|
|
72
|
+
P extends PropertyKey
|
|
73
|
+
> = P extends `${infer _Before}{${infer Param}}${infer Rest}`
|
|
74
|
+
? [Param, ...ExtractPathParamKeys<Rest>]
|
|
75
|
+
: [];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extract parameter keys from either
|
|
79
|
+
* - a single parameterized path string, or
|
|
80
|
+
* - an array (or readonly array) of those strings,
|
|
81
|
+
* and return them as a union.
|
|
82
|
+
*
|
|
83
|
+
* @template Path
|
|
84
|
+
* Either a string template or an (readonly) array of string templates.
|
|
85
|
+
* @returns A union of all parameter names.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* type U1 = ExtractPathParamUnion<"/foo/{a}/bar/{b}/baz/">;
|
|
89
|
+
* // -> "a" | "b"
|
|
90
|
+
*
|
|
91
|
+
* type U2 = ExtractPathParamUnion<
|
|
92
|
+
* ["/foo/{a}/bar/{b}/baz/", "/users/{user_id}/posts/{post_id}"]
|
|
93
|
+
* >;
|
|
94
|
+
* // -> "a" | "b" | "user_id" | "post_id"
|
|
95
|
+
*/
|
|
96
|
+
export type ExtractPathParamUnion<Path extends string | readonly string[]> =
|
|
97
|
+
Path extends readonly any[]
|
|
98
|
+
? ExtractPathParamKeys<Path[number]>[number]
|
|
99
|
+
: Path extends string
|
|
100
|
+
? ExtractPathParamKeys<Path>[number] : never;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* #### Build an array of elements from a flattened tuple of type "1" | "2" | "3" ...
|
|
105
|
+
*
|
|
106
|
+
* NOTE: This utility cannot calculate lengths greater than 48 (?).
|
|
107
|
+
*
|
|
108
|
+
* + Returns the final length of the array.
|
|
109
|
+
*
|
|
110
|
+
* @template T The union type to be converted to a tuple and measured.
|
|
111
|
+
* @returns {number} The length of the tuple.
|
|
112
|
+
* @date 2025/2/11 18:12:02
|
|
113
|
+
*/
|
|
114
|
+
export type InferKeysLen<T> = UnionToTuple<T>["length"];
|
|
115
|
+
/**
|
|
116
|
+
* Splits a string by a delimiter and returns a tuple of the resulting substrings.
|
|
117
|
+
* @example
|
|
118
|
+
* Split<"get:/characters/{character_id}/wallet/", ":">
|
|
119
|
+
* // Result: ["get", "/characters/{character_id}/wallet/"]
|
|
120
|
+
*/
|
|
121
|
+
export type Split<S extends string, D extends string = ":"> =
|
|
122
|
+
S extends `${infer T}${D}${infer U}`
|
|
123
|
+
? [T, ...Split<U, D>]
|
|
124
|
+
: [S];
|
|
125
|
+
|
|
126
|
+
// // Test cases
|
|
127
|
+
// type Test1 = Split<"get:/characters/{character_id}/wallet/">;
|
|
128
|
+
// // Expected: ["get", "/characters/{character_id}/wallet/"]
|
|
129
|
+
// type Test2 = Split<"a.b.c", ".">;
|
|
130
|
+
// // Expected: ['a', 'b', 'c']
|
|
131
|
+
// type Test3 = Split<"hello", ",">;
|
|
132
|
+
// // Expected: ['hello']
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Combines an intersection of object types into a single object type.
|
|
136
|
+
*
|
|
137
|
+
* @template IS The intersection of object types to combine.
|
|
138
|
+
* @returns {Record<string, unknown>} A single object type with all properties from the intersection.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* type Combined = CombineIntersection<{ a: string } & { b: number }>;
|
|
142
|
+
* // Result: { a: string; b: number }
|
|
143
|
+
*/
|
|
144
|
+
//* ctt
|
|
145
|
+
// export type CombineIntersection<IS> = IS extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
146
|
+
export type CombineIntersection<IS extends Record<string, unknown>> = { [K in keyof IS]: IS[K] };
|
|
147
|
+
/*/
|
|
148
|
+
export type CombineIntersection<IS> = IS;
|
|
149
|
+
//*/
|
package/lib/console-util.mjs
CHANGED
|
@@ -83,7 +83,7 @@ export function getLogger(banner, logSelector = ".log-frame") {
|
|
|
83
83
|
return console.log.bind(console, banner);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
/** @type {
|
|
86
|
+
/** @type {(...data: any[]) => void} */
|
|
87
87
|
const log = (...data) => {
|
|
88
88
|
let text = banner;
|
|
89
89
|
for (const d of data) {
|
package/lib/request-api.d.mts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
import * as util from "./rq-util.mjs";
|
|
9
|
-
import type { IESIRequestFunction2 } from "../v2";
|
|
9
|
+
import type { IESIRequestFunction2 } from "../dist/v2";
|
|
10
10
|
/**
|
|
11
|
-
* @typedef {import("../v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
12
|
-
* @typedef {import("../v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
11
|
+
* @typedef {import("../dist/v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
12
|
+
* @typedef {import("../dist/v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
13
13
|
*/
|
|
14
14
|
/** #### Sample of `TESIRequestFunctionSignature`
|
|
15
15
|
*
|
|
@@ -19,7 +19,7 @@ import type { IESIRequestFunction2 } from "../v2";
|
|
|
19
19
|
* @type {IESIRequestFunction2}
|
|
20
20
|
* @param method - The HTTP method to use for the request
|
|
21
21
|
* @param endpoint - The Path of the ESI endpoint to send the request to
|
|
22
|
-
* @param
|
|
22
|
+
* @param opt - An object of options to include in the request
|
|
23
23
|
* @returns A Promise object containing the response data
|
|
24
24
|
* @throws {util.ESIRequestError}
|
|
25
25
|
*/
|
package/lib/request-api.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="../v2"/>
|
|
8
|
+
/// <reference types="../dist/v2"/>
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -17,8 +17,8 @@ import * as util from "./rq-util.mjs";
|
|
|
17
17
|
const log = util.getUniversalLogger("[request-api]: ");
|
|
18
18
|
const DEBUG = util.isDebug();
|
|
19
19
|
/**
|
|
20
|
-
* @typedef {import("../v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
21
|
-
* @typedef {import("../v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
20
|
+
* @typedef {import("../dist/v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
21
|
+
* @typedef {import("../dist/v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
22
22
|
*/
|
|
23
23
|
// - - - - - - - - - - - - - - - - - - - -
|
|
24
24
|
// main functions
|
|
@@ -31,22 +31,20 @@ const DEBUG = util.isDebug();
|
|
|
31
31
|
* @type {IESIRequestFunction2}
|
|
32
32
|
* @param method - The HTTP method to use for the request
|
|
33
33
|
* @param endpoint - The Path of the ESI endpoint to send the request to
|
|
34
|
-
* @param
|
|
34
|
+
* @param opt - An object of options to include in the request
|
|
35
35
|
* @returns A Promise object containing the response data
|
|
36
36
|
* @throws {util.ESIRequestError}
|
|
37
37
|
*/
|
|
38
38
|
export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endpoint, opt) => {
|
|
39
|
+
// When only options are provided
|
|
40
|
+
const nOpt = util.normalizeOptions([opt]);
|
|
39
41
|
/** @type {number[]=} */
|
|
40
42
|
let pathParams;
|
|
41
|
-
if (typeof
|
|
42
|
-
pathParams =
|
|
43
|
-
}
|
|
44
|
-
if (Array.isArray(pathParams)) {
|
|
45
|
-
endpoint = util.replaceCbt(endpoint, pathParams);
|
|
43
|
+
if (typeof nOpt.pathParams === "number" || Array.isArray(nOpt.pathParams)) {
|
|
44
|
+
pathParams = (Array.isArray(nOpt.pathParams) ? nOpt.pathParams : [nOpt.pathParams]);
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const { rqopt, qss } = util.initOptions(method, actualOpt);
|
|
46
|
+
Array.isArray(pathParams) && (endpoint = util.replaceCbt(endpoint, pathParams));
|
|
47
|
+
const { rqopt, qss } = util.initOptions(method, nOpt);
|
|
50
48
|
const endpointUrl = util.curl(endpoint);
|
|
51
49
|
const up = new URLSearchParams(qss);
|
|
52
50
|
const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
|
|
@@ -59,7 +57,7 @@ export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endp
|
|
|
59
57
|
}
|
|
60
58
|
// else if (isError(status)) {}
|
|
61
59
|
// Actually, throw Error
|
|
62
|
-
throw await util.handleESIError(res, endpointUrl,
|
|
60
|
+
throw await util.handleESIError(res, endpointUrl, nOpt.cancelable);
|
|
63
61
|
}
|
|
64
62
|
catch (e) {
|
|
65
63
|
log(e);
|
|
@@ -69,8 +67,9 @@ export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endp
|
|
|
69
67
|
// implements rest methods of `request` (IESIRequestFunction2)
|
|
70
68
|
//
|
|
71
69
|
/** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
|
|
72
|
-
request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
|
|
73
|
-
// @ts-expect-
|
|
74
|
-
return request2(method, endpoint,
|
|
70
|
+
request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, ...opt) => {
|
|
71
|
+
// @ts-expect-error TODO: ts(2345)
|
|
72
|
+
return request2(method, endpoint, ...opt);
|
|
73
|
+
// return request2(method, endpoint, /** @type {Parameters<typeof request2>[2]} */(opt) as Parameters<typeof request2>[2]);
|
|
75
74
|
});
|
|
76
75
|
});
|