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,91 @@
1
+ import { Field, baseFieldConfigSchema } from './field';
2
+ import { entityKind } from '../helpers';
3
+ import * as z from 'zod';
4
+ const configSchema = z.strictObject({
5
+ /**
6
+ * The default value of the field.
7
+ * If set, the field will be pre-populated with this value when the form is loaded.
8
+ * If `adminGenerated` is not true, the field will be included when submitting the form with this value.
9
+ */
10
+ defaultValue: z.string().optional().describe('The default value of the field'),
11
+ });
12
+ export class ColorField extends Field {
13
+ static [entityKind] = 'ColorField';
14
+ _defaultValue;
15
+ value;
16
+ constructor(config) {
17
+ super(config, 'color');
18
+ this.value = config.defaultValue;
19
+ this._defaultValue = config.defaultValue;
20
+ }
21
+ /**
22
+ * Get the value of the field
23
+ */
24
+ getValue() {
25
+ return this.value;
26
+ }
27
+ exportForClient() {
28
+ return {
29
+ ...super.exportForClient(),
30
+ };
31
+ }
32
+ checkRequired() {
33
+ /**
34
+ * Check if the field is required
35
+ */
36
+ if (this.required) {
37
+ if (!this.value || this.value.trim().length === 0) {
38
+ throw new Error(`Field ${this.label} is required`);
39
+ }
40
+ }
41
+ }
42
+ hasSqlNameAndValue() {
43
+ /**
44
+ * Include the field in the SQL if it is admin-generated, or not admin-generated but has a default value
45
+ */
46
+ return this.adminGenerated === true || this._defaultValue !== undefined;
47
+ }
48
+ /**
49
+ * Prepare the field for submission
50
+ */
51
+ async prepareForSubmission() {
52
+ /**
53
+ * Check if the value represents a color
54
+ */
55
+ if (this.value && !/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(this.value)) {
56
+ throw new Error('Invalid color, please provide a valid hex color');
57
+ }
58
+ }
59
+ }
60
+ const optionsSchema = z.strictObject({
61
+ ...baseFieldConfigSchema.shape,
62
+ ...configSchema.shape,
63
+ });
64
+ const colorFieldConfigSchema = z.strictObject({
65
+ ...optionsSchema.shape,
66
+ type: z.literal('color').describe('The type of the field'),
67
+ build: z.function().output(z.instanceof(ColorField)).describe('Build a ColorField instance from this config'),
68
+ });
69
+ /**
70
+ * Helper function to create a color field configuration
71
+ * Returns a config object with a build() method that can be serialized and used anywhere
72
+ * @param field
73
+ */
74
+ export function colorField(field) {
75
+ /**
76
+ * Validate the field config
77
+ */
78
+ const result = optionsSchema.safeParse(field);
79
+ if (!result.success) {
80
+ throw new Error(`[Field: ${field.name}]: ${z.prettifyError(result.error)}`);
81
+ }
82
+ const config = {
83
+ ...field,
84
+ type: 'color',
85
+ build() {
86
+ // Use the original field config directly (it doesn't have build() method)
87
+ return new ColorField(field);
88
+ },
89
+ };
90
+ return config;
91
+ }
@@ -0,0 +1,100 @@
1
+ import type { BaseFieldConfig } from './field';
2
+ import { Field } from './field';
3
+ import { entityKind } from '../helpers';
4
+ import * as z from 'zod';
5
+ declare const configSchema: z.ZodObject<{
6
+ format: z.ZodOptional<z.ZodEnum<{
7
+ date: "date";
8
+ datetime: "datetime";
9
+ timestamp: "timestamp";
10
+ }>>;
11
+ /**
12
+ * The default value of the field.
13
+ * If set, the field will be pre-populated with this value when the form is loaded.
14
+ * If `adminGenerated` is not true, the field will be included when submitting the form with this value.
15
+ */
16
+ defaultValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
17
+ }, z.core.$strict>;
18
+ type Config = z.infer<typeof configSchema>;
19
+ export declare class DateField extends Field<'date', Config> {
20
+ static readonly [entityKind]: string;
21
+ readonly format: 'date' | 'datetime' | 'timestamp';
22
+ private readonly _defaultValue;
23
+ constructor(config: BaseFieldConfig<Config>);
24
+ /**
25
+ * Get the value of the field
26
+ */
27
+ getValue(): string;
28
+ exportForClient(): {
29
+ format: "date" | "datetime" | "timestamp";
30
+ type: "date";
31
+ name: string;
32
+ label: string;
33
+ required: boolean;
34
+ conditionalFields: import("../types").ConditionalField[];
35
+ readonly: boolean;
36
+ defaultValue: any;
37
+ value: any;
38
+ };
39
+ checkRequired(): void;
40
+ hasSqlNameAndValue(): boolean;
41
+ /**
42
+ * Prepare the field for submission
43
+ */
44
+ prepareForSubmission(): Promise<void>;
45
+ }
46
+ export type DateFieldClientConfig = ReturnType<DateField['exportForClient']>;
47
+ declare const optionsSchema: z.ZodObject<{
48
+ format: z.ZodOptional<z.ZodEnum<{
49
+ date: "date";
50
+ datetime: "datetime";
51
+ timestamp: "timestamp";
52
+ }>>;
53
+ /**
54
+ * The default value of the field.
55
+ * If set, the field will be pre-populated with this value when the form is loaded.
56
+ * If `adminGenerated` is not true, the field will be included when submitting the form with this value.
57
+ */
58
+ defaultValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
59
+ name: z.ZodString;
60
+ label: z.ZodOptional<z.ZodString>;
61
+ required: z.ZodOptional<z.ZodBoolean>;
62
+ order: z.ZodOptional<z.ZodNumber>;
63
+ conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types").ConditionalRule, import("../types").ConditionalRule>>>;
64
+ adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
65
+ }, z.core.$strict>;
66
+ declare const dateFieldConfigSchema: z.ZodObject<{
67
+ type: z.ZodLiteral<"date">;
68
+ build: z.ZodFunction<z.core.$ZodFunctionArgs, z.ZodCustom<DateField, DateField>>;
69
+ format: z.ZodOptional<z.ZodEnum<{
70
+ date: "date";
71
+ datetime: "datetime";
72
+ timestamp: "timestamp";
73
+ }>>;
74
+ /**
75
+ * The default value of the field.
76
+ * If set, the field will be pre-populated with this value when the form is loaded.
77
+ * If `adminGenerated` is not true, the field will be included when submitting the form with this value.
78
+ */
79
+ defaultValue: z.ZodOptional<z.ZodCustom<Date, Date>>;
80
+ name: z.ZodString;
81
+ label: z.ZodOptional<z.ZodString>;
82
+ required: z.ZodOptional<z.ZodBoolean>;
83
+ order: z.ZodOptional<z.ZodNumber>;
84
+ conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types").ConditionalRule, import("../types").ConditionalRule>>>;
85
+ adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
86
+ }, z.core.$strict>;
87
+ /**
88
+ * Date field configuration type
89
+ * This is a plain object that can be serialized and used anywhere
90
+ * The build() method allows creating a DateField instance when needed
91
+ */
92
+ export type DateFieldConfig = z.infer<typeof dateFieldConfigSchema>;
93
+ /**
94
+ * Helper function to create a date field configuration
95
+ * Returns a config object with a build() method that can be serialized and used anywhere
96
+ * @param field
97
+ */
98
+ export declare function dateField(field: z.infer<typeof optionsSchema>): DateFieldConfig;
99
+ export {};
100
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/core/fields/date.ts"],"names":[],"m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';
2
+ import { entityKind } from '../helpers';
3
+ import * as z from 'zod';
4
+ const configSchema = z.strictObject({
5
+ format: z.enum(['date', 'datetime', 'timestamp']).optional().describe('The format of the date field'),
6
+ /**
7
+ * The default value of the field.
8
+ * If set, the field will be pre-populated with this value when the form is loaded.
9
+ * If `adminGenerated` is not true, the field will be included when submitting the form with this value.
10
+ */
11
+ defaultValue: z.custom().optional().describe('The default value of the field'),
12
+ });
13
+ export class DateField extends Field {
14
+ static [entityKind] = 'DateField';
15
+ format;
16
+ _defaultValue;
17
+ constructor(config) {
18
+ super(config, 'date');
19
+ this.format = config.format || 'date';
20
+ /**
21
+ * Set the default date if not provided
22
+ */
23
+ this.value = config.defaultValue ?? new Date(Date.now());
24
+ this._defaultValue = config.defaultValue;
25
+ }
26
+ /**
27
+ * Get the value of the field
28
+ */
29
+ getValue() {
30
+ switch (this.format) {
31
+ case 'timestamp':
32
+ return new Date(this.value).getTime().toString();
33
+ case 'datetime':
34
+ return this.value;
35
+ case 'date':
36
+ default:
37
+ return this.value.split('T')[0];
38
+ }
39
+ }
40
+ exportForClient() {
41
+ return {
42
+ ...super.exportForClient(),
43
+ format: this.format,
44
+ };
45
+ }
46
+ checkRequired() {
47
+ /**
48
+ * Check if the field is required
49
+ */
50
+ if (this.required) {
51
+ if (!this.value || this.value.trim().length === 0) {
52
+ throw new Error(`Field ${this.label} is required`);
53
+ }
54
+ }
55
+ }
56
+ hasSqlNameAndValue() {
57
+ /**
58
+ * Include the field in the SQL if it is admin-generated, or not admin-generated but has a default value
59
+ */
60
+ return this.adminGenerated === true || this._defaultValue !== undefined;
61
+ }
62
+ /**
63
+ * Prepare the field for submission
64
+ */
65
+ async prepareForSubmission() {
66
+ /**
67
+ * Check if the value represents a date
68
+ */
69
+ try {
70
+ this.value = new Date(this.value).toISOString();
71
+ }
72
+ catch (error) {
73
+ throw new Error(`Field ${this.label}: Invalid date, please provide a valid date`);
74
+ }
75
+ }
76
+ }
77
+ const optionsSchema = z.strictObject({
78
+ ...baseFieldConfigSchema.shape,
79
+ ...configSchema.shape,
80
+ });
81
+ const dateFieldConfigSchema = z.strictObject({
82
+ ...optionsSchema.shape,
83
+ type: z.literal('date').describe('The type of the field'),
84
+ build: z.function().output(z.instanceof(DateField)).describe('Build a DateField instance from this config'),
85
+ });
86
+ /**
87
+ * Helper function to create a date field configuration
88
+ * Returns a config object with a build() method that can be serialized and used anywhere
89
+ * @param field
90
+ */
91
+ export function dateField(field) {
92
+ /**
93
+ * Validate the field config
94
+ */
95
+ const result = optionsSchema.safeParse(field);
96
+ if (!result.success) {
97
+ throw new Error(`[Field: ${field.name}]: ${z.prettifyError(result.error)}`);
98
+ }
99
+ const config = {
100
+ ...field,
101
+ type: 'date',
102
+ build() {
103
+ // Use the original field config directly (it doesn't have build() method)
104
+ return new DateField(field);
105
+ },
106
+ };
107
+ return config;
108
+ }
@@ -0,0 +1,180 @@
1
+ import type { BaseFieldConfig } from './field';
2
+ import { entityKind } from '../helpers';
3
+ import * as z from 'zod';
4
+ import { FileField } from './fileField';
5
+ declare const configSchema: z.ZodObject<{
6
+ /**
7
+ * Maximum file size
8
+ * @example
9
+ * maxFileSize: {
10
+ * size: 512,
11
+ * unit: 'kb',
12
+ * }
13
+ */
14
+ maxFileSize: z.ZodOptional<z.ZodObject<{
15
+ size: z.ZodNumber;
16
+ unit: z.ZodEnum<{
17
+ kb: "kb";
18
+ mb: "mb";
19
+ }>;
20
+ }, z.core.$strict>>;
21
+ /**
22
+ * Allowed document types
23
+ * @example
24
+ * type: ['pdf', 'doc', 'docx']
25
+ * @default ['pdf']
26
+ */
27
+ type: z.ZodOptional<z.ZodArray<z.ZodEnum<{
28
+ pdf: "pdf";
29
+ doc: "doc";
30
+ docx: "docx";
31
+ xls: "xls";
32
+ xlsx: "xlsx";
33
+ ppt: "ppt";
34
+ pptx: "pptx";
35
+ txt: "txt";
36
+ csv: "csv";
37
+ }>>>;
38
+ }, z.core.$strict>;
39
+ type Config = z.infer<typeof configSchema>;
40
+ export declare class DocumentField extends FileField<'document', Config> {
41
+ static readonly [entityKind]: string;
42
+ readonly maxFileSize: {
43
+ size: number;
44
+ unit: 'kb' | 'mb';
45
+ };
46
+ readonly mimeType: string[];
47
+ readonly extensions: string[];
48
+ readonly possibleExtensions: string[];
49
+ /**
50
+ * _file is the file object if it's present
51
+ * Whereas the value is the path to the file
52
+ */
53
+ private _file;
54
+ private _buffer;
55
+ private _folder;
56
+ private _allowedExtensions;
57
+ readonly uploadsFolder: string;
58
+ constructor(config: BaseFieldConfig<Config>, file?: File);
59
+ exportForClient(): {
60
+ maxFileSize: {
61
+ size: number;
62
+ unit: "kb" | "mb";
63
+ };
64
+ extensions: string[];
65
+ mimeType: string[];
66
+ type: "document";
67
+ name: string;
68
+ label: string;
69
+ required: boolean;
70
+ conditionalFields: import("../types").ConditionalField[];
71
+ readonly: boolean;
72
+ defaultValue: any;
73
+ value: any;
74
+ };
75
+ readChunkFromFile({ arrayBuffer, length, startPosition, }: {
76
+ readonly arrayBuffer: ArrayBuffer;
77
+ readonly length: number;
78
+ readonly startPosition?: number;
79
+ }): Promise<Uint8Array>;
80
+ /**
81
+ * Write the file to the disk
82
+ */
83
+ writeToFile(): Promise<void>;
84
+ postSubmit(folder: string): Promise<void>;
85
+ postSubmitRollback(): Promise<void>;
86
+ /**
87
+ * Get the value of the field
88
+ */
89
+ getValue(): string;
90
+ setFileName(value: string): void;
91
+ setValue(value: any): void;
92
+ setFile(file: File): void;
93
+ checkRequired(): void;
94
+ /**
95
+ * Prepare the field for submission
96
+ */
97
+ prepareForSubmission(): Promise<void>;
98
+ }
99
+ export type DocumentFieldClientConfig = ReturnType<DocumentField['exportForClient']>;
100
+ declare const optionsSchema: z.ZodObject<{
101
+ /**
102
+ * Maximum file size
103
+ * @example
104
+ * maxFileSize: {
105
+ * size: 512,
106
+ * unit: 'kb',
107
+ * }
108
+ */
109
+ maxFileSize: z.ZodOptional<z.ZodObject<{
110
+ size: z.ZodNumber;
111
+ unit: z.ZodEnum<{
112
+ kb: "kb";
113
+ mb: "mb";
114
+ }>;
115
+ }, z.core.$strict>>;
116
+ /**
117
+ * Allowed document types
118
+ * @example
119
+ * type: ['pdf', 'doc', 'docx']
120
+ * @default ['pdf']
121
+ */
122
+ type: z.ZodOptional<z.ZodArray<z.ZodEnum<{
123
+ pdf: "pdf";
124
+ doc: "doc";
125
+ docx: "docx";
126
+ xls: "xls";
127
+ xlsx: "xlsx";
128
+ ppt: "ppt";
129
+ pptx: "pptx";
130
+ txt: "txt";
131
+ csv: "csv";
132
+ }>>>;
133
+ name: z.ZodString;
134
+ label: z.ZodOptional<z.ZodString>;
135
+ required: z.ZodOptional<z.ZodBoolean>;
136
+ defaultValue: z.ZodOptional<z.ZodAny>;
137
+ order: z.ZodOptional<z.ZodNumber>;
138
+ conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types").ConditionalRule, import("../types").ConditionalRule>>>;
139
+ adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
140
+ }, z.core.$strict>;
141
+ declare const documentFieldConfigSchema: z.ZodObject<{
142
+ type: z.ZodLiteral<"document">;
143
+ build: z.ZodFunction<z.core.$ZodFunctionArgs, z.ZodCustom<DocumentField, DocumentField>>;
144
+ /**
145
+ * Maximum file size
146
+ * @example
147
+ * maxFileSize: {
148
+ * size: 512,
149
+ * unit: 'kb',
150
+ * }
151
+ */
152
+ maxFileSize: z.ZodOptional<z.ZodObject<{
153
+ size: z.ZodNumber;
154
+ unit: z.ZodEnum<{
155
+ kb: "kb";
156
+ mb: "mb";
157
+ }>;
158
+ }, z.core.$strict>>;
159
+ name: z.ZodString;
160
+ label: z.ZodOptional<z.ZodString>;
161
+ required: z.ZodOptional<z.ZodBoolean>;
162
+ defaultValue: z.ZodOptional<z.ZodAny>;
163
+ order: z.ZodOptional<z.ZodNumber>;
164
+ conditionalRules: z.ZodOptional<z.ZodArray<z.ZodCustom<import("../types").ConditionalRule, import("../types").ConditionalRule>>>;
165
+ adminGenerated: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodLiteral<false>, z.ZodLiteral<"readonly">]>>;
166
+ }, z.core.$strict>;
167
+ /**
168
+ * Document field configuration type
169
+ * This is a plain object that can be serialized and used anywhere
170
+ * The build() method allows creating a DocumentField instance when needed
171
+ */
172
+ export type DocumentFieldConfig = z.infer<typeof documentFieldConfigSchema>;
173
+ /**
174
+ * Helper function to create a document field configuration
175
+ * Returns a config object with a build() method that can be serialized and used anywhere
176
+ * @param field
177
+ */
178
+ export declare function documentField(field: z.infer<typeof optionsSchema>): DocumentFieldConfig;
179
+ export {};
180
+ //# sourceMappingURL=document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/core/fields/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAQvC,QAAA,MAAM,YAAY;IACd;;;;;;;OAOG;;;;;;;;IAEH;;;;;OAKG;;;;;;;;;;;;kBAEL,CAAA;AAEF,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAE1C,qBAAa,aAAc,SAAQ,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5D,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAkB;IAC/D,QAAQ,CAAC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,CAAA;IACzD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,EAA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