Skip to content

Commit

Permalink
Type refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa committed Sep 21, 2021
1 parent bf5961d commit 1b0863b
Show file tree
Hide file tree
Showing 21 changed files with 940 additions and 893 deletions.
141 changes: 123 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,130 @@
# Logs
logs
*.log
.idea
.DS_Store
.cache
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
lib
esm5
lib-esm
esm2015
lib-fesm
fesm
umd
bundles
typings
types
docs
dist
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

## this is generated by `npm pack`
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz
package

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# misc
.DS_Store

# parcel
.parcel_cache/

############################
# CYPRESS
############################
cypress/screenshots
cypress/videos
cypress/support
cypress/plugins
cypress/fixtures

############################
# MISC
############################

.DS_Store
dist
package
.vscode
dist_default_export_in_index
no_default_export_in_index
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"main": "./dist/bundles/meilisearch.umd.js",
"module": "./dist/bundles/meilisearch.esm.js",
"browser": "./dist/bundles/meilisearch.umd.js",
"typings": "./dist/types/types.d.ts",
"types": "./dist/types/types.d.ts",
"typings": "./dist/types/index.d.ts",
"types": "./dist/types/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PLUGINS = [
module.exports = [
// browser-friendly UMD build
{
input: 'src/meilisearch.ts', // directory to transpilation of typescript
input: 'src/index.ts', // directory to transpilation of typescript
external: ['cross-fetch', 'cross-fetch/polyfill'],
output: {
name: 'window',
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = [
// an array for the `output` option, where we can specify
// `file` and `format` for each target)
{
input: 'src/meilisearch.ts',
input: 'src/index.ts',
external: ['cross-fetch', 'cross-fetch/polyfill'],
output: [
{
Expand Down
10 changes: 10 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const a = [
[
[
1,2,3,4
]
]
]


console.log(a)
7 changes: 3 additions & 4 deletions src/errors/http-error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MeiliSearchCommunicationError from './meilisearch-communication-error'
import MeiliSearchApiError from './meilisearch-api-error'
import * as Types from '../types'
import { MeiliSearchCommunicationError, MeiliSearchApiError } from './'
import { FetchError } from '../types'

async function httpResponseErrorHandler(response: Response): Promise<Response> {
if (!response.ok) {
Expand All @@ -15,7 +14,7 @@ async function httpResponseErrorHandler(response: Response): Promise<Response> {
return response
}

function httpErrorHandler(response: Types.FetchError): Promise<void> {
function httpErrorHandler(response: FetchError): Promise<void> {
if (response.type !== 'MeiliSearchApiError') {
throw new MeiliSearchCommunicationError(response.message, response)
}
Expand Down
5 changes: 5 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './http-error-handler'
export * from './meilisearch-api-error'
export * from './meilisearch-communication-error'
export * from './meilisearch-error'
export * from './meilisearch-timeout-error'
12 changes: 5 additions & 7 deletions src/errors/meilisearch-api-error.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as Types from '../types'
import { MSApiError, MeiliSearchApiErrorResponse } from '../types'

const MeiliSearchApiError: Types.MSApiErrorConstructor = class
extends Error
implements Types.MSApiError {
const MeiliSearchApiError = class extends Error implements MSApiError {
httpStatus: number
response?: Types.MeiliSearchApiErrorResponse
response?: MeiliSearchApiErrorResponse
errorCode?: string
errorType?: string
errorLink?: string
stack?: string
type: string

constructor(error: Types.MSApiError, status: number) {
constructor(error: MSApiError, status: number) {
super(error.message)
this.type = 'MeiliSearchApiError'
this.name = 'MeiliSearchApiError'
Expand All @@ -27,4 +25,4 @@ const MeiliSearchApiError: Types.MSApiErrorConstructor = class
}
}
}
export default MeiliSearchApiError
export { MeiliSearchApiError }
6 changes: 3 additions & 3 deletions src/errors/meilisearch-communication-error.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'cross-fetch/polyfill'
import * as Types from '../types'
import { FetchError } from '../types'

class MeiliSearchCommunicationError extends Error {
type: string
statusCode?: number
errno?: string
code?: string

constructor(message: string, body: Response | Types.FetchError) {
constructor(message: string, body: Response | FetchError) {
super(message)
this.name = 'MeiliSearchCommunicationError'
this.type = 'MeiliSearchCommunicationError'
Expand All @@ -26,4 +26,4 @@ class MeiliSearchCommunicationError extends Error {
}
}

export default MeiliSearchCommunicationError
export { MeiliSearchCommunicationError }
2 changes: 1 addition & 1 deletion src/errors/meilisearch-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class MeiliSearchError extends Error {
}
}

export default MeiliSearchError
export { MeiliSearchError }
2 changes: 1 addition & 1 deletion src/errors/meilisearch-timeout-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class MeiliSearchTimeOutError extends Error {
}
}

export default MeiliSearchTimeOutError
export { MeiliSearchTimeOutError }
Loading

0 comments on commit 1b0863b

Please sign in to comment.