@hitgrab/finder 0.1.5-alpha → 0.1.7-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.
@@ -29,9 +29,15 @@ export declare const ERRORS: {
29
29
  RULE_NOT_FOUND: string;
30
30
  WRONG_RULE_TYPE_FOR_MIXIN: string;
31
31
  NO_SEARCH_RULE_SET: string;
32
+ SETTING_MULTIPLE_FILTER_WITHOUT_ARRAY: string;
33
+ ADDING_OPTION_TO_MULTIPLE_FILTER_WITHOUT_OPTION_VALUE: string;
34
+ DELETING_OPTION_VALUE_FROM_NON_MULTIPLE_FILTER: string;
35
+ SETTING_BOOLEAN_FILTER_WITHOUT_BOOLEAN_VALUE: string;
36
+ ADDING_OPTION_VALUE_TO_NON_MULTIPLE_FILTER: string;
32
37
  TOGGLING_OPTION_ON_RULE_WITH_NO_OPTIONS: string;
33
38
  TOGGLING_OPTION_ON_RULE_WITH_SINGLE_VALUE: string;
34
39
  TOGGLING_OPTION_THAT_DOES_NOT_EXIST: string;
40
+ TOGGLING_OPTION_WITHOUT_PASSING_OPTION: string;
35
41
  TESTING_OPTIONS_ON_RULE_WITH_NO_OPTIONS: string;
36
42
  INVALID_RULE_WITHOUT_ID: string;
37
43
  INVALID_RULE_SHAPE: string;
@@ -1,7 +1,3 @@
1
- declare class DebounceCallbackRegistry {
2
- #private;
3
- register(id: string, delay?: number): void;
4
- has(id: string): boolean;
5
- call(id: string, callback: CallableFunction): void;
6
- }
1
+ import { FinderRule } from "./types/rule-types";
2
+ declare function DebounceCallbackRegistry(): (rule: FinderRule, callback: () => void) => any;
7
3
  export { DebounceCallbackRegistry };
@@ -0,0 +1,10 @@
1
+ import { HydratedFilterRule } from "../types/rule-types";
2
+ export declare function BooleanFilter(rule: HydratedFilterRule): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): any;
5
+ has(value: unknown): any;
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
+ };
@@ -0,0 +1,18 @@
1
+ import { HydratedFilterRule } from "../types/rule-types";
2
+ export declare function makeFilter(rule: HydratedFilterRule): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): any;
5
+ has(value: unknown): any;
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
+ } | {
11
+ validate(value: unknown): boolean;
12
+ parse(value: unknown): any[];
13
+ has(value: unknown, optionValue?: any): boolean;
14
+ toggle(value: unknown, optionValue?: any): any[];
15
+ add(value: unknown, optionValue: any): any[];
16
+ delete(value: unknown, optionValue?: any): any[] | undefined;
17
+ isActive(value: unknown): boolean;
18
+ };
@@ -0,0 +1,10 @@
1
+ import { HydratedFilterRule } from "../types/rule-types";
2
+ export declare function MultipleFilter(rule: HydratedFilterRule): {
3
+ validate(value: unknown): boolean;
4
+ parse(value: unknown): any[];
5
+ has(value: unknown, optionValue?: any): boolean;
6
+ toggle(value: unknown, optionValue?: any): any[];
7
+ add(value: unknown, optionValue: any): any[];
8
+ delete(value: unknown, optionValue?: any): any[] | undefined;
9
+ isActive(value: unknown): boolean;
10
+ };
@@ -0,0 +1,10 @@
1
+ import { HydratedFilterRule } from "../types/rule-types";
2
+ export declare function SingleFilter(rule: HydratedFilterRule): {
3
+ validate(): 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
+ };
@@ -7,22 +7,22 @@ type FilterRuleIdentifier = string | FilterRuleUnion | HydratedFilterRule;
7
7
  declare class FiltersMixin {
8
8
  #private;
9
9
  constructor({ initialFilters }: InitialValues, deps: MixinInjectedDependencies);
10
- set<FValue>(identifier: FilterRuleIdentifier, incomingFilterValue: FValue | FValue[]): void;
10
+ set<FValue>(identifier: FilterRuleIdentifier, value: FValue | FValue[]): void;
11
11
  get rules(): HydratedFilterRule<unknown, any, any>[];
12
12
  get activeRules(): HydratedFilterRule<unknown, any, any>[];
13
13
  get(identifier: FilterRuleIdentifier): any;
14
- has(identifier: FilterRuleIdentifier, optionValue?: any): any;
14
+ has(identifier: FilterRuleIdentifier, optionValue?: any): boolean;
15
15
  getRule(identifier: FilterRuleIdentifier): HydratedFilterRule<any, any, any>;
16
- delete(identifier: FilterRuleIdentifier): void;
16
+ add(identifier: FilterRuleIdentifier, optionValue: any): void;
17
+ delete(identifier: FilterRuleIdentifier, optionValue?: any): void;
17
18
  isRuleActive(identifier: FilterRuleIdentifier): boolean;
18
19
  toggle(identifier: FilterRuleIdentifier, optionValue?: any): void;
19
20
  test(options: FilterTestOptions): any[];
20
21
  testRule({ rule: identifier, value, ...options }: FilterTestRuleOptions): any[];
21
22
  testRuleOptions({ rule: identifier, ...options }: FilterTestRuleOptionsOptions): Map<any, any>;
22
- getValues(): Record<string, any>;
23
- getRawValues(): Record<string, any>;
23
+ get values(): Record<string, any>;
24
+ get raw(): Record<string, any>;
24
25
  serialize(): SerializedFiltersMixin;
25
26
  static process<FItem>(options: SerializedFiltersMixin, items: FItem[], context?: any): FItem[];
26
- static isRuleActive(rule: FilterRuleUnion | HydratedFilterRule, value: any): boolean;
27
27
  }
28
28
  export { FiltersMixin };
@@ -29,7 +29,7 @@ declare class FinderCore<FItem = any, FContext = any> {
29
29
  searchTerm: string;
30
30
  hasSearchTerm: boolean;
31
31
  hasSearchRule: boolean;
32
- setSearchTerm: (incomingSearchTerm: string) => void;
32
+ setSearchTerm: (value: string) => void;
33
33
  reset: () => void;
34
34
  test: (searchTerm: string, isAdditive?: boolean) => FItem[];
35
35
  };
@@ -40,11 +40,12 @@ declare class FinderCore<FItem = any, FContext = any> {
40
40
  rules: import("..").HydratedFilterRule<unknown, any, any>[];
41
41
  isActive: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => boolean;
42
42
  get: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => any;
43
- has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => any;
43
+ add: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue: any) => void;
44
+ has: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => boolean;
44
45
  getRule: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => import("..").HydratedFilterRule<any, any, any>;
45
46
  toggle: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => void;
46
- set: <FValue>(identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, incomingFilterValue: FValue | FValue[]) => void;
47
- delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>) => void;
47
+ set: <FValue>(identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, value: FValue | FValue[]) => void;
48
+ delete: (identifier: string | import("..").FilterRuleUnion | import("..").HydratedFilterRule<any, any, any>, optionValue?: any) => void;
48
49
  test: (options: import("./types/rule-types").FilterTestOptions) => any[];
49
50
  testRule: ({ rule: identifier, value, ...options }: import("./types/rule-types").FilterTestRuleOptions) => any[];
50
51
  testRuleOptions: ({ rule: identifier, ...options }: import("./types/rule-types").FilterTestRuleOptionsOptions) => Map<any, any>;
@@ -9,7 +9,7 @@ declare class SearchMixin<FItem> {
9
9
  get rule(): import("..").SearchRule<unknown, any> | undefined;
10
10
  get hasSearchRule(): boolean;
11
11
  get hasSearchTerm(): boolean;
12
- setSearchTerm(incomingSearchTerm: string): void;
12
+ setSearchTerm(value: string): void;
13
13
  reset(): void;
14
14
  serialize(): SerializedSearchMixin;
15
15
  test(searchTerm: string, isAdditive?: boolean): FItem[];
@@ -42,7 +42,7 @@ export interface MixinInjectedDependencies<FItem = any, FContext = any> {
42
42
  touch: FinderTouchCallback;
43
43
  getItems: () => FItem[];
44
44
  test: (serializedMixins: SnapshotSerializedMixins, isAdditive?: boolean) => FItem[];
45
- debouncer: DebounceCallbackRegistry;
45
+ debouncer: ReturnType<typeof DebounceCallbackRegistry>;
46
46
  }
47
47
  export type EventCallback = (payload?: any) => void;
48
48
  export interface SnapshotOptions<FItem, FContext> {
@@ -2,19 +2,19 @@ import { FinderCore } from "../finder-core";
2
2
  import { FinderRule } from "./rule-types";
3
3
  export interface RuleEffect<FItem = any, FContext = any> {
4
4
  rules: string | FinderRule<FItem> | (string | FinderRule<FItem>)[] | ((items: FItem[], context: FContext) => string | FinderRule<FItem> | (string | FinderRule<FItem>)[]);
5
- onChange: (instance: FinderCore<FItem, FContext>) => void;
5
+ onChange: (instance: FinderCore<FItem, FContext>, rule: FinderRule<FItem>) => void;
6
6
  }
7
7
  export interface HydratedRuleEffect<FItem = any, FContext = any> {
8
8
  rules: (string | FinderRule<FItem>)[];
9
- onChange: (instance: FinderCore<FItem, FContext>) => void;
9
+ onChange: (instance: FinderCore<FItem, FContext>, rule: FinderRule<FItem>) => void;
10
10
  _isHydrated: true;
11
11
  }
12
12
  export interface SearchEffect<FItem = any, FContext = any> {
13
13
  haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]);
14
- onChange: (instance: FinderCore<FItem, FContext>) => void;
14
+ onChange: (instance: FinderCore<FItem, FContext>, searchTerm: string) => void;
15
15
  }
16
16
  export interface HydratedSearchEffect<FItem = any, FContext = any> {
17
17
  haystack: string[];
18
- onChange: (instance: FinderCore<FItem, FContext>) => void;
18
+ onChange: (instance: FinderCore<FItem, FContext>, searchTerm: string) => void;
19
19
  _isHydrated: true;
20
20
  }
@@ -3,13 +3,16 @@ 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 {
7
+ id: string;
8
+ debounceMilliseconds?: number;
9
+ label?: string;
10
+ hidden?: boolean;
11
+ }
6
12
  export type FinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | FilterRuleUnion<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
7
13
  export type HydratedFinderRule<FItem = any, FContext = any> = SearchRule<FItem, FContext> | HydratedFilterRule<FItem, FContext> | SortByRule<FItem, FContext> | GroupByRule<FItem, FContext>;
8
- export interface SearchRule<FItem = any, FContext = any> {
14
+ export interface SearchRule<FItem = any, FContext = any> extends Omit<RuleBase, "id"> {
9
15
  id?: string;
10
- label?: string;
11
- hidden?: boolean;
12
- debounceMilliseconds?: number;
13
16
  searchFn?: (item: FItem, context?: FContext) => string | string[];
14
17
  }
15
18
  export interface FilterOptionGeneratorFnOptions<FItem, FContext = any> {
@@ -24,13 +27,9 @@ export interface FilterOption<FValue = any> {
24
27
  value: FValue;
25
28
  disabled?: boolean;
26
29
  }
27
- export interface FilterRule<FItem = any, FValue = any, FContext = any> {
28
- id: string;
30
+ export interface FilterRule<FItem = any, FValue = any, FContext = any> extends RuleBase {
29
31
  options?: FilterOption<FValue>[] | ((options: FilterOptionGeneratorFnOptions<FItem, FContext>) => FilterOption<FValue>[]);
30
32
  required?: boolean;
31
- label?: string;
32
- hidden?: boolean;
33
- debounceMilliseconds?: number;
34
33
  }
35
34
  export interface FilterRuleWithBooleanValue<FItem, FContext = any> extends FilterRule<FItem> {
36
35
  multiple?: false;
@@ -64,15 +63,11 @@ export interface HydratedFilterRule<FItem = any, FValue = any, FContext = any> e
64
63
  defaultValue?: boolean | FValue | FValue[];
65
64
  _isHydrated: true;
66
65
  }
67
- export interface SortByRule<FItem = any, FContext = any> {
68
- id: string;
66
+ export interface SortByRule<FItem = any, FContext = any> extends RuleBase {
69
67
  sortFn: FinderPropertySelector<FItem, FContext> | FinderPropertySelector<FItem, FContext>[];
70
68
  defaultSortDirection?: SortDirection;
71
- label?: string;
72
- hidden?: boolean;
73
69
  }
74
- export interface GroupByRule<FItem = any, FContext = any> {
75
- id: string;
70
+ export interface GroupByRule<FItem = any, FContext = any> extends RuleBase {
76
71
  groupFn: FinderPropertySelector<FItem, FContext>;
77
72
  sortGroupFn?: FinderPropertySelector<FinderResultGroup<FItem>, FContext>;
78
73
  defaultGroupSortDirection?: SortDirection;
@@ -80,8 +75,6 @@ export interface GroupByRule<FItem = any, FContext = any> {
80
75
  header?: string | string[];
81
76
  footer?: string | string[];
82
77
  };
83
- label?: string;
84
- hidden?: boolean;
85
78
  }
86
79
  export interface SearchTestOptions {
87
80
  rule: SearchRule[];
@@ -102,3 +95,4 @@ export interface FilterTestRuleOptionsOptions {
102
95
  isAdditive?: boolean;
103
96
  mergeExistingValue?: boolean;
104
97
  }
98
+ export {};
@@ -11,5 +11,5 @@ export declare function filterRule<FItem, FValue = any, T = FilterRuleWithBoolea
11
11
  export declare function filterRule<FItem, FValue = any, T = FilterRuleWithSingleValue<FItem, FValue>>(rule: T): FilterRuleWithSingleValue<FItem, FValue>;
12
12
  export declare function sortByRule<FItem>(rule: SortByRule<FItem>): SortByRule<FItem, any>;
13
13
  export declare function groupByRule<FItem>(rule: GroupByRule<FItem>): GroupByRule<FItem, any>;
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>) => void): RuleEffect<FItem, FContext>;
15
- export declare function searchEffect<FItem, FContext = any>(haystack: string | string[] | ((items: FItem[], context: FContext) => string | string[]), onChange: (instance: FinderCore<FItem, FContext>) => void): SearchEffect<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>;
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>;