@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
@@ -1,4 +1,4 @@
1
- import { Bundle, DatabasePlugin, NodeStoragePlugin } from "@hot-updater/plugin-core";
1
+ import { Bundle, BundleRepository, StoragePluginWith } from "@hot-updater/plugin-core";
2
2
 
3
3
  //#region src/db/createBundleDiff.d.ts
4
4
  interface CreateBundleDiffInput {
@@ -6,8 +6,8 @@ interface CreateBundleDiffInput {
6
6
  bundleId: string;
7
7
  }
8
8
  interface CreateBundleDiffDependencies {
9
- databasePlugin: DatabasePlugin;
10
- storagePlugin: NodeStoragePlugin | null;
9
+ databasePlugin: BundleRepository;
10
+ storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
11
11
  }
12
12
  interface CreateBundleDiffOptions {
13
13
  makePrimary?: boolean;
@@ -1,4 +1,4 @@
1
- import { Bundle, DatabasePlugin, NodeStoragePlugin } from "@hot-updater/plugin-core";
1
+ import { Bundle, BundleRepository, StoragePluginWith } from "@hot-updater/plugin-core";
2
2
 
3
3
  //#region src/db/createBundleDiff.d.ts
4
4
  interface CreateBundleDiffInput {
@@ -6,8 +6,8 @@ interface CreateBundleDiffInput {
6
6
  bundleId: string;
7
7
  }
8
8
  interface CreateBundleDiffDependencies {
9
- databasePlugin: DatabasePlugin;
10
- storagePlugin: NodeStoragePlugin | null;
9
+ databasePlugin: BundleRepository;
10
+ storagePlugin: StoragePluginWith<"get" | "put" | "delete"> | null;
11
11
  }
12
12
  interface CreateBundleDiffOptions {
13
13
  makePrimary?: boolean;
@@ -1,15 +1,12 @@
1
- import { createBundleStorageKey, getManifestAssetDownloadPath, resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
1
+ import { createBundleStorageKey, createDatabaseClient, getManifestAssetDownloadPath, resolveManifestAssetStorageUri } from "@hot-updater/plugin-core";
2
2
  import { getAssetBaseStorageUri, getBundlePatch, getBundlePatches, getManifestStorageUri } from "@hot-updater/core";
3
- import crypto, { randomUUID } from "node:crypto";
4
- import fs from "node:fs/promises";
5
- import os from "node:os";
3
+ import crypto from "node:crypto";
6
4
  import path from "node:path";
7
5
  import { promisify } from "node:util";
8
6
  import { brotliDecompress } from "node:zlib";
9
7
  import { hdiff } from "@hot-updater/bsdiff";
10
8
  //#region src/db/createBundleDiff.ts
11
9
  const HBC_ASSET_PATH_RE = /\.bundle$/;
12
- const HOT_UPDATER_DOWNLOAD_DIR_PREFIX = "downloads-";
13
10
  const decompressBrotli = promisify(brotliDecompress);
14
11
  const isBundleManifest = (value) => {
15
12
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
@@ -34,23 +31,14 @@ async function downloadFromUrl(url) {
34
31
  }
35
32
  async function downloadStorageBytes(storageUri, storagePlugin) {
36
33
  const protocol = new URL(storageUri).protocol.replace(":", "");
37
- if (protocol === "http" || protocol === "https") return downloadFromUrl(storageUri);
38
- if (!storagePlugin) throw new Error("Storage plugin is not configured");
39
- if (storagePlugin.supportedProtocol !== protocol) throw new Error(`No storage plugin for protocol: ${protocol}`);
40
- const downloadRoot = path.join(process.cwd(), ".hot-updater");
41
- await fs.mkdir(downloadRoot, { recursive: true });
42
- const workDir = await fs.mkdtemp(path.join(downloadRoot, HOT_UPDATER_DOWNLOAD_DIR_PREFIX));
43
- const filename = path.basename(new URL(storageUri).pathname) || randomUUID();
44
- const filePath = path.join(workDir, filename);
45
- try {
46
- await storagePlugin.profiles.node.downloadFile(storageUri, filePath);
47
- return new Uint8Array(await fs.readFile(filePath));
48
- } finally {
49
- await fs.rm(workDir, {
50
- force: true,
51
- recursive: true
52
- });
34
+ if (!storagePlugin || storagePlugin.protocol !== protocol) {
35
+ if (protocol === "http" || protocol === "https") return downloadFromUrl(storageUri);
36
+ if (!storagePlugin) throw new Error("Storage plugin is not configured");
37
+ throw new Error(`No storage plugin for protocol: ${protocol}`);
53
38
  }
39
+ const { response } = await storagePlugin.get({ storageUri });
40
+ if (response === null) throw new Error(`Storage object not found: ${storageUri}`);
41
+ return new Uint8Array(await response.arrayBuffer());
54
42
  }
55
43
  async function fetchManifest(bundle, storagePlugin) {
56
44
  const manifestStorageUri = getManifestStorageUri(bundle);
@@ -76,12 +64,16 @@ async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
76
64
  const compressedAssetStorageUri = resolveManifestAssetStorageUri({
77
65
  assetBaseStorageUri,
78
66
  assetPath: downloadPath,
67
+ downloadFileHash: asset.downloadFileHash,
79
68
  fileHash: asset.fileHash
80
69
  });
81
70
  let compressedBytes = null;
82
71
  try {
83
72
  compressedBytes = await downloadStorageBytes(compressedAssetStorageUri, storagePlugin);
84
- } catch {}
73
+ } catch (error) {
74
+ if (!(error instanceof Error)) throw error;
75
+ compressedBytes = null;
76
+ }
85
77
  if (compressedBytes) return new Uint8Array(await decompressBrotli(compressedBytes));
86
78
  }
87
79
  return downloadStorageBytes(resolveManifestAssetStorageUri({
@@ -90,23 +82,16 @@ async function fetchAssetBytes(bundle, assetPath, manifest, storagePlugin) {
90
82
  fileHash: asset.fileHash
91
83
  }), storagePlugin);
92
84
  }
93
- async function getFileHash(filePath) {
94
- const file = await fs.readFile(filePath);
95
- return crypto.createHash("sha256").update(file).digest("hex");
96
- }
97
85
  function buildNextPatchState({ currentBundle, nextPatch, makePrimary }) {
98
86
  const existingPatches = getBundlePatches(currentBundle).filter((patch) => patch.baseBundleId !== nextPatch.baseBundleId);
99
- const orderedPatches = makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
100
- return {
101
- patches: orderedPatches,
102
- primaryPatch: orderedPatches[0] ?? nextPatch
103
- };
87
+ return makePrimary ? [nextPatch, ...existingPatches] : [...existingPatches, nextPatch];
104
88
  }
105
89
  async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {}) {
90
+ const database = createDatabaseClient(deps.databasePlugin);
106
91
  if (!deps.storagePlugin) throw new Error("Storage plugin is not configured");
107
92
  if (baseBundleId === bundleId) throw new Error("Base bundle must be different from the target bundle");
108
- const baseBundle = await deps.databasePlugin.getBundleById(baseBundleId);
109
- const targetBundle = await deps.databasePlugin.getBundleById(bundleId);
93
+ const baseBundle = await database.getBundleById(baseBundleId);
94
+ const targetBundle = await database.getBundleById(bundleId);
110
95
  if (!baseBundle || !targetBundle) throw new Error("Bundle not found");
111
96
  if (baseBundle.platform !== targetBundle.platform) throw new Error("Base bundle platform must match the target bundle");
112
97
  if (baseBundle.id.localeCompare(targetBundle.id) >= 0) throw new Error("Base bundle must be older than the target bundle");
@@ -120,43 +105,37 @@ async function createBundleDiff({ baseBundleId, bundleId }, deps, options = {})
120
105
  if (baseAssetHash === targetAssetHash) throw new Error("Hermes bundle is unchanged; no diff patch is required");
121
106
  const [baseBytes, targetBytes] = await Promise.all([fetchAssetBytes(baseBundle, baseAssetPath, baseManifest, deps.storagePlugin), fetchAssetBytes(targetBundle, targetAssetPath, targetManifest, deps.storagePlugin)]);
122
107
  const patchBytes = await hdiff(baseBytes, targetBytes);
123
- const workDir = await fs.mkdtemp(path.join(os.tmpdir(), "hot-updater-console-bsdiff-"));
108
+ const patchFileHash = crypto.createHash("sha256").update(patchBytes).digest("hex");
124
109
  const patchFilename = `${path.posix.basename(targetAssetPath)}.bsdiff`;
125
- const patchPath = path.join(workDir, patchFilename);
126
110
  const previousPatch = getBundlePatch(targetBundle, baseBundle.id);
127
- try {
128
- await fs.writeFile(patchPath, patchBytes);
129
- const uploadKey = createBundleStorageKey(targetBundle.id, "patches", baseBundle.id, getRelativeStorageDir(targetAssetPath));
130
- const patchUpload = await deps.storagePlugin.profiles.node.upload(uploadKey, patchPath);
131
- const patchFileHash = await getFileHash(patchPath);
132
- const nextState = buildNextPatchState({
133
- currentBundle: targetBundle,
134
- nextPatch: {
135
- baseBundleId: baseBundle.id,
136
- baseFileHash: baseAssetHash,
137
- patchFileHash,
138
- patchStorageUri: patchUpload.storageUri
139
- },
140
- makePrimary: options.makePrimary ?? true
141
- });
142
- await deps.databasePlugin.updateBundle(targetBundle.id, {
143
- patches: nextState.patches,
144
- patchBaseBundleId: nextState.primaryPatch.baseBundleId,
145
- patchBaseFileHash: nextState.primaryPatch.baseFileHash,
146
- patchFileHash: nextState.primaryPatch.patchFileHash,
147
- patchStorageUri: nextState.primaryPatch.patchStorageUri
148
- });
149
- await deps.databasePlugin.commitBundle();
150
- if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.profiles.node.delete(previousPatch.patchStorageUri).catch(() => {});
151
- const updatedBundle = await deps.databasePlugin.getBundleById(targetBundle.id);
152
- if (!updatedBundle) throw new Error("Updated bundle not found");
153
- return updatedBundle;
154
- } finally {
155
- await fs.rm(workDir, {
156
- force: true,
157
- recursive: true
158
- });
159
- }
111
+ const uploadKey = createBundleStorageKey(targetBundle.id, "patches", baseBundle.id, patchFileHash, getRelativeStorageDir(targetAssetPath), patchFilename);
112
+ const patchUpload = await deps.storagePlugin.put({
113
+ key: uploadKey,
114
+ body: new ReadableStream({ start(controller) {
115
+ controller.enqueue(patchBytes);
116
+ controller.close();
117
+ } }),
118
+ contentLength: patchBytes.byteLength,
119
+ contentType: "application/octet-stream"
120
+ });
121
+ const patches = buildNextPatchState({
122
+ currentBundle: targetBundle,
123
+ nextPatch: {
124
+ baseBundleId: baseBundle.id,
125
+ baseFileHash: baseAssetHash,
126
+ byteSize: patchBytes.byteLength,
127
+ patchFileHash,
128
+ patchStorageUri: patchUpload.storageUri
129
+ },
130
+ makePrimary: options.makePrimary ?? true
131
+ });
132
+ const updatedBundle = {
133
+ ...targetBundle,
134
+ patches
135
+ };
136
+ await database.updateBundleById(targetBundle.id, updatedBundle);
137
+ if (previousPatch?.patchStorageUri && previousPatch.patchStorageUri !== patchUpload.storageUri) await deps.storagePlugin.delete({ storageUri: previousPatch.patchStorageUri }).catch(() => {});
138
+ return updatedBundle;
160
139
  }
161
140
  //#endregion
162
141
  export { createBundleDiff };
@@ -0,0 +1,138 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_releaseCatalog = require("./releaseCatalog.cjs");
3
+ let _hot_updater_plugin_core = require("@hot-updater/plugin-core");
4
+ let _hot_updater_core = require("@hot-updater/core");
5
+ //#region src/db/databasePluginCore.ts
6
+ function createDatabasePluginCore(database, resolveFileUrl, options) {
7
+ const client = (0, _hot_updater_plugin_core.createDatabaseClient)(database);
8
+ const beforeOperation = options?.beforeOperation;
9
+ const getReleaseCatalog = require_releaseCatalog.createReleaseCatalogReader(database);
10
+ const getArtifact = require_releaseCatalog.createArtifactResolver({
11
+ database,
12
+ readStorageText: options?.readStorageText,
13
+ resolveFileUrl
14
+ });
15
+ return {
16
+ api: {
17
+ async getBundleById(id) {
18
+ await beforeOperation?.();
19
+ return client.getBundleById(id);
20
+ },
21
+ async getReleaseCatalog(input) {
22
+ await beforeOperation?.();
23
+ return getReleaseCatalog(input);
24
+ },
25
+ async getArtifactInfo(targetBundleId, currentBundleId) {
26
+ await beforeOperation?.();
27
+ return getArtifact(targetBundleId, currentBundleId);
28
+ },
29
+ async getReleaseById(id) {
30
+ await beforeOperation?.();
31
+ return database.models.releases.findById(id);
32
+ },
33
+ async getReleasesByScope(input) {
34
+ await beforeOperation?.();
35
+ return database.models.releases.findManyByScope({
36
+ ...input,
37
+ consistency: "strong"
38
+ });
39
+ },
40
+ async getReleases(input) {
41
+ await beforeOperation?.();
42
+ return database.models.releases.findMany(input);
43
+ },
44
+ async getReleaseCatalogByScopeKey(scopeKey) {
45
+ await beforeOperation?.();
46
+ return database.models.releaseCatalogs.findByScopeKey(scopeKey);
47
+ },
48
+ async getReleaseCatalogs(input) {
49
+ await beforeOperation?.();
50
+ return database.models.releaseCatalogs.findMany(input);
51
+ },
52
+ async updateReleasePolicy(input) {
53
+ await beforeOperation?.();
54
+ return (0, _hot_updater_plugin_core.updateReleasePolicy)({
55
+ database,
56
+ ...input
57
+ });
58
+ },
59
+ async preflightReleasePolicy(input) {
60
+ await beforeOperation?.();
61
+ return (0, _hot_updater_plugin_core.preflightReleasePolicy)({
62
+ database,
63
+ ...input
64
+ });
65
+ },
66
+ async deleteRelease(input) {
67
+ await beforeOperation?.();
68
+ return (0, _hot_updater_plugin_core.deleteRelease)({
69
+ database,
70
+ ...input
71
+ });
72
+ },
73
+ async rebuildReleaseCatalog(scopeKey) {
74
+ await beforeOperation?.();
75
+ const catalog = await database.models.releaseCatalogs.findByScopeKey(scopeKey);
76
+ if (catalog === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
77
+ return (0, _hot_updater_plugin_core.rebuildReleaseCatalog)({
78
+ database,
79
+ scope: {
80
+ channelId: catalog.channel_id,
81
+ channelName: (0, _hot_updater_core.decodeChannelKey)(catalog.channel_key),
82
+ fingerprintHash: catalog.fingerprint_hash,
83
+ platform: catalog.platform,
84
+ scopeKey: catalog.scope_key,
85
+ strategy: catalog.strategy
86
+ }
87
+ });
88
+ },
89
+ async commitDatabase(input) {
90
+ await beforeOperation?.();
91
+ return database.commit(input);
92
+ },
93
+ async getChannels() {
94
+ await beforeOperation?.();
95
+ return client.getChannels();
96
+ },
97
+ async insertChannel(input) {
98
+ await beforeOperation?.();
99
+ return database.models.channels.insert(input);
100
+ },
101
+ async deleteChannel(input) {
102
+ await beforeOperation?.();
103
+ return database.models.channels.delete(input);
104
+ },
105
+ async getBundles(options) {
106
+ await beforeOperation?.();
107
+ return client.getBundles(options);
108
+ },
109
+ async insertBundle(bundle) {
110
+ await beforeOperation?.();
111
+ await client.insertBundle(bundle);
112
+ },
113
+ async insertBundles(bundles) {
114
+ await beforeOperation?.();
115
+ await client.mutate(async (transaction) => {
116
+ for (const bundle of bundles) await transaction.insertBundle(bundle);
117
+ });
118
+ },
119
+ async updateBundleById(bundleId, update) {
120
+ await beforeOperation?.();
121
+ await client.updateBundleById(bundleId, update);
122
+ },
123
+ async deleteBundleById(bundleId) {
124
+ await beforeOperation?.();
125
+ await client.deleteBundleById(bundleId);
126
+ }
127
+ },
128
+ adapterName: database.name,
129
+ createMigrator: () => {
130
+ throw new Error("createMigrator is only available for Kysely/MongoDB database plugins.");
131
+ },
132
+ generateSchema: () => {
133
+ throw new Error("generateSchema is only available for Drizzle/Prisma database plugins.");
134
+ }
135
+ };
136
+ }
137
+ //#endregion
138
+ exports.createDatabasePluginCore = createDatabasePluginCore;
@@ -0,0 +1,137 @@
1
+ import { createArtifactResolver, createReleaseCatalogReader } from "./releaseCatalog.mjs";
2
+ import { createDatabaseClient, deleteRelease, preflightReleasePolicy, rebuildReleaseCatalog, updateReleasePolicy } from "@hot-updater/plugin-core";
3
+ import { decodeChannelKey } from "@hot-updater/core";
4
+ //#region src/db/databasePluginCore.ts
5
+ function createDatabasePluginCore(database, resolveFileUrl, options) {
6
+ const client = createDatabaseClient(database);
7
+ const beforeOperation = options?.beforeOperation;
8
+ const getReleaseCatalog = createReleaseCatalogReader(database);
9
+ const getArtifact = createArtifactResolver({
10
+ database,
11
+ readStorageText: options?.readStorageText,
12
+ resolveFileUrl
13
+ });
14
+ return {
15
+ api: {
16
+ async getBundleById(id) {
17
+ await beforeOperation?.();
18
+ return client.getBundleById(id);
19
+ },
20
+ async getReleaseCatalog(input) {
21
+ await beforeOperation?.();
22
+ return getReleaseCatalog(input);
23
+ },
24
+ async getArtifactInfo(targetBundleId, currentBundleId) {
25
+ await beforeOperation?.();
26
+ return getArtifact(targetBundleId, currentBundleId);
27
+ },
28
+ async getReleaseById(id) {
29
+ await beforeOperation?.();
30
+ return database.models.releases.findById(id);
31
+ },
32
+ async getReleasesByScope(input) {
33
+ await beforeOperation?.();
34
+ return database.models.releases.findManyByScope({
35
+ ...input,
36
+ consistency: "strong"
37
+ });
38
+ },
39
+ async getReleases(input) {
40
+ await beforeOperation?.();
41
+ return database.models.releases.findMany(input);
42
+ },
43
+ async getReleaseCatalogByScopeKey(scopeKey) {
44
+ await beforeOperation?.();
45
+ return database.models.releaseCatalogs.findByScopeKey(scopeKey);
46
+ },
47
+ async getReleaseCatalogs(input) {
48
+ await beforeOperation?.();
49
+ return database.models.releaseCatalogs.findMany(input);
50
+ },
51
+ async updateReleasePolicy(input) {
52
+ await beforeOperation?.();
53
+ return updateReleasePolicy({
54
+ database,
55
+ ...input
56
+ });
57
+ },
58
+ async preflightReleasePolicy(input) {
59
+ await beforeOperation?.();
60
+ return preflightReleasePolicy({
61
+ database,
62
+ ...input
63
+ });
64
+ },
65
+ async deleteRelease(input) {
66
+ await beforeOperation?.();
67
+ return deleteRelease({
68
+ database,
69
+ ...input
70
+ });
71
+ },
72
+ async rebuildReleaseCatalog(scopeKey) {
73
+ await beforeOperation?.();
74
+ const catalog = await database.models.releaseCatalogs.findByScopeKey(scopeKey);
75
+ if (catalog === null) throw new Error(`Release catalog "${scopeKey}" was not found.`);
76
+ return rebuildReleaseCatalog({
77
+ database,
78
+ scope: {
79
+ channelId: catalog.channel_id,
80
+ channelName: decodeChannelKey(catalog.channel_key),
81
+ fingerprintHash: catalog.fingerprint_hash,
82
+ platform: catalog.platform,
83
+ scopeKey: catalog.scope_key,
84
+ strategy: catalog.strategy
85
+ }
86
+ });
87
+ },
88
+ async commitDatabase(input) {
89
+ await beforeOperation?.();
90
+ return database.commit(input);
91
+ },
92
+ async getChannels() {
93
+ await beforeOperation?.();
94
+ return client.getChannels();
95
+ },
96
+ async insertChannel(input) {
97
+ await beforeOperation?.();
98
+ return database.models.channels.insert(input);
99
+ },
100
+ async deleteChannel(input) {
101
+ await beforeOperation?.();
102
+ return database.models.channels.delete(input);
103
+ },
104
+ async getBundles(options) {
105
+ await beforeOperation?.();
106
+ return client.getBundles(options);
107
+ },
108
+ async insertBundle(bundle) {
109
+ await beforeOperation?.();
110
+ await client.insertBundle(bundle);
111
+ },
112
+ async insertBundles(bundles) {
113
+ await beforeOperation?.();
114
+ await client.mutate(async (transaction) => {
115
+ for (const bundle of bundles) await transaction.insertBundle(bundle);
116
+ });
117
+ },
118
+ async updateBundleById(bundleId, update) {
119
+ await beforeOperation?.();
120
+ await client.updateBundleById(bundleId, update);
121
+ },
122
+ async deleteBundleById(bundleId) {
123
+ await beforeOperation?.();
124
+ await client.deleteBundleById(bundleId);
125
+ }
126
+ },
127
+ adapterName: database.name,
128
+ createMigrator: () => {
129
+ throw new Error("createMigrator is only available for Kysely/MongoDB database plugins.");
130
+ },
131
+ generateSchema: () => {
132
+ throw new Error("generateSchema is only available for Drizzle/Prisma database plugins.");
133
+ }
134
+ };
135
+ }
136
+ //#endregion
137
+ export { createDatabasePluginCore };
@@ -1,131 +1,75 @@
1
+ require("../_virtual/_rolldown/runtime.cjs");
1
2
  const require_types = require("../schema/types.cjs");
2
- const require_registry = require("./schema/registry.cjs");
3
+ const require_fixedMigratorShared = require("./fixedMigratorShared.cjs");
3
4
  const require_sql = require("./schema/sql.cjs");
4
- const require_mongodb = require("./schema/mongodb.cjs");
5
- const require_sqlMigrations = require("./schema/sqlMigrations.cjs");
6
5
  const require_sqlOperations = require("./schema/sqlOperations.cjs");
6
+ const require_sqlMigrationExecution = require("./sqlMigrationExecution.cjs");
7
+ require("./fixedMigratorMongo.cjs");
8
+ let kysely = require("kysely");
7
9
  //#region src/db/fixedMigrator.ts
8
- const getEmptyResult = () => ({
9
- operations: [],
10
- execute: async () => {},
11
- getSQL: () => ""
12
- });
13
- const assertSupportedMigrationMode = (options) => {
14
- if (options.mode === "from-database") throw new Error("Hot Updater migrations support only mode: 'from-schema'.");
15
- };
16
10
  const isMissingSettingsTableError = (error) => {
17
11
  if (!(error instanceof Error)) return false;
18
12
  const message = error.message.toLowerCase();
19
13
  return message.includes("private_hot_updater_settings") && (message.includes("does not exist") || message.includes("no such table") || message.includes("doesn't exist") || message.includes("not found"));
20
14
  };
21
- const isMongoNamespaceExistsError = (error) => {
22
- if (!(error instanceof Error)) return false;
23
- const mongoError = error;
24
- return mongoError.code === 48 || mongoError.codeName === "NamespaceExists";
25
- };
26
- const ignoreExistingCollection = (error) => {
27
- if (isMongoNamespaceExistsError(error)) return;
28
- throw error;
29
- };
30
- const toCustomOperations = (statements, settingsOperation) => [...statements.map((statement) => ({
31
- type: "custom",
32
- sql: statement
33
- })), ...settingsOperation ? [settingsOperation] : []];
34
- const assertSupportedSchemaVersion = (currentVersion) => {
35
- if (currentVersion !== void 0 && currentVersion !== "0.21.0" && currentVersion !== "0.29.0") throw new Error(`Unsupported Hot Updater schema version: ${currentVersion}`);
36
- };
37
15
  const createKyselyMigrator = ({ db, provider, relationMode = "foreign-keys" }) => {
38
- const getVersion = async () => {
16
+ const getSetting = async (key) => {
39
17
  try {
40
- const row = await db.selectFrom(require_types.HOT_UPDATER_SETTINGS_TABLE).select("value").where("key", "=", "version").executeTakeFirst();
41
- return typeof row?.value === "string" ? row.value : void 0;
18
+ const row = (await kysely.sql`select ${kysely.sql.ref("value")} from ${kysely.sql.table(require_types.HOT_UPDATER_SETTINGS_TABLE)} where ${kysely.sql.ref("key")} = ${key} limit 1`.execute(db)).rows[0];
19
+ if (!row) return void 0;
20
+ if (typeof row.value !== "string") throw new Error(`Invalid Hot Updater schema setting: ${key}`);
21
+ return row.value;
42
22
  } catch (error) {
43
23
  if (!isMissingSettingsTableError(error)) throw error;
44
24
  return;
45
25
  }
46
26
  };
27
+ const getCoreVersion = () => getSetting(require_types.HOT_UPDATER_CORE_SCHEMA_KEY);
28
+ const getSchemaVersions = async () => {
29
+ return {
30
+ coreVersion: await getCoreVersion(),
31
+ legacyCoreVersion: require_fixedMigratorShared.inferLegacyCoreSchemaVersion(await getSetting("version"))
32
+ };
33
+ };
34
+ const getVersion = async () => {
35
+ const { coreVersion, legacyCoreVersion } = await getSchemaVersions();
36
+ return coreVersion ?? legacyCoreVersion;
37
+ };
47
38
  const makeResult = async (options = {}) => {
48
- assertSupportedMigrationMode(options);
49
- const currentVersion = await getVersion();
50
- if (currentVersion === "0.31.0") return getEmptyResult();
51
- assertSupportedSchemaVersion(currentVersion);
39
+ require_fixedMigratorShared.assertSupportedMigrationMode(options);
40
+ const { coreVersion, legacyCoreVersion } = await getSchemaVersions();
41
+ if (require_fixedMigratorShared.isCurrentSchemaVersion(coreVersion)) return require_fixedMigratorShared.getEmptyMigrationResult();
42
+ require_fixedMigratorShared.assertCurrentOrEmptySchemaVersion(coreVersion ?? legacyCoreVersion);
52
43
  const settingsStatement = require_sqlOperations.getSettingsInsertSql(provider);
53
44
  const settingsOperation = options.updateSettings === false ? void 0 : {
54
45
  type: "custom",
55
46
  sql: settingsStatement
56
47
  };
57
- const executableSettingsStatements = options.updateSettings === false ? [] : [settingsStatement];
58
- const statements = currentVersion === void 0 ? [...require_sql.createTableSql(provider, relationMode), settingsStatement] : [
59
- ...currentVersion === "0.21.0" ? require_sqlMigrations.createV029AlterSql(provider) : [],
60
- ...currentVersion === "0.21.0" || currentVersion === "0.29.0" ? require_sqlMigrations.createV031AlterSql(provider, relationMode) : [],
61
- ...executableSettingsStatements
62
- ];
48
+ const statements = [...require_sql.createTableSql(provider, relationMode), settingsStatement];
63
49
  return {
64
- operations: currentVersion === void 0 ? require_sqlOperations.createSqlCreateOperations(provider, relationMode, settingsOperation) : toCustomOperations([...currentVersion === "0.21.0" ? require_sqlMigrations.createV029AlterSql(provider) : [], ...currentVersion === "0.21.0" || currentVersion === "0.29.0" ? require_sqlMigrations.createV031AlterSql(provider, relationMode) : []], settingsOperation),
50
+ operations: require_sqlOperations.createSqlCreateOperations(provider, relationMode, settingsOperation),
65
51
  getSQL: () => statements.map((statement) => `${statement};`).join("\n\n"),
66
- execute: async () => {
67
- const { sql } = await import("kysely");
68
- for (const statement of statements) await sql.raw(statement).execute(db);
69
- }
52
+ execute: () => require_sqlMigrationExecution.executeMigrationStatements({
53
+ db,
54
+ provider,
55
+ statements
56
+ })
70
57
  };
71
58
  };
72
59
  return {
73
60
  getVersion,
74
61
  getNameVariants: async () => void 0,
75
- next: async () => await getVersion() === "0.31.0" ? void 0 : { version: require_types.HOT_UPDATER_SCHEMA_VERSION },
76
- previous: async () => void 0,
77
- up: makeResult,
78
- down: async () => {
79
- throw new Error("No previous schema to migrate to.");
62
+ next: async () => {
63
+ const { coreVersion } = await getSchemaVersions();
64
+ return require_fixedMigratorShared.isCurrentSchemaVersion(coreVersion) ? void 0 : { version: require_types.HOT_UPDATER_SCHEMA_VERSION };
80
65
  },
81
- migrateTo: async (version, options) => {
82
- if (version !== "0.31.0") throw new Error(`Invalid version ${version}`);
83
- return makeResult(options);
84
- },
85
- migrateToLatest: makeResult
86
- };
87
- };
88
- const createMongoMigrator = (client) => {
89
- const settings = client.db().collection(require_types.HOT_UPDATER_SETTINGS_TABLE);
90
- const getVersion = async () => {
91
- const row = await settings.findOne({ key: "version" });
92
- return typeof row?.value === "string" ? row.value : void 0;
93
- };
94
- const makeResult = async (options = {}) => {
95
- assertSupportedMigrationMode(options);
96
- if (await getVersion() === "0.31.0") return getEmptyResult();
97
- return {
98
- operations: require_mongodb.createMongoMigrationOperations(options.updateSettings === false ? void 0 : {
99
- type: "custom",
100
- key: "version",
101
- value: require_types.HOT_UPDATER_SCHEMA_VERSION
102
- }),
103
- execute: async () => {
104
- const db = client.db();
105
- for (const table of require_registry.hotUpdaterSchema.tables) {
106
- if (table.internal) continue;
107
- await db.createCollection(table.ormName).catch(ignoreExistingCollection);
108
- }
109
- await db.collection("bundles").createIndex({ id: 1 }, { name: "bundles_id_idx" });
110
- for (const table of require_registry.hotUpdaterSchema.tables) {
111
- if (table.internal) continue;
112
- for (const index of (table.indexes ?? []).filter((item) => require_registry.schemaIndexAppliesToProvider(item, "mongodb"))) await db.collection(table.ormName).createIndex(Object.fromEntries(index.columns.map((column) => [column, 1])), { name: index.name });
113
- }
114
- if (options.updateSettings !== false) await settings.updateOne({ key: "version" }, { $set: { value: require_types.HOT_UPDATER_SCHEMA_VERSION } }, { upsert: true });
115
- }
116
- };
117
- };
118
- return {
119
- getVersion,
120
- getNameVariants: async () => void 0,
121
- next: async () => await getVersion() === "0.31.0" ? void 0 : { version: require_types.HOT_UPDATER_SCHEMA_VERSION },
122
66
  previous: async () => void 0,
123
67
  up: makeResult,
124
68
  down: async () => {
125
69
  throw new Error("No previous schema to migrate to.");
126
70
  },
127
71
  migrateTo: async (version, options) => {
128
- if (version !== "0.31.0") throw new Error(`Invalid version ${version}`);
72
+ if (version !== "1.0.0") throw new Error(`Invalid version ${version}`);
129
73
  return makeResult(options);
130
74
  },
131
75
  migrateToLatest: makeResult
@@ -133,4 +77,3 @@ const createMongoMigrator = (client) => {
133
77
  };
134
78
  //#endregion
135
79
  exports.createKyselyMigrator = createKyselyMigrator;
136
- exports.createMongoMigrator = createMongoMigrator;