@angular-architects/ngrx-toolkit 0.3.1 → 18.0.0-rc.2.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.
@@ -0,0 +1,130 @@
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 { SignalStoreFeature } from '@ngrx/signals';
10
+ import { EntityComputed, EntityState, NamedEntityComputed } from './shared/signal-store-models';
11
+ export type Page = {
12
+ label: string | number;
13
+ value: number;
14
+ };
15
+ export type NamedPaginationServiceState<E, Collection extends string> = {
16
+ [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Array<E>;
17
+ } & {
18
+ [K in Collection as `${Lowercase<K>}CurrentPage`]: number;
19
+ } & {
20
+ [K in Collection as `${Lowercase<K>}PageSize`]: number;
21
+ } & {
22
+ [K in Collection as `${Lowercase<K>}TotalCount`]: number;
23
+ } & {
24
+ [K in Collection as `${Lowercase<K>}PageCount`]: number;
25
+ } & {
26
+ [K in Collection as `${Lowercase<K>}PageNavigationArray`]: number;
27
+ } & {
28
+ [K in Collection as `${Lowercase<K>}PageNavigationArrayMax`]: number;
29
+ };
30
+ export type NamedPaginationServiceSignals<E, Collection extends string> = {
31
+ [K in Collection as `selectedPage${Capitalize<K>}Entities`]: Signal<E[]>;
32
+ } & {
33
+ [K in Collection as `${Lowercase<K>}CurrentPage`]: Signal<number>;
34
+ } & {
35
+ [K in Collection as `${Lowercase<K>}PageSize`]: Signal<number>;
36
+ } & {
37
+ [K in Collection as `${Lowercase<K>}TotalCount`]: Signal<number>;
38
+ } & {
39
+ [K in Collection as `${Lowercase<K>}PageCount`]: Signal<number>;
40
+ } & {
41
+ [K in Collection as `${Lowercase<K>}PageNavigationArray`]: Signal<Page[]>;
42
+ } & {
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>;
48
+ };
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> = {
63
+ selectedPageEntities: Array<E>;
64
+ currentPage: number;
65
+ pageSize: number;
66
+ totalCount: number;
67
+ pageCount: number;
68
+ pageNavigationArray: Page[];
69
+ pageNavigationArrayMax: number;
70
+ };
71
+ export type PaginationServiceSignals<E> = {
72
+ selectedPageEntities: Signal<E[]>;
73
+ currentPage: Signal<number>;
74
+ pageSize: Signal<number>;
75
+ totalCount: Signal<number>;
76
+ pageCount: Signal<number>;
77
+ pageNavigationArray: Signal<Page[]>;
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;
89
+ };
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;
93
+ collection: Collection;
94
+ }): SignalStoreFeature<{
95
+ state: {};
96
+ computed: NamedEntityComputed<E, Collection>;
97
+ methods: {};
98
+ }, {
99
+ state: NamedPaginationServiceState<E, Collection>;
100
+ computed: NamedPaginationServiceSignals<E, Collection>;
101
+ methods: NamedPaginationServiceMethods<Collection>;
102
+ }>;
103
+ export declare function withPagination<E>(): SignalStoreFeature<{
104
+ state: EntityState<E>;
105
+ computed: EntityComputed<E>;
106
+ methods: {};
107
+ }, {
108
+ state: PaginationServiceState<E>;
109
+ computed: PaginationServiceSignals<E>;
110
+ methods: PaginationServiceMethods;
111
+ }>;
112
+ export declare function gotoPage<E, Collection extends string>(page: number, options?: {
113
+ collection: Collection;
114
+ }): Partial<SetPaginationState<E, Collection>>;
115
+ export declare function setPageSize<E, Collection extends string>(pageSize: number, options?: {
116
+ collection: Collection;
117
+ }): Partial<SetPaginationState<E, Collection>>;
118
+ export declare function nextPage<E, Collection extends string>(options?: {
119
+ collection: Collection;
120
+ }): Partial<SetPaginationState<E, Collection>>;
121
+ export declare function previousPage<E, Collection extends string>(options?: {
122
+ collection: Collection;
123
+ }): Partial<SetPaginationState<E, Collection>>;
124
+ export declare function firstPage<E, Collection extends string>(options?: {
125
+ collection: Collection;
126
+ }): Partial<SetPaginationState<E, Collection>>;
127
+ export declare function setMaxPageNavigationArrayItems<E, Collection extends string>(maxPageNavigationArrayItems: number, options?: {
128
+ collection: Collection;
129
+ }): Partial<SetPaginationState<E, Collection>>;
130
+ export declare function createPageArray(currentPage: number, itemsPerPage: number, totalItems: number, paginationRange: number): Page[];
@@ -1,7 +1,6 @@
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 { SignalStoreFeature, StateSignal } from '@ngrx/signals';
3
+ import { EmptyFeatureResult, SignalStoreFeatureResult } from './shared/signal-store-models';
5
4
  /** Actions **/
6
5
  type Payload = Record<string, unknown>;
7
6
  type ActionFn<Type extends string = string, ActionPayload extends Payload = Payload> = ((payload: ActionPayload) => ActionPayload & {
@@ -1,11 +1,9 @@
1
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
- };
2
+ import { Empty } from './shared/empty';
3
+ import { SignalStoreFeatureResult } from './shared/signal-store-models';
6
4
  type WithStorageSyncFeatureResult = {
7
- state: Emtpy;
8
- signals: Emtpy;
5
+ state: Empty;
6
+ computed: Empty;
9
7
  methods: {
10
8
  clearStorage(): void;
11
9
  readFromStorage(): void;
@@ -53,6 +51,6 @@ export type SyncConfig<State> = {
53
51
  *
54
52
  * Only works on browser platform.
55
53
  */
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>;
54
+ export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureResult>(key: string): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
55
+ export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureResult>(config: SyncConfig<Input['state']>): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
58
56
  export {};
@@ -1,9 +1,8 @@
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 } from '@ngrx/signals';
2
+ import { EntityId, EntityMap, 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;
@@ -22,12 +21,12 @@ export declare function withUndoRedo<Collection extends string>(options?: {
22
21
  maxStackSize?: number;
23
22
  collections: Collection[];
24
23
  }): SignalStoreFeature<{
25
- state: Emtpy;
26
- signals: NamedEntitySignals<Entity, Collection>;
27
- methods: Emtpy;
24
+ state: {};
25
+ computed: NamedEntityComputed<Entity, Collection>;
26
+ methods: {};
28
27
  }, {
29
- state: Emtpy;
30
- signals: {
28
+ state: {};
29
+ computed: {
31
30
  canUndo: Signal<boolean>;
32
31
  canRedo: Signal<boolean>;
33
32
  };
@@ -40,11 +39,11 @@ export declare function withUndoRedo(options?: {
40
39
  maxStackSize?: number;
41
40
  }): SignalStoreFeature<{
42
41
  state: EntityState<Entity>;
43
- signals: EntitySignals<Entity>;
44
- methods: Emtpy;
42
+ computed: EntityComputed<Entity>;
43
+ methods: {};
45
44
  }, {
46
- state: Emtpy;
47
- signals: {
45
+ state: {};
46
+ computed: {
48
47
  canUndo: Signal<boolean>;
49
48
  canRedo: Signal<boolean>;
50
49
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@angular-architects/ngrx-toolkit",
3
- "version": "0.3.1",
3
+ "version": "18.0.0-rc.2.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.0.0"
10
+ "@ngrx/signals": "18.0.0-rc.2"
11
11
  },
12
12
  "dependencies": {
13
13
  "tslib": "^2.3.0"