nextjs-cms 0.0.1 → 0.5.1

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 (302) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +289 -0
  3. package/dist/api/axios/axiosInstance.d.ts +2 -0
  4. package/dist/api/axios/axiosInstance.d.ts.map +1 -0
  5. package/dist/api/axios/axiosInstance.js +8 -0
  6. package/dist/api/index.d.ts +856 -0
  7. package/dist/api/index.d.ts.map +1 -0
  8. package/dist/api/index.js +12 -0
  9. package/dist/api/lib/serverActions.d.ts +240 -0
  10. package/dist/api/lib/serverActions.d.ts.map +1 -0
  11. package/dist/api/lib/serverActions.js +834 -0
  12. package/dist/api/root.d.ts +829 -0
  13. package/dist/api/root.d.ts.map +1 -0
  14. package/dist/api/root.js +30 -0
  15. package/dist/api/routers/accountSettings.d.ts +61 -0
  16. package/dist/api/routers/accountSettings.d.ts.map +1 -0
  17. package/dist/api/routers/accountSettings.js +108 -0
  18. package/dist/api/routers/admins.d.ts +106 -0
  19. package/dist/api/routers/admins.d.ts.map +1 -0
  20. package/dist/api/routers/admins.js +219 -0
  21. package/dist/api/routers/auth.d.ts +48 -0
  22. package/dist/api/routers/auth.d.ts.map +1 -0
  23. package/dist/api/routers/auth.js +25 -0
  24. package/dist/api/routers/categorySection.d.ts +104 -0
  25. package/dist/api/routers/categorySection.d.ts.map +1 -0
  26. package/dist/api/routers/categorySection.js +38 -0
  27. package/dist/api/routers/cmsSettings.d.ts +49 -0
  28. package/dist/api/routers/cmsSettings.d.ts.map +1 -0
  29. package/dist/api/routers/cmsSettings.js +51 -0
  30. package/dist/api/routers/cpanel.d.ts +84 -0
  31. package/dist/api/routers/cpanel.d.ts.map +1 -0
  32. package/dist/api/routers/cpanel.js +216 -0
  33. package/dist/api/routers/files.d.ts +48 -0
  34. package/dist/api/routers/files.d.ts.map +1 -0
  35. package/dist/api/routers/files.js +23 -0
  36. package/dist/api/routers/gallery.d.ts +36 -0
  37. package/dist/api/routers/gallery.d.ts.map +1 -0
  38. package/dist/api/routers/gallery.js +62 -0
  39. package/dist/api/routers/googleAnalytics.d.ts +31 -0
  40. package/dist/api/routers/googleAnalytics.d.ts.map +1 -0
  41. package/dist/api/routers/googleAnalytics.js +7 -0
  42. package/dist/api/routers/hasItemsSection.d.ts +140 -0
  43. package/dist/api/routers/hasItemsSection.d.ts.map +1 -0
  44. package/dist/api/routers/hasItemsSection.js +34 -0
  45. package/dist/api/routers/navigation.d.ts +52 -0
  46. package/dist/api/routers/navigation.d.ts.map +1 -0
  47. package/dist/api/routers/navigation.js +11 -0
  48. package/dist/api/routers/simpleSection.d.ts +58 -0
  49. package/dist/api/routers/simpleSection.d.ts.map +1 -0
  50. package/dist/api/routers/simpleSection.js +12 -0
  51. package/dist/api/trpc.d.ts +107 -0
  52. package/dist/api/trpc.d.ts.map +1 -0
  53. package/dist/api/trpc.js +72 -0
  54. package/dist/auth/axios/axiosInstance.d.ts +2 -0
  55. package/dist/auth/axios/axiosInstance.d.ts.map +1 -0
  56. package/dist/auth/axios/axiosInstance.js +8 -0
  57. package/dist/auth/csrf.d.ts +30 -0
  58. package/dist/auth/csrf.d.ts.map +1 -0
  59. package/dist/auth/csrf.js +76 -0
  60. package/dist/auth/hooks/index.d.ts +4 -0
  61. package/dist/auth/hooks/index.d.ts.map +1 -0
  62. package/dist/auth/hooks/index.js +3 -0
  63. package/dist/auth/hooks/useAxiosPrivate.d.ts +5 -0
  64. package/dist/auth/hooks/useAxiosPrivate.d.ts.map +1 -0
  65. package/dist/auth/hooks/useAxiosPrivate.js +74 -0
  66. package/dist/auth/hooks/useRefreshToken.d.ts +7 -0
  67. package/dist/auth/hooks/useRefreshToken.d.ts.map +1 -0
  68. package/dist/auth/hooks/useRefreshToken.js +79 -0
  69. package/dist/auth/index.d.ts +23 -0
  70. package/dist/auth/index.d.ts.map +1 -0
  71. package/dist/auth/index.js +44 -0
  72. package/dist/auth/jwt.d.ts +6 -0
  73. package/dist/auth/jwt.d.ts.map +1 -0
  74. package/dist/auth/jwt.js +25 -0
  75. package/dist/auth/lib/actions.d.ts +33 -0
  76. package/dist/auth/lib/actions.d.ts.map +1 -0
  77. package/dist/auth/lib/actions.js +209 -0
  78. package/dist/auth/lib/client.d.ts +4 -0
  79. package/dist/auth/lib/client.d.ts.map +1 -0
  80. package/dist/auth/lib/client.js +46 -0
  81. package/dist/auth/lib/index.d.ts +3 -0
  82. package/dist/auth/lib/index.d.ts.map +1 -0
  83. package/dist/auth/lib/index.js +2 -0
  84. package/dist/auth/react.d.ts +106 -0
  85. package/dist/auth/react.d.ts.map +1 -0
  86. package/dist/auth/react.js +347 -0
  87. package/dist/auth/trpc.d.ts +6 -0
  88. package/dist/auth/trpc.d.ts.map +1 -0
  89. package/dist/auth/trpc.js +81 -0
  90. package/dist/core/config/config-loader.d.ts +92 -0
  91. package/dist/core/config/config-loader.d.ts.map +1 -0
  92. package/dist/core/config/config-loader.js +230 -0
  93. package/dist/core/config/index.d.ts +3 -0
  94. package/dist/core/config/index.d.ts.map +1 -0
  95. package/dist/core/config/index.js +1 -0
  96. package/dist/core/config/loader.d.ts +2 -0
  97. package/dist/core/config/loader.d.ts.map +1 -0
  98. package/dist/core/config/loader.js +42 -0
  99. package/dist/core/db/index.d.ts +2 -0
  100. package/dist/core/db/index.d.ts.map +1 -0
  101. package/dist/core/db/index.js +1 -0
  102. package/dist/core/db/table-checker/DbTable.d.ts +6 -0
  103. package/dist/core/db/table-checker/DbTable.d.ts.map +1 -0
  104. package/dist/core/db/table-checker/DbTable.js +5 -0
  105. package/dist/core/db/table-checker/MysqlTable.d.ts +34 -0
  106. package/dist/core/db/table-checker/MysqlTable.d.ts.map +1 -0
  107. package/dist/core/db/table-checker/MysqlTable.js +102 -0
  108. package/dist/core/db/table-checker/index.d.ts +2 -0
  109. package/dist/core/db/table-checker/index.d.ts.map +1 -0
  110. package/dist/core/db/table-checker/index.js +1 -0
  111. package/dist/core/factories/FieldFactory.d.ts +124 -0
  112. package/dist/core/factories/FieldFactory.d.ts.map +1 -0
  113. package/dist/core/factories/FieldFactory.js +411 -0
  114. package/dist/core/factories/SectionFactory.d.ts +110 -0
  115. package/dist/core/factories/SectionFactory.d.ts.map +1 -0
  116. package/dist/core/factories/SectionFactory.js +415 -0
  117. package/dist/core/factories/index.d.ts +3 -0
  118. package/dist/core/factories/index.d.ts.map +1 -0
  119. package/dist/core/factories/index.js +2 -0
  120. package/dist/core/fields/checkbox.d.ts +63 -0
  121. package/dist/core/fields/checkbox.d.ts.map +1 -0
  122. package/dist/core/fields/checkbox.js +62 -0
  123. package/dist/core/fields/color.d.ts +84 -0
  124. package/dist/core/fields/color.d.ts.map +1 -0
  125. package/dist/core/fields/color.js +91 -0
  126. package/dist/core/fields/date.d.ts +100 -0
  127. package/dist/core/fields/date.d.ts.map +1 -0
  128. package/dist/core/fields/date.js +108 -0
  129. package/dist/core/fields/document.d.ts +180 -0
  130. package/dist/core/fields/document.d.ts.map +1 -0
  131. package/dist/core/fields/document.js +277 -0
  132. package/dist/core/fields/field-group.d.ts +18 -0
  133. package/dist/core/fields/field-group.d.ts.map +1 -0
  134. package/dist/core/fields/field-group.js +6 -0
  135. package/dist/core/fields/field.d.ts +126 -0
  136. package/dist/core/fields/field.d.ts.map +1 -0
  137. package/dist/core/fields/field.js +148 -0
  138. package/dist/core/fields/fileField.d.ts +15 -0
  139. package/dist/core/fields/fileField.d.ts.map +1 -0
  140. package/dist/core/fields/fileField.js +5 -0
  141. package/dist/core/fields/index.d.ts +65 -0
  142. package/dist/core/fields/index.d.ts.map +1 -0
  143. package/dist/core/fields/index.js +18 -0
  144. package/dist/core/fields/map.d.ts +167 -0
  145. package/dist/core/fields/map.d.ts.map +1 -0
  146. package/dist/core/fields/map.js +152 -0
  147. package/dist/core/fields/number.d.ts +186 -0
  148. package/dist/core/fields/number.d.ts.map +1 -0
  149. package/dist/core/fields/number.js +241 -0
  150. package/dist/core/fields/password.d.ts +109 -0
  151. package/dist/core/fields/password.d.ts.map +1 -0
  152. package/dist/core/fields/password.js +133 -0
  153. package/dist/core/fields/photo.d.ts +289 -0
  154. package/dist/core/fields/photo.d.ts.map +1 -0
  155. package/dist/core/fields/photo.js +410 -0
  156. package/dist/core/fields/richText.d.ts +295 -0
  157. package/dist/core/fields/richText.d.ts.map +1 -0
  158. package/dist/core/fields/richText.js +338 -0
  159. package/dist/core/fields/select.d.ts +366 -0
  160. package/dist/core/fields/select.d.ts.map +1 -0
  161. package/dist/core/fields/select.js +499 -0
  162. package/dist/core/fields/selectMultiple.d.ts +236 -0
  163. package/dist/core/fields/selectMultiple.d.ts.map +1 -0
  164. package/dist/core/fields/selectMultiple.js +417 -0
  165. package/dist/core/fields/tags.d.ts +131 -0
  166. package/dist/core/fields/tags.d.ts.map +1 -0
  167. package/dist/core/fields/tags.js +105 -0
  168. package/dist/core/fields/text.d.ts +136 -0
  169. package/dist/core/fields/text.d.ts.map +1 -0
  170. package/dist/core/fields/text.js +157 -0
  171. package/dist/core/fields/textArea.d.ts +107 -0
  172. package/dist/core/fields/textArea.d.ts.map +1 -0
  173. package/dist/core/fields/textArea.js +126 -0
  174. package/dist/core/fields/video.d.ts +148 -0
  175. package/dist/core/fields/video.d.ts.map +1 -0
  176. package/dist/core/fields/video.js +248 -0
  177. package/dist/core/helpers/entity.d.ts +8 -0
  178. package/dist/core/helpers/entity.d.ts.map +1 -0
  179. package/dist/core/helpers/entity.js +27 -0
  180. package/dist/core/helpers/index.d.ts +5 -0
  181. package/dist/core/helpers/index.d.ts.map +1 -0
  182. package/dist/core/helpers/index.js +3 -0
  183. package/dist/core/index.d.ts +8 -0
  184. package/dist/core/index.d.ts.map +1 -0
  185. package/dist/core/index.js +7 -0
  186. package/dist/core/sections/category.d.ts +283 -0
  187. package/dist/core/sections/category.d.ts.map +1 -0
  188. package/dist/core/sections/category.js +147 -0
  189. package/dist/core/sections/hasItems.d.ts +632 -0
  190. package/dist/core/sections/hasItems.d.ts.map +1 -0
  191. package/dist/core/sections/hasItems.js +144 -0
  192. package/dist/core/sections/index.d.ts +5 -0
  193. package/dist/core/sections/index.d.ts.map +1 -0
  194. package/dist/core/sections/index.js +4 -0
  195. package/dist/core/sections/section.d.ts +226 -0
  196. package/dist/core/sections/section.d.ts.map +1 -0
  197. package/dist/core/sections/section.js +341 -0
  198. package/dist/core/sections/simple.d.ts +99 -0
  199. package/dist/core/sections/simple.d.ts.map +1 -0
  200. package/dist/core/sections/simple.js +95 -0
  201. package/dist/core/security/dom.d.ts +11 -0
  202. package/dist/core/security/dom.d.ts.map +1 -0
  203. package/dist/core/security/dom.js +92 -0
  204. package/dist/core/submit/ItemEditSubmit.d.ts +76 -0
  205. package/dist/core/submit/ItemEditSubmit.d.ts.map +1 -0
  206. package/dist/core/submit/ItemEditSubmit.js +186 -0
  207. package/dist/core/submit/NewItemSubmit.d.ts +14 -0
  208. package/dist/core/submit/NewItemSubmit.d.ts.map +1 -0
  209. package/dist/core/submit/NewItemSubmit.js +93 -0
  210. package/dist/core/submit/SimpleSectionSubmit.d.ts +13 -0
  211. package/dist/core/submit/SimpleSectionSubmit.d.ts.map +1 -0
  212. package/dist/core/submit/SimpleSectionSubmit.js +93 -0
  213. package/dist/core/submit/index.d.ts +5 -0
  214. package/dist/core/submit/index.d.ts.map +1 -0
  215. package/dist/core/submit/index.js +4 -0
  216. package/dist/core/submit/submit.d.ts +116 -0
  217. package/dist/core/submit/submit.d.ts.map +1 -0
  218. package/dist/core/submit/submit.js +479 -0
  219. package/dist/core/types/index.d.ts +280 -0
  220. package/dist/core/types/index.d.ts.map +1 -0
  221. package/dist/core/types/index.js +1 -0
  222. package/dist/db/client.d.ts +9 -0
  223. package/dist/db/client.d.ts.map +1 -0
  224. package/dist/db/client.js +19 -0
  225. package/dist/db/config.d.ts +6 -0
  226. package/dist/db/config.d.ts.map +1 -0
  227. package/dist/db/config.js +22 -0
  228. package/dist/db/drizzle.config.d.ts +6 -0
  229. package/dist/db/drizzle.config.d.ts.map +1 -0
  230. package/dist/db/drizzle.config.js +18 -0
  231. package/dist/db/index.d.ts +3 -0
  232. package/dist/db/index.d.ts.map +1 -0
  233. package/dist/db/index.js +3 -0
  234. package/dist/db/schema.d.ts +639 -0
  235. package/dist/db/schema.d.ts.map +1 -0
  236. package/dist/db/schema.js +73 -0
  237. package/dist/index.d.ts +7 -1
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +7 -1
  240. package/dist/translations/dictionaries/ar.json +279 -0
  241. package/dist/translations/dictionaries/en.json +279 -0
  242. package/dist/translations/index.d.ts +3 -0
  243. package/dist/translations/index.d.ts.map +1 -0
  244. package/dist/translations/index.js +15 -0
  245. package/dist/utils/CpanelApi.d.ts +25 -0
  246. package/dist/utils/CpanelApi.d.ts.map +1 -0
  247. package/dist/utils/CpanelApi.js +64 -0
  248. package/dist/utils/constants.d.ts +14 -0
  249. package/dist/utils/constants.d.ts.map +1 -0
  250. package/dist/utils/constants.js +61 -0
  251. package/dist/utils/index.d.ts +5 -0
  252. package/dist/utils/index.d.ts.map +1 -0
  253. package/dist/utils/index.js +4 -0
  254. package/dist/utils/utils.d.ts +60 -0
  255. package/dist/utils/utils.d.ts.map +1 -0
  256. package/dist/utils/utils.js +132 -0
  257. package/dist/validators/checkbox.d.ts +4 -0
  258. package/dist/validators/checkbox.d.ts.map +1 -0
  259. package/dist/validators/checkbox.js +12 -0
  260. package/dist/validators/color.d.ts +4 -0
  261. package/dist/validators/color.d.ts.map +1 -0
  262. package/dist/validators/color.js +7 -0
  263. package/dist/validators/date.d.ts +4 -0
  264. package/dist/validators/date.d.ts.map +1 -0
  265. package/dist/validators/date.js +5 -0
  266. package/dist/validators/document.d.ts +4 -0
  267. package/dist/validators/document.d.ts.map +1 -0
  268. package/dist/validators/document.js +57 -0
  269. package/dist/validators/index.d.ts +15 -0
  270. package/dist/validators/index.d.ts.map +1 -0
  271. package/dist/validators/index.js +14 -0
  272. package/dist/validators/map.d.ts +4 -0
  273. package/dist/validators/map.d.ts.map +1 -0
  274. package/dist/validators/map.js +5 -0
  275. package/dist/validators/number.d.ts +4 -0
  276. package/dist/validators/number.d.ts.map +1 -0
  277. package/dist/validators/number.js +20 -0
  278. package/dist/validators/password.d.ts +4 -0
  279. package/dist/validators/password.d.ts.map +1 -0
  280. package/dist/validators/password.js +11 -0
  281. package/dist/validators/photo.d.ts +4 -0
  282. package/dist/validators/photo.d.ts.map +1 -0
  283. package/dist/validators/photo.js +100 -0
  284. package/dist/validators/richText.d.ts +4 -0
  285. package/dist/validators/richText.d.ts.map +1 -0
  286. package/dist/validators/richText.js +8 -0
  287. package/dist/validators/select-multiple.d.ts +10 -0
  288. package/dist/validators/select-multiple.d.ts.map +1 -0
  289. package/dist/validators/select-multiple.js +20 -0
  290. package/dist/validators/select.d.ts +4 -0
  291. package/dist/validators/select.d.ts.map +1 -0
  292. package/dist/validators/select.js +5 -0
  293. package/dist/validators/text.d.ts +4 -0
  294. package/dist/validators/text.d.ts.map +1 -0
  295. package/dist/validators/text.js +7 -0
  296. package/dist/validators/textarea.d.ts +4 -0
  297. package/dist/validators/textarea.d.ts.map +1 -0
  298. package/dist/validators/textarea.js +7 -0
  299. package/dist/validators/video.d.ts +4 -0
  300. package/dist/validators/video.d.ts.map +1 -0
  301. package/dist/validators/video.js +57 -0
  302. package/package.json +150 -6
@@ -0,0 +1,76 @@
1
+ import type { SQL } from 'drizzle-orm';
2
+ import type { Field } from '../fields';
3
+ import { Submit } from './submit';
4
+ import { entityKind } from '../helpers';
5
+ import type { User } from '../../auth';
6
+ type ConstructorType = {
7
+ itemId: string;
8
+ sectionName: string;
9
+ user: User;
10
+ postData: FormData;
11
+ preSubmit?: boolean;
12
+ };
13
+ export declare class EditSubmit extends Submit {
14
+ static readonly [entityKind]: string;
15
+ protected readonly _itemId: string;
16
+ protected _values: Record<string, any>;
17
+ /**
18
+ * Constructor
19
+ */
20
+ constructor(config: ConstructorType);
21
+ /**
22
+ * Must be called after the constructor
23
+ * @override
24
+ */
25
+ initialize(): Promise<void>;
26
+ private initializeFieldValues;
27
+ /**
28
+ * Gets the field values from the associated table declared in the section info
29
+ * @private
30
+ */
31
+ private getFieldValue;
32
+ private getSelectMultipleValue;
33
+ /**
34
+ * Rollback post submit operations
35
+ * This will rollback the post submit operations for each field (if any)
36
+ * @private
37
+ * @override
38
+ */
39
+ protected postSubmitRollback(): Promise<void>;
40
+ /**
41
+ * Rollback submit
42
+ * This will rollback the submit for this item
43
+ * @returns
44
+ * @override
45
+ */
46
+ protected submitRollback(): Promise<void>;
47
+ /**
48
+ * Build the sql query
49
+ * @override
50
+ */
51
+ protected buildSqlQuery(): SQL | undefined;
52
+ /**
53
+ * Check required fields
54
+ * @param field
55
+ * @override
56
+ */
57
+ checkRequired(field: Field): void;
58
+ /**
59
+ * Handle field override, don't handle readonly or identifier fields
60
+ * @param field
61
+ * @override
62
+ */
63
+ handleField(field: Field): Promise<void>;
64
+ /**
65
+ * Item id value is already assigned in the constructor
66
+ */
67
+ assignItemIdValue(): void;
68
+ /**
69
+ * Set field value override
70
+ * @param field
71
+ * @override
72
+ */
73
+ setFieldValue(field: Field): void;
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=ItemEditSubmit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ItemEditSubmit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/ItemEditSubmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAC,MAAM,aAAa,CAAC;AAItC,OAAO,KAAK,EAAuB,KAAK,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,UAAU,EAAM,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAOtC,KAAK,eAAe,GAAG;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,qBAAa,UAAW,SAAQ,MAAM;IAClC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAe;IAC5D,mBAA4B,OAAO,EAAE,MAAM,CAAA;IAC3C,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAK;IAE3C;;OAEG;gBACS,MAAM,EAAE,eAAe;IAKnC;;;OAGG;IACmB,UAAU;YASlB,qBAAqB;IAuBnC;;;OAGG;YACW,aAAa;YAQb,sBAAsB;IAoBpC;;;;;OAKG;cACsB,kBAAkB;IAI3C;;;;;OAKG;cACsB,cAAc;IAUvC;;;OAGG;cACgB,aAAa,IAAI,GAAG,GAAG,SAAS;IAmBnD;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;IAmBnC;;;;OAIG;IACY,WAAW,CAAC,KAAK,EAAE,KAAK;IAQvC;;OAEG;IACM,iBAAiB;IAI1B;;;;OAIG;IACM,aAAa,CAAC,KAAK,EAAE,KAAK;CAgBtC"}
@@ -0,0 +1,186 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { db } from '../../db/client';
3
+ import { Submit } from './submit';
4
+ import { FileField } from '../fields';
5
+ import { entityKind, is } from '../helpers';
6
+ export class EditSubmit extends Submit {
7
+ static [entityKind] = 'EditSubmit';
8
+ _itemId;
9
+ _values = {};
10
+ /**
11
+ * Constructor
12
+ */
13
+ constructor(config) {
14
+ super(config);
15
+ this._itemId = config.itemId;
16
+ }
17
+ /**
18
+ * Must be called after the constructor
19
+ * @override
20
+ */
21
+ async initialize() {
22
+ await super.initialize('U');
23
+ /**
24
+ * It's an edit operation, let's get all fields values
25
+ */
26
+ await this.initializeFieldValues();
27
+ }
28
+ async initializeFieldValues() {
29
+ if (this._error)
30
+ return;
31
+ if (!this._itemId)
32
+ return;
33
+ if (this._sectionInfo?.db.table && this._sectionInfo.db.identifier) {
34
+ /**
35
+ * Let's get the section item values from its table and assign it to the `_values` property
36
+ */
37
+ // TODO: We still need to get the values from the `destinationDbTable` if it exists on any field
38
+ // also, select_multiple fields need to be handled the same way, plus value is array of strings
39
+ const [_v, fields] = await db.execute(sql `select * from ${sql.raw(this._sectionInfo.db.table)} where ${sql.raw(this._sectionInfo.db.identifier.name)} = ${this._itemId} limit 1`);
40
+ // @ts-ignore
41
+ // Bug: this is a bug in drizzle-orm/mysql2
42
+ this._values = _v[0];
43
+ }
44
+ else {
45
+ this._error = true;
46
+ this._errorMessage = 'Section table or section table identifier is missing';
47
+ return;
48
+ }
49
+ }
50
+ /**
51
+ * Gets the field values from the associated table declared in the section info
52
+ * @private
53
+ */
54
+ async getFieldValue(field) {
55
+ if (field.type === 'select_multiple') {
56
+ return await this.getSelectMultipleValue(field);
57
+ }
58
+ return this._values[field.name] ?? undefined;
59
+ }
60
+ async getSelectMultipleValue(field) {
61
+ if (!field.destinationDb)
62
+ return this._values[field.name] ?? undefined;
63
+ const [_rows, _fields] = await db.execute(sql `select * from ${sql.raw(field.destinationDb.table)} a JOIN ${sql.raw(field.db.table)} b ON a.${sql.raw(field.destinationDb.selectIdentifier)} = b.${sql.raw(field.db.identifier)} where ${sql.raw(field.destinationDb.itemIdentifier)} = ${this._itemId}`);
64
+ const values = [];
65
+ for (const row of _rows) {
66
+ values.push({
67
+ value: row[field.destinationDb.selectIdentifier],
68
+ label: row[field.db.label],
69
+ });
70
+ }
71
+ return values;
72
+ }
73
+ /**
74
+ * Rollback post submit operations
75
+ * This will rollback the post submit operations for each field (if any)
76
+ * @private
77
+ * @override
78
+ */
79
+ async postSubmitRollback() {
80
+ await super.postSubmitRollback();
81
+ }
82
+ /**
83
+ * Rollback submit
84
+ * This will rollback the submit for this item
85
+ * @returns
86
+ * @override
87
+ */
88
+ async submitRollback() {
89
+ if (!this._sectionInfo)
90
+ return;
91
+ /**
92
+ * TODO: Implement the rollback operation for the edit operation
93
+ * This will involve getting the original values of the fields,
94
+ * and updating the table with the original values
95
+ */
96
+ }
97
+ /**
98
+ * Build the sql query
99
+ * @override
100
+ */
101
+ buildSqlQuery() {
102
+ if (!this._sectionInfo)
103
+ return;
104
+ /**
105
+ * Add the updated_by field to the sqlNamesAndValues object
106
+ */
107
+ this.sqlNamesAndValues['updated_by'] = this.user.name;
108
+ const sqlChunks = [];
109
+ sqlChunks.push(sql `update ${sql.raw(this._sectionInfo.db.table)} set `);
110
+ Object.keys(this.sqlNamesAndValues).map((value, index) => {
111
+ sqlChunks.push(sql.raw(`\`${value}\``));
112
+ sqlChunks.push(sql ` = ${this.sqlNamesAndValues[value] ? this.sqlNamesAndValues[value] : sql `NULL`}`);
113
+ if (index < Object.values(this.sqlNamesAndValues).length - 1) {
114
+ sqlChunks.push(sql `, `);
115
+ }
116
+ });
117
+ sqlChunks.push(sql ` where ${sql.raw(this._sectionInfo.db.identifier.name)} = ${this._itemId}`);
118
+ return sql.join(sqlChunks);
119
+ }
120
+ /**
121
+ * Check required fields
122
+ * @param field
123
+ * @override
124
+ */
125
+ checkRequired(field) {
126
+ /**
127
+ * Don't check for required fields for photo, video, and document fields if they have values in the database
128
+ */
129
+ if (is(field, FileField)) {
130
+ /**
131
+ * Check if a field value is present in the database
132
+ */
133
+ if (!this._values[field.name]) {
134
+ /**
135
+ * If no value is present, check if the field is required
136
+ */
137
+ field.checkRequired();
138
+ }
139
+ }
140
+ else {
141
+ field.checkRequired();
142
+ }
143
+ }
144
+ /**
145
+ * Handle field override, don't handle readonly or identifier fields
146
+ * @param field
147
+ * @override
148
+ */
149
+ async handleField(field) {
150
+ /**
151
+ * Don't handle readonly fields
152
+ */
153
+ if (field.adminGenerated !== true || field.name === this._sectionInfo.db.identifier.name)
154
+ return;
155
+ await super.handleField(field);
156
+ }
157
+ /**
158
+ * Item id value is already assigned in the constructor
159
+ */
160
+ assignItemIdValue() {
161
+ return;
162
+ }
163
+ /**
164
+ * Set field value override
165
+ * @param field
166
+ * @override
167
+ */
168
+ setFieldValue(field) {
169
+ /**
170
+ * Don't set values for file fields
171
+ */
172
+ if (is(field, FileField)) {
173
+ const value = this._postData.get(field.name);
174
+ let file = value;
175
+ if (file.size !== 0 && file.name && file.name?.trim() !== '') {
176
+ field.setValue(value);
177
+ }
178
+ else {
179
+ field.setFileName(this._values[field.name]);
180
+ }
181
+ }
182
+ else {
183
+ super.setFieldValue(field);
184
+ }
185
+ }
186
+ }
@@ -0,0 +1,14 @@
1
+ import type { SQL } from 'drizzle-orm';
2
+ import { Submit } from './submit';
3
+ import { entityKind } from '../helpers';
4
+ export declare class NewSubmit extends Submit {
5
+ static readonly [entityKind]: string;
6
+ /**
7
+ * Rollback submit
8
+ * This will rollback the submit for this item
9
+ * @returns
10
+ */
11
+ protected submitRollback(): Promise<void>;
12
+ protected buildSqlQuery(): SQL | undefined;
13
+ }
14
+ //# sourceMappingURL=NewItemSubmit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NewItemSubmit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/NewItemSubmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAC,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,qBAAa,SAAU,SAAQ,MAAM;IACjC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAc;IAC3D;;;;OAIG;cACa,cAAc;IAY9B,SAAS,CAAC,aAAa,IAAI,GAAG,GAAG,SAAS;CAsE7C"}
@@ -0,0 +1,93 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { db } from '../../db/client';
3
+ import { Submit } from './submit';
4
+ import { entityKind } from '../helpers';
5
+ export class NewSubmit extends Submit {
6
+ static [entityKind] = 'NewSubmit';
7
+ /**
8
+ * Rollback submit
9
+ * This will rollback the submit for this item
10
+ * @returns
11
+ */
12
+ async submitRollback() {
13
+ if (!this._sectionInfo)
14
+ return;
15
+ const sqlQuery = sql `delete from ${sql.raw(this._sectionInfo?.db.table)} where ${sql.raw(this._sectionInfo?.db.identifier?.name)} = ${this._itemId}`;
16
+ try {
17
+ await db.execute(sqlQuery);
18
+ }
19
+ catch (e) {
20
+ this._error = true;
21
+ this._errorMessage = e.message;
22
+ return;
23
+ }
24
+ }
25
+ buildSqlQuery() {
26
+ if (this._error)
27
+ return;
28
+ if (!this._sectionInfo)
29
+ return;
30
+ /**
31
+ * Add the created_by field to the sqlNamesAndValues object
32
+ */
33
+ this.sqlNamesAndValues['created_by'] = this.user.name;
34
+ const sqlChunks = [];
35
+ /**
36
+ * Build the sql query to insert the new item
37
+ */
38
+ sqlChunks.push(sql `insert into ${sql.raw(this._sectionInfo.db.table)} (`);
39
+ /**
40
+ * Loop through the sqlNamesAndValues object and add the keys to the sql query
41
+ */
42
+ Object.keys(this.sqlNamesAndValues).map((value, index) => {
43
+ /**
44
+ * Add the key to the sql query
45
+ */
46
+ sqlChunks.push(sql.raw(`\`${value}\``));
47
+ if (index < Object.values(this.sqlNamesAndValues).length - 1) {
48
+ /**
49
+ * If the key is not the last key, add a comma
50
+ */
51
+ sqlChunks.push(sql `, `);
52
+ }
53
+ });
54
+ /**
55
+ * Close the sql query with a closing parenthesis and add the values to the sql query
56
+ */
57
+ sqlChunks.push(sql `) values (`);
58
+ /**
59
+ * Loop through the sqlNamesAndValues object and add the values to the sql query
60
+ */
61
+ Object.values(this.sqlNamesAndValues).map((value, index) => {
62
+ /**
63
+ * Explicitly check if the value is null or undefined
64
+ */
65
+ if (value !== null && value !== undefined) {
66
+ /**
67
+ * If the value is defined, insert the value
68
+ */
69
+ sqlChunks.push(sql `${value}`);
70
+ }
71
+ else {
72
+ /**
73
+ * If the value is null or undefined, insert NULL
74
+ */
75
+ sqlChunks.push(sql `NULL`);
76
+ }
77
+ if (index < Object.values(this.sqlNamesAndValues).length - 1) {
78
+ /**
79
+ * If the value is not the last value, add a comma
80
+ */
81
+ sqlChunks.push(sql `, `);
82
+ }
83
+ });
84
+ /**
85
+ * Close the sql query with a closing parenthesis
86
+ */
87
+ sqlChunks.push(sql `)`);
88
+ /**
89
+ * Join the sqlChunks array to create the final sql query and return it
90
+ */
91
+ return sql.join(sqlChunks);
92
+ }
93
+ }
@@ -0,0 +1,13 @@
1
+ import type { SQL } from 'drizzle-orm';
2
+ import { entityKind } from '../helpers';
3
+ import { EditSubmit } from './ItemEditSubmit';
4
+ export declare class SimpleSectionSubmit extends EditSubmit {
5
+ static readonly [entityKind]: string;
6
+ protected readonly _itemId: '1';
7
+ /**
8
+ * Build the sql query
9
+ * @override
10
+ */
11
+ protected buildSqlQuery(): SQL | undefined;
12
+ }
13
+ //# sourceMappingURL=SimpleSectionSubmit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SimpleSectionSubmit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/SimpleSectionSubmit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAC,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,qBAAa,mBAAoB,SAAQ,UAAU;IAC/C,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAwB;IACrE,mBAA4B,OAAO,EAAE,GAAG,CAAM;IAE9C;;;OAGG;cACgB,aAAa,IAAI,GAAG,GAAG,SAAS;CAmFtD"}
@@ -0,0 +1,93 @@
1
+ import { sql } from 'drizzle-orm';
2
+ import { entityKind } from '../helpers';
3
+ import { EditSubmit } from './ItemEditSubmit';
4
+ export class SimpleSectionSubmit extends EditSubmit {
5
+ static [entityKind] = 'SimpleSectionSubmit';
6
+ _itemId = '1';
7
+ /**
8
+ * Build the sql query
9
+ * @override
10
+ */
11
+ buildSqlQuery() {
12
+ if (!this._sectionInfo)
13
+ return;
14
+ /**
15
+ * Add the updated_by field to the sqlNamesAndValues object
16
+ */
17
+ this.sqlNamesAndValues['updated_by'] = this.user.name;
18
+ const sqlChunks = [];
19
+ /**
20
+ * Check if the row exists
21
+ */
22
+ if (!this._values) {
23
+ /**
24
+ * Do insert instead of update
25
+ */
26
+ sqlChunks.push(sql `insert into ${sql.raw(this._sectionInfo.db.table)} (`);
27
+ /**
28
+ * Add the fields to the query
29
+ */
30
+ Object.keys(this.sqlNamesAndValues).map((value, index) => {
31
+ sqlChunks.push(sql.raw(`\`${value}\``));
32
+ sqlChunks.push(sql `, `);
33
+ });
34
+ /**
35
+ * Add the id field
36
+ */
37
+ sqlChunks.push(sql.raw(this._sectionInfo.db.identifier.name));
38
+ /**
39
+ * Close the fields
40
+ */
41
+ sqlChunks.push(sql `) values (`);
42
+ /**
43
+ * Add the values to the query
44
+ */
45
+ Object.values(this.sqlNamesAndValues).map((value, index) => {
46
+ if (value) {
47
+ sqlChunks.push(sql `${value}`);
48
+ }
49
+ else {
50
+ sqlChunks.push(sql `NULL`);
51
+ }
52
+ sqlChunks.push(sql `, `);
53
+ });
54
+ /**
55
+ * Add the id value
56
+ */
57
+ sqlChunks.push(sql `${this._itemId}`);
58
+ /**
59
+ * Close the values
60
+ */
61
+ sqlChunks.push(sql `)`);
62
+ }
63
+ else {
64
+ /**
65
+ * Do update instead of insert
66
+ */
67
+ sqlChunks.push(sql `update ${sql.raw(this._sectionInfo.db.table)} set `);
68
+ /**
69
+ * Add the field and values to the query
70
+ */
71
+ Object.keys(this.sqlNamesAndValues).map((value, index) => {
72
+ sqlChunks.push(sql.raw(`\`${value}\``));
73
+ if (this.sqlNamesAndValues[value]) {
74
+ sqlChunks.push(sql ` = ${this.sqlNamesAndValues[value]}`);
75
+ }
76
+ else {
77
+ sqlChunks.push(sql ` = NULL`);
78
+ }
79
+ if (index < Object.values(this.sqlNamesAndValues).length - 1) {
80
+ sqlChunks.push(sql `, `);
81
+ }
82
+ });
83
+ /**
84
+ * Add the where clause
85
+ */
86
+ sqlChunks.push(sql ` where ${sql.raw(this._sectionInfo.db.identifier.name)} = ${this._itemId}`);
87
+ }
88
+ /**
89
+ * Join the sql chunks and return the query
90
+ */
91
+ return sql.join(sqlChunks);
92
+ }
93
+ }
@@ -0,0 +1,5 @@
1
+ export { NewSubmit } from './NewItemSubmit';
2
+ export { EditSubmit } from './ItemEditSubmit';
3
+ export { SimpleSectionSubmit } from './SimpleSectionSubmit';
4
+ export { Submit } from './submit';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/submit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,4 @@
1
+ export { NewSubmit } from './NewItemSubmit';
2
+ export { EditSubmit } from './ItemEditSubmit';
3
+ export { SimpleSectionSubmit } from './SimpleSectionSubmit';
4
+ export { Submit } from './submit';
@@ -0,0 +1,116 @@
1
+ import type { SQL } from 'drizzle-orm';
2
+ import type { Field } from '../fields';
3
+ import type { Section } from '../sections';
4
+ import { entityKind } from '../helpers';
5
+ import type { User } from '../../auth';
6
+ type ConstructorType = {
7
+ sectionName: string;
8
+ user: User;
9
+ postData: FormData;
10
+ preSubmit?: boolean;
11
+ };
12
+ export declare abstract class Submit {
13
+ static readonly [entityKind]: string;
14
+ protected readonly user: User;
15
+ protected _itemId: number | string | undefined;
16
+ protected _error: boolean;
17
+ protected _errorMessage: string;
18
+ private _notices;
19
+ protected sectionName: string;
20
+ readonly _postData: FormData;
21
+ protected _sectionInfo: Section;
22
+ protected preSubmit: boolean;
23
+ protected sqlNamesAndValues: Record<string, any>;
24
+ protected fields: Field[];
25
+ /**
26
+ * Constructor
27
+ */
28
+ constructor({ preSubmit, sectionName, user, postData }: ConstructorType);
29
+ /**
30
+ * Run custom hooks after the item is updated
31
+ * @protected
32
+ */
33
+ protected runPostSubmitHooks(): Promise<void>;
34
+ /**
35
+ * Log operation to the database
36
+ */
37
+ private logOperation;
38
+ /**
39
+ * Must be called after the constructor
40
+ */
41
+ initialize(requiredRole?: 'C' | 'U'): Promise<void>;
42
+ /**
43
+ * Gets the section info and assigns it to the `sectionInfo` property
44
+ * @param user
45
+ * @param requiredRole
46
+ * @private
47
+ */
48
+ private initializeSectionInfo;
49
+ /**
50
+ * Perform post submit operations
51
+ * This will initiate the post submit operations for each field (if any)
52
+ * @private
53
+ */
54
+ private postSubmit;
55
+ /**
56
+ * Rollback post submit operations.<br>
57
+ * This will rollback the post submit operations for each field (if any)
58
+ * @private
59
+ */
60
+ protected postSubmitRollback(): Promise<void>;
61
+ /**
62
+ * Rollback submit operation.<br>
63
+ * This will rollback the submit for this item
64
+ * @returns
65
+ */
66
+ protected abstract submitRollback(): Promise<void>;
67
+ /**
68
+ * Check if the conditional field conditions are met for a field.
69
+ * @param field
70
+ * @private
71
+ */
72
+ private checkConditionalField;
73
+ /**
74
+ * Build the sql query.
75
+ * @protected
76
+ */
77
+ protected abstract buildSqlQuery(): SQL | undefined;
78
+ /**
79
+ * Check if the field is required and perform the required checks.
80
+ * @param field
81
+ * @protected
82
+ */
83
+ protected checkRequired(field: Field): void;
84
+ /**
85
+ * Set the field value.
86
+ * @param field
87
+ * @protected
88
+ */
89
+ protected setFieldValue(field: Field): void;
90
+ protected updateSqlNamesAndValues(field: Field): void;
91
+ protected assignItemIdValue(field: Field): void;
92
+ /**
93
+ * Handle the field
94
+ * @param field
95
+ * @protected
96
+ */
97
+ protected handleField(field: Field): Promise<void>;
98
+ protected handleFields(): Promise<void>;
99
+ /**
100
+ * Execute the sql query.
101
+ * @param sqlQuery
102
+ * @private
103
+ */
104
+ private executeQuery;
105
+ /**
106
+ * Try to submit the form.
107
+ */
108
+ submit(): Promise<true | undefined>;
109
+ private handleGallery;
110
+ get errorMessage(): string;
111
+ get error(): boolean;
112
+ get notices(): string[] | null;
113
+ private addNotice;
114
+ }
115
+ export {};
116
+ //# sourceMappingURL=submit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../../src/core/submit/submit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAGtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,UAAU,EAAM,MAAM,YAAY,CAAA;AAG3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEtC,KAAK,eAAe,GAAG;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,8BAAsB,MAAM;IACxB,MAAM,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,CAAW;IAC/C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IAC7B,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAY;IAC1D,SAAS,CAAC,MAAM,EAAE,OAAO,CAAQ;IACjC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAK;IACpC,OAAO,CAAC,QAAQ,CAAwB;IACxC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAA;IAC5B,SAAS,CAAC,YAAY,EAAG,OAAO,CAAA;IAChC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAQ;IACpC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAK;IACrD,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,CAAK;IAE9B;;OAEG;gBACS,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,eAAe;IAOvE;;;OAGG;cACa,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAanD;;OAEG;YACW,YAAY;IAM1B;;OAEG;IACU,UAAU,CAAC,YAAY,GAAE,GAAG,GAAG,GAAS;IAIrD;;;;;OAKG;YACW,qBAAqB;IA4BnC;;;;OAIG;YACW,UAAU;IAoDxB;;;;OAIG;cACa,kBAAkB;IAMlC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAElD;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAqB7B;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,GAAG,GAAG,SAAS;IAEnD;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK;IAIpC;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK;IAqBpC,SAAS,CAAC,uBAAuB,CAAC,KAAK,EAAE,KAAK;IAM9C,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK;IAUxC;;;;OAIG;cACa,WAAW,CAAC,KAAK,EAAE,KAAK;cAoDxB,YAAY;IAU5B;;;;OAIG;YACW,YAAY;IA6B1B;;OAEG;IACU,MAAM;YAsEL,aAAa;IAiF3B,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,OAAO,IAAI,MAAM,EAAE,GAAG,IAAI,CAE7B;IAED,OAAO,CAAC,SAAS;CAMpB"}