ngx-essentials-schematics 0.0.9 → 0.0.11
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/package.json +1 -1
- package/src/ngrx/store/files/store/__name@dasherize__.model.ts.template +4 -6
- package/src/ngrx/store/files/store/__name@dasherize__.service.ts.template +1 -1
- package/src/ngrx/store/files/store/__name@dasherize__.store.ts.template +57 -56
- package/src/ngrx/store/index.js +2 -2
- package/src/ngrx/store/schema.d.ts +4 -4
- package/src/ngrx/store/schema.json +5 -5
package/package.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { FormGroupType } from '../common/form/form.model';
|
|
2
2
|
|
|
3
3
|
export interface Add<%= classify(name) %> {
|
|
4
|
-
nombre: string;
|
|
5
|
-
descripcion?: string;
|
|
6
4
|
}
|
|
7
5
|
|
|
8
6
|
export type Add<%= classify(name) %>Form = FormGroupType<Add<%= classify(name) %>>;
|
|
9
7
|
|
|
10
8
|
export interface <%= classify(name) %>Dto {
|
|
11
|
-
|
|
12
|
-
nombre: string;
|
|
13
|
-
descripcion?: string;
|
|
9
|
+
<%= pk %>: number;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
export type Update<%= classify(name) %> = Partial<<%= classify(name) %>Dto> & Pick<<%= classify(name) %>Dto, '
|
|
12
|
+
export type Update<%= classify(name) %> = Partial<<%= classify(name) %>Dto> & Pick<<%= classify(name) %>Dto, '<%= pk %>'>;
|
|
13
|
+
|
|
14
|
+
export interface <%= classify(name) %>Request{}
|
|
@@ -25,46 +25,47 @@ const initialStatus: EntityStatus = {
|
|
|
25
25
|
loading: false,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const
|
|
29
|
-
collection: '<%= camelize(name) %>',
|
|
28
|
+
const config = entityConfig({
|
|
30
29
|
entity: type<<%= classify(name) %>Dto>(),
|
|
31
|
-
selectId: (entity) => entity
|
|
30
|
+
selectId: (entity) => entity.<%= pk %>,
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
export const <%= classify(name) %>Store = signalStore(
|
|
35
34
|
{ providedIn: 'root' },
|
|
36
|
-
withEntities(
|
|
35
|
+
withEntities(config),
|
|
37
36
|
withState({
|
|
38
|
-
|
|
37
|
+
_status: initialStatus,
|
|
39
38
|
}),
|
|
40
|
-
withComputed(({ <%= camelize(name) %>EntityMap,
|
|
39
|
+
withComputed(({ <%= camelize(name) %>EntityMap, _status }) => ({
|
|
40
|
+
<%= camelize(pluralize(name)) %>: computed(() => Object.values(<%= camelize(name) %>EntityMap())),
|
|
41
41
|
<%= camelize(name) %>Seleccionado: computed(() => {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
42
|
+
const <%= pk %> = _status().idSelected;
|
|
43
|
+
return <%= pk %> ? <%= camelize(name) %>EntityMap()[<%= pk %>] : null;
|
|
44
44
|
}),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
error: computed(() => _status().error),
|
|
46
|
+
loaded: computed(() => _status().loaded),
|
|
47
|
+
loading: computed(() => _status().loading),
|
|
48
|
+
loadingRemove: computed(
|
|
49
|
+
() => (<%= pk %>?: number) =>
|
|
50
|
+
(<%= pk %> ? _status().idsDeleting?.includes(<%= pk %>) : _status().deleteLoading) || false
|
|
50
51
|
),
|
|
51
|
-
loadingUpdate
|
|
52
|
-
() => (
|
|
53
|
-
(
|
|
52
|
+
loadingUpdate: computed(
|
|
53
|
+
() => (<%= pk %>?: number) =>
|
|
54
|
+
(<%= pk %> ? _status().idsUpdating?.includes(<%= pk %>) : _status().updateLoading) || false
|
|
54
55
|
),
|
|
55
56
|
})),
|
|
56
57
|
withMethods((store, <%= camelize(name) %>Service = inject(<%= classify(name) %>Service)) => ({
|
|
57
58
|
add<%= classify(name) %>: rxMethod<Add<%= classify(name) %>>(
|
|
58
59
|
pipe(
|
|
59
60
|
tap(() => {
|
|
60
|
-
patchState(store, {
|
|
61
|
+
patchState(store, { _status: { ...store._status(), addLoading: true } });
|
|
61
62
|
}),
|
|
62
63
|
switchMap((entity) => {
|
|
63
64
|
return <%= camelize(name) %>Service.add<%= classify(name) %>$(entity).pipe(
|
|
64
|
-
tap((
|
|
65
|
-
patchState(store, addEntity({ ...entity,
|
|
66
|
-
|
|
67
|
-
...store
|
|
65
|
+
tap((<%= pk %>) => {
|
|
66
|
+
patchState(store, addEntity({ ...entity, <%= pk %> }, config), {
|
|
67
|
+
_status: {
|
|
68
|
+
...store._status(),
|
|
68
69
|
addLoading: false,
|
|
69
70
|
error: null,
|
|
70
71
|
},
|
|
@@ -72,8 +73,8 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
72
73
|
}),
|
|
73
74
|
catchError(() => {
|
|
74
75
|
patchState(store, {
|
|
75
|
-
|
|
76
|
-
...store
|
|
76
|
+
_status: {
|
|
77
|
+
...store._status(),
|
|
77
78
|
addLoading: false,
|
|
78
79
|
error: new Error('Error al agregar <%= name %>'),
|
|
79
80
|
},
|
|
@@ -87,14 +88,14 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
87
88
|
load<%= classify(pluralize(name)) %>: rxMethod<void>(
|
|
88
89
|
pipe(
|
|
89
90
|
tap(() => {
|
|
90
|
-
patchState(store, {
|
|
91
|
+
patchState(store, { _status: { ...store._status(), loading: true } });
|
|
91
92
|
}),
|
|
92
93
|
switchMap(() => {
|
|
93
94
|
return <%= camelize(name) %>Service.get<%= classify(pluralize(name)) %>$().pipe(
|
|
94
95
|
tap((response) => {
|
|
95
|
-
patchState(store, setAllEntities(response,
|
|
96
|
-
|
|
97
|
-
...store
|
|
96
|
+
patchState(store, setAllEntities(response, config), {
|
|
97
|
+
_status: {
|
|
98
|
+
...store._status(),
|
|
98
99
|
error: null,
|
|
99
100
|
loaded: true,
|
|
100
101
|
loading: false,
|
|
@@ -103,8 +104,8 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
103
104
|
}),
|
|
104
105
|
catchError(() => {
|
|
105
106
|
patchState(store, {
|
|
106
|
-
|
|
107
|
-
...store
|
|
107
|
+
_status: {
|
|
108
|
+
...store._status(),
|
|
108
109
|
error: new Error('Error al cargar <%= pluralize(name) %>'),
|
|
109
110
|
loading: false,
|
|
110
111
|
},
|
|
@@ -117,26 +118,26 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
117
118
|
),
|
|
118
119
|
remove<%= classify(name) %>: rxMethod<number>(
|
|
119
120
|
pipe(
|
|
120
|
-
tap((
|
|
121
|
+
tap((<%= pk %>) => {
|
|
121
122
|
patchState(store, {
|
|
122
|
-
|
|
123
|
-
...store
|
|
123
|
+
_status: {
|
|
124
|
+
...store._status(),
|
|
124
125
|
deleteLoading: true,
|
|
125
|
-
idsDeleting: [...(store
|
|
126
|
+
idsDeleting: [...(store._status().idsDeleting || []), <%= pk %>],
|
|
126
127
|
},
|
|
127
128
|
});
|
|
128
129
|
}),
|
|
129
|
-
switchMap((
|
|
130
|
-
return <%= camelize(name) %>Service.delete<%= classify(name) %>$(
|
|
130
|
+
switchMap((<%= pk %>) => {
|
|
131
|
+
return <%= camelize(name) %>Service.delete<%= classify(name) %>$(<%= pk %>).pipe(
|
|
131
132
|
tap((success) => {
|
|
132
133
|
if (success) {
|
|
133
|
-
const idsDeleting = store
|
|
134
|
-
patchState(store, removeEntity(
|
|
135
|
-
|
|
136
|
-
...store
|
|
134
|
+
const idsDeleting = store._status().idsDeleting || [];
|
|
135
|
+
patchState(store, removeEntity(<%= pk %>), {
|
|
136
|
+
_status: {
|
|
137
|
+
...store._status(),
|
|
137
138
|
deleteLoading: false,
|
|
138
139
|
error: null,
|
|
139
|
-
idsDeleting: idsDeleting.filter((
|
|
140
|
+
idsDeleting: idsDeleting.filter((idDeleting) => idDeleting !== <%= pk %>),
|
|
140
141
|
},
|
|
141
142
|
});
|
|
142
143
|
} else {
|
|
@@ -144,13 +145,13 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
144
145
|
}
|
|
145
146
|
}),
|
|
146
147
|
catchError(() => {
|
|
147
|
-
const idsDeleting = store
|
|
148
|
+
const idsDeleting = store._status().idsDeleting || [];
|
|
148
149
|
patchState(store, {
|
|
149
|
-
|
|
150
|
-
...store
|
|
150
|
+
_status: {
|
|
151
|
+
...store._status(),
|
|
151
152
|
deleteLoading: false,
|
|
152
153
|
error: new Error('Error al eliminar <%= name %>'),
|
|
153
|
-
idsDeleting: idsDeleting.filter((
|
|
154
|
+
idsDeleting: idsDeleting.filter((idDeleting) => idDeleting !== <%= pk %>),
|
|
154
155
|
},
|
|
155
156
|
});
|
|
156
157
|
return of(false);
|
|
@@ -163,9 +164,9 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
163
164
|
pipe(
|
|
164
165
|
tap((entity) => {
|
|
165
166
|
patchState(store, {
|
|
166
|
-
|
|
167
|
-
...store
|
|
168
|
-
idsUpdating: [...(store
|
|
167
|
+
_status: {
|
|
168
|
+
...store._status(),
|
|
169
|
+
idsUpdating: [...(store._status().idsUpdating || []), entity.<%= pk %>],
|
|
169
170
|
updateLoading: true,
|
|
170
171
|
},
|
|
171
172
|
});
|
|
@@ -174,12 +175,12 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
174
175
|
return <%= camelize(name) %>Service.update<%= classify(name) %>$(entity).pipe(
|
|
175
176
|
tap((success) => {
|
|
176
177
|
if (success) {
|
|
177
|
-
const idsUpdating = store
|
|
178
|
-
patchState(store, updateEntity({ changes: entity, id: entity
|
|
179
|
-
|
|
180
|
-
...store
|
|
178
|
+
const idsUpdating = store._status().idsUpdating || [];
|
|
179
|
+
patchState(store, updateEntity({ changes: entity, id: entity.<%= pk %> }, config), {
|
|
180
|
+
_status: {
|
|
181
|
+
...store._status(),
|
|
181
182
|
error: null,
|
|
182
|
-
idsUpdating: idsUpdating.filter((
|
|
183
|
+
idsUpdating: idsUpdating.filter((idUpdating) => idUpdating !== entity.<%= pk %>),
|
|
183
184
|
updateLoading: false,
|
|
184
185
|
},
|
|
185
186
|
});
|
|
@@ -188,12 +189,12 @@ export const <%= classify(name) %>Store = signalStore(
|
|
|
188
189
|
}
|
|
189
190
|
}),
|
|
190
191
|
catchError(() => {
|
|
191
|
-
const idsUpdating = store
|
|
192
|
+
const idsUpdating = store._status().idsUpdating || [];
|
|
192
193
|
patchState(store, {
|
|
193
|
-
|
|
194
|
-
...store
|
|
194
|
+
_status: {
|
|
195
|
+
...store._status(),
|
|
195
196
|
error: new Error('Error al actualizar <%= name %>'),
|
|
196
|
-
idsUpdating: idsUpdating.filter((
|
|
197
|
+
idsUpdating: idsUpdating.filter((idUpdating) => idUpdating !== entity.<%= pk %>),
|
|
197
198
|
updateLoading: false,
|
|
198
199
|
},
|
|
199
200
|
});
|
package/src/ngrx/store/index.js
CHANGED
|
@@ -61,7 +61,7 @@ function signalStore(options) {
|
|
|
61
61
|
const indexPath = (0, core_1.join)(movePath, "index.ts");
|
|
62
62
|
const nameDash = core_1.strings.dasherize(options.name);
|
|
63
63
|
const entityName = core_1.strings.classify(options.name);
|
|
64
|
-
const entityHeader =
|
|
64
|
+
const entityHeader = `/* ${entityName.toUpperCase()} */`;
|
|
65
65
|
const exportBlock = [
|
|
66
66
|
entityHeader,
|
|
67
67
|
`export * from './${nameDash}/${nameDash}.model';`,
|
|
@@ -99,7 +99,7 @@ function signalStore(options) {
|
|
|
99
99
|
default:
|
|
100
100
|
return pluralizeEn(word);
|
|
101
101
|
}
|
|
102
|
-
} })),
|
|
102
|
+
}, pk: options.pk })),
|
|
103
103
|
(0, schematics_1.move)((0, core_1.join)(movePath, core_1.strings.dasherize(options.name))),
|
|
104
104
|
]);
|
|
105
105
|
const commonEntityRule = mergeFilesSmart("./files/entity", (0, core_1.join)(movePath, "common/entity"), options);
|
|
@@ -10,12 +10,12 @@ export interface SchemaOptions {
|
|
|
10
10
|
path: string;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* El idioma para la pluralización ('en' para inglés, 'es' para español).
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
language: "en" | "es";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Indica el nombre de la clave primaria (por defecto 'id').
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
pk: string;
|
|
21
21
|
}
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"description": "Ruta de destino.",
|
|
16
16
|
"default": "src/app/core"
|
|
17
17
|
},
|
|
18
|
-
"generateExtras": {
|
|
19
|
-
"type": "boolean",
|
|
20
|
-
"description": "¿Generar archivos adicionales para formularios y entidades?",
|
|
21
|
-
"default": false
|
|
22
|
-
},
|
|
23
18
|
"language": {
|
|
24
19
|
"type": "string",
|
|
25
20
|
"description": "Idioma para la pluralización ('en' para inglés, 'es' para español).",
|
|
26
21
|
"enum": ["en", "es"],
|
|
27
22
|
"default": "en"
|
|
23
|
+
},
|
|
24
|
+
"pk": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Nombre de la clave primaria.",
|
|
27
|
+
"default": "id"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"required": ["name"]
|