@remoteoss/json-schema-form 0.11.9-dev.20241127210659 → 0.11.9-dev.20241213082826

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 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.9-dev.20241127210659
5
- Generated: Wed, 27 Nov 2024 21:07:13 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241213082826
5
+ Generated: Fri, 13 Dec 2024 08:29:06 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -98,6 +98,9 @@ function hasProperty(object2, propertyName) {
98
98
 
99
99
  // src/checkIfConditionMatches.js
100
100
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
101
+ if (typeof node.if === "boolean") {
102
+ return node.if;
103
+ }
101
104
  return Object.keys(node.if.properties ?? {}).every((name) => {
102
105
  const currentProperty = node.if.properties[name];
103
106
  const value = formValues[name];
@@ -1052,8 +1055,6 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
1052
1055
  subRule.map((item) => {
1053
1056
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
1054
1057
  if (isVar) {
1055
- if (Array.isArray(item.var))
1056
- return;
1057
1058
  const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
1058
1059
  if (exists === null) {
1059
1060
  throw Error(errorMessage(item));
@@ -1315,7 +1316,7 @@ function processNode({
1315
1316
  parentID
1316
1317
  });
1317
1318
  });
1318
- if (node.if) {
1319
+ if (node.if !== void 0) {
1319
1320
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
1320
1321
  if (matchesCondition && node.then) {
1321
1322
  const { required: branchRequired } = processNode({
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.9-dev.20241127210659
5
- Generated: Wed, 27 Nov 2024 21:07:13 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241213082826
5
+ Generated: Fri, 13 Dec 2024 08:29:06 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -61,6 +61,9 @@ function hasProperty(object2, propertyName) {
61
61
 
62
62
  // src/checkIfConditionMatches.js
63
63
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
64
+ if (typeof node.if === "boolean") {
65
+ return node.if;
66
+ }
64
67
  return Object.keys(node.if.properties ?? {}).every((name) => {
65
68
  const currentProperty = node.if.properties[name];
66
69
  const value = formValues[name];
@@ -1015,8 +1018,6 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
1015
1018
  subRule.map((item) => {
1016
1019
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
1017
1020
  if (isVar) {
1018
- if (Array.isArray(item.var))
1019
- return;
1020
1021
  const exists = jsonLogic.apply({ var: removeIndicesFromPath(item.var) }, data);
1021
1022
  if (exists === null) {
1022
1023
  throw Error(errorMessage(item));
@@ -1278,7 +1279,7 @@ function processNode({
1278
1279
  parentID
1279
1280
  });
1280
1281
  });
1281
- if (node.if) {
1282
+ if (node.if !== void 0) {
1282
1283
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
1283
1284
  if (matchesCondition && node.then) {
1284
1285
  const { required: branchRequired } = processNode({
@@ -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.9-dev.20241127210659
5
- Generated: Wed, 27 Nov 2024 21:07:13 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-dev.20241213082826
5
+ Generated: Fri, 13 Dec 2024 08:29:06 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11578,6 +11578,9 @@ function hasProperty(object2, propertyName) {
11578
11578
 
11579
11579
  // src/checkIfConditionMatches.js
11580
11580
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
11581
+ if (typeof node.if === "boolean") {
11582
+ return node.if;
11583
+ }
11581
11584
  return Object.keys(node.if.properties ?? {}).every((name) => {
11582
11585
  const currentProperty = node.if.properties[name];
11583
11586
  const value = formValues[name];
@@ -12531,8 +12534,6 @@ function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `[json-sche
12531
12534
  subRule.map((item) => {
12532
12535
  const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
12533
12536
  if (isVar) {
12534
- if (Array.isArray(item.var))
12535
- return;
12536
12537
  const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
12537
12538
  if (exists === null) {
12538
12539
  throw Error(errorMessage(item));
@@ -12794,7 +12795,7 @@ function processNode({
12794
12795
  parentID
12795
12796
  });
12796
12797
  });
12797
- if (node.if) {
12798
+ if (node.if !== void 0) {
12798
12799
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
12799
12800
  if (matchesCondition && node.then) {
12800
12801
  const { required: branchRequired } = processNode({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.9-dev.20241127210659",
3
+ "version": "0.11.9-dev.20241213082826",
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",
@@ -1,5 +1,13 @@
1
1
  import { checkIfConditionMatchesProperties } from '../checkIfConditionMatches';
2
2
 
3
+ it('True if is always going to be true', () => {
4
+ expect(checkIfConditionMatchesProperties({ if: true })).toBe(true);
5
+ });
6
+
7
+ it('False if is always going to be false', () => {
8
+ expect(checkIfConditionMatchesProperties({ if: false })).toBe(false);
9
+ });
10
+
3
11
  it('Empty if is always going to be true', () => {
4
12
  expect(checkIfConditionMatchesProperties({ if: { properties: {} } })).toBe(true);
5
13
  });
@@ -479,3 +479,71 @@ describe('Conditional with a minimum value check', () => {
479
479
  expect(handleValidation({ salary: 1000, reason: 'reason_one' }).formErrors).toEqual(undefined);
480
480
  });
481
481
  });
482
+
483
+ describe('Conditional with literal booleans', () => {
484
+ it('handles true case', () => {
485
+ const schema = {
486
+ properties: {
487
+ is_full_time: {
488
+ type: 'boolean',
489
+ },
490
+ salary: {
491
+ type: 'number',
492
+ },
493
+ },
494
+ required: [],
495
+ if: true,
496
+ then: {
497
+ required: ['is_full_time'],
498
+ },
499
+ else: {
500
+ required: ['salary'],
501
+ },
502
+ };
503
+ const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
504
+
505
+ handleValidation({});
506
+
507
+ expect(fields[0]).toMatchObject({
508
+ name: 'is_full_time',
509
+ required: true,
510
+ });
511
+ expect(fields[1]).toMatchObject({
512
+ name: 'salary',
513
+ required: false,
514
+ });
515
+ });
516
+
517
+ it('handles false case', () => {
518
+ const schema = {
519
+ properties: {
520
+ is_full_time: {
521
+ type: 'boolean',
522
+ },
523
+ salary: {
524
+ type: 'number',
525
+ },
526
+ },
527
+ required: [],
528
+ if: false,
529
+ then: {
530
+ required: ['is_full_time'],
531
+ },
532
+ else: {
533
+ required: ['salary'],
534
+ },
535
+ };
536
+ const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
537
+
538
+ handleValidation({});
539
+
540
+ expect(fields[0]).toMatchObject({
541
+ name: 'is_full_time',
542
+ required: false,
543
+ });
544
+ expect(fields[1]).toMatchObject({
545
+ name: 'salary',
546
+ required: true,
547
+ });
548
+ });
549
+ });
@@ -984,51 +984,3 @@ 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,7 +36,6 @@ import {
36
36
  schemaWithUnknownVariableInValidations,
37
37
  schemaWithValidationThatDoesNotExistOnProperty,
38
38
  badSchemaThatWillNotSetAForcedValue,
39
- schemaWithReduceAccumulator,
40
39
  } from './jsonLogic.fixtures';
41
40
  import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
42
41
 
@@ -245,22 +244,6 @@ describe('jsonLogic: cross-values validations', () => {
245
244
  });
246
245
  });
247
246
 
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
-
264
247
  describe('Logical: ||, &&', () => {
265
248
  it('AND: field_a > field_b && field_a > field_c (implicit with multiple rules in a single field)', () => {
266
249
  const schema = createSchemaWithThreePropertiesWithRuleOnFieldA({