Comparing version 0.17.0 to 0.18.0
@@ -12,3 +12,3 @@ "use strict"; | ||
return props.reqBody | ||
? " data" + (props.reqBody.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqBody']," | ||
? " body" + (props.reqBody.hasQuestion ? '?' : '') + ": " + importName + "['" + method + "']['reqBody']," | ||
: ''; | ||
@@ -61,3 +61,3 @@ }; | ||
]; | ||
return indent + " " + name + ": " + tmpChanks[0] + "\n" + indent + " " + tmpChanks[1] + ",\n" + indent + " $" + name + ": async " + tmpChanks[0] + "\n" + indent + " (await " + tmpChanks[1] + ").data"; | ||
return indent + " " + name + ": " + tmpChanks[0] + "\n" + indent + " " + tmpChanks[1] + ",\n" + indent + " $" + name + ": async " + tmpChanks[0] + "\n" + indent + " (await " + tmpChanks[1] + ").body"; | ||
}) | ||
@@ -64,0 +64,0 @@ .join(',\n'); |
@@ -16,6 +16,11 @@ "use strict"; | ||
}; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs_1 = __importDefault(require("fs")); | ||
var path_1 = __importDefault(require("path")); | ||
var defaultConfig = { input: 'apis', baseURL: '', trailingSlash: false }; | ||
var defaultConfig = { | ||
input: (_a = ['apis', 'server/api', 'api'].find(function (input) { return fs_1.default.existsSync(input); })) !== null && _a !== void 0 ? _a : 'apis', | ||
baseURL: '', | ||
trailingSlash: false | ||
}; | ||
exports.default = (function (configPath) { | ||
@@ -22,0 +27,0 @@ if (configPath === void 0) { configPath = 'aspida.config.js'; } |
@@ -9,4 +9,4 @@ export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'PATCH' | 'OPTIONS'; | ||
headers?: any; | ||
httpBody?: any; | ||
body?: any; | ||
data?: any; | ||
config?: Config; | ||
@@ -18,3 +18,3 @@ }; | ||
originalResponse: any; | ||
data: T; | ||
body: T; | ||
}; | ||
@@ -24,3 +24,3 @@ export declare type AspidaParams<Config = any> = { | ||
headers?: any; | ||
data?: any; | ||
body?: any; | ||
config?: Config; | ||
@@ -27,0 +27,0 @@ }; |
@@ -86,12 +86,12 @@ "use strict"; | ||
exports.optionToRequest = function (option, type) { | ||
if (!(option === null || option === void 0 ? void 0 : option.data)) | ||
if (!(option === null || option === void 0 ? void 0 : option.body)) | ||
return option; | ||
var body; | ||
var httpBody; | ||
var headers = {}; | ||
switch (type) { | ||
case 'FormData': | ||
body = exports.dataToFormData(option.data); | ||
httpBody = exports.dataToFormData(option.body); | ||
break; | ||
case 'URLSearchParams': | ||
body = exports.dataToURLString(option.data); | ||
httpBody = exports.dataToURLString(option.body); | ||
headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; | ||
@@ -103,11 +103,11 @@ break; | ||
case 'any': | ||
body = option.data; | ||
httpBody = option.body; | ||
break; | ||
default: | ||
body = JSON.stringify(option.data); | ||
httpBody = JSON.stringify(option.body); | ||
headers['Content-Type'] = 'application/json;charset=utf-8'; | ||
break; | ||
} | ||
return __assign(__assign({ body: body }, option), { headers: __assign(__assign({}, headers), option.headers) }); | ||
return __assign(__assign({ httpBody: httpBody }, option), { headers: __assign(__assign({}, headers), option.headers) }); | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "aspida", | ||
"version": "0.17.0", | ||
"version": "0.18.0", | ||
"description": "TypeScript friendly HTTP client wrapper for the browser and node.js", | ||
@@ -5,0 +5,0 @@ "author": "Solufa <solufa2020@gmail.com>", |
@@ -20,4 +20,4 @@ | aspida | [aspida-mock] | [@aspida/axios] | [@aspida/ky] | [@aspida/fetch] | [@aspida/node-fetch] | | ||
</a> | ||
<a href="https://circleci.com/gh/aspidajs/aspida"> | ||
<img src="https://img.shields.io/circleci/build/github/aspidajs/aspida.svg?label=test" alt="CircleCI" /> | ||
<a href="https://github.com/aspidajs/aspida/actions?query=workflow%3A%22Node.js+CI%22"> | ||
<img src="https://github.com/aspidajs/aspida/workflows/Node.js%20CI/badge.svg?branch=master" alt="Node.js CI" /> | ||
</a> | ||
@@ -46,2 +46,20 @@ <a href="https://codecov.io/gh/aspidajs/aspida"> | ||
## Breaking change (2020/06/16) :warning: | ||
Since aspida >= `0.18.0` , the property `data` of the request and response has been changed to `body`. | ||
```typescript | ||
const { body } = await client.v1.users.post({ body: { name: "taro" } }) | ||
const body = await client.v1.users.$post({ body: { name: "taro" } }) | ||
``` | ||
### The modules affected by this change | ||
- @aspida/axios >= `0.8.0` | ||
- @aspida/ky >= `0.6.0` | ||
- @aspida/fetch >= `0.6.0` | ||
- @aspida/node-fetch >= `0.5.0` | ||
- openapi2aspida >= `0.8.0` | ||
## Features | ||
@@ -178,3 +196,3 @@ | ||
await client.v1.users.post({ data: { name: "taro" } }) | ||
await client.v1.users.post({ body: { name: "taro" } }) | ||
@@ -184,3 +202,3 @@ const res = await client.v1.users.get({ query: { limit } }) | ||
// req -> GET: /v1/users/?limit=10 | ||
// res -> { status: 200, data: [{ id: 0, name: 'taro' }], headers: {...} } | ||
// res -> { status: 200, body: [{ id: 0, name: 'taro' }], headers: {...} } | ||
@@ -333,3 +351,3 @@ const user = await client.v1.users._userId(userId).$get() | ||
const user = await client.v1.users.$post({ | ||
data: { | ||
body: { | ||
name: "taro", | ||
@@ -374,3 +392,3 @@ icon: imageBuffer | ||
const user = await client.v1.users.$post({ data: { name: "taro" } }) | ||
const user = await client.v1.users.$post({ body: { name: "taro" } }) | ||
console.log(user) | ||
@@ -433,2 +451,8 @@ // req -> POST: /v1/users | ||
## Support | ||
<a href="https://twitter.com/solufa2020"> | ||
<img src="https://aspidajs.github.io/aspida/assets/images/twitter.svg" width="65" alt="Twitter" /> | ||
</a> | ||
## License | ||
@@ -435,0 +459,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71649
786
460
1