@lowdefy/build 3.23.0-alpha.0 → 4.0.0-alpha.4

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 (87) hide show
  1. package/dist/build/addDefaultPages/404.js +56 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +40 -0
  3. package/dist/build/buildAuth/buildAuth.js +50 -0
  4. package/dist/build/buildAuth/getPageRoles.js +34 -0
  5. package/dist/build/buildAuth/getProtectedPages.js +30 -0
  6. package/dist/build/buildConnections.js +47 -0
  7. package/dist/build/buildIcons.js +63 -0
  8. package/dist/build/buildMenu.js +122 -0
  9. package/dist/build/buildPages/buildBlock/buildBlock.js +31 -0
  10. package/dist/build/buildPages/buildBlock/buildEvents.js +72 -0
  11. package/dist/build/buildPages/buildBlock/buildRequests.js +52 -0
  12. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
  13. package/dist/build/buildPages/buildBlock/countBlockOperators.js +33 -0
  14. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
  15. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  16. package/dist/build/buildPages/buildBlock/validateBlock.js +39 -0
  17. package/dist/build/buildPages/buildPage.js +50 -0
  18. package/dist/build/buildPages/buildPages.js +33 -0
  19. package/dist/build/buildRefs/buildRefs.js +26 -0
  20. package/dist/build/buildRefs/getConfigFile.js +28 -0
  21. package/dist/build/buildRefs/getRefContent.js +44 -0
  22. package/dist/build/buildRefs/getRefPath.js +30 -0
  23. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  24. package/dist/build/buildRefs/getUserJavascriptFunction.js +21 -0
  25. package/dist/build/buildRefs/makeRefDefinition.js +31 -0
  26. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  27. package/dist/build/buildRefs/parseRefContent.js +37 -0
  28. package/dist/build/buildRefs/populateRefs.js +43 -0
  29. package/dist/build/buildRefs/recursiveBuild.js +63 -0
  30. package/dist/build/buildRefs/runRefResolver.js +33 -0
  31. package/dist/build/buildRefs/runTransformer.js +26 -0
  32. package/dist/build/buildStyles.js +29 -0
  33. package/dist/build/buildTypes.js +83 -0
  34. package/dist/build/cleanBuildDirectory.js +19 -0
  35. package/dist/build/testSchema.js +34 -0
  36. package/dist/build/validateApp.js +36 -0
  37. package/dist/build/validateConfig.js +53 -0
  38. package/dist/build/writeApp.js +22 -0
  39. package/dist/build/writeConfig.js +22 -0
  40. package/dist/build/writeConnections.js +29 -0
  41. package/dist/build/writeGlobal.js +29 -0
  42. package/dist/build/writeMenus.js +25 -0
  43. package/dist/build/writePages.js +37 -0
  44. package/dist/build/writePluginImports/writeBlockImports.js +39 -0
  45. package/dist/build/writePluginImports/writeConnectionImports.js +39 -0
  46. package/dist/build/writePluginImports/writeIconImports.js +37 -0
  47. package/dist/build/writePluginImports/writeStyleImports.js +30 -0
  48. package/dist/build/writeRequests.js +37 -0
  49. package/dist/build/writeTypes.js +21 -0
  50. package/dist/defaultTypes.json +66 -0
  51. package/dist/index.js +182 -1
  52. package/dist/lowdefySchema.js +699 -0
  53. package/dist/scripts/generateDefaultTypes.js +101 -0
  54. package/dist/scripts/run.js +25 -0
  55. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +25 -0
  56. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  57. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  58. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  59. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  60. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  61. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  62. package/dist/test/testContext.js +55 -0
  63. package/dist/utils/countOperators.js +30 -0
  64. package/dist/utils/createCheckDuplicateId.js +31 -0
  65. package/dist/utils/createCounter.js +33 -0
  66. package/dist/utils/files/readConfigFile.js +24 -0
  67. package/dist/utils/files/writeBuildArtifact.js +26 -0
  68. package/dist/utils/formatErrorMessage.js +56 -0
  69. package/package.json +22 -21
  70. package/dist/138.index.js +0 -2
  71. package/dist/138.index.js.LICENSE.txt +0 -3
  72. package/dist/231.index.js +0 -1
  73. package/dist/319.index.js +0 -1
  74. package/dist/35.index.js +0 -1
  75. package/dist/422.index.js +0 -1
  76. package/dist/443.index.js +0 -1
  77. package/dist/449.index.js +0 -1
  78. package/dist/5.index.js +0 -2
  79. package/dist/5.index.js.LICENSE.txt +0 -1
  80. package/dist/564.index.js +0 -1
  81. package/dist/569.index.js +0 -1
  82. package/dist/625.index.js +0 -1
  83. package/dist/693.index.js +0 -2
  84. package/dist/693.index.js.LICENSE.txt +0 -1
  85. package/dist/734.index.js +0 -1
  86. package/dist/904.index.js +0 -1
  87. package/dist/remoteEntry.js +0 -1
@@ -0,0 +1,56 @@
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
+ */ // TODO: temp fix while waiting for blocks-antd
16
+ export default {
17
+ id: '404',
18
+ type: 'Box'
19
+ }; // export default {
20
+ // id: '404',
21
+ // type: 'Result',
22
+ // style: {
23
+ // minHeight: '100vh',
24
+ // },
25
+ // properties: {
26
+ // status: 404,
27
+ // title: '404',
28
+ // subTitle: 'Sorry, the page you are visiting does not exist.',
29
+ // },
30
+ // areas: {
31
+ // extra: {
32
+ // blocks: [
33
+ // {
34
+ // id: 'home',
35
+ // type: 'Button',
36
+ // properties: {
37
+ // title: 'Go to home page',
38
+ // type: 'Link',
39
+ // icon: 'HomeOutlined',
40
+ // },
41
+ // events: {
42
+ // onClick: [
43
+ // {
44
+ // id: 'home',
45
+ // type: 'Link',
46
+ // params: {
47
+ // home: true,
48
+ // },
49
+ // },
50
+ // ],
51
+ // },
52
+ // },
53
+ // ],
54
+ // },
55
+ // },
56
+ // };
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import page404 from './404.js';
17
+ async function addDefaultPages({ components }) {
18
+ // If not copied, the same object is mutated by build every time
19
+ // build runs for dev server. See #647
20
+ const defaultPages = [
21
+ JSON.parse(JSON.stringify(page404))
22
+ ];
23
+ if (type.isNone(components.pages)) {
24
+ components.pages = [];
25
+ }
26
+ if (!type.isArray(components.pages)) {
27
+ throw new Error('lowdefy.pages is not an array.');
28
+ }
29
+ const pageIds = components.pages.map((page)=>page.id
30
+ );
31
+ // deep copy to avoid mutating defaultConfig
32
+ const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id)
33
+ );
34
+ components.pages = [
35
+ ...components.pages,
36
+ ...filteredDefaultPages
37
+ ];
38
+ return components;
39
+ }
40
+ export default addDefaultPages;
@@ -0,0 +1,50 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import getPageRoles from './getPageRoles.js';
17
+ import getProtectedPages from './getProtectedPages.js';
18
+ function buildAuth({ components }) {
19
+ const protectedPages = getProtectedPages({
20
+ components
21
+ });
22
+ const pageRoles = getPageRoles({
23
+ components
24
+ });
25
+ let configPublicPages = [];
26
+ if (type.isArray(components.config.auth.pages.public)) {
27
+ configPublicPages = components.config.auth.pages.public;
28
+ }
29
+ (components.pages || []).forEach((page)=>{
30
+ if (pageRoles[page.id]) {
31
+ if (configPublicPages.includes(page.id)) {
32
+ throw new Error(`Page "${page.id}" is both protected by roles ${JSON.stringify(pageRoles[page.id])} and public.`);
33
+ }
34
+ page.auth = {
35
+ public: false,
36
+ roles: pageRoles[page.id]
37
+ };
38
+ } else if (protectedPages.includes(page.id)) {
39
+ page.auth = {
40
+ public: false
41
+ };
42
+ } else {
43
+ page.auth = {
44
+ public: true
45
+ };
46
+ }
47
+ });
48
+ return components;
49
+ }
50
+ export default buildAuth;
@@ -0,0 +1,34 @@
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 getPageRoles({ components }) {
16
+ const roles = components.config.auth.pages.roles;
17
+ const pageRoles = {
18
+ };
19
+ Object.keys(roles).forEach((roleName)=>{
20
+ roles[roleName].forEach((pageId)=>{
21
+ if (!pageRoles[pageId]) {
22
+ pageRoles[pageId] = new Set();
23
+ }
24
+ pageRoles[pageId].add(roleName);
25
+ });
26
+ });
27
+ Object.keys(pageRoles).forEach((pageId)=>{
28
+ pageRoles[pageId] = [
29
+ ...pageRoles[pageId]
30
+ ];
31
+ });
32
+ return pageRoles;
33
+ }
34
+ export default getPageRoles;
@@ -0,0 +1,30 @@
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
+ function getProtectedPages({ components }) {
17
+ const pageIds = (components.pages || []).map((page)=>page.id
18
+ );
19
+ let protectedPages = [];
20
+ if (type.isArray(components.config.auth.pages.public)) {
21
+ protectedPages = pageIds.filter((pageId)=>!components.config.auth.pages.public.includes(pageId)
22
+ );
23
+ } else if (components.config.auth.pages.protected === true) {
24
+ protectedPages = pageIds;
25
+ } else if (type.isArray(components.config.auth.pages.protected)) {
26
+ protectedPages = components.config.auth.pages.protected;
27
+ }
28
+ return protectedPages;
29
+ }
30
+ export default getProtectedPages;
@@ -0,0 +1,47 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import countOperators from '../utils/countOperators.js';
17
+ import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
18
+ async function buildConnections({ components , context }) {
19
+ const checkDuplicateConnectionId = createCheckDuplicateId({
20
+ message: 'Duplicate connectionId "{{ id }}".'
21
+ });
22
+ if (type.isArray(components.connections)) {
23
+ components.connections.forEach((connection)=>{
24
+ if (type.isUndefined(connection.id)) {
25
+ throw new Error(`Connection id missing.`);
26
+ }
27
+ if (!type.isString(connection.id)) {
28
+ throw new Error(`Connection id is not a string. Received ${JSON.stringify(connection.id)}.`);
29
+ }
30
+ checkDuplicateConnectionId({
31
+ id: connection.id
32
+ });
33
+ if (!type.isString(connection.type)) {
34
+ throw new Error(`Connection type is not a string at connection "${connection.id}". Received ${JSON.stringify(connection.type)}.`);
35
+ }
36
+ context.typeCounters.connections.increment(connection.type);
37
+ connection.connectionId = connection.id;
38
+ connection.id = `connection:${connection.id}`;
39
+ countOperators(connection.properties || {
40
+ }, {
41
+ counter: context.typeCounters.operators.server
42
+ });
43
+ });
44
+ }
45
+ return components;
46
+ }
47
+ export default buildConnections;
@@ -0,0 +1,63 @@
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
+ */ const iconPackages = {
16
+ 'react-icons/ai': /"(Ai[A-Z0-9]\w*)"/gm,
17
+ 'react-icons/bs': /"(Bs[A-Z0-9]\w*)"/gm,
18
+ 'react-icons/bi': /"(Bi[A-Z0-9]\w*)"/gm,
19
+ 'react-icons/di': /"(Di[A-Z0-9]\w*)"/gm,
20
+ 'react-icons/fi': /"(Fi[A-Z0-9]\w*)"/gm,
21
+ 'react-icons/fc': /"(Fc[A-Z0-9]\w*)"/gm,
22
+ 'react-icons/fa': /"(Fa[A-Z0-9]\w*)"/gm,
23
+ 'react-icons/gi': /"(Gi[A-Z0-9]\w*)"/gm,
24
+ 'react-icons/go': /"(Go[A-Z0-9]\w*)"/gm,
25
+ 'react-icons/gr': /"(Gr[A-Z0-9]\w*)"/gm,
26
+ 'react-icons/hi': /"(Hi[A-Z0-9]\w*)"/gm,
27
+ 'react-icons/im': /"(Im[A-Z0-9]\w*)"/gm,
28
+ 'react-icons/io': /"(IoIos[A-Z0-9]\w*)"/gm,
29
+ 'react-icons/io5': /"(Io[A-Z0-9]\w*)"/gm,
30
+ 'react-icons/md': /"(Md[A-Z0-9]\w*)"/gm,
31
+ 'react-icons/ri': /"(Ri[A-Z0-9]\w*)"/gm,
32
+ 'react-icons/si': /"(Si[A-Z0-9]\w*)"/gm,
33
+ 'react-icons/ti': /"(Ti[A-Z0-9]\w*)"/gm,
34
+ 'react-icons/vsc': /"(Vsc[A-Z0-9]\w*)"/gm,
35
+ 'react-icons/wi': /"(Wi[A-Z0-9]\w*)"/gm,
36
+ 'react-icons/cg': /"(Cg[A-Z0-9]\w*)"/gm
37
+ };
38
+ function buildIcons({ components }) {
39
+ components.icons = [];
40
+ Object.entries(iconPackages).forEach(([iconPackage, regex])=>{
41
+ const icons = new Set();
42
+ [
43
+ ...JSON.stringify(components.global || {
44
+ }).matchAll(regex)
45
+ ].map((match)=>icons.add(match[1])
46
+ );
47
+ [
48
+ ...JSON.stringify(components.menus || []).matchAll(regex)
49
+ ].map((match)=>icons.add(match[1])
50
+ );
51
+ [
52
+ ...JSON.stringify(components.pages || []).matchAll(regex)
53
+ ].map((match)=>icons.add(match[1])
54
+ );
55
+ components.icons.push({
56
+ icons: [
57
+ ...icons
58
+ ],
59
+ package: iconPackage
60
+ });
61
+ });
62
+ }
63
+ export default buildIcons;
@@ -0,0 +1,122 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
17
+ async function buildDefaultMenu({ components , context }) {
18
+ context.logger.warn('No menus found. Building default menu.');
19
+ const pages = type.isArray(components.pages) ? components.pages : [];
20
+ const menus = [
21
+ {
22
+ id: 'default',
23
+ links: pages.map((page, i)=>({
24
+ id: `${i}`,
25
+ type: 'MenuLink',
26
+ pageId: page.pageId,
27
+ auth: page.auth
28
+ })
29
+ ).filter((page)=>page.pageId !== '404'
30
+ )
31
+ },
32
+ ];
33
+ return menus;
34
+ }
35
+ function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplicateMenuItemId }) {
36
+ if (type.isArray(parent.links)) {
37
+ parent.links.forEach((menuItem)=>{
38
+ if (menuItem.type === 'MenuLink') {
39
+ if (type.isString(menuItem.pageId)) {
40
+ const page = pages.find((pg)=>pg.pageId === menuItem.pageId
41
+ );
42
+ if (!page) {
43
+ missingPageWarnings.push({
44
+ menuItemId: menuItem.id,
45
+ pageId: menuItem.pageId
46
+ });
47
+ // remove menuItem from menu
48
+ menuItem.remove = true;
49
+ return;
50
+ } else {
51
+ menuItem.auth = page.auth;
52
+ }
53
+ } else {
54
+ menuItem.auth = {
55
+ public: true
56
+ };
57
+ }
58
+ }
59
+ if (menuItem.type === 'MenuGroup') {
60
+ menuItem.auth = {
61
+ public: true
62
+ };
63
+ }
64
+ checkDuplicateMenuItemId({
65
+ id: menuItem.id,
66
+ menuId
67
+ });
68
+ menuItem.menuItemId = menuItem.id;
69
+ menuItem.id = `menuitem:${menuId}:${menuItem.id}`;
70
+ loopItems({
71
+ parent: menuItem,
72
+ menuId,
73
+ pages,
74
+ missingPageWarnings,
75
+ checkDuplicateMenuItemId
76
+ });
77
+ });
78
+ parent.links = parent.links.filter((item)=>item.remove !== true
79
+ );
80
+ }
81
+ }
82
+ async function buildMenu({ components , context }) {
83
+ const pages = type.isArray(components.pages) ? components.pages : [];
84
+ if (type.isUndefined(components.menus) || components.menus.length === 0) {
85
+ components.menus = await buildDefaultMenu({
86
+ components,
87
+ context
88
+ });
89
+ }
90
+ const missingPageWarnings = [];
91
+ const checkDuplicateMenuId = createCheckDuplicateId({
92
+ message: 'Duplicate menuId "{{ id }}".'
93
+ });
94
+ components.menus.forEach((menu)=>{
95
+ if (type.isUndefined(menu.id)) {
96
+ throw new Error(`Menu id missing.`);
97
+ }
98
+ if (!type.isString(menu.id)) {
99
+ throw new Error(`Menu id is not a string. Received ${JSON.stringify(menu.id)}.`);
100
+ }
101
+ checkDuplicateMenuId({
102
+ id: menu.id
103
+ });
104
+ menu.menuId = menu.id;
105
+ menu.id = `menu:${menu.id}`;
106
+ const checkDuplicateMenuItemId = createCheckDuplicateId({
107
+ message: 'Duplicate menuItemId "{{ id }}" on menu "{{ menuId }}".'
108
+ });
109
+ loopItems({
110
+ parent: menu,
111
+ menuId: menu.menuId,
112
+ pages,
113
+ missingPageWarnings,
114
+ checkDuplicateMenuItemId
115
+ });
116
+ });
117
+ await Promise.all(missingPageWarnings.map(async (warning)=>{
118
+ await context.logger.warn(`Page "${warning.pageId}" referenced in menu link "${warning.menuItemId}" not found.`);
119
+ }));
120
+ return components;
121
+ }
122
+ export default buildMenu;
@@ -0,0 +1,31 @@
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 buildEvents from './buildEvents.js';
16
+ import buildRequests from './buildRequests.js';
17
+ import buildSubBlocks from './buildSubBlocks.js';
18
+ import countBlockOperators from './countBlockOperators.js';
19
+ import moveSubBlocksToArea from './moveSubBlocksToArea.js';
20
+ import setBlockId from './setBlockId.js';
21
+ import validateBlock from './validateBlock.js';
22
+ async function buildBlock(block, pageContext) {
23
+ validateBlock(block, pageContext);
24
+ countBlockOperators(block, pageContext);
25
+ setBlockId(block, pageContext);
26
+ buildEvents(block, pageContext);
27
+ buildRequests(block, pageContext);
28
+ moveSubBlocksToArea(block, pageContext);
29
+ await buildSubBlocks(block, pageContext);
30
+ }
31
+ export default buildBlock;
@@ -0,0 +1,72 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import createCheckDuplicateId from '../../../utils/createCheckDuplicateId.js';
17
+ function checkAction(action, { blockId , checkDuplicateActionId , eventId , pageId , typeCounters }) {
18
+ if (type.isUndefined(action.id)) {
19
+ throw new Error(`Action id missing on event "${eventId}" on block "${blockId}" on page "${pageId}".`);
20
+ }
21
+ if (!type.isString(action.id)) {
22
+ throw new Error(`Action id is not a string on event "${eventId}" on block "${blockId}" on page "${pageId}". Received ${JSON.stringify(action.id)}.`);
23
+ }
24
+ checkDuplicateActionId({
25
+ id: action.id,
26
+ eventId,
27
+ blockId,
28
+ pageId
29
+ });
30
+ if (!type.isString(action.type)) {
31
+ throw new Error(`Action type is not a string on action "${action.id}" on event "${eventId}" on block "${blockId}" on page "${pageId}". Received ${JSON.stringify(action.type)}.`);
32
+ }
33
+ typeCounters.actions.increment(action.type);
34
+ }
35
+ function buildEvents(block, pageContext) {
36
+ if (block.events) {
37
+ Object.keys(block.events).map((key)=>{
38
+ if (type.isArray(block.events[key])) {
39
+ block.events[key] = {
40
+ try: block.events[key],
41
+ catch: []
42
+ };
43
+ }
44
+ if (!type.isArray(block.events[key].try)) {
45
+ throw new Error(`Events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
46
+ }
47
+ if (!type.isArray(block.events[key].catch) && !type.isNone(block.events[key].catch)) {
48
+ throw new Error(`Catch events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
49
+ }
50
+ const checkDuplicateActionId = createCheckDuplicateId({
51
+ message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
52
+ });
53
+ block.events[key].try.map((action)=>checkAction(action, {
54
+ eventId: key,
55
+ blockId: block.blockId,
56
+ typeCounters: pageContext.typeCounters,
57
+ pageId: pageContext.pageId,
58
+ checkDuplicateActionId
59
+ })
60
+ );
61
+ block.events[key].catch.map((action)=>checkAction(action, {
62
+ eventId: key,
63
+ blockId: block.blockId,
64
+ typeCounters: pageContext.typeCounters,
65
+ pageId: pageContext.pageId,
66
+ checkDuplicateActionId
67
+ })
68
+ );
69
+ });
70
+ }
71
+ }
72
+ export default buildEvents;
@@ -0,0 +1,52 @@
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
+ function buildRequest(request, pageContext) {
17
+ const { auth , checkDuplicateRequestId , pageId , typeCounters } = pageContext;
18
+ if (type.isUndefined(request.id)) {
19
+ throw new Error(`Request id missing at page "${pageId}".`);
20
+ }
21
+ if (!type.isString(request.id)) {
22
+ throw new Error(`Request id is not a string at page "${pageId}". Received ${JSON.stringify(request.id)}.`);
23
+ }
24
+ checkDuplicateRequestId({
25
+ id: request.id,
26
+ pageId
27
+ });
28
+ if (request.id.includes('.')) {
29
+ throw new Error(`Request id "${request.id}" at page "${pageId}" should not include a period (".").`);
30
+ }
31
+ if (!type.isString(request.type)) {
32
+ throw new Error(`Request type is not a string at at request at "${request.id}" at page "${pageId}". Received ${JSON.stringify(request.type)}.`);
33
+ }
34
+ typeCounters.requests.increment(request.type);
35
+ if (type.isUndefined(request.payload)) request.payload = {
36
+ };
37
+ if (!type.isObject(request.payload)) {
38
+ throw new Error(`Request "${request.id}" at page "${pageId}" payload should be an object.`);
39
+ }
40
+ request.auth = auth;
41
+ request.requestId = request.id;
42
+ request.pageId = pageId;
43
+ request.id = `request:${pageId}:${request.id}`;
44
+ pageContext.requests.push(request);
45
+ }
46
+ function buildRequests(block, pageContext) {
47
+ (block.requests || []).forEach((request)=>{
48
+ buildRequest(request, pageContext);
49
+ });
50
+ delete block.requests;
51
+ }
52
+ export default buildRequests;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import buildBlock from './buildBlock.js';
17
+ async function buildSubBlocks(block, pageContext) {
18
+ if (type.isObject(block.areas)) {
19
+ let promises = [];
20
+ Object.keys(block.areas).forEach((key)=>{
21
+ if (type.isNone(block.areas[key].blocks)) {
22
+ block.areas[key].blocks = [];
23
+ }
24
+ if (!type.isArray(block.areas[key].blocks)) {
25
+ throw new Error(`Expected blocks to be an array at ${block.blockId} in area ${key} on page ${pageContext.pageId}. Received ${JSON.stringify(block.areas[key].blocks)}`);
26
+ }
27
+ const blockPromises = block.areas[key].blocks.map(async (blk)=>{
28
+ await buildBlock(blk, pageContext);
29
+ });
30
+ promises = promises.concat(blockPromises);
31
+ });
32
+ await Promise.all(promises);
33
+ }
34
+ }
35
+ export default buildSubBlocks;
@@ -0,0 +1,33 @@
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 countOperators from '../../../utils/countOperators.js';
16
+ function countBlockOperators(block, { typeCounters }) {
17
+ // eslint-disable-next-line no-unused-vars
18
+ const { requests , blocks , areas , ...webBlock } = block;
19
+ countOperators(webBlock, {
20
+ counter: typeCounters.operators.client
21
+ });
22
+ (requests || []).forEach((request)=>{
23
+ countOperators(request.payload || {
24
+ }, {
25
+ counter: typeCounters.operators.client
26
+ });
27
+ countOperators(request.properties || {
28
+ }, {
29
+ counter: typeCounters.operators.server
30
+ });
31
+ });
32
+ }
33
+ export default countBlockOperators;