@@ -132,6 +132,11 @@ const BaseDimensionWithoutSubQuery = {
132132 enableSuggestions : Joi . boolean ( ) . strict ( ) ,
133133 format : formatSchema ,
134134 meta : Joi . any ( ) ,
135+ values : Joi . when ( 'type' , {
136+ is : 'switch' ,
137+ then : Joi . array ( ) . items ( Joi . string ( ) ) ,
138+ otherwise : Joi . forbidden ( )
139+ } ) ,
135140 granularities : Joi . when ( 'type' , {
136141 is : 'time' ,
137142 then : Joi . object ( ) . pattern ( identifierRegex ,
@@ -647,53 +652,62 @@ const CalendarTimeShiftItem = Joi.alternatives().try(
647652 } )
648653) ;
649654
650- const DimensionsSchema = Joi . object ( ) . pattern ( identifierRegex , Joi . alternatives ( ) . try (
651- inherit ( BaseDimensionWithoutSubQuery , {
652- case : Joi . object ( ) . keys ( {
653- when : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
654- sql : Joi . func ( ) . required ( ) ,
655- label : Joi . alternatives ( [
656- Joi . string ( ) ,
657- Joi . object ( ) . keys ( {
658- sql : Joi . func ( ) . required ( )
659- } )
660- ] )
661- } ) ) ,
662- else : Joi . object ( ) . keys ( {
663- label : Joi . alternatives ( [
664- Joi . string ( ) ,
665- Joi . object ( ) . keys ( {
666- sql : Joi . func ( ) . required ( )
667- } )
668- ] )
669- } )
670- } ) . required ( )
671- } ) ,
672- inherit ( BaseDimensionWithoutSubQuery , {
673- latitude : Joi . object ( ) . keys ( {
674- sql : Joi . func ( ) . required ( )
675- } ) . required ( ) ,
676- longitude : Joi . object ( ) . keys ( {
677- sql : Joi . func ( ) . required ( )
678- } ) . required ( )
679- } ) ,
680- inherit ( BaseDimension , {
681- sql : Joi . func ( ) . required ( ) ,
682- } ) ,
683- inherit ( BaseDimension , {
684- multiStage : Joi . boolean ( ) . valid ( true ) ,
685- type : Joi . any ( ) . valid ( 'number' ) . required ( ) ,
686- sql : Joi . func ( ) . required ( ) ,
687- addGroupBy : Joi . func ( ) ,
688- } ) ,
689- // TODO should be valid only for calendar cubes, but this requires significant refactoring
690- // of all schemas. Left for the future when we'll switch to zod.
691- inherit ( BaseDimensionWithoutSubQuery , {
692- type : Joi . any ( ) . valid ( 'time' ) . required ( ) ,
693- sql : Joi . func ( ) . required ( ) ,
694- timeShift : Joi . array ( ) . items ( CalendarTimeShiftItem ) ,
695- } )
696- ) ) ;
655+ const SwitchDimension = Joi . object ( {
656+ type : Joi . string ( ) . valid ( 'switch' ) . required ( ) ,
657+ values : Joi . array ( ) . items ( Joi . string ( ) ) . min ( 1 ) . required ( )
658+ } ) ;
659+
660+ const DimensionsSchema = Joi . object ( ) . pattern ( identifierRegex , Joi . alternatives ( ) . conditional ( Joi . ref ( '.type' ) , {
661+ is : 'switch' ,
662+ then : SwitchDimension ,
663+ otherwise : Joi . alternatives ( ) . try (
664+ inherit ( BaseDimensionWithoutSubQuery , {
665+ case : Joi . object ( ) . keys ( {
666+ when : Joi . array ( ) . items ( Joi . object ( ) . keys ( {
667+ sql : Joi . func ( ) . required ( ) ,
668+ label : Joi . alternatives ( [
669+ Joi . string ( ) ,
670+ Joi . object ( ) . keys ( {
671+ sql : Joi . func ( ) . required ( )
672+ } )
673+ ] )
674+ } ) ) ,
675+ else : Joi . object ( ) . keys ( {
676+ label : Joi . alternatives ( [
677+ Joi . string ( ) ,
678+ Joi . object ( ) . keys ( {
679+ sql : Joi . func ( ) . required ( )
680+ } )
681+ ] )
682+ } )
683+ } ) . required ( )
684+ } ) ,
685+ inherit ( BaseDimensionWithoutSubQuery , {
686+ latitude : Joi . object ( ) . keys ( {
687+ sql : Joi . func ( ) . required ( )
688+ } ) . required ( ) ,
689+ longitude : Joi . object ( ) . keys ( {
690+ sql : Joi . func ( ) . required ( )
691+ } ) . required ( )
692+ } ) ,
693+ inherit ( BaseDimension , {
694+ sql : Joi . func ( ) . required ( ) ,
695+ } ) ,
696+ inherit ( BaseDimension , {
697+ multiStage : Joi . boolean ( ) . valid ( true ) ,
698+ type : Joi . any ( ) . valid ( 'number' ) . required ( ) ,
699+ sql : Joi . func ( ) . required ( ) ,
700+ addGroupBy : Joi . func ( ) ,
701+ } ) ,
702+ // TODO should be valid only for calendar cubes, but this requires significant refactoring
703+ // of all schemas. Left for the future when we'll switch to zod.
704+ inherit ( BaseDimensionWithoutSubQuery , {
705+ type : Joi . any ( ) . valid ( 'time' ) . required ( ) ,
706+ sql : Joi . func ( ) . required ( ) ,
707+ timeShift : Joi . array ( ) . items ( CalendarTimeShiftItem ) ,
708+ } )
709+ )
710+ } ) ) ;
697711
698712const SegmentsSchema = Joi . object ( ) . pattern ( identifierRegex , Joi . object ( ) . keys ( {
699713 aliases : Joi . array ( ) . items ( Joi . string ( ) ) ,
0 commit comments