@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.
- package/dist/build/addDefaultPages/404.js +56 -0
- package/dist/build/addDefaultPages/addDefaultPages.js +40 -0
- package/dist/build/buildAuth/buildAuth.js +50 -0
- package/dist/build/buildAuth/getPageRoles.js +34 -0
- package/dist/build/buildAuth/getProtectedPages.js +30 -0
- package/dist/build/buildConnections.js +47 -0
- package/dist/build/buildIcons.js +63 -0
- package/dist/build/buildMenu.js +122 -0
- package/dist/build/buildPages/buildBlock/buildBlock.js +31 -0
- package/dist/build/buildPages/buildBlock/buildEvents.js +72 -0
- package/dist/build/buildPages/buildBlock/buildRequests.js +52 -0
- package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
- package/dist/build/buildPages/buildBlock/countBlockOperators.js +33 -0
- package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
- package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
- package/dist/build/buildPages/buildBlock/validateBlock.js +39 -0
- package/dist/build/buildPages/buildPage.js +50 -0
- package/dist/build/buildPages/buildPages.js +33 -0
- package/dist/build/buildRefs/buildRefs.js +26 -0
- package/dist/build/buildRefs/getConfigFile.js +28 -0
- package/dist/build/buildRefs/getRefContent.js +44 -0
- package/dist/build/buildRefs/getRefPath.js +30 -0
- package/dist/build/buildRefs/getRefsFromFile.js +37 -0
- package/dist/build/buildRefs/getUserJavascriptFunction.js +21 -0
- package/dist/build/buildRefs/makeRefDefinition.js +31 -0
- package/dist/build/buildRefs/parseNunjucks.js +20 -0
- package/dist/build/buildRefs/parseRefContent.js +37 -0
- package/dist/build/buildRefs/populateRefs.js +43 -0
- package/dist/build/buildRefs/recursiveBuild.js +63 -0
- package/dist/build/buildRefs/runRefResolver.js +33 -0
- package/dist/build/buildRefs/runTransformer.js +26 -0
- package/dist/build/buildStyles.js +29 -0
- package/dist/build/buildTypes.js +83 -0
- package/dist/build/cleanBuildDirectory.js +19 -0
- package/dist/build/testSchema.js +34 -0
- package/dist/build/validateApp.js +36 -0
- package/dist/build/validateConfig.js +53 -0
- package/dist/build/writeApp.js +22 -0
- package/dist/build/writeConfig.js +22 -0
- package/dist/build/writeConnections.js +29 -0
- package/dist/build/writeGlobal.js +29 -0
- package/dist/build/writeMenus.js +25 -0
- package/dist/build/writePages.js +37 -0
- package/dist/build/writePluginImports/writeBlockImports.js +39 -0
- package/dist/build/writePluginImports/writeConnectionImports.js +39 -0
- package/dist/build/writePluginImports/writeIconImports.js +37 -0
- package/dist/build/writePluginImports/writeStyleImports.js +30 -0
- package/dist/build/writeRequests.js +37 -0
- package/dist/build/writeTypes.js +21 -0
- package/dist/defaultTypes.json +66 -0
- package/dist/index.js +182 -1
- package/dist/lowdefySchema.js +699 -0
- package/dist/scripts/generateDefaultTypes.js +101 -0
- package/dist/scripts/run.js +25 -0
- package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +25 -0
- package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
- package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
- package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
- package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
- package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
- package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
- package/dist/test/testContext.js +55 -0
- package/dist/utils/countOperators.js +30 -0
- package/dist/utils/createCheckDuplicateId.js +31 -0
- package/dist/utils/createCounter.js +33 -0
- package/dist/utils/files/readConfigFile.js +24 -0
- package/dist/utils/files/writeBuildArtifact.js +26 -0
- package/dist/utils/formatErrorMessage.js +56 -0
- package/package.json +22 -21
- package/dist/138.index.js +0 -2
- package/dist/138.index.js.LICENSE.txt +0 -3
- package/dist/231.index.js +0 -1
- package/dist/319.index.js +0 -1
- package/dist/35.index.js +0 -1
- package/dist/422.index.js +0 -1
- package/dist/443.index.js +0 -1
- package/dist/449.index.js +0 -1
- package/dist/5.index.js +0 -2
- package/dist/5.index.js.LICENSE.txt +0 -1
- package/dist/564.index.js +0 -1
- package/dist/569.index.js +0 -1
- package/dist/625.index.js +0 -1
- package/dist/693.index.js +0 -2
- package/dist/693.index.js.LICENSE.txt +0 -1
- package/dist/734.index.js +0 -1
- package/dist/904.index.js +0 -1
- package/dist/remoteEntry.js +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
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 { 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-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 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,39 @@
|
|
|
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 validateBlock(block, { pageId , typeCounters }) {
|
|
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
|
+
typeCounters.blocks.increment(block.type);
|
|
33
|
+
if (!type.isNone(block.requests)) {
|
|
34
|
+
if (!type.isArray(block.requests)) {
|
|
35
|
+
throw new Error(`Requests is not an array at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.requests)}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export default validateBlock;
|
|
@@ -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 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-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 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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 recursiveBuild from './recursiveBuild.js';
|
|
16
|
+
import makeRefDefinition from './makeRefDefinition.js';
|
|
17
|
+
async function buildRefs({ context }) {
|
|
18
|
+
const components = await recursiveBuild({
|
|
19
|
+
context,
|
|
20
|
+
refDef: makeRefDefinition('lowdefy.yaml'),
|
|
21
|
+
count: 0
|
|
22
|
+
});
|
|
23
|
+
return components || {
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export default buildRefs;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
async function getConfigFile({ context , refDef , referencedFrom }) {
|
|
17
|
+
if (!type.isString(refDef.path)) {
|
|
18
|
+
throw new Error(`Invalid _ref definition ${JSON.stringify({
|
|
19
|
+
_ref: refDef.original
|
|
20
|
+
})} in file ${referencedFrom}`);
|
|
21
|
+
}
|
|
22
|
+
const content = context.readConfigFile(refDef.path);
|
|
23
|
+
if (content === null) {
|
|
24
|
+
throw new Error(`Tried to reference file "${refDef.path}" from "${referencedFrom}", but file does not exist.`);
|
|
25
|
+
}
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
28
|
+
export default getConfigFile;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 getConfigFile from './getConfigFile.js';
|
|
16
|
+
import parseRefContent from './parseRefContent.js';
|
|
17
|
+
import runRefResolver from './runRefResolver.js';
|
|
18
|
+
async function getRefContent({ context , refDef , referencedFrom }) {
|
|
19
|
+
let content;
|
|
20
|
+
if (refDef.path === 'lowdefy.yaml') {
|
|
21
|
+
content = await getConfigFile({
|
|
22
|
+
context,
|
|
23
|
+
refDef,
|
|
24
|
+
referencedFrom
|
|
25
|
+
});
|
|
26
|
+
} else if (refDef.resolver || context.refResolver) {
|
|
27
|
+
content = await runRefResolver({
|
|
28
|
+
context,
|
|
29
|
+
refDef,
|
|
30
|
+
referencedFrom
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
content = await getConfigFile({
|
|
34
|
+
context,
|
|
35
|
+
refDef,
|
|
36
|
+
referencedFrom
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return parseRefContent({
|
|
40
|
+
content,
|
|
41
|
+
refDef
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export default getRefContent;
|
|
@@ -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 getRefPath(refDefinition) {
|
|
17
|
+
if (type.isObject(refDefinition)) {
|
|
18
|
+
if (refDefinition.path) {
|
|
19
|
+
return refDefinition.path;
|
|
20
|
+
}
|
|
21
|
+
if (refDefinition._var) {
|
|
22
|
+
return refDefinition;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (type.isString(refDefinition)) {
|
|
26
|
+
return refDefinition;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export default getRefPath;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 makeRefDefinition from './makeRefDefinition.js';
|
|
17
|
+
function getRefsFromFile(fileContent) {
|
|
18
|
+
const foundRefs = [];
|
|
19
|
+
const reviver = (key, value)=>{
|
|
20
|
+
if (type.isObject(value)) {
|
|
21
|
+
if (!type.isUndefined(value._ref)) {
|
|
22
|
+
const def = makeRefDefinition(value._ref);
|
|
23
|
+
foundRefs.push(def);
|
|
24
|
+
return {
|
|
25
|
+
_ref: def
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
const fileContentBuiltRefs = JSON.parse(JSON.stringify(fileContent), reviver);
|
|
32
|
+
return {
|
|
33
|
+
foundRefs,
|
|
34
|
+
fileContentBuiltRefs
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export default getRefsFromFile;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 path from 'path';
|
|
16
|
+
import { readFile } from '@lowdefy/node-utils';
|
|
17
|
+
async function getUserJavascriptFunction({ context , filePath }) {
|
|
18
|
+
const jsFile = await readFile(path.resolve(context.configDirectory, filePath));
|
|
19
|
+
return eval(jsFile);
|
|
20
|
+
}
|
|
21
|
+
export default getUserJavascriptFunction;
|
|
@@ -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 { get } from '@lowdefy/helpers';
|
|
16
|
+
import { v1 as uuid } from 'uuid';
|
|
17
|
+
import getRefPath from './getRefPath.js';
|
|
18
|
+
function makeRefDefinition(refDefinition) {
|
|
19
|
+
return {
|
|
20
|
+
id: uuid(),
|
|
21
|
+
original: refDefinition,
|
|
22
|
+
path: getRefPath(refDefinition),
|
|
23
|
+
resolver: get(refDefinition, 'resolver'),
|
|
24
|
+
transformer: get(refDefinition, 'transformer'),
|
|
25
|
+
vars: get(refDefinition, 'vars', {
|
|
26
|
+
default: {
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default makeRefDefinition;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { nunjucksFunction } from '@lowdefy/nunjucks';
|
|
16
|
+
function parseNunjucks(fileContent, vars) {
|
|
17
|
+
const template = nunjucksFunction(fileContent);
|
|
18
|
+
return template(vars);
|
|
19
|
+
}
|
|
20
|
+
export default parseNunjucks;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
|
|
17
|
+
import JSON5 from 'json5';
|
|
18
|
+
import YAML from 'js-yaml';
|
|
19
|
+
import parseNunjucks from './parseNunjucks.js';
|
|
20
|
+
function parseRefContent({ content , refDef }) {
|
|
21
|
+
const { path , vars } = refDef;
|
|
22
|
+
if (type.isString(path)) {
|
|
23
|
+
let ext = getFileExtension(path);
|
|
24
|
+
if (ext === 'njk') {
|
|
25
|
+
content = parseNunjucks(content, vars);
|
|
26
|
+
ext = getFileSubExtension(path);
|
|
27
|
+
}
|
|
28
|
+
if (ext === 'yaml' || ext === 'yml') {
|
|
29
|
+
return YAML.load(content);
|
|
30
|
+
}
|
|
31
|
+
if (ext === 'json') {
|
|
32
|
+
return JSON5.parse(content);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return content;
|
|
36
|
+
}
|
|
37
|
+
export default parseRefContent;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { get, type } from '@lowdefy/helpers';
|
|
16
|
+
function refReviver(key, value) {
|
|
17
|
+
if (type.isObject(value)) {
|
|
18
|
+
if (!type.isUndefined(value._ref)) {
|
|
19
|
+
return this.parsedFiles[value._ref.id];
|
|
20
|
+
}
|
|
21
|
+
if (value._var) {
|
|
22
|
+
if (type.isString(value._var)) {
|
|
23
|
+
return JSON.parse(JSON.stringify(get(this.vars, value._var, {
|
|
24
|
+
default: null
|
|
25
|
+
})));
|
|
26
|
+
}
|
|
27
|
+
if (type.isObject(value._var) && type.isString(value._var.name)) {
|
|
28
|
+
return JSON.parse(JSON.stringify(get(this.vars, value._var.name, {
|
|
29
|
+
default: type.isNone(value._var.default) ? null : value._var.default
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`"_var" operator takes a string or object with name field as arguments. Received "${JSON.stringify(value)}"`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function populateRefs({ parsedFiles , refDef , toPopulate }) {
|
|
38
|
+
return JSON.parse(JSON.stringify(toPopulate), refReviver.bind({
|
|
39
|
+
parsedFiles,
|
|
40
|
+
vars: refDef.vars
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
export default populateRefs;
|
|
@@ -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
|
+
*/ import getRefContent from './getRefContent.js';
|
|
16
|
+
import getRefsFromFile from './getRefsFromFile.js';
|
|
17
|
+
import populateRefs from './populateRefs.js';
|
|
18
|
+
import runTransformer from './runTransformer.js';
|
|
19
|
+
async function recursiveParseFile({ context , refDef , count , referencedFrom }) {
|
|
20
|
+
// TODO: Maybe it would be better to detect a cycle, since this is the real issue here?
|
|
21
|
+
if (count > 40) {
|
|
22
|
+
throw new Error(`Maximum recursion depth of references exceeded.`);
|
|
23
|
+
}
|
|
24
|
+
let fileContent = await getRefContent({
|
|
25
|
+
context,
|
|
26
|
+
refDef,
|
|
27
|
+
referencedFrom
|
|
28
|
+
});
|
|
29
|
+
const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent);
|
|
30
|
+
const parsedFiles = {
|
|
31
|
+
};
|
|
32
|
+
// Since we can have references in the variables of a reference, we need to first parse
|
|
33
|
+
// the deeper nodes, so we can use those parsed files in references higher in the tree.
|
|
34
|
+
// To do this, since foundRefs is an array of ref definitions that are in order of the
|
|
35
|
+
// deepest nodes first we for loop over over foundRefs one by one, awaiting each result.
|
|
36
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
37
|
+
for (const newRefDef of foundRefs.values()){
|
|
38
|
+
// Parse vars and path before passing down to parse new file
|
|
39
|
+
const parsedRefDef = populateRefs({
|
|
40
|
+
toPopulate: newRefDef,
|
|
41
|
+
parsedFiles,
|
|
42
|
+
refDef
|
|
43
|
+
});
|
|
44
|
+
const parsedFile = await recursiveParseFile({
|
|
45
|
+
context,
|
|
46
|
+
refDef: parsedRefDef,
|
|
47
|
+
count: count + 1,
|
|
48
|
+
referencedFrom: refDef.path
|
|
49
|
+
});
|
|
50
|
+
const transformedFile = await runTransformer({
|
|
51
|
+
context,
|
|
52
|
+
parsedFile,
|
|
53
|
+
refDef: parsedRefDef
|
|
54
|
+
});
|
|
55
|
+
parsedFiles[newRefDef.id] = transformedFile;
|
|
56
|
+
}
|
|
57
|
+
return populateRefs({
|
|
58
|
+
toPopulate: fileContentBuiltRefs,
|
|
59
|
+
parsedFiles,
|
|
60
|
+
refDef
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export default recursiveParseFile;
|
|
@@ -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 { type } from '@lowdefy/helpers';
|
|
16
|
+
import getUserJavascriptFunction from './getUserJavascriptFunction.js';
|
|
17
|
+
async function runRefResolver({ context , refDef , referencedFrom }) {
|
|
18
|
+
const resolverFn = await getUserJavascriptFunction({
|
|
19
|
+
context,
|
|
20
|
+
filePath: refDef.resolver || context.refResolver
|
|
21
|
+
});
|
|
22
|
+
let content;
|
|
23
|
+
try {
|
|
24
|
+
content = await resolverFn(refDef.path, refDef.vars, context);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`Error calling resolver "${refDef.resolver}" from "${referencedFrom}": ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
if (type.isNone(content)) {
|
|
29
|
+
throw new Error(`Tried to reference with resolver "${refDef.resolver}" from "${referencedFrom}", but received "${content}".`);
|
|
30
|
+
}
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
export default runRefResolver;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 getUserJavascriptFunction from './getUserJavascriptFunction.js';
|
|
16
|
+
async function runTransformer({ context , parsedFile , refDef }) {
|
|
17
|
+
if (refDef.transformer) {
|
|
18
|
+
const transformerFn = await getUserJavascriptFunction({
|
|
19
|
+
context,
|
|
20
|
+
filePath: refDef.transformer
|
|
21
|
+
});
|
|
22
|
+
return transformerFn(parsedFile, refDef.vars);
|
|
23
|
+
}
|
|
24
|
+
return parsedFile;
|
|
25
|
+
}
|
|
26
|
+
export default runTransformer;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 buildStyles({ components , context }) {
|
|
16
|
+
components.styles = [];
|
|
17
|
+
const styles = new Set();
|
|
18
|
+
Object.entries(components.types.blocks).forEach(([blockName, block])=>{
|
|
19
|
+
styles.add(...(context.types.styles[block.package].default || []).map((style)=>`${block.package}/${style}`
|
|
20
|
+
));
|
|
21
|
+
styles.add(...(context.types.styles[block.package][blockName] || []).map((style)=>`${block.package}/${style}`
|
|
22
|
+
));
|
|
23
|
+
});
|
|
24
|
+
components.styles = [
|
|
25
|
+
...styles
|
|
26
|
+
].filter((style)=>!!style
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
export default buildStyles;
|