function buildPipelineWrapper()

in core/rockefeller.ts [153:191]


function buildPipelineWrapper(buildSchema: IPipelineSchema, componentDependencies: IComponentDependencies) : IBuiltStage {
    const wrapperConfig = buildSchema.config;
    const wrapperTemplate = wrapperTemplates.find((wrapperTemplate => wrapperTemplate.name === buildSchema.component));

    /* Modify subschema */
    const subschema = buildSchema.child;
    const modifiedSubschema = wrapperTemplate.modifySubschema({...subschema}); /* future: add deep copy utility */

     /* Wrapper is constructed at the start of each execution, build dependencies stored in function closure */
     const wrapperConstructor = (executionContext: IExecutionContext, wrapperTemplate: IWrapper, wrapperConfig: any) => {

        const combinedManagedVariables = {
            ...componentDependencies.variables.managed,
            ...executionContext.managedVariables,
        }

        /* Update both managed variables at the execution context level, and wrapper level */
        const setAllManagedVariables = (key: string, value: any) => {
            combinedManagedVariables[key] = value;
            executionContext.setManagedVariable(key, value);
        }

        /* Include the managed variables from this point in the execution. */
        return wrapperTemplate.createConfiguredWrapper({
                ...wrapperTemplate.defaultConfig,
                ...wrapperConfig ?? {},
            }, {
                ...componentDependencies,
                variables: {
                    ...componentDependencies.variables,
                    managed: combinedManagedVariables,
                },
                setManagedVariable: setAllManagedVariables
            });
    }

    const builtChild = buildPipeline(modifiedSubschema, componentDependencies);
    return wrapWith(wrapperConstructor, wrapperTemplate, wrapperConfig, builtChild);
}