From 65c8533ba18d69d31a5fe0819d8d8ad608854007 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Fri, 15 May 2026 15:56:08 +0200 Subject: [PATCH] refactor: extract shared relation fields and fix type guard safety Signed-off-by: benjdlambert --- .../src/AIResourceEntityV1alpha1.ts | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/plugins/catalog-backend-module-ai-resource-entity-model/src/AIResourceEntityV1alpha1.ts b/plugins/catalog-backend-module-ai-resource-entity-model/src/AIResourceEntityV1alpha1.ts index 269a70d365..2cd3907dc7 100644 --- a/plugins/catalog-backend-module-ai-resource-entity-model/src/AIResourceEntityV1alpha1.ts +++ b/plugins/catalog-backend-module-ai-resource-entity-model/src/AIResourceEntityV1alpha1.ts @@ -115,7 +115,28 @@ export const isAIResourceEntity = ( export const isSkillAIResourceEntity = ( entity: Entity, ): entity is SkillAIResourceEntityV1alpha1 => - isAIResourceEntity(entity) && entity.spec.type === 'skill'; + isAIResourceEntity(entity) && entity.spec?.type === 'skill'; + +/** + * Extends the catalog model with the AIResource kind. + * + * @alpha + */ +const baseRelationFields = [ + { + selector: { path: 'spec.owner' }, + relation: 'ownedBy', + defaultKind: 'Group', + defaultNamespace: 'inherit' as const, + allowedKinds: ['Group', 'User'], + }, + { + selector: { path: 'spec.system' }, + relation: 'partOf', + defaultKind: 'System', + defaultNamespace: 'inherit' as const, + }, +]; /** * Extends the catalog model with the AIResource kind. @@ -137,21 +158,7 @@ export const aiResourceEntityModel = createCatalogModelLayer({ versions: [ { name: 'v1alpha1', - relationFields: [ - { - selector: { path: 'spec.owner' }, - relation: 'ownedBy', - defaultKind: 'Group', - defaultNamespace: 'inherit', - allowedKinds: ['Group', 'User'], - }, - { - selector: { path: 'spec.system' }, - relation: 'partOf', - defaultKind: 'System', - defaultNamespace: 'inherit', - }, - ], + relationFields: baseRelationFields, schema: { jsonSchema: defaultJsonSchema as JsonObject, }, @@ -160,24 +167,12 @@ export const aiResourceEntityModel = createCatalogModelLayer({ name: 'v1alpha1', specType: 'skill', relationFields: [ - { - selector: { path: 'spec.owner' }, - relation: 'ownedBy', - defaultKind: 'Group', - defaultNamespace: 'inherit', - allowedKinds: ['Group', 'User'], - }, - { - selector: { path: 'spec.system' }, - relation: 'partOf', - defaultKind: 'System', - defaultNamespace: 'inherit', - }, + ...baseRelationFields, { selector: { path: 'spec.dependsOn' }, relation: 'dependsOn', defaultKind: 'AIResource', - defaultNamespace: 'inherit', + defaultNamespace: 'inherit' as const, }, ], schema: {