@ngrx-traits/core 19.2.2 → 20.0.0-beta.1

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.
@@ -1,20 +0,0 @@
1
- export type CacheKey = string | (string | object)[];
2
- export interface CacheData {
3
- value: any;
4
- date: number;
5
- invalid: boolean;
6
- hitCount: number;
7
- }
8
- export interface CacheKeys {
9
- keys?: {
10
- [key: string]: CacheKeys;
11
- };
12
- data?: CacheData;
13
- }
14
- export type CacheState = CacheKeys;
15
- export interface CacheConfig {
16
- expires: number;
17
- }
18
- export declare function hashKey(key: CacheKey): string[];
19
- export declare function getCacheValue(keys: string[], state: CacheState): CacheData | undefined;
20
- export declare function isCacheValid(cache: CacheData, exp: number): boolean;
@@ -1,7 +0,0 @@
1
- import * as i0 from "@angular/core";
2
- import * as i1 from "@ngrx/store";
3
- export declare class CacheModule {
4
- static ɵfac: i0.ɵɵFactoryDeclaration<CacheModule, never>;
5
- static ɵmod: i0.ɵɵNgModuleDeclaration<CacheModule, never, [typeof i1.StoreFeatureModule], never>;
6
- static ɵinj: i0.ɵɵInjectorDeclaration<CacheModule>;
7
- }
@@ -1,3 +0,0 @@
1
- import { CacheKeys, CacheState } from './cache.models';
2
- export declare const initialState: CacheState;
3
- export declare const cacheReducer: import("@ngrx/store").ActionReducer<CacheKeys, import("@ngrx/store").Action<string>>;
@@ -1,3 +0,0 @@
1
- import { CacheKey } from './cache.models';
2
- export declare const cacheStateSelector: import("@ngrx/store").MemoizedSelector<object, import("./cache.models").CacheKeys, import("@ngrx/store").DefaultProjectorFn<import("./cache.models").CacheKeys>>;
3
- export declare const selectCache: (key: CacheKey) => import("@ngrx/store").MemoizedSelector<object, import("./cache.models").CacheData | undefined, (s1: import("./cache.models").CacheKeys) => import("./cache.models").CacheData | undefined>;
@@ -1,66 +0,0 @@
1
- import { Store } from '@ngrx/store';
2
- import { Observable } from 'rxjs';
3
- import { CacheKey } from './cache.models';
4
- /**
5
- * Cache the result of source parameter using the provided key, when call
6
- * again if the cache is valid (exist and is not expired or invalidated)
7
- * it will return the cache value without calling again source
8
- * @example
9
- * // cache for 3 min
10
- * loadStores$ = createEffect(() => {
11
- * return this.actions$.pipe(
12
- * ofType(ProductStoreActions.loadStores),
13
- * exhaustMap(() =>
14
- * cache({
15
- * key: ['stores'],
16
- * store: this.store,
17
- * source: this.storeService.getStores(),
18
- * expire: 1000 * 60 * 3 // optional param , cache forever if not present
19
- * }).pipe(
20
- * map((res) => ProductStoreActions.loadStoresSuccess({ entities: res })),
21
- * catchError(() => of(ProductStoreActions.loadStoresFail()))
22
- * )
23
- * )
24
- * );
25
- * });
26
- * // cache top 10, for 3 mins
27
- * loadDepartments$ = createEffect(() => {
28
- * return this.actions$.pipe(
29
- * ofType(this.localActions.loadDepartments),
30
- * concatLatestFrom(() =>
31
- * this.store.select(this.localSelectors.selectDepartmentsFilter)
32
- * ),
33
- * exhaustMap(([_, filters]) =>
34
- * cache({
35
- * key: ['stores','departments',{ storeId: filters!.storeId },
36
- * store: this.store,
37
- * source: this.storeService.getStoreDepartments(filters!.storeId),
38
- * expires: 1000 * 60 * 3,
39
- * maxCacheSize: 10,
40
- * }).pipe(
41
- * map((res) =>
42
- * this.localActions.loadDepartmentsSuccess({
43
- * entities: res,
44
- * })
45
- * ),
46
- * catchError(() => of(this.localActions.loadDepartmentsFail()))
47
- * )
48
- * )
49
- * );
50
- * });
51
- *
52
- * @param options - configuration
53
- * @param options.store - required ngrx store
54
- * @param options.key - key can be string, array of string or array of string with plain objects
55
- * @param options.source - called when cache is invalid
56
- * @param options.expires - time to expire the cache valued, if not present is infinite
57
- * @param options.maxCacheSize - max number of keys to store , only works if last key is variable
58
- */
59
- export declare function cache<T>({ store, key, source, expires, maxCacheSize, skip, }: {
60
- store: Store;
61
- key: CacheKey;
62
- source: Observable<T>;
63
- expires?: number;
64
- maxCacheSize?: number;
65
- skip?: boolean;
66
- }): Observable<any>;
package/cache/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export * from './cache.service';
2
- export * from './cache.module';
3
- export declare const CacheActions: {
4
- invalidateCache: import("@ngrx/store").ActionCreator<"[Cache] Invalidate Cache", (props: {
5
- key: import("./cache.models").CacheKey;
6
- }) => {
7
- key: import("./cache.models").CacheKey;
8
- } & import("@ngrx/store").Action<"[Cache] Invalidate Cache">>;
9
- deleteCache: import("@ngrx/store").ActionCreator<"[Cache] Delete Cache", (props: {
10
- key: import("./cache.models").CacheKey;
11
- }) => {
12
- key: import("./cache.models").CacheKey;
13
- } & import("@ngrx/store").Action<"[Cache] Delete Cache">>;
14
- };
15
- export declare const CacheSelectors: {
16
- getCache: (key: import("./cache.models").CacheKey) => import("@ngrx/store").MemoizedSelector<object, import("./cache.models").CacheData | undefined, (s1: import("./cache.models").CacheKeys) => import("./cache.models").CacheData | undefined>;
17
- };
@@ -1,250 +0,0 @@
1
- import { Config, ExtractActionsType, ExtractSelectorsType, ExtractStateType, EntityFeatureFactory, FeatureSelectors, KeyedConfig, TraitActions, TraitFactory, TraitSelectors, TraitStateMutators, UnionToIntersection, TraitActionsFactory, TraitSelectorsFactory, TraitInitialStateFactory, TraitStateMutatorsFactory, TraitReducerFactory, TraitEffectsFactory, AllTraitConfigs } from './model';
2
- import { ActionType, MemoizedSelector } from '@ngrx/store';
3
- import { Type } from './local-store';
4
- /**
5
- * Creates a function that when execute will combine all the traits, and return a EntityFeatureFactory
6
- * which combines all the traits actions, selectors , reducers and effects,
7
- * the names param will replace any action and selector with the word Entity or Entities,
8
- * with the corresponding entityName and entitiesName param (entityName+'s' if entitiesName is omitted).
9
- * @param namesConfig - Optional Names for entities
10
- * @param namesConfig.entityName - singular name for entity
11
- * @param [namesConfig.entitiesName] - plural name for entities, defaults to entityName + 's'
12
- * @param traits set of traits to be combined
13
- *
14
- * @example
15
- *
16
- * const featureFactory = createEntityFeatureFactory(
17
- * { entityName: 'product' },
18
- * addLoadEntitiesTrait<Product>(),
19
- * addSelectEntityTrait<Product>(),
20
- * addAsyncActionTrait({
21
- * name: 'checkout',
22
- * actionSuccessProps: props<{ orderId: string }>(),
23
- * })
24
- * );
25
- *
26
- * export const productsFeature = featureFactory({
27
- * actionsGroupKey: '[Products]',
28
- * featureSelector: 'products',
29
- * });
30
- */
31
- export declare function createEntityFeatureFactory<F extends readonly TraitFactory[], EntityName extends string, EntitiesName extends string = `${EntityName}s`>({ entityName, entitiesName, }: {
32
- entityName: EntityName;
33
- entitiesName?: EntitiesName;
34
- }, ...traits: F): EntityFeatureFactory<EntityName, EntitiesName, ExtractStateType<F>, ExtractActionsType<F>, ExtractSelectorsType<F>>;
35
- /**
36
- * Creates a function that when execute will combine all the traits, and return a EntityFeatureFactory
37
- * which combines all the traits actions, selectors , reducers and effects.
38
- * @param traits set of traits to be combined
39
- *
40
- * @example
41
- *
42
- * const featureFactory = createEntityFeatureFactory(
43
- * { entityName: 'product' },
44
- * addLoadEntitiesTrait<Product>(),
45
- * addSelectEntityTrait<Product>(),
46
- * addAsyncActionTrait({
47
- * name: 'checkout',
48
- * actionSuccessProps: props<{ orderId: string }>(),
49
- * })
50
- * );
51
- *
52
- * export const productsFeature = featureFactory({
53
- * actionsGroupKey: '[Products]',
54
- * featureSelector: 'products',
55
- * });
56
- *
57
- * productsFeature.actions.loadProducts();
58
- */
59
- export declare function createEntityFeatureFactory<F extends readonly TraitFactory[]>(...traits: F): EntityFeatureFactory<'Entity', 'Entities', ExtractStateType<F>, ExtractActionsType<F>, ExtractSelectorsType<F>>;
60
- /**
61
- * Combine a map entityFeatureFactories into one,
62
- * grouping the actions and selectors by the key of the respective entityFeatureFactory
63
- * @param traitFactoriesMap
64
- *
65
- * @example
66
- *
67
- * const clientsFeatureFactory = createEntityFeatureFactory(
68
- * { entityName: 'client', entitiesName: 'clients' },
69
- * addLoadEntitiesTrait<Client>(),
70
- * addCrudEntitiesTrait<Client>()
71
- * );
72
- *
73
- * const productOrderFeatureFactory = createEntityFeatureFactory(
74
- * { entityName: 'productOrder' },
75
- * addLoadEntitiesTrait<ProductOrder>(),
76
- * addSelectEntitiesTrait<ProductOrder>()
77
- * );
78
- *
79
- * const productFeatureFactory = createEntityFeatureFactory(
80
- * { entityName: 'product' },
81
- * addLoadEntitiesTrait<Product>(),
82
- * addSelectEntitiesTrait<Product>()
83
- * );
84
- *
85
- * const productCombinedFactory = combineEntityFeatures({
86
- * products: productFeatureFactory,
87
- * productOrders: productOrderFeatureFactory,
88
- * clients: clientsFeatureFactory,
89
- * });
90
- *
91
- * const combinedFeature = productCombinedFactory({
92
- * actionsGroupKey: '[Combined]',
93
- * featureSelector: 'combined',
94
- * });
95
- *
96
- * combinedFeature.actions.client.loadClients();
97
- * combinedFeature.actions.product.loadProducts();
98
- */
99
- export declare function combineEntityFeatures<T extends {
100
- [key: string]: EntityFeatureFactory<any, any>;
101
- }, K extends keyof T, State extends {
102
- [P in K]: ExtractStateType<ReturnType<T[P]>>;
103
- }, A extends {
104
- [P in K]: ExtractActionsType<ReturnType<T[P]>>;
105
- }, S extends {
106
- [P in K]: FeatureSelectors<State, ExtractSelectorsType<ReturnType<T[P]>>>;
107
- }, R extends (config: Config<State>) => {
108
- actions: A;
109
- selectors: S;
110
- reducer: (state: State, action: ActionType<any>) => State;
111
- effects: Type<any>[];
112
- initialState: State;
113
- }>(traitFactoriesMap: T): R;
114
- /**
115
- * Mix a map entityFeatureFactories into one, different from combine the actions and selectors a mix, not group by key like in combine, the keys are still use
116
- * internal in the reducers and selector to separate the state
117
- * @param traitFactoriesMap
118
- *
119
- * @example
120
- *
121
- * const clientsFeatureFactory = createEntityFeatureFactory(
122
- * { entityName: 'client', entitiesName: 'clients' },
123
- * addLoadEntitiesTrait<Client>(),
124
- * addCrudEntitiesTrait<Client>()
125
- * );
126
- *
127
- * const productOrderFeatureFactory = createEntityFeatureFactory(
128
- * { entityName: 'productOrder' },
129
- * addLoadEntitiesTrait<ProductOrder>(),
130
- * addSelectEntitiesTrait<ProductOrder>()
131
- * );
132
- *
133
- * const productFeatureFactory = createEntityFeatureFactory(
134
- * { entityName: 'product' },
135
- * addLoadEntitiesTrait<Product>(),
136
- * addSelectEntitiesTrait<Product>()
137
- * );
138
- *
139
- * const productMixedFactory = mixEntityFeatures({
140
- * products: productFeatureFactory,
141
- * productOrders: productOrderFeatureFactory,
142
- * clients: clientsFeatureFactory,
143
- * });
144
- *
145
- * const mixedFeature = productMixedFactory({
146
- * actionsGroupKey: '[Mixed]',
147
- * featureSelector: 'mixed',
148
- * });
149
- * mixedFeature.actions.loadClients();
150
- * mixedFeature.actions.loadProducts();
151
- *
152
- */
153
- export declare function mixEntityFeatures<T extends {
154
- [key: string]: EntityFeatureFactory<any, any>;
155
- }, K extends keyof T, State extends {
156
- [P in K]: ExtractStateType<ReturnType<T[P]>>;
157
- }, A extends TraitActions & UnionToIntersection<ExtractActionsType<ReturnType<T[K]>>>, S extends TraitSelectors<any> & UnionToIntersection<FeatureSelectors<State, ExtractSelectorsType<ReturnType<T[K]>>>>, R extends EntityFeatureFactory<any, any, State, A, S>>(traitFactoriesMap: T): R;
158
- /**
159
- * Combines targetTraitFactory with the traitFactoriesMap using the keys as props for the targetTraitFactory state,
160
- * and grouping the combined actions by key
161
- * @param targetTraitFactory
162
- * @param traitFactoriesMap
163
- *
164
- * @example
165
- *
166
- * const clientsFeatureFactory = createEntityFeatureFactory(
167
- * { entityName: 'client', entitiesName: 'clients' },
168
- * addLoadEntitiesTrait<Client>(),
169
- * addCrudEntitiesTrait<Client>()
170
- * );
171
- *
172
- * const productOrderFeatureFactory = createEntityFeatureFactory(
173
- * { entityName: 'productOrder' },
174
- * addLoadEntitiesTrait<ProductOrder>(),
175
- * addSelectEntitiesTrait<ProductOrder>()
176
- * );
177
- *
178
- * const productFeatureFactory = createEntityFeatureFactory(
179
- * { entityName: 'product' },
180
- * addLoadEntitiesTrait<Product>(),
181
- * addSelectEntitiesTrait<Product>()
182
- * );
183
- *
184
- * const productAddEntityPropertiesFactory = addEntityFeaturesProperties(
185
- * productFeatureFactory,
186
- * {
187
- * productOrders: productOrderFeatureFactory,
188
- * clients: clientsFeatureFactory,
189
- * }
190
- * );
191
- *
192
- * const combinedFeature = productAddEntityPropertiesFactory({
193
- * actionsGroupKey: '[addEntityFeatures]',
194
- * featureSelector: 'addEntityFeatures',
195
- * });
196
- *
197
- * combinedFeature.actions.loadProducts();
198
- * combinedFeature.actions.clients.loadClients();
199
- * combinedFeature.actions.productOrders.loadProductOrders();
200
- */
201
- export declare function addEntityFeaturesProperties<F extends EntityFeatureFactory<any, any>, T extends {
202
- [key: string]: EntityFeatureFactory<any, any, any, any, any>;
203
- }, K extends keyof T, State extends ExtractStateType<ReturnType<F>> & {
204
- [P in K]: ExtractStateType<ReturnType<T[P]>>;
205
- }, A extends ExtractActionsType<ReturnType<F>> & {
206
- [P in K]: ExtractActionsType<ReturnType<T[P]>>;
207
- }, S extends FeatureSelectors<State, ExtractSelectorsType<ReturnType<F>>> & {
208
- [P in K]: FeatureSelectors<State, ExtractSelectorsType<ReturnType<T[P]>>>;
209
- }, R extends (config: Config<State>) => {
210
- actions: A;
211
- selectors: S;
212
- reducer: (state: State, action: ActionType<any>) => State;
213
- effects: Type<any>[];
214
- initialState: State;
215
- }>(targetTraitFactory: F, traitFactoriesMap: T): R;
216
- /**
217
- * Helper function to create an implementation a TraitFactory
218
- * @param f TraitFactory implementation
219
- */
220
- export declare function createTraitFactory<State = {}, A extends TraitActions = {}, S extends TraitSelectors<State> = {}, M extends TraitStateMutators<State> = {}, KEY extends string = string, C = unknown, KC extends AllTraitConfigs = KeyedConfig<KEY, C>>(f: {
221
- key: KEY;
222
- config?: C;
223
- depends?: string[];
224
- actions?: TraitActionsFactory<A, KC>;
225
- selectors?: TraitSelectorsFactory<State, S, KC>;
226
- initialState?: TraitInitialStateFactory<State, KC>;
227
- mutators?: TraitStateMutatorsFactory<State, M, KC>;
228
- reducer?: TraitReducerFactory<State, A, S, M, KC>;
229
- effects?: TraitEffectsFactory<State, A, S, KC>;
230
- }): TraitFactory<State, A, S, M, KEY, C, KC>;
231
- /**
232
- * Helper function to combine selectors in components as map
233
- *
234
- * @example
235
- *
236
- * view = combineSelectors({
237
- * products: ProductSelectors.selectProductsCurrentPage,
238
- * isLoading: ProductSelectors.isLoadingProductsCurrentPage,
239
- * selectedProduct: ProductSelectors.selectProductSelected,
240
- * isLoadingCheckout: ProductSelectors.isLoadingCheckout,
241
- * selectedSort: ProductSelectors.selectProductsSort,
242
- * filters: ProductSelectors.selectProductsFilter,
243
- * });
244
- * @param t
245
- */
246
- export declare function combineSelectors<T extends {
247
- [k: string]: MemoizedSelector<any, any>;
248
- }>(t: T): MemoizedSelector<any, {
249
- [j in keyof T]: ReturnType<T[j]>;
250
- }>;
@@ -1,6 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
- /**
3
- * @ignore
4
- * @internal
5
- */
6
- export declare const DISABLE_LOCAL_TRAIT_EFFECTS: InjectionToken<boolean>;
@@ -1,2 +0,0 @@
1
- export * from './traits-local-store';
2
- export * from './disable-local-trait-effects.token';
@@ -1,106 +0,0 @@
1
- import { Injector, OnDestroy } from '@angular/core';
2
- import { BaseEntityFeatureFactory } from '../model';
3
- import { TraitEffect } from '../trait-effect';
4
- import * as i0 from "@angular/core";
5
- /**
6
- * Builds traitFactory and registers effects and reducers with
7
- * a generated component id, returns build actions and selectors
8
- * and a destroy method that will unergister the effects and reducers
9
- * when called, and a addEffect which can be use to register extra effects
10
- *
11
- * Used inside TraitsLocalStore, can be used to create your
12
- * own Component Service without extending TraitsLocalStore
13
- * @param injector
14
- * @param componentName
15
- * @param traitFactory
16
- */
17
- export declare function buildLocalTraits<State, F extends BaseEntityFeatureFactory<any, any, any>>(injector: Injector, componentName: string, traitFactory: F): {
18
- destroy: () => void;
19
- actions: any;
20
- selectors: any;
21
- addEffects(localEffect: TraitEffect): void;
22
- };
23
- export interface Type<T> extends Function {
24
- new (...args: any[]): T;
25
- }
26
- export interface LocalTraitsConfig<F extends BaseEntityFeatureFactory<any, any, any>> {
27
- componentName: string;
28
- traitsFactory: F;
29
- }
30
- /**
31
- * Class used to create local traits service, receives a trait factory, which will be
32
- * built and its reducers and effect register using a dynamic id when the service is built
33
- * and get destroyed when the onDestroy lifecycle method of the service is called, if the service
34
- * has effects this.traits.addEffects(this) should be call in the constructor
35
- *
36
- * @example
37
- * const productFeatureFactory = createEntityFeatureFactory(
38
- * { entityName: 'product' },
39
- * addLoadEntitiesTrait<Product>(),
40
- * addSelectEntityTrait<Product>(),
41
- * );
42
- *
43
- * Injectable()
44
- * export class ProductsLocalTraits extends TraitsLocalStore<
45
- * typeof productFeatureFactory
46
- * > {
47
- * loadProducts$ = createEffect(() =>
48
- * this.actions$.pipe(
49
- * ofType(this.localActions.loadProducts),
50
- * switchMap(() =>
51
- * //call your service to get the products data
52
- * this.productService.getProducts().pipe(
53
- * map((res) =>
54
- * this.localActions.loadProductsSuccess({ entities: res.resultList })
55
- * ),
56
- * catchError(() => of(this.localActions.loadProductsFail()))
57
- * )
58
- * )
59
- * )
60
- * );
61
- *
62
- * constructor(injector: Injector, private productService: ProductService) {
63
- * super(injector);
64
- * this.traits.addEffects(this); // IMPORTANT! add this line if the service has effects
65
- * }
66
- *
67
- * setup(): LocalTraitsConfig<typeof productFeatureFactory> {
68
- * return {
69
- * componentName: 'ProductsPickerComponent',
70
- * traitsFactory: productFeatureFactory,
71
- * };
72
- * }
73
- * }
74
- *
75
- * // use in component later
76
- *
77
- * Component({
78
- * selector: 'some-component',
79
- * template: `<div> some content</div> `,
80
- * providers: [ProductsLocalTraits],
81
- * changeDetection: ChangeDetectionStrategy.OnPush,
82
- * })
83
- * export class ProductSelectDialogComponent implements OnInit {
84
- * constructor(private store: Store, private traits: ProductsLocalTraits) {}
85
- *
86
- * ngOnInit() {
87
- * this.store.dispatch(this.traits.localActions.loadProducts());
88
- * }
89
- * }
90
- */
91
- export declare abstract class TraitsLocalStore<F extends BaseEntityFeatureFactory<any, any, any>> extends TraitEffect implements OnDestroy {
92
- traits: {
93
- actions: ReturnType<F>['actions'];
94
- selectors: ReturnType<F>['selectors'];
95
- destroy: () => void;
96
- addEffects: (localEffect: TraitEffect) => void;
97
- };
98
- localActions: ReturnType<F>['actions'];
99
- localSelectors: ReturnType<F>['selectors'];
100
- private injector;
101
- constructor();
102
- abstract setup(): LocalTraitsConfig<F>;
103
- ngOnDestroy(): void;
104
- static ɵfac: i0.ɵɵFactoryDeclaration<TraitsLocalStore<any>, never>;
105
- static ɵprov: i0.ɵɵInjectableDeclaration<TraitsLocalStore<any>>;
106
- }
package/model.d.ts DELETED
@@ -1,103 +0,0 @@
1
- import { Type } from '@angular/core';
2
- import { Action, ActionType, MemoizedSelector } from '@ngrx/store';
3
- import { ActionCreator, Selector, SelectorWithProps } from '@ngrx/store/src/models';
4
- import { TraitEffect } from './trait-effect';
5
- export type TraitActions = {
6
- [key: string]: ActionCreator<string, (...args: any[]) => Action<string>>;
7
- };
8
- export type TraitSelectors<State> = {
9
- [key: string]: Selector<State, any> | SelectorWithProps<State, any, any> | MemoizedSelector<State, any>;
10
- };
11
- export type TraitStateMutators<State> = {
12
- [key: string]: <S extends State>(...arg: any[]) => S;
13
- };
14
- export interface BaseFeatureTraits<State = any, A = any, S = any> {
15
- actions: A;
16
- selectors: S;
17
- reducer: (state: State, action: ActionType<any>) => State;
18
- effects: Type<any>[];
19
- initialState: State;
20
- }
21
- export type FeatureTraits<State, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>> = BaseFeatureTraits<State, A, FeatureSelectors<State, S>>;
22
- export type BaseEntityFeatureFactory<State, A, S> = (config: Config<State>) => BaseFeatureTraits<State, A, S>;
23
- export type EntityFeatureFactory<EntityName extends string | undefined, EntitiesName extends string = `${EntityName}s`, State = any, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>> = (config: Config<State>) => FeatureTraits<State, EntityName extends string ? ReplaceEntityNames<A, EntityName, EntitiesName> : A, EntityName extends string ? ReplaceEntityNames<S, EntityName, EntitiesName> : S>;
24
- export type Config<State, F extends MemoizedSelector<object, State> = MemoizedSelector<object, State>> = {
25
- actionsGroupKey: string;
26
- featureSelector: F | string;
27
- };
28
- export type FeatureSelectors<State, S extends TraitSelectors<State>> = {
29
- [key in keyof S]: MemoizedSelector<object, ReturnType<S[key]>, S[key]>;
30
- };
31
- export type AllTraitConfigs = {
32
- [id: string]: any;
33
- };
34
- export type TraitActionsFactory<A extends TraitActions = TraitActions, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitActionsFactoryConfig<C>) => A;
35
- export type TraitActionsFactoryConfig<C extends AllTraitConfigs = AllTraitConfigs> = {
36
- actionsGroupKey: string;
37
- entityName: string;
38
- entitiesName: string;
39
- allConfigs: C;
40
- };
41
- export type TraitSelectorsFactory<State = unknown, S extends TraitSelectors<State> = TraitSelectors<State>, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitSelectorsFactoryConfig<C>) => S;
42
- export type TraitSelectorsFactoryConfig<C extends AllTraitConfigs = AllTraitConfigs> = {
43
- previousSelectors: TraitSelectors<unknown> | undefined;
44
- allConfigs: C;
45
- };
46
- export type TraitInitialStateFactory<State = unknown, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitInitialStateFactoryConfig<C>) => State;
47
- export type TraitInitialStateFactoryConfig<C extends AllTraitConfigs = AllTraitConfigs> = {
48
- previousInitialState: any;
49
- allConfigs: C;
50
- };
51
- export type TraitStateMutatorsFactory<State = unknown, M extends TraitStateMutators<State> = TraitStateMutators<State>, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitStateMutatorsFactoryConfig<C>) => M;
52
- export type TraitStateMutatorsFactoryConfig<C extends AllTraitConfigs = AllTraitConfigs> = {
53
- allSelectors: TraitSelectors<any>;
54
- previousMutators: TraitStateMutators<unknown> | undefined;
55
- allConfigs: C;
56
- };
57
- export type TraitReducerFactory<State = unknown, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>, M extends TraitStateMutators<State> = TraitStateMutators<State>, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitReducerFactoryConfig<State, A, S, M, C>) => (initialState: State, action: Action) => State;
58
- export type TraitReducerFactoryConfig<State = unknown, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>, M extends TraitStateMutators<State> = TraitStateMutators<State>, C extends AllTraitConfigs = AllTraitConfigs> = {
59
- initialState: State;
60
- allActions: A;
61
- allSelectors: S;
62
- allMutators: M;
63
- allConfigs: C;
64
- };
65
- export type TraitEffectsFactory<State = unknown, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>, C extends AllTraitConfigs = AllTraitConfigs> = (options: TraitEffectsFactoryConfig<State, A, S, C>) => Type<TraitEffect>[];
66
- export type TraitEffectsFactoryConfig<State = unknown, A extends TraitActions = TraitActions, S extends TraitSelectors<State> = TraitSelectors<State>, C extends AllTraitConfigs = AllTraitConfigs> = {
67
- allActions: A;
68
- allSelectors: S;
69
- allConfigs: C;
70
- };
71
- export type KeyedConfig<KEY extends string, C> = Record<string, any> & {
72
- [K in KEY]?: C;
73
- };
74
- export interface TraitFactory<State = any, A extends TraitActions = any, S extends TraitSelectors<State> = any, M extends TraitStateMutators<State> = any, KEY extends string = string, C = any, KC extends AllTraitConfigs = KeyedConfig<KEY, C>> {
75
- key: KEY;
76
- config?: C;
77
- depends?: string[];
78
- actions: TraitActionsFactory<A, KC>;
79
- selectors: TraitSelectorsFactory<State, S, KC>;
80
- initialState: TraitInitialStateFactory<State, KC>;
81
- mutators: TraitStateMutatorsFactory<State, M, KC>;
82
- reducer?: TraitReducerFactory<State, A, S, M, KC>;
83
- effects?: TraitEffectsFactory<State, A, S, KC>;
84
- }
85
- type ExtractArrayElementTypes<X> = X extends ReadonlyArray<infer T> ? T : never;
86
- export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
87
- export type ExtractStateType<T> = T extends TraitFactory<infer State> ? State : T extends ReadonlyArray<TraitFactory> ? UnionToIntersection<ExtractStateType<ExtractArrayElementTypes<T>>> : T extends BaseFeatureTraits<infer State> ? State : never;
88
- export type ExtractActionsType<T> = T extends TraitFactory<any, infer A> ? A : T extends ReadonlyArray<TraitFactory> ? UnionToIntersection<ExtractActionsType<ExtractArrayElementTypes<T>>> : T extends BaseFeatureTraits<any, infer A> ? A : never;
89
- export type ExtractSelectorsType<T> = T extends TraitFactory<any, any, infer S> ? S : T extends ReadonlyArray<TraitFactory> ? UnionToIntersection<ExtractSelectorsType<ExtractArrayElementTypes<T>>> : T extends BaseFeatureTraits<any, any, infer S> ? S : never;
90
- export type ExtractMutatorsType<T> = T extends TraitFactory<any, any, any, infer M> ? M : T extends ReadonlyArray<TraitFactory> ? UnionToIntersection<ExtractMutatorsType<ExtractArrayElementTypes<T>>> : never;
91
- export type ExtractKeyedConfigType<T> = T extends TraitFactory<any, any, any, any, infer KEY, infer C> ? KeyedConfig<KEY, C> : T extends ReadonlyArray<TraitFactory> ? UnionToIntersection<ExtractKeyedConfigType<ExtractArrayElementTypes<T>>> : never;
92
- export type PrefixProps<T, P extends string> = {
93
- [K in keyof T as `${P}${Capitalize<string & K>}`]: T[K];
94
- };
95
- export type PostfixProps<T, P extends string> = {
96
- [K in keyof T as `${Uncapitalize<string & K>}${Capitalize<P>}`]: T[K];
97
- };
98
- type Replace<Target extends string, FindKey extends string, FindKey2 extends string, ReplaceKey extends string, ReplaceKey2 extends string> = Target extends `${infer Prefix}${FindKey}${infer Postfix}` ? `${Prefix}${Capitalize<ReplaceKey>}${Postfix}` : Target extends `${infer Prefix}${FindKey2}${infer Postfix}` ? `${Prefix}${Capitalize<ReplaceKey2>}${Postfix}` : Target;
99
- export type ReplaceProps<Target, FindKey extends string, FindKey2 extends string, ReplaceKey extends string, ReplaceKey2 extends string> = {
100
- [Prop in keyof Target as Replace<string & Prop, FindKey, FindKey2, ReplaceKey, ReplaceKey2>]: Target[Prop];
101
- };
102
- export type ReplaceEntityNames<T, EntityName extends string, EntitiesName extends string> = ReplaceProps<T, 'Entities', 'Entity', EntitiesName, EntityName>;
103
- export {};
@@ -1,8 +0,0 @@
1
- import { EntityFeatureFactory, TraitsLocalStore } from '@ngrx-traits/core';
2
- import { Provider, Type } from '@angular/core';
3
- export declare function provideMockLocalTraits<T extends TraitsLocalStore<EntityFeatureFactory<any, any>>>({ traitFactory, selectors, }: {
4
- traitFactory: Type<T>;
5
- selectors?: {
6
- [key in keyof T['localSelectors']]?: ReturnType<T['localSelectors'][key]>;
7
- };
8
- }): Provider[];
package/trait-effect.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { Actions, OnIdentifyEffects, OnRunEffects } from '@ngrx/effects';
2
- import { Store } from '@ngrx/store';
3
- import { Observable } from 'rxjs';
4
- import * as i0 from "@angular/core";
5
- export declare class TraitEffect implements OnIdentifyEffects, OnRunEffects {
6
- private name;
7
- componentId: string;
8
- protected actions$: Actions<any>;
9
- protected store: Store<any>;
10
- ngrxOnIdentifyEffects(): string;
11
- ngrxOnRunEffects(resolvedEffects$: Observable<any>): Observable<any>;
12
- static ɵfac: i0.ɵɵFactoryDeclaration<TraitEffect, never>;
13
- static ɵprov: i0.ɵɵInjectableDeclaration<TraitEffect>;
14
- }
15
- export declare function getDestroyActionName(id: string): string;
package/util.d.ts DELETED
@@ -1,43 +0,0 @@
1
- import { ReducerTypes } from '@ngrx/store/src/reducer_creator';
2
- import { ActionCreator } from '@ngrx/store/src/models';
3
- import { ActionType } from '@ngrx/store';
4
- export declare function insertIf<State>(condition: any, getElement: () => ReducerTypes<State, ActionCreator[]>): ReducerTypes<State, ActionCreator[]>[];
5
- export declare function toMap(a: Array<string | number>): {
6
- [key: string]: boolean;
7
- };
8
- export declare function capitalize(name: string): string;
9
- export declare function camelCaseToSentence(text: string): string;
10
- /**
11
- * Set propertyReducer in sourceReducer in a property of the source state,
12
- * @param sourceReducer
13
- * @param property
14
- * @param propertyReducer
15
- *
16
- * @example
17
- *
18
- * const newReducer = setPropertyReducer(productsReducer, 'selectedProduct', selectedProductReducer)
19
- */
20
- export declare function setPropertyReducer<State, P extends keyof State>(sourceReducer: (state: State, action: ActionType<any>) => State, property: P, propertyReducer: (state: State[P], action: ActionType<any>) => State[P]): (state: State, action: ActionType<any>) => State;
21
- /**
22
- * Set propertyReducers in sourceReducer each in a property of the source state,
23
- * @param sourceReducer
24
- * @param property
25
- * @param propertyReducer
26
- *
27
- * @example
28
- *
29
- * const newReducer = setPropertyReducer(productsReducer,
30
- * {
31
- * selectedProduct: selectedProductReducer
32
- * favoriteProduct: favoriteProductReducer
33
- * })
34
- */
35
- export declare function setPropertiesReducer<State, P extends keyof State>(sourceReducer: (state: State, action: ActionType<any>) => State, propertiesReducers: {
36
- [key in P]: (state: State[P], action: ActionType<any>) => State[P];
37
- }): (state: State, action: ActionType<any>) => State;
38
- /**
39
- * joins two reducers so the work in the same state
40
- * @param firstReducer
41
- * @param secondReducer
42
- */
43
- export declare function joinReducers<State>(firstReducer: (state: State, action: ActionType<any>) => State, secondReducer: (state: any, action: ActionType<any>) => any): (state: State, action: ActionType<any>) => State;