@ps-aux/api-client-axios 0.0.8-rc-6 → 0.0.9-rc-7
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/browser.esm.js +7 -4
- package/dist/browser.js +7 -4
- package/dist/node.esm.js +7 -4
- package/dist/node.js +7 -4
- package/dist/platform/browser.d.ts +3 -2
- package/dist/platform/node.d.ts +1 -0
- package/dist/platform/types.d.ts +1 -0
- package/package.json +4 -2
- package/src/AxiosOpenApiHttpClient.ts +6 -4
- package/src/platform/browser.ts +2 -0
- package/src/platform/node.ts +3 -0
- package/src/platform/types.ts +2 -0
- package/test/my.spec.ts +22 -0
package/dist/browser.esm.js
CHANGED
|
@@ -311,6 +311,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
311
311
|
const { query, type, body } = req;
|
|
312
312
|
const isBlobResponse = req.format === 'document';
|
|
313
313
|
const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
|
|
314
|
+
const headers = {};
|
|
315
|
+
if (type) {
|
|
316
|
+
headers['Content-Type'] = type;
|
|
317
|
+
}
|
|
314
318
|
return axios
|
|
315
319
|
.request({
|
|
316
320
|
method: req.method,
|
|
@@ -319,10 +323,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
319
323
|
// url: req.path,
|
|
320
324
|
...urlConverter(req),
|
|
321
325
|
data,
|
|
322
|
-
headers
|
|
323
|
-
|
|
324
|
-
},
|
|
325
|
-
responseType: isBlobResponse ? 'blob' : 'json',
|
|
326
|
+
headers,
|
|
327
|
+
responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
|
|
326
328
|
})
|
|
327
329
|
.then(r => {
|
|
328
330
|
const { data } = r;
|
|
@@ -353,6 +355,7 @@ class BrowserPlatFormHelper {
|
|
|
353
355
|
isFileList = (obj) => obj instanceof FileList;
|
|
354
356
|
// @ts-ignore
|
|
355
357
|
newFormData = () => new FormData();
|
|
358
|
+
getFileAxiosResponseType = () => 'blob';
|
|
356
359
|
}
|
|
357
360
|
|
|
358
361
|
const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
package/dist/browser.js
CHANGED
|
@@ -313,6 +313,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
313
313
|
const { query, type, body } = req;
|
|
314
314
|
const isBlobResponse = req.format === 'document';
|
|
315
315
|
const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
|
|
316
|
+
const headers = {};
|
|
317
|
+
if (type) {
|
|
318
|
+
headers['Content-Type'] = type;
|
|
319
|
+
}
|
|
316
320
|
return axios
|
|
317
321
|
.request({
|
|
318
322
|
method: req.method,
|
|
@@ -321,10 +325,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
321
325
|
// url: req.path,
|
|
322
326
|
...urlConverter(req),
|
|
323
327
|
data,
|
|
324
|
-
headers
|
|
325
|
-
|
|
326
|
-
},
|
|
327
|
-
responseType: isBlobResponse ? 'blob' : 'json',
|
|
328
|
+
headers,
|
|
329
|
+
responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
|
|
328
330
|
})
|
|
329
331
|
.then(r => {
|
|
330
332
|
const { data } = r;
|
|
@@ -355,6 +357,7 @@ class BrowserPlatFormHelper {
|
|
|
355
357
|
isFileList = (obj) => obj instanceof FileList;
|
|
356
358
|
// @ts-ignore
|
|
357
359
|
newFormData = () => new FormData();
|
|
360
|
+
getFileAxiosResponseType = () => 'blob';
|
|
358
361
|
}
|
|
359
362
|
|
|
360
363
|
const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
package/dist/node.esm.js
CHANGED
|
@@ -313,6 +313,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
313
313
|
const { query, type, body } = req;
|
|
314
314
|
const isBlobResponse = req.format === 'document';
|
|
315
315
|
const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
|
|
316
|
+
const headers = {};
|
|
317
|
+
if (type) {
|
|
318
|
+
headers['Content-Type'] = type;
|
|
319
|
+
}
|
|
316
320
|
return axios
|
|
317
321
|
.request({
|
|
318
322
|
method: req.method,
|
|
@@ -321,10 +325,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
321
325
|
// url: req.path,
|
|
322
326
|
...urlConverter(req),
|
|
323
327
|
data,
|
|
324
|
-
headers
|
|
325
|
-
|
|
326
|
-
},
|
|
327
|
-
responseType: isBlobResponse ? 'blob' : 'json',
|
|
328
|
+
headers,
|
|
329
|
+
responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
|
|
328
330
|
})
|
|
329
331
|
.then(r => {
|
|
330
332
|
const { data } = r;
|
|
@@ -365,6 +367,7 @@ class NodePlatFormHelper {
|
|
|
365
367
|
};
|
|
366
368
|
// @ts-ignore
|
|
367
369
|
newFormData = () => new NodeFormData();
|
|
370
|
+
getFileAxiosResponseType = () => 'arraybuffer';
|
|
368
371
|
}
|
|
369
372
|
|
|
370
373
|
const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
package/dist/node.js
CHANGED
|
@@ -315,6 +315,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
315
315
|
const { query, type, body } = req;
|
|
316
316
|
const isBlobResponse = req.format === 'document';
|
|
317
317
|
const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
|
|
318
|
+
const headers = {};
|
|
319
|
+
if (type) {
|
|
320
|
+
headers['Content-Type'] = type;
|
|
321
|
+
}
|
|
318
322
|
return axios
|
|
319
323
|
.request({
|
|
320
324
|
method: req.method,
|
|
@@ -323,10 +327,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
323
327
|
// url: req.path,
|
|
324
328
|
...urlConverter(req),
|
|
325
329
|
data,
|
|
326
|
-
headers
|
|
327
|
-
|
|
328
|
-
},
|
|
329
|
-
responseType: isBlobResponse ? 'blob' : 'json',
|
|
330
|
+
headers,
|
|
331
|
+
responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
|
|
330
332
|
})
|
|
331
333
|
.then(r => {
|
|
332
334
|
const { data } = r;
|
|
@@ -367,6 +369,7 @@ class NodePlatFormHelper {
|
|
|
367
369
|
};
|
|
368
370
|
// @ts-ignore
|
|
369
371
|
newFormData = () => new NodeFormData();
|
|
372
|
+
getFileAxiosResponseType = () => 'arraybuffer';
|
|
370
373
|
}
|
|
371
374
|
|
|
372
375
|
const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PlatformHelper } from './types';
|
|
2
2
|
export declare class BrowserPlatFormHelper implements PlatformHelper {
|
|
3
|
-
isFile: (obj: any) =>
|
|
3
|
+
isFile: (obj: any) => obj is File;
|
|
4
4
|
getFileAndName: (obj: any) => {
|
|
5
5
|
file: File;
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
|
-
isFileList: (obj: any) =>
|
|
8
|
+
isFileList: (obj: any) => obj is FileList;
|
|
9
9
|
newFormData: () => FormData;
|
|
10
|
+
getFileAxiosResponseType: () => "blob";
|
|
10
11
|
}
|
package/dist/platform/node.d.ts
CHANGED
package/dist/platform/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ps-aux/api-client-axios",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-rc-7",
|
|
4
4
|
"main": "dist/node.js",
|
|
5
5
|
"module": "dist/node.esm.js",
|
|
6
6
|
"browser": "dist/browser.esm.js",
|
|
7
7
|
"types": "dist/api-client-axios/src/node.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rollup -c",
|
|
10
|
+
"pub": "npm run build && npm --access public publish",
|
|
10
11
|
"dev": "rollup -c --watch",
|
|
11
|
-
"tc": "tsc"
|
|
12
|
+
"tc": "tsc",
|
|
13
|
+
"test": "jest"
|
|
12
14
|
},
|
|
13
15
|
"author": "",
|
|
14
16
|
"license": "ISC",
|
|
@@ -41,6 +41,10 @@ export const createHttpClient = (
|
|
|
41
41
|
const data =
|
|
42
42
|
type === ContentType.FormData ? convertToFormData(body, platform) : body
|
|
43
43
|
|
|
44
|
+
const headers: Record<string, string> = {}
|
|
45
|
+
if (type) {
|
|
46
|
+
headers['Content-Type'] = type
|
|
47
|
+
}
|
|
44
48
|
return axios
|
|
45
49
|
.request({
|
|
46
50
|
method: req.method,
|
|
@@ -49,10 +53,8 @@ export const createHttpClient = (
|
|
|
49
53
|
// url: req.path,
|
|
50
54
|
...urlConverter(req),
|
|
51
55
|
data,
|
|
52
|
-
headers
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
responseType: isBlobResponse ? 'blob' : 'json',
|
|
56
|
+
headers,
|
|
57
|
+
responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
|
|
56
58
|
})
|
|
57
59
|
.then(r => {
|
|
58
60
|
const { data } = r
|
package/src/platform/browser.ts
CHANGED
package/src/platform/node.ts
CHANGED
package/src/platform/types.ts
CHANGED
package/test/my.spec.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosApi } from '@ps-aux/api-client-api-testing/apis/axios/client'
|
|
2
|
+
import Axios from 'axios'
|
|
3
|
+
import { createHttpClient } from '../src/AxiosOpenApiHttpClient'
|
|
4
|
+
import { NodePlatFormHelper } from '../src/platform/node'
|
|
5
|
+
import { createHttpServer, MirroredReqRes } from '../../helpers/http-server'
|
|
6
|
+
|
|
7
|
+
const Api = (url: string) =>
|
|
8
|
+
new AxiosApi(createHttpClient(Axios.create({ baseURL: url }), new NodePlatFormHelper()))
|
|
9
|
+
|
|
10
|
+
it('test', async () => {
|
|
11
|
+
|
|
12
|
+
const server = createHttpServer()
|
|
13
|
+
const { url } = await server.start()
|
|
14
|
+
const api = Api(url)
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await api.app.getHello({ name: 'world' })
|
|
18
|
+
expect(server.lastRequest().url).toBe('/api/hello?name=world')
|
|
19
|
+
} finally {
|
|
20
|
+
await server.stop()
|
|
21
|
+
}
|
|
22
|
+
})
|