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": { "timeout": {
"description": "maximum allowed execution time in seconds", "description": "maximum allowed execution time in seconds",
"type": "float", "type": "number",
"default": 5.0 "default": 5.0
}, },
"follow_redirects": { "follow_redirects": {

View file

@ -3,7 +3,7 @@ namespace _heimdall.helpers.json_schema
/** /**
*/ */
type type_type = ( type type_name = (
"null" "null"
| |
"boolean" "boolean"
@ -21,30 +21,91 @@ 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 = { export type type_schema = (
type ?: ( {
type_type description ?: string;
deprecated ?: boolean;
}
&
(
{
type : "null";
}
| |
Array<type_type> {
); type : "boolean";
additionalProperties ?: ( default ?: boolean;
false enum ?: Array<boolean>;
}
| |
type_schema {
); type : "integer";
properties ?: Record<string, type_schema>; default ?: int;
required ?: Array<string>; enum ?: Array<int>;
description ?: string; minimum ?: int;
default ?: any; exclusiveMinimum ?: int;
minimum ?: int; maximum ?: int;
exclusiveMinimum ?: int; exclusiveMaximum ?: int;
maximum ?: int; }
exclusiveMaximum ?: int; |
enum ?: Array<any>; {
items ?: type_schema; type : "number";
anyOf ?: Array<type_schema>; default ?: float;
deprecated ?: boolean; 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
|
type_schema
);
properties ?: Record<string, type_schema>;
required ?: Array<string>;
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>;
}
|
{
allOf ?: Array<type_schema>;
}
)
);
} }

View file

@ -372,7 +372,7 @@ async function main(
"last_notification_timestamp": last_notification_timestamp, "last_notification_timestamp": last_notification_timestamp,
} }
const timestamp = (Date.now() / 1000); const timestamp : int = Math.floor(Date.now() / 1000);
const due : boolean = ( const due : boolean = (
(old_item_state === null) (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( function schema_active(
) : _heimdall.helpers.json_schema.type_schema ) : _heimdall.helpers.json_schema.type_schema
{ {
@ -61,6 +85,8 @@ namespace _heimdall.order
} }
/**
*/
function schema_threshold( function schema_threshold(
) : _heimdall.helpers.json_schema.type_schema ) : _heimdall.helpers.json_schema.type_schema
{ {
@ -73,6 +99,8 @@ namespace _heimdall.order
} }
/**
*/
function schema_annoy( function schema_annoy(
) : _heimdall.helpers.json_schema.type_schema ) : _heimdall.helpers.json_schema.type_schema
{ {
@ -84,8 +112,10 @@ namespace _heimdall.order
} }
/**
*/
function schema_interval( function schema_interval(
allow_null, allow_null : boolean,
default_ default_
) : _heimdall.helpers.json_schema.type_schema ) : _heimdall.helpers.json_schema.type_schema
{ {
@ -112,8 +142,10 @@ namespace _heimdall.order
} }
/**
*/
function schema_schedule( function schema_schedule(
) ) : _heimdall.helpers.json_schema.type_schema
{ {
return { return {
"type": "object", "type": "object",
@ -128,10 +160,12 @@ namespace _heimdall.order
}; };
} }
/**
*/
function schema_notifications( function schema_notifications(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind> notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>
) ) : _heimdall.helpers.json_schema.type_schema
{ {
return { return {
"type": "array", "type": "array",
@ -167,12 +201,14 @@ namespace _heimdall.order
], ],
}; };
} }
/**
*/
export function schema_root( export function schema_root(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>, check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>, notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
) ) : _heimdall.helpers.json_schema.type_schema
{ {
return { return {
"type": "object", "type": "object",
@ -261,10 +297,12 @@ namespace _heimdall.order
}; };
} }
/**
*/
function normalize_interval( function normalize_interval(
interval_raw interval_raw
) ) : (null | type_interval)
{ {
if (interval_raw === null) { if (interval_raw === null) {
return null; return null;
@ -274,7 +312,7 @@ namespace _heimdall.order
return interval_raw; return interval_raw;
} }
else if (typeof(interval_raw) === "string") { else if (typeof(interval_raw) === "string") {
const map_ = { const map_ : Record<("minute" | "hour" | "day" | "week"), int> = {
"minute": (60), "minute": (60),
"hour": (60 * 60), "hour": (60 * 60),
"day": (60 * 60 * 24), "day": (60 * 60 * 24),
@ -294,9 +332,11 @@ namespace _heimdall.order
} }
/**
*/
function normalize_schedule( function normalize_schedule(
node node
) ) : type_schedule
{ {
const node_ = Object.assign( const node_ = Object.assign(
{ {
@ -314,10 +354,12 @@ namespace _heimdall.order
} }
/**
*/
function normalize_notification( function normalize_notification(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>, notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node node : any
) ) : type_notification
{ {
if (! (node["kind"] in notification_kind_implementations)) { if (! (node["kind"] in notification_kind_implementations)) {
throw new Error("invalid notification kind: " + node["kind"]); throw new Error("invalid notification kind: " + node["kind"]);
@ -331,10 +373,12 @@ namespace _heimdall.order
} }
/**
*/
function normalize_defaults( function normalize_defaults(
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>, notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node node : any
) ) : type_check_common
{ {
const node_ = Object.assign( const node_ = Object.assign(
{ {
@ -441,7 +485,7 @@ namespace _heimdall.order
function normalize_root( function normalize_root(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>, check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>, notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,
node, node : any,
options : { options : {
use_implicit_default_values ?: boolean; use_implicit_default_values ?: boolean;
} = {} } = {}
@ -521,6 +565,8 @@ namespace _heimdall.order
} }
/**
*/
export async function load( export async function load(
check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>, check_kind_implementations : Record<string, _heimdall.check_kinds.type_check_kind>,
notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>, notification_kind_implementations : Record<string, _heimdall.notification_kinds.type_notification_kind>,