@kronor/dtv 9.5.1 → 10.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.
- package/dist/cli/typegen/runTypegen.js +4 -4
- package/dist/index.es.js +7356 -7359
- package/dist/types/App.d.ts +8 -7
- package/dist/types/components/Table.d.ts +5 -5
- package/dist/types/dsl/columnTyping.d.ts +9 -0
- package/dist/types/dsl/columns.d.ts +6 -3
- package/dist/types/dsl/index.d.ts +1 -0
- package/dist/types/dsl/rowExpansion.d.ts +24 -0
- package/dist/types/dsl/view.d.ts +7 -4
- package/dist/types/framework/actions.d.ts +5 -1
- package/dist/types/framework/column-definition.d.ts +9 -4
- package/dist/types/framework/graphql/query.d.ts +14 -3
- package/dist/types/framework/native-runtime/index.d.ts +2 -2
- package/dist/types/framework/rows.d.ts +2 -2
- package/dist/types/framework/typelevel.d.ts +1 -0
- package/dist/types/framework/view.d.ts +64 -20
- package/dist/types/lib/index.d.ts +4 -3
- package/docs/api/row-typed-views.md +60 -2
- package/docs/typegen.md +1 -1
- package/package.json +2 -2
package/dist/types/App.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AIIntegration, ModifyAiFilterPromptFn } from './components/aiAssistant';
|
|
2
2
|
import { type RequestHeaders } from './framework/data';
|
|
3
3
|
import { type DTVAnalytics } from './framework/analytics';
|
|
4
|
-
import { View } from './framework/view';
|
|
4
|
+
import { View, type SimplifiedRow } from './framework/view';
|
|
5
5
|
import type { UserDataJson } from './framework/user-data';
|
|
6
6
|
import { Runtime } from './framework/runtime';
|
|
7
7
|
import { ActionDefinition } from './framework/actions';
|
|
8
8
|
import type { UserDataLoadAPI, UserDataSaveAPI } from './framework/user-data-manager';
|
|
9
9
|
import type { Result } from './framework/result';
|
|
10
|
-
export interface AppProps {
|
|
10
|
+
export interface AppProps<V extends View = View> {
|
|
11
11
|
graphqlHost: string;
|
|
12
12
|
/**
|
|
13
13
|
* Headers sent with every GraphQL request. Pass a function to have it
|
|
@@ -33,7 +33,7 @@ export interface AppProps {
|
|
|
33
33
|
* Optional already-parsed views.
|
|
34
34
|
* When provided, `viewsJson` is ignored and no JSON parsing occurs.
|
|
35
35
|
*/
|
|
36
|
-
views?:
|
|
36
|
+
views?: V[];
|
|
37
37
|
/** JSON string containing array of view definitions (required if `views` is not provided). */
|
|
38
38
|
viewsJson?: string;
|
|
39
39
|
showViewsMenu: boolean;
|
|
@@ -47,12 +47,13 @@ export interface AppProps {
|
|
|
47
47
|
rowSelection?: {
|
|
48
48
|
/** Type of row selection. 'none' disables selection UI. 'multiple' enables checkbox multi-select. */
|
|
49
49
|
rowSelectionType: 'none' | 'multiple';
|
|
50
|
-
/** Callback invoked whenever the row selection changes */
|
|
51
|
-
onRowSelectionChange?: (selectedRows:
|
|
50
|
+
/** Callback invoked whenever the row selection changes, with the rows as `SimplifiedRow` describes them */
|
|
51
|
+
onRowSelectionChange?: (selectedRows: SimplifiedRow<V>[]) => void;
|
|
52
52
|
};
|
|
53
53
|
/** Optional array of custom action buttons rendered after built-in buttons in the menubar */
|
|
54
54
|
actions?: ActionDefinition[];
|
|
55
|
-
|
|
55
|
+
/** CSS classes for a row, each set when its value is true. Gets the row as `SimplifiedRow` describes it. */
|
|
56
|
+
rowClassFunction?: (row: SimplifiedRow<V>) => Record<string, boolean>;
|
|
56
57
|
rowsPerPageOptions?: number[];
|
|
57
58
|
/** Optional imperative API for controlling the App instance. */
|
|
58
59
|
apiRef?: React.RefObject<DTVAPI | null>;
|
|
@@ -92,5 +93,5 @@ export type DTVAPI = {
|
|
|
92
93
|
expandAll: () => void;
|
|
93
94
|
};
|
|
94
95
|
};
|
|
95
|
-
declare function App({ graphqlHost, requestHeaders, aiIntegration, showViewsMenu, showViewTitle, showCsvExportButton, showPopoutButton, views: viewsFromProps, viewsJson, externalRuntime, isOverlay, onCloseOverlay, syncFilterStateToUrl, rowSelection, actions, rowClassFunction, rowsPerPageOptions, userData, analytics, modifyAiFilterPrompt, apiRef }: AppProps): import("react/jsx-runtime").JSX.Element;
|
|
96
|
+
declare function App<V extends View = View>({ graphqlHost, requestHeaders, aiIntegration, showViewsMenu, showViewTitle, showCsvExportButton, showPopoutButton, views: viewsFromProps, viewsJson, externalRuntime, isOverlay, onCloseOverlay, syncFilterStateToUrl, rowSelection, actions, rowClassFunction, rowsPerPageOptions, userData, analytics, modifyAiFilterPrompt, apiRef }: AppProps<V>): import("react/jsx-runtime").JSX.Element;
|
|
96
97
|
export default App;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DataTable } from 'primereact/datatable';
|
|
3
3
|
import { type ColumnDefinition } from '../framework/column-definition';
|
|
4
|
-
import { NoRowsComponent, RowExpansionDefinition } from '../framework/view';
|
|
4
|
+
import { NoRowsComponent, RowExpansionDefinition, type SimplifiedRow } from '../framework/view';
|
|
5
5
|
import { FilterState } from '../framework/state';
|
|
6
6
|
import { type FlattenedDataRow } from '../framework/data';
|
|
7
7
|
import type { DataOrdering } from '../framework/data-ordering';
|
|
@@ -15,7 +15,7 @@ type LazyRowExpansionLoadArgs = {
|
|
|
15
15
|
row: Record<string, unknown>;
|
|
16
16
|
rowKey: string | number;
|
|
17
17
|
};
|
|
18
|
-
type TableProps = {
|
|
18
|
+
type TableProps<Row> = {
|
|
19
19
|
viewId: string;
|
|
20
20
|
columns: ColumnDefinition[];
|
|
21
21
|
hiddenColumnIds: string[];
|
|
@@ -31,14 +31,14 @@ type TableProps = {
|
|
|
31
31
|
ref?: React.Ref<DataTable<any>>;
|
|
32
32
|
rowSelection?: {
|
|
33
33
|
rowSelectionType: 'none' | 'multiple';
|
|
34
|
-
onRowSelectionChange?: (rows:
|
|
34
|
+
onRowSelectionChange?: (rows: Row[]) => void;
|
|
35
35
|
};
|
|
36
36
|
/** Optional callback invoked when row selection reset becomes available/unavailable. */
|
|
37
37
|
onRowSelectionResetChange?: (resetFn: RowSelectionResetFn | null) => void;
|
|
38
38
|
onRowExpansionApiChange?: (api: RowExpansionApi | null) => void;
|
|
39
|
-
rowClassFunction?: (row:
|
|
39
|
+
rowClassFunction?: (row: Row) => Record<string, boolean>;
|
|
40
40
|
ordering?: DataOrdering | null;
|
|
41
41
|
onOrderingChange?: (ordering: DataOrdering | null) => void;
|
|
42
42
|
};
|
|
43
|
-
declare function Table({ viewId, columns, hiddenColumnIds, paginationKey, data, rawRows, rowExpansion, loadLazyRowExpansionData, noRowsComponent, setFilterState, filterState, applyFilters, ref, rowSelection, rowClassFunction, onRowSelectionResetChange, onRowExpansionApiChange, ordering, onOrderingChange }: TableProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
declare function Table<Row extends object = SimplifiedRow>({ viewId, columns, hiddenColumnIds, paginationKey, data, rawRows, rowExpansion, loadLazyRowExpansionData, noRowsComponent, setFilterState, filterState, applyFilters, ref, rowSelection, rowClassFunction, onRowSelectionResetChange, onRowExpansionApiChange, ordering, onOrderingChange }: TableProps<Row>): import("react/jsx-runtime").JSX.Element;
|
|
44
44
|
export default Table;
|
|
@@ -79,6 +79,15 @@ export type ValidateColumnFieldType<Row, Field extends string, Value> = [
|
|
|
79
79
|
type ListElement<Value> = NonNullable<Value> extends readonly (infer Element)[] ? NonNullable<Element> : never;
|
|
80
80
|
/** The arguments a list selection takes besides its selection set. */
|
|
81
81
|
type ListArguments = Pick<ArrayQuery, 'orderBy' | 'distinctOn' | 'limit' | 'where'>;
|
|
82
|
+
/**
|
|
83
|
+
* The data a `fieldColumn` adds to its row (see `SimplifiedRow`): the field's value, typed as the
|
|
84
|
+
* renderer takes it, inside the objects on its path, each of them null when the row lets it be.
|
|
85
|
+
*/
|
|
86
|
+
export type FieldColumnData<Row, Path extends string, Value> = Path extends `${infer Head}.${infer Tail}` ? {
|
|
87
|
+
[K in Head]: FieldColumnData<NonNullable<Row[K & keyof Row]>, Tail, Value> | ([Extract<Row[K & keyof Row], Nullish>] extends [never] ? never : null);
|
|
88
|
+
} : {
|
|
89
|
+
[K in Path]: Value;
|
|
90
|
+
};
|
|
82
91
|
/** What `fieldColumn` can select inside its field, unchecked: see `FieldColumnSelect`. */
|
|
83
92
|
export type FieldSelection = {
|
|
84
93
|
object: readonly Query[];
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { ReactNode } from "react";
|
|
19
19
|
import { type FieldQuery, type DataFromFieldQueriesForRowSafe, type FieldQueryForRowSafe, type TableColumnDefinition, type VirtualColumnDefinition, type CellRenderer, type CellRendererProps, type OrderableFieldPath, type TableColumnDefinitionFooter } from "../framework/column-definition";
|
|
20
|
-
import type { ColumnFieldValue, FieldColumnOrderBy, FieldColumnSelect, ValidateColumnFieldType } from "./columnTyping";
|
|
20
|
+
import type { ColumnFieldValue, FieldColumnData, FieldColumnOrderBy, FieldColumnSelect, ValidateColumnFieldType } from "./columnTyping";
|
|
21
21
|
export { valueQuery, objectQuery, arrayQuery, rowType } from "@kronor/hasura-graphql";
|
|
22
22
|
/**
|
|
23
23
|
* Creates a renderable table column definition for a view over `Row`.
|
|
@@ -66,6 +66,9 @@ type FieldCellRenderer<Value> = (props: FieldCellRendererProps<Value>) => ReactN
|
|
|
66
66
|
* list, each checked against it. `orderBy` names the field itself for a
|
|
67
67
|
* scalar, or a scalar inside it for an object.
|
|
68
68
|
*
|
|
69
|
+
* The column puts the field on the row DTV hands out (`SimplifiedRow`) with the type
|
|
70
|
+
* its renderer takes.
|
|
71
|
+
*
|
|
69
72
|
* See ./columnTyping for how a helper's own field is checked.
|
|
70
73
|
*/
|
|
71
74
|
export declare function fieldColumn<Row, const Field extends string, Value = ColumnFieldValue<Row, Field>>(args: {
|
|
@@ -76,7 +79,7 @@ export declare function fieldColumn<Row, const Field extends string, Value = Col
|
|
|
76
79
|
footer?: TableColumnDefinitionFooter;
|
|
77
80
|
orderBy?: NoInfer<FieldColumnOrderBy<Field, Value>>;
|
|
78
81
|
cellRenderer: FieldCellRenderer<Value>;
|
|
79
|
-
} & NoInfer<FieldColumnSelect<Value>>): TableColumnDefinition
|
|
82
|
+
} & NoInfer<FieldColumnSelect<Value>>): TableColumnDefinition<readonly FieldQuery[], FieldColumnData<Row, Field, NoInfer<Value>>>;
|
|
80
83
|
/**
|
|
81
84
|
* Creates a data-only virtual column definition for a view over `Row`.
|
|
82
85
|
* Convenience wrapper around the underlying VirtualColumnDefinition type.
|
|
@@ -85,5 +88,5 @@ export declare function virtualColumn<Row, const FieldQueries extends readonly F
|
|
|
85
88
|
rowType: Row;
|
|
86
89
|
id: string;
|
|
87
90
|
data: FieldQueries & readonly FieldQueryForRowSafe<Row>[];
|
|
88
|
-
}): VirtualColumnDefinition<FieldQueries
|
|
91
|
+
}): VirtualColumnDefinition<FieldQueries, DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
|
|
89
92
|
export type { Query } from "../framework/column-definition";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { FieldQuery, DataFromFieldQueriesForRowSafe, FieldQueryForRowSafe } from '../framework/column-definition';
|
|
2
|
+
import type { RowExpansionDefinition, RowExpansionPredicate, RowExpansionRenderer } from '../framework/view';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a row expansion for a view over `Row`, like `column()`: its `data` is checked
|
|
5
|
+
* against the row, and `render` and `canExpand` get that data typed from it. A lazy
|
|
6
|
+
* expansion (`lazy: true`) fetches its data when the row is opened, so until `state` is
|
|
7
|
+
* `'ready'` (and always in `canExpand`) its fields can be missing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rowExpansion<Row, const FieldQueries extends readonly FieldQuery[]>(args: {
|
|
10
|
+
rowType: Row;
|
|
11
|
+
data: FieldQueries & readonly FieldQueryForRowSafe<Row>[];
|
|
12
|
+
mode: 'single' | 'multiple';
|
|
13
|
+
lazy?: false;
|
|
14
|
+
render: RowExpansionRenderer<DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
|
|
15
|
+
canExpand: RowExpansionPredicate<DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
|
|
16
|
+
}): RowExpansionDefinition<FieldQueries, DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
|
|
17
|
+
export declare function rowExpansion<Row, const FieldQueries extends readonly FieldQuery[]>(args: {
|
|
18
|
+
rowType: Row;
|
|
19
|
+
data: FieldQueries & readonly FieldQueryForRowSafe<Row>[];
|
|
20
|
+
mode: 'single' | 'multiple';
|
|
21
|
+
lazy: true;
|
|
22
|
+
render: RowExpansionRenderer<DataFromFieldQueriesForRowSafe<Row, FieldQueries>, true>;
|
|
23
|
+
canExpand: RowExpansionPredicate<DataFromFieldQueriesForRowSafe<Row, FieldQueries>, true>;
|
|
24
|
+
}): RowExpansionDefinition<FieldQueries, DataFromFieldQueriesForRowSafe<Row, FieldQueries>>;
|
package/dist/types/dsl/view.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ColumnDefinition } from '../framework/column-definition';
|
|
2
|
+
import type { View, SimplifiedRow } from '../framework/view';
|
|
3
|
+
export type { View, SimplifiedRow };
|
|
3
4
|
/**
|
|
4
5
|
* Identity helper for `View`.
|
|
5
6
|
*
|
|
6
|
-
* Keeps DSL call sites readable while we decide on a richer builder API.
|
|
7
|
+
* Keeps DSL call sites readable while we decide on a richer builder API. The view keeps the
|
|
8
|
+
* types of its columns (the `[]` in the bound makes TypeScript infer a tuple instead of
|
|
9
|
+
* merging them into one array element type), so `SimplifiedRow` can tell what its rows hold.
|
|
7
10
|
*/
|
|
8
|
-
export declare function view(view: View): View
|
|
11
|
+
export declare function view<Columns extends [] | ColumnDefinition[]>(view: View<Columns>): View<Columns>;
|
|
@@ -54,7 +54,11 @@ export interface ActionAPI {
|
|
|
54
54
|
ordering: DataOrdering | null;
|
|
55
55
|
/** Build a GraphQLQueryAST for an arbitrary rootField (usually the current view root field). */
|
|
56
56
|
generateGraphQLQueryAST: typeof generateGraphQLQueryAST;
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Build a GraphQLQueryAST with top-level selections aliased to column ids. A column with
|
|
59
|
+
* several top-level queries has no single selection to alias: the result is then a failure
|
|
60
|
+
* naming those columns, and the caller narrows their `data` to the query it wants.
|
|
61
|
+
*/
|
|
58
62
|
generateColumnAliasedGraphQLQueryAST: typeof generateColumnAliasedGraphQLQueryAST;
|
|
59
63
|
/** Render a GraphQLQueryAST to a string. */
|
|
60
64
|
renderGraphQLQuery: typeof renderGraphQLQuery;
|
|
@@ -13,7 +13,7 @@ import type { FieldQuery } from "@kronor/hasura-graphql";
|
|
|
13
13
|
import type { DataFromFieldQueriesSafe, OrderableFieldPath } from "@kronor/hasura-graphql";
|
|
14
14
|
export type { OrderByConfig, FieldAlias, ValueQuery, ObjectQuery, ArrayQuery, Query, FieldQuery, OrderableFieldPath, DataFromQuery, DataFromFieldQuery, DataFromSelectionSet, DataFromFieldQueries, DataFromFieldQueriesSafe, DataFromQueryForRow, DataFromFieldQueryForRow, DataFromSelectionSetForRow, DataFromFieldQueriesForRow, DataFromFieldQueriesForRowSafe, ValueQueryForRow, ObjectQueryForRow, ArrayQueryForRow, QueryForRow, QueryForRowSafe, FieldAliasForRow, FieldQueryForRow, FieldQueryForRowSafe, ValidateFieldQueriesForRow, } from "@kronor/hasura-graphql";
|
|
15
15
|
export { fieldAlias, getOrderableFieldPaths, orderByIsSelectedField } from "@kronor/hasura-graphql";
|
|
16
|
-
export type CellRendererProps<Data extends
|
|
16
|
+
export type CellRendererProps<Data extends object = Record<string, unknown>> = {
|
|
17
17
|
data: Data;
|
|
18
18
|
setFilterState: (updater: (currentState: FilterState) => FilterState) => void;
|
|
19
19
|
applyFilters: () => void;
|
|
@@ -38,12 +38,12 @@ export type CellRendererProps<Data extends Record<string, any> = Record<string,
|
|
|
38
38
|
*/
|
|
39
39
|
columnDefinition: TableColumnDefinition;
|
|
40
40
|
};
|
|
41
|
-
export type CellRenderer<Data extends
|
|
41
|
+
export type CellRenderer<Data extends object = Record<string, unknown>> = {
|
|
42
42
|
bivarianceHack(props: CellRendererProps<Data>): ReactNode;
|
|
43
43
|
}["bivarianceHack"];
|
|
44
44
|
export type TableColumnDefinitionFooter = ColumnProps["footer"];
|
|
45
45
|
export type ColumnId = string;
|
|
46
|
-
export type TableColumnDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[], CellData extends
|
|
46
|
+
export type TableColumnDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[], CellData extends object = DataFromFieldQueriesSafe<FieldQueries>> = {
|
|
47
47
|
type: "tableColumn";
|
|
48
48
|
id: ColumnId;
|
|
49
49
|
data: FieldQueries;
|
|
@@ -52,10 +52,15 @@ export type TableColumnDefinition<FieldQueries extends readonly FieldQuery[] = r
|
|
|
52
52
|
orderBy?: OrderableFieldPath<FieldQueries>;
|
|
53
53
|
cellRenderer: CellRenderer<CellData>;
|
|
54
54
|
};
|
|
55
|
-
export type VirtualColumnDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[]
|
|
55
|
+
export type VirtualColumnDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[], Data extends object = DataFromFieldQueriesSafe<FieldQueries>> = {
|
|
56
56
|
type: "virtualColumn";
|
|
57
57
|
id: ColumnId;
|
|
58
58
|
data: FieldQueries;
|
|
59
|
+
/**
|
|
60
|
+
* Type only, never set: the data the column adds to its row, typed against the view's
|
|
61
|
+
* row type (see `SimplifiedRow`). A table column carries it in its cell renderer.
|
|
62
|
+
*/
|
|
63
|
+
rowData?: Data;
|
|
59
64
|
};
|
|
60
65
|
export type ColumnDefinition = TableColumnDefinition | VirtualColumnDefinition;
|
|
61
66
|
export declare function getColumnOrderBy(column: TableColumnDefinition): string | undefined;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { ColumnDefinition, FieldQuery } from '../column-definition';
|
|
2
|
+
import { type Result } from '../result';
|
|
2
3
|
import type { GraphQLQueryAST, GraphQLSelectionSet } from '@kronor/hasura-graphql';
|
|
3
4
|
export declare function generateSelectionSetFromColumns(columns: ColumnDefinition[]): GraphQLSelectionSet;
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Why a column-aliased query cannot be built: these columns have several
|
|
7
|
+
* top-level queries, so none of them alone is the column's value. Which one is
|
|
8
|
+
* the caller's to say; pass such a column with `data` narrowed to that query.
|
|
9
|
+
*/
|
|
10
|
+
export type ColumnAliasedQueryError = {
|
|
11
|
+
kind: 'severalTopLevelQueries';
|
|
12
|
+
columnIds: string[];
|
|
13
|
+
};
|
|
14
|
+
/** One selection per column, aliased with the column id. */
|
|
15
|
+
export declare function generateColumnAliasedSelectionSetFromColumns(columns: ColumnDefinition[]): Result<ColumnAliasedQueryError, GraphQLSelectionSet>;
|
|
5
16
|
export declare function generateGraphQLQueryAST(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>, additionalFieldQueries?: readonly FieldQuery[]): GraphQLQueryAST;
|
|
6
|
-
export declare function generateColumnAliasedGraphQLQueryAST(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>): GraphQLQueryAST
|
|
17
|
+
export declare function generateColumnAliasedGraphQLQueryAST(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>): Result<ColumnAliasedQueryError, GraphQLQueryAST>;
|
|
7
18
|
export declare function generateGraphQLQuery(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>, additionalFieldQueries?: readonly FieldQuery[]): string;
|
|
8
|
-
export declare function generateColumnAliasedGraphQLQuery(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>): string
|
|
19
|
+
export declare function generateColumnAliasedGraphQLQuery(rootField: string, columns: ColumnDefinition[], boolExpType: string, orderByType: string, paginationKey: string, staticArgs?: Record<string, unknown>): Result<ColumnAliasedQueryError, string>;
|
|
@@ -16,8 +16,8 @@ export type NativeRuntime = Runtime & {
|
|
|
16
16
|
};
|
|
17
17
|
export declare function mapHasuraCustomOperatorInput(input: unknown, mapValue: (operator: string, value: unknown) => unknown): unknown;
|
|
18
18
|
export declare const cellRenderers: {
|
|
19
|
-
text: ({ data, columnDefinition }: import("../column-definition").CellRendererProps<Record<string,
|
|
20
|
-
json: ({ data }: import("../column-definition").CellRendererProps<Record<string,
|
|
19
|
+
text: ({ data, columnDefinition }: import("../column-definition").CellRendererProps<Record<string, unknown>>) => string;
|
|
20
|
+
json: ({ data }: import("../column-definition").CellRendererProps<Record<string, unknown>>) => string;
|
|
21
21
|
};
|
|
22
22
|
export declare const filterTransforms: {
|
|
23
23
|
autocomplete: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
1
|
+
import type { SimplifiedRow } from './view';
|
|
2
|
+
export type RawRow = Record<string, unknown>;
|
|
3
3
|
/**
|
|
4
4
|
* Flatten a single raw row (array of cell objects) into one object.
|
|
5
5
|
* Duplicate keys are overwritten by the last occurrence (right-most cell wins).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { UnionToIntersection, Simplify, EmptyObject } from '@kronor/hasura-graphql';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode, createElement } from 'react';
|
|
2
|
-
import type { CellRendererProps, DataFromFieldQueriesSafe, FieldQuery } from './column-definition';
|
|
2
|
+
import type { CellRenderer, CellRendererProps, DataFromFieldQueriesSafe, FieldQuery } from './column-definition';
|
|
3
3
|
import { ColumnDefinition } from "./column-definition";
|
|
4
4
|
import { FilterGroups, FilterSchema } from "./filters";
|
|
5
5
|
import { FilterState } from "./state";
|
|
@@ -7,6 +7,7 @@ import { FilterFormState } from "./filter-form-state";
|
|
|
7
7
|
import { HasuraFilterExpression, HasuraOrderBy } from "./graphql";
|
|
8
8
|
import type { OrderDirection } from "./order-direction";
|
|
9
9
|
import type { ViewMigrationChain } from "./view-migrations";
|
|
10
|
+
import type { Simplify, UnionToIntersection } from "./typelevel";
|
|
10
11
|
export type NoRowsComponentProps = {
|
|
11
12
|
setFilterState: (updater: (currentState: FilterState) => FilterState) => void;
|
|
12
13
|
filterState: FilterState;
|
|
@@ -14,10 +15,8 @@ export type NoRowsComponentProps = {
|
|
|
14
15
|
updateFilterById: (filterId: string, updater: (currentValue: FilterFormState) => FilterFormState) => void;
|
|
15
16
|
};
|
|
16
17
|
export type NoRowsComponent = (props: NoRowsComponentProps) => ReactNode;
|
|
17
|
-
|
|
18
|
-
row:
|
|
19
|
-
data: Data;
|
|
20
|
-
state: 'ready' | 'loading' | 'error';
|
|
18
|
+
type RowExpansionRendererBaseProps = {
|
|
19
|
+
row: SimplifiedRow;
|
|
21
20
|
collapse: () => void;
|
|
22
21
|
toggle: () => void;
|
|
23
22
|
setFilterState: (updater: (currentState: FilterState) => FilterState) => void;
|
|
@@ -27,21 +26,48 @@ export type RowExpansionRendererProps<Data extends Record<string, any> = Record<
|
|
|
27
26
|
components: CellRendererProps['components'];
|
|
28
27
|
currency: CellRendererProps['currency'];
|
|
29
28
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
/**
|
|
30
|
+
* What a row expansion's `render` gets. A lazy expansion (`Lazy`) fetches its data when the
|
|
31
|
+
* row is opened: while that loads, or when it failed, `data` holds only those of its fields
|
|
32
|
+
* the table's own query has.
|
|
33
|
+
*/
|
|
34
|
+
export type RowExpansionRendererProps<Data extends object = Record<string, unknown>, Lazy extends boolean = false> = RowExpansionRendererBaseProps & ({
|
|
35
|
+
state: 'ready';
|
|
33
36
|
data: Data;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
} | (Lazy extends true ? {
|
|
38
|
+
state: 'loading' | 'error';
|
|
39
|
+
data: Partial<Data>;
|
|
40
|
+
} : never));
|
|
41
|
+
export type RowExpansionRenderer<Data extends object = Record<string, unknown>, Lazy extends boolean = false> = {
|
|
42
|
+
bivarianceHack(props: RowExpansionRendererProps<Data, Lazy>): ReactNode;
|
|
43
|
+
}["bivarianceHack"];
|
|
44
|
+
/**
|
|
45
|
+
* Whether a row can be expanded. It runs before a lazy expansion has fetched anything, so a
|
|
46
|
+
* lazy one gets only those of its fields the table's own query has.
|
|
47
|
+
*/
|
|
48
|
+
export type RowExpansionPredicate<Data extends object = Record<string, unknown>, Lazy extends boolean = false> = {
|
|
49
|
+
bivarianceHack(args: {
|
|
50
|
+
row: SimplifiedRow;
|
|
51
|
+
data: Lazy extends true ? Partial<Data> : Data;
|
|
52
|
+
}): boolean;
|
|
53
|
+
}["bivarianceHack"];
|
|
54
|
+
/** A row expansion of a JSON view, which can be lazy or not. */
|
|
55
|
+
export type RowExpansionRuntimeEntry<Data extends object = Record<string, unknown>> = {
|
|
56
|
+
render: RowExpansionRenderer<Data, boolean>;
|
|
57
|
+
canExpand: RowExpansionPredicate<Data, boolean>;
|
|
38
58
|
};
|
|
39
|
-
|
|
59
|
+
type RowExpansionDefinitionBase<FieldQueries extends readonly FieldQuery[]> = {
|
|
40
60
|
data: FieldQueries;
|
|
61
|
+
mode: 'single' | 'multiple';
|
|
62
|
+
};
|
|
63
|
+
export type RowExpansionDefinition<FieldQueries extends readonly FieldQuery[] = readonly FieldQuery[], Data extends object = DataFromFieldQueriesSafe<FieldQueries>> = RowExpansionDefinitionBase<FieldQueries> & {
|
|
64
|
+
lazy?: false;
|
|
41
65
|
render: RowExpansionRenderer<Data>;
|
|
42
66
|
canExpand: RowExpansionPredicate<Data>;
|
|
43
|
-
|
|
44
|
-
lazy
|
|
67
|
+
} | RowExpansionDefinitionBase<FieldQueries> & {
|
|
68
|
+
lazy: true;
|
|
69
|
+
render: RowExpansionRenderer<Data, true>;
|
|
70
|
+
canExpand: RowExpansionPredicate<Data, true>;
|
|
45
71
|
};
|
|
46
72
|
export type ViewId = string;
|
|
47
73
|
export type CollectionViewSource = {
|
|
@@ -54,11 +80,11 @@ export type FunctionViewSource = {
|
|
|
54
80
|
args?: Record<string, unknown>;
|
|
55
81
|
};
|
|
56
82
|
export type ViewSource = CollectionViewSource | FunctionViewSource;
|
|
57
|
-
type ViewBase = {
|
|
83
|
+
type ViewBase<Columns extends ColumnDefinition[]> = {
|
|
58
84
|
title: string;
|
|
59
85
|
id: ViewId;
|
|
60
86
|
source: ViewSource;
|
|
61
|
-
columnDefinitions:
|
|
87
|
+
columnDefinitions: Columns;
|
|
62
88
|
rowExpansion?: RowExpansionDefinition;
|
|
63
89
|
filterGroups: FilterGroups;
|
|
64
90
|
/** Optional default prompt shown in the AI Filter Assistant for this view. */
|
|
@@ -81,13 +107,31 @@ type ViewBase = {
|
|
|
81
107
|
*/
|
|
82
108
|
migrations?: ViewMigrationChain;
|
|
83
109
|
};
|
|
84
|
-
export type CollectionView = ViewBase & {
|
|
110
|
+
export type CollectionView<Columns extends ColumnDefinition[] = ColumnDefinition[]> = ViewBase<Columns> & {
|
|
85
111
|
source: CollectionViewSource;
|
|
86
112
|
};
|
|
87
|
-
export type FunctionView = ViewBase & {
|
|
113
|
+
export type FunctionView<Columns extends ColumnDefinition[] = ColumnDefinition[]> = ViewBase<Columns> & {
|
|
88
114
|
source: FunctionViewSource;
|
|
89
115
|
};
|
|
90
|
-
export type View = CollectionView | FunctionView
|
|
116
|
+
export type View<Columns extends ColumnDefinition[] = ColumnDefinition[]> = CollectionView<Columns> | FunctionView<Columns>;
|
|
117
|
+
type ColumnRowData<Column> = Column extends {
|
|
118
|
+
type: 'tableColumn';
|
|
119
|
+
cellRenderer: CellRenderer<infer CellData>;
|
|
120
|
+
} ? KnownFields<CellData> : Column extends {
|
|
121
|
+
type: 'virtualColumn';
|
|
122
|
+
rowData?: infer Data;
|
|
123
|
+
} ? KnownFields<Exclude<Data, undefined>> : never;
|
|
124
|
+
type KnownFields<Data> = string extends keyof Data ? Record<string, unknown> : Data;
|
|
125
|
+
/**
|
|
126
|
+
* A row of `V` as DTV hands it out, to `rowSelection.onRowSelectionChange` and
|
|
127
|
+
* `rowClassFunction`: the data of every column merged into one object (see `simplifyRow`). It holds only what the columns select, not
|
|
128
|
+
* the whole row type the view was declared against, so a field no column queries is not
|
|
129
|
+
* on it. A view whose columns are not typed (parsed from JSON, or annotated as `View`) gives
|
|
130
|
+
* `Record<string, unknown>`; a typed view with some untyped columns gets it merged in, so its
|
|
131
|
+
* typed columns' fields keep their types and the rest are `unknown`. A union of views gives a
|
|
132
|
+
* union of rows.
|
|
133
|
+
*/
|
|
134
|
+
export type SimplifiedRow<V extends View = View> = V extends View<infer Columns> ? Simplify<UnionToIntersection<ColumnRowData<Columns[number]>>> : never;
|
|
91
135
|
export declare function getViewRootFieldName(view: View): string;
|
|
92
136
|
export declare function getViewStaticArgs(view: View): Record<string, unknown> | undefined;
|
|
93
137
|
export declare function getAllFilters(filterGroups: FilterGroups): FilterSchema[];
|
|
@@ -2,7 +2,7 @@ import '../index.css';
|
|
|
2
2
|
export { default as App } from '../App';
|
|
3
3
|
export type { AppProps, DTVAPI } from '../App';
|
|
4
4
|
export type { AIIntegration, ModifyAiFilterPromptFn, RequestAiFilterFn } from '../components/aiAssistant';
|
|
5
|
-
export type { View } from '../framework/view';
|
|
5
|
+
export type { View, SimplifiedRow } from '../framework/view';
|
|
6
6
|
export { getViewRootFieldName, getViewStaticArgs } from '../framework/view';
|
|
7
7
|
export type { ViewJson, ColumnDefinitionJson } from '../framework/view';
|
|
8
8
|
export type { ViewProjection, FilterProjection, ColumnProjection, ControlProjection } from '../framework/view-projection';
|
|
@@ -30,6 +30,7 @@ export type { ActionDefinition, ActionAPI, ActionUserDataAPI } from '../framewor
|
|
|
30
30
|
export type { DTVAnalytics, DTVAnalyticsEvent, DTVAnalyticsEventBase, DTVAnalyticsEventPayload, DTVAnalyticsEventType, DTVAnalyticsSpan, DTVAnalyticsError, DTVAnalyticsPanel, DTVAnalyticsResets, DTVAnalyticsRetainedView, DTVAnalyticsUserDataError, FiltersAppliedTrigger, FetchReason } from '../framework/analytics';
|
|
31
31
|
export type { FetchErrorInfo, FetchErrorKind } from '../framework/fetch-error';
|
|
32
32
|
export type { HasuraFilterObject, HasuraOperator, HasuraOperatorFor, HasuraComparable, HasuraFilterExpression, GraphQLVariable, HasuraOrderBy, GraphQLSelectionSetItem, GraphQLSelectionSet, GraphQLQueryAST, } from '../framework/graphql';
|
|
33
|
+
export type { ColumnAliasedQueryError } from '../framework/graphql/query';
|
|
33
34
|
export type { DataOrdering } from '../framework/data-ordering';
|
|
34
35
|
export type { OrderDirection } from '../framework/order-direction';
|
|
35
36
|
export { hasuraFilterExpressionToObject, hasuraFilterExpressionsAreEqual, buildHasuraConditions, hasuraOperatorsAreEqual, generateSelectionSetFromColumns, generateGraphQLQueryAST, generateGraphQLQuery, renderGraphQLQuery, } from '../framework/graphql';
|
|
@@ -42,6 +43,6 @@ export type { QueryBuilder } from '../dsl/queryForRow';
|
|
|
42
43
|
export type { Query, ValueQuery, ObjectQuery, ArrayQuery, FieldAlias, OrderByConfig } from '@kronor/hasura-graphql';
|
|
43
44
|
export { buildGraphQLQueryVariables } from '../framework/data';
|
|
44
45
|
export { hasuraCustomOperatorTransform, mapHasuraCustomOperatorInput } from '../framework/native-runtime';
|
|
45
|
-
export type {
|
|
46
|
-
export { isFailure, isSuccess, failure, success } from '../framework/result';
|
|
46
|
+
export type { Failure, Success } from '../framework/result';
|
|
47
|
+
export { Result, isFailure, isSuccess, failure, success, mapResult, mapFailure, bimap, flatMap, getOrElse, match, unwrapResult, } from '../framework/result';
|
|
47
48
|
export * as DSL from '../dsl';
|
|
@@ -6,7 +6,7 @@ checked against that row: field paths have to exist, controls have to be able to
|
|
|
6
6
|
produce the type of the field they filter, and operators have to be ones Hasura
|
|
7
7
|
offers for that type.
|
|
8
8
|
|
|
9
|
-
`column()`, `virtualColumn()`, `fieldColumn()` and `filter()` all require
|
|
9
|
+
`column()`, `virtualColumn()`, `fieldColumn()`, `rowExpansion()` and `filter()` all require
|
|
10
10
|
`rowType`: a column or filter has to say which row it is built on. JSON views are unaffected (they are
|
|
11
11
|
validated at runtime by the view parser, not by these types).
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@ export const PaymentRequestsRowType = DTV.rowType<PaymentRequestsRow>();
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
It also adds `rowType:` to the `DSL.column(...)`, `DSL.virtualColumn(...)`,
|
|
25
|
-
`DSL.fieldColumn(...)` and `DSL.filter(...)` calls written inline in the view,
|
|
25
|
+
`DSL.fieldColumn(...)`, `DSL.rowExpansion(...)` and `DSL.filter(...)` calls written inline in the view,
|
|
26
26
|
so in practice the wiring is done for you. See
|
|
27
27
|
[../typegen.md](../typegen.md). To write it by hand, `rowType<Row>()` produces
|
|
28
28
|
the phantom value from any row type you already have.
|
|
@@ -103,6 +103,64 @@ accountColumn(InvoicesRowType, 'memo', 'Memo');
|
|
|
103
103
|
`Account | null`, but a field checked to hold `Account | null` is rejected by
|
|
104
104
|
one that renders `Account` or a `string`.
|
|
105
105
|
|
|
106
|
+
## Row expansions
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
DSL.rowExpansion({
|
|
110
|
+
rowType: PaymentRequestsRowType,
|
|
111
|
+
mode: 'single',
|
|
112
|
+
lazy: true,
|
|
113
|
+
data: [arrayQuery({ field: 'attempts', selectionSet: [valueQuery({ field: 'state' })] })],
|
|
114
|
+
canExpand: ({ row }) => row.hasAttempts === true,
|
|
115
|
+
render: ({ data, state }) => (state === 'ready' ? data.attempts.length : 'Loading…'),
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`data` is checked against the row like a column's, and `render` and
|
|
120
|
+
`canExpand` get it typed from it. A lazy expansion fetches its data when the row
|
|
121
|
+
is opened, so until `state` is `'ready'` its fields can be missing (`Partial`),
|
|
122
|
+
and in `canExpand`, which runs before anything is fetched, they always can.
|
|
123
|
+
`row` is the row as the table has it (see below), with `unknown` fields.
|
|
124
|
+
|
|
125
|
+
## Rows DTV hands out
|
|
126
|
+
|
|
127
|
+
`DSL.view(...)` keeps the types of its columns, so `SimplifiedRow<typeof view>`
|
|
128
|
+
is the row DTV hands out for it. `App` passes it to
|
|
129
|
+
`rowSelection.onRowSelectionChange` and `rowClassFunction` for the views it is
|
|
130
|
+
given:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const paymentRequestsView = DSL.view({ ..., columnDefinitions: [...] });
|
|
134
|
+
type PaymentRequestRow = SimplifiedRow<typeof paymentRequestsView>;
|
|
135
|
+
|
|
136
|
+
<App
|
|
137
|
+
views={[paymentRequestsView]}
|
|
138
|
+
rowSelection={{
|
|
139
|
+
rowSelectionType: 'multiple',
|
|
140
|
+
onRowSelectionChange: rows => setSelected(rows), // PaymentRequestRow[]
|
|
141
|
+
}}
|
|
142
|
+
/>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Such a row is every column's data merged into one object (`simplifyRow`), so
|
|
146
|
+
it holds only what the columns select, not the whole row type: a field no
|
|
147
|
+
column queries is a type error, as it would be `undefined` at run time. To
|
|
148
|
+
read a field the table does not show, select it with a `virtualColumn()`. A
|
|
149
|
+
`fieldColumn()` puts its field on the row typed as its renderer takes it.
|
|
150
|
+
|
|
151
|
+
The types are kept only while nothing widens them: a view annotated as
|
|
152
|
+
`View` (for example as the return type of a factory), parsed from JSON or
|
|
153
|
+
built from columns that are not typed hands out `Record<string, unknown>`
|
|
154
|
+
rows. A typed view with some untyped columns gets `Record<string, unknown>`
|
|
155
|
+
merged in, so its other fields keep their types. Several views give a union of
|
|
156
|
+
their rows. `View` on its own is `View<ColumnDefinition[]>`: any view, with no
|
|
157
|
+
promise about its rows.
|
|
158
|
+
|
|
159
|
+
A renderer for a JSON view (in a runtime) gets `unknown` data, since nothing
|
|
160
|
+
checks what the JSON selects; it says what it reads, e.g.
|
|
161
|
+
`CellRenderer<{ amount: number }>` or `RowExpansionRenderer<Data, true>` for a
|
|
162
|
+
lazy expansion.
|
|
163
|
+
|
|
106
164
|
## Filters
|
|
107
165
|
|
|
108
166
|
```ts
|
package/docs/typegen.md
CHANGED
|
@@ -103,7 +103,7 @@ That file contains:
|
|
|
103
103
|
|
|
104
104
|
The generator also edits the view module itself, as a convenience: it imports
|
|
105
105
|
`<ViewIdPascal>RowType` and adds `rowType:` to the `DSL.column(...)`,
|
|
106
|
-
`DSL.virtualColumn(...)`, `DSL.fieldColumn(...)` and `DSL.filter(...)` calls
|
|
106
|
+
`DSL.virtualColumn(...)`, `DSL.fieldColumn(...)`, `DSL.rowExpansion(...)` and `DSL.filter(...)` calls
|
|
107
107
|
written inline in the `DSL.view({ ... })` argument that do not have one yet. Calls that already pass `rowType` are left alone, so
|
|
108
108
|
re-running the generator is safe.
|
|
109
109
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronor/dtv",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Schema-driven, declarative table views with advanced filtering, data fetching and AI-assisted filter generation.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"react-dom": "^19.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@kronor/hasura-graphql": "^0.
|
|
61
|
+
"@kronor/hasura-graphql": "^0.2.0",
|
|
62
62
|
"commander": "^14.0.0",
|
|
63
63
|
"fast-glob": "^3.3.3",
|
|
64
64
|
"graphql": "^16.14.2",
|