|
1 | | -const _ = require('lodash'); |
2 | | -const applyToInstanceHelper = require('./helpers/applyToInstanceHelper'); |
3 | | -const scriptHelper = require('./helpers/scriptHelper'); |
| 1 | +const { generateScript } = require('./generateScript'); |
| 2 | +const { generateContainerScript } = require('./generateContainerScript'); |
| 3 | +const { applyToInstance, testConnection } = require('./helpers/applyToInstanceHelper'); |
4 | 4 |
|
5 | 5 | module.exports = { |
6 | | - generateContainerScript(data, logger, callback) { |
7 | | - try { |
8 | | - const insertSamplesOption = |
9 | | - _.get(data, 'options.additionalOptions', []).find(option => option.id === 'INCLUDE_SAMPLES') || {}; |
10 | | - const withSamples = data.options.origin !== 'ui'; |
11 | | - const useDb = scriptHelper.useDbStatement(data.containerData); |
12 | | - let script = |
13 | | - useDb + |
14 | | - '\n\n' + |
15 | | - data.entities |
16 | | - .map(entityId => { |
17 | | - const entityData = data.entityData[entityId]; |
18 | | - const script = scriptHelper.getScript({ |
19 | | - entityData, |
20 | | - containerData: data.containerData, |
21 | | - jsonSchema: JSON.parse(data.jsonSchema[entityId]), |
22 | | - definitions: { |
23 | | - internal: JSON.parse(data.internalDefinitions[entityId]), |
24 | | - model: JSON.parse(data.modelDefinitions), |
25 | | - external: JSON.parse(data.externalDefinitions), |
26 | | - }, |
27 | | - }); |
28 | | - |
29 | | - if (entityData?.[0]?.isActivated) { |
30 | | - return script; |
31 | | - } |
32 | | - |
33 | | - return `/*\n${script}\n*/`; |
34 | | - }) |
35 | | - .join('\n\n'); |
36 | | - |
37 | | - const samples = scriptHelper.insertSamples(data); |
38 | | - script += withSamples ? '\n' + samples : ''; |
39 | | - |
40 | | - if (withSamples || !insertSamplesOption.value) { |
41 | | - return callback(null, script); |
42 | | - } |
43 | | - |
44 | | - return callback(null, [ |
45 | | - { title: 'MongoDB script', script }, |
46 | | - { |
47 | | - title: 'Sample data', |
48 | | - script: samples, |
49 | | - }, |
50 | | - ]); |
51 | | - } catch (e) { |
52 | | - const error = { message: e.message, stack: e.stack }; |
53 | | - logger.log('error', error, 'DocumentDB forward engineering error'); |
54 | | - callback(error); |
55 | | - } |
56 | | - }, |
57 | | - |
58 | | - generateScript(data, logger, callback) { |
59 | | - try { |
60 | | - const useDb = scriptHelper.useDbStatement(data.containerData); |
61 | | - const script = scriptHelper.getScript({ |
62 | | - containerData: data.containerData, |
63 | | - entityData: data.entityData, |
64 | | - jsonSchema: JSON.parse(data.jsonSchema), |
65 | | - definitions: { |
66 | | - model: JSON.parse(data.modelDefinitions), |
67 | | - internal: JSON.parse(data.internalDefinitions), |
68 | | - external: JSON.parse(data.externalDefinitions), |
69 | | - }, |
70 | | - }); |
71 | | - const samples = scriptHelper.insertSample({ |
72 | | - containerData: data.containerData, |
73 | | - entityData: data.entityData, |
74 | | - sample: data.jsonData, |
75 | | - }); |
76 | | - |
77 | | - return callback(null, [useDb, script, samples].join('\n\n')); |
78 | | - } catch (e) { |
79 | | - const error = { message: e.message, stack: e.stack }; |
80 | | - logger.log('error', error, 'DocumentDB forward engineering error'); |
81 | | - callback(error); |
82 | | - } |
83 | | - }, |
84 | | - |
85 | | - applyToInstance: applyToInstanceHelper.applyToInstance, |
86 | | - |
87 | | - testConnection: applyToInstanceHelper.testConnection, |
| 6 | + generateScript, |
| 7 | + generateContainerScript, |
| 8 | + applyToInstance, |
| 9 | + testConnection, |
88 | 10 | }; |
0 commit comments