ngssm-store 20.0.4 → 20.0.6

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.
@@ -36,7 +36,7 @@ interface CachedItem<TData = unknown> {
36
36
  * @remarks
37
37
  * This action is dispatched to update the cache with a new or modified item, along with its status and any error information.
38
38
  */
39
- declare class SetCachedItemAction<TData = never> implements Action {
39
+ declare class SetCachedItemAction<TData = unknown> implements Action {
40
40
  readonly cachedItemKey: string;
41
41
  readonly cachedItem: TData;
42
42
  readonly status: CachedItemStatus;
@@ -0,0 +1,46 @@
1
+ import * as i0 from '@angular/core';
2
+ import { EnvironmentProviders } from '@angular/core';
3
+ import { SetCachedItemAction, CachedItemStatus } from 'ngssm-store/caching';
4
+ import { StoreMock } from 'ngssm-store/testing';
5
+
6
+ /**
7
+ * App initializer that sets up the NgssmCaching state in the StoreMock for testing purposes.
8
+ * Throws an error if StoreMock is not registered.
9
+ */
10
+ declare const ngssmCachingStateInitializer: () => void;
11
+ /**
12
+ * Provides environment providers for NgssmCaching testing, including the state initializer.
13
+ */
14
+ declare const provideNgssmCachingTesting: () => EnvironmentProviders;
15
+
16
+ /**
17
+ * Utility service for setting and updating cached items in the StoreMock during tests.
18
+ * Provides methods to apply a SetCachedItemAction, set the status, or set the value of a cached item.
19
+ */
20
+ declare class NgssmCachedItemSetter {
21
+ readonly store: StoreMock;
22
+ /**
23
+ * Applies a SetCachedItemAction to the StoreMock, updating the cache state.
24
+ * @param action The SetCachedItemAction to apply.
25
+ * @returns The NgssmCachedItemSetter instance for chaining.
26
+ */
27
+ apply<T = unknown>(action: SetCachedItemAction<T>): NgssmCachedItemSetter;
28
+ /**
29
+ * Sets the status of a cached item in the StoreMock.
30
+ * @param cacheItemKey The key of the cached item.
31
+ * @param status The new status to set.
32
+ * @returns The NgssmCachedItemSetter instance for chaining.
33
+ */
34
+ setCacheItemStatus(cacheItemKey: string, status: CachedItemStatus): NgssmCachedItemSetter;
35
+ /**
36
+ * Sets the value of a cached item in the StoreMock.
37
+ * @param cacheItemKey The key of the cached item.
38
+ * @param value The value to set.
39
+ * @returns The NgssmCachedItemSetter instance for chaining.
40
+ */
41
+ setCacheItemValue<T>(cacheItemKey: string, value?: T): NgssmCachedItemSetter;
42
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgssmCachedItemSetter, never>;
43
+ static ɵprov: i0.ɵɵInjectableDeclaration<NgssmCachedItemSetter>;
44
+ }
45
+
46
+ export { NgssmCachedItemSetter, ngssmCachingStateInitializer, provideNgssmCachingTesting };
@@ -0,0 +1,101 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, Injectable, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
3
+ import { Store, Logger } from 'ngssm-store';
4
+ import { StoreMock } from 'ngssm-store/testing';
5
+ import { updateNgssmCachingState, NgssmCachingStateSpecification } from 'ngssm-store/caching';
6
+
7
+ /**
8
+ * Utility service for setting and updating cached items in the StoreMock during tests.
9
+ * Provides methods to apply a SetCachedItemAction, set the status, or set the value of a cached item.
10
+ */
11
+ class NgssmCachedItemSetter {
12
+ constructor() {
13
+ this.store = inject(Store);
14
+ }
15
+ /**
16
+ * Applies a SetCachedItemAction to the StoreMock, updating the cache state.
17
+ * @param action The SetCachedItemAction to apply.
18
+ * @returns The NgssmCachedItemSetter instance for chaining.
19
+ */
20
+ apply(action) {
21
+ this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
22
+ caches: {
23
+ [action.cachedItemKey]: {
24
+ $set: {
25
+ status: action.status,
26
+ item: action.cachedItem,
27
+ error: action.error
28
+ }
29
+ }
30
+ }
31
+ });
32
+ return this;
33
+ }
34
+ /**
35
+ * Sets the status of a cached item in the StoreMock.
36
+ * @param cacheItemKey The key of the cached item.
37
+ * @param status The new status to set.
38
+ * @returns The NgssmCachedItemSetter instance for chaining.
39
+ */
40
+ setCacheItemStatus(cacheItemKey, status) {
41
+ this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
42
+ caches: {
43
+ [cacheItemKey]: {
44
+ status: { $set: status }
45
+ }
46
+ }
47
+ });
48
+ return this;
49
+ }
50
+ /**
51
+ * Sets the value of a cached item in the StoreMock.
52
+ * @param cacheItemKey The key of the cached item.
53
+ * @param value The value to set.
54
+ * @returns The NgssmCachedItemSetter instance for chaining.
55
+ */
56
+ setCacheItemValue(cacheItemKey, value) {
57
+ this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
58
+ caches: {
59
+ [cacheItemKey]: {
60
+ item: { $set: value }
61
+ }
62
+ }
63
+ });
64
+ return this;
65
+ }
66
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmCachedItemSetter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
67
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmCachedItemSetter }); }
68
+ }
69
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmCachedItemSetter, decorators: [{
70
+ type: Injectable
71
+ }] });
72
+
73
+ /**
74
+ * App initializer that sets up the NgssmCaching state in the StoreMock for testing purposes.
75
+ * Throws an error if StoreMock is not registered.
76
+ */
77
+ const ngssmCachingStateInitializer = () => {
78
+ const logger = inject(Logger);
79
+ logger.information('[ngssm-caching-testing] Initialization of state');
80
+ const store = inject(Store);
81
+ if (!(store instanceof StoreMock)) {
82
+ throw new Error('StoreMock is not registered.');
83
+ }
84
+ store.stateValue = {
85
+ ...store.stateValue,
86
+ [NgssmCachingStateSpecification.featureStateKey]: NgssmCachingStateSpecification.initialState
87
+ };
88
+ };
89
+ /**
90
+ * Provides environment providers for NgssmCaching testing, including the state initializer.
91
+ */
92
+ const provideNgssmCachingTesting = () => {
93
+ return makeEnvironmentProviders([provideAppInitializer(ngssmCachingStateInitializer), NgssmCachedItemSetter]);
94
+ };
95
+
96
+ /**
97
+ * Generated bundle index. Do not edit.
98
+ */
99
+
100
+ export { NgssmCachedItemSetter, ngssmCachingStateInitializer, provideNgssmCachingTesting };
101
+ //# sourceMappingURL=ngssm-store-caching-testing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngssm-store-caching-testing.mjs","sources":["../../../projects/ngssm-store/caching/testing/src/ngssm-cached-item-setter.ts","../../../projects/ngssm-store/caching/testing/src/provide-ngssm-caching-testing.ts","../../../projects/ngssm-store/caching/testing/ngssm-store-caching-testing.ts"],"sourcesContent":["import { inject, Injectable } from '@angular/core';\n\nimport { Store } from 'ngssm-store';\nimport { CachedItemStatus, SetCachedItemAction, updateNgssmCachingState } from 'ngssm-store/caching';\nimport { StoreMock } from 'ngssm-store/testing';\n\n/**\n * Utility service for setting and updating cached items in the StoreMock during tests.\n * Provides methods to apply a SetCachedItemAction, set the status, or set the value of a cached item.\n */\n@Injectable()\nexport class NgssmCachedItemSetter {\n public readonly store = inject(Store) as unknown as StoreMock;\n\n /**\n * Applies a SetCachedItemAction to the StoreMock, updating the cache state.\n * @param action The SetCachedItemAction to apply.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public apply<T = unknown>(action: SetCachedItemAction<T>): NgssmCachedItemSetter {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [action.cachedItemKey]: {\n $set: {\n status: action.status,\n item: action.cachedItem,\n error: action.error\n }\n }\n }\n });\n\n return this;\n }\n\n /**\n * Sets the status of a cached item in the StoreMock.\n * @param cacheItemKey The key of the cached item.\n * @param status The new status to set.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public setCacheItemStatus(cacheItemKey: string, status: CachedItemStatus): NgssmCachedItemSetter {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cacheItemKey]: {\n status: { $set: status }\n }\n }\n });\n\n return this;\n }\n\n /**\n * Sets the value of a cached item in the StoreMock.\n * @param cacheItemKey The key of the cached item.\n * @param value The value to set.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public setCacheItemValue<T>(cacheItemKey: string, value?: T): NgssmCachedItemSetter {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cacheItemKey]: {\n item: { $set: value }\n }\n }\n });\n\n return this;\n }\n}\n","import { EnvironmentProviders, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\n\nimport { Logger, Store } from 'ngssm-store';\nimport { StoreMock } from 'ngssm-store/testing';\nimport { NgssmCachingStateSpecification } from 'ngssm-store/caching';\n\nimport { NgssmCachedItemSetter } from './ngssm-cached-item-setter';\n\n/**\n * App initializer that sets up the NgssmCaching state in the StoreMock for testing purposes.\n * Throws an error if StoreMock is not registered.\n */\nexport const ngssmCachingStateInitializer = () => {\n const logger = inject(Logger);\n logger.information('[ngssm-caching-testing] Initialization of state');\n const store = inject(Store);\n if (!(store instanceof StoreMock)) {\n throw new Error('StoreMock is not registered.');\n }\n\n store.stateValue = {\n ...store.stateValue,\n [NgssmCachingStateSpecification.featureStateKey]: NgssmCachingStateSpecification.initialState\n };\n};\n\n/**\n * Provides environment providers for NgssmCaching testing, including the state initializer.\n */\nexport const provideNgssmCachingTesting = (): EnvironmentProviders => {\n return makeEnvironmentProviders([provideAppInitializer(ngssmCachingStateInitializer), NgssmCachedItemSetter]);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;AAMA;;;AAGG;MAEU,qBAAqB,CAAA;AADlC,IAAA,WAAA,GAAA;AAEkB,QAAA,IAAA,CAAA,KAAK,GAAG,MAAM,CAAC,KAAK,CAAyB;AA0D9D;AAxDC;;;;AAIG;AACI,IAAA,KAAK,CAAc,MAA8B,EAAA;AACtD,QAAA,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;AACrE,YAAA,MAAM,EAAE;AACN,gBAAA,CAAC,MAAM,CAAC,aAAa,GAAG;AACtB,oB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Y,SAAS,CAAC,EAAE;AACjC,QAAA,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC;;IAGjD,KAAK,CAAC,UAAU,GAAG;QACjB,GAAG,KAAK,CAAC,UAAU;AACnB,QAAA,CAAC,8BAA8B,CAAC,eAAe,GAAG,8BAA8B,CAAC;KAClF;AACH;AAEA;;AAEG;AACI,MAAM,0BAA0B,GAAG,MAA2B;IACnE,OAAO,wBAAwB,CAAC,CAAC,qBAAqB,CAAC,4BAA4B,CAAC,EAAE,qBAAqB,CAAC,CAAC;AAC/G;;AC/BA;;AAEG;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ngssm-store-caching.mjs","sources":["../../../projects/ngssm-store/caching/src/actions/ngssm-caching-action-type.ts","../../../projects/ngssm-store/caching/src/model/cached-item-status.ts","../../../projects/ngssm-store/caching/src/actions/set-cached-item.action.ts","../../../projects/ngssm-store/caching/src/actions/unset-cached-item.action.ts","../../../projects/ngssm-store/caching/src/state/ngssm-caching.state.ts","../../../projects/ngssm-store/caching/src/state/selectors.ts","../../../projects/ngssm-store/caching/src/reducers/cached-item.reducer.ts","../../../projects/ngssm-store/caching/src/provide-ngssm-caching.ts","../../../projects/ngssm-store/caching/ngssm-store-caching.ts"],"sourcesContent":["export enum NgssmCachingActionType {\n setCachedItem = '[NgssmCachingActionType] setCachedItem',\n unsetCachedItem = '[NgssmCachingActionType] unsetCachedItem'\n}\n","export enum CachedItemStatus {\n notSet = 'Not Set',\n loading = 'Loading',\n set = 'Set',\n error = 'Error'\n}\n","import { Action } from 'ngssm-store';\n\nimport { NgssmCachingActionType } from './ngssm-caching-action-type';\nimport { CachedItemStatus } from '../model';\n\n/**\n * Represents an action to set a cached item in the state. If key is already set in the state, the value is replaced by the new one.\n *\n * @template TData The type of the cached item's data.\n * @implements {Action}\n *\n * @property {string} cachedItemKey - The unique key identifying the cached item.\n * @property {TData} cachedItem - The data to be cached.\n * @property {CachedItemStatus} [status=CachedItemStatus.set] - The status of the cached item operation.\n * @property {string} [error] - An optional error message if the caching operation failed.\n *\n * @remarks\n * This action is dispatched to update the cache with a new or modified item, along with its status and any error information.\n */\nexport class SetCachedItemAction<TData = never> implements Action {\n public readonly type: string = NgssmCachingActionType.setCachedItem;\n\n constructor(\n public readonly cachedItemKey: string,\n public readonly cachedItem: TData,\n public readonly status = CachedItemStatus.set,\n public readonly error?: string\n ) {}\n}\n","import { Action } from 'ngssm-store';\nimport { NgssmCachingActionType } from './ngssm-caching-action-type';\n\nexport class UnsetCachedItemAction implements Action {\n public readonly type: string = NgssmCachingActionType.unsetCachedItem;\n\n constructor(public readonly cachedItemKey: string) {}\n}\n","import update, { CustomCommands, Spec } from 'immutability-helper';\n\nimport { NgSsmFeatureState, State } from 'ngssm-store';\nimport { CachedItem } from '../model';\n\nexport const selectNgssmCachingState = (state: State): NgssmCachingState =>\n state[NgssmCachingStateSpecification.featureStateKey] as NgssmCachingState;\n\nexport const updateNgssmCachingState = <T extends CustomCommands<object> = never>(state: State, command: Spec<NgssmCachingState, T>): State =>\n update(state, {\n [NgssmCachingStateSpecification.featureStateKey]: command\n });\n\nexport interface NgssmCachingState {\n caches: Record<string, CachedItem>;\n}\n\n@NgSsmFeatureState({\n featureStateKey: NgssmCachingStateSpecification.featureStateKey,\n initialState: NgssmCachingStateSpecification.initialState\n})\nexport class NgssmCachingStateSpecification {\n public static readonly featureStateKey = 'ngssm-caching-state';\n public static readonly initialState: NgssmCachingState = {\n caches: {}\n };\n}\n","import { State } from 'ngssm-store';\nimport { CachedItem } from '../model';\nimport { selectNgssmCachingState } from './ngssm-caching.state';\n\nexport const selectNgssmCachedItem = <T = unknown>(state: State, key: string): CachedItem<T> | undefined =>\n selectNgssmCachingState(state).caches[key] as CachedItem<T>;\n","import { Injectable } from '@angular/core';\n\nimport { Reducer, State, Action } from 'ngssm-store';\n\nimport { NgssmCachingActionType, SetCachedItemAction, UnsetCachedItemAction } from '../actions';\nimport { selectNgssmCachedItem, updateNgssmCachingState } from '../state';\n\n@Injectable()\nexport class CachedItemReducer implements Reducer {\n public readonly processedActions: string[] = [NgssmCachingActionType.setCachedItem, NgssmCachingActionType.unsetCachedItem];\n\n public updateState(state: State, action: Action): State {\n switch (action.type) {\n case NgssmCachingActionType.setCachedItem: {\n const setCachedItemAction = action as SetCachedItemAction;\n\n return updateNgssmCachingState(state, {\n caches: {\n [setCachedItemAction.cachedItemKey]: {\n $set: {\n status: setCachedItemAction.status,\n error: setCachedItemAction.error,\n item: setCachedItemAction.cachedItem\n }\n }\n }\n });\n }\n\n case NgssmCachingActionType.unsetCachedItem: {\n const unsetCachedItemAction = action as UnsetCachedItemAction;\n if (selectNgssmCachedItem(state, unsetCachedItemAction.cachedItemKey) === undefined) {\n return state;\n }\n\n return updateNgssmCachingState(state, {\n caches: { $unset: [unsetCachedItemAction.cachedItemKey] }\n });\n }\n }\n\n return state;\n }\n}\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\nimport { provideReducers } from 'ngssm-store';\nimport { CachedItemReducer } from './reducers';\n\nexport const provideNgssmCaching = (): EnvironmentProviders => {\n return makeEnvironmentProviders([provideReducers(CachedItemReducer)]);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;IAAY;AAAZ,CAAA,UAAY,sBAAsB,EAAA;AAChC,IAAA,sBAAA,CAAA,eAAA,CAAA,GAAA,wCAAwD;AACxD,IAAA,sBAAA,CAAA,iBAAA,CAAA,GAAA,0CAA4D;AAC9D,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,GAGjC,EAAA,CAAA,CAAA;;ICHW;AAAZ,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,QAAA,CAAA,GAAA,SAAkB;AAClB,IAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,gBAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACj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AC,iBAAiB,CAAC,CAAC,CAAC;AACvE;;ACNA;;AAEG;;;;"}
1
+ {"version":3,"file":"ngssm-store-caching.mjs","sources":["../../../projects/ngssm-store/caching/src/actions/ngssm-caching-action-type.ts","../../../projects/ngssm-store/caching/src/model/cached-item-status.ts","../../../projects/ngssm-store/caching/src/actions/set-cached-item.action.ts","../../../projects/ngssm-store/caching/src/actions/unset-cached-item.action.ts","../../../projects/ngssm-store/caching/src/state/ngssm-caching.state.ts","../../../projects/ngssm-store/caching/src/state/selectors.ts","../../../projects/ngssm-store/caching/src/reducers/cached-item.reducer.ts","../../../projects/ngssm-store/caching/src/provide-ngssm-caching.ts","../../../projects/ngssm-store/caching/ngssm-store-caching.ts"],"sourcesContent":["export enum NgssmCachingActionType {\n setCachedItem = '[NgssmCachingActionType] setCachedItem',\n unsetCachedItem = '[NgssmCachingActionType] unsetCachedItem'\n}\n","export enum CachedItemStatus {\n notSet = 'Not Set',\n loading = 'Loading',\n set = 'Set',\n error = 'Error'\n}\n","import { Action } from 'ngssm-store';\n\nimport { NgssmCachingActionType } from './ngssm-caching-action-type';\nimport { CachedItemStatus } from '../model';\n\n/**\n * Represents an action to set a cached item in the state. If key is already set in the state, the value is replaced by the new one.\n *\n * @template TData The type of the cached item's data.\n * @implements {Action}\n *\n * @property {string} cachedItemKey - The unique key identifying the cached item.\n * @property {TData} cachedItem - The data to be cached.\n * @property {CachedItemStatus} [status=CachedItemStatus.set] - The status of the cached item operation.\n * @property {string} [error] - An optional error message if the caching operation failed.\n *\n * @remarks\n * This action is dispatched to update the cache with a new or modified item, along with its status and any error information.\n */\nexport class SetCachedItemAction<TData = unknown> implements Action {\n public readonly type: string = NgssmCachingActionType.setCachedItem;\n\n constructor(\n public readonly cachedItemKey: string,\n public readonly cachedItem: TData,\n public readonly status = CachedItemStatus.set,\n public readonly error?: string\n ) {}\n}\n","import { Action } from 'ngssm-store';\nimport { NgssmCachingActionType } from './ngssm-caching-action-type';\n\nexport class UnsetCachedItemAction implements Action {\n public readonly type: string = NgssmCachingActionType.unsetCachedItem;\n\n constructor(public readonly cachedItemKey: string) {}\n}\n","import update, { CustomCommands, Spec } from 'immutability-helper';\n\nimport { NgSsmFeatureState, State } from 'ngssm-store';\nimport { CachedItem } from '../model';\n\nexport const selectNgssmCachingState = (state: State): NgssmCachingState =>\n state[NgssmCachingStateSpecification.featureStateKey] as NgssmCachingState;\n\nexport const updateNgssmCachingState = <T extends CustomCommands<object> = never>(state: State, command: Spec<NgssmCachingState, T>): State =>\n update(state, {\n [NgssmCachingStateSpecification.featureStateKey]: command\n });\n\nexport interface NgssmCachingState {\n caches: Record<string, CachedItem>;\n}\n\n@NgSsmFeatureState({\n featureStateKey: NgssmCachingStateSpecification.featureStateKey,\n initialState: NgssmCachingStateSpecification.initialState\n})\nexport class NgssmCachingStateSpecification {\n public static readonly featureStateKey = 'ngssm-caching-state';\n public static readonly initialState: NgssmCachingState = {\n caches: {}\n };\n}\n","import { State } from 'ngssm-store';\nimport { CachedItem } from '../model';\nimport { selectNgssmCachingState } from './ngssm-caching.state';\n\nexport const selectNgssmCachedItem = <T = unknown>(state: State, key: string): CachedItem<T> | undefined =>\n selectNgssmCachingState(state).caches[key] as CachedItem<T>;\n","import { Injectable } from '@angular/core';\n\nimport { Reducer, State, Action } from 'ngssm-store';\n\nimport { NgssmCachingActionType, SetCachedItemAction, UnsetCachedItemAction } from '../actions';\nimport { selectNgssmCachedItem, updateNgssmCachingState } from '../state';\n\n@Injectable()\nexport class CachedItemReducer implements Reducer {\n public readonly processedActions: string[] = [NgssmCachingActionType.setCachedItem, NgssmCachingActionType.unsetCachedItem];\n\n public updateState(state: State, action: Action): State {\n switch (action.type) {\n case NgssmCachingActionType.setCachedItem: {\n const setCachedItemAction = action as SetCachedItemAction;\n\n return updateNgssmCachingState(state, {\n caches: {\n [setCachedItemAction.cachedItemKey]: {\n $set: {\n status: setCachedItemAction.status,\n error: setCachedItemAction.error,\n item: setCachedItemAction.cachedItem\n }\n }\n }\n });\n }\n\n case NgssmCachingActionType.unsetCachedItem: {\n const unsetCachedItemAction = action as UnsetCachedItemAction;\n if (selectNgssmCachedItem(state, unsetCachedItemAction.cachedItemKey) === undefined) {\n return state;\n }\n\n return updateNgssmCachingState(state, {\n caches: { $unset: [unsetCachedItemAction.cachedItemKey] }\n });\n }\n }\n\n return state;\n }\n}\n","import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\nimport { provideReducers } from 'ngssm-store';\nimport { CachedItemReducer } from './reducers';\n\nexport const provideNgssmCaching = (): EnvironmentProviders => {\n return makeEnvironmentProviders([provideReducers(CachedItemReducer)]);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;IAAY;AAAZ,CAAA,UAAY,sBAAsB,EAAA;AAChC,IAAA,sBAAA,CAAA,eAAA,CAAA,GAAA,wCAAwD;AACxD,IAAA,sBAAA,CAAA,iBAAA,CAAA,GAAA,0CAA4D;AAC9D,CAAC,EAHW,sBAAsB,KAAtB,sBAAsB,GAGjC,EAAA,CAAA,CAAA;;ICHW;AAAZ,CAAA,UAAY,gBAAgB,EAAA;AAC1B,IAAA,gBAAA,CAAA,QAAA,CAAA,GAAA,SAAkB;AAClB,IAAA,gBAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,gBAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,gBAAA,CAAA,OAAA,CAAA,GAAA,OAAe;AACjB,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,GAK3B,EAAA,CAAA,CAAA;;ACAD;;;;;;;;;;;;;AAaG;MACU,mBAAmB,CAAA;IAG9B,WACkB,CAAA,aAAqB,EACrB,UAAiB,EACjB,SAAS,gBAAgB,CAAC,GAAG,EAC7B,KAAc,EAAA;QAHd,IAAa,CAAA,aAAA,GAAb,aAAa;QACb,IAAU,CAAA,UAAA,GAAV,UAAU;QACV,IAAM,CAAA,MAAA,GAAN,MAAM;QACN,IAAK,CA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AA6B;gBAEzD,OAAO,uBAAuB,CAAC,KAAK,EAAE;AACpC,oBAAA,MAAM,EAAE;AACN,wBAAA,CAAC,mBAAmB,CAAC,aAAa,GAAG;AACnC,4BAAA,IAAI,EAAE;gCACJ,MAAM,EAAE,mBAAmB,CAAC,MAAM;gCAClC,KAAK,EAAE,mBAAmB,CAAC,KAAK;gCAChC,IAAI,EAAE,mBAAmB,CAAC;AAC3B;AACF;AACF;AACF,iBAAA,CAAC;;AAGJ,YAAA,KAAK,sBAAsB,CAAC,eAAe,EAAE;gBAC3C,MAAM,qBAAqB,GAAG,MAA+B;gBAC7D,IAAI,qBAAqB,CAAC,KAAK,EAAE,qBAAqB,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;AACnF,oBAAA,OAAO,KAAK;;gBAGd,OAAO,uBAAuB,CAAC,KAAK,EAAE;oBACpC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,qBAAqB,CAAC,aAAa,CAAC;AACxD,iBAAA,CAAC;;;AAIN,QAAA,OAAO,KAAK;;8GAjCH,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;kHAAjB,iBAAiB,EAAA,CAAA,CAAA;;2FAAjB,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAD7B;;;ACHM,MAAM,mBAAmB,GAAG,MAA2B;IAC5D,OAAO,wBAAwB,CAAC,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACvE;;ACNA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngssm-store",
3
- "version": "20.0.4",
3
+ "version": "20.0.6",
4
4
  "description": "NgSsm - Simple state management implementation.",
5
5
  "author": "Lion Marc",
6
6
  "license": "MIT",
@@ -38,6 +38,10 @@
38
38
  "./visibility": {
39
39
  "types": "./visibility/index.d.ts",
40
40
  "default": "./fesm2022/ngssm-store-visibility.mjs"
41
+ },
42
+ "./caching/testing": {
43
+ "types": "./caching/testing/index.d.ts",
44
+ "default": "./fesm2022/ngssm-store-caching-testing.mjs"
41
45
  }
42
46
  },
43
47
  "sideEffects": false