Skip to content

Commit

Permalink
chore(camel): update @hawtio/camel-model
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Oct 20, 2023
1 parent fd12d90 commit 073018b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/hawtio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions packages/hawtio/src/plugins/camel/camel-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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', () => {
Expand Down
11 changes: 5 additions & 6 deletions packages/hawtio/src/plugins/camel/camel-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions packages/hawtio/src/plugins/camel/schema-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ describe('schema-service', () => {
const schemaText = fs.readFileSync(schemaPath, { encoding: 'utf8', flag: 'r' })
const schema = JSON.parse(schemaText)

let defn: Record<string, unknown> | null = schemaService.lookupDefinition('base', schema)
let defn: Record<string, unknown> | null = schemaService.lookupDefinition('base', schema.definitions)
expect(defn).not.toBeNull()
let def: Record<string, unknown> = defn as Record<string, unknown>
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<string, unknown>
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<string, unknown>
expect(def.type).toBe('object')
Expand Down
15 changes: 6 additions & 9 deletions packages/hawtio/src/plugins/camel/schema-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>} definitions
*/
lookupDefinition(name: string, schema: Record<string, unknown>): Record<string, unknown> | null {
if (!schema) return null
lookupDefinition(name: string, definitions: Record<string, unknown>): Record<string, unknown> | null {
if (!definitions) return null

if (!isObject(schema.definitions)) return null
if (!isObject(definitions[name])) return null

const defs: Record<string, unknown> = schema.definitions as Record<string, unknown>
if (!isObject(defs[name])) return null

const answer = defs[name] as Record<string, unknown>
const answer = definitions[name] as Record<string, unknown>
if (isObject(answer['fullSchema'])) {
return answer['fullSchema'] as Record<string, unknown>
}
Expand All @@ -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)) {
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 073018b

Please sign in to comment.