Skip to content

Commit

Permalink
Support 'deprecates' metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AjBreidenbach committed Feb 7, 2024
1 parent 5e726be commit 80661f4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@ const getters = {
if(environment.instances) result = Object.values(environment.instances).filter(conn => {
const connExtends = [
...(resolver(conn.type)?.extends || []),
...(conn.metadata?.extends || [])
...(conn.metadata?.extends || []),
// allow types declaring deprecates to substitute for any type they deprecate
...(resolver(conn.type)?.metadata?.deprecates || [])
.map(deprecated => resolver(deprecated)?.extends || [])
.flat()
]
return connExtends?.includes(constraintType)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,26 @@ const getters = {
return function(requirement, all=false) {
if(!requirement) return []
const types = all? state.availableResourceTypes: getters.instantiableResourceTypes
return types.filter(type => {
const isValidImplementation = type.extends?.includes(requirement.constraint?.resourceType)
const validSubclasses = types.filter(type => {
const isValidImplementation = [
...(type.extends || []),
// allow types declaring deprecates to substitute for any type they deprecate
...(type.metadata.deprecates || [])
.map(deprecated => getters.resolveResourceTypeFromAny(deprecated)?.extends)
.flat()
].includes(requirement.constraint?.resourceType)
return isValidImplementation
})

// if a type is marked as deprecated by another type among validSubclasses, filter it out
let deprecatedTypes = []
validSubclasses.forEach(type => {
if(type.metadata.deprecates) {
deprecatedTypes = _.union(deprecatedTypes, type.metadata.deprecates)
}
})

return validSubclasses.filter(type => !deprecatedTypes.includes(type.name))
}
},

Expand Down
13 changes: 12 additions & 1 deletion packages/oc-pages/vue_shared/lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,21 @@ const transforms = {
resourceType.requirements = []
}

if(resourceType.metadata?.alias) {
if(!resourceType.metadata) {
resourceType.metadata = {}
}

if(resourceType.metadata.alias) {
resourceType.implementations = []
}

if(resourceType.metadata.deprecates) {
const deprecates = resourceType.metadata.deprecates
if(!Array.isArray(deprecates)) {
resourceType.metadata.deprecates = [deprecates]
}
}

normalizeDirectives(resourceType.directives)

const utilization = resourceType.directives?.includes('substitute')? 0: 1
Expand Down

0 comments on commit 80661f4

Please sign in to comment.