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.
- package/LICENSE +21 -0
- package/README.md +289 -0
- package/dist/api/axios/axiosInstance.d.ts +2 -0
- package/dist/api/axios/axiosInstance.d.ts.map +1 -0
- package/dist/api/axios/axiosInstance.js +8 -0
- package/dist/api/index.d.ts +856 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +12 -0
- package/dist/api/lib/serverActions.d.ts +240 -0
- package/dist/api/lib/serverActions.d.ts.map +1 -0
- package/dist/api/lib/serverActions.js +834 -0
- package/dist/api/root.d.ts +829 -0
- package/dist/api/root.d.ts.map +1 -0
- package/dist/api/root.js +30 -0
- package/dist/api/routers/accountSettings.d.ts +61 -0
- package/dist/api/routers/accountSettings.d.ts.map +1 -0
- package/dist/api/routers/accountSettings.js +108 -0
- package/dist/api/routers/admins.d.ts +106 -0
- package/dist/api/routers/admins.d.ts.map +1 -0
- package/dist/api/routers/admins.js +219 -0
- package/dist/api/routers/auth.d.ts +48 -0
- package/dist/api/routers/auth.d.ts.map +1 -0
- package/dist/api/routers/auth.js +25 -0
- package/dist/api/routers/categorySection.d.ts +104 -0
- package/dist/api/routers/categorySection.d.ts.map +1 -0
- package/dist/api/routers/categorySection.js +38 -0
- package/dist/api/routers/cmsSettings.d.ts +49 -0
- package/dist/api/routers/cmsSettings.d.ts.map +1 -0
- package/dist/api/routers/cmsSettings.js +51 -0
- package/dist/api/routers/cpanel.d.ts +84 -0
- package/dist/api/routers/cpanel.d.ts.map +1 -0
- package/dist/api/routers/cpanel.js +216 -0
- package/dist/api/routers/files.d.ts +48 -0
- package/dist/api/routers/files.d.ts.map +1 -0
- package/dist/api/routers/files.js +23 -0
- package/dist/api/routers/gallery.d.ts +36 -0
- package/dist/api/routers/gallery.d.ts.map +1 -0
- package/dist/api/routers/gallery.js +62 -0
- package/dist/api/routers/googleAnalytics.d.ts +31 -0
- package/dist/api/routers/googleAnalytics.d.ts.map +1 -0
- package/dist/api/routers/googleAnalytics.js +7 -0
- package/dist/api/routers/hasItemsSection.d.ts +140 -0
- package/dist/api/routers/hasItemsSection.d.ts.map +1 -0
- package/dist/api/routers/hasItemsSection.js +34 -0
- package/dist/api/routers/navigation.d.ts +52 -0
- package/dist/api/routers/navigation.d.ts.map +1 -0
- package/dist/api/routers/navigation.js +11 -0
- package/dist/api/routers/simpleSection.d.ts +58 -0
- package/dist/api/routers/simpleSection.d.ts.map +1 -0
- package/dist/api/routers/simpleSection.js +12 -0
- package/dist/api/trpc.d.ts +107 -0
- package/dist/api/trpc.d.ts.map +1 -0
- package/dist/api/trpc.js +72 -0
- package/dist/auth/axios/axiosInstance.d.ts +2 -0
- package/dist/auth/axios/axiosInstance.d.ts.map +1 -0
- package/dist/auth/axios/axiosInstance.js +8 -0
- package/dist/auth/csrf.d.ts +30 -0
- package/dist/auth/csrf.d.ts.map +1 -0
- package/dist/auth/csrf.js +76 -0
- package/dist/auth/hooks/index.d.ts +4 -0
- package/dist/auth/hooks/index.d.ts.map +1 -0
- package/dist/auth/hooks/index.js +3 -0
- package/dist/auth/hooks/useAxiosPrivate.d.ts +5 -0
- package/dist/auth/hooks/useAxiosPrivate.d.ts.map +1 -0
- package/dist/auth/hooks/useAxiosPrivate.js +74 -0
- package/dist/auth/hooks/useRefreshToken.d.ts +7 -0
- package/dist/auth/hooks/useRefreshToken.d.ts.map +1 -0
- package/dist/auth/hooks/useRefreshToken.js +79 -0
- package/dist/auth/index.d.ts +23 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +44 -0
- package/dist/auth/jwt.d.ts +6 -0
- package/dist/auth/jwt.d.ts.map +1 -0
- package/dist/auth/jwt.js +25 -0
- package/dist/auth/lib/actions.d.ts +33 -0
- package/dist/auth/lib/actions.d.ts.map +1 -0
- package/dist/auth/lib/actions.js +209 -0
- package/dist/auth/lib/client.d.ts +4 -0
- package/dist/auth/lib/client.d.ts.map +1 -0
- package/dist/auth/lib/client.js +46 -0
- package/dist/auth/lib/index.d.ts +3 -0
- package/dist/auth/lib/index.d.ts.map +1 -0
- package/dist/auth/lib/index.js +2 -0
- package/dist/auth/react.d.ts +106 -0
- package/dist/auth/react.d.ts.map +1 -0
- package/dist/auth/react.js +347 -0
- package/dist/auth/trpc.d.ts +6 -0
- package/dist/auth/trpc.d.ts.map +1 -0
- package/dist/auth/trpc.js +81 -0
- package/dist/core/config/config-loader.d.ts +92 -0
- package/dist/core/config/config-loader.d.ts.map +1 -0
- package/dist/core/config/config-loader.js +230 -0
- package/dist/core/config/index.d.ts +3 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +1 -0
- package/dist/core/config/loader.d.ts +2 -0
- package/dist/core/config/loader.d.ts.map +1 -0
- package/dist/core/config/loader.js +42 -0
- package/dist/core/db/index.d.ts +2 -0
- package/dist/core/db/index.d.ts.map +1 -0
- package/dist/core/db/index.js +1 -0
- package/dist/core/db/table-checker/DbTable.d.ts +6 -0
- package/dist/core/db/table-checker/DbTable.d.ts.map +1 -0
- package/dist/core/db/table-checker/DbTable.js +5 -0
- package/dist/core/db/table-checker/MysqlTable.d.ts +34 -0
- package/dist/core/db/table-checker/MysqlTable.d.ts.map +1 -0
- package/dist/core/db/table-checker/MysqlTable.js +102 -0
- package/dist/core/db/table-checker/index.d.ts +2 -0
- package/dist/core/db/table-checker/index.d.ts.map +1 -0
- package/dist/core/db/table-checker/index.js +1 -0
- package/dist/core/factories/FieldFactory.d.ts +124 -0
- package/dist/core/factories/FieldFactory.d.ts.map +1 -0
- package/dist/core/factories/FieldFactory.js +411 -0
- package/dist/core/factories/SectionFactory.d.ts +110 -0
- package/dist/core/factories/SectionFactory.d.ts.map +1 -0
- package/dist/core/factories/SectionFactory.js +415 -0
- package/dist/core/factories/index.d.ts +3 -0
- package/dist/core/factories/index.d.ts.map +1 -0
- package/dist/core/factories/index.js +2 -0
- package/dist/core/fields/checkbox.d.ts +63 -0
- package/dist/core/fields/checkbox.d.ts.map +1 -0
- package/dist/core/fields/checkbox.js +62 -0
- package/dist/core/fields/color.d.ts +84 -0
- package/dist/core/fields/color.d.ts.map +1 -0
- package/dist/core/fields/color.js +91 -0
- package/dist/core/fields/date.d.ts +100 -0
- package/dist/core/fields/date.d.ts.map +1 -0
- package/dist/core/fields/date.js +108 -0
- package/dist/core/fields/document.d.ts +180 -0
- package/dist/core/fields/document.d.ts.map +1 -0
- package/dist/core/fields/document.js +277 -0
- package/dist/core/fields/field-group.d.ts +18 -0
- package/dist/core/fields/field-group.d.ts.map +1 -0
- package/dist/core/fields/field-group.js +6 -0
- package/dist/core/fields/field.d.ts +126 -0
- package/dist/core/fields/field.d.ts.map +1 -0
- package/dist/core/fields/field.js +148 -0
- package/dist/core/fields/fileField.d.ts +15 -0
- package/dist/core/fields/fileField.d.ts.map +1 -0
- package/dist/core/fields/fileField.js +5 -0
- package/dist/core/fields/index.d.ts +65 -0
- package/dist/core/fields/index.d.ts.map +1 -0
- package/dist/core/fields/index.js +18 -0
- package/dist/core/fields/map.d.ts +167 -0
- package/dist/core/fields/map.d.ts.map +1 -0
- package/dist/core/fields/map.js +152 -0
- package/dist/core/fields/number.d.ts +186 -0
- package/dist/core/fields/number.d.ts.map +1 -0
- package/dist/core/fields/number.js +241 -0
- package/dist/core/fields/password.d.ts +109 -0
- package/dist/core/fields/password.d.ts.map +1 -0
- package/dist/core/fields/password.js +133 -0
- package/dist/core/fields/photo.d.ts +289 -0
- package/dist/core/fields/photo.d.ts.map +1 -0
- package/dist/core/fields/photo.js +410 -0
- package/dist/core/fields/richText.d.ts +295 -0
- package/dist/core/fields/richText.d.ts.map +1 -0
- package/dist/core/fields/richText.js +338 -0
- package/dist/core/fields/select.d.ts +366 -0
- package/dist/core/fields/select.d.ts.map +1 -0
- package/dist/core/fields/select.js +499 -0
- package/dist/core/fields/selectMultiple.d.ts +236 -0
- package/dist/core/fields/selectMultiple.d.ts.map +1 -0
- package/dist/core/fields/selectMultiple.js +417 -0
- package/dist/core/fields/tags.d.ts +131 -0
- package/dist/core/fields/tags.d.ts.map +1 -0
- package/dist/core/fields/tags.js +105 -0
- package/dist/core/fields/text.d.ts +136 -0
- package/dist/core/fields/text.d.ts.map +1 -0
- package/dist/core/fields/text.js +157 -0
- package/dist/core/fields/textArea.d.ts +107 -0
- package/dist/core/fields/textArea.d.ts.map +1 -0
- package/dist/core/fields/textArea.js +126 -0
- package/dist/core/fields/video.d.ts +148 -0
- package/dist/core/fields/video.d.ts.map +1 -0
- package/dist/core/fields/video.js +248 -0
- package/dist/core/helpers/entity.d.ts +8 -0
- package/dist/core/helpers/entity.d.ts.map +1 -0
- package/dist/core/helpers/entity.js +27 -0
- package/dist/core/helpers/index.d.ts +5 -0
- package/dist/core/helpers/index.d.ts.map +1 -0
- package/dist/core/helpers/index.js +3 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +7 -0
- package/dist/core/sections/category.d.ts +283 -0
- package/dist/core/sections/category.d.ts.map +1 -0
- package/dist/core/sections/category.js +147 -0
- package/dist/core/sections/hasItems.d.ts +632 -0
- package/dist/core/sections/hasItems.d.ts.map +1 -0
- package/dist/core/sections/hasItems.js +144 -0
- package/dist/core/sections/index.d.ts +5 -0
- package/dist/core/sections/index.d.ts.map +1 -0
- package/dist/core/sections/index.js +4 -0
- package/dist/core/sections/section.d.ts +226 -0
- package/dist/core/sections/section.d.ts.map +1 -0
- package/dist/core/sections/section.js +341 -0
- package/dist/core/sections/simple.d.ts +99 -0
- package/dist/core/sections/simple.d.ts.map +1 -0
- package/dist/core/sections/simple.js +95 -0
- package/dist/core/security/dom.d.ts +11 -0
- package/dist/core/security/dom.d.ts.map +1 -0
- package/dist/core/security/dom.js +92 -0
- package/dist/core/submit/ItemEditSubmit.d.ts +76 -0
- package/dist/core/submit/ItemEditSubmit.d.ts.map +1 -0
- package/dist/core/submit/ItemEditSubmit.js +186 -0
- package/dist/core/submit/NewItemSubmit.d.ts +14 -0
- package/dist/core/submit/NewItemSubmit.d.ts.map +1 -0
- package/dist/core/submit/NewItemSubmit.js +93 -0
- package/dist/core/submit/SimpleSectionSubmit.d.ts +13 -0
- package/dist/core/submit/SimpleSectionSubmit.d.ts.map +1 -0
- package/dist/core/submit/SimpleSectionSubmit.js +93 -0
- package/dist/core/submit/index.d.ts +5 -0
- package/dist/core/submit/index.d.ts.map +1 -0
- package/dist/core/submit/index.js +4 -0
- package/dist/core/submit/submit.d.ts +116 -0
- package/dist/core/submit/submit.d.ts.map +1 -0
- package/dist/core/submit/submit.js +479 -0
- package/dist/core/types/index.d.ts +280 -0
- package/dist/core/types/index.d.ts.map +1 -0
- package/dist/core/types/index.js +1 -0
- package/dist/db/client.d.ts +9 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +19 -0
- package/dist/db/config.d.ts +6 -0
- package/dist/db/config.d.ts.map +1 -0
- package/dist/db/config.js +22 -0
- package/dist/db/drizzle.config.d.ts +6 -0
- package/dist/db/drizzle.config.d.ts.map +1 -0
- package/dist/db/drizzle.config.js +18 -0
- package/dist/db/index.d.ts +3 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +3 -0
- package/dist/db/schema.d.ts +639 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +73 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/translations/dictionaries/ar.json +279 -0
- package/dist/translations/dictionaries/en.json +279 -0
- package/dist/translations/index.d.ts +3 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +15 -0
- package/dist/utils/CpanelApi.d.ts +25 -0
- package/dist/utils/CpanelApi.d.ts.map +1 -0
- package/dist/utils/CpanelApi.js +64 -0
- package/dist/utils/constants.d.ts +14 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +61 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/utils.d.ts +60 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +132 -0
- package/dist/validators/checkbox.d.ts +4 -0
- package/dist/validators/checkbox.d.ts.map +1 -0
- package/dist/validators/checkbox.js +12 -0
- package/dist/validators/color.d.ts +4 -0
- package/dist/validators/color.d.ts.map +1 -0
- package/dist/validators/color.js +7 -0
- package/dist/validators/date.d.ts +4 -0
- package/dist/validators/date.d.ts.map +1 -0
- package/dist/validators/date.js +5 -0
- package/dist/validators/document.d.ts +4 -0
- package/dist/validators/document.d.ts.map +1 -0
- package/dist/validators/document.js +57 -0
- package/dist/validators/index.d.ts +15 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +14 -0
- package/dist/validators/map.d.ts +4 -0
- package/dist/validators/map.d.ts.map +1 -0
- package/dist/validators/map.js +5 -0
- package/dist/validators/number.d.ts +4 -0
- package/dist/validators/number.d.ts.map +1 -0
- package/dist/validators/number.js +20 -0
- package/dist/validators/password.d.ts +4 -0
- package/dist/validators/password.d.ts.map +1 -0
- package/dist/validators/password.js +11 -0
- package/dist/validators/photo.d.ts +4 -0
- package/dist/validators/photo.d.ts.map +1 -0
- package/dist/validators/photo.js +100 -0
- package/dist/validators/richText.d.ts +4 -0
- package/dist/validators/richText.d.ts.map +1 -0
- package/dist/validators/richText.js +8 -0
- package/dist/validators/select-multiple.d.ts +10 -0
- package/dist/validators/select-multiple.d.ts.map +1 -0
- package/dist/validators/select-multiple.js +20 -0
- package/dist/validators/select.d.ts +4 -0
- package/dist/validators/select.d.ts.map +1 -0
- package/dist/validators/select.js +5 -0
- package/dist/validators/text.d.ts +4 -0
- package/dist/validators/text.d.ts.map +1 -0
- package/dist/validators/text.js +7 -0
- package/dist/validators/textarea.d.ts +4 -0
- package/dist/validators/textarea.d.ts.map +1 -0
- package/dist/validators/textarea.js +7 -0
- package/dist/validators/video.d.ts +4 -0
- package/dist/validators/video.d.ts.map +1 -0
- package/dist/validators/video.js +57 -0
- package/package.json +150 -6
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Section } from '../sections';
|
|
2
|
+
import type { Session } from '../../auth';
|
|
3
|
+
type ConstructorType = {
|
|
4
|
+
type: 'new';
|
|
5
|
+
sectionName: string;
|
|
6
|
+
session: Session;
|
|
7
|
+
itemId?: never;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'edit';
|
|
10
|
+
sectionName: string;
|
|
11
|
+
session: Session;
|
|
12
|
+
itemId: number | string;
|
|
13
|
+
};
|
|
14
|
+
export declare class FieldFactory {
|
|
15
|
+
private readonly session;
|
|
16
|
+
private _values;
|
|
17
|
+
private itemId;
|
|
18
|
+
private _error;
|
|
19
|
+
private _errorMessage;
|
|
20
|
+
protected type: 'new' | 'edit';
|
|
21
|
+
protected sectionName: string;
|
|
22
|
+
private _sectionInfo;
|
|
23
|
+
/**
|
|
24
|
+
* Default order value for items without explicit order.
|
|
25
|
+
* Ensures items without order come after explicitly ordered items.
|
|
26
|
+
* Typical order values: 0-15, with occasional values up to 1000.
|
|
27
|
+
*/
|
|
28
|
+
private static readonly DEFAULT_ORDER;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
*/
|
|
32
|
+
constructor({ type, sectionName, session, itemId }: ConstructorType);
|
|
33
|
+
/**
|
|
34
|
+
* Must be called after the constructor
|
|
35
|
+
*/
|
|
36
|
+
initialize(): Promise<void>;
|
|
37
|
+
private getFieldValue;
|
|
38
|
+
private initializeFieldValues;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the section info and assigns it to the `sectionInfo` property
|
|
41
|
+
* @param session
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
private initializeSectionInfo;
|
|
45
|
+
/**
|
|
46
|
+
* Get the section info from the `sectionsTable` table
|
|
47
|
+
* @param session
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
private getSectionInfo;
|
|
51
|
+
/**
|
|
52
|
+
* Prepare a field for use
|
|
53
|
+
* Fields are already instances (resolved in Section constructor), so we just need to set values
|
|
54
|
+
* @param field
|
|
55
|
+
*/
|
|
56
|
+
private prepareField;
|
|
57
|
+
private addPermissionField;
|
|
58
|
+
/**
|
|
59
|
+
* Generate the fields
|
|
60
|
+
*/
|
|
61
|
+
generateFields(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Sort the fields.
|
|
64
|
+
* This function sorts the conditional fields into their respective fields.
|
|
65
|
+
*/
|
|
66
|
+
private sortFields;
|
|
67
|
+
/**
|
|
68
|
+
* Sort fields by their order property, preserving original position for fields without order.
|
|
69
|
+
*
|
|
70
|
+
* Sorting behavior:
|
|
71
|
+
* 1. Fields with explicit `order` values are sorted by that value (ascending)
|
|
72
|
+
* 2. Fields without `order` maintain their original array position (stable sort)
|
|
73
|
+
* 3. Fields with the same `order` value maintain their relative positions (stable sort)
|
|
74
|
+
*
|
|
75
|
+
* This leverages JavaScript's stable Array.sort() (ES2019+) for optimal performance.
|
|
76
|
+
* Note: This mutates the input array for performance.
|
|
77
|
+
*
|
|
78
|
+
* @param fields - Array of fields to sort (will be mutated)
|
|
79
|
+
* @returns The sorted array (same reference as input)
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private sortFieldsByOrder;
|
|
83
|
+
/**
|
|
84
|
+
* Sort groups by their groupOrder property, preserving original position for groups without order.
|
|
85
|
+
*
|
|
86
|
+
* Sorting behavior:
|
|
87
|
+
* 1. Groups with explicit `groupOrder` values are sorted by that value (ascending)
|
|
88
|
+
* 2. Groups without `groupOrder` maintain their original array position (stable sort)
|
|
89
|
+
* 3. Groups with the same `groupOrder` value maintain their relative positions (stable sort)
|
|
90
|
+
*
|
|
91
|
+
* This leverages JavaScript's stable Array.sort() (ES2019+) for optimal performance.
|
|
92
|
+
* Note: This mutates the input array for performance.
|
|
93
|
+
* Note: groupOrder is normalized at creation time, so no nullish coalescing needed here.
|
|
94
|
+
*
|
|
95
|
+
* @param groups - Array of groups to sort (will be mutated)
|
|
96
|
+
* @returns The sorted array (same reference as input)
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
private sortGroupsByOrder;
|
|
100
|
+
/**
|
|
101
|
+
* Get field groups with filtered and sorted fields.
|
|
102
|
+
* Leverages the pre-built fieldGroups from the Section class for better performance.
|
|
103
|
+
*/
|
|
104
|
+
getGroupedFields(): {
|
|
105
|
+
groupId: number;
|
|
106
|
+
groupTitle: string;
|
|
107
|
+
groupOrder: number;
|
|
108
|
+
inputs: {
|
|
109
|
+
type: import("../types").FieldType;
|
|
110
|
+
name: string;
|
|
111
|
+
label: string;
|
|
112
|
+
required: boolean;
|
|
113
|
+
conditionalFields: import("../types").ConditionalField[];
|
|
114
|
+
readonly: boolean;
|
|
115
|
+
defaultValue: any;
|
|
116
|
+
value: any;
|
|
117
|
+
}[];
|
|
118
|
+
}[] | undefined;
|
|
119
|
+
get sectionInfo(): Section | undefined;
|
|
120
|
+
get errorMessage(): string;
|
|
121
|
+
get error(): boolean;
|
|
122
|
+
}
|
|
123
|
+
export {};
|
|
124
|
+
//# sourceMappingURL=FieldFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldFactory.d.ts","sourceRoot":"","sources":["../../../src/core/factories/FieldFactory.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAIzC,KAAK,eAAe,GACd;IACI,IAAI,EAAE,KAAK,CAAA;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,KAAK,CAAA;CACjB,GACD;IACI,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAC1B,CAAA;AAEP,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,aAAa,CAAa;IAClC,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAAA;IAC9B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAA;IAC7B,OAAO,CAAC,YAAY,CAA4B;IAGhD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAY;IAEjD;;OAEG;gBACS,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,eAAe;IASnE;;OAEG;IACU,UAAU;YAUT,aAAa;YASb,qBAAqB;IAkEnC;;;;OAIG;YACW,qBAAqB;IAuCnC;;;;OAIG;YACW,cAAc;IAuB5B;;;;OAIG;YACW,YAAY;IAgB1B,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACU,cAAc;IAqB3B;;;OAGG;IACH,OAAO,CAAC,UAAU;IA4ElB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAOzB;;;OAGG;IACI,gBAAgB;;;;;;;;;;;;;;;IAmEvB,IAAI,WAAW,IAAI,OAAO,GAAG,SAAS,CAErC;IACD,IAAI,YAAY,IAAI,MAAM,CAEzB;IACD,IAAI,KAAK,IAAI,OAAO,CAEnB;CACJ"}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { db } from '../../db/client';
|
|
3
|
+
import { SectionFactory } from './SectionFactory';
|
|
4
|
+
import { SimpleSection, HasItemsSection, CategorySection } from '../sections';
|
|
5
|
+
import { checkboxField, SelectField, SelectMultipleField } from '../fields';
|
|
6
|
+
import { is } from '../helpers';
|
|
7
|
+
import { cloneDeep } from 'lodash-es';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
export class FieldFactory {
|
|
10
|
+
session;
|
|
11
|
+
_values = {};
|
|
12
|
+
itemId = undefined;
|
|
13
|
+
_error = false;
|
|
14
|
+
_errorMessage = '';
|
|
15
|
+
type;
|
|
16
|
+
sectionName;
|
|
17
|
+
_sectionInfo;
|
|
18
|
+
// private _fields: Field[]
|
|
19
|
+
/**
|
|
20
|
+
* Default order value for items without explicit order.
|
|
21
|
+
* Ensures items without order come after explicitly ordered items.
|
|
22
|
+
* Typical order values: 0-15, with occasional values up to 1000.
|
|
23
|
+
*/
|
|
24
|
+
static DEFAULT_ORDER = 1_000_000;
|
|
25
|
+
/**
|
|
26
|
+
* Constructor
|
|
27
|
+
*/
|
|
28
|
+
constructor({ type, sectionName, session, itemId }) {
|
|
29
|
+
this.type = type;
|
|
30
|
+
this.sectionName = sectionName;
|
|
31
|
+
this.session = session;
|
|
32
|
+
this.itemId = itemId;
|
|
33
|
+
// this._fields = new Array<Field>()
|
|
34
|
+
this._sectionInfo = undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Must be called after the constructor
|
|
38
|
+
*/
|
|
39
|
+
async initialize() {
|
|
40
|
+
await this.initializeSectionInfo(this.session);
|
|
41
|
+
/**
|
|
42
|
+
* If it's an edit operation, let's initialize the field values
|
|
43
|
+
*/
|
|
44
|
+
if (this.type === 'edit') {
|
|
45
|
+
await this.initializeFieldValues();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async getFieldValue(field) {
|
|
49
|
+
if (this.type === 'new')
|
|
50
|
+
return undefined;
|
|
51
|
+
try {
|
|
52
|
+
return this._values[field.name];
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async initializeFieldValues() {
|
|
59
|
+
if (this._error)
|
|
60
|
+
return;
|
|
61
|
+
if (this._sectionInfo?.db.table && this._sectionInfo.db.identifier) {
|
|
62
|
+
/**
|
|
63
|
+
* Let's get the section item values from its table and assign it to the `_values` property
|
|
64
|
+
*/
|
|
65
|
+
// TODO: We still need to get the values from the `destinationDbTable` if it exists on any field
|
|
66
|
+
// also, select_multiple fields need to be handled the same way, plus value is array of strings
|
|
67
|
+
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`);
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
// Bug: this is a bug in drizzle-orm/mysql2
|
|
70
|
+
this._values = _v[0];
|
|
71
|
+
/**
|
|
72
|
+
* If the field has a destinationDb
|
|
73
|
+
* Get the result from the field's table and the destinationDb's table using a JOIN query
|
|
74
|
+
* Fields that can have a destinationDb are: SelectField, SelectMultipleField, TagsField
|
|
75
|
+
*/
|
|
76
|
+
for (const field of this._sectionInfo.fields) {
|
|
77
|
+
if (field.destinationDb && (is(field, SelectMultipleField) || is(field, SelectField))) {
|
|
78
|
+
const sqlChunks = [
|
|
79
|
+
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}`,
|
|
80
|
+
];
|
|
81
|
+
if (is(field, SelectField) && field.hasDepth()) {
|
|
82
|
+
/**
|
|
83
|
+
* Add the where clause to the select statement
|
|
84
|
+
*/
|
|
85
|
+
sqlChunks.push(sql ` ORDER BY b.level ASC`);
|
|
86
|
+
}
|
|
87
|
+
const [_rows, _fields] = await db.execute(sql.join(sqlChunks));
|
|
88
|
+
const values = [];
|
|
89
|
+
if (Array.isArray(_rows)) {
|
|
90
|
+
for (const row of _rows) {
|
|
91
|
+
values.push({
|
|
92
|
+
value: row[field.destinationDb.selectIdentifier],
|
|
93
|
+
label: row[field.db.label],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this._values[field.name] = values;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* If the section item is not found, set the `_error` property to true
|
|
102
|
+
*/
|
|
103
|
+
if (!is(this._sectionInfo, SimpleSection) && !this._values) {
|
|
104
|
+
this._error = true;
|
|
105
|
+
this._errorMessage = 'Item not found';
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this._error = true;
|
|
111
|
+
this._errorMessage = 'Section table or section table identifier is missing';
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Gets the section info and assigns it to the `sectionInfo` property
|
|
117
|
+
* @param session
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
async initializeSectionInfo(session) {
|
|
121
|
+
/**
|
|
122
|
+
* Get section info - could be a config (with build()) or an instance
|
|
123
|
+
* Section files should export configs, but we handle both for backward compatibility
|
|
124
|
+
*/
|
|
125
|
+
let _s = await this.getSectionInfo(session);
|
|
126
|
+
if (_s === undefined)
|
|
127
|
+
return;
|
|
128
|
+
/**
|
|
129
|
+
* Build the section from config when we need to use it
|
|
130
|
+
* SectionFactory returns configs, so we always build them here
|
|
131
|
+
*
|
|
132
|
+
* Double check if the config has a build() method
|
|
133
|
+
*/
|
|
134
|
+
if (typeof _s.build === 'function') {
|
|
135
|
+
// It's a config - build it to get a fresh instance
|
|
136
|
+
// We build here because we immediately need to access section properties (db.table, inputs, etc.)
|
|
137
|
+
this._sectionInfo = _s.build();
|
|
138
|
+
/**
|
|
139
|
+
* Build the fields from the field configs
|
|
140
|
+
*/
|
|
141
|
+
this._sectionInfo.buildFields();
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const errorMessage = 'Section config must have a build() method. Use helper functions like simpleSection(), hasItemsSection(), categorySection() to create section configs.';
|
|
145
|
+
console.error(chalk.bold.red('[FieldFactory Error]', errorMessage));
|
|
146
|
+
this._error = true;
|
|
147
|
+
this._errorMessage = errorMessage;
|
|
148
|
+
throw new Error(errorMessage);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Unset the `_s` variable to be garbage collected
|
|
152
|
+
*/
|
|
153
|
+
_s = undefined;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get the section info from the `sectionsTable` table
|
|
157
|
+
* @param session
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
async getSectionInfo(session) {
|
|
161
|
+
/**
|
|
162
|
+
* First, let's get the section details, and then get the section input fields
|
|
163
|
+
*/
|
|
164
|
+
const s = await SectionFactory.getSectionForAdmin({
|
|
165
|
+
name: this.sectionName,
|
|
166
|
+
admin: {
|
|
167
|
+
id: session.user.id,
|
|
168
|
+
requiredRole: this.type === 'new' ? 'C' : 'U',
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
if (!s || !s.name) {
|
|
172
|
+
this._error = true;
|
|
173
|
+
this._errorMessage = 'Section not found or you do not have access to this operation';
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
return s;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Prepare a field for use
|
|
180
|
+
* Fields are already instances (resolved in Section constructor), so we just need to set values
|
|
181
|
+
* @param field
|
|
182
|
+
*/
|
|
183
|
+
async prepareField(field) {
|
|
184
|
+
// Fields are already instances - no need to build them
|
|
185
|
+
// They were resolved from configs in the Section constructor
|
|
186
|
+
if (this.type === 'edit') {
|
|
187
|
+
/**
|
|
188
|
+
* If it's an edit operation, get the value from the database and set it
|
|
189
|
+
*/
|
|
190
|
+
const value = await this.getFieldValue(field);
|
|
191
|
+
// It's important to set the value to whatever is in the database,
|
|
192
|
+
// even if the field has a `defaultValue` set.
|
|
193
|
+
field.setValue(value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// TODO: Implement this, maybe set the roles in the trpc context?
|
|
197
|
+
addPermissionField() {
|
|
198
|
+
if (is(this._sectionInfo, HasItemsSection)) {
|
|
199
|
+
if (this._sectionInfo.requirePublishPermission && this.session.user) {
|
|
200
|
+
return checkboxField({
|
|
201
|
+
name: 'publish',
|
|
202
|
+
label: 'Publish',
|
|
203
|
+
required: true,
|
|
204
|
+
order: 1000,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generate the fields
|
|
211
|
+
*/
|
|
212
|
+
async generateFields() {
|
|
213
|
+
if (this._error)
|
|
214
|
+
return;
|
|
215
|
+
if (!this._sectionInfo)
|
|
216
|
+
return;
|
|
217
|
+
for (const input of this._sectionInfo.fields) {
|
|
218
|
+
/**
|
|
219
|
+
* If it's an edit operation, set the field to readonly if it's the identifier field,
|
|
220
|
+
* identifier fields must not be edited!
|
|
221
|
+
* They are always visible as a readonly text.
|
|
222
|
+
*/
|
|
223
|
+
if (this.type === 'edit' && input.name === this._sectionInfo.db.identifier.name) {
|
|
224
|
+
input.adminGenerated = 'readonly';
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Prepare the field (set values if editing)
|
|
228
|
+
*/
|
|
229
|
+
await this.prepareField(input);
|
|
230
|
+
}
|
|
231
|
+
this.sortFields();
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Sort the fields.
|
|
235
|
+
* This function sorts the conditional fields into their respective fields.
|
|
236
|
+
*/
|
|
237
|
+
sortFields() {
|
|
238
|
+
if (this._error)
|
|
239
|
+
return;
|
|
240
|
+
if (!this._sectionInfo)
|
|
241
|
+
return;
|
|
242
|
+
/**
|
|
243
|
+
* Create a map of conditional fields
|
|
244
|
+
*/
|
|
245
|
+
const _conditionalFieldMap = new Map();
|
|
246
|
+
/**
|
|
247
|
+
* Loop through the fields and get the conditional fields
|
|
248
|
+
*/
|
|
249
|
+
for (const input of this._sectionInfo.fields) {
|
|
250
|
+
input.conditionalFields = [];
|
|
251
|
+
/**
|
|
252
|
+
* Check if the field is conditional.
|
|
253
|
+
*/
|
|
254
|
+
if (input.isConditional()) {
|
|
255
|
+
for (const rule of input.conditionalRules ?? []) {
|
|
256
|
+
/**
|
|
257
|
+
* Add the conditional input to the conditional fields lists
|
|
258
|
+
*/
|
|
259
|
+
if (!_conditionalFieldMap.has(rule.field.name)) {
|
|
260
|
+
_conditionalFieldMap.set(rule.field.name, []);
|
|
261
|
+
}
|
|
262
|
+
_conditionalFieldMap.get(rule.field.name).push(
|
|
263
|
+
/**
|
|
264
|
+
* Clone the conditional field to avoid reference issues
|
|
265
|
+
*/
|
|
266
|
+
cloneDeep({
|
|
267
|
+
field: input.exportForClient(),
|
|
268
|
+
rule: {
|
|
269
|
+
condition: rule.condition,
|
|
270
|
+
value: rule.value,
|
|
271
|
+
},
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Assign conditionalFields to the appropriate fields
|
|
278
|
+
*/
|
|
279
|
+
for (const field of this._sectionInfo.fields) {
|
|
280
|
+
const matchingConditionalFields = _conditionalFieldMap.get(field.name);
|
|
281
|
+
if (matchingConditionalFields) {
|
|
282
|
+
field.conditionalFields.push(...matchingConditionalFields.map((clonedConditionalField) => ({
|
|
283
|
+
...clonedConditionalField,
|
|
284
|
+
rule: {
|
|
285
|
+
condition: clonedConditionalField.rule.condition,
|
|
286
|
+
value: clonedConditionalField.rule.value,
|
|
287
|
+
},
|
|
288
|
+
})));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Destroy the map
|
|
293
|
+
*/
|
|
294
|
+
_conditionalFieldMap.clear();
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Sort fields by their order property, preserving original position for fields without order.
|
|
298
|
+
*
|
|
299
|
+
* Sorting behavior:
|
|
300
|
+
* 1. Fields with explicit `order` values are sorted by that value (ascending)
|
|
301
|
+
* 2. Fields without `order` maintain their original array position (stable sort)
|
|
302
|
+
* 3. Fields with the same `order` value maintain their relative positions (stable sort)
|
|
303
|
+
*
|
|
304
|
+
* This leverages JavaScript's stable Array.sort() (ES2019+) for optimal performance.
|
|
305
|
+
* Note: This mutates the input array for performance.
|
|
306
|
+
*
|
|
307
|
+
* @param fields - Array of fields to sort (will be mutated)
|
|
308
|
+
* @returns The sorted array (same reference as input)
|
|
309
|
+
* @private
|
|
310
|
+
*/
|
|
311
|
+
sortFieldsByOrder(fields) {
|
|
312
|
+
// Sort in-place for performance (mutates array)
|
|
313
|
+
// JavaScript's sort is stable (ES2019+), so equal values maintain original order
|
|
314
|
+
return fields.sort((a, b) => (a.order ?? FieldFactory.DEFAULT_ORDER) - (b.order ?? FieldFactory.DEFAULT_ORDER));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Sort groups by their groupOrder property, preserving original position for groups without order.
|
|
318
|
+
*
|
|
319
|
+
* Sorting behavior:
|
|
320
|
+
* 1. Groups with explicit `groupOrder` values are sorted by that value (ascending)
|
|
321
|
+
* 2. Groups without `groupOrder` maintain their original array position (stable sort)
|
|
322
|
+
* 3. Groups with the same `groupOrder` value maintain their relative positions (stable sort)
|
|
323
|
+
*
|
|
324
|
+
* This leverages JavaScript's stable Array.sort() (ES2019+) for optimal performance.
|
|
325
|
+
* Note: This mutates the input array for performance.
|
|
326
|
+
* Note: groupOrder is normalized at creation time, so no nullish coalescing needed here.
|
|
327
|
+
*
|
|
328
|
+
* @param groups - Array of groups to sort (will be mutated)
|
|
329
|
+
* @returns The sorted array (same reference as input)
|
|
330
|
+
* @private
|
|
331
|
+
*/
|
|
332
|
+
sortGroupsByOrder(groups) {
|
|
333
|
+
// Sort in-place for performance (mutates array)
|
|
334
|
+
// JavaScript's sort is stable (ES2019+), so equal values maintain original order
|
|
335
|
+
// groupOrder is normalized at creation time, so direct subtraction is safe
|
|
336
|
+
return groups.sort((a, b) => a.groupOrder - b.groupOrder);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get field groups with filtered and sorted fields.
|
|
340
|
+
* Leverages the pre-built fieldGroups from the Section class for better performance.
|
|
341
|
+
*/
|
|
342
|
+
getGroupedFields() {
|
|
343
|
+
if (this._error)
|
|
344
|
+
return;
|
|
345
|
+
if (!this._sectionInfo)
|
|
346
|
+
return;
|
|
347
|
+
const fieldGroups = this._sectionInfo.fieldGroups;
|
|
348
|
+
const isNewOperation = this.type === 'new';
|
|
349
|
+
const isEditOperation = this.type === 'edit';
|
|
350
|
+
const isCategorySection = is(this._sectionInfo, CategorySection);
|
|
351
|
+
// Build groups in a single pass, skipping empty groups
|
|
352
|
+
const processedGroups = [];
|
|
353
|
+
for (let i = 0, len = fieldGroups.length; i < len; i++) {
|
|
354
|
+
const group = fieldGroups[i];
|
|
355
|
+
if (!group)
|
|
356
|
+
continue;
|
|
357
|
+
const fields = group.fields;
|
|
358
|
+
const validFields = [];
|
|
359
|
+
// Filter and collect valid fields in one pass
|
|
360
|
+
for (let j = 0, fieldLen = fields.length; j < fieldLen; j++) {
|
|
361
|
+
const field = fields[j];
|
|
362
|
+
if (!field)
|
|
363
|
+
continue;
|
|
364
|
+
// Skip conditional fields (they're nested in their parent field)
|
|
365
|
+
if (field.isConditional())
|
|
366
|
+
continue;
|
|
367
|
+
// For new item operations, exclude fields with adminGenerated not set to true
|
|
368
|
+
if (isNewOperation && field.adminGenerated !== true)
|
|
369
|
+
continue;
|
|
370
|
+
// For edit operations, exclude fields with adminGenerated set to false
|
|
371
|
+
if (isEditOperation && field.adminGenerated === false)
|
|
372
|
+
continue;
|
|
373
|
+
// For category sections, exclude parent_id and level fields
|
|
374
|
+
if (isCategorySection && (field.name === 'parent_id' || field.name === 'level'))
|
|
375
|
+
continue;
|
|
376
|
+
/**
|
|
377
|
+
* Add the field to the valid fields array
|
|
378
|
+
*/
|
|
379
|
+
validFields.push(field);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Only return the group if it has valid fields
|
|
383
|
+
*/
|
|
384
|
+
if (validFields.length > 0) {
|
|
385
|
+
processedGroups.push({
|
|
386
|
+
groupId: group.id,
|
|
387
|
+
groupTitle: group.title ?? '',
|
|
388
|
+
// Normalize order value here to avoid checking again in sort function
|
|
389
|
+
groupOrder: group.order ?? FieldFactory.DEFAULT_ORDER,
|
|
390
|
+
inputs: this.sortFieldsByOrder(validFields).map((field) => field.exportForClient()),
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// Sort groups by order using the optimized function
|
|
395
|
+
this.sortGroupsByOrder(processedGroups);
|
|
396
|
+
/**
|
|
397
|
+
* Unset the section info to be garbage collected
|
|
398
|
+
*/
|
|
399
|
+
this._sectionInfo = null;
|
|
400
|
+
return processedGroups;
|
|
401
|
+
}
|
|
402
|
+
get sectionInfo() {
|
|
403
|
+
return this._sectionInfo ?? undefined;
|
|
404
|
+
}
|
|
405
|
+
get errorMessage() {
|
|
406
|
+
return this._errorMessage;
|
|
407
|
+
}
|
|
408
|
+
get error() {
|
|
409
|
+
return this._error;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { HasItemsSection, SimpleSection, CategorySection } from '../sections';
|
|
2
|
+
import type { CategorySectionConfig, HasItemsSectionConfig, SimpleSectionConfig } from '../sections';
|
|
3
|
+
import type { SectionTypes } from '../types';
|
|
4
|
+
type AnySectionConfig = HasItemsSectionConfig | SimpleSectionConfig | CategorySectionConfig;
|
|
5
|
+
export declare class SectionFactory {
|
|
6
|
+
/**
|
|
7
|
+
* These are the fixed sections that can not be present in the sections folder.
|
|
8
|
+
*/
|
|
9
|
+
static readonly fixedSections: string[];
|
|
10
|
+
private static readonly isDev;
|
|
11
|
+
private static readonly isProd;
|
|
12
|
+
private static sectionProcessingErrors;
|
|
13
|
+
private static sectionFetchingErrors;
|
|
14
|
+
private static errorCount;
|
|
15
|
+
/**
|
|
16
|
+
* Global in-process cache for all section configs.
|
|
17
|
+
* Populated once per Node process via loadAllSections(),
|
|
18
|
+
* reused by all get*() calls until the process is restarted,
|
|
19
|
+
* so all subsequent calls reuse this array.
|
|
20
|
+
*/
|
|
21
|
+
private static allSectionsPromise;
|
|
22
|
+
private static allSectionsLoaded;
|
|
23
|
+
private static watcherStarted;
|
|
24
|
+
static bumpHotMarker(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get all sections
|
|
27
|
+
* @param type - The type of sections to get
|
|
28
|
+
* @returns The sections
|
|
29
|
+
*/
|
|
30
|
+
static getSections(type?: SectionTypes | SectionTypes[]): Promise<AnySectionConfig[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all accessible sections for an admin
|
|
33
|
+
* @param type - The type of section to get
|
|
34
|
+
* @param admin - The admin to get the sections for
|
|
35
|
+
* @returns The sections for the admin
|
|
36
|
+
*/
|
|
37
|
+
static getSectionsForAdmin({ type, admin, }: {
|
|
38
|
+
type?: SectionTypes | SectionTypes[];
|
|
39
|
+
admin: {
|
|
40
|
+
id: string;
|
|
41
|
+
requiredRole?: 'C' | 'U' | 'D';
|
|
42
|
+
};
|
|
43
|
+
}): Promise<{
|
|
44
|
+
simple: SimpleSectionConfig[];
|
|
45
|
+
has_items: HasItemsSectionConfig[];
|
|
46
|
+
category: CategorySectionConfig[];
|
|
47
|
+
fixed: string[];
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Get a section
|
|
51
|
+
* @param name - The name of the section to get
|
|
52
|
+
* @param type - The type of section to get
|
|
53
|
+
* @returns The section
|
|
54
|
+
*/
|
|
55
|
+
static getSection({ name, type, }: {
|
|
56
|
+
name: string;
|
|
57
|
+
type?: SectionTypes | SectionTypes[];
|
|
58
|
+
}): Promise<AnySectionConfig | null>;
|
|
59
|
+
/**
|
|
60
|
+
* Get an accessible section for an admin
|
|
61
|
+
* @param name - The name of the section to get
|
|
62
|
+
* @param type - The type of section to get
|
|
63
|
+
* @param admin - The admin to get the section for
|
|
64
|
+
* @returns The section for the admin
|
|
65
|
+
*/
|
|
66
|
+
static getSectionForAdmin({ name, type, admin, }: {
|
|
67
|
+
name: string;
|
|
68
|
+
type?: SectionTypes | SectionTypes[];
|
|
69
|
+
admin: {
|
|
70
|
+
id: string;
|
|
71
|
+
requiredRole?: 'C' | 'U' | 'D';
|
|
72
|
+
};
|
|
73
|
+
}): Promise<AnySectionConfig | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Create a Section instance from a section config
|
|
76
|
+
* The config must have a build() method (created via helper functions like simpleSection(), hasItemsSection(), etc.)
|
|
77
|
+
*
|
|
78
|
+
* Note: This factory only accepts configs. If you already have a Section instance,
|
|
79
|
+
* use it directly - don't pass it to this factory.
|
|
80
|
+
*
|
|
81
|
+
* @param config - A section config object with a build() method
|
|
82
|
+
* @returns A Section instance
|
|
83
|
+
* @throws Error if config doesn't have a build() method
|
|
84
|
+
*/
|
|
85
|
+
static create(config: {
|
|
86
|
+
build: () => HasItemsSection | SimpleSection | CategorySection;
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
}): HasItemsSection | SimpleSection | CategorySection;
|
|
89
|
+
/**
|
|
90
|
+
* Return a clone of the section(s) info to get a fresh copy of the section(s).
|
|
91
|
+
* Not cloning will cause the original section(s) (in *.section.ts file) to be modified!
|
|
92
|
+
* Each *.section.ts file must have exactly one default export (arrays are not allowed).
|
|
93
|
+
|
|
94
|
+
* @param name - The name of the section to get
|
|
95
|
+
* @param type - The type of section to get
|
|
96
|
+
* @param admin - The admin to get the section for
|
|
97
|
+
* @returns The section(s)
|
|
98
|
+
*/
|
|
99
|
+
private static get;
|
|
100
|
+
/**
|
|
101
|
+
* Load all *.section.ts files once, require their default exports,
|
|
102
|
+
* and cache the resulting configs for the lifetime of the process
|
|
103
|
+
* (until invalidated in dev by file changes).
|
|
104
|
+
*/
|
|
105
|
+
private static loadAllSections;
|
|
106
|
+
private static startWatcher;
|
|
107
|
+
private static init;
|
|
108
|
+
}
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=SectionFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionFactory.d.ts","sourceRoot":"","sources":["../../../src/core/factories/SectionFactory.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AA+C5C,KAAK,gBAAgB,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,qBAAqB,CAAA;AAY3F,qBAAa,cAAc;IACvB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,aAAa,WAAiD;IAE9E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAwC;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAc;IAE5C,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAA+B;IACrE,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAA+B;IACnE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAI;IAE7B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA2C;IAC5E,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAQ;IACxC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAQ;IAErC,MAAM,CAAC,aAAa,IAAI,IAAI;IAwB5B;;;;OAIG;WACU,WAAW,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI3F;;;;;OAKG;WACU,mBAAmB,CAAC,EAC7B,IAAI,EACJ,KAAK,GACR,EAAE;QACC,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;QACpC,KAAK,EAAE;YACH,EAAE,EAAE,MAAM,CAAA;YACV,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;SACjC,CAAA;KACJ,GAAG,OAAO,CAAC;QACR,MAAM,EAAE,mBAAmB,EAAE,CAAA;QAC7B,SAAS,EAAE,qBAAqB,EAAE,CAAA;QAClC,QAAQ,EAAE,qBAAqB,EAAE,CAAA;QACjC,KAAK,EAAE,MAAM,EAAE,CAAA;KAClB,CAAC;IA+BF;;;;;OAKG;WACU,UAAU,CAAC,EACpB,IAAI,EACJ,IAAI,GACP,EAAE;QACC,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;KACvC,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAKpC;;;;;;OAMG;WACU,kBAAkB,CAAC,EAC5B,IAAI,EACJ,IAAI,EACJ,KAAK,GACR,EAAE;QACC,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;QACpC,KAAK,EAAE;YACH,EAAE,EAAE,MAAM,CAAA;YACV,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;SACjC,CAAA;KACJ,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAKpC;;;;;;;;;;OAUG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;QAClB,KAAK,EAAE,MAAM,eAAe,GAAG,aAAa,GAAG,eAAe,CAAA;QAC9D,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACrB,GAAG,eAAe,GAAG,aAAa,GAAG,eAAe;IAYrD;;;;;;;;;OASG;mBACkB,GAAG;IA6FxB;;;;OAIG;mBACkB,eAAe;IAuHpC,OAAO,CAAC,MAAM,CAAC,YAAY;IA+D3B,OAAO,CAAC,MAAM,CAAC,IAAI;CAatB"}
|