meilisearch
Advanced tools
Comparing version 0.20.2 to 0.21.0
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.window = global.window || {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -2271,3 +2271,3 @@ /*! ***************************************************************************** | ||
exports.MeiliSearchTimeOutError = MeiliSearchTimeOutError; | ||
exports['default'] = MeiliSearch; | ||
exports["default"] = MeiliSearch; | ||
exports.httpErrorHandler = httpErrorHandler; | ||
@@ -2280,2 +2280,2 @@ exports.httpResponseErrorHandler = httpResponseErrorHandler; | ||
}))); | ||
})); |
@@ -1,2 +0,2 @@ | ||
// Type definitions for meilisearch 0.20.2 | ||
// Type definitions for meilisearch 0.21.0 | ||
// Project: https://github.com/meilisearch/meilisearch-js | ||
@@ -3,0 +3,0 @@ // Definitions by: cvermand <charlotte@meilisearch.com> <https://github.com/meilisearch> |
import { Config, Update, SearchResponse, SearchParams, IndexResponse, IndexOptions, IndexStats, GetDocumentsParams, GetDocumentsResponse, Document, AddDocumentParams, EnqueuedUpdate, Settings, Synonyms, StopWords, RankingRules, DistinctAttribute, FilterableAttributes, SortableAttributes, SearchableAttributes, DisplayedAttributes } from '../types'; | ||
import { HttpRequests } from './http-requests'; | ||
declare class Index<T> { | ||
declare class Index<T = Record<string, any>> { | ||
uid: string; | ||
@@ -17,3 +17,3 @@ primaryKey: string | undefined; | ||
*/ | ||
search<P extends SearchParams<T>>(query?: string | null, options?: P, config?: Partial<Request>): Promise<SearchResponse<T, P>>; | ||
search<T = Record<string, any>>(query?: string | null, options?: SearchParams, config?: Partial<Request>): Promise<SearchResponse<T>>; | ||
/** | ||
@@ -24,3 +24,3 @@ * Search for documents into an index using the GET method | ||
*/ | ||
searchGet<P extends SearchParams<T>>(query?: string | null, options?: P, config?: Partial<Request>): Promise<SearchResponse<T, P>>; | ||
searchGet<T = Record<string, any>>(query?: string | null, options?: SearchParams, config?: Partial<Request>): Promise<SearchResponse<T>>; | ||
/** | ||
@@ -49,3 +49,3 @@ * Get index information. | ||
*/ | ||
static create<T = any>(config: Config, uid: string, options?: IndexOptions): Promise<Index<T>>; | ||
static create<T = Record<string, any>>(config: Config, uid: string, options?: IndexOptions): Promise<Index<T>>; | ||
/** | ||
@@ -92,3 +92,3 @@ * Update an index. | ||
*/ | ||
getDocuments<P extends GetDocumentsParams<T>>(options?: P): Promise<GetDocumentsResponse<T, P>>; | ||
getDocuments<T = Record<string, any>>(options?: GetDocumentsParams<T>): Promise<GetDocumentsResponse<T>>; | ||
/** | ||
@@ -95,0 +95,0 @@ * Get one document |
@@ -24,9 +24,9 @@ export declare type Config = { | ||
export declare type Filter = string | Array<string | string[]>; | ||
export declare type SearchParams<T> = { | ||
export declare type SearchParams = { | ||
offset?: number; | ||
limit?: number; | ||
attributesToRetrieve?: Array<Extract<keyof T, string> | '*'>; | ||
attributesToCrop?: Array<Extract<keyof T, string> | '*'>; | ||
attributesToRetrieve?: string[]; | ||
attributesToCrop?: string[]; | ||
cropLength?: number; | ||
attributesToHighlight?: Array<Extract<keyof T, string> | '*'>; | ||
attributesToHighlight?: string[]; | ||
filter?: Filter; | ||
@@ -72,9 +72,12 @@ sort?: string[]; | ||
}>>>; | ||
export declare type Hit<T> = T & { | ||
export declare type document = { | ||
[field: string]: any; | ||
}; | ||
export declare type Hit<T = document> = T & { | ||
_formatted?: Partial<T>; | ||
_matchesInfo?: _matchesInfo<T>; | ||
}; | ||
export declare type Hits<T, P extends SearchParams<T>> = P['attributesToRetrieve'] extends Array<'*'> ? Array<Hit<T>> : P['attributesToRetrieve'] extends Array<infer K> ? Array<Hit<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>> : Array<Hit<T>>; | ||
export declare type SearchResponse<T, P extends SearchParams<T>> = { | ||
hits: Hits<T, P>; | ||
export declare type Hits<T = document> = Array<Hit<T>>; | ||
export declare type SearchResponse<T = Record<string, any>> = { | ||
hits: Hits<T>; | ||
offset: number; | ||
@@ -92,3 +95,3 @@ limit: number; | ||
}; | ||
export declare type GetDocumentsParams<T> = { | ||
export declare type GetDocumentsParams<T = Record<string, any>> = { | ||
offset?: number; | ||
@@ -98,4 +101,4 @@ limit?: number; | ||
}; | ||
export declare type GetDocumentsResponse<T, P extends GetDocumentsParams<T>> = P['attributesToRetrieve'] extends keyof T ? Array<Document<Pick<T, Exclude<keyof T, Exclude<keyof T, P['attributesToRetrieve']>>>>> : P['attributesToRetrieve'] extends Array<infer K> ? Array<Document<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>> : Array<Document<T>>; | ||
export declare type Document<T> = T; | ||
export declare type GetDocumentsResponse<T = Record<string, any>> = Array<Document<T>>; | ||
export declare type Document<T = Record<string, any>> = T; | ||
export declare type FilterableAttributes = string[] | null; | ||
@@ -102,0 +105,0 @@ export declare type DistinctAttribute = string | null; |
{ | ||
"name": "meilisearch", | ||
"version": "0.20.2", | ||
"version": "0.21.0", | ||
"description": "The MeiliSearch JS client for Node.js and the browser.", | ||
@@ -69,4 +69,4 @@ "keywords": [ | ||
"@rollup/plugin-json": "^4.0.2", | ||
"@rollup/plugin-node-resolve": "13.0.4", | ||
"@types/jest": "^27.0.1", | ||
"@rollup/plugin-node-resolve": "13.0.5", | ||
"@types/jest": "^27.0.2", | ||
"@types/prettier": "^2.2.3", | ||
@@ -94,3 +94,3 @@ "@typescript-eslint/eslint-plugin": "2.34.0", | ||
"pretty-bytes": "^5.6.0", | ||
"rollup": "^2.56.3", | ||
"rollup": "^2.57.0", | ||
"rollup-plugin-terser": "^7.0.0", | ||
@@ -97,0 +97,0 @@ "rollup-plugin-typescript2": "^0.30.0", |
@@ -519,2 +519,13 @@ <p align="center"> | ||
### Sortable Attributes <!-- omit in toc --> | ||
- Get Sortable Attributes | ||
`index.getSortableAttributes(): Promise<string[]>` | ||
- Update Sortable Attributes | ||
`index.updateSortableAttributes(sortableAttributes: string[] | null): Promise<EnqueuedUpdate>` | ||
- Reset Sortable Attributes | ||
`index.resetSortableAttributes(): Promise<EnqueuedUpdate>` | ||
### Keys <!-- omit in toc --> | ||
@@ -521,0 +532,0 @@ |
@@ -40,3 +40,3 @@ /* | ||
class Index<T> { | ||
class Index<T = Record<string, any>> { | ||
uid: string | ||
@@ -83,7 +83,7 @@ primaryKey: string | undefined | ||
*/ | ||
async search<P extends SearchParams<T>>( | ||
async search<T = Record<string, any>>( | ||
query?: string | null, | ||
options?: P, | ||
options?: SearchParams, | ||
config?: Partial<Request> | ||
): Promise<SearchResponse<T, P>> { | ||
): Promise<SearchResponse<T>> { | ||
const url = `indexes/${this.uid}/search` | ||
@@ -104,7 +104,7 @@ | ||
*/ | ||
async searchGet<P extends SearchParams<T>>( | ||
async searchGet<T = Record<string, any>>( | ||
query?: string | null, | ||
options?: P, | ||
options?: SearchParams, | ||
config?: Partial<Request> | ||
): Promise<SearchResponse<T, P>> { | ||
): Promise<SearchResponse<T>> { | ||
const url = `indexes/${this.uid}/search` | ||
@@ -140,3 +140,3 @@ | ||
return await this.httpRequest.get<SearchResponse<T, P>>( | ||
return await this.httpRequest.get<SearchResponse<T>>( | ||
url, | ||
@@ -189,3 +189,3 @@ removeUndefinedFromObject(getParams), | ||
*/ | ||
static async create<T = any>( | ||
static async create<T = Record<string, any>>( | ||
config: Config, | ||
@@ -286,5 +286,5 @@ uid: string, | ||
*/ | ||
async getDocuments<P extends GetDocumentsParams<T>>( | ||
options?: P | ||
): Promise<GetDocumentsResponse<T, P>> { | ||
async getDocuments<T = Record<string, any>>( | ||
options?: GetDocumentsParams<T> | ||
): Promise<GetDocumentsResponse<T>> { | ||
const url = `indexes/${this.uid}/documents` | ||
@@ -296,3 +296,3 @@ let attr | ||
return await this.httpRequest.get<GetDocumentsResponse<T, P>>(url, { | ||
return await this.httpRequest.get<GetDocumentsResponse<T>>(url, { | ||
...options, | ||
@@ -299,0 +299,0 @@ ...(attr !== undefined ? { attributesToRetrieve: attr } : {}), |
@@ -40,9 +40,9 @@ // Type definitions for meilisearch | ||
export type SearchParams<T> = { | ||
export type SearchParams = { | ||
offset?: number | ||
limit?: number | ||
attributesToRetrieve?: Array<Extract<keyof T, string> | '*'> | ||
attributesToCrop?: Array<Extract<keyof T, string> | '*'> | ||
attributesToRetrieve?: string[] | ||
attributesToCrop?: string[] | ||
cropLength?: number | ||
attributesToHighlight?: Array<Extract<keyof T, string> | '*'> | ||
attributesToHighlight?: string[] | ||
filter?: Filter | ||
@@ -92,3 +92,7 @@ sort?: string[] | ||
export type Hit<T> = T & { | ||
export type document = { | ||
[field: string]: any | ||
} | ||
export type Hit<T = document> = T & { | ||
_formatted?: Partial<T> | ||
@@ -98,17 +102,6 @@ _matchesInfo?: _matchesInfo<T> | ||
export type Hits< | ||
T, | ||
P extends SearchParams<T> | ||
> = P['attributesToRetrieve'] extends Array<'*'> | ||
? Array<Hit<T>> | ||
: P['attributesToRetrieve'] extends Array<infer K> // if P['attributesToRetrieve'] is an array, we use `infer K` to extract the keys in the array in place | ||
? Array<Hit<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>> // Same extraction method as above when we have a single `attributesToRetrieve` | ||
: Array<Hit<T>> // Finally return the full type as `attributesToRetrieve` is neither a single key nor an array of keys | ||
export type Hits<T = document> = Array<Hit<T>> | ||
// The second generic P is used to capture the SearchParams type | ||
export type SearchResponse<T, P extends SearchParams<T>> = { | ||
// P represents the SearchParams | ||
// and by using the indexer P['attributesToRetrieve'], we're able to pick the type of `attributesToRetrieve` | ||
// and check whether the attribute is a single key present in the generic | ||
hits: Hits<T, P> | ||
export type SearchResponse<T = Record<string, any>> = { | ||
hits: Hits<T> | ||
offset: number | ||
@@ -131,3 +124,3 @@ limit: number | ||
*/ | ||
export type GetDocumentsParams<T> = { | ||
export type GetDocumentsParams<T = Record<string, any>> = { | ||
offset?: number | ||
@@ -140,16 +133,5 @@ limit?: number | ||
export type GetDocumentsResponse< | ||
T, | ||
P extends GetDocumentsParams<T> | ||
> = P['attributesToRetrieve'] extends keyof T | ||
? Array< | ||
Document< | ||
Pick<T, Exclude<keyof T, Exclude<keyof T, P['attributesToRetrieve']>>> | ||
> | ||
> | ||
: P['attributesToRetrieve'] extends Array<infer K> | ||
? Array<Document<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>> | ||
: Array<Document<T>> | ||
export type GetDocumentsResponse<T = Record<string, any>> = Array<Document<T>> | ||
export type Document<T> = T | ||
export type Document<T = Record<string, any>> = T | ||
@@ -156,0 +138,0 @@ /* |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
573
277408
5845