@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.
Files changed (49) hide show
  1. package/dist/Actions.js +229 -309
  2. package/dist/Blocks.js +560 -608
  3. package/dist/Events.js +119 -163
  4. package/dist/Requests.js +105 -144
  5. package/dist/State.js +56 -82
  6. package/dist/actions/createCallMethod.js +29 -0
  7. package/dist/actions/{Reset.js → createDisplayMessage.js} +6 -21
  8. package/dist/actions/createGetActions.js +27 -0
  9. package/dist/actions/createGetBlockId.js +20 -0
  10. package/dist/actions/createGetEvent.js +27 -0
  11. package/dist/actions/createGetGlobal.js +27 -0
  12. package/dist/actions/createGetInput.js +27 -0
  13. package/dist/actions/createGetPageId.js +20 -0
  14. package/dist/actions/createGetRequestDetails.js +27 -0
  15. package/dist/actions/{Message.js → createGetState.js} +13 -23
  16. package/dist/actions/createGetUrlQuery.js +27 -0
  17. package/dist/actions/createGetUser.js +27 -0
  18. package/dist/actions/createLink.js +20 -0
  19. package/dist/actions/createLogin.js +20 -0
  20. package/dist/actions/createLogout.js +20 -0
  21. package/dist/actions/createRequest.js +25 -0
  22. package/dist/actions/createReset.js +23 -0
  23. package/dist/actions/createResetValidation.js +21 -0
  24. package/dist/actions/createSetGlobal.js +25 -0
  25. package/dist/actions/createSetState.js +25 -0
  26. package/dist/actions/createValidate.js +25 -0
  27. package/dist/actions/getActionMethods.js +61 -0
  28. package/dist/actions/getFromObject.js +42 -0
  29. package/dist/createLink.js +53 -60
  30. package/dist/getBlockMatcher.js +47 -59
  31. package/dist/getContext.js +106 -143
  32. package/dist/index.js +10 -71
  33. package/package.json +13 -13
  34. package/dist/actions/CallMethod.js +0 -47
  35. package/dist/actions/JsAction.js +0 -77
  36. package/dist/actions/Link.js +0 -38
  37. package/dist/actions/Login.js +0 -43
  38. package/dist/actions/Logout.js +0 -42
  39. package/dist/actions/Request.js +0 -65
  40. package/dist/actions/ResetValidation.js +0 -32
  41. package/dist/actions/ScrollTo.js +0 -52
  42. package/dist/actions/SetGlobal.js +0 -35
  43. package/dist/actions/SetState.js +0 -35
  44. package/dist/actions/Throw.js +0 -67
  45. package/dist/actions/Validate.js +0 -37
  46. package/dist/actions/Wait.js +0 -34
  47. package/dist/actions/index.js +0 -72
  48. package/dist/getFieldValues.js +0 -49
  49. package/dist/makeContextId.js +0 -44
package/dist/Events.js CHANGED
@@ -1,166 +1,122 @@
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
- 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); } }
11
-
12
- 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); }); }; }
13
-
14
- class Events {
15
- constructor(_ref) {
16
- var {
17
- arrayIndices,
18
- block,
19
- context
20
- } = _ref;
21
- this.defaultDebounceMs = 300;
22
- this.events = {};
23
- this.timeouts = {};
24
- this.arrayIndices = arrayIndices;
25
- this.block = block;
26
- this.context = context;
27
- this.init = this.init.bind(this);
28
- this.triggerEvent = this.triggerEvent.bind(this);
29
- this.registerEvent = this.registerEvent.bind(this);
30
- this.initEvent = this.initEvent.bind(this);
31
- this.init();
32
- }
33
-
34
- initEvent(actions) {
35
- return {
36
- actions: (_helpers.type.isObject(actions) ? actions.try : actions) || [],
37
- catchActions: (_helpers.type.isObject(actions) ? actions.catch : []) || [],
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,
94
- event,
95
- eventName: name
96
- });
97
- eventDescription.history.unshift(res);
98
-
99
- _this.context.eventLog.unshift(res);
100
-
101
- eventDescription.loading = false;
102
- _this.block.update = true;
103
-
104
- _this.context.update();
105
-
106
- return res;
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
+ 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]);
107
29
  });
108
-
109
- return function actionHandle() {
110
- return _ref4.apply(this, arguments);
30
+ }
31
+ registerEvent({ name , actions }) {
32
+ this.events[name] = this.initEvent(actions);
33
+ }
34
+ async triggerEvent({ name , event , progress }) {
35
+ const eventDescription = this.events[name];
36
+ let result = {
37
+ blockId: this.block.blockId,
38
+ event,
39
+ eventName: name,
40
+ responses: {},
41
+ endTimestamp: new Date(),
42
+ startTimestamp: new Date(),
43
+ success: true,
44
+ bounced: false
111
45
  };
112
- }(); // no debounce
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);
46
+ // no event
47
+ if (type.isUndefined(eventDescription)) {
48
+ return result;
49
+ }
50
+ eventDescription.loading = true;
51
+ this.block.update = true;
52
+ this.context._internal.update();
53
+ const actionHandle = async ()=>{
54
+ const res = await this.context._internal.Actions.callActions({
55
+ actions: eventDescription.actions,
56
+ arrayIndices: this.arrayIndices,
57
+ block: this.block,
58
+ catchActions: eventDescription.catchActions,
59
+ event,
60
+ eventName: name,
61
+ progress
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;
158
69
  };
159
- });
160
- })();
161
- }
162
-
163
- }
164
-
165
- var _default = Events;
166
- exports.default = _default;
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[name] && 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[name] = setTimeout(()=>{
85
+ this.timeouts[name] = 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
+ };
106
+ });
107
+ }
108
+ constructor({ arrayIndices , block , context }){
109
+ this.defaultDebounceMs = 300;
110
+ this.events = {};
111
+ this.timeouts = {};
112
+ this.arrayIndices = arrayIndices;
113
+ this.block = block;
114
+ this.context = context;
115
+ this.init = this.init.bind(this);
116
+ this.triggerEvent = this.triggerEvent.bind(this);
117
+ this.registerEvent = this.registerEvent.bind(this);
118
+ this.initEvent = this.initEvent.bind(this);
119
+ this.init();
120
+ }
121
+ };
122
+ export default Events;
package/dist/Requests.js CHANGED
@@ -1,147 +1,108 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
-
10
- var _helpers = require("@lowdefy/helpers");
11
-
12
- var _templateObject;
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- 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); } }
17
-
18
- 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); }); }; }
19
-
20
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
21
-
22
- var CALL_REQUEST = (0, _graphqlTag.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query callRequest($input: RequestInput!) {\n request(input: $input) {\n id\n type\n success\n response\n }\n }\n"])));
23
-
24
- class Requests {
25
- constructor(context) {
26
- this.context = context;
27
- this.requestList = this.context.rootBlock.requests || [];
28
- this.callRequests = this.callRequests.bind(this);
29
- this.callRequest = this.callRequest.bind(this);
30
- this.fetch = this.fetch.bind(this);
31
- }
32
-
33
- callRequests() {
34
- var {
35
- requestIds,
36
- event,
37
- arrayIndices
38
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
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-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 { get, serializer, type } from '@lowdefy/helpers';
16
+ let Requests = class Requests {
17
+ callRequests({ actions , arrayIndices , event , params } = {}) {
18
+ if (type.isObject(params) && params.all === true) {
19
+ return Promise.all(Object.keys(this.requestConfig).map((requestId)=>this.callRequest({
20
+ requestId,
21
+ event,
22
+ arrayIndices
23
+ })
24
+ ));
25
+ }
26
+ let requestIds = [];
27
+ if (type.isString(params)) requestIds = [
28
+ params
29
+ ];
30
+ if (type.isArray(params)) requestIds = params;
31
+ return Promise.all(requestIds.map((requestId)=>this.callRequest({
32
+ actions,
33
+ requestId,
34
+ event,
35
+ arrayIndices
36
+ })
37
+ ));
46
38
  }
47
-
48
- return Promise.all(requestIds.map(requestId => this.callRequest({
49
- requestId,
50
- event,
51
- arrayIndices
52
- })));
53
- }
54
-
55
- callRequest(_ref) {
56
- var {
57
- requestId,
58
- event,
59
- arrayIndices
60
- } = _ref;
61
-
62
- if (!this.context.requests[requestId]) {
63
- var request = this.requestList.find(req => req.requestId === requestId);
64
-
65
- if (!request) {
66
- this.context.requests[requestId] = {
67
- loading: false,
68
- response: null,
69
- error: [new Error("Configuration Error: Request ".concat(requestId, " not defined on context."))]
70
- };
71
- return Promise.reject(new Error("Configuration Error: Request ".concat(requestId, " not defined on context.")));
72
- }
73
-
74
- this.context.requests[requestId] = {
75
- loading: true,
76
- response: null,
77
- error: []
78
- };
39
+ callRequest({ actions , arrayIndices , event , requestId }) {
40
+ const request = this.requestConfig[requestId];
41
+ if (!request) {
42
+ const error = new Error(`Configuration Error: Request ${requestId} not defined on page.`);
43
+ this.context.requests[requestId] = {
44
+ loading: false,
45
+ response: null,
46
+ error: [
47
+ error
48
+ ]
49
+ };
50
+ return Promise.reject(error);
51
+ }
52
+ if (!this.context.requests[requestId]) {
53
+ this.context.requests[requestId] = {
54
+ loading: true,
55
+ response: null,
56
+ error: []
57
+ };
58
+ }
59
+ const { output: payload , errors: parserErrors } = this.context._internal.parser.parse({
60
+ actions,
61
+ event,
62
+ arrayIndices,
63
+ input: request.payload,
64
+ location: requestId
65
+ });
66
+ // TODO: We are throwing this error differently to the request does not exist error
67
+ if (parserErrors.length > 0) {
68
+ throw parserErrors[0];
69
+ }
70
+ return this.fetch({
71
+ requestId,
72
+ payload
73
+ });
79
74
  }
80
-
81
- return this.fetch({
82
- requestId,
83
- event,
84
- arrayIndices
85
- });
86
- }
87
-
88
- fetch(_ref2) {
89
- var _this = this;
90
-
91
- return _asyncToGenerator(function* () {
92
- var {
93
- requestId,
94
- event,
95
- arrayIndices
96
- } = _ref2;
97
- _this.context.requests[requestId].loading = true;
98
-
99
- if (_this.context.RootBlocks) {
100
- _this.context.RootBlocks.setBlocksLoadingCache();
101
- }
102
-
103
- try {
104
- var gqlResponse = yield _this.context.lowdefy.client.query({
105
- query: CALL_REQUEST,
106
- fetchPolicy: 'network-only',
107
- variables: {
108
- input: {
109
- arrayIndices,
110
- requestId,
111
- blockId: _this.context.blockId,
112
- event: _helpers.serializer.serialize(event) || {},
113
- input: _helpers.serializer.serialize(_this.context.lowdefy.inputs[_this.context.id]),
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
- }
75
+ async fetch({ requestId , payload }) {
76
+ this.context.requests[requestId].loading = true;
77
+ try {
78
+ const response = await this.context._internal.lowdefy._internal.callRequest({
79
+ pageId: this.context.pageId,
80
+ payload: serializer.serialize(payload),
81
+ requestId
82
+ });
83
+ const deserializedResponse = serializer.deserialize(get(response, 'response', {
84
+ default: null
85
+ }));
86
+ this.context.requests[requestId].response = deserializedResponse;
87
+ this.context.requests[requestId].loading = false;
88
+ this.context._internal.update();
89
+ return deserializedResponse;
90
+ } catch (error) {
91
+ this.context.requests[requestId].error.unshift(error);
92
+ this.context.requests[requestId].loading = false;
93
+ this.context._internal.update();
94
+ throw error;
95
+ }
96
+ }
97
+ constructor(context){
98
+ this.context = context;
99
+ this.callRequests = this.callRequests.bind(this);
100
+ this.callRequest = this.callRequest.bind(this);
101
+ this.fetch = this.fetch.bind(this);
102
+ this.requestConfig = {};
103
+ (this.context._internal.rootBlock.requests || []).forEach((request)=>{
104
+ this.requestConfig[request.requestId] = request;
120
105
  });
121
-
122
- var response = _helpers.serializer.deserialize((0, _helpers.get)(gqlResponse, 'data.request.response', {
123
- default: null
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;
106
+ }
107
+ };
108
+ export default Requests;