From 9eb7500829a932f557209c1ee068acc3fd9daa5d Mon Sep 17 00:00:00 2001 From: Andrew Breidenbach Date: Wed, 7 Feb 2024 22:25:11 +0100 Subject: [PATCH] Deprecates metadata: allow connecting deprecated type in place of new type --- .../project_overview/store/modules/environments.js | 10 ++++++++-- packages/oc-pages/vue_shared/lib/normalize.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/oc-pages/project_overview/store/modules/environments.js b/packages/oc-pages/project_overview/store/modules/environments.js index 89b52fa0..8bfdb11e 100644 --- a/packages/oc-pages/project_overview/store/modules/environments.js +++ b/packages/oc-pages/project_overview/store/modules/environments.js @@ -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 => { @@ -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)) + ) }) /* diff --git a/packages/oc-pages/vue_shared/lib/normalize.js b/packages/oc-pages/vue_shared/lib/normalize.js index a9f4897e..c7536d4a 100644 --- a/packages/oc-pages/vue_shared/lib/normalize.js +++ b/packages/oc-pages/vue_shared/lib/normalize.js @@ -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: Route53DNSZone@unfurl.cloud/onecommons/unfurl-types:dns-services + * this has the following consequences (assuming Route53DNSZone has the correct implementations): + - Route53DNSZone can always be created when Route53DNSZone@unfurl.cloud/onecommons/unfurl-types:dns-services is also a valid option to create + - Route53DNSZone@unfurl.cloud/onecommons/unfurl-types:dns-services cannot be created when Route53DNSZone is a valid option to create + - Route53DNSZone can always be connected when Route53DNSZone@unfurl.cloud/onecommons/unfurl-types:dns-services is also a valid option to connect + - inversely, Route53DNSZone@unfurl.cloud/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)) {