ViewService
import { ViewService } from "@skipcheck/tm1-client"; Views: a cube's public and private views (ViewScope), native
(NativeView: subsets on columns, rows and titles) or MDX (MDXView).
They're read as View, so each comes back as its own type.
A native view's subsets are in complex properties, reached by expanding through the
tm1.NativeView type: list with tm1.NativeView/Columns/Subset,
or getNative, which reads one view through the type. On TM1 11.8.35 the
type-cast expand works on a list holding MDX views too; an older server was reported to
fail it, and getNative doesn't depend on it.
Create a native view: each axis binds a subset, and every dimension of the cube has to be on one.
// Months across, regions down, and the cube's other dimensions as titles: every dimension
// of the cube must be on an axis. Each axis binds an existing subset.
const dimensions = ODataPath.of("Dimensions");
const months = dimensions.key("Month").nav("Hierarchies").key("Month").nav("Subsets").key("Quarters");
const regions = dimensions.key("Region").nav("Hierarchies").key("Region").nav("Subsets").key("Leaves");
const versions = dimensions.key("Version").nav("Hierarchies").key("Version");
const measures = dimensions.key("Measure").nav("Hierarchies").key("Measure");
const view = NativeViewPatch.builder()
.name("Revenue by Region")
.columns([ViewAxisSelectionPatch.builder().bindSubset(months).build()])
.rows([ViewAxisSelectionPatch.builder().bindSubset(regions).build()])
.titles([
ViewTitlePatch.builder().bindSubset(versions.nav("Subsets").key("All")).bindSelected(versions.nav("Elements").key("Actual")).build(),
ViewTitlePatch.builder().bindSubset(measures.nav("Subsets").key("All")).bindSelected(measures.nav("Elements").key("Revenue")).build(),
])
.suppressEmptyRows(true)
.build();
return tm1.views.create("Sales", ViewScope.Public, view);
Create an MDX view from its query:
// An MDX view is its query
const mdx =
"SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0," +
" {TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)} ON 1 FROM [Sales]" +
" WHERE ([Version].[Version].[Actual], [Measure].[Measure].[Revenue])";
return tm1.views.create("Sales", ViewScope.Private, MDXViewPatch.builder().name("My Revenue").mdx(mdx).build());
List a cube's views, telling the kinds apart by type:
// Each view says which type it is
const views = await tm1.views.list("Sales", ViewScope.Public).toArray();
return views.map((view) => {
switch (typeOf(View, view)) {
case "MDXView":
return `${view.Name}: ${(view as MDXView).MDX}`;
case "NativeView":
return `${view.Name}: native`;
default:
return `${view.Name}: unknown kind`;
}
});
Read the subsets on a native view's axes:
// A native view's axes are complex properties: expand them by path, through the view's
// type
const withSubsets = ODataQuery.none().expand("Columns/Subset").expand("Rows/Subset");
const view = await tm1.views.getNative("Sales", ViewScope.Public, "Revenue by Region", withSubsets);
return [...(view.Columns ?? []), ...(view.Rows ?? [])].map((axis) => axis.Subset!.UniqueName!);
Members
list | GET Cubes('c')/Views (or the private ones), streamed; a native view's axes expand through its type, as tm1.NativeView/Columns/Subset. |
get | The view as its own type, or a Tm1NotFoundException if there's none. |
getNative | Reads a native view through its type, so its axes can be expanded. |
create | Creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. |
update | Changes the properties the patch sets, such as an MDX view's MDX. |
delete | DELETE Cubes('c')/Views('v'); its subsets stay. |
cube | The view's cube. |
list
list(cube: string, scope: ViewScope, query?: ODataQuery | null, options?: Tm1CallOptions): Tm1Stream<View>GET Cubes('c')/Views (or the private ones), streamed; a native view's axes expand through its type, as tm1.NativeView/Columns/Subset.
get
get(cube: string, scope: ViewScope, view: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<View>GET Cubes('c')/Views('v'): the view as its own type, or a Tm1NotFoundException if there's none.
getNative
getNative(cube: string, scope: ViewScope, view: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<NativeView>GET Cubes('c')/Views('v')/ibm.tm1.api.v1.NativeView: reads a native view through its type, so its axes can be expanded: Columns/Subset, Rows/Subset, Titles/Subset, Titles/Selected. They're complex properties, so TM1 wants paths, not nested options. An MDX view is an error.
TM1 REST Navigation ViewAxisSelection/Subset Navigation ViewTitle/Subset Navigation ViewTitle/Selected
create
create(cube: string, scope: ViewScope, view: ViewPatch, options?: Tm1CallOptions): Promise<View>POST Cubes('c')/Views: creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. TM1 (11.8) refuses a native view that leaves any of the cube's dimensions off its columns, rows and titles (400, "All cube dimensions must be placed on an axis"). Returns the view as created.
update
update(cube: string, scope: ViewScope, view: string, patch: ViewPatch, etag?: string | null, options?: Tm1CallOptions): Promise<void>PATCH Cubes('c')/Views('v'): changes the properties the patch sets, such as an MDX view's MDX. With etag (from a read), sent as If-Match: only if the view hasn't changed since, else a Tm1PreconditionFailedException.
delete
delete(cube: string, scope: ViewScope, view: string, options?: Tm1CallOptions): Promise<void>DELETE Cubes('c')/Views('v'); its subsets stay.
cube
cube(cube: string, scope: ViewScope, view: string, query?: ODataQuery | null, options?: Tm1CallOptions): Promise<Cube>GET Cubes('c')/Views('v')/Cube: the view's cube.
TM1 REST Navigation View/Cube