@hot-updater/server 1.0.0-rc.18 → 1.0.0-rc.21

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 (485) hide show
  1. package/LICENSE +12 -14
  2. package/dist/adapters/drizzle.cjs +6 -8
  3. package/dist/adapters/drizzle.d.cts +2 -2
  4. package/dist/adapters/drizzle.d.mts +2 -2
  5. package/dist/adapters/drizzle.mjs +1 -3
  6. package/dist/adapters/drizzleExecutor.d.cts +1 -1
  7. package/dist/adapters/drizzleExecutor.d.mts +1 -1
  8. package/dist/adapters/kysely.cjs +4 -6
  9. package/dist/adapters/kysely.d.cts +3 -3
  10. package/dist/adapters/kysely.d.mts +3 -3
  11. package/dist/adapters/kysely.mjs +1 -3
  12. package/dist/adapters/kyselyExecutor.d.cts +1 -2
  13. package/dist/adapters/kyselyExecutor.d.mts +1 -2
  14. package/dist/adapters/mongodb.cjs +10 -21
  15. package/dist/adapters/mongodb.d.cts +1 -1
  16. package/dist/adapters/mongodb.d.mts +1 -1
  17. package/dist/adapters/mongodb.mjs +9 -20
  18. package/dist/adapters/mongodbAdapter.cjs +11 -11
  19. package/dist/adapters/mongodbAdapter.d.cts +1 -1
  20. package/dist/adapters/mongodbAdapter.d.mts +1 -1
  21. package/dist/adapters/mongodbAdapter.mjs +1 -1
  22. package/dist/adapters/prisma.cjs +7 -9
  23. package/dist/adapters/prisma.d.cts +1 -1
  24. package/dist/adapters/prisma.d.mts +1 -1
  25. package/dist/adapters/prisma.mjs +1 -3
  26. package/dist/adapters/prismaExecutor.cjs +2 -3
  27. package/dist/adapters/prismaExecutor.mjs +1 -2
  28. package/dist/adapters/sqlProviders.cjs +7 -2
  29. package/dist/adapters/sqlProviders.mjs +6 -1
  30. package/dist/assembly/assemblePlugins.cjs +26 -48
  31. package/dist/assembly/assemblePlugins.d.cts +2 -5
  32. package/dist/assembly/assemblePlugins.d.mts +2 -5
  33. package/dist/assembly/assemblePlugins.mjs +19 -45
  34. package/dist/assembly/clientPlugins.cjs +6 -4
  35. package/dist/assembly/clientPlugins.mjs +2 -0
  36. package/dist/assembly/configError.d.cts +1 -6
  37. package/dist/assembly/configError.d.mts +1 -6
  38. package/dist/assembly/configError.mjs +1 -6
  39. package/dist/core/api.cjs +0 -40
  40. package/dist/core/api.d.cts +5 -16
  41. package/dist/core/api.d.mts +5 -16
  42. package/dist/core/api.mjs +1 -37
  43. package/dist/core/baseCandidates.cjs +0 -43
  44. package/dist/core/baseCandidates.mjs +2 -43
  45. package/dist/core/operations.cjs +13 -12
  46. package/dist/core/operations.mjs +6 -5
  47. package/dist/core/reads.cjs +4 -4
  48. package/dist/core/reads.d.cts +2 -41
  49. package/dist/core/reads.d.mts +2 -41
  50. package/dist/core/reads.mjs +3 -3
  51. package/dist/core/releases.cjs +6 -6
  52. package/dist/core/releases.mjs +1 -1
  53. package/dist/core/writes.cjs +2 -2
  54. package/dist/core/writes.mjs +1 -1
  55. package/dist/createHotUpdaterCore.cjs +39 -39
  56. package/dist/createHotUpdaterCore.d.cts +61 -8
  57. package/dist/createHotUpdaterCore.d.mts +61 -8
  58. package/dist/createHotUpdaterCore.mjs +35 -32
  59. package/dist/db/engineDrizzleSchema.cjs +3 -4
  60. package/dist/db/engineDrizzleSchema.mjs +1 -2
  61. package/dist/db/enginePrismaSchema.cjs +4 -5
  62. package/dist/db/enginePrismaSchema.d.cts +1 -1
  63. package/dist/db/enginePrismaSchema.d.mts +1 -1
  64. package/dist/db/enginePrismaSchema.mjs +1 -2
  65. package/dist/db/releaseCatalog.cjs +6 -6
  66. package/dist/db/releaseCatalog.mjs +1 -1
  67. package/dist/db/updateArtifacts.cjs +6 -6
  68. package/dist/db/updateArtifacts.mjs +1 -1
  69. package/dist/handler.cjs +3 -4
  70. package/dist/handler.mjs +1 -1
  71. package/dist/handlerAdminRoutes.cjs +1 -2
  72. package/dist/handlerAdminRoutes.mjs +1 -2
  73. package/dist/handlerVersionRoutes.cjs +2 -2
  74. package/dist/handlerVersionRoutes.mjs +2 -2
  75. package/dist/index.cjs +9 -2
  76. package/dist/index.d.cts +4 -3
  77. package/dist/index.d.mts +4 -3
  78. package/dist/index.mjs +2 -1
  79. package/dist/node.cjs +3 -6
  80. package/dist/node.d.cts +3 -3
  81. package/dist/node.d.mts +3 -3
  82. package/dist/node.mjs +4 -4
  83. package/dist/package.cjs +1 -1
  84. package/dist/package.mjs +1 -1
  85. package/dist/plugins/api-keys/index.cjs +8 -52
  86. package/dist/plugins/api-keys/index.d.cts +1 -84
  87. package/dist/plugins/api-keys/index.d.mts +1 -84
  88. package/dist/plugins/api-keys/index.mjs +2 -49
  89. package/dist/plugins/definePlugin.d.cts +2 -200
  90. package/dist/plugins/definePlugin.d.mts +2 -200
  91. package/dist/plugins/insights/index.cjs +7 -126
  92. package/dist/plugins/insights/index.d.cts +1 -398
  93. package/dist/plugins/insights/index.d.mts +1 -398
  94. package/dist/plugins/insights/index.mjs +2 -121
  95. package/dist/plugins/official.cjs +30 -0
  96. package/dist/plugins/official.mjs +29 -0
  97. package/dist/storageAccess.cjs +13 -10
  98. package/dist/storageAccess.mjs +13 -10
  99. package/dist/types/index.d.cts +1 -1
  100. package/dist/types/index.d.mts +1 -1
  101. package/package.json +15 -37
  102. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  103. package/dist/assembly/clientPlugins.d.cts +0 -16
  104. package/dist/assembly/clientPlugins.d.mts +0 -16
  105. package/dist/assembly/configError.cjs +0 -7
  106. package/dist/assembly/databasePlugins.cjs +0 -27
  107. package/dist/assembly/databasePlugins.d.cts +0 -43
  108. package/dist/assembly/databasePlugins.d.mts +0 -43
  109. package/dist/assembly/databasePlugins.mjs +0 -26
  110. package/dist/assembly/pluginCli.cjs +0 -125
  111. package/dist/assembly/pluginCli.d.cts +0 -59
  112. package/dist/assembly/pluginCli.d.mts +0 -59
  113. package/dist/assembly/pluginCli.mjs +0 -121
  114. package/dist/core/baseCandidates.d.cts +0 -17
  115. package/dist/core/baseCandidates.d.mts +0 -17
  116. package/dist/core/schema.cjs +0 -279
  117. package/dist/core/schema.d.cts +0 -307
  118. package/dist/core/schema.d.mts +0 -307
  119. package/dist/core/schema.mjs +0 -277
  120. package/dist/database/aggregateBatching.cjs +0 -626
  121. package/dist/database/aggregateBatching.d.cts +0 -10
  122. package/dist/database/aggregateBatching.d.mts +0 -10
  123. package/dist/database/aggregateBatching.mjs +0 -625
  124. package/dist/database/busy.cjs +0 -36
  125. package/dist/database/busy.d.cts +0 -12
  126. package/dist/database/busy.d.mts +0 -12
  127. package/dist/database/busy.mjs +0 -36
  128. package/dist/database/cursor.cjs +0 -44
  129. package/dist/database/cursor.d.cts +0 -7
  130. package/dist/database/cursor.d.mts +0 -7
  131. package/dist/database/cursor.mjs +0 -40
  132. package/dist/database/database.cjs +0 -63
  133. package/dist/database/database.d.cts +0 -136
  134. package/dist/database/database.d.mts +0 -136
  135. package/dist/database/database.mjs +0 -63
  136. package/dist/database/definitions.d.cts +0 -78
  137. package/dist/database/definitions.d.mts +0 -78
  138. package/dist/database/engine.cjs +0 -37
  139. package/dist/database/engine.d.cts +0 -41
  140. package/dist/database/engine.d.mts +0 -41
  141. package/dist/database/engine.mjs +0 -37
  142. package/dist/database/engineAggregates.cjs +0 -118
  143. package/dist/database/engineAggregates.mjs +0 -115
  144. package/dist/database/engineReads.cjs +0 -182
  145. package/dist/database/engineReads.d.cts +0 -35
  146. package/dist/database/engineReads.d.mts +0 -35
  147. package/dist/database/engineReads.mjs +0 -181
  148. package/dist/database/engineTransaction.cjs +0 -399
  149. package/dist/database/engineTransaction.d.cts +0 -26
  150. package/dist/database/engineTransaction.d.mts +0 -26
  151. package/dist/database/engineTransaction.mjs +0 -398
  152. package/dist/database/errors.cjs +0 -27
  153. package/dist/database/errors.d.cts +0 -21
  154. package/dist/database/errors.d.mts +0 -21
  155. package/dist/database/errors.mjs +0 -24
  156. package/dist/database/fence.cjs +0 -125
  157. package/dist/database/fence.d.cts +0 -42
  158. package/dist/database/fence.d.mts +0 -42
  159. package/dist/database/fence.mjs +0 -117
  160. package/dist/database/index.cjs +0 -136
  161. package/dist/database/index.d.cts +0 -18
  162. package/dist/database/index.d.mts +0 -18
  163. package/dist/database/index.mjs +0 -16
  164. package/dist/database/kv/kvAdapter.cjs +0 -285
  165. package/dist/database/kv/kvAdapter.d.cts +0 -109
  166. package/dist/database/kv/kvAdapter.d.mts +0 -109
  167. package/dist/database/kv/kvAdapter.mjs +0 -284
  168. package/dist/database/resolveSchema.cjs +0 -199
  169. package/dist/database/resolveSchema.d.cts +0 -42
  170. package/dist/database/resolveSchema.d.mts +0 -42
  171. package/dist/database/resolveSchema.mjs +0 -196
  172. package/dist/database/retention.cjs +0 -92
  173. package/dist/database/retention.mjs +0 -90
  174. package/dist/database/schema.cjs +0 -24
  175. package/dist/database/schema.d.cts +0 -90
  176. package/dist/database/schema.d.mts +0 -90
  177. package/dist/database/schema.mjs +0 -23
  178. package/dist/database/sql/sqlAdapter.cjs +0 -290
  179. package/dist/database/sql/sqlAdapter.d.cts +0 -46
  180. package/dist/database/sql/sqlAdapter.d.mts +0 -46
  181. package/dist/database/sql/sqlAdapter.mjs +0 -287
  182. package/dist/database/sql/sqlSchema.cjs +0 -171
  183. package/dist/database/sql/sqlSchema.d.cts +0 -8
  184. package/dist/database/sql/sqlSchema.d.mts +0 -8
  185. package/dist/database/sql/sqlSchema.mjs +0 -165
  186. package/dist/db/coreDatabase.cjs +0 -85
  187. package/dist/db/coreDatabase.d.cts +0 -57
  188. package/dist/db/coreDatabase.d.mts +0 -57
  189. package/dist/db/coreDatabase.mjs +0 -78
  190. package/dist/db/createBundleDiff.cjs +0 -144
  191. package/dist/db/createBundleDiff.d.cts +0 -17
  192. package/dist/db/createBundleDiff.d.mts +0 -17
  193. package/dist/db/createBundleDiff.mjs +0 -141
  194. package/dist/db/engineMigrator.cjs +0 -53
  195. package/dist/db/engineMigrator.mjs +0 -53
  196. package/dist/db/engineSql.cjs +0 -26
  197. package/dist/db/engineSql.d.cts +0 -17
  198. package/dist/db/engineSql.d.mts +0 -17
  199. package/dist/db/engineSql.mjs +0 -25
  200. package/dist/db/engineSqlMigrator.cjs +0 -66
  201. package/dist/db/engineSqlMigrator.mjs +0 -66
  202. package/dist/db/fixedMigratorShared.cjs +0 -12
  203. package/dist/db/fixedMigratorShared.mjs +0 -11
  204. package/dist/db/index.cjs +0 -50
  205. package/dist/db/index.d.cts +0 -23
  206. package/dist/db/index.d.mts +0 -23
  207. package/dist/db/index.mjs +0 -33
  208. package/dist/db/releaseCatalog.d.cts +0 -16
  209. package/dist/db/releaseCatalog.d.mts +0 -16
  210. package/dist/db/schemaSettings.cjs +0 -63
  211. package/dist/db/schemaSettings.d.cts +0 -12
  212. package/dist/db/schemaSettings.d.mts +0 -12
  213. package/dist/db/schemaSettings.mjs +0 -62
  214. package/dist/db/settingsMigrator.cjs +0 -92
  215. package/dist/db/settingsMigrator.mjs +0 -89
  216. package/dist/db/types.cjs +0 -11
  217. package/dist/db/types.d.cts +0 -78
  218. package/dist/db/types.d.mts +0 -78
  219. package/dist/db/types.mjs +0 -10
  220. package/dist/diff.cjs +0 -3
  221. package/dist/diff.d.cts +0 -2
  222. package/dist/diff.d.mts +0 -2
  223. package/dist/diff.mjs +0 -2
  224. package/dist/plugins/api-keys/apiKeys.cjs +0 -139
  225. package/dist/plugins/api-keys/apiKeys.d.cts +0 -27
  226. package/dist/plugins/api-keys/apiKeys.d.mts +0 -27
  227. package/dist/plugins/api-keys/apiKeys.mjs +0 -129
  228. package/dist/plugins/api-keys/cli.cjs +0 -115
  229. package/dist/plugins/api-keys/cli.mjs +0 -114
  230. package/dist/plugins/api-keys/model.cjs +0 -58
  231. package/dist/plugins/api-keys/model.d.cts +0 -26
  232. package/dist/plugins/api-keys/model.d.mts +0 -26
  233. package/dist/plugins/api-keys/model.mjs +0 -58
  234. package/dist/plugins/api-keys/schema.cjs +0 -38
  235. package/dist/plugins/api-keys/schema.d.cts +0 -44
  236. package/dist/plugins/api-keys/schema.d.mts +0 -44
  237. package/dist/plugins/api-keys/schema.mjs +0 -39
  238. package/dist/plugins/definePlugin.cjs +0 -5
  239. package/dist/plugins/definePlugin.mjs +0 -5
  240. package/dist/plugins/index.cjs +0 -38
  241. package/dist/plugins/index.d.cts +0 -12
  242. package/dist/plugins/index.d.mts +0 -12
  243. package/dist/plugins/index.mjs +0 -9
  244. package/dist/plugins/insights/contract.cjs +0 -193
  245. package/dist/plugins/insights/contract.mjs +0 -189
  246. package/dist/plugins/insights/domain.d.cts +0 -149
  247. package/dist/plugins/insights/domain.d.mts +0 -149
  248. package/dist/plugins/insights/errors.cjs +0 -15
  249. package/dist/plugins/insights/errors.mjs +0 -14
  250. package/dist/plugins/insights/eventInput.cjs +0 -284
  251. package/dist/plugins/insights/eventInput.mjs +0 -282
  252. package/dist/plugins/insights/eventRow.cjs +0 -49
  253. package/dist/plugins/insights/eventRow.d.cts +0 -64
  254. package/dist/plugins/insights/eventRow.d.mts +0 -64
  255. package/dist/plugins/insights/eventRow.mjs +0 -47
  256. package/dist/plugins/insights/model.cjs +0 -17
  257. package/dist/plugins/insights/model.d.cts +0 -10
  258. package/dist/plugins/insights/model.d.mts +0 -10
  259. package/dist/plugins/insights/model.mjs +0 -17
  260. package/dist/plugins/insights/modelTypes.d.cts +0 -176
  261. package/dist/plugins/insights/modelTypes.d.mts +0 -176
  262. package/dist/plugins/insights/overview.cjs +0 -109
  263. package/dist/plugins/insights/overview.d.cts +0 -15
  264. package/dist/plugins/insights/overview.d.mts +0 -15
  265. package/dist/plugins/insights/overview.mjs +0 -107
  266. package/dist/plugins/insights/provider.cjs +0 -375
  267. package/dist/plugins/insights/provider.d.cts +0 -6
  268. package/dist/plugins/insights/provider.d.mts +0 -6
  269. package/dist/plugins/insights/provider.mjs +0 -374
  270. package/dist/plugins/insights/queryInput.cjs +0 -93
  271. package/dist/plugins/insights/queryInput.mjs +0 -91
  272. package/dist/plugins/insights/reads.cjs +0 -681
  273. package/dist/plugins/insights/reads.d.cts +0 -61
  274. package/dist/plugins/insights/reads.d.mts +0 -61
  275. package/dist/plugins/insights/reads.mjs +0 -674
  276. package/dist/plugins/insights/recordEvent.cjs +0 -319
  277. package/dist/plugins/insights/recordEvent.d.cts +0 -18
  278. package/dist/plugins/insights/recordEvent.d.mts +0 -18
  279. package/dist/plugins/insights/recordEvent.mjs +0 -316
  280. package/dist/plugins/insights/routes.cjs +0 -96
  281. package/dist/plugins/insights/routes.mjs +0 -95
  282. package/dist/plugins/insights/schema.cjs +0 -489
  283. package/dist/plugins/insights/schema.d.cts +0 -698
  284. package/dist/plugins/insights/schema.d.mts +0 -698
  285. package/dist/plugins/insights/schema.mjs +0 -483
  286. package/dist/plugins/insights/testing/eventRow.d.mts +0 -64
  287. package/dist/plugins/insights/testing/expectInsightsIndex.mjs +0 -18
  288. package/dist/plugins/insights/testing/fixtures.d.mts +0 -8
  289. package/dist/plugins/insights/testing/fixtures.mjs +0 -25
  290. package/dist/plugins/insights/testing/index.d.mts +0 -24
  291. package/dist/plugins/insights/testing/index.mjs +0 -25
  292. package/dist/plugins/insights/testing/insightsModelTests.mjs +0 -714
  293. package/dist/plugins/insights/testing/modelTypes.d.mts +0 -176
  294. package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.d.mts +0 -11
  295. package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.mjs +0 -107
  296. package/dist/plugins/insights/testing/setupInsightsModelTestSuite.d.mts +0 -11
  297. package/dist/plugins/insights/testing/setupInsightsModelTestSuite.mjs +0 -31
  298. package/dist/plugins/insights/testing/types.d.mts +0 -26
  299. package/dist/plugins/insights/types.d.cts +0 -33
  300. package/dist/plugins/insights/types.d.mts +0 -33
  301. package/src/adapters/drizzle.conformance.integration.spec.ts +0 -34
  302. package/src/adapters/drizzle.readBudgets.integration.spec.ts +0 -43
  303. package/src/adapters/drizzle.spec.ts +0 -314
  304. package/src/adapters/drizzle.ts +0 -64
  305. package/src/adapters/drizzleExecutor.ts +0 -166
  306. package/src/adapters/kysely.conformance.integration.spec.ts +0 -36
  307. package/src/adapters/kysely.readBudgets.integration.spec.ts +0 -44
  308. package/src/adapters/kysely.spec.ts +0 -244
  309. package/src/adapters/kysely.ts +0 -46
  310. package/src/adapters/kyselyExecutor.ts +0 -53
  311. package/src/adapters/mongodb.integration.spec.ts +0 -271
  312. package/src/adapters/mongodb.readBudgets.integration.spec.ts +0 -61
  313. package/src/adapters/mongodb.ts +0 -45
  314. package/src/adapters/mongodbAdapter.ts +0 -307
  315. package/src/adapters/prisma.conformance.integration.spec.ts +0 -36
  316. package/src/adapters/prisma.integration.spec.ts +0 -146
  317. package/src/adapters/prisma.readBudgets.integration.spec.ts +0 -43
  318. package/src/adapters/prisma.spec.ts +0 -257
  319. package/src/adapters/prisma.ts +0 -74
  320. package/src/adapters/prismaExecutor.ts +0 -107
  321. package/src/adapters/prismaTestClients.ts +0 -182
  322. package/src/adapters/sqlProviders.ts +0 -14
  323. package/src/assembly/assemblePlugins.ts +0 -302
  324. package/src/assembly/assembly.spec.ts +0 -377
  325. package/src/assembly/assembly.types.spec.ts +0 -203
  326. package/src/assembly/clientPlugins.ts +0 -113
  327. package/src/assembly/configError.ts +0 -4
  328. package/src/assembly/databasePlugins.spec.ts +0 -71
  329. package/src/assembly/databasePlugins.ts +0 -102
  330. package/src/assembly/pluginCli.spec.ts +0 -254
  331. package/src/assembly/pluginCli.ts +0 -248
  332. package/src/assembly/pluginRoutes.spec.ts +0 -186
  333. package/src/core/api.ts +0 -139
  334. package/src/core/baseCandidates.spec.ts +0 -378
  335. package/src/core/baseCandidates.ts +0 -136
  336. package/src/core/index.ts +0 -44
  337. package/src/core/operations.spec.ts +0 -415
  338. package/src/core/operations.ts +0 -551
  339. package/src/core/reads.spec.ts +0 -300
  340. package/src/core/reads.ts +0 -417
  341. package/src/core/releases.spec.ts +0 -308
  342. package/src/core/releases.ts +0 -345
  343. package/src/core/schema.ts +0 -173
  344. package/src/core/writes.ts +0 -160
  345. package/src/createHotUpdaterCore.ts +0 -260
  346. package/src/database/aggregateBatching.spec.ts +0 -577
  347. package/src/database/aggregateBatching.ts +0 -803
  348. package/src/database/busy.spec.ts +0 -45
  349. package/src/database/busy.ts +0 -50
  350. package/src/database/cursor.ts +0 -65
  351. package/src/database/database.ts +0 -366
  352. package/src/database/database.types.spec.ts +0 -135
  353. package/src/database/definitions.ts +0 -76
  354. package/src/database/engine.ts +0 -62
  355. package/src/database/engineAggregates.spec.ts +0 -536
  356. package/src/database/engineAggregates.ts +0 -189
  357. package/src/database/engineReads.spec.ts +0 -219
  358. package/src/database/engineReads.ts +0 -304
  359. package/src/database/engineTransaction.spec.ts +0 -710
  360. package/src/database/engineTransaction.ts +0 -582
  361. package/src/database/errors.ts +0 -30
  362. package/src/database/fence.spec.ts +0 -223
  363. package/src/database/fence.ts +0 -175
  364. package/src/database/index.ts +0 -160
  365. package/src/database/kv/kvAdapter.batching.integration.spec.ts +0 -15
  366. package/src/database/kv/kvAdapter.conformance.integration.spec.ts +0 -19
  367. package/src/database/kv/kvAdapter.readBudgets.integration.spec.ts +0 -17
  368. package/src/database/kv/kvAdapter.spec.ts +0 -595
  369. package/src/database/kv/kvAdapter.ts +0 -479
  370. package/src/database/kv/kvTestStore.ts +0 -118
  371. package/src/database/memory.readBudgets.integration.spec.ts +0 -13
  372. package/src/database/resolveSchema.spec.ts +0 -230
  373. package/src/database/resolveSchema.ts +0 -375
  374. package/src/database/retention.spec.ts +0 -314
  375. package/src/database/retention.ts +0 -129
  376. package/src/database/schema.ts +0 -213
  377. package/src/database/schema.types.spec.ts +0 -94
  378. package/src/database/sql/docker-compose.yml +0 -36
  379. package/src/database/sql/sqlAdapter.integration.spec.ts +0 -145
  380. package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +0 -123
  381. package/src/database/sql/sqlAdapter.spec.ts +0 -343
  382. package/src/database/sql/sqlAdapter.ts +0 -552
  383. package/src/database/sql/sqlSchema.ts +0 -286
  384. package/src/database/sql/sqlTestExecutors.ts +0 -183
  385. package/src/databaseTestSuite.spec.ts +0 -44
  386. package/src/db/bundleRows.spec.ts +0 -164
  387. package/src/db/bundleRows.ts +0 -10
  388. package/src/db/coreDatabase.ts +0 -153
  389. package/src/db/createBundleDiff.spec.ts +0 -464
  390. package/src/db/createBundleDiff.ts +0 -370
  391. package/src/db/engineDrizzleSchema.ts +0 -72
  392. package/src/db/engineMigrator.ts +0 -105
  393. package/src/db/enginePrismaSchema.ts +0 -147
  394. package/src/db/engineSql.spec.ts +0 -130
  395. package/src/db/engineSql.ts +0 -48
  396. package/src/db/engineSqlMigrator.ts +0 -116
  397. package/src/db/fixedMigratorShared.ts +0 -17
  398. package/src/db/index.spec.ts +0 -554
  399. package/src/db/index.ts +0 -93
  400. package/src/db/node-sqlite.d.ts +0 -25
  401. package/src/db/pluginTables.spec.ts +0 -248
  402. package/src/db/releaseCatalog.ts +0 -106
  403. package/src/db/schemaSettings.ts +0 -104
  404. package/src/db/settingsMigrator.spec.ts +0 -65
  405. package/src/db/settingsMigrator.ts +0 -152
  406. package/src/db/types.ts +0 -82
  407. package/src/db/updateArtifacts.spec.ts +0 -235
  408. package/src/db/updateArtifacts.ts +0 -473
  409. package/src/db/updateCheck.bench.ts +0 -47
  410. package/src/diff.ts +0 -6
  411. package/src/handler-standalone.integration.spec.ts +0 -321
  412. package/src/handler.spec.ts +0 -273
  413. package/src/handler.testFixtures.ts +0 -25
  414. package/src/handler.ts +0 -302
  415. package/src/handlerAdminRoutes.spec.ts +0 -183
  416. package/src/handlerAdminRoutes.ts +0 -536
  417. package/src/handlerAuth.integration.spec.ts +0 -33
  418. package/src/handlerErrors.ts +0 -7
  419. package/src/handlerManagement.spec.ts +0 -202
  420. package/src/handlerParameters.ts +0 -105
  421. package/src/handlerReleaseCatalogRoutes.ts +0 -176
  422. package/src/handlerTypes.ts +0 -19
  423. package/src/handlerVersionRoutes.ts +0 -25
  424. package/src/index.ts +0 -13
  425. package/src/internalRouter.ts +0 -104
  426. package/src/lintRules.spec.ts +0 -76
  427. package/src/node.spec.ts +0 -119
  428. package/src/node.ts +0 -111
  429. package/src/plugins/api-keys/apiKeys.integration.spec.ts +0 -92
  430. package/src/plugins/api-keys/apiKeys.spec.ts +0 -166
  431. package/src/plugins/api-keys/apiKeys.ts +0 -214
  432. package/src/plugins/api-keys/apiKeysPlugin.spec.ts +0 -168
  433. package/src/plugins/api-keys/cli.spec.ts +0 -187
  434. package/src/plugins/api-keys/cli.ts +0 -140
  435. package/src/plugins/api-keys/index.ts +0 -73
  436. package/src/plugins/api-keys/model.ts +0 -88
  437. package/src/plugins/api-keys/schema.ts +0 -22
  438. package/src/plugins/definePlugin.ts +0 -242
  439. package/src/plugins/index.ts +0 -73
  440. package/src/plugins/insights/contract.spec.ts +0 -285
  441. package/src/plugins/insights/contract.ts +0 -372
  442. package/src/plugins/insights/domain.ts +0 -176
  443. package/src/plugins/insights/errors.ts +0 -11
  444. package/src/plugins/insights/eventInput.ts +0 -381
  445. package/src/plugins/insights/eventRow.ts +0 -209
  446. package/src/plugins/insights/index.ts +0 -222
  447. package/src/plugins/insights/insights.integration.spec.ts +0 -921
  448. package/src/plugins/insights/insightsRollout.integration.spec.ts +0 -186
  449. package/src/plugins/insights/model.spec.ts +0 -64
  450. package/src/plugins/insights/model.ts +0 -18
  451. package/src/plugins/insights/modelTypes.ts +0 -197
  452. package/src/plugins/insights/overview.spec.ts +0 -64
  453. package/src/plugins/insights/overview.ts +0 -214
  454. package/src/plugins/insights/provider.spec.ts +0 -585
  455. package/src/plugins/insights/provider.ts +0 -704
  456. package/src/plugins/insights/queryInput.ts +0 -142
  457. package/src/plugins/insights/reads.spec.ts +0 -1013
  458. package/src/plugins/insights/reads.ts +0 -1037
  459. package/src/plugins/insights/recordEvent.spec.ts +0 -897
  460. package/src/plugins/insights/recordEvent.ts +0 -476
  461. package/src/plugins/insights/retention.spec.ts +0 -115
  462. package/src/plugins/insights/routes.ts +0 -149
  463. package/src/plugins/insights/schema.ts +0 -409
  464. package/src/plugins/insights/testing/expectInsightsIndex.spec.ts +0 -42
  465. package/src/plugins/insights/testing/expectInsightsIndex.ts +0 -20
  466. package/src/plugins/insights/testing/fixtures.ts +0 -30
  467. package/src/plugins/insights/testing/index.ts +0 -45
  468. package/src/plugins/insights/testing/insightsModelTests.ts +0 -860
  469. package/src/plugins/insights/testing/setupInsightsHttpTestSuite.ts +0 -152
  470. package/src/plugins/insights/testing/setupInsightsModelTestSuite.ts +0 -36
  471. package/src/plugins/insights/testing/types.ts +0 -30
  472. package/src/plugins/insights/types.ts +0 -55
  473. package/src/plugins/pluginTestHarness.spec.ts +0 -56
  474. package/src/readBudgets.testFixtures.ts +0 -15
  475. package/src/releaseCatalogRoutes.integration.spec.ts +0 -200
  476. package/src/retention.spec.ts +0 -73
  477. package/src/runtime.spec.ts +0 -207
  478. package/src/runtime.testFixtures.ts +0 -60
  479. package/src/runtimeBundles.integration.spec.ts +0 -112
  480. package/src/storageAccess.spec.ts +0 -152
  481. package/src/storageAccess.ts +0 -141
  482. package/src/testUtilsMutation.integration.spec.ts +0 -216
  483. package/src/testUtilsPackage.integration.spec.ts +0 -180
  484. package/src/types/index.ts +0 -2
  485. package/src/version.ts +0 -3
@@ -1,897 +0,0 @@
1
- import { DatabaseSync } from "node:sqlite";
2
-
3
- import {
4
- countDistinct,
5
- createMemoryAdapter,
6
- type DatabaseAdapter,
7
- type WriteOp,
8
- } from "@hot-updater/plugin-core/internal";
9
- import { createPluginTestHarness } from "@hot-updater/test-utils";
10
- import { describe, expect, it } from "vitest";
11
-
12
- import * as engine from "../../database";
13
- import type { HotUpdaterDatabase } from "../../database/database";
14
- import { createKvAdapter } from "../../database/kv/kvAdapter";
15
- import { createMemoryKeyValueStore } from "../../database/kv/kvTestStore";
16
- import { createSqlAdapter } from "../../database/sql/sqlAdapter";
17
- import { sqliteExecutor } from "../../database/sql/sqlTestExecutors";
18
- import type { BundleEventRow } from "./eventRow";
19
- import {
20
- insights,
21
- insightsIdentity,
22
- type InsightsIdentityParts,
23
- type InsightsSchema,
24
- } from "./index";
25
- import { DAILY_EVENTS } from "./schema";
26
-
27
- const HOUR = 3_600_000;
28
- const DAY = 86_400_000;
29
- const T = Date.UTC(2026, 8, 23, 10, 15);
30
- const hour = (ms: number) => ms - (ms % HOUR);
31
- const day = (ms: number) => ms - (ms % DAY);
32
-
33
- const uuid = (n: number) =>
34
- `00000000-0000-7000-8000-${String(n).padStart(12, "0")}`;
35
-
36
- const event = (
37
- n: number,
38
- overrides: Partial<BundleEventRow> = {},
39
- ): BundleEventRow =>
40
- ({
41
- id: uuid(n),
42
- type: "UPDATE_APPLIED",
43
- install_id: "install-1",
44
- user_id: "user-1",
45
- from_release_id: "release-1",
46
- from_bundle_id: "bundle-1",
47
- to_release_id: "release-2",
48
- to_bundle_id: "bundle-2",
49
- platform: "ios",
50
- app_version: "1.0.0",
51
- channel: "production",
52
- metadata: {
53
- cohort: "1",
54
- update_strategy: "appVersion",
55
- fingerprint_hash: null,
56
- sdk_version: null,
57
- },
58
- received_at_ms: T,
59
- ...overrides,
60
- }) as BundleEventRow;
61
-
62
- const unchanged = (
63
- n: number,
64
- overrides: Partial<BundleEventRow> = {},
65
- ): BundleEventRow =>
66
- event(n, {
67
- type: "UNCHANGED",
68
- from_release_id: null,
69
- from_bundle_id: null,
70
- metadata: { ...event(n).metadata, update_strategy: null },
71
- ...overrides,
72
- } as Partial<BundleEventRow>);
73
-
74
- /** An update failure from install-2, which runs bundle-2 and targets bundle-3. */
75
- const failure = (
76
- n: number,
77
- failed: Record<string, unknown>,
78
- overrides: Partial<BundleEventRow> = {},
79
- ): BundleEventRow =>
80
- event(n, {
81
- type: "UPDATE_FAILED",
82
- install_id: "install-2",
83
- from_release_id: "release-2",
84
- from_bundle_id: "bundle-2",
85
- to_release_id: "release-3",
86
- to_bundle_id: "bundle-3",
87
- metadata: { ...event(n).metadata, failure: failed },
88
- ...overrides,
89
- } as Partial<BundleEventRow>);
90
-
91
- const backends: [string, () => DatabaseAdapter][] = [
92
- ["memory", () => createMemoryAdapter()],
93
- [
94
- "SQLite",
95
- () =>
96
- createSqlAdapter({
97
- executor: sqliteExecutor(new DatabaseSync(":memory:")),
98
- }),
99
- ],
100
- [
101
- "the key-value helper",
102
- () => createKvAdapter({ store: createMemoryKeyValueStore() }),
103
- ],
104
- ];
105
-
106
- const identity = (
107
- parts: Partial<InsightsIdentityParts> &
108
- Pick<InsightsIdentityParts, "periodKind">,
109
- ) =>
110
- insightsIdentity({
111
- scopeKind: "channel",
112
- releaseKind: "all",
113
- releaseId: "",
114
- channel: "production",
115
- platform: "ios",
116
- appVersionKind: "all",
117
- appVersion: "",
118
- ...parts,
119
- });
120
-
121
- describe.each(backends)("insights recordEvent on %s", (_name, adapter) => {
122
- const setup = async (wrap = (inner: DatabaseAdapter) => inner) => {
123
- const harness = await createPluginTestHarness(insights(), {
124
- engine,
125
- adapter: wrap(adapter()),
126
- });
127
- const db = harness.db as HotUpdaterDatabase<InsightsSchema>;
128
- const at = (key: string, bucket: number) => ({
129
- index: "window" as const,
130
- where: { identity: key },
131
- range: { gte: bucket, lte: bucket },
132
- limit: 100,
133
- });
134
- /** Each period's rows live in an aggregate of their own, with its retention. */
135
- const counters = {
136
- hour: "insights_overview",
137
- day: "insights_overview_daily",
138
- lifetime: "insights_overview_lifetime",
139
- } as const;
140
- const sketches = {
141
- hour: "insights_sketches",
142
- day: "insights_sketches_daily",
143
- } as const;
144
- const overview = async (
145
- key: string,
146
- bucket: number,
147
- period: keyof typeof counters = "hour",
148
- ) => (await db.findAggregates(counters[period], at(key, bucket))).rows[0];
149
- const sketch = async (
150
- key: string,
151
- bucket: number,
152
- period: keyof typeof sketches = "hour",
153
- ) => (await db.findAggregates(sketches[period], at(key, bucket))).rows[0];
154
- const distribution = async () =>
155
- (
156
- await db.findAggregates("insights_distribution", {
157
- index: "byScope",
158
- where: { channel: "production", platform: "ios" },
159
- limit: 100,
160
- })
161
- ).rows;
162
- const byBundle = async (
163
- field: "from_bundle_id" | "to_bundle_id",
164
- bundleId: string,
165
- type: string,
166
- ) =>
167
- (
168
- await db.findAggregates("insights_latest_by_bundle", {
169
- index: "byBundle",
170
- where: {
171
- platform: "ios",
172
- channel: "production",
173
- bundle_field: field,
174
- bundle_id: bundleId,
175
- type,
176
- },
177
- limit: 100,
178
- })
179
- ).rows;
180
- const outcomes = async (type: string, ref: string) =>
181
- (
182
- await db.findAggregates("insights_outcomes", {
183
- index: "byRef",
184
- where: {
185
- platform: "ios",
186
- channel: "production",
187
- type,
188
- bundle_ref: ref,
189
- },
190
- limit: 100,
191
- })
192
- ).rows;
193
- /** The per-day count of every event, which the global event list reads. */
194
- const everyEvent = async () =>
195
- (
196
- await db.findAggregates("insights_outcomes", {
197
- index: "byRef",
198
- where: DAILY_EVENTS,
199
- limit: 100,
200
- })
201
- ).rows;
202
- /** Update failures and recovery exits by what failed, which the breakdown reads. */
203
- const failures = async () =>
204
- (
205
- await db.findAggregates("insights_failures", {
206
- index: "byScope",
207
- where: { platform: "ios", channel: "production" },
208
- limit: 100,
209
- })
210
- ).rows;
211
- const failedUsers = async (
212
- key: string,
213
- bucket: number,
214
- period: "hour" | "day" | "lifetime" = "hour",
215
- ) =>
216
- countDistinct(
217
- (
218
- await db.findAggregates(
219
- period === "lifetime"
220
- ? "insights_sketches_lifetime"
221
- : sketches[period],
222
- at(key, bucket),
223
- )
224
- ).rows[0]?.failed_users,
225
- );
226
- return {
227
- ...harness,
228
- db,
229
- overview,
230
- sketch,
231
- distribution,
232
- byBundle,
233
- outcomes,
234
- everyEvent,
235
- failures,
236
- failedUsers,
237
- };
238
- };
239
-
240
- it("records the event with derived keys, the head, gauges, counters, and sketches", async () => {
241
- const {
242
- api,
243
- db,
244
- overview,
245
- sketch,
246
- distribution,
247
- byBundle,
248
- outcomes,
249
- everyEvent,
250
- } = await setup();
251
- await api.recordEvent(event(1));
252
-
253
- await expect(
254
- db.findOne("bundle_events", { id: uuid(1) }),
255
- ).resolves.toMatchObject({
256
- day: T - (T % DAY),
257
- movement_install_id: "install-1",
258
- bundle_ref: ["to:bundle-2"],
259
- });
260
- await expect(
261
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
262
- ).resolves.toEqual(event(1));
263
- // Gauges count the head in the UTC day of its event.
264
- await expect(distribution()).resolves.toEqual([
265
- {
266
- channel: "production",
267
- platform: "ios",
268
- app_version: "1.0.0",
269
- release_id: "release-2",
270
- bucket_start_ms: day(T),
271
- latest_installations: 1,
272
- },
273
- ]);
274
- for (const [field, bundle] of [
275
- ["from_bundle_id", "bundle-1"],
276
- ["to_bundle_id", "bundle-2"],
277
- ] as const) {
278
- await expect(
279
- byBundle(field, bundle, "UPDATE_APPLIED"),
280
- ).resolves.toMatchObject([{ installations: 1 }]);
281
- }
282
- await expect(
283
- outcomes("UPDATE_APPLIED", "to:bundle-2"),
284
- ).resolves.toMatchObject([{ bucket_start_ms: hour(T), events: 1 }]);
285
- // Every event's row is a UTC day's, not an hour's.
286
- await expect(everyEvent()).resolves.toEqual([
287
- { ...DAILY_EVENTS, bucket_start_ms: T - (T % DAY), events: 1 },
288
- ]);
289
-
290
- const release = { scopeKind: "release", releaseKind: "specific" } as const;
291
- const counters = { downloads: 0, launches: 1, failed_launches: 0 };
292
- await expect(
293
- overview(
294
- identity({
295
- ...release,
296
- releaseId: "release-2",
297
- periodKind: "lifetime",
298
- }),
299
- 0,
300
- "lifetime",
301
- ),
302
- ).resolves.toMatchObject(counters);
303
- const releaseHour = await sketch(
304
- identity({ ...release, releaseId: "release-2", periodKind: "hour" }),
305
- hour(T),
306
- );
307
- expect(countDistinct(releaseHour!.launch_users)).toBe(1);
308
- for (const [periodKind, bucket] of [
309
- ["hour", hour(T)],
310
- ["day", T - (T % DAY)],
311
- ] as const) {
312
- await expect(
313
- overview(identity({ periodKind }), bucket, periodKind),
314
- ).resolves.toMatchObject(counters);
315
- // A channel's active installations come from its usage rows.
316
- await expect(
317
- sketch(identity({ periodKind }), bucket, periodKind),
318
- ).resolves.toBeUndefined();
319
- for (const appVersionKind of ["specific", "all"] as const) {
320
- const usage = await sketch(
321
- identity({
322
- scopeKind: "usage",
323
- appVersionKind,
324
- appVersion: appVersionKind === "specific" ? "1.0.0" : "",
325
- periodKind,
326
- }),
327
- bucket,
328
- periodKind,
329
- );
330
- expect(countDistinct(usage!.activity_users)).toBe(1);
331
- // Every platform's usage merges the platforms' rows on read.
332
- await expect(
333
- sketch(
334
- identity({
335
- scopeKind: "usage",
336
- platform: "all",
337
- appVersionKind,
338
- appVersion: appVersionKind === "specific" ? "1.0.0" : "",
339
- periodKind,
340
- }),
341
- bucket,
342
- periodKind,
343
- ),
344
- ).resolves.toBeUndefined();
345
- }
346
- }
347
- });
348
-
349
- it("keys an event by the one bundle its bundle filter reads", async () => {
350
- const { api, db } = await setup();
351
- await api.recordEvent(event(1));
352
- await api.recordEvent(
353
- event(2, { type: "RECOVERED", install_id: "install-2" }),
354
- );
355
-
356
- await expect(
357
- db.findOne("bundle_events", { id: uuid(2) }),
358
- ).resolves.toMatchObject({ bundle_ref: ["from:bundle-1"] });
359
- const scope = { platform: "ios", channel: "production" } as const;
360
- for (const [n, filter] of [
361
- [1, { ...scope, type: "UPDATE_APPLIED", toBundleId: "bundle-2" }],
362
- [2, { ...scope, type: "RECOVERED", fromBundleId: "bundle-1" }],
363
- ] as const) {
364
- await expect(
365
- api.listEvents({
366
- filter: { kind: "bundle", ...filter },
367
- sinceMs: T,
368
- beforeReceivedAtMs: T + HOUR,
369
- limit: 10,
370
- }),
371
- ).resolves.toMatchObject([{ id: uuid(n) }]);
372
- }
373
- });
374
-
375
- it("changes nothing for a repeated id, even with another payload", async () => {
376
- const { api, db, outcomes, everyEvent } = await setup();
377
- await api.recordEvent(event(1));
378
- await api.recordEvent(
379
- event(1, { install_id: "install-2", received_at_ms: T + HOUR }),
380
- );
381
-
382
- await expect(
383
- db.findOne("bundle_events", { id: uuid(1) }),
384
- ).resolves.toMatchObject({ install_id: "install-1" });
385
- await expect(
386
- db.findOne("bundle_event_heads", { install_id: "install-2" }),
387
- ).resolves.toBeNull();
388
- await expect(
389
- outcomes("UPDATE_APPLIED", "to:bundle-2"),
390
- ).resolves.toMatchObject([{ events: 1 }]);
391
- await expect(everyEvent()).resolves.toMatchObject([{ events: 1 }]);
392
- });
393
-
394
- it("moves the head only for a newer event and deletes gauge rows that reach zero", async () => {
395
- const { api, db, distribution, byBundle, outcomes } = await setup();
396
- await api.recordEvent(event(1));
397
- await api.recordEvent(
398
- event(2, {
399
- type: "UPDATE_DOWNLOADED",
400
- user_id: null,
401
- from_release_id: "release-2",
402
- from_bundle_id: "bundle-2",
403
- to_release_id: "release-3",
404
- to_bundle_id: "bundle-3",
405
- received_at_ms: T + 2 * HOUR,
406
- }),
407
- );
408
- await api.recordEvent(event(3, { received_at_ms: T + HOUR }));
409
-
410
- await expect(
411
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
412
- ).resolves.toMatchObject({
413
- id: uuid(2),
414
- user_id: null,
415
- type: "UPDATE_DOWNLOADED",
416
- });
417
- // A download leaves the installation on release-2, in the same UTC day.
418
- await expect(distribution()).resolves.toMatchObject([
419
- {
420
- release_id: "release-2",
421
- bucket_start_ms: day(T),
422
- latest_installations: 1,
423
- },
424
- ]);
425
- await expect(
426
- byBundle("to_bundle_id", "bundle-2", "UPDATE_APPLIED"),
427
- ).resolves.toEqual([]);
428
- await expect(
429
- byBundle("to_bundle_id", "bundle-3", "UPDATE_DOWNLOADED"),
430
- ).resolves.toMatchObject([{ installations: 1 }]);
431
- await expect(
432
- outcomes("UPDATE_APPLIED", "to:bundle-2"),
433
- ).resolves.toMatchObject([
434
- { bucket_start_ms: hour(T), events: 1 },
435
- { bucket_start_ms: hour(T + HOUR), events: 1 },
436
- ]);
437
-
438
- await api.recordEvent(event(4, { received_at_ms: T + 2 * HOUR }));
439
- await expect(
440
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
441
- ).resolves.toMatchObject({ id: uuid(4), type: "UPDATE_APPLIED" });
442
- await expect(distribution()).resolves.toMatchObject([
443
- {
444
- release_id: "release-2",
445
- bucket_start_ms: day(T),
446
- latest_installations: 1,
447
- },
448
- ]);
449
-
450
- // The next UTC day's event takes the head out of this day's rows.
451
- await api.recordEvent(event(5, { received_at_ms: T + DAY }));
452
- await expect(distribution()).resolves.toMatchObject([
453
- {
454
- release_id: "release-2",
455
- bucket_start_ms: day(T + DAY),
456
- latest_installations: 1,
457
- },
458
- ]);
459
- });
460
-
461
- it("records an UNCHANGED report as a launch that no event or outcome row keeps", async () => {
462
- const { api, db, overview, outcomes, everyEvent, byBundle } = await setup();
463
- await api.recordEvent(unchanged(1));
464
-
465
- await expect(db.findOne("bundle_events", { id: uuid(1) })).resolves.toBe(
466
- null,
467
- );
468
- await expect(
469
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
470
- ).resolves.toEqual(unchanged(1));
471
- await expect(outcomes("UNCHANGED", "to:bundle-2")).resolves.toEqual([]);
472
- await expect(everyEvent()).resolves.toEqual([]);
473
- await expect(
474
- overview(identity({ periodKind: "day" }), day(T), "day"),
475
- ).resolves.toMatchObject({ launches: 1 });
476
- await expect(
477
- byBundle("to_bundle_id", "bundle-2", "UNCHANGED"),
478
- ).resolves.toMatchObject([{ bucket_start_ms: day(T), installations: 1 }]);
479
- await expect(
480
- api.listEvents({
481
- filter: { kind: "all" },
482
- sinceMs: day(T),
483
- beforeReceivedAtMs: day(T) + DAY,
484
- limit: 10,
485
- }),
486
- ).resolves.toEqual([]);
487
- });
488
-
489
- it("writes nothing for an UNCHANGED report that repeats its head the same UTC day", async () => {
490
- const calls: string[] = [];
491
- const { api, db, overview } = await setup((inner) => ({
492
- ...inner,
493
- write: async (ops: readonly WriteOp[]) => {
494
- calls.push("write");
495
- return inner.write(ops);
496
- },
497
- }));
498
- await api.recordEvent(event(1));
499
- calls.length = 0;
500
- // Relaunches on the bundle the apply moved to, later that day.
501
- await api.recordEvent(unchanged(2, { received_at_ms: T + 5 * HOUR }));
502
- await api.recordEvent(unchanged(3, { received_at_ms: T + 6 * HOUR }));
503
- expect(calls).toEqual([]);
504
- await expect(
505
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
506
- ).resolves.toMatchObject({ id: uuid(1), type: "UPDATE_APPLIED" });
507
- await expect(
508
- overview(identity({ periodKind: "day" }), day(T), "day"),
509
- ).resolves.toMatchObject({ launches: 1 });
510
-
511
- // An UNCHANGED report keeps no event row, so a retry that lands the next
512
- // UTC day is known by the head's id.
513
- await api.recordEvent(unchanged(4, { received_at_ms: T + DAY }));
514
- calls.length = 0;
515
- await api.recordEvent(unchanged(4, { received_at_ms: T + 2 * DAY }));
516
- expect(calls).toEqual([]);
517
- await expect(
518
- overview(identity({ periodKind: "day" }), day(T + 2 * DAY), "day"),
519
- ).resolves.toBeUndefined();
520
- });
521
-
522
- it("records an UNCHANGED report again for a new UTC day, bundle, user, or a download's head", async () => {
523
- const { api, db, overview } = await setup();
524
- const head = () =>
525
- db.findOne("bundle_event_heads", { install_id: "install-1" });
526
- const launches = async (bucket: number) =>
527
- (await overview(identity({ periodKind: "day" }), bucket, "day"))
528
- ?.launches;
529
-
530
- await api.recordEvent(unchanged(1));
531
- await api.recordEvent(unchanged(2, { user_id: "user-2" }));
532
- await expect(head()).resolves.toMatchObject({ id: uuid(2) });
533
- await api.recordEvent(
534
- unchanged(3, { to_bundle_id: "bundle-3", to_release_id: "release-3" }),
535
- );
536
- await expect(head()).resolves.toMatchObject({ id: uuid(3) });
537
- await expect(launches(day(T))).resolves.toBe(3);
538
-
539
- // A download's head still runs the bundle it came from.
540
- await api.recordEvent(
541
- event(4, {
542
- type: "UPDATE_DOWNLOADED",
543
- from_release_id: "release-3",
544
- from_bundle_id: "bundle-3",
545
- to_release_id: "release-4",
546
- to_bundle_id: "bundle-4",
547
- received_at_ms: T + HOUR,
548
- }),
549
- );
550
- await api.recordEvent(
551
- unchanged(5, {
552
- to_bundle_id: "bundle-4",
553
- to_release_id: "release-4",
554
- received_at_ms: T + 2 * HOUR,
555
- }),
556
- );
557
- await expect(head()).resolves.toMatchObject({ id: uuid(5) });
558
-
559
- await api.recordEvent(
560
- unchanged(6, {
561
- to_bundle_id: "bundle-4",
562
- to_release_id: "release-4",
563
- received_at_ms: T + DAY,
564
- }),
565
- );
566
- await expect(head()).resolves.toMatchObject({ id: uuid(6) });
567
- await expect(launches(day(T + DAY))).resolves.toBe(1);
568
- });
569
-
570
- it("records an update failure for its target release and channel, and moves no head", async () => {
571
- const {
572
- api,
573
- db,
574
- overview,
575
- sketch,
576
- outcomes,
577
- everyEvent,
578
- failures,
579
- failedUsers,
580
- } = await setup();
581
- await api.recordEvent(event(1, { install_id: "install-2" }));
582
- const failed = {
583
- stage: "download",
584
- reason: "http",
585
- resource: "artifact",
586
- http_status: 403,
587
- origin_code: "AccessDenied",
588
- };
589
- await api.recordEvent(failure(2, failed));
590
-
591
- await expect(
592
- db.findOne("bundle_events", { id: uuid(2) }),
593
- ).resolves.toMatchObject({
594
- movement_install_id: "install-2",
595
- bundle_ref: ["to:bundle-3"],
596
- });
597
- await expect(
598
- db.findOne("bundle_event_heads", { install_id: "install-2" }),
599
- ).resolves.toMatchObject({ id: uuid(1), type: "UPDATE_APPLIED" });
600
- await expect(
601
- outcomes("UPDATE_FAILED", "to:bundle-3"),
602
- ).resolves.toMatchObject([{ bucket_start_ms: hour(T), events: 1 }]);
603
- await expect(everyEvent()).resolves.toMatchObject([{ events: 2 }]);
604
- await expect(
605
- api.listEvents({
606
- filter: { kind: "installationMovement", installId: "install-2" },
607
- beforeReceivedAtMs: T + HOUR,
608
- limit: 10,
609
- }),
610
- ).resolves.toMatchObject([{ id: uuid(2) }, { id: uuid(1) }]);
611
-
612
- const release = {
613
- scopeKind: "release",
614
- releaseKind: "specific",
615
- releaseId: "release-3",
616
- } as const;
617
- // Only the lifetime row counts the failure: windowed reads sum the
618
- // breakdown's hourly rows.
619
- await expect(
620
- overview(identity({ ...release, periodKind: "lifetime" }), 0, "lifetime"),
621
- ).resolves.toMatchObject({ failed_updates: 1, launches: 0 });
622
- await expect(
623
- overview(identity({ ...release, periodKind: "hour" }), hour(T)),
624
- ).resolves.toBeUndefined();
625
- for (const [periodKind, bucket] of [
626
- ["hour", hour(T)],
627
- ["lifetime", 0],
628
- ] as const) {
629
- await expect(
630
- failedUsers(
631
- identity({ ...release, scopeKind: "failure", periodKind }),
632
- bucket,
633
- periodKind,
634
- ),
635
- ).resolves.toBe(1);
636
- }
637
- for (const [periodKind, bucket] of [
638
- ["hour", hour(T)],
639
- ["day", day(T)],
640
- ] as const) {
641
- // A failure is no launch, and no counter: the channel's launch is the
642
- // apply's.
643
- await expect(
644
- overview(identity({ periodKind }), bucket, periodKind),
645
- ).resolves.toMatchObject({ failed_updates: 0, launches: 1 });
646
- await expect(
647
- failedUsers(
648
- identity({ scopeKind: "failure", periodKind }),
649
- bucket,
650
- periodKind,
651
- ),
652
- ).resolves.toBe(1);
653
- // Nor activity: install-2 counts once, from its apply.
654
- const usage = await sketch(
655
- identity({ scopeKind: "usage", periodKind }),
656
- bucket,
657
- periodKind,
658
- );
659
- expect(countDistinct(usage!.activity_users)).toBe(1);
660
- }
661
- await expect(failures()).resolves.toEqual([
662
- {
663
- platform: "ios",
664
- channel: "production",
665
- bucket_start_ms: hour(T),
666
- release_id: "release-3",
667
- stage: "download",
668
- reason: "http",
669
- detail: JSON.stringify(["artifact", 403, "AccessDenied", null]),
670
- events: 1,
671
- },
672
- ]);
673
- });
674
-
675
- it("counts a failed check for its channel only, and in no bundle list", async () => {
676
- const { api, db, overview, outcomes, everyEvent, failures, failedUsers } =
677
- await setup();
678
- await api.recordEvent(
679
- failure(
680
- 1,
681
- { stage: "check", reason: "invalid_response", resource: "catalog" },
682
- { to_release_id: null, to_bundle_id: "bundle-2" },
683
- ),
684
- );
685
-
686
- await expect(
687
- db.findOne("bundle_events", { id: uuid(1) }),
688
- ).resolves.toMatchObject({
689
- movement_install_id: "install-2",
690
- bundle_ref: [],
691
- });
692
- await expect(
693
- db.findOne("bundle_event_heads", { install_id: "install-2" }),
694
- ).resolves.toBeNull();
695
- await expect(outcomes("UPDATE_FAILED", "to:bundle-2")).resolves.toEqual([]);
696
- await expect(everyEvent()).resolves.toMatchObject([{ events: 1 }]);
697
- const scope = { platform: "ios", channel: "production" } as const;
698
- await expect(
699
- api.listEvents({
700
- filter: {
701
- kind: "bundle",
702
- ...scope,
703
- type: "UPDATE_FAILED",
704
- toBundleId: "bundle-2",
705
- },
706
- sinceMs: day(T),
707
- beforeReceivedAtMs: T + HOUR,
708
- limit: 10,
709
- }),
710
- ).resolves.toEqual([]);
711
- await expect(
712
- api.listEvents({
713
- filter: { kind: "all" },
714
- sinceMs: day(T),
715
- beforeReceivedAtMs: T + HOUR,
716
- limit: 10,
717
- }),
718
- ).resolves.toMatchObject([{ id: uuid(1) }]);
719
- for (const [periodKind, bucket] of [
720
- ["hour", hour(T)],
721
- ["day", day(T)],
722
- ] as const) {
723
- await expect(
724
- overview(identity({ periodKind }), bucket, periodKind),
725
- ).resolves.toBeUndefined();
726
- await expect(
727
- failedUsers(
728
- identity({ scopeKind: "check", periodKind }),
729
- bucket,
730
- periodKind,
731
- ),
732
- ).resolves.toBe(1);
733
- await expect(
734
- failedUsers(
735
- identity({ scopeKind: "failure", periodKind }),
736
- bucket,
737
- periodKind,
738
- ),
739
- ).resolves.toBe(0);
740
- }
741
- await expect(failures()).resolves.toMatchObject([
742
- {
743
- release_id: "",
744
- stage: "check",
745
- reason: "invalid_response",
746
- detail: JSON.stringify(["catalog", null, null, null]),
747
- events: 1,
748
- },
749
- ]);
750
- });
751
-
752
- it("counts a download a patch delivered, and one that fell back from a patch", async () => {
753
- const { api, overview } = await setup();
754
- const download = (n: number, metadata: Record<string, unknown>) =>
755
- event(n, {
756
- type: "UPDATE_DOWNLOADED",
757
- install_id: `install-${n}`,
758
- metadata: { ...event(n).metadata, ...metadata },
759
- } as Partial<BundleEventRow>);
760
- await api.recordEvent(download(1, { delivery: "patch" }));
761
- await api.recordEvent(
762
- download(2, { delivery: "archive", patch_fallback: true }),
763
- );
764
- await api.recordEvent(download(3, { delivery: "manifest" }));
765
-
766
- const counted = { downloads: 3, patch_downloads: 1, patch_fallbacks: 1 };
767
- const release = {
768
- scopeKind: "release",
769
- releaseKind: "specific",
770
- releaseId: "release-2",
771
- } as const;
772
- await expect(
773
- overview(identity({ ...release, periodKind: "hour" }), hour(T)),
774
- ).resolves.toMatchObject(counted);
775
- await expect(
776
- overview(identity({ ...release, periodKind: "lifetime" }), 0, "lifetime"),
777
- ).resolves.toMatchObject(counted);
778
- await expect(
779
- overview(identity({ periodKind: "day" }), day(T), "day"),
780
- ).resolves.toMatchObject(counted);
781
- });
782
-
783
- it("keeps a recovery's exit reason in the breakdown of the release that failed to launch", async () => {
784
- const { api, failures } = await setup();
785
- await api.recordEvent(
786
- event(1, {
787
- type: "RECOVERED",
788
- metadata: { ...event(1).metadata, previous_process_exit: "CRASH" },
789
- } as Partial<BundleEventRow>),
790
- );
791
- // A recovery without one, as on iOS, has no row.
792
- await api.recordEvent(
793
- event(2, { type: "RECOVERED", install_id: "install-2" }),
794
- );
795
-
796
- await expect(failures()).resolves.toEqual([
797
- {
798
- platform: "ios",
799
- channel: "production",
800
- bucket_start_ms: hour(T),
801
- release_id: "release-1",
802
- stage: "launch",
803
- reason: "CRASH",
804
- detail: "",
805
- events: 1,
806
- },
807
- ]);
808
- });
809
-
810
- it("reads the event and head in one round, gauge and sketch rows in a second, and writes once", async () => {
811
- const calls: string[] = [];
812
- const { api, measureReads } = await setup((inner) => ({
813
- ...inner,
814
- get: async (table, keys) => {
815
- calls.push(`get ${table.name}`);
816
- return inner.get(table, keys);
817
- },
818
- write: async (ops: readonly WriteOp[]) => {
819
- calls.push("write");
820
- return inner.write(ops);
821
- },
822
- }));
823
- const measured = await measureReads(() => api.recordEvent(event(1)));
824
-
825
- expect(measured.adapter.queries).toBe(0);
826
- expect(calls).toEqual([
827
- "get bundle_events",
828
- "get bundle_event_heads",
829
- "get insights_sketches",
830
- "get insights_sketches_daily",
831
- "get insights_distribution",
832
- "get insights_latest_by_bundle",
833
- "write",
834
- ]);
835
- });
836
-
837
- it("serializes events per installation and keeps gauges exact under concurrency", async () => {
838
- const { api, db, distribution } = await setup();
839
- const installs = ["a", "b", "c", "d"];
840
- const events = installs.flatMap((install, position) =>
841
- [0, 1, 2].map((step) =>
842
- event(position * 10 + step + 1, {
843
- install_id: `install-${install}`,
844
- received_at_ms: T + ((step * 7 + position) % 3) * HOUR,
845
- }),
846
- ),
847
- );
848
- await Promise.all(events.map((row) => api.recordEvent(row)));
849
-
850
- for (const install of installs) {
851
- const latest = events
852
- .filter((row) => row.install_id === `install-${install}`)
853
- .toSorted(
854
- (left, right) =>
855
- left.received_at_ms - right.received_at_ms ||
856
- (left.id < right.id ? -1 : 1),
857
- )
858
- .at(-1)!;
859
- await expect(
860
- db.findOne("bundle_event_heads", { install_id: `install-${install}` }),
861
- ).resolves.toMatchObject({ id: latest.id });
862
- }
863
- const counted = (await distribution()).reduce(
864
- (sum, row) => sum + row.latest_installations,
865
- 0,
866
- );
867
- expect(counted).toBe(installs.length);
868
- });
869
-
870
- it("records a retried report once, and a racing installation's report under its id not at all", async () => {
871
- const { api, db, outcomes } = await setup();
872
- await api.recordEvent(event(1));
873
- // A retry repeats the report's id, even when it arrives an hour later.
874
- await api.recordEvent(event(1, { received_at_ms: T + HOUR }));
875
- await expect(
876
- db.findOne("bundle_event_heads", { install_id: "install-1" }),
877
- ).resolves.toMatchObject({ id: uuid(1), received_at_ms: T });
878
- await expect(
879
- outcomes("UPDATE_APPLIED", "to:bundle-2"),
880
- ).resolves.toMatchObject([{ events: 1 }]);
881
-
882
- // The later writer reads the winner's row, at once or in the rerun after
883
- // its own insert fails, and changes nothing.
884
- const installs = ["install-2", "install-3"];
885
- await Promise.all(
886
- installs.map((install) =>
887
- api.recordEvent(event(2, { install_id: install })),
888
- ),
889
- );
890
- const stored = await db.findOne("bundle_events", { id: uuid(2) });
891
- const loser = installs.find((install) => install !== stored?.install_id);
892
- expect(installs).toContain(stored?.install_id);
893
- await expect(
894
- db.findOne("bundle_event_heads", { install_id: loser! }),
895
- ).resolves.toBeNull();
896
- });
897
- });