Skip to main content

cube

cube(apiToken: string | () => Promise‹string›, options: CubeApiOptions): CubeApi
Creates an instance of the CubeApi. The API entry point.
You can also pass an async function or a promise that will resolve to the API token
If you need to set up cancellation for all requests made by this API instance:
Parameters:
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): string
Formats 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): GetFormatResult
Returns 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): string
Formats 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?: LoadMethodCallbackTDryRunResponse›): void
Get query related meta without query execution

load

load(query: Query | Query[], options?: LoadMethodOptions): Promise‹ResultSet
load(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallbackResultSet›): void
Fetch data for the passed query.
You can also use AbortController to cancel a request:
Parameters:

meta

meta(options?: MetaMethodOptions): Promise‹Meta
meta(options?: MetaMethodOptions, callback?: LoadMethodCallbackMeta›): void
Get 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.
Parameters:

sql

sql(query: Query | Query[], options?: LoadMethodOptions): Promise‹SqlQuery
sql(query: Query | Query[], options?: LoadMethodOptions, callback?: LoadMethodCallbackSqlQuery›): void
Get generated SQL string for the given query. Parameters:

subscribe

subscribe(query: Query | Query[], options: LoadMethodOptions | null, callback: LoadMethodCallbackResultSet›): void
Allows 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

resolveMemberT›(memberName: string, memberType: T | T[]): object | TCubeMemberByType‹T›
Get meta information for a cube member Member meta information contains:
Type parameters: Parameters:

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
When using 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(): Object
Can 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 | null
Returns a measure drill down query. Provided you have a measure with the defined drillMemebers on the Orders cube
Then you can use the drillDown method to see the rows that contribute to that metric
the result will be a query with the required filters applied and the dimensions/measures filled out
In case when you want to add 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(): Object
Can be used to stash the ResultSet in a storage and restored later with deserialize

series

seriesSeriesItem›(pivotConfig?: PivotConfig): Series‹SeriesItem›[]
Returns an array of series with key, title and series data.
Type parameters:
  • 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:
In case we want to pivot the table axes
then 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 deserializeTData›(data: Object, options?: Object): ResultSet‹TData›
Type parameters:
  • TData
Parameters:

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
If we put the Users.gender dimension on y axis
The resulting table will look the following way Now let’s put the Users.country dimension on y axis instead
in this case the 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”