@lowdefy/build 4.0.0-alpha.5 → 4.0.0-alpha.8

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 (57) hide show
  1. package/dist/build/addDefaultPages/404.js +36 -41
  2. package/dist/build/addDefaultPages/addDefaultPages.js +6 -2
  3. package/dist/build/buildAuth/getPageRoles.js +1 -2
  4. package/dist/build/buildConnections.js +1 -2
  5. package/dist/build/buildIcons.js +42 -14
  6. package/dist/build/buildPages/buildBlock/buildEvents.js +4 -1
  7. package/dist/build/buildPages/buildBlock/buildRequests.js +1 -2
  8. package/dist/build/buildPages/buildBlock/countBlockOperators.js +2 -4
  9. package/dist/build/buildRefs/buildRefs.js +2 -2
  10. package/dist/build/buildRefs/evaluateBuildOperators.js +35 -0
  11. package/dist/build/buildRefs/getRefContent.js +1 -1
  12. package/dist/build/buildRefs/getUserJavascriptFunction.js +6 -3
  13. package/dist/build/buildRefs/makeRefDefinition.js +1 -2
  14. package/dist/build/buildRefs/parseRefContent.js +2 -2
  15. package/dist/build/buildRefs/recursiveBuild.js +9 -4
  16. package/dist/build/buildRefs/runTransformer.js +7 -3
  17. package/dist/build/buildStyles.js +2 -2
  18. package/dist/build/buildTypes.js +35 -31
  19. package/dist/build/cleanBuildDirectory.js +1 -1
  20. package/dist/build/copyPublicFolder.js +23 -0
  21. package/dist/build/updateServerPackageJson.js +2 -6
  22. package/dist/build/validateApp.js +2 -8
  23. package/dist/build/validateConfig.js +12 -8
  24. package/dist/build/writeApp.js +1 -5
  25. package/dist/build/writeConfig.js +1 -5
  26. package/dist/build/writeConnections.js +1 -4
  27. package/dist/build/writeGlobal.js +2 -6
  28. package/dist/build/writeMenus.js +1 -4
  29. package/dist/build/writePages.js +2 -13
  30. package/dist/build/writePluginImports/generateImportFile.js +6 -6
  31. package/dist/build/writePluginImports/writeActionImports.js +22 -0
  32. package/dist/build/writePluginImports/writeBlockImports.js +4 -7
  33. package/dist/build/writePluginImports/writeConnectionImports.js +4 -7
  34. package/dist/build/writePluginImports/writeIconImports.js +10 -16
  35. package/dist/build/writePluginImports/writeOperatorImports.js +8 -15
  36. package/dist/build/writePluginImports/writeStyleImports.js +3 -6
  37. package/dist/build/writeRequests.js +2 -7
  38. package/dist/build/writeTypes.js +1 -4
  39. package/dist/defaultTypesMap.json +1499 -0
  40. package/dist/index.js +133 -124
  41. package/dist/lowdefySchema.js +69 -28
  42. package/dist/scripts/generateDefaultTypes.js +34 -70
  43. package/dist/scripts/run.js +7 -3
  44. package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +2 -5
  45. package/dist/test/buildRefs/testBuildRefsErrorResolver.js +1 -1
  46. package/dist/test/buildRefs/testBuildRefsNullResolver.js +1 -1
  47. package/dist/test/buildRefs/testBuildRefsParsingResolver.js +1 -1
  48. package/dist/test/buildRefs/testBuildRefsResolver.js +1 -1
  49. package/dist/test/buildRefs/testBuildRefsTransform.js +1 -1
  50. package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +1 -1
  51. package/dist/test/testContext.js +8 -17
  52. package/dist/utils/createPluginTypesMap.js +85 -0
  53. package/dist/utils/formatErrorMessage.js +1 -1
  54. package/dist/utils/{files/readConfigFile.js → readConfigFile.js} +0 -0
  55. package/dist/utils/{files/writeBuildArtifact.js → writeBuildArtifact.js} +2 -5
  56. package/package.json +47 -23
  57. package/dist/defaultTypes.json +0 -896
package/dist/index.js CHANGED
@@ -12,10 +12,12 @@
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 { readFile } from '@lowdefy/node-utils';
15
+ */ import { mergeObjects } from '@lowdefy/helpers';
16
+ import { readFile } from '@lowdefy/node-utils';
16
17
  import createCounter from './utils/createCounter.js';
17
- import createReadConfigFile from './utils/files/readConfigFile.js';
18
- import createWriteBuildArtifact from './utils/files/writeBuildArtifact.js';
18
+ import createPluginTypesMap from './utils/createPluginTypesMap.js';
19
+ import createReadConfigFile from './utils/readConfigFile.js';
20
+ import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
19
21
  import addDefaultPages from './build/addDefaultPages/addDefaultPages.js';
20
22
  import buildAuth from './build/buildAuth/buildAuth.js';
21
23
  import buildConnections from './build/buildConnections.js';
@@ -26,11 +28,13 @@ import buildRefs from './build/buildRefs/buildRefs.js';
26
28
  import buildStyles from './build/buildStyles.js';
27
29
  import buildTypes from './build/buildTypes.js';
28
30
  import cleanBuildDirectory from './build/cleanBuildDirectory.js';
31
+ import copyPublicFolder from './build/copyPublicFolder.js';
29
32
  import testSchema from './build/testSchema.js';
30
33
  import validateApp from './build/validateApp.js';
31
34
  import validateConfig from './build/validateConfig.js';
32
35
  import updateServerPackageJson from './build/updateServerPackageJson.js';
33
36
  import writeApp from './build/writeApp.js';
37
+ import writeActionImports from './build/writePluginImports/writeActionImports.js';
34
38
  import writeBlockImports from './build/writePluginImports/writeBlockImports.js';
35
39
  import writeConfig from './build/writeConfig.js';
36
40
  import writeConnectionImports from './build/writePluginImports/writeConnectionImports.js';
@@ -43,12 +47,15 @@ import writePages from './build/writePages.js';
43
47
  import writeRequests from './build/writeRequests.js';
44
48
  import writeStyleImports from './build/writePluginImports/writeStyleImports.js';
45
49
  import writeTypes from './build/writeTypes.js';
46
- async function createContext(options) {
47
- const { directories , logger , refResolver } = options;
48
- const defaultTypes = JSON.parse(await readFile(new URL('./defaultTypes.json', import.meta.url).pathname));
49
- // TODO: resolve custom plugin types
50
+ async function createContext({ customTypesMap , directories , logger , refResolver }) {
51
+ const defaultTypesMap = JSON.parse(await readFile(new URL('./defaultTypesMap.json', import.meta.url).pathname));
50
52
  const context = {
51
53
  directories,
54
+ logger,
55
+ readConfigFile: createReadConfigFile({
56
+ directories
57
+ }),
58
+ refResolver,
52
59
  typeCounters: {
53
60
  actions: createCounter(),
54
61
  blocks: createCounter(),
@@ -59,12 +66,10 @@ async function createContext(options) {
59
66
  server: createCounter()
60
67
  }
61
68
  },
62
- logger,
63
- readConfigFile: createReadConfigFile({
64
- directories
65
- }),
66
- refResolver,
67
- types: defaultTypes,
69
+ typesMap: mergeObjects([
70
+ defaultTypesMap,
71
+ customTypesMap
72
+ ]),
68
73
  writeBuildArtifact: createWriteBuildArtifact({
69
74
  directories
70
75
  })
@@ -73,116 +78,120 @@ async function createContext(options) {
73
78
  }
74
79
  async function build(options) {
75
80
  const context = await createContext(options);
76
- try {
77
- const components = await buildRefs({
78
- context
79
- });
80
- await testSchema({
81
- components,
82
- context
83
- });
84
- await validateApp({
85
- components,
86
- context
87
- });
88
- await validateConfig({
89
- components,
90
- context
91
- });
92
- await addDefaultPages({
93
- components,
94
- context
95
- });
96
- await buildAuth({
97
- components,
98
- context
99
- });
100
- await buildConnections({
101
- components,
102
- context
103
- });
104
- await buildPages({
105
- components,
106
- context
107
- });
108
- await buildIcons({
109
- components
110
- });
111
- await buildMenu({
112
- components,
113
- context
114
- });
115
- await buildTypes({
116
- components,
117
- context
118
- });
119
- await buildStyles({
120
- components,
121
- context
122
- });
123
- await cleanBuildDirectory({
124
- context
125
- });
126
- await writeApp({
127
- components,
128
- context
129
- });
130
- await writeConnections({
131
- components,
132
- context
133
- });
134
- await writeRequests({
135
- components,
136
- context
137
- });
138
- await writePages({
139
- components,
140
- context
141
- });
142
- await writeConfig({
143
- components,
144
- context
145
- });
146
- await writeGlobal({
147
- components,
148
- context
149
- });
150
- await writeMenus({
151
- components,
152
- context
153
- });
154
- await writeTypes({
155
- components,
156
- context
157
- });
158
- await writeBlockImports({
159
- components,
160
- context
161
- });
162
- await writeConnectionImports({
163
- components,
164
- context
165
- });
166
- await writeOperatorImports({
167
- components,
168
- context
169
- });
170
- await writeStyleImports({
171
- components,
172
- context
173
- });
174
- await writeIconImports({
175
- components,
176
- context
177
- });
178
- await updateServerPackageJson({
179
- components,
180
- context
181
- });
182
- } catch (error) {
183
- context.logger.error(error);
184
- throw error;
185
- }
81
+ const components = await buildRefs({
82
+ context
83
+ });
84
+ await testSchema({
85
+ components,
86
+ context
87
+ });
88
+ await validateApp({
89
+ components,
90
+ context
91
+ });
92
+ await validateConfig({
93
+ components,
94
+ context
95
+ });
96
+ await addDefaultPages({
97
+ components,
98
+ context
99
+ });
100
+ await buildAuth({
101
+ components,
102
+ context
103
+ });
104
+ await buildConnections({
105
+ components,
106
+ context
107
+ });
108
+ await buildPages({
109
+ components,
110
+ context
111
+ });
112
+ await buildMenu({
113
+ components,
114
+ context
115
+ });
116
+ await buildTypes({
117
+ components,
118
+ context
119
+ });
120
+ await buildIcons({
121
+ components,
122
+ context
123
+ });
124
+ await buildStyles({
125
+ components,
126
+ context
127
+ });
128
+ await cleanBuildDirectory({
129
+ context
130
+ });
131
+ await writeActionImports({
132
+ components,
133
+ context
134
+ });
135
+ await writeApp({
136
+ components,
137
+ context
138
+ });
139
+ await writeConnections({
140
+ components,
141
+ context
142
+ });
143
+ await writeRequests({
144
+ components,
145
+ context
146
+ });
147
+ await writePages({
148
+ components,
149
+ context
150
+ });
151
+ await writeConfig({
152
+ components,
153
+ context
154
+ });
155
+ await writeGlobal({
156
+ components,
157
+ context
158
+ });
159
+ await writeMenus({
160
+ components,
161
+ context
162
+ });
163
+ await writeTypes({
164
+ components,
165
+ context
166
+ });
167
+ await writeBlockImports({
168
+ components,
169
+ context
170
+ });
171
+ await writeConnectionImports({
172
+ components,
173
+ context
174
+ });
175
+ await writeOperatorImports({
176
+ components,
177
+ context
178
+ });
179
+ await writeStyleImports({
180
+ components,
181
+ context
182
+ });
183
+ await writeIconImports({
184
+ components,
185
+ context
186
+ });
187
+ await updateServerPackageJson({
188
+ components,
189
+ context
190
+ });
191
+ await copyPublicFolder({
192
+ components,
193
+ context
194
+ });
186
195
  }
187
- export { createContext };
196
+ export { createContext, createPluginTypesMap };
188
197
  export default build;
@@ -24,12 +24,9 @@ export default {
24
24
  type: 'Action "id" should be a string.'
25
25
  }
26
26
  },
27
- messages: {
28
- },
29
- params: {
30
- },
31
- skip: {
32
- },
27
+ messages: {},
28
+ params: {},
29
+ skip: {},
33
30
  type: {
34
31
  type: 'string',
35
32
  errorMessage: {
@@ -68,12 +65,6 @@ export default {
68
65
  }
69
66
  }
70
67
  }
71
- },
72
- styles: {
73
- type: 'object',
74
- errorMessage: {
75
- type: 'App "app.styles" should be an object.'
76
- }
77
68
  }
78
69
  }
79
70
  },
@@ -253,8 +244,7 @@ export default {
253
244
  type: 'Block "style" should be an object.'
254
245
  }
255
246
  },
256
- visible: {
257
- },
247
+ visible: {},
258
248
  blocks: {
259
249
  type: 'array',
260
250
  items: {
@@ -273,8 +263,7 @@ export default {
273
263
  type: 'Block "requests" should be an array.'
274
264
  }
275
265
  },
276
- required: {
277
- },
266
+ required: {},
278
267
  validate: {
279
268
  type: 'array',
280
269
  items: {
@@ -547,6 +536,41 @@ export default {
547
536
  }
548
537
  }
549
538
  },
539
+ plugin: {
540
+ type: 'object',
541
+ additionalProperties: false,
542
+ required: [
543
+ 'name',
544
+ 'version'
545
+ ],
546
+ properties: {
547
+ name: {
548
+ type: 'string',
549
+ errorMessage: {
550
+ type: 'Plugin "name" should be a string.'
551
+ }
552
+ },
553
+ version: {
554
+ type: 'string',
555
+ errorMessage: {
556
+ type: 'Plugin "version" should be a string.'
557
+ }
558
+ },
559
+ typePrefix: {
560
+ type: 'string',
561
+ errorMessage: {
562
+ type: 'Plugin "typePrefix" should be a string.'
563
+ }
564
+ }
565
+ },
566
+ errorMessage: {
567
+ type: 'Plugin should be an object.',
568
+ required: {
569
+ name: 'Plugin should have required property "name".',
570
+ version: 'Plugin should have required property "version".'
571
+ }
572
+ }
573
+ },
550
574
  request: {
551
575
  type: 'object',
552
576
  additionalProperties: false,
@@ -636,6 +660,16 @@ export default {
636
660
  },
637
661
  additionalProperties: false,
638
662
  properties: {
663
+ auth: {
664
+ $ref: '#/definitions/authConfig'
665
+ },
666
+ basePath: {
667
+ type: 'string',
668
+ description: 'App base path to apply to all routes. Base path must start with "/".',
669
+ errorMessage: {
670
+ type: 'App "config.basePath" should be a string.'
671
+ }
672
+ },
639
673
  homePageId: {
640
674
  type: 'string',
641
675
  description: 'Page id to use as homepage. When visiting home route "/", the router will redirect to this page. If not provided, the first page in default or first menu will be used as the homePageId.',
@@ -643,23 +677,30 @@ export default {
643
677
  type: 'App "config.homePageId" should be a string.'
644
678
  }
645
679
  },
646
- auth: {
647
- $ref: '#/definitions/authConfig'
648
- }
649
- }
650
- },
651
- types: {
652
- type: 'object',
653
- patternProperties: {
654
- '^.*$': {
655
- url: 'string',
680
+ theme: {
681
+ type: 'object',
656
682
  errorMessage: {
657
- enum: 'Type "url" should be a string.'
683
+ type: 'App "config.theme" should be an object.'
684
+ },
685
+ properties: {
686
+ lessVariables: {
687
+ type: 'object',
688
+ description: 'App theme less variables.',
689
+ errorMessage: {
690
+ type: 'App "config.theme.lessVariables" should be an object.'
691
+ }
692
+ }
658
693
  }
659
694
  }
695
+ }
696
+ },
697
+ plugins: {
698
+ type: 'array',
699
+ items: {
700
+ $ref: '#/definitions/plugin'
660
701
  },
661
702
  errorMessage: {
662
- type: 'App "types" should be an object.'
703
+ type: 'App "plugins" should be an array.'
663
704
  }
664
705
  },
665
706
  global: {
@@ -14,95 +14,59 @@
14
14
  See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */ import path from 'path';
17
- import { type } from '@lowdefy/helpers';
18
17
  import { readFile, writeFile } from '@lowdefy/node-utils';
18
+ import createPluginTypesMap from '../utils/createPluginTypesMap.js';
19
19
  const defaultPackages = [
20
+ '@lowdefy/actions-core',
20
21
  '@lowdefy/blocks-antd',
21
22
  '@lowdefy/blocks-basic',
22
- // '@lowdefy/blocks-color-selectors',
23
- // '@lowdefy/blocks-echarts',
23
+ '@lowdefy/blocks-color-selectors',
24
+ '@lowdefy/blocks-echarts',
24
25
  '@lowdefy/blocks-loaders',
25
- // '@lowdefy/blocks-markdown',
26
+ '@lowdefy/blocks-markdown',
26
27
  '@lowdefy/connection-axios-http',
28
+ '@lowdefy/connection-elasticsearch',
29
+ '@lowdefy/connection-google-sheets',
30
+ '@lowdefy/connection-knex',
31
+ '@lowdefy/connection-mongodb',
32
+ '@lowdefy/connection-redis',
33
+ '@lowdefy/connection-sendgrid',
34
+ '@lowdefy/connection-stripe',
35
+ '@lowdefy/operators-change-case',
36
+ '@lowdefy/operators-diff',
27
37
  '@lowdefy/operators-js',
28
- '@lowdefy/operators-nunjucks',
38
+ '@lowdefy/operators-mql',
39
+ '@lowdefy/operators-nunjucks',
40
+ '@lowdefy/operators-uuid',
41
+ '@lowdefy/operators-yaml',
29
42
  ];
30
- function createTypeDefinitions({ typeNames , store , packageName , version }) {
31
- if (type.isArray(typeNames)) {
32
- typeNames.forEach((typeName)=>{
33
- store[typeName] = {
34
- package: packageName,
35
- version
36
- };
37
- });
38
- }
39
- }
40
- async function generateDefaultTypes() {
43
+ async function generateDefaultTypesMap() {
41
44
  const packageFile = JSON.parse(await readFile(path.resolve(process.cwd(), './package.json')));
42
- const defaultTypes = {
43
- actions: {
44
- },
45
- blocks: {
46
- },
47
- connections: {
48
- },
49
- requests: {
50
- },
45
+ const defaultTypesMap = {
46
+ actions: {},
47
+ blocks: {},
48
+ connections: {},
49
+ icons: {},
51
50
  operators: {
52
- client: {
53
- },
54
- server: {
55
- }
51
+ client: {},
52
+ server: {}
56
53
  },
54
+ requests: {},
57
55
  styles: {
56
+ packages: {},
57
+ blocks: {}
58
58
  }
59
59
  };
60
60
  await Promise.all(defaultPackages.map(async (packageName)=>{
61
61
  const { default: types } = await import(`${packageName}/types`);
62
62
  const version = packageFile.devDependencies[packageName];
63
- createTypeDefinitions({
64
- typeNames: types.actions,
65
- store: defaultTypes.actions,
66
- packageName,
67
- version
68
- });
69
- createTypeDefinitions({
70
- typeNames: types.blocks,
71
- store: defaultTypes.blocks,
72
- packageName,
73
- version
74
- });
75
- createTypeDefinitions({
76
- typeNames: types.connections,
77
- store: defaultTypes.connections,
78
- packageName,
79
- version
80
- });
81
- createTypeDefinitions({
82
- typeNames: types.requests,
83
- store: defaultTypes.requests,
63
+ createPluginTypesMap({
64
+ packageTypes: types,
65
+ typesMap: defaultTypesMap,
84
66
  packageName,
85
67
  version
86
68
  });
87
- createTypeDefinitions({
88
- typeNames: type.isObject(types.operators) ? types.operators.client : [],
89
- store: defaultTypes.operators.client,
90
- packageName,
91
- version
92
- });
93
- createTypeDefinitions({
94
- typeNames: type.isObject(types.operators) ? types.operators.server : [],
95
- store: defaultTypes.operators.server,
96
- packageName,
97
- version
98
- });
99
- if (type.isObject(types.styles)) {
100
- defaultTypes.styles[packageName] = types.styles;
101
- }
102
69
  }));
103
- await writeFile({
104
- filePath: path.resolve(process.cwd(), './dist/defaultTypes.json'),
105
- content: JSON.stringify(defaultTypes, null, 2)
106
- });
70
+ await writeFile(path.resolve(process.cwd(), './dist/defaultTypesMap.json'), JSON.stringify(defaultTypesMap, null, 2));
107
71
  }
108
- generateDefaultTypes();
72
+ generateDefaultTypesMap();
@@ -14,14 +14,18 @@
14
14
  See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */ import path from 'path';
17
+ import yargs from 'yargs';
18
+ import { hideBin } from 'yargs/helpers';
17
19
  import build from '../index.js';
20
+ const argv = yargs(hideBin(process.argv)).argv;
18
21
  async function run() {
19
22
  await build({
20
23
  logger: console,
24
+ refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
21
25
  directories: {
22
- build: path.resolve(process.env.LOWDEFY_BUILD_DIRECTORY || path.join(process.cwd(), 'build')),
23
- config: path.resolve(process.env.LOWDEFY_CONFIG_DIRECTORY || process.cwd()),
24
- server: path.resolve(process.env.LOWDEFY_SERVER_DIRECTORY || process.cwd())
26
+ build: path.resolve(argv.buildDirectory || process.env.LOWDEFY_DIRECTORY_BUILD || path.join(process.cwd(), 'build')),
27
+ config: path.resolve(argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
28
+ server: path.resolve(argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd())
25
29
  }
26
30
  });
27
31
  }
@@ -12,14 +12,11 @@
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
- */ const wait = (ms)=>{
16
- return new Promise((resolve)=>setTimeout(resolve, ms)
17
- );
18
- };
15
+ */ import { wait } from '@lowdefy/helpers';
19
16
  async function asyncFn() {
20
17
  await wait(20);
21
18
  return {
22
19
  async: true
23
20
  };
24
21
  }
25
- module.exports = asyncFn;
22
+ export default asyncFn;
@@ -15,4 +15,4 @@
15
15
  */ function resolver() {
16
16
  throw new Error('Test error');
17
17
  }
18
- module.exports = resolver;
18
+ export default resolver;
@@ -16,4 +16,4 @@
16
16
  if (path === 'null') return null;
17
17
  return undefined;
18
18
  }
19
- module.exports = resolver;
19
+ export default resolver;
@@ -36,4 +36,4 @@ array:
36
36
  return null;
37
37
  }
38
38
  }
39
- module.exports = resolver;
39
+ export default resolver;
@@ -20,4 +20,4 @@
20
20
  contextId: context.id
21
21
  };
22
22
  }
23
- module.exports = resolver;
23
+ export default resolver;
@@ -22,4 +22,4 @@ function transformer(obj, vars) {
22
22
  var: vars.var1
23
23
  };
24
24
  }
25
- module.exports = transformer;
25
+ export default transformer;
@@ -18,4 +18,4 @@
18
18
  vars
19
19
  };
20
20
  }
21
- module.exports = transformer;
21
+ export default transformer;