/
index.ts
179 lines (147 loc) · 3.26 KB
/
index.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
/*
* Bundle: Meili
* Project: Meili - Javascript API
* Author: Quentin de Quelen <quentin@meilisearch.com>
* Copyright: 2019, Meili
*/
'use strict'
import instance, { AxiosInstance } from 'axios'
import { Indexes } from './indexes'
import * as Types from './types'
interface Config {
host: string
apiKey?: string
}
class Meili {
baseURL: string
apiKey?: string
instance: AxiosInstance
constructor(config: Config) {
this.baseURL = config.host
this.apiKey = config.apiKey
if (config.apiKey) {
this.instance = instance.create({
baseURL: this.baseURL,
timeout: 1000,
headers: {
'X-Meili-API-Key': config.apiKey,
},
})
} else {
this.instance = instance.create({
baseURL: this.baseURL,
timeout: 1000,
})
}
this.instance.interceptors.response.use((response) => response.data)
}
/**
* Return an Index instance
* @memberof Meili
* @method Index
*/
Index(indexUid: string): Indexes {
return new Indexes(this.instance, indexUid)
}
/**
* List all indexes in the database
* @memberof Meili
* @method listIndexes
*/
listIndexes(): Promise<object[]> {
const url = '/indexes'
return this.instance.get(url)
}
/**
* Create a new index with am optional schema
* @memberof Meili
* @method createIndex
*/
createIndex(
data: Types.CreateIndexRequest
): Promise<Types.CreateIndexResponse> {
const url = `/indexes`
return this.instance.post(url, data)
}
///
/// HEALTH
///
/**
* Check if the server is healhty
* @memberof Admin
* @method isHealthy
*/
isHealthy(): Promise<void> {
const url = '/health'
return this.instance.get(url)
}
/**
* Change the healthyness to healthy
* @memberof Admin
* @method setHealthy
*/
setHealthy(): Promise<void> {
const url = '/health'
return this.instance.post(url)
}
/**
* Change the healthyness to unhealthy
* @memberof Admin
* @method setUnhealthy
*/
setUnhealthy(): Promise<void> {
const url = '/health'
return this.instance.delete(url)
}
/**
* Change the healthyness to unhealthy
* @memberof Admin
* @method setUnhealthy
*/
changeHealthTo(health: boolean): Promise<void> {
const url = '/health'
return this.instance.put(url, {
health,
})
}
///
/// STATS
///
/**
* Get the stats of all the database
* @memberof Admin
* @method databaseStats
*/
databaseStats(): Promise<object> {
const url = '/stats'
return this.instance.get(url)
}
/**
* Get the version of the server
* @memberof Admin
* @method version
*/
version(): Promise<object> {
const url = '/version'
return this.instance.get(url)
}
/**
* Get the server consuption, RAM / CPU / Network
* @memberof Admin
* @method systemInformation
*/
systemInformation(): Promise<object> {
const url = '/sys-info'
return this.instance.get(url)
}
/**
* Get the server consuption, RAM / CPU / Network. All information as human readable
* @memberof Admin
* @method systemInformationPretty
*/
systemInformationPretty(): Promise<object> {
const url = '/sys-info/pretty'
return this.instance.get(url)
}
}
export default Meili