@lowdefy/engine 4.0.0-alpha.5 → 4.0.0-alpha.8

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 (37) hide show
  1. package/dist/Actions.js +70 -68
  2. package/dist/Blocks.js +41 -61
  3. package/dist/Events.js +12 -15
  4. package/dist/Requests.js +14 -16
  5. package/dist/State.js +7 -7
  6. package/dist/actions/createCallMethod.js +29 -0
  7. package/dist/actions/{Request.js → createDisplayMessage.js} +5 -8
  8. package/dist/actions/createGetActions.js +27 -0
  9. package/dist/actions/{Logout.js → createGetBlockId.js} +5 -3
  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/{Login.js → createGetPageId.js} +5 -3
  14. package/dist/actions/createGetRequestDetails.js +27 -0
  15. package/dist/actions/{Wait.js → createGetState.js} +12 -8
  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/{Message.js → createRequest.js} +10 -9
  22. package/dist/actions/{Reset.js → createReset.js} +7 -5
  23. package/dist/actions/{ResetValidation.js → createResetValidation.js} +5 -3
  24. package/dist/actions/{SetGlobal.js → createSetGlobal.js} +10 -8
  25. package/dist/actions/{SetState.js → createSetState.js} +9 -7
  26. package/dist/actions/{Validate.js → createValidate.js} +9 -7
  27. package/dist/actions/getActionMethods.js +61 -0
  28. package/dist/actions/getFromObject.js +42 -0
  29. package/dist/createLink.js +45 -22
  30. package/dist/getContext.js +6 -10
  31. package/package.json +9 -8
  32. package/dist/actions/CallMethod.js +0 -28
  33. package/dist/actions/JsAction.js +0 -55
  34. package/dist/actions/Link.js +0 -27
  35. package/dist/actions/ScrollTo.js +0 -26
  36. package/dist/actions/Throw.js +0 -40
  37. package/dist/actions/index.js +0 -46
@@ -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;
@@ -12,12 +12,16 @@
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
- */ import { type } 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 new Promise((resolve)=>setTimeout(resolve, params.ms)
21
- );
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
+ };
22
26
  }
23
- export default Wait;
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,13 +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
- } }) {
17
- context._internal.lowdefy._internal.displayMessage({
18
- content: params.content || 'Success',
19
- duration: params.duration,
20
- icon: params.icon,
21
- status: params.status
22
- });
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
+ };
23
24
  }
24
- 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
  }