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/v2.mjs CHANGED
@@ -1,3 +1,15 @@
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
+ /// <reference types="./v2"/>
9
+ // - - - - - - - - - - - - - - - - - - - -
10
+ // imports
11
+ // - - - - - - - - - - - - - - - - - - - -
12
+ // import type { TESIResponseOKMap, TPathParamsNever } from "./v2";
1
13
  // import type { TESIResponseOKMap } from "eve-esi-types";
2
14
  import { is, curl, replaceCbt, getSDEVersion, initOptions, isDebug, fireRequestsDoesNotRequireAuth, isSuccess, handleESIError, handleSuccessResponse } from "./lib/rq-util.mjs";
3
15
  // - - - - - - - - - - - - - - - - - - - -
@@ -13,6 +25,8 @@ let LOG = isDebug();
13
25
  /**
14
26
  * @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
15
27
  * @typedef {import("./lib/rq-util.mjs").ESIRequestOptions} ESIRequestOptions
28
+ * @typedef {import("./lib/rq-util.mjs").ESIRequestError} ESIRequestError
29
+ * @typedef {import("./lib/rq-util.mjs").Truthy} Truthy
16
30
  */
17
31
  // - - - - - - - - - - - - - - - - - - - -
18
32
  // module vars, functions
@@ -21,6 +35,7 @@ let LOG = isDebug();
21
35
  * Get the number of currently executing ESI requests
22
36
  */
23
37
  let ax = 0;
38
+ /** @type {(m?: Truthy) => number} */
24
39
  const incrementAx = (minus) => minus ? ax-- : ax++;
25
40
  /**
26
41
  * @returns Get The Current ESI request pending count.
@@ -30,33 +45,23 @@ export const getRequestPending = () => ax;
30
45
  // main functions
31
46
  // - - - - - - - - - - - - - - - - - - - -
32
47
  /**
33
- * fire ESI request
34
- * @template {TESIEntryMethod} M
35
- * @template {keyof TESIResponseOKMap[M]} EP
36
- * @template {IfParameterizedPath<EP, Opt>} P2
37
- * @template {IdentifyParameters<TESIResponseOKMap[M][EP], ESIRequestOptions>} Opt
38
- * @template {InferESIResponseResult<M, EP>} R
48
+ * fire ESI request ESIRequestOptions
39
49
  *
40
- * @param {M} mthd
41
- * @param {EP} endp - The endpoint to request.
42
- * @param {Opt} [opt] - default is empty object {}. `body` is json string
43
- * @param {P2} [pathParams] - Optional path parameters.
44
- * @returns {Promise<R>} - The response from the endpoint.
45
- * @throws
50
+ * @type {TESIRequestFunctionSignature2<ESIRequestOptions>}
51
+ * @throws {ESIRequestError}
46
52
  * @async
47
53
  */
48
- export async function fire(mthd, endp, pathParams, opt) {
49
- if (typeof pathParams === "number") {
50
- // @ts-expect-error
51
- pathParams = [pathParams]; // as unknown as P2;
54
+ export const fire = async (mthd, endp, opt) => {
55
+ /** @type {number[]=} */
56
+ let pathParams;
57
+ if (opt && typeof opt.pathParams !== "undefined") {
58
+ pathParams = typeof opt.pathParams === "number" ? [opt.pathParams] : isArray(opt.pathParams) ? opt.pathParams : void 0;
52
59
  }
53
60
  if (isArray(pathParams)) {
54
61
  endp = replaceCbt(endp, pathParams);
55
62
  }
56
63
  // When only options are provided
57
- /** @type {Opt} */
58
- // @ts-ignore
59
- const actualOpt = opt || pathParams || {};
64
+ const actualOpt = opt || /** @type {NonNullable<typeof opt>} */ ({});
60
65
  const { rqopt, qss } = initOptions(mthd, actualOpt);
61
66
  const endpointUrl = curl(endp);
62
67
  const up = new URLSearchParams(qss);
@@ -76,10 +81,10 @@ export async function fire(mthd, endp, pathParams, opt) {
76
81
  catch (e) {
77
82
  throw e;
78
83
  }
79
- }
84
+ };
80
85
  // It should complete correctly.
81
86
  /**
82
- * @param {TESIRequestFunctionSignature<ESIRequestOptions>} fn
87
+ * @param {TESIRequestFunctionSignature2<ESIRequestOptions>} fn
83
88
  */
84
89
  async function getEVEStatus(fn) {
85
90
  const sdeVersion = await getSDEVersion();
package/esi-types-util.md DELETED
@@ -1,127 +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 Definitions
10
-
11
- ### TESIRequestFunctionSignature
12
-
13
- `TESIRequestFunctionSignature<ActualOpt>` is a type that defines the signature of an ESI request function,
14
- which sends a request to a specified endpoint and returns a response.
15
-
16
- ```ts
17
- type TESIRequestFunctionSignature<ActualOpt> = <
18
- M extends TESIEntryMethod,
19
- EP extends keyof TESIResponseOKMap[M],
20
- P2 extends IfParameterizedPath<EP, Opt>,
21
- Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt>,
22
- R extends InferESIResponseResult<M, EP>
23
- >(method: M, endpoint: EP, pathParams?: P2, options?: Opt) => Promise<R>;
24
- ```
25
-
26
- ### IfParameterizedPath
27
-
28
- `IfParameterizedPath<EP, Opt>` if parameterized path then specify number type, otherwise will be `Opt` type.
29
-
30
- ```ts
31
- type IfParameterizedPath<EP, Opt> = EP extends `${string}/{${string}}${string}`
32
- ? PickPathParameters<EP> extends never
33
- ? Opt : InferKeysLen<PickPathParameters<EP>> extends 1
34
- ? number : [number, number]
35
- : Opt;
36
- ```
37
-
38
- ### IdentifyParameters
39
-
40
- `IdentifyParameters<Entry, Opt>` is a type to identify the required parameters for a given entry type.
41
-
42
- ```ts
43
- type IdentifyParameters<Entry, Opt> = Opt & Pick<Entry, Exclude<keyof Entry, "result">>;
44
- ```
45
-
46
- ### InferESIResponseResult
47
-
48
- `InferESIResponseResult<M extends TESIEntryMethod, EP extends keyof TESIResponseOKMap[M]>` is a type to infer the result type of an ESI response based on the method and endpoint.
49
-
50
- ```ts
51
- type InferESIResponseResult<
52
- M extends TESIEntryMethod,
53
- EP extends keyof TESIResponseOKMap[M]
54
- > = TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never;
55
- ```
56
-
57
- ### TESIEntryMethod
58
-
59
- `TESIEntryMethod` represents the HTTP methods supported by ESI.
60
-
61
- ```ts
62
- type TESIEntryMethod = keyof TESIResponseOKMap;
63
- ```
64
-
65
- ### TEndPointGet
66
-
67
- `TEndPointGet` represents the endpoints for the "get" method.
68
-
69
- ```ts
70
- type TEndPointGet = keyof TESIResponseOKMap["get"];
71
- ```
72
-
73
- ### TEndPointPost
74
-
75
- `TEndPointPost` represents the endpoints for the "post" method.
76
-
77
- ```ts
78
- type TEndPointPost = keyof TESIResponseOKMap["post"];
79
- ```
80
-
81
- ### TEndPointPut
82
-
83
- `TEndPointPut` represents the endpoints for the "put" method.
84
-
85
- ```ts
86
- type TEndPointPut = keyof TESIResponseOKMap["put"];
87
- ```
88
-
89
- ### TEndPointDelete
90
-
91
- `TEndPointDelete` represents the endpoints for the "delete" method.
92
-
93
- ```ts
94
- type TEndPointDelete = keyof TESIResponseOKMap["delete"];
95
- ```
96
-
97
- ### TESIResponseGetEntry
98
-
99
- `TESIResponseGetEntry<K extends TEndPointGet>` represents the entry details for the "get" method.
100
-
101
- ```ts
102
- type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
103
- ```
104
-
105
- ### TESIResponsePutEntry
106
-
107
- `TESIResponsePutEntry<K extends TEndPointPut>` represents the entry details for the "put" method.
108
-
109
- ```ts
110
- type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
111
- ```
112
-
113
- ### TESIResponsePostEntry
114
-
115
- `TESIResponsePostEntry<K extends TEndPointPost>` represents the entry details for the "post" method.
116
-
117
- ```ts
118
- type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][K];
119
- ```
120
-
121
- ### TESIResponseDeleteEntry
122
-
123
- `TESIResponseDeleteEntry<K extends TEndPointDelete>` represents the entry details for the "delete" method.
124
-
125
- ```ts
126
- type TESIResponseDeleteEntry<K extends TEndPointDelete> = TESIResponseOKMap["delete"][K];
127
- ```