@ember-lattice/protocol 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import type { AllowList, RowsRequest, RowsResponse } from '../types';
2
+ import type { IServerSideGetRowsRequest, LoadSuccessParams } from './types';
3
+ /** `fromAgGrid` throws this when the AG Grid request has no Lattice mapping, or is not well formed. */
4
+ export declare class AgGridTranslationError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export interface FromAgGridOptions {
8
+ /** The allow-list. With it, string group keys and set values become numbers or booleans by column type. */
9
+ columns?: AllowList;
10
+ /** Match the AG Grid `inRangeInclusive` filter param. Default false: `inRange` excludes both ends. */
11
+ inRangeInclusive?: boolean;
12
+ /**
13
+ * The AG Grid `treeData` option (ADR 0022). `groupKeys` become `tree.keys`, typed by the key
14
+ * column of `columns`. `rowGroupCols` must be empty.
15
+ */
16
+ treeData?: boolean;
17
+ }
18
+ /**
19
+ * Translate an AG Grid server-side row model request (`IServerSideGetRowsRequest`) into a Lattice
20
+ * `RowsRequest`. Both filter grammars map into the one Lattice filter tree. The result is not yet
21
+ * trusted: the server must still call `parseRowsRequest` with its allow-list.
22
+ */
23
+ export declare function fromAgGrid(request: IServerSideGetRowsRequest, options?: FromAgGridOptions): RowsRequest;
24
+ /**
25
+ * The AG Grid grid options for server-side tree data over a Lattice server (ADR 0022). A row
26
+ * with `$count > 0` has children. Its group key is the row key, as a string.
27
+ */
28
+ export declare function agGridTree(key: string): {
29
+ treeData: true;
30
+ isServerSideGroup: (row: Record<string, unknown>) => boolean;
31
+ getServerSideGroupKey: (row: Record<string, unknown>) => string;
32
+ getChildCount: (row: Record<string, unknown>) => number;
33
+ };
34
+ /**
35
+ * Translate a Lattice `RowsResponse` into AG Grid `LoadSuccessParams`. Pivot fields become AG Grid
36
+ * pivot result fields: the pivot keys and the value key, joined with `_` (the default
37
+ * `serverSidePivotResultFieldSeparator`).
38
+ *
39
+ * Pass the AG Grid request to get `grandTotalData`. AG Grid replaces its grand total row with any
40
+ * `grandTotalData`, so it is sent only for a root request (no group keys).
41
+ */
42
+ export declare function toAgGrid(response: RowsResponse, request?: IServerSideGetRowsRequest): LoadSuccessParams<Record<string, unknown>>;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * AG Grid server-side row model shapes, copied (JSON parts only) from the AG Grid source:
3
+ *
4
+ * repo https://github.com/ag-grid/ag-grid
5
+ * branch latest, at commit a87e7f20590bad427b8f2af85a0a9e925baa1f0d (2026-12-01)
6
+ * package ag-grid-community 36.3.0-beta.20261201.1142 (latest release tag: release-36.3.0)
7
+ *
8
+ * Files, under packages/ag-grid-community/src/ at that commit:
9
+ * interfaces/iServerSideDatasource.ts IServerSideGetRowsRequest
10
+ * interfaces/iServerSideRowModel.ts LoadSuccessParams
11
+ * interfaces/iColumnVO.ts ColumnVO
12
+ * interfaces/iSortModelItem.ts SortModelItem
13
+ * interfaces/iSort.ts SortDirection, SortType
14
+ * interfaces/iFilter.ts FilterModel
15
+ * interfaces/iSetFilter.ts SetFilterModel, SetFilterModelValue
16
+ * interfaces/iMultiFilter.ts IMultiFilterModel
17
+ * interfaces/advancedFilterModel.ts AdvancedFilterModel and its members
18
+ * filter/provided/iProvidedFilter.ts ProvidedFilterModel
19
+ * filter/provided/iSimpleFilter.ts ISimpleFilterModel, ICombinedSimpleModel, option keys
20
+ * filter/provided/text/iTextFilter.ts TextFilterModel
21
+ * filter/provided/number/iNumberFilter.ts NumberFilterModel
22
+ * filter/provided/date/iDateFilter.ts DateFilterModel
23
+ * filter/provided/bigInt/iBigIntFilter.ts BigIntFilterModel
24
+ * filter/provided/iScalarFilter.ts inRangeInclusive (default false: exclusive)
25
+ *
26
+ * Lattice does not depend on AG Grid. These types are a copy so the translator can type its input.
27
+ */
28
+ export interface ColumnVO {
29
+ id: string;
30
+ displayName: string;
31
+ field?: string;
32
+ aggFunc?: string;
33
+ }
34
+ export interface SortModelItem {
35
+ colId: string;
36
+ sort: 'asc' | 'desc';
37
+ type?: 'absolute' | 'default';
38
+ }
39
+ export interface FilterModel {
40
+ [colId: string]: unknown;
41
+ }
42
+ export interface IServerSideGetRowsRequest {
43
+ startRow: number | undefined;
44
+ endRow: number | undefined;
45
+ rowGroupCols: ColumnVO[];
46
+ valueCols: ColumnVO[];
47
+ pivotCols: ColumnVO[];
48
+ pivotMode: boolean;
49
+ groupKeys: string[];
50
+ filterModel: FilterModel | AdvancedFilterModel | null;
51
+ sortModel: SortModelItem[];
52
+ }
53
+ export interface LoadSuccessParams<TData = unknown> {
54
+ rowData: TData[];
55
+ rowCount?: number;
56
+ groupLevelInfo?: unknown;
57
+ pivotResultFields?: string[];
58
+ grandTotalData?: Partial<TData> | null;
59
+ }
60
+ export type ISimpleFilterModelPresetType = 'today' | 'yesterday' | 'tomorrow' | 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth' | 'thisQuarter' | 'lastQuarter' | 'nextQuarter' | 'thisYear' | 'lastYear' | 'nextYear' | 'yearToDate' | 'last7Days' | 'last30Days' | 'last90Days' | 'last6Months' | 'last12Months' | 'last24Months';
61
+ export type TextFilterOptionKey = 'empty' | 'blank' | 'notBlank' | 'equals' | 'notEqual' | 'contains' | 'notContains' | 'startsWith' | 'endsWith';
62
+ export type ScalarFilterOptionKey = 'empty' | 'blank' | 'notBlank' | 'equals' | 'notEqual' | 'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'inRange';
63
+ export interface TextFilterModel {
64
+ filterType?: 'text';
65
+ type?: TextFilterOptionKey | string | null;
66
+ filter?: string | null;
67
+ filterTo?: string | null;
68
+ }
69
+ export interface NumberFilterModel {
70
+ filterType?: 'number';
71
+ type?: ScalarFilterOptionKey | string | null;
72
+ filter?: number | null;
73
+ filterTo?: number | null;
74
+ }
75
+ export interface BigIntFilterModel {
76
+ filterType?: 'bigint';
77
+ type?: ScalarFilterOptionKey | string | null;
78
+ filter?: string | null;
79
+ filterTo?: string | null;
80
+ }
81
+ /** `dateFrom` and `dateTo` are `YYYY-MM-DD hh:mm:ss`, `YYYY-MM-DDThh:mm:ss` or `YYYY-MM-DD`. */
82
+ export interface DateFilterModel {
83
+ filterType?: 'date';
84
+ type?: ScalarFilterOptionKey | ISimpleFilterModelPresetType | string | null;
85
+ dateFrom: string | null | undefined;
86
+ dateTo: string | null | undefined;
87
+ }
88
+ export type ISimpleFilterModel = TextFilterModel | NumberFilterModel | BigIntFilterModel | DateFilterModel;
89
+ /** A column filter with two or more conditions. AG Grid finds it by `operator`. */
90
+ export interface ICombinedSimpleModel<M extends ISimpleFilterModel = ISimpleFilterModel> {
91
+ filterType?: string;
92
+ operator: 'AND' | 'OR';
93
+ conditions: M[];
94
+ }
95
+ export type SetFilterModelValue = (string | null)[];
96
+ export interface SetFilterModel {
97
+ filterType?: 'set';
98
+ values: SetFilterModelValue;
99
+ }
100
+ /** Child models are in `filterParams` order. A child is null when that filter is not active. */
101
+ export interface IMultiFilterModel {
102
+ filterType?: 'multi';
103
+ filterModels: unknown[] | null;
104
+ }
105
+ export type AdvancedFilterModel = JoinAdvancedFilterModel | ColumnAdvancedFilterModel;
106
+ export interface JoinAdvancedFilterModel {
107
+ filterType: 'join';
108
+ type: 'AND' | 'OR';
109
+ conditions: AdvancedFilterModel[];
110
+ }
111
+ export type TextAdvancedFilterModelType = 'equals' | 'notEqual' | 'contains' | 'notContains' | 'startsWith' | 'endsWith' | 'blank' | 'notBlank';
112
+ export type ScalarAdvancedFilterModelType = 'equals' | 'notEqual' | 'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'inRange' | 'blank' | 'notBlank';
113
+ interface ColumnAdvancedBase<F extends string, T, V> {
114
+ filterType: F;
115
+ colId: string;
116
+ type: T;
117
+ filter?: V;
118
+ filterTo?: V;
119
+ }
120
+ export type ColumnAdvancedFilterModel = ColumnAdvancedBase<'text' | 'object', TextAdvancedFilterModelType | string, string> | ColumnAdvancedBase<'number', ScalarAdvancedFilterModelType | string, number> | ColumnAdvancedBase<'bigint', ScalarAdvancedFilterModelType | string, string> | ColumnAdvancedBase<'date' | 'dateString' | 'dateTime' | 'dateTimeString', ScalarAdvancedFilterModelType | ISimpleFilterModelPresetType | string, string> | ColumnAdvancedBase<'boolean', 'true' | 'false' | 'blank' | 'notBlank' | string, string> | {
121
+ filterType: 'set';
122
+ colId: string;
123
+ type: 'isAnyOf' | 'isNoneOf';
124
+ values: SetFilterModelValue;
125
+ };
126
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { AllowList, Row } from '../types';
2
+ /** ASCII strings and integers only, so every language and database gives the same values. */
3
+ export declare const peopleColumns: AllowList;
4
+ export declare const peopleRows: Row[];
5
+ /** One more distinct `bucket` value than `LIMITS.maxPivotValues`, for the pivot width case. */
6
+ export declare const wideColumns: AllowList;
7
+ export declare const wideRows: Row[];
8
+ export declare const treeParentColumns: AllowList;
9
+ export declare const treePathColumns: AllowList;
10
+ export declare const treeParentRows: Row[];
11
+ export declare const treePathRows: Row[];
@@ -0,0 +1,54 @@
1
+ import type { AllowList, IssueCode, ProtocolIssue, Row, RowsRequest, RowsResponse } from '../types';
2
+ /** A request and the exact response every server must give. */
3
+ export interface ResponseCase {
4
+ name: string;
5
+ dataset: string;
6
+ request: RowsRequest;
7
+ expected: RowsResponse;
8
+ }
9
+ /** A cursor walk: send `request`, then follow `cursor.next` until it is absent. Cursors are opaque. */
10
+ export interface WalkCase {
11
+ name: string;
12
+ dataset: string;
13
+ request: RowsRequest;
14
+ pages: Row[][];
15
+ count: number;
16
+ }
17
+ /** A request the server must reject with an error that has this code. */
18
+ export interface ErrorCase {
19
+ name: string;
20
+ dataset: string;
21
+ request: unknown;
22
+ error: IssueCode;
23
+ }
24
+ export type ConformanceCase = ResponseCase | WalkCase | ErrorCase;
25
+ export interface ConformanceSuite {
26
+ version: 1;
27
+ datasets: Record<string, {
28
+ columns: AllowList;
29
+ rows: Row[];
30
+ }>;
31
+ cases: ConformanceCase[];
32
+ }
33
+ /**
34
+ * The conformance suite as plain JSON. The expected values come from the reference evaluator, and
35
+ * a test checks them against the committed `conformance/cases.v1.json`. Servers in other languages
36
+ * read that file.
37
+ */
38
+ export declare function conformanceCases(): ConformanceSuite;
39
+ /** A server under test: it answers a request, or rejects it with errors. */
40
+ export type ConformanceHandler = (request: RowsRequest, dataset: string) => RowsResponse | {
41
+ errors: ProtocolIssue[];
42
+ } | Promise<RowsResponse | {
43
+ errors: ProtocolIssue[];
44
+ }>;
45
+ /** Run one case. Returns the list of differences; an empty list is a pass. */
46
+ export declare function checkCase(c: ConformanceCase, handler: ConformanceHandler): Promise<string[]>;
47
+ /**
48
+ * Compare a response with the expected one. Rules for every port:
49
+ * - Rows come in the same order, and each row has the same keys.
50
+ * - Numbers match within 1e-9, relative to the larger value (or absolute below 1).
51
+ * - Cursor values are opaque: only the presence of `next` and `prev` must match.
52
+ * - `count`, `total`, `pivotColumns` and `cursor` are present exactly when expected.
53
+ */
54
+ export declare function compareResponse(actual: RowsResponse, expected: RowsResponse): string[];
@@ -0,0 +1,21 @@
1
+ import { type AllowList, type FilterNode, type ProtocolIssue, type Row, type RowsRequest, type RowsResponse } from './types';
2
+ /**
3
+ * `evaluate` throws this when the request fails `parseRowsRequest`, the cursor is bad, or the scope
4
+ * has more distinct pivot values than `LIMITS.maxPivotValues`.
5
+ */
6
+ export declare class ProtocolValidationError extends Error {
7
+ readonly errors: ProtocolIssue[];
8
+ constructor(errors: ProtocolIssue[]);
9
+ }
10
+ /**
11
+ * True when the filter tree keeps the row: the row test of `evaluate`, with SQL three-valued
12
+ * logic. The allow-list gives the column types. Call `parseRowsRequest` first for input you do not
13
+ * trust. A column that is not in the allow-list compares as a string.
14
+ */
15
+ export declare function matchesFilter(node: FilterNode, row: Row, allowList: AllowList): boolean;
16
+ /**
17
+ * The reference implementation of the Lattice protocol over rows in memory. It is the executable
18
+ * spec: the conformance suite comes from it, and every server must give the same response.
19
+ * It validates the request first, and throws `ProtocolValidationError` when the request is bad.
20
+ */
21
+ export declare function evaluate(request: RowsRequest, rows: readonly Row[], allowList: AllowList): RowsResponse;
@@ -0,0 +1,10 @@
1
+ export * from './types';
2
+ export { LIMITS } from './limits';
3
+ export { parseRowsRequest, aggregateKey } from './parse';
4
+ export { evaluate, matchesFilter, ProtocolValidationError } from './evaluate';
5
+ export { rowsRequestSchema, rowsResponseSchema, rowOpSchema, transactionSchema, mutateResultSchema, } from './schema';
6
+ export { conformanceCases, checkCase, compareResponse } from './conformance/index';
7
+ export type { ConformanceCase, ConformanceHandler, ConformanceSuite, ErrorCase, ResponseCase, WalkCase, } from './conformance/index';
8
+ export { fromAgGrid, toAgGrid, agGridTree, AgGridTranslationError } from './ag-grid/index';
9
+ export type { FromAgGridOptions } from './ag-grid/index';
10
+ export type * from './ag-grid/types';