Skip to content

Commit 1155bc8

Browse files
committed
feat(jsodc): add JSDoc comments for Types
1 parent d81feb4 commit 1155bc8

File tree

3 files changed

+127
-4
lines changed

3 files changed

+127
-4
lines changed

src/types/@types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ export type AllowedTypes =
1111
| 'datetime_array';
1212

1313
export type MethodParamsOptions = {
14+
/**
15+
* The context ID to be used for the request, you can get all context IDs by calling `hyper.contexts.list()` and then using the `id` field from the response.
16+
*/
1417
contextId: string;
1518
};

src/types/types.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Hypercode Types API methods', () => {
7070

7171
describe('integer method', () => {
7272
it('should return correct integer for a count query', async () => {
73-
fetchMock.mockOnce(JSON.stringify({ data: 42 }), {
73+
fetchMock.mockOnce(JSON.stringify({ data: 8 }), {
7474
status: 200,
7575
});
7676

@@ -79,13 +79,13 @@ describe('Hypercode Types API methods', () => {
7979
);
8080

8181
expect(typeof result.data).toBe('number');
82-
expect(result.data).toBe(42);
82+
expect(result.data).toBe(8);
8383
});
8484

8585
it('should return correct integer for a count query with contextId', async () => {
8686
const contextId = 'context-456';
8787

88-
fetchMock.mockOnce(JSON.stringify({ data: 42 }), {
88+
fetchMock.mockOnce(JSON.stringify({ data: 8 }), {
8989
status: 200,
9090
});
9191

@@ -95,7 +95,7 @@ describe('Hypercode Types API methods', () => {
9595
);
9696

9797
expect(typeof result.data).toBe('number');
98-
expect(result.data).toBe(42);
98+
expect(result.data).toBe(8);
9999
expect(fetchMock).toHaveBeenLastCalledWith(
100100
fullEndpoint('integer'), // endpoint
101101
// body and headers

src/types/types.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ export class Types {
3737
return { data: null, error: res.error };
3838
}
3939

40+
/**
41+
*
42+
* @param {string} query - The query to be processed
43+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
44+
* @returns The result of the query as a string data type
45+
* @example
46+
* const { data, error } = await hyper.types.string(
47+
'Who is the CEO of SpaceX?',
48+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
49+
);
50+
* console.log(data); // Elon Musk
51+
*/
4052
async string(query: string, options?: MethodParamsOptions) {
4153
const data = await this.makeRequest<string>({
4254
endpointType: 'string',
@@ -47,6 +59,18 @@ export class Types {
4759
return data;
4860
}
4961

62+
/**
63+
*
64+
* @param {string} query - The query to be processed
65+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
66+
* @returns The result of the query as an integer data type
67+
* @example
68+
* const { data, error } = await hyper.types.integer(
69+
'How many planets are in the Solar System?',
70+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
71+
);
72+
* console.log(data); // 8
73+
*/
5074
async integer(query: string, options?: MethodParamsOptions) {
5175
const data = await this.makeRequest<number>({
5276
endpointType: 'integer',
@@ -57,6 +81,18 @@ export class Types {
5781
return data;
5882
}
5983

84+
/**
85+
*
86+
* @param {string} query - The query to be processed
87+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
88+
* @returns The result of the query as a float data type
89+
* @example
90+
* const { data, error } = await hyper.types.float(
91+
'How many billion years old is the universe?',
92+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
93+
);
94+
* console.log(data); // 13.8
95+
*/
6096
async float(query: string, options?: MethodParamsOptions) {
6197
const data = await this.makeRequest<number>({
6298
endpointType: 'float',
@@ -67,6 +103,18 @@ export class Types {
67103
return data;
68104
}
69105

106+
/**
107+
*
108+
* @param {string} query - The query to be processed
109+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
110+
* @returns The result of the query as a boolean data type
111+
* @example
112+
* const { data, error } = await hyper.types.boolean(
113+
'Can cats see in the dark?',
114+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
115+
);
116+
* console.log(data); // true
117+
*/
70118
async boolean(query: string, options?: MethodParamsOptions) {
71119
const data = await this.makeRequest<boolean>({
72120
endpointType: 'boolean',
@@ -77,6 +125,18 @@ export class Types {
77125
return data;
78126
}
79127

128+
/**
129+
*
130+
* @param {string} query - The query to be processed
131+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
132+
* @returns The result of the query as a datetime data type
133+
* @example
134+
* const { data, error } = await hyper.types.datetime(
135+
'What is the date of the Apollo 11 moon landing?',
136+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
137+
);
138+
* console.log(data); // '1969-07-20T20:17:00Z'
139+
*/
80140
async datetime(query: string, options?: MethodParamsOptions) {
81141
const data = await this.makeRequest<string>({
82142
endpointType: 'datetime',
@@ -87,6 +147,18 @@ export class Types {
87147
return data;
88148
}
89149

150+
/**
151+
*
152+
* @param {string} query - The query to be processed
153+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
154+
* @returns The result of the query as a array of strings
155+
* @example
156+
* const { data, error } = await hyper.types.stringArray(
157+
'List all department names',
158+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
159+
);
160+
* console.log(data); // ['Human Resources', 'Finance', 'Research and Development', 'Sales', 'Customer Support']
161+
*/
90162
async stringArray(query: string, options?: MethodParamsOptions) {
91163
const data = await this.makeRequest<string[]>({
92164
endpointType: 'string_array',
@@ -97,6 +169,18 @@ export class Types {
97169
return data;
98170
}
99171

172+
/**
173+
*
174+
* @param {string} query - The query to be processed
175+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
176+
* @returns The result of the query as a array of integers
177+
* @example
178+
* const { data, error } = await hyper.types.integerArray(
179+
'What is the headcount for each department?',
180+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
181+
);
182+
* console.log(data); // [25, 40, 15, 50, 30]
183+
*/
100184
async integerArray(query: string, options?: MethodParamsOptions) {
101185
const data = await this.makeRequest<number[]>({
102186
endpointType: 'integer_array',
@@ -107,6 +191,18 @@ export class Types {
107191
return data;
108192
}
109193

194+
/**
195+
*
196+
* @param {string} query - The query to be processed
197+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
198+
* @returns The result of the query as a array of floats
199+
* @example
200+
* const { data, error } = await hyper.types.floatArray(
201+
'What were the customer satisfaction ratings from the last survey?',
202+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
203+
);
204+
* console.log(data); // [4.2, 3.8, 4.5, 4.7, 3.9]
205+
*/
110206
async floatArray(query: string, options?: MethodParamsOptions) {
111207
const data = await this.makeRequest<number[]>({
112208
endpointType: 'float_array',
@@ -117,6 +213,18 @@ export class Types {
117213
return data;
118214
}
119215

216+
/**
217+
*
218+
* @param {string} query - The query to be processed
219+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
220+
* @returns The result of the query as a array of booleans
221+
* @example
222+
* const { data, error } = await hyper.types.booleanArray(
223+
'Are services meeting performance targets?',
224+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
225+
);
226+
* console.log(data); // [true, false, true, true, false]
227+
*/
120228
async booleanArray(query: string, options?: MethodParamsOptions) {
121229
const data = await this.makeRequest<boolean[]>({
122230
endpointType: 'boolean_array',
@@ -127,6 +235,18 @@ export class Types {
127235
return data;
128236
}
129237

238+
/**
239+
*
240+
* @param {string} query - The query to be processed
241+
* @param {MethodParamsOptions} options - Optional parameters to be passed to the request, such as `contextId`
242+
* @returns The result of the query as a array of datetime strings
243+
* @example
244+
* const { data, error } = await hyper.types.datetimeArray(
245+
'What are the upcoming project deadlines?',
246+
{ contextId: '123e4567-e89b-12d3-a456-426614174000' },
247+
);
248+
* console.log(data); // ['2023-11-15T17:00:00Z', '2023-12-01T17:00:00Z', '2023-12-20T17:00:00Z']
249+
*/
130250
async datetimeArray(query: string, options?: MethodParamsOptions) {
131251
const data = await this.makeRequest<string[]>({
132252
endpointType: 'datetime_array',

0 commit comments

Comments
 (0)