function getEntryPoint()

in src/LegacyFunctionLoader.ts [40:75]


function getEntryPoint(f: any, entryPoint?: string): [FunctionCallback, unknown] {
    let thisArg: unknown;
    if (f !== null && typeof f === 'object') {
        thisArg = f;
        if (entryPoint) {
            // the module exports multiple functions
            // and an explicit entry point was named
            f = f[entryPoint];
        } else if (Object.keys(f).length === 1) {
            // a single named function was exported
            const name = Object.keys(f)[0];
            f = f[name];
        } else {
            // finally, see if there is an exported function named
            // 'run' or 'index' by convention
            f = f.run || f.index;
        }
    }

    if (!f) {
        const msg =
            (entryPoint
                ? `Unable to determine function entry point: ${entryPoint}. `
                : 'Unable to determine function entry point. ') +
            'If multiple functions are exported, ' +
            "you must indicate the entry point, either by naming it 'run' or 'index', or by naming it " +
            "explicitly via the 'entryPoint' metadata property.";
        throw new AzFuncSystemError(msg);
    } else if (typeof f !== 'function') {
        throw new AzFuncSystemError(
            'The resolved entry point is not a function and cannot be invoked by the functions runtime. Make sure the function has been correctly exported.'
        );
    }

    return [f, thisArg];
}