aerie icon indicating copy to clipboard operation
aerie copied to clipboard

Allow user-defined helpers for templating in sequencing-server

Open pranav-super opened this issue 9 months ago • 1 comments

Checked for duplicates

No - I haven't checked

Alternatives considered

No - I haven't considered

Related problems

This request is not related to a specific problem but IS based on a new feature that presently is on its way into develop: Sequence Templates.

Describe the feature request

Presently, sequence templating introduces the notion of 'helpers', which are methods in a sequence template acting on some input (currently limited to simulated activity properties). These can be used to manipulate time strings and print arrays.

It is very possible that more helpers may be desired by missions than just the 4 generic, provided in-AERIE helpers. The purpose of this ticket is to request that it be possible for users to upload their own helpers.

The infrastructure to do so has been figured out (but has been removed from the codebase) - if a user includes a custom helper function (any export function with any name that takes in and returns strings suffice) in a file in ./sequencing-server/src/lib/mustache/user-defined, it will automatically be included in the templating server. However, this would only work if the file is created and included in that folder prior to deploying AERIE locally; there is no easy and straightforward way to upload one of these helper function files and have it be included for future templating, like what is possible with mission model uploads. The agenda this issue seeks to push is that this becomes possible! The implementation that used to exist in sequencing-server/src/lib/mustache/util/index.ts follows:

import * as fs from 'fs';

//... code up until and including in-built AERIE helper registration

// TODO: FIGURE OUT A GOOD WAY TO ALLOW USER UPLOADS/DEFINITION IN AERIE MAIN? Ask about this.
/////////////// USER HELPERS ///////////////
//  Allow the user to provide their own helpers. WORK IN PROGRESS.

// relative to index.ts
const testFolder = './user-defined/';

fs.readdir(testFolder, (err, files) => {
    if (!err) {
        files.forEach(file => {
            if (file.includes(".js")) {
                // relative to mustache.ts
                import("../" + testFolder + file).then((module) => {
                    let moduleName = file.replace(".js", "")
                    let castedFunctions: { [key: string]: any } = module

                    Object.keys(castedFunctions).forEach(funcName => {
                        Handlebars.registerHelper(moduleName + "." + funcName, castedFunctions[funcName])
                    })
                })
            }
        });
    }
});

pranav-super avatar Mar 17 '25 16:03 pranav-super

Suggest that the adaptation parcel could include TS helpers that get automatically loaded during template expansion, since parcel is part of the template definition.

cartermak avatar May 09 '25 15:05 cartermak