This commit is contained in:
Christian Fraß 2023-06-19 18:27:04 +02:00
parent 1e9a6e2f4f
commit 2b6e350e3b
4 changed files with 150 additions and 43 deletions

View file

@ -33,7 +33,7 @@ namespace _heimdall.check_kinds.http_request
},
"timeout": {
"description": "maximum allowed execution time in seconds",
"type": "float",
"type": "number",
"default": 5.0
},
"follow_redirects": {

View file

@ -3,7 +3,7 @@ namespace _heimdall.helpers.json_schema
/**
*/
type type_type = (
type type_name = (
"null"
|
"boolean"
@ -21,13 +21,60 @@ namespace _heimdall.helpers.json_schema
/**
* @see https://json-schema.org/
* @see https://json-schema.org/understanding-json-schema/reference/type.html
*/
export type type_schema = {
type ?: (
type_type
export type type_schema = (
{
description ?: string;
deprecated ?: boolean;
}
&
(
{
type : "null";
}
|
Array<type_type>
);
{
type : "boolean";
default ?: boolean;
enum ?: Array<boolean>;
}
|
{
type : "integer";
default ?: int;
enum ?: Array<int>;
minimum ?: int;
exclusiveMinimum ?: int;
maximum ?: int;
exclusiveMaximum ?: int;
}
|
{
type : "number";
default ?: float;
enum ?: Array<float>;
minimum ?: float;
exclusiveMinimum ?: float;
maximum ?: float;
exclusiveMaximum ?: float;
}
|
{
type : "string";
default ?: string;
enum ?: Array<string>;
minLength ?: int;
maxLength ?: int;
pattern ?: string;
}
|
/**
* @see https://json-schema.org/understanding-json-schema/reference/object.html#object
*/
{
type : "object";
additionalProperties ?: (
false
|
@ -35,16 +82,30 @@ namespace _heimdall.helpers.json_schema
);
properties ?: Record<string, type_schema>;
required ?: Array<string>;
description ?: string;
default ?: any;
minimum ?: int;
exclusiveMinimum ?: int;
maximum ?: int;
exclusiveMaximum ?: int;
enum ?: Array<any>;
unevaluatedProperties ?: boolean;
default ?: Object;
enum ?: Array<Object>;
}
|
{
type ?: "array";
items ?: type_schema;
default ?: Array<any>;
enum ?: Array<Array<any>>;
}
|
{
type ?: Array<type_name>;
}
|
{
anyOf ?: Array<type_schema>;
deprecated ?: boolean;
};
}
|
{
allOf ?: Array<type_schema>;
}
)
);
}

View file

@ -372,7 +372,7 @@ async function main(
"last_notification_timestamp": last_notification_timestamp,
}
const timestamp = (Date.now() / 1000);
const timestamp : int = Math.floor(Date.now() / 1000);
const due : boolean = (
(old_item_state === null)
||

View file

@ -2,9 +2,31 @@ namespace _heimdall.order
{
/**
* @todo
*/
type type_schedule = any;
type type_interval = (
null
|
int
|
(
"minute"
|
"hour"
|
"day"
|
"week"
)
);
/**
*/
type type_schedule = {
regular_interval : type_interval;
attentive_interval : type_interval;
reminding_interval : type_interval;
};
/**
@ -50,6 +72,8 @@ namespace _heimdall.order
};
/**
*/
function schema_active(
) : _heimdall.helpers.json_schema.type_schema
{
@ -61,6 +85,8 @@ namespace _heimdall.order
}
/**
*/
function schema_threshold(
) : _heimdall.helpers.json_schema.type_schema
{
@ -73,6 +99,8 @@ namespace _heimdall.order
}
/**
*/
function schema_annoy(
) : _heimdall.helpers.json_schema.type_schema
{
@ -84,8 +112,10 @@ namespace _heimdall.order
}
/**
*/
function schema_interval(
allow_null,
allow_null : boolean,
default_
) : _heimdall.helpers.json_schema.type_schema
{
@ -112,8 +142,10 @@ namespace _heimdall.order
}
/**
*/
function schema_schedule(
)
) : _heimdall.helpers.json_schema.type_schema
{
return {
"type": "object",
@ -129,9 +161,11 @@ namespace _heimdall.order
}
/**
*/
function schema_notifications(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>
)
) : _heimdall.helpers.json_schema.type_schema
{
return {
"type": "array",
@ -169,10 +203,12 @@ namespace _heimdall.order
}
/**
*/
export function schema_root(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
)
) : _heimdall.helpers.json_schema.type_schema
{
return {
"type": "object",
@ -262,9 +298,11 @@ namespace _heimdall.order
}
/**
*/
function normalize_interval(
interval_raw
)
) : (null | type_interval)
{
if (interval_raw === null) {
return null;
@ -274,7 +312,7 @@ namespace _heimdall.order
return interval_raw;
}
else if (typeof(interval_raw) === "string") {
const map_ = {
const map_ : Record<("minute" | "hour" | "day" | "week"), int> = {
"minute": (60),
"hour": (60 * 60),
"day": (60 * 60 * 24),
@ -294,9 +332,11 @@ namespace _heimdall.order
}
/**
*/
function normalize_schedule(
node
)
) : type_schedule
{
const node_ = Object.assign(
{
@ -314,10 +354,12 @@ namespace _heimdall.order
}
/**
*/
function normalize_notification(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node
)
node : any
) : type_notification
{
if (! (node["kind"] in notification_kind_implementations)) {
throw new Error("invalid notification kind: " + node["kind"]);
@ -331,10 +373,12 @@ namespace _heimdall.order
}
/**
*/
function normalize_defaults(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node
)
node : any
) : type_check_common
{
const node_ = Object.assign(
{
@ -441,7 +485,7 @@ namespace _heimdall.order
function normalize_root(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node,
node : any,
options : {
use_implicit_default_values ?: boolean;
} = {}
@ -521,6 +565,8 @@ namespace _heimdall.order
}
/**
*/
export async function load(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,