mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-08-29 00:30:06 +02:00
added some tests for index.d.ts
This commit is contained in:
71
index.d.ts
vendored
71
index.d.ts
vendored
@@ -198,7 +198,7 @@ declare module "flexsearch" {
|
||||
D extends DocumentData = undefined
|
||||
> = R extends true
|
||||
? DefaultSearchResults
|
||||
: Resolver<D, W, S>;
|
||||
: Resolver<D, W, S>
|
||||
|
||||
/**
|
||||
* Basic usage and variants: https://github.com/nextapps-de/flexsearch#basic-usage-and-variants \
|
||||
@@ -209,12 +209,13 @@ declare module "flexsearch" {
|
||||
export type IndexSearchResultsWrapper<
|
||||
W extends WorkerType = false,
|
||||
S extends StorageInterface | boolean = false,
|
||||
R extends boolean = true
|
||||
R extends boolean = true,
|
||||
D extends DocumentData = undefined
|
||||
> = W extends false
|
||||
? S extends false
|
||||
? SearchResults<W, S, R>
|
||||
: Promise<SearchResults<W, S, R>>
|
||||
: Promise<SearchResults<W, S, R>>
|
||||
? SearchResults<W, S, R, D>
|
||||
: Promise<SearchResults<W, S, R, D>>
|
||||
: Promise<SearchResults<W, S, R, D>>
|
||||
|
||||
export class Index<
|
||||
W extends WorkerType = false,
|
||||
@@ -364,8 +365,8 @@ declare module "flexsearch" {
|
||||
type WorkerConfigPath = string;
|
||||
type WorkerType = boolean | WorkerURL | WorkerPath;
|
||||
|
||||
export type WorkerIndexOptions = IndexOptions & {
|
||||
config?: WorkerConfigURL | WorkerConfigPath,
|
||||
export type WorkerIndexOptions = IndexOptions & IndexWorkerConfig & {
|
||||
//config?: WorkerConfigURL | WorkerConfigPath,
|
||||
export?: () => Promise<void>;
|
||||
import?: () => Promise<void>;
|
||||
// no persistent supported
|
||||
@@ -373,6 +374,10 @@ declare module "flexsearch" {
|
||||
commit?: null;
|
||||
};
|
||||
|
||||
export interface IndexWorkerConfig {
|
||||
config?: WorkerConfigURL | WorkerConfigPath;
|
||||
}
|
||||
|
||||
export class Worker extends Index<true> {
|
||||
constructor(options?: Preset | WorkerIndexOptions);
|
||||
|
||||
@@ -402,33 +407,31 @@ declare module "flexsearch" {
|
||||
}[keyof D]
|
||||
: never;
|
||||
|
||||
export type DefaultFieldOptions<
|
||||
D = DocumentData,
|
||||
> = IndexOptions & {
|
||||
field: FieldName<D>;
|
||||
filter?: (doc: D) => boolean;
|
||||
db?: StorageInterface;
|
||||
};
|
||||
export type DefaultFieldOptions<D = DocumentData> =
|
||||
IndexOptions & {
|
||||
field: FieldName<D>;
|
||||
filter?: (doc: D) => boolean;
|
||||
db?: StorageInterface;
|
||||
};
|
||||
|
||||
export type DefaultCustomFieldOptions<
|
||||
D = DocumentData,
|
||||
> = IndexOptions & {
|
||||
custom: CustomFN<D>;
|
||||
field: FieldName;
|
||||
filter?: (doc: D) => boolean;
|
||||
db?: StorageInterface;
|
||||
};
|
||||
export type DefaultCustomFieldOptions<D = DocumentData> =
|
||||
IndexOptions & {
|
||||
custom: CustomFN<D>;
|
||||
field: FieldName;
|
||||
filter?: (doc: D) => boolean;
|
||||
db?: StorageInterface;
|
||||
};
|
||||
|
||||
export type TagOptions<D = DocumentData> = DefaultFieldOptions<D> | DefaultCustomFieldOptions<D>;
|
||||
export type TagOptions<D = DocumentData> =
|
||||
| DefaultFieldOptions<D>
|
||||
| DefaultCustomFieldOptions<D>;
|
||||
|
||||
export type StoreOptions<D = DocumentData> = DefaultFieldOptions<D> | DefaultCustomFieldOptions<D>;
|
||||
|
||||
export interface IndexWorkerConfig {
|
||||
config?: WorkerConfigURL | WorkerConfigPath;
|
||||
}
|
||||
export type StoreOptions<D = DocumentData> =
|
||||
| DefaultFieldOptions<D>
|
||||
| DefaultCustomFieldOptions<D>;
|
||||
|
||||
export type FieldOptions<D extends DocumentData> =
|
||||
(DefaultFieldOptions<D> & IndexWorkerConfig)
|
||||
| (DefaultFieldOptions<D> & IndexWorkerConfig)
|
||||
| (DefaultCustomFieldOptions<D> & IndexWorkerConfig)
|
||||
|
||||
/**
|
||||
@@ -992,16 +995,16 @@ declare module "flexsearch" {
|
||||
constructor(options?: ResolverOptions<D, W, S> | IntermediateSearchResults);
|
||||
|
||||
and<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||
SearchResults<W, S, R, D>;
|
||||
IndexSearchResultsWrapper<W, S, R, D>;
|
||||
|
||||
or<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||
SearchResults<W, S, R, D>;
|
||||
IndexSearchResultsWrapper<W, S, R, D>;
|
||||
|
||||
xor<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||
SearchResults<W, S, R, D>;
|
||||
IndexSearchResultsWrapper<W, S, R, D>;
|
||||
|
||||
not<R extends boolean = false>(...args: ResolverOptions<D, W, S, unknown, R>[]):
|
||||
SearchResults<W, S, R, D>;
|
||||
IndexSearchResultsWrapper<W, S, R, D>;
|
||||
|
||||
limit(limit: number): Resolver<D, W, S>;
|
||||
|
||||
@@ -1009,7 +1012,7 @@ declare module "flexsearch" {
|
||||
|
||||
boost(boost: number): Resolver<D, W, S>;
|
||||
|
||||
resolve(options?: DefaultResolve<D>): SearchResults<W, S, true, D>;
|
||||
resolve(options?: DefaultResolve<D>): IndexSearchResultsWrapper<W, S, true, D>;
|
||||
}
|
||||
|
||||
export class StorageInterface {
|
||||
|
@@ -3,7 +3,7 @@ import {
|
||||
Index,
|
||||
Worker,
|
||||
Resolver,
|
||||
IndexedDB
|
||||
IndexedDB, EnrichedResults
|
||||
} from "flexsearch";
|
||||
import {
|
||||
DefaultDocumentSearchResults,
|
||||
@@ -44,9 +44,14 @@ async function test_index() {
|
||||
const idx19: Promise<Resolver> = index2.searchCacheAsync({});
|
||||
|
||||
const res1: Resolver = new Resolver({ index });
|
||||
const res2: Resolver = res1.and({ index }).limit(100);
|
||||
const res2: Resolver = res1.and({}, { index }).limit(100);
|
||||
const res3: DefaultSearchResults = res2.resolve();
|
||||
|
||||
const res4: Resolver<undefined, false, IndexedDB> = new Resolver({ index: index3 });
|
||||
const res5: Promise<Resolver<undefined, false, IndexedDB>> = res4.and();
|
||||
const res6: Promise<Resolver<undefined, false, IndexedDB>> = res4.and({ index: index3 });
|
||||
const res7: Promise<DefaultSearchResults> = (await res6).limit(100).resolve();
|
||||
|
||||
// @ts-expect-error
|
||||
const idx_err1 = index.search({ highlight: true });
|
||||
// @ts-expect-error
|
||||
@@ -78,6 +83,8 @@ async function test_index() {
|
||||
// @ts-expect-error
|
||||
const idx_err12: Promise<Resolver> = index3.searchAsync({ resolve: false, cache: true });
|
||||
|
||||
// @ts-expect-deprecation
|
||||
const idx_err13: DefaultSearchResults = index.search("query", 100);
|
||||
}
|
||||
|
||||
async function test_document() {
|
||||
@@ -168,12 +175,22 @@ async function test_document() {
|
||||
const doc10: Promise<DefaultDocumentSearchResults> = document.searchAsync({ cache: true });
|
||||
const doc11: Promise<DefaultDocumentSearchResults> = document.searchCacheAsync({});
|
||||
const doc13: DefaultDocumentSearchResults = document.search({ resolve: true });
|
||||
|
||||
const doc14: Resolver = document.search({ resolve: false });
|
||||
const doc15: DefaultSearchResults = doc14.resolve({});
|
||||
const doc16: DefaultSearchResults = doc14.and({ resolve: true });
|
||||
const doc17: EnrichedResults = doc14.resolve({ enrich: true });
|
||||
const doc18: EnrichedResults = doc14.and({ resolve: true, enrich: true });
|
||||
const doc19: Resolver = doc14.and({ index: document, field: "title" });
|
||||
const doc20: Resolver = doc19.or({ index: document2, field: "meta:title" });
|
||||
const doc21: DefaultDocumentSearchResults = doc20.resolve();
|
||||
const doc22: EnrichedResults = doc20.resolve({ enrich: true });
|
||||
const doc23: EnrichedResults = doc20.resolve({ highlight: true });
|
||||
|
||||
const res1: Resolver = doc14.and({ index: document, field: "meta:title" });
|
||||
const res2: DefaultDocumentSearchResults = doc14.resolve();
|
||||
const doc24: Resolver = new Resolver({ index: document });
|
||||
const doc25: EnrichedResults = doc24.and({}, { index: document2, resolve: true, enrich: true });
|
||||
const doc26: EnrichedResults = doc24.and({}, { index: document2 }).resolve({ enrich: true });
|
||||
const doc27: EnrichedResults = doc24.and({}, { index: document2 }).resolve({ highlight: true });
|
||||
|
||||
// @ts-expect-error
|
||||
let tmp1: DocumentData = doc1[0].result[0].doc;
|
||||
|
Reference in New Issue
Block a user