eve-esi-types 2.3.5 → 3.0.1

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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # eve-esi-types
2
- Extracted the main type of ESI. Used for ESI request response types.
2
+ Extracted main types of ESI. Used for ESI request response types.
3
3
 
4
4
  ## Usage
5
5
 
@@ -8,12 +8,12 @@ Extracted the main type of ESI. Used for ESI request response types.
8
8
  + If you need to use version 1, please refer to the following link:
9
9
  [eve-esi-types v1](https://github.com/jeffy-g/eve-esi-types/tree/version-1.x)
10
10
 
11
-
12
11
  > Sample code is provided -> [`v2.mjs`](./v2.mjs)
13
12
 
14
13
  ```shell
15
14
  $ node v2.mjs
16
15
  ```
16
+
17
17
  ## API
18
18
 
19
19
  > The following function signature allows you to benefit from `eve-esi-types`.
@@ -22,31 +22,32 @@ $ node v2.mjs
22
22
  > and whether OAuth authentication is necessary (`auth: true`).
23
23
 
24
24
  ```ts
25
- // function signature
26
- export declare function fire<
27
- M extends TESIEntryMethod,
28
- EP extends keyof TESIResponseOKMap[M],
29
- P2 extends IfParameterizedPath<EP, Opt>,
30
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ESIRequestOptions>,
31
- R extends InferESIResponseResult<M, EP>
32
- >(mthd: M, endp: EP, pathParams?: P2, opt?: Opt): Promise<R>;
25
+ // This function signature has been removed in version 3.x
26
+ // export declare function fire<
27
+ // M extends TESIEntryMethod,
28
+ // EP extends keyof TESIResponseOKMap[M],
29
+ // P2 extends IfParameterizedPath<EP, Opt>,
30
+ // Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ESIRequestOptions>,
31
+ // R extends InferESIResponseResult<M, EP>
32
+ // >(mthd: M, endp: EP, pathParams?: P2, opt?: Opt): Promise<R>;
33
33
  ```
34
34
 
35
35
  ## New Features in v2.3.0
36
36
 
37
37
  ### ESI Tagged Types
38
38
 
39
- > Introduced intuitive ESI requests handling using "tags" from the EVE Swagger JSON.
39
+ > Introduced intuitive ESI request handling using "tags" from the EVE Swagger JSON.
40
40
 
41
- ### injectESIRequestBody
41
+ ### ~~injectESIRequestBody~~
42
42
 
43
- > Utilized `injectESIRequestBody` to generate ESI request API objects with narrowed endpoints by accessing camel-cased "tags".
43
+ > Utilized ~~`injectESIRequestBody`~~ to generate ESI request API objects with narrowed endpoints by accessing camel-cased "tags".
44
44
 
45
45
  ```ts
46
46
  import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
47
47
 
48
- const esiRequest = taggedApi.injectESIRequestBody(...);
49
- const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
48
+ // `injectESIRequestBody` has been removed in version 3.x
49
+ // const esiRequest = taggedApi.injectESIRequestBody(...);
50
+ // const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
50
51
  ```
51
52
 
52
53
  + or
@@ -58,6 +59,45 @@ import { esi } from "eve-esi-types/lib/tagged-request-api.mjs";
58
59
  const ret = await esi.universe.get("/universe/structures/", { query: { filter: "market" }});
59
60
  ```
60
61
 
62
+ ## New Features in v3.0.0
63
+
64
+ ### `TESIRequestFunctionSignature` has been renamed to `TESIRequestFunctionSignature2` and the generic parameters have been changed.
65
+
66
+ > `RealEP` and `EP` help maintain endpoint inference.
67
+ > With `RealEP`, TypeScript inference partially lists the possible endpoints while allowing for path parameter replacement.
68
+
69
+
70
+ ```ts
71
+ type TESIRequestFunctionSignature2<ActualOpt> = <
72
+ M extends TESIEntryMethod,
73
+ RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
74
+ EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP : InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
75
+ // If RealEP points to an endpoint origin (not a replaced endpoint), the path parameter is required
76
+ PathParams extends RealEP extends EP ? IfNeedPathParams<EP> : TPathParamsNever,
77
+ Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
78
+ R extends InferESIResponseResult<M, EP>
79
+ >(method: M, endpoint: RealEP, options?: Opt) => Promise<R>;
80
+ ```
81
+
82
+ + NOTE: Accordingly, the generic parameters for other request function signatures have also been changed, with "2" appended to their names.
83
+
84
+ + `IESIRequestFunction` -> `IESIRequestFunction2`
85
+ + `TESIRequestFunctionMethods` -> `TESIRequestFunctionMethods2`
86
+ + `TESIRequestFunctionEachMethod` -> `TESIRequestFunctionEachMethod2`
87
+ + etc. Also, `v2/esi-tagged-types.d.ts` too
88
+
89
+ ### decoreateESIRequestBody
90
+
91
+ > Utilized `decoreateESIRequestBody` to generate ESI request API objects with narrowed endpoints by accessing camel-cased "tags".
92
+
93
+ ```ts
94
+ import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
95
+
96
+ const esiRequest = taggedApi.decoreateESIRequestBody(...);
97
+ const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
98
+ ```
99
+
100
+
61
101
  ## References
62
102
 
63
- - [`ESI Types Utility Definitions`](./esi-types-util.md)
103
+ - [`ESI Types Utility Definitions`](./esi-types-util3.md)
@@ -0,0 +1,186 @@
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 Summary
10
+
11
+ ## TESICachedSeconds
12
+ `TESICachedSeconds` is a type to get the cached seconds for a specific HTTP method.
13
+
14
+ ```typescript
15
+ type TESICachedSeconds<
16
+ Method extends TESIEntryMethod, AsEndpoint = void
17
+ > = {
18
+ [M in TESIEntryMethod]: {
19
+ [EP in keyof TESIResponseOKMap[M]]: TESIResponseOKMap[M][EP]["cachedSeconds"] extends number
20
+ ? AsEndpoint extends void
21
+ ? TESIResponseOKMap[M][EP]["cachedSeconds"]: EP
22
+ : never
23
+ }[keyof TESIResponseOKMap[M]];
24
+ }[Method];
25
+ ```
26
+
27
+ ## TPathParamsNever
28
+ `TPathParamsNever` is a type used when path parameters are not required.
29
+
30
+ ```typescript
31
+ type TPathParamsNever = { pathParams?: never };
32
+ ```
33
+
34
+ ## TESIRequestFunctionSignature2
35
+ `TESIRequestFunctionSignature2` is a type that defines the signature of an ESI request function.
36
+
37
+ ```typescript
38
+ type TESIRequestFunctionSignature2<ActualOpt> = <
39
+ M extends TESIEntryMethod,
40
+ RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
41
+ EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
42
+ PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
43
+ Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
44
+ R extends InferESIResponseResult<M, EP>
45
+ >(method: M, endpoint: RealEP, options?: Opt) => Promise<R>;
46
+ ```
47
+
48
+ ## TESIRequestFunctionEachMethod2
49
+ `TESIRequestFunctionEachMethod2` is a type that defines functions to make ESI requests for a specific HTTP method.
50
+
51
+ ```typescript
52
+ type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
53
+ RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
54
+ EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
55
+ PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
56
+ Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
57
+ R extends InferESIResponseResult<M, EP>
58
+ >(endpoint: RealEP, options?: Opt) => Promise<R>;
59
+ ```
60
+
61
+ ## ReplacePathParams
62
+ `ReplacePathParams` is a type that replaces path parameters in a string with numbers.
63
+
64
+ ```typescript
65
+ type ReplacePathParams<T extends string> = T extends `${infer Start}{${infer Param}}${infer End}`
66
+ ? `${Start}${number}${ReplacePathParams<End>}` : T;
67
+ ```
68
+
69
+ ## IfNeedPathParams
70
+ `IfNeedPathParams` is a type that determines if the endpoint requires path parameters.
71
+
72
+ ```typescript
73
+ type IfNeedPathParams<EP> = IfParameterizedPath<EP> extends never ? TPathParamsNever :
74
+ EP extends ReplacePathParams<EP> ? TPathParamsNever : { pathParams: IfParameterizedPath<EP> };
75
+ ```
76
+
77
+ ## InferEndpointOrigin
78
+ `InferEndpointOrigin` is a type that infers the original endpoint path from a real endpoint path.
79
+
80
+ ```typescript
81
+ type InferEndpointOrigin<RealEP extends unknown, Endpoints> = {
82
+ [EP in Endpoints]: RealEP extends ReplacePathParams<EP>
83
+ ? EP : never;
84
+ }[Endpoints];
85
+ ```
86
+
87
+ ## IfParameterizedPath
88
+ `IfParameterizedPath` is a type that determines the required number of replacements if the endpoint is a parameterized path.
89
+
90
+ ```typescript
91
+ type IfParameterizedPath<EP, Opt = never> = EP extends `${string}/{${string}}${string}`
92
+ ? PickPathParameters<EP> extends never
93
+ ? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
94
+ ? number : [number, number]
95
+ : Opt;
96
+ ```
97
+
98
+ ## IdentifyParameters
99
+ `IdentifyParameters` is a type that identifies the required parameters for a given entry type.
100
+
101
+ ```typescript
102
+ type IdentifyParameters<
103
+ Entry, Opt,
104
+ Keys = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">
105
+ > = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
106
+ ```
107
+
108
+ ## InferESIResponseResult
109
+ `InferESIResponseResult` is a type that infers the result type of an ESI response based on the method and endpoint.
110
+
111
+ ```typescript
112
+ type InferESIResponseResult<
113
+ M extends TESIEntryMethod,
114
+ EP extends keyof TESIResponseOKMap[M]
115
+ > = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
116
+ ```
117
+
118
+ ## NoContentResponse
119
+ `NoContentResponse` is a type that represents a response with no content (HTTP status 204).
120
+
121
+ ```typescript
122
+ type NoContentResponse = { /* status: 204 */ };
123
+ ```
124
+
125
+ ## TESIEntryMethod
126
+ `TESIEntryMethod` is a type that represents the HTTP methods supported by ESI.
127
+
128
+ ```typescript
129
+ type TESIEntryMethod = keyof TESIResponseOKMap;
130
+ ```
131
+
132
+ ## TEndPointGet
133
+ `TEndPointGet` is a type that represents the endpoints for the "get" method.
134
+
135
+ ```typescript
136
+ type TEndPointGet = keyof TESIResponseOKMap["get"];
137
+ ```
138
+
139
+ ## TEndPointPost
140
+ `TEndPointPost` is a type that represents the endpoints for the "post" method.
141
+
142
+ ```typescript
143
+ type TEndPointPost = keyof TESIResponseOKMap["post"];
144
+ ```
145
+
146
+ ## TEndPointPut
147
+ `TEndPointPut` is a type that represents the endpoints for the "put" method.
148
+
149
+ ```typescript
150
+ type TEndPointPut = keyof TESIResponseOKMap["put"];
151
+ ```
152
+
153
+ ## TEndPointDelete
154
+ `TEndPointDelete` is a type that represents the endpoints for the "delete" method.
155
+
156
+ ```typescript
157
+ type TEndPointDelete = keyof TESIResponseOKMap["delete"];
158
+ ```
159
+
160
+ ## TESIResponseGetEntry
161
+ `TESIResponseGetEntry` is a type that represents the entry details for the "get" method.
162
+
163
+ ```typescript
164
+ type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
165
+ ```
166
+
167
+ ## TESIResponsePutEntry
168
+ `TESIResponsePutEntry` is a type that represents the entry details for the "put" method.
169
+
170
+ ```typescript
171
+ type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
172
+ ```
173
+
174
+ ## TESIResponsePostEntry
175
+ `TESIResponsePostEntry` is a type that represents the entry details for the "post" method.
176
+
177
+ ```typescript
178
+ type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][K];
179
+ ```
180
+
181
+ ## TESIResponseDeleteEntry
182
+ `TESIResponseDeleteEntry` is a type that represents the entry details for the "delete" method.
183
+
184
+ ```typescript
185
+ type TESIResponseDeleteEntry<K extends TEndPointDelete> = TESIResponseOKMap["delete"][K];
186
+ ```
@@ -6,22 +6,21 @@
6
6
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
7
  */
8
8
  import * as util from "./rq-util.mjs";
9
- import type { IESIRequestFunction } from "../v2";
9
+ import type { IESIRequestFunction2 } from "../v2";
10
10
  /**
11
- * @typedef {import("../v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
12
- * @typedef {import("../v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
11
+ * @typedef {import("../v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
12
+ * @typedef {import("../v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
13
13
  */
14
14
  /** #### Sample of `TESIRequestFunctionSignature`
15
15
  *
16
16
  * + This is a minimal implementation using `TESIRequestFunctionSignature`.
17
17
  * If the response contains "page", only the first page can be retrieved.
18
18
  *
19
- * @type {IESIRequestFunction}
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 pathParams - An object of parameters to include in the request
23
22
  * @param options - An object of options to include in the request
24
23
  * @returns A Promise object containing the response data
25
24
  * @throws {util.ESIRequestError}
26
25
  */
27
- export declare const request: IESIRequestFunction<util.ESIRequestOptions>;
26
+ export declare const request2: IESIRequestFunction2<util.ESIRequestOptions>;
@@ -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").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
21
- * @typedef {import("../v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
20
+ * @typedef {import("../v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
21
+ * @typedef {import("../v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
22
22
  */
23
23
  // - - - - - - - - - - - - - - - - - - - -
24
24
  // main functions
@@ -28,23 +28,24 @@ const DEBUG = util.isDebug();
28
28
  * + This is a minimal implementation using `TESIRequestFunctionSignature`.
29
29
  * If the response contains "page", only the first page can be retrieved.
30
30
  *
31
- * @type {IESIRequestFunction}
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 pathParams - An object of parameters to include in the request
35
34
  * @param options - An object of options to include in the request
36
35
  * @returns A Promise object containing the response data
37
36
  * @throws {util.ESIRequestError}
38
37
  */
39
- export const request = /** @type {IESIRequestFunction} */ (async (method, endpoint, pathParams, opt) => {
40
- if (typeof pathParams === "number") {
41
- pathParams = /** @type {typeof pathParams} */ ([pathParams]);
38
+ export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endpoint, opt) => {
39
+ /** @type {number[]=} */
40
+ let pathParams;
41
+ if (typeof opt?.pathParams === "number" || Array.isArray(opt?.pathParams)) {
42
+ pathParams = /** @type {number[]} */ (Array.isArray(opt.pathParams) ? opt.pathParams : [opt.pathParams]);
42
43
  }
43
44
  if (Array.isArray(pathParams)) {
44
45
  endpoint = util.replaceCbt(endpoint, pathParams);
45
46
  }
46
47
  // When only options are provided
47
- const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || pathParams || {});
48
+ const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || {});
48
49
  const { rqopt, qss } = util.initOptions(method, actualOpt);
49
50
  const endpointUrl = util.curl(endpoint);
50
51
  const up = new URLSearchParams(qss);
@@ -65,10 +66,11 @@ export const request = /** @type {IESIRequestFunction} */ (async (method, endpoi
65
66
  }
66
67
  });
67
68
  //
68
- // implements rest methods of `request` (IESIRequestFunction)
69
+ // implements rest methods of `request` (IESIRequestFunction2)
69
70
  //
70
71
  /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
71
- request[method] = /** @type {TESIRequestFunctionEachMethod<typeof method>} */ (function (endpoint, params, opt) {
72
- return this(method, endpoint, params, opt);
72
+ request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method>} */ (function (endpoint, opt) {
73
+ // @ts-expect-error TODO: 2025/3/12
74
+ return this(method, endpoint, opt);
73
75
  });
74
76
  });
package/lib/rq-util.d.mts CHANGED
@@ -16,7 +16,7 @@
16
16
  // https://opensource.org/licenses/mit-license.php
17
17
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
18
18
  */
19
- import type { TESIRequestFunctionMethods } from "../v2";
19
+ import type { TESIResponseOKMap, TESIRequestFunctionMethods2, TPathParamsNever } from "../v2";
20
20
  import type { TESIErrorStats } from "./esi-error-types";
21
21
  export { isNode } from "./constants.mjs";
22
22
  /**
@@ -53,6 +53,11 @@ export type ESIRequestOptions = {
53
53
  * @date 2020/1/23
54
54
  */
55
55
  auth?: true;
56
+ /**
57
+ * @date 2025/3/13
58
+ * @since v3.0.0
59
+ */
60
+ pathParams?: number | number[];
56
61
  };
57
62
  /**
58
63
  * @typedef {string | number | boolean} Truthy
@@ -98,9 +103,10 @@ export declare const handleSuccessResponse: (response: Response, endpointUrl: st
98
103
  * @param {Response} res
99
104
  * @param {string} endpointUrl
100
105
  * @param {AbortController=} abortable
101
- * @returns {Promise<void>}
106
+ * @throws {ESIRequestError}
107
+ * @returns {Promise<never>}
102
108
  */
103
- export declare const handleESIError: (res: Response, endpointUrl: string, abortable?: AbortController) => Promise<void>;
109
+ export declare const handleESIError: (res: Response, endpointUrl: string, abortable?: AbortController) => Promise<never>;
104
110
  /**
105
111
  * @param {number} stat
106
112
  * @returns {stat is 200 | 201 | 204}
@@ -175,10 +181,24 @@ export declare function getLogger(): {
175
181
  clog: (...args: any[]) => void;
176
182
  rlog: (...args: any[]) => void;
177
183
  };
184
+ /**
185
+ * Need typescript v5.5 later
186
+ * @import * as ESI from "../v2";
187
+ * @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
188
+ * @typedef {ESI.TPathParamsNever} TPathParamsNever
189
+ * @typedef {ESI.IESIRequestFunction2<ESIRequestOptions>} IESIRequestFunction2
190
+ * @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
191
+ */
192
+ /**
193
+ * #### Fire a request that does not require authentication.
194
+ *
195
+ * @type {import("./rq-util.d.mts").fireWithoutAuth}
196
+ */
197
+ export declare function fireWithoutAuth<M extends TESIEntryMethod, RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M], EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP : InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>, PathParams extends RealEP extends EP ? IfNeedPathParams<EP> : TPathParamsNever, Opt extends IdentifyParameters<TESIResponseOKMap[M][Extract<EP, keyof TESIResponseOKMap[M]>], ESIRequestOptions & PathParams>, R extends InferESIResponseResult<M, Extract<EP, keyof TESIResponseOKMap[M]>>>(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>, method: M, endpoint: RealEP, opt?: Opt): Promise<R>;
178
198
  /**
179
199
  * #### Fire a request that does not require authentication.
180
200
  *
181
- * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
201
+ * @param {TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2} fn
182
202
  * @returns {Promise<void>}
183
203
  */
184
- export declare function fireRequestsDoesNotRequireAuth(fn: TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods<ESIRequestOptions>): Promise<void>;
204
+ export declare function fireRequestsDoesNotRequireAuth(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>): Promise<void>;
package/lib/rq-util.mjs CHANGED
@@ -101,7 +101,8 @@ export const handleSuccessResponse = async (response, endpointUrl, requestOpt, u
101
101
  * @param {Response} res
102
102
  * @param {string} endpointUrl
103
103
  * @param {AbortController=} abortable
104
- * @returns {Promise<void>}
104
+ * @throws {ESIRequestError}
105
+ * @returns {Promise<never>}
105
106
  */
106
107
  export const handleESIError = async (res, endpointUrl, abortable) => {
107
108
  const status = /** @type {TESIErrorStats} */ (res.status);
@@ -323,35 +324,29 @@ export function getLogger() {
323
324
  * Need typescript v5.5 later
324
325
  * @import * as ESI from "../v2";
325
326
  * @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
326
- * @typedef {ESI.IESIRequestFunction<ESIRequestOptions>} IESIRequestFunction
327
- * @typedef {ESI.TESIRequestFunctionMethods<ESIRequestOptions>} TESIRequestFunctionMethods
327
+ * @typedef {ESI.TPathParamsNever} TPathParamsNever
328
+ * @typedef {ESI.IESIRequestFunction2<ESIRequestOptions>} IESIRequestFunction2
329
+ * @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
328
330
  */
331
+ // type ESIEndpointBrand<EP> = EP & { __esi: "x"; };
332
+ // type EPPost = ESIEndpointBrand<keyof TESIResponseOKMap["post"]>;
329
333
  /**
330
334
  * #### Fire a request that does not require authentication.
331
335
  *
332
- * @template {TESIEntryMethod} M
333
- * @template {keyof TESIResponseOKMap[M]} EP
334
- * @template {IfParameterizedPath<EP, Opt>} P2
335
- * @template {IdentifyParameters<TESIResponseOKMap[M][EP], ESIRequestOptions>} Opt
336
- * @template {InferESIResponseResult<M, EP>} R
337
- *
338
- * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
339
- * @param {M} method
340
- * @param {EP} endpoint
341
- * @param {P2} [pathParams]
342
- * @param {Opt} [opt]
343
- * @returns {Promise<R>}
336
+ * @type {import("./rq-util.d.mts").fireWithoutAuth}
344
337
  */
345
- function fireWithoutAuth(fn, method, endpoint, pathParams, opt) {
338
+ export function fireWithoutAuth(fn, method, endpoint, opt) {
346
339
  if (typeof fn === "function") {
347
- return fn(method, endpoint, pathParams, opt);
340
+ // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
341
+ return fn(method, endpoint, opt);
348
342
  }
349
- return fn[method](endpoint, pathParams, opt);
343
+ // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
344
+ return fn[method](endpoint, opt);
350
345
  }
351
346
  /**
352
347
  * #### Fire a request that does not require authentication.
353
348
  *
354
- * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
349
+ * @param {TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2} fn
355
350
  * @returns {Promise<void>}
356
351
  */
357
352
  export async function fireRequestsDoesNotRequireAuth(fn) {
@@ -363,16 +358,22 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
363
358
  // - - - - - - - - - - - -
364
359
  // Here, I borrow data from "CCP Zoetrope".
365
360
  clog();
366
- await fireWithoutAuth(fn, "get", "/characters/{character_id}/", ID_CCP_Zoetrope).then(log);
367
- clog('(portrait)');
368
- await fireWithoutAuth(fn, "get", "/characters/{character_id}/portrait/", ID_CCP_Zoetrope).then(log);
369
- clog('(affiliation)');
370
- const affiliation = await fireWithoutAuth(fn, "post", "/characters/affiliation/", { body: [ID_CCP_Zoetrope] });
371
- log(affiliation);
372
- clog('(corporation)');
373
- await fireWithoutAuth(fn, "get", "/corporations/{corporation_id}/", affiliation[0].corporation_id).then(log);
374
- rlog("get:/incursions/".green);
375
- await fireWithoutAuth(fn, "get", "/incursions/").then(log);
361
+ casefireWithoutAuth: {
362
+ await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/`).then(log);
363
+ clog('(portrait)');
364
+ await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/portrait/`).then(log);
365
+ clog('(affiliation)');
366
+ const affiliation = await fireWithoutAuth(fn, "post", "/characters/affiliation/", { body: [ID_CCP_Zoetrope] });
367
+ log(affiliation);
368
+ clog('(corporation)');
369
+ await fireWithoutAuth(fn, "get", `/corporations/${affiliation[0].corporation_id}/`).then(log);
370
+ rlog("get:/incursions/".green);
371
+ await fireWithoutAuth(fn, "get", "/incursions/").then(log);
372
+ fireWithoutAuth(fn, "delete", `/characters/${1234}/fittings/${56789}/`, {
373
+ // pathParams: [1234, 56789],
374
+ auth: true
375
+ }).catch(console.log);
376
+ }
376
377
  // - - - - - - - - - - - -
377
378
  // Miscellaneous
378
379
  // - - - - - - - - - - - -
@@ -381,7 +382,8 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
381
382
  log(ids.inventory_types, ids.regions);
382
383
  rlog(`get:/markets/${ids?.regions?.[0].id}/orders/?type_id=${ids?.inventory_types?.[0].id}, item PLEX`.green);
383
384
  // in this case, "order_type" is required
384
- const orders = await fireWithoutAuth(fn, "get", "/markets/{region_id}/orders/", ids?.regions?.[0].id, {
385
+ const orders = await fireWithoutAuth(fn, "get", "/markets/{region_id}/orders/", {
386
+ pathParams: ids?.regions?.[0].id || 0,
385
387
  query: {
386
388
  // page: 1,
387
389
  order_type: "sell",
@@ -401,13 +403,13 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
401
403
  // The following is code to observe the behavior of completion by generics.
402
404
  // Authentication is required, so an error will occur.
403
405
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
404
- let willFailed = await fireWithoutAuth(fn, "get", "/characters/{character_id}/ship/", ID_CCP_Zoetrope, {
406
+ let willFailed = await fireWithoutAuth(fn, "get", `/characters/${ID_CCP_Zoetrope}/ship/`, {
405
407
  auth: true,
406
- ignoreError: true,
407
408
  token: "token.token.token"
408
409
  });
409
410
  // in this case, "categories" and "search" is required
410
- await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", ID_CCP_Zoetrope, {
411
+ await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
412
+ pathParams: ID_CCP_Zoetrope,
411
413
  query: {
412
414
  categories: ["agent"],
413
415
  search: "ok"
@@ -8,29 +8,26 @@
8
8
  /// <reference types="../v2/esi-tagged-types"/>
9
9
  import type { ESIRequestOptions } from "./rq-util.mjs";
10
10
  /**
11
- * `esi-tagged-types` and `injectESIRequestBody` allow for more intuitive use of ESI requests based on the "tags" defined in the EVE Swagger JSON.
12
- *
13
- * + The `ESI request API object` constructed by `injectESIRequestBody` lists narrowed endpoints by accessing the camel-cased "tags" members.
11
+ * Decorates the ESI request body into a tagged ESI request map.
14
12
  *
15
13
  * @example
16
14
  * import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
17
15
  *
18
- * const esiRequest = taggedApi.injectESIRequestBody(...);
16
+ * const esiRequest = taggedApi.decoreateESIRequestBody(...);
19
17
  * const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
20
18
  *
21
19
  * @template {Record<string, unknown>} Opt - The options type for the request.
22
- * @param {TESIRequestFunctionSignature<Opt>} requestBody - The function signature for the ESI request.
23
- * @returns {XESI.TaggedESIRequestMap} - The tagged ESI request map.
24
- * @since 2.3
20
+ * @param {TESIRequestFunctionSignature2<Opt>} requestBody - The function signature for the ESI request.
21
+ * @returns {XESI.TaggedESIRequestMap2<Opt>} - The tagged ESI request map.
25
22
  */
26
- export declare function injectESIRequestBody<Opt extends Record<string, unknown>>(requestBody: TESIRequestFunctionSignature<Opt>): XESI.TaggedESIRequestMap<Opt>;
23
+ export declare function decoreateESIRequestBody<Opt extends Record<string, unknown>>(requestBody: TESIRequestFunctionSignature2<Opt>): XESI.TaggedESIRequestMap2<Opt>;
27
24
  /**
28
25
  * @import { ESIRequestOptions } from "./rq-util.mjs";
29
26
  */
30
27
  /**
31
- * Injects the minimal implementation of ESI requests into `XESI.TaggedESIRequestMap`.
28
+ * Injects the minimal implementation of ESI requests into `XESI.TaggedESIRequestMap2`.
32
29
  *
33
- * @since 2.3
34
- * @type {XESI.TaggedESIRequestMap<ESIRequestOptions>}
30
+ * @since 2.x
31
+ * @type {XESI.TaggedESIRequestMap2<ESIRequestOptions>}
35
32
  */
36
- export declare const esi: import("../v2/esi-tagged-types").TaggedESIRequestMap<ESIRequestOptions>;
33
+ export declare const esi: import("../v2/esi-tagged-types").TaggedESIRequestMap2<ESIRequestOptions>;