@lowdefy/engine 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (34) hide show
  1. package/dist/Actions.js +18 -13
  2. package/dist/Requests.js +1 -1
  3. package/dist/actions/createCallMethod.js +29 -0
  4. package/dist/actions/{Request.js → createDisplayMessage.js} +5 -8
  5. package/dist/actions/createGetActions.js +27 -0
  6. package/dist/actions/{Logout.js → createGetBlockId.js} +5 -3
  7. package/dist/actions/createGetEvent.js +27 -0
  8. package/dist/actions/createGetGlobal.js +27 -0
  9. package/dist/actions/createGetInput.js +27 -0
  10. package/dist/actions/{Login.js → createGetPageId.js} +5 -3
  11. package/dist/actions/createGetRequestDetails.js +27 -0
  12. package/dist/actions/createGetState.js +27 -0
  13. package/dist/actions/createGetUrlQuery.js +27 -0
  14. package/dist/actions/createGetUser.js +27 -0
  15. package/dist/actions/createLink.js +20 -0
  16. package/dist/actions/createLogin.js +20 -0
  17. package/dist/actions/createLogout.js +20 -0
  18. package/dist/actions/{Message.js → createRequest.js} +10 -8
  19. package/dist/actions/{Reset.js → createReset.js} +7 -5
  20. package/dist/actions/{ResetValidation.js → createResetValidation.js} +5 -3
  21. package/dist/actions/{SetGlobal.js → createSetGlobal.js} +10 -8
  22. package/dist/actions/{SetState.js → createSetState.js} +9 -7
  23. package/dist/actions/{Validate.js → createValidate.js} +9 -7
  24. package/dist/actions/getActionMethods.js +61 -0
  25. package/dist/actions/getFromObject.js +42 -0
  26. package/dist/createLink.js +45 -22
  27. package/package.json +7 -6
  28. package/dist/actions/CallMethod.js +0 -28
  29. package/dist/actions/JsAction.js +0 -54
  30. package/dist/actions/Link.js +0 -27
  31. package/dist/actions/ScrollTo.js +0 -25
  32. package/dist/actions/Throw.js +0 -39
  33. package/dist/actions/Wait.js +0 -22
  34. package/dist/actions/index.js +0 -46
package/dist/Actions.js CHANGED
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- import actions from './actions/index.js';
16
+ import getActionMethods from './actions/getActionMethods.js';
17
17
  let Actions = class Actions {
18
18
  async callAsyncAction({ action , arrayIndices , block , event , index , responses }) {
19
19
  try {
@@ -31,8 +31,8 @@ let Actions = class Actions {
31
31
  console.error(error);
32
32
  }
33
33
  }
34
- async callActionLoop({ actions: actions1 , arrayIndices , block , event , responses }) {
35
- for (const [index, action] of actions1.entries()){
34
+ async callActionLoop({ actions , arrayIndices , block , event , responses }) {
35
+ for (const [index, action] of actions.entries()){
36
36
  try {
37
37
  if (action.async === true) {
38
38
  this.callAsyncAction({
@@ -63,12 +63,12 @@ let Actions = class Actions {
63
63
  }
64
64
  }
65
65
  }
66
- async callActions({ actions: actions2 , arrayIndices , block , catchActions , event , eventName }) {
66
+ async callActions({ actions , arrayIndices , block , catchActions , event , eventName }) {
67
67
  const startTimestamp = new Date();
68
68
  const responses = {};
69
69
  try {
70
70
  await this.callActionLoop({
71
- actions: actions2,
71
+ actions,
72
72
  arrayIndices,
73
73
  block,
74
74
  event,
@@ -123,7 +123,7 @@ let Actions = class Actions {
123
123
  };
124
124
  }
125
125
  async callAction({ action , arrayIndices , block , event , index , responses }) {
126
- if (!actions[action.type]) {
126
+ if (!this.actions[action.type]) {
127
127
  throw {
128
128
  error: new Error(`Invalid action type "${action.type}" at "${block.blockId}".`),
129
129
  type: action.type,
@@ -160,12 +160,17 @@ let Actions = class Actions {
160
160
  status: 'loading'
161
161
  });
162
162
  try {
163
- response = await actions[action.type]({
164
- arrayIndices,
165
- blockId: block.blockId,
166
- context: this.context,
167
- event,
168
- params: parsedAction.params
163
+ response = await this.actions[action.type]({
164
+ methods: getActionMethods({
165
+ actions: responses,
166
+ arrayIndices,
167
+ blockId: block.blockId,
168
+ context: this.context,
169
+ event
170
+ }),
171
+ document: this.context._internal.lowdefy._internal.document,
172
+ params: parsedAction.params,
173
+ window: this.context._internal.lowdefy._internal.window
169
174
  });
170
175
  } catch (error) {
171
176
  responses[action.id] = {
@@ -232,7 +237,7 @@ let Actions = class Actions {
232
237
  this.callActionLoop = this.callActionLoop.bind(this);
233
238
  this.callActions = this.callActions.bind(this);
234
239
  this.displayMessage = this.displayMessage.bind(this);
235
- this.actions = actions;
240
+ this.actions = context._internal.lowdefy._internal.actions;
236
241
  }
237
242
  };
238
243
  export default Actions;
package/dist/Requests.js CHANGED
@@ -15,7 +15,7 @@
15
15
  */ import { get, serializer, type } from '@lowdefy/helpers';
16
16
  let Requests = class Requests {
17
17
  callRequests({ actions , arrayIndices , event , params } = {}) {
18
- if (params.all === true) {
18
+ if (type.isObject(params) && params.all === true) {
19
19
  return Promise.all(Object.keys(this.requestConfig).map((requestId)=>this.callRequest({
20
20
  requestId,
21
21
  event,
@@ -0,0 +1,29 @@
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 { applyArrayIndices, type } from '@lowdefy/helpers';
16
+ function createCallMethod({ arrayIndices , context }) {
17
+ return function callMethod(params) {
18
+ const { blockId , method , args =[] } = params;
19
+ const blockMethod = context._internal.RootBlocks.map[applyArrayIndices(arrayIndices, blockId)].methods[method];
20
+ if (!type.isArray(args)) {
21
+ throw new Error(`Failed to call method "${method}" on block "${blockId}": "args" should be an array. Received "${JSON.stringify(params)}".`);
22
+ }
23
+ if (!type.isFunction(blockMethod)) {
24
+ throw new Error(`Failed to call method "${method}" on block "${blockId}". Check if "${method}" is a valid block method for block "${blockId}". Received "${JSON.stringify(params)}".`);
25
+ }
26
+ return blockMethod(...args);
27
+ };
28
+ }
29
+ export default createCallMethod;
@@ -12,12 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ async function Request({ actions , arrayIndices , context , event , params }) {
16
- return context._internal.Requests.callRequests({
17
- actions,
18
- arrayIndices,
19
- event,
20
- params
21
- });
15
+ */ function createDisplayMessage({ context }) {
16
+ return function displayMessage(params = {}) {
17
+ context._internal.lowdefy._internal.displayMessage(params);
18
+ };
22
19
  }
23
- export default Request;
20
+ export default createDisplayMessage;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetActions({ actions , arrayIndices , blockId }) {
17
+ return function getActions(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: actions,
22
+ method: 'getActions',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetActions;
@@ -12,7 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ async function Logout({ context }) {
16
- return context._internal.lowdefy._internal.auth.logout();
15
+ */ function createGetBlockId({ blockId }) {
16
+ return function getBlockId() {
17
+ return blockId;
18
+ };
17
19
  }
18
- export default Logout;
20
+ export default createGetBlockId;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetEvent({ arrayIndices , blockId , event }) {
17
+ return function getEvent(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: event,
22
+ method: 'getEvent',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetEvent;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetGlobal({ arrayIndices , blockId , context }) {
17
+ return function getGlobal(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context._internal.lowdefy.lowdefyGlobal,
22
+ method: 'getGlobal',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetGlobal;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetInput({ arrayIndices , blockId , context }) {
17
+ return function getInput(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context._internal.lowdefy.inputs[context.id],
22
+ method: 'getInput',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetInput;
@@ -12,7 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ async function Login({ context , params }) {
16
- return context._internal.lowdefy._internal.auth.login(params);
15
+ */ function createGetPageId({ context }) {
16
+ return function getPageId() {
17
+ return context.pageId;
18
+ };
17
19
  }
18
- export default Login;
20
+ export default createGetPageId;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ const createGetRequestDetails = ({ arrayIndices , blockId , context })=>{
17
+ return function getRequestDetails(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context.requests,
22
+ method: 'getRequestDetails',
23
+ params
24
+ });
25
+ };
26
+ };
27
+ export default createGetRequestDetails;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetState({ arrayIndices , blockId , context }) {
17
+ return function getState(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context.state,
22
+ method: 'getState',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetState;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetUrlQuery({ arrayIndices , blockId , context }) {
17
+ return function getUrlQuery(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context._internal.lowdefy.urlQuery,
22
+ method: 'getUrlQuery',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetUrlQuery;
@@ -0,0 +1,27 @@
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 getFromObject from './getFromObject.js';
16
+ function createGetUser({ arrayIndices , blockId , context }) {
17
+ return function getUser(params) {
18
+ return getFromObject({
19
+ arrayIndices,
20
+ location: blockId,
21
+ object: context._internal.lowdefy.user,
22
+ method: 'getUser',
23
+ params
24
+ });
25
+ };
26
+ }
27
+ export default createGetUser;
@@ -0,0 +1,20 @@
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
+ */ function createLink({ context }) {
16
+ return function link(params) {
17
+ context._internal.lowdefy._internal.link(params);
18
+ };
19
+ }
20
+ export default createLink;
@@ -0,0 +1,20 @@
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
+ */ function createLogin({ context }) {
16
+ return function login(params) {
17
+ return context._internal.lowdefy._internal.auth.login(params);
18
+ };
19
+ }
20
+ export default createLogin;
@@ -0,0 +1,20 @@
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
+ */ function createLogout({ context }) {
16
+ return function logout() {
17
+ return context._internal.lowdefy._internal.auth.logout();
18
+ };
19
+ }
20
+ export default createLogout;
@@ -12,12 +12,14 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function Message({ context , params ={} }) {
16
- context._internal.lowdefy._internal.displayMessage({
17
- content: params.content || 'Success',
18
- duration: params.duration,
19
- icon: params.icon,
20
- status: params.status
21
- });
15
+ */ function createRequest({ actions , arrayIndices , context , event }) {
16
+ return async function request(params) {
17
+ return await context._internal.Requests.callRequests({
18
+ actions,
19
+ arrayIndices,
20
+ event,
21
+ params
22
+ });
23
+ };
22
24
  }
23
- export default Message;
25
+ export default createRequest;
@@ -13,9 +13,11 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { serializer } from '@lowdefy/helpers';
16
- function Reset({ context }) {
17
- context._internal.State.resetState();
18
- context._internal.RootBlocks.reset(serializer.deserializeFromString(context._internal.State.frozenState));
19
- context._internal.update();
16
+ function createReset({ context }) {
17
+ return function reset() {
18
+ context._internal.State.resetState();
19
+ context._internal.RootBlocks.reset(serializer.deserializeFromString(context._internal.State.frozenState));
20
+ context._internal.update();
21
+ };
20
22
  }
21
- export default Reset;
23
+ export default createReset;
@@ -13,7 +13,9 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import getBlockMatcher from '../getBlockMatcher.js';
16
- async function ResetValidation({ context , params }) {
17
- context._internal.RootBlocks.resetValidation(getBlockMatcher(params));
16
+ function createResetValidation({ context }) {
17
+ return function resetValidation(params) {
18
+ context._internal.RootBlocks.resetValidation(getBlockMatcher(params));
19
+ };
18
20
  }
19
- export default ResetValidation;
21
+ export default createResetValidation;
@@ -13,11 +13,13 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices, set } from '@lowdefy/helpers';
16
- async function SetGlobal({ arrayIndices , context , params }) {
17
- Object.keys(params).forEach((key)=>{
18
- set(context._internal.lowdefy.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
19
- });
20
- context._internal.RootBlocks.reset();
21
- context._internal.update();
22
- }
23
- export default SetGlobal;
16
+ const createSetGlobal = ({ arrayIndices , context })=>{
17
+ return function setGlobal(params) {
18
+ Object.keys(params).forEach((key)=>{
19
+ set(context._internal.lowdefy._internal.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
20
+ });
21
+ context._internal.RootBlocks.reset();
22
+ context._internal.update();
23
+ };
24
+ };
25
+ export default createSetGlobal;
@@ -13,11 +13,13 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { applyArrayIndices } from '@lowdefy/helpers';
16
- async function SetState({ arrayIndices , context , params }) {
17
- Object.keys(params).forEach((key)=>{
18
- context._internal.State.set(applyArrayIndices(arrayIndices, key), params[key]);
19
- });
20
- context._internal.RootBlocks.reset();
21
- context._internal.update();
16
+ function createSetState({ arrayIndices , context }) {
17
+ return function setState(params) {
18
+ Object.keys(params).forEach((key)=>{
19
+ context._internal.State.set(applyArrayIndices(arrayIndices, key), params[key]);
20
+ });
21
+ context._internal.RootBlocks.reset();
22
+ context._internal.update();
23
+ };
22
24
  }
23
- export default SetState;
25
+ export default createSetState;
@@ -13,11 +13,13 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import getBlockMatcher from '../getBlockMatcher.js';
16
- async function Validate({ context , params }) {
17
- const validationErrors = context.RootBlocks.validate(getBlockMatcher(params));
18
- if (validationErrors.length > 0) {
19
- const error = new Error(`Your input has ${validationErrors.length} validation error${validationErrors.length !== 1 ? 's' : ''}.`);
20
- throw error;
21
- }
16
+ function createValidate({ context }) {
17
+ return function validate(params) {
18
+ const validationErrors = context._internal.RootBlocks.validate(getBlockMatcher(params));
19
+ if (validationErrors.length > 0) {
20
+ const error = new Error(`Your input has ${validationErrors.length} validation error${validationErrors.length !== 1 ? 's' : ''}.`);
21
+ throw error;
22
+ }
23
+ };
22
24
  }
23
- export default Validate;
25
+ export default createValidate;
@@ -0,0 +1,61 @@
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 createCallMethod from './createCallMethod.js';
16
+ import createGetActions from './createGetActions.js';
17
+ import createGetBlockId from './createGetBlockId.js';
18
+ import createGetEvent from './createGetEvent.js';
19
+ import createGetGlobal from './createGetGlobal.js';
20
+ import createGetInput from './createGetInput.js';
21
+ import createGetPageId from './createGetPageId.js';
22
+ import createGetRequestDetails from './createGetRequestDetails.js';
23
+ import createGetState from './createGetState.js';
24
+ import createGetUrlQuery from './createGetUrlQuery.js';
25
+ import createGetUser from './createGetUser.js';
26
+ import createLink from './createLink.js';
27
+ import createLogin from './createLogin.js';
28
+ import createLogout from './createLogout.js';
29
+ import createDisplayMessage from './createDisplayMessage.js';
30
+ import createRequest from './createRequest.js';
31
+ import createReset from './createReset.js';
32
+ import createResetValidation from './createResetValidation.js';
33
+ import createSetGlobal from './createSetGlobal.js';
34
+ import createSetState from './createSetState.js';
35
+ import createValidate from './createValidate.js';
36
+ function getActionMethods(props) {
37
+ return {
38
+ callMethod: createCallMethod(props),
39
+ displayMessage: createDisplayMessage(props),
40
+ getActions: createGetActions(props),
41
+ getBlockId: createGetBlockId(props),
42
+ getEvent: createGetEvent(props),
43
+ getGlobal: createGetGlobal(props),
44
+ getInput: createGetInput(props),
45
+ getPageId: createGetPageId(props),
46
+ getRequestDetails: createGetRequestDetails(props),
47
+ getState: createGetState(props),
48
+ getUrlQuery: createGetUrlQuery(props),
49
+ getUser: createGetUser(props),
50
+ link: createLink(props),
51
+ login: createLogin(props),
52
+ logout: createLogout(props),
53
+ request: createRequest(props),
54
+ reset: createReset(props),
55
+ resetValidation: createResetValidation(props),
56
+ setGlobal: createSetGlobal(props),
57
+ setState: createSetState(props),
58
+ validate: createValidate(props)
59
+ };
60
+ }
61
+ export default getActionMethods;
@@ -0,0 +1,42 @@
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 { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
16
+ const getFromObject = ({ arrayIndices , location , method , object , params })=>{
17
+ if (params === true) params = {
18
+ all: true
19
+ };
20
+ if (type.isString(params) || type.isInt(params)) params = {
21
+ key: params
22
+ };
23
+ if (!type.isObject(params)) {
24
+ throw new Error(`Method Error: ${method} params must be of type string, integer, boolean or object. Received: ${JSON.stringify(params)} at ${location}.`);
25
+ }
26
+ if (params.key === null) return get(params, 'default', {
27
+ default: null,
28
+ copy: true
29
+ });
30
+ if (params.all === true) return serializer.copy(object);
31
+ if (!type.isString(params.key) && !type.isInt(params.key)) {
32
+ throw new Error(`Method Error: ${method} params.key must be of type string or integer. Received: ${JSON.stringify(params)} at ${location}.`);
33
+ }
34
+ return get(object, applyArrayIndices(arrayIndices, params.key), {
35
+ default: get(params, 'default', {
36
+ default: null,
37
+ copy: true
38
+ }),
39
+ copy: true
40
+ });
41
+ };
42
+ export default getFromObject;
@@ -13,32 +13,55 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
- function createLink({ backLink , lowdefy , newOriginLink , sameOriginLink }) {
17
- function link({ back , home , input , newTab , pageId , url , urlQuery }) {
18
- let pathname = pageId;
19
- if (back) {
20
- return backLink();
16
+ function createLink({ backLink , disabledLink , lowdefy , newOriginLink , noLink , sameOriginLink }) {
17
+ function link(props) {
18
+ if (props.disabled === true) {
19
+ return disabledLink(props);
21
20
  }
22
- const lowdefyUrlQuery = type.isNone(urlQuery) ? '' : `?${urlQueryFn.stringify(urlQuery)}`;
23
- if (home) {
24
- if (lowdefy.home.configured) {
25
- pathname = '';
26
- pageId = lowdefy.home.pageId;
27
- } else {
28
- pathname = lowdefy.home.pageId;
29
- pageId = lowdefy.home.pageId;
30
- }
21
+ if ([
22
+ !props.pageId,
23
+ !props.back,
24
+ !props.home,
25
+ !props.url
26
+ ].filter((v)=>!v
27
+ ).length > 1) {
28
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'back', 'home', 'pageId' or 'url' can be defined.`);
31
29
  }
32
- if (!type.isNone(pathname)) {
33
- if (!type.isNone(input)) {
34
- lowdefy.inputs[pageId] = input;
35
- }
36
- return sameOriginLink(`/${pathname}${lowdefyUrlQuery}`, newTab);
30
+ if (props.back === true) {
31
+ // Cannot set input or urlQuery on back
32
+ return backLink(props);
37
33
  }
38
- if (!type.isNone(url)) {
39
- return newOriginLink(`${url}${lowdefyUrlQuery}`, newTab);
34
+ const query = type.isNone(props.urlQuery) ? '' : `${urlQueryFn.stringify(props.urlQuery)}`;
35
+ if (props.home === true) {
36
+ const pathname = `/${lowdefy.home.configured ? '' : lowdefy.home.pageId}`;
37
+ return sameOriginLink({
38
+ ...props,
39
+ pathname,
40
+ query,
41
+ setInput: ()=>{
42
+ lowdefy.inputs[`page:${lowdefy.home.pageId}`] = props.input || {};
43
+ }
44
+ });
40
45
  }
41
- throw new Error(`Invalid Link.`);
46
+ if (type.isString(props.pageId)) {
47
+ return sameOriginLink({
48
+ ...props,
49
+ pathname: `/${props.pageId}`,
50
+ query,
51
+ setInput: ()=>{
52
+ lowdefy.inputs[`page:${props.pageId}`] = props.input || {};
53
+ }
54
+ });
55
+ }
56
+ if (type.isString(props.url)) {
57
+ const protocol = props.url.includes(':') ? '' : 'https://';
58
+ return newOriginLink({
59
+ ...props,
60
+ url: `${protocol}${props.url}`,
61
+ query
62
+ });
63
+ }
64
+ return noLink(props);
42
65
  }
43
66
  return link;
44
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/engine",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.7",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -38,17 +38,18 @@
38
38
  "test": "jest --coverage"
39
39
  },
40
40
  "dependencies": {
41
- "@lowdefy/helpers": "4.0.0-alpha.6",
42
- "@lowdefy/operators": "4.0.0-alpha.6"
41
+ "@lowdefy/helpers": "4.0.0-alpha.7",
42
+ "@lowdefy/operators": "4.0.0-alpha.7"
43
43
  },
44
44
  "devDependencies": {
45
+ "@lowdefy/operators-js": "4.0.0-alpha.7",
45
46
  "@swc/cli": "0.1.55",
46
- "@swc/core": "1.2.130",
47
+ "@swc/core": "1.2.135",
47
48
  "@swc/jest": "0.2.17",
48
- "jest": "27.3.1"
49
+ "jest": "27.5.1"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"
52
53
  },
53
- "gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
54
+ "gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
54
55
  }
@@ -1,28 +0,0 @@
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 { applyArrayIndices, type } from '@lowdefy/helpers';
16
- // context, event, params
17
- async function CallMethod({ arrayIndices , context , params }) {
18
- const { blockId , method , args =[] } = params;
19
- const blockMethod = context._internal.RootBlocks.map[applyArrayIndices(arrayIndices, blockId)].methods[method];
20
- if (!type.isArray(args)) {
21
- throw new Error(`Failed to call method "${method}" on block "${blockId}": "args" should be an array. Received "${JSON.stringify(params)}".`);
22
- }
23
- if (!type.isFunction(blockMethod)) {
24
- throw new Error(`Failed to call method "${method}" on block "${blockId}". Check if "${method}" is a valid block method for block "${blockId}". Received "${JSON.stringify(params)}".`);
25
- }
26
- return blockMethod(...args);
27
- }
28
- export default CallMethod;
@@ -1,54 +0,0 @@
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, serializer } from '@lowdefy/helpers';
16
- import actionFns from './index.js';
17
- async function JsAction({ context , event , params , arrayIndices , blockId }) {
18
- if (!type.isString(params.name)) {
19
- throw new Error(`JsAction requires a string for 'params.name'.`);
20
- }
21
- if (!type.isNone(params.args) && !type.isArray(params.args)) {
22
- throw new Error(`JsAction requires a array for 'params.args'.`);
23
- }
24
- if (!type.isFunction(context.lowdefy.imports.jsActions[params.name])) {
25
- throw new Error(`JsAction ${params.name} is not a function.`);
26
- }
27
- const actions = {};
28
- Object.keys(actionFns).forEach((name)=>{
29
- actions[name] = (actionParams)=>actionFns[name]({
30
- arrayIndices,
31
- blockId,
32
- context,
33
- event,
34
- params: actionParams
35
- })
36
- ;
37
- });
38
- return context.lowdefy.imports.jsActions[params.name]({
39
- ...serializer.copy({
40
- global: context.lowdefy.lowdefyGlobal,
41
- input: context.lowdefy.inputs[context.id],
42
- state: context.state,
43
- urlQuery: context.lowdefy.urlQuery,
44
- user: context.lowdefy.user
45
- }),
46
- actions,
47
- contextId: context.id,
48
- pageId: context.pageId,
49
- requests: {
50
- ...context.requests
51
- }
52
- }, ...params.args || []);
53
- }
54
- export default JsAction;
@@ -1,27 +0,0 @@
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
- async function Link({ context , params }) {
17
- const linkParams = type.isString(params) ? {
18
- pageId: params
19
- } : params;
20
- try {
21
- context._internal.lowdefy._internal.link(linkParams);
22
- } catch (error) {
23
- console.log(error);
24
- throw new Error(`Invalid Link, check action params. Received "${JSON.stringify(params)}".`);
25
- }
26
- }
27
- export default Link;
@@ -1,25 +0,0 @@
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
- */ async function ScrollTo({ context , params ={} }) {
16
- if (params.blockId) {
17
- const element = context._internal.lowdefy._internal.document.getElementById(params.blockId);
18
- if (element) {
19
- element.scrollIntoView(params.options);
20
- }
21
- } else {
22
- context._internal.lowdefy._internal.window.scrollTo(params);
23
- }
24
- }
25
- export default ScrollTo;
@@ -1,39 +0,0 @@
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 ThrowActionError = class ThrowActionError extends Error {
17
- constructor(message, { blockId , context , metaData }){
18
- super(message);
19
- this.blockId = blockId;
20
- this.metaData = metaData;
21
- this.name = 'ThrowError';
22
- this.pageId = context.pageId;
23
- }
24
- };
25
- function Throw({ blockId , context , params ={} }) {
26
- if (params.throw === false || type.isNone(params.throw)) {
27
- return;
28
- }
29
- if (params.throw === true) {
30
- throw new ThrowActionError(params.message, {
31
- blockId,
32
- context,
33
- metaData: params.metaData
34
- });
35
- }
36
- throw new Error(`Invalid Throw, check action params. Received "${JSON.stringify(params)}".`);
37
- }
38
- export default Throw;
39
- export { Throw, ThrowActionError };
@@ -1,22 +0,0 @@
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, wait } from '@lowdefy/helpers';
16
- async function Wait({ params }) {
17
- if (!type.isInt(params.ms)) {
18
- throw new Error(`Wait action "ms" param should be an integer.`);
19
- }
20
- return wait(params.ms);
21
- }
22
- export default Wait;
@@ -1,46 +0,0 @@
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 CallMethod from './CallMethod.js';
16
- import JsAction from './JsAction.js';
17
- import Link from './Link.js';
18
- import Login from './Login.js';
19
- import Logout from './Logout.js';
20
- import Message from './Message.js';
21
- import Request from './Request.js';
22
- import Reset from './Reset.js';
23
- import ResetValidation from './ResetValidation.js';
24
- import ScrollTo from './ScrollTo.js';
25
- import SetGlobal from './SetGlobal.js';
26
- import SetState from './SetState.js';
27
- import Throw from './Throw.js';
28
- import Validate from './Validate.js';
29
- import Wait from './Wait.js';
30
- export default {
31
- CallMethod,
32
- JsAction,
33
- Link,
34
- Login,
35
- Logout,
36
- Message,
37
- Request,
38
- Reset,
39
- ResetValidation,
40
- ScrollTo,
41
- SetGlobal,
42
- SetState,
43
- Throw,
44
- Validate,
45
- Wait
46
- };