@remoteoss/json-schema-form 0.11.5-dev.20240821091937 → 0.11.5-dev.20240821134012
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/dist/index.cjs +10 -9
- package/dist/index.js +10 -9
- package/dist/standalone.js +10 -9
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +30 -0
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-dev.
|
|
5
|
-
Generated: Wed, 21 Aug 2024
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821134012
|
|
5
|
+
Generated: Wed, 21 Aug 2024 13:40:24 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -673,24 +673,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
673
673
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
674
674
|
);
|
|
675
675
|
}
|
|
676
|
-
function
|
|
677
|
-
return
|
|
676
|
+
function isValidFileInput(files) {
|
|
677
|
+
return files === void 0 || files === null || files.every((file) => file instanceof File);
|
|
678
678
|
}
|
|
679
679
|
function withFile(yupSchema) {
|
|
680
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
680
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
681
681
|
}
|
|
682
682
|
function withMaxFileSize(yupSchema) {
|
|
683
683
|
return yupSchema.test(
|
|
684
684
|
"isValidFileSize",
|
|
685
685
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
686
|
-
(files) =>
|
|
686
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
687
687
|
);
|
|
688
688
|
}
|
|
689
689
|
function withFileFormat(yupSchema) {
|
|
690
690
|
return yupSchema.test(
|
|
691
691
|
"isSupportedFormat",
|
|
692
692
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
693
|
-
(files) =>
|
|
693
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
694
694
|
const fileType = file.name.split(".").pop();
|
|
695
695
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
696
696
|
}) : true
|
|
@@ -745,12 +745,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
745
745
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
746
746
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
747
747
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
748
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
749
|
-
validators.push(withFile);
|
|
750
748
|
}
|
|
751
749
|
if (propertyFields.required) {
|
|
752
750
|
validators.push(withRequired);
|
|
753
751
|
}
|
|
752
|
+
if (inputType === supportedTypes.FILE) {
|
|
753
|
+
validators.push(withFile);
|
|
754
|
+
}
|
|
754
755
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
755
756
|
validators.push(withMin);
|
|
756
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-dev.
|
|
5
|
-
Generated: Wed, 21 Aug 2024
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821134012
|
|
5
|
+
Generated: Wed, 21 Aug 2024 13:40:24 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -636,24 +636,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
636
636
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
637
637
|
);
|
|
638
638
|
}
|
|
639
|
-
function
|
|
640
|
-
return
|
|
639
|
+
function isValidFileInput(files) {
|
|
640
|
+
return files === void 0 || files === null || files.every((file) => file instanceof File);
|
|
641
641
|
}
|
|
642
642
|
function withFile(yupSchema) {
|
|
643
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
643
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
644
644
|
}
|
|
645
645
|
function withMaxFileSize(yupSchema) {
|
|
646
646
|
return yupSchema.test(
|
|
647
647
|
"isValidFileSize",
|
|
648
648
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
649
|
-
(files) =>
|
|
649
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
650
650
|
);
|
|
651
651
|
}
|
|
652
652
|
function withFileFormat(yupSchema) {
|
|
653
653
|
return yupSchema.test(
|
|
654
654
|
"isSupportedFormat",
|
|
655
655
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
656
|
-
(files) =>
|
|
656
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
657
657
|
const fileType = file.name.split(".").pop();
|
|
658
658
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
659
659
|
}) : true
|
|
@@ -708,12 +708,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
708
708
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
709
709
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
710
710
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
711
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
712
|
-
validators.push(withFile);
|
|
713
711
|
}
|
|
714
712
|
if (propertyFields.required) {
|
|
715
713
|
validators.push(withRequired);
|
|
716
714
|
}
|
|
715
|
+
if (inputType === supportedTypes.FILE) {
|
|
716
|
+
validators.push(withFile);
|
|
717
|
+
}
|
|
717
718
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
718
719
|
validators.push(withMin);
|
|
719
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-dev.
|
|
5
|
-
Generated: Wed, 21 Aug 2024
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.11.5-dev.20240821134012
|
|
5
|
+
Generated: Wed, 21 Aug 2024 13:40:24 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12152,24 +12152,24 @@ function buildYupSchema(field, config, logic) {
|
|
|
12152
12152
|
() => errorMessage.pattern ?? errorMessageFromConfig.pattern ?? `Must have a valid format. E.g. ${randomPlaceholder}`
|
|
12153
12153
|
);
|
|
12154
12154
|
}
|
|
12155
|
-
function
|
|
12156
|
-
return
|
|
12155
|
+
function isValidFileInput(files) {
|
|
12156
|
+
return files === void 0 || files === null || files.every((file) => file instanceof File);
|
|
12157
12157
|
}
|
|
12158
12158
|
function withFile(yupSchema) {
|
|
12159
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
12159
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
12160
12160
|
}
|
|
12161
12161
|
function withMaxFileSize(yupSchema) {
|
|
12162
12162
|
return yupSchema.test(
|
|
12163
12163
|
"isValidFileSize",
|
|
12164
12164
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
12165
|
-
(files) =>
|
|
12165
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
12166
12166
|
);
|
|
12167
12167
|
}
|
|
12168
12168
|
function withFileFormat(yupSchema) {
|
|
12169
12169
|
return yupSchema.test(
|
|
12170
12170
|
"isSupportedFormat",
|
|
12171
12171
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
12172
|
-
(files) =>
|
|
12172
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
12173
12173
|
const fileType = file.name.split(".").pop();
|
|
12174
12174
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
12175
12175
|
}) : true
|
|
@@ -12224,12 +12224,13 @@ function buildYupSchema(field, config, logic) {
|
|
|
12224
12224
|
validators[0] = () => withBaseSchema().of(buildGroupArraySchema());
|
|
12225
12225
|
} else if (inputType === supportedTypes.FIELDSET) {
|
|
12226
12226
|
validators[0] = () => withBaseSchema().shape(buildFieldSetSchema(propertyFields.fields));
|
|
12227
|
-
} else if (inputType === supportedTypes.FILE) {
|
|
12228
|
-
validators.push(withFile);
|
|
12229
12227
|
}
|
|
12230
12228
|
if (propertyFields.required) {
|
|
12231
12229
|
validators.push(withRequired);
|
|
12232
12230
|
}
|
|
12231
|
+
if (inputType === supportedTypes.FILE) {
|
|
12232
|
+
validators.push(withFile);
|
|
12233
|
+
}
|
|
12233
12234
|
if (typeof propertyFields.minimum !== "undefined") {
|
|
12234
12235
|
validators.push(withMin);
|
|
12235
12236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.11.5-dev.
|
|
3
|
+
"version": "0.11.5-dev.20240821134012",
|
|
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",
|
|
@@ -61,6 +61,7 @@ import {
|
|
|
61
61
|
schemaInputTypeNumberWithPercentage,
|
|
62
62
|
schemaForErrorMessageSpecificity,
|
|
63
63
|
jsfConfigForErrorMessageSpecificity,
|
|
64
|
+
schemaInputTypeFile,
|
|
64
65
|
} from './helpers';
|
|
65
66
|
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
|
|
66
67
|
|
|
@@ -2773,6 +2774,35 @@ describe('createHeadlessForm', () => {
|
|
|
2773
2774
|
.validate(emptyFile)
|
|
2774
2775
|
).resolves.toEqual(emptyFile);
|
|
2775
2776
|
});
|
|
2777
|
+
|
|
2778
|
+
it('it validates missing file correctly', () => {
|
|
2779
|
+
const { handleValidation } = createHeadlessForm(
|
|
2780
|
+
JSONSchemaBuilder().addInput({ fileInput: mockFileInput }).build()
|
|
2781
|
+
);
|
|
2782
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
2783
|
+
|
|
2784
|
+
expect(validateForm({})).toBeUndefined();
|
|
2785
|
+
expect(validateForm({ fileInput: null })).toBeUndefined();
|
|
2786
|
+
});
|
|
2787
|
+
});
|
|
2788
|
+
|
|
2789
|
+
describe('when a field file is required', () => {
|
|
2790
|
+
it('it validates missing file correctly', () => {
|
|
2791
|
+
const { handleValidation } = createHeadlessForm(schemaInputTypeFile);
|
|
2792
|
+
const validateForm = (vals) => friendlyError(handleValidation(vals));
|
|
2793
|
+
|
|
2794
|
+
expect(validateForm({})).toEqual({
|
|
2795
|
+
a_file: 'Required field',
|
|
2796
|
+
});
|
|
2797
|
+
|
|
2798
|
+
expect(
|
|
2799
|
+
validateForm({
|
|
2800
|
+
a_file: null,
|
|
2801
|
+
})
|
|
2802
|
+
).toEqual({
|
|
2803
|
+
a_file: 'Required field',
|
|
2804
|
+
});
|
|
2805
|
+
});
|
|
2776
2806
|
});
|
|
2777
2807
|
|
|
2778
2808
|
describe('when a field has accepted extensions', () => {
|