Skip to content

Commit fdaa38b

Browse files
committed
Refactor interfaces to types
1 parent 1b0863b commit fdaa38b

29 files changed

+262
-263
lines changed

scripts/test.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/errors/http-error-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { MeiliSearchCommunicationError, MeiliSearchApiError } from './'
1+
import { MeiliSearchCommunicationError } from './meilisearch-communication-error'
2+
import { MeiliSearchApiError } from './meilisearch-api-error'
23
import { FetchError } from '../types'
34

45
async function httpResponseErrorHandler(response: Response): Promise<Response> {

src/errors/meilisearch-api-error.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { MSApiError, MeiliSearchApiErrorResponse } from '../types'
1+
import {
2+
MSApiError,
3+
MeiliSearchApiErrorResponse,
4+
MSApiErrorConstructor,
5+
} from '../types'
26

3-
const MeiliSearchApiError = class extends Error implements MSApiError {
7+
const MeiliSearchApiError: MSApiErrorConstructor = class
8+
extends Error
9+
implements MSApiError {
410
httpStatus: number
511
response?: MeiliSearchApiErrorResponse
612
errorCode?: string
@@ -19,10 +25,6 @@ const MeiliSearchApiError = class extends Error implements MSApiError {
1925
this.errorLink = error.errorLink
2026
this.message = error.message
2127
this.httpStatus = status
22-
23-
if (Error.captureStackTrace) {
24-
Error.captureStackTrace(this, MeiliSearchApiError)
25-
}
2628
}
2729
}
2830
export { MeiliSearchApiError }

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ export * from './types'
22
export * from './errors'
33
export * from './lib'
44

5-
// import { MeiliSearch } from './lib'
5+
import { MeiliSearch } from './lib'
6+
7+
export default MeiliSearch

src/lib/http-requests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
EnqueuedUpdate,
77
IndexResponse,
88
IndexOptions,
9-
httpResponseErrorHandler,
10-
httpErrorHandler,
11-
} from '../'
9+
} from '../types'
10+
11+
import { httpResponseErrorHandler, httpErrorHandler } from '../errors'
1212

1313
class HttpRequests {
1414
headers: {}

src/lib/indexes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
'use strict'
99

10+
import { MeiliSearchTimeOutError, MeiliSearchError } from '../errors'
11+
1012
import {
11-
MeiliSearchTimeOutError,
12-
MeiliSearchError,
1313
Config,
1414
Update,
1515
SearchResponse,
@@ -33,7 +33,7 @@ import {
3333
SortableAttributes,
3434
SearchableAttributes,
3535
DisplayedAttributes,
36-
} from '../'
36+
} from '../types'
3737
import { sleep, removeUndefinedFromObject } from './utils'
3838
import { HttpRequests } from './http-requests'
3939

src/lib/meilisearch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
'use strict'
99

1010
import { Index } from './indexes'
11+
import { MeiliSearchApiError } from '../errors'
1112
import {
12-
MeiliSearchApiError,
1313
Config,
1414
IndexOptions,
1515
IndexResponse,
@@ -18,10 +18,10 @@ import {
1818
Stats,
1919
Version,
2020
EnqueuedDump,
21-
} from '../'
21+
} from '../types'
2222
import { HttpRequests } from './http-requests'
2323

24-
export class MeiliSearch {
24+
class MeiliSearch {
2525
config: Config
2626
httpRequest: HttpRequests
2727

@@ -227,3 +227,5 @@ export class MeiliSearch {
227227
return await this.httpRequest.get<EnqueuedDump>(url)
228228
}
229229
}
230+
231+
export { MeiliSearch }

src/types/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ export type Version = {
249249
** ERROR HANDLER
250250
*/
251251

252+
export type MSApiErrorConstructor = new (
253+
error: MSApiError,
254+
status: number
255+
) => void
256+
252257
export type MeiliSearchApiErrorResponse = {
253258
status?: number
254259
statusText?: string

0 commit comments

Comments
 (0)