This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit 3c58d0d2017d80dc6dfa385d5db42ff4a87f31f7 Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Mon Feb 13 17:52:07 2023 -0500 Augment component data in core #658 --- karavan-core/src/core/api/ComponentApi.ts | 32 +++++++- karavan-core/src/core/api/KameletApi.ts | 2 - karavan-core/src/core/model/ComponentModels.ts | 101 ++++++++++++++----------- 3 files changed, 84 insertions(+), 51 deletions(-) diff --git a/karavan-core/src/core/api/ComponentApi.ts b/karavan-core/src/core/api/ComponentApi.ts index ccffd67d..daa8d3c0 100644 --- a/karavan-core/src/core/api/ComponentApi.ts +++ b/karavan-core/src/core/api/ComponentApi.ts @@ -14,12 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {Component, ComponentProperty} from "../model/ComponentModels"; +import {Component, ComponentProperty, SupportedComponent} from "../model/ComponentModels"; -export const Components: Component[] = []; +const Components: Component[] = []; +const SupportedComponents: SupportedComponent[] = []; export const ComponentApi = { + saveSupportedComponents: (jsons: string[]) => { + SupportedComponents.length = 0; + const sc: SupportedComponent[] = jsons.map(json => ComponentApi.jsonToSupportedComponent(json)); + SupportedComponents.push(...sc); + }, + + jsonToSupportedComponent: (json: string) => { + const fromJson: SupportedComponent = JSON.parse(json) as SupportedComponent; + const k: SupportedComponent = new SupportedComponent(fromJson); + return k; + }, + jsonToComponent: (json: string) => { const fromJson: Component = JSON.parse(json) as Component; const k: Component = new Component(fromJson); @@ -40,7 +53,18 @@ export const ComponentApi = { }, getComponents: (): Component[] => { - return Components.sort((a, b) => { + return Components + .map(comp => { + const sc = SupportedComponents.find(sc => sc.name === comp.component.name); + if (sc !== undefined) { + comp.component.supportLevel = sc.level; + comp.component.supportType = "supported"; + return comp; + } else { + return comp; + } + }) + .sort((a, b) => { if (a.component.name < b.component.name) { return -1; } @@ -49,7 +73,7 @@ export const ComponentApi = { }, findByName: (name: string): Component | undefined => { - return Components.find((c: Component) => c.component.name === name); + return ComponentApi.getComponents().find((c: Component) => c.component.name === name); }, getComponentNameFromUri: (uri: string): string | undefined => { diff --git a/karavan-core/src/core/api/KameletApi.ts b/karavan-core/src/core/api/KameletApi.ts index ea1bd479..6d5dd33c 100644 --- a/karavan-core/src/core/api/KameletApi.ts +++ b/karavan-core/src/core/api/KameletApi.ts @@ -16,8 +16,6 @@ */ import {KameletModel, Property} from "../model/KameletModels"; import * as yaml from 'js-yaml'; -import {Component} from "../model/ComponentModels"; -import {Components} from "./ComponentApi"; export const Kamelets: KameletModel[] = []; export const CustomNames: string[] = []; diff --git a/karavan-core/src/core/model/ComponentModels.ts b/karavan-core/src/core/model/ComponentModels.ts index 599e7b5f..db8d6e31 100644 --- a/karavan-core/src/core/model/ComponentModels.ts +++ b/karavan-core/src/core/model/ComponentModels.ts @@ -15,58 +15,69 @@ * limitations under the License. */ export class Header { - kind: string = ''; - name: string = ''; - title: string = ''; - description: string = ''; - deprecated: boolean = false; - firstVersion: string = ''; - label: string = ''; - javaType: string = ''; - supportLevel: string = ''; - groupId: string = ''; - artifactId: string = ''; - version: string = ''; - scheme: string = ''; - extendsScheme: string = ''; - syntax: string = ''; - async: boolean = false; - api: boolean = false; - consumerOnly: boolean = false; - producerOnly: boolean = false; - lenientProperties: boolean = false; - componentProperties: any; + kind: string = ''; + name: string = ''; + title: string = ''; + description: string = ''; + deprecated: boolean = false; + firstVersion: string = ''; + label: string = ''; + javaType: string = ''; + supportLevel: string = ''; + supportType: string = 'community'; + groupId: string = ''; + artifactId: string = ''; + version: string = ''; + scheme: string = ''; + extendsScheme: string = ''; + syntax: string = ''; + async: boolean = false; + api: boolean = false; + consumerOnly: boolean = false; + producerOnly: boolean = false; + lenientProperties: boolean = false; + componentProperties: any; - public constructor(init?: Partial<Header>) { - Object.assign(this, init); - } + public constructor(init?: Partial<Header>) { + Object.assign(this, init); + } } export class Component { - component: Header = new Header(); - properties: any; + component: Header = new Header(); + properties: any; - public constructor(init?: Partial<Component>) { - Object.assign(this, init); - } + public constructor(init?: Partial<Component>) { + Object.assign(this, init); + } } export class ComponentProperty { - name: string = ''; - deprecated: boolean = false; - description: string = ''; - displayName: string = ''; - group: string = ''; - kind: string = ''; - label: string = ''; - type: string = ''; - secret: boolean = false; - enum: string[] = []; - required: boolean = false; - defaultValue: string | number | boolean | any; - value: string | any; + name: string = ''; + deprecated: boolean = false; + description: string = ''; + displayName: string = ''; + group: string = ''; + kind: string = ''; + label: string = ''; + type: string = ''; + secret: boolean = false; + enum: string[] = []; + required: boolean = false; + defaultValue: string | number | boolean | any; + value: string | any; - public constructor(init?: Partial<ComponentProperty>) { - Object.assign(this, init); - } + public constructor(init?: Partial<ComponentProperty>) { + Object.assign(this, init); + } } + +export class SupportedComponent { + name: string = ''; + level: string = ''; + native: boolean = false; + + public constructor(init?: Partial<SupportedComponent>) { + Object.assign(this, init); + } +} \ No newline at end of file