@lowdefy/engine 3.22.0 → 4.0.0-alpha.1
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/dist/Actions.js +221 -310
- package/dist/Blocks.js +577 -607
- package/dist/Events.js +120 -162
- package/dist/Requests.js +110 -144
- package/dist/State.js +55 -81
- package/dist/actions/CallMethod.js +20 -39
- package/dist/actions/JsAction.js +50 -72
- package/dist/actions/Link.js +22 -33
- package/dist/actions/Login.js +3 -28
- package/dist/actions/Logout.js +3 -27
- package/dist/actions/Message.js +9 -22
- package/dist/actions/Request.js +21 -63
- package/dist/actions/Reset.js +6 -20
- package/dist/actions/ResetValidation.js +18 -31
- package/dist/actions/ScrollTo.js +8 -34
- package/dist/actions/SetGlobal.js +18 -30
- package/dist/actions/SetState.js +18 -30
- package/dist/actions/Throw.js +25 -52
- package/dist/actions/Validate.js +20 -34
- package/dist/actions/Wait.js +21 -32
- package/dist/actions/index.js +31 -57
- package/dist/createLink.js +29 -59
- package/dist/getBlockMatcher.js +46 -58
- package/dist/getContext.js +100 -142
- package/dist/getFieldValues.js +18 -32
- package/dist/index.js +9 -70
- package/package.json +12 -13
- package/dist/makeContextId.js +0 -44
package/dist/Events.js
CHANGED
|
@@ -1,166 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
debounce: _helpers.type.isObject(actions) ? actions.debounce : null,
|
|
39
|
-
history: [],
|
|
40
|
-
loading: false
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
init() {
|
|
45
|
-
Object.keys(this.block.events).forEach(eventName => {
|
|
46
|
-
this.events[eventName] = this.initEvent(this.block.events[eventName]);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
registerEvent(_ref2) {
|
|
51
|
-
var {
|
|
52
|
-
name,
|
|
53
|
-
actions
|
|
54
|
-
} = _ref2;
|
|
55
|
-
this.events[name] = this.initEvent(actions);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
triggerEvent(_ref3) {
|
|
59
|
-
var _this = this;
|
|
60
|
-
|
|
61
|
-
return _asyncToGenerator(function* () {
|
|
62
|
-
var {
|
|
63
|
-
name,
|
|
64
|
-
event
|
|
65
|
-
} = _ref3;
|
|
66
|
-
var eventDescription = _this.events[name];
|
|
67
|
-
var result = {
|
|
68
|
-
blockId: _this.block.blockId,
|
|
69
|
-
event,
|
|
70
|
-
eventName: name,
|
|
71
|
-
responses: {},
|
|
72
|
-
endTimestamp: new Date(),
|
|
73
|
-
startTimestamp: new Date(),
|
|
74
|
-
success: true,
|
|
75
|
-
bounced: false
|
|
76
|
-
}; // no event
|
|
77
|
-
|
|
78
|
-
if (_helpers.type.isUndefined(eventDescription)) {
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
eventDescription.loading = true;
|
|
83
|
-
_this.block.update = true;
|
|
84
|
-
|
|
85
|
-
_this.context.update();
|
|
86
|
-
|
|
87
|
-
var actionHandle = /*#__PURE__*/function () {
|
|
88
|
-
var _ref4 = _asyncToGenerator(function* () {
|
|
89
|
-
var res = yield _this.context.Actions.callActions({
|
|
90
|
-
actions: eventDescription.actions,
|
|
91
|
-
arrayIndices: _this.arrayIndices,
|
|
92
|
-
block: _this.block,
|
|
93
|
-
catchActions: eventDescription.catchActions,
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
let Events = class Events {
|
|
17
|
+
initEvent(actions) {
|
|
18
|
+
return {
|
|
19
|
+
actions: (type.isObject(actions) ? actions.try : actions) || [],
|
|
20
|
+
catchActions: (type.isObject(actions) ? actions.catch : []) || [],
|
|
21
|
+
debounce: type.isObject(actions) ? actions.debounce : null,
|
|
22
|
+
history: [],
|
|
23
|
+
loading: false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
init() {
|
|
27
|
+
Object.keys(this.block.events).forEach((eventName)=>{
|
|
28
|
+
this.events[eventName] = this.initEvent(this.block.events[eventName]);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
registerEvent({ name , actions: actions1 }) {
|
|
32
|
+
this.events[name] = this.initEvent(actions1);
|
|
33
|
+
}
|
|
34
|
+
async triggerEvent({ name: name1 , event }) {
|
|
35
|
+
const eventDescription = this.events[name1];
|
|
36
|
+
let result = {
|
|
37
|
+
blockId: this.block.blockId,
|
|
94
38
|
event,
|
|
95
|
-
eventName:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
39
|
+
eventName: name1,
|
|
40
|
+
responses: {
|
|
41
|
+
},
|
|
42
|
+
endTimestamp: new Date(),
|
|
43
|
+
startTimestamp: new Date(),
|
|
44
|
+
success: true,
|
|
45
|
+
bounced: false
|
|
46
|
+
};
|
|
47
|
+
// no event
|
|
48
|
+
if (type.isUndefined(eventDescription)) {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
eventDescription.loading = true;
|
|
52
|
+
this.block.update = true;
|
|
53
|
+
this.context._internal.update();
|
|
54
|
+
const actionHandle = async ()=>{
|
|
55
|
+
const res = await this.context._internal.Actions.callActions({
|
|
56
|
+
actions: eventDescription.actions,
|
|
57
|
+
arrayIndices: this.arrayIndices,
|
|
58
|
+
block: this.block,
|
|
59
|
+
catchActions: eventDescription.catchActions,
|
|
60
|
+
event,
|
|
61
|
+
eventName: name1
|
|
62
|
+
});
|
|
63
|
+
eventDescription.history.unshift(res);
|
|
64
|
+
this.context.eventLog.unshift(res);
|
|
65
|
+
eventDescription.loading = false;
|
|
66
|
+
this.block.update = true;
|
|
67
|
+
this.context._internal.update();
|
|
68
|
+
return res;
|
|
69
|
+
};
|
|
70
|
+
// no debounce
|
|
71
|
+
if (type.isNone(eventDescription.debounce)) {
|
|
72
|
+
return actionHandle();
|
|
73
|
+
}
|
|
74
|
+
const delay = !type.isNone(eventDescription.debounce.ms) ? eventDescription.debounce.ms : this.defaultDebounceMs;
|
|
75
|
+
// leading edge: bounce
|
|
76
|
+
if (this.timeouts[name1] && eventDescription.debounce.immediate === true) {
|
|
77
|
+
result.bounced = true;
|
|
78
|
+
eventDescription.history.unshift(result);
|
|
79
|
+
this.context.eventLog.unshift(result);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
// leading edge: trigger
|
|
83
|
+
if (eventDescription.debounce.immediate === true) {
|
|
84
|
+
this.timeouts[name1] = setTimeout(()=>{
|
|
85
|
+
this.timeouts[name1] = null;
|
|
86
|
+
}, delay);
|
|
87
|
+
return actionHandle();
|
|
88
|
+
}
|
|
89
|
+
// trailing edge
|
|
90
|
+
if (eventDescription.bouncer) {
|
|
91
|
+
eventDescription.bouncer();
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve)=>{
|
|
94
|
+
const timeout = setTimeout(async ()=>{
|
|
95
|
+
eventDescription.bouncer = null;
|
|
96
|
+
const res = await actionHandle();
|
|
97
|
+
resolve(res);
|
|
98
|
+
}, delay);
|
|
99
|
+
eventDescription.bouncer = ()=>{
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
result.bounced = true;
|
|
102
|
+
eventDescription.history.unshift(result);
|
|
103
|
+
this.context.eventLog.unshift(result);
|
|
104
|
+
resolve(result);
|
|
105
|
+
};
|
|
107
106
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
}
|
|
108
|
+
constructor({ arrayIndices , block , context }){
|
|
109
|
+
this.defaultDebounceMs = 300;
|
|
110
|
+
this.events = {
|
|
111
111
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (_helpers.type.isNone(eventDescription.debounce)) {
|
|
116
|
-
return actionHandle();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var delay = !_helpers.type.isNone(eventDescription.debounce.ms) ? eventDescription.debounce.ms : _this.defaultDebounceMs; // leading edge: bounce
|
|
120
|
-
|
|
121
|
-
if (_this.timeouts[name] && eventDescription.debounce.immediate === true) {
|
|
122
|
-
result.bounced = true;
|
|
123
|
-
eventDescription.history.unshift(result);
|
|
124
|
-
|
|
125
|
-
_this.context.eventLog.unshift(result);
|
|
126
|
-
|
|
127
|
-
return result;
|
|
128
|
-
} // leading edge: trigger
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (eventDescription.debounce.immediate === true) {
|
|
132
|
-
_this.timeouts[name] = setTimeout(() => {
|
|
133
|
-
_this.timeouts[name] = null;
|
|
134
|
-
}, delay);
|
|
135
|
-
return actionHandle();
|
|
136
|
-
} // trailing edge
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (eventDescription.bouncer) {
|
|
140
|
-
eventDescription.bouncer();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return new Promise(resolve => {
|
|
144
|
-
var timeout = setTimeout( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
145
|
-
eventDescription.bouncer = null;
|
|
146
|
-
var res = yield actionHandle();
|
|
147
|
-
resolve(res);
|
|
148
|
-
}), delay);
|
|
149
|
-
|
|
150
|
-
eventDescription.bouncer = () => {
|
|
151
|
-
clearTimeout(timeout);
|
|
152
|
-
result.bounced = true;
|
|
153
|
-
eventDescription.history.unshift(result);
|
|
154
|
-
|
|
155
|
-
_this.context.eventLog.unshift(result);
|
|
156
|
-
|
|
157
|
-
resolve(result);
|
|
112
|
+
this.timeouts = {
|
|
158
113
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
114
|
+
this.arrayIndices = arrayIndices;
|
|
115
|
+
this.block = block;
|
|
116
|
+
this.context = context;
|
|
117
|
+
this.init = this.init.bind(this);
|
|
118
|
+
this.triggerEvent = this.triggerEvent.bind(this);
|
|
119
|
+
this.registerEvent = this.registerEvent.bind(this);
|
|
120
|
+
this.initEvent = this.initEvent.bind(this);
|
|
121
|
+
this.init();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
export default Events;
|
package/dist/Requests.js
CHANGED
|
@@ -1,147 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!requestIds) {
|
|
41
|
-
return Promise.all(this.requestList.map(request => this.callRequest({
|
|
42
|
-
requestId: request.requestId,
|
|
43
|
-
event,
|
|
44
|
-
arrayIndices
|
|
45
|
-
})));
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { get, serializer, type } from '@lowdefy/helpers';
|
|
16
|
+
let Requests = class Requests {
|
|
17
|
+
callRequests({ actions , arrayIndices , event , params } = {
|
|
18
|
+
}) {
|
|
19
|
+
if (params.all === true) {
|
|
20
|
+
return Promise.all(Object.keys(this.requestConfig).map((requestId)=>this.callRequest({
|
|
21
|
+
requestId,
|
|
22
|
+
event,
|
|
23
|
+
arrayIndices
|
|
24
|
+
})
|
|
25
|
+
));
|
|
26
|
+
}
|
|
27
|
+
let requestIds = [];
|
|
28
|
+
if (type.isString(params)) requestIds = [
|
|
29
|
+
params
|
|
30
|
+
];
|
|
31
|
+
if (type.isArray(params)) requestIds = params;
|
|
32
|
+
return Promise.all(requestIds.map((requestId)=>this.callRequest({
|
|
33
|
+
actions,
|
|
34
|
+
requestId,
|
|
35
|
+
event,
|
|
36
|
+
arrayIndices
|
|
37
|
+
})
|
|
38
|
+
));
|
|
46
39
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
40
|
+
callRequest({ actions: actions1 , arrayIndices: arrayIndices1 , event: event1 , requestId }) {
|
|
41
|
+
const request = this.requestConfig[requestId];
|
|
42
|
+
if (!request) {
|
|
43
|
+
const error = new Error(`Configuration Error: Request ${requestId} not defined on page.`);
|
|
44
|
+
this.context.requests[requestId] = {
|
|
45
|
+
loading: false,
|
|
46
|
+
response: null,
|
|
47
|
+
error: [
|
|
48
|
+
error
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
return Promise.reject(error);
|
|
52
|
+
}
|
|
53
|
+
if (!this.context.requests[requestId]) {
|
|
54
|
+
this.context.requests[requestId] = {
|
|
55
|
+
loading: true,
|
|
56
|
+
response: null,
|
|
57
|
+
error: []
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const { output: payload , errors: parserErrors } = this.context._internal.parser.parse({
|
|
61
|
+
actions: actions1,
|
|
62
|
+
event: event1,
|
|
63
|
+
arrayIndices: arrayIndices1,
|
|
64
|
+
input: request.payload,
|
|
65
|
+
location: requestId
|
|
66
|
+
});
|
|
67
|
+
// TODO: We are throwing this error differently to the request does not exist error
|
|
68
|
+
if (parserErrors.length > 0) {
|
|
69
|
+
throw parserErrors[0];
|
|
70
|
+
}
|
|
71
|
+
return this.fetch({
|
|
72
|
+
requestId,
|
|
73
|
+
payload
|
|
74
|
+
});
|
|
79
75
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
lowdefyGlobal: _helpers.serializer.serialize(_this.context.lowdefy.lowdefyGlobal),
|
|
115
|
-
pageId: _this.context.pageId,
|
|
116
|
-
state: _helpers.serializer.serialize(_this.context.state),
|
|
117
|
-
urlQuery: _helpers.serializer.serialize(_this.context.lowdefy.urlQuery)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
76
|
+
async fetch({ requestId: requestId1 , payload }) {
|
|
77
|
+
this.context.requests[requestId1].loading = true;
|
|
78
|
+
if (this.context._internal.RootBlocks) {
|
|
79
|
+
this.context._internal.RootBlocks.setBlocksLoadingCache();
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const response = await this.context._internal.lowdefy._internal.callRequest({
|
|
83
|
+
pageId: this.context.pageId,
|
|
84
|
+
payload: serializer.serialize(payload),
|
|
85
|
+
requestId: requestId1
|
|
86
|
+
});
|
|
87
|
+
const deserializedResponse = serializer.deserialize(get(response, 'response', {
|
|
88
|
+
default: null
|
|
89
|
+
}));
|
|
90
|
+
this.context.requests[requestId1].response = deserializedResponse;
|
|
91
|
+
this.context.requests[requestId1].loading = false;
|
|
92
|
+
this.context._internal.update();
|
|
93
|
+
return deserializedResponse;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
this.context.requests[requestId1].error.unshift(error);
|
|
96
|
+
this.context.requests[requestId1].loading = false;
|
|
97
|
+
this.context._internal.update();
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
constructor(context){
|
|
102
|
+
this.context = context;
|
|
103
|
+
this.callRequests = this.callRequests.bind(this);
|
|
104
|
+
this.callRequest = this.callRequest.bind(this);
|
|
105
|
+
this.fetch = this.fetch.bind(this);
|
|
106
|
+
this.requestConfig = {
|
|
107
|
+
};
|
|
108
|
+
(this.context._internal.rootBlock.requests || []).forEach((request)=>{
|
|
109
|
+
this.requestConfig[request.requestId] = request;
|
|
120
110
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}));
|
|
125
|
-
|
|
126
|
-
_this.context.requests[requestId].response = response;
|
|
127
|
-
_this.context.requests[requestId].loading = false;
|
|
128
|
-
|
|
129
|
-
_this.context.update();
|
|
130
|
-
|
|
131
|
-
return response;
|
|
132
|
-
} catch (error) {
|
|
133
|
-
_this.context.requests[requestId].error.unshift(error);
|
|
134
|
-
|
|
135
|
-
_this.context.requests[requestId].loading = false;
|
|
136
|
-
|
|
137
|
-
_this.context.update();
|
|
138
|
-
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
})();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
var _default = Requests;
|
|
147
|
-
exports.default = _default;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export default Requests;
|