@lowdefy/engine 3.23.2 → 4.0.0-alpha.10
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 +229 -309
- package/dist/Blocks.js +560 -608
- package/dist/Events.js +119 -163
- package/dist/Requests.js +105 -144
- package/dist/State.js +56 -82
- package/dist/actions/createCallMethod.js +29 -0
- package/dist/actions/{Reset.js → createDisplayMessage.js} +6 -21
- package/dist/actions/createGetActions.js +27 -0
- package/dist/actions/createGetBlockId.js +20 -0
- package/dist/actions/createGetEvent.js +27 -0
- package/dist/actions/createGetGlobal.js +27 -0
- package/dist/actions/createGetInput.js +27 -0
- package/dist/actions/createGetPageId.js +20 -0
- package/dist/actions/createGetRequestDetails.js +27 -0
- package/dist/actions/{Message.js → createGetState.js} +13 -23
- package/dist/actions/createGetUrlQuery.js +27 -0
- package/dist/actions/createGetUser.js +27 -0
- package/dist/actions/createLink.js +20 -0
- package/dist/actions/createLogin.js +20 -0
- package/dist/actions/createLogout.js +20 -0
- package/dist/actions/createRequest.js +25 -0
- package/dist/actions/createReset.js +23 -0
- package/dist/actions/createResetValidation.js +21 -0
- package/dist/actions/createSetGlobal.js +25 -0
- package/dist/actions/createSetState.js +25 -0
- package/dist/actions/createValidate.js +25 -0
- package/dist/actions/getActionMethods.js +61 -0
- package/dist/actions/getFromObject.js +42 -0
- package/dist/createLink.js +53 -60
- package/dist/getBlockMatcher.js +47 -59
- package/dist/getContext.js +106 -143
- package/dist/index.js +10 -71
- package/package.json +13 -13
- package/dist/actions/CallMethod.js +0 -47
- package/dist/actions/JsAction.js +0 -77
- package/dist/actions/Link.js +0 -38
- package/dist/actions/Login.js +0 -43
- package/dist/actions/Logout.js +0 -42
- package/dist/actions/Request.js +0 -65
- package/dist/actions/ResetValidation.js +0 -32
- package/dist/actions/ScrollTo.js +0 -52
- package/dist/actions/SetGlobal.js +0 -35
- package/dist/actions/SetState.js +0 -35
- package/dist/actions/Throw.js +0 -67
- package/dist/actions/Validate.js +0 -37
- package/dist/actions/Wait.js +0 -34
- package/dist/actions/index.js +0 -72
- package/dist/getFieldValues.js +0 -49
- package/dist/makeContextId.js +0 -44
package/dist/Actions.js
CHANGED
|
@@ -1,330 +1,250 @@
|
|
|
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-2022 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 getActionMethods from './actions/getActionMethods.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 , arrayIndices , block , event , progress , responses }) {
|
|
35
|
+
for (const [index, action] of actions.entries()){
|
|
36
|
+
try {
|
|
37
|
+
if (action.async === true) {
|
|
38
|
+
this.callAsyncAction({
|
|
39
|
+
action,
|
|
40
|
+
arrayIndices,
|
|
41
|
+
block,
|
|
42
|
+
event,
|
|
43
|
+
index,
|
|
44
|
+
progress,
|
|
45
|
+
responses
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const response = await this.callAction({
|
|
49
|
+
action,
|
|
50
|
+
arrayIndices,
|
|
51
|
+
block,
|
|
52
|
+
event,
|
|
53
|
+
index,
|
|
54
|
+
progress,
|
|
55
|
+
responses
|
|
56
|
+
});
|
|
57
|
+
responses[action.id] = response;
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
responses[action.id] = error;
|
|
61
|
+
throw {
|
|
62
|
+
error,
|
|
63
|
+
action
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async callActions({ actions , arrayIndices , block , catchActions , event , eventName , progress }) {
|
|
69
|
+
const startTimestamp = new Date();
|
|
70
|
+
const responses = {};
|
|
129
71
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
72
|
+
await this.callActionLoop({
|
|
73
|
+
actions,
|
|
74
|
+
arrayIndices,
|
|
75
|
+
block,
|
|
76
|
+
event,
|
|
77
|
+
responses,
|
|
78
|
+
progress
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(error);
|
|
82
|
+
try {
|
|
83
|
+
await this.callActionLoop({
|
|
84
|
+
actions: catchActions,
|
|
85
|
+
arrayIndices,
|
|
86
|
+
block,
|
|
87
|
+
event,
|
|
88
|
+
responses,
|
|
89
|
+
progress
|
|
90
|
+
});
|
|
91
|
+
} catch (errorCatch) {
|
|
92
|
+
console.error(errorCatch);
|
|
93
|
+
return {
|
|
94
|
+
blockId: block.blockId,
|
|
95
|
+
bounced: false,
|
|
96
|
+
endTimestamp: new Date(),
|
|
97
|
+
error,
|
|
98
|
+
errorCatch,
|
|
99
|
+
event,
|
|
100
|
+
eventName,
|
|
101
|
+
responses,
|
|
102
|
+
startTimestamp,
|
|
103
|
+
success: false
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
blockId: block.blockId,
|
|
108
|
+
bounced: false,
|
|
109
|
+
endTimestamp: new Date(),
|
|
110
|
+
error,
|
|
111
|
+
event,
|
|
112
|
+
eventName,
|
|
113
|
+
responses,
|
|
114
|
+
startTimestamp,
|
|
115
|
+
success: false
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
140
119
|
blockId: block.blockId,
|
|
141
120
|
bounced: false,
|
|
142
121
|
endTimestamp: new Date(),
|
|
143
|
-
error,
|
|
144
|
-
errorCatch,
|
|
145
122
|
event,
|
|
146
123
|
eventName,
|
|
147
124
|
responses,
|
|
148
125
|
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
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
blockId: block.blockId,
|
|
168
|
-
bounced: false,
|
|
169
|
-
endTimestamp: new Date(),
|
|
170
|
-
event,
|
|
171
|
-
eventName,
|
|
172
|
-
responses,
|
|
173
|
-
startTimestamp,
|
|
174
|
-
success: true
|
|
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
|
|
126
|
+
success: true
|
|
197
127
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
|
128
|
+
}
|
|
129
|
+
async callAction({ action , arrayIndices , block , event , index , progress , responses }) {
|
|
130
|
+
if (!this.actions[action.type]) {
|
|
131
|
+
throw {
|
|
132
|
+
error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
|
|
133
|
+
type: action.type,
|
|
134
|
+
index
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const { output: parsedAction , errors: parserErrors } = this.context._internal.parser.parse({
|
|
138
|
+
actions: responses,
|
|
139
|
+
event,
|
|
140
|
+
arrayIndices,
|
|
141
|
+
input: action,
|
|
142
|
+
location: block.blockId
|
|
244
143
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
144
|
+
if (parserErrors.length > 0) {
|
|
145
|
+
throw {
|
|
146
|
+
error: parserErrors[0],
|
|
147
|
+
type: action.type,
|
|
148
|
+
index
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (parsedAction.skip === true) {
|
|
152
|
+
return {
|
|
153
|
+
type: action.type,
|
|
154
|
+
skipped: true,
|
|
155
|
+
index
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const messages = parsedAction.messages || {};
|
|
159
|
+
let response;
|
|
160
|
+
const closeLoading = this.displayMessage({
|
|
161
|
+
defaultMessage: 'Loading',
|
|
162
|
+
duration: 0,
|
|
163
|
+
message: messages.loading,
|
|
164
|
+
status: 'loading'
|
|
261
165
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
166
|
+
try {
|
|
167
|
+
response = await this.actions[action.type]({
|
|
168
|
+
methods: getActionMethods({
|
|
169
|
+
actions: responses,
|
|
170
|
+
arrayIndices,
|
|
171
|
+
blockId: block.blockId,
|
|
172
|
+
context: this.context,
|
|
173
|
+
event
|
|
174
|
+
}),
|
|
175
|
+
document: this.context._internal.lowdefy._internal.document,
|
|
176
|
+
params: parsedAction.params,
|
|
177
|
+
window: this.context._internal.lowdefy._internal.window
|
|
178
|
+
});
|
|
179
|
+
if (progress) {
|
|
180
|
+
progress();
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
responses[action.id] = {
|
|
184
|
+
error,
|
|
185
|
+
index,
|
|
186
|
+
type: action.type
|
|
187
|
+
};
|
|
188
|
+
const { output: parsedMessages , errors: parserErrors } = this.context._internal.parser.parse({
|
|
189
|
+
actions: responses,
|
|
190
|
+
event,
|
|
191
|
+
arrayIndices,
|
|
192
|
+
input: action.messages,
|
|
193
|
+
location: block.blockId
|
|
194
|
+
});
|
|
195
|
+
if (parserErrors.length > 0) {
|
|
196
|
+
// this condition is very unlikely since parser errors usually occur in the first parse.
|
|
197
|
+
throw {
|
|
198
|
+
error: parserErrors[0],
|
|
199
|
+
type: action.type,
|
|
200
|
+
index
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
closeLoading();
|
|
204
|
+
this.displayMessage({
|
|
205
|
+
defaultMessage: error.message,
|
|
206
|
+
duration: 6,
|
|
207
|
+
hideExplicitly: true,
|
|
208
|
+
message: (parsedMessages || {}).error,
|
|
209
|
+
status: 'error'
|
|
210
|
+
});
|
|
211
|
+
throw {
|
|
212
|
+
type: action.type,
|
|
213
|
+
error,
|
|
214
|
+
index
|
|
215
|
+
};
|
|
270
216
|
}
|
|
271
|
-
|
|
272
217
|
closeLoading();
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
hideExplicitly: true,
|
|
278
|
-
message: (parsedMessages || {}).error,
|
|
279
|
-
status: 'error'
|
|
218
|
+
this.displayMessage({
|
|
219
|
+
defaultMessage: 'Success',
|
|
220
|
+
message: messages.success,
|
|
221
|
+
status: 'success'
|
|
280
222
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
index
|
|
223
|
+
return {
|
|
224
|
+
type: action.type,
|
|
225
|
+
response,
|
|
226
|
+
index
|
|
286
227
|
};
|
|
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
228
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
229
|
+
displayMessage({ defaultMessage , duration , hideExplicitly , message , status }) {
|
|
230
|
+
let close = ()=>undefined
|
|
231
|
+
;
|
|
232
|
+
if (hideExplicitly && message !== false || !hideExplicitly && !type.isNone(message)) {
|
|
233
|
+
close = this.context._internal.lowdefy._internal.displayMessage({
|
|
234
|
+
content: type.isString(message) ? message : defaultMessage,
|
|
235
|
+
duration,
|
|
236
|
+
status
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return close;
|
|
240
|
+
}
|
|
241
|
+
constructor(context){
|
|
242
|
+
this.context = context;
|
|
243
|
+
this.callAction = this.callAction.bind(this);
|
|
244
|
+
this.callActionLoop = this.callActionLoop.bind(this);
|
|
245
|
+
this.callActions = this.callActions.bind(this);
|
|
246
|
+
this.displayMessage = this.displayMessage.bind(this);
|
|
247
|
+
this.actions = context._internal.lowdefy._internal.actions;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
export default Actions;
|