@remoteoss/json-schema-form 0.7.1-dev.20231031082524 → 0.7.2-beta.0

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.7.2-beta.0 (2023-11-06)
2
+
3
+ ##### Bug Fixes
4
+
5
+ * **select/radio:** Support oneOf[].pattern validation ([#47](https://github.com/remoteoss/json-schema-form/pull/47)) ([5a4bb592](https://github.com/remoteoss/json-schema-form/commit/5a4bb59266ff595a9cb65f5b261a4ae2f3ad279f))
6
+
7
+ #### 0.7.1-beta.0 (2023-10-31)
8
+
9
+ ##### Bug Fixes
10
+
11
+ - **select:** support string type ([#54](https://github.com/remoteoss/json-schema-form/pull/54)) ([b00f8776](https://github.com/remoteoss/json-schema-form/commit/b00f8776aa244803375ba64fbdd52c8fff9b9bd8))
12
+
1
13
  #### 0.7.0-beta.0 (2023-10-23)
2
14
 
3
15
  ##### Chores
@@ -27,10 +39,8 @@ BREAKING CHANGES:
27
39
 
28
40
  - json-logic: Add conditional logic checking. ([#41](https://github.com/remoteoss/json-schema-form/pull/41)) ([6292b01e](https://github.com/remoteoss/json-schema-form/commit/6292b01e3f77a9038328d7375080ffc4cb30dbc8))
29
41
 
30
-
31
42
  ###### Full API additions now supported from 0.6.5 onwards.
32
43
 
33
-
34
44
  - New custom JSON Schema keyword `x-jsf-logic` added to support cross-field validations. Built on top of [JsonLogic](https://jsonlogic.com/).
35
45
 
36
46
  - `x-jsf-logic` can contain:
@@ -49,16 +59,11 @@ While docs are underway, you can read examples from all the [tests](https://gith
49
59
 
50
60
  In short: `x-jsf-logic` is added to support complex conditional cross-field validations. Properties like `x-jsf-logic-validations` allow hooking those up to individual fields.
51
61
 
52
-
53
62
  #### 0.6.4-beta.0 (2023-09-15)
54
63
 
55
-
56
-
57
64
  ##### Changes
58
- - json-logic: computedAttrs - handle inline rules ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
59
-
60
-
61
65
 
66
+ - json-logic: computedAttrs - handle inline rules ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
62
67
 
63
68
  #### 0.6.1-beta.0 (2023-09-13)
64
69
 
@@ -66,50 +71,43 @@ In short: `x-jsf-logic` is added to support complex conditional cross-field vali
66
71
 
67
72
  - json-logic: Computed string based values ([#37](https://github.com/remoteoss/json-schema-form/pull/37)) ([6e042ea5](https://github.com/remoteoss/json-schema-form/commit/6e042ea579497ea573710c307a6ff7ee2f19b931))
68
73
 
69
-
70
-
71
-
72
74
  #### 0.5.0-beta.0 (2023-09-12)
73
75
 
74
76
  ##### Changes
77
+
75
78
  - json-logic: Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
76
79
  - json-logic: Initial skeleton implementation ([#35](https://github.com/remoteoss/json-schema-form/pull/35)) ([63149ae8](https://github.com/remoteoss/json-schema-form/commit/63149ae863cf1b5ad76a3b2a49c7f343e55ce07b))
77
80
 
78
-
79
-
80
-
81
81
  #### 0.4.5-beta.0 (2023-08-31)
82
+
82
83
  ##### Bug fixes
83
84
 
84
85
  - Validate values based on `const` key ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
85
86
 
86
-
87
-
88
-
89
87
  #### 0.4.4-beta.0 (2023-08-30)
90
88
 
91
89
  ##### Chores
92
90
 
93
- * **fieldset:** ignore values not matching the field type ([#44](https://github.com/remoteoss/json-schema-form/pull/44)) ([f0af54e5](https://github.com/remoteoss/json-schema-form/commit/f0af54e5d425fb78524ab150bb31629d00369a61))
91
+ - **fieldset:** ignore values not matching the field type ([#44](https://github.com/remoteoss/json-schema-form/pull/44)) ([f0af54e5](https://github.com/remoteoss/json-schema-form/commit/f0af54e5d425fb78524ab150bb31629d00369a61))
94
92
 
95
93
  #### 0.4.3-beta.0 (2023-08-09)
96
94
 
97
95
  ##### Bug fixes
98
96
 
99
- * **conditions:** Validate a deeply nested if (e.g. checking an object with a number property) in an if property now doesn't break the form. ([#33](https://github.com/remoteoss/json-schema-form/pull/33)) ([e34cfcc](https://github.com/remoteoss/json-schema-form/commit/e34cfccaf45f1460b346f3cff0c797b3d11259e3))
97
+ - **conditions:** Validate a deeply nested if (e.g. checking an object with a number property) in an if property now doesn't break the form. ([#33](https://github.com/remoteoss/json-schema-form/pull/33)) ([e34cfcc](https://github.com/remoteoss/json-schema-form/commit/e34cfccaf45f1460b346f3cff0c797b3d11259e3))
100
98
 
101
99
  #### 0.4.2-beta.0 (2023-07-20)
102
100
 
103
101
  ##### Bug Fixes
104
102
 
105
- * **date:** Validate based on minDate and maxDate ([#30](https://github.com/remoteoss/json-schema-form/pull/30)) ([01c0143e](https://github.com/remoteoss/json-schema-form/commit/01c0143ea4a3775f9489ae6cb8fd99a90b3f1394))
103
+ - **date:** Validate based on minDate and maxDate ([#30](https://github.com/remoteoss/json-schema-form/pull/30)) ([01c0143e](https://github.com/remoteoss/json-schema-form/commit/01c0143ea4a3775f9489ae6cb8fd99a90b3f1394))
106
104
 
107
105
  #### 0.4.1-beta.0 (2023-07-03)
108
106
 
109
107
  ##### Bug Fixes
110
108
 
111
- * **fieldset:** support root conditionals for fieldsets ([#23](https://github.com/remoteoss/json-schema-form/pull/23)) ([65d87b3a](https://github.com/remoteoss/json-schema-form/commit/65d87b3a93018f0729aed565000eb2a2ce1f2ce7))
112
- * **select/radio:** Accept just the values in options (plus `''` and `null` for backward-compatibility) ([#18](https://github.com/remoteoss/json-schema-form/pull/18)) ([37501d2d](https://github.com/remoteoss/json-schema-form/commit/37501d2ddafdd5e207b34d2ca3f6b7b7a1006e9d))
109
+ - **fieldset:** support root conditionals for fieldsets ([#23](https://github.com/remoteoss/json-schema-form/pull/23)) ([65d87b3a](https://github.com/remoteoss/json-schema-form/commit/65d87b3a93018f0729aed565000eb2a2ce1f2ce7))
110
+ - **select/radio:** Accept just the values in options (plus `''` and `null` for backward-compatibility) ([#18](https://github.com/remoteoss/json-schema-form/pull/18)) ([37501d2d](https://github.com/remoteoss/json-schema-form/commit/37501d2ddafdd5e207b34d2ca3f6b7b7a1006e9d))
113
111
 
114
112
  #### 0.4.0-beta.0 (2023-06-22)
115
113
 
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
5
- Generated: Tue, 31 Oct 2023 08:25:53 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
5
+ Generated: Mon, 06 Nov 2023 19:11:58 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -469,13 +469,34 @@ var yupSchemas = {
469
469
  if (value === "") {
470
470
  return void 0;
471
471
  }
472
- if (options?.includes(null)) {
472
+ if (options?.some((option) => option.value === null)) {
473
473
  return value;
474
474
  }
475
475
  return value === null ? void 0 : value;
476
- }).oneOf(options, ({ value }) => {
477
- return `The option ${JSON.stringify(value)} is not valid.`;
478
- });
476
+ }).test(
477
+ /*
478
+ Custom test determines if the value either:
479
+ - Matches a specific option by value
480
+ - Matches a pattern
481
+ If the option is undefined do not test, to allow for optional fields.
482
+ */
483
+ "matchesOptionOrPattern",
484
+ ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
485
+ (value) => {
486
+ if (value === void 0) {
487
+ return true;
488
+ }
489
+ const exactMatch = options.some((option) => option.value === value);
490
+ if (exactMatch) {
491
+ return true;
492
+ }
493
+ const patternMatch = options.some((option) => option.pattern?.test(value));
494
+ if (patternMatch) {
495
+ return true;
496
+ }
497
+ return false;
498
+ }
499
+ );
479
500
  },
480
501
  date: ({ minDate, maxDate }) => {
481
502
  let dateString = (0, import_yup.string)().nullable().transform((value) => {
@@ -534,12 +555,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
534
555
  }
535
556
  var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
536
557
  var getOptions = (field) => {
537
- const allValues = field.options?.map((option) => option.value);
558
+ const allValues = field.options?.map((option) => ({
559
+ value: option.value,
560
+ pattern: option.pattern ? new RegExp(option.pattern) : null
561
+ }));
538
562
  const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
539
563
  // option but we don't have direct access at this point.
540
564
  // Otherwise the JSON Schema validator will fail as explained in PR#18
541
565
  field.jsonType.includes("null");
542
- return isOptionalWithNull ? [...allValues, null] : allValues;
566
+ return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
543
567
  };
544
568
  var getYupSchema = ({ inputType, ...field }) => {
545
569
  const jsonType = getJsonTypeInArray(field.jsonType);
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
5
- Generated: Tue, 31 Oct 2023 08:25:53 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
5
+ Generated: Mon, 06 Nov 2023 19:11:58 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -433,13 +433,34 @@ var yupSchemas = {
433
433
  if (value === "") {
434
434
  return void 0;
435
435
  }
436
- if (options?.includes(null)) {
436
+ if (options?.some((option) => option.value === null)) {
437
437
  return value;
438
438
  }
439
439
  return value === null ? void 0 : value;
440
- }).oneOf(options, ({ value }) => {
441
- return `The option ${JSON.stringify(value)} is not valid.`;
442
- });
440
+ }).test(
441
+ /*
442
+ Custom test determines if the value either:
443
+ - Matches a specific option by value
444
+ - Matches a pattern
445
+ If the option is undefined do not test, to allow for optional fields.
446
+ */
447
+ "matchesOptionOrPattern",
448
+ ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
449
+ (value) => {
450
+ if (value === void 0) {
451
+ return true;
452
+ }
453
+ const exactMatch = options.some((option) => option.value === value);
454
+ if (exactMatch) {
455
+ return true;
456
+ }
457
+ const patternMatch = options.some((option) => option.pattern?.test(value));
458
+ if (patternMatch) {
459
+ return true;
460
+ }
461
+ return false;
462
+ }
463
+ );
443
464
  },
444
465
  date: ({ minDate, maxDate }) => {
445
466
  let dateString = string().nullable().transform((value) => {
@@ -498,12 +519,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
498
519
  }
499
520
  var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
500
521
  var getOptions = (field) => {
501
- const allValues = field.options?.map((option) => option.value);
522
+ const allValues = field.options?.map((option) => ({
523
+ value: option.value,
524
+ pattern: option.pattern ? new RegExp(option.pattern) : null
525
+ }));
502
526
  const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
503
527
  // option but we don't have direct access at this point.
504
528
  // Otherwise the JSON Schema validator will fail as explained in PR#18
505
529
  field.jsonType.includes("null");
506
- return isOptionalWithNull ? [...allValues, null] : allValues;
530
+ return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
507
531
  };
508
532
  var getYupSchema = ({ inputType, ...field }) => {
509
533
  const jsonType = getJsonTypeInArray(field.jsonType);
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.7.1-dev.20231031082524
5
- Generated: Tue, 31 Oct 2023 08:25:53 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.7.2-beta.0
5
+ Generated: Mon, 06 Nov 2023 19:11:58 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11787,13 +11787,34 @@ var yupSchemas = {
11787
11787
  if (value === "") {
11788
11788
  return void 0;
11789
11789
  }
11790
- if (options?.includes(null)) {
11790
+ if (options?.some((option) => option.value === null)) {
11791
11791
  return value;
11792
11792
  }
11793
11793
  return value === null ? void 0 : value;
11794
- }).oneOf(options, ({ value }) => {
11795
- return `The option ${JSON.stringify(value)} is not valid.`;
11796
- });
11794
+ }).test(
11795
+ /*
11796
+ Custom test determines if the value either:
11797
+ - Matches a specific option by value
11798
+ - Matches a pattern
11799
+ If the option is undefined do not test, to allow for optional fields.
11800
+ */
11801
+ "matchesOptionOrPattern",
11802
+ ({ value }) => `The option ${JSON.stringify(value)} is not valid.`,
11803
+ (value) => {
11804
+ if (value === void 0) {
11805
+ return true;
11806
+ }
11807
+ const exactMatch = options.some((option) => option.value === value);
11808
+ if (exactMatch) {
11809
+ return true;
11810
+ }
11811
+ const patternMatch = options.some((option) => option.pattern?.test(value));
11812
+ if (patternMatch) {
11813
+ return true;
11814
+ }
11815
+ return false;
11816
+ }
11817
+ );
11797
11818
  },
11798
11819
  date: ({ minDate, maxDate }) => {
11799
11820
  let dateString = StringSchema().nullable().transform((value) => {
@@ -11852,12 +11873,15 @@ function getRequiredErrorMessage(inputType, { inlineError, configError }) {
11852
11873
  }
11853
11874
  var getJsonTypeInArray = (jsonType) => Array.isArray(jsonType) ? jsonType.find((val) => val !== "null") : jsonType;
11854
11875
  var getOptions = (field) => {
11855
- const allValues = field.options?.map((option) => option.value);
11876
+ const allValues = field.options?.map((option) => ({
11877
+ value: option.value,
11878
+ pattern: option.pattern ? new RegExp(option.pattern) : null
11879
+ }));
11856
11880
  const isOptionalWithNull = Array.isArray(field.jsonType) && // @TODO should also check the "oneOf" directly looking for "null"
11857
11881
  // option but we don't have direct access at this point.
11858
11882
  // Otherwise the JSON Schema validator will fail as explained in PR#18
11859
11883
  field.jsonType.includes("null");
11860
- return isOptionalWithNull ? [...allValues, null] : allValues;
11884
+ return isOptionalWithNull ? [...allValues, { option: null }] : allValues;
11861
11885
  };
11862
11886
  var getYupSchema = ({ inputType, ...field }) => {
11863
11887
  const jsonType = getJsonTypeInArray(field.jsonType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.7.1-dev.20231031082524",
3
+ "version": "0.7.2-beta.0",
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",
@@ -39,6 +39,7 @@ import {
39
39
  mockFileInput,
40
40
  mockRadioCardInput,
41
41
  mockRadioCardExpandableInput,
42
+ mockTelWithPattern,
42
43
  mockTextInput,
43
44
  mockTextInputDeprecated,
44
45
  mockNumberInput,
@@ -1485,6 +1486,51 @@ describe('createHeadlessForm', () => {
1485
1486
  });
1486
1487
  });
1487
1488
 
1489
+ it('supports oneOf pattern validation', () => {
1490
+ const result = createHeadlessForm(mockTelWithPattern);
1491
+
1492
+ expect(result).toMatchObject({
1493
+ fields: [
1494
+ {
1495
+ label: 'Phone number',
1496
+ name: 'phone_number',
1497
+ type: 'tel',
1498
+ required: false,
1499
+ options: [
1500
+ {
1501
+ label: 'Portugal',
1502
+ pattern: '^(\\+351)[0-9]{9,}$',
1503
+ },
1504
+ {
1505
+ label: 'United Kingdom (UK)',
1506
+ pattern: '^(\\+44)[0-9]{1,}$',
1507
+ },
1508
+ {
1509
+ label: 'Bolivia',
1510
+ pattern: '^(\\+591)[0-9]{9,}$',
1511
+ },
1512
+ {
1513
+ label: 'Canada',
1514
+ pattern: '^(\\+1)(206|224)[0-9]{1,}$',
1515
+ },
1516
+ {
1517
+ label: 'United States',
1518
+ pattern: '^(\\+1)[0-9]{1,}$',
1519
+ },
1520
+ ],
1521
+ },
1522
+ ],
1523
+ });
1524
+
1525
+ const fieldValidator = result.fields[0].schema;
1526
+
1527
+ expect(fieldValidator.isValidSync('+351123123123')).toBe(true);
1528
+ expect(() => fieldValidator.validateSync('+35100')).toThrowError(
1529
+ 'The option "+35100" is not valid.'
1530
+ );
1531
+ expect(fieldValidator.isValidSync(undefined)).toBe(true);
1532
+ });
1533
+
1488
1534
  describe('supports "fieldset" field type', () => {
1489
1535
  it('supports basic case', () => {
1490
1536
  const result = createHeadlessForm({
@@ -458,6 +458,46 @@ export const mockCheckboxInput = {
458
458
  type: 'string',
459
459
  };
460
460
 
461
+ export const mockTelWithPattern = {
462
+ properties: {
463
+ phone_number: {
464
+ title: 'Phone number',
465
+ description: 'Enter your telephone number',
466
+ type: 'string',
467
+ 'x-jsf-presentation': {
468
+ inputType: 'tel',
469
+ },
470
+ oneOf: [
471
+ {
472
+ title: 'Portugal',
473
+ pattern: '^(\\+351)[0-9]{9,}$',
474
+ 'x-jsf-presentation': { meta: { countryCode: '351' } },
475
+ },
476
+ {
477
+ title: 'United Kingdom (UK)',
478
+ pattern: '^(\\+44)[0-9]{1,}$',
479
+ 'x-jsf-presentation': { meta: { countryCode: '44' } },
480
+ },
481
+ {
482
+ title: 'Bolivia',
483
+ pattern: '^(\\+591)[0-9]{9,}$',
484
+ 'x-jsf-presentation': { meta: { countryCode: '591' } },
485
+ },
486
+ {
487
+ title: 'Canada',
488
+ pattern: '^(\\+1)(206|224)[0-9]{1,}$',
489
+ 'x-jsf-presentation': { meta: { countryCode: '1' } },
490
+ },
491
+ {
492
+ title: 'United States',
493
+ pattern: '^(\\+1)[0-9]{1,}$',
494
+ 'x-jsf-presentation': { meta: { countryCode: '1' } },
495
+ },
496
+ ],
497
+ },
498
+ },
499
+ };
500
+
461
501
  /**
462
502
  * Compose a schema with lower chance of human error
463
503
  * @param {Object} schema version