@aemforms/af-core 0.22.25 → 0.22.26

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 (76) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/esm/BaseNode.d.ts +93 -0
  5. package/lib/esm/BaseNode.js +454 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/esm/CheckboxGroup.d.ts +18 -0
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/esm/Container.js +290 -0
  12. package/lib/esm/DateField.d.ts +5 -0
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/esm/Field.d.ts +206 -0
  15. package/lib/esm/Field.js +656 -0
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/esm/FileObject.d.ts +16 -0
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/esm/FileUpload.d.ts +22 -0
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/esm/Scriptable.js +163 -0
  34. package/lib/esm/controller/EventQueue.d.ts +17 -0
  35. package/lib/esm/controller/EventQueue.js +86 -0
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/esm/controller/Logger.d.ts +11 -0
  39. package/lib/esm/controller/Logger.js +30 -0
  40. package/lib/esm/data/DataGroup.d.ts +20 -0
  41. package/lib/esm/data/DataGroup.js +77 -0
  42. package/lib/esm/data/DataValue.d.ts +16 -0
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/esm/data/EmptyDataValue.d.ts +14 -0
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/esm/rules/FunctionRuntime.d.ts +51 -0
  49. package/lib/esm/rules/FunctionRuntime.js +320 -0
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/esm/utils/DataRefParser.d.ts +27 -0
  59. package/lib/esm/utils/DataRefParser.js +222 -0
  60. package/lib/esm/utils/Fetch.d.ts +8 -0
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/esm/utils/LogUtils.d.ts +4 -0
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/esm/utils/ValidationUtils.js +274 -0
  76. package/package.json +1 -1
@@ -0,0 +1,274 @@
1
+ import { extractFileInfo, getFileSizeInBytes } from './FormUtils.js';
2
+ import { FileObject } from '../FileObject.js';
3
+ const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
4
+ const days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
5
+ const daysInMonth = (leapYear, month) => {
6
+ if (leapYear && month == 2) {
7
+ return 29;
8
+ }
9
+ return days[month - 1];
10
+ };
11
+ const isLeapYear = (year) => {
12
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
13
+ };
14
+ export const coerceType = (param, type) => {
15
+ let num;
16
+ switch (type) {
17
+ case 'string':
18
+ return param + '';
19
+ case 'number':
20
+ num = +param;
21
+ if (!isNaN(num)) {
22
+ return num;
23
+ }
24
+ break;
25
+ case 'boolean':
26
+ if (typeof param === 'string') {
27
+ return param === 'true';
28
+ }
29
+ else if (typeof param === 'number') {
30
+ return param !== 0;
31
+ }
32
+ }
33
+ throw `${param} has invalid type. Expected : ${type}, Actual ${typeof param}`;
34
+ };
35
+ const checkNumber = (inputVal) => {
36
+ if (inputVal === '' || inputVal == null) {
37
+ return {
38
+ value: '', valid: true
39
+ };
40
+ }
41
+ let value = parseFloat(inputVal);
42
+ const valid = !isNaN(value);
43
+ if (!valid) {
44
+ value = inputVal;
45
+ }
46
+ return {
47
+ value, valid
48
+ };
49
+ };
50
+ const checkInteger = (inputVal) => {
51
+ if (inputVal == '' || inputVal == null) {
52
+ return {
53
+ value: '', valid: true
54
+ };
55
+ }
56
+ let value = parseFloat(inputVal);
57
+ const valid = !isNaN(value) && Math.round(value) === value;
58
+ if (!valid) {
59
+ value = inputVal;
60
+ }
61
+ return {
62
+ value, valid
63
+ };
64
+ };
65
+ const toArray = (inputVal) => {
66
+ if (inputVal != null && !(inputVal instanceof Array)) {
67
+ return [inputVal];
68
+ }
69
+ return inputVal;
70
+ };
71
+ const checkBool = (inputVal) => {
72
+ const valid = typeof inputVal === 'boolean' || inputVal === 'true' || inputVal === 'false';
73
+ const value = typeof inputVal === 'boolean' ? inputVal : (valid ? inputVal === 'true' : inputVal);
74
+ return { valid, value };
75
+ };
76
+ const checkFile = (inputVal) => {
77
+ const value = extractFileInfo(inputVal);
78
+ const valid = value !== null;
79
+ return {
80
+ value: valid ? value : inputVal,
81
+ valid
82
+ };
83
+ };
84
+ const matchMediaType = (mediaType, accepts) => {
85
+ return !mediaType || accepts.some((accept) => {
86
+ const trimmedAccept = accept.trim();
87
+ const prefixAccept = trimmedAccept.split('/')[0];
88
+ const suffixAccept = trimmedAccept.split('.')[1];
89
+ return ((trimmedAccept.includes('*') && mediaType.startsWith(prefixAccept)) ||
90
+ (trimmedAccept.includes('.') && mediaType.endsWith(suffixAccept)) ||
91
+ (trimmedAccept === mediaType));
92
+ });
93
+ };
94
+ const partitionArray = (inputVal, validatorFn) => {
95
+ const value = toArray(inputVal);
96
+ if (value == null) {
97
+ return [[], [value]];
98
+ }
99
+ return value.reduce((acc, x) => {
100
+ if (acc[1].length == 0) {
101
+ const r = validatorFn(x);
102
+ const index = r.valid ? 0 : 1;
103
+ acc[index].push(r.value);
104
+ }
105
+ return acc;
106
+ }, [[], []]);
107
+ };
108
+ export const ValidConstraints = {
109
+ date: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'format'],
110
+ string: ['minLength', 'maxLength', 'pattern'],
111
+ number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
112
+ array: ['minItems', 'maxItems', 'uniqueItems'],
113
+ file: ['accept', 'maxFileSize']
114
+ };
115
+ export const Constraints = {
116
+ type: (constraint, inputVal) => {
117
+ let value = inputVal;
118
+ if (inputVal == undefined) {
119
+ return {
120
+ valid: true,
121
+ value: inputVal
122
+ };
123
+ }
124
+ let valid = true, res;
125
+ switch (constraint) {
126
+ case 'string':
127
+ valid = true;
128
+ value = inputVal.toString();
129
+ break;
130
+ case 'string[]':
131
+ value = toArray(inputVal);
132
+ break;
133
+ case 'number':
134
+ res = checkNumber(inputVal);
135
+ value = res.value;
136
+ valid = res.valid;
137
+ break;
138
+ case 'boolean':
139
+ res = checkBool(inputVal);
140
+ valid = res.valid;
141
+ value = res.value;
142
+ break;
143
+ case 'integer':
144
+ res = checkInteger(inputVal);
145
+ valid = res.valid;
146
+ value = res.value;
147
+ break;
148
+ case 'integer[]':
149
+ res = partitionArray(inputVal, checkInteger);
150
+ valid = res[1].length === 0;
151
+ value = valid ? res[0] : inputVal;
152
+ break;
153
+ case 'file':
154
+ res = checkFile(inputVal instanceof Array ? inputVal[0] : inputVal);
155
+ valid = res.valid;
156
+ value = res.value;
157
+ break;
158
+ case 'file[]':
159
+ res = partitionArray(inputVal, checkFile);
160
+ valid = res[1].length === 0;
161
+ value = valid ? res[0] : inputVal;
162
+ break;
163
+ case 'number[]':
164
+ res = partitionArray(inputVal, checkNumber);
165
+ valid = res[1].length === 0;
166
+ value = valid ? res[0] : inputVal;
167
+ break;
168
+ case 'boolean[]':
169
+ res = partitionArray(inputVal, checkBool);
170
+ valid = res[1].length === 0;
171
+ value = valid ? res[0] : inputVal;
172
+ break;
173
+ }
174
+ return {
175
+ valid,
176
+ value
177
+ };
178
+ },
179
+ format: (constraint, input) => {
180
+ let valid = true;
181
+ const value = input;
182
+ if (input === null) {
183
+ return { value, valid };
184
+ }
185
+ let res;
186
+ switch (constraint) {
187
+ case 'date':
188
+ res = dateRegex.exec((input || '').trim());
189
+ if (res != null) {
190
+ const [match, year, month, date] = res;
191
+ const [nMonth, nDate] = [+month, +date];
192
+ const leapYear = isLeapYear(+year);
193
+ valid = (nMonth >= 1 && nMonth <= 12) &&
194
+ (nDate >= 1 && nDate <= daysInMonth(leapYear, nMonth));
195
+ }
196
+ else {
197
+ valid = false;
198
+ }
199
+ break;
200
+ case 'data-url':
201
+ valid = true;
202
+ break;
203
+ }
204
+ return { valid, value };
205
+ },
206
+ minimum: (constraint, value) => {
207
+ return { valid: value >= constraint, value };
208
+ },
209
+ maximum: (constraint, value) => {
210
+ return { valid: value <= constraint, value };
211
+ },
212
+ exclusiveMinimum: (constraint, value) => {
213
+ return { valid: value > constraint, value };
214
+ },
215
+ exclusiveMaximum: (constraint, value) => {
216
+ return { valid: value < constraint, value };
217
+ },
218
+ minItems: (constraint, value) => {
219
+ return { valid: (value instanceof Array) && value.length >= constraint, value };
220
+ },
221
+ maxItems: (constraint, value) => {
222
+ return { valid: (value instanceof Array) && value.length <= constraint, value };
223
+ },
224
+ uniqueItems: (constraint, value) => {
225
+ return { valid: !constraint || ((value instanceof Array) && value.length === new Set(value).size), value };
226
+ },
227
+ minLength: (constraint, value) => {
228
+ return { ...Constraints.minimum(constraint, typeof value === 'string' ? value.length : 0), value };
229
+ },
230
+ maxLength: (constraint, value) => {
231
+ return { ...Constraints.maximum(constraint, typeof value === 'string' ? value.length : 0), value };
232
+ },
233
+ pattern: (constraint, value) => {
234
+ let regex;
235
+ if (typeof constraint === 'string') {
236
+ regex = new RegExp(constraint);
237
+ }
238
+ else {
239
+ regex = constraint;
240
+ }
241
+ return { valid: regex.test(value), value };
242
+ },
243
+ required: (constraint, value) => {
244
+ const valid = constraint ? value != null && value !== '' : true;
245
+ return { valid, value };
246
+ },
247
+ enum: (constraint, value) => {
248
+ return {
249
+ valid: constraint.indexOf(value) > -1,
250
+ value
251
+ };
252
+ },
253
+ accept: (constraint, value) => {
254
+ if (!constraint || constraint.length === 0 || value === null || value === undefined) {
255
+ return {
256
+ valid: true,
257
+ value
258
+ };
259
+ }
260
+ const tempValue = value instanceof Array ? value : [value];
261
+ const invalidFile = tempValue.some((file) => !matchMediaType(file.type, constraint));
262
+ return {
263
+ valid: !invalidFile,
264
+ value
265
+ };
266
+ },
267
+ maxFileSize: (constraint, value) => {
268
+ const sizeLimit = typeof constraint === 'string' ? getFileSizeInBytes(constraint) : constraint;
269
+ return {
270
+ valid: !(value instanceof FileObject) || value.size <= sizeLimit,
271
+ value
272
+ };
273
+ }
274
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.25",
3
+ "version": "0.22.26",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",