I am trying to develop some typescript functions that I can expose to Workshop for my particular application.
At the moment, I am not understanding how to access linked objects through the typescript functions in my code repository.
An example of what I am hoping to do:
I have a notional “Constellation” ontology that has RSO’s linked to each entry based on the RSO id. So for instance, the MUOS Constellation has the MUOS 1-5 RSO’s linked to it.
What i’d like to be able to do is to pass in a single RSO (or object set of RSO’s) and return the linked Constellation object that it is associated with.
ex: If I pass in MUOS-1 (RSO), I should get out MUOS (single constellation object).
Any thoughts or suggestions on this would be greatly helpful!
Hi @brianpatrick3 , I don’t know the exact API names of the object types in your Ontology, but hopefully these examples can help serve as a starting point for what you need.
Pass in a single RSO and return the singly linked Constellation object (note that the link access could be undefined if the RSO does not have a linked Constellation):
import { Function } from "@foundry/functions-api";
import { Constellation, Rso } from "@foundry/ontology-api";
export class MyFunctions {
@Function()
public getLinkedConstellation(rso: Rso): Constellation | undefined {
// The linked Constellation is a property of the RSO.
return rso.constellation.get();
}
}
Pass in an object set of RSOs and get all of their linked Constellations:
import { Function } from "@foundry/functions-api";
import { Constellation, ObjectSet, Rso } from "@foundry/ontology-api";
export class MyFunctions {
@Function()
public getLinkedConstellations(rsos: ObjectSet<Rso>): ObjectSet<Constellation> {
// The generated method will begin with "searchAround".
return rsos.searchAroundConstellation();
}
}
Additionally, we have some docs here that expand on the different ways linked objects can be accessed.
The missing piece here was that when you import an ontology using the resource imports menu, you ALSO have to import the link between the ontologies that you want to traverse in the typescript function.
Once you import the ontology and the links that you want to be able to access, you can then follow the steps described by @timurm above.