@tech4good/angular-schematics 21.6.0 → 21.7.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 (229) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +266 -1
  3. package/package.json +34 -7
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
  5. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
  6. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +14 -6
  7. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +12 -6
  8. package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
  9. package/src/entity/index.js +4 -49
  10. package/src/entity/index.js.map +1 -1
  11. package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
  12. package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
  13. package/src/ng-add/files/.gitignore.template +3 -0
  14. package/src/ng-add/files/analytics/datasets.js.template +206 -0
  15. package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
  16. package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
  17. package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
  18. package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
  19. package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
  20. package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
  21. package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
  22. package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
  23. package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
  24. package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
  25. package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
  26. package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
  27. package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
  28. package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
  29. package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
  30. package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
  31. package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
  32. package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
  33. package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
  34. package/src/ng-add/files/analytics/server/server.js.template +212 -0
  35. package/src/ng-add/files/angular.json.template +80 -1
  36. package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
  37. package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
  38. package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
  39. package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
  40. package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
  41. package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
  42. package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
  43. package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
  44. package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
  45. package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
  46. package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
  47. package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
  48. package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
  49. package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
  50. package/src/ng-add/files/docs-infra/authentication-architecture.md.template +54 -24
  51. package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
  52. package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
  53. package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +108 -29
  54. package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
  55. package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
  56. package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
  57. package/src/ng-add/files/eslint.config.js.template +22 -3
  58. package/src/ng-add/files/functions/package.json.template +1 -0
  59. package/src/ng-add/files/functions/src/email.ts.template +23 -0
  60. package/src/ng-add/files/jest.config.ts.template +3 -2
  61. package/src/ng-add/files/package.json.template +39 -16
  62. package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
  63. package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
  64. package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
  65. package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
  66. package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
  67. package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
  68. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
  69. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
  70. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
  71. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
  72. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
  73. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
  74. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
  75. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
  76. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
  77. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
  78. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
  79. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
  80. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
  81. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
  82. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
  83. package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
  84. package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
  85. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
  86. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
  87. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
  88. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
  89. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
  90. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
  91. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
  92. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
  93. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
  94. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
  95. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
  96. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
  97. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
  98. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
  99. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
  100. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
  101. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
  102. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
  103. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
  104. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
  105. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
  106. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
  107. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
  108. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
  109. package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
  110. package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
  111. package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
  112. package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
  113. package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
  114. package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
  115. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +4 -5
  116. package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
  117. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
  118. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
  119. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +8 -10
  120. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
  121. package/src/ng-add/files/src/app/app.component.html.template +1 -1
  122. package/src/ng-add/files/src/app/app.component.scss.template +1 -1
  123. package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
  124. package/src/ng-add/files/src/app/app.component.ts.template +1 -2
  125. package/src/ng-add/files/src/app/app.config.ts.template +21 -15
  126. package/src/ng-add/files/src/app/auth-routing.spec.ts.template +4 -5
  127. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
  128. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
  129. package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
  130. package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
  131. package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +9 -23
  132. package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +3 -14
  133. package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
  134. package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
  135. package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
  136. package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
  137. package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
  138. package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +19 -67
  139. package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +102 -12
  140. package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +32 -237
  141. package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +17 -12
  142. package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +6 -7
  143. package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
  144. package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
  145. package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
  146. package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
  147. package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
  148. package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +5 -6
  149. package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
  150. package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
  151. package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
  152. package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
  153. package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
  154. package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
  155. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +15 -15
  156. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +11 -3
  157. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
  158. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
  159. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
  160. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
  161. package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
  162. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +17 -1
  163. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +15 -0
  164. package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +4 -5
  165. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +15 -0
  166. package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +2 -0
  167. package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +21 -3
  168. package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +26 -0
  169. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
  170. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
  171. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +2 -2
  172. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +2 -2
  173. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +4 -4
  174. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +2 -2
  175. package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
  176. package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -1
  177. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +4 -4
  178. package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +2 -2
  179. package/src/ng-add/files/tsconfig.spec.json.template +3 -1
  180. package/src/ng-add/index.js +7 -0
  181. package/src/ng-add/index.js.map +1 -1
  182. package/src/shared/entity-registry.d.ts +8 -0
  183. package/src/shared/entity-registry.js +28 -0
  184. package/src/shared/entity-registry.js.map +1 -0
  185. package/.agents/skills/publish-npm/SKILL.md +0 -37
  186. package/.agents/skills/publish-npm/eval.yaml +0 -32
  187. package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
  188. package/.husky/commit-msg +0 -1
  189. package/.husky/pre-commit +0 -1
  190. package/.t4g/agent-memory.db +0 -0
  191. package/src/component/index_spec.d.ts +0 -1
  192. package/src/component/index_spec.js +0 -68
  193. package/src/component/index_spec.js.map +0 -1
  194. package/src/entity/index_spec.d.ts +0 -1
  195. package/src/entity/index_spec.js +0 -153
  196. package/src/entity/index_spec.js.map +0 -1
  197. package/src/guard/index_spec.d.ts +0 -1
  198. package/src/guard/index_spec.js +0 -64
  199. package/src/guard/index_spec.js.map +0 -1
  200. package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
  201. package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
  202. package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -500
  203. package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -73
  204. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +0 -59
  205. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +0 -147
  206. package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -453
  207. package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +0 -116
  208. package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -639
  209. package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
  210. package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
  211. package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
  212. package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
  213. package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
  214. package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
  215. package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
  216. package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
  217. package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1320
  218. package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
  219. package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
  220. package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
  221. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
  222. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
  223. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
  224. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
  225. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
  226. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
  227. package/src/ng-add/index_spec.d.ts +0 -1
  228. package/src/ng-add/index_spec.js +0 -108
  229. package/src/ng-add/index_spec.js.map +0 -1
@@ -1,104 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { signalStore, withState } from '@ngrx/signals';
3
- import { withEntitiesAndSelectMethods, withEntitiesAndDBMethods } from '../store/app.store';
4
- import { DATABASE_SERVICE } from './database.service';
5
- import { provideFirebaseMock } from './firebase.mock.service';
6
- import { MOCK_SIMULATION_USERS } from './simulation.mock';
7
- import { LoggingService } from '../logging/logging.service';
8
- import { Timestamp } from '@angular/fire/firestore';
9
-
10
- export const UserStore = signalStore(
11
- { providedIn: 'root' },
12
- withState({}),
13
- withEntitiesAndDBMethods<any>('users'),
14
- );
15
-
16
- describe('Simulation for Load Bucketing Strategy', () => {
17
- let currentTime = 0;
18
- let timestampSpy: jest.SpyInstance;
19
-
20
- beforeEach(() => {
21
- // Spy on Firestore Timestamp.now() to control the time without breaking JS setTimeouts
22
- timestampSpy = jest.spyOn(Timestamp, 'now').mockImplementation(() => {
23
- return Timestamp.fromMillis(currentTime);
24
- });
25
- });
26
-
27
- afterEach(() => {
28
- timestampSpy.mockRestore();
29
- });
30
-
31
- it('runs the load time bucketing simulation', async () => {
32
- TestBed.configureTestingModule({
33
- providers: [
34
- UserStore,
35
- provideFirebaseMock({ users: MOCK_SIMULATION_USERS }),
36
- ],
37
- });
38
-
39
- const userStore = TestBed.inject(UserStore) as any;
40
- const db = TestBed.inject(DATABASE_SERVICE) as any;
41
-
42
- const logSpy = jest.spyOn(LoggingService.prototype, 'logForNamespace').mockImplementation(() => {});
43
- const getEntitiesSpy = jest.spyOn(db, 'getEntities');
44
- const getEntitySpy = jest.spyOn(db, 'getEntity');
45
-
46
- currentTime = 300000; // start exactly at T = 5 minutes (Bucket index 1)
47
-
48
- console.log('\n---> Action: Initial Load of id1, id2 at T=5m');
49
- await userStore.load([['__id', 'in', ['id1', 'id2']]], {});
50
-
51
- // Expect 2 queries (one for _deleted: false, one for _deleted: true)
52
- expect(getEntitiesSpy).toHaveBeenCalledTimes(2);
53
- let callArgs = getEntitiesSpy.mock.calls[0];
54
- expect(callArgs[1]).toContainEqual(['_deleted', '==', false]);
55
-
56
- currentTime += 2 * 60 * 1000; // T = 7m (Still in the 5m-10m bucket index 1)
57
- console.log('\n---> Action: Initial Load of id3, id4 at T=7m');
58
- getEntitiesSpy.mockClear();
59
- await userStore.load([['__id', 'in', ['id3', 'id4']]], {});
60
- expect(getEntitiesSpy).toHaveBeenCalledTimes(2);
61
-
62
- // Now id1 and id2 have lastLoadTime = 5m
63
- // id3 and id4 have lastLoadTime = 7m
64
- // Both belong to the [5m, 10m) bucket (index 1).
65
-
66
- currentTime += 2 * 60 * 1000; // T = 9m
67
- console.log('\n---> Action: Load id1, id2, id3, id4 together at T=9m');
68
- getEntitiesSpy.mockClear();
69
- await userStore.load([['__id', 'in', ['id1', 'id2', 'id3', 'id4']]], {});
70
-
71
- // Should be batched into exactly ONE group! So 2 queries total.
72
- expect(getEntitiesSpy).toHaveBeenCalledTimes(2);
73
- callArgs = getEntitiesSpy.mock.calls[0];
74
- // We expect the min time among the bucket items to be used (5m)
75
- const timestampCondition = (callArgs[1] as any[]).find((param: any) => param[0] === '_updatedAt');
76
- expect(timestampCondition).toBeDefined();
77
- expect(timestampCondition![2].toMillis()).toEqual(300000); // exactly 5m
78
-
79
- // Now ALL of id1, id2, id3, id4 have lastLoadTime = 9m (which is in the 5m-10m bucket)
80
-
81
- currentTime += 3 * 60 * 1000; // T = 12m (Next bucket index 2)
82
- console.log('\n---> Action: Initial Load of id5 at T=12m');
83
- getEntitiesSpy.mockClear();
84
- getEntitySpy.mockClear();
85
- await userStore.load([['__id', 'in', ['id5']]], {});
86
- expect(getEntitiesSpy).toHaveBeenCalledTimes(0);
87
- expect(getEntitySpy).toHaveBeenCalledTimes(1);
88
-
89
- // Now we load id1, id2, id3, id4 (lastLoadTime=9m, bucket index 1)
90
- // AND id5 (lastLoadTime=12m, bucket index 2)
91
- currentTime += 1 * 60 * 1000; // T = 13m
92
- console.log('\n---> Action: Load all id1..id5 together at T=13m');
93
- getEntitiesSpy.mockClear();
94
- await userStore.load([['__id', 'in', ['id1', 'id2', 'id3', 'id4', 'id5']]], {});
95
-
96
- // Check if the spy caught the actual internal library logs properly!
97
- // The previous test tried to assert against the internal console logs of the test file.
98
- // Instead, assert on the actual bucketing logs from app.store.ts
99
- const allLogs = logSpy.mock.calls.map((args) => args.join(' '));
100
- expect(allLogs.some((log) => log.includes('[Store] Grouped 5 IDs into 2 time bucket(s).'))).toBe(true);
101
-
102
- console.log('\n=== FULL LOAD BUCKETING SIMULATION COMPLETE ===');
103
- });
104
- });
@@ -1,127 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { DestroyRef, EnvironmentInjector } from '@angular/core';
3
- import { Subject } from 'rxjs';
4
- import { StreamMultiplexer } from './stream-multiplexer';
5
- import { DatabaseService, DATABASE_SERVICE } from './database.service';
6
- import { signalStore, withState } from '@ngrx/signals';
7
- import { withEntitiesAndSelectMethods, withEntitiesAndDBMethods } from '../store/app.store';
8
-
9
- import { provideFirebaseMock } from './firebase.mock.service';
10
- import { MOCK_SIMULATION_USERS, MOCK_SIMULATION_USER_CONTEXTS } from './simulation.mock';
11
- import { LoggingService } from '../logging/logging.service';
12
-
13
- // Define realistic Stores
14
- export const UserStore = signalStore(
15
- { providedIn: 'root' },
16
- withState({}),
17
- withEntitiesAndDBMethods<any>('users'),
18
- );
19
-
20
- export const UserContextStore = signalStore(
21
- { providedIn: 'root' },
22
- withState({}),
23
- withEntitiesAndDBMethods<any>('userContexts'),
24
- );
25
-
26
- describe('Simulation with Actual Store Syntax', () => {
27
- it('runs the full stream multiplexer simulation and logs the output', async () => {
28
- TestBed.configureTestingModule({
29
- providers: [
30
- ...provideFirebaseMock({
31
- users: MOCK_SIMULATION_USERS,
32
- userContexts: MOCK_SIMULATION_USER_CONTEXTS,
33
- }),
34
- UserStore,
35
- UserContextStore,
36
- ],
37
- });
38
-
39
- const userStore = TestBed.inject(UserStore) as any;
40
- const userContextStore = TestBed.inject(UserContextStore) as any;
41
- const injector = TestBed.inject(EnvironmentInjector);
42
-
43
- const logSpy = jest.spyOn(LoggingService.prototype, 'logForNamespace').mockImplementation(() => {});
44
- console.log('=== STARTING REALISTIC STORE SIMULATION ===\n');
45
-
46
- // Create mock injectors and destroy refs for separate components
47
- const componentA = { onDestroyFns: [] as any[] };
48
- const mockInjectorA = { get: (token: any, notFound?: any, flags?: any) => token === DestroyRef ? { onDestroy: (cb: any) => componentA.onDestroyFns.push(cb) } : injector.get(token, notFound, flags) };
49
-
50
- const componentB = { onDestroyFns: [] as any[] };
51
- const mockInjectorB = { get: (token: any, notFound?: any, flags?: any) => token === DestroyRef ? { onDestroy: (cb: any) => componentB.onDestroyFns.push(cb) } : injector.get(token, notFound, flags) };
52
-
53
- const componentC = { onDestroyFns: [] as any[] };
54
- const mockInjectorC = { get: (token: any, notFound?: any, flags?: any) => token === DestroyRef ? { onDestroy: (cb: any) => componentC.onDestroyFns.push(cb) } : injector.get(token, notFound, flags) };
55
-
56
- // 1. Initial load, component A asks for 5 IDs using the actual stream API
57
- userStore.stream([['__id', 'in', ['id1', 'id2', 'id3', 'id4', 'id5']]], {}, mockInjectorA);
58
- await new Promise((r) => setTimeout(r, 50));
59
-
60
- // 2. Component B asks for 3 completely different IDs
61
- userStore.stream([['__id', 'in', ['id6', 'id7', 'id8']]], {}, mockInjectorB);
62
- await new Promise((r) => setTimeout(r, 50));
63
-
64
- // 3. Component C asks for 3 IDs (2 overlap with A, 1 new) and has a NESTED stream query
65
- // Streaming the user's UserContext
66
- userStore.stream(
67
- [['__id', 'in', ['id1', 'id2', 'id9']]],
68
- {},
69
- mockInjectorC,
70
- (user: any) => {
71
- const contextId = `${user.__id}_context`;
72
- return [{
73
- collection: 'userContexts',
74
- store: userContextStore,
75
- queryParams: [['__id', '==', contextId]],
76
- queryOptions: {},
77
- }];
78
- },
79
- );
80
- await new Promise((r) => setTimeout(r, 50));
81
-
82
- // 4. Component A destroys (orphans 3 IDs: id3, id4, id5. id1, id2 stay active for C)
83
- console.log('\n---> Action: Component A destroys (tears down stream for id1, id2, id3, id4, id5)');
84
- componentA.onDestroyFns.forEach((fn) => fn());
85
- await new Promise((r) => setTimeout(r, 5100));
86
-
87
- // 5. Fire off a bunch of singleton queries to hit the bloat threshold (trigger repacking)
88
- const singletons = ['id10', 'id11', 'id12', 'id13', 'id14', 'id15', 'id16', 'id17'];
89
- for (const id of singletons) {
90
- userStore.stream([['__id', 'in', [id]]], {}, mockInjectorC);
91
- }
92
- await new Promise((r) => setTimeout(r, 50));
93
-
94
- // 6. Request a MASSIVE array that has to be chunked (e.g. 35 IDs)
95
- const hugeArray = Array.from({ length: 35 }, (_, i) => `huge_${i}`);
96
- userStore.stream([['__id', 'in', hugeArray]], {}, mockInjectorB);
97
- await new Promise((r) => setTimeout(r, 50));
98
-
99
- // 8. Test quick recreation (Component E requests id100, dies, Component F requests id100 immediately)
100
- const componentE = { onDestroyFns: [] as any[] };
101
- const mockInjectorE = { get: (token: any, notFound?: any, flags?: any) => token === DestroyRef ? { onDestroy: (cb: any) => componentE.onDestroyFns.push(cb) } : injector.get(token, notFound, flags) };
102
-
103
- console.log('\n---> Action: Component E mounts, requests id100');
104
- userStore.stream([['__id', 'in', ['id100']]], {}, mockInjectorE);
105
- await new Promise((r) => setTimeout(r, 50));
106
-
107
- console.log('\n---> Action: Component E destroys itself');
108
- componentE.onDestroyFns.forEach((fn) => fn());
109
- await new Promise((r) => setTimeout(r, 1000)); // wait 1s (less than 5s)
110
-
111
- const componentF = { onDestroyFns: [] as any[] };
112
- const mockInjectorF = { get: (token: any, notFound?: any, flags?: any) => token === DestroyRef ? { onDestroy: (cb: any) => componentF.onDestroyFns.push(cb) } : injector.get(token, notFound, flags) };
113
-
114
- console.log('\n---> Action: Component F mounts and requests id100 BEFORE the 5s timeout finishes');
115
- userStore.stream([['__id', 'in', ['id100']]], {}, mockInjectorF);
116
-
117
- await new Promise((r) => setTimeout(r, 4500)); // Wait out the rest of Component E's 5s timeout
118
-
119
- // Verify key behaviors through logs
120
- expect(logSpy).toHaveBeenCalledWith('query', expect.stringContaining('[StreamMultiplexer] Opening 1 new websocket stream(s) for chunks:'));
121
- expect(logSpy).toHaveBeenCalledWith('query', expect.stringContaining('[StreamMultiplexer] Tearing down 9 old websocket stream(s).'));
122
- expect(logSpy).toHaveBeenCalledWith('query', expect.stringContaining('[StreamMultiplexer] Smart Repack Triggered!'));
123
- expect(logSpy).toHaveBeenCalledWith('query', expect.stringContaining('[StreamMultiplexer] Component destroyed 5 seconds ago! Releasing its holds on IDs: [id100]'));
124
-
125
- console.log('\n=== FULL STREAMING SIMULATION COMPLETE ===');
126
- }, 15000);
127
- });
@@ -1,38 +0,0 @@
1
- export const MOCK_SIMULATION_USERS = [];
2
- export const MOCK_SIMULATION_USER_CONTEXTS = [];
3
-
4
- // Seed 1-20
5
- for (let i = 1; i <= 20; i++) {
6
- MOCK_SIMULATION_USERS.push({
7
- __id: `id${i}`,
8
- name: `User id${i}`,
9
- });
10
- MOCK_SIMULATION_USER_CONTEXTS.push({
11
- __id: `id${i}_context`,
12
- userId: `id${i}`,
13
- data: `Context for user id${i}`,
14
- });
15
- }
16
-
17
- // Seed huge_0 to huge_50
18
- for (let i = 0; i <= 50; i++) {
19
- MOCK_SIMULATION_USERS.push({
20
- __id: `huge_${i}`,
21
- name: `User huge_${i}`,
22
- });
23
- MOCK_SIMULATION_USER_CONTEXTS.push({
24
- __id: `huge_${i}_context`,
25
- userId: `huge_${i}`,
26
- data: `Context for user huge_${i}`,
27
- });
28
- }
29
-
30
- MOCK_SIMULATION_USERS.push({
31
- __id: `id99`,
32
- name: `User id99`,
33
- });
34
-
35
- MOCK_SIMULATION_USERS.push({
36
- __id: `id100`,
37
- name: `User id100`,
38
- });