@tech4good/angular-schematics 21.6.0 → 21.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +266 -1
  3. package/package.json +34 -7
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
  5. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
  6. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +14 -6
  7. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +12 -6
  8. package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
  9. package/src/entity/index.js +4 -49
  10. package/src/entity/index.js.map +1 -1
  11. package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
  12. package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
  13. package/src/ng-add/files/.gitignore.template +3 -0
  14. package/src/ng-add/files/analytics/datasets.js.template +206 -0
  15. package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
  16. package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
  17. package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
  18. package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
  19. package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
  20. package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
  21. package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
  22. package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
  23. package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
  24. package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
  25. package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
  26. package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
  27. package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
  28. package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
  29. package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
  30. package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
  31. package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
  32. package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
  33. package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
  34. package/src/ng-add/files/analytics/server/server.js.template +212 -0
  35. package/src/ng-add/files/angular.json.template +80 -1
  36. package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
  37. package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
  38. package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
  39. package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
  40. package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
  41. package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
  42. package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
  43. package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
  44. package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
  45. package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
  46. package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
  47. package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
  48. package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
  49. package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
  50. package/src/ng-add/files/docs-infra/authentication-architecture.md.template +54 -24
  51. package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
  52. package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
  53. package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +108 -29
  54. package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
  55. package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
  56. package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
  57. package/src/ng-add/files/eslint.config.js.template +22 -3
  58. package/src/ng-add/files/functions/package.json.template +1 -0
  59. package/src/ng-add/files/functions/src/email.ts.template +23 -0
  60. package/src/ng-add/files/jest.config.ts.template +3 -2
  61. package/src/ng-add/files/package.json.template +39 -16
  62. package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
  63. package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
  64. package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
  65. package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
  66. package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
  67. package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
  68. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
  69. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
  70. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
  71. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
  72. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
  73. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
  74. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
  75. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
  76. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
  77. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
  78. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
  79. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
  80. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
  81. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
  82. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
  83. package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
  84. package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
  85. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
  86. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
  87. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
  88. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
  89. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
  90. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
  91. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
  92. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
  93. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
  94. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
  95. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
  96. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
  97. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
  98. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
  99. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
  100. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
  101. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
  102. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
  103. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
  104. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
  105. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
  106. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
  107. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
  108. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
  109. package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
  110. package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
  111. package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
  112. package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
  113. package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
  114. package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
  115. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +4 -5
  116. package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
  117. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
  118. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
  119. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +8 -10
  120. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
  121. package/src/ng-add/files/src/app/app.component.html.template +1 -1
  122. package/src/ng-add/files/src/app/app.component.scss.template +1 -1
  123. package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
  124. package/src/ng-add/files/src/app/app.component.ts.template +1 -2
  125. package/src/ng-add/files/src/app/app.config.ts.template +21 -15
  126. package/src/ng-add/files/src/app/auth-routing.spec.ts.template +4 -5
  127. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
  128. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
  129. package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
  130. package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
  131. package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +9 -23
  132. package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +3 -14
  133. package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
  134. package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
  135. package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
  136. package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
  137. package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
  138. package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +19 -67
  139. package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +102 -12
  140. package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +32 -237
  141. package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +17 -12
  142. package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +6 -7
  143. package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
  144. package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
  145. package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
  146. package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
  147. package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
  148. package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +5 -6
  149. package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
  150. package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
  151. package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
  152. package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
  153. package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
  154. package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
  155. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +15 -15
  156. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +11 -3
  157. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
  158. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
  159. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
  160. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
  161. package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
  162. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +17 -1
  163. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +15 -0
  164. package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +4 -5
  165. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +15 -0
  166. package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +2 -0
  167. package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +21 -3
  168. package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +26 -0
  169. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
  170. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
  171. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +2 -2
  172. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +2 -2
  173. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +4 -4
  174. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +2 -2
  175. package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
  176. package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -1
  177. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +4 -4
  178. package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +2 -2
  179. package/src/ng-add/files/tsconfig.spec.json.template +3 -1
  180. package/src/ng-add/index.js +7 -0
  181. package/src/ng-add/index.js.map +1 -1
  182. package/src/shared/entity-registry.d.ts +8 -0
  183. package/src/shared/entity-registry.js +28 -0
  184. package/src/shared/entity-registry.js.map +1 -0
  185. package/.agents/skills/publish-npm/SKILL.md +0 -37
  186. package/.agents/skills/publish-npm/eval.yaml +0 -32
  187. package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
  188. package/.husky/commit-msg +0 -1
  189. package/.husky/pre-commit +0 -1
  190. package/.t4g/agent-memory.db +0 -0
  191. package/src/component/index_spec.d.ts +0 -1
  192. package/src/component/index_spec.js +0 -68
  193. package/src/component/index_spec.js.map +0 -1
  194. package/src/entity/index_spec.d.ts +0 -1
  195. package/src/entity/index_spec.js +0 -153
  196. package/src/entity/index_spec.js.map +0 -1
  197. package/src/guard/index_spec.d.ts +0 -1
  198. package/src/guard/index_spec.js +0 -64
  199. package/src/guard/index_spec.js.map +0 -1
  200. package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
  201. package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
  202. package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -500
  203. package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -73
  204. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +0 -59
  205. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +0 -147
  206. package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -453
  207. package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +0 -116
  208. package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -639
  209. package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
  210. package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
  211. package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
  212. package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
  213. package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
  214. package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
  215. package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
  216. package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
  217. package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1320
  218. package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
  219. package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
  220. package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
  221. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
  222. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
  223. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
  224. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
  225. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
  226. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
  227. package/src/ng-add/index_spec.d.ts +0 -1
  228. package/src/ng-add/index_spec.js +0 -108
  229. package/src/ng-add/index_spec.js.map +0 -1
@@ -14,7 +14,6 @@ describe('<%= camelize(name) %> (handleAccess)', () => {
14
14
  name: 'Test User',
15
15
  email: 'test@test.com',
16
16
  isAdmin: false,
17
- isMentor: false,
18
17
  accessState: AccessState.DONE,
19
18
  consented: true,
20
19
  _createdAt: Timestamp.now(),
@@ -62,6 +62,9 @@ jobs:
62
62
  - name: 🛡️ Test Firestore Rules
63
63
  run: npm run test:rules
64
64
 
65
+ - name: 🔍 Check Firestore Indexes
66
+ run: npm run check:indexes
67
+
65
68
  - name: 🏗️ Build Project
66
69
  run: npm run build
67
70
 
@@ -60,3 +60,6 @@ Thumbs.db
60
60
  *.log
61
61
  .t4g/
62
62
  .impeccable/
63
+
64
+ # Rebuildable local analytics snapshots and private pseudonymization salt
65
+ /.local/analytics/
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Analytics Dataset Registry
3
+ *
4
+ * Defines the schema and API contract for all local analytics datasets.
5
+ *
6
+ * Privacy Invariants:
7
+ * - Datasets must define a privacy level (`aggregate` vs `deidentified-observation`).
8
+ * - Raw text or non-pseudonymized identifiers must never be exposed to local clients.
9
+ *
10
+ * Admin Traffic Variants:
11
+ * - Datasets with `adminVariants: true` are computed twice during refresh:
12
+ * once with admin traffic included (_includes_admin = 1) and once without
13
+ * (_includes_admin = 0). The Express API filters by the `includeAdmin`
14
+ * query parameter.
15
+ * - Datasets without `adminVariants` (e.g., data-quality, entity tables) are
16
+ * stored once and served regardless of the toggle state.
17
+ */
18
+
19
+ // Helper factory functions to build typed column definition objects
20
+ const integer = (name, options = {}) => ({ name, type: 'INTEGER', ...options });
21
+ const real = (name, options = {}) => ({ name, type: 'REAL', ...options });
22
+ const text = (name, options = {}) => ({ name, type: 'TEXT', ...options });
23
+
24
+ /** Registry of all analytics datasets. */
25
+ export const datasets = [
26
+ {
27
+ id: 'route-visits',
28
+ table: 'fact_route_visit',
29
+ sourceQuery: 'bigquery/queries/dashboard_route_visits.sql',
30
+ grain: 'One finalized deidentified route telemetry segment',
31
+ privacy: 'deidentified-observation',
32
+ requiresIdSalt: true,
33
+ adminVariants: true,
34
+ columns: [
35
+ integer('_includes_admin'),
36
+ text('visit_key', { primaryKey: true }),
37
+ text('journey_key'),
38
+ text('session_key'),
39
+ text('user_key'),
40
+ text('route'),
41
+ integer('started_at_ms'),
42
+ integer('active_ms'),
43
+ integer('rest_ms'),
44
+ ],
45
+ indexes: [['route'], ['started_at_ms'], ['journey_key'], ['_includes_admin']],
46
+ api: {
47
+ filterFields: ['route', 'journey_key', 'session_key'],
48
+ sortFields: ['route', 'started_at_ms', 'active_ms', 'rest_ms'],
49
+ defaultSort: 'started_at_ms',
50
+ defaultDirection: 'desc',
51
+ maxRows: 25000,
52
+ },
53
+ },
54
+ {
55
+ id: 'route-engagement',
56
+ table: 'agg_route_engagement',
57
+ sourceQuery: 'bigquery/queries/active_time_by_route.sql',
58
+ grain: 'One normalized route',
59
+ privacy: 'aggregate',
60
+ requiresIdSalt: true,
61
+ adminVariants: true,
62
+ columns: [
63
+ integer('_includes_admin'),
64
+ text('route', { primaryKey: true }),
65
+ integer('total_visits'),
66
+ real('mean_active_seconds'),
67
+ real('min_active_seconds'),
68
+ real('q1_active_seconds'),
69
+ real('median_active_seconds'),
70
+ real('q3_active_seconds'),
71
+ real('max_active_seconds'),
72
+ ],
73
+ indexes: [['total_visits'], ['_includes_admin']],
74
+ api: {
75
+ filterFields: ['route'],
76
+ sortFields: ['route', 'total_visits', 'mean_active_seconds', 'median_active_seconds'],
77
+ defaultSort: 'total_visits',
78
+ defaultDirection: 'desc',
79
+ maxRows: 1000,
80
+ },
81
+ },
82
+ {
83
+ id: 'onboarding-cohorts',
84
+ table: 'agg_onboarding_cohort',
85
+ sourceQuery: 'bigquery/queries/onboarding_funnel.sql',
86
+ grain: 'One stage in an acquisition or activation cohort',
87
+ privacy: 'aggregate',
88
+ requiresIdSalt: true,
89
+ adminVariants: true,
90
+ columns: [
91
+ integer('_includes_admin'),
92
+ text('cohort_stage_key', { primaryKey: true }),
93
+ text('analysis'),
94
+ text('stage'),
95
+ integer('stage_order'),
96
+ integer('journeys'),
97
+ real('conversion_from_cohort'),
98
+ ],
99
+ indexes: [['analysis', 'stage_order'], ['_includes_admin']],
100
+ api: {
101
+ filterFields: ['analysis', 'stage'],
102
+ sortFields: ['analysis', 'stage_order', 'journeys', 'conversion_from_cohort'],
103
+ defaultSort: 'stage_order',
104
+ defaultDirection: 'asc',
105
+ maxRows: 100,
106
+ },
107
+ },
108
+ {
109
+ id: 'active-user-windows',
110
+ table: 'agg_active_user_window',
111
+ sourceQuery: 'bigquery/queries/active_user_windows.sql',
112
+ grain: 'One calendar day with trailing 1-, 7-, and 30-day active identity windows',
113
+ privacy: 'aggregate',
114
+ requiresIdSalt: true,
115
+ adminVariants: true,
116
+ columns: [
117
+ integer('_includes_admin'),
118
+ text('activity_date', { primaryKey: true }),
119
+ integer('dau'),
120
+ integer('wau'),
121
+ integer('mau'),
122
+ ],
123
+ indexes: [['activity_date'], ['_includes_admin']],
124
+ api: {
125
+ filterFields: [],
126
+ sortFields: ['activity_date', 'dau', 'wau', 'mau'],
127
+ defaultSort: 'activity_date',
128
+ defaultDirection: 'desc',
129
+ maxRows: 5000,
130
+ },
131
+ },
132
+ {
133
+ id: 'weekly-retention-cohorts',
134
+ table: 'agg_weekly_retention_cohort',
135
+ sourceQuery: 'bigquery/queries/weekly_retention_cohorts.sql',
136
+ grain: 'One first-active-week cohort at one elapsed week',
137
+ privacy: 'aggregate',
138
+ requiresIdSalt: true,
139
+ adminVariants: true,
140
+ columns: [
141
+ integer('_includes_admin'),
142
+ text('retention_key', { primaryKey: true }),
143
+ text('cohort_week'),
144
+ integer('weeks_since_first_active'),
145
+ integer('active_users'),
146
+ integer('cohort_size'),
147
+ real('retention_rate'),
148
+ ],
149
+ indexes: [['cohort_week', 'weeks_since_first_active'], ['_includes_admin']],
150
+ api: {
151
+ filterFields: ['cohort_week', 'weeks_since_first_active'],
152
+ sortFields: ['cohort_week', 'weeks_since_first_active', 'active_users', 'cohort_size', 'retention_rate'],
153
+ defaultSort: 'cohort_week',
154
+ defaultDirection: 'desc',
155
+ maxRows: 10000,
156
+ },
157
+ },
158
+ {
159
+ id: 'user-dimensions',
160
+ table: 'dim_user',
161
+ entitySource: 'user-dimensions',
162
+ uploadToBigQuery: true,
163
+ grain: 'One de-identified user entity record',
164
+ privacy: 'deidentified-observation',
165
+ requiresIdSalt: true,
166
+ columns: [
167
+ text('user_key', { primaryKey: true }),
168
+ text('role'),
169
+ text('access_state'),
170
+ integer('source_created_at_ms'),
171
+ integer('source_updated_at_ms'),
172
+ ],
173
+ indexes: [['role'], ['access_state']],
174
+ api: {
175
+ filterFields: ['role', 'access_state'],
176
+ sortFields: ['user_key', 'role', 'access_state', 'source_created_at_ms'],
177
+ defaultSort: 'user_key',
178
+ defaultDirection: 'asc',
179
+ maxRows: 10000,
180
+ },
181
+ },
182
+ {
183
+ id: 'data-quality',
184
+ table: 'agg_data_quality',
185
+ sourceQuery: 'bigquery/queries/data_quality.sql',
186
+ grain: 'One snapshot-level diagnostic',
187
+ privacy: 'aggregate',
188
+ columns: [
189
+ text('metric', { primaryKey: true }),
190
+ integer('value'),
191
+ text('severity'),
192
+ text('detail'),
193
+ ],
194
+ indexes: [['severity']],
195
+ api: {
196
+ filterFields: ['severity'],
197
+ sortFields: ['metric', 'value', 'severity'],
198
+ defaultSort: 'severity',
199
+ defaultDirection: 'asc',
200
+ maxRows: 1000,
201
+ },
202
+ },
203
+ ];
204
+
205
+ /** Lookup map by dataset ID. */
206
+ export const datasetsById = new Map(datasets.map((dataset) => [dataset.id, dataset]));
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Firestore Entity Sources Registry (`entity_sources.js`)
3
+ *
4
+ * Registers Firestore entity mappers to pull incremental updates from the
5
+ * Firestore `users` collection into local SQLite tables.
6
+ *
7
+ * Privacy Invariant:
8
+ * Derived entity mappers MUST strip raw PII (emails, real names) and apply
9
+ * salted HMAC hashing (`pseudonymousEntityKey`) to all user IDs.
10
+ */
11
+
12
+ import { createHash } from 'node:crypto';
13
+
14
+ /** Returns string or empty string if non-string */
15
+ function asString(value) {
16
+ return typeof value === 'string' ? value : '';
17
+ }
18
+
19
+ /** Generates SHA256 pseudonymous key using idSalt */
20
+ export function pseudonymousEntityKey(idSalt, value) {
21
+ if (value === null || value === undefined || value === '') return null;
22
+ return createHash('sha256')
23
+ .update(`${idSalt}:${String(value)}:${idSalt}`)
24
+ .digest('hex');
25
+ }
26
+
27
+ /** Derives non-PII user dimension features from Firestore `users` documents */
28
+ export function deriveUserEntity(data, context) {
29
+ return {
30
+ user_key: pseudonymousEntityKey(context.idSalt, context.documentId),
31
+ role: data.isAdmin === true ? 'admin' : 'user',
32
+ access_state: asString(data.accessState) || null,
33
+ source_created_at_ms: context.sourceCreatedAtMs,
34
+ source_updated_at_ms: context.sourceUpdatedAtMs,
35
+ };
36
+ }
37
+
38
+ function materializeRows(cachedRows) {
39
+ return cachedRows.map((row) => row.derived);
40
+ }
41
+
42
+ /** Entity dataset derivation definitions map */
43
+ export const entityDatasetDefinitions = new Map([
44
+ [
45
+ 'user-dimensions',
46
+ {
47
+ analysisVersion: 4,
48
+ sources: [
49
+ {
50
+ id: 'users',
51
+ collection: 'users',
52
+ derive: deriveUserEntity,
53
+ },
54
+ ],
55
+ materialize: materializeRows,
56
+ },
57
+ ],
58
+ ]);
@@ -0,0 +1,57 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { deriveUserEntity, pseudonymousEntityKey } from './entity_sources.js';
4
+
5
+ describe('entity_sources mapping', () => {
6
+ const context = {
7
+ idSalt: 'test-salt-123',
8
+ documentId: 'user_abc123',
9
+ sourceUpdatedAtMs: 1700000000000,
10
+ sourceCreatedAtMs: 1690000000000,
11
+ };
12
+
13
+ it('correctly maps Firestore user document to a pseudonymous dim_user record', () => {
14
+ const rawDoc = {
15
+ isAdmin: true,
16
+ accessState: 'DONE',
17
+ email: 'secret@example.com', // PII — must not appear in output
18
+ };
19
+
20
+ const derived = deriveUserEntity(rawDoc, context);
21
+
22
+ assert.equal(derived.user_key, pseudonymousEntityKey('test-salt-123', 'user_abc123'));
23
+ assert.match(derived.user_key, /^[0-9a-f]{64}$/);
24
+ assert.equal(derived.role, 'admin');
25
+ assert.equal(derived.access_state, 'DONE');
26
+ assert.equal(derived.source_created_at_ms, 1690000000000);
27
+ assert.equal(derived.source_updated_at_ms, 1700000000000);
28
+ // Verifies PII fields are stripped
29
+ assert.equal(derived.email, undefined);
30
+ });
31
+
32
+ it('passes through sourceCreatedAtMs from context (timestamp conversion is in entity_sync)', () => {
33
+ const derived = deriveUserEntity({}, {
34
+ ...context,
35
+ sourceCreatedAtMs: 1695555000000,
36
+ });
37
+ assert.equal(derived.source_created_at_ms, 1695555000000);
38
+ });
39
+
40
+ it('returns null sourceCreatedAtMs when context has null', () => {
41
+ const derived = deriveUserEntity({}, {
42
+ ...context,
43
+ sourceCreatedAtMs: null,
44
+ });
45
+ assert.equal(derived.source_created_at_ms, null);
46
+ });
47
+
48
+ it('defaults role to "user" when not provided', () => {
49
+ const derived = deriveUserEntity({}, context);
50
+ assert.equal(derived.role, 'user');
51
+ });
52
+
53
+ it('does not treat a legacy role string as an admin flag', () => {
54
+ const derived = deriveUserEntity({ role: 'admin', isAdmin: false }, context);
55
+ assert.equal(derived.role, 'user');
56
+ });
57
+ });
@@ -0,0 +1,87 @@
1
+ /**
2
+ * SQLite API Query Builder
3
+ *
4
+ * Builds parameterized SQL queries for the Express proxy API.
5
+ * Validates client parameters against dataset schema contracts to prevent
6
+ * SQL injection and ensure safe constraints (pagination, allowlists).
7
+ *
8
+ * Admin Traffic Filtering:
9
+ * For datasets with `adminVariants: true`, the builder appends a
10
+ * `_includes_admin = ?` filter based on the `includeAdmin` query parameter.
11
+ */
12
+
13
+ import { quoteIdentifier } from './dataset_schema.js';
14
+
15
+ /**
16
+ * @param {object} dataset
17
+ * @param {URL} url
18
+ * @returns {{ sql: string, params: Array<any>, limit: number, offset: number }}
19
+ */
20
+ export function queryForDataset(dataset, url) {
21
+ const api = dataset.api;
22
+ const where = [];
23
+ const params = [];
24
+
25
+ // Admin traffic variant filtering — only for datasets that have dual variants
26
+ if (dataset.adminVariants) {
27
+ const includeAdmin = url.searchParams.get('includeAdmin') === '1' ? 1 : 0;
28
+ where.push('"_includes_admin" = ?');
29
+ params.push(includeAdmin);
30
+ }
31
+
32
+ for (const [name, value] of url.searchParams.entries()) {
33
+ if (!name.startsWith('filter.')) continue;
34
+ const field = name.slice('filter.'.length);
35
+ if (!api.filterFields.includes(field)) {
36
+ throw new Error(`Filter "${field}" is not allowed for ${dataset.id}.`);
37
+ }
38
+ where.push(`${quoteIdentifier(field)} = ?`);
39
+ params.push(value);
40
+ }
41
+
42
+
43
+ const requestedSort = url.searchParams.get('sort');
44
+ const sort = requestedSort || api.defaultSort;
45
+ if (sort && !api.sortFields.includes(sort)) {
46
+ throw new Error(`Sort "${sort}" is not allowed for ${dataset.id}.`);
47
+ }
48
+
49
+
50
+ const requestedDirection = (
51
+ url.searchParams.get('direction') ||
52
+ api.defaultDirection ||
53
+ 'asc'
54
+ ).toLowerCase();
55
+ if (!['asc', 'desc'].includes(requestedDirection)) {
56
+ throw new Error('Sort direction must be asc or desc.');
57
+ }
58
+
59
+
60
+ const requestedLimit = Number(url.searchParams.get('limit') || api.maxRows);
61
+ const limit = Math.min(
62
+ Number.isInteger(requestedLimit) && requestedLimit > 0 ?
63
+ requestedLimit :
64
+ api.maxRows,
65
+ api.maxRows,
66
+ );
67
+ const requestedOffset = Number(url.searchParams.get('offset') || 0);
68
+ const offset =
69
+ Number.isInteger(requestedOffset) && requestedOffset >= 0 ?
70
+ requestedOffset :
71
+ 0;
72
+
73
+
74
+ const clauses = [
75
+ `SELECT * FROM ${quoteIdentifier(dataset.table)}`,
76
+ where.length ? `WHERE ${where.join(' AND ')}` : '',
77
+ sort ? `ORDER BY ${quoteIdentifier(sort)} ${requestedDirection.toUpperCase()}` : '',
78
+ 'LIMIT ? OFFSET ?',
79
+ ].filter(Boolean);
80
+
81
+ return {
82
+ sql: clauses.join(' '),
83
+ params: [...params, limit, offset],
84
+ limit,
85
+ offset,
86
+ };
87
+ }
@@ -0,0 +1,84 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { datasetsById } from '../datasets.js';
4
+ import { queryForDataset } from './api_query.js';
5
+
6
+ const routeDataset = datasetsById.get('route-engagement');
7
+ const qualityDataset = datasetsById.get('data-quality');
8
+
9
+ describe('analytics API query allowlists', () => {
10
+ it('uses parameters for allowlisted filters and caps requested rows', () => {
11
+ const url = new URL(
12
+ 'http://localhost/api/datasets/route-engagement?' +
13
+ 'filter.route=%2Fhome&sort=median_active_seconds&direction=asc&limit=99999',
14
+ );
15
+
16
+ const query = queryForDataset(routeDataset, url);
17
+
18
+ // _includes_admin filter is prepended automatically for adminVariants datasets
19
+ assert.equal(
20
+ query.sql,
21
+ 'SELECT * FROM "agg_route_engagement" WHERE "_includes_admin" = ? AND "route" = ? ' +
22
+ 'ORDER BY "median_active_seconds" ASC LIMIT ? OFFSET ?',
23
+ );
24
+ // Default includeAdmin is 0 (exclude admin traffic)
25
+ assert.deepEqual(query.params, [0, '/home', 1000, 0]);
26
+ });
27
+
28
+ it('rejects filters, sorts, and directions outside the registry contract', () => {
29
+ assert.throws(
30
+ () => queryForDataset(
31
+ routeDataset,
32
+ new URL('http://localhost?filter.not_allowed=value'),
33
+ ),
34
+ /not allowed/,
35
+ );
36
+ assert.throws(
37
+ () => queryForDataset(
38
+ routeDataset,
39
+ new URL('http://localhost?sort=not_allowed'),
40
+ ),
41
+ /not allowed/,
42
+ );
43
+ assert.throws(
44
+ () => queryForDataset(
45
+ routeDataset,
46
+ new URL('http://localhost?direction=sideways'),
47
+ ),
48
+ /must be asc or desc/,
49
+ );
50
+ });
51
+ });
52
+
53
+ describe('admin traffic variant filtering', () => {
54
+ it('defaults to excluding admin traffic (_includes_admin = 0)', () => {
55
+ const query = queryForDataset(
56
+ routeDataset,
57
+ new URL('http://localhost/api/datasets/route-engagement'),
58
+ );
59
+
60
+ assert.ok(query.sql.includes('"_includes_admin" = ?'));
61
+ assert.equal(query.params[0], 0);
62
+ });
63
+
64
+ it('includes admin traffic when includeAdmin=1 is passed', () => {
65
+ const query = queryForDataset(
66
+ routeDataset,
67
+ new URL('http://localhost/api/datasets/route-engagement?includeAdmin=1'),
68
+ );
69
+
70
+ assert.ok(query.sql.includes('"_includes_admin" = ?'));
71
+ assert.equal(query.params[0], 1);
72
+ });
73
+
74
+ it('does not add _includes_admin filter for datasets without adminVariants', () => {
75
+ const query = queryForDataset(
76
+ qualityDataset,
77
+ new URL('http://localhost/api/datasets/data-quality'),
78
+ );
79
+
80
+ assert.ok(!query.sql.includes('_includes_admin'));
81
+ // Params should be just limit + offset
82
+ assert.deepEqual(query.params, [1000, 0]);
83
+ });
84
+ });
@@ -0,0 +1,53 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { describe, it } from 'node:test';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
8
+ const repoRoot = path.resolve(scriptDirectory, '..', '..');
9
+
10
+ describe('analytics BigQuery query compatibility', () => {
11
+ const queryDirectory = path.join(repoRoot, 'bigquery', 'queries');
12
+ const viewDirectory = path.join(repoRoot, 'bigquery', 'views');
13
+ const readQuery = (filename) =>
14
+ fs.readFileSync(path.join(queryDirectory, filename), 'utf8');
15
+
16
+ it('keeps interactions in the standard four-field tuple', () => {
17
+ const view = fs.readFileSync(path.join(viewDirectory, 'events_flat.sql'), 'utf8');
18
+ assert.ok(view.includes("JSON_VALUE(ix, '$[3]') AS properties"));
19
+ assert.ok(!view.includes("'$[4]'"));
20
+ assert.ok(!view.includes('actor_user_id'));
21
+ });
22
+
23
+ it('attributes authentication through serialized properties', () => {
24
+ const query = readQuery('onboarding_funnel.sql');
25
+ assert.ok(query.includes("'$.authenticatedUserId'"));
26
+ assert.ok(query.includes("'$.accessState'"));
27
+ assert.ok(query.includes('COALESCE('));
28
+ assert.ok(query.includes('pre_sign_in_cohort AS'));
29
+ assert.ok(query.includes('landing.cohort_started_at_ms < auth.authenticated_at_ms'));
30
+ assert.ok(query.includes('landing.cohort_started_at_ms < known_user.first_known_user_at_ms'));
31
+ });
32
+
33
+ it('excludes completed returning users and enforces sequential activation stages', () => {
34
+ const query = readQuery('onboarding_funnel.sql');
35
+ assert.ok(query.includes('activation_completed_by_user AS'));
36
+ assert.ok(query.includes('auth_followup_signals AS'));
37
+ });
38
+
39
+ it('uses generated activation routes and normalized route patterns', () => {
40
+ assert.ok(readQuery('onboarding_funnel.sql').includes("event.route_path = '/home'"));
41
+ assert.ok(readQuery('onboarding_funnel.sql').includes("'Home reached'"));
42
+ assert.ok(
43
+ readQuery('active_time_by_route.sql').includes("r'/([a-zA-Z0-9_-]{16,}|[0-9a-fA-F-]{36})'"),
44
+ );
45
+ });
46
+
47
+ it('does not use unsupported HMAC_SHA256 calls', () => {
48
+ for (const filename of fs.readdirSync(queryDirectory)) {
49
+ if (!filename.endsWith('.sql')) continue;
50
+ assert.ok(!readQuery(filename).includes('HMAC_SHA256'));
51
+ }
52
+ });
53
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * SQLite Dataset DDL Schema Generator
3
+ *
4
+ * Generates `CREATE TABLE ... STRICT` DDL statements for SQLite databases.
5
+ * Uses STRICT mode to enforce rigid type checking (INTEGER, REAL, TEXT).
6
+ *
7
+ * Composite Primary Keys:
8
+ * When a dataset has `adminVariants: true`, the `_includes_admin` column is
9
+ * combined with the existing primary key column(s) to form a composite
10
+ * primary key. This allows two copies of each logical row (one per variant)
11
+ * to coexist in the same table.
12
+ */
13
+
14
+ /**
15
+ * @param {string} identifier
16
+ * @returns {string}
17
+ */
18
+ export function quoteIdentifier(identifier) {
19
+ if (!/^[a-z_][a-z0-9_]*$/i.test(identifier)) {
20
+ throw new Error(`Unsafe SQLite identifier: ${identifier}`);
21
+ }
22
+ return `"${identifier}"`;
23
+ }
24
+
25
+ /**
26
+ * @param {object} dataset
27
+ * @returns {string}
28
+ */
29
+ export function createTableSql(dataset) {
30
+ const pkColumns = dataset.columns
31
+ .filter((column) => column.primaryKey || column.name === '_includes_admin')
32
+ .map((column) => column.name);
33
+ const useCompositePk = pkColumns.length > 1;
34
+
35
+ const definitions = dataset.columns.map((column) => {
36
+ // When using a composite PK, don't mark individual columns as PRIMARY KEY
37
+ if (useCompositePk) {
38
+ const notNull = column.primaryKey || column.name === '_includes_admin'
39
+ ? ' NOT NULL'
40
+ : '';
41
+ return `${quoteIdentifier(column.name)} ${column.type}${notNull}`;
42
+ }
43
+ const constraints = column.primaryKey ? ' PRIMARY KEY NOT NULL' : '';
44
+ return `${quoteIdentifier(column.name)} ${column.type}${constraints}`;
45
+ });
46
+
47
+ // Append composite PRIMARY KEY constraint when multiple key columns exist
48
+ if (useCompositePk) {
49
+ definitions.push(`PRIMARY KEY (${pkColumns.map(quoteIdentifier).join(', ')})`);
50
+ }
51
+
52
+ return `CREATE TABLE ${quoteIdentifier(dataset.table)} (${definitions.join(', ')}) STRICT`;
53
+ }
@@ -0,0 +1,34 @@
1
+ import assert from 'node:assert/strict';
2
+ import sqlite3 from 'sqlite3';
3
+ import { describe, it } from 'node:test';
4
+ import { datasets } from '../datasets.js';
5
+ import { closeDatabase, get, openDatabase } from './sqlite.js';
6
+ import { createTableSql } from './dataset_schema.js';
7
+
8
+ describe('registered SQLite schemas', () => {
9
+ it('creates strict tables matching every explicit dataset contract', async () => {
10
+ const db = await openDatabase(':memory:', sqlite3.OPEN_READWRITE);
11
+ try {
12
+ for (const dataset of datasets) {
13
+ await new Promise((resolve, reject) => {
14
+ db.exec(createTableSql(dataset), (error) => {
15
+ if (error) reject(error);
16
+ else resolve();
17
+ });
18
+ });
19
+ const table = await get(
20
+ db,
21
+ 'SELECT sql FROM sqlite_schema WHERE type = ? AND name = ?',
22
+ ['table', dataset.table],
23
+ );
24
+ assert.match(table.sql, / STRICT$/);
25
+ for (const column of dataset.columns) {
26
+ assert.match(table.sql, new RegExp(`"${column.name}" ${column.type}`));
27
+ }
28
+ }
29
+ } finally {
30
+ await closeDatabase(db);
31
+ }
32
+ });
33
+ });
34
+