@remoteoss/json-schema-form 0.4.3-beta.0 → 0.4.4-dev.20230829101351

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.
@@ -0,0 +1,1489 @@
1
+ export function createSchemaWithRulesOnFieldA(rules) {
2
+ return {
3
+ properties: {
4
+ field_a: {
5
+ type: 'number',
6
+ 'x-jsf-logic-validations': Object.keys(rules),
7
+ },
8
+ field_b: {
9
+ type: 'number',
10
+ },
11
+ },
12
+ required: ['field_a', 'field_b'],
13
+ 'x-jsf-logic': { validations: rules },
14
+ };
15
+ }
16
+
17
+ export function createSchemaWithThreePropertiesWithRuleOnFieldA(rules) {
18
+ return {
19
+ properties: {
20
+ field_a: {
21
+ type: 'number',
22
+ 'x-jsf-logic-validations': Object.keys(rules),
23
+ },
24
+ field_b: {
25
+ type: 'number',
26
+ },
27
+ field_c: {
28
+ type: 'number',
29
+ },
30
+ },
31
+ 'x-jsf-logic': { validations: rules },
32
+ required: ['field_a', 'field_b', 'field_c'],
33
+ };
34
+ }
35
+
36
+ export const schemaWithNonRequiredField = {
37
+ properties: {
38
+ field_a: {
39
+ type: 'number',
40
+ 'x-jsf-logic-validations': ['a_greater_than_ten'],
41
+ },
42
+ },
43
+ 'x-jsf-logic': {
44
+ validations: {
45
+ a_greater_than_ten: {
46
+ errorMessage: 'Must be greater than 10',
47
+ rule: {
48
+ '>': [{ var: 'field_a' }, 10],
49
+ },
50
+ },
51
+ },
52
+ },
53
+ required: [],
54
+ };
55
+
56
+ export const schemaWithNativeAndJSONLogicChecks = {
57
+ properties: {
58
+ field_a: {
59
+ type: 'number',
60
+ minimum: 5,
61
+ 'x-jsf-logic-validations': ['a_greater_than_ten'],
62
+ },
63
+ },
64
+ 'x-jsf-logic': {
65
+ validations: {
66
+ a_greater_than_ten: {
67
+ errorMessage: 'Must be greater than 10',
68
+ rule: {
69
+ '>': [{ var: 'field_a' }, 10],
70
+ },
71
+ },
72
+ },
73
+ },
74
+ required: ['field_a'],
75
+ };
76
+
77
+ export const schemaWithMissingRule = {
78
+ properties: {
79
+ field_a: {
80
+ type: 'number',
81
+ 'x-jsf-logic-validations': ['a_greater_than_ten'],
82
+ },
83
+ },
84
+ 'x-jsf-logic': {
85
+ validations: {
86
+ a_greater_than_ten: {
87
+ errorMessage: 'Must be greater than 10',
88
+ },
89
+ },
90
+ },
91
+ required: [],
92
+ };
93
+
94
+ export const schemaWithMissingComputedValue = {
95
+ properties: {
96
+ field_a: {
97
+ type: 'number',
98
+ 'x-jsf-logic-computedAttrs': {
99
+ title: '{{a_plus_ten}}',
100
+ },
101
+ },
102
+ },
103
+ 'x-jsf-logic': {
104
+ computedValues: {
105
+ a_plus_ten: {},
106
+ },
107
+ },
108
+ required: [],
109
+ };
110
+
111
+ export const schemaWithMissingValueInlineRule = {
112
+ properties: {
113
+ field_a: {
114
+ type: 'number',
115
+ 'x-jsf-logic-computedAttrs': {
116
+ title: {
117
+ ruleOne: {
118
+ '+': [1, 2],
119
+ },
120
+ ruleTwo: {
121
+ '+': [3, 4],
122
+ },
123
+ },
124
+ },
125
+ },
126
+ },
127
+ required: [],
128
+ };
129
+
130
+ export const schemaWithVarThatDoesNotExist = {
131
+ properties: {
132
+ field_a: {
133
+ type: 'number',
134
+ },
135
+ },
136
+ 'x-jsf-logic': {
137
+ validations: {
138
+ a_greater_than_ten: {
139
+ errorMessage: 'Must be greater than 10',
140
+ rule: {
141
+ '>': [{ var: 'field_b' }, 10],
142
+ },
143
+ },
144
+ },
145
+ },
146
+ required: [],
147
+ };
148
+
149
+ export const schemaWithDeepVarThatDoesNotExist = {
150
+ properties: {
151
+ field_a: {
152
+ type: 'number',
153
+ },
154
+ },
155
+ 'x-jsf-logic': {
156
+ validations: {
157
+ a_greater_than_ten: {
158
+ errorMessage: 'Must be greater than 10',
159
+ rule: {
160
+ '>': [{ var: 'field_a' }, { '*': [2, { '/': [2, { '*': [1, { var: 'field_b' }] }] }] }],
161
+ },
162
+ },
163
+ },
164
+ },
165
+ required: [],
166
+ };
167
+
168
+ export const schemaWithDeepVarThatDoesNotExistOnFieldset = {
169
+ properties: {
170
+ field_a: {
171
+ type: 'object',
172
+ properties: {
173
+ child: {
174
+ type: 'number',
175
+ },
176
+ },
177
+ 'x-jsf-logic': {
178
+ validations: {
179
+ a_greater_than_ten: {
180
+ errorMessage: 'Must be greater than 10',
181
+ rule: {
182
+ '>': [{ var: 'child' }, { '*': [2, { '/': [2, { '*': [1, { var: 'field_a' }] }] }] }],
183
+ },
184
+ },
185
+ },
186
+ },
187
+ },
188
+ },
189
+ required: [],
190
+ };
191
+
192
+ export const schemaWithValidationThatDoesNotExistOnProperty = {
193
+ properties: {
194
+ field_a: {
195
+ type: 'number',
196
+ 'x-jsf-logic-validations': ['iDontExist'],
197
+ },
198
+ },
199
+ };
200
+
201
+ export const schemaWithComputedAttributeThatDoesntExist = {
202
+ properties: {
203
+ field_a: {
204
+ type: 'number',
205
+ 'x-jsf-logic-computedAttrs': {
206
+ default: 'iDontExist',
207
+ },
208
+ },
209
+ },
210
+ };
211
+
212
+ export const schemaWithInlinedRuleOnComputedAttributeThatReferencesUnknownVar = {
213
+ properties: {
214
+ field_a: {
215
+ type: 'number',
216
+ 'x-jsf-logic-computedAttrs': {
217
+ title: {
218
+ rule: {
219
+ '+': [{ var: 'IdontExist' }],
220
+ },
221
+ },
222
+ },
223
+ },
224
+ },
225
+ };
226
+
227
+ export const schemaWithComputedAttributeThatDoesntExistTitle = {
228
+ properties: {
229
+ field_a: {
230
+ type: 'number',
231
+ 'x-jsf-logic-computedAttrs': {
232
+ title: `this doesn't exist {{iDontExist}}`,
233
+ },
234
+ },
235
+ },
236
+ };
237
+
238
+ export const schemaWithComputedAttributeThatDoesntExistDescription = {
239
+ properties: {
240
+ field_a: {
241
+ type: 'number',
242
+ 'x-jsf-logic-computedAttrs': {
243
+ description: `this doesn't exist {{iDontExist}}`,
244
+ },
245
+ },
246
+ },
247
+ };
248
+
249
+ export const ifConditionWithMissingComputedValue = {
250
+ properties: {
251
+ field_a: {
252
+ type: 'number',
253
+ },
254
+ },
255
+ 'x-jsf-logic': {
256
+ allOf: [
257
+ {
258
+ if: {
259
+ computedValues: {
260
+ iDontExist: {
261
+ const: 10,
262
+ },
263
+ },
264
+ },
265
+ },
266
+ ],
267
+ },
268
+ };
269
+
270
+ export const ifConditionWithMissingValidation = {
271
+ properties: {
272
+ field_a: {
273
+ type: 'number',
274
+ },
275
+ },
276
+ 'x-jsf-logic': {
277
+ allOf: [
278
+ {
279
+ if: {
280
+ validations: {
281
+ iDontExist: {
282
+ const: true,
283
+ },
284
+ },
285
+ },
286
+ },
287
+ ],
288
+ },
289
+ };
290
+
291
+ export const schemaWithGreaterThanChecksForThreeFields = {
292
+ properties: {
293
+ field_a: {
294
+ type: 'number',
295
+ },
296
+ field_b: {
297
+ type: 'number',
298
+ },
299
+ field_c: {
300
+ type: 'number',
301
+ },
302
+ },
303
+ required: ['field_a', 'field_b'],
304
+ 'x-jsf-logic': {
305
+ validations: {
306
+ require_c: {
307
+ rule: {
308
+ and: [
309
+ { '!==': [{ var: 'field_b' }, null] },
310
+ { '!==': [{ var: 'field_a' }, null] },
311
+ { '>': [{ var: 'field_a' }, { var: 'field_b' }] },
312
+ ],
313
+ },
314
+ },
315
+ },
316
+ allOf: [
317
+ {
318
+ if: {
319
+ validations: {
320
+ require_c: {
321
+ const: true,
322
+ },
323
+ },
324
+ },
325
+ then: {
326
+ required: ['field_c'],
327
+ },
328
+ else: {
329
+ properties: {
330
+ field_c: false,
331
+ },
332
+ },
333
+ },
334
+ ],
335
+ },
336
+ };
337
+
338
+ export const schemaWithPropertiesCheckAndValidationsInAIf = {
339
+ properties: {
340
+ field_a: {
341
+ type: 'number',
342
+ },
343
+ field_b: {
344
+ type: 'number',
345
+ },
346
+ field_c: {
347
+ type: 'number',
348
+ },
349
+ },
350
+ required: ['field_a', 'field_b'],
351
+ 'x-jsf-logic': {
352
+ validations: {
353
+ require_c: {
354
+ rule: {
355
+ and: [
356
+ { '!==': [{ var: 'field_b' }, null] },
357
+ { '!==': [{ var: 'field_a' }, null] },
358
+ { '>': [{ var: 'field_a' }, { var: 'field_b' }] },
359
+ ],
360
+ },
361
+ },
362
+ },
363
+ allOf: [
364
+ {
365
+ if: {
366
+ validations: {
367
+ require_c: {
368
+ const: true,
369
+ },
370
+ },
371
+ properties: {
372
+ field_a: {
373
+ const: 10,
374
+ },
375
+ },
376
+ },
377
+ then: {
378
+ required: ['field_c'],
379
+ },
380
+ else: {
381
+ properties: {
382
+ field_c: false,
383
+ },
384
+ },
385
+ },
386
+ ],
387
+ },
388
+ };
389
+
390
+ export const schemaWithChecksAndThenValidationsOnThen = {
391
+ properties: {
392
+ field_a: {
393
+ type: 'number',
394
+ },
395
+ field_b: {
396
+ type: 'number',
397
+ },
398
+ field_c: {
399
+ type: 'number',
400
+ },
401
+ },
402
+ required: ['field_a', 'field_b'],
403
+ 'x-jsf-logic': {
404
+ validations: {
405
+ c_must_be_large: {
406
+ errorMessage: 'Needs more numbers',
407
+ rule: {
408
+ '>': [{ var: 'field_c' }, 200],
409
+ },
410
+ },
411
+ require_c: {
412
+ rule: {
413
+ and: [
414
+ { '!==': [{ var: 'field_b' }, null] },
415
+ { '!==': [{ var: 'field_a' }, null] },
416
+ { '>': [{ var: 'field_a' }, { var: 'field_b' }] },
417
+ ],
418
+ },
419
+ },
420
+ },
421
+ allOf: [
422
+ {
423
+ if: {
424
+ validations: {
425
+ require_c: {
426
+ const: true,
427
+ },
428
+ },
429
+ },
430
+ then: {
431
+ required: ['field_c'],
432
+ properties: {
433
+ field_c: {
434
+ description: 'I am a description!',
435
+ 'x-jsf-logic-validations': ['c_must_be_large'],
436
+ },
437
+ },
438
+ },
439
+ else: {
440
+ properties: {
441
+ field_c: false,
442
+ },
443
+ },
444
+ },
445
+ ],
446
+ },
447
+ };
448
+
449
+ export const schemaWithComputedValueChecksInIf = {
450
+ properties: {
451
+ field_a: {
452
+ type: 'number',
453
+ },
454
+ field_b: {
455
+ type: 'number',
456
+ },
457
+ field_c: {
458
+ type: 'number',
459
+ },
460
+ },
461
+ required: ['field_a', 'field_b'],
462
+ 'x-jsf-logic': {
463
+ computedValues: {
464
+ require_c: {
465
+ rule: {
466
+ and: [
467
+ { '!==': [{ var: 'field_b' }, null] },
468
+ { '!==': [{ var: 'field_a' }, null] },
469
+ { '>': [{ var: 'field_a' }, { var: 'field_b' }] },
470
+ ],
471
+ },
472
+ },
473
+ },
474
+ allOf: [
475
+ {
476
+ if: {
477
+ computedValues: {
478
+ require_c: {
479
+ const: true,
480
+ },
481
+ },
482
+ },
483
+ then: {
484
+ required: ['field_c'],
485
+ },
486
+ else: {
487
+ properties: {
488
+ field_c: false,
489
+ },
490
+ },
491
+ },
492
+ ],
493
+ },
494
+ };
495
+
496
+ export const schemaWithMultipleComputedValueChecks = {
497
+ properties: {
498
+ field_a: {
499
+ type: 'number',
500
+ },
501
+ field_b: {
502
+ type: 'number',
503
+ },
504
+ field_c: {
505
+ type: 'number',
506
+ },
507
+ },
508
+ required: ['field_a', 'field_b'],
509
+ 'x-jsf-logic': {
510
+ validations: {
511
+ double_b: {
512
+ errorMessage: 'Must be two times B',
513
+ rule: {
514
+ '>': [{ var: 'field_c' }, { '*': [{ var: 'field_b' }, 2] }],
515
+ },
516
+ },
517
+ },
518
+ computedValues: {
519
+ a_times_two: {
520
+ rule: {
521
+ '*': [{ var: 'field_a' }, 2],
522
+ },
523
+ },
524
+ mod_by_five: {
525
+ rule: {
526
+ '%': [{ var: 'field_b' }, 5],
527
+ },
528
+ },
529
+ },
530
+ allOf: [
531
+ {
532
+ if: {
533
+ computedValues: {
534
+ a_times_two: {
535
+ const: 20,
536
+ },
537
+ mod_by_five: {
538
+ const: 3,
539
+ },
540
+ },
541
+ },
542
+ then: {
543
+ required: ['field_c'],
544
+ properties: {
545
+ field_c: {
546
+ 'x-jsf-logic-validations': ['double_b'],
547
+ title: 'Adding a title.',
548
+ },
549
+ },
550
+ },
551
+ else: {
552
+ properties: {
553
+ field_c: false,
554
+ },
555
+ },
556
+ },
557
+ ],
558
+ },
559
+ };
560
+
561
+ export const schemaWithIfStatementWithComputedValuesAndValidationChecks = {
562
+ properties: {
563
+ field_a: {
564
+ type: 'number',
565
+ },
566
+ field_b: {
567
+ type: 'number',
568
+ },
569
+ field_c: {
570
+ type: 'number',
571
+ },
572
+ },
573
+ required: ['field_a', 'field_b'],
574
+ 'x-jsf-logic': {
575
+ validations: {
576
+ greater_than_b: {
577
+ rule: {
578
+ '>': [{ var: 'field_a' }, { var: 'field_b' }],
579
+ },
580
+ },
581
+ },
582
+ computedValues: {
583
+ a_times_two: {
584
+ rule: {
585
+ '*': [{ var: 'field_a' }, 2],
586
+ },
587
+ },
588
+ },
589
+ allOf: [
590
+ {
591
+ if: {
592
+ computedValues: {
593
+ a_times_two: {
594
+ const: 20,
595
+ },
596
+ },
597
+ validations: {
598
+ greater_than_b: {
599
+ const: true,
600
+ },
601
+ },
602
+ },
603
+ then: {
604
+ required: ['field_c'],
605
+ },
606
+ else: {
607
+ properties: {
608
+ field_c: false,
609
+ },
610
+ },
611
+ },
612
+ ],
613
+ },
614
+ };
615
+
616
+ export const schemaWhereValidationAndComputedValueIsAppliedOnNormalThenStatement = {
617
+ properties: {
618
+ field_a: {
619
+ type: 'number',
620
+ },
621
+ field_b: {
622
+ type: 'number',
623
+ },
624
+ },
625
+ 'x-jsf-logic': {
626
+ computedValues: {
627
+ a_plus_ten: {
628
+ rule: {
629
+ '+': [{ var: 'field_a' }, 10],
630
+ },
631
+ },
632
+ },
633
+ validations: {
634
+ greater_than_a_plus_ten: {
635
+ errorMessage: 'Must be greater than Field A + 10',
636
+ rule: {
637
+ '>': [{ var: 'field_b' }, { '+': [{ var: 'field_a' }, 10] }],
638
+ },
639
+ },
640
+ },
641
+ },
642
+ allOf: [
643
+ {
644
+ if: {
645
+ properties: {
646
+ field_a: {
647
+ const: 20,
648
+ },
649
+ },
650
+ },
651
+ then: {
652
+ properties: {
653
+ field_b: {
654
+ 'x-jsf-logic-computedAttrs': {
655
+ title: 'Must be greater than {{a_plus_ten}}.',
656
+ },
657
+ 'x-jsf-logic-validations': ['greater_than_a_plus_ten'],
658
+ },
659
+ },
660
+ },
661
+ },
662
+ ],
663
+ };
664
+
665
+ export const schemaWithTwoValidationsWhereOneOfThemIsAppliedConditionally = {
666
+ required: ['field_a', 'field_b'],
667
+ properties: {
668
+ field_a: {
669
+ type: 'number',
670
+ },
671
+ field_b: {
672
+ type: 'number',
673
+ 'x-jsf-logic-validations': ['greater_than_field_a'],
674
+ },
675
+ },
676
+ 'x-jsf-logic': {
677
+ validations: {
678
+ greater_than_field_a: {
679
+ errorMessage: 'Must be greater than A',
680
+ rule: {
681
+ '>': [{ var: 'field_b' }, { var: 'field_a' }],
682
+ },
683
+ },
684
+ greater_than_two_times_a: {
685
+ errorMessage: 'Must be greater than two times A',
686
+ rule: {
687
+ '>': [{ var: 'field_b' }, { '*': [{ var: 'field_a' }, 2] }],
688
+ },
689
+ },
690
+ },
691
+ },
692
+ allOf: [
693
+ {
694
+ if: {
695
+ properties: {
696
+ field_a: {
697
+ const: 20,
698
+ },
699
+ },
700
+ },
701
+ then: {
702
+ properties: {
703
+ field_b: {
704
+ 'x-jsf-logic-validations': ['greater_than_two_times_a'],
705
+ },
706
+ },
707
+ },
708
+ },
709
+ ],
710
+ };
711
+
712
+ export const multiRuleSchema = {
713
+ properties: {
714
+ field_a: {
715
+ type: 'number',
716
+ 'x-jsf-logic-validations': ['a_bigger_than_b', 'is_even_number'],
717
+ },
718
+ field_b: {
719
+ type: 'number',
720
+ },
721
+ },
722
+ required: ['field_a', 'field_b'],
723
+ 'x-jsf-logic': {
724
+ validations: {
725
+ a_bigger_than_b: {
726
+ errorMessage: 'A must be bigger than B',
727
+ rule: {
728
+ '>': [{ var: 'field_a' }, { var: 'field_b' }],
729
+ },
730
+ },
731
+ is_even_number: {
732
+ errorMessage: 'A must be even',
733
+ rule: {
734
+ '===': [{ '%': [{ var: 'field_a' }, 2] }, 0],
735
+ },
736
+ },
737
+ },
738
+ },
739
+ };
740
+
741
+ export const schemaWithTwoRules = {
742
+ properties: {
743
+ field_a: {
744
+ type: 'number',
745
+ 'x-jsf-logic-validations': ['a_bigger_than_b'],
746
+ },
747
+ field_b: {
748
+ type: 'number',
749
+ 'x-jsf-logic-validations': ['is_even_number'],
750
+ },
751
+ },
752
+ required: ['field_a', 'field_b'],
753
+ 'x-jsf-logic': {
754
+ validations: {
755
+ a_bigger_than_b: {
756
+ errorMessage: 'A must be bigger than B',
757
+ rule: {
758
+ '>': [{ var: 'field_a' }, { var: 'field_b' }],
759
+ },
760
+ },
761
+ is_even_number: {
762
+ errorMessage: 'B must be even',
763
+ rule: {
764
+ '===': [{ '%': [{ var: 'field_b' }, 2] }, 0],
765
+ },
766
+ },
767
+ },
768
+ },
769
+ };
770
+
771
+ export const schemaWithComputedAttributes = {
772
+ properties: {
773
+ field_a: {
774
+ type: 'number',
775
+ },
776
+ field_b: {
777
+ type: 'number',
778
+ 'x-jsf-logic-computedAttrs': {
779
+ title: 'This is {{a_times_two}}!',
780
+ const: 'a_times_two',
781
+ default: 'a_times_two',
782
+ description: 'This field is 2 times bigger than field_a with value of {{a_times_two}}.',
783
+ },
784
+ },
785
+ },
786
+ required: ['field_a', 'field_b'],
787
+ 'x-jsf-logic': {
788
+ computedValues: {
789
+ a_times_two: {
790
+ rule: {
791
+ '*': [{ var: 'field_a' }, 2],
792
+ },
793
+ },
794
+ },
795
+ },
796
+ };
797
+
798
+ export const nestedFieldsetWithValidationSchema = {
799
+ properties: {
800
+ field_a: {
801
+ type: 'object',
802
+ 'x-jsf-presentation': {
803
+ inputType: 'fieldset',
804
+ },
805
+ properties: {
806
+ child: {
807
+ type: 'number',
808
+ 'x-jsf-logic-validations': ['child_greater_than_10'],
809
+ },
810
+ },
811
+ required: ['child'],
812
+ 'x-jsf-logic': {
813
+ validations: {
814
+ child_greater_than_10: {
815
+ errorMessage: 'Must be greater than 10!',
816
+ rule: {
817
+ '>': [{ var: 'child' }, 10],
818
+ },
819
+ },
820
+ },
821
+ },
822
+ },
823
+ },
824
+ required: ['field_a'],
825
+ };
826
+
827
+ export const validatingTwoNestedFieldsSchema = {
828
+ properties: {
829
+ field_a: {
830
+ type: 'object',
831
+ 'x-jsf-presentation': {
832
+ inputType: 'fieldset',
833
+ },
834
+ properties: {
835
+ child: {
836
+ type: 'number',
837
+ 'x-jsf-logic-validations': ['child_greater_than_10'],
838
+ },
839
+ other_child: {
840
+ type: 'number',
841
+ 'x-jsf-logic-validations': ['greater_than_child'],
842
+ },
843
+ },
844
+ required: ['child', 'other_child'],
845
+ 'x-jsf-logic': {
846
+ validations: {
847
+ child_greater_than_10: {
848
+ errorMessage: 'Must be greater than 10!',
849
+ rule: {
850
+ '>': [{ var: 'child' }, 10],
851
+ },
852
+ },
853
+ greater_than_child: {
854
+ errorMessage: 'Must be greater than child',
855
+ rule: {
856
+ '>': [{ var: 'other_child' }, { var: 'child' }],
857
+ },
858
+ },
859
+ },
860
+ },
861
+ },
862
+ },
863
+ required: ['field_a'],
864
+ };
865
+
866
+ export const twoLevelsOfJSONLogicSchema = {
867
+ properties: {
868
+ field_a: {
869
+ type: 'object',
870
+ 'x-jsf-presentation': {
871
+ inputType: 'fieldset',
872
+ },
873
+ properties: {
874
+ child: {
875
+ type: 'number',
876
+ 'x-jsf-logic-validations': ['child_greater_than_10'],
877
+ },
878
+ },
879
+ required: ['child'],
880
+ 'x-jsf-logic': {
881
+ validations: {
882
+ child_greater_than_10: {
883
+ errorMessage: 'Must be greater than 10!',
884
+ rule: {
885
+ '>': [{ var: 'child' }, 10],
886
+ },
887
+ },
888
+ },
889
+ },
890
+ },
891
+ field_b: {
892
+ type: 'number',
893
+ 'x-jsf-logic-validations': ['validation_parent', 'peek_to_nested'],
894
+ },
895
+ },
896
+ 'x-jsf-logic': {
897
+ validations: {
898
+ validation_parent: {
899
+ errorMessage: 'Must be greater than 10!',
900
+ rule: {
901
+ '>': [{ var: 'field_b' }, 10],
902
+ },
903
+ },
904
+ peek_to_nested: {
905
+ errorMessage: 'child must be greater than 15!',
906
+ rule: {
907
+ '>': [{ var: 'field_a.child' }, 15],
908
+ },
909
+ },
910
+ },
911
+ },
912
+ required: ['field_a', 'field_b'],
913
+ };
914
+
915
+ export const fieldsetWithComputedAttributes = {
916
+ properties: {
917
+ field_a: {
918
+ type: 'object',
919
+ 'x-jsf-presentation': {
920
+ inputType: 'fieldset',
921
+ },
922
+ properties: {
923
+ child: {
924
+ type: 'number',
925
+ },
926
+ other_child: {
927
+ type: 'number',
928
+ readOnly: true,
929
+ 'x-jsf-logic-computedAttrs': {
930
+ default: 'child_times_10',
931
+ const: 'child_times_10',
932
+ description: 'this is {{child_times_10}}',
933
+ },
934
+ },
935
+ },
936
+ required: ['child'],
937
+ 'x-jsf-logic': {
938
+ computedValues: {
939
+ child_times_10: {
940
+ rule: {
941
+ '*': [{ var: 'child' }, 10],
942
+ },
943
+ },
944
+ },
945
+ },
946
+ },
947
+ },
948
+ required: ['field_a'],
949
+ };
950
+
951
+ export const fieldsetWithAConditionalToApplyExtraValidations = {
952
+ properties: {
953
+ field_a: {
954
+ type: 'object',
955
+ 'x-jsf-presentation': {
956
+ inputType: 'fieldset',
957
+ },
958
+ properties: {
959
+ child: {
960
+ type: 'number',
961
+ },
962
+ other_child: {
963
+ type: 'number',
964
+ },
965
+ third_child: {
966
+ type: 'number',
967
+ },
968
+ },
969
+ required: ['child', 'other_child'],
970
+ 'x-jsf-logic': {
971
+ validations: {
972
+ child_is_greater_than_other_child: {
973
+ rule: {
974
+ '>': [{ var: 'child' }, { var: 'other_child' }],
975
+ },
976
+ },
977
+ third_child_is_greater_than_other_child: {
978
+ errorMessage: 'Must be greater than other child.',
979
+ rule: {
980
+ '>': [{ var: 'third_child' }, { var: 'other_child' }],
981
+ },
982
+ },
983
+ },
984
+ computedValues: {
985
+ child_times_10: {
986
+ rule: {
987
+ '*': [{ var: 'child' }, 10],
988
+ },
989
+ },
990
+ },
991
+ allOf: [
992
+ {
993
+ if: {
994
+ computedValues: {
995
+ child_times_10: {
996
+ const: 100,
997
+ },
998
+ },
999
+ validations: {
1000
+ child_is_greater_than_other_child: {
1001
+ const: false,
1002
+ },
1003
+ },
1004
+ properties: {
1005
+ child: {
1006
+ const: 10,
1007
+ },
1008
+ },
1009
+ },
1010
+ then: {
1011
+ required: ['third_child'],
1012
+ properties: {
1013
+ third_child: {
1014
+ 'x-jsf-logic-validations': ['third_child_is_greater_than_other_child'],
1015
+ },
1016
+ },
1017
+ },
1018
+ else: {
1019
+ properties: {
1020
+ third_child: false,
1021
+ },
1022
+ },
1023
+ },
1024
+ ],
1025
+ },
1026
+ },
1027
+ },
1028
+ required: ['field_a'],
1029
+ };
1030
+
1031
+ export const schemaWithPropertyThatDoesNotExistInThatLevelButDoesInFieldset = {
1032
+ properties: {
1033
+ field_a: {
1034
+ type: 'object',
1035
+ 'x-jsf-presentation': {
1036
+ inputType: 'fieldset',
1037
+ },
1038
+ properties: {
1039
+ child: {
1040
+ type: 'number',
1041
+ 'x-jsf-logic-validations': ['child_greater_than_10'],
1042
+ },
1043
+ other_child: {
1044
+ type: 'number',
1045
+ 'x-jsf-logic-validations': ['greater_than_child'],
1046
+ },
1047
+ },
1048
+ required: ['child', 'other_child'],
1049
+ },
1050
+ },
1051
+ 'x-jsf-logic': {
1052
+ validations: {
1053
+ validation_parent: {
1054
+ errorMessage: 'Must be greater than 10!',
1055
+ rule: {
1056
+ '>': [{ var: 'child' }, 10],
1057
+ },
1058
+ },
1059
+ greater_than_child: {
1060
+ errorMessage: 'Must be greater than child',
1061
+ rule: {
1062
+ '>': [{ var: 'other_child' }, { var: 'child' }],
1063
+ },
1064
+ },
1065
+ },
1066
+ },
1067
+ required: ['field_a'],
1068
+ };
1069
+
1070
+ export const simpleArrayValidationSchema = {
1071
+ properties: {
1072
+ field_array: {
1073
+ type: 'array',
1074
+ items: {
1075
+ properties: {
1076
+ array_item: {
1077
+ type: 'number',
1078
+ 'x-jsf-logic-validations': ['divisible_by_two'],
1079
+ },
1080
+ },
1081
+ required: ['array_item'],
1082
+ 'x-jsf-logic': {
1083
+ validations: {
1084
+ divisible_by_two: {
1085
+ errorMessage: 'Must be divisible by two',
1086
+ rule: {
1087
+ '===': [{ '%': [{ var: 'array_item' }, 2] }, 0],
1088
+ },
1089
+ },
1090
+ },
1091
+ },
1092
+ },
1093
+ },
1094
+ },
1095
+ };
1096
+
1097
+ export const validatingASingleItemInTheArray = {
1098
+ properties: {
1099
+ field_array: {
1100
+ type: 'array',
1101
+ 'x-jsf-logic-validations': ['second_item_is_divisible_by_four'],
1102
+ items: {
1103
+ properties: {
1104
+ item: {
1105
+ type: 'number',
1106
+ },
1107
+ },
1108
+ required: ['item'],
1109
+ },
1110
+ },
1111
+ },
1112
+ 'x-jsf-logic': {
1113
+ validations: {
1114
+ second_item_is_divisible_by_four: {
1115
+ errorMessage: 'Second item in array must be divisible by 4',
1116
+ rule: {
1117
+ '===': [{ '%': [{ var: 'field_array.1.item' }, 4] }, 0],
1118
+ },
1119
+ },
1120
+ },
1121
+ },
1122
+ };
1123
+
1124
+ // FIXME: This doesn't work because conditionals in items are not supported.
1125
+ export const conditionalAppliedInAnItem = {
1126
+ properties: {
1127
+ field_array: {
1128
+ type: 'array',
1129
+ items: {
1130
+ properties: {
1131
+ item: {
1132
+ type: 'number',
1133
+ },
1134
+ other_item: {
1135
+ type: 'number',
1136
+ },
1137
+ },
1138
+ required: ['item'],
1139
+ 'x-jsf-logic': {
1140
+ validations: {
1141
+ divisible_by_three: {
1142
+ rule: {
1143
+ '===': [{ '%': [{ var: 'item' }, 3] }, 0],
1144
+ },
1145
+ },
1146
+ other_item_divisible_by_three: {
1147
+ errorMessage: 'Must be disivisble_by_three',
1148
+ rule: {
1149
+ '===': [{ '%': [{ var: 'other_item' }, 3] }, 0],
1150
+ },
1151
+ },
1152
+ },
1153
+ allOf: [
1154
+ {
1155
+ if: { validations: { divisible_by_three: { cosnt: true } } },
1156
+ then: {
1157
+ required: ['other_item'],
1158
+ other_item: { 'x-jsf-logic-validations': ['other_item_divisible_by_three'] },
1159
+ },
1160
+ else: { properties: { other_item: false } },
1161
+ },
1162
+ ],
1163
+ },
1164
+ },
1165
+ },
1166
+ },
1167
+ };
1168
+
1169
+ export const aConditionallyAppliedComputedAttributeMinimumAndMaximum = {
1170
+ properties: {
1171
+ field_a: {
1172
+ type: 'number',
1173
+ },
1174
+ field_b: {
1175
+ type: 'number',
1176
+ },
1177
+ },
1178
+ allOf: [
1179
+ {
1180
+ if: { properties: { field_a: { const: 20 } } },
1181
+ then: {
1182
+ properties: {
1183
+ field_b: {
1184
+ 'x-jsf-logic-computedAttrs': {
1185
+ minimum: 'a_divided_by_two',
1186
+ maximum: 'a_multiplied_by_two',
1187
+ 'x-jsf-errorMessage': {
1188
+ minimum: 'use {{a_divided_by_two}} or more',
1189
+ maximum: 'use less than {{a_multiplied_by_two}}',
1190
+ },
1191
+ },
1192
+ },
1193
+ },
1194
+ },
1195
+ },
1196
+ ],
1197
+ 'x-jsf-logic': {
1198
+ computedValues: {
1199
+ a_divided_by_two: {
1200
+ rule: {
1201
+ '/': [{ var: 'field_a' }, 2],
1202
+ },
1203
+ },
1204
+ a_multiplied_by_two: {
1205
+ rule: {
1206
+ '*': [{ var: 'field_a' }, 2],
1207
+ },
1208
+ },
1209
+ },
1210
+ },
1211
+ };
1212
+
1213
+ export const aConditionallyAppliedComputedAttributeValue = {
1214
+ properties: {
1215
+ field_a: {
1216
+ type: 'number',
1217
+ },
1218
+ field_b: {
1219
+ type: 'number',
1220
+ },
1221
+ },
1222
+ allOf: [
1223
+ {
1224
+ if: { properties: { field_a: { const: 20 } } },
1225
+ then: {
1226
+ properties: {
1227
+ field_b: {
1228
+ readOnly: true,
1229
+ 'x-jsf-logic-computedAttrs': {
1230
+ const: 'a_divided_by_two',
1231
+ default: 'a_divided_by_two',
1232
+ },
1233
+ },
1234
+ },
1235
+ },
1236
+ else: {
1237
+ properties: {
1238
+ field_b: {
1239
+ readOnly: false,
1240
+ },
1241
+ },
1242
+ },
1243
+ },
1244
+ ],
1245
+ 'x-jsf-logic': {
1246
+ computedValues: {
1247
+ a_divided_by_two: {
1248
+ rule: {
1249
+ '/': [{ var: 'field_a' }, 2],
1250
+ },
1251
+ },
1252
+ },
1253
+ },
1254
+ };
1255
+
1256
+ export const schemaWithInlineRuleForComputedAttributeWithCopy = {
1257
+ properties: {
1258
+ field_a: {
1259
+ type: 'number',
1260
+ },
1261
+ field_b: {
1262
+ type: 'number',
1263
+ 'x-jsf-logic-computedAttrs': {
1264
+ title: {
1265
+ value: 'I need this to work using the {{rule}}.',
1266
+ rule: {
1267
+ '+': [{ var: 'field_a' }, 10],
1268
+ },
1269
+ },
1270
+ },
1271
+ },
1272
+ },
1273
+ };
1274
+
1275
+ export const schemaWithInlineRuleForComputedAttributeWithoutCopy = {
1276
+ properties: {
1277
+ field_a: {
1278
+ type: 'number',
1279
+ },
1280
+ field_b: {
1281
+ type: 'number',
1282
+ 'x-jsf-logic-computedAttrs': {
1283
+ title: {
1284
+ rule: {
1285
+ '+': [{ var: 'field_a' }, 10],
1286
+ },
1287
+ },
1288
+ },
1289
+ },
1290
+ },
1291
+ };
1292
+
1293
+ export const schemaWithInlineRuleForComputedAttributeWithOnlyTheRule = {
1294
+ properties: {
1295
+ field_a: {
1296
+ type: 'number',
1297
+ },
1298
+ field_b: {
1299
+ type: 'number',
1300
+ 'x-jsf-logic-computedAttrs': {
1301
+ minimum: {
1302
+ rule: {
1303
+ '+': [{ var: 'field_a' }, 10],
1304
+ },
1305
+ },
1306
+ 'x-jsf-errorMessage': {
1307
+ minimum: {
1308
+ value: 'This should be greater than {{rule}}.',
1309
+ rule: {
1310
+ '+': [{ var: 'field_a' }, 10],
1311
+ },
1312
+ },
1313
+ },
1314
+ },
1315
+ },
1316
+ },
1317
+ };
1318
+
1319
+ export const schemaWithInlineRuleForComputedAttributeInConditionallyAppliedSchema = {
1320
+ properties: {
1321
+ field_a: {
1322
+ type: 'number',
1323
+ },
1324
+ field_b: {
1325
+ description: 'Hello world',
1326
+ type: 'number',
1327
+ },
1328
+ },
1329
+ allOf: [
1330
+ {
1331
+ if: {
1332
+ properties: {
1333
+ field_a: {
1334
+ const: 20,
1335
+ },
1336
+ },
1337
+ required: ['field_a'],
1338
+ },
1339
+ then: {
1340
+ properties: {
1341
+ field_b: {
1342
+ 'x-jsf-logic-computedAttrs': {
1343
+ description: {
1344
+ value: 'Must be between {{half_a}} and {{double_a}}.',
1345
+ half_a: {
1346
+ '/': [{ var: 'field_a' }, 2],
1347
+ },
1348
+ double_a: {
1349
+ '*': [{ var: 'field_a' }, 2],
1350
+ },
1351
+ },
1352
+ },
1353
+ },
1354
+ },
1355
+ },
1356
+ },
1357
+ ],
1358
+ };
1359
+
1360
+ export const schemaWithInlineMultipleRulesForComputedAttributes = {
1361
+ properties: {
1362
+ field_a: {
1363
+ type: 'number',
1364
+ },
1365
+ field_b: {
1366
+ type: 'number',
1367
+ 'x-jsf-logic-computedAttrs': {
1368
+ description: {
1369
+ value: 'Must be between {{half_a}} and {{double_a}}.',
1370
+ half_a: {
1371
+ '/': [{ var: 'field_a' }, 2],
1372
+ },
1373
+ double_a: {
1374
+ '*': [{ var: 'field_a' }, 2],
1375
+ },
1376
+ },
1377
+ },
1378
+ },
1379
+ },
1380
+ };
1381
+
1382
+ export const schemaSelfContainedValueForTitleWithNoTemplate = {
1383
+ properties: {
1384
+ field_a: {
1385
+ type: 'number',
1386
+ },
1387
+ field_b: {
1388
+ type: 'number',
1389
+ 'x-jsf-logic-computedAttrs': {
1390
+ title: {
1391
+ value: '{{rule}}',
1392
+ rule: {
1393
+ '+': [{ var: 'field_a' }, 10],
1394
+ },
1395
+ },
1396
+ },
1397
+ },
1398
+ },
1399
+ };
1400
+
1401
+ export const schemaSelfContainedValueForMaximumMinimumValues = {
1402
+ properties: {
1403
+ field_a: {
1404
+ type: 'number',
1405
+ },
1406
+ field_b: {
1407
+ type: 'number',
1408
+ 'x-jsf-logic-computedAttrs': {
1409
+ maximum: {
1410
+ rule: {
1411
+ '+': [{ var: 'field_a' }, 10],
1412
+ },
1413
+ },
1414
+ minimum: {
1415
+ rule: {
1416
+ '-': [{ var: 'field_a' }, 10],
1417
+ },
1418
+ },
1419
+ },
1420
+ },
1421
+ },
1422
+ };
1423
+
1424
+ export const schemaWithJSFLogicAndInlineRule = {
1425
+ properties: {
1426
+ field_a: {
1427
+ type: 'number',
1428
+ },
1429
+ field_b: {
1430
+ type: 'number',
1431
+ 'x-jsf-logic-computedAttrs': {
1432
+ title: {
1433
+ value: 'Going to use {{rule}} and {{not_inline}}',
1434
+ rule: {
1435
+ '+': [{ var: 'field_a' }, 10],
1436
+ },
1437
+ },
1438
+ },
1439
+ },
1440
+ },
1441
+ 'x-jsf-logic': {
1442
+ computedValues: {
1443
+ not_inline: {
1444
+ rule: {
1445
+ '+': [1, 3],
1446
+ },
1447
+ },
1448
+ },
1449
+ },
1450
+ };
1451
+
1452
+ export const schemaWithComputedAttributesAndErrorMessages = {
1453
+ properties: {
1454
+ field_a: {
1455
+ type: 'number',
1456
+ },
1457
+ field_b: {
1458
+ type: 'number',
1459
+ 'x-jsf-logic-computedAttrs': {
1460
+ minimum: 'a_times_two',
1461
+ maximum: 'a_times_four',
1462
+ 'x-jsf-errorMessage': {
1463
+ minimum: 'Must be bigger than {{a_times_two}}',
1464
+ maximum: 'Must be smaller than {{a_times_four}}',
1465
+ },
1466
+ 'x-jsf-presentation': {
1467
+ statement: {
1468
+ description: 'Must be bigger than {{a_times_two}} and smaller than {{a_times_four}}',
1469
+ },
1470
+ },
1471
+ },
1472
+ },
1473
+ },
1474
+ required: ['field_a', 'field_b'],
1475
+ 'x-jsf-logic': {
1476
+ computedValues: {
1477
+ a_times_two: {
1478
+ rule: {
1479
+ '*': [{ var: 'field_a' }, 2],
1480
+ },
1481
+ },
1482
+ a_times_four: {
1483
+ rule: {
1484
+ '*': [{ var: 'field_a' }, 4],
1485
+ },
1486
+ },
1487
+ },
1488
+ },
1489
+ };