@tech4good/angular-schematics 17.0.4 → 18.0.1

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 (223) hide show
  1. package/README.md +8 -0
  2. package/package.json +4 -4
  3. package/src/collection.json +0 -16
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +22 -8
  5. package/src/component/index.js +2 -45
  6. package/src/component/index.js.map +1 -1
  7. package/src/component/schema.json +0 -5
  8. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +12 -0
  9. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +1 -0
  10. package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +41 -0
  11. package/src/entity/index.js +29 -50
  12. package/src/entity/index.js.map +1 -1
  13. package/src/init/files/.eslintrc.json.template +1 -1
  14. package/src/init/files/.firebaserc.template +8 -0
  15. package/src/init/files/.github/workflows/angular-github-ci.yml.template +1 -1
  16. package/src/init/files/README.md.template +13 -10
  17. package/src/init/files/angular.json.template +18 -11
  18. package/src/init/files/package.json.template +29 -30
  19. package/src/init/files/src/app/admin/{waitlist/waitlist.animations.ts.template → admin-panel/admin-panel.animations.ts.template} +1 -1
  20. package/src/init/files/src/app/admin/{waitlist/waitlist.component.html.template → admin-panel/admin-panel.component.html.template} +3 -3
  21. package/src/init/files/src/app/admin/{waitlist/waitlist.component.scss.template → admin-panel/admin-panel.component.scss.template} +1 -1
  22. package/src/init/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +25 -0
  23. package/src/init/files/src/app/admin/admin-panel/admin-panel.component.ts.template +99 -0
  24. package/src/init/files/src/app/app.component.ts.template +12 -8
  25. package/src/init/files/src/app/app.config.ts.template +65 -0
  26. package/src/init/files/src/app/app.routes.ts.template +32 -0
  27. package/src/init/files/src/app/core/analytics/log.service.ts.template +122 -89
  28. package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +9 -17
  29. package/src/init/files/src/app/core/auth/auth.guard.ts.template +26 -23
  30. package/src/init/files/src/app/core/firebase/cached-listeners.service.ts.template +291 -0
  31. package/src/init/files/src/app/core/firebase/database.service.ts.template +56 -0
  32. package/src/init/files/src/app/core/firebase/firebase.mock.service.ts.template +276 -0
  33. package/src/init/files/src/app/core/firebase/firebase.service.ts.template +265 -215
  34. package/src/init/files/src/app/core/local-storage/session.service.ts.template +3 -4
  35. package/src/init/files/src/app/core/store/app.model.ts.template +19 -0
  36. package/src/init/files/src/app/core/store/app.store.ts.template +1074 -0
  37. package/src/init/files/src/app/core/store/auth/auth.mock.ts.template +20 -0
  38. package/src/init/files/src/app/core/store/auth/auth.store.ts.template +136 -0
  39. package/src/init/files/src/app/core/store/batch-write.firebase.service.ts.template +58 -0
  40. package/src/init/files/src/app/core/store/batch-write.mock.service.ts.template +105 -0
  41. package/src/init/files/src/app/core/store/batch-write.service.ts.template +126 -0
  42. package/src/init/files/src/app/core/store/user/user.mock.ts.template +24 -0
  43. package/src/init/files/src/app/core/store/user/user.model.ts.template +3 -6
  44. package/src/init/files/src/app/core/store/user/user.store.ts.template +41 -0
  45. package/src/init/files/src/app/core/store/user-context/user-context.mock.ts.template +24 -0
  46. package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +1 -0
  47. package/src/init/files/src/app/core/store/user-context/user-context.store.ts.template +41 -0
  48. package/src/init/files/src/app/core/utils/rand.utils.ts.template +13 -0
  49. package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.html.template +10 -14
  50. package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.scss.template +2 -2
  51. package/src/init/files/src/app/first-time/consent/consent.component.ts.template +95 -0
  52. package/src/init/files/src/app/first-time/early-access/early-access.animations.ts.template +4 -0
  53. package/src/init/files/src/app/first-time/early-access/early-access.component.html.template +65 -0
  54. package/src/init/files/src/app/{onboarding/waiting/waiting.component.scss.template → first-time/early-access/early-access.component.scss.template} +10 -3
  55. package/src/init/files/src/app/first-time/early-access/early-access.component.spec.ts.template +25 -0
  56. package/src/init/files/src/app/first-time/early-access/early-access.component.ts.template +254 -0
  57. package/src/init/files/src/app/first-time/early-access/early-access.model.ts.template +7 -0
  58. package/src/init/files/src/app/{general → first-time}/landing/landing.component.html.template +1 -1
  59. package/src/init/files/src/app/first-time/landing/landing.component.ts.template +44 -0
  60. package/src/init/files/src/app/first-time/login/login.component.html.template +10 -0
  61. package/src/init/files/src/app/first-time/login/login.component.ts.template +45 -0
  62. package/src/init/files/src/app/first-time/onboarding/onboarding.animations.ts.template +4 -0
  63. package/src/init/files/src/app/first-time/onboarding/onboarding.component.html.template +2 -0
  64. package/src/init/files/src/app/first-time/onboarding/onboarding.component.scss.template +5 -0
  65. package/src/init/files/src/app/{admin/waitlist/waitlist.component.spec.ts.template → first-time/onboarding/onboarding.component.spec.ts.template} +6 -6
  66. package/src/init/files/src/app/first-time/onboarding/onboarding.component.ts.template +41 -0
  67. package/src/init/files/src/app/main/home/home.component.html.template +6 -0
  68. package/src/init/files/src/app/{general → main}/home/home.component.scss.template +1 -0
  69. package/src/init/files/src/app/main/home/home.component.ts.template +55 -0
  70. package/src/init/files/src/app/shared/navbar/navbar.component.html.template +15 -0
  71. package/src/init/files/src/app/shared/navbar/navbar.component.scss.template +41 -0
  72. package/src/init/files/src/app/shared/navbar/navbar.component.spec.ts.template +25 -0
  73. package/src/init/files/src/app/shared/navbar/navbar.component.ts.template +40 -0
  74. package/src/init/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +9 -0
  75. package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.ts.template +17 -6
  76. package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.service.ts.template +2 -2
  77. package/src/init/files/src/assets/images/close-x.svg +3 -0
  78. package/src/init/files/src/environments/environment.prod.ts.template +6 -2
  79. package/src/init/files/src/environments/environment.ts.template +4 -2
  80. package/src/init/files/src/index.html.template +1 -1
  81. package/src/init/files/src/styles.scss.template +4 -0
  82. package/src/init/files/tsconfig.json.template +0 -1
  83. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +0 -26
  84. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +0 -48
  85. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
  86. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +0 -20
  87. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +0 -13
  88. package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +0 -4
  89. package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +0 -3
  90. package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +0 -5
  91. package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +0 -25
  92. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +0 -90
  93. package/src/container/index.d.ts +0 -2
  94. package/src/container/index.js +0 -127
  95. package/src/container/index.js.map +0 -1
  96. package/src/container/index_spec.d.ts +0 -1
  97. package/src/container/index_spec.js +0 -23
  98. package/src/container/index_spec.js.map +0 -1
  99. package/src/container/schema.json +0 -50
  100. package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -249
  101. package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
  102. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
  103. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
  104. package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
  105. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.actions.ts.template +0 -270
  106. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.effects.ts.template +0 -131
  107. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.model.ts.template +0 -3
  108. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +0 -13
  109. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +0 -51
  110. package/src/entity-in-example/files/__name@dasherize__/__name@dasherize__.service.ts.template +0 -50
  111. package/src/entity-in-example/index.d.ts +0 -2
  112. package/src/entity-in-example/index.js +0 -141
  113. package/src/entity-in-example/index.js.map +0 -1
  114. package/src/entity-in-example/index_spec.d.ts +0 -1
  115. package/src/entity-in-example/index_spec.js +0 -23
  116. package/src/entity-in-example/index_spec.js.map +0 -1
  117. package/src/entity-in-example/schema.json +0 -45
  118. package/src/init/files/CHANGELOG.md.template +0 -10
  119. package/src/init/files/src/app/admin/admin-routing.module.ts.template +0 -17
  120. package/src/init/files/src/app/admin/admin.module.spec.ts.template +0 -13
  121. package/src/init/files/src/app/admin/admin.module.ts.template +0 -28
  122. package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +0 -23
  123. package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +0 -50
  124. package/src/init/files/src/app/admin/waitlist/+state/waitlist.model.ts.template +0 -0
  125. package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +0 -39
  126. package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +0 -13
  127. package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +0 -141
  128. package/src/init/files/src/app/app-routing.module.ts.template +0 -26
  129. package/src/init/files/src/app/app.module.ts.template +0 -34
  130. package/src/init/files/src/app/core/core.module.ts.template +0 -75
  131. package/src/init/files/src/app/core/setup/firebase-setup.ts.template +0 -25
  132. package/src/init/files/src/app/core/setup/module-import-guard.ts.template +0 -5
  133. package/src/init/files/src/app/core/snackbar/snackbar.actions.ts.template +0 -24
  134. package/src/init/files/src/app/core/snackbar/snackbar.effects.ts.template +0 -41
  135. package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +0 -249
  136. package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +0 -131
  137. package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +0 -8
  138. package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +0 -13
  139. package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +0 -51
  140. package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +0 -50
  141. package/src/init/files/src/app/core/store/app.actions.ts.template +0 -92
  142. package/src/init/files/src/app/core/store/app.effects.ts.template +0 -175
  143. package/src/init/files/src/app/core/store/app.reducer.ts.template +0 -36
  144. package/src/init/files/src/app/core/store/app.selectors.ts.template +0 -42
  145. package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +0 -77
  146. package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +0 -163
  147. package/src/init/files/src/app/core/store/auth/auth.reducer.spec.ts.template +0 -13
  148. package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +0 -26
  149. package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +0 -25
  150. package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +0 -405
  151. package/src/init/files/src/app/core/store/cached-selectors.service.ts.template +0 -376
  152. package/src/init/files/src/app/core/store/effects.helpers.ts.template +0 -66
  153. package/src/init/files/src/app/core/store/user/user.actions.ts.template +0 -248
  154. package/src/init/files/src/app/core/store/user/user.effects.ts.template +0 -148
  155. package/src/init/files/src/app/core/store/user/user.reducer.spec.ts.template +0 -13
  156. package/src/init/files/src/app/core/store/user/user.reducer.ts.template +0 -50
  157. package/src/init/files/src/app/core/store/user/user.service.ts.template +0 -50
  158. package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +0 -248
  159. package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +0 -131
  160. package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +0 -13
  161. package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +0 -51
  162. package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +0 -50
  163. package/src/init/files/src/app/core/utils/string-case.utils.ts.template +0 -96
  164. package/src/init/files/src/app/general/general-routing.module.ts.template +0 -25
  165. package/src/init/files/src/app/general/general.module.spec.ts.template +0 -13
  166. package/src/init/files/src/app/general/general.module.ts.template +0 -36
  167. package/src/init/files/src/app/general/home/+state/home.actions.ts.template +0 -26
  168. package/src/init/files/src/app/general/home/+state/home.effects.ts.template +0 -48
  169. package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
  170. package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +0 -20
  171. package/src/init/files/src/app/general/home/+state/home.state.ts.template +0 -13
  172. package/src/init/files/src/app/general/home/home.component.html.template +0 -5
  173. package/src/init/files/src/app/general/home/home.component.ts.template +0 -88
  174. package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +0 -26
  175. package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +0 -48
  176. package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
  177. package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +0 -20
  178. package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +0 -13
  179. package/src/init/files/src/app/general/landing/landing.component.ts.template +0 -98
  180. package/src/init/files/src/app/general/login/login.component.html.template +0 -11
  181. package/src/init/files/src/app/general/login/login.component.ts.template +0 -80
  182. package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +0 -23
  183. package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +0 -47
  184. package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
  185. package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +0 -20
  186. package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +0 -13
  187. package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +0 -151
  188. package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +0 -19
  189. package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +0 -13
  190. package/src/init/files/src/app/onboarding/onboarding.module.ts.template +0 -32
  191. package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +0 -26
  192. package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +0 -52
  193. package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +0 -9
  194. package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +0 -42
  195. package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +0 -13
  196. package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +0 -4
  197. package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +0 -57
  198. package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +0 -25
  199. package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +0 -281
  200. package/src/init/files/src/app/shared/components/redeployment-warning/redeployment-warning.component.html.template +0 -10
  201. package/src/init/files/src/app/shared/shared.module.ts.template +0 -87
  202. package/src/init/files/src/main.ts.template +0 -12
  203. package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +0 -15
  204. package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +0 -13
  205. package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +0 -24
  206. package/src/module/index.d.ts +0 -2
  207. package/src/module/index.js +0 -97
  208. package/src/module/index.js.map +0 -1
  209. package/src/module/index_spec.d.ts +0 -1
  210. package/src/module/index_spec.js +0 -23
  211. package/src/module/index_spec.js.map +0 -1
  212. package/src/module/schema.json +0 -38
  213. /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.animations.ts.template +0 -0
  214. /package/src/init/files/src/app/{onboarding → first-time}/consent/consent.component.spec.ts.template +0 -0
  215. /package/src/init/files/src/app/{general → first-time}/landing/landing.animations.ts.template +0 -0
  216. /package/src/init/files/src/app/{general → first-time}/landing/landing.component.scss.template +0 -0
  217. /package/src/init/files/src/app/{general → first-time}/landing/landing.component.spec.ts.template +0 -0
  218. /package/src/init/files/src/app/{general → first-time}/login/login.component.scss.template +0 -0
  219. /package/src/init/files/src/app/{general → first-time}/login/login.component.spec.ts.template +0 -0
  220. /package/src/init/files/src/app/{general → main}/home/home.animations.ts.template +0 -0
  221. /package/src/init/files/src/app/{general → main}/home/home.component.spec.ts.template +0 -0
  222. /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.scss.template +0 -0
  223. /package/src/init/files/src/app/shared/{components/redeployment-warning → redeployment-warning}/redeployment-warning.component.spec.ts.template +0 -0
@@ -1,148 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Action } from '@ngrx/store';
3
- import { Actions, createEffect, ofType } from '@ngrx/effects';
4
- import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
5
- import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
6
- import { FirebaseService } from '../../firebase/firebase.service';
7
- import { CachedLoadConnectionsService } from '../cached-load-connections.service';
8
- import { Store, select } from '@ngrx/store';
9
- import * as fromStore from '../../store/app.reducer';
10
- import * as fromAuth from '../../store/auth/auth.reducer';
11
- import { UpdateAppState } from '../../store/app-state/app-state.actions';
12
-
13
- import { User, AccessState } from './user.model';
14
- import { UserActionTypes, UserActions,
15
- AddedUser, RemovedUser,
16
- StreamUser, StreamUserSuccess, StreamUserFail,
17
- LoadUser, LoadUserSuccess, LoadUserFail,
18
- AddUser, AddUserSuccess, AddUserFail,
19
- UpdateUser, UpdateUserSuccess, UpdateUserFail,
20
- RemoveUser, RemoveUserSuccess, RemoveUserFail } from './user.actions';
21
-
22
- @Injectable()
23
- export class UserEffects {
24
- /** Process the stream action to create firebase connections. */
25
- stream$: Observable<Action> = createEffect(
26
- () => this.actions$.pipe(
27
- ofType<StreamUser>(UserActionTypes.STREAM),
28
- mergeMap((action: StreamUser) => {
29
- const connection = this.clc.processLoadAction(action);
30
- return connection.loadStream.pipe(
31
- take(1),
32
- map(() => new StreamUserSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
33
- catchError((error) => of(new StreamUserFail(error, action.correlationId))),
34
- );
35
- }),
36
- ),
37
- );
38
-
39
- /** Process the load action to create firebase connections. */
40
- load$: Observable<Action> = createEffect(
41
- () => this.actions$.pipe(
42
- ofType<LoadUser>(UserActionTypes.LOAD),
43
- mergeMap((action: LoadUser) => {
44
- const connection = this.clc.processLoadAction(action);
45
- return connection.loadStream.pipe(
46
- take(1),
47
- map(() => new LoadUserSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
48
- catchError((error) => of(new LoadUserFail(error, action.correlationId))),
49
- );
50
- }),
51
- ),
52
- );
53
-
54
- /** Process the add action to update database and initiate callbacks. */
55
- add$: Observable<Action> = createEffect(
56
- () => this.actions$.pipe(
57
- ofType<AddUser>(UserActionTypes.ADD),
58
- mergeMap((action: AddUser) => {
59
- if (action.options && action.options.optimistic) {
60
- return merge(
61
- of(new AddedUser(action.user, action.correlationId)),
62
- this.db.addEntity('users', action.user).pipe(
63
- mergeMap(() => merge(
64
- of(new AddUserSuccess(action.user, action.correlationId)),
65
- this.actionsOnAdd(action),
66
- )),
67
- catchError((error) => merge(
68
- of(new AddUserFail(error, action.correlationId)),
69
- of(new RemovedUser(action.user, action.correlationId)),
70
- )),
71
- ),
72
- );
73
- } else {
74
- return this.db.addEntity('users', action.user).pipe(
75
- mergeMap(() => merge(
76
- of(new AddUserSuccess(action.user, action.correlationId)),
77
- this.actionsOnAdd(action),
78
- )),
79
- catchError((error) => of(new AddUserFail(error, action.correlationId))),
80
- );
81
- }
82
- }),
83
- ),
84
- );
85
-
86
- /** Process the update action to update database and initiate callbacks. */
87
- update$: Observable<Action> = createEffect(
88
- () => this.actions$.pipe(
89
- ofType<UpdateUser>(UserActionTypes.UPDATE),
90
- mergeMap((action: UpdateUser) => {
91
- return this.db.updateEntity('users', action.__id, action.changes).pipe(
92
- mergeMap(() => merge(
93
- of(new UpdateUserSuccess(action.__id, action.changes, action.correlationId)),
94
- this.actionsOnUpdate(action),
95
- )),
96
- catchError((error) => of(new UpdateUserFail(error, action.correlationId))),
97
- );
98
- }),
99
- ),
100
- );
101
-
102
- /** Process the remove action to update database and initiate callbacks. */
103
- remove$: Observable<Action> = createEffect(
104
- () => this.actions$.pipe(
105
- ofType<RemoveUser>(UserActionTypes.REMOVE),
106
- mergeMap((action: RemoveUser) => {
107
- return this.db.removeEntity('users', action.__id).pipe(
108
- mergeMap(() => merge(
109
- of(new RemoveUserSuccess(action.__id, action.correlationId)),
110
- this.actionsOnRemove(action),
111
- )),
112
- catchError((error) => of(new RemoveUserFail(error, action.correlationId))),
113
- );
114
- }),
115
- ),
116
- );
117
-
118
- actionsOnAdd(action: AddUser): Observable<Action> {
119
- return EMPTY;
120
- }
121
-
122
- actionsOnUpdate(action: UpdateUser): Observable<Action> {
123
- if (Object.prototype.hasOwnProperty.call(action.changes, 'accessState')) {
124
- // TODO: inefficient since we're querying all users. replace with count query
125
- // once added to library
126
- return this.db.queryListOnce('users', [['accessState', '==', AccessState.WAITING]]).pipe(
127
- mergeMap((users: User[]) => {
128
- return [new UpdateAppState('app', {
129
- _totalWaiting: users.length,
130
- }, action.correlationId)];
131
- }),
132
- );
133
- } else {
134
- return EMPTY;
135
- }
136
- }
137
-
138
- actionsOnRemove(action: RemoveUser): Observable<Action> {
139
- return EMPTY;
140
- }
141
-
142
- constructor(
143
- private store: Store<fromStore.State>,
144
- private actions$: Actions,
145
- private db: FirebaseService,
146
- private clc: CachedLoadConnectionsService,
147
- ) {}
148
- }
@@ -1,13 +0,0 @@
1
- import { reducer, initialState } from './user.reducer';
2
-
3
- describe('User Reducer', () => {
4
- describe('unknown action', () => {
5
- it('should return the initial state', () => {
6
- const action = {} as any;
7
-
8
- const result = reducer(initialState, action);
9
-
10
- expect(result).toBe(initialState);
11
- });
12
- });
13
- });
@@ -1,50 +0,0 @@
1
- import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
2
- import { User } from './user.model';
3
- import { UserActions, UserActionTypes } from './user.actions';
4
- import { createFeatureSelector } from '@ngrx/store';
5
-
6
- export interface State extends EntityState<User> {
7
- // additional entities state properties
8
- }
9
-
10
- export const adapter: EntityAdapter<User> = createEntityAdapter<User>({
11
- selectId: (user: User) => user.__id,
12
- sortComparer: false,
13
- });
14
-
15
- export const initialState: State = adapter.getInitialState({
16
- // additional entity state properties
17
- });
18
-
19
- export function reducer(
20
- state: State = initialState,
21
- action: UserActions) {
22
- switch (action.type) {
23
- case UserActionTypes.ADDED:
24
- return adapter.upsertOne(action.payload, state);
25
-
26
- case UserActionTypes.LOADED:
27
- return adapter.upsertMany(action.payload, state);
28
-
29
- case UserActionTypes.MODIFIED:
30
- return adapter.updateOne({
31
- id: action.payload.__id,
32
- changes: action.payload,
33
- }, state);
34
-
35
- case UserActionTypes.REMOVED:
36
- return adapter.removeOne(action.payload.__id, state);
37
-
38
- default:
39
- return state;
40
- }
41
- }
42
-
43
- export const getUserState = createFeatureSelector<State>('user');
44
-
45
- export const {
46
- selectIds,
47
- selectEntities,
48
- selectAll,
49
- selectTotal,
50
- } = adapter.getSelectors(getUserState);
@@ -1,50 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Observable } from 'rxjs';
3
- import { CachedSelectorsService } from '../cached-selectors.service';
4
- import { FirebaseService } from '../../firebase/firebase.service';
5
- import { User } from './user.model';
6
-
7
- @Injectable({
8
- providedIn: 'root',
9
- })
10
- export class UserService {
11
- constructor(
12
- private cs: CachedSelectorsService,
13
- private db: FirebaseService,
14
- ) { }
15
-
16
- /** Select a user from the store. */
17
- public selectUser = <T extends User>(
18
- id: string,
19
- correlationId: string,
20
- childrenFn?: (e: User) => { [index: string]: Observable<any> },
21
- ): Observable<T> => {
22
- return this.cs.selectEntityObj<User, T>('user', id, correlationId, childrenFn);
23
- };
24
-
25
- /** Select users from the store. */
26
- public selectUsers = <T extends User>(
27
- queryParams: [string, string, any][],
28
- correlationId: string,
29
- childrenFn?: (e: User) => { [index: string]: Observable<any> },
30
- ): Observable<Array<T>> => {
31
- return this.cs.selectEntityList<User, T>('user', queryParams, correlationId, childrenFn);
32
- };
33
-
34
- /** Get a user directly from the database. */
35
- public getUser = <T extends User>(
36
- id: string,
37
- childrenFn?: (e: User) => { [index: string]: Observable<any> },
38
- ): Observable<T> => {
39
- return this.db.queryObjOnce<User, T>('users', id, childrenFn);
40
- };
41
-
42
- /** Get users directly from the database. */
43
- public getUsers = <T extends User>(
44
- queryParams: [string, string, any][],
45
- queryOptions?: { [index: string]: any },
46
- childrenFn?: (e: User) => { [index: string]: Observable<any> },
47
- ): Observable<Array<T>> => {
48
- return this.db.queryListOnce<User, T>('users', queryParams, queryOptions, childrenFn);
49
- };
50
- }
@@ -1,248 +0,0 @@
1
- import { Action } from '@ngrx/store';
2
- import { LoadAction } from '../app.actions';
3
- import { UserContext } from './user-context.model';
4
-
5
- export enum UserContextActionTypes {
6
- STREAM = '[UserContext] stream userContext',
7
- STREAM_SUCCESS = '[UserContext] stream userContext success',
8
- STREAM_FAIL = '[UserContext] stream userContext fail',
9
- LOAD = '[UserContext] load userContext',
10
- LOAD_SUCCESS = '[UserContext] load userContext success',
11
- LOAD_FAIL = '[UserContext] load userContext fail',
12
- ADD = '[UserContext] add userContext',
13
- ADD_SUCCESS = '[UserContext] add userContext success',
14
- ADD_FAIL = '[UserContext] add userContext fail',
15
- UPDATE = '[UserContext] update userContext',
16
- UPDATE_SUCCESS = '[UserContext] update userContext success',
17
- UPDATE_FAIL = '[UserContext] update userContext fail',
18
- REMOVE = '[UserContext] remove userContext',
19
- REMOVE_SUCCESS = '[UserContext] remove userContext success',
20
- REMOVE_FAIL = '[UserContext] remove userContext fail',
21
- LOADED = '[UserContext] loaded',
22
- ADDED = '[UserContext] added',
23
- MODIFIED = '[UserContext] modified',
24
- REMOVED = '[UserContext] removed',
25
- }
26
-
27
- // See Firebase Docs for current constraints on valid queries
28
- export class StreamUserContext implements Action {
29
- readonly type = UserContextActionTypes.STREAM;
30
- constructor(
31
- // property, comparator, value
32
- public queryParams: [string, string, any][],
33
- public queryOptions: {
34
- orderBy?: string | [string, string],
35
- limit?: number,
36
- startAt?: string,
37
- startAfter?: string,
38
- endAt?: string,
39
- endBefore?: string,
40
- },
41
- public correlationId: string,
42
- public followupActions?: (userContext: UserContext) => LoadAction[],
43
- ) {}
44
- }
45
-
46
- export class StreamUserContextSuccess implements Action {
47
- readonly type = UserContextActionTypes.STREAM_SUCCESS;
48
- constructor(
49
- public queryParams: [string, string, any][],
50
- public queryOptions: {
51
- orderBy?: string | [string, string],
52
- limit?: number,
53
- startAt?: string,
54
- startAfter?: string,
55
- endAt?: string,
56
- endBefore?: string,
57
- },
58
- public correlationId: string,
59
- public followupActions?: (userContext: UserContext) => LoadAction[],
60
- ) {}
61
- }
62
-
63
- export class StreamUserContextFail implements Action {
64
- readonly type = UserContextActionTypes.STREAM_FAIL;
65
- constructor(
66
- public error: any,
67
- public correlationId?: string,
68
- ) {}
69
- }
70
-
71
- export class LoadUserContext implements Action {
72
- readonly type = UserContextActionTypes.LOAD;
73
- constructor(
74
- // property, comparator, value
75
- public queryParams: [string, string, any][],
76
- public queryOptions: {
77
- orderBy?: string | [string, string],
78
- limit?: number,
79
- startAt?: string,
80
- startAfter?: string,
81
- endAt?: string,
82
- endBefore?: string,
83
- },
84
- public correlationId: string,
85
- public followupActions?: (userContext: UserContext) => LoadAction[],
86
- ) {}
87
- }
88
-
89
- export class LoadUserContextSuccess implements Action {
90
- readonly type = UserContextActionTypes.LOAD_SUCCESS;
91
- constructor(
92
- public queryParams: [string, string, any][],
93
- public queryOptions: {
94
- orderBy?: string | [string, string],
95
- limit?: number,
96
- startAt?: string,
97
- startAfter?: string,
98
- endAt?: string,
99
- endBefore?: string,
100
- },
101
- public correlationId: string,
102
- public followupActions?: (userContext: UserContext) => LoadAction[],
103
- ) {}
104
- }
105
-
106
- export class LoadUserContextFail implements Action {
107
- readonly type = UserContextActionTypes.LOAD_FAIL;
108
- constructor(
109
- public error: any,
110
- public correlationId?: string,
111
- ) {}
112
- }
113
-
114
- export class AddUserContext implements Action {
115
- readonly type = UserContextActionTypes.ADD;
116
- constructor(
117
- public userContext: UserContext,
118
- public correlationId?: string,
119
- public options?: {
120
- optimistic?: boolean,
121
- },
122
- ) {}
123
- }
124
-
125
- export class AddUserContextSuccess implements Action {
126
- readonly type = UserContextActionTypes.ADD_SUCCESS;
127
- constructor(
128
- public userContext: UserContext,
129
- public correlationId?: string,
130
- public options?: {
131
- optimistic?: boolean,
132
- },
133
- ) {}
134
- }
135
-
136
- export class AddUserContextFail implements Action {
137
- readonly type = UserContextActionTypes.ADD_FAIL;
138
- constructor(
139
- public error: any,
140
- public correlationId?: string,
141
- public options?: {
142
- optimistic?: boolean,
143
- },
144
- ) {}
145
- }
146
-
147
- export class UpdateUserContext implements Action {
148
- readonly type = UserContextActionTypes.UPDATE;
149
- constructor(
150
- public __id: string,
151
- public changes: Partial<UserContext>,
152
- public correlationId?: string,
153
- ) { }
154
- }
155
-
156
- export class UpdateUserContextSuccess implements Action {
157
- readonly type = UserContextActionTypes.UPDATE_SUCCESS;
158
- constructor(
159
- public __id: string,
160
- public changes: Partial<UserContext>,
161
- public correlationId?: string,
162
- ) {}
163
- }
164
-
165
- export class UpdateUserContextFail implements Action {
166
- readonly type = UserContextActionTypes.UPDATE_FAIL;
167
- constructor(
168
- public error: any,
169
- public correlationId?: string,
170
- ) {}
171
- }
172
-
173
- export class RemoveUserContext implements Action {
174
- readonly type = UserContextActionTypes.REMOVE;
175
- constructor(
176
- public __id: string,
177
- public correlationId?: string,
178
- ) { }
179
- }
180
-
181
- export class RemoveUserContextSuccess implements Action {
182
- readonly type = UserContextActionTypes.REMOVE_SUCCESS;
183
- constructor(
184
- public __id: string,
185
- public correlationId?: string,
186
- ) {}
187
- }
188
-
189
- export class RemoveUserContextFail implements Action {
190
- readonly type = UserContextActionTypes.REMOVE_FAIL;
191
- constructor(
192
- public error: any,
193
- public correlationId?: string,
194
- ) {}
195
- }
196
-
197
- export class LoadedUserContext implements Action {
198
- readonly type = UserContextActionTypes.LOADED;
199
- constructor(
200
- public payload: UserContext[],
201
- public correlationId?: string,
202
- ) {}
203
- }
204
-
205
- export class AddedUserContext implements Action {
206
- readonly type = UserContextActionTypes.ADDED;
207
- constructor(
208
- public payload: UserContext,
209
- public correlationId?: string,
210
- ) {}
211
- }
212
-
213
- export class ModifiedUserContext implements Action {
214
- readonly type = UserContextActionTypes.MODIFIED;
215
- constructor(
216
- public payload: UserContext,
217
- public correlationId?: string,
218
- ) {}
219
- }
220
-
221
- export class RemovedUserContext implements Action {
222
- readonly type = UserContextActionTypes.REMOVED;
223
- constructor(
224
- public payload: UserContext,
225
- public correlationId?: string,
226
- ) {}
227
- }
228
-
229
- export type UserContextActions =
230
- StreamUserContext |
231
- StreamUserContextSuccess |
232
- StreamUserContextFail |
233
- LoadUserContext |
234
- LoadUserContextSuccess |
235
- LoadUserContextFail |
236
- AddUserContext |
237
- AddUserContextSuccess |
238
- AddUserContextFail |
239
- UpdateUserContext |
240
- UpdateUserContextSuccess |
241
- UpdateUserContextFail |
242
- RemoveUserContext |
243
- RemoveUserContextSuccess |
244
- RemoveUserContextFail |
245
- LoadedUserContext |
246
- AddedUserContext |
247
- ModifiedUserContext |
248
- RemovedUserContext;
@@ -1,131 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Action } from '@ngrx/store';
3
- import { Actions, createEffect, ofType } from '@ngrx/effects';
4
- import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
5
- import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
6
- import { FirebaseService } from '../../firebase/firebase.service';
7
- import { CachedLoadConnectionsService } from '../cached-load-connections.service';
8
-
9
- import { UserContext } from './user-context.model';
10
- import { UserContextActionTypes, UserContextActions,
11
- AddedUserContext, RemovedUserContext,
12
- StreamUserContext, StreamUserContextSuccess, StreamUserContextFail,
13
- LoadUserContext, LoadUserContextSuccess, LoadUserContextFail,
14
- AddUserContext, AddUserContextSuccess, AddUserContextFail,
15
- UpdateUserContext, UpdateUserContextSuccess, UpdateUserContextFail,
16
- RemoveUserContext, RemoveUserContextSuccess, RemoveUserContextFail } from './user-context.actions';
17
-
18
- @Injectable()
19
- export class UserContextEffects {
20
- /** Process the stream action to create firebase connections. */
21
- stream$: Observable<Action> = createEffect(
22
- () => this.actions$.pipe(
23
- ofType<StreamUserContext>(UserContextActionTypes.STREAM),
24
- mergeMap((action: StreamUserContext) => {
25
- const connection = this.clc.processLoadAction(action);
26
- return connection.loadStream.pipe(
27
- take(1),
28
- map(() => new StreamUserContextSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
29
- catchError((error) => of(new StreamUserContextFail(error, action.correlationId))),
30
- );
31
- }),
32
- ),
33
- );
34
-
35
- /** Process the load action to create firebase connections. */
36
- load$: Observable<Action> = createEffect(
37
- () => this.actions$.pipe(
38
- ofType<LoadUserContext>(UserContextActionTypes.LOAD),
39
- mergeMap((action: LoadUserContext) => {
40
- const connection = this.clc.processLoadAction(action);
41
- return connection.loadStream.pipe(
42
- take(1),
43
- map(() => new LoadUserContextSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
44
- catchError((error) => of(new LoadUserContextFail(error, action.correlationId))),
45
- );
46
- }),
47
- ),
48
- );
49
-
50
- /** Process the add action to update database and initiate callbacks. */
51
- add$: Observable<Action> = createEffect(
52
- () => this.actions$.pipe(
53
- ofType<AddUserContext>(UserContextActionTypes.ADD),
54
- mergeMap((action: AddUserContext) => {
55
- if (action.options && action.options.optimistic) {
56
- return merge(
57
- of(new AddedUserContext(action.userContext, action.correlationId)),
58
- this.db.addEntity('userContexts', action.userContext).pipe(
59
- mergeMap(() => merge(
60
- of(new AddUserContextSuccess(action.userContext, action.correlationId)),
61
- this.actionsOnAdd(action),
62
- )),
63
- catchError((error) => merge(
64
- of(new AddUserContextFail(error, action.correlationId)),
65
- of(new RemovedUserContext(action.userContext, action.correlationId)),
66
- )),
67
- ),
68
- );
69
- } else {
70
- return this.db.addEntity('userContexts', action.userContext).pipe(
71
- mergeMap(() => merge(
72
- of(new AddUserContextSuccess(action.userContext, action.correlationId)),
73
- this.actionsOnAdd(action),
74
- )),
75
- catchError((error) => of(new AddUserContextFail(error, action.correlationId))),
76
- );
77
- }
78
- }),
79
- ),
80
- );
81
-
82
- /** Process the update action to update database and initiate callbacks. */
83
- update$: Observable<Action> = createEffect(
84
- () => this.actions$.pipe(
85
- ofType<UpdateUserContext>(UserContextActionTypes.UPDATE),
86
- mergeMap((action: UpdateUserContext) => {
87
- return this.db.updateEntity('userContexts', action.__id, action.changes).pipe(
88
- mergeMap(() => merge(
89
- of(new UpdateUserContextSuccess(action.__id, action.changes, action.correlationId)),
90
- this.actionsOnUpdate(action),
91
- )),
92
- catchError((error) => of(new UpdateUserContextFail(error, action.correlationId))),
93
- );
94
- }),
95
- ),
96
- );
97
-
98
- /** Process the remove action to update database and initiate callbacks. */
99
- remove$: Observable<Action> = createEffect(
100
- () => this.actions$.pipe(
101
- ofType<RemoveUserContext>(UserContextActionTypes.REMOVE),
102
- mergeMap((action: RemoveUserContext) => {
103
- return this.db.removeEntity('userContexts', action.__id).pipe(
104
- mergeMap(() => merge(
105
- of(new RemoveUserContextSuccess(action.__id, action.correlationId)),
106
- this.actionsOnRemove(action),
107
- )),
108
- catchError((error) => of(new RemoveUserContextFail(error, action.correlationId))),
109
- );
110
- }),
111
- ),
112
- );
113
-
114
- actionsOnAdd(action: AddUserContext): Observable<Action> {
115
- return EMPTY;
116
- }
117
-
118
- actionsOnUpdate(action: UpdateUserContext): Observable<Action> {
119
- return EMPTY;
120
- }
121
-
122
- actionsOnRemove(action: RemoveUserContext): Observable<Action> {
123
- return EMPTY;
124
- }
125
-
126
- constructor(
127
- private actions$: Actions,
128
- private db: FirebaseService,
129
- private clc: CachedLoadConnectionsService,
130
- ) {}
131
- }
@@ -1,13 +0,0 @@
1
- import { reducer, initialState } from './user-context.reducer';
2
-
3
- describe('UserContext Reducer', () => {
4
- describe('unknown action', () => {
5
- it('should return the initial state', () => {
6
- const action = {} as any;
7
-
8
- const result = reducer(initialState, action);
9
-
10
- expect(result).toBe(initialState);
11
- });
12
- });
13
- });