Skip to content

Commit 1b0863b

Browse files
committed
Type refactor
1 parent bf5961d commit 1b0863b

21 files changed

+940
-893
lines changed

.gitignore

Lines changed: 123 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,130 @@
1+
# Logs
2+
logs
13
*.log
2-
.idea
3-
.DS_Store
4-
.cache
5-
node_modules
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
620

21+
# Coverage directory used by tools like istanbul
722
coverage
8-
lib
9-
esm5
10-
lib-esm
11-
esm2015
12-
lib-fesm
13-
fesm
14-
umd
15-
bundles
16-
typings
17-
types
18-
docs
19-
dist
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
2036

21-
## this is generated by `npm pack`
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
2266
*.tgz
23-
package
2467

68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port
105+
106+
# misc
107+
.DS_Store
108+
109+
# parcel
110+
.parcel_cache/
111+
112+
############################
113+
# CYPRESS
114+
############################
115+
cypress/screenshots
116+
cypress/videos
117+
cypress/support
118+
cypress/plugins
119+
cypress/fixtures
120+
121+
############################
122+
# MISC
123+
############################
124+
125+
.DS_Store
126+
dist
127+
package
25128
.vscode
129+
dist_default_export_in_index
130+
no_default_export_in_index

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"main": "./dist/bundles/meilisearch.umd.js",
2020
"module": "./dist/bundles/meilisearch.esm.js",
2121
"browser": "./dist/bundles/meilisearch.umd.js",
22-
"typings": "./dist/types/types.d.ts",
23-
"types": "./dist/types/types.d.ts",
22+
"typings": "./dist/types/index.d.ts",
23+
"types": "./dist/types/index.d.ts",
2424
"sideEffects": false,
2525
"repository": {
2626
"type": "git",

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const PLUGINS = [
2828
module.exports = [
2929
// browser-friendly UMD build
3030
{
31-
input: 'src/meilisearch.ts', // directory to transpilation of typescript
31+
input: 'src/index.ts', // directory to transpilation of typescript
3232
external: ['cross-fetch', 'cross-fetch/polyfill'],
3333
output: {
3434
name: 'window',
@@ -79,7 +79,7 @@ module.exports = [
7979
// an array for the `output` option, where we can specify
8080
// `file` and `format` for each target)
8181
{
82-
input: 'src/meilisearch.ts',
82+
input: 'src/index.ts',
8383
external: ['cross-fetch', 'cross-fetch/polyfill'],
8484
output: [
8585
{

scripts/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const a = [
2+
[
3+
[
4+
1,2,3,4
5+
]
6+
]
7+
]
8+
9+
10+
console.log(a)

src/errors/http-error-handler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import MeiliSearchCommunicationError from './meilisearch-communication-error'
2-
import MeiliSearchApiError from './meilisearch-api-error'
3-
import * as Types from '../types'
1+
import { MeiliSearchCommunicationError, MeiliSearchApiError } from './'
2+
import { FetchError } from '../types'
43

54
async function httpResponseErrorHandler(response: Response): Promise<Response> {
65
if (!response.ok) {
@@ -15,7 +14,7 @@ async function httpResponseErrorHandler(response: Response): Promise<Response> {
1514
return response
1615
}
1716

18-
function httpErrorHandler(response: Types.FetchError): Promise<void> {
17+
function httpErrorHandler(response: FetchError): Promise<void> {
1918
if (response.type !== 'MeiliSearchApiError') {
2019
throw new MeiliSearchCommunicationError(response.message, response)
2120
}

src/errors/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './http-error-handler'
2+
export * from './meilisearch-api-error'
3+
export * from './meilisearch-communication-error'
4+
export * from './meilisearch-error'
5+
export * from './meilisearch-timeout-error'

src/errors/meilisearch-api-error.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import * as Types from '../types'
1+
import { MSApiError, MeiliSearchApiErrorResponse } from '../types'
22

3-
const MeiliSearchApiError: Types.MSApiErrorConstructor = class
4-
extends Error
5-
implements Types.MSApiError {
3+
const MeiliSearchApiError = class extends Error implements MSApiError {
64
httpStatus: number
7-
response?: Types.MeiliSearchApiErrorResponse
5+
response?: MeiliSearchApiErrorResponse
86
errorCode?: string
97
errorType?: string
108
errorLink?: string
119
stack?: string
1210
type: string
1311

14-
constructor(error: Types.MSApiError, status: number) {
12+
constructor(error: MSApiError, status: number) {
1513
super(error.message)
1614
this.type = 'MeiliSearchApiError'
1715
this.name = 'MeiliSearchApiError'
@@ -27,4 +25,4 @@ const MeiliSearchApiError: Types.MSApiErrorConstructor = class
2725
}
2826
}
2927
}
30-
export default MeiliSearchApiError
28+
export { MeiliSearchApiError }

src/errors/meilisearch-communication-error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import 'cross-fetch/polyfill'
2-
import * as Types from '../types'
2+
import { FetchError } from '../types'
33

44
class MeiliSearchCommunicationError extends Error {
55
type: string
66
statusCode?: number
77
errno?: string
88
code?: string
99

10-
constructor(message: string, body: Response | Types.FetchError) {
10+
constructor(message: string, body: Response | FetchError) {
1111
super(message)
1212
this.name = 'MeiliSearchCommunicationError'
1313
this.type = 'MeiliSearchCommunicationError'
@@ -26,4 +26,4 @@ class MeiliSearchCommunicationError extends Error {
2626
}
2727
}
2828

29-
export default MeiliSearchCommunicationError
29+
export { MeiliSearchCommunicationError }

src/errors/meilisearch-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class MeiliSearchError extends Error {
1111
}
1212
}
1313

14-
export default MeiliSearchError
14+
export { MeiliSearchError }

src/errors/meilisearch-timeout-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class MeiliSearchTimeOutError extends Error {
1111
}
1212
}
1313

14-
export default MeiliSearchTimeOutError
14+
export { MeiliSearchTimeOutError }

0 commit comments

Comments
 (0)