@remoteoss/json-schema-form 0.8.0-beta.0 → 0.8.1-dev.20240209164254
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 +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 +15 -3
- package/src/tests/jsonLogic.fixtures.js +29 -0
- package/src/tests/jsonLogic.test.js +11 -1
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.8.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1383,7 +1383,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1383
1383
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1384
1384
|
const description = presentation?.description || node.description;
|
|
1385
1385
|
const statementDescription = presentation.statement?.description;
|
|
1386
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1386
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1387
1387
|
return (0, import_omitBy.default)(
|
|
1388
1388
|
{
|
|
1389
1389
|
const: node.const,
|
|
@@ -1479,9 +1479,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1479
1479
|
};
|
|
1480
1480
|
};
|
|
1481
1481
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1482
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1482
1483
|
return {
|
|
1483
1484
|
...computedAttributes ?? {},
|
|
1484
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1485
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1485
1486
|
};
|
|
1486
1487
|
}
|
|
1487
1488
|
|
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.8.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -1347,7 +1347,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1347
1347
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1348
1348
|
const description = presentation?.description || node.description;
|
|
1349
1349
|
const statementDescription = presentation.statement?.description;
|
|
1350
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1350
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1351
1351
|
return omitBy(
|
|
1352
1352
|
{
|
|
1353
1353
|
const: node.const,
|
|
@@ -1443,9 +1443,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1443
1443
|
};
|
|
1444
1444
|
};
|
|
1445
1445
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1446
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1446
1447
|
return {
|
|
1447
1448
|
...computedAttributes ?? {},
|
|
1448
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1449
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1449
1450
|
};
|
|
1450
1451
|
}
|
|
1451
1452
|
|
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.8.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -12701,7 +12701,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12701
12701
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12702
12702
|
const description = presentation?.description || node.description;
|
|
12703
12703
|
const statementDescription = presentation.statement?.description;
|
|
12704
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
12704
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
12705
12705
|
return (0, import_omitBy.default)(
|
|
12706
12706
|
{
|
|
12707
12707
|
const: node.const,
|
|
@@ -12797,9 +12797,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values2) => {
|
|
|
12797
12797
|
};
|
|
12798
12798
|
};
|
|
12799
12799
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
12800
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
12800
12801
|
return {
|
|
12801
12802
|
...computedAttributes ?? {},
|
|
12802
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
12803
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
12803
12804
|
};
|
|
12804
12805
|
}
|
|
12805
12806
|
|
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,21 @@ 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
|
+
});
|
|
159
171
|
});
|
|
@@ -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,
|