Skip to content

Commit

Permalink
Deprecates metadata: allow connecting deprecated type in place of new…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
AjBreidenbach committed Feb 7, 2024
1 parent 80661f4 commit 9eb7500
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/oc-pages/project_overview/store/modules/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,12 @@ function envFilter(name){
const getters = {
getEnvironments: state => state.projectEnvironments,
lookupEnvironment: (_, getters) => function(name) {return getters.getEnvironments.find(envFilter(name))},
getValidEnvironmentConnections: (state, getters) => function(environmentName, requirement, _resolver) {
getValidEnvironmentConnections: (state, getters, _, rootGetters) => function(environmentName, requirement, _resolver) {
const resolver = _resolver? _resolver: getters.environmentResolveResourceType.bind(getters, environmentName)
const filter = envFilter(environmentName)
const environment = state.projectEnvironments.find(filter)
const constraintType = constraintTypeFromRequirement(requirement)
const availableTypes = rootGetters.availableResourceTypesForRequirement(requirement) // types that would be available to create
if(!environment) return []
let result = []
if(environment.instances) result = Object.values(environment.instances).filter(conn => {
Expand All @@ -680,7 +681,12 @@ const getters = {
.map(deprecated => resolver(deprecated)?.extends || [])
.flat()
]
return connExtends?.includes(constraintType)

return (
// is our create type in extends or would a deprecating type be valid to connect
connExtends?.includes(constraintType) ||
availableTypes.some(type => type.metadata.deprecates?.includes(conn.type))
)
})

/*
Expand Down
14 changes: 14 additions & 0 deletions packages/oc-pages/vue_shared/lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ const transforms = {
resourceType.implementations = []
}

/*
* see also getValidEnvironmentConnections and availableResourceTypesForRequirement
* if a resource type specifies deprecates, its extends will be searched along with the extends of every type that it 'deprecates'
* if a resource type is marked as deprecated by another type, it cannot be 'created' if its deprecating type is an option to create
* if a resource type is marked as deprecated by another type, it can be 'connected' when its deprecating type would be connectable
* this ultimately affects how both types will be available to connect or create
* e.g. Route53DNSZone has deprecates: [email protected]/onecommons/unfurl-types:dns-services
* this has the following consequences (assuming Route53DNSZone has the correct implementations):
- Route53DNSZone can always be created when [email protected]/onecommons/unfurl-types:dns-services is also a valid option to create
- [email protected]/onecommons/unfurl-types:dns-services cannot be created when Route53DNSZone is a valid option to create
- Route53DNSZone can always be connected when [email protected]/onecommons/unfurl-types:dns-services is also a valid option to connect
- inversely, [email protected]/onecommons/unfurl-types:dns-services can always be connected when Route53DNSZone is also a valid option to connect
*/
if(resourceType.metadata.deprecates) {
const deprecates = resourceType.metadata.deprecates
if(!Array.isArray(deprecates)) {
Expand Down

0 comments on commit 9eb7500

Please sign in to comment.