@remoteoss/json-schema-form 0.11.4-dev.20240820134847 → 0.11.5-dev.20240821121440
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 +10 -0
- package/dist/index.cjs +12 -6
- package/dist/index.js +12 -6
- package/dist/standalone.js +12 -6
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +63 -0
- package/src/tests/helpers.js +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
#### 0.11.4-beta.0 (2024-08-20)
|
|
2
|
+
|
|
3
|
+
##### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* **file:** Validate the value is an instance of File ([#87](https://github.com/remoteoss/json-schema-form/pull/87)) ([8361df0d](https://github.com/remoteoss/json-schema-form/commit/8361df0d4e9f7d83342cdc91c41efb493e391307))
|
|
6
|
+
|
|
7
|
+
##### Chores
|
|
8
|
+
|
|
9
|
+
* **tests:** Move code in global test scope to inside beforeAll ([#90](https://github.com/remoteoss/json-schema-form/pull/90)) ([88f7d3c9](https://github.com/remoteoss/json-schema-form/commit/88f7d3c95330c828fc2539962b878c43b61ca8a0))
|
|
10
|
+
|
|
1
11
|
#### 0.11.3-beta.0 (2024-08-19)
|
|
2
12
|
|
|
3
13
|
##### Bug Fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821121440
|
|
5
|
+
Generated: Wed, 21 Aug 2024 12:15:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -553,7 +553,12 @@ var yupSchemas = {
|
|
|
553
553
|
multiple: {
|
|
554
554
|
select: (0, import_yup.array)().nullable(),
|
|
555
555
|
"group-array": (0, import_yup.array)().nullable()
|
|
556
|
-
}
|
|
556
|
+
},
|
|
557
|
+
null: (0, import_yup.mixed)().typeError("The value must be null").test(
|
|
558
|
+
"matchesNullValue",
|
|
559
|
+
({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
|
|
560
|
+
(value) => value === void 0 || value === null
|
|
561
|
+
)
|
|
557
562
|
};
|
|
558
563
|
var yupSchemasToJsonTypes = {
|
|
559
564
|
string: yupSchemas.text,
|
|
@@ -562,7 +567,7 @@ var yupSchemasToJsonTypes = {
|
|
|
562
567
|
object: yupSchemas.fieldset,
|
|
563
568
|
array: yupSchemas.multiple.select,
|
|
564
569
|
boolean: yupSchemas.checkboxBool,
|
|
565
|
-
null:
|
|
570
|
+
null: yupSchemas.null
|
|
566
571
|
};
|
|
567
572
|
function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
568
573
|
if (inlineError)
|
|
@@ -740,12 +745,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
740
745
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
741
746
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
742
747
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
743
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
744
|
-
validators.push(withFile);
|
|
745
748
|
}
|
|
746
749
|
if (propertyFields.required) {
|
|
747
750
|
validators.push(withRequired);
|
|
748
751
|
}
|
|
752
|
+
if (inputType === supportedTypes.FILE) {
|
|
753
|
+
validators.push(withFile);
|
|
754
|
+
}
|
|
749
755
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
750
756
|
validators.push(withMin);
|
|
751
757
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821121440
|
|
5
|
+
Generated: Wed, 21 Aug 2024 12:15:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -516,7 +516,12 @@ var yupSchemas = {
|
|
|
516
516
|
multiple: {
|
|
517
517
|
select: array().nullable(),
|
|
518
518
|
"group-array": array().nullable()
|
|
519
|
-
}
|
|
519
|
+
},
|
|
520
|
+
null: mixed().typeError("The value must be null").test(
|
|
521
|
+
"matchesNullValue",
|
|
522
|
+
({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
|
|
523
|
+
(value) => value === void 0 || value === null
|
|
524
|
+
)
|
|
520
525
|
};
|
|
521
526
|
var yupSchemasToJsonTypes = {
|
|
522
527
|
string: yupSchemas.text,
|
|
@@ -525,7 +530,7 @@ var yupSchemasToJsonTypes = {
|
|
|
525
530
|
object: yupSchemas.fieldset,
|
|
526
531
|
array: yupSchemas.multiple.select,
|
|
527
532
|
boolean: yupSchemas.checkboxBool,
|
|
528
|
-
null:
|
|
533
|
+
null: yupSchemas.null
|
|
529
534
|
};
|
|
530
535
|
function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
531
536
|
if (inlineError)
|
|
@@ -703,12 +708,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
703
708
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
704
709
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
705
710
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
706
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
707
|
-
validators.push(withFile);
|
|
708
711
|
}
|
|
709
712
|
if (propertyFields.required) {
|
|
710
713
|
validators.push(withRequired);
|
|
711
714
|
}
|
|
715
|
+
if (inputType === supportedTypes.FILE) {
|
|
716
|
+
validators.push(withFile);
|
|
717
|
+
}
|
|
712
718
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
713
719
|
validators.push(withMin);
|
|
714
720
|
}
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.11.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821121440
|
|
5
|
+
Generated: Wed, 21 Aug 2024 12:15:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12032,7 +12032,12 @@ var yupSchemas = {
|
|
|
12032
12032
|
multiple: {
|
|
12033
12033
|
select: array_default().nullable(),
|
|
12034
12034
|
"group-array": array_default().nullable()
|
|
12035
|
-
}
|
|
12035
|
+
},
|
|
12036
|
+
null: SchemaType().typeError("The value must be null").test(
|
|
12037
|
+
"matchesNullValue",
|
|
12038
|
+
({ value }) => `The value ${JSON.stringify(value)} is not valid.`,
|
|
12039
|
+
(value) => value === void 0 || value === null
|
|
12040
|
+
)
|
|
12036
12041
|
};
|
|
12037
12042
|
var yupSchemasToJsonTypes = {
|
|
12038
12043
|
string: yupSchemas.text,
|
|
@@ -12041,7 +12046,7 @@ var yupSchemasToJsonTypes = {
|
|
|
12041
12046
|
object: yupSchemas.fieldset,
|
|
12042
12047
|
array: yupSchemas.multiple.select,
|
|
12043
12048
|
boolean: yupSchemas.checkboxBool,
|
|
12044
|
-
null:
|
|
12049
|
+
null: yupSchemas.null
|
|
12045
12050
|
};
|
|
12046
12051
|
function getRequiredErrorMessage(inputType, { inlineError, configError }) {
|
|
12047
12052
|
if (inlineError)
|
|
@@ -12219,12 +12224,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
12219
12224
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
12220
12225
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
12221
12226
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
12222
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
12223
|
-
validators.push(withFile);
|
|
12224
12227
|
}
|
|
12225
12228
|
if (propertyFields.required) {
|
|
12226
12229
|
validators.push(withRequired);
|
|
12227
12230
|
}
|
|
12231
|
+
if (inputType === supportedTypes.FILE) {
|
|
12232
|
+
validators.push(withFile);
|
|
12233
|
+
}
|
|
12228
12234
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
12229
12235
|
validators.push(withMin);
|
|
12230
12236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5-dev.20240821121440",
|
|
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",
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
schemaInputWithStatement,
|
|
30
30
|
schemaInputTypeCheckbox,
|
|
31
31
|
schemaInputTypeCheckboxBooleans,
|
|
32
|
+
schemaInputTypeNull,
|
|
32
33
|
schemaWithOrderKeyword,
|
|
33
34
|
schemaWithPositionDeprecated,
|
|
34
35
|
schemaDynamicValidationConst,
|
|
@@ -60,6 +61,7 @@ import {
|
|
|
60
61
|
schemaInputTypeNumberWithPercentage,
|
|
61
62
|
schemaForErrorMessageSpecificity,
|
|
62
63
|
jsfConfigForErrorMessageSpecificity,
|
|
64
|
+
schemaInputTypeFile,
|
|
63
65
|
} from './helpers';
|
|
64
66
|
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
|
|
65
67
|
|
|
@@ -1578,6 +1580,48 @@ describe('createHeadlessForm', () => {
|
|
|
1578
1580
|
});
|
|
1579
1581
|
});
|
|
1580
1582
|
|
|
1583
|
+
it('supports "null" field type', () => {
|
|
1584
|
+
const { handleValidation, fields } = createHeadlessForm(schemaInputTypeNull, {
|
|
1585
|
+
strictInputType: false,
|
|
1586
|
+
});
|
|
1587
|
+
|
|
1588
|
+
expect(fields).toMatchObject([
|
|
1589
|
+
{
|
|
1590
|
+
name: 'name',
|
|
1591
|
+
label: '(Optional) Name',
|
|
1592
|
+
type: undefined,
|
|
1593
|
+
jsonType: 'null',
|
|
1594
|
+
schema: expect.any(Object),
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
name: 'username',
|
|
1598
|
+
label: 'Username',
|
|
1599
|
+
type: 'text',
|
|
1600
|
+
jsonType: 'string',
|
|
1601
|
+
inputType: 'text',
|
|
1602
|
+
maxLength: 4,
|
|
1603
|
+
schema: expect.any(Object),
|
|
1604
|
+
},
|
|
1605
|
+
]);
|
|
1606
|
+
|
|
1607
|
+
// jsonType `null` fields do not have a corresponding inputType
|
|
1608
|
+
expect(fields[0].inputType).toBeUndefined();
|
|
1609
|
+
|
|
1610
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
1611
|
+
|
|
1612
|
+
expect(validateForm({})).toEqual({
|
|
1613
|
+
username: 'Required field',
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
expect(validateForm({ username: 'hello', name: 'John' })).toEqual({
|
|
1617
|
+
username: 'Please insert up to 4 characters',
|
|
1618
|
+
name: 'The value "John" is not valid.',
|
|
1619
|
+
});
|
|
1620
|
+
|
|
1621
|
+
expect(validateForm({ username: 'john' })).toBeUndefined();
|
|
1622
|
+
expect(validateForm({ username: 'john', name: null })).toBeUndefined();
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1581
1625
|
it('supports oneOf pattern validation', () => {
|
|
1582
1626
|
const result = createHeadlessForm(mockTelWithPattern);
|
|
1583
1627
|
|
|
@@ -2732,6 +2776,25 @@ describe('createHeadlessForm', () => {
|
|
|
2732
2776
|
});
|
|
2733
2777
|
});
|
|
2734
2778
|
|
|
2779
|
+
describe('when a field file is required', () => {
|
|
2780
|
+
it('it validates missing file correctly', () => {
|
|
2781
|
+
const { handleValidation } = createHeadlessForm(schemaInputTypeFile);
|
|
2782
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
2783
|
+
|
|
2784
|
+
expect(validateForm({})).toEqual({
|
|
2785
|
+
a_file: 'Required field',
|
|
2786
|
+
});
|
|
2787
|
+
|
|
2788
|
+
expect(
|
|
2789
|
+
validateForm({
|
|
2790
|
+
a_file: null,
|
|
2791
|
+
})
|
|
2792
|
+
).toEqual({
|
|
2793
|
+
a_file: 'Required field',
|
|
2794
|
+
});
|
|
2795
|
+
});
|
|
2796
|
+
});
|
|
2797
|
+
|
|
2735
2798
|
describe('when a field has accepted extensions', () => {
|
|
2736
2799
|
let fields;
|
|
2737
2800
|
beforeEach(() => {
|
package/src/tests/helpers.js
CHANGED
|
@@ -1141,6 +1141,23 @@ export const schemaInputTypeCheckboxBooleans = JSONSchemaBuilder()
|
|
|
1141
1141
|
.setRequiredFields(['boolean_required'])
|
|
1142
1142
|
.build();
|
|
1143
1143
|
|
|
1144
|
+
export const schemaInputTypeNull = {
|
|
1145
|
+
additionalProperties: false,
|
|
1146
|
+
type: 'object',
|
|
1147
|
+
properties: {
|
|
1148
|
+
name: {
|
|
1149
|
+
type: 'null',
|
|
1150
|
+
title: '(Optional) Name',
|
|
1151
|
+
},
|
|
1152
|
+
username: {
|
|
1153
|
+
type: 'string',
|
|
1154
|
+
title: 'Username',
|
|
1155
|
+
maxLength: 4,
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
required: ['username'],
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1144
1161
|
export const schemaCustomErrorMessageByField = {
|
|
1145
1162
|
properties: {
|
|
1146
1163
|
tabs: {
|