@remoteoss/json-schema-form 0.11.5-dev.20240821121440 → 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 +7 -7
- package/dist/index.js +7 -7
- package/dist/standalone.js +7 -7
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +10 -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
|
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
|
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
|
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",
|
|
@@ -2774,6 +2774,16 @@ describe('createHeadlessForm', () => {
|
|
|
2774
2774
|
.validate(emptyFile)
|
|
2775
2775
|
).resolves.toEqual(emptyFile);
|
|
2776
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
|
+
});
|
|
2777
2787
|
});
|
|
2778
2788
|
|
|
2779
2789
|
describe('when a field file is required', () => {
|