ngssm-remote-data 20.0.4 → 20.0.5
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.
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { inject, Injectable, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
|
|
3
|
+
import { updateNgssmRemoteCallState, NgssmRemoteCallStateSpecification, NgssmRemoteCallStateInitializer } from 'ngssm-remote-data';
|
|
4
|
+
import { Store, Logger } from 'ngssm-store';
|
|
5
|
+
import { StoreMock } from 'ngssm-store/testing';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Utility service for setting and updating remote call status and errors in the StoreMock during tests.
|
|
9
|
+
* Provides methods to set the status or error of a remote call.
|
|
10
|
+
*/
|
|
11
|
+
class NgssmRemoteCallSetter {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.store = inject(Store);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets the status of a remote call in the StoreMock.
|
|
17
|
+
* @param remoteCallId The identifier of the remote call.
|
|
18
|
+
* @param status The new status to set.
|
|
19
|
+
* @returns The NgssmRemoteCallSetter instance for chaining.
|
|
20
|
+
*/
|
|
21
|
+
setRemoteCallStatus(remoteCallId, status) {
|
|
22
|
+
this.store.stateValue = updateNgssmRemoteCallState(this.store.stateValue, {
|
|
23
|
+
remoteCalls: {
|
|
24
|
+
[remoteCallId]: {
|
|
25
|
+
status: { $set: status }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Sets the error of a remote call in the StoreMock.
|
|
33
|
+
* @param remoteCallId The identifier of the remote call.
|
|
34
|
+
* @param error The error to set (optional).
|
|
35
|
+
* @returns The NgssmRemoteCallSetter instance for chaining.
|
|
36
|
+
*/
|
|
37
|
+
setRemoteCallError(remoteCallId, error) {
|
|
38
|
+
this.store.stateValue = updateNgssmRemoteCallState(this.store.stateValue, {
|
|
39
|
+
remoteCalls: {
|
|
40
|
+
[remoteCallId]: {
|
|
41
|
+
error: { $set: error }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmRemoteCallSetter, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
48
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmRemoteCallSetter }); }
|
|
49
|
+
}
|
|
50
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.2", ngImport: i0, type: NgssmRemoteCallSetter, decorators: [{
|
|
51
|
+
type: Injectable
|
|
52
|
+
}] });
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* App initializer that sets up the NgssmRemoteCall state and sources in the StoreMock for testing purposes.
|
|
56
|
+
* Throws an error if StoreMock is not registered.
|
|
57
|
+
*/
|
|
58
|
+
const ngssmRemoteCallStateAndRemoteCallsInitializer = () => {
|
|
59
|
+
const logger = inject(Logger);
|
|
60
|
+
logger.information('[ngssm-remote-call-testing] Initialization of state and sources');
|
|
61
|
+
const store = inject(Store);
|
|
62
|
+
if (!(store instanceof StoreMock)) {
|
|
63
|
+
throw new Error('StoreMock is not registered.');
|
|
64
|
+
}
|
|
65
|
+
store.stateValue = {
|
|
66
|
+
...store.stateValue,
|
|
67
|
+
[NgssmRemoteCallStateSpecification.featureStateKey]: NgssmRemoteCallStateSpecification.initialState
|
|
68
|
+
};
|
|
69
|
+
const stateInitializer = inject(NgssmRemoteCallStateInitializer);
|
|
70
|
+
store.stateValue = stateInitializer.initializeState(store.stateValue);
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Provides environment providers for remote call testing, including the state initializer and helper services.
|
|
74
|
+
*/
|
|
75
|
+
const provideNgssmRemoteCallTesting = () => {
|
|
76
|
+
return makeEnvironmentProviders([
|
|
77
|
+
provideAppInitializer(ngssmRemoteCallStateAndRemoteCallsInitializer),
|
|
78
|
+
NgssmRemoteCallStateInitializer,
|
|
79
|
+
NgssmRemoteCallSetter
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Generated bundle index. Do not edit.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
export { NgssmRemoteCallSetter, ngssmRemoteCallStateAndRemoteCallsInitializer, provideNgssmRemoteCallTesting };
|
|
88
|
+
//# sourceMappingURL=ngssm-remote-data-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngssm-remote-data-testing.mjs","sources":["../../../projects/ngssm-remote-data/testing/src/ngssm-remote-call-setter.ts","../../../projects/ngssm-remote-data/testing/src/provide-ngssm-remote-call-testing.ts","../../../projects/ngssm-remote-data/testing/ngssm-remote-data-testing.ts"],"sourcesContent":["import { inject, Injectable } from '@angular/core';\n\nimport { RemoteCallError, RemoteCallStatus, updateNgssmRemoteCallState } from 'ngssm-remote-data';\nimport { Store } from 'ngssm-store';\nimport { StoreMock } from 'ngssm-store/testing';\n\n/**\n * Utility service for setting and updating remote call status and errors in the StoreMock during tests.\n * Provides methods to set the status or error of a remote call.\n */\n@Injectable()\nexport class NgssmRemoteCallSetter {\n public readonly store = inject(Store) as unknown as StoreMock;\n\n /**\n * Sets the status of a remote call in the StoreMock.\n * @param remoteCallId The identifier of the remote call.\n * @param status The new status to set.\n * @returns The NgssmRemoteCallSetter instance for chaining.\n */\n public setRemoteCallStatus(remoteCallId: string, status: RemoteCallStatus): NgssmRemoteCallSetter {\n this.store.stateValue = updateNgssmRemoteCallState(this.store.stateValue, {\n remoteCalls: {\n [remoteCallId]: {\n status: { $set: status }\n }\n }\n });\n\n return this;\n }\n\n /**\n * Sets the error of a remote call in the StoreMock.\n * @param remoteCallId The identifier of the remote call.\n * @param error The error to set (optional).\n * @returns The NgssmRemoteCallSetter instance for chaining.\n */\n public setRemoteCallError(remoteCallId: string, error?: RemoteCallError): NgssmRemoteCallSetter {\n this.store.stateValue = updateNgssmRemoteCallState(this.store.stateValue, {\n remoteCalls: {\n [remoteCallId]: {\n error: { $set: error }\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';\n\nimport { NgssmRemoteCallStateSpecification, NgssmRemoteCallStateInitializer } from 'ngssm-remote-data';\nimport { NgssmRemoteCallSetter } from './ngssm-remote-call-setter';\n\n/**\n * App initializer that sets up the NgssmRemoteCall state and sources in the StoreMock for testing purposes.\n * Throws an error if StoreMock is not registered.\n */\nexport const ngssmRemoteCallStateAndRemoteCallsInitializer = () => {\n const logger = inject(Logger);\n logger.information('[ngssm-remote-call-testing] Initialization of state and sources');\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 [NgssmRemoteCallStateSpecification.featureStateKey]: NgssmRemoteCallStateSpecification.initialState\n };\n\n const stateInitializer = inject(NgssmRemoteCallStateInitializer);\n store.stateValue = stateInitializer.initializeState(store.stateValue);\n};\n\n/**\n * Provides environment providers for remote call testing, including the state initializer and helper services.\n */\nexport const provideNgssmRemoteCallTesting = (): EnvironmentProviders => {\n return makeEnvironmentProviders([\n provideAppInitializer(ngssmRemoteCallStateAndRemoteCallsInitializer),\n NgssmRemoteCallStateInitializer,\n NgssmRemoteCallSetter\n ]);\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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,UAAU;AACnB,QAAA,CAAC,iCAAiC,CAAC,eAAe,GAAG,iCAAiC,CAAC;KACxF;AAED,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,+BAA+B,CAAC;IAChE,KAAK,CAAC,UAAU,GAAG,gBAAgB,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC;AACvE;AAEA;;AAEG;AACI,MAAM,6BAA6B,GAAG,MAA2B;AACtE,IAAA,OAAO,wBAAwB,CAAC;QAC9B,qBAAqB,CAAC,6CAA6C,CAAC;QACpE,+BAA+B;QAC/B;AACD,KAAA,CAAC;AACJ;;ACtCA;;AAEG;;;;"}
|
|
@@ -643,5 +643,5 @@ const atLeastOneLoadingOrInProgress = (state, remoteDataKeys, remoteCallIds) =>
|
|
|
643
643
|
* Generated bundle index. Do not edit.
|
|
644
644
|
*/
|
|
645
645
|
|
|
646
|
-
export { DataStatus, LoadRemoteDataAction, NGSSM_REMOTE_CALL_CONFIG, NGSSM_REMOTE_DATA_PROVIDER, NgssmCachesComponent, NgssmCachesDisplayButtonComponent, NgssmRemoteCallActionType, NgssmRemoteCallDirective, NgssmRemoteCallErrorComponent, NgssmRemoteCallResultAction, NgssmRemoteCallStateSpecification, NgssmRemoteDataOverlayDirective, NgssmRemoteDataReloadButtonComponent, RegisterLoadedRemoteDataAction, RemoteCallStatus, RemoteDataActionType, RemoteDataLoadingGuard, RemoteDataStateSpecification, SetRemoteCallAction, atLeastOneLoadingOrInProgress, getDefaultRemoteCall, getDefaultRemoteData, isNgssmRemoteCallInProgress, ngssmReloadRemoteData, processRemoteCallError, provideNgssmRemoteCall, provideNgssmRemoteCallConfig, provideNgssmRemoteData, provideRemoteDataFunc, provideRemoteDataProviders, selectNgssmRemoteCallState, selectRemoteCall, selectRemoteData, selectRemoteDataState, updateNgssmRemoteCallState, updateRemoteDataState };
|
|
646
|
+
export { DataStatus, LoadRemoteDataAction, NGSSM_REMOTE_CALL_CONFIG, NGSSM_REMOTE_DATA_PROVIDER, NgssmCachesComponent, NgssmCachesDisplayButtonComponent, NgssmRemoteCallActionType, NgssmRemoteCallDirective, NgssmRemoteCallErrorComponent, NgssmRemoteCallResultAction, NgssmRemoteCallStateInitializer, NgssmRemoteCallStateSpecification, NgssmRemoteDataOverlayDirective, NgssmRemoteDataReloadButtonComponent, RegisterLoadedRemoteDataAction, RemoteCallStatus, RemoteDataActionType, RemoteDataLoadingGuard, RemoteDataStateSpecification, SetRemoteCallAction, atLeastOneLoadingOrInProgress, getDefaultRemoteCall, getDefaultRemoteData, isNgssmRemoteCallInProgress, ngssmReloadRemoteData, processRemoteCallError, provideNgssmRemoteCall, provideNgssmRemoteCallConfig, provideNgssmRemoteData, provideRemoteDataFunc, provideRemoteDataProviders, selectNgssmRemoteCallState, selectRemoteCall, selectRemoteData, selectRemoteDataState, updateNgssmRemoteCallState, updateRemoteDataState };
|
|
647
647
|
//# sourceMappingURL=ngssm-remote-data.mjs.map
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { InjectionToken, Type, EnvironmentProviders, Provider } from '@angular/core';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
4
|
import { Spec } from 'immutability-helper';
|
|
5
|
-
import { ActionDispatcher, Logger, State, Action } from 'ngssm-store';
|
|
5
|
+
import { ActionDispatcher, Logger, State, Action, StateInitializer } from 'ngssm-store';
|
|
6
6
|
import { ActivatedRouteSnapshot, UrlTree } from '@angular/router';
|
|
7
7
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
8
8
|
import { NgssmNotifierService } from 'ngssm-toolkit';
|
|
@@ -232,7 +232,14 @@ declare const selectRemoteCall: (state: State, id: string) => RemoteCall;
|
|
|
232
232
|
*/
|
|
233
233
|
declare const isNgssmRemoteCallInProgress: (state: State, remoteCallId: string) => boolean;
|
|
234
234
|
|
|
235
|
+
declare class NgssmRemoteCallStateInitializer implements StateInitializer {
|
|
236
|
+
private readonly remoteCallConfigs;
|
|
237
|
+
initializeState(state: State): State;
|
|
238
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgssmRemoteCallStateInitializer, never>;
|
|
239
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<NgssmRemoteCallStateInitializer>;
|
|
240
|
+
}
|
|
241
|
+
|
|
235
242
|
declare const atLeastOneLoadingOrInProgress: (state: State, remoteDataKeys: string[], remoteCallIds: string[]) => boolean;
|
|
236
243
|
|
|
237
|
-
export { DataStatus, LoadRemoteDataAction, NGSSM_REMOTE_CALL_CONFIG, NGSSM_REMOTE_DATA_PROVIDER, NgssmCachesComponent, NgssmCachesDisplayButtonComponent, NgssmRemoteCallActionType, NgssmRemoteCallDirective, NgssmRemoteCallErrorComponent, NgssmRemoteCallResultAction, NgssmRemoteCallStateSpecification, NgssmRemoteDataOverlayDirective, NgssmRemoteDataReloadButtonComponent, RegisterLoadedRemoteDataAction, RemoteCallStatus, RemoteDataActionType, RemoteDataLoadingGuard, RemoteDataStateSpecification, SetRemoteCallAction, atLeastOneLoadingOrInProgress, getDefaultRemoteCall, getDefaultRemoteData, isNgssmRemoteCallInProgress, ngssmReloadRemoteData, processRemoteCallError, provideNgssmRemoteCall, provideNgssmRemoteCallConfig, provideNgssmRemoteData, provideRemoteDataFunc, provideRemoteDataProviders, selectNgssmRemoteCallState, selectRemoteCall, selectRemoteData, selectRemoteDataState, updateNgssmRemoteCallState, updateRemoteDataState };
|
|
244
|
+
export { DataStatus, LoadRemoteDataAction, NGSSM_REMOTE_CALL_CONFIG, NGSSM_REMOTE_DATA_PROVIDER, NgssmCachesComponent, NgssmCachesDisplayButtonComponent, NgssmRemoteCallActionType, NgssmRemoteCallDirective, NgssmRemoteCallErrorComponent, NgssmRemoteCallResultAction, NgssmRemoteCallStateInitializer, NgssmRemoteCallStateSpecification, NgssmRemoteDataOverlayDirective, NgssmRemoteDataReloadButtonComponent, RegisterLoadedRemoteDataAction, RemoteCallStatus, RemoteDataActionType, RemoteDataLoadingGuard, RemoteDataStateSpecification, SetRemoteCallAction, atLeastOneLoadingOrInProgress, getDefaultRemoteCall, getDefaultRemoteData, isNgssmRemoteCallInProgress, ngssmReloadRemoteData, processRemoteCallError, provideNgssmRemoteCall, provideNgssmRemoteCallConfig, provideNgssmRemoteData, provideRemoteDataFunc, provideRemoteDataProviders, selectNgssmRemoteCallState, selectRemoteCall, selectRemoteData, selectRemoteDataState, updateNgssmRemoteCallState, updateRemoteDataState };
|
|
238
245
|
export type { NgssmRemoteCallState, ReloadParams, RemoteCall, RemoteCallConfig, RemoteCallError, RemoteData, RemoteDataGetterParams, RemoteDataLoadingFunc, RemoteDataLoadingGuardItem, RemoteDataLoadingGuardParameters, RemoteDataProvider, RemoteDataState };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngssm-remote-data",
|
|
3
|
-
"version": "20.0.
|
|
3
|
+
"version": "20.0.5",
|
|
4
4
|
"description": "NgSsm - Utilities to manage data loaded from remote services with the store.",
|
|
5
5
|
"author": "Lion Marc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
".": {
|
|
27
27
|
"types": "./index.d.ts",
|
|
28
28
|
"default": "./fesm2022/ngssm-remote-data.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./testing": {
|
|
31
|
+
"types": "./testing/index.d.ts",
|
|
32
|
+
"default": "./fesm2022/ngssm-remote-data-testing.mjs"
|
|
29
33
|
}
|
|
30
34
|
},
|
|
31
35
|
"sideEffects": false
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RemoteCallStatus, RemoteCallError } from 'ngssm-remote-data';
|
|
2
|
+
import { StoreMock } from 'ngssm-store/testing';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { EnvironmentProviders } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Utility service for setting and updating remote call status and errors in the StoreMock during tests.
|
|
8
|
+
* Provides methods to set the status or error of a remote call.
|
|
9
|
+
*/
|
|
10
|
+
declare class NgssmRemoteCallSetter {
|
|
11
|
+
readonly store: StoreMock;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the status of a remote call in the StoreMock.
|
|
14
|
+
* @param remoteCallId The identifier of the remote call.
|
|
15
|
+
* @param status The new status to set.
|
|
16
|
+
* @returns The NgssmRemoteCallSetter instance for chaining.
|
|
17
|
+
*/
|
|
18
|
+
setRemoteCallStatus(remoteCallId: string, status: RemoteCallStatus): NgssmRemoteCallSetter;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the error of a remote call in the StoreMock.
|
|
21
|
+
* @param remoteCallId The identifier of the remote call.
|
|
22
|
+
* @param error The error to set (optional).
|
|
23
|
+
* @returns The NgssmRemoteCallSetter instance for chaining.
|
|
24
|
+
*/
|
|
25
|
+
setRemoteCallError(remoteCallId: string, error?: RemoteCallError): NgssmRemoteCallSetter;
|
|
26
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgssmRemoteCallSetter, never>;
|
|
27
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<NgssmRemoteCallSetter>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* App initializer that sets up the NgssmRemoteCall state and sources in the StoreMock for testing purposes.
|
|
32
|
+
* Throws an error if StoreMock is not registered.
|
|
33
|
+
*/
|
|
34
|
+
declare const ngssmRemoteCallStateAndRemoteCallsInitializer: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Provides environment providers for remote call testing, including the state initializer and helper services.
|
|
37
|
+
*/
|
|
38
|
+
declare const provideNgssmRemoteCallTesting: () => EnvironmentProviders;
|
|
39
|
+
|
|
40
|
+
export { NgssmRemoteCallSetter, ngssmRemoteCallStateAndRemoteCallsInitializer, provideNgssmRemoteCallTesting };
|