Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify code after cleaning up support array of planEntityVersion codec #213

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unocha/hpc-api-core",
"version": "10.8.1",
"version": "10.9.0",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
38 changes: 16 additions & 22 deletions src/lib/data/planEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
annotatedMap,
getRequiredData,
getRequiredDataByValue,
isDefined,
type AnnotatedMap,
} from '../../util';
import type { MapOfGoverningEntities } from './governingEntities';
Expand Down Expand Up @@ -135,29 +134,24 @@ export const getAndValidateAllPlanEntities = async ({
// Able to inspect entity details
entityDetails.description = planEntityVersion.value.description;

if (
planEntityVersion.value.support &&
Array.isArray(planEntityVersion.value.support)
) {
const supportingPlanEntityIds = planEntityVersion.value.support
.flatMap((s) => s?.planEntityIds)
.filter(isDefined);
// Check that the list of planEntityIds is valid
const missing = supportingPlanEntityIds.filter(
(id) => !planEntityIDs.has(id)
);
if (!allowMissingPlanEntities && missing.length > 0) {
throw new Error(
`Missing supporting planEntityIds: ${missing.join(', ')}`
);
}

// TODO: Check that the plan entities pass the canSupport requirements
// specified in the prototype, including matching the cardinality
entityDetails.supports = supportingPlanEntityIds.filter((id) =>
planEntityIDs.has(id)
const supportingPlanEntityIds = planEntityVersion.value.support.flatMap(
(s) => s.planEntityIds ?? []
);
// Check that the list of planEntityIds is valid
const missing = supportingPlanEntityIds.filter(
(id) => !planEntityIDs.has(id)
);
if (!allowMissingPlanEntities && missing.length > 0) {
throw new Error(
`Missing supporting planEntityIds: ${missing.join(', ')}`
);
}

// TODO: Check that the plan entities pass the canSupport requirements
// specified in the prototype, including matching the cardinality
entityDetails.supports = supportingPlanEntityIds.filter((id) =>
planEntityIDs.has(id)
);
}

result.set(entityDetails.id, entityDetails);
Expand Down
Loading