The Lattice wire protocol, version 1
The package exports TypeScript types for RowsRequest, RowsResponse, FilterNode, RowOp, Transaction, MutateResult and ColumnSchema.
Context
- Plan: section 5.3 (decision 16), sections 5.1, 5.4 and 5.5
- Package:
@ember-lattice/protocol
Lattice loads rows from servers in three languages: Node, Ruby and Python. All three must give the same rows for the same request. The grid also must work with servers that already speak the AG Grid server-side row model (SSRM).
A grid request is hostile input. It names columns, ops and aggregate functions. If a server puts these names into SQL without a check, an attacker can read data or break the database.
SQL databases do not agree on some rules. Postgres sorts nulls last in ascending order and first in descending order. MySQL does the opposite. Collations differ. Each database has its own rules for text case. If the protocol does not set these rules, the three servers give different rows.
JSON Schema can check the shape of a message. It cannot check an allow-list, the depth of a
recursive tree, or a rule such as start <= end.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
Messages
The package exports TypeScript types for RowsRequest, RowsResponse, FilterNode, RowOp,
Transaction, MutateResult and ColumnSchema. It has no runtime dependencies and imports
nothing from Ember. The build inlines @sindresorhus/is.
The request follows plan 5.3. This ADR adds these fields and rules to plan 5.3:
RowsRequest.count?: booleanasks forcount. Plan 5.4 rule 6 needs a way to ask.Aggregate.as?: stringsets the output key of an aggregate. The default key isfn(column), for examplesum(salary). The AG Grid translator setsasto the column id.- A group row has the key
$count: the number of leaf rows in the group. Column names cannot start with$, so the key cannot collide with a column. ColumnSchema.key: truemarks the unique row id. The key is always the last sort key. Cursor paging needs it.- The filter node uses one discriminant,
op:{ op: 'and' | 'or', nodes },{ op: 'not', node }, or a leaf{ column, op, value? }. - A pivot column has a
field. The field is the compact JSON array of the pivot keys and the value key, for example["east","sum(salary)"]. JSON gives one field for each pivot column, also when a key contains a separator.
The trust boundary
Every server calls parseRowsRequest(input, allowList) before it does any work. The allow-list
is a list of ColumnSchema. Each entry names a column, its type, its filter ops, its aggregate
functions, and whether it can sort, group or search.
The parser:
- Rejects unknown keys on every object. This rejects
__proto__andconstructor. - Looks up columns in a
Map, never in a plain object. - Checks that each op and each aggregate function fits the column type. For example, it rejects
containson a number even when the allow-list permits it. - Rejects an aggregate
asthat is not an identifier, or that is__proto__,constructororprototype. - Never throws. It returns
{ ok: true, value }with a fresh copy, or{ ok: false, errors }. Each error has a path and a code.
The limits are in LIMITS:
| Limit | Value |
|---|---|
Filter depth (and, or, not nesting; a root leaf is depth 1) |
16 |
| Filter nodes in one tree | 256 |
| Values in one filter tree (each is one SQL bind parameter) | 1000 |
Items in one list (in values, and/or nodes, columns, aggregates) |
1000 |
| Sort items | 16 |
group.by and pivot.by |
16 |
| Rows in one page | 10000 |
| String value, search, cursor length | 1024, 256, 4096 |
| Distinct pivot values in the scope (checked at run time) | 200 |
| Errors returned | 50 |
The parser checks a length before it reads a list, and a depth before it reads a node. A server
must also limit the request body size. A server rejects a bad request with HTTP 400 and the body
{ "errors": ProtocolIssue[] }.
Semantics
The reference evaluator, evaluate(request, rows, allowList), is the executable spec. Its rules
are possible in plain SQL on Postgres, MySQL and SQLite:
- Filter logic. Filters use SQL three-valued logic. A comparison with null is unknown. Only
a true result keeps a row. So
ne,notInandnotdo not match null values. - Blank. On a string column,
blankmatches null and the empty string. On other column types, it matches null only.notBlankis the opposite. - Text.
eqis case-sensitive.contains,startsWithandendsWithignore case. The conformance data uses ASCII only.%,_and\in a value are literal characters. A server that usesLIKEmust escape them. - Ranges.
betweenincludes both ends.inRangeis for dates. It includes the start and excludes the end. - Dates. Dates are ISO 8601 strings. A date-time without a zone is UTC.
- Sort. Nulls are last by default, in both directions. Strings sort by binary collation (UTF-16 code unit order for ASCII). The key column is the last sort key, ascending.
- Quick search. A case-insensitive substring match on the string columns with
search: true. - Groups. When
keys.length < by.length, the server returns group rows forby[keys.length]. Else it returns leaf rows. A group row has the group value, the aggregates and$count. Group rows sort by the group column. A null key is a group. - Aggregates.
sum,avg,minandmaxignore nulls, and give null when no value is present.countcounts the values that are not null.firstandlasttake the value from the first and last row in sort order. - Pivot. The pivot columns are the distinct pivot keys in the scope, sorted ascending with nulls last. Each group row has a cell for each pivot column. At the leaf level, the response has one aggregate row.
- Projection. Leaf rows hold only allow-listed columns. With
columns, they hold those columns and the key. The key is always in the row, also whencolumnsdoes not name it. The cursor comes from the full row, not the projected row. So a SQL server selects the sort columns also whencolumnsleaves them out. - Paging. An offset range is
[start, end). A cursor range is keyset paging. A cursor is opaque: only the server that made it reads it. A cursor response hascursor.nextwhen rows follow, andcursor.prevwhen rows come before. A cursor is client input. A server must check each decoded cursor value against the type of its sort column and bind it as a parameter, or sign the cursor. - Response fields.
countis present when the request asks, or when the page is the last page.totalis present whenaggregateis not empty.pivotColumnsis present whenpivotis set.
JSON Schema
The package exports a draft 2020-12 schema for each message: rowsRequestSchema,
rowsResponseSchema, rowOpSchema, transactionSchema and mutateResultSchema. The schema
limits come from LIMITS. The schemas cannot check the allow-list, the filter depth, the node
count, start <= end, or duplicate output keys. A test checks that the schema and the parser
agree on a set of valid and invalid fixtures.
Conformance
conformanceCases() returns the suite as plain JSON. The committed file
packages/protocol/conformance/cases.v1.json holds the same data, and a test keeps them equal.
The npm package ships the file. There are three kinds of case:
- A response case: send the request, and compare the response.
- A walk case: send the request, then follow
cursor.nextuntil it is absent. Compare each page. The last page must havecount. - An error case: the server must reject the request with an error that has the given code.
The comparison rules (compareResponse): rows come in the same order with the same keys.
Numbers match within 1e-9, relative to the larger value. Only the presence of a cursor matters,
not its value.
AG Grid translator
fromAgGrid(request, options) translates an IServerSideGetRowsRequest into a RowsRequest.
toAgGrid(response, request) translates a RowsResponse into LoadSuccessParams. AG Grid
replaces its grand total row with any grandTotalData. So toAgGrid sends total as
grandTotalData only when it gets the AG Grid request and the request has no group keys. The translator output
is not trusted: the server must still call parseRowsRequest.
The AG Grid shapes are copied from the AG Grid source, branch latest, commit
a87e7f20590bad427b8f2af85a0a9e925baa1f0d (package version 36.3.0-beta.20261201.1142; latest
release tag release-36.3.0). The files, under
https://github.com/ag-grid/ag-grid/blob/a87e7f20590bad427b8f2af85a0a9e925baa1f0d/packages/ag-grid-community/src/:
interfaces/iServerSideDatasource.tsinterfaces/iServerSideRowModel.tsinterfaces/iColumnVO.tsinterfaces/iSortModelItem.tsandinterfaces/iSort.tsinterfaces/iFilter.ts,interfaces/iSetFilter.tsandinterfaces/iMultiFilter.tsinterfaces/advancedFilterModel.tsfilter/provided/iProvidedFilter.tsandfilter/provided/iSimpleFilter.tsfilter/provided/text/iTextFilter.ts,number/iNumberFilter.ts,date/iDateFilter.tsandbigInt/iBigIntFilter.tsfilter/provided/iScalarFilter.tsandfilter/provided/scalarFilterHandler.ts
The mapping:
- Column filter model: each column gives one node, and the nodes join with
and. A model withoperatoris a combined model. A multi filter joins its children withandand skips null children. A set model maps toin, and a null value maps toblank.emptyis no condition. - Advanced filter model: a
joinmaps toandoror. Each leaf maps by itsfilterType. A set leaf maps toinornotIn. A boolean leaf maps toeq. - Text options map to the Lattice ops.
notContainsmaps tonot(contains). inRangeexcludes both ends, as the AG Grid default (inRangeInclusiveis false) does. It maps togtandlt. WithinRangeInclusive: trueit maps tobetween.- AG Grid sends group keys and set values as strings. With the
columnsoption, the translator changes them to numbers or booleans by column type. - Pivot result fields join the pivot keys and the value key with
_, the AG Grid defaultserverSidePivotResultFieldSeparator. - AG Grid does not allow a null group key in the server-side row model. Its warning 190 says
"null and undefined values are not allowed for server side row model keys"
(
validation/errorMessages/errorText.ts, andserverSideRowModel/blocks/blockUtils.tsinag-grid-enterprise). Lattice null groups do not work with an AG Grid client. - The translator rejects date presets, custom filter options,
bigintfilters andsort.type: 'absolute'. It throwsAgGridTranslationError.
v1 changes (2026-12-01)
These changes apply to version 1. The three server ports must follow them.
Cursor and projection. A cursor holds the sort values of the full row. Before this change, the reference evaluator made the cursor from the projected row. When
columnsleft out a sort column, that value became null and a walk skipped rows. Two walk cases now use a projection: one leaves out a sort column, and one leaves out the key.NUL. The parser rejects every string that contains U+0000, with the code
bad_string. This applies to values,inlists, search, cursors, column names, group keys and aggregateas. Postgres cannot store U+0000 in text. The JSON Schema strings have the pattern^[^\u0000]*$.Dates. A date or a date-time must have a written year from 0001 to 9999 (ISO 8601 with four digits). The parser rejects other years with the code
invalid. The check uses the year as written, not the year after the zone offset.Pivot width.
LIMITS.maxPivotValuesis 200. It limits the distinctpivot.byvalue tuples in the scope of the request (after the filter, the search and the group keys). A null value counts as one value. The number of value aggregates does not change the count. The values come from the data, so the check is at run time:evaluatethrowsProtocolValidationErrorwith the codepivot_too_wideand the pathpivot. A server must count the distinct pivot values before it builds the pivot SQL, and reject the request with HTTP 400 when the count is too high.Lone surrogates. The parser rejects every string that contains a lone UTF-16 surrogate, with the code
bad_string. A lone surrogate is a high surrogate without a low surrogate after it, or a low surrogate without a high surrogate before it. This applies in the same places as the NUL rule. Ruby and Python reject invalid UTF-8, so all servers must agree. A valid surrogate pair (for example an emoji) is permitted.Calendar dates. The parser rejects a date or a date-time with a field that does not exist on the calendar, with the code
invalid. The month is 01 to 12. The day is 01 to the last day of the month. February has 29 days in a leap year: a year that 4 divides, except a year that 100 divides and 400 does not (2000 and 2024 are leap years, 1900 is not). The hour is 00 to 23, the minute and the second are 00 to 59, and there is no leap second. Hour 24 is permitted only as the end of the day:24:00,24:00:00or24:00:00.000. The offset hour is 00 to 23 and the offset minute is 00 to 59. Before this change, the parser accepted some of these values, because JavaScriptDatemoves2020-02-30to2020-03-01.Tree data (2026-12-02, ADR 0022).
RowsRequest.treeand the column flagsparentandpathare new, optional fields. A request withouttreegives the same response as before. A server that does not knowtreerejects it withunknown_key. ADR 0022 has the rules.
The conformance suite now has the datasets people, wide for the pivot width case, and
tree_parent and tree_path for tree data (item 7). Each
case names its dataset, so a port must load every dataset in the file.
Consequences
- One parser guards every server. The Ruby and Python packages must port the parser and pass the same error cases.
- The conformance suite fixes null order, collation, three-valued logic and aggregate rules.
Each SQL server must state them in SQL:
NULLS LAST(or an emulation on MySQL), a binary collation, andLIKEwith escaped%,_and\. - For
blank, a string column usescol IS NULL OR col = ''. Every other type usescol IS NULL. On Postgres,int_col = ''is an error. On MySQL,''becomes 0, so= ''also matches 0 and false. A conformance case checksblankon a boolean. - The parser limits a filter to 1000 values. One value is one bind parameter, so a query stays under the Postgres and MySQL cap (65535) and the SQLite cap (32766). Old SQLite builds have a cap of 999.
- A server that uses
IN ()must not get an empty list: the parser rejects empty lists. The translator maps an empty AG Grid set selection toblank AND notBlankon the same column, so that column must allow both ops. - The pivot field format is JSON. Ports must write compact JSON (no spaces) to match.
parseRowsRequestrejects an aggregateasthat is not an identifier. AG Grid column ids with dots (for exampleathlete.name) do not work as value columns.- AG Grid text
equalsignores case by default. Latticeeqdoes not. The translator keeps the Lattice rule. - The translator serves an AG Grid client with a Lattice server. The
data-ag-gridadapter (plan 5.5) needs the other direction: a Lattice request to an AG Grid backend. That work is not in this ADR. - JSON Schema does not limit the filter depth. Only the parser does.
Confirmation
Not recorded in the original ADR.
Interview record
Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.
| Question | Answer | Source |
|---|---|---|
| Where does the text of this page come from? | From the Markdown file docs/adr/0005-wire-protocol.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so. | Document: docs/adr/0005-wire-protocol.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: proposed |
| 2026-12-01 | Joe Gaudet | v1 changes (2026-12-01) |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0005-wire-protocol.md to this page. The text is the text of the Markdown file. |
The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.