ObjectStackObjectStack

Dataset schema — UI Protocol reference

Analytics Dataset — the one semantic layer. Reference for Dataset, DatasetDimension, DatasetDurationUnit and 5 more: every property with its type and default.

Analytics Dataset — the one semantic layer (ADR-0021).

A dataset is a named, reusable analytical definition: a base object, the relationships to include (joins are derived from the object graph — the author never writes an ON clause), and the declared dimensions (groupable axes) and measures (aggregatable values). It is deliberately SMALLER than QuerySchema: no raw SQL, no hand-authored join predicates, no window/having grammar in the author surface.

Presentations (report / dashboard) bind to a dataset by reference and pick dimensions/measures by name. The dataset compiles to the existing Cube analytics runtime (ADR-0021 D-A=(c)); RLS / tenant scoping is enforced by the runtime per joined object (D-C), never declared here.

Naming: this module owns the high-prior dataset / dimension / measure vocabulary (LookML / dbt / Cube / PowerBI). The Zod export identifiers are Dataset-prefixed (DatasetDimensionSchema, DatasetMeasureSchema) so they do not clash with the Cube layer's DimensionSchema / MetricSchema in data/analytics.zod.ts while the two layers coexist (Phase 1). The Cube layer is absorbed/retired in a later phase (D-A).

Business vocabulary (ADR-0149 D1): every dimension and measure may carry synonyms — the words people use for it in a question, matched and never rendered — and a description, one or two sentences of business definition in plain language, never a prompt. Within one dataset a word answers to one member: a synonym may not equal another member's name, label or synonym.

Source: packages/spec/src/ui/dataset.zod.ts

TypeScript Usage

import { DatasetSchema, DatasetDimensionSchema, DatasetDurationUnit, DatasetMeasureSchema, DatasetMeasureDurationSchema, DatasetMeasurePolarity, DatasetMemberSynonymsSchema, DerivedMeasureOp } from '@objectstack/spec/ui';
import type { Dataset, DatasetDimension, DatasetDurationUnit, DatasetMeasure, DatasetMeasureDuration, DatasetMeasurePolarity, DatasetMemberSynonyms } from '@objectstack/spec/ui';

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

Dataset

Properties

PropertyTypeRequiredDescription
namestring✅Dataset unique name
labelstring | Record<string, string>✅Dataset label
descriptionstring | Record<string, string>optionalDisplay label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time
objectstring✅Base object name
includestring[]optionalRelationship names/paths to join (derived from object graph; max 3 hops)
filteranyoptionalIntrinsic dataset scope filter
dimensions{ name: string; label?: string | Record<string, string>; field: string; type?: Enum<'string' | 'number' | 'date' | 'boolean' | 'lookup'>; … }[]✅Groupable axes
measures{ name: string; label?: string | Record<string, string>; aggregate?: Enum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'>; field?: string; … }[]✅Aggregatable values
protection{ lock: Enum<'none' | 'no-overlay' | 'no-delete' | 'full'>; reason: string; docsUrl?: string }optionalPackage author protection block — lock policy for this dataset.
_lockEnum<'none' | 'no-overlay' | 'no-delete' | 'full'>optionalItem-level lock — controls overlay & delete (ADR-0010).
_lockReasonstringoptionalHuman-readable reason shown when a write is refused by _lock.
_lockSourceEnum<'artifact' | 'package' | 'env-forced'>optionalLayer that set _lock (artifact | package | env-forced).
_provenanceEnum<'package' | 'org' | 'env-forced' | 'platform'>optionalOrigin of the item (package | org | env-forced | platform).
_packageIdstringoptionalOwning package machine id.
_packageVersionstringoptionalOwning package version.
_lockDocsUrlstringoptionalOptional documentation link surfaced next to _lockReason.
overrides{ package: string; basedOn: string }optionalOverride declaration (ADR-0146 D2): { package, basedOn } — this item of "<base>.custom" replaces the base package's same-named item whole. basedOn is recorded and never gates; a base's upgrade plan reads it only as advice.

Nested Shape: Dataset.dimensions[number]

PropertyTypeRequiredDescription
namestring✅Dimension name — referenced by presentations
labelstring | Record<string, string>optionalDisplay label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time
fieldstring✅Base field, or relationship[.relationship].field path. A column reference, never a SQL expression.
typeEnum<'string' | 'number' | 'date' | 'boolean' | 'lookup'>optional
dateGranularityEnum<'day' | 'week' | 'month' | 'quarter' | 'year'>optional
nullLabelstring | Record<string, string>optionalLabel for the bucket of rows whose value for this dimension is null (e.g. "System" on a user axis). Display copy only: grouping is unchanged. When absent, consumers fall back to their own default label for that bucket.
synonymsstring[]optionalWords a person uses for this member in a question (e.g. ["收入", "销售额", "revenue"]), matched after normalization and never rendered. Each trimmed, non-empty, at most 60 characters; at most 20. Within one dataset a synonym may not equal another member's name, label or synonym.
descriptionstring | Record<string, string>optionalBusiness definition of this dimension in plain language — one or two sentences on what it is and when to use it (e.g. "商机当前所处的销售阶段,从初步接洽到赢单或丢单"). Never a prompt or an instruction to an AI. At most 500 characters per locale.

Nested Shape: Dataset.measures[number]

PropertyTypeRequiredDescription
namestring✅Measure name — e.g. "revenue"; defined once
labelstring | Record<string, string>optionalDisplay label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time
aggregateEnum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'>optionalAggregation (sum/avg/count/...); omit when derived is set
fieldstringoptionalAggregated field: a base field, a relationship path, or "" for a count; optional for count(). Never a SQL expression.
filteranyoptional
formatstringoptionalNumeral pattern for a NUMERIC measure — grouping, decimals, percent; e.g. "0,0.00", "0.0%". An amount takes its symbol from currency, not from a "$" in the pattern. A DATE-valued measure never reads a date pattern: "YYYY-MM-DD" renders that arm's default face. A date or datetime value reads format as a display style — short or relative, honoured on both.
currencystringoptionalDisplay currency code (ISO 4217)
polarityEnum<'higher' | 'lower' | 'neutral'>optionalWhich direction of change is good news: higher (rise green, fall red), lower (fall green, rise red) or neutral (no good/bad colour). Colours a period-over-period delta; undeclared keeps rise green, fall red.
derived{ op: Enum<'ratio' | 'sum' | 'difference' | 'product'>; of: string[] }optional
duration{ from: string; to: string; unit: Enum<'seconds' | 'minutes' | 'hours' | 'days'> }optionalTime between two datetime columns of each record ({ from, to, unit }), reduced by aggregate (avg / min / max / sum). Records with either instant null are excluded. Replaces field.
synonymsstring[]optionalWords a person uses for this member in a question (e.g. ["收入", "销售额", "revenue"]), matched after normalization and never rendered. Each trimmed, non-empty, at most 60 characters; at most 20. Within one dataset a synonym may not equal another member's name, label or synonym.
descriptionstring | Record<string, string>optionalBusiness definition of this measure in plain language — one or two sentences on what it is and when to use it (e.g. "已赢单金额合计,按成交日期归月;不含报价中与已丢单"). Never a prompt or an instruction to an AI. At most 500 characters per locale.

Nested Shape: Dataset.protection

PropertyTypeRequiredDescription
lockEnum<'none' | 'no-overlay' | 'no-delete' | 'full'>✅Lock policy — none | no-overlay | no-delete | full.
reasonstring✅User-visible reason shown when the lock blocks an action.
docsUrlstringoptionalOptional URL the Studio banner links to for more context.

Nested Shape: Dataset.overrides

PropertyTypeRequiredDescription
packagestring✅The base package id whose same-named item this item replaces whole (e.g. "com.acme.crm"). Only an item of the base's paired "<base>.custom" package declares an override.
basedOnstring✅Recorded, never a gate: the base package's manifest.version this override was taken from (e.g. "3.2.0"), not a history version of the item. Nothing is refused, merged or rebased on it; it tells a person re-basing the override where it started. One reader, as advice: a base's upgrade plan lists an override whose basedOn is not the installed base version as stale, beside each override whose base item the upgrade changes (ADR-0146 D2, as amended).

DatasetDimension

Properties

PropertyTypeRequiredDescription
namestring✅Dimension name — referenced by presentations
labelstring | Record<string, string>optionalDisplay label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time
fieldstring✅Base field, or relationship[.relationship].field path. A column reference, never a SQL expression.
typeEnum<'string' | 'number' | 'date' | 'boolean' | 'lookup'>optional
dateGranularityEnum<'day' | 'week' | 'month' | 'quarter' | 'year'>optional
nullLabelstring | Record<string, string>optionalLabel for the bucket of rows whose value for this dimension is null (e.g. "System" on a user axis). Display copy only: grouping is unchanged. When absent, consumers fall back to their own default label for that bucket.
synonymsstring[]optionalWords a person uses for this member in a question (e.g. ["收入", "销售额", "revenue"]), matched after normalization and never rendered. Each trimmed, non-empty, at most 60 characters; at most 20. Within one dataset a synonym may not equal another member's name, label or synonym.
descriptionstring | Record<string, string>optionalBusiness definition of this dimension in plain language — one or two sentences on what it is and when to use it (e.g. "商机当前所处的销售阶段,从初步接洽到赢单或丢单"). Never a prompt or an instruction to an AI. At most 500 characters per locale.

DatasetDurationUnit

Allowed Values

  • seconds
  • minutes
  • hours
  • days

DatasetMeasure

Properties

PropertyTypeRequiredDescription
namestring✅Measure name — e.g. "revenue"; defined once
labelstring | Record<string, string>optionalDisplay label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time
aggregateEnum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'>optionalAggregation (sum/avg/count/...); omit when derived is set
fieldstringoptionalAggregated field: a base field, a relationship path, or "" for a count; optional for count(). Never a SQL expression.
filteranyoptional
formatstringoptionalNumeral pattern for a NUMERIC measure — grouping, decimals, percent; e.g. "0,0.00", "0.0%". An amount takes its symbol from currency, not from a "$" in the pattern. A DATE-valued measure never reads a date pattern: "YYYY-MM-DD" renders that arm's default face. A date or datetime value reads format as a display style — short or relative, honoured on both.
currencystringoptionalDisplay currency code (ISO 4217)
polarityEnum<'higher' | 'lower' | 'neutral'>optionalWhich direction of change is good news: higher (rise green, fall red), lower (fall green, rise red) or neutral (no good/bad colour). Colours a period-over-period delta; undeclared keeps rise green, fall red.
derived{ op: Enum<'ratio' | 'sum' | 'difference' | 'product'>; of: string[] }optional
duration{ from: string; to: string; unit: Enum<'seconds' | 'minutes' | 'hours' | 'days'> }optionalTime between two datetime columns of each record ({ from, to, unit }), reduced by aggregate (avg / min / max / sum). Records with either instant null are excluded. Replaces field.
synonymsstring[]optionalWords a person uses for this member in a question (e.g. ["收入", "销售额", "revenue"]), matched after normalization and never rendered. Each trimmed, non-empty, at most 60 characters; at most 20. Within one dataset a synonym may not equal another member's name, label or synonym.
descriptionstring | Record<string, string>optionalBusiness definition of this measure in plain language — one or two sentences on what it is and when to use it (e.g. "已赢单金额合计,按成交日期归月;不含报价中与已丢单"). Never a prompt or an instruction to an AI. At most 500 characters per locale.

Nested Shape: DatasetMeasure.duration

PropertyTypeRequiredDescription
fromstring✅The earlier instant: a datetime field of the dataset's own object, by its bare name.
tostring✅The later instant: a datetime field of the dataset's own object, by its bare name.
unitEnum<'seconds' | 'minutes' | 'hours' | 'days'>✅Unit of the result: the measure answers a number of these (1.5 with "days" is a day and a half).

DatasetMeasureDuration

Properties

PropertyTypeRequiredDescription
fromstring✅The earlier instant: a datetime field of the dataset's own object, by its bare name.
tostring✅The later instant: a datetime field of the dataset's own object, by its bare name.
unitEnum<'seconds' | 'minutes' | 'hours' | 'days'>✅Unit of the result: the measure answers a number of these (1.5 with "days" is a day and a half).

DatasetMeasurePolarity

Allowed Values

  • higher
  • lower
  • neutral

DatasetMemberSynonyms

Words a person uses for this member in a question (e.g. ["收入", "销售额", "revenue"]), matched after normalization and never rendered. Each trimmed, non-empty, at most 60 characters; at most 20. Within one dataset a synonym may not equal another member's name, label or synonym.

Type: string[]


DerivedMeasureOp

Allowed Values

  • ratio
  • sum
  • difference
  • product

On this page