@tech4good/angular-schematics 21.5.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.
- package/CHANGELOG.md +44 -0
- package/README.md +266 -1
- package/package.json +34 -7
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +16 -7
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +13 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
- package/src/entity/index.js +61 -49
- package/src/entity/index.js.map +1 -1
- package/src/entity/schema.json +4 -0
- package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
- package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
- package/src/ng-add/files/.gitignore.template +5 -0
- package/src/ng-add/files/analytics/datasets.js.template +206 -0
- package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
- package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
- package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
- package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
- package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
- package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
- package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
- package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
- package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
- package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
- package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
- package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
- package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
- package/src/ng-add/files/analytics/server/server.js.template +212 -0
- package/src/ng-add/files/angular.json.template +80 -1
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
- package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
- package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
- package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
- package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
- package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
- package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
- package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
- package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
- package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +300 -0
- package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
- package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +123 -38
- package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
- package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
- package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
- package/src/ng-add/files/eslint.config.js.template +22 -3
- package/src/ng-add/files/firebase.json.template +6 -0
- package/src/ng-add/files/firestore.indexes.json.template +23 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
- package/src/ng-add/files/firestore.rules.template +29 -17
- package/src/ng-add/files/functions/.gitignore.template +3 -0
- package/src/ng-add/files/functions/package.json.template +13 -0
- package/src/ng-add/files/functions/src/email.ts.template +23 -0
- package/src/ng-add/files/functions/src/index.ts.template +44 -0
- package/src/ng-add/files/functions/tsconfig.json.template +13 -0
- package/src/ng-add/files/jest.config.ts.template +3 -2
- package/src/ng-add/files/package.json.template +41 -16
- package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
- package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
- package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
- package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
- package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
- package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
- package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
- package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +10 -13
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
- 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
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
- package/src/ng-add/files/src/app/app.component.html.template +3 -3
- package/src/ng-add/files/src/app/app.component.scss.template +1 -1
- package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/app.component.ts.template +3 -2
- package/src/ng-add/files/src/app/app.config.ts.template +21 -15
- package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +13 -9
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
- package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
- package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +14 -23
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +27 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +7 -2
- package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
- package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
- package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +20 -82
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +217 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +36 -172
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +18 -15
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +7 -8
- package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
- package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +6 -6
- package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +27 -16
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +102 -49
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +56 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +91 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +11 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +44 -5
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +33 -10
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
- package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
- package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +30 -32
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +85 -31
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
- package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -6
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
- package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/tsconfig.spec.json.template +3 -1
- package/src/ng-add/index.js +7 -0
- package/src/ng-add/index.js.map +1 -1
- package/src/shared/entity-registry.d.ts +8 -0
- package/src/shared/entity-registry.js +28 -0
- package/src/shared/entity-registry.js.map +1 -0
- package/tsconfig.json +2 -2
- package/.agents/skills/publish-npm/SKILL.md +0 -37
- package/.agents/skills/publish-npm/eval.yaml +0 -32
- package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.t4g/agent-memory.db +0 -0
- package/src/component/index_spec.d.ts +0 -1
- package/src/component/index_spec.js +0 -68
- package/src/component/index_spec.js.map +0 -1
- package/src/entity/index_spec.d.ts +0 -1
- package/src/entity/index_spec.js +0 -153
- package/src/entity/index_spec.js.map +0 -1
- package/src/guard/index_spec.d.ts +0 -1
- package/src/guard/index_spec.js +0 -64
- package/src/guard/index_spec.js.map +0 -1
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -494
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -56
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -366
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -342
- package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
- package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
- package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
- package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
- package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
- package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
- package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1317
- package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
- package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
- package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
|
|
2
|
-
import { Firestore, WriteBatch, writeBatch } from '@angular/fire/firestore';
|
|
3
|
-
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
4
|
-
import { FirebaseMockService } from '../firebase/firebase.mock.service';
|
|
5
|
-
import { processBatchWrite, BatchWriteService } from './batch-write.service';
|
|
6
|
-
|
|
7
|
-
@Injectable({
|
|
8
|
-
providedIn: 'root',
|
|
9
|
-
})
|
|
10
|
-
export class BatchWriteDBService implements BatchWriteService {
|
|
11
|
-
private firestore = inject(Firestore);
|
|
12
|
-
private snackBar = inject(MatSnackBar);
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
) { }
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param batchFn function that contains any number of add, update,
|
|
19
|
-
* or remove calls and writes them all as a batch write. It takes a
|
|
20
|
-
* batchConfig as an input, which contains the batch and revertBatch objects
|
|
21
|
-
* as the patchFns or revertFns arrays for collecting the functions
|
|
22
|
-
* that need to be run to either add things to the store after success or
|
|
23
|
-
* revert things from the store on failure in an optimistic write setting.
|
|
24
|
-
* It also stores whether these will be optimistic writes or not.
|
|
25
|
-
* @param options support for optimistic writes, a loading icon, and
|
|
26
|
-
* a snackbar that has an undo option.
|
|
27
|
-
*/
|
|
28
|
-
async batchWrite(
|
|
29
|
-
batchFn: (batchConfig: {
|
|
30
|
-
batch: WriteBatch,
|
|
31
|
-
revertBatch: WriteBatch,
|
|
32
|
-
patchFns: Array<() => void>,
|
|
33
|
-
revertFns: Array<() => void>,
|
|
34
|
-
dbRevertFns: Array<() => void>,
|
|
35
|
-
optimistic?: boolean,
|
|
36
|
-
}) => void,
|
|
37
|
-
options?: {
|
|
38
|
-
optimistic?: boolean,
|
|
39
|
-
loading?: WritableSignal<boolean>,
|
|
40
|
-
snackBarConfig?: {
|
|
41
|
-
successMessage: string,
|
|
42
|
-
failureMessage: string,
|
|
43
|
-
undoOnAction?: boolean,
|
|
44
|
-
config?: MatSnackBarConfig<any>,
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
) {
|
|
48
|
-
const batch = writeBatch(this.firestore);
|
|
49
|
-
const revertBatch = writeBatch(this.firestore);
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
await processBatchWrite(batchFn, options, batch, revertBatch, this.snackBar);
|
|
53
|
-
} catch (e) {
|
|
54
|
-
console.log(e);
|
|
55
|
-
throw e;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
|
|
2
|
-
import { Firestore, WriteBatch, writeBatch } from '@angular/fire/firestore';
|
|
3
|
-
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
4
|
-
import { FirebaseMockService } from '../firebase/firebase.mock.service';
|
|
5
|
-
import { WriteBatchI, BatchWriteService, processBatchWrite } from './batch-write.service';
|
|
6
|
-
|
|
7
|
-
// after doing a bunch of update/sets, then we need to actually do that when we commit
|
|
8
|
-
export class WriteBatchMock {
|
|
9
|
-
saveFns;
|
|
10
|
-
db;
|
|
11
|
-
|
|
12
|
-
// Constant for simulating delay (e.g. to see loading icon in action)
|
|
13
|
-
PUT_LATENCY_SIMULATION_DELAY = 300;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
db: FirebaseMockService,
|
|
17
|
-
) {
|
|
18
|
-
this.saveFns = [];
|
|
19
|
-
this.db = db;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async update(docRef, changes) {
|
|
23
|
-
const [collectionName, id] = docRef.path.split('/').slice(0, 2);
|
|
24
|
-
this.saveFns.push(async () => {
|
|
25
|
-
try {
|
|
26
|
-
await this.db.updateEntity(collectionName, id, changes);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.error(e);
|
|
29
|
-
throw e;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async set(docRef, entity) {
|
|
35
|
-
const [collectionName] = docRef.path.split('/').slice(0, 1);
|
|
36
|
-
this.saveFns.push(async () => {
|
|
37
|
-
try {
|
|
38
|
-
await this.db.addEntity(collectionName, entity);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
console.error(e);
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async delete(docRef) {
|
|
47
|
-
const [collectionName, id] = docRef.path.split('/').slice(0, 2);
|
|
48
|
-
this.saveFns.push(async () => {
|
|
49
|
-
try {
|
|
50
|
-
await this.db.removeEntity(collectionName, id);
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error(e);
|
|
53
|
-
throw e;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async commit() {
|
|
59
|
-
await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
|
|
60
|
-
return Promise.all(this.saveFns.map((saveFn) => saveFn()));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Injectable({
|
|
65
|
-
providedIn: 'root',
|
|
66
|
-
})
|
|
67
|
-
export class BatchWriteMockService implements BatchWriteService {
|
|
68
|
-
private snackBar = inject(MatSnackBar);
|
|
69
|
-
|
|
70
|
-
constructor(
|
|
71
|
-
private db: FirebaseMockService,
|
|
72
|
-
) {
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async batchWrite(
|
|
76
|
-
batchFn: (batchConfig: {
|
|
77
|
-
batch: WriteBatchMock,
|
|
78
|
-
revertBatch: WriteBatchMock,
|
|
79
|
-
patchFns: Array<() => void>,
|
|
80
|
-
revertFns: Array<() => void>,
|
|
81
|
-
dbRevertFns: Array<() => void>,
|
|
82
|
-
optimistic?: boolean,
|
|
83
|
-
}) => void,
|
|
84
|
-
options?: {
|
|
85
|
-
optimistic?: boolean,
|
|
86
|
-
loading?: WritableSignal<boolean>,
|
|
87
|
-
snackBarConfig?: {
|
|
88
|
-
successMessage: string,
|
|
89
|
-
failureMessage: string,
|
|
90
|
-
undoOnAction?: boolean,
|
|
91
|
-
config?: MatSnackBarConfig<any>,
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
): Promise<void> {
|
|
95
|
-
const batch = new WriteBatchMock(this.db);
|
|
96
|
-
const revertBatch = new WriteBatchMock(this.db);
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
await processBatchWrite(batchFn, options, batch, revertBatch, this.snackBar);
|
|
100
|
-
} catch (e) {
|
|
101
|
-
console.log(e);
|
|
102
|
-
throw e;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { openSnackBarWithUndoOption } from './app.store';
|
|
2
|
-
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
3
|
-
import { InjectionToken, Injectable, WritableSignal, inject } from '@angular/core';
|
|
4
|
-
import { WriteBatchMock } from './batch-write.mock.service';
|
|
5
|
-
import { WriteBatch } from '@angular/fire/firestore';
|
|
6
|
-
|
|
7
|
-
export interface WriteBatchI {
|
|
8
|
-
update(docRef, changes);
|
|
9
|
-
set(docRef, entity);
|
|
10
|
-
delete(docRef);
|
|
11
|
-
commit();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface BatchWriteService {
|
|
15
|
-
batchWrite(
|
|
16
|
-
batchFn: (batchConfig: {
|
|
17
|
-
batch: WriteBatch | WriteBatchMock,
|
|
18
|
-
revertBatch: WriteBatch | WriteBatchMock,
|
|
19
|
-
patchFns: Array<() => void>,
|
|
20
|
-
revertFns: Array<() => void>,
|
|
21
|
-
dbRevertFns: Array<() => void>,
|
|
22
|
-
optimistic?: boolean,
|
|
23
|
-
}) => void,
|
|
24
|
-
options?: {
|
|
25
|
-
optimistic?: boolean,
|
|
26
|
-
loading?: WritableSignal<boolean>,
|
|
27
|
-
snackBarConfig?: {
|
|
28
|
-
successMessage: string,
|
|
29
|
-
failureMessage: string,
|
|
30
|
-
undoOnAction?: boolean,
|
|
31
|
-
config?: MatSnackBarConfig<any>,
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const BATCH_WRITE_SERVICE = new InjectionToken<BatchWriteService>('BatchWriteService');
|
|
38
|
-
|
|
39
|
-
export async function processBatchWrite(
|
|
40
|
-
batchFn: (batchConfig: {
|
|
41
|
-
batch: WriteBatchI,
|
|
42
|
-
revertBatch: WriteBatchI,
|
|
43
|
-
patchFns: Array<() => void>,
|
|
44
|
-
revertFns: Array<() => void>,
|
|
45
|
-
dbRevertFns: Array<() => void>,
|
|
46
|
-
optimistic?: boolean,
|
|
47
|
-
}) => void,
|
|
48
|
-
options: {
|
|
49
|
-
optimistic?: boolean,
|
|
50
|
-
loading?: WritableSignal<boolean>,
|
|
51
|
-
snackBarConfig?: {
|
|
52
|
-
successMessage: string,
|
|
53
|
-
failureMessage: string,
|
|
54
|
-
undoOnAction?: boolean,
|
|
55
|
-
config?: MatSnackBarConfig<any>,
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
batch: WriteBatchI,
|
|
59
|
-
revertBatch: WriteBatchI,
|
|
60
|
-
snackBar: MatSnackBar,
|
|
61
|
-
) {
|
|
62
|
-
const patchFns = [];
|
|
63
|
-
const revertFns = [];
|
|
64
|
-
const dbRevertFns = [];
|
|
65
|
-
|
|
66
|
-
if (options?.optimistic) {
|
|
67
|
-
// this includes optimistically patching locally assuming
|
|
68
|
-
// they are using the add, update, remove functions from
|
|
69
|
-
// the ngrx signal stores
|
|
70
|
-
await batchFn({ batch, revertBatch, patchFns, revertFns, dbRevertFns, optimistic: options.optimistic });
|
|
71
|
-
try {
|
|
72
|
-
await batch.commit();
|
|
73
|
-
if (options?.snackBarConfig) {
|
|
74
|
-
openSnackBarWithUndoOption(
|
|
75
|
-
snackBar,
|
|
76
|
-
options.snackBarConfig,
|
|
77
|
-
revertFns,
|
|
78
|
-
dbRevertFns,
|
|
79
|
-
revertBatch,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
} catch (e) {
|
|
83
|
-
revertFns.forEach((revertFn) => revertFn());
|
|
84
|
-
console.error(e);
|
|
85
|
-
if (options?.snackBarConfig) {
|
|
86
|
-
snackBar.open(
|
|
87
|
-
options.snackBarConfig.failureMessage,
|
|
88
|
-
'',
|
|
89
|
-
options.snackBarConfig.config,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
throw e;
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
// start loading icon
|
|
96
|
-
options?.loading?.set(true);
|
|
97
|
-
try {
|
|
98
|
-
await batchFn({ batch, revertBatch, patchFns, revertFns, dbRevertFns });
|
|
99
|
-
await batch.commit();
|
|
100
|
-
patchFns.forEach((patchFn) => patchFn());
|
|
101
|
-
|
|
102
|
-
if (options?.snackBarConfig) {
|
|
103
|
-
openSnackBarWithUndoOption(
|
|
104
|
-
snackBar,
|
|
105
|
-
options.snackBarConfig,
|
|
106
|
-
revertFns,
|
|
107
|
-
dbRevertFns,
|
|
108
|
-
revertBatch,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
} catch (e) {
|
|
112
|
-
console.error(e);
|
|
113
|
-
if (options?.snackBarConfig) {
|
|
114
|
-
snackBar.open(
|
|
115
|
-
options.snackBarConfig.failureMessage,
|
|
116
|
-
'',
|
|
117
|
-
options.snackBarConfig.config,
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
throw e;
|
|
121
|
-
} finally {
|
|
122
|
-
// stop loading icon
|
|
123
|
-
options?.loading?.set(false);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
@if (showRedeploymentWarning()) {
|
|
2
|
-
<div class="warning-container">
|
|
3
|
-
<div class="header">
|
|
4
|
-
<div class="title">This version is out of date!</div>
|
|
5
|
-
<img (click)="close()" src="images/close-x.svg" />
|
|
6
|
-
</div>
|
|
7
|
-
<button (click)="update()" class="update">Update Now</button>
|
|
8
|
-
</div>
|
|
9
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
z-index: 100;
|
|
3
|
-
|
|
4
|
-
.warning-container {
|
|
5
|
-
padding: 10px 13px;
|
|
6
|
-
display: flex;
|
|
7
|
-
flex-direction: column;
|
|
8
|
-
width: 350px;
|
|
9
|
-
height: 63px;
|
|
10
|
-
background: #fff;
|
|
11
|
-
border-radius: 5px;
|
|
12
|
-
border: 1px solid #999;
|
|
13
|
-
box-shadow: 0px 1px 4px #999;
|
|
14
|
-
|
|
15
|
-
.header {
|
|
16
|
-
display: flex;
|
|
17
|
-
width: 100%;
|
|
18
|
-
|
|
19
|
-
.title {
|
|
20
|
-
text-transform: uppercase;
|
|
21
|
-
color: #283262;
|
|
22
|
-
font-weight: bold;
|
|
23
|
-
font-size: 13px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
img {
|
|
27
|
-
cursor: pointer;
|
|
28
|
-
margin-left: auto;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
button {
|
|
33
|
-
margin-top: auto;
|
|
34
|
-
border: none;
|
|
35
|
-
padding: 0;
|
|
36
|
-
width: fit-content;
|
|
37
|
-
outline: 0;
|
|
38
|
-
font-weight: bold;
|
|
39
|
-
font-size: 13px;
|
|
40
|
-
text-decoration-line: underline;
|
|
41
|
-
background: none;
|
|
42
|
-
text-transform: capitalize;
|
|
43
|
-
cursor: pointer;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/angular';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { Subject } from 'rxjs';
|
|
4
|
-
import { Provider } from '@angular/core';
|
|
5
|
-
|
|
6
|
-
import { RedeploymentWarningComponent } from './redeployment-warning.component';
|
|
7
|
-
import { DetectRedeploymentService } from './redeployment-warning.service';
|
|
8
|
-
|
|
9
|
-
/** Sets up the testing environment for RedeploymentWarningComponent using render. */
|
|
10
|
-
async function setup() {
|
|
11
|
-
const user = userEvent.setup();
|
|
12
|
-
const redeployedSubject = new Subject<void>();
|
|
13
|
-
const detectRedeploymentMock = {
|
|
14
|
-
redeployed: jest.fn().mockReturnValue(redeployedSubject.asObservable()),
|
|
15
|
-
refresh: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const view = await render(RedeploymentWarningComponent, {
|
|
19
|
-
imports: [],
|
|
20
|
-
providers: [
|
|
21
|
-
{ provide: DetectRedeploymentService, useValue: detectRedeploymentMock },
|
|
22
|
-
],
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
user,
|
|
27
|
-
fixture: view.fixture,
|
|
28
|
-
detectRedeploymentMock,
|
|
29
|
-
redeployedSubject,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe('RedeploymentWarningComponent', () => {
|
|
34
|
-
it('should not show warning initially', async () => {
|
|
35
|
-
await setup();
|
|
36
|
-
expect(screen.queryByText(/This version is out of date/i)).toBeNull();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should show warning when redeployment is detected, and close it when clicked', async () => {
|
|
40
|
-
const { user, redeployedSubject, fixture } = await setup();
|
|
41
|
-
|
|
42
|
-
// Trigger redeployment
|
|
43
|
-
redeployedSubject.next();
|
|
44
|
-
fixture.detectChanges();
|
|
45
|
-
|
|
46
|
-
// Warning should be visible
|
|
47
|
-
expect(screen.getByText(/This version is out of date/i)).toBeVisible();
|
|
48
|
-
|
|
49
|
-
// Click close icon
|
|
50
|
-
const closeBtn = screen.getByRole('img');
|
|
51
|
-
await user.click(closeBtn);
|
|
52
|
-
|
|
53
|
-
// Warning should be hidden
|
|
54
|
-
expect(screen.queryByText(/This version is out of date/i)).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should call refresh on the service when Update Now is clicked', async () => {
|
|
58
|
-
const { user, redeployedSubject, detectRedeploymentMock, fixture } = await setup();
|
|
59
|
-
|
|
60
|
-
// Trigger redeployment
|
|
61
|
-
redeployedSubject.next();
|
|
62
|
-
fixture.detectChanges();
|
|
63
|
-
|
|
64
|
-
const updateBtn = screen.getByRole('button', { name: /Update Now/i });
|
|
65
|
-
await user.click(updateBtn);
|
|
66
|
-
|
|
67
|
-
expect(detectRedeploymentMock.refresh).toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Component, OnInit, WritableSignal, signal } from '@angular/core';
|
|
2
|
-
import { DetectRedeploymentService } from './redeployment-warning.service';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'app-redeployment-warning',
|
|
6
|
-
templateUrl: './redeployment-warning.component.html',
|
|
7
|
-
styleUrl: './redeployment-warning.component.scss',
|
|
8
|
-
})
|
|
9
|
-
export class RedeploymentWarningComponent implements OnInit {
|
|
10
|
-
// --------------- INPUTS AND OUTPUTS ------------------
|
|
11
|
-
|
|
12
|
-
// --------------- LOCAL UI STATE ----------------------
|
|
13
|
-
|
|
14
|
-
showRedeploymentWarning: WritableSignal<boolean> = signal(false);
|
|
15
|
-
|
|
16
|
-
// --------------- COMPUTED DATA -----------------------
|
|
17
|
-
|
|
18
|
-
// --------------- EVENT HANDLING ----------------------
|
|
19
|
-
|
|
20
|
-
/** Triggers a refresh. */
|
|
21
|
-
update() {
|
|
22
|
-
this.detectRedeployment.refresh();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Ignores the warning. */
|
|
26
|
-
close() {
|
|
27
|
-
this.showRedeploymentWarning.set(false);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// --------------- OTHER -------------------------------
|
|
31
|
-
|
|
32
|
-
constructor(public detectRedeployment: DetectRedeploymentService) {}
|
|
33
|
-
|
|
34
|
-
ngOnInit() {
|
|
35
|
-
this.detectRedeployment.redeployed().subscribe(() => {
|
|
36
|
-
this.showRedeploymentWarning.set(true);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { config } from 'rxjs';
|
|
3
|
-
import { DetectRedeploymentService } from './redeployment-warning.service';
|
|
4
|
-
|
|
5
|
-
describe('DetectRedeploymentService', () => {
|
|
6
|
-
let service: DetectRedeploymentService;
|
|
7
|
-
let originalFetch: any;
|
|
8
|
-
let fetchSpy: jest.Mock;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
jest.useFakeTimers();
|
|
12
|
-
TestBed.configureTestingModule({
|
|
13
|
-
providers: [DetectRedeploymentService],
|
|
14
|
-
});
|
|
15
|
-
service = TestBed.inject(DetectRedeploymentService);
|
|
16
|
-
|
|
17
|
-
// Mock fetch
|
|
18
|
-
originalFetch = window.fetch;
|
|
19
|
-
fetchSpy = jest.fn().mockReturnValue(
|
|
20
|
-
Promise.resolve({
|
|
21
|
-
text: () => Promise.resolve('<script src="main-12345.js"></script>'),
|
|
22
|
-
}),
|
|
23
|
-
);
|
|
24
|
-
window.fetch = fetchSpy as any;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
window.fetch = originalFetch;
|
|
29
|
-
jest.useRealTimers();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should multicast the interval to multiple subscribers with share()', async () => {
|
|
33
|
-
service.init();
|
|
34
|
-
|
|
35
|
-
// The first fetch is triggered immediately due to startWith(0)
|
|
36
|
-
jest.advanceTimersByTime(1);
|
|
37
|
-
// await microtasks to resolve promises
|
|
38
|
-
await Promise.resolve();
|
|
39
|
-
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
40
|
-
fetchSpy.mockClear();
|
|
41
|
-
|
|
42
|
-
// Two different components subscribe to redeployed()
|
|
43
|
-
const sub1 = service.redeployed().subscribe();
|
|
44
|
-
const sub2 = service.redeployed().subscribe();
|
|
45
|
-
|
|
46
|
-
// Advance time by 2 minutes to trigger the next interval
|
|
47
|
-
jest.advanceTimersByTime(2 * 60 * 1000);
|
|
48
|
-
await Promise.resolve();
|
|
49
|
-
|
|
50
|
-
// Because of `share()`, the interval is multicasted, meaning the underlying
|
|
51
|
-
// `fetch` should only be called ONCE per interval, not twice.
|
|
52
|
-
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
53
|
-
|
|
54
|
-
sub1.unsubscribe();
|
|
55
|
-
sub2.unsubscribe();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should gracefully handle network errors without killing the polling interval', async () => {
|
|
59
|
-
// Force a network error for the first fetch
|
|
60
|
-
fetchSpy.mockRejectedValueOnce(new Error('Network error'));
|
|
61
|
-
|
|
62
|
-
// Start the interval
|
|
63
|
-
service.init();
|
|
64
|
-
|
|
65
|
-
// First tick encounters the network error, which is caught and returns null, keeping the interval alive
|
|
66
|
-
jest.advanceTimersByTime(1);
|
|
67
|
-
await Promise.resolve();
|
|
68
|
-
|
|
69
|
-
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
70
|
-
fetchSpy.mockClear();
|
|
71
|
-
|
|
72
|
-
// Now restore fetch to working order for the next interval
|
|
73
|
-
fetchSpy.mockReturnValue(
|
|
74
|
-
Promise.resolve({
|
|
75
|
-
text: () => Promise.resolve('<script src="main-12345.js"></script>'),
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// The interval is still alive! Advance time to the next 2-minute mark
|
|
80
|
-
jest.advanceTimersByTime(2 * 60 * 1000);
|
|
81
|
-
await Promise.resolve();
|
|
82
|
-
|
|
83
|
-
// Fetch should be called again, proving the interval survived
|
|
84
|
-
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should detect redeployment immediately on startup if the DOM script hash differs from the fetched index.html', async () => {
|
|
88
|
-
// Inject a script tag into the mock DOM
|
|
89
|
-
const scriptEl = document.createElement('script');
|
|
90
|
-
scriptEl.setAttribute('src', 'main-OLDHASH.js');
|
|
91
|
-
document.body.appendChild(scriptEl);
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
// Mock fetch to return a newer hash
|
|
95
|
-
fetchSpy.mockReturnValue(
|
|
96
|
-
Promise.resolve({
|
|
97
|
-
text: () => Promise.resolve('<script src="main-NEWHASH.js"></script>'),
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
let triggered = false;
|
|
102
|
-
const triggeredPromise = new Promise<void>((resolve) => {
|
|
103
|
-
service.redeployed().subscribe({
|
|
104
|
-
next: () => {
|
|
105
|
-
triggered = true;
|
|
106
|
-
resolve();
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
service.init();
|
|
112
|
-
|
|
113
|
-
// Resolve startup fetch
|
|
114
|
-
jest.advanceTimersByTime(1);
|
|
115
|
-
await triggeredPromise;
|
|
116
|
-
|
|
117
|
-
expect(triggered).toBe(true);
|
|
118
|
-
} finally {
|
|
119
|
-
document.body.removeChild(scriptEl);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { BehaviorSubject, Observable, interval, Subject, from } from 'rxjs';
|
|
3
|
-
import { startWith, share, distinctUntilChanged, tap, skip, map, filter, mergeMap } from 'rxjs/operators';
|
|
4
|
-
|
|
5
|
-
@Injectable({
|
|
6
|
-
providedIn: 'root',
|
|
7
|
-
})
|
|
8
|
-
export class DetectRedeploymentService {
|
|
9
|
-
/** Event stream that emits when an app redeployment is detected. */
|
|
10
|
-
private redeployed$: Observable<void>;
|
|
11
|
-
private initialized$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
|
12
|
-
|
|
13
|
-
constructor() {}
|
|
14
|
-
|
|
15
|
-
/** Retrieves the filename of the currently loaded main javascript bundle. */
|
|
16
|
-
private getLoadedMainScript(): string | null {
|
|
17
|
-
if (typeof document === 'undefined') {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const scripts = Array.from(document.querySelectorAll('script'));
|
|
21
|
-
for (const script of scripts) {
|
|
22
|
-
const src = script.getAttribute('src');
|
|
23
|
-
if (src) {
|
|
24
|
-
const m = src.match(/main[-a-zA-Z0-9]*\.js/);
|
|
25
|
-
if (m) {
|
|
26
|
-
return m[0];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Sets redeployed$ and returns it. */
|
|
34
|
-
public init() {
|
|
35
|
-
// Matches the filename of the main javascript file, which contains the hash in the name
|
|
36
|
-
const regexp = /main[-a-zA-Z0-9]*\.js/;
|
|
37
|
-
const currentScript = this.getLoadedMainScript();
|
|
38
|
-
|
|
39
|
-
const observable = (interval(2 * 60 * 1000) // every 2 minutes
|
|
40
|
-
.pipe(
|
|
41
|
-
startWith(0),
|
|
42
|
-
// Fetch index.html with a timestamp query parameter so it definitely doesn't get cached anywhere.
|
|
43
|
-
mergeMap(() => fetch('/index.html?t=' + Date.now()).catch(() => null)),
|
|
44
|
-
mergeMap((urlResponse: Response | null) => urlResponse ? urlResponse.text() : Promise.resolve('')),
|
|
45
|
-
map((responseText: string) => {
|
|
46
|
-
const m = responseText.match(regexp);
|
|
47
|
-
if (m === null) {
|
|
48
|
-
// Probably running a dev build or something where there's no hash.
|
|
49
|
-
// No biggie, we'll just do nothing.
|
|
50
|
-
return null;
|
|
51
|
-
} else {
|
|
52
|
-
return m[0];
|
|
53
|
-
}
|
|
54
|
-
}),
|
|
55
|
-
filter((val) => !!val),
|
|
56
|
-
// Prepend the currently loaded script tag if available so that if index.html
|
|
57
|
-
// is updated before loading, we detect it immediately on the first check.
|
|
58
|
-
startWith(currentScript),
|
|
59
|
-
filter((val) => !!val),
|
|
60
|
-
// Only emit when there are unique versions
|
|
61
|
-
distinctUntilChanged(),
|
|
62
|
-
// Skip the first starting version so we only get changes
|
|
63
|
-
skip(1),
|
|
64
|
-
// Map to void to match the return type
|
|
65
|
-
map(() => undefined as void),
|
|
66
|
-
// Modeled after example 1 in: https://www.learnrxjs.io/operators/multicasting/multicast.html
|
|
67
|
-
share(),
|
|
68
|
-
) as Observable<void>);
|
|
69
|
-
|
|
70
|
-
observable.subscribe();
|
|
71
|
-
|
|
72
|
-
this.redeployed$ = observable;
|
|
73
|
-
this.initialized$.next(true);
|
|
74
|
-
|
|
75
|
-
return observable;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public redeployed() {
|
|
79
|
-
return this.initialized$.pipe(
|
|
80
|
-
filter((val) => val),
|
|
81
|
-
mergeMap(() => this.redeployed$),
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public refresh() {
|
|
86
|
-
window.location.reload();
|
|
87
|
-
}
|
|
88
|
-
}
|