qarpeo 0.1.35 → 0.2.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 (363) hide show
  1. package/README.md +114 -26
  2. package/dist/apps/cms.d.ts +4 -0
  3. package/dist/apps/comments.d.ts +4 -0
  4. package/dist/apps/payments.d.ts +4 -0
  5. package/dist/apps/store.d.ts +4 -0
  6. package/dist/chunks/auth-schema.mjs +169 -30
  7. package/dist/chunks/tools.mjs +1680 -0
  8. package/dist/cli/index.mjs +1256 -221
  9. package/dist/core/aliases.d.ts +5 -0
  10. package/dist/core/context.d.ts +10 -0
  11. package/dist/core/cross-drive.d.ts +2 -0
  12. package/dist/core/d1-migrate.d.ts +4 -0
  13. package/dist/core/devtools.d.ts +4 -0
  14. package/dist/core/nitro.d.ts +4 -0
  15. package/dist/core/schema.d.ts +4 -0
  16. package/dist/core/server-utils.d.ts +4 -0
  17. package/dist/core/wrangler.d.ts +4 -0
  18. package/dist/dev/wrangler.d.ts +1 -0
  19. package/dist/fate/index.d.ts +8 -8
  20. package/dist/features/agents.d.ts +4 -0
  21. package/dist/features/auth.d.ts +4 -0
  22. package/dist/features/bots.d.ts +4 -0
  23. package/dist/features/fate.d.ts +4 -0
  24. package/dist/features/mail.d.ts +4 -0
  25. package/dist/features/mcp.d.ts +4 -0
  26. package/dist/features/multitenant.d.ts +4 -0
  27. package/dist/features/notifications.d.ts +4 -0
  28. package/dist/features/realtime.d.ts +4 -0
  29. package/dist/module.d.ts +10 -2
  30. package/dist/module.mjs +6313 -5118
  31. package/dist/primitives/ai.d.ts +4 -0
  32. package/dist/primitives/analytics.d.ts +4 -0
  33. package/dist/primitives/blob.d.ts +4 -0
  34. package/dist/primitives/browser.d.ts +4 -0
  35. package/dist/primitives/cache.d.ts +4 -0
  36. package/dist/primitives/d1.d.ts +4 -0
  37. package/dist/primitives/do.d.ts +4 -0
  38. package/dist/primitives/email.d.ts +4 -0
  39. package/dist/primitives/hyperdrive.d.ts +4 -0
  40. package/dist/primitives/kv.d.ts +4 -0
  41. package/dist/primitives/queue.d.ts +4 -0
  42. package/dist/primitives/ratelimit.d.ts +4 -0
  43. package/dist/primitives/vectorize.d.ts +4 -0
  44. package/dist/primitives/workflows.d.ts +4 -0
  45. package/dist/runtime/ai.d.ts +3 -3
  46. package/dist/runtime/ai.mjs +8 -1
  47. package/dist/runtime/app/components/RealtimeCursors.vue +2 -2
  48. package/dist/runtime/app/composables/ai.d.ts +56 -29
  49. package/dist/runtime/app/composables/analytics.d.ts +26 -106
  50. package/dist/runtime/app/composables/api-tokens.d.ts +31 -34
  51. package/dist/runtime/app/composables/auth.d.ts +147 -51
  52. package/dist/runtime/app/composables/auth.mjs +0 -7
  53. package/dist/runtime/app/composables/chat.d.ts +38 -35
  54. package/dist/runtime/app/composables/cms-preview.d.ts +30 -25
  55. package/dist/runtime/app/composables/cms.d.ts +57 -282
  56. package/dist/runtime/app/composables/cms.mjs +0 -35
  57. package/dist/runtime/app/composables/comments.d.ts +32 -5
  58. package/dist/runtime/app/composables/comments.mjs +29 -1
  59. package/dist/runtime/app/composables/docs-version.d.ts +25 -28
  60. package/dist/runtime/app/composables/impersonation.d.ts +22 -5
  61. package/dist/runtime/app/composables/organization.d.ts +38 -91
  62. package/dist/runtime/app/composables/passkey.d.ts +22 -6
  63. package/dist/runtime/app/composables/passwordless.d.ts +24 -7
  64. package/dist/runtime/app/composables/payments.d.ts +50 -34
  65. package/dist/runtime/app/composables/payments.mjs +1 -0
  66. package/dist/runtime/app/composables/sse.d.ts +76 -0
  67. package/dist/runtime/app/composables/sse.mjs +152 -0
  68. package/dist/runtime/app/composables/storage.d.ts +53 -65
  69. package/dist/runtime/app/composables/storage.mjs +17 -0
  70. package/dist/runtime/app/composables/store.d.ts +198 -0
  71. package/dist/runtime/app/composables/store.mjs +414 -0
  72. package/dist/runtime/app/composables/tenant.d.ts +31 -72
  73. package/dist/runtime/app/composables/turnstile.d.ts +16 -3
  74. package/dist/runtime/app/composables/two-factor.d.ts +23 -6
  75. package/dist/runtime/app/pages/devtools/notifications.vue +30 -27
  76. package/dist/runtime/app/pages/devtools/realtime.vue +19 -31
  77. package/dist/runtime/app/pages/devtools.vue +0 -7
  78. package/dist/runtime/auth.d.ts +9 -9
  79. package/dist/runtime/blob.d.ts +10 -1
  80. package/dist/runtime/blob.mjs +83 -0
  81. package/dist/runtime/cache.d.ts +48 -0
  82. package/dist/runtime/cache.mjs +92 -0
  83. package/dist/runtime/comments.d.ts +4 -0
  84. package/dist/runtime/comments.mjs +2 -0
  85. package/dist/runtime/db.d.ts +21 -1
  86. package/dist/runtime/db.mjs +54 -0
  87. package/dist/runtime/drizzle.d.ts +4 -2
  88. package/dist/runtime/drizzle.mjs +68 -1
  89. package/dist/runtime/durable-object.d.ts +2 -0
  90. package/dist/runtime/durable-object.mjs +2 -0
  91. package/dist/runtime/email.d.ts +1 -1
  92. package/dist/runtime/email.mjs +1 -1
  93. package/dist/runtime/kv.mjs +50 -1
  94. package/dist/runtime/mcp.d.ts +2 -0
  95. package/dist/runtime/mcp.mjs +2 -0
  96. package/dist/runtime/queue.d.ts +12 -2
  97. package/dist/runtime/queue.mjs +19 -1
  98. package/dist/runtime/ratelimit.d.ts +1 -0
  99. package/dist/runtime/ratelimit.mjs +7 -0
  100. package/dist/runtime/schema.d.ts +313 -0
  101. package/dist/runtime/schema.mjs +259 -0
  102. package/dist/runtime/server/db/cms-schema.d.ts +1225 -171
  103. package/dist/runtime/server/db/cms-schema.mjs +69 -70
  104. package/dist/runtime/server/db/store-schema.d.ts +4344 -0
  105. package/dist/runtime/server/db/store-schema.mjs +266 -0
  106. package/dist/runtime/server/durable-objects/agent.mjs +35 -0
  107. package/dist/runtime/server/durable-objects/room.mjs +0 -1
  108. package/dist/runtime/server/middleware/ratelimit.mjs +10 -8
  109. package/dist/runtime/server/plugins/comments.d.ts +7 -0
  110. package/dist/runtime/server/plugins/comments.mjs +7 -0
  111. package/dist/runtime/server/plugins/email-inbound.d.ts +5 -0
  112. package/dist/runtime/server/plugins/email-inbound.mjs +17 -0
  113. package/dist/runtime/server/plugins/store.d.ts +7 -0
  114. package/dist/runtime/server/plugins/store.mjs +7 -0
  115. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +2 -2
  116. package/dist/runtime/server/routes/atom.xml.get.mjs +3 -1
  117. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +13 -2
  118. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +9 -3
  119. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -3
  120. package/dist/runtime/server/routes/auth/account.delete.mjs +2 -1
  121. package/dist/runtime/server/routes/auth/audit-logs.get.mjs +1 -1
  122. package/dist/runtime/server/routes/auth/magic-link/send.post.d.ts +1 -9
  123. package/dist/runtime/server/routes/auth/magic-link/send.post.mjs +8 -0
  124. package/dist/runtime/server/routes/auth/organization/sso/[id].delete.mjs +1 -1
  125. package/dist/runtime/server/routes/auth/organization/sso/index.get.mjs +1 -1
  126. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +1 -1
  127. package/dist/runtime/server/routes/auth/otp/send.post.d.ts +1 -9
  128. package/dist/runtime/server/routes/auth/otp/send.post.mjs +8 -0
  129. package/dist/runtime/server/routes/auth/sso/login.get.mjs +3 -3
  130. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +1 -1
  131. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +2 -2
  132. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  133. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +1 -1
  134. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +2 -2
  135. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +1 -1
  136. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +1 -1
  137. package/dist/runtime/server/routes/cms/[collection]/atom.xml.get.mjs +3 -1
  138. package/dist/runtime/server/routes/cms/[collection]/feed.xml.get.mjs +3 -1
  139. package/dist/runtime/server/routes/cms/bookmarks/[id].delete.mjs +1 -1
  140. package/dist/runtime/server/routes/cms/bookmarks/check.post.mjs +1 -1
  141. package/dist/runtime/server/routes/cms/bookmarks/index.get.mjs +1 -1
  142. package/dist/runtime/server/routes/cms/bookmarks/index.post.mjs +1 -1
  143. package/dist/runtime/server/routes/cms/deploy.post.mjs +1 -1
  144. package/dist/runtime/server/routes/cms/export.post.mjs +4 -3
  145. package/dist/runtime/server/routes/cms/search.get.mjs +7 -5
  146. package/dist/runtime/server/routes/cms/sync.post.mjs +2 -1
  147. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +1 -2
  148. package/dist/runtime/server/routes/comments/[id]/report.post.d.ts +1 -1
  149. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +0 -2
  150. package/dist/runtime/server/routes/comments/[id].delete.mjs +8 -4
  151. package/dist/runtime/server/routes/comments/[id].get.d.ts +1 -1
  152. package/dist/runtime/server/routes/comments/[id].get.mjs +1 -2
  153. package/dist/runtime/server/routes/comments/[id].patch.d.ts +1 -1
  154. package/dist/runtime/server/routes/comments/[id].patch.mjs +6 -3
  155. package/dist/runtime/server/routes/comments/batch.post.d.ts +2 -0
  156. package/dist/runtime/server/routes/comments/batch.post.mjs +33 -0
  157. package/dist/runtime/server/routes/comments/index.get.d.ts +1 -1
  158. package/dist/runtime/server/routes/comments/index.get.mjs +6 -4
  159. package/dist/runtime/server/routes/comments/index.post.d.ts +1 -1
  160. package/dist/runtime/server/routes/comments/index.post.mjs +6 -2
  161. package/dist/runtime/server/routes/feed.xml.get.mjs +3 -1
  162. package/dist/runtime/server/routes/sitemap.xml.get.mjs +3 -1
  163. package/dist/runtime/server/routes/storage/presigned-r2.post.d.ts +17 -0
  164. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +29 -0
  165. package/dist/runtime/server/routes/store/cart/index.delete.d.ts +6 -0
  166. package/dist/runtime/server/routes/store/cart/index.delete.mjs +11 -0
  167. package/dist/runtime/server/routes/store/cart/index.get.d.ts +5 -0
  168. package/dist/runtime/server/routes/store/cart/index.get.mjs +14 -0
  169. package/dist/runtime/server/routes/store/cart/items/[id].delete.d.ts +6 -0
  170. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +25 -0
  171. package/dist/runtime/server/routes/store/cart/items/[id].patch.d.ts +6 -0
  172. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +29 -0
  173. package/dist/runtime/server/routes/store/cart/items.post.d.ts +6 -0
  174. package/dist/runtime/server/routes/store/cart/items.post.mjs +36 -0
  175. package/dist/runtime/server/routes/store/categories/index.get.d.ts +2 -0
  176. package/dist/runtime/server/routes/store/categories/index.get.mjs +8 -0
  177. package/dist/runtime/server/routes/store/checkout.post.d.ts +6 -0
  178. package/dist/runtime/server/routes/store/checkout.post.mjs +21 -0
  179. package/dist/runtime/server/routes/store/coupons/apply.post.d.ts +7 -0
  180. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +18 -0
  181. package/dist/runtime/server/routes/store/currencies.get.d.ts +15 -0
  182. package/dist/runtime/server/routes/store/currencies.get.mjs +13 -0
  183. package/dist/runtime/server/routes/store/orders/[id].get.d.ts +2 -0
  184. package/dist/runtime/server/routes/store/orders/[id].get.mjs +26 -0
  185. package/dist/runtime/server/routes/store/orders/download/[token].get.d.ts +7 -0
  186. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +57 -0
  187. package/dist/runtime/server/routes/store/orders/index.get.d.ts +5 -0
  188. package/dist/runtime/server/routes/store/orders/index.get.mjs +30 -0
  189. package/dist/runtime/server/routes/store/products/[slug].get.d.ts +2 -0
  190. package/dist/runtime/server/routes/store/products/[slug].get.mjs +18 -0
  191. package/dist/runtime/server/routes/store/products/index.get.d.ts +5 -0
  192. package/dist/runtime/server/routes/store/products/index.get.mjs +33 -0
  193. package/dist/runtime/server/routes/store/tax/calculate.post.d.ts +9 -0
  194. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +18 -0
  195. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +14 -1
  196. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +14 -1
  197. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +24 -1
  198. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +6 -0
  199. package/dist/runtime/server/utils/ai.d.ts +146 -21
  200. package/dist/runtime/server/utils/ai.mjs +406 -11
  201. package/dist/runtime/server/utils/analytics-query.d.ts +13 -58
  202. package/dist/runtime/server/utils/audit.d.ts +5 -4
  203. package/dist/runtime/server/utils/audit.mjs +25 -14
  204. package/dist/runtime/server/utils/auth.d.ts +29 -12
  205. package/dist/runtime/server/utils/auth.mjs +88 -70
  206. package/dist/runtime/server/utils/bots.d.ts +20 -4
  207. package/dist/runtime/server/utils/bots.mjs +7 -3
  208. package/dist/runtime/server/utils/browser-utils.d.ts +23 -23
  209. package/dist/runtime/server/utils/cache.d.ts +3 -3
  210. package/dist/runtime/server/utils/cms/collections.d.ts +23 -0
  211. package/dist/runtime/server/utils/cms/collections.mjs +143 -0
  212. package/dist/runtime/server/utils/cms/common.d.ts +9 -0
  213. package/dist/runtime/server/utils/cms/common.mjs +28 -0
  214. package/dist/runtime/server/utils/cms/git.mjs +2 -2
  215. package/dist/runtime/server/utils/cms/navigation.d.ts +46 -0
  216. package/dist/runtime/server/utils/cms/navigation.mjs +683 -0
  217. package/dist/runtime/server/utils/cms/preview.d.ts +11 -0
  218. package/dist/runtime/server/utils/cms/preview.mjs +50 -0
  219. package/dist/runtime/server/utils/cms/search.d.ts +1 -1
  220. package/dist/runtime/server/utils/cms/search.mjs +11 -7
  221. package/dist/runtime/server/utils/cms/sync.d.ts +34 -0
  222. package/dist/runtime/server/utils/cms/sync.mjs +1082 -0
  223. package/dist/runtime/server/utils/cms/taxonomy.d.ts +103 -0
  224. package/dist/runtime/server/utils/cms/taxonomy.mjs +348 -0
  225. package/dist/runtime/server/utils/cms.d.ts +13 -249
  226. package/dist/runtime/server/utils/cms.mjs +108 -2350
  227. package/dist/runtime/server/utils/comments-filter.d.ts +45 -0
  228. package/dist/runtime/server/utils/comments-filter.mjs +541 -0
  229. package/dist/runtime/server/utils/comments.d.ts +71 -0
  230. package/dist/runtime/server/utils/comments.mjs +137 -61
  231. package/dist/runtime/server/utils/config.d.ts +4 -3
  232. package/dist/runtime/server/utils/config.mjs +7 -6
  233. package/dist/runtime/server/utils/context.d.ts +14 -0
  234. package/dist/runtime/server/utils/context.mjs +2 -2
  235. package/dist/runtime/server/utils/crypto.d.ts +44 -5
  236. package/dist/runtime/server/utils/crypto.mjs +18 -0
  237. package/dist/runtime/server/utils/domains.mjs +9 -5
  238. package/dist/runtime/server/utils/drizzle.d.ts +35 -3
  239. package/dist/runtime/server/utils/drizzle.mjs +115 -6
  240. package/dist/runtime/server/utils/durable-object.d.ts +106 -0
  241. package/dist/runtime/server/utils/durable-object.mjs +628 -0
  242. package/dist/runtime/server/utils/email-inbound.d.ts +29 -0
  243. package/dist/runtime/server/utils/email-inbound.mjs +76 -0
  244. package/dist/runtime/server/utils/impersonation.d.ts +32 -2
  245. package/dist/runtime/server/utils/impersonation.mjs +16 -13
  246. package/dist/runtime/server/utils/lock.d.ts +71 -0
  247. package/dist/runtime/server/utils/lock.mjs +139 -0
  248. package/dist/runtime/server/utils/mail-suppression.mjs +7 -7
  249. package/dist/runtime/server/utils/mail.d.ts +30 -19
  250. package/dist/runtime/server/utils/mcp.d.ts +44 -0
  251. package/dist/runtime/server/utils/mcp.mjs +308 -0
  252. package/dist/runtime/server/utils/notifications.d.ts +72 -7
  253. package/dist/runtime/server/utils/notifications.mjs +67 -55
  254. package/dist/runtime/server/utils/oauth.d.ts +27 -4
  255. package/dist/runtime/server/utils/organization.d.ts +63 -7
  256. package/dist/runtime/server/utils/organization.mjs +26 -21
  257. package/dist/runtime/server/utils/passwordless.d.ts +62 -33
  258. package/dist/runtime/server/utils/payments.d.ts +51 -12
  259. package/dist/runtime/server/utils/payments.mjs +472 -282
  260. package/dist/runtime/server/utils/queue.d.ts +106 -13
  261. package/dist/runtime/server/utils/queue.mjs +313 -28
  262. package/dist/runtime/server/utils/rag.d.ts +42 -14
  263. package/dist/runtime/server/utils/rag.mjs +169 -4
  264. package/dist/runtime/server/utils/ratelimit.d.ts +34 -5
  265. package/dist/runtime/server/utils/ratelimit.mjs +95 -14
  266. package/dist/runtime/server/utils/realtime.d.ts +68 -52
  267. package/dist/runtime/server/utils/scheduled-task.d.ts +42 -1
  268. package/dist/runtime/server/utils/scheduled-task.mjs +29 -0
  269. package/dist/runtime/server/utils/schema-fallback.d.ts +1 -1
  270. package/dist/runtime/server/utils/schema-fallback.mjs +1 -1
  271. package/dist/runtime/server/utils/session.d.ts +84 -10
  272. package/dist/runtime/server/utils/session.mjs +12 -10
  273. package/dist/runtime/server/utils/sse.d.ts +75 -0
  274. package/dist/runtime/server/utils/sse.mjs +147 -0
  275. package/dist/runtime/server/utils/sso.d.ts +1 -1
  276. package/dist/runtime/server/utils/storage.d.ts +53 -4
  277. package/dist/runtime/server/utils/storage.mjs +15 -11
  278. package/dist/runtime/server/utils/store-localization.d.ts +51 -0
  279. package/dist/runtime/server/utils/store-localization.mjs +417 -0
  280. package/dist/runtime/server/utils/store.d.ts +207 -0
  281. package/dist/runtime/server/utils/store.mjs +2227 -0
  282. package/dist/runtime/server/utils/table-names.d.ts +51 -0
  283. package/dist/runtime/server/utils/table-names.mjs +69 -0
  284. package/dist/runtime/server/utils/tenant.d.ts +26 -2
  285. package/dist/runtime/server/utils/tenant.mjs +16 -12
  286. package/dist/runtime/server/utils/tools-registry-fallback.d.ts +1 -0
  287. package/dist/runtime/server/utils/tools-registry-fallback.mjs +1 -0
  288. package/dist/runtime/server/utils/totp.d.ts +45 -2
  289. package/dist/runtime/server/utils/tracker.d.ts +10 -11
  290. package/dist/runtime/server/utils/turnstile.d.ts +16 -1
  291. package/dist/runtime/server/utils/workflows.d.ts +92 -0
  292. package/dist/runtime/server/utils/workflows.mjs +299 -0
  293. package/dist/runtime/server.d.ts +8 -1
  294. package/dist/runtime/server.mjs +8 -5
  295. package/dist/runtime/service.d.ts +10 -10
  296. package/dist/runtime/storage.d.ts +1 -0
  297. package/dist/runtime/storage.mjs +1 -0
  298. package/dist/runtime/store.d.ts +4 -0
  299. package/dist/runtime/store.mjs +2 -0
  300. package/dist/runtime/test-utils.d.ts +11 -10
  301. package/dist/runtime/test-utils.mjs +64 -4
  302. package/dist/runtime/types/ai.d.ts +21 -2
  303. package/dist/runtime/types/d1.d.ts +17 -0
  304. package/dist/runtime/types/drizzle.d.ts +2 -2
  305. package/dist/runtime/types/durable-object.d.ts +62 -2
  306. package/dist/runtime/types/email.d.ts +46 -0
  307. package/dist/runtime/types/imports.d.ts +6 -1
  308. package/dist/runtime/types/index.d.ts +58 -0
  309. package/dist/runtime/types/index.mjs +3 -0
  310. package/dist/runtime/types/mcp.d.ts +83 -0
  311. package/dist/runtime/types/mcp.mjs +0 -0
  312. package/dist/runtime/types/queue.d.ts +36 -0
  313. package/dist/runtime/types/r2.d.ts +41 -0
  314. package/dist/runtime/types/store.d.ts +313 -0
  315. package/dist/runtime/types/store.mjs +0 -0
  316. package/dist/runtime/types/workflows.d.ts +98 -0
  317. package/dist/runtime/types/workflows.mjs +0 -0
  318. package/dist/runtime/workflows.d.ts +5 -0
  319. package/dist/runtime/workflows.mjs +2 -0
  320. package/dist/types/ai.d.ts +721 -0
  321. package/dist/types/cms.d.ts +710 -0
  322. package/dist/types.d.ts +406 -1288
  323. package/dist/utils/auth-schema.d.ts +3 -2
  324. package/dist/utils/bots.d.ts +20 -0
  325. package/dist/utils/comments-schema.d.ts +5 -4
  326. package/dist/utils/drizzle.d.ts +83 -3
  327. package/dist/utils/durable-objects.d.ts +10 -0
  328. package/dist/utils/email-inbound.d.ts +10 -0
  329. package/dist/utils/local-db.d.ts +1 -3
  330. package/dist/utils/mcp.d.ts +24 -0
  331. package/dist/utils/notifications-schema.d.ts +5 -4
  332. package/dist/utils/payments-schema.d.ts +4 -3
  333. package/dist/utils/store-schema.d.ts +14 -0
  334. package/dist/utils/table-names.d.ts +1 -0
  335. package/dist/utils/tenants-schema.d.ts +4 -3
  336. package/dist/utils/tools.d.ts +20 -0
  337. package/dist/utils/workflows.d.ts +8 -0
  338. package/package.json +34 -4
  339. package/dist/chunks/wrangler.mjs +0 -897
  340. package/dist/runtime/app/components/AuthRegister.vue +0 -306
  341. package/dist/runtime/app/components/AuthSessionsList.vue +0 -137
  342. package/dist/runtime/app/components/AuthSignIn.vue +0 -298
  343. package/dist/runtime/app/components/CMSBookmarkButton.vue +0 -59
  344. package/dist/runtime/app/components/CMSImage.vue +0 -47
  345. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +0 -110
  346. package/dist/runtime/app/components/CMSNewsletter.vue +0 -81
  347. package/dist/runtime/app/components/CMSPreviewBanner.vue +0 -83
  348. package/dist/runtime/app/components/CMSTableOfContents.vue +0 -84
  349. package/dist/runtime/app/components/CMSVersionBanner.vue +0 -53
  350. package/dist/runtime/app/components/CMSVersionSwitcher.vue +0 -140
  351. package/dist/runtime/app/components/Comments.vue +0 -411
  352. package/dist/runtime/app/components/FileUpload.vue +0 -200
  353. package/dist/runtime/app/components/ImpersonationBanner.vue +0 -61
  354. package/dist/runtime/app/components/NotificationBell.vue +0 -263
  355. package/dist/runtime/app/components/NotificationList.vue +0 -205
  356. package/dist/runtime/app/components/NotificationPrompt.vue +0 -133
  357. package/dist/runtime/app/components/PricingGated.vue +0 -81
  358. package/dist/runtime/app/components/PricingTable.vue +0 -274
  359. package/dist/runtime/app/components/RealtimeChat.vue +0 -164
  360. package/dist/runtime/app/components/RealtimePresence.vue +0 -129
  361. package/dist/runtime/app/components/RealtimeStatus.vue +0 -79
  362. package/dist/runtime/app/components/SubscriptionCard.vue +0 -207
  363. package/dist/runtime/app/components/UserProfile.vue +0 -558
@@ -0,0 +1,1680 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, statSync, readdirSync, readFileSync } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import { drizzle } from 'drizzle-orm/node-sqlite';
5
+ import { resolve, dirname, join, extname, basename, relative } from 'pathe';
6
+ import { stdin, stdout } from 'node:process';
7
+ import readline from 'node:readline/promises';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { mkdir, writeFile, readFile } from 'node:fs/promises';
10
+ import { defu } from 'defu';
11
+
12
+ const version = "0.2.0";
13
+
14
+ function resolveBindingName(service, override, defaultName) {
15
+ if (override && typeof override === "string") {
16
+ return override;
17
+ }
18
+ const upper = service.toUpperCase();
19
+ return process.env[`QARPEO_DEFAULT_${upper}_BINDING`] || process.env[`QARPEO_${upper}_BINDING`] || process.env[`${upper}_BINDING`] || defaultName || upper;
20
+ }
21
+
22
+ function singularize(name) {
23
+ let clean = name.replace(/_?tables?$/i, "");
24
+ if (!clean) clean = name;
25
+ if (clean.endsWith("ies") && clean.length > 3) return clean.slice(0, -3) + "y";
26
+ if (clean.endsWith("sses") && clean.length > 4) return clean.slice(0, -2);
27
+ if (clean.endsWith("xes") && clean.length > 3) return clean.slice(0, -2);
28
+ if (clean.endsWith("ches") && clean.length > 4) return clean.slice(0, -2);
29
+ if (clean.endsWith("shes") && clean.length > 4) return clean.slice(0, -2);
30
+ if (clean.endsWith("us") || clean.endsWith("is") || clean.endsWith("ss") || clean === "news") return clean;
31
+ if (clean.endsWith("s") && clean.length > 2) return clean.slice(0, -1);
32
+ return clean;
33
+ }
34
+ function toPascalCase$1(str) {
35
+ return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
36
+ }
37
+ function toCamelCase$1(str) {
38
+ const pascal = toPascalCase$1(str);
39
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
40
+ }
41
+ function scanSchemaExports(schemaFiles) {
42
+ const types = [];
43
+ const zod = [];
44
+ const tables = [];
45
+ for (const file of schemaFiles) {
46
+ let src;
47
+ try {
48
+ src = readFileSync(file, "utf-8");
49
+ } catch {
50
+ continue;
51
+ }
52
+ for (const m of src.matchAll(/^export\s+type\s+([A-Z][A-Za-z0-9_]*)\b/gm)) {
53
+ types.push({ name: m[1], file });
54
+ }
55
+ for (const m of src.matchAll(/^export\s+const\s+([a-z][A-Za-z0-9_]*Schema)\b/gm)) {
56
+ zod.push({ name: m[1], file });
57
+ }
58
+ for (const m of src.matchAll(/^export\s+const\s+([a-zA-Z0-9_]+)\s*=\s*(?:[a-zA-Z0-9_$.]+\.)?(?:snakeCase\.table|sqliteTable|pgTable|mysqlTable|msTable|sqlTable|table)\b/gm)) {
59
+ const varName = m[1];
60
+ if (varName.startsWith("ALL_") || varName.endsWith("_NAMES")) continue;
61
+ const singular = singularize(varName);
62
+ tables.push({
63
+ name: varName,
64
+ modelName: toPascalCase$1(singular),
65
+ camelName: toCamelCase$1(singular),
66
+ file
67
+ });
68
+ }
69
+ }
70
+ return { types, zod, tables };
71
+ }
72
+ function checkDrizzleVersion(rootDir) {
73
+ try {
74
+ let req;
75
+ let entry;
76
+ try {
77
+ req = createRequire(resolve(rootDir, "package.json"));
78
+ entry = req.resolve("drizzle-orm");
79
+ } catch {
80
+ req = createRequire(import.meta.url);
81
+ entry = req.resolve("drizzle-orm");
82
+ }
83
+ let dir = dirname(entry);
84
+ let pkgJsonPath = null;
85
+ while (dir !== dirname(dir)) {
86
+ const candidate = resolve(dir, "package.json");
87
+ if (existsSync(candidate)) {
88
+ try {
89
+ const pkg2 = JSON.parse(readFileSync(candidate, "utf-8"));
90
+ if (pkg2.name === "drizzle-orm") {
91
+ pkgJsonPath = candidate;
92
+ break;
93
+ }
94
+ } catch {
95
+ }
96
+ }
97
+ dir = dirname(dir);
98
+ }
99
+ if (!pkgJsonPath) {
100
+ return {
101
+ installed: false,
102
+ isRC: false,
103
+ error: `[qarpeo] Could not locate drizzle-orm package.json.`
104
+ };
105
+ }
106
+ const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
107
+ const version = pkg.version || "";
108
+ const isOutdated = version.startsWith("0.");
109
+ if (isOutdated) {
110
+ return {
111
+ installed: true,
112
+ version,
113
+ isRC: false,
114
+ error: `[qarpeo] Outdated "drizzle-orm" detected in your project (v${version}).
115
+ qarpeo requires Drizzle ORM v1.0.0 RC (drizzle-orm@rc) or newer.
116
+ Please remove or upgrade your project's drizzle-orm dependency:
117
+ vp add drizzle-orm@rc`
118
+ };
119
+ }
120
+ return {
121
+ installed: true,
122
+ version,
123
+ isRC: true
124
+ };
125
+ } catch {
126
+ return {
127
+ installed: false,
128
+ isRC: false,
129
+ error: `[qarpeo] Drizzle ORM is enabled (db: { orm: 'drizzle' }), but "drizzle-orm" could not be resolved.
130
+ Please ensure qarpeo dependencies are installed.`
131
+ };
132
+ }
133
+ }
134
+ function getDatabaseIdentifiers(dirName, isPrimary = false) {
135
+ if (isPrimary || dirName === "d1") {
136
+ return {
137
+ schema: "d1Schema",
138
+ db: "d1Db",
139
+ zod: "d1Zod",
140
+ types: "D1Types",
141
+ isPrimary: true,
142
+ engine: "d1"
143
+ };
144
+ }
145
+ if (dirName.startsWith("d1-")) {
146
+ const raw = dirName.slice(3);
147
+ const pascal2 = toPascalCase$1(raw);
148
+ return {
149
+ schema: `d1${pascal2}Schema`,
150
+ db: `d1${pascal2}Db`,
151
+ zod: `d1${pascal2}Zod`,
152
+ types: `D1${pascal2}Types`,
153
+ isPrimary: false,
154
+ engine: "d1"
155
+ };
156
+ }
157
+ if (dirName === "pg" || dirName === "postgres") {
158
+ return {
159
+ schema: "pgSchema",
160
+ db: "pgDb",
161
+ zod: "pgZod",
162
+ types: "PgTypes",
163
+ isPrimary: false,
164
+ engine: "pg"
165
+ };
166
+ }
167
+ if (dirName.startsWith("pg-")) {
168
+ const raw = dirName.slice(3);
169
+ const pascal2 = toPascalCase$1(raw);
170
+ return {
171
+ schema: `pg${pascal2}Schema`,
172
+ db: `pg${pascal2}Db`,
173
+ zod: `pg${pascal2}Zod`,
174
+ types: `Pg${pascal2}Types`,
175
+ isPrimary: false,
176
+ engine: "pg"
177
+ };
178
+ }
179
+ if (dirName.startsWith("postgres-")) {
180
+ const raw = dirName.slice(9);
181
+ const pascal2 = toPascalCase$1(raw);
182
+ return {
183
+ schema: `pg${pascal2}Schema`,
184
+ db: `pg${pascal2}Db`,
185
+ zod: `pg${pascal2}Zod`,
186
+ types: `Pg${pascal2}Types`,
187
+ isPrimary: false,
188
+ engine: "pg"
189
+ };
190
+ }
191
+ if (dirName === "ms" || dirName === "mysql") {
192
+ return {
193
+ schema: "msSchema",
194
+ db: "msDb",
195
+ zod: "msZod",
196
+ types: "MsTypes",
197
+ isPrimary: false,
198
+ engine: "ms"
199
+ };
200
+ }
201
+ if (dirName.startsWith("ms-")) {
202
+ const raw = dirName.slice(3);
203
+ const pascal2 = toPascalCase$1(raw);
204
+ return {
205
+ schema: `ms${pascal2}Schema`,
206
+ db: `ms${pascal2}Db`,
207
+ zod: `ms${pascal2}Zod`,
208
+ types: `Ms${pascal2}Types`,
209
+ isPrimary: false,
210
+ engine: "ms"
211
+ };
212
+ }
213
+ if (dirName.startsWith("mysql-")) {
214
+ const raw = dirName.slice(6);
215
+ const pascal2 = toPascalCase$1(raw);
216
+ return {
217
+ schema: `ms${pascal2}Schema`,
218
+ db: `ms${pascal2}Db`,
219
+ zod: `ms${pascal2}Zod`,
220
+ types: `Ms${pascal2}Types`,
221
+ isPrimary: false,
222
+ engine: "ms"
223
+ };
224
+ }
225
+ const pascal = toPascalCase$1(dirName);
226
+ const camel = toCamelCase$1(dirName);
227
+ return {
228
+ schema: `${camel}Schema`,
229
+ db: `${camel}Db`,
230
+ zod: `${camel}Zod`,
231
+ types: `${pascal}Types`,
232
+ isPrimary: false,
233
+ engine: "other"
234
+ };
235
+ }
236
+ function hasDatabaseSchema(dirPath) {
237
+ if (!existsSync(dirPath)) return false;
238
+ try {
239
+ const stat = statSync(dirPath);
240
+ if (!stat.isDirectory()) return false;
241
+ if (existsSync(resolve(dirPath, "schema.ts")) || existsSync(resolve(dirPath, "schema.js"))) return true;
242
+ if (existsSync(resolve(dirPath, "index.ts")) || existsSync(resolve(dirPath, "index.js"))) return true;
243
+ const schemaDir = resolve(dirPath, "schema");
244
+ if (existsSync(schemaDir) && statSync(schemaDir).isDirectory()) {
245
+ const files = readdirSync(schemaDir);
246
+ if (files.some((f) => (f.endsWith(".ts") || f.endsWith(".js")) && !f.endsWith(".d.ts"))) {
247
+ return true;
248
+ }
249
+ }
250
+ } catch {
251
+ }
252
+ return false;
253
+ }
254
+ function discoverDatabases(layers, options) {
255
+ const dbs = /* @__PURE__ */ new Map();
256
+ const dbOpts = typeof options?.db === "object" ? options.db : {};
257
+ for (const layer of layers) {
258
+ const baseDirs = /* @__PURE__ */ new Set();
259
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
260
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
261
+ if (layer.cwd) baseDirs.add(layer.cwd);
262
+ for (const baseDir of baseDirs) {
263
+ const rootDbDir = resolve(baseDir, "db");
264
+ const collectSchemaFromDir = (dirPath, targetSet) => {
265
+ if (!existsSync(dirPath) || !statSync(dirPath).isDirectory()) return;
266
+ const schemaFile = resolve(dirPath, "schema.ts");
267
+ if (existsSync(schemaFile)) targetSet.add(schemaFile);
268
+ const indexFile = resolve(dirPath, "index.ts");
269
+ if (existsSync(indexFile)) targetSet.add(indexFile);
270
+ const schemaDir = resolve(dirPath, "schema");
271
+ if (existsSync(schemaDir) && statSync(schemaDir).isDirectory()) {
272
+ const idx = resolve(schemaDir, "index.ts");
273
+ if (existsSync(idx)) {
274
+ targetSet.add(idx);
275
+ } else {
276
+ for (const file of readdirSync(schemaDir)) {
277
+ if ((file.endsWith(".ts") || file.endsWith(".js")) && !file.endsWith(".d.ts")) {
278
+ targetSet.add(resolve(schemaDir, file));
279
+ }
280
+ }
281
+ }
282
+ }
283
+ };
284
+ const primarySchemaFiles = /* @__PURE__ */ new Set();
285
+ const rootD1Dir = resolve(baseDir, "db/d1");
286
+ if (existsSync(rootD1Dir)) {
287
+ collectSchemaFromDir(rootD1Dir, primarySchemaFiles);
288
+ }
289
+ const rootDbSchemaFile = resolve(baseDir, "db/schema.ts");
290
+ if (existsSync(rootDbSchemaFile)) primarySchemaFiles.add(rootDbSchemaFile);
291
+ const rootDbSchemaDir = resolve(baseDir, "db/schema");
292
+ if (existsSync(rootDbSchemaDir) && statSync(rootDbSchemaDir).isDirectory()) {
293
+ const indexFile = resolve(rootDbSchemaDir, "index.ts");
294
+ if (existsSync(indexFile)) {
295
+ primarySchemaFiles.add(indexFile);
296
+ } else {
297
+ for (const file of readdirSync(rootDbSchemaDir)) {
298
+ if ((file.endsWith(".ts") || file.endsWith(".js")) && !file.endsWith(".d.ts")) {
299
+ primarySchemaFiles.add(resolve(rootDbSchemaDir, file));
300
+ }
301
+ }
302
+ }
303
+ }
304
+ if (primarySchemaFiles.size > 0 || !dbs.has("default")) {
305
+ const primaryBinding = resolveBindingName("db", dbOpts.binding);
306
+ const primaryId = dbOpts.databaseId || process.env.QARPEO_DB_ID || process.env.DATABASE_ID || process.env.DB_ID || `${primaryBinding}_LOCAL_DEV`;
307
+ const rootD1Migrations = resolve(baseDir, "db/d1/migrations");
308
+ const primaryMigrationsDir = existsSync(rootD1Migrations) ? rootD1Migrations : existsSync(rootD1Dir) ? rootD1Migrations : resolve(baseDir, "db/migrations");
309
+ const primaryDir = existsSync(rootD1Dir) ? rootD1Dir : rootDbDir;
310
+ dbs.set("default", {
311
+ name: "default",
312
+ dirName: "d1",
313
+ isPrimary: true,
314
+ binding: primaryBinding,
315
+ databaseName: dbOpts.databaseName || primaryBinding,
316
+ databaseId: primaryId,
317
+ dir: primaryDir,
318
+ migrationsDir: primaryMigrationsDir,
319
+ schemaFiles: Array.from(primarySchemaFiles),
320
+ dialect: "sqlite",
321
+ identifiers: getDatabaseIdentifiers("d1", true)
322
+ });
323
+ }
324
+ if (existsSync(rootDbDir) && statSync(rootDbDir).isDirectory()) {
325
+ try {
326
+ const entries = readdirSync(rootDbDir, { withFileTypes: true });
327
+ for (const entry of entries) {
328
+ if (!entry.isDirectory()) continue;
329
+ if (entry.name === "d1" || entry.name === "migrations" || entry.name === "schema" || entry.name === "data") {
330
+ continue;
331
+ }
332
+ const dirPath = resolve(rootDbDir, entry.name);
333
+ if (!hasDatabaseSchema(dirPath)) continue;
334
+ if (entry.name.startsWith("d1-")) {
335
+ const name = entry.name.slice(3);
336
+ const binding = process.env[`D1_${name.toUpperCase()}_BINDING`] || `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_DB`;
337
+ const secId = process.env[`D1_${name.toUpperCase()}_ID`] || process.env[`DATABASE_${name.toUpperCase()}_ID`] || `${binding}_LOCAL_DEV`;
338
+ const migrationsDir = resolve(dirPath, "migrations");
339
+ const secSchemaFiles = /* @__PURE__ */ new Set();
340
+ collectSchemaFromDir(dirPath, secSchemaFiles);
341
+ dbs.set(name.toLowerCase(), {
342
+ name,
343
+ dirName: entry.name,
344
+ isPrimary: false,
345
+ binding,
346
+ databaseId: secId,
347
+ dir: dirPath,
348
+ migrationsDir,
349
+ schemaFiles: Array.from(secSchemaFiles),
350
+ dialect: "sqlite",
351
+ identifiers: getDatabaseIdentifiers(entry.name, false)
352
+ });
353
+ } else if (entry.name === "pg" || entry.name.startsWith("pg-") || entry.name === "postgres" || entry.name.startsWith("postgres-")) {
354
+ const name = entry.name === "pg" || entry.name === "postgres" ? "postgres" : entry.name.startsWith("pg-") ? entry.name.slice(3) : entry.name.slice(9);
355
+ const binding = process.env[`HYPERDRIVE_${name.toUpperCase()}_BINDING`] || `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_HD`;
356
+ const secId = process.env[`HYPERDRIVE_${name.toUpperCase()}_ID`] || `${binding}_LOCAL_DEV`;
357
+ const migrationsDir = resolve(dirPath, "migrations");
358
+ const secSchemaFiles = /* @__PURE__ */ new Set();
359
+ collectSchemaFromDir(dirPath, secSchemaFiles);
360
+ dbs.set(name.toLowerCase(), {
361
+ name,
362
+ dirName: entry.name,
363
+ isPrimary: false,
364
+ binding,
365
+ databaseId: secId,
366
+ dir: dirPath,
367
+ migrationsDir,
368
+ schemaFiles: Array.from(secSchemaFiles),
369
+ dialect: "postgres",
370
+ identifiers: getDatabaseIdentifiers(entry.name, false)
371
+ });
372
+ } else if (entry.name === "ms" || entry.name.startsWith("ms-") || entry.name === "mysql" || entry.name.startsWith("mysql-")) {
373
+ const name = entry.name === "ms" || entry.name === "mysql" ? "mysql" : entry.name.startsWith("ms-") ? entry.name.slice(3) : entry.name.slice(6);
374
+ const binding = process.env[`MYSQL_${name.toUpperCase()}_BINDING`] || process.env[`HYPERDRIVE_${name.toUpperCase()}_BINDING`] || `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_HD`;
375
+ const secId = process.env[`MYSQL_${name.toUpperCase()}_ID`] || process.env[`HYPERDRIVE_${name.toUpperCase()}_ID`] || `${binding}_LOCAL_DEV`;
376
+ const migrationsDir = resolve(dirPath, "migrations");
377
+ const secSchemaFiles = /* @__PURE__ */ new Set();
378
+ collectSchemaFromDir(dirPath, secSchemaFiles);
379
+ dbs.set(name.toLowerCase(), {
380
+ name,
381
+ dirName: entry.name,
382
+ isPrimary: false,
383
+ binding,
384
+ databaseId: secId,
385
+ dir: dirPath,
386
+ migrationsDir,
387
+ schemaFiles: Array.from(secSchemaFiles),
388
+ dialect: "mysql",
389
+ identifiers: getDatabaseIdentifiers(entry.name, false)
390
+ });
391
+ }
392
+ }
393
+ } catch {
394
+ }
395
+ }
396
+ }
397
+ }
398
+ const configuredDbs = dbOpts.databases;
399
+ if (Array.isArray(configuredDbs)) {
400
+ for (const name of configuredDbs) {
401
+ if (!name || typeof name !== "string") continue;
402
+ const key = name.toLowerCase();
403
+ if (!dbs.has(key)) {
404
+ const binding = `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_DB`;
405
+ const secId = process.env[`D1_${name.toUpperCase()}_ID`] || process.env[`DATABASE_${name.toUpperCase()}_ID`] || `${binding}_LOCAL_DEV`;
406
+ const baseDir = layers[0]?.cwd || process.cwd();
407
+ const targetDir = resolve(baseDir, `db/d1-${name}`);
408
+ const migDir = resolve(baseDir, `db/migrations/${name}`);
409
+ dbs.set(key, {
410
+ name,
411
+ dirName: `d1-${name}`,
412
+ isPrimary: false,
413
+ binding,
414
+ databaseId: secId,
415
+ dir: targetDir,
416
+ migrationsDir: migDir,
417
+ schemaFiles: [],
418
+ dialect: "sqlite",
419
+ identifiers: getDatabaseIdentifiers(`d1-${name}`, false)
420
+ });
421
+ }
422
+ }
423
+ } else if (configuredDbs && typeof configuredDbs === "object") {
424
+ for (const [name, cfg] of Object.entries(configuredDbs)) {
425
+ const conf = cfg;
426
+ const key = name.toLowerCase();
427
+ const isHyperdrive = Boolean(conf.hyperdrive);
428
+ const binding = conf.binding || (isHyperdrive ? `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_HD` : `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_DB`);
429
+ const baseDir = layers[0]?.cwd || process.cwd();
430
+ const existing = dbs.get(key);
431
+ if (existing) {
432
+ if (conf.binding) existing.binding = conf.binding;
433
+ if (conf.databaseName) existing.databaseName = conf.databaseName;
434
+ if (conf.databaseId) existing.databaseId = conf.databaseId;
435
+ if (conf.migrationsDir) existing.migrationsDir = resolve(baseDir, conf.migrationsDir);
436
+ } else {
437
+ const isMysql = conf.driver === "mysql" || conf.dialect === "mysql" || name.startsWith("ms") || name.startsWith("mysql");
438
+ const dirName = isMysql ? name === "mysql" || name === "ms" ? "mysql" : `ms-${name}` : isHyperdrive ? name === "postgres" ? "postgres" : `postgres-${name}` : `d1-${name}`;
439
+ const targetDir = resolve(baseDir, `db/${dirName}`);
440
+ const dialect = isMysql ? "mysql" : isHyperdrive ? "postgres" : "sqlite";
441
+ dbs.set(key, {
442
+ name,
443
+ dirName,
444
+ isPrimary: false,
445
+ binding,
446
+ databaseName: conf.databaseName || binding,
447
+ databaseId: conf.databaseId || `${binding}_LOCAL_DEV`,
448
+ dir: targetDir,
449
+ migrationsDir: resolve(baseDir, conf.migrationsDir || `db/migrations/${name}`),
450
+ schemaFiles: [],
451
+ dialect,
452
+ identifiers: getDatabaseIdentifiers(dirName, false)
453
+ });
454
+ }
455
+ }
456
+ }
457
+ for (const [envKey, envVal] of Object.entries(process.env)) {
458
+ if (envKey.startsWith("D1_") && envKey.endsWith("_ID") && envKey !== "D1_DATABASE_ID") {
459
+ const name = envKey.slice(3, -3);
460
+ const binding = `${name}_DB`;
461
+ const key = name.toLowerCase();
462
+ const primaryBinding = dbs.get("default")?.binding || "DB";
463
+ const alreadyAdded = Array.from(dbs.values()).some((d) => d.binding === binding) || primaryBinding === binding;
464
+ if (!alreadyAdded && envVal) {
465
+ const baseDir = layers[0]?.cwd || process.cwd();
466
+ const dirName = `d1-${name.toLowerCase()}`;
467
+ const targetDir = resolve(baseDir, `db/${dirName}`);
468
+ dbs.set(key, {
469
+ name: name.toLowerCase(),
470
+ dirName,
471
+ isPrimary: false,
472
+ binding,
473
+ databaseId: envVal,
474
+ dir: targetDir,
475
+ migrationsDir: resolve(baseDir, `db/migrations/${name.toLowerCase()}`),
476
+ schemaFiles: [],
477
+ dialect: "sqlite",
478
+ identifiers: getDatabaseIdentifiers(dirName, false)
479
+ });
480
+ }
481
+ }
482
+ }
483
+ return Array.from(dbs.values());
484
+ }
485
+ function resolveDatabaseTarget(layers, targetDbName, options) {
486
+ const allDbs = discoverDatabases(layers, options);
487
+ if (!targetDbName || ["default", "primary", "d1"].includes(targetDbName.toLowerCase())) {
488
+ const primary = allDbs.find((d) => d.isPrimary);
489
+ if (primary) return primary;
490
+ const baseDir = layers[0]?.cwd || process.cwd();
491
+ const d1Dir = resolve(baseDir, "db/d1");
492
+ const d1Mig = resolve(baseDir, "db/d1/migrations");
493
+ return {
494
+ name: "default",
495
+ dirName: "d1",
496
+ isPrimary: true,
497
+ binding: "DB",
498
+ databaseId: "DB_LOCAL_DEV",
499
+ dir: d1Dir,
500
+ migrationsDir: d1Mig,
501
+ schemaFiles: [],
502
+ dialect: "sqlite",
503
+ identifiers: getDatabaseIdentifiers("d1", true)
504
+ };
505
+ }
506
+ const query = targetDbName.trim();
507
+ const lower = query.toLowerCase();
508
+ const upper = query.toUpperCase();
509
+ const match = allDbs.find(
510
+ (d) => d.name.toLowerCase() === lower || d.dirName.toLowerCase() === lower || d.binding.toUpperCase() === upper || d.binding.toUpperCase() === `${upper}_DB` || d.binding.toUpperCase() === `${upper}_HD` || d.name.toLowerCase() === lower.replace(/^d1-/, "") || d.name.toLowerCase() === lower.replace(/^postgres-/, "")
511
+ );
512
+ if (match) {
513
+ return match;
514
+ }
515
+ const available = allDbs.map((d) => ` - "${d.name}" (binding: ${d.binding}, dir: server/db/${d.dirName})`).join("\n");
516
+ throw new Error(
517
+ `Database target "${targetDbName}" was not found.
518
+ Available databases:
519
+ ${available || " (none discovered)"}`
520
+ );
521
+ }
522
+ function findSchemaFiles(layers, targetDb) {
523
+ if (targetDb) {
524
+ const target = resolveDatabaseTarget(layers, targetDb);
525
+ return target.schemaFiles;
526
+ }
527
+ const allDbs = discoverDatabases(layers);
528
+ const files = /* @__PURE__ */ new Set();
529
+ for (const db of allDbs) {
530
+ for (const f of db.schemaFiles) {
531
+ files.add(f);
532
+ }
533
+ }
534
+ return Array.from(files);
535
+ }
536
+
537
+ function spawnBinSync(bin, args, options = {}) {
538
+ const isWindows = process.platform === "win32";
539
+ const env = {
540
+ ...process.env,
541
+ ...options.env,
542
+ WRANGLER_HIDE_BANNER: "true"
543
+ };
544
+ if (isWindows && (bin.endsWith(".cmd") || bin.endsWith(".bat"))) {
545
+ const cmd = process.env.ComSpec || "cmd.exe";
546
+ return spawnSync(cmd, ["/d", "/s", "/c", bin, ...args], {
547
+ ...options,
548
+ env,
549
+ shell: false
550
+ });
551
+ }
552
+ return spawnSync(bin, args, { ...options, env, shell: false });
553
+ }
554
+ function isPackageInstalled(packageName, cwd = process.cwd()) {
555
+ const localDir = resolve(cwd, "node_modules", packageName);
556
+ const rootDir = resolve(cwd, "../node_modules", packageName);
557
+ if (existsSync(localDir) || existsSync(rootDir)) {
558
+ return true;
559
+ }
560
+ try {
561
+ const req = createRequire(resolve(cwd, "package.json"));
562
+ req.resolve(packageName);
563
+ return true;
564
+ } catch {
565
+ try {
566
+ const selfReq = createRequire(import.meta.url);
567
+ selfReq.resolve(packageName);
568
+ return true;
569
+ } catch {
570
+ return false;
571
+ }
572
+ }
573
+ }
574
+ function resolveBinaryPath(binName, cwd = process.cwd()) {
575
+ const isWindows = process.platform === "win32";
576
+ const actualBin = isWindows ? `${binName}.cmd` : binName;
577
+ const localBin = resolve(cwd, "node_modules/.bin", actualBin);
578
+ if (existsSync(localBin)) return localBin;
579
+ const rootBin = resolve(cwd, "../node_modules/.bin", actualBin);
580
+ if (existsSync(rootBin)) return rootBin;
581
+ try {
582
+ let currentDir = dirname(fileURLToPath(import.meta.url));
583
+ while (currentDir !== dirname(currentDir)) {
584
+ const binCandidate = resolve(currentDir, "node_modules/.bin", actualBin);
585
+ if (existsSync(binCandidate)) {
586
+ return binCandidate;
587
+ }
588
+ currentDir = dirname(currentDir);
589
+ }
590
+ } catch {
591
+ }
592
+ return null;
593
+ }
594
+ async function confirmInstall(packageName, purpose) {
595
+ if (!stdin.isTTY) {
596
+ return false;
597
+ }
598
+ const rl = readline.createInterface({ input: stdin, output: stdout });
599
+ try {
600
+ const answer = await rl.question(
601
+ `
602
+ \u{1F4E6} [qarpeo] "${packageName}" is required for ${purpose}.
603
+ Would you like to install it now? (Y/n): `
604
+ );
605
+ return answer.trim().toLowerCase() !== "n";
606
+ } finally {
607
+ rl.close();
608
+ }
609
+ }
610
+ async function ensurePackage(packageName, options = {}) {
611
+ const cwd = options?.cwd || process.cwd();
612
+ const purpose = options?.purpose || "this operation";
613
+ if (isPackageInstalled(packageName, cwd)) {
614
+ return true;
615
+ }
616
+ const confirmed = await confirmInstall(packageName, purpose);
617
+ if (!confirmed) {
618
+ console.error(
619
+ `
620
+ \u274C [qarpeo] Missing dependency: "${packageName}". Please install it manually:
621
+ vp add ${options.dev ? "-D " : ""}${packageName}
622
+ `
623
+ );
624
+ return false;
625
+ }
626
+ console.log(`
627
+ \u26A1 [qarpeo] Installing ${packageName}...`);
628
+ try {
629
+ const { addDependency } = await import('nypm');
630
+ await addDependency(packageName, {
631
+ cwd,
632
+ dev: options.dev ?? true,
633
+ silent: false
634
+ });
635
+ console.log(`\u2705 [qarpeo] Successfully installed ${packageName}!
636
+ `);
637
+ return true;
638
+ } catch (err) {
639
+ console.error(`\u274C [qarpeo] Failed to install ${packageName}:`, err?.message || err);
640
+ return false;
641
+ }
642
+ }
643
+
644
+ function findLocalD1Database(cwd) {
645
+ const possibleDirs = [
646
+ resolve(cwd, ".wrangler/state/v3/d1/miniflare-D1DatabaseObject"),
647
+ resolve(cwd, ".data/db")
648
+ ];
649
+ for (const dir of possibleDirs) {
650
+ if (existsSync(dir)) {
651
+ const files = readdirSync(dir).filter((f) => f.endsWith(".sqlite") || f.endsWith(".db")).filter((f) => !f.endsWith("-journal") && !f.endsWith("-wal") && !f.endsWith("-shm"));
652
+ if (files.length === 1) {
653
+ return resolve(dir, files[0]);
654
+ }
655
+ if (files.length > 1) {
656
+ const sorted = files.map((f) => ({ path: resolve(dir, f), mtime: statSync(resolve(dir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
657
+ return sorted[0].path;
658
+ }
659
+ }
660
+ }
661
+ return null;
662
+ }
663
+ async function getJiti(cwd) {
664
+ const req = createRequire(import.meta.url);
665
+ const sharedDir = resolve(cwd, "shared");
666
+ const dbDir = resolve(cwd, "db");
667
+ const alias = {
668
+ "#shared": sharedDir,
669
+ "#shared/": `${sharedDir}/`,
670
+ "~~": cwd,
671
+ "~~/": `${cwd}/`,
672
+ "~": cwd,
673
+ "~/": `${cwd}/`,
674
+ "#db": dbDir,
675
+ "#db/": `${dbDir}/`
676
+ };
677
+ try {
678
+ const jitiEntry = req.resolve("jiti");
679
+ const { createJiti } = await import(jitiEntry);
680
+ return createJiti(cwd, { interopDefault: true, alias });
681
+ } catch {
682
+ const jitiMod = await import('jiti');
683
+ return (jitiMod.createJiti || jitiMod.default || jitiMod)(cwd, { interopDefault: true, alias });
684
+ }
685
+ }
686
+ async function getLocalDatabaseContext(cwd, nuxtConfig, targetDb) {
687
+ const sqlitePath = findLocalD1Database(cwd);
688
+ if (!sqlitePath) {
689
+ throw new Error(
690
+ `No local D1 database found in .wrangler/state/v3/d1.
691
+ Please apply migrations first: qp db:migrate`
692
+ );
693
+ }
694
+ const qarpeoOpts = nuxtConfig?.qarpeo || {};
695
+ const layers = nuxtConfig._layers || [{ cwd, config: nuxtConfig }];
696
+ const target = resolveDatabaseTarget(layers, targetDb, qarpeoOpts);
697
+ const schemaFiles = target.schemaFiles;
698
+ if (schemaFiles.length === 0) {
699
+ const hint = target.isPrimary ? "db/d1/schema.ts" : `db/${target.dirName}/schema.ts`;
700
+ throw new Error(
701
+ `No database schema files found for "${target.name}". Create a schema file at ${hint} first.`
702
+ );
703
+ }
704
+ const jiti = await getJiti(cwd);
705
+ const schema = {};
706
+ for (const file of schemaFiles) {
707
+ try {
708
+ const mod = await jiti.import(file);
709
+ Object.assign(schema, mod);
710
+ } catch (err) {
711
+ console.warn(`[qarpeo] Warning: Failed to import schema file ${file}: ${err?.message || err}`);
712
+ }
713
+ }
714
+ const db = drizzle(sqlitePath);
715
+ let customSeedPath = null;
716
+ const seedCandidates = target.isPrimary ? [
717
+ resolve(target.dir, "seed.ts"),
718
+ resolve(target.dir, "seed.js"),
719
+ resolve(cwd, "db/seed.ts"),
720
+ resolve(cwd, "db/seed.js")
721
+ ] : [
722
+ resolve(target.dir, "seed.ts"),
723
+ resolve(target.dir, "seed.js"),
724
+ resolve(cwd, `db/seed-${target.name}.ts`),
725
+ resolve(cwd, `db/seed-${target.name}.js`)
726
+ ];
727
+ for (const candidate of seedCandidates) {
728
+ if (existsSync(candidate)) {
729
+ customSeedPath = candidate;
730
+ break;
731
+ }
732
+ }
733
+ return {
734
+ sqlitePath,
735
+ schema,
736
+ db,
737
+ customSeedPath
738
+ };
739
+ }
740
+ function applyD1Migrations(cwd, options = {}) {
741
+ const isWindows = process.platform === "win32";
742
+ let execPath = resolveBinaryPath("wrangler", cwd);
743
+ if (!execPath) {
744
+ execPath = isWindows ? "wrangler.cmd" : "wrangler";
745
+ }
746
+ const rootWranglerPath = resolve(cwd, "wrangler.json");
747
+ const wranglerConfigPath = options.wranglerConfigPath || (existsSync(rootWranglerPath) ? rootWranglerPath : resolve(cwd, ".nuxt/wrangler.json"));
748
+ const dbs = discoverDatabases([{ cwd }], {});
749
+ const d1Dbs = dbs.filter((d) => d.dialect === "sqlite");
750
+ const hasSql = (dir) => {
751
+ if (!dir || !existsSync(dir)) return false;
752
+ try {
753
+ const entries = readdirSync(dir, { withFileTypes: true });
754
+ return entries.some(
755
+ (e) => e.isFile() && e.name.endsWith(".sql") || e.isDirectory() && existsSync(resolve(dir, e.name, "migration.sql"))
756
+ );
757
+ } catch {
758
+ return false;
759
+ }
760
+ };
761
+ const targets = (options.dbName ? d1Dbs.filter((d) => d.binding === options.dbName) : d1Dbs).filter((d) => hasSql(d.migrationsDir) || d.isPrimary && hasSql(resolve(cwd, "db/migrations")));
762
+ if (targets.length === 0) {
763
+ return true;
764
+ }
765
+ let allSuccess = true;
766
+ for (const target of targets) {
767
+ const dbName = target.binding;
768
+ const wranglerArgs = ["d1", "migrations", "apply", dbName];
769
+ if (existsSync(wranglerConfigPath)) {
770
+ wranglerArgs.push("-c", wranglerConfigPath);
771
+ }
772
+ if (options.remote) {
773
+ wranglerArgs.push("--remote");
774
+ } else {
775
+ wranglerArgs.push("--local", "--persist-to", resolve(cwd, ".wrangler/state"));
776
+ }
777
+ const targetLabel = options.remote ? "remote Cloudflare D1" : "local Cloudflare D1";
778
+ const actionLabel = options.label || "Auto-checking";
779
+ console.log(`\u26A1 [qarpeo] ${actionLabel}: applying ${targetLabel} migrations for ${dbName}...`);
780
+ try {
781
+ const result = spawnSync(execPath, wranglerArgs, {
782
+ cwd,
783
+ stdio: "inherit",
784
+ shell: isWindows
785
+ });
786
+ if (result.status !== 0) {
787
+ allSuccess = false;
788
+ }
789
+ } catch (err) {
790
+ console.warn(`\u26A0\uFE0F [qarpeo] Migration failed for ${dbName}: ${err?.message || err}`);
791
+ allSuccess = false;
792
+ }
793
+ }
794
+ return allSuccess;
795
+ }
796
+
797
+ const localDb = {
798
+ __proto__: null,
799
+ applyD1Migrations: applyD1Migrations,
800
+ findLocalD1Database: findLocalD1Database,
801
+ getJiti: getJiti,
802
+ getLocalDatabaseContext: getLocalDatabaseContext
803
+ };
804
+
805
+ function findJobFiles(layers, dirName = "server/jobs") {
806
+ const jobsMap = /* @__PURE__ */ new Map();
807
+ for (const layer of layers) {
808
+ const baseDirs = /* @__PURE__ */ new Set();
809
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
810
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
811
+ if (layer.cwd) baseDirs.add(layer.cwd);
812
+ for (const baseDir of baseDirs) {
813
+ const jobsDir = resolve(baseDir, dirName);
814
+ if (!existsSync(jobsDir)) continue;
815
+ try {
816
+ const entries = readdirSync(jobsDir);
817
+ for (const entry of entries) {
818
+ const fullPath = join(jobsDir, entry);
819
+ const stat = statSync(fullPath);
820
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
821
+ if (entry.endsWith(".d.ts")) continue;
822
+ const ext = extname(entry);
823
+ const name = basename(entry, ext);
824
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
825
+ jobsMap.set(name, { name, file: fullPath, importPath });
826
+ }
827
+ }
828
+ } catch {
829
+ }
830
+ }
831
+ }
832
+ return Array.from(jobsMap.values());
833
+ }
834
+
835
+ function findQueueFiles(layers) {
836
+ const queueFiles = /* @__PURE__ */ new Set();
837
+ for (const layer of layers) {
838
+ const baseDirs = /* @__PURE__ */ new Set();
839
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
840
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
841
+ if (layer.cwd) baseDirs.add(layer.cwd);
842
+ for (const baseDir of baseDirs) {
843
+ const queueFile = resolve(baseDir, "server/queue.ts");
844
+ if (existsSync(queueFile)) {
845
+ queueFiles.add(queueFile);
846
+ }
847
+ const queueIndexFile = resolve(baseDir, "server/queue/index.ts");
848
+ if (existsSync(queueIndexFile)) {
849
+ queueFiles.add(queueIndexFile);
850
+ }
851
+ const queuesDir = resolve(baseDir, "server/queues");
852
+ if (existsSync(queuesDir)) {
853
+ try {
854
+ const files = readdirSync(queuesDir);
855
+ for (const file of files) {
856
+ if ((file.endsWith(".ts") || file.endsWith(".js") || file.endsWith(".mjs")) && !file.endsWith(".d.ts")) {
857
+ queueFiles.add(resolve(queuesDir, file));
858
+ }
859
+ }
860
+ } catch {
861
+ }
862
+ }
863
+ }
864
+ }
865
+ return Array.from(queueFiles);
866
+ }
867
+
868
+ function findScheduledTasks(layers, dirNames = ["server/tasks", "server/cron"]) {
869
+ const tasksMap = /* @__PURE__ */ new Map();
870
+ for (const layer of layers) {
871
+ const baseDirs = /* @__PURE__ */ new Set();
872
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
873
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
874
+ if (layer.cwd) baseDirs.add(layer.cwd);
875
+ for (const baseDir of baseDirs) {
876
+ for (const dirName of dirNames) {
877
+ const tasksDir = resolve(baseDir, dirName);
878
+ if (!existsSync(tasksDir)) continue;
879
+ try {
880
+ scanDirectory(tasksDir, tasksDir, tasksMap);
881
+ } catch {
882
+ }
883
+ }
884
+ }
885
+ }
886
+ return Array.from(tasksMap.values());
887
+ }
888
+ function scanDirectory(currentDir, rootDir, map) {
889
+ const entries = readdirSync(currentDir);
890
+ for (const entry of entries) {
891
+ const fullPath = join(currentDir, entry);
892
+ const stat = statSync(fullPath);
893
+ if (stat.isDirectory()) {
894
+ scanDirectory(fullPath, rootDir, map);
895
+ continue;
896
+ }
897
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
898
+ if (entry.endsWith(".d.ts")) continue;
899
+ const relPath = fullPath.slice(rootDir.length + 1).replace(/\\/g, "/");
900
+ const ext = extname(relPath);
901
+ const taskName = relPath.slice(0, -ext.length).replace(/\//g, ":");
902
+ let cron;
903
+ let description;
904
+ try {
905
+ const content = readFileSync(fullPath, "utf8");
906
+ const cronMatch = content.match(/cron:\s*["']([^"']+)["']/);
907
+ if (cronMatch) {
908
+ cron = cronMatch[1];
909
+ }
910
+ const descMatch = content.match(/description:\s*["']([^"']+)["']/);
911
+ if (descMatch) {
912
+ description = descMatch[1];
913
+ }
914
+ } catch {
915
+ }
916
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
917
+ map.set(taskName, {
918
+ name: taskName,
919
+ file: fullPath,
920
+ importPath,
921
+ cron,
922
+ description
923
+ });
924
+ }
925
+ }
926
+ }
927
+
928
+ function findWorkflowFiles(layers, dirName = "server/workflows") {
929
+ const workflowsMap = /* @__PURE__ */ new Map();
930
+ for (const layer of layers) {
931
+ const baseDirs = /* @__PURE__ */ new Set();
932
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
933
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
934
+ if (layer.cwd) baseDirs.add(layer.cwd);
935
+ for (const baseDir of baseDirs) {
936
+ const workflowsDir = resolve(baseDir, dirName);
937
+ if (!existsSync(workflowsDir)) continue;
938
+ try {
939
+ const entries = readdirSync(workflowsDir);
940
+ for (const entry of entries) {
941
+ const fullPath = join(workflowsDir, entry);
942
+ const stat = statSync(fullPath);
943
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
944
+ if (entry.endsWith(".d.ts")) continue;
945
+ const ext = extname(entry);
946
+ const name = basename(entry, ext);
947
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
948
+ workflowsMap.set(name, { name, file: fullPath, importPath });
949
+ }
950
+ }
951
+ } catch {
952
+ }
953
+ }
954
+ }
955
+ return Array.from(workflowsMap.values());
956
+ }
957
+
958
+ function toPascalCase(str) {
959
+ return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^(\w)/, (_, c) => c.toUpperCase());
960
+ }
961
+ function toConstantCase(str) {
962
+ return str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[-\s]/g, "_").toUpperCase();
963
+ }
964
+ function findDurableObjectFiles(layers, customDir) {
965
+ const doMap = /* @__PURE__ */ new Map();
966
+ const candidateDirs = customDir ? [customDir] : ["server/do"];
967
+ for (const layer of layers) {
968
+ const baseDirs = /* @__PURE__ */ new Set();
969
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
970
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
971
+ if (layer.cwd) baseDirs.add(layer.cwd);
972
+ for (const baseDir of baseDirs) {
973
+ for (const relDir of candidateDirs) {
974
+ const fullDir = resolve(baseDir, relDir);
975
+ if (!existsSync(fullDir)) continue;
976
+ try {
977
+ const entries = readdirSync(fullDir);
978
+ for (const entry of entries) {
979
+ const fullPath = join(fullDir, entry);
980
+ const stat = statSync(fullPath);
981
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
982
+ if (entry.endsWith(".d.ts")) continue;
983
+ const ext = extname(entry);
984
+ const rawName = basename(entry, ext);
985
+ const name = rawName.replace(/\.do$/, "");
986
+ const pascal = toPascalCase(name);
987
+ const className = pascal.endsWith("DO") ? pascal : `${pascal}DO`;
988
+ const bindingName = toConstantCase(name);
989
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
990
+ doMap.set(name, {
991
+ name,
992
+ className,
993
+ bindingName,
994
+ file: fullPath,
995
+ importPath
996
+ });
997
+ }
998
+ }
999
+ } catch {
1000
+ }
1001
+ }
1002
+ }
1003
+ }
1004
+ return Array.from(doMap.values());
1005
+ }
1006
+
1007
+ function resolveProjectName(nuxt, options) {
1008
+ let rawName = "";
1009
+ if (options?.workerName) rawName = options.workerName;
1010
+ else if (options?.site?.name) rawName = options.site.name;
1011
+ else if (options?.name) rawName = options.name;
1012
+ else {
1013
+ const qarpeoConfig = nuxt.options.qarpeo || {};
1014
+ if (qarpeoConfig.workerName) rawName = qarpeoConfig.workerName;
1015
+ else if (qarpeoConfig.site?.name) rawName = qarpeoConfig.site.name;
1016
+ else if (qarpeoConfig.name) rawName = qarpeoConfig.name;
1017
+ else {
1018
+ const siteConfig = nuxt.options.site || {};
1019
+ if (siteConfig.name) rawName = siteConfig.name;
1020
+ else if (process.env.CLOUDFLARE_PROJECT_NAME) rawName = process.env.CLOUDFLARE_PROJECT_NAME;
1021
+ else if (process.env.WRANGLER_NAME) rawName = process.env.WRANGLER_NAME;
1022
+ else if (process.env.QARPEO_WORKER_NAME) rawName = process.env.QARPEO_WORKER_NAME;
1023
+ else if (process.env.WORKER_NAME) rawName = process.env.WORKER_NAME;
1024
+ else if (process.env.CF_WORKER_NAME) rawName = process.env.CF_WORKER_NAME;
1025
+ else {
1026
+ try {
1027
+ const pkgPath = resolve(nuxt.options.rootDir, "package.json");
1028
+ if (existsSync(pkgPath)) {
1029
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
1030
+ if (pkg.name) rawName = pkg.name;
1031
+ }
1032
+ } catch {
1033
+ }
1034
+ }
1035
+ }
1036
+ }
1037
+ const sanitized = (rawName || "").toLowerCase().replace(/^@/, "").replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "");
1038
+ return sanitized || "qarpeo-app";
1039
+ }
1040
+ async function createWranglerConfig(nuxt, options) {
1041
+ let rootConfig = {};
1042
+ for (const file of ["wrangler.jsonc", "wrangler.json"]) {
1043
+ const rootPath = join(nuxt.options.rootDir, file);
1044
+ if (existsSync(rootPath)) {
1045
+ try {
1046
+ const content = await readFile(rootPath, "utf8");
1047
+ const stripped = content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/,\s*([}\]])/g, "$1");
1048
+ rootConfig = JSON.parse(stripped);
1049
+ break;
1050
+ } catch {
1051
+ }
1052
+ }
1053
+ }
1054
+ const compatDate = typeof nuxt.options.compatibilityDate === "string" ? nuxt.options.compatibilityDate : nuxt.options.compatibilityDate?.default || "2025-02-01";
1055
+ const projectName = resolveProjectName(nuxt, options);
1056
+ const baseConfig = {
1057
+ $schema: "node_modules/wrangler/config-schema.json",
1058
+ name: projectName,
1059
+ compatibility_date: compatDate,
1060
+ compatibility_flags: ["nodejs_compat"],
1061
+ observability: { enabled: true }
1062
+ };
1063
+ const isRemote = Boolean(options.remote || process.env.QARPEO_CF_REMOTE);
1064
+ const accountId = process.env.CLOUDFLARE_ACCOUNT_ID || process.env.CF_ACCOUNT_ID;
1065
+ if (accountId) {
1066
+ baseConfig.account_id = accountId;
1067
+ }
1068
+ if (options.kv || options.cache || options.auth || options.realtime || options.payments || options.ratelimit || options.agents || options.multitenant) {
1069
+ const kvBinding = resolveBindingName("kv");
1070
+ const kvId = process.env.QARPEO_KV_ID || process.env.KV_ID || `${kvBinding}_LOCAL_DEV`;
1071
+ baseConfig.kv_namespaces = [
1072
+ {
1073
+ binding: kvBinding,
1074
+ id: kvId,
1075
+ ...isRemote ? { remote: true } : {}
1076
+ }
1077
+ ];
1078
+ }
1079
+ if (options.blob || options.r2 || options.cms || options.storage) {
1080
+ const blobBinding = resolveBindingName("blob");
1081
+ const bucketName = process.env.QARPEO_BLOB_BUCKET || process.env.BLOB_NAME || `${blobBinding.toLowerCase().replace(/[^a-z0-9-]/g, "-")}-local-dev`;
1082
+ baseConfig.r2_buckets = [
1083
+ {
1084
+ binding: blobBinding,
1085
+ bucket_name: bucketName,
1086
+ ...isRemote ? { remote: true } : {}
1087
+ }
1088
+ ];
1089
+ }
1090
+ const layers = nuxt.options._layers || [
1091
+ {
1092
+ cwd: nuxt.options.rootDir,
1093
+ config: nuxt.options
1094
+ }
1095
+ ];
1096
+ const allDbs = discoverDatabases(layers, options);
1097
+ const isDbActive = options.db !== false && Boolean(
1098
+ options.db || options.d1 || options.cms || options.auth || options.payments || options.comments || options.store || options.notifications || allDbs.some((d) => d.schemaFiles.length > 0)
1099
+ );
1100
+ if (isDbActive) {
1101
+ const buildDir = nuxt.options.buildDir || resolve(nuxt.options.rootDir, ".nuxt");
1102
+ const d1Databases = [];
1103
+ for (const db of allDbs) {
1104
+ if (db.dialect === "sqlite") {
1105
+ const relMigrationsDir = relative(buildDir, db.migrationsDir).replace(/\\/g, "/");
1106
+ d1Databases.push({
1107
+ binding: db.binding,
1108
+ database_name: db.databaseName || db.binding,
1109
+ database_id: db.databaseId,
1110
+ migrations_dir: relMigrationsDir,
1111
+ migrations_pattern: `${relMigrationsDir}/*/migration.sql`,
1112
+ ...isRemote ? { remote: true } : {}
1113
+ });
1114
+ } else if (db.dialect === "postgres" || db.dialect === "mysql") {
1115
+ baseConfig.hyperdrive = baseConfig.hyperdrive || [];
1116
+ if (!baseConfig.hyperdrive.some((h) => h.binding === db.binding)) {
1117
+ baseConfig.hyperdrive.push({
1118
+ binding: db.binding,
1119
+ id: db.databaseId
1120
+ });
1121
+ }
1122
+ }
1123
+ }
1124
+ if (d1Databases.length > 0) {
1125
+ baseConfig.d1_databases = d1Databases;
1126
+ }
1127
+ }
1128
+ if (options.cache) {
1129
+ const cacheConfig = typeof options.cache === "object" ? options.cache : {};
1130
+ const cacheBinding = cacheConfig.binding || resolveBindingName("cache");
1131
+ const cacheId = process.env.QARPEO_CACHE_ID || process.env.CACHE_ID || `${cacheBinding}_LOCAL_DEV`;
1132
+ baseConfig.kv_namespaces = baseConfig.kv_namespaces || [];
1133
+ baseConfig.kv_namespaces.push({
1134
+ binding: cacheBinding,
1135
+ id: cacheId,
1136
+ ...isRemote ? { remote: true } : {}
1137
+ });
1138
+ }
1139
+ if (options.ai || options.agents) {
1140
+ const hasToken = Boolean(
1141
+ process.env.CLOUDFLARE_API_TOKEN || process.env.CLOUDFLARE_ACCOUNT_ID || isRemote
1142
+ );
1143
+ if (hasToken || !nuxt.options.dev) {
1144
+ const aiBinding = resolveBindingName("ai");
1145
+ baseConfig.ai = {
1146
+ binding: aiBinding
1147
+ };
1148
+ }
1149
+ }
1150
+ if (options.vectorize || options.agents) {
1151
+ const vectorizeBinding = resolveBindingName("vectorize");
1152
+ const indexName = `${vectorizeBinding.toLowerCase().replace(/[^a-z0-9-]/g, "-")}-local-dev`;
1153
+ baseConfig.vectorize = [
1154
+ {
1155
+ binding: vectorizeBinding,
1156
+ index_name: indexName,
1157
+ ...isRemote ? { remote: true } : {}
1158
+ }
1159
+ ];
1160
+ }
1161
+ if (options.queue || options.jobs || options.payments) {
1162
+ const queueBinding = resolveBindingName("queue");
1163
+ const queueName = process.env.QARPEO_QUEUE_NAME || `${queueBinding.toLowerCase().replace(/[^a-z0-9-]/g, "-")}-local-dev`;
1164
+ baseConfig.queues = baseConfig.queues || {};
1165
+ baseConfig.queues.producers = [
1166
+ {
1167
+ binding: queueBinding,
1168
+ queue: queueName,
1169
+ ...isRemote ? { remote: true } : {}
1170
+ }
1171
+ ];
1172
+ const queueFiles = findQueueFiles(
1173
+ nuxt.options._layers || [{ cwd: nuxt.options.rootDir, config: nuxt.options }]
1174
+ );
1175
+ const jobFiles = options.jobs ? findJobFiles(
1176
+ nuxt.options._layers || [{ cwd: nuxt.options.rootDir, config: nuxt.options }],
1177
+ typeof options.jobs === "object" && options.jobs.dir ? options.jobs.dir : "server/jobs"
1178
+ ) : [];
1179
+ if (queueFiles.length > 0 || jobFiles.length > 0) {
1180
+ const jobsConfig = typeof options.jobs === "object" ? options.jobs : {};
1181
+ baseConfig.queues.consumers = [
1182
+ {
1183
+ queue: queueName,
1184
+ max_batch_size: jobsConfig.maxBatchSize ?? 10,
1185
+ max_batch_timeout: jobsConfig.maxBatchTimeout ?? 5
1186
+ }
1187
+ ];
1188
+ }
1189
+ }
1190
+ if (options.workflows) {
1191
+ const workflowsConfig = typeof options.workflows === "object" ? options.workflows : {};
1192
+ const wfFiles = findWorkflowFiles(
1193
+ nuxt.options._layers || [{ cwd: nuxt.options.rootDir, config: nuxt.options }],
1194
+ workflowsConfig.dir || "server/workflows"
1195
+ );
1196
+ if (wfFiles.length > 0) {
1197
+ baseConfig.workflows = wfFiles.map((wf) => {
1198
+ const bindingName = `WORKFLOW_${wf.name.toUpperCase()}`;
1199
+ const className = `${wf.name.charAt(0).toUpperCase()}${wf.name.slice(1)}Workflow`;
1200
+ return {
1201
+ name: wf.name,
1202
+ binding: bindingName,
1203
+ class_name: className
1204
+ };
1205
+ });
1206
+ }
1207
+ }
1208
+ if (options.analytics) {
1209
+ const analyticsOpts = typeof options.analytics === "object" ? options.analytics : void 0;
1210
+ const analyticsBinding = resolveBindingName("analytics", analyticsOpts?.binding);
1211
+ const datasetName = analyticsOpts?.dataset || process.env.QARPEO_ANALYTICS_DATASET || `${analyticsBinding.toLowerCase().replace(/[^a-z0-9-]/g, "-")}-local-dev`;
1212
+ baseConfig.analytics_engine_datasets = [
1213
+ {
1214
+ binding: analyticsBinding,
1215
+ dataset: datasetName
1216
+ }
1217
+ ];
1218
+ }
1219
+ if (options.ratelimit) {
1220
+ const rateLimitBinding = resolveBindingName("ratelimit", void 0, "RATE_LIMITER");
1221
+ const limit = typeof options.ratelimit === "object" ? options.ratelimit.limit ?? 100 : 100;
1222
+ const period = typeof options.ratelimit === "object" ? options.ratelimit.period ?? 60 : 60;
1223
+ const namespaceId = typeof options.ratelimit === "object" ? options.ratelimit.namespaceId ?? 1001 : 1001;
1224
+ baseConfig.ratelimits = [
1225
+ {
1226
+ name: rateLimitBinding,
1227
+ namespace_id: String(namespaceId),
1228
+ simple: {
1229
+ limit,
1230
+ period
1231
+ }
1232
+ }
1233
+ ];
1234
+ }
1235
+ if (options.hyperdrive) {
1236
+ const hyperdriveBinding = resolveBindingName("hyperdrive");
1237
+ const id = process.env.QARPEO_HYPERDRIVE_ID || `${hyperdriveBinding}_LOCAL_DEV`;
1238
+ const localConnectionString = (typeof options.hyperdrive === "object" ? options.hyperdrive.localConnectionString : void 0) || process.env.LOCAL_CONNECTION_STRING || process.env.QARPEO_HYPERDRIVE_LOCAL_URL;
1239
+ baseConfig.hyperdrive = [
1240
+ {
1241
+ binding: hyperdriveBinding,
1242
+ id,
1243
+ ...localConnectionString ? { localConnectionString } : nuxt.options.dev && !isRemote ? { localConnectionString: "postgresql://postgres:postgres@localhost:5432/postgres" } : {},
1244
+ ...isRemote ? { remote: true } : {}
1245
+ }
1246
+ ];
1247
+ }
1248
+ if (options.browser) {
1249
+ const browserBinding = resolveBindingName("browser");
1250
+ baseConfig.browser = {
1251
+ binding: browserBinding
1252
+ };
1253
+ }
1254
+ if (options.email || options.mail) {
1255
+ const emailBinding = resolveBindingName(
1256
+ "email",
1257
+ typeof options.email === "object" ? options.email.binding : void 0,
1258
+ "EMAIL"
1259
+ );
1260
+ baseConfig.send_email = [
1261
+ {
1262
+ name: emailBinding,
1263
+ ...isRemote ? { remote: true } : {}
1264
+ }
1265
+ ];
1266
+ }
1267
+ const isCronDisabled = options.cron === false;
1268
+ if (!isCronDisabled) {
1269
+ let crons = [];
1270
+ if (options.cron && typeof options.cron === "object") {
1271
+ crons = Object.keys(options.cron);
1272
+ }
1273
+ if (!crons.length) {
1274
+ const nitroScheduled = nuxt.options.nitro?.scheduledTasks;
1275
+ const nitroCrons = nitroScheduled ? Object.keys(nitroScheduled) : [];
1276
+ crons = nuxt.options.nitro?.cloudflare?.wrangler?.triggers?.crons || nitroCrons;
1277
+ }
1278
+ const discoveredTasks = findScheduledTasks(
1279
+ nuxt.options._layers || [{ cwd: nuxt.options.rootDir, config: nuxt.options }]
1280
+ );
1281
+ for (const task of discoveredTasks) {
1282
+ if (task.cron && !crons.includes(task.cron)) {
1283
+ crons.push(task.cron);
1284
+ }
1285
+ }
1286
+ const cmsScheduled = typeof options.cms === "object" && options.cms?.scheduledPublish;
1287
+ if (cmsScheduled && !crons.includes("*/5 * * * *")) {
1288
+ crons.push("*/5 * * * *");
1289
+ }
1290
+ if (crons.length > 0) {
1291
+ baseConfig.triggers = { crons };
1292
+ }
1293
+ }
1294
+ const discoveredDOs = findDurableObjectFiles(nuxt.options?._layers || []);
1295
+ if (options.do || options.realtime || options.agents || discoveredDOs.length > 0) {
1296
+ baseConfig.durable_objects = baseConfig.durable_objects || { bindings: [] };
1297
+ baseConfig.durable_objects.bindings = baseConfig.durable_objects.bindings || [];
1298
+ baseConfig.migrations = baseConfig.migrations || [];
1299
+ if (options.realtime || !options.agents && options.do) {
1300
+ const doBinding = resolveBindingName(
1301
+ "do",
1302
+ typeof options.realtime === "object" ? options.realtime.binding : void 0,
1303
+ "QARPEO_ROOM_DO"
1304
+ );
1305
+ baseConfig.durable_objects.bindings.push({
1306
+ name: doBinding,
1307
+ class_name: "QarpeoRoomDO"
1308
+ });
1309
+ baseConfig.migrations.push({
1310
+ tag: "v1-realtime-room",
1311
+ new_classes: ["QarpeoRoomDO"]
1312
+ });
1313
+ if (typeof options.realtime === "object") {
1314
+ if (options.realtime.historyLimit) {
1315
+ baseConfig.vars = baseConfig.vars || {};
1316
+ baseConfig.vars.REALTIME_HISTORY_LIMIT = String(options.realtime.historyLimit);
1317
+ }
1318
+ if (options.realtime.maxConnectionsPerRoom) {
1319
+ baseConfig.vars = baseConfig.vars || {};
1320
+ baseConfig.vars.MAX_CONNECTIONS_PER_ROOM = String(options.realtime.maxConnectionsPerRoom);
1321
+ }
1322
+ }
1323
+ if (process.env.REALTIME_HISTORY_LIMIT && !baseConfig.vars?.REALTIME_HISTORY_LIMIT) {
1324
+ baseConfig.vars = baseConfig.vars || {};
1325
+ baseConfig.vars.REALTIME_HISTORY_LIMIT = String(process.env.REALTIME_HISTORY_LIMIT);
1326
+ }
1327
+ if (process.env.MAX_CONNECTIONS_PER_ROOM && !baseConfig.vars?.MAX_CONNECTIONS_PER_ROOM) {
1328
+ baseConfig.vars = baseConfig.vars || {};
1329
+ baseConfig.vars.MAX_CONNECTIONS_PER_ROOM = String(process.env.MAX_CONNECTIONS_PER_ROOM);
1330
+ }
1331
+ }
1332
+ if (options.agents) {
1333
+ const agentsConfig = typeof options.agents === "object" ? options.agents : {};
1334
+ const agentBinding = agentsConfig.binding || "QARPEO_AGENT_DO";
1335
+ baseConfig.durable_objects.bindings.push({
1336
+ name: agentBinding,
1337
+ class_name: "QarpeoAgentDO"
1338
+ });
1339
+ baseConfig.migrations.push({
1340
+ tag: "v1-agent-do",
1341
+ new_sqlite_classes: ["QarpeoAgentDO"]
1342
+ });
1343
+ }
1344
+ for (const doFile of discoveredDOs) {
1345
+ baseConfig.durable_objects.bindings.push({
1346
+ name: doFile.bindingName,
1347
+ class_name: doFile.className
1348
+ });
1349
+ baseConfig.migrations.push({
1350
+ tag: `v1-${doFile.name.toLowerCase()}`,
1351
+ new_sqlite_classes: [doFile.className]
1352
+ });
1353
+ }
1354
+ }
1355
+ const merged = defu(rootConfig, baseConfig);
1356
+ if (Array.isArray(merged.kv_namespaces)) {
1357
+ const seen = /* @__PURE__ */ new Set();
1358
+ merged.kv_namespaces = merged.kv_namespaces.filter((item) => {
1359
+ if (!item?.binding || seen.has(item.binding)) return false;
1360
+ seen.add(item.binding);
1361
+ return true;
1362
+ });
1363
+ }
1364
+ if (Array.isArray(merged.r2_buckets)) {
1365
+ const seen = /* @__PURE__ */ new Set();
1366
+ merged.r2_buckets = merged.r2_buckets.filter((item) => {
1367
+ if (!item?.binding || seen.has(item.binding)) return false;
1368
+ seen.add(item.binding);
1369
+ return true;
1370
+ });
1371
+ }
1372
+ if (Array.isArray(merged.d1_databases)) {
1373
+ const seen = /* @__PURE__ */ new Set();
1374
+ merged.d1_databases = merged.d1_databases.filter((item) => {
1375
+ if (!item?.binding || seen.has(item.binding)) return false;
1376
+ seen.add(item.binding);
1377
+ return true;
1378
+ });
1379
+ }
1380
+ if (Array.isArray(merged.vectorize)) {
1381
+ const seen = /* @__PURE__ */ new Set();
1382
+ merged.vectorize = merged.vectorize.filter((item) => {
1383
+ if (!item?.binding || seen.has(item.binding)) return false;
1384
+ seen.add(item.binding);
1385
+ return true;
1386
+ });
1387
+ }
1388
+ if (Array.isArray(merged.workflows)) {
1389
+ const seen = /* @__PURE__ */ new Set();
1390
+ merged.workflows = merged.workflows.filter((item) => {
1391
+ if (!item?.name || seen.has(item.name)) return false;
1392
+ seen.add(item.name);
1393
+ return true;
1394
+ });
1395
+ }
1396
+ if (Array.isArray(merged.analytics_engine_datasets)) {
1397
+ const seen = /* @__PURE__ */ new Set();
1398
+ merged.analytics_engine_datasets = merged.analytics_engine_datasets.filter((item) => {
1399
+ if (!item?.binding || seen.has(item.binding)) return false;
1400
+ seen.add(item.binding);
1401
+ return true;
1402
+ });
1403
+ }
1404
+ if (Array.isArray(merged.ratelimits)) {
1405
+ const seen = /* @__PURE__ */ new Set();
1406
+ merged.ratelimits = merged.ratelimits.filter((item) => {
1407
+ if (!item?.name || seen.has(item.name)) return false;
1408
+ seen.add(item.name);
1409
+ return true;
1410
+ });
1411
+ }
1412
+ if (Array.isArray(merged.hyperdrive)) {
1413
+ const seen = /* @__PURE__ */ new Set();
1414
+ merged.hyperdrive = merged.hyperdrive.filter((item) => {
1415
+ if (!item?.binding || seen.has(item.binding)) return false;
1416
+ seen.add(item.binding);
1417
+ return true;
1418
+ });
1419
+ }
1420
+ if (Array.isArray(merged.send_email)) {
1421
+ const seen = /* @__PURE__ */ new Set();
1422
+ merged.send_email = merged.send_email.filter((item) => {
1423
+ if (!item?.name || seen.has(item.name)) return false;
1424
+ seen.add(item.name);
1425
+ return true;
1426
+ });
1427
+ }
1428
+ if (merged.durable_objects && Array.isArray(merged.durable_objects.bindings)) {
1429
+ const seen = /* @__PURE__ */ new Set();
1430
+ merged.durable_objects.bindings = merged.durable_objects.bindings.filter((item) => {
1431
+ if (!item?.name || seen.has(item.name)) return false;
1432
+ seen.add(item.name);
1433
+ return true;
1434
+ });
1435
+ }
1436
+ return merged;
1437
+ }
1438
+ async function buildDevWranglerConfig(nuxt, options) {
1439
+ const merged = await createWranglerConfig(nuxt, options);
1440
+ const isRemote = Boolean(options.remote || process.env.QARPEO_CF_REMOTE);
1441
+ const hasToken = Boolean(process.env.CLOUDFLARE_API_TOKEN || process.env.CLOUDFLARE_ACCOUNT_ID);
1442
+ if ((nuxt.options.dev || nuxt.options._prepare) && !isRemote && !hasToken && merged.ai) {
1443
+ delete merged.ai;
1444
+ }
1445
+ return merged;
1446
+ }
1447
+ async function generateDevWranglerConfig(nuxt, options) {
1448
+ const buildDir = nuxt.options.buildDir;
1449
+ const configPath = join(buildDir, "wrangler.json");
1450
+ const merged = await buildDevWranglerConfig(nuxt, options);
1451
+ await mkdir(buildDir, { recursive: true });
1452
+ await writeFile(configPath, JSON.stringify(merged, null, 2), "utf8");
1453
+ return configPath;
1454
+ }
1455
+
1456
+ const wrangler = {
1457
+ __proto__: null,
1458
+ buildDevWranglerConfig: buildDevWranglerConfig,
1459
+ createWranglerConfig: createWranglerConfig,
1460
+ generateDevWranglerConfig: generateDevWranglerConfig,
1461
+ resolveProjectName: resolveProjectName
1462
+ };
1463
+
1464
+ function findAgentFiles(layers, dirName = "server/agents") {
1465
+ const agentsMap = /* @__PURE__ */ new Map();
1466
+ for (const layer of layers) {
1467
+ const baseDirs = /* @__PURE__ */ new Set();
1468
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
1469
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
1470
+ if (layer.cwd) baseDirs.add(layer.cwd);
1471
+ for (const baseDir of baseDirs) {
1472
+ const agentsDir = resolve(baseDir, dirName);
1473
+ if (!existsSync(agentsDir)) continue;
1474
+ try {
1475
+ const entries = readdirSync(agentsDir);
1476
+ for (const entry of entries) {
1477
+ const fullPath = join(agentsDir, entry);
1478
+ const stat = statSync(fullPath);
1479
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
1480
+ if (entry.endsWith(".d.ts")) continue;
1481
+ const ext = extname(entry);
1482
+ const name = basename(entry, ext);
1483
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
1484
+ agentsMap.set(name, { name, file: fullPath, importPath });
1485
+ }
1486
+ }
1487
+ } catch {
1488
+ }
1489
+ }
1490
+ }
1491
+ return Array.from(agentsMap.values());
1492
+ }
1493
+
1494
+ function findBotFiles(layers, options) {
1495
+ const botsMap = /* @__PURE__ */ new Map();
1496
+ const candidateDirs = options?.dir ? [options.dir] : ["server/bots", "server/bot"];
1497
+ const basePath = (options?.path || "/api/bots").replace(/\/$/, "");
1498
+ for (const layer of layers) {
1499
+ const baseDirs = /* @__PURE__ */ new Set();
1500
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
1501
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
1502
+ if (layer.cwd) baseDirs.add(layer.cwd);
1503
+ for (const baseDir of baseDirs) {
1504
+ for (const relDir of candidateDirs) {
1505
+ const fullDir = resolve(baseDir, relDir);
1506
+ if (!existsSync(fullDir)) continue;
1507
+ try {
1508
+ const entries = readdirSync(fullDir);
1509
+ for (const entry of entries) {
1510
+ const fullPath = join(fullDir, entry);
1511
+ const stat = statSync(fullPath);
1512
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
1513
+ if (entry.endsWith(".d.ts")) continue;
1514
+ const ext = extname(entry);
1515
+ let rawName = basename(entry, ext);
1516
+ rawName = rawName.replace(/\.(post|get|put|delete|patch)$/i, "");
1517
+ const name = rawName.toLowerCase();
1518
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
1519
+ const route = `${basePath}/${name}`;
1520
+ botsMap.set(name, {
1521
+ name,
1522
+ file: fullPath,
1523
+ importPath,
1524
+ route
1525
+ });
1526
+ }
1527
+ }
1528
+ } catch {
1529
+ }
1530
+ }
1531
+ }
1532
+ }
1533
+ return Array.from(botsMap.values());
1534
+ }
1535
+
1536
+ function findEmailHandlerFiles(layers, customDir) {
1537
+ const handlerFiles = /* @__PURE__ */ new Set();
1538
+ for (const layer of layers) {
1539
+ const baseDirs = /* @__PURE__ */ new Set();
1540
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
1541
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
1542
+ if (layer.cwd) baseDirs.add(layer.cwd);
1543
+ for (const baseDir of baseDirs) {
1544
+ if (customDir) {
1545
+ const customPath = resolve(baseDir, customDir);
1546
+ if (existsSync(customPath)) {
1547
+ if (customPath.endsWith(".ts") || customPath.endsWith(".js") || customPath.endsWith(".mjs")) {
1548
+ handlerFiles.add(customPath);
1549
+ } else {
1550
+ try {
1551
+ for (const file of readdirSync(customPath)) {
1552
+ if ((file.endsWith(".ts") || file.endsWith(".js") || file.endsWith(".mjs")) && !file.endsWith(".d.ts")) {
1553
+ handlerFiles.add(resolve(customPath, file));
1554
+ }
1555
+ }
1556
+ } catch {
1557
+ }
1558
+ }
1559
+ }
1560
+ }
1561
+ const emailFile = resolve(baseDir, "server/email.ts");
1562
+ if (existsSync(emailFile)) {
1563
+ handlerFiles.add(emailFile);
1564
+ }
1565
+ const emailIndexFile = resolve(baseDir, "server/email/index.ts");
1566
+ if (existsSync(emailIndexFile)) {
1567
+ handlerFiles.add(emailIndexFile);
1568
+ }
1569
+ const emailIncomingFile = resolve(baseDir, "server/email/incoming.ts");
1570
+ if (existsSync(emailIncomingFile)) {
1571
+ handlerFiles.add(emailIncomingFile);
1572
+ }
1573
+ const emailDir = resolve(baseDir, "server/email");
1574
+ if (existsSync(emailDir)) {
1575
+ try {
1576
+ const files = readdirSync(emailDir);
1577
+ for (const file of files) {
1578
+ if ((file.endsWith(".ts") || file.endsWith(".js") || file.endsWith(".mjs")) && !file.endsWith(".d.ts") && file !== "index.ts" && file !== "incoming.ts") {
1579
+ handlerFiles.add(resolve(emailDir, file));
1580
+ }
1581
+ }
1582
+ } catch {
1583
+ }
1584
+ }
1585
+ }
1586
+ }
1587
+ return Array.from(handlerFiles);
1588
+ }
1589
+
1590
+ function findMcpFiles(layers, options) {
1591
+ const mcpMap = /* @__PURE__ */ new Map();
1592
+ const candidateDirs = options?.dir ? [options.dir] : ["server/mcp"];
1593
+ const basePath = (options?.path || "/mcp").replace(/\/$/, "");
1594
+ for (const layer of layers) {
1595
+ const baseDirs = /* @__PURE__ */ new Set();
1596
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
1597
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
1598
+ if (layer.cwd) baseDirs.add(layer.cwd);
1599
+ for (const baseDir of baseDirs) {
1600
+ const singleFile = resolve(baseDir, "server/mcp.ts");
1601
+ if (existsSync(singleFile)) {
1602
+ const importPath = singleFile.replace(/\\/g, "/").replace(/\.ts$/, "");
1603
+ mcpMap.set("default", {
1604
+ name: "default",
1605
+ file: singleFile,
1606
+ importPath,
1607
+ route: basePath || "/mcp"
1608
+ });
1609
+ }
1610
+ for (const relDir of candidateDirs) {
1611
+ const fullDir = resolve(baseDir, relDir);
1612
+ if (!existsSync(fullDir)) continue;
1613
+ try {
1614
+ const entries = readdirSync(fullDir);
1615
+ for (const entry of entries) {
1616
+ const fullPath = join(fullDir, entry);
1617
+ const stat = statSync(fullPath);
1618
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
1619
+ if (entry.endsWith(".d.ts")) continue;
1620
+ const ext = extname(entry);
1621
+ let rawName = basename(entry, ext);
1622
+ rawName = rawName.replace(/\.(post|get|put|delete|patch)$/i, "");
1623
+ const isIndex = rawName === "index";
1624
+ const name = isIndex ? "default" : rawName.toLowerCase();
1625
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
1626
+ const route = isIndex ? basePath || "/mcp" : `${basePath}/${name}`;
1627
+ mcpMap.set(name, {
1628
+ name,
1629
+ file: fullPath,
1630
+ importPath,
1631
+ route
1632
+ });
1633
+ }
1634
+ }
1635
+ } catch {
1636
+ }
1637
+ }
1638
+ }
1639
+ }
1640
+ return Array.from(mcpMap.values());
1641
+ }
1642
+
1643
+ function toCamelCase(str) {
1644
+ return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
1645
+ }
1646
+ function findToolFiles(layers, customDir) {
1647
+ const toolsMap = /* @__PURE__ */ new Map();
1648
+ const candidateDirs = customDir ? [customDir] : ["server/tools"];
1649
+ for (const layer of layers) {
1650
+ const baseDirs = /* @__PURE__ */ new Set();
1651
+ if (layer.config?.srcDir) baseDirs.add(layer.config.srcDir);
1652
+ if (layer.config?.rootDir) baseDirs.add(layer.config.rootDir);
1653
+ if (layer.cwd) baseDirs.add(layer.cwd);
1654
+ for (const baseDir of baseDirs) {
1655
+ for (const relDir of candidateDirs) {
1656
+ const fullDir = resolve(baseDir, relDir);
1657
+ if (!existsSync(fullDir)) continue;
1658
+ try {
1659
+ const entries = readdirSync(fullDir);
1660
+ for (const entry of entries) {
1661
+ const fullPath = join(fullDir, entry);
1662
+ const stat = statSync(fullPath);
1663
+ if (stat.isFile() && (entry.endsWith(".ts") || entry.endsWith(".js") || entry.endsWith(".mjs"))) {
1664
+ if (entry.endsWith(".d.ts")) continue;
1665
+ const ext = extname(entry);
1666
+ const rawName = basename(entry, ext);
1667
+ const name = toCamelCase(rawName);
1668
+ const importPath = fullPath.replace(/\\/g, "/").replace(/\.(ts|js|mjs)$/, "");
1669
+ toolsMap.set(rawName, { name, file: fullPath, importPath });
1670
+ }
1671
+ }
1672
+ } catch {
1673
+ }
1674
+ }
1675
+ }
1676
+ }
1677
+ return Array.from(toolsMap.values());
1678
+ }
1679
+
1680
+ export { findQueueFiles as A, findDurableObjectFiles as B, hasDatabaseSchema as C, localDb as D, wrangler as E, resolveBinaryPath as a, getJiti as b, resolveProjectName as c, discoverDatabases as d, ensurePackage as e, checkDrizzleVersion as f, getLocalDatabaseContext as g, findSchemaFiles as h, findLocalD1Database as i, findAgentFiles as j, findToolFiles as k, findBotFiles as l, findMcpFiles as m, findJobFiles as n, findWorkflowFiles as o, findEmailHandlerFiles as p, buildDevWranglerConfig as q, resolveDatabaseTarget as r, spawnBinSync as s, scanSchemaExports as t, findScheduledTasks as u, version as v, resolveBindingName as w, createWranglerConfig as x, generateDevWranglerConfig as y, applyD1Migrations as z };