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

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 CHANGED
@@ -1,3 +1,15 @@
1
+ #### 0.11.8-beta.0 (2024-11-20)
2
+
3
+ ##### Bug Fixes
4
+
5
+ * **integer:** support integer field type ([#11](https://github.com/remoteoss/json-schema-form/pull/11)) ([14f34971](https://github.com/remoteoss/json-schema-form/commit/14f349714ce7b294ae710801168b017692c659af))
6
+
7
+ #### 0.11.7-beta.0 (2024-11-14)
8
+
9
+ ##### Bug Fixes
10
+
11
+ * **validation:** validate radio with string-y types; ([#94](https://github.com/remoteoss/json-schema-form/pull/94)) ([606913d8](https://github.com/remoteoss/json-schema-form/commit/606913d8412a02d9a38a43e903add58b8e11a7e4))
12
+
1
13
  #### 0.11.6-beta.0 (2024-10-15)
2
14
 
3
15
  ##### 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.7-dev.20241120091537
5
- Generated: Wed, 20 Nov 2024 09:15:48 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241127210659
5
+ Generated: Wed, 27 Nov 2024 21:07:13 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -481,7 +481,12 @@ var yupSchemas = {
481
481
  }).test(
482
482
  "matchesOptionOrPattern",
483
483
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
484
- (value) => validateRadioOrSelectOptions(value, options)
484
+ (castValue, { originalValue }) => {
485
+ if (castValue !== void 0 && typeof originalValue !== "string") {
486
+ return false;
487
+ }
488
+ return validateRadioOrSelectOptions(castValue, options);
489
+ }
485
490
  );
486
491
  },
487
492
  date: ({ minDate, maxDate }) => {
@@ -1047,6 +1052,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
1047
1052
  subRule.map((item) => {
1048
1053
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
1049
1054
  if (isVar) {
1055
+ if (Array.isArray(item.var))
1056
+ return;
1050
1057
  const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
1051
1058
  if (exists === null) {
1052
1059
  throw Error(errorMessage(item));
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.20241120091537
5
- Generated: Wed, 20 Nov 2024 09:15:48 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241127210659
5
+ Generated: Wed, 27 Nov 2024 21:07:13 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -444,7 +444,12 @@ var yupSchemas = {
444
444
  }).test(
445
445
  "matchesOptionOrPattern",
446
446
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
447
- (value) => validateRadioOrSelectOptions(value, options)
447
+ (castValue, { originalValue }) => {
448
+ if (castValue !== void 0 && typeof originalValue !== "string") {
449
+ return false;
450
+ }
451
+ return validateRadioOrSelectOptions(castValue, options);
452
+ }
448
453
  );
449
454
  },
450
455
  date: ({ minDate, maxDate }) => {
@@ -1010,6 +1015,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
1010
1015
  subRule.map((item) => {
1011
1016
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
1012
1017
  if (isVar) {
1018
+ if (Array.isArray(item.var))
1019
+ return;
1013
1020
  const exists = jsonLogic.apply({ var: removeIndicesFromPath(item.var) }, data);
1014
1021
  if (exists === null) {
1015
1022
  throw Error(errorMessage(item));
@@ -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.20241120091537
5
- Generated: Wed, 20 Nov 2024 09:15:48 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241127210659
5
+ Generated: Wed, 27 Nov 2024 21:07:13 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11960,7 +11960,12 @@ var yupSchemas = {
11960
11960
  }).test(
11961
11961
  "matchesOptionOrPattern",
11962
11962
  ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
11963
- (value) => validateRadioOrSelectOptions(value, options)
11963
+ (castValue, { originalValue }) => {
11964
+ if (castValue !== void 0 && typeof originalValue !== "string") {
11965
+ return false;
11966
+ }
11967
+ return validateRadioOrSelectOptions(castValue, options);
11968
+ }
11964
11969
  );
11965
11970
  },
11966
11971
  date: ({ minDate, maxDate }) => {
@@ -12526,6 +12531,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
12526
12531
  subRule.map((item) => {
12527
12532
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
12528
12533
  if (isVar) {
12534
+ if (Array.isArray(item.var))
12535
+ return;
12529
12536
  const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
12530
12537
  if (exists === null) {
12531
12538
  throw Error(errorMessage(item));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.7-dev.20241120091537",
3
+ "version": "0.11.9-dev.20241127210659",
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,6 +9,7 @@ import {
9
9
  schemaInputTypeText,
10
10
  schemaInputTypeRadioDeprecated,
11
11
  schemaInputTypeRadioString,
12
+ schemaInputTypeRadioStringY,
12
13
  schemaInputTypeRadioBoolean,
13
14
  schemaInputTypeRadioNumber,
14
15
  schemaInputTypeRadioRequiredAndOptional,
@@ -821,6 +822,45 @@ describe('createHeadlessForm', () => {
821
822
  });
822
823
  });
823
824
 
825
+ // @BUG COD-1859
826
+ // it should validate when type is string but value is not a boolean
827
+ it('support "radio" field string-y type', () => {
828
+ const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioStringY);
829
+
830
+ const validateForm = (vals) => friendlyError(handleValidation(vals));
831
+
832
+ expect(fields).toMatchObject([
833
+ {
834
+ description: 'Do you have any siblings?',
835
+ label: 'Has siblings',
836
+ name: 'has_siblings',
837
+ options: [
838
+ {
839
+ label: 'Yes',
840
+ value: 'true',
841
+ },
842
+ {
843
+ label: 'No',
844
+ value: 'false',
845
+ },
846
+ ],
847
+ required: true,
848
+ schema: expect.any(Object),
849
+ type: 'radio',
850
+ },
851
+ ]);
852
+
853
+ assertOptionsAllowed({
854
+ handleValidation,
855
+ fieldName: 'has_siblings',
856
+ validOptions: ['true', 'false'],
857
+ });
858
+
859
+ expect(validateForm({ has_siblings: false })).toEqual({
860
+ has_siblings: 'The option "false" is not valid.',
861
+ });
862
+ });
863
+
824
864
  it('support "radio" field number type', () => {
825
865
  const { fields, handleValidation } = createHeadlessForm(schemaInputTypeRadioNumber);
826
866
 
@@ -163,6 +163,25 @@ export const mockRadioInputBoolean = {
163
163
  type: 'boolean',
164
164
  };
165
165
 
166
+ export const mockRadioInputStringY = {
167
+ title: 'Has siblings',
168
+ description: 'Do you have any siblings?',
169
+ oneOf: [
170
+ {
171
+ title: 'Yes',
172
+ const: 'true',
173
+ },
174
+ {
175
+ title: 'No',
176
+ const: 'false',
177
+ },
178
+ ],
179
+ 'x-jsf-presentation': {
180
+ inputType: 'radio',
181
+ },
182
+ type: 'string',
183
+ };
184
+
166
185
  export const mockRadioInputNumber = {
167
186
  title: 'Number of siblings',
168
187
  description: 'How many siblings do you have?',
@@ -914,6 +933,13 @@ export const schemaInputTypeRadioString = {
914
933
  required: ['has_siblings'],
915
934
  };
916
935
 
936
+ export const schemaInputTypeRadioStringY = {
937
+ properties: {
938
+ has_siblings: mockRadioInputStringY,
939
+ },
940
+ required: ['has_siblings'],
941
+ };
942
+
917
943
  export const schemaInputTypeRadioBoolean = {
918
944
  properties: {
919
945
  over_18: mockRadioInputBoolean,
@@ -984,3 +984,51 @@ export const schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally = {
984
984
  },
985
985
  ],
986
986
  };
987
+
988
+ export const schemaWithReduceAccumulator = {
989
+ properties: {
990
+ work_days: {
991
+ items: {
992
+ anyOf: [
993
+ { const: 'monday', title: 'Monday' },
994
+ { const: 'tuesday', title: 'Tuesday' },
995
+ { const: 'wednesday', title: 'Wednesday' },
996
+ { const: 'thursday', title: 'Thursday' },
997
+ { const: 'friday', title: 'Friday' },
998
+ { const: 'saturday', title: 'Saturday' },
999
+ { const: 'sunday', title: 'Sunday' },
1000
+ ],
1001
+ },
1002
+ type: 'array',
1003
+ uniqueItems: true,
1004
+ 'x-jsf-presentation': {
1005
+ inputType: 'select',
1006
+ },
1007
+ },
1008
+ working_hours_per_day: {
1009
+ type: 'number',
1010
+ },
1011
+ working_hours_per_week: {
1012
+ type: 'number',
1013
+ 'x-jsf-logic-computedAttrs': {
1014
+ const: 'computed_work_hours_per_week',
1015
+ defaultValue: 'computed_work_hours_per_week',
1016
+ title: '{{computed_work_hours_per_week}} hours per week',
1017
+ },
1018
+ },
1019
+ },
1020
+ 'x-jsf-logic': {
1021
+ computedValues: {
1022
+ computed_work_hours_per_week: {
1023
+ rule: {
1024
+ '*': [
1025
+ { var: 'working_hours_per_day' },
1026
+ {
1027
+ reduce: [{ var: 'work_days' }, { '+': [{ var: ['accumulator', 0] }, 1] }, 0],
1028
+ },
1029
+ ],
1030
+ },
1031
+ },
1032
+ },
1033
+ },
1034
+ };
@@ -36,6 +36,7 @@ import {
36
36
  schemaWithUnknownVariableInValidations,
37
37
  schemaWithValidationThatDoesNotExistOnProperty,
38
38
  badSchemaThatWillNotSetAForcedValue,
39
+ schemaWithReduceAccumulator,
39
40
  } from './jsonLogic.fixtures';
40
41
  import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
41
42
 
@@ -244,6 +245,22 @@ describe('jsonLogic: cross-values validations', () => {
244
245
  });
245
246
  });
246
247
 
248
+ describe('Reduce', () => {
249
+ it('reduce: working_hours_per_day * work_days', () => {
250
+ const { fields, handleValidation } = createHeadlessForm(schemaWithReduceAccumulator, {
251
+ strictInputType: false,
252
+ });
253
+ handleValidation({
254
+ work_days: ['monday', 'tuesday'],
255
+ working_hours_per_day: 8,
256
+ });
257
+ const field = fields.find((i) => i.name === 'working_hours_per_week');
258
+ expect(field.const).toEqual(16);
259
+ expect(field.default).toEqual(16);
260
+ expect(field.label).toEqual('16 hours per week');
261
+ });
262
+ });
263
+
247
264
  describe('Logical: ||, &&', () => {
248
265
  it('AND: field_a > field_b && field_a > field_c (implicit with multiple rules in a single field)', () => {
249
266
  const schema = createSchemaWithThreePropertiesWithRuleOnFieldA({