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

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 (309) hide show
  1. package/dist/adapters/drizzle.cjs +5 -5
  2. package/dist/adapters/drizzle.mjs +4 -4
  3. package/dist/adapters/kysely.cjs +3 -3
  4. package/dist/adapters/kysely.mjs +2 -2
  5. package/dist/adapters/mongodb.cjs +3 -3
  6. package/dist/adapters/mongodb.mjs +2 -2
  7. package/dist/adapters/mongodbAdapter.cjs +19 -1
  8. package/dist/adapters/mongodbAdapter.mjs +19 -1
  9. package/dist/adapters/prisma.cjs +5 -5
  10. package/dist/adapters/prisma.mjs +4 -4
  11. package/dist/assembly/assemblePlugins.cjs +47 -28
  12. package/dist/assembly/assemblePlugins.d.cts +3 -7
  13. package/dist/assembly/assemblePlugins.d.mts +3 -7
  14. package/dist/assembly/assemblePlugins.mjs +46 -27
  15. package/dist/assembly/clientPlugins.cjs +86 -0
  16. package/dist/assembly/clientPlugins.d.cts +16 -0
  17. package/dist/assembly/clientPlugins.d.mts +16 -0
  18. package/dist/assembly/clientPlugins.mjs +86 -0
  19. package/dist/assembly/configError.cjs +7 -0
  20. package/dist/assembly/configError.d.cts +7 -0
  21. package/dist/assembly/configError.d.mts +7 -0
  22. package/dist/assembly/configError.mjs +7 -0
  23. package/dist/assembly/databasePlugins.cjs +5 -1
  24. package/dist/assembly/databasePlugins.d.cts +5 -5
  25. package/dist/assembly/databasePlugins.d.mts +5 -5
  26. package/dist/assembly/databasePlugins.mjs +5 -1
  27. package/dist/assembly/pluginCli.cjs +125 -0
  28. package/dist/assembly/pluginCli.d.cts +59 -0
  29. package/dist/assembly/pluginCli.d.mts +59 -0
  30. package/dist/assembly/pluginCli.mjs +121 -0
  31. package/dist/createHotUpdaterCore.cjs +14 -16
  32. package/dist/createHotUpdaterCore.d.cts +10 -3
  33. package/dist/createHotUpdaterCore.d.mts +10 -3
  34. package/dist/createHotUpdaterCore.mjs +11 -13
  35. package/dist/database/aggregateBatching.cjs +626 -0
  36. package/dist/database/aggregateBatching.d.cts +10 -0
  37. package/dist/database/aggregateBatching.d.mts +10 -0
  38. package/dist/database/aggregateBatching.mjs +625 -0
  39. package/dist/{insights/errors.cjs → database/busy.cjs} +2 -15
  40. package/dist/database/busy.d.cts +12 -0
  41. package/dist/database/busy.d.mts +12 -0
  42. package/dist/{insights/errors.mjs → database/busy.mjs} +3 -14
  43. package/dist/database/database.cjs +22 -3
  44. package/dist/database/database.d.cts +15 -2
  45. package/dist/database/database.d.mts +15 -2
  46. package/dist/database/database.mjs +22 -3
  47. package/dist/database/definitions.d.cts +10 -0
  48. package/dist/database/definitions.d.mts +10 -0
  49. package/dist/database/engine.d.cts +2 -1
  50. package/dist/database/engine.d.mts +2 -1
  51. package/dist/database/engineAggregates.cjs +7 -4
  52. package/dist/database/engineAggregates.mjs +8 -5
  53. package/dist/database/engineReads.cjs +5 -3
  54. package/dist/database/engineReads.mjs +6 -4
  55. package/dist/database/engineTransaction.cjs +2 -6
  56. package/dist/database/engineTransaction.mjs +2 -6
  57. package/dist/database/fence.cjs +2 -1
  58. package/dist/database/fence.mjs +2 -1
  59. package/dist/database/index.cjs +17 -8
  60. package/dist/database/index.d.cts +5 -4
  61. package/dist/database/index.d.mts +5 -4
  62. package/dist/database/index.mjs +6 -5
  63. package/dist/database/kv/kvAdapter.cjs +15 -3
  64. package/dist/database/kv/kvAdapter.d.cts +8 -0
  65. package/dist/database/kv/kvAdapter.d.mts +8 -0
  66. package/dist/database/kv/kvAdapter.mjs +16 -4
  67. package/dist/database/resolveSchema.cjs +4 -1
  68. package/dist/database/resolveSchema.d.cts +1 -1
  69. package/dist/database/resolveSchema.d.mts +1 -1
  70. package/dist/database/resolveSchema.mjs +4 -1
  71. package/dist/database/retention.cjs +92 -0
  72. package/dist/database/retention.mjs +90 -0
  73. package/dist/database/schema.cjs +5 -2
  74. package/dist/database/schema.d.cts +30 -1
  75. package/dist/database/schema.d.mts +30 -1
  76. package/dist/database/schema.mjs +5 -2
  77. package/dist/database/sql/sqlAdapter.cjs +8 -0
  78. package/dist/database/sql/sqlAdapter.mjs +9 -1
  79. package/dist/database/sql/sqlSchema.cjs +56 -0
  80. package/dist/database/sql/sqlSchema.mjs +55 -1
  81. package/dist/db/coreDatabase.cjs +85 -0
  82. package/dist/db/coreDatabase.d.cts +57 -0
  83. package/dist/db/coreDatabase.d.mts +57 -0
  84. package/dist/db/coreDatabase.mjs +78 -0
  85. package/dist/db/index.cjs +11 -3
  86. package/dist/db/index.d.cts +7 -3
  87. package/dist/db/index.d.mts +7 -3
  88. package/dist/db/index.mjs +6 -3
  89. package/dist/db/types.d.cts +3 -3
  90. package/dist/db/types.d.mts +3 -3
  91. package/dist/diff.cjs +3 -0
  92. package/dist/diff.d.cts +2 -0
  93. package/dist/diff.d.mts +2 -0
  94. package/dist/diff.mjs +2 -0
  95. package/dist/handler.cjs +2 -14
  96. package/dist/handler.mjs +1 -13
  97. package/dist/handlerReleaseCatalogRoutes.cjs +21 -2
  98. package/dist/handlerReleaseCatalogRoutes.mjs +21 -2
  99. package/dist/index.cjs +2 -6
  100. package/dist/index.d.cts +4 -7
  101. package/dist/index.d.mts +4 -7
  102. package/dist/index.mjs +2 -4
  103. package/dist/package.cjs +1 -1
  104. package/dist/package.mjs +1 -1
  105. package/dist/{apiKeys.cjs → plugins/api-keys/apiKeys.cjs} +1 -1
  106. package/dist/{apiKeys.d.cts → plugins/api-keys/apiKeys.d.cts} +2 -2
  107. package/dist/{apiKeys.d.mts → plugins/api-keys/apiKeys.d.mts} +2 -2
  108. package/dist/{apiKeys.mjs → plugins/api-keys/apiKeys.mjs} +1 -1
  109. package/dist/plugins/api-keys/cli.cjs +115 -0
  110. package/dist/plugins/api-keys/cli.mjs +114 -0
  111. package/dist/plugins/api-keys/index.cjs +9 -6
  112. package/dist/plugins/api-keys/index.d.cts +4 -5
  113. package/dist/plugins/api-keys/index.d.mts +4 -5
  114. package/dist/plugins/api-keys/index.mjs +9 -7
  115. package/dist/plugins/api-keys/model.d.cts +20 -2
  116. package/dist/plugins/api-keys/model.d.mts +20 -2
  117. package/dist/plugins/definePlugin.cjs +1 -1
  118. package/dist/plugins/definePlugin.d.cts +130 -3
  119. package/dist/plugins/definePlugin.d.mts +130 -3
  120. package/dist/plugins/definePlugin.mjs +1 -1
  121. package/dist/plugins/index.cjs +25 -4
  122. package/dist/plugins/index.d.cts +7 -4
  123. package/dist/plugins/index.d.mts +7 -4
  124. package/dist/plugins/index.mjs +6 -4
  125. package/dist/plugins/insights/contract.cjs +193 -0
  126. package/dist/plugins/insights/contract.mjs +189 -0
  127. package/dist/{insights → plugins/insights}/domain.d.cts +60 -15
  128. package/dist/{insights → plugins/insights}/domain.d.mts +60 -15
  129. package/dist/plugins/insights/errors.cjs +15 -0
  130. package/dist/plugins/insights/errors.mjs +14 -0
  131. package/dist/{insights → plugins/insights}/eventInput.cjs +155 -22
  132. package/dist/{insights → plugins/insights}/eventInput.mjs +155 -22
  133. package/dist/plugins/insights/eventRow.cjs +49 -0
  134. package/dist/plugins/insights/eventRow.d.cts +64 -0
  135. package/dist/plugins/insights/eventRow.d.mts +64 -0
  136. package/dist/plugins/insights/eventRow.mjs +47 -0
  137. package/dist/plugins/insights/index.cjs +106 -26
  138. package/dist/plugins/insights/index.d.cts +130 -27
  139. package/dist/plugins/insights/index.d.mts +130 -27
  140. package/dist/plugins/insights/index.mjs +106 -29
  141. package/dist/plugins/insights/model.cjs +2 -2
  142. package/dist/plugins/insights/model.d.cts +1 -1
  143. package/dist/plugins/insights/model.d.mts +1 -1
  144. package/dist/plugins/insights/model.mjs +1 -1
  145. package/dist/plugins/insights/modelTypes.d.cts +176 -0
  146. package/dist/plugins/insights/modelTypes.d.mts +176 -0
  147. package/dist/plugins/insights/overview.cjs +109 -0
  148. package/dist/plugins/insights/overview.d.cts +15 -0
  149. package/dist/plugins/insights/overview.d.mts +15 -0
  150. package/dist/plugins/insights/overview.mjs +107 -0
  151. package/dist/{insights → plugins/insights}/provider.cjs +33 -14
  152. package/dist/{insights → plugins/insights}/provider.d.cts +2 -2
  153. package/dist/{insights → plugins/insights}/provider.d.mts +2 -2
  154. package/dist/{insights → plugins/insights}/provider.mjs +30 -11
  155. package/dist/{insights → plugins/insights}/queryInput.cjs +2 -2
  156. package/dist/{insights → plugins/insights}/queryInput.mjs +2 -2
  157. package/dist/plugins/insights/reads.cjs +298 -88
  158. package/dist/plugins/insights/reads.d.cts +61 -0
  159. package/dist/plugins/insights/reads.d.mts +61 -0
  160. package/dist/plugins/insights/reads.mjs +298 -90
  161. package/dist/plugins/insights/recordEvent.cjs +223 -39
  162. package/dist/plugins/insights/recordEvent.d.cts +9 -4
  163. package/dist/plugins/insights/recordEvent.d.mts +9 -4
  164. package/dist/plugins/insights/recordEvent.mjs +221 -37
  165. package/dist/{insights → plugins/insights}/routes.cjs +3 -30
  166. package/dist/{insights → plugins/insights}/routes.mjs +4 -28
  167. package/dist/plugins/insights/schema.cjs +182 -40
  168. package/dist/plugins/insights/schema.d.cts +446 -6
  169. package/dist/plugins/insights/schema.d.mts +446 -6
  170. package/dist/plugins/insights/schema.mjs +180 -41
  171. package/dist/plugins/insights/testing/eventRow.d.mts +64 -0
  172. package/dist/plugins/insights/testing/expectInsightsIndex.mjs +18 -0
  173. package/dist/plugins/insights/testing/fixtures.d.mts +8 -0
  174. package/dist/plugins/insights/testing/fixtures.mjs +25 -0
  175. package/dist/plugins/insights/testing/index.d.mts +24 -0
  176. package/dist/plugins/insights/testing/index.mjs +25 -0
  177. package/dist/plugins/insights/testing/insightsModelTests.mjs +714 -0
  178. package/dist/plugins/insights/testing/modelTypes.d.mts +176 -0
  179. package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.d.mts +11 -0
  180. package/dist/plugins/insights/testing/setupInsightsHttpTestSuite.mjs +107 -0
  181. package/dist/plugins/insights/testing/setupInsightsModelTestSuite.d.mts +11 -0
  182. package/dist/plugins/insights/testing/setupInsightsModelTestSuite.mjs +31 -0
  183. package/dist/plugins/insights/testing/types.d.mts +26 -0
  184. package/dist/{insights → plugins/insights}/types.d.cts +3 -2
  185. package/dist/{insights → plugins/insights}/types.d.mts +3 -2
  186. package/package.json +18 -7
  187. package/src/adapters/drizzle.conformance.integration.spec.ts +2 -2
  188. package/src/adapters/drizzle.readBudgets.integration.spec.ts +6 -4
  189. package/src/adapters/drizzle.spec.ts +15 -7
  190. package/src/adapters/drizzle.ts +6 -6
  191. package/src/adapters/kysely.conformance.integration.spec.ts +2 -2
  192. package/src/adapters/kysely.readBudgets.integration.spec.ts +4 -2
  193. package/src/adapters/kysely.spec.ts +13 -9
  194. package/src/adapters/kysely.ts +2 -2
  195. package/src/adapters/mongodb.integration.spec.ts +98 -7
  196. package/src/adapters/mongodb.ts +2 -2
  197. package/src/adapters/mongodbAdapter.ts +14 -0
  198. package/src/adapters/prisma.conformance.integration.spec.ts +2 -2
  199. package/src/adapters/prisma.integration.spec.ts +16 -8
  200. package/src/adapters/prisma.readBudgets.integration.spec.ts +5 -2
  201. package/src/adapters/prisma.spec.ts +17 -9
  202. package/src/adapters/prisma.ts +6 -6
  203. package/src/adapters/prismaTestClients.ts +8 -1
  204. package/src/assembly/assemblePlugins.ts +73 -40
  205. package/src/assembly/assembly.spec.ts +63 -11
  206. package/src/assembly/assembly.types.spec.ts +50 -2
  207. package/src/assembly/clientPlugins.ts +113 -0
  208. package/src/assembly/configError.ts +4 -0
  209. package/src/assembly/databasePlugins.ts +11 -5
  210. package/src/assembly/pluginCli.spec.ts +254 -0
  211. package/src/assembly/pluginCli.ts +248 -0
  212. package/src/assembly/{builtInRoutes.spec.ts → pluginRoutes.spec.ts} +10 -37
  213. package/src/createHotUpdaterCore.ts +21 -17
  214. package/src/database/aggregateBatching.spec.ts +577 -0
  215. package/src/database/aggregateBatching.ts +803 -0
  216. package/src/{insights/errors.spec.ts → database/busy.spec.ts} +2 -5
  217. package/src/{insights/errors.ts → database/busy.ts} +1 -13
  218. package/src/database/database.ts +39 -8
  219. package/src/database/definitions.ts +4 -0
  220. package/src/database/engineAggregates.spec.ts +4 -7
  221. package/src/database/engineAggregates.ts +5 -9
  222. package/src/database/engineReads.ts +7 -5
  223. package/src/database/engineTransaction.ts +1 -7
  224. package/src/database/fence.spec.ts +5 -5
  225. package/src/database/fence.ts +4 -0
  226. package/src/database/index.ts +13 -7
  227. package/src/database/kv/kvAdapter.batching.integration.spec.ts +15 -0
  228. package/src/database/kv/kvAdapter.conformance.integration.spec.ts +2 -0
  229. package/src/database/kv/kvAdapter.spec.ts +128 -1
  230. package/src/database/kv/kvAdapter.ts +30 -1
  231. package/src/database/kv/kvTestStore.ts +28 -1
  232. package/src/database/resolveSchema.ts +4 -1
  233. package/src/database/retention.spec.ts +314 -0
  234. package/src/database/retention.ts +129 -0
  235. package/src/database/schema.ts +44 -0
  236. package/src/database/sql/sqlAdapter.integration.spec.ts +4 -7
  237. package/src/database/sql/sqlAdapter.readBudgets.integration.spec.ts +18 -4
  238. package/src/database/sql/sqlAdapter.spec.ts +91 -3
  239. package/src/database/sql/sqlAdapter.ts +20 -0
  240. package/src/database/sql/sqlSchema.ts +81 -0
  241. package/src/databaseTestSuite.spec.ts +9 -4
  242. package/src/db/coreDatabase.ts +153 -0
  243. package/src/db/engineSql.spec.ts +8 -7
  244. package/src/db/index.ts +19 -2
  245. package/src/db/pluginTables.spec.ts +57 -27
  246. package/src/db/types.ts +3 -3
  247. package/src/diff.ts +6 -0
  248. package/src/handler-standalone.integration.spec.ts +2 -3
  249. package/src/handler.ts +1 -32
  250. package/src/handlerReleaseCatalogRoutes.ts +26 -2
  251. package/src/index.ts +0 -10
  252. package/src/{apiKeys.integration.spec.ts → plugins/api-keys/apiKeys.integration.spec.ts} +4 -4
  253. package/src/{apiKeys.spec.ts → plugins/api-keys/apiKeys.spec.ts} +3 -3
  254. package/src/{apiKeys.ts → plugins/api-keys/apiKeys.ts} +1 -1
  255. package/src/plugins/api-keys/apiKeysPlugin.spec.ts +11 -15
  256. package/src/plugins/api-keys/cli.spec.ts +187 -0
  257. package/src/plugins/api-keys/cli.ts +140 -0
  258. package/src/plugins/api-keys/index.ts +48 -41
  259. package/src/plugins/api-keys/model.ts +21 -2
  260. package/src/plugins/definePlugin.ts +144 -2
  261. package/src/plugins/index.ts +20 -2
  262. package/src/plugins/insights/contract.spec.ts +285 -0
  263. package/src/plugins/insights/contract.ts +372 -0
  264. package/src/{insights → plugins/insights}/domain.ts +73 -15
  265. package/src/plugins/insights/errors.ts +11 -0
  266. package/src/{insights → plugins/insights}/eventInput.ts +189 -29
  267. package/src/plugins/insights/eventRow.ts +209 -0
  268. package/src/plugins/insights/index.ts +181 -45
  269. package/src/{insights → plugins/insights}/insights.integration.spec.ts +330 -34
  270. package/src/plugins/insights/insightsRollout.integration.spec.ts +1 -2
  271. package/src/plugins/insights/model.spec.ts +3 -5
  272. package/src/plugins/insights/model.ts +2 -3
  273. package/src/plugins/insights/modelTypes.ts +197 -0
  274. package/src/plugins/insights/overview.spec.ts +64 -0
  275. package/src/plugins/insights/overview.ts +214 -0
  276. package/src/{insights → plugins/insights}/provider.spec.ts +21 -10
  277. package/src/{insights → plugins/insights}/provider.ts +58 -21
  278. package/src/{insights → plugins/insights}/queryInput.ts +2 -2
  279. package/src/plugins/insights/reads.spec.ts +340 -52
  280. package/src/plugins/insights/reads.ts +453 -123
  281. package/src/plugins/insights/recordEvent.spec.ts +474 -20
  282. package/src/plugins/insights/recordEvent.ts +301 -63
  283. package/src/plugins/insights/retention.spec.ts +115 -0
  284. package/src/{insights → plugins/insights}/routes.ts +1 -31
  285. package/src/plugins/insights/schema.ts +356 -176
  286. package/src/plugins/insights/testing/expectInsightsIndex.spec.ts +42 -0
  287. package/src/plugins/insights/testing/expectInsightsIndex.ts +20 -0
  288. package/src/plugins/insights/testing/fixtures.ts +30 -0
  289. package/src/plugins/insights/testing/index.ts +45 -0
  290. package/src/plugins/insights/testing/insightsModelTests.ts +860 -0
  291. package/src/plugins/insights/testing/setupInsightsHttpTestSuite.ts +152 -0
  292. package/src/plugins/insights/testing/setupInsightsModelTestSuite.ts +36 -0
  293. package/src/plugins/insights/testing/types.ts +30 -0
  294. package/src/{insights → plugins/insights}/types.ts +1 -1
  295. package/src/readBudgets.testFixtures.ts +2 -2
  296. package/src/releaseCatalogRoutes.integration.spec.ts +7 -0
  297. package/src/retention.spec.ts +73 -0
  298. package/src/runtime.spec.ts +11 -12
  299. package/src/runtime.testFixtures.ts +7 -2
  300. package/src/testUtilsMutation.integration.spec.ts +2 -1
  301. package/src/testUtilsPackage.integration.spec.ts +7 -3
  302. package/dist/db/builtInDatabase.cjs +0 -104
  303. package/dist/db/builtInDatabase.d.cts +0 -38
  304. package/dist/db/builtInDatabase.d.mts +0 -38
  305. package/dist/db/builtInDatabase.mjs +0 -97
  306. package/dist/plugins/builtIn.cjs +0 -7
  307. package/dist/plugins/builtIn.mjs +0 -6
  308. package/src/db/builtInDatabase.ts +0 -149
  309. package/src/plugins/builtIn.ts +0 -5
@@ -9,7 +9,7 @@ import {
9
9
  HotUpdaterConfigError,
10
10
  } from "./assembly/assemblePlugins";
11
11
  import type { CoreApi } from "./core/api";
12
- import { toolingTargetOf } from "./db/builtInDatabase";
12
+ import { toolingTargetOf } from "./db/coreDatabase";
13
13
  import type { ToolingDatabase, ToolingTarget } from "./db/types";
14
14
  import {
15
15
  type ClientRoutePolicy,
@@ -30,12 +30,19 @@ export type RuntimeHotUpdaterAPI<
30
30
  readonly api: PluginApis<TPlugins>;
31
31
  /** The database's name, which `hot-updater db` commands read. */
32
32
  readonly adapterName: string;
33
+ /**
34
+ * Applies aggregate changes the database batches that are still pending:
35
+ * this process's buffer, and the log rows no compaction has merged yet.
36
+ * A long-lived server with `aggregateBatching: { mode: "memory" }` calls
37
+ * it before it exits.
38
+ */
39
+ readonly flush: () => Promise<void>;
33
40
  };
34
41
 
35
42
  export type HotUpdaterAPI = RuntimeHotUpdaterAPI;
36
43
 
37
44
  const REMOVED_CLIENT_ACCESS =
38
- 'clientAccess objects were removed in 1.0: set clientAccess: "public", or add apiKeys() from @hot-updater/server/plugins/api-keys to plugins';
45
+ 'clientAccess objects were removed in 1.0: set clientAccess: "public", or add a plugin that provides clientAuth';
39
46
 
40
47
  /**
41
48
  * A `clientAccess` object from before 1.0. Its `type` names the fix, so
@@ -113,7 +120,7 @@ export type CreateHotUpdaterOptions<
113
120
  readonly database: ToolingDatabase;
114
121
  /** Storage implementations used to read provider-specific storage URIs. */
115
122
  readonly storage?: readonly StoragePlugin[];
116
- /** Built-in and third-party plugins; at most one provides clientAuth. Defaults to none. */
123
+ /** The plugins the server runs; at most one provides clientAuth. Defaults to none. */
117
124
  readonly plugins?: TPlugins;
118
125
  } & ClientAccessRule<TPlugins>;
119
126
 
@@ -141,24 +148,14 @@ const databaseOf = (value: unknown): ToolingDatabase => {
141
148
  );
142
149
  };
143
150
 
144
- /** A release candidate's config moving to 1.0 also needs `insights()`. */
145
- const KEEP_INSIGHTS =
146
- "To keep Insights, which the release candidates ran by default, add insights() from @hot-updater/server/plugins/insights to plugins.";
147
-
148
- /** `"public"`, or nothing; a `clientAccess` object names what replaced it. */
151
+ /** `"public"`, or nothing; a `clientAccess` object says what replaced it. */
149
152
  const isPublic = (value: unknown): boolean => {
150
153
  if (value === undefined) return false;
151
154
  if (value === "public") return true;
152
- if (isRecord(value)) {
153
- const type = value.type;
154
- throw new HotUpdaterConfigError(
155
- type === "api-key"
156
- ? `clientAccess: { type: "api-key" } was removed in 1.0. Remove it and add apiKeys(${value.headerName === undefined ? "" : `{ headerName: ${JSON.stringify(value.headerName)} }`}) from @hot-updater/server/plugins/api-keys to plugins, which protects client routes the same way. ${KEEP_INSIGHTS}`
157
- : `clientAccess objects were removed in 1.0. Use clientAccess: "public", or add apiKeys() from @hot-updater/server/plugins/api-keys to plugins. ${KEEP_INSIGHTS}`,
158
- );
159
- }
160
155
  throw new HotUpdaterConfigError(
161
- 'clientAccess must be "public"; to protect client routes, add apiKeys() from @hot-updater/server/plugins/api-keys to plugins.',
156
+ isRecord(value)
157
+ ? 'clientAccess objects were removed in 1.0. Set clientAccess: "public", or add a plugin that provides clientAuth to plugins.'
158
+ : 'clientAccess must be "public"; to protect client routes, add a plugin that provides clientAuth to plugins.',
162
159
  );
163
160
  };
164
161
 
@@ -171,6 +168,8 @@ export type HotUpdaterCoreMetadata = {
171
168
  readonly database: ToolingDatabase;
172
169
  /** The tables and settings rows that tooling creates for this server's plugins. */
173
170
  readonly target: ToolingTarget;
171
+ /** The plugins as configured, whose commands the CLI adds. */
172
+ readonly plugins: readonly AnyHotUpdaterPlugin[];
174
173
  };
175
174
 
176
175
  export function getHotUpdaterCoreMetadata(
@@ -210,6 +209,9 @@ export function createHotUpdater<
210
209
  ...(database.onCachedRoutesChange === undefined
211
210
  ? {}
212
211
  : { onCachedRoutesChange: () => database.onCachedRoutesChange!() }),
212
+ ...(database.aggregateBatching === undefined
213
+ ? {}
214
+ : { batching: database.aggregateBatching }),
213
215
  });
214
216
  const clientAuth = plugins.clientAuth;
215
217
  if (clientAuth !== undefined && publicClients) {
@@ -244,12 +246,14 @@ export function createHotUpdater<
244
246
  handlers,
245
247
  core: plugins.core,
246
248
  api: plugins.api as PluginApis<TPlugins>,
249
+ flush: plugins.flush,
247
250
  };
248
251
  Object.defineProperty(api, hotUpdaterCoreMetadata, {
249
252
  enumerable: false,
250
253
  value: {
251
254
  database,
252
255
  target: toolingTargetOf(options.plugins ?? []),
256
+ plugins: options.plugins ?? [],
253
257
  } satisfies HotUpdaterCoreMetadata,
254
258
  });
255
259
  return api;
@@ -0,0 +1,577 @@
1
+ import type { AggregateBatching } from "@hot-updater/plugin-core";
2
+ import {
3
+ addDistinct,
4
+ countDistinct,
5
+ createMemoryAdapter,
6
+ type DatabaseAdapter,
7
+ type WriteOp,
8
+ type WriteResult,
9
+ } from "@hot-updater/plugin-core/internal";
10
+ import { afterEach, describe, expect, it, vi } from "vitest";
11
+
12
+ import { aggregateBatchingModule } from "./aggregateBatching";
13
+ import { createDatabaseEngine } from "./database";
14
+ import { resolveSchema } from "./resolveSchema";
15
+ import { defineAggregate, defineTable } from "./schema";
16
+
17
+ const installs = defineTable(
18
+ {
19
+ id: { type: "string", maxLength: 64 },
20
+ release: { type: "string", maxLength: 16 },
21
+ },
22
+ { key: ["id"] },
23
+ );
24
+
25
+ /** Installations by the release they run: a gauge each move takes from one row and gives another. */
26
+ const distribution = defineAggregate(
27
+ { release: { type: "string", maxLength: 16 } },
28
+ {
29
+ key: ["release"],
30
+ gauges: ["installations"],
31
+ shards: 8,
32
+ batched: true,
33
+ indexes: { byRelease: { eq: ["release"], sort: [] } },
34
+ },
35
+ );
36
+
37
+ const opens = defineAggregate(
38
+ { day: { type: "integer" } },
39
+ {
40
+ key: ["day"],
41
+ counters: ["opens", "failures"],
42
+ shards: 4,
43
+ batched: true,
44
+ indexes: { all: { eq: [], sort: ["day"] } },
45
+ },
46
+ );
47
+
48
+ const users = defineAggregate(
49
+ { day: { type: "integer" } },
50
+ {
51
+ key: ["day"],
52
+ distinct: ["users"],
53
+ shards: 4,
54
+ batched: true,
55
+ indexes: { all: { eq: [], sort: ["day"] } },
56
+ },
57
+ );
58
+
59
+ /** Not batched: it commits with each transaction, batching or not. */
60
+ const totals = defineAggregate(
61
+ { scope: { type: "string", maxLength: 16 } },
62
+ {
63
+ key: ["scope"],
64
+ counters: ["hits"],
65
+ indexes: { all: { eq: [], sort: ["scope"] } },
66
+ },
67
+ );
68
+
69
+ const module = {
70
+ id: "stats",
71
+ schema: { installs, distribution, opens, users, totals },
72
+ } as const;
73
+ const plain = resolveSchema([module]);
74
+ const batched = resolveSchema([module, aggregateBatchingModule]);
75
+ const table = (name: string) => batched.models.get(name)!.table;
76
+ const LOG_TABLES = Array.from({ length: 8 }, (_, at) => `aggregate_log_${at}`);
77
+
78
+ const sketchOf = (id: string) => addDistinct(null, id);
79
+
80
+ interface Setup {
81
+ readonly batching?: AggregateBatching;
82
+ readonly adapter?: DatabaseAdapter;
83
+ /** Answers a write in place of the store, which `write` reaches; undefined writes as usual. */
84
+ readonly fault?: (
85
+ ops: readonly WriteOp[],
86
+ write: DatabaseAdapter["write"],
87
+ ) => WriteResult | Promise<WriteResult | undefined> | undefined;
88
+ readonly maxOps?: number;
89
+ }
90
+
91
+ const setup = async ({ batching, adapter, fault, maxOps }: Setup = {}) => {
92
+ const memory = createMemoryAdapter(maxOps === undefined ? {} : { maxOps });
93
+ const schema = batching === undefined ? plain : batched;
94
+ if (adapter === undefined) await memory.migrations?.apply(schema.tables);
95
+ const base = adapter ?? memory;
96
+ const writes: (readonly WriteOp[])[] = [];
97
+ const clock = { now: 1_000_000 };
98
+ const engine = createDatabaseEngine({
99
+ adapter: {
100
+ ...base,
101
+ async write(ops) {
102
+ writes.push(ops);
103
+ return (
104
+ (await fault?.(ops, (given) => base.write(given))) ?? base.write(ops)
105
+ );
106
+ },
107
+ },
108
+ schema,
109
+ retry: { attempts: 8, baseDelayMs: 0, maxDelayMs: 1 },
110
+ ...(batching === undefined ? {} : { batching, now: () => clock.now }),
111
+ });
112
+ return {
113
+ memory: base,
114
+ writes,
115
+ clock,
116
+ engine,
117
+ db: engine.database(module),
118
+ };
119
+ };
120
+
121
+ type Db = Awaited<ReturnType<typeof setup>>["db"];
122
+
123
+ /** An installation opens the app on `release`, moving its gauge when the release changed. */
124
+ const open = (db: Db, id: string, release: string, day = 1) =>
125
+ db.transaction(async (tx) => {
126
+ const head = await tx.findOne("installs", { id });
127
+ if (head === null) {
128
+ tx.create("installs", { id, release });
129
+ } else if (head.release !== release) {
130
+ tx.update("installs", head, { release });
131
+ tx.aggregate(
132
+ "distribution",
133
+ { release: head.release },
134
+ { installations: -1 },
135
+ { shardBy: id },
136
+ );
137
+ }
138
+ if (head?.release !== release) {
139
+ tx.aggregate(
140
+ "distribution",
141
+ { release },
142
+ { installations: 1 },
143
+ { shardBy: id },
144
+ );
145
+ }
146
+ tx.aggregate("opens", { day }, { opens: 1 }, { shardBy: id });
147
+ tx.aggregate("users", { day }, { users: sketchOf(id) }, { shardBy: id });
148
+ tx.aggregate("totals", { scope: "all" }, { hits: 1 });
149
+ });
150
+
151
+ /** Every aggregate as reads see it. */
152
+ const snapshot = async (db: Db) => {
153
+ const [releases, days, sketches, scopes] = await Promise.all([
154
+ Promise.all(
155
+ ["A", "B", "C"].map((release) =>
156
+ db.findAggregates("distribution", {
157
+ index: "byRelease",
158
+ where: { release },
159
+ limit: 10,
160
+ }),
161
+ ),
162
+ ),
163
+ db.findAggregates("opens", { index: "all", where: {}, limit: 10 }),
164
+ db.findAggregates("users", { index: "all", where: {}, limit: 10 }),
165
+ db.findAggregates("totals", { index: "all", where: {}, limit: 10 }),
166
+ ]);
167
+ return {
168
+ distribution: releases.flatMap(({ rows }) => rows),
169
+ opens: days.rows,
170
+ users: sketches.rows.map((row) => ({
171
+ day: row.day,
172
+ users: countDistinct(row.users),
173
+ })),
174
+ totals: scopes.rows,
175
+ };
176
+ };
177
+
178
+ const logRows = async (memory: DatabaseAdapter) =>
179
+ (
180
+ await Promise.all(
181
+ LOG_TABLES.map((name) =>
182
+ memory.query(table(name), {
183
+ index: "oldest",
184
+ eq: [],
185
+ order: "asc",
186
+ limit: 500,
187
+ }),
188
+ ),
189
+ )
190
+ ).flat();
191
+
192
+ const RELEASES = ["A", "B", "C"] as const;
193
+ /** Step `step` of the traffic: 12 installations, each moving to the next release every round. */
194
+ const stepOf = (step: number) => ({
195
+ id: `i${step % 12}`,
196
+ release: RELEASES[(Math.floor(step / 12) + step) % 3]!,
197
+ day: 1 + (step % 2),
198
+ });
199
+
200
+ /** 60 opens: five rounds of 12 installations over 3 releases and 2 days. */
201
+ const traffic = async (db: Db) => {
202
+ for (let step = 0; step < 60; step += 1) {
203
+ const { id, release, day } = stepOf(step);
204
+ await open(db, id, release, day);
205
+ }
206
+ };
207
+
208
+ afterEach(() => {
209
+ vi.useRealTimers();
210
+ vi.restoreAllMocks();
211
+ });
212
+
213
+ describe("aggregate batching", () => {
214
+ it("writes one log row with each transaction instead of its batched aggregate rows", async () => {
215
+ const { db, writes, memory, clock } = await setup({
216
+ batching: { mode: "log", windowMs: 60_000 },
217
+ });
218
+ await open(db, "i1", "A");
219
+ writes.length = 0;
220
+ clock.now += 1_000;
221
+ await open(db, "i1", "B");
222
+
223
+ // Not due yet: the first commit compacted, and the window has not passed.
224
+ expect(writes).toHaveLength(1);
225
+ expect(writes[0]!.map((op) => [op.type, op.table.name])).toEqual([
226
+ ["insert", expect.stringMatching(/^aggregate_log_\d$/)],
227
+ ["patch", "installs"],
228
+ ["increment", "totals"],
229
+ ]);
230
+ expect(await logRows(memory)).toHaveLength(1);
231
+ });
232
+
233
+ it("reads what log, memory, and transactional writes all read, whichever writes it", async () => {
234
+ const reference = await setup();
235
+ const log = await setup({ batching: { mode: "log", windowMs: 60_000 } });
236
+ const memory = await setup({ batching: { mode: "memory" } });
237
+ for (const { db } of [reference, log, memory]) await traffic(db);
238
+
239
+ const expected = await snapshot(reference.db);
240
+ expect(expected.distribution.map((row) => row.installations)).toEqual([
241
+ 4, 4, 4,
242
+ ]);
243
+ expect(await snapshot(log.db)).toEqual(expected);
244
+ expect(await snapshot(memory.db)).toEqual(expected);
245
+ expect(await logRows(log.memory)).toEqual([]);
246
+ });
247
+
248
+ it("writes each batched row once per compaction, however many transactions changed it", async () => {
249
+ const reference = await setup();
250
+ const log = await setup({ batching: { mode: "log", windowMs: 60_000 } });
251
+ await traffic(reference.db);
252
+ await traffic(log.db);
253
+ await log.engine.flush();
254
+
255
+ const aggregateOps = (writes: readonly (readonly WriteOp[])[]) =>
256
+ writes
257
+ .flat()
258
+ .filter(({ table: { name } }) =>
259
+ ["distribution", "opens", "users"].includes(name),
260
+ ).length;
261
+ // One compaction after the first commit, one on flush: a few rows each.
262
+ expect(aggregateOps(log.writes)).toBeLessThanOrEqual(10);
263
+ expect(aggregateOps(reference.writes)).toBeGreaterThan(150);
264
+ });
265
+
266
+ it("applies each log row once when a compaction write's outcome is lost", async () => {
267
+ const reference = await setup();
268
+ await traffic(reference.db);
269
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
270
+ // The group write (aggregate rows and the lease listing them as applied),
271
+ // then the deletes after it: each lost after it committed, or before.
272
+ const writes = {
273
+ group: (ops: readonly WriteOp[]) =>
274
+ ops.some(({ table: { name } }) => name === "opens"),
275
+ deletes: (ops: readonly WriteOp[]) =>
276
+ ops.every((op) => op.type === "delete"),
277
+ };
278
+ for (const [kind, matches] of Object.entries(writes)) {
279
+ for (const applied of [true, false]) {
280
+ let lose = false;
281
+ const log = await setup({
282
+ batching: { mode: "log", windowMs: 60_000 },
283
+ fault: async (ops, write) => {
284
+ if (!lose || !matches(ops)) return undefined;
285
+ lose = false;
286
+ if (applied) await write(ops);
287
+ throw new Error("socket hang up");
288
+ },
289
+ });
290
+ await traffic(log.db);
291
+ lose = true;
292
+ await log.engine.flush();
293
+ expect(lose, `${kind} write`).toBe(false);
294
+ expect(warn).toHaveBeenLastCalledWith(
295
+ "[hot-updater] Aggregate compaction failed.",
296
+ expect.any(Error),
297
+ );
298
+ expect(await snapshot(log.db)).toEqual(await snapshot(reference.db));
299
+ expect(await logRows(log.memory)).toEqual([]);
300
+ }
301
+ }
302
+ });
303
+
304
+ it("deletes applied log rows through the adapter's unguarded delete, and falls back when it fails", async () => {
305
+ const reference = await setup();
306
+ await traffic(reference.db);
307
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
308
+ for (const refused of [false, true]) {
309
+ const memory = createMemoryAdapter();
310
+ await memory.migrations?.apply(batched.tables);
311
+ let consumed = 0;
312
+ const log = await setup({
313
+ batching: { mode: "log", windowMs: 60_000 },
314
+ adapter: {
315
+ ...memory,
316
+ async deleteConsumed(physical, rows) {
317
+ // A role without the permission is refused before it deletes.
318
+ if (refused) throw new Error("AccessDeniedException");
319
+ const keys = rows.map((row) => [String(row.id)]);
320
+ const current = await memory.get(physical, keys);
321
+ await memory.write(
322
+ rows.flatMap((row, at) =>
323
+ current[at] === null
324
+ ? []
325
+ : [
326
+ {
327
+ type: "delete" as const,
328
+ table: physical,
329
+ key: keys[at]!,
330
+ guard: { v: Number(row._v) },
331
+ previous: row,
332
+ },
333
+ ],
334
+ ),
335
+ );
336
+ consumed += rows.length;
337
+ },
338
+ },
339
+ });
340
+ await traffic(log.db);
341
+ await log.engine.flush();
342
+ expect(await snapshot(log.db)).toEqual(await snapshot(reference.db));
343
+ expect(await logRows(memory)).toEqual([]);
344
+ const guarded = log.writes
345
+ .flat()
346
+ .filter(
347
+ (op) =>
348
+ op.type === "delete" && op.table.name.startsWith("aggregate_log_"),
349
+ );
350
+ if (refused) {
351
+ expect(warn).toHaveBeenCalledWith(
352
+ "[hot-updater] Aggregate log cleanup failed.",
353
+ expect.any(Error),
354
+ );
355
+ expect(guarded).toHaveLength(60);
356
+ } else {
357
+ expect(consumed).toBe(60);
358
+ expect(guarded).toEqual([]);
359
+ }
360
+ }
361
+ });
362
+
363
+ it("applies each log row once when two processes compact the same log", async () => {
364
+ const shared = createMemoryAdapter();
365
+ await shared.migrations?.apply(batched.tables);
366
+ const reference = await setup();
367
+ const first = await setup({
368
+ adapter: shared,
369
+ batching: { mode: "log", windowMs: 60_000 },
370
+ });
371
+ const second = await setup({
372
+ adapter: shared,
373
+ batching: { mode: "log", windowMs: 60_000 },
374
+ });
375
+ for (let step = 0; step < 60; step += 1) {
376
+ const { id, release, day } = stepOf(step);
377
+ await open(step % 2 === 0 ? first.db : second.db, id, release, day);
378
+ await open(reference.db, id, release, day);
379
+ }
380
+ await Promise.all([first.engine.flush(), second.engine.flush()]);
381
+ await first.engine.flush();
382
+
383
+ expect(await snapshot(first.db)).toEqual(await snapshot(reference.db));
384
+ expect(await logRows(shared)).toEqual([]);
385
+ });
386
+
387
+ it("keeps a shard row below zero when another process holds its gains, and reads the sum", async () => {
388
+ const shared = createMemoryAdapter();
389
+ await shared.migrations?.apply(batched.tables);
390
+ const gain = await setup({ adapter: shared, batching: { mode: "memory" } });
391
+ const loss = await setup({ adapter: shared, batching: { mode: "memory" } });
392
+ // Each process picks its shard on its first flush.
393
+ const flushOnShard = async (engine: typeof gain.engine, random: number) => {
394
+ vi.spyOn(Math, "random").mockReturnValue(random);
395
+ await engine.flush();
396
+ vi.restoreAllMocks();
397
+ };
398
+
399
+ await open(gain.db, "i1", "A");
400
+ await flushOnShard(gain.engine, 0);
401
+ await open(loss.db, "i1", "B");
402
+ await flushOnShard(loss.engine, 0.99);
403
+
404
+ const shards = await shared.query(table("distribution"), {
405
+ index: "byRelease",
406
+ eq: ["A"],
407
+ order: "asc",
408
+ limit: 10,
409
+ });
410
+ expect(shards.map((row) => [row._shard, row.installations])).toEqual([
411
+ [0, 1],
412
+ [7, -1],
413
+ ]);
414
+ const read = await gain.db.findAggregates("distribution", {
415
+ index: "byRelease",
416
+ where: { release: "A" },
417
+ limit: 10,
418
+ });
419
+ expect(read.rows).toEqual([{ release: "A", installations: 0 }]);
420
+ });
421
+
422
+ it("records only the attempt that committed when a transaction reruns", async () => {
423
+ let conflicts = 1;
424
+ const { db, engine } = await setup({
425
+ batching: { mode: "log", windowMs: 60_000 },
426
+ fault: (ops) =>
427
+ ops.some(({ table: { name } }) => name === "installs") &&
428
+ conflicts-- > 0
429
+ ? { ok: false, failedOp: 0 }
430
+ : undefined,
431
+ });
432
+ let attempts = 0;
433
+ await db.transaction(async (tx) => {
434
+ attempts += 1;
435
+ tx.create("installs", { id: "i1", release: "A" });
436
+ tx.aggregate("opens", { day: 1 }, { opens: 1 }, { shardBy: "i1" });
437
+ });
438
+ await engine.flush();
439
+ expect(attempts).toBe(2);
440
+ expect(
441
+ (await db.findAggregates("opens", { index: "all", where: {}, limit: 10 }))
442
+ .rows,
443
+ ).toEqual([{ day: 1, opens: 1, failures: 0 }]);
444
+ });
445
+
446
+ it("fails the transaction on an invalid batched change, even one fn caught", async () => {
447
+ const { db, writes } = await setup({ batching: { mode: "log" } });
448
+ await expect(
449
+ db.transaction(async (tx) => {
450
+ tx.create("installs", { id: "i1", release: "A" });
451
+ try {
452
+ tx.aggregate("distribution", { release: "A" }, { installations: 1 });
453
+ } catch {}
454
+ }),
455
+ ).rejects.toThrow("gauges of a sharded aggregate need shardBy");
456
+ expect(writes).toEqual([]);
457
+ });
458
+
459
+ it("splits a log row too large for one write, applying every change once", async () => {
460
+ const reference = await setup();
461
+ // Three ops a write: one change and its log row's patch, or two and its delete.
462
+ const log = await setup({
463
+ batching: { mode: "log", windowMs: 60_000 },
464
+ maxOps: 3,
465
+ });
466
+ const five = (db: Db) =>
467
+ db.transaction(async (tx) => {
468
+ for (let day = 1; day <= 5; day += 1) {
469
+ tx.aggregate("opens", { day }, { opens: day }, { shardBy: "i1" });
470
+ }
471
+ });
472
+ await five(reference.db);
473
+ await five(log.db);
474
+ await log.engine.flush();
475
+ expect(await snapshot(log.db)).toEqual(await snapshot(reference.db));
476
+ expect(await logRows(log.memory)).toEqual([]);
477
+ });
478
+
479
+ it("serves stored aggregates when a read cannot compact", async () => {
480
+ const reference = await setup();
481
+ const log = await setup({
482
+ batching: { mode: "log", windowMs: 60_000 },
483
+ });
484
+ await open(reference.db, "i1", "A");
485
+ await open(log.db, "i1", "A");
486
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
487
+ const readOnly = await setup({
488
+ adapter: log.memory,
489
+ batching: { mode: "log", windowMs: 60_000 },
490
+ fault: () => {
491
+ throw new Error("AccessDeniedException");
492
+ },
493
+ });
494
+ await open(log.db, "i2", "B");
495
+
496
+ const stale = await snapshot(readOnly.db);
497
+ expect(stale.distribution).toEqual([{ release: "A", installations: 1 }]);
498
+ expect(warn).toHaveBeenCalledWith(
499
+ "[hot-updater] Aggregate compaction failed.",
500
+ expect.any(Error),
501
+ );
502
+ await open(reference.db, "i2", "B");
503
+ expect(await snapshot(log.db)).toEqual(await snapshot(reference.db));
504
+ });
505
+
506
+ it("leaves a log row naming an aggregate it lacks for a process that has it", async () => {
507
+ const shared = createMemoryAdapter();
508
+ await shared.migrations?.apply(batched.tables);
509
+ const full = await setup({
510
+ adapter: shared,
511
+ batching: { mode: "log", windowMs: 60_000 },
512
+ });
513
+ const partial = createDatabaseEngine({
514
+ adapter: shared,
515
+ schema: resolveSchema([
516
+ { id: "stats", schema: { installs, opens } },
517
+ aggregateBatchingModule,
518
+ ]),
519
+ batching: { mode: "log" },
520
+ });
521
+ await open(full.db, "i1", "A");
522
+ await open(full.db, "i1", "B");
523
+ await partial.flush();
524
+ expect(await logRows(shared)).toHaveLength(1);
525
+ await full.engine.flush();
526
+ expect(await logRows(shared)).toEqual([]);
527
+ });
528
+
529
+ it("keeps memory-mode changes in the process until the window passes or a read", async () => {
530
+ vi.useFakeTimers();
531
+ const { db, writes, memory } = await setup({
532
+ batching: { mode: "memory", windowMs: 5_000 },
533
+ });
534
+ for (const id of ["i1", "i2", "i3"]) await open(db, id, "A");
535
+ const rows = () =>
536
+ memory.query(table("opens"), {
537
+ index: "all",
538
+ eq: [],
539
+ order: "asc",
540
+ limit: 10,
541
+ });
542
+ expect(await rows()).toEqual([]);
543
+ expect(writes.flat().map((op) => op.table.name)).not.toContain("opens");
544
+
545
+ await vi.advanceTimersByTimeAsync(5_000);
546
+ expect((await rows()).map((row) => row.opens)).toEqual([3]);
547
+
548
+ await open(db, "i4", "A");
549
+ await expect(
550
+ db.findAggregates("opens", { index: "all", where: {}, limit: 10 }),
551
+ ).resolves.toEqual({ rows: [{ day: 1, opens: 4, failures: 0 }] });
552
+ });
553
+
554
+ it("keeps changes a memory flush could not write for the next flush", async () => {
555
+ let failing = true;
556
+ const { db, engine, memory } = await setup({
557
+ batching: { mode: "memory" },
558
+ fault: (ops) =>
559
+ failing && ops.some(({ table: { name } }) => name === "opens")
560
+ ? { ok: false, retry: true }
561
+ : undefined,
562
+ });
563
+ await open(db, "i1", "A");
564
+ await engine.flush();
565
+ const opens = () =>
566
+ memory.query(table("opens"), {
567
+ index: "all",
568
+ eq: [],
569
+ order: "asc",
570
+ limit: 10,
571
+ });
572
+ expect(await opens()).toEqual([]);
573
+ failing = false;
574
+ await engine.flush();
575
+ expect((await opens()).map((row) => row.opens)).toEqual([1]);
576
+ });
577
+ });