@lowdefy/build 4.0.0-alpha.8 → 4.0.0-rc.0

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 (91) hide show
  1. package/dist/build/addDefaultPages/404.js +1 -1
  2. package/dist/build/addDefaultPages/addDefaultPages.js +3 -4
  3. package/dist/build/buildAuth/buildAuth.js +12 -28
  4. package/dist/build/buildAuth/buildAuthPlugins.js +71 -0
  5. package/dist/build/buildAuth/buildPageAuth.js +50 -0
  6. package/dist/build/buildAuth/getPageRoles.js +2 -2
  7. package/dist/build/buildAuth/getProtectedPages.js +7 -9
  8. package/dist/build/buildAuth/validateAuthConfig.js +64 -0
  9. package/dist/build/buildConnections.js +2 -2
  10. package/dist/build/{buildIcons.js → buildImports/buildIconImports.js} +16 -24
  11. package/dist/build/buildImports/buildImports.js +30 -0
  12. package/dist/build/buildImports/buildImportsDev.js +106 -0
  13. package/dist/build/buildImports/buildImportsProd.js +54 -0
  14. package/dist/build/{buildStyles.js → buildImports/buildStyleImports.js} +8 -12
  15. package/dist/build/buildImports/defaultIconsDev.js +584 -0
  16. package/dist/build/buildImports/defaultIconsProd.js +21 -0
  17. package/dist/build/buildMenu.js +10 -14
  18. package/dist/build/buildPages/buildBlock/buildBlock.js +8 -4
  19. package/dist/build/buildPages/buildBlock/buildEvents.js +8 -7
  20. package/dist/build/buildPages/buildBlock/buildRequests.js +1 -1
  21. package/dist/build/buildPages/buildBlock/buildSubBlocks.js +3 -8
  22. package/dist/build/buildPages/buildBlock/countBlockOperators.js +2 -2
  23. package/dist/build/buildPages/buildBlock/countBlockTypes.js +18 -0
  24. package/dist/build/buildPages/buildBlock/moveSkeletonBlocksToArea.js +35 -0
  25. package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +1 -1
  26. package/dist/build/buildPages/buildBlock/setBlockId.js +1 -1
  27. package/dist/build/buildPages/buildBlock/validateBlock.js +2 -3
  28. package/dist/build/buildPages/buildPage.js +3 -3
  29. package/dist/build/buildPages/buildPages.js +4 -6
  30. package/dist/build/buildPages/buildTestPage.js +46 -0
  31. package/dist/build/buildRefs/buildRefs.js +11 -5
  32. package/dist/build/buildRefs/evaluateBuildOperators.js +3 -4
  33. package/dist/build/buildRefs/getConfigFile.js +2 -2
  34. package/dist/build/buildRefs/getRefContent.js +1 -1
  35. package/dist/build/buildRefs/getRefPath.js +1 -1
  36. package/dist/build/buildRefs/getRefsFromFile.js +1 -1
  37. package/dist/build/buildRefs/getUserJavascriptFunction.js +3 -2
  38. package/dist/build/buildRefs/makeRefDefinition.js +2 -1
  39. package/dist/build/buildRefs/parseNunjucks.js +1 -1
  40. package/dist/build/buildRefs/parseRefContent.js +9 -4
  41. package/dist/build/buildRefs/populateRefs.js +4 -4
  42. package/dist/build/buildRefs/recursiveBuild.js +6 -6
  43. package/dist/build/buildRefs/runRefResolver.js +1 -1
  44. package/dist/build/buildRefs/runTransformer.js +1 -1
  45. package/dist/build/buildTypes.js +39 -2
  46. package/dist/build/cleanBuildDirectory.js +1 -1
  47. package/dist/build/copyPublicFolder.js +1 -1
  48. package/dist/build/testSchema.js +5 -7
  49. package/dist/build/updateServerPackageJson.js +5 -1
  50. package/dist/build/validateApp.js +2 -2
  51. package/dist/build/validateConfig.js +2 -29
  52. package/dist/build/writeApp.js +1 -1
  53. package/dist/build/writeAuth.js +18 -0
  54. package/dist/build/writeConfig.js +1 -1
  55. package/dist/build/writeConnections.js +1 -1
  56. package/dist/build/writeGlobal.js +1 -1
  57. package/dist/build/writeMenus.js +1 -1
  58. package/dist/build/writePages.js +2 -3
  59. package/dist/build/writePluginImports/generateImportFile.js +2 -7
  60. package/dist/build/writePluginImports/writeActionImports.js +2 -2
  61. package/dist/build/writePluginImports/writeAuthImports.js +34 -0
  62. package/dist/build/writePluginImports/writeBlockImports.js +2 -2
  63. package/dist/build/writePluginImports/writeConnectionImports.js +2 -2
  64. package/dist/build/writePluginImports/writeIconImports.js +2 -2
  65. package/dist/build/writePluginImports/writeOperatorImports.js +5 -5
  66. package/dist/build/writePluginImports/writePluginImports.js +52 -0
  67. package/dist/build/writePluginImports/writeStyleImports.js +10 -3
  68. package/dist/build/writeRequests.js +2 -3
  69. package/dist/build/writeTypes.js +1 -1
  70. package/dist/createContext.js +55 -0
  71. package/dist/{defaultTypesMap.json → defaultTypesMap.js} +989 -388
  72. package/dist/index.js +20 -78
  73. package/dist/lowdefySchema.js +177 -68
  74. package/dist/scripts/generateDefaultTypes.js +22 -4
  75. package/dist/scripts/run.js +5 -4
  76. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +1 -1
  77. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +1 -1
  78. package/dist/test/buildRefs/testBuildRefsNullResolver.js +1 -1
  79. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +1 -1
  80. package/dist/test/buildRefs/testBuildRefsResolver.js +2 -2
  81. package/dist/test/buildRefs/testBuildRefsTransform.js +1 -1
  82. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +1 -1
  83. package/dist/test/testContext.js +8 -2
  84. package/dist/utils/countOperators.js +1 -1
  85. package/dist/utils/createCheckDuplicateId.js +1 -1
  86. package/dist/utils/createCounter.js +1 -1
  87. package/dist/utils/createPluginTypesMap.js +29 -1
  88. package/dist/utils/formatErrorMessage.js +1 -1
  89. package/dist/utils/readConfigFile.js +5 -2
  90. package/dist/utils/writeBuildArtifact.js +1 -1
  91. package/package.json +55 -44
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -35,6 +35,9 @@ function checkAction(action, { blockId , checkDuplicateActionId , eventId , page
35
35
  function buildEvents(block, pageContext) {
36
36
  if (block.events) {
37
37
  Object.keys(block.events).map((key)=>{
38
+ if (!type.isArray(block.events[key]) && !type.isObject(block.events[key]) || type.isObject(block.events[key]) && type.isNone(block.events[key].try)) {
39
+ throw new Error(`Actions must be an array at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
40
+ }
38
41
  if (type.isArray(block.events[key])) {
39
42
  block.events[key] = {
40
43
  try: block.events[key],
@@ -42,13 +45,13 @@ function buildEvents(block, pageContext) {
42
45
  };
43
46
  }
44
47
  if (!type.isArray(block.events[key].try)) {
45
- throw new Error(`Events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
48
+ throw new Error(`Try actions must be an array at "${block.blockId}" in event "${key}.try" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
46
49
  }
47
50
  if (type.isNone(block.events[key].catch)) {
48
51
  block.events[key].catch = [];
49
52
  }
50
53
  if (!type.isArray(block.events[key].catch)) {
51
- throw new Error(`Catch events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
54
+ throw new Error(`Catch actions must be an array at "${block.blockId}" in event "${key}.catch" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
52
55
  }
53
56
  const checkDuplicateActionId = createCheckDuplicateId({
54
57
  message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
@@ -59,16 +62,14 @@ function buildEvents(block, pageContext) {
59
62
  typeCounters: pageContext.typeCounters,
60
63
  pageId: pageContext.pageId,
61
64
  checkDuplicateActionId
62
- })
63
- );
65
+ }));
64
66
  block.events[key].catch.map((action)=>checkAction(action, {
65
67
  eventId: key,
66
68
  blockId: block.blockId,
67
69
  typeCounters: pageContext.typeCounters,
68
70
  pageId: pageContext.pageId,
69
71
  checkDuplicateActionId
70
- })
71
- );
72
+ }));
72
73
  });
73
74
  }
74
75
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,9 +14,8 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import buildBlock from './buildBlock.js';
17
- async function buildSubBlocks(block, pageContext) {
17
+ function buildSubBlocks(block, pageContext) {
18
18
  if (type.isObject(block.areas)) {
19
- let promises = [];
20
19
  Object.keys(block.areas).forEach((key)=>{
21
20
  if (type.isNone(block.areas[key].blocks)) {
22
21
  block.areas[key].blocks = [];
@@ -24,12 +23,8 @@ async function buildSubBlocks(block, pageContext) {
24
23
  if (!type.isArray(block.areas[key].blocks)) {
25
24
  throw new Error(`Expected blocks to be an array at ${block.blockId} in area ${key} on page ${pageContext.pageId}. Received ${JSON.stringify(block.areas[key].blocks)}`);
26
25
  }
27
- const blockPromises = block.areas[key].blocks.map(async (blk)=>{
28
- await buildBlock(blk, pageContext);
29
- });
30
- promises = promises.concat(blockPromises);
26
+ block.areas[key].blocks.map((blk)=>buildBlock(blk, pageContext));
31
27
  });
32
- await Promise.all(promises);
33
28
  }
34
29
  }
35
30
  export default buildSubBlocks;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
15
15
  */ import countOperators from '../../../utils/countOperators.js';
16
16
  function countBlockOperators(block, { typeCounters }) {
17
17
  // eslint-disable-next-line no-unused-vars
18
- const { requests , blocks , areas , ...webBlock } = block;
18
+ const { requests , areas , blocks , ...webBlock } = block;
19
19
  countOperators(webBlock, {
20
20
  counter: typeCounters.operators.client
21
21
  });
@@ -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;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
- function validateBlock(block, { pageId , typeCounters }) {
16
+ function validateBlock(block, { pageId }) {
17
17
  if (!type.isObject(block)) {
18
18
  throw new Error(`Expected block to be an object on page "${pageId}". Received ${JSON.stringify(block)}.`);
19
19
  }
@@ -29,7 +29,6 @@ function validateBlock(block, { pageId , typeCounters }) {
29
29
  if (!type.isString(block.type)) {
30
30
  throw new Error(`Block type is not a string at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.type)}.`);
31
31
  }
32
- typeCounters.blocks.increment(block.type);
33
32
  if (!type.isNone(block.requests)) {
34
33
  if (!type.isArray(block.requests)) {
35
34
  throw new Error(`Requests is not an array at "${block.id}" on page "${pageId}". Received ${JSON.stringify(block.requests)}`);
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
16
16
  import buildBlock from './buildBlock/buildBlock.js';
17
17
  import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
18
  import createCounter from '../../utils/createCounter.js';
19
- async function buildPage({ page , index , context , checkDuplicatePageId }) {
19
+ function buildPage({ page , index , context , checkDuplicatePageId }) {
20
20
  if (type.isUndefined(page.id)) {
21
21
  throw new Error(`Page id missing at page ${index}.`);
22
22
  }
@@ -29,7 +29,7 @@ async function buildPage({ page , index , context , checkDuplicatePageId }) {
29
29
  page.pageId = page.id;
30
30
  const requests = [];
31
31
  const operators = new Set();
32
- await buildBlock(page, {
32
+ buildBlock(page, {
33
33
  auth: page.auth,
34
34
  blockIdCounter: createCounter(),
35
35
  checkDuplicateRequestId: createCheckDuplicateId({
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-param-reassign */ /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,19 +15,17 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import buildPage from './buildPage.js';
17
17
  import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
- async function buildPages({ components , context }) {
18
+ function buildPages({ components , context }) {
19
19
  const pages = type.isArray(components.pages) ? components.pages : [];
20
20
  const checkDuplicatePageId = createCheckDuplicateId({
21
21
  message: 'Duplicate pageId "{{ id }}".'
22
22
  });
23
- const pageBuildPromises = pages.map((page, index)=>buildPage({
23
+ pages.map((page, index)=>buildPage({
24
24
  page,
25
25
  index,
26
26
  context,
27
27
  checkDuplicatePageId
28
- })
29
- );
30
- await Promise.all(pageBuildPromises);
28
+ }));
31
29
  return components;
32
30
  }
33
31
  export default buildPages;
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-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
+ */ // Used in @lowdefy/engine tests
16
+ import buildAuth from '../buildAuth/buildAuth.js';
17
+ import buildPages from './buildPages.js';
18
+ import createContext from '../../createContext.js';
19
+ function buildTestPage({ pageConfig }) {
20
+ const context = createContext({
21
+ customTypesMap: {},
22
+ directories: {},
23
+ logger: {
24
+ debug: ()=>{},
25
+ log: ()=>{},
26
+ warn: ()=>{},
27
+ error: ()=>{}
28
+ },
29
+ stage: 'test'
30
+ });
31
+ const components = {
32
+ pages: [
33
+ pageConfig
34
+ ]
35
+ };
36
+ buildAuth({
37
+ components,
38
+ context
39
+ });
40
+ buildPages({
41
+ components,
42
+ context
43
+ });
44
+ return components.pages[0];
45
+ }
46
+ export default buildTestPage;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,13 +14,19 @@
14
14
  limitations under the License.
15
15
  */ import recursiveBuild from './recursiveBuild.js';
16
16
  import makeRefDefinition from './makeRefDefinition.js';
17
- // TODO: build operators aren't evaluated in lowdefy.yaml file. Move recursive call up a layer or something.
17
+ import evaluateBuildOperators from './evaluateBuildOperators.js';
18
18
  async function buildRefs({ context }) {
19
- const components = await recursiveBuild({
19
+ const refDef = makeRefDefinition('lowdefy.yaml');
20
+ let components = await recursiveBuild({
20
21
  context,
21
- refDef: makeRefDefinition('lowdefy.yaml'),
22
+ refDef,
22
23
  count: 0
23
24
  });
24
- return components || {};
25
+ components = await evaluateBuildOperators({
26
+ context,
27
+ input: components,
28
+ refDef
29
+ });
30
+ return components ?? {};
25
31
  }
26
32
  export default buildRefs;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -21,13 +21,12 @@ async function evaluateBuildOperators({ context , input , refDef }) {
21
21
  });
22
22
  const { output , errors } = operatorsParser.parse({
23
23
  input,
24
- location: refDef.path,
24
+ location: refDef.path ?? refDef.resolver,
25
25
  operatorPrefix: '_build.'
26
26
  });
27
27
  if (errors.length > 0) {
28
28
  await context.logger.warn('Build operator errors.');
29
- const promises = errors.map((error)=>context.logger.warn(error.message)
30
- );
29
+ const promises = errors.map((error)=>context.logger.warn(error.message));
31
30
  await promises;
32
31
  }
33
32
  return output;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ async function getConfigFile({ context , refDef , referencedFrom }) {
19
19
  _ref: refDef.original
20
20
  })} in file ${referencedFrom}`);
21
21
  }
22
- const content = context.readConfigFile(refDef.path);
22
+ const content = await context.readConfigFile(refDef.path);
23
23
  if (content === null) {
24
24
  throw new Error(`Tried to reference file "${refDef.path}" from "${referencedFrom}", but file does not exist.`);
25
25
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
+ import { pathToFileURL } from 'url';
16
17
  async function getUserJavascriptFunction({ context , filePath }) {
17
18
  try {
18
- return (await import(path.resolve(context.directories.config, filePath))).default;
19
+ return (await import(pathToFileURL(path.join(context.directories.config, filePath)))).default;
19
20
  } catch (error) {
20
21
  context.logger.error(`Error importing ${filePath}.`);
21
22
  throw Error(error);
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ function makeRefDefinition(refDefinition) {
20
20
  id: uuid(),
21
21
  original: refDefinition,
22
22
  path: getRefPath(refDefinition),
23
+ key: get(refDefinition, 'key'),
23
24
  resolver: get(refDefinition, 'resolver'),
24
25
  transformer: get(refDefinition, 'transformer'),
25
26
  vars: get(refDefinition, 'vars', {
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,7 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { type } from '@lowdefy/helpers';
15
+ */ /* eslint-disable no-param-reassign */ import { get, type } from '@lowdefy/helpers';
16
16
  import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
17
17
  import JSON5 from 'json5';
18
18
  import YAML from 'yaml';
@@ -26,12 +26,17 @@ function parseRefContent({ content , refDef }) {
26
26
  ext = getFileSubExtension(path);
27
27
  }
28
28
  if (ext === 'yaml' || ext === 'yml') {
29
- return YAML.parse(content);
29
+ content = YAML.parse(content);
30
30
  }
31
31
  if (ext === 'json') {
32
- return JSON5.parse(content);
32
+ content = JSON5.parse(content);
33
33
  }
34
34
  }
35
+ if (refDef.key) {
36
+ content = get(content, refDef.key, {
37
+ default: null
38
+ });
39
+ }
35
40
  return content;
36
41
  }
37
42
  export default parseRefContent;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -24,12 +24,12 @@ function refReviver(key, value) {
24
24
  default: null
25
25
  })));
26
26
  }
27
- if (type.isObject(value._var) && type.isString(value._var.name)) {
28
- return JSON.parse(JSON.stringify(get(this.vars, value._var.name, {
27
+ if (type.isObject(value._var) && type.isString(value._var.key)) {
28
+ return JSON.parse(JSON.stringify(get(this.vars, value._var.key, {
29
29
  default: type.isNone(value._var.default) ? null : value._var.default
30
30
  })));
31
31
  }
32
- throw new Error(`"_var" operator takes a string or object with name field as arguments. Received "${JSON.stringify(value)}"`);
32
+ throw new Error(`"_var" operator takes a string or object with "key" field as arguments. Received "${JSON.stringify(value)}"`);
33
33
  }
34
34
  }
35
35
  return value;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
33
33
  // the deeper nodes, so we can use those parsed files in references higher in the tree.
34
34
  // To do this, since foundRefs is an array of ref definitions that are in order of the
35
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
36
  for (const newRefDef of foundRefs.values()){
38
37
  // Parse vars and path before passing down to parse new file
39
38
  const parsedRefDef = populateRefs({
@@ -47,17 +46,18 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
47
46
  count: count + 1,
48
47
  referencedFrom: refDef.path
49
48
  });
50
- const evaluatedOperators = await evaluateBuildOperators({
49
+ const transformedFile = await runTransformer({
51
50
  context,
52
51
  input: parsedFile,
53
52
  refDef: parsedRefDef
54
53
  });
55
- const transformedFile = await runTransformer({
54
+ // Evaluated in recursive loop for better error messages
55
+ const evaluatedOperators = await evaluateBuildOperators({
56
56
  context,
57
- input: evaluatedOperators,
57
+ input: transformedFile,
58
58
  refDef: parsedRefDef
59
59
  });
60
- parsedFiles[newRefDef.id] = transformedFile;
60
+ parsedFiles[newRefDef.id] = evaluatedOperators;
61
61
  }
62
62
  return populateRefs({
63
63
  toPopulate: fileContentBuiltRefs,
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -12,7 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function buildTypeClass(context, { counter , definitions , store , typeClass , warnIfMissing =false }) {
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 }) {
16
18
  const counts = counter.getCounts();
17
19
  Object.keys(counts).forEach((typeName)=>{
18
20
  if (!definitions[typeName]) {
@@ -32,11 +34,22 @@
32
34
  }
33
35
  function buildTypes({ components , context }) {
34
36
  const { typeCounters } = context;
37
+ // Add Mandatory Types
35
38
  // Add operators used by form validation
36
39
  typeCounters.operators.client.increment('_not');
37
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
38
45
  components.types = {
39
46
  actions: {},
47
+ auth: {
48
+ adapters: {},
49
+ callbacks: {},
50
+ events: {},
51
+ providers: {}
52
+ },
40
53
  blocks: {},
41
54
  connections: {},
42
55
  requests: {},
@@ -51,6 +64,30 @@ function buildTypes({ components , context }) {
51
64
  store: components.types.actions,
52
65
  typeClass: 'Action'
53
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
+ });
54
91
  buildTypeClass(context, {
55
92
  counter: typeCounters.blocks,
56
93
  definitions: context.typesMap.blocks,
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.