@aemforms/af-core 0.22.12 → 0.22.15

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/BaseNode.d.ts CHANGED
@@ -1,7 +1,16 @@
1
1
  import { Action, BaseJson, BaseModel, callbackFn, ContainerModel, FormModel, Primitives, ValidationError } from './types';
2
2
  import DataGroup from './data/DataGroup';
3
3
  import DataValue from './data/DataValue';
4
+ /**
5
+ * Defines the properties that are editable. These properties can be modified during rule execution.
6
+ */
7
+ export declare const editableProperties: string[];
8
+ /**
9
+ * Defines props that are dynamic and can be changed at runtime.
10
+ */
11
+ export declare const dynamicProps: string[];
4
12
  export declare const target: unique symbol;
13
+ export declare function dependencyTracked(): (target: BaseNode<any>, propertyKey: string, descriptor: PropertyDescriptor) => void;
5
14
  /**
6
15
  * Defines a generic base class which all objects of form runtime model should extend from.
7
16
  * @typeparam T type of the form object which extends from {@link BaseJson | base type}
package/lib/BaseNode.js CHANGED
@@ -6,14 +6,54 @@
6
6
  *
7
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
8
  */
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
9
15
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
17
  };
12
18
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.BaseNode = exports.target = void 0;
19
+ exports.BaseNode = exports.dependencyTracked = exports.target = exports.dynamicProps = exports.editableProperties = void 0;
14
20
  const controller_1 = require("./controller");
15
21
  const DataRefParser_1 = require("./utils/DataRefParser");
16
22
  const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
23
+ /**
24
+ * Defines the properties that are editable. These properties can be modified during rule execution.
25
+ */
26
+ exports.editableProperties = [
27
+ 'value',
28
+ 'label',
29
+ 'description',
30
+ 'visible',
31
+ 'enabled',
32
+ 'readOnly',
33
+ 'enum',
34
+ 'enumNames',
35
+ 'required',
36
+ 'properties',
37
+ // 'enforceEnum', // not exposed for now
38
+ 'exclusiveMinimum',
39
+ 'exclusiveMaximum',
40
+ 'maxLength',
41
+ 'maximum',
42
+ 'maxItems',
43
+ 'minLength',
44
+ 'minimum',
45
+ 'minItems',
46
+ 'step'
47
+ // 'placeholder' // not exposed for now.
48
+ ];
49
+ /**
50
+ * Defines props that are dynamic and can be changed at runtime.
51
+ */
52
+ exports.dynamicProps = [
53
+ ...exports.editableProperties,
54
+ 'valid',
55
+ 'index'
56
+ ];
17
57
  /**
18
58
  * Implementation of action with target
19
59
  * @private
@@ -52,6 +92,19 @@ class ActionImplWithTarget {
52
92
  }
53
93
  }
54
94
  exports.target = Symbol('target');
95
+ function dependencyTracked() {
96
+ return function (target, propertyKey, descriptor) {
97
+ const get = descriptor.get;
98
+ if (get != undefined) {
99
+ descriptor.get = function () {
100
+ // @ts-ignore
101
+ this.ruleEngine.trackDependency(this);
102
+ return get.call(this);
103
+ };
104
+ }
105
+ };
106
+ }
107
+ exports.dependencyTracked = dependencyTracked;
55
108
  /**
56
109
  * Defines a generic base class which all objects of form runtime model should extend from.
57
110
  * @typeparam T type of the form object which extends from {@link BaseJson | base type}
@@ -235,7 +288,7 @@ class BaseNode {
235
288
  if (this._dependents.find(({ node }) => node === dependent) === undefined) {
236
289
  const subscription = this.subscribe((change) => {
237
290
  const changes = change.payload.changes;
238
- const propsToLook = ['value', 'items'];
291
+ const propsToLook = [...exports.dynamicProps, 'items'];
239
292
  // @ts-ignore
240
293
  const isPropChanged = changes.findIndex(x => {
241
294
  return propsToLook.indexOf(x.propertyName) > -1;
@@ -402,4 +455,19 @@ class BaseNode {
402
455
  }
403
456
  }
404
457
  }
458
+ __decorate([
459
+ dependencyTracked()
460
+ ], BaseNode.prototype, "index", null);
461
+ __decorate([
462
+ dependencyTracked()
463
+ ], BaseNode.prototype, "description", null);
464
+ __decorate([
465
+ dependencyTracked()
466
+ ], BaseNode.prototype, "visible", null);
467
+ __decorate([
468
+ dependencyTracked()
469
+ ], BaseNode.prototype, "label", null);
470
+ __decorate([
471
+ dependencyTracked()
472
+ ], BaseNode.prototype, "properties", null);
405
473
  exports.BaseNode = BaseNode;
@@ -22,7 +22,9 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
22
22
  */
23
23
  ruleNodeReference(): any;
24
24
  get items(): (FieldModel | FieldsetModel)[];
25
+ get maxItems(): number;
25
26
  set maxItems(m: number);
27
+ get minItems(): number;
26
28
  /**
27
29
  * returns whether the items in the Panel can repeat or not
28
30
  */
package/lib/Container.js CHANGED
@@ -6,6 +6,12 @@
6
6
  *
7
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
8
  */
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
9
15
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
17
  };
@@ -14,6 +20,7 @@ const JsonUtils_1 = require("./utils/JsonUtils");
14
20
  const Scriptable_1 = __importDefault(require("./Scriptable"));
15
21
  const controller_1 = require("./controller");
16
22
  const DataGroup_1 = __importDefault(require("./data/DataGroup"));
23
+ const BaseNode_1 = require("./BaseNode");
17
24
  /**
18
25
  * Defines a generic container class which any form container should extend from.
19
26
  * @typeparam T type of the node which extends {@link ContainerJson} and {@link RulesJson}
@@ -34,6 +41,9 @@ class Container extends Scriptable_1.default {
34
41
  get items() {
35
42
  return this._children;
36
43
  }
44
+ get maxItems() {
45
+ return this._jsonModel.maxItems;
46
+ }
37
47
  set maxItems(m) {
38
48
  this._jsonModel.maxItems = m;
39
49
  const minItems = this._jsonModel.minItems || 1;
@@ -48,6 +58,9 @@ class Container extends Scriptable_1.default {
48
58
  this.notifyDependents((0, controller_1.propertyChange)('items', elems, null));
49
59
  }
50
60
  }
61
+ get minItems() {
62
+ return this._jsonModel.minItems;
63
+ }
51
64
  /**
52
65
  * returns whether the items in the Panel can repeat or not
53
66
  */
@@ -192,6 +205,9 @@ class Container extends Scriptable_1.default {
192
205
  this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState, null));
193
206
  retVal.dispatch(new controller_1.Initialize());
194
207
  retVal.dispatch(new controller_1.ExecuteRule());
208
+ for (let i = index + 1; i < this._children.length; i++) {
209
+ this._children[i].dispatch(new controller_1.ExecuteRule());
210
+ }
195
211
  }
196
212
  }
197
213
  }
@@ -286,4 +302,10 @@ class Container extends Scriptable_1.default {
286
302
  });
287
303
  }
288
304
  }
305
+ __decorate([
306
+ (0, BaseNode_1.dependencyTracked)()
307
+ ], Container.prototype, "maxItems", null);
308
+ __decorate([
309
+ (0, BaseNode_1.dependencyTracked)()
310
+ ], Container.prototype, "minItems", null);
289
311
  exports.default = Container;
package/lib/Field.d.ts CHANGED
@@ -15,10 +15,12 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
15
15
  form: FormModel;
16
16
  parent: ContainerModel;
17
17
  });
18
+ private _ruleNodeReference;
18
19
  /**
19
20
  * @private
20
21
  */
21
22
  _initialize(): any;
23
+ ruleNodeReference(): any;
22
24
  protected _getDefaults(): {
23
25
  readOnly: boolean;
24
26
  enabled: boolean;
@@ -103,7 +105,10 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
103
105
  };
104
106
  maxItems: <T_1>(constraint: number, value: T_1[]) => {
105
107
  valid: boolean;
106
- value: T_1[];
108
+ value: T_1[]; /**
109
+ * Returns the error message for a given constraint
110
+ * @param constraint
111
+ */
107
112
  };
108
113
  uniqueItems: <T_2>(constraint: boolean, value: T_2[]) => {
109
114
  valid: boolean;
@@ -208,9 +213,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
208
213
  minimum?: number | undefined;
209
214
  minItems?: number | undefined;
210
215
  pattern?: string | undefined;
211
- required?: boolean | undefined; /**
212
- * @private
213
- */
216
+ required?: boolean | undefined;
214
217
  step?: number | undefined;
215
218
  type?: string | undefined;
216
219
  validationExpression?: string | undefined;
package/lib/Field.js CHANGED
@@ -6,6 +6,12 @@
6
6
  *
7
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
8
  */
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
9
15
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
17
  };
@@ -30,6 +36,7 @@ class Field extends Scriptable_1.default {
30
36
  */
31
37
  constructor(params, _options) {
32
38
  super(params, _options);
39
+ this._ruleNodeReference = [];
33
40
  this._applyDefaults();
34
41
  this.queueEvent(new controller_1.Initialize());
35
42
  this.queueEvent(new controller_1.ExecuteRule());
@@ -41,6 +48,16 @@ class Field extends Scriptable_1.default {
41
48
  super._initialize();
42
49
  this.setupRuleNode();
43
50
  }
51
+ ruleNodeReference() {
52
+ var _a;
53
+ if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
54
+ this._ruleNodeReference = [];
55
+ }
56
+ else {
57
+ this._ruleNodeReference = this;
58
+ }
59
+ return this._ruleNodeReference;
60
+ }
44
61
  _getDefaults() {
45
62
  return {
46
63
  readOnly: false,
@@ -195,8 +212,6 @@ class Field extends Scriptable_1.default {
195
212
  }
196
213
  }
197
214
  get value() {
198
- //@ts-ignore
199
- this.ruleEngine.trackDependency(this);
200
215
  if (this._jsonModel.value === undefined) {
201
216
  return null;
202
217
  }
@@ -205,11 +220,27 @@ class Field extends Scriptable_1.default {
205
220
  }
206
221
  }
207
222
  set value(v) {
223
+ var _a;
208
224
  const Constraints = this._getConstraintObject();
209
225
  const typeRes = Constraints.type(this._jsonModel.type || 'string', v);
210
226
  const changes = this._setProperty('value', typeRes.value, false);
211
227
  let uniqueRes = { valid: true };
212
228
  if (changes.length > 0) {
229
+ if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
230
+ if (typeRes.value != null) {
231
+ typeRes.value.forEach((val, index) => {
232
+ this._ruleNodeReference[index] = val;
233
+ });
234
+ while (typeRes.value.length !== this._ruleNodeReference.length) {
235
+ this._ruleNodeReference.pop();
236
+ }
237
+ }
238
+ else {
239
+ while (this._ruleNodeReference.length !== 0) {
240
+ this._ruleNodeReference.pop();
241
+ }
242
+ }
243
+ }
213
244
  const dataNode = this.getDataNode();
214
245
  if (typeof dataNode !== 'undefined') {
215
246
  dataNode.setValue(this.isEmpty() ? this.emptyValue : this._jsonModel.value, this._jsonModel.value);
@@ -474,4 +505,25 @@ class Field extends Scriptable_1.default {
474
505
  return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
475
506
  }
476
507
  }
508
+ __decorate([
509
+ (0, BaseNode_1.dependencyTracked)()
510
+ ], Field.prototype, "readOnly", null);
511
+ __decorate([
512
+ (0, BaseNode_1.dependencyTracked)()
513
+ ], Field.prototype, "enabled", null);
514
+ __decorate([
515
+ (0, BaseNode_1.dependencyTracked)()
516
+ ], Field.prototype, "valid", null);
517
+ __decorate([
518
+ (0, BaseNode_1.dependencyTracked)()
519
+ ], Field.prototype, "enum", null);
520
+ __decorate([
521
+ (0, BaseNode_1.dependencyTracked)()
522
+ ], Field.prototype, "enumNames", null);
523
+ __decorate([
524
+ (0, BaseNode_1.dependencyTracked)()
525
+ ], Field.prototype, "required", null);
526
+ __decorate([
527
+ (0, BaseNode_1.dependencyTracked)()
528
+ ], Field.prototype, "value", null);
477
529
  exports.default = Field;
package/lib/Form.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Action, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, F
3
3
  import FormMetaData from './FormMetaData';
4
4
  import EventQueue from './controller/EventQueue';
5
5
  import RuleEngine from './rules/RuleEngine';
6
- declare type LogFunction = 'info' | 'warn' | 'error';
6
+ declare type LogFunction = 'info' | 'warn' | 'error' | 'debug';
7
7
  /**
8
8
  * Logging levels.
9
9
  */
@@ -12,6 +12,7 @@ export declare type LogLevel = 'off' | LogFunction;
12
12
  * @private
13
13
  */
14
14
  export declare class Logger {
15
+ debug(msg: string): void;
15
16
  info(msg: string): void;
16
17
  warn(msg: string): void;
17
18
  error(msg: string): void;
@@ -70,9 +71,6 @@ declare class Form extends Container<FormJson> implements FormModel {
70
71
  enum?: any[] | undefined;
71
72
  } & {
72
73
  accept?: string[] | undefined;
73
- /**
74
- * @private
75
- */
76
74
  enforceEnum?: boolean | undefined;
77
75
  exclusiveMinimum?: number | undefined;
78
76
  exclusiveMaximum?: number | undefined;
@@ -121,9 +119,6 @@ declare class Form extends Container<FormJson> implements FormModel {
121
119
  enumNames?: string[] | undefined;
122
120
  enum?: any[] | undefined;
123
121
  accept?: string[] | undefined;
124
- /**
125
- * @private
126
- */
127
122
  enforceEnum?: boolean | undefined;
128
123
  exclusiveMinimum?: number | undefined;
129
124
  exclusiveMaximum?: number | undefined;
@@ -171,9 +166,6 @@ declare class Form extends Container<FormJson> implements FormModel {
171
166
  enumNames?: string[] | undefined;
172
167
  enum?: any[] | undefined;
173
168
  accept?: string[] | undefined;
174
- /**
175
- * @private
176
- */
177
169
  enforceEnum?: boolean | undefined;
178
170
  exclusiveMinimum?: number | undefined;
179
171
  exclusiveMaximum?: number | undefined;
@@ -210,9 +202,6 @@ declare class Form extends Container<FormJson> implements FormModel {
210
202
  enum?: any[] | undefined;
211
203
  } & {
212
204
  accept?: string[] | undefined;
213
- /**
214
- * @private
215
- */
216
205
  enforceEnum?: boolean | undefined;
217
206
  exclusiveMinimum?: number | undefined;
218
207
  exclusiveMaximum?: number | undefined;
@@ -265,9 +254,6 @@ declare class Form extends Container<FormJson> implements FormModel {
265
254
  enum?: any[] | undefined;
266
255
  } & {
267
256
  accept?: string[] | undefined;
268
- /**
269
- * @private
270
- */
271
257
  enforceEnum?: boolean | undefined;
272
258
  exclusiveMinimum?: number | undefined;
273
259
  exclusiveMaximum?: number | undefined;
@@ -310,9 +296,6 @@ declare class Form extends Container<FormJson> implements FormModel {
310
296
  enum?: any[] | undefined;
311
297
  } & {
312
298
  accept?: string[] | undefined;
313
- /**
314
- * @private
315
- */
316
299
  enforceEnum?: boolean | undefined;
317
300
  exclusiveMinimum?: number | undefined;
318
301
  exclusiveMaximum?: number | undefined;
@@ -365,9 +348,6 @@ declare class Form extends Container<FormJson> implements FormModel {
365
348
  enum?: any[] | undefined;
366
349
  } & {
367
350
  accept?: string[] | undefined;
368
- /**
369
- * @private
370
- */
371
351
  enforceEnum?: boolean | undefined;
372
352
  exclusiveMinimum?: number | undefined;
373
353
  exclusiveMaximum?: number | undefined;
package/lib/Form.js CHANGED
@@ -21,9 +21,10 @@ const FunctionRuntime_1 = require("./rules/FunctionRuntime");
21
21
  const controller_1 = require("./controller");
22
22
  const levels = {
23
23
  off: 0,
24
- info: 1,
25
- warn: 2,
26
- error: 3
24
+ debug: 1,
25
+ info: 2,
26
+ warn: 3,
27
+ error: 4
27
28
  };
28
29
  /**
29
30
  * @private
@@ -32,6 +33,9 @@ class Logger {
32
33
  constructor(logLevel = 'off') {
33
34
  this.logLevel = levels[logLevel];
34
35
  }
36
+ debug(msg) {
37
+ this.log(msg, 'debug');
38
+ }
35
39
  info(msg) {
36
40
  this.log(msg, 'info');
37
41
  }
@@ -1,5 +1,9 @@
1
1
  import { Action, RulesJson, ScriptableField } from './types';
2
2
  import { BaseNode } from './BaseNode';
3
+ /**
4
+ * Defines scriptable aspects (ie rules, events) of form runtime model. Any form runtime object which requires
5
+ * execution of rules/events should extend from this class.
6
+ */
3
7
  declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> implements ScriptableField {
4
8
  private _events;
5
9
  private _rules;
package/lib/Scriptable.js CHANGED
@@ -12,27 +12,6 @@ const BaseNode_1 = require("./BaseNode");
12
12
  * Defines scriptable aspects (ie rules, events) of form runtime model. Any form runtime object which requires
13
13
  * execution of rules/events should extend from this class.
14
14
  */
15
- const dynamicProps = ['label',
16
- 'enum',
17
- 'enumNames',
18
- 'enforceEnum',
19
- 'exclusiveMinimum',
20
- 'exclusiveMaximum',
21
- 'maxLength',
22
- 'maximum',
23
- 'maxItems',
24
- 'minLength',
25
- 'minimum',
26
- 'minItems',
27
- 'required',
28
- 'step',
29
- 'description',
30
- 'properties',
31
- 'readOnly',
32
- 'value',
33
- 'visible',
34
- 'enabled',
35
- 'placeholder'];
36
15
  class Scriptable extends BaseNode_1.BaseNode {
37
16
  constructor() {
38
17
  super(...arguments);
@@ -85,7 +64,7 @@ class Scriptable extends BaseNode_1.BaseNode {
85
64
  // @ts-ignore
86
65
  // the first check is to disable accessing this.value & this.items property
87
66
  // otherwise that will trigger dependency tracking
88
- if (key in dynamicProps || (key in this && typeof this[key] !== 'function')) {
67
+ if (key in BaseNode_1.editableProperties || (key in this && typeof this[key] !== 'function')) {
89
68
  try {
90
69
  // @ts-ignore
91
70
  this[key] = value;
@@ -100,19 +79,19 @@ class Scriptable extends BaseNode_1.BaseNode {
100
79
  const entries = Object.entries(this.rules);
101
80
  if (entries.length > 0) {
102
81
  const scope = this.getExpressionScope();
103
- const values = entries.map(([prop, rule]) => {
82
+ entries.forEach(([prop, rule]) => {
104
83
  const node = this.getCompiledRule(prop, rule);
105
- let newVal;
106
84
  if (node) {
107
- newVal = this.ruleEngine.execute(node, scope, context, true);
108
- if (dynamicProps.indexOf(prop) > -1) {
85
+ const newVal = this.ruleEngine.execute(node, scope, context, true);
86
+ if (BaseNode_1.editableProperties.indexOf(prop) > -1) {
109
87
  //@ts-ignore
110
88
  this[prop] = newVal;
111
89
  }
90
+ else {
91
+ this.form.logger.warn(`${prop} is not a valid editable property.`);
92
+ }
112
93
  }
113
- return [];
114
- }).filter(x => x.length == 2);
115
- this.applyUpdates(Object.fromEntries(values));
94
+ });
116
95
  }
117
96
  }
118
97
  getExpressionScope() {
@@ -65,8 +65,7 @@ class EventQueue {
65
65
  events.forEach(e => {
66
66
  const evntNode = new EventNode(node, e);
67
67
  const counter = this._runningEventCount[evntNode.valueOf()] || 0;
68
- const alreadyExists = this.isQueued(node, e);
69
- if (!alreadyExists || counter < EventQueue.MAX_EVENT_CYCLE_COUNT) {
68
+ if (counter < EventQueue.MAX_EVENT_CYCLE_COUNT) {
70
69
  this.logger.info(`Queued event : ${e.type} node: ${node.id} - ${node.name}`);
71
70
  //console.log(`Event Details ${e.toString()}`)
72
71
  if (priority) {
@@ -12,11 +12,21 @@ declare type HTTP_VERB = 'GET' | 'POST';
12
12
  */
13
13
  export declare const request: (context: any, uri: string, httpVerb: HTTP_VERB, payload: any, success: string, error: string, payloadContentType: string) => Promise<void>;
14
14
  export declare const submit: (context: any, success: string, error: string, submitAs?: 'application/json' | 'multipart/form-data', input_data?: any) => Promise<void>;
15
+ declare type CustomFunction = Function;
16
+ declare type FunctionDefinition = {
17
+ _func: CustomFunction;
18
+ _signature: Array<any>;
19
+ };
15
20
  /**
16
21
  * Implementation of function runtime
17
22
  * @private
18
23
  */
19
24
  declare class FunctionRuntimeImpl {
25
+ private customFunctions;
26
+ registerFunctions(functions: {
27
+ [key: string]: FunctionDefinition | CustomFunction;
28
+ }): void;
29
+ unregisterFunctions(...names: string[]): void;
20
30
  getFunctions(): {
21
31
  validate: {
22
32
  _func: (args: Array<unknown>, data: unknown, interpreter: any) => any;
@@ -162,6 +162,35 @@ const createAction = (name, payload = {}) => {
162
162
  * @private
163
163
  */
164
164
  class FunctionRuntimeImpl {
165
+ constructor() {
166
+ this.customFunctions = {};
167
+ }
168
+ registerFunctions(functions) {
169
+ Object.entries(functions).forEach(([name, funcDef]) => {
170
+ let finalFunction = funcDef;
171
+ if (typeof funcDef === 'function') {
172
+ finalFunction = {
173
+ _func: (args) => {
174
+ // eslint-disable-next-line @typescript-eslint/ban-types
175
+ return funcDef(...args);
176
+ },
177
+ _signature: []
178
+ };
179
+ }
180
+ if (!finalFunction.hasOwnProperty('_func')) {
181
+ console.warn(`Unable to register function with name ${name}.`);
182
+ return;
183
+ }
184
+ this.customFunctions[name] = finalFunction;
185
+ });
186
+ }
187
+ unregisterFunctions(...names) {
188
+ names.forEach(name => {
189
+ if (name in this.customFunctions) {
190
+ delete this.customFunctions[name];
191
+ }
192
+ });
193
+ }
165
194
  getFunctions() {
166
195
  // todo: remove these once json-formula exposes a way to call them from custom functions
167
196
  function isArray(obj) {
@@ -185,7 +214,7 @@ class FunctionRuntimeImpl {
185
214
  }
186
215
  return a.toString();
187
216
  }
188
- return {
217
+ const defaultFunctions = {
189
218
  validate: {
190
219
  _func: (args, data, interpreter) => {
191
220
  const element = args[0];
@@ -295,6 +324,7 @@ class FunctionRuntimeImpl {
295
324
  _signature: []
296
325
  }
297
326
  };
327
+ return Object.assign(Object.assign({}, defaultFunctions), this.customFunctions);
298
328
  }
299
329
  }
300
330
  const FunctionRuntime = new FunctionRuntimeImpl();
@@ -29,9 +29,20 @@ class RuleEngine {
29
29
  return new json_formula_1.Formula(rule, customFunctions, undefined, this._globalNames);
30
30
  }
31
31
  execute(node, data, globals, useValueOf = false) {
32
+ var _a, _b, _c, _d, _e, _f;
32
33
  const oldContext = this._context;
33
34
  this._context = globals;
34
- const res = node.search(data, globals);
35
+ let res = undefined;
36
+ try {
37
+ node.debug = []; // clean previous debug info
38
+ res = node.search(data, globals);
39
+ }
40
+ catch (err) {
41
+ (_c = (_b = (_a = this._context) === null || _a === void 0 ? void 0 : _a.form) === null || _b === void 0 ? void 0 : _b.logger) === null || _c === void 0 ? void 0 : _c.error(err);
42
+ }
43
+ for (const debugInfo of node.debug) {
44
+ (_f = (_e = (_d = this._context) === null || _d === void 0 ? void 0 : _d.form) === null || _e === void 0 ? void 0 : _e.logger) === null || _f === void 0 ? void 0 : _f.debug(debugInfo);
45
+ }
35
46
  let finalRes = res;
36
47
  if (useValueOf) {
37
48
  if (typeof res === 'object' && res !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.12",
3
+ "version": "0.22.15",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "^0.1.44",
38
- "@aemforms/af-formatters": "^0.22.12"
38
+ "@aemforms/af-formatters": "^0.22.15"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/jest": "^27.5.1",