@hitgrab/finder 0.1.16-alpha → 0.1.18-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/core/__tests__/json.test.d.ts +1 -0
  2. package/dist/core/core-constants.d.ts +4 -0
  3. package/dist/core/debounce-callback-registry.d.ts +2 -2
  4. package/dist/core/effect-book.d.ts +2 -2
  5. package/dist/core/filters.d.ts +10 -9
  6. package/dist/core/finder-core-implementation.d.ts +5 -4
  7. package/dist/core/finder-core.d.ts +25 -23
  8. package/dist/core/group-by.d.ts +10 -8
  9. package/dist/core/rule-book/boolean-filter-handler.d.ts +11 -0
  10. package/dist/core/rule-book/filter-handler.d.ts +29 -0
  11. package/dist/core/{filter-utils/multiple-filter.d.ts → rule-book/multiple-filter-handler.d.ts} +3 -2
  12. package/dist/core/rule-book/rule-book.d.ts +14 -0
  13. package/dist/core/rule-book/single-filter-handler.d.ts +11 -0
  14. package/dist/core/search/default-search-and-sort-algorithm.d.ts +2 -0
  15. package/dist/core/search.d.ts +1 -1
  16. package/dist/core/sort-by.d.ts +5 -5
  17. package/dist/core/types/core-types.d.ts +9 -14
  18. package/dist/core/types/effect-types.d.ts +5 -5
  19. package/dist/core/types/event-types.d.ts +2 -2
  20. package/dist/core/types/rule-types.d.ts +25 -29
  21. package/dist/core/utils/rule-type-enforcers.d.ts +10 -7
  22. package/dist/core/utils/rule-utils.d.ts +13 -8
  23. package/dist/index.d.ts +2 -2
  24. package/dist/index.js +2182 -2090
  25. package/dist/index.umd.cjs +15 -15
  26. package/dist/react/components/finder.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/dist/core/filter-utils/boolean-filter.d.ts +0 -10
  29. package/dist/core/filter-utils/filter-factory.d.ts +0 -18
  30. package/dist/core/filter-utils/single-filter.d.ts +0 -10
  31. package/dist/core/rule-book.d.ts +0 -14
@@ -0,0 +1 @@
1
+ export {};
@@ -10,6 +10,7 @@ export declare const EVENTS: {
10
10
  readonly SET_SEARCH_TERM: "setSearchTerm";
11
11
  readonly RESET_SEARCH_TERM: "resetSearchTerm";
12
12
  readonly SET_FILTER: "setFilter";
13
+ readonly RESET_FILTERS: "resetFilters";
13
14
  readonly SET_SORT_BY: "setSortBy";
14
15
  readonly SET_SORT_BY_DIRECTION: "setSortDirection";
15
16
  readonly SET_GROUP_BY: "setGroupBy";
@@ -30,6 +31,8 @@ export declare const ERRORS: {
30
31
  RULE_NOT_FOUND: string;
31
32
  WRONG_RULE_TYPE_FOR_MIXIN: string;
32
33
  NO_SEARCH_RULE_SET: string;
34
+ INVALID_SEARCH_TERM_TYPE: string;
35
+ NO_MATCHING_OPTION_FOUND_WITH_STRICT_OPTIONS: string;
33
36
  SETTING_MULTIPLE_FILTER_WITHOUT_ARRAY: string;
34
37
  ADDING_OPTION_TO_MULTIPLE_FILTER_WITHOUT_OPTION_VALUE: string;
35
38
  DELETING_OPTION_VALUE_FROM_NON_MULTIPLE_FILTER: string;
@@ -39,6 +42,7 @@ export declare const ERRORS: {
39
42
  TOGGLING_OPTION_ON_RULE_WITH_SINGLE_VALUE: string;
40
43
  TOGGLING_OPTION_THAT_DOES_NOT_EXIST: string;
41
44
  TOGGLING_OPTION_WITHOUT_PASSING_OPTION: string;
45
+ TOGGLING_BOOLEAN_FILTER_WITH_UNUSED_VALUE: string;
42
46
  TESTING_OPTIONS_ON_RULE_WITH_NO_OPTIONS: string;
43
47
  INVALID_RULE_WITHOUT_ID: string;
44
48
  INVALID_RULE_SHAPE: string;
@@ -1,3 +1,3 @@
1
- import { FinderRule } from "./types/rule-types";
2
- declare function DebounceCallbackRegistry(): (rule: FinderRule, callback: () => void) => any;
1
+ import { RuleDefinition } from "./types/rule-types";
2
+ declare function DebounceCallbackRegistry(): (rule: RuleDefinition, callback: () => void) => any;
3
3
  export { DebounceCallbackRegistry };
@@ -1,12 +1,12 @@
1
1
  import { FinderCore } from "./finder-core";
2
2
  import { HydratedRuleEffect, HydratedSearchEffect, RuleEffect, SearchEffect } from "./types/effect-types";
3
- import { FinderRule } from "./types/rule-types";
3
+ import { RuleDefinition } from "./types/rule-types";
4
4
  export declare class EffectBook<FItem, FContext> {
5
5
  #private;
6
6
  searchEffects: HydratedSearchEffect[];
7
7
  ruleEffects: HydratedRuleEffect[];
8
8
  constructor(effects: (RuleEffect | SearchEffect)[], items: FItem[], context: FContext);
9
9
  hydrateDefinitions(items: FItem[], context: FContext): void;
10
- processRule(rule: FinderRule, instance: FinderCore): void;
10
+ processRule(rule: RuleDefinition, instance: FinderCore): void;
11
11
  processSearchTerm(searchTerm: string, instance: FinderCore): void;
12
12
  }
@@ -1,22 +1,23 @@
1
- import { FilterRuleUnion, FilterTestOptions, FilterTestRuleOptions, HydratedFilterRule } from "./types/rule-types";
1
+ import { AnyFilterRuleDefinition, FilterOption, FilterTestOptions, FilterTestRuleOptions } from "./types/rule-types";
2
2
  import { MixinInjectedDependencies, SerializedFiltersMixin } from "./types/core-types";
3
3
  interface InitialValues {
4
4
  initialFilters: Record<string, any> | undefined;
5
5
  }
6
- type FilterRuleIdentifier = string | FilterRuleUnion | HydratedFilterRule;
6
+ type FilterRuleIdentifier<FValue = any> = string | AnyFilterRuleDefinition<any, FValue>;
7
7
  declare class FiltersMixin {
8
8
  #private;
9
9
  constructor({ initialFilters }: InitialValues, deps: MixinInjectedDependencies);
10
- set<FValue>(identifier: FilterRuleIdentifier, value: FValue | FValue[]): void;
11
- get rules(): HydratedFilterRule<unknown, any, any>[];
12
- get activeRules(): HydratedFilterRule<unknown, any, any>[];
10
+ set<FValue>(identifier: FilterRuleIdentifier<FValue>, value?: FValue | FValue[]): void;
11
+ get rules(): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
12
+ get activeRules(): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
13
13
  get(identifier: FilterRuleIdentifier): any;
14
14
  has(identifier: FilterRuleIdentifier, optionValue?: any): boolean;
15
- getRule(identifier: FilterRuleIdentifier): HydratedFilterRule<any, any, any>;
16
- add(identifier: FilterRuleIdentifier, optionValue: any): void;
17
- delete(identifier: FilterRuleIdentifier, optionValue?: any): void;
15
+ getRule(identifier: FilterRuleIdentifier): import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>;
16
+ add<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
17
+ delete<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
18
+ toggle<FValue>(identifier: FilterRuleIdentifier<FValue>, optionValue?: FValue | FilterOption<FValue>): void;
19
+ reset(): void;
18
20
  isRuleActive(identifier: FilterRuleIdentifier): boolean;
19
- toggle(identifier: FilterRuleIdentifier, optionValue?: any): void;
20
21
  test(options: FilterTestOptions): any[];
21
22
  testRule({ rule: identifier, value, ...options }: FilterTestRuleOptions): any[];
22
23
  testRuleOptions(identifier: FilterRuleIdentifier, isAdditive?: boolean): Map<any, any>;
@@ -6,7 +6,7 @@ import { PaginationMixin } from "./pagination";
6
6
  import { FinderCore } from "./finder-core";
7
7
  import { FinderConstructorOptions, SnapshotSerializedMixins, EventCallback } from "./types/core-types";
8
8
  import { FinderEventName } from "./types/event-types";
9
- import { FinderRule } from "./types/rule-types";
9
+ import { RuleDefinition } from "./types/rule-types";
10
10
  declare class FinderCoreImplementation<FItem, FContext = any> {
11
11
  #private;
12
12
  isReady: boolean;
@@ -20,7 +20,7 @@ declare class FinderCoreImplementation<FItem, FContext = any> {
20
20
  pagination: PaginationMixin<FItem>;
21
21
  context: FContext;
22
22
  getInstanceFn: () => FinderCore;
23
- constructor(items: FItem[] | null | undefined, { rules, effects, initialSearchTerm, initialSortBy, initialSortDirection, initialGroupBy, initialFilters, context, page, numItemsPerPage, isLoading, disabled, requireGroup, ignoreSortByRulesWhileSearchRuleIsActive, onInit, onReady, onFirstUserInteraction, onChange, }: FinderConstructorOptions<FItem, FContext>, getInstanceFn: () => FinderCore);
23
+ constructor(items: FItem[] | null | undefined, { rules, effects, initialSearchTerm, initialSortBy, initialSortDirection, initialGroupBy, initialGroupBySortDirection, initialFilters, context, page, numItemsPerPage, isLoading, disabled, requireGroup, ignoreSortByRulesWhileSearchRuleIsActive, onInit, onReady, onFirstUserInteraction, onChange, }: FinderConstructorOptions<FItem, FContext>, getInstanceFn: () => FinderCore);
24
24
  emitFirstUserInteraction(): void;
25
25
  get items(): FItem[];
26
26
  get matches(): import("./types/core-types").ResultSnapshot<FItem>;
@@ -33,12 +33,13 @@ declare class FinderCoreImplementation<FItem, FContext = any> {
33
33
  silently: (callback: EventCallback) => void;
34
34
  isSilent: () => boolean;
35
35
  };
36
- getRule(identifier: string | FinderRule<FItem>): FinderRule<FItem>;
36
+ getRule(identifier: string | RuleDefinition<FItem>): RuleDefinition;
37
37
  get state(): "loading" | "empty" | "groups" | "items" | "noMatches";
38
38
  setItems(items: FItem[] | null | undefined): void;
39
39
  setIsLoading(value?: boolean): void;
40
40
  setIsDisabled(value?: boolean): void;
41
- setRules(definitions: FinderRule<FItem, FContext>[]): void;
41
+ setRules(definitions: RuleDefinition<FItem, FContext>[]): void;
42
42
  setContext(context: FContext): void;
43
+ toJSON(): Omit<FinderConstructorOptions<FItem>, "rules">;
43
44
  }
44
45
  export { FinderCoreImplementation };
@@ -1,5 +1,5 @@
1
1
  import { FinderConstructorOptions, SnapshotSerializedMixins } from "./types/core-types";
2
- import { FinderRule } from "./types/rule-types";
2
+ import { RuleDefinition } from "./types/rule-types";
3
3
  /**
4
4
  * This thin wrapper around FinderCoreImplementation defines the mixin interfaces and hides private methods.
5
5
  */
@@ -26,7 +26,7 @@ declare class FinderCore<FItem = any, FContext = any> {
26
26
  */
27
27
  get matches(): import("./types/core-types").ResultSnapshot<FItem>;
28
28
  get search(): {
29
- rule: import("..").SearchRule<unknown, any> | undefined;
29
+ rule: import("..").SearchRuleDefinition<unknown, any> | undefined;
30
30
  searchTerm: string;
31
31
  hasSearchTerm: boolean;
32
32
  hasSearchRule: boolean;
@@ -37,38 +37,39 @@ declare class FinderCore<FItem = any, FContext = any> {
37
37
  get filters(): {
38
38
  values: Record<string, any>;
39
39
  raw: Record<string, any>;
40
- activeRules: import("..").HydratedFilterRule<unknown, any, any>[];
41
- rules: import("..").HydratedFilterRule<unknown, any, any>[];
42
- isActive: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => boolean;
43
- get: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => any;
44
- add: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue: any) => void;
45
- has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => boolean;
46
- getRule: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => import("..").HydratedFilterRule<any, any, any>;
47
- toggle: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => void;
48
- set: <FValue>(identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, value: FValue | FValue[]) => void;
49
- delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => void;
40
+ activeRules: import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
41
+ rules: import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>[];
42
+ isActive: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => boolean;
43
+ get: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => any;
44
+ add: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
45
+ has: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>, optionValue?: any) => boolean;
46
+ getRule: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>) => import("./types/rule-types").HydratedFilterRuleDefinition<any, any, any>;
47
+ toggle: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
48
+ set: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, value?: FValue | FValue[]) => void;
49
+ delete: <FValue>(identifier: string | import("..").AnyFilterRuleDefinition<any, FValue>, optionValue?: FValue | import("..").FilterOption<FValue>) => void;
50
+ reset: () => void;
50
51
  test: (options: import("./types/rule-types").FilterTestOptions) => any[];
51
52
  testRule: ({ rule: identifier, value, ...options }: import("./types/rule-types").FilterTestRuleOptions) => any[];
52
- testRuleOptions: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, isAdditive?: boolean) => Map<any, any>;
53
+ testRuleOptions: (identifier: string | import("..").AnyFilterRuleDefinition<any, any>, isAdditive?: boolean) => Map<any, any>;
53
54
  };
54
55
  get sortBy(): {
55
- activeRule: import("..").SortByRule<unknown, any> | undefined;
56
+ activeRule: import("..").SortByRuleDefinition<unknown, any> | undefined;
56
57
  sortDirection: import("..").SortDirection;
57
58
  userHasSetSortDirection: boolean;
58
- rules: import("..").SortByRule<unknown, any>[];
59
- set: (identifier?: string | import("..").SortByRule, incomingSortDirection?: import("..").SortDirection) => void;
59
+ rules: import("..").SortByRuleDefinition<unknown, any>[];
60
+ set: (identifier?: string | import("..").SortByRuleDefinition, incomingSortDirection?: import("..").SortDirection) => void;
60
61
  setSortDirection: (incomingSortDirection?: import("..").SortDirection) => void;
61
62
  cycleSortDirection: () => void;
62
63
  toggleSortDirection: () => void;
63
64
  reset: () => void;
64
65
  };
65
66
  get groupBy(): {
66
- activeRule: import("..").GroupByRule<unknown, any> | undefined;
67
+ activeRule: import("..").GroupByRuleDefinition<unknown, any> | undefined;
67
68
  requireGroup: boolean;
68
- rules: import("..").GroupByRule<unknown, any>[];
69
- groupSortDirection: import("..").SortDirection | undefined;
70
- set: (identifier?: string | import("..").GroupByRule) => void;
71
- toggle: (identifier: import("..").GroupByRule | string) => void;
69
+ rules: import("..").GroupByRuleDefinition<unknown, any>[];
70
+ groupBySortDirection: import("..").SortDirection | undefined;
71
+ set: (identifier?: string | import("..").GroupByRuleDefinition<any, any>) => void;
72
+ toggle: (identifier: string | import("..").GroupByRuleDefinition<any, any>) => void;
72
73
  setGroupSortDirection: (direction?: import("..").SortDirection) => void;
73
74
  reset: () => void;
74
75
  };
@@ -88,12 +89,13 @@ declare class FinderCore<FItem = any, FContext = any> {
88
89
  setItems(items: FItem[] | null | undefined): void;
89
90
  setIsLoading(value?: boolean): void;
90
91
  setIsDisabled(value?: boolean): void;
91
- setRules(definitions: FinderRule<FItem>[]): void;
92
+ setRules(definitions: RuleDefinition<FItem>[]): void;
92
93
  setContext(context: FContext): void;
93
94
  /**
94
95
  * Utils
95
96
  */
96
97
  test(mixins: SnapshotSerializedMixins, isAdditive?: boolean): FItem[];
97
- getRule(identifier: string | FinderRule<FItem>): FinderRule<FItem>;
98
+ getRule<T extends RuleDefinition<FItem>>(identifier: string | RuleDefinition<FItem>): T | undefined;
99
+ toJSON(): Omit<FinderConstructorOptions<FItem, any>, "rules">;
98
100
  }
99
101
  export { FinderCore };
@@ -1,21 +1,23 @@
1
- import { GroupByRule } from "./types/rule-types";
1
+ import { GroupByRuleDefinition } from "./types/rule-types";
2
2
  import { FinderResultGroup, MixinInjectedDependencies, SerializedGroupByMixin, SortDirection } from "./types/core-types";
3
3
  interface InitialValues {
4
4
  initialGroupBy: string | undefined;
5
+ initialGroupBySortDirection?: SortDirection;
5
6
  requireGroup: boolean;
6
7
  }
8
+ type GroupByRuleIdentifier = string | GroupByRuleDefinition;
7
9
  declare class GroupByMixin<FItem, FContext> {
8
10
  #private;
9
11
  requireGroup: boolean;
10
- constructor({ initialGroupBy, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
11
- getRule(identifier: string | GroupByRule): GroupByRule<unknown, any>;
12
- get rules(): GroupByRule<unknown, any>[];
13
- get activeRule(): GroupByRule<unknown, any> | undefined;
12
+ constructor({ initialGroupBy, initialGroupBySortDirection, requireGroup }: InitialValues, deps: MixinInjectedDependencies<FItem, FContext>);
13
+ getRule(identifier: GroupByRuleIdentifier): GroupByRuleDefinition<any, any>;
14
+ get rules(): GroupByRuleDefinition<unknown, any>[];
15
+ get activeRule(): GroupByRuleDefinition<unknown, any> | undefined;
14
16
  get hasGroupByRule(): boolean;
15
- get groupSortDirection(): SortDirection | undefined;
16
- set(identifier?: string | GroupByRule): void;
17
+ get groupBySortDirection(): SortDirection | undefined;
18
+ set(identifier?: GroupByRuleIdentifier): void;
17
19
  setGroupSortDirection(direction?: SortDirection): void;
18
- toggle(identifier: GroupByRule | string): void;
20
+ toggle(identifier: GroupByRuleIdentifier): void;
19
21
  reset(): void;
20
22
  serialize(): SerializedGroupByMixin;
21
23
  static process<FItem>(options: SerializedGroupByMixin, items: FItem[], context: unknown): FinderResultGroup<FItem>[];
@@ -0,0 +1,11 @@
1
+ import { FilterRuleWithBooleanValue, HydratedFilterRuleDefinition } from "../types/rule-types";
2
+ export declare function BooleanFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithBooleanValue): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): boolean;
5
+ has(value: unknown): boolean;
6
+ toggle(value: unknown, optionValue?: any): boolean;
7
+ add(value: unknown, optionValue: any): never;
8
+ delete(value: unknown, optionValue?: any): undefined;
9
+ isActive(value: unknown): boolean;
10
+ isMatch(item: unknown, value: unknown, context: unknown): boolean;
11
+ };
@@ -0,0 +1,29 @@
1
+ import { HydratedFilterRuleDefinition } from "../types/rule-types";
2
+ export declare function makeFilterHandler(definition: HydratedFilterRuleDefinition): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): boolean;
5
+ has(value: unknown): boolean;
6
+ toggle(value: unknown, optionValue?: any): boolean;
7
+ add(value: unknown, optionValue: any): never;
8
+ delete(value: unknown, optionValue?: any): undefined;
9
+ isActive(value: unknown): boolean;
10
+ isMatch(item: unknown, value: unknown, context: unknown): boolean;
11
+ } | {
12
+ validate(value: unknown): boolean;
13
+ parse(value: unknown): any[];
14
+ has(value: unknown, optionValue?: any): boolean;
15
+ toggle(value: unknown, optionValue?: any): any[];
16
+ add(value: unknown, optionValue: any): any[];
17
+ delete(value: unknown, optionValue?: any): any[] | undefined;
18
+ isActive(value: unknown): boolean;
19
+ isMatch(item: any, value: unknown, context: unknown): boolean;
20
+ } | {
21
+ validate(value: unknown): boolean;
22
+ parse(value: unknown): any;
23
+ has(value: unknown): value is {} | null;
24
+ toggle(value: unknown, optionValue?: any): never;
25
+ add(value: unknown, optionValue: any): never;
26
+ delete(value: unknown, optionValue?: any): undefined;
27
+ isActive(value: unknown): boolean;
28
+ isMatch(item: unknown, value: unknown, context: unknown): boolean;
29
+ };
@@ -1,5 +1,5 @@
1
- import { HydratedFilterRule } from "../types/rule-types";
2
- export declare function MultipleFilter(rule: HydratedFilterRule): {
1
+ import { FilterRuleWithMultipleValues, HydratedFilterRuleDefinition } from "../types/rule-types";
2
+ export declare function MultipleFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithMultipleValues): {
3
3
  validate(value: unknown): boolean;
4
4
  parse(value: unknown): any[];
5
5
  has(value: unknown, optionValue?: any): boolean;
@@ -7,4 +7,5 @@ export declare function MultipleFilter(rule: HydratedFilterRule): {
7
7
  add(value: unknown, optionValue: any): any[];
8
8
  delete(value: unknown, optionValue?: any): any[] | undefined;
9
9
  isActive(value: unknown): boolean;
10
+ isMatch(item: any, value: unknown, context: unknown): boolean;
10
11
  };
@@ -0,0 +1,14 @@
1
+ import { RuleDefinition } from "../types/rule-types";
2
+ /**
3
+ * Stores rule definitions and hydrated rules class objects
4
+ */
5
+ export declare class RuleBook<FItem, FContext> {
6
+ #private;
7
+ rules: RuleDefinition[];
8
+ constructor(definitions: RuleDefinition<FItem>[], items: FItem[], context: FContext);
9
+ hydrateDefinitions(items: FItem[], context: FContext): void;
10
+ getRule(identifier: string | RuleDefinition): RuleDefinition;
11
+ getDefinitions(): RuleDefinition<FItem>[];
12
+ setRules(definitions: RuleDefinition<FItem>[]): void;
13
+ static validateDefinitions(definitions: RuleDefinition[]): boolean;
14
+ }
@@ -0,0 +1,11 @@
1
+ import { FilterRuleWithSingleValue, HydratedFilterRuleDefinition } from "../types/rule-types";
2
+ export declare function SingleFilterHandler(definition: HydratedFilterRuleDefinition & FilterRuleWithSingleValue): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): any;
5
+ has(value: unknown): value is {} | null;
6
+ toggle(value: unknown, optionValue?: any): never;
7
+ add(value: unknown, optionValue: any): never;
8
+ delete(value: unknown, optionValue?: any): undefined;
9
+ isActive(value: unknown): boolean;
10
+ isMatch(item: unknown, value: unknown, context: unknown): boolean;
11
+ };
@@ -0,0 +1,2 @@
1
+ import { SerializedSearchMixin } from "../types/core-types";
2
+ export declare function defaultSearchAndSortAlgorithm<FItem>(options: SerializedSearchMixin, items: FItem[], context: unknown): FItem[];
@@ -6,7 +6,7 @@ declare class SearchMixin<FItem> {
6
6
  #private;
7
7
  searchTerm: string;
8
8
  constructor({ initialSearchTerm }: InitialValues, deps: MixinInjectedDependencies<FItem>);
9
- get rule(): import("..").SearchRule<unknown, any> | undefined;
9
+ get rule(): import("..").SearchRuleDefinition<unknown, any> | undefined;
10
10
  get hasSearchRule(): boolean;
11
11
  get hasSearchTerm(): boolean;
12
12
  setSearchTerm(value: string): void;
@@ -1,4 +1,4 @@
1
- import { SortByRule } from "./types/rule-types";
1
+ import { SortByRuleDefinition } from "./types/rule-types";
2
2
  import { MixinInjectedDependencies, SerializedSortByMixin, SortDirection } from "./types/core-types";
3
3
  interface InitialValues {
4
4
  initialSortBy: string | undefined;
@@ -7,15 +7,15 @@ interface InitialValues {
7
7
  declare class SortByMixin<FItem> {
8
8
  #private;
9
9
  constructor({ initialSortBy, initialSortDirection }: InitialValues, deps: MixinInjectedDependencies<FItem>);
10
- getRule(identifier: string | SortByRule): SortByRule<unknown, any>;
11
- get rules(): SortByRule<unknown, any>[];
12
- get activeRule(): SortByRule<unknown, any> | undefined;
10
+ getRule(identifier: string | SortByRuleDefinition): SortByRuleDefinition<any, any>;
11
+ get rules(): SortByRuleDefinition<unknown, any>[];
12
+ get activeRule(): SortByRuleDefinition<unknown, any> | undefined;
13
13
  get sortDirection(): SortDirection;
14
14
  get userHasSetSortDirection(): boolean;
15
15
  setSortDirection(incomingSortDirection?: SortDirection): void;
16
16
  cycleSortDirection(): void;
17
17
  toggleSortDirection(): void;
18
- set(identifier?: string | SortByRule, incomingSortDirection?: SortDirection): void;
18
+ set(identifier?: string | SortByRuleDefinition, incomingSortDirection?: SortDirection): void;
19
19
  reset(): void;
20
20
  serialize(): SerializedSortByMixin;
21
21
  static process<FItem>(options: SerializedSortByMixin, items: FItem[], context: unknown): FItem[];
@@ -1,11 +1,10 @@
1
1
  import { DebounceCallbackRegistry } from "../debounce-callback-registry";
2
- import { FinderCore } from "../finder-core";
3
- import { RuleBook } from "../rule-book";
2
+ import { RuleBook } from "../rule-book/rule-book";
4
3
  import { RuleEffect, SearchEffect } from "./effect-types";
5
4
  import { FinderOnChangeCallback, FinderOnFirstUserInteractCallback, FinderOnInitCallback, FinderOnReadyCallback, FinderTouchCallback } from "./event-types";
6
- import { FinderRule, GroupByRule, HydratedFilterRule, SearchRule, SortByRule } from "./rule-types";
5
+ import { RuleDefinition, GroupByRuleDefinition, SearchRuleDefinition, SortByRuleDefinition, HydratedFilterRuleDefinition } from "./rule-types";
7
6
  export interface FinderConstructorOptions<FItem, FContext = any> {
8
- rules: FinderRule<FItem>[];
7
+ rules: RuleDefinition<FItem>[];
9
8
  effects?: (RuleEffect | SearchEffect)[];
10
9
  context?: FContext;
11
10
  isLoading?: boolean;
@@ -14,6 +13,7 @@ export interface FinderConstructorOptions<FItem, FContext = any> {
14
13
  initialSortBy?: string;
15
14
  initialSortDirection?: SortDirection;
16
15
  initialGroupBy?: string;
16
+ initialGroupBySortDirection?: SortDirection;
17
17
  initialFilters?: Record<string, any>;
18
18
  ignoreSortByRulesWhileSearchRuleIsActive?: boolean;
19
19
  requireGroup?: boolean;
@@ -60,14 +60,14 @@ export interface SnapshotSerializedMixins {
60
60
  }
61
61
  export interface SerializedSearchMixin {
62
62
  searchTerm: string;
63
- rule?: SearchRule;
63
+ rule?: SearchRuleDefinition;
64
64
  }
65
65
  export interface SerializedFiltersMixin {
66
- rules: HydratedFilterRule[];
66
+ rules: HydratedFilterRuleDefinition[];
67
67
  values: Record<string, any>;
68
68
  }
69
69
  export interface SerializedSortByMixin {
70
- rule?: SortByRule;
70
+ rule?: SortByRuleDefinition;
71
71
  sortDirection?: SortDirection;
72
72
  }
73
73
  export interface SerializedPaginationMixin {
@@ -75,12 +75,8 @@ export interface SerializedPaginationMixin {
75
75
  numItemsPerPage?: number;
76
76
  }
77
77
  export interface SerializedGroupByMixin {
78
- rule?: GroupByRule;
79
- sortDirection?: SortDirection;
80
- }
81
- export interface SearchScore {
82
- percentOfHaystackMatched: number;
83
- longestSequentialSequence: number;
78
+ rule?: GroupByRuleDefinition;
79
+ groupBySortDirection?: SortDirection;
84
80
  }
85
81
  export interface PaginationMixinInterface {
86
82
  page: number;
@@ -92,4 +88,3 @@ export interface PaginationMixinInterface {
92
88
  setPage: (value: number) => void;
93
89
  setNumItemsPerPage: (value: number) => void;
94
90
  }
95
- export type SyncListenerFn = (instance: FinderCore) => void;
@@ -1,12 +1,12 @@
1
1
  import { FinderCore } from "../finder-core";
2
- import { FinderRule } from "./rule-types";
2
+ import { RuleDefinition } from "./rule-types";
3
3
  export interface RuleEffect<FItem = any, FContext = any> {
4
- rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]);
5
- onChange: (instance: FinderCore<FItem, FContext>, rule: FinderRule<FItem>) => void;
4
+ rules: string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[] | ((items: FItem[], context: FContext) => string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[]);
5
+ onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition<FItem>) => void;
6
6
  }
7
7
  export interface HydratedRuleEffect<FItem = any, FContext = any> {
8
- rules: (string | FinderRule<FItem>)[];
9
- onChange: (instance: FinderCore<FItem, FContext>, rule: FinderRule<FItem>) => void;
8
+ rules: (string | RuleDefinition<FItem>)[];
9
+ onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition<FItem>) => void;
10
10
  _isHydrated: true;
11
11
  }
12
12
  export interface SearchEffect<FItem = any, FContext = any> {
@@ -1,6 +1,6 @@
1
1
  import { EVENT_SOURCE, EVENTS } from "../core-constants";
2
2
  import { FinderCore } from "../finder-core";
3
- import { FinderRule } from "./rule-types";
3
+ import { RuleDefinition } from "./rule-types";
4
4
  export type FinderTouchSource = (typeof EVENT_SOURCE)[keyof typeof EVENT_SOURCE];
5
5
  interface FinderSharedEventProps {
6
6
  source: string;
@@ -34,7 +34,7 @@ export interface FinderTouchEvent {
34
34
  event: FinderEventName;
35
35
  current: any;
36
36
  initial: any;
37
- rule?: FinderRule;
37
+ rule?: RuleDefinition;
38
38
  }
39
39
  /**
40
40
  * External type that consumers will receive
@@ -3,71 +3,67 @@ import { FinderResultGroup, SortDirection } from "./core-types";
3
3
  * Select a property from the item to sort by.
4
4
  */
5
5
  export type FinderPropertySelector<FItem, FContext = any> = (item: FItem, context: FContext) => string | number;
6
- interface RuleBase {
6
+ interface Rule {
7
7
  id: string;
8
8
  debounceMilliseconds?: number;
9
9
  label?: string;
10
10
  hidden?: boolean;
11
11
  }
12
- export type FinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | FilterRuleUnion<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
13
- export type HydratedFinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
14
- export interface SearchRule<FItem = any, FContext = any> extends Omit<RuleBase, "id"> {
12
+ export type RuleDefinition<FItem = any, FContext = any> = SearchRuleDefinition<FItem, FContext> | FilterRuleDefinition<FItem, FContext> | SortByRuleDefinition<FItem, FContext> | GroupByRuleDefinition<FItem, FContext>;
13
+ export interface SearchRuleDefinition<FItem = any, FContext = any> extends Omit<Rule, "id"> {
15
14
  id?: string;
16
15
  searchFn?: (item: FItem, context: FContext) => string | string[];
17
16
  }
18
- export interface FilterOptionGeneratorFnOptions<FItem, FContext = any> {
19
- items: FItem[];
20
- context: FContext;
21
- }
22
17
  /**
23
18
  * Describes the display of a filter or sort option.
24
19
  */
25
20
  export interface FilterOption<FValue = any> {
26
- label: string;
21
+ label?: string;
27
22
  value: FValue;
28
23
  disabled?: boolean;
29
24
  }
30
- export interface FilterRule<FItem = any, FValue = any, FContext = any> extends RuleBase {
31
- options?: FilterOption<FValue>[] | ((options: FilterOptionGeneratorFnOptions<FItem, FContext>) => FilterOption<FValue>[]);
25
+ export interface FilterRuleDefinition<FItem = any, FValue = any, FContext = any> extends Rule {
26
+ filterFn: (item: FItem, value: FValue, context: FContext) => boolean;
32
27
  required?: boolean;
28
+ strictOptions?: boolean;
29
+ multiple?: boolean;
30
+ boolean?: boolean;
31
+ options?: FilterOption<FValue>[] | ((options: {
32
+ items: FItem[];
33
+ context: FContext;
34
+ }) => FilterOption<FValue>[]);
33
35
  }
34
- export interface FilterRuleWithBooleanValue<FItem, FContext = any> extends FilterRule<FItem> {
36
+ export type AnyFilterRuleDefinition<FItem = any, FValue = any> = Omit<FilterRuleDefinition<FItem, FValue>, "options">;
37
+ export interface FilterRuleWithBooleanValue<FItem = any, FValue = boolean, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
35
38
  multiple?: false;
36
39
  boolean: true;
37
- filterFn: (item: FItem, value: boolean, context: FContext) => boolean;
38
40
  defaultValue?: boolean;
41
+ options?: never;
39
42
  }
40
- export interface FilterRuleWithSingleValue<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
43
+ export interface FilterRuleWithSingleValue<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
41
44
  multiple?: false;
42
45
  boolean?: false;
43
- filterFn: (item: FItem, value: FValue, context: FContext) => boolean;
44
46
  defaultValue?: FValue;
45
47
  }
46
- export interface FilterRuleWithMultipleValues<FItem, FValue, FContext = any> extends FilterRule<FItem, FValue, FContext> {
48
+ export interface FilterRuleWithMultipleValues<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
47
49
  multiple: true;
48
50
  boolean?: false;
49
- filterFn: (item: FItem, value: FValue[], context: FContext) => boolean;
50
51
  defaultValue?: FValue[];
51
52
  }
52
- export type FilterRuleUnion<FItem = any, FValue = any> = FilterRuleWithBooleanValue<FItem> | FilterRuleWithSingleValue<FItem, FValue> | FilterRuleWithMultipleValues<FItem, FValue>;
53
53
  /**
54
54
  * A hydrated filter has rendered any option generator functions, and narrowed ambiguous properties from FilterRule.
55
55
  */
56
- export interface HydratedFilterRule<FItem = any, FValue = any, FContext = any> extends Omit<FilterRule<FItem, FValue>, "options"> {
56
+ export interface HydratedFilterRuleDefinition<FItem = any, FValue = any, FContext = any> extends FilterRuleDefinition<FItem, FValue, FContext> {
57
57
  options?: FilterOption<FValue>[];
58
- required: boolean;
59
- boolean: boolean;
60
- hidden: boolean;
61
58
  multiple: boolean;
62
- filterFn: ((item: FItem, value: FValue, context: FContext) => boolean) | ((item: FItem, value: FValue[], context: FContext) => boolean);
63
- defaultValue?: boolean | FValue | FValue[];
59
+ boolean: boolean;
64
60
  _isHydrated: true;
65
61
  }
66
- export interface SortByRule<FItem = any, FContext = any> extends RuleBase {
62
+ export interface SortByRuleDefinition<FItem = any, FContext = any> extends Rule {
67
63
  sortFn: FinderPropertySelector<FItem, FContext> | FinderPropertySelector<FItem, FContext>[];
68
64
  defaultSortDirection?: SortDirection;
69
65
  }
70
- export interface GroupByRule<FItem = any, FContext = any> extends RuleBase {
66
+ export interface GroupByRuleDefinition<FItem = any, FContext = any> extends Rule {
71
67
  groupFn: FinderPropertySelector<FItem, FContext>;
72
68
  sortGroupFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
73
69
  defaultGroupSortDirection?: SortDirection;
@@ -77,16 +73,16 @@ export interface GroupByRule<FItem = any, FContext = any> extends RuleBase {
77
73
  };
78
74
  }
79
75
  export interface SearchTestOptions {
80
- rule: SearchRule[];
76
+ rule: SearchRuleDefinition[];
81
77
  searchTerm: string;
82
78
  }
83
79
  export interface FilterTestOptions {
84
- rules: HydratedFilterRule[];
80
+ rules: HydratedFilterRuleDefinition[];
85
81
  values?: Record<string, any>;
86
82
  isAdditive?: boolean;
87
83
  }
88
84
  export interface FilterTestRuleOptions {
89
- rule: string | FilterRuleUnion | HydratedFilterRule;
85
+ rule: string | AnyFilterRuleDefinition;
90
86
  value: any;
91
87
  isAdditive?: boolean;
92
88
  }
@@ -1,15 +1,18 @@
1
1
  import { FinderCore } from "../finder-core";
2
2
  import { RuleEffect, SearchEffect } from "../types/effect-types";
3
- import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue, FinderRule, GroupByRule, SearchRule, SortByRule } from "../types/rule-types";
3
+ import { FilterRuleWithBooleanValue, FilterRuleWithMultipleValues, FilterRuleWithSingleValue, RuleDefinition, GroupByRuleDefinition, SearchRuleDefinition, SortByRuleDefinition, AnyFilterRuleDefinition } from "../types/rule-types";
4
4
  /**
5
5
  * Enforce structure for an array of rule of mixed types.
6
6
  */
7
- export declare function finderRuleset<FItem, FContext = any>(rules: FinderRule<FItem, FContext>[]): FinderRule<FItem, FContext>[];
8
- export declare function searchRule<FItem, FContext = any>(rule: SearchRule<FItem, FContext>): SearchRule<FItem, FContext>;
7
+ export declare function finderRuleset<FItem, FContext = any>(rules: RuleDefinition<FItem, FContext>[]): RuleDefinition<FItem, FContext>[];
8
+ export declare function searchRule<FItem, FContext = any>(rule: SearchRuleDefinition<FItem, FContext>): SearchRuleDefinition<FItem, FContext>;
9
9
  export declare function filterRule<FItem, FValue = any, FContext = any, T = FilterRuleWithMultipleValues<FItem, FValue, FContext>>(rule: T): FilterRuleWithMultipleValues<FItem, FValue>;
10
- export declare function filterRule<FItem, FValue = any, FContext = any, T = FilterRuleWithBooleanValue<FItem, FContext>>(rule: T): FilterRuleWithBooleanValue<FItem, FValue>;
10
+ export declare function filterRule<FItem, FValue = boolean, FContext = any, T = FilterRuleWithBooleanValue<FItem, FValue, FContext>>(rule: T): FilterRuleWithBooleanValue<FItem, FValue>;
11
11
  export declare function filterRule<FItem, FValue = any, FContext = any, T = FilterRuleWithSingleValue<FItem, FValue, FContext>>(rule: T): FilterRuleWithSingleValue<FItem, FValue>;
12
- export declare function sortByRule<FItem, FContext = any>(rule: SortByRule<FItem, FContext>): SortByRule<FItem, FContext>;
13
- export declare function groupByRule<FItem, FContext = any>(rule: GroupByRule<FItem, FContext>): GroupByRule<FItem, FContext>;
14
- export declare function ruleEffect<FItem, FContext = any>(rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]), onChange: (instance: FinderCore<FItem, FContext>, rule: FinderRule) => void): RuleEffect<FItem, FContext>;
12
+ export declare function sortByRule<FItem, FContext = any>(rule: SortByRuleDefinition<FItem, FContext>): SortByRuleDefinition<FItem, FContext>;
13
+ export declare function groupByRule<FItem, FContext = any>(rule: GroupByRuleDefinition<FItem, FContext>): GroupByRuleDefinition<FItem, FContext>;
14
+ export declare function ruleEffect<FItem, FContext = any>(rules: string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[] | ((items: FItem[], context: FContext) => string | RuleDefinition<FItem> | (string | RuleDefinition<FItem>)[]), onChange: (instance: FinderCore<FItem, FContext>, rule: RuleDefinition) => void): RuleEffect<FItem, FContext>;
15
15
  export declare function searchEffect<FItem, FContext = any>(haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]), onChange: (instance: FinderCore<FItem, FContext>, searchTerm: string) => void): SearchEffect<FItem, FContext>;
16
+ export declare function transformFilterToSingleValue<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithMultipleValues<FItem, FValue, FContext>;
17
+ export declare function transformFilterToBoolean<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithBooleanValue<FItem, boolean, FContext>;
18
+ export declare function transformFilterToMultiple<FItem, FValue, FContext = any>(filter: AnyFilterRuleDefinition<FItem, FValue>): FilterRuleWithMultipleValues<FItem, FValue, FContext>;