Zone Query
Zone query can be used to expand objects, or you can use it to evaluate select expressions on a list of objects. It is a more generic service that can be more flexible than using the more type specific REST API endpoints.
Below is an example showing how to expand an item 5 level and traversing the result.
const api = context.dsxAPI();
const space = api.getSpaceService();
const session = api.getTenantSession();
const zoneQueryService = space.getZoneQueryService();
const query = zoneQueryService.getObjectFactory().queryInput();
query.getRootPath().add(itemId);
query.addObjectSelects("name", "ds6w:type", "ds6w:label");
query.addObjectSelects("revision", "current", "vault");
query.addObjectSelects("ds6w:manufacturable");
query.addObjectSelects("ds6w:contentStructure");
query.addRelationshipSelects("type");
query.setExpandDepth(5);
const queryResult = zoneQueryService.perform(session, query);
const structure = zoneQueryService.toStructure(queryResult);
const nodeFn = (node, level=0) => {
const id = node.getPhysicalId();
const attributes = node.getAttributes(); // Map<String, Object>
node.getOut().forEach(rel => {
const relId = rel.getPhysicalId();
const relAttributes = rel.getAttributes();
nodeFn(rel.getTo(), level+1);
});
};
structure.getRoots().forEach(node => nodeFn(node, 0));