@aemforms/af-core 0.15.0

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 (69) hide show
  1. package/LICENSE +5 -0
  2. package/README.md +34 -0
  3. package/lib/BaseNode.d.ts +117 -0
  4. package/lib/BaseNode.js +368 -0
  5. package/lib/Checkbox.d.ts +80 -0
  6. package/lib/Checkbox.js +49 -0
  7. package/lib/CheckboxGroup.d.ts +30 -0
  8. package/lib/CheckboxGroup.js +40 -0
  9. package/lib/Container.d.ts +336 -0
  10. package/lib/Container.js +279 -0
  11. package/lib/Field.d.ts +185 -0
  12. package/lib/Field.js +432 -0
  13. package/lib/Fieldset.d.ts +31 -0
  14. package/lib/Fieldset.js +97 -0
  15. package/lib/FileObject.d.ts +17 -0
  16. package/lib/FileObject.js +30 -0
  17. package/lib/FileUpload.d.ts +42 -0
  18. package/lib/FileUpload.js +299 -0
  19. package/lib/Form.d.ts +413 -0
  20. package/lib/Form.js +247 -0
  21. package/lib/FormInstance.d.ts +26 -0
  22. package/lib/FormInstance.js +116 -0
  23. package/lib/FormMetaData.d.ts +11 -0
  24. package/lib/FormMetaData.js +28 -0
  25. package/lib/Node.d.ts +12 -0
  26. package/lib/Node.js +27 -0
  27. package/lib/Scriptable.d.ts +27 -0
  28. package/lib/Scriptable.js +216 -0
  29. package/lib/controller/Controller.d.ts +207 -0
  30. package/lib/controller/Controller.js +263 -0
  31. package/lib/controller/EventQueue.d.ts +24 -0
  32. package/lib/controller/EventQueue.js +99 -0
  33. package/lib/controller/index.d.ts +1 -0
  34. package/lib/controller/index.js +24 -0
  35. package/lib/data/DataGroup.d.ts +25 -0
  36. package/lib/data/DataGroup.js +74 -0
  37. package/lib/data/DataValue.d.ts +22 -0
  38. package/lib/data/DataValue.js +50 -0
  39. package/lib/data/EmptyDataValue.d.ts +14 -0
  40. package/lib/data/EmptyDataValue.js +46 -0
  41. package/lib/index.d.ts +27 -0
  42. package/lib/index.js +59 -0
  43. package/lib/rules/FunctionRuntime.d.ts +44 -0
  44. package/lib/rules/FunctionRuntime.js +271 -0
  45. package/lib/rules/RuleEngine.d.ts +23 -0
  46. package/lib/rules/RuleEngine.js +67 -0
  47. package/lib/types/Json.d.ts +126 -0
  48. package/lib/types/Json.js +16 -0
  49. package/lib/types/Model.d.ts +352 -0
  50. package/lib/types/Model.js +20 -0
  51. package/lib/types/index.d.ts +2 -0
  52. package/lib/types/index.js +25 -0
  53. package/lib/utils/DataRefParser.d.ts +30 -0
  54. package/lib/utils/DataRefParser.js +249 -0
  55. package/lib/utils/Fetch.d.ts +7 -0
  56. package/lib/utils/Fetch.js +29 -0
  57. package/lib/utils/FormUtils.d.ts +47 -0
  58. package/lib/utils/FormUtils.js +172 -0
  59. package/lib/utils/JsonUtils.d.ts +55 -0
  60. package/lib/utils/JsonUtils.js +128 -0
  61. package/lib/utils/LogUtils.d.ts +7 -0
  62. package/lib/utils/LogUtils.js +17 -0
  63. package/lib/utils/SchemaUtils.d.ts +16 -0
  64. package/lib/utils/SchemaUtils.js +92 -0
  65. package/lib/utils/TranslationUtils.d.ts +34 -0
  66. package/lib/utils/TranslationUtils.js +156 -0
  67. package/lib/utils/ValidationUtils.d.ts +153 -0
  68. package/lib/utils/ValidationUtils.js +339 -0
  69. package/package.json +60 -0
package/lib/index.js ADDED
@@ -0,0 +1,59 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.getFileSizeInBytes = exports.Scriptable = exports.Node = exports.FormMetaData = exports.FileUpload = exports.FileObject = exports.Fieldset = exports.Field = exports.Container = exports.CheckboxGroup = exports.Checkbox = exports.BaseNode = exports.Form = void 0;
28
+ __exportStar(require("./FormInstance"), exports);
29
+ __exportStar(require("./types/index"), exports);
30
+ __exportStar(require("./controller/index"), exports);
31
+ __exportStar(require("./utils/TranslationUtils"), exports);
32
+ __exportStar(require("./utils/JsonUtils"), exports);
33
+ __exportStar(require("./utils/SchemaUtils"), exports);
34
+ const FormUtils_1 = require("./utils/FormUtils");
35
+ Object.defineProperty(exports, "getFileSizeInBytes", { enumerable: true, get: function () { return FormUtils_1.getFileSizeInBytes; } });
36
+ const BaseNode_1 = require("./BaseNode");
37
+ Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return BaseNode_1.BaseNode; } });
38
+ const Checkbox_1 = __importDefault(require("./Checkbox"));
39
+ exports.Checkbox = Checkbox_1.default;
40
+ const CheckboxGroup_1 = __importDefault(require("./CheckboxGroup"));
41
+ exports.CheckboxGroup = CheckboxGroup_1.default;
42
+ const Container_1 = __importDefault(require("./Container"));
43
+ exports.Container = Container_1.default;
44
+ const Field_1 = __importDefault(require("./Field"));
45
+ exports.Field = Field_1.default;
46
+ const Fieldset_1 = require("./Fieldset");
47
+ Object.defineProperty(exports, "Fieldset", { enumerable: true, get: function () { return Fieldset_1.Fieldset; } });
48
+ const FileObject_1 = require("./FileObject");
49
+ Object.defineProperty(exports, "FileObject", { enumerable: true, get: function () { return FileObject_1.FileObject; } });
50
+ const FileUpload_1 = __importDefault(require("./FileUpload"));
51
+ exports.FileUpload = FileUpload_1.default;
52
+ const FormMetaData_1 = __importDefault(require("./FormMetaData"));
53
+ exports.FormMetaData = FormMetaData_1.default;
54
+ const Node_1 = __importDefault(require("./Node"));
55
+ exports.Node = Node_1.default;
56
+ const Scriptable_1 = __importDefault(require("./Scriptable"));
57
+ exports.Scriptable = Scriptable_1.default;
58
+ const Form_1 = __importDefault(require("./Form"));
59
+ exports.Form = Form_1.default;
@@ -0,0 +1,44 @@
1
+ declare type HTTP_VERB = 'GET' | 'POST';
2
+ /**
3
+ * Implementation of generic request API. This API can be used to make external web request
4
+ * @param context expression execution context(consists of current form, current field, current event)
5
+ * @param uri request URI
6
+ * @param httpVerb http verb (for example, GET or POST)
7
+ * @param payload request payload
8
+ * @param success success handler
9
+ * @param error error handler
10
+ * @param payloadContentType content type of the request
11
+ * @private
12
+ */
13
+ export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType?: string) => Promise<void>;
14
+ export declare const submit: (context: any, success: string, error: string, submitAs?: 'json' | 'multipart', input_data?: any) => Promise<void>;
15
+ /**
16
+ * Implementation of function runtime
17
+ * @private
18
+ */
19
+ declare class FunctionRuntimeImpl {
20
+ getFunctions(): {
21
+ validate: {
22
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
23
+ _signature: never[];
24
+ };
25
+ getData: {
26
+ _func: (args: unknown, data: unknown, interpreter: any) => any;
27
+ _signature: never[];
28
+ };
29
+ submitForm: {
30
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
31
+ _signature: never[];
32
+ };
33
+ request: {
34
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
35
+ _signature: never[];
36
+ };
37
+ dispatchEvent: {
38
+ _func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
39
+ _signature: never[];
40
+ };
41
+ };
42
+ }
43
+ declare const FunctionRuntime: FunctionRuntimeImpl;
44
+ export default FunctionRuntime;
@@ -0,0 +1,271 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
+ return new (P || (P = Promise))(function (resolve, reject) {
12
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
16
+ });
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.submit = exports.request = void 0;
20
+ /**
21
+ * Implementation of function runtime in rule engine
22
+ */
23
+ const JsonUtils_1 = require("../utils/JsonUtils");
24
+ const Controller_1 = require("../controller/Controller");
25
+ const Fetch_1 = require("../utils/Fetch");
26
+ const FileObject_1 = require("../FileObject");
27
+ const FormUtils_1 = require("../utils/FormUtils");
28
+ /**
29
+ * Implementation of generic request API. This API can be used to make external web request
30
+ * @param context expression execution context(consists of current form, current field, current event)
31
+ * @param uri request URI
32
+ * @param httpVerb http verb (for example, GET or POST)
33
+ * @param payload request payload
34
+ * @param success success handler
35
+ * @param error error handler
36
+ * @param payloadContentType content type of the request
37
+ * @private
38
+ */
39
+ const request = (context, uri, httpVerb, payload, success, error, payloadContentType = 'application/json') => __awaiter(void 0, void 0, void 0, function* () {
40
+ const endpoint = uri;
41
+ const requestOptions = {
42
+ method: httpVerb
43
+ };
44
+ let result;
45
+ let inputPayload;
46
+ try {
47
+ if (payload && payload instanceof FileObject_1.FileObject && payload.data instanceof File) {
48
+ // todo: have to implement array type
49
+ const formData = new FormData();
50
+ formData.append(payload.name, payload.data);
51
+ inputPayload = formData;
52
+ }
53
+ else if (payload && typeof payload === 'object' && Object.keys(payload).length > 0) {
54
+ if (payloadContentType.length > 0) {
55
+ requestOptions.headers = {
56
+ 'Content-Type': payloadContentType // this should match content type of the payload
57
+ };
58
+ }
59
+ inputPayload = JSON.stringify(payload);
60
+ }
61
+ result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
62
+ }
63
+ catch (e) {
64
+ //todo: define error payload
65
+ context.form.logger.error('Error invoking a rest API');
66
+ context.form.dispatch(new Controller_1.CustomEvent(error, {}, true));
67
+ return;
68
+ }
69
+ context.form.dispatch(new Controller_1.CustomEvent(success, result, true));
70
+ });
71
+ exports.request = request;
72
+ /**
73
+ * Create multi part form data using form data and form attachments
74
+ * @param data form data
75
+ * @param attachments form events
76
+ * @private
77
+ */
78
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
+ const multipartFormData = (data, attachments) => {
80
+ const formData = new FormData();
81
+ formData.append(':data', data);
82
+ formData.append(':contentType', 'application/json');
83
+ const transformAttachment = (objValue, formData) => {
84
+ const newValue = {
85
+ ':name': objValue.name,
86
+ ':contentType': objValue.mediaType,
87
+ ':data': objValue.data,
88
+ ':bindRef': objValue.dataRef
89
+ };
90
+ if ((objValue === null || objValue === void 0 ? void 0 : objValue.data) instanceof File) {
91
+ let attIdentifier = `${objValue === null || objValue === void 0 ? void 0 : objValue.dataRef}/${objValue === null || objValue === void 0 ? void 0 : objValue.name}`;
92
+ if (!attIdentifier.startsWith('/')) {
93
+ attIdentifier = `/${attIdentifier}`;
94
+ }
95
+ formData.append(attIdentifier, objValue.data);
96
+ newValue[':data'] = `#${attIdentifier}`;
97
+ }
98
+ return newValue;
99
+ };
100
+ // @ts-ignore
101
+ const submitAttachments = Object.keys(attachments).reduce((acc, curr) => {
102
+ const objValue = attachments[curr];
103
+ if (objValue && objValue instanceof Array) {
104
+ return [...acc, ...objValue.map((x) => transformAttachment(x, formData))];
105
+ }
106
+ else {
107
+ return [...acc, transformAttachment(objValue, formData)];
108
+ }
109
+ }, []);
110
+ if ((submitAttachments === null || submitAttachments === void 0 ? void 0 : submitAttachments.length) > 0) {
111
+ formData.append(':attachments', (0, JsonUtils_1.jsonString)(submitAttachments));
112
+ }
113
+ return formData;
114
+ };
115
+ const submit = (context, success, error, submitAs = 'json', input_data = null) => __awaiter(void 0, void 0, void 0, function* () {
116
+ const endpoint = context.form.action;
117
+ let data = input_data;
118
+ if (typeof data != 'object' || data == null) {
119
+ data = context.form.exportData();
120
+ }
121
+ // todo: have to implement sending of attachments here
122
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
123
+ const attachments = (0, FormUtils_1.getAttachments)(context.$form);
124
+ let submitContentType = submitAs;
125
+ //let formData: any;
126
+ //if (Object.keys(attachments).length > 0) {
127
+ // multipartFormData(jsonString(data), attachments);
128
+ // submitContentType = 'multipart/form-data';
129
+ //} else {
130
+ const formData = { 'data': data };
131
+ submitContentType = 'application/json';
132
+ //}
133
+ // note: don't send multipart/form-data let browser decide on the content type
134
+ yield (0, exports.request)(context, endpoint, 'POST', formData, success, error, submitContentType);
135
+ });
136
+ exports.submit = submit;
137
+ /**
138
+ * Helper function to create an action
139
+ * @param name name of the event
140
+ * @param payload event payload
141
+ * @param dispatch true to trigger the event on all the fields in DFS order starting from the top level form element, false otherwise
142
+ * @private
143
+ */
144
+ const createAction = (name, payload = {}) => {
145
+ switch (name) {
146
+ case 'change':
147
+ return new Controller_1.Change(payload);
148
+ case 'submit':
149
+ return new Controller_1.Submit(payload);
150
+ case 'click':
151
+ return new Controller_1.Click(payload);
152
+ case 'addItem':
153
+ return new Controller_1.AddItem(payload);
154
+ case 'removeItem':
155
+ return new Controller_1.RemoveItem(payload);
156
+ default:
157
+ console.error('invalid action');
158
+ }
159
+ };
160
+ /**
161
+ * Implementation of function runtime
162
+ * @private
163
+ */
164
+ class FunctionRuntimeImpl {
165
+ getFunctions() {
166
+ // todo: remove these once json-formula exposes a way to call them from custom functions
167
+ function isArray(obj) {
168
+ if (obj !== null) {
169
+ return Object.prototype.toString.call(obj) === '[object Array]';
170
+ }
171
+ return false;
172
+ }
173
+ function valueOf(a) {
174
+ if (a === null || a === undefined) {
175
+ return a;
176
+ }
177
+ if (isArray(a)) {
178
+ return a.map(i => valueOf(i));
179
+ }
180
+ return a.valueOf();
181
+ }
182
+ function toString(a) {
183
+ if (a === null || a === undefined) {
184
+ return '';
185
+ }
186
+ return a.toString();
187
+ }
188
+ return {
189
+ validate: {
190
+ _func: (args, data, interpreter) => {
191
+ const element = args[0];
192
+ if (typeof element === 'string' || typeof element === 'undefined') {
193
+ return interpreter.globals.form.validate();
194
+ }
195
+ else {
196
+ return interpreter.globals.form.getElement(element.$id).validate();
197
+ }
198
+ },
199
+ _signature: []
200
+ },
201
+ getData: {
202
+ _func: (args, data, interpreter) => {
203
+ return interpreter.globals.form.exportData();
204
+ },
205
+ _signature: []
206
+ },
207
+ submitForm: {
208
+ _func: (args, data, interpreter) => {
209
+ // success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
210
+ const success = toString(args[0]);
211
+ const error = toString(args[1]);
212
+ const submit_as = args.length > 2 ? toString(args[2]) : 'json';
213
+ const submit_data = args.length > 3 ? valueOf(args[3]) : null;
214
+ interpreter.globals.form.dispatch(new Controller_1.Submit({
215
+ success,
216
+ error,
217
+ submit_as,
218
+ data: submit_data
219
+ }));
220
+ return {};
221
+ },
222
+ _signature: []
223
+ },
224
+ // todo: only supports application/json for now
225
+ request: {
226
+ _func: (args, data, interpreter) => {
227
+ const uri = toString(args[0]);
228
+ const httpVerb = toString(args[1]);
229
+ const payload = valueOf(args[2]);
230
+ const success = valueOf(args[3]);
231
+ const error = valueOf(args[4]);
232
+ (0, exports.request)(interpreter.globals, uri, httpVerb, payload, success, error, 'application/json');
233
+ return {};
234
+ },
235
+ _signature: []
236
+ },
237
+ dispatchEvent: {
238
+ _func: (args, data, interpreter) => {
239
+ const element = args[0];
240
+ let eventName = valueOf(args[1]);
241
+ let payload = args.length > 2 ? valueOf(args[2]) : undefined;
242
+ let dispatch = false;
243
+ if (typeof element === 'string') {
244
+ payload = eventName;
245
+ eventName = element;
246
+ dispatch = true;
247
+ }
248
+ let event;
249
+ if (eventName.startsWith('custom:')) {
250
+ event = new Controller_1.CustomEvent(eventName.substring('custom:'.length), payload, dispatch);
251
+ }
252
+ else {
253
+ event = createAction(eventName, payload);
254
+ }
255
+ if (event != null) {
256
+ if (typeof element === 'string') {
257
+ interpreter.globals.form.dispatch(event);
258
+ }
259
+ else {
260
+ interpreter.globals.form.getElement(element.$id).dispatch(event);
261
+ }
262
+ }
263
+ return {};
264
+ },
265
+ _signature: []
266
+ }
267
+ };
268
+ }
269
+ }
270
+ const FunctionRuntime = new FunctionRuntimeImpl();
271
+ exports.default = FunctionRuntime;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Implementation of rule engine
3
+ * @module
4
+ * @private
5
+ */
6
+ import { BaseModel } from '../types';
7
+ import { Formula } from '@adobe/json-formula';
8
+ /**
9
+ * Implementation of rule engine
10
+ * @private
11
+ */
12
+ declare class RuleEngine {
13
+ private _context;
14
+ private _globalNames;
15
+ compileRule(rule: string): Formula;
16
+ execute(node: any, data: any, globals: any, useValueOf?: boolean): any;
17
+ /**
18
+ * Listen to subscriber for
19
+ * @param subscriber
20
+ */
21
+ trackDependency(subscriber: BaseModel): void;
22
+ }
23
+ export default RuleEngine;
@@ -0,0 +1,67 @@
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 Controller_1 = require("../controller/Controller");
14
+ const json_formula_1 = require("@adobe/json-formula");
15
+ const FunctionRuntime_1 = __importDefault(require("./FunctionRuntime"));
16
+ /**
17
+ * Implementation of AddDependant event
18
+ * @private
19
+ */
20
+ class AddDependent extends Controller_1.ActionImpl {
21
+ constructor(payload) {
22
+ super(payload, 'addDependent');
23
+ }
24
+ payloadToJson() {
25
+ return this.payload.getState();
26
+ }
27
+ }
28
+ /**
29
+ * Implementation of rule engine
30
+ * @private
31
+ */
32
+ class RuleEngine {
33
+ constructor() {
34
+ this._globalNames = [
35
+ '$form',
36
+ '$field',
37
+ '$event'
38
+ ];
39
+ }
40
+ compileRule(rule) {
41
+ const customFunctions = FunctionRuntime_1.default.getFunctions();
42
+ return new json_formula_1.Formula(rule, customFunctions, undefined, this._globalNames);
43
+ }
44
+ execute(node, data, globals, useValueOf = false) {
45
+ const oldContext = this._context;
46
+ this._context = globals;
47
+ const res = node.search(data, globals);
48
+ let finalRes = res;
49
+ if (useValueOf) {
50
+ if (typeof res === 'object' && res !== null) {
51
+ finalRes = Object.getPrototypeOf(res).valueOf.call(res);
52
+ }
53
+ }
54
+ this._context = oldContext;
55
+ return finalRes;
56
+ }
57
+ /**
58
+ * Listen to subscriber for
59
+ * @param subscriber
60
+ */
61
+ trackDependency(subscriber) {
62
+ if (this._context && this._context.field !== undefined && this._context.field !== subscriber) {
63
+ subscriber.dispatch(new AddDependent(this._context.field));
64
+ }
65
+ }
66
+ }
67
+ exports.default = RuleEngine;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Defines generic types based on `adaptive form specification`
3
+ */
4
+ /** Type for `items property` based on `adaptive form specification` */
5
+ export declare type Items<T> = {
6
+ [key: string]: T;
7
+ };
8
+ /** Type alias for primitive types */
9
+ export declare type Primitives = string | number | boolean | null | undefined;
10
+ /** Type for `label` based on `adaptive form specification` */
11
+ export declare type Label = {
12
+ value: string;
13
+ richText?: boolean;
14
+ visible?: boolean;
15
+ };
16
+ /** Type for `constraint properties` which can be translated based on `adaptive form specification` */
17
+ declare type TranslationConstraintsJson = {
18
+ enumNames?: string[];
19
+ enum?: any[];
20
+ };
21
+ /** Type for `constraint properties` based on `adaptive form specification` */
22
+ export declare type ConstraintsJson = TranslationConstraintsJson & {
23
+ accept?: string[];
24
+ enforceEnum?: boolean;
25
+ exclusiveMinimum?: number;
26
+ exclusiveMaximum?: number;
27
+ format?: string;
28
+ maxFileSize?: number | string;
29
+ maxLength?: number;
30
+ maximum?: number;
31
+ maxItems?: number;
32
+ minLength?: number;
33
+ minimum?: number;
34
+ minItems?: number;
35
+ pattern?: string;
36
+ required?: boolean;
37
+ step?: number;
38
+ type?: string;
39
+ validationExpression?: string;
40
+ };
41
+ /** Type for `constraint messages` based on `adaptive form specification` */
42
+ export declare type ConstraintsMessages = {
43
+ accept?: string;
44
+ enum?: string;
45
+ exclusiveMinimum?: string;
46
+ exclusiveMaximum?: string;
47
+ format?: string;
48
+ maxFileSize?: string;
49
+ maxLength?: string;
50
+ maximum?: string;
51
+ maxItems?: string;
52
+ minLength?: string;
53
+ minimum?: string;
54
+ minItems?: string;
55
+ pattern?: string;
56
+ required?: string;
57
+ step?: string;
58
+ type?: string;
59
+ validationExpression?: string;
60
+ };
61
+ /** Type for `constraint messages` based on `adaptive form specification` */
62
+ export declare type RulesJson = {
63
+ rules?: Items<string>;
64
+ events?: Items<string[] | string | undefined>;
65
+ };
66
+ /** Type for `generic form properties` which can be translated based on `adaptive form specification` */
67
+ declare type TranslationBaseJson = {
68
+ description?: string;
69
+ };
70
+ /** Type for `generic form properties` based on `adaptive form specification` */
71
+ export declare type BaseJson = TranslationBaseJson & RulesJson & ConstraintsJson & {
72
+ dataRef?: string | null;
73
+ ':type'?: string;
74
+ label?: Label;
75
+ enabled?: boolean;
76
+ visible?: boolean;
77
+ name?: string;
78
+ constraintMessages?: ConstraintsMessages;
79
+ fieldType?: string;
80
+ errorMessage?: string;
81
+ properties?: {
82
+ [key: string]: any;
83
+ };
84
+ };
85
+ /** Type for `form field properties`which can be translated based on `adaptive form specification` */
86
+ declare type TranslationFieldJson = {
87
+ placeholder?: string;
88
+ };
89
+ /** Type for `form field properties` based on `adaptive form specification` */
90
+ export declare type FieldJson = BaseJson & TranslationFieldJson & {
91
+ readOnly?: boolean;
92
+ valid?: boolean;
93
+ default?: any;
94
+ value?: any;
95
+ emptyValue?: 'null' | 'undefined' | '';
96
+ };
97
+ /** Type for `form container properties` based on `adaptive form specification` */
98
+ export declare type ContainerJson = BaseJson & {
99
+ items: Array<FieldJson | ContainerJson>;
100
+ initialItems?: number;
101
+ };
102
+ /** Type for `form metadata` based on `adaptive form specification` */
103
+ export declare type MetaDataJson = {
104
+ version?: string;
105
+ grammar?: string;
106
+ locale?: string;
107
+ };
108
+ /** Type for `form fieldset` based on `adaptive form specification` */
109
+ export declare type FieldsetJson = ContainerJson & {
110
+ 'type'?: 'array' | 'object';
111
+ };
112
+ /** Type for `form model` based on `adaptive form specification` */
113
+ export declare type FormJson = ContainerJson & {
114
+ metadata?: MetaDataJson;
115
+ data?: any;
116
+ title?: string;
117
+ action?: string;
118
+ adaptiveForm?: string;
119
+ };
120
+ /** Type for all properties which can be translated based on `adaptive form specification` */
121
+ export declare type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
122
+ /** Constant for all properties which can be translated based on `adaptive form specification` */
123
+ export declare const translationProps: string[];
124
+ /** Constant for all properties which are constraints based on `adaptive form specification` */
125
+ export declare const constraintProps: string[];
126
+ export {};
@@ -0,0 +1,16 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.constraintProps = exports.translationProps = void 0;
11
+ /** Constant for all properties which can be translated based on `adaptive form specification` */
12
+ exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames'];
13
+ /** Constant for all properties which are constraints based on `adaptive form specification` */
14
+ exports.constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
15
+ 'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
16
+ 'minLength', 'minimum', 'minItems', 'pattern', 'required', 'step', 'validationExpression', 'enumNames'];