@hot-updater/server 0.36.7 → 1.0.0-rc.1

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 (291) hide show
  1. package/dist/adapters/databaseConstraintErrors.cjs +23 -0
  2. package/dist/adapters/databaseConstraintErrors.mjs +21 -0
  3. package/dist/adapters/databasePluginUtils.cjs +117 -0
  4. package/dist/adapters/databasePluginUtils.mjs +106 -0
  5. package/dist/adapters/drizzle.cjs +53 -176
  6. package/dist/adapters/drizzle.d.cts +6 -4
  7. package/dist/adapters/drizzle.d.mts +6 -4
  8. package/dist/adapters/drizzle.mjs +54 -177
  9. package/dist/adapters/drizzleCrud.cjs +250 -0
  10. package/dist/adapters/drizzleCrud.mjs +249 -0
  11. package/dist/adapters/drizzleLazyDB.cjs +84 -36
  12. package/dist/adapters/drizzleLazyDB.mjs +84 -36
  13. package/dist/adapters/drizzleQuery.cjs +68 -0
  14. package/dist/adapters/drizzleQuery.mjs +67 -0
  15. package/dist/adapters/kysely.cjs +18 -138
  16. package/dist/adapters/kysely.d.cts +3 -12
  17. package/dist/adapters/kysely.d.mts +3 -12
  18. package/dist/adapters/kysely.mjs +19 -139
  19. package/dist/adapters/kyselyCrud.cjs +254 -0
  20. package/dist/adapters/kyselyCrud.mjs +253 -0
  21. package/dist/adapters/kyselyQuery.cjs +56 -0
  22. package/dist/adapters/kyselyQuery.mjs +55 -0
  23. package/dist/adapters/mongodb.cjs +21 -174
  24. package/dist/adapters/mongodb.d.cts +3 -2
  25. package/dist/adapters/mongodb.d.mts +3 -2
  26. package/dist/adapters/mongodb.mjs +21 -174
  27. package/dist/adapters/mongodbCollections.cjs +36 -0
  28. package/dist/adapters/mongodbCollections.mjs +30 -0
  29. package/dist/adapters/mongodbQuery.cjs +77 -0
  30. package/dist/adapters/mongodbQuery.mjs +70 -0
  31. package/dist/adapters/mongodbReads.cjs +148 -0
  32. package/dist/adapters/mongodbReads.mjs +147 -0
  33. package/dist/adapters/mongodbWrites.cjs +134 -0
  34. package/dist/adapters/mongodbWrites.mjs +133 -0
  35. package/dist/adapters/prisma.cjs +205 -180
  36. package/dist/adapters/prisma.d.cts +3 -3
  37. package/dist/adapters/prisma.d.mts +3 -3
  38. package/dist/adapters/prisma.mjs +206 -181
  39. package/dist/adapters/prismaQuery.cjs +58 -0
  40. package/dist/adapters/prismaQuery.mjs +56 -0
  41. package/dist/adapters/prismaRows.cjs +198 -0
  42. package/dist/adapters/prismaRows.mjs +188 -0
  43. package/dist/apiKeys.cjs +139 -0
  44. package/dist/apiKeys.d.cts +50 -0
  45. package/dist/apiKeys.d.mts +50 -0
  46. package/dist/apiKeys.mjs +133 -0
  47. package/dist/createHotUpdaterCore.cjs +48 -26
  48. package/dist/createHotUpdaterCore.d.cts +49 -17
  49. package/dist/createHotUpdaterCore.d.mts +49 -17
  50. package/dist/createHotUpdaterCore.mjs +51 -29
  51. package/dist/db/createBundleDiff.cjs +45 -68
  52. package/dist/db/createBundleDiff.d.cts +3 -3
  53. package/dist/db/createBundleDiff.d.mts +3 -3
  54. package/dist/db/createBundleDiff.mjs +47 -68
  55. package/dist/db/databasePluginCore.cjs +138 -0
  56. package/dist/db/databasePluginCore.mjs +137 -0
  57. package/dist/db/fixedMigrator.cjs +36 -93
  58. package/dist/db/fixedMigrator.mjs +36 -93
  59. package/dist/db/fixedMigratorMongo.cjs +319 -0
  60. package/dist/db/fixedMigratorMongo.mjs +319 -0
  61. package/dist/db/fixedMigratorShared.cjs +23 -0
  62. package/dist/db/fixedMigratorShared.mjs +18 -0
  63. package/dist/db/mongoMigrationExecution.cjs +11 -0
  64. package/dist/db/mongoMigrationExecution.mjs +11 -0
  65. package/dist/db/releaseCatalog.cjs +66 -0
  66. package/dist/db/releaseCatalog.d.cts +17 -0
  67. package/dist/db/releaseCatalog.d.mts +17 -0
  68. package/dist/db/releaseCatalog.mjs +64 -0
  69. package/dist/db/schema/mongodb.cjs +14 -6
  70. package/dist/db/schema/mongodb.mjs +14 -6
  71. package/dist/db/schema/registry.cjs +0 -2
  72. package/dist/db/schema/registry.mjs +1 -2
  73. package/dist/db/schema/sql.cjs +31 -14
  74. package/dist/db/schema/sql.mjs +32 -13
  75. package/dist/db/schema/sqlOperations.cjs +4 -4
  76. package/dist/db/schema/sqlOperations.mjs +5 -5
  77. package/dist/db/schemaGenerators.cjs +52 -18
  78. package/dist/db/schemaGenerators.mjs +52 -18
  79. package/dist/db/schemaReadiness.cjs +4 -3
  80. package/dist/db/schemaReadiness.mjs +4 -3
  81. package/dist/db/sqlMigrationExecution.cjs +67 -0
  82. package/dist/db/sqlMigrationExecution.mjs +66 -0
  83. package/dist/db/types.cjs +2 -6
  84. package/dist/db/types.d.cts +60 -16
  85. package/dist/db/types.d.mts +60 -16
  86. package/dist/db/types.mjs +3 -6
  87. package/dist/db/updateArtifacts.cjs +114 -60
  88. package/dist/db/updateArtifacts.mjs +117 -62
  89. package/dist/handler.cjs +108 -282
  90. package/dist/handler.d.cts +3 -46
  91. package/dist/handler.d.mts +3 -46
  92. package/dist/handler.mjs +107 -281
  93. package/dist/handlerBundleRoutes.cjs +155 -0
  94. package/dist/handlerBundleRoutes.mjs +155 -0
  95. package/dist/handlerErrors.cjs +9 -0
  96. package/dist/handlerErrors.mjs +9 -0
  97. package/dist/handlerParameters.cjs +39 -0
  98. package/dist/handlerParameters.mjs +34 -0
  99. package/dist/handlerReleaseCatalogRoutes.cjs +111 -0
  100. package/dist/handlerReleaseCatalogRoutes.mjs +110 -0
  101. package/dist/handlerReleaseManagementRoutes.cjs +125 -0
  102. package/dist/handlerReleaseManagementRoutes.mjs +124 -0
  103. package/dist/handlerTypes.d.cts +63 -0
  104. package/dist/handlerTypes.d.mts +63 -0
  105. package/dist/handlerVersionRoutes.cjs +10 -0
  106. package/dist/handlerVersionRoutes.d.cts +4 -0
  107. package/dist/handlerVersionRoutes.d.mts +4 -0
  108. package/dist/handlerVersionRoutes.mjs +9 -0
  109. package/dist/index.cjs +10 -1
  110. package/dist/index.d.cts +9 -3
  111. package/dist/index.d.mts +9 -3
  112. package/dist/index.mjs +5 -2
  113. package/dist/insights/bounded/activeOverview.cjs +87 -0
  114. package/dist/insights/bounded/activeOverview.mjs +85 -0
  115. package/dist/insights/bounded/installationSearch.cjs +42 -0
  116. package/dist/insights/bounded/installationSearch.mjs +42 -0
  117. package/dist/insights/bounded/persistence.cjs +39 -0
  118. package/dist/insights/bounded/persistence.mjs +38 -0
  119. package/dist/insights/bounded/provider.cjs +170 -0
  120. package/dist/insights/bounded/provider.d.cts +7 -0
  121. package/dist/insights/bounded/provider.d.mts +7 -0
  122. package/dist/insights/bounded/provider.mjs +170 -0
  123. package/dist/insights/bounded/scan.cjs +144 -0
  124. package/dist/insights/bounded/scan.mjs +138 -0
  125. package/dist/insights/domain.d.cts +121 -0
  126. package/dist/insights/domain.d.mts +121 -0
  127. package/dist/insights/errors.cjs +22 -0
  128. package/dist/insights/errors.mjs +20 -0
  129. package/dist/insights/eventInput.cjs +111 -0
  130. package/dist/insights/eventInput.mjs +111 -0
  131. package/dist/insights/persistence.d.cts +6 -0
  132. package/dist/insights/persistence.d.mts +6 -0
  133. package/dist/insights/queryInput.cjs +58 -0
  134. package/dist/insights/queryInput.mjs +55 -0
  135. package/dist/insights/routes.cjs +63 -0
  136. package/dist/insights/routes.mjs +61 -0
  137. package/dist/insights/types.d.cts +17 -0
  138. package/dist/insights/types.d.mts +17 -0
  139. package/dist/node.cjs +19 -12
  140. package/dist/node.d.cts +15 -10
  141. package/dist/node.d.mts +15 -10
  142. package/dist/node.mjs +19 -13
  143. package/dist/package.cjs +1 -1
  144. package/dist/package.mjs +1 -1
  145. package/dist/schema/dsl.cjs +19 -2
  146. package/dist/schema/dsl.mjs +17 -3
  147. package/dist/schema/index.cjs +1 -8
  148. package/dist/schema/index.mjs +2 -8
  149. package/dist/schema/types.cjs +3 -1
  150. package/dist/schema/types.mjs +3 -2
  151. package/dist/schema/v1_0_0.cjs +364 -0
  152. package/dist/schema/v1_0_0.mjs +357 -0
  153. package/dist/storageAccess.cjs +69 -25
  154. package/dist/storageAccess.mjs +68 -25
  155. package/dist/types/index.d.cts +4 -3
  156. package/dist/types/index.d.mts +5 -4
  157. package/package.json +8 -7
  158. package/src/adapters/databaseConstraintErrors.ts +25 -0
  159. package/src/adapters/databasePluginTestDatabase.ts +106 -0
  160. package/src/adapters/databasePluginUtils.spec.ts +29 -0
  161. package/src/adapters/databasePluginUtils.ts +214 -0
  162. package/src/adapters/drizzle.spec.ts +208 -47
  163. package/src/adapters/drizzle.ts +106 -293
  164. package/src/adapters/drizzleCrud.ts +419 -0
  165. package/src/adapters/drizzleLazyDB.ts +206 -100
  166. package/src/adapters/drizzleQuery.ts +164 -0
  167. package/src/adapters/kysely.spec.ts +126 -88
  168. package/src/adapters/kysely.ts +76 -334
  169. package/src/adapters/kyselyCrud.ts +588 -0
  170. package/src/adapters/kyselyQuery.ts +128 -0
  171. package/src/adapters/mongodb.spec.ts +141 -0
  172. package/src/adapters/mongodb.ts +60 -288
  173. package/src/adapters/mongodbCollections.ts +62 -0
  174. package/src/adapters/mongodbQuery.ts +226 -0
  175. package/src/adapters/mongodbReads.ts +311 -0
  176. package/src/adapters/mongodbRows.spec.ts +64 -0
  177. package/src/adapters/mongodbRows.ts +118 -0
  178. package/src/adapters/mongodbTestClient.ts +342 -0
  179. package/src/adapters/mongodbTestFilter.ts +166 -0
  180. package/src/adapters/mongodbWrites.ts +260 -0
  181. package/src/adapters/prisma.spec.ts +196 -0
  182. package/src/adapters/prisma.ts +417 -292
  183. package/src/adapters/prismaQuery.ts +129 -0
  184. package/src/adapters/prismaRows.spec.ts +98 -0
  185. package/src/adapters/prismaRows.ts +301 -0
  186. package/src/adapters/prismaTestClient.ts +396 -0
  187. package/src/apiKeys.integration.spec.ts +192 -0
  188. package/src/apiKeys.spec.ts +162 -0
  189. package/src/apiKeys.ts +220 -0
  190. package/src/createHotUpdaterCore.ts +164 -100
  191. package/src/db/bundleRows.spec.ts +164 -0
  192. package/src/db/bundleRows.ts +10 -140
  193. package/src/db/createBundleDiff.spec.ts +172 -127
  194. package/src/db/createBundleDiff.ts +91 -110
  195. package/src/db/databasePluginCore.spec.ts +62 -0
  196. package/src/db/databasePluginCore.testFixtures.ts +76 -0
  197. package/src/db/databasePluginCore.ts +185 -0
  198. package/src/db/databasePluginUpdateCheck.bench.ts +107 -0
  199. package/src/db/fixedMigrator.spec.ts +184 -42
  200. package/src/db/fixedMigrator.ts +64 -205
  201. package/src/db/fixedMigratorMongo.spec.ts +192 -0
  202. package/src/db/fixedMigratorMongo.ts +425 -0
  203. package/src/db/fixedMigratorShared.ts +36 -0
  204. package/src/db/hotUpdaterSchema.ts +0 -1
  205. package/src/db/index.spec.ts +333 -1025
  206. package/src/db/mongoMigrationExecution.ts +23 -0
  207. package/src/db/node-sqlite.d.ts +25 -0
  208. package/src/db/releaseCatalog.ts +148 -0
  209. package/src/db/schema/mongodb.ts +20 -6
  210. package/src/db/schema/sql.ts +52 -11
  211. package/src/db/schema/sqlOperations.ts +5 -4
  212. package/src/db/schemaGenerators.ts +107 -23
  213. package/src/db/schemaReadiness.ts +2 -1
  214. package/src/db/sqlMigrationExecution.spec.ts +65 -0
  215. package/src/db/sqlMigrationExecution.ts +108 -0
  216. package/src/db/types.spec.ts +55 -0
  217. package/src/db/types.ts +129 -65
  218. package/src/db/updateArtifacts.spec.ts +359 -0
  219. package/src/db/updateArtifacts.ts +290 -126
  220. package/src/handler-standalone.integration.spec.ts +401 -364
  221. package/src/handler.spec.ts +137 -582
  222. package/src/handler.testFixtures.ts +30 -0
  223. package/src/handler.ts +218 -616
  224. package/src/handlerAuth.integration.spec.ts +33 -0
  225. package/src/handlerBundleRoutes.ts +259 -0
  226. package/src/handlerErrors.ts +7 -0
  227. package/src/handlerManagement.spec.ts +262 -0
  228. package/src/handlerParameters.ts +105 -0
  229. package/src/handlerReleaseCatalogRoutes.ts +154 -0
  230. package/src/handlerReleaseManagementRoutes.ts +213 -0
  231. package/src/handlerTypes.ts +96 -0
  232. package/src/handlerVersionRoutes.ts +12 -0
  233. package/src/index.ts +22 -2
  234. package/src/insights/bounded/activeOverview.spec.ts +189 -0
  235. package/src/insights/bounded/activeOverview.ts +148 -0
  236. package/src/insights/bounded/installationSearch.spec.ts +130 -0
  237. package/src/insights/bounded/installationSearch.ts +69 -0
  238. package/src/insights/bounded/persistence.ts +43 -0
  239. package/src/insights/bounded/provider.spec.ts +219 -0
  240. package/src/insights/bounded/provider.ts +229 -0
  241. package/src/insights/bounded/scan.ts +235 -0
  242. package/src/insights/domain.ts +139 -0
  243. package/src/insights/errors.ts +18 -0
  244. package/src/insights/eventInput.ts +168 -0
  245. package/src/insights/insights.integration.spec.ts +144 -0
  246. package/src/insights/persistence.ts +10 -0
  247. package/src/insights/queryInput.ts +102 -0
  248. package/src/insights/routes.ts +123 -0
  249. package/src/insights/types.ts +44 -0
  250. package/src/node.spec.ts +79 -10
  251. package/src/node.ts +20 -17
  252. package/src/releaseCatalogRoutes.integration.spec.ts +238 -0
  253. package/src/runtime.spec.ts +126 -959
  254. package/src/runtime.testFixtures.ts +71 -0
  255. package/src/schema/dsl-all-versions.spec.ts +26 -17
  256. package/src/schema/dsl.ts +41 -2
  257. package/src/schema/index.ts +3 -9
  258. package/src/schema/types.ts +9 -3
  259. package/src/schema/v1_0_0.spec.ts +146 -0
  260. package/src/schema/v1_0_0.ts +465 -0
  261. package/src/storageAccess.spec.ts +127 -32
  262. package/src/storageAccess.ts +106 -55
  263. package/src/types/index.ts +2 -1
  264. package/dist/db/bundleRows.cjs +0 -82
  265. package/dist/db/bundleRows.d.cts +0 -33
  266. package/dist/db/bundleRows.d.mts +0 -33
  267. package/dist/db/bundleRows.mjs +0 -79
  268. package/dist/db/pluginCore.cjs +0 -242
  269. package/dist/db/pluginCore.mjs +0 -241
  270. package/dist/db/schema/sqlMigrations.cjs +0 -74
  271. package/dist/db/schema/sqlMigrations.mjs +0 -73
  272. package/dist/db/schemaEnhancements.cjs +0 -20
  273. package/dist/db/schemaEnhancements.mjs +0 -19
  274. package/dist/route.cjs +0 -7
  275. package/dist/route.mjs +0 -7
  276. package/dist/schema/v0_21_0.cjs +0 -38
  277. package/dist/schema/v0_21_0.mjs +0 -37
  278. package/dist/schema/v0_29_0.cjs +0 -45
  279. package/dist/schema/v0_29_0.mjs +0 -44
  280. package/dist/schema/v0_31_0.cjs +0 -82
  281. package/dist/schema/v0_31_0.mjs +0 -80
  282. package/src/db/pluginCore.spec.ts +0 -1095
  283. package/src/db/pluginCore.ts +0 -475
  284. package/src/db/pluginUpdateCheck.bench.ts +0 -254
  285. package/src/db/schema/sqlMigrations.ts +0 -219
  286. package/src/db/schemaEnhancements.ts +0 -55
  287. package/src/route.ts +0 -7
  288. package/src/schema/v0_21_0.ts +0 -52
  289. package/src/schema/v0_29_0.ts +0 -62
  290. package/src/schema/v0_31_0.spec.ts +0 -73
  291. package/src/schema/v0_31_0.ts +0 -120
@@ -0,0 +1,465 @@
1
+ import {
2
+ bool,
3
+ check,
4
+ column,
5
+ foreignKey,
6
+ float,
7
+ idColumn,
8
+ index,
9
+ integer,
10
+ json,
11
+ largeString,
12
+ relation,
13
+ schema,
14
+ stringColumn,
15
+ table,
16
+ uniqueIndex,
17
+ uuid,
18
+ varchar,
19
+ } from "./dsl";
20
+ import { createSettingsTable } from "./settings";
21
+ import { HOT_UPDATER_SETTINGS_TABLE } from "./types";
22
+
23
+ const channelIdentityCollations = {
24
+ mysql: "utf8mb4_bin",
25
+ mssql: "Latin1_General_100_BIN2_SC",
26
+ sqlite: "binary",
27
+ } as const;
28
+
29
+ const catalogKeyCollations = {
30
+ mysql: "ascii_bin",
31
+ mssql: "Latin1_General_100_BIN2",
32
+ sqlite: "binary",
33
+ } as const;
34
+
35
+ export const channelsV100 = table(
36
+ "channels",
37
+ {
38
+ id: idColumn("id", varchar(255)).collate(channelIdentityCollations),
39
+ name: column("name", varchar(255)).collate(channelIdentityCollations),
40
+ },
41
+ {
42
+ indexes: [uniqueIndex("channels_name_key", ["name"])],
43
+ checks: [
44
+ check({
45
+ name: "channels_id_length_check",
46
+ expression: "char_length(id) between 1 and 255",
47
+ providerExpressions: {
48
+ mssql:
49
+ "len(id collate Latin1_General_100_BIN2_SC + N'#') - 1 between 1 and 255",
50
+ sqlite: "length(id) between 1 and 255",
51
+ },
52
+ sqliteInline: true,
53
+ }),
54
+ check({
55
+ name: "channels_name_length_check",
56
+ expression: "char_length(name) between 1 and 255",
57
+ providerExpressions: {
58
+ mssql:
59
+ "len(name collate Latin1_General_100_BIN2_SC + N'#') - 1 between 1 and 255",
60
+ sqlite: "length(name) between 1 and 255",
61
+ },
62
+ sqliteInline: true,
63
+ }),
64
+ ],
65
+ },
66
+ );
67
+
68
+ export const bundlePatchesV100 = table(
69
+ "bundle_patches",
70
+ {
71
+ id: idColumn("id", varchar(255)),
72
+ bundle_id: uuid("bundle_id"),
73
+ base_bundle_id: uuid("base_bundle_id"),
74
+ base_file_hash: column("base_file_hash", "string"),
75
+ patch_file_hash: column("patch_file_hash", "string"),
76
+ patch_storage_uri: column("patch_storage_uri", "string"),
77
+ byte_size: float("byte_size"),
78
+ order_index: integer("order_index").defaultTo(0),
79
+ },
80
+ {
81
+ indexes: [
82
+ index("bundle_patches_bundle_id_idx", ["bundle_id"]),
83
+ index("bundle_patches_base_bundle_id_idx", ["base_bundle_id"]),
84
+ ],
85
+ foreignKeys: [
86
+ foreignKey("bundle_patches_bundle_id_fk", ["bundle_id"], "bundles", [
87
+ "id",
88
+ ]),
89
+ foreignKey(
90
+ "bundle_patches_base_bundle_id_fk",
91
+ ["base_bundle_id"],
92
+ "bundles",
93
+ ["id"],
94
+ ),
95
+ ],
96
+ relations: [
97
+ relation({
98
+ name: "bundle",
99
+ fieldName: "patches",
100
+ targetFieldName: "bundle",
101
+ relationName: "bundle_patches_bundles_patches",
102
+ columns: ["bundle_id"],
103
+ referencedTable: "bundles",
104
+ referencedColumns: ["id"],
105
+ }),
106
+ relation({
107
+ name: "baseBundle",
108
+ fieldName: "baseForPatches",
109
+ targetFieldName: "baseBundle",
110
+ relationName: "bundle_patches_bundles_baseForPatches",
111
+ columns: ["base_bundle_id"],
112
+ referencedTable: "bundles",
113
+ referencedColumns: ["id"],
114
+ }),
115
+ ],
116
+ checks: [
117
+ check({
118
+ name: "bundle_patches_byte_size_check",
119
+ expression: "byte_size >= 0 and byte_size <= 9007199254740991",
120
+ sqliteInline: true,
121
+ }),
122
+ ],
123
+ },
124
+ );
125
+
126
+ export const apiKeysV100 = table(
127
+ "api_keys",
128
+ {
129
+ id: idColumn("id", varchar(255)),
130
+ hash: stringColumn("hash"),
131
+ name: stringColumn("name"),
132
+ prefix: stringColumn("prefix"),
133
+ role: stringColumn("role"),
134
+ created_at_ms: float("created_at_ms"),
135
+ revoked_at_ms: float("revoked_at_ms").nullable(),
136
+ },
137
+ {
138
+ indexes: [
139
+ uniqueIndex("api_keys_hash_key", ["hash"]),
140
+ index("api_keys_created_at_idx", ["created_at_ms", "id"]),
141
+ ],
142
+ checks: [
143
+ check({
144
+ name: "api_keys_role_check",
145
+ expression: "role = 'client'",
146
+ sqliteInline: true,
147
+ }),
148
+ check({
149
+ name: "api_keys_created_at_check",
150
+ expression: "created_at_ms >= 0",
151
+ sqliteInline: true,
152
+ }),
153
+ check({
154
+ name: "api_keys_revoked_at_check",
155
+ expression: "revoked_at_ms is null or revoked_at_ms >= 0",
156
+ sqliteInline: true,
157
+ }),
158
+ ],
159
+ },
160
+ );
161
+
162
+ export const bundlesV100 = table(
163
+ "bundles",
164
+ {
165
+ id: idColumn("id", "uuid"),
166
+ platform: stringColumn("platform"),
167
+ file_hash: stringColumn("file_hash"),
168
+ git_commit_hash: stringColumn("git_commit_hash").nullable(),
169
+ storage_uri: stringColumn("storage_uri"),
170
+ archive_byte_size: float("archive_byte_size"),
171
+ metadata: json("metadata").defaultTo({}),
172
+ manifest_storage_uri: stringColumn("manifest_storage_uri").nullable(),
173
+ manifest_file_hash: stringColumn("manifest_file_hash").nullable(),
174
+ asset_base_storage_uri: stringColumn("asset_base_storage_uri").nullable(),
175
+ },
176
+ {
177
+ indexes: [index("bundles_platform_idx", ["platform"], ["mongodb"])],
178
+ checks: [
179
+ check({
180
+ name: "bundles_archive_byte_size_check",
181
+ expression:
182
+ "archive_byte_size >= 0 and archive_byte_size <= 9007199254740991",
183
+ sqliteInline: true,
184
+ }),
185
+ ],
186
+ },
187
+ );
188
+
189
+ export const releasesV100 = table(
190
+ "releases",
191
+ {
192
+ id: idColumn("id", "uuid"),
193
+ revision: integer("revision"),
194
+ scope_key: column("scope_key", varchar(2048)).collate(catalogKeyCollations),
195
+ channel_id: column("channel_id", varchar(255)).collate(
196
+ channelIdentityCollations,
197
+ ),
198
+ platform: stringColumn("platform"),
199
+ kind: stringColumn("kind"),
200
+ bundle_id: column("bundle_id", "uuid").nullable(),
201
+ strategy: stringColumn("strategy"),
202
+ target_app_version: stringColumn("target_app_version").nullable(),
203
+ fingerprint_hash: stringColumn("fingerprint_hash").nullable(),
204
+ enabled: bool("enabled"),
205
+ should_force_update: bool("should_force_update"),
206
+ message: stringColumn("message").nullable(),
207
+ rollout_cohort_count: integer("rollout_cohort_count").defaultTo(1000),
208
+ target_cohorts: json("target_cohorts").defaultTo([]),
209
+ operation: stringColumn("operation"),
210
+ source_release_id: column("source_release_id", "uuid").nullable(),
211
+ created_at_ms: float("created_at_ms"),
212
+ updated_at_ms: float("updated_at_ms"),
213
+ },
214
+ {
215
+ indexes: [
216
+ index("releases_scope_order_idx", ["scope_key", "id"]),
217
+ index("releases_channel_platform_order_idx", [
218
+ "channel_id",
219
+ "platform",
220
+ "id",
221
+ ]),
222
+ index("releases_bundle_id_idx", ["bundle_id"]),
223
+ index("releases_fingerprint_hash_idx", ["fingerprint_hash"]),
224
+ index("releases_enabled_idx", ["enabled"]),
225
+ ],
226
+ checks: [
227
+ check({
228
+ name: "releases_revision_check",
229
+ expression: "revision >= 1",
230
+ sqliteInline: true,
231
+ }),
232
+ check({
233
+ name: "releases_kind_bundle_check",
234
+ expression:
235
+ "(kind = 'BUNDLE' and bundle_id is not null) or (kind = 'EMBEDDED' and bundle_id is null)",
236
+ sqliteInline: true,
237
+ }),
238
+ check({
239
+ name: "releases_strategy_target_check",
240
+ expression:
241
+ "(strategy = 'APP_VERSION' and target_app_version is not null and fingerprint_hash is null) or (strategy = 'FINGERPRINT' and target_app_version is null and fingerprint_hash is not null)",
242
+ sqliteInline: true,
243
+ }),
244
+ check({
245
+ name: "releases_rollout_cohort_count_check",
246
+ expression:
247
+ "rollout_cohort_count >= 0 and rollout_cohort_count <= 1000",
248
+ sqliteInline: true,
249
+ }),
250
+ check({
251
+ name: "releases_operation_check",
252
+ expression: "operation in ('DEPLOY', 'PROMOTE', 'ROLLBACK')",
253
+ sqliteInline: true,
254
+ }),
255
+ ],
256
+ foreignKeys: [
257
+ foreignKey("releases_channel_id_fk", ["channel_id"], "channels", ["id"], {
258
+ onDelete: "restrict",
259
+ }),
260
+ foreignKey("releases_bundle_id_fk", ["bundle_id"], "bundles", ["id"], {
261
+ onDelete: "restrict",
262
+ }),
263
+ foreignKey(
264
+ "releases_source_release_id_fk",
265
+ ["source_release_id"],
266
+ "releases",
267
+ ["id"],
268
+ { onDelete: "set null" },
269
+ ),
270
+ ],
271
+ relations: [
272
+ relation({
273
+ name: "channelRecord",
274
+ fieldName: "releases",
275
+ targetFieldName: "channelRecord",
276
+ relationName: "releases_channels",
277
+ columns: ["channel_id"],
278
+ referencedTable: "channels",
279
+ referencedColumns: ["id"],
280
+ }),
281
+ relation({
282
+ name: "bundle",
283
+ fieldName: "releases",
284
+ targetFieldName: "bundle",
285
+ relationName: "releases_bundles",
286
+ columns: ["bundle_id"],
287
+ referencedTable: "bundles",
288
+ referencedColumns: ["id"],
289
+ }),
290
+ relation({
291
+ name: "sourceRelease",
292
+ fieldName: "derivedReleases",
293
+ targetFieldName: "sourceRelease",
294
+ relationName: "releases_source_release",
295
+ columns: ["source_release_id"],
296
+ referencedTable: "releases",
297
+ referencedColumns: ["id"],
298
+ }),
299
+ ],
300
+ },
301
+ );
302
+
303
+ export const releaseCatalogsV100 = table(
304
+ "release_catalogs",
305
+ {
306
+ scope_key: idColumn("scope_key", varchar(2048)).collate(
307
+ catalogKeyCollations,
308
+ ),
309
+ catalog_id: column("catalog_id", varchar(255)),
310
+ strategy: stringColumn("strategy"),
311
+ channel_id: column("channel_id", varchar(255)).collate(
312
+ channelIdentityCollations,
313
+ ),
314
+ channel_key: column("channel_key", varchar(1400)).collate(
315
+ catalogKeyCollations,
316
+ ),
317
+ platform: stringColumn("platform"),
318
+ fingerprint_hash: stringColumn("fingerprint_hash").nullable(),
319
+ generation: float("generation"),
320
+ payload: largeString("payload"),
321
+ catalog_hash: column("catalog_hash", varchar(71)),
322
+ byte_size: integer("byte_size"),
323
+ is_tombstone: bool("is_tombstone"),
324
+ updated_at_ms: float("updated_at_ms"),
325
+ },
326
+ {
327
+ indexes: [index("release_catalogs_channel_idx", ["channel_id"])],
328
+ checks: [
329
+ check({
330
+ name: "release_catalogs_strategy_target_check",
331
+ expression:
332
+ "(strategy = 'APP_VERSION' and fingerprint_hash is null) or (strategy = 'FINGERPRINT' and fingerprint_hash is not null)",
333
+ sqliteInline: true,
334
+ }),
335
+ check({
336
+ name: "release_catalogs_generation_check",
337
+ expression: "generation >= 1 and generation <= 9007199254740991",
338
+ sqliteInline: true,
339
+ }),
340
+ check({
341
+ name: "release_catalogs_byte_size_check",
342
+ expression: "byte_size >= 0 and byte_size <= 262144",
343
+ sqliteInline: true,
344
+ }),
345
+ ],
346
+ foreignKeys: [
347
+ foreignKey(
348
+ "release_catalogs_channel_id_fk",
349
+ ["channel_id"],
350
+ "channels",
351
+ ["id"],
352
+ { onDelete: "restrict" },
353
+ ),
354
+ ],
355
+ relations: [
356
+ relation({
357
+ name: "channelRecord",
358
+ fieldName: "releaseCatalogs",
359
+ targetFieldName: "channelRecord",
360
+ relationName: "release_catalogs_channels",
361
+ columns: ["channel_id"],
362
+ referencedTable: "channels",
363
+ referencedColumns: ["id"],
364
+ }),
365
+ ],
366
+ },
367
+ );
368
+
369
+ export const bundleEventsV100 = table(
370
+ "bundle_events",
371
+ {
372
+ id: idColumn("id", "uuid"),
373
+ type: stringColumn("type"),
374
+ install_id: stringColumn("install_id"),
375
+ user_id: stringColumn("user_id").nullable(),
376
+ username: stringColumn("username").nullable(),
377
+ from_release_id: uuid("from_release_id").nullable(),
378
+ from_bundle_id: uuid("from_bundle_id").nullable(),
379
+ to_release_id: uuid("to_release_id").nullable(),
380
+ to_bundle_id: uuid("to_bundle_id"),
381
+ platform: stringColumn("platform"),
382
+ app_version: stringColumn("app_version"),
383
+ channel: stringColumn("channel"),
384
+ cohort: stringColumn("cohort"),
385
+ update_strategy: stringColumn("update_strategy").nullable(),
386
+ fingerprint_hash: stringColumn("fingerprint_hash").nullable(),
387
+ sdk_version: stringColumn("sdk_version").nullable(),
388
+ received_at_ms: float("received_at_ms"),
389
+ },
390
+ {
391
+ indexes: [
392
+ index("bundle_events_received_at_idx", ["received_at_ms", "id"]),
393
+ index("bundle_events_install_idx", [
394
+ "install_id",
395
+ "received_at_ms",
396
+ "id",
397
+ ]),
398
+ index("bundle_events_user_id_idx", ["user_id", "received_at_ms", "id"]),
399
+ index("bundle_events_username_idx", ["username", "received_at_ms", "id"]),
400
+ index("bundle_events_to_bundle_idx", [
401
+ "type",
402
+ "to_bundle_id",
403
+ "received_at_ms",
404
+ "id",
405
+ ]),
406
+ index("bundle_events_from_bundle_idx", [
407
+ "type",
408
+ "from_bundle_id",
409
+ "received_at_ms",
410
+ "id",
411
+ ]),
412
+ index("bundle_events_to_release_idx", [
413
+ "type",
414
+ "to_release_id",
415
+ "received_at_ms",
416
+ "id",
417
+ ]),
418
+ index("bundle_events_from_release_idx", [
419
+ "type",
420
+ "from_release_id",
421
+ "received_at_ms",
422
+ "id",
423
+ ]),
424
+ ],
425
+ checks: [
426
+ check({
427
+ name: "bundle_events_type_check",
428
+ expression:
429
+ "type in ('UPDATE_APPLIED', 'RECOVERED', 'RELEASE_ADOPTED', 'UNCHANGED')",
430
+ sqliteInline: true,
431
+ }),
432
+ check({
433
+ name: "bundle_events_platform_check",
434
+ expression: "platform in ('ios', 'android')",
435
+ sqliteInline: true,
436
+ }),
437
+ check({
438
+ name: "bundle_events_shape_check",
439
+ expression:
440
+ "((type in ('UPDATE_APPLIED', 'RECOVERED', 'RELEASE_ADOPTED')) and from_bundle_id is not null and update_strategy is not null and update_strategy in ('fingerprint', 'appVersion')) or (type = 'UNCHANGED' and from_bundle_id is null and update_strategy is null)",
441
+ sqliteInline: true,
442
+ }),
443
+ check({
444
+ name: "bundle_events_received_at_check",
445
+ expression: "received_at_ms >= 0",
446
+ sqliteInline: true,
447
+ }),
448
+ ],
449
+ },
450
+ );
451
+
452
+ export const v1_0_0 = schema({
453
+ version: "1.0.0",
454
+ settingsTable: HOT_UPDATER_SETTINGS_TABLE,
455
+ tables: [
456
+ channelsV100,
457
+ bundlesV100,
458
+ bundlePatchesV100,
459
+ releasesV100,
460
+ releaseCatalogsV100,
461
+ bundleEventsV100,
462
+ apiKeysV100,
463
+ createSettingsTable("1.0.0"),
464
+ ],
465
+ });
@@ -1,4 +1,7 @@
1
- import type { RuntimeStoragePlugin } from "@hot-updater/plugin-core";
1
+ import {
2
+ createStorageDownloadPath,
3
+ createStoragePlugin,
4
+ } from "@hot-updater/plugin-core";
2
5
  import { afterEach, describe, expect, it, vi } from "vitest";
3
6
 
4
7
  import { createStorageAccess } from "./storageAccess";
@@ -8,50 +11,142 @@ describe("createStorageAccess", () => {
8
11
  vi.unstubAllGlobals();
9
12
  });
10
13
 
11
- it("reads text through a matching runtime storage plugin before direct HTTP fetch", async () => {
12
- const readText = vi.fn(async () => "manifest text");
13
- const storagePlugin: RuntimeStoragePlugin = {
14
- name: "httpStorage",
15
- supportedProtocol: "http",
16
- profiles: {
17
- runtime: {
18
- readText,
19
- async getDownloadUrl(storageUri) {
20
- return { fileUrl: storageUri };
21
- },
22
- },
23
- },
24
- };
25
- const fetchMock = vi.fn<typeof fetch>(async () => {
26
- return new Response("should not be used", { status: 500 });
14
+ it("reads text through a matching storage implementation", async () => {
15
+ const get = vi.fn(
16
+ async (_storageUri: string) => new Response("manifest text"),
17
+ );
18
+ const storage = createStoragePlugin({
19
+ name: "r2Storage",
20
+ protocol: "r2",
21
+ get: async (input) => ({ response: await get(input.storageUri) }),
27
22
  });
28
- vi.stubGlobal("fetch", fetchMock);
23
+ const { readStorageText } = createStorageAccess([storage]);
29
24
 
30
- const { readStorageText } = createStorageAccess([storagePlugin]);
25
+ await expect(readStorageText("r2://assets/manifest.json")).resolves.toBe(
26
+ "manifest text",
27
+ );
28
+ expect(get).toHaveBeenCalledWith("r2://assets/manifest.json");
29
+ });
30
+
31
+ it("reads direct HTTP storage when no plugin owns the protocol", async () => {
32
+ const fetchMock = vi.fn<typeof fetch>(
33
+ async () => new Response("manifest text"),
34
+ );
35
+ vi.stubGlobal("fetch", fetchMock);
36
+ const { readStorageText } = createStorageAccess([]);
31
37
 
32
38
  await expect(
33
- readStorageText("http://assets.example.com/manifest.json"),
39
+ readStorageText("https://assets.example.com/manifest.json"),
34
40
  ).resolves.toBe("manifest text");
35
- expect(readText).toHaveBeenCalledWith(
36
- "http://assets.example.com/manifest.json",
37
- undefined,
41
+ });
42
+
43
+ it("uses an unowned HTTPS URI directly as the download URL", async () => {
44
+ const { resolveFileUrl } = createStorageAccess([]);
45
+ const storageUri = "https://assets.example.com/bundle.zip";
46
+
47
+ await expect(resolveFileUrl(storageUri)).resolves.toBe(storageUri);
48
+ });
49
+
50
+ it("lets a matching HTTPS storage own reads before direct fetch", async () => {
51
+ const fetchMock = vi.fn<typeof fetch>();
52
+ vi.stubGlobal("fetch", fetchMock);
53
+ const get = vi.fn(
54
+ async () => ({ response: new Response("owned manifest") }) as const,
38
55
  );
56
+ const storage = createStoragePlugin({
57
+ name: "standaloneStorage",
58
+ protocol: "https",
59
+ get,
60
+ });
61
+ const { readStorageText } = createStorageAccess([storage]);
62
+ const storageUri = "https://storage.example.com/manifest.json";
63
+
64
+ await expect(readStorageText(storageUri)).resolves.toBe("owned manifest");
65
+ expect(get).toHaveBeenCalledWith({ storageUri });
39
66
  expect(fetchMock).not.toHaveBeenCalled();
40
67
  });
41
68
 
42
- it("reads direct HTTP storage text when no storage plugin owns the protocol", async () => {
43
- const fetchMock = vi.fn<typeof fetch>(async () => {
44
- return new Response("manifest text", { status: 200 });
69
+ it("lets a matching HTTPS storage resolve the download URL", async () => {
70
+ const getDownloadUrl = vi.fn(async () => ({
71
+ url: "https://cdn.example.com/bundle.zip",
72
+ }));
73
+ const storage = createStoragePlugin({
74
+ name: "standaloneStorage",
75
+ protocol: "https",
76
+ get: async () => ({ response: null }),
77
+ getDownloadUrl,
45
78
  });
46
- vi.stubGlobal("fetch", fetchMock);
79
+ const { resolveFileUrl } = createStorageAccess([storage]);
80
+ const storageUri = "https://storage.example.com/bundle.zip";
47
81
 
48
- const { readStorageText } = createStorageAccess([]);
82
+ await expect(resolveFileUrl(storageUri)).resolves.toBe(
83
+ "https://cdn.example.com/bundle.zip",
84
+ );
85
+ expect(getDownloadUrl).toHaveBeenCalledWith({ storageUri });
86
+ });
87
+
88
+ it("creates and serves a runtime-neutral delivery URL", async () => {
89
+ const storage = createStoragePlugin({
90
+ name: "r2Storage",
91
+ protocol: "r2",
92
+ get: vi.fn(
93
+ async () =>
94
+ ({
95
+ response: new Response("bundle", {
96
+ headers: { "content-type": "application/zip" },
97
+ }),
98
+ }) as const,
99
+ ),
100
+ getDownloadUrl: async ({ storageUri }) => ({
101
+ url: createStorageDownloadPath(storageUri, "test-signature"),
102
+ }),
103
+ });
104
+ const access = createStorageAccess([storage]);
49
105
 
106
+ const fileUrl = await access.resolveFileUrl("r2://bucket/bundle.zip");
107
+ expect(fileUrl).toMatch(/^\/storage\//);
108
+ const segments = fileUrl!.split("/");
109
+ const token = segments.at(-2)!;
110
+ const signature = segments.at(-1)!;
111
+ const response = await access.downloadStorageObject!(token, signature);
112
+ await expect(response?.text()).resolves.toBe("bundle");
50
113
  await expect(
51
- readStorageText("https://assets.example.com/manifest.json"),
52
- ).resolves.toBe("manifest text");
53
- expect(fetchMock).toHaveBeenCalledWith(
54
- "https://assets.example.com/manifest.json",
114
+ access.downloadStorageObject!(token, `${signature}tampered`),
115
+ ).resolves.toBeNull();
116
+ });
117
+
118
+ it("lets a CDN resolver bypass built-in server delivery", async () => {
119
+ const resolveUrl = vi.fn(async () => ({
120
+ url: "https://cdn.example.com/bundle.zip",
121
+ }));
122
+ const storage = createStoragePlugin({
123
+ name: "s3Storage",
124
+ protocol: "s3",
125
+ get: async () => ({ response: null }),
126
+ getDownloadUrl: resolveUrl,
127
+ });
128
+ const access = createStorageAccess([storage]);
129
+
130
+ await expect(access.resolveFileUrl("s3://bucket/bundle.zip")).resolves.toBe(
131
+ "https://cdn.example.com/bundle.zip",
132
+ );
133
+ expect(access.downloadStorageObject).toEqual(expect.any(Function));
134
+ });
135
+
136
+ it("rejects ambiguous storage protocol ownership", () => {
137
+ const first = createStoragePlugin({
138
+ name: "firstR2Storage",
139
+ protocol: "r2",
140
+ get: async () => ({ response: null }),
141
+ });
142
+ const second = createStoragePlugin({
143
+ name: "secondR2Storage",
144
+ protocol: "r2",
145
+ get: async () => ({ response: null }),
146
+ });
147
+
148
+ expect(() => createStorageAccess([first, second])).toThrow(
149
+ "Multiple storage plugins handle protocol: r2",
55
150
  );
56
151
  });
57
152
  });