cube
cube(apiToken: string | () => Promise‹string›, options: CubeApiOptions): CubeApiCreates an instance of the
CubeApi. The API entry point.
cube(options: CubeApiOptions): CubeApi
defaultHeuristics
defaultHeuristics(newQuery: Query, oldQuery: Query, options: TDefaultHeuristicsOptions): any
defaultOrder
defaultOrder(query: Query): object
movePivotItem
movePivotItem(pivotConfig: PivotConfig, sourceIndex: number, destinationIndex: number, sourceAxis: TSourceAxis, destinationAxis: TSourceAxis): PivotConfig
Format API
A set of helpers for formatting member values on the client, consistently with how Cube formats them. They are imported from the@cubejs-client/core/format subpath:
formatValue
formatValue(value: any, options: FormatValueOptions): stringFormats a single value according to a member’s
type and format. options extends the
member’s metadata (type, format, currency, granularity) with an optional locale
(e.g. 'en-US', 'de-DE') and an emptyPlaceholder for empty values. Numeric formats use
d3-format specifiers, and the precision of named formats (e.g.
currency_2) is treated as an upper bound — insignificant trailing zeros are trimmed.
getFormat
getFormat(member: FormatValueMember, options?: GetFormatOptions): GetFormatResultReturns a reusable formatter for a member.
options accepts an optional locale. The result
has two properties: formatString (the resolved format specifier, or null for non-numeric
formats) and formatFunc, a function that formats a value. Use it when formatting many values
for the same member.
formatDateByGranularity
formatDateByGranularity(value: Date | string | number, granularity?: string): stringFormats a date value for a given time dimension
granularity (e.g. 'day', 'month',
'year').
CubeApi
Main class for accessing Cube API
dryRun
dryRun(query: Query | Query[], options?: LoadMethodOptions): Promise‹TDryRunResponse›
dryRun(query: Query | Query[], options: LoadMethodOptions, callback?: LoadMethodCallback‹TDryRunResponse›): voidGet query related meta without query execution
load
load(query: Query | Query[], options?: LoadMethodOptions): Promise‹ResultSet›
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback‹ResultSet›): voidFetch data for the passed
query.
meta
meta(options?: MetaMethodOptions): Promise‹Meta›
meta(options?: MetaMethodOptions, callback?: LoadMethodCallback‹Meta›): voidGet meta description of cubes available for querying. Pass
onlyViews: true to request views only. On large data models this keeps cubes
out of the response payload:
Cube versions predating this option behave differently per transport: over HTTP they
ignore it and return the full data model, while over
WebSocketTransport
they reject the message with a 400, because meta params are validated strictly.sql
sql(query: Query | Query[], options?: LoadMethodOptions): Promise‹SqlQuery›
sql(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallback‹SqlQuery›): voidGet generated SQL string for the given
query.
Parameters:
subscribe
subscribe(query: Query | Query[], options: LoadMethodOptions | null, callback: LoadMethodCallback‹ResultSet›): voidAllows you to fetch data and receive updates over time. See Real-Time Data Fetch
HttpTransport
Default transport implementation.
constructor
new HttpTransport(options: TransportOptions): HttpTransport
request
request(method: string, params: any): () => Promise‹any›Implementation of ITransport
Meta
Contains information about available cubes and it’s members.
defaultTimeDimensionNameFor
defaultTimeDimensionNameFor(memberName: string): string
filterOperatorsForMember
filterOperatorsForMember(memberName: string, memberType: MemberType | MemberType[]): any
membersForQuery
membersForQuery(query: Query | null, memberType: MemberType): TCubeMeasure[] | TCubeDimension[] | TCubeMember[]Get all members of a specific type for a given query. If empty query is provided no filtering is done based on query context and all available members are retrieved. Parameters:
resolveMember
resolveMember‹T›(memberName: string, memberType: T | T[]): object | TCubeMemberByType‹T›Get meta information for a cube member Member meta information contains:
- T: MemberType
ProgressResult
stage
stage(): string
timeElapsed
timeElapsed(): string
ResultSet
Provides a convenient interface for data manipulation.
annotation
annotation(): QueryAnnotations
chartPivot
chartPivot(pivotConfig?: PivotConfig): ChartPivotRow[]Returns normalized query result data in the following format. You can find the examples of using the
pivotConfig here
chartPivot() or seriesNames(), you can pass aliasSeries in the pivotConfig
to give each series a unique prefix. This is useful for blending queries which use the same measure multiple times.
decompose
decompose(): ObjectCan be used when you need access to the methods that can’t be used with some query types (eg
compareDateRangeQuery or blendingQuery)
drillDown
drillDown(drillDownLocator: DrillDownLocator, pivotConfig?: PivotConfig): Query | nullReturns a measure drill down query. Provided you have a measure with the defined
drillMemebers on the Orders cube
drillDown method to see the rows that contribute to that metric
order or limit to the query, you can simply spread it
pivot
pivot(pivotConfig?: PivotConfig): PivotRow[]Base method for pivoting ResultSet data. Most of the times shouldn’t be used directly and
chartPivot
or tablePivot should be used instead.
You can find the examples of using the pivotConfig here
query
query(): Query
rawData
rawData(): T[]
serialize
serialize(): ObjectCan be used to stash the
ResultSet in a storage and restored later with deserialize
series
series‹SeriesItem›(pivotConfig?: PivotConfig): Series‹SeriesItem›[]Returns an array of series with key, title and series data.
- SeriesItem
seriesNames
seriesNames(pivotConfig?: PivotConfig): SeriesNamesColumn[]Returns an array of series objects, containing
key and title parameters.
tableColumns
tableColumns(pivotConfig?: PivotConfig): TableColumn[]Returns an array of column definitions for
tablePivot.
For example:
tableColumns will group the table head and return
tablePivot
tablePivot(pivotConfig?: PivotConfig): Array‹object›Returns normalized query result data prepared for visualization in the table format. You can find the examples of using the
pivotConfig here
For example:
deserialize
static deserialize‹TData›(data: Object, options?: Object): ResultSet‹TData›
- TData
getNormalizedPivotConfig
static getNormalizedPivotConfig(query: PivotQuery, pivotConfig?: Partial‹PivotConfig›): PivotConfig
SqlQuery
rawQuery
rawQuery(): SqlData
sql
sql(): string
ITransport
request
request(method: string, params: any): () => Promise‹void›
Types
Annotation
CacheMode
CacheMode: “stale-if-slow” | “stale-while-revalidate” | “must-revalidate” | “no-cache”Cache mode options for query execution. See cache control for details on available strategies.
BinaryFilter
BinaryOperator
BinaryOperator: “equals” | “notEquals” | “contains” | “notContains” | “gt” | “gte” | “lt” | “lte” | “inDateRange” | “notInDateRange” | “beforeDate” | “afterDate”
ChartPivotRow
Column
CubeApiOptions
DateRange
DateRange: string | [string, string]
DrillDownLocator
Filter
Filter: BinaryFilter | UnaryFilter
LoadMethodCallback
LoadMethodCallback: function
LoadMethodOptions
MetaMethodOptions
Extends LoadMethodOptions with the options accepted by meta.
LoadResponse
LoadResponseResult
MemberType
MemberType: “measures” | “dimensions” | “segments”
PivotConfig
Configuration object that contains information about pivot axes and other options.
Let’s apply pivotConfig and see how it affects the axes
Users.gender dimension on y axis
Now let’s put the
Users.country dimension on y axis instead
Users.country values will be laid out on y or columns axis
It’s also possible to put the
measures on x axis. But in either case it should always be the last item of the array.
PivotQuery
PivotQuery: Query & object
PivotRow
ProgressResponse
Query
QueryAnnotations
QueryOrder
QueryOrder: “asc” | “desc”
QueryType
QueryType: “regularQuery” | “compareDateRangeQuery” | “blendingQuery”
Series
SeriesNamesColumn
SqlApiResponse
SqlData
SqlQueryTuple
SqlQueryTuple: [string, boolean | string | number]
TCubeDimension
TCubeDimension: TCubeMember & object
TCubeMeasure
TCubeMeasure: TCubeMember & object
TCubeMember
TCubeMemberByType
TCubeMemberByType: T extends “measures” ? TCubeMeasure : T extends “dimensions” ? TCubeDimension : T extends “segments” ? TCubeSegment : never
TCubeMemberType
TCubeMemberType: “time” | “number” | “string” | “boolean”
TCubeSegment
TCubeSegment: Pick‹TCubeMember, “name” | “shortTitle” | “title”›
TDefaultHeuristicsOptions
TDryRunResponse
TFlatFilter
TQueryOrderArray
TQueryOrderArray: Array‹[string, QueryOrder]›
TQueryOrderObject
TableColumn
TimeDimension
TimeDimension: TimeDimensionComparison | TimeDimensionRanged
TimeDimensionBase
TimeDimensionComparison
TimeDimensionComparison: TimeDimensionBase & object
TimeDimensionGranularity
TimeDimensionGranularity: “second” | “minute” | “hour” | “day” | “week” | “month” | “year”
TimeDimensionRanged
TimeDimensionRanged: TimeDimensionBase & object
TransportOptions
UnaryFilter
UnaryOperator
UnaryOperator: “set” | “notSet”