@angular-architects/ngrx-toolkit 0.0.2 → 0.0.4
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 +144 -0
- package/esm2022/index.mjs +4 -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 +161 -0
- package/esm2022/lib/with-undo-redo.mjs +93 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +307 -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 +115 -0
- package/lib/with-undo-redo.d.ts +55 -0
- package/package.json +2 -2
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
updateAll(entity: E[]): Promise<E[]>;
|
|
17
|
+
delete(entity: E): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare function capitalize(str: string): string;
|
|
20
|
+
export declare function getDataServiceKeys(options: {
|
|
21
|
+
collection?: string;
|
|
22
|
+
}): {
|
|
23
|
+
filterKey: string;
|
|
24
|
+
selectedIdsKey: string;
|
|
25
|
+
selectedEntitiesKey: string;
|
|
26
|
+
updateFilterKey: string;
|
|
27
|
+
updateSelectedKey: string;
|
|
28
|
+
loadKey: string;
|
|
29
|
+
entitiesKey: string;
|
|
30
|
+
entityMapKey: string;
|
|
31
|
+
idsKey: string;
|
|
32
|
+
currentKey: string;
|
|
33
|
+
loadByIdKey: string;
|
|
34
|
+
setCurrentKey: string;
|
|
35
|
+
createKey: string;
|
|
36
|
+
updateKey: string;
|
|
37
|
+
updateAllKey: string;
|
|
38
|
+
deleteKey: string;
|
|
39
|
+
};
|
|
40
|
+
export type NamedDataServiceState<E extends Entity, F extends Filter, Collection extends string> = {
|
|
41
|
+
[K in Collection as `${K}Filter`]: F;
|
|
42
|
+
} & {
|
|
43
|
+
[K in Collection as `selected${Capitalize<K>}Ids`]: Record<EntityId, boolean>;
|
|
44
|
+
} & {
|
|
45
|
+
[K in Collection as `current${Capitalize<K>}`]: E;
|
|
46
|
+
};
|
|
47
|
+
export type DataServiceState<E extends Entity, F extends Filter> = {
|
|
48
|
+
filter: F;
|
|
49
|
+
selectedIds: Record<EntityId, boolean>;
|
|
50
|
+
current: E;
|
|
51
|
+
};
|
|
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> = {
|
|
56
|
+
selectedEntities: Signal<E[]>;
|
|
57
|
+
};
|
|
58
|
+
export type NamedDataServiceMethods<E extends Entity, F extends Filter, Collection extends string> = {
|
|
59
|
+
[K in Collection as `update${Capitalize<K>}Filter`]: (filter: F) => void;
|
|
60
|
+
} & {
|
|
61
|
+
[K in Collection as `updateSelected${Capitalize<K>}Entities`]: (id: EntityId, selected: boolean) => void;
|
|
62
|
+
} & {
|
|
63
|
+
[K in Collection as `load${Capitalize<K>}Entities`]: () => Promise<void>;
|
|
64
|
+
} & {
|
|
65
|
+
[K in Collection as `setCurrent${Capitalize<K>}`]: (entity: E) => void;
|
|
66
|
+
} & {
|
|
67
|
+
[K in Collection as `load${Capitalize<K>}ById`]: (id: EntityId) => Promise<void>;
|
|
68
|
+
} & {
|
|
69
|
+
[K in Collection as `create${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
70
|
+
} & {
|
|
71
|
+
[K in Collection as `update${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
72
|
+
} & {
|
|
73
|
+
[K in Collection as `updateAll${Capitalize<K>}`]: (entity: E[]) => Promise<void>;
|
|
74
|
+
} & {
|
|
75
|
+
[K in Collection as `delete${Capitalize<K>}`]: (entity: E) => Promise<void>;
|
|
76
|
+
};
|
|
77
|
+
export type DataServiceMethods<E extends Entity, F extends Filter> = {
|
|
78
|
+
updateFilter: (filter: F) => void;
|
|
79
|
+
updateSelected: (id: EntityId, selected: boolean) => void;
|
|
80
|
+
load: () => Promise<void>;
|
|
81
|
+
setCurrent(entity: E): void;
|
|
82
|
+
loadById(id: EntityId): Promise<void>;
|
|
83
|
+
create(entity: E): Promise<void>;
|
|
84
|
+
update(entity: E): Promise<void>;
|
|
85
|
+
updateAll(entities: E[]): Promise<void>;
|
|
86
|
+
delete(entity: E): Promise<void>;
|
|
87
|
+
};
|
|
88
|
+
export type Empty = Record<string, never>;
|
|
89
|
+
export declare function withDataService<E extends Entity, F extends Filter, Collection extends string>(options: {
|
|
90
|
+
dataServiceType: ProviderToken<DataService<E, F>>;
|
|
91
|
+
filter: F;
|
|
92
|
+
collection: Collection;
|
|
93
|
+
}): SignalStoreFeature<{
|
|
94
|
+
state: Emtpy;
|
|
95
|
+
signals: NamedEntitySignals<E, Collection>;
|
|
96
|
+
methods: Emtpy;
|
|
97
|
+
}, {
|
|
98
|
+
state: NamedDataServiceState<E, F, Collection>;
|
|
99
|
+
signals: NamedDataServiceSignals<E, Collection>;
|
|
100
|
+
methods: NamedDataServiceMethods<E, F, Collection>;
|
|
101
|
+
}>;
|
|
102
|
+
export declare function withDataService<E extends Entity, F extends Filter>(options: {
|
|
103
|
+
dataServiceType: ProviderToken<DataService<E, F>>;
|
|
104
|
+
filter: F;
|
|
105
|
+
}): SignalStoreFeature<{
|
|
106
|
+
state: {
|
|
107
|
+
callState: CallState;
|
|
108
|
+
} & EntityState<E>;
|
|
109
|
+
signals: Emtpy;
|
|
110
|
+
methods: Emtpy;
|
|
111
|
+
}, {
|
|
112
|
+
state: DataServiceState<E, F>;
|
|
113
|
+
signals: DataServiceSignals<E>;
|
|
114
|
+
methods: DataServiceMethods<E, F>;
|
|
115
|
+
}>;
|
|
@@ -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.4",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^17.0.0",
|
|
6
6
|
"@angular/core": "^17.0.0",
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
"default": "./fesm2022/angular-architects-ngrx-toolkit.mjs"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
}
|
|
26
|
+
}
|