@btst/stack 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) 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 +9 -107
  19. package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +9 -107
  20. package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +1 -1
  21. package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +1 -1
  22. package/dist/packages/stack/src/plugins/cms/api/getters.cjs +146 -0
  23. package/dist/packages/stack/src/plugins/cms/api/getters.mjs +138 -0
  24. package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +560 -622
  25. package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +559 -621
  26. package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.cjs +1 -1
  27. package/dist/packages/stack/src/plugins/cms/client/components/pages/content-editor-page.internal.mjs +1 -1
  28. package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.cjs +6 -3
  29. package/dist/packages/stack/src/plugins/cms/client/hooks/cms-hooks.mjs +6 -3
  30. package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +111 -0
  31. package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +104 -0
  32. package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +16 -88
  33. package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +12 -84
  34. package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.cjs +1 -1
  35. package/dist/packages/stack/src/plugins/form-builder/client/components/pages/submissions-page.internal.mjs +1 -1
  36. package/dist/packages/stack/src/plugins/kanban/api/getters.cjs +84 -0
  37. package/dist/packages/stack/src/plugins/kanban/api/getters.mjs +81 -0
  38. package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +9 -123
  39. package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +9 -123
  40. package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +1 -1
  41. package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +1 -1
  42. package/dist/plugins/ai-chat/api/index.cjs +3 -0
  43. package/dist/plugins/ai-chat/api/index.d.cts +27 -4
  44. package/dist/plugins/ai-chat/api/index.d.mts +27 -4
  45. package/dist/plugins/ai-chat/api/index.d.ts +27 -4
  46. package/dist/plugins/ai-chat/api/index.mjs +1 -0
  47. package/dist/plugins/ai-chat/client/hooks/index.d.cts +2 -2
  48. package/dist/plugins/ai-chat/client/hooks/index.d.mts +2 -2
  49. package/dist/plugins/ai-chat/client/hooks/index.d.ts +2 -2
  50. package/dist/plugins/ai-chat/query-keys.d.cts +9 -284
  51. package/dist/plugins/ai-chat/query-keys.d.mts +9 -284
  52. package/dist/plugins/ai-chat/query-keys.d.ts +9 -284
  53. package/dist/plugins/api/index.d.cts +4 -3
  54. package/dist/plugins/api/index.d.mts +4 -3
  55. package/dist/plugins/api/index.d.ts +4 -3
  56. package/dist/plugins/blog/api/index.cjs +4 -0
  57. package/dist/plugins/blog/api/index.d.cts +3 -2
  58. package/dist/plugins/blog/api/index.d.mts +3 -2
  59. package/dist/plugins/blog/api/index.d.ts +3 -2
  60. package/dist/plugins/blog/api/index.mjs +1 -0
  61. package/dist/plugins/blog/client/hooks/index.d.cts +4 -4
  62. package/dist/plugins/blog/client/hooks/index.d.mts +4 -4
  63. package/dist/plugins/blog/client/hooks/index.d.ts +4 -4
  64. package/dist/plugins/blog/client/index.d.cts +1 -1
  65. package/dist/plugins/blog/client/index.d.mts +1 -1
  66. package/dist/plugins/blog/client/index.d.ts +1 -1
  67. package/dist/plugins/blog/query-keys.cjs +7 -4
  68. package/dist/plugins/blog/query-keys.d.cts +81 -27
  69. package/dist/plugins/blog/query-keys.d.mts +81 -27
  70. package/dist/plugins/blog/query-keys.d.ts +81 -27
  71. package/dist/plugins/blog/query-keys.mjs +7 -4
  72. package/dist/plugins/client/index.d.cts +2 -2
  73. package/dist/plugins/client/index.d.mts +2 -2
  74. package/dist/plugins/client/index.d.ts +2 -2
  75. package/dist/plugins/cms/api/index.cjs +4 -0
  76. package/dist/plugins/cms/api/index.d.cts +61 -5
  77. package/dist/plugins/cms/api/index.d.mts +61 -5
  78. package/dist/plugins/cms/api/index.d.ts +61 -5
  79. package/dist/plugins/cms/api/index.mjs +1 -0
  80. package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
  81. package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
  82. package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
  83. package/dist/plugins/cms/query-keys.d.cts +2 -1
  84. package/dist/plugins/cms/query-keys.d.mts +2 -1
  85. package/dist/plugins/cms/query-keys.d.ts +2 -1
  86. package/dist/plugins/form-builder/api/index.cjs +4 -0
  87. package/dist/plugins/form-builder/api/index.d.cts +77 -7
  88. package/dist/plugins/form-builder/api/index.d.mts +77 -7
  89. package/dist/plugins/form-builder/api/index.d.ts +77 -7
  90. package/dist/plugins/form-builder/api/index.mjs +1 -0
  91. package/dist/plugins/form-builder/client/components/index.d.cts +1 -1
  92. package/dist/plugins/form-builder/client/components/index.d.mts +1 -1
  93. package/dist/plugins/form-builder/client/components/index.d.ts +1 -1
  94. package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
  95. package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
  96. package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
  97. package/dist/plugins/form-builder/query-keys.d.cts +2 -1
  98. package/dist/plugins/form-builder/query-keys.d.mts +2 -1
  99. package/dist/plugins/form-builder/query-keys.d.ts +2 -1
  100. package/dist/plugins/kanban/api/index.cjs +3 -0
  101. package/dist/plugins/kanban/api/index.d.cts +40 -43
  102. package/dist/plugins/kanban/api/index.d.mts +40 -43
  103. package/dist/plugins/kanban/api/index.d.ts +40 -43
  104. package/dist/plugins/kanban/api/index.mjs +1 -0
  105. package/dist/plugins/kanban/client/components/index.d.cts +1 -1
  106. package/dist/plugins/kanban/client/components/index.d.mts +1 -1
  107. package/dist/plugins/kanban/client/components/index.d.ts +1 -1
  108. package/dist/plugins/kanban/client/hooks/index.d.cts +1 -1
  109. package/dist/plugins/kanban/client/hooks/index.d.mts +1 -1
  110. package/dist/plugins/kanban/client/hooks/index.d.ts +1 -1
  111. package/dist/plugins/kanban/client/index.d.cts +1 -1
  112. package/dist/plugins/kanban/client/index.d.mts +1 -1
  113. package/dist/plugins/kanban/client/index.d.ts +1 -1
  114. package/dist/plugins/kanban/query-keys.cjs +4 -3
  115. package/dist/plugins/kanban/query-keys.d.cts +2 -1
  116. package/dist/plugins/kanban/query-keys.d.mts +2 -1
  117. package/dist/plugins/kanban/query-keys.d.ts +2 -1
  118. package/dist/plugins/kanban/query-keys.mjs +4 -3
  119. package/dist/plugins/open-api/api/index.d.cts +2 -2
  120. package/dist/plugins/open-api/api/index.d.mts +2 -2
  121. package/dist/plugins/open-api/api/index.d.ts +2 -2
  122. package/dist/plugins/route-docs/client/index.d.cts +1 -1
  123. package/dist/plugins/route-docs/client/index.d.mts +1 -1
  124. package/dist/plugins/route-docs/client/index.d.ts +1 -1
  125. package/dist/plugins/ui-builder/index.d.cts +1 -1
  126. package/dist/plugins/ui-builder/index.d.mts +1 -1
  127. package/dist/plugins/ui-builder/index.d.ts +1 -1
  128. package/dist/shared/{stack.BoA0xkJv.d.cts → stack.7n9Y_u7N.d.cts} +33 -7
  129. package/dist/shared/{stack.BoA0xkJv.d.mts → stack.7n9Y_u7N.d.mts} +33 -7
  130. package/dist/shared/{stack.BoA0xkJv.d.ts → stack.7n9Y_u7N.d.ts} +33 -7
  131. package/dist/shared/stack.BeSm90va.d.ts +289 -0
  132. package/dist/shared/{stack.DzH_wcvr.d.mts → stack.CIrIsc-A.d.cts} +2 -2
  133. package/dist/shared/{stack.DzH_wcvr.d.ts → stack.CIrIsc-A.d.mts} +2 -2
  134. package/dist/shared/{stack.DzH_wcvr.d.cts → stack.CIrIsc-A.d.ts} +2 -2
  135. package/dist/shared/stack.CMh_EdxW.d.cts +289 -0
  136. package/dist/shared/{stack.BsXokfNh.d.mts → stack.CXjzTMsb.d.cts} +1 -1
  137. package/dist/shared/{stack.BsXokfNh.d.ts → stack.CXjzTMsb.d.mts} +1 -1
  138. package/dist/shared/{stack.BsXokfNh.d.cts → stack.CXjzTMsb.d.ts} +1 -1
  139. package/dist/shared/stack.Dg09R0oB.d.mts +289 -0
  140. package/dist/shared/{stack.DKDMI-QO.d.mts → stack.QD1y_7NY.d.cts} +7 -1
  141. package/dist/shared/{stack.DKDMI-QO.d.ts → stack.QD1y_7NY.d.mts} +7 -1
  142. package/dist/shared/{stack.DKDMI-QO.d.cts → stack.QD1y_7NY.d.ts} +7 -1
  143. package/package.json +1 -1
  144. package/src/__tests__/stack-api.test.ts +118 -0
  145. package/src/api/index.ts +15 -1
  146. package/src/plugins/ai-chat/__tests__/getters.test.ts +109 -0
  147. package/src/plugins/ai-chat/api/getters.ts +71 -0
  148. package/src/plugins/ai-chat/api/index.ts +1 -0
  149. package/src/plugins/ai-chat/api/plugin.ts +8 -0
  150. package/src/plugins/api/index.ts +3 -1
  151. package/src/plugins/blog/__tests__/getters.test.ts +540 -0
  152. package/src/plugins/blog/api/getters.ts +243 -0
  153. package/src/plugins/blog/api/index.ts +7 -0
  154. package/src/plugins/blog/api/plugin.ts +13 -141
  155. package/src/plugins/blog/client/plugin.tsx +2 -1
  156. package/src/plugins/blog/query-keys.ts +16 -13
  157. package/src/plugins/cms/__tests__/getters.test.ts +206 -0
  158. package/src/plugins/cms/api/getters.ts +244 -0
  159. package/src/plugins/cms/api/index.ts +5 -0
  160. package/src/plugins/cms/api/plugin.ts +50 -154
  161. package/src/plugins/cms/client/components/pages/content-editor-page.internal.tsx +1 -1
  162. package/src/plugins/cms/client/hooks/cms-hooks.tsx +3 -0
  163. package/src/plugins/cms/types.ts +1 -1
  164. package/src/plugins/form-builder/__tests__/getters.test.ts +159 -0
  165. package/src/plugins/form-builder/api/getters.ts +203 -0
  166. package/src/plugins/form-builder/api/index.ts +1 -0
  167. package/src/plugins/form-builder/api/plugin.ts +22 -115
  168. package/src/plugins/form-builder/client/components/pages/submissions-page.internal.tsx +1 -1
  169. package/src/plugins/form-builder/types.ts +2 -2
  170. package/src/plugins/kanban/__tests__/getters.test.ts +172 -0
  171. package/src/plugins/kanban/api/getters.ts +149 -0
  172. package/src/plugins/kanban/api/index.ts +1 -0
  173. package/src/plugins/kanban/api/plugin.ts +16 -146
  174. package/src/plugins/kanban/client/plugin.tsx +2 -1
  175. package/src/plugins/kanban/query-keys.ts +8 -5
  176. package/src/types.ts +44 -5
  177. package/dist/shared/{stack.CbuN2zVV.d.cts → stack.BkYlUT_8.d.cts} +6 -6
  178. package/dist/shared/{stack.CbuN2zVV.d.mts → stack.BkYlUT_8.d.mts} +6 -6
  179. package/dist/shared/{stack.CbuN2zVV.d.ts → stack.BkYlUT_8.d.ts} +6 -6
@@ -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 };
@@ -5,6 +5,7 @@ const z = require('zod');
5
5
  const db = require('../db.cjs');
6
6
  const utils = require('../utils.cjs');
7
7
  const schemas = require('../schemas.cjs');
8
+ const getters = require('./getters.cjs');
8
9
 
9
10
  const PostListQuerySchema = z.z.object({
10
11
  slug: z.z.string().optional(),
@@ -25,6 +26,11 @@ const NextPreviousPostsQuerySchema = z.z.object({
25
26
  const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
26
27
  name: "blog",
27
28
  dbPlugin: db.blogSchema,
29
+ api: (adapter) => ({
30
+ getAllPosts: (params) => getters.getAllPosts(adapter, params),
31
+ getPostBySlug: (slug) => getters.getPostBySlug(adapter, slug),
32
+ getAllTags: () => getters.getAllTags(adapter)
33
+ }),
28
34
  routes: (adapter) => {
29
35
  const findOrCreateTags = async (tagInputs) => {
30
36
  if (tagInputs.length === 0) return [];
@@ -105,111 +111,9 @@ const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
105
111
  });
106
112
  }
107
113
  }
108
- let tagFilterPostIds = null;
109
- if (query.tagSlug) {
110
- const tag = await adapter.findOne({
111
- model: "tag",
112
- where: [
113
- {
114
- field: "slug",
115
- value: query.tagSlug,
116
- operator: "eq"
117
- }
118
- ]
119
- });
120
- if (!tag) {
121
- return [];
122
- }
123
- const postTags = await adapter.findMany({
124
- model: "postTag",
125
- where: [
126
- {
127
- field: "tagId",
128
- value: tag.id,
129
- operator: "eq"
130
- }
131
- ]
132
- });
133
- tagFilterPostIds = new Set(postTags.map((pt) => pt.postId));
134
- if (tagFilterPostIds.size === 0) {
135
- return [];
136
- }
137
- }
138
- const whereConditions = [];
139
- if (query.published !== void 0) {
140
- whereConditions.push({
141
- field: "published",
142
- value: query.published,
143
- operator: "eq"
144
- });
145
- }
146
- if (query.slug) {
147
- whereConditions.push({
148
- field: "slug",
149
- value: query.slug,
150
- operator: "eq"
151
- });
152
- }
153
- const posts = await adapter.findMany({
154
- model: "post",
155
- limit: query.query || query.tagSlug ? void 0 : query.limit ?? 10,
156
- offset: query.query || query.tagSlug ? void 0 : query.offset ?? 0,
157
- where: whereConditions,
158
- sortBy: {
159
- field: "createdAt",
160
- direction: "desc"
161
- },
162
- join: {
163
- postTag: true
164
- }
165
- });
166
- const tagIds = /* @__PURE__ */ new Set();
167
- for (const post of posts) {
168
- if (post.postTag) {
169
- for (const pt of post.postTag) {
170
- tagIds.add(pt.tagId);
171
- }
172
- }
173
- }
174
- const tags = tagIds.size > 0 ? await adapter.findMany({
175
- model: "tag"
176
- }) : [];
177
- const tagMap = /* @__PURE__ */ new Map();
178
- for (const tag of tags) {
179
- if (tagIds.has(tag.id)) {
180
- tagMap.set(tag.id, tag);
181
- }
182
- }
183
- let result = posts.map((post) => {
184
- const postTags = (post.postTag || []).map((pt) => {
185
- const tag = tagMap.get(pt.tagId);
186
- return tag ? { ...tag } : void 0;
187
- }).filter((tag) => tag !== void 0);
188
- const { postTag: _, ...postWithoutJoin } = post;
189
- return {
190
- ...postWithoutJoin,
191
- tags: postTags
192
- };
193
- });
194
- if (tagFilterPostIds) {
195
- result = result.filter((post) => tagFilterPostIds.has(post.id));
196
- }
197
- if (query.query) {
198
- const searchLower = query.query.toLowerCase();
199
- result = result.filter((post) => {
200
- const titleMatch = post.title?.toLowerCase().includes(searchLower);
201
- const contentMatch = post.content?.toLowerCase().includes(searchLower);
202
- const excerptMatch = post.excerpt?.toLowerCase().includes(searchLower);
203
- return titleMatch || contentMatch || excerptMatch;
204
- });
205
- }
206
- if (query.tagSlug || query.query) {
207
- const offset = query.offset ?? 0;
208
- const limit = query.limit ?? 10;
209
- result = result.slice(offset, offset + limit);
210
- }
114
+ const result = await getters.getAllPosts(adapter, query);
211
115
  if (hooks?.onPostsRead) {
212
- await hooks.onPostsRead(result, query, context);
116
+ await hooks.onPostsRead(result.items, query, context);
213
117
  }
214
118
  return result;
215
119
  } catch (error) {
@@ -552,9 +456,7 @@ const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
552
456
  method: "GET"
553
457
  },
554
458
  async () => {
555
- return await adapter.findMany({
556
- model: "tag"
557
- });
459
+ return await getters.getAllTags(adapter);
558
460
  }
559
461
  );
560
462
  return {