Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code style after configuration changes #1638

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"size": "node scripts/file-size ./dist/bundles/meilisearch.esm.min.js ./dist/bundles/meilisearch.umd.min.js",
"style": "yarn fmt && yarn lint",
"style:fix": "yarn fmt:fix && yarn lint:fix",
"fmt": "prettier -c ./**/*.{js,ts,tsx}",
"fmt:fix": "prettier -w ./**/*.{js,ts,tsx}",
"fmt": "prettier -c ./**/*.{js,ts}",
"fmt:fix": "prettier -w ./**/*.{js,ts}",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
"typingsheader": "node scripts/build.js"
Expand Down
6 changes: 1 addition & 5 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* This file only purpose is to execute any build related tasks
*/
/** This file only purpose is to execute any build related tasks */

const { resolve, normalize } = require('path')
const { readFileSync, writeFileSync } = require('fs')
Expand Down Expand Up @@ -28,7 +26,6 @@ function writeDtsHeader() {
}

/**
*
* @param {string} pkgName
* @param {string} version
* @param {string} author
Expand All @@ -49,7 +46,6 @@ function getDtsHeader(pkgName, version, author, repoUrl, tsVersion) {
}

/**
*
* @param {string} path
* @param {string | Blob} data
*/
Expand Down
5 changes: 1 addition & 4 deletions scripts/file-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async function main() {
}

/**
*
* @param {string} pkgName
* @param {string[]} filesOutput
*/
Expand All @@ -49,7 +48,6 @@ function getFormatedOutput(pkgName, filesOutput) {
}

/**
*
* @param {number} size
* @param {string} filename
* @param {'br' | 'gz'} type
Expand All @@ -66,10 +64,9 @@ function formatSize(size, filename, type, raw) {
}

/**
*
* @param {string} code
* @param {string} filename
* @param {boolean} [raw=false]
* @param {boolean} [raw=false] Default is `false`
*/
async function getSizeInfo(code, filename, raw = false) {
const isRaw = raw || code.length < 5000
Expand Down
11 changes: 7 additions & 4 deletions src/http-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ function constructHostURL(host: string): string {

function cloneAndParseHeaders(headers: HeadersInit): Record<string, string> {
if (Array.isArray(headers)) {
return headers.reduce((acc, headerPair) => {
acc[headerPair[0]] = headerPair[1]
return acc
}, {} as Record<string, string>)
return headers.reduce(
(acc, headerPair) => {
acc[headerPair[0]] = headerPair[1]
return acc
},
{} as Record<string, string>
)
} else if ('has' in headers) {
const clonedHeaders: Record<string, string> = {}
;(headers as Headers).forEach((value, key) => (clonedHeaders[key] = value))
Expand Down
4 changes: 2 additions & 2 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
*/
async search<
D extends Record<string, any> = T,
S extends SearchParams = SearchParams
S extends SearchParams = SearchParams,
>(
query?: string | null,
options?: S,
Expand All @@ -118,7 +118,7 @@ class Index<T extends Record<string, any> = Record<string, any>> {
*/
async searchGet<
D extends Record<string, any> = T,
S extends SearchParams = SearchParams
S extends SearchParams = SearchParams,
>(
query?: string | null,
options?: S,
Expand Down
10 changes: 6 additions & 4 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ class TaskClient {
while (Date.now() - startingTime < timeOutMs) {
const response = await this.getTask(taskUid)
if (
!([
TaskStatus.TASK_ENQUEUED,
TaskStatus.TASK_PROCESSING,
] as readonly string[]).includes(response.status)
!(
[
TaskStatus.TASK_ENQUEUED,
TaskStatus.TASK_PROCESSING,
] as readonly string[]
).includes(response.status)
)
return response
await sleep(intervalMs)
Expand Down
20 changes: 11 additions & 9 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export const MatchingStrategies = {
LAST: 'last',
} as const

export type MatchingStrategies = typeof MatchingStrategies[keyof typeof MatchingStrategies]
export type MatchingStrategies =
(typeof MatchingStrategies)[keyof typeof MatchingStrategies]

export type Filter = string | Array<string | string[]>

Expand Down Expand Up @@ -207,7 +208,7 @@ export type FacetStats = Record<string, FacetStat>

export type SearchResponse<
T = Record<string, any>,
S extends SearchParams | undefined = undefined
S extends SearchParams | undefined = undefined,
> = {
hits: Hits<T>
processingTimeMs: number
Expand All @@ -218,8 +219,8 @@ export type SearchResponse<
} & (undefined extends S
? Partial<FinitePagination & InfinitePagination>
: true extends IsFinitePagination<NonNullable<S>>
? FinitePagination
: InfinitePagination)
? FinitePagination
: InfinitePagination)

type FinitePagination = {
totalHits: number
Expand All @@ -241,8 +242,8 @@ type IsFinitePagination<S extends SearchParams> = Or<
type Or<A extends boolean, B extends boolean> = true extends A
? true
: true extends B
? true
: false
? true
: false

type HasHitsPerPage<S extends SearchParams> = undefined extends S['hitsPerPage']
? false
Expand Down Expand Up @@ -403,7 +404,7 @@ export const TaskStatus = {
TASK_CANCELED: 'canceled',
} as const

export type TaskStatus = typeof TaskStatus[keyof typeof TaskStatus]
export type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus]

export const TaskTypes = {
DOCUMENTS_ADDITION_OR_UPDATE: 'documentAdditionOrUpdate',
Expand All @@ -419,7 +420,7 @@ export const TaskTypes = {
TASK_DELETION: 'taskDeletion',
} as const

export type TaskTypes = typeof TaskTypes[keyof typeof TaskTypes]
export type TaskTypes = (typeof TaskTypes)[keyof typeof TaskTypes]

export type TasksQuery = {
indexUids?: string[]
Expand Down Expand Up @@ -972,7 +973,8 @@ export const ErrorStatusCode = {
INVALID_FACET_SEARCH_FACET_QUERY: 'invalid_facet_search_facet_query',
}

export type ErrorStatusCode = typeof ErrorStatusCode[keyof typeof ErrorStatusCode]
export type ErrorStatusCode =
(typeof ErrorStatusCode)[keyof typeof ErrorStatusCode]

export type TokenIndexRules = {
[field: string]: any
Expand Down
16 changes: 10 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/** Removes undefined entries from object */
function removeUndefinedFromObject(obj: Record<string, any>): object {
return Object.entries(obj).reduce((acc, curEntry) => {
const [key, val] = curEntry
if (val !== undefined) acc[key] = val
return acc
}, {} as Record<string, any>)
return Object.entries(obj).reduce(
(acc, curEntry) => {
const [key, val] = curEntry
if (val !== undefined) acc[key] = val
return acc
},
{} as Record<string, any>
)
}

async function sleep(ms: number): Promise<void> {
Expand All @@ -26,7 +29,8 @@ function addTrailingSlash(url: string): string {
}

function validateUuid4(uuid: string): boolean {
const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi
const regexExp =
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi
return regexExp.test(uuid)
}

Expand Down
10 changes: 6 additions & 4 deletions tests/utils/meilisearch-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ async function getKey(permission: string): Promise<string> {
const { results: keys } = await masterClient.getKeys()

if (permission === 'Search') {
const key = keys.find((key: any) => key.name === 'Default Search API Key')
?.key
const key = keys.find(
(key: any) => key.name === 'Default Search API Key'
)?.key
return key || ''
}

if (permission === 'Admin') {
const key = keys.find((key: any) => key.name === 'Default Admin API Key')
?.key
const key = keys.find(
(key: any) => key.name === 'Default Admin API Key'
)?.key
return key || ''
}
return MASTER_KEY
Expand Down