@remoteoss/json-schema-form 0.11.8-beta.0 → 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/dist/index.cjs +4 -2
- package/dist/index.js +4 -2
- package/dist/standalone.js +4 -2
- package/package.json +1 -1
- package/src/tests/jsonLogic.fixtures.js +48 -0
- package/src/tests/jsonLogic.test.js +17 -0
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.
|
|
5
|
-
Generated: Wed,
|
|
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
|
|
|
@@ -1052,6 +1052,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
|
|
|
1052
1052
|
subRule.map((item) => {
|
|
1053
1053
|
const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
|
|
1054
1054
|
if (isVar) {
|
|
1055
|
+
if (Array.isArray(item.var))
|
|
1056
|
+
return;
|
|
1055
1057
|
const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
|
|
1056
1058
|
if (exists === null) {
|
|
1057
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.
|
|
5
|
-
Generated: Wed,
|
|
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
|
|
|
@@ -1015,6 +1015,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
|
|
|
1015
1015
|
subRule.map((item) => {
|
|
1016
1016
|
const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
|
|
1017
1017
|
if (isVar) {
|
|
1018
|
+
if (Array.isArray(item.var))
|
|
1019
|
+
return;
|
|
1018
1020
|
const exists = jsonLogic.apply({ var: removeIndicesFromPath(item.var) }, data);
|
|
1019
1021
|
if (exists === null) {
|
|
1020
1022
|
throw Error(errorMessage(item));
|
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.11.
|
|
5
|
-
Generated: Wed,
|
|
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
|
|
|
@@ -12531,6 +12531,8 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
|
|
|
12531
12531
|
subRule.map((item) => {
|
|
12532
12532
|
const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
|
|
12533
12533
|
if (isVar) {
|
|
12534
|
+
if (Array.isArray(item.var))
|
|
12535
|
+
return;
|
|
12534
12536
|
const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
|
|
12535
12537
|
if (exists === null) {
|
|
12536
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.
|
|
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",
|
|
@@ -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({
|