ObjectStackObjectStack

Analytics

Analytics protocol schemas

Analytics API Protocol

Defines the HTTP interface for the Semantic Layer. Provides endpoints for executing analytical queries and discovering metadata.

Source: packages/spec/src/api/analytics.zod.ts

TypeScript Usage

import { AnalyticsEndpoint, AnalyticsMetadataResponseSchema, AnalyticsQueryRequestSchema, AnalyticsResultResponseSchema, AnalyticsSqlResponseSchema, GetAnalyticsMetaRequestSchema } from '@objectstack/spec/api';
import type { AnalyticsEndpoint, AnalyticsMetadataResponse, AnalyticsQueryRequest, AnalyticsResultResponse, AnalyticsSqlResponse, GetAnalyticsMetaRequest } from '@objectstack/spec/api';

// Validate data
const result = AnalyticsEndpoint.parse(data);

AnalyticsEndpoint

Allowed Values

  • /api/v1/analytics/query
  • /api/v1/analytics/meta
  • /api/v1/analytics/sql

AnalyticsMetadataResponse

Properties

PropertyTypeRequiredDescription
successbooleanOperation success status
error{ code: Enum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>; declaredCode?: string; message: string; userMessage?: string; … }optionalError details if success is false
meta{ timestamp: string; duration?: number; requestId?: string; traceId?: string }optionalResponse metadata
data{ name: string; title?: string; measures: object[]; dimensions: object[] }[]Available cubes, each as the CubeMeta discovery projection — the cube name, its title, and the measures/dimensions a client may name in a query. A bare array: there is no cubes wrapper object, and no cube sql is published.

Nested Shape: AnalyticsMetadataResponse.error

PropertyTypeRequiredDescription
codeEnum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages)
declaredCodestringoptionalThe producer-declared code, verbatim, when it is not a member of the closed code vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112)
messagestringReadable error message
userMessagestringoptionalProducer-marked user-facing refusal text, verbatim. Present exactly when the producer opted in at throw time; consumers render it to end users and keep their generic substitution for anything unmarked. Status-agnostic; never replaces message.
categorystringoptionalError category (e.g. validation, authorization)
httpStatusintegeroptionalHTTP status of the response carrying this error
detailsanyoptionalAdditional error context (e.g. field validation errors)
requestIdstringoptionalRequest ID for tracking

Nested Shape: AnalyticsMetadataResponse.data[number]

PropertyTypeRequiredDescription
namestringCube name
titlestringoptionalHuman-readable cube title
measures{ name: string; type: string; title?: string }[]Measures this cube accepts in /analytics/query
dimensions{ name: string; type: string; title?: string }[]Dimensions this cube accepts in /analytics/query

AnalyticsQueryRequest

Properties

PropertyTypeRequiredDescription
cubestringTarget cube name
measuresstring[]List of metrics to calculate
dimensionsstring[]optionalList of dimensions to group by
whereanyoptionalFiltering criteria (canonical Query DSL FilterCondition)
timeDimensions{ dimension: string; granularity?: Enum<'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'>; dateRange?: string | string[] }[]optional
orderRecord<string, Enum<'asc' | 'desc'>>optional
limitnumberoptional
offsetnumberoptional
timezonestringoptional
queryneveroptional[REMOVED] query was removed from AnalyticsQueryRequest in @objectstack/spec 17.0.0. The { cube, query: {...} } envelope was the dialect of the retired degraded analytics shim — the real engine never understood it. Move the query.* fields to the body top level: { cube, measures, dimensions?, where?, timeDimensions?, order?, limit?, offset?, timezone? }.
formatneveroptional[REMOVED] format was removed from AnalyticsQueryRequest in @objectstack/spec 17.0.0. It was never implemented — every response is the JSON envelope. Delete the key; for CSV/XLSX use the export surface instead.

AnalyticsResultResponse

Properties

PropertyTypeRequiredDescription
successbooleanOperation success status
error{ code: Enum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>; declaredCode?: string; message: string; userMessage?: string; … }optionalError details if success is false
meta{ timestamp: string; duration?: number; requestId?: string; traceId?: string }optionalResponse metadata
data{ rows: Record<string, any>[]; fields: object[]; sql?: string; totals?: object[] }

Nested Shape: AnalyticsResultResponse.error

PropertyTypeRequiredDescription
codeEnum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages)
declaredCodestringoptionalThe producer-declared code, verbatim, when it is not a member of the closed code vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112)
messagestringReadable error message
userMessagestringoptionalProducer-marked user-facing refusal text, verbatim. Present exactly when the producer opted in at throw time; consumers render it to end users and keep their generic substitution for anything unmarked. Status-agnostic; never replaces message.
categorystringoptionalError category (e.g. validation, authorization)
httpStatusintegeroptionalHTTP status of the response carrying this error
detailsanyoptionalAdditional error context (e.g. field validation errors)
requestIdstringoptionalRequest ID for tracking

Nested Shape: AnalyticsResultResponse.data

PropertyTypeRequiredDescription
rowsRecord<string, any>[]Result rows
fields{ name: string; type: string; label?: string; format?: string; … }[]Column metadata
sqlstringoptionalExecuted SQL (if debug enabled)
totals{ dimensions: string[]; rows: Record<string, any>[] }[]optionalMarginal aggregates - one entry per requested totals grouping, in request order, each computed with the measure's true aggregate over the underlying data (never re-derived from bucketed values). The grand-total grouping yields a single dimensionless row.

AnalyticsSqlResponse

Properties

PropertyTypeRequiredDescription
successbooleanOperation success status
error{ code: Enum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>; declaredCode?: string; message: string; userMessage?: string; … }optionalError details if success is false
meta{ timestamp: string; duration?: number; requestId?: string; traceId?: string }optionalResponse metadata
data{ sql: string; params: any[] }

Nested Shape: AnalyticsSqlResponse.error

PropertyTypeRequiredDescription
codeEnum<'VALIDATION_ERROR' | 'INVALID_FIELD' | 'MISSING_REQUIRED_FIELD' | …>Error code (e.g. VALIDATION_ERROR; StandardErrorCode ∪ the ledger the serving side registers — ERROR_CODE_LEDGER for framework packages)
declaredCodestringoptionalThe producer-declared code, verbatim, when it is not a member of the closed code vocabulary — the open, author-authored channel (app-specific spellings; ADR-0112)
messagestringReadable error message
userMessagestringoptionalProducer-marked user-facing refusal text, verbatim. Present exactly when the producer opted in at throw time; consumers render it to end users and keep their generic substitution for anything unmarked. Status-agnostic; never replaces message.
categorystringoptionalError category (e.g. validation, authorization)
httpStatusintegeroptionalHTTP status of the response carrying this error
detailsanyoptionalAdditional error context (e.g. field validation errors)
requestIdstringoptionalRequest ID for tracking

GetAnalyticsMetaRequest

Properties

PropertyTypeRequiredDescription
cubestringoptionalOptional cube name to filter

On this page