@remoteoss/json-schema-form 0.6.5-beta.0 → 0.6.6-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,37 +1,77 @@
1
+ #### 0.6.6-beta.0 (2023-10-17)
2
+
3
+ ##### Chores
4
+
5
+ - **github:** Add template for issues and pull requests ([#45](https://github.com/remoteoss/json-schema-form/pull/45)) ([621e3338](https://github.com/remoteoss/json-schema-form/commit/621e33389638541e771d2229c91655e430ea7ec4))
6
+
7
+ ##### Bug Fixes
8
+
9
+ - allow 0 in const validation ([#48](https://github.com/remoteoss/json-schema-form/pull/48)) ([cde19fc9](https://github.com/remoteoss/json-schema-form/commit/cde19fc960c4eacdde476ddcdd8c650a4ff5ce96))
10
+
1
11
  #### 0.6.5-beta.0 (2023-09-18)
2
12
 
3
13
  ##### Changes
4
14
 
5
- - Add conditional logic checking for json-logic ([#41](https://github.com/remoteoss/json-schema-form/pull/41)) ([6292b01e](https://github.com/remoteoss/json-schema-form/commit/6292b01e3f77a9038328d7375080ffc4cb30dbc8))
15
+ - 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))
16
+
17
+
18
+ ###### Full API additions now supported from 0.6.5 onwards.
19
+
20
+
21
+ - New custom JSON Schema keyword `x-jsf-logic` added to support cross-field validations. Built on top of [JsonLogic](https://jsonlogic.com/).
22
+
23
+ - `x-jsf-logic` can contain:
24
+
25
+ - `validations` - JsonLogic rules that validate fields and return booleans
26
+ - `computedValues` - JsonLogic rules that compute dynamic values
27
+ - `allOf.if/then/else` - Conditional logic using validations and computedValues
28
+
29
+ - New property `x-jsf-logic-validations` added to individual schema properties. Lists the validation names that should run on that property.
30
+ - New property `x-jsf-logic-computedAttrs` added to individual schema properties. Allows computed values to be used for attributes like `title`, `description`, `const`, etc.
31
+ - Computed values and validations defined in `x-jsf-logic` can reference schema properties using `vars` and any syntax supported from [JsonLogic](https://jsonlogic.com/).
32
+
33
+ - Conditional logic blocks allow selectively requiring fields or applying attributes based on validations/computed values.
34
+
35
+ While docs are underway, you can read examples from all the [tests](https://github.com/remoteoss/json-schema-form/blob/main/src/tests/jsonLogic.test.js) along with the [sample schemas](https://github.com/remoteoss/json-schema-form/blob/main/src/tests/jsonLogic.fixtures.js).
36
+
37
+ 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.
38
+
6
39
 
7
40
  #### 0.6.4-beta.0 (2023-09-15)
8
41
 
9
42
 
10
43
 
11
44
  ##### Changes
45
+ - 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))
46
+
47
+
12
48
 
13
- * Inline rule handling for computedAttrs ([#40](https://github.com/remoteoss/json-schema-form/pull/40)) ([860ad91b](https://github.com/remoteoss/json-schema-form/commit/860ad91b034ab35d4d4bc51c0c04675f102bf278))
14
49
 
15
50
  #### 0.6.1-beta.0 (2023-09-13)
16
51
 
17
52
  ##### Changes
18
53
 
54
+ - 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))
55
+
19
56
 
20
57
 
21
- - Computed string based values for json-logic ([#37](https://github.com/remoteoss/json-schema-form/pull/37)) ([6e042ea5](https://github.com/remoteoss/json-schema-form/commit/6e042ea579497ea573710c307a6ff7ee2f19b931))
22
58
 
23
59
  #### 0.5.0-beta.0 (2023-09-12)
24
60
 
25
61
  ##### Changes
62
+ - json-logic: Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
63
+ - 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))
64
+
65
+
26
66
 
27
- - Computed Attributes ([#36](https://github.com/remoteoss/json-schema-form/pull/36)) ([80c29589](https://github.com/remoteoss/json-schema-form/commit/80c29589ac0972e0f33add70a59df15a46db1b43))
28
- - JSON Logic Skeleton ([#35](https://github.com/remoteoss/json-schema-form/pull/35)) ([63149ae8](https://github.com/remoteoss/json-schema-form/commit/63149ae863cf1b5ad76a3b2a49c7f343e55ce07b))
29
67
 
30
68
  #### 0.4.5-beta.0 (2023-08-31)
69
+ ##### Bug fixes
70
+
71
+ - 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))
72
+
31
73
 
32
- ##### Changes
33
74
 
34
- * Allow validation of consts to support single values ([#34](https://github.com/remoteoss/json-schema-form/pull/34)) ([bf07870d](https://github.com/remoteoss/json-schema-form/commit/bf07870d407d9b9b078882a078b9e4c7928df868))
35
75
 
36
76
  #### 0.4.4-beta.0 (2023-08-30)
37
77
 
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.6.5-beta.0
5
- Generated: Mon, 18 Sep 2023 10:09:01 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.6.6-beta.0
5
+ Generated: Tue, 17 Oct 2023 13:38:25 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -701,7 +701,7 @@ function buildYupSchema(field, config, logic) {
701
701
  if (propertyFields.accept) {
702
702
  validators.push(withFileFormat);
703
703
  }
704
- if (propertyFields.const) {
704
+ if (typeof propertyFields.const !== "undefined") {
705
705
  validators.push(withConst);
706
706
  }
707
707
  if (propertyFields.jsonLogicValidations) {
@@ -1330,10 +1330,11 @@ function extractParametersFromNode(schemaNode) {
1330
1330
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
1331
1331
  const description = presentation?.description || node.description;
1332
1332
  const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
1333
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
1333
1334
  return (0, import_omitBy.default)(
1334
1335
  {
1335
1336
  const: node.const,
1336
- ...node.const && node.default ? { value: node.const } : {},
1337
+ ...value,
1337
1338
  label: node.title,
1338
1339
  readOnly: node.readOnly,
1339
1340
  ...node.deprecated && {
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.6.5-beta.0
5
- Generated: Mon, 18 Sep 2023 10:09:01 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.6.6-beta.0
5
+ Generated: Tue, 17 Oct 2023 13:38:25 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -665,7 +665,7 @@ function buildYupSchema(field, config, logic) {
665
665
  if (propertyFields.accept) {
666
666
  validators.push(withFileFormat);
667
667
  }
668
- if (propertyFields.const) {
668
+ if (typeof propertyFields.const !== "undefined") {
669
669
  validators.push(withConst);
670
670
  }
671
671
  if (propertyFields.jsonLogicValidations) {
@@ -1294,10 +1294,11 @@ function extractParametersFromNode(schemaNode) {
1294
1294
  const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
1295
1295
  const description = presentation?.description || node.description;
1296
1296
  const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
1297
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
1297
1298
  return omitBy(
1298
1299
  {
1299
1300
  const: node.const,
1300
- ...node.const && node.default ? { value: node.const } : {},
1301
+ ...value,
1301
1302
  label: node.title,
1302
1303
  readOnly: node.readOnly,
1303
1304
  ...node.deprecated && {
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.6.5-beta.0
5
- Generated: Mon, 18 Sep 2023 10:09:01 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.6.6-beta.0
5
+ Generated: Tue, 17 Oct 2023 13:38:25 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -12019,7 +12019,7 @@ function buildYupSchema(field, config, logic) {
12019
12019
  if (propertyFields.accept) {
12020
12020
  validators.push(withFileFormat);
12021
12021
  }
12022
- if (propertyFields.const) {
12022
+ if (typeof propertyFields.const !== "undefined") {
12023
12023
  validators.push(withConst);
12024
12024
  }
12025
12025
  if (propertyFields.jsonLogicValidations) {
@@ -12648,10 +12648,11 @@ function extractParametersFromNode(schemaNode) {
12648
12648
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
12649
12649
  const description = presentation?.description || node.description;
12650
12650
  const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
12651
+ const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? { value: node.const } : {};
12651
12652
  return (0, import_omitBy.default)(
12652
12653
  {
12653
12654
  const: node.const,
12654
- ...node.const && node.default ? { value: node.const } : {},
12655
+ ...value,
12655
12656
  label: node.title,
12656
12657
  readOnly: node.readOnly,
12657
12658
  ...node.deprecated && {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.6.5-beta.0",
3
+ "version": "0.6.6-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",
@@ -20,6 +20,25 @@ describe('validations: const', () => {
20
20
  expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
21
21
  });
22
22
 
23
+ it('Should work for when the number is 0', () => {
24
+ const { handleValidation } = createHeadlessForm(
25
+ {
26
+ properties: {
27
+ zero_only: { type: 'number', const: 0 },
28
+ },
29
+ },
30
+ { strictInputType: false }
31
+ );
32
+ expect(handleValidation({}).formErrors).toEqual(undefined);
33
+ expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
34
+ zero_only: 'The only accepted value is 0.',
35
+ });
36
+ expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
37
+ // null is also considered valid until we fix @BUG RMT-518
38
+ // Expectation: To fail with error "The only accepted value is 0."
39
+ expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
40
+ });
41
+
23
42
  it('Should work for text', () => {
24
43
  const { handleValidation } = createHeadlessForm(
25
44
  {
@@ -96,3 +115,45 @@ describe('validations: const', () => {
96
115
  expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
97
116
  });
98
117
  });
118
+
119
+ describe('const/default with forced values', () => {
120
+ it('Should work for when the number is 0', () => {
121
+ const { fields, handleValidation } = createHeadlessForm(
122
+ {
123
+ properties: {
124
+ zero_only: { type: 'number', const: 0, default: 0 },
125
+ },
126
+ },
127
+ { strictInputType: false }
128
+ );
129
+ expect(handleValidation({}).formErrors).toEqual(undefined);
130
+ expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
131
+ zero_only: 'The only accepted value is 0.',
132
+ });
133
+ expect(fields[0]).toMatchObject({ value: 0, const: 0, default: 0 });
134
+ expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
135
+ // null is also considered valid until we fix @BUG RMT-518
136
+ // Expectation: To fail with error "The only accepted value is 0."
137
+ expect(handleValidation({ zero_only: null }).formErrors).toBeUndefined();
138
+ });
139
+
140
+ it('Should work for number', () => {
141
+ const { fields, handleValidation } = createHeadlessForm(
142
+ {
143
+ properties: {
144
+ ten_only: { type: 'number', const: 10, default: 10 },
145
+ },
146
+ },
147
+ { strictInputType: false }
148
+ );
149
+ expect(handleValidation({}).formErrors).toEqual(undefined);
150
+ expect(handleValidation({ ten_only: 1 }).formErrors).toEqual({
151
+ ten_only: 'The only accepted value is 10.',
152
+ });
153
+ expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
154
+ expect(fields[0]).toMatchObject({ value: 10, const: 10, default: 10 });
155
+ // null is also considered valid until we fix @BUG RMT-518
156
+ // Expectation: To fail with error "The only accepted value is 10."
157
+ expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
158
+ });
159
+ });