Skip to content

Commit

Permalink
Revert formatting changes, ignore tests/env and coverage from being f…
Browse files Browse the repository at this point in the history
…ormatted
  • Loading branch information
flevi29 committed Jan 11, 2024
1 parent e5f0194 commit 5887422
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 91 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist
*.md
tests/env
coverage
6 changes: 5 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** 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 @@ -26,6 +28,7 @@ function writeDtsHeader() {
}

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

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

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

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

/**
*
* @param {string} code
* @param {string} filename
* @param {boolean} [raw=false] Default is `false`
* @param {boolean} [raw=false]
*/
async function getSizeInfo(code, filename, raw = false) {
const isRaw = raw || code.length < 5000
Expand Down
11 changes: 4 additions & 7 deletions src/http-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ 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 @@ -90,7 +90,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 @@ -116,7 +116,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: 4 additions & 6 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ 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: 9 additions & 11 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ 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 @@ -200,7 +199,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 @@ -211,8 +210,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 @@ -234,8 +233,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 @@ -364,7 +363,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 @@ -380,7 +379,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 @@ -933,8 +932,7 @@ 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: 6 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/** 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 @@ -29,8 +26,7 @@ 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
3 changes: 1 addition & 2 deletions tests/env/browser/meilisearch.umd.js
15 changes: 3 additions & 12 deletions tests/env/esm/src/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { MeiliSearch } from '../../../../'
import * as DefaultMeiliSearch from '../../../../'

const client = new MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'masterKey',
})
const defaultClient = new DefaultMeiliSearch.MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'masterKey',
})
const token = client.generateTenantToken(
'e489fe16-3381-431b-bee3-00430192915d',
[]
)
const client = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey'})
const defaultClient = new DefaultMeiliSearch.MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey'})
const token = client.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [])
console.log({ client, token, defaultClient })
2 changes: 1 addition & 1 deletion tests/env/express/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// jest.config.js
module.exports = {
preset: 'jest-puppeteer',
setupFilesAfterEnv: ['./jest.setup.js'],
setupFilesAfterEnv: ['./jest.setup.js']
}
3 changes: 1 addition & 2 deletions tests/env/express/public/meilisearch.umd.js
9 changes: 5 additions & 4 deletions tests/env/express/tests/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ describe('Meilisearch JS Browser test', () => {
})

it('Should have created an index and displayed it', async () => {
await page.waitForSelector('#indexes')
await page.waitForSelector("#indexes")
let element = await page.$('#indexes')
let value = await page.evaluate((el) => el.textContent, element)
let value = await page.evaluate(el => el.textContent, element)
await expect(value).toMatch('testIndex')
})
})
Expand All @@ -16,9 +16,10 @@ describe('Meilisearch JS CORS test', () => {
await page.goto('http://localhost:3000/headers')
})
it('Should not throw cors error', async () => {
await page.waitForSelector('#error')
await page.waitForSelector("#error")
let element = await page.$('#error')
let value = await page.evaluate((el) => el.textContent, element)
let value = await page.evaluate(el => el.textContent, element)
await expect(value).toMatch('NO ERRORS')
})

})
35 changes: 19 additions & 16 deletions tests/env/node/getting_started.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ const { MeiliSearch } = require('../../../dist/bundles/meilisearch.umd.js')
const index = client.index('movies')

const dataset = [
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
{
id: 4,
title: 'Mad Max: Fury Road',
genres: ['Adventure', 'Science Fiction'],
},
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action'] },
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
{ id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
]

// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
await index.updateFilterableAttributes(['director', 'genres', 'id'])
await index.updateFilterableAttributes([
'director',
'genres',
'id'
])

let response = await index.addDocuments(dataset)

Expand All @@ -35,12 +35,15 @@ const { MeiliSearch } = require('../../../dist/bundles/meilisearch.umd.js')
console.log({ search, hit: search.hits })
const filteredSearch = await index.search('Wonder', {
attributesToHighlight: ['*'],
filter: 'id >= 1',
filter: 'id >= 1'
})
console.log({ filteredSearch, hit: filteredSearch.hits[0] })
const facetedSearch = await index.search('', {
filter: ['genres = action'],
facets: ['genres'],
})
const facetedSearch = await index.search(
'',
{
filter: ['genres = action'],
facets: ['genres']
}
)
console.log(JSON.stringify(facetedSearch))
})()
10 changes: 2 additions & 8 deletions tests/env/node/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
const { MeiliSearch } = require('../../../')
const DefaultMeiliSearch = require('../../../')

const CJStest = new MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'masterKey',
})
const DefaultCJSTest = new DefaultMeiliSearch.MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'masterKey',
})
const CJStest = new MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey'})
const DefaultCJSTest = new DefaultMeiliSearch.MeiliSearch({ host:'http://localhost:7700', apiKey: 'masterKey'})

DefaultCJSTest.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', []) // Resolved using the `main` field
CJStest.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', []) // Resolved using the `main` field
Expand Down
4 changes: 1 addition & 3 deletions tests/env/typescript-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ function greeter(person: string) {
user
)} this is the list of all your indexes: \n ${uids.join(', ')}`

console.log(
await client.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [])
) // Resolved using the `browser` field
console.log(await client.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [])) // Resolved using the `browser` field
})()
1 change: 1 addition & 0 deletions tests/env/typescript-browser/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let config = {
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],

},
}

Expand Down
12 changes: 7 additions & 5 deletions tests/env/typescript-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// @ts-ignore
import {
// @ts-ignore
Expand All @@ -24,7 +25,7 @@ interface Movie {
}

const client = new MeiliSearch(config)
const indexUid = 'movies'
const indexUid = "movies"

;(async () => {
await client.deleteIndex(indexUid)
Expand All @@ -45,7 +46,10 @@ const indexUid = 'movies'
// test: true -> ERROR Test does not exist on type SearchParams
}
indexes.results.map((index: IndexObject) => index.uid)
const res: SearchResponse<Movie> = await index.search('avenger', searchParams)
const res: SearchResponse<Movie> = await index.search(
'avenger',
searchParams
)

// both work
const { hits }: { hits: Hits<Movie> } = res
Expand All @@ -58,9 +62,7 @@ const indexUid = 'movies'
console.log(hit?._formatted?.title)
})

console.log(
await client.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', [])
)
console.log(await client.generateTenantToken('e489fe16-3381-431b-bee3-00430192915d', []))

await index.delete()
})()

0 comments on commit 5887422

Please sign in to comment.