@kronor/dtv 13.0.1 → 13.0.2
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.
|
@@ -70,6 +70,32 @@ export type UndecodedFilterFormStateFor<F> = F extends {
|
|
|
70
70
|
child: UndecodedFilterFormStateFor<Child>;
|
|
71
71
|
} : never;
|
|
72
72
|
type StateOf<P extends ViewProjection, Id extends keyof P['filters']> = UndecodedFilterFormStateFor<P['filters'][Id]>;
|
|
73
|
+
type OneValueControl = {
|
|
74
|
+
type: 'dropdown';
|
|
75
|
+
} | {
|
|
76
|
+
type: 'autocomplete';
|
|
77
|
+
multiple: false;
|
|
78
|
+
};
|
|
79
|
+
type ListControl = {
|
|
80
|
+
type: 'multiselect';
|
|
81
|
+
} | {
|
|
82
|
+
type: 'autocomplete';
|
|
83
|
+
multiple: true;
|
|
84
|
+
};
|
|
85
|
+
/** The comparison of a filter taking one value, and of the same filter taking a list of them. */
|
|
86
|
+
type ListComparison<One, List> = Same<One, List> extends true ? true : [One, List] extends ['equals', 'in'] | ['notEquals', 'notIn'] ? true : false;
|
|
87
|
+
/** Whether the filter `F` became `T` by taking a list of the values it took one of, on the same field. */
|
|
88
|
+
export type WrapsInList<F, T> = F extends {
|
|
89
|
+
kind: 'leaf';
|
|
90
|
+
cmp: infer FromCmp;
|
|
91
|
+
field: infer FromField;
|
|
92
|
+
control: OneValueControl;
|
|
93
|
+
} ? T extends {
|
|
94
|
+
kind: 'leaf';
|
|
95
|
+
cmp: infer ToCmp;
|
|
96
|
+
field: infer ToField;
|
|
97
|
+
control: ListControl;
|
|
98
|
+
} ? Same<FromField, ToField> extends true ? ListComparison<FromCmp, ToCmp> : false : false : false;
|
|
73
99
|
/** A value a filter's items offer, when the snapshot has them; any value otherwise. */
|
|
74
100
|
export type ItemValueOf<P extends ViewProjection, Id extends string> = P extends {
|
|
75
101
|
items: infer Items;
|
|
@@ -101,6 +127,12 @@ export interface MigrationBuilder<From extends ViewProjection, To extends ViewPr
|
|
|
101
127
|
mapOperators<Id extends FilterIdOf<From> & FilterIdOf<To>>(id: Id, map: {
|
|
102
128
|
[O in Exclude<OperatorsOf<From['filters'][Id]>, OperatorsOf<To['filters'][Id]>>]: OperatorsOf<To['filters'][Id]> | null;
|
|
103
129
|
}): MigrationOp;
|
|
130
|
+
/**
|
|
131
|
+
* The filter takes several values where it took one, on the same field: a dropdown became
|
|
132
|
+
* a multiselect, or an autocomplete `multiple` (comparing with `in` where it compared with
|
|
133
|
+
* `equals`). A value stored for it becomes a list of that value.
|
|
134
|
+
*/
|
|
135
|
+
wrapInList<Id extends FilterIdOf<From> & FilterIdOf<To>>(id: Id & Check<WrapsInList<From['filters'][Id], To['filters'][Id]>, `wrapInList: "${Id}" did not go from one value to a list of them on the same field; use custom() or reset()`>): MigrationOp;
|
|
104
136
|
/** Turn what is stored for `from` into a state of `to`, or `RESET`. */
|
|
105
137
|
custom<A extends FilterIdOf<From>, B extends FilterIdOf<To>>(from: A, to: B, migrate: (state: StateOf<From, A>) => StateOf<To, B> | typeof RESET): MigrationOp;
|
|
106
138
|
renameColumn<A extends ColumnIdOf<From>, B extends ColumnIdOf<To>>(from: A, to: B): MigrationOp;
|
|
@@ -28,6 +28,11 @@ export type MigrationOp = {
|
|
|
28
28
|
readonly kind: 'mapOperators';
|
|
29
29
|
readonly filterId: FilterId;
|
|
30
30
|
readonly map: Readonly<Record<string, string | null>>;
|
|
31
|
+
}
|
|
32
|
+
/** The filter takes several values where it took one: a value stored for it becomes a list of that value. */
|
|
33
|
+
| {
|
|
34
|
+
readonly kind: 'wrapInList';
|
|
35
|
+
readonly filterId: FilterId;
|
|
31
36
|
} | {
|
|
32
37
|
readonly kind: 'custom';
|
|
33
38
|
readonly from: FilterId;
|
package/docs/view-migrations.md
CHANGED
|
@@ -126,7 +126,8 @@ writes `m.todo(…)` with the candidates in comments. **A `todo` does not type-c
|
|
|
126
126
|
| Filter removed and exactly one added with the same definition, matching no other | `m.renameFilter(old, new)` |
|
|
127
127
|
| Filters removed and added with the same definition, but not one to one | `m.todo` for each removed one (rename or drop) |
|
|
128
128
|
| Filter removed and one added that its stored state fits, after a change | `m.todo` (`custom` rename, or drop) |
|
|
129
|
-
| Filter
|
|
129
|
+
| Filter takes a list of the values it took one of, on the same field (dropdown to multiselect, autocomplete to `multiple`; `equals` to `in`) | `m.wrapInList(id)` |
|
|
130
|
+
| Filter gained/lost parts, or its control changed type otherwise | `m.reset(id)` |
|
|
130
131
|
| Filter's comparison or field changed | `m.todo` (keep or reset) |
|
|
131
132
|
| Custom operators added / removed | `m.mapOperators(id, {})` / `m.todo` (map them) |
|
|
132
133
|
| Column removed, none added / some added | `m.dropColumn(id)` / `m.todo` (rename or drop) |
|
|
@@ -142,6 +143,7 @@ writes `m.todo(…)` with the candidates in comments. **A `todo` does not type-c
|
|
|
142
143
|
| `m.drop(id)` | The filter was removed. |
|
|
143
144
|
| `m.mapValues(id, value => …)` | Stored values change, e.g. renamed enum values. Lists are mapped element by element; return `DROP` to remove one. Users are told about removed values. Where the snapshots have the filter's items, `value` is one of the older items (other stored values are left as they are) and the result has to be one of the newer ones (checked by the types, and by running it). |
|
|
144
145
|
| `m.mapOperators(id, { old: 'new' \| null })` | Custom operators were removed (checked: every removed one is mapped). `null` clears what used it; users are told. |
|
|
146
|
+
| `m.wrapInList(id)` | The filter takes several values where it took one, on the same field (checked: a dropdown or single autocomplete became a multiselect or `multiple` one, comparing with `in` where it compared with `equals`). A stored value becomes a list of that value. |
|
|
145
147
|
| `m.custom(from, to, state => … \| RESET)` | Anything else; `state` is typed by both snapshots. |
|
|
146
148
|
| `m.renameColumn(from, to)`, `m.dropColumn(id)`, `m.resetSort(id)` | Columns. A stored sort by what a dropped column, or one given `resetSort`, sorted by is reset. |
|
|
147
149
|
|
|
@@ -181,6 +183,11 @@ are named in a notice.
|
|
|
181
183
|
error is logged and the stored state of the changed filters is reset rather than misread. Columns
|
|
182
184
|
are not compared at runtime (an instance may show a column only with some arguments); `check` does.
|
|
183
185
|
- Shared links carry the view and revision they were made for, and are migrated too.
|
|
186
|
+
- A stored value that does not fit its filter's control after migrating — a list for a dropdown, a
|
|
187
|
+
record for a number — resets that filter rather than breaking the filter form. Users are told
|
|
188
|
+
where it was persisted or in a saved filter. One value where the control takes several (a multiselect, an autocomplete with `multiple`)
|
|
189
|
+
is read as a list of it, as `m.wrapInList` does. That covers data no migration reaches: data
|
|
190
|
+
written before a view's first snapshot, and links built by hand, which are read as revision 1.
|
|
184
191
|
|
|
185
192
|
## Known limits
|
|
186
193
|
|
package/package.json
CHANGED