@lowdefy/engine 3.23.2 → 4.0.0-alpha.6

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 CHANGED
@@ -1,330 +1,238 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _helpers = require("@lowdefy/helpers");
9
-
10
- var _index = _interopRequireDefault(require("./actions/index.js"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
15
-
16
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
17
-
18
- class Actions {
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
- if (action.async === true) {
73
- _this2.callAsyncAction({
74
- action,
75
- arrayIndices,
76
- block,
77
- event,
78
- index,
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
- responses[action.id] = error;
94
- throw {
95
- error,
96
- action
97
- };
30
+ responses[action.id] = error;
31
+ console.error(error);
98
32
  }
99
- }
100
- })();
101
- }
102
-
103
- callActions(_ref3) {
104
- var _this3 = this;
105
-
106
- return _asyncToGenerator(function* () {
107
- var {
108
- actions,
109
- arrayIndices,
110
- block,
111
- catchActions,
112
- event,
113
- eventName
114
- } = _ref3;
115
- var startTimestamp = new Date();
116
- var responses = {};
117
-
118
- try {
119
- yield _this3.callActionLoop({
120
- actions,
121
- arrayIndices,
122
- block,
123
- event,
124
- responses
125
- });
126
- } catch (error) {
127
- console.error(error);
128
-
33
+ }
34
+ async callActionLoop({ actions: actions1 , arrayIndices , block , event , responses }) {
35
+ for (const [index, action] of actions1.entries()){
36
+ try {
37
+ if (action.async === true) {
38
+ this.callAsyncAction({
39
+ action,
40
+ arrayIndices,
41
+ block,
42
+ event,
43
+ index,
44
+ responses
45
+ });
46
+ } else {
47
+ const response = await this.callAction({
48
+ action,
49
+ arrayIndices,
50
+ block,
51
+ event,
52
+ index,
53
+ responses
54
+ });
55
+ responses[action.id] = response;
56
+ }
57
+ } catch (error) {
58
+ responses[action.id] = error;
59
+ throw {
60
+ error,
61
+ action
62
+ };
63
+ }
64
+ }
65
+ }
66
+ async callActions({ actions: actions2 , arrayIndices , block , catchActions , event , eventName }) {
67
+ const startTimestamp = new Date();
68
+ const responses = {};
129
69
  try {
130
- yield _this3.callActionLoop({
131
- actions: catchActions,
132
- arrayIndices,
133
- block,
134
- event,
135
- responses
136
- });
137
- } catch (errorCatch) {
138
- console.error(errorCatch);
139
- return {
70
+ await this.callActionLoop({
71
+ actions: actions2,
72
+ arrayIndices,
73
+ block,
74
+ event,
75
+ responses
76
+ });
77
+ } catch (error) {
78
+ console.error(error);
79
+ try {
80
+ await this.callActionLoop({
81
+ actions: catchActions,
82
+ arrayIndices,
83
+ block,
84
+ event,
85
+ responses
86
+ });
87
+ } catch (errorCatch) {
88
+ console.error(errorCatch);
89
+ return {
90
+ blockId: block.blockId,
91
+ bounced: false,
92
+ endTimestamp: new Date(),
93
+ error,
94
+ errorCatch,
95
+ event,
96
+ eventName,
97
+ responses,
98
+ startTimestamp,
99
+ success: false
100
+ };
101
+ }
102
+ return {
103
+ blockId: block.blockId,
104
+ bounced: false,
105
+ endTimestamp: new Date(),
106
+ error,
107
+ event,
108
+ eventName,
109
+ responses,
110
+ startTimestamp,
111
+ success: false
112
+ };
113
+ }
114
+ return {
140
115
  blockId: block.blockId,
141
116
  bounced: false,
142
117
  endTimestamp: new Date(),
143
- error,
144
- errorCatch,
145
118
  event,
146
119
  eventName,
147
120
  responses,
148
121
  startTimestamp,
149
- success: false
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
122
+ success: true
197
123
  };
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
124
+ }
125
+ async callAction({ action , arrayIndices , block , event , index , responses }) {
126
+ if (!actions[action.type]) {
127
+ throw {
128
+ error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
129
+ type: action.type,
130
+ index
131
+ };
132
+ }
133
+ const { output: parsedAction , errors: parserErrors } = this.context._internal.parser.parse({
134
+ actions: responses,
135
+ event,
136
+ arrayIndices,
137
+ input: action,
138
+ location: block.blockId
244
139
  });
245
- } catch (error) {
246
- responses[action.id] = {
247
- error,
248
- index,
249
- type: action.type
250
- };
251
-
252
- var {
253
- output: parsedMessages,
254
- errors: _parserErrors
255
- } = _this4.context.parser.parse({
256
- actions: responses,
257
- event,
258
- arrayIndices,
259
- input: action.messages,
260
- location: block.blockId
140
+ if (parserErrors.length > 0) {
141
+ throw {
142
+ error: parserErrors[0],
143
+ type: action.type,
144
+ index
145
+ };
146
+ }
147
+ if (parsedAction.skip === true) {
148
+ return {
149
+ type: action.type,
150
+ skipped: true,
151
+ index
152
+ };
153
+ }
154
+ const messages = parsedAction.messages || {};
155
+ let response;
156
+ const closeLoading = this.displayMessage({
157
+ defaultMessage: 'Loading',
158
+ duration: 0,
159
+ message: messages.loading,
160
+ status: 'loading'
261
161
  });
262
-
263
- if (_parserErrors.length > 0) {
264
- // this condition is very unlikely since parser errors usually occur in the first parse.
265
- throw {
266
- error: _parserErrors[0],
267
- type: action.type,
268
- index
269
- };
162
+ try {
163
+ response = await actions[action.type]({
164
+ arrayIndices,
165
+ blockId: block.blockId,
166
+ context: this.context,
167
+ event,
168
+ params: parsedAction.params
169
+ });
170
+ } catch (error) {
171
+ responses[action.id] = {
172
+ error,
173
+ index,
174
+ type: action.type
175
+ };
176
+ const { output: parsedMessages , errors: parserErrors } = this.context._internal.parser.parse({
177
+ actions: responses,
178
+ event,
179
+ arrayIndices,
180
+ input: action.messages,
181
+ location: block.blockId
182
+ });
183
+ if (parserErrors.length > 0) {
184
+ // this condition is very unlikely since parser errors usually occur in the first parse.
185
+ throw {
186
+ error: parserErrors[0],
187
+ type: action.type,
188
+ index
189
+ };
190
+ }
191
+ closeLoading();
192
+ this.displayMessage({
193
+ defaultMessage: error.message,
194
+ duration: 6,
195
+ hideExplicitly: true,
196
+ message: (parsedMessages || {}).error,
197
+ status: 'error'
198
+ });
199
+ throw {
200
+ type: action.type,
201
+ error,
202
+ index
203
+ };
270
204
  }
271
-
272
205
  closeLoading();
273
-
274
- _this4.displayMessage({
275
- defaultMessage: error.message,
276
- duration: 6,
277
- hideExplicitly: true,
278
- message: (parsedMessages || {}).error,
279
- status: 'error'
206
+ this.displayMessage({
207
+ defaultMessage: 'Success',
208
+ message: messages.success,
209
+ status: 'success'
280
210
  });
281
-
282
- throw {
283
- type: action.type,
284
- error,
285
- index
211
+ return {
212
+ type: action.type,
213
+ response,
214
+ index
286
215
  };
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
216
  }
323
-
324
- return close;
325
- }
326
-
327
- }
328
-
329
- var _default = Actions;
330
- exports.default = _default;
217
+ displayMessage({ defaultMessage , duration , hideExplicitly , message , status }) {
218
+ let close = ()=>undefined
219
+ ;
220
+ if (hideExplicitly && message !== false || !hideExplicitly && !type.isNone(message)) {
221
+ close = this.context._internal.lowdefy._internal.displayMessage({
222
+ content: type.isString(message) ? message : defaultMessage,
223
+ duration,
224
+ status
225
+ });
226
+ }
227
+ return close;
228
+ }
229
+ constructor(context){
230
+ this.context = context;
231
+ this.callAction = this.callAction.bind(this);
232
+ this.callActionLoop = this.callActionLoop.bind(this);
233
+ this.callActions = this.callActions.bind(this);
234
+ this.displayMessage = this.displayMessage.bind(this);
235
+ this.actions = actions;
236
+ }
237
+ };
238
+ export default Actions;