@angular-architects/ngrx-toolkit 0.4.0 → 18.0.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 (33) hide show
  1. package/README.md +47 -2
  2. package/esm2022/index.mjs +2 -2
  3. package/esm2022/lib/assertions/assertions.mjs +1 -1
  4. package/esm2022/lib/redux-connector/create-redux.mjs +1 -1
  5. package/esm2022/lib/redux-connector/model.mjs +1 -1
  6. package/esm2022/lib/redux-connector/rxjs-interop/redux-method.mjs +1 -1
  7. package/esm2022/lib/redux-connector/signal-redux-store.mjs +4 -4
  8. package/esm2022/lib/shared/prettify.mjs +2 -0
  9. package/esm2022/lib/shared/signal-store-models.mjs +2 -0
  10. package/esm2022/lib/with-call-state.mjs +6 -4
  11. package/esm2022/lib/with-data-service.mjs +73 -32
  12. package/esm2022/lib/with-devtools.mjs +5 -5
  13. package/esm2022/lib/with-pagination.mjs +70 -13
  14. package/esm2022/lib/with-redux.mjs +1 -1
  15. package/esm2022/lib/with-storage-sync.mjs +1 -1
  16. package/esm2022/lib/with-undo-redo.mjs +25 -11
  17. package/fesm2022/angular-architects-ngrx-toolkit.mjs +274 -160
  18. package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -1
  19. package/index.d.ts +1 -1
  20. package/lib/redux-connector/model.d.ts +6 -7
  21. package/lib/redux-connector/signal-redux-store.d.ts +2 -2
  22. package/lib/shared/prettify.d.ts +3 -0
  23. package/lib/shared/signal-store-models.d.ts +26 -0
  24. package/lib/with-call-state.d.ts +5 -16
  25. package/lib/with-data-service.d.ts +14 -20
  26. package/lib/with-devtools.d.ts +5 -10
  27. package/lib/with-pagination.d.ts +50 -27
  28. package/lib/with-redux.d.ts +2 -4
  29. package/lib/with-storage-sync.d.ts +4 -10
  30. package/lib/with-undo-redo.d.ts +13 -27
  31. package/package.json +2 -2
  32. package/esm2022/lib/shared/empty.mjs +0 -2
  33. package/lib/shared/empty.d.ts +0 -1
@@ -1,9 +1,8 @@
1
- import { ProviderToken, Signal } from "@angular/core";
2
- import { SignalStoreFeature } from "@ngrx/signals";
3
- import { CallState } from "./with-call-state";
4
- import { EntityId } from "@ngrx/signals/entities";
5
- import { EntityState, NamedEntitySignals } from "@ngrx/signals/entities/src/models";
6
- import { Emtpy } from "./shared/empty";
1
+ import { ProviderToken, Signal } from '@angular/core';
2
+ import { SignalStoreFeature, EmptyFeatureResult } from '@ngrx/signals';
3
+ import { CallState } from './with-call-state';
4
+ import { EntityId } from '@ngrx/signals/entities';
5
+ import { EntityState, NamedEntityComputed } from './shared/signal-store-models';
7
6
  export type Filter = Record<string, unknown>;
8
7
  export type Entity = {
9
8
  id: EntityId;
@@ -49,12 +48,12 @@ export type DataServiceState<E extends Entity, F extends Filter> = {
49
48
  selectedIds: Record<EntityId, boolean>;
50
49
  current: E;
51
50
  };
52
- export type NamedDataServiceSignals<E extends Entity, Collection extends string> = {
53
- [K in Collection as `selected${Capitalize<K>}Entities`]: Signal<E[]>;
54
- };
55
- export type DataServiceSignals<E extends Entity> = {
51
+ export type DataServiceComputed<E extends Entity> = {
56
52
  selectedEntities: Signal<E[]>;
57
53
  };
54
+ export type NamedDataServiceComputed<E extends Entity, Collection extends string> = {
55
+ [K in Collection as `selected${Capitalize<K>}Entities`]: Signal<E[]>;
56
+ };
58
57
  export type NamedDataServiceMethods<E extends Entity, F extends Filter, Collection extends string> = {
59
58
  [K in Collection as `update${Capitalize<K>}Filter`]: (filter: F) => void;
60
59
  } & {
@@ -85,31 +84,26 @@ export type DataServiceMethods<E extends Entity, F extends Filter> = {
85
84
  updateAll(entities: E[]): Promise<void>;
86
85
  delete(entity: E): Promise<void>;
87
86
  };
88
- export type Empty = Record<string, never>;
89
87
  export declare function withDataService<E extends Entity, F extends Filter, Collection extends string>(options: {
90
88
  dataServiceType: ProviderToken<DataService<E, F>>;
91
89
  filter: F;
92
90
  collection: Collection;
93
- }): SignalStoreFeature<{
94
- state: Emtpy;
95
- signals: NamedEntitySignals<E, Collection>;
96
- methods: Emtpy;
91
+ }): SignalStoreFeature<EmptyFeatureResult & {
92
+ computed: NamedEntityComputed<E, Collection>;
97
93
  }, {
98
94
  state: NamedDataServiceState<E, F, Collection>;
99
- signals: NamedDataServiceSignals<E, Collection>;
95
+ computed: NamedDataServiceComputed<E, Collection>;
100
96
  methods: NamedDataServiceMethods<E, F, Collection>;
101
97
  }>;
102
98
  export declare function withDataService<E extends Entity, F extends Filter>(options: {
103
99
  dataServiceType: ProviderToken<DataService<E, F>>;
104
100
  filter: F;
105
- }): SignalStoreFeature<{
101
+ }): SignalStoreFeature<EmptyFeatureResult & {
106
102
  state: {
107
103
  callState: CallState;
108
104
  } & EntityState<E>;
109
- signals: Emtpy;
110
- methods: Emtpy;
111
105
  }, {
112
106
  state: DataServiceState<E, F>;
113
- signals: DataServiceSignals<E>;
107
+ computed: DataServiceComputed<E>;
114
108
  methods: DataServiceMethods<E, F>;
115
109
  }>;
@@ -1,5 +1,5 @@
1
- import { patchState as originalPatchState, SignalStoreFeature } from '@ngrx/signals';
2
- import { SignalStoreFeatureResult } from '@ngrx/signals/src/signal-store-models';
1
+ import { EmptyFeatureResult, PartialStateUpdater, patchState as originalPatchState, SignalStoreFeature, WritableStateSource } from '@ngrx/signals';
2
+ import { Prettify } from './shared/prettify';
3
3
  declare global {
4
4
  interface Window {
5
5
  __REDUX_DEVTOOLS_EXTENSION__: {
@@ -11,11 +11,6 @@ declare global {
11
11
  } | undefined;
12
12
  }
13
13
  }
14
- type EmptyFeatureResult = {
15
- state: {};
16
- signals: {};
17
- methods: {};
18
- };
19
14
  export type Action = {
20
15
  type: string;
21
16
  };
@@ -26,7 +21,7 @@ export declare function reset(): void;
26
21
  /**
27
22
  * @param name store's name as it should appear in the DevTools
28
23
  */
29
- export declare function withDevtools<Input extends SignalStoreFeatureResult>(name: string): SignalStoreFeature<Input, EmptyFeatureResult>;
24
+ export declare function withDevtools<Input extends EmptyFeatureResult>(name: string): SignalStoreFeature<Input, EmptyFeatureResult>;
30
25
  type PatchFn = typeof originalPatchState extends (arg1: infer First, ...args: infer Rest) => infer Returner ? (state: First, action: string, ...rest: Rest) => Returner : never;
31
26
  /**
32
27
  * @deprecated Has been renamed to `updateState`
@@ -35,9 +30,9 @@ export declare const patchState: PatchFn;
35
30
  /**
36
31
  * Wrapper of `patchState` for DevTools integration. Next to updating the state,
37
32
  * it also sends the action to the DevTools.
38
- * @param state state of Signal Store
33
+ * @param stateSource state of Signal Store
39
34
  * @param action name of action how it will show in DevTools
40
35
  * @param updaters updater functions or objects
41
36
  */
42
- export declare const updateState: PatchFn;
37
+ export declare function updateState<State extends object>(stateSource: WritableStateSource<State>, action: string, ...updaters: Array<Partial<Prettify<State>> | PartialStateUpdater<Prettify<State>>>): void;
43
38
  export {};
@@ -6,15 +6,13 @@
6
6
  * This feature implements the local pagination.
7
7
  */
8
8
  import { Signal } from '@angular/core';
9
- import { SignalStoreFeature } from '@ngrx/signals';
10
- import { Emtpy } from './shared/empty';
11
- import { EntitySignals, EntityState, NamedEntitySignals } from '@ngrx/signals/entities/src/models';
12
- import { Entity } from './with-data-service';
9
+ import { SignalStoreFeature, EmptyFeatureResult } from '@ngrx/signals';
10
+ import { EntityComputed, EntityState, NamedEntityComputed } from './shared/signal-store-models';
13
11
  export type Page = {
14
12
  label: string | number;
15
13
  value: number;
16
14
  };
17
- export type NamedPaginationServiceState<E extends Entity, Collection extends string> = {
15
+ export type NamedPaginationServiceState<E, Collection extends string> = {
18
16
  [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Array<E>;
19
17
  } & {
20
18
  [K in Collection as `${Lowercase<K>}CurrentPage`]: number;
@@ -29,7 +27,7 @@ export type NamedPaginationServiceState<E extends Entity, Collection extends str
29
27
  } & {
30
28
  [K in Collection as `${Lowercase<K>}PageNavigationArrayMax`]: number;
31
29
  };
32
- export type NamedPaginationServiceSignals<E extends Entity, Collection extends string> = {
30
+ export type NamedPaginationServiceSignals<E, Collection extends string> = {
33
31
  [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Signal<E[]>;
34
32
  } & {
35
33
  [K in Collection as `${Lowercase<K>}CurrentPage`]: Signal<number>;
@@ -43,8 +41,25 @@ export type NamedPaginationServiceSignals<E extends Entity, Collection extends s
43
41
  [K in Collection as `${Lowercase<K>}PageNavigationArray`]: Signal<Page[]>;
44
42
  } & {
45
43
  [K in Collection as `${Lowercase<K>}PageNavigationArrayMax`]: Signal<number>;
44
+ } & {
45
+ [K in Collection as `hasNext${Capitalize<K>}Page`]: Signal<boolean>;
46
+ } & {
47
+ [K in Collection as `hasPrevious${Capitalize<K>}Page`]: Signal<boolean>;
46
48
  };
47
- export type PaginationServiceState<E extends Entity> = {
49
+ export type NamedPaginationServiceMethods<Collection extends string> = {
50
+ [K in Collection as `set${Capitalize<K>}PageSize`]: (size: number) => void;
51
+ } & {
52
+ [K in Collection as `next${Capitalize<K>}Page`]: () => void;
53
+ } & {
54
+ [K in Collection as `previous${Capitalize<K>}Page`]: () => void;
55
+ } & {
56
+ [K in Collection as `last${Capitalize<K>}Page`]: () => void;
57
+ } & {
58
+ [K in Collection as `first${Capitalize<K>}Page`]: () => void;
59
+ } & {
60
+ [K in Collection as `goto${Capitalize<K>}Page`]: (page: number) => void;
61
+ };
62
+ export type PaginationServiceState<E> = {
48
63
  selectedPageEntities: Array<E>;
49
64
  currentPage: number;
50
65
  pageSize: number;
@@ -53,7 +68,7 @@ export type PaginationServiceState<E extends Entity> = {
53
68
  pageNavigationArray: Page[];
54
69
  pageNavigationArrayMax: number;
55
70
  };
56
- export type PaginationServiceSignals<E extends Entity> = {
71
+ export type PaginationServiceSignals<E> = {
57
72
  selectedPageEntities: Signal<E[]>;
58
73
  currentPage: Signal<number>;
59
74
  pageSize: Signal<number>;
@@ -61,44 +76,52 @@ export type PaginationServiceSignals<E extends Entity> = {
61
76
  pageCount: Signal<number>;
62
77
  pageNavigationArray: Signal<Page[]>;
63
78
  pageNavigationArrayMax: Signal<number>;
79
+ hasNextPage: Signal<boolean>;
80
+ hasPreviousPage: Signal<boolean>;
81
+ };
82
+ export type PaginationServiceMethods = {
83
+ setPageSize: (size: number) => void;
84
+ nextPageKey: () => void;
85
+ previousPage: () => void;
86
+ lastPage: () => void;
87
+ firstPage: () => void;
88
+ gotoPage: (page: number) => void;
64
89
  };
65
- export type SetPaginationState<E extends Entity, Collection extends string | undefined> = Collection extends string ? NamedPaginationServiceState<E, Collection> : PaginationServiceState<E>;
66
- export declare function withPagination<E extends Entity, Collection extends string>(options: {
90
+ export type SetPaginationState<E, Collection extends string | undefined> = Collection extends string ? NamedPaginationServiceState<E, Collection> : PaginationServiceState<E>;
91
+ export declare function withPagination<E, Collection extends string>(options: {
92
+ entity: E;
67
93
  collection: Collection;
68
- }): SignalStoreFeature<{
69
- state: Emtpy;
70
- signals: NamedEntitySignals<E, Collection>;
71
- methods: Emtpy;
94
+ }): SignalStoreFeature<EmptyFeatureResult & {
95
+ computed: NamedEntityComputed<E, Collection>;
72
96
  }, {
73
97
  state: NamedPaginationServiceState<E, Collection>;
74
- signals: NamedPaginationServiceSignals<E, Collection>;
75
- methods: Emtpy;
98
+ computed: NamedPaginationServiceSignals<E, Collection>;
99
+ methods: NamedPaginationServiceMethods<Collection>;
76
100
  }>;
77
- export declare function withPagination<E extends Entity>(): SignalStoreFeature<{
101
+ export declare function withPagination<E>(): SignalStoreFeature<EmptyFeatureResult & {
78
102
  state: EntityState<E>;
79
- signals: EntitySignals<E>;
80
- methods: Emtpy;
103
+ computed: EntityComputed<E>;
81
104
  }, {
82
105
  state: PaginationServiceState<E>;
83
- signals: PaginationServiceSignals<E>;
84
- methods: Emtpy;
106
+ computed: PaginationServiceSignals<E>;
107
+ methods: PaginationServiceMethods;
85
108
  }>;
86
- export declare function gotoPage<E extends Entity, Collection extends string>(page: number, options?: {
109
+ export declare function gotoPage<E, Collection extends string>(page: number, options?: {
87
110
  collection: Collection;
88
111
  }): Partial<SetPaginationState<E, Collection>>;
89
- export declare function setPageSize<E extends Entity, Collection extends string>(pageSize: number, options?: {
112
+ export declare function setPageSize<E, Collection extends string>(pageSize: number, options?: {
90
113
  collection: Collection;
91
114
  }): Partial<SetPaginationState<E, Collection>>;
92
- export declare function nextPage<E extends Entity, Collection extends string>(options?: {
115
+ export declare function nextPage<E, Collection extends string>(options?: {
93
116
  collection: Collection;
94
117
  }): Partial<SetPaginationState<E, Collection>>;
95
- export declare function previousPage<E extends Entity, Collection extends string>(options?: {
118
+ export declare function previousPage<E, Collection extends string>(options?: {
96
119
  collection: Collection;
97
120
  }): Partial<SetPaginationState<E, Collection>>;
98
- export declare function firstPage<E extends Entity, Collection extends string>(options?: {
121
+ export declare function firstPage<E, Collection extends string>(options?: {
99
122
  collection: Collection;
100
123
  }): Partial<SetPaginationState<E, Collection>>;
101
- export declare function setMaxPageNavigationArrayItems<E extends Entity, Collection extends string>(maxPageNavigationArrayItems: number, options?: {
124
+ export declare function setMaxPageNavigationArrayItems<E, Collection extends string>(maxPageNavigationArrayItems: number, options?: {
102
125
  collection: Collection;
103
126
  }): Partial<SetPaginationState<E, Collection>>;
104
127
  export declare function createPageArray(currentPage: number, itemsPerPage: number, totalItems: number, paginationRange: number): Page[];
@@ -1,7 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
- import { SignalStoreFeature } from '@ngrx/signals';
3
- import { EmptyFeatureResult, SignalStoreFeatureResult } from '@ngrx/signals/src/signal-store-models';
4
- import { StateSignal } from '@ngrx/signals/src/state-signal';
2
+ import { EmptyFeatureResult, SignalStoreFeature, SignalStoreFeatureResult, WritableStateSource } from '@ngrx/signals';
5
3
  /** Actions **/
6
4
  type Payload = Record<string, unknown>;
7
5
  type ActionFn<Type extends string = string, ActionPayload extends Payload = Payload> = ((payload: ActionPayload) => ActionPayload & {
@@ -51,7 +49,7 @@ type EffectsFactory<StateActionFns extends ActionFns> = (actions: StateActionFns
51
49
  */
52
50
  export declare function withRedux<Spec extends ActionsFnSpecs, Input extends SignalStoreFeatureResult, StateActionFns extends ActionFnsCreator<Spec> = ActionFnsCreator<Spec>, PublicStoreActionFns extends PublicActionFns<Spec> = PublicActionFns<Spec>>(redux: {
53
51
  actions: Spec;
54
- reducer: ReducerFactory<StateActionFns, StateSignal<Input['state']>>;
52
+ reducer: ReducerFactory<StateActionFns, WritableStateSource<Input['state']>>;
55
53
  effects: EffectsFactory<StateActionFns>;
56
54
  }): SignalStoreFeature<Input, EmptyFeatureResult & {
57
55
  methods: PublicStoreActionFns;
@@ -1,11 +1,5 @@
1
- import { SignalStoreFeature } from '@ngrx/signals';
2
- import { Emtpy } from './shared/empty';
3
- type SignalStoreFeatureInput<State> = Pick<Parameters<SignalStoreFeature>[0], 'signals' | 'methods'> & {
4
- state: State;
5
- };
6
- type WithStorageSyncFeatureResult = {
7
- state: Emtpy;
8
- signals: Emtpy;
1
+ import { SignalStoreFeature, SignalStoreFeatureResult, EmptyFeatureResult } from '@ngrx/signals';
2
+ type WithStorageSyncFeatureResult = EmptyFeatureResult & {
9
3
  methods: {
10
4
  clearStorage(): void;
11
5
  readFromStorage(): void;
@@ -53,6 +47,6 @@ export type SyncConfig<State> = {
53
47
  *
54
48
  * Only works on browser platform.
55
49
  */
56
- export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureInput<State>>(key: string): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
57
- export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureInput<State>>(config: SyncConfig<Input['state']>): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
50
+ export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureResult>(key: string): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
51
+ export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureResult>(config: SyncConfig<Input['state']>): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
58
52
  export {};
@@ -1,33 +1,21 @@
1
- import { SignalStoreFeature } from "@ngrx/signals";
2
- import { EntityId, EntityMap, EntityState } from "@ngrx/signals/entities";
3
- import { Signal } from "@angular/core";
4
- import { EntitySignals, NamedEntitySignals } from "@ngrx/signals/entities/src/models";
5
- import { Entity } from "./with-data-service";
6
- import { Emtpy } from "./shared/empty";
1
+ import { SignalStoreFeature, EmptyFeatureResult } from '@ngrx/signals';
2
+ import { EntityState } from '@ngrx/signals/entities';
3
+ import { Signal } from '@angular/core';
4
+ import { Entity } from './with-data-service';
5
+ import { EntityComputed, NamedEntityComputed } from './shared/signal-store-models';
7
6
  export type StackItem = Record<string, unknown>;
8
7
  export type NormalizedUndoRedoOptions = {
9
8
  maxStackSize: number;
10
9
  collections?: string[];
11
10
  };
12
- export type NamedUndoRedoState<Collection extends string> = {
13
- [K in Collection as `${K}EntityMap`]: EntityMap<Entity>;
14
- } & {
15
- [K in Collection as `${K}Ids`]: EntityId[];
16
- };
17
- export type NamedUndoRedoSignals<Collection extends string> = {
18
- [K in Collection as `${K}Entities`]: Signal<Entity[]>;
19
- };
20
11
  export declare function getUndoRedoKeys(collections?: string[]): string[];
21
12
  export declare function withUndoRedo<Collection extends string>(options?: {
22
13
  maxStackSize?: number;
23
14
  collections: Collection[];
24
- }): SignalStoreFeature<{
25
- state: Emtpy;
26
- signals: NamedEntitySignals<Entity, Collection>;
27
- methods: Emtpy;
28
- }, {
29
- state: Emtpy;
30
- signals: {
15
+ }): SignalStoreFeature<EmptyFeatureResult & {
16
+ computed: NamedEntityComputed<Entity, Collection>;
17
+ }, EmptyFeatureResult & {
18
+ computed: {
31
19
  canUndo: Signal<boolean>;
32
20
  canRedo: Signal<boolean>;
33
21
  };
@@ -38,13 +26,11 @@ export declare function withUndoRedo<Collection extends string>(options?: {
38
26
  }>;
39
27
  export declare function withUndoRedo(options?: {
40
28
  maxStackSize?: number;
41
- }): SignalStoreFeature<{
29
+ }): SignalStoreFeature<EmptyFeatureResult & {
42
30
  state: EntityState<Entity>;
43
- signals: EntitySignals<Entity>;
44
- methods: Emtpy;
45
- }, {
46
- state: Emtpy;
47
- signals: {
31
+ computed: EntityComputed<Entity>;
32
+ }, EmptyFeatureResult & {
33
+ computed: {
48
34
  canUndo: Signal<boolean>;
49
35
  canRedo: Signal<boolean>;
50
36
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@angular-architects/ngrx-toolkit",
3
- "version": "0.4.0",
3
+ "version": "18.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "GitHub",
7
7
  "url": "https://github.com/angular-architects/ngrx-toolkit"
8
8
  },
9
9
  "peerDependencies": {
10
- "@ngrx/signals": "^17.2.0"
10
+ "@ngrx/signals": "18.0.0"
11
11
  },
12
12
  "dependencies": {
13
13
  "tslib": "^2.3.0"
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1wdHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9saWJzL25ncngtdG9vbGtpdC9zcmMvbGliL3NoYXJlZC9lbXB0eS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIiwic291cmNlc0NvbnRlbnQiOlsiLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIEB0eXBlc2NyaXB0LWVzbGludC9iYW4tdHlwZXNcbmV4cG9ydCB0eXBlIEVtdHB5ID0ge307Il19
@@ -1 +0,0 @@
1
- export type Emtpy = {};