File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { Types } from './types' ;
2
+ import { Search } from './search' ;
2
3
3
4
const baseUrl = process . env . HYPER_BASE_URL || 'https://api.gethyper.ai/v1' ;
4
5
@@ -12,6 +13,7 @@ export class Hyper {
12
13
private readonly headers : Headers ;
13
14
14
15
readonly types = new Types ( this ) ;
16
+ readonly search = new Search ( this ) ;
15
17
16
18
constructor ( private readonly apiKey ?: string ) {
17
19
if ( ! apiKey ) {
@@ -36,7 +38,16 @@ export class Hyper {
36
38
} : {
37
39
endpoint : string ;
38
40
options ?: RequestInit ;
39
- } ) : Promise < { data : T | null ; error : string | null } > {
41
+ } ) : Promise <
42
+ | {
43
+ data : T ;
44
+ error : null ;
45
+ }
46
+ | {
47
+ data : null ;
48
+ error : string ;
49
+ }
50
+ > {
40
51
const res = await fetch ( `${ baseUrl } ${ endpoint } ` , options ) ;
41
52
42
53
if ( ! res . ok ) {
@@ -45,7 +56,7 @@ export class Hyper {
45
56
return { data : null , error } ;
46
57
}
47
58
48
- const { data } = ( await res . json ( ) ) as { data : T } ;
59
+ const data = ( await res . json ( ) ) as T ;
49
60
return { data, error : null } ;
50
61
}
51
62
Original file line number Diff line number Diff line change 1
1
import { Hyper } from '../hyper' ;
2
- import { MethodParamsOptions , SearchResultData } from './@types' ;
2
+ import type { MethodParamsOptions , SearchResultData } from './@types' ;
3
3
4
4
export class Search {
5
5
constructor ( private readonly hyper : Hyper ) { }
Original file line number Diff line number Diff line change @@ -36,12 +36,14 @@ export class Types {
36
36
? { query : query , context_id : contextId }
37
37
: { content : query } ;
38
38
39
- const res = await this . hyper . post < T > ( {
39
+ const res = await this . hyper . post < { data : T } > ( {
40
40
endpoint,
41
41
body : payload ,
42
42
} ) ;
43
43
44
- return res ;
44
+ if ( res . data ?. data ) return { data : res . data . data , error : null } ;
45
+
46
+ return { data : null , error : res . error } ;
45
47
}
46
48
47
49
async string ( query : string , options ?: MethodParamsOptions ) {
You can’t perform that action at this time.
0 commit comments