@hot-updater/server 1.0.0-rc.0 → 1.0.0-rc.2

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 (210) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -1
  2. package/dist/adapters/databaseConstraintErrors.cjs +0 -1
  3. package/dist/adapters/databasePluginUtils.cjs +0 -1
  4. package/dist/adapters/drizzle.cjs +11 -4
  5. package/dist/adapters/drizzle.d.cts +0 -1
  6. package/dist/adapters/drizzle.d.mts +0 -1
  7. package/dist/adapters/drizzle.mjs +12 -4
  8. package/dist/adapters/drizzleCrud.cjs +62 -1
  9. package/dist/adapters/drizzleCrud.mjs +61 -2
  10. package/dist/adapters/drizzleLazyDB.cjs +6 -1
  11. package/dist/adapters/drizzleLazyDB.mjs +6 -1
  12. package/dist/adapters/drizzleQuery.cjs +3 -2
  13. package/dist/adapters/drizzleQuery.mjs +3 -1
  14. package/dist/adapters/insightsTransaction.cjs +22 -0
  15. package/dist/adapters/insightsTransaction.mjs +22 -0
  16. package/dist/adapters/kysely.cjs +2 -1
  17. package/dist/adapters/kysely.d.cts +0 -1
  18. package/dist/adapters/kysely.d.mts +0 -1
  19. package/dist/adapters/kysely.mjs +3 -1
  20. package/dist/adapters/kyselyCrud.cjs +54 -3
  21. package/dist/adapters/kyselyCrud.mjs +54 -3
  22. package/dist/adapters/kyselyQuery.cjs +2 -2
  23. package/dist/adapters/kyselyQuery.mjs +2 -1
  24. package/dist/adapters/mongodb.cjs +27 -1
  25. package/dist/adapters/mongodb.d.cts +1 -1
  26. package/dist/adapters/mongodb.d.mts +1 -1
  27. package/dist/adapters/mongodb.mjs +28 -1
  28. package/dist/adapters/mongodbCollections.cjs +2 -0
  29. package/dist/adapters/mongodbCollections.mjs +2 -0
  30. package/dist/adapters/mongodbQuery.cjs +21 -4
  31. package/dist/adapters/mongodbQuery.mjs +21 -5
  32. package/dist/adapters/mongodbReads.cjs +91 -29
  33. package/dist/adapters/mongodbReads.mjs +92 -29
  34. package/dist/adapters/mongodbWrites.cjs +16 -2
  35. package/dist/adapters/mongodbWrites.mjs +18 -3
  36. package/dist/adapters/prisma.cjs +55 -7
  37. package/dist/adapters/prisma.d.cts +0 -1
  38. package/dist/adapters/prisma.d.mts +0 -1
  39. package/dist/adapters/prisma.mjs +56 -7
  40. package/dist/adapters/prismaQuery.cjs +0 -1
  41. package/dist/adapters/prismaRows.cjs +22 -1
  42. package/dist/adapters/prismaRows.mjs +22 -1
  43. package/dist/apiKeys.cjs +6 -2
  44. package/dist/apiKeys.d.cts +0 -1
  45. package/dist/apiKeys.d.mts +0 -1
  46. package/dist/apiKeys.mjs +3 -3
  47. package/dist/createHotUpdaterCore.cjs +27 -12
  48. package/dist/createHotUpdaterCore.d.cts +8 -8
  49. package/dist/createHotUpdaterCore.d.mts +8 -8
  50. package/dist/createHotUpdaterCore.mjs +26 -12
  51. package/dist/db/createBundleDiff.cjs +2 -2
  52. package/dist/db/createBundleDiff.d.cts +1 -5
  53. package/dist/db/createBundleDiff.d.mts +1 -5
  54. package/dist/db/databasePluginCore.cjs +0 -1
  55. package/dist/db/fixedMigrator.cjs +2 -2
  56. package/dist/db/fixedMigrator.mjs +2 -2
  57. package/dist/db/fixedMigratorMongo.cjs +6 -4
  58. package/dist/db/fixedMigratorMongo.mjs +6 -4
  59. package/dist/db/index.d.cts +0 -1
  60. package/dist/db/index.d.mts +0 -1
  61. package/dist/db/releaseCatalog.cjs +0 -1
  62. package/dist/db/releaseCatalog.d.cts +0 -1
  63. package/dist/db/releaseCatalog.d.mts +0 -1
  64. package/dist/db/schema/insightsCollation.cjs +14 -0
  65. package/dist/db/schema/insightsCollation.mjs +14 -0
  66. package/dist/db/schema/sql.cjs +11 -7
  67. package/dist/db/schema/sql.mjs +8 -8
  68. package/dist/db/schemaGenerators.cjs +28 -9
  69. package/dist/db/schemaGenerators.mjs +28 -9
  70. package/dist/db/schemaReadiness.cjs +2 -0
  71. package/dist/db/schemaReadiness.d.cts +1 -0
  72. package/dist/db/schemaReadiness.d.mts +1 -0
  73. package/dist/db/schemaReadiness.mjs +2 -0
  74. package/dist/db/sqlMigrationExecution.cjs +1 -1
  75. package/dist/db/sqlMigrationExecution.mjs +1 -0
  76. package/dist/db/types.cjs +3 -1
  77. package/dist/db/types.d.cts +3 -6
  78. package/dist/db/types.d.mts +3 -6
  79. package/dist/db/types.mjs +2 -2
  80. package/dist/db/updateArtifacts.cjs +0 -1
  81. package/dist/handler.cjs +5 -5
  82. package/dist/handler.d.cts +1 -2
  83. package/dist/handler.d.mts +1 -2
  84. package/dist/handler.mjs +5 -5
  85. package/dist/handlerReleaseCatalogRoutes.cjs +0 -1
  86. package/dist/handlerReleaseManagementRoutes.cjs +0 -1
  87. package/dist/handlerTypes.d.cts +0 -1
  88. package/dist/handlerTypes.d.mts +0 -1
  89. package/dist/handlerVersionRoutes.d.cts +1 -0
  90. package/dist/handlerVersionRoutes.d.mts +1 -0
  91. package/dist/index.cjs +2 -2
  92. package/dist/index.d.cts +4 -4
  93. package/dist/index.d.mts +4 -4
  94. package/dist/index.mjs +2 -2
  95. package/dist/insights/domain.d.cts +89 -0
  96. package/dist/insights/domain.d.mts +89 -0
  97. package/dist/insights/errors.cjs +15 -0
  98. package/dist/insights/errors.mjs +14 -0
  99. package/dist/{analytics → insights}/eventInput.cjs +58 -14
  100. package/dist/{analytics → insights}/eventInput.mjs +58 -16
  101. package/dist/insights/provider.cjs +314 -0
  102. package/dist/insights/provider.d.cts +6 -0
  103. package/dist/insights/provider.d.mts +6 -0
  104. package/dist/insights/provider.mjs +314 -0
  105. package/dist/insights/queryInput.cjs +93 -0
  106. package/dist/insights/queryInput.mjs +91 -0
  107. package/dist/insights/routes.cjs +58 -0
  108. package/dist/insights/routes.mjs +56 -0
  109. package/dist/insights/types.d.cts +32 -0
  110. package/dist/insights/types.d.mts +32 -0
  111. package/dist/node.d.cts +0 -1
  112. package/dist/node.d.mts +0 -1
  113. package/dist/package.cjs +1 -1
  114. package/dist/package.mjs +1 -1
  115. package/dist/schema/index.cjs +17 -3
  116. package/dist/schema/index.mjs +4 -4
  117. package/dist/schema/v1_0_0.cjs +72 -30
  118. package/dist/schema/v1_0_0.mjs +72 -31
  119. package/dist/storageAccess.cjs +0 -1
  120. package/dist/types/index.d.cts +0 -1
  121. package/dist/types/index.d.mts +0 -1
  122. package/package.json +7 -7
  123. package/src/adapters/databasePluginTestDatabase.ts +14 -0
  124. package/src/adapters/drizzle.spec.ts +99 -0
  125. package/src/adapters/drizzle.ts +22 -4
  126. package/src/adapters/drizzleCrud.ts +154 -2
  127. package/src/adapters/drizzleLazyDB.ts +17 -3
  128. package/src/adapters/insightsTransaction.ts +32 -0
  129. package/src/adapters/kysely.spec.ts +29 -0
  130. package/src/adapters/kysely.ts +10 -1
  131. package/src/adapters/kyselyCrud.ts +121 -0
  132. package/src/adapters/mongodb.integration.spec.ts +210 -0
  133. package/src/adapters/mongodb.spec.ts +69 -1
  134. package/src/adapters/mongodb.ts +66 -2
  135. package/src/adapters/mongodbCollections.ts +5 -0
  136. package/src/adapters/mongodbQuery.ts +32 -3
  137. package/src/adapters/mongodbReads.ts +69 -0
  138. package/src/adapters/mongodbTestClient.ts +41 -6
  139. package/src/adapters/mongodbTestFilter.ts +4 -1
  140. package/src/adapters/mongodbWrites.ts +27 -0
  141. package/src/adapters/prisma.spec.ts +97 -0
  142. package/src/adapters/prisma.ts +103 -3
  143. package/src/adapters/prismaRows.ts +37 -1
  144. package/src/adapters/prismaTestClient.ts +22 -5
  145. package/src/apiKeys.integration.spec.ts +3 -3
  146. package/src/createHotUpdaterCore.ts +30 -16
  147. package/src/db/databasePluginUpdateCheck.bench.ts +3 -0
  148. package/src/db/fixedMigrator.spec.ts +65 -0
  149. package/src/db/fixedMigratorMongo.spec.ts +56 -9
  150. package/src/db/fixedMigratorMongo.ts +10 -10
  151. package/src/db/index.spec.ts +8 -1
  152. package/src/db/schema/insightsCollation.ts +21 -0
  153. package/src/db/schema/sql.ts +8 -5
  154. package/src/db/schemaGenerators.ts +41 -13
  155. package/src/db/types.spec.ts +11 -3
  156. package/src/db/types.ts +13 -7
  157. package/src/handler-standalone.integration.spec.ts +6 -8
  158. package/src/handler.ts +12 -12
  159. package/src/index.ts +3 -3
  160. package/src/insights/domain.ts +103 -0
  161. package/src/insights/errors.ts +11 -0
  162. package/src/{analytics → insights}/eventInput.ts +71 -14
  163. package/src/insights/insights.integration.spec.ts +381 -0
  164. package/src/insights/provider.spec.ts +385 -0
  165. package/src/insights/provider.ts +591 -0
  166. package/src/insights/queryInput.ts +141 -0
  167. package/src/insights/routes.ts +104 -0
  168. package/src/insights/types.ts +55 -0
  169. package/src/schema/dsl-all-versions.spec.ts +3 -1
  170. package/src/schema/v1_0_0.spec.ts +77 -3
  171. package/src/schema/v1_0_0.ts +94 -30
  172. package/dist/analytics/bounded/activeOverview.cjs +0 -87
  173. package/dist/analytics/bounded/activeOverview.mjs +0 -85
  174. package/dist/analytics/bounded/installationSearch.cjs +0 -42
  175. package/dist/analytics/bounded/installationSearch.mjs +0 -42
  176. package/dist/analytics/bounded/persistence.cjs +0 -39
  177. package/dist/analytics/bounded/persistence.mjs +0 -38
  178. package/dist/analytics/bounded/provider.cjs +0 -170
  179. package/dist/analytics/bounded/provider.d.cts +0 -7
  180. package/dist/analytics/bounded/provider.d.mts +0 -7
  181. package/dist/analytics/bounded/provider.mjs +0 -170
  182. package/dist/analytics/bounded/scan.cjs +0 -144
  183. package/dist/analytics/bounded/scan.mjs +0 -138
  184. package/dist/analytics/domain.d.cts +0 -121
  185. package/dist/analytics/domain.d.mts +0 -121
  186. package/dist/analytics/errors.cjs +0 -22
  187. package/dist/analytics/errors.mjs +0 -20
  188. package/dist/analytics/persistence.d.cts +0 -6
  189. package/dist/analytics/persistence.d.mts +0 -6
  190. package/dist/analytics/queryInput.cjs +0 -58
  191. package/dist/analytics/queryInput.mjs +0 -55
  192. package/dist/analytics/routes.cjs +0 -63
  193. package/dist/analytics/routes.mjs +0 -61
  194. package/dist/analytics/types.d.cts +0 -17
  195. package/dist/analytics/types.d.mts +0 -17
  196. package/src/analytics/analytics.integration.spec.ts +0 -144
  197. package/src/analytics/bounded/activeOverview.spec.ts +0 -189
  198. package/src/analytics/bounded/activeOverview.ts +0 -148
  199. package/src/analytics/bounded/installationSearch.spec.ts +0 -130
  200. package/src/analytics/bounded/installationSearch.ts +0 -69
  201. package/src/analytics/bounded/persistence.ts +0 -43
  202. package/src/analytics/bounded/provider.spec.ts +0 -219
  203. package/src/analytics/bounded/provider.ts +0 -229
  204. package/src/analytics/bounded/scan.ts +0 -235
  205. package/src/analytics/domain.ts +0 -139
  206. package/src/analytics/errors.ts +0 -18
  207. package/src/analytics/persistence.ts +0 -10
  208. package/src/analytics/queryInput.ts +0 -102
  209. package/src/analytics/routes.ts +0 -123
  210. package/src/analytics/types.ts +0 -44
@@ -1,85 +0,0 @@
1
- //#region src/analytics/bounded/activeOverview.ts
2
- const HOUR_MS = 3600 * 1e3;
3
- const DAY_MS = 24 * HOUR_MS;
4
- const ACTIVE_BUNDLE_EVENT_TYPES = [
5
- "UPDATE_APPLIED",
6
- "RECOVERED",
7
- "RELEASE_ADOPTED",
8
- "UNCHANGED"
9
- ];
10
- const activeWindowDefinitions = {
11
- "24h": {
12
- bucketCount: 24,
13
- bucketSizeMs: HOUR_MS
14
- },
15
- "7d": {
16
- bucketCount: 7,
17
- bucketSizeMs: DAY_MS
18
- },
19
- "30d": {
20
- bucketCount: 30,
21
- bucketSizeMs: DAY_MS
22
- }
23
- };
24
- function getActiveWindowDefinition(window) {
25
- return activeWindowDefinitions[window];
26
- }
27
- function compareCodePoints(left, right) {
28
- if (left < right) return -1;
29
- if (left > right) return 1;
30
- return 0;
31
- }
32
- function isNewer(candidate, current) {
33
- return candidate.received_at_ms > current.received_at_ms || candidate.received_at_ms === current.received_at_ms && compareCodePoints(candidate.id, current.id) > 0;
34
- }
35
- function collectActiveInstallationOverview(request) {
36
- const definition = getActiveWindowDefinition(request.window);
37
- const windowStartMs = request.asOfMs - definition.bucketCount * definition.bucketSizeMs;
38
- const rows = request.rows.filter((row) => row.received_at_ms >= windowStartMs && row.received_at_ms < request.asOfMs);
39
- const latestByInstall = /* @__PURE__ */ new Map();
40
- for (const row of rows) {
41
- const current = latestByInstall.get(row.install_id);
42
- if (current === void 0 || isNewer(row, current)) latestByInstall.set(row.install_id, row);
43
- }
44
- const selectedRows = [...latestByInstall.values()].filter((row) => request.userId === void 0 || row.user_id === request.userId);
45
- const selectedInstallIds = new Set(selectedRows.map((row) => row.install_id));
46
- const bundleCounts = /* @__PURE__ */ new Map();
47
- for (const row of selectedRows) bundleCounts.set(row.to_bundle_id, (bundleCounts.get(row.to_bundle_id) ?? 0) + 1);
48
- const latestByBucket = Array.from({ length: definition.bucketCount }, () => /* @__PURE__ */ new Map());
49
- for (const row of rows) {
50
- if (!selectedInstallIds.has(row.install_id)) continue;
51
- const bucket = latestByBucket[Math.floor((row.received_at_ms - windowStartMs) / definition.bucketSizeMs)];
52
- if (bucket === void 0) continue;
53
- const current = bucket.get(row.install_id);
54
- if (current === void 0 || isNewer(row, current)) bucket.set(row.install_id, row);
55
- }
56
- const bundleCountsByBucket = latestByBucket.map((bucket) => {
57
- const counts = /* @__PURE__ */ new Map();
58
- for (const row of bucket.values()) counts.set(row.to_bundle_id, (counts.get(row.to_bundle_id) ?? 0) + 1);
59
- return counts;
60
- });
61
- const bundleObservationTotals = /* @__PURE__ */ new Map();
62
- for (const counts of bundleCountsByBucket) for (const [bundleId, count] of counts) bundleObservationTotals.set(bundleId, (bundleObservationTotals.get(bundleId) ?? 0) + count);
63
- return {
64
- asOfMs: request.asOfMs,
65
- window: request.window,
66
- activeInstallations: selectedInstallIds.size,
67
- series: latestByBucket.map((bucket, index) => ({
68
- bucketStartMs: windowStartMs + index * definition.bucketSizeMs,
69
- value: bucket.size
70
- })),
71
- bundleSeries: [...bundleObservationTotals].sort(([leftId, leftTotal], [rightId, rightTotal]) => rightTotal - leftTotal || compareCodePoints(leftId, rightId)).map(([bundleId]) => ({
72
- bundleId,
73
- series: bundleCountsByBucket.map((counts, index) => ({
74
- bucketStartMs: windowStartMs + index * definition.bucketSizeMs,
75
- value: counts.get(bundleId) ?? 0
76
- }))
77
- })),
78
- bundles: [...bundleCounts].map(([bundleId, installations]) => ({
79
- bundleId,
80
- installations
81
- })).sort((left, right) => right.installations - left.installations || compareCodePoints(left.bundleId, right.bundleId))
82
- };
83
- }
84
- //#endregion
85
- export { ACTIVE_BUNDLE_EVENT_TYPES, collectActiveInstallationOverview, getActiveWindowDefinition };
@@ -1,42 +0,0 @@
1
- const require_scan = require("./scan.cjs");
2
- //#region src/analytics/bounded/installationSearch.ts
3
- function toSearchRow(row) {
4
- return {
5
- installId: row.install_id,
6
- username: row.username,
7
- userId: row.user_id,
8
- lastKnownBundleId: row.to_bundle_id,
9
- latestStatus: row.type,
10
- platform: row.platform,
11
- appVersion: row.app_version,
12
- channel: row.channel,
13
- cohort: row.cohort,
14
- receivedAtMs: row.received_at_ms
15
- };
16
- }
17
- function matchesIdentity(row, query) {
18
- return row.install_id.toLowerCase().includes(query) || row.user_id?.toLowerCase().includes(query) === true || row.username?.toLowerCase().includes(query) === true;
19
- }
20
- function searchEventInstallations(request) {
21
- const query = request.query.toLowerCase();
22
- const matchingInstallIds = /* @__PURE__ */ new Set();
23
- for (const row of request.rows) if (query.length === 0 || matchesIdentity(row, query)) matchingInstallIds.add(row.install_id);
24
- const latestByInstall = /* @__PURE__ */ new Map();
25
- for (const row of request.rows) {
26
- if (!matchingInstallIds.has(row.install_id)) continue;
27
- const current = latestByInstall.get(row.install_id);
28
- if (current === void 0 || require_scan.compareEventNewest(row, current) < 0) latestByInstall.set(row.install_id, row);
29
- }
30
- const matchingRows = [...latestByInstall.values()].sort((left, right) => require_scan.compareCodePoints(left.install_id, right.install_id));
31
- const pageSize = Math.min(Math.max(request.limit, 0), 100);
32
- return {
33
- data: matchingRows.slice(request.offset, request.offset + pageSize).map(toSearchRow),
34
- pagination: {
35
- total: matchingRows.length,
36
- limit: request.limit,
37
- offset: request.offset
38
- }
39
- };
40
- }
41
- //#endregion
42
- exports.searchEventInstallations = searchEventInstallations;
@@ -1,42 +0,0 @@
1
- import { compareCodePoints, compareEventNewest } from "./scan.mjs";
2
- //#region src/analytics/bounded/installationSearch.ts
3
- function toSearchRow(row) {
4
- return {
5
- installId: row.install_id,
6
- username: row.username,
7
- userId: row.user_id,
8
- lastKnownBundleId: row.to_bundle_id,
9
- latestStatus: row.type,
10
- platform: row.platform,
11
- appVersion: row.app_version,
12
- channel: row.channel,
13
- cohort: row.cohort,
14
- receivedAtMs: row.received_at_ms
15
- };
16
- }
17
- function matchesIdentity(row, query) {
18
- return row.install_id.toLowerCase().includes(query) || row.user_id?.toLowerCase().includes(query) === true || row.username?.toLowerCase().includes(query) === true;
19
- }
20
- function searchEventInstallations(request) {
21
- const query = request.query.toLowerCase();
22
- const matchingInstallIds = /* @__PURE__ */ new Set();
23
- for (const row of request.rows) if (query.length === 0 || matchesIdentity(row, query)) matchingInstallIds.add(row.install_id);
24
- const latestByInstall = /* @__PURE__ */ new Map();
25
- for (const row of request.rows) {
26
- if (!matchingInstallIds.has(row.install_id)) continue;
27
- const current = latestByInstall.get(row.install_id);
28
- if (current === void 0 || compareEventNewest(row, current) < 0) latestByInstall.set(row.install_id, row);
29
- }
30
- const matchingRows = [...latestByInstall.values()].sort((left, right) => compareCodePoints(left.install_id, right.install_id));
31
- const pageSize = Math.min(Math.max(request.limit, 0), 100);
32
- return {
33
- data: matchingRows.slice(request.offset, request.offset + pageSize).map(toSearchRow),
34
- pagination: {
35
- total: matchingRows.length,
36
- limit: request.limit,
37
- offset: request.offset
38
- }
39
- };
40
- }
41
- //#endregion
42
- export { searchEventInstallations };
@@ -1,39 +0,0 @@
1
- require("../../_virtual/_rolldown/runtime.cjs");
2
- let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
3
- //#region src/analytics/bounded/persistence.ts
4
- function createBundleEventRow(input) {
5
- const base = {
6
- id: (0, _hot_updater_plugin_core.createUUIDv7)(),
7
- install_id: input.installId,
8
- user_id: input.userId ?? null,
9
- username: input.username ?? null,
10
- from_release_id: input.fromReleaseId,
11
- to_release_id: input.toReleaseId,
12
- to_bundle_id: input.toBundleId,
13
- platform: input.platform,
14
- app_version: input.appVersion,
15
- channel: input.channel,
16
- cohort: input.cohort,
17
- fingerprint_hash: input.fingerprintHash,
18
- sdk_version: input.sdkVersion ?? null,
19
- received_at_ms: Date.now()
20
- };
21
- switch (input.type) {
22
- case "UPDATE_APPLIED":
23
- case "RECOVERED":
24
- case "RELEASE_ADOPTED": return {
25
- ...base,
26
- type: input.type,
27
- from_bundle_id: input.fromBundleId,
28
- update_strategy: input.updateStrategy
29
- };
30
- case "UNCHANGED": return {
31
- ...base,
32
- type: input.type,
33
- from_bundle_id: null,
34
- update_strategy: null
35
- };
36
- }
37
- }
38
- //#endregion
39
- exports.createBundleEventRow = createBundleEventRow;
@@ -1,38 +0,0 @@
1
- import { createUUIDv7 } from "@hot-updater/plugin-core";
2
- //#region src/analytics/bounded/persistence.ts
3
- function createBundleEventRow(input) {
4
- const base = {
5
- id: createUUIDv7(),
6
- install_id: input.installId,
7
- user_id: input.userId ?? null,
8
- username: input.username ?? null,
9
- from_release_id: input.fromReleaseId,
10
- to_release_id: input.toReleaseId,
11
- to_bundle_id: input.toBundleId,
12
- platform: input.platform,
13
- app_version: input.appVersion,
14
- channel: input.channel,
15
- cohort: input.cohort,
16
- fingerprint_hash: input.fingerprintHash,
17
- sdk_version: input.sdkVersion ?? null,
18
- received_at_ms: Date.now()
19
- };
20
- switch (input.type) {
21
- case "UPDATE_APPLIED":
22
- case "RECOVERED":
23
- case "RELEASE_ADOPTED": return {
24
- ...base,
25
- type: input.type,
26
- from_bundle_id: input.fromBundleId,
27
- update_strategy: input.updateStrategy
28
- };
29
- case "UNCHANGED": return {
30
- ...base,
31
- type: input.type,
32
- from_bundle_id: null,
33
- update_strategy: null
34
- };
35
- }
36
- }
37
- //#endregion
38
- export { createBundleEventRow };
@@ -1,170 +0,0 @@
1
- const require_activeOverview = require("./activeOverview.cjs");
2
- const require_scan = require("./scan.cjs");
3
- const require_installationSearch = require("./installationSearch.cjs");
4
- const require_persistence = require("./persistence.cjs");
5
- //#region src/analytics/bounded/provider.ts
6
- const isTransitionEventRow = (row) => row.type === "UPDATE_APPLIED" || row.type === "RECOVERED";
7
- const toHistoryRow = (row) => ({
8
- id: row.id,
9
- type: row.type,
10
- fromBundleId: row.from_bundle_id,
11
- toBundleId: row.to_bundle_id,
12
- username: row.username,
13
- userId: row.user_id,
14
- platform: row.platform,
15
- appVersion: row.app_version,
16
- channel: row.channel,
17
- cohort: row.cohort,
18
- receivedAtMs: row.received_at_ms
19
- });
20
- const isInstalledForBundle = (row, bundleId) => row.type === "UPDATE_APPLIED" && row.to_bundle_id === bundleId;
21
- const isRecoveredFromBundle = (row, bundleId) => row.type === "RECOVERED" && row.from_bundle_id === bundleId;
22
- const countDistinctInstallations = (rows) => new Set(rows.map(({ install_id }) => install_id)).size;
23
- const getAnalyticsResult = async (persistence, bundleId, window, limit, offset) => {
24
- const scope = {
25
- persistence,
26
- cutoffMs: Date.now()
27
- };
28
- const rows = (await require_scan.materializeRowsForWindow(scope, window)).filter(isTransitionEventRow);
29
- const installedRows = rows.filter((row) => isInstalledForBundle(row, bundleId));
30
- const recoveredRows = rows.filter((row) => isRecoveredFromBundle(row, bundleId));
31
- const installed = require_scan.collectEventActivity({
32
- rows: installedRows,
33
- window,
34
- cutoffMs: scope.cutoffMs
35
- });
36
- const recovered = require_scan.collectEventActivity({
37
- rows: recoveredRows,
38
- window,
39
- cutoffMs: scope.cutoffMs
40
- });
41
- const recentRows = [...installedRows, ...recoveredRows].sort(require_scan.compareEventNewest);
42
- return {
43
- summary: {
44
- installed: installed.summary,
45
- recovered: recovered.summary
46
- },
47
- series: {
48
- installed: installed.series,
49
- recovered: recovered.series
50
- },
51
- cohorts: {
52
- installed: installed.cohorts,
53
- recovered: recovered.cohorts
54
- },
55
- recentEvents: {
56
- data: recentRows.slice(offset, offset + limit).map(toHistoryRow),
57
- pagination: {
58
- total: recentRows.length,
59
- limit,
60
- offset
61
- }
62
- }
63
- };
64
- };
65
- const getAnalyticsSummaries = async (persistence, bundleIds, window) => {
66
- const normalizedBundleIds = [...new Set(bundleIds)];
67
- if (normalizedBundleIds.length === 0) return [];
68
- const requestedBundleIds = new Set(normalizedBundleIds);
69
- const installedByBundleId = /* @__PURE__ */ new Map();
70
- const recoveredByBundleId = /* @__PURE__ */ new Map();
71
- const rows = (await require_scan.materializeRowsForWindow({
72
- persistence,
73
- cutoffMs: Date.now()
74
- }, window)).filter(isTransitionEventRow);
75
- for (const row of rows) {
76
- const bundleId = row.type === "UPDATE_APPLIED" ? row.to_bundle_id : row.from_bundle_id;
77
- if (!requestedBundleIds.has(bundleId)) continue;
78
- const counts = row.type === "UPDATE_APPLIED" ? installedByBundleId : recoveredByBundleId;
79
- const installIds = counts.get(bundleId) ?? /* @__PURE__ */ new Set();
80
- installIds.add(row.install_id);
81
- counts.set(bundleId, installIds);
82
- }
83
- return normalizedBundleIds.map((bundleId) => ({
84
- bundleId,
85
- installed: installedByBundleId.get(bundleId)?.size ?? 0,
86
- recovered: recoveredByBundleId.get(bundleId)?.size ?? 0
87
- }));
88
- };
89
- const createAnalyticsProvider = (persistence) => Object.freeze({
90
- mode: "bounded",
91
- maxMatchingRows: require_scan.ANALYTICS_SCAN_MAX_ROWS,
92
- async appendBundleEvent(input) {
93
- await persistence.append(require_persistence.createBundleEventRow(input));
94
- },
95
- async getBundleEventSummary(bundleId) {
96
- const rows = (await require_scan.materializeEventRows({
97
- persistence,
98
- cutoffMs: Date.now()
99
- })).filter(isTransitionEventRow);
100
- return {
101
- installed: countDistinctInstallations(rows.filter((row) => isInstalledForBundle(row, bundleId))),
102
- recovered: countDistinctInstallations(rows.filter((row) => isRecoveredFromBundle(row, bundleId)))
103
- };
104
- },
105
- getBundleEventSummaries(bundleIds, window) {
106
- return getAnalyticsSummaries(persistence, bundleIds, window);
107
- },
108
- getBundleEventAnalytics(bundleId, window, limit, offset) {
109
- return getAnalyticsResult(persistence, bundleId, window, limit, offset);
110
- },
111
- async getBundleEventOverview() {
112
- const rows = await require_scan.materializeEventRows({
113
- persistence,
114
- cutoffMs: Date.now()
115
- });
116
- const latestByInstall = /* @__PURE__ */ new Map();
117
- for (const row of rows) {
118
- const current = latestByInstall.get(row.install_id);
119
- if (current === void 0 || require_scan.compareEventNewest(row, current) < 0) latestByInstall.set(row.install_id, row);
120
- }
121
- const counts = /* @__PURE__ */ new Map();
122
- for (const row of latestByInstall.values()) counts.set(row.to_bundle_id, (counts.get(row.to_bundle_id) ?? 0) + 1);
123
- return {
124
- trackedInstallations: latestByInstall.size,
125
- bundles: [...counts].map(([bundleId, installations]) => ({
126
- bundleId,
127
- installations
128
- })).sort((left, right) => right.installations - left.installations || require_scan.compareCodePoints(left.bundleId, right.bundleId))
129
- };
130
- },
131
- async getActiveInstallationOverview(input) {
132
- const asOfMs = Date.now();
133
- return require_activeOverview.collectActiveInstallationOverview({
134
- rows: await require_scan.materializeActiveRows({
135
- persistence,
136
- cutoffMs: asOfMs
137
- }, input.window),
138
- asOfMs,
139
- window: input.window,
140
- ...input.userId === void 0 ? {} : { userId: input.userId }
141
- });
142
- },
143
- async searchInstallations(query, limit, offset) {
144
- return require_installationSearch.searchEventInstallations({
145
- rows: await require_scan.materializeEventRows({
146
- persistence,
147
- cutoffMs: Date.now()
148
- }),
149
- query,
150
- limit,
151
- offset
152
- });
153
- },
154
- async getInstallationHistory(installId, limit, offset) {
155
- const ordered = (await require_scan.materializeEventRows({
156
- persistence,
157
- cutoffMs: Date.now()
158
- })).filter((row) => row.install_id === installId && isTransitionEventRow(row)).toSorted(require_scan.compareEventNewest);
159
- return {
160
- data: ordered.slice(offset, offset + limit).map(toHistoryRow),
161
- pagination: {
162
- total: ordered.length,
163
- limit,
164
- offset
165
- }
166
- };
167
- }
168
- });
169
- //#endregion
170
- exports.createAnalyticsProvider = createAnalyticsProvider;
@@ -1,7 +0,0 @@
1
- import { AnalyticsProvider } from "../types.cjs";
2
- import { AnalyticsPersistence } from "../persistence.cjs";
3
-
4
- //#region src/analytics/bounded/provider.d.ts
5
- declare const createAnalyticsProvider: (persistence: AnalyticsPersistence) => AnalyticsProvider;
6
- //#endregion
7
- export { createAnalyticsProvider };
@@ -1,7 +0,0 @@
1
- import { AnalyticsProvider } from "../types.mjs";
2
- import { AnalyticsPersistence } from "../persistence.mjs";
3
-
4
- //#region src/analytics/bounded/provider.d.ts
5
- declare const createAnalyticsProvider: (persistence: AnalyticsPersistence) => AnalyticsProvider;
6
- //#endregion
7
- export { createAnalyticsProvider };
@@ -1,170 +0,0 @@
1
- import { collectActiveInstallationOverview } from "./activeOverview.mjs";
2
- import { ANALYTICS_SCAN_MAX_ROWS, collectEventActivity, compareCodePoints, compareEventNewest, materializeActiveRows, materializeEventRows, materializeRowsForWindow } from "./scan.mjs";
3
- import { searchEventInstallations } from "./installationSearch.mjs";
4
- import { createBundleEventRow } from "./persistence.mjs";
5
- //#region src/analytics/bounded/provider.ts
6
- const isTransitionEventRow = (row) => row.type === "UPDATE_APPLIED" || row.type === "RECOVERED";
7
- const toHistoryRow = (row) => ({
8
- id: row.id,
9
- type: row.type,
10
- fromBundleId: row.from_bundle_id,
11
- toBundleId: row.to_bundle_id,
12
- username: row.username,
13
- userId: row.user_id,
14
- platform: row.platform,
15
- appVersion: row.app_version,
16
- channel: row.channel,
17
- cohort: row.cohort,
18
- receivedAtMs: row.received_at_ms
19
- });
20
- const isInstalledForBundle = (row, bundleId) => row.type === "UPDATE_APPLIED" && row.to_bundle_id === bundleId;
21
- const isRecoveredFromBundle = (row, bundleId) => row.type === "RECOVERED" && row.from_bundle_id === bundleId;
22
- const countDistinctInstallations = (rows) => new Set(rows.map(({ install_id }) => install_id)).size;
23
- const getAnalyticsResult = async (persistence, bundleId, window, limit, offset) => {
24
- const scope = {
25
- persistence,
26
- cutoffMs: Date.now()
27
- };
28
- const rows = (await materializeRowsForWindow(scope, window)).filter(isTransitionEventRow);
29
- const installedRows = rows.filter((row) => isInstalledForBundle(row, bundleId));
30
- const recoveredRows = rows.filter((row) => isRecoveredFromBundle(row, bundleId));
31
- const installed = collectEventActivity({
32
- rows: installedRows,
33
- window,
34
- cutoffMs: scope.cutoffMs
35
- });
36
- const recovered = collectEventActivity({
37
- rows: recoveredRows,
38
- window,
39
- cutoffMs: scope.cutoffMs
40
- });
41
- const recentRows = [...installedRows, ...recoveredRows].sort(compareEventNewest);
42
- return {
43
- summary: {
44
- installed: installed.summary,
45
- recovered: recovered.summary
46
- },
47
- series: {
48
- installed: installed.series,
49
- recovered: recovered.series
50
- },
51
- cohorts: {
52
- installed: installed.cohorts,
53
- recovered: recovered.cohorts
54
- },
55
- recentEvents: {
56
- data: recentRows.slice(offset, offset + limit).map(toHistoryRow),
57
- pagination: {
58
- total: recentRows.length,
59
- limit,
60
- offset
61
- }
62
- }
63
- };
64
- };
65
- const getAnalyticsSummaries = async (persistence, bundleIds, window) => {
66
- const normalizedBundleIds = [...new Set(bundleIds)];
67
- if (normalizedBundleIds.length === 0) return [];
68
- const requestedBundleIds = new Set(normalizedBundleIds);
69
- const installedByBundleId = /* @__PURE__ */ new Map();
70
- const recoveredByBundleId = /* @__PURE__ */ new Map();
71
- const rows = (await materializeRowsForWindow({
72
- persistence,
73
- cutoffMs: Date.now()
74
- }, window)).filter(isTransitionEventRow);
75
- for (const row of rows) {
76
- const bundleId = row.type === "UPDATE_APPLIED" ? row.to_bundle_id : row.from_bundle_id;
77
- if (!requestedBundleIds.has(bundleId)) continue;
78
- const counts = row.type === "UPDATE_APPLIED" ? installedByBundleId : recoveredByBundleId;
79
- const installIds = counts.get(bundleId) ?? /* @__PURE__ */ new Set();
80
- installIds.add(row.install_id);
81
- counts.set(bundleId, installIds);
82
- }
83
- return normalizedBundleIds.map((bundleId) => ({
84
- bundleId,
85
- installed: installedByBundleId.get(bundleId)?.size ?? 0,
86
- recovered: recoveredByBundleId.get(bundleId)?.size ?? 0
87
- }));
88
- };
89
- const createAnalyticsProvider = (persistence) => Object.freeze({
90
- mode: "bounded",
91
- maxMatchingRows: ANALYTICS_SCAN_MAX_ROWS,
92
- async appendBundleEvent(input) {
93
- await persistence.append(createBundleEventRow(input));
94
- },
95
- async getBundleEventSummary(bundleId) {
96
- const rows = (await materializeEventRows({
97
- persistence,
98
- cutoffMs: Date.now()
99
- })).filter(isTransitionEventRow);
100
- return {
101
- installed: countDistinctInstallations(rows.filter((row) => isInstalledForBundle(row, bundleId))),
102
- recovered: countDistinctInstallations(rows.filter((row) => isRecoveredFromBundle(row, bundleId)))
103
- };
104
- },
105
- getBundleEventSummaries(bundleIds, window) {
106
- return getAnalyticsSummaries(persistence, bundleIds, window);
107
- },
108
- getBundleEventAnalytics(bundleId, window, limit, offset) {
109
- return getAnalyticsResult(persistence, bundleId, window, limit, offset);
110
- },
111
- async getBundleEventOverview() {
112
- const rows = await materializeEventRows({
113
- persistence,
114
- cutoffMs: Date.now()
115
- });
116
- const latestByInstall = /* @__PURE__ */ new Map();
117
- for (const row of rows) {
118
- const current = latestByInstall.get(row.install_id);
119
- if (current === void 0 || compareEventNewest(row, current) < 0) latestByInstall.set(row.install_id, row);
120
- }
121
- const counts = /* @__PURE__ */ new Map();
122
- for (const row of latestByInstall.values()) counts.set(row.to_bundle_id, (counts.get(row.to_bundle_id) ?? 0) + 1);
123
- return {
124
- trackedInstallations: latestByInstall.size,
125
- bundles: [...counts].map(([bundleId, installations]) => ({
126
- bundleId,
127
- installations
128
- })).sort((left, right) => right.installations - left.installations || compareCodePoints(left.bundleId, right.bundleId))
129
- };
130
- },
131
- async getActiveInstallationOverview(input) {
132
- const asOfMs = Date.now();
133
- return collectActiveInstallationOverview({
134
- rows: await materializeActiveRows({
135
- persistence,
136
- cutoffMs: asOfMs
137
- }, input.window),
138
- asOfMs,
139
- window: input.window,
140
- ...input.userId === void 0 ? {} : { userId: input.userId }
141
- });
142
- },
143
- async searchInstallations(query, limit, offset) {
144
- return searchEventInstallations({
145
- rows: await materializeEventRows({
146
- persistence,
147
- cutoffMs: Date.now()
148
- }),
149
- query,
150
- limit,
151
- offset
152
- });
153
- },
154
- async getInstallationHistory(installId, limit, offset) {
155
- const ordered = (await materializeEventRows({
156
- persistence,
157
- cutoffMs: Date.now()
158
- })).filter((row) => row.install_id === installId && isTransitionEventRow(row)).toSorted(compareEventNewest);
159
- return {
160
- data: ordered.slice(offset, offset + limit).map(toHistoryRow),
161
- pagination: {
162
- total: ordered.length,
163
- limit,
164
- offset
165
- }
166
- };
167
- }
168
- });
169
- //#endregion
170
- export { createAnalyticsProvider };