@rivascva/dt-idl 1.1.8 → 1.1.9
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/dist/index.cjs.js +65 -35
- package/dist/index.d.ts +254 -38
- package/dist/index.esm.js +65 -35
- package/package.json +4 -4
- package/redocly.yaml +9 -0
- package/ts/services/dt-market-service.ts +468 -339
- package/ts/services/dt-trade-service.ts +374 -281
package/dist/index.esm.js
CHANGED
|
@@ -5,9 +5,7 @@ const DEFAULT_HEADERS = {
|
|
|
5
5
|
|
|
6
6
|
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Add custom parameters to Request object
|
|
10
|
-
*/
|
|
8
|
+
/** Add custom parameters to Request object */
|
|
11
9
|
class CustomRequest extends Request {
|
|
12
10
|
constructor(input, init) {
|
|
13
11
|
super(input, init);
|
|
@@ -21,6 +19,14 @@ class CustomRequest extends Request {
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Returns a cheap, non-cryptographically-secure random ID
|
|
24
|
+
* Courtesy of @imranbarbhuiya (https://github.com/imranbarbhuiya)
|
|
25
|
+
*/
|
|
26
|
+
function randomID() {
|
|
27
|
+
return Math.random().toString(36).slice(2, 11);
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* Create an openapi-fetch client.
|
|
26
32
|
* @type {import("./index.js").default}
|
|
@@ -45,7 +51,7 @@ function createClient(clientOptions) {
|
|
|
45
51
|
* @param {T} url
|
|
46
52
|
* @param {import('./index.js').FetchOptions<T>} fetchOptions
|
|
47
53
|
*/
|
|
48
|
-
async function coreFetch(
|
|
54
|
+
async function coreFetch(schemaPath, fetchOptions) {
|
|
49
55
|
const {
|
|
50
56
|
fetch = baseFetch,
|
|
51
57
|
headers,
|
|
@@ -78,30 +84,42 @@ function createClient(clientOptions) {
|
|
|
78
84
|
};
|
|
79
85
|
if (requestInit.body) {
|
|
80
86
|
requestInit.body = bodySerializer(requestInit.body);
|
|
87
|
+
// remove `Content-Type` if serialized body is FormData; browser will correctly set Content-Type & boundary expression
|
|
88
|
+
if (requestInit.body instanceof FormData) {
|
|
89
|
+
requestInit.headers.delete("Content-Type");
|
|
90
|
+
}
|
|
81
91
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
|
|
93
|
+
let id;
|
|
94
|
+
let options;
|
|
95
|
+
let request = new CustomRequest(createFinalURL(schemaPath, { baseUrl, params, querySerializer }), requestInit);
|
|
96
|
+
|
|
97
|
+
if (middlewares.length) {
|
|
98
|
+
id = randomID();
|
|
99
|
+
|
|
100
|
+
// middleware (request)
|
|
101
|
+
options = Object.freeze({
|
|
102
|
+
baseUrl,
|
|
103
|
+
fetch,
|
|
104
|
+
parseAs,
|
|
105
|
+
querySerializer,
|
|
106
|
+
bodySerializer,
|
|
107
|
+
});
|
|
108
|
+
for (const m of middlewares) {
|
|
109
|
+
if (m && typeof m === "object" && typeof m.onRequest === "function") {
|
|
110
|
+
const result = await m.onRequest({
|
|
111
|
+
request,
|
|
112
|
+
schemaPath,
|
|
113
|
+
params,
|
|
114
|
+
options,
|
|
115
|
+
id,
|
|
116
|
+
});
|
|
117
|
+
if (result) {
|
|
118
|
+
if (!(result instanceof Request)) {
|
|
119
|
+
throw new Error("onRequest: must return new Request() when modifying the request");
|
|
120
|
+
}
|
|
121
|
+
request = result;
|
|
103
122
|
}
|
|
104
|
-
request = result;
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
125
|
}
|
|
@@ -111,15 +129,24 @@ function createClient(clientOptions) {
|
|
|
111
129
|
|
|
112
130
|
// middleware (response)
|
|
113
131
|
// execute in reverse-array order (first priority gets last transform)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
132
|
+
if (middlewares.length) {
|
|
133
|
+
for (let i = middlewares.length - 1; i >= 0; i--) {
|
|
134
|
+
const m = middlewares[i];
|
|
135
|
+
if (m && typeof m === "object" && typeof m.onResponse === "function") {
|
|
136
|
+
const result = await m.onResponse({
|
|
137
|
+
request,
|
|
138
|
+
response,
|
|
139
|
+
schemaPath,
|
|
140
|
+
params,
|
|
141
|
+
options,
|
|
142
|
+
id,
|
|
143
|
+
});
|
|
144
|
+
if (result) {
|
|
145
|
+
if (!(result instanceof Response)) {
|
|
146
|
+
throw new Error("onResponse: must return new Response() when modifying the response");
|
|
147
|
+
}
|
|
148
|
+
response = result;
|
|
121
149
|
}
|
|
122
|
-
response = result;
|
|
123
150
|
}
|
|
124
151
|
}
|
|
125
152
|
}
|
|
@@ -397,7 +424,7 @@ function defaultPathSerializer(pathname, pathParams) {
|
|
|
397
424
|
nextURL = nextURL.replace(match, `;${serializePrimitiveParam(name, value)}`);
|
|
398
425
|
continue;
|
|
399
426
|
}
|
|
400
|
-
nextURL = nextURL.replace(match, style === "label" ? `.${value}` : value);
|
|
427
|
+
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
|
|
401
428
|
}
|
|
402
429
|
return nextURL;
|
|
403
430
|
}
|
|
@@ -407,6 +434,9 @@ function defaultPathSerializer(pathname, pathParams) {
|
|
|
407
434
|
* @type {import("./index.js").defaultBodySerializer}
|
|
408
435
|
*/
|
|
409
436
|
function defaultBodySerializer(body) {
|
|
437
|
+
if (body instanceof FormData) {
|
|
438
|
+
return body;
|
|
439
|
+
}
|
|
410
440
|
return JSON.stringify(body);
|
|
411
441
|
}
|
|
412
442
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivascva/dt-idl",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Dream Trade - Interface Definition Language",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"check": "tsc --noEmit",
|
|
10
10
|
"lint": "eslint .",
|
|
11
11
|
"lint:fix": "eslint . --fix",
|
|
12
|
-
"gen": "rimraf ts/services &&
|
|
12
|
+
"gen": "rimraf ts/services && openapi-typescript --redocly redocly.yaml",
|
|
13
13
|
"build": "rimraf dist && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript"
|
|
14
14
|
},
|
|
15
15
|
"homepage": "https://github.com/RivasCVA/dt-idl",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"eslint-config-prettier": "^9.1.0",
|
|
28
28
|
"eslint-plugin-import": "^2.29.1",
|
|
29
29
|
"eslint-plugin-prettier": "^5.1.3",
|
|
30
|
-
"openapi-typescript": "^
|
|
30
|
+
"openapi-typescript": "^7.2.0",
|
|
31
31
|
"rimraf": "^5.0.7",
|
|
32
32
|
"rollup": "^4.17.2",
|
|
33
33
|
"rollup-plugin-dts": "^6.1.1",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"typescript": "^5.4.5"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"openapi-fetch": "^0.
|
|
38
|
+
"openapi-fetch": "^0.10.5"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/redocly.yaml
ADDED