-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathObjectGetDto.js
More file actions
112 lines (102 loc) · 3.75 KB
/
ObjectGetDto.js
File metadata and controls
112 lines (102 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import Joi from 'joi';
import { RunNumberDto } from './filters/RunNumberDto.js';
const periodNamePattern = /^LHC\d{1,2}[a-z0-9]+$/i;
const qcVersionPattern = /^\d+\.\d+(\.\d+)?$/;
/**
* Creates and returns a filters schema for object DTOs
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for filters
*/
function createFiltersSchema(runTypes) {
return Joi.object({
RunNumber: RunNumberDto.optional(),
RunType: runTypes.length > 0
? Joi.string().valid(...runTypes).optional()
: Joi.string().optional(),
PeriodName: Joi.string().pattern(periodNamePattern).optional(),
PassName: Joi.string().optional(),
QcVersion: Joi.string().pattern(qcVersionPattern).optional(),
}).optional();
}
/**
* Creates and returns the base object get schema
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for base object get
*/
function createBaseObjectGetDto({ runTypes }) {
return Joi.object({
token: Joi.string().required(),
id: Joi.string().optional(),
validFrom: Joi.number().optional().min(0),
filters: createFiltersSchema(runTypes),
}).options({ allowUnknown: false });
}
/**
* Creates and returns the base objects get schema
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for base objects get
*/
function createBaseObjectsGetDto({ runTypes }) {
return Joi.object({
token: Joi.string().required(),
fields: Joi.array().default([]).items(Joi.string()),
filters: createFiltersSchema(runTypes),
inRunMode: Joi.boolean().default(false),
}).options({ allowUnknown: false });
}
/**
* Creates and returns the ObjectsGetDto schema
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for getting multiple objects
*/
export function createObjectsGetDto({ runTypes }) {
return createBaseObjectsGetDto({ runTypes }).keys({
prefix: Joi.string(),
});
}
/**
* Creates and returns the ObjectContentsGetDto schema
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for getting object contents
*/
export function createObjectContentsGetDto({ runTypes }) {
return createBaseObjectGetDto({ runTypes }).keys({
path: Joi.string().required(),
});
}
/**
* Creates and returns the ObjectGetByIdDto schema
* @param {Array<string>} runTypes - Array of valid run types
* @returns {Joi.ObjectSchema} Joi validation schema for getting an object by ID
*/
export function createObjectGetByIdDto({ runTypes }) {
return createBaseObjectGetDto({ runTypes }); // doesn't require any alterations.
}
/**
* Joi validation schema for object ID in URL
*/
export const qcObjectIdDto =
Joi.string().required().trim().min(1).messages({ 'string.empty': 'Missing object ID in URL' });
/**
* Joi calidation schema for downloading ROOT objects trough the QcdbDownloadService
*/
export const ObjectGetDownloadDTO = Joi.object({
token: Joi.string().required(),
objectIds: Joi.alternatives().try(
Joi.array().min(1).items(Joi.string()).required(),
Joi.string(),
).required(),
});