import type { PayloadAction } from '../createAction' ; import type { IsAny } from '../tsHelpers' ; public export type EntityId = number | string ; public export type Comparer < T > = ( a : T , b : T ) => number ; public export type IdSelector < T > = ( model : T ) => EntityId ; public export interface DictionaryNum < T > { [ id ] : T | undefined ; } public export interface Dictionary < T > extends DictionaryNum < T > { [ id ] : T | undefined ; } public export type Update < T > = { id : EntityId ; changes : Partial < T > ; } ; public export interface EntityState < T > { ids : EntityId [ ] ; entities : Dictionary < T > ; } public export interface EntityDefinition < T > { selectId : IdSelector < T > ; sortComparer : false | Comparer < T > ; } export type PreventAny < S , T > = IsAny < S , EntityState < T > , S > ; public export interface EntityStateAdapter < T > { addOne < S extends EntityState < T > > ( state , entity ) : S ; addOne < S extends EntityState < T > > ( state , action ) : S ; addMany < S extends EntityState < T > > ( state , entities ) : S ; addMany < S extends EntityState < T > > ( state , entities ) : S ; setOne < S extends EntityState < T > > ( state , entity ) : S ; setOne < S extends EntityState < T > > ( state , action ) : S ; setMany < S extends EntityState < T > > ( state , entities ) : S ; setMany < S extends EntityState < T > > ( state , entities ) : S ; setAll < S extends EntityState < T > > ( state , entities ) : S ; setAll < S extends EntityState < T > > ( state , entities ) : S ; removeOne < S extends EntityState < T > > ( state , key ) : S ; removeOne < S extends EntityState < T > > ( state , key ) : S ; removeMany < S extends EntityState < T > > ( state , keys ) : S ; removeMany < S extends EntityState < T > > ( state , keys ) : S ; removeAll < S extends EntityState < T > > ( state ) : S ; updateOne < S extends EntityState < T > > ( state , update ) : S ; updateOne < S extends EntityState < T > > ( state , update ) : S ; updateMany < S extends EntityState < T > > ( state , updates ) : S ; updateMany < S extends EntityState < T > > ( state , updates ) : S ; upsertOne < S extends EntityState < T > > ( state , entity ) : S ; upsertOne < S extends EntityState < T > > ( state , entity ) : S ; upsertMany < S extends EntityState < T > > ( state , entities ) : S ; upsertMany < S extends EntityState < T > > ( state , entities ) : S ; } public export interface EntitySelectors < T , V > { selectIds : ( state : V ) => EntityId [ ] ; selectEntities : ( state : V ) => Dictionary < T > ; selectAll : ( state : V ) => T [ ] ; selectTotal : ( state : V ) => number ; selectById : ( state : V , id : EntityId ) => T | undefined ; } public export interface EntityAdapter < T > extends EntityStateAdapter < T > { selectId : IdSelector < T > ; sortComparer : false | Comparer < T > ; getInitialState ( ) : EntityState < T > ; getInitialState < S extends object > ( state ) : EntityState < T > & S ; getSelectors ( ) : EntitySelectors < T , EntityState < T > > ; getSelectors < V > ( selectState ) : EntitySelectors < T , V > ; }