-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathutilities.mjs
More file actions
45 lines (43 loc) · 1.23 KB
/
utilities.mjs
File metadata and controls
45 lines (43 loc) · 1.23 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
import { ERRORS } from './constants.mjs';
/**
* Helper function to replace placeholders in error messages with dynamic values.
* @param {string} message - The error message with placeholders.
* @param {Object} params - The values to replace the placeholders.
* @returns {string} - The formatted error message.
*/
export function formatErrorMessage(message, params) {
return message.replace(/{{(\w+)}}/g, (_, key) => params[key] || `{{${key}}}`);
}
/**
* Returns the JSON Schema definition for a given C++ type.
*
* @param {string} type - The type to get the schema for.
* @returns {object} JSON Schema definition for the given type.
*/
export function getTypeSchema(type) {
switch (type) {
case 'std::vector<std::string>':
return {
oneOf: [
{ type: 'string' },
{
type: 'array',
items: { type: 'string' },
minItems: 1,
},
],
};
case 'uint64_t':
case 'int64_t':
case 'HostPort':
return { type: 'number' };
case 'std::string':
return { type: 'string' };
case 'bool':
return { type: 'boolean' };
default:
throw new Error(
formatErrorMessage(ERRORS.missingTypeDefinition, { type })
);
}
}