-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypesense.d.ts
186 lines (162 loc) · 5.08 KB
/
typesense.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
declare module 'typesense' {
export interface Typesense {
Client: TypesenseClientCtor;
}
export interface TypesenseDocument {
id: string;
}
export type TypesenseClientCtor = new (options: TypesenseClientOptions) => TypesenseClient;
export interface Alias {
name: string;
collection_name: string;
}
export interface TypesenseCollection<T extends TypesenseDocument> {
retrieve(): Promise<CollectionSchema>;
delete(): Promise<CollectionSchema>;
documents(): {
create(document: T): Promise<T>;
upsert(document: Partial<T>): Promise<T>;
search(
params: TypesenseRawSearchParams & { group_by: string },
): Promise<TypesenseRawGroupedResponse<T>>;
search(params: TypesenseRawSearchParams): Promise<TypesenseRawResponse<T>>;
import(documents: T[], config?: { action: 'create' | 'update' | 'upsert' }): Promise<any>;
export(): Promise<T[]>;
delete(query: TypesenseRawSearchParams): Promise<{ num_deleted: number }>;
};
documents(
id: string,
): {
retrieve(): Promise<any>;
update(document: T): Promise<T>;
delete(): Promise<any>;
};
}
export interface TypesenseClient {
aliases(): {
upsert(name: string, config: { collection_name: string }): Promise<Alias>;
retrieve(): Promise<{ aliases: Alias[] }>;
};
aliases(
name: string,
): {
retrieve(): Promise<Alias>;
delete(): Promise<Alias>;
};
keys: (name?: string) => any;
collections(): {
create(schema: Omit<CollectionSchema, 'num_documents'>): Promise<CollectionSchema>;
retrieve(): Promise<CollectionSchema[]>;
};
collections<T extends TypesenseDocument>(name: string): TypesenseCollection<T>;
health: {
retrieve: () => { ok: boolean };
};
}
export interface TypesenseNodeConfig {
host: string;
port: number;
protocol: 'http' | 'https';
}
export interface TypesenseClientOptions {
nodes: TypesenseNodeConfig[];
apiKey: string;
numRetries?: number;
connectionTimeoutSeconds?: number;
logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
}
export type FieldType =
| 'string'
| 'int32'
| 'int64'
| 'float'
| 'bool'
| 'string[]'
| 'int32[]'
| 'int64[]'
| 'float[]'
| 'bool[]';
export interface FieldDefinition {
name: string;
type: FieldType;
optional?: boolean;
facet: boolean;
}
export interface CollectionSchema {
name: string;
num_documents: number;
fields: FieldDefinition[];
default_sorting_field: string;
}
/**
* Ref: https://typesense.org/docs/0.19.0/api/documents.html#arguments
*/
export interface TypesenseRawSearchParams {
q?: string;
query_by?: string;
query_by_weights?: string;
filter_by?: string;
sort_by?: string;
group_by?: string;
group_limit?: number;
prefix?: boolean;
facet_by?: string;
max_facet_values?: number;
facet_query?: string;
num_typos?: number;
page?: number;
per_page?: number;
include_fields?: string;
exclude_fields?: string;
highlight_full_fields?: string;
highlight_affix_num_tokens?: number;
highlight_start_tag?: string;
highlight_end_tag?: string;
snippet_threshold?: number;
drop_tokens_threshold?: number;
typo_tokens_threshold?: number;
pinned_hits?: string;
hidden_hits?: string;
limit_hits?: number;
}
export interface TypesenseRawResponseBase {
facet_counts: Array<{
counts: Array<{
count: number;
highlighted: string;
value: string;
}>;
field_name: string;
stats?: {
avg: number;
max: number;
min: number;
sum: number;
};
}>;
found: number;
out_of: number;
page: number;
request_params: Record<string, string>;
search_time_ms: number;
}
export interface HighlightData {
field: string;
matched_tokens: string[];
snippet: string;
}
export interface TypesenseHit<T extends TypesenseDocument> {
document: T;
highlights: HighlightData[];
text_match: number;
}
export interface TypesenseRawResponse<T extends TypesenseDocument> extends TypesenseRawResponseBase {
hits: Array<TypesenseHit<T>>;
}
export interface TypesenseRawGroupedResponse<T extends TypesenseDocument> extends TypesenseRawResponseBase {
grouped_hits: Array<{
group_key: string[];
hits: Array<TypesenseHit<T>>;
}>;
}
}