@hot-updater/server 1.0.0-rc.2 → 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 (328) hide show
  1. package/LICENSE +12 -14
  2. package/dist/adapters/drizzle.cjs +32 -75
  3. package/dist/adapters/drizzle.d.cts +13 -5
  4. package/dist/adapters/drizzle.d.mts +13 -5
  5. package/dist/adapters/drizzle.mjs +32 -77
  6. package/dist/adapters/drizzleExecutor.cjs +114 -0
  7. package/dist/adapters/drizzleExecutor.d.cts +9 -0
  8. package/dist/adapters/drizzleExecutor.d.mts +9 -0
  9. package/dist/adapters/drizzleExecutor.mjs +112 -0
  10. package/dist/adapters/kysely.cjs +22 -31
  11. package/dist/adapters/kysely.d.cts +10 -6
  12. package/dist/adapters/kysely.d.mts +10 -6
  13. package/dist/adapters/kysely.mjs +23 -33
  14. package/dist/adapters/kyselyExecutor.cjs +32 -0
  15. package/dist/adapters/kyselyExecutor.d.cts +11 -0
  16. package/dist/adapters/kyselyExecutor.d.mts +11 -0
  17. package/dist/adapters/kyselyExecutor.mjs +32 -0
  18. package/dist/adapters/mongodb.cjs +18 -54
  19. package/dist/adapters/mongodb.d.cts +10 -5
  20. package/dist/adapters/mongodb.d.mts +10 -5
  21. package/dist/adapters/mongodb.mjs +19 -56
  22. package/dist/adapters/mongodbAdapter.cjs +192 -0
  23. package/dist/adapters/mongodbAdapter.d.cts +9 -0
  24. package/dist/adapters/mongodbAdapter.d.mts +9 -0
  25. package/dist/adapters/mongodbAdapter.mjs +191 -0
  26. package/dist/adapters/prisma.cjs +35 -267
  27. package/dist/adapters/prisma.d.cts +12 -7
  28. package/dist/adapters/prisma.d.mts +12 -7
  29. package/dist/adapters/prisma.mjs +36 -268
  30. package/dist/adapters/prismaExecutor.cjs +63 -0
  31. package/dist/adapters/prismaExecutor.mjs +63 -0
  32. package/dist/adapters/sqlProviders.cjs +14 -0
  33. package/dist/adapters/sqlProviders.mjs +14 -0
  34. package/dist/assembly/assemblePlugins.cjs +144 -0
  35. package/dist/assembly/assemblePlugins.d.cts +5 -0
  36. package/dist/assembly/assemblePlugins.d.mts +5 -0
  37. package/dist/assembly/assemblePlugins.mjs +139 -0
  38. package/dist/assembly/clientPlugins.cjs +88 -0
  39. package/dist/assembly/clientPlugins.mjs +88 -0
  40. package/dist/assembly/configError.d.cts +2 -0
  41. package/dist/assembly/configError.d.mts +2 -0
  42. package/dist/assembly/configError.mjs +2 -0
  43. package/dist/core/api.cjs +51 -0
  44. package/dist/core/api.d.cts +54 -0
  45. package/dist/core/api.d.mts +54 -0
  46. package/dist/core/api.mjs +51 -0
  47. package/dist/core/baseCandidates.cjs +28 -0
  48. package/dist/core/baseCandidates.mjs +28 -0
  49. package/dist/core/operations.cjs +351 -0
  50. package/dist/core/operations.mjs +351 -0
  51. package/dist/core/reads.cjs +273 -0
  52. package/dist/core/reads.d.cts +9 -0
  53. package/dist/core/reads.d.mts +9 -0
  54. package/dist/core/reads.mjs +267 -0
  55. package/dist/core/releases.cjs +193 -0
  56. package/dist/core/releases.mjs +190 -0
  57. package/dist/core/writes.cjs +96 -0
  58. package/dist/core/writes.mjs +91 -0
  59. package/dist/createHotUpdaterCore.cjs +72 -91
  60. package/dist/createHotUpdaterCore.d.cts +106 -38
  61. package/dist/createHotUpdaterCore.d.mts +106 -38
  62. package/dist/createHotUpdaterCore.mjs +74 -89
  63. package/dist/db/engineDrizzleSchema.cjs +53 -0
  64. package/dist/db/engineDrizzleSchema.mjs +53 -0
  65. package/dist/db/enginePrismaSchema.cjs +84 -0
  66. package/dist/db/enginePrismaSchema.d.cts +5 -0
  67. package/dist/db/enginePrismaSchema.d.mts +5 -0
  68. package/dist/db/enginePrismaSchema.mjs +83 -0
  69. package/dist/db/releaseCatalog.cjs +24 -47
  70. package/dist/db/releaseCatalog.mjs +20 -44
  71. package/dist/db/updateArtifacts.cjs +43 -72
  72. package/dist/db/updateArtifacts.mjs +40 -69
  73. package/dist/handler.cjs +59 -43
  74. package/dist/handler.d.cts +3 -5
  75. package/dist/handler.d.mts +3 -5
  76. package/dist/handler.mjs +61 -43
  77. package/dist/handlerAdminRoutes.cjs +374 -0
  78. package/dist/handlerAdminRoutes.mjs +372 -0
  79. package/dist/handlerParameters.cjs +6 -11
  80. package/dist/handlerParameters.mjs +6 -10
  81. package/dist/handlerReleaseCatalogRoutes.cjs +32 -15
  82. package/dist/handlerReleaseCatalogRoutes.mjs +32 -15
  83. package/dist/handlerTypes.d.cts +2 -55
  84. package/dist/handlerTypes.d.mts +2 -55
  85. package/dist/handlerVersionRoutes.cjs +20 -4
  86. package/dist/handlerVersionRoutes.mjs +20 -4
  87. package/dist/index.cjs +9 -9
  88. package/dist/index.d.cts +8 -9
  89. package/dist/index.d.mts +8 -9
  90. package/dist/index.mjs +3 -4
  91. package/dist/node.cjs +3 -6
  92. package/dist/node.d.cts +2 -2
  93. package/dist/node.d.mts +2 -2
  94. package/dist/node.mjs +4 -4
  95. package/dist/package.cjs +1 -1
  96. package/dist/package.mjs +1 -1
  97. package/dist/plugins/api-keys/index.cjs +9 -0
  98. package/dist/plugins/api-keys/index.d.cts +1 -0
  99. package/dist/plugins/api-keys/index.d.mts +1 -0
  100. package/dist/plugins/api-keys/index.mjs +2 -0
  101. package/dist/plugins/definePlugin.d.cts +2 -0
  102. package/dist/plugins/definePlugin.d.mts +2 -0
  103. package/dist/plugins/insights/index.cjs +9 -0
  104. package/dist/plugins/insights/index.d.cts +1 -0
  105. package/dist/plugins/insights/index.d.mts +1 -0
  106. package/dist/plugins/insights/index.mjs +2 -0
  107. package/dist/plugins/official.cjs +30 -0
  108. package/dist/plugins/official.mjs +29 -0
  109. package/dist/storageAccess.cjs +13 -10
  110. package/dist/storageAccess.mjs +13 -10
  111. package/dist/types/index.d.cts +2 -28
  112. package/dist/types/index.d.mts +2 -28
  113. package/package.json +26 -14
  114. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  115. package/dist/adapters/databaseConstraintErrors.cjs +0 -22
  116. package/dist/adapters/databaseConstraintErrors.mjs +0 -21
  117. package/dist/adapters/databasePluginUtils.cjs +0 -116
  118. package/dist/adapters/databasePluginUtils.mjs +0 -106
  119. package/dist/adapters/drizzleCrud.cjs +0 -311
  120. package/dist/adapters/drizzleCrud.mjs +0 -308
  121. package/dist/adapters/drizzleLazyDB.cjs +0 -106
  122. package/dist/adapters/drizzleLazyDB.mjs +0 -106
  123. package/dist/adapters/drizzleQuery.cjs +0 -69
  124. package/dist/adapters/drizzleQuery.mjs +0 -69
  125. package/dist/adapters/insightsTransaction.cjs +0 -22
  126. package/dist/adapters/insightsTransaction.mjs +0 -22
  127. package/dist/adapters/kyselyCrud.cjs +0 -305
  128. package/dist/adapters/kyselyCrud.mjs +0 -304
  129. package/dist/adapters/kyselyQuery.cjs +0 -56
  130. package/dist/adapters/kyselyQuery.mjs +0 -56
  131. package/dist/adapters/mongodbCollections.cjs +0 -38
  132. package/dist/adapters/mongodbCollections.mjs +0 -32
  133. package/dist/adapters/mongodbQuery.cjs +0 -94
  134. package/dist/adapters/mongodbQuery.mjs +0 -86
  135. package/dist/adapters/mongodbReads.cjs +0 -210
  136. package/dist/adapters/mongodbReads.mjs +0 -210
  137. package/dist/adapters/mongodbWrites.cjs +0 -148
  138. package/dist/adapters/mongodbWrites.mjs +0 -148
  139. package/dist/adapters/prismaQuery.cjs +0 -57
  140. package/dist/adapters/prismaQuery.mjs +0 -56
  141. package/dist/adapters/prismaRows.cjs +0 -219
  142. package/dist/adapters/prismaRows.mjs +0 -209
  143. package/dist/apiKeys.cjs +0 -143
  144. package/dist/apiKeys.d.cts +0 -49
  145. package/dist/apiKeys.d.mts +0 -49
  146. package/dist/apiKeys.mjs +0 -133
  147. package/dist/db/createBundleDiff.cjs +0 -144
  148. package/dist/db/createBundleDiff.d.cts +0 -16
  149. package/dist/db/createBundleDiff.d.mts +0 -16
  150. package/dist/db/createBundleDiff.mjs +0 -141
  151. package/dist/db/databasePluginCore.cjs +0 -137
  152. package/dist/db/databasePluginCore.mjs +0 -137
  153. package/dist/db/fixedMigrator.cjs +0 -79
  154. package/dist/db/fixedMigrator.mjs +0 -78
  155. package/dist/db/fixedMigratorMongo.cjs +0 -321
  156. package/dist/db/fixedMigratorMongo.mjs +0 -321
  157. package/dist/db/fixedMigratorShared.cjs +0 -23
  158. package/dist/db/fixedMigratorShared.mjs +0 -18
  159. package/dist/db/index.cjs +0 -27
  160. package/dist/db/index.d.cts +0 -12
  161. package/dist/db/index.d.mts +0 -12
  162. package/dist/db/index.mjs +0 -22
  163. package/dist/db/mongoMigrationExecution.cjs +0 -11
  164. package/dist/db/mongoMigrationExecution.mjs +0 -11
  165. package/dist/db/releaseCatalog.d.cts +0 -16
  166. package/dist/db/releaseCatalog.d.mts +0 -16
  167. package/dist/db/schema/insightsCollation.cjs +0 -14
  168. package/dist/db/schema/insightsCollation.mjs +0 -14
  169. package/dist/db/schema/mongodb.cjs +0 -25
  170. package/dist/db/schema/mongodb.mjs +0 -25
  171. package/dist/db/schema/registry.cjs +0 -21
  172. package/dist/db/schema/registry.mjs +0 -17
  173. package/dist/db/schema/sql.cjs +0 -105
  174. package/dist/db/schema/sql.mjs +0 -97
  175. package/dist/db/schema/sqlOperations.cjs +0 -27
  176. package/dist/db/schema/sqlOperations.mjs +0 -26
  177. package/dist/db/schemaGenerators.cjs +0 -275
  178. package/dist/db/schemaGenerators.mjs +0 -273
  179. package/dist/db/schemaReadiness.cjs +0 -26
  180. package/dist/db/schemaReadiness.d.cts +0 -9
  181. package/dist/db/schemaReadiness.d.mts +0 -9
  182. package/dist/db/schemaReadiness.mjs +0 -25
  183. package/dist/db/sqlMigrationExecution.cjs +0 -67
  184. package/dist/db/sqlMigrationExecution.mjs +0 -67
  185. package/dist/db/types.cjs +0 -22
  186. package/dist/db/types.d.cts +0 -118
  187. package/dist/db/types.d.mts +0 -118
  188. package/dist/db/types.mjs +0 -19
  189. package/dist/handlerBundleRoutes.cjs +0 -155
  190. package/dist/handlerBundleRoutes.mjs +0 -155
  191. package/dist/handlerReleaseManagementRoutes.cjs +0 -124
  192. package/dist/handlerReleaseManagementRoutes.mjs +0 -124
  193. package/dist/insights/domain.d.cts +0 -89
  194. package/dist/insights/domain.d.mts +0 -89
  195. package/dist/insights/errors.cjs +0 -15
  196. package/dist/insights/errors.mjs +0 -14
  197. package/dist/insights/eventInput.cjs +0 -155
  198. package/dist/insights/eventInput.mjs +0 -153
  199. package/dist/insights/provider.cjs +0 -314
  200. package/dist/insights/provider.d.cts +0 -6
  201. package/dist/insights/provider.d.mts +0 -6
  202. package/dist/insights/provider.mjs +0 -314
  203. package/dist/insights/queryInput.cjs +0 -93
  204. package/dist/insights/queryInput.mjs +0 -91
  205. package/dist/insights/routes.cjs +0 -58
  206. package/dist/insights/routes.mjs +0 -56
  207. package/dist/insights/types.d.cts +0 -32
  208. package/dist/insights/types.d.mts +0 -32
  209. package/dist/schema/dsl.cjs +0 -103
  210. package/dist/schema/dsl.mjs +0 -87
  211. package/dist/schema/index.cjs +0 -20
  212. package/dist/schema/index.mjs +0 -7
  213. package/dist/schema/settings.cjs +0 -9
  214. package/dist/schema/settings.mjs +0 -9
  215. package/dist/schema/types.cjs +0 -8
  216. package/dist/schema/types.mjs +0 -6
  217. package/dist/schema/v1_0_0.cjs +0 -406
  218. package/dist/schema/v1_0_0.mjs +0 -398
  219. package/src/adapters/databaseConstraintErrors.ts +0 -25
  220. package/src/adapters/databasePluginTestDatabase.ts +0 -120
  221. package/src/adapters/databasePluginUtils.spec.ts +0 -29
  222. package/src/adapters/databasePluginUtils.ts +0 -214
  223. package/src/adapters/drizzle.spec.ts +0 -336
  224. package/src/adapters/drizzle.ts +0 -162
  225. package/src/adapters/drizzleCrud.ts +0 -571
  226. package/src/adapters/drizzleLazyDB.ts +0 -271
  227. package/src/adapters/drizzleQuery.ts +0 -164
  228. package/src/adapters/insightsTransaction.ts +0 -32
  229. package/src/adapters/kysely.spec.ts +0 -174
  230. package/src/adapters/kysely.ts +0 -110
  231. package/src/adapters/kyselyCrud.ts +0 -709
  232. package/src/adapters/kyselyQuery.ts +0 -128
  233. package/src/adapters/mongodb.integration.spec.ts +0 -210
  234. package/src/adapters/mongodb.spec.ts +0 -209
  235. package/src/adapters/mongodb.ts +0 -138
  236. package/src/adapters/mongodbCollections.ts +0 -67
  237. package/src/adapters/mongodbQuery.ts +0 -255
  238. package/src/adapters/mongodbReads.ts +0 -380
  239. package/src/adapters/mongodbRows.spec.ts +0 -64
  240. package/src/adapters/mongodbRows.ts +0 -118
  241. package/src/adapters/mongodbTestClient.ts +0 -377
  242. package/src/adapters/mongodbTestFilter.ts +0 -169
  243. package/src/adapters/mongodbWrites.ts +0 -287
  244. package/src/adapters/prisma.spec.ts +0 -293
  245. package/src/adapters/prisma.ts +0 -565
  246. package/src/adapters/prismaQuery.ts +0 -129
  247. package/src/adapters/prismaRows.spec.ts +0 -98
  248. package/src/adapters/prismaRows.ts +0 -337
  249. package/src/adapters/prismaTestClient.ts +0 -413
  250. package/src/apiKeys.integration.spec.ts +0 -192
  251. package/src/apiKeys.spec.ts +0 -162
  252. package/src/apiKeys.ts +0 -220
  253. package/src/calculatePagination.ts +0 -34
  254. package/src/createHotUpdaterCore.ts +0 -246
  255. package/src/db/bundleRows.spec.ts +0 -164
  256. package/src/db/bundleRows.ts +0 -10
  257. package/src/db/createBundleDiff.spec.ts +0 -450
  258. package/src/db/createBundleDiff.ts +0 -364
  259. package/src/db/databasePluginCore.spec.ts +0 -62
  260. package/src/db/databasePluginCore.testFixtures.ts +0 -76
  261. package/src/db/databasePluginCore.ts +0 -185
  262. package/src/db/databasePluginUpdateCheck.bench.ts +0 -110
  263. package/src/db/fixedMigrator.spec.ts +0 -296
  264. package/src/db/fixedMigrator.ts +0 -147
  265. package/src/db/fixedMigratorMongo.spec.ts +0 -239
  266. package/src/db/fixedMigratorMongo.ts +0 -425
  267. package/src/db/fixedMigratorShared.ts +0 -36
  268. package/src/db/hotUpdaterSchema.ts +0 -5
  269. package/src/db/index.spec.ts +0 -1269
  270. package/src/db/index.ts +0 -47
  271. package/src/db/mongoMigrationExecution.ts +0 -23
  272. package/src/db/node-sqlite.d.ts +0 -25
  273. package/src/db/releaseCatalog.ts +0 -148
  274. package/src/db/schema/definitions.ts +0 -1
  275. package/src/db/schema/insightsCollation.ts +0 -21
  276. package/src/db/schema/mongodb.ts +0 -40
  277. package/src/db/schema/registry.ts +0 -55
  278. package/src/db/schema/sql.ts +0 -244
  279. package/src/db/schema/sqlOperations.ts +0 -63
  280. package/src/db/schema/types.ts +0 -1
  281. package/src/db/schemaGenerators.ts +0 -494
  282. package/src/db/schemaReadiness.ts +0 -34
  283. package/src/db/sqlMigrationExecution.spec.ts +0 -65
  284. package/src/db/sqlMigrationExecution.ts +0 -108
  285. package/src/db/types.spec.ts +0 -63
  286. package/src/db/types.ts +0 -228
  287. package/src/db/updateArtifacts.spec.ts +0 -359
  288. package/src/db/updateArtifacts.ts +0 -541
  289. package/src/handler-standalone.integration.spec.ts +0 -528
  290. package/src/handler.spec.ts +0 -190
  291. package/src/handler.testFixtures.ts +0 -30
  292. package/src/handler.ts +0 -245
  293. package/src/handlerAuth.integration.spec.ts +0 -33
  294. package/src/handlerBundleRoutes.ts +0 -259
  295. package/src/handlerErrors.ts +0 -7
  296. package/src/handlerManagement.spec.ts +0 -262
  297. package/src/handlerParameters.ts +0 -105
  298. package/src/handlerReleaseCatalogRoutes.ts +0 -154
  299. package/src/handlerReleaseManagementRoutes.ts +0 -213
  300. package/src/handlerTypes.ts +0 -96
  301. package/src/handlerVersionRoutes.ts +0 -12
  302. package/src/index.ts +0 -30
  303. package/src/insights/domain.ts +0 -103
  304. package/src/insights/errors.ts +0 -11
  305. package/src/insights/eventInput.ts +0 -225
  306. package/src/insights/insights.integration.spec.ts +0 -381
  307. package/src/insights/provider.spec.ts +0 -385
  308. package/src/insights/provider.ts +0 -591
  309. package/src/insights/queryInput.ts +0 -141
  310. package/src/insights/routes.ts +0 -104
  311. package/src/insights/types.ts +0 -55
  312. package/src/internalRouter.ts +0 -104
  313. package/src/node.spec.ts +0 -119
  314. package/src/node.ts +0 -111
  315. package/src/releaseCatalogRoutes.integration.spec.ts +0 -238
  316. package/src/runtime.spec.ts +0 -194
  317. package/src/runtime.testFixtures.ts +0 -71
  318. package/src/schema/dsl-all-versions.spec.ts +0 -37
  319. package/src/schema/dsl.ts +0 -187
  320. package/src/schema/index.ts +0 -10
  321. package/src/schema/settings.ts +0 -15
  322. package/src/schema/types.ts +0 -79
  323. package/src/schema/v1_0_0.spec.ts +0 -220
  324. package/src/schema/v1_0_0.ts +0 -529
  325. package/src/storageAccess.spec.ts +0 -152
  326. package/src/storageAccess.ts +0 -141
  327. package/src/types/index.ts +0 -34
  328. package/src/version.ts +0 -3
@@ -1,63 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
4
- import { isDatabasePlugin } from "./types";
5
-
6
- describe("isDatabasePlugin", () => {
7
- it("accepts a direct fixed-model plugin object", () => {
8
- const plugin = createInMemoryDatabasePlugin();
9
-
10
- const result = isDatabasePlugin(plugin);
11
-
12
- expect(result).toBe(true);
13
- });
14
-
15
- it("rejects a v1 factory and malformed required domains", () => {
16
- const plugin = createInMemoryDatabasePlugin();
17
- const factory = () => plugin;
18
- const malformedBundles = {
19
- ...plugin,
20
- models: {
21
- ...plugin.models,
22
- bundles: { ...plugin.models.bundles, findMany: null },
23
- },
24
- };
25
- const missingInsights = {
26
- ...plugin,
27
- models: { ...plugin.models, insights: undefined },
28
- };
29
- const malformedInsights = {
30
- ...plugin,
31
- models: {
32
- ...plugin.models,
33
- insights: { ...plugin.models.insights, listEvents: null },
34
- },
35
- };
36
- const malformedChannels = {
37
- ...plugin,
38
- models: {
39
- ...plugin.models,
40
- channels: { ...plugin.models.channels, delete: null },
41
- },
42
- };
43
- const malformedApiKeys = {
44
- ...plugin,
45
- models: {
46
- ...plugin.models,
47
- apiKeys: {
48
- ...plugin.models.apiKeys,
49
- revoke: null,
50
- },
51
- },
52
- };
53
- const malformedDispose = { ...plugin, dispose: null };
54
-
55
- expect(isDatabasePlugin(factory)).toBe(false);
56
- expect(isDatabasePlugin(malformedBundles)).toBe(false);
57
- expect(isDatabasePlugin(missingInsights)).toBe(false);
58
- expect(isDatabasePlugin(malformedInsights)).toBe(false);
59
- expect(isDatabasePlugin(malformedChannels)).toBe(false);
60
- expect(isDatabasePlugin(malformedApiKeys)).toBe(false);
61
- expect(isDatabasePlugin(malformedDispose)).toBe(false);
62
- });
63
- });
package/src/db/types.ts DELETED
@@ -1,228 +0,0 @@
1
- import type { ArtifactInfo, Bundle } from "@hot-updater/core";
2
- import type {
3
- ChannelDeleteInput,
4
- ChannelDeleteResult,
5
- ChannelInsertInput,
6
- ChannelInsertResult,
7
- ChannelRow,
8
- DatabaseCommit,
9
- DatabaseCommitResult,
10
- DatabasePlugin as DatabasePluginContract,
11
- ReleaseCatalogMutationPreflight,
12
- ReleaseCatalogMutationResult,
13
- ReleaseCatalogRebuildResult,
14
- ReleaseCatalogRow,
15
- ReleasePolicyPatch,
16
- ReleaseRow,
17
- } from "@hot-updater/plugin-core";
18
-
19
- import type { PaginatedResult } from "../types";
20
-
21
- export const sqlProviders = [
22
- "sqlite",
23
- "cockroachdb",
24
- "mysql",
25
- "postgresql",
26
- "mssql",
27
- ] as const;
28
-
29
- export const noSqlProviders = ["mongodb"] as const;
30
- export const providers = [...sqlProviders, ...noSqlProviders] as const;
31
-
32
- export type ORMProvider = (typeof providers)[number];
33
- export type ORMSQLProvider = (typeof sqlProviders)[number];
34
- export type RelationMode = "foreign-keys" | "fumadb";
35
-
36
- export interface MigrateOptions {
37
- mode?: "from-schema" | "from-database";
38
- updateSettings?: boolean;
39
- unsafe?: boolean;
40
- }
41
-
42
- export type MigrationOperation =
43
- | {
44
- type: "create-table";
45
- value: {
46
- ormName: string;
47
- columns: Record<string, { ormName: string; type: string }>;
48
- };
49
- }
50
- | { type: "custom"; description: string }
51
- | { type: "custom"; sql: string }
52
- | { type: "custom"; key: string; value: unknown };
53
-
54
- export interface MigrationResult {
55
- operations: MigrationOperation[];
56
- execute: () => Promise<void>;
57
- getSQL?: () => string;
58
- }
59
-
60
- export interface Migrator {
61
- getVersion: () => Promise<string | undefined>;
62
- getNameVariants: () => Promise<unknown>;
63
- next: () => Promise<{ version: string } | undefined>;
64
- previous: () => Promise<{ version: string } | undefined>;
65
- up: (options?: MigrateOptions) => Promise<MigrationResult>;
66
- down: (options?: MigrateOptions) => Promise<MigrationResult>;
67
- migrateTo: (
68
- version: string,
69
- options?: MigrateOptions,
70
- ) => Promise<MigrationResult>;
71
- migrateToLatest: (options?: MigrateOptions) => Promise<MigrationResult>;
72
- }
73
-
74
- export type SchemaGenerator = (
75
- version: string | "latest",
76
- name?: string,
77
- ) => {
78
- code: string;
79
- path: string;
80
- };
81
-
82
- export interface DatabaseAdapterCapabilities {
83
- adapterName?: string;
84
- provider?: ORMProvider;
85
- createMigrator?: () => Migrator;
86
- generateSchema?: SchemaGenerator;
87
- }
88
-
89
- export type DatabaseAdapterWithCapabilities = DatabasePluginContract &
90
- DatabaseAdapterCapabilities;
91
-
92
- export type DatabasePlugin = DatabaseAdapterWithCapabilities;
93
-
94
- export function isDatabasePlugin(plugin: unknown): plugin is DatabasePlugin {
95
- return (
96
- typeof plugin === "object" &&
97
- plugin !== null &&
98
- "name" in plugin &&
99
- typeof plugin.name === "string" &&
100
- "models" in plugin &&
101
- typeof plugin.models === "object" &&
102
- plugin.models !== null &&
103
- "bundles" in plugin.models &&
104
- typeof plugin.models.bundles === "object" &&
105
- plugin.models.bundles !== null &&
106
- "findById" in plugin.models.bundles &&
107
- typeof plugin.models.bundles.findById === "function" &&
108
- "findMany" in plugin.models.bundles &&
109
- typeof plugin.models.bundles.findMany === "function" &&
110
- "count" in plugin.models.bundles &&
111
- typeof plugin.models.bundles.count === "function" &&
112
- "bundlePatches" in plugin.models &&
113
- typeof plugin.models.bundlePatches === "object" &&
114
- plugin.models.bundlePatches !== null &&
115
- "findByBundleIds" in plugin.models.bundlePatches &&
116
- typeof plugin.models.bundlePatches.findByBundleIds === "function" &&
117
- "channels" in plugin.models &&
118
- typeof plugin.models.channels === "object" &&
119
- plugin.models.channels !== null &&
120
- "insert" in plugin.models.channels &&
121
- typeof plugin.models.channels.insert === "function" &&
122
- "list" in plugin.models.channels &&
123
- typeof plugin.models.channels.list === "function" &&
124
- "delete" in plugin.models.channels &&
125
- typeof plugin.models.channels.delete === "function" &&
126
- "insights" in plugin.models &&
127
- typeof plugin.models.insights === "object" &&
128
- plugin.models.insights !== null &&
129
- "record" in plugin.models.insights &&
130
- typeof plugin.models.insights.record === "function" &&
131
- "listEvents" in plugin.models.insights &&
132
- typeof plugin.models.insights.listEvents === "function" &&
133
- "findInstallations" in plugin.models.insights &&
134
- typeof plugin.models.insights.findInstallations === "function" &&
135
- "countEvents" in plugin.models.insights &&
136
- typeof plugin.models.insights.countEvents === "function" &&
137
- "countInstallations" in plugin.models.insights &&
138
- typeof plugin.models.insights.countInstallations === "function" &&
139
- "apiKeys" in plugin.models &&
140
- typeof plugin.models.apiKeys === "object" &&
141
- plugin.models.apiKeys !== null &&
142
- "create" in plugin.models.apiKeys &&
143
- typeof plugin.models.apiKeys.create === "function" &&
144
- "findByHash" in plugin.models.apiKeys &&
145
- typeof plugin.models.apiKeys.findByHash === "function" &&
146
- "list" in plugin.models.apiKeys &&
147
- typeof plugin.models.apiKeys.list === "function" &&
148
- "revoke" in plugin.models.apiKeys &&
149
- typeof plugin.models.apiKeys.revoke === "function" &&
150
- "commit" in plugin &&
151
- typeof plugin.commit === "function" &&
152
- (!("dispose" in plugin) ||
153
- plugin.dispose === undefined ||
154
- typeof plugin.dispose === "function")
155
- );
156
- }
157
-
158
- export function getSQLProvider(
159
- provider: ORMProvider | undefined,
160
- ): ORMSQLProvider | undefined {
161
- if (!provider) {
162
- return undefined;
163
- }
164
-
165
- return (sqlProviders as readonly string[]).includes(provider)
166
- ? (provider as ORMSQLProvider)
167
- : undefined;
168
- }
169
-
170
- export interface DatabaseAPI {
171
- getBundleById(id: string): Promise<Bundle | null>;
172
- getReleaseCatalog(
173
- input: import("./releaseCatalog").ReleaseCatalogRequest,
174
- ): Promise<import("@hot-updater/core").ReleaseCatalog | null>;
175
- getArtifactInfo(
176
- targetBundleId: string,
177
- currentBundleId: string,
178
- ): Promise<ArtifactInfo | null>;
179
- getReleaseById(id: string): Promise<ReleaseRow | null>;
180
- getReleasesByScope(input: {
181
- readonly scopeKey: string;
182
- readonly afterReleaseId?: string;
183
- readonly limit: number;
184
- }): Promise<readonly ReleaseRow[]>;
185
- getReleases(input: {
186
- readonly afterReleaseId?: string;
187
- readonly beforeReleaseId?: string;
188
- readonly bundleId?: string;
189
- readonly channelId?: string;
190
- readonly enabled?: boolean;
191
- readonly platform?: "ios" | "android";
192
- readonly targetAppVersion?: string;
193
- readonly limit: number;
194
- }): Promise<readonly ReleaseRow[]>;
195
- getReleaseCatalogByScopeKey(
196
- scopeKey: string,
197
- ): Promise<ReleaseCatalogRow | null>;
198
- getReleaseCatalogs(input: {
199
- readonly afterScopeKey?: string;
200
- readonly limit: number;
201
- }): Promise<readonly ReleaseCatalogRow[]>;
202
- updateReleasePolicy(input: {
203
- readonly expectedRevision?: number;
204
- readonly patch: ReleasePolicyPatch;
205
- readonly releaseId: string;
206
- }): Promise<ReleaseCatalogMutationResult>;
207
- preflightReleasePolicy(input: {
208
- readonly expectedRevision?: number;
209
- readonly patch: ReleasePolicyPatch;
210
- readonly releaseId: string;
211
- }): Promise<ReleaseCatalogMutationPreflight>;
212
- deleteRelease(input: {
213
- readonly expectedRevision?: number;
214
- readonly releaseId: string;
215
- }): Promise<ReleaseCatalogMutationResult>;
216
- rebuildReleaseCatalog(scopeKey: string): Promise<ReleaseCatalogRebuildResult>;
217
- commitDatabase(input: DatabaseCommit): Promise<DatabaseCommitResult>;
218
- getChannels(): Promise<readonly ChannelRow[]>;
219
- insertChannel(input: ChannelInsertInput): Promise<ChannelInsertResult>;
220
- deleteChannel(input: ChannelDeleteInput): Promise<ChannelDeleteResult>;
221
- getBundles(
222
- options: import("@hot-updater/plugin-core").DatabaseBundleQueryOptions,
223
- ): Promise<PaginatedResult>;
224
- insertBundle(bundle: Bundle): Promise<void>;
225
- insertBundles(bundles: readonly Bundle[]): Promise<void>;
226
- updateBundleById(bundleId: string, newBundle: Partial<Bundle>): Promise<void>;
227
- deleteBundleById(bundleId: string): Promise<void>;
228
- }
@@ -1,359 +0,0 @@
1
- import { NIL_UUID, type Bundle } from "@hot-updater/core";
2
- import { createDatabaseClient } from "@hot-updater/plugin-core";
3
- import { describe, expect, it, vi } from "vitest";
4
-
5
- import { createInMemoryDatabasePlugin } from "../../../test-utils/test/inMemoryDatabasePlugin";
6
- import { createArtifactResolver } from "./releaseCatalog";
7
- import { resolveManifestArtifacts } from "./updateArtifacts";
8
-
9
- type TestManifestAsset = {
10
- downloadByteSize?: unknown;
11
- downloadFileHash?: unknown;
12
- fileHash: string;
13
- };
14
-
15
- const CURRENT_BUNDLE_ID = "00000000-0000-0000-0000-000000000101";
16
- const TARGET_BUNDLE_ID = "00000000-0000-0000-0000-000000000102";
17
- const CURRENT_MANIFEST_URI = `s3://test-bucket/bundles/${CURRENT_BUNDLE_ID}/manifest.json`;
18
- const TARGET_MANIFEST_URI = `s3://test-bucket/bundles/${TARGET_BUNDLE_ID}/manifest.json`;
19
- const PATCH_STORAGE_URI = `s3://test-bucket/bundles/${TARGET_BUNDLE_ID}/patches/${CURRENT_BUNDLE_ID}/patch.bsdiff`;
20
- const VALID_DOWNLOAD_FILE_HASH = "a".repeat(64);
21
-
22
- const getUtf8ByteSize = (value: string) =>
23
- new TextEncoder().encode(value).byteLength;
24
-
25
- const createBundle = (
26
- id: string,
27
- archiveByteSize: number,
28
- overrides: Partial<Bundle> = {},
29
- ): Bundle => ({
30
- archiveByteSize,
31
- assetBaseStorageUri: "s3://test-bucket/assets",
32
- fileHash: `${id}-archive-hash`,
33
- gitCommitHash: null,
34
- id,
35
- manifestFileHash: `${id}-manifest-hash`,
36
- manifestStorageUri:
37
- id === CURRENT_BUNDLE_ID ? CURRENT_MANIFEST_URI : TARGET_MANIFEST_URI,
38
- platform: "ios",
39
- storageUri: `s3://test-bucket/bundles/${id}/bundle.zip`,
40
- ...overrides,
41
- });
42
-
43
- async function runScenario({
44
- archiveByteSize,
45
- archiveUrlUsable = true,
46
- assetPath = "index.ios.bundle",
47
- patchByteSize,
48
- resolveUrl,
49
- targetAsset,
50
- targetManifestSuffix = "",
51
- }: {
52
- archiveByteSize: number | ((manifestByteSize: number) => number);
53
- archiveUrlUsable?: boolean;
54
- assetPath?: string;
55
- patchByteSize?: unknown;
56
- resolveUrl?: (storageUri: string) => Promise<string | null>;
57
- targetAsset: TestManifestAsset;
58
- targetManifestSuffix?: string;
59
- }) {
60
- const currentManifestText = JSON.stringify({
61
- assets: {
62
- [assetPath]: {
63
- fileHash: "current-file-hash",
64
- },
65
- },
66
- bundleId: CURRENT_BUNDLE_ID,
67
- });
68
- const targetManifestText = `${JSON.stringify({
69
- assets: {
70
- [assetPath]: targetAsset,
71
- },
72
- bundleId: TARGET_BUNDLE_ID,
73
- })}${targetManifestSuffix}`;
74
- const manifestByteSize = getUtf8ByteSize(targetManifestText);
75
- const resolvedArchiveByteSize =
76
- typeof archiveByteSize === "function"
77
- ? archiveByteSize(manifestByteSize)
78
- : archiveByteSize;
79
- const hasPatch = patchByteSize !== undefined;
80
- const currentBundle = createBundle(CURRENT_BUNDLE_ID, 1_024);
81
- const targetBundle = createBundle(
82
- TARGET_BUNDLE_ID,
83
- resolvedArchiveByteSize,
84
- hasPatch
85
- ? {
86
- patches: [
87
- {
88
- baseBundleId: CURRENT_BUNDLE_ID,
89
- baseFileHash: "current-file-hash",
90
- byteSize: patchByteSize as number,
91
- patchFileHash: "patch-file-hash",
92
- patchStorageUri: PATCH_STORAGE_URI,
93
- },
94
- ],
95
- }
96
- : {},
97
- );
98
- const storageTexts = new Map([
99
- [CURRENT_MANIFEST_URI, currentManifestText],
100
- [TARGET_MANIFEST_URI, targetManifestText],
101
- ]);
102
- const resolveFileUrl = vi.fn(async (storageUri: string | null) => {
103
- if (!storageUri) return null;
104
- if (resolveUrl) return resolveUrl(storageUri);
105
- return `https://download.example.com/${encodeURIComponent(storageUri)}`;
106
- });
107
-
108
- const result = await resolveManifestArtifacts({
109
- archiveUrlUsable,
110
- currentBundle,
111
- readStorageText: async (storageUri) => storageTexts.get(storageUri) ?? null,
112
- resolveFileUrl,
113
- targetBundle,
114
- });
115
-
116
- return {
117
- manifestByteSize,
118
- resolveFileUrl,
119
- result,
120
- };
121
- }
122
-
123
- describe("resolveManifestArtifacts", () => {
124
- it("uses raw UTF-8 manifest bytes and selects archive at equal size", async () => {
125
- const { resolveFileUrl, result } = await runScenario({
126
- archiveByteSize: (manifestByteSize) => manifestByteSize + 7,
127
- assetPath: "assets/한글.png",
128
- targetAsset: {
129
- downloadByteSize: 7,
130
- fileHash: "target-file-hash",
131
- },
132
- targetManifestSuffix: "\n",
133
- });
134
-
135
- expect(result).toBeNull();
136
- expect(resolveFileUrl).not.toHaveBeenCalled();
137
- });
138
-
139
- it("accepts a valid download hash and size pair on a raw asset", async () => {
140
- const { resolveFileUrl, result } = await runScenario({
141
- archiveByteSize: (manifestByteSize) => manifestByteSize + 7,
142
- assetPath: "assets/logo.png",
143
- targetAsset: {
144
- downloadByteSize: 7,
145
- downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
146
- fileHash: "target-file-hash",
147
- },
148
- });
149
-
150
- expect(result).toBeNull();
151
- expect(resolveFileUrl).not.toHaveBeenCalled();
152
- });
153
-
154
- it("treats an invalid present hash on a raw asset as unknown cost", async () => {
155
- const { resolveFileUrl, result } = await runScenario({
156
- archiveByteSize: 1,
157
- assetPath: "assets/logo.png",
158
- targetAsset: {
159
- downloadByteSize: 100,
160
- downloadFileHash: "INVALID",
161
- fileHash: "target-file-hash",
162
- },
163
- });
164
-
165
- expect(result).not.toBeNull();
166
- expect(resolveFileUrl).toHaveBeenCalledWith(
167
- "s3://test-bucket/assets/sha256/ta/target-file-hash.png",
168
- );
169
- });
170
-
171
- it.each([
172
- ["missing", undefined],
173
- ["invalid", "INVALID"],
174
- ])(
175
- "treats a Brotli asset as unknown cost when its download hash is %s",
176
- async (_label, downloadFileHash) => {
177
- const { resolveFileUrl, result } = await runScenario({
178
- archiveByteSize: 1,
179
- targetAsset: {
180
- downloadByteSize: 100,
181
- downloadFileHash,
182
- fileHash: "target-file-hash",
183
- },
184
- });
185
-
186
- expect(result).not.toBeNull();
187
- expect(resolveFileUrl).toHaveBeenCalledWith(
188
- "s3://test-bucket/assets/sha256/ta/target-file-hash.br",
189
- );
190
- },
191
- );
192
-
193
- it.each([
194
- ["keeps", 9, true],
195
- ["omits", 10, false],
196
- ])(
197
- "%s a %i-byte patch when the file is 10 bytes",
198
- async (_action, patchByteSize, expectsPatch) => {
199
- const { resolveFileUrl, result } = await runScenario({
200
- archiveByteSize: (manifestByteSize) => manifestByteSize + 1_000,
201
- patchByteSize,
202
- targetAsset: {
203
- downloadByteSize: 10,
204
- downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
205
- fileHash: "target-file-hash",
206
- },
207
- });
208
-
209
- expect(result?.changedAssets?.["index.ios.bundle"]?.patch).toEqual(
210
- expectsPatch
211
- ? expect.objectContaining({ patchUrl: expect.any(String) })
212
- : undefined,
213
- );
214
- expect(resolveFileUrl).toHaveBeenCalledWith(
215
- `s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`,
216
- );
217
- expect(resolveFileUrl).toHaveBeenCalledWith(PATCH_STORAGE_URI);
218
- },
219
- );
220
-
221
- it("keeps a larger patch when the file and archive URLs are unavailable", async () => {
222
- const fileStorageUri = `s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`;
223
- const { result } = await runScenario({
224
- archiveByteSize: 1,
225
- archiveUrlUsable: false,
226
- patchByteSize: 100,
227
- resolveUrl: async (storageUri) =>
228
- storageUri === fileStorageUri
229
- ? null
230
- : `https://download.example.com/${encodeURIComponent(storageUri)}`,
231
- targetAsset: {
232
- downloadByteSize: 50,
233
- downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
234
- fileHash: "target-file-hash",
235
- },
236
- });
237
-
238
- expect(result?.changedAssets?.["index.ios.bundle"]).toEqual({
239
- fileHash: "target-file-hash",
240
- patch: expect.objectContaining({
241
- patchUrl: expect.any(String),
242
- }),
243
- });
244
- });
245
-
246
- it("recalculates from the file when an unknown-size patch URL is unavailable", async () => {
247
- const { resolveFileUrl, result } = await runScenario({
248
- archiveByteSize: (manifestByteSize) => manifestByteSize + 50,
249
- patchByteSize: Number.NaN,
250
- resolveUrl: async (storageUri) =>
251
- storageUri === PATCH_STORAGE_URI
252
- ? null
253
- : `https://download.example.com/${encodeURIComponent(storageUri)}`,
254
- targetAsset: {
255
- downloadByteSize: 100,
256
- downloadFileHash: VALID_DOWNLOAD_FILE_HASH,
257
- fileHash: "target-file-hash",
258
- },
259
- });
260
-
261
- expect(result).toBeNull();
262
- expect(resolveFileUrl).toHaveBeenCalledWith(PATCH_STORAGE_URI);
263
- expect(resolveFileUrl).toHaveBeenCalledWith(
264
- `s3://test-bucket/assets/sha256/aa/${VALID_DOWNLOAD_FILE_HASH}.br`,
265
- );
266
- });
267
-
268
- it("recalculates from a known patch when the file fallback cost is unknown", async () => {
269
- const { result } = await runScenario({
270
- archiveByteSize: (manifestByteSize) => manifestByteSize + 50,
271
- patchByteSize: 100,
272
- targetAsset: {
273
- downloadByteSize: 100,
274
- fileHash: "target-file-hash",
275
- },
276
- });
277
-
278
- expect(result).toBeNull();
279
- });
280
-
281
- it("keeps the manifest path when safe addition overflows", async () => {
282
- const { result } = await runScenario({
283
- archiveByteSize: 1,
284
- assetPath: "assets/logo.png",
285
- targetAsset: {
286
- downloadByteSize: Number.MAX_SAFE_INTEGER,
287
- fileHash: "target-file-hash",
288
- },
289
- });
290
-
291
- expect(result).not.toBeNull();
292
- });
293
-
294
- it("keeps the manifest path when a byte size is invalid", async () => {
295
- const { result } = await runScenario({
296
- archiveByteSize: 1,
297
- assetPath: "assets/logo.png",
298
- targetAsset: {
299
- downloadByteSize: -1,
300
- fileHash: "target-file-hash",
301
- },
302
- });
303
-
304
- expect(result).not.toBeNull();
305
- });
306
-
307
- it("does not select archive when its URL is unavailable", async () => {
308
- const { result } = await runScenario({
309
- archiveByteSize: 1,
310
- archiveUrlUsable: false,
311
- assetPath: "assets/logo.png",
312
- targetAsset: {
313
- downloadByteSize: 100,
314
- fileHash: "target-file-hash",
315
- },
316
- });
317
-
318
- expect(result).not.toBeNull();
319
- });
320
- });
321
-
322
- describe("createArtifactResolver", () => {
323
- it("returns usable manifest artifacts when the archive URL is null", async () => {
324
- const databasePlugin = createInMemoryDatabasePlugin();
325
- const database = createDatabaseClient(databasePlugin);
326
- const targetManifestText = JSON.stringify({
327
- assets: {
328
- "assets/logo.png": {
329
- downloadByteSize: 100,
330
- fileHash: "target-file-hash",
331
- },
332
- },
333
- bundleId: TARGET_BUNDLE_ID,
334
- });
335
- const targetBundle = createBundle(TARGET_BUNDLE_ID, 1);
336
- await database.insertBundle(targetBundle);
337
-
338
- const resolver = createArtifactResolver({
339
- database: databasePlugin,
340
- readStorageText: async (storageUri) =>
341
- storageUri === TARGET_MANIFEST_URI ? targetManifestText : null,
342
- resolveFileUrl: async (storageUri) =>
343
- storageUri === targetBundle.storageUri
344
- ? null
345
- : `https://download.example.com/${encodeURIComponent(storageUri ?? "")}`,
346
- });
347
-
348
- await expect(resolver(TARGET_BUNDLE_ID, NIL_UUID)).resolves.toMatchObject({
349
- changedAssets: {
350
- "assets/logo.png": {
351
- file: { url: expect.any(String) },
352
- fileHash: "target-file-hash",
353
- },
354
- },
355
- fileUrl: null,
356
- manifestUrl: expect.any(String),
357
- });
358
- });
359
- });