@lowdefy/engine 0.0.0-alpha.6 → 0.0.0-experimental-20231123101256

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 (39) hide show
  1. package/LICENSE +201 -0
  2. package/dist/Actions.js +231 -486
  3. package/dist/Blocks.js +563 -572
  4. package/dist/Events.js +126 -0
  5. package/dist/Requests.js +107 -134
  6. package/dist/State.js +56 -83
  7. package/dist/actions/createCallMethod.js +29 -0
  8. package/dist/actions/createDisplayMessage.js +20 -0
  9. package/dist/actions/createGetActions.js +27 -0
  10. package/dist/actions/createGetBlockId.js +20 -0
  11. package/dist/actions/createGetEvent.js +27 -0
  12. package/dist/actions/createGetGlobal.js +27 -0
  13. package/dist/actions/createGetInput.js +27 -0
  14. package/dist/actions/createGetPageId.js +20 -0
  15. package/dist/actions/createGetRequestDetails.js +27 -0
  16. package/dist/actions/createGetState.js +27 -0
  17. package/dist/actions/createGetUrlQuery.js +32 -0
  18. package/dist/actions/createGetUser.js +27 -0
  19. package/dist/actions/createLink.js +20 -0
  20. package/dist/actions/createLogin.js +20 -0
  21. package/dist/actions/createLogout.js +20 -0
  22. package/dist/actions/createRequest.js +26 -0
  23. package/dist/actions/createReset.js +22 -0
  24. package/dist/actions/createResetValidation.js +21 -0
  25. package/dist/actions/createSetGlobal.js +25 -0
  26. package/dist/actions/createSetState.js +25 -0
  27. package/dist/actions/createUpdateSession.js +20 -0
  28. package/dist/actions/createValidate.js +25 -0
  29. package/dist/actions/getActionMethods.js +63 -0
  30. package/dist/actions/getFromObject.js +42 -0
  31. package/dist/createLink.js +71 -0
  32. package/dist/getBlockMatcher.js +61 -0
  33. package/dist/getContext.js +106 -153
  34. package/dist/index.js +10 -63
  35. package/package.json +27 -26
  36. package/dist/BlockActions.js +0 -211
  37. package/dist/Mutations.js +0 -100
  38. package/dist/getFieldValues.js +0 -49
  39. package/dist/makeContextId.js +0 -44
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2023 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-2023 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;
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2020-2023 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 createGetPageId({ context }) {
16
+ return function getPageId() {
17
+ return context.pageId;
18
+ };
19
+ }
20
+ export default createGetPageId;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2023 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-2023 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,32 @@
1
+ /*
2
+ Copyright 2020-2023 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
+ import { urlQuery } from '@lowdefy/helpers';
17
+ function createGetUrlQuery({ arrayIndices, blockId, context }) {
18
+ return function getUrlQuery(params) {
19
+ const { window } = context._internal.lowdefy._internal.globals;
20
+ if (!window?.location) {
21
+ throw new Error(`Browser window.location not available for getUrlQuery. Received: ${JSON.stringify(params)} on blockId: ${blockId}.`);
22
+ }
23
+ return getFromObject({
24
+ arrayIndices,
25
+ location: blockId,
26
+ object: urlQuery.parse(window.location.search.slice(1)),
27
+ method: 'getUrlQuery',
28
+ params
29
+ });
30
+ };
31
+ }
32
+ export default createGetUrlQuery;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2023 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-2023 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-2023 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-2023 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(params) {
17
+ return context._internal.lowdefy._internal.auth.logout(params);
18
+ };
19
+ }
20
+ export default createLogout;
@@ -0,0 +1,26 @@
1
+ /*
2
+ Copyright 2020-2023 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 createRequest({ actions, arrayIndices, blockId, context, event }) {
16
+ return function request(params) {
17
+ return context._internal.Requests.callRequests({
18
+ actions,
19
+ arrayIndices,
20
+ blockId,
21
+ event,
22
+ params
23
+ });
24
+ };
25
+ }
26
+ export default createRequest;
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2020-2023 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 { serializer } from '@lowdefy/helpers';
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
+ };
21
+ }
22
+ export default createReset;
@@ -0,0 +1,21 @@
1
+ /*
2
+ Copyright 2020-2023 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 getBlockMatcher from '../getBlockMatcher.js';
16
+ function createResetValidation({ context }) {
17
+ return function resetValidation(params) {
18
+ context._internal.RootBlocks.resetValidation(getBlockMatcher(params));
19
+ };
20
+ }
21
+ export default createResetValidation;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2023 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, set } from '@lowdefy/helpers';
16
+ const createSetGlobal = ({ arrayIndices, context })=>{
17
+ return function setGlobal(params) {
18
+ Object.keys(params).forEach((key)=>{
19
+ set(context._internal.lowdefy.lowdefyGlobal, applyArrayIndices(arrayIndices, key), params[key]);
20
+ });
21
+ context._internal.RootBlocks.reset();
22
+ context._internal.update();
23
+ };
24
+ };
25
+ export default createSetGlobal;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2023 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 } from '@lowdefy/helpers';
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
+ };
24
+ }
25
+ export default createSetState;
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2020-2023 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 createUpdateSession({ context }) {
16
+ return function updateSession() {
17
+ return context._internal.lowdefy._internal.auth.updateSession();
18
+ };
19
+ }
20
+ export default createUpdateSession;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2023 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 getBlockMatcher from '../getBlockMatcher.js';
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
+ };
24
+ }
25
+ export default createValidate;
@@ -0,0 +1,63 @@
1
+ /*
2
+ Copyright 2020-2023 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 createUpdateSession from './createUpdateSession.js';
36
+ import createValidate from './createValidate.js';
37
+ function getActionMethods(props) {
38
+ return {
39
+ callMethod: createCallMethod(props),
40
+ displayMessage: createDisplayMessage(props),
41
+ getActions: createGetActions(props),
42
+ getBlockId: createGetBlockId(props),
43
+ getEvent: createGetEvent(props),
44
+ getGlobal: createGetGlobal(props),
45
+ getInput: createGetInput(props),
46
+ getPageId: createGetPageId(props),
47
+ getRequestDetails: createGetRequestDetails(props),
48
+ getState: createGetState(props),
49
+ getUrlQuery: createGetUrlQuery(props),
50
+ getUser: createGetUser(props),
51
+ link: createLink(props),
52
+ login: createLogin(props),
53
+ logout: createLogout(props),
54
+ request: createRequest(props),
55
+ reset: createReset(props),
56
+ resetValidation: createResetValidation(props),
57
+ setGlobal: createSetGlobal(props),
58
+ setState: createSetState(props),
59
+ updateSession: createUpdateSession(props),
60
+ validate: createValidate(props)
61
+ };
62
+ }
63
+ export default getActionMethods;
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2020-2023 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;
@@ -0,0 +1,71 @@
1
+ /*
2
+ Copyright 2020-2023 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, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
+ function createLink({ backLink, disabledLink, lowdefy, newOriginLink, noLink, sameOriginLink }) {
17
+ function link(props) {
18
+ if (props.disabled === true) {
19
+ return disabledLink(props);
20
+ }
21
+ if ([
22
+ !props.pageId,
23
+ !props.back,
24
+ !props.home,
25
+ !props.href,
26
+ !props.url
27
+ ].filter((v)=>!v).length > 1) {
28
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'back', 'home', 'href', 'pageId' or 'url' can be defined.`);
29
+ }
30
+ if (props.back === true) {
31
+ // Cannot set input or urlQuery on back
32
+ return backLink(props);
33
+ }
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
+ });
45
+ }
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.href)) {
57
+ return newOriginLink(props);
58
+ }
59
+ if (type.isString(props.url)) {
60
+ const protocol = props.url.includes(':') ? '' : 'https://';
61
+ return newOriginLink({
62
+ ...props,
63
+ url: `${protocol}${props.url}`,
64
+ query
65
+ });
66
+ }
67
+ return noLink(props);
68
+ }
69
+ return link;
70
+ }
71
+ export default createLink;