@aemforms/af-core 0.22.22 → 0.22.25

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/README.md +14 -5
  2. package/package.json +2 -14
  3. package/lib/cjs/index.cjs +0 -7277
  4. package/lib/esm/BaseNode-dc59ab07.js +0 -478
  5. package/lib/esm/BaseNode.d.ts +0 -93
  6. package/lib/esm/BaseNode.js +0 -26
  7. package/lib/esm/Checkbox.d.ts +0 -79
  8. package/lib/esm/Checkbox.js +0 -63
  9. package/lib/esm/CheckboxGroup.d.ts +0 -18
  10. package/lib/esm/CheckboxGroup.js +0 -60
  11. package/lib/esm/Container.d.ts +0 -53
  12. package/lib/esm/Container.js +0 -311
  13. package/lib/esm/DateField.d.ts +0 -5
  14. package/lib/esm/DateField.js +0 -57
  15. package/lib/esm/Field.d.ts +0 -206
  16. package/lib/esm/Field.js +0 -692
  17. package/lib/esm/Fieldset.d.ts +0 -16
  18. package/lib/esm/Fieldset.js +0 -78
  19. package/lib/esm/FileObject.d.ts +0 -16
  20. package/lib/esm/FileObject.js +0 -48
  21. package/lib/esm/FileUpload.d.ts +0 -22
  22. package/lib/esm/FileUpload.js +0 -141
  23. package/lib/esm/Form.d.ts +0 -113
  24. package/lib/esm/Form.js +0 -208
  25. package/lib/esm/FormInstance.d.ts +0 -13
  26. package/lib/esm/FormInstance.js +0 -129
  27. package/lib/esm/FormMetaData.d.ts +0 -7
  28. package/lib/esm/FormMetaData.js +0 -35
  29. package/lib/esm/InstanceManager.d.ts +0 -9
  30. package/lib/esm/InstanceManager.js +0 -58
  31. package/lib/esm/Node.d.ts +0 -7
  32. package/lib/esm/Node.js +0 -40
  33. package/lib/esm/Scriptable.d.ts +0 -17
  34. package/lib/esm/Scriptable.js +0 -190
  35. package/lib/esm/controller/EventQueue.d.ts +0 -17
  36. package/lib/esm/controller/EventQueue.js +0 -108
  37. package/lib/esm/controller/Events.d.ts +0 -85
  38. package/lib/esm/controller/Events.js +0 -171
  39. package/lib/esm/controller/Logger.d.ts +0 -11
  40. package/lib/esm/controller/Logger.js +0 -52
  41. package/lib/esm/data/DataGroup.d.ts +0 -20
  42. package/lib/esm/data/DataGroup.js +0 -100
  43. package/lib/esm/data/DataValue.d.ts +0 -16
  44. package/lib/esm/data/DataValue.js +0 -68
  45. package/lib/esm/data/EmptyDataValue.d.ts +0 -14
  46. package/lib/esm/data/EmptyDataValue.js +0 -51
  47. package/lib/esm/index.d.ts +0 -21
  48. package/lib/esm/index.js +0 -55
  49. package/lib/esm/rules/FunctionRuntime.d.ts +0 -51
  50. package/lib/esm/rules/FunctionRuntime.js +0 -345
  51. package/lib/esm/rules/RuleEngine.d.ts +0 -12
  52. package/lib/esm/rules/RuleEngine.js +0 -76
  53. package/lib/esm/types/Json.d.ts +0 -119
  54. package/lib/esm/types/Json.js +0 -29
  55. package/lib/esm/types/Model.d.ts +0 -131
  56. package/lib/esm/types/Model.js +0 -30
  57. package/lib/esm/types/index.d.ts +0 -2
  58. package/lib/esm/types/index.js +0 -22
  59. package/lib/esm/utils/DataRefParser.d.ts +0 -27
  60. package/lib/esm/utils/DataRefParser.js +0 -247
  61. package/lib/esm/utils/Fetch.d.ts +0 -8
  62. package/lib/esm/utils/Fetch.js +0 -83
  63. package/lib/esm/utils/FormCreationUtils.d.ts +0 -9
  64. package/lib/esm/utils/FormCreationUtils.js +0 -112
  65. package/lib/esm/utils/FormUtils.d.ts +0 -12
  66. package/lib/esm/utils/FormUtils.js +0 -212
  67. package/lib/esm/utils/JsonUtils.d.ts +0 -11
  68. package/lib/esm/utils/JsonUtils.js +0 -99
  69. package/lib/esm/utils/LogUtils.d.ts +0 -4
  70. package/lib/esm/utils/LogUtils.js +0 -28
  71. package/lib/esm/utils/SchemaUtils.d.ts +0 -3
  72. package/lib/esm/utils/SchemaUtils.js +0 -93
  73. package/lib/esm/utils/TranslationUtils.d.ts +0 -11
  74. package/lib/esm/utils/TranslationUtils.js +0 -138
  75. package/lib/esm/utils/ValidationUtils.d.ts +0 -19
  76. package/lib/esm/utils/ValidationUtils.js +0 -300
@@ -1,300 +0,0 @@
1
- /*************************************************************************
2
- * ADOBE CONFIDENTIAL
3
- * ___________________
4
- *
5
- * Copyright 2022 Adobe
6
- * All Rights Reserved.
7
- *
8
- * NOTICE: All information contained herein is, and remains
9
- * the property of Adobe and its suppliers, if any. The intellectual
10
- * and technical concepts contained herein are proprietary to Adobe
11
- * and its suppliers and are protected by all applicable intellectual
12
- * property laws, including trade secret and copyright laws.
13
- * Dissemination of this information or reproduction of this material
14
- * is strictly forbidden unless prior written permission is obtained
15
- * from Adobe.
16
-
17
- * Adobe permits you to use and modify this file solely in accordance with
18
- * the terms of the Adobe license agreement accompanying it.
19
- *************************************************************************/
20
-
21
- import { getFileSizeInBytes, extractFileInfo } from './FormUtils.js';
22
- import { FileObject } from '../FileObject.js';
23
- import './JsonUtils.js';
24
- import '../types/Json.js';
25
- import './SchemaUtils.js';
26
-
27
- const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
28
- const days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
29
- const daysInMonth = (leapYear, month) => {
30
- if (leapYear && month == 2) {
31
- return 29;
32
- }
33
- return days[month - 1];
34
- };
35
- const isLeapYear = (year) => {
36
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
37
- };
38
- const coerceType = (param, type) => {
39
- let num;
40
- switch (type) {
41
- case 'string':
42
- return param + '';
43
- case 'number':
44
- num = +param;
45
- if (!isNaN(num)) {
46
- return num;
47
- }
48
- break;
49
- case 'boolean':
50
- if (typeof param === 'string') {
51
- return param === 'true';
52
- }
53
- else if (typeof param === 'number') {
54
- return param !== 0;
55
- }
56
- }
57
- throw `${param} has invalid type. Expected : ${type}, Actual ${typeof param}`;
58
- };
59
- const checkNumber = (inputVal) => {
60
- if (inputVal === '' || inputVal == null) {
61
- return {
62
- value: '', valid: true
63
- };
64
- }
65
- let value = parseFloat(inputVal);
66
- const valid = !isNaN(value);
67
- if (!valid) {
68
- value = inputVal;
69
- }
70
- return {
71
- value, valid
72
- };
73
- };
74
- const checkInteger = (inputVal) => {
75
- if (inputVal == '' || inputVal == null) {
76
- return {
77
- value: '', valid: true
78
- };
79
- }
80
- let value = parseFloat(inputVal);
81
- const valid = !isNaN(value) && Math.round(value) === value;
82
- if (!valid) {
83
- value = inputVal;
84
- }
85
- return {
86
- value, valid
87
- };
88
- };
89
- const toArray = (inputVal) => {
90
- if (inputVal != null && !(inputVal instanceof Array)) {
91
- return [inputVal];
92
- }
93
- return inputVal;
94
- };
95
- const checkBool = (inputVal) => {
96
- const valid = typeof inputVal === 'boolean' || inputVal === 'true' || inputVal === 'false';
97
- const value = typeof inputVal === 'boolean' ? inputVal : (valid ? inputVal === 'true' : inputVal);
98
- return { valid, value };
99
- };
100
- const checkFile = (inputVal) => {
101
- const value = extractFileInfo(inputVal);
102
- const valid = value !== null;
103
- return {
104
- value: valid ? value : inputVal,
105
- valid
106
- };
107
- };
108
- const matchMediaType = (mediaType, accepts) => {
109
- return !mediaType || accepts.some((accept) => {
110
- const trimmedAccept = accept.trim();
111
- const prefixAccept = trimmedAccept.split('/')[0];
112
- const suffixAccept = trimmedAccept.split('.')[1];
113
- return ((trimmedAccept.includes('*') && mediaType.startsWith(prefixAccept)) ||
114
- (trimmedAccept.includes('.') && mediaType.endsWith(suffixAccept)) ||
115
- (trimmedAccept === mediaType));
116
- });
117
- };
118
- const partitionArray = (inputVal, validatorFn) => {
119
- const value = toArray(inputVal);
120
- if (value == null) {
121
- return [[], [value]];
122
- }
123
- return value.reduce((acc, x) => {
124
- if (acc[1].length == 0) {
125
- const r = validatorFn(x);
126
- const index = r.valid ? 0 : 1;
127
- acc[index].push(r.value);
128
- }
129
- return acc;
130
- }, [[], []]);
131
- };
132
- const ValidConstraints = {
133
- date: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'format'],
134
- string: ['minLength', 'maxLength', 'pattern'],
135
- number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
136
- array: ['minItems', 'maxItems', 'uniqueItems'],
137
- file: ['accept', 'maxFileSize']
138
- };
139
- const Constraints = {
140
- type: (constraint, inputVal) => {
141
- let value = inputVal;
142
- if (inputVal == undefined) {
143
- return {
144
- valid: true,
145
- value: inputVal
146
- };
147
- }
148
- let valid = true, res;
149
- switch (constraint) {
150
- case 'string':
151
- valid = true;
152
- value = inputVal.toString();
153
- break;
154
- case 'string[]':
155
- value = toArray(inputVal);
156
- break;
157
- case 'number':
158
- res = checkNumber(inputVal);
159
- value = res.value;
160
- valid = res.valid;
161
- break;
162
- case 'boolean':
163
- res = checkBool(inputVal);
164
- valid = res.valid;
165
- value = res.value;
166
- break;
167
- case 'integer':
168
- res = checkInteger(inputVal);
169
- valid = res.valid;
170
- value = res.value;
171
- break;
172
- case 'integer[]':
173
- res = partitionArray(inputVal, checkInteger);
174
- valid = res[1].length === 0;
175
- value = valid ? res[0] : inputVal;
176
- break;
177
- case 'file':
178
- res = checkFile(inputVal instanceof Array ? inputVal[0] : inputVal);
179
- valid = res.valid;
180
- value = res.value;
181
- break;
182
- case 'file[]':
183
- res = partitionArray(inputVal, checkFile);
184
- valid = res[1].length === 0;
185
- value = valid ? res[0] : inputVal;
186
- break;
187
- case 'number[]':
188
- res = partitionArray(inputVal, checkNumber);
189
- valid = res[1].length === 0;
190
- value = valid ? res[0] : inputVal;
191
- break;
192
- case 'boolean[]':
193
- res = partitionArray(inputVal, checkBool);
194
- valid = res[1].length === 0;
195
- value = valid ? res[0] : inputVal;
196
- break;
197
- }
198
- return {
199
- valid,
200
- value
201
- };
202
- },
203
- format: (constraint, input) => {
204
- let valid = true;
205
- const value = input;
206
- if (input === null) {
207
- return { value, valid };
208
- }
209
- let res;
210
- switch (constraint) {
211
- case 'date':
212
- res = dateRegex.exec((input || '').trim());
213
- if (res != null) {
214
- const [match, year, month, date] = res;
215
- const [nMonth, nDate] = [+month, +date];
216
- const leapYear = isLeapYear(+year);
217
- valid = (nMonth >= 1 && nMonth <= 12) &&
218
- (nDate >= 1 && nDate <= daysInMonth(leapYear, nMonth));
219
- }
220
- else {
221
- valid = false;
222
- }
223
- break;
224
- case 'data-url':
225
- valid = true;
226
- break;
227
- }
228
- return { valid, value };
229
- },
230
- minimum: (constraint, value) => {
231
- return { valid: value >= constraint, value };
232
- },
233
- maximum: (constraint, value) => {
234
- return { valid: value <= constraint, value };
235
- },
236
- exclusiveMinimum: (constraint, value) => {
237
- return { valid: value > constraint, value };
238
- },
239
- exclusiveMaximum: (constraint, value) => {
240
- return { valid: value < constraint, value };
241
- },
242
- minItems: (constraint, value) => {
243
- return { valid: (value instanceof Array) && value.length >= constraint, value };
244
- },
245
- maxItems: (constraint, value) => {
246
- return { valid: (value instanceof Array) && value.length <= constraint, value };
247
- },
248
- uniqueItems: (constraint, value) => {
249
- return { valid: !constraint || ((value instanceof Array) && value.length === new Set(value).size), value };
250
- },
251
- minLength: (constraint, value) => {
252
- return { ...Constraints.minimum(constraint, typeof value === 'string' ? value.length : 0), value };
253
- },
254
- maxLength: (constraint, value) => {
255
- return { ...Constraints.maximum(constraint, typeof value === 'string' ? value.length : 0), value };
256
- },
257
- pattern: (constraint, value) => {
258
- let regex;
259
- if (typeof constraint === 'string') {
260
- regex = new RegExp(constraint);
261
- }
262
- else {
263
- regex = constraint;
264
- }
265
- return { valid: regex.test(value), value };
266
- },
267
- required: (constraint, value) => {
268
- const valid = constraint ? value != null && value !== '' : true;
269
- return { valid, value };
270
- },
271
- enum: (constraint, value) => {
272
- return {
273
- valid: constraint.indexOf(value) > -1,
274
- value
275
- };
276
- },
277
- accept: (constraint, value) => {
278
- if (!constraint || constraint.length === 0 || value === null || value === undefined) {
279
- return {
280
- valid: true,
281
- value
282
- };
283
- }
284
- const tempValue = value instanceof Array ? value : [value];
285
- const invalidFile = tempValue.some((file) => !matchMediaType(file.type, constraint));
286
- return {
287
- valid: !invalidFile,
288
- value
289
- };
290
- },
291
- maxFileSize: (constraint, value) => {
292
- const sizeLimit = typeof constraint === 'string' ? getFileSizeInBytes(constraint) : constraint;
293
- return {
294
- valid: !(value instanceof FileObject) || value.size <= sizeLimit,
295
- value
296
- };
297
- }
298
- };
299
-
300
- export { Constraints, ValidConstraints, coerceType };