Skip to content

Commit 0c0a780

Browse files
chore(internal): move stringifyQuery implementation to internal function
1 parent 2622949 commit 0c0a780

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

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 Uploads from './core/uploads';
@@ -272,8 +272,8 @@ export class Hypeman {
272272
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
273273
}
274274

275-
protected stringifyQuery(query: Record<string, unknown>): string {
276-
return qs.stringify(query, { arrayFormat: 'comma' });
275+
protected stringifyQuery(query: object | Record<string, unknown>): string {
276+
return stringifyQuery(query);
277277
}
278278

279279
private getUserAgent(): string {
@@ -310,7 +310,7 @@ export class Hypeman {
310310
}
311311

312312
if (typeof query === 'object' && query && !Array.isArray(query)) {
313-
url.search = this.stringifyQuery(query as Record<string, unknown>);
313+
url.search = this.stringifyQuery(query);
314314
}
315315

316316
return url.toString();
@@ -749,7 +749,7 @@ export class Hypeman {
749749
) {
750750
return {
751751
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
752-
body: this.stringifyQuery(body as Record<string, unknown>),
752+
body: this.stringifyQuery(body),
753753
};
754754
} else {
755755
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 { Hypeman } from '@onkernel/hypeman';
4-
5-
const { stringifyQuery } = Hypeman.prototype as any;
3+
import { stringifyQuery } from '@onkernel/hypeman/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)