@angular-architects/ngrx-toolkit 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -7
- package/esm2022/index.mjs +4 -1
- package/esm2022/lib/assertions/assertions.mjs +1 -1
- package/esm2022/lib/shared/empty.mjs +2 -0
- package/esm2022/lib/with-call-state.mjs +58 -0
- package/esm2022/lib/with-data-service.mjs +147 -0
- package/esm2022/lib/with-devtools.mjs +1 -1
- package/esm2022/lib/with-redux.mjs +1 -1
- package/esm2022/lib/with-undo-redo.mjs +93 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +293 -3
- package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -1
- package/index.d.ts +3 -0
- package/lib/shared/empty.d.ts +1 -0
- package/lib/with-call-state.d.ts +55 -0
- package/lib/with-data-service.d.ts +110 -0
- package/lib/with-undo-redo.d.ts +55 -0
- package/package.json +2 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { SignalStoreFeature } from '@ngrx/signals';
|
|
3
|
+
import { Emtpy } from './shared/empty';
|
|
4
|
+
export type CallState = 'init' | 'loading' | 'loaded' | {
|
|
5
|
+
error: string;
|
|
6
|
+
};
|
|
7
|
+
export type NamedCallStateSlice<Collection extends string> = {
|
|
8
|
+
[K in Collection as `${K}CallState`]: CallState;
|
|
9
|
+
};
|
|
10
|
+
export type CallStateSlice = {
|
|
11
|
+
callState: CallState;
|
|
12
|
+
};
|
|
13
|
+
export type NamedCallStateSignals<Prop extends string> = {
|
|
14
|
+
[K in Prop as `${K}Loading`]: Signal<boolean>;
|
|
15
|
+
} & {
|
|
16
|
+
[K in Prop as `${K}Loaded`]: Signal<boolean>;
|
|
17
|
+
} & {
|
|
18
|
+
[K in Prop as `${K}Error`]: Signal<string | null>;
|
|
19
|
+
};
|
|
20
|
+
export type CallStateSignals = {
|
|
21
|
+
loading: Signal<boolean>;
|
|
22
|
+
loaded: Signal<boolean>;
|
|
23
|
+
error: Signal<string | null>;
|
|
24
|
+
};
|
|
25
|
+
export declare function getCallStateKeys(config?: {
|
|
26
|
+
collection?: string;
|
|
27
|
+
}): {
|
|
28
|
+
callStateKey: string;
|
|
29
|
+
loadingKey: string;
|
|
30
|
+
loadedKey: string;
|
|
31
|
+
errorKey: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function withCallState<Collection extends string>(config: {
|
|
34
|
+
collection: Collection;
|
|
35
|
+
}): SignalStoreFeature<{
|
|
36
|
+
state: Emtpy;
|
|
37
|
+
signals: Emtpy;
|
|
38
|
+
methods: Emtpy;
|
|
39
|
+
}, {
|
|
40
|
+
state: NamedCallStateSlice<Collection>;
|
|
41
|
+
signals: NamedCallStateSignals<Collection>;
|
|
42
|
+
methods: Emtpy;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function withCallState(): SignalStoreFeature<{
|
|
45
|
+
state: Emtpy;
|
|
46
|
+
signals: Emtpy;
|
|
47
|
+
methods: Emtpy;
|
|
48
|
+
}, {
|
|
49
|
+
state: CallStateSlice;
|
|
50
|
+
signals: CallStateSignals;
|
|
51
|
+
methods: Emtpy;
|
|
52
|
+
}>;
|
|
53
|
+
export declare function setLoading<Prop extends string>(prop?: Prop): NamedCallStateSlice<Prop> | CallStateSlice;
|
|
54
|
+
export declare function setLoaded<Prop extends string>(prop?: Prop): NamedCallStateSlice<Prop> | CallStateSlice;
|
|
55
|
+
export declare function setError<Prop extends string>(error: unknown, prop?: Prop): NamedCallStateSlice<Prop> | CallStateSlice;
|
|
@@ -0,0 +1,110 @@
|
|
|
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";
|
|
7
|
+
export type Filter = Record<string, unknown>;
|
|
8
|
+
export type Entity = {
|
|
9
|
+
id: EntityId;
|
|
10
|
+
};
|
|
11
|
+
export interface DataService<E extends Entity, F extends Filter> {
|
|
12
|
+
load(filter: F): Promise<E[]>;
|
|
13
|
+
loadById(id: EntityId): Promise<E>;
|
|
14
|
+
create(entity: E): Promise<E>;
|
|
15
|
+
update(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
|
+
deleteKey: string;
|
|
37
|
+
};
|
|
38
|
+
export type NamedDataServiceState<E extends Entity, F extends Filter, Collection extends string> = {
|
|
39
|
+
[K in Collection as `${K}Filter`]: F;
|
|
40
|
+
} & {
|
|
41
|
+
[K in Collection as `selected${Capitalize<K>}Ids`]: Record<EntityId, boolean>;
|
|
42
|
+
} & {
|
|
43
|
+
[K in Collection as `current${Capitalize<K>}`]: E;
|
|
44
|
+
};
|
|
45
|
+
export type DataServiceState<E extends Entity, F extends Filter> = {
|
|
46
|
+
filter: F;
|
|
47
|
+
selectedIds: Record<EntityId, boolean>;
|
|
48
|
+
current: E;
|
|
49
|
+
};
|
|
50
|
+
export type NamedDataServiceSignals<E extends Entity, Collection extends string> = {
|
|
51
|
+
[K in Collection as `selected${Capitalize<K>}Entities`]: Signal<E[]>;
|
|
52
|
+
};
|
|
53
|
+
export type DataServiceSignals<E extends Entity> = {
|
|
54
|
+
selectedEntities: Signal<E[]>;
|
|
55
|
+
};
|
|
56
|
+
export type NamedDataServiceMethods<E extends Entity, F extends Filter, Collection extends string> = {
|
|
57
|
+
[K in Collection as `update${Capitalize<K>}Filter`]: (filter: F) => void;
|
|
58
|
+
} & {
|
|
59
|
+
[K in Collection as `updateSelected${Capitalize<K>}Entities`]: (id: EntityId, selected: boolean) => void;
|
|
60
|
+
} & {
|
|
61
|
+
[K in Collection as `load${Capitalize<K>}Entities`]: () => Promise<void>;
|
|
62
|
+
} & {
|
|
63
|
+
[K in Collection as `setCurrent${Capitalize<K>}`]: (entity: E) => void;
|
|
64
|
+
} & {
|
|
65
|
+
[K in Collection as `load${Capitalize<K>}ById`]: (id: EntityId) => Promise<void>;
|
|
66
|
+
} & {
|
|
67
|
+
[K in Collection as `create${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
68
|
+
} & {
|
|
69
|
+
[K in Collection as `update${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
70
|
+
} & {
|
|
71
|
+
[K in Collection as `delete${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
export type DataServiceMethods<E extends Entity, F extends Filter> = {
|
|
74
|
+
updateFilter: (filter: F) => void;
|
|
75
|
+
updateSelected: (id: EntityId, selected: boolean) => void;
|
|
76
|
+
load: () => Promise<void>;
|
|
77
|
+
setCurrent(entity: E): void;
|
|
78
|
+
loadById(id: EntityId): Promise<void>;
|
|
79
|
+
create(entity: E): Promise<void>;
|
|
80
|
+
update(entity: E): Promise<void>;
|
|
81
|
+
delete(entity: E): Promise<void>;
|
|
82
|
+
};
|
|
83
|
+
export type Empty = Record<string, never>;
|
|
84
|
+
export declare function withDataService<E extends Entity, F extends Filter, Collection extends string>(options: {
|
|
85
|
+
dataServiceType: ProviderToken<DataService<E, F>>;
|
|
86
|
+
filter: F;
|
|
87
|
+
collection: Collection;
|
|
88
|
+
}): SignalStoreFeature<{
|
|
89
|
+
state: Emtpy;
|
|
90
|
+
signals: NamedEntitySignals<E, Collection>;
|
|
91
|
+
methods: Emtpy;
|
|
92
|
+
}, {
|
|
93
|
+
state: NamedDataServiceState<E, F, Collection>;
|
|
94
|
+
signals: NamedDataServiceSignals<E, Collection>;
|
|
95
|
+
methods: NamedDataServiceMethods<E, F, Collection>;
|
|
96
|
+
}>;
|
|
97
|
+
export declare function withDataService<E extends Entity, F extends Filter>(options: {
|
|
98
|
+
dataServiceType: ProviderToken<DataService<E, F>>;
|
|
99
|
+
filter: F;
|
|
100
|
+
}): SignalStoreFeature<{
|
|
101
|
+
state: {
|
|
102
|
+
callState: CallState;
|
|
103
|
+
} & EntityState<E>;
|
|
104
|
+
signals: Emtpy;
|
|
105
|
+
methods: Emtpy;
|
|
106
|
+
}, {
|
|
107
|
+
state: DataServiceState<E, F>;
|
|
108
|
+
signals: DataServiceSignals<E>;
|
|
109
|
+
methods: DataServiceMethods<E, F>;
|
|
110
|
+
}>;
|
|
@@ -0,0 +1,55 @@
|
|
|
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";
|
|
7
|
+
export type StackItem = Record<string, unknown>;
|
|
8
|
+
export type NormalizedUndoRedoOptions = {
|
|
9
|
+
maxStackSize: number;
|
|
10
|
+
collections?: string[];
|
|
11
|
+
};
|
|
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
|
+
export declare function getUndoRedoKeys(collections?: string[]): string[];
|
|
21
|
+
export declare function withUndoRedo<Collection extends string>(options?: {
|
|
22
|
+
maxStackSize?: number;
|
|
23
|
+
collections: Collection[];
|
|
24
|
+
}): SignalStoreFeature<{
|
|
25
|
+
state: Emtpy;
|
|
26
|
+
signals: NamedEntitySignals<Entity, Collection>;
|
|
27
|
+
methods: Emtpy;
|
|
28
|
+
}, {
|
|
29
|
+
state: Emtpy;
|
|
30
|
+
signals: {
|
|
31
|
+
canUndo: Signal<boolean>;
|
|
32
|
+
canRedo: Signal<boolean>;
|
|
33
|
+
};
|
|
34
|
+
methods: {
|
|
35
|
+
undo: () => void;
|
|
36
|
+
redo: () => void;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
export declare function withUndoRedo(options?: {
|
|
40
|
+
maxStackSize?: number;
|
|
41
|
+
}): SignalStoreFeature<{
|
|
42
|
+
state: EntityState<Entity>;
|
|
43
|
+
signals: EntitySignals<Entity>;
|
|
44
|
+
methods: Emtpy;
|
|
45
|
+
}, {
|
|
46
|
+
state: Emtpy;
|
|
47
|
+
signals: {
|
|
48
|
+
canUndo: Signal<boolean>;
|
|
49
|
+
canRedo: Signal<boolean>;
|
|
50
|
+
};
|
|
51
|
+
methods: {
|
|
52
|
+
undo: () => void;
|
|
53
|
+
redo: () => void;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-architects/ngrx-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^17.0.0",
|
|
6
6
|
"@angular/core": "^17.0.0",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"tslib": "^2.3.0"
|
|
11
11
|
},
|
|
12
|
-
"private": false,
|
|
13
12
|
"sideEffects": false,
|
|
14
13
|
"module": "fesm2022/angular-architects-ngrx-toolkit.mjs",
|
|
15
14
|
"typings": "index.d.ts",
|
|
@@ -24,4 +23,4 @@
|
|
|
24
23
|
"default": "./fesm2022/angular-architects-ngrx-toolkit.mjs"
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
|
-
}
|
|
26
|
+
}
|