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

Bootstrap ZDT migration algorithm #151282

Merged
merged 12 commits into from
Feb 27, 2023
Prev Previous commit
Next Next commit
improve ModelStage utility type
  • Loading branch information
pgayvallet committed Feb 27, 2023
commit f7d6c7fe357030474dfb01ec55799526bfa56584
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isTypeof } from '../../actions';
import type { State } from '../../state';
import type { ModelStage } from '../types';

export const init: ModelStage<'INIT'> = (state, res, context): State => {
export const init: ModelStage<'INIT', 'DONE' | 'FATAL'> = (state, res, context): State => {
if (Either.isLeft(res)) {
const left = res.left;
if (isTypeof(left, 'incompatible_cluster_routing_allocation')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import { ExcludeRetryableEsError } from '../../model/types';
import type { MigratorContext } from '../context';
import type { State, AllActionStates, StateFromActionState } from '../state';
import type {
AllActionStates,
AllControlStates,
StateFromActionState,
StateFromControlState,
} from '../state';
import type { ResponseType } from '../next';

/**
Expand All @@ -21,8 +26,8 @@ export type StateActionResponse<T extends AllActionStates> = ExcludeRetryableEsE
/**
* Defines a stage delegation function for the model
*/
export type ModelStage<T extends AllActionStates> = (
export type ModelStage<T extends AllActionStates, R extends AllControlStates> = (
state: StateFromActionState<T>,
res: StateActionResponse<T>,
context: MigratorContext
) => State;
) => StateFromControlState<T | R>;
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export type {
AllActionStates,
AllControlStates,
StateFromActionState,
StateFromControlState,
} from './types';
export { createInitialState } from './create_initial_state';
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ export interface ControlStateMap {
/**
* Utility type to reverse lookup an `AllControlStates` to it's corresponding State subtype.
*/
export type StateFromActionState<T extends AllActionStates> = ControlStateMap[T];
export type StateFromControlState<T extends AllControlStates> = ControlStateMap[T];

/**
* Utility type to reverse lookup an `AllActionStates` to it's corresponding State subtype.
*/
export type StateFromActionState<T extends AllActionStates> = StateFromControlState<T>;