@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
@@ -4,38 +4,77 @@ import { formSchemaToZod } from '../../../../../ui/src/lib/schema-converter.mjs'
4
4
  import { formBuilderSchema } from '../db.mjs';
5
5
  import { listFormsQuerySchema, createFormSchema, updateFormSchema, listSubmissionsQuerySchema } from '../schemas.mjs';
6
6
  import { extractUserAgent, extractIpAddress, slugify } from '../utils.mjs';
7
+ import { getFormSubmissions, getFormBySlug, getFormById, getAllForms, serializeForm, serializeFormSubmission, serializeFormSubmissionWithData } from './getters.mjs';
8
+ import { FORM_QUERY_KEYS } from './query-key-defs.mjs';
7
9
 
8
- function serializeForm(form) {
9
- return {
10
- id: form.id,
11
- name: form.name,
12
- slug: form.slug,
13
- description: form.description,
14
- schema: form.schema,
15
- successMessage: form.successMessage,
16
- redirectUrl: form.redirectUrl,
17
- status: form.status,
18
- createdBy: form.createdBy,
19
- createdAt: form.createdAt.toISOString(),
20
- updatedAt: form.updatedAt.toISOString()
21
- };
22
- }
23
- function serializeFormSubmission(submission) {
24
- return {
25
- ...submission,
26
- submittedAt: submission.submittedAt.toISOString()
27
- };
28
- }
29
- function serializeFormSubmissionWithData(submission) {
30
- return {
31
- ...serializeFormSubmission(submission),
32
- parsedData: JSON.parse(submission.data),
33
- form: submission.form ? serializeForm(submission.form) : void 0
10
+ function createFormBuilderPrefetchForRoute(adapter) {
11
+ return async function prefetchForRoute(key, qc, params) {
12
+ switch (key) {
13
+ case "formList": {
14
+ const result = await getAllForms(adapter, { limit: 20, offset: 0 });
15
+ qc.setQueryData(FORM_QUERY_KEYS.formsList({ limit: 20, offset: 0 }), {
16
+ pages: [
17
+ {
18
+ items: result.items,
19
+ total: result.total,
20
+ limit: result.limit ?? 20,
21
+ offset: result.offset ?? 0
22
+ }
23
+ ],
24
+ pageParams: [0]
25
+ });
26
+ break;
27
+ }
28
+ case "editForm": {
29
+ const id = params?.id ?? "";
30
+ if (id) {
31
+ const form = await getFormById(adapter, id);
32
+ qc.setQueryData(FORM_QUERY_KEYS.formById(id), form);
33
+ }
34
+ break;
35
+ }
36
+ case "submissions": {
37
+ const id = params?.id ?? "";
38
+ if (id) {
39
+ const [form, submissionsResult] = await Promise.all([
40
+ getFormById(adapter, id),
41
+ getFormSubmissions(adapter, id, { limit: 20, offset: 0 })
42
+ ]);
43
+ qc.setQueryData(FORM_QUERY_KEYS.formById(id), form);
44
+ qc.setQueryData(
45
+ FORM_QUERY_KEYS.submissionsList({
46
+ formId: id,
47
+ limit: 20,
48
+ offset: 0
49
+ }),
50
+ {
51
+ pages: [
52
+ {
53
+ items: submissionsResult.items,
54
+ total: submissionsResult.total,
55
+ limit: submissionsResult.limit ?? 20,
56
+ offset: submissionsResult.offset ?? 0
57
+ }
58
+ ],
59
+ pageParams: [0]
60
+ }
61
+ );
62
+ }
63
+ break;
64
+ }
65
+ }
34
66
  };
35
67
  }
36
68
  const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
37
69
  name: "form-builder",
38
70
  dbPlugin: formBuilderSchema,
71
+ api: (adapter) => ({
72
+ getAllForms: (params) => getAllForms(adapter, params),
73
+ getFormById: (id) => getFormById(adapter, id),
74
+ getFormBySlug: (slug) => getFormBySlug(adapter, slug),
75
+ getFormSubmissions: (formId, params) => getFormSubmissions(adapter, formId, params),
76
+ prefetchForRoute: createFormBuilderPrefetchForRoute(adapter)
77
+ }),
39
78
  routes: (adapter) => {
40
79
  const createContext = (headers) => ({
41
80
  headers,
@@ -62,35 +101,10 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
62
101
  throw ctx.error(403, { message: "Access denied" });
63
102
  }
64
103
  }
65
- const whereConditions = [];
66
- if (status) {
67
- whereConditions.push({
68
- field: "status",
69
- value: status,
70
- operator: "eq"
71
- });
72
- }
73
- const allForms = await adapter.findMany({
74
- model: "form",
75
- where: whereConditions.length > 0 ? whereConditions : void 0
76
- });
77
- const total = allForms.length;
78
- const forms = await adapter.findMany({
79
- model: "form",
80
- where: whereConditions.length > 0 ? whereConditions : void 0,
81
- limit,
82
- offset,
83
- sortBy: { field: "createdAt", direction: "desc" }
84
- });
85
- return {
86
- items: forms.map(serializeForm),
87
- total,
88
- limit,
89
- offset
90
- };
104
+ return getAllForms(adapter, { status, limit, offset });
91
105
  }
92
106
  );
93
- const getFormBySlug = createEndpoint(
107
+ const getFormBySlug$1 = createEndpoint(
94
108
  "/forms/:slug",
95
109
  {
96
110
  method: "GET",
@@ -105,14 +119,11 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
105
119
  throw ctx.error(403, { message: "Access denied" });
106
120
  }
107
121
  }
108
- const form = await adapter.findOne({
109
- model: "form",
110
- where: [{ field: "slug", value: slug, operator: "eq" }]
111
- });
122
+ const form = await getFormBySlug(adapter, slug);
112
123
  if (!form) {
113
124
  throw ctx.error(404, { message: "Form not found" });
114
125
  }
115
- return serializeForm(form);
126
+ return form;
116
127
  }
117
128
  );
118
129
  const getFormById = createEndpoint(
@@ -479,29 +490,7 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
479
490
  throw ctx.error(403, { message: "Access denied" });
480
491
  }
481
492
  }
482
- const allSubmissions = await adapter.findMany({
483
- model: "formSubmission",
484
- where: [
485
- { field: "formId", value: formId, operator: "eq" }
486
- ]
487
- });
488
- const total = allSubmissions.length;
489
- const submissions = await adapter.findMany({
490
- model: "formSubmission",
491
- where: [
492
- { field: "formId", value: formId, operator: "eq" }
493
- ],
494
- limit,
495
- offset,
496
- sortBy: { field: "submittedAt", direction: "desc" },
497
- join: { form: true }
498
- });
499
- return {
500
- items: submissions.map(serializeFormSubmissionWithData),
501
- total,
502
- limit,
503
- offset
504
- };
493
+ return getFormSubmissions(adapter, formId, { limit, offset });
505
494
  }
506
495
  );
507
496
  const getSubmission = createEndpoint(
@@ -570,7 +559,7 @@ const formBuilderBackendPlugin = (config = {}) => defineBackendPlugin({
570
559
  );
571
560
  return {
572
561
  listForms,
573
- getFormBySlug,
562
+ getFormBySlug: getFormBySlug$1,
574
563
  getFormById,
575
564
  createForm,
576
565
  updateForm,
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ function formsListDiscriminator(params) {
4
+ return {
5
+ status: params?.status,
6
+ limit: params?.limit ?? 20,
7
+ offset: params?.offset ?? 0
8
+ };
9
+ }
10
+ function submissionsListDiscriminator(params) {
11
+ return {
12
+ formId: params.formId,
13
+ limit: params.limit ?? 20,
14
+ offset: params.offset ?? 0
15
+ };
16
+ }
17
+ const FORM_QUERY_KEYS = {
18
+ /**
19
+ * Key for forms.list(params) query.
20
+ * Full key: ["forms", "list", "list", { status, limit, offset }]
21
+ */
22
+ formsList: (params) => ["forms", "list", "list", formsListDiscriminator(params)],
23
+ /**
24
+ * Key for forms.byId(id) query.
25
+ * Full key: ["forms", "byId", "byId", id]
26
+ */
27
+ formById: (id) => ["forms", "byId", "byId", id],
28
+ /**
29
+ * Key for formSubmissions.list(params) query.
30
+ * Full key: ["formSubmissions", "list", { formId, limit, offset }]
31
+ */
32
+ submissionsList: (params) => ["formSubmissions", "list", submissionsListDiscriminator(params)]
33
+ };
34
+
35
+ exports.FORM_QUERY_KEYS = FORM_QUERY_KEYS;
36
+ exports.formsListDiscriminator = formsListDiscriminator;
37
+ exports.submissionsListDiscriminator = submissionsListDiscriminator;
@@ -0,0 +1,33 @@
1
+ function formsListDiscriminator(params) {
2
+ return {
3
+ status: params?.status,
4
+ limit: params?.limit ?? 20,
5
+ offset: params?.offset ?? 0
6
+ };
7
+ }
8
+ function submissionsListDiscriminator(params) {
9
+ return {
10
+ formId: params.formId,
11
+ limit: params.limit ?? 20,
12
+ offset: params.offset ?? 0
13
+ };
14
+ }
15
+ const FORM_QUERY_KEYS = {
16
+ /**
17
+ * Key for forms.list(params) query.
18
+ * Full key: ["forms", "list", "list", { status, limit, offset }]
19
+ */
20
+ formsList: (params) => ["forms", "list", "list", formsListDiscriminator(params)],
21
+ /**
22
+ * Key for forms.byId(id) query.
23
+ * Full key: ["forms", "byId", "byId", id]
24
+ */
25
+ formById: (id) => ["forms", "byId", "byId", id],
26
+ /**
27
+ * Key for formSubmissions.list(params) query.
28
+ * Full key: ["formSubmissions", "list", { formId, limit, offset }]
29
+ */
30
+ submissionsList: (params) => ["formSubmissions", "list", submissionsListDiscriminator(params)]
31
+ };
32
+
33
+ export { FORM_QUERY_KEYS, formsListDiscriminator, submissionsListDiscriminator };
@@ -76,7 +76,7 @@ function SubmissionsPage({ formId }) {
76
76
  sub.id.slice(0, 8),
77
77
  "..."
78
78
  ] }),
79
- /* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData) }),
79
+ /* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData ?? {}) }),
80
80
  /* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "text-muted-foreground", children: new Date(sub.submittedAt).toLocaleString() }),
81
81
  /* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { className: "text-muted-foreground font-mono text-xs", children: sub.ipAddress || "-" }),
82
82
  /* @__PURE__ */ jsxRuntime.jsx(table.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-1", children: [
@@ -74,7 +74,7 @@ function SubmissionsPage({ formId }) {
74
74
  sub.id.slice(0, 8),
75
75
  "..."
76
76
  ] }),
77
- /* @__PURE__ */ jsx(TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData) }),
77
+ /* @__PURE__ */ jsx(TableCell, { className: "max-w-xs truncate text-sm text-muted-foreground", children: formatSubmissionData(sub.parsedData ?? {}) }),
78
78
  /* @__PURE__ */ jsx(TableCell, { className: "text-muted-foreground", children: new Date(sub.submittedAt).toLocaleString() }),
79
79
  /* @__PURE__ */ jsx(TableCell, { className: "text-muted-foreground font-mono text-xs", children: sub.ipAddress || "-" }),
80
80
  /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
@@ -70,6 +70,11 @@ function createFormListLoader(config) {
70
70
  await hooks.onLoadError(error, context);
71
71
  }
72
72
  } catch (error) {
73
+ if (client.isConnectionError(error)) {
74
+ console.warn(
75
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
76
+ );
77
+ }
73
78
  if (hooks?.onLoadError) {
74
79
  await hooks.onLoadError(error, context);
75
80
  }
@@ -117,6 +122,11 @@ function createFormBuilderLoader(id, config) {
117
122
  }
118
123
  }
119
124
  } catch (error) {
125
+ if (client.isConnectionError(error)) {
126
+ console.warn(
127
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
128
+ );
129
+ }
120
130
  if (hooks?.onLoadError) {
121
131
  await hooks.onLoadError(error, context);
122
132
  }
@@ -189,6 +199,11 @@ function createSubmissionsLoader(formId, config) {
189
199
  await hooks.onLoadError(error, context);
190
200
  }
191
201
  } catch (error) {
202
+ if (client.isConnectionError(error)) {
203
+ console.warn(
204
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
205
+ );
206
+ }
192
207
  if (hooks?.onLoadError) {
193
208
  await hooks.onLoadError(error, context);
194
209
  }
@@ -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 { createFormBuilderQueryKeys } from '../../../../../../plugins/form-builder/query-keys.mjs';
6
6
 
@@ -68,6 +68,11 @@ function createFormListLoader(config) {
68
68
  await hooks.onLoadError(error, context);
69
69
  }
70
70
  } catch (error) {
71
+ if (isConnectionError(error)) {
72
+ console.warn(
73
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
74
+ );
75
+ }
71
76
  if (hooks?.onLoadError) {
72
77
  await hooks.onLoadError(error, context);
73
78
  }
@@ -115,6 +120,11 @@ function createFormBuilderLoader(id, config) {
115
120
  }
116
121
  }
117
122
  } catch (error) {
123
+ if (isConnectionError(error)) {
124
+ console.warn(
125
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
126
+ );
127
+ }
118
128
  if (hooks?.onLoadError) {
119
129
  await hooks.onLoadError(error, context);
120
130
  }
@@ -187,6 +197,11 @@ function createSubmissionsLoader(formId, config) {
187
197
  await hooks.onLoadError(error, context);
188
198
  }
189
199
  } catch (error) {
200
+ if (isConnectionError(error)) {
201
+ console.warn(
202
+ "[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
203
+ );
204
+ }
190
205
  if (hooks?.onLoadError) {
191
206
  await hooks.onLoadError(error, context);
192
207
  }
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ async function hydrateColumnsWithTasks(adapter, board) {
4
+ const columnIds = (board.column || []).map((c) => c.id);
5
+ const tasksByColumn = /* @__PURE__ */ new Map();
6
+ if (columnIds.length > 0) {
7
+ const taskResults = await Promise.all(
8
+ columnIds.map(
9
+ (columnId) => adapter.findMany({
10
+ model: "kanbanTask",
11
+ where: [
12
+ { field: "columnId", value: columnId, operator: "eq" }
13
+ ],
14
+ sortBy: { field: "order", direction: "asc" }
15
+ })
16
+ )
17
+ );
18
+ for (let i = 0; i < columnIds.length; i++) {
19
+ const columnId = columnIds[i];
20
+ const tasks = taskResults[i];
21
+ if (columnId && tasks) {
22
+ tasksByColumn.set(columnId, tasks);
23
+ }
24
+ }
25
+ }
26
+ const columns = (board.column || []).sort((a, b) => a.order - b.order).map((col) => ({ ...col, tasks: tasksByColumn.get(col.id) || [] }));
27
+ const { column: _, ...boardWithoutJoin } = board;
28
+ return { ...boardWithoutJoin, columns };
29
+ }
30
+ async function getAllBoards(adapter, params) {
31
+ const query = params ?? {};
32
+ const whereConditions = [];
33
+ if (query.slug) {
34
+ whereConditions.push({
35
+ field: "slug",
36
+ value: query.slug,
37
+ operator: "eq"
38
+ });
39
+ }
40
+ if (query.ownerId) {
41
+ whereConditions.push({
42
+ field: "ownerId",
43
+ value: query.ownerId,
44
+ operator: "eq"
45
+ });
46
+ }
47
+ if (query.organizationId) {
48
+ whereConditions.push({
49
+ field: "organizationId",
50
+ value: query.organizationId,
51
+ operator: "eq"
52
+ });
53
+ }
54
+ const where = whereConditions.length > 0 ? whereConditions : void 0;
55
+ const [boards, total] = await Promise.all([
56
+ adapter.findMany({
57
+ model: "kanbanBoard",
58
+ limit: query.limit ?? 50,
59
+ offset: query.offset ?? 0,
60
+ where,
61
+ sortBy: { field: "createdAt", direction: "desc" },
62
+ join: { kanbanColumn: true }
63
+ }),
64
+ adapter.count({ model: "kanbanBoard", where })
65
+ ]);
66
+ const items = await Promise.all(
67
+ boards.map((board) => hydrateColumnsWithTasks(adapter, board))
68
+ );
69
+ return { items, total, limit: query.limit, offset: query.offset };
70
+ }
71
+ async function getBoardById(adapter, id) {
72
+ const board = await adapter.findOne({
73
+ model: "kanbanBoard",
74
+ where: [{ field: "id", value: id, operator: "eq" }],
75
+ join: { kanbanColumn: true }
76
+ });
77
+ if (!board) {
78
+ return null;
79
+ }
80
+ return hydrateColumnsWithTasks(adapter, board);
81
+ }
82
+
83
+ exports.getAllBoards = getAllBoards;
84
+ exports.getBoardById = getBoardById;
@@ -0,0 +1,81 @@
1
+ async function hydrateColumnsWithTasks(adapter, board) {
2
+ const columnIds = (board.column || []).map((c) => c.id);
3
+ const tasksByColumn = /* @__PURE__ */ new Map();
4
+ if (columnIds.length > 0) {
5
+ const taskResults = await Promise.all(
6
+ columnIds.map(
7
+ (columnId) => adapter.findMany({
8
+ model: "kanbanTask",
9
+ where: [
10
+ { field: "columnId", value: columnId, operator: "eq" }
11
+ ],
12
+ sortBy: { field: "order", direction: "asc" }
13
+ })
14
+ )
15
+ );
16
+ for (let i = 0; i < columnIds.length; i++) {
17
+ const columnId = columnIds[i];
18
+ const tasks = taskResults[i];
19
+ if (columnId && tasks) {
20
+ tasksByColumn.set(columnId, tasks);
21
+ }
22
+ }
23
+ }
24
+ const columns = (board.column || []).sort((a, b) => a.order - b.order).map((col) => ({ ...col, tasks: tasksByColumn.get(col.id) || [] }));
25
+ const { column: _, ...boardWithoutJoin } = board;
26
+ return { ...boardWithoutJoin, columns };
27
+ }
28
+ async function getAllBoards(adapter, params) {
29
+ const query = params ?? {};
30
+ const whereConditions = [];
31
+ if (query.slug) {
32
+ whereConditions.push({
33
+ field: "slug",
34
+ value: query.slug,
35
+ operator: "eq"
36
+ });
37
+ }
38
+ if (query.ownerId) {
39
+ whereConditions.push({
40
+ field: "ownerId",
41
+ value: query.ownerId,
42
+ operator: "eq"
43
+ });
44
+ }
45
+ if (query.organizationId) {
46
+ whereConditions.push({
47
+ field: "organizationId",
48
+ value: query.organizationId,
49
+ operator: "eq"
50
+ });
51
+ }
52
+ const where = whereConditions.length > 0 ? whereConditions : void 0;
53
+ const [boards, total] = await Promise.all([
54
+ adapter.findMany({
55
+ model: "kanbanBoard",
56
+ limit: query.limit ?? 50,
57
+ offset: query.offset ?? 0,
58
+ where,
59
+ sortBy: { field: "createdAt", direction: "desc" },
60
+ join: { kanbanColumn: true }
61
+ }),
62
+ adapter.count({ model: "kanbanBoard", where })
63
+ ]);
64
+ const items = await Promise.all(
65
+ boards.map((board) => hydrateColumnsWithTasks(adapter, board))
66
+ );
67
+ return { items, total, limit: query.limit, offset: query.offset };
68
+ }
69
+ async function getBoardById(adapter, id) {
70
+ const board = await adapter.findOne({
71
+ model: "kanbanBoard",
72
+ where: [{ field: "id", value: id, operator: "eq" }],
73
+ join: { kanbanColumn: true }
74
+ });
75
+ if (!board) {
76
+ return null;
77
+ }
78
+ return hydrateColumnsWithTasks(adapter, board);
79
+ }
80
+
81
+ export { getAllBoards, getBoardById };