@lowdefy/build 4.0.0-alpha.29 → 4.0.0-alpha.31
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 +51 -0
- package/dist/build/addDefaultPages/addDefaultPages.js +43 -0
- package/dist/build/buildAuth/buildAuth.js +34 -0
- package/dist/build/buildAuth/buildAuthPlugins.js +71 -0
- package/dist/build/buildAuth/buildPageAuth.js +50 -0
- package/dist/build/buildAuth/getPageRoles.js +33 -0
- package/dist/build/buildAuth/getProtectedPages.js +28 -0
- package/dist/build/buildAuth/validateAuthConfig.js +61 -0
- package/dist/build/buildConnections.js +46 -0
- package/dist/build/buildImports/buildIconImports.js +83 -0
- 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/buildImports/buildStyleImports.js +25 -0
- package/dist/build/buildImports/defaultIconsDev.js +584 -0
- package/dist/build/buildImports/defaultIconsProd.js +21 -0
- package/dist/build/buildMenu.js +118 -0
- package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
- package/dist/build/buildPages/buildBlock/buildEvents.js +76 -0
- package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
- package/dist/build/buildPages/buildBlock/buildSubBlocks.js +30 -0
- package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
- package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
- package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -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 +38 -0
- package/dist/build/buildPages/buildPage.js +50 -0
- package/dist/build/buildPages/buildPages.js +31 -0
- package/dist/build/buildPages/buildTestPage.js +46 -0
- package/dist/build/buildRefs/buildRefs.js +32 -0
- package/dist/build/buildRefs/evaluateBuildOperators.js +34 -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 +24 -0
- package/dist/build/buildRefs/makeRefDefinition.js +31 -0
- package/dist/build/buildRefs/parseNunjucks.js +20 -0
- package/dist/build/buildRefs/parseRefContent.js +42 -0
- package/dist/build/buildRefs/populateRefs.js +43 -0
- package/dist/build/buildRefs/recursiveBuild.js +68 -0
- package/dist/build/buildRefs/runRefResolver.js +33 -0
- package/dist/build/buildRefs/runTransformer.js +30 -0
- package/dist/build/buildTypes.js +124 -0
- package/dist/build/cleanBuildDirectory.js +19 -0
- package/dist/build/copyPublicFolder.js +23 -0
- package/dist/build/testSchema.js +32 -0
- package/dist/build/updateServerPackageJson.js +50 -0
- package/dist/build/validateApp.js +34 -0
- package/dist/build/validateConfig.js +33 -0
- package/dist/build/writeApp.js +18 -0
- package/dist/build/writeAuth.js +18 -0
- package/dist/build/writeConfig.js +18 -0
- package/dist/build/writeConnections.js +26 -0
- package/dist/build/writeGlobal.js +25 -0
- package/dist/build/writeMenus.js +22 -0
- package/dist/build/writePages.js +25 -0
- package/dist/build/writePluginImports/generateImportFile.js +31 -0
- package/dist/build/writePluginImports/writeActionImports.js +22 -0
- package/dist/build/writePluginImports/writeAuthImports.js +34 -0
- package/dist/build/writePluginImports/writeBlockImports.js +22 -0
- package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
- package/dist/build/writePluginImports/writeIconImports.js +31 -0
- package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
- package/dist/build/writePluginImports/writePluginImports.js +52 -0
- package/dist/build/writePluginImports/writeStyleImports.js +28 -0
- package/dist/build/writeRequests.js +31 -0
- package/dist/build/writeTypes.js +18 -0
- package/dist/createContext.js +55 -0
- package/dist/defaultTypesMap.js +2046 -0
- package/dist/index.js +139 -0
- package/dist/lowdefySchema.js +841 -0
- package/dist/scripts/generateDefaultTypes.js +88 -0
- package/dist/scripts/run.js +33 -0
- package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -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 +54 -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/createPluginTypesMap.js +113 -0
- package/dist/utils/formatErrorMessage.js +56 -0
- package/dist/utils/readConfigFile.js +24 -0
- package/dist/utils/writeBuildArtifact.js +23 -0
- package/package.json +36 -36
|
@@ -0,0 +1,34 @@
|
|
|
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 { NodeParser } from '@lowdefy/operators';
|
|
16
|
+
import operators from '@lowdefy/operators-js/operators/build';
|
|
17
|
+
async function evaluateBuildOperators({ context , input , refDef }) {
|
|
18
|
+
const operatorsParser = new NodeParser({
|
|
19
|
+
env: process.env,
|
|
20
|
+
operators
|
|
21
|
+
});
|
|
22
|
+
const { output , errors } = operatorsParser.parse({
|
|
23
|
+
input,
|
|
24
|
+
location: refDef.path ?? refDef.resolver,
|
|
25
|
+
operatorPrefix: '_build.'
|
|
26
|
+
});
|
|
27
|
+
if (errors.length > 0) {
|
|
28
|
+
await context.logger.warn('Build operator errors.');
|
|
29
|
+
const promises = errors.map((error)=>context.logger.warn(error.message));
|
|
30
|
+
await promises;
|
|
31
|
+
}
|
|
32
|
+
return output;
|
|
33
|
+
}
|
|
34
|
+
export default evaluateBuildOperators;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ 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 = await 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-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 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' || refDef.path === 'lowdefy.yml') {
|
|
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-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 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-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 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,24 @@
|
|
|
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 path from 'path';
|
|
16
|
+
async function getUserJavascriptFunction({ context , filePath }) {
|
|
17
|
+
try {
|
|
18
|
+
return (await import(path.resolve(context.directories.config, filePath))).default;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
context.logger.error(`Error importing ${filePath}.`);
|
|
21
|
+
throw Error(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export default getUserJavascriptFunction;
|
|
@@ -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 { 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
|
+
key: get(refDefinition, 'key'),
|
|
24
|
+
resolver: get(refDefinition, 'resolver'),
|
|
25
|
+
transformer: get(refDefinition, 'transformer'),
|
|
26
|
+
vars: get(refDefinition, 'vars', {
|
|
27
|
+
default: {}
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export default makeRefDefinition;
|
|
@@ -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
|
+
*/ 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,42 @@
|
|
|
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
|
+
*/ /* eslint-disable no-param-reassign */ import { get, type } from '@lowdefy/helpers';
|
|
16
|
+
import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
|
|
17
|
+
import JSON5 from 'json5';
|
|
18
|
+
import YAML from '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
|
+
content = YAML.parse(content);
|
|
30
|
+
}
|
|
31
|
+
if (ext === 'json') {
|
|
32
|
+
content = JSON5.parse(content);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (refDef.key) {
|
|
36
|
+
content = get(content, refDef.key, {
|
|
37
|
+
default: null
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return content;
|
|
41
|
+
}
|
|
42
|
+
export default parseRefContent;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { 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.key)) {
|
|
28
|
+
return JSON.parse(JSON.stringify(get(this.vars, value._var.key, {
|
|
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 "key" 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,68 @@
|
|
|
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 evaluateBuildOperators from './evaluateBuildOperators.js';
|
|
16
|
+
import getRefContent from './getRefContent.js';
|
|
17
|
+
import getRefsFromFile from './getRefsFromFile.js';
|
|
18
|
+
import populateRefs from './populateRefs.js';
|
|
19
|
+
import runTransformer from './runTransformer.js';
|
|
20
|
+
async function recursiveParseFile({ context , refDef , count , referencedFrom }) {
|
|
21
|
+
// TODO: Maybe it would be better to detect a cycle, since this is the real issue here?
|
|
22
|
+
if (count > 40) {
|
|
23
|
+
throw new Error(`Maximum recursion depth of references exceeded.`);
|
|
24
|
+
}
|
|
25
|
+
let fileContent = await getRefContent({
|
|
26
|
+
context,
|
|
27
|
+
refDef,
|
|
28
|
+
referencedFrom
|
|
29
|
+
});
|
|
30
|
+
const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent);
|
|
31
|
+
const parsedFiles = {};
|
|
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
|
+
for (const newRefDef of foundRefs.values()){
|
|
37
|
+
// Parse vars and path before passing down to parse new file
|
|
38
|
+
const parsedRefDef = populateRefs({
|
|
39
|
+
toPopulate: newRefDef,
|
|
40
|
+
parsedFiles,
|
|
41
|
+
refDef
|
|
42
|
+
});
|
|
43
|
+
const parsedFile = await recursiveParseFile({
|
|
44
|
+
context,
|
|
45
|
+
refDef: parsedRefDef,
|
|
46
|
+
count: count + 1,
|
|
47
|
+
referencedFrom: refDef.path
|
|
48
|
+
});
|
|
49
|
+
const transformedFile = await runTransformer({
|
|
50
|
+
context,
|
|
51
|
+
input: parsedFile,
|
|
52
|
+
refDef: parsedRefDef
|
|
53
|
+
});
|
|
54
|
+
// Evaluated in recursive loop for better error messages
|
|
55
|
+
const evaluatedOperators = await evaluateBuildOperators({
|
|
56
|
+
context,
|
|
57
|
+
input: transformedFile,
|
|
58
|
+
refDef: parsedRefDef
|
|
59
|
+
});
|
|
60
|
+
parsedFiles[newRefDef.id] = evaluatedOperators;
|
|
61
|
+
}
|
|
62
|
+
return populateRefs({
|
|
63
|
+
toPopulate: fileContentBuiltRefs,
|
|
64
|
+
parsedFiles,
|
|
65
|
+
refDef
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export default recursiveParseFile;
|
|
@@ -0,0 +1,33 @@
|
|
|
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 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,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 getUserJavascriptFunction from './getUserJavascriptFunction.js';
|
|
16
|
+
async function runTransformer({ context , input , refDef }) {
|
|
17
|
+
if (refDef.transformer) {
|
|
18
|
+
const transformerFn = await getUserJavascriptFunction({
|
|
19
|
+
context,
|
|
20
|
+
filePath: refDef.transformer
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
return transformerFn(input, refDef.vars);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw Error(`Error calling transformer "${refDef.transformer}" from "${refDef.path}": ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
export default runTransformer;
|
|
@@ -0,0 +1,124 @@
|
|
|
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 basicTypes from '@lowdefy/blocks-basic/types';
|
|
16
|
+
import loaderTypes from '@lowdefy/blocks-loaders/types';
|
|
17
|
+
function buildTypeClass(context, { counter , definitions , store , typeClass , warnIfMissing =false }) {
|
|
18
|
+
const counts = counter.getCounts();
|
|
19
|
+
Object.keys(counts).forEach((typeName)=>{
|
|
20
|
+
if (!definitions[typeName]) {
|
|
21
|
+
if (warnIfMissing) {
|
|
22
|
+
context.logger.warn(`${typeClass} type "${typeName}" was used but is not defined.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`${typeClass} type "${typeName}" was used but is not defined.`);
|
|
26
|
+
}
|
|
27
|
+
store[typeName] = {
|
|
28
|
+
originalTypeName: definitions[typeName].originalTypeName,
|
|
29
|
+
package: definitions[typeName].package,
|
|
30
|
+
version: definitions[typeName].version,
|
|
31
|
+
count: counts[typeName]
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function buildTypes({ components , context }) {
|
|
36
|
+
const { typeCounters } = context;
|
|
37
|
+
// Add Mandatory Types
|
|
38
|
+
// Add operators used by form validation
|
|
39
|
+
typeCounters.operators.client.increment('_not');
|
|
40
|
+
typeCounters.operators.client.increment('_type');
|
|
41
|
+
// Add loaders and basic
|
|
42
|
+
basicTypes.blocks.forEach((block)=>typeCounters.blocks.increment(block));
|
|
43
|
+
loaderTypes.blocks.forEach((block)=>typeCounters.blocks.increment(block));
|
|
44
|
+
typeCounters.blocks.increment('Message'); // Used for DisplayMessage in @lowdefy/client
|
|
45
|
+
components.types = {
|
|
46
|
+
actions: {},
|
|
47
|
+
auth: {
|
|
48
|
+
adapters: {},
|
|
49
|
+
callbacks: {},
|
|
50
|
+
events: {},
|
|
51
|
+
providers: {}
|
|
52
|
+
},
|
|
53
|
+
blocks: {},
|
|
54
|
+
connections: {},
|
|
55
|
+
requests: {},
|
|
56
|
+
operators: {
|
|
57
|
+
client: {},
|
|
58
|
+
server: {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
buildTypeClass(context, {
|
|
62
|
+
counter: typeCounters.actions,
|
|
63
|
+
definitions: context.typesMap.actions,
|
|
64
|
+
store: components.types.actions,
|
|
65
|
+
typeClass: 'Action'
|
|
66
|
+
});
|
|
67
|
+
buildTypeClass(context, {
|
|
68
|
+
counter: typeCounters.auth.adapters,
|
|
69
|
+
definitions: context.typesMap.auth.adapters,
|
|
70
|
+
store: components.types.auth.adapters,
|
|
71
|
+
typeClass: 'Auth adapter'
|
|
72
|
+
});
|
|
73
|
+
buildTypeClass(context, {
|
|
74
|
+
counter: typeCounters.auth.callbacks,
|
|
75
|
+
definitions: context.typesMap.auth.callbacks,
|
|
76
|
+
store: components.types.auth.callbacks,
|
|
77
|
+
typeClass: 'Auth callback'
|
|
78
|
+
});
|
|
79
|
+
buildTypeClass(context, {
|
|
80
|
+
counter: typeCounters.auth.events,
|
|
81
|
+
definitions: context.typesMap.auth.events,
|
|
82
|
+
store: components.types.auth.events,
|
|
83
|
+
typeClass: 'Auth event'
|
|
84
|
+
});
|
|
85
|
+
buildTypeClass(context, {
|
|
86
|
+
counter: typeCounters.auth.providers,
|
|
87
|
+
definitions: context.typesMap.auth.providers,
|
|
88
|
+
store: components.types.auth.providers,
|
|
89
|
+
typeClass: 'Auth provider'
|
|
90
|
+
});
|
|
91
|
+
buildTypeClass(context, {
|
|
92
|
+
counter: typeCounters.blocks,
|
|
93
|
+
definitions: context.typesMap.blocks,
|
|
94
|
+
store: components.types.blocks,
|
|
95
|
+
typeClass: 'Block'
|
|
96
|
+
});
|
|
97
|
+
buildTypeClass(context, {
|
|
98
|
+
counter: typeCounters.connections,
|
|
99
|
+
definitions: context.typesMap.connections,
|
|
100
|
+
store: components.types.connections,
|
|
101
|
+
typeClass: 'Connection'
|
|
102
|
+
});
|
|
103
|
+
buildTypeClass(context, {
|
|
104
|
+
counter: typeCounters.requests,
|
|
105
|
+
definitions: context.typesMap.requests,
|
|
106
|
+
store: components.types.requests,
|
|
107
|
+
typeClass: 'Request'
|
|
108
|
+
});
|
|
109
|
+
buildTypeClass(context, {
|
|
110
|
+
counter: typeCounters.operators.client,
|
|
111
|
+
definitions: context.typesMap.operators.client,
|
|
112
|
+
store: components.types.operators.client,
|
|
113
|
+
typeClass: 'Operator',
|
|
114
|
+
warnIfMissing: true
|
|
115
|
+
});
|
|
116
|
+
buildTypeClass(context, {
|
|
117
|
+
counter: typeCounters.operators.server,
|
|
118
|
+
definitions: context.typesMap.operators.server,
|
|
119
|
+
store: components.types.operators.server,
|
|
120
|
+
typeClass: 'Operator',
|
|
121
|
+
warnIfMissing: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export default buildTypes;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { cleanDirectory } from '@lowdefy/node-utils';
|
|
16
|
+
async function cleanBuildDirectory({ context }) {
|
|
17
|
+
await cleanDirectory(context.directories.build);
|
|
18
|
+
}
|
|
19
|
+
export default cleanBuildDirectory;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 path from 'path';
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import { copyDirectory } from '@lowdefy/node-utils';
|
|
18
|
+
async function copyPublicFolder({ context }) {
|
|
19
|
+
if (context.directories.config === context.directories.server) return;
|
|
20
|
+
if (!fs.existsSync(path.resolve(context.directories.config, 'public'))) return;
|
|
21
|
+
await copyDirectory(path.resolve(context.directories.config, 'public'), path.resolve(context.directories.server, 'public'));
|
|
22
|
+
}
|
|
23
|
+
export default copyPublicFolder;
|