@remoteoss/json-schema-form 0.11.7-dev.20241029090957 → 0.11.7-dev.20241120091537

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 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.7-dev.20241029090957
5
- Generated: Tue, 29 Oct 2024 09:10:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241120091537
5
+ Generated: Wed, 20 Nov 2024 09:15:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -481,12 +481,7 @@ var yupSchemas = {
481
481
  }).test(
482
482
  "matchesOptionOrPattern",
483
483
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
484
- (castValue, { originalValue }) => {
485
- if (castValue !== void 0 && typeof originalValue !== "string") {
486
- return false;
487
- }
488
- return validateRadioOrSelectOptions(castValue, options);
489
- }
484
+ (value) => validateRadioOrSelectOptions(value, options)
490
485
  );
491
486
  },
492
487
  date: ({ minDate, maxDate }) => {
@@ -627,6 +622,7 @@ function buildYupSchema(field, config, logic) {
627
622
  const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
628
623
  let baseSchema;
629
624
  const errorMessageFromConfig = config?.inputTypes?.[inputType]?.errorMessage || {};
625
+ const jsonType = getJsonTypeInArray(field.jsonType);
630
626
  if (propertyFields.multiple) {
631
627
  baseSchema = yupSchemas.multiple[inputType] || yupSchemasToJsonTypes.array;
632
628
  } else if (isCheckboxBoolean) {
@@ -648,6 +644,11 @@ function buildYupSchema(field, config, logic) {
648
644
  }
649
645
  return yupSchema.required(requiredMessage);
650
646
  }
647
+ function withInteger(yupSchema) {
648
+ return yupSchema.integer(
649
+ (message) => errorMessage.integer ?? errorMessageFromConfig.integer ?? `Must not contain decimal points. E.g. ${Math.floor(message.value)} instead of ${message.value}`
650
+ );
651
+ }
651
652
  function withMin(yupSchema) {
652
653
  return yupSchema.min(
653
654
  propertyFields.minimum,
@@ -759,6 +760,9 @@ function buildYupSchema(field, config, logic) {
759
760
  if (inputType === supportedTypes.FILE) {
760
761
  validators.push(withFile);
761
762
  }
763
+ if (jsonType === "integer") {
764
+ validators.push(withInteger);
765
+ }
762
766
  if (typeof propertyFields.minimum !== "undefined") {
763
767
  validators.push(withMin);
764
768
  }
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.7-dev.20241029090957
5
- Generated: Tue, 29 Oct 2024 09:10:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241120091537
5
+ Generated: Wed, 20 Nov 2024 09:15:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -444,12 +444,7 @@ var yupSchemas = {
444
444
  }).test(
445
445
  "matchesOptionOrPattern",
446
446
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
447
- (castValue, { originalValue }) => {
448
- if (castValue !== void 0 && typeof originalValue !== "string") {
449
- return false;
450
- }
451
- return validateRadioOrSelectOptions(castValue, options);
452
- }
447
+ (value) => validateRadioOrSelectOptions(value, options)
453
448
  );
454
449
  },
455
450
  date: ({ minDate, maxDate }) => {
@@ -590,6 +585,7 @@ function buildYupSchema(field, config, logic) {
590
585
  const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
591
586
  let baseSchema;
592
587
  const errorMessageFromConfig = config?.inputTypes?.[inputType]?.errorMessage || {};
588
+ const jsonType = getJsonTypeInArray(field.jsonType);
593
589
  if (propertyFields.multiple) {
594
590
  baseSchema = yupSchemas.multiple[inputType] || yupSchemasToJsonTypes.array;
595
591
  } else if (isCheckboxBoolean) {
@@ -611,6 +607,11 @@ function buildYupSchema(field, config, logic) {
611
607
  }
612
608
  return yupSchema.required(requiredMessage);
613
609
  }
610
+ function withInteger(yupSchema) {
611
+ return yupSchema.integer(
612
+ (message) => errorMessage.integer ?? errorMessageFromConfig.integer ?? `Must not contain decimal points. E.g. ${Math.floor(message.value)} instead of ${message.value}`
613
+ );
614
+ }
614
615
  function withMin(yupSchema) {
615
616
  return yupSchema.min(
616
617
  propertyFields.minimum,
@@ -722,6 +723,9 @@ function buildYupSchema(field, config, logic) {
722
723
  if (inputType === supportedTypes.FILE) {
723
724
  validators.push(withFile);
724
725
  }
726
+ if (jsonType === "integer") {
727
+ validators.push(withInteger);
728
+ }
725
729
  if (typeof propertyFields.minimum !== "undefined") {
726
730
  validators.push(withMin);
727
731
  }
@@ -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.7-dev.20241029090957
5
- Generated: Tue, 29 Oct 2024 09:10:21 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.7-dev.20241120091537
5
+ Generated: Wed, 20 Nov 2024 09:15:48 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11960,12 +11960,7 @@ var yupSchemas = {
11960
11960
  }).test(
11961
11961
  "matchesOptionOrPattern",
11962
11962
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
11963
- (castValue, { originalValue }) => {
11964
- if (castValue !== void 0 && typeof originalValue !== "string") {
11965
- return false;
11966
- }
11967
- return validateRadioOrSelectOptions(castValue, options);
11968
- }
11963
+ (value) => validateRadioOrSelectOptions(value, options)
11969
11964
  );
11970
11965
  },
11971
11966
  date: ({ minDate, maxDate }) => {
@@ -12106,6 +12101,7 @@ function buildYupSchema(field, config, logic) {
12106
12101
  const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
12107
12102
  let baseSchema;
12108
12103
  const errorMessageFromConfig = config?.inputTypes?.[inputType]?.errorMessage || {};
12104
+ const jsonType = getJsonTypeInArray(field.jsonType);
12109
12105
  if (propertyFields.multiple) {
12110
12106
  baseSchema = yupSchemas.multiple[inputType] || yupSchemasToJsonTypes.array;
12111
12107
  } else if (isCheckboxBoolean) {
@@ -12127,6 +12123,11 @@ function buildYupSchema(field, config, logic) {
12127
12123
  }
12128
12124
  return yupSchema.required(requiredMessage);
12129
12125
  }
12126
+ function withInteger(yupSchema) {
12127
+ return yupSchema.integer(
12128
+ (message) => errorMessage.integer ?? errorMessageFromConfig.integer ?? `Must not contain decimal points. E.g. ${Math.floor(message.value)} instead of ${message.value}`
12129
+ );
12130
+ }
12130
12131
  function withMin(yupSchema) {
12131
12132
  return yupSchema.min(
12132
12133
  propertyFields.minimum,
@@ -12238,6 +12239,9 @@ function buildYupSchema(field, config, logic) {
12238
12239
  if (inputType === supportedTypes.FILE) {
12239
12240
  validators.push(withFile);
12240
12241
  }
12242
+ if (jsonType === "integer") {
12243
+ validators.push(withInteger);
12244
+ }
12241
12245
  if (typeof propertyFields.minimum !== "undefined") {
12242
12246
  validators.push(withMin);
12243
12247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.7-dev.20241029090957",
3
+ "version": "0.11.7-dev.20241120091537",
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",
@@ -9,7 +9,6 @@ import {
9
9
  schemaInputTypeText,
10
10
  schemaInputTypeRadioDeprecated,
11
11
  schemaInputTypeRadioString,
12
- schemaInputTypeRadioStringY,
13
12
  schemaInputTypeRadioBoolean,
14
13
  schemaInputTypeRadioNumber,
15
14
  schemaInputTypeRadioRequiredAndOptional,
@@ -23,6 +22,7 @@ import {
23
22
  schemaInputTypeSelectMultiple,
24
23
  schemaInputTypeSelectMultipleOptional,
25
24
  schemaInputTypeFieldset,
25
+ schemaInputTypeIntegerNumber,
26
26
  schemaInputTypeNumber,
27
27
  schemaInputTypeNumberZeroMaximum,
28
28
  schemaInputTypeDate,
@@ -821,45 +821,6 @@ describe('createHeadlessForm', () => {
821
821
  });
822
822
  });
823
823
 
824
- // @BUG COD-1859
825
- // it should validate when type is string but value is not a boolean
826
- it('support "radio" field string-y type', () => {
827
- const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioStringY);
828
-
829
- const validateForm = (vals) => friendlyError(handleValidation(vals));
830
-
831
- expect(fields).toMatchObject([
832
- {
833
- description: 'Do you have any siblings?',
834
- label: 'Has siblings',
835
- name: 'has_siblings',
836
- options: [
837
- {
838
- label: 'Yes',
839
- value: 'true',
840
- },
841
- {
842
- label: 'No',
843
- value: 'false',
844
- },
845
- ],
846
- required: true,
847
- schema: expect.any(Object),
848
- type: 'radio',
849
- },
850
- ]);
851
-
852
- assertOptionsAllowed({
853
- handleValidation,
854
- fieldName: 'has_siblings',
855
- validOptions: ['true', 'false'],
856
- });
857
-
858
- expect(validateForm({ has_siblings: false })).toEqual({
859
- has_siblings: 'The option "false" is not valid.',
860
- });
861
- });
862
-
863
824
  it('support "radio" field number type', () => {
864
825
  const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioNumber);
865
826
 
@@ -1034,6 +995,41 @@ describe('createHeadlessForm', () => {
1034
995
  expect(fieldOptions).toEqual([]);
1035
996
  });
1036
997
 
998
+ it('support "integer" field type', () => {
999
+ const result = createHeadlessForm(schemaInputTypeIntegerNumber);
1000
+ expect(result).toMatchObject({
1001
+ fields: [
1002
+ {
1003
+ description: 'How many open tabs do you have?',
1004
+ label: 'Tabs',
1005
+ name: 'tabs',
1006
+ required: false,
1007
+ schema: expect.any(Object),
1008
+ type: 'number',
1009
+ jsonType: 'integer',
1010
+ inputType: 'number',
1011
+ minimum: 1,
1012
+ maximum: 10,
1013
+ },
1014
+ ],
1015
+ });
1016
+
1017
+ const fieldValidator = result.fields[0].schema;
1018
+ expect(fieldValidator.isValidSync('0')).toBe(false);
1019
+ expect(fieldValidator.isValidSync('10')).toBe(true);
1020
+ expect(fieldValidator.isValidSync('11')).toBe(false);
1021
+ expect(fieldValidator.isValidSync('5.5')).toBe(false);
1022
+ expect(fieldValidator.isValidSync('1.0')).toBe(true);
1023
+ expect(fieldValidator.isValidSync('this is text with a number 1')).toBe(false);
1024
+ expect(() => fieldValidator.validateSync('5.5')).toThrowError(
1025
+ 'Must not contain decimal points. E.g. 5 instead of 5.5'
1026
+ );
1027
+ expect(() => fieldValidator.validateSync('some text')).toThrowError(
1028
+ 'The value must be a number'
1029
+ );
1030
+ expect(() => fieldValidator.validateSync('')).toThrowError('The value must be a number');
1031
+ });
1032
+
1037
1033
  it('support "number" field type', () => {
1038
1034
  const result = createHeadlessForm(schemaInputTypeNumber);
1039
1035
  expect(result).toMatchObject({
@@ -194,7 +194,7 @@ export const schemaInputTypeHidden = {
194
194
  title: 'Money hidden',
195
195
  'x-jsf-presentation': { inputType: 'hidden', currency: 'EUR' },
196
196
  minimum: 0,
197
- default: 12.3,
197
+ default: 1099,
198
198
  },
199
199
  a_hidden_select: {
200
200
  ...mockSelectInputSolo,
@@ -61,6 +61,21 @@ export const schemaInputTypeNumberZeroMaximum = {
61
61
  },
62
62
  };
63
63
 
64
+ export const schemaInputTypeIntegerNumber = {
65
+ properties: {
66
+ tabs: {
67
+ title: 'Tabs',
68
+ description: 'How many open tabs do you have?',
69
+ 'x-jsf-presentation': {
70
+ inputType: 'number',
71
+ },
72
+ minimum: 1,
73
+ maximum: 10,
74
+ type: 'integer',
75
+ },
76
+ },
77
+ };
78
+
64
79
  export const mockNumberInputWithPercentage = {
65
80
  title: 'Shares',
66
81
  description: 'What % of shares do you own?',
@@ -148,25 +163,6 @@ export const mockRadioInputBoolean = {
148
163
  type: 'boolean',
149
164
  };
150
165
 
151
- export const mockRadioInputStringY = {
152
- title: 'Has siblings',
153
- description: 'Do you have any siblings?',
154
- oneOf: [
155
- {
156
- title: 'Yes',
157
- const: 'true',
158
- },
159
- {
160
- title: 'No',
161
- const: 'false',
162
- },
163
- ],
164
- 'x-jsf-presentation': {
165
- inputType: 'radio',
166
- },
167
- type: 'string',
168
- };
169
-
170
166
  export const mockRadioInputNumber = {
171
167
  title: 'Number of siblings',
172
168
  description: 'How many siblings do you have?',
@@ -918,13 +914,6 @@ export const schemaInputTypeRadioString = {
918
914
  required: ['has_siblings'],
919
915
  };
920
916
 
921
- export const schemaInputTypeRadioStringY = {
922
- properties: {
923
- has_siblings: mockRadioInputStringY,
924
- },
925
- required: ['has_siblings'],
926
- };
927
-
928
917
  export const schemaInputTypeRadioBoolean = {
929
918
  properties: {
930
919
  over_18: mockRadioInputBoolean,