ADL 0.6.0 reference · Review draft 1 · November 14, 2026.
Contents · Source map · Evidence
The 0.6 edition note
Declared queries are part of this edition through retained §38.8. Earlier query-design notes calling them an unimplemented prototype are historical. The fresh example validates at 0.5.2 and 0.6.0 and is rejected at 0.5.1 with ADL_QUERY_VERSION.
A declared aggregate query has row authority and field authority. An unreadable field does not automatically become available for aggregation; the separate aggregate permission and its owning rule matter. A grouped result is not the same as a paginated list. Exactness and store behavior require runtime evidence on the named adapter.
Resource policies and ranked handling do not imply unrestricted query compatibility. The policy profile refuses paths where its row policy cannot be applied, and classification propagation does not cover analytics generally. The new query fixture establishes grammar/version admission, not query-result correctness or PostgreSQL decimal behavior.
Retained reference detail
The numbered sections below are carried from 38-reports-views-and-dashboards.md. Their original baseline and evidence remain attached to the source. Statements about “current” or “checked” behavior in this retained text refer to those original observations unless the edition note explicitly updates them. This is a consolidated draft, not a claim of complete re-verification.
38.1 Scope and three declaration kinds
Views, reports, and dashboards are read-only domain declarations that expose analytical results. A view selects records and adds column metadata or computed cells. A report assembles metric and table sections. A dashboard computes a named set of widgets with layout and refresh metadata.
This chapter owns those declarations and output shapes. ADL 18 owns expressions; ADL 16 owns resource scopes; ADL 21 owns ordinary resource/field permissions; ADL 27 owns general resource query parameters. A view is a separate endpoint, not a named scope applied to resource listing.
The inherited chapter (v0.5.0, retired)
is the baseline, but its simplified resource/top-level metric examples do not
match the complete current builder. The executable examples use views.*.source
and reports.*.sections. Runtime observations are dated evidence, not implicit
changes to the inherited contract.
38.2 Views: declarations and result shape
domain.views is a mapping of names to definitions. A view reads source,
optional filter and sort strings, defaultLimit (default 50), a permission
array, and column definitions:
# Domain fragment; analytics.yaml supplies Ticket and the remaining declarations.
views:
tickets:
source: Ticket
sort: amount desc
defaultLimit: 1
permissions: [reader]
columns:
- field: title
- field: amount
format: money
- name: double
computed: amount * 2
format: money
Each column can specify field, name, label, computed, format, and
highlight. Name defaults to the field; label defaults to the name. A computed
column is evaluated in declaration order and stored in the working row, so a
later column can refer to an earlier computed value. A failed computed expression
produces an error cell rather than a silent null.
The view response contains view, columns, items, totalCount, limit, and
offset. Column metadata has name, label, and format. The current row builder
starts with every source field and adds computed fields; columns does not
project away unlisted fields. The checked response includes secret, which was
not selected as a column, and includes stored values as strings. This is a
material difference from interpreting a view as a restricted field projection.
format on a view column is metadata. The checked amount cell remains the
string "30"; its money label is in columns. It is not converted to currency
text or always wrapped as {value, _format}. Reports use the latter wrapper in
a separate path (§38.4).
Highlights evaluate numeric threshold strings such as < 30 or >= 90, in
red, yellow, then green order. A matching state is returned in _highlights.
The engine does not render a color or validate a complete presentation design.
An unparseable numeric cell can fall back to zero for threshold evaluation.
38.3 Selection, ordering, pagination, and query cost
The native view engine issues an unbounded SELECT * on the source table,
converts database nulls, then applies the AEL filter in memory. It sorts the
filtered rows before slicing the requested page. Thus limit: 1 bounds the
returned page, not the database scan or materialized working set.
Declared sort supports field asc, field desc, leading -field, and comma
separated keys. Request sort can override it. An ID tie-breaker supplies a total
order even when no sort is declared. Missing values sort last. Source numeric
strings receive numeric ordering in the checked helper/tests, rather than
lexical ordering such as 10 before 2.
Request pagination consumes integer values for limit, page, and offset.
Explicit limit is clamped to 1–1000; a positive declaration default is used when
not overridden. Page takes precedence over offset. A view with a missing source
name returns VIEW_INVALID; an unavailable named source in production returns
HTTP 500 with ANALYTICS_SOURCE_UNAVAILABLE. The earlier recorded empty-success
behavior predates #1672. The legacy-source.yaml fixture demonstrates
that resource: Ticket is not the builder’s source: Ticket key.
AEL filtering and computed columns have bare-field and $record/$this
contexts. Current view execution does not bind request parameters into that
filter. The parameter-view.yaml example supplies floor but the filter
amount >= $params.floor does not behave as a parameterized view contract.
Report parameter support must not be inferred for views merely because both
use AEL.
These direct source reads bypass the resource list handler’s scopes, soft-delete exclusion, and field filtering. The checked soft-delete scenario still exposes the deleted row through a view and through a raw dashboard widget. AEL aggregate queries can use the installed domain query handler instead; direct rows and aggregate values need not have identical visibility or value conversion. No production-volume benchmark or database query-plan claim is made here.
38.4 Reports, parameters, and sections
Declare reports under domain.reports. The current structure has optional
description, permissions, header, footer, parameters, and sections.
Header supports title/subtitle; footer supports text/confidentiality.
# Report fragment from the checked analytics example.
reports:
overview:
permissions: [reader]
parameters:
- name: floor
type: integer
header:
title: At least {$params.floor}
sections:
- name: summary
type: metrics
metrics:
- label: Count
value: count(Ticket, amount >= $params.floor)
- name: rows
type: table
view: tickets
totals: [amount, double]
A parameter declares name, type (default string), default, label,
optional (default false), and enum. Current resolution checks presence and
uses defaults; it does not fully enforce type or enum membership. Supplied values
are copied as-is. $today and $currentYear have special default handling;
other nonempty defaults remain strings. Missing nonoptional values without a
default produce HTTP 400 MALFORMED_REQUEST.
The response contains report identity, rendered header/footer text, resolved
parameters, sections, and a generation timestamp. Header/footer interpolation
recognizes {$params.name}, {$now}, {$date}, and {$actor.name}.
A metrics section has an array of {label, value, format} entries. value is an
AEL expression, with parameters under $params and the domain query service
installed. Bare resource targets and quoted full addresses follow ADL 18; a
quoted bare resource name is not a full ADL address. Each failed metric becomes
an error value. A nonempty format wraps the result as {value, _format}; that is
a tag for client rendering, not formatted currency/date output.
A table section names a view, optional totals, emptyMessage, and groupBy.
It executes the view with the requesting principal, so the view’s permission
check still applies. A missing or forbidden view becomes a section error inside
an otherwise successful report response. The report does not become an alternate
authorization grant for that view.
The implementation removes page when invoking a table section but retains
other request pagination and the view’s default limit. It therefore does not
necessarily load all rows. Totals sum the returned numeric JSON cells, including
numeric values inside wrappers. Database strings are not included by this sum.
The example reports totalCount: 3, returns one row, totals its computed
double as 60, and totals raw string amount as 0. groupBy is retained but
this path does not build grouped table sections. These are output limitations,
not a dependable whole-dataset accounting contract.
38.5 Dashboards and refresh
A dashboard has permissions, refresh (default 5m), layout.columns
(default 3), and a widgets array. Widgets have a name, type (default counter),
label, format, icon, optional target, and position (row, col, span, each
defaulting to 1). Their query mapping can include value, resource, filter,
groupBy, metric, limit (default 10), and history.
| Widget path | Current output |
|---|---|
counter, gauge, scorecard | Evaluated query.value, threshold state, and metadata |
breakdown | Source rows grouped by query.groupBy, counted or summed using metric: sum:<field> |
Other types, including table, timeSeries, timeline | Raw source rows up to query.limit |
A breakdown can attach colors from colorMap. The other raw-row path does not
implement time bucketing or history semantics merely because the type or
query.history suggests them. Unknown widget type names also reach that fallback.
Widget format is metadata; the scalar path does not universally call the
report’s format wrapper.
Dashboard results contain named widgets, layout columns, refresh metadata,
computation time, and cached. Production dashboards recompute caller-bound
results on every request (cached: false), including when refresh is positive
(#1672). A caller-specific key alone would still retain rows after a membership
or ownership change. Individual widget requests also compute freshly. refresh
remains refresh metadata; it does not authorize reuse of protected source rows.
The standalone engine without a caller-bound query factory retains its TTL cache.
The original recorded examples predate #1672 and compare cached and uncached results around a soft delete; their cache-hit observation is historical. The raw-row widget still includes the deleted record when no row condition excludes it, demonstrating why refresh and access/selection correctness are separate concerns. Layout metadata is not a server-rendered dashboard or a standardized future UI vocabulary.
38.6 Authorization and generated operations
Each declaration’s own permission array governs its use and its catalog entry.
An empty array means admin/administrator only. * permits anonymous access;
authenticated requires a user identity; concrete names require an authenticated
matching role. A nonempty list is not an automatic admin bypass. The checked
public-view case exercises anonymous access explicitly.
The source resource’s permissions.readCondition bounds every analytics source
query (#1672), including relational sharedVia rules from §21.7.3. The SQL
predicate is bound to the caller before view pagination, report aggregation,
widget grouping or raw-row limits. AEL targets in metrics, computed columns
and filters follow the same rule, including imported targets. A failed source
or policy lookup is an error; it never falls back to an unrestricted query.
The analytical declaration still governs admission independently of the source
resource’s list/get role grants. Source field confidentiality is a separate
contract (#1372); this row-security change does not claim to close it. The
original example with an unlisted secret field records that earlier boundary,
not permission to bypass a source read condition.
All paths below are under /api/v1/{domain}:
| Method | Suffix | Purpose |
|---|---|---|
| GET | /views, /reports, /dashboards | Permission-filtered catalogs |
| GET | /views/{name} | View result |
| GET | /reports/{name} | Report result |
| GET | /dashboards/{name} | Dashboard result |
| GET | /dashboards/{name}/widgets/{widget} | One widget result |
Missing names use VALIDATION_ERROR; unknown definitions use NOT_FOUND;
permission failures use FORBIDDEN. A report or dashboard can still return HTTP
200 with errors in individual sections/values. ADL 31
owns the envelope, and ADL 33 owns the complete
registered API inventory. These are generated result endpoints, not new writes
to resource schemas.
38.7 Export, provenance, and verification
Native model export refuses a domain containing analytics declarations as a lossy unsupported projection. A registry reload with retained source restores them; forced source-free restoration cannot recover the example model. The independent modeller admits the main analytical declarations and separately reports a missing source or the legacy view key. Its admission is not evidence for native row visibility, pagination, aggregation, or cache behavior.
The evidence record links the parser, models, query engine, registrars, and focused tests directly. The executable artifact is the recorded JSON response sequence over disposable SQLite records. It includes page contents, metric errors, totals, filtered catalogs, cache results, and stored rows. No browser rendering, charting library, cross-provider performance test, or implicit enforcement of future UI declarations is claimed.
38.8 Declared queries (ADL 0.5.2)
A declared query is a named total over one resource: grouped, complete,
and scoped to the caller. It needs adl: "0.5.2" (ADL 6 §6.3) and is served
by kalos_adl 0.121.0 and later.
adl: "0.5.2"
domain:
queries:
forecast:
resource: Opportunity
permissions: [sales_member, admin]
input:
quarter: {type: string}
filter: "stage != 'lost' && ($input.quarter == null || quarter == $input.quarter)"
exclude:
reason: "amount == null ? 'no_amount' : null"
groupBy: [currency, stage]
select:
count: "count()"
total: "sum(amount) ?? 0"
weighted: "round(sum(amount * probability / 100), 2)"
GET /api/v1/{domain}/{collection}/queries/{name}?quarter=2026-Q4
→ {"groups": [{"currency": "USD", "stage": "proposal", "count": 4,
"total": "1200.0000", "weighted": "480.00"}],
"excluded": {"no_amount": 1}}
| Key | Meaning |
|---|---|
resource | Required. A resource of this domain |
permissions | Roles that may run the query. Empty means admin only (§38.6) |
input | Named inputs, each {type: string | integer | decimal | money | boolean | date}. An input the request leaves out is null |
filter | A condition on one row |
exclude.reason | A value worked out from one row. Null keeps the row; any text sets it aside and is counted under that text in excluded |
groupBy | Fields of the resource. Without it the answer is one group |
select | Required. Names mapped to expressions; totals (count, sum, avg, min, max) are allowed here only |
exact | false accepts an inexact store (below). Default true |
Rows. A query reads the rows list would show the caller: the consent
gate, the relationship read policy or the owner scope, and the default scope
(soft-deleted rows are left out). It has no paging and no row cap.
Fields. A query that names a field the caller may not read, in filter,
exclude, groupBy or select, is refused with 403 FIELD_NOT_READABLE.
Inputs. Each input is a bound parameter. A value of the wrong type, or a
request parameter that is not a declared input, is 400 INVALID_QUERY.
Values. A count and a total of integers are JSON numbers. A total that involves a decimal, money, float or percentage field, a division or an average is a string, as the store returned it, so no digit is lost.
The expressions a query accepts. A query has no row-by-row path, so an expression outside this set is refused when the document is submitted:
| Accepted | Notes |
|---|---|
literals, fields of the resource, $input.name | every value is bound |
== != < <= > >= | != counts a null as different, as AEL does. Ordering is for numbers and dates |
== null, != null, &&, ||, !, in [...] | ! of a comparison with a null is true, as in AEL |
a ?? b, c ? a : b | |
+ - * / | / is real division. A zero divisor is 422 ADL_QUERY_DIVISION_BY_ZERO on both stores |
round(x), round(x, n), abs, lower, upper, today(), now() | n is written out, 0 to 12 |
count(), count(cond), sum, avg, min, max | in select only, not nested. Over no rows count and sum are 0; the others are null |
Refused, each with its reason in the message: a related field
(account.region), $record and $user, contains/startsWith/endsWith,
date arithmetic, lookup/exists/query/findOne/findMany, hasRole,
%, ordering on text, and a bare field in select that is not in groupBy.
Activation errors (all 422):
| Code | When |
|---|---|
ADL_QUERY_VERSION | queries: in a document below 0.5.2 |
ADL_QUERY_NOT_COMPILABLE | an expression outside the accepted set, or a malformed query |
ADL_QUERY_UNKNOWN_FIELD | a resource or field that does not exist |
ADL_QUERY_INEXACT_STORE | on SQLite, a decimal total without exact: false |
SQLite. SQLite keeps a decimal as a binary fraction, so it cannot add
decimals exactly. A query whose select gives a decimal is refused there
unless it declares exact: false; the response then carries "exact": false.
Counts and integer totals need no flag.
Not in this edition: ordering or limiting the groups.
Verification: python3 tools/repro/adl/77_declared_queries.py and
--postgres.
38.8.1 Totals of a field the caller cannot read: aggregate:
A field’s read: list hides it from a role entirely, its totals included. An
aggregate: grant on the field permission lets named roles total the
field in a declared query without reading it (kalos_adl 0.122.0 and later;
needs adl: "0.5.2").
permissions:
fields:
amount:
read: [sales_member, admin]
aggregate:
roles: [sales_viewer]
dimensions: [currency, stage]
minGroupSize: 3 # default 3; 2 or more
The grant defines one fixed table of cells for the field: one cell per combination of its dimensions. Every query a granted role can run over the field answers some of those same cells, so two answers cannot be subtracted to find one row’s value. That is why the dimensions are on the field and not on the query.
A grant is refused (ADL_AGGREGATE_GRANT_INVALID) when the field is not a
number or has no read: list, when minGroupSize is below 2, or when a
dimension is not a field, is the granted field itself, is the primary key or
unique, has its own read: list, or has no closed set of values. A
dimension is a boolean or a field with an enum.
A query is held to the grant when its permissions admit a role the
grant names and that role is not in the field’s read: list (* and
authenticated admit every role). Such a query is refused at submit
(ADL_AGGREGATE_QUERY_LEAKS) unless all of these hold:
| Rule | Why |
|---|---|
groupBy is exactly the grant’s dimensions | a coarser or finer table can be subtracted from this one |
filter and exclude.reason name only dimensions, with ==, in, &&, || | a filter must select whole cells |
no input | an input changes which rows are totalled |
the field appears only as sum(field) or avg(field) | min and max show one row; a count condition asks about single values; several weighted totals can be solved for them |
no exact: false |
A query only readers of the field can run is not held to any of this.
At run time a caller who cannot read the field and holds a granted role
gets the cells. A cell with fewer rows than minGroupSize keeps its counts;
every select that names the field is null there, and the group carries
"suppressed": true. A caller who reads the field gets the same query with
nothing suppressed. A caller with neither gets 403 FIELD_NOT_READABLE.
The grant opens the query path only. The field stays hidden in list, get,
views, filters and count.
On SQLite a grant is usable on an integer field only: a decimal total there
needs exact: false, which a granted field may not have.
Not in this edition: request-time filters on a dimension (a granted caller runs the query as declared).
Verification: python3 tools/repro/adl/78_aggregate_grant.py and
--postgres.