eve-esi-types 2.2.6 → 2.3.0
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 +25 -0
- package/lib/request-api.d.mts +27 -0
- package/lib/request-api.mjs +76 -0
- package/{rq-util.d.mts → lib/rq-util.d.mts} +2 -1
- package/{rq-util.mjs → lib/rq-util.mjs} +3 -2
- package/lib/tagged-request-api.d.mts +29 -0
- package/lib/tagged-request-api.mjs +69 -0
- package/minimal-rq.d.mts +1 -29
- package/minimal-rq.mjs +5 -48
- package/package.json +4 -2
- package/tagged-rq.d.mts +1 -0
- package/tagged-rq.mjs +22 -0
- package/tsconfig.json +2 -2
- package/v2/esi-tagged-types.d.ts +148 -0
- package/v2/get_characters_character_id_skillqueue_ok.d.ts +1 -1
- package/v2/index.d.ts +8 -8
- package/v2/response-map.d.ts +207 -7
- package/v2/types-index.d.ts +2 -2
- package/v2.d.mts +1 -1
- package/v2.mjs +5 -3
package/README.md
CHANGED
|
@@ -32,6 +32,31 @@ export declare function fire<
|
|
|
32
32
|
>(mthd: M, endp: EP, pathParams?: P2, opt?: Opt): Promise<R>;
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## New Features in v2.3.0
|
|
36
|
+
|
|
37
|
+
### ESI Tagged Types
|
|
38
|
+
|
|
39
|
+
> Introduced intuitive ESI requests handling using "tags" from the EVE Swagger JSON.
|
|
40
|
+
|
|
41
|
+
### injectESIRequestBody
|
|
42
|
+
|
|
43
|
+
> Utilized `injectESIRequestBody` to generate ESI request API objects with narrowed endpoints by accessing camel-cased "tags".
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
|
|
47
|
+
|
|
48
|
+
const esiRequest = taggedApi.injectESIRequestBody(...);
|
|
49
|
+
const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
+ or
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// Minimal default ESI request body implementation
|
|
56
|
+
import { esi } from "eve-esi-types/lib/tagged-request-api.mjs";
|
|
57
|
+
|
|
58
|
+
const ret = await esi.universe.get("/universe/structures/", { query: { filter: "market" }});
|
|
59
|
+
```
|
|
35
60
|
|
|
36
61
|
## References
|
|
37
62
|
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
import * as util from "./rq-util.mjs";
|
|
9
|
+
import type { IESIRequestFunction } from "../v2";
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import("../v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
|
|
12
|
+
* @typedef {import("../v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
|
|
13
|
+
*/
|
|
14
|
+
/** #### Sample of `TESIRequestFunctionSignature`
|
|
15
|
+
*
|
|
16
|
+
* + This is a minimal implementation using `TESIRequestFunctionSignature`.
|
|
17
|
+
* If the response contains "page", only the first page can be retrieved.
|
|
18
|
+
*
|
|
19
|
+
* @type {IESIRequestFunction}
|
|
20
|
+
* @param method - The HTTP method to use for the request
|
|
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
|
+
* @param options - An object of options to include in the request
|
|
24
|
+
* @returns A Promise object containing the response data
|
|
25
|
+
* @throws {ESIRequesError}
|
|
26
|
+
*/
|
|
27
|
+
export declare const request: IESIRequestFunction<util.ESIRequestOptions>;
|
|
@@ -0,0 +1,76 @@
|
|
|
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 * as util from "./rq-util.mjs";
|
|
13
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
14
|
+
// constants, types
|
|
15
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
16
|
+
// shorthands
|
|
17
|
+
const log = console.log;
|
|
18
|
+
const DEBUG = util.isDebug();
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {import("../v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
|
|
21
|
+
* @typedef {import("../v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
|
|
22
|
+
*/
|
|
23
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
24
|
+
// main functions
|
|
25
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
26
|
+
/** #### Sample of `TESIRequestFunctionSignature`
|
|
27
|
+
*
|
|
28
|
+
* + This is a minimal implementation using `TESIRequestFunctionSignature`.
|
|
29
|
+
* If the response contains "page", only the first page can be retrieved.
|
|
30
|
+
*
|
|
31
|
+
* @type {IESIRequestFunction}
|
|
32
|
+
* @param method - The HTTP method to use for the request
|
|
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
|
+
* @param options - An object of options to include in the request
|
|
36
|
+
* @returns A Promise object containing the response data
|
|
37
|
+
* @throws {ESIRequesError}
|
|
38
|
+
*/
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
export const request = async (method, endpoint, pathParams, opt) => {
|
|
41
|
+
if (typeof pathParams === "number") {
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
pathParams = [pathParams];
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(pathParams)) {
|
|
46
|
+
// @ts-expect-error actualy endp is string
|
|
47
|
+
endpoint = util.replaceCbt(endpoint, pathParams);
|
|
48
|
+
}
|
|
49
|
+
// When only options are provided
|
|
50
|
+
const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || pathParams || {});
|
|
51
|
+
const { rqopt, qss } = util.initOptions(method, actualOpt);
|
|
52
|
+
// @ts-expect-error actualy endp is string
|
|
53
|
+
const endpointUrl = util.curl(endpoint);
|
|
54
|
+
const up = new URLSearchParams(qss);
|
|
55
|
+
const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
|
|
56
|
+
DEBUG && log(url);
|
|
57
|
+
try {
|
|
58
|
+
return await fetch(url, rqopt).then(res => {
|
|
59
|
+
if (res.status >= 400) {
|
|
60
|
+
throw new util.ESIRequesError(`${res.statusText} (status=${res.status})`);
|
|
61
|
+
}
|
|
62
|
+
return res.json();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
log(e);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
//
|
|
70
|
+
// implements rest methods of `request` (IESIRequestFunction)
|
|
71
|
+
//
|
|
72
|
+
/** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
|
|
73
|
+
request[method] = /** @type {TESIRequestFunctionEachMethod<typeof method>} */ (function (endpoint, params, opt) {
|
|
74
|
+
return this(method, endpoint, params, opt);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
import "colors.ts";
|
|
9
|
-
import type { TESIRequestFunctionMethods } from "
|
|
9
|
+
import type { TESIRequestFunctionMethods } from "../v2";
|
|
10
10
|
/**
|
|
11
11
|
* this always `https://esi.evetech.net`
|
|
12
12
|
*/
|
|
@@ -62,6 +62,7 @@ export declare class ESIErrorLimitReachedError extends ESIRequesError {
|
|
|
62
62
|
* @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
|
|
63
63
|
*/
|
|
64
64
|
export declare const isDebug: () => boolean;
|
|
65
|
+
export declare const is: (opt: string) => boolean;
|
|
65
66
|
/**
|
|
66
67
|
* @param {string} method
|
|
67
68
|
* @param {ESIRequestOptions} opt
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="
|
|
8
|
+
/// <reference types="../v2"/>
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -49,6 +49,7 @@ export class ESIErrorLimitReachedError extends ESIRequesError {
|
|
|
49
49
|
export const isDebug = () => {
|
|
50
50
|
return process.argv.includes("-debug");
|
|
51
51
|
};
|
|
52
|
+
export const is = (opt) => process.argv.includes(`-${opt}`);
|
|
52
53
|
/**
|
|
53
54
|
* @param {string} method
|
|
54
55
|
* @param {ESIRequestOptions} opt
|
|
@@ -179,7 +180,7 @@ export function getLogger() {
|
|
|
179
180
|
}
|
|
180
181
|
/**
|
|
181
182
|
* Need typescript v5.5 later
|
|
182
|
-
* @import * as ESI from "
|
|
183
|
+
* @import * as ESI from "../v2";
|
|
183
184
|
* @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
|
|
184
185
|
* @typedef {ESI.IESIRequestFunction<ESIRequestOptions>} IESIRequestFunction
|
|
185
186
|
* @typedef {ESI.TESIRequestFunctionMethods<ESIRequestOptions>} TESIRequestFunctionMethods
|
|
@@ -0,0 +1,29 @@
|
|
|
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/esi-tagged-types"/>
|
|
9
|
+
/**
|
|
10
|
+
* `esi-tagged-types` and `injectESIRequestBody` allow for more intuitive use of ESI requests based on the "tags" defined in the EVE Swagger JSON.
|
|
11
|
+
*
|
|
12
|
+
* + The `ESI request API object` constructed by `injectESIRequestBody` lists narrowed endpoints by accessing the camel-cased "tags" members.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
|
|
16
|
+
*
|
|
17
|
+
* const esiRequest = taggedApi.injectESIRequestBody(...);
|
|
18
|
+
* const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
|
|
19
|
+
*
|
|
20
|
+
* @param {TESIRequestFunctionSignature<{}>} requestBody
|
|
21
|
+
* @returns {XESI.TaggedESIRequestMap}
|
|
22
|
+
* @since 2.3
|
|
23
|
+
*/
|
|
24
|
+
export declare function injectESIRequestBody(requestBody: TESIRequestFunctionSignature<{}>): XESI.TaggedESIRequestMap;
|
|
25
|
+
/**
|
|
26
|
+
* Injects the minimal implementation of ESI requests into `XESI.TaggedESIRequestMap`.
|
|
27
|
+
* @since 2.3
|
|
28
|
+
*/
|
|
29
|
+
export declare const esi: XESI.TaggedESIRequestMap;
|
|
@@ -0,0 +1,69 @@
|
|
|
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/esi-tagged-types"/>
|
|
9
|
+
/**
|
|
10
|
+
* @file eve-esi-types/lib/tagged-request-api.mts
|
|
11
|
+
*/
|
|
12
|
+
import { request } from "./request-api.mjs";
|
|
13
|
+
/** @satisfies {XESI.ESITags[]} */
|
|
14
|
+
const ESI_TAGs = [
|
|
15
|
+
"Alliance", "Assets",
|
|
16
|
+
"Calendar", "Character",
|
|
17
|
+
"Clones", "Contacts",
|
|
18
|
+
"Contracts", "Corporation",
|
|
19
|
+
"Dogma", "Faction Warfare",
|
|
20
|
+
"Fittings", "Fleets",
|
|
21
|
+
"Incursions", "Industry",
|
|
22
|
+
"Insurance", "Killmails",
|
|
23
|
+
"Location", "Loyalty",
|
|
24
|
+
"Mail", "Market",
|
|
25
|
+
"Opportunities", "Planetary Interaction",
|
|
26
|
+
"Routes", "Search",
|
|
27
|
+
"Skills", "Sovereignty",
|
|
28
|
+
"Status", "Universe",
|
|
29
|
+
"User Interface", "Wallet",
|
|
30
|
+
"Wars"
|
|
31
|
+
];
|
|
32
|
+
/** @satisfies {TESIEntryMethod[]} */
|
|
33
|
+
const METHODs = ["get", "post", "put", "delete"];
|
|
34
|
+
/**
|
|
35
|
+
* `esi-tagged-types` and `injectESIRequestBody` allow for more intuitive use of ESI requests based on the "tags" defined in the EVE Swagger JSON.
|
|
36
|
+
*
|
|
37
|
+
* + The `ESI request API object` constructed by `injectESIRequestBody` lists narrowed endpoints by accessing the camel-cased "tags" members.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* import * as taggedApi from "eve-esi-types/lib/tagged-request-api.mjs";
|
|
41
|
+
*
|
|
42
|
+
* const esiRequest = taggedApi.injectESIRequestBody(...);
|
|
43
|
+
* const ret = await esiRequest.universe.get("/universe/structures/", { query: { filter: "market" }});
|
|
44
|
+
*
|
|
45
|
+
* @param {TESIRequestFunctionSignature<{}>} requestBody
|
|
46
|
+
* @returns {XESI.TaggedESIRequestMap}
|
|
47
|
+
* @since 2.3
|
|
48
|
+
*/
|
|
49
|
+
// Here, functions are implemented for "get", "post", "put", and "delete" for convenience.
|
|
50
|
+
// However, in the completion listed by `injectESIRequestBody(<requestBody>).`, only the inferred methods will be listed.
|
|
51
|
+
export function injectESIRequestBody(requestBody) {
|
|
52
|
+
const rq = /** @type {XESI.TaggedESIRequestMap} */ ({});
|
|
53
|
+
for (const tag of ESI_TAGs) {
|
|
54
|
+
const camel =
|
|
55
|
+
/** @type {XESI.LCamelCase<XESI.ESITags>} */ (tag[0].toLowerCase() + tag.slice(1).replace(/\s(\w)/g, "$1"));
|
|
56
|
+
const entry = /** @type {XESI.ESITaggedEndpointRequest<typeof tag>} */ ({});
|
|
57
|
+
for (const method of METHODs) {
|
|
58
|
+
// @ts-ignore ignore ts(2590)
|
|
59
|
+
entry[method] = /** @satisfies {XESI.TaggedEndpointRequestFunction<typeof method, typeof tag>} */ ((e, params, opt) => requestBody(method, e, params, opt));
|
|
60
|
+
}
|
|
61
|
+
rq[camel] = entry;
|
|
62
|
+
}
|
|
63
|
+
return rq;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Injects the minimal implementation of ESI requests into `XESI.TaggedESIRequestMap`.
|
|
67
|
+
* @since 2.3
|
|
68
|
+
*/
|
|
69
|
+
export const esi = injectESIRequestBody(request);
|
package/minimal-rq.d.mts
CHANGED
|
@@ -1,29 +1 @@
|
|
|
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
|
-
import * as util from "./rq-util.mjs";
|
|
9
|
-
import type { IESIRequestFunction } from "./v2";
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
|
|
12
|
-
* @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
|
|
13
|
-
* @typedef {import("./v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
|
|
14
|
-
* @typedef {import("./v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
|
|
15
|
-
*/
|
|
16
|
-
/** #### Sample of `TESIRequestFunctionSignature`
|
|
17
|
-
*
|
|
18
|
-
* + This is a minimal implementation using `TESIRequestFunctionSignature`.
|
|
19
|
-
* If the response contains "page", only the first page can be retrieved.
|
|
20
|
-
*
|
|
21
|
-
* @type {IESIRequestFunction}
|
|
22
|
-
* @param method - The HTTP method to use for the request
|
|
23
|
-
* @param endpoint - The Path of the ESI endpoint to send the request to
|
|
24
|
-
* @param pathParams - An object of parameters to include in the request
|
|
25
|
-
* @param options - An object of options to include in the request
|
|
26
|
-
* @returns A Promise object containing the response data
|
|
27
|
-
* @throws {ESIRequesError}
|
|
28
|
-
*/
|
|
29
|
-
export declare const request: IESIRequestFunction<util.ESIRequestOptions>;
|
|
1
|
+
export {};
|
package/minimal-rq.mjs
CHANGED
|
@@ -9,65 +9,20 @@
|
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
12
|
-
import * as util from "./rq-util.mjs";
|
|
12
|
+
import * as util from "./lib/rq-util.mjs";
|
|
13
|
+
import { request } from "./lib/request-api.mjs";
|
|
13
14
|
// - - - - - - - - - - - - - - - - - - - -
|
|
14
15
|
// constants, types
|
|
15
16
|
// - - - - - - - - - - - - - - - - - - - -
|
|
16
17
|
// shorthands
|
|
17
18
|
const log = console.log;
|
|
18
|
-
const DEBUG = util.isDebug();
|
|
19
19
|
/**
|
|
20
|
-
* @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
|
|
21
|
-
* @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
|
|
22
20
|
* @typedef {import("./v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
|
|
23
21
|
* @typedef {import("./v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
|
|
24
22
|
*/
|
|
25
23
|
// - - - - - - - - - - - - - - - - - - - -
|
|
26
24
|
// main functions
|
|
27
25
|
// - - - - - - - - - - - - - - - - - - - -
|
|
28
|
-
/** #### Sample of `TESIRequestFunctionSignature`
|
|
29
|
-
*
|
|
30
|
-
* + This is a minimal implementation using `TESIRequestFunctionSignature`.
|
|
31
|
-
* If the response contains "page", only the first page can be retrieved.
|
|
32
|
-
*
|
|
33
|
-
* @type {IESIRequestFunction}
|
|
34
|
-
* @param method - The HTTP method to use for the request
|
|
35
|
-
* @param endpoint - The Path of the ESI endpoint to send the request to
|
|
36
|
-
* @param pathParams - An object of parameters to include in the request
|
|
37
|
-
* @param options - An object of options to include in the request
|
|
38
|
-
* @returns A Promise object containing the response data
|
|
39
|
-
* @throws {ESIRequesError}
|
|
40
|
-
*/
|
|
41
|
-
// @ts-expect-error
|
|
42
|
-
export const request = (method, endpoint, pathParams, opt) => {
|
|
43
|
-
if (typeof pathParams === "number") {
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
pathParams = [pathParams];
|
|
46
|
-
}
|
|
47
|
-
if (Array.isArray(pathParams)) {
|
|
48
|
-
// @ts-expect-error actualy endp is string
|
|
49
|
-
endpoint = util.replaceCbt(endpoint, pathParams);
|
|
50
|
-
}
|
|
51
|
-
// When only options are provided
|
|
52
|
-
const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || pathParams || {});
|
|
53
|
-
const { rqopt, qss } = util.initOptions(method, actualOpt);
|
|
54
|
-
// @ts-expect-error actualy endp is string
|
|
55
|
-
const endpointUrl = util.curl(endpoint);
|
|
56
|
-
const up = new URLSearchParams(qss);
|
|
57
|
-
const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
|
|
58
|
-
DEBUG && log(url);
|
|
59
|
-
return fetch(url, rqopt).then(res => res.json()).catch(reason => {
|
|
60
|
-
throw new util.ESIRequesError(reason.message ? reason.message : reason);
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
//
|
|
64
|
-
// implements rest methods of `request` (IESIRequestFunction)
|
|
65
|
-
//
|
|
66
|
-
/** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
|
|
67
|
-
request[method] = /** @type {TESIRequestFunctionEachMethod<typeof method>} */ (function (endpoint, params, opt) {
|
|
68
|
-
return this(method, endpoint, params, opt);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
26
|
//
|
|
72
27
|
// Delegates implementation to `request` (TESIRequestFunctionMethods)
|
|
73
28
|
//
|
|
@@ -126,7 +81,9 @@ async function getEVEStatus(fn) {
|
|
|
126
81
|
}
|
|
127
82
|
// type following and run
|
|
128
83
|
// node minimal-rq.mjs -debug
|
|
129
|
-
|
|
84
|
+
if (!util.is("x")) {
|
|
85
|
+
getEVEStatus(request).then(eveStatus => log(eveStatus));
|
|
86
|
+
}
|
|
130
87
|
// {
|
|
131
88
|
// "players": 16503,
|
|
132
89
|
// "server_version": "2794925",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-esi-types",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"v2",
|
|
16
|
+
"lib",
|
|
16
17
|
"*.d.mts",
|
|
17
18
|
"*.mjs",
|
|
18
19
|
"LICENSE",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
},
|
|
37
38
|
"homepage": "https://github.com/jeffy-g/eve-esi-types#readme",
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"colors.ts": "^1.0.20"
|
|
40
|
+
"colors.ts": "^1.0.20",
|
|
41
|
+
"typescript": "latest"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/tagged-rq.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/tagged-rq.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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 tagged-rq.mts
|
|
10
|
+
* @command node tagged-rq.mjs -x
|
|
11
|
+
*/
|
|
12
|
+
import { esi as esiRq } from "./lib/tagged-request-api.mjs";
|
|
13
|
+
// console.log(esiRq);
|
|
14
|
+
// Furthermore, the endpoint selected is narrowed down by "tags" and "method".
|
|
15
|
+
esiRq.character.get("/characters/{character_id}/", 2112625428).then(console.log);
|
|
16
|
+
esiRq.universe.get("/universe/structures/", { query: { filter: "market" } }).then(console.log);
|
|
17
|
+
esiRq.universe.post("/universe/ids/", {
|
|
18
|
+
body: ["the forge", "plex"]
|
|
19
|
+
}).then(console.log);
|
|
20
|
+
esiRq.assets.get("/characters/{character_id}/assets/", 1234, {
|
|
21
|
+
auth: true
|
|
22
|
+
}).then(console.log).catch(console.log);
|
package/tsconfig.json
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"outDir": ".",
|
|
9
9
|
"target": "esnext",
|
|
10
10
|
"module": "esnext",
|
|
11
|
-
// "declaration": true,
|
|
12
11
|
"diagnostics": true,
|
|
13
12
|
"newLine": "LF",
|
|
14
13
|
"strict": true,
|
|
@@ -18,7 +17,8 @@
|
|
|
18
17
|
]
|
|
19
18
|
},
|
|
20
19
|
"include": [
|
|
21
|
-
"./scripts
|
|
20
|
+
"./scripts/**/*.mts",
|
|
21
|
+
"./v2/*.d.ts"
|
|
22
22
|
],
|
|
23
23
|
"exclude": [
|
|
24
24
|
"./scripts/auth-*",
|
|
@@ -0,0 +1,148 @@
|
|
|
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/esi-tagged-types.d.ts
|
|
12
|
+
* @summary This file is auto-generated and defines version 2.3.0 of the EVE Online ESI response types.
|
|
13
|
+
*/
|
|
14
|
+
import { TESIResponseOKMap } from "./index.d.ts";
|
|
15
|
+
export * from "./index.d.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a string to lower camel case.
|
|
19
|
+
*
|
|
20
|
+
* @template S - The string to convert.
|
|
21
|
+
* @example
|
|
22
|
+
* // returns "assets"
|
|
23
|
+
* LCamelCase<"Assets">
|
|
24
|
+
* @example
|
|
25
|
+
* // returns "factionWarfare"
|
|
26
|
+
* LCamelCase<"Faction Warfare">
|
|
27
|
+
* @date 2025/2/27
|
|
28
|
+
*/
|
|
29
|
+
export declare type LCamelCase<S extends string> = S extends `${infer P1} ${infer P2}`
|
|
30
|
+
? `${Lowercase<P1>}${Capitalize<P2>}` : Lowercase<S>;
|
|
31
|
+
|
|
32
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
33
|
+
// Utility Type `ESITags`
|
|
34
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
35
|
+
/**
|
|
36
|
+
* Maps HTTP methods to their corresponding tags.
|
|
37
|
+
* @template M - The HTTP method.
|
|
38
|
+
* @date 2025/2/28
|
|
39
|
+
*/
|
|
40
|
+
export declare type ESITags = {
|
|
41
|
+
[M in TESIEntryMethod]: TESIResponseOKMap[M] extends Record<`/${string}/`, { tag: infer Tag }>
|
|
42
|
+
? Tag : never
|
|
43
|
+
}[TESIEntryMethod];
|
|
44
|
+
|
|
45
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
46
|
+
// Utility Type `InferMethod`
|
|
47
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
48
|
+
/**
|
|
49
|
+
* Infers the HTTP method based on the provided tag.
|
|
50
|
+
*
|
|
51
|
+
* @template Tag - The tag to infer the method for.
|
|
52
|
+
* @date 2025/2/28
|
|
53
|
+
*/
|
|
54
|
+
export declare type InferMethod<Tag> = {
|
|
55
|
+
[M in TESIEntryMethod]: TESIResponseOKMap[M] extends Record<`/${string}/`, { tag: infer ActualTag }>
|
|
56
|
+
? ActualTag extends Tag
|
|
57
|
+
? M : never
|
|
58
|
+
: never;
|
|
59
|
+
}[TESIEntryMethod];
|
|
60
|
+
// type XAssets = InferMethod<"Assets">;
|
|
61
|
+
// type XContacts = InferMethod<"Contacts">;
|
|
62
|
+
// type XPlanetary = InferMethod<"Planetary Interaction">;
|
|
63
|
+
|
|
64
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
65
|
+
// Utility Type `TaggedEndpointRequestFunction`
|
|
66
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
67
|
+
/**
|
|
68
|
+
* Creates a function type for making requests to tagged endpoints.
|
|
69
|
+
*
|
|
70
|
+
* @template M - The HTTP method.
|
|
71
|
+
* @template Tag - The tag associated with the endpoint.
|
|
72
|
+
* @template ActualOpt - The actual options for the request.
|
|
73
|
+
* @template EP - The endpoint path.
|
|
74
|
+
* @template P2 - The path parameters.
|
|
75
|
+
* @template Opt - The request options.
|
|
76
|
+
* @template R - The response type.
|
|
77
|
+
*
|
|
78
|
+
* @param endpoint - The endpoint path.
|
|
79
|
+
* @param pathParams - The path parameters.
|
|
80
|
+
* @param options - The request options.
|
|
81
|
+
* @returns A promise that resolves to the response.
|
|
82
|
+
* @date 2025/2/28
|
|
83
|
+
*/
|
|
84
|
+
export declare type TaggedEndpointRequestFunction<M extends TESIEntryMethod, Tag extends ESITags, ActualOpt = {}> = <
|
|
85
|
+
EP extends SelectEndpointByTag<Tag, M>,
|
|
86
|
+
P2 extends IfParameterizedPath<EP, Opt>,
|
|
87
|
+
Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt>,
|
|
88
|
+
R extends InferESIResponseResult<M, EP>
|
|
89
|
+
>(endpoint: EP, pathParams?: P2, options?: Opt) => Promise<R>;
|
|
90
|
+
|
|
91
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
92
|
+
// Utility Type `ESITaggedEndpointRequest`
|
|
93
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
94
|
+
/**
|
|
95
|
+
* Maps tags to their corresponding endpoint request functions.
|
|
96
|
+
*
|
|
97
|
+
* @template Tag - The tag to map.
|
|
98
|
+
* @date 2025/2/28
|
|
99
|
+
*/
|
|
100
|
+
export declare type ESITaggedEndpointRequest<Tag extends ESITags> = {
|
|
101
|
+
[tag in Tag]: {
|
|
102
|
+
[method in InferMethod<Tag>]: TaggedEndpointRequestFunction<method, tag>;
|
|
103
|
+
};
|
|
104
|
+
}[Tag];
|
|
105
|
+
|
|
106
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
107
|
+
// Utility Type `SelectEndpointByTag`
|
|
108
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
109
|
+
/**
|
|
110
|
+
* Selects an endpoint by tag and method.
|
|
111
|
+
*
|
|
112
|
+
* @template Tag - The tag associated with the endpoint.
|
|
113
|
+
* @template M - The HTTP method.
|
|
114
|
+
* @template EP - The endpoint path.
|
|
115
|
+
* @date 2025/2/28
|
|
116
|
+
*/
|
|
117
|
+
export declare type SelectEndpointByTag<
|
|
118
|
+
Tag extends ESITags, M extends TESIEntryMethod
|
|
119
|
+
> = {
|
|
120
|
+
[EP in keyof TESIResponseOKMap[M]]: TESIResponseOKMap[M][EP] extends { tag: infer ActualTag }
|
|
121
|
+
? ActualTag extends Tag
|
|
122
|
+
? EP : never
|
|
123
|
+
: never;
|
|
124
|
+
}[keyof TESIResponseOKMap[M]];
|
|
125
|
+
// type XAssetsEndpointGet = SelectEndpointByTag<"Assets", "get">;
|
|
126
|
+
// type XAssetsEndpointPost = SelectEndpointByTag<"Assets", "post">;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Maps lower camel case tags to their corresponding endpoint request functions.
|
|
130
|
+
* @date 2025/2/28
|
|
131
|
+
*/
|
|
132
|
+
export declare type TaggedESIRequestMap = {
|
|
133
|
+
[tag in ESITags as LCamelCase<tag>]: ESITaggedEndpointRequest<tag>;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Creates a partial map of lower camel case tags to their corresponding endpoint request functions.
|
|
138
|
+
* ```ts
|
|
139
|
+
* // implements "factionWarfare", "wallet"
|
|
140
|
+
* const esiRq: XTaggedESIRequestMapPartial<"factionWarfare" | "wallet">;
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @template Props - The properties to require in the partial map.
|
|
144
|
+
* @date 2025/2/28
|
|
145
|
+
*/
|
|
146
|
+
export declare type TaggedESIRequestMapPartial<Props extends LCamelCase<ESITags>> = RequireThese<Partial<TaggedESIRequestMap>, Props>;
|
|
147
|
+
|
|
148
|
+
export as namespace XESI;
|
package/v2/index.d.ts
CHANGED
|
@@ -6,20 +6,15 @@
|
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
* THIS
|
|
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 2.
|
|
12
|
+
* @summary This file is auto-generated and defines version 2.3.0 of the EVE Online ESI response types.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import type { TESIResponseOKMap } from "./response-map.d.ts";
|
|
16
16
|
export type { TESIResponseOKMap } from "./response-map.d.ts";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* mark a specific property as `required`
|
|
20
|
-
*/
|
|
21
|
-
type RequireThese<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
22
|
-
|
|
23
18
|
/**
|
|
24
19
|
* Represents a function that can make ESI requests with various HTTP methods.
|
|
25
20
|
*
|
|
@@ -73,6 +68,11 @@ export type TESIRequestFunctionMethods<ActualOpt = {}> = {
|
|
|
73
68
|
|
|
74
69
|
declare global {
|
|
75
70
|
|
|
71
|
+
/**
|
|
72
|
+
* mark a specific property as `required`
|
|
73
|
+
*/
|
|
74
|
+
type RequireThese<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
75
|
+
|
|
76
76
|
/**
|
|
77
77
|
* ### ESI request function all in one signature
|
|
78
78
|
*
|
|
@@ -136,7 +136,7 @@ declare global {
|
|
|
136
136
|
//* ctt
|
|
137
137
|
type IdentifyParameters<
|
|
138
138
|
Entry, Opt,
|
|
139
|
-
Keys = Exclude<keyof Entry, "result">
|
|
139
|
+
Keys = Exclude<keyof Entry, "result" | "tag">
|
|
140
140
|
> = RequireThese<Opt, Keys> & Pick<Entry, Keys>;
|
|
141
141
|
/*/
|
|
142
142
|
type IdentifyParameters<
|