@remoteoss/json-schema-form 0.11.5-dev.20240821121440 → 0.11.5-dev.20240821144620
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 +9 -7
- package/dist/index.js +9 -7
- package/dist/standalone.js +9 -7
- package/package.json +1 -1
- package/src/tests/createHeadlessForm.test.js +22 -1
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.20240821144620
|
|
5
|
+
Generated: Wed, 21 Aug 2024 14:46:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -673,24 +673,26 @@ 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(
|
|
678
|
+
(file) => file instanceof File || Object.prototype.hasOwnProperty.call(file, "name")
|
|
679
|
+
);
|
|
678
680
|
}
|
|
679
681
|
function withFile(yupSchema) {
|
|
680
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
682
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
681
683
|
}
|
|
682
684
|
function withMaxFileSize(yupSchema) {
|
|
683
685
|
return yupSchema.test(
|
|
684
686
|
"isValidFileSize",
|
|
685
687
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
686
|
-
(files) =>
|
|
688
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
687
689
|
);
|
|
688
690
|
}
|
|
689
691
|
function withFileFormat(yupSchema) {
|
|
690
692
|
return yupSchema.test(
|
|
691
693
|
"isSupportedFormat",
|
|
692
694
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
693
|
-
(files) =>
|
|
695
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
694
696
|
const fileType = file.name.split(".").pop();
|
|
695
697
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
696
698
|
}) : 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.20240821144620
|
|
5
|
+
Generated: Wed, 21 Aug 2024 14:46:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -636,24 +636,26 @@ 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(
|
|
641
|
+
(file) => file instanceof File || Object.prototype.hasOwnProperty.call(file, "name")
|
|
642
|
+
);
|
|
641
643
|
}
|
|
642
644
|
function withFile(yupSchema) {
|
|
643
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
645
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
644
646
|
}
|
|
645
647
|
function withMaxFileSize(yupSchema) {
|
|
646
648
|
return yupSchema.test(
|
|
647
649
|
"isValidFileSize",
|
|
648
650
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
649
|
-
(files) =>
|
|
651
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
650
652
|
);
|
|
651
653
|
}
|
|
652
654
|
function withFileFormat(yupSchema) {
|
|
653
655
|
return yupSchema.test(
|
|
654
656
|
"isSupportedFormat",
|
|
655
657
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
656
|
-
(files) =>
|
|
658
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
657
659
|
const fileType = file.name.split(".").pop();
|
|
658
660
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
659
661
|
}) : 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.20240821144620
|
|
5
|
+
Generated: Wed, 21 Aug 2024 14:46:34 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12152,24 +12152,26 @@ 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(
|
|
12157
|
+
(file) => file instanceof File || Object.prototype.hasOwnProperty.call(file, "name")
|
|
12158
|
+
);
|
|
12157
12159
|
}
|
|
12158
12160
|
function withFile(yupSchema) {
|
|
12159
|
-
return yupSchema.test("isValidFile", "Not a valid file.",
|
|
12161
|
+
return yupSchema.test("isValidFile", "Not a valid file.", isValidFileInput);
|
|
12160
12162
|
}
|
|
12161
12163
|
function withMaxFileSize(yupSchema) {
|
|
12162
12164
|
return yupSchema.test(
|
|
12163
12165
|
"isValidFileSize",
|
|
12164
12166
|
errorMessage.maxFileSize ?? errorMessageFromConfig.maxFileSize ?? `File size too large. The limit is ${convertKbBytesToMB(propertyFields.maxFileSize)} MB.`,
|
|
12165
|
-
(files) =>
|
|
12167
|
+
(files) => isValidFileInput(files) && !files?.some((file) => convertBytesToKB(file.size) > propertyFields.maxFileSize)
|
|
12166
12168
|
);
|
|
12167
12169
|
}
|
|
12168
12170
|
function withFileFormat(yupSchema) {
|
|
12169
12171
|
return yupSchema.test(
|
|
12170
12172
|
"isSupportedFormat",
|
|
12171
12173
|
errorMessage.accept ?? errorMessageFromConfig.accept ?? `Unsupported file format. The acceptable formats are ${propertyFields.accept}.`,
|
|
12172
|
-
(files) =>
|
|
12174
|
+
(files) => isValidFileInput(files) && files?.length > 0 ? files.some((file) => {
|
|
12173
12175
|
const fileType = file.name.split(".").pop();
|
|
12174
12176
|
return propertyFields.accept.includes(fileType.toLowerCase());
|
|
12175
12177
|
}) : 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.20240821144620",
|
|
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', () => {
|
|
@@ -2852,8 +2862,19 @@ describe('createHeadlessForm', () => {
|
|
|
2852
2862
|
.validate({ fileInput: [file] })
|
|
2853
2863
|
).resolves.toEqual(assertObj));
|
|
2854
2864
|
});
|
|
2865
|
+
|
|
2855
2866
|
describe('and file is not instance of a File', () => {
|
|
2856
|
-
it('
|
|
2867
|
+
it('accepts if file object has name property', async () => {
|
|
2868
|
+
expect(
|
|
2869
|
+
object()
|
|
2870
|
+
.shape({
|
|
2871
|
+
fileInput: fields[0].schema,
|
|
2872
|
+
})
|
|
2873
|
+
.validate({ fileInput: [{ name: 'foo.pdf' }] })
|
|
2874
|
+
).resolves.toEqual({ fileInput: [{ name: 'foo.pdf' }] });
|
|
2875
|
+
});
|
|
2876
|
+
|
|
2877
|
+
it('throw an error if invalid file object', async () =>
|
|
2857
2878
|
expect(
|
|
2858
2879
|
object()
|
|
2859
2880
|
.shape({
|