@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
108 lines (107 loc) • 3.96 kB
TypeScript
import { Observable } from 'rxjs';
import { PersistentWorkItemState } from './persistent-work-item-state';
import { PersistentWorkflowContext } from './persistent-workflow-context';
declare type PersistentDataType = any;
declare type TransitDataType = any;
/**
* Abstract class of work item to build a work flow. The sequence of handlers called within
* the work item.
*
* [Standard sequence]
* The workflow has been completed within single worker instance. If there is an error the
* sequence stops at the error.
*
* 1) init() => void.
* 2) preValidate() => Observable. (state === PersistentWorkItemState.PreValidating)
* 3) apply() => Observable.
* 4) postValidate() => Observable.
* 5) finalize() => void.
*
* [Restore the work item]
* When user closed the browser but completion of apply() was not undetermined, restoration of
* work item will be processed.
*
* If preValidate() updates applyState to 'PersistentWorkItemApplyState.Required', call apply() again.
* 1) preValidate() => Observable. (state === PersistentWorkItemState.PreValidating)
* 2) apply() => Observable.
* 3) postValidate() => Observable.
* 4) finalize() => void.
*
* If preValidate() updates applyState to 'PersistentWorkItemApplyState.Skip', skip apply().
* 1) preValidate() => Observable. (state === PersistentWorkItemState.PreValidating)
* 2) postValidate() => Observable.
* 3) finalize() => void.
*
* When apply() was already succeeded state, it starts from postValidate() call.
*
* 1) postValidate() => Observable.
* 2) finalize() => void.
*
*/
export declare abstract class PersistentWorkItem<TContext extends PersistentWorkflowContext<TransitDataType, PersistentDataType>> {
name: string;
/**
* The identification of work item in the workflow.
*/
id: number;
/**
* The next identification of work item. This value can be update dynamically to switch the work item
* instead of single sequence.
*/
nextId: number;
/**
* The state of work item. This value is maintained by the workflow runner, so don't modify it.
*/
state: PersistentWorkItemState;
/**
* Initializes a new instance of the PersistentWorkItem class.
*
* @param name the name of work item.
*/
constructor(name: string);
/**
* Initializes the transit data in the context before processing apply() call.
* Update the persistent data just before calling apply().
*
* @param context the workflow context.
*/
abstract init(context: TContext): void;
/**
* The function is called after init() call and before apply() call.
*
* Pre-validation can determine to skip 'apply()' call if not required, set context.applyState to 'Skip'.
*
* Two states of work item are possible:
* - PersistentWorkItemState.PreValidatingByRestore
* pre-validation is called by restore operation.
* - PersistentWorkItemState.PreValidating
* pre-validation is called in normal sequence.
*
* @param context the workflow context.
* @returns Observable<TContext> the observable to execute.
*/
abstract preValidate(context: TContext): Observable<TContext>;
/**
* Apply the change.
*
* @param context the workflow context.
* @returns Observable<TContext> the observable to execute.
*/
abstract apply(context: TContext): Observable<TContext>;
/**
* Verify the change if it was completely done.
*
* @param context the workflow context.
* @returns Observable<TContext> the observable to execute.
*/
abstract postValidate(context: TContext): Observable<TContext>;
/**
* Finalize the work item
*
* Within this call, it can update property nextId to switch to non-predefined work item.
*
* @param context the workflow context.
*/
abstract finalize(context: TContext): void;
}
export {};