From 2b6e350e3b59aa953012848f570ae281e418a2f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Mon, 19 Jun 2023 18:27:04 +0200 Subject: [PATCH] [int] --- source/logic/check_kinds/http_request.ts | 2 +- source/logic/helpers/json_schema.ts | 107 ++++++++++++++++++----- source/logic/main.ts | 2 +- source/logic/order.ts | 82 +++++++++++++---- 4 files changed, 150 insertions(+), 43 deletions(-) diff --git a/source/logic/check_kinds/http_request.ts b/source/logic/check_kinds/http_request.ts index ea849e2..8f09636 100644 --- a/source/logic/check_kinds/http_request.ts +++ b/source/logic/check_kinds/http_request.ts @@ -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": { diff --git a/source/logic/helpers/json_schema.ts b/source/logic/helpers/json_schema.ts index c398653..5729a11 100644 --- a/source/logic/helpers/json_schema.ts +++ b/source/logic/helpers/json_schema.ts @@ -3,7 +3,7 @@ namespace _heimdall.helpers.json_schema /** */ - type type_type = ( + type type_name = ( "null" | "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 = { - type ?: ( - type_type + export type type_schema = ( + { + description ?: string; + deprecated ?: boolean; + } + & + ( + { + type : "null"; + } | - Array - ); - additionalProperties ?: ( - false + { + type : "boolean"; + default ?: boolean; + enum ?: Array; + } | - type_schema - ); - properties ?: Record; - required ?: Array; - description ?: string; - default ?: any; - minimum ?: int; - exclusiveMinimum ?: int; - maximum ?: int; - exclusiveMaximum ?: int; - enum ?: Array; - items ?: type_schema; - anyOf ?: Array; - deprecated ?: boolean; - }; + { + type : "integer"; + default ?: int; + enum ?: Array; + minimum ?: int; + exclusiveMinimum ?: int; + maximum ?: int; + exclusiveMaximum ?: int; + } + | + { + type : "number"; + default ?: float; + enum ?: Array; + minimum ?: float; + exclusiveMinimum ?: float; + maximum ?: float; + exclusiveMaximum ?: float; + } + | + { + type : "string"; + default ?: string; + enum ?: Array; + 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; + required ?: Array; + unevaluatedProperties ?: boolean; + default ?: Object; + enum ?: Array; + } + | + { + type ?: "array"; + items ?: type_schema; + default ?: Array; + enum ?: Array>; + } + | + { + type ?: Array; + } + | + { + anyOf ?: Array; + } + | + { + allOf ?: Array; + } + ) + ); } diff --git a/source/logic/main.ts b/source/logic/main.ts index ece80cf..b191d0b 100644 --- a/source/logic/main.ts +++ b/source/logic/main.ts @@ -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) || diff --git a/source/logic/order.ts b/source/logic/order.ts index 9c15a5e..51938fa 100644 --- a/source/logic/order.ts +++ b/source/logic/order.ts @@ -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", @@ -128,10 +160,12 @@ namespace _heimdall.order }; } - + + /** + */ function schema_notifications( notification_kind_implementations : Record - ) + ) : _heimdall.helpers.json_schema.type_schema { return { "type": "array", @@ -167,12 +201,14 @@ namespace _heimdall.order ], }; } - - + + + /** + */ export function schema_root( check_kind_implementations : Record, notification_kind_implementations : Record, - ) + ) : _heimdall.helpers.json_schema.type_schema { return { "type": "object", @@ -261,10 +297,12 @@ 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, - 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, - node - ) + node : any + ) : type_check_common { const node_ = Object.assign( { @@ -441,7 +485,7 @@ namespace _heimdall.order function normalize_root( check_kind_implementations : Record, notification_kind_implementations : Record, - node, + node : any, options : { use_implicit_default_values ?: boolean; } = {} @@ -521,6 +565,8 @@ namespace _heimdall.order } + /** + */ export async function load( check_kind_implementations : Record, notification_kind_implementations : Record,