@lowdefy/build 4.0.0-alpha.9 → 4.0.0-rc.1
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.
- package/dist/build/addDefaultPages/404.js +4 -4
- package/dist/build/addDefaultPages/addDefaultPages.js +3 -4
- package/dist/build/buildAuth/buildAuth.js +12 -28
- package/dist/build/buildAuth/buildAuthPlugins.js +71 -0
- package/dist/build/buildAuth/buildPageAuth.js +50 -0
- package/dist/build/buildAuth/getPageRoles.js +2 -2
- package/dist/build/buildAuth/getProtectedPages.js +7 -9
- package/dist/build/buildAuth/validateAuthConfig.js +64 -0
- package/dist/build/buildConnections.js +2 -2
- package/dist/build/{buildIcons.js → buildImports/buildIconImports.js} +26 -29
- package/dist/build/buildImports/buildImports.js +30 -0
- package/dist/build/buildImports/buildImportsDev.js +106 -0
- package/dist/build/buildImports/buildImportsProd.js +54 -0
- package/dist/build/{buildStyles.js → buildImports/buildStyleImports.js} +8 -12
- package/dist/build/buildImports/defaultIconsDev.js +584 -0
- package/dist/build/buildImports/defaultIconsProd.js +21 -0
- package/dist/build/buildMenu.js +11 -15
- package/dist/build/buildPages/buildBlock/buildBlock.js +3 -3
- package/dist/build/buildPages/buildBlock/buildEvents.js +8 -7
- package/dist/build/buildPages/buildBlock/buildRequests.js +1 -1
- package/dist/build/buildPages/buildBlock/buildSubBlocks.js +3 -8
- package/dist/build/buildPages/buildBlock/countBlockOperators.js +1 -1
- package/dist/build/buildPages/buildBlock/countBlockTypes.js +1 -1
- package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +9 -9
- package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +1 -1
- package/dist/build/buildPages/buildBlock/setBlockId.js +1 -1
- package/dist/build/buildPages/buildBlock/validateBlock.js +1 -1
- package/dist/build/buildPages/buildPage.js +3 -3
- package/dist/build/buildPages/buildPages.js +4 -6
- package/dist/build/buildPages/buildTestPage.js +46 -0
- package/dist/build/buildRefs/buildRefs.js +11 -5
- package/dist/build/buildRefs/evaluateBuildOperators.js +3 -4
- package/dist/build/buildRefs/getConfigFile.js +2 -2
- package/dist/build/buildRefs/getKey.js +24 -0
- package/dist/build/buildRefs/getRefContent.js +1 -1
- package/dist/build/buildRefs/getRefPath.js +1 -1
- package/dist/build/buildRefs/getRefsFromFile.js +1 -1
- package/dist/build/buildRefs/getUserJavascriptFunction.js +3 -2
- package/dist/build/buildRefs/makeRefDefinition.js +2 -1
- package/dist/build/buildRefs/parseNunjucks.js +1 -1
- package/dist/build/buildRefs/parseRefContent.js +4 -4
- package/dist/build/buildRefs/populateRefs.js +4 -4
- package/dist/build/buildRefs/recursiveBuild.js +9 -5
- package/dist/build/buildRefs/runRefResolver.js +1 -1
- package/dist/build/buildRefs/runTransformer.js +1 -1
- package/dist/build/buildTypes.js +33 -5
- package/dist/build/cleanBuildDirectory.js +1 -1
- package/dist/build/copyPublicFolder.js +7 -4
- package/dist/build/testSchema.js +5 -7
- package/dist/build/updateServerPackageJson.js +5 -1
- package/dist/build/validateApp.js +2 -2
- package/dist/build/validateConfig.js +2 -29
- package/dist/build/writeApp.js +1 -1
- package/dist/build/writeAuth.js +18 -0
- package/dist/build/writeConfig.js +1 -1
- package/dist/build/writeConnections.js +1 -1
- package/dist/build/writeGlobal.js +1 -1
- package/dist/build/writeMenus.js +1 -1
- package/dist/build/writePages.js +2 -3
- package/dist/build/writePluginImports/generateImportFile.js +2 -7
- package/dist/build/writePluginImports/writeActionImports.js +2 -2
- package/dist/build/writePluginImports/writeAuthImports.js +34 -0
- package/dist/build/writePluginImports/writeBlockImports.js +2 -2
- package/dist/build/writePluginImports/writeConnectionImports.js +2 -2
- package/dist/build/writePluginImports/writeIconImports.js +2 -2
- package/dist/build/writePluginImports/writeOperatorImports.js +5 -5
- package/dist/build/writePluginImports/writePluginImports.js +52 -0
- package/dist/build/writePluginImports/writeStyleImports.js +9 -3
- package/dist/build/writeRequests.js +2 -3
- package/dist/build/writeTypes.js +1 -1
- package/dist/createContext.js +55 -0
- package/dist/{defaultTypesMap.json → defaultTypesMap.js} +922 -405
- package/dist/index.js +20 -78
- package/dist/lowdefySchema.js +176 -68
- package/dist/scripts/generateDefaultTypes.js +21 -3
- package/dist/scripts/run.js +5 -4
- package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +1 -1
- package/dist/test/buildRefs/testBuildRefsErrorResolver.js +1 -1
- package/dist/test/buildRefs/testBuildRefsNullResolver.js +1 -1
- package/dist/test/buildRefs/testBuildRefsParsingResolver.js +1 -1
- package/dist/test/buildRefs/testBuildRefsResolver.js +2 -2
- package/dist/test/buildRefs/testBuildRefsTransform.js +1 -1
- package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +1 -1
- package/dist/test/testContext.js +8 -2
- package/dist/utils/countOperators.js +1 -1
- package/dist/utils/createCheckDuplicateId.js +1 -1
- package/dist/utils/createCounter.js +1 -1
- package/dist/utils/createPluginTypesMap.js +29 -1
- package/dist/utils/formatErrorMessage.js +1 -1
- package/dist/utils/readConfigFile.js +5 -2
- package/dist/utils/writeBuildArtifact.js +1 -1
- package/package.json +56 -45
package/dist/build/buildMenu.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
|
|
17
|
-
|
|
17
|
+
function buildDefaultMenu({ components , context }) {
|
|
18
18
|
context.logger.warn('No menus found. Building default menu.');
|
|
19
19
|
const pages = type.isArray(components.pages) ? components.pages : [];
|
|
20
20
|
const menus = [
|
|
@@ -25,10 +25,8 @@ async function buildDefaultMenu({ components , context }) {
|
|
|
25
25
|
type: 'MenuLink',
|
|
26
26
|
pageId: page.pageId,
|
|
27
27
|
auth: page.auth
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
},
|
|
28
|
+
})).filter((page)=>page.pageId !== '404')
|
|
29
|
+
}
|
|
32
30
|
];
|
|
33
31
|
return menus;
|
|
34
32
|
}
|
|
@@ -37,8 +35,7 @@ function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplic
|
|
|
37
35
|
parent.links.forEach((menuItem)=>{
|
|
38
36
|
if (menuItem.type === 'MenuLink') {
|
|
39
37
|
if (type.isString(menuItem.pageId)) {
|
|
40
|
-
const page = pages.find((pg)=>pg.pageId === menuItem.pageId
|
|
41
|
-
);
|
|
38
|
+
const page = pages.find((pg)=>pg.pageId === menuItem.pageId);
|
|
42
39
|
if (!page) {
|
|
43
40
|
missingPageWarnings.push({
|
|
44
41
|
menuItemId: menuItem.id,
|
|
@@ -75,14 +72,13 @@ function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplic
|
|
|
75
72
|
checkDuplicateMenuItemId
|
|
76
73
|
});
|
|
77
74
|
});
|
|
78
|
-
parent.links = parent.links.filter((item)=>item.remove !== true
|
|
79
|
-
);
|
|
75
|
+
parent.links = parent.links.filter((item)=>item.remove !== true);
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
|
-
|
|
78
|
+
function buildMenu({ components , context }) {
|
|
83
79
|
const pages = type.isArray(components.pages) ? components.pages : [];
|
|
84
80
|
if (type.isUndefined(components.menus) || components.menus.length === 0) {
|
|
85
|
-
components.menus =
|
|
81
|
+
components.menus = buildDefaultMenu({
|
|
86
82
|
components,
|
|
87
83
|
context
|
|
88
84
|
});
|
|
@@ -114,9 +110,9 @@ async function buildMenu({ components , context }) {
|
|
|
114
110
|
checkDuplicateMenuItemId
|
|
115
111
|
});
|
|
116
112
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
})
|
|
113
|
+
missingPageWarnings.map(async (warning)=>{
|
|
114
|
+
context.logger.warn(`Page "${warning.pageId}" referenced in menu link "${warning.menuItemId}" not found.`);
|
|
115
|
+
});
|
|
120
116
|
return components;
|
|
121
117
|
}
|
|
122
118
|
export default buildMenu;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -21,7 +21,7 @@ import moveSubBlocksToArea from './moveSubBlocksToArea.js';
|
|
|
21
21
|
import moveSkeletonBlocksToArea from './moveSkeletonBlocksToArea.js';
|
|
22
22
|
import setBlockId from './setBlockId.js';
|
|
23
23
|
import validateBlock from './validateBlock.js';
|
|
24
|
-
|
|
24
|
+
function buildBlock(block, pageContext) {
|
|
25
25
|
validateBlock(block, pageContext);
|
|
26
26
|
setBlockId(block, pageContext);
|
|
27
27
|
countBlockOperators(block, pageContext);
|
|
@@ -30,6 +30,6 @@ async function buildBlock(block, pageContext) {
|
|
|
30
30
|
moveSubBlocksToArea(block, pageContext);
|
|
31
31
|
moveSkeletonBlocksToArea(block, pageContext);
|
|
32
32
|
countBlockTypes(block, pageContext);
|
|
33
|
-
|
|
33
|
+
buildSubBlocks(block, pageContext);
|
|
34
34
|
}
|
|
35
35
|
export default buildBlock;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -35,6 +35,9 @@ function checkAction(action, { blockId , checkDuplicateActionId , eventId , page
|
|
|
35
35
|
function buildEvents(block, pageContext) {
|
|
36
36
|
if (block.events) {
|
|
37
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
|
+
}
|
|
38
41
|
if (type.isArray(block.events[key])) {
|
|
39
42
|
block.events[key] = {
|
|
40
43
|
try: block.events[key],
|
|
@@ -42,13 +45,13 @@ function buildEvents(block, pageContext) {
|
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
if (!type.isArray(block.events[key].try)) {
|
|
45
|
-
throw new Error(`
|
|
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)}`);
|
|
46
49
|
}
|
|
47
50
|
if (type.isNone(block.events[key].catch)) {
|
|
48
51
|
block.events[key].catch = [];
|
|
49
52
|
}
|
|
50
53
|
if (!type.isArray(block.events[key].catch)) {
|
|
51
|
-
throw new Error(`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)}`);
|
|
52
55
|
}
|
|
53
56
|
const checkDuplicateActionId = createCheckDuplicateId({
|
|
54
57
|
message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
|
|
@@ -59,16 +62,14 @@ function buildEvents(block, pageContext) {
|
|
|
59
62
|
typeCounters: pageContext.typeCounters,
|
|
60
63
|
pageId: pageContext.pageId,
|
|
61
64
|
checkDuplicateActionId
|
|
62
|
-
})
|
|
63
|
-
);
|
|
65
|
+
}));
|
|
64
66
|
block.events[key].catch.map((action)=>checkAction(action, {
|
|
65
67
|
eventId: key,
|
|
66
68
|
blockId: block.blockId,
|
|
67
69
|
typeCounters: pageContext.typeCounters,
|
|
68
70
|
pageId: pageContext.pageId,
|
|
69
71
|
checkDuplicateActionId
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
+
}));
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import buildBlock from './buildBlock.js';
|
|
17
|
-
|
|
17
|
+
function buildSubBlocks(block, pageContext) {
|
|
18
18
|
if (type.isObject(block.areas)) {
|
|
19
|
-
let promises = [];
|
|
20
19
|
Object.keys(block.areas).forEach((key)=>{
|
|
21
20
|
if (type.isNone(block.areas[key].blocks)) {
|
|
22
21
|
block.areas[key].blocks = [];
|
|
@@ -24,12 +23,8 @@ async function buildSubBlocks(block, pageContext) {
|
|
|
24
23
|
if (!type.isArray(block.areas[key].blocks)) {
|
|
25
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)}`);
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
await buildBlock(blk, pageContext);
|
|
29
|
-
});
|
|
30
|
-
promises = promises.concat(blockPromises);
|
|
26
|
+
block.areas[key].blocks.map((blk)=>buildBlock(blk, pageContext));
|
|
31
27
|
});
|
|
32
|
-
await Promise.all(promises);
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
export default buildSubBlocks;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { set, type } from '@lowdefy/helpers';
|
|
16
|
-
function recMoveSkeletonBlocksToArea(
|
|
17
|
-
if (!type.isNone(
|
|
18
|
-
if (!type.isArray(
|
|
19
|
-
throw new Error(`Skeleton blocks at ${blockId} on page ${pageId} is not an array. Received ${JSON.stringify(
|
|
16
|
+
function recMoveSkeletonBlocksToArea(block, blockId, pageId) {
|
|
17
|
+
if (!type.isNone(block.blocks)) {
|
|
18
|
+
if (!type.isArray(block.blocks)) {
|
|
19
|
+
throw new Error(`Skeleton blocks at ${blockId} on page ${pageId} is not an array. Received ${JSON.stringify(block.blocks)}`);
|
|
20
20
|
}
|
|
21
|
-
set(
|
|
22
|
-
delete
|
|
21
|
+
set(block, 'areas.content.blocks', block.blocks);
|
|
22
|
+
delete block.blocks;
|
|
23
23
|
}
|
|
24
|
-
Object.keys(
|
|
25
|
-
|
|
24
|
+
Object.keys(block.areas || {}).forEach((area)=>{
|
|
25
|
+
block.areas[area].blocks.forEach((block, i)=>{
|
|
26
26
|
recMoveSkeletonBlocksToArea(block, `${blockId}.areas.${area}.${i}.blocks`, pageId);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import buildBlock from './buildBlock/buildBlock.js';
|
|
17
17
|
import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
|
|
18
18
|
import createCounter from '../../utils/createCounter.js';
|
|
19
|
-
|
|
19
|
+
function buildPage({ page , index , context , checkDuplicatePageId }) {
|
|
20
20
|
if (type.isUndefined(page.id)) {
|
|
21
21
|
throw new Error(`Page id missing at page ${index}.`);
|
|
22
22
|
}
|
|
@@ -29,7 +29,7 @@ async function buildPage({ page , index , context , checkDuplicatePageId }) {
|
|
|
29
29
|
page.pageId = page.id;
|
|
30
30
|
const requests = [];
|
|
31
31
|
const operators = new Set();
|
|
32
|
-
|
|
32
|
+
buildBlock(page, {
|
|
33
33
|
auth: page.auth,
|
|
34
34
|
blockIdCounter: createCounter(),
|
|
35
35
|
checkDuplicateRequestId: createCheckDuplicateId({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */ /*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,19 +15,17 @@
|
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import buildPage from './buildPage.js';
|
|
17
17
|
import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
|
|
18
|
-
|
|
18
|
+
function buildPages({ components , context }) {
|
|
19
19
|
const pages = type.isArray(components.pages) ? components.pages : [];
|
|
20
20
|
const checkDuplicatePageId = createCheckDuplicateId({
|
|
21
21
|
message: 'Duplicate pageId "{{ id }}".'
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
pages.map((page, index)=>buildPage({
|
|
24
24
|
page,
|
|
25
25
|
index,
|
|
26
26
|
context,
|
|
27
27
|
checkDuplicatePageId
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
await Promise.all(pageBuildPromises);
|
|
28
|
+
}));
|
|
31
29
|
return components;
|
|
32
30
|
}
|
|
33
31
|
export default buildPages;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // 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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,13 +14,19 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import recursiveBuild from './recursiveBuild.js';
|
|
16
16
|
import makeRefDefinition from './makeRefDefinition.js';
|
|
17
|
-
|
|
17
|
+
import evaluateBuildOperators from './evaluateBuildOperators.js';
|
|
18
18
|
async function buildRefs({ context }) {
|
|
19
|
-
const
|
|
19
|
+
const refDef = makeRefDefinition('lowdefy.yaml');
|
|
20
|
+
let components = await recursiveBuild({
|
|
20
21
|
context,
|
|
21
|
-
refDef
|
|
22
|
+
refDef,
|
|
22
23
|
count: 0
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
+
components = await evaluateBuildOperators({
|
|
26
|
+
context,
|
|
27
|
+
input: components,
|
|
28
|
+
refDef
|
|
29
|
+
});
|
|
30
|
+
return components ?? {};
|
|
25
31
|
}
|
|
26
32
|
export default buildRefs;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -21,13 +21,12 @@ async function evaluateBuildOperators({ context , input , refDef }) {
|
|
|
21
21
|
});
|
|
22
22
|
const { output , errors } = operatorsParser.parse({
|
|
23
23
|
input,
|
|
24
|
-
location: refDef.path,
|
|
24
|
+
location: refDef.path ?? refDef.resolver,
|
|
25
25
|
operatorPrefix: '_build.'
|
|
26
26
|
});
|
|
27
27
|
if (errors.length > 0) {
|
|
28
28
|
await context.logger.warn('Build operator errors.');
|
|
29
|
-
const promises = errors.map((error)=>context.logger.warn(error.message)
|
|
30
|
-
);
|
|
29
|
+
const promises = errors.map((error)=>context.logger.warn(error.message));
|
|
31
30
|
await promises;
|
|
32
31
|
}
|
|
33
32
|
return output;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,7 @@ async function getConfigFile({ context , refDef , referencedFrom }) {
|
|
|
19
19
|
_ref: refDef.original
|
|
20
20
|
})} in file ${referencedFrom}`);
|
|
21
21
|
}
|
|
22
|
-
const content = context.readConfigFile(refDef.path);
|
|
22
|
+
const content = await context.readConfigFile(refDef.path);
|
|
23
23
|
if (content === null) {
|
|
24
24
|
throw new Error(`Tried to reference file "${refDef.path}" from "${referencedFrom}", but file does not exist.`);
|
|
25
25
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { get } from '@lowdefy/helpers';
|
|
16
|
+
function getKey({ input , refDef }) {
|
|
17
|
+
if (refDef.key) {
|
|
18
|
+
return get(input, refDef.key, {
|
|
19
|
+
default: null
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
export default getKey;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
|
+
import { pathToFileURL } from 'url';
|
|
16
17
|
async function getUserJavascriptFunction({ context , filePath }) {
|
|
17
18
|
try {
|
|
18
|
-
return (await import(path.
|
|
19
|
+
return (await import(pathToFileURL(path.join(context.directories.config, filePath)))).default;
|
|
19
20
|
} catch (error) {
|
|
20
21
|
context.logger.error(`Error importing ${filePath}.`);
|
|
21
22
|
throw Error(error);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -20,6 +20,7 @@ function makeRefDefinition(refDefinition) {
|
|
|
20
20
|
id: uuid(),
|
|
21
21
|
original: refDefinition,
|
|
22
22
|
path: getRefPath(refDefinition),
|
|
23
|
+
key: get(refDefinition, 'key'),
|
|
23
24
|
resolver: get(refDefinition, 'resolver'),
|
|
24
25
|
transformer: get(refDefinition, 'transformer'),
|
|
25
26
|
vars: get(refDefinition, 'vars', {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { type } from '@lowdefy/helpers';
|
|
15
|
+
*/ /* eslint-disable no-param-reassign */ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
|
|
17
17
|
import JSON5 from 'json5';
|
|
18
18
|
import YAML from 'yaml';
|
|
@@ -26,10 +26,10 @@ function parseRefContent({ content , refDef }) {
|
|
|
26
26
|
ext = getFileSubExtension(path);
|
|
27
27
|
}
|
|
28
28
|
if (ext === 'yaml' || ext === 'yml') {
|
|
29
|
-
|
|
29
|
+
content = YAML.parse(content);
|
|
30
30
|
}
|
|
31
31
|
if (ext === 'json') {
|
|
32
|
-
|
|
32
|
+
content = JSON5.parse(content);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
return content;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -24,12 +24,12 @@ function refReviver(key, value) {
|
|
|
24
24
|
default: null
|
|
25
25
|
})));
|
|
26
26
|
}
|
|
27
|
-
if (type.isObject(value._var) && type.isString(value._var.
|
|
28
|
-
return JSON.parse(JSON.stringify(get(this.vars, value._var.
|
|
27
|
+
if (type.isObject(value._var) && type.isString(value._var.key)) {
|
|
28
|
+
return JSON.parse(JSON.stringify(get(this.vars, value._var.key, {
|
|
29
29
|
default: type.isNone(value._var.default) ? null : value._var.default
|
|
30
30
|
})));
|
|
31
31
|
}
|
|
32
|
-
throw new Error(`"_var" operator takes a string or object with
|
|
32
|
+
throw new Error(`"_var" operator takes a string or object with "key" field as arguments. Received "${JSON.stringify(value)}"`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
return value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import evaluateBuildOperators from './evaluateBuildOperators.js';
|
|
16
|
+
import getKey from './getKey.js';
|
|
16
17
|
import getRefContent from './getRefContent.js';
|
|
17
18
|
import getRefsFromFile from './getRefsFromFile.js';
|
|
18
19
|
import populateRefs from './populateRefs.js';
|
|
@@ -33,7 +34,6 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
33
34
|
// the deeper nodes, so we can use those parsed files in references higher in the tree.
|
|
34
35
|
// To do this, since foundRefs is an array of ref definitions that are in order of the
|
|
35
36
|
// deepest nodes first we for loop over over foundRefs one by one, awaiting each result.
|
|
36
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
37
37
|
for (const newRefDef of foundRefs.values()){
|
|
38
38
|
// Parse vars and path before passing down to parse new file
|
|
39
39
|
const parsedRefDef = populateRefs({
|
|
@@ -47,17 +47,21 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
|
|
|
47
47
|
count: count + 1,
|
|
48
48
|
referencedFrom: refDef.path
|
|
49
49
|
});
|
|
50
|
-
const
|
|
50
|
+
const transformedFile = await runTransformer({
|
|
51
51
|
context,
|
|
52
52
|
input: parsedFile,
|
|
53
53
|
refDef: parsedRefDef
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
// Evaluated in recursive loop for better error messages
|
|
56
|
+
const evaluatedOperators = await evaluateBuildOperators({
|
|
56
57
|
context,
|
|
58
|
+
input: transformedFile,
|
|
59
|
+
refDef: parsedRefDef
|
|
60
|
+
});
|
|
61
|
+
parsedFiles[newRefDef.id] = getKey({
|
|
57
62
|
input: evaluatedOperators,
|
|
58
63
|
refDef: parsedRefDef
|
|
59
64
|
});
|
|
60
|
-
parsedFiles[newRefDef.id] = transformedFile;
|
|
61
65
|
}
|
|
62
66
|
return populateRefs({
|
|
63
67
|
toPopulate: fileContentBuiltRefs,
|