@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
@@ -1,19 +1,302 @@
1
- import { mongoAdapter as fumadbMongoAdapter } from "fumadb/adapters/mongodb";
1
+ import { NIL_UUID } from "@hot-updater/core";
2
+ import type {
3
+ Bundle,
4
+ DatabaseBundleQueryOptions,
5
+ DatabaseBundleQueryWhere,
6
+ } from "@hot-updater/plugin-core";
7
+ import {
8
+ calculatePagination,
9
+ createDatabasePlugin,
10
+ filterCompatibleAppVersions,
11
+ resolveUpdateInfoFromBundles,
12
+ } from "@hot-updater/plugin-core";
13
+ import type { ClientSession, Collection, Filter, MongoClient } from "mongodb";
2
14
 
3
- import type { ORMDatabaseAdapter } from "../db/types";
15
+ import {
16
+ bundleToPatchRows,
17
+ bundleToRow,
18
+ type BundlePatchRow,
19
+ type BundleRow,
20
+ rowToBundle,
21
+ } from "../db/bundleRows";
22
+ import { createMongoMigrator } from "../db/fixedMigrator";
23
+ import type { DatabasePluginFactory } from "../db/types";
4
24
 
5
- export interface MongoDBConfig<TClient extends object = object> {
6
- client: TClient;
25
+ export interface MongoDBConfig {
26
+ readonly client: MongoClient;
7
27
  }
8
28
 
9
- export const mongoAdapter = <TClient extends object>(
10
- options: MongoDBConfig<TClient>,
11
- ): ORMDatabaseAdapter =>
12
- Object.assign(
13
- fumadbMongoAdapter(
14
- options as unknown as Parameters<typeof fumadbMongoAdapter>[0],
15
- ) as unknown as ORMDatabaseAdapter,
16
- {
17
- provider: "mongodb",
18
- },
19
- );
29
+ const mongoWhere = (
30
+ where: DatabaseBundleQueryWhere | undefined,
31
+ ): Filter<BundleRow> => {
32
+ const baseFilter: Filter<BundleRow> = {
33
+ ...(where?.channel !== undefined ? { channel: where.channel } : {}),
34
+ ...(where?.platform !== undefined ? { platform: where.platform } : {}),
35
+ ...(where?.enabled !== undefined ? { enabled: where.enabled } : {}),
36
+ ...(where?.fingerprintHash !== undefined
37
+ ? where.fingerprintHash === null
38
+ ? { fingerprint_hash: { $in: [null, ""] } }
39
+ : { fingerprint_hash: where.fingerprintHash }
40
+ : {}),
41
+ ...(where?.id
42
+ ? {
43
+ id: {
44
+ ...(where.id.eq !== undefined ? { $eq: where.id.eq } : {}),
45
+ ...(where.id.gt !== undefined ? { $gt: where.id.gt } : {}),
46
+ ...(where.id.gte !== undefined ? { $gte: where.id.gte } : {}),
47
+ ...(where.id.lt !== undefined ? { $lt: where.id.lt } : {}),
48
+ ...(where.id.lte !== undefined ? { $lte: where.id.lte } : {}),
49
+ ...(where.id.in !== undefined ? { $in: where.id.in } : {}),
50
+ },
51
+ }
52
+ : {}),
53
+ };
54
+ const targetAppVersionFilters: Filter<BundleRow>[] = [];
55
+ if (where?.targetAppVersion !== undefined) {
56
+ targetAppVersionFilters.push(
57
+ where.targetAppVersion === null
58
+ ? { target_app_version: { $in: [null, ""] } }
59
+ : { target_app_version: where.targetAppVersion },
60
+ );
61
+ }
62
+ if (where?.targetAppVersionIn) {
63
+ targetAppVersionFilters.push({
64
+ target_app_version: { $in: where.targetAppVersionIn },
65
+ });
66
+ }
67
+ if (where?.targetAppVersionNotNull) {
68
+ targetAppVersionFilters.push({
69
+ target_app_version: { $exists: true, $nin: [null, ""] },
70
+ });
71
+ }
72
+
73
+ const filters = [
74
+ ...(Object.keys(baseFilter).length > 0 ? [baseFilter] : []),
75
+ ...targetAppVersionFilters,
76
+ ];
77
+ if (filters.length === 0) return {};
78
+ if (filters.length === 1) return filters[0] ?? {};
79
+ return { $and: filters };
80
+ };
81
+
82
+ const createMongoPlugin = createDatabasePlugin<MongoDBConfig>({
83
+ name: "mongodb",
84
+ factory: ({ client }) => {
85
+ const db = client.db();
86
+ const bundles = db.collection<BundleRow>("bundles");
87
+ const patches = db.collection<BundlePatchRow>("bundle_patches");
88
+ const fetchPatchMap = async (bundleIds: readonly string[]) => {
89
+ const patchMap = new Map<string, BundlePatchRow[]>();
90
+ if (bundleIds.length === 0) return patchMap;
91
+ const rows = await patches
92
+ .find({ bundle_id: { $in: [...bundleIds] } })
93
+ .sort({ order_index: 1 })
94
+ .toArray();
95
+ for (const row of rows) {
96
+ const current = patchMap.get(row.bundle_id) ?? [];
97
+ current.push(row);
98
+ patchMap.set(row.bundle_id, current);
99
+ }
100
+ return patchMap;
101
+ };
102
+ const mapRowsToBundles = async (
103
+ rows: readonly BundleRow[],
104
+ ): Promise<Bundle[]> => {
105
+ const patchMap = await fetchPatchMap(rows.map((row) => row.id));
106
+ return rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? []));
107
+ };
108
+ const isTransactionUnsupported = (error: unknown): boolean =>
109
+ error instanceof Error &&
110
+ /Transaction numbers are only allowed|replica set member or mongos|Transaction API error/i.test(
111
+ error.message,
112
+ );
113
+ const runInTransaction = async <T>(
114
+ operation: (session: ClientSession | undefined) => Promise<T>,
115
+ ) => {
116
+ if (typeof client.startSession !== "function") {
117
+ return operation(undefined);
118
+ }
119
+ const session = client.startSession();
120
+ try {
121
+ if (typeof session.withTransaction !== "function") {
122
+ return await operation(session);
123
+ }
124
+ let result: T | undefined;
125
+ await session.withTransaction(async () => {
126
+ result = await operation(session);
127
+ });
128
+ return result as T;
129
+ } catch (error) {
130
+ if (isTransactionUnsupported(error)) {
131
+ return operation(undefined);
132
+ }
133
+ throw error;
134
+ } finally {
135
+ await session.endSession();
136
+ }
137
+ };
138
+ const replaceBundle = async (
139
+ bundle: Bundle,
140
+ session: ClientSession | undefined,
141
+ ) => {
142
+ const row = bundleToRow(bundle);
143
+ await bundles.updateOne(
144
+ { id: bundle.id },
145
+ { $set: row },
146
+ { session, upsert: true },
147
+ );
148
+ await patches.deleteMany({ bundle_id: bundle.id }, { session });
149
+ const patchRows = bundleToPatchRows(bundle);
150
+ if (patchRows.length > 0)
151
+ await patches.insertMany(patchRows, { session });
152
+ };
153
+ const deleteByBundleId = async (
154
+ collection: Collection<BundlePatchRow>,
155
+ field: "bundle_id" | "base_bundle_id",
156
+ bundleId: string,
157
+ session: ClientSession | undefined,
158
+ ) => {
159
+ await collection.deleteMany({ [field]: bundleId }, { session });
160
+ };
161
+ return {
162
+ async getBundleById(bundleId) {
163
+ const row = await bundles.findOne({ id: bundleId });
164
+ if (!row) return null;
165
+ const patchMap = await fetchPatchMap([bundleId]);
166
+ return rowToBundle(row, patchMap.get(bundleId) ?? []);
167
+ },
168
+ async getBundles(
169
+ options: DatabaseBundleQueryOptions & { offset?: number },
170
+ ) {
171
+ const offset = options.offset ?? 0;
172
+ const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
173
+ const where = mongoWhere(options.where);
174
+ const [total, rows] = await Promise.all([
175
+ bundles.countDocuments(where),
176
+ bundles
177
+ .find(where)
178
+ .sort({ id: orderBy.direction === "asc" ? 1 : -1 })
179
+ .skip(offset)
180
+ .limit(options.limit)
181
+ .toArray(),
182
+ ]);
183
+ const patchMap = await fetchPatchMap(rows.map((row) => row.id));
184
+ return {
185
+ data: rows.map((row) => rowToBundle(row, patchMap.get(row.id) ?? [])),
186
+ pagination: calculatePagination(total, {
187
+ limit: options.limit,
188
+ offset,
189
+ }),
190
+ };
191
+ },
192
+ async getUpdateInfo(args, context) {
193
+ if (args._updateStrategy === "appVersion") {
194
+ const channel = args.channel ?? "production";
195
+ const minBundleId = args.minBundleId ?? NIL_UUID;
196
+ const rows = await bundles
197
+ .find({
198
+ enabled: true,
199
+ platform: args.platform,
200
+ channel,
201
+ id: { $gte: minBundleId },
202
+ target_app_version: { $exists: true, $nin: [null, ""] },
203
+ })
204
+ .project<{ target_app_version?: string | null }>({
205
+ target_app_version: 1,
206
+ })
207
+ .toArray();
208
+
209
+ const targetAppVersions = Array.from(
210
+ new Set(
211
+ rows
212
+ .map((row) => row.target_app_version)
213
+ .filter(
214
+ (value): value is string =>
215
+ typeof value === "string" && value.length > 0,
216
+ ),
217
+ ),
218
+ );
219
+ const compatibleAppVersions = filterCompatibleAppVersions(
220
+ targetAppVersions,
221
+ args.appVersion,
222
+ );
223
+ const updateRows =
224
+ compatibleAppVersions.length > 0
225
+ ? await bundles
226
+ .find({
227
+ enabled: true,
228
+ platform: args.platform,
229
+ channel,
230
+ id: { $gte: minBundleId },
231
+ target_app_version: { $in: compatibleAppVersions },
232
+ })
233
+ .sort({ id: -1 })
234
+ .toArray()
235
+ : [];
236
+
237
+ return resolveUpdateInfoFromBundles({
238
+ args: { ...args, channel, minBundleId },
239
+ bundles: await mapRowsToBundles(updateRows),
240
+ context,
241
+ });
242
+ }
243
+
244
+ const channel = args.channel ?? "production";
245
+ const minBundleId = args.minBundleId ?? NIL_UUID;
246
+ const rows = await bundles
247
+ .find({
248
+ enabled: true,
249
+ platform: args.platform,
250
+ channel,
251
+ id: { $gte: minBundleId },
252
+ fingerprint_hash: args.fingerprintHash,
253
+ })
254
+ .sort({ id: -1 })
255
+ .toArray();
256
+
257
+ return resolveUpdateInfoFromBundles({
258
+ args: { ...args, channel, minBundleId },
259
+ bundles: await mapRowsToBundles(rows),
260
+ context,
261
+ });
262
+ },
263
+ async getChannels() {
264
+ const channels = await bundles.distinct("channel");
265
+ return channels
266
+ .filter((channel): channel is string => typeof channel === "string")
267
+ .sort((left, right) => left.localeCompare(right));
268
+ },
269
+ async commitBundle({ changedSets }) {
270
+ await runInTransaction(async (session) => {
271
+ for (const change of changedSets) {
272
+ if (change.operation === "delete") {
273
+ await deleteByBundleId(
274
+ patches,
275
+ "bundle_id",
276
+ change.data.id,
277
+ session,
278
+ );
279
+ await deleteByBundleId(
280
+ patches,
281
+ "base_bundle_id",
282
+ change.data.id,
283
+ session,
284
+ );
285
+ await bundles.deleteMany({ id: change.data.id }, { session });
286
+ continue;
287
+ }
288
+ await replaceBundle(change.data, session);
289
+ }
290
+ });
291
+ },
292
+ };
293
+ },
294
+ });
295
+
296
+ export const mongoAdapter = (config: MongoDBConfig): DatabasePluginFactory => {
297
+ return Object.assign(createMongoPlugin(config), {
298
+ adapterName: "mongodb",
299
+ provider: "mongodb" as const,
300
+ createMigrator: () => createMongoMigrator(config.client),
301
+ });
302
+ };
@@ -1,15 +1,340 @@
1
- import { prismaAdapter as fumadbPrismaAdapter } from "fumadb/adapters/prisma";
1
+ import { NIL_UUID } from "@hot-updater/core";
2
+ import type {
3
+ Bundle,
4
+ DatabaseBundleQueryOptions,
5
+ DatabaseBundleQueryWhere,
6
+ } from "@hot-updater/plugin-core";
7
+ import {
8
+ calculatePagination,
9
+ createDatabasePlugin,
10
+ filterCompatibleAppVersions,
11
+ resolveUpdateInfoFromBundles,
12
+ } from "@hot-updater/plugin-core";
2
13
 
3
- import type { ORMDatabaseAdapter } from "../db/types";
14
+ import {
15
+ bundleToPatchRows,
16
+ bundleToRow,
17
+ type BundlePatchRow,
18
+ type BundleRow,
19
+ rowToBundle,
20
+ } from "../db/bundleRows";
21
+ import {
22
+ getHotUpdaterSchemaVersion,
23
+ hotUpdaterSchema,
24
+ } from "../db/schema/registry";
25
+ import { generatePrismaSchema } from "../db/schemaGenerators";
26
+ import type {
27
+ DatabasePluginFactory,
28
+ ORMProvider,
29
+ SchemaGenerator,
30
+ } from "../db/types";
4
31
 
5
- export type PrismaConfig = Parameters<typeof fumadbPrismaAdapter>[0];
32
+ type PrismaRelationMode = "prisma" | "foreign-keys";
6
33
 
7
- export const prismaAdapter = (config: PrismaConfig): ORMDatabaseAdapter =>
8
- Object.assign(
9
- fumadbPrismaAdapter(
10
- config as unknown as Parameters<typeof fumadbPrismaAdapter>[0],
11
- ) as unknown as ORMDatabaseAdapter,
12
- {
13
- provider: config.provider,
14
- },
15
- );
34
+ type PrismaDelegate = {
35
+ readonly count: (args?: unknown) => Promise<number>;
36
+ readonly createMany: (args: unknown) => Promise<unknown>;
37
+ readonly deleteMany: (args?: unknown) => Promise<unknown>;
38
+ readonly findFirst: (
39
+ args?: unknown,
40
+ ) => Promise<Record<string, unknown> | null>;
41
+ readonly findMany: (args?: unknown) => Promise<Record<string, unknown>[]>;
42
+ readonly upsert: (args: unknown) => Promise<unknown>;
43
+ };
44
+
45
+ type PrismaClient = Record<string, unknown> & {
46
+ readonly $transaction?: <T>(
47
+ operation: (tx: Record<string, unknown>) => Promise<T>,
48
+ ) => Promise<T>;
49
+ };
50
+
51
+ export interface PrismaConfig {
52
+ readonly prisma: object;
53
+ readonly provider: ORMProvider;
54
+ readonly relationMode?: PrismaRelationMode;
55
+ readonly db?: unknown;
56
+ }
57
+
58
+ const assertSupportedRelationMode = (
59
+ relationMode: PrismaRelationMode | undefined,
60
+ ) => {
61
+ if (
62
+ relationMode &&
63
+ relationMode !== "prisma" &&
64
+ relationMode !== "foreign-keys"
65
+ ) {
66
+ throw new Error(`Unsupported Prisma relation mode: ${relationMode}`);
67
+ }
68
+ };
69
+
70
+ const getDelegate = (
71
+ prisma: Record<string, unknown>,
72
+ model: "bundles" | "bundle_patches",
73
+ ): PrismaDelegate => {
74
+ const delegate = prisma[model];
75
+ if (!delegate || typeof delegate !== "object") {
76
+ throw new Error(`Prisma client is missing model delegate "${model}".`);
77
+ }
78
+ return delegate as PrismaDelegate;
79
+ };
80
+
81
+ const prismaWhere = (where: DatabaseBundleQueryWhere | undefined) => {
82
+ const targetAppVersionFilters = [];
83
+ if (where?.targetAppVersion !== undefined) {
84
+ targetAppVersionFilters.push({
85
+ target_app_version: where.targetAppVersion,
86
+ });
87
+ }
88
+ if (where?.targetAppVersionIn) {
89
+ targetAppVersionFilters.push({
90
+ target_app_version: { in: where.targetAppVersionIn },
91
+ });
92
+ }
93
+ if (where?.targetAppVersionNotNull) {
94
+ targetAppVersionFilters.push({
95
+ target_app_version: { not: null },
96
+ });
97
+ }
98
+
99
+ return {
100
+ ...(where?.channel !== undefined ? { channel: where.channel } : {}),
101
+ ...(where?.platform !== undefined ? { platform: where.platform } : {}),
102
+ ...(where?.enabled !== undefined ? { enabled: where.enabled } : {}),
103
+ ...(where?.fingerprintHash !== undefined
104
+ ? { fingerprint_hash: where.fingerprintHash }
105
+ : {}),
106
+ ...(where?.id
107
+ ? {
108
+ id: {
109
+ ...(where.id.eq !== undefined ? { equals: where.id.eq } : {}),
110
+ ...(where.id.gt !== undefined ? { gt: where.id.gt } : {}),
111
+ ...(where.id.gte !== undefined ? { gte: where.id.gte } : {}),
112
+ ...(where.id.lt !== undefined ? { lt: where.id.lt } : {}),
113
+ ...(where.id.lte !== undefined ? { lte: where.id.lte } : {}),
114
+ ...(where.id.in !== undefined ? { in: where.id.in } : {}),
115
+ },
116
+ }
117
+ : {}),
118
+ ...(targetAppVersionFilters.length > 0
119
+ ? { AND: targetAppVersionFilters }
120
+ : {}),
121
+ };
122
+ };
123
+
124
+ const createPrismaPlugin = createDatabasePlugin<PrismaConfig>({
125
+ name: "prisma",
126
+ factory: (config) => {
127
+ const prisma = config.prisma as PrismaClient;
128
+ const runInTransaction = async <T>(
129
+ operation: (client: Record<string, unknown>) => Promise<T>,
130
+ ) => {
131
+ if (typeof prisma.$transaction !== "function") {
132
+ return operation(prisma);
133
+ }
134
+ return prisma.$transaction(operation);
135
+ };
136
+ const fetchPatchMap = async (bundleIds: readonly string[]) => {
137
+ const patches = getDelegate(prisma, "bundle_patches");
138
+ const patchMap = new Map<string, BundlePatchRow[]>();
139
+ if (bundleIds.length === 0) return patchMap;
140
+ const rows = await patches.findMany({
141
+ where: { bundle_id: { in: [...bundleIds] } },
142
+ orderBy: { order_index: "asc" },
143
+ });
144
+ for (const row of rows) {
145
+ const patch = row as BundlePatchRow;
146
+ const current = patchMap.get(patch.bundle_id) ?? [];
147
+ current.push(patch);
148
+ patchMap.set(patch.bundle_id, current);
149
+ }
150
+ return patchMap;
151
+ };
152
+ const mapRowsToBundles = async (
153
+ rows: readonly Record<string, unknown>[],
154
+ ): Promise<Bundle[]> => {
155
+ const patchMap = await fetchPatchMap(
156
+ rows.map((row) => String(row["id"])),
157
+ );
158
+ return rows.map((row) =>
159
+ rowToBundle(row as BundleRow, patchMap.get(String(row["id"])) ?? []),
160
+ );
161
+ };
162
+ const upsertBundle = async (
163
+ client: Record<string, unknown>,
164
+ bundle: Bundle,
165
+ ) => {
166
+ const bundles = getDelegate(client, "bundles");
167
+ const patches = getDelegate(client, "bundle_patches");
168
+ const row = bundleToRow(bundle);
169
+ const { id, ...update } = row;
170
+ await bundles.upsert({
171
+ where: { id },
172
+ create: row,
173
+ update,
174
+ });
175
+ await patches.deleteMany({ where: { bundle_id: id } });
176
+ const patchRows = bundleToPatchRows(bundle);
177
+ if (patchRows.length > 0) {
178
+ await patches.createMany({ data: patchRows });
179
+ }
180
+ };
181
+ return {
182
+ async getBundleById(bundleId) {
183
+ const bundles = getDelegate(prisma, "bundles");
184
+ const row = await bundles.findFirst({ where: { id: bundleId } });
185
+ if (!row) return null;
186
+ const patchMap = await fetchPatchMap([bundleId]);
187
+ return rowToBundle(row as BundleRow, patchMap.get(bundleId) ?? []);
188
+ },
189
+ async getBundles(
190
+ options: DatabaseBundleQueryOptions & { offset?: number },
191
+ ) {
192
+ const bundles = getDelegate(prisma, "bundles");
193
+ const offset = options.offset ?? 0;
194
+ const orderBy = options.orderBy ?? { field: "id", direction: "desc" };
195
+ const where = prismaWhere(options.where);
196
+ const [total, rows] = await Promise.all([
197
+ bundles.count({ where }),
198
+ bundles.findMany({
199
+ where,
200
+ orderBy: { id: orderBy.direction },
201
+ skip: offset,
202
+ take: options.limit,
203
+ }),
204
+ ]);
205
+ const patchMap = await fetchPatchMap(
206
+ rows.map((row) => String(row["id"])),
207
+ );
208
+ return {
209
+ data: rows.map((row) =>
210
+ rowToBundle(
211
+ row as BundleRow,
212
+ patchMap.get(String(row["id"])) ?? [],
213
+ ),
214
+ ),
215
+ pagination: calculatePagination(total, {
216
+ limit: options.limit,
217
+ offset,
218
+ }),
219
+ };
220
+ },
221
+ async getUpdateInfo(args, context) {
222
+ const bundles = getDelegate(prisma, "bundles");
223
+
224
+ if (args._updateStrategy === "appVersion") {
225
+ const channel = args.channel ?? "production";
226
+ const minBundleId = args.minBundleId ?? NIL_UUID;
227
+ const rows = await bundles.findMany({
228
+ select: { target_app_version: true },
229
+ where: {
230
+ enabled: true,
231
+ platform: args.platform,
232
+ channel,
233
+ id: { gte: minBundleId },
234
+ target_app_version: { not: null },
235
+ },
236
+ });
237
+
238
+ const targetAppVersions = Array.from(
239
+ new Set(
240
+ rows
241
+ .map((row) => row["target_app_version"])
242
+ .filter(
243
+ (value): value is string =>
244
+ typeof value === "string" && value.length > 0,
245
+ ),
246
+ ),
247
+ );
248
+ const compatibleAppVersions = filterCompatibleAppVersions(
249
+ targetAppVersions,
250
+ args.appVersion,
251
+ );
252
+ const updateBundles =
253
+ compatibleAppVersions.length > 0
254
+ ? await bundles
255
+ .findMany({
256
+ where: {
257
+ enabled: true,
258
+ platform: args.platform,
259
+ channel,
260
+ id: { gte: minBundleId },
261
+ target_app_version: { in: compatibleAppVersions },
262
+ },
263
+ orderBy: { id: "desc" },
264
+ })
265
+ .then(mapRowsToBundles)
266
+ : [];
267
+
268
+ return resolveUpdateInfoFromBundles({
269
+ args: { ...args, channel, minBundleId },
270
+ bundles: updateBundles,
271
+ context,
272
+ });
273
+ }
274
+
275
+ const channel = args.channel ?? "production";
276
+ const minBundleId = args.minBundleId ?? NIL_UUID;
277
+ const rows = await bundles.findMany({
278
+ where: {
279
+ enabled: true,
280
+ platform: args.platform,
281
+ channel,
282
+ id: { gte: minBundleId },
283
+ fingerprint_hash: args.fingerprintHash,
284
+ },
285
+ orderBy: { id: "desc" },
286
+ });
287
+
288
+ return resolveUpdateInfoFromBundles({
289
+ args: { ...args, channel, minBundleId },
290
+ bundles: await mapRowsToBundles(rows),
291
+ context,
292
+ });
293
+ },
294
+ async getChannels() {
295
+ const bundles = getDelegate(prisma, "bundles");
296
+ const rows = await bundles.findMany({
297
+ select: { channel: true },
298
+ orderBy: { channel: "asc" },
299
+ });
300
+ return Array.from(new Set(rows.map((row) => String(row["channel"]))));
301
+ },
302
+ async commitBundle({ changedSets }) {
303
+ await runInTransaction(async (client) => {
304
+ const bundles = getDelegate(client, "bundles");
305
+ const patches = getDelegate(client, "bundle_patches");
306
+ for (const change of changedSets) {
307
+ if (change.operation === "delete") {
308
+ await patches.deleteMany({
309
+ where: { bundle_id: change.data.id },
310
+ });
311
+ await patches.deleteMany({
312
+ where: { base_bundle_id: change.data.id },
313
+ });
314
+ await bundles.deleteMany({ where: { id: change.data.id } });
315
+ continue;
316
+ }
317
+ await upsertBundle(client, change.data);
318
+ }
319
+ });
320
+ },
321
+ };
322
+ },
323
+ });
324
+
325
+ export const prismaAdapter = (config: PrismaConfig): DatabasePluginFactory => {
326
+ assertSupportedRelationMode(config.relationMode);
327
+ return Object.assign(createPrismaPlugin(config), {
328
+ adapterName: "prisma",
329
+ provider: config.provider,
330
+ generateSchema: (version: Parameters<SchemaGenerator>[0]) => ({
331
+ code: generatePrismaSchema(
332
+ config.provider,
333
+ version === "latest"
334
+ ? hotUpdaterSchema
335
+ : getHotUpdaterSchemaVersion(version),
336
+ ),
337
+ path: "./prisma/schema/hot_updater.prisma",
338
+ }),
339
+ });
340
+ };