@lowdefy/build 4.0.0-alpha.29 → 4.0.0-alpha.30

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 (91) hide show
  1. package/dist/build/addDefaultPages/404.js +51 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +43 -0
  3. package/dist/build/buildAuth/buildAuth.js +34 -0
  4. package/dist/build/buildAuth/buildAuthPlugins.js +71 -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 +28 -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 +83 -0
  11. package/dist/build/buildImports/buildImports.js +30 -0
  12. package/dist/build/buildImports/buildImportsDev.js +106 -0
  13. package/dist/build/buildImports/buildImportsProd.js +54 -0
  14. package/dist/build/buildImports/buildStyleImports.js +25 -0
  15. package/dist/build/buildImports/defaultIconsDev.js +584 -0
  16. package/dist/build/buildImports/defaultIconsProd.js +21 -0
  17. package/dist/build/buildMenu.js +118 -0
  18. package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
  19. package/dist/build/buildPages/buildBlock/buildEvents.js +76 -0
  20. package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
  21. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +30 -0
  22. package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
  23. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  24. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  25. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
  26. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  27. package/dist/build/buildPages/buildBlock/validateBlock.js +38 -0
  28. package/dist/build/buildPages/buildPage.js +50 -0
  29. package/dist/build/buildPages/buildPages.js +31 -0
  30. package/dist/build/buildPages/buildTestPage.js +46 -0
  31. package/dist/build/buildRefs/buildRefs.js +32 -0
  32. package/dist/build/buildRefs/evaluateBuildOperators.js +34 -0
  33. package/dist/build/buildRefs/getConfigFile.js +28 -0
  34. package/dist/build/buildRefs/getRefContent.js +44 -0
  35. package/dist/build/buildRefs/getRefPath.js +30 -0
  36. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  37. package/dist/build/buildRefs/getUserJavascriptFunction.js +24 -0
  38. package/dist/build/buildRefs/makeRefDefinition.js +30 -0
  39. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  40. package/dist/build/buildRefs/parseRefContent.js +37 -0
  41. package/dist/build/buildRefs/populateRefs.js +43 -0
  42. package/dist/build/buildRefs/recursiveBuild.js +68 -0
  43. package/dist/build/buildRefs/runRefResolver.js +33 -0
  44. package/dist/build/buildRefs/runTransformer.js +30 -0
  45. package/dist/build/buildTypes.js +124 -0
  46. package/dist/build/cleanBuildDirectory.js +19 -0
  47. package/dist/build/copyPublicFolder.js +23 -0
  48. package/dist/build/testSchema.js +32 -0
  49. package/dist/build/updateServerPackageJson.js +50 -0
  50. package/dist/build/validateApp.js +34 -0
  51. package/dist/build/validateConfig.js +33 -0
  52. package/dist/build/writeApp.js +18 -0
  53. package/dist/build/writeAuth.js +18 -0
  54. package/dist/build/writeConfig.js +18 -0
  55. package/dist/build/writeConnections.js +26 -0
  56. package/dist/build/writeGlobal.js +25 -0
  57. package/dist/build/writeMenus.js +22 -0
  58. package/dist/build/writePages.js +25 -0
  59. package/dist/build/writePluginImports/generateImportFile.js +31 -0
  60. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  61. package/dist/build/writePluginImports/writeAuthImports.js +34 -0
  62. package/dist/build/writePluginImports/writeBlockImports.js +22 -0
  63. package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
  64. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  65. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  66. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  67. package/dist/build/writePluginImports/writeStyleImports.js +28 -0
  68. package/dist/build/writeRequests.js +31 -0
  69. package/dist/build/writeTypes.js +18 -0
  70. package/dist/createContext.js +55 -0
  71. package/dist/defaultTypesMap.js +2046 -0
  72. package/dist/index.js +139 -0
  73. package/dist/lowdefySchema.js +841 -0
  74. package/dist/scripts/generateDefaultTypes.js +88 -0
  75. package/dist/scripts/run.js +33 -0
  76. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
  77. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  78. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  79. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  80. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  81. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  82. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  83. package/dist/test/testContext.js +54 -0
  84. package/dist/utils/countOperators.js +30 -0
  85. package/dist/utils/createCheckDuplicateId.js +31 -0
  86. package/dist/utils/createCounter.js +33 -0
  87. package/dist/utils/createPluginTypesMap.js +113 -0
  88. package/dist/utils/formatErrorMessage.js +56 -0
  89. package/dist/utils/readConfigFile.js +24 -0
  90. package/dist/utils/writeBuildArtifact.js +23 -0
  91. package/package.json +36 -36
@@ -0,0 +1,118 @@
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
+ 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
+ })).filter((page)=>page.pageId !== '404')
29
+ },
30
+ ];
31
+ return menus;
32
+ }
33
+ function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplicateMenuItemId }) {
34
+ if (type.isArray(parent.links)) {
35
+ parent.links.forEach((menuItem)=>{
36
+ if (menuItem.type === 'MenuLink') {
37
+ if (type.isString(menuItem.pageId)) {
38
+ const page = pages.find((pg)=>pg.pageId === menuItem.pageId);
39
+ if (!page) {
40
+ missingPageWarnings.push({
41
+ menuItemId: menuItem.id,
42
+ pageId: menuItem.pageId
43
+ });
44
+ // remove menuItem from menu
45
+ menuItem.remove = true;
46
+ return;
47
+ } else {
48
+ menuItem.auth = page.auth;
49
+ }
50
+ } else {
51
+ menuItem.auth = {
52
+ public: true
53
+ };
54
+ }
55
+ }
56
+ if (menuItem.type === 'MenuGroup') {
57
+ menuItem.auth = {
58
+ public: true
59
+ };
60
+ }
61
+ checkDuplicateMenuItemId({
62
+ id: menuItem.id,
63
+ menuId
64
+ });
65
+ menuItem.menuItemId = menuItem.id;
66
+ menuItem.id = `menuitem:${menuId}:${menuItem.id}`;
67
+ loopItems({
68
+ parent: menuItem,
69
+ menuId,
70
+ pages,
71
+ missingPageWarnings,
72
+ checkDuplicateMenuItemId
73
+ });
74
+ });
75
+ parent.links = parent.links.filter((item)=>item.remove !== true);
76
+ }
77
+ }
78
+ function buildMenu({ components , context }) {
79
+ const pages = type.isArray(components.pages) ? components.pages : [];
80
+ if (type.isUndefined(components.menus) || components.menus.length === 0) {
81
+ components.menus = buildDefaultMenu({
82
+ components,
83
+ context
84
+ });
85
+ }
86
+ const missingPageWarnings = [];
87
+ const checkDuplicateMenuId = createCheckDuplicateId({
88
+ message: 'Duplicate menuId "{{ id }}".'
89
+ });
90
+ components.menus.forEach((menu)=>{
91
+ if (type.isUndefined(menu.id)) {
92
+ throw new Error(`Menu id missing.`);
93
+ }
94
+ if (!type.isString(menu.id)) {
95
+ throw new Error(`Menu id is not a string. Received ${JSON.stringify(menu.id)}.`);
96
+ }
97
+ checkDuplicateMenuId({
98
+ id: menu.id
99
+ });
100
+ menu.menuId = menu.id;
101
+ menu.id = `menu:${menu.id}`;
102
+ const checkDuplicateMenuItemId = createCheckDuplicateId({
103
+ message: 'Duplicate menuItemId "{{ id }}" on menu "{{ menuId }}".'
104
+ });
105
+ loopItems({
106
+ parent: menu,
107
+ menuId: menu.menuId,
108
+ pages,
109
+ missingPageWarnings,
110
+ checkDuplicateMenuItemId
111
+ });
112
+ });
113
+ missingPageWarnings.map(async (warning)=>{
114
+ context.logger.warn(`Page "${warning.pageId}" referenced in menu link "${warning.menuItemId}" not found.`);
115
+ });
116
+ return components;
117
+ }
118
+ 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
+ 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
+ buildSubBlocks(block, pageContext);
34
+ }
35
+ export default buildBlock;
@@ -0,0 +1,76 @@
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]) && !type.isObject(block.events[key]) || type.isObject(block.events[key]) && type.isNone(block.events[key].try)) {
39
+ throw new Error(`Actions must be an array at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
40
+ }
41
+ if (type.isArray(block.events[key])) {
42
+ block.events[key] = {
43
+ try: block.events[key],
44
+ catch: []
45
+ };
46
+ }
47
+ if (!type.isArray(block.events[key].try)) {
48
+ throw new Error(`Try actions must be an array at "${block.blockId}" in event "${key}.try" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
49
+ }
50
+ if (type.isNone(block.events[key].catch)) {
51
+ block.events[key].catch = [];
52
+ }
53
+ if (!type.isArray(block.events[key].catch)) {
54
+ throw new Error(`Catch actions must be an array at "${block.blockId}" in event "${key}.catch" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
55
+ }
56
+ const checkDuplicateActionId = createCheckDuplicateId({
57
+ message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
58
+ });
59
+ block.events[key].try.map((action)=>checkAction(action, {
60
+ eventId: key,
61
+ blockId: block.blockId,
62
+ typeCounters: pageContext.typeCounters,
63
+ pageId: pageContext.pageId,
64
+ checkDuplicateActionId
65
+ }));
66
+ block.events[key].catch.map((action)=>checkAction(action, {
67
+ eventId: key,
68
+ blockId: block.blockId,
69
+ typeCounters: pageContext.typeCounters,
70
+ pageId: pageContext.pageId,
71
+ checkDuplicateActionId
72
+ }));
73
+ });
74
+ }
75
+ }
76
+ 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,30 @@
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
+ function buildSubBlocks(block, pageContext) {
18
+ if (type.isObject(block.areas)) {
19
+ Object.keys(block.areas).forEach((key)=>{
20
+ if (type.isNone(block.areas[key].blocks)) {
21
+ block.areas[key].blocks = [];
22
+ }
23
+ if (!type.isArray(block.areas[key].blocks)) {
24
+ 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)}`);
25
+ }
26
+ block.areas[key].blocks.map((blk)=>buildBlock(blk, pageContext));
27
+ });
28
+ }
29
+ }
30
+ 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
+ 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
+ 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,31 @@
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
+ function buildPages({ components , context }) {
19
+ const pages = type.isArray(components.pages) ? components.pages : [];
20
+ const checkDuplicatePageId = createCheckDuplicateId({
21
+ message: 'Duplicate pageId "{{ id }}".'
22
+ });
23
+ pages.map((page, index)=>buildPage({
24
+ page,
25
+ index,
26
+ context,
27
+ checkDuplicatePageId
28
+ }));
29
+ return components;
30
+ }
31
+ export default buildPages;
@@ -0,0 +1,46 @@
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
+ */ // Used in @lowdefy/engine tests
16
+ import buildAuth from '../buildAuth/buildAuth.js';
17
+ import buildPages from './buildPages.js';
18
+ import createContext from '../../createContext.js';
19
+ function buildTestPage({ pageConfig }) {
20
+ const context = createContext({
21
+ customTypesMap: {},
22
+ directories: {},
23
+ logger: {
24
+ debug: ()=>{},
25
+ log: ()=>{},
26
+ warn: ()=>{},
27
+ error: ()=>{}
28
+ },
29
+ stage: 'test'
30
+ });
31
+ const components = {
32
+ pages: [
33
+ pageConfig
34
+ ]
35
+ };
36
+ buildAuth({
37
+ components,
38
+ context
39
+ });
40
+ buildPages({
41
+ components,
42
+ context
43
+ });
44
+ return components.pages[0];
45
+ }
46
+ export default buildTestPage;
@@ -0,0 +1,32 @@
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 recursiveBuild from './recursiveBuild.js';
16
+ import makeRefDefinition from './makeRefDefinition.js';
17
+ import evaluateBuildOperators from './evaluateBuildOperators.js';
18
+ async function buildRefs({ context }) {
19
+ const refDef = makeRefDefinition('lowdefy.yaml');
20
+ let components = await recursiveBuild({
21
+ context,
22
+ refDef,
23
+ count: 0
24
+ });
25
+ components = await evaluateBuildOperators({
26
+ context,
27
+ input: components,
28
+ refDef
29
+ });
30
+ return components ?? {};
31
+ }
32
+ export default buildRefs;