@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,31 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import countOperators from '../../../utils/countOperators.js';
16
+ function countBlockOperators(block, { typeCounters }) {
17
+ // eslint-disable-next-line no-unused-vars
18
+ const { requests , areas , blocks , ...webBlock } = block;
19
+ countOperators(webBlock, {
20
+ counter: typeCounters.operators.client
21
+ });
22
+ (requests || []).forEach((request)=>{
23
+ countOperators(request.payload || {}, {
24
+ counter: typeCounters.operators.client
25
+ });
26
+ countOperators(request.properties || {}, {
27
+ counter: typeCounters.operators.server
28
+ });
29
+ });
30
+ }
31
+ export default countBlockOperators;
@@ -0,0 +1,18 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function countBlockTypes(block, { typeCounters }) {
16
+ typeCounters.blocks.increment(block.type);
17
+ }
18
+ export default countBlockTypes;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { set, type } from '@lowdefy/helpers';
16
+ function recMoveSkeletonBlocksToArea(block1, blockId, pageId) {
17
+ if (!type.isNone(block1.blocks)) {
18
+ if (!type.isArray(block1.blocks)) {
19
+ throw new Error(`Skeleton blocks at ${blockId} on page ${pageId} is not an array. Received ${JSON.stringify(block1.blocks)}`);
20
+ }
21
+ set(block1, 'areas.content.blocks', block1.blocks);
22
+ delete block1.blocks;
23
+ }
24
+ Object.keys(block1.areas || {}).forEach((area)=>{
25
+ block1.areas[area].blocks.forEach((block, i)=>{
26
+ recMoveSkeletonBlocksToArea(block, `${blockId}.areas.${area}.${i}.blocks`, pageId);
27
+ });
28
+ });
29
+ }
30
+ function moveSkeletonBlocksToArea(block, pageContext) {
31
+ if (type.isObject(block.skeleton)) {
32
+ recMoveSkeletonBlocksToArea(block.skeleton, `${block.blockId}.skeleton`, pageContext.pageId);
33
+ }
34
+ }
35
+ export default moveSkeletonBlocksToArea;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { set, type } from '@lowdefy/helpers';
16
+ function moveSubBlocksToArea(block, pageContext) {
17
+ if (!type.isNone(block.blocks)) {
18
+ if (!type.isArray(block.blocks)) {
19
+ throw new Error(`Blocks at ${block.blockId} on page ${pageContext.pageId} is not an array. Received ${JSON.stringify(block.blocks)}`);
20
+ }
21
+ set(block, 'areas.content.blocks', block.blocks);
22
+ delete block.blocks;
23
+ }
24
+ }
25
+ export default moveSubBlocksToArea;
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ function setBlockId(block, { pageId , blockIdCounter }) {
16
+ block.blockId = block.id;
17
+ block.id = `block:${pageId}:${block.blockId}:${blockIdCounter.getCount(block.blockId)}`;
18
+ blockIdCounter.increment(block.blockId);
19
+ }
20
+ export default setBlockId;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ function validateBlock(block, { pageId }) {
17
+ if (!type.isObject(block)) {
18
+ throw new Error(`Expected block to be an object on page "${pageId}". Received ${JSON.stringify(block)}.`);
19
+ }
20
+ if (type.isUndefined(block.id)) {
21
+ throw new Error(`Block id missing at page "${pageId}".`);
22
+ }
23
+ if (!type.isString(block.id)) {
24
+ throw new Error(`Block id is not a string at page "${pageId}". Received ${JSON.stringify(block.id)}.`);
25
+ }
26
+ if (type.isNone(block.type)) {
27
+ throw new Error(`Block type is not defined at "${block.id}" on page "${pageId}".`);
28
+ }
29
+ if (!type.isString(block.type)) {
30
+ throw new Error(`Block type is not a string at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.type)}.`);
31
+ }
32
+ if (!type.isNone(block.requests)) {
33
+ if (!type.isArray(block.requests)) {
34
+ throw new Error(`Requests is not an array at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.requests)}`);
35
+ }
36
+ }
37
+ }
38
+ export default validateBlock;
@@ -0,0 +1,50 @@
1
+ /* eslint-disable no-param-reassign */ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import buildBlock from './buildBlock/buildBlock.js';
17
+ import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
+ import createCounter from '../../utils/createCounter.js';
19
+ 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-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import buildPage from './buildPage.js';
17
+ import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
+ 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-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import recursiveBuild from './recursiveBuild.js';
16
+ import makeRefDefinition from './makeRefDefinition.js';
17
+ // TODO: build operators aren't evaluated in lowdefy.yaml file. Move recursive call up a layer or something.
18
+ async function buildRefs({ context }) {
19
+ const components = await recursiveBuild({
20
+ context,
21
+ refDef: makeRefDefinition('lowdefy.yaml'),
22
+ count: 0
23
+ });
24
+ return components || {};
25
+ }
26
+ export default buildRefs;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { 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,
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
+ );
31
+ await promises;
32
+ }
33
+ return output;
34
+ }
35
+ 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 = 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,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 { 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
+ 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,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 { 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
+ return YAML.parse(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-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.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;