@@ -17,17 +17,22 @@ const { CustomJoi } = require('../CustomJoi.js');
1717/**
1818 * Used by Bookkeeping-LHC Plugin to send data as per LHC
1919 */
20- const DASH_SEPARATED_BEAM_TYPE_PATTERN = / ^ [ A - Z a - z 0 - 9 ] + ? - ? [ A - Z a - z 0 - 9 ] + $ / ;
20+ const DASH_SEPARATED_BEAM_TYPE_PATTERN = / ^ [ A - Z a - z 0 - 9 ] { 1 , 6 } ? - ? [ A - Z a - z 0 - 9 ] { 1 , 6 } $ / ;
2121
2222/**
2323 * User Input format declared by user at deployment of environment
2424 */
2525const COMPACT_BEAM_TYPE_PATTERN = / ^ [ A - Z a - z ] { 2 , 15 } $ / ;
2626
27+ const BEAM_TYPE_MIN_LENGTH = 5 ;
28+ const BEAM_TYPE_MAX_LENGTH = 15 ;
29+ const PDP_BEAM_TYPE_MIN_LENGTH = 2 ;
30+ const PDP_BEAM_TYPE_MAX_LENGTH = 10 ;
31+
2732/**
2833 * @typedef {string[] } BeamTypesDto
2934 * @description An array of beam types, each represented as a string.
30- * Each beam type must be a string with a minimum length of 3 characters and a maximum length of 15 characters.
35+ * Each beam type must be a string with a minimum length of 2 characters and a maximum length of 15 characters.
3136 * The string must match patterns such as "PROTON - PROTON", "NE10 - NE10", where the two parts are separated by a hyphen and optional spaces.
3237 *
3338 * RUN3 has the following beam types:
@@ -36,20 +41,45 @@ const COMPACT_BEAM_TYPE_PATTERN = /^[A-Za-z]{2,15}$/;
3641 * "O8 - O8"
3742 * "PB82 - PB82"
3843 * "PROTON - O8"
39- * "PROTON - PROTON"
44+ *
45+ * RUN3 has the following compact beam types:
46+ * "pp"
47+ * "pPb"
48+ * "NeNe"
49+ * "OO"
50+ * "cosmic"
51+ * "technical"
4052 *
4153 * @example
4254 * const beamTypes = ["PROTON - PROTON", "NE10 - NE10"];
4355 */
4456exports . BeamTypesDto = CustomJoi . stringArray ( )
4557 . items ( Joi . string ( )
4658 . trim ( )
47- . min ( 2 )
48- . max ( 15 )
49- . pattern ( new RegExp ( `(?: ${ DASH_SEPARATED_BEAM_TYPE_PATTERN . source } )|(?: ${ COMPACT_BEAM_TYPE_PATTERN . source } )` ) )
59+ . min ( BEAM_TYPE_MIN_LENGTH )
60+ . max ( BEAM_TYPE_MAX_LENGTH )
61+ . pattern ( DASH_SEPARATED_BEAM_TYPE_PATTERN )
5062 . messages ( {
5163 'string.base' : 'Beam type must be a string' ,
52- 'string.min' : 'Beam type must be at least 2 characters long' ,
53- 'string.max' : 'Beam type must be at most 15 characters long' ,
54- 'string.pattern.base' : 'Beam type must look like "PROTON - PROTON", "NE10 - NE10", "pp", "pPb", "NeNe", "OO", etc.' ,
64+ 'string.min' : `Beam type must be at least ${ BEAM_TYPE_MIN_LENGTH } characters long` ,
65+ 'string.max' : `Beam type must be at most ${ BEAM_TYPE_MAX_LENGTH } characters long` ,
66+ 'string.pattern.base' : 'Beam type must look like "PROTON - PROTON", "NE10 - NE10", etc.' ,
67+ } ) ) ;
68+
69+ /**
70+ * @typedef {string[] } PdpBeamTypesDto
71+ * @description An array of compact PDP beam types represented as strings.
72+ * Values can include examples like "pp", "pPb", "NeNe", "OO", "cosmic", and "technical".
73+ */
74+ exports . PdpBeamTypesDto = CustomJoi . stringArray ( )
75+ . items ( Joi . string ( )
76+ . trim ( )
77+ . min ( PDP_BEAM_TYPE_MIN_LENGTH )
78+ . max ( PDP_BEAM_TYPE_MAX_LENGTH )
79+ . pattern ( COMPACT_BEAM_TYPE_PATTERN )
80+ . messages ( {
81+ 'string.base' : 'PDP beam type must be a string' ,
82+ 'string.min' : `PDP beam type must be at least ${ PDP_BEAM_TYPE_MIN_LENGTH } characters long` ,
83+ 'string.max' : `PDP beam type must be at most ${ PDP_BEAM_TYPE_MAX_LENGTH } characters long` ,
84+ 'string.pattern.base' : 'PDP beam type must look like "pp", "pPb", "NeNe", "OO", "cosmic", "technical", etc.' ,
5585 } ) ) ;
0 commit comments