@remoteoss/json-schema-form 0.8.2-beta.0 → 0.9.0-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 +6 -0
- package/dist/index.cjs +5 -4
- package/dist/index.js +5 -4
- package/dist/standalone.js +5 -4
- package/package.json +1 -1
- package/src/tests/const.test.js +39 -3
- package/src/tests/jsonLogic.fixtures.js +29 -0
- package/src/tests/jsonLogic.test.js +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
#### 0.9.0-beta.0 (2024-03-11)
|
|
2
|
+
|
|
3
|
+
##### Breaking changes
|
|
4
|
+
|
|
5
|
+
* Rename `value` -> `forcedValue`. This is in regards to the `json-logic`, where a "forced value" will now be returned in each relevant field (i.e. fields where the schema `const` and `default` are the same) with `forcedValue` over `value`. ([#66](https://github.com/remoteoss/json-schema-form/pull/66)) ([77c445a9](https://github.com/remoteoss/json-schema-form/commit/77c445a9dce657a7648642312f22c18f972187c7))
|
|
6
|
+
|
|
1
7
|
#### 0.8.2-beta.0 (2024-02-13)
|
|
2
8
|
|
|
3
9
|
##### 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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.0-beta.0
|
|
5
|
+
Generated: Mon, 11 Mar 2024 14:55:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1381,7 +1381,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1381
1381
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1382
1382
|
const description = presentation?.description || node.description;
|
|
1383
1383
|
const statementDescription = presentation.statement?.description;
|
|
1384
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1384
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1385
1385
|
return (0, import_omitBy.default)(
|
|
1386
1386
|
{
|
|
1387
1387
|
const: node.const,
|
|
@@ -1477,9 +1477,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1477
1477
|
};
|
|
1478
1478
|
};
|
|
1479
1479
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1480
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1480
1481
|
return {
|
|
1481
1482
|
...computedAttributes ?? {},
|
|
1482
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1483
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1483
1484
|
};
|
|
1484
1485
|
}
|
|
1485
1486
|
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.0-beta.0
|
|
5
|
+
Generated: Mon, 11 Mar 2024 14:55:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1345,7 +1345,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1345
1345
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1346
1346
|
const description = presentation?.description || node.description;
|
|
1347
1347
|
const statementDescription = presentation.statement?.description;
|
|
1348
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1348
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1349
1349
|
return omitBy(
|
|
1350
1350
|
{
|
|
1351
1351
|
const: node.const,
|
|
@@ -1441,9 +1441,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1441
1441
|
};
|
|
1442
1442
|
};
|
|
1443
1443
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1444
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1444
1445
|
return {
|
|
1445
1446
|
...computedAttributes ?? {},
|
|
1446
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1447
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1447
1448
|
};
|
|
1448
1449
|
}
|
|
1449
1450
|
|
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.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.9.0-beta.0
|
|
5
|
+
Generated: Mon, 11 Mar 2024 14:55:00 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12699,7 +12699,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12699
12699
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12700
12700
|
const description = presentation?.description || node.description;
|
|
12701
12701
|
const statementDescription = presentation.statement?.description;
|
|
12702
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
12702
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
12703
12703
|
return (0, import_omitBy.default)(
|
|
12704
12704
|
{
|
|
12705
12705
|
const: node.const,
|
|
@@ -12795,9 +12795,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values2) => {
|
|
|
12795
12795
|
};
|
|
12796
12796
|
};
|
|
12797
12797
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
12798
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
12798
12799
|
return {
|
|
12799
12800
|
...computedAttributes ?? {},
|
|
12800
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
12801
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
12801
12802
|
};
|
|
12802
12803
|
}
|
|
12803
12804
|
|
package/package.json
CHANGED
package/src/tests/const.test.js
CHANGED
|
@@ -112,7 +112,7 @@ describe('validations: const', () => {
|
|
|
112
112
|
},
|
|
113
113
|
{ strictInputType: false }
|
|
114
114
|
);
|
|
115
|
-
expect(fields[0]).toMatchObject({
|
|
115
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -130,7 +130,7 @@ describe('const/default with forced values', () => {
|
|
|
130
130
|
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
131
131
|
zero_only: 'The only accepted value is 0.',
|
|
132
132
|
});
|
|
133
|
-
expect(fields[0]).toMatchObject({
|
|
133
|
+
expect(fields[0]).toMatchObject({ forcedValue: 0, const: 0, default: 0 });
|
|
134
134
|
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
135
135
|
// null is also considered valid until we fix @BUG RMT-518
|
|
136
136
|
// Expectation: To fail with error "The only accepted value is 0."
|
|
@@ -151,9 +151,45 @@ describe('const/default with forced values', () => {
|
|
|
151
151
|
ten_only: 'The only accepted value is 10.',
|
|
152
152
|
});
|
|
153
153
|
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
154
|
-
expect(fields[0]).toMatchObject({
|
|
154
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
155
155
|
// null is also considered valid until we fix @BUG RMT-518
|
|
156
156
|
// Expectation: To fail with error "The only accepted value is 10."
|
|
157
157
|
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
it('do not set a forced value if const and default do not equal', () => {
|
|
161
|
+
const { fields } = createHeadlessForm(
|
|
162
|
+
{
|
|
163
|
+
properties: {
|
|
164
|
+
bad_field_for_number: { type: 'number', const: 10, default: 20 },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{ strictInputType: false }
|
|
168
|
+
);
|
|
169
|
+
expect(fields[0]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('Should work numbers with non-standard input types', () => {
|
|
173
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
174
|
+
{
|
|
175
|
+
properties: {
|
|
176
|
+
number: {
|
|
177
|
+
type: 'integer',
|
|
178
|
+
const: 300,
|
|
179
|
+
default: 300,
|
|
180
|
+
'x-jsf-presentation': {
|
|
181
|
+
inputType: 'money',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
required: ['number'],
|
|
186
|
+
},
|
|
187
|
+
{ strictInputType: true }
|
|
188
|
+
);
|
|
189
|
+
expect(handleValidation({ number: 0 }).formErrors).toEqual({
|
|
190
|
+
number: 'The only accepted value is 300.',
|
|
191
|
+
});
|
|
192
|
+
expect(handleValidation({ number: 300 }).formErrors).toBeUndefined();
|
|
193
|
+
expect(fields[0]).toMatchObject({ forcedValue: 300 });
|
|
194
|
+
});
|
|
159
195
|
});
|
|
@@ -227,6 +227,35 @@ export const schemaWithComputedAttributes = {
|
|
|
227
227
|
},
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
export const badSchemaThatWillNotSetAForcedValue = {
|
|
231
|
+
properties: {
|
|
232
|
+
field_a: {
|
|
233
|
+
type: 'number',
|
|
234
|
+
},
|
|
235
|
+
field_b: {
|
|
236
|
+
type: 'number',
|
|
237
|
+
'x-jsf-logic-computedAttrs': {
|
|
238
|
+
const: 'a_times_three',
|
|
239
|
+
default: 'a_times_two',
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
'x-jsf-logic': {
|
|
244
|
+
computedValues: {
|
|
245
|
+
a_times_two: {
|
|
246
|
+
rule: {
|
|
247
|
+
'*': [{ var: 'field_a' }, 2],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
a_times_three: {
|
|
251
|
+
rule: {
|
|
252
|
+
'*': [{ var: 'field_a' }, 3],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
230
259
|
export const schemaWithInlineRuleForComputedAttributeWithoutCopy = {
|
|
231
260
|
properties: {
|
|
232
261
|
field_a: {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
schemaWithUnknownVariableInComputedValues,
|
|
36
36
|
schemaWithUnknownVariableInValidations,
|
|
37
37
|
schemaWithValidationThatDoesNotExistOnProperty,
|
|
38
|
+
badSchemaThatWillNotSetAForcedValue,
|
|
38
39
|
} from './jsonLogic.fixtures';
|
|
39
40
|
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
|
|
40
41
|
|
|
@@ -335,12 +336,21 @@ describe('jsonLogic: cross-values validations', () => {
|
|
|
335
336
|
'This field is 2 times bigger than field_a with value of 4.'
|
|
336
337
|
);
|
|
337
338
|
expect(fieldB.default).toEqual(4);
|
|
338
|
-
expect(fieldB.
|
|
339
|
+
expect(fieldB.forcedValue).toEqual(4);
|
|
339
340
|
handleValidation({ field_a: 4 });
|
|
340
341
|
expect(fieldB.default).toEqual(8);
|
|
341
342
|
expect(fieldB.label).toEqual('This is 8!');
|
|
342
343
|
});
|
|
343
344
|
|
|
345
|
+
it('A forced value will not be set when const and default are not equal', () => {
|
|
346
|
+
const { fields } = createHeadlessForm(badSchemaThatWillNotSetAForcedValue, {
|
|
347
|
+
strictInputType: false,
|
|
348
|
+
initialValues: { field_a: 2 },
|
|
349
|
+
});
|
|
350
|
+
expect(fields[1]).toMatchObject({ const: 6, default: 4 });
|
|
351
|
+
expect(fields[1]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
352
|
+
});
|
|
353
|
+
|
|
344
354
|
it('Derived errorMessages and statements work', () => {
|
|
345
355
|
const { fields, handleValidation } = createHeadlessForm(
|
|
346
356
|
schemaWithComputedAttributesAndErrorMessages,
|