@lowdefy/build 3.23.2 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/build/addDefaultPages/404.js +51 -0
  2. package/dist/build/addDefaultPages/addDefaultPages.js +44 -0
  3. package/dist/build/buildAuth/buildAuth.js +50 -0
  4. package/dist/build/buildAuth/getPageRoles.js +33 -0
  5. package/dist/build/buildAuth/getProtectedPages.js +30 -0
  6. package/dist/build/buildConnections.js +46 -0
  7. package/dist/build/buildIcons.js +91 -0
  8. package/dist/build/buildMenu.js +122 -0
  9. package/dist/build/buildPages/buildBlock/buildBlock.js +35 -0
  10. package/dist/build/buildPages/buildBlock/buildEvents.js +75 -0
  11. package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
  12. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
  13. package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
  14. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  15. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  16. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
  17. package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
  18. package/dist/build/buildPages/buildBlock/validateBlock.js +38 -0
  19. package/dist/build/buildPages/buildPage.js +50 -0
  20. package/dist/build/buildPages/buildPages.js +33 -0
  21. package/dist/build/buildRefs/buildRefs.js +26 -0
  22. package/dist/build/buildRefs/evaluateBuildOperators.js +35 -0
  23. package/dist/build/buildRefs/getConfigFile.js +28 -0
  24. package/dist/build/buildRefs/getRefContent.js +44 -0
  25. package/dist/build/buildRefs/getRefPath.js +30 -0
  26. package/dist/build/buildRefs/getRefsFromFile.js +37 -0
  27. package/dist/build/buildRefs/getUserJavascriptFunction.js +24 -0
  28. package/dist/build/buildRefs/makeRefDefinition.js +30 -0
  29. package/dist/build/buildRefs/parseNunjucks.js +20 -0
  30. package/dist/build/buildRefs/parseRefContent.js +37 -0
  31. package/dist/build/buildRefs/populateRefs.js +43 -0
  32. package/dist/build/buildRefs/recursiveBuild.js +68 -0
  33. package/dist/build/buildRefs/runRefResolver.js +33 -0
  34. package/dist/build/buildRefs/runTransformer.js +30 -0
  35. package/dist/build/buildStyles.js +29 -0
  36. package/dist/build/buildTypes.js +96 -0
  37. package/dist/build/cleanBuildDirectory.js +19 -0
  38. package/dist/build/copyPublicFolder.js +23 -0
  39. package/dist/build/testSchema.js +34 -0
  40. package/dist/build/updateServerPackageJson.js +46 -0
  41. package/dist/build/validateApp.js +34 -0
  42. package/dist/build/validateConfig.js +57 -0
  43. package/dist/build/writeApp.js +18 -0
  44. package/dist/build/writeConfig.js +18 -0
  45. package/dist/build/writeConnections.js +26 -0
  46. package/dist/build/writeGlobal.js +25 -0
  47. package/dist/build/writeMenus.js +22 -0
  48. package/dist/build/writePages.js +26 -0
  49. package/dist/build/writePluginImports/generateImportFile.js +36 -0
  50. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  51. package/dist/build/writePluginImports/writeBlockImports.js +22 -0
  52. package/dist/build/writePluginImports/writeConnectionImports.js +22 -0
  53. package/dist/build/writePluginImports/writeIconImports.js +31 -0
  54. package/dist/build/writePluginImports/writeOperatorImports.js +26 -0
  55. package/dist/build/writePluginImports/writeStyleImports.js +28 -0
  56. package/dist/build/writeRequests.js +32 -0
  57. package/dist/build/writeTypes.js +18 -0
  58. package/dist/defaultTypesMap.json +1598 -0
  59. package/dist/index.js +197 -1
  60. package/dist/lowdefySchema.js +747 -0
  61. package/dist/scripts/generateDefaultTypes.js +72 -0
  62. package/dist/scripts/run.js +32 -0
  63. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
  64. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
  65. package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
  66. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
  67. package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
  68. package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
  69. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
  70. package/dist/test/testContext.js +48 -0
  71. package/dist/utils/countOperators.js +30 -0
  72. package/dist/utils/createCheckDuplicateId.js +31 -0
  73. package/dist/utils/createCounter.js +33 -0
  74. package/dist/utils/createPluginTypesMap.js +85 -0
  75. package/dist/utils/formatErrorMessage.js +56 -0
  76. package/dist/utils/readConfigFile.js +24 -0
  77. package/dist/utils/writeBuildArtifact.js +23 -0
  78. package/package.json +55 -23
  79. package/dist/138.index.js +0 -2
  80. package/dist/138.index.js.LICENSE.txt +0 -3
  81. package/dist/231.index.js +0 -1
  82. package/dist/319.index.js +0 -1
  83. package/dist/35.index.js +0 -1
  84. package/dist/422.index.js +0 -1
  85. package/dist/443.index.js +0 -1
  86. package/dist/449.index.js +0 -1
  87. package/dist/5.index.js +0 -2
  88. package/dist/5.index.js.LICENSE.txt +0 -1
  89. package/dist/564.index.js +0 -1
  90. package/dist/569.index.js +0 -1
  91. package/dist/625.index.js +0 -1
  92. package/dist/693.index.js +0 -2
  93. package/dist/693.index.js.LICENSE.txt +0 -1
  94. package/dist/734.index.js +0 -1
  95. package/dist/904.index.js +0 -1
  96. package/dist/remoteEntry.js +0 -1
@@ -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
+ // 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 evaluatedOperators = await evaluateBuildOperators({
51
+ context,
52
+ input: parsedFile,
53
+ refDef: parsedRefDef
54
+ });
55
+ const transformedFile = await runTransformer({
56
+ context,
57
+ input: evaluatedOperators,
58
+ refDef: parsedRefDef
59
+ });
60
+ parsedFiles[newRefDef.id] = transformedFile;
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,29 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function buildStyles({ components , context }) {
16
+ components.styles = [];
17
+ const styles = new Set();
18
+ Object.entries(components.types.blocks).forEach(([blockName, block])=>{
19
+ styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`
20
+ ));
21
+ styles.add(...(context.typesMap.styles.blocks[blockName] || []).map((style)=>`${block.package}/${style}`
22
+ ));
23
+ });
24
+ components.styles = [
25
+ ...styles
26
+ ].filter((style)=>!!style
27
+ );
28
+ }
29
+ export default buildStyles;
@@ -0,0 +1,96 @@
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
+ );
44
+ loaderTypes.blocks.forEach((block)=>typeCounters.blocks.increment(block)
45
+ );
46
+ typeCounters.blocks.increment('Message'); // Used for DisplayMessage in @lowdefy/client
47
+ components.types = {
48
+ actions: {},
49
+ blocks: {},
50
+ connections: {},
51
+ requests: {},
52
+ operators: {
53
+ client: {},
54
+ server: {}
55
+ }
56
+ };
57
+ buildTypeClass(context, {
58
+ counter: typeCounters.actions,
59
+ definitions: context.typesMap.actions,
60
+ store: components.types.actions,
61
+ typeClass: 'Action'
62
+ });
63
+ buildTypeClass(context, {
64
+ counter: typeCounters.blocks,
65
+ definitions: context.typesMap.blocks,
66
+ store: components.types.blocks,
67
+ typeClass: 'Block'
68
+ });
69
+ buildTypeClass(context, {
70
+ counter: typeCounters.connections,
71
+ definitions: context.typesMap.connections,
72
+ store: components.types.connections,
73
+ typeClass: 'Connection'
74
+ });
75
+ buildTypeClass(context, {
76
+ counter: typeCounters.requests,
77
+ definitions: context.typesMap.requests,
78
+ store: components.types.requests,
79
+ typeClass: 'Request'
80
+ });
81
+ buildTypeClass(context, {
82
+ counter: typeCounters.operators.client,
83
+ definitions: context.typesMap.operators.client,
84
+ store: components.types.operators.client,
85
+ typeClass: 'Operator',
86
+ warnIfMissing: true
87
+ });
88
+ buildTypeClass(context, {
89
+ counter: typeCounters.operators.server,
90
+ definitions: context.typesMap.operators.server,
91
+ store: components.types.operators.server,
92
+ typeClass: 'Operator',
93
+ warnIfMissing: true
94
+ });
95
+ }
96
+ 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;
@@ -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 { validate } from '@lowdefy/ajv';
16
+ import lowdefySchema from '../lowdefySchema.js';
17
+ import formatErrorMessage from '../utils/formatErrorMessage.js';
18
+ async function testSchema({ components , context }) {
19
+ const { valid , errors } = validate({
20
+ schema: lowdefySchema,
21
+ data: components,
22
+ returnErrors: true
23
+ });
24
+ if (!valid) {
25
+ await context.logger.warn('Schema not valid.');
26
+ const promises = errors.map((error)=>context.logger.warn(formatErrorMessage({
27
+ error,
28
+ components
29
+ }))
30
+ );
31
+ await promises;
32
+ }
33
+ }
34
+ export default testSchema;
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import path from 'path';
16
+ import { readFile, writeFile } from '@lowdefy/node-utils';
17
+ async function updateServerPackageJson({ components , context }) {
18
+ const filePath = path.join(context.directories.server, 'package.json');
19
+ const packageJsonContent = await readFile(filePath);
20
+ const packageJson = JSON.parse(packageJsonContent);
21
+ const dependencies = packageJson.dependencies;
22
+ function getPackages(types) {
23
+ Object.values(types).forEach((type)=>{
24
+ dependencies[type.package] = type.version;
25
+ });
26
+ }
27
+ getPackages(components.types.actions);
28
+ getPackages(components.types.blocks);
29
+ getPackages(components.types.connections);
30
+ getPackages(components.types.requests);
31
+ getPackages(components.types.operators.client);
32
+ getPackages(components.types.operators.server);
33
+ // Sort dependencies
34
+ packageJson.dependencies = {};
35
+ Object.keys(dependencies).sort().forEach((name)=>{
36
+ packageJson.dependencies[name] = dependencies[name];
37
+ });
38
+ const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
39
+ // Only write package.json if it has changed since dev server will
40
+ // be watching the file to trigger reinstalls
41
+ if (newPackageJsonContent !== packageJsonContent) {
42
+ context.logger.warn('Plugin dependencies have changed. Updating "package.json".');
43
+ await writeFile(filePath, newPackageJsonContent);
44
+ }
45
+ }
46
+ export default updateServerPackageJson;
@@ -0,0 +1,34 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ async function validateApp({ components }) {
17
+ if (type.isNone(components.app)) {
18
+ components.app = {};
19
+ }
20
+ if (!type.isObject(components.app)) {
21
+ throw new Error('lowdefy.app is not an object.');
22
+ }
23
+ if (type.isNone(components.app.html)) {
24
+ components.app.html = {};
25
+ }
26
+ if (type.isNone(components.app.html.appendBody)) {
27
+ components.app.html.appendBody = '';
28
+ }
29
+ if (type.isNone(components.app.html.appendHead)) {
30
+ components.app.html.appendHead = '';
31
+ }
32
+ return components;
33
+ }
34
+ export default validateApp;
@@ -0,0 +1,57 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import { validate } from '@lowdefy/ajv';
17
+ import lowdefySchema from '../lowdefySchema.js';
18
+ async function validateConfig({ components }) {
19
+ if (type.isNone(components.config)) {
20
+ components.config = {};
21
+ }
22
+ if (!type.isObject(components.config)) {
23
+ throw new Error('lowdefy.config is not an object.');
24
+ }
25
+ if (type.isNone(components.config.auth)) {
26
+ components.config.auth = {};
27
+ }
28
+ if (type.isNone(components.config.auth.pages)) {
29
+ components.config.auth.pages = {};
30
+ }
31
+ if (type.isNone(components.config.auth.pages.roles)) {
32
+ components.config.auth.pages.roles = {};
33
+ }
34
+ if (type.isNone(components.config.theme)) {
35
+ components.config.theme = {};
36
+ }
37
+ if (type.isString(components.config.basePath)) {
38
+ if (components.config.basePath[0] !== '/') {
39
+ throw Error('Base path must start with "/".');
40
+ }
41
+ }
42
+ validate({
43
+ schema: lowdefySchema.definitions.authConfig,
44
+ data: components.config.auth
45
+ });
46
+ if (components.config.auth.pages.protected === true && components.config.auth.pages.public === true || type.isArray(components.config.auth.pages.protected) && type.isArray(components.config.auth.pages.public)) {
47
+ throw new Error('Protected and public pages are mutually exclusive. When protected pages are listed, all unlisted pages are public by default and visa versa.');
48
+ }
49
+ if (components.config.auth.pages.protected === false) {
50
+ throw new Error('Protected pages can not be set to false.');
51
+ }
52
+ if (components.config.auth.pages.public === false) {
53
+ throw new Error('Public pages can not be set to false.');
54
+ }
55
+ return components;
56
+ }
57
+ export default validateConfig;
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ async function writeApp({ components , context }) {
16
+ await context.writeBuildArtifact('app.json', JSON.stringify(components.app || {}, null, 2));
17
+ }
18
+ export default writeApp;
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ async function writeConfig({ components , context }) {
16
+ await context.writeBuildArtifact('config.json', JSON.stringify(components.config || {}, null, 2));
17
+ }
18
+ export default writeConfig;
@@ -0,0 +1,26 @@
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 writeConnections({ components , context }) {
17
+ if (type.isNone(components.connections)) return;
18
+ if (!type.isArray(components.connections)) {
19
+ throw new Error(`Connections is not an array.`);
20
+ }
21
+ const writePromises = components.connections.map(async (connection)=>{
22
+ await context.writeBuildArtifact(`connections/${connection.connectionId}.json`, JSON.stringify(connection, null, 2));
23
+ });
24
+ return Promise.all(writePromises);
25
+ }
26
+ export default writeConnections;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ async function writeGlobal({ components , context }) {
17
+ if (type.isNone(components.global)) {
18
+ components.global = {};
19
+ }
20
+ if (!type.isObject(components.global)) {
21
+ throw new Error('Global is not an object.');
22
+ }
23
+ await context.writeBuildArtifact('global.json', JSON.stringify(components.global, null, 2));
24
+ }
25
+ export default writeGlobal;
@@ -0,0 +1,22 @@
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 writeMenus({ components , context }) {
17
+ if (!type.isArray(components.menus)) {
18
+ throw new Error('Menus is not an array.');
19
+ }
20
+ await context.writeBuildArtifact('menus.json', JSON.stringify(components.menus, null, 2));
21
+ }
22
+ export default writeMenus;
@@ -0,0 +1,26 @@
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
+ */ async function writePage({ page , context }) {
16
+ await context.writeBuildArtifact(`pages/${page.pageId}/${page.pageId}.json`, JSON.stringify(page, null, 2));
17
+ }
18
+ async function writePages({ components , context }) {
19
+ const writePromises = components.pages.map((page)=>writePage({
20
+ page,
21
+ context
22
+ })
23
+ );
24
+ return Promise.all(writePromises);
25
+ }
26
+ export default writePages;
@@ -0,0 +1,36 @@
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
+ const template = `{%- for import in imports -%}
17
+ import { {{ import.originalTypeName }} as {{ import.typeName }} } from '{{ import.package }}/{{ importPath }}';
18
+ {% endfor -%}
19
+ export default {
20
+ {% for import in imports -%}
21
+ {{ import.typeName }},
22
+ {% endfor -%}
23
+ };`;
24
+ function generateImportFile({ types , importPath }) {
25
+ const templateFn = nunjucksFunction(template);
26
+ const imports = Object.keys(types).map((typeName)=>({
27
+ typeName,
28
+ ...types[typeName]
29
+ })
30
+ );
31
+ return templateFn({
32
+ imports,
33
+ importPath
34
+ });
35
+ }
36
+ export default generateImportFile;