@btst/stack 2.1.0 → 2.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 (229) hide show
  1. package/dist/api/index.cjs +9 -1
  2. package/dist/api/index.d.cts +4 -4
  3. package/dist/api/index.d.mts +4 -4
  4. package/dist/api/index.d.ts +4 -4
  5. package/dist/api/index.mjs +9 -1
  6. package/dist/client/index.d.cts +2 -2
  7. package/dist/client/index.d.mts +2 -2
  8. package/dist/client/index.d.ts +2 -2
  9. package/dist/index.d.cts +1 -1
  10. package/dist/index.d.mts +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/packages/stack/src/plugins/ai-chat/api/getters.cjs +42 -0
  13. package/dist/packages/stack/src/plugins/ai-chat/api/getters.mjs +39 -0
  14. package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +5 -0
  15. package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +5 -0
  16. package/dist/packages/stack/src/plugins/blog/api/getters.cjs +131 -0
  17. package/dist/packages/stack/src/plugins/blog/api/getters.mjs +127 -0
  18. package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +60 -107
  19. package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +60 -107
  20. package/dist/packages/stack/src/plugins/blog/api/query-key-defs.cjs +18 -0
  21. package/dist/packages/stack/src/plugins/blog/api/query-key-defs.mjs +15 -0
  22. package/dist/packages/stack/src/plugins/blog/api/serializers.cjs +21 -0
  23. package/dist/packages/stack/src/plugins/blog/api/serializers.mjs +18 -0
  24. package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +16 -1
  25. package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +17 -2
  26. package/dist/packages/stack/src/plugins/cms/api/getters.cjs +156 -0
  27. package/dist/packages/stack/src/plugins/cms/api/getters.mjs +147 -0
  28. package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +624 -617
  29. package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +623 -616
  30. package/dist/packages/stack/src/plugins/cms/api/query-key-defs.cjs +29 -0
  31. package/dist/packages/stack/src/plugins/cms/api/query-key-defs.mjs +26 -0
  32. package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +1 -1
  33. package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +1 -1
  34. package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.cjs +6 -3
  35. package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.mjs +6 -3
  36. package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +15 -0
  37. package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +16 -1
  38. package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +120 -0
  39. package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +112 -0
  40. package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +75 -86
  41. package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +71 -82
  42. package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.cjs +37 -0
  43. package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.mjs +33 -0
  44. package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +1 -1
  45. package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +1 -1
  46. package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +15 -0
  47. package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +16 -1
  48. package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +84 -0
  49. package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +81 -0
  50. package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +37 -123
  51. package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +37 -123
  52. package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.cjs +26 -0
  53. package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.mjs +23 -0
  54. package/dist/packages/stack/src/plugins/kanban/api/serializers.cjs +30 -0
  55. package/dist/packages/stack/src/plugins/kanban/api/serializers.mjs +26 -0
  56. package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +11 -1
  57. package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +12 -2
  58. package/dist/packages/stack/src/plugins/utils.cjs +6 -0
  59. package/dist/packages/stack/src/plugins/utils.mjs +6 -1
  60. package/dist/plugins/ai-chat/api/index.cjs +3 -0
  61. package/dist/plugins/ai-chat/api/index.d.cts +27 -4
  62. package/dist/plugins/ai-chat/api/index.d.mts +27 -4
  63. package/dist/plugins/ai-chat/api/index.d.ts +27 -4
  64. package/dist/plugins/ai-chat/api/index.mjs +1 -0
  65. package/dist/plugins/ai-chat/client/hooks/index.d.cts +2 -2
  66. package/dist/plugins/ai-chat/client/hooks/index.d.mts +2 -2
  67. package/dist/plugins/ai-chat/client/hooks/index.d.ts +2 -2
  68. package/dist/plugins/ai-chat/query-keys.d.cts +9 -284
  69. package/dist/plugins/ai-chat/query-keys.d.mts +9 -284
  70. package/dist/plugins/ai-chat/query-keys.d.ts +9 -284
  71. package/dist/plugins/api/index.d.cts +4 -3
  72. package/dist/plugins/api/index.d.mts +4 -3
  73. package/dist/plugins/api/index.d.ts +4 -3
  74. package/dist/plugins/blog/api/index.cjs +9 -0
  75. package/dist/plugins/blog/api/index.d.cts +20 -4
  76. package/dist/plugins/blog/api/index.d.mts +20 -4
  77. package/dist/plugins/blog/api/index.d.ts +20 -4
  78. package/dist/plugins/blog/api/index.mjs +3 -0
  79. package/dist/plugins/blog/client/hooks/index.d.cts +5 -5
  80. package/dist/plugins/blog/client/hooks/index.d.mts +5 -5
  81. package/dist/plugins/blog/client/hooks/index.d.ts +5 -5
  82. package/dist/plugins/blog/client/index.d.cts +1 -1
  83. package/dist/plugins/blog/client/index.d.mts +1 -1
  84. package/dist/plugins/blog/client/index.d.ts +1 -1
  85. package/dist/plugins/blog/query-keys.cjs +13 -9
  86. package/dist/plugins/blog/query-keys.d.cts +8 -333
  87. package/dist/plugins/blog/query-keys.d.mts +8 -333
  88. package/dist/plugins/blog/query-keys.d.ts +8 -333
  89. package/dist/plugins/blog/query-keys.mjs +13 -9
  90. package/dist/plugins/client/index.cjs +1 -0
  91. package/dist/plugins/client/index.d.cts +10 -3
  92. package/dist/plugins/client/index.d.mts +10 -3
  93. package/dist/plugins/client/index.d.ts +10 -3
  94. package/dist/plugins/client/index.mjs +1 -1
  95. package/dist/plugins/cms/api/index.cjs +10 -0
  96. package/dist/plugins/cms/api/index.d.cts +7 -163
  97. package/dist/plugins/cms/api/index.d.mts +7 -163
  98. package/dist/plugins/cms/api/index.d.ts +7 -163
  99. package/dist/plugins/cms/api/index.mjs +2 -0
  100. package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
  101. package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
  102. package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
  103. package/dist/plugins/cms/query-keys.cjs +2 -1
  104. package/dist/plugins/cms/query-keys.d.cts +6 -9
  105. package/dist/plugins/cms/query-keys.d.mts +6 -9
  106. package/dist/plugins/cms/query-keys.d.ts +6 -9
  107. package/dist/plugins/cms/query-keys.mjs +2 -1
  108. package/dist/plugins/form-builder/api/index.cjs +10 -0
  109. package/dist/plugins/form-builder/api/index.d.cts +7 -141
  110. package/dist/plugins/form-builder/api/index.d.mts +7 -141
  111. package/dist/plugins/form-builder/api/index.d.ts +7 -141
  112. package/dist/plugins/form-builder/api/index.mjs +2 -0
  113. package/dist/plugins/form-builder/client/components/index.d.cts +1 -1
  114. package/dist/plugins/form-builder/client/components/index.d.mts +1 -1
  115. package/dist/plugins/form-builder/client/components/index.d.ts +1 -1
  116. package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
  117. package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
  118. package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
  119. package/dist/plugins/form-builder/query-keys.cjs +3 -2
  120. package/dist/plugins/form-builder/query-keys.d.cts +7 -6
  121. package/dist/plugins/form-builder/query-keys.d.mts +7 -6
  122. package/dist/plugins/form-builder/query-keys.d.ts +7 -6
  123. package/dist/plugins/form-builder/query-keys.mjs +3 -2
  124. package/dist/plugins/kanban/api/index.cjs +9 -0
  125. package/dist/plugins/kanban/api/index.d.cts +17 -395
  126. package/dist/plugins/kanban/api/index.d.mts +17 -395
  127. package/dist/plugins/kanban/api/index.d.ts +17 -395
  128. package/dist/plugins/kanban/api/index.mjs +3 -0
  129. package/dist/plugins/kanban/client/components/index.d.cts +1 -1
  130. package/dist/plugins/kanban/client/components/index.d.mts +1 -1
  131. package/dist/plugins/kanban/client/components/index.d.ts +1 -1
  132. package/dist/plugins/kanban/client/hooks/index.d.cts +1 -1
  133. package/dist/plugins/kanban/client/hooks/index.d.mts +1 -1
  134. package/dist/plugins/kanban/client/hooks/index.d.ts +1 -1
  135. package/dist/plugins/kanban/client/index.d.cts +1 -1
  136. package/dist/plugins/kanban/client/index.d.mts +1 -1
  137. package/dist/plugins/kanban/client/index.d.ts +1 -1
  138. package/dist/plugins/kanban/query-keys.cjs +6 -12
  139. package/dist/plugins/kanban/query-keys.d.cts +5 -16
  140. package/dist/plugins/kanban/query-keys.d.mts +5 -16
  141. package/dist/plugins/kanban/query-keys.d.ts +5 -16
  142. package/dist/plugins/kanban/query-keys.mjs +6 -12
  143. package/dist/plugins/open-api/api/index.d.cts +2 -2
  144. package/dist/plugins/open-api/api/index.d.mts +2 -2
  145. package/dist/plugins/open-api/api/index.d.ts +2 -2
  146. package/dist/plugins/route-docs/client/index.d.cts +1 -1
  147. package/dist/plugins/route-docs/client/index.d.mts +1 -1
  148. package/dist/plugins/route-docs/client/index.d.ts +1 -1
  149. package/dist/plugins/ui-builder/index.d.cts +1 -1
  150. package/dist/plugins/ui-builder/index.d.mts +1 -1
  151. package/dist/plugins/ui-builder/index.d.ts +1 -1
  152. package/dist/shared/{stack.BoA0xkJv.d.cts → stack.7n9Y_u7N.d.cts} +33 -7
  153. package/dist/shared/{stack.BoA0xkJv.d.mts → stack.7n9Y_u7N.d.mts} +33 -7
  154. package/dist/shared/{stack.BoA0xkJv.d.ts → stack.7n9Y_u7N.d.ts} +33 -7
  155. package/dist/shared/stack.B1EeBt1b.d.ts +297 -0
  156. package/dist/shared/stack.BIXEI6v_.d.mts +419 -0
  157. package/dist/shared/stack.BKfolAyK.d.ts +419 -0
  158. package/dist/shared/stack.BeSm90va.d.ts +289 -0
  159. package/dist/shared/stack.BpolpQpf.d.cts +445 -0
  160. package/dist/shared/stack.C5dtIncc.d.mts +293 -0
  161. package/dist/shared/stack.CIP6QS9l.d.ts +293 -0
  162. package/dist/shared/stack.CMh_EdxW.d.cts +289 -0
  163. package/dist/shared/stack.CP68pFEH.d.mts +297 -0
  164. package/dist/shared/{stack.BsXokfNh.d.mts → stack.CVDTkMoO.d.cts} +8 -2
  165. package/dist/shared/{stack.BsXokfNh.d.ts → stack.CVDTkMoO.d.mts} +8 -2
  166. package/dist/shared/{stack.BsXokfNh.d.cts → stack.CVDTkMoO.d.ts} +8 -2
  167. package/dist/shared/{stack.DKDMI-QO.d.mts → stack.DJaKVY7v.d.cts} +7 -1
  168. package/dist/shared/{stack.DKDMI-QO.d.ts → stack.DJaKVY7v.d.mts} +7 -1
  169. package/dist/shared/{stack.DKDMI-QO.d.cts → stack.DJaKVY7v.d.ts} +7 -1
  170. package/dist/shared/{stack.DzH_wcvr.d.mts → stack.DdI5W6MB.d.cts} +9 -3
  171. package/dist/shared/{stack.DzH_wcvr.d.ts → stack.DdI5W6MB.d.mts} +9 -3
  172. package/dist/shared/{stack.DzH_wcvr.d.cts → stack.DdI5W6MB.d.ts} +9 -3
  173. package/dist/shared/stack.Dg09R0oB.d.mts +289 -0
  174. package/dist/shared/stack.Dw0Ly2TM.d.cts +293 -0
  175. package/dist/shared/stack.IdtKDRka.d.cts +297 -0
  176. package/dist/shared/stack.TIBF2AOx.d.ts +445 -0
  177. package/dist/shared/stack.rTy7-wQU.d.mts +445 -0
  178. package/dist/shared/stack.snB1EDP7.d.cts +419 -0
  179. package/package.json +3 -3
  180. package/src/__tests__/stack-api.test.ts +118 -0
  181. package/src/api/index.ts +15 -1
  182. package/src/plugins/ai-chat/__tests__/getters.test.ts +109 -0
  183. package/src/plugins/ai-chat/api/getters.ts +71 -0
  184. package/src/plugins/ai-chat/api/index.ts +1 -0
  185. package/src/plugins/ai-chat/api/plugin.ts +8 -0
  186. package/src/plugins/api/index.ts +3 -1
  187. package/src/plugins/blog/__tests__/getters.test.ts +540 -0
  188. package/src/plugins/blog/api/getters.ts +243 -0
  189. package/src/plugins/blog/api/index.ts +9 -0
  190. package/src/plugins/blog/api/plugin.ts +98 -141
  191. package/src/plugins/blog/api/query-key-defs.ts +46 -0
  192. package/src/plugins/blog/api/serializers.ts +27 -0
  193. package/src/plugins/blog/client/plugin.tsx +21 -1
  194. package/src/plugins/blog/query-keys.ts +21 -20
  195. package/src/plugins/client/index.ts +1 -1
  196. package/src/plugins/cms/__tests__/getters.test.ts +206 -0
  197. package/src/plugins/cms/api/getters.ts +268 -0
  198. package/src/plugins/cms/api/index.ts +15 -1
  199. package/src/plugins/cms/api/plugin.ts +151 -150
  200. package/src/plugins/cms/api/query-key-defs.ts +53 -0
  201. package/src/plugins/cms/api/serializers.ts +12 -0
  202. package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +1 -1
  203. package/src/plugins/cms/client/hooks/cms-hooks.tsx +3 -0
  204. package/src/plugins/cms/client/plugin.tsx +19 -0
  205. package/src/plugins/cms/query-keys.ts +2 -1
  206. package/src/plugins/cms/types.ts +1 -1
  207. package/src/plugins/form-builder/__tests__/getters.test.ts +159 -0
  208. package/src/plugins/form-builder/api/getters.ts +226 -0
  209. package/src/plugins/form-builder/api/index.ts +15 -1
  210. package/src/plugins/form-builder/api/plugin.ts +107 -109
  211. package/src/plugins/form-builder/api/query-key-defs.ts +79 -0
  212. package/src/plugins/form-builder/api/serializers.ts +12 -0
  213. package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +1 -1
  214. package/src/plugins/form-builder/client/plugin.tsx +19 -0
  215. package/src/plugins/form-builder/query-keys.ts +6 -2
  216. package/src/plugins/form-builder/types.ts +2 -2
  217. package/src/plugins/kanban/__tests__/getters.test.ts +172 -0
  218. package/src/plugins/kanban/api/getters.ts +149 -0
  219. package/src/plugins/kanban/api/index.ts +4 -0
  220. package/src/plugins/kanban/api/plugin.ts +65 -146
  221. package/src/plugins/kanban/api/query-key-defs.ts +54 -0
  222. package/src/plugins/kanban/api/serializers.ts +49 -0
  223. package/src/plugins/kanban/client/plugin.tsx +15 -1
  224. package/src/plugins/kanban/query-keys.ts +10 -14
  225. package/src/plugins/utils.ts +19 -0
  226. package/src/types.ts +44 -5
  227. package/dist/shared/{stack.CbuN2zVV.d.cts → stack.CBON0dWL.d.cts} +7 -7
  228. package/dist/shared/{stack.CbuN2zVV.d.mts → stack.CBON0dWL.d.mts} +7 -7
  229. package/dist/shared/{stack.CbuN2zVV.d.ts → stack.CBON0dWL.d.ts} +7 -7
@@ -24,13 +24,21 @@ function stack(config) {
24
24
  allRoutes[compositeKey] = endpoint;
25
25
  }
26
26
  }
27
+ const pluginApis = {};
28
+ for (const [pluginKey, plugin] of Object.entries(plugins)) {
29
+ if (plugin.api) {
30
+ pluginApis[pluginKey] = plugin.api(adapterInstance);
31
+ }
32
+ }
27
33
  const router = betterCall.createRouter(allRoutes, {
28
34
  basePath
29
35
  });
30
36
  return {
31
37
  handler: router.handler,
32
38
  router,
33
- dbSchema: betterDbSchema
39
+ dbSchema: betterDbSchema,
40
+ adapter: adapterInstance,
41
+ api: pluginApis
34
42
  };
35
43
  }
36
44
 
@@ -1,5 +1,5 @@
1
- import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib } from '../shared/stack.BoA0xkJv.cjs';
2
- export { B as BackendPlugin, S as StackContext } from '../shared/stack.BoA0xkJv.cjs';
1
+ import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib, j as PluginApis } from '../shared/stack.7n9Y_u7N.cjs';
2
+ export { B as BackendPlugin, S as StackContext } from '../shared/stack.7n9Y_u7N.cjs';
3
3
  export { toNodeHandler } from 'better-call/node';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
@@ -25,6 +25,6 @@ import 'better-call';
25
25
  * @template TPlugins - The exact plugins map (inferred from config)
26
26
  * @template TRoutes - All routes with prefixed keys like "pluginName_routeName" (computed automatically)
27
27
  */
28
- declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes>;
28
+ declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes, PluginApis<TPlugins>>;
29
29
 
30
- export { BackendLib, BackendLibConfig, stack };
30
+ export { BackendLib, BackendLibConfig, PluginApis, stack };
@@ -1,5 +1,5 @@
1
- import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib } from '../shared/stack.BoA0xkJv.mjs';
2
- export { B as BackendPlugin, S as StackContext } from '../shared/stack.BoA0xkJv.mjs';
1
+ import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib, j as PluginApis } from '../shared/stack.7n9Y_u7N.mjs';
2
+ export { B as BackendPlugin, S as StackContext } from '../shared/stack.7n9Y_u7N.mjs';
3
3
  export { toNodeHandler } from 'better-call/node';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
@@ -25,6 +25,6 @@ import 'better-call';
25
25
  * @template TPlugins - The exact plugins map (inferred from config)
26
26
  * @template TRoutes - All routes with prefixed keys like "pluginName_routeName" (computed automatically)
27
27
  */
28
- declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes>;
28
+ declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes, PluginApis<TPlugins>>;
29
29
 
30
- export { BackendLib, BackendLibConfig, stack };
30
+ export { BackendLib, BackendLibConfig, PluginApis, stack };
@@ -1,5 +1,5 @@
1
- import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib } from '../shared/stack.BoA0xkJv.js';
2
- export { B as BackendPlugin, S as StackContext } from '../shared/stack.BoA0xkJv.js';
1
+ import { g as PrefixedPluginRoutes, h as BackendLibConfig, i as BackendLib, j as PluginApis } from '../shared/stack.7n9Y_u7N.js';
2
+ export { B as BackendPlugin, S as StackContext } from '../shared/stack.7n9Y_u7N.js';
3
3
  export { toNodeHandler } from 'better-call/node';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
@@ -25,6 +25,6 @@ import 'better-call';
25
25
  * @template TPlugins - The exact plugins map (inferred from config)
26
26
  * @template TRoutes - All routes with prefixed keys like "pluginName_routeName" (computed automatically)
27
27
  */
28
- declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes>;
28
+ declare function stack<TPlugins extends Record<string, any>, TRoutes extends PrefixedPluginRoutes<TPlugins> = PrefixedPluginRoutes<TPlugins>>(config: BackendLibConfig<TPlugins>): BackendLib<TRoutes, PluginApis<TPlugins>>;
29
29
 
30
- export { BackendLib, BackendLibConfig, stack };
30
+ export { BackendLib, BackendLibConfig, PluginApis, stack };
@@ -22,13 +22,21 @@ function stack(config) {
22
22
  allRoutes[compositeKey] = endpoint;
23
23
  }
24
24
  }
25
+ const pluginApis = {};
26
+ for (const [pluginKey, plugin] of Object.entries(plugins)) {
27
+ if (plugin.api) {
28
+ pluginApis[pluginKey] = plugin.api(adapterInstance);
29
+ }
30
+ }
25
31
  const router = createRouter(allRoutes, {
26
32
  basePath
27
33
  });
28
34
  return {
29
35
  handler: router.handler,
30
36
  router,
31
- dbSchema: betterDbSchema
37
+ dbSchema: betterDbSchema,
38
+ adapter: adapterInstance,
39
+ api: pluginApis
32
40
  };
33
41
  }
34
42
 
@@ -1,5 +1,5 @@
1
- import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.BoA0xkJv.cjs';
2
- export { b as ClientStackContext } from '../shared/stack.BoA0xkJv.cjs';
1
+ import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.7n9Y_u7N.cjs';
2
+ export { b as ClientStackContext } from '../shared/stack.7n9Y_u7N.cjs';
3
3
  import '@btst/yar';
4
4
  import '@btst/db';
5
5
  import 'better-call';
@@ -1,5 +1,5 @@
1
- import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.BoA0xkJv.mjs';
2
- export { b as ClientStackContext } from '../shared/stack.BoA0xkJv.mjs';
1
+ import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.7n9Y_u7N.mjs';
2
+ export { b as ClientStackContext } from '../shared/stack.7n9Y_u7N.mjs';
3
3
  import '@btst/yar';
4
4
  import '@btst/db';
5
5
  import 'better-call';
@@ -1,5 +1,5 @@
1
- import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.BoA0xkJv.js';
2
- export { b as ClientStackContext } from '../shared/stack.BoA0xkJv.js';
1
+ import { c as Sitemap, C as ClientPlugin, d as PluginRoutes, e as ClientLibConfig, f as ClientLib } from '../shared/stack.7n9Y_u7N.js';
2
+ export { b as ClientStackContext } from '../shared/stack.7n9Y_u7N.js';
3
3
  import '@btst/yar';
4
4
  import '@btst/db';
5
5
  import 'better-call';
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { stack } from './api/index.cjs';
2
2
  export { toNodeHandler } from 'better-call/node';
3
- export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, S as StackContext } from './shared/stack.BoA0xkJv.cjs';
3
+ export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, j as PluginApis, S as StackContext } from './shared/stack.7n9Y_u7N.cjs';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
6
6
  import 'better-call';
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { stack } from './api/index.mjs';
2
2
  export { toNodeHandler } from 'better-call/node';
3
- export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, S as StackContext } from './shared/stack.BoA0xkJv.mjs';
3
+ export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, j as PluginApis, S as StackContext } from './shared/stack.7n9Y_u7N.mjs';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
6
6
  import 'better-call';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { stack } from './api/index.js';
2
2
  export { toNodeHandler } from 'better-call/node';
3
- export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, S as StackContext } from './shared/stack.BoA0xkJv.js';
3
+ export { i as BackendLib, h as BackendLibConfig, B as BackendPlugin, j as PluginApis, S as StackContext } from './shared/stack.7n9Y_u7N.js';
4
4
  import '@btst/yar';
5
5
  import '@btst/db';
6
6
  import 'better-call';
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ async function getAllConversations(adapter, userId) {
4
+ const whereConditions = [];
5
+ if (userId) {
6
+ whereConditions.push({
7
+ field: "userId",
8
+ value: userId,
9
+ operator: "eq"
10
+ });
11
+ }
12
+ return adapter.findMany({
13
+ model: "conversation",
14
+ where: whereConditions.length > 0 ? whereConditions : void 0,
15
+ sortBy: { field: "updatedAt", direction: "desc" }
16
+ });
17
+ }
18
+ async function getConversationById(adapter, id) {
19
+ const conversations = await adapter.findMany({
20
+ model: "conversation",
21
+ where: [{ field: "id", value: id, operator: "eq" }],
22
+ limit: 1,
23
+ join: {
24
+ message: true
25
+ }
26
+ });
27
+ if (!conversations.length) {
28
+ return null;
29
+ }
30
+ const conversation = conversations[0];
31
+ const messages = (conversation.message || []).sort(
32
+ (a, b) => a.createdAt.getTime() - b.createdAt.getTime()
33
+ );
34
+ const { message: _, ...conversationWithoutJoin } = conversation;
35
+ return {
36
+ ...conversationWithoutJoin,
37
+ messages
38
+ };
39
+ }
40
+
41
+ exports.getAllConversations = getAllConversations;
42
+ exports.getConversationById = getConversationById;
@@ -0,0 +1,39 @@
1
+ async function getAllConversations(adapter, userId) {
2
+ const whereConditions = [];
3
+ if (userId) {
4
+ whereConditions.push({
5
+ field: "userId",
6
+ value: userId,
7
+ operator: "eq"
8
+ });
9
+ }
10
+ return adapter.findMany({
11
+ model: "conversation",
12
+ where: whereConditions.length > 0 ? whereConditions : void 0,
13
+ sortBy: { field: "updatedAt", direction: "desc" }
14
+ });
15
+ }
16
+ async function getConversationById(adapter, id) {
17
+ const conversations = await adapter.findMany({
18
+ model: "conversation",
19
+ where: [{ field: "id", value: id, operator: "eq" }],
20
+ limit: 1,
21
+ join: {
22
+ message: true
23
+ }
24
+ });
25
+ if (!conversations.length) {
26
+ return null;
27
+ }
28
+ const conversation = conversations[0];
29
+ const messages = (conversation.message || []).sort(
30
+ (a, b) => a.createdAt.getTime() - b.createdAt.getTime()
31
+ );
32
+ const { message: _, ...conversationWithoutJoin } = conversation;
33
+ return {
34
+ ...conversationWithoutJoin,
35
+ messages
36
+ };
37
+ }
38
+
39
+ export { getAllConversations, getConversationById };
@@ -4,11 +4,16 @@ const api = require('@btst/stack/plugins/api');
4
4
  const ai = require('ai');
5
5
  const db = require('../db.cjs');
6
6
  const schemas = require('../schemas.cjs');
7
+ const getters = require('./getters.cjs');
7
8
 
8
9
  const aiChatBackendPlugin = (config) => api.defineBackendPlugin({
9
10
  name: "ai-chat",
10
11
  // Always include db schema - in public mode we just don't use it
11
12
  dbPlugin: db.aiChatSchema,
13
+ api: (adapter) => ({
14
+ getAllConversations: (userId) => getters.getAllConversations(adapter, userId),
15
+ getConversationById: (id) => getters.getConversationById(adapter, id)
16
+ }),
12
17
  routes: (adapter) => {
13
18
  const mode = config.mode ?? "authenticated";
14
19
  const isPublicMode = mode === "public";
@@ -2,11 +2,16 @@ import { defineBackendPlugin, createEndpoint } from '@btst/stack/plugins/api';
2
2
  import { convertToModelMessages, streamText, stepCountIs } from 'ai';
3
3
  import { aiChatSchema } from '../db.mjs';
4
4
  import { chatRequestSchema, createConversationSchema, updateConversationSchema } from '../schemas.mjs';
5
+ import { getConversationById, getAllConversations } from './getters.mjs';
5
6
 
6
7
  const aiChatBackendPlugin = (config) => defineBackendPlugin({
7
8
  name: "ai-chat",
8
9
  // Always include db schema - in public mode we just don't use it
9
10
  dbPlugin: aiChatSchema,
11
+ api: (adapter) => ({
12
+ getAllConversations: (userId) => getAllConversations(adapter, userId),
13
+ getConversationById: (id) => getConversationById(adapter, id)
14
+ }),
10
15
  routes: (adapter) => {
11
16
  const mode = config.mode ?? "authenticated";
12
17
  const isPublicMode = mode === "public";
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ async function getAllPosts(adapter, params) {
4
+ const query = params ?? {};
5
+ const whereConditions = [];
6
+ if (query.tagSlug) {
7
+ const tag = await adapter.findOne({
8
+ model: "tag",
9
+ where: [{ field: "slug", value: query.tagSlug, operator: "eq" }]
10
+ });
11
+ if (!tag) {
12
+ return { items: [], total: 0, limit: query.limit, offset: query.offset };
13
+ }
14
+ const postTags = await adapter.findMany({
15
+ model: "postTag",
16
+ where: [{ field: "tagId", value: tag.id, operator: "eq" }]
17
+ });
18
+ const taggedPostIds = postTags.map((pt) => pt.postId);
19
+ if (taggedPostIds.length === 0) {
20
+ return { items: [], total: 0, limit: query.limit, offset: query.offset };
21
+ }
22
+ whereConditions.push({
23
+ field: "id",
24
+ value: taggedPostIds,
25
+ operator: "in"
26
+ });
27
+ }
28
+ if (query.published !== void 0) {
29
+ whereConditions.push({
30
+ field: "published",
31
+ value: query.published,
32
+ operator: "eq"
33
+ });
34
+ }
35
+ if (query.slug) {
36
+ whereConditions.push({
37
+ field: "slug",
38
+ value: query.slug,
39
+ operator: "eq"
40
+ });
41
+ }
42
+ const needsInMemoryFilter = !!query.query;
43
+ const dbWhere = whereConditions.length > 0 ? whereConditions : void 0;
44
+ const dbTotal = !needsInMemoryFilter ? await adapter.count({ model: "post", where: dbWhere }) : void 0;
45
+ const posts = await adapter.findMany({
46
+ model: "post",
47
+ limit: !needsInMemoryFilter ? query.limit : void 0,
48
+ offset: !needsInMemoryFilter ? query.offset : void 0,
49
+ where: dbWhere,
50
+ sortBy: { field: "createdAt", direction: "desc" },
51
+ join: { postTag: true }
52
+ });
53
+ const tagIds = /* @__PURE__ */ new Set();
54
+ for (const post of posts) {
55
+ if (post.postTag) {
56
+ for (const pt of post.postTag) {
57
+ tagIds.add(pt.tagId);
58
+ }
59
+ }
60
+ }
61
+ const tags = tagIds.size > 0 ? await adapter.findMany({
62
+ model: "tag",
63
+ where: [
64
+ {
65
+ field: "id",
66
+ value: Array.from(tagIds),
67
+ operator: "in"
68
+ }
69
+ ]
70
+ }) : [];
71
+ const tagMap = new Map(tags.map((t) => [t.id, t]));
72
+ let result = posts.map((post) => {
73
+ const postTags = (post.postTag || []).map((pt) => {
74
+ const tag = tagMap.get(pt.tagId);
75
+ return tag ? { ...tag } : void 0;
76
+ }).filter((tag) => tag !== void 0);
77
+ const { postTag: _, ...postWithoutJoin } = post;
78
+ return { ...postWithoutJoin, tags: postTags };
79
+ });
80
+ if (query.query) {
81
+ const searchLower = query.query.toLowerCase();
82
+ result = result.filter(
83
+ (post) => post.title?.toLowerCase().includes(searchLower) || post.content?.toLowerCase().includes(searchLower) || post.excerpt?.toLowerCase().includes(searchLower)
84
+ );
85
+ }
86
+ if (needsInMemoryFilter) {
87
+ const total = result.length;
88
+ const offset = query.offset ?? 0;
89
+ const limit = query.limit;
90
+ result = result.slice(
91
+ offset,
92
+ limit !== void 0 ? offset + limit : void 0
93
+ );
94
+ return { items: result, total, limit: query.limit, offset: query.offset };
95
+ }
96
+ return {
97
+ items: result,
98
+ total: dbTotal ?? result.length,
99
+ limit: query.limit,
100
+ offset: query.offset
101
+ };
102
+ }
103
+ async function getPostBySlug(adapter, slug) {
104
+ const posts = await adapter.findMany({
105
+ model: "post",
106
+ where: [{ field: "slug", value: slug, operator: "eq" }],
107
+ limit: 1,
108
+ join: { postTag: true }
109
+ });
110
+ if (posts.length === 0) return null;
111
+ const post = posts[0];
112
+ const tagIds = (post.postTag || []).map((pt) => pt.tagId);
113
+ const tags = tagIds.length > 0 ? await adapter.findMany({
114
+ model: "tag",
115
+ where: [{ field: "id", value: tagIds, operator: "in" }]
116
+ }) : [];
117
+ const tagMap = new Map(tags.map((t) => [t.id, t]));
118
+ const resolvedTags = (post.postTag || []).map((pt) => tagMap.get(pt.tagId)).filter((t) => t !== void 0);
119
+ const { postTag: _, ...postWithoutJoin } = post;
120
+ return { ...postWithoutJoin, tags: resolvedTags };
121
+ }
122
+ async function getAllTags(adapter) {
123
+ return adapter.findMany({
124
+ model: "tag",
125
+ sortBy: { field: "name", direction: "asc" }
126
+ });
127
+ }
128
+
129
+ exports.getAllPosts = getAllPosts;
130
+ exports.getAllTags = getAllTags;
131
+ exports.getPostBySlug = getPostBySlug;
@@ -0,0 +1,127 @@
1
+ async function getAllPosts(adapter, params) {
2
+ const query = params ?? {};
3
+ const whereConditions = [];
4
+ if (query.tagSlug) {
5
+ const tag = await adapter.findOne({
6
+ model: "tag",
7
+ where: [{ field: "slug", value: query.tagSlug, operator: "eq" }]
8
+ });
9
+ if (!tag) {
10
+ return { items: [], total: 0, limit: query.limit, offset: query.offset };
11
+ }
12
+ const postTags = await adapter.findMany({
13
+ model: "postTag",
14
+ where: [{ field: "tagId", value: tag.id, operator: "eq" }]
15
+ });
16
+ const taggedPostIds = postTags.map((pt) => pt.postId);
17
+ if (taggedPostIds.length === 0) {
18
+ return { items: [], total: 0, limit: query.limit, offset: query.offset };
19
+ }
20
+ whereConditions.push({
21
+ field: "id",
22
+ value: taggedPostIds,
23
+ operator: "in"
24
+ });
25
+ }
26
+ if (query.published !== void 0) {
27
+ whereConditions.push({
28
+ field: "published",
29
+ value: query.published,
30
+ operator: "eq"
31
+ });
32
+ }
33
+ if (query.slug) {
34
+ whereConditions.push({
35
+ field: "slug",
36
+ value: query.slug,
37
+ operator: "eq"
38
+ });
39
+ }
40
+ const needsInMemoryFilter = !!query.query;
41
+ const dbWhere = whereConditions.length > 0 ? whereConditions : void 0;
42
+ const dbTotal = !needsInMemoryFilter ? await adapter.count({ model: "post", where: dbWhere }) : void 0;
43
+ const posts = await adapter.findMany({
44
+ model: "post",
45
+ limit: !needsInMemoryFilter ? query.limit : void 0,
46
+ offset: !needsInMemoryFilter ? query.offset : void 0,
47
+ where: dbWhere,
48
+ sortBy: { field: "createdAt", direction: "desc" },
49
+ join: { postTag: true }
50
+ });
51
+ const tagIds = /* @__PURE__ */ new Set();
52
+ for (const post of posts) {
53
+ if (post.postTag) {
54
+ for (const pt of post.postTag) {
55
+ tagIds.add(pt.tagId);
56
+ }
57
+ }
58
+ }
59
+ const tags = tagIds.size > 0 ? await adapter.findMany({
60
+ model: "tag",
61
+ where: [
62
+ {
63
+ field: "id",
64
+ value: Array.from(tagIds),
65
+ operator: "in"
66
+ }
67
+ ]
68
+ }) : [];
69
+ const tagMap = new Map(tags.map((t) => [t.id, t]));
70
+ let result = posts.map((post) => {
71
+ const postTags = (post.postTag || []).map((pt) => {
72
+ const tag = tagMap.get(pt.tagId);
73
+ return tag ? { ...tag } : void 0;
74
+ }).filter((tag) => tag !== void 0);
75
+ const { postTag: _, ...postWithoutJoin } = post;
76
+ return { ...postWithoutJoin, tags: postTags };
77
+ });
78
+ if (query.query) {
79
+ const searchLower = query.query.toLowerCase();
80
+ result = result.filter(
81
+ (post) => post.title?.toLowerCase().includes(searchLower) || post.content?.toLowerCase().includes(searchLower) || post.excerpt?.toLowerCase().includes(searchLower)
82
+ );
83
+ }
84
+ if (needsInMemoryFilter) {
85
+ const total = result.length;
86
+ const offset = query.offset ?? 0;
87
+ const limit = query.limit;
88
+ result = result.slice(
89
+ offset,
90
+ limit !== void 0 ? offset + limit : void 0
91
+ );
92
+ return { items: result, total, limit: query.limit, offset: query.offset };
93
+ }
94
+ return {
95
+ items: result,
96
+ total: dbTotal ?? result.length,
97
+ limit: query.limit,
98
+ offset: query.offset
99
+ };
100
+ }
101
+ async function getPostBySlug(adapter, slug) {
102
+ const posts = await adapter.findMany({
103
+ model: "post",
104
+ where: [{ field: "slug", value: slug, operator: "eq" }],
105
+ limit: 1,
106
+ join: { postTag: true }
107
+ });
108
+ if (posts.length === 0) return null;
109
+ const post = posts[0];
110
+ const tagIds = (post.postTag || []).map((pt) => pt.tagId);
111
+ const tags = tagIds.length > 0 ? await adapter.findMany({
112
+ model: "tag",
113
+ where: [{ field: "id", value: tagIds, operator: "in" }]
114
+ }) : [];
115
+ const tagMap = new Map(tags.map((t) => [t.id, t]));
116
+ const resolvedTags = (post.postTag || []).map((pt) => tagMap.get(pt.tagId)).filter((t) => t !== void 0);
117
+ const { postTag: _, ...postWithoutJoin } = post;
118
+ return { ...postWithoutJoin, tags: resolvedTags };
119
+ }
120
+ async function getAllTags(adapter) {
121
+ return adapter.findMany({
122
+ model: "tag",
123
+ sortBy: { field: "name", direction: "asc" }
124
+ });
125
+ }
126
+
127
+ export { getAllPosts, getAllTags, getPostBySlug };