karavan-core 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/.bebelrc +3 -0
  2. package/.mocharc.json +11 -0
  3. package/.prettierignore +9 -0
  4. package/.prettierrc +14 -0
  5. package/package.json +62 -0
  6. package/src/core/api/CamelDefinitionApi.ts +3271 -0
  7. package/src/core/api/CamelDefinitionApiExt.ts +757 -0
  8. package/src/core/api/CamelDefinitionYaml.ts +412 -0
  9. package/src/core/api/CamelDefinitionYamlStep.ts +4733 -0
  10. package/src/core/api/CamelDisplayUtil.ts +143 -0
  11. package/src/core/api/CamelUtil.ts +360 -0
  12. package/src/core/api/ComponentApi.ts +368 -0
  13. package/src/core/api/KameletApi.ts +147 -0
  14. package/src/core/api/MainConfigurationApi.ts +47 -0
  15. package/src/core/api/ProjectModelApi.ts +75 -0
  16. package/src/core/api/SpiBeanApi.ts +104 -0
  17. package/src/core/api/TemplateApi.ts +58 -0
  18. package/src/core/api/TopologyUtils.ts +392 -0
  19. package/src/core/api/VariableUtil.ts +104 -0
  20. package/src/core/model/CamelDefinition.ts +3783 -0
  21. package/src/core/model/CamelMetadata.ts +2714 -0
  22. package/src/core/model/ComponentModels.ts +106 -0
  23. package/src/core/model/IntegrationDefinition.ts +188 -0
  24. package/src/core/model/KameletModels.ts +223 -0
  25. package/src/core/model/MainConfigurationModel.ts +37 -0
  26. package/src/core/model/ProjectModel.ts +43 -0
  27. package/src/core/model/SpiBeanModels.ts +53 -0
  28. package/src/core/model/TopologyDefinition.ts +117 -0
  29. package/test/addStep.spec.ts +124 -0
  30. package/test/addStep1.yaml +27 -0
  31. package/test/allowableValues.camel.yaml +19 -0
  32. package/test/allowableValues.spec.ts +30 -0
  33. package/test/avro-serialize-action.kamelet.yaml +70 -0
  34. package/test/beans.spec.ts +92 -0
  35. package/test/beans1.yaml +36 -0
  36. package/test/beans2.yaml +42 -0
  37. package/test/beans3.yaml +7 -0
  38. package/test/checkRequired.spec.ts +53 -0
  39. package/test/circuitBreaker.spec.ts +57 -0
  40. package/test/circuitBreaker.yaml +19 -0
  41. package/test/cloneDefinition.spec.ts +106 -0
  42. package/test/createKamelet.spec.ts +38 -0
  43. package/test/cxf.json +615 -0
  44. package/test/cxf.spec.ts +44 -0
  45. package/test/cxf.yaml +15 -0
  46. package/test/deleteStep.spec.ts +74 -0
  47. package/test/demo.spec.ts +49 -0
  48. package/test/demo.yaml +32 -0
  49. package/test/doCatchOnWhen.camel.yaml +20 -0
  50. package/test/doCatchOnWhen.spec.ts +36 -0
  51. package/test/errorHandler.spec.ts +38 -0
  52. package/test/errorHandler1.yaml +27 -0
  53. package/test/expression.spec.ts +55 -0
  54. package/test/findStep.spec.ts +112 -0
  55. package/test/findStep.yaml +65 -0
  56. package/test/getElementProperties.spec.ts +32 -0
  57. package/test/getElementPropertiesByName.spec.ts +31 -0
  58. package/test/getExpressionLanguage.spec.ts +40 -0
  59. package/test/hasElementWithId.camel.yaml +98 -0
  60. package/test/hasElementWithId.spec.ts +57 -0
  61. package/test/hasElementWithId1.camel.yaml +16 -0
  62. package/test/hasElementWithIdError.camel.yaml +98 -0
  63. package/test/integration.spec.ts +60 -0
  64. package/test/integration1.yaml +24 -0
  65. package/test/integration2.yaml +23 -0
  66. package/test/integrationToYaml.spec.ts +51 -0
  67. package/test/intercept.spec.ts +62 -0
  68. package/test/intercept.yaml +19 -0
  69. package/test/is-not-integration.yaml +5114 -0
  70. package/test/isIntegration.spec.ts +45 -0
  71. package/test/kamelet.spec.ts +61 -0
  72. package/test/metadata/components.json +697 -0
  73. package/test/metadata/kamelets.yaml +23414 -0
  74. package/test/metadata/spiBeans.json +3094 -0
  75. package/test/multiObjectProperties.spec.ts +46 -0
  76. package/test/multiObjectProperties1.yaml +19 -0
  77. package/test/multiple.spec.ts +38 -0
  78. package/test/multiple.yaml +29 -0
  79. package/test/openapi.spec.ts +48 -0
  80. package/test/openapi.yaml +7 -0
  81. package/test/placeholder.spec.ts +32 -0
  82. package/test/placeholder.yaml +133 -0
  83. package/test/plain-try-catch.yaml +31 -0
  84. package/test/plain.spec.ts +72 -0
  85. package/test/plain1.yaml +22 -0
  86. package/test/plain2.yaml +13 -0
  87. package/test/plain3.yaml +5 -0
  88. package/test/plain4.yaml +5 -0
  89. package/test/postgresql-source.kamelet.yaml +113 -0
  90. package/test/restConfigDsl.yaml +15 -0
  91. package/test/restDsl.spec.ts +83 -0
  92. package/test/restDsl.yaml +29 -0
  93. package/test/routes.spec.ts +37 -0
  94. package/test/routes1.yaml +31 -0
  95. package/test/supported-components.json +1221 -0
  96. package/test/supportedComponents.spec.ts +34 -0
  97. package/test/template1.AggregationStrategy.java +21 -0
  98. package/test/template1.Processor.java +13 -0
  99. package/test/template2.AggregationStrategy.java +21 -0
  100. package/test/template2.Processor.java +13 -0
  101. package/test/templateApi.spec.ts +45 -0
  102. package/test/timer-source.kamelet.yaml +75 -0
  103. package/test/tod.spec.ts +31 -0
  104. package/test/tod.yaml +9 -0
  105. package/test/topology.spec.ts +51 -0
  106. package/test/topology1.camel.yaml +56 -0
  107. package/test/topology2.camel.yaml +44 -0
  108. package/test/topology3.camel.yaml +27 -0
  109. package/test/tsconfig.testing.json +14 -0
  110. package/test/updateStep.spec.ts +72 -0
  111. package/test/variable1.camel.yaml +42 -0
  112. package/test/variable2.camel.yaml +42 -0
  113. package/test/variables.spec.ts +34 -0
  114. package/tsconfig.json +34 -0
@@ -0,0 +1,412 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import * as yaml from 'js-yaml';
18
+ import { Beans, CamelElement, Integration } from '../model/IntegrationDefinition';
19
+ import { BeanFactoryDefinition, RouteConfigurationDefinition, RouteDefinition } from '../model/CamelDefinition';
20
+ import { CamelUtil } from './CamelUtil';
21
+ import { CamelDefinitionYamlStep } from './CamelDefinitionYamlStep';
22
+
23
+ export class CamelDefinitionYaml {
24
+ private constructor() {
25
+ }
26
+
27
+ static integrationToYaml = (integration: Integration): string => {
28
+ const clone: any = CamelUtil.cloneIntegration(integration);
29
+ const flows = integration.spec.flows;
30
+ clone.spec.flows = flows
31
+ ?.map((f: any) => CamelDefinitionYaml.cleanupElement(f))
32
+ .filter(x => Object.keys(x).length !== 0);
33
+ if (integration.type === 'crd') {
34
+ delete clone.type;
35
+ const i = JSON.parse(JSON.stringify(clone, (key, value) => CamelDefinitionYaml.replacer(key, value), 3)); // fix undefined in string attributes
36
+ return CamelDefinitionYaml.yamlDump(i);
37
+ } else if (integration.type === 'kamelet') {
38
+ delete clone.type;
39
+ // turn array of flows to object properties in template for Kamelet
40
+ const template: any = {route: {}}
41
+ const route: RouteDefinition = clone.spec.flows.filter((f: any) => f.dslName === 'RouteDefinition')?.[0];
42
+ if (route) {
43
+ template.route = Object.assign(template.route, route);
44
+ } else if (clone.spec.template?.route) {
45
+ template.route = clone.spec.template.route;
46
+ } else if (clone.spec.template?.from) {
47
+ template.route = {from: clone.spec.template?.from};
48
+ }
49
+ const from: RouteDefinition = clone.spec.flows.filter((f: any) => f.dslName === 'FromDefinition')?.[0];
50
+ if (from) {
51
+ template.from = {from: from};
52
+ }
53
+ const beans = clone.spec.flows.filter((f: any) => f.dslName === 'Beans')?.at(0)?.beans;
54
+ if (beans) {
55
+ template.beans = beans;
56
+ } else if (clone.spec.template?.beans){
57
+ template.beans = clone.spec.template.beans;
58
+ }
59
+ clone.spec.template = template;
60
+ delete clone.spec.flows;
61
+ const i = JSON.parse(JSON.stringify(clone, (key, value) => CamelDefinitionYaml.replacer(key, value, true), 3)); // fix undefined in string attributes
62
+ return CamelDefinitionYaml.yamlDump(i);
63
+ } else {
64
+ const f = JSON.parse(
65
+ JSON.stringify(clone.spec.flows, (key, value) => CamelDefinitionYaml.replacer(key, value), 3),
66
+ );
67
+ return CamelDefinitionYaml.yamlDump(f);
68
+ }
69
+ };
70
+
71
+ static isEmpty = (value?: string): boolean => {
72
+ return value === undefined || (value.trim && value.trim().length === 0);
73
+ };
74
+
75
+ static isEmptyObject(obj: any): boolean {
76
+ // Check if it's an object and not null
77
+ if (obj && typeof obj === 'object') {
78
+ // Get all enumerable property names
79
+ const keys = Object.keys(obj);
80
+ // Get all non-enumerable property names
81
+ const nonEnumProps = Object.getOwnPropertyNames(obj);
82
+ // Check if there are no properties
83
+ return keys.length === 0 && nonEnumProps.length === 0;
84
+ }
85
+ return false;
86
+ }
87
+
88
+
89
+ static cleanupElement = (element: CamelElement, inArray?: boolean, inSteps?: boolean): CamelElement => {
90
+ const result: any = {};
91
+ const object: any = { ...element };
92
+
93
+ if (inArray) {
94
+ object.inArray = inArray;
95
+ object.inSteps = !!inSteps;
96
+ }
97
+
98
+ if (object.dslName.endsWith('Expression')) {
99
+ delete object.language;
100
+ delete object.expressionName;
101
+ } else if (object.dslName.endsWith('DataFormat')) {
102
+ delete object.dataFormatName;
103
+ } else if (object.dslName === 'BeanFactoryDefinition') {
104
+ if (object.properties && Object.keys(object.properties).length === 0) {
105
+ delete object.properties;
106
+ }
107
+ if (object.constructors && CamelDefinitionYaml.isEmptyObject(object.constructors)) {
108
+ delete object.constructors;
109
+ }
110
+ } else if (object.dslName === 'CatchDefinition' && object?.onWhen?.stepName !== undefined) {
111
+ object.onWhen.stepName = 'onWhen'; // https://github.com/apache/camel-karavan/issues/1420
112
+ }
113
+
114
+ delete object.uuid;
115
+ delete object.showChildren;
116
+
117
+ for (const [key, value] of Object.entries(object) as [string, any][]) {
118
+ if (value instanceof CamelElement || (typeof value === 'object' && value?.dslName)) {
119
+ result[key] = CamelDefinitionYaml.cleanupElement(value);
120
+ } else if (Array.isArray(value)) {
121
+ if (value.length > 0) {
122
+ result[key] = CamelDefinitionYaml.cleanupElements(value, key === 'steps');
123
+ }
124
+ } else if (key === 'parameters' && typeof value === 'object') {
125
+ const parameters = Object.entries(value || {})
126
+ .filter(([_, v]: [string, any]) => !CamelDefinitionYaml.isEmpty(v))
127
+ .reduce((x: any, [k, v]) => ({ ...x, [k]: v }), {});
128
+ if (Object.keys(parameters).length > 0) {
129
+ result[key] = parameters;
130
+ }
131
+ } else {
132
+ if (!CamelDefinitionYaml.isEmpty(value)) {
133
+ result[key] = value;
134
+ }
135
+ }
136
+ }
137
+ return result as CamelElement;
138
+ };
139
+
140
+ static cleanupElements = (elements: CamelElement[], inSteps?: boolean): CamelElement[] => {
141
+ const result: any[] = [];
142
+ for (const element of elements) {
143
+ if (typeof element === 'object') {
144
+ result.push(CamelDefinitionYaml.cleanupElement(element, true, inSteps));
145
+ } else {
146
+ result.push(element);
147
+ }
148
+ }
149
+ return result;
150
+ };
151
+
152
+ static yamlDump = (integration: any): string => {
153
+ return yaml.dump(integration, {
154
+ noRefs: false,
155
+ noArrayIndent: false,
156
+ // forceQuotes: true,
157
+ quotingType: '"',
158
+ sortKeys: function(a: any, b: any) {
159
+ if (a === 'steps') return 1;
160
+ else if (b === 'steps') return -1;
161
+ else return 0;
162
+ },
163
+ });
164
+ };
165
+
166
+ static replacer = (key: string, value: any, isKamelet: boolean = false): any => {
167
+ if (
168
+ typeof value === 'object' &&
169
+ (value.hasOwnProperty('stepName') || value.hasOwnProperty('inArray') || value.hasOwnProperty('inSteps'))
170
+ ) {
171
+ const stepNameField = value.hasOwnProperty('stepName') ? 'stepName' : 'step-name';
172
+ const stepName = value[stepNameField];
173
+ const dslName = value.dslName;
174
+ let newValue: any = JSON.parse(JSON.stringify(value));
175
+ delete newValue.dslName;
176
+ delete newValue[stepNameField];
177
+
178
+ if (
179
+ value.inArray &&
180
+ !value.inSteps &&
181
+ ['intercept', 'interceptFrom', 'interceptSendToEndpoint', 'onCompletion', 'onException'].includes(
182
+ stepName,
183
+ )
184
+ ) {
185
+ delete newValue.inArray;
186
+ delete newValue.inSteps;
187
+ const xValue: any = {};
188
+ xValue[stepName] = newValue;
189
+ return xValue;
190
+ } else if (
191
+ (value.inArray && !value.inSteps) ||
192
+ dslName === 'ExpressionSubElementDefinition' ||
193
+ dslName === 'ExpressionDefinition' ||
194
+ dslName?.endsWith('Expression') ||
195
+ stepName === 'otherwise' ||
196
+ stepName === 'doFinally' ||
197
+ stepName === 'resilience4jConfiguration' ||
198
+ stepName === 'faultToleranceConfiguration' ||
199
+ stepName === 'errorHandler' ||
200
+ stepName === 'onWhen' || // https://github.com/apache/camel-karavan/issues/1420
201
+ stepName === 'deadLetterChannel' ||
202
+ stepName === 'defaultErrorHandler' ||
203
+ stepName === 'jtaTransactionErrorHandler' ||
204
+ stepName === 'noErrorHandler' ||
205
+ stepName === 'springTransactionErrorHandler' ||
206
+ stepName === 'redeliveryPolicy' ||
207
+ stepName === 'securityDefinitions' ||
208
+ stepName === 'apiKey' ||
209
+ stepName === 'basicAuth' ||
210
+ stepName === 'bearer' ||
211
+ stepName === 'mutualTls' ||
212
+ stepName === 'oauth2' ||
213
+ stepName === 'openIdConnect' ||
214
+ stepName === 'openApi' ||
215
+ key === 'from'
216
+ ) {
217
+ delete newValue.inArray;
218
+ delete newValue.inSteps;
219
+ return newValue;
220
+ } else if (isKamelet && dslName === 'RouteDefinition') {
221
+ delete value?.dslName;
222
+ delete value?.stepName;
223
+ return value;
224
+ } else {
225
+ delete newValue.inArray;
226
+ delete newValue.inSteps;
227
+ const xValue: any = {};
228
+ xValue[stepName] = newValue;
229
+ return xValue;
230
+ }
231
+ } else {
232
+ delete value?.dslName;
233
+ return value;
234
+ }
235
+ };
236
+
237
+ static yamlToIntegration = (filename: string, text: string): Integration => {
238
+ const integration: Integration = Integration.createNew(filename);
239
+ const fromYaml: any = yaml.load(text);
240
+ const camelized: any = CamelUtil.camelizeObject(fromYaml);
241
+ if (camelized?.apiVersion && camelized.apiVersion.startsWith('camel.apache.org') && camelized.kind) {
242
+ if (camelized?.metadata) {
243
+ integration.metadata = camelized?.metadata;
244
+ }
245
+ if (camelized?.spec) {
246
+ integration.spec.definition = camelized?.spec.definition;
247
+ integration.spec.dependencies = camelized?.spec.dependencies;
248
+ integration.spec.types = camelized?.spec.types;
249
+ }
250
+ const int: Integration = new Integration({ ...camelized });
251
+ if (camelized.kind === 'Integration') {
252
+ integration.type = 'crd';
253
+ integration.spec.flows?.push(...CamelDefinitionYaml.flowsToCamelElements(int.spec.flows || []));
254
+ } else if (camelized.kind === 'Kamelet') {
255
+ integration.type = 'kamelet';
256
+ integration.kind = 'Kamelet';
257
+ const flows: any[] = [];
258
+ // turn kamelet template object properties to array of flows
259
+ const beans = int.spec.template?.beans;
260
+ if (beans) {
261
+ flows.push(new Beans({beans: beans}))
262
+ }
263
+ const from = int.spec.template?.from;
264
+ if (from) {
265
+ flows.push(new RouteDefinition({from: from}))
266
+ } else {
267
+ const route = int.spec.template?.route;
268
+ flows.push(route);
269
+ }
270
+ integration.spec.flows?.push(...CamelDefinitionYaml.flowsToCamelElements(flows || []));
271
+ }
272
+ } else if (Array.isArray(camelized)) {
273
+ integration.type = 'plain';
274
+ const flows: any[] = camelized;
275
+ integration.spec.flows?.push(...CamelDefinitionYaml.flowsToCamelElements(flows));
276
+ }
277
+ return integration;
278
+ };
279
+
280
+ static yamlIsIntegration = (text: string): 'crd' | 'plain' | 'kamelet' | 'none' => {
281
+ try {
282
+ const fromYaml: any = yaml.load(text);
283
+ const camelized: any = CamelUtil.camelizeObject(fromYaml);
284
+ if (camelized?.apiVersion && camelized.apiVersion.startsWith('camel.apache.org') && camelized.kind) {
285
+ if (camelized.kind === 'Integration') {
286
+ return 'crd';
287
+ } else if (camelized.kind === 'Kamelet') {
288
+ return 'kamelet';
289
+ }
290
+ } else if (Array.isArray(camelized)) {
291
+ return 'plain';
292
+ } else {
293
+ return 'none';
294
+ }
295
+ } catch (e) {
296
+ }
297
+ return 'none';
298
+ };
299
+ static flowsToCamelElements = (flows: any[]): any[] => {
300
+ const result: any[] = [];
301
+ flows.filter((e: any) => e.hasOwnProperty('restConfiguration'))
302
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRestConfigurationDefinition(f.restConfiguration)));
303
+ flows.filter((e: any) => e.hasOwnProperty('rest'))
304
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRestDefinition(f.rest)));
305
+ flows.filter((e: any) => e.hasOwnProperty('route'))
306
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteDefinition(f.route)));
307
+ flows.filter((e: any) => e.hasOwnProperty('from'))
308
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteDefinition(new RouteDefinition({from: f.from}))));
309
+ flows.filter((e: any) => e.hasOwnProperty('beans'))
310
+ .forEach((b: any) => result.push(CamelDefinitionYaml.readBeanDefinition(b)));
311
+ flows.filter((e: any) => e.hasOwnProperty('routeConfiguration'))
312
+ .forEach((e: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(e.routeConfiguration)));
313
+ flows.filter((e: any) => e.hasOwnProperty('errorHandler'))
314
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({errorHandler: f.errorHandler}))));
315
+ flows.filter((e: any) => e.hasOwnProperty('onException'))
316
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({onException: f.onException}))));
317
+ flows.filter((e: any) => e.hasOwnProperty('intercept'))
318
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({intercept: f.intercept}))));
319
+ flows.filter((e: any) => e.hasOwnProperty('interceptFrom'))
320
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({interceptFrom: f.interceptFrom}))));
321
+ flows.filter((e: any) => e.hasOwnProperty('interceptSendToEndpoint'))
322
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({interceptSendToEndpoint: f.interceptSendToEndpoint}))));
323
+ flows.filter((e: any) => e.hasOwnProperty('onCompletion'))
324
+ .forEach((f: any) => result.push(CamelDefinitionYamlStep.readRouteConfigurationDefinition(new RouteConfigurationDefinition({onCompletion: f.onCompletion}))));
325
+
326
+ return result;
327
+ };
328
+
329
+ static readBeanDefinition = (beans: any): Beans => {
330
+ const result: Beans = new Beans();
331
+ for (const bean of beans.beans) {
332
+ const props: any = {};
333
+ if (bean && bean.properties) {
334
+ // convert map style to properties if requires
335
+ for (const [key, value] of Object.entries(bean.properties)) {
336
+ CamelDefinitionYaml.flatMapProperty(key, value, new Map<string, any>()).forEach(
337
+ (v, k) => (props[k] = v),
338
+ );
339
+ }
340
+ }
341
+ if (bean && bean.property && Array.isArray(bean.property)) {
342
+ // convert map style to properties if requires
343
+ Array.from(bean.property).forEach((val: any) => {
344
+ props[val.key] = val.value;
345
+ })
346
+ delete bean.property;
347
+ }
348
+ bean.properties = props;
349
+ result.beans.push(new BeanFactoryDefinition(bean));
350
+ }
351
+ return result;
352
+ };
353
+
354
+ // convert map style to properties if requires
355
+ static flatMapProperty = (key: string, value: any, properties: Map<string, any>): Map<string, any> => {
356
+ if (value === undefined) {
357
+ return properties;
358
+ }
359
+
360
+ if (typeof value === 'object') {
361
+ for (const k in value) {
362
+ const key2 = key + '.' + k;
363
+ const value2: any = value[k];
364
+ CamelDefinitionYaml.flatMapProperty(key2, value2, new Map<string, any>()).forEach((value1, key1) =>
365
+ properties.set(key1, value1),
366
+ );
367
+ }
368
+ } else {
369
+ properties.set(key, value);
370
+ }
371
+ return properties;
372
+ };
373
+
374
+ // add generated Integration YAML into existing Integration YAML
375
+ static addYamlToIntegrationYaml = (
376
+ filename: string,
377
+ camelYaml: string | undefined,
378
+ restYaml: string,
379
+ addREST: boolean,
380
+ addRoutes: boolean,
381
+ ): string => {
382
+ const existing =
383
+ camelYaml !== undefined
384
+ ? CamelDefinitionYaml.yamlToIntegration(filename, camelYaml)
385
+ : Integration.createNew(filename);
386
+ const generated = CamelDefinitionYaml.yamlToIntegration(filename, restYaml);
387
+
388
+ const flows: CamelElement[] =
389
+ existing.spec.flows?.filter(f => !['RouteDefinition', 'RestDefinition'].includes(f.dslName)) || [];
390
+
391
+ const restE: CamelElement[] = existing.spec.flows?.filter(f => f.dslName === 'RestDefinition') || [];
392
+ const restG: CamelElement[] = generated.spec.flows?.filter(f => f.dslName === 'RestDefinition') || [];
393
+
394
+ if (addREST) {
395
+ flows.push(...restG);
396
+ } else {
397
+ flows.push(...restE);
398
+ }
399
+
400
+ const routeE: CamelElement[] = existing.spec.flows?.filter(f => f.dslName === 'RouteDefinition') || [];
401
+ const routeG: CamelElement[] = generated.spec.flows?.filter(f => f.dslName === 'RouteDefinition') || [];
402
+
403
+ if (addRoutes) {
404
+ flows.push(...routeG);
405
+ } else {
406
+ flows.push(...routeE);
407
+ }
408
+
409
+ existing.spec.flows = flows;
410
+ return CamelDefinitionYaml.integrationToYaml(existing);
411
+ };
412
+ }