@hot-updater/server 0.30.12 → 0.31.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 (165) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +25 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +6 -0
  3. package/dist/adapters/drizzle.cjs +6 -9
  4. package/dist/adapters/drizzle.d.cts +8 -1
  5. package/dist/adapters/drizzle.d.mts +8 -1
  6. package/dist/adapters/drizzle.mjs +5 -2
  7. package/dist/adapters/kysely.cjs +7 -9
  8. package/dist/adapters/kysely.d.cts +14 -1
  9. package/dist/adapters/kysely.d.mts +14 -1
  10. package/dist/adapters/kysely.mjs +6 -2
  11. package/dist/adapters/mongodb.cjs +7 -9
  12. package/dist/adapters/mongodb.d.cts +9 -1
  13. package/dist/adapters/mongodb.d.mts +9 -1
  14. package/dist/adapters/mongodb.mjs +5 -2
  15. package/dist/adapters/prisma.cjs +6 -9
  16. package/dist/adapters/prisma.d.cts +8 -1
  17. package/dist/adapters/prisma.d.mts +8 -1
  18. package/dist/adapters/prisma.mjs +5 -2
  19. package/dist/db/createBundleDiff.cjs +166 -0
  20. package/dist/db/createBundleDiff.d.cts +20 -0
  21. package/dist/db/createBundleDiff.d.mts +20 -0
  22. package/dist/db/createBundleDiff.mjs +161 -0
  23. package/dist/db/index.cjs +15 -16
  24. package/dist/db/index.d.cts +5 -4
  25. package/dist/db/index.d.mts +5 -4
  26. package/dist/db/index.mjs +14 -16
  27. package/dist/db/ormCore.cjs +173 -65
  28. package/dist/db/ormCore.d.cts +100 -34
  29. package/dist/db/ormCore.d.mts +100 -34
  30. package/dist/db/ormCore.mjs +171 -64
  31. package/dist/db/pluginCore.cjs +37 -3
  32. package/dist/db/pluginCore.mjs +36 -3
  33. package/dist/db/schemaEnhancements.cjs +171 -0
  34. package/dist/db/schemaEnhancements.mjs +167 -0
  35. package/dist/db/types.cjs +6 -0
  36. package/dist/db/types.d.cts +19 -7
  37. package/dist/db/types.d.mts +22 -10
  38. package/dist/db/types.mjs +6 -1
  39. package/dist/db/updateArtifacts.cjs +127 -0
  40. package/dist/db/updateArtifacts.mjs +125 -0
  41. package/dist/handler.cjs +61 -5
  42. package/dist/handler.d.cts +2 -2
  43. package/dist/handler.d.mts +5 -5
  44. package/dist/handler.mjs +59 -5
  45. package/dist/index.cjs +2 -0
  46. package/dist/index.d.cts +3 -2
  47. package/dist/index.d.mts +3 -2
  48. package/dist/index.mjs +2 -1
  49. package/dist/node.d.cts +0 -1
  50. package/dist/node.d.mts +0 -1
  51. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.cjs +112 -0
  52. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/_u64.mjs +108 -0
  53. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.cjs +22 -0
  54. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/cryptoNode.mjs +18 -0
  55. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.cjs +219 -0
  56. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/sha3.mjs +214 -0
  57. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.cjs +275 -0
  58. package/dist/node_modules/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/utils.mjs +270 -0
  59. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.cjs +17 -0
  60. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/index.mjs +13 -0
  61. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.cjs +69 -0
  62. package/dist/node_modules/.pnpm/@paralleldrive_cuid2@2.3.1/node_modules/@paralleldrive/cuid2/src/index.mjs +65 -0
  63. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/column.cjs +52 -0
  64. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/column.mjs +52 -0
  65. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/entity.cjs +16 -0
  66. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/entity.mjs +15 -0
  67. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/pg-core/columns/enum.cjs +7 -0
  68. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/pg-core/columns/enum.mjs +7 -0
  69. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/expressions/conditions.cjs +92 -0
  70. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/expressions/conditions.mjs +78 -0
  71. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/expressions/select.cjs +11 -0
  72. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/expressions/select.mjs +10 -0
  73. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/sql.cjs +383 -0
  74. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/sql/sql.mjs +366 -0
  75. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/subquery.cjs +17 -0
  76. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/subquery.mjs +17 -0
  77. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/table.cjs +60 -0
  78. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/table.mjs +59 -0
  79. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/table.utils.cjs +4 -0
  80. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/table.utils.mjs +4 -0
  81. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/tracing.cjs +6 -0
  82. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/tracing.mjs +6 -0
  83. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/view-common.cjs +4 -0
  84. package/dist/node_modules/.pnpm/drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pglite@0.2.17_@_31f44b782f9321d71f3ce9d35aa1edf7/node_modules/drizzle-orm/view-common.mjs +4 -0
  85. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/drizzle/index.cjs +383 -0
  86. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/drizzle/index.d.cts +12 -0
  87. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/drizzle/index.d.mts +12 -0
  88. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/drizzle/index.mjs +383 -0
  89. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/kysely/index.cjs +4 -0
  90. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/kysely/index.mjs +5 -0
  91. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/prisma/index.cjs +339 -0
  92. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/prisma/index.d.cts +70 -0
  93. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/prisma/index.d.mts +70 -0
  94. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/adapters/prisma/index.mjs +339 -0
  95. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-7PZK4ONR.cjs +57 -0
  96. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-7PZK4ONR.mjs +56 -0
  97. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-C6OTUURW.cjs +330 -0
  98. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-C6OTUURW.mjs +326 -0
  99. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-CHTIKPQU.cjs +166 -0
  100. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-CHTIKPQU.mjs +163 -0
  101. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-GUE4GMNC.cjs +14 -0
  102. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-GUE4GMNC.mjs +13 -0
  103. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-LHHP6UVP.cjs +24 -0
  104. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-LHHP6UVP.mjs +24 -0
  105. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-LVCPMTAT.cjs +1190 -0
  106. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-LVCPMTAT.mjs +1189 -0
  107. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-PK2W2SQ7.cjs +197 -0
  108. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-PK2W2SQ7.mjs +197 -0
  109. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-ZEQMAIFI.cjs +410 -0
  110. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-ZEQMAIFI.mjs +400 -0
  111. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-ZOCGSAWS.cjs +213 -0
  112. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-ZOCGSAWS.mjs +212 -0
  113. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/create-tg0451Y_.d.cts +285 -0
  114. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/create-tg0451Y_.d.mts +285 -0
  115. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index-CMqePMTF.d.cts +45 -0
  116. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index-CMqePMTF.d.mts +45 -0
  117. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.cjs +69 -0
  118. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.cts +49 -0
  119. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.mts +49 -0
  120. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.mjs +67 -0
  121. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.cts +156 -0
  122. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.mts +156 -0
  123. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/schema/index.cjs +1 -0
  124. package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/schema/index.mjs +2 -0
  125. package/dist/{package.cjs → packages/server/package.cjs} +1 -1
  126. package/dist/{package.mjs → packages/server/package.mjs} +1 -1
  127. package/dist/runtime.cjs +13 -13
  128. package/dist/runtime.d.cts +4 -4
  129. package/dist/runtime.d.mts +4 -4
  130. package/dist/runtime.mjs +12 -13
  131. package/dist/schema/v0_21_0.cjs +16 -15
  132. package/dist/schema/v0_21_0.mjs +3 -2
  133. package/dist/schema/v0_29_0.cjs +18 -17
  134. package/dist/schema/v0_29_0.mjs +3 -2
  135. package/dist/schema/v0_31_0.cjs +48 -0
  136. package/dist/schema/v0_31_0.mjs +48 -0
  137. package/dist/storageAccess.cjs +44 -0
  138. package/dist/storageAccess.mjs +44 -0
  139. package/dist/version.cjs +1 -1
  140. package/dist/version.mjs +1 -1
  141. package/package.json +15 -7
  142. package/src/adapters/drizzle.ts +15 -1
  143. package/src/adapters/kysely.ts +24 -1
  144. package/src/adapters/mongodb.ts +19 -1
  145. package/src/adapters/prisma.ts +15 -1
  146. package/src/db/createBundleDiff.spec.ts +402 -0
  147. package/src/db/createBundleDiff.ts +375 -0
  148. package/src/db/index.spec.ts +528 -27
  149. package/src/db/index.ts +22 -36
  150. package/src/db/ormCore.ts +308 -75
  151. package/src/db/pluginCore.spec.ts +385 -0
  152. package/src/db/pluginCore.ts +45 -4
  153. package/src/db/schemaEnhancements.ts +460 -0
  154. package/src/db/types.ts +38 -7
  155. package/src/db/updateArtifacts.ts +388 -0
  156. package/src/handler-standalone.integration.spec.ts +1 -0
  157. package/src/handler.spec.ts +121 -0
  158. package/src/handler.ts +117 -5
  159. package/src/runtime.spec.ts +287 -55
  160. package/src/runtime.ts +21 -37
  161. package/src/schema/v0_21_0.ts +1 -1
  162. package/src/schema/v0_29_0.ts +1 -1
  163. package/src/schema/v0_31_0.ts +58 -0
  164. package/src/storageAccess.spec.ts +57 -0
  165. package/src/storageAccess.ts +90 -0
@@ -0,0 +1,330 @@
1
+ require("../../../../../../_virtual/_rolldown/runtime.cjs");
2
+ const require_chunk_7PZK4ONR = require("./chunk-7PZK4ONR.cjs");
3
+ const require_chunk_ZEQMAIFI = require("./chunk-ZEQMAIFI.cjs");
4
+ let semver = require("semver");
5
+ //#region ../../node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare+workers-types@4.20260313.1_@electric-sql+pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-C6OTUURW.js
6
+ function isUpdated(op) {
7
+ return op.updateDataType || op.updateDefault || op.updateNullable;
8
+ }
9
+ function generateMigrationFromSchema(old, schema2, options) {
10
+ const { provider, relationMode = provider === "mssql" || provider === "mongodb" ? "fumadb" : "foreign-keys", dropUnusedTables = true, dropUnusedColumns = true } = options;
11
+ function getName(names) {
12
+ return provider === "mongodb" ? names.mongodb : names.sql;
13
+ }
14
+ function columnActionToOperation(tableName, actions) {
15
+ if (actions.length === 0) return [];
16
+ if (provider === "mysql" || provider === "postgresql" || provider === "mongodb") return [{
17
+ type: "update-table",
18
+ name: tableName,
19
+ value: actions
20
+ }];
21
+ return actions.map((action) => ({
22
+ type: "update-table",
23
+ name: tableName,
24
+ value: [action]
25
+ }));
26
+ }
27
+ function onUniqueConstraintCheck(prev, next) {
28
+ const operations = [];
29
+ const newConstraints = next.getUniqueConstraints();
30
+ const oldConstraints = prev.getUniqueConstraints();
31
+ for (const con of newConstraints) {
32
+ const oldCon = oldConstraints.find((item) => item.name === con.name);
33
+ const columnNames = con.columns.map((col) => getName(col.names));
34
+ if (!oldCon) {
35
+ operations.push({
36
+ type: "add-unique-constraint",
37
+ name: con.name,
38
+ table: getName(next.names),
39
+ columns: columnNames
40
+ });
41
+ continue;
42
+ }
43
+ if (require_chunk_ZEQMAIFI.deepEqual(columnNames, oldCon.columns.map((col) => getName(col.names)))) continue;
44
+ operations.push({
45
+ type: "drop-unique-constraint",
46
+ table: getName(next.names),
47
+ name: con.name
48
+ }, {
49
+ type: "add-unique-constraint",
50
+ table: getName(next.names),
51
+ name: con.name,
52
+ columns: columnNames
53
+ });
54
+ }
55
+ for (const con of oldConstraints) if (newConstraints.every((item) => item.name !== con.name)) operations.push({
56
+ type: "drop-unique-constraint",
57
+ table: getName(next.names),
58
+ name: con.name
59
+ });
60
+ return operations;
61
+ }
62
+ function onTableRenameCheck(oldTable, newTable) {
63
+ const operations = [];
64
+ if (getName(newTable.names) !== getName(oldTable.names)) operations.push({
65
+ type: "rename-table",
66
+ from: getName(oldTable.names),
67
+ to: getName(newTable.names),
68
+ enforce: "pre"
69
+ });
70
+ return operations;
71
+ }
72
+ function onTableColumnsCheck(oldTable, newTable) {
73
+ const colActions = [];
74
+ for (const column of Object.values(newTable.columns)) {
75
+ let hashDefaultValue2 = function(col) {
76
+ if (!col.default || "runtime" in col.default) return;
77
+ if (col.type === "string" && provider === "mysql") return;
78
+ return col.default.value;
79
+ };
80
+ const oldColumn = oldTable.columns[column.ormName];
81
+ if (!oldColumn) {
82
+ colActions.push({
83
+ type: "create-column",
84
+ value: column
85
+ });
86
+ continue;
87
+ }
88
+ if (getName(column.names) !== getName(oldColumn.names)) colActions.push({
89
+ type: "rename-column",
90
+ from: getName(oldColumn.names),
91
+ to: getName(column.names)
92
+ });
93
+ const action = {
94
+ type: "update-column",
95
+ name: getName(column.names),
96
+ updateDataType: column.type !== oldColumn.type,
97
+ updateDefault: !require_chunk_ZEQMAIFI.deepEqual(hashDefaultValue2(column), hashDefaultValue2(oldColumn)),
98
+ updateNullable: column.isNullable !== oldColumn.isNullable,
99
+ value: column
100
+ };
101
+ if (isUpdated(action)) colActions.push(action);
102
+ }
103
+ return columnActionToOperation(getName(newTable.names), colActions);
104
+ }
105
+ function onTableForeignKeyCheck(oldTable, newTable) {
106
+ const tableName = getName(newTable.names);
107
+ const operations = [];
108
+ if (relationMode === "fumadb") return operations;
109
+ for (const foreignKey of newTable.foreignKeys) {
110
+ const compiled = require_chunk_ZEQMAIFI.compileForeignKey(foreignKey, "sql");
111
+ const oldKey = oldTable.foreignKeys.find((key) => key.name === foreignKey.name);
112
+ if (!oldKey) {
113
+ operations.push({
114
+ type: "add-foreign-key",
115
+ table: tableName,
116
+ value: compiled,
117
+ enforce: "post"
118
+ });
119
+ continue;
120
+ }
121
+ if (!require_chunk_ZEQMAIFI.deepEqual(compiled, require_chunk_ZEQMAIFI.compileForeignKey(oldKey, "sql"))) operations.push({
122
+ type: "drop-foreign-key",
123
+ name: oldKey.name,
124
+ table: tableName,
125
+ enforce: "post"
126
+ }, {
127
+ type: "add-foreign-key",
128
+ table: tableName,
129
+ value: compiled,
130
+ enforce: "post"
131
+ });
132
+ }
133
+ return operations;
134
+ }
135
+ function onTableUnusedForeignKeyCheck(oldTable, newTable) {
136
+ const operations = [];
137
+ for (const oldKey of oldTable.foreignKeys) {
138
+ if (!newTable.foreignKeys.every((key) => key.name !== oldKey.name)) continue;
139
+ operations.push({
140
+ type: "drop-foreign-key",
141
+ name: oldKey.name,
142
+ table: getName(oldTable.names),
143
+ enforce: "pre"
144
+ });
145
+ }
146
+ return operations;
147
+ }
148
+ function onTableUnusedColumnsCheck(oldTable, newTable) {
149
+ const constraints = newTable.getUniqueConstraints();
150
+ const operations = [];
151
+ for (const oldColumn of Object.values(oldTable.columns)) {
152
+ const isUnused = !newTable.columns[oldColumn.ormName];
153
+ const isRequired = !oldColumn.isNullable && !oldColumn.default;
154
+ if (!(isUnused && (dropUnusedColumns || isRequired))) continue;
155
+ if (provider === "mssql" && oldColumn.isUnique) for (const con of constraints) {
156
+ if (con.columns.every((col) => col.ormName !== oldColumn.ormName)) continue;
157
+ operations.push({
158
+ type: "drop-unique-constraint",
159
+ name: con.name,
160
+ table: getName(newTable.names)
161
+ });
162
+ }
163
+ operations.push({
164
+ type: "update-table",
165
+ name: getName(newTable.names),
166
+ value: [{
167
+ type: "drop-column",
168
+ name: getName(oldColumn.names)
169
+ }],
170
+ enforce: "post"
171
+ });
172
+ }
173
+ return operations;
174
+ }
175
+ function reorder(operations) {
176
+ const out = [];
177
+ for (const item of operations) if (item.enforce === "pre") out.push(item);
178
+ for (const item of operations) if (!item.enforce) out.push(item);
179
+ for (const item of operations) if (item.enforce === "post") out.push(item);
180
+ return out;
181
+ }
182
+ function generate() {
183
+ const operations = [];
184
+ for (const table of Object.values(schema2.tables)) {
185
+ const oldTable = old.tables[table.ormName];
186
+ if (!oldTable) {
187
+ operations.push({
188
+ type: "create-table",
189
+ value: table
190
+ });
191
+ continue;
192
+ }
193
+ operations.push(...onTableUnusedForeignKeyCheck(oldTable, table), ...onTableRenameCheck(oldTable, table), ...onTableColumnsCheck(oldTable, table), ...onUniqueConstraintCheck(oldTable, table), ...onTableForeignKeyCheck(oldTable, table), ...onTableUnusedColumnsCheck(oldTable, table));
194
+ }
195
+ for (const oldTable of Object.values(old.tables)) if (!schema2.tables[oldTable.ormName] && dropUnusedTables) operations.push({
196
+ type: "drop-table",
197
+ name: getName(oldTable.names),
198
+ enforce: "post"
199
+ });
200
+ return reorder(operations);
201
+ }
202
+ return generate();
203
+ }
204
+ function createMigrator({ settings, generateMigrationFromDatabase, generateMigrationFromSchema: generateMigrationFromSchema2 = generateMigrationFromSchema, libConfig: { schemas, initialVersion = "0.0.0" }, userConfig, executor, sql: sqlConfig, transformers = [] }) {
205
+ const indexedSchemas = /* @__PURE__ */ new Map();
206
+ indexedSchemas.set(initialVersion, require_chunk_ZEQMAIFI.schema({
207
+ version: initialVersion,
208
+ tables: {}
209
+ }));
210
+ for (const schema2 of schemas) {
211
+ if (indexedSchemas.has(schema2.version)) throw new Error(`Duplicated version: ${schema2.version}`);
212
+ indexedSchemas.set(schema2.version, schema2);
213
+ }
214
+ function getSchemaByVersion(version) {
215
+ const schema2 = indexedSchemas.get(version);
216
+ if (!schema2) throw new Error(`Invalid version ${version}`);
217
+ return schema2;
218
+ }
219
+ async function getCurrentSchema() {
220
+ const version = await settings.getVersion() ?? initialVersion;
221
+ const nameVariants = await settings.getNameVariants();
222
+ let schema2 = getSchemaByVersion(version);
223
+ if (nameVariants) schema2 = require_chunk_7PZK4ONR.applyNameVariants(schema2, nameVariants);
224
+ return schema2;
225
+ }
226
+ function getSchemasOfVariant(variant) {
227
+ return schemas.filter((schema2) => require_chunk_ZEQMAIFI.deepEqual((0, semver.parse)(schema2.version).prerelease, variant));
228
+ }
229
+ return {
230
+ getVersion() {
231
+ return settings.getVersion();
232
+ },
233
+ getNameVariants() {
234
+ return settings.getNameVariants();
235
+ },
236
+ async next() {
237
+ const version = await settings.getVersion() ?? initialVersion;
238
+ const list = getSchemasOfVariant((0, semver.parse)(version).prerelease);
239
+ return list[list.findIndex((schema2) => schema2.version === version) + 1];
240
+ },
241
+ async previous() {
242
+ const version = await settings.getVersion();
243
+ if (!version) return;
244
+ const list = getSchemasOfVariant((0, semver.parse)(version).prerelease);
245
+ return list[list.findIndex((schema2) => schema2.version === version) - 1];
246
+ },
247
+ async up(options = {}) {
248
+ const next = await this.next();
249
+ if (!next) throw new Error("Already up to date.");
250
+ return this.migrateTo(next.version, options);
251
+ },
252
+ async down(options = {}) {
253
+ const prev = await this.previous();
254
+ if (!prev) throw new Error("No previous schema to migrate to.");
255
+ return this.migrateTo(prev.version, options);
256
+ },
257
+ async migrateTo(version, options = {}) {
258
+ const { updateSettings: updateVersion = true, unsafe = false, mode = "from-schema" } = options;
259
+ const targetSchema = getSchemaByVersion(version);
260
+ const currentSchema = await getCurrentSchema();
261
+ let run;
262
+ const prevVariant = (0, semver.parse)(targetSchema.version).prerelease;
263
+ const variant = (0, semver.parse)(currentSchema.version).prerelease;
264
+ if (require_chunk_ZEQMAIFI.deepEqual(prevVariant, variant)) {
265
+ const list = getSchemasOfVariant(variant);
266
+ const targetIdx = list.indexOf(targetSchema);
267
+ switch (currentSchema.version) {
268
+ case list[targetIdx - 1]?.version:
269
+ run = targetSchema.up;
270
+ break;
271
+ case list[targetIdx + 1]?.version:
272
+ run = targetSchema.down;
273
+ break;
274
+ }
275
+ }
276
+ run ??= (context2) => context2.auto();
277
+ let operations = await run({ async auto() {
278
+ let generated;
279
+ if (mode === "from-schema") generated = generateMigrationFromSchema2(currentSchema, targetSchema, userConfig);
280
+ else {
281
+ if (!generateMigrationFromDatabase) throw new Error(`${mode} is not supported for this adapter.`);
282
+ generated = await generateMigrationFromDatabase({
283
+ target: targetSchema,
284
+ dropUnusedColumns: unsafe
285
+ });
286
+ }
287
+ for (const transformer of transformers) {
288
+ if (!transformer.afterAuto) continue;
289
+ generated = transformer.afterAuto(generated, {
290
+ prev: currentSchema,
291
+ next: targetSchema,
292
+ options
293
+ });
294
+ }
295
+ return generated;
296
+ } });
297
+ if (updateVersion) operations.push(...await settings.updateSettingsInMigration(targetSchema));
298
+ for (const transformer of transformers) {
299
+ if (!transformer.afterAll) continue;
300
+ operations = transformer.afterAll(operations, {
301
+ prev: currentSchema,
302
+ next: targetSchema
303
+ });
304
+ }
305
+ return {
306
+ operations,
307
+ getSQL: sqlConfig ? () => sqlConfig.toSql(operations) : void 0,
308
+ execute: () => executor(operations)
309
+ };
310
+ },
311
+ async migrateToLatest(options) {
312
+ const last = getSchemasOfVariant((0, semver.parse)(await settings.getVersion() ?? initialVersion).prerelease).at(-1);
313
+ if (!last) throw new Error(`Cannot find other schemas`);
314
+ return this.migrateTo(last.version, options);
315
+ }
316
+ };
317
+ }
318
+ function exportNameVariants(schema2) {
319
+ const out = {};
320
+ for (const table of Object.values(schema2.tables)) {
321
+ out[table.ormName] = table.names;
322
+ for (const col of Object.values(table.columns)) out[`${table.ormName}.${col.ormName}`] = col.names;
323
+ }
324
+ return out;
325
+ }
326
+ //#endregion
327
+ exports.createMigrator = createMigrator;
328
+ exports.exportNameVariants = exportNameVariants;
329
+ exports.generateMigrationFromSchema = generateMigrationFromSchema;
330
+ exports.isUpdated = isUpdated;
@@ -0,0 +1,326 @@
1
+ import { applyNameVariants } from "./chunk-7PZK4ONR.mjs";
2
+ import { compileForeignKey, deepEqual, schema } from "./chunk-ZEQMAIFI.mjs";
3
+ import { parse } from "semver";
4
+ //#region ../../node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare+workers-types@4.20260313.1_@electric-sql+pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/chunk-C6OTUURW.js
5
+ function isUpdated(op) {
6
+ return op.updateDataType || op.updateDefault || op.updateNullable;
7
+ }
8
+ function generateMigrationFromSchema(old, schema2, options) {
9
+ const { provider, relationMode = provider === "mssql" || provider === "mongodb" ? "fumadb" : "foreign-keys", dropUnusedTables = true, dropUnusedColumns = true } = options;
10
+ function getName(names) {
11
+ return provider === "mongodb" ? names.mongodb : names.sql;
12
+ }
13
+ function columnActionToOperation(tableName, actions) {
14
+ if (actions.length === 0) return [];
15
+ if (provider === "mysql" || provider === "postgresql" || provider === "mongodb") return [{
16
+ type: "update-table",
17
+ name: tableName,
18
+ value: actions
19
+ }];
20
+ return actions.map((action) => ({
21
+ type: "update-table",
22
+ name: tableName,
23
+ value: [action]
24
+ }));
25
+ }
26
+ function onUniqueConstraintCheck(prev, next) {
27
+ const operations = [];
28
+ const newConstraints = next.getUniqueConstraints();
29
+ const oldConstraints = prev.getUniqueConstraints();
30
+ for (const con of newConstraints) {
31
+ const oldCon = oldConstraints.find((item) => item.name === con.name);
32
+ const columnNames = con.columns.map((col) => getName(col.names));
33
+ if (!oldCon) {
34
+ operations.push({
35
+ type: "add-unique-constraint",
36
+ name: con.name,
37
+ table: getName(next.names),
38
+ columns: columnNames
39
+ });
40
+ continue;
41
+ }
42
+ if (deepEqual(columnNames, oldCon.columns.map((col) => getName(col.names)))) continue;
43
+ operations.push({
44
+ type: "drop-unique-constraint",
45
+ table: getName(next.names),
46
+ name: con.name
47
+ }, {
48
+ type: "add-unique-constraint",
49
+ table: getName(next.names),
50
+ name: con.name,
51
+ columns: columnNames
52
+ });
53
+ }
54
+ for (const con of oldConstraints) if (newConstraints.every((item) => item.name !== con.name)) operations.push({
55
+ type: "drop-unique-constraint",
56
+ table: getName(next.names),
57
+ name: con.name
58
+ });
59
+ return operations;
60
+ }
61
+ function onTableRenameCheck(oldTable, newTable) {
62
+ const operations = [];
63
+ if (getName(newTable.names) !== getName(oldTable.names)) operations.push({
64
+ type: "rename-table",
65
+ from: getName(oldTable.names),
66
+ to: getName(newTable.names),
67
+ enforce: "pre"
68
+ });
69
+ return operations;
70
+ }
71
+ function onTableColumnsCheck(oldTable, newTable) {
72
+ const colActions = [];
73
+ for (const column of Object.values(newTable.columns)) {
74
+ let hashDefaultValue2 = function(col) {
75
+ if (!col.default || "runtime" in col.default) return;
76
+ if (col.type === "string" && provider === "mysql") return;
77
+ return col.default.value;
78
+ };
79
+ const oldColumn = oldTable.columns[column.ormName];
80
+ if (!oldColumn) {
81
+ colActions.push({
82
+ type: "create-column",
83
+ value: column
84
+ });
85
+ continue;
86
+ }
87
+ if (getName(column.names) !== getName(oldColumn.names)) colActions.push({
88
+ type: "rename-column",
89
+ from: getName(oldColumn.names),
90
+ to: getName(column.names)
91
+ });
92
+ const action = {
93
+ type: "update-column",
94
+ name: getName(column.names),
95
+ updateDataType: column.type !== oldColumn.type,
96
+ updateDefault: !deepEqual(hashDefaultValue2(column), hashDefaultValue2(oldColumn)),
97
+ updateNullable: column.isNullable !== oldColumn.isNullable,
98
+ value: column
99
+ };
100
+ if (isUpdated(action)) colActions.push(action);
101
+ }
102
+ return columnActionToOperation(getName(newTable.names), colActions);
103
+ }
104
+ function onTableForeignKeyCheck(oldTable, newTable) {
105
+ const tableName = getName(newTable.names);
106
+ const operations = [];
107
+ if (relationMode === "fumadb") return operations;
108
+ for (const foreignKey of newTable.foreignKeys) {
109
+ const compiled = compileForeignKey(foreignKey, "sql");
110
+ const oldKey = oldTable.foreignKeys.find((key) => key.name === foreignKey.name);
111
+ if (!oldKey) {
112
+ operations.push({
113
+ type: "add-foreign-key",
114
+ table: tableName,
115
+ value: compiled,
116
+ enforce: "post"
117
+ });
118
+ continue;
119
+ }
120
+ if (!deepEqual(compiled, compileForeignKey(oldKey, "sql"))) operations.push({
121
+ type: "drop-foreign-key",
122
+ name: oldKey.name,
123
+ table: tableName,
124
+ enforce: "post"
125
+ }, {
126
+ type: "add-foreign-key",
127
+ table: tableName,
128
+ value: compiled,
129
+ enforce: "post"
130
+ });
131
+ }
132
+ return operations;
133
+ }
134
+ function onTableUnusedForeignKeyCheck(oldTable, newTable) {
135
+ const operations = [];
136
+ for (const oldKey of oldTable.foreignKeys) {
137
+ if (!newTable.foreignKeys.every((key) => key.name !== oldKey.name)) continue;
138
+ operations.push({
139
+ type: "drop-foreign-key",
140
+ name: oldKey.name,
141
+ table: getName(oldTable.names),
142
+ enforce: "pre"
143
+ });
144
+ }
145
+ return operations;
146
+ }
147
+ function onTableUnusedColumnsCheck(oldTable, newTable) {
148
+ const constraints = newTable.getUniqueConstraints();
149
+ const operations = [];
150
+ for (const oldColumn of Object.values(oldTable.columns)) {
151
+ const isUnused = !newTable.columns[oldColumn.ormName];
152
+ const isRequired = !oldColumn.isNullable && !oldColumn.default;
153
+ if (!(isUnused && (dropUnusedColumns || isRequired))) continue;
154
+ if (provider === "mssql" && oldColumn.isUnique) for (const con of constraints) {
155
+ if (con.columns.every((col) => col.ormName !== oldColumn.ormName)) continue;
156
+ operations.push({
157
+ type: "drop-unique-constraint",
158
+ name: con.name,
159
+ table: getName(newTable.names)
160
+ });
161
+ }
162
+ operations.push({
163
+ type: "update-table",
164
+ name: getName(newTable.names),
165
+ value: [{
166
+ type: "drop-column",
167
+ name: getName(oldColumn.names)
168
+ }],
169
+ enforce: "post"
170
+ });
171
+ }
172
+ return operations;
173
+ }
174
+ function reorder(operations) {
175
+ const out = [];
176
+ for (const item of operations) if (item.enforce === "pre") out.push(item);
177
+ for (const item of operations) if (!item.enforce) out.push(item);
178
+ for (const item of operations) if (item.enforce === "post") out.push(item);
179
+ return out;
180
+ }
181
+ function generate() {
182
+ const operations = [];
183
+ for (const table of Object.values(schema2.tables)) {
184
+ const oldTable = old.tables[table.ormName];
185
+ if (!oldTable) {
186
+ operations.push({
187
+ type: "create-table",
188
+ value: table
189
+ });
190
+ continue;
191
+ }
192
+ operations.push(...onTableUnusedForeignKeyCheck(oldTable, table), ...onTableRenameCheck(oldTable, table), ...onTableColumnsCheck(oldTable, table), ...onUniqueConstraintCheck(oldTable, table), ...onTableForeignKeyCheck(oldTable, table), ...onTableUnusedColumnsCheck(oldTable, table));
193
+ }
194
+ for (const oldTable of Object.values(old.tables)) if (!schema2.tables[oldTable.ormName] && dropUnusedTables) operations.push({
195
+ type: "drop-table",
196
+ name: getName(oldTable.names),
197
+ enforce: "post"
198
+ });
199
+ return reorder(operations);
200
+ }
201
+ return generate();
202
+ }
203
+ function createMigrator({ settings, generateMigrationFromDatabase, generateMigrationFromSchema: generateMigrationFromSchema2 = generateMigrationFromSchema, libConfig: { schemas, initialVersion = "0.0.0" }, userConfig, executor, sql: sqlConfig, transformers = [] }) {
204
+ const indexedSchemas = /* @__PURE__ */ new Map();
205
+ indexedSchemas.set(initialVersion, schema({
206
+ version: initialVersion,
207
+ tables: {}
208
+ }));
209
+ for (const schema2 of schemas) {
210
+ if (indexedSchemas.has(schema2.version)) throw new Error(`Duplicated version: ${schema2.version}`);
211
+ indexedSchemas.set(schema2.version, schema2);
212
+ }
213
+ function getSchemaByVersion(version) {
214
+ const schema2 = indexedSchemas.get(version);
215
+ if (!schema2) throw new Error(`Invalid version ${version}`);
216
+ return schema2;
217
+ }
218
+ async function getCurrentSchema() {
219
+ const version = await settings.getVersion() ?? initialVersion;
220
+ const nameVariants = await settings.getNameVariants();
221
+ let schema2 = getSchemaByVersion(version);
222
+ if (nameVariants) schema2 = applyNameVariants(schema2, nameVariants);
223
+ return schema2;
224
+ }
225
+ function getSchemasOfVariant(variant) {
226
+ return schemas.filter((schema2) => deepEqual(parse(schema2.version).prerelease, variant));
227
+ }
228
+ return {
229
+ getVersion() {
230
+ return settings.getVersion();
231
+ },
232
+ getNameVariants() {
233
+ return settings.getNameVariants();
234
+ },
235
+ async next() {
236
+ const version = await settings.getVersion() ?? initialVersion;
237
+ const list = getSchemasOfVariant(parse(version).prerelease);
238
+ return list[list.findIndex((schema2) => schema2.version === version) + 1];
239
+ },
240
+ async previous() {
241
+ const version = await settings.getVersion();
242
+ if (!version) return;
243
+ const list = getSchemasOfVariant(parse(version).prerelease);
244
+ return list[list.findIndex((schema2) => schema2.version === version) - 1];
245
+ },
246
+ async up(options = {}) {
247
+ const next = await this.next();
248
+ if (!next) throw new Error("Already up to date.");
249
+ return this.migrateTo(next.version, options);
250
+ },
251
+ async down(options = {}) {
252
+ const prev = await this.previous();
253
+ if (!prev) throw new Error("No previous schema to migrate to.");
254
+ return this.migrateTo(prev.version, options);
255
+ },
256
+ async migrateTo(version, options = {}) {
257
+ const { updateSettings: updateVersion = true, unsafe = false, mode = "from-schema" } = options;
258
+ const targetSchema = getSchemaByVersion(version);
259
+ const currentSchema = await getCurrentSchema();
260
+ let run;
261
+ const prevVariant = parse(targetSchema.version).prerelease;
262
+ const variant = parse(currentSchema.version).prerelease;
263
+ if (deepEqual(prevVariant, variant)) {
264
+ const list = getSchemasOfVariant(variant);
265
+ const targetIdx = list.indexOf(targetSchema);
266
+ switch (currentSchema.version) {
267
+ case list[targetIdx - 1]?.version:
268
+ run = targetSchema.up;
269
+ break;
270
+ case list[targetIdx + 1]?.version:
271
+ run = targetSchema.down;
272
+ break;
273
+ }
274
+ }
275
+ run ??= (context2) => context2.auto();
276
+ let operations = await run({ async auto() {
277
+ let generated;
278
+ if (mode === "from-schema") generated = generateMigrationFromSchema2(currentSchema, targetSchema, userConfig);
279
+ else {
280
+ if (!generateMigrationFromDatabase) throw new Error(`${mode} is not supported for this adapter.`);
281
+ generated = await generateMigrationFromDatabase({
282
+ target: targetSchema,
283
+ dropUnusedColumns: unsafe
284
+ });
285
+ }
286
+ for (const transformer of transformers) {
287
+ if (!transformer.afterAuto) continue;
288
+ generated = transformer.afterAuto(generated, {
289
+ prev: currentSchema,
290
+ next: targetSchema,
291
+ options
292
+ });
293
+ }
294
+ return generated;
295
+ } });
296
+ if (updateVersion) operations.push(...await settings.updateSettingsInMigration(targetSchema));
297
+ for (const transformer of transformers) {
298
+ if (!transformer.afterAll) continue;
299
+ operations = transformer.afterAll(operations, {
300
+ prev: currentSchema,
301
+ next: targetSchema
302
+ });
303
+ }
304
+ return {
305
+ operations,
306
+ getSQL: sqlConfig ? () => sqlConfig.toSql(operations) : void 0,
307
+ execute: () => executor(operations)
308
+ };
309
+ },
310
+ async migrateToLatest(options) {
311
+ const last = getSchemasOfVariant(parse(await settings.getVersion() ?? initialVersion).prerelease).at(-1);
312
+ if (!last) throw new Error(`Cannot find other schemas`);
313
+ return this.migrateTo(last.version, options);
314
+ }
315
+ };
316
+ }
317
+ function exportNameVariants(schema2) {
318
+ const out = {};
319
+ for (const table of Object.values(schema2.tables)) {
320
+ out[table.ormName] = table.names;
321
+ for (const col of Object.values(table.columns)) out[`${table.ormName}.${col.ormName}`] = col.names;
322
+ }
323
+ return out;
324
+ }
325
+ //#endregion
326
+ export { createMigrator, exportNameVariants, generateMigrationFromSchema, isUpdated };