Emit Data Structures
The response of a Service takes place via a utility called SmeupDataStructureWriter. This class is injected into each function method and supports the output of data structures via streaming.
Emit a Tree Data Structure
You can use the method writeDataNode(node: SmeupDataNode)
to return a node of a tree data structure.
async function methodThatReturnTree(
_fun: Fun,
_context: ExecutionContext,
printer: SmeupDataStructureWriter
) {
printer.writeDataNode({
children: [{
children: [],
value: "Nested node (1.1)"
}],
obj: {
t: "",
p: "",
k: "",
},
value: "Node 1",
});
printer.writeDataNode({
children: [],
obj: {
t: "",
p: "",
k: "",
},
value: "Node 2",
});
}
Result:
|
└-Node 1
└─── Nested node (1.1)
|
└-Node 2
Emit a Data Table Structure
The data table is based on columns and rows and each rows contais cells. To emit a Data Table you can emit data in two steps:
- create and emit the data grid
- create and emit row by row
The method to emit data structure is the same as Tree. You can use the instance of SmeupDataStructurePrinter
especially the methods:ù
writeDataColumns(columns: SmeupDataColumns[])
: return the columns of the gridwriteDataRow(row: SmeupDataRow)
: return one row
async function methodThatReturnDataTable(
_fun: Fun,
_context: ExecutionContext,
printer: SmeupDataStructureWriter
) {
printer.writeDataColumns([
{
name: "ID",
title: "Contact ID",
},
{
name: "NAME",
title: "Contact Name",
},
]);
printer.writeDataRow({
cells: {
COL1: {
value: "ROSMAR",
obj: {
t: "",
p: "",
k: "",
},
},
COL2: {
value: "Rossi Mario",
obj: {
t: "",
p: "",
k: "",
},
},
},
});
}
Code | Name |
---|---|
ROSMAR | Rossi Mario |
BIAMAR | Bianca Maria |