-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c2d4f3
commit a2c7b37
Showing
2 changed files
with
29 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
export type FixerStatus = 'not_started' | 'in_progress' | 'fixed' | 'not_fixed'; | ||
|
||
// Discriminated union for top-level error | ||
export type FixersStatusTopLevelError = { | ||
ok: false; // Discriminator for overall failure | ||
error: string; // When `ok` is false, top-level error is required | ||
/** | ||
* Threat Fix Status | ||
* | ||
* Individual fixer status for a threat. | ||
*/ | ||
export type ThreatFixStatusError = { | ||
error: string; | ||
}; | ||
|
||
// Discriminated union for threat-level errors | ||
export type FixersStatusThreatError = { | ||
ok: true; // Discriminator for overall success | ||
threats: { | ||
[ key: number ]: ThreatFixError; // At least one threat has an error | ||
}; | ||
export type ThreatFixStatusSuccess = { | ||
status: FixerStatus; | ||
last_updated: string; | ||
}; | ||
|
||
// Discriminated union for success scenario | ||
export type FixersStatusSuccess = { | ||
ok: true; // Discriminator for overall success | ||
threats: { | ||
[ key: number ]: ThreatFixStatusSuccess; // Threats with successful statuses | ||
}; | ||
}; | ||
export type ThreatFixStatus = ThreatFixStatusError | ThreatFixStatusSuccess; | ||
|
||
// Union type for fixers status (top-level or threat-level error, or success) | ||
export type FixersStatus = | ||
| FixersStatusTopLevelError | ||
| FixersStatusThreatError | ||
| FixersStatusSuccess; | ||
/** | ||
* Fixers Status | ||
* | ||
* Overall status of all fixers. | ||
*/ | ||
type FixersStatusBase = { | ||
ok: boolean; // Discriminator for overall success | ||
}; | ||
|
||
// Threat-level error (discriminated) | ||
export type ThreatFixError = { | ||
error: string; // Discriminator for threat-level error | ||
export type FixersStatusError = FixersStatusBase & { | ||
ok: false; | ||
error: string; | ||
}; | ||
|
||
// Threat-level success (discriminated) | ||
export type ThreatFixStatusSuccess = { | ||
status: FixerStatus; // Threat fix status (one of 'not_started', 'in_progress', etc.) | ||
last_updated: string; // Last updated timestamp | ||
export type FixersStatusSuccess = FixersStatusBase & { | ||
ok: true; | ||
threats: { | ||
[ key: number ]: ThreatFixStatus; | ||
}; | ||
}; | ||
|
||
export type ThreatFixStatus = ThreatFixError | ThreatFixStatusSuccess; | ||
export type FixersStatus = FixersStatusSuccess | FixersStatusError; |