@kronor/dtv 9.3.0 → 9.4.1
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/README.md +8 -2
- package/dist/cli/commands/definitions.js +76 -0
- package/dist/cli/config/loadConfig.js +69 -5
- package/dist/cli/definitions/discover.js +130 -0
- package/dist/cli/definitions/generate.js +261 -0
- package/dist/cli/definitions/loadProject.js +107 -0
- package/dist/cli/definitions/project.js +122 -0
- package/dist/cli/definitions/resolve.js +53 -0
- package/dist/cli/definitions/run.js +223 -0
- package/dist/cli/definitions/types.js +8 -0
- package/dist/cli/definitions/wire.js +111 -0
- package/dist/cli/dtv.js +2 -0
- package/dist/cli/typegen/runTypegen.js +4 -3
- package/dist/index.es.js +14103 -13451
- package/dist/types/components/UserPreferencesPanel.d.ts +2 -1
- package/dist/types/dsl/index.d.ts +1 -0
- package/dist/types/dsl/migrations.d.ts +114 -0
- package/dist/types/framework/decoder.d.ts +61 -0
- package/dist/types/framework/filter-form-state.d.ts +18 -2
- package/dist/types/framework/filter-sharing.d.ts +21 -9
- package/dist/types/framework/runtime.d.ts +2 -0
- package/dist/types/framework/saved-filters.d.ts +10 -14
- package/dist/types/framework/state/app-state.d.ts +8 -0
- package/dist/types/framework/useUserDataManager.d.ts +3 -0
- package/dist/types/framework/user-data-errors.d.ts +8 -0
- package/dist/types/framework/user-data-manager.d.ts +6 -1
- package/dist/types/framework/user-data-undecoded.d.ts +86 -0
- package/dist/types/framework/user-data.d.ts +120 -33
- package/dist/types/framework/user-data.migrations.d.ts +9 -8
- package/dist/types/framework/view-migrations.d.ts +112 -0
- package/dist/types/framework/view-parser.d.ts +2 -1
- package/dist/types/framework/view-projection.d.ts +52 -0
- package/dist/types/framework/view.d.ts +7 -0
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/typegen/index.d.ts +26 -4
- package/docs/typegen.md +12 -0
- package/docs/view-migrations.md +183 -0
- package/package.json +1 -1
|
@@ -1,63 +1,150 @@
|
|
|
1
|
-
import { ViewId } from './view';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { ViewId, type View } from './view';
|
|
2
|
+
import type { DataOrdering } from './data-ordering';
|
|
3
|
+
import { type SavedFilter } from './saved-filters';
|
|
4
|
+
import { FilterGroups, FilterId } from './filters';
|
|
4
5
|
import { FilterState } from './state';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { type DecodeIssue } from './decoder';
|
|
7
|
+
import { Result } from './result';
|
|
8
|
+
import { type UndecodedViewData, type UserDataWithUndecodedViews, type UserPreferences } from './user-data-undecoded';
|
|
9
|
+
import { type UserDataJsonObject, type UserDataMigrationError } from './user-data.migrations';
|
|
10
|
+
import { type ViewMigrationChain } from './view-migrations';
|
|
11
|
+
import { type ViewProjection } from './view-projection';
|
|
12
|
+
export { INITIAL_USERDATA_FORMAT_REVISION, REVISION_2026_01_05, REVISION_2026_01_29, REVISION_2026_03_26, REVISION_2026_05_06, REVISION_2026_10_25 } from './user-data.migrations';
|
|
13
|
+
export { defaultUserPreferences, type UserPreferences } from './user-data-undecoded';
|
|
10
14
|
export interface ViewData {
|
|
11
15
|
columnOrder: string[] | null;
|
|
12
16
|
hiddenColumns: string[];
|
|
13
17
|
rowsPerPage: number | null;
|
|
18
|
+
syncOrderingToUserData: boolean;
|
|
19
|
+
ordering: DataOrdering | null;
|
|
14
20
|
syncFilterStateToUserData: boolean;
|
|
15
21
|
persistedFilterState: FilterState | null;
|
|
16
22
|
savedFilters: SavedFilter[];
|
|
17
23
|
}
|
|
24
|
+
/** A saved filter as JSON, as `onLoad` and `onSave` hand it over. */
|
|
25
|
+
export interface SavedFilterJson {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
view: string;
|
|
29
|
+
state: unknown;
|
|
30
|
+
createdAt: string | Date;
|
|
31
|
+
formatRevision: string;
|
|
32
|
+
}
|
|
33
|
+
/** A view's user data as JSON, as `onLoad` and `onSave` hand it over. */
|
|
18
34
|
export interface ViewDataJson {
|
|
19
35
|
columnOrder: string[] | null;
|
|
20
36
|
hiddenColumns: string[];
|
|
21
37
|
rowsPerPage: number | null;
|
|
38
|
+
syncOrderingToUserData?: boolean;
|
|
39
|
+
ordering?: DataOrdering | null;
|
|
22
40
|
syncFilterStateToUserData?: boolean;
|
|
23
41
|
persistedFilterState?: unknown;
|
|
24
42
|
savedFilters: SavedFilterJson[];
|
|
43
|
+
definitionRevision?: number;
|
|
44
|
+
}
|
|
45
|
+
/** User data as JSON, as `onLoad` and `onSave` hand it over. */
|
|
46
|
+
export interface UserDataJson {
|
|
47
|
+
preferences: UserPreferences;
|
|
48
|
+
views: Record<ViewId, ViewDataJson>;
|
|
49
|
+
revision: number;
|
|
50
|
+
formatRevision: string;
|
|
25
51
|
}
|
|
26
|
-
export type UserPreferences = {
|
|
27
|
-
/**
|
|
28
|
-
* When set, overrides the App option `syncFilterStateToUrl`.
|
|
29
|
-
* - `true`: always sync filter state to URL
|
|
30
|
-
* - `false`: never sync filter state to URL
|
|
31
|
-
* - `null`: use the App option
|
|
32
|
-
*/
|
|
33
|
-
syncFilterStateToUrlOverride: boolean | null;
|
|
34
|
-
/**
|
|
35
|
-
* When enabled, closes the filters panel after applying the current filter state.
|
|
36
|
-
*/
|
|
37
|
-
closeFilterPanelOnApply: boolean;
|
|
38
|
-
};
|
|
39
52
|
export interface UserData {
|
|
40
53
|
preferences: UserPreferences;
|
|
54
|
+
/** The views decoded against their definitions. */
|
|
41
55
|
views: Record<ViewId, ViewData>;
|
|
56
|
+
/**
|
|
57
|
+
* Views kept as they were stored, and written back unchanged: views without a definition
|
|
58
|
+
* here (other apps' or other tables' views share the user data), views written for a
|
|
59
|
+
* newer revision of their definition, and views that failed to decode.
|
|
60
|
+
*/
|
|
61
|
+
retainedViews: Record<ViewId, UndecodedViewData>;
|
|
42
62
|
/**
|
|
43
63
|
* Monotonic per-writer revision number, incremented on each persisted change.
|
|
44
64
|
*/
|
|
45
65
|
revision: number;
|
|
46
66
|
formatRevision: string;
|
|
47
67
|
}
|
|
48
|
-
export interface UserDataJson {
|
|
49
|
-
preferences: UserPreferences;
|
|
50
|
-
views: Record<ViewId, ViewDataJson>;
|
|
51
|
-
revision: number;
|
|
52
|
-
formatRevision: string;
|
|
53
|
-
}
|
|
54
|
-
export declare const defaultUserPreferences: UserPreferences;
|
|
55
68
|
export declare function defaultUserData(): UserData;
|
|
56
69
|
export declare function defaultViewData(): ViewData;
|
|
57
|
-
export declare function toUserDataJson(data: UserData, filterGroupsByViewId: Record<ViewId, FilterGroups>): UserDataJson;
|
|
58
|
-
export declare function fromUserDataJson(json: UserDataJson, filterGroupsByViewId: Record<ViewId, FilterGroups>): UserData;
|
|
59
70
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
71
|
+
* What is stored before anything is: user data at the first format revision, so that the
|
|
72
|
+
* user-data-level migrations bring in what earlier versions kept elsewhere.
|
|
73
|
+
*/
|
|
74
|
+
export declare function initialUserDataJson(): UserDataJsonObject;
|
|
75
|
+
export type UserDataDecodeError =
|
|
76
|
+
/** Not user data at all. */
|
|
77
|
+
{
|
|
78
|
+
kind: 'malformed';
|
|
79
|
+
issue: DecodeIssue;
|
|
80
|
+
}
|
|
81
|
+
/** User data at a format revision this version cannot migrate from, e.g. a newer one. */
|
|
82
|
+
| {
|
|
83
|
+
kind: 'migrationFailed';
|
|
84
|
+
error: UserDataMigrationError;
|
|
85
|
+
};
|
|
86
|
+
export type UserDataDecoding = {
|
|
87
|
+
data: UserDataWithUndecodedViews;
|
|
88
|
+
/** Whether user-data-level migrations changed the data. */
|
|
89
|
+
migrated: boolean;
|
|
90
|
+
/** What the decoders worked around. */
|
|
91
|
+
issues: DecodeIssue[];
|
|
92
|
+
};
|
|
93
|
+
/** Migrates stored user data to the current format and decodes it, up to the views. */
|
|
94
|
+
export declare function decodeUserData(json: unknown): Result<UserDataDecodeError, UserDataDecoding>;
|
|
95
|
+
/** Filters reset while decoding a view, because their stored state no longer fit the view. */
|
|
96
|
+
export type ViewResets = {
|
|
97
|
+
viewId: ViewId;
|
|
98
|
+
persistedFilterState: FilterId[];
|
|
99
|
+
savedFilters: Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
filterIds: FilterId[];
|
|
102
|
+
}>;
|
|
103
|
+
};
|
|
104
|
+
export type ViewDataDecoding = {
|
|
105
|
+
viewData: ViewData;
|
|
106
|
+
/** `null` when nothing was reset. */
|
|
107
|
+
resets: ViewResets | null;
|
|
108
|
+
};
|
|
109
|
+
export declare function decodeViewData(viewId: ViewId, stored: UndecodedViewData, filterGroups: FilterGroups): ViewDataDecoding;
|
|
110
|
+
export declare function encodeViewData(viewData: ViewData, filterGroups: FilterGroups, definitionRevision?: number): UndecodedViewData;
|
|
111
|
+
/** What a view's user data is migrated with: its definition's migrations, and the definition as it is now. */
|
|
112
|
+
export type ViewMigrationContext = {
|
|
113
|
+
chain: ViewMigrationChain;
|
|
114
|
+
/** The projection of the live definition, to compare with the chain's latest snapshot. */
|
|
115
|
+
live: ViewProjection;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The migration context of a view with migrations. Logs an error when the view's filters
|
|
119
|
+
* changed since its latest snapshot: `dtv definitions snapshot` has not been run for the change.
|
|
120
|
+
* Columns are not compared: an instance may lack a column its snapshot has (or have one
|
|
121
|
+
* more), e.g. one shown only when the app passes row actions, and stored column ids of
|
|
122
|
+
* absent columns are harmless; `dtv definitions check` compares them.
|
|
123
|
+
*/
|
|
124
|
+
export declare function viewMigrationContext(view: View): ViewMigrationContext | undefined;
|
|
125
|
+
export type ViewsDecoding = {
|
|
126
|
+
userData: UserData;
|
|
127
|
+
resets: ViewResets[];
|
|
128
|
+
/** Whether view-level migrations changed any view's data. */
|
|
129
|
+
migrated: boolean;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Decodes the views this app defines; the others are retained. Views with migrations are
|
|
133
|
+
* migrated to their definition's current revision first, and a view renamed between
|
|
134
|
+
* snapshots takes over the data stored under its old id. A view stored for a newer
|
|
135
|
+
* revision than this app knows, or that fails to decode, is retained too, so that what is
|
|
136
|
+
* stored is not lost to this version's reading.
|
|
137
|
+
*/
|
|
138
|
+
export declare function decodeViews(data: UserDataWithUndecodedViews, filterGroupsByViewId: Record<ViewId, FilterGroups>, migrationsByViewId?: Record<ViewId, ViewMigrationContext>): ViewsDecoding;
|
|
139
|
+
export type UserDataRead = ViewsDecoding & {
|
|
140
|
+
issues: DecodeIssue[];
|
|
141
|
+
};
|
|
142
|
+
/** Stored user data in memory: migrated, decoded up to the views, and the views migrated and decoded. */
|
|
143
|
+
export declare function readUserData(json: unknown, filterGroupsByViewId: Record<ViewId, FilterGroups>, migrationsByViewId?: Record<ViewId, ViewMigrationContext>): Result<UserDataDecodeError, UserDataRead>;
|
|
144
|
+
/**
|
|
145
|
+
* User data as stored. Views are layered: `baseViews` (what is stored already), then the
|
|
146
|
+
* retained views, then the decoded ones, encoded. A view written for a newer revision of its
|
|
147
|
+
* definition is never replaced by what this version makes of it, and data stored under the
|
|
148
|
+
* old id of a renamed view is dropped once the view wrote its own.
|
|
62
149
|
*/
|
|
63
|
-
export declare function
|
|
150
|
+
export declare function encodeUserData(data: UserData, filterGroupsByViewId: Record<ViewId, FilterGroups>, baseViews?: Record<ViewId, UndecodedViewData>, migrationsByViewId?: Record<ViewId, ViewMigrationContext>): UserDataWithUndecodedViews;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { FilterGroups } from './filters';
|
|
2
|
-
import { type UserData } from './user-data';
|
|
3
|
-
import { ViewId } from './view';
|
|
4
1
|
import { type Result } from './result';
|
|
2
|
+
export declare const INITIAL_USERDATA_FORMAT_REVISION = "1970-01-01T00:00:00.000Z";
|
|
3
|
+
export declare const REVISION_2026_01_05 = "2026-01-05T00:00:00.000Z";
|
|
4
|
+
export declare const REVISION_2026_01_29 = "2026-01-29T00:00:00.000Z";
|
|
5
|
+
export declare const REVISION_2026_03_26 = "2026-03-26T00:00:00.000Z";
|
|
6
|
+
export declare const REVISION_2026_05_06 = "2026-05-06T00:00:00.000Z";
|
|
7
|
+
export declare const REVISION_2026_10_25 = "2026-10-25T00:00:00.000Z";
|
|
5
8
|
export declare const SAVED_FILTERS_MIGRATED_TO_USERDATA_KEY = "dtvSavedFiltersMigratedToUserData";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
+
/** Stored user data as JSON: only its top level is known to be an object. */
|
|
10
|
+
export type UserDataJsonObject = Record<string, unknown>;
|
|
9
11
|
export declare const CURRENT_USERDATA_FORMAT_REVISION: string;
|
|
10
12
|
export type UserDataMigrationError = {
|
|
11
13
|
kind: 'outOfOrder';
|
|
@@ -26,5 +28,4 @@ export type UserDataMigrationError = {
|
|
|
26
28
|
expectedRevision: string;
|
|
27
29
|
};
|
|
28
30
|
export declare function userDataMigrationErrorToMessage(err: UserDataMigrationError): string;
|
|
29
|
-
export declare function applyUserDataMigrations(
|
|
30
|
-
export {};
|
|
31
|
+
export declare function applyUserDataMigrations(json: UserDataJsonObject): Result<UserDataMigrationError, UserDataJsonObject>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Json } from './decoder';
|
|
2
|
+
import type { FilterId } from './filters';
|
|
3
|
+
import { type UndecodedFilterFormState, type UndecodedFilterState, type UndecodedViewData } from './user-data-undecoded';
|
|
4
|
+
import { type ViewProjection } from './view-projection';
|
|
5
|
+
/** Returned by a `custom` migration to reset the filter instead. */
|
|
6
|
+
export declare const RESET: unique symbol;
|
|
7
|
+
/** Returned by a `mapValues` function to clear the value instead. */
|
|
8
|
+
export declare const DROP: unique symbol;
|
|
9
|
+
export type MigrationOp = {
|
|
10
|
+
readonly kind: 'renameFilter';
|
|
11
|
+
readonly from: FilterId;
|
|
12
|
+
readonly to: FilterId;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'keep';
|
|
15
|
+
readonly filterId: FilterId;
|
|
16
|
+
readonly because: string;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'reset';
|
|
19
|
+
readonly filterId: FilterId;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'drop';
|
|
22
|
+
readonly filterId: FilterId;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'mapValues';
|
|
25
|
+
readonly filterId: FilterId;
|
|
26
|
+
readonly map: (value: Json) => Json | typeof DROP;
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: 'mapOperators';
|
|
29
|
+
readonly filterId: FilterId;
|
|
30
|
+
readonly map: Readonly<Record<string, string | null>>;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: 'custom';
|
|
33
|
+
readonly from: FilterId;
|
|
34
|
+
readonly to: FilterId;
|
|
35
|
+
readonly migrate: (state: UndecodedFilterFormState) => UndecodedFilterFormState | typeof RESET;
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: 'renameColumn';
|
|
38
|
+
readonly from: string;
|
|
39
|
+
readonly to: string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: 'dropColumn';
|
|
42
|
+
readonly columnId: string;
|
|
43
|
+
}
|
|
44
|
+
/** The column sorts by another field: a stored sort by its old field is reset. */
|
|
45
|
+
| {
|
|
46
|
+
readonly kind: 'resetSort';
|
|
47
|
+
readonly columnId: string;
|
|
48
|
+
}
|
|
49
|
+
/** A decision left open by `dtv definitions snapshot`. Fails the check; at runtime it resets `subject` if it is a filter. */
|
|
50
|
+
| {
|
|
51
|
+
readonly kind: 'todo';
|
|
52
|
+
readonly subject: string;
|
|
53
|
+
readonly message: string;
|
|
54
|
+
};
|
|
55
|
+
export type ViewMigration = {
|
|
56
|
+
readonly from: ViewProjection;
|
|
57
|
+
readonly to: ViewProjection;
|
|
58
|
+
readonly ops: readonly MigrationOp[];
|
|
59
|
+
};
|
|
60
|
+
/** The snapshots of a view definition, oldest first, and the migrations between them. */
|
|
61
|
+
export type ViewMigrationChain = {
|
|
62
|
+
readonly baseline: ViewProjection;
|
|
63
|
+
readonly migrations: readonly ViewMigration[];
|
|
64
|
+
/** The current revision of the definition. */
|
|
65
|
+
readonly latest: ViewProjection;
|
|
66
|
+
};
|
|
67
|
+
/** Checks that the migrations follow on from each other, starting at `baseline`. */
|
|
68
|
+
export declare function viewMigrationChain(baseline: ViewProjection, migrations: readonly ViewMigration[]): ViewMigrationChain;
|
|
69
|
+
/** What `op` does to the snapshot `projection` of a migration to `to`. */
|
|
70
|
+
export declare function applySchema(op: MigrationOp, projection: ViewProjection, to: ViewProjection): ViewProjection;
|
|
71
|
+
export type MigrationProblem = {
|
|
72
|
+
readonly message: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* What `migration` leaves uncovered: replaying its operations over the older snapshot has
|
|
76
|
+
* to give the newer one, except for filters and columns the newer one adds. Undecided
|
|
77
|
+
* `todo`s are problems too.
|
|
78
|
+
*/
|
|
79
|
+
export declare function checkMigration(migration: ViewMigration): MigrationProblem[];
|
|
80
|
+
/** Filters reset by migrations, or that lost stored values to them (`mapValues`, `mapOperators`), where they were stored. */
|
|
81
|
+
export type MigrationResets = {
|
|
82
|
+
persistedFilterState: FilterId[];
|
|
83
|
+
savedFilters: Array<{
|
|
84
|
+
name: string;
|
|
85
|
+
filterIds: FilterId[];
|
|
86
|
+
}>;
|
|
87
|
+
};
|
|
88
|
+
export type ViewDataMigration = {
|
|
89
|
+
data: UndecodedViewData;
|
|
90
|
+
resets: MigrationResets;
|
|
91
|
+
};
|
|
92
|
+
/** Applies one migration's state side to a view's stored data. */
|
|
93
|
+
export declare function applyToViewData(migration: ViewMigration, data: UndecodedViewData): ViewDataMigration;
|
|
94
|
+
export declare function mergeResets(left: MigrationResets, right: MigrationResets): MigrationResets;
|
|
95
|
+
export declare const noResets: () => MigrationResets;
|
|
96
|
+
/**
|
|
97
|
+
* Takes a view's stored data from the revision it was written for to the chain's latest.
|
|
98
|
+
* Data at or past the latest revision is returned as it is.
|
|
99
|
+
*/
|
|
100
|
+
export declare function migrateViewData(chain: ViewMigrationChain, data: UndecodedViewData): ViewDataMigration;
|
|
101
|
+
/**
|
|
102
|
+
* Drops the stored state of filters whose definition differs from the chain's latest
|
|
103
|
+
* snapshot: the definition changed and no migration was generated for it yet, so the
|
|
104
|
+
* stored state cannot be trusted to fit.
|
|
105
|
+
*/
|
|
106
|
+
export declare function resetFiltersChangedSinceSnapshot(latest: ViewProjection, live: ViewProjection, data: UndecodedViewData): ViewDataMigration;
|
|
107
|
+
/** The revision of the definition user data is written for; without migrations, the baseline. */
|
|
108
|
+
export declare function currentDefinitionRevision(chain: ViewMigrationChain | undefined): number;
|
|
109
|
+
/** A single filter state (e.g. a shared one) taken from `revision` to the chain's latest. */
|
|
110
|
+
export declare function migrateFilterState(chain: ViewMigrationChain, revision: number, state: UndecodedFilterState): UndecodedFilterState;
|
|
111
|
+
/** The definition ids older snapshots had, latest first, other than the latest's. */
|
|
112
|
+
export declare function previousDefinitions(chain: ViewMigrationChain): string[];
|
|
@@ -5,7 +5,7 @@ import type { Runtime } from './runtime';
|
|
|
5
5
|
import type { HasuraFilterExpression, HasuraOrderBy } from './graphql';
|
|
6
6
|
import { type OrderDirection } from './order-direction';
|
|
7
7
|
export type RuntimeReference = {
|
|
8
|
-
section: 'cellRenderers' | 'noRowsComponents' | 'rowExpansions' | 'columnFooters' | 'customFilterComponents' | 'queryTransforms' | 'initialValues' | 'suggestionFetchers';
|
|
8
|
+
section: 'cellRenderers' | 'noRowsComponents' | 'rowExpansions' | 'columnFooters' | 'customFilterComponents' | 'queryTransforms' | 'initialValues' | 'suggestionFetchers' | 'viewMigrations';
|
|
9
9
|
key: string;
|
|
10
10
|
};
|
|
11
11
|
export declare function resolveRuntimeReference<T>(reference: RuntimeReference, externalRuntime: Runtime | undefined, builtInRuntime: Runtime): T;
|
|
@@ -204,6 +204,7 @@ export type ViewJson = {
|
|
|
204
204
|
staticConditions?: HasuraFilterExpression[];
|
|
205
205
|
staticOrdering?: HasuraOrderBy[];
|
|
206
206
|
noRowsComponent?: RuntimeReference;
|
|
207
|
+
migrations?: RuntimeReference;
|
|
207
208
|
rowExpansion?: {
|
|
208
209
|
data: FieldQueryJson[];
|
|
209
210
|
runtime: RuntimeReference;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FilterExpr } from './filters';
|
|
2
|
+
import { type View } from './view';
|
|
3
|
+
export type ControlProjection = {
|
|
4
|
+
readonly type: 'text' | 'number' | 'date' | 'dropdown' | 'multiselect' | 'custom';
|
|
5
|
+
} | {
|
|
6
|
+
readonly type: 'autocomplete';
|
|
7
|
+
readonly multiple: boolean;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: 'customOperator';
|
|
10
|
+
readonly operators: readonly string[];
|
|
11
|
+
readonly valueControl: ControlProjection;
|
|
12
|
+
};
|
|
13
|
+
export type FieldProjection = string | {
|
|
14
|
+
readonly and: readonly string[];
|
|
15
|
+
} | {
|
|
16
|
+
readonly or: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
export type LeafComparison = Extract<FilterExpr, {
|
|
19
|
+
field: unknown;
|
|
20
|
+
}>['type'];
|
|
21
|
+
export type FilterProjection = {
|
|
22
|
+
readonly kind: 'leaf';
|
|
23
|
+
readonly cmp: LeafComparison;
|
|
24
|
+
readonly field: FieldProjection;
|
|
25
|
+
readonly control: ControlProjection;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'and' | 'or';
|
|
28
|
+
readonly children: readonly FilterProjection[];
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'not';
|
|
31
|
+
readonly child: FilterProjection;
|
|
32
|
+
};
|
|
33
|
+
export type ColumnProjection = {
|
|
34
|
+
/** The field the column sorts by; `null` when it cannot be sorted. */
|
|
35
|
+
readonly orderBy: string | null;
|
|
36
|
+
};
|
|
37
|
+
export type ViewProjection = {
|
|
38
|
+
/** The definition's id: the literal id given to `view()`, which instances may derive their ids from. */
|
|
39
|
+
readonly definition: string;
|
|
40
|
+
readonly revision: number;
|
|
41
|
+
readonly filters: {
|
|
42
|
+
readonly [filterId: string]: FilterProjection;
|
|
43
|
+
};
|
|
44
|
+
readonly columns: {
|
|
45
|
+
readonly [columnId: string]: ColumnProjection;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export declare function projectFilter(expression: FilterExpr): FilterProjection;
|
|
49
|
+
/** The projection of `view`, as revision `revision` of the definition `definition`. */
|
|
50
|
+
export declare function projectView(view: View, definition: string, revision: number): ViewProjection;
|
|
51
|
+
/** Whether two projections (or parts of them) are the same. Key order does not matter. */
|
|
52
|
+
export declare function projectionsEqual(left: unknown, right: unknown): boolean;
|
|
@@ -6,6 +6,7 @@ import { FilterState } from "./state";
|
|
|
6
6
|
import { FilterFormState } from "./filter-form-state";
|
|
7
7
|
import { HasuraFilterExpression, HasuraOrderBy } from "./graphql";
|
|
8
8
|
import type { OrderDirection } from "./order-direction";
|
|
9
|
+
import type { ViewMigrationChain } from "./view-migrations";
|
|
9
10
|
export type NoRowsComponentProps = {
|
|
10
11
|
setFilterState: (updater: (currentState: FilterState) => FilterState) => void;
|
|
11
12
|
filterState: FilterState;
|
|
@@ -73,6 +74,12 @@ type ViewBase = {
|
|
|
73
74
|
noRowsComponent?: NoRowsComponent;
|
|
74
75
|
staticConditions?: HasuraFilterExpression[];
|
|
75
76
|
staticOrdering?: HasuraOrderBy[];
|
|
77
|
+
/**
|
|
78
|
+
* The view definition's snapshots and the migrations between them, which take the user
|
|
79
|
+
* data stored for the view to the definition's current revision. Generated by
|
|
80
|
+
* `dtv definitions snapshot`.
|
|
81
|
+
*/
|
|
82
|
+
migrations?: ViewMigrationChain;
|
|
76
83
|
};
|
|
77
84
|
export type CollectionView = ViewBase & {
|
|
78
85
|
source: CollectionViewSource;
|
|
@@ -5,6 +5,10 @@ export type { AIIntegration, ModifyAiFilterPromptFn, RequestAiFilterFn } from '.
|
|
|
5
5
|
export type { View } from '../framework/view';
|
|
6
6
|
export { getViewRootFieldName, getViewStaticArgs } from '../framework/view';
|
|
7
7
|
export type { ViewJson, ColumnDefinitionJson } from '../framework/view';
|
|
8
|
+
export type { ViewProjection, FilterProjection, ColumnProjection, ControlProjection } from '../framework/view-projection';
|
|
9
|
+
export type { ViewMigration, ViewMigrationChain } from '../framework/view-migrations';
|
|
10
|
+
export { projectView, projectionsEqual } from '../framework/view-projection';
|
|
11
|
+
export { checkMigration } from '../framework/view-migrations';
|
|
8
12
|
export type { RowExpansionDefinition, RowExpansionRenderer, RowExpansionRendererProps, RowExpansionRuntimeEntry, } from '../framework/view';
|
|
9
13
|
export type { Runtime } from '../framework/runtime';
|
|
10
14
|
export type { ColumnDefinition } from '../framework/column-definition';
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
export type DtvSchemaConfig = {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
};
|
|
1
5
|
export type DtvTypegenConfig = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The GraphQL schema typegen reads. A function is only called by `dtv typegen`, so that
|
|
8
|
+
* other commands do not need what it needs (e.g. an admin secret from the environment).
|
|
9
|
+
*/
|
|
10
|
+
schema: DtvSchemaConfig | (() => DtvSchemaConfig | Promise<DtvSchemaConfig>);
|
|
6
11
|
scan: {
|
|
7
12
|
include: string[];
|
|
8
13
|
exclude?: string[];
|
|
@@ -26,6 +31,23 @@ export type DtvTypegenConfig = {
|
|
|
26
31
|
* graphql-codegen option.
|
|
27
32
|
*/
|
|
28
33
|
immutableTypes?: boolean;
|
|
34
|
+
/** `dtv definitions`: snapshots of view definitions and migrations of their user data. */
|
|
35
|
+
definitions?: {
|
|
36
|
+
/**
|
|
37
|
+
* View factories `dtv definitions` cannot build with arguments made up from their parameter
|
|
38
|
+
* types, by export name (or `path/to/module.ts#name` when several modules export the
|
|
39
|
+
* name): the arguments to build them with, and the definition id when the id the
|
|
40
|
+
* factory makes is computed from its arguments.
|
|
41
|
+
*/
|
|
42
|
+
factories?: Record<string, {
|
|
43
|
+
definition?: string;
|
|
44
|
+
args?: unknown[];
|
|
45
|
+
}>;
|
|
46
|
+
/** Where migrations go for views whose module is not found (default `dtv-migrations`). */
|
|
47
|
+
migrationsDir?: string;
|
|
48
|
+
/** Vite config to load the views with (default: vite.config.* next to dtv.config.ts). */
|
|
49
|
+
viteConfig?: string;
|
|
50
|
+
};
|
|
29
51
|
debug?: {
|
|
30
52
|
/** Include original GraphQL type references as comments in generated output. */
|
|
31
53
|
includeGraphqlTypeComments?: boolean;
|
package/docs/typegen.md
CHANGED
|
@@ -77,6 +77,18 @@ const config: DtvTypegenConfig = {
|
|
|
77
77
|
export default config;
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
`schema` may also be a function returning the same object (or a promise of it). Only `dtv typegen`
|
|
81
|
+
calls it, so other commands reading `dtv.config.ts` (`dtv definitions`) do not need what it needs, e.g. a
|
|
82
|
+
secret from the environment:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
schema: () => {
|
|
86
|
+
const secret = process.env.HASURA_GRAPHQL_ADMIN_SECRET;
|
|
87
|
+
if (!secret) throw new Error('HASURA_GRAPHQL_ADMIN_SECRET is required for type generation.');
|
|
88
|
+
return { endpoint: 'https://my-hasura.example.com/v1/graphql', headers: { 'x-hasura-admin-secret': secret } };
|
|
89
|
+
},
|
|
90
|
+
```
|
|
91
|
+
|
|
80
92
|
## Output
|
|
81
93
|
|
|
82
94
|
For each discovered `DSL.view({ id, collectionName, ... })` call, the generator writes one file next to the view source file, named by `output.fileNamePattern`.
|