A hosted CanopyX data grid never holds the whole dataset. It sends typed queries as the reader scrolls, sorts, searches, filters, opens a value list or exports, and expects revisioned documents back (see Flat Grid Documents). These two packages answer those queries from .NET:
CanopyX.Data(net472,netstandard2.0,net10.0) parses and validates every request against a column allow-list and safety limits, executes it, and writes thegridPage,gridFacetPage,gridSummary,gridRangePageandgridCommitResultdocuments the browser runtime accepts. It runs requests over anyIQueryable<T>(EF Core, LINQ to objects, any LINQ provider), over a provider you write for another back end, streams exports, serves grouping with up to four levels, saves edited rows through a writer you choose (Saving edits), and loads one record's details for the record panel on demand (Record details). Calendar and timeline views read the records that overlap a date window through range queries (Range queries).CanopyX.AspNetCore(net10.0) maps it to minimal-API endpoints and writes the small browser script that connects the grid to them.
browser grid ── gridQuery / gridFacetQuery / export request ──▶ endpoint ──▶ CanopyRemoteHandler
│ parse + allow-list + limits + revision
▼
ICanopyDataProvider
(CanopyQueryableProvider<T> │ your SQL provider │ CanopyInMemoryProvider<T>)
browser grid ◀── gridPage / gridFacetPage / gridSummary / file ──────────────────┘
browser grid ── gridCommit ──▶ commit endpoint (write policy) ──▶ CanopyRemoteHandler
│ editable columns + values checked again
▼
ICanopyDataWriter (CanopyQueryableWriter<T> │ your writer)
browser grid ◀── gridCommitResult (saved │ error │ conflict per row, new revision) ┘
record panel ── gridRecordQuery ──▶ record endpoint ──▶ CanopyRemoteHandler
│ fields allowed + readable, revision, limits
▼
ICanopyRecordProvider (CanopyQueryableRecordProvider<T> │ your provider)
│ Where(key == id) on the grid's own query, children through it
record panel ◀── gridRecord (fields, cells, row │ one collection page) ┘
// 1. The grid definition the browser renders.
var view = new CanopyDataGridView("machines", "Machines") { Source = CanopyGridSource.HostedOffset(), PageSize = 200, Selection = CanopySelectionMode.Multiple };
view.Columns.Add(new CanopyColumn("name", "Machine") { Sortable = true });
view.Columns.Add(new CanopyColumn("site", "Site") { Sortable = true });
view.Columns.Add(new CanopyColumn("memory", "Memory (GB)") { Kind = CanopyColumnKind.Number, Sortable = true });
view.Columns.Add(new CanopyColumn("lastSeen", "Last seen") { Kind = CanopyColumnKind.DateTime, Sortable = true });
view.Columns.Add(new CanopyColumn("team", "Team") { Sortable = true });
view.Reporting = new CanopyGridReporting { HeaderFilters = true, FilterGroups = true };
view.Reporting.FacetColumns.Add("site");
// 2. The allow-list: protocol column ids mapped to expressions. Nothing else is reachable.
var map = new CanopyColumnMap<Machine>(view)
.Key(machine => machine.Id)
.Column("name", machine => machine.Name)
.Column("site", machine => machine.Site)
.Column("memory", machine => machine.MemoryGb)
// This store writes UTC whole milliseconds; its indexed timestamp already has the protocol's precision.
.Column("lastSeen", machine => machine.LastSeen, column => column.SortBy(machine => machine.LastSeen))
.Column("team", machine => machine.Team!.Name);
// 3. The endpoints. The query callback returns what this caller may see; authorization is required by default.
app.MapCanopyRemote("/api/machines", http => http.RequestServices.GetRequiredService<FleetDb>().Machines, map, options => {
options.Query.Revision = token => store.GetRevisionAsync(token);
options.AuthorizationPolicy = "Inventory.Read";
});
// 4. The page: the grid plus the script that points its source at the endpoints.
app.MapGet("/machines", () => Results.Content(
view.ToHtml(new CanopyHtmlOptions { Title = "Machines", HeadHtml = CanopyRemoteScript.Element(map.Schema, "/api/machines") }),
"text/html"));For a page with a nonce-based Content Security Policy, pass the response's nonce to both CanopyHtmlOptions.Nonce
and CanopyRemoteScript.ElementWithNonce(map.Schema, "/api/machines", nonce). The configuration script must run
before the grid mounts. See Content Security Policy.
The default executor already counts through EF Core's asynchronous query provider and enumerates EF queries asynchronously, without a dependency on EF Core. An executor of your own uses other operators, for example:
sealed class EfCoreExecutor : CanopyQueryExecutor {
public override Task<int> CountAsync<TSource>(IQueryable<TSource> query, CancellationToken token) => query.CountAsync(token);
}Pages that are not rendered by .NET configure the same source by hand; this is what CanopyRemoteScript writes:
const post = (path, body, signal) => fetch("/api/machines" + path, { method: "POST", signal, credentials: "same-origin",
headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })
.then(async response => { if (!response.ok) throw new Error((await response.json()).message); return response; });
CanopyX.configure("machines", { source: {
query: (query, { signal }) => post("/query", query, signal).then(r => r.json()),
facet: (request, { signal }) => post("/facet", request, signal).then(r => r.json()),
summary: (query, { signal }) => post("/summary", query, signal).then(r => r.json()),
// Views with editable columns save through the commit endpoint.
commit: (batch, { signal }) => post("/commit", batch, signal).then(r => r.json()),
// Views whose record panel loads details on demand (CanopyRemoteScript also answers null for a 404 recordNotFound).
record: (request, { signal }) => post("/record", request, signal).then(r => r.json())
} });
document.addEventListener("canopyx:commit", event => {
const grid = event.target.canopyx, result = event.detail, revision = result && result.revision;
if (!grid || grid.view.id !== "machines") return;
if (revision ? revision !== grid.getQuery()?.revision : result && result.saved > 0)
grid.reload().catch(() => {}); // The grid displays the reload error and calls onError.
}, true); // grid events do not bubble, so listen in the capture phaseThe fleet inventory sample runs this end to end over 100,000 SQLite rows.
Suppose a page renders a table from a list your controller loads in full. To move paging, sorting, searching, filtering and export to the server without changing what readers see:
- Declare the grid once. Build a
CanopyDataGridViewwithCanopyGridSource.HostedOffset()and the same columns. Mark the columns readers may sort (Sortable), list the columns quick search reads (SearchColumns), and opt columns into value lists (Reporting.FacetColumns). This definition is the contract the browser enforces. - Keep your query, drop the
ToList(). TheIQueryable<T>your controller already builds (including its authorizationWhere) becomes the callback ofMapCanopyRemote. The adapter composes search, filters, ordering and the window on top and asks the database only for one page. - Map columns explicitly. One
Column(id, expression)per grid column. Columns you do not map cannot be sorted, filtered, searched or exported, even if a request names them. - Give the data a revision. Return a value that changes when the data changes (a row version, a change counter, an import timestamp). Clients that hold an older revision reload instead of mixing snapshots.
- Replace the page's data with the script. Render the grid with
ToHtml/ToHtmlFragmentand addCanopyRemoteScript.Element(...). The grid's Export menu gains a server CSV entry that downloads every matching row. - Index for the common orders. The default order is the key; add indexes for frequently sorted or filtered columns (see Performance).
- Let readers edit (optional). Mark the columns readers may change
Editable(with anEditorandValidation), map a writer and name the policy that may write (see Saving edits). The server repeats the checks, writes nothing else, and answers conflicts when another user changed a row first.
MapCanopyRemote(pattern, …) returns a RouteGroupBuilder serving:
| Route | Request | Response |
|---|---|---|
POST {pattern}/query |
gridQuery document |
gridPage |
GET {pattern}/query (with AllowGetQueries) |
?q=<gridQuery JSON>, or offset, limit, search, searchMode, revision, sort (name, name:desc, -name, repeatable or comma separated), filters (JSON array), filterGroup (JSON object) |
gridPage |
POST {pattern}/facet |
gridFacetQuery document |
gridFacetPage |
POST {pattern}/summary |
gridQuery with its accepted revision |
gridSummary |
POST {pattern}/range |
gridRangeQuery document |
gridRangePage (400 unsupported when the provider has no range capability) |
POST {pattern}/export/{format} |
the grid's export request (scope, query, revision, selection, querySelection, columns, values, …) |
the file, streamed |
GET {pattern}/view |
the grid definition document |
|
POST {pattern}/commit (with options.UseQueryableWriter or options.Writer) |
gridCommit document |
gridCommitResult |
POST {pattern}/record (with a record map or options.Records) |
gridRecordQuery document |
gridRecord (404 recordNotFound when the caller has no such record) |
The GET form is off by default because query strings reach access logs, proxies and referrers. POST bodies must be application/json (or +json); other content types get 415, which also means cross-origin pages
cannot post without passing a CORS preflight. Responses carry Cache-Control: no-store and X-Content-Type-Options: nosniff.
Every handler observes HttpContext.RequestAborted; the token flows into the provider and the database command.
Factories run per request (provider, options.Writer, options.Records, and the store of UseQueryableWriter): the
endpoint disposes an instance that is IDisposable or IAsyncDisposable when the response completes, so return a new
instance each time rather than a shared disposable one.
Outside ASP.NET Core, use CanopyRemoteHandler directly: QueryAsync(json), FacetAsync(json), SummaryAsync(json), RangeAsync(json),
PrepareExportAsync(json, format), with a writer (new CanopyRemoteHandler(schema, provider, options, writer))
CommitAsync(json), and with a record provider (new CanopyRemoteHandler(schema, provider, options, writer, records))
RecordAsync(json, canRead) return documents (or an export job) and throw CanopyRequestException for client errors.
CanopyRequestParser exposes the parsing step on its own, and CanopyRequestParser.FromQuery(CanopyGridQuery, schema)
validates a typed C# query with the same rules.
CanopyColumnMap<T> binds each protocol column id to an expression. Every mapped id must be declared by the view, with a
kind that fits the expression type:
| Column kind | Expression types | Wire value |
|---|---|---|
Text |
string, bool, enumerations |
text; booleans stay JSON booleans; enumerations are their [EnumMember(Value = …)] names, else their member names |
Number |
byte … long, float, double, decimal |
number (keep magnitudes within ±2^53−1) |
DateTime |
DateTime (stored as UTC), DateTimeOffset, DateOnly (.NET 10 asset, midnight UTC) |
ISO 8601 UTC |
Other types throw when you map them; project them to text (x => x.Id.ToString()). Navigation chains (x => x.Team!.Name)
are fine: EF Core turns them into joins, and in-memory queries are rewritten so a missing reference yields a missing value.
Per-column options (.Column(id, expr, column => column…)):
| Option | Effect |
|---|---|
SortBy(x => key) |
Sorts by another expression, for example a sortable code beside a display name. |
SearchBy(x => text) |
Quick search reads this text instead of the value, for example a joined alias list. |
Cell(value => new CanopyCell(value) { Text = …, Tone = … }) |
Formats the written cell (display text, tone, badges, tooltip). Keep Value raw. |
NotNull() |
Declares the value never null, so sorting needs no missing-values-last key and can use an index. The .NET 10 asset detects non-nullable reference annotations automatically. |
Filterable(false) |
The column can be read and sorted but not filtered. |
Key(x => x.Id) maps the stable record identity: row ids are its invariant text, selected exports look records up by it,
and it is the final sort key. DecorateRows(row => …) adjusts every written row (a row tone or class). The map freezes when
its Schema is first used. Declared view columns that are not mapped remain display-only.
The schema captures its column rules and advertised view at construction. Later changes to the authoring view or copies
returned by the column descriptors do not change the endpoint contract; create a new map/schema to publish a new definition.
| Capability | Wire | Status |
|---|---|---|
| Paging with total and matching counts | gridQuery → gridPage |
Full. offset/limit (1–10,000, capped by MaxPageSize), exact total and matched, window filled exactly. |
| Multi-column sort | sort[] |
Full. Missing values last in both directions; record key as final tie-breaker. Grouped views always lead with the grouping column. |
| Text ordering policies | reporting.ordering |
Categories translate to a rank expression; natural orders fall back to the store's text order in databases (exact in memory). Use SortBy for a natural key. |
| Column filters | filters[] |
Every operator: eq, ne, contains, startsWith, in (≤ 1,000), gt, ge, lt, le, isNull, isNotNull. |
| Filter builder | filterGroup |
Full nesting of all/any groups (8 levels, 64 groups, 64 predicates, lowered by limits). |
| Text comparison | Case-insensitive; see Text, numbers and dates. | |
| Quick search | search, searchMode |
Substring and all-words (quoted phrases) over the searchable columns. |
| Value lists | gridFacetQuery → gridFacetPage |
Full: case-insensitive buckets, counts over the complete query, value search, includeCurrentFilter: false projection, deterministic order, ≤ 200 buckets. |
| Grouping and aggregates | source.summary → gridSummary |
Full: a fixed grouping or up to four runtime groupBy levels (ordered by value or by an aggregate), nested groups with absolute ranges and keys unique across levels, count/distinctCount/sum/average/minimum/maximum; pages and exports read group by group. median/percentile in memory and in pivots only. Custom aggregates need a provider of your own (see Grouping levels). |
| Editing | gridCommit → gridCommitResult |
Full with a writer: editable columns only, values checked again with the view's validation, rows saved independently (or all or nothing), conflicts from original values, the new revision (see Saving edits). |
| Record details | gridRecordQuery → gridRecord |
Full with a record map or provider: record fields, columns' drawer values (cells), the row, collections that page with totals, timelines, change lists and links to related records (see Record details). |
| Range queries | gridRangeQuery → gridRangePage |
Full with the built-in providers: the records that overlap a UTC window after the query's criteria, recurring series, resource restriction, start order, matched and truncated (see Range queries). |
| Revisions | revision |
Full: a stale revision answers 409 staleRevision. |
| Exports | export request → file | Full: filtered, selected (ids or all-matching with exclusions) and all scopes, chosen columns, raw or display values, streamed. |
| Cursor navigation | gridCursorQuery |
Not served; rejected with unsupported. Offset navigation covers the protocol's hosted grids. |
Return a stable revision that changes when the dataset changes, and keep its lookup cheap. The handler reads it before
and after pages, facets and summaries, and checks exports after counting and around streaming. A provider that always
returns the same revision, such as live, does not provide a snapshot guarantee.
The protocol defines exact rules (see Filter semantics): text matching is
case-insensitive with a frozen folding table, a missing value fails every operator except isNull (including ne),
the empty string is a value, and dates compare as UTC instants at millisecond precision. CanopyInMemoryProvider<T> and
LINQ to objects implement them exactly (CanopyTextFolding is the shared folding). Databases get the closest translation:
- Text.
CanopyQueryOptions.TextComparison:Lowercase(the default for database providers) comparesLOWER(column)with the operand lowered invariantly (in memory the column is lowered invariantly too), which folds ASCII on SQLite and as far as the database'sLOWERgoes elsewhere;Collationleaves case to a case-insensitive column collation and keeps index seeks;Canonicalis the exact in-memory rule. Wildcard characters (%,_,[) in operands match literally: operands are parameters toContains/StartsWith, which the LINQ provider escapes. - Text order. Sorting uses the store's order. SQLite's default binary collation matches the protocol's ordinal order; a case-insensitive collation interleaves case. Grouping columns need a binary (case-sensitive) collation, because groups are exact values.
- Text value lists. After applying the effective query, facets search and merge text with the protocol's frozen folding
table before choosing their ordered prefix and counting distinct values. This includes Unicode spellings the database's
LOWERkeeps apart. Query filters and quick search still followTextComparisonabove. Use a binary collation when raw spelling matters: the adapter cannot recover spellings the store already merged into one group. - Numeric value lists. Search reads the protocol's binary64 number text, including exponent spelling and full precision. With a nonempty search, the adapter streams the database's ordered numeric groups, merges equivalent values, then counts matches and retains the requested prefix. Empty search keeps the database distinct count and limited prefix query.
- Enumerations and booleans evaluate every member against the exact rule and send the matching members as an
INtest, socontains "ux"on an enumeration becomesos IN (Linux). Enumerations sort by their raw text (an[EnumMember]value or the member name). Flags include unnamed combinations of up to eight declared bits (at most 256 values). Map larger flag domains to host-projected text. - Integers accept fractional operands as the protocol's binary64 comparison would:
gt 4.5becomes> 4,eq 4.5matches nothing, and out-of-range operands become always/never true. - Decimal numbers. Cells retain their exact decimal JSON text. Numeric operations use the binary64 value a browser reads from it: comparisons, default sorting, group keys, value lists, distinct counts and aggregate inputs round once with ties to even. In-memory fractional decimal conversion uses temporary exact integer arithmetic; database expressions use a translated binary64 cast. Consider the conversion and cast cost for large decimal datasets. On .NET Framework, request readers normalize exactly representable decimal JSON spellings before converting them; number texts outside decimal's precision or range retain the platform JSON parser's rounding.
- Dates become half-open bounds:
eq tist ≤ v < t + 1 ms,gt tisv ≥ t + 1 ms. Store UTC;DateTimevalues without a kind are read as UTC. In memory, aDateTimeof kindLocalis filtered, sorted and grouped as the UTC instant its cell shows; databases do not keep the kind, so a store that holds local times is compared as if they were UTC. In-memory ordering compares UTC milliseconds and breaks ties by record identity. Database ordering requires an explicitSortBymapping whose values have the same ordering and ties, usually an indexed UTC millisecond key. Mapping the timestamp itself is appropriate only when the store guarantees whole milliseconds. Without that mapping, date sorts returnunsupportedbefore querying or preparing an export. No client-side full-table sort is used. Date facets merge submillisecond values before counting and limiting the list. Exact totals scan and transfer the distinct raw date groups while retained memory stays proportional to the requested limit; consider this cost for high-cardinality columns. - Large numbers. Number columns follow the protocol's binary64 range: comparisons are bounded to ±2^53−1, so store larger identifiers as text.
- Search over numbers and dates. In memory, quick search reads every searchable column's raw text. Databases search
number columns through the store's text form only when the view lists them in
SearchColumns; this spelling can differ from protocol number text. UseSearchBywith a stored canonical text column when quick search needs the exact protocol spelling. Databases never search date columns without aSearchBytext mapping (there is no portable text form). Value-list search on a date column answersunsupported.
A view with a fixed Reporting.Grouping groups by one column the reader cannot change. A view with runtime grouping
(Reporting.GroupBy levels and/or Reporting.Groupable) carries the levels in every query as groupBy, at most four,
outermost first (data-protocol.md):
view.Reporting = new CanopyGridReporting { Groupable = true };
view.Reporting.Aggregates.Add(new CanopyGridAggregate("machines", "name", CanopyGridAggregateOperation.Count, "Machines"));
view.Reporting.Aggregates.Add(new CanopyGridAggregate("models", "model", CanopyGridAggregateOperation.DistinctCount, "Models"));
view.Reporting.GroupBy.Add(new CanopyGridGroupLevel("site", descending: true, aggregate: "machines")); // busiest sites first
view.Reporting.GroupBy.Add(new CanopyGridGroupLevel("os"));-
Parsing.
groupBylevels name allowed sortable columns, once each, withasc/descand an optional declared aggregate; anything else answersinvalidGroupBy, and so doesgroupByon a view without runtime grouping. A query withoutgroupBytakes the declared levels;[]is ungrouped. The parser normalizes the query as the browser does: the levels' columns lead the sort (ascending for a level ordered by an aggregate), and a sort entry for a column grouped by value turns that level around.CanopyDataRequest.LevelsandCanopySummaryRequest.Levelshold the result (CanopySummaryLevel: column, direction, aggregate); a fixed grouping is one level. -
Record order. Records follow the levels: each level's groups by raw value (ordinal text, numbers and dates, missing last), or by the level's aggregate over the group (missing aggregates last, equal values by value ascending), then the other sort keys inside the innermost groups and the record key. Pages and exports read innermost group by innermost group, so their order always agrees with the summary.
-
Nested summaries. Each level's groups nest in their outer group with absolute offsets into the complete query. Keys are unique across the summary: first-level keys keep the single-level form (
s:North,n:4,null), inner keys are the depth and the path of level keys (2:s:North/s:Open, with\and/escaped). The 10,000-group limit counts every level. -
Aggregates.
distinctCountcounts distinct nonmissing raw values of any column (COUNT(DISTINCT …)in a database; dates at protocol precision in memory). Custom aggregate operations (aCanopyGridAggregatewith an operation name) reach a provider asCanopySummaryAggregate.CustomOperation; the built-in providers answerunsupported, so a view with a custom aggregate needs anICanopyDataProviderthat computes it. -
Medians and percentiles.
medianandpercentile(CanopyGridAggregate.AtPercentile) interpolate linearly between the closest ranks, as Grouping describes. A rank needs every value of a group, which LINQ cannot translate portably and which CanopyX never reads by materialising a query:Provider Groups, totals and footers Pivots CanopyInMemoryProvider<T>computed computed CanopyQueryableProvider<T>unsupported(400)computed: the store groups by the value, within the 100,000-contribution bound ( limitExceededbeyond)your ICanopyDataProvidercomputes them ( PERCENTILE_CONT(p / 100) WITHIN GROUP (ORDER BY …)matches)through ICanopyPivotProviderOver a translated query, a view with a median or percentile answers summary requests
unsupportedand shows all-records footers as unavailable; implementSummarizeAsyncin a provider of your own (for example with the database'sPERCENTILE_CONT) to serve them. ReadCanopySummaryAggregate.Percentile(null for a median, the 50th). -
Echo. The summary includes a complete normalized
gridQuery, even when a direct handler request contains only its revision. The offset is zero; the accepted limit, search, predicate shape and operands are retained, and the effective grouping levels lead the sort. For code-built requests, an unused summary limit outside 1–10,000 is echoed as the view's page size. Ignored input fields do not become part of the response. Typed summaries returnunsupportedbefore provider access for constant filters, identity restrictions, or grouping overrides that a fixed or ungrouped view cannot express. These shapes remain supported in ordinary typed queries and direct provider requests; use runtime grouping for query-owned grouping levels.
Every request passes through CanopyRequestParser before a provider sees it:
- Allow-list. Only mapped columns are reachable; unknown ids answer
unknownColumn. Sorting needs a sortable column, filtering a filterable one, value lists a declared facet column. - Typed operands. Operands are converted per column kind and rejected when they do not fit (
invalidOperand): numbers must be finite within ±2^53−1, dates ISO 8601 with an explicit zone, text at mostMaxOperandLength. - Parameters only. The queryable provider passes every operand as a captured value, which LINQ providers send as a query parameter; request text never becomes SQL. The tests check the SQL EF Core sends for hostile operands.
- Limits (
CanopyRemoteLimits, protocol caps in brackets):
| Limit | Default | Protocol cap |
|---|---|---|
MaxPageSize |
1,000 | 10,000 |
MaxExportRows |
100,000 | — |
MaxFilterDepth |
8 | 8 |
MaxFilterTerms (flat and nested predicates) |
64 | 64 |
MaxFilterGroups |
64 | 64 |
MaxInValues |
1,000 | 1,000 |
MaxFilterValues (operands of all predicates in one query) |
1,000 | 64,000 |
MaxValueListSize |
200 | 200 |
MaxSearchLength |
1,024 | 16,384 |
MaxSearchTerms (all-words search; repeated words count once) |
16 | — |
MaxOperandLength |
4,096 | — |
MaxRequestBytes |
1 MiB | — (JSON nesting is also capped at 64) |
MaxSelectedIds (selected exports, exclusions) |
1,000 | 10,000 |
MaxGroups (across all grouping levels) |
10,000 | 10,000 |
MaxCommitRows |
100 | — |
MaxCommitTextLength (one written text value) |
65,536 | — |
MaxRecordPageSize (rows of a collection page, and first rows of each collection in a whole record) |
200 | 10,000 |
MaxRecordItems (timeline events or changes of one record field) |
200 | 10,000 (changes 512) |
MaxRecordBytes (one serialized record answer; refused, never cut short) |
1 MiB | — |
MaxRecordTextLength (one text value of a record answer, held for every provider; longer text ends with an ellipsis and fits the limit) |
8,192 | — |
MaxRecordOffset (offset of a collection page) |
10,000 | — |
MaxRecordRequestBytes (one record request body, within MaxRequestBytes) |
16 KiB | — |
MaxRangeRows (records of one range answer; a larger request limit is lowered to it) |
5,000 | 10,000 |
- Regex quick search runs in memory only.
MapCanopyRemoterefuses anIQueryablecallback for a view withAllowRegexSearch, and a regex query that still reachesCanopyQueryableProvider<T>answersunsupported. In memory, a pattern that exceeds its 100 ms evaluation budget answerslimitExceeded. - Typed errors. Rejections throw
CanopyRequestExceptionand answer{ "error": code, "message": text }with status 400 (409 forstaleRevision, 404 forrecordNotFound, 413 for an oversized body, 415 for a non-JSON body). Codes:invalidJson,invalidDocument,unknownColumn,invalidSort,columnNotFilterable,invalidOperator,invalidOperand,limitExceeded,offsetOutOfRange,staleRevision,unsupported,notFacetable,invalidExport,unknownFormat,invalidGroupBy,columnNotEditable,unknownField,notCollection,recordNotFound. Messages never echo request text or server internals. Any other exception is logged and answered with a generic 500serverError. - Authorization. Endpoints require authorization by default (the default policy, or
AuthorizationPolicy); setAllowAnonymousonly for public data. Row-level restrictions belong in the query callback, which runs per request. The commit route requiresWriteAuthorizationPolicyon top of the read authorization, and mapping a writer without one (or with a blank name) fails: the default policy would let every reader write.AllowAnonymousWritesexists for local samples. A route group opened with.AllowAnonymous()makes ASP.NET Core skip every policy, so the commit route then refuses with 403writeNotAllowedunlessAllowAnonymousWritesis set. The record route requires the read authorization like the other reads;CanReadRecordFielddecides per request which record fields a caller sees. - Rate limiting belongs to the host:
MapCanopyRemote(...).RequireRateLimiting("grid")limits every route, andoptions.RecordEndpoint = route => route.RequireRateLimiting("records")the record route alone. - Writes. Only columns the view declares editable and the schema allows can be written; any other column fails the
whole batch with
columnNotEditable. Every value is checked again (kind, the view's validation, the editor's step and choices) before a writer sees it, so a modified client cannot write what the grid would refuse. The reference writer also writes only columns mapped to a member of the record, converts values with range and membership checks, and answers store failures with a generic message (log them withCanopyQueryableWriterOptions.Failed). Commit bodies are JSON only, so another site's form cannot post one; cross-origin scripts need a CORS policy you grant. - The column map is the access boundary. Rows carry every mapped column and exports accept hidden columns; a view's
Hiddenflag is presentation. Leave out of the map whatever a caller must not read, and leaveEditableoff whatever a caller must not write. Commits change the records the writer's store loads by key: restrict that store as you restrict the query callback when callers may change only some records. - Stale data. A window that no longer matches its counts (records written between the count and the read) answers
409
staleRevision; an export that reads fewer records than it counted fails, and the endpoint aborts the response so the download does not look complete. - Exports are validated and counted before the first byte: an oversized scope answers
limitExceeded, a missing selected recordinvalidExport, a changed countstaleRevision. CSV cells that would start a spreadsheet formula are prefixed with an apostrophe, and file names are reduced to safe characters.
ICanopyDataProvider is the seam for back ends without a LINQ provider, such as raw SQL through a micro-ORM:
public interface ICanopyDataProvider {
ValueTask<string> GetRevisionAsync(CancellationToken cancellationToken);
ValueTask<CanopyPageResult> QueryAsync(CanopyDataRequest request, CancellationToken cancellationToken);
ValueTask<int> CountAsync(CanopyDataRequest request, CancellationToken cancellationToken);
IAsyncEnumerable<CanopyGridRow> ReadAsync(CanopyDataRequest request, CancellationToken cancellationToken);
ValueTask<CanopyFacetResult> FacetAsync(CanopyFacetRequest request, CancellationToken cancellationToken);
ValueTask<CanopySummaryResult> SummarizeAsync(CanopySummaryRequest request, CancellationToken cancellationToken);
}Requests arrive validated. A CanopyDataRequest carries Ids/ExcludedIds (selection), SearchTerms with the
Schema.SearchColumns, a Filter tree (CanopyFilterGroup, CanopyFilterCondition, CanopyFilterConstant) whose
conditions hold an allowed CanopyDataColumn, an operator and typed operands, the Sort keys and the window. An
implementation keeps its own fixed map from column id to SQL expression and binds every operand as a parameter:
string Condition(CanopyFilterCondition condition, DbCommand command) {
var column = Columns[condition.Column.Id]; // your fixed, allow-listed SQL expression
string P(object value) { var p = command.CreateParameter(); p.ParameterName = "@p" + command.Parameters.Count; p.Value = value; command.Parameters.Add(p); return p.ParameterName; }
return condition.Operator switch {
CanopyGridFilterOperator.IsNull => column + " IS NULL",
CanopyGridFilterOperator.Contains => "LOWER(" + column + ") LIKE '%' || " + P(Escape(((string)condition.Values[0]).ToLowerInvariant())) + " || '%' ESCAPE '\\'",
CanopyGridFilterOperator.GreaterThan => column + " > " + P(condition.Values[0]),
// … the remaining operators, with "column IS NOT NULL AND" in front of every value comparison
};
}Contract details:
- Order. Apply the sort keys with missing values last in both directions, then the record key ascending. A grouped
request (
request.Levels: the fixed grouping or thegroupBylevels) orders records level by level first, as Grouping levels describes, then by the sort keys of other columns; its levels' columns also leadrequest.Sort, as on the wire. - Counts.
QueryAsyncreturns the unfilteredTotal, theMatchedcount before the window, and exactlymin(limit, matched − offset)rows. - Value lists. Buckets are case-insensitive for text (one bucket per folded value), null last, at most
Limit, withTotalValuescounted after value search. - Summaries. Return every group of the first level (any order; the endpoint orders them and assigns ranges) with its
count and the declared aggregates, and inside each group of an outer level the groups of the next level
(
new CanopySummaryGroup(value, count, aggregates, innerGroups));countanddistinctCountcount nonmissing values,medianandpercentileinterpolate between ranks, the others are null for a group without values. Group by every prefix of the levels (oneGROUP BYper level, or a rollup). - Rows. Build
CanopyGridRows;CanopyDataValues.ToCellconverts store values to protocol cells andFormatIdformats keys. - Unsupported capabilities throw
CanopyRequestException(CanopyRequestError.Unsupported, …).
CanopyInMemoryProvider<T> is the reference implementation of this contract over records in memory (it evaluates every
rule directly, without LINQ providers) and the oracle the tests compare EF Core and LINQ results with. Register any
provider with MapCanopyRemote(pattern, schema, http => provider), or new CanopyRemoteHandler(schema, provider).
Calendar and timeline presentations of a hosted grid show the records of a period, not a page. The browser asks for them
with a gridRangeQuery through the source's optional range(request, { signal }) capability (without it, it falls back to
query() with equivalent predicates). MapCanopyRemote answers it at POST {pattern}/range under the same authorization,
body limit, content-type checks and error mapping as /query and /facet, and CanopyRemoteScript wires the range
hook for every view with a filterable date column. The request names its columns itself, so the endpoint needs no
calendar definition: each column is checked against the allow-list.
{ "protocol": "canopyx/2", "type": "gridRangeQuery", "view": "maintenance",
"query": { "protocol": "canopyx/2", "type": "gridQuery", "view": "maintenance", "offset": 0, "limit": 100, "search": "patch",
"revision": "r7", "sort": [], "filters": [{ "column": "kind", "operator": "eq", "values": ["maintenance"] }] },
"from": "2026-10-01T00:00:00Z", "to": "2026-11-01T00:00:00Z",
"start": "starts", "end": "ends", "recurrence": "rule", "seriesEnd": "seriesEnd",
"resource": "host", "resources": ["host-1", "host-2"], "calendarView": "month", "limit": 5000 }| Field | Rule |
|---|---|
query |
A complete gridQuery, parsed with the query rules (allow-list, operators, operands, filter limits, revision). Its search, predicates and filter group select the records; its window, sort and groupBy do not apply. |
from, to |
ISO 8601 UTC instants ending in Z, read at millisecond precision; from < to, at most 3,700 days apart (invalidDocument when reversed, limitExceeded when longer). |
start |
Required. An allowed, filterable date column. |
end, seriesEnd |
Optional allowed, filterable date columns. |
recurrence, resource |
Optional allowed, filterable text columns. |
resources |
Optional, 1 to 1,000 unique nonempty strings (at most MaxInValues, each at most MaxOperandLength and 4,096); requires resource. |
calendarView |
Optional, one of month, week, day, days, agenda, year, timeline, mini, weekList, dayList, months. Informational only (logging, host decisions); it never changes the answer. |
limit |
1 to 10,000; default and ceiling MaxRangeRows (5,000). A larger value is lowered, not rejected. |
An unknown column answers unknownColumn, a column that cannot be filtered columnNotFilterable, a column of the wrong kind
invalidDocument. Unknown additive fields are ignored, as everywhere in the protocol.
Semantics. After the query's criteria and the resource restriction, a record overlaps the window when:
- it has no recurrence (no
recurrencecolumn, or a null or empty value):start < toand (start >= fromorend > from). A null end, or noendcolumn, makes it a zero-length marker at its start, so onlystart >= fromcounts: a marker exactly atfromis included, one exactly attois not, and an event that ends exactly atfromis not; - it has a recurrence:
start < to, and with aseriesEndcolumn alsoseriesEnd IS NULL OR seriesEnd > from(fill the column with the end of the series' last occurrence, null for an endless series).
A record without a start never overlaps. resources keeps records whose resource is one of them with the semantics of an
in predicate on the resource column (case-insensitive, like every text comparison). The query's sort is ignored: records
are ordered by start ascending, then by record identity: ordinally in memory, and by the key column in the database's order
and collation for CanopyQueryableProvider<T>. Dates compare as UTC instants at millisecond precision.
{ "protocol": "canopyx/2", "type": "gridRangePage", "view": "maintenance", "revision": "r7",
"from": "2026-10-01T00:00:00Z", "to": "2026-11-01T00:00:00Z",
"matched": 1234, "truncated": true, "items": [ { "id": "evt-00017", "cells": { "starts": "2026-09-28T22:00:00Z" } } ] }matched counts every overlapping record; items are the first limit of them, written exactly as page rows are (every
mapped column, DecorateRows, cell formatters); truncated is items.length < matched. A stale query.revision answers
409 staleRevision, and so does an answer whose rows no longer fit its count (records written between the count and the
read). CanopyGridRangePage.ToJson(view) checks the rows against the view, the counts and the start order (every row has a
start before to, never earlier than the row before it).
Provider capability. The handler calls ICanopyRangeProvider.RangeAsync(CanopyRangeRequest, token), an optional
interface beside ICanopyDataProvider; a provider without it answers 400 unsupported. CanopyQueryableProvider<T> and
CanopyInMemoryProvider<T> implement it. A CanopyRangeRequest carries the parsed Query, From, To, the
CanopyDataColumns (Start, End, Recurrence, SeriesEnd, Resource), Resources, Limit and CalendarView, and
Selection: the same range as an ordinary CanopyDataRequest (the query's filter AND the resource in predicate AND the
overlap predicates, sorted by the start column, ungrouped, window 0..Limit). A custom provider can implement the capability
by counting Selection and reading its window with its own filter and order code:
public async ValueTask<CanopyRangeResult> RangeAsync(CanopyRangeRequest request, CancellationToken token) {
var matched = await CountAsync(request.Selection, token);
var rows = new List<CanopyGridRow>();
await foreach (var row in ReadAsync(request.Selection, token)) rows.Add(row);
return new CanopyRangeResult(matched, rows);
}CanopyInMemoryProvider<T> evaluates the overlap directly on the values, independently of Selection, and is the oracle
the tests compare LINQ to objects and EF Core (SQLite) with, byte for byte, over random ranges and the boundary cases above.
In C#, CanopyGridRangeQuery writes a request (for tests, mocks and .NET clients) and
CanopyRequestParser.FromRangeQuery(query, schema) validates it with the wire rules; ParseRange(json, schema) parses one.
EF Core translation. CanopyQueryableProvider<T> builds one predicate from the mapped expressions: the query's search,
predicates and filter group exactly as pages apply them, the resource in test, and the overlap as half-open millisecond
bounds (start < @to, start >= @from, end >= @from + 1 ms, seriesEnd IS NULL OR seriesEnd >= @from + 1 ms) with
IS NULL and = '' tests on the recurrence value. It composes on the host's base IQueryable, so the caller's scope still
applies; every instant and resource identity is a parameter. The answer is one COUNT and one window
ORDER BY start, key LIMIT @limit. As for date sorting, database ordering by the start column requires its
SortBy mapping (usually the indexed UTC timestamp itself when the store keeps whole milliseconds); without it the range
answers unsupported before querying. Index the start column (and the resource column for timelines). The overlap is an
OR of the single-event and series branches, which some databases cannot answer with one range seek on that index; measure
the plan on real data, and for very large tables consider a provider that reads each branch separately. Stores that pad or
trim trailing spaces in comparisons treat a whitespace-only rule as empty; keep the recurrence column null for single events.
The browser grid hands its export request to the server: the scope (filtered, selected or all), the accepted query
and revision, selected identities or an all-matching selection with exclusions, the columns in order and raw or display
values. CanopyRemoteScript registers one Export menu entry per server format (CanopyX.registerExportFormat), so the
menu's scope picker, progress and cancellation apply, and also answers grid.exportToHost(format, …).
On the server, PrepareExportAsync validates and counts the scope, then CanopyExportJob.WriteAsync(stream) streams the
records from the provider straight to the response, never materializing the result:
- CSV (
CanopyCsvExportFormat, registered by default): UTF-8 with a byte order mark, CRLF, column titles first, quoting for delimiters, quotes and line breaks, formula protection, and a comma, semicolon or tab delimiter. Display values use the cell's own text or the request locale (numbers with up to three decimals, datesyyyy-MM-dd HH:mm UTC,Yes/No); raw values are invariant (ISO dates, plain numbers). A column declared withExportAs = CanopyColumnExport.Textalways writes display text, including when the request asks for raw values. The server uses its own column definition. - Other formats implement
ICanopyExportFormat(Id,ContentType,Extension,WriteAsync(context, stream, token)) and are added toCanopyRemoteOptions.ExportFormats.CanopyExportContextsupplies the ordered records andGetValue/GetTexthelpers that respect the request's value mode.
A prepared export is checked again before writing. If the revision changes while streaming, the job fails and the
ASP.NET Core host aborts a response that has already started. Other hosts must discard a file whose WriteAsync fails.
A grid with editable columns (CanopyColumn.Editable, with an optional Editor and Validation) keeps changes in its
change set until the reader saves; it then posts one gridCommit document with each changed row's new and original
values and the revision it read (data-protocol.md). Map a writer to save them:
// What this caller may read: the grid's query, and also the records a commit may change.
IQueryable<Machine> Readable(HttpContext http) => http.RequestServices.GetRequiredService<FleetDb>().Machines
.Where(machine => machine.Team!.Members.Any(member => member.Login == http.User.Identity!.Name));
app.MapCanopyRemote("/api/machines", Readable, map, options => {
options.Query.Revision = store.GetRevisionAsync;
options.AuthorizationPolicy = "Inventory.Read";
options.WriteAuthorizationPolicy = "Inventory.Write"; // required with a writer, on top of the read policy
// The writer's scope is Readable: a commit changes only records the caller can read.
options.UseQueryableWriter(http => new EfCoreWriteStore<Machine>(http.RequestServices.GetRequiredService<FleetDb>()), (http, writer) => {
var db = http.RequestServices.GetRequiredService<FleetDb>();
writer.Revision = store.GetRevisionAsync;
writer.Saving = async (context, token) => { await store.BumpRevisionAsync(db, token); return null; }; // inside the row's transaction
});
});What the endpoint does before a writer sees a batch. It rejects the whole batch when a row changes a column the view
does not declare editable or the schema does not allow (columnNotEditable, unknownColumn), when it is malformed or
larger than MaxCommitRows. It checks every value against its column's kind (numbers within ±2^53−1, ISO 8601 moments
with a time zone, text or booleans) and the view's rules (Required, Minimum/Maximum, Earliest/Latest,
MinLength/MaxLength, Pattern anchored as in the browser), the editor's Step and its select choices; a row that
fails answers error with messages by column (CanopyCommitMessages, or the column's Validation.Message) and does not
reach the writer. The writer gets typed values (text, booleans, double, UTC DateTime) and the revision the endpoint
read. Its answer is checked too, but because the writer may already have committed its rows, a faulty answer never fails
the request: rows the writer was not asked about or answered twice, cells that break the page rules or belong to columns
outside the schema, messages for other columns and an invalid revision are left out and reported to
CanopyRemoteOptions.WriterProblem (the ASP.NET Core endpoints log them), and messages longer than 4,096 characters
are shortened.
ICanopyDataWriter is the seam: ValueTask<CanopyCommitResult> CommitAsync(CanopyCommitBatch batch, string revision, CancellationToken token) answers per row with CanopyCommitRowResult.Saved(id, cells), Failed(id, error, errors) or
Conflict(id, error), and the revision after the commit (null lets the endpoint read it from the provider). A row the
result leaves out was not saved.
Inserts. A row with "op": "insert" (a calendar's created or dropped event, for example) arrives as a CanopyCommitRow
whose Operation is CanopyCommitOperation.Insert: its Id is the client's temporary id, which always starts with new-,
its Values are the new record's values and its Original is empty. The endpoint checks it like an update (only editable,
allowed columns; an original on an insert, an id without new-, or an unknown op rejects the batch) and also answers
Required errors for required editable columns the insert leaves out. Inserts reach only a writer that implements
ICanopyInsertWriter and answers AcceptsInserts with true; a writer written for updates alone never sees one, and the insert
answers InsertRefused. A writer answers a saved insert with CanopyCommitRowResult.Saved(id, cells, newId); the
endpoint writes newId only for a saved insert whose new id is a well-formed identity (other cases are left out and
reported to WriterProblem). Inserts count towards MaxCommitRows like any row.
Custom writers declare their transaction boundary with CanopyCommitTransaction Transaction { get; }. Return PerRow
for independent row saves or PerBatch for an atomic batch. If any input row fails endpoint validation, a per-batch
writer is not called and every row answers as not saved; the invalid rows retain their specific validation messages.
CanopyQueryableWriter<T> is the reference writer over the column map:
- It writes only editable columns mapped to a member of the record itself (
x => x.Cores); creating it fails when an editable column maps a navigation chain such asx => x.Team!.Name, the record key, or a member marked[ConcurrencyCheck]or[Timestamp](tokens configured fluently are not visible to it: keep those columns read-only). - Scope. A row whose record lies outside
Options.Scopeanswers as missing and is not written.UseQueryableWritersets the scope to the endpoint's query callback, as above. A writer you create yourself needsScope, orAllowUnscoped = truewhen every caller may change every recordICanopyWriteStore<T>.Recordsreturns (for example becauseRecordsitself is restricted); creating it with neither fails. - Per row it loads the record by the map's key and compares each changed column's original value with the stored one at
protocol precision: a difference is a
conflictand nothing is written. A record that no longer exists is a conflict too. With a revision source (Options.Revision, read inside the row's transaction), the comparison is skipped while the revision still equals the batch's;AlwaysCompareOriginalscompares regardless. Without one, every row is compared. - Concurrency. The comparison is only as strong as the store's transaction: it must serialize the load, the comparison
and the save (serializable or snapshot isolation, or row locks), or another writer can change the record in between.
Give the record a concurrency token (EF Core
IsRowVersion()orIsConcurrencyToken()); the store then refuses a save over a newer version and the row answers a conflict. - It converts values to the member types: whole numbers in range for integer members, enumeration members by their raw
text (
[EnumMember]value or name) and null for nullable value types. The .NET 10 asset rejects null for reference members annotated as non-nullable. The .NET Standard 2.0 and .NET Framework assets leave reference nullability to the host. A value a member cannot hold, such as a number beyond afloatordecimalmember's range (CommitMessages.OutOfRange), answers a cell error. - It runs
Saving(stamp an audit column, change the revision, or refuse the row with a message) and saves. A store exception stops its row only: the row answers "The row could not be saved." (the exception goes toFailedfor logging), or a conflict when the store reports a concurrency failure (EF Core'sDbUpdateConcurrencyExceptionfor concurrency tokens). Transaction = CanopyCommitTransaction.PerRow(default) saves each row in its own transaction;PerBatchwrites all rows in one transaction and nothing when any row fails: the first failing row stops the batch, and the others answerBatchNotSaved; a failed commit of the batch answers every row as not saved. After any row that is not saved the writer rolls back (a failing rollback does not hide the row's answer) and discards the store's unsaved changes.- A saved row answers canonical cells of its changed columns, formatted by the map like page rows.
- Inserts are refused (
CommitMessages.InsertRefused, "New rows cannot be added here.") unlessOptions.NewRecordcreates the new record and the store implementsICanopyInsertStore<T>(Add(record)).NewRecordruns first, so it sets what the caller must not choose (owner, tenant, audit fields); the row's editable values follow (never the key, which the store orNewRecordassigns), thenSaving,Addand the save. The answer carries the stored key asnewIdand canonical cells. After saving, the new record must be returned by the store'sRecordsquery and, when configured,Options.Scope. A record excluded by either query is rolled back and answers as not saved without anewId. Both queries must see the saved record in the same unit of work (the sameDbContext) inside the transaction. The save runs before the scope check, so store-side effects of a rolled-back insert (triggers, identity values) still happen. In aPerBatchcommit an insert is kept only when every row is saved.
The writer reaches the store through ICanopyWriteStore<T> (and ICanopyInsertStore<T> for inserts), so CanopyX.Data stays
free of EF Core. The EF Core adapter:
public sealed class EfCoreWriteStore<T>(DbContext db) : ICanopyInsertStore<T> where T : class {
public IQueryable<T> Records => db.Set<T>().AsTracking(); // tracked, also when the context reads without tracking
public async ValueTask<ICanopyWriteTransaction> BeginTransactionAsync(CancellationToken token) => new Transaction(await db.Database.BeginTransactionAsync(token));
public async ValueTask SaveChangesAsync(CancellationToken token) => await db.SaveChangesAsync(token);
public void DiscardChanges() => db.ChangeTracker.Clear();
public void Add(T record) => db.Set<T>().Add(record); // inserts; implement ICanopyWriteStore<T> alone to refuse them
sealed class Transaction(IDbContextTransaction transaction) : ICanopyWriteTransaction {
public ValueTask CommitAsync(CancellationToken token) => new(transaction.CommitAsync(token));
public ValueTask RollbackAsync(CancellationToken token) => new(transaction.RollbackAsync(token));
public ValueTask DisposeAsync() => transaction.DisposeAsync();
}
}Revisions. A commit changes the data, so give the dataset a revision the writer changes (Saving above, a row
version, a change counter) and answer it. The grid keeps reading pages at the revision it accepted. CanopyRemoteScript
reloads after a commit reports a different revision, or after rows were saved without a revision because the server could
not read it after the write. Reload keeps the reader's latest query and page length. If it fails, the grid displays the
error and offers Retry. Readers of an older revision elsewhere get staleRevision and reload too.
A grid with a record panel whose details load on demand (CanopyRecordSource.Host()) keeps its rows
small: the drawer asks for one record's details when it opens, for the next rows of a collection when the reader presses
Load more, and for the record's row when a deep link or a related record names a record the grid has not loaded. Each is a
gridRecordQuery (data-protocol.md); the record route answers it with a gridRecord.
// 1. The record panel the drawer shows: record-only fields, with their details loaded from the server.
view.RowAction = CanopyGridRowAction.Details;
var panel = view.Record = new CanopyRecordPanel { Source = CanopyRecordSource.Host(), DeepLink = true };
panel.Fields.Add(new CanopyColumn("serial", "Serial number"));
panel.Fields.Add(new CanopyColumn("purchased", "Purchased") { Kind = CanopyColumnKind.DateTime });
panel.Fields.Add(new CanopyColumn("replaces", "Replaces"));
panel.Fields.Add(new CanopyColumn("software", "Installed software"));
panel.Fields.Add(new CanopyColumn("maintenance", "Maintenance"));
panel.Fields.Add(new CanopyColumn("changes", "Configuration changes"));
panel.Fields.Add(new CanopyColumn("rack", "Machines in the same rack"));
// 2. The record allow-list, next to the column map: only these fields are read, and only through these expressions.
var records = new CanopyRecordMap<Machine>(map)
.Field("serial", m => m.SerialNumber)
.Field("purchased", m => m.PurchasedOn)
.Link("replaces", m => m.ReplacesId, m => m.Replaces!.Name) // a link into this grid: empty when the caller cannot read it
.Collection("software", m => m.Software, list => list.Key(s => s.Id).OrderBy(s => s.Name)
.Column(new CanopyColumn("name", "Program"), s => s.Name)
.Column(new CanopyColumn("installed", "Installed") { Kind = CanopyColumnKind.DateTime }, s => s.InstalledOn)
.PageSize(10))
.Timeline("maintenance", m => m.Maintenance, events => events.Key(e => e.Id).Time(e => e.At)
.Summary(e => e.Summary).Actor(e => e.Technician).Kind(e => e.Kind, kind => kind == "Failure" ? Tone.Danger : Tone.Neutral))
.Changes("changes", m => m.Changes, changes => changes.Key(c => c.Id).Name(c => c.Setting)
.Before(c => c.Before).After(c => c.After).OrderBy(c => c.At, descending: true))
// Machines of this grid: by default only those the caller's query reads are shown (and counted).
.Collection("rack", m => m.Rack!.Machines, list => list.Key(peer => peer.Id).OrderBy(peer => peer.Name)
.Column(new CanopyColumn("name", "Machine"), peer => peer.Name).Target("machines"));
// 3. The endpoints: the record map carries the column map, and the record route looks records up through the same query
// callback as the grid.
app.MapCanopyRemote("/api/machines", Readable, records, options => {
options.AuthorizationPolicy = "Inventory.Read";
options.CanReadRecordField = (http, field) => field != "serial" || http.User.IsInRole("Inventory.Assets");
options.RecordEndpoint = route => route.RequireRateLimiting("records"); // limit the record route (see Safety)
});
// 4. The page script: a record schema wires the grid source's record hook to the route.
var html = view.ToHtml(new CanopyHtmlOptions { HeadHtml = CanopyRemoteScript.Element(records.Schema, "/api/machines") });Mapping. Every mapped field must be a record panel field of the view (CanopyRecordPanel.Fields), every drawer value a
declared view column; nothing else is reachable.
| Method | Answer | Notes |
|---|---|---|
Field(id, value, format?) |
a scalar field | Text, booleans, enumerations, numbers and dates, whose kind fits the field's as column values do; format builds the cell (display text, tone, badges). |
Link(id, key, text?, view?, withinGrid?) |
CanopyCell.Link |
A related record: no key is an empty field, no text shows the identity; view names another grid on the page. A link into this grid (no view, or this grid's) shows only when the related record belongs to the caller's query, otherwise it is an empty field, and its key must have the grid key's type. withinGrid: false opts out and reveals related records outside the caller's scope; links into other grids show what they reach. |
Cell(column, value, format?) |
cells |
A fuller value of a grid column for the drawer, for example a whole list whose grid cell shows a count. |
Collection(id, items, list => …) |
CanopyRecordList |
Key (unique among the rows, the row identity and the last order key), Column(column, value, format?), OrderBy (missing values last), PageSize (default 50), PageLength, Target(view, column?) so rows open their records and "Open all in grid" filters that grid. Rows of the grid's own record type are kept to those the caller's query reads (and so is the total); Unscoped() opts out and reveals records outside the caller's scope. Rows of other types show what the navigation reaches. Rows without a key are left out. |
Timeline(id, items, events => …) |
CanopyCell.Timeline |
Key, Time, Summary (blank shows an em dash), Actor, Kind with a tone, newest first unless OldestFirst, missing times last, Limit (default 50). |
Changes(id, items, changes => …) |
CanopyCell.Diff |
Key, Name, Before, After, OrderBy, Limit (default 50, at most 512). |
The record's row is the row the page route writes for it: the column map's columns, cell formats and DecorateRows.
Records are found by the column map's key, which must be text, a GUID or an integer up to 64 bits.
How a request is answered.
- Parsing (
CanopyRequestParser.ParseRecord, orFromRecordQueryfor aCanopyGridRecordQuerybuilt in C#): theviewmust be the grid's;idis 1 to 4,096 characters of well-formed text that is never interpreted as an expression;revisionandroware optional. A collection page names itsfield, anoffset(default 0) and alimit(1 to 10,000, at mostMaxRecordPageSize; default the field's page size) and anoffsetof at mostMaxRecordOffset.offsetorlimitwithoutfield, androwwithfield, areinvalidDocument; a field the endpoint does not serve isunknownField, and one that is not a collectionnotCollection. The body may hold at mostMaxRecordRequestBytes. - Read check.
CanReadRecordField(http, id)(canReadoutside ASP.NET Core) runs for every record field and drawer value; one the caller may not read is left out of the answer, which the drawer shows as an empty field, and is not queried. A collection page of such a field answersunknownField, exactly as a field the endpoint does not serve. The check hides whole fields only, never single collection rows, events or changes: restrict those in the field's mapping. - Revision. A stale
revisionanswers 409staleRevisionbefore the record is looked up, so it reveals nothing about the record; the answer echoes the revision it was read at. - Lookup.
CanopyQueryableRecordProvider<T>runsWhere(key == id)on the query callback (the caller's scope) with the identity converted to the key type as a parameter, and reads every readable value field, drawer value and, when asked, the row in one projection. An identity converts only when it is the key's own invariant text:007,+7,7, an upper-case or braced GUID, or a number the key type cannot hold find nothing, without a query. A store collation that matches other spellings of a text key finds nothing either: the found key's text must equal the identity. A record that is missing, outside the caller's scope or whose identity is not a key answers the same 404recordNotFound, with the same message, so callers cannot tell them apart. - Children. Collections, timelines and change lists read the rows of the record found (
SelectManyover its navigation), never a table of their own: a collection costs a count and a window, a timeline or change list one window, in the same order every time (the order keys, then the child key). A whole record carries each collection's firstPageSizerows (at mostMaxRecordPageSize) with its total, and each timeline or change list its firstLimititems (at mostMaxRecordItems). A collection page checks that the record exists, then answers its rows fromoffsetand the total; past the end it answers an empty page. Rows written between the count and the window answer 409staleRevision, as pages do. ThepageSizea collection carries (what Load more asks for) is its page size withinMaxRecordPageSize. Text orders by the column's collation in a database and ordinally in memory; the child key decides every tie. Child rows without a key (null, or empty text) are left out of the rows and the total. - Text. Text in record fields, drawer values, collection cells, timelines and changes longer than
MaxRecordTextLength(8,192 by default) is shortened so that it ends with an ellipsis (…) and, ellipsis included, fits the limit, never inside a surrogate pair; a database reads at most one character more, enough to tell longer text apart. The handler applies the same bound to every provider's answer, customICanopyRecordProviderimplementations included (values, display text, tooltips, badges, list items, object fields, collection rows, events and changes). Identities, link keys and the row are never shortened. - Answer. The handler checks the provider's answer and fails the request (500) instead of sending a field or drawer
value that was not asked for, more rows or items than allowed, a collection whose total is below its rows or whose page
size the endpoint would refuse, or a row of another record; then it writes the document with
CanopyGridRecord.ToJson(view), which checks it against the view, and refuses one larger thanMaxRecordByteswithlimitExceededinstead of cutting it short.
In the browser. CanopyRemoteScript.Element(records.Schema, endpoint) (a record schema instead of the column schema)
wires the source's record hook to {endpoint}/record; rejected requests carry the HTTP status and the error code. A
404 recordNotFound answers null: the drawer shows the row without details, and a deep link or related record the grid
has not loaded stays unopened (the runtime rejects openRecord with "not available"). A 409 staleRevision (the data
changed since the grid read its rows, for example after a save here or elsewhere) reloads the grid at the current revision
and opens the same record again there: details always belong to the rows they open from, so the drawer never mixes two
revisions. Any other error
rejects, so the drawer shows the message with Retry; a failed Load more says so and keeps its button.
Safety.
- Scope. The lookup composes on the query callback, so a record a caller cannot see in the grid cannot be opened, and
child rows come only through it. A navigation that reaches other records of the grid (related records, rack peers, a
replaced record's name) is kept within the grid by default: a collection of the grid's own record type keeps its rows
(and its total) to records the caller's query reads, and a link into this grid answers an empty field for a related
record outside it. Both test
source.Any(visible => visible.Key == key)on the query callback (anEXISTSkey lookup per row or link in a database). Opting out is explicit and named:Unscoped()on a collection andwithinGrid: falseon a link answer records outside the caller's scope, so use them only when every caller may see every record they reach. Navigations to records of other kinds (links into other grids, collections of other types) show what they reach: when those records have a scope of their own, restrict them in their expression, withCanReadRecordField, or leave the field out of the map. - Keys. The column map's key must be unique under the store's own comparison: a text key in a case-insensitive column needs values that differ beyond case, or two records answer one identity and the request fails as a server error.
- Fields. Only mapped fields are read;
CanReadRecordFieldhides whole fields and drawer values per caller (record field identities never equal column identities). Grid columns, and so the record'srow, follow the column map exactly as page rows do: leave out of the map what a caller must not read. - Bounds. Record request bodies are bounded by
MaxRecordRequestBytes(16 KiB); answers byMaxRecordPageSize,MaxRecordItems,MaxRecordTextLengthandMaxRecordBytes. An answer is built in memory beforeMaxRecordBytesis checked, so the largest answer the endpoint builds is the mapped collections' rows times their columns of bounded text (an answer whose text alone exceedsMaxRecordBytesis refused before it is serialized). KeepMaxRecordTextLengthandMaxRecordPageSizenear what the drawer shows. A record request is a key lookup plus one count and one window per collection, so its cost does not grow with the table; offsets into one record's collection cost their distance, up toMaxRecordOffset. - Rate limiting. Rate-limit the record route in production: it is cheap per request but answers on demand, so an
unthrottled caller can make the server build many bounded answers. Register a policy with
AddRateLimiterandUseRateLimiter, then apply it withoptions.RecordEndpoint = route => route.RequireRateLimiting("records"). - Errors never echo the identity, the field or other request text.
Other back ends. ICanopyRecordProvider is the seam for stores without a LINQ provider: describe the served fields with
a CanopyRecordSchema and answer each CanopyRecordRequest with a CanopyGridRecord (null when the caller has no such
record), following the contract above; CanopyInMemoryRecordProvider<T> is the reference implementation the tests compare
EF Core and LINQ to objects with. The handler checks the answer's shape and shortens its text to MaxTextLength whatever
the provider, but it cannot scope it: a custom provider keeps related records within the caller's scope itself. A
hand-built CanopyRecordSchema refuses a record field whose identity is a column's, as the record map does.
var schema = new CanopyRecordSchema(map.Schema, new[] { CanopyRecordField.Value("serial"), CanopyRecordField.Collection("software", 10) });
app.MapCanopyRemote("/api/machines", map.Schema, http => new SqlMachineProvider(http), options => {
options.Records = http => new SqlMachineRecords(schema, http); // WHERE Id = @id AND <the caller's scope>, children by machine
});Each page request runs two counts (dataset and matches; one when there are no criteria) and one windowed query that selects only the key and mapped columns. Measured with the sample on SQLite (EF Core 10, Release, in process, median of five runs after warm-up, on a shared 16-core workstation, so treat the numbers as orders of magnitude):
| Request | 100,000 rows | 1,000,000 rows |
|---|---|---|
| First page, default order (key) | 3 ms | 25–55 ms |
| First page, sorted by an indexed column | 3–14 ms | 26–30 ms |
| Middle / last page, indexed sort (offset 500,000) | 6–10 ms | 80–160 ms |
| First page, sorted by an unindexed column | 15 ms | 125–320 ms |
| Quick search over four text columns | 65–110 ms | 0.8–1.8 s |
Filter group (cores ≥ 64 or site is null) |
15–20 ms | 120–290 ms |
| Value list (site / model, filtered) | 50–140 ms | 0.7–1.4 s |
| Summary, three aggregates | 40–70 ms | 310–430 ms |
| Grouped summary by site (one grouped scan) | 0.3 s | 2–2.8 s |
| Grouped page in the middle | 20–25 ms | 120–230 ms |
| Two-level summary (site by machine count, then operating system; five aggregates with a distinct count) | 0.4 s | 4 s |
| Three-level summary with a distinct count | 0.6 s | 7 s |
| Two-level page in the middle (index on site, operating system, name) | 15–20 ms | 115–120 ms |
| CSV export of every row | 0.75 s, 7 MiB | 7 s, 72 MiB, flat 130 MiB working set |
| Record details with the row (key lookup, a count and a window per collection, one window per timeline and change list, rack peers and a link checked against the caller's query) | 1.5 ms | — |
| Collection page of one record (offset 10) | 0.6 ms | — |
Notes:
- Index the orders readers use. The default order is the key. With an index on a sorted column (and non-nullable
annotations or
NotNull(), so no missing-values key is added), deep pages stay cheap; an unindexed sort scans the matches. - Offsets cost their distance.
OFFSET nwalks n index entries; at a million rows the last page of an indexed order takes about 150 ms. The browser asks only for the pages the reader reaches. - Counts scan.
COUNT(*)over the filtered set runs per request. For very large tables, keep filters selective or give the query callback a pre-filtered set. - Search and lowercased comparisons scan.
LOWER(column)prevents plain index use; with a case-insensitive collation chooseTextComparison.Collation. Consider full-text search behindSearchByfor large text columns. - Value lists and summaries group the complete query; they run when a reader opens a value list or the query changes. Text value lists stream every raw text group so nonadjacent Unicode spellings can merge before search, counts and the prefix are finalized. They retain one canonical key per distinct matching value and at most the requested prefix's values and counts; they do not buffer records or the complete grouped result. For high-cardinality columns, consider host-normalized text with suitable indexes, or a host provider that groups and counts indexed canonical keys in the store. Nonempty numeric value-list search also transfers every distinct numeric group to search its canonical text; retained values/counts stay proportional to the requested limit. Empty numeric search retains the database-limited prefix path.
- Large parameter lists. A selected export sends its identities, and each membership filter its values, as one
parameterized collection. Some providers expand a collection into a parameter per element (EF Core can, depending on
version and configuration), and SQL Server allows 2,100 parameters per command. The defaults (
MaxFilterValuesandMaxSelectedIdsat 1,000 each) keep a query within that limit. When your provider sends a collection as one parameter (EF Core's JSON orOPENJSONtranslation), you can raise them up to 64,000 operands and 10,000 identities. - Grouped views read the group counts with each page request (one grouped scan per level over each prefix of the
grouping columns, with the aggregate a level orders by; summaries and pages build the same group tree, so they agree
also under case-insensitive collations) and then fetch the window: up to eight innermost groups slice by slice through
WHERE level1 = value AND level2 = value …(an index on the grouping columns and the sort column serves it), more in queries ordered by a rank over at most 64 groups each; a page may span at most 1,000 groups. Exports read the same way, so their rows follow the group ranges. Summaries run one grouped scan per level, plus one for complete-query totals when a distinct count is declared. Grouping values must be distinct at protocol precision (instants that differ below a millisecond cannot be two groups). - Commits load each changed record by key and save it in its own transaction (or one for the batch); a batch is
bounded by
MaxCommitRows. - Run the measurements yourself:
FleetInventory --bench --rows 1000000 --database <path>(--sqlprints the SQL).
samples/FleetInventory serves a generic fleet inventory (machines with site, operating system, model, cores, memory,
online state, last seen and team, and record details: serial number, purchase date, notes, the machine each replaces,
installed software, maintenance visits, configuration changes and racks) from SQLite through EF Core, seeded with 100,000
deterministic machines on first start (about 130 MB with their details; a database from an earlier sample version is rebuilt):
dotnet run --project samples/FleetInventory -- --urls http://127.0.0.1:5199 --rows 100000/ shows every machine with value lists, the filter builder, selection, aggregates and the server CSV export, and opens
each machine in a record panel (Overview, Software, History and Related tabs, deep links such as /#record=machines:42)
whose details load from the record route;
/by-site shows the same data grouped by site; /by-site-os groups by site (busiest sites first, ordered by the machine
count) and operating system with a distinct count of models, and readers can regroup; /edit edits names, sites,
operating systems, models, cores, memory and the online state and saves them to SQLite through CanopyQueryableWriter
and an EF Core store. Every saved row increments a revision counter in the database inside its transaction, and the
page's Simulate another user's change button changes the selected machine behind the reader's back, so saving shows a
conflict. Add ?theme=dark for the dark theme. The browser tests tests/browser/specs/remote-dotnet.spec.mjs,
remote-dotnet-commit-groups.spec.mjs and remote-dotnet-records.spec.mjs start the built sample against a temporary
database and check paging, sorting, searching, filtering, value lists, exports, grouping (one and two levels), commits,
conflicts, record details (Load more, related records, deep links, Retry) and error answers against the real endpoints.