@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,366 +0,0 @@
|
|
|
1
|
-
import { Injectable, inject, Injector, computed, Provider } from '@angular/core';
|
|
2
|
-
import { toObservable } from '@angular/core/rxjs-interop';
|
|
3
|
-
import { Observable, combineLatest, merge, of, from, pipe, BehaviorSubject, throwError, NEVER } from 'rxjs';
|
|
4
|
-
import { tap, pluck, mergeMap, pairwise, delay, startWith, filter, takeUntil, skip, switchMap, map, take } from 'rxjs/operators';
|
|
5
|
-
import { environment } from '../../../environments/environment';
|
|
6
|
-
import { DocumentSnapshot, serverTimestamp, Timestamp, getDoc, getDocs, doc, setDoc, updateDoc, deleteDoc, docData, collection, collectionData, collectionChanges, query, where, orderBy, OrderByDirection, limit, startAt, startAfter, endAt, endBefore, DocumentChange, increment, AggregateQuerySnapshot, AggregateField, AggregateSpec, getAggregateFromServer, getCountFromServer } from '@angular/fire/firestore';
|
|
7
|
-
import { AnyEntity, QueryParams, QueryOptions } from '../store/app.model';
|
|
8
|
-
import { DatabaseService, DATABASE_SERVICE } from './database.service';
|
|
9
|
-
import { SelectEntityId } from '@ngrx/signals/entities';
|
|
10
|
-
import { AuthMockDB } from '../store/auth/auth.mock';
|
|
11
|
-
|
|
12
|
-
// Entity Model DB Data
|
|
13
|
-
import { UserMockDB, USER_DB } from '../store/user/user.mock';
|
|
14
|
-
import { UserContextMockDB, USERCONTEXT_DB } from '../store/user-context/user-context.mock';
|
|
15
|
-
import { UserPrivateMockDB, USERPRIVATE_DB } from '../store/user-private/user-private.mock';
|
|
16
|
-
|
|
17
|
-
const selectId: SelectEntityId<AnyEntity> = (entity) => entity.__id;
|
|
18
|
-
|
|
19
|
-
@Injectable({
|
|
20
|
-
providedIn: 'root',
|
|
21
|
-
})
|
|
22
|
-
export class FirebaseMockService implements DatabaseService {
|
|
23
|
-
readonly authDB = inject(AuthMockDB);
|
|
24
|
-
readonly DB = {
|
|
25
|
-
'users': inject(UserMockDB),
|
|
26
|
-
'userContexts': inject(UserContextMockDB),
|
|
27
|
-
'userPrivates': inject(UserPrivateMockDB),
|
|
28
|
-
};
|
|
29
|
-
private user$ = new BehaviorSubject(this.authDB.afUser());
|
|
30
|
-
|
|
31
|
-
// Constant for simulating delay (e.g. to see loading icon in action)
|
|
32
|
-
GET_LATENCY_SIMULATION_DELAY = 100;
|
|
33
|
-
PUT_LATENCY_SIMULATION_DELAY = 300;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Collections that throw/reject on any read operation.
|
|
37
|
-
* Set via `provideFirebaseMock({ failCollections: [...] })` or mutate mid-test
|
|
38
|
-
* via `db.failCollections = [...]` to simulate error → recovery flows.
|
|
39
|
-
*/
|
|
40
|
-
failCollections: string[] = [];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Collections where reads never emit/resolve (simulates perpetual loading).
|
|
44
|
-
* Set via `provideFirebaseMock({ stallCollections: [...] })` or mutate mid-test
|
|
45
|
-
* via `db.stallCollections = [...]`.
|
|
46
|
-
*/
|
|
47
|
-
stallCollections: string[] = [];
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
private injector: Injector,
|
|
51
|
-
) {
|
|
52
|
-
// Init Entity Models
|
|
53
|
-
this.DB['users'].init(USER_DB);
|
|
54
|
-
this.DB['userContexts'].init(USERCONTEXT_DB);
|
|
55
|
-
this.DB['userPrivates'].init(USERPRIVATE_DB);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Creates a unique id */
|
|
59
|
-
createId(): string {
|
|
60
|
-
// see https://stackoverflow.com/questions/56574593/access-firestore-id-generator-on-the-front-end?noredirect=1&lq=1
|
|
61
|
-
// see https://github.com/firebase/firebase-js-sdk/blob/73a586c92afe3f39a844b2be86086fddb6877bb7/packages/firestore/src/util/misc.ts#L36
|
|
62
|
-
// Alphanumeric characters
|
|
63
|
-
const chars =
|
|
64
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
65
|
-
let autoId = '';
|
|
66
|
-
for (let i = 0; i < 20; i++) {
|
|
67
|
-
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
68
|
-
}
|
|
69
|
-
return autoId;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
afUser(): Observable<{ uid: string, email: string, displayName: string, photoURL: string } | null> {
|
|
73
|
-
return this.user$;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async login(providerId, scope?: string): Promise<any> {
|
|
77
|
-
this.authDB.login();
|
|
78
|
-
this.user$.next(this.authDB.afUser());
|
|
79
|
-
return {
|
|
80
|
-
user: {
|
|
81
|
-
uid: USER_DB[0].__id,
|
|
82
|
-
email: USER_DB[0].email,
|
|
83
|
-
displayName: USER_DB[0].name,
|
|
84
|
-
photoURL: USER_DB[0].photoURL,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
loginLink(error) { }
|
|
90
|
-
|
|
91
|
-
logout() {
|
|
92
|
-
this.authDB.logout();
|
|
93
|
-
this.user$.next(this.authDB.afUser());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
streamEntity<T>(collectionName: string, id: string) {
|
|
97
|
-
if (this.stallCollections.includes(collectionName)) return NEVER;
|
|
98
|
-
if (this.failCollections.includes(collectionName)) {
|
|
99
|
-
return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
|
|
100
|
-
}
|
|
101
|
-
const store = this.DB[collectionName];
|
|
102
|
-
const entity = computed(() => {
|
|
103
|
-
return store.selectEntity(id);
|
|
104
|
-
});
|
|
105
|
-
return toObservable(entity, { injector: this.injector }).pipe(
|
|
106
|
-
delay(this.GET_LATENCY_SIMULATION_DELAY),
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
streamEntities<T>(collectionName, queryParams, queryOptions) {
|
|
111
|
-
if (this.stallCollections.includes(collectionName)) return NEVER;
|
|
112
|
-
if (this.failCollections.includes(collectionName)) {
|
|
113
|
-
return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
|
|
114
|
-
}
|
|
115
|
-
const store = this.DB[collectionName];
|
|
116
|
-
const entities = computed(() => {
|
|
117
|
-
return store.selectEntities(queryParams, queryOptions);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
return toObservable(entities, { injector: this.injector }).pipe(
|
|
121
|
-
delay(this.GET_LATENCY_SIMULATION_DELAY),
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
streamEntitiesChanges<T>(collectionName, queryParams, queryOptions) {
|
|
126
|
-
if (this.stallCollections.includes(collectionName)) return NEVER;
|
|
127
|
-
if (this.failCollections.includes(collectionName)) {
|
|
128
|
-
return throwError(() => new Error(`Simulated read error for collection: ${collectionName}`));
|
|
129
|
-
}
|
|
130
|
-
const store = this.DB[collectionName];
|
|
131
|
-
const streamEntities = computed(() => {
|
|
132
|
-
return store.selectEntities(queryParams, queryOptions);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
return toObservable(streamEntities, { injector: this.injector }).pipe(
|
|
136
|
-
// convert to entityMap to more easily compare
|
|
137
|
-
map((entities) => {
|
|
138
|
-
const entityMap = {};
|
|
139
|
-
for (const entity of entities) {
|
|
140
|
-
entityMap[entity.__id] = entity;
|
|
141
|
-
}
|
|
142
|
-
return entityMap;
|
|
143
|
-
}),
|
|
144
|
-
// compare current with prior including the first
|
|
145
|
-
startWith({}),
|
|
146
|
-
pairwise(),
|
|
147
|
-
// get the changedEntities
|
|
148
|
-
map(([prevEntities, currEntities]) => {
|
|
149
|
-
const changedEntities = [];
|
|
150
|
-
for (const key in currEntities) {
|
|
151
|
-
if (!(key in prevEntities)) {
|
|
152
|
-
// the entity was added
|
|
153
|
-
changedEntities.push({
|
|
154
|
-
type: 'added',
|
|
155
|
-
docData: currEntities[key],
|
|
156
|
-
});
|
|
157
|
-
} else if (currEntities[key]['_deleted']) {
|
|
158
|
-
// the entity was removed
|
|
159
|
-
changedEntities.push({
|
|
160
|
-
type: 'removed',
|
|
161
|
-
docData: currEntities[key],
|
|
162
|
-
});
|
|
163
|
-
} else if (currEntities[key]['_updatedAt'] !== prevEntities[key]['_updatedAt']) {
|
|
164
|
-
// the entity was modified
|
|
165
|
-
changedEntities.push({
|
|
166
|
-
type: 'modified',
|
|
167
|
-
docData: currEntities[key],
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return changedEntities;
|
|
173
|
-
}),
|
|
174
|
-
filter((changes: Array<{ type: string, docData: T }>) => changes.length > 0),
|
|
175
|
-
delay(this.GET_LATENCY_SIMULATION_DELAY),
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async getEntity<T>(collectionName: string, id: string) {
|
|
180
|
-
if (this.stallCollections.includes(collectionName)) return new Promise(() => {});
|
|
181
|
-
if (this.failCollections.includes(collectionName)) {
|
|
182
|
-
throw new Error(`Simulated read error for collection: ${collectionName}`);
|
|
183
|
-
}
|
|
184
|
-
const store = this.DB[collectionName];
|
|
185
|
-
await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
|
|
186
|
-
return store.selectEntity(id);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
async getEntities<S>(
|
|
190
|
-
collectionName: string,
|
|
191
|
-
queryParams: [string, string, any][],
|
|
192
|
-
queryOptions?: { [index: string]: any },
|
|
193
|
-
): Promise<S[]> {
|
|
194
|
-
if (this.stallCollections.includes(collectionName)) return new Promise(() => {}) as Promise<S[]>;
|
|
195
|
-
if (this.failCollections.includes(collectionName)) {
|
|
196
|
-
throw new Error(`Simulated read error for collection: ${collectionName}`);
|
|
197
|
-
}
|
|
198
|
-
const db = this.DB[collectionName];
|
|
199
|
-
await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
|
|
200
|
-
return db.selectEntities(queryParams, queryOptions);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async count(
|
|
204
|
-
collectionName: string,
|
|
205
|
-
queryParams: QueryParams,
|
|
206
|
-
queryOptions?: QueryOptions,
|
|
207
|
-
): Promise<number> {
|
|
208
|
-
const result = await this.aggregate(collectionName, queryParams, queryOptions, {
|
|
209
|
-
count: ['count'],
|
|
210
|
-
});
|
|
211
|
-
await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
|
|
212
|
-
return result['count'];
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/*
|
|
216
|
-
* Example of aggregateSpec
|
|
217
|
-
* {
|
|
218
|
-
* countOfDocs: ['count'],
|
|
219
|
-
* totalPopulation: ['sum', 'population'],
|
|
220
|
-
* averagePopulation: ['average', 'population'],
|
|
221
|
-
* }
|
|
222
|
-
*/
|
|
223
|
-
async aggregate<S extends { [k: string]: number }>(
|
|
224
|
-
collectionName: string,
|
|
225
|
-
queryParams: QueryParams,
|
|
226
|
-
queryOptions: QueryOptions,
|
|
227
|
-
aggregateSpec: { [K in keyof S]: [string] | [string, string] },
|
|
228
|
-
): Promise<{ [K in keyof S]: number }> {
|
|
229
|
-
const store = this.DB[collectionName];
|
|
230
|
-
const entities = store.selectEntities(queryParams, queryOptions);
|
|
231
|
-
const result: Partial<{ [K in keyof S]: number }> = {};
|
|
232
|
-
for (const key in aggregateSpec) {
|
|
233
|
-
if (Object.prototype.hasOwnProperty.call(aggregateSpec, key)) {
|
|
234
|
-
const value = aggregateSpec[key];
|
|
235
|
-
|
|
236
|
-
if (value[0] === 'count') {
|
|
237
|
-
result[key] = entities.length;
|
|
238
|
-
} else if (value[0] === 'sum') {
|
|
239
|
-
result[key] = entities.reduce((s, e) => s + e[value[1]], 0);
|
|
240
|
-
} else if (value[0] === 'average') {
|
|
241
|
-
result[key] = entities.reduce((s, e) => s + e[value[1]], 0)/entities.length;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
await new Promise((resolve) => setTimeout(resolve, this.GET_LATENCY_SIMULATION_DELAY));
|
|
246
|
-
return result as { [K in keyof S]: number };
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
async addEntity(collectionName, entity, batch?) {
|
|
250
|
-
const store = this.DB[collectionName];
|
|
251
|
-
const entityFinal = Object.assign({}, entity, {
|
|
252
|
-
_createdAt: Timestamp.now(),
|
|
253
|
-
_updatedAt: Timestamp.now(),
|
|
254
|
-
_deleted: false,
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
if (batch) {
|
|
258
|
-
const docRef = {
|
|
259
|
-
path: `${collectionName}/${entity.__id}`,
|
|
260
|
-
};
|
|
261
|
-
return batch.set(docRef, entityFinal);
|
|
262
|
-
} else {
|
|
263
|
-
await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
|
|
264
|
-
return store.add(entityFinal);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async updateEntity(collectionName, id, changes, batch?) {
|
|
269
|
-
const store = this.DB[collectionName];
|
|
270
|
-
const changesFinal = Object.assign({}, changes, {
|
|
271
|
-
_updatedAt: Timestamp.now(),
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
if (batch) {
|
|
275
|
-
const docRef = {
|
|
276
|
-
path: `${collectionName}/${id}`,
|
|
277
|
-
};
|
|
278
|
-
return batch.update(docRef, changesFinal);
|
|
279
|
-
} else {
|
|
280
|
-
await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
|
|
281
|
-
return store.update(id, changesFinal);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async removeEntity(collectionName, id, batch?) {
|
|
286
|
-
const store = this.DB[collectionName];
|
|
287
|
-
const changes = {
|
|
288
|
-
_updatedAt: Timestamp.now(),
|
|
289
|
-
_deleted: true,
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
if (batch) {
|
|
293
|
-
const docRef = {
|
|
294
|
-
path: `${collectionName}/${id}`,
|
|
295
|
-
};
|
|
296
|
-
return batch.update(docRef, changes);
|
|
297
|
-
} else {
|
|
298
|
-
await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
|
|
299
|
-
return store.update(id, changes);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
async incrementEntityField(collectionName, id, field, delta) {
|
|
304
|
-
const store = this.DB[collectionName];
|
|
305
|
-
const entity = store.selectEntity(id);
|
|
306
|
-
const changes = {
|
|
307
|
-
_updatedAt: Timestamp.now(),
|
|
308
|
-
};
|
|
309
|
-
changes[field] = entity[field] + delta;
|
|
310
|
-
|
|
311
|
-
await new Promise((resolve) => setTimeout(resolve, this.PUT_LATENCY_SIMULATION_DELAY));
|
|
312
|
-
return await store.update(id, changes);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Creates provider configuration for FirebaseMockService with custom DB collection seeding.
|
|
318
|
-
*
|
|
319
|
-
* @param options.disableLatency - When true, sets GET and PUT latency simulation delays to 0ms.
|
|
320
|
-
* Use this in spec files to avoid the `APP_INITIALIZER` boilerplate for zeroing latency.
|
|
321
|
-
* See TEST-AP-005 in testing-guide.md.
|
|
322
|
-
* @param options.failCollections - Collections that throw/reject on any read operation.
|
|
323
|
-
* The property is mutable mid-test via `db.failCollections = [...]` to simulate
|
|
324
|
-
* error → recovery flows (e.g., set failCollections, verify error banner,
|
|
325
|
-
* clear failCollections, click Retry, verify recovery).
|
|
326
|
-
* @param options.stallCollections - Collections where reads never emit/resolve, simulating
|
|
327
|
-
* perpetual loading. Mutable mid-test via `db.stallCollections = [...]`.
|
|
328
|
-
*/
|
|
329
|
-
export function provideFirebaseMock({
|
|
330
|
-
users,
|
|
331
|
-
userContexts,
|
|
332
|
-
userPrivates,
|
|
333
|
-
disableLatency,
|
|
334
|
-
failCollections,
|
|
335
|
-
stallCollections,
|
|
336
|
-
}: {
|
|
337
|
-
users?: any[];
|
|
338
|
-
userContexts?: any[];
|
|
339
|
-
userPrivates?: any[];
|
|
340
|
-
disableLatency?: boolean;
|
|
341
|
-
/** Collections that throw/reject on any read. Mutable mid-test via `db.failCollections`. */
|
|
342
|
-
failCollections?: string[];
|
|
343
|
-
/** Collections where reads never emit/resolve. Mutable mid-test via `db.stallCollections`. */
|
|
344
|
-
stallCollections?: string[];
|
|
345
|
-
} = {}): Provider[] {
|
|
346
|
-
return [
|
|
347
|
-
{
|
|
348
|
-
provide: FirebaseMockService,
|
|
349
|
-
useFactory: (injector: Injector) => {
|
|
350
|
-
const service = new FirebaseMockService(injector);
|
|
351
|
-
if (disableLatency) {
|
|
352
|
-
service.GET_LATENCY_SIMULATION_DELAY = 0;
|
|
353
|
-
service.PUT_LATENCY_SIMULATION_DELAY = 0;
|
|
354
|
-
}
|
|
355
|
-
if (failCollections) service.failCollections = failCollections;
|
|
356
|
-
if (stallCollections) service.stallCollections = stallCollections;
|
|
357
|
-
if (users) service.DB['users'].init(users);
|
|
358
|
-
if (userContexts) service.DB['userContexts'].init(userContexts);
|
|
359
|
-
if (userPrivates) service.DB['userPrivates'].init(userPrivates);
|
|
360
|
-
return service;
|
|
361
|
-
},
|
|
362
|
-
deps: [Injector],
|
|
363
|
-
},
|
|
364
|
-
{ provide: DATABASE_SERVICE, useExisting: FirebaseMockService },
|
|
365
|
-
];
|
|
366
|
-
}
|
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { Injectable, inject, InjectionToken } from '@angular/core';
|
|
2
|
-
import { Observable, combineLatest, merge, of, from, pipe } from 'rxjs';
|
|
3
|
-
import { tap, pluck, mergeMap, filter, takeUntil, skip, switchMap, map, take } from 'rxjs/operators';
|
|
4
|
-
import { environment } from '../../../environments/environment';
|
|
5
|
-
import { Firestore, DocumentSnapshot, serverTimestamp, sum, count, average, Timestamp, getDoc, getDocs, doc, setDoc, updateDoc, deleteDoc, docData, collection, collectionData, collectionChanges, query, where, orderBy, OrderByDirection, limit, startAt, startAfter, endAt, endBefore, DocumentChange, increment, AggregateQuerySnapshot, AggregateField, AggregateSpec, getAggregateFromServer, getCountFromServer, writeBatch, WriteBatch } from '@angular/fire/firestore';
|
|
6
|
-
import { Auth, user, User, signInWithPopup, signInWithCredential, signOut, linkWithPopup, linkWithCredential, fetchSignInMethodsForEmail, GoogleAuthProvider, GithubAuthProvider } from '@angular/fire/auth';
|
|
7
|
-
import { QueryParams, QueryOptions, AnyEntity } from '../store/app.model';
|
|
8
|
-
import { DatabaseService } from './database.service';
|
|
9
|
-
|
|
10
|
-
@Injectable({
|
|
11
|
-
providedIn: 'root',
|
|
12
|
-
})
|
|
13
|
-
export class FirebaseService implements DatabaseService {
|
|
14
|
-
private afAuth = inject(Auth);
|
|
15
|
-
private firestore = inject(Firestore);
|
|
16
|
-
private user$ = user(this.afAuth);
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
) { }
|
|
20
|
-
|
|
21
|
-
/** Creates a unique id */
|
|
22
|
-
createId(): string {
|
|
23
|
-
// see https://stackoverflow.com/questions/56574593/access-firestore-id-generator-on-the-front-end?noredirect=1&lq=1
|
|
24
|
-
// see https://github.com/firebase/firebase-js-sdk/blob/73a586c92afe3f39a844b2be86086fddb6877bb7/packages/firestore/src/util/misc.ts#L36
|
|
25
|
-
// Alphanumeric characters
|
|
26
|
-
const chars =
|
|
27
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
28
|
-
let autoId = '';
|
|
29
|
-
for (let i = 0; i < 20; i++) {
|
|
30
|
-
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
31
|
-
}
|
|
32
|
-
return autoId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
afUser(): Observable<User | null> {
|
|
36
|
-
return from(this.afAuth.authStateReady()).pipe(
|
|
37
|
-
switchMap(() => this.user$),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
login(providerId, scope?: string): any {
|
|
42
|
-
const provider = this.getProvider(providerId, scope);
|
|
43
|
-
|
|
44
|
-
if (provider) {
|
|
45
|
-
return signInWithPopup(this.afAuth, provider);
|
|
46
|
-
} else {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private getProvider(providerId, scope?: string) {
|
|
52
|
-
let provider;
|
|
53
|
-
switch (providerId) {
|
|
54
|
-
case 'google.com': {
|
|
55
|
-
provider = new GoogleAuthProvider();
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case 'github.com': {
|
|
59
|
-
provider = new GithubAuthProvider();
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (provider && scope) {
|
|
64
|
-
provider.addScope(scope);
|
|
65
|
-
}
|
|
66
|
-
return provider;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
loginLink(error) {
|
|
70
|
-
fetchSignInMethodsForEmail(this.afAuth, error.email)
|
|
71
|
-
.then(async (providers) => {
|
|
72
|
-
const provider = this.getProvider(providers[0]);
|
|
73
|
-
|
|
74
|
-
// This only handles if you already had an OAuthProvider user and are now signing in with email for first time
|
|
75
|
-
// Thus, it starts by signing into the OAuthProvider account with popup, then linking it together
|
|
76
|
-
// If we want to do the reverse, need to have them sign in with email
|
|
77
|
-
// If we want to link two OAuth, then see https://firebase.google.com/docs/auth/web/account-linking#web-modular-api_6
|
|
78
|
-
signInWithPopup(this.afAuth, provider).then((result) => {
|
|
79
|
-
const credential = provider.credentialFromResult(result);
|
|
80
|
-
signInWithCredential(this.afAuth, credential).then((result2) => {
|
|
81
|
-
linkWithCredential(result2.user, error.credential);
|
|
82
|
-
});
|
|
83
|
-
console.log('Successfully linked');
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async logout() {
|
|
89
|
-
await signOut(this.afAuth);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
streamEntity<T>(collectionName: string, id: string) {
|
|
93
|
-
const docRef = doc(this.firestore, `${collectionName}/${id}`);
|
|
94
|
-
return docData(docRef) as Observable<T>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
streamEntities<T>(collectionName, queryParams, queryOptions?) {
|
|
98
|
-
const collectionRef = collection(this.firestore, collectionName);
|
|
99
|
-
if (queryParams.length === 0 && (!queryOptions || Object.keys(queryOptions).length === 0)) {
|
|
100
|
-
return collectionData(collectionRef) as Observable<T[]>;
|
|
101
|
-
} else {
|
|
102
|
-
return collectionData(
|
|
103
|
-
query(collectionRef, ...this.constructQueryListRefMod(queryParams, queryOptions)),
|
|
104
|
-
) as Observable<T[]>;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
streamEntitiesChanges<T>(collectionName, queryParams, queryOptions?): Observable<{
|
|
109
|
-
type: string;
|
|
110
|
-
docData: T;
|
|
111
|
-
}[]> {
|
|
112
|
-
let stateChangeObs$;
|
|
113
|
-
const collectionRef = collection(this.firestore, collectionName);
|
|
114
|
-
|
|
115
|
-
if (queryParams.length === 0 && (!queryOptions || Object.keys(queryOptions).length === 0)) {
|
|
116
|
-
stateChangeObs$ = collectionChanges(collectionRef);
|
|
117
|
-
} else {
|
|
118
|
-
stateChangeObs$ = collectionChanges(
|
|
119
|
-
query(collectionRef, ...this.constructQueryListRefMod(queryParams, queryOptions)),
|
|
120
|
-
) as Observable<DocumentChange<T>[]>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return stateChangeObs$.pipe(
|
|
124
|
-
map((changes: DocumentChange<T>[]) => {
|
|
125
|
-
return changes.map((dc) => ({
|
|
126
|
-
type: dc.type,
|
|
127
|
-
docData: dc.doc.data(),
|
|
128
|
-
}));
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private constructQueryListRefMod(queryParams, queryOptions?) {
|
|
134
|
-
// Convert queryParams to queryArray
|
|
135
|
-
// Note: firestore supports setting and querying for null, but not
|
|
136
|
-
// undefined. We filter out cases where the value is undefined
|
|
137
|
-
// to protect against cases when people are doing a nested query
|
|
138
|
-
// and some entity does not have a particular field, e.g.
|
|
139
|
-
// [['__hashtagId', '==', q.__hashtagId]] when __hashtagId is
|
|
140
|
-
// an optional parameter
|
|
141
|
-
const queryArray = queryParams
|
|
142
|
-
.filter((query) => query[2] !== undefined)
|
|
143
|
-
.map((query) => {
|
|
144
|
-
const [prop, comp, val] = query;
|
|
145
|
-
return where(prop, comp, val);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Add queryOptions to queryArray
|
|
149
|
-
if (queryOptions) {
|
|
150
|
-
Object.keys(queryOptions).forEach((queryKey) => {
|
|
151
|
-
switch (queryKey) {
|
|
152
|
-
case 'orderBy': {
|
|
153
|
-
if (Array.isArray(queryOptions.orderBy)) {
|
|
154
|
-
if (Array.isArray(queryOptions.orderBy[0])) {
|
|
155
|
-
for (const order of queryOptions.orderBy) {
|
|
156
|
-
queryArray.push(orderBy(order[0], order[1] as OrderByDirection));
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
queryArray.push(orderBy(queryOptions.orderBy[0] as string, queryOptions.orderBy[1] as OrderByDirection));
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
queryArray.push(orderBy(queryOptions.orderBy));
|
|
163
|
-
}
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
case 'limit':
|
|
167
|
-
queryArray.push(limit(queryOptions.limit));
|
|
168
|
-
break;
|
|
169
|
-
|
|
170
|
-
case 'startAt':
|
|
171
|
-
queryArray.push(startAt(queryOptions.startAt));
|
|
172
|
-
break;
|
|
173
|
-
|
|
174
|
-
case 'startAfter':
|
|
175
|
-
queryArray.push(startAfter(queryOptions.startAfter));
|
|
176
|
-
break;
|
|
177
|
-
|
|
178
|
-
case 'endAt':
|
|
179
|
-
queryArray.push(endAt(queryOptions.endAt));
|
|
180
|
-
break;
|
|
181
|
-
|
|
182
|
-
case 'endBefore':
|
|
183
|
-
queryArray.push(endBefore(queryOptions.endBefore));
|
|
184
|
-
break;
|
|
185
|
-
|
|
186
|
-
default:
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return queryArray;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async getEntity<T>(collectionName: string, id: string) {
|
|
195
|
-
const docRef = doc(this.firestore, `${collectionName}/${id}`);
|
|
196
|
-
const docSnap = await getDoc(docRef) as DocumentSnapshot<T, T>;
|
|
197
|
-
|
|
198
|
-
if (docSnap.exists()) {
|
|
199
|
-
return docSnap.data();
|
|
200
|
-
} else {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async getEntities<S>(
|
|
206
|
-
collectionName: string,
|
|
207
|
-
queryParams: [string, string, any][],
|
|
208
|
-
queryOptions?: { [index: string]: any },
|
|
209
|
-
): Promise<S[]> {
|
|
210
|
-
const collectionRef = collection(this.firestore, collectionName);
|
|
211
|
-
let querySnapshot;
|
|
212
|
-
if (queryParams.length === 0 && (!queryOptions || Object.keys(queryOptions).length === 0)) {
|
|
213
|
-
querySnapshot = await getDocs(collectionRef);
|
|
214
|
-
} else {
|
|
215
|
-
querySnapshot = await getDocs(
|
|
216
|
-
query(collectionRef, ...this.constructQueryListRefMod(queryParams, queryOptions)),
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
const entities = querySnapshot.docs.map((doc) => doc.data());
|
|
220
|
-
return entities;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async count(
|
|
224
|
-
collectionName: string,
|
|
225
|
-
queryParams: QueryParams,
|
|
226
|
-
queryOptions?: QueryOptions,
|
|
227
|
-
): Promise<number> {
|
|
228
|
-
const collectionRef = collection(this.firestore, collectionName);
|
|
229
|
-
let querySnapshot;
|
|
230
|
-
if (queryParams.length === 0 && (!queryOptions || Object.keys(queryOptions).length === 0)) {
|
|
231
|
-
querySnapshot = await getCountFromServer(collectionRef);
|
|
232
|
-
} else {
|
|
233
|
-
querySnapshot = await getCountFromServer(
|
|
234
|
-
query(collectionRef, ...this.constructQueryListRefMod(queryParams, queryOptions)),
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
return querySnapshot.data().count;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/*
|
|
241
|
-
* Example of aggregateSpec
|
|
242
|
-
* {
|
|
243
|
-
* countOfDocs: ['count'],
|
|
244
|
-
* totalPopulation: ['sum', 'population'],
|
|
245
|
-
* averagePopulation: ['average', 'population'],
|
|
246
|
-
* }
|
|
247
|
-
*/
|
|
248
|
-
async aggregate<S extends { [k: string]: number }>(
|
|
249
|
-
collectionName: string,
|
|
250
|
-
queryParams: QueryParams,
|
|
251
|
-
queryOptions: QueryOptions,
|
|
252
|
-
aggregateParams: { [K in keyof S]: [string] | [string, string] },
|
|
253
|
-
): Promise<{ [K in keyof S]: number }> {
|
|
254
|
-
const collectionRef = collection(this.firestore, collectionName);
|
|
255
|
-
let querySnapshot;
|
|
256
|
-
|
|
257
|
-
const aggregateSpec: AggregateSpec = {};
|
|
258
|
-
|
|
259
|
-
for (const key in aggregateParams) {
|
|
260
|
-
if (key === 'count') {
|
|
261
|
-
aggregateSpec[key] = count();
|
|
262
|
-
} else if (key === 'sum') {
|
|
263
|
-
aggregateSpec[key] = sum(aggregateParams[key][1]);
|
|
264
|
-
} else if (key === 'average') {
|
|
265
|
-
aggregateSpec[key] = average(aggregateParams[key][1]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (queryParams.length === 0 && (!queryOptions || Object.keys(queryOptions).length === 0)) {
|
|
270
|
-
querySnapshot = await getAggregateFromServer(collectionRef, aggregateSpec);
|
|
271
|
-
} else {
|
|
272
|
-
querySnapshot = await getAggregateFromServer(
|
|
273
|
-
query(collectionRef, ...this.constructQueryListRefMod(queryParams, queryOptions)),
|
|
274
|
-
aggregateSpec,
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
return querySnapshot.data();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async addEntity(
|
|
281
|
-
collectionName: string,
|
|
282
|
-
entity: AnyEntity,
|
|
283
|
-
batch?: WriteBatch,
|
|
284
|
-
) {
|
|
285
|
-
const docRef = doc(this.firestore, `${collectionName}/${entity.__id}`);
|
|
286
|
-
const entityFinal = Object.assign({}, entity, {
|
|
287
|
-
_createdAt: serverTimestamp(),
|
|
288
|
-
_updatedAt: serverTimestamp(),
|
|
289
|
-
_deleted: false,
|
|
290
|
-
});
|
|
291
|
-
if (batch) {
|
|
292
|
-
return batch.set(docRef, entityFinal);
|
|
293
|
-
} else {
|
|
294
|
-
return setDoc(docRef, entityFinal);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async updateEntity(
|
|
299
|
-
collectionName: string,
|
|
300
|
-
id: string,
|
|
301
|
-
changes: Partial<AnyEntity>,
|
|
302
|
-
batch?: WriteBatch,
|
|
303
|
-
) {
|
|
304
|
-
const docRef = doc(this.firestore, `${collectionName}/${id}`);
|
|
305
|
-
const changesFinal = Object.assign({}, changes, {
|
|
306
|
-
_updatedAt: serverTimestamp(),
|
|
307
|
-
});
|
|
308
|
-
if (batch) {
|
|
309
|
-
return batch.update(docRef, changesFinal);
|
|
310
|
-
} else {
|
|
311
|
-
return updateDoc(docRef, changesFinal);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async removeEntity(
|
|
316
|
-
collectionName: string,
|
|
317
|
-
id: string,
|
|
318
|
-
batch?: WriteBatch,
|
|
319
|
-
) {
|
|
320
|
-
const docRef = doc(this.firestore, `${collectionName}/${id}`);
|
|
321
|
-
// we do soft deletes from client side
|
|
322
|
-
const changes = {
|
|
323
|
-
_updatedAt: serverTimestamp(),
|
|
324
|
-
_deleted: true,
|
|
325
|
-
};
|
|
326
|
-
if (batch) {
|
|
327
|
-
return batch.update(docRef, changes);
|
|
328
|
-
} else {
|
|
329
|
-
return updateDoc(docRef, changes);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
async incrementEntityField(collectionName, id, field, delta) {
|
|
334
|
-
const docRef = doc(this.firestore, collectionName, id);
|
|
335
|
-
const changes = {};
|
|
336
|
-
changes[field] = increment(delta);
|
|
337
|
-
|
|
338
|
-
return updateDoc(docRef, Object.assign({}, changes, {
|
|
339
|
-
_updatedAt: serverTimestamp(),
|
|
340
|
-
}));
|
|
341
|
-
}
|
|
342
|
-
}
|