Hi,
I’m building a large application in Workshop using TypeScript (version 1). Currently, all of my functions are written in a single index.ts file, but as the application grows, it’s becoming difficult to manage and maintain.
Is it possible to organize these functions into separate files and folders, grouped by topic, so the codebase is more modular and easier to navigate? If so, what’s the recommended approach for structuring a Workshop project this way?
Yes you can split a TypeScript v1 Repository into multiple files! But Foundry will only recognize/publish functions that are referenced in your src/index.ts file.
For example, if you have a separate src/editFunctions.ts file that defines a few functions and you wish to publish them to the Foundry Registry, you’ll need to export them into the src/index.ts file.
–
Sample src/editFunctions.ts file:
import { Edits, OntologyEditFunction, Timestamp } from "@foundry/functions-api";
import { Objects, ObjectTypeA } from "@foundry/ontology-api";
export class MyEditFunctions {
@Edits(ObjectTypeA)
@OntologyEditFunction()
public updateStatus(
objectToUpdate: ObjectTypeA,
newStatus: string,
currentUserId: string,
): void {
objectToUpdate.status = newStatus;
objectToUpdate.updatedBy = currentUserId;
objectToUpdate.updatedOn = Timestamp.now();
}
// ... other functions defined below
}
Sample src/index.ts file:
import { Edits, OntologyEditFunction } from "@foundry/functions-api";
import { Objects, ObjectTypeA } from "@foundry/ontology-api";
export { MyEditFunctions } from "./editFunctions";
export class MyPrimaryFunctions {
// ... regular functions here
}