Skip to content

Commit ab09d94

Browse files
authored
core: Refactor UI Schema types for better type safety (#2436)
Refactor UI Schema types for better typechecks by TypeScript * Rename current UISchemaElement type to BaseUISchemaElement * Add UISchemaElement type that is a union of all ui schema element types (e.g. Control) * Rename current Condition type to BaseCondition * Add Condition type that is a union of all rule conidtion types (e.g. AndCondition). * Misc: Align node version in .nvmrc with actual requirements fixes #2109
1 parent 28f36ed commit ab09d94

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.19.0
1+
22

MIGRATION.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Migration guide
22

3+
## Migrating to JSON Forms 3.6
4+
5+
### UI schema type changes
6+
7+
The `UISchemaElement` type was renamed to `BaseUISchemaElement` and a new `UISchemaElement` type was introduced, which is a union of all available UI schema types.
8+
9+
The `Condition` type was renamed to `BaseCondition` and a new `Condition` type was introduced, which is a union of all available condition types.
10+
11+
Both unions include their respective base type for backwards compatibility, but if you run into errors, replace `UISchemaElement` with `BaseUISchemaElement`/`Condition` with `BaseCondition` in your code to restore the old behaviour.
12+
313
## Migrating to JSON Forms 3.5
414

515
### Angular support now targets Angular 18 and Angular 19

packages/core/src/models/uischema.ts

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*
22
The MIT License
3-
3+
44
Copyright (c) 2017-2019 EclipseSource Munich
55
https://github.com/eclipsesource/jsonforms
6-
6+
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
99
in the Software without restriction, including without limitation the rights
1010
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1111
copies of the Software, and to permit persons to whom the Software is
1212
furnished to do so, subject to the following conditions:
13-
13+
1414
The above copyright notice and this permission notice shall be included in
1515
all copies or substantial portions of the Software.
16-
16+
1717
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -114,7 +114,7 @@ export enum RuleEffect {
114114
/**
115115
* Represents a condition to be evaluated.
116116
*/
117-
export interface Condition {
117+
export interface BaseCondition {
118118
/**
119119
* The type of condition.
120120
*/
@@ -124,7 +124,7 @@ export interface Condition {
124124
/**
125125
* A leaf condition.
126126
*/
127-
export interface LeafCondition extends Condition, Scoped {
127+
export interface LeafCondition extends BaseCondition, Scoped {
128128
type: 'LEAF';
129129

130130
/**
@@ -133,7 +133,7 @@ export interface LeafCondition extends Condition, Scoped {
133133
expectedValue: any;
134134
}
135135

136-
export interface SchemaBasedCondition extends Condition, Scoped {
136+
export interface SchemaBasedCondition extends BaseCondition, Scoped {
137137
schema: JsonSchema;
138138

139139
/**
@@ -153,7 +153,7 @@ export interface SchemaBasedCondition extends Condition, Scoped {
153153
/**
154154
* A composable condition.
155155
*/
156-
export interface ComposableCondition extends Condition {
156+
export interface ComposableCondition extends BaseCondition {
157157
conditions: Condition[];
158158
}
159159

@@ -171,10 +171,20 @@ export interface AndCondition extends ComposableCondition {
171171
type: 'AND';
172172
}
173173

174+
/**
175+
* A union of all available conditions.
176+
*/
177+
export type Condition =
178+
| BaseCondition
179+
| LeafCondition
180+
| OrCondition
181+
| AndCondition
182+
| SchemaBasedCondition;
183+
174184
/**
175185
* Common base interface for any UI schema element.
176186
*/
177-
export interface UISchemaElement {
187+
export interface BaseUISchemaElement {
178188
/**
179189
* The type of this UI schema element.
180190
*/
@@ -195,7 +205,7 @@ export interface UISchemaElement {
195205
* Represents a layout element which can order its children
196206
* in a specific way.
197207
*/
198-
export interface Layout extends UISchemaElement {
208+
export interface Layout extends BaseUISchemaElement {
199209
/**
200210
* The child elements of this layout.
201211
*/
@@ -241,7 +251,7 @@ export interface LabelDescription {
241251
/**
242252
* A label element.
243253
*/
244-
export interface LabelElement extends UISchemaElement, Internationalizable {
254+
export interface LabelElement extends BaseUISchemaElement, Internationalizable {
245255
type: 'Label';
246256
/**
247257
* The text of label.
@@ -254,7 +264,7 @@ export interface LabelElement extends UISchemaElement, Internationalizable {
254264
* to which part of the schema the control should be bound.
255265
*/
256266
export interface ControlElement
257-
extends UISchemaElement,
267+
extends BaseUISchemaElement,
258268
Scoped,
259269
Labelable<string | boolean | LabelDescription>,
260270
Internationalizable {
@@ -274,7 +284,7 @@ export interface Category extends Layout, Labeled, Internationalizable {
274284
* the categorization element can be used to represent recursive structures like trees.
275285
*/
276286
export interface Categorization
277-
extends UISchemaElement,
287+
extends BaseUISchemaElement,
278288
Labeled,
279289
Internationalizable {
280290
type: 'Categorization';
@@ -284,3 +294,19 @@ export interface Categorization
284294
*/
285295
elements: (Category | Categorization)[];
286296
}
297+
298+
/**
299+
* A union of all available UI schema elements.
300+
* This includes all layout elements, control elements, label elements,
301+
* group elements, category elements and categorization elements.
302+
*/
303+
export type UISchemaElement =
304+
| BaseUISchemaElement
305+
| ControlElement
306+
| Layout
307+
| LabelElement
308+
| GroupLayout
309+
| Category
310+
| Categorization
311+
| VerticalLayout
312+
| HorizontalLayout;

0 commit comments

Comments
 (0)