Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to picoquery #3606

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"node-fetch-commonjs": "^3.3.2",
"openapi-path-templating": "^1.5.1",
"openapi-server-url-templating": "^1.0.0",
"qs": "^6.10.2",
"picoquery": "^1.4.0",
"ramda-adjunct": "^5.0.0",
"neotraverse": "=0.6.15"
},
Expand Down
17 changes: 13 additions & 4 deletions src/http/serializers/request/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import qs from 'qs';
import * as pq from 'picoquery';

import formatKeyValue from './format.js';
import { isFile, isArrayOfFile, FileWithData } from './file.js';

const PQ_OPTIONS = {
arrayRepeat: true,
arrayRepeatSyntax: 'repeat',
};

function stringifyQuery(obj) {
return decodeURIComponent(pq.stringify(obj, PQ_OPTIONS));
}

function buildFormData(reqForm) {
/**
* Build a new FormData instance, support array as field value
Expand Down Expand Up @@ -60,7 +69,7 @@ export function encodeFormOrQuery(data) {
return result;
}, {});

return qs.stringify(encodedQuery, { encode: false, indices: false }) || '';
return stringifyQuery(encodedQuery);
}

// If the request has a `query` object, merge it into the request.url, and delete the object
Expand Down Expand Up @@ -96,10 +105,10 @@ export function serializeRequest(req = {}) {
let newStr = '';

if (oriSearch) {
const oriQuery = qs.parse(oriSearch);
const oriQuery = pq.parse(oriSearch, PQ_OPTIONS);
const keysToRemove = Object.keys(query);
keysToRemove.forEach((key) => delete oriQuery[key]);
newStr = qs.stringify(oriQuery, { encode: true });
newStr = pq.stringify(oriQuery, PQ_OPTIONS);
}

const finalStr = joinSearch(newStr, encodeFormOrQuery(query));
Expand Down