@tech4good/angular-schematics 0.0.2 → 13.1.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.
- package/README.md +46 -46
- package/package.json +27 -27
- package/src/collection.json +25 -25
- package/src/component/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +7 -0
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +30 -0
- package/src/component/index.d.ts +2 -2
- package/src/component/index.js +93 -102
- package/src/component/index.js.map +1 -1
- package/src/component/index_spec.d.ts +1 -1
- package/src/component/index_spec.js +22 -22
- package/src/component/schema.json +47 -29
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +27 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +47 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +20 -0
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +13 -0
- package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +5 -0
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +81 -0
- package/src/container/index.d.ts +2 -2
- package/src/container/index.js +115 -282
- package/src/container/index.js.map +1 -1
- package/src/container/index_spec.d.ts +1 -1
- package/src/container/index_spec.js +22 -22
- package/src/container/schema.json +47 -24
- package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +270 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +131 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +7 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +13 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +51 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +50 -0
- package/src/entity/index.d.ts +2 -2
- package/src/entity/index.js +123 -524
- package/src/entity/index.js.map +1 -1
- package/src/entity/index_spec.d.ts +1 -1
- package/src/entity/index_spec.js +22 -22
- package/src/entity/schema.json +42 -19
- package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +13 -0
- package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +13 -0
- package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +24 -0
- package/src/module/index.d.ts +2 -2
- package/src/module/index.js +96 -87
- package/src/module/index.js.map +1 -1
- package/src/module/index_spec.d.ts +1 -1
- package/src/module/index_spec.js +22 -22
- package/src/module/schema.json +38 -19
- package/src/shared/camelcase-formatter.d.ts +1 -1
- package/src/shared/camelcase-formatter.js +18 -18
- package/src/shared/statements-adder.d.ts +8 -5
- package/src/shared/statements-adder.js +52 -31
- package/src/shared/statements-adder.js.map +1 -1
- package/tsconfig.json +34 -34
package/src/entity/index.js
CHANGED
|
@@ -1,525 +1,124 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export class Update${camelName}Fail implements Action {
|
|
127
|
-
readonly type = ${camelName}ActionTypes.UPDATE_FAIL;
|
|
128
|
-
constructor(
|
|
129
|
-
public error: any,
|
|
130
|
-
public correlationId?: string,
|
|
131
|
-
) {}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export class Upsert${camelName} implements Action {
|
|
135
|
-
readonly type = ${camelName}ActionTypes.UPSERT;
|
|
136
|
-
constructor(
|
|
137
|
-
public ${lowerCamelName}: ${camelName},
|
|
138
|
-
public correlationId?: string,
|
|
139
|
-
) {}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export class Upsert${camelName}Success implements Action {
|
|
143
|
-
readonly type = ${camelName}ActionTypes.UPSERT_SUCCESS;
|
|
144
|
-
constructor(
|
|
145
|
-
public ${lowerCamelName}: ${camelName},
|
|
146
|
-
public correlationId?: string,
|
|
147
|
-
) {}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export class Upsert${camelName}Fail implements Action {
|
|
151
|
-
readonly type = ${camelName}ActionTypes.UPSERT_FAIL;
|
|
152
|
-
constructor(
|
|
153
|
-
public error: any,
|
|
154
|
-
public correlationId?: string,
|
|
155
|
-
) {}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export class Remove${camelName} implements Action {
|
|
159
|
-
readonly type = ${camelName}ActionTypes.REMOVE;
|
|
160
|
-
constructor(
|
|
161
|
-
public __id: string,
|
|
162
|
-
public correlationId?: string,
|
|
163
|
-
) { }
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export class Remove${camelName}Success implements Action {
|
|
167
|
-
readonly type = ${camelName}ActionTypes.REMOVE_SUCCESS;
|
|
168
|
-
constructor(
|
|
169
|
-
public __id: string,
|
|
170
|
-
public correlationId?: string,
|
|
171
|
-
) {}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export class Remove${camelName}Fail implements Action {
|
|
175
|
-
readonly type = ${camelName}ActionTypes.REMOVE_FAIL;
|
|
176
|
-
constructor(
|
|
177
|
-
public error: any,
|
|
178
|
-
public correlationId?: string,
|
|
179
|
-
) {}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export class Loaded${camelName} implements Action {
|
|
183
|
-
readonly type = ${camelName}ActionTypes.LOADED;
|
|
184
|
-
constructor(
|
|
185
|
-
public payload: ${camelName}[],
|
|
186
|
-
public correlationId?: string,
|
|
187
|
-
) {}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export class Added${camelName} implements Action {
|
|
191
|
-
readonly type = ${camelName}ActionTypes.ADDED;
|
|
192
|
-
constructor(
|
|
193
|
-
public payload: ${camelName},
|
|
194
|
-
public correlationId?: string,
|
|
195
|
-
) {}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export class Modified${camelName} implements Action {
|
|
199
|
-
readonly type = ${camelName}ActionTypes.MODIFIED;
|
|
200
|
-
constructor(
|
|
201
|
-
public payload: ${camelName},
|
|
202
|
-
public correlationId?: string,
|
|
203
|
-
) {}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export class Removed${camelName} implements Action {
|
|
207
|
-
readonly type = ${camelName}ActionTypes.REMOVED;
|
|
208
|
-
constructor(
|
|
209
|
-
public payload: ${camelName},
|
|
210
|
-
public correlationId?: string,
|
|
211
|
-
) {}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export type ${camelName}Actions =
|
|
215
|
-
Load${camelName} |
|
|
216
|
-
Load${camelName}Success |
|
|
217
|
-
Load${camelName}Fail |
|
|
218
|
-
Add${camelName} |
|
|
219
|
-
Add${camelName}Success |
|
|
220
|
-
Add${camelName}Fail |
|
|
221
|
-
Update${camelName} |
|
|
222
|
-
Update${camelName}Success |
|
|
223
|
-
Update${camelName}Fail |
|
|
224
|
-
Upsert${camelName} |
|
|
225
|
-
Upsert${camelName}Success |
|
|
226
|
-
Upsert${camelName}Fail |
|
|
227
|
-
Remove${camelName} |
|
|
228
|
-
Remove${camelName}Success |
|
|
229
|
-
Remove${camelName}Fail |
|
|
230
|
-
Loaded${camelName} |
|
|
231
|
-
Added${camelName} |
|
|
232
|
-
Modified${camelName} |
|
|
233
|
-
Removed${camelName};`;
|
|
234
|
-
const EffectsFile = `import { Injectable } from '@angular/core';
|
|
235
|
-
import { Action } from '@ngrx/store';
|
|
236
|
-
import { Actions, createEffect, Effect, ofType } from '@ngrx/effects';
|
|
237
|
-
import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
|
|
238
|
-
import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
|
|
239
|
-
import { FirebaseService } from '../../firebase/firebase.service';
|
|
240
|
-
import { CachedLoadConnectionsService } from '../cached-load-connections.service';
|
|
241
|
-
|
|
242
|
-
import { ${camelName} } from './${name}.model';
|
|
243
|
-
import { ${camelName}ActionTypes, ${camelName}Actions,
|
|
244
|
-
Load${camelName}, Load${camelName}Success, Load${camelName}Fail,
|
|
245
|
-
Add${camelName}, Add${camelName}Success, Add${camelName}Fail,
|
|
246
|
-
Update${camelName}, Update${camelName}Success, Update${camelName}Fail,
|
|
247
|
-
Upsert${camelName}, Upsert${camelName}Success, Upsert${camelName}Fail,
|
|
248
|
-
Remove${camelName}, Remove${camelName}Success, Remove${camelName}Fail } from './${name}.actions';
|
|
249
|
-
|
|
250
|
-
@Injectable()
|
|
251
|
-
export class ${camelName}Effects {
|
|
252
|
-
|
|
253
|
-
/** Process the load action to create firebase connections. */
|
|
254
|
-
load$: Observable<Action> = createEffect(
|
|
255
|
-
() => this.actions$.pipe(
|
|
256
|
-
ofType<Load${camelName}>(${camelName}ActionTypes.LOAD),
|
|
257
|
-
mergeMap((action: Load${camelName}) => {
|
|
258
|
-
const connection = this.clc.processLoadAction(action);
|
|
259
|
-
return connection.loadStream.pipe(
|
|
260
|
-
take(1),
|
|
261
|
-
map(() => new Load${camelName}Success(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
|
|
262
|
-
catchError((error) => of(new Load${camelName}Fail(error, action.correlationId))),
|
|
263
|
-
);
|
|
264
|
-
}),
|
|
265
|
-
),
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
/** Process the add action to update database and initiate callbacks. */
|
|
269
|
-
add$: Observable<Action> = createEffect(
|
|
270
|
-
() => this.actions$.pipe(
|
|
271
|
-
ofType<Add${camelName}>(${camelName}ActionTypes.ADD),
|
|
272
|
-
mergeMap((action: Add${camelName}) => {
|
|
273
|
-
return this.db.addEntity('${lowerCamelName}s', action.${lowerCamelName}).pipe(
|
|
274
|
-
mergeMap(() => merge(
|
|
275
|
-
of(new Add${camelName}Success(action.${lowerCamelName}, action.correlationId)),
|
|
276
|
-
this.actionsOnAdd(action),
|
|
277
|
-
)),
|
|
278
|
-
catchError((error) => of(new Add${camelName}Fail(error, action.correlationId))),
|
|
279
|
-
);
|
|
280
|
-
}),
|
|
281
|
-
),
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
/** Process the update action to update database and initiate callbacks. */
|
|
285
|
-
update$: Observable<Action> = createEffect(
|
|
286
|
-
() => this.actions$.pipe(
|
|
287
|
-
ofType<Update${camelName}>(${camelName}ActionTypes.UPDATE),
|
|
288
|
-
mergeMap((action: Update${camelName}) => {
|
|
289
|
-
return this.db.updateEntity('${lowerCamelName}s', action.__id, action.changes).pipe(
|
|
290
|
-
mergeMap(() => merge(
|
|
291
|
-
of(new Update${camelName}Success(action.__id, action.changes, action.correlationId)),
|
|
292
|
-
this.actionsOnUpdate(action),
|
|
293
|
-
)),
|
|
294
|
-
catchError((error) => of(new Update${camelName}Fail(error, action.correlationId))),
|
|
295
|
-
);
|
|
296
|
-
}),
|
|
297
|
-
),
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
/** Process the upsert action to update database and initiate callbacks. */
|
|
301
|
-
upsert$: Observable<Action> = createEffect(
|
|
302
|
-
() => this.actions$.pipe(
|
|
303
|
-
ofType<Upsert${camelName}>(${camelName}ActionTypes.UPSERT),
|
|
304
|
-
mergeMap((action: Upsert${camelName}) => {
|
|
305
|
-
return this.db.upsertEntity('${lowerCamelName}s', action.${lowerCamelName}).pipe(
|
|
306
|
-
mergeMap((results) => merge(
|
|
307
|
-
of(new Upsert${camelName}Success(action.${lowerCamelName}, action.correlationId)),
|
|
308
|
-
results.type === 'add' ? this.actionsOnAdd(new Add${camelName}(action.${lowerCamelName}, action.correlationId)) : this.actionsOnUpdate(new Update${camelName}(action.${lowerCamelName}.__id, action.${lowerCamelName}, action.correlationId)),
|
|
309
|
-
)),
|
|
310
|
-
catchError((error) => of(new Upsert${camelName}Fail(error, action.correlationId))),
|
|
311
|
-
);
|
|
312
|
-
}),
|
|
313
|
-
),
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
/** Process the remove action to update database and initiate callbacks. */
|
|
317
|
-
remove$: Observable<Action> = createEffect(
|
|
318
|
-
() => this.actions$.pipe(
|
|
319
|
-
ofType<Remove${camelName}>(${camelName}ActionTypes.REMOVE),
|
|
320
|
-
mergeMap((action: Remove${camelName}) => {
|
|
321
|
-
return this.db.removeEntity('${lowerCamelName}s', action.__id).pipe(
|
|
322
|
-
mergeMap(() => merge(
|
|
323
|
-
of(new Remove${camelName}Success(action.__id, action.correlationId)),
|
|
324
|
-
this.actionsOnRemove(action),
|
|
325
|
-
)),
|
|
326
|
-
catchError((error) => of(new Remove${camelName}Fail(error, action.correlationId))),
|
|
327
|
-
);
|
|
328
|
-
}),
|
|
329
|
-
),
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
actionsOnAdd(action: Add${camelName}): Observable<Action> {
|
|
333
|
-
return EMPTY;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
actionsOnUpdate(action: Update${camelName}): Observable<Action> {
|
|
337
|
-
return EMPTY;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
actionsOnRemove(action: Remove${camelName}): Observable<Action> {
|
|
341
|
-
return EMPTY;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
constructor(
|
|
345
|
-
private actions$: Actions,
|
|
346
|
-
private db: FirebaseService,
|
|
347
|
-
private clc: CachedLoadConnectionsService,
|
|
348
|
-
) {}
|
|
349
|
-
}`;
|
|
350
|
-
const ModelFile = `import { firestore } from 'firebase/app';
|
|
351
|
-
|
|
352
|
-
/** test */
|
|
353
|
-
export interface ${camelName} {
|
|
354
|
-
__id: string;
|
|
355
|
-
_createdAt?: firestore.Timestamp;
|
|
356
|
-
_updatedAt?: firestore.Timestamp;
|
|
357
|
-
}`;
|
|
358
|
-
const SpecFile = `import { reducer, initialState } from './${name}.reducer';
|
|
359
|
-
|
|
360
|
-
describe('${camelName} Reducer', () => {
|
|
361
|
-
describe('unknown action', () => {
|
|
362
|
-
it('should return the initial state', () => {
|
|
363
|
-
const action = {} as any;
|
|
364
|
-
|
|
365
|
-
const result = reducer(initialState, action);
|
|
366
|
-
|
|
367
|
-
expect(result).toBe(initialState);
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});`;
|
|
371
|
-
const ReducerFile = `import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
|
|
372
|
-
import { ${camelName} } from './${name}.model';
|
|
373
|
-
import { ${camelName}Actions, ${camelName}ActionTypes } from './${name}.actions';
|
|
374
|
-
import { createFeatureSelector } from '@ngrx/store';
|
|
375
|
-
|
|
376
|
-
export interface State extends EntityState<${camelName}> {
|
|
377
|
-
// additional entities state properties
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
export const adapter: EntityAdapter<${camelName}> = createEntityAdapter<${camelName}>({
|
|
381
|
-
selectId: (${lowerCamelName}: ${camelName}) => ${lowerCamelName}.__id,
|
|
382
|
-
sortComparer: false,
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
export const initialState: State = adapter.getInitialState({
|
|
386
|
-
// additional entity state properties
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
export function reducer(
|
|
390
|
-
state: State = initialState,
|
|
391
|
-
action: ${camelName}Actions) {
|
|
392
|
-
|
|
393
|
-
switch (action.type) {
|
|
394
|
-
|
|
395
|
-
case ${camelName}ActionTypes.ADDED:
|
|
396
|
-
return adapter.upsertOne(action.payload, state);
|
|
397
|
-
|
|
398
|
-
case ${camelName}ActionTypes.LOADED:
|
|
399
|
-
return adapter.upsertMany(action.payload, state);
|
|
400
|
-
|
|
401
|
-
case ${camelName}ActionTypes.MODIFIED:
|
|
402
|
-
return adapter.updateOne({
|
|
403
|
-
id: action.payload.__id,
|
|
404
|
-
changes: action.payload,
|
|
405
|
-
}, state);
|
|
406
|
-
|
|
407
|
-
case ${camelName}ActionTypes.REMOVED:
|
|
408
|
-
return adapter.removeOne(action.payload.__id, state);
|
|
409
|
-
|
|
410
|
-
default:
|
|
411
|
-
return state;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
export const get${camelName}State = createFeatureSelector<State>('${lowerCamelName}');
|
|
416
|
-
|
|
417
|
-
export const {
|
|
418
|
-
selectIds,
|
|
419
|
-
selectEntities,
|
|
420
|
-
selectAll,
|
|
421
|
-
selectTotal,
|
|
422
|
-
} = adapter.getSelectors(get${camelName}State);`;
|
|
423
|
-
const ServiceFile = `import { Injectable } from '@angular/core';
|
|
424
|
-
import { Observable } from 'rxjs';
|
|
425
|
-
import { CachedSelectorsService } from '../cached-selectors.service';
|
|
426
|
-
import { FirebaseService } from '../../firebase/firebase.service';
|
|
427
|
-
import { ${camelName} } from './${name}.model';
|
|
428
|
-
|
|
429
|
-
@Injectable({
|
|
430
|
-
providedIn: 'root',
|
|
431
|
-
})
|
|
432
|
-
export class ${camelName}Service {
|
|
433
|
-
|
|
434
|
-
constructor(
|
|
435
|
-
private cs: CachedSelectorsService,
|
|
436
|
-
private db: FirebaseService,
|
|
437
|
-
) { }
|
|
438
|
-
|
|
439
|
-
/** Select a ${lowerCamelName} from the store. */
|
|
440
|
-
public select${camelName} = <T extends ${camelName}>(
|
|
441
|
-
id: string,
|
|
442
|
-
correlationId: string,
|
|
443
|
-
childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
|
|
444
|
-
): Observable<T> => {
|
|
445
|
-
|
|
446
|
-
return this.cs.selectEntityObj<${camelName}, T>('${lowerCamelName}', id, correlationId, childrenFn);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/** Select ${lowerCamelName}s from the store. */
|
|
450
|
-
public select${camelName}s = <T extends ${camelName}>(
|
|
451
|
-
queryParams: [string, string, any][],
|
|
452
|
-
correlationId: string,
|
|
453
|
-
childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
|
|
454
|
-
): Observable<Array<T>> => {
|
|
455
|
-
|
|
456
|
-
return this.cs.selectEntityList<${camelName}, T>('${lowerCamelName}', queryParams, correlationId, childrenFn);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/** Get a ${lowerCamelName} directly from the database. */
|
|
460
|
-
public get${camelName} = <T extends ${camelName}>(
|
|
461
|
-
id: string,
|
|
462
|
-
childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
|
|
463
|
-
): Observable<T> => {
|
|
464
|
-
|
|
465
|
-
return this.db.queryObjOnce<${camelName}, T>('${lowerCamelName}s', id, childrenFn);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/** Get ${lowerCamelName}s directly from the database. */
|
|
469
|
-
public get${camelName}s = <T extends ${camelName}>(
|
|
470
|
-
queryParams: [string, string, any][],
|
|
471
|
-
queryOptions?: { [index: string]: any },
|
|
472
|
-
childrenFn?: (e: ${camelName}) => { [index: string]: Observable<any> },
|
|
473
|
-
): Observable<Array<T>> => {
|
|
474
|
-
|
|
475
|
-
return this.db.queryListOnce<${camelName}, T>('${lowerCamelName}s', queryParams, queryOptions, childrenFn);
|
|
476
|
-
}
|
|
477
|
-
}`;
|
|
478
|
-
statements_adder_1.AddStatements('src/app/core/core.module.ts', [
|
|
479
|
-
'// Entity Effects',
|
|
480
|
-
'// Entity Effects'
|
|
481
|
-
], [
|
|
482
|
-
`import { ${camelName}Effects } from './store/${name}/${name}.effects';`,
|
|
483
|
-
` ${camelName}Effects,`
|
|
484
|
-
], tree);
|
|
485
|
-
statements_adder_1.AddStatements('src/app/core/firebase/firebase.mock.service.ts', [
|
|
486
|
-
'// Entity Models',
|
|
487
|
-
'this.mockDBChanges = {'
|
|
488
|
-
], [
|
|
489
|
-
`import { ${camelName} } from '../store/${name}/${name}.model';`,
|
|
490
|
-
` ${lowerCamelName}s: new BehaviorSubject<Array<{ type: string, result: ${camelName} }>>\n(this.mockDBService.getInitialDBStateChanges('${lowerCamelName}s')),`
|
|
491
|
-
], tree);
|
|
492
|
-
statements_adder_1.AddStatements('src/app/core/store/app.reducer.ts', [
|
|
493
|
-
'// Entity Reducers',
|
|
494
|
-
'// Entity State',
|
|
495
|
-
'// Entity Reducers'
|
|
496
|
-
], [
|
|
497
|
-
`import * as from${camelName} from './${name}/${name}.reducer';`,
|
|
498
|
-
` ${lowerCamelName}: from${camelName}.State;`,
|
|
499
|
-
` ${lowerCamelName}: from${camelName}.reducer,`
|
|
500
|
-
], tree);
|
|
501
|
-
statements_adder_1.AddStatements('src/app/core/store/app.selectors.ts', [
|
|
502
|
-
'// Entity Selectors',
|
|
503
|
-
'// Entity Selectors',
|
|
504
|
-
'// Entity Selectors'
|
|
505
|
-
], [
|
|
506
|
-
`import { ${camelName}Service } from './${name}/${name}.service';`,
|
|
507
|
-
` private ${lowerCamelName}: ${camelName}Service,`,
|
|
508
|
-
` public get${camelName} = this.${lowerCamelName}.get${camelName};\n public get${camelName}s = this.${lowerCamelName}.get${camelName}s;\n public select${camelName} = this.${lowerCamelName}.select${camelName};\n public select${camelName}s = this.${lowerCamelName}.select${camelName}s;`
|
|
509
|
-
], tree);
|
|
510
|
-
// create directories before adding files
|
|
511
|
-
const dir = `./src/app/core/store/${name}`;
|
|
512
|
-
if (!fs.existsSync(dir)) {
|
|
513
|
-
fs.mkdirSync(dir);
|
|
514
|
-
}
|
|
515
|
-
tree.create(`${dir}/${name}.actions.ts`, ActionsFile);
|
|
516
|
-
tree.create(`${dir}/${name}.effects.ts`, EffectsFile);
|
|
517
|
-
tree.create(`${dir}/${name}.model.ts`, ModelFile);
|
|
518
|
-
tree.create(`${dir}/${name}.reducer.spec.ts`, SpecFile);
|
|
519
|
-
tree.create(`${dir}/${name}.reducer.ts`, ReducerFile);
|
|
520
|
-
tree.create(`${dir}/${name}.service.ts`, ServiceFile);
|
|
521
|
-
return tree;
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
exports.entity = entity;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.entity = void 0;
|
|
13
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
14
|
+
const change_1 = require("@schematics/angular/utility/change");
|
|
15
|
+
const find_module_1 = require("@schematics/angular/utility/find-module");
|
|
16
|
+
const parse_name_1 = require("@schematics/angular/utility/parse-name");
|
|
17
|
+
const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
18
|
+
const core_1 = require("@angular-devkit/core");
|
|
19
|
+
const statements_adder_1 = require("../shared/statements-adder");
|
|
20
|
+
function addInserts(options) {
|
|
21
|
+
return (host, context) => {
|
|
22
|
+
const classifiedName = core_1.strings.classify(options.name);
|
|
23
|
+
const camelizedName = core_1.strings.camelize(options.name);
|
|
24
|
+
context.logger.info(`names: ${classifiedName}, ${camelizedName}`);
|
|
25
|
+
// Add core module changes
|
|
26
|
+
const coreModulePath = options.module;
|
|
27
|
+
const coreModuleText = (0, statements_adder_1.getSourceText)(host, coreModulePath);
|
|
28
|
+
context.logger.info(`modulePath: ${coreModulePath}`);
|
|
29
|
+
const entityEffectsPath = `/${options.path}/` +
|
|
30
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
31
|
+
core_1.strings.dasherize(options.name) + '.effects';
|
|
32
|
+
context.logger.info(`entityEffectsPath: ${entityEffectsPath}`);
|
|
33
|
+
const coreToEffectsPath = (0, find_module_1.buildRelativePath)(coreModulePath, entityEffectsPath);
|
|
34
|
+
context.logger.info(`coreToEffectsPath: ${coreToEffectsPath}`);
|
|
35
|
+
let insertChangesInCore = (0, statements_adder_1.simpleInsert)(coreModuleText, coreModulePath, [
|
|
36
|
+
'// Entity Effects',
|
|
37
|
+
'// Entity Effects'
|
|
38
|
+
], [
|
|
39
|
+
`import { ${classifiedName}Effects } from '${coreToEffectsPath}';`,
|
|
40
|
+
` ${classifiedName}Effects,`
|
|
41
|
+
]);
|
|
42
|
+
// Add app reducer changes
|
|
43
|
+
const appReducerPath = '//src/app/core/store/app.reducer.ts';
|
|
44
|
+
const appReducerText = (0, statements_adder_1.getSourceText)(host, appReducerPath);
|
|
45
|
+
context.logger.info(`appReducerPath: ${appReducerPath}`);
|
|
46
|
+
const entityReducerPath = `/${options.path}/` +
|
|
47
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
48
|
+
core_1.strings.dasherize(options.name) + '.reducer';
|
|
49
|
+
context.logger.info(`entityReducerPath: ${entityReducerPath}`);
|
|
50
|
+
const appToEntityReducerPath = (0, find_module_1.buildRelativePath)(appReducerPath, entityReducerPath);
|
|
51
|
+
let insertChangesInAppReducer = (0, statements_adder_1.simpleInsert)(appReducerText, appReducerPath, [
|
|
52
|
+
'// Entity Reducers',
|
|
53
|
+
'// Entity State',
|
|
54
|
+
'// Entity Reducers'
|
|
55
|
+
], [
|
|
56
|
+
`import * as from${classifiedName} from '${appToEntityReducerPath}';`,
|
|
57
|
+
` ${camelizedName}: from${classifiedName}.State;`,
|
|
58
|
+
` ${camelizedName}: from${classifiedName}.reducer,`
|
|
59
|
+
]);
|
|
60
|
+
// Add app selector changes
|
|
61
|
+
const appSelectorPath = '//src/app/core/store/app.selectors.ts';
|
|
62
|
+
const appSelectorText = (0, statements_adder_1.getSourceText)(host, appSelectorPath);
|
|
63
|
+
const entityServicePath = `/${options.path}/` +
|
|
64
|
+
core_1.strings.dasherize(options.name) + '/' +
|
|
65
|
+
core_1.strings.dasherize(options.name) + '.service';
|
|
66
|
+
const appToEntityServicePath = (0, find_module_1.buildRelativePath)(appSelectorPath, entityServicePath);
|
|
67
|
+
let insertChangesInAppSelector = (0, statements_adder_1.simpleInsert)(appSelectorText, appSelectorPath, [
|
|
68
|
+
'// Entity Selectors',
|
|
69
|
+
'// Entity Selectors',
|
|
70
|
+
'// Entity Selectors'
|
|
71
|
+
], [
|
|
72
|
+
`import { ${classifiedName}Service } from '${appToEntityServicePath}';`,
|
|
73
|
+
` private ${camelizedName}: ${classifiedName}Service,`,
|
|
74
|
+
` public get${classifiedName} = this.${camelizedName}.get${classifiedName};\n public get${classifiedName}s = this.${camelizedName}.get${classifiedName}s;\n public select${classifiedName} = this.${camelizedName}.select${classifiedName};\n public select${classifiedName}s = this.${camelizedName}.select${classifiedName}s;`
|
|
75
|
+
]);
|
|
76
|
+
context.logger.info(`about to start committing`);
|
|
77
|
+
// For each of the files and corresponding set of changes, commit to the tree
|
|
78
|
+
[
|
|
79
|
+
[coreModulePath, insertChangesInCore],
|
|
80
|
+
[appReducerPath, insertChangesInAppReducer],
|
|
81
|
+
[appSelectorPath, insertChangesInAppSelector]
|
|
82
|
+
].map(([filePath, insertChanges]) => {
|
|
83
|
+
const declarationRecorder = host.beginUpdate(filePath);
|
|
84
|
+
for (const change of insertChanges) {
|
|
85
|
+
if (change instanceof change_1.InsertChange) {
|
|
86
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
host.commitUpdate(declarationRecorder);
|
|
90
|
+
});
|
|
91
|
+
return host;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function entity(options) {
|
|
95
|
+
return (tree, context) => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
// Make sure the command is executed in the directory where the component should be generated
|
|
97
|
+
if (!options.inDirectory) {
|
|
98
|
+
context.logger.info("Please navigate to the directory where you want to generate the entity.");
|
|
99
|
+
return (0, schematics_1.noop)();
|
|
100
|
+
}
|
|
101
|
+
const workspace = yield (0, workspace_1.getWorkspace)(tree);
|
|
102
|
+
const project = workspace.projects.get(options.project);
|
|
103
|
+
if (!project) {
|
|
104
|
+
throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
|
|
105
|
+
}
|
|
106
|
+
if (options.path === undefined) {
|
|
107
|
+
options.path = (0, workspace_1.buildDefaultPath)(project);
|
|
108
|
+
}
|
|
109
|
+
options.module = (0, find_module_1.findModuleFromOptions)(tree, options);
|
|
110
|
+
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
111
|
+
options.name = parsedPath.name;
|
|
112
|
+
options.path = parsedPath.path;
|
|
113
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
114
|
+
(0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
115
|
+
(0, schematics_1.move)(parsedPath.path),
|
|
116
|
+
]);
|
|
117
|
+
return (0, schematics_1.chain)([
|
|
118
|
+
addInserts(options),
|
|
119
|
+
(0, schematics_1.mergeWith)(templateSource)
|
|
120
|
+
]);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.entity = entity;
|
|
525
124
|
//# sourceMappingURL=index.js.map
|