@hot-updater/server 0.33.2 → 0.34.0

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 (198) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +0 -2
  2. package/dist/adapters/drizzle.cjs +195 -2
  3. package/dist/adapters/drizzle.d.cts +7 -4
  4. package/dist/adapters/drizzle.d.mts +7 -4
  5. package/dist/adapters/drizzle.mjs +194 -2
  6. package/dist/adapters/drizzleLazyDB.cjs +53 -0
  7. package/dist/adapters/drizzleLazyDB.mjs +53 -0
  8. package/dist/adapters/kysely.cjs +154 -3
  9. package/dist/adapters/kysely.d.cts +18 -10
  10. package/dist/adapters/kysely.d.mts +18 -10
  11. package/dist/adapters/kysely.mjs +153 -3
  12. package/dist/adapters/mongodb.cjs +183 -2
  13. package/dist/adapters/mongodb.d.cts +5 -4
  14. package/dist/adapters/mongodb.d.mts +5 -4
  15. package/dist/adapters/mongodb.mjs +183 -2
  16. package/dist/adapters/prisma.cjs +200 -2
  17. package/dist/adapters/prisma.d.cts +9 -4
  18. package/dist/adapters/prisma.d.mts +9 -4
  19. package/dist/adapters/prisma.mjs +199 -2
  20. package/dist/db/bundleRows.cjs +82 -0
  21. package/dist/db/bundleRows.d.cts +33 -0
  22. package/dist/db/bundleRows.d.mts +33 -0
  23. package/dist/db/bundleRows.mjs +79 -0
  24. package/dist/db/fixedMigrator.cjs +136 -0
  25. package/dist/db/fixedMigrator.mjs +135 -0
  26. package/dist/db/index.cjs +17 -15
  27. package/dist/db/index.d.cts +3 -3
  28. package/dist/db/index.d.mts +3 -3
  29. package/dist/db/index.mjs +17 -15
  30. package/dist/db/pluginCore.cjs +13 -5
  31. package/dist/db/pluginCore.mjs +13 -5
  32. package/dist/db/schema/mongodb.cjs +17 -0
  33. package/dist/db/schema/mongodb.mjs +17 -0
  34. package/dist/db/schema/registry.cjs +23 -0
  35. package/dist/db/schema/registry.mjs +18 -0
  36. package/dist/db/schema/sql.cjs +84 -0
  37. package/dist/db/schema/sql.mjs +78 -0
  38. package/dist/db/schema/sqlMigrations.cjs +74 -0
  39. package/dist/db/schema/sqlMigrations.mjs +73 -0
  40. package/dist/db/schema/sqlOperations.cjs +27 -0
  41. package/dist/db/schema/sqlOperations.mjs +26 -0
  42. package/dist/db/schemaEnhancements.cjs +1 -152
  43. package/dist/db/schemaEnhancements.mjs +1 -149
  44. package/dist/db/schemaGenerators.cjs +222 -0
  45. package/dist/db/schemaGenerators.mjs +220 -0
  46. package/dist/db/schemaReadiness.cjs +23 -0
  47. package/dist/db/schemaReadiness.d.cts +8 -0
  48. package/dist/db/schemaReadiness.d.mts +8 -0
  49. package/dist/db/schemaReadiness.mjs +22 -0
  50. package/dist/db/types.cjs +10 -2
  51. package/dist/db/types.d.cts +58 -14
  52. package/dist/db/types.d.mts +58 -14
  53. package/dist/db/types.mjs +9 -1
  54. package/dist/index.cjs +2 -2
  55. package/dist/index.d.cts +3 -2
  56. package/dist/index.d.mts +3 -2
  57. package/dist/index.mjs +2 -2
  58. package/dist/{packages/server/package.cjs → package.cjs} +1 -1
  59. package/dist/{packages/server/package.mjs → package.mjs} +1 -1
  60. package/dist/runtime.cjs +9 -2
  61. package/dist/runtime.mjs +9 -2
  62. package/dist/schema/dsl.cjs +86 -0
  63. package/dist/schema/dsl.mjs +73 -0
  64. package/dist/schema/index.cjs +13 -0
  65. package/dist/schema/index.mjs +13 -0
  66. package/dist/schema/settings.cjs +9 -0
  67. package/dist/schema/settings.mjs +9 -0
  68. package/dist/schema/types.cjs +6 -0
  69. package/dist/schema/types.mjs +5 -0
  70. package/dist/schema/v0_21_0.cjs +33 -18
  71. package/dist/schema/v0_21_0.mjs +32 -18
  72. package/dist/schema/v0_29_0.cjs +40 -20
  73. package/dist/schema/v0_29_0.mjs +39 -20
  74. package/dist/schema/v0_31_0.cjs +77 -43
  75. package/dist/schema/v0_31_0.mjs +75 -43
  76. package/dist/version.cjs +1 -1
  77. package/dist/version.mjs +1 -1
  78. package/package.json +30 -16
  79. package/src/adapters/drizzle.spec.ts +75 -0
  80. package/src/adapters/drizzle.ts +328 -12
  81. package/src/adapters/drizzleLazyDB.ts +151 -0
  82. package/src/adapters/kysely.spec.ts +107 -0
  83. package/src/adapters/kysely.ts +349 -14
  84. package/src/adapters/mongodb.ts +298 -15
  85. package/src/adapters/prisma.ts +337 -12
  86. package/src/db/bundleRows.ts +140 -0
  87. package/src/db/fixedMigrator.spec.ts +89 -0
  88. package/src/db/fixedMigrator.ts +288 -0
  89. package/src/db/hotUpdaterSchema.ts +6 -0
  90. package/src/db/index.spec.ts +976 -13
  91. package/src/db/index.ts +37 -36
  92. package/src/db/pluginCore.spec.ts +17 -11
  93. package/src/db/pluginCore.ts +15 -6
  94. package/src/db/schema/definitions.ts +1 -0
  95. package/src/db/schema/mongodb.ts +26 -0
  96. package/src/db/schema/registry.ts +55 -0
  97. package/src/db/schema/sql.ts +200 -0
  98. package/src/db/schema/sqlMigrations.ts +219 -0
  99. package/src/db/schema/sqlOperations.ts +62 -0
  100. package/src/db/schema/types.ts +1 -0
  101. package/src/db/schemaEnhancements.ts +0 -405
  102. package/src/db/schemaGenerators.ts +382 -0
  103. package/src/db/schemaReadiness.ts +33 -0
  104. package/src/db/types.ts +69 -25
  105. package/src/runtime.spec.ts +70 -0
  106. package/src/runtime.ts +14 -2
  107. package/src/schema/dsl-all-versions.spec.ts +26 -0
  108. package/src/schema/dsl.ts +148 -0
  109. package/src/schema/index.ts +16 -0
  110. package/src/schema/settings.ts +15 -0
  111. package/src/schema/types.ts +73 -0
  112. package/src/schema/v0_21_0.ts +48 -18
  113. package/src/schema/v0_29_0.ts +58 -22
  114. package/src/schema/v0_31_0.spec.ts +73 -0
  115. package/src/schema/v0_31_0.ts +116 -54
  116. package/dist/_virtual/_rolldown/runtime.mjs +0 -6
  117. package/dist/calculatePagination.cjs +0 -25
  118. package/dist/calculatePagination.mjs +0 -25
  119. package/dist/db/ormCore.cjs +0 -577
  120. package/dist/db/ormCore.d.cts +0 -110
  121. package/dist/db/ormCore.d.mts +0 -110
  122. package/dist/db/ormCore.mjs +0 -575
  123. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.cjs +0 -112
  124. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.mjs +0 -108
  125. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.cjs +0 -22
  126. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.mjs +0 -18
  127. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.cjs +0 -219
  128. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.mjs +0 -214
  129. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.cjs +0 -275
  130. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.mjs +0 -270
  131. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.cjs +0 -17
  132. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.mjs +0 -13
  133. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.cjs +0 -69
  134. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.mjs +0 -65
  135. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/column.cjs +0 -52
  136. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/column.mjs +0 -52
  137. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/entity.cjs +0 -16
  138. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/entity.mjs +0 -15
  139. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/pg-core/columns/enum.cjs +0 -7
  140. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/pg-core/columns/enum.mjs +0 -7
  141. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/conditions.cjs +0 -92
  142. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/conditions.mjs +0 -78
  143. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/select.cjs +0 -11
  144. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/expressions/select.mjs +0 -10
  145. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/sql.cjs +0 -383
  146. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/sql/sql.mjs +0 -366
  147. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/subquery.cjs +0 -17
  148. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/subquery.mjs +0 -17
  149. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.cjs +0 -60
  150. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.mjs +0 -59
  151. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.utils.cjs +0 -4
  152. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/table.utils.mjs +0 -4
  153. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/tracing.cjs +0 -6
  154. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/tracing.mjs +0 -6
  155. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/view-common.cjs +0 -4
  156. package/dist/node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare_workers-types@4.20260611.1_@electric-sql_pglite@0.4.1_@l_601a3995dfc55b0b7fac93cbe1e76579/node_modules/drizzle-orm/view-common.mjs +0 -4
  157. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.cjs +0 -383
  158. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.d.cts +0 -12
  159. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.d.mts +0 -12
  160. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/drizzle/index.mjs +0 -383
  161. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/kysely/index.cjs +0 -4
  162. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/kysely/index.mjs +0 -5
  163. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.cjs +0 -339
  164. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.d.cts +0 -70
  165. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.d.mts +0 -70
  166. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/adapters/prisma/index.mjs +0 -339
  167. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-7PZK4ONR.cjs +0 -57
  168. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-7PZK4ONR.mjs +0 -56
  169. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-C6OTUURW.cjs +0 -330
  170. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-C6OTUURW.mjs +0 -326
  171. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-CHTIKPQU.cjs +0 -166
  172. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-CHTIKPQU.mjs +0 -163
  173. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-GUE4GMNC.cjs +0 -14
  174. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-GUE4GMNC.mjs +0 -13
  175. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LHHP6UVP.cjs +0 -24
  176. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LHHP6UVP.mjs +0 -24
  177. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LVCPMTAT.cjs +0 -1190
  178. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-LVCPMTAT.mjs +0 -1189
  179. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-PK2W2SQ7.cjs +0 -197
  180. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-PK2W2SQ7.mjs +0 -197
  181. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZEQMAIFI.cjs +0 -410
  182. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZEQMAIFI.mjs +0 -400
  183. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZOCGSAWS.cjs +0 -213
  184. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/chunk-ZOCGSAWS.mjs +0 -212
  185. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/create-tg0451Y_.d.cts +0 -285
  186. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/create-tg0451Y_.d.mts +0 -285
  187. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index-CMqePMTF.d.cts +0 -45
  188. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index-CMqePMTF.d.mts +0 -45
  189. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.cjs +0 -69
  190. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.d.cts +0 -49
  191. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.d.mts +0 -49
  192. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/index.mjs +0 -67
  193. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/query/index.d.cts +0 -156
  194. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/query/index.d.mts +0 -156
  195. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/schema/index.cjs +0 -1
  196. package/dist/node_modules/.pnpm/fumadb@0.2.2_mongodb@6.20.0_@aws-sdk_credential-providers@3.1066.0_socks@2.8.9__prisma@_ee79457f0e32f18f0beb5c2db02e4f73/node_modules/fumadb/dist/schema/index.mjs +0 -2
  197. package/src/db/ormCore.ts +0 -1059
  198. package/src/db/ormUpdateCheck.bench.ts +0 -262
package/src/db/ormCore.ts DELETED
@@ -1,1059 +0,0 @@
1
- import type {
2
- AppUpdateAvailableInfo,
3
- AppVersionGetBundlesArgs,
4
- Bundle,
5
- BundlePatchArtifact,
6
- FingerprintGetBundlesArgs,
7
- GetBundlesArgs,
8
- Platform,
9
- UpdateInfo,
10
- } from "@hot-updater/core";
11
- import {
12
- getAssetBaseStorageUri,
13
- getBundlePatches,
14
- getManifestFileHash,
15
- getManifestStorageUri,
16
- DEFAULT_ROLLOUT_COHORT_COUNT,
17
- isCohortEligibleForUpdate,
18
- NIL_UUID,
19
- stripBundleArtifactMetadata,
20
- } from "@hot-updater/core";
21
- import type {
22
- DatabaseBundleCursor,
23
- DatabaseBundleIdFilter,
24
- DatabaseBundleQueryOrder,
25
- DatabaseBundleQueryOptions,
26
- DatabaseBundleQueryWhere,
27
- HotUpdaterContext,
28
- } from "@hot-updater/plugin-core";
29
- import { semverSatisfies } from "@hot-updater/plugin-core";
30
- import type { InferFumaDB } from "fumadb";
31
- import { fumadb } from "fumadb";
32
-
33
- import { calculatePagination } from "../calculatePagination";
34
- import { v0_21_0 } from "../schema/v0_21_0";
35
- import { v0_29_0 } from "../schema/v0_29_0";
36
- import { v0_31_0 } from "../schema/v0_31_0";
37
- import type { Paginated } from "../types";
38
- import {
39
- assertBundlePersistenceConstraints,
40
- enhanceGeneratedSchema,
41
- wrapKyselyMigrator,
42
- } from "./schemaEnhancements";
43
- import {
44
- getSQLProvider,
45
- type DatabaseAPI,
46
- type ORMDatabaseAdapter,
47
- } from "./types";
48
- import {
49
- parseBundleMetadata,
50
- resolveManifestArtifacts,
51
- } from "./updateArtifacts";
52
-
53
- const parseTargetCohorts = (value: unknown): string[] | null => {
54
- if (!value) return null;
55
- if (Array.isArray(value)) {
56
- return value.filter((v): v is string => typeof v === "string");
57
- }
58
- if (typeof value === "string") {
59
- try {
60
- const parsed = JSON.parse(value) as unknown;
61
- if (Array.isArray(parsed)) {
62
- return parsed.filter((v): v is string => typeof v === "string");
63
- }
64
- } catch {
65
- return null;
66
- }
67
- }
68
- return null;
69
- };
70
-
71
- const schemas: [typeof v0_21_0, typeof v0_29_0, typeof v0_31_0] = [
72
- v0_21_0,
73
- v0_29_0,
74
- v0_31_0,
75
- ];
76
-
77
- const getLastItem = <T extends unknown[]>(
78
- items: T,
79
- ): T extends [...infer _, infer Last] ? Last : never =>
80
- items.at(-1) as T extends [...infer _, infer Last] ? Last : never;
81
-
82
- const DEFAULT_BUNDLE_ORDER = { field: "id", direction: "desc" } as const;
83
-
84
- type BundleRecord = {
85
- id: string;
86
- platform: string;
87
- should_force_update: unknown;
88
- enabled: unknown;
89
- file_hash: string;
90
- git_commit_hash: string | null;
91
- message: string | null;
92
- channel: string;
93
- storage_uri: string;
94
- target_app_version: string | null;
95
- fingerprint_hash: string | null;
96
- metadata?: unknown;
97
- manifest_storage_uri?: string | null;
98
- manifest_file_hash?: string | null;
99
- asset_base_storage_uri?: string | null;
100
- rollout_cohort_count?: number | null;
101
- target_cohorts?: unknown;
102
- };
103
-
104
- type BundlePatchRecord = {
105
- id: string;
106
- bundle_id: string;
107
- base_bundle_id: string;
108
- base_file_hash: string;
109
- patch_file_hash: string;
110
- patch_storage_uri: string;
111
- order_index?: number | null;
112
- };
113
-
114
- const buildBundlePatchId = (bundleId: string, baseBundleId: string) =>
115
- `${bundleId}:${baseBundleId}`;
116
-
117
- const toBundlePatchRecords = (
118
- bundle: Pick<
119
- Bundle,
120
- | "id"
121
- | "patches"
122
- | "patchBaseBundleId"
123
- | "patchBaseFileHash"
124
- | "patchFileHash"
125
- | "patchStorageUri"
126
- | "metadata"
127
- >,
128
- ): BundlePatchRecord[] =>
129
- getBundlePatches(bundle).map((patch, index) => ({
130
- id: buildBundlePatchId(bundle.id, patch.baseBundleId),
131
- bundle_id: bundle.id,
132
- base_bundle_id: patch.baseBundleId,
133
- base_file_hash: patch.baseFileHash,
134
- patch_file_hash: patch.patchFileHash,
135
- patch_storage_uri: patch.patchStorageUri,
136
- order_index: index,
137
- }));
138
-
139
- const mapPatchRecordToPatch = (
140
- record: BundlePatchRecord,
141
- ): BundlePatchArtifact => ({
142
- baseBundleId: record.base_bundle_id,
143
- baseFileHash: record.base_file_hash,
144
- patchFileHash: record.patch_file_hash,
145
- patchStorageUri: record.patch_storage_uri,
146
- });
147
-
148
- const mergeIdFilter = (
149
- base: DatabaseBundleIdFilter | undefined,
150
- patch: DatabaseBundleIdFilter,
151
- ): DatabaseBundleIdFilter => ({
152
- ...base,
153
- ...patch,
154
- });
155
-
156
- const mergeWhereWithIdFilter = (
157
- where: DatabaseBundleQueryWhere | undefined,
158
- idFilter: DatabaseBundleIdFilter,
159
- ): DatabaseBundleQueryWhere => ({
160
- ...where,
161
- id: mergeIdFilter(where?.id, idFilter),
162
- });
163
-
164
- const buildCursorPageWhere = (
165
- where: DatabaseBundleQueryWhere | undefined,
166
- cursor: DatabaseBundleCursor,
167
- orderBy: DatabaseBundleQueryOrder,
168
- ): {
169
- reverseData: boolean;
170
- where: DatabaseBundleQueryWhere;
171
- orderBy: DatabaseBundleQueryOrder;
172
- } => {
173
- const direction = orderBy.direction;
174
-
175
- if (cursor.after) {
176
- return {
177
- reverseData: false,
178
- where: mergeWhereWithIdFilter(where, {
179
- [direction === "desc" ? "lt" : "gt"]: cursor.after,
180
- }),
181
- orderBy,
182
- };
183
- }
184
-
185
- if (cursor.before) {
186
- return {
187
- reverseData: true,
188
- where: mergeWhereWithIdFilter(where, {
189
- [direction === "desc" ? "gt" : "lt"]: cursor.before,
190
- }),
191
- orderBy: {
192
- field: orderBy.field,
193
- direction: direction === "desc" ? "asc" : "desc",
194
- },
195
- };
196
- }
197
-
198
- return {
199
- reverseData: false,
200
- where: where ?? {},
201
- orderBy,
202
- };
203
- };
204
-
205
- const buildCountBeforeWhere = (
206
- where: DatabaseBundleQueryWhere | undefined,
207
- firstBundleId: string,
208
- orderBy: DatabaseBundleQueryOrder,
209
- ): DatabaseBundleQueryWhere =>
210
- mergeWhereWithIdFilter(where, {
211
- [orderBy.direction === "desc" ? "gt" : "lt"]: firstBundleId,
212
- });
213
-
214
- export const HotUpdaterDB = fumadb({
215
- namespace: "hot_updater",
216
- schemas,
217
- });
218
- export type HotUpdaterClient = InferFumaDB<typeof HotUpdaterDB>;
219
-
220
- export type Migrator = ReturnType<HotUpdaterClient["createMigrator"]>;
221
-
222
- export function createOrmDatabaseCore<TContext = unknown>({
223
- database,
224
- resolveFileUrl,
225
- readStorageText,
226
- }: {
227
- database: ORMDatabaseAdapter;
228
- resolveFileUrl: (
229
- storageUri: string | null,
230
- context?: HotUpdaterContext<TContext>,
231
- ) => Promise<string | null>;
232
- readStorageText?: (
233
- storageUri: string,
234
- context?: HotUpdaterContext<TContext>,
235
- ) => Promise<string | null>;
236
- }): {
237
- api: DatabaseAPI<TContext>;
238
- adapterName: string;
239
- createMigrator: () => Migrator;
240
- generateSchema: HotUpdaterClient["generateSchema"];
241
- } {
242
- const client = HotUpdaterDB.client(
243
- database as Parameters<typeof HotUpdaterDB.client>[0],
244
- );
245
- const UPDATE_CHECK_PAGE_SIZE = 100;
246
- const isMongoAdapter = client.adapter.name.toLowerCase().includes("mongodb");
247
- const latestSchema = getLastItem(schemas);
248
- const lastSchemaVersion = latestSchema.version;
249
-
250
- const ensureORM = async () => {
251
- try {
252
- const migrator = client.createMigrator();
253
- const currentVersion = await migrator.getVersion();
254
-
255
- if (currentVersion === undefined) {
256
- throw new Error(
257
- "Database is not initialized. Please run 'npx hot-updater migrate' to set up the database schema.",
258
- );
259
- }
260
-
261
- if (currentVersion !== lastSchemaVersion) {
262
- throw new Error(
263
- `Database schema version mismatch. Expected version ${lastSchemaVersion}, but database is on version ${currentVersion}. ` +
264
- "Please run 'npx hot-updater migrate' to update your database schema.",
265
- );
266
- }
267
-
268
- return client.orm(lastSchemaVersion);
269
- } catch (error) {
270
- if (
271
- error instanceof Error &&
272
- error.message.includes("doesn't support migration")
273
- ) {
274
- return client.orm(lastSchemaVersion);
275
- }
276
- throw error;
277
- }
278
- };
279
-
280
- const buildBundleWhere = (where?: DatabaseBundleQueryWhere) => (b: any) => {
281
- if (where?.id?.in && where.id.in.length === 0) {
282
- return false;
283
- }
284
-
285
- if (where?.targetAppVersionIn && where.targetAppVersionIn.length === 0) {
286
- return false;
287
- }
288
-
289
- const conditions = [];
290
-
291
- if (where?.channel !== undefined) {
292
- conditions.push(b("channel", "=", where.channel));
293
- }
294
- if (where?.platform !== undefined) {
295
- conditions.push(b("platform", "=", where.platform));
296
- }
297
- if (where?.enabled !== undefined) {
298
- conditions.push(b("enabled", "=", where.enabled));
299
- }
300
- if (where?.id?.eq !== undefined) {
301
- conditions.push(b("id", "=", where.id.eq));
302
- }
303
- if (where?.id?.gt !== undefined) {
304
- conditions.push(b("id", ">", where.id.gt));
305
- }
306
- if (where?.id?.gte !== undefined) {
307
- conditions.push(b("id", ">=", where.id.gte));
308
- }
309
- if (where?.id?.lt !== undefined) {
310
- conditions.push(b("id", "<", where.id.lt));
311
- }
312
- if (where?.id?.lte !== undefined) {
313
- conditions.push(b("id", "<=", where.id.lte));
314
- }
315
- if (where?.id?.in) {
316
- conditions.push(b("id", "in", where.id.in));
317
- }
318
- if (where?.targetAppVersionNotNull) {
319
- conditions.push(b.isNotNull("target_app_version"));
320
- }
321
- if (where?.targetAppVersion !== undefined) {
322
- conditions.push(
323
- where.targetAppVersion === null
324
- ? b.isNull("target_app_version")
325
- : b("target_app_version", "=", where.targetAppVersion),
326
- );
327
- }
328
- if (where?.targetAppVersionIn) {
329
- conditions.push(b("target_app_version", "in", where.targetAppVersionIn));
330
- }
331
- if (where?.fingerprintHash !== undefined) {
332
- conditions.push(
333
- where.fingerprintHash === null
334
- ? b.isNull("fingerprint_hash")
335
- : b("fingerprint_hash", "=", where.fingerprintHash),
336
- );
337
- }
338
-
339
- return conditions.length > 0 ? b.and(...conditions) : true;
340
- };
341
-
342
- const mapBundleRecordToBundle = (
343
- record: BundleRecord,
344
- patchRecords: BundlePatchRecord[] = [],
345
- ): Bundle => {
346
- const patches = patchRecords
347
- .slice()
348
- .sort(
349
- (left, right) =>
350
- (left.order_index ?? 0) - (right.order_index ?? 0) ||
351
- left.base_bundle_id.localeCompare(right.base_bundle_id),
352
- )
353
- .map(mapPatchRecordToPatch);
354
- const primaryPatch = patches[0] ?? null;
355
-
356
- return {
357
- id: record.id,
358
- platform: record.platform as Platform,
359
- shouldForceUpdate: Boolean(record.should_force_update),
360
- enabled: Boolean(record.enabled),
361
- fileHash: record.file_hash,
362
- gitCommitHash: record.git_commit_hash ?? null,
363
- message: record.message ?? null,
364
- channel: record.channel,
365
- storageUri: record.storage_uri,
366
- targetAppVersion: record.target_app_version ?? null,
367
- fingerprintHash: record.fingerprint_hash ?? null,
368
- metadata: parseBundleMetadata(record.metadata),
369
- manifestStorageUri: record.manifest_storage_uri ?? null,
370
- manifestFileHash: record.manifest_file_hash ?? null,
371
- assetBaseStorageUri: record.asset_base_storage_uri ?? null,
372
- patches,
373
- patchBaseBundleId: primaryPatch?.baseBundleId ?? null,
374
- patchBaseFileHash: primaryPatch?.baseFileHash ?? null,
375
- patchFileHash: primaryPatch?.patchFileHash ?? null,
376
- patchStorageUri: primaryPatch?.patchStorageUri ?? null,
377
- rolloutCohortCount:
378
- record.rollout_cohort_count ?? DEFAULT_ROLLOUT_COHORT_COUNT,
379
- targetCohorts: parseTargetCohorts(record.target_cohorts),
380
- };
381
- };
382
-
383
- const fetchBundlePatchMap = async (
384
- orm: Awaited<ReturnType<typeof ensureORM>>,
385
- bundleIds: string[],
386
- ): Promise<Map<string, BundlePatchRecord[]>> => {
387
- const patchMap = new Map<string, BundlePatchRecord[]>();
388
-
389
- if (bundleIds.length === 0) {
390
- return patchMap;
391
- }
392
-
393
- const patchRows = await orm.findMany("bundle_patches", {
394
- select: [
395
- "id",
396
- "bundle_id",
397
- "base_bundle_id",
398
- "base_file_hash",
399
- "patch_file_hash",
400
- "patch_storage_uri",
401
- "order_index",
402
- ],
403
- where: (b) => b("bundle_id", "in", bundleIds),
404
- });
405
-
406
- for (const row of patchRows) {
407
- const current = patchMap.get(row.bundle_id) ?? [];
408
- current.push(row);
409
- patchMap.set(row.bundle_id, current);
410
- }
411
-
412
- return patchMap;
413
- };
414
-
415
- const fetchBundleById = async (id: string): Promise<Bundle | null> => {
416
- const orm = await ensureORM();
417
- const result = await orm.findFirst("bundles", {
418
- select: [
419
- "id",
420
- "platform",
421
- "should_force_update",
422
- "enabled",
423
- "file_hash",
424
- "git_commit_hash",
425
- "message",
426
- "channel",
427
- "storage_uri",
428
- "target_app_version",
429
- "fingerprint_hash",
430
- "metadata",
431
- "manifest_storage_uri",
432
- "manifest_file_hash",
433
- "asset_base_storage_uri",
434
- "rollout_cohort_count",
435
- "target_cohorts",
436
- ],
437
- where: (b) => b("id", "=", id),
438
- });
439
-
440
- if (!result) {
441
- return null;
442
- }
443
-
444
- const patchMap = await fetchBundlePatchMap(orm, [id]);
445
- return mapBundleRecordToBundle(result, patchMap.get(id) ?? []);
446
- };
447
-
448
- const api: DatabaseAPI<TContext> = {
449
- async getBundleById(id: string): Promise<Bundle | null> {
450
- return fetchBundleById(id);
451
- },
452
-
453
- async getUpdateInfo(args: GetBundlesArgs): Promise<UpdateInfo | null> {
454
- const orm = await ensureORM();
455
-
456
- type UpdateSelectRow = {
457
- id: string;
458
- should_force_update: boolean;
459
- message: string | null;
460
- storage_uri: string | null;
461
- file_hash: string;
462
- rollout_cohort_count?: number | null;
463
- target_cohorts?: unknown | null;
464
- target_app_version?: string | null;
465
- fingerprint_hash?: string | null;
466
- };
467
-
468
- const toUpdateInfo = (
469
- row: UpdateSelectRow,
470
- status: "UPDATE" | "ROLLBACK",
471
- ): UpdateInfo => ({
472
- id: row.id,
473
- shouldForceUpdate:
474
- status === "ROLLBACK" ? true : Boolean(row.should_force_update),
475
- message: row.message ?? null,
476
- status,
477
- storageUri: row.storage_uri ?? null,
478
- fileHash: row.file_hash ?? null,
479
- });
480
-
481
- const INIT_BUNDLE_ROLLBACK_UPDATE_INFO: UpdateInfo = {
482
- id: NIL_UUID,
483
- message: null,
484
- shouldForceUpdate: true,
485
- status: "ROLLBACK",
486
- storageUri: null,
487
- fileHash: null,
488
- };
489
-
490
- const isEligibleForUpdate = (
491
- row: UpdateSelectRow,
492
- cohort: string | undefined,
493
- ): boolean => {
494
- return isCohortEligibleForUpdate(
495
- row.id,
496
- cohort,
497
- row.rollout_cohort_count ?? null,
498
- parseTargetCohorts(row.target_cohorts),
499
- );
500
- };
501
-
502
- const findUpdateInfoByScanning = async ({
503
- args,
504
- where,
505
- isCandidate,
506
- }: {
507
- args: AppVersionGetBundlesArgs | FingerprintGetBundlesArgs;
508
- where: DatabaseBundleQueryWhere;
509
- isCandidate: (row: UpdateSelectRow) => boolean;
510
- }): Promise<UpdateInfo | null> => {
511
- if (isMongoAdapter) {
512
- const rows = await orm.findMany("bundles", {
513
- select: [
514
- "id",
515
- "should_force_update",
516
- "message",
517
- "storage_uri",
518
- "file_hash",
519
- "rollout_cohort_count",
520
- "target_cohorts",
521
- "target_app_version",
522
- "fingerprint_hash",
523
- ],
524
- where: buildBundleWhere(where),
525
- });
526
-
527
- rows.sort((a, b) => b.id.localeCompare(a.id));
528
-
529
- for (const row of rows) {
530
- if (!isCandidate(row)) {
531
- continue;
532
- }
533
-
534
- if (args.bundleId === NIL_UUID) {
535
- if (isEligibleForUpdate(row, args.cohort)) {
536
- return toUpdateInfo(row, "UPDATE");
537
- }
538
- continue;
539
- }
540
-
541
- const compareResult = row.id.localeCompare(args.bundleId);
542
-
543
- if (compareResult > 0) {
544
- if (isEligibleForUpdate(row, args.cohort)) {
545
- return toUpdateInfo(row, "UPDATE");
546
- }
547
- continue;
548
- }
549
-
550
- if (compareResult === 0) {
551
- if (isEligibleForUpdate(row, args.cohort)) {
552
- return null;
553
- }
554
- continue;
555
- }
556
-
557
- return toUpdateInfo(row, "ROLLBACK");
558
- }
559
-
560
- if (args.bundleId === NIL_UUID) {
561
- return null;
562
- }
563
-
564
- if (
565
- args.minBundleId &&
566
- args.bundleId.localeCompare(args.minBundleId) <= 0
567
- ) {
568
- return null;
569
- }
570
-
571
- return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
572
- }
573
-
574
- let offset = 0;
575
-
576
- while (true) {
577
- const rows = await orm.findMany("bundles", {
578
- select: [
579
- "id",
580
- "should_force_update",
581
- "message",
582
- "storage_uri",
583
- "file_hash",
584
- "rollout_cohort_count",
585
- "target_cohorts",
586
- "target_app_version",
587
- "fingerprint_hash",
588
- ],
589
- where: buildBundleWhere(where),
590
- orderBy: [["id", "desc"]],
591
- limit: UPDATE_CHECK_PAGE_SIZE,
592
- offset,
593
- });
594
-
595
- for (const row of rows) {
596
- if (!isCandidate(row)) {
597
- continue;
598
- }
599
-
600
- if (args.bundleId === NIL_UUID) {
601
- if (isEligibleForUpdate(row, args.cohort)) {
602
- return toUpdateInfo(row, "UPDATE");
603
- }
604
- continue;
605
- }
606
-
607
- const compareResult = row.id.localeCompare(args.bundleId);
608
-
609
- if (compareResult > 0) {
610
- if (isEligibleForUpdate(row, args.cohort)) {
611
- return toUpdateInfo(row, "UPDATE");
612
- }
613
- continue;
614
- }
615
-
616
- if (compareResult === 0) {
617
- if (isEligibleForUpdate(row, args.cohort)) {
618
- return null;
619
- }
620
- continue;
621
- }
622
-
623
- return toUpdateInfo(row, "ROLLBACK");
624
- }
625
-
626
- if (rows.length < UPDATE_CHECK_PAGE_SIZE) {
627
- break;
628
- }
629
-
630
- offset += UPDATE_CHECK_PAGE_SIZE;
631
- }
632
-
633
- if (args.bundleId === NIL_UUID) {
634
- return null;
635
- }
636
-
637
- if (
638
- args.minBundleId &&
639
- args.bundleId.localeCompare(args.minBundleId) <= 0
640
- ) {
641
- return null;
642
- }
643
-
644
- return INIT_BUNDLE_ROLLBACK_UPDATE_INFO;
645
- };
646
-
647
- const appVersionStrategy = async ({
648
- platform,
649
- appVersion,
650
- bundleId,
651
- minBundleId = NIL_UUID,
652
- channel = "production",
653
- cohort,
654
- }: AppVersionGetBundlesArgs): Promise<UpdateInfo | null> => {
655
- return findUpdateInfoByScanning({
656
- args: {
657
- _updateStrategy: "appVersion",
658
- platform,
659
- appVersion,
660
- bundleId,
661
- minBundleId,
662
- channel,
663
- cohort,
664
- },
665
- where: {
666
- enabled: true,
667
- platform,
668
- channel,
669
- id: {
670
- gte: minBundleId,
671
- },
672
- targetAppVersionNotNull: true,
673
- },
674
- isCandidate: (row) =>
675
- !!row.target_app_version &&
676
- semverSatisfies(row.target_app_version, appVersion),
677
- });
678
- };
679
-
680
- const fingerprintStrategy = async ({
681
- platform,
682
- fingerprintHash,
683
- bundleId,
684
- minBundleId = NIL_UUID,
685
- channel = "production",
686
- cohort,
687
- }: FingerprintGetBundlesArgs): Promise<UpdateInfo | null> => {
688
- return findUpdateInfoByScanning({
689
- args: {
690
- _updateStrategy: "fingerprint",
691
- platform,
692
- fingerprintHash,
693
- bundleId,
694
- minBundleId,
695
- channel,
696
- cohort,
697
- },
698
- where: {
699
- enabled: true,
700
- platform,
701
- channel,
702
- id: {
703
- gte: minBundleId,
704
- },
705
- fingerprintHash,
706
- },
707
- isCandidate: (row) => row.fingerprint_hash === fingerprintHash,
708
- });
709
- };
710
-
711
- if (args._updateStrategy === "appVersion") {
712
- return appVersionStrategy(args);
713
- }
714
- if (args._updateStrategy === "fingerprint") {
715
- return fingerprintStrategy(args);
716
- }
717
- return null;
718
- },
719
-
720
- async getAppUpdateInfo(
721
- args: GetBundlesArgs,
722
- context?: HotUpdaterContext<TContext>,
723
- ): Promise<AppUpdateAvailableInfo | null> {
724
- const info = await this.getUpdateInfo(args);
725
- if (!info) return null;
726
- const { storageUri, ...rest } = info as UpdateInfo & {
727
- storageUri: string | null;
728
- };
729
- if (!readStorageText) {
730
- const fileUrl = await resolveFileUrl(storageUri ?? null, context);
731
- const baseResponse = { ...rest, fileUrl };
732
- return baseResponse;
733
- }
734
-
735
- const [fileUrl, currentBundle, targetBundle] = await Promise.all([
736
- resolveFileUrl(storageUri ?? null, context),
737
- args.bundleId !== NIL_UUID ? fetchBundleById(args.bundleId) : null,
738
- info.id !== NIL_UUID ? fetchBundleById(info.id) : null,
739
- ]);
740
- const baseResponse = { ...rest, fileUrl };
741
- const manifestArtifacts = await resolveManifestArtifacts({
742
- currentBundle,
743
- resolveFileUrl,
744
- readStorageText,
745
- targetBundle,
746
- context,
747
- });
748
-
749
- if (!manifestArtifacts) {
750
- return baseResponse;
751
- }
752
-
753
- return {
754
- ...baseResponse,
755
- ...manifestArtifacts,
756
- };
757
- },
758
-
759
- async getChannels(): Promise<string[]> {
760
- const orm = await ensureORM();
761
- const rows = await orm.findMany("bundles", {
762
- select: ["channel"],
763
- orderBy: [["channel", "asc"]],
764
- });
765
- const set = new Set(rows?.map((r) => r.channel) ?? []);
766
- return Array.from(set);
767
- },
768
-
769
- async getBundles(
770
- options: DatabaseBundleQueryOptions,
771
- ): Promise<Paginated<Bundle[]>> {
772
- const orm = await ensureORM();
773
- const { where, limit } = options;
774
- const orderBy = options.orderBy ?? DEFAULT_BUNDLE_ORDER;
775
- const offset =
776
- (("offset" in options ? options.offset : undefined) as
777
- | number
778
- | undefined) ?? 0;
779
-
780
- const total = await orm.count("bundles", {
781
- where: buildBundleWhere(where),
782
- });
783
-
784
- const selectedColumns: Array<
785
- | "id"
786
- | "platform"
787
- | "should_force_update"
788
- | "enabled"
789
- | "file_hash"
790
- | "git_commit_hash"
791
- | "message"
792
- | "channel"
793
- | "storage_uri"
794
- | "target_app_version"
795
- | "fingerprint_hash"
796
- | "metadata"
797
- | "manifest_storage_uri"
798
- | "manifest_file_hash"
799
- | "asset_base_storage_uri"
800
- | "rollout_cohort_count"
801
- | "target_cohorts"
802
- > = [
803
- "id",
804
- "platform",
805
- "should_force_update",
806
- "enabled",
807
- "file_hash",
808
- "git_commit_hash",
809
- "message",
810
- "channel",
811
- "storage_uri",
812
- "target_app_version",
813
- "fingerprint_hash",
814
- "metadata",
815
- "manifest_storage_uri",
816
- "manifest_file_hash",
817
- "asset_base_storage_uri",
818
- "rollout_cohort_count",
819
- "target_cohorts",
820
- ];
821
-
822
- const findBundles = async ({
823
- where,
824
- orderBy,
825
- limit,
826
- offset,
827
- }: {
828
- where?: DatabaseBundleQueryWhere;
829
- orderBy: DatabaseBundleQueryOrder;
830
- limit: number;
831
- offset: number;
832
- }) => {
833
- const rows = isMongoAdapter
834
- ? (
835
- await orm.findMany("bundles", {
836
- select: selectedColumns,
837
- where: buildBundleWhere(where),
838
- })
839
- )
840
- .sort((a, b) => {
841
- const result = a.id.localeCompare(b.id);
842
- return orderBy.direction === "asc" ? result : -result;
843
- })
844
- .slice(offset, offset + limit)
845
- : await orm.findMany("bundles", {
846
- select: selectedColumns,
847
- where: buildBundleWhere(where),
848
- orderBy: [[orderBy.field, orderBy.direction]],
849
- limit,
850
- offset,
851
- });
852
-
853
- const patchMap = await fetchBundlePatchMap(
854
- orm,
855
- rows.map((row) => row.id),
856
- );
857
-
858
- return rows.map((row) =>
859
- mapBundleRecordToBundle(row, patchMap.get(row.id) ?? []),
860
- );
861
- };
862
-
863
- if (!options.cursor?.after && !options.cursor?.before) {
864
- const data = await findBundles({
865
- where,
866
- orderBy,
867
- limit,
868
- offset,
869
- });
870
-
871
- return {
872
- data,
873
- pagination: {
874
- ...calculatePagination(total, { limit, offset }),
875
- ...(data.length > 0 && offset + data.length < total
876
- ? { nextCursor: data.at(-1)?.id }
877
- : {}),
878
- ...(data.length > 0 && offset > 0
879
- ? { previousCursor: data[0]?.id }
880
- : {}),
881
- },
882
- };
883
- }
884
-
885
- const {
886
- where: cursorWhere,
887
- orderBy: cursorOrderBy,
888
- reverseData,
889
- } = buildCursorPageWhere(where, options.cursor, orderBy);
890
- const cursorPage = await findBundles({
891
- where: cursorWhere,
892
- orderBy: cursorOrderBy,
893
- limit,
894
- offset: 0,
895
- });
896
- const data = reverseData ? cursorPage.slice().reverse() : cursorPage;
897
-
898
- if (data.length === 0) {
899
- const emptyStartIndex = options.cursor.after ? total : 0;
900
- return {
901
- data,
902
- pagination: {
903
- ...calculatePagination(total, {
904
- limit,
905
- offset: emptyStartIndex,
906
- }),
907
- ...(options.cursor.after
908
- ? { previousCursor: options.cursor.after }
909
- : {}),
910
- ...(options.cursor.before
911
- ? { nextCursor: options.cursor.before }
912
- : {}),
913
- },
914
- };
915
- }
916
-
917
- const startIndex = await orm.count("bundles", {
918
- where: buildBundleWhere(
919
- buildCountBeforeWhere(where, data[0]!.id, orderBy),
920
- ),
921
- });
922
-
923
- return {
924
- data,
925
- pagination: {
926
- ...calculatePagination(total, { limit, offset: startIndex }),
927
- ...(startIndex + data.length < total
928
- ? { nextCursor: data.at(-1)?.id }
929
- : {}),
930
- ...(startIndex > 0 ? { previousCursor: data[0]?.id } : {}),
931
- },
932
- };
933
- },
934
-
935
- async insertBundle(bundle: Bundle): Promise<void> {
936
- assertBundlePersistenceConstraints(bundle);
937
- const orm = await ensureORM();
938
- const values = {
939
- id: bundle.id,
940
- platform: bundle.platform,
941
- should_force_update: bundle.shouldForceUpdate,
942
- enabled: bundle.enabled,
943
- file_hash: bundle.fileHash,
944
- git_commit_hash: bundle.gitCommitHash,
945
- message: bundle.message,
946
- channel: bundle.channel,
947
- storage_uri: bundle.storageUri,
948
- target_app_version: bundle.targetAppVersion,
949
- fingerprint_hash: bundle.fingerprintHash,
950
- metadata: stripBundleArtifactMetadata(bundle.metadata) ?? {},
951
- manifest_storage_uri: getManifestStorageUri(bundle),
952
- manifest_file_hash: getManifestFileHash(bundle),
953
- asset_base_storage_uri: getAssetBaseStorageUri(bundle),
954
- rollout_cohort_count:
955
- bundle.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
956
- target_cohorts: bundle.targetCohorts ?? null,
957
- };
958
- const { id, ...updateValues } = values;
959
- await orm.upsert("bundles", {
960
- where: (b) => b("id", "=", id),
961
- create: values,
962
- update: updateValues,
963
- });
964
- await orm.deleteMany("bundle_patches", {
965
- where: (b) => b("bundle_id", "=", bundle.id),
966
- });
967
- const patchValues = toBundlePatchRecords(bundle);
968
- if (patchValues.length > 0) {
969
- await orm.createMany("bundle_patches", patchValues);
970
- }
971
- },
972
-
973
- async updateBundleById(
974
- bundleId: string,
975
- newBundle: Partial<Bundle>,
976
- ): Promise<void> {
977
- const orm = await ensureORM();
978
- const current = await this.getBundleById(bundleId);
979
- if (!current) throw new Error("targetBundleId not found");
980
- const merged: Bundle = { ...current, ...newBundle };
981
- assertBundlePersistenceConstraints(merged);
982
- const values = {
983
- id: merged.id,
984
- platform: merged.platform,
985
- should_force_update: merged.shouldForceUpdate,
986
- enabled: merged.enabled,
987
- file_hash: merged.fileHash,
988
- git_commit_hash: merged.gitCommitHash,
989
- message: merged.message,
990
- channel: merged.channel,
991
- storage_uri: merged.storageUri,
992
- target_app_version: merged.targetAppVersion,
993
- fingerprint_hash: merged.fingerprintHash,
994
- metadata: stripBundleArtifactMetadata(merged.metadata) ?? {},
995
- manifest_storage_uri: getManifestStorageUri(merged),
996
- manifest_file_hash: getManifestFileHash(merged),
997
- asset_base_storage_uri: getAssetBaseStorageUri(merged),
998
- rollout_cohort_count:
999
- merged.rolloutCohortCount ?? DEFAULT_ROLLOUT_COHORT_COUNT,
1000
- target_cohorts: merged.targetCohorts ?? null,
1001
- };
1002
- const { id: id2, ...updateValues2 } = values;
1003
- await orm.upsert("bundles", {
1004
- where: (b) => b("id", "=", id2),
1005
- create: values,
1006
- update: updateValues2,
1007
- });
1008
- await orm.deleteMany("bundle_patches", {
1009
- where: (b) => b("bundle_id", "=", merged.id),
1010
- });
1011
- const patchValues = toBundlePatchRecords(merged);
1012
- if (patchValues.length > 0) {
1013
- await orm.createMany("bundle_patches", patchValues);
1014
- }
1015
- },
1016
-
1017
- async deleteBundleById(bundleId: string): Promise<void> {
1018
- const orm = await ensureORM();
1019
- const existingBundle = await orm.findFirst("bundles", {
1020
- select: ["id"],
1021
- where: (b) => b("id", "=", bundleId),
1022
- });
1023
-
1024
- if (!existingBundle) {
1025
- return;
1026
- }
1027
-
1028
- await orm.deleteMany("bundle_patches", {
1029
- where: (b) => b("bundle_id", "=", bundleId),
1030
- });
1031
- await orm.deleteMany("bundle_patches", {
1032
- where: (b) => b("base_bundle_id", "=", bundleId),
1033
- });
1034
- await orm.deleteMany("bundles", { where: (b) => b("id", "=", bundleId) });
1035
- },
1036
- };
1037
-
1038
- return {
1039
- api,
1040
- adapterName: client.adapter.name,
1041
- createMigrator: () =>
1042
- wrapKyselyMigrator(
1043
- client.createMigrator(),
1044
- getSQLProvider(database.provider),
1045
- lastSchemaVersion,
1046
- ) as Migrator,
1047
- generateSchema: (version, name) => {
1048
- const result = client.generateSchema(version, name);
1049
- return {
1050
- ...result,
1051
- code: enhanceGeneratedSchema(
1052
- client.adapter.name,
1053
- result.code,
1054
- database.provider,
1055
- ),
1056
- };
1057
- },
1058
- };
1059
- }