imports/vx/server/code/vxapp.js
/**
     * Deploy a user-written function.
     *
     * @param {string} functionId Function ID to deploy.
     */
Deploy a user-written function.
@param {string} functionId Function ID to deploy.
Deploy a user - written function . @param { string } functionId Function ID to deploy .
deployFunction(functionId) {
        try {
            const newFunction = Functions.findOne(functionId)
            if (!newFunction) {
                OLog.error(`vxapp.js deployFunction unable to find functionId=${functionId}`)
                return { success : false, icon : "BUG", key : "common.alert_transaction_fail_function_not_found",
                    variables : { functionId : functionId } }
            }
            const functionAnchor = VXApp.functionAnchorForDomain(newFunction.domain)
            const qualifiedFunctionAnchor = VXApp.qualifiedFunctionAnchor(functionAnchor, newFunction.domain)
            const fullyQualifiedFunctionAnchor = VXApp.fullyQualifiedFunctionAnchor(qualifiedFunctionAnchor)
            if (!FunctionAnchors[qualifiedFunctionAnchor]) {
                OLog.debug(`vxapp.js deployFunction *instantiating* ${fullyQualifiedFunctionAnchor}`)
                FunctionAnchors[qualifiedFunctionAnchor] = {}
            }
            if (!newFunction.name) {
                OLog.debug(`vxapp.js deployFunction no name yet ignoring functionId=${functionId}`)
                return { success: true, icon: "ENVELOPE", key: "common.alert_transaction_success" }
            }
            if (typeof newFunction.name === "string") {
                delete FunctionAnchors[qualifiedFunctionAnchor][newFunction.name]
            }
            if (!newFunction.value) {
                OLog.debug(`vxapp.js deployFunction no value supplied implicitly deleting functionId=${functionId}`)
                return { success: true, icon: "ENVELOPE", key: "common.alert_transaction_success" }
            }
            let adjustedFunction =
                VXApp.replaceFunctionAnchorReferences(newFunction.value, functionAnchor, fullyQualifiedFunctionAnchor)
            adjustedFunction = VXApp.augmentFunctionWithName(adjustedFunction, newFunction.name)
            const func = eval(`(${adjustedFunction})`)
            if (typeof newFunction.name === "string" && typeof func === "function") {
                FunctionAnchors[qualifiedFunctionAnchor][newFunction.name] = func
            }
            OLog.debug(`vxapp.js deployFunction has added ${fullyQualifiedFunctionAnchor}.${newFunction.name} ` +
                `resulting in keys=${Object.keys(FunctionAnchors[qualifiedFunctionAnchor])}`)
            return { success: true, icon: "ENVELOPE", key: "common.alert_transaction_success" }
        }
        catch (error) {
            OLog.error(`vxapp.js deployFunction unexpected error=${error}`)
            return { success : false, icon : "BUG", key : "common.alert_unexpected_error", variables : { error : error.toString() } }
        }
    }
deployFunction ( functionId ) { try { const newFunction = Functions . findOne ( functionId ) if ( ! newFunction ) { OLog . error ( ` ${ functionId } ` ) return { success : false , icon : "BUG" , key : "common.alert_transaction_fail_function_not_found" , variables : { functionId : functionId } } } const functionAnchor = VXApp . functionAnchorForDomain ( newFunction . domain ) const qualifiedFunctionAnchor = VXApp . qualifiedFunctionAnchor ( functionAnchor , newFunction . domain ) const fullyQualifiedFunctionAnchor = VXApp . fullyQualifiedFunctionAnchor ( qualifiedFunctionAnchor ) if ( ! FunctionAnchors [ qualifiedFunctionAnchor ] ) { OLog . debug ( ` ${ fullyQualifiedFunctionAnchor } ` ) FunctionAnchors [ qualifiedFunctionAnchor ] = { } } if ( ! newFunction . name ) { OLog . debug ( ` ${ functionId } ` ) return { success : true , icon : "ENVELOPE" , key : "common.alert_transaction_success" } } if ( typeof newFunction . name === "string" ) { delete FunctionAnchors [ qualifiedFunctionAnchor ] [ newFunction . name ] } if ( ! newFunction . value ) { OLog . debug ( ` ${ functionId } ` ) return { success : true , icon : "ENVELOPE" , key : "common.alert_transaction_success" } } let adjustedFunction = VXApp . replaceFunctionAnchorReferences ( newFunction . value , functionAnchor , fullyQualifiedFunctionAnchor ) adjustedFunction = VXApp . augmentFunctionWithName ( adjustedFunction , newFunction . name ) const func = eval ( ` ${ adjustedFunction } ` ) if ( typeof newFunction . name === "string" && typeof func === "function" ) { FunctionAnchors [ qualifiedFunctionAnchor ] [ newFunction . name ] = func } OLog . debug ( ` ${ fullyQualifiedFunctionAnchor } ${ newFunction . name } ` + ` ${ Object . keys ( FunctionAnchors [ qualifiedFunctionAnchor ] ) } ` ) return { success : true , icon : "ENVELOPE" , key : "common.alert_transaction_success" } } catch ( error ) { OLog . error ( ` ${ error } ` ) return { success : false , icon : "BUG" , key : "common.alert_unexpected_error" , variables : { error : error . toString ( ) } } } }
Deploy a user-written function.
Deploy a user - written function .