@angular-architects/ngrx-toolkit 19.3.0 → 19.4.0

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.
Files changed (126) hide show
  1. package/eslint.config.cjs +43 -0
  2. package/jest.config.ts +22 -0
  3. package/ng-package.json +7 -0
  4. package/package.json +4 -21
  5. package/project.json +37 -0
  6. package/redux-connector/docs/README.md +131 -0
  7. package/redux-connector/index.ts +6 -0
  8. package/redux-connector/ng-package.json +5 -0
  9. package/redux-connector/src/lib/create-redux.ts +102 -0
  10. package/redux-connector/src/lib/model.ts +89 -0
  11. package/redux-connector/src/lib/rxjs-interop/redux-method.ts +66 -0
  12. package/redux-connector/src/lib/signal-redux-store.ts +59 -0
  13. package/redux-connector/src/lib/util.ts +22 -0
  14. package/{index.d.ts → src/index.ts} +35 -6
  15. package/src/lib/assertions/assertions.ts +9 -0
  16. package/{lib/devtools/features/with-disabled-name-indicies.d.ts → src/lib/devtools/features/with-disabled-name-indicies.ts} +5 -1
  17. package/{lib/devtools/features/with-glitch-tracking.d.ts → src/lib/devtools/features/with-glitch-tracking.ts} +6 -1
  18. package/{lib/devtools/features/with-mapper.d.ts → src/lib/devtools/features/with-mapper.ts} +7 -1
  19. package/src/lib/devtools/internal/current-action-names.ts +1 -0
  20. package/src/lib/devtools/internal/default-tracker.ts +60 -0
  21. package/src/lib/devtools/internal/devtools-feature.ts +37 -0
  22. package/src/lib/devtools/internal/devtools-syncer.service.ts +202 -0
  23. package/src/lib/devtools/internal/glitch-tracker.service.ts +61 -0
  24. package/src/lib/devtools/internal/models.ts +29 -0
  25. package/{lib/devtools/provide-devtools-config.d.ts → src/lib/devtools/provide-devtools-config.ts} +16 -4
  26. package/src/lib/devtools/rename-devtools-name.ts +21 -0
  27. package/src/lib/devtools/tests/action-name.spec.ts +48 -0
  28. package/src/lib/devtools/tests/basic.spec.ts +111 -0
  29. package/src/lib/devtools/tests/connecting.spec.ts +37 -0
  30. package/src/lib/devtools/tests/helpers.spec.ts +43 -0
  31. package/src/lib/devtools/tests/naming.spec.ts +216 -0
  32. package/src/lib/devtools/tests/provide-devtools-config.spec.ts +25 -0
  33. package/src/lib/devtools/tests/types.spec.ts +19 -0
  34. package/src/lib/devtools/tests/update-state.spec.ts +29 -0
  35. package/src/lib/devtools/tests/with-devtools.spec.ts +5 -0
  36. package/src/lib/devtools/tests/with-glitch-tracking.spec.ts +272 -0
  37. package/src/lib/devtools/tests/with-mapper.spec.ts +69 -0
  38. package/src/lib/devtools/update-state.ts +38 -0
  39. package/{lib/devtools/with-dev-tools-stub.d.ts → src/lib/devtools/with-dev-tools-stub.ts} +2 -1
  40. package/src/lib/devtools/with-devtools.ts +81 -0
  41. package/src/lib/flattening-operator.ts +42 -0
  42. package/src/lib/immutable-state/deep-freeze.ts +43 -0
  43. package/src/lib/immutable-state/is-dev-mode.ts +6 -0
  44. package/src/lib/immutable-state/tests/with-immutable-state.spec.ts +260 -0
  45. package/src/lib/immutable-state/with-immutable-state.ts +115 -0
  46. package/src/lib/mutation/http-mutation.spec.ts +473 -0
  47. package/src/lib/mutation/http-mutation.ts +172 -0
  48. package/src/lib/mutation/mutation.ts +26 -0
  49. package/src/lib/mutation/rx-mutation.spec.ts +594 -0
  50. package/src/lib/mutation/rx-mutation.ts +208 -0
  51. package/src/lib/shared/prettify.ts +3 -0
  52. package/{lib/shared/signal-store-models.d.ts → src/lib/shared/signal-store-models.ts} +8 -4
  53. package/src/lib/shared/throw-if-null.ts +7 -0
  54. package/src/lib/storage-sync/features/with-indexed-db.ts +81 -0
  55. package/src/lib/storage-sync/features/with-local-storage.ts +58 -0
  56. package/src/lib/storage-sync/internal/indexeddb.service.ts +124 -0
  57. package/src/lib/storage-sync/internal/local-storage.service.ts +19 -0
  58. package/src/lib/storage-sync/internal/models.ts +62 -0
  59. package/src/lib/storage-sync/internal/session-storage.service.ts +18 -0
  60. package/src/lib/storage-sync/tests/indexeddb.service.spec.ts +99 -0
  61. package/src/lib/storage-sync/tests/with-storage-async.spec.ts +308 -0
  62. package/src/lib/storage-sync/tests/with-storage-sync.spec.ts +268 -0
  63. package/src/lib/storage-sync/with-storage-sync.ts +233 -0
  64. package/src/lib/with-call-state.spec.ts +42 -0
  65. package/src/lib/with-call-state.ts +195 -0
  66. package/src/lib/with-conditional.spec.ts +125 -0
  67. package/{lib/with-conditional.d.ts → src/lib/with-conditional.ts} +31 -7
  68. package/src/lib/with-data-service.spec.ts +564 -0
  69. package/src/lib/with-data-service.ts +433 -0
  70. package/src/lib/with-feature-factory.spec.ts +69 -0
  71. package/{lib/with-feature-factory.d.ts → src/lib/with-feature-factory.ts} +32 -4
  72. package/src/lib/with-mutations.spec.ts +537 -0
  73. package/src/lib/with-mutations.ts +146 -0
  74. package/src/lib/with-pagination.spec.ts +90 -0
  75. package/src/lib/with-pagination.ts +353 -0
  76. package/src/lib/with-redux.spec.ts +258 -0
  77. package/src/lib/with-redux.ts +387 -0
  78. package/src/lib/with-reset.spec.ts +112 -0
  79. package/src/lib/with-reset.ts +62 -0
  80. package/src/lib/with-undo-redo.spec.ts +287 -0
  81. package/src/lib/with-undo-redo.ts +199 -0
  82. package/src/test-setup.ts +8 -0
  83. package/tsconfig.json +29 -0
  84. package/tsconfig.lib.json +17 -0
  85. package/tsconfig.lib.prod.json +9 -0
  86. package/tsconfig.spec.json +17 -0
  87. package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs +0 -119
  88. package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs.map +0 -1
  89. package/fesm2022/angular-architects-ngrx-toolkit.mjs +0 -1967
  90. package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +0 -1
  91. package/lib/assertions/assertions.d.ts +0 -2
  92. package/lib/devtools/internal/current-action-names.d.ts +0 -1
  93. package/lib/devtools/internal/default-tracker.d.ts +0 -13
  94. package/lib/devtools/internal/devtools-feature.d.ts +0 -24
  95. package/lib/devtools/internal/devtools-syncer.service.d.ts +0 -35
  96. package/lib/devtools/internal/glitch-tracker.service.d.ts +0 -18
  97. package/lib/devtools/internal/models.d.ts +0 -24
  98. package/lib/devtools/rename-devtools-name.d.ts +0 -7
  99. package/lib/devtools/update-state.d.ts +0 -15
  100. package/lib/devtools/with-devtools.d.ts +0 -24
  101. package/lib/flattening-operator.d.ts +0 -14
  102. package/lib/immutable-state/deep-freeze.d.ts +0 -11
  103. package/lib/immutable-state/is-dev-mode.d.ts +0 -1
  104. package/lib/immutable-state/with-immutable-state.d.ts +0 -60
  105. package/lib/rx-mutation.d.ts +0 -58
  106. package/lib/shared/throw-if-null.d.ts +0 -1
  107. package/lib/storage-sync/features/with-indexed-db.d.ts +0 -2
  108. package/lib/storage-sync/features/with-local-storage.d.ts +0 -3
  109. package/lib/storage-sync/internal/indexeddb.service.d.ts +0 -29
  110. package/lib/storage-sync/internal/local-storage.service.d.ts +0 -8
  111. package/lib/storage-sync/internal/models.d.ts +0 -45
  112. package/lib/storage-sync/internal/session-storage.service.d.ts +0 -8
  113. package/lib/storage-sync/with-storage-sync.d.ts +0 -45
  114. package/lib/with-call-state.d.ts +0 -58
  115. package/lib/with-data-service.d.ts +0 -109
  116. package/lib/with-mutations.d.ts +0 -66
  117. package/lib/with-pagination.d.ts +0 -98
  118. package/lib/with-redux.d.ts +0 -147
  119. package/lib/with-reset.d.ts +0 -29
  120. package/lib/with-undo-redo.d.ts +0 -31
  121. package/redux-connector/index.d.ts +0 -2
  122. package/redux-connector/src/lib/create-redux.d.ts +0 -13
  123. package/redux-connector/src/lib/model.d.ts +0 -40
  124. package/redux-connector/src/lib/rxjs-interop/redux-method.d.ts +0 -14
  125. package/redux-connector/src/lib/signal-redux-store.d.ts +0 -11
  126. package/redux-connector/src/lib/util.d.ts +0 -5
@@ -1,60 +0,0 @@
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
- }>;
@@ -1,58 +0,0 @@
1
- import { Injector } from '@angular/core';
2
- import { Observable } from 'rxjs';
3
- import { FlatteningOperator } from './flattening-operator';
4
- import { Mutation } from './with-mutations';
5
- export type Func<P, R> = (params: P) => R;
6
- export interface RxMutationOptions<P, R> {
7
- operation: Func<P, Observable<R>>;
8
- onSuccess?: (result: R, params: P) => void;
9
- onError?: (error: unknown, params: P) => 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
- * ```typescript
26
- * export type Params = {
27
- * value: number;
28
- * };
29
- *
30
- * export const CounterStore = signalStore(
31
- * { providedIn: 'root' },
32
- * withState({ counter: 0 }),
33
- * withMutations((store) => ({
34
- * increment: rxMutation({
35
- * operation: (params: Params) => {
36
- * return calcSum(store.counter(), params.value);
37
- * },
38
- * operator: concatOp,
39
- * onSuccess: (result) => {
40
- * console.log('result', result);
41
- * patchState(store, { counter: result });
42
- * },
43
- * onError: (error) => {
44
- * console.error('Error occurred:', error);
45
- * },
46
- * }),
47
- * })),
48
- * );
49
- *
50
- * function calcSum(a: number, b: number): Observable<number> {
51
- * return of(a + b);
52
- * }
53
- * ```
54
- *
55
- * @param options
56
- * @returns
57
- */
58
- export declare function rxMutation<P, R>(options: RxMutationOptions<P, R>): Mutation<P, R>;
@@ -1 +0,0 @@
1
- export declare function throwIfNull<T>(obj: T): NonNullable<T>;
@@ -1,2 +0,0 @@
1
- import { AsyncStorageStrategy } from '../internal/models';
2
- export declare function withIndexedDB<State extends object>(): AsyncStorageStrategy<State>;
@@ -1,3 +0,0 @@
1
- import { SyncStorageStrategy } from '../internal/models';
2
- export declare function withLocalStorage<State extends object>(): SyncStorageStrategy<State>;
3
- export declare function withSessionStorage<State extends object>(): SyncStorageStrategy<State>;
@@ -1,29 +0,0 @@
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
- }
@@ -1,8 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
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>;
@@ -1,58 +0,0 @@
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>;
@@ -1,109 +0,0 @@
1
- import { ProviderToken, Signal } from '@angular/core';
2
- import { EmptyFeatureResult, SignalStoreFeature } from '@ngrx/signals';
3
- import { EntityId, NamedEntityState } from '@ngrx/signals/entities';
4
- import { EntityState } from './shared/signal-store-models';
5
- import { CallState, NamedCallStateSlice } from './with-call-state';
6
- export type Filter = Record<string, unknown>;
7
- export type Entity = {
8
- id: EntityId;
9
- };
10
- export interface DataService<E extends Entity, F extends Filter> {
11
- load(filter: F): Promise<E[]>;
12
- loadById(id: EntityId): Promise<E>;
13
- create(entity: E): Promise<E>;
14
- update(entity: E): Promise<E>;
15
- updateAll(entity: E[]): Promise<E[]>;
16
- delete(entity: E): Promise<void>;
17
- }
18
- export declare function capitalize(str: string): string;
19
- export declare function getDataServiceKeys(options: {
20
- collection?: string;
21
- }): {
22
- filterKey: string;
23
- selectedIdsKey: string;
24
- selectedEntitiesKey: string;
25
- updateFilterKey: string;
26
- updateSelectedKey: string;
27
- loadKey: string;
28
- entitiesKey: string;
29
- entityMapKey: string;
30
- idsKey: string;
31
- currentKey: string;
32
- loadByIdKey: string;
33
- setCurrentKey: string;
34
- createKey: string;
35
- updateKey: string;
36
- updateAllKey: string;
37
- deleteKey: string;
38
- };
39
- export type NamedDataServiceState<E extends Entity, F extends Filter, Collection extends string> = {
40
- [K in Collection as `${K}Filter`]: F;
41
- } & {
42
- [K in Collection as `selected${Capitalize<K>}Ids`]: Record<EntityId, boolean>;
43
- } & {
44
- [K in Collection as `current${Capitalize<K>}`]: E;
45
- };
46
- export type DataServiceState<E extends Entity, F extends Filter> = {
47
- filter: F;
48
- selectedIds: Record<EntityId, boolean>;
49
- current: E;
50
- };
51
- export type DataServiceComputed<E extends Entity> = {
52
- selectedEntities: Signal<E[]>;
53
- };
54
- export type NamedDataServiceComputed<E extends Entity, Collection extends string> = {
55
- [K in Collection as `selected${Capitalize<K>}Entities`]: Signal<E[]>;
56
- };
57
- export type NamedDataServiceMethods<E extends Entity, F extends Filter, Collection extends string> = {
58
- [K in Collection as `update${Capitalize<K>}Filter`]: (filter: F) => void;
59
- } & {
60
- [K in Collection as `updateSelected${Capitalize<K>}Entities`]: (id: EntityId, selected: boolean) => void;
61
- } & {
62
- [K in Collection as `load${Capitalize<K>}Entities`]: () => Promise<void>;
63
- } & {
64
- [K in Collection as `setCurrent${Capitalize<K>}`]: (entity: E) => void;
65
- } & {
66
- [K in Collection as `load${Capitalize<K>}ById`]: (id: EntityId) => Promise<void>;
67
- } & {
68
- [K in Collection as `create${Capitalize<K>}`]: (entity: E) => Promise<void>;
69
- } & {
70
- [K in Collection as `update${Capitalize<K>}`]: (entity: E) => Promise<void>;
71
- } & {
72
- [K in Collection as `updateAll${Capitalize<K>}`]: (entity: E[]) => Promise<void>;
73
- } & {
74
- [K in Collection as `delete${Capitalize<K>}`]: (entity: E) => Promise<void>;
75
- };
76
- export type DataServiceMethods<E extends Entity, F extends Filter> = {
77
- updateFilter: (filter: F) => void;
78
- updateSelected: (id: EntityId, selected: boolean) => void;
79
- load: () => Promise<void>;
80
- setCurrent(entity: E): void;
81
- loadById(id: EntityId): Promise<void>;
82
- create(entity: E): Promise<void>;
83
- update(entity: E): Promise<void>;
84
- updateAll(entities: E[]): Promise<void>;
85
- delete(entity: E): Promise<void>;
86
- };
87
- export declare function withDataService<E extends Entity, F extends Filter, Collection extends string>(options: {
88
- dataServiceType: ProviderToken<DataService<E, F>>;
89
- filter: F;
90
- collection: Collection;
91
- }): SignalStoreFeature<EmptyFeatureResult & {
92
- state: NamedCallStateSlice<Collection> & NamedEntityState<E, Collection>;
93
- }, {
94
- state: NamedDataServiceState<E, F, Collection>;
95
- props: NamedDataServiceComputed<E, Collection>;
96
- methods: NamedDataServiceMethods<E, F, Collection>;
97
- }>;
98
- export declare function withDataService<E extends Entity, F extends Filter>(options: {
99
- dataServiceType: ProviderToken<DataService<E, F>>;
100
- filter: F;
101
- }): SignalStoreFeature<EmptyFeatureResult & {
102
- state: {
103
- callState: CallState;
104
- } & EntityState<E>;
105
- }, {
106
- state: DataServiceState<E, F>;
107
- props: DataServiceComputed<E>;
108
- methods: DataServiceMethods<E, F>;
109
- }>;
@@ -1,66 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult, StateSignals, WritableStateSource } from '@ngrx/signals';
3
- export type Mutation<P, R> = {
4
- (params: P): Promise<MutationResult<R>>;
5
- status: Signal<MutationStatus>;
6
- isPending: Signal<boolean>;
7
- error: Signal<unknown>;
8
- };
9
- type MutationsDictionary = Record<string, Mutation<any, any>>;
10
- export type MutationResult<T> = {
11
- status: 'success';
12
- value: T;
13
- } | {
14
- status: 'error';
15
- error: unknown;
16
- } | {
17
- status: 'aborted';
18
- };
19
- export type MutationStatus = 'idle' | 'pending' | 'error' | 'success';
20
- export type MethodsDictionary = Record<string, Function>;
21
- type NamedMutationProps<T extends MutationsDictionary> = {
22
- [Prop in keyof T as `${Prop & string}IsPending`]: Signal<boolean>;
23
- } & {
24
- [Prop in keyof T as `${Prop & string}Status`]: Signal<MutationStatus>;
25
- } & {
26
- [Prop in keyof T as `${Prop & string}Error`]: Signal<Error | undefined>;
27
- };
28
- type NamedMutationMethods<T extends MutationsDictionary> = {
29
- [Prop in keyof T as `${Prop & string}`]: T[Prop] extends Mutation<infer P, infer R> ? Mutation<P, R> : never;
30
- };
31
- export type NamedMutationResult<T extends MutationsDictionary> = EmptyFeatureResult & {
32
- props: NamedMutationProps<T>;
33
- methods: NamedMutationMethods<T>;
34
- };
35
- /**
36
- * Adds mutation methods to the store. Also, for each mutation method, several
37
- * Signals are added informing about the mutation's status and errors.
38
- *
39
- * ```typescript
40
- * export type Params = {
41
- * value: number;
42
- * };
43
- *
44
- * export const CounterStore = signalStore(
45
- * { providedIn: 'root' },
46
- * withState({ counter: 0 }),
47
- * withMutations((store) => ({
48
- * increment: rxMutation({ ... }),
49
- * })),
50
- * );
51
- * ```
52
- *
53
- * There are several types of mutations. In the example shown, an {@link module:rx-mutation.rxMutation | rxMutation}
54
- * leveraging RxJS is used
55
- *
56
- * For the defined `increment` mutation, several the following properties and
57
- * methods are added to the store:
58
- * - `increment(params: Params): Promise<MutationResult<number>>`: The mutation method.
59
- * - `incrementIsPending`: A signal indicating if the mutation is in progress.
60
- * - `incrementStatus`: A signal representing the current status of the mutation.
61
- * - `incrementError`: A signal containing any error that occurred during the mutation.
62
- *
63
- * @param mutationsFactory
64
- */
65
- export declare function withMutations<Input extends SignalStoreFeatureResult, Result extends MutationsDictionary>(mutationsFactory: (store: Input['props'] & Input['methods'] & WritableStateSource<Input['state']> & StateSignals<Input['state']>) => Result): SignalStoreFeature<Input, NamedMutationResult<Result>>;
66
- export {};
@@ -1,98 +0,0 @@
1
- /** With pagination comes in two flavors the first one is local pagination or in memory pagination. For example we have 2000 items which we want
2
- * to display in a table and the response payload is small enough to be stored in the memory. But we can not display all 2000 items at once
3
- * so we need to paginate the data. The second flavor is server side pagination where the response payload is too large to be stored in the memory
4
- * and we need to fetch the data from the server in chunks. In the second case we 'could' also cache the data in the memory but that could lead to
5
- * other problems like memory leaks and stale data. So we will not cache the data in the memory in the second case.
6
- * This feature implements the local pagination.
7
- */
8
- import { Signal } from '@angular/core';
9
- import { EmptyFeatureResult, SignalStoreFeature } from '@ngrx/signals';
10
- export type Page = {
11
- label: string | number;
12
- value: number;
13
- };
14
- export type NamedPaginationServiceState<E, Collection extends string> = {
15
- [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Array<E>;
16
- } & {
17
- [K in Collection as `${Lowercase<K>}CurrentPage`]: number;
18
- } & {
19
- [K in Collection as `${Lowercase<K>}PageSize`]: number;
20
- } & {
21
- [K in Collection as `${Lowercase<K>}TotalCount`]: number;
22
- } & {
23
- [K in Collection as `${Lowercase<K>}PageCount`]: number;
24
- } & {
25
- [K in Collection as `${Lowercase<K>}PageNavigationArray`]: number;
26
- } & {
27
- [K in Collection as `${Lowercase<K>}PageNavigationArrayMax`]: number;
28
- };
29
- export type NamedPaginationServiceSignals<E, Collection extends string> = {
30
- [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Signal<E[]>;
31
- } & {
32
- [K in Collection as `${Lowercase<K>}CurrentPage`]: Signal<number>;
33
- } & {
34
- [K in Collection as `${Lowercase<K>}PageSize`]: Signal<number>;
35
- } & {
36
- [K in Collection as `${Lowercase<K>}TotalCount`]: Signal<number>;
37
- } & {
38
- [K in Collection as `${Lowercase<K>}PageCount`]: Signal<number>;
39
- } & {
40
- [K in Collection as `${Lowercase<K>}PageNavigationArray`]: Signal<Page[]>;
41
- } & {
42
- [K in Collection as `${Lowercase<K>}PageNavigationArrayMax`]: Signal<number>;
43
- } & {
44
- [K in Collection as `hasNext${Capitalize<K>}Page`]: Signal<boolean>;
45
- } & {
46
- [K in Collection as `hasPrevious${Capitalize<K>}Page`]: Signal<boolean>;
47
- };
48
- export type PaginationServiceState<E> = {
49
- selectedPageEntities: Array<E>;
50
- currentPage: number;
51
- pageSize: number;
52
- totalCount: number;
53
- pageCount: number;
54
- pageNavigationArray: Page[];
55
- pageNavigationArrayMax: number;
56
- };
57
- export type PaginationServiceSignals<E> = {
58
- selectedPageEntities: Signal<E[]>;
59
- currentPage: Signal<number>;
60
- pageSize: Signal<number>;
61
- totalCount: Signal<number>;
62
- pageCount: Signal<number>;
63
- pageNavigationArray: Signal<Page[]>;
64
- pageNavigationArrayMax: Signal<number>;
65
- hasNextPage: Signal<boolean>;
66
- hasPreviousPage: Signal<boolean>;
67
- };
68
- export type SetPaginationState<E, Collection extends string | undefined> = Collection extends string ? NamedPaginationServiceState<E, Collection> : PaginationServiceState<E>;
69
- export declare function withPagination<E, Collection extends string>(options: {
70
- entity: E;
71
- collection: Collection;
72
- }): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
73
- state: NamedPaginationServiceState<E, Collection>;
74
- props: NamedPaginationServiceSignals<E, Collection>;
75
- }>;
76
- export declare function withPagination<E>(): SignalStoreFeature<EmptyFeatureResult, EmptyFeatureResult & {
77
- state: PaginationServiceState<E>;
78
- props: PaginationServiceSignals<E>;
79
- }>;
80
- export declare function gotoPage<E, Collection extends string>(page: number, options?: {
81
- collection: Collection;
82
- }): Partial<SetPaginationState<E, Collection>>;
83
- export declare function setPageSize<E, Collection extends string>(pageSize: number, options?: {
84
- collection: Collection;
85
- }): Partial<SetPaginationState<E, Collection>>;
86
- export declare function nextPage<E, Collection extends string>(options?: {
87
- collection: Collection;
88
- }): Partial<SetPaginationState<E, Collection>>;
89
- export declare function previousPage<E, Collection extends string>(options?: {
90
- collection: Collection;
91
- }): Partial<SetPaginationState<E, Collection>>;
92
- export declare function firstPage<E, Collection extends string>(options?: {
93
- collection: Collection;
94
- }): Partial<SetPaginationState<E, Collection>>;
95
- export declare function setMaxPageNavigationArrayItems<E, Collection extends string>(maxPageNavigationArrayItems: number, options?: {
96
- collection: Collection;
97
- }): Partial<SetPaginationState<E, Collection>>;
98
- export declare function createPageArray(currentPage: number, itemsPerPage: number, totalItems: number, paginationRange: number): Page[];