Skip to content

Commit bd7185c

Browse files
committed
feat: export buildClientParams function
1 parent 1a01aa5 commit bd7185c

File tree

9 files changed

+470
-0
lines changed

9 files changed

+470
-0
lines changed

.changeset/twenty-numbers-talk.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@hey-api/client-custom': minor
3+
'@hey-api/client-axios': minor
4+
'@hey-api/client-fetch': minor
5+
'@hey-api/client-core': minor
6+
'@hey-api/client-next': minor
7+
'@hey-api/client-nuxt': minor
8+
---
9+
10+
feat: export buildClientParams function

packages/client-axios/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type {
1313
export { createConfig } from './utils';
1414
export type { Auth, QuerySerializerOptions } from '@hey-api/client-core';
1515
export {
16+
buildClientParams,
1617
formDataBodySerializer,
1718
jsonBodySerializer,
1819
urlSearchParamsBodySerializer,
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import type { Config } from '../params';
4+
import { buildClientParams } from '../params';
5+
6+
describe('buildClientParams', () => {
7+
const scenarios: ReadonlyArray<{
8+
args: ReadonlyArray<unknown>;
9+
config: Config;
10+
description: string;
11+
params: Record<string, unknown>;
12+
}> = [
13+
{
14+
args: [1, 2, 3, 4],
15+
config: [
16+
{
17+
in: 'path',
18+
key: 'foo',
19+
},
20+
{
21+
in: 'query',
22+
key: 'bar',
23+
},
24+
{
25+
in: 'headers',
26+
key: 'baz',
27+
},
28+
{
29+
in: 'body',
30+
key: 'qux',
31+
},
32+
],
33+
description: 'positional arguments',
34+
params: {
35+
body: {
36+
qux: 4,
37+
},
38+
headers: {
39+
baz: 3,
40+
},
41+
path: {
42+
foo: 1,
43+
},
44+
query: {
45+
bar: 2,
46+
},
47+
},
48+
},
49+
{
50+
args: [
51+
{
52+
bar: 2,
53+
baz: 3,
54+
foo: 1,
55+
qux: 4,
56+
},
57+
],
58+
config: [
59+
{
60+
args: [
61+
{
62+
in: 'path',
63+
key: 'foo',
64+
},
65+
{
66+
in: 'query',
67+
key: 'bar',
68+
},
69+
{
70+
in: 'headers',
71+
key: 'baz',
72+
},
73+
{
74+
in: 'body',
75+
key: 'qux',
76+
},
77+
],
78+
},
79+
],
80+
description: 'flat arguments',
81+
params: {
82+
body: {
83+
qux: 4,
84+
},
85+
headers: {
86+
baz: 3,
87+
},
88+
path: {
89+
foo: 1,
90+
},
91+
query: {
92+
bar: 2,
93+
},
94+
},
95+
},
96+
{
97+
args: [
98+
1,
99+
2,
100+
{
101+
baz: 3,
102+
qux: 4,
103+
},
104+
],
105+
config: [
106+
{
107+
in: 'path',
108+
key: 'foo',
109+
},
110+
{
111+
in: 'query',
112+
key: 'bar',
113+
},
114+
{
115+
args: [
116+
{
117+
in: 'headers',
118+
key: 'baz',
119+
},
120+
{
121+
in: 'body',
122+
key: 'qux',
123+
},
124+
],
125+
},
126+
],
127+
description: 'mixed arguments',
128+
params: {
129+
body: {
130+
qux: 4,
131+
},
132+
headers: {
133+
baz: 3,
134+
},
135+
path: {
136+
foo: 1,
137+
},
138+
query: {
139+
bar: 2,
140+
},
141+
},
142+
},
143+
{
144+
args: [1, 2, 3, 4],
145+
config: [
146+
{
147+
in: 'path',
148+
key: 'foo',
149+
map: 'f_o_o',
150+
},
151+
{
152+
in: 'query',
153+
key: 'bar',
154+
map: 'b_a_r',
155+
},
156+
{
157+
in: 'headers',
158+
key: 'baz',
159+
map: 'b_a_z',
160+
},
161+
{
162+
in: 'body',
163+
key: 'qux',
164+
map: 'q_u_x',
165+
},
166+
],
167+
description: 'positional mapped arguments',
168+
params: {
169+
body: {
170+
q_u_x: 4,
171+
},
172+
headers: {
173+
b_a_z: 3,
174+
},
175+
path: {
176+
f_o_o: 1,
177+
},
178+
query: {
179+
b_a_r: 2,
180+
},
181+
},
182+
},
183+
{
184+
args: [
185+
{
186+
bar: 2,
187+
baz: 3,
188+
foo: 1,
189+
qux: 4,
190+
},
191+
],
192+
config: [
193+
{
194+
args: [
195+
{
196+
in: 'path',
197+
key: 'foo',
198+
map: 'f_o_o',
199+
},
200+
{
201+
in: 'query',
202+
key: 'bar',
203+
map: 'b_a_r',
204+
},
205+
{
206+
in: 'headers',
207+
key: 'baz',
208+
map: 'b_a_z',
209+
},
210+
{
211+
in: 'body',
212+
key: 'qux',
213+
map: 'q_u_x',
214+
},
215+
],
216+
},
217+
],
218+
description: 'flat mapped arguments',
219+
params: {
220+
body: {
221+
q_u_x: 4,
222+
},
223+
headers: {
224+
b_a_z: 3,
225+
},
226+
path: {
227+
f_o_o: 1,
228+
},
229+
query: {
230+
b_a_r: 2,
231+
},
232+
},
233+
},
234+
{
235+
args: [1],
236+
config: [
237+
{
238+
in: 'body',
239+
},
240+
],
241+
description: 'positional primitive body',
242+
params: {
243+
body: 1,
244+
},
245+
},
246+
{
247+
args: [
248+
{
249+
$body_qux: 4,
250+
$headers_baz: 3,
251+
$path_foo: 1,
252+
$query_bar: 2,
253+
},
254+
],
255+
config: [
256+
{
257+
allowExtra: {},
258+
},
259+
],
260+
description: 'namespace extra arguments',
261+
params: {
262+
body: {
263+
qux: 4,
264+
},
265+
headers: {
266+
baz: 3,
267+
},
268+
path: {
269+
foo: 1,
270+
},
271+
query: {
272+
bar: 2,
273+
},
274+
},
275+
},
276+
{
277+
args: [
278+
{
279+
bar: 2,
280+
baz: 3,
281+
foo: 1,
282+
qux: 4,
283+
},
284+
],
285+
config: [
286+
{
287+
allowExtra: {
288+
query: true,
289+
},
290+
},
291+
],
292+
description: 'slot extra arguments',
293+
params: {
294+
query: {
295+
bar: 2,
296+
baz: 3,
297+
foo: 1,
298+
qux: 4,
299+
},
300+
},
301+
},
302+
{
303+
args: [],
304+
config: [],
305+
description: 'strip empty slots',
306+
params: {},
307+
},
308+
];
309+
310+
it.each(scenarios)('$description', async ({ args, config, params }) => {
311+
expect(buildClientParams(args, config)).toEqual(params);
312+
});
313+
});

packages/client-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
jsonBodySerializer,
1111
urlSearchParamsBodySerializer,
1212
} from './bodySerializer';
13+
export { buildClientParams } from './params';
1314
export type {
1415
ArraySeparatorStyle,
1516
ArrayStyle,

0 commit comments

Comments
 (0)