Skip to content

Commit abfec4e

Browse files
chore(internal): move stringifyQuery implementation to internal function
1 parent 3a33fba commit abfec4e

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';
@@ -252,8 +252,8 @@ export class Arcade {
252252
return buildHeaders([{ Authorization: this.apiKey }]);
253253
}
254254

255-
protected stringifyQuery(query: Record<string, unknown>): string {
256-
return qs.stringify(query, { arrayFormat: 'comma' });
255+
protected stringifyQuery(query: object | Record<string, unknown>): string {
256+
return stringifyQuery(query);
257257
}
258258

259259
private getUserAgent(): string {
@@ -290,7 +290,7 @@ export class Arcade {
290290
}
291291

292292
if (typeof query === 'object' && query && !Array.isArray(query)) {
293-
url.search = this.stringifyQuery(query as Record<string, unknown>);
293+
url.search = this.stringifyQuery(query);
294294
}
295295

296296
return url.toString();
@@ -753,7 +753,7 @@ export class Arcade {
753753
) {
754754
return {
755755
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
756-
body: this.stringifyQuery(body as Record<string, unknown>),
756+
body: this.stringifyQuery(body),
757757
};
758758
} else {
759759
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: 'comma' });
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 { Arcade } from '@arcadeai/arcadejs';
4-
5-
const { stringifyQuery } = Arcade.prototype as any;
3+
import { stringifyQuery } from '@arcadeai/arcadejs/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)