@lowdefy/build 4.0.0-rc.1 → 4.0.0-rc.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 (77) hide show
  1. package/dist/build/addDefaultPages/addDefaultPages.js +1 -1
  2. package/dist/build/addKeys.js +48 -0
  3. package/dist/build/buildAuth/buildAuth.js +1 -1
  4. package/dist/build/buildAuth/buildAuthPlugins.js +4 -4
  5. package/dist/build/buildAuth/buildPageAuth.js +1 -1
  6. package/dist/build/buildAuth/getPageRoles.js +1 -1
  7. package/dist/build/buildAuth/getProtectedPages.js +1 -1
  8. package/dist/build/buildAuth/validateAuthConfig.js +1 -1
  9. package/dist/build/buildConnections.js +1 -1
  10. package/dist/build/buildImports/buildIconImports.js +3 -3
  11. package/dist/build/buildImports/buildImports.js +1 -1
  12. package/dist/build/buildImports/buildImportsDev.js +3 -3
  13. package/dist/build/buildImports/buildImportsProd.js +1 -1
  14. package/dist/build/buildImports/buildStyleImports.js +1 -1
  15. package/dist/build/buildMenu.js +3 -3
  16. package/dist/build/buildPages/buildBlock/buildEvents.js +1 -1
  17. package/dist/build/buildPages/buildBlock/buildRequests.js +1 -1
  18. package/dist/build/buildPages/buildBlock/countBlockOperators.js +2 -2
  19. package/dist/build/buildPages/buildBlock/countBlockTypes.js +1 -1
  20. package/dist/build/buildPages/buildBlock/setBlockId.js +1 -1
  21. package/dist/build/buildPages/buildBlock/validateBlock.js +1 -1
  22. package/dist/build/buildPages/buildPage.js +1 -1
  23. package/dist/build/buildPages/buildPages.js +1 -1
  24. package/dist/build/buildPages/buildTestPage.js +1 -1
  25. package/dist/build/buildRefs/buildRefs.js +2 -2
  26. package/dist/build/buildRefs/evaluateBuildOperators.js +4 -4
  27. package/dist/build/buildRefs/getConfigFile.js +1 -1
  28. package/dist/build/buildRefs/getKey.js +1 -1
  29. package/dist/build/buildRefs/getRefContent.js +1 -1
  30. package/dist/build/buildRefs/getRefsFromFile.js +2 -2
  31. package/dist/build/buildRefs/getUserJavascriptFunction.js +1 -1
  32. package/dist/build/buildRefs/makeRefDefinition.js +10 -4
  33. package/dist/build/buildRefs/parseRefContent.js +2 -2
  34. package/dist/build/buildRefs/populateRefs.js +1 -1
  35. package/dist/build/buildRefs/recursiveBuild.js +20 -7
  36. package/dist/build/buildRefs/runRefResolver.js +1 -1
  37. package/dist/build/buildRefs/runTransformer.js +1 -1
  38. package/dist/build/buildTypes.js +3 -3
  39. package/dist/build/cleanBuildDirectory.js +1 -1
  40. package/dist/build/copyPublicFolder.js +1 -1
  41. package/dist/build/testSchema.js +2 -2
  42. package/dist/build/updateServerPackageJson.js +2 -7
  43. package/dist/build/validateApp.js +1 -1
  44. package/dist/build/validateConfig.js +1 -1
  45. package/dist/build/writeApp.js +5 -2
  46. package/dist/build/writeAuth.js +5 -2
  47. package/dist/build/writeConfig.js +5 -2
  48. package/dist/build/writeConnections.js +5 -3
  49. package/dist/build/writeGlobal.js +5 -3
  50. package/dist/build/writeMaps.js +30 -0
  51. package/dist/build/writeMenus.js +5 -3
  52. package/dist/build/writePages.js +6 -3
  53. package/dist/build/writePluginImports/generateImportFile.js +1 -1
  54. package/dist/build/writePluginImports/writeActionImports.js +1 -1
  55. package/dist/build/writePluginImports/writeAuthImports.js +1 -1
  56. package/dist/build/writePluginImports/writeBlockImports.js +1 -1
  57. package/dist/build/writePluginImports/writeConnectionImports.js +1 -1
  58. package/dist/build/writePluginImports/writeIconImports.js +1 -1
  59. package/dist/build/writePluginImports/writeOperatorImports.js +1 -1
  60. package/dist/build/writePluginImports/writePluginImports.js +1 -1
  61. package/dist/build/writePluginImports/writeStyleImports.js +1 -1
  62. package/dist/build/writeRequests.js +6 -3
  63. package/dist/build/writeTypes.js +5 -2
  64. package/dist/createContext.js +3 -1
  65. package/dist/defaultTypesMap.js +339 -356
  66. package/dist/index.js +10 -0
  67. package/dist/lowdefySchema.js +6 -0
  68. package/dist/scripts/generateDefaultTypes.js +1 -1
  69. package/dist/test/testContext.js +4 -2
  70. package/dist/utils/countOperators.js +1 -1
  71. package/dist/utils/createCheckDuplicateId.js +2 -2
  72. package/dist/utils/createPluginTypesMap.js +2 -2
  73. package/dist/utils/formatErrorMessage.js +3 -3
  74. package/dist/utils/makeId.js +20 -0
  75. package/dist/utils/readConfigFile.js +1 -1
  76. package/dist/utils/writeBuildArtifact.js +1 -1
  77. package/package.json +45 -46
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import page404 from './404.js';
17
- function addDefaultPages({ components }) {
17
+ function addDefaultPages({ components }) {
18
18
  // If not copied, the same object is mutated by build every time
19
19
  // build runs for dev server. See #647
20
20
  const defaultPages = [
@@ -0,0 +1,48 @@
1
+ /*
2
+ Copyright 2020-2023 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 makeId from '../utils/makeId.js';
17
+ function recAddKeys(object, key, keyMap, parentId) {
18
+ const id = makeId();
19
+ keyMap[id] = {
20
+ key,
21
+ '~r': object['~r'],
22
+ '~k_parent': parentId
23
+ };
24
+ Object.defineProperty(object, '~k', {
25
+ value: id,
26
+ enumerable: false,
27
+ writable: true,
28
+ configurable: true
29
+ });
30
+ delete object['~r'];
31
+ Object.keys(object).forEach((nextKey)=>{
32
+ if (type.isObject(object[nextKey])) {
33
+ recAddKeys(object[nextKey], `${key}.${nextKey}`, keyMap, id);
34
+ }
35
+ if (type.isArray(object[nextKey])) {
36
+ object[nextKey].forEach((item, index)=>{
37
+ if (type.isObject(item)) {
38
+ recAddKeys(item, `${key}.${nextKey}[${index}:${item.blockId ?? item.menuId ?? item.menuItemId ?? item.requestId ?? item.connectionId ?? item.connectionId ?? item.id}:${item.type}]`, keyMap, id);
39
+ }
40
+ });
41
+ }
42
+ });
43
+ }
44
+ function addKeys({ components, context }) {
45
+ const id = makeId();
46
+ recAddKeys(components, 'root', context.keyMap, id);
47
+ }
48
+ export default addKeys;
@@ -16,7 +16,7 @@
16
16
  import buildAuthPlugins from './buildAuthPlugins.js';
17
17
  import buildPageAuth from './buildPageAuth.js';
18
18
  import validateAuthConfig from './validateAuthConfig.js';
19
- function buildAuth({ components , context }) {
19
+ function buildAuth({ components, context }) {
20
20
  const configured = !type.isNone(components.auth);
21
21
  validateAuthConfig({
22
22
  components
@@ -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 buildAuthPlugin({ counter , pluginConfig , typeClass }) {
16
+ function buildAuthPlugin({ counter, pluginConfig, typeClass }) {
17
17
  if (type.isArray(pluginConfig)) {
18
18
  pluginConfig.forEach((plugin)=>{
19
19
  if (type.isUndefined(plugin.id)) {
@@ -29,8 +29,8 @@ function buildAuthPlugin({ counter , pluginConfig , typeClass }) {
29
29
  });
30
30
  }
31
31
  }
32
- function buildAdapter({ components , context }) {
33
- const { adapter } = components.auth;
32
+ function buildAdapter({ components, context }) {
33
+ const { adapter } = components.auth;
34
34
  if (type.isNone(adapter)) {
35
35
  return;
36
36
  }
@@ -45,7 +45,7 @@ function buildAdapter({ components , context }) {
45
45
  }
46
46
  context.typeCounters.auth.adapters.increment(adapter.type);
47
47
  }
48
- function buildAuthPlugins({ components , context }) {
48
+ function buildAuthPlugins({ components, context }) {
49
49
  const counters = context.typeCounters.auth;
50
50
  const authConfig = components.auth;
51
51
  buildAdapter({
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import getPageRoles from './getPageRoles.js';
17
17
  import getProtectedPages from './getProtectedPages.js';
18
- function buildPageAuth({ components }) {
18
+ function buildPageAuth({ components }) {
19
19
  const protectedPages = getProtectedPages({
20
20
  components
21
21
  });
@@ -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
- */ function getPageRoles({ components }) {
15
+ */ function getPageRoles({ components }) {
16
16
  const roles = components.auth.pages.roles;
17
17
  const pageRoles = {};
18
18
  Object.keys(roles).forEach((roleName)=>{
@@ -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 getProtectedPages({ components }) {
16
+ function getProtectedPages({ components }) {
17
17
  const pageIds = (components.pages || []).map((page)=>page.id);
18
18
  let protectedPages = [];
19
19
  if (type.isArray(components.auth.pages.public)) {
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import { validate } from '@lowdefy/ajv';
17
17
  import lowdefySchema from '../../lowdefySchema.js';
18
- async function validateAuthConfig({ components }) {
18
+ async function validateAuthConfig({ components }) {
19
19
  if (type.isNone(components.auth)) {
20
20
  components.auth = {};
21
21
  }
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import countOperators from '../utils/countOperators.js';
17
17
  import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
18
- function buildConnections({ components , context }) {
18
+ function buildConnections({ components, context }) {
19
19
  const checkDuplicateConnectionId = createCheckDuplicateId({
20
20
  message: 'Duplicate connectionId "{{ id }}".'
21
21
  });
@@ -40,7 +40,7 @@
40
40
  'react-icons/vsc': /"(Vsc[A-Z0-9]\w*)"/gm,
41
41
  'react-icons/wi': /"(Wi[A-Z0-9]\w*)"/gm
42
42
  };
43
- function getConfigIcons({ components , icons , regex }) {
43
+ function getConfigIcons({ components, icons, regex }) {
44
44
  [
45
45
  ...JSON.stringify(components.global || {}).matchAll(regex)
46
46
  ].map((match)=>icons.add(match[1]));
@@ -51,7 +51,7 @@ function getConfigIcons({ components , icons , regex }) {
51
51
  ...JSON.stringify(components.pages || []).matchAll(regex)
52
52
  ].map((match)=>icons.add(match[1]));
53
53
  }
54
- function getBlockDefaultIcons({ blocks , context , icons , regex }) {
54
+ function getBlockDefaultIcons({ blocks, context, icons, regex }) {
55
55
  blocks.forEach((block)=>{
56
56
  (context.typesMap.icons[block.typeName] || []).forEach((icon)=>{
57
57
  [
@@ -60,7 +60,7 @@ function getBlockDefaultIcons({ blocks , context , icons , regex }) {
60
60
  });
61
61
  });
62
62
  }
63
- function buildIconImports({ blocks , components , context , defaults ={} }) {
63
+ function buildIconImports({ blocks, components, context, defaults = {} }) {
64
64
  const iconImports = [];
65
65
  Object.entries(iconPackages).forEach(([iconPackage, regex])=>{
66
66
  defaults;
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import buildImportsDev from './buildImportsDev.js';
16
16
  import buildImportsProd from './buildImportsProd.js';
17
- function buildImports({ components , context }) {
17
+ function buildImports({ components, context }) {
18
18
  if (context.stage === 'dev') {
19
19
  components.imports = buildImportsDev({
20
20
  components,
@@ -15,7 +15,7 @@
15
15
  */ import buildIconImports from './buildIconImports.js';
16
16
  import buildStyleImports from './buildStyleImports.js';
17
17
  import defaultIconsDev from './defaultIconsDev.js';
18
- function getPluginPackages({ components }) {
18
+ function getPluginPackages({ components }) {
19
19
  const pluginPackages = new Set();
20
20
  function getPackages(types) {
21
21
  Object.values(types).forEach((type)=>{
@@ -34,14 +34,14 @@ function getPluginPackages({ components }) {
34
34
  getPackages(components.types.operators.server);
35
35
  return pluginPackages;
36
36
  }
37
- function buildImportClassDev({ pluginPackages , map }) {
37
+ function buildImportClassDev({ pluginPackages, map }) {
38
38
  return Object.entries(map).map(([typeName, type])=>({
39
39
  originalTypeName: type.originalTypeName,
40
40
  package: type.package,
41
41
  typeName
42
42
  })).filter((type)=>pluginPackages.has(type.package));
43
43
  }
44
- function buildImportsDev({ components , context }) {
44
+ function buildImportsDev({ components, context }) {
45
45
  const pluginPackages = getPluginPackages({
46
46
  components
47
47
  });
@@ -22,7 +22,7 @@ function buildImportClassProd(types) {
22
22
  typeName
23
23
  }));
24
24
  }
25
- function buildImportsProd({ components , context }) {
25
+ function buildImportsProd({ components, context }) {
26
26
  const blocks = buildImportClassProd(components.types.blocks);
27
27
  return {
28
28
  actions: buildImportClassProd(components.types.actions),
@@ -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
- */ function buildStyleImports({ blocks , context }) {
15
+ */ function buildStyleImports({ blocks, context }) {
16
16
  const styles = new Set();
17
17
  blocks.forEach((block)=>{
18
18
  styles.add(...(context.typesMap.styles.packages[block.package] || []).map((style)=>`${block.package}/${style}`));
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
17
- function buildDefaultMenu({ components , context }) {
17
+ function buildDefaultMenu({ components, context }) {
18
18
  context.logger.warn('No menus found. Building default menu.');
19
19
  const pages = type.isArray(components.pages) ? components.pages : [];
20
20
  const menus = [
@@ -30,7 +30,7 @@ function buildDefaultMenu({ components , context }) {
30
30
  ];
31
31
  return menus;
32
32
  }
33
- function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplicateMenuItemId }) {
33
+ function loopItems({ parent, menuId, pages, missingPageWarnings, checkDuplicateMenuItemId }) {
34
34
  if (type.isArray(parent.links)) {
35
35
  parent.links.forEach((menuItem)=>{
36
36
  if (menuItem.type === 'MenuLink') {
@@ -75,7 +75,7 @@ function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplic
75
75
  parent.links = parent.links.filter((item)=>item.remove !== true);
76
76
  }
77
77
  }
78
- function buildMenu({ components , context }) {
78
+ function buildMenu({ components, context }) {
79
79
  const pages = type.isArray(components.pages) ? components.pages : [];
80
80
  if (type.isUndefined(components.menus) || components.menus.length === 0) {
81
81
  components.menus = buildDefaultMenu({
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import createCheckDuplicateId from '../../../utils/createCheckDuplicateId.js';
17
- function checkAction(action, { blockId , checkDuplicateActionId , eventId , pageId , typeCounters }) {
17
+ function checkAction(action, { blockId, checkDuplicateActionId, eventId, pageId, typeCounters }) {
18
18
  if (type.isUndefined(action.id)) {
19
19
  throw new Error(`Action id missing on event "${eventId}" on block "${blockId}" on page "${pageId}".`);
20
20
  }
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  function buildRequest(request, pageContext) {
17
- const { auth , checkDuplicateRequestId , pageId , typeCounters } = pageContext;
17
+ const { auth, checkDuplicateRequestId, pageId, typeCounters } = pageContext;
18
18
  if (type.isUndefined(request.id)) {
19
19
  throw new Error(`Request id missing at page "${pageId}".`);
20
20
  }
@@ -13,9 +13,9 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import countOperators from '../../../utils/countOperators.js';
16
- function countBlockOperators(block, { typeCounters }) {
16
+ function countBlockOperators(block, { typeCounters }) {
17
17
  // eslint-disable-next-line no-unused-vars
18
- const { requests , areas , blocks , ...webBlock } = block;
18
+ const { requests, areas, blocks, ...webBlock } = block;
19
19
  countOperators(webBlock, {
20
20
  counter: typeCounters.operators.client
21
21
  });
@@ -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
- */ function countBlockTypes(block, { typeCounters }) {
15
+ */ function countBlockTypes(block, { typeCounters }) {
16
16
  typeCounters.blocks.increment(block.type);
17
17
  }
18
18
  export default countBlockTypes;
@@ -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
- */ function setBlockId(block, { pageId , blockIdCounter }) {
15
+ */ function setBlockId(block, { pageId, blockIdCounter }) {
16
16
  block.blockId = block.id;
17
17
  block.id = `block:${pageId}:${block.blockId}:${blockIdCounter.getCount(block.blockId)}`;
18
18
  blockIdCounter.increment(block.blockId);
@@ -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 }) {
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
  }
@@ -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
- 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
  }
@@ -15,7 +15,7 @@
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import buildPage from './buildPage.js';
17
17
  import createCheckDuplicateId from '../../utils/createCheckDuplicateId.js';
18
- 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 }}".'
@@ -16,7 +16,7 @@
16
16
  import buildAuth from '../buildAuth/buildAuth.js';
17
17
  import buildPages from './buildPages.js';
18
18
  import createContext from '../../createContext.js';
19
- function buildTestPage({ pageConfig }) {
19
+ function buildTestPage({ pageConfig }) {
20
20
  const context = createContext({
21
21
  customTypesMap: {},
22
22
  directories: {},
@@ -15,8 +15,8 @@
15
15
  */ import recursiveBuild from './recursiveBuild.js';
16
16
  import makeRefDefinition from './makeRefDefinition.js';
17
17
  import evaluateBuildOperators from './evaluateBuildOperators.js';
18
- async function buildRefs({ context }) {
19
- const refDef = makeRefDefinition('lowdefy.yaml');
18
+ async function buildRefs({ context }) {
19
+ const refDef = makeRefDefinition('lowdefy.yaml', null, context.refMap);
20
20
  let components = await recursiveBuild({
21
21
  context,
22
22
  refDef,
@@ -12,14 +12,14 @@
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 { NodeParser } from '@lowdefy/operators';
15
+ */ import { BuildParser } from '@lowdefy/operators';
16
16
  import operators from '@lowdefy/operators-js/operators/build';
17
- async function evaluateBuildOperators({ context , input , refDef }) {
18
- const operatorsParser = new NodeParser({
17
+ async function evaluateBuildOperators({ context, input, refDef }) {
18
+ const operatorsParser = new BuildParser({
19
19
  env: process.env,
20
20
  operators
21
21
  });
22
- const { output , errors } = operatorsParser.parse({
22
+ const { output, errors } = operatorsParser.parse({
23
23
  input,
24
24
  location: refDef.path ?? refDef.resolver,
25
25
  operatorPrefix: '_build.'
@@ -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
- async function getConfigFile({ context , refDef , referencedFrom }) {
16
+ async function getConfigFile({ context, refDef, referencedFrom }) {
17
17
  if (!type.isString(refDef.path)) {
18
18
  throw new Error(`Invalid _ref definition ${JSON.stringify({
19
19
  _ref: refDef.original
@@ -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 { get } from '@lowdefy/helpers';
16
- function getKey({ input , refDef }) {
16
+ function getKey({ input, refDef }) {
17
17
  if (refDef.key) {
18
18
  return get(input, refDef.key, {
19
19
  default: null
@@ -15,7 +15,7 @@
15
15
  */ import getConfigFile from './getConfigFile.js';
16
16
  import parseRefContent from './parseRefContent.js';
17
17
  import runRefResolver from './runRefResolver.js';
18
- async function getRefContent({ context , refDef , referencedFrom }) {
18
+ async function getRefContent({ context, refDef, referencedFrom }) {
19
19
  let content;
20
20
  if (refDef.path === 'lowdefy.yaml' || refDef.path === 'lowdefy.yml') {
21
21
  content = await getConfigFile({
@@ -14,12 +14,12 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import makeRefDefinition from './makeRefDefinition.js';
17
- function getRefsFromFile(fileContent) {
17
+ function getRefsFromFile(fileContent, parentRefDefId, refMap) {
18
18
  const foundRefs = [];
19
19
  const reviver = (key, value)=>{
20
20
  if (type.isObject(value)) {
21
21
  if (!type.isUndefined(value._ref)) {
22
- const def = makeRefDefinition(value._ref);
22
+ const def = makeRefDefinition(value._ref, parentRefDefId, refMap);
23
23
  foundRefs.push(def);
24
24
  return {
25
25
  _ref: def
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
16
  import { pathToFileURL } from 'url';
17
- async function getUserJavascriptFunction({ context , filePath }) {
17
+ async function getUserJavascriptFunction({ context, filePath }) {
18
18
  try {
19
19
  return (await import(pathToFileURL(path.join(context.directories.config, filePath)))).default;
20
20
  } catch (error) {
@@ -13,14 +13,20 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { get } from '@lowdefy/helpers';
16
- import { v1 as uuid } from 'uuid';
17
16
  import getRefPath from './getRefPath.js';
18
- function makeRefDefinition(refDefinition) {
17
+ import makeId from '../../utils/makeId.js';
18
+ function makeRefDefinition(refDefinition, parent, refMap) {
19
+ const id = makeId();
20
+ const refDef = {
21
+ parent
22
+ };
23
+ refMap[id] = refDef;
19
24
  return {
20
- id: uuid(),
25
+ ...refDef,
26
+ id,
27
+ key: get(refDefinition, 'key'),
21
28
  original: refDefinition,
22
29
  path: getRefPath(refDefinition),
23
- key: get(refDefinition, 'key'),
24
30
  resolver: get(refDefinition, 'resolver'),
25
31
  transformer: get(refDefinition, 'transformer'),
26
32
  vars: get(refDefinition, 'vars', {
@@ -17,8 +17,8 @@ import { getFileExtension, getFileSubExtension } from '@lowdefy/node-utils';
17
17
  import JSON5 from 'json5';
18
18
  import YAML from 'yaml';
19
19
  import parseNunjucks from './parseNunjucks.js';
20
- function parseRefContent({ content , refDef }) {
21
- const { path , vars } = refDef;
20
+ function parseRefContent({ content, refDef }) {
21
+ const { path, vars } = refDef;
22
22
  if (type.isString(path)) {
23
23
  let ext = getFileExtension(path);
24
24
  if (ext === 'njk') {
@@ -34,7 +34,7 @@ function refReviver(key, value) {
34
34
  }
35
35
  return value;
36
36
  }
37
- function populateRefs({ parsedFiles , refDef , toPopulate }) {
37
+ function populateRefs({ parsedFiles, refDef, toPopulate }) {
38
38
  return JSON.parse(JSON.stringify(toPopulate), refReviver.bind({
39
39
  parsedFiles,
40
40
  vars: refDef.vars
@@ -12,15 +12,16 @@
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 evaluateBuildOperators from './evaluateBuildOperators.js';
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import evaluateBuildOperators from './evaluateBuildOperators.js';
16
17
  import getKey from './getKey.js';
17
18
  import getRefContent from './getRefContent.js';
18
19
  import getRefsFromFile from './getRefsFromFile.js';
19
20
  import populateRefs from './populateRefs.js';
20
21
  import runTransformer from './runTransformer.js';
21
- async function recursiveParseFile({ context , refDef , count , referencedFrom }) {
22
+ async function recursiveBuild({ context, refDef, count, referencedFrom }) {
22
23
  // TODO: Maybe it would be better to detect a cycle, since this is the real issue here?
23
- if (count > 40) {
24
+ if (count > 10000) {
24
25
  throw new Error(`Maximum recursion depth of references exceeded.`);
25
26
  }
26
27
  let fileContent = await getRefContent({
@@ -28,7 +29,7 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
28
29
  refDef,
29
30
  referencedFrom
30
31
  });
31
- const { foundRefs , fileContentBuiltRefs } = getRefsFromFile(fileContent);
32
+ const { foundRefs, fileContentBuiltRefs } = getRefsFromFile(fileContent, refDef.id, context.refMap);
32
33
  const parsedFiles = {};
33
34
  // Since we can have references in the variables of a reference, we need to first parse
34
35
  // the deeper nodes, so we can use those parsed files in references higher in the tree.
@@ -41,7 +42,8 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
41
42
  parsedFiles,
42
43
  refDef
43
44
  });
44
- const parsedFile = await recursiveParseFile({
45
+ context.refMap[parsedRefDef.id].path = parsedRefDef.path;
46
+ const parsedFile = await recursiveBuild({
45
47
  context,
46
48
  refDef: parsedRefDef,
47
49
  count: count + 1,
@@ -58,10 +60,21 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
58
60
  input: transformedFile,
59
61
  refDef: parsedRefDef
60
62
  });
61
- parsedFiles[newRefDef.id] = getKey({
63
+ const withRefKey = getKey({
62
64
  input: evaluatedOperators,
63
65
  refDef: parsedRefDef
64
66
  });
67
+ const reviver = (_, value)=>{
68
+ if (!type.isObject(value)) return value;
69
+ Object.defineProperty(value, '~r', {
70
+ value: refDef.id,
71
+ enumerable: false,
72
+ writable: true,
73
+ configurable: true
74
+ });
75
+ return value;
76
+ };
77
+ parsedFiles[newRefDef.id] = JSON.parse(JSON.stringify(withRefKey), reviver);
65
78
  }
66
79
  return populateRefs({
67
80
  toPopulate: fileContentBuiltRefs,
@@ -69,4 +82,4 @@ async function recursiveParseFile({ context , refDef , count , referencedFrom }
69
82
  refDef
70
83
  });
71
84
  }
72
- export default recursiveParseFile;
85
+ export default recursiveBuild;
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import { type } from '@lowdefy/helpers';
16
16
  import getUserJavascriptFunction from './getUserJavascriptFunction.js';
17
- async function runRefResolver({ context , refDef , referencedFrom }) {
17
+ async function runRefResolver({ context, refDef, referencedFrom }) {
18
18
  const resolverFn = await getUserJavascriptFunction({
19
19
  context,
20
20
  filePath: refDef.resolver || context.refResolver
@@ -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 getUserJavascriptFunction from './getUserJavascriptFunction.js';
16
- async function runTransformer({ context , input , refDef }) {
16
+ async function runTransformer({ context, input, refDef }) {
17
17
  if (refDef.transformer) {
18
18
  const transformerFn = await getUserJavascriptFunction({
19
19
  context,
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import basicTypes from '@lowdefy/blocks-basic/types';
16
16
  import loaderTypes from '@lowdefy/blocks-loaders/types';
17
- function buildTypeClass(context, { counter , definitions , store , typeClass , warnIfMissing =false }) {
17
+ function buildTypeClass(context, { counter, definitions, store, typeClass, warnIfMissing = false }) {
18
18
  const counts = counter.getCounts();
19
19
  Object.keys(counts).forEach((typeName)=>{
20
20
  if (!definitions[typeName]) {
@@ -32,8 +32,8 @@ function buildTypeClass(context, { counter , definitions , store , typeClass , w
32
32
  };
33
33
  });
34
34
  }
35
- function buildTypes({ components , context }) {
36
- const { typeCounters } = context;
35
+ function buildTypes({ components, context }) {
36
+ const { typeCounters } = context;
37
37
  // Add Mandatory Types
38
38
  // Add operators used by form validation
39
39
  typeCounters.operators.client.increment('_not');
@@ -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 { cleanDirectory } from '@lowdefy/node-utils';
16
- async function cleanBuildDirectory({ context }) {
16
+ async function cleanBuildDirectory({ context }) {
17
17
  await cleanDirectory(context.directories.build);
18
18
  }
19
19
  export default cleanBuildDirectory;
@@ -15,7 +15,7 @@
15
15
  */ import path from 'path';
16
16
  import fs from 'fs';
17
17
  import { cleanDirectory, copyFileOrDirectory } from '@lowdefy/node-utils';
18
- async function copyPublicFolder({ context }) {
18
+ async function copyPublicFolder({ context }) {
19
19
  if (context.directories.config === context.directories.server) return;
20
20
  await cleanDirectory(path.resolve(context.directories.server, 'public'));
21
21
  await copyFileOrDirectory(path.resolve(context.directories.server, 'public_default'), path.resolve(context.directories.server, 'public'));
@@ -15,8 +15,8 @@
15
15
  */ import { validate } from '@lowdefy/ajv';
16
16
  import lowdefySchema from '../lowdefySchema.js';
17
17
  import formatErrorMessage from '../utils/formatErrorMessage.js';
18
- function testSchema({ components , context }) {
19
- const { valid , errors } = validate({
18
+ function testSchema({ components, context }) {
19
+ const { valid, errors } = validate({
20
20
  schema: lowdefySchema,
21
21
  data: components,
22
22
  returnErrors: true