@aemforms/af-core 0.22.25 → 0.22.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib/browser/afb-events.js +151 -0
  2. package/lib/browser/afb-runtime.js +3620 -0
  3. package/lib/cjs/index.cjs +8886 -0
  4. package/lib/esm/BaseNode.d.ts +93 -0
  5. package/lib/esm/BaseNode.js +454 -0
  6. package/lib/esm/Checkbox.d.ts +79 -0
  7. package/lib/esm/Checkbox.js +27 -0
  8. package/lib/esm/CheckboxGroup.d.ts +18 -0
  9. package/lib/esm/CheckboxGroup.js +23 -0
  10. package/lib/esm/Container.d.ts +53 -0
  11. package/lib/esm/Container.js +290 -0
  12. package/lib/esm/DateField.d.ts +5 -0
  13. package/lib/esm/DateField.js +21 -0
  14. package/lib/esm/Field.d.ts +206 -0
  15. package/lib/esm/Field.js +656 -0
  16. package/lib/esm/Fieldset.d.ts +16 -0
  17. package/lib/esm/Fieldset.js +45 -0
  18. package/lib/esm/FileObject.d.ts +16 -0
  19. package/lib/esm/FileObject.js +26 -0
  20. package/lib/esm/FileUpload.d.ts +22 -0
  21. package/lib/esm/FileUpload.js +108 -0
  22. package/lib/esm/Form.d.ts +113 -0
  23. package/lib/esm/Form.js +176 -0
  24. package/lib/esm/FormInstance.d.ts +13 -0
  25. package/lib/esm/FormInstance.js +81 -0
  26. package/lib/esm/FormMetaData.d.ts +7 -0
  27. package/lib/esm/FormMetaData.js +10 -0
  28. package/lib/esm/InstanceManager.d.ts +9 -0
  29. package/lib/esm/InstanceManager.js +31 -0
  30. package/lib/esm/Node.d.ts +7 -0
  31. package/lib/esm/Node.js +16 -0
  32. package/lib/esm/Scriptable.d.ts +17 -0
  33. package/lib/esm/Scriptable.js +163 -0
  34. package/lib/esm/controller/EventQueue.d.ts +17 -0
  35. package/lib/esm/controller/EventQueue.js +86 -0
  36. package/lib/esm/controller/Events.d.ts +85 -0
  37. package/lib/esm/controller/Events.js +149 -0
  38. package/lib/esm/controller/Logger.d.ts +11 -0
  39. package/lib/esm/controller/Logger.js +30 -0
  40. package/lib/esm/data/DataGroup.d.ts +20 -0
  41. package/lib/esm/data/DataGroup.js +77 -0
  42. package/lib/esm/data/DataValue.d.ts +16 -0
  43. package/lib/esm/data/DataValue.js +46 -0
  44. package/lib/esm/data/EmptyDataValue.d.ts +14 -0
  45. package/lib/esm/data/EmptyDataValue.js +29 -0
  46. package/lib/esm/index.d.ts +21 -0
  47. package/lib/esm/index.js +21 -0
  48. package/lib/esm/rules/FunctionRuntime.d.ts +51 -0
  49. package/lib/esm/rules/FunctionRuntime.js +320 -0
  50. package/lib/esm/rules/RuleEngine.d.ts +12 -0
  51. package/lib/esm/rules/RuleEngine.js +47 -0
  52. package/lib/esm/types/Json.d.ts +119 -0
  53. package/lib/esm/types/Json.js +7 -0
  54. package/lib/esm/types/Model.d.ts +131 -0
  55. package/lib/esm/types/Model.js +8 -0
  56. package/lib/esm/types/index.d.ts +2 -0
  57. package/lib/esm/types/index.js +2 -0
  58. package/lib/esm/utils/DataRefParser.d.ts +27 -0
  59. package/lib/esm/utils/DataRefParser.js +222 -0
  60. package/lib/esm/utils/Fetch.d.ts +8 -0
  61. package/lib/esm/utils/Fetch.js +61 -0
  62. package/lib/esm/utils/FormCreationUtils.d.ts +9 -0
  63. package/lib/esm/utils/FormCreationUtils.js +74 -0
  64. package/lib/esm/utils/FormUtils.d.ts +12 -0
  65. package/lib/esm/utils/FormUtils.js +187 -0
  66. package/lib/esm/utils/JsonUtils.d.ts +11 -0
  67. package/lib/esm/utils/JsonUtils.js +76 -0
  68. package/lib/esm/utils/LogUtils.d.ts +4 -0
  69. package/lib/esm/utils/LogUtils.js +6 -0
  70. package/lib/esm/utils/SchemaUtils.d.ts +3 -0
  71. package/lib/esm/utils/SchemaUtils.js +71 -0
  72. package/lib/esm/utils/TranslationUtils.d.ts +11 -0
  73. package/lib/esm/utils/TranslationUtils.js +115 -0
  74. package/lib/esm/utils/ValidationUtils.d.ts +19 -0
  75. package/lib/esm/utils/ValidationUtils.js +274 -0
  76. package/package.json +1 -1
@@ -0,0 +1,16 @@
1
+ import { getProperty } from './utils/JsonUtils.js';
2
+ class Node {
3
+ _jsonModel;
4
+ constructor(inputModel) {
5
+ this._jsonModel = {
6
+ ...inputModel
7
+ };
8
+ }
9
+ getP(key, def) {
10
+ return getProperty(this._jsonModel, key, def);
11
+ }
12
+ get isContainer() {
13
+ return false;
14
+ }
15
+ }
16
+ export default Node;
@@ -0,0 +1,17 @@
1
+ import { Action, RulesJson, ScriptableField } from './types/index.js';
2
+ import { BaseNode } from './BaseNode.js';
3
+ declare abstract class Scriptable<T extends RulesJson> extends BaseNode<T> implements ScriptableField {
4
+ private _events;
5
+ private _rules;
6
+ getRules(): import("./types/Json.js").Items<string>;
7
+ private getCompiledRule;
8
+ private getCompiledEvent;
9
+ private applyUpdates;
10
+ protected executeAllRules(context: any): void;
11
+ private getExpressionScope;
12
+ private executeEvent;
13
+ executeRule(event: Action, context: any): void;
14
+ executeExpression(expr: string): any;
15
+ executeAction(action: Action): void;
16
+ }
17
+ export default Scriptable;
@@ -0,0 +1,163 @@
1
+ import { BaseNode, editableProperties } from './BaseNode.js';
2
+ class Scriptable extends BaseNode {
3
+ _events = {};
4
+ _rules = {};
5
+ getRules() {
6
+ return typeof this._jsonModel.rules !== 'object' ? {} : this._jsonModel.rules;
7
+ }
8
+ getCompiledRule(eName, rule) {
9
+ if (!(eName in this._rules)) {
10
+ const eString = rule || this.getRules()[eName];
11
+ if (typeof eString === 'string' && eString.length > 0) {
12
+ try {
13
+ this._rules[eName] = this.ruleEngine.compileRule(eString);
14
+ }
15
+ catch (e) {
16
+ this.form.logger.error(`Unable to compile rule \`"${eName}" : "${eString}"\` Exception : ${e}`);
17
+ }
18
+ }
19
+ else {
20
+ throw new Error(`only expression strings are supported. ${typeof (eString)} types are not supported`);
21
+ }
22
+ }
23
+ return this._rules[eName];
24
+ }
25
+ getCompiledEvent(eName) {
26
+ if (!(eName in this._events)) {
27
+ let eString = this._jsonModel.events?.[eName];
28
+ if (typeof eString === 'string' && eString.length > 0) {
29
+ eString = [eString];
30
+ }
31
+ if (typeof eString !== 'undefined' && eString.length > 0) {
32
+ this._events[eName] = eString.map(x => {
33
+ try {
34
+ return this.ruleEngine.compileRule(x);
35
+ }
36
+ catch (e) {
37
+ this.form.logger.error(`Unable to compile expression \`"${eName}" : "${eString}"\` Exception : ${e}`);
38
+ }
39
+ return null;
40
+ }).filter(x => x !== null);
41
+ }
42
+ }
43
+ return this._events[eName] || [];
44
+ }
45
+ applyUpdates(updates) {
46
+ Object.entries(updates).forEach(([key, value]) => {
47
+ if (key in editableProperties || (key in this && typeof this[key] !== 'function')) {
48
+ try {
49
+ this[key] = value;
50
+ }
51
+ catch (e) {
52
+ console.error(e);
53
+ }
54
+ }
55
+ });
56
+ }
57
+ executeAllRules(context) {
58
+ const entries = Object.entries(this.getRules());
59
+ if (entries.length > 0) {
60
+ const scope = this.getExpressionScope();
61
+ entries.forEach(([prop, rule]) => {
62
+ const node = this.getCompiledRule(prop, rule);
63
+ if (node) {
64
+ const newVal = this.ruleEngine.execute(node, scope, context, true);
65
+ if (editableProperties.indexOf(prop) > -1) {
66
+ this[prop] = newVal;
67
+ }
68
+ else {
69
+ this.form.logger.warn(`${prop} is not a valid editable property.`);
70
+ }
71
+ }
72
+ });
73
+ }
74
+ }
75
+ getExpressionScope() {
76
+ const parent = this.getNonTransparentParent();
77
+ const target = {
78
+ self: this.getRuleNode(),
79
+ siblings: parent?.ruleNodeReference() || {}
80
+ };
81
+ const scope = new Proxy(target, {
82
+ get: (target, prop) => {
83
+ if (prop === Symbol.toStringTag) {
84
+ return 'Object';
85
+ }
86
+ prop = prop;
87
+ if (prop.startsWith('$')) {
88
+ const retValue = target.self[prop];
89
+ if (retValue instanceof BaseNode) {
90
+ return retValue.getRuleNode();
91
+ }
92
+ else if (retValue instanceof Array) {
93
+ return retValue.map(r => r instanceof BaseNode ? r.getRuleNode() : r);
94
+ }
95
+ else {
96
+ return retValue;
97
+ }
98
+ }
99
+ else {
100
+ if (prop in target.siblings) {
101
+ return target.siblings[prop];
102
+ }
103
+ else {
104
+ return target.self[prop];
105
+ }
106
+ }
107
+ },
108
+ has: (target, prop) => {
109
+ prop = prop;
110
+ const selfPropertyOrChild = target.self[prop];
111
+ const sibling = target.siblings[prop];
112
+ return typeof selfPropertyOrChild != 'undefined' || typeof sibling != 'undefined';
113
+ }
114
+ });
115
+ return scope;
116
+ }
117
+ executeEvent(context, node) {
118
+ let updates;
119
+ if (node) {
120
+ updates = this.ruleEngine.execute(node, this.getExpressionScope(), context);
121
+ }
122
+ if (typeof updates !== 'undefined' && updates != null) {
123
+ this.applyUpdates(updates);
124
+ }
125
+ }
126
+ executeRule(event, context) {
127
+ if (typeof event.payload.ruleName === 'undefined') {
128
+ this.executeAllRules(context);
129
+ }
130
+ }
131
+ executeExpression(expr) {
132
+ const ruleContext = {
133
+ 'form': this.form,
134
+ '$form': this.form.getRuleNode(),
135
+ '$field': this.getRuleNode(),
136
+ 'field': this
137
+ };
138
+ const node = this.ruleEngine.compileRule(expr);
139
+ return this.ruleEngine.execute(node, this.getExpressionScope(), ruleContext);
140
+ }
141
+ executeAction(action) {
142
+ const context = {
143
+ 'form': this.form,
144
+ '$form': this.form.getRuleNode(),
145
+ '$field': this.getRuleNode(),
146
+ 'field': this,
147
+ '$event': {
148
+ type: action.type,
149
+ payload: action.payload,
150
+ target: this.getRuleNode()
151
+ }
152
+ };
153
+ const eventName = action.isCustomEvent ? `custom:${action.type}` : action.type;
154
+ const funcName = action.isCustomEvent ? `custom_${action.type}` : action.type;
155
+ const node = this.getCompiledEvent(eventName);
156
+ if (funcName in this && typeof this[funcName] === 'function') {
157
+ this[funcName](action, context);
158
+ }
159
+ node.forEach((n) => this.executeEvent(context, n));
160
+ this.notifyDependents(action);
161
+ }
162
+ }
163
+ export default Scriptable;
@@ -0,0 +1,17 @@
1
+ import { Action, BaseJson } from '../types/index.js';
2
+ import { BaseNode } from '../BaseNode.js';
3
+ import { Logger } from './Logger.js';
4
+ declare class EventQueue {
5
+ private logger;
6
+ static readonly MAX_EVENT_CYCLE_COUNT = 10;
7
+ private _runningEventCount;
8
+ private _isProcessing;
9
+ private _pendingEvents;
10
+ constructor(logger?: Logger);
11
+ get length(): number;
12
+ get isProcessing(): boolean;
13
+ isQueued<T extends BaseJson>(node: BaseNode<T>, event: Action): boolean;
14
+ queue<T extends BaseJson>(node: BaseNode<T>, events: Action | Action[], priority?: boolean): void;
15
+ runPendingQueue(): void;
16
+ }
17
+ export default EventQueue;
@@ -0,0 +1,86 @@
1
+ import { Logger } from './Logger.js';
2
+ class EventNode {
3
+ _node;
4
+ _event;
5
+ constructor(_node, _event) {
6
+ this._node = _node;
7
+ this._event = _event;
8
+ }
9
+ get node() {
10
+ return this._node;
11
+ }
12
+ get event() {
13
+ return this._event;
14
+ }
15
+ isEqual(that) {
16
+ return that !== null && that !== undefined && this._node == that._node && this._event.type == that._event.type;
17
+ }
18
+ toString() {
19
+ return this._node.id + '__' + this.event.type;
20
+ }
21
+ valueOf() {
22
+ return this.toString();
23
+ }
24
+ }
25
+ class EventQueue {
26
+ logger;
27
+ static MAX_EVENT_CYCLE_COUNT = 10;
28
+ _runningEventCount;
29
+ _isProcessing = false;
30
+ _pendingEvents = [];
31
+ constructor(logger = new Logger('off')) {
32
+ this.logger = logger;
33
+ this._runningEventCount = {};
34
+ }
35
+ get length() {
36
+ return this._pendingEvents.length;
37
+ }
38
+ get isProcessing() {
39
+ return this._isProcessing;
40
+ }
41
+ isQueued(node, event) {
42
+ const evntNode = new EventNode(node, event);
43
+ return this._pendingEvents.find(x => evntNode.isEqual(x)) !== undefined;
44
+ }
45
+ queue(node, events, priority = false) {
46
+ if (!node || !events) {
47
+ return;
48
+ }
49
+ if (!(events instanceof Array)) {
50
+ events = [events];
51
+ }
52
+ events.forEach(e => {
53
+ const evntNode = new EventNode(node, e);
54
+ const counter = this._runningEventCount[evntNode.valueOf()] || 0;
55
+ if (counter < EventQueue.MAX_EVENT_CYCLE_COUNT) {
56
+ this.logger.info(`Queued event : ${e.type} node: ${node.id} - ${node.name}`);
57
+ if (priority) {
58
+ const index = this._isProcessing ? 1 : 0;
59
+ this._pendingEvents.splice(index, 0, evntNode);
60
+ }
61
+ else {
62
+ this._pendingEvents.push(evntNode);
63
+ }
64
+ this._runningEventCount[evntNode.valueOf()] = counter + 1;
65
+ }
66
+ else {
67
+ this.logger.info(`Skipped queueing event : ${e.type} node: ${node.id} - ${node.name} with count=${counter}`);
68
+ }
69
+ });
70
+ }
71
+ runPendingQueue() {
72
+ if (this._isProcessing) {
73
+ return;
74
+ }
75
+ this._isProcessing = true;
76
+ while (this._pendingEvents.length > 0) {
77
+ const e = this._pendingEvents[0];
78
+ this.logger.info(`Dequeued event : ${e.event.type} node: ${e.node.id} - ${e.node.name}`);
79
+ e.node.executeAction(e.event);
80
+ this._pendingEvents.shift();
81
+ }
82
+ this._runningEventCount = {};
83
+ this._isProcessing = false;
84
+ }
85
+ }
86
+ export default EventQueue;
@@ -0,0 +1,85 @@
1
+ import { Action, BaseJson, FieldModel, FieldsetModel, FormModel, ValidationError } from '../types/index.js';
2
+ declare class ActionImpl implements Action {
3
+ private _metadata?;
4
+ protected _type: string;
5
+ private _payload?;
6
+ private _target;
7
+ constructor(payload: any, type: string, _metadata?: any);
8
+ get type(): string;
9
+ get payload(): any;
10
+ get metadata(): any;
11
+ get target(): FormModel | FieldModel | FieldsetModel;
12
+ get isCustomEvent(): boolean;
13
+ protected payloadToJson(): any;
14
+ toJson(): {
15
+ payload: any;
16
+ type: string;
17
+ isCustomEvent: boolean;
18
+ };
19
+ toString(): string;
20
+ }
21
+ export declare type ChangePayload = {
22
+ changes: Array<{
23
+ propertyName: string;
24
+ prevValue?: any;
25
+ currentValue: any;
26
+ }>;
27
+ };
28
+ export declare class Change extends ActionImpl {
29
+ constructor(payload: ChangePayload, dispatch?: boolean);
30
+ withAdditionalChange(change: Change): Change;
31
+ }
32
+ export declare class Invalid extends ActionImpl {
33
+ constructor(payload?: any);
34
+ }
35
+ export declare class Valid extends ActionImpl {
36
+ constructor(payload?: any);
37
+ }
38
+ export declare class ExecuteRule extends ActionImpl {
39
+ constructor(payload?: any, dispatch?: boolean);
40
+ }
41
+ export declare const propertyChange: (propertyName: string, currentValue: any, prevValue?: any) => Change;
42
+ export declare class Initialize extends ActionImpl {
43
+ constructor(payload?: any, dispatch?: boolean);
44
+ }
45
+ export declare class FormLoad extends ActionImpl {
46
+ constructor();
47
+ }
48
+ export declare class Click extends ActionImpl {
49
+ constructor(payload?: any, dispatch?: boolean);
50
+ }
51
+ export declare class Blur extends ActionImpl {
52
+ constructor(payload?: any, dispatch?: boolean);
53
+ }
54
+ export declare class ValidationComplete extends ActionImpl {
55
+ constructor(payload?: Array<ValidationError>, dispatch?: boolean);
56
+ }
57
+ export declare class Focus extends ActionImpl {
58
+ constructor();
59
+ }
60
+ export declare class Submit extends ActionImpl {
61
+ constructor(payload?: any, dispatch?: boolean);
62
+ }
63
+ export declare class Reset extends ActionImpl {
64
+ constructor(payload?: any, dispatch?: boolean);
65
+ }
66
+ export declare class FieldChanged extends ActionImpl {
67
+ constructor(changes: ChangePayload, field: BaseJson);
68
+ }
69
+ export declare class CustomEvent extends ActionImpl {
70
+ constructor(eventName: string, payload?: any, dispatch?: boolean);
71
+ get isCustomEvent(): boolean;
72
+ }
73
+ export declare class AddItem extends ActionImpl {
74
+ constructor(payload?: number);
75
+ }
76
+ export declare class RemoveItem extends ActionImpl {
77
+ constructor(payload?: number);
78
+ }
79
+ export declare class AddInstance extends ActionImpl {
80
+ constructor(payload?: number);
81
+ }
82
+ export declare class RemoveInstance extends ActionImpl {
83
+ constructor(payload?: number);
84
+ }
85
+ export {};
@@ -0,0 +1,149 @@
1
+ class ActionImpl {
2
+ _metadata;
3
+ _type;
4
+ _payload;
5
+ _target;
6
+ constructor(payload, type, _metadata) {
7
+ this._metadata = _metadata;
8
+ this._payload = payload;
9
+ this._type = type;
10
+ }
11
+ get type() {
12
+ return this._type;
13
+ }
14
+ get payload() {
15
+ return this._payload;
16
+ }
17
+ get metadata() {
18
+ return this._metadata;
19
+ }
20
+ get target() {
21
+ return this._target;
22
+ }
23
+ get isCustomEvent() {
24
+ return false;
25
+ }
26
+ payloadToJson() {
27
+ return this.payload;
28
+ }
29
+ toJson() {
30
+ return {
31
+ payload: this.payloadToJson(),
32
+ type: this.type,
33
+ isCustomEvent: this.isCustomEvent
34
+ };
35
+ }
36
+ toString() {
37
+ return JSON.stringify(this.toJson());
38
+ }
39
+ }
40
+ export class Change extends ActionImpl {
41
+ constructor(payload, dispatch = false) {
42
+ super(payload, 'change', { dispatch });
43
+ }
44
+ withAdditionalChange(change) {
45
+ return new Change(this.payload.changes.concat(change.payload.changes), this.metadata);
46
+ }
47
+ }
48
+ export class Invalid extends ActionImpl {
49
+ constructor(payload = {}) {
50
+ super(payload, 'invalid', {});
51
+ }
52
+ }
53
+ export class Valid extends ActionImpl {
54
+ constructor(payload = {}) {
55
+ super(payload, 'valid', {});
56
+ }
57
+ }
58
+ export class ExecuteRule extends ActionImpl {
59
+ constructor(payload = {}, dispatch = false) {
60
+ super(payload, 'executeRule', { dispatch });
61
+ }
62
+ }
63
+ export const propertyChange = (propertyName, currentValue, prevValue) => {
64
+ return new Change({
65
+ changes: [
66
+ {
67
+ propertyName,
68
+ currentValue,
69
+ prevValue
70
+ }
71
+ ]
72
+ });
73
+ };
74
+ export class Initialize extends ActionImpl {
75
+ constructor(payload, dispatch = false) {
76
+ super(payload, 'initialize', { dispatch });
77
+ }
78
+ }
79
+ export class FormLoad extends ActionImpl {
80
+ constructor() {
81
+ super({}, 'load', { dispatch: false });
82
+ }
83
+ }
84
+ export class Click extends ActionImpl {
85
+ constructor(payload, dispatch = false) {
86
+ super(payload, 'click', { dispatch });
87
+ }
88
+ }
89
+ export class Blur extends ActionImpl {
90
+ constructor(payload, dispatch = false) {
91
+ super(payload, 'blur', { dispatch });
92
+ }
93
+ }
94
+ export class ValidationComplete extends ActionImpl {
95
+ constructor(payload, dispatch = false) {
96
+ super(payload, 'validationComplete', { dispatch });
97
+ }
98
+ }
99
+ export class Focus extends ActionImpl {
100
+ constructor() {
101
+ super({}, 'focus', { dispatch: false });
102
+ }
103
+ }
104
+ export class Submit extends ActionImpl {
105
+ constructor(payload, dispatch = false) {
106
+ super(payload, 'submit', { dispatch });
107
+ }
108
+ }
109
+ export class Reset extends ActionImpl {
110
+ constructor(payload, dispatch = false) {
111
+ super(payload, 'reset', { dispatch });
112
+ }
113
+ }
114
+ export class FieldChanged extends ActionImpl {
115
+ constructor(changes, field) {
116
+ super({
117
+ field,
118
+ changes
119
+ }, 'fieldChanged');
120
+ }
121
+ }
122
+ export class CustomEvent extends ActionImpl {
123
+ constructor(eventName, payload = {}, dispatch = false) {
124
+ super(payload, eventName, { dispatch });
125
+ }
126
+ get isCustomEvent() {
127
+ return true;
128
+ }
129
+ }
130
+ export class AddItem extends ActionImpl {
131
+ constructor(payload) {
132
+ super(payload, 'addItem');
133
+ }
134
+ }
135
+ export class RemoveItem extends ActionImpl {
136
+ constructor(payload) {
137
+ super(payload, 'removeItem');
138
+ }
139
+ }
140
+ export class AddInstance extends ActionImpl {
141
+ constructor(payload) {
142
+ super(payload, 'addInstance');
143
+ }
144
+ }
145
+ export class RemoveInstance extends ActionImpl {
146
+ constructor(payload) {
147
+ super(payload, 'removeInstance');
148
+ }
149
+ }
@@ -0,0 +1,11 @@
1
+ export declare type LogFunction = 'info' | 'warn' | 'error' | 'debug';
2
+ export declare type LogLevel = 'off' | LogFunction;
3
+ export declare class Logger {
4
+ debug(msg: string): void;
5
+ info(msg: string): void;
6
+ warn(msg: string): void;
7
+ error(msg: string): void;
8
+ log(msg: string, level: LogFunction): void;
9
+ private logLevel;
10
+ constructor(logLevel?: LogLevel);
11
+ }
@@ -0,0 +1,30 @@
1
+ const levels = {
2
+ off: 0,
3
+ debug: 1,
4
+ info: 2,
5
+ warn: 3,
6
+ error: 4
7
+ };
8
+ export class Logger {
9
+ debug(msg) {
10
+ this.log(msg, 'debug');
11
+ }
12
+ info(msg) {
13
+ this.log(msg, 'info');
14
+ }
15
+ warn(msg) {
16
+ this.log(msg, 'warn');
17
+ }
18
+ error(msg) {
19
+ this.log(msg, 'error');
20
+ }
21
+ log(msg, level) {
22
+ if (this.logLevel !== 0 && this.logLevel <= levels[level]) {
23
+ console[level](msg);
24
+ }
25
+ }
26
+ logLevel;
27
+ constructor(logLevel = 'off') {
28
+ this.logLevel = levels[logLevel];
29
+ }
30
+ }
@@ -0,0 +1,20 @@
1
+ import DataValue from './DataValue.js';
2
+ export default class DataGroup extends DataValue {
3
+ $_items: {
4
+ [key: string]: DataValue | DataGroup;
5
+ } | DataValue[] | DataGroup[];
6
+ private createEntry;
7
+ constructor(_name: string | number, _value: {
8
+ [key: string]: any;
9
+ } | any[], _type?: string);
10
+ get $value(): Array<any> | {
11
+ [key: string]: any;
12
+ };
13
+ get $length(): number;
14
+ $convertToDataValue(): DataValue;
15
+ $addDataNode(name: string | number, value: DataGroup | DataValue, override?: boolean): void;
16
+ $removeDataNode(name: string | number): void;
17
+ $getDataNode(name: string | number): any;
18
+ $containsDataNode(name: string | number): boolean;
19
+ get $isDataGroup(): boolean;
20
+ }
@@ -0,0 +1,77 @@
1
+ import DataValue from './DataValue.js';
2
+ import NullDataValue from './EmptyDataValue.js';
3
+ export default class DataGroup extends DataValue {
4
+ $_items;
5
+ createEntry(key, value) {
6
+ const t = value instanceof Array ? 'array' : typeof value;
7
+ if (typeof value === 'object' && value != null) {
8
+ return new DataGroup(key, value, t);
9
+ }
10
+ else {
11
+ return new DataValue(key, value, t);
12
+ }
13
+ }
14
+ constructor(_name, _value, _type = typeof _value) {
15
+ super(_name, _value, _type);
16
+ if (_value instanceof Array) {
17
+ this.$_items = _value.map((value, index) => {
18
+ return this.createEntry(index, value);
19
+ });
20
+ }
21
+ else {
22
+ this.$_items = Object.fromEntries(Object.entries(_value).map(([key, value]) => {
23
+ return [key, this.createEntry(key, value)];
24
+ }));
25
+ }
26
+ }
27
+ get $value() {
28
+ const enabled = this.$_fields.find(x => x.enabled !== false);
29
+ if (!enabled && this.$_fields.length) {
30
+ return this.$type === 'array' ? [] : {};
31
+ }
32
+ else if (this.$type === 'array') {
33
+ return Object.values(this.$_items).filter(x => typeof x !== 'undefined').map(x => x.$value);
34
+ }
35
+ else {
36
+ return Object.fromEntries(Object.values(this.$_items).filter(x => typeof x !== 'undefined').map(x => {
37
+ return [x.$name, x.$value];
38
+ }));
39
+ }
40
+ }
41
+ get $length() {
42
+ return Object.entries(this.$_items).length;
43
+ }
44
+ $convertToDataValue() {
45
+ return new DataValue(this.$name, this.$value, this.$type);
46
+ }
47
+ $addDataNode(name, value, override = false) {
48
+ if (value !== NullDataValue) {
49
+ if (this.$type === 'array') {
50
+ const index = name;
51
+ if (!override) {
52
+ this.$_items.splice(index, 0, value);
53
+ }
54
+ else {
55
+ this.$_items[name] = value;
56
+ }
57
+ }
58
+ else {
59
+ this.$_items[name] = value;
60
+ }
61
+ }
62
+ }
63
+ $removeDataNode(name) {
64
+ this.$_items[name] = undefined;
65
+ }
66
+ $getDataNode(name) {
67
+ if (this.$_items.hasOwnProperty(name)) {
68
+ return this.$_items[name];
69
+ }
70
+ }
71
+ $containsDataNode(name) {
72
+ return this.$_items.hasOwnProperty(name) && typeof (this.$_items[name]) !== 'undefined';
73
+ }
74
+ get $isDataGroup() {
75
+ return true;
76
+ }
77
+ }
@@ -0,0 +1,16 @@
1
+ import { FieldModel } from '../types/index.js';
2
+ export default class DataValue {
3
+ private $_name;
4
+ private $_value;
5
+ private $_type;
6
+ $_fields: Array<FieldModel>;
7
+ constructor($_name: string | number, $_value: any, $_type?: string);
8
+ valueOf(): any;
9
+ get $name(): string | number;
10
+ get $value(): any;
11
+ setValue(typedValue: any, originalValue: any, fromField: FieldModel): void;
12
+ get $type(): string;
13
+ $bindToField(field: FieldModel): void;
14
+ $convertToDataValue(): DataValue;
15
+ get $isDataGroup(): boolean;
16
+ }