ngx-t-forms-types 0.0.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 (139) hide show
  1. package/dist/Configs/currencies.d.ts +6 -0
  2. package/dist/Configs/currencies.js +1083 -0
  3. package/dist/Configs/datePipes.d.ts +4 -0
  4. package/dist/Configs/datePipes.js +16 -0
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.js +8 -0
  7. package/dist/interfaces/Form/ArrayFunctions.d.ts +9 -0
  8. package/dist/interfaces/Form/ArrayFunctions.js +7 -0
  9. package/dist/interfaces/Form/CustomeConfigInter.d.ts +10 -0
  10. package/dist/interfaces/Form/CustomeConfigInter.js +1 -0
  11. package/dist/interfaces/Form/FileUploadFn.d.ts +11 -0
  12. package/dist/interfaces/Form/FileUploadFn.js +1 -0
  13. package/dist/interfaces/Form/FormInClassUtils.d.ts +52 -0
  14. package/dist/interfaces/Form/FormInClassUtils.js +1 -0
  15. package/dist/interfaces/Form/IFormsInitStateInterface.d.ts +51 -0
  16. package/dist/interfaces/Form/IFormsInitStateInterface.js +14 -0
  17. package/dist/interfaces/Form/PrePopulateDataInterface.d.ts +4 -0
  18. package/dist/interfaces/Form/PrePopulateDataInterface.js +1 -0
  19. package/dist/interfaces/Form/formChangeHistory.d.ts +5 -0
  20. package/dist/interfaces/Form/formChangeHistory.js +1 -0
  21. package/dist/interfaces/Form/formInterface.d.ts +19 -0
  22. package/dist/interfaces/Form/formInterface.js +1 -0
  23. package/dist/interfaces/Form/formSubmissionHandleInterface.d.ts +7 -0
  24. package/dist/interfaces/Form/formSubmissionHandleInterface.js +1 -0
  25. package/dist/interfaces/Form/index.d.ts +12 -0
  26. package/dist/interfaces/Form/index.js +2 -0
  27. package/dist/interfaces/FormBuilder/DefaultEelement.d.ts +3 -0
  28. package/dist/interfaces/FormBuilder/DefaultEelement.js +741 -0
  29. package/dist/interfaces/FormBuilder/DefaultInputConfigInterface.d.ts +143 -0
  30. package/dist/interfaces/FormBuilder/DefaultInputConfigInterface.js +1 -0
  31. package/dist/interfaces/FormBuilder/ElementEditorTypes.d.ts +31 -0
  32. package/dist/interfaces/FormBuilder/ElementEditorTypes.js +40 -0
  33. package/dist/interfaces/FormBuilder/FormBuilderCallBackFunctions.d.ts +20 -0
  34. package/dist/interfaces/FormBuilder/FormBuilderCallBackFunctions.js +1 -0
  35. package/dist/interfaces/FormBuilder/FormInputKeys.d.ts +86 -0
  36. package/dist/interfaces/FormBuilder/FormInputKeys.js +90 -0
  37. package/dist/interfaces/FormBuilder/elementEditor.d.ts +82 -0
  38. package/dist/interfaces/FormBuilder/elementEditor.js +34 -0
  39. package/dist/interfaces/FormBuilder/index.d.ts +10 -0
  40. package/dist/interfaces/FormBuilder/index.js +6 -0
  41. package/dist/interfaces/FormBuilder/inputConfig/ElementEditConfig.d.ts +3 -0
  42. package/dist/interfaces/FormBuilder/inputConfig/ElementEditConfig.js +644 -0
  43. package/dist/interfaces/FormBuilder/inputConfig/getInputValueFromElement.d.ts +1 -0
  44. package/dist/interfaces/FormBuilder/inputConfig/getInputValueFromElement.js +37 -0
  45. package/dist/interfaces/FormBuilder/postmanCollection.d.ts +126 -0
  46. package/dist/interfaces/FormBuilder/postmanCollection.js +1 -0
  47. package/dist/interfaces/FormBuilder/workflowSelectionConfig.d.ts +7 -0
  48. package/dist/interfaces/FormBuilder/workflowSelectionConfig.js +1 -0
  49. package/dist/interfaces/FormSlide/accessTree.d.ts +23 -0
  50. package/dist/interfaces/FormSlide/accessTree.js +1 -0
  51. package/dist/interfaces/FormSlide/controlValidation.d.ts +12 -0
  52. package/dist/interfaces/FormSlide/controlValidation.js +1 -0
  53. package/dist/interfaces/FormSlide/formSlideInterface.d.ts +22 -0
  54. package/dist/interfaces/FormSlide/formSlideInterface.js +7 -0
  55. package/dist/interfaces/FormSlide/index.d.ts +4 -0
  56. package/dist/interfaces/FormSlide/index.js +2 -0
  57. package/dist/interfaces/Tower/ITowerFormSteps.d.ts +14 -0
  58. package/dist/interfaces/Tower/ITowerFormSteps.js +1 -0
  59. package/dist/interfaces/Tower/index.d.ts +2 -0
  60. package/dist/interfaces/Tower/index.js +1 -0
  61. package/dist/interfaces/environment/IStoreFunctions.d.ts +58 -0
  62. package/dist/interfaces/environment/IStoreFunctions.js +1 -0
  63. package/dist/interfaces/environment/environment.d.ts +6 -0
  64. package/dist/interfaces/environment/environment.js +1 -0
  65. package/dist/interfaces/environment/index.d.ts +2 -0
  66. package/dist/interfaces/environment/index.js +1 -0
  67. package/dist/interfaces/formInput/APIDataFetchingConfigurationInterface.d.ts +54 -0
  68. package/dist/interfaces/formInput/APIDataFetchingConfigurationInterface.js +7 -0
  69. package/dist/interfaces/formInput/BasicFormInputInterface.d.ts +141 -0
  70. package/dist/interfaces/formInput/BasicFormInputInterface.js +99 -0
  71. package/dist/interfaces/formInput/ConditionalInputRule.d.ts +7 -0
  72. package/dist/interfaces/formInput/ConditionalInputRule.js +1 -0
  73. package/dist/interfaces/formInput/DateRangePickerInput.d.ts +9 -0
  74. package/dist/interfaces/formInput/DateRangePickerInput.js +1 -0
  75. package/dist/interfaces/formInput/FileUploadInputInterface.d.ts +49 -0
  76. package/dist/interfaces/formInput/FileUploadInputInterface.js +40 -0
  77. package/dist/interfaces/formInput/FormControlCustomValidatorsInterface.d.ts +10 -0
  78. package/dist/interfaces/formInput/FormControlCustomValidatorsInterface.js +1 -0
  79. package/dist/interfaces/formInput/FormInputBasicOptionInterface.d.ts +4 -0
  80. package/dist/interfaces/formInput/FormInputBasicOptionInterface.js +1 -0
  81. package/dist/interfaces/formInput/FormSectionTitleDescription.d.ts +6 -0
  82. package/dist/interfaces/formInput/FormSectionTitleDescription.js +1 -0
  83. package/dist/interfaces/formInput/IMscoaAccount.d.ts +84 -0
  84. package/dist/interfaces/formInput/IMscoaAccount.js +1 -0
  85. package/dist/interfaces/formInput/MatDataOptionsInterface.d.ts +14 -0
  86. package/dist/interfaces/formInput/MatDataOptionsInterface.js +1 -0
  87. package/dist/interfaces/formInput/MatrixInputInterface.d.ts +8 -0
  88. package/dist/interfaces/formInput/MatrixInputInterface.js +1 -0
  89. package/dist/interfaces/formInput/MinimumInputRequiredInterface.d.ts +33 -0
  90. package/dist/interfaces/formInput/MinimumInputRequiredInterface.js +18 -0
  91. package/dist/interfaces/formInput/MscoaInput.d.ts +16 -0
  92. package/dist/interfaces/formInput/MscoaInput.js +19 -0
  93. package/dist/interfaces/formInput/MultipleInterface.d.ts +15 -0
  94. package/dist/interfaces/formInput/MultipleInterface.js +1 -0
  95. package/dist/interfaces/formInput/RichTextEditorInput.d.ts +8 -0
  96. package/dist/interfaces/formInput/RichTextEditorInput.js +5 -0
  97. package/dist/interfaces/formInput/TableConfigurationsInterface.d.ts +17 -0
  98. package/dist/interfaces/formInput/TableConfigurationsInterface.js +1 -0
  99. package/dist/interfaces/formInput/TableSelectionInput.d.ts +6 -0
  100. package/dist/interfaces/formInput/TableSelectionInput.js +1 -0
  101. package/dist/interfaces/formInput/TextAreaInput.d.ts +5 -0
  102. package/dist/interfaces/formInput/TextAreaInput.js +1 -0
  103. package/dist/interfaces/formInput/ToggleInputInterface.d.ts +8 -0
  104. package/dist/interfaces/formInput/ToggleInputInterface.js +5 -0
  105. package/dist/interfaces/formInput/calculatedFieldRules.d.ts +7 -0
  106. package/dist/interfaces/formInput/calculatedFieldRules.js +1 -0
  107. package/dist/interfaces/formInput/calculationVariableInterface.d.ts +21 -0
  108. package/dist/interfaces/formInput/calculationVariableInterface.js +7 -0
  109. package/dist/interfaces/formInput/index.d.ts +22 -0
  110. package/dist/interfaces/formInput/index.js +7 -0
  111. package/dist/interfaces/formInput/schema.d.ts +9 -0
  112. package/dist/interfaces/formInput/schema.js +1 -0
  113. package/dist/interfaces/formInput/userSignature.d.ts +7 -0
  114. package/dist/interfaces/formInput/userSignature.js +1 -0
  115. package/dist/interfaces/pipeline-builder/index.d.ts +2 -0
  116. package/dist/interfaces/pipeline-builder/index.js +2 -0
  117. package/dist/interfaces/pipeline-builder/pipelineStages.d.ts +47 -0
  118. package/dist/interfaces/pipeline-builder/pipelineStages.js +30 -0
  119. package/dist/interfaces/upgradeFunctions/interfaces/init-form.d.ts +268 -0
  120. package/dist/interfaces/upgradeFunctions/interfaces/init-form.js +6 -0
  121. package/dist/schemas/CalculatedFieldRulesSchema.d.ts +6 -0
  122. package/dist/schemas/CalculatedFieldRulesSchema.js +27 -0
  123. package/dist/schemas/FormInputSchema.d.ts +15 -0
  124. package/dist/schemas/FormInputSchema.js +197 -0
  125. package/dist/schemas/FormSchema.d.ts +26 -0
  126. package/dist/schemas/FormSchema.js +134 -0
  127. package/dist/schemas/MatOptionsSchema.d.ts +8 -0
  128. package/dist/schemas/MatOptionsSchema.js +54 -0
  129. package/dist/schemas/MscoaConfigSchema.d.ts +8 -0
  130. package/dist/schemas/MscoaConfigSchema.js +22 -0
  131. package/dist/schemas/customValidationSchema.d.ts +2 -0
  132. package/dist/schemas/customValidationSchema.js +8 -0
  133. package/dist/schemas/index.d.ts +4 -0
  134. package/dist/schemas/index.js +4 -0
  135. package/dist/schemas/tests/FormInputValidator.spec.d.ts +1 -0
  136. package/dist/schemas/tests/FormInputValidator.spec.js +68 -0
  137. package/dist/schemas/tests/MOCK_DATA.d.ts +49 -0
  138. package/dist/schemas/tests/MOCK_DATA.js +59 -0
  139. package/package.json +61 -0
@@ -0,0 +1,268 @@
1
+ import { MatFormFieldAppearance } from "@angular/material/form-field";
2
+ interface conditionalInputRule {
3
+ formControlName: string;
4
+ label: string;
5
+ testType: string;
6
+ valueMatch: string;
7
+ id: string;
8
+ }
9
+ interface MinimumInputRequiredInterface {
10
+ name: string;
11
+ type: 'default' | 'mapto' | 'mapDocFilter' | undefined;
12
+ primaryKey?: boolean;
13
+ value?: string;
14
+ mapTo?: MinInputMapInput | Array<MinInputMapInput> | undefined;
15
+ defaultValue?: string;
16
+ dataFor?: string;
17
+ activeChangeId: string | undefined;
18
+ }
19
+ interface MinInputMapInput {
20
+ activeChangeId: string | undefined;
21
+ formControlName: string;
22
+ dataType: string;
23
+ element: string;
24
+ }
25
+ interface DataFetchingBaseConfig {
26
+ valueAccessRules: FormInputBasicOptionInterface;
27
+ }
28
+ interface APIDataFetchingConfigurationInterface extends DataFetchingBaseConfig {
29
+ _id: string;
30
+ name: string;
31
+ httpEndPoint: string;
32
+ inputSourceId?: string;
33
+ httpMethod: 'GET' | 'POST';
34
+ postFormData: boolean;
35
+ backEndConfig: {
36
+ minimumInputRequired: MinimumInputRequiredInterface[];
37
+ };
38
+ }
39
+ interface MongoDbPipeLineConfigInterface extends DataFetchingBaseConfig {
40
+ workflowId: string;
41
+ pipeline: any[];
42
+ }
43
+ interface FormInputBasicOptionInterface {
44
+ label: string;
45
+ value: string;
46
+ }
47
+ interface calculationVariableInterface {
48
+ formControlName: string;
49
+ label: string;
50
+ variable: string;
51
+ id: string;
52
+ function?: string;
53
+ parentInputId?: string;
54
+ parentInputFormControl?: string;
55
+ applyFunctionToCol?: string;
56
+ applyFunctionToLabel?: string;
57
+ filterValuesByThisColLabel?: string;
58
+ filterValuesByCol?: string;
59
+ tableCell?: boolean;
60
+ }
61
+ interface MatDataOptionsInterface {
62
+ source?: {
63
+ value?: string;
64
+ options?: string;
65
+ } | 'local';
66
+ optionType?: 'user';
67
+ options?: Array<FormInputBasicOptionInterface | DynamicObjectInterface>;
68
+ fetchFor?: string | 'valueForOptions';
69
+ fetch: {
70
+ value?: APIDataFetchingConfigurationInterface | MongoDbPipeLineConfigInterface;
71
+ options?: APIDataFetchingConfigurationInterface | MongoDbPipeLineConfigInterface;
72
+ };
73
+ }
74
+ interface DynamicObjectInterface {
75
+ [key: string | number]: number | string | boolean | object;
76
+ }
77
+ declare enum MaxMinCustomScripts {
78
+ IServeBudgetPeriods = "IServePeriods",
79
+ IServeDateLimiter = "IServeDateLimiter"
80
+ }
81
+ interface calculatedFieldRules {
82
+ formular: string;
83
+ variables: calculationVariableInterface[];
84
+ }
85
+ interface TableConfigurationsInterface {
86
+ displayedColumnsInOrder: string[];
87
+ columnsConfig: {
88
+ [key: string]: TableColumnConfigInterface | any;
89
+ };
90
+ }
91
+ interface TableColumnConfigInterface {
92
+ type: 'caluculated' | 'property' | 'checkBox' | 'primaryKey';
93
+ property: string;
94
+ reductionFunction?: 'sum';
95
+ calculatedFieldRules: calculatedFieldRules;
96
+ label: string;
97
+ inEdit: boolean;
98
+ checkUpto: string;
99
+ colorScale?: string;
100
+ }
101
+ interface BasicFormInputInterface {
102
+ element: string;
103
+ matOptions?: MatDataOptionsInterface;
104
+ appearance: MatFormFieldAppearance;
105
+ required: boolean;
106
+ type: string;
107
+ color?: string;
108
+ colSize: number;
109
+ validators: Array<FormControlCustomValidatorsInterface | string>;
110
+ label: string;
111
+ formControlName: string;
112
+ labelPosition?: 'before' | 'after';
113
+ handleIcon: string;
114
+ startMinDate?: Date;
115
+ endMaxDate?: Date;
116
+ startMaxDate?: Date;
117
+ endDateControl?: string;
118
+ startDateControl?: string;
119
+ endMinDate?: Date;
120
+ id: string;
121
+ sectionId: string;
122
+ handleLabel?: string;
123
+ pipe?: {
124
+ pipeType: string;
125
+ param: string;
126
+ };
127
+ hintLabel?: string;
128
+ tourContent?: string;
129
+ value?: any;
130
+ min?: number | string | Date | MaxMinCustomScripts;
131
+ max?: number | string | Date | MaxMinCustomScripts;
132
+ maxLength?: string;
133
+ minLength?: string;
134
+ placeholder?: string;
135
+ readonly?: boolean;
136
+ pattern?: string;
137
+ spellcheck?: boolean;
138
+ rows?: number;
139
+ autocapitalize?: string | 'none' | 'sentences' | 'words' | 'characters';
140
+ wrap?: string | 'hard' | 'soft';
141
+ autocomplete?: string | 'on' | 'off';
142
+ multipleInputInEditId?: string;
143
+ suffixText?: string;
144
+ prefixText?: string;
145
+ prefixIcon?: string;
146
+ suffixIcon?: string;
147
+ disabled?: boolean;
148
+ conditionalInputConfig?: conditionalInputRule[];
149
+ calculatedFieldRules?: calculatedFieldRules;
150
+ viewType?: string;
151
+ }
152
+ interface multipleInterface extends BasicFormInputInterface {
153
+ itemLabels: {
154
+ label: string;
155
+ key: string;
156
+ property?: string;
157
+ }[];
158
+ formInputs: Array<IAllInputs>;
159
+ showTotalsOf: Array<string>;
160
+ groupBy: Array<string>;
161
+ }
162
+ interface IIncludedSegmentConfig {
163
+ segment: string;
164
+ label: string;
165
+ readOnly: boolean;
166
+ }
167
+ interface IMscoaInputConfig {
168
+ inputs: IAllInputs[];
169
+ segments: IIncludedSegmentConfig[];
170
+ showAllSegments: boolean;
171
+ }
172
+ interface matrixInputInterface extends BasicFormInputInterface {
173
+ matrixTableConfig: {
174
+ dataSource: string;
175
+ };
176
+ tableConfig: TableConfigurationsInterface;
177
+ }
178
+ interface MscoaInput extends BasicFormInputInterface {
179
+ mscoaConfig: IMscoaInputConfig;
180
+ }
181
+ interface TableSelectionInput extends BasicFormInputInterface {
182
+ selectUpto: number | undefined;
183
+ tableConfig: TableConfigurationsInterface;
184
+ }
185
+ interface fileUploadInputInterface extends BasicFormInputInterface {
186
+ fileType: string;
187
+ singleSelect?: boolean;
188
+ accept: string;
189
+ }
190
+ interface FormControlCustomValidatorsInterface {
191
+ id: string;
192
+ message: string;
193
+ expression: string;
194
+ canOverride: boolean;
195
+ inputsObservedForChanges: string[];
196
+ }
197
+ type IAllInputs = BasicFormInputInterface | multipleInterface | TableSelectionInput | MscoaInput | fileUploadInputInterface | matrixInputInterface;
198
+ interface SlideContentRowInterface {
199
+ columns: Array<IAllInputs>;
200
+ rowType: string;
201
+ }
202
+ interface FormSlideInterface {
203
+ sectionId: string;
204
+ slideContentRows: Array<SlideContentRowInterface>;
205
+ }
206
+ interface FormSubmisionHandleInterface {
207
+ innerComponentShowSubmitButton?: boolean;
208
+ localAction: boolean;
209
+ activeSubmisionMode?: boolean;
210
+ canSubmitAPI?: SubmissionAPI;
211
+ submissionId: SubmissionAPI;
212
+ handle: SubmissionHandle;
213
+ }
214
+ interface SubmissionAPI {
215
+ _id: string;
216
+ httpEndPoint: string;
217
+ httpMethod: 'POST' | 'GET';
218
+ }
219
+ interface SubmissionHandle {
220
+ submissionMessage: string;
221
+ }
222
+ interface SectionsDefinitionsInterface {
223
+ sectionId: string;
224
+ label: string;
225
+ subStep: boolean;
226
+ inEdit?: boolean;
227
+ expanded?: boolean;
228
+ sectionType?: string;
229
+ }
230
+ interface CustomConfigInterface {
231
+ showProgressBar?: boolean;
232
+ formBackground?: string;
233
+ closeAfterSubmission?: string;
234
+ formPrePopulationOption?: {
235
+ listHeading: string;
236
+ matTooltip: string;
237
+ label: string;
238
+ submissionId: string;
239
+ };
240
+ }
241
+ interface OLD_FormInterface {
242
+ slides: Array<FormSlideInterface>;
243
+ activeSlideNumber: number | 0;
244
+ horizontal?: boolean;
245
+ submisionHandle: FormSubmisionHandleInterface;
246
+ formId: string | any;
247
+ formTitle: string;
248
+ formSectionSteps: Array<SectionsDefinitionsInterface>;
249
+ prePopulationRules?: PrepopulateDataInterface;
250
+ customConfig?: CustomConfigInterface;
251
+ createdAt?: Date;
252
+ updatedAt?: Date;
253
+ originDocId?: string;
254
+ previousDocRef?: string;
255
+ doc_reference?: string;
256
+ }
257
+ interface PrepopulateDataInterface {
258
+ localFetchData?: FecthLocalStateData;
259
+ dbFecthData?: string;
260
+ fetchedInformations?: any;
261
+ }
262
+ interface FecthLocalStateData {
263
+ service: string;
264
+ method: string;
265
+ param: string;
266
+ passFunction?: string;
267
+ }
268
+ export { OLD_FormInterface, IAllInputs };
@@ -0,0 +1,6 @@
1
+ var MaxMinCustomScripts;
2
+ (function (MaxMinCustomScripts) {
3
+ MaxMinCustomScripts["IServeBudgetPeriods"] = "IServePeriods";
4
+ MaxMinCustomScripts["IServeDateLimiter"] = "IServeDateLimiter";
5
+ })(MaxMinCustomScripts || (MaxMinCustomScripts = {}));
6
+ export {};
@@ -0,0 +1,6 @@
1
+ import * as Joi from 'joi';
2
+ export declare const calculatedFieldRulesSchema: Joi.ObjectSchema<any>;
3
+ export declare function validateCalculatedFieldRules(value: any): {
4
+ error: Joi.ValidationError | undefined;
5
+ value: any;
6
+ };
@@ -0,0 +1,27 @@
1
+ import * as Joi from 'joi';
2
+ const calculationVariableSchema = Joi.object({
3
+ formControlName: Joi.string().required(),
4
+ label: Joi.string().required(),
5
+ variable: Joi.string().required(),
6
+ id: Joi.string().required(),
7
+ inputId: Joi.string().required(),
8
+ function: Joi.string().valid('avg', 'sum', 'max', 'min').optional(),
9
+ parentInputId: Joi.string().optional(),
10
+ parentInputFormControl: Joi.string().optional(),
11
+ applyFunctionToCol: Joi.string().optional(),
12
+ applyFunctionToLabel: Joi.string().optional(),
13
+ filterValuesByThisColLabel: Joi.string().optional(),
14
+ filterValuesByCol: Joi.string().optional(),
15
+ tableCell: Joi.boolean().optional()
16
+ });
17
+ export const calculatedFieldRulesSchema = Joi.object({
18
+ formula: Joi.string().required(),
19
+ variables: Joi.array().items(calculationVariableSchema).required(),
20
+ getFormulaFromAFormInput: Joi.boolean().optional(),
21
+ formControlWithFormula: Joi.string().optional()
22
+ });
23
+ export function validateCalculatedFieldRules(value) {
24
+ const { error, value: validatedValue } = calculatedFieldRulesSchema.validate(value);
25
+ return { error, value: validatedValue };
26
+ }
27
+ console.error("ffffffffffffff");
@@ -0,0 +1,15 @@
1
+ import Joi from 'joi';
2
+ import { FormColumnInputs } from '../interfaces/Form';
3
+ import { ValidationError, ValidationOptions } from '../interfaces/formInput/schema';
4
+ declare const formColumnInputsSchema: Joi.ObjectSchema<any>;
5
+ declare function validateFormColumnInputs(data: FormColumnInputs): {
6
+ key: string;
7
+ message: string;
8
+ }[];
9
+ /**
10
+ * Validates form column inputs by separating required and optional fields
11
+ * @param options - ValidationOptions containing data and required keys
12
+ * @returns Array of ValidationError objects
13
+ */
14
+ declare function validateFormColumnInputsWithRequired({ data, requiredKeys }: ValidationOptions): ValidationError[];
15
+ export { formColumnInputsSchema, validateFormColumnInputs, validateFormColumnInputsWithRequired };
@@ -0,0 +1,197 @@
1
+ import Joi from 'joi';
2
+ import { AllFormInputPrimaryKeys } from '../interfaces/FormBuilder';
3
+ import { AutocapitalizeOptions, ElementTypes, InputDataTypes, InputPipeTypes, InputTypes } from '../interfaces/formInput';
4
+ // import { InputFileType } from '../interfaces/formInput/FileUploadInputInterface';
5
+ // import { LabelPosition } from '../interfaces/formInput/ToggleInputInterface';
6
+ // import { MscoaInputConfigSchema } from './MscoaConfigSchema';
7
+ // import { calculatedFieldRulesSchema } from './CalculatedFieldRulesSchema';
8
+ // import { MatDataOptionsSchema } from './MatOptionsSchema';
9
+ import { formControlCustomValidatorSchema } from './customValidationSchema';
10
+ import { InputFileType } from '../interfaces/formInput/FileUploadInputInterface';
11
+ import { LabelPosition } from '../interfaces/formInput/ToggleInputInterface';
12
+ import { calculatedFieldRulesSchema } from './CalculatedFieldRulesSchema';
13
+ import { MscoaInputConfigSchema } from './MscoaConfigSchema';
14
+ import { MatDataOptionsSchema } from './MatOptionsSchema';
15
+ import { CalculationFunctions } from '../interfaces/formInput/calculationVariableInterface';
16
+ import { RichTextEditorType } from '../interfaces/formInput/RichTextEditorInput';
17
+ import { InputViewTypes } from '../interfaces/formInput/BasicFormInputInterface';
18
+ const baseFormColumnInputsSchema = Joi.object({
19
+ [AllFormInputPrimaryKeys.Id]: Joi.string().optional(),
20
+ [AllFormInputPrimaryKeys.SectionId]: Joi.string().optional(),
21
+ [AllFormInputPrimaryKeys.Element]: Joi.string().valid(...Object.values(ElementTypes)).required(),
22
+ [AllFormInputPrimaryKeys.ColSize]: Joi.number().integer().min(1).max(12).required(),
23
+ [AllFormInputPrimaryKeys.Label]: Joi.string().required(),
24
+ [AllFormInputPrimaryKeys.FormControlName]: Joi.string().required(),
25
+ [AllFormInputPrimaryKeys.Appearance]: Joi.string().valid("fill", "outline").required(),
26
+ [AllFormInputPrimaryKeys.Required]: Joi.boolean().required(),
27
+ [AllFormInputPrimaryKeys.StartDateControl]: Joi.string().optional(),
28
+ [AllFormInputPrimaryKeys.EndDateControl]: Joi.string().optional(),
29
+ [AllFormInputPrimaryKeys.Type]: Joi.string().valid(...Object.values(InputTypes)).optional(),
30
+ [AllFormInputPrimaryKeys.FileType]: Joi.string().valid(...Object.values(InputFileType)).optional(),
31
+ [AllFormInputPrimaryKeys.SingleSelect]: Joi.boolean().optional(),
32
+ [AllFormInputPrimaryKeys.LabelPosition]: Joi.string().valid(...Object.values(LabelPosition)).optional(),
33
+ [AllFormInputPrimaryKeys.Min]: Joi.alternatives().try(Joi.number(), Joi.string(), Joi.date()).optional(),
34
+ [AllFormInputPrimaryKeys.Max]: Joi.alternatives().try(Joi.number(), Joi.string(), Joi.date()).optional(),
35
+ [AllFormInputPrimaryKeys.MinLength]: Joi.number().integer().optional(),
36
+ [AllFormInputPrimaryKeys.MaxLength]: Joi.number().integer().optional(),
37
+ [AllFormInputPrimaryKeys.MscoaConfig]: MscoaInputConfigSchema.optional(),
38
+ [AllFormInputPrimaryKeys.Value]: Joi.alternatives().try(Joi.number(), Joi.string().allow(''), Joi.boolean(), Joi.date(), Joi.object(), Joi.array().items(Joi.object())).optional(),
39
+ [AllFormInputPrimaryKeys.DataType]: Joi.string().valid(...Object.values(InputDataTypes)).required(),
40
+ [AllFormInputPrimaryKeys.Readonly]: Joi.boolean().optional(),
41
+ [AllFormInputPrimaryKeys.IServeInputWithRequisitionItems]: Joi.boolean().optional(),
42
+ [AllFormInputPrimaryKeys.CalculatedFieldRules]: calculatedFieldRulesSchema.optional(), // Assuming it's an object, adjust as needed
43
+ [AllFormInputPrimaryKeys.MatOptions]: MatDataOptionsSchema.optional(), // Assuming it's an object, adjust as needed
44
+ [AllFormInputPrimaryKeys.HintLabel]: Joi.string().allow('').optional(),
45
+ [AllFormInputPrimaryKeys.TourContent]: Joi.string().optional(),
46
+ [AllFormInputPrimaryKeys.Spellcheck]: Joi.boolean().optional(),
47
+ [AllFormInputPrimaryKeys.Pipe]: Joi.object({
48
+ pipeType: Joi.string().valid(...Object.values(InputPipeTypes)).required(),
49
+ param: Joi.string().required()
50
+ }).optional(),
51
+ [AllFormInputPrimaryKeys.Script]: Joi.object().optional(),
52
+ [AllFormInputPrimaryKeys.Validators]: Joi.array().items(Joi.alternatives().try(Joi.string(), formControlCustomValidatorSchema)).required(),
53
+ [AllFormInputPrimaryKeys.Accept]: Joi.string().optional(),
54
+ [AllFormInputPrimaryKeys.CalculateListFunctions]: Joi.array().items(Joi.object({
55
+ id: Joi.string().required(),
56
+ func: Joi.string().valid(...Object.values(CalculationFunctions)).required(),
57
+ })).optional(),
58
+ [AllFormInputPrimaryKeys.HandleLabel]: Joi.string().optional(),
59
+ [AllFormInputPrimaryKeys.MultipleInputInEditId]: Joi.string().optional(),
60
+ [AllFormInputPrimaryKeys.ShowAsLabel]: Joi.boolean().optional(),
61
+ [AllFormInputPrimaryKeys.Autocapitalize]: Joi.string().valid(...Object.values(AutocapitalizeOptions)).optional(),
62
+ [AllFormInputPrimaryKeys.Rows]: Joi.number().integer().optional(),
63
+ [AllFormInputPrimaryKeys.Wrap]: Joi.string().valid('hard', 'soft').optional(),
64
+ [AllFormInputPrimaryKeys.RichTextEditorLibrary]: Joi.string().valid(...Object.values(RichTextEditorType)).optional(),
65
+ [AllFormInputPrimaryKeys.OnlySetTempErrorOnTouch]: Joi.boolean().optional(),
66
+ [AllFormInputPrimaryKeys.IsCalculatedField]: Joi.boolean().optional(),
67
+ [AllFormInputPrimaryKeys.TemporaryHint]: Joi.string().optional(),
68
+ [AllFormInputPrimaryKeys.ValueUpdatedAt]: Joi.date().optional(),
69
+ [AllFormInputPrimaryKeys.Status]: Joi.object().pattern(Joi.string(), Joi.string()).optional(),
70
+ [AllFormInputPrimaryKeys.ViewType]: Joi.string().valid(...Object.values(InputViewTypes)).optional(),
71
+ [AllFormInputPrimaryKeys.FormIsOpen]: Joi.boolean().optional(),
72
+ }).id('formColumnInputs');
73
+ const formColumnInputsSchema = baseFormColumnInputsSchema.append({
74
+ [AllFormInputPrimaryKeys.FormInputs]: Joi.array().items(Joi.link('#formColumnInputs')).optional()
75
+ }).shared(baseFormColumnInputsSchema);
76
+ function validateFormColumnInputs(data) {
77
+ const isTitleInput = data[AllFormInputPrimaryKeys.Element] === ElementTypes.SectionTitle;
78
+ if (isTitleInput) {
79
+ return [];
80
+ }
81
+ const { error } = formColumnInputsSchema.validate(data, { abortEarly: false });
82
+ if (error) {
83
+ return error.details.map(detail => ({
84
+ key: detail.path.join('.'),
85
+ message: detail.message
86
+ }));
87
+ }
88
+ return [];
89
+ }
90
+ /**
91
+ * Validates form column inputs by separating required and optional fields
92
+ * @param options - ValidationOptions containing data and required keys
93
+ * @returns Array of ValidationError objects
94
+ */
95
+ function validateFormColumnInputsWithRequired({ data, requiredKeys }) {
96
+ try {
97
+ // Validate that all requiredKeys exist in schema
98
+ const schemaKeys = Object.values(AllFormInputPrimaryKeys);
99
+ const invalidRequiredKeys = requiredKeys.filter(key => !schemaKeys.includes(key));
100
+ if (invalidRequiredKeys.length > 0) {
101
+ return [{
102
+ key: 'validation',
103
+ message: `Invalid required keys: ${invalidRequiredKeys.join(', ')}`
104
+ }];
105
+ }
106
+ // Get all valid keys from the data object
107
+ const dataKeys = Object.keys(data);
108
+ const invalidDataKeys = dataKeys.filter(key => !schemaKeys.includes(key));
109
+ if (invalidDataKeys.length > 0) {
110
+ return [{
111
+ key: 'validation',
112
+ message: `Invalid data keys: ${invalidDataKeys.join(', ')}`
113
+ }];
114
+ }
115
+ const calculationRulesRequiredKeys = (data[AllFormInputPrimaryKeys.IsCalculatedField] === true && (!data[AllFormInputPrimaryKeys.CalculatedFieldRules] ||
116
+ Object.keys(data[AllFormInputPrimaryKeys.CalculatedFieldRules]).length === 0));
117
+ const allRequiredKeys = [...requiredKeys, ...(calculationRulesRequiredKeys ? [AllFormInputPrimaryKeys.CalculatedFieldRules] : [])];
118
+ // Validate required fields
119
+ const requiredValidationErrors = allRequiredKeys
120
+ .map(key => validateFormColumnInputKey(key, data[key], true));
121
+ // Validate optional fields (fields in data that aren't required)
122
+ const optionalValidationErrors = dataKeys
123
+ .filter(key => !requiredKeys.includes(key))
124
+ .map(key => validateFormColumnInputKey(key, data[key], false));
125
+ // Combine and flatten all validation errors
126
+ const allErrors = [
127
+ ...requiredValidationErrors,
128
+ ...optionalValidationErrors
129
+ ].flat();
130
+ return allErrors;
131
+ }
132
+ catch (err) {
133
+ // Enhanced error handling
134
+ if (err instanceof Error) {
135
+ return [{
136
+ key: 'validation',
137
+ message: err.message
138
+ }];
139
+ }
140
+ return [{
141
+ key: 'validation',
142
+ message: 'An unknown error occurred during validation'
143
+ }];
144
+ }
145
+ }
146
+ /**
147
+ * Validates a single key from the form input data
148
+ * @param key - The key to validate
149
+ * @param value - The value to validate
150
+ * @param isRequired - Whether this field should be treated as required
151
+ * @returns ValidationError[] - Empty array if valid, array with error if invalid
152
+ */
153
+ function validateFormColumnInputKey(key, value, isRequired = false) {
154
+ try {
155
+ // Get the original field schema
156
+ const fieldSchema = formColumnInputsSchema.extract(key);
157
+ if (!fieldSchema) {
158
+ return [{
159
+ key,
160
+ message: `Invalid field: ${key} does not exist in schema`
161
+ }];
162
+ }
163
+ // Apply required/optional state while preserving all other rules
164
+ const modifiedFieldSchema = isRequired ? fieldSchema.required() : fieldSchema.optional();
165
+ // Validate the single field
166
+ const { error } = modifiedFieldSchema.validate(value, {
167
+ abortEarly: false,
168
+ presence: isRequired ? 'required' : 'optional'
169
+ });
170
+ if (error) {
171
+ return error.details.map(detail => ({
172
+ key,
173
+ message: detail.message
174
+ }));
175
+ }
176
+ return [];
177
+ }
178
+ catch (err) {
179
+ if (err instanceof Error) {
180
+ if ('isJoi' in err && err.isJoi) {
181
+ return [{
182
+ key,
183
+ message: `Schema validation error: ${err.message}`
184
+ }];
185
+ }
186
+ return [{
187
+ key,
188
+ message: err.message
189
+ }];
190
+ }
191
+ return [{
192
+ key,
193
+ message: 'An unknown error occurred during validation'
194
+ }];
195
+ }
196
+ }
197
+ export { formColumnInputsSchema, validateFormColumnInputs, validateFormColumnInputsWithRequired };
@@ -0,0 +1,26 @@
1
+ import * as Joi from 'joi';
2
+ import { FormInterface } from "../interfaces/Form";
3
+ export declare const FormSlideSchema: Joi.ObjectSchema<any>;
4
+ export declare const FormSubmissionHandleSchema: Joi.ObjectSchema<any>;
5
+ export declare const FormSchema: Joi.ObjectSchema<any>;
6
+ export declare const DatabaseFormSchema: Joi.ObjectSchema<any>;
7
+ export declare function validateFormSlide(data: any): {
8
+ key: string;
9
+ message: string;
10
+ }[];
11
+ export declare function validateForm(data: FormInterface): {
12
+ key: string;
13
+ message: string;
14
+ }[];
15
+ export declare function validateApiDataFetchingConfiguration(data: any): {
16
+ key: string;
17
+ message: string;
18
+ }[];
19
+ export declare function validateDatabaseForm(data: any): {
20
+ key: string;
21
+ message: string;
22
+ }[];
23
+ export declare function validateSubmissionHandle(data: any): {
24
+ key: string;
25
+ message: string;
26
+ }[];
@@ -0,0 +1,134 @@
1
+ import * as Joi from 'joi';
2
+ import { formColumnInputsSchema } from "./FormInputSchema";
3
+ import { APIDataFetchingConfigurationSchema, MongoDbPipeLineConfigSchema } from "./MatOptionsSchema";
4
+ export const FormSlideSchema = Joi.object({
5
+ sectionId: Joi.string().required(),
6
+ label: Joi.string().required(),
7
+ columns: Joi.array().items(formColumnInputsSchema).min(1).required(),
8
+ inEdit: Joi.boolean().optional()
9
+ });
10
+ export const FormSubmissionHandleSchema = Joi.object({
11
+ innerComponentShowSubmitButton: Joi.boolean().optional(),
12
+ canSubmitAPI: Joi.array().items(APIDataFetchingConfigurationSchema, MongoDbPipeLineConfigSchema).optional(),
13
+ submissionAPI: Joi.array().items(APIDataFetchingConfigurationSchema).min(1).required(),
14
+ submissionMessage: Joi.string().optional()
15
+ });
16
+ export const FormSchema = Joi.object({
17
+ slides: Joi.array().items(FormSlideSchema).min(1).required(),
18
+ submissionHandle: FormSubmissionHandleSchema.required(),
19
+ formId: Joi.string().optional(),
20
+ formTitle: Joi.string().required(),
21
+ systemDefault: Joi.boolean().optional(),
22
+ });
23
+ export const DatabaseFormSchema = Joi.object({
24
+ _id: Joi.string().required(),
25
+ systemDefault: Joi.boolean().required(),
26
+ archive: Joi.boolean().required(),
27
+ userId: Joi.string().required(),
28
+ defaultDepartment: Joi.string().required(),
29
+ form: FormSchema.required(),
30
+ createdAt: Joi.date().required(),
31
+ updatedAt: Joi.date().required(),
32
+ __v: Joi.number().required
33
+ });
34
+ export function validateFormSlide(data) {
35
+ const { error } = FormSlideSchema.validate(data);
36
+ if (error) {
37
+ return error.details.map((detail) => ({
38
+ key: detail.path.join('.'),
39
+ message: transformValidationError(detail.message)
40
+ }));
41
+ }
42
+ return [];
43
+ }
44
+ export function validateForm(data) {
45
+ try {
46
+ if (typeof data !== 'object' || data === null) {
47
+ return [
48
+ {
49
+ key: 'validation',
50
+ message: 'Form is required and must be an object'
51
+ }
52
+ ];
53
+ }
54
+ const form = {
55
+ ...data,
56
+ slides: data.slides.map(slide => ({
57
+ ...slide,
58
+ columns: (slide.columns || []).filter(column => column.element !== 'sectionTitle')
59
+ }))
60
+ };
61
+ const { error } = FormSchema.validate(form, {
62
+ abortEarly: false,
63
+ });
64
+ if (error) {
65
+ return error.details.map((detail) => ({
66
+ key: detail.path.join('.'),
67
+ message: transformValidationError(detail.message)
68
+ }));
69
+ }
70
+ return [];
71
+ }
72
+ catch (error) {
73
+ console.error(error);
74
+ return [
75
+ {
76
+ key: 'validation',
77
+ message: 'An error occurred while validating the form'
78
+ }
79
+ ];
80
+ }
81
+ }
82
+ export function validateApiDataFetchingConfiguration(data) {
83
+ const { error } = APIDataFetchingConfigurationSchema.validate(data);
84
+ if (error) {
85
+ return error.details.map(detail => ({
86
+ key: detail.path.join('.'),
87
+ message: transformValidationError(detail.message)
88
+ }));
89
+ }
90
+ return [];
91
+ }
92
+ export function validateDatabaseForm(data) {
93
+ const { error } = DatabaseFormSchema.validate(data);
94
+ if (error) {
95
+ return error.details.map((detail) => ({
96
+ key: detail.path.join('.'),
97
+ message: transformValidationError(detail.message)
98
+ }));
99
+ }
100
+ return [];
101
+ }
102
+ export function validateSubmissionHandle(data) {
103
+ const { error } = FormSubmissionHandleSchema.validate(data);
104
+ if (error) {
105
+ return error.details.map((detail) => ({
106
+ key: detail.path.join('.'),
107
+ message: transformValidationError(detail.message)
108
+ }));
109
+ }
110
+ return [];
111
+ }
112
+ function transformValidationError(errorMessage) {
113
+ // Extract text between quotes and keep track of the full message
114
+ const quotedTextRegex = /"([^"]+)"/;
115
+ const match = errorMessage.match(quotedTextRegex);
116
+ if (!match)
117
+ return errorMessage;
118
+ const originalQuotedText = match[0]; // includes quotes
119
+ const path = match[1]; // just the path
120
+ // Transform the path into readable text
121
+ const transformedPath = (path || '')
122
+ .split(/[\[\].]+/)
123
+ .filter(part => part && isNaN(Number(part)))
124
+ .map(part => {
125
+ const words = part.replace(/([A-Z])/g, ' $1').toLowerCase();
126
+ return words
127
+ .split(' ')
128
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
129
+ .join(' ');
130
+ })
131
+ .join(' > ');
132
+ // Replace only the quoted part while preserving the rest of the message
133
+ return errorMessage.replace(originalQuotedText, `"${transformedPath}"`);
134
+ }