@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.
Files changed (128) hide show
  1. package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs +119 -0
  2. package/fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs.map +1 -0
  3. package/fesm2022/angular-architects-ngrx-toolkit.mjs +2108 -0
  4. package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -0
  5. package/{src/index.ts → index.d.ts} +5 -32
  6. package/lib/assertions/assertions.d.ts +2 -0
  7. package/{src/lib/devtools/features/with-disabled-name-indicies.ts → lib/devtools/features/with-disabled-name-indicies.d.ts} +1 -5
  8. package/{src/lib/devtools/features/with-glitch-tracking.ts → lib/devtools/features/with-glitch-tracking.d.ts} +1 -6
  9. package/{src/lib/devtools/features/with-mapper.ts → lib/devtools/features/with-mapper.d.ts} +1 -7
  10. package/lib/devtools/internal/current-action-names.d.ts +1 -0
  11. package/lib/devtools/internal/default-tracker.d.ts +13 -0
  12. package/lib/devtools/internal/devtools-feature.d.ts +24 -0
  13. package/lib/devtools/internal/devtools-syncer.service.d.ts +39 -0
  14. package/lib/devtools/internal/glitch-tracker.service.d.ts +18 -0
  15. package/lib/devtools/internal/models.d.ts +24 -0
  16. package/{src/lib/devtools/provide-devtools-config.ts → lib/devtools/provide-devtools-config.d.ts} +4 -16
  17. package/lib/devtools/rename-devtools-name.d.ts +7 -0
  18. package/lib/devtools/update-state.d.ts +15 -0
  19. package/{src/lib/devtools/with-dev-tools-stub.ts → lib/devtools/with-dev-tools-stub.d.ts} +1 -2
  20. package/lib/devtools/with-devtools.d.ts +24 -0
  21. package/lib/flattening-operator.d.ts +14 -0
  22. package/lib/immutable-state/deep-freeze.d.ts +11 -0
  23. package/lib/immutable-state/is-dev-mode.d.ts +1 -0
  24. package/lib/immutable-state/with-immutable-state.d.ts +60 -0
  25. package/lib/mutation/http-mutation.d.ts +86 -0
  26. package/lib/mutation/mutation.d.ts +20 -0
  27. package/lib/mutation/rx-mutation.d.ts +76 -0
  28. package/{src/lib/shared/signal-store-models.ts → lib/shared/signal-store-models.d.ts} +4 -8
  29. package/lib/shared/throw-if-null.d.ts +1 -0
  30. package/lib/storage-sync/features/with-indexed-db.d.ts +2 -0
  31. package/lib/storage-sync/features/with-local-storage.d.ts +3 -0
  32. package/lib/storage-sync/internal/indexeddb.service.d.ts +29 -0
  33. package/lib/storage-sync/internal/local-storage.service.d.ts +8 -0
  34. package/lib/storage-sync/internal/models.d.ts +45 -0
  35. package/lib/storage-sync/internal/session-storage.service.d.ts +8 -0
  36. package/lib/storage-sync/with-storage-sync.d.ts +45 -0
  37. package/lib/with-call-state.d.ts +58 -0
  38. package/{src/lib/with-conditional.ts → lib/with-conditional.d.ts} +7 -31
  39. package/lib/with-data-service.d.ts +109 -0
  40. package/{src/lib/with-feature-factory.ts → lib/with-feature-factory.d.ts} +4 -32
  41. package/lib/with-mutations.d.ts +51 -0
  42. package/lib/with-pagination.d.ts +98 -0
  43. package/lib/with-redux.d.ts +147 -0
  44. package/lib/with-reset.d.ts +29 -0
  45. package/lib/with-undo-redo.d.ts +31 -0
  46. package/package.json +21 -4
  47. package/redux-connector/index.d.ts +2 -0
  48. package/redux-connector/src/lib/create-redux.d.ts +13 -0
  49. package/redux-connector/src/lib/model.d.ts +40 -0
  50. package/redux-connector/src/lib/rxjs-interop/redux-method.d.ts +14 -0
  51. package/redux-connector/src/lib/signal-redux-store.d.ts +11 -0
  52. package/redux-connector/src/lib/util.d.ts +5 -0
  53. package/eslint.config.cjs +0 -43
  54. package/jest.config.ts +0 -22
  55. package/ng-package.json +0 -7
  56. package/project.json +0 -37
  57. package/redux-connector/docs/README.md +0 -131
  58. package/redux-connector/index.ts +0 -6
  59. package/redux-connector/ng-package.json +0 -5
  60. package/redux-connector/src/lib/create-redux.ts +0 -102
  61. package/redux-connector/src/lib/model.ts +0 -89
  62. package/redux-connector/src/lib/rxjs-interop/redux-method.ts +0 -66
  63. package/redux-connector/src/lib/signal-redux-store.ts +0 -59
  64. package/redux-connector/src/lib/util.ts +0 -22
  65. package/src/lib/assertions/assertions.ts +0 -9
  66. package/src/lib/devtools/internal/current-action-names.ts +0 -1
  67. package/src/lib/devtools/internal/default-tracker.ts +0 -60
  68. package/src/lib/devtools/internal/devtools-feature.ts +0 -37
  69. package/src/lib/devtools/internal/devtools-syncer.service.ts +0 -202
  70. package/src/lib/devtools/internal/glitch-tracker.service.ts +0 -61
  71. package/src/lib/devtools/internal/models.ts +0 -29
  72. package/src/lib/devtools/rename-devtools-name.ts +0 -21
  73. package/src/lib/devtools/tests/action-name.spec.ts +0 -48
  74. package/src/lib/devtools/tests/basic.spec.ts +0 -111
  75. package/src/lib/devtools/tests/connecting.spec.ts +0 -37
  76. package/src/lib/devtools/tests/helpers.spec.ts +0 -43
  77. package/src/lib/devtools/tests/naming.spec.ts +0 -216
  78. package/src/lib/devtools/tests/provide-devtools-config.spec.ts +0 -25
  79. package/src/lib/devtools/tests/types.spec.ts +0 -19
  80. package/src/lib/devtools/tests/update-state.spec.ts +0 -29
  81. package/src/lib/devtools/tests/with-devtools.spec.ts +0 -5
  82. package/src/lib/devtools/tests/with-glitch-tracking.spec.ts +0 -272
  83. package/src/lib/devtools/tests/with-mapper.spec.ts +0 -69
  84. package/src/lib/devtools/update-state.ts +0 -38
  85. package/src/lib/devtools/with-devtools.ts +0 -81
  86. package/src/lib/flattening-operator.ts +0 -42
  87. package/src/lib/immutable-state/deep-freeze.ts +0 -43
  88. package/src/lib/immutable-state/is-dev-mode.ts +0 -6
  89. package/src/lib/immutable-state/tests/with-immutable-state.spec.ts +0 -260
  90. package/src/lib/immutable-state/with-immutable-state.ts +0 -115
  91. package/src/lib/mutation/http-mutation.spec.ts +0 -473
  92. package/src/lib/mutation/http-mutation.ts +0 -172
  93. package/src/lib/mutation/mutation.ts +0 -26
  94. package/src/lib/mutation/rx-mutation.spec.ts +0 -594
  95. package/src/lib/mutation/rx-mutation.ts +0 -208
  96. package/src/lib/shared/prettify.ts +0 -3
  97. package/src/lib/shared/throw-if-null.ts +0 -7
  98. package/src/lib/storage-sync/features/with-indexed-db.ts +0 -81
  99. package/src/lib/storage-sync/features/with-local-storage.ts +0 -58
  100. package/src/lib/storage-sync/internal/indexeddb.service.ts +0 -124
  101. package/src/lib/storage-sync/internal/local-storage.service.ts +0 -19
  102. package/src/lib/storage-sync/internal/models.ts +0 -62
  103. package/src/lib/storage-sync/internal/session-storage.service.ts +0 -18
  104. package/src/lib/storage-sync/tests/indexeddb.service.spec.ts +0 -99
  105. package/src/lib/storage-sync/tests/with-storage-async.spec.ts +0 -308
  106. package/src/lib/storage-sync/tests/with-storage-sync.spec.ts +0 -268
  107. package/src/lib/storage-sync/with-storage-sync.ts +0 -233
  108. package/src/lib/with-call-state.spec.ts +0 -42
  109. package/src/lib/with-call-state.ts +0 -195
  110. package/src/lib/with-conditional.spec.ts +0 -125
  111. package/src/lib/with-data-service.spec.ts +0 -564
  112. package/src/lib/with-data-service.ts +0 -433
  113. package/src/lib/with-feature-factory.spec.ts +0 -69
  114. package/src/lib/with-mutations.spec.ts +0 -537
  115. package/src/lib/with-mutations.ts +0 -146
  116. package/src/lib/with-pagination.spec.ts +0 -90
  117. package/src/lib/with-pagination.ts +0 -353
  118. package/src/lib/with-redux.spec.ts +0 -258
  119. package/src/lib/with-redux.ts +0 -387
  120. package/src/lib/with-reset.spec.ts +0 -112
  121. package/src/lib/with-reset.ts +0 -62
  122. package/src/lib/with-undo-redo.spec.ts +0 -287
  123. package/src/lib/with-undo-redo.ts +0 -199
  124. package/src/test-setup.ts +0 -8
  125. package/tsconfig.json +0 -29
  126. package/tsconfig.lib.json +0 -17
  127. package/tsconfig.lib.prod.json +0 -9
  128. package/tsconfig.spec.json +0 -17
@@ -1,11 +1,4 @@
1
- import {
2
- signalStoreFeature,
3
- SignalStoreFeature,
4
- SignalStoreFeatureResult,
5
- StateSignals,
6
- withState,
7
- } from '@ngrx/signals';
8
-
1
+ import { SignalStoreFeature, SignalStoreFeatureResult, StateSignals } from '@ngrx/signals';
9
2
  /**
10
3
  * `withConditional` activates a feature based on a given condition.
11
4
  *
@@ -49,26 +42,9 @@ import {
49
42
  * @param featureIfFalse - The feature to activate if the condition evaluates to `false`.
50
43
  * @returns A `SignalStoreFeature` that applies the selected feature based on the condition.
51
44
  */
52
- export function withConditional<
53
- Input extends SignalStoreFeatureResult,
54
- Output extends SignalStoreFeatureResult,
55
- >(
56
- condition: (
57
- store: StateSignals<Input['state']> & Input['props'] & Input['methods'],
58
- ) => boolean,
59
- featureIfTrue: SignalStoreFeature<NoInfer<Input>, Output>,
60
- featureIfFalse: SignalStoreFeature<NoInfer<Input>, NoInfer<Output>>,
61
- ): SignalStoreFeature<Input, Output> {
62
- return (store) => {
63
- const conditionStore = {
64
- ...store['stateSignals'],
65
- ...store['props'],
66
- ...store['methods'],
67
- };
68
- return condition(conditionStore)
69
- ? featureIfTrue(store)
70
- : featureIfFalse(store);
71
- };
72
- }
73
-
74
- export const emptyFeature = signalStoreFeature(withState({}));
45
+ export declare function withConditional<Input extends SignalStoreFeatureResult, Output extends SignalStoreFeatureResult>(condition: (store: StateSignals<Input['state']> & Input['props'] & Input['methods']) => boolean, featureIfTrue: SignalStoreFeature<NoInfer<Input>, Output>, featureIfFalse: SignalStoreFeature<NoInfer<Input>, NoInfer<Output>>): SignalStoreFeature<Input, Output>;
46
+ export declare const emptyFeature: SignalStoreFeature<import("@ngrx/signals").EmptyFeatureResult, {
47
+ state: {};
48
+ props: {};
49
+ methods: {};
50
+ }>;
@@ -0,0 +1,109 @@
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,15 +1,5 @@
1
- import {
2
- SignalStoreFeature,
3
- SignalStoreFeatureResult,
4
- StateSignals,
5
- } from '@ngrx/signals';
6
-
7
- type StoreForFactory<Input extends SignalStoreFeatureResult> = StateSignals<
8
- Input['state']
9
- > &
10
- Input['props'] &
11
- Input['methods'];
12
-
1
+ import { SignalStoreFeature, SignalStoreFeatureResult, StateSignals } from '@ngrx/signals';
2
+ type StoreForFactory<Input extends SignalStoreFeatureResult> = StateSignals<Input['state']> & Input['props'] & Input['methods'];
13
3
  /**
14
4
  * @deprecated Use `import { withFeature } from '@ngrx/signals'` instead, starting with `ngrx/signals` 19.1: https://ngrx.io/guide/signals/signal-store/custom-store-features#connecting-a-custom-feature-with-the-store
15
5
  *
@@ -34,23 +24,5 @@ type StoreForFactory<Input extends SignalStoreFeatureResult> = StateSignals<
34
24
  * ```
35
25
  * @param factoryFn
36
26
  */
37
- export function withFeatureFactory<
38
- Input extends SignalStoreFeatureResult,
39
- Output extends SignalStoreFeatureResult,
40
- >(
41
- factoryFn: (
42
- store: StoreForFactory<Input>,
43
- ) => SignalStoreFeature<Input, Output>,
44
- ): SignalStoreFeature<Input, Output> {
45
- return (store) => {
46
- const storeForFactory = {
47
- ...store['stateSignals'],
48
- ...store['props'],
49
- ...store['methods'],
50
- } as StoreForFactory<Input>;
51
-
52
- const feature = factoryFn(storeForFactory);
53
-
54
- return feature(store);
55
- };
56
- }
27
+ export declare function withFeatureFactory<Input extends SignalStoreFeatureResult, Output extends SignalStoreFeatureResult>(factoryFn: (store: StoreForFactory<Input>) => SignalStoreFeature<Input, Output>): SignalStoreFeature<Input, Output>;
28
+ export {};
@@ -0,0 +1,51 @@
1
+ import { Signal } from '@angular/core';
2
+ import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult, StateSignals, WritableStateSource } from '@ngrx/signals';
3
+ import { Mutation, MutationStatus } from './mutation/mutation';
4
+ type MutationsDictionary = Record<string, Mutation<any, any>>;
5
+ export type MethodsDictionary = Record<string, Function>;
6
+ type NamedMutationProps<T extends MutationsDictionary> = {
7
+ [Prop in keyof T as `${Prop & string}IsPending`]: Signal<boolean>;
8
+ } & {
9
+ [Prop in keyof T as `${Prop & string}Status`]: Signal<MutationStatus>;
10
+ } & {
11
+ [Prop in keyof T as `${Prop & string}Error`]: Signal<Error | undefined>;
12
+ };
13
+ type NamedMutationMethods<T extends MutationsDictionary> = {
14
+ [Prop in keyof T as `${Prop & string}`]: T[Prop] extends Mutation<infer P, infer R> ? Mutation<P, R> : never;
15
+ };
16
+ export type NamedMutationResult<T extends MutationsDictionary> = EmptyFeatureResult & {
17
+ props: NamedMutationProps<T>;
18
+ methods: NamedMutationMethods<T>;
19
+ };
20
+ /**
21
+ * Adds mutation methods to the store. Also, for each mutation method, several
22
+ * Signals are added informing about the mutation's status and errors.
23
+ *
24
+ * ```typescript
25
+ * export type Params = {
26
+ * value: number;
27
+ * };
28
+ *
29
+ * export const CounterStore = signalStore(
30
+ * { providedIn: 'root' },
31
+ * withState({ counter: 0 }),
32
+ * withMutations((store) => ({
33
+ * increment: rxMutation({ ... }),
34
+ * })),
35
+ * );
36
+ * ```
37
+ *
38
+ * There are several types of mutations. In the example shown, an {@link module:rx-mutation.rxMutation | rxMutation}
39
+ * leveraging RxJS is used
40
+ *
41
+ * For the defined `increment` mutation, several the following properties and
42
+ * methods are added to the store:
43
+ * - `increment(params: Params): Promise<MutationResult<number>>`: The mutation method.
44
+ * - `incrementIsPending`: A signal indicating if the mutation is in progress.
45
+ * - `incrementStatus`: A signal representing the current status of the mutation.
46
+ * - `incrementError`: A signal containing any error that occurred during the mutation.
47
+ *
48
+ * @param mutationsFactory
49
+ */
50
+ 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>>;
51
+ export {};
@@ -0,0 +1,98 @@
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[];
@@ -0,0 +1,147 @@
1
+ import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult, WritableStateSource } from '@ngrx/signals';
2
+ import { Observable } from 'rxjs';
3
+ /** Actions **/
4
+ type Payload = Record<string, unknown>;
5
+ type ActionFn<Type extends string = string, ActionPayload extends Payload = Payload> = ((payload: ActionPayload) => ActionPayload & {
6
+ type: Type;
7
+ }) & {
8
+ type: Type;
9
+ };
10
+ type ActionFns = Record<string, ActionFn>;
11
+ export type ActionsFnSpecs = Record<string, Payload>;
12
+ type ActionFnCreator<Spec extends ActionsFnSpecs> = {
13
+ [ActionName in keyof Spec]: (Record<never, never> extends Spec[ActionName] ? () => Spec[ActionName] & {
14
+ type: ActionName;
15
+ } : (payload: Spec[ActionName]) => Spec[ActionName] & {
16
+ type: ActionName;
17
+ }) & {
18
+ type: ActionName & string;
19
+ };
20
+ };
21
+ type ActionFnPayload<Action> = Action extends (payload: infer Payload) => void ? Payload : never;
22
+ type ActionFnsCreator<Spec extends ActionsFnSpecs> = Spec extends {
23
+ private: Record<string, Payload>;
24
+ public: Record<string, Payload>;
25
+ } ? ActionFnCreator<Spec['private']> & ActionFnCreator<Spec['public']> : ActionFnCreator<Spec>;
26
+ type PublicActionFns<Spec extends ActionsFnSpecs> = Spec extends {
27
+ public: Record<string, Payload>;
28
+ } ? ActionFnCreator<Spec['public']> : ActionFnCreator<Spec>;
29
+ export declare function payload<Type extends Payload>(): Type;
30
+ export declare const noPayload: {};
31
+ /** Reducer **/
32
+ type ReducerFunction<ReducerAction, State> = (state: State, action: ActionFnPayload<ReducerAction>) => void;
33
+ type ReducerFactory<StateActionFns extends ActionFns, State> = (actions: StateActionFns, on: <ReducerAction extends {
34
+ type: string;
35
+ }>(action: ReducerAction, reducerFn: ReducerFunction<ReducerAction, State>) => void) => void;
36
+ /**
37
+ * Creates a reducer function to separate the reducer logic into another file.
38
+ *
39
+ * ```typescript
40
+ * interface FlightState {
41
+ * flights: Flight[];
42
+ * effect1: boolean;
43
+ * effect2: boolean;
44
+ * }
45
+ *
46
+ * const initialState: FlightState = {
47
+ * flights: [],
48
+ * effect1: false,
49
+ * effect2: false,
50
+ * };
51
+ *
52
+ * const actions = {
53
+ * init: noPayload,
54
+ * updateEffect1: payload<{ value: boolean }>(),
55
+ * updateEffect2: payload<{ value: boolean }>(),
56
+ * };
57
+ *
58
+ * const reducer = createReducer<FlightState, typeof actions>((actions, on) => {
59
+ * on(actions.updateEffect1, (state, { value }) => {
60
+ * patchState(state, { effect1: value });
61
+ * });
62
+ *
63
+ * on(actions.updateEffect2, (state, { value }) => {
64
+ * patchState(state, { effect2: value });
65
+ * });
66
+ * });
67
+ *
68
+ * signalStore(
69
+ * withState(initialState),
70
+ * withRedux({
71
+ * actions,
72
+ * reducer,
73
+ * })
74
+ * );
75
+ * ```
76
+ * @param reducerFactory
77
+ */
78
+ export declare function createReducer<State extends object, Actions extends ActionsFnSpecs>(reducerFactory: ReducerFactory<ActionFnsCreator<Actions>, WritableStateSource<State>>): ReducerFactory<ActionFnsCreator<Actions>, WritableStateSource<State>>;
79
+ /** Effect **/
80
+ type EffectsFactory<StateActionFns extends ActionFns> = (actions: StateActionFns, create: <EffectAction extends {
81
+ type: string;
82
+ }>(action: EffectAction) => Observable<ActionFnPayload<EffectAction>>) => Record<string, Observable<unknown>>;
83
+ /**
84
+ * @deprecated Use NgRx's `@ngrx/signals/events` starting in 19.2
85
+ *
86
+ * Creates the effects function to separate the effects logic into another file.
87
+ *
88
+ * ```typescript
89
+ * interface FlightState {
90
+ * flights: Flight[];
91
+ * effect1: boolean;
92
+ * effect2: boolean;
93
+ * }
94
+ *
95
+ * const initialState: FlightState = {
96
+ * flights: [],
97
+ * effect1: false,
98
+ * effect2: false,
99
+ * };
100
+ *
101
+ * const actions = {
102
+ * init: noPayload,
103
+ * updateEffect1: payload<{ value: boolean }>(),
104
+ * updateEffect2: payload<{ value: boolean }>(),
105
+ * };
106
+ *
107
+ * const effects = createEffects(actions, (actions, create) => {
108
+ * return {
109
+ * init1$: create(actions.init).pipe(
110
+ * map(() => actions.updateEffect1({ value: true }))
111
+ * ),
112
+ * init2$: create(actions.init).pipe(
113
+ * map(() => actions.updateEffect2({ value: true }))
114
+ * ),
115
+ * };
116
+ * });
117
+ *
118
+ * signalStore(
119
+ * withState(initialState),
120
+ * withRedux({
121
+ * actions,
122
+ * effects,
123
+ * })
124
+ * );
125
+ * ```
126
+ * @param actions
127
+ * @param effectsFactory
128
+ */
129
+ export declare function createEffects<Actions extends ActionsFnSpecs>(actions: Actions, effectsFactory: EffectsFactory<ActionFnsCreator<Actions>>): EffectsFactory<ActionFnsCreator<Actions>>;
130
+ /**
131
+ * @param redux redux
132
+ *
133
+ * properties do not start with `with` since they are not extension functions on their own.
134
+ *
135
+ * no dependency to NgRx
136
+ *
137
+ * actions are passed to reducer and effects, but it is also possible to use other actions.
138
+ * effects provide forAction and do not return anything. that is important because effects should stay inaccessible
139
+ */
140
+ export declare function withRedux<Spec extends ActionsFnSpecs, Input extends SignalStoreFeatureResult, StateActionFns extends ActionFnsCreator<Spec> = ActionFnsCreator<Spec>, PublicStoreActionFns extends PublicActionFns<Spec> = PublicActionFns<Spec>>(redux: {
141
+ actions: Spec;
142
+ reducer: ReducerFactory<StateActionFns, WritableStateSource<Input['state']>>;
143
+ effects: EffectsFactory<StateActionFns>;
144
+ }): SignalStoreFeature<Input, EmptyFeatureResult & {
145
+ methods: PublicStoreActionFns;
146
+ }>;
147
+ export {};
@@ -0,0 +1,29 @@
1
+ import { StateSource } from '@ngrx/signals';
2
+ export type PublicMethods = {
3
+ resetState(): void;
4
+ };
5
+ /**
6
+ * Adds a `resetState` method to the store, which resets the state
7
+ * to the initial state.
8
+ *
9
+ * If you want to set a custom initial state, you can use {@link setResetState}.
10
+ */
11
+ export declare function withReset(): import("@ngrx/signals").SignalStoreFeature<import("@ngrx/signals").EmptyFeatureResult, {
12
+ state: {};
13
+ props: {
14
+ _resetState: {
15
+ value: {};
16
+ };
17
+ };
18
+ methods: {
19
+ resetState: () => void;
20
+ };
21
+ }>;
22
+ /**
23
+ * Sets the reset state of the store to the given state.
24
+ *
25
+ * Throws an error if the store is not configured with {@link withReset}.
26
+ * @param store the instance of a SignalStore
27
+ * @param state the state to set as the reset state
28
+ */
29
+ export declare function setResetState<State extends object>(store: StateSource<State>, state: State): void;
@@ -0,0 +1,31 @@
1
+ import { Signal } from '@angular/core';
2
+ import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult } from '@ngrx/signals';
3
+ export type StackItem = Record<string, unknown>;
4
+ export type NormalizedUndoRedoOptions = {
5
+ maxStackSize: number;
6
+ collections?: string[];
7
+ keys: string[];
8
+ skip: number;
9
+ };
10
+ export declare function getUndoRedoKeys(collections?: string[]): string[];
11
+ type NonNever<T> = T extends never ? never : T;
12
+ type ExtractEntityCollection<T> = T extends `${infer U}Entities` ? U : never;
13
+ type ExtractEntityCollections<Store extends SignalStoreFeatureResult> = NonNever<{
14
+ [K in keyof Store['props']]: ExtractEntityCollection<K>;
15
+ }[keyof Store['props']]>;
16
+ type OptionsForState<Store extends SignalStoreFeatureResult> = Partial<Omit<NormalizedUndoRedoOptions, 'collections' | 'keys'>> & {
17
+ collections?: ExtractEntityCollections<Store>[];
18
+ keys?: (keyof Store['state'])[];
19
+ };
20
+ export declare function withUndoRedo<Input extends EmptyFeatureResult>(options?: OptionsForState<Input>): SignalStoreFeature<Input, EmptyFeatureResult & {
21
+ props: {
22
+ canUndo: Signal<boolean>;
23
+ canRedo: Signal<boolean>;
24
+ };
25
+ methods: {
26
+ undo: () => void;
27
+ redo: () => void;
28
+ clearStack: () => void;
29
+ };
30
+ }>;
31
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-architects/ngrx-toolkit",
3
- "version": "19.4.0",
3
+ "version": "19.4.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "GitHub",
@@ -18,6 +18,23 @@
18
18
  "optional": true
19
19
  }
20
20
  },
21
- "dependencies": {},
22
- "sideEffects": false
23
- }
21
+ "dependencies": {
22
+ "tslib": "^2.3.0"
23
+ },
24
+ "sideEffects": false,
25
+ "module": "fesm2022/angular-architects-ngrx-toolkit.mjs",
26
+ "typings": "index.d.ts",
27
+ "exports": {
28
+ "./package.json": {
29
+ "default": "./package.json"
30
+ },
31
+ ".": {
32
+ "types": "./index.d.ts",
33
+ "default": "./fesm2022/angular-architects-ngrx-toolkit.mjs"
34
+ },
35
+ "./redux-connector": {
36
+ "types": "./redux-connector/index.d.ts",
37
+ "default": "./fesm2022/angular-architects-ngrx-toolkit-redux-connector.mjs"
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ export { createReduxState, mapAction, withActionMappers, } from './src/lib/create-redux';
2
+ export { reduxMethod } from './src/lib/rxjs-interop/redux-method';
@@ -0,0 +1,13 @@
1
+ import { ActionCreator, ActionType } from '@ngrx/store/src/models';
2
+ import { CreateReduxState, MapperTypes, Store } from './model';
3
+ export declare function mapAction<Creators extends readonly ActionCreator[]>(...args: [
4
+ ...creators: Creators,
5
+ storeMethod: (action: ActionType<Creators[number]>) => unknown
6
+ ]): MapperTypes<Creators>;
7
+ export declare function mapAction<Creators extends readonly ActionCreator[], T>(...args: [
8
+ ...creators: Creators,
9
+ storeMethod: (action: ActionType<Creators[number]>, resultMethod: (input: T) => unknown) => unknown,
10
+ resultMethod: (input: T) => unknown
11
+ ]): MapperTypes<Creators>;
12
+ export declare function withActionMappers(...mappers: MapperTypes<ActionCreator[]>[]): MapperTypes<ActionCreator[]>[];
13
+ export declare function createReduxState<StoreName extends string, STORE extends Store>(storeName: StoreName, signalStore: STORE, withActionMappers: (store: InstanceType<STORE>) => MapperTypes<ActionCreator[]>[]): CreateReduxState<StoreName, STORE>;
@@ -0,0 +1,40 @@
1
+ import { EnvironmentProviders, Signal, Type } from '@angular/core';
2
+ import { DeepSignal } from '@ngrx/signals/src/deep-signal';
3
+ import { SignalStoreFeatureResult, StateSignals } from '@ngrx/signals/src/signal-store-models';
4
+ import { Action, ActionCreator, ActionType, Prettify } from '@ngrx/store/src/models';
5
+ import { Observable, Unsubscribable } from 'rxjs';
6
+ export type IncludePropType<T, V, WithNevers = {
7
+ [K in keyof T]: Exclude<T[K], undefined> extends V ? T[K] extends Record<string, unknown> ? IncludePropType<T[K], V> : T[K] : never;
8
+ }> = Prettify<Pick<WithNevers, {
9
+ [K in keyof WithNevers]: WithNevers[K] extends never ? never : K extends string ? K : never;
10
+ }[keyof WithNevers]>>;
11
+ export type Store = Type<Record<string, unknown> & StateSignals<SignalStoreFeatureResult['state']>>;
12
+ export type CreateReduxState<StoreName extends string, STORE extends Store> = {
13
+ [K in StoreName as `provide${Capitalize<K>}Store`]: (connectReduxDevtools?: boolean) => EnvironmentProviders;
14
+ } & {
15
+ [K in StoreName as `inject${Capitalize<K>}Store`]: () => InjectableReduxSlice<STORE>;
16
+ };
17
+ export type Selectors<STORE extends Store> = IncludePropType<InstanceType<STORE>, Signal<unknown> | DeepSignal<unknown>>;
18
+ export type Dispatch = {
19
+ dispatch: (input: Action | Observable<Action> | Signal<Action>) => Unsubscribable;
20
+ };
21
+ export type InjectableReduxSlice<STORE extends Store> = Selectors<STORE> & Dispatch;
22
+ export type ExtractActionTypes<Creators extends readonly ActionCreator[]> = {
23
+ [Key in keyof Creators]: Creators[Key] extends ActionCreator<infer T> ? T : never;
24
+ };
25
+ export interface ActionMethod<T, V extends Action = Action> {
26
+ (action: V): T;
27
+ }
28
+ export interface StoreMethod<Creators extends readonly ActionCreator[], ResultState = unknown> {
29
+ (action: ActionType<Creators[number]>): ResultState;
30
+ }
31
+ export interface MapperTypes<Creators extends readonly ActionCreator[]> {
32
+ types: ExtractActionTypes<Creators>;
33
+ storeMethod: StoreMethod<Creators>;
34
+ resultMethod?: (...args: unknown[]) => unknown;
35
+ }
36
+ export type ServiceWithDecorator = {
37
+ ɵprov?: {
38
+ providedIn?: string;
39
+ };
40
+ };
@@ -0,0 +1,14 @@
1
+ import { Injector, Signal } from '@angular/core';
2
+ import { Observable } from 'rxjs';
3
+ type RxMethodInput<Input> = Input | Observable<Input> | Signal<Input>;
4
+ type RxMethodRef = {
5
+ destroy: () => void;
6
+ };
7
+ type RxMethod<Input, MethodInput = Input, MethodResult = unknown> = ((input: RxMethodInput<Input>, resultMethod: (input: MethodInput) => MethodResult) => RxMethodRef) & RxMethodRef;
8
+ export declare function reduxMethod<Input, MethodInput = Input>(generator: (source$: Observable<Input>) => Observable<MethodInput>, config?: {
9
+ injector?: Injector;
10
+ }): RxMethod<Input, MethodInput>;
11
+ export declare function reduxMethod<Input, MethodInput = Input, MethodResult = unknown>(generator: (source$: Observable<Input>) => Observable<MethodInput>, resultMethod: (input: MethodInput) => MethodResult, config?: {
12
+ injector?: Injector;
13
+ }): RxMethod<Input, MethodInput, MethodResult>;
14
+ export {};