1 | export type Comparer<T> = (a: T, b: T) => number;
|
2 | export type IdSelectorStr<T> = (model: T) => string;
|
3 | export type IdSelectorNum<T> = (model: T) => number;
|
4 | export type IdSelector<T> = IdSelectorStr<T> | IdSelectorNum<T>;
|
5 | export interface DictionaryNum<T> {
|
6 | [id: number]: T | undefined;
|
7 | }
|
8 | export declare abstract class Dictionary<T> implements DictionaryNum<T> {
|
9 | [id: string]: T | undefined;
|
10 | }
|
11 | export interface UpdateStr<T> {
|
12 | id: string;
|
13 | changes: Partial<T>;
|
14 | }
|
15 | export interface UpdateNum<T> {
|
16 | id: number;
|
17 | changes: Partial<T>;
|
18 | }
|
19 | export type Update<T> = UpdateStr<T> | UpdateNum<T>;
|
20 | export type Predicate<T> = (entity: T) => boolean;
|
21 | export type EntityMap<T> = (entity: T) => T;
|
22 | export interface EntityMapOneNum<T> {
|
23 | id: number;
|
24 | map: EntityMap<T>;
|
25 | }
|
26 | export interface EntityMapOneStr<T> {
|
27 | id: string;
|
28 | map: EntityMap<T>;
|
29 | }
|
30 | export type EntityMapOne<T> = EntityMapOneNum<T> | EntityMapOneStr<T>;
|
31 | export interface EntityState<T> {
|
32 | ids: string[] | number[];
|
33 | entities: Dictionary<T>;
|
34 | }
|
35 | export interface EntityDefinition<T> {
|
36 | selectId: IdSelector<T>;
|
37 | sortComparer: false | Comparer<T>;
|
38 | }
|
39 | export interface EntityStateAdapter<T> {
|
40 | addOne<S extends EntityState<T>>(entity: T, state: S): S;
|
41 | addMany<S extends EntityState<T>>(entities: T[], state: S): S;
|
42 | setAll<S extends EntityState<T>>(entities: T[], state: S): S;
|
43 | setOne<S extends EntityState<T>>(entity: T, state: S): S;
|
44 | setMany<S extends EntityState<T>>(entities: T[], state: S): S;
|
45 | removeOne<S extends EntityState<T>>(key: string, state: S): S;
|
46 | removeOne<S extends EntityState<T>>(key: number, state: S): S;
|
47 | removeMany<S extends EntityState<T>>(keys: string[], state: S): S;
|
48 | removeMany<S extends EntityState<T>>(keys: number[], state: S): S;
|
49 | removeMany<S extends EntityState<T>>(predicate: Predicate<T>, state: S): S;
|
50 | removeAll<S extends EntityState<T>>(state: S): S;
|
51 | updateOne<S extends EntityState<T>>(update: Update<T>, state: S): S;
|
52 | updateMany<S extends EntityState<T>>(updates: Update<T>[], state: S): S;
|
53 | upsertOne<S extends EntityState<T>>(entity: T, state: S): S;
|
54 | upsertMany<S extends EntityState<T>>(entities: T[], state: S): S;
|
55 | mapOne<S extends EntityState<T>>(map: EntityMapOne<T>, state: S): S;
|
56 | map<S extends EntityState<T>>(map: EntityMap<T>, state: S): S;
|
57 | }
|
58 | export type EntitySelectors<T, V> = {
|
59 | selectIds: (state: V) => string[] | number[];
|
60 | selectEntities: (state: V) => Dictionary<T>;
|
61 | selectAll: (state: V) => T[];
|
62 | selectTotal: (state: V) => number;
|
63 | };
|
64 | export interface EntityAdapter<T> extends EntityStateAdapter<T> {
|
65 | selectId: IdSelector<T>;
|
66 | sortComparer: false | Comparer<T>;
|
67 | getInitialState(): EntityState<T>;
|
68 | getInitialState<S extends object>(state: S): EntityState<T> & S;
|
69 | getSelectors(): EntitySelectors<T, EntityState<T>>;
|
70 | getSelectors<V>(selectState: (state: V) => EntityState<T>): EntitySelectors<T, V>;
|
71 | }
|
72 |
|
\ | No newline at end of file |