chore: bump version to 0.0.39 and enhance adapter to merge existing search parameters with body and params
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/query",
|
"name": "@kevisual/query",
|
||||||
"version": "0.0.38",
|
"version": "0.0.39",
|
||||||
"main": "dist/query-browser.js",
|
"main": "dist/query-browser.js",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -64,11 +64,15 @@ export const adapter = async (opts: AdapterOpts = {}, overloadOpts?: RequestInit
|
|||||||
url = new URL(opts.url, origin);
|
url = new URL(opts.url, origin);
|
||||||
}
|
}
|
||||||
const isGet = method === 'GET';
|
const isGet = method === 'GET';
|
||||||
|
const oldSearchParams = url.searchParams;
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
let searchParams = new URLSearchParams(opts.body as SimpleObject);
|
let searchParams = new URLSearchParams({ ...Object.fromEntries(oldSearchParams), ...opts.body } as SimpleObject);
|
||||||
url.search = searchParams.toString();
|
url.search = searchParams.toString();
|
||||||
} else {
|
} else {
|
||||||
const params = opts.params || {};
|
const params = {
|
||||||
|
...Object.fromEntries(oldSearchParams),
|
||||||
|
...opts.params,
|
||||||
|
}
|
||||||
const searchParams = new URLSearchParams(params as SimpleObject);
|
const searchParams = new URLSearchParams(params as SimpleObject);
|
||||||
if (typeof opts.body === 'object' && opts.body !== null) {
|
if (typeof opts.body === 'object' && opts.body !== null) {
|
||||||
// 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
|
// 浏览器环境下,自动将 body 中的 path 和 key 提取到查询参数中, 更容易排查问题
|
||||||
|
|||||||
Reference in New Issue
Block a user