Skip to content

Commit a0969c4

Browse files
committed
fix(types): pass contextId as options
remove second param `contextId` for the types' methods and pass `contextId` inside optional `options` param
1 parent 235e72e commit a0969c4

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/types/types.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ describe('Hypercode Types API methods', () => {
2727
status: 200,
2828
});
2929

30-
const result = await hyper.types.string(
31-
'Who is the CEO of SpaceX?',
30+
const result = await hyper.types.string('Who is the CEO of SpaceX?', {
3231
contextId,
33-
);
32+
});
3433

3534
expect(typeof result.data).toBe('string');
3635
expect(result.data).toBe('Elon Musk');
@@ -72,7 +71,7 @@ describe('Hypercode Types API methods', () => {
7271

7372
const result = await hyper.types.string(
7473
'How many planets are in the Solar System?',
75-
contextId,
74+
{ contextId },
7675
);
7776

7877
expect(typeof result.data).toBe('number');
@@ -118,7 +117,7 @@ describe('Hypercode Types API methods', () => {
118117

119118
const result = await hyper.types.float(
120119
'How many billion years old is the universe?',
121-
contextId,
120+
{ contextId },
122121
);
123122

124123
expect(typeof result.data).toBe('number');
@@ -157,10 +156,9 @@ describe('Hypercode Types API methods', () => {
157156
status: 200,
158157
});
159158

160-
const result = await hyper.types.boolean(
161-
'Can cats see in the dark?',
159+
const result = await hyper.types.boolean('Can cats see in the dark?', {
162160
contextId,
163-
);
161+
});
164162

165163
expect(typeof result.data).toBe('boolean');
166164
expect(result.data).toBe(true);
@@ -204,7 +202,7 @@ describe('Hypercode Types API methods', () => {
204202

205203
const { data } = await hyper.types.datetime(
206204
'What is the date of the Apollo 11 moon landing?',
207-
contextId,
205+
{ contextId },
208206
);
209207

210208
expect(typeof data).toBe('string');

src/types/types.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ type allowedTypes =
1212
| 'boolean_array'
1313
| 'datetime_array';
1414

15+
type MethodParamsOptions = {
16+
contextId: string;
17+
};
18+
1519
export class Types {
1620
constructor(private readonly hyper: Hyper) {}
1721

@@ -40,51 +44,51 @@ export class Types {
4044
return res;
4145
}
4246

43-
async string(query: string, contextId?: string) {
47+
async string(query: string, options?: MethodParamsOptions) {
4448
const data = await this.makeRequest<string>({
4549
endpointType: 'string',
4650
query,
47-
contextId,
51+
contextId: options?.contextId,
4852
});
4953

5054
return data;
5155
}
5256

53-
async integer(query: string, contextId?: string) {
57+
async integer(query: string, options?: MethodParamsOptions) {
5458
const data = await this.makeRequest<number>({
5559
endpointType: 'integer',
5660
query,
57-
contextId,
61+
contextId: options?.contextId,
5862
});
5963

6064
return data;
6165
}
6266

63-
async float(query: string, contextId?: string) {
67+
async float(query: string, options?: MethodParamsOptions) {
6468
const data = await this.makeRequest<number>({
6569
endpointType: 'float',
6670
query,
67-
contextId,
71+
contextId: options?.contextId,
6872
});
6973

7074
return data;
7175
}
7276

73-
async boolean(query: string, contextId?: string) {
77+
async boolean(query: string, options?: MethodParamsOptions) {
7478
const data = await this.makeRequest<boolean>({
7579
endpointType: 'boolean',
7680
query,
77-
contextId,
81+
contextId: options?.contextId,
7882
});
7983

8084
return data;
8185
}
8286

83-
async datetime(query: string, contextId?: string) {
87+
async datetime(query: string, options?: MethodParamsOptions) {
8488
const data = await this.makeRequest<string>({
8589
endpointType: 'datetime',
8690
query,
87-
contextId,
91+
contextId: options?.contextId,
8892
});
8993

9094
return data;

0 commit comments

Comments
 (0)