Decorators

TypeScript ↗ Functions are declared as methods of a TypeScript class ↗. There are a few requirements for a Function to be discovered and published:

  • The method must be public
  • The class the method belongs to must be exported from the functions-typescript/src/index.ts file
  • The method must be decorated with one of the following decorators imported from the @foundry/functions-api package:
    • @Function() for generic Functions.
    • @OntologyEditFunction() for Functions that will back an Action.
      • Object provenance information may be optionally specified with the @Edits([object type]) decorator when using the@OntologyEditFunction() method.
      • Object provenance information will be inferred on a best-efforts basis using the static analysis of code if the @Edits([object type]) decorator is absent.
    • @Query({ apiName: "userDefinedAPIName"}) for read-only queries that you want to execute through Foundry API. Note that this decorator should not be used in addition to the @Function decorator; it should be used on its own.

Here are examples of Functions that are correctly exported in this way:

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import { Function, OntologyEditFunction, Integer, Edits } from "@foundry/functions-api"; import { Employee } from "@foundry/ontology-api"; export class MyUsefulFunctions { @Function() public incrementNumber(x: Integer): Integer { return x + 1; } @Edits(Employee) @OntologyEditFunction() public updateName(employee: Employee, newName: string): void { employee.firstName = newName; } @Query({ apiName: "getEmployeesByName" }) public async getEmployeesByName(name: string): Promise<ObjectSet<Employee>> { return Objects.search().employee().filter(employee => employee.firstName.exactMatch(name)); } }

Any method that is private or not decorated with the relevant decorations will not be published to the Function Registry. This allows users to create helper functions and utilities for reuse or organization.

Republishing

Note that each Function in a TypeScript repository is uniquely defined by its class name and method name—if you change the name of the class or method, the Function will be published under a new identifier.