@lowdefy/engine 3.23.0-alpha.0 → 4.0.0-alpha.4
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/Actions.js
CHANGED
|
@@ -1,330 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
constructor(context) {
|
|
20
|
-
this.context = context;
|
|
21
|
-
this.callAction = this.callAction.bind(this);
|
|
22
|
-
this.callActionLoop = this.callActionLoop.bind(this);
|
|
23
|
-
this.callActions = this.callActions.bind(this);
|
|
24
|
-
this.displayMessage = this.displayMessage.bind(this);
|
|
25
|
-
this.actions = _index.default;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
callAsyncAction(_ref) {
|
|
29
|
-
var _this = this;
|
|
30
|
-
|
|
31
|
-
return _asyncToGenerator(function* () {
|
|
32
|
-
var {
|
|
33
|
-
action,
|
|
34
|
-
arrayIndices,
|
|
35
|
-
block,
|
|
36
|
-
event,
|
|
37
|
-
index,
|
|
38
|
-
responses
|
|
39
|
-
} = _ref;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
var response = yield _this.callAction({
|
|
43
|
-
action,
|
|
44
|
-
arrayIndices,
|
|
45
|
-
block,
|
|
46
|
-
event,
|
|
47
|
-
index,
|
|
48
|
-
responses
|
|
49
|
-
});
|
|
50
|
-
responses[action.id] = response;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
responses[action.id] = error;
|
|
53
|
-
console.error(error);
|
|
54
|
-
}
|
|
55
|
-
})();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
callActionLoop(_ref2) {
|
|
59
|
-
var _this2 = this;
|
|
60
|
-
|
|
61
|
-
return _asyncToGenerator(function* () {
|
|
62
|
-
var {
|
|
63
|
-
actions,
|
|
64
|
-
arrayIndices,
|
|
65
|
-
block,
|
|
66
|
-
event,
|
|
67
|
-
responses
|
|
68
|
-
} = _ref2;
|
|
69
|
-
|
|
70
|
-
for (var [index, action] of actions.entries()) {
|
|
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
|
+
import actions from './actions/index.js';
|
|
17
|
+
let Actions = class Actions {
|
|
18
|
+
async callAsyncAction({ action , arrayIndices , block , event , index , responses }) {
|
|
71
19
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
responses
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
var response = yield _this2.callAction({
|
|
83
|
-
action,
|
|
84
|
-
arrayIndices,
|
|
85
|
-
block,
|
|
86
|
-
event,
|
|
87
|
-
index,
|
|
88
|
-
responses
|
|
20
|
+
const response = await this.callAction({
|
|
21
|
+
action,
|
|
22
|
+
arrayIndices,
|
|
23
|
+
block,
|
|
24
|
+
event,
|
|
25
|
+
index,
|
|
26
|
+
responses
|
|
89
27
|
});
|
|
90
28
|
responses[action.id] = response;
|
|
91
|
-
}
|
|
92
29
|
} catch (error) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
error,
|
|
96
|
-
action
|
|
97
|
-
};
|
|
30
|
+
responses[action.id] = error;
|
|
31
|
+
console.error(error);
|
|
98
32
|
}
|
|
99
|
-
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
33
|
+
}
|
|
34
|
+
async callActionLoop({ actions: actions1 , arrayIndices: arrayIndices1 , block: block1 , event: event1 , responses: responses1 }) {
|
|
35
|
+
for (const [index, action] of actions1.entries()){
|
|
36
|
+
try {
|
|
37
|
+
if (action.async === true) {
|
|
38
|
+
this.callAsyncAction({
|
|
39
|
+
action,
|
|
40
|
+
arrayIndices: arrayIndices1,
|
|
41
|
+
block: block1,
|
|
42
|
+
event: event1,
|
|
43
|
+
index,
|
|
44
|
+
responses: responses1
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
const response = await this.callAction({
|
|
48
|
+
action,
|
|
49
|
+
arrayIndices: arrayIndices1,
|
|
50
|
+
block: block1,
|
|
51
|
+
event: event1,
|
|
52
|
+
index,
|
|
53
|
+
responses: responses1
|
|
54
|
+
});
|
|
55
|
+
responses1[action.id] = response;
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
responses1[action.id] = error;
|
|
59
|
+
throw {
|
|
60
|
+
error,
|
|
61
|
+
action
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async callActions({ actions: actions2 , arrayIndices: arrayIndices2 , block: block2 , catchActions , event: event2 , eventName }) {
|
|
67
|
+
const startTimestamp = new Date();
|
|
68
|
+
const responses = {
|
|
69
|
+
};
|
|
129
70
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} catch (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
71
|
+
await this.callActionLoop({
|
|
72
|
+
actions: actions2,
|
|
73
|
+
arrayIndices: arrayIndices2,
|
|
74
|
+
block: block2,
|
|
75
|
+
event: event2,
|
|
76
|
+
responses
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(error);
|
|
80
|
+
try {
|
|
81
|
+
await this.callActionLoop({
|
|
82
|
+
actions: catchActions,
|
|
83
|
+
arrayIndices: arrayIndices2,
|
|
84
|
+
block: block2,
|
|
85
|
+
event: event2,
|
|
86
|
+
responses
|
|
87
|
+
});
|
|
88
|
+
} catch (errorCatch) {
|
|
89
|
+
console.error(errorCatch);
|
|
90
|
+
return {
|
|
91
|
+
blockId: block2.blockId,
|
|
92
|
+
bounced: false,
|
|
93
|
+
endTimestamp: new Date(),
|
|
94
|
+
error,
|
|
95
|
+
errorCatch,
|
|
96
|
+
event: event2,
|
|
97
|
+
eventName,
|
|
98
|
+
responses,
|
|
99
|
+
startTimestamp,
|
|
100
|
+
success: false
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
blockId: block2.blockId,
|
|
105
|
+
bounced: false,
|
|
106
|
+
endTimestamp: new Date(),
|
|
107
|
+
error,
|
|
108
|
+
event: event2,
|
|
109
|
+
eventName,
|
|
110
|
+
responses,
|
|
111
|
+
startTimestamp,
|
|
112
|
+
success: false
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
blockId: block2.blockId,
|
|
141
117
|
bounced: false,
|
|
142
118
|
endTimestamp: new Date(),
|
|
143
|
-
|
|
144
|
-
errorCatch,
|
|
145
|
-
event,
|
|
119
|
+
event: event2,
|
|
146
120
|
eventName,
|
|
147
121
|
responses,
|
|
148
122
|
startTimestamp,
|
|
149
|
-
success:
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
blockId: block.blockId,
|
|
155
|
-
bounced: false,
|
|
156
|
-
endTimestamp: new Date(),
|
|
157
|
-
error,
|
|
158
|
-
event,
|
|
159
|
-
eventName,
|
|
160
|
-
responses,
|
|
161
|
-
startTimestamp,
|
|
162
|
-
success: false
|
|
123
|
+
success: true
|
|
163
124
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
callAction(_ref4) {
|
|
180
|
-
var _this4 = this;
|
|
181
|
-
|
|
182
|
-
return _asyncToGenerator(function* () {
|
|
183
|
-
var {
|
|
184
|
-
action,
|
|
185
|
-
arrayIndices,
|
|
186
|
-
block,
|
|
187
|
-
event,
|
|
188
|
-
index,
|
|
189
|
-
responses
|
|
190
|
-
} = _ref4;
|
|
191
|
-
|
|
192
|
-
if (!_index.default[action.type]) {
|
|
193
|
-
throw {
|
|
194
|
-
error: new Error("Invalid action type \"".concat(action.type, "\" at \"").concat(block.blockId, "\".")),
|
|
195
|
-
type: action.type,
|
|
196
|
-
index
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
var {
|
|
201
|
-
output: parsedAction,
|
|
202
|
-
errors: parserErrors
|
|
203
|
-
} = _this4.context.parser.parse({
|
|
204
|
-
actions: responses,
|
|
205
|
-
event,
|
|
206
|
-
arrayIndices,
|
|
207
|
-
input: action,
|
|
208
|
-
location: block.blockId
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
if (parserErrors.length > 0) {
|
|
212
|
-
throw {
|
|
213
|
-
error: parserErrors[0],
|
|
214
|
-
type: action.type,
|
|
215
|
-
index
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (parsedAction.skip === true) {
|
|
220
|
-
return {
|
|
221
|
-
type: action.type,
|
|
222
|
-
skipped: true,
|
|
223
|
-
index
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
var messages = parsedAction.messages || {};
|
|
228
|
-
var response;
|
|
229
|
-
|
|
230
|
-
var closeLoading = _this4.displayMessage({
|
|
231
|
-
defaultMessage: 'Loading',
|
|
232
|
-
duration: 0,
|
|
233
|
-
message: messages.loading,
|
|
234
|
-
status: 'loading'
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
response = yield _index.default[action.type]({
|
|
239
|
-
arrayIndices,
|
|
240
|
-
blockId: block.blockId,
|
|
241
|
-
context: _this4.context,
|
|
242
|
-
event,
|
|
243
|
-
params: parsedAction.params
|
|
125
|
+
}
|
|
126
|
+
async callAction({ action: action1 , arrayIndices: arrayIndices3 , block: block3 , event: event3 , index: index1 , responses: responses2 }) {
|
|
127
|
+
if (!actions[action1.type]) {
|
|
128
|
+
throw {
|
|
129
|
+
error: new Error(`Invalid action type "${action1.type}" at "${block3.blockId}".`),
|
|
130
|
+
type: action1.type,
|
|
131
|
+
index: index1
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const { output: parsedAction , errors: parserErrors } = this.context._internal.parser.parse({
|
|
135
|
+
actions: responses2,
|
|
136
|
+
event: event3,
|
|
137
|
+
arrayIndices: arrayIndices3,
|
|
138
|
+
input: action1,
|
|
139
|
+
location: block3.blockId
|
|
244
140
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
141
|
+
if (parserErrors.length > 0) {
|
|
142
|
+
throw {
|
|
143
|
+
error: parserErrors[0],
|
|
144
|
+
type: action1.type,
|
|
145
|
+
index: index1
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (parsedAction.skip === true) {
|
|
149
|
+
return {
|
|
150
|
+
type: action1.type,
|
|
151
|
+
skipped: true,
|
|
152
|
+
index: index1
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const messages = parsedAction.messages || {
|
|
250
156
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
event,
|
|
258
|
-
arrayIndices,
|
|
259
|
-
input: action.messages,
|
|
260
|
-
location: block.blockId
|
|
157
|
+
let response;
|
|
158
|
+
const closeLoading = this.displayMessage({
|
|
159
|
+
defaultMessage: 'Loading',
|
|
160
|
+
duration: 0,
|
|
161
|
+
message: messages.loading,
|
|
162
|
+
status: 'loading'
|
|
261
163
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
164
|
+
try {
|
|
165
|
+
response = await actions[action1.type]({
|
|
166
|
+
arrayIndices: arrayIndices3,
|
|
167
|
+
blockId: block3.blockId,
|
|
168
|
+
context: this.context,
|
|
169
|
+
event: event3,
|
|
170
|
+
params: parsedAction.params
|
|
171
|
+
});
|
|
172
|
+
} catch (error) {
|
|
173
|
+
responses2[action1.id] = {
|
|
174
|
+
error,
|
|
175
|
+
index: index1,
|
|
176
|
+
type: action1.type
|
|
177
|
+
};
|
|
178
|
+
const { output: parsedMessages , errors: parserErrors } = this.context._internal.parser.parse({
|
|
179
|
+
actions: responses2,
|
|
180
|
+
event: event3,
|
|
181
|
+
arrayIndices: arrayIndices3,
|
|
182
|
+
input: action1.messages,
|
|
183
|
+
location: block3.blockId
|
|
184
|
+
});
|
|
185
|
+
if (parserErrors.length > 0) {
|
|
186
|
+
// this condition is very unlikely since parser errors usually occur in the first parse.
|
|
187
|
+
throw {
|
|
188
|
+
error: parserErrors[0],
|
|
189
|
+
type: action1.type,
|
|
190
|
+
index: index1
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
closeLoading();
|
|
194
|
+
this.displayMessage({
|
|
195
|
+
defaultMessage: error.message,
|
|
196
|
+
duration: 6,
|
|
197
|
+
hideExplicitly: true,
|
|
198
|
+
message: (parsedMessages || {
|
|
199
|
+
}).error,
|
|
200
|
+
status: 'error'
|
|
201
|
+
});
|
|
202
|
+
throw {
|
|
203
|
+
type: action1.type,
|
|
204
|
+
error,
|
|
205
|
+
index: index1
|
|
206
|
+
};
|
|
270
207
|
}
|
|
271
|
-
|
|
272
208
|
closeLoading();
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
hideExplicitly: true,
|
|
278
|
-
message: (parsedMessages || {}).error,
|
|
279
|
-
status: 'error'
|
|
209
|
+
this.displayMessage({
|
|
210
|
+
defaultMessage: 'Success',
|
|
211
|
+
message: messages.success,
|
|
212
|
+
status: 'success'
|
|
280
213
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
index
|
|
214
|
+
return {
|
|
215
|
+
type: action1.type,
|
|
216
|
+
response,
|
|
217
|
+
index: index1
|
|
286
218
|
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
closeLoading();
|
|
290
|
-
|
|
291
|
-
_this4.displayMessage({
|
|
292
|
-
defaultMessage: 'Success',
|
|
293
|
-
message: messages.success,
|
|
294
|
-
status: 'success'
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
return {
|
|
298
|
-
type: action.type,
|
|
299
|
-
response,
|
|
300
|
-
index
|
|
301
|
-
};
|
|
302
|
-
})();
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
displayMessage(_ref5) {
|
|
306
|
-
var {
|
|
307
|
-
defaultMessage,
|
|
308
|
-
duration,
|
|
309
|
-
hideExplicitly,
|
|
310
|
-
message,
|
|
311
|
-
status
|
|
312
|
-
} = _ref5;
|
|
313
|
-
|
|
314
|
-
var close = () => undefined;
|
|
315
|
-
|
|
316
|
-
if (hideExplicitly && message !== false || !hideExplicitly && !_helpers.type.isNone(message)) {
|
|
317
|
-
close = this.context.lowdefy.displayMessage({
|
|
318
|
-
content: _helpers.type.isString(message) ? message : defaultMessage,
|
|
319
|
-
duration,
|
|
320
|
-
status
|
|
321
|
-
});
|
|
322
219
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
220
|
+
displayMessage({ defaultMessage , duration , hideExplicitly , message , status }) {
|
|
221
|
+
let close = ()=>undefined
|
|
222
|
+
;
|
|
223
|
+
if (hideExplicitly && message !== false || !hideExplicitly && !type.isNone(message)) {
|
|
224
|
+
close = this.context._internal.lowdefy._internal.displayMessage({
|
|
225
|
+
content: type.isString(message) ? message : defaultMessage,
|
|
226
|
+
duration,
|
|
227
|
+
status
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return close;
|
|
231
|
+
}
|
|
232
|
+
constructor(context){
|
|
233
|
+
this.context = context;
|
|
234
|
+
this.callAction = this.callAction.bind(this);
|
|
235
|
+
this.callActionLoop = this.callActionLoop.bind(this);
|
|
236
|
+
this.callActions = this.callActions.bind(this);
|
|
237
|
+
this.displayMessage = this.displayMessage.bind(this);
|
|
238
|
+
this.actions = actions;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
export default Actions;
|