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
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Dataset unique name |
| label | string | Record<string, string> | ✅ | Dataset label |
| description | string | Record<string, string> | optional | Display label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time |
| object | string | ✅ | Base object name |
| include | string[] | optional | Relationship names/paths to join (derived from object graph; max 3 hops) |
| filter | any | optional | Intrinsic 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 } | optional | Package author protection block — lock policy for this dataset. |
| _lock | Enum<'none' | 'no-overlay' | 'no-delete' | 'full'> | optional | Item-level lock — controls overlay & delete (ADR-0010). |
| _lockReason | string | optional | Human-readable reason shown when a write is refused by _lock. |
| _lockSource | Enum<'artifact' | 'package' | 'env-forced'> | optional | Layer that set _lock (artifact | package | env-forced). |
| _provenance | Enum<'package' | 'org' | 'env-forced' | 'platform'> | optional | Origin of the item (package | org | env-forced | platform). |
| _packageId | string | optional | Owning package machine id. |
| _packageVersion | string | optional | Owning package version. |
| _lockDocsUrl | string | optional | Optional documentation link surfaced next to _lockReason. |
| overrides | { package: string; basedOn: string } | optional | Override 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]
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Dimension name — referenced by presentations |
| label | string | Record<string, string> | optional | Display label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time |
| field | string | ✅ | Base field, or relationship[.relationship].field path. A column reference, never a SQL expression. |
| type | Enum<'string' | 'number' | 'date' | 'boolean' | 'lookup'> | optional | |
| dateGranularity | Enum<'day' | 'week' | 'month' | 'quarter' | 'year'> | optional | |
| nullLabel | string | Record<string, string> | optional | Label 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. |
| synonyms | string[] | optional | 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. |
| description | string | Record<string, string> | optional | Business 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]
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Measure name — e.g. "revenue"; defined once |
| label | string | Record<string, string> | optional | Display label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time |
| aggregate | Enum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'> | optional | Aggregation (sum/avg/count/...); omit when derived is set |
| field | string | optional | Aggregated field: a base field, a relationship path, or "" for a count; optional for count(). Never a SQL expression. |
| filter | any | optional | |
| format | string | optional | Numeral 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. |
| currency | string | optional | Display currency code (ISO 4217) |
| polarity | Enum<'higher' | 'lower' | 'neutral'> | optional | Which 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'> } | optional | Time 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. |
| synonyms | string[] | optional | 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. |
| description | string | Record<string, string> | optional | Business 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
| Property | Type | Required | Description |
|---|---|---|---|
| lock | Enum<'none' | 'no-overlay' | 'no-delete' | 'full'> | ✅ | Lock policy — none | no-overlay | no-delete | full. |
| reason | string | ✅ | User-visible reason shown when the lock blocks an action. |
| docsUrl | string | optional | Optional URL the Studio banner links to for more context. |
Nested Shape: Dataset.overrides
| Property | Type | Required | Description |
|---|---|---|---|
| package | string | ✅ | 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. |
| basedOn | string | ✅ | 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
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Dimension name — referenced by presentations |
| label | string | Record<string, string> | optional | Display label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time |
| field | string | ✅ | Base field, or relationship[.relationship].field path. A column reference, never a SQL expression. |
| type | Enum<'string' | 'number' | 'date' | 'boolean' | 'lookup'> | optional | |
| dateGranularity | Enum<'day' | 'week' | 'month' | 'quarter' | 'year'> | optional | |
| nullLabel | string | Record<string, string> | optional | Label 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. |
| synonyms | string[] | optional | 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. |
| description | string | Record<string, string> | optional | Business 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
secondsminuteshoursdays
DatasetMeasure
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Measure name — e.g. "revenue"; defined once |
| label | string | Record<string, string> | optional | Display label — the default-language string, or an inline locale map ({ en, "zh-CN" }) resolved at render time |
| aggregate | Enum<'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct'> | optional | Aggregation (sum/avg/count/...); omit when derived is set |
| field | string | optional | Aggregated field: a base field, a relationship path, or "" for a count; optional for count(). Never a SQL expression. |
| filter | any | optional | |
| format | string | optional | Numeral 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. |
| currency | string | optional | Display currency code (ISO 4217) |
| polarity | Enum<'higher' | 'lower' | 'neutral'> | optional | Which 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'> } | optional | Time 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. |
| synonyms | string[] | optional | 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. |
| description | string | Record<string, string> | optional | Business 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
| Property | Type | Required | Description |
|---|---|---|---|
| from | string | ✅ | The earlier instant: a datetime field of the dataset's own object, by its bare name. |
| to | string | ✅ | The later instant: a datetime field of the dataset's own object, by its bare name. |
| unit | Enum<'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
| Property | Type | Required | Description |
|---|---|---|---|
| from | string | ✅ | The earlier instant: a datetime field of the dataset's own object, by its bare name. |
| to | string | ✅ | The later instant: a datetime field of the dataset's own object, by its bare name. |
| unit | Enum<'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
higherlowerneutral
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
ratiosumdifferenceproduct
Dashboard
Dashboard schemas of the ObjectStack UI Protocol: Dashboard, DashboardHeader and 8 more — each property with its type, default and a TypeScript example.
Expression Bindable Text Keys
Expression-bindable text keys — the CLOSED vocabulary of top-level text keys a SchemaRenderer evaluation memo evaluates.