constructor()

in src/orchestrations/OrchestratorState.ts [55:93]


    constructor(options: IOrchestratorState, _literalActions = false) {
        this.isDone = options.isDone;
        this.actions = options.actions;
        this.output = options.output;
        this.schemaVersion = options.schemaVersion;

        if (options.error) {
            this.error = options.error;
        }

        if (options.customStatus) {
            this.customStatus = options.customStatus;
        }
        // Under replay protocol V1, compound actions are treated as lists of actions and
        // atomic actions are represented as a 1-element lists.
        // For example, given actions list: [Activity, WhenAny(ExternalEvent, WhenAll(Timer, Activity))]
        // The V1 protocol expects: [[Activity], [ExternalEvent, Timer, Activity]]
        if (options.schemaVersion === ReplaySchema.V1 && !_literalActions) {
            // We need to transform our V2 action representation to V1.
            // In V2, actions are represented as 2D arrays (for legacy reasons) with a singular element: an array of actions.
            const actions = this.actions[0];
            const newActions: IAction[][] = [];
            // guard against empty array, meaning no user actions were scheduled
            if (actions !== undefined) {
                for (const action of actions) {
                    // Each action is represented as an array in V1
                    const newEntry: IAction[] = [];
                    if (action instanceof WhenAllAction || action instanceof WhenAnyAction) {
                        const innerActionArr = this.flattenCompoundActions(action.compoundActions);
                        newEntry.push(...innerActionArr);
                    } else {
                        newEntry.push(action);
                    }
                    newActions.push(newEntry);
                }
                this.actions = newActions;
            }
        }
    }