@lowdefy/build 3.23.3 → 4.0.0-alpha.11

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 (105) hide show
  1. package/dist/build/addDefaultPages/404.js +51 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +44 -0
  3. package/dist/build/buildAuth/buildAuth.js +31 -0
  4. package/dist/build/buildAuth/buildAuthPlugins.js +78 -0
  5. package/dist/build/buildAuth/buildPageAuth.js +50 -0
  6. package/dist/build/buildAuth/getPageRoles.js +33 -0
  7. package/dist/build/buildAuth/getProtectedPages.js +30 -0
  8. package/dist/build/buildAuth/validateAuthConfig.js +61 -0
  9. package/dist/build/buildConnections.js +46 -0
  10. package/dist/build/buildImports/buildIconImports.js +92 -0
  11. package/dist/build/buildImports/buildImports.js +30 -0
  12. package/dist/build/buildImports/buildImportsDev.js +101 -0
  13. package/dist/build/buildImports/buildImportsProd.js +52 -0
  14. package/dist/build/buildImports/buildStyleImports.js +28 -0
  15. package/dist/build/buildMenu.js +122 -0
  16. package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
  17. package/dist/build/buildPages/buildBlock/buildEvents.js +75 -0
  18. package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
  19. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
  20. package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
  21. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  22. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  23. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
  24. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  25. package/dist/build/buildPages/buildBlock/validateBlock.js +38 -0
  26. package/dist/build/buildPages/buildPage.js +50 -0
  27. package/dist/build/buildPages/buildPages.js +33 -0
  28. package/dist/build/buildRefs/buildRefs.js +26 -0
  29. package/dist/build/buildRefs/evaluateBuildOperators.js +35 -0
  30. package/dist/build/buildRefs/getConfigFile.js +28 -0
  31. package/dist/build/buildRefs/getRefContent.js +44 -0
  32. package/dist/build/buildRefs/getRefPath.js +30 -0
  33. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  34. package/dist/build/buildRefs/getUserJavascriptFunction.js +24 -0
  35. package/dist/build/buildRefs/makeRefDefinition.js +30 -0
  36. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  37. package/dist/build/buildRefs/parseRefContent.js +37 -0
  38. package/dist/build/buildRefs/populateRefs.js +43 -0
  39. package/dist/build/buildRefs/recursiveBuild.js +68 -0
  40. package/dist/build/buildRefs/runRefResolver.js +33 -0
  41. package/dist/build/buildRefs/runTransformer.js +30 -0
  42. package/dist/build/buildTypes.js +119 -0
  43. package/dist/build/cleanBuildDirectory.js +19 -0
  44. package/dist/build/copyPublicFolder.js +23 -0
  45. package/dist/build/testSchema.js +33 -0
  46. package/dist/build/updateServerPackageJson.js +49 -0
  47. package/dist/build/validateApp.js +34 -0
  48. package/dist/build/validateConfig.js +33 -0
  49. package/dist/build/writeApp.js +18 -0
  50. package/dist/build/writeAuth.js +18 -0
  51. package/dist/build/writeConfig.js +18 -0
  52. package/dist/build/writeConnections.js +26 -0
  53. package/dist/build/writeGlobal.js +25 -0
  54. package/dist/build/writeMenus.js +22 -0
  55. package/dist/build/writePages.js +26 -0
  56. package/dist/build/writePluginImports/generateImportFile.js +31 -0
  57. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  58. package/dist/build/writePluginImports/writeAuthImports.js +30 -0
  59. package/dist/build/writePluginImports/writeBlockImports.js +22 -0
  60. package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
  61. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  62. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  63. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  64. package/dist/build/writePluginImports/writeStyleImports.js +28 -0
  65. package/dist/build/writeRequests.js +32 -0
  66. package/dist/build/writeTypes.js +18 -0
  67. package/dist/defaultTypesMap.json +1874 -0
  68. package/dist/index.js +179 -1
  69. package/dist/lowdefySchema.js +793 -0
  70. package/dist/scripts/generateDefaultTypes.js +78 -0
  71. package/dist/scripts/run.js +33 -0
  72. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
  73. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  74. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  75. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  76. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  77. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  78. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  79. package/dist/test/testContext.js +48 -0
  80. package/dist/utils/countOperators.js +30 -0
  81. package/dist/utils/createCheckDuplicateId.js +31 -0
  82. package/dist/utils/createCounter.js +33 -0
  83. package/dist/utils/createPluginTypesMap.js +106 -0
  84. package/dist/utils/formatErrorMessage.js +56 -0
  85. package/dist/utils/readConfigFile.js +24 -0
  86. package/dist/utils/writeBuildArtifact.js +23 -0
  87. package/package.json +56 -23
  88. package/dist/138.index.js +0 -2
  89. package/dist/138.index.js.LICENSE.txt +0 -3
  90. package/dist/231.index.js +0 -1
  91. package/dist/319.index.js +0 -1
  92. package/dist/35.index.js +0 -1
  93. package/dist/422.index.js +0 -1
  94. package/dist/443.index.js +0 -1
  95. package/dist/449.index.js +0 -1
  96. package/dist/5.index.js +0 -2
  97. package/dist/5.index.js.LICENSE.txt +0 -1
  98. package/dist/564.index.js +0 -1
  99. package/dist/569.index.js +0 -1
  100. package/dist/625.index.js +0 -1
  101. package/dist/693.index.js +0 -2
  102. package/dist/693.index.js.LICENSE.txt +0 -1
  103. package/dist/734.index.js +0 -1
  104. package/dist/904.index.js +0 -1
  105. package/dist/remoteEntry.js +0 -1
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import buildIconImports from './buildIconImports.js';
16
+ import buildStyleImports from './buildStyleImports.js';
17
+ function buildImportClassProd(types) {
18
+ return Object.entries(types).map(([typeName, type])=>({
19
+ originalTypeName: type.originalTypeName,
20
+ package: type.package,
21
+ typeName
22
+ })
23
+ );
24
+ }
25
+ function buildImportsProd({ components , context }) {
26
+ const blocks = buildImportClassProd(components.types.blocks);
27
+ return {
28
+ actions: buildImportClassProd(components.types.actions),
29
+ auth: {
30
+ callbacks: buildImportClassProd(components.types.auth.callbacks),
31
+ events: buildImportClassProd(components.types.auth.events),
32
+ providers: buildImportClassProd(components.types.auth.providers)
33
+ },
34
+ blocks,
35
+ connections: buildImportClassProd(components.types.connections),
36
+ icons: buildIconImports({
37
+ blocks,
38
+ components,
39
+ context
40
+ }),
41
+ requests: buildImportClassProd(components.types.requests),
42
+ operators: {
43
+ client: buildImportClassProd(components.types.operators.client),
44
+ server: buildImportClassProd(components.types.operators.server)
45
+ },
46
+ styles: buildStyleImports({
47
+ blocks,
48
+ context
49
+ })
50
+ };
51
+ }
52
+ export default buildImportsProd;
@@ -0,0 +1,28 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function buildStyleImports({ blocks , context }) {
16
+ const styles = new Set();
17
+ blocks.forEach((block)=>{
18
+ styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`
19
+ ));
20
+ styles.add(...(context.typesMap.styles.blocks[block.typeName] || []).map((style)=>`${block.package}/${style}`
21
+ ));
22
+ });
23
+ return [
24
+ ...styles
25
+ ].filter((style)=>!!style
26
+ );
27
+ }
28
+ export default buildStyleImports;
@@ -0,0 +1,122 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ 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,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import buildEvents from './buildEvents.js';
16
+ import buildRequests from './buildRequests.js';
17
+ import buildSubBlocks from './buildSubBlocks.js';
18
+ import countBlockOperators from './countBlockOperators.js';
19
+ import countBlockTypes from './countBlockTypes.js';
20
+ import moveSubBlocksToArea from './moveSubBlocksToArea.js';
21
+ import moveSkeletonBlocksToArea from './moveSkeletonBlocksToArea.js';
22
+ import setBlockId from './setBlockId.js';
23
+ import validateBlock from './validateBlock.js';
24
+ async function buildBlock(block, pageContext) {
25
+ validateBlock(block, pageContext);
26
+ setBlockId(block, pageContext);
27
+ countBlockOperators(block, pageContext);
28
+ buildEvents(block, pageContext);
29
+ buildRequests(block, pageContext);
30
+ moveSubBlocksToArea(block, pageContext);
31
+ moveSkeletonBlocksToArea(block, pageContext);
32
+ countBlockTypes(block, pageContext);
33
+ await buildSubBlocks(block, pageContext);
34
+ }
35
+ export default buildBlock;
@@ -0,0 +1,75 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ 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.isNone(block.events[key].catch)) {
48
+ block.events[key].catch = [];
49
+ }
50
+ if (!type.isArray(block.events[key].catch)) {
51
+ 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)}`);
52
+ }
53
+ const checkDuplicateActionId = createCheckDuplicateId({
54
+ message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
55
+ });
56
+ block.events[key].try.map((action)=>checkAction(action, {
57
+ eventId: key,
58
+ blockId: block.blockId,
59
+ typeCounters: pageContext.typeCounters,
60
+ pageId: pageContext.pageId,
61
+ checkDuplicateActionId
62
+ })
63
+ );
64
+ block.events[key].catch.map((action)=>checkAction(action, {
65
+ eventId: key,
66
+ blockId: block.blockId,
67
+ typeCounters: pageContext.typeCounters,
68
+ pageId: pageContext.pageId,
69
+ checkDuplicateActionId
70
+ })
71
+ );
72
+ });
73
+ }
74
+ }
75
+ export default buildEvents;
@@ -0,0 +1,51 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ 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
+ if (!type.isObject(request.payload)) {
37
+ throw new Error(`Request "${request.id}" at page "${pageId}" payload should be an object.`);
38
+ }
39
+ request.auth = auth;
40
+ request.requestId = request.id;
41
+ request.pageId = pageId;
42
+ request.id = `request:${pageId}:${request.id}`;
43
+ pageContext.requests.push(request);
44
+ }
45
+ function buildRequests(block, pageContext) {
46
+ (block.requests || []).forEach((request)=>{
47
+ buildRequest(request, pageContext);
48
+ });
49
+ delete block.requests;
50
+ }
51
+ export default buildRequests;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ 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,31 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import countOperators from '../../../utils/countOperators.js';
16
+ function countBlockOperators(block, { typeCounters }) {
17
+ // eslint-disable-next-line no-unused-vars
18
+ const { requests , areas , blocks , ...webBlock } = block;
19
+ countOperators(webBlock, {
20
+ counter: typeCounters.operators.client
21
+ });
22
+ (requests || []).forEach((request)=>{
23
+ countOperators(request.payload || {}, {
24
+ counter: typeCounters.operators.client
25
+ });
26
+ countOperators(request.properties || {}, {
27
+ counter: typeCounters.operators.server
28
+ });
29
+ });
30
+ }
31
+ export default countBlockOperators;
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function countBlockTypes(block, { typeCounters }) {
16
+ typeCounters.blocks.increment(block.type);
17
+ }
18
+ export default countBlockTypes;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { set, type } from '@lowdefy/helpers';
16
+ function recMoveSkeletonBlocksToArea(block1, blockId, pageId) {
17
+ if (!type.isNone(block1.blocks)) {
18
+ if (!type.isArray(block1.blocks)) {
19
+ throw new Error(`Skeleton blocks at ${blockId} on page ${pageId} is not an array. Received ${JSON.stringify(block1.blocks)}`);
20
+ }
21
+ set(block1, 'areas.content.blocks', block1.blocks);
22
+ delete block1.blocks;
23
+ }
24
+ Object.keys(block1.areas || {}).forEach((area)=>{
25
+ block1.areas[area].blocks.forEach((block, i)=>{
26
+ recMoveSkeletonBlocksToArea(block, `${blockId}.areas.${area}.${i}.blocks`, pageId);
27
+ });
28
+ });
29
+ }
30
+ function moveSkeletonBlocksToArea(block, pageContext) {
31
+ if (type.isObject(block.skeleton)) {
32
+ recMoveSkeletonBlocksToArea(block.skeleton, `${block.blockId}.skeleton`, pageContext.pageId);
33
+ }
34
+ }
35
+ export default moveSkeletonBlocksToArea;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { set, type } from '@lowdefy/helpers';
16
+ function moveSubBlocksToArea(block, pageContext) {
17
+ if (!type.isNone(block.blocks)) {
18
+ if (!type.isArray(block.blocks)) {
19
+ throw new Error(`Blocks at ${block.blockId} on page ${pageContext.pageId} is not an array. Received ${JSON.stringify(block.blocks)}`);
20
+ }
21
+ set(block, 'areas.content.blocks', block.blocks);
22
+ delete block.blocks;
23
+ }
24
+ }
25
+ export default moveSubBlocksToArea;
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function setBlockId(block, { pageId , blockIdCounter }) {
16
+ block.blockId = block.id;
17
+ block.id = `block:${pageId}:${block.blockId}:${blockIdCounter.getCount(block.blockId)}`;
18
+ blockIdCounter.increment(block.blockId);
19
+ }
20
+ export default setBlockId;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ function validateBlock(block, { pageId }) {
17
+ if (!type.isObject(block)) {
18
+ throw new Error(`Expected block to be an object on page "${pageId}". Received ${JSON.stringify(block)}.`);
19
+ }
20
+ if (type.isUndefined(block.id)) {
21
+ throw new Error(`Block id missing at page "${pageId}".`);
22
+ }
23
+ if (!type.isString(block.id)) {
24
+ throw new Error(`Block id is not a string at page "${pageId}". Received ${JSON.stringify(block.id)}.`);
25
+ }
26
+ if (type.isNone(block.type)) {
27
+ throw new Error(`Block type is not defined at "${block.id}" on page "${pageId}".`);
28
+ }
29
+ if (!type.isString(block.type)) {
30
+ throw new Error(`Block type is not a string at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.type)}.`);
31
+ }
32
+ if (!type.isNone(block.requests)) {
33
+ if (!type.isArray(block.requests)) {
34
+ throw new Error(`Requests is not an array at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.requests)}`);
35
+ }
36
+ }
37
+ }
38
+ export default validateBlock;
@@ -0,0 +1,50 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import buildBlock from './buildBlock/buildBlock.js';
17
+ import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
+ import createCounter from '../../utils/createCounter.js';
19
+ async function buildPage({ page , index , context , checkDuplicatePageId }) {
20
+ if (type.isUndefined(page.id)) {
21
+ throw new Error(`Page id missing at page ${index}.`);
22
+ }
23
+ if (!type.isString(page.id)) {
24
+ throw new Error(`Page id is not a string at page ${index}. Received ${JSON.stringify(page.id)}.`);
25
+ }
26
+ checkDuplicatePageId({
27
+ id: page.id
28
+ });
29
+ page.pageId = page.id;
30
+ const requests = [];
31
+ const operators = new Set();
32
+ await buildBlock(page, {
33
+ auth: page.auth,
34
+ blockIdCounter: createCounter(),
35
+ checkDuplicateRequestId: createCheckDuplicateId({
36
+ message: 'Duplicate requestId "{{ id }}" on page "{{ pageId }}".'
37
+ }),
38
+ operators,
39
+ pageId: page.pageId,
40
+ requests,
41
+ typeCounters: context.typeCounters
42
+ });
43
+ // set page.id since buildBlock sets id as well.
44
+ page.id = `page:${page.pageId}`;
45
+ page.requests = requests;
46
+ page.operators = [
47
+ ...operators
48
+ ];
49
+ }
50
+ export default buildPage;
@@ -0,0 +1,33 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import buildPage from './buildPage.js';
17
+ import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
+ async function buildPages({ components , context }) {
19
+ const pages = type.isArray(components.pages) ? components.pages : [];
20
+ const checkDuplicatePageId = createCheckDuplicateId({
21
+ message: 'Duplicate pageId "{{ id }}".'
22
+ });
23
+ const pageBuildPromises = pages.map((page, index)=>buildPage({
24
+ page,
25
+ index,
26
+ context,
27
+ checkDuplicatePageId
28
+ })
29
+ );
30
+ await Promise.all(pageBuildPromises);
31
+ return components;
32
+ }
33
+ export default buildPages;