From 073018bcc2c1b3407e523fec668522caf87c3918 Mon Sep 17 00:00:00 2001 From: Tadayoshi Sato Date: Fri, 20 Oct 2023 17:21:04 +0900 Subject: [PATCH] chore(camel): update @hawtio/camel-model --- packages/hawtio/package.json | 4 ++-- .../src/plugins/camel/camel-service.test.ts | 20 +++++++++---------- .../hawtio/src/plugins/camel/camel-service.ts | 11 +++++----- .../camel/endpoints/endpoints-service.ts | 2 +- .../src/plugins/camel/schema-service.test.ts | 6 +++--- .../src/plugins/camel/schema-service.ts | 15 ++++++-------- yarn.lock | 20 +++++++++---------- 7 files changed, 37 insertions(+), 41 deletions(-) diff --git a/packages/hawtio/package.json b/packages/hawtio/package.json index db0a2669..3ba8542c 100644 --- a/packages/hawtio/package.json +++ b/packages/hawtio/package.json @@ -33,8 +33,8 @@ "prepack": "yarn build && yarn replace-version" }, "dependencies": { - "@hawtio/camel-model-v3": "npm:@hawtio/camel-model@^3.21.0", - "@hawtio/camel-model-v4": "npm:@hawtio/camel-model@^4.0.0", + "@hawtio/camel-model-v3": "npm:@hawtio/camel-model@^3.21.1", + "@hawtio/camel-model-v4": "npm:@hawtio/camel-model@^4.0.1", "@module-federation/utilities": "^3.0.0", "@patternfly/react-charts": "^7.1.1", "@patternfly/react-code-editor": "^5.1.1", diff --git a/packages/hawtio/src/plugins/camel/camel-service.test.ts b/packages/hawtio/src/plugins/camel/camel-service.test.ts index 69ede49f..1e6bbec2 100644 --- a/packages/hawtio/src/plugins/camel/camel-service.test.ts +++ b/packages/hawtio/src/plugins/camel/camel-service.test.ts @@ -45,11 +45,11 @@ describe('camel-service', () => { const camel3Model = camelService.getCamelModel(camel3Node) expect(camel3Model).toBeDefined() expect(camel3Model.apacheCamelModelVersion).toBe(camel3.apacheCamelModelVersion) - expect(camel3Model.components.components).not.toBeUndefined() - expect(camel3Model.dataformats.dataformats).not.toBeUndefined() - expect(camel3Model.definitions.definitions).not.toBeUndefined() - expect(camel3Model.languages.languages).not.toBeUndefined() - expect(camel3Model.rests.rests).not.toBeUndefined() + expect(camel3Model.components).not.toBeUndefined() + expect(camel3Model.dataformats).not.toBeUndefined() + expect(camel3Model.definitions).not.toBeUndefined() + expect(camel3Model.languages).not.toBeUndefined() + expect(camel3Model.rests).not.toBeUndefined() const camel4Node = new MBeanNode(null, 'test-context-camel4', true) camel4Node.addMetadata('domain', jmxDomain) @@ -58,11 +58,11 @@ describe('camel-service', () => { const camel4Model = camelService.getCamelModel(camel4Node) expect(camel4Model).toBeDefined() expect(camel4Model.apacheCamelModelVersion).toBe(camel4.apacheCamelModelVersion) - expect(camel4Model.components.components).not.toBeUndefined() - expect(camel4Model.dataformats.dataformats).not.toBeUndefined() - expect(camel4Model.definitions.definitions).not.toBeUndefined() - expect(camel4Model.languages.languages).not.toBeUndefined() - expect(camel4Model.rests.rests).not.toBeUndefined() + expect(camel4Model.components).not.toBeUndefined() + expect(camel4Model.dataformats).not.toBeUndefined() + expect(camel4Model.definitions).not.toBeUndefined() + expect(camel4Model.languages).not.toBeUndefined() + expect(camel4Model.rests).not.toBeUndefined() }) test('compareVersions', () => { diff --git a/packages/hawtio/src/plugins/camel/camel-service.ts b/packages/hawtio/src/plugins/camel/camel-service.ts index d609dc91..dd634936 100644 --- a/packages/hawtio/src/plugins/camel/camel-service.ts +++ b/packages/hawtio/src/plugins/camel/camel-service.ts @@ -24,14 +24,13 @@ import { import { ROUTE_OPERATIONS } from './routes-service' // TODO: Should be provided by @hawtio/camel-model package -// TODO: Why are the properties redundant? (e.g. components.components, dataformats.dataformats) export type CamelModel = { apacheCamelModelVersion: string - components: { components: { [name: string]: CamelModelSchema } } - dataformats: { dataformats: { [name: string]: CamelModelSchema } } - definitions: { definitions: { [name: string]: CamelModelSchema } } - languages: { languages: { [name: string]: CamelModelSchema } } - rests: { rests: { [name: string]: CamelModelSchema } } + components: { [name: string]: CamelModelSchema } + dataformats: { [name: string]: CamelModelSchema } + definitions: { [name: string]: CamelModelSchema } + languages: { [name: string]: CamelModelSchema } + rests: { [name: string]: CamelModelSchema } } export type CamelModelSchema = { diff --git a/packages/hawtio/src/plugins/camel/endpoints/endpoints-service.ts b/packages/hawtio/src/plugins/camel/endpoints/endpoints-service.ts index 001c4caf..1c0a0ee7 100644 --- a/packages/hawtio/src/plugins/camel/endpoints/endpoints-service.ts +++ b/packages/hawtio/src/plugins/camel/endpoints/endpoints-service.ts @@ -161,7 +161,7 @@ export function loadEndpointSchema(node: MBeanNode, componentName: string): came if (isBlank(componentName)) return null const camelModel = camelService.getCamelModel(ctxNode) - return camelModel.components.components[componentName] ?? null + return camelModel.components[componentName] ?? null } export async function doSendMessage( diff --git a/packages/hawtio/src/plugins/camel/schema-service.test.ts b/packages/hawtio/src/plugins/camel/schema-service.test.ts index c7a02626..78b4cc86 100644 --- a/packages/hawtio/src/plugins/camel/schema-service.test.ts +++ b/packages/hawtio/src/plugins/camel/schema-service.test.ts @@ -11,21 +11,21 @@ describe('schema-service', () => { const schemaText = fs.readFileSync(schemaPath, { encoding: 'utf8', flag: 'r' }) const schema = JSON.parse(schemaText) - let defn: Record | null = schemaService.lookupDefinition('base', schema) + let defn: Record | null = schemaService.lookupDefinition('base', schema.definitions) expect(defn).not.toBeNull() let def: Record = defn as Record expect(def.type).toBe('object') expect(isObject(def['properties'])).toBeTruthy() expect(Object.entries(def['properties'] as object).length).toBe(2) - defn = schemaService.lookupDefinition('typed', schema) + defn = schemaService.lookupDefinition('typed', schema.definitions) expect(defn).not.toBeNull() def = defn as Record expect(def.type).toBe('base') expect(isObject(def['properties'])).toBeTruthy() expect(Object.entries(def['properties'] as object).length).toBe(3) - defn = schemaService.lookupDefinition('extended', schema) + defn = schemaService.lookupDefinition('extended', schema.definitions) expect(defn).not.toBeNull() def = defn as Record expect(def.type).toBe('object') diff --git a/packages/hawtio/src/plugins/camel/schema-service.ts b/packages/hawtio/src/plugins/camel/schema-service.ts index 7631261c..67d2fc29 100644 --- a/packages/hawtio/src/plugins/camel/schema-service.ts +++ b/packages/hawtio/src/plugins/camel/schema-service.ts @@ -7,17 +7,14 @@ class SchemaService { * Looks up the given type name in the schemas definitions * @method lookupDefinition * @param {String} name - * @param {any} schema + * @param {Record} definitions */ - lookupDefinition(name: string, schema: Record): Record | null { - if (!schema) return null + lookupDefinition(name: string, definitions: Record): Record | null { + if (!definitions) return null - if (!isObject(schema.definitions)) return null + if (!isObject(definitions[name])) return null - const defs: Record = schema.definitions as Record - if (!isObject(defs[name])) return null - - const answer = defs[name] as Record + const answer = definitions[name] as Record if (isObject(answer['fullSchema'])) { return answer['fullSchema'] as Record } @@ -35,7 +32,7 @@ class SchemaService { const fullSchema = cloneObject(answer) fullSchema.properties = fullSchema.properties || {} for (const extendType of extendsTypes) { - const extendDef = this.lookupDefinition(fullSchema[extendType] as string, schema) + const extendDef = this.lookupDefinition(fullSchema[extendType] as string, definitions) const properties = extendDef?.properties if (isObject(properties)) { for (const [key, property] of Object.entries(properties)) { diff --git a/yarn.lock b/yarn.lock index 1c4008eb..874d737c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2467,17 +2467,17 @@ __metadata: languageName: node linkType: hard -"@hawtio/camel-model-v3@npm:@hawtio/camel-model@^3.21.0": - version: 3.21.0 - resolution: "@hawtio/camel-model@npm:3.21.0" - checksum: 6e4f02eda269a0e53966fdfc126b6467ed965edb34a56a749c81fcacdb68c28644d1970e45ee0b4df1c912f664c5be99afe4ca7e3d9c7f3758b0c571d55400a2 +"@hawtio/camel-model-v3@npm:@hawtio/camel-model@^3.21.1": + version: 3.21.1 + resolution: "@hawtio/camel-model@npm:3.21.1" + checksum: ae920bd9c3b75286c31f0a0b5168e09b982c61cfbeeca000201a175490afa6060b5b7900fd01be156db92020aab505cd6dc6a812fc0e181db6ae5cb178b729e1 languageName: node linkType: hard -"@hawtio/camel-model-v4@npm:@hawtio/camel-model@^4.0.0": - version: 4.0.0 - resolution: "@hawtio/camel-model@npm:4.0.0" - checksum: d02d19170ef9ff2ccdbceae6a2f9848dc88be80878e1b13de426ef0cf876b80c3c40570d9193585e74251d9bb45da9ad5bdaf0be7efa051189657e3a53d6491e +"@hawtio/camel-model-v4@npm:@hawtio/camel-model@^4.0.1": + version: 4.0.1 + resolution: "@hawtio/camel-model@npm:4.0.1" + checksum: d203615c4fae515fbfc56d735fcb0f853c79cadb56e0f7020c6e192a67c185c0a25d511dd623f34786e5e5fdbc7f6a006743093df24e402576c5baf399c349f3 languageName: node linkType: hard @@ -2502,8 +2502,8 @@ __metadata: version: 0.0.0-use.local resolution: "@hawtio/react@workspace:packages/hawtio" dependencies: - "@hawtio/camel-model-v3": "npm:@hawtio/camel-model@^3.21.0" - "@hawtio/camel-model-v4": "npm:@hawtio/camel-model@^4.0.0" + "@hawtio/camel-model-v3": "npm:@hawtio/camel-model@^3.21.1" + "@hawtio/camel-model-v4": "npm:@hawtio/camel-model@^4.0.1" "@module-federation/utilities": ^3.0.0 "@patternfly/react-charts": ^7.1.1 "@patternfly/react-code-editor": ^5.1.1