@remoteoss/json-schema-form 0.4.3-dev.20230808130245 → 0.4.4-dev.20230829102031
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +13 -2
- package/dist/index.js +13 -2
- package/dist/standalone.js +13 -2
- package/package.json +1 -1
- package/src/tests/const.test.js +78 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
#### 0.4.3-beta.0 (2023-08-09)
|
|
2
|
+
|
|
3
|
+
##### Bug fixes
|
|
4
|
+
|
|
5
|
+
* **conditions:** Validate a deeply nested if (e.g. checking an object with a number property) in an if property now doesn't break the form. ([#33](https://github.com/remoteoss/json-schema-form/pull/33)) ([e34cfcc](https://github.com/remoteoss/json-schema-form/commit/e34cfccaf45f1460b346f3cff0c797b3d11259e3))
|
|
6
|
+
|
|
1
7
|
#### 0.4.2-beta.0 (2023-07-20)
|
|
2
8
|
|
|
3
9
|
##### Bug Fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated: Tue,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230829102031
|
|
5
|
+
Generated: Tue, 29 Aug 2023 10:20:47 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -606,6 +606,13 @@ function buildYupSchema(field, config) {
|
|
|
606
606
|
}) : true
|
|
607
607
|
);
|
|
608
608
|
}
|
|
609
|
+
function withConst(yupSchema) {
|
|
610
|
+
return yupSchema.test(
|
|
611
|
+
"isConst",
|
|
612
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
613
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
614
|
+
);
|
|
615
|
+
}
|
|
609
616
|
function withBaseSchema() {
|
|
610
617
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
611
618
|
if (customErrorMsg) {
|
|
@@ -673,6 +680,9 @@ function buildYupSchema(field, config) {
|
|
|
673
680
|
if (propertyFields.accept) {
|
|
674
681
|
validators.push(withFileFormat);
|
|
675
682
|
}
|
|
683
|
+
if (propertyFields.const) {
|
|
684
|
+
validators.push(withConst);
|
|
685
|
+
}
|
|
676
686
|
return (0, import_flow.default)(validators);
|
|
677
687
|
}
|
|
678
688
|
function getNoSortEdges(fields = []) {
|
|
@@ -934,6 +944,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
934
944
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
935
945
|
return (0, import_omitBy.default)(
|
|
936
946
|
{
|
|
947
|
+
const: node.const,
|
|
937
948
|
label: node.title,
|
|
938
949
|
readOnly: node.readOnly,
|
|
939
950
|
...node.deprecated && {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated: Tue,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230829102031
|
|
5
|
+
Generated: Tue, 29 Aug 2023 10:20:47 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -570,6 +570,13 @@ function buildYupSchema(field, config) {
|
|
|
570
570
|
}) : true
|
|
571
571
|
);
|
|
572
572
|
}
|
|
573
|
+
function withConst(yupSchema) {
|
|
574
|
+
return yupSchema.test(
|
|
575
|
+
"isConst",
|
|
576
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
577
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
578
|
+
);
|
|
579
|
+
}
|
|
573
580
|
function withBaseSchema() {
|
|
574
581
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
575
582
|
if (customErrorMsg) {
|
|
@@ -637,6 +644,9 @@ function buildYupSchema(field, config) {
|
|
|
637
644
|
if (propertyFields.accept) {
|
|
638
645
|
validators.push(withFileFormat);
|
|
639
646
|
}
|
|
647
|
+
if (propertyFields.const) {
|
|
648
|
+
validators.push(withConst);
|
|
649
|
+
}
|
|
640
650
|
return flow(validators);
|
|
641
651
|
}
|
|
642
652
|
function getNoSortEdges(fields = []) {
|
|
@@ -898,6 +908,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
898
908
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
899
909
|
return omitBy(
|
|
900
910
|
{
|
|
911
|
+
const: node.const,
|
|
901
912
|
label: node.title,
|
|
902
913
|
readOnly: node.readOnly,
|
|
903
914
|
...node.deprecated && {
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.
|
|
5
|
-
Generated: Tue,
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230829102031
|
|
5
|
+
Generated: Tue, 29 Aug 2023 10:20:47 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11546,6 +11546,13 @@ function buildYupSchema(field, config) {
|
|
|
11546
11546
|
}) : true
|
|
11547
11547
|
);
|
|
11548
11548
|
}
|
|
11549
|
+
function withConst(yupSchema) {
|
|
11550
|
+
return yupSchema.test(
|
|
11551
|
+
"isConst",
|
|
11552
|
+
errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
|
|
11553
|
+
(value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
|
|
11554
|
+
);
|
|
11555
|
+
}
|
|
11549
11556
|
function withBaseSchema() {
|
|
11550
11557
|
const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
|
|
11551
11558
|
if (customErrorMsg) {
|
|
@@ -11613,6 +11620,9 @@ function buildYupSchema(field, config) {
|
|
|
11613
11620
|
if (propertyFields.accept) {
|
|
11614
11621
|
validators.push(withFileFormat);
|
|
11615
11622
|
}
|
|
11623
|
+
if (propertyFields.const) {
|
|
11624
|
+
validators.push(withConst);
|
|
11625
|
+
}
|
|
11616
11626
|
return (0, import_flow.default)(validators);
|
|
11617
11627
|
}
|
|
11618
11628
|
function getNoSortEdges(fields = []) {
|
|
@@ -11874,6 +11884,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
11874
11884
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
11875
11885
|
return (0, import_omitBy.default)(
|
|
11876
11886
|
{
|
|
11887
|
+
const: node.const,
|
|
11877
11888
|
label: node.title,
|
|
11878
11889
|
readOnly: node.readOnly,
|
|
11879
11890
|
...node.deprecated && {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4-dev.20230829102031",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHeadlessForm } from '../createHeadlessForm';
|
|
2
|
+
|
|
3
|
+
it('Should work for number', () => {
|
|
4
|
+
const { handleValidation } = createHeadlessForm(
|
|
5
|
+
{
|
|
6
|
+
properties: {
|
|
7
|
+
ten_only: { type: 'number', const: 10 },
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
{ strictInputType: false }
|
|
11
|
+
);
|
|
12
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
13
|
+
expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
|
|
14
|
+
ten_only: 'The only accepted value is 10.',
|
|
15
|
+
});
|
|
16
|
+
expect(handleValidation({ ten_only: 10 }).formErrors).toEqual(undefined);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Should work for text', () => {
|
|
20
|
+
const { handleValidation } = createHeadlessForm(
|
|
21
|
+
{
|
|
22
|
+
properties: {
|
|
23
|
+
hello_only: { type: 'string', const: 'hello' },
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{ strictInputType: false }
|
|
27
|
+
);
|
|
28
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
29
|
+
expect(handleValidation({ hello_only: 'what' }).formErrors).toEqual({
|
|
30
|
+
hello_only: 'The only accepted value is hello.',
|
|
31
|
+
});
|
|
32
|
+
expect(handleValidation({ hello_only: 'hello' }).formErrors).toEqual(undefined);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Should work for a conditionally applied const', () => {
|
|
36
|
+
const { handleValidation } = createHeadlessForm(
|
|
37
|
+
{
|
|
38
|
+
properties: {
|
|
39
|
+
answer: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] },
|
|
40
|
+
amount: { description: 'If you select yes, this needs to be exactly 10.', type: 'number' },
|
|
41
|
+
},
|
|
42
|
+
allOf: [
|
|
43
|
+
{
|
|
44
|
+
if: { properties: { answer: { const: 'yes' } }, required: ['answer'] },
|
|
45
|
+
then: { properties: { amount: { const: 10 } }, required: ['amount'] },
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
{ strictInputType: false }
|
|
50
|
+
);
|
|
51
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
52
|
+
expect(handleValidation({ answer: 'no' }).formErrors).toEqual(undefined);
|
|
53
|
+
expect(handleValidation({ answer: 'yes' }).formErrors).toEqual({ amount: 'Required field' });
|
|
54
|
+
expect(handleValidation({ answer: 'yes', amount: 1 }).formErrors).toEqual({
|
|
55
|
+
amount: 'The only accepted value is 10.',
|
|
56
|
+
});
|
|
57
|
+
expect(handleValidation({ answer: 'yes', amount: 10 }).formErrors).toEqual(undefined);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('Should show the custom error message', () => {
|
|
61
|
+
const { handleValidation } = createHeadlessForm(
|
|
62
|
+
{
|
|
63
|
+
properties: {
|
|
64
|
+
string: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
const: 'hello',
|
|
67
|
+
'x-jsf-errorMessage': { const: 'You must say hello!!!' },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{ strictInputType: false }
|
|
72
|
+
);
|
|
73
|
+
expect(handleValidation({}).formErrors).toEqual(undefined);
|
|
74
|
+
expect(handleValidation({ string: 'hi' }).formErrors).toEqual({
|
|
75
|
+
string: 'You must say hello!!!',
|
|
76
|
+
});
|
|
77
|
+
expect(handleValidation({ string: 'hello' }).formErrors).toEqual(undefined);
|
|
78
|
+
});
|