qarpeo 0.2.0 → 0.3.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 (260) hide show
  1. package/dist/chunks/tools.mjs +993 -31
  2. package/dist/cli/index.mjs +1102 -31
  3. package/dist/fate/index.d.ts +9 -1
  4. package/dist/fate/index.mjs +20 -3
  5. package/dist/module.mjs +296 -753
  6. package/dist/runtime/browser.mjs +2 -2
  7. package/dist/runtime/comments-server.d.ts +3 -0
  8. package/dist/runtime/comments-server.mjs +2 -0
  9. package/dist/runtime/comments.d.ts +0 -2
  10. package/dist/runtime/comments.mjs +0 -2
  11. package/dist/runtime/db.d.ts +10 -9
  12. package/dist/runtime/db.mjs +79 -8
  13. package/dist/runtime/drizzle.mjs +21 -6
  14. package/dist/runtime/index.d.ts +4 -0
  15. package/dist/runtime/realtime-server.d.ts +4 -0
  16. package/dist/runtime/realtime-server.mjs +13 -0
  17. package/dist/runtime/realtime.d.ts +1 -4
  18. package/dist/runtime/realtime.mjs +0 -13
  19. package/dist/runtime/replica.d.ts +27 -0
  20. package/dist/runtime/replica.mjs +229 -0
  21. package/dist/runtime/server/durable-objects/agent.mjs +14 -2
  22. package/dist/runtime/server/durable-objects/room.d.ts +10 -0
  23. package/dist/runtime/server/durable-objects/room.mjs +119 -28
  24. package/dist/runtime/server/middleware/devtools.mjs +1 -1
  25. package/dist/runtime/server/middleware/tenancy.mjs +7 -4
  26. package/dist/runtime/server/plugins/store.mjs +1 -1
  27. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
  28. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
  29. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
  30. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
  31. package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
  32. package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
  33. package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
  34. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
  35. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
  36. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
  37. package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
  38. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
  39. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
  40. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
  41. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
  42. package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
  43. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
  44. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
  45. package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
  46. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
  47. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
  48. package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
  49. package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
  50. package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
  51. package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
  52. package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
  53. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
  54. package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
  55. package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
  56. package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
  57. package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
  58. package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
  59. package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
  60. package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
  61. package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
  62. package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
  63. package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
  64. package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
  65. package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
  66. package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
  67. package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
  68. package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
  69. package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
  70. package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
  71. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
  72. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
  73. package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
  74. package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
  75. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
  76. package/dist/runtime/server/routes/fate.d.ts +6 -0
  77. package/dist/runtime/server/routes/fate.mjs +32 -3
  78. package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
  79. package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
  80. package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
  81. package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
  82. package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
  83. package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
  84. package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
  85. package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
  86. package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
  87. package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
  88. package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
  89. package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
  90. package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
  91. package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
  92. package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
  93. package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
  94. package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
  95. package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
  96. package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
  97. package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
  98. package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
  99. package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
  100. package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
  101. package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
  102. package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
  103. package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
  104. package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
  105. package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
  106. package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
  107. package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
  108. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
  109. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
  110. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
  111. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
  112. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
  113. package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
  114. package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
  115. package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
  116. package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
  118. package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
  119. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
  120. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
  121. package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
  122. package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
  123. package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
  124. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
  125. package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
  126. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
  127. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  128. package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
  129. package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
  130. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
  131. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
  132. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
  133. package/dist/runtime/server/utils/ai.d.ts +6 -0
  134. package/dist/runtime/server/utils/ai.mjs +12 -2
  135. package/dist/runtime/server/utils/analytics-query.mjs +8 -4
  136. package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
  137. package/dist/runtime/server/utils/browser-utils.mjs +135 -0
  138. package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
  139. package/dist/runtime/server/utils/cms/cache.mjs +95 -0
  140. package/dist/runtime/server/utils/cms/common.mjs +1 -1
  141. package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
  142. package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
  143. package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
  144. package/dist/runtime/server/utils/cms/path.d.ts +8 -0
  145. package/dist/runtime/server/utils/cms/path.mjs +23 -0
  146. package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
  147. package/dist/runtime/server/utils/cms/queries.mjs +366 -0
  148. package/dist/runtime/server/utils/cms/references.d.ts +48 -0
  149. package/dist/runtime/server/utils/cms/references.mjs +309 -0
  150. package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
  151. package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
  152. package/dist/runtime/server/utils/cms/sync.mjs +3 -3
  153. package/dist/runtime/server/utils/cms.d.ts +5 -82
  154. package/dist/runtime/server/utils/cms.mjs +28 -1367
  155. package/dist/runtime/server/utils/comments.d.ts +11 -0
  156. package/dist/runtime/server/utils/comments.mjs +65 -17
  157. package/dist/runtime/server/utils/crypto.mjs +1 -1
  158. package/dist/runtime/server/utils/domains.mjs +9 -0
  159. package/dist/runtime/server/utils/drizzle.d.ts +26 -1
  160. package/dist/runtime/server/utils/drizzle.mjs +78 -19
  161. package/dist/runtime/server/utils/email-inbound.mjs +9 -1
  162. package/dist/runtime/server/utils/impersonation.mjs +58 -1
  163. package/dist/runtime/server/utils/lock.d.ts +11 -0
  164. package/dist/runtime/server/utils/lock.mjs +4 -0
  165. package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
  166. package/dist/runtime/server/utils/mail.d.ts +2 -1
  167. package/dist/runtime/server/utils/mail.mjs +17 -11
  168. package/dist/runtime/server/utils/notifications.d.ts +13 -4
  169. package/dist/runtime/server/utils/notifications.mjs +20 -4
  170. package/dist/runtime/server/utils/organization.mjs +36 -1
  171. package/dist/runtime/server/utils/passwordless.mjs +8 -0
  172. package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
  173. package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
  174. package/dist/runtime/server/utils/payments/common.d.ts +45 -0
  175. package/dist/runtime/server/utils/payments/common.mjs +234 -0
  176. package/dist/runtime/server/utils/payments/index.d.ts +9 -0
  177. package/dist/runtime/server/utils/payments/index.mjs +21 -0
  178. package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
  179. package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
  180. package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
  181. package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
  182. package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
  183. package/dist/runtime/server/utils/payments/polar.mjs +66 -0
  184. package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
  185. package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
  186. package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
  187. package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
  188. package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
  189. package/dist/runtime/server/utils/payments/usage.mjs +143 -0
  190. package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
  191. package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
  192. package/dist/runtime/server/utils/payments.d.ts +1 -158
  193. package/dist/runtime/server/utils/payments.mjs +1 -1289
  194. package/dist/runtime/server/utils/queue.d.ts +2 -0
  195. package/dist/runtime/server/utils/queue.mjs +34 -21
  196. package/dist/runtime/server/utils/rag.mjs +30 -17
  197. package/dist/runtime/server/utils/realtime.d.ts +5 -1
  198. package/dist/runtime/server/utils/realtime.mjs +43 -7
  199. package/dist/runtime/server/utils/session.mjs +16 -3
  200. package/dist/runtime/server/utils/sso.d.ts +3 -0
  201. package/dist/runtime/server/utils/sso.mjs +43 -0
  202. package/dist/runtime/server/utils/storage.mjs +12 -1
  203. package/dist/runtime/server/utils/store/cart.d.ts +63 -0
  204. package/dist/runtime/server/utils/store/cart.mjs +542 -0
  205. package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
  206. package/dist/runtime/server/utils/store/checkout.mjs +118 -0
  207. package/dist/runtime/server/utils/store/common.d.ts +29 -0
  208. package/dist/runtime/server/utils/store/common.mjs +479 -0
  209. package/dist/runtime/server/utils/store/index.d.ts +7 -0
  210. package/dist/runtime/server/utils/store/index.mjs +30 -0
  211. package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
  212. package/dist/runtime/server/utils/store/inventory.mjs +190 -0
  213. package/dist/runtime/server/utils/store/orders.d.ts +60 -0
  214. package/dist/runtime/server/utils/store/orders.mjs +590 -0
  215. package/dist/runtime/server/utils/store/products.d.ts +35 -0
  216. package/dist/runtime/server/utils/store/products.mjs +461 -0
  217. package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
  218. package/dist/runtime/server/utils/store/vendor.mjs +68 -0
  219. package/dist/runtime/server/utils/store.d.ts +1 -207
  220. package/dist/runtime/server/utils/store.mjs +1 -2227
  221. package/dist/runtime/server/utils/string.d.ts +1 -1
  222. package/dist/runtime/server/utils/string.mjs +12 -4
  223. package/dist/runtime/server/utils/tenant.mjs +19 -5
  224. package/dist/runtime/server/utils/tracker.mjs +2 -0
  225. package/dist/runtime/server.d.ts +3 -3
  226. package/dist/runtime/server.mjs +4 -4
  227. package/dist/runtime/storage-server.d.ts +2 -0
  228. package/dist/runtime/storage-server.mjs +1 -0
  229. package/dist/runtime/storage.d.ts +1 -1
  230. package/dist/runtime/storage.mjs +0 -1
  231. package/dist/runtime/store.d.ts +0 -1
  232. package/dist/runtime/store.mjs +0 -1
  233. package/dist/runtime/test-utils.d.ts +4 -0
  234. package/dist/runtime/test-utils.mjs +54 -0
  235. package/dist/runtime/types/d1.d.ts +43 -0
  236. package/dist/runtime/types/drizzle.d.ts +6 -0
  237. package/dist/runtime/types/store.d.ts +1 -1
  238. package/dist/types/analytics.d.ts +80 -0
  239. package/dist/types/auth.d.ts +282 -0
  240. package/dist/types/cache.d.ts +55 -0
  241. package/dist/types/comments.d.ts +130 -0
  242. package/dist/types/db.d.ts +29 -0
  243. package/dist/types/email.d.ts +182 -0
  244. package/dist/types/index.d.ts +22 -0
  245. package/dist/types/jobs.d.ts +58 -0
  246. package/dist/types/notifications.d.ts +77 -0
  247. package/dist/types/options.d.ts +363 -0
  248. package/dist/types/payments.d.ts +145 -0
  249. package/dist/types/ratelimit.d.ts +71 -0
  250. package/dist/types/realtime.d.ts +136 -0
  251. package/dist/types/site.d.ts +121 -0
  252. package/dist/types/storage.d.ts +164 -0
  253. package/dist/types/store-options.d.ts +199 -0
  254. package/dist/types/tenant.d.ts +100 -0
  255. package/dist/types.d.ts +1 -2174
  256. package/dist/utils/migration-lock.d.ts +139 -0
  257. package/dist/utils/pkg.d.ts +14 -1
  258. package/dist/utils/schema-diff.d.ts +39 -0
  259. package/package.json +55 -17
  260. package/dist/chunks/auth-schema.mjs +0 -364
@@ -6,10 +6,12 @@ import { resolve, dirname, join, extname, basename, relative } from 'pathe';
6
6
  import { stdin, stdout } from 'node:process';
7
7
  import readline from 'node:readline/promises';
8
8
  import { fileURLToPath } from 'node:url';
9
+ import { snakeCase, integer, text, index, uniqueIndex } from 'drizzle-orm/sqlite-core';
10
+ import { useRuntimeConfig } from 'nuxt/server';
9
11
  import { mkdir, writeFile, readFile } from 'node:fs/promises';
10
12
  import { defu } from 'defu';
11
13
 
12
- const version = "0.2.0";
14
+ const version = "0.3.0";
13
15
 
14
16
  function resolveBindingName(service, override, defaultName) {
15
17
  if (override && typeof override === "string") {
@@ -34,7 +36,7 @@ function singularize(name) {
34
36
  function toPascalCase$1(str) {
35
37
  return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
36
38
  }
37
- function toCamelCase$1(str) {
39
+ function toCamelCase$2(str) {
38
40
  const pascal = toPascalCase$1(str);
39
41
  return pascal.charAt(0).toLowerCase() + pascal.slice(1);
40
42
  }
@@ -62,7 +64,7 @@ function scanSchemaExports(schemaFiles) {
62
64
  tables.push({
63
65
  name: varName,
64
66
  modelName: toPascalCase$1(singular),
65
- camelName: toCamelCase$1(singular),
67
+ camelName: toCamelCase$2(singular),
66
68
  file
67
69
  });
68
70
  }
@@ -132,13 +134,23 @@ Please ensure qarpeo dependencies are installed.`
132
134
  }
133
135
  }
134
136
  function getDatabaseIdentifiers(dirName, isPrimary = false) {
135
- if (isPrimary || dirName === "d1") {
137
+ if (isPrimary) {
138
+ return {
139
+ schema: "schema",
140
+ db: "db",
141
+ zod: "dbZod",
142
+ types: "DbTypes",
143
+ isPrimary: true,
144
+ engine: "d1"
145
+ };
146
+ }
147
+ if (dirName === "d1") {
136
148
  return {
137
149
  schema: "d1Schema",
138
150
  db: "d1Db",
139
151
  zod: "d1Zod",
140
152
  types: "D1Types",
141
- isPrimary: true,
153
+ isPrimary: false,
142
154
  engine: "d1"
143
155
  };
144
156
  }
@@ -223,7 +235,7 @@ function getDatabaseIdentifiers(dirName, isPrimary = false) {
223
235
  };
224
236
  }
225
237
  const pascal = toPascalCase$1(dirName);
226
- const camel = toCamelCase$1(dirName);
238
+ const camel = toCamelCase$2(dirName);
227
239
  return {
228
240
  schema: `${camel}Schema`,
229
241
  db: `${camel}Db`,
@@ -282,10 +294,6 @@ function discoverDatabases(layers, options) {
282
294
  }
283
295
  };
284
296
  const primarySchemaFiles = /* @__PURE__ */ new Set();
285
- const rootD1Dir = resolve(baseDir, "db/d1");
286
- if (existsSync(rootD1Dir)) {
287
- collectSchemaFromDir(rootD1Dir, primarySchemaFiles);
288
- }
289
297
  const rootDbSchemaFile = resolve(baseDir, "db/schema.ts");
290
298
  if (existsSync(rootDbSchemaFile)) primarySchemaFiles.add(rootDbSchemaFile);
291
299
  const rootDbSchemaDir = resolve(baseDir, "db/schema");
@@ -301,24 +309,26 @@ function discoverDatabases(layers, options) {
301
309
  }
302
310
  }
303
311
  }
304
- if (primarySchemaFiles.size > 0 || !dbs.has("default")) {
312
+ const hasExplicitDb = Boolean(options?.db || options?.d1);
313
+ const hasBuiltins = Boolean(
314
+ options?.auth || options?.cms || options?.payments || options?.store || options?.comments || options?.notifications || options?.notify
315
+ );
316
+ if (primarySchemaFiles.size > 0 || hasExplicitDb || hasBuiltins) {
305
317
  const primaryBinding = resolveBindingName("db", dbOpts.binding);
306
318
  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;
319
+ const primaryMigrationsDir = resolve(baseDir, "db/migrations");
310
320
  dbs.set("default", {
311
321
  name: "default",
312
- dirName: "d1",
322
+ dirName: "schema",
313
323
  isPrimary: true,
314
324
  binding: primaryBinding,
315
325
  databaseName: dbOpts.databaseName || primaryBinding,
316
326
  databaseId: primaryId,
317
- dir: primaryDir,
327
+ dir: rootDbDir,
318
328
  migrationsDir: primaryMigrationsDir,
319
329
  schemaFiles: Array.from(primarySchemaFiles),
320
330
  dialect: "sqlite",
321
- identifiers: getDatabaseIdentifiers("d1", true)
331
+ identifiers: getDatabaseIdentifiers("schema", true)
322
332
  });
323
333
  }
324
334
  if (existsSync(rootDbDir) && statSync(rootDbDir).isDirectory()) {
@@ -326,19 +336,38 @@ function discoverDatabases(layers, options) {
326
336
  const entries = readdirSync(rootDbDir, { withFileTypes: true });
327
337
  for (const entry of entries) {
328
338
  if (!entry.isDirectory()) continue;
329
- if (entry.name === "d1" || entry.name === "migrations" || entry.name === "schema" || entry.name === "data") {
339
+ if (entry.name === "migrations" || entry.name === "schema" || entry.name === "data") {
330
340
  continue;
331
341
  }
332
342
  const dirPath = resolve(rootDbDir, entry.name);
333
343
  if (!hasDatabaseSchema(dirPath)) continue;
334
- if (entry.name.startsWith("d1-")) {
344
+ if (entry.name === "d1") {
345
+ const name = "d1";
346
+ const binding = process.env.D1_BINDING || process.env.D1_DB_BINDING || "D1_DB";
347
+ const secId = process.env.D1_ID || process.env.DATABASE_D1_ID || `${binding}_LOCAL_DEV`;
348
+ const migrationsDir = resolve(dirPath, "migrations");
349
+ const secSchemaFiles = /* @__PURE__ */ new Set();
350
+ collectSchemaFromDir(dirPath, secSchemaFiles);
351
+ dbs.set("d1", {
352
+ name,
353
+ dirName: "d1",
354
+ isPrimary: false,
355
+ binding,
356
+ databaseId: secId,
357
+ dir: dirPath,
358
+ migrationsDir,
359
+ schemaFiles: Array.from(secSchemaFiles),
360
+ dialect: "sqlite",
361
+ identifiers: getDatabaseIdentifiers("d1", false)
362
+ });
363
+ } else if (entry.name.startsWith("d1-")) {
335
364
  const name = entry.name.slice(3);
336
365
  const binding = process.env[`D1_${name.toUpperCase()}_BINDING`] || `${name.toUpperCase().replace(/[^A-Z0-9_]/g, "_")}_DB`;
337
366
  const secId = process.env[`D1_${name.toUpperCase()}_ID`] || process.env[`DATABASE_${name.toUpperCase()}_ID`] || `${binding}_LOCAL_DEV`;
338
367
  const migrationsDir = resolve(dirPath, "migrations");
339
368
  const secSchemaFiles = /* @__PURE__ */ new Set();
340
369
  collectSchemaFromDir(dirPath, secSchemaFiles);
341
- dbs.set(name.toLowerCase(), {
370
+ dbs.set(entry.name.toLowerCase(), {
342
371
  name,
343
372
  dirName: entry.name,
344
373
  isPrimary: false,
@@ -357,7 +386,7 @@ function discoverDatabases(layers, options) {
357
386
  const migrationsDir = resolve(dirPath, "migrations");
358
387
  const secSchemaFiles = /* @__PURE__ */ new Set();
359
388
  collectSchemaFromDir(dirPath, secSchemaFiles);
360
- dbs.set(name.toLowerCase(), {
389
+ dbs.set(entry.name.toLowerCase(), {
361
390
  name,
362
391
  dirName: entry.name,
363
392
  isPrimary: false,
@@ -376,7 +405,7 @@ function discoverDatabases(layers, options) {
376
405
  const migrationsDir = resolve(dirPath, "migrations");
377
406
  const secSchemaFiles = /* @__PURE__ */ new Set();
378
407
  collectSchemaFromDir(dirPath, secSchemaFiles);
379
- dbs.set(name.toLowerCase(), {
408
+ dbs.set(entry.name.toLowerCase(), {
380
409
  name,
381
410
  dirName: entry.name,
382
411
  isPrimary: false,
@@ -484,23 +513,23 @@ function discoverDatabases(layers, options) {
484
513
  }
485
514
  function resolveDatabaseTarget(layers, targetDbName, options) {
486
515
  const allDbs = discoverDatabases(layers, options);
487
- if (!targetDbName || ["default", "primary", "d1"].includes(targetDbName.toLowerCase())) {
516
+ if (!targetDbName || ["default", "primary"].includes(targetDbName.toLowerCase())) {
488
517
  const primary = allDbs.find((d) => d.isPrimary);
489
518
  if (primary) return primary;
490
519
  const baseDir = layers[0]?.cwd || process.cwd();
491
- const d1Dir = resolve(baseDir, "db/d1");
492
- const d1Mig = resolve(baseDir, "db/d1/migrations");
520
+ const schemaDir = resolve(baseDir, "db/schema");
521
+ const schemaMig = resolve(baseDir, "db/migrations");
493
522
  return {
494
523
  name: "default",
495
- dirName: "d1",
524
+ dirName: "schema",
496
525
  isPrimary: true,
497
526
  binding: "DB",
498
527
  databaseId: "DB_LOCAL_DEV",
499
- dir: d1Dir,
500
- migrationsDir: d1Mig,
528
+ dir: schemaDir,
529
+ migrationsDir: schemaMig,
501
530
  schemaFiles: [],
502
531
  dialect: "sqlite",
503
- identifiers: getDatabaseIdentifiers("d1", true)
532
+ identifiers: getDatabaseIdentifiers("schema", true)
504
533
  };
505
534
  }
506
535
  const query = targetDbName.trim();
@@ -607,6 +636,31 @@ async function confirmInstall(packageName, purpose) {
607
636
  rl.close();
608
637
  }
609
638
  }
639
+ async function formatAddCommand(packageName, options = {}) {
640
+ const cwd = options.cwd || process.cwd();
641
+ try {
642
+ const { detectPackageManager, addDependencyCommand } = await import('nypm');
643
+ const pm = await detectPackageManager(cwd);
644
+ if (pm) {
645
+ return addDependencyCommand(pm.name, packageName, { dev: options.dev });
646
+ }
647
+ } catch {
648
+ }
649
+ return `npm install ${options.dev ? "-D " : ""}${packageName}`;
650
+ }
651
+ async function formatDlxCommand(command, args = [], options = {}) {
652
+ const cwd = options.cwd || process.cwd();
653
+ const fullCmd = args.length > 0 ? `${command} ${args.join(" ")}` : command;
654
+ try {
655
+ const { detectPackageManager, dlxCommand } = await import('nypm');
656
+ const pm = await detectPackageManager(cwd);
657
+ if (pm) {
658
+ return dlxCommand(pm.name, fullCmd);
659
+ }
660
+ } catch {
661
+ }
662
+ return `npx ${fullCmd}`;
663
+ }
610
664
  async function ensurePackage(packageName, options = {}) {
611
665
  const cwd = options?.cwd || process.cwd();
612
666
  const purpose = options?.purpose || "this operation";
@@ -615,10 +669,11 @@ async function ensurePackage(packageName, options = {}) {
615
669
  }
616
670
  const confirmed = await confirmInstall(packageName, purpose);
617
671
  if (!confirmed) {
672
+ const addCmd = await formatAddCommand(packageName, { cwd, dev: options.dev });
618
673
  console.error(
619
674
  `
620
675
  \u274C [qarpeo] Missing dependency: "${packageName}". Please install it manually:
621
- vp add ${options.dev ? "-D " : ""}${packageName}
676
+ ${addCmd}
622
677
  `
623
678
  );
624
679
  return false;
@@ -802,6 +857,913 @@ const localDb = {
802
857
  getLocalDatabaseContext: getLocalDatabaseContext
803
858
  };
804
859
 
860
+ function getQarpeoConfig(event) {
861
+ let rc;
862
+ try {
863
+ rc = useRuntimeConfig(event);
864
+ } catch {
865
+ rc = void 0;
866
+ }
867
+ if (!rc || !rc.qarpeo) {
868
+ rc = globalThis.__NUXT_RUNTIME_CONFIG__ || rc || {};
869
+ }
870
+ const q = event?.context?.qarpeo || rc?.qarpeo || {};
871
+ return {
872
+ auth: q.auth || {},
873
+ blob: q.blob || q.storage || {},
874
+ storage: q.storage || q.blob || {},
875
+ cms: q.cms || {},
876
+ comments: q.comments || {},
877
+ payments: q.payments || {},
878
+ ratelimit: q.ratelimit || {},
879
+ realtime: q.realtime || {},
880
+ mail: q.mail || {},
881
+ analytics: q.analytics || {},
882
+ multitenant: q.multitenant || {},
883
+ store: q.store || {},
884
+ agents: q.agents || {},
885
+ jobs: q.jobs || {},
886
+ ...q
887
+ };
888
+ }
889
+
890
+ function getTablePrefix(event, explicitPrefix) {
891
+ let prefix = explicitPrefix;
892
+ if (prefix === void 0) {
893
+ try {
894
+ const cfg = getQarpeoConfig(event);
895
+ if (cfg) {
896
+ prefix = cfg.tablePrefix ?? cfg.prefix;
897
+ }
898
+ } catch {
899
+ }
900
+ }
901
+ if (prefix === void 0 && typeof process !== "undefined" && process?.env) {
902
+ const envVal = process.env.QARPEO_TABLE_PREFIX;
903
+ if (envVal === "1" || envVal === "true") {
904
+ prefix = true;
905
+ } else if (envVal && envVal !== "0" && envVal !== "false") {
906
+ prefix = envVal;
907
+ }
908
+ }
909
+ if (!prefix || prefix === false) return "";
910
+ if (prefix === true) return "qarpeo_";
911
+ return typeof prefix === "string" && prefix.endsWith("_") ? prefix : `${prefix}_`;
912
+ }
913
+ function getTableOverrides(event) {
914
+ try {
915
+ const cfg = getQarpeoConfig(event);
916
+ if (cfg?.tables && typeof cfg.tables === "object") {
917
+ return cfg.tables;
918
+ }
919
+ } catch {
920
+ }
921
+ if (typeof process !== "undefined" && process?.env?.QARPEO_TABLES) {
922
+ try {
923
+ return JSON.parse(process.env.QARPEO_TABLES);
924
+ } catch {
925
+ }
926
+ }
927
+ return {};
928
+ }
929
+ function toCamelCase$1(str) {
930
+ return str.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase());
931
+ }
932
+ function resolveTableName(baseName, prefixOrEventOrOptions, event) {
933
+ let explicitPrefix;
934
+ let tablesMap;
935
+ let effectiveEvent = event;
936
+ if (typeof prefixOrEventOrOptions === "object" && prefixOrEventOrOptions !== null && !("req" in prefixOrEventOrOptions && "res" in prefixOrEventOrOptions)) {
937
+ const opts = prefixOrEventOrOptions;
938
+ explicitPrefix = opts.tablePrefix ?? opts.prefix;
939
+ tablesMap = opts.tables;
940
+ } else if (typeof prefixOrEventOrOptions === "boolean" || typeof prefixOrEventOrOptions === "string") {
941
+ explicitPrefix = prefixOrEventOrOptions;
942
+ } else if (prefixOrEventOrOptions) {
943
+ effectiveEvent = prefixOrEventOrOptions;
944
+ }
945
+ const runtimeOverrides = getTableOverrides(effectiveEvent);
946
+ const mergedTables = { ...runtimeOverrides, ...tablesMap || {} };
947
+ const camelKey = toCamelCase$1(baseName);
948
+ const override = mergedTables[baseName] || mergedTables[camelKey];
949
+ if (override) {
950
+ return override;
951
+ }
952
+ const p = getTablePrefix(effectiveEvent, explicitPrefix);
953
+ return `${p}${baseName}`;
954
+ }
955
+ function resolveIndexName(tableName, suffix) {
956
+ return `idx_${tableName}_${suffix}`;
957
+ }
958
+
959
+ const ALL_AUTH_TABLE_NAMES = [
960
+ "user",
961
+ "account",
962
+ "session",
963
+ "verification",
964
+ "twoFactor",
965
+ "passkey",
966
+ "organization",
967
+ "member",
968
+ "invitation",
969
+ "auditLogs"
970
+ ];
971
+ function getActiveAuthTableNames(auth, prefixOrOptions) {
972
+ if (!auth) return [];
973
+ const opts = typeof auth === "object" ? auth : {};
974
+ const tables = [
975
+ resolveTableName("user", prefixOrOptions),
976
+ resolveTableName("account", prefixOrOptions),
977
+ resolveTableName("session", prefixOrOptions),
978
+ resolveTableName("verification", prefixOrOptions),
979
+ resolveTableName("audit_log", prefixOrOptions)
980
+ ];
981
+ if (opts.twoFactor) tables.push(resolveTableName("two_factor", prefixOrOptions));
982
+ if (opts.webauthn || opts.webAuthn) tables.push(resolveTableName("passkey", prefixOrOptions));
983
+ if (opts.organizations) {
984
+ tables.push(
985
+ resolveTableName("organization", prefixOrOptions),
986
+ resolveTableName("member", prefixOrOptions),
987
+ resolveTableName("invitation", prefixOrOptions)
988
+ );
989
+ }
990
+ return tables;
991
+ }
992
+ function compileExtendedField(key, def) {
993
+ switch (def.type) {
994
+ case "string": {
995
+ let chain = `text("${key}")`;
996
+ if (def.default !== void 0) chain += `.default(${JSON.stringify(def.default)})`;
997
+ if (def.nullable === false) chain += `.notNull()`;
998
+ return ` ${key}: ${chain},`;
999
+ }
1000
+ case "number": {
1001
+ let chain = `integer("${key}")`;
1002
+ if (def.default !== void 0) chain += `.default(${Number(def.default)})`;
1003
+ if (def.nullable === false) chain += `.notNull()`;
1004
+ return ` ${key}: ${chain},`;
1005
+ }
1006
+ case "boolean": {
1007
+ let chain = `integer("${key}", { mode: "boolean" })`;
1008
+ if (def.default !== void 0) chain += `.default(${def.default ? 1 : 0})`;
1009
+ return ` ${key}: ${chain},`;
1010
+ }
1011
+ case "json": {
1012
+ return ` ${key}: text("${key}", { mode: "json" }),`;
1013
+ }
1014
+ default:
1015
+ return ` ${key}: text("${key}"),`;
1016
+ }
1017
+ }
1018
+ function generateAuthSchema(auth, prefixOrOptions) {
1019
+ const opts = typeof auth === "object" ? auth : {};
1020
+ const extendsFields = opts.fields?.extends || {};
1021
+ const userTbl = resolveTableName("user", prefixOrOptions);
1022
+ const sessionTbl = resolveTableName("session", prefixOrOptions);
1023
+ const accountTbl = resolveTableName("account", prefixOrOptions);
1024
+ const verificationTbl = resolveTableName("verification", prefixOrOptions);
1025
+ const auditLogTbl = resolveTableName("audit_log", prefixOrOptions);
1026
+ const twoFactorTbl = resolveTableName("two_factor", prefixOrOptions);
1027
+ const passkeyTbl = resolveTableName("passkey", prefixOrOptions);
1028
+ const organizationTbl = resolveTableName("organization", prefixOrOptions);
1029
+ const memberTbl = resolveTableName("member", prefixOrOptions);
1030
+ const invitationTbl = resolveTableName("invitation", prefixOrOptions);
1031
+ const lines = [
1032
+ `// Auto-generated by Qarpeo for Better Auth on Cloudflare D1`,
1033
+ `// snakeCase.table maps camelCase property names \u2192 snake_case column names automatically`,
1034
+ `import { sql } from "drizzle-orm";
1035
+ import { snakeCase, text, integer, blob, index } from "drizzle-orm/sqlite-core";`,
1036
+ ``,
1037
+ `// \u2500\u2500\u2500 1. User Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1038
+ `export const user = snakeCase.table("${userTbl}", {`,
1039
+ ` id: text("id").primaryKey(),`,
1040
+ ` name: text("name").notNull(),`,
1041
+ ` email: text("email").notNull().unique(),`,
1042
+ ` emailVerified: integer("email_verified", { mode: "boolean" }).notNull().default(false),`,
1043
+ ` image: text("image"),`
1044
+ ];
1045
+ if (!extendsFields.role) {
1046
+ lines.push(` role: text("role").default("user"),`);
1047
+ }
1048
+ for (const [key, fieldDef] of Object.entries(extendsFields)) {
1049
+ lines.push(compileExtendedField(key, fieldDef));
1050
+ }
1051
+ lines.push(
1052
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1053
+ ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
1054
+ `});`,
1055
+ `export const users = user;`,
1056
+ ``,
1057
+ `// \u2500\u2500\u2500 2. Session Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1058
+ `export const session = snakeCase.table("${sessionTbl}", {`,
1059
+ ` id: text("id").primaryKey(),`,
1060
+ ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
1061
+ ` token: text("token").notNull().unique(),`,
1062
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1063
+ ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
1064
+ ` ipAddress: text("ip_address"),`,
1065
+ ` userAgent: text("user_agent"),`,
1066
+ ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
1067
+ `}, (table) => [`,
1068
+ ` index("${resolveIndexName(sessionTbl, "user_id")}").on(table.userId),`,
1069
+ ` index("${resolveIndexName(sessionTbl, "token")}").on(table.token),`,
1070
+ `]);`,
1071
+ `export const sessions = session;`,
1072
+ ``,
1073
+ `// \u2500\u2500\u2500 3. Account Table (OAuth & Passwords) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1074
+ `export const account = snakeCase.table("${accountTbl}", {`,
1075
+ ` id: text("id").primaryKey(),`,
1076
+ ` accountId: text("account_id").notNull(),`,
1077
+ ` providerId: text("provider_id").notNull(),`,
1078
+ ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
1079
+ ` accessToken: text("access_token"),`,
1080
+ ` refreshToken: text("refresh_token"),`,
1081
+ ` idToken: text("id_token"),`,
1082
+ ` accessTokenExpiresAt: integer("access_token_expires_at", { mode: "timestamp_ms" }),`,
1083
+ ` refreshTokenExpiresAt: integer("refresh_token_expires_at", { mode: "timestamp_ms" }),`,
1084
+ ` scope: text("scope"),`,
1085
+ ` password: text("password"),`,
1086
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1087
+ ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`).$onUpdate(() => new Date()),`,
1088
+ `}, (table) => [`,
1089
+ ` index("${resolveIndexName(accountTbl, "user_id")}").on(table.userId),`,
1090
+ `]);`,
1091
+ `export const accounts = account;`,
1092
+ ``,
1093
+ `// \u2500\u2500\u2500 4. Verification Table (Tokens & OTP) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1094
+ `export const verification = snakeCase.table("${verificationTbl}", {`,
1095
+ ` id: text("id").primaryKey(),`,
1096
+ ` identifier: text("identifier").notNull(),`,
1097
+ ` value: text("value").notNull(),`,
1098
+ ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
1099
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }),`,
1100
+ ` updatedAt: integer("updated_at", { mode: "timestamp_ms" }),`,
1101
+ `});`,
1102
+ `export const verifications = verification;`,
1103
+ ``,
1104
+ `// \u2500\u2500\u2500 5. Audit Logs Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1105
+ `export const auditLogs = snakeCase.table("${auditLogTbl}", {`,
1106
+ ` id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),`,
1107
+ ` userId: text("user_id"),`,
1108
+ ` action: text("action").notNull(),`,
1109
+ ` targetType: text("target_type"),`,
1110
+ ` targetId: text("target_id"),`,
1111
+ ` details: text("details", { mode: "json" }),`,
1112
+ ` ipAddress: text("ip_address"),`,
1113
+ ` userAgent: text("user_agent"),`,
1114
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" })`,
1115
+ ` .notNull()`,
1116
+ ` .$defaultFn(() => new Date()),`,
1117
+ ` updatedAt: integer("updated_at", { mode: "timestamp_ms" })`,
1118
+ ` .notNull()`,
1119
+ ` .$defaultFn(() => new Date()),`,
1120
+ `}, (table) => [`,
1121
+ ` index("${resolveIndexName(auditLogTbl, "user_id")}").on(table.userId),`,
1122
+ ` index("${resolveIndexName(auditLogTbl, "action")}").on(table.action),`,
1123
+ ` index("${resolveIndexName(auditLogTbl, "target")}").on(table.targetType, table.targetId),`,
1124
+ ` index("${resolveIndexName(auditLogTbl, "created_at")}").on(table.createdAt),`,
1125
+ `]);`,
1126
+ `export const auditLog = auditLogs;`,
1127
+ `export { auditLogs as audit_logs };`
1128
+ );
1129
+ if (opts.twoFactor) {
1130
+ lines.push(
1131
+ ``,
1132
+ `// \u2500\u2500\u2500 6. Two-Factor Authentication Table (TOTP) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1133
+ `export const twoFactor = snakeCase.table("${twoFactorTbl}", {`,
1134
+ ` id: text("id").primaryKey(),`,
1135
+ ` userId: text("user_id").notNull().unique().references(() => user.id, { onDelete: "cascade" }),`,
1136
+ ` secret: text("secret").notNull(),`,
1137
+ ` backupCodes: text("backup_codes").notNull(),`,
1138
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1139
+ `});`
1140
+ );
1141
+ }
1142
+ if (opts.webauthn || opts.webAuthn) {
1143
+ lines.push(
1144
+ ``,
1145
+ `// \u2500\u2500\u2500 7. Passkeys Table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1146
+ `export const passkey = snakeCase.table("${passkeyTbl}", {`,
1147
+ ` id: text("id").primaryKey(),`,
1148
+ ` name: text("name"),`,
1149
+ ` publicKey: text("public_key").notNull(),`,
1150
+ ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
1151
+ ` credentialId: text("credential_id").notNull().unique(),`,
1152
+ ` counter: integer("counter").notNull().default(0),`,
1153
+ ` deviceType: text("device_type").notNull(),`,
1154
+ ` backedUp: integer("backed_up", { mode: "boolean" }).notNull().default(false),`,
1155
+ ` transports: text("transports"),`,
1156
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1157
+ `});`
1158
+ );
1159
+ }
1160
+ if (opts.organizations) {
1161
+ lines.push(
1162
+ ``,
1163
+ `// \u2500\u2500\u2500 8. Organizations & Members Tables \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1164
+ `export const organization = snakeCase.table("${organizationTbl}", {`,
1165
+ ` id: text("id").primaryKey(),`,
1166
+ ` name: text("name").notNull(),`,
1167
+ ` slug: text("slug").notNull().unique(),`,
1168
+ ` logo: text("logo"),`,
1169
+ ` metadata: text("metadata"),`,
1170
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1171
+ `});`,
1172
+ `export const organizations = organization;`,
1173
+ ``,
1174
+ `export const member = snakeCase.table("${memberTbl}", {`,
1175
+ ` id: text("id").primaryKey(),`,
1176
+ ` organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),`,
1177
+ ` userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
1178
+ ` role: text("role").notNull().default("member"),`,
1179
+ ` createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull().default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`),`,
1180
+ `});`,
1181
+ `export const members = member;`,
1182
+ ``,
1183
+ `export const invitation = snakeCase.table("${invitationTbl}", {`,
1184
+ ` id: text("id").primaryKey(),`,
1185
+ ` organizationId: text("organization_id").notNull().references(() => organization.id, { onDelete: "cascade" }),`,
1186
+ ` email: text("email").notNull(),`,
1187
+ ` role: text("role").notNull().default("member"),`,
1188
+ ` status: text("status").notNull().default("pending"),`,
1189
+ ` expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),`,
1190
+ ` inviterId: text("inviter_id").notNull().references(() => user.id, { onDelete: "cascade" }),`,
1191
+ `});`,
1192
+ `export const invitations = invitation;`
1193
+ );
1194
+ }
1195
+ if (!opts.twoFactor) {
1196
+ lines.push(`export const twoFactor = undefined;`);
1197
+ }
1198
+ if (!opts.webauthn && !opts.webAuthn) {
1199
+ lines.push(`export const passkey = undefined;`);
1200
+ lines.push(`export const authenticators = undefined;`);
1201
+ } else {
1202
+ lines.push(`export { passkey as authenticators };`);
1203
+ }
1204
+ if (!opts.organizations) {
1205
+ lines.push(
1206
+ `export const organization = undefined;`,
1207
+ `export const member = undefined;`,
1208
+ `export const invitation = undefined;`
1209
+ );
1210
+ }
1211
+ return lines.join("\n") + "\n";
1212
+ }
1213
+
1214
+ const authSchema = {
1215
+ __proto__: null,
1216
+ ALL_AUTH_TABLE_NAMES: ALL_AUTH_TABLE_NAMES,
1217
+ generateAuthSchema: generateAuthSchema,
1218
+ getActiveAuthTableNames: getActiveAuthTableNames
1219
+ };
1220
+
1221
+ const ALL_CMS_TABLE_NAMES = [
1222
+ "cms_collection",
1223
+ "cms_entry",
1224
+ "cms_revision",
1225
+ "cms_category",
1226
+ "cms_tag",
1227
+ "cms_bookmark",
1228
+ "cms_subscriber"
1229
+ ];
1230
+ function getActiveCmsTableNames(cms, prefixOrOptions) {
1231
+ if (!cms) return [];
1232
+ return [
1233
+ resolveTableName("cms_collection", prefixOrOptions),
1234
+ resolveTableName("cms_entry", prefixOrOptions),
1235
+ resolveTableName("cms_revision", prefixOrOptions),
1236
+ resolveTableName("cms_category", prefixOrOptions),
1237
+ resolveTableName("cms_tag", prefixOrOptions),
1238
+ resolveTableName("cms_bookmark", prefixOrOptions),
1239
+ resolveTableName("cms_subscriber", prefixOrOptions)
1240
+ ];
1241
+ }
1242
+ const collectionTbl = resolveTableName("cms_collection");
1243
+ const entryTbl = resolveTableName("cms_entry");
1244
+ const revisionTbl = resolveTableName("cms_revision");
1245
+ const categoryTbl = resolveTableName("cms_category");
1246
+ const tagTbl = resolveTableName("cms_tag");
1247
+ const bookmarkTbl = resolveTableName("cms_bookmark");
1248
+ const subscriberTbl = resolveTableName("cms_subscriber");
1249
+ const cmsCollection = snakeCase.table(collectionTbl, {
1250
+ id: text().primaryKey(),
1251
+ tenantId: text(),
1252
+ name: text().notNull(),
1253
+ description: text(),
1254
+ schemaJson: text().notNull().default("{}"),
1255
+ source: text().notNull().default("db"),
1256
+ order: integer().notNull().default(0),
1257
+ createdAt: integer().notNull(),
1258
+ updatedAt: integer().notNull()
1259
+ });
1260
+ const cmsCollections = cmsCollection;
1261
+ const cmsEntry = snakeCase.table(
1262
+ entryTbl,
1263
+ {
1264
+ id: text().primaryKey(),
1265
+ tenantId: text(),
1266
+ collectionId: text().notNull(),
1267
+ slug: text().notNull(),
1268
+ title: text().notNull(),
1269
+ description: text(),
1270
+ coverImage: text(),
1271
+ tags: text(),
1272
+ order: integer().notNull().default(0),
1273
+ contentMd: text().notNull().default(""),
1274
+ contentHtml: text().notNull().default(""),
1275
+ metadataJson: text().default("{}"),
1276
+ status: text().notNull().default("draft"),
1277
+ source: text().notNull().default("db"),
1278
+ path: text(),
1279
+ filePath: text(),
1280
+ contentHash: text(),
1281
+ authorId: text(),
1282
+ categoryId: text(),
1283
+ subCategoryId: text(),
1284
+ featured: integer({ mode: "boolean" }).notNull().default(false),
1285
+ viewCount: integer().notNull().default(0),
1286
+ readingTime: integer(),
1287
+ locale: text().notNull().default("en"),
1288
+ version: text().notNull().default("latest"),
1289
+ publishedAt: integer(),
1290
+ createdAt: integer().notNull(),
1291
+ updatedAt: integer().notNull()
1292
+ },
1293
+ (t) => [
1294
+ index(resolveIndexName(entryTbl, "collection")).on(t.collectionId),
1295
+ index(resolveIndexName(entryTbl, "tenant")).on(t.tenantId, t.collectionId),
1296
+ uniqueIndex(resolveIndexName(entryTbl, "slug")).on(t.collectionId, t.slug),
1297
+ index(resolveIndexName(entryTbl, "status")).on(t.status),
1298
+ index(resolveIndexName(entryTbl, "order")).on(t.collectionId, t.order),
1299
+ index(resolveIndexName(entryTbl, "path")).on(t.collectionId, t.path),
1300
+ index(resolveIndexName(entryTbl, "locale")).on(t.collectionId, t.locale),
1301
+ index(resolveIndexName(entryTbl, "path_locale")).on(t.path, t.locale),
1302
+ index(resolveIndexName(entryTbl, "category")).on(t.collectionId, t.categoryId),
1303
+ index(resolveIndexName(entryTbl, "featured")).on(t.collectionId, t.featured),
1304
+ index(resolveIndexName(entryTbl, "published_at")).on(t.publishedAt),
1305
+ index(resolveIndexName(entryTbl, "list")).on(t.collectionId, t.status, t.publishedAt)
1306
+ ]
1307
+ );
1308
+ const cmsEntries = cmsEntry;
1309
+ const cmsRevision = snakeCase.table(
1310
+ revisionTbl,
1311
+ {
1312
+ id: text().primaryKey(),
1313
+ entryId: text().notNull(),
1314
+ title: text().notNull(),
1315
+ contentMd: text().notNull(),
1316
+ metadataJson: text().default("{}"),
1317
+ authorId: text(),
1318
+ createdAt: integer().notNull()
1319
+ },
1320
+ (t) => [index(resolveIndexName(revisionTbl, "entry")).on(t.entryId, t.createdAt)]
1321
+ );
1322
+ const cmsRevisions = cmsRevision;
1323
+ const cmsCategory = snakeCase.table(
1324
+ categoryTbl,
1325
+ {
1326
+ id: text().primaryKey(),
1327
+ tenantId: text(),
1328
+ name: text().notNull(),
1329
+ slug: text().notNull(),
1330
+ description: text(),
1331
+ icon: text(),
1332
+ parentId: text(),
1333
+ order: integer().notNull().default(0),
1334
+ metadataJson: text().default("{}"),
1335
+ createdAt: integer().notNull(),
1336
+ updatedAt: integer().notNull()
1337
+ },
1338
+ (t) => [
1339
+ uniqueIndex(resolveIndexName(categoryTbl, "slug")).on(t.tenantId, t.slug),
1340
+ index(resolveIndexName(categoryTbl, "parent")).on(t.parentId),
1341
+ index(resolveIndexName(categoryTbl, "tenant")).on(t.tenantId)
1342
+ ]
1343
+ );
1344
+ const cmsCategories = cmsCategory;
1345
+ const cmsTag = snakeCase.table(
1346
+ tagTbl,
1347
+ {
1348
+ id: text().primaryKey(),
1349
+ tenantId: text(),
1350
+ name: text().notNull(),
1351
+ slug: text().notNull(),
1352
+ description: text(),
1353
+ count: integer().notNull().default(0),
1354
+ metadataJson: text().default("{}"),
1355
+ createdAt: integer().notNull(),
1356
+ updatedAt: integer().notNull()
1357
+ },
1358
+ (t) => [
1359
+ uniqueIndex(resolveIndexName(tagTbl, "slug")).on(t.tenantId, t.slug),
1360
+ index(resolveIndexName(tagTbl, "tenant")).on(t.tenantId)
1361
+ ]
1362
+ );
1363
+ const cmsTags = cmsTag;
1364
+ const cmsBookmark = snakeCase.table(
1365
+ bookmarkTbl,
1366
+ {
1367
+ id: text().primaryKey(),
1368
+ tenantId: text(),
1369
+ userId: text().notNull(),
1370
+ entryId: text().notNull(),
1371
+ createdAt: integer().notNull()
1372
+ },
1373
+ (t) => [
1374
+ index(resolveIndexName(bookmarkTbl, "user")).on(t.userId),
1375
+ index(resolveIndexName(bookmarkTbl, "entry")).on(t.entryId),
1376
+ uniqueIndex(resolveIndexName(bookmarkTbl, "unique")).on(t.tenantId, t.userId, t.entryId)
1377
+ ]
1378
+ );
1379
+ const cmsBookmarks = cmsBookmark;
1380
+ const cmsSubscriber = snakeCase.table(
1381
+ subscriberTbl,
1382
+ {
1383
+ id: text().primaryKey(),
1384
+ tenantId: text(),
1385
+ email: text().notNull(),
1386
+ status: text().notNull().default("active"),
1387
+ source: text().default("website"),
1388
+ createdAt: integer().notNull()
1389
+ },
1390
+ (t) => [
1391
+ uniqueIndex(resolveIndexName(subscriberTbl, "unique_email")).on(t.tenantId, t.email),
1392
+ index(resolveIndexName(subscriberTbl, "status")).on(t.status),
1393
+ index(resolveIndexName(subscriberTbl, "tenant")).on(t.tenantId)
1394
+ ]
1395
+ );
1396
+ const cmsSubscribers = cmsSubscriber;
1397
+
1398
+ const ALL_STORE_TABLE_NAMES = [
1399
+ "store_product",
1400
+ "store_product_variant",
1401
+ "store_inventory",
1402
+ "store_category",
1403
+ "store_cart",
1404
+ "store_cart_item",
1405
+ "store_order",
1406
+ "store_order_item",
1407
+ "store_discount",
1408
+ "store_customer_address"
1409
+ ];
1410
+ function getActiveStoreTableNames(store, prefixOrOptions) {
1411
+ if (!store) return [];
1412
+ const resolvedPrefix = prefixOrOptions !== void 0 ? prefixOrOptions : typeof store === "object" && store.tablePrefix !== void 0 ? store.tablePrefix : void 0;
1413
+ return ALL_STORE_TABLE_NAMES.map((name) => resolveTableName(name, resolvedPrefix));
1414
+ }
1415
+ function generateStoreSchema(store, prefixOrOptions) {
1416
+ if (!store) {
1417
+ return "// Qarpeo Store App is disabled\nexport default {};\n";
1418
+ }
1419
+ const resolvedPrefix = prefixOrOptions !== void 0 ? prefixOrOptions : typeof store === "object" && store.tablePrefix !== void 0 ? store.tablePrefix : void 0;
1420
+ const productTbl = resolveTableName("store_product", resolvedPrefix);
1421
+ const variantTbl = resolveTableName("store_product_variant", resolvedPrefix);
1422
+ const inventoryTbl = resolveTableName("store_inventory", resolvedPrefix);
1423
+ const categoryTbl = resolveTableName("store_category", resolvedPrefix);
1424
+ const cartTbl = resolveTableName("store_cart", resolvedPrefix);
1425
+ const cartItemTbl = resolveTableName("store_cart_item", resolvedPrefix);
1426
+ const orderTbl = resolveTableName("store_order", resolvedPrefix);
1427
+ const orderItemTbl = resolveTableName("store_order_item", resolvedPrefix);
1428
+ const discountTbl = resolveTableName("store_discount", resolvedPrefix);
1429
+ const addressTbl = resolveTableName("store_customer_address", resolvedPrefix);
1430
+ const lines = [
1431
+ `// Auto-generated by qarpeo \u2014 Edge-Native Store App Engine`,
1432
+ `// snakeCase.table maps camelCase property names -> snake_case column names automatically`,
1433
+ `import { integer, real, text, index, uniqueIndex, snakeCase } from "drizzle-orm/sqlite-core";`,
1434
+ ``,
1435
+ `// \u2500\u2500\u2500 1. Products \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1436
+ `export const storeProduct = snakeCase.table("${productTbl}", {`,
1437
+ ` id: text().primaryKey(),`,
1438
+ ` tenantId: text(),`,
1439
+ ` vendorId: text(),`,
1440
+ ` slug: text().notNull(),`,
1441
+ ` title: text().notNull(),`,
1442
+ ` description: text(),`,
1443
+ ` status: text().notNull().default("draft"),`,
1444
+ ` type: text().notNull().default("physical"),`,
1445
+ ` basePrice: integer().notNull(),`,
1446
+ ` currency: text().notNull().default("USD"),`,
1447
+ ` categoryId: text(),`,
1448
+ ` imagesJson: text().notNull().default("[]"),`,
1449
+ ` metadataJson: text().notNull().default("{}"),`,
1450
+ ` createdAt: integer().notNull(),`,
1451
+ ` updatedAt: integer().notNull(),`,
1452
+ `}, (t) => [`,
1453
+ ` uniqueIndex("${resolveIndexName(productTbl, "unique_slug")}").on(t.tenantId, t.slug),`,
1454
+ ` index("${resolveIndexName(productTbl, "status")}").on(t.status),`,
1455
+ ` index("${resolveIndexName(productTbl, "category")}").on(t.categoryId),`,
1456
+ ` index("${resolveIndexName(productTbl, "tenant")}").on(t.tenantId),`,
1457
+ ` index("${resolveIndexName(productTbl, "vendor")}").on(t.vendorId),`,
1458
+ `]);`,
1459
+ ``,
1460
+ `// \u2500\u2500\u2500 2. Product Variants \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1461
+ `export const storeProductVariant = snakeCase.table("${variantTbl}", {`,
1462
+ ` id: text().primaryKey(),`,
1463
+ ` productId: text().notNull(),`,
1464
+ ` sku: text().notNull(),`,
1465
+ ` title: text().notNull(),`,
1466
+ ` optionsJson: text().notNull().default("{}"),`,
1467
+ ` priceOverride: integer(),`,
1468
+ ` weight: real(),`,
1469
+ ` barcode: text(),`,
1470
+ ` image: text(),`,
1471
+ ` createdAt: integer().notNull(),`,
1472
+ ` updatedAt: integer().notNull(),`,
1473
+ `}, (t) => [`,
1474
+ ` index("${resolveIndexName(variantTbl, "product")}").on(t.productId),`,
1475
+ ` index("${resolveIndexName(variantTbl, "sku")}").on(t.sku),`,
1476
+ `]);`,
1477
+ ``,
1478
+ `// \u2500\u2500\u2500 3. Inventory \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1479
+ `export const storeInventory = snakeCase.table("${inventoryTbl}", {`,
1480
+ ` id: text().primaryKey(),`,
1481
+ ` variantId: text().notNull(),`,
1482
+ ` productId: text().notNull(),`,
1483
+ ` stockQuantity: integer().notNull().default(0),`,
1484
+ ` reservedQuantity: integer().notNull().default(0),`,
1485
+ ` allowBackorder: integer().notNull().default(0),`,
1486
+ ` lowStockThreshold: integer().notNull().default(5),`,
1487
+ ` createdAt: integer().notNull(),`,
1488
+ ` updatedAt: integer().notNull(),`,
1489
+ `}, (t) => [`,
1490
+ ` uniqueIndex("${resolveIndexName(inventoryTbl, "variant")}").on(t.variantId),`,
1491
+ ` index("${resolveIndexName(inventoryTbl, "product")}").on(t.productId),`,
1492
+ `]);`,
1493
+ ``,
1494
+ `// \u2500\u2500\u2500 4. Categories \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1495
+ `export const storeCategory = snakeCase.table("${categoryTbl}", {`,
1496
+ ` id: text().primaryKey(),`,
1497
+ ` tenantId: text(),`,
1498
+ ` slug: text().notNull(),`,
1499
+ ` name: text().notNull(),`,
1500
+ ` description: text(),`,
1501
+ ` image: text(),`,
1502
+ ` parentId: text(),`,
1503
+ ` order: integer().notNull().default(0),`,
1504
+ ` metadataJson: text().notNull().default("{}"),`,
1505
+ ` createdAt: integer().notNull(),`,
1506
+ ` updatedAt: integer().notNull(),`,
1507
+ `}, (t) => [`,
1508
+ ` uniqueIndex("${resolveIndexName(categoryTbl, "unique_slug")}").on(t.tenantId, t.slug),`,
1509
+ ` index("${resolveIndexName(categoryTbl, "parent")}").on(t.parentId),`,
1510
+ ` index("${resolveIndexName(categoryTbl, "tenant")}").on(t.tenantId),`,
1511
+ `]);`,
1512
+ ``,
1513
+ `// \u2500\u2500\u2500 5. Carts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1514
+ `export const storeCart = snakeCase.table("${cartTbl}", {`,
1515
+ ` id: text().primaryKey(),`,
1516
+ ` tenantId: text(),`,
1517
+ ` userId: text(),`,
1518
+ ` sessionToken: text().notNull(),`,
1519
+ ` currency: text().notNull().default("USD"),`,
1520
+ ` couponCode: text(),`,
1521
+ ` metadataJson: text().notNull().default("{}"),`,
1522
+ ` expiresAt: integer().notNull(),`,
1523
+ ` createdAt: integer().notNull(),`,
1524
+ ` updatedAt: integer().notNull(),`,
1525
+ `}, (t) => [`,
1526
+ ` uniqueIndex("${resolveIndexName(cartTbl, "session")}").on(t.sessionToken),`,
1527
+ ` index("${resolveIndexName(cartTbl, "user")}").on(t.userId),`,
1528
+ ` index("${resolveIndexName(cartTbl, "expires")}").on(t.expiresAt),`,
1529
+ `]);`,
1530
+ ``,
1531
+ `// \u2500\u2500\u2500 6. Cart Items \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1532
+ `export const storeCartItem = snakeCase.table("${cartItemTbl}", {`,
1533
+ ` id: text().primaryKey(),`,
1534
+ ` cartId: text().notNull(),`,
1535
+ ` productId: text().notNull(),`,
1536
+ ` variantId: text().notNull(),`,
1537
+ ` quantity: integer().notNull().default(1),`,
1538
+ ` customAttributesJson: text().notNull().default("{}"),`,
1539
+ ` createdAt: integer().notNull(),`,
1540
+ ` updatedAt: integer().notNull(),`,
1541
+ `}, (t) => [`,
1542
+ ` index("${resolveIndexName(cartItemTbl, "cart")}").on(t.cartId),`,
1543
+ ` index("${resolveIndexName(cartItemTbl, "variant")}").on(t.variantId),`,
1544
+ `]);`,
1545
+ ``,
1546
+ `// \u2500\u2500\u2500 7. Orders \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1547
+ `export const storeOrder = snakeCase.table("${orderTbl}", {`,
1548
+ ` id: text().primaryKey(),`,
1549
+ ` tenantId: text(),`,
1550
+ ` orderNumber: text().notNull(),`,
1551
+ ` userId: text(),`,
1552
+ ` customerEmail: text().notNull(),`,
1553
+ ` customerName: text(),`,
1554
+ ` status: text().notNull().default("pending"),`,
1555
+ ` currency: text().notNull().default("USD"),`,
1556
+ ` subtotal: integer().notNull(),`,
1557
+ ` taxTotal: integer().notNull().default(0),`,
1558
+ ` shippingTotal: integer().notNull().default(0),`,
1559
+ ` discountTotal: integer().notNull().default(0),`,
1560
+ ` total: integer().notNull(),`,
1561
+ ` paymentProvider: text(),`,
1562
+ ` paymentIntentId: text(),`,
1563
+ ` shippingAddressJson: text().notNull().default("{}"),`,
1564
+ ` billingAddressJson: text().notNull().default("{}"),`,
1565
+ ` metadataJson: text().notNull().default("{}"),`,
1566
+ ` paidAt: integer(),`,
1567
+ ` shippedAt: integer(),`,
1568
+ ` deliveredAt: integer(),`,
1569
+ ` cancelledAt: integer(),`,
1570
+ ` refundedAt: integer(),`,
1571
+ ` createdAt: integer().notNull(),`,
1572
+ ` updatedAt: integer().notNull(),`,
1573
+ `}, (t) => [`,
1574
+ ` uniqueIndex("${resolveIndexName(orderTbl, "unique_number")}").on(t.tenantId, t.orderNumber),`,
1575
+ ` index("${resolveIndexName(orderTbl, "user")}").on(t.userId),`,
1576
+ ` index("${resolveIndexName(orderTbl, "email")}").on(t.customerEmail),`,
1577
+ ` index("${resolveIndexName(orderTbl, "status")}").on(t.status),`,
1578
+ ` index("${resolveIndexName(orderTbl, "created")}").on(t.createdAt),`,
1579
+ `]);`,
1580
+ ``,
1581
+ `// \u2500\u2500\u2500 8. Order Items \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1582
+ `export const storeOrderItem = snakeCase.table("${orderItemTbl}", {`,
1583
+ ` id: text().primaryKey(),`,
1584
+ ` orderId: text().notNull(),`,
1585
+ ` productId: text().notNull(),`,
1586
+ ` variantId: text().notNull(),`,
1587
+ ` vendorId: text(),`,
1588
+ ` sku: text().notNull(),`,
1589
+ ` title: text().notNull(),`,
1590
+ ` unitPrice: integer().notNull(),`,
1591
+ ` quantity: integer().notNull().default(1),`,
1592
+ ` totalPrice: integer().notNull(),`,
1593
+ ` isDigital: integer().notNull().default(0),`,
1594
+ ` downloadKey: text(),`,
1595
+ ` metadataJson: text().notNull().default("{}"),`,
1596
+ ` createdAt: integer().notNull(),`,
1597
+ `}, (t) => [`,
1598
+ ` index("${resolveIndexName(orderItemTbl, "order")}").on(t.orderId),`,
1599
+ ` index("${resolveIndexName(orderItemTbl, "variant")}").on(t.variantId),`,
1600
+ ` index("${resolveIndexName(orderItemTbl, "vendor")}").on(t.vendorId),`,
1601
+ `]);`,
1602
+ ``,
1603
+ `// \u2500\u2500\u2500 9. Discounts / Coupons \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1604
+ `export const storeDiscount = snakeCase.table("${discountTbl}", {`,
1605
+ ` id: text().primaryKey(),`,
1606
+ ` tenantId: text(),`,
1607
+ ` code: text().notNull(),`,
1608
+ ` type: text().notNull().default("percentage"),`,
1609
+ ` value: integer().notNull(),`,
1610
+ ` minOrderAmount: integer().notNull().default(0),`,
1611
+ ` maxUses: integer(),`,
1612
+ ` usedCount: integer().notNull().default(0),`,
1613
+ ` startsAt: integer(),`,
1614
+ ` expiresAt: integer(),`,
1615
+ ` isActive: integer().notNull().default(1),`,
1616
+ ` metadataJson: text().notNull().default("{}"),`,
1617
+ ` createdAt: integer().notNull(),`,
1618
+ ` updatedAt: integer().notNull(),`,
1619
+ `}, (t) => [`,
1620
+ ` uniqueIndex("${resolveIndexName(discountTbl, "unique_code")}").on(t.tenantId, t.code),`,
1621
+ ` index("${resolveIndexName(discountTbl, "active")}").on(t.isActive),`,
1622
+ `]);`,
1623
+ ``,
1624
+ `// \u2500\u2500\u2500 10. Customer Addresses \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1625
+ `export const storeCustomerAddress = snakeCase.table("${addressTbl}", {`,
1626
+ ` id: text().primaryKey(),`,
1627
+ ` userId: text().notNull(),`,
1628
+ ` type: text().notNull().default("shipping"),`,
1629
+ ` name: text().notNull(),`,
1630
+ ` company: text(),`,
1631
+ ` line1: text().notNull(),`,
1632
+ ` line2: text(),`,
1633
+ ` city: text().notNull(),`,
1634
+ ` state: text(),`,
1635
+ ` postalCode: text().notNull(),`,
1636
+ ` country: text().notNull(),`,
1637
+ ` phone: text(),`,
1638
+ ` isDefault: integer().notNull().default(0),`,
1639
+ ` createdAt: integer().notNull(),`,
1640
+ ` updatedAt: integer().notNull(),`,
1641
+ `}, (t) => [`,
1642
+ ` index("${resolveIndexName(addressTbl, "user")}").on(t.userId),`,
1643
+ ` index("${resolveIndexName(addressTbl, "type")}").on(t.type),`,
1644
+ `]);`,
1645
+ ``,
1646
+ `// Backward-compatibility / plural aliases`,
1647
+ `export const storeProducts = storeProduct;`,
1648
+ `export const storeProductVariants = storeProductVariant;`,
1649
+ `export const storeInventories = storeInventory;`,
1650
+ `export const storeCategories = storeCategory;`,
1651
+ `export const storeCarts = storeCart;`,
1652
+ `export const storeCartItems = storeCartItem;`,
1653
+ `export const storeOrders = storeOrder;`,
1654
+ `export const storeOrderItems = storeOrderItem;`,
1655
+ `export const storeDiscounts = storeDiscount;`,
1656
+ `export const storeCustomerAddresses = storeCustomerAddress;`
1657
+ ];
1658
+ return lines.join("\n");
1659
+ }
1660
+
1661
+ const ALL_COMMENTS_TABLE_NAMES = [
1662
+ "comment",
1663
+ "comment_report",
1664
+ "comment_reaction"
1665
+ ];
1666
+ function getActiveCommentsTableNames(comments, prefixOrOptions) {
1667
+ if (!comments) return [];
1668
+ const resolvedPrefix = prefixOrOptions !== void 0 ? prefixOrOptions : typeof comments === "object" && comments.tablePrefix !== void 0 ? comments.tablePrefix : void 0;
1669
+ return [
1670
+ resolveTableName("comment", resolvedPrefix),
1671
+ resolveTableName("comment_report", resolvedPrefix),
1672
+ resolveTableName("comment_reaction", resolvedPrefix)
1673
+ ];
1674
+ }
1675
+ function generateCommentsSchema(comments, prefixOrOptions) {
1676
+ if (!comments) {
1677
+ return "// Qarpeo Comments is disabled\nexport default {};\n";
1678
+ }
1679
+ const resolvedPrefix = prefixOrOptions !== void 0 ? prefixOrOptions : typeof comments === "object" && comments.tablePrefix !== void 0 ? comments.tablePrefix : void 0;
1680
+ const commentTbl = resolveTableName("comment", resolvedPrefix);
1681
+ const reportTbl = resolveTableName("comment_report", resolvedPrefix);
1682
+ const reactionTbl = resolveTableName("comment_reaction", resolvedPrefix);
1683
+ const lines = [
1684
+ `// Auto-generated by qarpeo \u2014 Threaded Comments System`,
1685
+ `// snakeCase.table maps camelCase property names \u2192 snake_case column names automatically`,
1686
+ `import { integer, text, index, uniqueIndex, snakeCase } from "drizzle-orm/sqlite-core";`,
1687
+ ``,
1688
+ `// \u2500\u2500\u2500 1. Comments \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1689
+ `export const comment = snakeCase.table("${commentTbl}", {`,
1690
+ ` id: text().primaryKey(),`,
1691
+ ` /** Universal Resource Name of the target entity, e.g. "urn:cms:blog:abc123" */`,
1692
+ ` targetUrn: text().notNull(),`,
1693
+ ` tenantId: text(),`,
1694
+ ` /** Parent comment ID; null for root-level comments */`,
1695
+ ` parentId: text(),`,
1696
+ ` /** Materialized path for fast subtree queries, e.g. "/0001/0002/" */`,
1697
+ ` path: text().notNull().default("/"),`,
1698
+ ` depth: integer().notNull().default(0),`,
1699
+ ` /** Authenticated author user ID; null for anonymous guest comments */`,
1700
+ ` authorId: text(),`,
1701
+ ` authorName: text().notNull(),`,
1702
+ ` authorEmail: text(),`,
1703
+ ` /** Deterministic inline SVG data-URI avatar \u2014 no external CDN calls */`,
1704
+ ` authorAvatar: text(),`,
1705
+ ` /** Anonymous author IP; never exposed in public API responses */`,
1706
+ ` authorIp: text(),`,
1707
+ ` content: text().notNull(),`,
1708
+ ` /** pending | approved | spam | deleted */`,
1709
+ ` status: text().notNull().default("pending"),`,
1710
+ ` /** Unix ms timestamp; non-null means the comment is tombstoned */`,
1711
+ ` deletedAt: integer(),`,
1712
+ ` reportCount: integer().notNull().default(0),`,
1713
+ ` /** JSON map of reaction type \u2192 count, e.g. {"like":3,"heart":1} */`,
1714
+ ` reactionCounts: text().notNull().default("{}"),`,
1715
+ ` metadataJson: text().notNull().default("{}"),`,
1716
+ ` createdAt: integer().notNull(),`,
1717
+ ` updatedAt: integer().notNull(),`,
1718
+ `}, (t) => [`,
1719
+ ` index("${resolveIndexName(commentTbl, "target")}").on(t.targetUrn, t.status, t.createdAt),`,
1720
+ ` index("${resolveIndexName(commentTbl, "parent")}").on(t.parentId),`,
1721
+ ` index("${resolveIndexName(commentTbl, "path")}").on(t.path),`,
1722
+ ` index("${resolveIndexName(commentTbl, "tenant")}").on(t.tenantId),`,
1723
+ ` index("${resolveIndexName(commentTbl, "author")}").on(t.authorId),`,
1724
+ `]);`,
1725
+ ``,
1726
+ `// Backward-compatibility alias`,
1727
+ `export const qarpeoComments = comment;`,
1728
+ ``,
1729
+ `// \u2500\u2500\u2500 2. Community Reports \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1730
+ `export const commentReport = snakeCase.table("${reportTbl}", {`,
1731
+ ` id: text().primaryKey(),`,
1732
+ ` commentId: text().notNull(),`,
1733
+ ` reporterIp: text(),`,
1734
+ ` reporterUserId: text(),`,
1735
+ ` /** spam | harassment | off-topic | misinformation | other */`,
1736
+ ` reason: text().notNull(),`,
1737
+ ` note: text(),`,
1738
+ ` createdAt: integer().notNull(),`,
1739
+ `}, (t) => [`,
1740
+ ` index("${resolveIndexName(reportTbl, "comment")}").on(t.commentId),`,
1741
+ `]);`,
1742
+ ``,
1743
+ `// Backward-compatibility alias`,
1744
+ `export const qarpeoCommentReports = commentReport;`,
1745
+ ``,
1746
+ `// \u2500\u2500\u2500 3. Comment Reactions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`,
1747
+ `export const commentReaction = snakeCase.table("${reactionTbl}", {`,
1748
+ ` id: text().primaryKey(),`,
1749
+ ` commentId: text().notNull(),`,
1750
+ ` /** Authenticated user ID; null for anonymous reactions (keyed by IP) */`,
1751
+ ` userId: text(),`,
1752
+ ` ip: text(),`,
1753
+ ` /** like | heart | fire | unicorn \u2014 or any string from CommentsOptions.reactions */`,
1754
+ ` reaction: text().notNull(),`,
1755
+ ` createdAt: integer().notNull(),`,
1756
+ `}, (t) => [`,
1757
+ ` index("${resolveIndexName(reactionTbl, "comment")}").on(t.commentId),`,
1758
+ ` uniqueIndex("${resolveIndexName(reactionTbl, "unique_user")}").on(t.commentId, t.userId, t.reaction),`,
1759
+ `]);`,
1760
+ ``,
1761
+ `// Backward-compatibility alias`,
1762
+ `export const qarpeoCommentReactions = commentReaction;`
1763
+ ];
1764
+ return lines.join("\n") + "\n";
1765
+ }
1766
+
805
1767
  function findJobFiles(layers, dirName = "server/jobs") {
806
1768
  const jobsMap = /* @__PURE__ */ new Map();
807
1769
  for (const layer of layers) {
@@ -1677,4 +2639,4 @@ function findToolFiles(layers, customDir) {
1677
2639
  return Array.from(toolsMap.values());
1678
2640
  }
1679
2641
 
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 };
2642
+ export { ALL_CMS_TABLE_NAMES as A, generateAuthSchema as B, generateCommentsSchema as C, generateStoreSchema as D, findScheduledTasks as E, formatDlxCommand as F, resolveBindingName as G, createWranglerConfig as H, generateDevWranglerConfig as I, applyD1Migrations as J, findQueueFiles as K, findDurableObjectFiles as L, cmsBookmarks as M, cmsCategories as N, cmsCollections as O, cmsEntries as P, cmsRevisions as Q, cmsSubscribers as R, cmsTags as S, getActiveCmsTableNames as T, getActiveCommentsTableNames as U, getActiveStoreTableNames as V, hasDatabaseSchema as W, localDb as X, authSchema as Y, wrangler as Z, resolveBinaryPath as a, getActiveAuthTableNames as b, ALL_STORE_TABLE_NAMES as c, ALL_COMMENTS_TABLE_NAMES as d, ensurePackage as e, discoverDatabases as f, getLocalDatabaseContext as g, findLocalD1Database as h, spawnBinSync as i, getJiti as j, resolveProjectName as k, checkDrizzleVersion as l, findSchemaFiles as m, findAgentFiles as n, findToolFiles as o, findBotFiles as p, findMcpFiles as q, resolveDatabaseTarget as r, scanSchemaExports as s, findJobFiles as t, findWorkflowFiles as u, findEmailHandlerFiles as v, version as w, resolveTableName as x, resolveIndexName as y, buildDevWranglerConfig as z };