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

HPC-9997: Simplify support array in PLAN_ENTITY_VERSION_VALUE codec #202

Merged
merged 2 commits into from
Jan 16, 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.7.0",
"version": "10.7.1",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
43 changes: 14 additions & 29 deletions src/db/models/planEntityVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,22 @@ const PLAN_ENTITY_VERSION_REF = t.partial({
entityPrototypeId: ENTITY_PROTOTYPE_ID,
});

export const PLAN_ENTITY_VERSION_VALUE = t.intersection([
t.type({
categories: t.array(CATEGORY_ID),
description: t.string,
type: LOCALIZED_PLURAL_STRING,
}),
t.partial({
support: t.union([
t.array(
t.union([
/**
* TODO: Some records in the database have `null` inside `support` array,
* which is problematic. Stricter validation of data being stored should
* be done, existing values removed and then `null` removed from this type.
*/
t.null,
PLAN_ENTITY_VERSION_REF,
])
),
export const PLAN_ENTITY_VERSION_VALUE = t.type({
categories: t.array(CATEGORY_ID),
description: t.string,
type: LOCALIZED_PLURAL_STRING,
support: t.array(
t.union([
/**
* TODO: Some records have object with key "0" instead of array of objects,
* which is absolutely ridiculous. We need to have stricter validation of
* data being stored here, convert existing cases to arrays, and then remove
* this awful type edge case
* TODO: Some records in the database have `null` inside `support` array,
* which is problematic. Stricter validation of data being stored should
* be done, existing values removed and then `null` removed from this type.
*/
t.partial({
0: PLAN_ENTITY_VERSION_REF,
}),
]),
}),
]);
t.null,
PLAN_ENTITY_VERSION_REF,
])
),
});
export type PlanEntityVersionValue = t.TypeOf<typeof PLAN_ENTITY_VERSION_VALUE>;

export default defineLegacyVersionedModel({
Expand Down
Loading