@jsonforms/core 3.1.1-alpha.0 → 3.2.0-alpha.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/lib/jsonforms-core.cjs.js +15 -15
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +10 -14
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/models/uischema.d.ts +12 -0
- package/package.json +5 -6
- package/src/models/uischema.ts +13 -0
- package/src/util/combinators.ts +9 -16
- package/src/util/path.ts +1 -1
- package/src/util/renderer.ts +1 -1
- package/src/util/runtime.ts +3 -0
package/lib/models/uischema.d.ts
CHANGED
|
@@ -93,6 +93,18 @@ export interface LeafCondition extends Condition, Scoped {
|
|
|
93
93
|
}
|
|
94
94
|
export interface SchemaBasedCondition extends Condition, Scoped {
|
|
95
95
|
schema: JsonSchema;
|
|
96
|
+
/**
|
|
97
|
+
* When the scope resolves to undefined and `failWhenUndefined` is set to `true`, the condition
|
|
98
|
+
* will fail. Therefore the reverse effect will be applied.
|
|
99
|
+
*
|
|
100
|
+
* Background:
|
|
101
|
+
* Most JSON Schemas will successfully validate against `undefined` data. Specifying that a
|
|
102
|
+
* condition shall fail when data is `undefined` requires to lift the scope to being able to use
|
|
103
|
+
* JSON Schema's `required`.
|
|
104
|
+
*
|
|
105
|
+
* Using `failWhenUndefined` allows to more conveniently express this condition.
|
|
106
|
+
*/
|
|
107
|
+
failWhenUndefined?: boolean;
|
|
96
108
|
}
|
|
97
109
|
/**
|
|
98
110
|
* A composable condition.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonforms/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0-alpha.1",
|
|
4
4
|
"description": "Core module of JSON Forms",
|
|
5
5
|
"repository": "https://github.com/eclipsesource/jsonforms",
|
|
6
6
|
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"lint": "eslint .",
|
|
43
43
|
"lint:fix": "eslint --fix .",
|
|
44
44
|
"report": "nyc report --reporter=html",
|
|
45
|
-
"test": "
|
|
46
|
-
"test-cov": "rimraf -rf .nyc_output &&
|
|
45
|
+
"test": "ava",
|
|
46
|
+
"test-cov": "rimraf -rf .nyc_output && nyc ava",
|
|
47
47
|
"doc": "typedoc --name 'JSON Forms Core' --excludeExternals --theme ../../typedoc-jsonforms --out docs src"
|
|
48
48
|
},
|
|
49
49
|
"ava": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"ts"
|
|
56
56
|
],
|
|
57
57
|
"require": [
|
|
58
|
-
"ts-node
|
|
58
|
+
"./test-config/ts-node.config.js",
|
|
59
59
|
"source-map-support/register"
|
|
60
60
|
]
|
|
61
61
|
},
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
78
78
|
"@typescript-eslint/parser": "^5.54.1",
|
|
79
79
|
"ava": "~2.4.0",
|
|
80
|
-
"cross-env": "^7.0.2",
|
|
81
80
|
"document-register-element": "^1.14.3",
|
|
82
81
|
"eslint": "^7.32.0",
|
|
83
82
|
"eslint-config-prettier": "^8.7.0",
|
|
@@ -100,5 +99,5 @@
|
|
|
100
99
|
"typedoc": "~0.21.9",
|
|
101
100
|
"typescript": "4.2.3"
|
|
102
101
|
},
|
|
103
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "deb2c7cd71f6065cca7777420b1018f17e73052a"
|
|
104
103
|
}
|
package/src/models/uischema.ts
CHANGED
|
@@ -135,6 +135,19 @@ export interface LeafCondition extends Condition, Scoped {
|
|
|
135
135
|
|
|
136
136
|
export interface SchemaBasedCondition extends Condition, Scoped {
|
|
137
137
|
schema: JsonSchema;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* When the scope resolves to undefined and `failWhenUndefined` is set to `true`, the condition
|
|
141
|
+
* will fail. Therefore the reverse effect will be applied.
|
|
142
|
+
*
|
|
143
|
+
* Background:
|
|
144
|
+
* Most JSON Schemas will successfully validate against `undefined` data. Specifying that a
|
|
145
|
+
* condition shall fail when data is `undefined` requires to lift the scope to being able to use
|
|
146
|
+
* JSON Schema's `required`.
|
|
147
|
+
*
|
|
148
|
+
* Using `failWhenUndefined` allows to more conveniently express this condition.
|
|
149
|
+
*/
|
|
150
|
+
failWhenUndefined?: boolean;
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
/**
|
package/src/util/combinators.ts
CHANGED
|
@@ -35,18 +35,6 @@ export interface CombinatorSubSchemaRenderInfo {
|
|
|
35
35
|
|
|
36
36
|
export type CombinatorKeyword = 'anyOf' | 'oneOf' | 'allOf';
|
|
37
37
|
|
|
38
|
-
const createLabel = (
|
|
39
|
-
subSchema: JsonSchema,
|
|
40
|
-
subSchemaIndex: number,
|
|
41
|
-
keyword: CombinatorKeyword
|
|
42
|
-
): string => {
|
|
43
|
-
if (subSchema.title) {
|
|
44
|
-
return subSchema.title;
|
|
45
|
-
} else {
|
|
46
|
-
return keyword + '-' + subSchemaIndex;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
38
|
export const createCombinatorRenderInfos = (
|
|
51
39
|
combinatorSubSchemas: JsonSchema[],
|
|
52
40
|
rootSchema: JsonSchema,
|
|
@@ -56,9 +44,11 @@ export const createCombinatorRenderInfos = (
|
|
|
56
44
|
uischemas: JsonFormsUISchemaRegistryEntry[]
|
|
57
45
|
): CombinatorSubSchemaRenderInfo[] =>
|
|
58
46
|
combinatorSubSchemas.map((subSchema, subSchemaIndex) => {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
const resolvedSubSchema =
|
|
48
|
+
subSchema.$ref && Resolve.schema(rootSchema, subSchema.$ref, rootSchema);
|
|
49
|
+
|
|
50
|
+
const schema = resolvedSubSchema ?? subSchema;
|
|
51
|
+
|
|
62
52
|
return {
|
|
63
53
|
schema,
|
|
64
54
|
uischema: findUISchema(
|
|
@@ -70,6 +60,9 @@ export const createCombinatorRenderInfos = (
|
|
|
70
60
|
control,
|
|
71
61
|
rootSchema
|
|
72
62
|
),
|
|
73
|
-
label:
|
|
63
|
+
label:
|
|
64
|
+
subSchema.title ??
|
|
65
|
+
resolvedSubSchema?.title ??
|
|
66
|
+
`${keyword}-${subSchemaIndex}`,
|
|
74
67
|
};
|
|
75
68
|
});
|
package/src/util/path.ts
CHANGED
|
@@ -57,7 +57,7 @@ export { compose as composePaths };
|
|
|
57
57
|
*/
|
|
58
58
|
export const toDataPathSegments = (schemaPath: string): string[] => {
|
|
59
59
|
const s = schemaPath
|
|
60
|
-
.replace(/(anyOf|allOf|oneOf)\/[\d]
|
|
60
|
+
.replace(/(anyOf|allOf|oneOf)\/[\d]+\//g, '')
|
|
61
61
|
.replace(/(then|else)\//g, '');
|
|
62
62
|
const segments = s.split('/');
|
|
63
63
|
|
package/src/util/renderer.ts
CHANGED
package/src/util/runtime.ts
CHANGED
|
@@ -79,6 +79,9 @@ const evaluateCondition = (
|
|
|
79
79
|
return value === condition.expectedValue;
|
|
80
80
|
} else if (isSchemaCondition(condition)) {
|
|
81
81
|
const value = resolveData(data, getConditionScope(condition, path));
|
|
82
|
+
if (condition.failWhenUndefined && value === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
82
85
|
return ajv.validate(condition.schema, value) as boolean;
|
|
83
86
|
} else {
|
|
84
87
|
// unknown condition
|