@tech4good/angular-schematics 13.3.0 → 13.5.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.
Files changed (59) hide show
  1. package/package.json +1 -1
  2. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +2 -4
  3. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +1 -1
  4. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +2 -4
  5. package/src/init/files/{.eslintrc.json → .eslintrc.json.template} +0 -0
  6. package/src/init/files/{.gitattributes → .gitattributes.template} +0 -0
  7. package/src/init/files/.gitignore.template +55 -0
  8. package/src/init/files/angular.json.template +1 -1
  9. package/src/init/files/package.json.template +1 -1
  10. package/src/init/files/src/app/app-routing.module.ts.template +19 -0
  11. package/src/init/files/src/app/{app.component.html → app.component.html.template} +0 -0
  12. package/src/init/files/src/app/{app.component.scss → app.component.scss.template} +0 -0
  13. package/src/init/files/src/app/app.component.ts.template +41 -0
  14. package/src/init/files/src/app/app.module.ts.template +34 -0
  15. package/src/init/files/src/app/core/analytics/log.service.ts.template +35 -0
  16. package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +223 -0
  17. package/src/init/files/src/app/core/core.module.ts.template +71 -0
  18. package/src/init/files/src/app/core/firebase/firebase.service.ts.template +284 -0
  19. package/src/init/files/src/app/core/router/routing-state.service.ts.template +28 -0
  20. package/src/init/files/src/app/core/setup/firebase-setup.ts.template +25 -0
  21. package/src/init/files/src/app/core/setup/module-import-guard.ts.template +5 -0
  22. package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +24 -0
  23. package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +41 -0
  24. package/src/init/files/src/app/core/store/app.actions.ts.template +92 -0
  25. package/src/init/files/src/app/core/store/app.effects.ts.template +167 -0
  26. package/src/init/files/src/app/core/store/app.reducer.ts.template +30 -0
  27. package/src/init/files/src/app/core/store/app.selectors.ts.template +30 -0
  28. package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +75 -0
  29. package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +164 -0
  30. package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +13 -0
  31. package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +26 -0
  32. package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +21 -0
  33. package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +404 -0
  34. package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +376 -0
  35. package/src/init/files/src/app/core/store/effects.helpers.ts.template +66 -0
  36. package/src/init/files/src/app/core/store/user/user.actions.ts.template +269 -0
  37. package/src/init/files/src/app/core/store/user/user.effects.ts.template +131 -0
  38. package/src/init/files/src/app/core/store/user/user.model.ts.template +15 -0
  39. package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +13 -0
  40. package/src/init/files/src/app/core/store/user/user.reducer.ts.template +50 -0
  41. package/src/init/files/src/app/core/store/user/user.service.ts.template +50 -0
  42. package/src/init/files/src/app/core/utils/string-case.utils.ts.template +96 -0
  43. package/src/init/files/src/app/general/e404/{e404.component.html → e404.component.html.template} +0 -0
  44. package/src/init/files/src/app/general/e404/{e404.component.scss → e404.component.scss.template} +0 -0
  45. package/src/init/files/src/app/general/e404/e404.component.spec.ts.template +25 -0
  46. package/src/init/files/src/app/general/e404/e404.component.ts.template +28 -0
  47. package/src/init/files/src/app/general/general-routing.module.ts.template +21 -0
  48. package/src/init/files/src/app/general/general.module.spec.ts.template +13 -0
  49. package/src/init/files/src/app/general/general.module.ts.template +30 -0
  50. package/src/init/files/src/app/general/login/{login.component.html → login.component.html.template} +0 -0
  51. package/src/init/files/src/app/general/login/{login.component.scss → login.component.scss.template} +0 -0
  52. package/src/init/files/src/app/general/login/login.component.spec.ts.template +25 -0
  53. package/src/init/files/src/app/general/login/login.component.ts.template +72 -0
  54. package/src/init/files/src/app/shared/shared.module.ts.template +81 -0
  55. package/src/init/files/src/environments/environment.prod.ts.template +5 -0
  56. package/src/init/files/src/environments/environment.ts.template +18 -0
  57. package/src/init/files/src/styles/{_variables.scss → _variables.scss.template} +0 -0
  58. package/src/init/files/src/{styles.scss → styles.scss.template} +0 -0
  59. package/src/init/files/tsconfig.json.template +31 -0
@@ -0,0 +1,376 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { MemoizedSelector, createSelector, createFeatureSelector } from '@ngrx/store';
3
+ import { EntityState } from '@ngrx/entity';
4
+ import { Store, select } from '@ngrx/store';
5
+ import * as fromStore from '../../core/store/app.reducer';
6
+ import { pluck, tap, map, switchMap, filter } from 'rxjs/operators';
7
+ import { Observable, of, combineLatest } from 'rxjs';
8
+ import { FirebaseService } from '../firebase/firebase.service';
9
+
10
+ export interface CachedSelector<T> {
11
+ hashKey: string;
12
+ selector: MemoizedSelector<fromStore.State, T>;
13
+ correlationIds: string[];
14
+ }
15
+
16
+ export enum SelectType {
17
+ OBJECT = 'object',
18
+ LIST = 'list',
19
+ }
20
+
21
+ @Injectable({
22
+ providedIn: 'root',
23
+ })
24
+ export class CachedSelectorsService {
25
+ /** Store selectors by entityStoreKey. */
26
+ private entityStoreSelectors: { [entityStoreKey: string]: MemoizedSelector<fromStore.State, any> } = {};
27
+
28
+ /** Selectors by hashKey. */
29
+ private selectorsByHashKey: { [hashKey: string]: CachedSelector<any> } = {};
30
+
31
+ /** Selectors by correlationId. */
32
+ private selectorsByCorrelationId: { [cId: string]: CachedSelector<any>[] } = {};
33
+
34
+ /** Any hardcoded data that needs to be merged into observable selected from store. */
35
+ private hardcodedFields = {
36
+ };
37
+
38
+ constructor(
39
+ private store: Store<fromStore.State>,
40
+ private db: FirebaseService,
41
+ ) { }
42
+
43
+ public createId = () => {
44
+ return this.db.createId();
45
+ };
46
+
47
+ /**
48
+ * Define a unique key for each selector.
49
+ * @param queryParams - either a simple id string (for SelectType.OBJECT) or the queryParams array (for SelectType.LIST)
50
+ */
51
+ private getHashKey(selectType: SelectType, entityStoreKey: string, queryParams: string | [string, string, any][]): string {
52
+ return `${selectType}.${entityStoreKey}.${queryParams}`;
53
+ }
54
+
55
+ /** Gets a cached selector if one exists. */
56
+ private getSelector(selectType: SelectType, entityStoreKey: string, queryParams: string | [string, string, any][]): CachedSelector<any> {
57
+ const hashKey = this.getHashKey(selectType, entityStoreKey, queryParams);
58
+ return this.selectorsByHashKey[hashKey];
59
+ }
60
+
61
+ /**
62
+ * Releases all "virtual" selectors with that correlationId.
63
+ * For selectors where this correlationId was the only one, release
64
+ * it in actuality.
65
+ */
66
+ public release = (correlationId: string) => {
67
+ // Add a 5-second delay so we don't have to reselect multiple times
68
+ // if the next view happens to use the same selectors
69
+ setTimeout(() => {
70
+ const selectors = this.selectorsByCorrelationId[correlationId];
71
+
72
+ // If there are no selectors, just return
73
+ if (!selectors) {
74
+ return;
75
+ }
76
+
77
+ while (selectors.length > 0) {
78
+ const s = selectors.pop();
79
+
80
+ // Remove the correlationId from the list in that selector
81
+ const index = s.correlationIds.findIndex((cId) => cId === correlationId);
82
+ s.correlationIds.splice(index, 1);
83
+
84
+ // If there are no more correlationIds, then release
85
+ if (s.correlationIds.length === 0) {
86
+ s.selector.release();
87
+
88
+ // Update selectorsByHashKey
89
+ this.selectorsByHashKey[s.hashKey] = undefined;
90
+ }
91
+ }
92
+ }, 5000);
93
+ };
94
+
95
+ public selectEntityObj = <S, T>(
96
+ entityStoreKey: string,
97
+ id: string,
98
+ correlationId: string,
99
+ childrenFn?: (e: S) => { [index: string]: Observable<any> },
100
+ ): Observable<T> => {
101
+ return this.store.pipe(
102
+ select(this.getEntityObjSelector<S>(entityStoreKey, id, correlationId)),
103
+ // TODO: filter or not? principle is that if it should exist, we shouldn't emit before it's been
104
+ // loaded into the store. On the other hand, what if the db messes up? could this be fragile?
105
+ filter((val) => val !== undefined),
106
+ switchMap((e) => {
107
+ if (!e || !childrenFn) {
108
+ return of(e);
109
+ } else {
110
+ const children = childrenFn(e);
111
+ // transform the hash of observables into an array of observable hashes
112
+ const obsArray = Object.keys(children).map((objKey) => {
113
+ const obs = children[objKey];
114
+ return obs.pipe(
115
+ map((entity) => {
116
+ const obj = {};
117
+ obj[objKey] = entity;
118
+ return obj;
119
+ }),
120
+ );
121
+ });
122
+ return obsArray.length === 0 ? of(e) : combineLatest(obsArray).pipe(
123
+ map((array) => {
124
+ return Object.assign({}, e, ...array);
125
+ }),
126
+ );
127
+ }
128
+ }),
129
+ );
130
+ };
131
+
132
+ public selectEntityList = <S, T>(
133
+ entityStoreKey: string,
134
+ queryParams: [string, string, any][],
135
+ correlationId: string,
136
+ childrenFn?: (e: S) => { [index: string]: Observable<any> },
137
+ ): Observable<Array<T>> => {
138
+ return this.store.pipe(
139
+ select(this.getEntityListSelector<S>(entityStoreKey, queryParams, correlationId)),
140
+ // TODO: filter or not? principle is that if it should exist, we shouldn't emit before it's been
141
+ // loaded into the store. On the other hand, what if the db messes up? could this be fragile?
142
+ filter((val) => val !== undefined),
143
+ switchMap((entities) => {
144
+ if (!entities || !childrenFn || entities.length === 0) {
145
+ return of(entities);
146
+ } else {
147
+ return combineLatest(entities.map((e) => {
148
+ // If there are children, then we need to transform the hash of observables into an observable with the data object
149
+ const children = childrenFn(e);
150
+
151
+ const obsArray = Object.keys(children).map((objKey) => {
152
+ const obs = children[objKey];
153
+ return obs.pipe(map((entity) => {
154
+ const obj = {};
155
+ obj[objKey] = entity;
156
+ return obj;
157
+ }));
158
+ });
159
+ return obsArray.length === 0 ? of(e) : combineLatest(obsArray).pipe(
160
+ map((array) => {
161
+ return Object.assign({}, e, ...array);
162
+ }),
163
+ );
164
+ }));
165
+ }
166
+ }),
167
+ );
168
+ };
169
+
170
+ /* ---------------- HELPERS --------------------- */
171
+
172
+ private getEntityStoreSelector<T>(
173
+ entityStoreKey: string,
174
+ ): (s: fromStore.State) => EntityState<T> {
175
+ const selector = this.entityStoreSelectors[entityStoreKey] ||
176
+ createFeatureSelector<T>(entityStoreKey);
177
+
178
+ return selector;
179
+ }
180
+
181
+ private getEntityListSelector<T>(
182
+ entityStoreKey: string,
183
+ queryParams: [string, string, any][],
184
+ correlationId: string,
185
+ ): (s: fromStore.State) => T[] {
186
+ // get selector
187
+ let cachedSelector = this.getSelector(SelectType.LIST, entityStoreKey, queryParams);
188
+
189
+ if (cachedSelector) {
190
+ // if the selector already exists, just need to add correlationId
191
+ // if it doesn't already exist
192
+ if (!cachedSelector.correlationIds.some((cId) => cId === correlationId)) {
193
+ cachedSelector.correlationIds.push(correlationId);
194
+ this.selectorsByCorrelationId[correlationId] = this.selectorsByCorrelationId[correlationId] || [];
195
+ this.selectorsByCorrelationId[correlationId].push(cachedSelector);
196
+ }
197
+ } else {
198
+ // if the selector does not exist, create it
199
+ cachedSelector = this.createEntityListSelector<T>(entityStoreKey, queryParams, correlationId);
200
+ this.selectorsByHashKey[cachedSelector.hashKey] = cachedSelector;
201
+ this.selectorsByCorrelationId[correlationId] = this.selectorsByCorrelationId[correlationId] || [];
202
+ this.selectorsByCorrelationId[correlationId].push(cachedSelector);
203
+ }
204
+ return cachedSelector.selector;
205
+ }
206
+
207
+ private createEntityListSelector<T>(
208
+ entityStoreKey: string,
209
+ queryParams: [string, string, any][],
210
+ correlationId: string,
211
+ ): CachedSelector<T[]> {
212
+ return {
213
+ hashKey: this.getHashKey(SelectType.LIST, entityStoreKey, queryParams),
214
+ selector: createSelector(
215
+ this.getEntityStoreSelector<T>(entityStoreKey),
216
+ (entityStore) => {
217
+ const val = this.getList<T>(entityStore.entities, queryParams);
218
+ return val.map((e) => {
219
+ if (this.hardcodedFields[entityStoreKey]) {
220
+ return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e.__id]);
221
+ } else {
222
+ return e;
223
+ }
224
+ });
225
+ },
226
+ ),
227
+ correlationIds: [correlationId],
228
+ };
229
+ }
230
+
231
+ private getList<T>(
232
+ entityHash: { [index: string]: T },
233
+ queryParams: [string, string, any][],
234
+ ): Array<T & { [index: string]: any }> {
235
+ let filteredEntities = [];
236
+
237
+ // APPLY '__id', '=='/in FILTERS
238
+
239
+ const selectIdEqQueries = queryParams.filter((q) => q[0] === '__id' && q[1] === '==');
240
+ const uniqSelectEqIds = selectIdEqQueries.map((q) => q[2]).filter((q, i, a) => a.indexOf(q) === i);
241
+ const selectIdInQueries = queryParams.filter((q) => q[0] === '__id' && q[1] === 'in');
242
+
243
+ if (uniqSelectEqIds.length === 1 && entityHash[uniqSelectEqIds[0]]) {
244
+ // If there is exactly one '__id', we can start with that to filter
245
+ if (entityHash[uniqSelectEqIds[0]]) {
246
+ filteredEntities.push(entityHash[uniqSelectEqIds[0]]);
247
+ }
248
+ } else if (uniqSelectEqIds.length > 1) {
249
+ // If there are more than one select id ==, then there cannot be any matches
250
+ console.log('Is this really what you wanted to query?');
251
+ console.log(queryParams);
252
+ return [];
253
+ } else if (selectIdInQueries.length > 0) {
254
+ // If there is at least one 'in' query, start with that.
255
+ const firstInIds = selectIdInQueries[0][2];
256
+ filteredEntities = firstInIds.map((id) => entityHash[id]).filter((e) => e !== undefined);
257
+
258
+ // Then apply remaining 'in' filters. See general filter section
259
+ // for comments since this is just copied from that.
260
+ if (selectIdInQueries.length > 1) {
261
+ filteredEntities = filteredEntities.filter((e) => {
262
+ return !selectIdInQueries.slice(1).find((f) => {
263
+ const [key, rel, val] = f;
264
+ return !(val.find((ev) => ev === e[key]));
265
+ });
266
+ });
267
+ }
268
+ } else {
269
+ // Otherwise, start with the full list and filter further.
270
+ filteredEntities = Object.keys(entityHash).map((id) => entityHash[id]);
271
+ }
272
+
273
+ // APPLY REMAINING FILTERS
274
+ if (queryParams) {
275
+ filteredEntities = filteredEntities.filter((e) => {
276
+ // Looks for the first failed filter. If there exists any,
277
+ // return false (filter it out)
278
+ return !queryParams.find((f) => {
279
+ const [key, rel, val] = f;
280
+
281
+ // already processed '__id', '=='/'in', so always passes this filter
282
+ if (key === '__id' && (rel === '==' || rel === 'in')) {
283
+ return false;
284
+ }
285
+
286
+ // we try to handle the same operations as Firestore for consistency
287
+ switch (rel) {
288
+ case '==':
289
+ return !(e[key] === val);
290
+ case '!=':
291
+ return !(e[key] !== val);
292
+
293
+ case '>=':
294
+ return !(e[key] >= val);
295
+
296
+ case '<=':
297
+ return !(e[key] <= val);
298
+
299
+ case '>':
300
+ return !(e[key] > val);
301
+
302
+ case '<':
303
+ return !(e[key] < val);
304
+
305
+ case 'array-contains':
306
+ // If the parameter in question is optional, it should be filtered out
307
+ return e[key] ? !(e[key].find((ev) => ev === val)) : true;
308
+
309
+ case 'in':
310
+ return !(val.find((ev) => ev === e[key]));
311
+
312
+ default:
313
+ return false;
314
+ }
315
+ });
316
+ });
317
+ }
318
+
319
+ return filteredEntities;
320
+ }
321
+
322
+ private getEntityObjSelector<T>(
323
+ entityStoreKey: string,
324
+ id: string,
325
+ correlationId: string,
326
+ ): (s: fromStore.State) => T {
327
+ // get selector
328
+ let cachedSelector = this.getSelector(SelectType.OBJECT, entityStoreKey, id);
329
+
330
+ if (cachedSelector) {
331
+ // if the selector already exists, just need to add correlationId
332
+ // if it doesn't already exist
333
+ if (!cachedSelector.correlationIds.some((cId) => cId === correlationId)) {
334
+ cachedSelector.correlationIds.push(correlationId);
335
+ this.selectorsByCorrelationId[correlationId] = this.selectorsByCorrelationId[correlationId] || [];
336
+ this.selectorsByCorrelationId[correlationId].push(cachedSelector);
337
+ }
338
+ } else {
339
+ // if the selector does not exist, create it
340
+ cachedSelector = this.createEntityObjSelector<T>(entityStoreKey, id, correlationId);
341
+ this.selectorsByHashKey[cachedSelector.hashKey] = cachedSelector;
342
+ this.selectorsByCorrelationId[correlationId] = this.selectorsByCorrelationId[correlationId] || [];
343
+ this.selectorsByCorrelationId[correlationId].push(cachedSelector);
344
+ }
345
+ return cachedSelector.selector;
346
+ }
347
+
348
+ private createEntityObjSelector<T>(
349
+ entityStoreKey: string,
350
+ id: string,
351
+ correlationId: string,
352
+ ): CachedSelector<T> {
353
+ return {
354
+ hashKey: this.getHashKey(SelectType.OBJECT, entityStoreKey, id),
355
+ selector: createSelector(
356
+ this.getEntityStoreSelector<T>(entityStoreKey),
357
+ (entityStore) => {
358
+ const e = this.getObj<T>(entityStore.entities, id);
359
+ if (e && this.hardcodedFields[entityStoreKey]) {
360
+ return Object.assign({}, e, this.hardcodedFields[entityStoreKey][e.__id]);
361
+ } else {
362
+ return e;
363
+ }
364
+ },
365
+ ),
366
+ correlationIds: [correlationId],
367
+ };
368
+ }
369
+
370
+ private getObj<T>(
371
+ entityHash: { [index: string]: T },
372
+ id: string,
373
+ ): T & { [index: string]: any } {
374
+ return entityHash[id];
375
+ }
376
+ }
@@ -0,0 +1,66 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Action } from '@ngrx/store';
3
+ import { Actions, ofType } from '@ngrx/effects';
4
+ import { select, Store } from '@ngrx/store';
5
+ import * as fromStore from './app.reducer';
6
+ import { Observable, pipe, forkJoin } from 'rxjs';
7
+ import { reduce, filter, mergeMap, map, take, first } from 'rxjs/operators';
8
+
9
+ @Injectable({
10
+ providedIn: 'root',
11
+ })
12
+ export class EffectsHelpers {
13
+ constructor(
14
+ private actions$: Actions,
15
+ private store: Store<fromStore.State>,
16
+ ) {}
17
+
18
+ /**
19
+ * aggregates multiple actions together based on a calculated actionTypeArray
20
+ * (computed from the passed in function applied to the original action) and
21
+ * the correlationId
22
+ */
23
+ aggregate = <A, R extends Action>(fn: (o: A) => Array<string|string[]>, correlationId: string) => pipe(
24
+ mergeMap((origAction: A): Observable<R[]> => {
25
+ const actionTypeArray = fn(origAction);
26
+ const actionObs = actionTypeArray.map((at) => {
27
+ return this.actions$.pipe(
28
+ Array.isArray(at) ? ofType(...at) : ofType(at),
29
+ this.hasCorrelationId(correlationId),
30
+ first(),
31
+ );
32
+ }) as Array<Observable<R>>;
33
+ return forkJoin(actionObs);
34
+ }),
35
+ );
36
+
37
+ /**
38
+ * enriches the original content in the event stream with the result from contentFn's
39
+ * returned the observable when it is applied to the original content.
40
+ */
41
+ enrich = <A, P extends object>(contentFn$: (o: A) => Observable<P>) => pipe(
42
+ mergeMap((orig: A): Observable<A & { payload: P }> => {
43
+ // payload may not be defined on this Action
44
+ const payload = orig['payload'] || { };
45
+
46
+ return contentFn$(orig).pipe(
47
+ take(1),
48
+ map<P, A & { payload: P }>((c) => Object.assign({}, orig, {
49
+ payload: { ...payload, ...(c as object) },
50
+ })),
51
+ );
52
+ }),
53
+ );
54
+
55
+ /** Filter to Actions with specified correlationId(s). */
56
+ hasCorrelationId = <T extends Action>(correlationIds: string | string[]) => pipe(
57
+ // Use hash syntax since correlationId may not be defined on this Action
58
+ filter<T>((origAction) => {
59
+ if (!Array.isArray(correlationIds)) {
60
+ return origAction['correlationId'] === correlationIds;
61
+ } else {
62
+ return correlationIds.includes(origAction['correlationId']);
63
+ }
64
+ }),
65
+ );
66
+ }
@@ -0,0 +1,269 @@
1
+ import { Action } from '@ngrx/store';
2
+ import { LoadAction } from '../app.actions';
3
+ import { User } from './user.model';
4
+
5
+ export enum UserActionTypes {
6
+ STREAM = '[User] stream user',
7
+ STREAM_SUCCESS = '[User] stream user success',
8
+ STREAM_FAIL = '[User] stream user fail',
9
+ LOAD = '[User] load user',
10
+ LOAD_SUCCESS = '[User] load user success',
11
+ LOAD_FAIL = '[User] load user fail',
12
+ ADD = '[User] add user',
13
+ ADD_SUCCESS = '[User] add user success',
14
+ ADD_FAIL = '[User] add user fail',
15
+ UPDATE = '[User] update user',
16
+ UPDATE_SUCCESS = '[User] update user success',
17
+ UPDATE_FAIL = '[User] update user fail',
18
+ UPSERT = '[User] upsert user',
19
+ UPSERT_SUCCESS = '[User] upsert user success',
20
+ UPSERT_FAIL = '[User] upsert user fail',
21
+ REMOVE = '[User] remove user',
22
+ REMOVE_SUCCESS = '[User] remove user success',
23
+ REMOVE_FAIL = '[User] remove user fail',
24
+ LOADED = '[User] loaded',
25
+ ADDED = '[User] added',
26
+ MODIFIED = '[User] modified',
27
+ REMOVED = '[User] removed',
28
+ }
29
+
30
+ // See Firebase Docs for current constraints on valid queries
31
+ export class StreamUser implements Action {
32
+ readonly type = UserActionTypes.STREAM;
33
+ constructor(
34
+ // property, comparator, value
35
+ public queryParams: [string, string, any][],
36
+ public queryOptions: {
37
+ orderBy?: string | [string, string],
38
+ limit?: number,
39
+ startAt?: string,
40
+ startAfter?: string,
41
+ endAt?: string,
42
+ endBefore?: string,
43
+ },
44
+ public correlationId: string,
45
+ public followupActions?: (user: User) => LoadAction[],
46
+ ) {}
47
+ }
48
+
49
+ export class StreamUserSuccess implements Action {
50
+ readonly type = UserActionTypes.STREAM_SUCCESS;
51
+ constructor(
52
+ public queryParams: [string, string, any][],
53
+ public queryOptions: {
54
+ orderBy?: string | [string, string],
55
+ limit?: number,
56
+ startAt?: string,
57
+ startAfter?: string,
58
+ endAt?: string,
59
+ endBefore?: string,
60
+ },
61
+ public correlationId: string,
62
+ public followupActions?: (user: User) => LoadAction[],
63
+ ) {}
64
+ }
65
+
66
+ export class StreamUserFail implements Action {
67
+ readonly type = UserActionTypes.STREAM_FAIL;
68
+ constructor(
69
+ public error: any,
70
+ public correlationId?: string,
71
+ ) {}
72
+ }
73
+
74
+ export class LoadUser implements Action {
75
+ readonly type = UserActionTypes.LOAD;
76
+ constructor(
77
+ // property, comparator, value
78
+ public queryParams: [string, string, any][],
79
+ public queryOptions: {
80
+ orderBy?: string | [string, string],
81
+ limit?: number,
82
+ startAt?: string,
83
+ startAfter?: string,
84
+ endAt?: string,
85
+ endBefore?: string,
86
+ },
87
+ public correlationId: string,
88
+ public followupActions?: (user: User) => LoadAction[],
89
+ ) {}
90
+ }
91
+
92
+ export class LoadUserSuccess implements Action {
93
+ readonly type = UserActionTypes.LOAD_SUCCESS;
94
+ constructor(
95
+ public queryParams: [string, string, any][],
96
+ public queryOptions: {
97
+ orderBy?: string | [string, string],
98
+ limit?: number,
99
+ startAt?: string,
100
+ startAfter?: string,
101
+ endAt?: string,
102
+ endBefore?: string,
103
+ },
104
+ public correlationId: string,
105
+ public followupActions?: (user: User) => LoadAction[],
106
+ ) {}
107
+ }
108
+
109
+ export class LoadUserFail implements Action {
110
+ readonly type = UserActionTypes.LOAD_FAIL;
111
+ constructor(
112
+ public error: any,
113
+ public correlationId?: string,
114
+ ) {}
115
+ }
116
+
117
+ export class AddUser implements Action {
118
+ readonly type = UserActionTypes.ADD;
119
+ constructor(
120
+ public user: User,
121
+ public correlationId?: string,
122
+ ) {}
123
+ }
124
+
125
+ export class AddUserSuccess implements Action {
126
+ readonly type = UserActionTypes.ADD_SUCCESS;
127
+ constructor(
128
+ public user: User,
129
+ public correlationId?: string,
130
+ ) {}
131
+ }
132
+
133
+ export class AddUserFail implements Action {
134
+ readonly type = UserActionTypes.ADD_FAIL;
135
+ constructor(
136
+ public error: any,
137
+ public correlationId?: string,
138
+ ) {}
139
+ }
140
+
141
+ export class UpdateUser implements Action {
142
+ readonly type = UserActionTypes.UPDATE;
143
+ constructor(
144
+ public __id: string,
145
+ public changes: Partial<User>,
146
+ public correlationId?: string,
147
+ ) { }
148
+ }
149
+
150
+ export class UpdateUserSuccess implements Action {
151
+ readonly type = UserActionTypes.UPDATE_SUCCESS;
152
+ constructor(
153
+ public __id: string,
154
+ public changes: Partial<User>,
155
+ public correlationId?: string,
156
+ ) {}
157
+ }
158
+
159
+ export class UpdateUserFail implements Action {
160
+ readonly type = UserActionTypes.UPDATE_FAIL;
161
+ constructor(
162
+ public error: any,
163
+ public correlationId?: string,
164
+ ) {}
165
+ }
166
+
167
+ export class UpsertUser implements Action {
168
+ readonly type = UserActionTypes.UPSERT;
169
+ constructor(
170
+ public user: User,
171
+ public correlationId?: string,
172
+ ) {}
173
+ }
174
+
175
+ export class UpsertUserSuccess implements Action {
176
+ readonly type = UserActionTypes.UPSERT_SUCCESS;
177
+ constructor(
178
+ public user: User,
179
+ public correlationId?: string,
180
+ ) {}
181
+ }
182
+
183
+ export class UpsertUserFail implements Action {
184
+ readonly type = UserActionTypes.UPSERT_FAIL;
185
+ constructor(
186
+ public error: any,
187
+ public correlationId?: string,
188
+ ) {}
189
+ }
190
+
191
+ export class RemoveUser implements Action {
192
+ readonly type = UserActionTypes.REMOVE;
193
+ constructor(
194
+ public __id: string,
195
+ public correlationId?: string,
196
+ ) { }
197
+ }
198
+
199
+ export class RemoveUserSuccess implements Action {
200
+ readonly type = UserActionTypes.REMOVE_SUCCESS;
201
+ constructor(
202
+ public __id: string,
203
+ public correlationId?: string,
204
+ ) {}
205
+ }
206
+
207
+ export class RemoveUserFail implements Action {
208
+ readonly type = UserActionTypes.REMOVE_FAIL;
209
+ constructor(
210
+ public error: any,
211
+ public correlationId?: string,
212
+ ) {}
213
+ }
214
+
215
+ export class LoadedUser implements Action {
216
+ readonly type = UserActionTypes.LOADED;
217
+ constructor(
218
+ public payload: User[],
219
+ public correlationId?: string,
220
+ ) {}
221
+ }
222
+
223
+ export class AddedUser implements Action {
224
+ readonly type = UserActionTypes.ADDED;
225
+ constructor(
226
+ public payload: User,
227
+ public correlationId?: string,
228
+ ) {}
229
+ }
230
+
231
+ export class ModifiedUser implements Action {
232
+ readonly type = UserActionTypes.MODIFIED;
233
+ constructor(
234
+ public payload: User,
235
+ public correlationId?: string,
236
+ ) {}
237
+ }
238
+
239
+ export class RemovedUser implements Action {
240
+ readonly type = UserActionTypes.REMOVED;
241
+ constructor(
242
+ public payload: User,
243
+ public correlationId?: string,
244
+ ) {}
245
+ }
246
+
247
+ export type UserActions =
248
+ StreamUser |
249
+ StreamUserSuccess |
250
+ StreamUserFail |
251
+ LoadUser |
252
+ LoadUserSuccess |
253
+ LoadUserFail |
254
+ AddUser |
255
+ AddUserSuccess |
256
+ AddUserFail |
257
+ UpdateUser |
258
+ UpdateUserSuccess |
259
+ UpdateUserFail |
260
+ UpsertUser |
261
+ UpsertUserSuccess |
262
+ UpsertUserFail |
263
+ RemoveUser |
264
+ RemoveUserSuccess |
265
+ RemoveUserFail |
266
+ LoadedUser |
267
+ AddedUser |
268
+ ModifiedUser |
269
+ RemovedUser;