eve-esi-types 3.0.2 → 3.0.4

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.
@@ -69,8 +69,8 @@ export const request2 = /** @type {IESIRequestFunction2} */ (async (method, endp
69
69
  // implements rest methods of `request` (IESIRequestFunction2)
70
70
  //
71
71
  /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
72
- request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method>} */ (function (endpoint, opt) {
73
- // @ts-expect-error TODO: 2025/3/12
74
- return this(method, endpoint, opt);
72
+ request2[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
73
+ // @ts-expect-error TODO: ts(2345)
74
+ return request2(method, endpoint, opt);
75
75
  });
76
76
  });
package/lib/rq-util.d.mts CHANGED
@@ -181,6 +181,9 @@ export declare function getLogger(): {
181
181
  clog: (...args: any[]) => void;
182
182
  rlog: (...args: any[]) => void;
183
183
  };
184
+ export type TFireWithoutAuth = {
185
+ 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]>>, HasOpt = HasRequireParams<TESIResponseOKMap[M][Extract<EP, keyof TESIResponseOKMap[M]>]> extends never ? 0 : 1>(fn: TESIRequestFunctionSignature2<ESIRequestOptions> | TESIRequestFunctionMethods2<ESIRequestOptions>, method: M, endpoint: RealEP, ...opt: HasOpt extends 1 ? [Opt] : [Opt?]): Promise<R>;
186
+ }["fireWithoutAuth"];
184
187
  /**
185
188
  * Need typescript v5.5 later
186
189
  * @import * as ESI from "../v2";
@@ -189,12 +192,6 @@ export declare function getLogger(): {
189
192
  * @typedef {ESI.IESIRequestFunction2<ESIRequestOptions>} IESIRequestFunction2
190
193
  * @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
191
194
  */
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>;
198
195
  /**
199
196
  * #### Fire a request that does not require authentication.
200
197
  *
package/lib/rq-util.mjs CHANGED
@@ -320,29 +320,28 @@ export function getLogger() {
320
320
  const rlog = consoleUtil.getLogger("- - -> Run ESI request".cyan);
321
321
  return { clog, rlog };
322
322
  }
323
- /**
324
- * Need typescript v5.5 later
325
- * @import * as ESI from "../v2";
326
- * @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
327
- * @typedef {ESI.TPathParamsNever} TPathParamsNever
328
- * @typedef {ESI.IESIRequestFunction2<ESIRequestOptions>} IESIRequestFunction2
329
- * @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
330
- */
331
- // type ESIEndpointBrand<EP> = EP & { __esi: "x"; };
332
- // type EPPost = ESIEndpointBrand<keyof TESIResponseOKMap["post"]>;
333
323
  /**
334
324
  * #### Fire a request that does not require authentication.
335
325
  *
336
- * @type {import("./rq-util.d.mts").fireWithoutAuth}
326
+ * @type {import("./rq-util.d.mts").TFireWithoutAuth}
337
327
  */
338
- export function fireWithoutAuth(fn, method, endpoint, opt) {
328
+ // @ts-expect-error
329
+ const fireWithoutAuth = (fn, method, endpoint, opt) => {
339
330
  if (typeof fn === "function") {
340
331
  // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
341
332
  return fn(method, endpoint, opt);
342
333
  }
343
334
  // @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
344
335
  return fn[method](endpoint, opt);
345
- }
336
+ };
337
+ /**
338
+ * Need typescript v5.5 later
339
+ * @import * as ESI from "../v2";
340
+ * @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
341
+ * @typedef {ESI.TPathParamsNever} TPathParamsNever
342
+ * @typedef {ESI.IESIRequestFunction2<ESIRequestOptions>} IESIRequestFunction2
343
+ * @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
344
+ */
346
345
  /**
347
346
  * #### Fire a request that does not require authentication.
348
347
  *
@@ -369,10 +368,10 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
369
368
  await fireWithoutAuth(fn, "get", `/corporations/${affiliation[0].corporation_id}/`).then(log);
370
369
  rlog("get:/incursions/".green);
371
370
  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);
371
+ // fireWithoutAuth(fn, "delete", `/characters/${1234}/fittings/${56789}/`, {
372
+ // // pathParams: [1234, 56789],
373
+ // auth: true
374
+ // }).catch(console.log);
376
375
  }
377
376
  // - - - - - - - - - - - -
378
377
  // Miscellaneous
@@ -407,6 +406,7 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
407
406
  auth: true,
408
407
  token: "token.token.token"
409
408
  });
409
+ log(`get:/characters/${ID_CCP_Zoetrope}/ship/, returns=${willFailed}`);
410
410
  // in this case, "categories" and "search" is required
411
411
  await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
412
412
  pathParams: ID_CCP_Zoetrope,
@@ -416,10 +416,15 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
416
416
  },
417
417
  auth: true
418
418
  });
419
- // TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
420
- // Or rather, I don't know how to do it.
421
- await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/");
422
- log(willFailed);
419
+ // // TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
420
+ // // Or rather, I don't know how to do it.
421
+ // await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", {
422
+ // auth: true,
423
+ // pathParams: 1234,
424
+ // query: {
425
+ // categories: ["alliance"], search: "test!!"
426
+ // }
427
+ // });
423
428
  }
424
429
  catch (e) {
425
430
  console.error("Failed to request -", e);
package/minimal-rq.mjs CHANGED
@@ -27,9 +27,9 @@ const log = util.getUniversalLogger("[request-mini]: ");
27
27
  // Delegates implementation to `request` (TESIRequestFunctionMethods2)
28
28
  //
29
29
  const esiMethods = /** @type {TESIRequestFunctionMethods2} */ ({});
30
- /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
31
- esiMethods[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method>} */ (function (endpoint, opt) {
32
- // @ts-expect-error
30
+ /** @satisfies {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
31
+ esiMethods[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
32
+ // @ts-expect-error ts(2345)
33
33
  return request2(method, endpoint, opt);
34
34
  });
35
35
  });
@@ -39,18 +39,20 @@ const esiMethods = /** @type {TESIRequestFunctionMethods2} */ ({});
39
39
  */
40
40
  async function getEVEStatus2(fn) {
41
41
  await util.getSDEVersion().then(sdeVersion => log(`sdeVersion: ${sdeVersion}`.blue));
42
+ const { clog, rlog } = util.getLogger();
43
+ rlog("- - - - - - - > run as IESIRequestFunction2<ESIRequestOptions>".red, fn);
42
44
  await util.fireRequestsDoesNotRequireAuth(fn);
43
45
  CaseIESIRequestFunctionMethods: {
46
+ rlog("- - - - - - - > run as TESIRequestFunctionMethods2<ESIRequestOptions>".red, esiMethods);
44
47
  await util.fireRequestsDoesNotRequireAuth(esiMethods);
45
48
  }
46
- const { clog, rlog } = util.getLogger();
47
49
  CaseIESIRequestFunction2: {
48
50
  const ID_CCP_Zoetrope = 2112625428;
49
51
  // - - - - - - - - - - - -
50
52
  // Character
51
53
  // - - - - - - - - - - - -
52
54
  // Here, I borrow data from "CCP Zoetrope".
53
- rlog("- - - - - - - > run as IESIRequestFunction2<ESIRequestOptions>".red);
55
+ rlog("- - - - - - - > run as IESIRequestFunction2::TESIRequestFunctionMethods2<ESIRequestOptions>".red, fn);
54
56
  clog();
55
57
  await fn.get("/characters/{character_id}/", { pathParams: ID_CCP_Zoetrope }).then(log);
56
58
  clog('(portrait)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve-esi-types",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Extracted the main type of ESI. use for ESI request response types (version 2 only)",
5
5
  "main": "v2/index.d.ts",
6
6
  "scripts": {
package/tagged-rq.mjs CHANGED
@@ -27,7 +27,7 @@ esi.universe.post("/universe/names/", {
27
27
  body: [44992, 434243723, 109299958, 10000002]
28
28
  }).then(console.log);
29
29
  esi.universe.get("/universe/structures/", { query: { filter: "market" } }).then(console.log);
30
- // node tagged-rq.mjs -x -withError
30
+ // node tagged-rq.mjs -x -debug -withError
31
31
  if (util.is("withError")) {
32
32
  esi.assets.get("/characters/2112625428/assets/", {
33
33
  auth: true
@@ -47,5 +47,7 @@ if (util.is("withError")) {
47
47
  pathParams: [1234, 56789],
48
48
  auth: true
49
49
  });
50
- esi.character.post("/characters/affiliation/").catch(console.log);
50
+ esi.character.post("/characters/affiliation/", {
51
+ body: [12345]
52
+ }).catch(console.log);
51
53
  }
@@ -9,7 +9,7 @@
9
9
  * THIS DTS IS AUTO GENERATED, DO NOT EDIT
10
10
  *
11
11
  * @file eve-esi-types/v2/esi-tagged-types.d.ts
12
- * @summary This file is auto-generated and defines version 3.0.2 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.0.4 of the EVE Online ESI response types.
13
13
  */
14
14
  import { TESIResponseOKMap, TPathParamsNever } from "./index.d.ts";
15
15
  export * from "./index.d.ts";
@@ -82,9 +82,12 @@ export declare type InferMethod<Tag> = InferSomethingBy<Tag>
82
82
  *
83
83
  * @param endpoint - The endpoint path.
84
84
  * @param pathParams - The path parameters.
85
- * @param options - The request options.
85
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
86
86
  * @returns A promise that resolves to the response.
87
- * @date 2025/2/28
87
+ *
88
+ * @remarks
89
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
90
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
88
91
  */
89
92
  export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Tag extends ESITags, ActualOpt = {}> = <
90
93
  RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
@@ -92,9 +95,10 @@ export declare type TaggedEndpointRequestFunction2<M extends TESIEntryMethod, Ta
92
95
  PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
93
96
  Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
94
97
  R extends InferESIResponseResult<M, EP>,
98
+ HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
95
99
  // RealEPX = ReplacePathParamsX<RealEPX>,
96
100
  // EPX = ReplacePathParams<EP>,
97
- >(endpoint: RealEP, options?: Opt) => Promise<R>;
101
+ >(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
98
102
 
99
103
 
100
104
  // - - - - - - - - - - - - - - - - - - - - - - - - - -
package/v2/index.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  * THIS DTS IS AUTO GENERATED, DO NOT EDIT
10
10
  *
11
11
  * @file eve-esi-types/v2/index.d.ts
12
- * @summary This file is auto-generated and defines version 3.0.2 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.0.4 of the EVE Online ESI response types.
13
13
  */
14
14
 
15
15
  import type { TESIResponseOKMap } from "./response-map.d.ts";
@@ -125,9 +125,13 @@ declare global {
125
125
  *
126
126
  * @param method - The HTTP method to use for the request (e.g., "get", "post").
127
127
  * @param endpoint - The real path of the ESI endpoint to send the request to.
128
- * @param options - An optional object containing additional options for the request.
128
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
129
129
  *
130
130
  * @returns A Promise object containing the response data, with the type inferred based on the method and endpoint.
131
+ *
132
+ * @remarks
133
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
134
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
131
135
  */
132
136
  type TESIRequestFunctionSignature2<ActualOpt> = <
133
137
  M extends TESIEntryMethod,
@@ -138,8 +142,9 @@ declare global {
138
142
  // If RealEP points to an endpoint origin (not a replaced endpoint), the path parameter is required
139
143
  PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
140
144
  Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
141
- R extends InferESIResponseResult<M, EP>
142
- >(method: M, endpoint: RealEP, options?: Opt) => Promise<R>;
145
+ R extends InferESIResponseResult<M, EP>,
146
+ HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
147
+ >(method: M, endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
143
148
 
144
149
  /**
145
150
  * Represents a function that can make ESI requests for a specific HTTP method.
@@ -156,17 +161,22 @@ declare global {
156
161
  * @template R - The response type.
157
162
  *
158
163
  * @param endpoint - The real path of the ESI endpoint to send the request to.
159
- * @param options - An optional object containing additional options for the request.
164
+ * @param options - An optional object containing additional options for the request. If the endpoint has required parameters, this parameter must be provided.
160
165
  *
161
166
  * @returns A Promise object containing the response data, with the type inferred based on the method and endpoint.
167
+ *
168
+ * @remarks
169
+ * The `...options: HasOpt extends 1 ? [Opt] : [Opt?]` parameter is defined this way to enforce that if the endpoint has required parameters,
170
+ * the `options` parameter must be provided. If there are no required parameters, the `options` parameter is optional.
162
171
  */
163
172
  type TESIRequestFunctionEachMethod2<M extends TESIEntryMethod, ActualOpt = {}> = <
164
173
  RealEP extends ReplacePathParams<keyof TESIResponseOKMap[M] & string> | keyof TESIResponseOKMap[M],
165
174
  EP extends InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]> extends never ? RealEP: InferEndpointOrigin<RealEP, keyof TESIResponseOKMap[M]>,
166
175
  PathParams extends RealEP extends EP ? IfNeedPathParams<EP>: TPathParamsNever,
167
176
  Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt & PathParams>,
168
- R extends InferESIResponseResult<M, EP>
169
- >(endpoint: RealEP, options?: Opt) => Promise<R>;
177
+ R extends InferESIResponseResult<M, EP>,
178
+ HasOpt = HasRequireParams<TESIResponseOKMap[M][EP]> extends never ? 0 : 1
179
+ >(endpoint: RealEP, ...options: HasOpt extends 1 ? [Opt] : [Opt?]) => Promise<R>;
170
180
 
171
181
  /**
172
182
  * Replaces path parameters in a string with numbers.
@@ -222,6 +232,22 @@ declare global {
222
232
  // }[keyof TESIResponseOKMap[Method]]
223
233
  // }[TESIEntryMethod];
224
234
 
235
+ /**
236
+ * Determines if the given entry has required parameters.
237
+ *
238
+ * This type checks if an entry has any required parameters by excluding the keys "result", "tag", and "cachedSeconds".
239
+ * If any keys remain after this exclusion, it means the entry has required parameters.
240
+ *
241
+ * @template Entry - The entry type to check for required parameters.
242
+ *
243
+ * @example
244
+ * ```ts
245
+ * type ExampleEntry = { result: string, tag: string, cachedSeconds: number, auth: string };
246
+ * type HasRequired = HasRequireParams<ExampleEntry>; // "auth"
247
+ * ```
248
+ */
249
+ type HasRequireParams<Entry> = Exclude<keyof Entry, "result" | "tag" | "cachedSeconds">;
250
+
225
251
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
226
252
  // Version 2 types
227
253
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -9,7 +9,7 @@
9
9
  * THIS DTS IS AUTO GENERATED, DO NOT EDIT
10
10
  *
11
11
  * @file eve-esi-types/v2/response-map.d.ts
12
- * @summary This file is auto-generated and defines version 3.0.2 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.0.4 of the EVE Online ESI response types.
13
13
  */
14
14
  import "./types-index.d.ts";
15
15
 
@@ -9,7 +9,7 @@
9
9
  * THIS DTS IS AUTO GENERATED, DO NOT EDIT
10
10
  *
11
11
  * @file eve-esi-types/v2/types-index.d.ts
12
- * @summary This file is auto-generated and defines version 3.0.2 of the EVE Online ESI response types.
12
+ * @summary This file is auto-generated and defines version 3.0.4 of the EVE Online ESI response types.
13
13
  */
14
14
  import "./get_wars_ok.d.ts";
15
15
  import "./get_status_ok.d.ts";
package/v2.d.mts CHANGED
@@ -13,7 +13,6 @@ export declare const getRequestPending: () => number;
13
13
  /**
14
14
  * fire ESI request ESIRequestOptions
15
15
  *
16
- * @type {TESIRequestFunctionSignature2<ESIRequestOptions>}
17
16
  * @throws {ESIRequestError}
18
17
  * @async
19
18
  */
package/v2.mjs CHANGED
@@ -35,7 +35,7 @@ let LOG = isDebug();
35
35
  * Get the number of currently executing ESI requests
36
36
  */
37
37
  let ax = 0;
38
- /** @type {(m?: Truthy) => number} */
38
+ /** @type {function(Truthy=): number} */
39
39
  const incrementAx = (minus) => minus ? ax-- : ax++;
40
40
  /**
41
41
  * @returns Get The Current ESI request pending count.
@@ -47,11 +47,10 @@ export const getRequestPending = () => ax;
47
47
  /**
48
48
  * fire ESI request ESIRequestOptions
49
49
  *
50
- * @type {TESIRequestFunctionSignature2<ESIRequestOptions>}
51
50
  * @throws {ESIRequestError}
52
51
  * @async
53
52
  */
54
- export const fire = async (mthd, endp, opt) => {
53
+ export const fire = /** @type {TESIRequestFunctionSignature2<ESIRequestOptions>} */ (async (mthd, endp, opt) => {
55
54
  /** @type {number[]=} */
56
55
  let pathParams;
57
56
  if (opt && typeof opt.pathParams !== "undefined") {
@@ -81,7 +80,7 @@ export const fire = async (mthd, endp, opt) => {
81
80
  catch (e) {
82
81
  throw e;
83
82
  }
84
- };
83
+ });
85
84
  // It should complete correctly.
86
85
  /**
87
86
  * @param {TESIRequestFunctionSignature2<ESIRequestOptions>} fn