@remoteoss/json-schema-form 0.6.1-beta.0 → 0.6.4-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 +8 -0
- package/dist/index.cjs +8 -4
- package/dist/index.js +8 -4
- package/dist/standalone.js +8 -4
- package/package.json +1 -1
- package/src/tests/jsonLogic.fixtures.js +112 -0
- package/src/tests/jsonLogic.test.js +72 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
#### 0.6.4-beta.0 (2023-09-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
##### Changes
|
|
6
|
+
|
|
7
|
+
* 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))
|
|
8
|
+
|
|
1
9
|
#### 0.6.1-beta.0 (2023-09-13)
|
|
2
10
|
|
|
3
11
|
##### Changes
|
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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.6.4-beta.0
|
|
5
|
+
Generated: Fri, 15 Sep 2023 12:36:13 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -527,7 +527,7 @@ function replaceHandlebarsTemplates({
|
|
|
527
527
|
throw Error("Cannot define multiple rules without a template string with key `value`.");
|
|
528
528
|
}
|
|
529
529
|
const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
|
|
530
|
-
const computedValue = logic.getScope(parentID).
|
|
530
|
+
const computedValue = logic.getScope(parentID).validate(rule, formValues);
|
|
531
531
|
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
532
532
|
}, value);
|
|
533
533
|
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
@@ -577,8 +577,12 @@ function handleComputedAttribute(logic, formValues, parentID, name) {
|
|
|
577
577
|
];
|
|
578
578
|
}
|
|
579
579
|
case "const":
|
|
580
|
-
default:
|
|
580
|
+
default: {
|
|
581
|
+
if (typeof value === "object" && value.rule) {
|
|
582
|
+
return [key, logic.getScope(parentID).validate(value.rule, formValues)];
|
|
583
|
+
}
|
|
581
584
|
return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues, name)];
|
|
585
|
+
}
|
|
582
586
|
}
|
|
583
587
|
};
|
|
584
588
|
}
|
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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.6.4-beta.0
|
|
5
|
+
Generated: Fri, 15 Sep 2023 12:36:13 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -491,7 +491,7 @@ function replaceHandlebarsTemplates({
|
|
|
491
491
|
throw Error("Cannot define multiple rules without a template string with key `value`.");
|
|
492
492
|
}
|
|
493
493
|
const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
|
|
494
|
-
const computedValue = logic.getScope(parentID).
|
|
494
|
+
const computedValue = logic.getScope(parentID).validate(rule, formValues);
|
|
495
495
|
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
496
496
|
}, value);
|
|
497
497
|
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
@@ -541,8 +541,12 @@ function handleComputedAttribute(logic, formValues, parentID, name) {
|
|
|
541
541
|
];
|
|
542
542
|
}
|
|
543
543
|
case "const":
|
|
544
|
-
default:
|
|
544
|
+
default: {
|
|
545
|
+
if (typeof value === "object" && value.rule) {
|
|
546
|
+
return [key, logic.getScope(parentID).validate(value.rule, formValues)];
|
|
547
|
+
}
|
|
545
548
|
return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues, name)];
|
|
549
|
+
}
|
|
546
550
|
}
|
|
547
551
|
};
|
|
548
552
|
}
|
package/dist/standalone.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
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.6.4-beta.0
|
|
5
|
+
Generated: Fri, 15 Sep 2023 12:36:13 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11845,7 +11845,7 @@ function replaceHandlebarsTemplates({
|
|
|
11845
11845
|
throw Error("Cannot define multiple rules without a template string with key `value`.");
|
|
11846
11846
|
}
|
|
11847
11847
|
const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
|
|
11848
|
-
const computedValue = logic.getScope(parentID).
|
|
11848
|
+
const computedValue = logic.getScope(parentID).validate(rule, formValues);
|
|
11849
11849
|
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
11850
11850
|
}, value);
|
|
11851
11851
|
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
@@ -11895,8 +11895,12 @@ function handleComputedAttribute(logic, formValues, parentID, name) {
|
|
|
11895
11895
|
];
|
|
11896
11896
|
}
|
|
11897
11897
|
case "const":
|
|
11898
|
-
default:
|
|
11898
|
+
default: {
|
|
11899
|
+
if (typeof value === "object" && value.rule) {
|
|
11900
|
+
return [key, logic.getScope(parentID).validate(value.rule, formValues)];
|
|
11901
|
+
}
|
|
11899
11902
|
return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues, name)];
|
|
11903
|
+
}
|
|
11900
11904
|
}
|
|
11901
11905
|
};
|
|
11902
11906
|
}
|
package/package.json
CHANGED
|
@@ -439,3 +439,115 @@ export const schemaWithBadOperation = {
|
|
|
439
439
|
},
|
|
440
440
|
},
|
|
441
441
|
};
|
|
442
|
+
|
|
443
|
+
export const schemaWithInlineRuleForComputedAttributeWithCopy = {
|
|
444
|
+
properties: {
|
|
445
|
+
field_a: {
|
|
446
|
+
type: 'number',
|
|
447
|
+
},
|
|
448
|
+
field_b: {
|
|
449
|
+
type: 'number',
|
|
450
|
+
'x-jsf-logic-computedAttrs': {
|
|
451
|
+
title: {
|
|
452
|
+
value: 'I need this to work using the {{rule}}.',
|
|
453
|
+
rule: {
|
|
454
|
+
'+': [{ var: 'field_a' }, 10],
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
export const schemaWithInlineMultipleRulesForComputedAttributes = {
|
|
463
|
+
properties: {
|
|
464
|
+
field_a: {
|
|
465
|
+
type: 'number',
|
|
466
|
+
},
|
|
467
|
+
field_b: {
|
|
468
|
+
type: 'number',
|
|
469
|
+
'x-jsf-logic-computedAttrs': {
|
|
470
|
+
description: {
|
|
471
|
+
value: 'Must be between {{half_a}} and {{double_a}}.',
|
|
472
|
+
half_a: {
|
|
473
|
+
'/': [{ var: 'field_a' }, 2],
|
|
474
|
+
},
|
|
475
|
+
double_a: {
|
|
476
|
+
'*': [{ var: 'field_a' }, 2],
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
export const schemaInlineComputedAttrForTitle = {
|
|
485
|
+
properties: {
|
|
486
|
+
field_a: {
|
|
487
|
+
type: 'number',
|
|
488
|
+
},
|
|
489
|
+
field_b: {
|
|
490
|
+
type: 'number',
|
|
491
|
+
'x-jsf-logic-computedAttrs': {
|
|
492
|
+
title: {
|
|
493
|
+
value: '{{rule}}',
|
|
494
|
+
rule: {
|
|
495
|
+
'+': [{ var: 'field_a' }, 10],
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export const schemaInlineComputedAttrForMaximumMinimumValues = {
|
|
504
|
+
properties: {
|
|
505
|
+
field_a: {
|
|
506
|
+
type: 'number',
|
|
507
|
+
default: 0,
|
|
508
|
+
},
|
|
509
|
+
field_b: {
|
|
510
|
+
type: 'number',
|
|
511
|
+
'x-jsf-logic-computedAttrs': {
|
|
512
|
+
maximum: {
|
|
513
|
+
rule: {
|
|
514
|
+
'+': [{ var: 'field_a' }, 10],
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
minimum: {
|
|
518
|
+
rule: {
|
|
519
|
+
'-': [{ var: 'field_a' }, 10],
|
|
520
|
+
},
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
export const schemaWithJSFLogicAndInlineRule = {
|
|
528
|
+
properties: {
|
|
529
|
+
field_a: {
|
|
530
|
+
type: 'number',
|
|
531
|
+
},
|
|
532
|
+
field_b: {
|
|
533
|
+
type: 'number',
|
|
534
|
+
'x-jsf-logic-computedAttrs': {
|
|
535
|
+
title: {
|
|
536
|
+
value: 'Going to use {{rule}} and {{not_inline}}',
|
|
537
|
+
rule: {
|
|
538
|
+
'+': [{ var: 'field_a' }, 10],
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
'x-jsf-logic': {
|
|
545
|
+
computedValues: {
|
|
546
|
+
not_inline: {
|
|
547
|
+
rule: {
|
|
548
|
+
'+': [1, 3],
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
};
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
createSchemaWithRulesOnFieldA,
|
|
5
5
|
createSchemaWithThreePropertiesWithRuleOnFieldA,
|
|
6
6
|
multiRuleSchema,
|
|
7
|
+
schemaInlineComputedAttrForMaximumMinimumValues,
|
|
8
|
+
schemaInlineComputedAttrForTitle,
|
|
7
9
|
schemaWithBadOperation,
|
|
8
10
|
schemaWithComputedAttributeThatDoesntExist,
|
|
9
11
|
schemaWithComputedAttributeThatDoesntExistDescription,
|
|
@@ -12,7 +14,10 @@ import {
|
|
|
12
14
|
schemaWithComputedAttributesAndErrorMessages,
|
|
13
15
|
schemaWithDeepVarThatDoesNotExist,
|
|
14
16
|
schemaWithDeepVarThatDoesNotExistOnFieldset,
|
|
17
|
+
schemaWithInlineMultipleRulesForComputedAttributes,
|
|
18
|
+
schemaWithInlineRuleForComputedAttributeWithCopy,
|
|
15
19
|
schemaWithInlinedRuleOnComputedAttributeThatReferencesUnknownVar,
|
|
20
|
+
schemaWithJSFLogicAndInlineRule,
|
|
16
21
|
schemaWithMissingComputedValue,
|
|
17
22
|
schemaWithMissingRule,
|
|
18
23
|
schemaWithNativeAndJSONLogicChecks,
|
|
@@ -344,5 +349,72 @@ describe('jsonLogic: cross-values validations', () => {
|
|
|
344
349
|
expect(fieldB.maximum).toEqual(8);
|
|
345
350
|
expect(fieldB.statement).toEqual({ description: 'Must be bigger than 4 and smaller than 8' });
|
|
346
351
|
});
|
|
352
|
+
|
|
353
|
+
it('Use a inline-rule in a schema for a title attribute', () => {
|
|
354
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
355
|
+
schemaWithInlineRuleForComputedAttributeWithCopy,
|
|
356
|
+
{
|
|
357
|
+
strictInputType: false,
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
const [, fieldB] = fields;
|
|
361
|
+
expect(handleValidation({ field_a: 0, field_b: null }).formErrors).toEqual(undefined);
|
|
362
|
+
expect(fieldB.label).toEqual('I need this to work using the 10.');
|
|
363
|
+
expect(handleValidation({ field_a: 10 }).formErrors).toEqual(undefined);
|
|
364
|
+
expect(fieldB.label).toEqual('I need this to work using the 20.');
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('Use multiple inline rules with different identifiers', () => {
|
|
369
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
370
|
+
schemaWithInlineMultipleRulesForComputedAttributes,
|
|
371
|
+
{
|
|
372
|
+
strictInputType: false,
|
|
373
|
+
}
|
|
374
|
+
);
|
|
375
|
+
const [, fieldB] = fields;
|
|
376
|
+
expect(handleValidation({ field_a: 10, field_b: null }).formErrors).toEqual(undefined);
|
|
377
|
+
expect(fieldB.description).toEqual('Must be between 5 and 20.');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it('Use an inline rule in a schema for a title but it just uses the value', () => {
|
|
381
|
+
const { fields, handleValidation } = createHeadlessForm(schemaInlineComputedAttrForTitle, {
|
|
382
|
+
strictInputType: false,
|
|
383
|
+
});
|
|
384
|
+
const [, fieldB] = fields;
|
|
385
|
+
expect(handleValidation({ field_a: 10, field_b: null }).formErrors).toEqual(undefined);
|
|
386
|
+
expect(fieldB.label).toEqual('20');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('Use an inline rule for a minimum, maximum value', () => {
|
|
390
|
+
const { fields, handleValidation } = createHeadlessForm(
|
|
391
|
+
schemaInlineComputedAttrForMaximumMinimumValues,
|
|
392
|
+
{
|
|
393
|
+
strictInputType: false,
|
|
394
|
+
}
|
|
395
|
+
);
|
|
396
|
+
const [, fieldB] = fields;
|
|
397
|
+
expect(fieldB).toMatchObject({ minimum: -10, maximum: 10 });
|
|
398
|
+
expect(handleValidation({ field_a: 10, field_b: null }).formErrors).toBeUndefined();
|
|
399
|
+
expect(fieldB).toMatchObject({ minimum: 0, maximum: 20 });
|
|
400
|
+
expect(handleValidation({ field_a: 50, field_b: 20 }).formErrors).toEqual({
|
|
401
|
+
field_b: 'Must be greater or equal to 40',
|
|
402
|
+
});
|
|
403
|
+
expect(fieldB).toMatchObject({ minimum: 40, maximum: 60 });
|
|
404
|
+
expect(handleValidation({ field_a: 50, field_b: 70 }).formErrors).toEqual({
|
|
405
|
+
field_b: 'Must be smaller or equal to 60',
|
|
406
|
+
});
|
|
407
|
+
expect(fieldB).toMatchObject({ minimum: 40, maximum: 60 });
|
|
408
|
+
expect(handleValidation({ field_a: 50, field_b: 50 }).formErrors).toBeUndefined();
|
|
409
|
+
expect(fieldB).toMatchObject({ minimum: 40, maximum: 60 });
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('Mix use of multiple inline rules and an external rule', () => {
|
|
413
|
+
const { fields, handleValidation } = createHeadlessForm(schemaWithJSFLogicAndInlineRule, {
|
|
414
|
+
strictInputType: false,
|
|
415
|
+
});
|
|
416
|
+
handleValidation({ field_a: 10 });
|
|
417
|
+
const [, fieldB] = fields;
|
|
418
|
+
expect(fieldB.label).toEqual('Going to use 20 and 4');
|
|
347
419
|
});
|
|
348
420
|
});
|