Skip to content

Commit 94fe3aa

Browse files
committed
add language presets and persistent adapter types to index.d.ts
1 parent 58c1a09 commit 94fe3aa

File tree

2 files changed

+77
-33
lines changed

2 files changed

+77
-33
lines changed

index.d.ts

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ declare module "flexsearch" {
116116
* * Language: https://github.com/nextapps-de/flexsearch#languages
117117
*/
118118

119+
global {
119120
type EncoderOptions = {
120121
rtl?: boolean;
121122
dedupe?: boolean;
@@ -134,7 +135,7 @@ declare module "flexsearch" {
134135
minlength?: number;
135136
maxlength?: number;
136137
cache?: boolean|number;
137-
};
138+
}}
138139

139140
type EncoderSplitOptions = {
140141
letter?: boolean;
@@ -152,7 +153,8 @@ declare module "flexsearch" {
152153
LatinBalance: EncoderOptions,
153154
LatinAdvanced: EncoderOptions,
154155
LatinExtra: EncoderOptions,
155-
LatinSoundex: EncoderOptions
156+
LatinSoundex: EncoderOptions,
157+
CJK: EncoderOptions
156158
};
157159

158160
/**
@@ -502,34 +504,6 @@ declare module "flexsearch" {
502504
): Promise<DocumentSearchResults>;
503505
}
504506

505-
type IdType =
506-
"text" |
507-
"char" |
508-
"varchar" |
509-
"string" |
510-
"number" |
511-
"numeric" |
512-
"integer" |
513-
"smallint" |
514-
"tinyint" |
515-
"mediumint" |
516-
"int" |
517-
"int8" |
518-
"uint8" |
519-
"int16" |
520-
"uint16" |
521-
"int32" |
522-
"uint32" |
523-
"int64" |
524-
"uint64" |
525-
"bigint";
526-
527-
type PersistentOptions = {
528-
name?: string;
529-
type?: IdType;
530-
db?: any;
531-
};
532-
533507
type DefaultResolve = {
534508
query?: string;
535509
limit?: number;
@@ -597,6 +571,7 @@ declare module "flexsearch" {
597571
resolve(options?: DefaultResolve): SearchResults;
598572
}
599573

574+
global{
600575
class StorageInterface {
601576
constructor(name: string, config: PersistentOptions);
602577
constructor(config: string | PersistentOptions);
@@ -606,7 +581,7 @@ declare module "flexsearch" {
606581
destroy() : Promise<void>;
607582
clear() : Promise<void>;
608583
db: any;
609-
}
584+
}}
610585

611586
export class IndexedDB extends StorageInterface{
612587
db: IDBDatabase
@@ -625,7 +600,76 @@ declare module "flexsearch" {
625600
export default FlexSearch;
626601
}
627602

603+
// -----------------------------------
604+
605+
type IdType =
606+
"text" |
607+
"char" |
608+
"varchar" |
609+
"string" |
610+
"number" |
611+
"numeric" |
612+
"integer" |
613+
"smallint" |
614+
"tinyint" |
615+
"mediumint" |
616+
"int" |
617+
"int8" |
618+
"uint8" |
619+
"int16" |
620+
"uint16" |
621+
"int32" |
622+
"uint32" |
623+
"int64" |
624+
"uint64" |
625+
"bigint";
626+
627+
type PersistentOptions = {
628+
name?: string;
629+
type?: IdType;
630+
db?: any;
631+
};
632+
633+
declare module "flexsearch/db/redis" {
634+
export default StorageInterface;
635+
}
636+
637+
declare module "flexsearch/db/postgres" {
638+
export default StorageInterface;
639+
}
640+
641+
declare module "flexsearch/db/mongodb" {
642+
export default StorageInterface;
643+
}
644+
645+
declare module "flexsearch/db/sqlite" {
646+
export default StorageInterface;
647+
}
648+
649+
declare module "flexsearch/db/clickhouse" {
650+
export default StorageInterface;
651+
}
652+
653+
declare module "flexsearch/db/indexeddb" {
654+
export default class IndexedDB extends StorageInterface{
655+
db: IDBDatabase
656+
}
657+
}
658+
659+
// -----------------------------------
660+
661+
declare module "flexsearch/lang/en" {
662+
export default EncoderOptions;
663+
}
664+
665+
declare module "flexsearch/lang/de" {
666+
export default EncoderOptions;
667+
}
668+
669+
declare module "flexsearch/lang/fr" {
670+
export default EncoderOptions;
671+
}
672+
628673
// https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
629674
// https://github.com/futurGH/ts-to-jsdoc
630675
// https://sethmac.com/typescript-to-jsdoc/
631-

test/async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if(!build_light) describe("Add (Async)", function(){
5757
if(duration) break;
5858
}
5959

60-
expect(duration).to.closeTo(0, 3);
60+
expect(duration).to.closeTo(0, 4);
6161

6262
for(let i = 0; i < 999999999; i++){
6363
await index.addAsync(i, "foo");

0 commit comments

Comments
 (0)