@angular-architects/ngrx-toolkit 19.4.0 → 19.4.2
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.
- package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs +119 -0
- package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs.map +1 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +2108 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -0
- package/{src/index.ts → index.d.ts} +5 -32
- package/lib/assertions/assertions.d.ts +2 -0
- package/{src/lib/devtools/features/with-disabled-name-indicies.ts → lib/devtools/features/with-disabled-name-indicies.d.ts} +1 -5
- package/{src/lib/devtools/features/with-glitch-tracking.ts → lib/devtools/features/with-glitch-tracking.d.ts} +1 -6
- package/{src/lib/devtools/features/with-mapper.ts → lib/devtools/features/with-mapper.d.ts} +1 -7
- package/lib/devtools/internal/current-action-names.d.ts +1 -0
- package/lib/devtools/internal/default-tracker.d.ts +13 -0
- package/lib/devtools/internal/devtools-feature.d.ts +24 -0
- package/lib/devtools/internal/devtools-syncer.service.d.ts +39 -0
- package/lib/devtools/internal/glitch-tracker.service.d.ts +18 -0
- package/lib/devtools/internal/models.d.ts +24 -0
- package/{src/lib/devtools/provide-devtools-config.ts → lib/devtools/provide-devtools-config.d.ts} +4 -16
- package/lib/devtools/rename-devtools-name.d.ts +7 -0
- package/lib/devtools/update-state.d.ts +15 -0
- package/{src/lib/devtools/with-dev-tools-stub.ts → lib/devtools/with-dev-tools-stub.d.ts} +1 -2
- package/lib/devtools/with-devtools.d.ts +24 -0
- package/lib/flattening-operator.d.ts +14 -0
- package/lib/immutable-state/deep-freeze.d.ts +11 -0
- package/lib/immutable-state/is-dev-mode.d.ts +1 -0
- package/lib/immutable-state/with-immutable-state.d.ts +60 -0
- package/lib/mutation/http-mutation.d.ts +86 -0
- package/lib/mutation/mutation.d.ts +20 -0
- package/lib/mutation/rx-mutation.d.ts +76 -0
- package/{src/lib/shared/signal-store-models.ts → lib/shared/signal-store-models.d.ts} +4 -8
- package/lib/shared/throw-if-null.d.ts +1 -0
- package/lib/storage-sync/features/with-indexed-db.d.ts +2 -0
- package/lib/storage-sync/features/with-local-storage.d.ts +3 -0
- package/lib/storage-sync/internal/indexeddb.service.d.ts +29 -0
- package/lib/storage-sync/internal/local-storage.service.d.ts +8 -0
- package/lib/storage-sync/internal/models.d.ts +45 -0
- package/lib/storage-sync/internal/session-storage.service.d.ts +8 -0
- package/lib/storage-sync/with-storage-sync.d.ts +45 -0
- package/lib/with-call-state.d.ts +58 -0
- package/{src/lib/with-conditional.ts → lib/with-conditional.d.ts} +7 -31
- package/lib/with-data-service.d.ts +109 -0
- package/{src/lib/with-feature-factory.ts → lib/with-feature-factory.d.ts} +4 -32
- package/lib/with-mutations.d.ts +51 -0
- package/lib/with-pagination.d.ts +98 -0
- package/lib/with-redux.d.ts +147 -0
- package/lib/with-reset.d.ts +29 -0
- package/lib/with-undo-redo.d.ts +31 -0
- package/package.json +21 -4
- package/redux-connector/index.d.ts +2 -0
- package/redux-connector/src/lib/create-redux.d.ts +13 -0
- package/redux-connector/src/lib/model.d.ts +40 -0
- package/redux-connector/src/lib/rxjs-interop/redux-method.d.ts +14 -0
- package/redux-connector/src/lib/signal-redux-store.d.ts +11 -0
- package/redux-connector/src/lib/util.d.ts +5 -0
- package/eslint.config.cjs +0 -43
- package/jest.config.ts +0 -22
- package/ng-package.json +0 -7
- package/project.json +0 -37
- package/redux-connector/docs/README.md +0 -131
- package/redux-connector/index.ts +0 -6
- package/redux-connector/ng-package.json +0 -5
- package/redux-connector/src/lib/create-redux.ts +0 -102
- package/redux-connector/src/lib/model.ts +0 -89
- package/redux-connector/src/lib/rxjs-interop/redux-method.ts +0 -66
- package/redux-connector/src/lib/signal-redux-store.ts +0 -59
- package/redux-connector/src/lib/util.ts +0 -22
- package/src/lib/assertions/assertions.ts +0 -9
- package/src/lib/devtools/internal/current-action-names.ts +0 -1
- package/src/lib/devtools/internal/default-tracker.ts +0 -60
- package/src/lib/devtools/internal/devtools-feature.ts +0 -37
- package/src/lib/devtools/internal/devtools-syncer.service.ts +0 -202
- package/src/lib/devtools/internal/glitch-tracker.service.ts +0 -61
- package/src/lib/devtools/internal/models.ts +0 -29
- package/src/lib/devtools/rename-devtools-name.ts +0 -21
- package/src/lib/devtools/tests/action-name.spec.ts +0 -48
- package/src/lib/devtools/tests/basic.spec.ts +0 -111
- package/src/lib/devtools/tests/connecting.spec.ts +0 -37
- package/src/lib/devtools/tests/helpers.spec.ts +0 -43
- package/src/lib/devtools/tests/naming.spec.ts +0 -216
- package/src/lib/devtools/tests/provide-devtools-config.spec.ts +0 -25
- package/src/lib/devtools/tests/types.spec.ts +0 -19
- package/src/lib/devtools/tests/update-state.spec.ts +0 -29
- package/src/lib/devtools/tests/with-devtools.spec.ts +0 -5
- package/src/lib/devtools/tests/with-glitch-tracking.spec.ts +0 -272
- package/src/lib/devtools/tests/with-mapper.spec.ts +0 -69
- package/src/lib/devtools/update-state.ts +0 -38
- package/src/lib/devtools/with-devtools.ts +0 -81
- package/src/lib/flattening-operator.ts +0 -42
- package/src/lib/immutable-state/deep-freeze.ts +0 -43
- package/src/lib/immutable-state/is-dev-mode.ts +0 -6
- package/src/lib/immutable-state/tests/with-immutable-state.spec.ts +0 -260
- package/src/lib/immutable-state/with-immutable-state.ts +0 -115
- package/src/lib/mutation/http-mutation.spec.ts +0 -473
- package/src/lib/mutation/http-mutation.ts +0 -172
- package/src/lib/mutation/mutation.ts +0 -26
- package/src/lib/mutation/rx-mutation.spec.ts +0 -594
- package/src/lib/mutation/rx-mutation.ts +0 -208
- package/src/lib/shared/prettify.ts +0 -3
- package/src/lib/shared/throw-if-null.ts +0 -7
- package/src/lib/storage-sync/features/with-indexed-db.ts +0 -81
- package/src/lib/storage-sync/features/with-local-storage.ts +0 -58
- package/src/lib/storage-sync/internal/indexeddb.service.ts +0 -124
- package/src/lib/storage-sync/internal/local-storage.service.ts +0 -19
- package/src/lib/storage-sync/internal/models.ts +0 -62
- package/src/lib/storage-sync/internal/session-storage.service.ts +0 -18
- package/src/lib/storage-sync/tests/indexeddb.service.spec.ts +0 -99
- package/src/lib/storage-sync/tests/with-storage-async.spec.ts +0 -308
- package/src/lib/storage-sync/tests/with-storage-sync.spec.ts +0 -268
- package/src/lib/storage-sync/with-storage-sync.ts +0 -233
- package/src/lib/with-call-state.spec.ts +0 -42
- package/src/lib/with-call-state.ts +0 -195
- package/src/lib/with-conditional.spec.ts +0 -125
- package/src/lib/with-data-service.spec.ts +0 -564
- package/src/lib/with-data-service.ts +0 -433
- package/src/lib/with-feature-factory.spec.ts +0 -69
- package/src/lib/with-mutations.spec.ts +0 -537
- package/src/lib/with-mutations.ts +0 -146
- package/src/lib/with-pagination.spec.ts +0 -90
- package/src/lib/with-pagination.ts +0 -353
- package/src/lib/with-redux.spec.ts +0 -258
- package/src/lib/with-redux.ts +0 -387
- package/src/lib/with-reset.spec.ts +0 -112
- package/src/lib/with-reset.ts +0 -62
- package/src/lib/with-undo-redo.spec.ts +0 -287
- package/src/lib/with-undo-redo.ts +0 -199
- package/src/test-setup.ts +0 -8
- package/tsconfig.json +0 -29
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -17
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StateSource } from '@ngrx/signals';
|
|
2
|
+
import { Tracker, TrackerStores } from './models';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Internal Service used by {@link withGlitchTracking}. It does not rely
|
|
6
|
+
* on `effect` as {@link DefaultTracker} does but uses the NgRx function
|
|
7
|
+
* `watchState` to track all state changes.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GlitchTrackerService implements Tracker {
|
|
10
|
+
#private;
|
|
11
|
+
get stores(): TrackerStores;
|
|
12
|
+
onChange(callback: (changedState: Record<string, object>) => void): void;
|
|
13
|
+
removeStore(id: string): void;
|
|
14
|
+
track(id: string, store: StateSource<object>): void;
|
|
15
|
+
notifyRenamedStore(id: string): void;
|
|
16
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<GlitchTrackerService, never>;
|
|
17
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<GlitchTrackerService>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StateSource } from '@ngrx/signals';
|
|
2
|
+
import { ReduxDevtoolsConfig } from '../provide-devtools-config';
|
|
3
|
+
import { DevtoolsInnerOptions } from './devtools-feature';
|
|
4
|
+
export type Action = {
|
|
5
|
+
type: string;
|
|
6
|
+
};
|
|
7
|
+
export type Connection = {
|
|
8
|
+
send: (action: Action, state: Record<string, unknown>) => void;
|
|
9
|
+
};
|
|
10
|
+
export type ReduxDevtoolsExtension = {
|
|
11
|
+
connect: (options: ReduxDevtoolsConfig) => Connection;
|
|
12
|
+
};
|
|
13
|
+
export type StoreRegistry = Record<string, {
|
|
14
|
+
options: DevtoolsInnerOptions;
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type Tracker = {
|
|
18
|
+
track(id: string, store: StateSource<object>): void;
|
|
19
|
+
onChange(callback: (changedState: Record<string, object>) => void): void;
|
|
20
|
+
notifyRenamedStore(id: string): void;
|
|
21
|
+
removeStore(id: string): void;
|
|
22
|
+
get stores(): TrackerStores;
|
|
23
|
+
};
|
|
24
|
+
export type TrackerStores = Record<string, StateSource<object>>;
|
package/{src/lib/devtools/provide-devtools-config.ts → lib/devtools/provide-devtools-config.d.ts}
RENAMED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
import { InjectionToken, ValueProvider } from '@angular/core';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Provides the configuration options for connecting to the Redux DevTools Extension.
|
|
5
4
|
*/
|
|
6
|
-
export function provideDevtoolsConfig(
|
|
7
|
-
config: ReduxDevtoolsConfig,
|
|
8
|
-
): ValueProvider {
|
|
9
|
-
return {
|
|
10
|
-
provide: REDUX_DEVTOOLS_CONFIG,
|
|
11
|
-
useValue: config,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
5
|
+
export declare function provideDevtoolsConfig(config: ReduxDevtoolsConfig): ValueProvider;
|
|
15
6
|
/**
|
|
16
7
|
* Injection token for the configuration options for connecting to the Redux DevTools Extension.
|
|
17
8
|
*/
|
|
18
|
-
export const REDUX_DEVTOOLS_CONFIG
|
|
19
|
-
'ReduxDevtoolsConfig',
|
|
20
|
-
);
|
|
21
|
-
|
|
9
|
+
export declare const REDUX_DEVTOOLS_CONFIG: InjectionToken<ReduxDevtoolsConfig>;
|
|
22
10
|
/**
|
|
23
11
|
* Options for connecting to the Redux DevTools Extension.
|
|
24
12
|
* @example
|
|
@@ -27,6 +15,6 @@ export const REDUX_DEVTOOLS_CONFIG = new InjectionToken<ReduxDevtoolsConfig>(
|
|
|
27
15
|
* };
|
|
28
16
|
*/
|
|
29
17
|
export type ReduxDevtoolsConfig = {
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
/** Optional name for the devtools instance. If empty, "NgRx SignalStore" will be used. */
|
|
19
|
+
name?: string;
|
|
32
20
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StateSource } from '@ngrx/signals';
|
|
2
|
+
/**
|
|
3
|
+
* Renames the name of a store how it appears in the Devtools.
|
|
4
|
+
* @param store instance of the SignalStore
|
|
5
|
+
* @param newName new name for the Devtools
|
|
6
|
+
*/
|
|
7
|
+
export declare function renameDevtoolsName<State extends object>(store: StateSource<State>, newName: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { patchState as originalPatchState, PartialStateUpdater, WritableStateSource } from '@ngrx/signals';
|
|
2
|
+
type PatchFn = typeof originalPatchState extends (arg1: infer First, ...args: infer Rest) => infer Returner ? (state: First, action: string, ...rest: Rest) => Returner : never;
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Has been renamed to `updateState`
|
|
5
|
+
*/
|
|
6
|
+
export declare const patchState: PatchFn;
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper of `patchState` for DevTools integration. Next to updating the state,
|
|
9
|
+
* it also sends the action to the DevTools.
|
|
10
|
+
* @param stateSource state of Signal Store
|
|
11
|
+
* @param action name of action how it will show in DevTools
|
|
12
|
+
* @param updaters updater functions or objects
|
|
13
|
+
*/
|
|
14
|
+
export declare function updateState<State extends object>(stateSource: WritableStateSource<State>, action: string, ...updaters: Array<Partial<NoInfer<State>> | PartialStateUpdater<NoInfer<State>>>): void;
|
|
15
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { withDevtools } from './with-devtools';
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* Stub for DevTools integration. Can be used to disable DevTools in production.
|
|
5
4
|
*/
|
|
6
|
-
export const withDevToolsStub: typeof withDevtools
|
|
5
|
+
export declare const withDevToolsStub: typeof withDevtools;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EmptyFeatureResult, SignalStoreFeature } from '@ngrx/signals';
|
|
2
|
+
import { DevtoolsFeature } from './internal/devtools-feature';
|
|
3
|
+
import { ReduxDevtoolsExtension } from './internal/models';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__REDUX_DEVTOOLS_EXTENSION__: ReduxDevtoolsExtension | undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare const renameDevtoolsMethodName = "___renameDevtoolsName";
|
|
10
|
+
export declare const uniqueDevtoolsId = "___uniqueDevtoolsId";
|
|
11
|
+
/**
|
|
12
|
+
* Adds this store as a feature state to the Redux DevTools.
|
|
13
|
+
*
|
|
14
|
+
* By default, the action name is 'Store Update'. You can
|
|
15
|
+
* change that via the {@link updateState} method, which has as second
|
|
16
|
+
* parameter the action name.
|
|
17
|
+
*
|
|
18
|
+
* The standalone function {@link renameDevtoolsName} can rename
|
|
19
|
+
* the store name.
|
|
20
|
+
*
|
|
21
|
+
* @param name name of the store as it should appear in the DevTools
|
|
22
|
+
* @param features features to extend or modify the behavior of the Devtools
|
|
23
|
+
*/
|
|
24
|
+
export declare function withDevtools(name: string, ...features: DevtoolsFeature[]): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ObservableInput, ObservedValueOf, OperatorFunction } from 'rxjs';
|
|
2
|
+
export type RxJsFlatteningOperator = <T, O extends ObservableInput<unknown>>(project: (value: T, index: number) => O) => OperatorFunction<T, ObservedValueOf<O>>;
|
|
3
|
+
/**
|
|
4
|
+
* A wrapper for an RxJS flattening operator.
|
|
5
|
+
* This wrapper informs about whether the operator has exhaust semantics or not.
|
|
6
|
+
*/
|
|
7
|
+
export type FlatteningOperator = {
|
|
8
|
+
rxJsOperator: RxJsFlatteningOperator;
|
|
9
|
+
exhaustSemantics: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const switchOp: FlatteningOperator;
|
|
12
|
+
export declare const mergeOp: FlatteningOperator;
|
|
13
|
+
export declare const concatOp: FlatteningOperator;
|
|
14
|
+
export declare const exhaustOp: FlatteningOperator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep freezes a state object along its properties with primitive values
|
|
3
|
+
* on the first level.
|
|
4
|
+
*
|
|
5
|
+
* The reason for this is that the final state is a merge of all
|
|
6
|
+
* root properties of all states, i.e. `withState`,....
|
|
7
|
+
*
|
|
8
|
+
* Since the root object will not be part of the state (shadow clone),
|
|
9
|
+
* we are not freezing it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deepFreeze<T extends Record<string | symbol, unknown>>(target: T, propertyNamesToBeFrozen: (string | symbol)[], isRoot?: boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDevMode(): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult } from '@ngrx/signals';
|
|
2
|
+
/**
|
|
3
|
+
* The implementation of this feature is a little bit tricky.
|
|
4
|
+
*
|
|
5
|
+
* `signalStore` does a shallow clone in the initial phase, in order to
|
|
6
|
+
* merge all different states together.
|
|
7
|
+
*
|
|
8
|
+
* Shallow cloning also happens in `patchState`.
|
|
9
|
+
*
|
|
10
|
+
* With shallow cloning, the root state object is replaced, which means,
|
|
11
|
+
* the freezing only stays for its nested properties but not for
|
|
12
|
+
* the primitive and immediate properties.
|
|
13
|
+
*
|
|
14
|
+
* For example:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const state = {
|
|
18
|
+
* id: 1,
|
|
19
|
+
* address: {
|
|
20
|
+
* street: 'Main St',
|
|
21
|
+
* city: 'Springfield',
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Running `Object.freeze` on `state` will freeze the `address` object, and
|
|
27
|
+
* the `id`. But since `state` is shallow cloned, the "frozing" state of the
|
|
28
|
+
* `id` is lost. `address`, being an object, is still frozen.
|
|
29
|
+
*
|
|
30
|
+
* To overcome that, we run `watchState` and run `deepFreeze`
|
|
31
|
+
* on every change.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Prevents mutation of the state.
|
|
35
|
+
*
|
|
36
|
+
* This is done by deeply applying `Object.freeze`. Any mutable change within
|
|
37
|
+
* or outside the `SignalStore` will throw an error.
|
|
38
|
+
*
|
|
39
|
+
* @param state the state object
|
|
40
|
+
* @param options enable protection in production (default: false)
|
|
41
|
+
*/
|
|
42
|
+
export declare function withImmutableState<State extends object>(state: State, options?: {
|
|
43
|
+
enableInProduction?: boolean;
|
|
44
|
+
}): SignalStoreFeature<SignalStoreFeatureResult, EmptyFeatureResult & {
|
|
45
|
+
state: State;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Prevents mutation of the state.
|
|
49
|
+
*
|
|
50
|
+
* This is done by deeply applying `Object.freeze`. Any mutable change within
|
|
51
|
+
* or outside the `SignalStore` will throw an error.
|
|
52
|
+
*
|
|
53
|
+
* @param stateFactory a function returning the state object
|
|
54
|
+
* @param options enable protection in production (default: false)
|
|
55
|
+
*/
|
|
56
|
+
export declare function withImmutableState<State extends object>(stateFactory: () => State, options?: {
|
|
57
|
+
enableInProduction?: boolean;
|
|
58
|
+
}): SignalStoreFeature<SignalStoreFeatureResult, EmptyFeatureResult & {
|
|
59
|
+
state: State;
|
|
60
|
+
}>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { HttpContext, HttpHeaders, HttpParams, HttpProgressEvent } from '@angular/common/http';
|
|
2
|
+
import { Signal } from '@angular/core';
|
|
3
|
+
import { Mutation } from './mutation';
|
|
4
|
+
import { RxMutationOptions } from './rx-mutation';
|
|
5
|
+
export type HttpMutationRequest = {
|
|
6
|
+
url: string;
|
|
7
|
+
method: string;
|
|
8
|
+
body?: unknown;
|
|
9
|
+
headers?: HttpHeaders | Record<string, string | string[]>;
|
|
10
|
+
context?: HttpContext;
|
|
11
|
+
reportProgress?: boolean;
|
|
12
|
+
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
|
|
13
|
+
withCredentials?: boolean;
|
|
14
|
+
credentials?: RequestCredentials;
|
|
15
|
+
keepalive?: boolean;
|
|
16
|
+
priority?: RequestPriority;
|
|
17
|
+
cache?: RequestCache;
|
|
18
|
+
mode?: RequestMode;
|
|
19
|
+
redirect?: RequestRedirect;
|
|
20
|
+
transferCache?: {
|
|
21
|
+
includeHeaders?: string[];
|
|
22
|
+
} | boolean;
|
|
23
|
+
};
|
|
24
|
+
export type HttpMutationOptions<Parameter, Result> = Omit<RxMutationOptions<Parameter, NoInfer<Result>>, 'operation'> & {
|
|
25
|
+
request: (param: Parameter) => HttpMutationRequest;
|
|
26
|
+
parse?: (response: unknown) => Result;
|
|
27
|
+
};
|
|
28
|
+
export type HttpMutation<Parameter, Result> = Mutation<Parameter, Result> & {
|
|
29
|
+
uploadProgress: Signal<HttpProgressEvent | undefined>;
|
|
30
|
+
downloadProgress: Signal<HttpProgressEvent | undefined>;
|
|
31
|
+
headers: Signal<HttpHeaders | undefined>;
|
|
32
|
+
statusCode: Signal<string | undefined>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Creates an HTTP mutation.
|
|
36
|
+
*
|
|
37
|
+
* export type Params = {
|
|
38
|
+
* value: number;
|
|
39
|
+
* };
|
|
40
|
+
*
|
|
41
|
+
* export type CounterResponse = {
|
|
42
|
+
* // httpbin.org echos the request using the
|
|
43
|
+
* // json property
|
|
44
|
+
* json: { counter: number };
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* const simpleSaveUser = httpMutation({
|
|
48
|
+
* request: (userData: AddUserEntry) => ({
|
|
49
|
+
* url: 'api/users',
|
|
50
|
+
* body: userData,
|
|
51
|
+
* }),
|
|
52
|
+
* parse: Boolean,
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* const saveUser = httpMutation({
|
|
56
|
+
* request: (p: Params) => ({
|
|
57
|
+
* url: `https://httpbin.org/post`,
|
|
58
|
+
* method: 'POST',
|
|
59
|
+
* body: { counter: p.value },
|
|
60
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
61
|
+
* }),
|
|
62
|
+
* onSuccess: (response: CounterResponse) => {
|
|
63
|
+
* console.log('Counter sent to server:', response);
|
|
64
|
+
* },
|
|
65
|
+
* onError: (error) => {
|
|
66
|
+
* console.error('Failed to send counter:', error);
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* ...
|
|
71
|
+
*
|
|
72
|
+
* const result = await this.saveUser({ value: 17 });
|
|
73
|
+
* if (result.status === 'success') {
|
|
74
|
+
* console.log('Successfully saved to server:', result.value);
|
|
75
|
+
* }
|
|
76
|
+
* else if (result.status === 'error') {
|
|
77
|
+
* console.log('Failed to save:', result.error);
|
|
78
|
+
* }
|
|
79
|
+
* else {
|
|
80
|
+
* console.log('Operation aborted');
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* @param options The options for the HTTP mutation.
|
|
84
|
+
* @returns The HTTP mutation.
|
|
85
|
+
*/
|
|
86
|
+
export declare function httpMutation<Parameter, Result>(optionsOrRequest: HttpMutationOptions<Parameter, Result> | ((param: Parameter) => HttpMutationRequest)): HttpMutation<Parameter, Result>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
export type MutationResult<Result> = {
|
|
3
|
+
status: 'success';
|
|
4
|
+
value: Result;
|
|
5
|
+
} | {
|
|
6
|
+
status: 'error';
|
|
7
|
+
error: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
status: 'aborted';
|
|
10
|
+
};
|
|
11
|
+
export type MutationStatus = 'idle' | 'pending' | 'error' | 'success';
|
|
12
|
+
export type Mutation<Parameter, Result> = {
|
|
13
|
+
(params: Parameter): Promise<MutationResult<Result>>;
|
|
14
|
+
status: Signal<MutationStatus>;
|
|
15
|
+
value: Signal<Result | undefined>;
|
|
16
|
+
isPending: Signal<boolean>;
|
|
17
|
+
isSuccess: Signal<boolean>;
|
|
18
|
+
error: Signal<unknown>;
|
|
19
|
+
hasValue(): this is Mutation<Exclude<Parameter, undefined>, Result>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Injector } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { FlatteningOperator } from '../flattening-operator';
|
|
4
|
+
import { Mutation } from './mutation';
|
|
5
|
+
export type Operation<Parameter, Result> = (param: Parameter) => Result;
|
|
6
|
+
export interface RxMutationOptions<Parameter, Result> {
|
|
7
|
+
operation: Operation<Parameter, Observable<Result>>;
|
|
8
|
+
onSuccess?: (result: Result, param: Parameter) => void;
|
|
9
|
+
onError?: (error: unknown, param: Parameter) => void;
|
|
10
|
+
operator?: FlatteningOperator;
|
|
11
|
+
injector?: Injector;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a mutation that leverages RxJS.
|
|
15
|
+
*
|
|
16
|
+
* For each mutation the following options can be defined:
|
|
17
|
+
* - `operation`: A function that defines the mutation logic. It returns an Observable.
|
|
18
|
+
* - `onSuccess`: A callback that is called when the mutation is successful.
|
|
19
|
+
* - `onError`: A callback that is called when the mutation fails.
|
|
20
|
+
* - `operator`: An optional wrapper of an RxJS flattening operator. By default `concat` sematics are used.
|
|
21
|
+
* - `injector`: An optional Angular injector to use for dependency injection.
|
|
22
|
+
*
|
|
23
|
+
* The `operation` is the only mandatory option.
|
|
24
|
+
*
|
|
25
|
+
* The returned mutation can be called as an async function and returns a Promise.
|
|
26
|
+
* This promise informs about whether the mutation was successful, failed, or aborted
|
|
27
|
+
* (due to switchMap or exhaustMap semantics).
|
|
28
|
+
*
|
|
29
|
+
* The mutation also provides several Signals such as error, status or isPending (see below).
|
|
30
|
+
*
|
|
31
|
+
* Example usage without Store:
|
|
32
|
+
*
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const counterSignal = signal(0);
|
|
35
|
+
*
|
|
36
|
+
* const increment = rxMutation({
|
|
37
|
+
* operation: (param: Param) => {
|
|
38
|
+
* return calcSum(this.counterSignal(), param.value);
|
|
39
|
+
* },
|
|
40
|
+
* operator: concatOp,
|
|
41
|
+
* onSuccess: (result) => {
|
|
42
|
+
* this.counterSignal.set(result);
|
|
43
|
+
* },
|
|
44
|
+
* onError: (error) => {
|
|
45
|
+
* console.error('Error occurred:', error);
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const error = increment.error;
|
|
50
|
+
* const isPending = increment.isPending;
|
|
51
|
+
* const status = increment.status;
|
|
52
|
+
* const value = increment.value;
|
|
53
|
+
* const hasValue = increment.hasValue;
|
|
54
|
+
*
|
|
55
|
+
* async function incrementCounter() {
|
|
56
|
+
* const result = await increment({ value: 1 });
|
|
57
|
+
* if (result.status === 'success') {
|
|
58
|
+
* console.log('Success:', result.value);
|
|
59
|
+
* }
|
|
60
|
+
* if (result.status === 'error') {
|
|
61
|
+
* console.log('Error:', result.error);
|
|
62
|
+
* }
|
|
63
|
+
* if (result.status === 'aborted') {
|
|
64
|
+
* console.log('Operation aborted');
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* function calcSum(a: number, b: number): Observable<number> {
|
|
69
|
+
* return of(result).pipe(delay(500));
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param options
|
|
74
|
+
* @returns the actual mutation function along tracking data as properties/methods
|
|
75
|
+
*/
|
|
76
|
+
export declare function rxMutation<Parameter, Result>(optionsOrOperation: RxMutationOptions<Parameter, Result> | Operation<Parameter, Observable<Result>>): Mutation<Parameter, Result>;
|
|
@@ -14,17 +14,13 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { Signal } from '@angular/core';
|
|
16
16
|
import { EntityId } from '@ngrx/signals/entities';
|
|
17
|
-
|
|
18
|
-
// withEntites models
|
|
19
17
|
export type EntityState<Entity> = {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
entityMap: Record<EntityId, Entity>;
|
|
19
|
+
ids: EntityId[];
|
|
22
20
|
};
|
|
23
|
-
|
|
24
21
|
export type EntityComputed<Entity> = {
|
|
25
|
-
|
|
22
|
+
entities: Signal<Entity[]>;
|
|
26
23
|
};
|
|
27
|
-
|
|
28
24
|
export type NamedEntityComputed<Entity, Collection extends string> = {
|
|
29
|
-
|
|
25
|
+
[K in keyof EntityComputed<Entity> as `${Collection}${Capitalize<K>}`]: EntityComputed<Entity>[K];
|
|
30
26
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function throwIfNull<T>(obj: T): NonNullable<T>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare const keyPath = "ngrxToolkitKeyPath";
|
|
3
|
+
export declare const dbName = "ngrxToolkitDb";
|
|
4
|
+
export declare const storeName = "ngrxToolkitStore";
|
|
5
|
+
export declare const VERSION: number;
|
|
6
|
+
export declare class IndexedDBService {
|
|
7
|
+
/**
|
|
8
|
+
* write to indexedDB
|
|
9
|
+
* @param key
|
|
10
|
+
* @param data
|
|
11
|
+
*/
|
|
12
|
+
setItem(key: string, data: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* read from indexedDB
|
|
15
|
+
* @param key
|
|
16
|
+
*/
|
|
17
|
+
getItem(key: string): Promise<string | null>;
|
|
18
|
+
/**
|
|
19
|
+
* delete indexedDB
|
|
20
|
+
* @param key
|
|
21
|
+
*/
|
|
22
|
+
clear(key: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* open indexedDB
|
|
25
|
+
*/
|
|
26
|
+
private openDB;
|
|
27
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<IndexedDBService, never>;
|
|
28
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<IndexedDBService>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare class LocalStorageService {
|
|
3
|
+
getItem(key: string): string | null;
|
|
4
|
+
setItem(key: string, data: string): void;
|
|
5
|
+
clear(key: string): void;
|
|
6
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LocalStorageService, never>;
|
|
7
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<LocalStorageService>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Signal, WritableSignal } from '@angular/core';
|
|
2
|
+
import { EmptyFeatureResult, WritableStateSource } from '@ngrx/signals';
|
|
3
|
+
import { SyncConfig } from '../with-storage-sync';
|
|
4
|
+
export type SyncMethods = {
|
|
5
|
+
clearStorage(): void;
|
|
6
|
+
readFromStorage(): void;
|
|
7
|
+
writeToStorage(): void;
|
|
8
|
+
};
|
|
9
|
+
export type SyncFeatureResult = EmptyFeatureResult & {
|
|
10
|
+
methods: SyncMethods;
|
|
11
|
+
};
|
|
12
|
+
export type SyncStoreForFactory<State extends object> = WritableStateSource<State>;
|
|
13
|
+
export type SyncStorageStrategy<State extends object> = ((config: Required<SyncConfig<State>>, store: SyncStoreForFactory<State>, useStubs: boolean) => SyncMethods) & {
|
|
14
|
+
type: 'sync';
|
|
15
|
+
};
|
|
16
|
+
export type AsyncMethods = {
|
|
17
|
+
clearStorage(): Promise<void>;
|
|
18
|
+
readFromStorage(): Promise<void>;
|
|
19
|
+
writeToStorage(): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* AsyncFeatureResult is used as the public interface that users interact with
|
|
23
|
+
* when calling `withIndexedDB`. It intentionally omits the internal SYNC_STATUS
|
|
24
|
+
* property to avoid TypeScript error TS4058 (return type of public method
|
|
25
|
+
* includes private type).
|
|
26
|
+
*
|
|
27
|
+
* For internal implementation, we use AsyncStoreForFactory which includes
|
|
28
|
+
* the SYNC_STATUS property needed for state management.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SYNC_STATUS: unique symbol;
|
|
31
|
+
export type SyncStatus = 'idle' | 'syncing' | 'synced';
|
|
32
|
+
export type InternalAsyncProps = AsyncFeatureResult['props'] & {
|
|
33
|
+
[SYNC_STATUS]: WritableSignal<SyncStatus>;
|
|
34
|
+
};
|
|
35
|
+
export type AsyncFeatureResult = EmptyFeatureResult & {
|
|
36
|
+
methods: AsyncMethods;
|
|
37
|
+
props: {
|
|
38
|
+
isSynced: Signal<boolean>;
|
|
39
|
+
whenSynced: () => Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export type AsyncStoreForFactory<State extends object> = WritableStateSource<State> & InternalAsyncProps;
|
|
43
|
+
export type AsyncStorageStrategy<State extends object> = ((config: Required<SyncConfig<State>>, store: AsyncStoreForFactory<State>, useStubs: boolean) => AsyncMethods) & {
|
|
44
|
+
type: 'async';
|
|
45
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare class SessionStorageService {
|
|
3
|
+
getItem(key: string): string | null;
|
|
4
|
+
setItem(key: string, data: string): void;
|
|
5
|
+
clear(key: string): void;
|
|
6
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SessionStorageService, never>;
|
|
7
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SessionStorageService>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SignalStoreFeature, SignalStoreFeatureResult } from '@ngrx/signals';
|
|
2
|
+
import { AsyncFeatureResult, AsyncStorageStrategy, SyncFeatureResult, SyncStorageStrategy } from './internal/models';
|
|
3
|
+
export type SyncConfig<State> = {
|
|
4
|
+
/**
|
|
5
|
+
* The key which is used to access the storage.
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
/**
|
|
9
|
+
* Flag indicating if the store should read from storage on init and write to storage on every state change.
|
|
10
|
+
*
|
|
11
|
+
* `true` by default
|
|
12
|
+
*/
|
|
13
|
+
autoSync?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Function to select that portion of the state which should be stored.
|
|
16
|
+
*
|
|
17
|
+
* Returns the whole state object by default
|
|
18
|
+
*/
|
|
19
|
+
select?: (state: State) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Function used to parse the state coming from storage.
|
|
22
|
+
*
|
|
23
|
+
* `JSON.parse()` by default
|
|
24
|
+
*/
|
|
25
|
+
parse?: (stateString: string) => State;
|
|
26
|
+
/**
|
|
27
|
+
* Function used to transform the state into a string representation.
|
|
28
|
+
*
|
|
29
|
+
* `JSON.stringify()` by default
|
|
30
|
+
*/
|
|
31
|
+
stringify?: (state: State) => string;
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use {@link withSessionStorage} instead.
|
|
34
|
+
* Factory function used to switch to sessionStorage.
|
|
35
|
+
*
|
|
36
|
+
* `localStorage` by default
|
|
37
|
+
*/
|
|
38
|
+
storage?: () => Storage;
|
|
39
|
+
};
|
|
40
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(key: string): SignalStoreFeature<Input, SyncFeatureResult>;
|
|
41
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(key: string, storageStrategy: AsyncStorageStrategy<Input['state']>): SignalStoreFeature<Input, AsyncFeatureResult>;
|
|
42
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(key: string, storageStrategy: SyncStorageStrategy<Input['state']>): SignalStoreFeature<Input, SyncFeatureResult>;
|
|
43
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(config: SyncConfig<Input['state']>): SignalStoreFeature<Input, SyncFeatureResult>;
|
|
44
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(config: SyncConfig<Input['state']>, storageStrategy: AsyncStorageStrategy<Input['state']>): SignalStoreFeature<Input, AsyncFeatureResult>;
|
|
45
|
+
export declare function withStorageSync<Input extends SignalStoreFeatureResult>(config: SyncConfig<Input['state']>, storageStrategy: SyncStorageStrategy<Input['state']>): SignalStoreFeature<Input, SyncFeatureResult>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { EmptyFeatureResult, SignalStoreFeature } from '@ngrx/signals';
|
|
3
|
+
export type CallState = 'init' | 'loading' | 'loaded' | {
|
|
4
|
+
error: string;
|
|
5
|
+
};
|
|
6
|
+
export type CallStateSlice = {
|
|
7
|
+
callState: CallState;
|
|
8
|
+
};
|
|
9
|
+
export type NamedCallStateSlice<Collection extends string> = {
|
|
10
|
+
[K in keyof CallStateSlice as Collection extends '' ? `${Collection}${K}` : `${Collection}${Capitalize<K>}`]: CallStateSlice[K];
|
|
11
|
+
};
|
|
12
|
+
export type CallStateSignals = {
|
|
13
|
+
loading: Signal<boolean>;
|
|
14
|
+
loaded: Signal<boolean>;
|
|
15
|
+
error: Signal<string | null>;
|
|
16
|
+
};
|
|
17
|
+
export type NamedCallStateSignals<Prop extends string> = {
|
|
18
|
+
[K in keyof CallStateSignals as Prop extends '' ? `${Prop}${K}` : `${Prop}${Capitalize<K>}`]: CallStateSignals[K];
|
|
19
|
+
};
|
|
20
|
+
export type SetCallState<Prop extends string | undefined> = Prop extends string ? NamedCallStateSlice<Prop> : CallStateSlice;
|
|
21
|
+
export declare function deriveCallStateKeys<Collection extends string>(collection?: Collection): {
|
|
22
|
+
callStateKey: string;
|
|
23
|
+
loadingKey: string;
|
|
24
|
+
loadedKey: string;
|
|
25
|
+
errorKey: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function getCallStateKeys(config?: {
|
|
28
|
+
collection?: string;
|
|
29
|
+
}): {
|
|
30
|
+
callStateKey: string;
|
|
31
|
+
loadingKey: string;
|
|
32
|
+
loadedKey: string;
|
|
33
|
+
errorKey: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function getCollectionArray(config: {
|
|
36
|
+
collection?: string;
|
|
37
|
+
} | {
|
|
38
|
+
collections?: string[];
|
|
39
|
+
}): string[] | undefined;
|
|
40
|
+
export declare function withCallState<Collection extends string>(config: {
|
|
41
|
+
collections: Collection[];
|
|
42
|
+
}): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
|
|
43
|
+
state: NamedCallStateSlice<Collection>;
|
|
44
|
+
props: NamedCallStateSignals<Collection>;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function withCallState<Collection extends string>(config: {
|
|
47
|
+
collection: Collection;
|
|
48
|
+
}): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
|
|
49
|
+
state: NamedCallStateSlice<Collection>;
|
|
50
|
+
props: NamedCallStateSignals<Collection>;
|
|
51
|
+
}>;
|
|
52
|
+
export declare function withCallState(): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
|
|
53
|
+
state: CallStateSlice;
|
|
54
|
+
props: CallStateSignals;
|
|
55
|
+
}>;
|
|
56
|
+
export declare function setLoading<Prop extends string | undefined = undefined>(prop?: Prop): SetCallState<Prop>;
|
|
57
|
+
export declare function setLoaded<Prop extends string | undefined = undefined>(prop?: Prop): SetCallState<Prop>;
|
|
58
|
+
export declare function setError<Prop extends string | undefined = undefined>(error: unknown, prop?: Prop): SetCallState<Prop>;
|