@aemforms/af-core 0.22.19 → 0.22.20
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/lib/browser/afb-events.js +151 -0
- package/lib/browser/afb-runtime.js +3620 -0
- package/lib/cjs/index.cjs +8886 -0
- package/lib/{BaseNode.d.ts → esm/BaseNode.d.ts} +10 -69
- package/lib/{BaseNode.js → esm/BaseNode.js} +84 -184
- package/lib/esm/Checkbox.d.ts +79 -0
- package/lib/esm/Checkbox.js +27 -0
- package/lib/{CheckboxGroup.d.ts → esm/CheckboxGroup.d.ts} +2 -14
- package/lib/esm/CheckboxGroup.js +23 -0
- package/lib/{Container.d.ts → esm/Container.d.ts} +12 -59
- package/lib/{Container.js → esm/Container.js} +54 -116
- package/lib/{DateField.d.ts → esm/DateField.d.ts} +1 -1
- package/lib/esm/DateField.js +21 -0
- package/lib/{Field.d.ts → esm/Field.d.ts} +39 -104
- package/lib/{Field.js → esm/Field.js} +142 -208
- package/lib/esm/Fieldset.d.ts +16 -0
- package/lib/esm/Fieldset.js +45 -0
- package/lib/{FileObject.d.ts → esm/FileObject.d.ts} +1 -4
- package/lib/esm/FileObject.js +26 -0
- package/lib/{FileUpload.d.ts → esm/FileUpload.d.ts} +3 -18
- package/lib/esm/FileUpload.js +108 -0
- package/lib/{Form.d.ts → esm/Form.d.ts} +19 -85
- package/lib/esm/Form.js +176 -0
- package/lib/esm/FormInstance.d.ts +13 -0
- package/lib/esm/FormInstance.js +81 -0
- package/lib/esm/FormMetaData.d.ts +7 -0
- package/lib/esm/FormMetaData.js +10 -0
- package/lib/esm/InstanceManager.d.ts +9 -0
- package/lib/esm/InstanceManager.js +31 -0
- package/lib/esm/Node.d.ts +7 -0
- package/lib/esm/Node.js +16 -0
- package/lib/esm/Scriptable.d.ts +17 -0
- package/lib/{Scriptable.js → esm/Scriptable.js} +11 -54
- package/lib/{controller → esm/controller}/EventQueue.d.ts +3 -11
- package/lib/{controller → esm/controller}/EventQueue.js +10 -26
- package/lib/esm/controller/Events.d.ts +85 -0
- package/lib/esm/controller/Events.js +149 -0
- package/lib/{controller → esm/controller}/Logger.d.ts +0 -6
- package/lib/{controller → esm/controller}/Logger.js +5 -11
- package/lib/{data → esm/data}/DataGroup.d.ts +1 -7
- package/lib/{data → esm/data}/DataGroup.js +15 -34
- package/lib/{data → esm/data}/DataValue.d.ts +1 -7
- package/lib/esm/data/DataValue.js +46 -0
- package/lib/{data → esm/data}/EmptyDataValue.d.ts +1 -1
- package/lib/esm/data/EmptyDataValue.js +29 -0
- package/lib/esm/index.d.ts +21 -0
- package/lib/esm/index.js +21 -0
- package/lib/{rules → esm/rules}/FunctionRuntime.d.ts +2 -24
- package/lib/{rules → esm/rules}/FunctionRuntime.js +41 -117
- package/lib/esm/rules/RuleEngine.d.ts +12 -0
- package/lib/esm/rules/RuleEngine.js +47 -0
- package/lib/{types → esm/types}/Json.d.ts +3 -22
- package/lib/esm/types/Json.js +7 -0
- package/lib/esm/types/Model.d.ts +131 -0
- package/lib/esm/types/Model.js +8 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/{utils → esm/utils}/DataRefParser.d.ts +2 -5
- package/lib/{utils → esm/utils}/DataRefParser.js +22 -49
- package/lib/{utils → esm/utils}/Fetch.d.ts +0 -6
- package/lib/esm/utils/Fetch.js +61 -0
- package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
- package/lib/esm/utils/FormCreationUtils.js +74 -0
- package/lib/esm/utils/FormUtils.d.ts +12 -0
- package/lib/esm/utils/FormUtils.js +187 -0
- package/lib/esm/utils/JsonUtils.d.ts +11 -0
- package/lib/esm/utils/JsonUtils.js +76 -0
- package/lib/{utils → esm/utils}/LogUtils.d.ts +1 -4
- package/lib/esm/utils/LogUtils.js +6 -0
- package/lib/esm/utils/SchemaUtils.d.ts +3 -0
- package/lib/esm/utils/SchemaUtils.js +71 -0
- package/lib/esm/utils/TranslationUtils.d.ts +11 -0
- package/lib/esm/utils/TranslationUtils.js +115 -0
- package/lib/esm/utils/ValidationUtils.d.ts +19 -0
- package/lib/{utils → esm/utils}/ValidationUtils.js +29 -187
- package/package.json +17 -10
- package/lib/Checkbox.d.ts +0 -88
- package/lib/Checkbox.js +0 -49
- package/lib/CheckboxGroup.js +0 -43
- package/lib/DateField.js +0 -35
- package/lib/Fieldset.d.ts +0 -24
- package/lib/Fieldset.js +0 -74
- package/lib/FileObject.js +0 -39
- package/lib/FileUpload.js +0 -155
- package/lib/Form.js +0 -252
- package/lib/FormInstance.d.ts +0 -38
- package/lib/FormInstance.js +0 -127
- package/lib/FormMetaData.d.ts +0 -11
- package/lib/FormMetaData.js +0 -28
- package/lib/InstanceManager.d.ts +0 -16
- package/lib/InstanceManager.js +0 -53
- package/lib/Node.d.ts +0 -12
- package/lib/Node.js +0 -27
- package/lib/Scriptable.d.ts +0 -31
- package/lib/controller/Controller.d.ts +0 -255
- package/lib/controller/Controller.js +0 -328
- package/lib/controller/index.d.ts +0 -1
- package/lib/controller/index.js +0 -24
- package/lib/data/DataValue.js +0 -56
- package/lib/data/EmptyDataValue.js +0 -46
- package/lib/index.d.ts +0 -28
- package/lib/index.js +0 -63
- package/lib/rules/RuleEngine.d.ts +0 -23
- package/lib/rules/RuleEngine.js +0 -62
- package/lib/types/Json.js +0 -19
- package/lib/types/Model.d.ts +0 -393
- package/lib/types/Model.js +0 -20
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -25
- package/lib/utils/Fetch.js +0 -87
- package/lib/utils/FormCreationUtils.d.ts +0 -11
- package/lib/utils/FormCreationUtils.js +0 -83
- package/lib/utils/FormUtils.d.ts +0 -47
- package/lib/utils/FormUtils.js +0 -257
- package/lib/utils/JsonUtils.d.ts +0 -63
- package/lib/utils/JsonUtils.js +0 -157
- package/lib/utils/LogUtils.js +0 -17
- package/lib/utils/SchemaUtils.d.ts +0 -16
- package/lib/utils/SchemaUtils.js +0 -92
- package/lib/utils/TranslationUtils.d.ts +0 -41
- package/lib/utils/TranslationUtils.js +0 -185
- package/lib/utils/ValidationUtils.d.ts +0 -170
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Copyright 2022 Adobe, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
|
|
6
|
-
*
|
|
7
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Constraints = exports.ValidConstraints = exports.isDataUrl = void 0;
|
|
11
|
-
const FormUtils_1 = require("./FormUtils");
|
|
12
|
-
const FileObject_1 = require("../FileObject");
|
|
13
|
-
/**
|
|
14
|
-
* Defines generic utilities to validate form runtime model based on the constraints defined
|
|
15
|
-
* as per `adaptive form specification`
|
|
16
|
-
*/
|
|
17
|
-
// issue with import
|
|
18
|
-
//import {FieldJson, isFileObject} from '../types';
|
|
1
|
+
import { extractFileInfo, getFileSizeInBytes } from './FormUtils.js';
|
|
2
|
+
import { FileObject } from '../FileObject.js';
|
|
19
3
|
const dateRegex = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
|
|
20
|
-
const dataUrlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;
|
|
21
4
|
const days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
22
5
|
const daysInMonth = (leapYear, month) => {
|
|
23
6
|
if (leapYear && month == 2) {
|
|
@@ -28,26 +11,27 @@ const daysInMonth = (leapYear, month) => {
|
|
|
28
11
|
const isLeapYear = (year) => {
|
|
29
12
|
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
30
13
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
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}`;
|
|
33
34
|
};
|
|
34
|
-
exports.isDataUrl = isDataUrl;
|
|
35
|
-
/**
|
|
36
|
-
* Checks whether inputVal is valid number value or not
|
|
37
|
-
*
|
|
38
|
-
* ```
|
|
39
|
-
* const x = checkNumber('12')
|
|
40
|
-
* ```
|
|
41
|
-
* would return
|
|
42
|
-
* ```
|
|
43
|
-
* {
|
|
44
|
-
* value : 12,
|
|
45
|
-
* valid : true
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
* @param inputVal input value
|
|
49
|
-
* @returns {@link ValidationResult | Validation result}
|
|
50
|
-
*/
|
|
51
35
|
const checkNumber = (inputVal) => {
|
|
52
36
|
if (inputVal === '' || inputVal == null) {
|
|
53
37
|
return {
|
|
@@ -63,10 +47,6 @@ const checkNumber = (inputVal) => {
|
|
|
63
47
|
value, valid
|
|
64
48
|
};
|
|
65
49
|
};
|
|
66
|
-
/**
|
|
67
|
-
*
|
|
68
|
-
* @param inputVal
|
|
69
|
-
*/
|
|
70
50
|
const checkInteger = (inputVal) => {
|
|
71
51
|
if (inputVal == '' || inputVal == null) {
|
|
72
52
|
return {
|
|
@@ -82,55 +62,25 @@ const checkInteger = (inputVal) => {
|
|
|
82
62
|
value, valid
|
|
83
63
|
};
|
|
84
64
|
};
|
|
85
|
-
/**
|
|
86
|
-
* Wraps a non-null value and not an array value into an array
|
|
87
|
-
* @param inputVal input value
|
|
88
|
-
* @returns wraps the input value into an array
|
|
89
|
-
*/
|
|
90
65
|
const toArray = (inputVal) => {
|
|
91
66
|
if (inputVal != null && !(inputVal instanceof Array)) {
|
|
92
67
|
return [inputVal];
|
|
93
68
|
}
|
|
94
69
|
return inputVal;
|
|
95
70
|
};
|
|
96
|
-
/**
|
|
97
|
-
* Checks whether inputVal is valid boolean value or not
|
|
98
|
-
*
|
|
99
|
-
* ```
|
|
100
|
-
* const x = checkBool('false')
|
|
101
|
-
* ```
|
|
102
|
-
* would return
|
|
103
|
-
* ```
|
|
104
|
-
* {
|
|
105
|
-
* value : false,
|
|
106
|
-
* valid : true
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
* @param inputVal input value
|
|
110
|
-
* @returns {@link ValidationResult | Validation result}
|
|
111
|
-
*/
|
|
112
71
|
const checkBool = (inputVal) => {
|
|
113
72
|
const valid = typeof inputVal === 'boolean' || inputVal === 'true' || inputVal === 'false';
|
|
114
73
|
const value = typeof inputVal === 'boolean' ? inputVal : (valid ? inputVal === 'true' : inputVal);
|
|
115
74
|
return { valid, value };
|
|
116
75
|
};
|
|
117
|
-
/**
|
|
118
|
-
*
|
|
119
|
-
* @param inputVal
|
|
120
|
-
*/
|
|
121
76
|
const checkFile = (inputVal) => {
|
|
122
|
-
const value =
|
|
77
|
+
const value = extractFileInfo(inputVal);
|
|
123
78
|
const valid = value !== null;
|
|
124
79
|
return {
|
|
125
80
|
value: valid ? value : inputVal,
|
|
126
81
|
valid
|
|
127
82
|
};
|
|
128
83
|
};
|
|
129
|
-
/**
|
|
130
|
-
* validates whether the mediaType is one present in the accepts list
|
|
131
|
-
* @param mediaType
|
|
132
|
-
* @param accepts
|
|
133
|
-
*/
|
|
134
84
|
const matchMediaType = (mediaType, accepts) => {
|
|
135
85
|
return !mediaType || accepts.some((accept) => {
|
|
136
86
|
const trimmedAccept = accept.trim();
|
|
@@ -141,13 +91,6 @@ const matchMediaType = (mediaType, accepts) => {
|
|
|
141
91
|
(trimmedAccept === mediaType));
|
|
142
92
|
});
|
|
143
93
|
};
|
|
144
|
-
/**
|
|
145
|
-
* Validates an array of values using a validator function.
|
|
146
|
-
* @param inputVal
|
|
147
|
-
* @param validatorFn
|
|
148
|
-
* @return an array containing two arrays, the first one with all the valid values and the second one with one invalid
|
|
149
|
-
* value (if there is).
|
|
150
|
-
*/
|
|
151
94
|
const partitionArray = (inputVal, validatorFn) => {
|
|
152
95
|
const value = toArray(inputVal);
|
|
153
96
|
if (value == null) {
|
|
@@ -162,23 +105,14 @@ const partitionArray = (inputVal, validatorFn) => {
|
|
|
162
105
|
return acc;
|
|
163
106
|
}, [[], []]);
|
|
164
107
|
};
|
|
165
|
-
|
|
108
|
+
export const ValidConstraints = {
|
|
166
109
|
date: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'format'],
|
|
167
110
|
string: ['minLength', 'maxLength', 'pattern'],
|
|
168
111
|
number: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'],
|
|
169
112
|
array: ['minItems', 'maxItems', 'uniqueItems'],
|
|
170
113
|
file: ['accept', 'maxFileSize']
|
|
171
114
|
};
|
|
172
|
-
|
|
173
|
-
* Implementation of all constraints defined by `adaptive form specification`
|
|
174
|
-
*/
|
|
175
|
-
exports.Constraints = {
|
|
176
|
-
/**
|
|
177
|
-
* Implementation of type constraint
|
|
178
|
-
* @param constraint `type` property of the form object
|
|
179
|
-
* @param inputVal value of the form object
|
|
180
|
-
* @return {@link ValidationResult | validation result}
|
|
181
|
-
*/
|
|
115
|
+
export const Constraints = {
|
|
182
116
|
type: (constraint, inputVal) => {
|
|
183
117
|
let value = inputVal;
|
|
184
118
|
if (inputVal == undefined) {
|
|
@@ -217,7 +151,6 @@ exports.Constraints = {
|
|
|
217
151
|
value = valid ? res[0] : inputVal;
|
|
218
152
|
break;
|
|
219
153
|
case 'file':
|
|
220
|
-
// for file types only, we support setting value via an array
|
|
221
154
|
res = checkFile(inputVal instanceof Array ? inputVal[0] : inputVal);
|
|
222
155
|
valid = res.valid;
|
|
223
156
|
value = res.value;
|
|
@@ -243,12 +176,6 @@ exports.Constraints = {
|
|
|
243
176
|
value
|
|
244
177
|
};
|
|
245
178
|
},
|
|
246
|
-
/**
|
|
247
|
-
* Implementation of format constraint
|
|
248
|
-
* @param constraint `format` property of the form object
|
|
249
|
-
* @param input value of the form object
|
|
250
|
-
* @return {@link ValidationResult | validation result}
|
|
251
|
-
*/
|
|
252
179
|
format: (constraint, input) => {
|
|
253
180
|
let valid = true;
|
|
254
181
|
const value = input;
|
|
@@ -260,7 +187,6 @@ exports.Constraints = {
|
|
|
260
187
|
case 'date':
|
|
261
188
|
res = dateRegex.exec((input || '').trim());
|
|
262
189
|
if (res != null) {
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
264
190
|
const [match, year, month, date] = res;
|
|
265
191
|
const [nMonth, nDate] = [+month, +date];
|
|
266
192
|
const leapYear = isLeapYear(+year);
|
|
@@ -272,101 +198,38 @@ exports.Constraints = {
|
|
|
272
198
|
}
|
|
273
199
|
break;
|
|
274
200
|
case 'data-url':
|
|
275
|
-
// todo: input is of type file, do we need this format ? since value is always of type file object
|
|
276
|
-
//res = dataUrlRegex.exec(input.trim());
|
|
277
|
-
//valid = res != null;
|
|
278
201
|
valid = true;
|
|
279
202
|
break;
|
|
280
203
|
}
|
|
281
204
|
return { valid, value };
|
|
282
205
|
},
|
|
283
|
-
//todo : add support for date
|
|
284
|
-
/**
|
|
285
|
-
* Implementation of minimum constraint
|
|
286
|
-
* @param constraint `minimum` property of the form object
|
|
287
|
-
* @param value value of the form object
|
|
288
|
-
* @return {@link ValidationResult | validation result}
|
|
289
|
-
*/
|
|
290
206
|
minimum: (constraint, value) => {
|
|
291
207
|
return { valid: value >= constraint, value };
|
|
292
208
|
},
|
|
293
|
-
//todo : add support for date
|
|
294
|
-
/**
|
|
295
|
-
* Implementation of maximum constraint
|
|
296
|
-
* @param constraint `maximum` property of the form object
|
|
297
|
-
* @param value value of the form object
|
|
298
|
-
* @return {@link ValidationResult | validation result}
|
|
299
|
-
*/
|
|
300
209
|
maximum: (constraint, value) => {
|
|
301
210
|
return { valid: value <= constraint, value };
|
|
302
211
|
},
|
|
303
|
-
/**
|
|
304
|
-
* Implementation of exclusiveMinimum constraint
|
|
305
|
-
* @param constraint `minimum` property of the form object
|
|
306
|
-
* @param value value of the form object
|
|
307
|
-
* @return {@link ValidationResult | validation result}
|
|
308
|
-
*/
|
|
309
212
|
exclusiveMinimum: (constraint, value) => {
|
|
310
213
|
return { valid: value > constraint, value };
|
|
311
214
|
},
|
|
312
|
-
//todo : add support for date
|
|
313
|
-
/**
|
|
314
|
-
* Implementation of exclusiveMaximum constraint
|
|
315
|
-
* @param constraint `maximum` property of the form object
|
|
316
|
-
* @param value value of the form object
|
|
317
|
-
* @return {@link ValidationResult | validation result}
|
|
318
|
-
*/
|
|
319
215
|
exclusiveMaximum: (constraint, value) => {
|
|
320
216
|
return { valid: value < constraint, value };
|
|
321
217
|
},
|
|
322
|
-
/**
|
|
323
|
-
* Implementation of the minItems constraint
|
|
324
|
-
* @param constraint `minItems` constraint from object
|
|
325
|
-
* @param value value of the form object
|
|
326
|
-
*/
|
|
327
218
|
minItems: (constraint, value) => {
|
|
328
219
|
return { valid: (value instanceof Array) && value.length >= constraint, value };
|
|
329
220
|
},
|
|
330
|
-
/**
|
|
331
|
-
* Implementation of the maxItems constraint
|
|
332
|
-
* @param constraint `maxItems` constraint from object
|
|
333
|
-
* @param value value of the form object
|
|
334
|
-
*/
|
|
335
221
|
maxItems: (constraint, value) => {
|
|
336
222
|
return { valid: (value instanceof Array) && value.length <= constraint, value };
|
|
337
223
|
},
|
|
338
|
-
/**
|
|
339
|
-
* Implementation of the uniqueItems constraint
|
|
340
|
-
* @param constraint `uniqueItems` constraint from object
|
|
341
|
-
* @param value value of the form object
|
|
342
|
-
*/
|
|
343
224
|
uniqueItems: (constraint, value) => {
|
|
344
225
|
return { valid: !constraint || ((value instanceof Array) && value.length === new Set(value).size), value };
|
|
345
226
|
},
|
|
346
|
-
/**
|
|
347
|
-
* Implementation of minLength constraint
|
|
348
|
-
* @param constraint `minLength` property of the form object
|
|
349
|
-
* @param value value of the form object
|
|
350
|
-
* @return {@link ValidationResult | validation result}
|
|
351
|
-
*/
|
|
352
227
|
minLength: (constraint, value) => {
|
|
353
|
-
return
|
|
228
|
+
return { ...Constraints.minimum(constraint, typeof value === 'string' ? value.length : 0), value };
|
|
354
229
|
},
|
|
355
|
-
/**
|
|
356
|
-
* Implementation of maxLength constraint
|
|
357
|
-
* @param constraint `maxLength` property of the form object
|
|
358
|
-
* @param value value of the form object
|
|
359
|
-
* @return {@link ValidationResult | validation result}
|
|
360
|
-
*/
|
|
361
230
|
maxLength: (constraint, value) => {
|
|
362
|
-
return
|
|
231
|
+
return { ...Constraints.maximum(constraint, typeof value === 'string' ? value.length : 0), value };
|
|
363
232
|
},
|
|
364
|
-
/**
|
|
365
|
-
* Implementation of pattern constraint
|
|
366
|
-
* @param constraint `pattern` property of the form object
|
|
367
|
-
* @param value value of the form object
|
|
368
|
-
* @return {@link ValidationResult | validation result}
|
|
369
|
-
*/
|
|
370
233
|
pattern: (constraint, value) => {
|
|
371
234
|
let regex;
|
|
372
235
|
if (typeof constraint === 'string') {
|
|
@@ -377,33 +240,16 @@ exports.Constraints = {
|
|
|
377
240
|
}
|
|
378
241
|
return { valid: regex.test(value), value };
|
|
379
242
|
},
|
|
380
|
-
/**
|
|
381
|
-
* Implementation of required constraint
|
|
382
|
-
* @param constraint `required` property of the form object
|
|
383
|
-
* @param value value of the form object
|
|
384
|
-
* @return {@link ValidationResult | validation result}
|
|
385
|
-
*/
|
|
386
243
|
required: (constraint, value) => {
|
|
387
244
|
const valid = constraint ? value != null && value !== '' : true;
|
|
388
245
|
return { valid, value };
|
|
389
246
|
},
|
|
390
|
-
/**
|
|
391
|
-
* Implementation of enum constraint
|
|
392
|
-
* @param constraint `enum` property of the form object
|
|
393
|
-
* @param value value of the form object
|
|
394
|
-
* @return {@link ValidationResult | validation result}
|
|
395
|
-
*/
|
|
396
247
|
enum: (constraint, value) => {
|
|
397
248
|
return {
|
|
398
249
|
valid: constraint.indexOf(value) > -1,
|
|
399
250
|
value
|
|
400
251
|
};
|
|
401
252
|
},
|
|
402
|
-
/**
|
|
403
|
-
*
|
|
404
|
-
* @param constraint
|
|
405
|
-
* @param value
|
|
406
|
-
*/
|
|
407
253
|
accept: (constraint, value) => {
|
|
408
254
|
if (!constraint || constraint.length === 0 || value === null || value === undefined) {
|
|
409
255
|
return {
|
|
@@ -418,14 +264,10 @@ exports.Constraints = {
|
|
|
418
264
|
value
|
|
419
265
|
};
|
|
420
266
|
},
|
|
421
|
-
/**
|
|
422
|
-
* @param constraint
|
|
423
|
-
* @param value
|
|
424
|
-
*/
|
|
425
267
|
maxFileSize: (constraint, value) => {
|
|
426
|
-
const sizeLimit = typeof constraint === 'string' ?
|
|
268
|
+
const sizeLimit = typeof constraint === 'string' ? getFileSizeInBytes(constraint) : constraint;
|
|
427
269
|
return {
|
|
428
|
-
valid: !(value instanceof
|
|
270
|
+
valid: !(value instanceof FileObject) || value.size <= sizeLimit,
|
|
429
271
|
value
|
|
430
272
|
};
|
|
431
273
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.20",
|
|
4
4
|
"description": "Core Module for Forms Runtime",
|
|
5
5
|
"author": "Adobe Systems",
|
|
6
6
|
"license": "Adobe Proprietary",
|
|
7
|
-
"
|
|
7
|
+
"type": "module",
|
|
8
|
+
"module": "lib/esm/index.js",
|
|
9
|
+
"types": "lib/esm/index.d.ts",
|
|
10
|
+
"main": "lib/cjs/index.cjs",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./lib/esm/index.js"
|
|
13
|
+
},
|
|
8
14
|
"directories": {
|
|
9
15
|
"lib": "lib",
|
|
10
16
|
"source": "src",
|
|
@@ -24,21 +30,21 @@
|
|
|
24
30
|
"access": "public"
|
|
25
31
|
},
|
|
26
32
|
"scripts": {
|
|
27
|
-
"test": "jest --silent",
|
|
33
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --silent",
|
|
28
34
|
"eslint": "npx eslint src/**",
|
|
29
35
|
"eslint:fix": "npx eslint --fix src/**",
|
|
30
|
-
"test:ci": "jest --silent --coverage",
|
|
31
|
-
"build": "npm run eslint && npx tsc",
|
|
36
|
+
"test:ci": "NODE_OPTIONS=--experimental-vm-modules jest --silent --coverage",
|
|
37
|
+
"build": "npm run clean && npm run eslint && npx tsc && rollup -c rollup.config.js",
|
|
32
38
|
"clean": "rm -rf lib target",
|
|
33
39
|
"prepublishOnly": "npm run build && npm run test",
|
|
34
40
|
"docs": "npx typedoc --options .typedoc.cjs"
|
|
35
41
|
},
|
|
36
42
|
"dependencies": {
|
|
37
|
-
"@adobe/json-formula": "
|
|
38
|
-
"@aemforms/af-formatters": "^0.22.
|
|
43
|
+
"@adobe/json-formula": "0.1.50",
|
|
44
|
+
"@aemforms/af-formatters": "^0.22.20"
|
|
39
45
|
},
|
|
40
46
|
"devDependencies": {
|
|
41
|
-
"@types/jest": "
|
|
47
|
+
"@types/jest": "29.2.4",
|
|
42
48
|
"@types/lodash": "^4.14.171",
|
|
43
49
|
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
|
44
50
|
"@typescript-eslint/parser": "^4.28.2",
|
|
@@ -50,11 +56,12 @@
|
|
|
50
56
|
"eslint-plugin-node": "^11.1.0",
|
|
51
57
|
"eslint-plugin-promise": "^5.1.0",
|
|
52
58
|
"form-data": "^4.0.0",
|
|
53
|
-
"jest": "
|
|
59
|
+
"jest": "29.3",
|
|
60
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
54
61
|
"jest-junit": "^12.2.0",
|
|
55
62
|
"nock": "^13.1.3",
|
|
56
63
|
"node-fetch": "^2.6.1",
|
|
57
|
-
"ts-jest": "
|
|
64
|
+
"ts-jest": "29.0",
|
|
58
65
|
"typedoc": "0.22.11",
|
|
59
66
|
"typedoc-plugin-markdown": "3.11.13",
|
|
60
67
|
"typescript": "^4.3.5"
|
package/lib/Checkbox.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import Field from './Field';
|
|
2
|
-
/**
|
|
3
|
-
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
4
|
-
*/
|
|
5
|
-
declare class Checkbox extends Field {
|
|
6
|
-
private offValue;
|
|
7
|
-
/**
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
_getConstraintObject(): {
|
|
11
|
-
type: (constraint: string, inputVal: any) => {
|
|
12
|
-
valid: boolean;
|
|
13
|
-
value: any;
|
|
14
|
-
};
|
|
15
|
-
format: (constraint: string, input: string | null) => {
|
|
16
|
-
value: string | null;
|
|
17
|
-
valid: boolean;
|
|
18
|
-
};
|
|
19
|
-
minimum: (constraint: number, value: number) => {
|
|
20
|
-
valid: boolean;
|
|
21
|
-
value: number;
|
|
22
|
-
};
|
|
23
|
-
maximum: (constraint: number, value: number) => {
|
|
24
|
-
valid: boolean;
|
|
25
|
-
value: number;
|
|
26
|
-
};
|
|
27
|
-
exclusiveMinimum: (constraint: number, value: number) => {
|
|
28
|
-
valid: boolean;
|
|
29
|
-
value: number;
|
|
30
|
-
};
|
|
31
|
-
exclusiveMaximum: (constraint: number, value: number) => {
|
|
32
|
-
valid: boolean;
|
|
33
|
-
value: number;
|
|
34
|
-
};
|
|
35
|
-
minItems: <T>(constraint: number, value: T[]) => {
|
|
36
|
-
valid: boolean;
|
|
37
|
-
value: T[];
|
|
38
|
-
};
|
|
39
|
-
maxItems: <T_1>(constraint: number, value: T_1[]) => {
|
|
40
|
-
valid: boolean;
|
|
41
|
-
value: T_1[];
|
|
42
|
-
};
|
|
43
|
-
uniqueItems: <T_2>(constraint: boolean, value: T_2[]) => {
|
|
44
|
-
valid: boolean;
|
|
45
|
-
value: T_2[];
|
|
46
|
-
};
|
|
47
|
-
minLength: (constraint: number, value: string) => {
|
|
48
|
-
value: string;
|
|
49
|
-
valid: boolean;
|
|
50
|
-
};
|
|
51
|
-
maxLength: (constraint: number, value: string) => {
|
|
52
|
-
value: string;
|
|
53
|
-
valid: boolean;
|
|
54
|
-
};
|
|
55
|
-
pattern: (constraint: string | RegExp, value: string) => {
|
|
56
|
-
valid: boolean;
|
|
57
|
-
value: string;
|
|
58
|
-
};
|
|
59
|
-
required: (constraint: boolean, value: any) => {
|
|
60
|
-
valid: boolean;
|
|
61
|
-
value: any;
|
|
62
|
-
};
|
|
63
|
-
enum: (constraint: any[], value: any) => {
|
|
64
|
-
valid: boolean;
|
|
65
|
-
value: any;
|
|
66
|
-
};
|
|
67
|
-
accept: (constraint: string[], value: any) => {
|
|
68
|
-
valid: boolean;
|
|
69
|
-
value: any;
|
|
70
|
-
};
|
|
71
|
-
maxFileSize: (constraint: string | number, value: any) => {
|
|
72
|
-
valid: boolean;
|
|
73
|
-
value: any;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
protected _getDefaults(): {
|
|
77
|
-
enforceEnum: boolean;
|
|
78
|
-
readOnly: boolean;
|
|
79
|
-
enabled: boolean;
|
|
80
|
-
visible: boolean;
|
|
81
|
-
type: string | undefined;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Returns the `enum` constraints from the json
|
|
85
|
-
*/
|
|
86
|
-
get enum(): any[];
|
|
87
|
-
}
|
|
88
|
-
export default Checkbox;
|
package/lib/Checkbox.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2022 Adobe, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
|
|
6
|
-
*
|
|
7
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
-
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
14
|
-
const ValidationUtils_1 = require("./utils/ValidationUtils");
|
|
15
|
-
/**
|
|
16
|
-
* @param offValue
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
const requiredConstraint = (offValue) => (constraint, value) => {
|
|
20
|
-
const valid = ValidationUtils_1.Constraints.required(constraint, value).valid && (!constraint || value != offValue);
|
|
21
|
-
return { valid, value };
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Implementation of check box runtime model which extends from {@link Field | field} model
|
|
25
|
-
*/
|
|
26
|
-
class Checkbox extends Field_1.default {
|
|
27
|
-
offValue() {
|
|
28
|
-
const opts = this.enum;
|
|
29
|
-
return opts.length > 1 ? opts[1] : null;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
_getConstraintObject() {
|
|
35
|
-
const baseConstraints = Object.assign({}, super._getConstraintObject());
|
|
36
|
-
baseConstraints.required = requiredConstraint(this.offValue());
|
|
37
|
-
return baseConstraints;
|
|
38
|
-
}
|
|
39
|
-
_getDefaults() {
|
|
40
|
-
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true });
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns the `enum` constraints from the json
|
|
44
|
-
*/
|
|
45
|
-
get enum() {
|
|
46
|
-
return this._jsonModel.enum || [];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.default = Checkbox;
|
package/lib/CheckboxGroup.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2022 Adobe, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
|
|
6
|
-
*
|
|
7
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
-
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
14
|
-
/**
|
|
15
|
-
* Implementation of CheckBoxGroup runtime model which extends from {@link Field | field}
|
|
16
|
-
*/
|
|
17
|
-
class CheckboxGroup extends Field_1.default {
|
|
18
|
-
/**
|
|
19
|
-
* @param params
|
|
20
|
-
* @param _options
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
constructor(params, _options) {
|
|
24
|
-
super(params, _options);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* converts the fallback type, if required, to an array. Since checkbox-group has an array type
|
|
28
|
-
* @protected
|
|
29
|
-
*/
|
|
30
|
-
_getFallbackType() {
|
|
31
|
-
const fallbackType = super._getFallbackType();
|
|
32
|
-
if (typeof fallbackType === 'string') {
|
|
33
|
-
return `${fallbackType}[]`;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return 'string[]';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
_getDefaults() {
|
|
40
|
-
return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true, enum: [] });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.default = CheckboxGroup;
|
package/lib/DateField.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
*
|
|
4
|
-
* * Copyright 2022 Adobe, Inc.
|
|
5
|
-
* *
|
|
6
|
-
* * Your access and use of this software is governed by the Adobe Customer Feedback Program Terms and Conditions or other Beta License Agreement signed by your employer and Adobe, Inc.. This software is NOT open source and may not be used without one of the foregoing licenses. Even with a foregoing license, your access and use of this file is limited to the earlier of (a) 180 days, (b) general availability of the product(s) which utilize this software (i.e. AEM Forms), (c) January 1, 2023, (d) Adobe providing notice to you that you may no longer use the software or that your beta trial has otherwise ended.
|
|
7
|
-
* *
|
|
8
|
-
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
16
|
-
const af_formatters_1 = require("@aemforms/af-formatters");
|
|
17
|
-
class DateField extends Field_1.default {
|
|
18
|
-
_applyDefaults() {
|
|
19
|
-
super._applyDefaults();
|
|
20
|
-
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
21
|
-
if (!this._jsonModel.editFormat) {
|
|
22
|
-
this._jsonModel.editFormat = 'short';
|
|
23
|
-
}
|
|
24
|
-
if (!this._jsonModel.displayFormat) {
|
|
25
|
-
this._jsonModel.displayFormat = this._jsonModel.editFormat;
|
|
26
|
-
}
|
|
27
|
-
if (!this._jsonModel.placeholder) {
|
|
28
|
-
this._jsonModel.placeholder = (0, af_formatters_1.getSkeleton)(this._jsonModel.editFormat, locale);
|
|
29
|
-
}
|
|
30
|
-
if (!this._jsonModel.description) {
|
|
31
|
-
this._jsonModel.description = `To enter today's date use ${(0, af_formatters_1.formatDate)(new Date(), locale, this._jsonModel.editFormat)}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = DateField;
|
package/lib/Fieldset.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import Container from './Container';
|
|
2
|
-
import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Defines a field set class which extends from {@link Container | container}
|
|
5
|
-
*/
|
|
6
|
-
export declare class Fieldset extends Container<FieldsetJson> implements FieldsetModel {
|
|
7
|
-
/**
|
|
8
|
-
* @param params
|
|
9
|
-
* @param _options
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
constructor(params: FieldsetJson, _options: {
|
|
13
|
-
form: FormModel;
|
|
14
|
-
parent: ContainerModel;
|
|
15
|
-
});
|
|
16
|
-
private _applyDefaults;
|
|
17
|
-
get type(): "array" | "object" | undefined;
|
|
18
|
-
protected _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
|
|
19
|
-
get items(): (FieldModel | FieldsetModel)[];
|
|
20
|
-
get value(): null;
|
|
21
|
-
get fieldType(): string;
|
|
22
|
-
get enabled(): boolean | undefined;
|
|
23
|
-
set enabled(e: boolean | undefined);
|
|
24
|
-
}
|