apostrophe 3.59.0 → 3.59.1
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 +6 -0
- package/modules/@apostrophecms/schema/index.js +12 -13
- package/package.json +1 -1
- package/test/schemas.js +243 -33
package/CHANGELOG.md
CHANGED
|
@@ -498,10 +498,10 @@ module.exports = {
|
|
|
498
498
|
}
|
|
499
499
|
continue;
|
|
500
500
|
} else if (val.$ne) {
|
|
501
|
-
|
|
502
|
-
if (val.$ne == destinationKey) {
|
|
501
|
+
if (val.$ne === destinationKey) {
|
|
503
502
|
return false;
|
|
504
503
|
}
|
|
504
|
+
continue;
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
// Handle external conditions:
|
|
@@ -526,23 +526,22 @@ module.exports = {
|
|
|
526
526
|
continue;
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
529
|
+
// test with Object.prototype for the case val.min === 0
|
|
530
|
+
if (Object.hasOwn(val, 'min') || Object.hasOwn(val, 'max')) {
|
|
531
|
+
if (destinationKey < val.min) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
if (destinationKey > val.max) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
537
|
+
continue;
|
|
534
538
|
}
|
|
535
539
|
|
|
536
540
|
if (conditionalFields?.[key] === false) {
|
|
537
541
|
return false;
|
|
538
542
|
}
|
|
539
543
|
|
|
540
|
-
if (
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// eslint-disable-next-line eqeqeq
|
|
545
|
-
if ((typeof val === 'string' || typeof val === 'number') && destinationKey != val) {
|
|
544
|
+
if (destinationKey !== val) {
|
|
546
545
|
return false;
|
|
547
546
|
}
|
|
548
547
|
}
|
package/package.json
CHANGED
package/test/schemas.js
CHANGED
|
@@ -2381,7 +2381,9 @@ describe('Schemas', function() {
|
|
|
2381
2381
|
|
|
2382
2382
|
assert.deepEqual(actual, expected);
|
|
2383
2383
|
});
|
|
2384
|
+
});
|
|
2384
2385
|
|
|
2386
|
+
describe('field if|ifRequired', function () {
|
|
2385
2387
|
it('should enforce required property not equal match', async function() {
|
|
2386
2388
|
const req = apos.task.getReq();
|
|
2387
2389
|
const schema = apos.schema.compose({
|
|
@@ -2468,10 +2470,7 @@ describe('Schemas', function() {
|
|
|
2468
2470
|
subfield: false
|
|
2469
2471
|
}
|
|
2470
2472
|
}, output);
|
|
2471
|
-
|
|
2472
|
-
colors: true,
|
|
2473
|
-
depth: 1
|
|
2474
|
-
}));
|
|
2473
|
+
|
|
2475
2474
|
assert(!output.requiredProp);
|
|
2476
2475
|
});
|
|
2477
2476
|
|
|
@@ -2676,6 +2675,120 @@ describe('Schemas', function() {
|
|
|
2676
2675
|
}, 'requiredProp', 'required');
|
|
2677
2676
|
});
|
|
2678
2677
|
|
|
2678
|
+
it('should enforce required property number min', async function() {
|
|
2679
|
+
const req = apos.task.getReq();
|
|
2680
|
+
const schema = apos.schema.compose({
|
|
2681
|
+
addFields: [
|
|
2682
|
+
{
|
|
2683
|
+
name: 'prop1',
|
|
2684
|
+
type: 'integer',
|
|
2685
|
+
required: false
|
|
2686
|
+
},
|
|
2687
|
+
{
|
|
2688
|
+
name: 'prop2',
|
|
2689
|
+
type: 'string',
|
|
2690
|
+
required: true,
|
|
2691
|
+
if: {
|
|
2692
|
+
prop1: {
|
|
2693
|
+
min: 0,
|
|
2694
|
+
max: 10
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
]
|
|
2699
|
+
});
|
|
2700
|
+
const output = {};
|
|
2701
|
+
await apos.schema.convert(req, schema, {
|
|
2702
|
+
prop1: -1,
|
|
2703
|
+
prop2: ''
|
|
2704
|
+
}, output);
|
|
2705
|
+
assert(output.prop2 === '');
|
|
2706
|
+
});
|
|
2707
|
+
|
|
2708
|
+
it('should error required property number min', async function() {
|
|
2709
|
+
const schema = apos.schema.compose({
|
|
2710
|
+
addFields: [
|
|
2711
|
+
{
|
|
2712
|
+
name: 'prop1',
|
|
2713
|
+
type: 'integer',
|
|
2714
|
+
required: false
|
|
2715
|
+
},
|
|
2716
|
+
{
|
|
2717
|
+
name: 'prop2',
|
|
2718
|
+
type: 'string',
|
|
2719
|
+
required: true,
|
|
2720
|
+
if: {
|
|
2721
|
+
prop1: {
|
|
2722
|
+
min: 0,
|
|
2723
|
+
max: 10
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
]
|
|
2728
|
+
});
|
|
2729
|
+
await testSchemaError(schema, {
|
|
2730
|
+
prop1: 0,
|
|
2731
|
+
prop2: ''
|
|
2732
|
+
}, 'prop2', 'required');
|
|
2733
|
+
});
|
|
2734
|
+
|
|
2735
|
+
it('should enforce required property number max', async function() {
|
|
2736
|
+
const req = apos.task.getReq();
|
|
2737
|
+
const schema = apos.schema.compose({
|
|
2738
|
+
addFields: [
|
|
2739
|
+
{
|
|
2740
|
+
name: 'prop1',
|
|
2741
|
+
type: 'integer',
|
|
2742
|
+
required: false
|
|
2743
|
+
},
|
|
2744
|
+
{
|
|
2745
|
+
name: 'prop2',
|
|
2746
|
+
type: 'string',
|
|
2747
|
+
required: true,
|
|
2748
|
+
if: {
|
|
2749
|
+
prop1: {
|
|
2750
|
+
min: -10,
|
|
2751
|
+
max: 0
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
]
|
|
2756
|
+
});
|
|
2757
|
+
const output = {};
|
|
2758
|
+
await apos.schema.convert(req, schema, {
|
|
2759
|
+
prop1: 1,
|
|
2760
|
+
prop2: ''
|
|
2761
|
+
}, output);
|
|
2762
|
+
assert(output.prop2 === '');
|
|
2763
|
+
});
|
|
2764
|
+
|
|
2765
|
+
it('should error required property number max', async function() {
|
|
2766
|
+
const schema = apos.schema.compose({
|
|
2767
|
+
addFields: [
|
|
2768
|
+
{
|
|
2769
|
+
name: 'prop1',
|
|
2770
|
+
type: 'integer',
|
|
2771
|
+
required: false
|
|
2772
|
+
},
|
|
2773
|
+
{
|
|
2774
|
+
name: 'prop2',
|
|
2775
|
+
type: 'string',
|
|
2776
|
+
required: true,
|
|
2777
|
+
if: {
|
|
2778
|
+
prop1: {
|
|
2779
|
+
min: -10,
|
|
2780
|
+
max: 0
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
]
|
|
2785
|
+
});
|
|
2786
|
+
await testSchemaError(schema, {
|
|
2787
|
+
prop1: 0,
|
|
2788
|
+
prop2: ''
|
|
2789
|
+
}, 'prop2', 'required');
|
|
2790
|
+
});
|
|
2791
|
+
|
|
2679
2792
|
it('should enforce required property nested logical AND', async function() {
|
|
2680
2793
|
const req = apos.task.getReq();
|
|
2681
2794
|
const schema = apos.schema.compose({
|
|
@@ -2956,48 +3069,49 @@ describe('Schemas', function() {
|
|
|
2956
3069
|
const schema = apos.schema.compose({
|
|
2957
3070
|
addFields: [
|
|
2958
3071
|
{
|
|
2959
|
-
name: '
|
|
2960
|
-
type: '
|
|
3072
|
+
name: 'prop1',
|
|
3073
|
+
type: 'boolean',
|
|
2961
3074
|
required: false
|
|
2962
3075
|
},
|
|
2963
3076
|
{
|
|
2964
|
-
name: '
|
|
2965
|
-
type: '
|
|
3077
|
+
name: 'prop2',
|
|
3078
|
+
type: 'string',
|
|
2966
3079
|
requiredIf: {
|
|
2967
|
-
|
|
3080
|
+
prop1: true
|
|
2968
3081
|
}
|
|
2969
3082
|
}
|
|
2970
3083
|
]
|
|
2971
3084
|
});
|
|
2972
3085
|
const output = {};
|
|
2973
3086
|
await apos.schema.convert(req, schema, {
|
|
2974
|
-
|
|
2975
|
-
|
|
3087
|
+
prop1: false,
|
|
3088
|
+
prop2: ''
|
|
2976
3089
|
}, output);
|
|
2977
|
-
|
|
3090
|
+
|
|
3091
|
+
assert(output.prop2 === '');
|
|
2978
3092
|
});
|
|
2979
3093
|
|
|
2980
3094
|
it('should error required property with ifRequired boolean', async function() {
|
|
2981
3095
|
const schema = apos.schema.compose({
|
|
2982
3096
|
addFields: [
|
|
2983
3097
|
{
|
|
2984
|
-
name: '
|
|
2985
|
-
type: '
|
|
3098
|
+
name: 'prop1',
|
|
3099
|
+
type: 'boolean',
|
|
2986
3100
|
required: false
|
|
2987
3101
|
},
|
|
2988
3102
|
{
|
|
2989
|
-
name: '
|
|
2990
|
-
type: '
|
|
3103
|
+
name: 'prop2',
|
|
3104
|
+
type: 'string',
|
|
2991
3105
|
requiredIf: {
|
|
2992
|
-
|
|
3106
|
+
prop1: true
|
|
2993
3107
|
}
|
|
2994
3108
|
}
|
|
2995
3109
|
]
|
|
2996
3110
|
});
|
|
2997
3111
|
await testSchemaError(schema, {
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
}, '
|
|
3112
|
+
prop1: true,
|
|
3113
|
+
prop2: ''
|
|
3114
|
+
}, 'prop2', 'required');
|
|
3001
3115
|
});
|
|
3002
3116
|
|
|
3003
3117
|
it('should enforce required property with ifRequired string', async function() {
|
|
@@ -3006,7 +3120,7 @@ describe('Schemas', function() {
|
|
|
3006
3120
|
addFields: [
|
|
3007
3121
|
{
|
|
3008
3122
|
name: 'age',
|
|
3009
|
-
type: '
|
|
3123
|
+
type: 'string',
|
|
3010
3124
|
required: false
|
|
3011
3125
|
},
|
|
3012
3126
|
{
|
|
@@ -3031,7 +3145,7 @@ describe('Schemas', function() {
|
|
|
3031
3145
|
addFields: [
|
|
3032
3146
|
{
|
|
3033
3147
|
name: 'age',
|
|
3034
|
-
type: '
|
|
3148
|
+
type: 'string',
|
|
3035
3149
|
required: false
|
|
3036
3150
|
},
|
|
3037
3151
|
{
|
|
@@ -3135,8 +3249,29 @@ describe('Schemas', function() {
|
|
|
3135
3249
|
required: false
|
|
3136
3250
|
},
|
|
3137
3251
|
{
|
|
3138
|
-
name: '
|
|
3139
|
-
type: '
|
|
3252
|
+
name: 'shoeSize',
|
|
3253
|
+
type: 'integer',
|
|
3254
|
+
requiredIf: {
|
|
3255
|
+
age: {
|
|
3256
|
+
min: 18
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
]
|
|
3261
|
+
});
|
|
3262
|
+
await testSchemaError(schema, {
|
|
3263
|
+
shoeSize: '',
|
|
3264
|
+
age: 19
|
|
3265
|
+
}, 'shoeSize', 'required');
|
|
3266
|
+
});
|
|
3267
|
+
|
|
3268
|
+
it('should enforce required property with ifRequired number min 0', async function() {
|
|
3269
|
+
const req = apos.task.getReq();
|
|
3270
|
+
const schema = apos.schema.compose({
|
|
3271
|
+
addFields: [
|
|
3272
|
+
{
|
|
3273
|
+
name: 'age',
|
|
3274
|
+
type: 'integer',
|
|
3140
3275
|
required: false
|
|
3141
3276
|
},
|
|
3142
3277
|
{
|
|
@@ -3144,7 +3279,34 @@ describe('Schemas', function() {
|
|
|
3144
3279
|
type: 'integer',
|
|
3145
3280
|
requiredIf: {
|
|
3146
3281
|
age: {
|
|
3147
|
-
min:
|
|
3282
|
+
min: 1
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
]
|
|
3287
|
+
});
|
|
3288
|
+
const output = {};
|
|
3289
|
+
await apos.schema.convert(req, schema, {
|
|
3290
|
+
shoeSize: '',
|
|
3291
|
+
age: 0
|
|
3292
|
+
}, output);
|
|
3293
|
+
assert(output.shoeSize === null);
|
|
3294
|
+
});
|
|
3295
|
+
|
|
3296
|
+
it('should error required property with ifRequired number min 0', async function() {
|
|
3297
|
+
const schema = apos.schema.compose({
|
|
3298
|
+
addFields: [
|
|
3299
|
+
{
|
|
3300
|
+
name: 'age',
|
|
3301
|
+
type: 'integer',
|
|
3302
|
+
required: false
|
|
3303
|
+
},
|
|
3304
|
+
{
|
|
3305
|
+
name: 'shoeSize',
|
|
3306
|
+
type: 'integer',
|
|
3307
|
+
requiredIf: {
|
|
3308
|
+
age: {
|
|
3309
|
+
min: 0
|
|
3148
3310
|
}
|
|
3149
3311
|
}
|
|
3150
3312
|
}
|
|
@@ -3152,8 +3314,7 @@ describe('Schemas', function() {
|
|
|
3152
3314
|
});
|
|
3153
3315
|
await testSchemaError(schema, {
|
|
3154
3316
|
shoeSize: '',
|
|
3155
|
-
age:
|
|
3156
|
-
prop2: false
|
|
3317
|
+
age: 0
|
|
3157
3318
|
}, 'shoeSize', 'required');
|
|
3158
3319
|
});
|
|
3159
3320
|
|
|
@@ -3194,11 +3355,6 @@ describe('Schemas', function() {
|
|
|
3194
3355
|
type: 'integer',
|
|
3195
3356
|
required: false
|
|
3196
3357
|
},
|
|
3197
|
-
{
|
|
3198
|
-
name: 'prop2',
|
|
3199
|
-
type: 'boolean',
|
|
3200
|
-
required: false
|
|
3201
|
-
},
|
|
3202
3358
|
{
|
|
3203
3359
|
name: 'shoeSize',
|
|
3204
3360
|
type: 'integer',
|
|
@@ -3217,6 +3373,61 @@ describe('Schemas', function() {
|
|
|
3217
3373
|
}, 'shoeSize', 'required');
|
|
3218
3374
|
});
|
|
3219
3375
|
|
|
3376
|
+
it('should enforce required property with ifRequired number max 0', async function() {
|
|
3377
|
+
const req = apos.task.getReq();
|
|
3378
|
+
const schema = apos.schema.compose({
|
|
3379
|
+
addFields: [
|
|
3380
|
+
{
|
|
3381
|
+
name: 'prop1',
|
|
3382
|
+
type: 'integer',
|
|
3383
|
+
required: false
|
|
3384
|
+
},
|
|
3385
|
+
{
|
|
3386
|
+
name: 'prop2',
|
|
3387
|
+
type: 'string',
|
|
3388
|
+
requiredIf: {
|
|
3389
|
+
prop1: {
|
|
3390
|
+
min: -10,
|
|
3391
|
+
max: 0
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
]
|
|
3396
|
+
});
|
|
3397
|
+
const output = {};
|
|
3398
|
+
await apos.schema.convert(req, schema, {
|
|
3399
|
+
prop1: 1,
|
|
3400
|
+
prop2: ''
|
|
3401
|
+
}, output);
|
|
3402
|
+
assert(output.prop2 === '');
|
|
3403
|
+
});
|
|
3404
|
+
|
|
3405
|
+
it('should error required property with ifRequired number max 0', async function() {
|
|
3406
|
+
const schema = apos.schema.compose({
|
|
3407
|
+
addFields: [
|
|
3408
|
+
{
|
|
3409
|
+
name: 'prop1',
|
|
3410
|
+
type: 'integer',
|
|
3411
|
+
required: false
|
|
3412
|
+
},
|
|
3413
|
+
{
|
|
3414
|
+
name: 'prop2',
|
|
3415
|
+
type: 'string',
|
|
3416
|
+
requiredIf: {
|
|
3417
|
+
prop1: {
|
|
3418
|
+
min: -10,
|
|
3419
|
+
max: 0
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
]
|
|
3424
|
+
});
|
|
3425
|
+
await testSchemaError(schema, {
|
|
3426
|
+
prop1: 0,
|
|
3427
|
+
prop2: ''
|
|
3428
|
+
}, 'prop2', 'required');
|
|
3429
|
+
});
|
|
3430
|
+
|
|
3220
3431
|
it('should enforce required property with ifRequired logical AND', async function() {
|
|
3221
3432
|
const req = apos.task.getReq();
|
|
3222
3433
|
const schema = apos.schema.compose({
|
|
@@ -4080,7 +4291,6 @@ describe('Schemas', function() {
|
|
|
4080
4291
|
|
|
4081
4292
|
await testSchemaError(schema, {}, 'age', 'required');
|
|
4082
4293
|
});
|
|
4083
|
-
|
|
4084
4294
|
});
|
|
4085
4295
|
});
|
|
4086
4296
|
|