eve-esi-types 2.3.2 → 2.3.3

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/index.html ADDED
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>eve-esi-types ESI request test</title>
7
+ <script type="module" src="./minimal-rq.mjs"></script>
8
+ </head>
9
+ <body>
10
+ <div class="container">
11
+ </div>
12
+ <div class="info">
13
+ browser-sync start -s --port 8080 --no-open --ss ./<br>
14
+ then access to <a href="http://localhost:8080/?x=1&debug=1">eve-esi-types ESI request test</a>
15
+ </div>
16
+ <footer class="footer"></footer>
17
+ </body>
18
+ </html>
@@ -43,22 +43,19 @@ export const request = async (method, endpoint, pathParams, opt) => {
43
43
  pathParams = [pathParams];
44
44
  }
45
45
  if (Array.isArray(pathParams)) {
46
- // @ts-expect-error actualy endp is string
47
46
  endpoint = util.replaceCbt(endpoint, pathParams);
48
47
  }
49
48
  // When only options are provided
50
49
  const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || pathParams || {});
51
50
  const { rqopt, qss } = util.initOptions(method, actualOpt);
52
- // @ts-expect-error actualy endp is string
53
51
  const endpointUrl = util.curl(endpoint);
54
52
  const up = new URLSearchParams(qss);
55
53
  const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
56
54
  DEBUG && log(url);
57
55
  try {
58
56
  const res = await fetch(url, rqopt);
59
- const { status } = res;
60
57
  // The parameters are different for successful and error responses.
61
- if (util.isSuccess(status)) {
58
+ if (util.isSuccess(res.status)) {
62
59
  return util.handleSuccessResponse(res, endpointUrl, rqopt, up);
63
60
  }
64
61
  // else if (isError(status)) {}
package/lib/rq-util.d.mts CHANGED
@@ -5,9 +5,22 @@
5
5
  // https://opensource.org/licenses/mit-license.php
6
6
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
7
  */
8
- import "colors.ts";
8
+ /// <reference types="../v2"/>
9
+ // - - - - - - - - - - - - - - - - - - - -
10
+ // imports
11
+ // - - - - - - - - - - - - - - - - - - - -
9
12
  import type { TESIRequestFunctionMethods } from "../v2";
10
13
  import type { TESIErrorStats } from "./esi-error-types";
14
+ /**
15
+ * Dummy import
16
+ * @import * as cc from "colors.ts";
17
+ */
18
+ /**
19
+ * will almost certainly be able to detect if you are in a nodejs environment
20
+ *
21
+ * @date 2020/5/9
22
+ */
23
+ export declare const isNode: boolean;
11
24
  /**
12
25
  * this always `https://esi.evetech.net`
13
26
  */
@@ -138,18 +151,20 @@ export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: Req
138
151
  * // ->
139
152
  * "/characters/<char.character_id>/skills"
140
153
  *
141
- * @param {string} endpoint e.g - "/characters/{character_id}/"
154
+ * @template {unknown} T
155
+ * @param {T} endpoint e.g - "/characters/{character_id}/"
142
156
  * @param {number[]} ids
143
- * @returns {string | null} fragment of qualified endpoint uri or null.
157
+ * @returns {T} fragment of qualified endpoint uri or null.
144
158
  */
145
- export declare const replaceCbt: (endpoint: string, ids: number[]) => string;
159
+ export declare const replaceCbt: <T extends unknown>(endpoint: T, ids: number[]) => T;
146
160
  /**
147
161
  *
148
- * @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
162
+ * @template {unknown} T
163
+ * @param {T} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
149
164
  * + The version parameter is forced to apply `latest`
150
165
  * @returns {string}
151
166
  */
152
- export declare const curl: (endp: string) => string;
167
+ export declare const curl: <T extends unknown>(endp: T) => string;
153
168
  /**
154
169
  * @date 2020/03/31
155
170
  * @version 2.1
package/lib/rq-util.mjs CHANGED
@@ -9,7 +9,29 @@
9
9
  // - - - - - - - - - - - - - - - - - - - -
10
10
  // imports
11
11
  // - - - - - - - - - - - - - - - - - - - -
12
- import "colors.ts";
12
+ /**
13
+ * Dummy import
14
+ * @import * as cc from "colors.ts";
15
+ */
16
+ /**
17
+ * will almost certainly be able to detect if you are in a nodejs environment
18
+ *
19
+ * @date 2020/5/9
20
+ */
21
+ export const isNode = await (async () => {
22
+ let modId, returnValue;
23
+ if (typeof process === "object") {
24
+ modId = "colors.ts";
25
+ // @ts-ignore
26
+ returnValue = typeof process.versions === "object" && /\d+\.\d+\.\d+/.test(process.versions.node);
27
+ }
28
+ else {
29
+ modId = "https://cdn.jsdelivr.net/npm/colors.ts@1.0.20/+esm";
30
+ returnValue = false;
31
+ }
32
+ await import(modId);
33
+ return returnValue;
34
+ })();
13
35
  // - - - - - - - - - - - - - - - - - - - -
14
36
  // constants, types
15
37
  // - - - - - - - - - - - - - - - - - - - -
@@ -153,13 +175,36 @@ export const isError = (stat) => {
153
175
  * @returns {boolean}
154
176
  */
155
177
  export const isDebug = () => {
156
- return process.argv.includes("-debug");
178
+ return is("debug");
157
179
  };
158
180
  /**
159
181
  * @param {string} opt
160
182
  * @returns {boolean}
161
183
  */
162
- export const is = (opt) => process.argv.includes(`-${opt}`);
184
+ export const is = (opt) => {
185
+ if (typeof process === "object") {
186
+ return process.argv.includes(`-${opt}`);
187
+ }
188
+ else {
189
+ const q = location.search || location.hash;
190
+ if (q) {
191
+ //* ctt
192
+ const entries = q.substring(1).split("&");
193
+ for (const entry of entries) {
194
+ const [key, /*value*/] = entry.split("=");
195
+ if (key === opt)
196
+ return true;
197
+ }
198
+ /*/
199
+ const usp = new URLSearchParams(q.substring(1));
200
+ for (const [key, value] of usp.entries()) {
201
+ if (key === opt) return true;
202
+ }
203
+ //*/
204
+ }
205
+ }
206
+ return false;
207
+ };
163
208
  /**
164
209
  * @param {string} method
165
210
  * @param {ESIRequestOptions} opt
@@ -176,7 +221,9 @@ export const initOptions = (method, opt) => {
176
221
  };
177
222
  /** @type {Record<string, string>} */
178
223
  const qss = {
179
- // language: "en",
224
+ // CAVEAT: If the language parameter is not set, some endpoints such as "/universe/ids/" may return incomplete results.
225
+ // Therefore, the language parameter should always be set.
226
+ language: "en",
180
227
  };
181
228
  if (opt.query) {
182
229
  // Object.assign(query, options.query); Object.assign is too slow
@@ -238,23 +285,26 @@ export const fetchP = async (endpointUrl, rqopt, rqp, pc, increment = () => { })
238
285
  * // ->
239
286
  * "/characters/<char.character_id>/skills"
240
287
  *
241
- * @param {string} endpoint e.g - "/characters/{character_id}/"
288
+ * @template {unknown} T
289
+ * @param {T} endpoint e.g - "/characters/{character_id}/"
242
290
  * @param {number[]} ids
243
- * @returns {string | null} fragment of qualified endpoint uri or null.
291
+ * @returns {T} fragment of qualified endpoint uri or null.
244
292
  */
245
293
  export const replaceCbt = (endpoint, ids) => {
246
294
  let idx = 0;
295
+ // @ts-expect-error
247
296
  return endpoint.replace(/{([\w]+)}/g, $0 => ids[idx++] + "");
248
297
  };
249
298
  /**
250
299
  *
251
- * @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
300
+ * @template {unknown} T
301
+ * @param {T} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
252
302
  * + The version parameter is forced to apply `latest`
253
303
  * @returns {string}
254
304
  */
255
305
  export const curl = (endp) => {
256
- endp = endp.replace(/^\/+|\/+$/g, "");
257
- return `${BASE}/latest/${endp}/`;
306
+ // @ts-expect-error
307
+ return `${BASE}/latest/${endp.replace(/^\/+|\/+$/g, "")}/`;
258
308
  };
259
309
  /**
260
310
  * @date 2020/03/31
package/minimal-rq.mjs CHANGED
@@ -83,6 +83,12 @@ async function getEVEStatus(fn) {
83
83
  if (!util.is("x")) {
84
84
  getEVEStatus(request).then(eveStatus => log(eveStatus));
85
85
  }
86
+ else {
87
+ // @ts-ignore
88
+ globalThis.runTest = () => {
89
+ getEVEStatus(request).then(eveStatus => log(eveStatus));
90
+ };
91
+ }
86
92
  // {
87
93
  // "players": 16503,
88
94
  // "server_version": "2794925",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve-esi-types",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
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": {
@@ -15,6 +15,7 @@
15
15
  "v2",
16
16
  "lib",
17
17
  "*.d.mts",
18
+ "index.html",
18
19
  "*.mjs",
19
20
  "LICENSE",
20
21
  "*.md",
package/v2.mjs CHANGED
@@ -51,7 +51,6 @@ export async function fire(mthd, endp, pathParams, opt) {
51
51
  pathParams = [pathParams]; // as unknown as P2;
52
52
  }
53
53
  if (isArray(pathParams)) {
54
- // @ts-expect-error actualy endp is string
55
54
  endp = replaceCbt(endp, pathParams);
56
55
  }
57
56
  // When only options are provided
@@ -59,7 +58,6 @@ export async function fire(mthd, endp, pathParams, opt) {
59
58
  // @ts-ignore
60
59
  const actualOpt = opt || pathParams || {};
61
60
  const { rqopt, qss } = initOptions(mthd, actualOpt);
62
- // @ts-expect-error actualy endp is string
63
61
  const endpointUrl = curl(endp);
64
62
  const up = new URLSearchParams(qss);
65
63
  const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
@@ -67,9 +65,8 @@ export async function fire(mthd, endp, pathParams, opt) {
67
65
  ax++;
68
66
  try {
69
67
  const res = await fetch(url, rqopt).finally(() => ax--);
70
- const { status } = res;
71
68
  // The parameters are different for successful and error responses.
72
- if (isSuccess(status)) {
69
+ if (isSuccess(res.status)) {
73
70
  return handleSuccessResponse(res, endpointUrl, rqopt, up, incrementAx);
74
71
  }
75
72
  // else if (isError(status)) {}