Skip to content

Commit 06e8759

Browse files
chore(internal): move stringifyQuery implementation to internal function
1 parent 4e01aa5 commit 06e8759

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { APIResponseProps } from './internal/parse';
1111
import { getPlatformHeaders } from './internal/detect-platform';
1212
import * as Shims from './internal/shims';
1313
import * as Opts from './internal/request-options';
14-
import * as qs from './internal/qs';
14+
import { stringifyQuery } from './internal/utils/query';
1515
import { VERSION } from './version';
1616
import * as Errors from './core/error';
1717
import * as Pagination from './core/pagination';
@@ -333,8 +333,8 @@ export class Finch {
333333
return buildHeaders([{ Authorization }]);
334334
}
335335

336-
protected stringifyQuery(query: Record<string, unknown>): string {
337-
return qs.stringify(query, { arrayFormat: 'brackets' });
336+
protected stringifyQuery(query: object | Record<string, unknown>): string {
337+
return stringifyQuery(query);
338338
}
339339

340340
private getUserAgent(): string {
@@ -371,7 +371,7 @@ export class Finch {
371371
}
372372

373373
if (typeof query === 'object' && query && !Array.isArray(query)) {
374-
url.search = this.stringifyQuery(query as Record<string, unknown>);
374+
url.search = this.stringifyQuery(query);
375375
}
376376

377377
return url.toString();
@@ -835,7 +835,7 @@ export class Finch {
835835
) {
836836
return {
837837
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
838-
body: this.stringifyQuery(body as Record<string, unknown>),
838+
body: this.stringifyQuery(body),
839839
};
840840
} else {
841841
return this.#encoder({ body, headers });

src/internal/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './utils/env';
66
export * from './utils/log';
77
export * from './utils/uuid';
88
export * from './utils/sleep';
9+
export * from './utils/query';

src/internal/utils/query.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import * as qs from '../qs/stringify';
4+
5+
export function stringifyQuery(query: object | Record<string, unknown>) {
6+
return qs.stringify(query, { arrayFormat: 'brackets' });
7+
}

tests/stringifyQuery.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { Finch } from '@tryfinch/finch-api';
4-
5-
const { stringifyQuery } = Finch.prototype as any;
3+
import { stringifyQuery } from '@tryfinch/finch-api/internal/utils/query';
64

75
describe(stringifyQuery, () => {
86
for (const [input, expected] of [
@@ -15,7 +13,7 @@ describe(stringifyQuery, () => {
1513
'e=f',
1614
)}=${encodeURIComponent('g&h')}`,
1715
],
18-
]) {
16+
] as const) {
1917
it(`${JSON.stringify(input)} -> ${expected}`, () => {
2018
expect(stringifyQuery(input)).toEqual(expected);
2119
});

0 commit comments

Comments
 (0)