@btst/stack 2.2.0 → 2.4.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 (237) hide show
  1. package/dist/packages/stack/src/client/components/compose.cjs +1 -2
  2. package/dist/packages/stack/src/client/components/compose.mjs +1 -2
  3. package/dist/packages/stack/src/plugins/ai-chat/api/page-tools.cjs +71 -0
  4. package/dist/packages/stack/src/plugins/ai-chat/api/page-tools.mjs +68 -0
  5. package/dist/packages/stack/src/plugins/ai-chat/api/plugin.cjs +54 -7
  6. package/dist/packages/stack/src/plugins/ai-chat/api/plugin.mjs +54 -7
  7. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.cjs +2 -2
  8. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-input.mjs +2 -2
  9. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.cjs +89 -22
  10. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-interface.mjs +90 -23
  11. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.cjs +110 -33
  12. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-layout.mjs +112 -35
  13. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.cjs +1 -1
  14. package/dist/packages/stack/src/plugins/ai-chat/client/components/chat-sidebar.mjs +1 -1
  15. package/dist/packages/stack/src/plugins/ai-chat/schemas.cjs +17 -1
  16. package/dist/packages/stack/src/plugins/ai-chat/schemas.mjs +17 -1
  17. package/dist/packages/stack/src/plugins/blog/api/plugin.cjs +52 -1
  18. package/dist/packages/stack/src/plugins/blog/api/plugin.mjs +52 -1
  19. package/dist/packages/stack/src/plugins/blog/api/query-key-defs.cjs +18 -0
  20. package/dist/packages/stack/src/plugins/blog/api/query-key-defs.mjs +15 -0
  21. package/dist/packages/stack/src/plugins/blog/api/serializers.cjs +21 -0
  22. package/dist/packages/stack/src/plugins/blog/api/serializers.mjs +18 -0
  23. package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.cjs +15 -2
  24. package/dist/packages/stack/src/plugins/blog/client/components/forms/post-forms.mjs +16 -3
  25. package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.cjs +24 -1
  26. package/dist/packages/stack/src/plugins/blog/client/components/pages/edit-post-page.internal.mjs +24 -1
  27. package/dist/packages/stack/src/plugins/blog/client/components/pages/fill-blog-form-handler.cjs +26 -0
  28. package/dist/packages/stack/src/plugins/blog/client/components/pages/fill-blog-form-handler.mjs +24 -0
  29. package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.cjs +30 -1
  30. package/dist/packages/stack/src/plugins/blog/client/components/pages/new-post-page.internal.mjs +30 -1
  31. package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +18 -0
  32. package/dist/packages/stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +18 -0
  33. package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +15 -0
  34. package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +16 -1
  35. package/dist/packages/stack/src/plugins/cms/api/getters.cjs +10 -0
  36. package/dist/packages/stack/src/plugins/cms/api/getters.mjs +10 -1
  37. package/dist/packages/stack/src/plugins/cms/api/mutations.cjs +48 -0
  38. package/dist/packages/stack/src/plugins/cms/api/mutations.mjs +46 -0
  39. package/dist/packages/stack/src/plugins/cms/api/plugin.cjs +75 -0
  40. package/dist/packages/stack/src/plugins/cms/api/plugin.mjs +76 -1
  41. package/dist/packages/stack/src/plugins/cms/api/query-key-defs.cjs +29 -0
  42. package/dist/packages/stack/src/plugins/cms/api/query-key-defs.mjs +26 -0
  43. package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +15 -0
  44. package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +16 -1
  45. package/dist/packages/stack/src/plugins/form-builder/api/getters.cjs +9 -0
  46. package/dist/packages/stack/src/plugins/form-builder/api/getters.mjs +9 -1
  47. package/dist/packages/stack/src/plugins/form-builder/api/plugin.cjs +62 -1
  48. package/dist/packages/stack/src/plugins/form-builder/api/plugin.mjs +63 -2
  49. package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.cjs +37 -0
  50. package/dist/packages/stack/src/plugins/form-builder/api/query-key-defs.mjs +33 -0
  51. package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +15 -0
  52. package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +16 -1
  53. package/dist/packages/stack/src/plugins/kanban/api/mutations.cjs +91 -0
  54. package/dist/packages/stack/src/plugins/kanban/api/mutations.mjs +87 -0
  55. package/dist/packages/stack/src/plugins/kanban/api/plugin.cjs +34 -1
  56. package/dist/packages/stack/src/plugins/kanban/api/plugin.mjs +34 -1
  57. package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.cjs +26 -0
  58. package/dist/packages/stack/src/plugins/kanban/api/query-key-defs.mjs +23 -0
  59. package/dist/packages/stack/src/plugins/kanban/api/serializers.cjs +30 -0
  60. package/dist/packages/stack/src/plugins/kanban/api/serializers.mjs +26 -0
  61. package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.cjs +7 -3
  62. package/dist/packages/stack/src/plugins/kanban/client/hooks/kanban-hooks.mjs +7 -3
  63. package/dist/packages/stack/src/plugins/kanban/client/plugin.cjs +10 -0
  64. package/dist/packages/stack/src/plugins/kanban/client/plugin.mjs +11 -1
  65. package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.cjs +89 -0
  66. package/dist/packages/stack/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.mjs +89 -0
  67. package/dist/packages/stack/src/plugins/utils.cjs +6 -0
  68. package/dist/packages/stack/src/plugins/utils.mjs +6 -1
  69. package/dist/plugins/ai-chat/api/index.d.cts +1 -1
  70. package/dist/plugins/ai-chat/api/index.d.mts +1 -1
  71. package/dist/plugins/ai-chat/api/index.d.ts +1 -1
  72. package/dist/plugins/ai-chat/client/components/index.d.cts +1 -1
  73. package/dist/plugins/ai-chat/client/components/index.d.mts +1 -1
  74. package/dist/plugins/ai-chat/client/components/index.d.ts +1 -1
  75. package/dist/plugins/ai-chat/client/context/page-ai-context.cjs +92 -0
  76. package/dist/plugins/ai-chat/client/context/page-ai-context.d.cts +84 -0
  77. package/dist/plugins/ai-chat/client/context/page-ai-context.d.mts +84 -0
  78. package/dist/plugins/ai-chat/client/context/page-ai-context.d.ts +84 -0
  79. package/dist/plugins/ai-chat/client/context/page-ai-context.mjs +88 -0
  80. package/dist/plugins/ai-chat/client/hooks/index.d.cts +1 -1
  81. package/dist/plugins/ai-chat/client/hooks/index.d.mts +1 -1
  82. package/dist/plugins/ai-chat/client/hooks/index.d.ts +1 -1
  83. package/dist/plugins/ai-chat/client/index.d.cts +2 -2
  84. package/dist/plugins/ai-chat/client/index.d.mts +2 -2
  85. package/dist/plugins/ai-chat/client/index.d.ts +2 -2
  86. package/dist/plugins/ai-chat/query-keys.d.cts +1 -1
  87. package/dist/plugins/ai-chat/query-keys.d.mts +1 -1
  88. package/dist/plugins/ai-chat/query-keys.d.ts +1 -1
  89. package/dist/plugins/blog/api/index.cjs +5 -0
  90. package/dist/plugins/blog/api/index.d.cts +19 -4
  91. package/dist/plugins/blog/api/index.d.mts +19 -4
  92. package/dist/plugins/blog/api/index.d.ts +19 -4
  93. package/dist/plugins/blog/api/index.mjs +2 -0
  94. package/dist/plugins/blog/client/hooks/index.d.cts +3 -3
  95. package/dist/plugins/blog/client/hooks/index.d.mts +3 -3
  96. package/dist/plugins/blog/client/hooks/index.d.ts +3 -3
  97. package/dist/plugins/blog/client/index.d.cts +1 -1
  98. package/dist/plugins/blog/client/index.d.mts +1 -1
  99. package/dist/plugins/blog/client/index.d.ts +1 -1
  100. package/dist/plugins/blog/query-keys.cjs +6 -5
  101. package/dist/plugins/blog/query-keys.d.cts +8 -387
  102. package/dist/plugins/blog/query-keys.d.mts +8 -387
  103. package/dist/plugins/blog/query-keys.d.ts +8 -387
  104. package/dist/plugins/blog/query-keys.mjs +6 -5
  105. package/dist/plugins/client/index.cjs +1 -0
  106. package/dist/plugins/client/index.d.cts +8 -1
  107. package/dist/plugins/client/index.d.mts +8 -1
  108. package/dist/plugins/client/index.d.ts +8 -1
  109. package/dist/plugins/client/index.mjs +1 -1
  110. package/dist/plugins/cms/api/index.cjs +8 -0
  111. package/dist/plugins/cms/api/index.d.cts +7 -219
  112. package/dist/plugins/cms/api/index.d.mts +7 -219
  113. package/dist/plugins/cms/api/index.d.ts +7 -219
  114. package/dist/plugins/cms/api/index.mjs +3 -1
  115. package/dist/plugins/cms/client/hooks/index.d.cts +1 -1
  116. package/dist/plugins/cms/client/hooks/index.d.mts +1 -1
  117. package/dist/plugins/cms/client/hooks/index.d.ts +1 -1
  118. package/dist/plugins/cms/query-keys.cjs +2 -1
  119. package/dist/plugins/cms/query-keys.d.cts +5 -9
  120. package/dist/plugins/cms/query-keys.d.mts +5 -9
  121. package/dist/plugins/cms/query-keys.d.ts +5 -9
  122. package/dist/plugins/cms/query-keys.mjs +2 -1
  123. package/dist/plugins/form-builder/api/index.cjs +6 -0
  124. package/dist/plugins/form-builder/api/index.d.cts +7 -211
  125. package/dist/plugins/form-builder/api/index.d.mts +7 -211
  126. package/dist/plugins/form-builder/api/index.d.ts +7 -211
  127. package/dist/plugins/form-builder/api/index.mjs +2 -1
  128. package/dist/plugins/form-builder/client/components/index.d.cts +1 -1
  129. package/dist/plugins/form-builder/client/components/index.d.mts +1 -1
  130. package/dist/plugins/form-builder/client/components/index.d.ts +1 -1
  131. package/dist/plugins/form-builder/client/hooks/index.d.cts +1 -1
  132. package/dist/plugins/form-builder/client/hooks/index.d.mts +1 -1
  133. package/dist/plugins/form-builder/client/hooks/index.d.ts +1 -1
  134. package/dist/plugins/form-builder/query-keys.cjs +3 -2
  135. package/dist/plugins/form-builder/query-keys.d.cts +6 -6
  136. package/dist/plugins/form-builder/query-keys.d.mts +6 -6
  137. package/dist/plugins/form-builder/query-keys.d.ts +6 -6
  138. package/dist/plugins/form-builder/query-keys.mjs +3 -2
  139. package/dist/plugins/kanban/api/index.cjs +10 -0
  140. package/dist/plugins/kanban/api/index.d.cts +17 -392
  141. package/dist/plugins/kanban/api/index.d.mts +17 -392
  142. package/dist/plugins/kanban/api/index.d.ts +17 -392
  143. package/dist/plugins/kanban/api/index.mjs +3 -0
  144. package/dist/plugins/kanban/client/components/index.d.cts +1 -1
  145. package/dist/plugins/kanban/client/components/index.d.mts +1 -1
  146. package/dist/plugins/kanban/client/components/index.d.ts +1 -1
  147. package/dist/plugins/kanban/client/hooks/index.d.cts +1 -1
  148. package/dist/plugins/kanban/client/hooks/index.d.mts +1 -1
  149. package/dist/plugins/kanban/client/hooks/index.d.ts +1 -1
  150. package/dist/plugins/kanban/client/index.d.cts +1 -1
  151. package/dist/plugins/kanban/client/index.d.mts +1 -1
  152. package/dist/plugins/kanban/client/index.d.ts +1 -1
  153. package/dist/plugins/kanban/query-keys.cjs +2 -9
  154. package/dist/plugins/kanban/query-keys.d.cts +4 -16
  155. package/dist/plugins/kanban/query-keys.d.mts +4 -16
  156. package/dist/plugins/kanban/query-keys.d.ts +4 -16
  157. package/dist/plugins/kanban/query-keys.mjs +2 -9
  158. package/dist/plugins/ui-builder/index.d.cts +1 -1
  159. package/dist/plugins/ui-builder/index.d.mts +1 -1
  160. package/dist/plugins/ui-builder/index.d.ts +1 -1
  161. package/dist/shared/stack.B7ONvlD_.d.mts +293 -0
  162. package/dist/shared/{stack.BeSm90va.d.ts → stack.BEn34wW6.d.ts} +60 -2
  163. package/dist/shared/stack.BUkC2EsZ.d.cts +327 -0
  164. package/dist/shared/{stack.DaOcgmrM.d.ts → stack.BV9hnvu4.d.cts} +31 -7
  165. package/dist/shared/{stack.DaOcgmrM.d.cts → stack.BV9hnvu4.d.mts} +31 -7
  166. package/dist/shared/{stack.DaOcgmrM.d.mts → stack.BV9hnvu4.d.ts} +31 -7
  167. package/dist/shared/stack.BepFXT3w.d.mts +500 -0
  168. package/dist/shared/stack.CL8ts1Mu.d.ts +419 -0
  169. package/dist/shared/{stack.CXjzTMsb.d.cts → stack.CVDTkMoO.d.cts} +7 -1
  170. package/dist/shared/{stack.CXjzTMsb.d.mts → stack.CVDTkMoO.d.mts} +7 -1
  171. package/dist/shared/{stack.CXjzTMsb.d.ts → stack.CVDTkMoO.d.ts} +7 -1
  172. package/dist/shared/stack.CczspVn2.d.mts +327 -0
  173. package/dist/shared/stack.CgWzG5jH.d.ts +500 -0
  174. package/dist/shared/stack.D3GB6wKv.d.cts +500 -0
  175. package/dist/shared/stack.DASmUVjX.d.ts +327 -0
  176. package/dist/shared/{stack.QD1y_7NY.d.cts → stack.DJaKVY7v.d.cts} +1 -1
  177. package/dist/shared/{stack.QD1y_7NY.d.mts → stack.DJaKVY7v.d.mts} +1 -1
  178. package/dist/shared/{stack.QD1y_7NY.d.ts → stack.DJaKVY7v.d.ts} +1 -1
  179. package/dist/shared/{stack.Dg09R0oB.d.mts → stack.DTDxgFj8.d.mts} +60 -2
  180. package/dist/shared/{stack.CMh_EdxW.d.cts → stack.DWoCZff7.d.cts} +60 -2
  181. package/dist/shared/{stack.CIrIsc-A.d.cts → stack.DdI5W6MB.d.cts} +7 -1
  182. package/dist/shared/{stack.CIrIsc-A.d.mts → stack.DdI5W6MB.d.mts} +7 -1
  183. package/dist/shared/{stack.CIrIsc-A.d.ts → stack.DdI5W6MB.d.ts} +7 -1
  184. package/dist/shared/stack.Dk5r4W1F.d.mts +419 -0
  185. package/dist/shared/stack.Kq2-QzOC.d.ts +293 -0
  186. package/dist/shared/stack.heOA9gzA.d.cts +419 -0
  187. package/dist/shared/stack.kcdnD4gA.d.cts +293 -0
  188. package/package.json +16 -3
  189. package/src/client/components/compose.tsx +7 -4
  190. package/src/plugins/ai-chat/api/page-tools.ts +111 -0
  191. package/src/plugins/ai-chat/api/plugin.ts +180 -9
  192. package/src/plugins/ai-chat/client/components/chat-input.tsx +2 -2
  193. package/src/plugins/ai-chat/client/components/chat-interface.tsx +154 -58
  194. package/src/plugins/ai-chat/client/components/chat-layout.tsx +166 -32
  195. package/src/plugins/ai-chat/client/components/chat-sidebar.tsx +1 -1
  196. package/src/plugins/ai-chat/client/context/page-ai-context.tsx +240 -0
  197. package/src/plugins/ai-chat/schemas.ts +16 -0
  198. package/src/plugins/blog/api/index.ts +2 -0
  199. package/src/plugins/blog/api/plugin.ts +85 -0
  200. package/src/plugins/blog/api/query-key-defs.ts +46 -0
  201. package/src/plugins/blog/api/serializers.ts +27 -0
  202. package/src/plugins/blog/client/components/forms/post-forms.tsx +29 -2
  203. package/src/plugins/blog/client/components/pages/edit-post-page.internal.tsx +28 -0
  204. package/src/plugins/blog/client/components/pages/fill-blog-form-handler.ts +38 -0
  205. package/src/plugins/blog/client/components/pages/new-post-page.internal.tsx +33 -1
  206. package/src/plugins/blog/client/components/pages/post-page.internal.tsx +20 -0
  207. package/src/plugins/blog/client/plugin.tsx +19 -0
  208. package/src/plugins/blog/query-keys.ts +5 -7
  209. package/src/plugins/client/index.ts +1 -1
  210. package/src/plugins/cms/api/getters.ts +24 -0
  211. package/src/plugins/cms/api/index.ts +14 -1
  212. package/src/plugins/cms/api/mutations.ts +84 -0
  213. package/src/plugins/cms/api/plugin.ts +114 -0
  214. package/src/plugins/cms/api/query-key-defs.ts +53 -0
  215. package/src/plugins/cms/api/serializers.ts +12 -0
  216. package/src/plugins/cms/client/plugin.tsx +19 -0
  217. package/src/plugins/cms/query-keys.ts +2 -1
  218. package/src/plugins/form-builder/api/getters.ts +23 -0
  219. package/src/plugins/form-builder/api/index.ts +15 -2
  220. package/src/plugins/form-builder/api/plugin.ts +91 -0
  221. package/src/plugins/form-builder/api/query-key-defs.ts +79 -0
  222. package/src/plugins/form-builder/api/serializers.ts +12 -0
  223. package/src/plugins/form-builder/client/plugin.tsx +19 -0
  224. package/src/plugins/form-builder/query-keys.ts +6 -2
  225. package/src/plugins/kanban/api/index.ts +9 -0
  226. package/src/plugins/kanban/api/mutations.ts +169 -0
  227. package/src/plugins/kanban/api/plugin.ts +61 -0
  228. package/src/plugins/kanban/api/query-key-defs.ts +54 -0
  229. package/src/plugins/kanban/api/serializers.ts +49 -0
  230. package/src/plugins/kanban/client/hooks/kanban-hooks.tsx +4 -0
  231. package/src/plugins/kanban/client/plugin.tsx +13 -0
  232. package/src/plugins/kanban/query-keys.ts +2 -9
  233. package/src/plugins/ui-builder/client/components/pages/page-builder-page.internal.tsx +132 -0
  234. package/src/plugins/utils.ts +19 -0
  235. package/dist/shared/{stack.BkYlUT_8.d.cts → stack.BQmuNl5p.d.cts} +6 -6
  236. package/dist/shared/{stack.BkYlUT_8.d.mts → stack.BQmuNl5p.d.mts} +6 -6
  237. package/dist/shared/{stack.BkYlUT_8.d.ts → stack.BQmuNl5p.d.ts} +6 -6
@@ -1,5 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { defineClientPlugin, createApiClient } from '@btst/stack/plugins/client';
2
+ import { defineClientPlugin, createApiClient, isConnectionError } from '@btst/stack/plugins/client';
3
3
  import { createRoute } from '@btst/yar';
4
4
  import { createBlogQueryKeys } from '../../../../../../plugins/blog/query-keys.mjs';
5
5
  import { HomePageComponent } from './components/pages/home-page.mjs';
@@ -62,6 +62,11 @@ function createPostsLoader(published, config) {
62
62
  }
63
63
  }
64
64
  } catch (error) {
65
+ if (isConnectionError(error)) {
66
+ console.warn(
67
+ "[btst/blog] route.loader() failed \u2014 no server running at build time. Use myStack.api.blog.prefetchForRoute() for SSG data prefetching."
68
+ );
69
+ }
65
70
  if (hooks?.onLoadError) {
66
71
  await hooks.onLoadError(error, context);
67
72
  }
@@ -110,6 +115,11 @@ function createPostLoader(slug, config, path) {
110
115
  }
111
116
  }
112
117
  } catch (error) {
118
+ if (isConnectionError(error)) {
119
+ console.warn(
120
+ "[btst/blog] route.loader() failed \u2014 no server running at build time. Use myStack.api.blog.prefetchForRoute() for SSG data prefetching."
121
+ );
122
+ }
113
123
  if (hooks?.onLoadError) {
114
124
  await hooks.onLoadError(error, context);
115
125
  }
@@ -188,6 +198,11 @@ function createTagLoader(tagSlug, config) {
188
198
  await hooks.onLoadError(error, context);
189
199
  }
190
200
  } catch (error) {
201
+ if (isConnectionError(error)) {
202
+ console.warn(
203
+ "[btst/blog] route.loader() failed \u2014 no server running at build time. Use myStack.api.blog.prefetchForRoute() for SSG data prefetching."
204
+ );
205
+ }
191
206
  if (hooks?.onLoadError) {
192
207
  await hooks.onLoadError(error, context);
193
208
  }
@@ -105,6 +105,15 @@ async function getAllContentItems(adapter, contentTypeSlug, params) {
105
105
  offset: params?.offset
106
106
  };
107
107
  }
108
+ async function getContentItemById(adapter, id) {
109
+ const item = await adapter.findOne({
110
+ model: "contentItem",
111
+ where: [{ field: "id", value: id, operator: "eq" }],
112
+ join: { contentType: true }
113
+ });
114
+ if (!item) return null;
115
+ return serializeContentItemWithType(item);
116
+ }
108
117
  async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
109
118
  const contentType = await adapter.findOne({
110
119
  model: "contentType",
@@ -139,6 +148,7 @@ async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
139
148
 
140
149
  exports.getAllContentItems = getAllContentItems;
141
150
  exports.getAllContentTypes = getAllContentTypes;
151
+ exports.getContentItemById = getContentItemById;
142
152
  exports.getContentItemBySlug = getContentItemBySlug;
143
153
  exports.migrateToUnifiedSchema = migrateToUnifiedSchema;
144
154
  exports.serializeContentItem = serializeContentItem;
@@ -103,6 +103,15 @@ async function getAllContentItems(adapter, contentTypeSlug, params) {
103
103
  offset: params?.offset
104
104
  };
105
105
  }
106
+ async function getContentItemById(adapter, id) {
107
+ const item = await adapter.findOne({
108
+ model: "contentItem",
109
+ where: [{ field: "id", value: id, operator: "eq" }],
110
+ join: { contentType: true }
111
+ });
112
+ if (!item) return null;
113
+ return serializeContentItemWithType(item);
114
+ }
106
115
  async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
107
116
  const contentType = await adapter.findOne({
108
117
  model: "contentType",
@@ -135,4 +144,4 @@ async function getContentItemBySlug(adapter, contentTypeSlug, slug) {
135
144
  return serializeContentItemWithType(item);
136
145
  }
137
146
 
138
- export { getAllContentItems, getAllContentTypes, getContentItemBySlug, migrateToUnifiedSchema, serializeContentItem, serializeContentItemWithType, serializeContentType };
147
+ export { getAllContentItems, getAllContentTypes, getContentItemById, getContentItemBySlug, migrateToUnifiedSchema, serializeContentItem, serializeContentItemWithType, serializeContentType };
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ const getters = require('./getters.cjs');
4
+
5
+ async function createCMSContentItem(adapter, contentTypeSlug, input) {
6
+ const contentType = await adapter.findOne({
7
+ model: "contentType",
8
+ where: [
9
+ {
10
+ field: "slug",
11
+ value: contentTypeSlug,
12
+ operator: "eq"
13
+ }
14
+ ]
15
+ });
16
+ if (!contentType) {
17
+ throw new Error(`Content type "${contentTypeSlug}" not found`);
18
+ }
19
+ const existing = await adapter.findOne({
20
+ model: "contentItem",
21
+ where: [
22
+ {
23
+ field: "contentTypeId",
24
+ value: contentType.id,
25
+ operator: "eq"
26
+ },
27
+ { field: "slug", value: input.slug, operator: "eq" }
28
+ ]
29
+ });
30
+ if (existing) {
31
+ throw new Error(
32
+ `Content item with slug "${input.slug}" already exists in type "${contentTypeSlug}"`
33
+ );
34
+ }
35
+ const item = await adapter.create({
36
+ model: "contentItem",
37
+ data: {
38
+ contentTypeId: contentType.id,
39
+ slug: input.slug,
40
+ data: JSON.stringify(input.data),
41
+ createdAt: /* @__PURE__ */ new Date(),
42
+ updatedAt: /* @__PURE__ */ new Date()
43
+ }
44
+ });
45
+ return getters.serializeContentItem(item);
46
+ }
47
+
48
+ exports.createCMSContentItem = createCMSContentItem;
@@ -0,0 +1,46 @@
1
+ import { serializeContentItem } from './getters.mjs';
2
+
3
+ async function createCMSContentItem(adapter, contentTypeSlug, input) {
4
+ const contentType = await adapter.findOne({
5
+ model: "contentType",
6
+ where: [
7
+ {
8
+ field: "slug",
9
+ value: contentTypeSlug,
10
+ operator: "eq"
11
+ }
12
+ ]
13
+ });
14
+ if (!contentType) {
15
+ throw new Error(`Content type "${contentTypeSlug}" not found`);
16
+ }
17
+ const existing = await adapter.findOne({
18
+ model: "contentItem",
19
+ where: [
20
+ {
21
+ field: "contentTypeId",
22
+ value: contentType.id,
23
+ operator: "eq"
24
+ },
25
+ { field: "slug", value: input.slug, operator: "eq" }
26
+ ]
27
+ });
28
+ if (existing) {
29
+ throw new Error(
30
+ `Content item with slug "${input.slug}" already exists in type "${contentTypeSlug}"`
31
+ );
32
+ }
33
+ const item = await adapter.create({
34
+ model: "contentItem",
35
+ data: {
36
+ contentTypeId: contentType.id,
37
+ slug: input.slug,
38
+ data: JSON.stringify(input.data),
39
+ createdAt: /* @__PURE__ */ new Date(),
40
+ updatedAt: /* @__PURE__ */ new Date()
41
+ }
42
+ });
43
+ return serializeContentItem(item);
44
+ }
45
+
46
+ export { createCMSContentItem };
@@ -7,6 +7,8 @@ const db = require('../db.cjs');
7
7
  const schemas = require('../schemas.cjs');
8
8
  const utils = require('../utils.cjs');
9
9
  const getters = require('./getters.cjs');
10
+ const mutations = require('./mutations.cjs');
11
+ const queryKeyDefs = require('./query-key-defs.cjs');
10
12
 
11
13
  async function syncContentTypes(adapter, config) {
12
14
  for (const ct of config.contentTypes) {
@@ -243,6 +245,69 @@ const cmsBackendPlugin = (config) => {
243
245
  }
244
246
  return syncPromise;
245
247
  };
248
+ const getContentTypesWithCounts = async (adapter) => {
249
+ const contentTypes = await getters.getAllContentTypes(adapter);
250
+ return Promise.all(
251
+ contentTypes.map(async (ct) => {
252
+ const count = await adapter.count({
253
+ model: "contentItem",
254
+ where: [
255
+ { field: "contentTypeId", value: ct.id, operator: "eq" }
256
+ ]
257
+ });
258
+ return { ...ct, itemCount: count };
259
+ })
260
+ );
261
+ };
262
+ const createCMSPrefetchForRoute = (adapter) => {
263
+ return async function prefetchForRoute(key, qc, params) {
264
+ await ensureSynced(adapter);
265
+ switch (key) {
266
+ case "dashboard":
267
+ case "newContent": {
268
+ const typesWithCounts = await getContentTypesWithCounts(adapter);
269
+ qc.setQueryData(queryKeyDefs.CMS_QUERY_KEYS.typesList(), typesWithCounts);
270
+ break;
271
+ }
272
+ case "contentList": {
273
+ const typeSlug = params?.typeSlug ?? "";
274
+ const [contentTypes, contentItems] = await Promise.all([
275
+ getContentTypesWithCounts(adapter),
276
+ getters.getAllContentItems(adapter, typeSlug, { limit: 20, offset: 0 })
277
+ ]);
278
+ qc.setQueryData(queryKeyDefs.CMS_QUERY_KEYS.typesList(), contentTypes);
279
+ qc.setQueryData(
280
+ queryKeyDefs.CMS_QUERY_KEYS.contentList({ typeSlug, limit: 20, offset: 0 }),
281
+ {
282
+ pages: [
283
+ {
284
+ items: contentItems.items,
285
+ total: contentItems.total,
286
+ limit: contentItems.limit ?? 20,
287
+ offset: contentItems.offset ?? 0
288
+ }
289
+ ],
290
+ pageParams: [0]
291
+ }
292
+ );
293
+ break;
294
+ }
295
+ case "editContent": {
296
+ const typeSlug = params?.typeSlug ?? "";
297
+ const id = params?.id ?? "";
298
+ const [contentTypes, item] = await Promise.all([
299
+ getContentTypesWithCounts(adapter),
300
+ id ? getters.getContentItemById(adapter, id) : Promise.resolve(null)
301
+ ]);
302
+ qc.setQueryData(queryKeyDefs.CMS_QUERY_KEYS.typesList(), contentTypes);
303
+ if (id) {
304
+ qc.setQueryData(queryKeyDefs.CMS_QUERY_KEYS.contentDetail(typeSlug, id), item);
305
+ }
306
+ break;
307
+ }
308
+ }
309
+ };
310
+ };
246
311
  return api.defineBackendPlugin({
247
312
  name: "cms",
248
313
  dbPlugin: db.cmsSchema,
@@ -258,6 +323,16 @@ const cmsBackendPlugin = (config) => {
258
323
  getContentItemBySlug: async (contentTypeSlug, slug) => {
259
324
  await ensureSynced(adapter);
260
325
  return getters.getContentItemBySlug(adapter, contentTypeSlug, slug);
326
+ },
327
+ getContentItemById: async (id) => {
328
+ await ensureSynced(adapter);
329
+ return getters.getContentItemById(adapter, id);
330
+ },
331
+ prefetchForRoute: createCMSPrefetchForRoute(adapter),
332
+ // Mutations
333
+ createContentItem: async (typeSlug, input) => {
334
+ await ensureSynced(adapter);
335
+ return mutations.createCMSContentItem(adapter, typeSlug, input);
261
336
  }
262
337
  }),
263
338
  routes: (adapter) => {
@@ -4,7 +4,9 @@ import { formSchemaToZod, zodToFormSchema } from '../../../../../ui/src/lib/sche
4
4
  import { cmsSchema } from '../db.mjs';
5
5
  import { listContentQuerySchema } from '../schemas.mjs';
6
6
  import { slugify } from '../utils.mjs';
7
- import { serializeContentType, getAllContentItems, serializeContentItemWithType, serializeContentItem, getContentItemBySlug, getAllContentTypes } from './getters.mjs';
7
+ import { serializeContentType, getAllContentItems, serializeContentItemWithType, serializeContentItem, getContentItemById, getContentItemBySlug, getAllContentTypes } from './getters.mjs';
8
+ import { createCMSContentItem } from './mutations.mjs';
9
+ import { CMS_QUERY_KEYS } from './query-key-defs.mjs';
8
10
 
9
11
  async function syncContentTypes(adapter, config) {
10
12
  for (const ct of config.contentTypes) {
@@ -241,6 +243,69 @@ const cmsBackendPlugin = (config) => {
241
243
  }
242
244
  return syncPromise;
243
245
  };
246
+ const getContentTypesWithCounts = async (adapter) => {
247
+ const contentTypes = await getAllContentTypes(adapter);
248
+ return Promise.all(
249
+ contentTypes.map(async (ct) => {
250
+ const count = await adapter.count({
251
+ model: "contentItem",
252
+ where: [
253
+ { field: "contentTypeId", value: ct.id, operator: "eq" }
254
+ ]
255
+ });
256
+ return { ...ct, itemCount: count };
257
+ })
258
+ );
259
+ };
260
+ const createCMSPrefetchForRoute = (adapter) => {
261
+ return async function prefetchForRoute(key, qc, params) {
262
+ await ensureSynced(adapter);
263
+ switch (key) {
264
+ case "dashboard":
265
+ case "newContent": {
266
+ const typesWithCounts = await getContentTypesWithCounts(adapter);
267
+ qc.setQueryData(CMS_QUERY_KEYS.typesList(), typesWithCounts);
268
+ break;
269
+ }
270
+ case "contentList": {
271
+ const typeSlug = params?.typeSlug ?? "";
272
+ const [contentTypes, contentItems] = await Promise.all([
273
+ getContentTypesWithCounts(adapter),
274
+ getAllContentItems(adapter, typeSlug, { limit: 20, offset: 0 })
275
+ ]);
276
+ qc.setQueryData(CMS_QUERY_KEYS.typesList(), contentTypes);
277
+ qc.setQueryData(
278
+ CMS_QUERY_KEYS.contentList({ typeSlug, limit: 20, offset: 0 }),
279
+ {
280
+ pages: [
281
+ {
282
+ items: contentItems.items,
283
+ total: contentItems.total,
284
+ limit: contentItems.limit ?? 20,
285
+ offset: contentItems.offset ?? 0
286
+ }
287
+ ],
288
+ pageParams: [0]
289
+ }
290
+ );
291
+ break;
292
+ }
293
+ case "editContent": {
294
+ const typeSlug = params?.typeSlug ?? "";
295
+ const id = params?.id ?? "";
296
+ const [contentTypes, item] = await Promise.all([
297
+ getContentTypesWithCounts(adapter),
298
+ id ? getContentItemById(adapter, id) : Promise.resolve(null)
299
+ ]);
300
+ qc.setQueryData(CMS_QUERY_KEYS.typesList(), contentTypes);
301
+ if (id) {
302
+ qc.setQueryData(CMS_QUERY_KEYS.contentDetail(typeSlug, id), item);
303
+ }
304
+ break;
305
+ }
306
+ }
307
+ };
308
+ };
244
309
  return defineBackendPlugin({
245
310
  name: "cms",
246
311
  dbPlugin: cmsSchema,
@@ -256,6 +321,16 @@ const cmsBackendPlugin = (config) => {
256
321
  getContentItemBySlug: async (contentTypeSlug, slug) => {
257
322
  await ensureSynced(adapter);
258
323
  return getContentItemBySlug(adapter, contentTypeSlug, slug);
324
+ },
325
+ getContentItemById: async (id) => {
326
+ await ensureSynced(adapter);
327
+ return getContentItemById(adapter, id);
328
+ },
329
+ prefetchForRoute: createCMSPrefetchForRoute(adapter),
330
+ // Mutations
331
+ createContentItem: async (typeSlug, input) => {
332
+ await ensureSynced(adapter);
333
+ return createCMSContentItem(adapter, typeSlug, input);
259
334
  }
260
335
  }),
261
336
  routes: (adapter) => {
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ function contentListDiscriminator(params) {
4
+ return {
5
+ typeSlug: params.typeSlug,
6
+ limit: params.limit ?? 20,
7
+ offset: params.offset ?? 0
8
+ };
9
+ }
10
+ const CMS_QUERY_KEYS = {
11
+ /**
12
+ * Key for the cmsTypes.list() query.
13
+ * Full key: ["cmsTypes", "list", "list"]
14
+ */
15
+ typesList: () => ["cmsTypes", "list", "list"],
16
+ /**
17
+ * Key for the cmsContent.list({ typeSlug, limit, offset }) query.
18
+ * Full key: ["cmsContent", "list", { typeSlug, limit, offset }]
19
+ */
20
+ contentList: (params) => ["cmsContent", "list", contentListDiscriminator(params)],
21
+ /**
22
+ * Key for the cmsContent.detail(typeSlug, id) query.
23
+ * Full key: ["cmsContent", "detail", typeSlug, id]
24
+ */
25
+ contentDetail: (typeSlug, id) => ["cmsContent", "detail", typeSlug, id]
26
+ };
27
+
28
+ exports.CMS_QUERY_KEYS = CMS_QUERY_KEYS;
29
+ exports.contentListDiscriminator = contentListDiscriminator;
@@ -0,0 +1,26 @@
1
+ function contentListDiscriminator(params) {
2
+ return {
3
+ typeSlug: params.typeSlug,
4
+ limit: params.limit ?? 20,
5
+ offset: params.offset ?? 0
6
+ };
7
+ }
8
+ const CMS_QUERY_KEYS = {
9
+ /**
10
+ * Key for the cmsTypes.list() query.
11
+ * Full key: ["cmsTypes", "list", "list"]
12
+ */
13
+ typesList: () => ["cmsTypes", "list", "list"],
14
+ /**
15
+ * Key for the cmsContent.list({ typeSlug, limit, offset }) query.
16
+ * Full key: ["cmsContent", "list", { typeSlug, limit, offset }]
17
+ */
18
+ contentList: (params) => ["cmsContent", "list", contentListDiscriminator(params)],
19
+ /**
20
+ * Key for the cmsContent.detail(typeSlug, id) query.
21
+ * Full key: ["cmsContent", "detail", typeSlug, id]
22
+ */
23
+ contentDetail: (typeSlug, id) => ["cmsContent", "detail", typeSlug, id]
24
+ };
25
+
26
+ export { CMS_QUERY_KEYS, contentListDiscriminator };
@@ -56,6 +56,11 @@ function createDashboardLoader(config) {
56
56
  await hooks.onLoadError(error, context);
57
57
  }
58
58
  } catch (error) {
59
+ if (client.isConnectionError(error)) {
60
+ console.warn(
61
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
62
+ );
63
+ }
59
64
  if (hooks?.onLoadError) {
60
65
  await hooks.onLoadError(error, context);
61
66
  }
@@ -123,6 +128,11 @@ function createContentListLoader(typeSlug, config) {
123
128
  await hooks.onLoadError(error, context);
124
129
  }
125
130
  } catch (error) {
131
+ if (client.isConnectionError(error)) {
132
+ console.warn(
133
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
134
+ );
135
+ }
126
136
  if (hooks?.onLoadError) {
127
137
  await hooks.onLoadError(error, context);
128
138
  }
@@ -180,6 +190,11 @@ function createContentEditorLoader(typeSlug, id, config) {
180
190
  await hooks.onLoadError(error, context);
181
191
  }
182
192
  } catch (error) {
193
+ if (client.isConnectionError(error)) {
194
+ console.warn(
195
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
196
+ );
197
+ }
183
198
  if (hooks?.onLoadError) {
184
199
  await hooks.onLoadError(error, context);
185
200
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { lazy } from 'react';
3
- import { defineClientPlugin, createApiClient } from '@btst/stack/plugins/client';
3
+ import { defineClientPlugin, createApiClient, isConnectionError } from '@btst/stack/plugins/client';
4
4
  import { createRoute } from '@btst/yar';
5
5
  import { createCMSQueryKeys } from '../../../../../../plugins/cms/query-keys.mjs';
6
6
 
@@ -54,6 +54,11 @@ function createDashboardLoader(config) {
54
54
  await hooks.onLoadError(error, context);
55
55
  }
56
56
  } catch (error) {
57
+ if (isConnectionError(error)) {
58
+ console.warn(
59
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
60
+ );
61
+ }
57
62
  if (hooks?.onLoadError) {
58
63
  await hooks.onLoadError(error, context);
59
64
  }
@@ -121,6 +126,11 @@ function createContentListLoader(typeSlug, config) {
121
126
  await hooks.onLoadError(error, context);
122
127
  }
123
128
  } catch (error) {
129
+ if (isConnectionError(error)) {
130
+ console.warn(
131
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
132
+ );
133
+ }
124
134
  if (hooks?.onLoadError) {
125
135
  await hooks.onLoadError(error, context);
126
136
  }
@@ -178,6 +188,11 @@ function createContentEditorLoader(typeSlug, id, config) {
178
188
  await hooks.onLoadError(error, context);
179
189
  }
180
190
  } catch (error) {
191
+ if (isConnectionError(error)) {
192
+ console.warn(
193
+ "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
194
+ );
195
+ }
181
196
  if (hooks?.onLoadError) {
182
197
  await hooks.onLoadError(error, context);
183
198
  }
@@ -60,6 +60,14 @@ async function getAllForms(adapter, params) {
60
60
  offset: params?.offset
61
61
  };
62
62
  }
63
+ async function getFormById(adapter, id) {
64
+ const form = await adapter.findOne({
65
+ model: "form",
66
+ where: [{ field: "id", value: id, operator: "eq" }]
67
+ });
68
+ if (!form) return null;
69
+ return serializeForm(form);
70
+ }
63
71
  async function getFormBySlug(adapter, slug) {
64
72
  const form = await adapter.findOne({
65
73
  model: "form",
@@ -104,6 +112,7 @@ async function getFormSubmissions(adapter, formId, params) {
104
112
  }
105
113
 
106
114
  exports.getAllForms = getAllForms;
115
+ exports.getFormById = getFormById;
107
116
  exports.getFormBySlug = getFormBySlug;
108
117
  exports.getFormSubmissions = getFormSubmissions;
109
118
  exports.serializeForm = serializeForm;
@@ -58,6 +58,14 @@ async function getAllForms(adapter, params) {
58
58
  offset: params?.offset
59
59
  };
60
60
  }
61
+ async function getFormById(adapter, id) {
62
+ const form = await adapter.findOne({
63
+ model: "form",
64
+ where: [{ field: "id", value: id, operator: "eq" }]
65
+ });
66
+ if (!form) return null;
67
+ return serializeForm(form);
68
+ }
61
69
  async function getFormBySlug(adapter, slug) {
62
70
  const form = await adapter.findOne({
63
71
  model: "form",
@@ -101,4 +109,4 @@ async function getFormSubmissions(adapter, formId, params) {
101
109
  };
102
110
  }
103
111
 
104
- export { getAllForms, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionWithData };
112
+ export { getAllForms, getFormById, getFormBySlug, getFormSubmissions, serializeForm, serializeFormSubmission, serializeFormSubmissionWithData };
@@ -7,14 +7,75 @@ const db = require('../db.cjs');
7
7
  const schemas = require('../schemas.cjs');
8
8
  const utils = require('../utils.cjs');
9
9
  const getters = require('./getters.cjs');
10
+ const queryKeyDefs = require('./query-key-defs.cjs');
10
11
 
12
+ function createFormBuilderPrefetchForRoute(adapter) {
13
+ return async function prefetchForRoute(key, qc, params) {
14
+ switch (key) {
15
+ case "formList": {
16
+ const result = await getters.getAllForms(adapter, { limit: 20, offset: 0 });
17
+ qc.setQueryData(queryKeyDefs.FORM_QUERY_KEYS.formsList({ limit: 20, offset: 0 }), {
18
+ pages: [
19
+ {
20
+ items: result.items,
21
+ total: result.total,
22
+ limit: result.limit ?? 20,
23
+ offset: result.offset ?? 0
24
+ }
25
+ ],
26
+ pageParams: [0]
27
+ });
28
+ break;
29
+ }
30
+ case "editForm": {
31
+ const id = params?.id ?? "";
32
+ if (id) {
33
+ const form = await getters.getFormById(adapter, id);
34
+ qc.setQueryData(queryKeyDefs.FORM_QUERY_KEYS.formById(id), form);
35
+ }
36
+ break;
37
+ }
38
+ case "submissions": {
39
+ const id = params?.id ?? "";
40
+ if (id) {
41
+ const [form, submissionsResult] = await Promise.all([
42
+ getters.getFormById(adapter, id),
43
+ getters.getFormSubmissions(adapter, id, { limit: 20, offset: 0 })
44
+ ]);
45
+ qc.setQueryData(queryKeyDefs.FORM_QUERY_KEYS.formById(id), form);
46
+ qc.setQueryData(
47
+ queryKeyDefs.FORM_QUERY_KEYS.submissionsList({
48
+ formId: id,
49
+ limit: 20,
50
+ offset: 0
51
+ }),
52
+ {
53
+ pages: [
54
+ {
55
+ items: submissionsResult.items,
56
+ total: submissionsResult.total,
57
+ limit: submissionsResult.limit ?? 20,
58
+ offset: submissionsResult.offset ?? 0
59
+ }
60
+ ],
61
+ pageParams: [0]
62
+ }
63
+ );
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ };
69
+ }
11
70
  const formBuilderBackendPlugin = (config = {}) => api.defineBackendPlugin({
12
71
  name: "form-builder",
13
72
  dbPlugin: db.formBuilderSchema,
14
73
  api: (adapter) => ({
15
74
  getAllForms: (params) => getters.getAllForms(adapter, params),
75
+ getFormById: (id) => getters.getFormById(adapter, id),
16
76
  getFormBySlug: (slug) => getters.getFormBySlug(adapter, slug),
17
- getFormSubmissions: (formId, params) => getters.getFormSubmissions(adapter, formId, params)
77
+ getFormSubmissions: (formId, params) => getters.getFormSubmissions(adapter, formId, params),
78
+ prefetchForRoute: createFormBuilderPrefetchForRoute(adapter)
18
79
  }),
19
80
  routes: (adapter) => {
20
81
  const createContext = (headers) => ({