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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-essentials-schematics",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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
- cod: number;
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, 'cod'>;
12
+ export type Update<%= classify(name) %> = Partial<<%= classify(name) %>Dto> & Pick<<%= classify(name) %>Dto, '<%= pk %>'>;
13
+
14
+ export interface <%= classify(name) %>Request{}
@@ -15,7 +15,7 @@ export class <%= classify(name) %>Service {
15
15
  return of(0);
16
16
  }
17
17
 
18
- delete<%= classify(name) %>$(cod: number): Observable<boolean> {
18
+ delete<%= classify(name) %>$(<%= pk %>: number): Observable<boolean> {
19
19
  return of(true);
20
20
  }
21
21
 
@@ -25,46 +25,47 @@ const initialStatus: EntityStatus = {
25
25
  loading: false,
26
26
  };
27
27
 
28
- const <%= camelize(name) %>EntitiesConfig = entityConfig({
29
- collection: '<%= camelize(name) %>',
28
+ const config = entityConfig({
30
29
  entity: type<<%= classify(name) %>Dto>(),
31
- selectId: (entity) => entity.cod,
30
+ selectId: (entity) => entity.<%= pk %>,
32
31
  });
33
32
 
34
33
  export const <%= classify(name) %>Store = signalStore(
35
34
  { providedIn: 'root' },
36
- withEntities(<%= camelize(name) %>EntitiesConfig),
35
+ withEntities(config),
37
36
  withState({
38
- <%= camelize(name) %>Status: initialStatus,
37
+ _status: initialStatus,
39
38
  }),
40
- withComputed(({ <%= camelize(name) %>EntityMap, <%= camelize(name) %>Status }) => ({
39
+ withComputed(({ <%= camelize(name) %>EntityMap, _status }) => ({
40
+ <%= camelize(pluralize(name)) %>: computed(() => Object.values(<%= camelize(name) %>EntityMap())),
41
41
  <%= camelize(name) %>Seleccionado: computed(() => {
42
- const id = <%= camelize(name) %>Status().idSelected;
43
- return id ? <%= camelize(name) %>EntityMap()[id] : null;
42
+ const <%= pk %> = _status().idSelected;
43
+ return <%= pk %> ? <%= camelize(name) %>EntityMap()[<%= pk %>] : null;
44
44
  }),
45
- <%= camelize(pluralize(name)) %>: computed(() => Object.values(<%= camelize(name) %>EntityMap())),
46
- loading<%= classify(pluralize(name)) %>: computed(() => <%= camelize(name) %>Status().loading),
47
- loadingRemove<%= classify(name) %>: computed(
48
- () => (cod?: number) =>
49
- (cod ? <%= camelize(name) %>Status().idsDeleting?.includes(cod) : <%= camelize(name) %>Status().deleteLoading) || false
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<%= classify(name) %>: computed(
52
- () => (cod?: number) =>
53
- (cod ? <%= camelize(name) %>Status().idsUpdating?.includes(cod) : <%= camelize(name) %>Status().updateLoading) || false
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, { <%= camelize(name) %>Status: { ...store.<%= camelize(name) %>Status(), addLoading: true } });
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((cod) => {
65
- patchState(store, addEntity({ ...entity, cod }, <%= camelize(name) %>EntitiesConfig), {
66
- <%= camelize(name) %>Status: {
67
- ...store.<%= camelize(name) %>Status(),
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
- <%= camelize(name) %>Status: {
76
- ...store.<%= camelize(name) %>Status(),
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, { <%= camelize(name) %>Status: { ...store.<%= camelize(name) %>Status(), loading: true } });
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, <%= camelize(name) %>EntitiesConfig), {
96
- <%= camelize(name) %>Status: {
97
- ...store.<%= camelize(name) %>Status(),
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
- <%= camelize(name) %>Status: {
107
- ...store.<%= camelize(name) %>Status(),
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((cod) => {
121
+ tap((<%= pk %>) => {
121
122
  patchState(store, {
122
- <%= camelize(name) %>Status: {
123
- ...store.<%= camelize(name) %>Status(),
123
+ _status: {
124
+ ...store._status(),
124
125
  deleteLoading: true,
125
- idsDeleting: [...(store.<%= camelize(name) %>Status().idsDeleting || []), cod],
126
+ idsDeleting: [...(store._status().idsDeleting || []), <%= pk %>],
126
127
  },
127
128
  });
128
129
  }),
129
- switchMap((cod) => {
130
- return <%= camelize(name) %>Service.delete<%= classify(name) %>$(cod).pipe(
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.<%= camelize(name) %>Status().idsDeleting || [];
134
- patchState(store, removeEntity(cod, <%= camelize(name) %>EntitiesConfig), {
135
- <%= camelize(name) %>Status: {
136
- ...store.<%= camelize(name) %>Status(),
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((id) => id !== cod),
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.<%= camelize(name) %>Status().idsDeleting || [];
148
+ const idsDeleting = store._status().idsDeleting || [];
148
149
  patchState(store, {
149
- <%= camelize(name) %>Status: {
150
- ...store.<%= camelize(name) %>Status(),
150
+ _status: {
151
+ ...store._status(),
151
152
  deleteLoading: false,
152
153
  error: new Error('Error al eliminar <%= name %>'),
153
- idsDeleting: idsDeleting.filter((id) => id !== cod),
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
- <%= camelize(name) %>Status: {
167
- ...store.<%= camelize(name) %>Status(),
168
- idsUpdating: [...(store.<%= camelize(name) %>Status().idsUpdating || []), entity.cod],
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.<%= camelize(name) %>Status().idsUpdating || [];
178
- patchState(store, updateEntity({ changes: entity, id: entity.cod }, <%= camelize(name) %>EntitiesConfig), {
179
- <%= camelize(name) %>Status: {
180
- ...store.<%= camelize(name) %>Status(),
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((id) => id !== entity.cod),
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.<%= camelize(name) %>Status().idsUpdating || [];
192
+ const idsUpdating = store._status().idsUpdating || [];
192
193
  patchState(store, {
193
- <%= camelize(name) %>Status: {
194
- ...store.<%= camelize(name) %>Status(),
194
+ _status: {
195
+ ...store._status(),
195
196
  error: new Error('Error al actualizar <%= name %>'),
196
- idsUpdating: idsUpdating.filter((id) => id !== entity.cod),
197
+ idsUpdating: idsUpdating.filter((idUpdating) => idUpdating !== entity.<%= pk %>),
197
198
  updateLoading: false,
198
199
  },
199
200
  });
@@ -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 = `/** ${entityName.toUpperCase()} **/`;
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
- * Indica si se deben generar archivos adicionales para formularios y entidades.
13
+ * El idioma para la pluralización ('en' para inglés, 'es' para español).
14
14
  */
15
- generateExtras?: boolean;
15
+ language: "en" | "es";
16
16
 
17
17
  /**
18
- * El idioma para la pluralización ('en' para inglés, 'es' para español).
18
+ * Indica el nombre de la clave primaria (por defecto 'id').
19
19
  */
20
- language?: "en" | "es";
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"]