@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,144 +0,0 @@
1
- const require_errors = require("../errors.cjs");
2
- const require_activeOverview = require("./activeOverview.cjs");
3
- //#region src/analytics/bounded/scan.ts
4
- const ANALYTICS_SCAN_MAX_ROWS = 5e4;
5
- const ANALYTICS_MATERIALIZATION_LIMIT = ANALYTICS_SCAN_MAX_ROWS + 1;
6
- const ANALYTICS_SCAN_PAGE_SIZE = 1e3;
7
- const ANALYTICS_LOWER_BOUND_ID = "00000000-0000-0000-0000-000000000000";
8
- const compareCodePoints = (left, right) => {
9
- if (left < right) return -1;
10
- if (left > right) return 1;
11
- return 0;
12
- };
13
- const compareEventNewest = (left, right) => right.received_at_ms - left.received_at_ms || compareCodePoints(right.id, left.id);
14
- const compareEventOldest = (left, right) => left.received_at_ms - right.received_at_ms || compareCodePoints(left.id, right.id);
15
- const materializeEventRows = async (scope) => {
16
- const rows = [];
17
- const seenIds = /* @__PURE__ */ new Set();
18
- let after = scope.lowerBoundMs === void 0 ? void 0 : {
19
- receivedAtMs: scope.lowerBoundMs,
20
- id: ANALYTICS_LOWER_BOUND_ID
21
- };
22
- while (rows.length < ANALYTICS_MATERIALIZATION_LIMIT) {
23
- const limit = Math.min(ANALYTICS_SCAN_PAGE_SIZE, ANALYTICS_MATERIALIZATION_LIMIT - rows.length);
24
- const page = await scope.persistence.scan({
25
- beforeReceivedAtMs: scope.cutoffMs,
26
- ...after === void 0 ? {} : { after },
27
- limit
28
- });
29
- if (page.length === 0) break;
30
- if (page.length > limit) throw new AnalyticsPersistenceOrderError();
31
- let previous = after === void 0 ? void 0 : {
32
- received_at_ms: after.receivedAtMs,
33
- id: after.id
34
- };
35
- for (const row of page) {
36
- if (row.received_at_ms >= scope.cutoffMs || previous !== void 0 && compareEventOldest(previous, row) >= 0 || seenIds.has(row.id)) throw new AnalyticsPersistenceOrderError();
37
- seenIds.add(row.id);
38
- rows.push(row);
39
- previous = row;
40
- }
41
- const last = page.at(-1);
42
- if (last !== void 0) after = {
43
- receivedAtMs: last.received_at_ms,
44
- id: last.id
45
- };
46
- if (rows.length > 5e4) throw new require_errors.AnalyticsScanLimitExceededError(ANALYTICS_SCAN_MAX_ROWS);
47
- }
48
- return rows;
49
- };
50
- var AnalyticsPersistenceOrderError = class extends Error {
51
- name = "AnalyticsPersistenceOrderError";
52
- constructor() {
53
- super("Analytics persistence did not advance its scan cursor.");
54
- }
55
- };
56
- const materializeActiveRows = async (scope, window) => {
57
- const definition = require_activeOverview.getActiveWindowDefinition(window);
58
- const durationMs = definition.bucketCount * definition.bucketSizeMs;
59
- return (await materializeEventRows({
60
- ...scope,
61
- lowerBoundMs: scope.cutoffMs - durationMs
62
- })).filter((row) => row.received_at_ms >= scope.cutoffMs - durationMs && require_activeOverview.ACTIVE_BUNDLE_EVENT_TYPES.includes(row.type));
63
- };
64
- const startOfUtcHour = (value) => {
65
- const date = new Date(value);
66
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours());
67
- };
68
- const startOfUtcDay = (value) => {
69
- const date = new Date(value);
70
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
71
- };
72
- const getWindowRange = (window, now) => {
73
- if (window === "24h") return {
74
- sizeMs: 3600 * 1e3,
75
- rangeStart: startOfUtcHour(now) - 1380 * 60 * 1e3
76
- };
77
- const days = window === "7d" ? 7 : 30;
78
- return {
79
- sizeMs: 1440 * 60 * 1e3,
80
- rangeStart: startOfUtcDay(now) - (days - 1) * 24 * 60 * 60 * 1e3
81
- };
82
- };
83
- const materializeRowsForWindow = async (scope, window) => {
84
- if (window === "all") return materializeEventRows(scope);
85
- const range = getWindowRange(window, scope.cutoffMs);
86
- return (await materializeEventRows({
87
- ...scope,
88
- lowerBoundMs: range.rangeStart
89
- })).filter(({ received_at_ms }) => received_at_ms >= range.rangeStart);
90
- };
91
- const bucketStart = (receivedAtMs, sizeMs) => sizeMs === 3600 * 1e3 ? startOfUtcHour(receivedAtMs) : startOfUtcDay(receivedAtMs);
92
- const createSeries = (request) => {
93
- const range = request.window === "all" ? void 0 : getWindowRange(request.window, request.cutoffMs);
94
- const sizeMs = range?.sizeMs ?? 1440 * 60 * 1e3;
95
- const installIdsByBucket = /* @__PURE__ */ new Map();
96
- let oldestMs = request.cutoffMs;
97
- for (const row of request.rows) {
98
- oldestMs = Math.min(oldestMs, row.received_at_ms);
99
- const start = bucketStart(row.received_at_ms, sizeMs);
100
- const installIds = installIdsByBucket.get(start) ?? /* @__PURE__ */ new Set();
101
- installIds.add(row.install_id);
102
- installIdsByBucket.set(start, installIds);
103
- }
104
- const first = range?.rangeStart ?? startOfUtcDay(oldestMs);
105
- const last = bucketStart(request.cutoffMs, sizeMs);
106
- return Array.from({ length: Math.floor((last - first) / sizeMs) + 1 }, (_, index) => {
107
- const start = first + index * sizeMs;
108
- return {
109
- bucketStartMs: start,
110
- value: installIdsByBucket.get(start)?.size ?? 0
111
- };
112
- });
113
- };
114
- const collectEventActivity = (request) => {
115
- const range = request.window === "all" ? void 0 : getWindowRange(request.window, request.cutoffMs);
116
- const rows = range === void 0 ? request.rows : request.rows.filter(({ received_at_ms }) => received_at_ms >= range.rangeStart && received_at_ms < request.cutoffMs);
117
- const installs = /* @__PURE__ */ new Set();
118
- const installsByCohort = /* @__PURE__ */ new Map();
119
- for (const row of rows) {
120
- installs.add(row.install_id);
121
- const cohort = installsByCohort.get(row.cohort) ?? /* @__PURE__ */ new Set();
122
- cohort.add(row.install_id);
123
- installsByCohort.set(row.cohort, cohort);
124
- }
125
- return {
126
- summary: installs.size,
127
- cohorts: [...installsByCohort].sort(([left], [right]) => compareCodePoints(left, right)).map(([cohort, installIds]) => ({
128
- cohort,
129
- value: installIds.size
130
- })),
131
- series: createSeries({
132
- ...request,
133
- rows
134
- })
135
- };
136
- };
137
- //#endregion
138
- exports.ANALYTICS_SCAN_MAX_ROWS = ANALYTICS_SCAN_MAX_ROWS;
139
- exports.collectEventActivity = collectEventActivity;
140
- exports.compareCodePoints = compareCodePoints;
141
- exports.compareEventNewest = compareEventNewest;
142
- exports.materializeActiveRows = materializeActiveRows;
143
- exports.materializeEventRows = materializeEventRows;
144
- exports.materializeRowsForWindow = materializeRowsForWindow;
@@ -1,138 +0,0 @@
1
- import { AnalyticsScanLimitExceededError } from "../errors.mjs";
2
- import { ACTIVE_BUNDLE_EVENT_TYPES, getActiveWindowDefinition } from "./activeOverview.mjs";
3
- //#region src/analytics/bounded/scan.ts
4
- const ANALYTICS_SCAN_MAX_ROWS = 5e4;
5
- const ANALYTICS_MATERIALIZATION_LIMIT = ANALYTICS_SCAN_MAX_ROWS + 1;
6
- const ANALYTICS_SCAN_PAGE_SIZE = 1e3;
7
- const ANALYTICS_LOWER_BOUND_ID = "00000000-0000-0000-0000-000000000000";
8
- const compareCodePoints = (left, right) => {
9
- if (left < right) return -1;
10
- if (left > right) return 1;
11
- return 0;
12
- };
13
- const compareEventNewest = (left, right) => right.received_at_ms - left.received_at_ms || compareCodePoints(right.id, left.id);
14
- const compareEventOldest = (left, right) => left.received_at_ms - right.received_at_ms || compareCodePoints(left.id, right.id);
15
- const materializeEventRows = async (scope) => {
16
- const rows = [];
17
- const seenIds = /* @__PURE__ */ new Set();
18
- let after = scope.lowerBoundMs === void 0 ? void 0 : {
19
- receivedAtMs: scope.lowerBoundMs,
20
- id: ANALYTICS_LOWER_BOUND_ID
21
- };
22
- while (rows.length < ANALYTICS_MATERIALIZATION_LIMIT) {
23
- const limit = Math.min(ANALYTICS_SCAN_PAGE_SIZE, ANALYTICS_MATERIALIZATION_LIMIT - rows.length);
24
- const page = await scope.persistence.scan({
25
- beforeReceivedAtMs: scope.cutoffMs,
26
- ...after === void 0 ? {} : { after },
27
- limit
28
- });
29
- if (page.length === 0) break;
30
- if (page.length > limit) throw new AnalyticsPersistenceOrderError();
31
- let previous = after === void 0 ? void 0 : {
32
- received_at_ms: after.receivedAtMs,
33
- id: after.id
34
- };
35
- for (const row of page) {
36
- if (row.received_at_ms >= scope.cutoffMs || previous !== void 0 && compareEventOldest(previous, row) >= 0 || seenIds.has(row.id)) throw new AnalyticsPersistenceOrderError();
37
- seenIds.add(row.id);
38
- rows.push(row);
39
- previous = row;
40
- }
41
- const last = page.at(-1);
42
- if (last !== void 0) after = {
43
- receivedAtMs: last.received_at_ms,
44
- id: last.id
45
- };
46
- if (rows.length > 5e4) throw new AnalyticsScanLimitExceededError(ANALYTICS_SCAN_MAX_ROWS);
47
- }
48
- return rows;
49
- };
50
- var AnalyticsPersistenceOrderError = class extends Error {
51
- name = "AnalyticsPersistenceOrderError";
52
- constructor() {
53
- super("Analytics persistence did not advance its scan cursor.");
54
- }
55
- };
56
- const materializeActiveRows = async (scope, window) => {
57
- const definition = getActiveWindowDefinition(window);
58
- const durationMs = definition.bucketCount * definition.bucketSizeMs;
59
- return (await materializeEventRows({
60
- ...scope,
61
- lowerBoundMs: scope.cutoffMs - durationMs
62
- })).filter((row) => row.received_at_ms >= scope.cutoffMs - durationMs && ACTIVE_BUNDLE_EVENT_TYPES.includes(row.type));
63
- };
64
- const startOfUtcHour = (value) => {
65
- const date = new Date(value);
66
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours());
67
- };
68
- const startOfUtcDay = (value) => {
69
- const date = new Date(value);
70
- return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
71
- };
72
- const getWindowRange = (window, now) => {
73
- if (window === "24h") return {
74
- sizeMs: 3600 * 1e3,
75
- rangeStart: startOfUtcHour(now) - 1380 * 60 * 1e3
76
- };
77
- const days = window === "7d" ? 7 : 30;
78
- return {
79
- sizeMs: 1440 * 60 * 1e3,
80
- rangeStart: startOfUtcDay(now) - (days - 1) * 24 * 60 * 60 * 1e3
81
- };
82
- };
83
- const materializeRowsForWindow = async (scope, window) => {
84
- if (window === "all") return materializeEventRows(scope);
85
- const range = getWindowRange(window, scope.cutoffMs);
86
- return (await materializeEventRows({
87
- ...scope,
88
- lowerBoundMs: range.rangeStart
89
- })).filter(({ received_at_ms }) => received_at_ms >= range.rangeStart);
90
- };
91
- const bucketStart = (receivedAtMs, sizeMs) => sizeMs === 3600 * 1e3 ? startOfUtcHour(receivedAtMs) : startOfUtcDay(receivedAtMs);
92
- const createSeries = (request) => {
93
- const range = request.window === "all" ? void 0 : getWindowRange(request.window, request.cutoffMs);
94
- const sizeMs = range?.sizeMs ?? 1440 * 60 * 1e3;
95
- const installIdsByBucket = /* @__PURE__ */ new Map();
96
- let oldestMs = request.cutoffMs;
97
- for (const row of request.rows) {
98
- oldestMs = Math.min(oldestMs, row.received_at_ms);
99
- const start = bucketStart(row.received_at_ms, sizeMs);
100
- const installIds = installIdsByBucket.get(start) ?? /* @__PURE__ */ new Set();
101
- installIds.add(row.install_id);
102
- installIdsByBucket.set(start, installIds);
103
- }
104
- const first = range?.rangeStart ?? startOfUtcDay(oldestMs);
105
- const last = bucketStart(request.cutoffMs, sizeMs);
106
- return Array.from({ length: Math.floor((last - first) / sizeMs) + 1 }, (_, index) => {
107
- const start = first + index * sizeMs;
108
- return {
109
- bucketStartMs: start,
110
- value: installIdsByBucket.get(start)?.size ?? 0
111
- };
112
- });
113
- };
114
- const collectEventActivity = (request) => {
115
- const range = request.window === "all" ? void 0 : getWindowRange(request.window, request.cutoffMs);
116
- const rows = range === void 0 ? request.rows : request.rows.filter(({ received_at_ms }) => received_at_ms >= range.rangeStart && received_at_ms < request.cutoffMs);
117
- const installs = /* @__PURE__ */ new Set();
118
- const installsByCohort = /* @__PURE__ */ new Map();
119
- for (const row of rows) {
120
- installs.add(row.install_id);
121
- const cohort = installsByCohort.get(row.cohort) ?? /* @__PURE__ */ new Set();
122
- cohort.add(row.install_id);
123
- installsByCohort.set(row.cohort, cohort);
124
- }
125
- return {
126
- summary: installs.size,
127
- cohorts: [...installsByCohort].sort(([left], [right]) => compareCodePoints(left, right)).map(([cohort, installIds]) => ({
128
- cohort,
129
- value: installIds.size
130
- })),
131
- series: createSeries({
132
- ...request,
133
- rows
134
- })
135
- };
136
- };
137
- //#endregion
138
- export { ANALYTICS_SCAN_MAX_ROWS, collectEventActivity, compareCodePoints, compareEventNewest, materializeActiveRows, materializeEventRows, materializeRowsForWindow };
@@ -1,121 +0,0 @@
1
- //#region src/analytics/domain.d.ts
2
- type CreateBundleEventRequestBase = {
3
- readonly installId: string;
4
- readonly toBundleId: string;
5
- readonly userId?: string;
6
- readonly username?: string;
7
- readonly platform: "ios" | "android";
8
- readonly appVersion: string;
9
- readonly channel: string;
10
- readonly cohort: string;
11
- readonly fingerprintHash: string | null;
12
- readonly sdkVersion?: string | null;
13
- readonly fromReleaseId: string | null;
14
- readonly toReleaseId: string | null;
15
- };
16
- type CreateBundleEventRequest = (CreateBundleEventRequestBase & {
17
- readonly type: "UPDATE_APPLIED";
18
- readonly fromBundleId: string;
19
- readonly updateStrategy: "fingerprint" | "appVersion";
20
- }) | (CreateBundleEventRequestBase & {
21
- readonly type: "RECOVERED";
22
- readonly fromBundleId: string;
23
- readonly updateStrategy: "fingerprint" | "appVersion";
24
- }) | (CreateBundleEventRequestBase & {
25
- readonly type: "RELEASE_ADOPTED";
26
- readonly fromBundleId: string;
27
- readonly updateStrategy: "fingerprint" | "appVersion";
28
- }) | (CreateBundleEventRequestBase & {
29
- readonly type: "UNCHANGED";
30
- readonly fromBundleId: null;
31
- readonly updateStrategy: null;
32
- });
33
- type BundleEventSummary = {
34
- readonly installed: number;
35
- readonly recovered: number;
36
- };
37
- type BundleEventSummaryByBundle = BundleEventSummary & {
38
- readonly bundleId: string;
39
- };
40
- type BundleEventAnalyticsWindow = "24h" | "7d" | "30d" | "all";
41
- type ActiveInstallationWindow = "24h" | "7d" | "30d";
42
- type InstallationSearchRow = {
43
- readonly installId: string;
44
- readonly username: string | null;
45
- readonly userId: string | null;
46
- readonly lastKnownBundleId: string;
47
- readonly latestStatus: "UPDATE_APPLIED" | "RECOVERED" | "RELEASE_ADOPTED" | "UNCHANGED";
48
- readonly platform: "ios" | "android";
49
- readonly appVersion: string;
50
- readonly channel: string;
51
- readonly cohort: string;
52
- readonly receivedAtMs: number;
53
- };
54
- type InstallationHistoryRow = {
55
- readonly id: string;
56
- readonly type: "UPDATE_APPLIED" | "RECOVERED";
57
- readonly fromBundleId: string;
58
- readonly toBundleId: string;
59
- readonly username: string | null;
60
- readonly userId: string | null;
61
- readonly platform: "ios" | "android";
62
- readonly appVersion: string;
63
- readonly channel: string;
64
- readonly cohort: string;
65
- readonly receivedAtMs: number;
66
- };
67
- type OffsetPaginationResult<TData> = {
68
- readonly data: readonly TData[];
69
- readonly pagination: {
70
- readonly total: number;
71
- readonly limit: number;
72
- readonly offset: number;
73
- };
74
- };
75
- type AnalyticsSeriesPoint = {
76
- readonly bucketStartMs: number;
77
- readonly value: number;
78
- };
79
- type AnalyticsCohortPoint = {
80
- readonly cohort: string;
81
- readonly value: number;
82
- };
83
- type BundleEventAnalyticsResult = {
84
- readonly summary: BundleEventSummary;
85
- readonly series: {
86
- readonly installed: readonly AnalyticsSeriesPoint[];
87
- readonly recovered: readonly AnalyticsSeriesPoint[];
88
- };
89
- readonly cohorts: {
90
- readonly installed: readonly AnalyticsCohortPoint[];
91
- readonly recovered: readonly AnalyticsCohortPoint[];
92
- };
93
- readonly recentEvents: OffsetPaginationResult<InstallationHistoryRow>;
94
- };
95
- type BundleEventOverview = {
96
- readonly trackedInstallations: number;
97
- readonly bundles: readonly {
98
- readonly bundleId: string;
99
- readonly installations: number;
100
- }[];
101
- };
102
- type ActiveInstallationOverview = {
103
- readonly asOfMs: number;
104
- readonly window: ActiveInstallationWindow;
105
- readonly activeInstallations: number;
106
- readonly series: readonly AnalyticsSeriesPoint[];
107
- readonly bundleSeries: readonly {
108
- readonly bundleId: string;
109
- readonly series: readonly AnalyticsSeriesPoint[];
110
- }[];
111
- readonly bundles: readonly {
112
- readonly bundleId: string;
113
- readonly installations: number;
114
- }[];
115
- };
116
- type ActiveInstallationInput = {
117
- readonly window: ActiveInstallationWindow;
118
- readonly userId?: string;
119
- };
120
- //#endregion
121
- export { ActiveInstallationInput, ActiveInstallationOverview, ActiveInstallationWindow, AnalyticsCohortPoint, AnalyticsSeriesPoint, BundleEventAnalyticsResult, BundleEventAnalyticsWindow, BundleEventOverview, BundleEventSummary, BundleEventSummaryByBundle, CreateBundleEventRequest, CreateBundleEventRequestBase, InstallationHistoryRow, InstallationSearchRow, OffsetPaginationResult };
@@ -1,121 +0,0 @@
1
- //#region src/analytics/domain.d.ts
2
- type CreateBundleEventRequestBase = {
3
- readonly installId: string;
4
- readonly toBundleId: string;
5
- readonly userId?: string;
6
- readonly username?: string;
7
- readonly platform: "ios" | "android";
8
- readonly appVersion: string;
9
- readonly channel: string;
10
- readonly cohort: string;
11
- readonly fingerprintHash: string | null;
12
- readonly sdkVersion?: string | null;
13
- readonly fromReleaseId: string | null;
14
- readonly toReleaseId: string | null;
15
- };
16
- type CreateBundleEventRequest = (CreateBundleEventRequestBase & {
17
- readonly type: "UPDATE_APPLIED";
18
- readonly fromBundleId: string;
19
- readonly updateStrategy: "fingerprint" | "appVersion";
20
- }) | (CreateBundleEventRequestBase & {
21
- readonly type: "RECOVERED";
22
- readonly fromBundleId: string;
23
- readonly updateStrategy: "fingerprint" | "appVersion";
24
- }) | (CreateBundleEventRequestBase & {
25
- readonly type: "RELEASE_ADOPTED";
26
- readonly fromBundleId: string;
27
- readonly updateStrategy: "fingerprint" | "appVersion";
28
- }) | (CreateBundleEventRequestBase & {
29
- readonly type: "UNCHANGED";
30
- readonly fromBundleId: null;
31
- readonly updateStrategy: null;
32
- });
33
- type BundleEventSummary = {
34
- readonly installed: number;
35
- readonly recovered: number;
36
- };
37
- type BundleEventSummaryByBundle = BundleEventSummary & {
38
- readonly bundleId: string;
39
- };
40
- type BundleEventAnalyticsWindow = "24h" | "7d" | "30d" | "all";
41
- type ActiveInstallationWindow = "24h" | "7d" | "30d";
42
- type InstallationSearchRow = {
43
- readonly installId: string;
44
- readonly username: string | null;
45
- readonly userId: string | null;
46
- readonly lastKnownBundleId: string;
47
- readonly latestStatus: "UPDATE_APPLIED" | "RECOVERED" | "RELEASE_ADOPTED" | "UNCHANGED";
48
- readonly platform: "ios" | "android";
49
- readonly appVersion: string;
50
- readonly channel: string;
51
- readonly cohort: string;
52
- readonly receivedAtMs: number;
53
- };
54
- type InstallationHistoryRow = {
55
- readonly id: string;
56
- readonly type: "UPDATE_APPLIED" | "RECOVERED";
57
- readonly fromBundleId: string;
58
- readonly toBundleId: string;
59
- readonly username: string | null;
60
- readonly userId: string | null;
61
- readonly platform: "ios" | "android";
62
- readonly appVersion: string;
63
- readonly channel: string;
64
- readonly cohort: string;
65
- readonly receivedAtMs: number;
66
- };
67
- type OffsetPaginationResult<TData> = {
68
- readonly data: readonly TData[];
69
- readonly pagination: {
70
- readonly total: number;
71
- readonly limit: number;
72
- readonly offset: number;
73
- };
74
- };
75
- type AnalyticsSeriesPoint = {
76
- readonly bucketStartMs: number;
77
- readonly value: number;
78
- };
79
- type AnalyticsCohortPoint = {
80
- readonly cohort: string;
81
- readonly value: number;
82
- };
83
- type BundleEventAnalyticsResult = {
84
- readonly summary: BundleEventSummary;
85
- readonly series: {
86
- readonly installed: readonly AnalyticsSeriesPoint[];
87
- readonly recovered: readonly AnalyticsSeriesPoint[];
88
- };
89
- readonly cohorts: {
90
- readonly installed: readonly AnalyticsCohortPoint[];
91
- readonly recovered: readonly AnalyticsCohortPoint[];
92
- };
93
- readonly recentEvents: OffsetPaginationResult<InstallationHistoryRow>;
94
- };
95
- type BundleEventOverview = {
96
- readonly trackedInstallations: number;
97
- readonly bundles: readonly {
98
- readonly bundleId: string;
99
- readonly installations: number;
100
- }[];
101
- };
102
- type ActiveInstallationOverview = {
103
- readonly asOfMs: number;
104
- readonly window: ActiveInstallationWindow;
105
- readonly activeInstallations: number;
106
- readonly series: readonly AnalyticsSeriesPoint[];
107
- readonly bundleSeries: readonly {
108
- readonly bundleId: string;
109
- readonly series: readonly AnalyticsSeriesPoint[];
110
- }[];
111
- readonly bundles: readonly {
112
- readonly bundleId: string;
113
- readonly installations: number;
114
- }[];
115
- };
116
- type ActiveInstallationInput = {
117
- readonly window: ActiveInstallationWindow;
118
- readonly userId?: string;
119
- };
120
- //#endregion
121
- export { ActiveInstallationInput, ActiveInstallationOverview, ActiveInstallationWindow, AnalyticsCohortPoint, AnalyticsSeriesPoint, BundleEventAnalyticsResult, BundleEventAnalyticsWindow, BundleEventOverview, BundleEventSummary, BundleEventSummaryByBundle, CreateBundleEventRequest, CreateBundleEventRequestBase, InstallationHistoryRow, InstallationSearchRow, OffsetPaginationResult };
@@ -1,22 +0,0 @@
1
- //#region src/analytics/errors.ts
2
- var AnalyticsScanLimitExceededError = class extends Error {
3
- constructor(limit) {
4
- super(`Analytics event scan exceeded ${limit} rows.`);
5
- this.limit = limit;
6
- this.name = "AnalyticsScanLimitExceededError";
7
- }
8
- };
9
- var AnalyticsBadRequestError = class extends Error {
10
- name = "AnalyticsBadRequestError";
11
- };
12
- var AnalyticsPayloadTooLargeError = class extends Error {
13
- name = "AnalyticsPayloadTooLargeError";
14
- constructor(maximumBytes) {
15
- super(`Event payload exceeds ${maximumBytes} bytes`);
16
- this.maximumBytes = maximumBytes;
17
- }
18
- };
19
- //#endregion
20
- exports.AnalyticsBadRequestError = AnalyticsBadRequestError;
21
- exports.AnalyticsPayloadTooLargeError = AnalyticsPayloadTooLargeError;
22
- exports.AnalyticsScanLimitExceededError = AnalyticsScanLimitExceededError;
@@ -1,20 +0,0 @@
1
- //#region src/analytics/errors.ts
2
- var AnalyticsScanLimitExceededError = class extends Error {
3
- constructor(limit) {
4
- super(`Analytics event scan exceeded ${limit} rows.`);
5
- this.limit = limit;
6
- this.name = "AnalyticsScanLimitExceededError";
7
- }
8
- };
9
- var AnalyticsBadRequestError = class extends Error {
10
- name = "AnalyticsBadRequestError";
11
- };
12
- var AnalyticsPayloadTooLargeError = class extends Error {
13
- name = "AnalyticsPayloadTooLargeError";
14
- constructor(maximumBytes) {
15
- super(`Event payload exceeds ${maximumBytes} bytes`);
16
- this.maximumBytes = maximumBytes;
17
- }
18
- };
19
- //#endregion
20
- export { AnalyticsBadRequestError, AnalyticsPayloadTooLargeError, AnalyticsScanLimitExceededError };
@@ -1,6 +0,0 @@
1
- import { AnalyticsModel } from "@hot-updater/plugin-core";
2
-
3
- //#region src/analytics/persistence.d.ts
4
- type AnalyticsPersistence = AnalyticsModel;
5
- //#endregion
6
- export { AnalyticsPersistence };
@@ -1,6 +0,0 @@
1
- import { AnalyticsModel } from "@hot-updater/plugin-core";
2
-
3
- //#region src/analytics/persistence.d.ts
4
- type AnalyticsPersistence = AnalyticsModel;
5
- //#endregion
6
- export { AnalyticsPersistence };
@@ -1,58 +0,0 @@
1
- const require_errors = require("./errors.cjs");
2
- //#region src/analytics/queryInput.ts
3
- const EVENT_LIST_BOUNDS = {
4
- defaultValue: 50,
5
- maximum: 100,
6
- minimum: 1
7
- };
8
- const EVENT_LIST_OFFSET_BOUNDS = {
9
- defaultValue: 0,
10
- minimum: 0
11
- };
12
- const MAX_USER_ID_LENGTH = 1024;
13
- function parseInteger(url, key, bounds) {
14
- const value = url.searchParams.get(key);
15
- if (value === null) return bounds.defaultValue;
16
- const parsed = Number(value);
17
- if (!Number.isSafeInteger(parsed) || parsed < bounds.minimum || bounds.maximum !== void 0 && parsed > bounds.maximum) throw new require_errors.AnalyticsBadRequestError(`Invalid '${key}' query parameter.`);
18
- return parsed;
19
- }
20
- const parsePagination = (request) => {
21
- const url = new URL(request.url);
22
- return {
23
- limit: parseInteger(url, "limit", EVENT_LIST_BOUNDS),
24
- offset: parseInteger(url, "offset", EVENT_LIST_OFFSET_BOUNDS)
25
- };
26
- };
27
- const parseAnalyticsQuery = (request) => {
28
- const window = new URL(request.url).searchParams.get("window") ?? "24h";
29
- if (window !== "24h" && window !== "7d" && window !== "30d" && window !== "all") throw new require_errors.AnalyticsBadRequestError("Invalid 'window' query parameter.");
30
- return {
31
- ...parsePagination(request),
32
- window
33
- };
34
- };
35
- const parseActiveInstallationInput = (request) => {
36
- const url = new URL(request.url);
37
- const windows = url.searchParams.getAll("window");
38
- if (windows.length > 1) throw new require_errors.AnalyticsBadRequestError("Duplicate 'window' query parameter.");
39
- const window = windows[0] ?? "30d";
40
- if (window !== "24h" && window !== "7d" && window !== "30d") throw new require_errors.AnalyticsBadRequestError("Invalid 'window' query parameter.");
41
- const userIds = url.searchParams.getAll("userId");
42
- if (userIds.length > 1) throw new require_errors.AnalyticsBadRequestError("Duplicate 'userId' query parameter.");
43
- const userId = userIds[0];
44
- if (userId !== void 0 && (userId.length === 0 || userId.length > MAX_USER_ID_LENGTH)) throw new require_errors.AnalyticsBadRequestError("Invalid 'userId' query parameter.");
45
- return userId === void 0 ? { window } : {
46
- window,
47
- userId
48
- };
49
- };
50
- const parseSearchInput = (request) => ({
51
- ...parsePagination(request),
52
- query: new URL(request.url).searchParams.get("query")?.trim() ?? ""
53
- });
54
- //#endregion
55
- exports.parseActiveInstallationInput = parseActiveInstallationInput;
56
- exports.parseAnalyticsQuery = parseAnalyticsQuery;
57
- exports.parsePagination = parsePagination;
58
- exports.parseSearchInput = parseSearchInput;